@feathersjs/feathers 5.0.0-pre.14 → 5.0.0-pre.15
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/CHANGELOG.md +18 -0
- package/lib/application.d.ts +11 -11
- package/lib/application.js +5 -5
- package/lib/application.js.map +1 -1
- package/lib/declarations.d.ts +51 -33
- package/lib/hooks/index.d.ts +2 -3
- package/lib/hooks/index.js +24 -12
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/regular.d.ts +12 -0
- package/lib/hooks/regular.js +169 -0
- package/lib/hooks/regular.js.map +1 -0
- package/lib/service.js +1 -0
- package/lib/service.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +6 -6
- package/src/application.ts +22 -22
- package/src/declarations.ts +52 -37
- package/src/hooks/index.ts +27 -14
- package/src/hooks/regular.ts +207 -0
- package/src/service.ts +1 -0
- package/src/version.ts +1 -1
- package/lib/hooks/legacy.d.ts +0 -7
- package/lib/hooks/legacy.js +0 -126
- package/lib/hooks/legacy.js.map +0 -1
- package/src/hooks/legacy.ts +0 -150
package/src/service.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '5.0.0-pre.
|
|
1
|
+
export default '5.0.0-pre.15';
|
package/lib/hooks/legacy.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { LegacyHookFunction } from '../declarations';
|
|
2
|
-
export declare function fromBeforeHook(hook: LegacyHookFunction): (context: any, next: any) => Promise<any>;
|
|
3
|
-
export declare function fromAfterHook(hook: LegacyHookFunction): (context: any, next: any) => any;
|
|
4
|
-
export declare function fromErrorHooks(hooks: LegacyHookFunction[]): (context: any, next: any) => any;
|
|
5
|
-
export declare function collectLegacyHooks(target: any, method: string): any[];
|
|
6
|
-
export declare function convertHookData(obj: any): any;
|
|
7
|
-
export declare function enableLegacyHooks(obj: any, methods?: string[], types?: string[]): (this: any, allHooks: any) => any;
|
package/lib/hooks/legacy.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enableLegacyHooks = exports.convertHookData = exports.collectLegacyHooks = exports.fromErrorHooks = exports.fromAfterHook = exports.fromBeforeHook = void 0;
|
|
4
|
-
const dependencies_1 = require("../dependencies");
|
|
5
|
-
const { each } = dependencies_1._;
|
|
6
|
-
const mergeContext = (context) => (res) => {
|
|
7
|
-
if (res && res !== context) {
|
|
8
|
-
Object.assign(context, res);
|
|
9
|
-
}
|
|
10
|
-
return res;
|
|
11
|
-
};
|
|
12
|
-
function fromBeforeHook(hook) {
|
|
13
|
-
return (context, next) => {
|
|
14
|
-
context.type = 'before';
|
|
15
|
-
return Promise.resolve(hook.call(context.self, context))
|
|
16
|
-
.then(mergeContext(context))
|
|
17
|
-
.then(() => {
|
|
18
|
-
context.type = null;
|
|
19
|
-
return next();
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
exports.fromBeforeHook = fromBeforeHook;
|
|
24
|
-
function fromAfterHook(hook) {
|
|
25
|
-
return (context, next) => {
|
|
26
|
-
return next()
|
|
27
|
-
.then(() => {
|
|
28
|
-
context.type = 'after';
|
|
29
|
-
return hook.call(context.self, context);
|
|
30
|
-
})
|
|
31
|
-
.then(mergeContext(context))
|
|
32
|
-
.then(() => {
|
|
33
|
-
context.type = null;
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
exports.fromAfterHook = fromAfterHook;
|
|
38
|
-
function fromErrorHooks(hooks) {
|
|
39
|
-
return (context, next) => {
|
|
40
|
-
return next().catch((error) => {
|
|
41
|
-
let promise = Promise.resolve();
|
|
42
|
-
context.original = { ...context };
|
|
43
|
-
context.error = error;
|
|
44
|
-
context.type = 'error';
|
|
45
|
-
delete context.result;
|
|
46
|
-
for (const hook of hooks) {
|
|
47
|
-
promise = promise.then(() => hook.call(context.self, context))
|
|
48
|
-
.then(mergeContext(context));
|
|
49
|
-
}
|
|
50
|
-
return promise.then(() => {
|
|
51
|
-
context.type = null;
|
|
52
|
-
if (context.result === undefined) {
|
|
53
|
-
throw context.error;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
exports.fromErrorHooks = fromErrorHooks;
|
|
60
|
-
function collectLegacyHooks(target, method) {
|
|
61
|
-
const { before: { [method]: before = [] }, after: { [method]: after = [] }, error: { [method]: error = [] } } = target.__hooks;
|
|
62
|
-
const beforeHooks = before;
|
|
63
|
-
const afterHooks = [...after].reverse();
|
|
64
|
-
const errorHook = fromErrorHooks(error);
|
|
65
|
-
return [errorHook, ...beforeHooks, ...afterHooks];
|
|
66
|
-
}
|
|
67
|
-
exports.collectLegacyHooks = collectLegacyHooks;
|
|
68
|
-
// Converts different hook registration formats into the
|
|
69
|
-
// same internal format
|
|
70
|
-
function convertHookData(obj) {
|
|
71
|
-
let hook = {};
|
|
72
|
-
if (Array.isArray(obj)) {
|
|
73
|
-
hook = { all: obj };
|
|
74
|
-
}
|
|
75
|
-
else if (typeof obj !== 'object') {
|
|
76
|
-
hook = { all: [obj] };
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
each(obj, function (value, key) {
|
|
80
|
-
hook[key] = !Array.isArray(value) ? [value] : value;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return hook;
|
|
84
|
-
}
|
|
85
|
-
exports.convertHookData = convertHookData;
|
|
86
|
-
// Add `.hooks` functionality to an object
|
|
87
|
-
function enableLegacyHooks(obj, methods = ['find', 'get', 'create', 'update', 'patch', 'remove'], types = ['before', 'after', 'error']) {
|
|
88
|
-
const hookData = {};
|
|
89
|
-
types.forEach(type => {
|
|
90
|
-
// Initialize properties where hook functions are stored
|
|
91
|
-
hookData[type] = {};
|
|
92
|
-
});
|
|
93
|
-
// Add non-enumerable `__hooks` property to the object
|
|
94
|
-
Object.defineProperty(obj, '__hooks', {
|
|
95
|
-
configurable: true,
|
|
96
|
-
value: hookData,
|
|
97
|
-
writable: true
|
|
98
|
-
});
|
|
99
|
-
return function legacyHooks(allHooks) {
|
|
100
|
-
each(allHooks, (current, type) => {
|
|
101
|
-
if (!this.__hooks[type]) {
|
|
102
|
-
throw new Error(`'${type}' is not a valid hook type`);
|
|
103
|
-
}
|
|
104
|
-
const hooks = convertHookData(current);
|
|
105
|
-
each(hooks, (_value, method) => {
|
|
106
|
-
if (method !== 'all' && methods.indexOf(method) === -1) {
|
|
107
|
-
throw new Error(`'${method}' is not a valid hook method`);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
methods.forEach(method => {
|
|
111
|
-
let currentHooks = [...(hooks.all || []), ...(hooks[method] || [])];
|
|
112
|
-
this.__hooks[type][method] = this.__hooks[type][method] || [];
|
|
113
|
-
if (type === 'before') {
|
|
114
|
-
currentHooks = currentHooks.map(fromBeforeHook);
|
|
115
|
-
}
|
|
116
|
-
if (type === 'after') {
|
|
117
|
-
currentHooks = currentHooks.map(fromAfterHook);
|
|
118
|
-
}
|
|
119
|
-
this.__hooks[type][method].push(...currentHooks);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
return this;
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
exports.enableLegacyHooks = enableLegacyHooks;
|
|
126
|
-
//# sourceMappingURL=legacy.js.map
|
package/lib/hooks/legacy.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../src/hooks/legacy.ts"],"names":[],"mappings":";;;AAAA,kDAAoC;AAGpC,MAAM,EAAE,IAAI,EAAE,GAAG,gBAAC,CAAC;AACnB,MAAM,YAAY,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,CAAC,GAAQ,EAAE,EAAE;IAClD,IAAI,GAAG,IAAI,GAAG,KAAK,OAAO,EAAE;QAC1B,M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|
package/src/hooks/legacy.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { _ } from '../dependencies';
|
|
2
|
-
import { LegacyHookFunction } from '../declarations';
|
|
3
|
-
|
|
4
|
-
const { each } = _;
|
|
5
|
-
const mergeContext = (context: any) => (res: any) => {
|
|
6
|
-
if (res && res !== context) {
|
|
7
|
-
Object.assign(context, res);
|
|
8
|
-
}
|
|
9
|
-
return res;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function fromBeforeHook (hook: LegacyHookFunction) {
|
|
13
|
-
return (context: any, next: any) => {
|
|
14
|
-
context.type = 'before';
|
|
15
|
-
|
|
16
|
-
return Promise.resolve(hook.call(context.self, context))
|
|
17
|
-
.then(mergeContext(context))
|
|
18
|
-
.then(() => {
|
|
19
|
-
context.type = null;
|
|
20
|
-
return next();
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function fromAfterHook (hook: LegacyHookFunction) {
|
|
26
|
-
return (context: any, next: any) => {
|
|
27
|
-
return next()
|
|
28
|
-
.then(() => {
|
|
29
|
-
context.type = 'after';
|
|
30
|
-
return hook.call(context.self, context)
|
|
31
|
-
})
|
|
32
|
-
.then(mergeContext(context))
|
|
33
|
-
.then(() => {
|
|
34
|
-
context.type = null;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function fromErrorHooks (hooks: LegacyHookFunction[]) {
|
|
40
|
-
return (context: any, next: any) => {
|
|
41
|
-
return next().catch((error: any) => {
|
|
42
|
-
let promise: Promise<any> = Promise.resolve();
|
|
43
|
-
|
|
44
|
-
context.original = { ...context };
|
|
45
|
-
context.error = error;
|
|
46
|
-
context.type = 'error';
|
|
47
|
-
|
|
48
|
-
delete context.result;
|
|
49
|
-
|
|
50
|
-
for (const hook of hooks) {
|
|
51
|
-
promise = promise.then(() => hook.call(context.self, context))
|
|
52
|
-
.then(mergeContext(context))
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return promise.then(() => {
|
|
56
|
-
context.type = null;
|
|
57
|
-
|
|
58
|
-
if (context.result === undefined) {
|
|
59
|
-
throw context.error;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function collectLegacyHooks (target: any, method: string) {
|
|
67
|
-
const {
|
|
68
|
-
before: { [method]: before = [] },
|
|
69
|
-
after: { [method]: after = [] },
|
|
70
|
-
error: { [method]: error = [] }
|
|
71
|
-
} = target.__hooks;
|
|
72
|
-
const beforeHooks = before;
|
|
73
|
-
const afterHooks = [...after].reverse();
|
|
74
|
-
const errorHook = fromErrorHooks(error);
|
|
75
|
-
|
|
76
|
-
return [errorHook, ...beforeHooks, ...afterHooks];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Converts different hook registration formats into the
|
|
80
|
-
// same internal format
|
|
81
|
-
export function convertHookData (obj: any) {
|
|
82
|
-
let hook: any = {};
|
|
83
|
-
|
|
84
|
-
if (Array.isArray(obj)) {
|
|
85
|
-
hook = { all: obj };
|
|
86
|
-
} else if (typeof obj !== 'object') {
|
|
87
|
-
hook = { all: [ obj ] };
|
|
88
|
-
} else {
|
|
89
|
-
each(obj, function (value, key) {
|
|
90
|
-
hook[key] = !Array.isArray(value) ? [ value ] : value;
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return hook;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Add `.hooks` functionality to an object
|
|
98
|
-
export function enableLegacyHooks (
|
|
99
|
-
obj: any,
|
|
100
|
-
methods: string[] = ['find', 'get', 'create', 'update', 'patch', 'remove'],
|
|
101
|
-
types: string[] = ['before', 'after', 'error']
|
|
102
|
-
) {
|
|
103
|
-
const hookData: any = {};
|
|
104
|
-
|
|
105
|
-
types.forEach(type => {
|
|
106
|
-
// Initialize properties where hook functions are stored
|
|
107
|
-
hookData[type] = {};
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Add non-enumerable `__hooks` property to the object
|
|
111
|
-
Object.defineProperty(obj, '__hooks', {
|
|
112
|
-
configurable: true,
|
|
113
|
-
value: hookData,
|
|
114
|
-
writable: true
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
return function legacyHooks (this: any, allHooks: any) {
|
|
118
|
-
each(allHooks, (current: any, type) => {
|
|
119
|
-
if (!this.__hooks[type]) {
|
|
120
|
-
throw new Error(`'${type}' is not a valid hook type`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const hooks = convertHookData(current);
|
|
124
|
-
|
|
125
|
-
each(hooks, (_value, method) => {
|
|
126
|
-
if (method !== 'all' && methods.indexOf(method) === -1) {
|
|
127
|
-
throw new Error(`'${method}' is not a valid hook method`);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
methods.forEach(method => {
|
|
132
|
-
let currentHooks = [...(hooks.all || []), ...(hooks[method] || [])];
|
|
133
|
-
|
|
134
|
-
this.__hooks[type][method] = this.__hooks[type][method] || [];
|
|
135
|
-
|
|
136
|
-
if (type === 'before') {
|
|
137
|
-
currentHooks = currentHooks.map(fromBeforeHook);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (type === 'after') {
|
|
141
|
-
currentHooks = currentHooks.map(fromAfterHook);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
this.__hooks[type][method].push(...currentHooks);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
}
|