@feathersjs/feathers 5.0.0-pre.9 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/hooks.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hookMixin = exports.FeathersHookManager = exports.createContext = exports.enableHooks = exports.collectHooks = exports.convertHookData = void 0;
4
+ const hooks_1 = require("@feathersjs/hooks");
5
+ const service_1 = require("./service");
6
+ const types = ['before', 'after', 'error', 'around'];
7
+ const isType = (value) => types.includes(value);
8
+ // Converts different hook registration formats into the
9
+ // same internal format
10
+ function convertHookData(input) {
11
+ const result = {};
12
+ if (Array.isArray(input)) {
13
+ result.all = input;
14
+ }
15
+ else if (typeof input !== 'object') {
16
+ result.all = [input];
17
+ }
18
+ else {
19
+ for (const key of Object.keys(input)) {
20
+ const value = input[key];
21
+ result[key] = Array.isArray(value) ? value : [value];
22
+ }
23
+ }
24
+ return result;
25
+ }
26
+ exports.convertHookData = convertHookData;
27
+ function collectHooks(target, method) {
28
+ const { collected, collectedAll, around } = target.__hooks;
29
+ return [
30
+ ...(around.all || []),
31
+ ...(around[method] || []),
32
+ ...(collectedAll.before || []),
33
+ ...(collected[method] || []),
34
+ ...(collectedAll.after || [])
35
+ ];
36
+ }
37
+ exports.collectHooks = collectHooks;
38
+ // Add `.hooks` functionality to an object
39
+ function enableHooks(object) {
40
+ const store = {
41
+ around: {},
42
+ before: {},
43
+ after: {},
44
+ error: {},
45
+ collected: {},
46
+ collectedAll: {}
47
+ };
48
+ Object.defineProperty(object, '__hooks', {
49
+ configurable: true,
50
+ value: store,
51
+ writable: true
52
+ });
53
+ return function registerHooks(input) {
54
+ const store = this.__hooks;
55
+ const map = Object.keys(input).reduce((map, type) => {
56
+ if (!isType(type)) {
57
+ throw new Error(`'${type}' is not a valid hook type`);
58
+ }
59
+ map[type] = convertHookData(input[type]);
60
+ return map;
61
+ }, {});
62
+ const types = Object.keys(map);
63
+ types.forEach((type) => Object.keys(map[type]).forEach((method) => {
64
+ var _a;
65
+ const mapHooks = map[type][method];
66
+ const storeHooks = ((_a = store[type])[method] || (_a[method] = []));
67
+ storeHooks.push(...mapHooks);
68
+ if (method === 'all') {
69
+ if (store.before[method] || store.error[method]) {
70
+ const beforeAll = (0, hooks_1.collect)({
71
+ before: store.before[method] || [],
72
+ error: store.error[method] || []
73
+ });
74
+ store.collectedAll.before = [beforeAll];
75
+ }
76
+ if (store.after[method]) {
77
+ const afterAll = (0, hooks_1.collect)({
78
+ after: store.after[method] || []
79
+ });
80
+ store.collectedAll.after = [afterAll];
81
+ }
82
+ }
83
+ else {
84
+ if (store.before[method] || store.after[method] || store.error[method]) {
85
+ const collected = (0, hooks_1.collect)({
86
+ before: store.before[method] || [],
87
+ after: store.after[method] || [],
88
+ error: store.error[method] || []
89
+ });
90
+ store.collected[method] = [collected];
91
+ }
92
+ }
93
+ }));
94
+ return this;
95
+ };
96
+ }
97
+ exports.enableHooks = enableHooks;
98
+ function createContext(service, method, data = {}) {
99
+ const createContext = service[method].createContext;
100
+ if (typeof createContext !== 'function') {
101
+ throw new Error(`Can not create context for method ${method}`);
102
+ }
103
+ return createContext(data);
104
+ }
105
+ exports.createContext = createContext;
106
+ class FeathersHookManager extends hooks_1.HookManager {
107
+ constructor(app, method) {
108
+ super();
109
+ this.app = app;
110
+ this.method = method;
111
+ this._middleware = [];
112
+ }
113
+ collectMiddleware(self, args) {
114
+ const appHooks = collectHooks(this.app, this.method);
115
+ const middleware = super.collectMiddleware(self, args);
116
+ const methodHooks = collectHooks(self, this.method);
117
+ return [...appHooks, ...middleware, ...methodHooks];
118
+ }
119
+ initializeContext(self, args, context) {
120
+ const ctx = super.initializeContext(self, args, context);
121
+ ctx.params = ctx.params || {};
122
+ return ctx;
123
+ }
124
+ middleware(mw) {
125
+ this._middleware.push(...mw);
126
+ return this;
127
+ }
128
+ }
129
+ exports.FeathersHookManager = FeathersHookManager;
130
+ function hookMixin(service, path, options) {
131
+ if (typeof service.hooks === 'function') {
132
+ return service;
133
+ }
134
+ const hookMethods = (0, service_1.getHookMethods)(service, options);
135
+ const serviceMethodHooks = hookMethods.reduce((res, method) => {
136
+ const params = service_1.defaultServiceArguments[method] || ['data', 'params'];
137
+ res[method] = new FeathersHookManager(this, method).params(...params).props({
138
+ app: this,
139
+ path,
140
+ method,
141
+ service,
142
+ event: null,
143
+ type: 'around',
144
+ get statusCode() {
145
+ var _a;
146
+ return (_a = this.http) === null || _a === void 0 ? void 0 : _a.status;
147
+ },
148
+ set statusCode(value) {
149
+ this.http = this.http || {};
150
+ this.http.status = value;
151
+ }
152
+ });
153
+ return res;
154
+ }, {});
155
+ const registerHooks = enableHooks(service);
156
+ (0, hooks_1.hooks)(service, serviceMethodHooks);
157
+ service.hooks = function (hookOptions) {
158
+ if (hookOptions.before || hookOptions.after || hookOptions.error || hookOptions.around) {
159
+ return registerHooks.call(this, hookOptions);
160
+ }
161
+ if (Array.isArray(hookOptions)) {
162
+ return (0, hooks_1.hooks)(this, hookOptions);
163
+ }
164
+ Object.keys(hookOptions).forEach((method) => {
165
+ const manager = (0, hooks_1.getManager)(this[method]);
166
+ if (!(manager instanceof FeathersHookManager)) {
167
+ throw new Error(`Method ${method} is not a Feathers hooks enabled service method`);
168
+ }
169
+ manager.middleware(hookOptions[method]);
170
+ });
171
+ return this;
172
+ };
173
+ return service;
174
+ }
175
+ exports.hookMixin = hookMixin;
176
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;AAAA,6CAQ0B;AAW1B,uCAAmE;AAenE,MAAM,KAAK,GAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;AAEhE,MAAM,MAAM,GAAG,CAAC,KAAU,EAAqB,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,KA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AAW,CAAC,MAAM,EAAE;YACtF,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;SAC7C;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAC9B,OAAO,IAAA,aAAK,EAAC,IAAI,EAAE,WAAW,CAAC,CAAA;SAChC;QAED,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1C,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;YAExC,IAAI,CAAC,CAAC,OAAO,YAAY,mBAAmB,CAAC,EAAE;gBAC7C,MAAM,IAAI,KAAK,CAAC,UAAU,MAAM,iDAAiD,CAAC,CAAA;aACnF;YAED,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAxDD,8BAwDC"}
package/lib/index.d.ts CHANGED
@@ -3,9 +3,9 @@ import { Feathers } from './application';
3
3
  import { Application } from './declarations';
