@feathersjs/feathers 5.0.0-pre.20 → 5.0.0-pre.23

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.
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;AAAA,iDAA4D;AAG/C,QAAA,OAAO,GAAG,IAAA,2BAAY,EAAC,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;CAC3B,CAAA;AAEY,QAAA,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAC,+BAAuB,CAAC,CAAC;AAE7D,QAAA,eAAe,GAAG;IAC7B,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;CAClB,CAAA;AAEY,QAAA,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;KAC1D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,2BAAY,CAAC,SAAS,CAAC,CAAC;KAC3C,MAAM,CAAC;IACN,KAAK;IACL,QAAQ;IACR,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,UAAU;IACV,SAAS;CACV,CAAC,CAAC;AAEL,SAAgB,cAAc,CAAE,OAAY,EAAE,OAAuB;IACnE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAE5B,OAAO,6BAAqB,CAAC,M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AC,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,UAAU,EAAE;QAC3F,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;AAlBD,kCAkBC"}
package/lib/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "5.0.0-pre.20";
1
+ declare const _default: "5.0.0-pre.23";
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.20';
3
+ exports.default = '5.0.0-pre.23';
4
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
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.20",
4
+ "version": "5.0.0-pre.23",
5
5
  "homepage": "http://feathersjs.com",
6
6
  "repository": {
7
7
  "type": "git",
@@ -57,17 +57,17 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "@feathersjs/commons": "^5.0.0-pre.20",
61
- "@feathersjs/hooks": "^0.7.4",
60
+ "@feathersjs/commons": "^5.0.0-pre.23",
61
+ "@feathersjs/hooks": "^0.7.5",
62
62
  "events": "^3.3.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/mocha": "^9.1.1",
66
- "@types/node": "^17.0.31",
66
+ "@types/node": "^17.0.40",
67
67
  "mocha": "^10.0.0",
68
68
  "shx": "^0.3.4",
69
- "ts-node": "^10.7.0",
70
- "typescript": "^4.6.4"
69
+ "ts-node": "^10.8.1",
70
+ "typescript": "^4.7.3"
71
71
  },
72
- "gitHead": "54de749a0b392c7da726c668002b50cafaca530c"
72
+ "gitHead": "a60910bd730b88053ca6648337095f1ca1e3b39f"
73
73
  }
