Skip to content

Commit d606ac6

Browse files
authored
fix(core): context.type for around hooks (#2890)
1 parent 801a503 commit d606ac6

File tree

12 files changed

+1760
-1112
lines changed

12 files changed

+1760
-1112
lines changed

docs/package-lock.json

Lines changed: 572 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1172 additions & 1030 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/authentication/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@feathersjs/commons": "^5.0.0-pre.33",
5757
"@feathersjs/errors": "^5.0.0-pre.33",
5858
"@feathersjs/feathers": "^5.0.0-pre.33",
59-
"@feathersjs/hooks": "^0.7.5",
59+
"@feathersjs/hooks": "^0.7.6",
6060
"@feathersjs/schema": "^5.0.0-pre.33",
6161
"@feathersjs/transport-commons": "^5.0.0-pre.33",
6262
"@types/jsonwebtoken": "^8.5.9",

packages/authentication/src/hooks/authenticate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default (originalSettings: string | AuthenticateHookSettings, ...original
3030

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

33-
if (type && type !== 'before') {
33+
if (type && type !== 'before' && type !== 'around') {
3434
throw new NotAuthenticated('The authenticate hook must be used as a before hook')
3535
}
3636

packages/express/test/rest.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('@feathersjs/express/rest provider', () => {
177177
id: 'dishes',
178178
params: paramsWithHeaders,
179179
arguments: ['dishes', paramsWithHeaders],
180-
type: null,
180+
type: 'around',
181181
method: 'get',
182182
path: 'hook',
183183
http: {},
@@ -283,7 +283,7 @@ describe('@feathersjs/express/rest provider', () => {
283283
id: 'dishes',
284284
params: paramsWithHeaders,
285285
arguments: ['dishes', paramsWithHeaders],
286-
type: null,
286+
type: 'around',
287287
event: null,
288288
method: 'get',
289289
path: 'hook-error',

packages/feathers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
},
6060
"dependencies": {
6161
"@feathersjs/commons": "^5.0.0-pre.33",
62-
"@feathersjs/hooks": "^0.7.5",
62+
"@feathersjs/hooks": "^0.7.6",
6363
"events": "^3.3.0"
6464
},
6565
"devDependencies": {

packages/feathers/src/declarations.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ export interface Http {
346346
location?: string
347347
}
348348

349+
export type HookType = 'before' | 'after' | 'error' | 'around'
350+
349351
export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
350352
/**
351353
* A read only property that contains the Feathers application object. This can be used to
@@ -367,10 +369,9 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
367369
*/
368370
readonly service: S
369371
/**
370-
* A read only property with the hook type (one of before, after or error).
371-
* Will be `null` for asynchronous hooks.
372+
* A read only property with the hook type (one of 'around', 'before', 'after' or 'error').
372373
*/
373-
readonly type: null | 'before' | 'after' | 'error'
374+
readonly type: HookType
374375
/**
375376
* The list of method arguments. Should not be modified, modify the
376377
* `params`, `data` and `id` properties instead.

packages/feathers/src/hooks.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import {
1414
FeathersService,
1515
HookMap,
1616
AroundHookFunction,
17-
HookFunction
17+
HookFunction,
18+
HookType
1819
} from './declarations'
1920
import { defaultServiceArguments, getHookMethods } from './service'
2021

21-
type HookType = 'before' | 'after' | 'error' | 'around'
22-
2322
type ConvertedMap = { [type in HookType]: ReturnType<typeof convertHookData> }
2423

2524
type HookStore = {
@@ -172,7 +171,7 @@ export function hookMixin<A>(this: A, service: FeathersService<A>, path: string,
172171
method,
173172
service,
174173
event: null,
175-
type: null,
174+
type: 'around',
176175
get statusCode() {
177176
return this.http?.status
178177
},

packages/feathers/test/events.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ describe('Service events', () => {
289289
assert.ok(hook.changed)
290290
assert.strictEqual(hook.service, service)
291291
assert.strictEqual(hook.method, 'create')
292-
assert.strictEqual(hook.type, null)
292+
assert.strictEqual(hook.type, 'around')
293293
done()
294294
} catch (error: any) {
295295
done(error)

packages/feathers/test/hooks/around.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('`around` hooks', () => {
114114
service.hooks({
115115
create: [
116116
async (hook, next) => {
117-
assert.strictEqual(hook.type, null)
117+
assert.strictEqual(hook.type, 'around')
118118

119119
hook.data.modified = 'data'
120120

0 commit comments

Comments
 (0)