4
4
  export declare function feathers<T = any, S = any>(): Application<T, S>;
5
5
  export declare namespace feathers {
6
- var setDebug: typeof import("@feathersjs/commons/lib/debug").setDebug;
6
+ var setDebug: typeof import("@feathersjs/commons").setDebug;
7
7
  }
8
8
  export { version, Feathers };
9
- export * from './hooks/index';
9
+ export * from './hooks';
10
10
  export * from './declarations';
11
11
  export * from './service';
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -14,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
18
  };
15
19
  Object.defineProperty(exports, "__esModule", { value: true });
16
20
  exports.Feathers = exports.version = exports.feathers = void 0;
17
- const dependencies_1 = require("./dependencies");
21
+ const commons_1 = require("@feathersjs/commons");
18
22
  const version_1 = __importDefault(require("./version"));
19
23
  exports.version = version_1.default;
20
24
  const application_1 = require("./application");
@@ -23,8 +27,8 @@ function feathers() {
23
27
  return new application_1.Feathers();
24
28
  }
25
29
  exports.feathers = feathers;
26
- feathers.setDebug = dependencies_1.setDebug;
27
- __exportStar(require("./hooks/index"), exports);
30
+ feathers.setDebug = commons_1.setDebug;
31
+ __exportStar(require("./hooks"), exports);
28
32
  __exportStar(require("./declarations"), exports);
