@feathersjs/transport-commons 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/CHANGELOG.md +193 -227
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/client.d.ts +1 -1
- package/lib/channels/channel/base.d.ts +1 -3
- package/lib/channels/channel/base.js +2 -2
- package/lib/channels/channel/base.js.map +1 -1
- package/lib/channels/channel/combined.d.ts +2 -1
- package/lib/channels/channel/combined.js +2 -2
- package/lib/channels/channel/combined.js.map +1 -1
- package/lib/channels/index.d.ts +14 -12
- package/lib/channels/index.js +15 -10
- package/lib/channels/index.js.map +1 -1
- package/lib/channels/mixins.d.ts +3 -3
- package/lib/channels/mixins.js +3 -3
- package/lib/channels/mixins.js.map +1 -1
- package/lib/client.d.ts +2 -2
- package/lib/client.js +10 -12
- package/lib/client.js.map +1 -1
- package/lib/http.d.ts +14 -9
- package/lib/http.js +30 -20
- package/lib/http.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.js +8 -2
- package/lib/index.js.map +1 -1
- package/lib/routing/index.d.ts +9 -4
- package/lib/routing/index.js +26 -16
- package/lib/routing/index.js.map +1 -1
- package/lib/routing/router.d.ts +4 -1
- package/lib/routing/router.js +37 -4
- package/lib/routing/router.js.map +1 -1
- package/lib/socket/index.d.ts +1 -2
- package/lib/socket/index.js +10 -10
- package/lib/socket/index.js.map +1 -1
- package/lib/socket/utils.d.ts +1 -2
- package/lib/socket/utils.js +43 -53
- package/lib/socket/utils.js.map +1 -1
- package/package.json +19 -14
- package/src/channels/channel/base.ts +28 -31
- package/src/channels/channel/combined.ts +32 -31
- package/src/channels/index.ts +67 -61
- package/src/channels/mixins.ts +49 -46
- package/src/client.ts +70 -70
- package/src/http.ts +55 -43
- package/src/index.ts +6 -5
- package/src/routing/index.ts +45 -28
- package/src/routing/router.ts +80 -42
- package/src/socket/index.ts +43 -44
- package/src/socket/utils.ts +71 -59
package/lib/routing/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.
|
|
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];
|
|
@@ -13,26 +17,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
17
|
exports.routing = void 0;
|
|
14
18
|
const router_1 = require("./router");
|
|
15
19
|
__exportStar(require("./router"), exports);
|
|
20
|
+
const lookup = function (path) {
|
|
21
|
+
const result = this.routes.lookup(path);
|
|
22
|
+
if (result === null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const { params: colonParams, data: { service, params: dataParams } } = result;
|
|
26
|
+
const params = dataParams ? { ...dataParams, ...colonParams } : colonParams;
|
|
27
|
+
return { service, params };
|
|
28
|
+
};
|
|
16
29
|
const routing = () => (app) => {
|
|
17
30
|
if (typeof app.lookup === 'function') {
|
|
18
31
|
return;
|
|
19
32
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
33
|
+
const { unuse } = app;
|
|
34
|
+
app.routes = new router_1.Router();
|
|
35
|
+
app.lookup = lookup;
|
|
36
|
+
app.unuse = function (path) {
|
|
37
|
+
app.routes.remove(path);
|
|
38
|
+
app.routes.remove(`${path}/:__id`);
|
|
39
|
+
return unuse.call(this, path);
|
|
40
|
+
};
|
|
32
41
|
// Add a mixin that registers a service on the router
|
|
33
|
-
app.mixins.push((service, path) => {
|
|
34
|
-
|
|
35
|
-
app.routes.insert(
|
|
42
|
+
app.mixins.push((service, path, options) => {
|
|
43
|
+
const { routeParams: params = {} } = options;
|
|
44
|
+
app.routes.insert(path, { service, params });
|
|
45
|
+
app.routes.insert(`${path}/:__id`, { service, params });
|
|
36
46
|
});
|
|
37
47
|
};
|
|
38
48
|
exports.routing = routing;
|
package/lib/routing/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,qCAAiC;AAmBjC,2CAAwB;AAExB,MAAM,MAAM,GAAG,UAA6B,IAAY;IACtD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAEvC,IAAI,MAAM,KAAK,IAAI,EAAE;QACnB,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,EACJ,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,EACtC,GAAG,MAAM,CAAA;IAEV,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC,WAAW,CAAA;IAE3E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;AAC5B,CAAC,CAAA;AAEM,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,GAAgB,EAAE,EAAE;IAChD,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE;QACpC,OAAM;KACP;IAED,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;IAErB,GAAG,CAAC,MAAM,GAAG,IAAI,eAAM,EAAE,CAAA;IACzB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAA;IACnB,GAAG,CAAC,KAAK,GAAG,UAAU,IAAY;QAChC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACvB,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAA;QAClC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAC/B,CAAC,CAAA;IAED,qDAAqD;IACrD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAwB,EAAE,IAAY,EAAE,OAAuB,EAAE,EAAE;QAClF,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,OAAO,CAAA;QAE5C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;QAC5C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAtBY,QAAA,OAAO,WAsBnB"}
|
package/lib/routing/router.d.ts
CHANGED
|
@@ -15,13 +15,16 @@ export declare class RouteNode<T = any> {
|
|
|
15
15
|
};
|
|
16
16
|
placeholders: RouteNode[];
|
|
17
17
|
constructor(name: string, depth: number);
|
|
18
|
+
get hasChildren(): boolean;
|
|
18
19
|
insert(path: string[], data: T): RouteNode<T>;
|
|
20
|
+
remove(path: string[]): void;
|
|
19
21
|
lookup(path: string[], info: LookupData): LookupResult<T> | null;
|
|
20
22
|
}
|
|
21
|
-
export declare class Router<T> {
|
|
23
|
+
export declare class Router<T = any> {
|
|
22
24
|
root: RouteNode<T>;
|
|
23
25
|
constructor(root?: RouteNode<T>);
|
|
24
26
|
getPath(path: string): string[];
|
|
25
27
|
insert(path: string, data: T): RouteNode<T>;
|
|
28
|
+
remove(path: string): void;
|
|
26
29
|
lookup(path: string): LookupResult<T>;
|
|
27
30
|
}
|
package/lib/routing/router.js
CHANGED
|
@@ -9,6 +9,9 @@ class RouteNode {
|
|
|
9
9
|
this.children = {};
|
|
10
10
|
this.placeholders = [];
|
|
11
11
|
}
|
|
12
|
+
get hasChildren() {
|
|
13
|
+
return Object.keys(this.children).length !== 0 || this.placeholders.length !== 0;
|
|
14
|
+
}
|
|
12
15
|
insert(path, data) {
|
|
13
16
|
if (this.depth === path.length) {
|
|
14
17
|
if (this.data !== undefined) {
|
|
@@ -22,7 +25,7 @@ class RouteNode {
|
|
|
22
25
|
if (current.startsWith(':')) {
|
|
23
26
|
// Insert a placeholder node like /messages/:id
|
|
24
27
|
const placeholderName = current.substring(1);
|
|
25
|
-
let placeholder = this.placeholders.find(p => p.name === placeholderName);
|
|
28
|
+
let placeholder = this.placeholders.find((p) => p.name === placeholderName);
|
|
26
29
|
if (!placeholder) {
|
|
27
30
|
placeholder = new RouteNode(placeholderName, nextDepth);
|
|
28
31
|
this.placeholders.push(placeholder);
|
|
@@ -33,14 +36,41 @@ class RouteNode {
|
|
|
33
36
|
this.children[current] = child;
|
|
34
37
|
return child.insert(path, data);
|
|
35
38
|
}
|
|
39
|
+
remove(path) {
|
|
40
|
+
if (path.length === this.depth) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const current = path[this.depth];
|
|
44
|
+
if (current.startsWith(':')) {
|
|
45
|
+
const placeholderName = current.substring(1);
|
|
46
|
+
const placeholder = this.placeholders.find((p) => p.name === placeholderName);
|
|
47
|
+
placeholder.remove(path);
|
|
48
|
+
this.placeholders = this.placeholders.filter((p) => p !== placeholder);
|
|
49
|
+
}
|
|
50
|
+
else if (this.children[current]) {
|
|
51
|
+
const child = this.children[current];
|
|
52
|
+
child.remove(path);
|
|
53
|
+
if (!child.hasChildren) {
|
|
54
|
+
delete this.children[current];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
36
58
|
lookup(path, info) {
|
|
37
59
|
if (path.length === this.depth) {
|
|
38
|
-
return this.data === undefined
|
|
60
|
+
return this.data === undefined
|
|
61
|
+
? null
|
|
62
|
+
: {
|
|
63
|
+
...info,
|
|
64
|
+
data: this.data
|
|
65
|
+
};
|
|
39
66
|
}
|
|
40
67
|
const current = path[this.depth];
|
|
41
68
|
const child = this.children[current];
|
|
42
69
|
if (child) {
|
|
43
|
-
|
|
70
|
+
const lookup = child.lookup(path, info);
|
|
71
|
+
if (lookup !== null) {
|
|
72
|
+
return lookup;
|
|
73
|
+
}
|
|
44
74
|
}
|
|
45
75
|
// This will return the first placeholder that matches early
|
|
46
76
|
for (const placeholder of this.placeholders) {
|
|
@@ -59,11 +89,14 @@ class Router {
|
|
|
59
89
|
this.root = root;
|
|
60
90
|
}
|
|
61
91
|
getPath(path) {
|
|
62
|
-
return commons_1.stripSlashes(path).split('/');
|
|
92
|
+
return (0, commons_1.stripSlashes)(path).split('/');
|
|
63
93
|
}
|
|
64
94
|
insert(path, data) {
|
|
65
95
|
return this.root.insert(this.getPath(path), data);
|
|
66
96
|
}
|
|
97
|
+
remove(path) {
|
|
98
|
+
return this.root.remove(this.getPath(path));
|
|
99
|
+
}
|
|
67
100
|
lookup(path) {
|
|
68
101
|
if (typeof path !== 'string') {
|
|
69
102
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/routing/router.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/routing/router.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAUlD,MAAa,SAAS;IAKpB,YAAmB,IAAY,EAAS,KAAa;QAAlC,SAAI,GAAJ,IAAI,CAAQ;QAAS,UAAK,GAAL,KAAK,CAAQ;QAHrD,aAA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AAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7C,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC5B,OAAO,IAAI,CAAA;SACZ;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAA;IAC7D,CAAC;CACF;AAtBD,wBAsBC"}
|
package/lib/socket/index.d.ts
CHANGED
package/lib/socket/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const commons_1 = require("@feathersjs/commons");
|
|
|
6
6
|
const channels_1 = require("../channels");
|
|
7
7
|
const routing_1 = require("../routing");
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
|
-
const debug = commons_1.createDebug('@feathersjs/transport-commons');
|
|
9
|
+
const debug = (0, commons_1.createDebug)('@feathersjs/transport-commons');
|
|
10
10
|
function socket({ done, emit, socketMap, socketKey, getParams }) {
|
|
11
11
|
return (app) => {
|
|
12
12
|
const leaveChannels = (connection) => {
|
|
@@ -15,9 +15,9 @@ function socket({ done, emit, socketMap, socketKey, getParams }) {
|
|
|
15
15
|
app.channel(app.channels).leave(connection);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
-
app.configure(channels_1.channels());
|
|
19
|
-
app.configure(routing_1.routing());
|
|
20
|
-
app.on('publish', utils_1.getDispatcher(emit, socketMap, socketKey));
|
|
18
|
+
app.configure((0, channels_1.channels)());
|
|
19
|
+
app.configure((0, routing_1.routing)());
|
|
20
|
+
app.on('publish', (0, utils_1.getDispatcher)(emit, socketMap, socketKey));
|
|
21
21
|
app.on('disconnect', leaveChannels);
|
|
22
22
|
app.on('logout', (_authResult, params) => {
|
|
23
23
|
const { connection } = params;
|
|
@@ -26,23 +26,23 @@ function socket({ done, emit, socketMap, socketKey, getParams }) {
|
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
// `connection` event
|
|
29
|
-
done.then(provider => provider.on('connection', (connection) => app.emit('connection', getParams(connection))));
|
|
29
|
+
done.then((provider) => provider.on('connection', (connection) => app.emit('connection', getParams(connection))));
|
|
30
30
|
// `socket.emit('methodName', 'serviceName', ...args)` handlers
|
|
31
|
-
done.then(provider => provider.on('connection', (connection) => {
|
|
31
|
+
done.then((provider) => provider.on('connection', (connection) => {
|
|
32
32
|
const methodHandlers = Object.keys(app.services).reduce((result, name) => {
|
|
33
|
-
const { methods } = feathers_1.getServiceOptions(app.service(name));
|
|
34
|
-
methods.forEach(method => {
|
|
33
|
+
const { methods } = (0, feathers_1.getServiceOptions)(app.service(name));
|
|
34
|
+
methods.forEach((method) => {
|
|
35
35
|
if (!result[method]) {
|
|
36
36
|
result[method] = (...args) => {
|
|
37
37
|
const path = args.shift();
|
|
38
38
|
debug(`Got '${method}' call for service '${path}'`);
|
|
39
|
-
utils_1.runMethod(app, getParams(connection), path, method, args);
|
|
39
|
+
(0, utils_1.runMethod)(app, getParams(connection), path, method, args);
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
return result;
|
|
44
44
|
}, {});
|
|
45
|
-
Object.keys(methodHandlers).forEach(key => connection.on(key, methodHandlers[key]));
|
|
45
|
+
Object.keys(methodHandlers).forEach((key) => connection.on(key, methodHandlers[key]));
|
|
46
46
|
}));
|
|
47
47
|
};
|
|
48
48
|
}
|
package/lib/socket/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":";;;AAAA,mDAAiG;AACjG,iDAAiD;AACjD,0CAAsC;AACtC,wCAAoC;AACpC,mCAAkD;AAElD,MAAM,KAAK,GAAG,IAAA,qBAAW,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AQ,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,UAAe,EAAE,EAAE;YAC5C,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;gBACvE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,4BAAiB,EAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;gBAExD,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;oBACzB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;wBACnB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;4BAClC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAA;4BAEzB,KAAK,CAAC,QAAQ,MAAM,uBAAuB,IAAI,GAAG,CAAC,CAAA;4BACnD,IAAA,iBAAS,EAAC,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;wBAC3D,CAAC,CAAA;qBACF;gBACH,CAAC,CAAC,CAAA;gBAEF,OAAO,MAAM,CAAA;YACf,CAAC,EAAE,EAAS,CAAC,CAAA;YAEb,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACvF,CAAC,CAAC,CACH,CAAA;IACH,CAAC,CAAA;AACH,CAAC;AApDD,wBAoDC"}
|
package/lib/socket/utils.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { HookContext, Application } from '@feathersjs/feathers';
|
|
1
|
+
import { HookContext, Application, RealTimeConnection } from '@feathersjs/feathers';
|
|
2
2
|
import { CombinedChannel } from '../channels/channel/combined';
|
|
3
|
-
import { RealTimeConnection } from '../channels/channel/base';
|
|
4
3
|
export declare const DEFAULT_PARAMS_POSITION = 1;
|
|
5
4
|
export declare const paramsPositions: {
|
|
6
5
|
[key: string]: number;
|
package/lib/socket/utils.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -17,7 +8,7 @@ const feathers_1 = require("@feathersjs/feathers");
|
|
|
17
8
|
const errors_1 = require("@feathersjs/errors");
|
|
18
9
|
const commons_1 = require("@feathersjs/commons");
|
|
19
10
|
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
20
|
-
const debug = commons_1.createDebug('@feathersjs/transport-commons');
|
|
11
|
+
const debug = (0, commons_1.createDebug)('@feathersjs/transport-commons');
|
|
21
12
|
exports.DEFAULT_PARAMS_POSITION = 1;
|
|
22
13
|
exports.paramsPositions = {
|
|
23
14
|
find: 0,
|
|
@@ -28,7 +19,7 @@ function normalizeError(e) {
|
|
|
28
19
|
const hasToJSON = typeof e.toJSON === 'function';
|
|
29
20
|
const result = hasToJSON ? e.toJSON() : {};
|
|
30
21
|
if (!hasToJSON) {
|
|
31
|
-
Object.getOwnPropertyNames(e).forEach(key => {
|
|
22
|
+
Object.getOwnPropertyNames(e).forEach((key) => {
|
|
32
23
|
result[key] = e[key];
|
|
33
24
|
});
|
|
34
25
|
}
|
|
@@ -42,7 +33,7 @@ exports.normalizeError = normalizeError;
|
|
|
42
33
|
function getDispatcher(emit, socketMap, socketKey) {
|
|
43
34
|
return function (event, channel, context, data) {
|
|
44
35
|
debug(`Dispatching '${event}' to ${channel.length} connections`);
|
|
45
|
-
channel.connections.forEach(connection => {
|
|
36
|
+
channel.connections.forEach((connection) => {
|
|
46
37
|
// The reference between connection and socket is set in `app.setup`
|
|
47
38
|
const socket = socketKey ? connection[socketKey] : socketMap.get(connection);
|
|
48
39
|
if (socket) {
|
|
@@ -51,7 +42,7 @@ function getDispatcher(emit, socketMap, socketKey) {
|
|
|
51
42
|
// If we are getting events from an array but try to dispatch individual data
|
|
52
43
|
// try to get the individual item to dispatch from the correct index.
|
|
53
44
|
if (!Array.isArray(data) && Array.isArray(context.result) && Array.isArray(result)) {
|
|
54
|
-
result = context.result.find(resultData => isEqual_1.default(resultData, data));
|
|
45
|
+
result = context.result.find((resultData) => (0, isEqual_1.default)(resultData, data));
|
|
55
46
|
}
|
|
56
47
|
debug(`Dispatching '${eventName}' to Socket ${socket.id} with`, result);
|
|
57
48
|
socket[emit](eventName, result);
|
|
@@ -60,48 +51,47 @@ function getDispatcher(emit, socketMap, socketKey) {
|
|
|
60
51
|
};
|
|
61
52
|
}
|
|
62
53
|
exports.getDispatcher = getDispatcher;
|
|
63
|
-
function runMethod(app, connection, path, method, args) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
const position = exports.paramsPositions[method] !== undefined ? exports.paramsPositions[method] : exports.DEFAULT_PARAMS_POSITION;
|
|
87
|
-
const query = methodArgs[position] || {};
|
|
88
|
-
// `params` have to be re-mapped to the query and added with the route
|
|
89
|
-
const params = Object.assign({ query, route, connection }, connection);
|
|
90
|
-
// `params` is always the last parameter. Error if we got more arguments.
|
|
91
|
-
if (methodArgs.length > (position + 1)) {
|
|
92
|
-
throw new errors_1.BadRequest(`Too many arguments for '${method}' method`);
|
|
93
|
-
}
|
|
94
|
-
methodArgs[position] = params;
|
|
95
|
-
const ctx = feathers_1.createContext(service, method);
|
|
96
|
-
const returnedCtx = yield service[method](...methodArgs, ctx);
|
|
97
|
-
const result = returnedCtx.dispatch || returnedCtx.result;
|
|
98
|
-
debug(`Returned successfully ${trace}`, result);
|
|
99
|
-
callback(null, result);
|
|
54
|
+
async function runMethod(app, connection, path, method, args) {
|
|
55
|
+
const trace = `method '${method}' on service '${path}'`;
|
|
56
|
+
const methodArgs = args.slice(0);
|
|
57
|
+
const callback =
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
59
|
+
typeof methodArgs[methodArgs.length - 1] === 'function' ? methodArgs.pop() : function () { };
|
|
60
|
+
debug(`Running ${trace}`, connection, args);
|
|
61
|
+
const handleError = (error) => {
|
|
62
|
+
debug(`Error in ${trace}`, error);
|
|
63
|
+
callback(normalizeError(error));
|
|
64
|
+
};
|
|
65
|
+
try {
|
|
66
|
+
const lookup = app.lookup(path);
|
|
67
|
+
// No valid service was found throw a NotFound error
|
|
68
|
+
if (lookup === null) {
|
|
69
|
+
throw new errors_1.NotFound(`Service '${path}' not found`);
|
|
70
|
+
}
|
|
71
|
+
const { service, params: route = {} } = lookup;
|
|
72
|
+
const { methods } = (0, feathers_1.getServiceOptions)(service);
|
|
73
|
+
// Only service methods are allowed
|
|
74
|
+
if (!methods.includes(method)) {
|
|
75
|
+
throw new errors_1.MethodNotAllowed(`Method '${method}' not allowed on service '${path}'`);
|
|
100
76
|
}
|
|
101
|
-
|
|
102
|
-
|
|
77
|
+
const position = exports.paramsPositions[method] !== undefined ? exports.paramsPositions[method] : exports.DEFAULT_PARAMS_POSITION;
|
|
78
|
+
const query = Object.assign({}, methodArgs[position]);
|
|
79
|
+
// `params` have to be re-mapped to the query and added with the route
|
|
80
|
+
const params = Object.assign({ query, route, connection }, connection);
|
|
81
|
+
// `params` is always the last parameter. Error if we got more arguments.
|
|
82
|
+
if (methodArgs.length > position + 1) {
|
|
83
|
+
throw new errors_1.BadRequest(`Too many arguments for '${method}' method`);
|
|
103
84
|
}
|
|
104
|
-
|
|
85
|
+
methodArgs[position] = params;
|
|
86
|
+
const ctx = (0, feathers_1.createContext)(service, method);
|
|
87
|
+
const returnedCtx = await service[method](...methodArgs, ctx);
|
|
88
|
+
const result = returnedCtx.dispatch || returnedCtx.result;
|
|
89
|
+
debug(`Returned successfully ${trace}`, result);
|
|
90
|
+
callback(null, result);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
handleError(error);
|
|
94
|
+
}
|
|
105
95
|
}
|
|
106
96
|
exports.runMethod = runMethod;
|
|
107
97
|
//# sourceMappingURL=utils.js.map
|
package/lib/socket/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/socket/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/socket/utils.ts"],"names":[],"mappings":";;;;;;AAAA,mDAM6B;AAC7B,+CAA2E;AAC3E,iDAAiD;AACjD,6DAAoC;AAGpC,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,+BAA+B,CAAC,CAAA;AAE7C,QAAA,uBAAuB,GAAG,CAAC,CAAA;AAE3B,QAAA,eAAe,GAA8B;IACxD,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACT,CAAA;AAED,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,EAAE,GAAG,CAAC,CAAA;QACnF,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,MAAM,CAAA;QAEzD,KAAK,CAAC,yBAAyB,KAAK,EAAE,EAAE,MAAM,CAAC,CAAA;QAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;KACvB;IAAC,OAAO,KAAU,EAAE;QACnB,WAAW,CAAC,KAAK,CAAC,CAAA;KACnB;AACH,CAAC;AAzDD,8BAyDC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/transport-commons",
|
|
3
3
|
"description": "Shared functionality for websocket providers",
|
|
4
|
-
"version": "5.0.0
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git://github.com/feathersjs/feathers.git"
|
|
19
|
+
"url": "git://github.com/feathersjs/feathers.git",
|
|
20
|
+
"directory": "packages/transport-commons"
|
|
20
21
|
},
|
|
21
22
|
"author": {
|
|
22
23
|
"name": "Feathers contributors",
|
|
@@ -32,8 +33,9 @@
|
|
|
32
33
|
},
|
|
33
34
|
"scripts": {
|
|
34
35
|
"prepublish": "npm run compile",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
36
|
+
"pack": "npm pack --pack-destination ../generators/test/build",
|
|
37
|
+
"compile": "shx rm -rf lib/ && tsc && npm run pack",
|
|
38
|
+
"test": "npm run mocha",
|
|
37
39
|
"mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
|
|
38
40
|
},
|
|
39
41
|
"directories": {
|
|
@@ -52,18 +54,21 @@
|
|
|
52
54
|
"*.js"
|
|
53
55
|
],
|
|
54
56
|
"dependencies": {
|
|
55
|
-
"@feathersjs/commons": "^5.0.0
|
|
56
|
-
"@feathersjs/errors": "^5.0.0
|
|
57
|
+
"@feathersjs/commons": "^5.0.0",
|
|
58
|
+
"@feathersjs/errors": "^5.0.0",
|
|
59
|
+
"@feathersjs/feathers": "^5.0.0",
|
|
60
|
+
"encodeurl": "^1.0.2",
|
|
57
61
|
"lodash": "^4.17.21"
|
|
58
62
|
},
|
|
59
63
|
"devDependencies": {
|
|
60
|
-
"@
|
|
61
|
-
"@types/
|
|
62
|
-
"@types/
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
64
|
+
"@types/encodeurl": "^1.0.0",
|
|
65
|
+
"@types/lodash": "^4.14.191",
|
|
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"
|
|
67
72
|
},
|
|
68
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "90caf635aec850550b9d37bea2762af959d9e8d5"
|
|
69
74
|
}
|
|
@@ -1,61 +1,58 @@
|
|
|
1
|
-
import { EventEmitter } from 'events'
|
|
2
|
-
|
|
3
|
-
export interface RealTimeConnection {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
}
|
|
1
|
+
import { EventEmitter } from 'events'
|
|
2
|
+
import { RealTimeConnection } from '@feathersjs/feathers'
|
|
6
3
|
|
|
7
4
|
export class Channel extends EventEmitter {
|
|
8
|
-
connections: RealTimeConnection[]
|
|
9
|
-
data: any
|
|
5
|
+
connections: RealTimeConnection[]
|
|
6
|
+
data: any
|
|
10
7
|
|
|
11
|
-
constructor
|
|
12
|
-
super()
|
|
8
|
+
constructor(connections: RealTimeConnection[] = [], data: any = null) {
|
|
9
|
+
super()
|
|
13
10
|
|
|
14
|
-
this.connections = connections
|
|
15
|
-
this.data = data
|
|
11
|
+
this.connections = connections
|
|
12
|
+
this.data = data
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
get length
|
|
19
|
-
return this.connections.length
|
|
15
|
+
get length() {
|
|
16
|
+
return this.connections.length
|
|
20
17
|
}
|
|
21
18
|
|
|
22
|
-
leave
|
|
23
|
-
connections.forEach(current => {
|
|
19
|
+
leave(...connections: RealTimeConnection[]) {
|
|
20
|
+
connections.forEach((current) => {
|
|
24
21
|
if (typeof current === 'function') {
|
|
25
|
-
const callback = current as (connection: RealTimeConnection) => boolean
|
|
22
|
+
const callback = current as (connection: RealTimeConnection) => boolean
|
|
26
23
|
|
|
27
|
-
this.leave(...this.connections.filter(callback))
|
|
24
|
+
this.leave(...this.connections.filter(callback))
|
|
28
25
|
} else {
|
|
29
|
-
const index = this.connections.indexOf(current)
|
|
26
|
+
const index = this.connections.indexOf(current)
|
|
30
27
|
|
|
31
28
|
if (index !== -1) {
|
|
32
|
-
this.connections.splice(index, 1)
|
|
29
|
+
this.connections.splice(index, 1)
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
|
-
})
|
|
32
|
+
})
|
|
36
33
|
|
|
37
34
|
if (this.length === 0) {
|
|
38
|
-
this.emit('empty')
|
|
35
|
+
this.emit('empty')
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
return this
|
|
38
|
+
return this
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
join
|
|
45
|
-
connections.forEach(connection => {
|
|
41
|
+
join(...connections: RealTimeConnection[]) {
|
|
42
|
+
connections.forEach((connection) => {
|
|
46
43
|
if (connection && this.connections.indexOf(connection) === -1) {
|
|
47
|
-
this.connections.push(connection)
|
|
44
|
+
this.connections.push(connection)
|
|
48
45
|
}
|
|
49
|
-
})
|
|
46
|
+
})
|
|
50
47
|
|
|
51
|
-
return this
|
|
48
|
+
return this
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
filter
|
|
55
|
-
return new Channel(this.connections.filter(fn), this.data)
|
|
51
|
+
filter(fn: (connection: RealTimeConnection) => boolean) {
|
|
52
|
+
return new Channel(this.connections.filter(fn), this.data)
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
send
|
|
59
|
-
return new Channel(this.connections, data)
|
|
55
|
+
send(data: any) {
|
|
56
|
+
return new Channel(this.connections, data)
|
|
60
57
|
}
|
|
61
58
|
}
|