Skip to content

Commit

Permalink
Merge pull request #58 from fratzinger/dove
Browse files Browse the repository at this point in the history
refactor!: dove
  • Loading branch information
fratzinger authored Mar 17, 2023
2 parents 8f7a606 + 52098ac commit a32ce09
Show file tree
Hide file tree
Showing 29 changed files with 9,332 additions and 5,030 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -22,3 +22,15 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 18.x
uses: actions/setup-node@v1
with:
node-version: 18.x
- run: npm ci
- run: npm run compile
11 changes: 0 additions & 11 deletions .mocharc.js

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2022 Feathers
Copyright (c) 2023 Feathers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12,686 changes: 8,489 additions & 4,197 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 18 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,38 @@
"LICENSE",
"README.md",
"src/**",
"lib/**",
"dist/**"
],
"scripts": {
"compile": "shx rm -rf dist/ && tsup lib/index.ts --format cjs,esm --dts",
"test": "npm run lint && npm run mocha",
"compile": "shx rm -rf dist/ && tsup src/index.ts --format cjs,esm --dts",
"version": "npm run compile",
"release": "np",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"mocha": "cross-env NODE_ENV=test TS_NODE_PROJECT='tsconfig.test.json' mocha --timeout 10000",
"format": "prettier -w .",
"test": "vitest run",
"vitest": "vitest",
"coverage": "vitest run --coverage",
"docs": "vuepress dev docs",
"docs:build": "vuepress build docs"
},
"dependencies": {
"@feathersjs/commons": "^4.5.12",
"@feathersjs/commons": "^5.0.1",
"lodash": "^4.17.21"
},
"devDependencies": {
"@feathersjs/errors": "^4.5.12",
"@feathersjs/feathers": "^4.5.12",
"@types/lodash": "^4.14.178",
"@types/mocha": "^9.1.0",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"cross-env": "^7.0.3",
"eslint": "^8.9.0",
"feathers-memory": "^4.1.0",
"mocha": "^9.2.0",
"np": "^7.6.0",
"@feathersjs/errors": "^5.0.1",
"@feathersjs/feathers": "^5.0.1",
"@feathersjs/memory": "^5.0.1",
"@types/lodash": "^4.14.191",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"eslint": "^8.36.0",
"np": "^7.6.3",
"shx": "^0.3.4",
"ts-node": "^10.5.0",
"tsup": "^5.11.13",
"typescript": "^4.5.5",
"vuepress": "^1.9.7",
"tsup": "^6.6.3",
"typescript": "^4.9.5",
"vite": "^4.2.0",
"vitest": "^0.29.3",
"vuepress": "^1.9.9",
"vuepress-theme-default-prefers-color-scheme": "^2.0.0"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class GraphPopulateApplication {
method: Method,
service: Service<unknown>,
): SingleGraphPopulateParams[] {
// @ts-expect-error add graphPopulate to service
const serviceHooks = service?.graphPopulate?.__hooks
if (!this.__hooks && !serviceHooks) {
if (!params) {
Expand All @@ -38,19 +39,21 @@ export class GraphPopulateApplication {
}
const currentParams = [] as SingleGraphPopulateParams[]

// @ts-expect-error add graphPopulate to service
const before = getHooks(this, service.graphPopulate, 'before', method)
if (before.length > 0) {
currentParams.push(...before)
}

if (params) {
if (Array.isArray(params) && params.length > 0) {
if (Array.isArray(params)) {
currentParams.push(...params)
} else {
currentParams.push(params)
}
}

// @ts-expect-error add graphPopulate to service
const after = getHooks(this, service.graphPopulate, 'after', method, true)

if (after.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { enableHooks } from './hooks.commons'

import type { Service } from '@feathersjs/feathers'

export default (service: Service<unknown>): void => {
export default (service: Service & { graphPopulate?: any }): void => {
if (!service.graphPopulate) {
service.graphPopulate = {}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/app/hooks.commons.ts → src/app/hooks.commons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { _ } from '@feathersjs/commons'
const { each } = _
import _get from 'lodash/get'
import _get from 'lodash/get.js'

import type { AnyData, GraphPopulateHook, GraphPopulateHookMap } from '../types'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import _get from 'lodash/get'
import _isEmpty from 'lodash/isEmpty'
import _merge from 'lodash/merge'
import _get from 'lodash/get.js'
import _isEmpty from 'lodash/isEmpty.js'
import _merge from 'lodash/merge.js'

import { shallowPopulate as makeShallowPopulate } from './shallow-populate.hook'

import type { HookContext, Query } from '@feathersjs/feathers'

import type { GraphPopulateHookOptions } from '../types'
import type { GraphPopulateHookOptions, Method } from '../types'
import type { GraphPopulateApplication } from '../app/graph-populate.class'

const FILTERS = ['$limit', '$select', '$skip', '$sort']
Expand Down Expand Up @@ -87,7 +87,7 @@ export function graphPopulate(
}

if (graphPopulateApp) {
params = graphPopulateApp.withAppParams(params, context.method, service)
params = graphPopulateApp.withAppParams(params, context.method as Method, service)
}

currentPopulates.push(Object.assign({}, populate, { params }))
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/hooks/populate.hook.ts → src/hooks/populate.hook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _set from 'lodash/set'
import _set from 'lodash/set.js'

import { graphPopulate } from './graph-populate.hook'
import { getQuery } from '../utils/get-query'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _get from 'lodash/get'
import _set from 'lodash/set'
import _has from 'lodash/has'
import _get from 'lodash/get.js'
import _set from 'lodash/set.js'
import _has from 'lodash/has.js'

import {
assertIncludes,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Application, HookContext, Params } from '@feathersjs/feathers'
import _get from 'lodash/get'
import _has from 'lodash/has'
import _isEmpty from 'lodash/isEmpty'
import _isEqual from 'lodash/isEqual'
import _isFunction from 'lodash/isFunction'
import _merge from 'lodash/merge'
import _set from 'lodash/set'
import _uniqBy from 'lodash/uniqBy'
import _get from 'lodash/get.js'
import _has from 'lodash/has.js'
import _isEmpty from 'lodash/isEmpty.js'
import _isEqual from 'lodash/isEqual.js'
import _isFunction from 'lodash/isFunction.js'
import _merge from 'lodash/merge.js'
import _set from 'lodash/set.js'
import _uniqBy from 'lodash/uniqBy.js'
import type {
AnyData,
ChainedParamsOptions,
Expand Down Expand Up @@ -91,7 +91,7 @@ export const assertIncludes = (includes: PopulateObject[]): void => {
export const chainedParams = async (
paramsArr: GraphPopulateParams,
context: HookContext,
target: Params,
target: any,
options: ChainedParamsOptions = {},
): Promise<Params> => {
if (!paramsArr) return undefined
Expand All @@ -104,7 +104,8 @@ export const chainedParams = async (
if (_isFunction(params)) {
params =
thisKey == null
? params(resultingParams, context, target)
? // @ts-expect-error todo
params(resultingParams, context, target)
: params.call(thisKey, resultingParams, context, target)
params = await Promise.resolve(params)
}
Expand All @@ -123,7 +124,7 @@ export async function makeCumulatedRequest(
): Promise<CumulatedRequestResult> {
const { keyHere, keyThere } = include

let params: Params = { paginate: false }
let params = { paginate: false } as Params

if (_has(include, 'keyHere') && _has(include, 'keyThere')) {
const keyVals = dataMap[keyHere]
Expand Down Expand Up @@ -194,7 +195,7 @@ export async function makeRequestPerItem(
}

const params = await chainedParams(
[{ paginate: false }, ...paramsFromInclude],
[{ paginate: false } as Params, ...paramsFromInclude],
context,
target,
paramsOptions,
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/util.populate.ts → src/utils/util.populate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { graphPopulate } from '../hooks/graph-populate.hook'
import _isObject from 'lodash/isObject'
import _isObject from 'lodash/isObject.js'

import type { HookContext } from '@feathersjs/feathers'

Expand All @@ -20,9 +20,11 @@ export async function populateUtil(
throw new Error('The app object must be provided in the populateUtil options.')
}
// If there's nothing to populate, return.
// @ts-expect-error add $populateParams to params
if (!_isObject(params.$populateParams)) {
return records
}
// @ts-expect-error add $populateParams to params
const $populateParams: PopulateParams = params.$populateParams
const populateQuery = $populateParams.query
if (!populates || !populateQuery || !Object.keys(populateQuery).length) {
Expand Down
31 changes: 19 additions & 12 deletions test/graph-populate-hooks/graph-populate.app.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import assert from 'assert'
import feathers from '@feathersjs/feathers'
import { Service } from 'feathers-memory'
import type { ServiceAddons, Params } from '@feathersjs/feathers'
import { feathers } from '@feathersjs/feathers'
import { MemoryService } from '@feathersjs/memory'

import configureGraphPopulate, { populate } from '../../lib'
import configureGraphPopulate, { populate } from '../../src'

type GraphPopulateParams = Params & { $populateParams: any; test: any }

const mockApp = () => {
const app = feathers()
const app = feathers<{
users: MemoryService<any, any, GraphPopulateParams> & { graphPopulate: any }
companies: MemoryService<any, any, GraphPopulateParams> & { graphPopulate: any }
posts: MemoryService<any, any, GraphPopulateParams> & { graphPopulate: any }
}>()
app.configure(configureGraphPopulate())

app.use('users', new Service({ multi: true, startId: 1 }))
app.use('companies', new Service({ multi: true, startId: 1 }))
app.use('posts', new Service({ multi: true, startId: 1 }))
app.use('users', new MemoryService({ multi: true, startId: 1 }) as any)
app.use('companies', new MemoryService({ multi: true, startId: 1 }) as any)
app.use('posts', new MemoryService({ multi: true, startId: 1 }) as any)

const usersService = app.service('users')

Expand Down Expand Up @@ -81,7 +88,7 @@ const mockApp = () => {
}
}

describe('graph-populate.app', () => {
describe('graph-populate.app.test.ts', () => {
it('initializes graph-populate with app.configure', () => {
const { app, usersService, companiesService, postsService } = mockApp()

Expand Down Expand Up @@ -554,13 +561,13 @@ describe('graph-populate.app', () => {
},
})

const [result] = await usersService.find({
const [result] = (await usersService.find({
query: {},
test: true,
$populateParams: {
name: 'complete',
},
})
})) as any

const expected = {
id: 1,
Expand Down Expand Up @@ -679,13 +686,13 @@ describe('graph-populate.app', () => {
},
})

const [result] = await usersService.find({
const [result] = (await usersService.find({
query: {},
test: true,
$populateParams: {
name: 'complete',
},
})
})) as any

const expected = {
id: 1,
Expand Down
Loading

0 comments on commit a32ce09

Please # to comment.