@feathersjs/feathers 5.0.37 → 6.0.0-pre.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/service.js DELETED
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeServiceOptions = exports.protectedMethods = exports.defaultServiceEvents = exports.defaultEventMap = exports.defaultServiceMethods = exports.defaultServiceArguments = exports.SERVICE = void 0;
4
- exports.getHookMethods = getHookMethods;
5
- exports.getServiceOptions = getServiceOptions;
6
- exports.wrapService = wrapService;
7
- const events_1 = require("events");
8
- const commons_1 = require("@feathersjs/commons");
9
- exports.SERVICE = (0, commons_1.createSymbol)('@feathersjs/service');
10
- exports.defaultServiceArguments = {
11
- find: ['params'],
12
- get: ['id', 'params'],
13
- create: ['data', 'params'],
14
- update: ['id', 'data', 'params'],
15
- patch: ['id', 'data', 'params'],
16
- remove: ['id', 'params']
17
- };
18
- exports.defaultServiceMethods = ['find', 'get', 'create', 'update', 'patch', 'remove'];
19
- exports.defaultEventMap = {
20
- create: 'created',
21
- update: 'updated',
22
- patch: 'patched',
23
- remove: 'removed'
24
- };
25
- exports.defaultServiceEvents = Object.values(exports.defaultEventMap);
26
- exports.protectedMethods = Object.keys(Object.prototype)
27
- .concat(Object.keys(events_1.EventEmitter.prototype))
28
- .concat(['all', 'around', 'before', 'after', 'error', 'hooks', 'setup', 'teardown', 'publish']);
29
- function getHookMethods(service, options) {
30
- const { methods } = options;
31
- return exports.defaultServiceMethods
32
- .filter((m) => typeof service[m] === 'function' && !methods.includes(m))
33
- .concat(methods);
34
- }
35
- function getServiceOptions(service) {
36
- return service[exports.SERVICE];
37
- }
38
- const normalizeServiceOptions = (service, options = {}) => {
39
- const { methods = exports.defaultServiceMethods.filter((method) => typeof service[method] === 'function'), events = service.events || [] } = options;
40
- const serviceEvents = options.serviceEvents || exports.defaultServiceEvents.concat(events);
41
- return {
42
- ...options,
43
- events,
44
- methods,
45
- serviceEvents
46
- };
47
- };
48
- exports.normalizeServiceOptions = normalizeServiceOptions;
49
- function wrapService(location, service, options) {
50
- // Do nothing if this is already an initialized
51
- if (service[exports.SERVICE]) {
52
- return service;
53
- }
54
- const protoService = Object.create(service);
55
- const serviceOptions = (0, exports.normalizeServiceOptions)(service, options);
56
- if (Object.keys(serviceOptions.methods).length === 0 &&
57
- ![...exports.defaultServiceMethods, 'setup', 'teardown'].some((method) => typeof service[method] === 'function')) {
58
- throw new Error(`Invalid service object passed for path \`${location}\``);
59
- }
60
- Object.defineProperty(protoService, exports.SERVICE, {
61
- value: serviceOptions
62
- });
63
- return protoService;
64
- }
65
- //# sourceMappingURL=service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;AA6BA,wCAMC;AAED,8CAEC;AAiBD,kCAqBC;AA7ED,mCAAqC;AACrC,iDAAkD;AAGrC,QAAA,OAAO,GAAG,IAAA,sBAAY,EAAC,qBAAqB,CAAC,CAAA;AAE7C,QAAA,uBAAuB,GAAG;IACrC,IAAI,EAAE,CAAC,QAAQ,CAAC;IAChB,GAAG,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC;IACrB,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC;IAChC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC;CACzB,CAAA;AACY,QAAA,qBAAqB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;AAE9E,QAAA,eAAe,GAAG;IAC7B,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,SAAS;IAChB,MAAM,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;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,CAAC;QACrB,OAAO,OAAO,CAAA;IAChB,CAAC;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,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,IAAI,CAAC,CAAA;IAC3E,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,YAAY,EAAE,eAAO,EAAE;QAC3C,KAAK,EAAE,cAAc;KACtB,CAAC,CAAA;IAEF,OAAO,YAAY,CAAA;AACrB,CAAC"}
package/lib/version.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const _default: "5.0.37";
2
- export default _default;
package/lib/version.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '5.0.37';
4
- //# sourceMappingURL=version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,QAAQ,CAAA"}
@@ -1,224 +0,0 @@
1
- import version from './version'
2
- import { EventEmitter } from 'events'
3
- import { stripSlashes, createDebug } from '@feathersjs/commons'
4
- import { HOOKS, hooks, middleware } from '@feathersjs/hooks'
5
- import { eventHook, eventMixin } from './events'
6
- import { hookMixin } from './hooks'
7
- import { wrapService, getServiceOptions, protectedMethods } from './service'
8
- import {
9
- FeathersApplication,
10
- ServiceMixin,
11
- Service,
12
- ServiceOptions,
13
- ServiceInterface,
14
- Application,
15
- FeathersService,
16
- ApplicationHookOptions
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()
36
- this.registerHooks = enableHooks(this)
37
- this.registerHooks({
38
- around: [eventHook]
39
- })
40
- }
41
-
42
- get<L extends keyof Settings & string>(name: L): Settings[L] {
43
- return this.settings[name]
44
- }
45
-
46
- set<L extends keyof Settings & string>(name: L, value: Settings[L]) {
47
- this.settings[name] = value
48
- return this
49
- }
50
-
51
- configure(callback: (this: this, app: this) => void) {
52
- callback.call(this, this)
53
-
54
- return this
55
- }
56
-
57
- defaultService(location: string): ServiceInterface {
58
- throw new Error(`Can not find service '${location}'`)
59
- }
60
-
61
- service<L extends keyof Services & string>(
62
- location: L
63
- ): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]> {
64
- const path = (stripSlashes(location) || '/') as L
65
- const current = this.services.hasOwnProperty(path) ? this.services[path] : undefined
66
-
67
- if (typeof current === 'undefined') {
68
- this.use(path, this.defaultService(path) as any)
69
- return this.service(path)
70
- }
71
-
72
- return current as any
73
- }
74
-
75
- protected _setup() {
76
- this._isSetup = true
77
-
78
- return Object.keys(this.services)
79
- .reduce(
80
- (current, path) =>
81
- current.then(() => {
82
- const service: any = this.service(path as any)
83
-
84
- if (typeof service.setup === 'function') {
85
- debug(`Setting up service for \`${path}\``)
86
-
87
- return service.setup(this, path)
88
- }
89
- }),
90
- Promise.resolve()
91
- )
92
- .then(() => this)
93
- }
94
-
95
- get setup() {
96
- return this._setup
97
- }
98
-
99
- set setup(value) {
100
- this._setup = (value as any)[HOOKS]
101
- ? value
102
- : hooks(
103
- value,
104
- middleware().params('server').props({
105
- app: this
106
- })
107
- )
108
- }
109
-
110
- protected _teardown() {
111
- this._isSetup = false
112
-
113
- return Object.keys(this.services)
114
- .reduce(
115
- (current, path) =>
116
- current.then(() => {
117
- const service: any = this.service(path as any)
118
-
119
- if (typeof service.teardown === 'function') {
120
- debug(`Tearing down service for \`${path}\``)
121
-
122
- return service.teardown(this, path)
123
- }
124
- }),
125
- Promise.resolve()
126
- )
127
- .then(() => this)
128
- }
129
-
130
- get teardown() {
131
- return this._teardown
132
- }
133
-
134
- set teardown(value) {
135
- this._teardown = (value as any)[HOOKS]
136
- ? value
137
- : hooks(
138
- value,
139
- middleware().params('server').props({
140
- app: this
141
- })
142
- )
143
- }
144
-
145
- use<L extends keyof Services & string>(
146
- path: L,
147
- service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L],
148
- options?: ServiceOptions<keyof any extends keyof Services ? string : keyof Services[L]>
149
- ): this {
150
- if (typeof path !== 'string') {
151
- throw new Error(`'${path}' is not a valid service path.`)
152
- }
153
-
154
- const location = (stripSlashes(path) || '/') as L
155
- const subApp = service as Application
156
- const isSubApp = typeof subApp.service === 'function' && subApp.services
157
-
158
- if (isSubApp) {
159
- Object.keys(subApp.services).forEach((subPath) =>
160
- this.use(`${location}/${subPath}` as any, subApp.service(subPath) as any)
161
- )
162
-
163
- return this
164
- }
165
-
166
- const protoService = wrapService(location, service, options as ServiceOptions)
167
- const serviceOptions = getServiceOptions(protoService)
168
-
169
- for (const name of protectedMethods) {
170
- if (serviceOptions.methods.includes(name)) {
171
- throw new Error(`'${name}' on service '${location}' is not allowed as a custom method name`)
172
- }
173
- }
174
-
175
- debug(`Registering new service at \`${location}\``)
176
-
177
- // Add all the mixins
178
- this.mixins.forEach((fn) => fn.call(this, protoService, location, serviceOptions))
179
-
180
- this.services[location] = protoService
181
-
182
- // If we ran setup already, set this service up explicitly, this will not `await`
183
- if (this._isSetup && typeof protoService.setup === 'function') {
184
- debug(`Setting up service for \`${location}\``)
185
- protoService.setup(this, location)
186
- }
187
-
188
- return this
189
- }
190
-
191
- async unuse<L extends keyof Services & string>(
192
- location: L
193
- ): Promise<FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>> {
194
- const path = (stripSlashes(location) || '/') as L
195
- const service = this.services[path] as Service
196
-
197
- if (service && typeof service.teardown === 'function') {
198
- await service.teardown(this as any, path)
199
- }
200
-
201
- delete this.services[path]
202
-
203
- return service as any
204
- }
205
-
206
- hooks(hookMap: ApplicationHookOptions<this>) {
207
- const untypedMap = hookMap as any
208
-
209
- if (untypedMap.before || untypedMap.after || untypedMap.error || untypedMap.around) {
210
- // regular hooks for all service methods
211
- this.registerHooks(untypedMap)
212
- } else if (untypedMap.setup || untypedMap.teardown) {
213
- // .setup and .teardown application hooks
214
- hooks(this, untypedMap)
215
- } else {
216
- // Other registration formats are just `around` hooks
217
- this.registerHooks({
218
- around: untypedMap
219
- })
220
- }
221
-
222
- return this
223
- }
224
- }