@feathersjs/feathers 5.0.0-pre.10

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/src/service.ts ADDED
@@ -0,0 +1,90 @@
1
+ import { createSymbol, EventEmitter } from './dependencies';
2
+ import { ServiceOptions } from './declarations';
3
+
4
+ export const SERVICE = createSymbol('@feathersjs/service');
5
+
6
+ export const defaultServiceArguments = {
7
+ find: [ 'params' ],
8
+ get: [ 'id', 'params' ],
9
+ create: [ 'data', 'params' ],
10
+ update: [ 'id', 'data', 'params' ],
11
+ patch: [ 'id', 'data', 'params' ],
12
+ remove: [ 'id', 'params' ]
13
+ }
14
+
15
+ export const defaultServiceMethods = Object.keys(defaultServiceArguments);
16
+
17
+ export const defaultEventMap = {
18
+ create: 'created',
19
+ update: 'updated',
20
+ patch: 'patched',
21
+ remove: 'removed'
22
+ }
23
+
24
+ export const protectedMethods = Object.keys(Object.prototype)
25
+ .concat(Object.keys(EventEmitter.prototype))
26
+ .concat([
27
+ 'before',
28
+ 'after',
29
+ 'error',
30
+ 'hooks',
31
+ 'setup',
32
+ 'publish'
33
+ ]);
34
+
35
+ export function getHookMethods (service: any, options: ServiceOptions) {
36
+ const { methods } = options;
37
+
38
+ return defaultServiceMethods.filter(m =>
39
+ typeof service[m] === 'function' && !methods.includes(m)
40
+ ).concat(methods);
41
+ }
42
+
43
+ export function getServiceOptions (
44
+ service: any, options: ServiceOptions = {}
45
+ ): ServiceOptions {
46
+ const existingOptions = service[SERVICE];
47
+
48
+ if (existingOptions) {
49
+ return existingOptions;
50
+ }
51
+
52
+ const {
53
+ methods = defaultServiceMethods.filter(method =>
54
+ typeof service[method] === 'function'
55
+ ),
56
+ events = service.events || []
57
+ } = options;
58
+ const {
59
+ serviceEvents = Object.values(defaultEventMap).concat(events)
60
+ } = options;
61
+
62
+ return {
63
+ ...options,
64
+ events,
65
+ methods,
66
+ serviceEvents
67
+ };
68
+ }
69
+
70
+ export function wrapService (
71
+ location: string, service: any, options: ServiceOptions
72
+ ) {
73
+ // Do nothing if this is already an initialized
74
+ if (service[SERVICE]) {
75
+ return service;
76
+ }
77
+
78
+ const protoService = Object.create(service);
79
+ const serviceOptions = getServiceOptions(service, options);
80
+
81
+ if (Object.keys(serviceOptions.methods).length === 0 && typeof service.setup !== 'function') {
82
+ throw new Error(`Invalid service object passed for path \`${location}\``);
83
+ }
84
+
85
+ Object.defineProperty(protoService, SERVICE, {
86
+ value: serviceOptions
87
+ });
88
+
89
+ return protoService;
90
+ }
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export default '5.0.0-pre.10';