FFFF fix(core): `context.type` for around hooks by fratzinger · Pull Request #2890 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
638 changes: 572 additions & 66 deletions docs/package-lock.json

Large diffs are not rendered by default.

2,202 changes: 1,172 additions & 1,030 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@feathersjs/commons": "^5.0.0-pre.33",
"@feathersjs/errors": "^5.0.0-pre.33",
"@feathersjs/feathers": "^5.0.0-pre.33",
"@feathersjs/hooks": "^0.7.5",
"@feathersjs/hooks": "^0.7.6",
"@feathersjs/schema": "^5.0.0-pre.33",
"@feathersjs/transport-commons": "^5.0.0-pre.33",
"@types/jsonwebtoken": "^8.5.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/src/hooks/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default (originalSettings: string | AuthenticateHookSettings, ...original

debug(`Running authenticate hook on '${path}'`)

if (type && type !== 'before') {
if (type && type !== 'before' && type !== 'around') {
throw new NotAuthenticated('The authenticate hook must be used as a before hook')
}

Expand Down
4 changes: 2 additions & 2 deletions packages/express/test/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('@feathersjs/express/rest provider', () => {
id: 'dishes',
params: paramsWithHeaders,
arguments: ['dishes', paramsWithHeaders],
type: null,
type: 'around',
method: 'get',
path: 'hook',
http: {},
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('@feathersjs/express/rest provider', () => {
id: 'dishes',
params: paramsWithHeaders,
arguments: ['dishes', paramsWithHeaders],
type: null,
type: 'around',
event: null,
method: 'get',
path: 'hook-error',
Expand Down
2 changes: 1 addition & 1 deletion packages/feathers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"dependencies": {
"@feathersjs/commons": "^5.0.0-pre.33",
"@feathersjs/hooks": "^0.7.5",
"@feathersjs/hooks": "^0.7.6",
"events": "^3.3.0"
},
"devDependencies": {
Expand Down
7 changes: 4 additions & 3 deletions packages/feathers/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ export interface Http {
location?: string
}

export type HookType = 'before' | 'after' | 'error' | 'around'

export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
/**
* A read only property that contains the Feathers application object. This can be used to
Expand All @@ -367,10 +369,9 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
*/
readonly service: S
/**
* A read only property with the hook type (one of before, after or error).
* Will be `null` for asynchronous hooks.
* A read only property with the hook type (one of 'around', 'before', 'after' or 'error').
*/
readonly type: null | 'before' | 'after' | 'error'
readonly type: HookType
/**
* The list of method arguments. Should not be modified, modify the
* `params`, `data` and `id` properties instead.
Expand Down
7 changes: 3 additions & 4 deletions packages/feathers/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import {
FeathersService,
HookMap,
AroundHookFunction,
HookFunction
HookFunction,
HookType
} from './declarations'
import { defaultServiceArguments, getHookMethods } from './service'

type HookType = 'before' | 'after' | 'error' | 'around'

type ConvertedMap = { [type in HookType]: ReturnType<typeof convertHookData> }

type HookStore = {
Expand Down Expand Up @@ -172,7 +171,7 @@ export function hookMixin<A>(this: A, service: FeathersService<A>, path: string,
method,
service,
event: null,
type: null,
type: 'around',
get statusCode() {
return this.http?.status
},
Expand Down
2 changes: 1 addition & 1 deletion packages/feathers/test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ describe('Service events', () => {
assert.ok(hook.changed)
assert.strictEqual(hook.service, service)
assert.strictEqual(hook.method, 'create')
assert.strictEqual(hook.type, null)
assert.strictEqual(hook.type, 'around')
done()
} catch (error: any) {
done(error)
Expand Down
2 changes: 1 addition & 1 deletion packages/feathers/test/hooks/around.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('`around` hooks', () => {
service.hooks({
create: [
async (hook, next) => {
assert.strictEqual(hook.type, null)
assert.strictEqual(hook.type, 'around')

hook.data.modified = 'data'

Expand Down
2 changes: 1 addition & 1 deletion packages/feathers/test/hooks/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe('hooks basics', () => {
const returnedContext = await app.service('dummy').get(10, {}, context)

assert.strictEqual(returnedContext.service, app.service('dummy'))
assert.strictEqual(returnedContext.type, null)
assert.strictEqual(returnedContext.type, 'around')
assert.strictEqual(returnedContext.path, 'dummy')
assert.deepStrictEqual(returnedContext.result, {
id: 10,
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@feathersjs/commons": "^5.0.0-pre.33",
"@feathersjs/errors": "^5.0.0-pre.33",
"@feathersjs/feathers": "^5.0.0-pre.33",
"@feathersjs/hooks": "^0.7.5",
"@feathersjs/hooks": "^0.7.6",
"@types/json-schema": "^7.0.11",
"ajv": "^8.11.2",
"ajv-formats": "^2.1.1",
Expand Down
0