@feathersjs/schema
Advanced tools
Comparing version 5.0.0-pre.21 to 5.0.0-pre.22
@@ -6,2 +6,13 @@ # Change Log | ||
# [5.0.0-pre.22](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.21...v5.0.0-pre.22) (2022-05-24) | ||
### Bug Fixes | ||
* **schema:** Allows resolveData with different resolvers based on method ([#2644](https://github.com/feathersjs/feathers/issues/2644)) ([be71fa2](https://github.com/feathersjs/feathers/commit/be71fa2fe260e05b7dcc0d5f439e33f2e9ec2434)) | ||
# [5.0.0-pre.21](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.20...v5.0.0-pre.21) (2022-05-23) | ||
@@ -8,0 +19,0 @@ |
import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
import { Resolver } from '../resolver'; | ||
export declare type ResolverSetting<H extends HookContext> = Resolver<any, H> | Resolver<any, H>[]; | ||
export declare type DataResolvers<H extends HookContext> = { | ||
create: Resolver<any, H>; | ||
patch: Resolver<any, H>; | ||
update: Resolver<any, H>; | ||
}; | ||
export declare type ResolveAllSettings<H extends HookContext> = { | ||
data?: DataResolvers<H>; | ||
query?: Resolver<any, H>; | ||
result?: Resolver<any, H>; | ||
dispatch?: Resolver<any, H>; | ||
}; | ||
export declare const DISPATCH: unique symbol; | ||
export declare const resolveQuery: <T, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<T, H>[]) => (context: H, next?: NextFunction) => Promise<any>; | ||
export declare const resolveData: <T, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<T, H>[]) => (context: H, next?: NextFunction) => Promise<any>; | ||
export declare const resolveData: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(settings: DataResolvers<H> | Resolver<any, H>) => (context: H, next?: NextFunction) => Promise<any>; | ||
export declare const resolveResult: <T, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<T, H>[]) => (context: H, next?: NextFunction) => Promise<void>; | ||
export declare const resolveDispatch: <T, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<T, H>[]) => (context: H, next?: NextFunction) => Promise<void>; | ||
export declare type ResolveAllSettings<H extends HookContext> = { | ||
data?: Resolver<any, H> | Resolver<any, H>[]; | ||
query?: Resolver<any, H> | Resolver<any, H>[]; | ||
result?: Resolver<any, H> | Resolver<any, H>[]; | ||
dispatch?: Resolver<any, H> | Resolver<any, H>[]; | ||
}; | ||
export declare const resolveAll: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(map: ResolveAllSettings<H>) => (this: any, context: H, next?: import("@feathersjs/hooks").AsyncMiddleware<H>) => Promise<any>; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const hooks_1 = require("@feathersjs/hooks"); | ||
const resolver_1 = require("../resolver"); | ||
const getContext = (context) => { | ||
@@ -42,4 +43,5 @@ return { | ||
exports.resolveQuery = resolveQuery; | ||
const resolveData = (...resolvers) => async (context, next) => { | ||
const resolveData = (settings) => async (context, next) => { | ||
if (context.method === 'create' || context.method === 'patch' || context.method === 'update') { | ||
const resolvers = settings instanceof resolver_1.Resolver ? [settings] : [settings[context.method]]; | ||
const ctx = getContext(context); | ||
@@ -121,13 +123,19 @@ const data = context.data; | ||
exports.resolveDispatch = resolveDispatch; | ||
const getResolvers = (map, name) => { | ||
const value = map[name]; | ||
return Array.isArray(value) ? value : (value !== undefined ? [value] : []); | ||
const resolveAll = (map) => { | ||
const middleware = []; | ||
if (map.dispatch) { | ||
middleware.push((0, exports.resolveDispatch)(map.dispatch)); | ||
} | ||
if (map.result) { | ||
middleware.push((0, exports.resolveResult)(map.result)); | ||
} | ||
if (map.query) { | ||
middleware.push((0, exports.resolveQuery)(map.query)); | ||
} | ||
if (map.data) { | ||
middleware.push((0, exports.resolveData)(map.data)); | ||
} | ||
return (0, hooks_1.compose)(middleware); | ||
}; | ||
const resolveAll = (map) => (0, hooks_1.compose)([ | ||
(0, exports.resolveDispatch)(...getResolvers(map, 'dispatch')), | ||
(0, exports.resolveResult)(...getResolvers(map, 'result')), | ||
(0, exports.resolveQuery)(...getResolvers(map, 'query')), | ||
(0, exports.resolveData)(...getResolvers(map, 'data')) | ||
]); | ||
exports.resolveAll = resolveAll; | ||
//# sourceMappingURL=resolve.js.map |
{ | ||
"name": "@feathersjs/schema", | ||
"description": "A common data schema definition format", | ||
"version": "5.0.0-pre.21", | ||
"version": "5.0.0-pre.22", | ||
"homepage": "https://feathersjs.com", | ||
@@ -56,4 +56,4 @@ "main": "lib/", | ||
"dependencies": { | ||
"@feathersjs/errors": "^5.0.0-pre.21", | ||
"@feathersjs/feathers": "^5.0.0-pre.21", | ||
"@feathersjs/errors": "^5.0.0-pre.22", | ||
"@feathersjs/feathers": "^5.0.0-pre.22", | ||
"@feathersjs/hooks": "^0.7.4", | ||
@@ -66,3 +66,3 @@ "@types/json-schema": "^7.0.11", | ||
"devDependencies": { | ||
"@feathersjs/memory": "^5.0.0-pre.21", | ||
"@feathersjs/memory": "^5.0.0-pre.22", | ||
"@types/mocha": "^9.1.1", | ||
@@ -75,3 +75,3 @@ "@types/node": "^17.0.31", | ||
}, | ||
"gitHead": "ac3baed231f72370a80a06c5944538915479b96e" | ||
"gitHead": "e452e02063e6d8943a9cae2315ab585bc4f82fb6" | ||
} |
@@ -37,2 +37,17 @@ import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
export type ResolverSetting<H extends HookContext> = Resolver<any, H>|Resolver<any, H>[]; | ||
export type DataResolvers<H extends HookContext> = { | ||
create: Resolver<any, H> | ||
patch: Resolver<any, H> | ||
update: Resolver<any, H> | ||
} | ||
export type ResolveAllSettings<H extends HookContext> = { | ||
data?: DataResolvers<H> | ||
query?: Resolver<any, H> | ||
result?: Resolver<any, H> | ||
dispatch?: Resolver<any, H> | ||
} | ||
export const DISPATCH = Symbol('@feathersjs/schema/dispatch'); | ||
@@ -56,5 +71,6 @@ | ||
export const resolveData = <T, H extends HookContext> (...resolvers: Resolver<T, H>[]) => | ||
export const resolveData = <H extends HookContext> (settings: DataResolvers<H>|Resolver<any, H>) => | ||
async (context: H, next?: NextFunction) => { | ||
if (context.method === 'create' || context.method === 'patch' || context.method === 'update') { | ||
const resolvers = settings instanceof Resolver ? [ settings ] : [ settings[context.method] ]; | ||
const ctx = getContext(context); | ||
@@ -151,23 +167,22 @@ const data = context.data; | ||
export type ResolveAllSettings<H extends HookContext> = { | ||
data?: Resolver<any, H>|Resolver<any, H>[] | ||
query?: Resolver<any, H>|Resolver<any, H>[] | ||
result?: Resolver<any, H>|Resolver<any, H>[] | ||
dispatch?: Resolver<any, H>|Resolver<any, H>[] | ||
} | ||
export const resolveAll = <H extends HookContext> (map: ResolveAllSettings<H>) => { | ||
const middleware = []; | ||
const getResolvers = <H extends HookContext> ( | ||
map: ResolveAllSettings<H>, | ||
name: keyof ResolveAllSettings<H> | ||
) => { | ||
const value = map[name]; | ||
if (map.dispatch) { | ||
middleware.push(resolveDispatch(map.dispatch)); | ||
} | ||
return Array.isArray(value) ? value : (value !== undefined ? [ value ] : []); | ||
if (map.result) { | ||
middleware.push(resolveResult(map.result)); | ||
} | ||
if (map.query) { | ||
middleware.push(resolveQuery(map.query)); | ||
} | ||
if (map.data) { | ||
middleware.push(resolveData(map.data)); | ||
} | ||
return compose(middleware); | ||
} | ||
export const resolveAll = <H extends HookContext> (map: ResolveAllSettings<H>) => compose([ | ||
resolveDispatch(...getResolvers(map, 'dispatch')), | ||
resolveResult(...getResolvers(map, 'result')), | ||
resolveQuery(...getResolvers(map, 'query')), | ||
resolveData(...getResolvers(map, 'data')) | ||
]) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58930
1002