@feathersjs/schema
Advanced tools
Comparing version 5.0.0-pre.36 to 5.0.0-pre.37
@@ -6,2 +6,9 @@ # Change Log | ||
# [5.0.0-pre.37](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.36...v5.0.0-pre.37) (2023-02-09) | ||
### Bug Fixes | ||
- **schema:** Do not change the hook context in resolvers ([#3048](https://github.com/feathersjs/feathers/issues/3048)) ([bfd8c04](https://github.com/feathersjs/feathers/commit/bfd8c04c15279063a0d4b70771715c656dda5f7c)) | ||
- **schema:** Ensure that resolveResult and resolveExternal are run as around hooks ([#3032](https://github.com/feathersjs/feathers/issues/3032)) ([71942f4](https://github.com/feathersjs/feathers/commit/71942f418e3afe167aef4f98b1a97356dae7625c)) | ||
# [5.0.0-pre.36](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.35...v5.0.0-pre.36) (2023-01-29) | ||
@@ -8,0 +15,0 @@ |
@@ -6,3 +6,3 @@ import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
export declare const resolveData: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next?: NextFunction) => Promise<any>; | ||
export declare const resolveResult: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next?: NextFunction) => Promise<void>; | ||
export declare const resolveResult: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next: NextFunction) => Promise<void>; | ||
export declare const DISPATCH: unique symbol; | ||
@@ -12,4 +12,4 @@ export declare const getDispatchValue: (value: any) => any; | ||
export declare const setDispatch: (current: any, dispatch: any) => any; | ||
export declare const resolveDispatch: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next?: NextFunction) => Promise<void>; | ||
export declare const resolveExternal: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next?: NextFunction) => Promise<void>; | ||
export declare const resolveExternal: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next: NextFunction) => Promise<void>; | ||
export declare const resolveDispatch: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next: NextFunction) => Promise<void>; | ||
type ResolveAllSettings<H extends HookContext> = { | ||
@@ -16,0 +16,0 @@ data?: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveAll = exports.resolveExternal = exports.resolveDispatch = exports.setDispatch = exports.getDispatch = exports.getDispatchValue = exports.DISPATCH = exports.resolveResult = exports.resolveData = exports.resolveQuery = void 0; | ||
exports.resolveAll = exports.resolveDispatch = exports.resolveExternal = exports.setDispatch = exports.getDispatch = exports.getDispatchValue = exports.DISPATCH = exports.resolveResult = exports.resolveData = exports.resolveQuery = void 0; | ||
const hooks_1 = require("@feathersjs/hooks"); | ||
const getContext = (context) => { | ||
return Object.freeze({ | ||
...context, | ||
params: Object.freeze({ | ||
...context.params, | ||
query: Object.freeze({}) | ||
}) | ||
}); | ||
}; | ||
const getResult = (context) => { | ||
@@ -30,5 +21,4 @@ const isPaginated = context.method === 'find' && context.result.data; | ||
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 runResolvers(resolvers, data, ctx); | ||
const query = await runResolvers(resolvers, data, context); | ||
context.params = { | ||
@@ -45,3 +35,2 @@ ...context.params, | ||
if (context.data !== undefined) { | ||
const ctx = getContext(context); | ||
const data = context.data; | ||
@@ -52,6 +41,6 @@ const status = { | ||
if (Array.isArray(data)) { | ||
context.data = await Promise.all(data.map((current) => runResolvers(resolvers, current, ctx, status))); | ||
context.data = await Promise.all(data.map((current) => runResolvers(resolvers, current, context, status))); | ||
} | ||
else { | ||
context.data = await runResolvers(resolvers, data, ctx, status); | ||
context.data = await runResolvers(resolvers, data, context, status); | ||
} | ||
@@ -68,26 +57,26 @@ } | ||
var _a; | ||
if (typeof next === 'function') { | ||
const { $resolve, $select: select, ...query } = ((_a = context.params) === null || _a === void 0 ? void 0 : _a.query) || {}; | ||
const $select = Array.isArray(select) ? select.filter((name) => !virtualProperties.has(name)) : select; | ||
const resolve = { | ||
originalContext: context, | ||
...context.params.resolve, | ||
properties: $resolve || select | ||
}; | ||
context.params = { | ||
...context.params, | ||
resolve, | ||
query: { | ||
...query, | ||
...($select ? { $select } : {}) | ||
} | ||
}; | ||
await next(); | ||
if (typeof next !== 'function') { | ||
throw new Error('The resolveResult hook must be used as an around hook'); | ||
} | ||
const ctx = getContext(context); | ||
const { $resolve, $select: select, ...query } = ((_a = context.params) === null || _a === void 0 ? void 0 : _a.query) || {}; | ||
const $select = Array.isArray(select) ? select.filter((name) => !virtualProperties.has(name)) : select; | ||
const resolve = { | ||
originalContext: context, | ||
...context.params.resolve, | ||
properties: $resolve || select | ||
}; | ||
context.params = { | ||
...context.params, | ||
resolve, | ||
query: { | ||
...query, | ||
...($select ? { $select } : {}) | ||
} | ||
}; | ||
await next(); | ||
const status = context.params.resolve; | ||
const { isPaginated, data } = getResult(context); | ||
const result = Array.isArray(data) | ||
? await Promise.all(data.map(async (current) => runResolvers(resolvers, current, ctx, status))) | ||
: await runResolvers(resolvers, data, ctx, status); | ||
? await Promise.all(data.map(async (current) => runResolvers(resolvers, current, context, status))) | ||
: await runResolvers(resolvers, data, context, status); | ||
if (isPaginated) { | ||
@@ -126,7 +115,7 @@ context.result.data = result; | ||
exports.setDispatch = setDispatch; | ||
const resolveDispatch = (...resolvers) => async (context, next) => { | ||
if (typeof next === 'function') { | ||
await next(); | ||
const resolveExternal = (...resolvers) => async (context, next) => { | ||
if (typeof next !== 'function') { | ||
throw new Error('The resolveExternal hook must be used as an around hook'); | ||
} | ||
const ctx = getContext(context); | ||
await next(); | ||
const existingDispatch = (0, exports.getDispatch)(context.result); | ||
@@ -140,3 +129,3 @@ if (existingDispatch !== null) { | ||
const resolveAndGetDispatch = async (current) => { | ||
const resolved = await runResolvers(resolvers, current, ctx, status); | ||
const resolved = await runResolvers(resolvers, current, context, status); | ||
const currentDispatch = Object.keys(resolved).reduce((res, key) => { | ||
@@ -160,4 +149,4 @@ res[key] = (0, exports.getDispatchValue)(resolved[key]); | ||
}; | ||
exports.resolveDispatch = resolveDispatch; | ||
exports.resolveExternal = exports.resolveDispatch; | ||
exports.resolveExternal = resolveExternal; | ||
exports.resolveDispatch = exports.resolveExternal; | ||
const dataMethods = ['create', 'update', 'patch']; | ||
@@ -164,0 +153,0 @@ /** |
{ | ||
"name": "@feathersjs/schema", | ||
"description": "A common data schema definition format", | ||
"version": "5.0.0-pre.36", | ||
"version": "5.0.0-pre.37", | ||
"homepage": "https://feathersjs.com", | ||
@@ -57,6 +57,6 @@ "main": "lib/", | ||
"dependencies": { | ||
"@feathersjs/adapter-commons": "^5.0.0-pre.36", | ||
"@feathersjs/commons": "^5.0.0-pre.36", | ||
"@feathersjs/errors": "^5.0.0-pre.36", | ||
"@feathersjs/feathers": "^5.0.0-pre.36", | ||
"@feathersjs/adapter-commons": "^5.0.0-pre.37", | ||
"@feathersjs/commons": "^5.0.0-pre.37", | ||
"@feathersjs/errors": "^5.0.0-pre.37", | ||
"@feathersjs/feathers": "^5.0.0-pre.37", | ||
"@feathersjs/hooks": "^0.7.6", | ||
@@ -69,3 +69,3 @@ "@types/json-schema": "^7.0.11", | ||
"devDependencies": { | ||
"@feathersjs/memory": "^5.0.0-pre.36", | ||
"@feathersjs/memory": "^5.0.0-pre.37", | ||
"@types/mocha": "^10.0.1", | ||
@@ -76,5 +76,5 @@ "@types/node": "^18.11.18", | ||
"shx": "^0.3.4", | ||
"typescript": "^4.9.4" | ||
"typescript": "^4.9.5" | ||
}, | ||
"gitHead": "9a107b463cc80d7f3c28553c908987e05b0b634a" | ||
"gitHead": "17a8b3b2614876772472d3cab3d96d45c01db6ed" | ||
} |
@@ -5,12 +5,2 @@ import { HookContext, NextFunction } from '@feathersjs/feathers' | ||
const getContext = <H extends HookContext>(context: H) => { | ||
return Object.freeze({ | ||
...context, | ||
params: Object.freeze({ | ||
...context.params, | ||
query: Object.freeze({}) | ||
}) | ||
}) | ||
} | ||
const getResult = <H extends HookContext>(context: H) => { | ||
@@ -45,5 +35,4 @@ const isPaginated = context.method === 'find' && context.result.data | ||
async (context: H, next?: NextFunction) => { | ||
const ctx = getContext(context) | ||
const data = context?.params?.query || {} | ||
const query = await runResolvers(resolvers, data, ctx) | ||
const query = await runResolvers(resolvers, data, context) | ||
@@ -64,3 +53,2 @@ context.params = { | ||
if (context.data !== undefined) { | ||
const ctx = getContext(context) | ||
const data = context.data | ||
@@ -73,5 +61,7 @@ | ||
if (Array.isArray(data)) { | ||
context.data = await Promise.all(data.map((current) => runResolvers(resolvers, current, ctx, status))) | ||
context.data = await Promise.all( | ||
data.map((current) => runResolvers(resolvers, current, context, status)) | ||
) | ||
} else { | ||
context.data = await runResolvers(resolvers, data, ctx, status) | ||
context.data = await runResolvers(resolvers, data, context, status) | ||
} | ||
@@ -88,25 +78,26 @@ } | ||
return async (context: H, next?: NextFunction) => { | ||
if (typeof next === 'function') { | ||
const { $resolve, $select: select, ...query } = context.params?.query || {} | ||
const $select = Array.isArray(select) ? select.filter((name) => !virtualProperties.has(name)) : select | ||
const resolve = { | ||
originalContext: context, | ||
...context.params.resolve, | ||
properties: $resolve || select | ||
} | ||
return async (context: H, next: NextFunction) => { | ||
if (typeof next !== 'function') { | ||
throw new Error('The resolveResult hook must be used as an around hook') | ||
} | ||
context.params = { | ||
...context.params, | ||
resolve, | ||
query: { | ||
...query, | ||
...($select ? { $select } : {}) | ||
} | ||
const { $resolve, $select: select, ...query } = context.params?.query || {} | ||
const $select = Array.isArray(select) ? select.filter((name) => !virtualProperties.has(name)) : select | ||
const resolve = { | ||
originalContext: context, | ||
...context.params.resolve, | ||
properties: $resolve || select | ||
} | ||
context.params = { | ||
...context.params, | ||
resolve, | ||
query: { | ||
...query, | ||
...($select ? { $select } : {}) | ||
} | ||
await next() | ||
} | ||
const ctx = getContext(context) | ||
await next() | ||
const status = context.params.resolve | ||
@@ -116,4 +107,4 @@ const { isPaginated, data } = getResult(context) | ||
const result = Array.isArray(data) | ||
? await Promise.all(data.map(async (current) => runResolvers(resolvers, current, ctx, status))) | ||
: await runResolvers(resolvers, data, ctx, status) | ||
? await Promise.all(data.map(async (current) => runResolvers(resolvers, current, context, status))) | ||
: await runResolvers(resolvers, data, context, status) | ||
@@ -157,10 +148,11 @@ if (isPaginated) { | ||
export const resolveDispatch = | ||
export const resolveExternal = | ||
<H extends HookContext>(...resolvers: Resolver<any, H>[]) => | ||
async (context: H, next?: NextFunction) => { | ||
if (typeof next === 'function') { | ||
await next() | ||
async (context: H, next: NextFunction) => { | ||
if (typeof next !== 'function') { | ||
throw new Error('The resolveExternal hook must be used as an around hook') | ||
} | ||
const ctx = getContext(context) | ||
await next() | ||
const existingDispatch = getDispatch(context.result) | ||
@@ -174,3 +166,3 @@ | ||
const resolveAndGetDispatch = async (current: any) => { | ||
const resolved = await runResolvers(resolvers, current, ctx, status) | ||
const resolved = await runResolvers(resolvers, current, context, status) | ||
const currentDispatch = Object.keys(resolved).reduce((res, key) => { | ||
@@ -199,3 +191,3 @@ res[key] = getDispatchValue(resolved[key]) | ||
export const resolveExternal = resolveDispatch | ||
export const resolveDispatch = resolveExternal | ||
@@ -202,0 +194,0 @@ type ResolveAllSettings<H extends HookContext> = { |
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
140486
2743