@@ -1,10 +1,10 @@
1
- import version from './version';
2
- import {
3
- EventEmitter, stripSlashes, createDebug, HOOKS, hooks, middleware
4
- } from './dependencies';
5
- import { eventHook, eventMixin } from './events';
6
- import { hookMixin } from './hooks/index';
7
- import { wrapService, getServiceOptions, protectedMethods } from './service';
1
+ import version from './version'
2
+ import { EventEmitter } from 'events'
3
+ import { stripSlashes, createDebug } from '@feathersjs/commons'
4
+ import { hooks, middleware } from '@feathersjs/hooks'
5
+ import { eventHook, eventMixin } from './events'
6
+ import { hookMixin } from './hooks'
7
+ import { wrapService, getServiceOptions, protectedMethods } from './service'
8
8
  import {
9
9
  FeathersApplication,
10
10
  ServiceMixin,
@@ -13,28 +13,26 @@ import {
13
13
  ServiceInterface,
14
14
  Application,
15
15
  FeathersService,
16
- HookMap,
17
16
  ApplicationHookOptions
18
- } from './declarations';
19
- import { enableRegularHooks } from './hooks/regular';
20
-
21
- const debug = createDebug('@feathersjs/feathers');
22
-
23
- export class Feathers<Services, Settings> extends EventEmitter implements FeathersApplication<Services, Settings> {
24
- services: Services = ({} as Services);
25
- settings: Settings = ({} as Settings);
26
- mixins: ServiceMixin<Application<Services, Settings>>[] = [ hookMixin, eventMixin ];
27
- version: string = version;
28
- _isSetup = false;
29
- appHooks: HookMap<Application<Services, Settings>, any> = {
30
- [HOOKS]: [ (eventHook as any) ]
31
- };
32
-
33
- private regularHooks: (this: any, allHooks: any) => any;
34
-
35
- constructor () {
36
- super();
37
- this.regularHooks = enableRegularHooks(this);
17
+ } from './declarations'
18
+ import { enableHooks } from './hooks'
19
+
20
+ const debug = createDebug('@feathersjs/feathers')
21
+
22
+ export class Feathers<Services, Settings>
23
+ extends EventEmitter
24
+ implements FeathersApplication<Services, Settings>
25
+ {
26
+ services: Services = {} as Services
27
+ settings: Settings = {} as Settings
28
+ mixins: ServiceMixin<Application<Services, Settings>>[] = [hookMixin, eventMixin]
29
+ version: string = version
30
+ _isSetup = false
31
+
32
+ protected registerHooks: (this: any, allHooks: any) => any
33
+
34
+ constructor() {
35
+ super()
38
36
  hooks(this, {
39
37
  setup: middleware().params('server').props({
40
38
  app: this
@@ -42,137 +40,148 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe
42
40
  teardown: middleware().params('server').props({
43
41
  app: this
44
42
  })
45
- });
43
+ })
44
+ this.registerHooks = enableHooks(this)
45
+ this.registerHooks({
46
+ around: [eventHook]
47
+ })
46
48
  }
47
49
 
48
- get<L extends keyof Settings & string> (name: L): Settings[L] {
49
- return this.settings[name];
50
+ get<L extends keyof Settings & string>(name: L): Settings[L] {
51
+ return this.settings[name]
50
52
  }
51
53
 
52
- set<L extends keyof Settings & string> (name: L, value: Settings[L]) {
53
- this.settings[name] = value;
54
- return this;
54
+ set<L extends keyof Settings & string>(name: L, value: Settings[L]) {
55
+ this.settings[name] = value
56
+ return this
55
57
  }
56
58
 
57
- configure (callback: (this: this, app: this) => void) {
58
- callback.call(this, this);
59
+ configure(callback: (this: this, app: this) => void) {
60
+ callback.call(this, this)
59
61
 
60
- return this;
62
+ return this
61
63
  }
62
64
 
63
- defaultService (location: string): ServiceInterface {
64
- throw new Error(`Can not find service '${location}'`);
65
+ defaultService(location: string): ServiceInterface {
66
+ throw new Error(`Can not find service '${location}'`)
65
67
  }
66
68
 
67
- service<L extends keyof Services & string> (
69
+ service<L extends keyof Services & string>(
68
70
  location: L
69
71
  ): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]> {
70
- const path = (stripSlashes(location) || '/') as L;
71
- const current = this.services[path];
72
+ const path = (stripSlashes(location) || '/') as L
73
+ const current = this.services[path]
72
74
 
73
75
  if (typeof current === 'undefined') {
74
- this.use(path, this.defaultService(path) as any);
75
- return this.service(path);
76
+ this.use(path, this.defaultService(path) as any)
77
+ return this.service(path)
76
78
  }
77
79
 
78
- return current as any;
80
+ return current as any
79
81
  }
80
82
 
81
- use<L extends keyof Services & string> (
83
+ use<L extends keyof Services & string>(
82
84
  path: L,
83
85
  service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L],
84
86
  options?: ServiceOptions
85
87
  ): this {
86
88
  if (typeof path !== 'string') {
87
- throw new Error(`'${path}' is not a valid service path.`);
89
+ throw new Error(`'${path}' is not a valid service path.`)
88
90
  }
89
91
 
90
- const location = (stripSlashes(path) || '/') as L;
91
- const subApp = service as Application;
92
- const isSubApp = typeof subApp.service === 'function' && subApp.services;
92
+ const location = (stripSlashes(path) || '/') as L
93
+ const subApp = service as Application
94
+ const isSubApp = typeof subApp.service === 'function' && subApp.services
93
95
 
94
96
  if (isSubApp) {
95
- Object.keys(subApp.services).forEach(subPath =>
97
+ Object.keys(subApp.services).forEach((subPath) =>
96
98
  this.use(`${location}/${subPath}` as any, subApp.service(subPath) as any)
97
- );
99
+ )
98
100
 
99
- return this;
101
+ return this
100
102
  }
101
103
 
102
- const protoService = wrapService(location, service, options);
103
- const serviceOptions = getServiceOptions(protoService);
104
+ const protoService = wrapService(location, service, options)
105
+ const serviceOptions = getServiceOptions(protoService)
104
106
 
105
107
  for (const name of protectedMethods) {
106
108
  if (serviceOptions.methods.includes(name)) {
107
- throw new Error(`'${name}' on service '${location}' is not allowed as a custom method name`);
109
+ throw new Error(`'${name}' on service '${location}' is not allowed as a custom method name`)
108
110
  }
109
111
  }
110
112
 
111
- debug(`Registering new service at \`${location}\``);
113
+ debug(`Registering new service at \`${location}\``)
112
114
 
113
115
  // Add all the mixins
114
- this.mixins.forEach(fn => fn.call(this, protoService, location, serviceOptions));
116
+ this.mixins.forEach((fn) => fn.call(this, protoService, location, serviceOptions))
115
117
 
116
- this.services[location] = protoService;
118
+ this.services[location] = protoService
117
119
 
118
120
  // If we ran setup already, set this service up explicitly, this will not `await`
119
121
  if (this._isSetup && typeof protoService.setup === 'function') {
120
- debug(`Setting up service for \`${location}\``);
121
- protoService.setup(this, location);
122
+ debug(`Setting up service for \`${location}\``)
123
+ protoService.setup(this, location)
122
124
  }
123
125
 
124
- return this;
126
+ return this
125
127
  }
126
128
 
127
- hooks (hookMap: ApplicationHookOptions<this>) {
128
- const untypedMap = hookMap as any;
129
+ hooks(hookMap: ApplicationHookOptions<this>) {
130
+ const untypedMap = hookMap as any
129
131
 
130
- if (untypedMap.before || untypedMap.after || untypedMap.error) {
131
- this.regularHooks(untypedMap);
132
+ if (untypedMap.before || untypedMap.after || untypedMap.error || untypedMap.around) {
133
+ // regular hooks for all service methods
134
+ this.registerHooks(untypedMap)
132
135
  } else if (untypedMap.setup || untypedMap.teardown) {
133
- hooks(this, untypedMap);
134
- } else if (Array.isArray(hookMap)) {
135
- this.appHooks[HOOKS].push(...hookMap as any);
136
+ // .setup and .teardown application hooks
137
+ hooks(this, untypedMap)
136
138
  } else {
137
- const methodHookMap = hookMap as HookMap<Application<Services, Settings>, any>;
138
-
139
- Object.keys(methodHookMap).forEach(key => {
140
- const methodHooks = this.appHooks[key] || [];
141
-
142
- this.appHooks[key] = methodHooks.concat(methodHookMap[key]);
143
- });
139
+ // Other registration formats are just `around` hooks
140
+ this.registerHooks({
141
+ around: untypedMap
142
+ })
144
143
  }
145
144
 
146
- return this;
145
+ return this
147
146
  }
148
147
 
149
- setup () {
150
- this._isSetup = true;
148
+ setup() {
149
+ this._isSetup = true
151
150
 
152
- return Object.keys(this.services).reduce((current, path) => current
153
- .then(() => {
154
- const service: any = this.service(path as any);
151
+ return Object.keys(this.services)
152
+ .reduce(
153
+ (current, path) =>
154
+ current.then(() => {
155
+ const service: any = this.service(path as any)
155
156
 
156
- if (typeof service.setup === 'function') {
157
- debug(`Setting up service for \`${path}\``);
157
+ if (typeof service.setup === 'function') {
158
+ debug(`Setting up service for \`${path}\``)
158
159
 
159
- return service.setup(this, path);
160
- }
161
- }), Promise.resolve()).then(() => this);
160
+ return service.setup(this, path)
161
+ }
162
+ }),
163
+ Promise.resolve()
164
+ )
165
+ .then(() => this)
162
166
  }
163
167
 
164
- teardown () {
165
- this._isSetup = false;
168
+ teardown() {
169
+ this._isSetup = false
166
170
 
167
- return Object.keys(this.services).reduce((current, path) => current
168
- .then(() => {
169
- const service: any = this.service(path as any);
171
+ return Object.keys(this.services)
172
+ .reduce(
173
+ (current, path) =>
174
+ current.then(() => {
175
+ const service: any = this.service(path as any)
170
176
 
171
- if (typeof service.teardown === 'function') {
172
- debug(`Tearing down service for \`${path}\``);
177
+ if (typeof service.teardown === 'function') {
178
+ debug(`Tearing down service for \`${path}\``)
173
179
 
174
- return service.teardown(this, path);
175
- }
176
- }), Promise.resolve()).then(() => this)
180
+ return service.teardown(this, path)
181
+ }
182
+ }),
183
+ Promise.resolve()
184
+ )
185
+ .then(() => this)
177
186
  }
178
187
  }