29
33
  __exportStar(require("./service"), exports);
30
34
  if (typeof module !== 'undefined') {
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA0C;AAC1C,wDAAgC;AAUvB,kBAVF,iBAAO,CAUE;AAThB,+CAAyC;AASvB,yFATT,sBAAQ,OASS;AAN1B,SAAgB,QAAQ;IACtB,OAAO,IAAI,sBAAQ,EAA6B,CAAC;AACnD,CAAC;AAFD,4BAEC;AAED,QAAQ,CAAC,QAAQ,GAAG,uBAAQ,CAAC;AAG7B,gDAA8B;AAC9B,iDAA+B;AAC/B,4CAA0B;AAE1B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CAC1D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,iDAA8C;AAE9C,wDAA+B;AAUtB,kBAVF,iBAAO,CAUE;AAThB,+CAAwC;AAStB,yFATT,sBAAQ,OASS;AAN1B,SAAgB,QAAQ;IACtB,OAAO,IAAI,sBAAQ,EAA6B,CAAA;AAClD,CAAC;AAFD,4BAEC;AAED,QAAQ,CAAC,QAAQ,GAAG,kBAAQ,CAAA;AAG5B,0CAAuB;AACvB,iDAA8B;AAC9B,4CAAyB;AAEzB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;CACzD"}
package/lib/service.d.ts CHANGED
@@ -15,7 +15,9 @@ export declare const defaultEventMap: {
15
15
  patch: string;
16
16
  remove: string;
17
17
  };
18
+ export declare const defaultServiceEvents: string[];
18
19
  export declare const protectedMethods: string[];
19
20
  export declare function getHookMethods(service: any, options: ServiceOptions): string[];
20
- export declare function getServiceOptions(service: any, options?: ServiceOptions): ServiceOptions;
21
+ export declare function getServiceOptions(service: any): ServiceOptions;
22
+ export declare const normalizeServiceOptions: (service: any, options?: ServiceOptions) => ServiceOptions;
21
23
  export declare function wrapService(location: string, service: any, options: ServiceOptions): any;
package/lib/service.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapService = exports.getServiceOptions = exports.getHookMethods = exports.protectedMethods = exports.defaultEventMap = exports.defaultServiceMethods = exports.defaultServiceArguments = exports.SERVICE = void 0;
4
- const dependencies_1 = require("./dependencies");
5
- exports.SERVICE = dependencies_1.createSymbol('@feathersjs/service');
3
+ exports.wrapService = exports.normalizeServiceOptions = exports.getServiceOptions = exports.getHookMethods = exports.protectedMethods = exports.defaultServiceEvents = exports.defaultEventMap = exports.defaultServiceMethods = exports.defaultServiceArguments = exports.SERVICE = void 0;
4
+ const events_1 = require("events");
5
+ const commons_1 = require("@feathersjs/commons");
6
+ exports.SERVICE = (0, commons_1.createSymbol)('@feathersjs/service');
6
7
  exports.defaultServiceArguments = {
7
8
  find: ['params'],
8
9
  get: ['id', 'params'],
@@ -11,48 +12,48 @@ exports.defaultServiceArguments = {
11
12
  patch: ['id', 'data', 'params'],
12
13
  remove: ['id', 'params']
13
14
  };
14
- exports.defaultServiceMethods = Object.keys(exports.defaultServiceArguments);
15
+ exports.defaultServiceMethods = ['find', 'get', 'create', 'update', 'patch', 'remove'];
15
16
  exports.defaultEventMap = {
16
17
  create: 'created',
17
18
  update: 'updated',
18
19
  patch: 'patched',
19
20
  remove: 'removed'
20
21
  };
22
+ exports.defaultServiceEvents = Object.values(exports.defaultEventMap);
21
23
  exports.protectedMethods = Object.keys(Object.prototype)
22
- .concat(Object.keys(dependencies_1.EventEmitter.prototype))
23
- .concat([
24
- 'before',
25
- 'after',
26
- 'error',
27
- 'hooks',
28
- 'setup',
29
- 'publish'
30
- ]);
24
+ .concat(Object.keys(events_1.EventEmitter.prototype))
25
+ .concat(['all', 'around', 'before', 'after', 'error', 'hooks', 'setup', 'teardown', 'publish']);
31
26
  function getHookMethods(service, options) {
32
27
  const { methods } = options;
33
- return exports.defaultServiceMethods.filter(m => typeof service[m] === 'function' && !methods.includes(m)).concat(methods);
28
+ return exports.defaultServiceMethods
29
+ .filter((m) => typeof service[m] === 'function' && !methods.includes(m))
30
+ .concat(methods);
34
31
  }
35
32
  exports.getHookMethods = getHookMethods;
36
- function getServiceOptions(service, options = {}) {
37
- const existingOptions = service[exports.SERVICE];
38
- if (existingOptions) {
39
- return existingOptions;
40
- }
41
- const { methods = exports.defaultServiceMethods.filter(method => typeof service[method] === 'function'), events = service.events || [] } = options;
42
- const { serviceEvents = Object.values(exports.defaultEventMap).concat(events) } = options;
43
- return Object.assign(Object.assign({}, options), { events,
44
- methods,
45
- serviceEvents });
33
+ function getServiceOptions(service) {
34
+ return service[exports.SERVICE];
46
35
  }
47
36
  exports.getServiceOptions = getServiceOptions;
37
+ const normalizeServiceOptions = (service, options = {}) => {
38
+ const { methods = exports.defaultServiceMethods.filter((method) => typeof service[method] === 'function'), events = service.events || [] } = options;
39
+ const serviceEvents = options.serviceEvents || exports.defaultServiceEvents.concat(events);
40
+ return {
41
+ ...options,
42
+ events,
43
+ methods,
44
+ serviceEvents
45
+ };
46
+ };
47
+ exports.normalizeServiceOptions = normalizeServiceOptions;
48
48
  function wrapService(location, service, options) {
49
49
  // Do nothing if this is already an initialized
50
50
  if (service[exports.SERVICE]) {
51
51
  return service;
52
52
  }
53
53
  const protoService = Object.create(service);
54
- const serviceOptions = getServiceOptions(service, options);
55
- if (Object.keys(serviceOptions.methods).length === 0 && typeof service.setup !== 'function') {
54
+ const serviceOptions = (0, exports.normalizeServiceOptions)(service, options);
55
+ if (Object.keys(serviceOptions.methods).length === 0 &&
56
+ ![...exports.defaultServiceMethods, 'setup', 'teardown'].some((method) => typeof service[method] === 'function')) {
56
57
  throw new Error(`Invalid service object passed for path \`${location}\``);
57
58
  }
58
59
  Object.defineProperty(protoService, exports.SERVICE, {
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;AAAA,iDAA4D;AAG/C,QAAA,OAAO,GAAG,2BAAY,CAAC,qBAAqB,CAAC,CAAC;AAE9C,QAAA,uBAAuB,GAAG;IACrC,IAAI,EAAE,CAAE,QAAQ,CAAE;IAClB,GAAG,EAAE,CAAE,IAAI,EAAE,QAAQ,CAAE;IACvB,MAAM,EAAE,CAAE,MAAM,EAAE,QAAQ,CAAE;IAC5B,MAAM,EAAE,CAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAE;IAClC,KAAK,EAAE,CAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAE;IACjC,MAAM,EAAE,CAAE,IAAI,EAAE,QAAQ,CAAE;CAC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O,OAAO,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,EACzF,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,EAC9B,GAAG,OAAO,CAAA;IACX,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,4BAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAElF,OAAO;QACL,GAAG,OAAO;QACV,MAAM;QACN,OAAO;QACP,aAAa;KACd,CAAA;AACH,CAAC,CAAA;AAbY,QAAA,uBAAuB,2BAanC;AAED,SAAgB,WAAW,CAAC,QAAgB,EAAE,OAAY,EAAE,OAAuB;IACjF,+CAA+C;IAC/C,IAAI,OAAO,CAAC,eAAO,CAAC,EAAE;QACpB,OAAO,OAAO,CAAA;KACf;IAED,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,cAAc,GAAG,IAAA,+BAAuB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAEhE,IACE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC;QAChD,CAAC,CAAC,GAAG,6BAAqB,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,EACxG;QACA,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,IAAI,CAAC,CAAA;KAC1E;IAED,MAAM,CAAC,cAAc,CAAC,YAAY,EAAE,eAAO,EAAE;QAC3C,KAAK,EAAE,cAAc;KACtB,CAAC,CAAA;IAEF,OAAO,YAAY,CAAA;AACrB,CAAC;AArBD,kCAqBC"}
package/lib/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "5.0.0-pre.9";
1
+ declare const _default: "5.0.0";
2
2
  export default _default;
package/lib/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '5.0.0-pre.9';
3
+ exports.default = '5.0.0';
4
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,OAAO,CAAA"}
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@feathersjs/feathers",
3
3
  "description": "A framework for real-time applications and REST API with JavaScript and TypeScript",
4
- "version": "5.0.0-pre.9",
4
+ "version": "5.0.0",
5
5
  "homepage": "http://feathersjs.com",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git://github.com/feathersjs/feathers.git"
8
+ "url": "git://github.com/feathersjs/feathers.git",
9
+ "directory": "packages/feathers"
9
10
  },
10
11
  "keywords": [
11
12
  "feathers",
@@ -41,14 +42,14 @@
41
42
  "*.js"
42
43
  ],
43
44
  "scripts": {
44
- "write-version": "node -e \"console.log('export default \\'' + require('./package.json').version + '\\';')\" > src/version.ts",
45
- "reset-version": "node -e \"console.log('export default \\'development\\';')\" > src/version.ts",
45
+ "write-version": "node -e \"console.log('export default \\'' + require('./package.json').version + '\\'')\" > src/version.ts",
46
+ "reset-version": "node -e \"console.log('export default \\'development\\'')\" > src/version.ts",
46
47
  "prepublish": "npm run compile",
47
48
  "version": "npm run write-version",
48
49
  "publish": "npm run reset-version",
49
- "compile": "shx rm -rf lib/ && tsc",
50
- "test": "npm run compile && npm run mocha",
51
- "mocha": "mocha --config ../../.mocharc.json --recursive test/"
50
+ "pack": "npm pack --pack-destination ../generators/test/build",
51
+ "compile": "shx rm -rf lib/ && tsc && npm run pack",
52
+ "test": "mocha --config ../../.mocharc.json --recursive test/"
52
53
  },
53
54
  "engines": {
54
55
  "node": ">= 12"
@@ -57,17 +58,17 @@
57
58
  "access": "public"
58
59
  },
59
60
  "dependencies": {
60
- "@feathersjs/commons": "^5.0.0-pre.9",
61
- "@feathersjs/hooks": "^0.6.5",
61
+ "@feathersjs/commons": "^5.0.0",
62
+ "@feathersjs/hooks": "^0.8.1",
62
63
  "events": "^3.3.0"
63
64
  },
64
65
  "devDependencies": {
65
- "@types/mocha": "^9.0.0",
66
- "@types/node": "^16.4.13",
67
- "mocha": "^9.0.3",
68
- "shx": "^0.3.3",
69
- "ts-node": "^10.1.0",
70
- "typescript": "^4.3.5"
66
+ "@types/mocha": "^10.0.1",
67
+ "@types/node": "^18.14.1",
68
+ "mocha": "^10.2.0",
69
+ "shx": "^0.3.4",
70
+ "ts-node": "^10.9.1",
71
+ "typescript": "^4.9.5"
71
72
  },
72
- "gitHead": "3d1721a7286e6a7f37bbc38695fe45084023f13b"
73
+ "gitHead": "90caf635aec850550b9d37bea2762af959d9e8d5"
73
74
  }