@feathersjs/schema
Advanced tools
Comparing version 5.0.0-pre.18 to 5.0.0-pre.19
@@ -6,2 +6,15 @@ # Change Log | ||
# [5.0.0-pre.19](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.18...v5.0.0-pre.19) (2022-05-01) | ||
### Features | ||
* **schema:** Allow hooks to run resolvers in sequence ([#2609](https://github.com/feathersjs/feathers/issues/2609)) ([d85c507](https://github.com/feathersjs/feathers/commit/d85c507c76d07e48fc8e7e28ff7de0ef435e0ef8)) | ||
* **typescript:** Improve adapter typings ([#2605](https://github.com/feathersjs/feathers/issues/2605)) ([3b2ca0a](https://github.com/feathersjs/feathers/commit/3b2ca0a6a8e03e8390272c4d7e930b4bffdaacf5)) | ||
* **typescript:** Improve params and query typeability ([#2600](https://github.com/feathersjs/feathers/issues/2600)) ([df28b76](https://github.com/feathersjs/feathers/commit/df28b7619161f1df5e700326f52cca1a92dc5d28)) | ||
# [5.0.0-pre.18](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.17...v5.0.0-pre.18) (2022-04-11) | ||
@@ -8,0 +21,0 @@ |
import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
import { Resolver } from './resolver'; | ||
import { Schema } from './schema'; | ||
export declare const resolveQuery: <T>(resolver: Resolver<T, HookContext<import("@feathersjs/feathers").Application<any, any>, any>>) => (context: HookContext, next?: NextFunction) => Promise<any>; | ||
export declare const resolveData: <T>(resolver: Resolver<T, HookContext<import("@feathersjs/feathers").Application<any, any>, any>>) => (context: HookContext, next?: NextFunction) => Promise<any>; | ||
export declare const resolveResult: <T>(resolver: Resolver<T, HookContext<import("@feathersjs/feathers").Application<any, any>, any>>) => (context: HookContext, next?: NextFunction) => Promise<void>; | ||
export declare const resolveQuery: <T>(...resolvers: Resolver<T, HookContext<import("@feathersjs/feathers").Application<any, any>, any>>[]) => (context: HookContext, next?: NextFunction) => Promise<any>; | ||
export declare const resolveData: <T>(...resolvers: Resolver<T, HookContext<import("@feathersjs/feathers").Application<any, any>, any>>[]) => (context: HookContext, next?: NextFunction) => Promise<any>; | ||
export declare const resolveResult: <T>(...resolvers: Resolver<T, HookContext<import("@feathersjs/feathers").Application<any, any>, any>>[]) => (context: HookContext, next?: NextFunction) => Promise<void>; | ||
export declare const validateQuery: (schema: Schema<any>) => (context: HookContext, next?: NextFunction) => Promise<any>; | ||
export declare const validateData: (schema: Schema<any>) => (context: HookContext, next?: NextFunction) => Promise<any>; |
@@ -14,9 +14,14 @@ "use strict"; | ||
}; | ||
const resolveQuery = (resolver) => async (context, next) => { | ||
const runResolvers = async (resolvers, data, ctx, status) => { | ||
let current = data; | ||
for (const resolver of resolvers) { | ||
current = await resolver.resolve(current, ctx, status); | ||
} | ||
return current; | ||
}; | ||
const resolveQuery = (...resolvers) => async (context, next) => { | ||
var _a; | ||
const ctx = getContext(context); | ||
const data = ((_a = context === null || context === void 0 ? void 0 : context.params) === null || _a === void 0 ? void 0 : _a.query) || {}; | ||
const query = await resolver.resolve(data, ctx, { | ||
originalContext: context | ||
}); | ||
const query = await runResolvers(resolvers, data, ctx); | ||
context.params = { | ||
@@ -31,3 +36,3 @@ ...context.params, | ||
exports.resolveQuery = resolveQuery; | ||
const resolveData = (resolver) => async (context, next) => { | ||
const resolveData = (...resolvers) => async (context, next) => { | ||
const ctx = getContext(context); | ||
@@ -39,6 +44,6 @@ const data = context.data; | ||
if (Array.isArray(data)) { | ||
context.data = await Promise.all(data.map(current => resolver.resolve(current, ctx, status))); | ||
context.data = await Promise.all(data.map(current => runResolvers(resolvers, current, ctx, status))); | ||
} | ||
else { | ||
context.data = await resolver.resolve(data, ctx, status); | ||
context.data = await runResolvers(resolvers, data, ctx, status); | ||
} | ||
@@ -50,3 +55,3 @@ if (typeof next === 'function') { | ||
exports.resolveData = resolveData; | ||
const resolveResult = (resolver) => async (context, next) => { | ||
const resolveResult = (...resolvers) => async (context, next) => { | ||
var _a; | ||
@@ -72,4 +77,4 @@ if (typeof next === 'function') { | ||
const result = Array.isArray(data) ? | ||
await Promise.all(data.map(async (current) => resolver.resolve(current, ctx, status))) : | ||
await resolver.resolve(data, ctx, status); | ||
await Promise.all(data.map(async (current) => runResolvers(resolvers, current, ctx, status))) : | ||
await runResolvers(resolvers, data, ctx, status); | ||
if (isPaginated) { | ||
@@ -76,0 +81,0 @@ context.result.data = result; |
@@ -1,3 +0,2 @@ | ||
import { JSONSchema } from 'json-schema-to-ts'; | ||
export declare const queryProperty: <T extends JSONSchema>(definition: T) => { | ||
export declare const queryProperty: <T extends import("json-schema-to-ts").JSONSchema7>(definition: T) => { | ||
readonly anyOf: readonly [T, { | ||
@@ -4,0 +3,0 @@ readonly type: "object"; |
{ | ||
"name": "@feathersjs/schema", | ||
"description": "A common data schema definition format", | ||
"version": "5.0.0-pre.18", | ||
"version": "5.0.0-pre.19", | ||
"homepage": "https://feathersjs.com", | ||
@@ -56,19 +56,19 @@ "main": "lib/", | ||
"dependencies": { | ||
"@feathersjs/errors": "^5.0.0-pre.18", | ||
"@feathersjs/feathers": "^5.0.0-pre.18", | ||
"@feathersjs/errors": "^5.0.0-pre.19", | ||
"@feathersjs/feathers": "^5.0.0-pre.19", | ||
"@types/json-schema": "^7.0.11", | ||
"ajv": "^8.11.0", | ||
"json-schema": "^0.4.0", | ||
"json-schema-to-ts": "^1.6.5" | ||
"json-schema-to-ts": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"@feathersjs/memory": "^5.0.0-pre.18", | ||
"@types/mocha": "^9.1.0", | ||
"@types/node": "^17.0.23", | ||
"@feathersjs/memory": "^5.0.0-pre.19", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^17.0.31", | ||
"ajv-formats": "^2.1.1", | ||
"mocha": "^9.2.2", | ||
"mocha": "^10.0.0", | ||
"shx": "^0.3.4", | ||
"typescript": "^4.6.3" | ||
"typescript": "^4.6.4" | ||
}, | ||
"gitHead": "c0b7b67d872dcd6b6d94e4587f21332c8a519b50" | ||
"gitHead": "57f3e18bb62735e1869ffafee90286498738fdfa" | ||
} |
import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
import { BadRequest } from '../../errors/lib'; | ||
import { Resolver } from './resolver'; | ||
import { Resolver, ResolverStatus } from './resolver'; | ||
import { Schema } from './schema'; | ||
@@ -16,9 +16,22 @@ | ||
export const resolveQuery = <T> (resolver: Resolver<T, HookContext>) => | ||
const runResolvers = async <T> ( | ||
resolvers: Resolver<T, HookContext>[], | ||
data: any, | ||
ctx: HookContext, | ||
status?: Partial<ResolverStatus<T, HookContext>> | ||
) => { | ||
let current: any = data; | ||
for (const resolver of resolvers) { | ||
current = await resolver.resolve(current, ctx, status); | ||
} | ||
return current as T; | ||
} | ||
export const resolveQuery = <T> (...resolvers: Resolver<T, HookContext>[]) => | ||
async (context: HookContext, next?: NextFunction) => { | ||
const ctx = getContext(context); | ||
const data = context?.params?.query || {}; | ||
const query = await resolver.resolve(data, ctx, { | ||
originalContext: context | ||
}); | ||
const query = await runResolvers(resolvers, data, ctx); | ||
@@ -35,3 +48,3 @@ context.params = { | ||
export const resolveData = <T> (resolver: Resolver<T, HookContext>) => | ||
export const resolveData = <T> (...resolvers: Resolver<T, HookContext>[]) => | ||
async (context: HookContext, next?: NextFunction) => { | ||
@@ -46,6 +59,6 @@ const ctx = getContext(context); | ||
context.data = await Promise.all(data.map(current => | ||
resolver.resolve(current, ctx, status) | ||
runResolvers(resolvers, current, ctx, status) | ||
)); | ||
} else { | ||
context.data = await resolver.resolve(data, ctx, status); | ||
context.data = await runResolvers(resolvers, data, ctx, status); | ||
} | ||
@@ -58,3 +71,3 @@ | ||
export const resolveResult = <T> (resolver: Resolver<T, HookContext>) => | ||
export const resolveResult = <T> (...resolvers: Resolver<T, HookContext>[]) => | ||
async (context: HookContext, next?: NextFunction) => { | ||
@@ -85,4 +98,4 @@ if (typeof next === 'function') { | ||
const result = Array.isArray(data) ? | ||
await Promise.all(data.map(async current => resolver.resolve(current, ctx, status))) : | ||
await resolver.resolve(data, ctx, status); | ||
await Promise.all(data.map(async current => runResolvers(resolvers, current, ctx, status))) : | ||
await runResolvers(resolvers, data, ctx, status); | ||
@@ -89,0 +102,0 @@ if (isPaginated) { |
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
39631
644
6411
+ Added@babel/runtime@7.26.0(transitive)
+ Addedjson-schema-to-ts@2.12.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedts-algebra@1.2.2(transitive)
- Removedjson-schema-to-ts@1.6.5(transitive)
- Removedts-toolbelt@6.15.5(transitive)
Updatedjson-schema-to-ts@^2.3.0