@feathersjs/schema
Advanced tools
Comparing version 5.0.0-pre.16 to 5.0.0-pre.17
@@ -6,2 +6,15 @@ # Change Log | ||
# [5.0.0-pre.17](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.16...v5.0.0-pre.17) (2022-02-15) | ||
### Bug Fixes | ||
* **hooks:** Allow all built-in hooks to be used the async and regular way ([#2559](https://github.com/feathersjs/feathers/issues/2559)) ([8f9f631](https://github.com/feathersjs/feathers/commit/8f9f631e0ce89de349207db72def84e7ab496a4a)) | ||
* **queryProperty:** allow compound oneOf ([#2545](https://github.com/feathersjs/feathers/issues/2545)) ([3077d2d](https://github.com/feathersjs/feathers/commit/3077d2d896a38d579ce4d5b530e21ad332bcf221)) | ||
* **schema:** Properly handle resolver errors ([#2540](https://github.com/feathersjs/feathers/issues/2540)) ([31fbdff](https://github.com/feathersjs/feathers/commit/31fbdff8bd848ac7e0eda56e307ac34b1bfcf17f)) | ||
# [5.0.0-pre.16](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.15...v5.0.0-pre.16) (2022-01-12) | ||
@@ -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 validateQuery: (schema: Schema<any>) => (context: HookContext, next: NextFunction) => Promise<any>; | ||
export declare const validateData: (schema: Schema<any>) => (context: HookContext, next: NextFunction) => Promise<any>; | ||
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 validateQuery: (schema: Schema<any>) => (context: HookContext, next?: NextFunction) => Promise<any>; | ||
export declare const validateData: (schema: Schema<any>) => (context: HookContext, next?: NextFunction) => Promise<any>; |
@@ -25,3 +25,5 @@ "use strict"; | ||
}; | ||
return next(); | ||
if (typeof next === 'function') { | ||
return next(); | ||
} | ||
}; | ||
@@ -41,3 +43,5 @@ exports.resolveQuery = resolveQuery; | ||
} | ||
return next(); | ||
if (typeof next === 'function') { | ||
return next(); | ||
} | ||
}; | ||
@@ -47,15 +51,18 @@ exports.resolveData = resolveData; | ||
var _a; | ||
const { $resolve: properties, ...query } = ((_a = context.params) === null || _a === void 0 ? void 0 : _a.query) || {}; | ||
const { resolve } = context.params; | ||
const status = { | ||
originalContext: context, | ||
...resolve, | ||
properties | ||
}; | ||
context.params = { | ||
...context.params, | ||
query | ||
}; | ||
await next(); | ||
if (typeof next === 'function') { | ||
const { $resolve: properties, ...query } = ((_a = context.params) === null || _a === void 0 ? void 0 : _a.query) || {}; | ||
const resolve = { | ||
originalContext: context, | ||
...context.params.resolve, | ||
properties | ||
}; | ||
context.params = { | ||
...context.params, | ||
resolve, | ||
query | ||
}; | ||
await next(); | ||
} | ||
const ctx = getContext(context); | ||
const status = context.params.resolve; | ||
const data = context.method === 'find' && context.result.data | ||
@@ -81,3 +88,5 @@ ? context.result.data | ||
}; | ||
return next(); | ||
if (typeof next === 'function') { | ||
return next(); | ||
} | ||
} | ||
@@ -102,5 +111,7 @@ catch (error) { | ||
} | ||
return next(); | ||
if (typeof next === 'function') { | ||
return next(); | ||
} | ||
}; | ||
exports.validateData = validateData; | ||
//# sourceMappingURL=hooks.js.map |
import { JSONSchema } from 'json-schema-to-ts'; | ||
export declare const queryProperty: <T extends JSONSchema>(definition: T) => { | ||
readonly oneOf: readonly [T, { | ||
readonly anyOf: readonly [T, { | ||
readonly type: "object"; | ||
@@ -5,0 +5,0 @@ readonly additionalProperties: false; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const queryProperty = (definition) => ({ | ||
oneOf: [ | ||
anyOf: [ | ||
definition, | ||
@@ -8,0 +8,0 @@ { |
@@ -1,2 +0,1 @@ | ||
import { Schema } from './schema'; | ||
export declare type PropertyResolver<T, V, C> = (value: V | undefined, obj: T, context: C, status: ResolverStatus<T, C>) => Promise<V | undefined>; | ||
@@ -7,3 +6,3 @@ export declare type PropertyResolverMap<T, C> = { | ||
export interface ResolverConfig<T, C> { | ||
schema?: Schema<any>; | ||
schema?: any; | ||
validate?: 'before' | 'after' | false; | ||
@@ -15,3 +14,3 @@ properties: PropertyResolverMap<T, C>; | ||
originalContext?: C; | ||
properties?: (keyof T)[]; | ||
properties?: string[]; | ||
stack: PropertyResolver<T, any, C>[]; | ||
@@ -18,0 +17,0 @@ } |
@@ -58,3 +58,4 @@ "use strict"; | ||
if (hasErrors) { | ||
throw new errors_1.BadRequest(`Error resolving data ${status === null || status === void 0 ? void 0 : status.properties.join('.')}`, errors); | ||
const propertyName = (status === null || status === void 0 ? void 0 : status.properties) ? ` ${status.properties.join('.')}` : ''; | ||
throw new errors_1.BadRequest('Error resolving data' + propertyName, errors); | ||
} | ||
@@ -61,0 +62,0 @@ return schema && validate === 'after' |
{ | ||
"name": "@feathersjs/schema", | ||
"description": "A common data schema definition format", | ||
"version": "5.0.0-pre.16", | ||
"version": "5.0.0-pre.17", | ||
"homepage": "https://feathersjs.com", | ||
@@ -53,19 +53,19 @@ "main": "lib/", | ||
"dependencies": { | ||
"@feathersjs/errors": "^5.0.0-pre.16", | ||
"@feathersjs/feathers": "^5.0.0-pre.16", | ||
"@feathersjs/errors": "^5.0.0-pre.17", | ||
"@feathersjs/feathers": "^5.0.0-pre.17", | ||
"@types/json-schema": "^7.0.9", | ||
"ajv": "^8.8.2", | ||
"ajv": "^8.10.0", | ||
"json-schema": "^0.4.0", | ||
"json-schema-to-ts": "^1.6.4" | ||
"json-schema-to-ts": "^1.6.5" | ||
}, | ||
"devDependencies": { | ||
"@feathersjs/memory": "^5.0.0-pre.16", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^17.0.5", | ||
"@feathersjs/memory": "^5.0.0-pre.17", | ||
"@types/mocha": "^9.1.0", | ||
"@types/node": "^17.0.15", | ||
"ajv-formats": "^2.1.1", | ||
"mocha": "^9.1.3", | ||
"shx": "^0.3.3", | ||
"typescript": "^4.5.4" | ||
"mocha": "^9.2.0", | ||
"shx": "^0.3.4", | ||
"typescript": "^4.5.5" | ||
}, | ||
"gitHead": "f0cd227a82d159b528193bd33747c97684a48773" | ||
"gitHead": "d828748e57b40abfaa15710663afed417de14a1d" | ||
} |
# @feathersjs/schema | ||
[![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI) | ||
[![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/socketio)](https://david-dm.org/feathersjs/feathers?path=packages/schema) | ||
[![Download Status](https://img.shields.io/npm/dm/@feathersjs/schema.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/schema) | ||
@@ -21,4 +20,4 @@ | ||
Copyright (c) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors) | ||
Copyright (c) 2022 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors) | ||
Licensed under the [MIT license](LICENSE). |
@@ -17,3 +17,3 @@ import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
export const resolveQuery = <T> (resolver: Resolver<T, HookContext>) => | ||
async (context: HookContext, next: NextFunction) => { | ||
async (context: HookContext, next?: NextFunction) => { | ||
const ctx = getContext(context); | ||
@@ -30,7 +30,9 @@ const data = context?.params?.query || {}; | ||
return next(); | ||
if (typeof next === 'function') { | ||
return next(); | ||
} | ||
}; | ||
export const resolveData = <T> (resolver: Resolver<T, HookContext>) => | ||
async (context: HookContext, next: NextFunction) => { | ||
async (context: HookContext, next?: NextFunction) => { | ||
const ctx = getContext(context); | ||
@@ -50,23 +52,28 @@ const data = context.data; | ||
return next(); | ||
if (typeof next === 'function') { | ||
return next(); | ||
} | ||
}; | ||
export const resolveResult = <T> (resolver: Resolver<T, HookContext>) => | ||
async (context: HookContext, next: NextFunction) => { | ||
const { $resolve: properties, ...query } = context.params?.query || {}; | ||
const { resolve } = context.params; | ||
const status = { | ||
originalContext: context, | ||
...resolve, | ||
properties | ||
}; | ||
async (context: HookContext, next?: NextFunction) => { | ||
if (typeof next === 'function') { | ||
const { $resolve: properties, ...query } = context.params?.query || {}; | ||
const resolve = { | ||
originalContext: context, | ||
...context.params.resolve, | ||
properties | ||
}; | ||
context.params = { | ||
...context.params, | ||
query | ||
context.params = { | ||
...context.params, | ||
resolve, | ||
query | ||
} | ||
await next(); | ||
} | ||
await next(); | ||
const ctx = getContext(context); | ||
const status = context.params.resolve; | ||
const data = context.method === 'find' && context.result.data | ||
@@ -86,3 +93,3 @@ ? context.result.data | ||
export const validateQuery = (schema: Schema<any>) => | ||
async (context: HookContext, next: NextFunction) => { | ||
async (context: HookContext, next?: NextFunction) => { | ||
const data = context?.params?.query || {}; | ||
@@ -98,3 +105,5 @@ | ||
return next(); | ||
if (typeof next === 'function') { | ||
return next(); | ||
} | ||
} catch (error: any) { | ||
@@ -106,3 +115,3 @@ throw (error.ajv ? new BadRequest(error.message, error.errors) : error); | ||
export const validateData = (schema: Schema<any>) => | ||
async (context: HookContext, next: NextFunction) => { | ||
async (context: HookContext, next?: NextFunction) => { | ||
const data = context.data; | ||
@@ -122,3 +131,5 @@ | ||
return next(); | ||
if (typeof next === 'function') { | ||
return next(); | ||
} | ||
}; |
import { JSONSchema } from 'json-schema-to-ts'; | ||
export const queryProperty = <T extends JSONSchema> (definition: T) => ({ | ||
oneOf: [ | ||
anyOf: [ | ||
definition, | ||
@@ -6,0 +6,0 @@ { |
import { BadRequest } from '@feathersjs/errors'; | ||
import { Schema } from './schema'; | ||
@@ -16,3 +15,5 @@ export type PropertyResolver<T, V, C> = ( | ||
export interface ResolverConfig<T, C> { | ||
schema?: Schema<any>, | ||
// TODO this should be `Schema<any>` but has recently produced an error, see | ||
// https://github.com/ThomasAribart/json-schema-to-ts/issues/53 | ||
schema?: any, | ||
validate?: 'before'|'after'|false, | ||
@@ -25,3 +26,3 @@ properties: PropertyResolverMap<T, C> | ||
originalContext?: C; | ||
properties?: (keyof T)[]; | ||
properties?: string[]; | ||
stack: PropertyResolver<T, any, C>[]; | ||
@@ -99,3 +100,5 @@ } | ||
if (hasErrors) { | ||
throw new BadRequest(`Error resolving data ${status?.properties.join('.')}`, errors); | ||
const propertyName = status?.properties ? ` ${status.properties.join('.')}` : ''; | ||
throw new BadRequest('Error resolving data' + propertyName, errors); | ||
} | ||
@@ -102,0 +105,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
36287
615
23
Updatedajv@^8.10.0
Updatedjson-schema-to-ts@^1.6.5