@feathersjs/transport-commons 5.0.0-pre.1 → 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 +169 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/lib/channels/channel/base.js +1 -1
- package/lib/channels/channel/base.js.map +1 -1
- package/lib/channels/channel/combined.js +1 -2
- package/lib/channels/channel/combined.js.map +1 -1
- package/lib/channels/index.d.ts +14 -12
- package/lib/channels/index.js +9 -11
- package/lib/channels/index.js.map +1 -1
- package/lib/channels/mixins.d.ts +2 -2
- package/lib/channels/mixins.js +5 -7
- package/lib/channels/mixins.js.map +1 -1
- package/lib/client.d.ts +11 -9
- package/lib/client.js +11 -6
- package/lib/client.js.map +1 -1
- package/lib/http.d.ts +28 -0
- package/lib/http.js +62 -0
- package/lib/http.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +21 -1
- package/lib/index.js.map +1 -1
- package/lib/routing/index.d.ts +21 -0
- package/lib/routing/index.js +39 -0
- package/lib/routing/index.js.map +1 -0
- package/lib/routing/router.d.ts +27 -0
- package/lib/routing/router.js +78 -0
- package/lib/routing/router.js.map +1 -0
- package/lib/socket/index.js +19 -26
- package/lib/socket/index.js.map +1 -1
- package/lib/socket/utils.d.ts +2 -1
- package/lib/socket/utils.js +25 -30
- package/lib/socket/utils.js.map +1 -1
- package/package.json +13 -15
- package/src/channels/channel/base.ts +1 -1
- package/src/channels/channel/combined.ts +1 -2
- package/src/channels/index.ts +21 -19
- package/src/channels/mixins.ts +7 -6
- package/src/client.ts +27 -16
- package/src/http.ts +76 -0
- package/src/index.ts +1 -0
- package/src/routing/index.ts +50 -0
- package/src/routing/router.ts +98 -0
- package/src/socket/index.ts +19 -21
- package/src/socket/utils.ts +27 -31
- package/lib/routing.d.ts +0 -10
- package/lib/routing.js +0 -37
- package/lib/routing.js.map +0 -1
- package/src/routing.ts +0 -42
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAkC;AAKzB,uFALA,eAAM,OAKA;AAJf,uCAAoC;AAInB,wFAJR,iBAAO,OAIQ;AAHxB,yCAAsC;AAGZ,yFAHjB,mBAAQ,OAGiB;AADlC,+CAA+B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Application } from '@feathersjs/feathers';
|
|
2
|
+
import { Router } from './router';
|
|
3
|
+
declare module '@feathersjs/feathers/lib/declarations' {
|
|
4
|
+
interface RouteLookup {
|
|
5
|
+
service: Service;
|
|
6
|
+
params: {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
interface Application<Services, Settings> {
|
|
11
|
+
routes: Router<{
|
|
12
|
+
service: Service;
|
|
13
|
+
params?: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
lookup(path: string): RouteLookup;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export * from './router';
|
|
21
|
+
export declare const routing: () => (app: Application) => void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.routing = void 0;
|
|
14
|
+
const router_1 = require("./router");
|
|
15
|
+
__exportStar(require("./router"), exports);
|
|
16
|
+
const lookup = function (path) {
|
|
17
|
+
const result = this.routes.lookup(path);
|
|
18
|
+
if (result === null) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const { params: colonParams, data: { service, params: dataParams } } = result;
|
|
22
|
+
const params = dataParams ? { ...dataParams, ...colonParams } : colonParams;
|
|
23
|
+
return { service, params };
|
|
24
|
+
};
|
|
25
|
+
const routing = () => (app) => {
|
|
26
|
+
if (typeof app.lookup === 'function') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
app.routes = new router_1.Router();
|
|
30
|
+
app.lookup = lookup;
|
|
31
|
+
// Add a mixin that registers a service on the router
|
|
32
|
+
app.mixins.push((service, path, options) => {
|
|
33
|
+
const { routeParams: params = {} } = options;
|
|
34
|
+
app.routes.insert(path, { service, params });
|
|
35
|
+
app.routes.insert(`${path}/:__id`, { service, params });
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.routing = routing;
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,qCAAkC;AAiBlC,2CAAyB;AAEzB,MAAM,MAAM,GAAG,UAA6B,IAAY;IACtD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAExC,IAAI,MAAM,KAAK,IAAI,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,GAAG,MAAM,CAAC;IAE9E,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;IAE5E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC7B,CAAC,CAAC;AAEK,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,GAAgB,EAAE,EAAE;IAChD,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE;QACpC,OAAO;KACR;IAED,GAAG,CAAC,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IAC1B,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IAEpB,qDAAqD;IACrD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAgB,EAAE,IAAY,EAAE,OAAuB,EAAE,EAAE;QAC1E,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;QAE7C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAfW,QAAA,OAAO,WAelB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface LookupData {
|
|
2
|
+
params: {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
export interface LookupResult<T> extends LookupData {
|
|
7
|
+
data?: T;
|
|
8
|
+
}
|
|
9
|
+
export declare class RouteNode<T = any> {
|
|
10
|
+
name: string;
|
|
11
|
+
depth: number;
|
|
12
|
+
data?: T;
|
|
13
|
+
children: {
|
|
14
|
+
[key: string]: RouteNode;
|
|
15
|
+
};
|
|
16
|
+
placeholders: RouteNode[];
|
|
17
|
+
constructor(name: string, depth: number);
|
|
18
|
+
insert(path: string[], data: T): RouteNode<T>;
|
|
19
|
+
lookup(path: string[], info: LookupData): LookupResult<T> | null;
|
|
20
|
+
}
|
|
21
|
+
export declare class Router<T = any> {
|
|
22
|
+
root: RouteNode<T>;
|
|
23
|
+
constructor(root?: RouteNode<T>);
|
|
24
|
+
getPath(path: string): string[];
|
|
25
|
+
insert(path: string, data: T): RouteNode<T>;
|
|
26
|
+
lookup(path: string): LookupResult<T>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Router = exports.RouteNode = void 0;
|
|
4
|
+
const commons_1 = require("@feathersjs/commons");
|
|
5
|
+
class RouteNode {
|
|
6
|
+
constructor(name, depth) {
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.depth = depth;
|
|
9
|
+
this.children = {};
|
|
10
|
+
this.placeholders = [];
|
|
11
|
+
}
|
|
12
|
+
insert(path, data) {
|
|
13
|
+
if (this.depth === path.length) {
|
|
14
|
+
if (this.data !== undefined) {
|
|
15
|
+
throw new Error(`Path ${path.join('/')} already exists`);
|
|
16
|
+
}
|
|
17
|
+
this.data = data;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
const current = path[this.depth];
|
|
21
|
+
const nextDepth = this.depth + 1;
|
|
22
|
+
if (current.startsWith(':')) {
|
|
23
|
+
// Insert a placeholder node like /messages/:id
|
|
24
|
+
const placeholderName = current.substring(1);
|
|
25
|
+
let placeholder = this.placeholders.find(p => p.name === placeholderName);
|
|
26
|
+
if (!placeholder) {
|
|
27
|
+
placeholder = new RouteNode(placeholderName, nextDepth);
|
|
28
|
+
this.placeholders.push(placeholder);
|
|
29
|
+
}
|
|
30
|
+
return placeholder.insert(path, data);
|
|
31
|
+
}
|
|
32
|
+
const child = this.children[current] || new RouteNode(current, nextDepth);
|
|
33
|
+
this.children[current] = child;
|
|
34
|
+
return child.insert(path, data);
|
|
35
|
+
}
|
|
36
|
+
lookup(path, info) {
|
|
37
|
+
if (path.length === this.depth) {
|
|
38
|
+
return this.data === undefined ? null : {
|
|
39
|
+
...info,
|
|
40
|
+
data: this.data
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const current = path[this.depth];
|
|
44
|
+
const child = this.children[current];
|
|
45
|
+
if (child) {
|
|
46
|
+
return child.lookup(path, info);
|
|
47
|
+
}
|
|
48
|
+
// This will return the first placeholder that matches early
|
|
49
|
+
for (const placeholder of this.placeholders) {
|
|
50
|
+
const result = placeholder.lookup(path, info);
|
|
51
|
+
if (result !== null) {
|
|
52
|
+
result.params[placeholder.name] = current;
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.RouteNode = RouteNode;
|
|
60
|
+
class Router {
|
|
61
|
+
constructor(root = new RouteNode('', 0)) {
|
|
62
|
+
this.root = root;
|
|
63
|
+
}
|
|
64
|
+
getPath(path) {
|
|
65
|
+
return (0, commons_1.stripSlashes)(path).split('/');
|
|
66
|
+
}
|
|
67
|
+
insert(path, data) {
|
|
68
|
+
return this.root.insert(this.getPath(path), data);
|
|
69
|
+
}
|
|
70
|
+
lookup(path) {
|
|
71
|
+
if (typeof path !== 'string') {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return this.root.lookup(this.getPath(path), { params: {} });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.Router = Router;
|
|
78
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/routing/router.ts"],"names":[],"mappings":";;;AAAA,iDAAmD;AAUnD,MAAa,SAAS;IAKpB,YAAoB,IAAY,EAAS,KAAa;QAA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O,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,CAAE,IAAY;QAClB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC5B,OAAO,IAAI,CAAC;SACb;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF;AAlBD,wBAkBC"}
|
package/lib/socket/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.socket = void 0;
|
|
7
|
-
const
|
|
4
|
+
const feathers_1 = require("@feathersjs/feathers");
|
|
5
|
+
const commons_1 = require("@feathersjs/commons");
|
|
8
6
|
const channels_1 = require("../channels");
|
|
9
7
|
const routing_1 = require("../routing");
|
|
10
8
|
const utils_1 = require("./utils");
|
|
11
|
-
const debug =
|
|
9
|
+
const debug = (0, commons_1.createDebug)('@feathersjs/transport-commons');
|
|
12
10
|
function socket({ done, emit, socketMap, socketKey, getParams }) {
|
|
13
11
|
return (app) => {
|
|
14
12
|
const leaveChannels = (connection) => {
|
|
@@ -17,9 +15,9 @@ function socket({ done, emit, socketMap, socketKey, getParams }) {
|
|
|
17
15
|
app.channel(app.channels).leave(connection);
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
|
-
app.configure(channels_1.channels());
|
|
21
|
-
app.configure(routing_1.routing());
|
|
22
|
-
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));
|
|
23
21
|
app.on('disconnect', leaveChannels);
|
|
24
22
|
app.on('logout', (_authResult, params) => {
|
|
25
23
|
const { connection } = params;
|
|
@@ -31,25 +29,20 @@ function socket({ done, emit, socketMap, socketKey, getParams }) {
|
|
|
31
29
|
done.then(provider => provider.on('connection', (connection) => app.emit('connection', getParams(connection))));
|
|
32
30
|
// `socket.emit('methodName', 'serviceName', ...args)` handlers
|
|
33
31
|
done.then(provider => provider.on('connection', (connection) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const methodHandlers = Object.keys(app.services).reduce((result, name) => {
|
|
33
|
+
const { methods } = (0, feathers_1.getServiceOptions)(app.service(name));
|
|
34
|
+
methods.forEach(method => {
|
|
35
|
+
if (!result[method]) {
|
|
36
|
+
result[method] = (...args) => {
|
|
37
|
+
const path = args.shift();
|
|
38
|
+
debug(`Got '${method}' call for service '${path}'`);
|
|
39
|
+
(0, utils_1.runMethod)(app, getParams(connection), path, method, args);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
39
42
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
debug('Got legacy authenticate event');
|
|
44
|
-
utils_1.runMethod(app, getParams(connection), app.get('defaultAuthentication'), 'create', args);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
connection.on('logout', (callback) => {
|
|
48
|
-
if (app.get('defaultAuthentication')) {
|
|
49
|
-
debug('Got legacy authenticate event');
|
|
50
|
-
utils_1.runMethod(app, getParams(connection), app.get('defaultAuthentication'), 'remove', [null, {}, callback]);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
43
|
+
return result;
|
|
44
|
+
}, {});
|
|
45
|
+
Object.keys(methodHandlers).forEach(key => connection.on(key, methodHandlers[key]));
|
|
53
46
|
}));
|
|
54
47
|
};
|
|
55
48
|
}
|
package/lib/socket/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":";;;AAAA,mDAA8E;AAC9E,iDAAkD;AAClD,0CAAuC;AACvC,wCAAqC;AACrC,mCAAmD;AAGnD,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,+BAA+B,CAAC,CAAC;AAU3D,SAAgB,MAAM,CAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAiB;IACpF,OAAO,CAAC,GAAgB,EAAE,EAAE;QAC1B,MAAM,aAAa,GAAG,CAAC,UAA8B,EAAE,EAAE;YACvD,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC;YAEzB,IAAI,QAAQ,CAAC,MAAM,EAAE;gBACnB,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;aAC7C;QACH,CAAC,CAAC;QAEF,GAAG,CAAC,SAAS,CAAC,IAAA,mBAAQ,GAAE,CAAC,CAAC;QAC1B,GAAG,CAAC,SAAS,CAAC,IAAA,iBAAO,GAAE,CAAC,CAAC;QAEzB,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,IAAA,qBAAa,EAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;QAC7D,GAAG,CAAC,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QACpC,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,WAAgB,EAAE,MAAc,EAAE,EAAE;YACpD,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;YAE9B,IAAI,UAAU,EAAE;gBACd,aAAa,CAAC,UAAU,CAAC,CAAC;aAC3B;QACH,CAAC,CAAC,CAAC;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GAAG,CAAC,CAAC,CACxC,CAAC;QACJ,CAAC,CAAC,CAAC,CAAC;IACN,CAAC,CAAC;AACJ,CAAC;AApDD,wBAoDC"}
|
package/lib/socket/utils.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { HookContext, Application } from '@feathersjs/feathers';
|
|
2
2
|
import { CombinedChannel } from '../channels/channel/combined';
|
|
3
3
|
import { RealTimeConnection } from '../channels/channel/base';
|
|
4
|
+
export declare const DEFAULT_PARAMS_POSITION = 1;
|
|
4
5
|
export declare const paramsPositions: {
|
|
5
6
|
[key: string]: number;
|
|
6
7
|
};
|
|
7
8
|
export declare function normalizeError(e: any): any;
|
|
8
9
|
export declare function getDispatcher(emit: string, socketMap: WeakMap<RealTimeConnection, any>, socketKey?: any): (event: string, channel: CombinedChannel, context: HookContext, data?: any) => void;
|
|
9
|
-
export declare function runMethod(app: Application, connection: RealTimeConnection, path: string, method: string, args: any[]): void
|
|
10
|
+
export declare function runMethod(app: Application, connection: RealTimeConnection, path: string, method: string, args: any[]): Promise<void>;
|
package/lib/socket/utils.js
CHANGED
|
@@ -3,16 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.runMethod = exports.getDispatcher = exports.normalizeError = exports.paramsPositions = void 0;
|
|
7
|
-
const
|
|
8
|
-
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
6
|
+
exports.runMethod = exports.getDispatcher = exports.normalizeError = exports.paramsPositions = exports.DEFAULT_PARAMS_POSITION = void 0;
|
|
7
|
+
const feathers_1 = require("@feathersjs/feathers");
|
|
9
8
|
const errors_1 = require("@feathersjs/errors");
|
|
10
|
-
const
|
|
9
|
+
const commons_1 = require("@feathersjs/commons");
|
|
10
|
+
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
11
|
+
const debug = (0, commons_1.createDebug)('@feathersjs/transport-commons');
|
|
12
|
+
exports.DEFAULT_PARAMS_POSITION = 1;
|
|
11
13
|
exports.paramsPositions = {
|
|
12
14
|
find: 0,
|
|
13
|
-
get: 1,
|
|
14
|
-
remove: 1,
|
|
15
|
-
create: 1,
|
|
16
15
|
update: 2,
|
|
17
16
|
patch: 2
|
|
18
17
|
};
|
|
@@ -43,7 +42,7 @@ function getDispatcher(emit, socketMap, socketKey) {
|
|
|
43
42
|
// If we are getting events from an array but try to dispatch individual data
|
|
44
43
|
// try to get the individual item to dispatch from the correct index.
|
|
45
44
|
if (!Array.isArray(data) && Array.isArray(context.result) && Array.isArray(result)) {
|
|
46
|
-
result = context.result.find(resultData => isEqual_1.default(resultData, data));
|
|
45
|
+
result = context.result.find(resultData => (0, isEqual_1.default)(resultData, data));
|
|
47
46
|
}
|
|
48
47
|
debug(`Dispatching '${eventName}' to Socket ${socket.id} with`, result);
|
|
49
48
|
socket[emit](eventName, result);
|
|
@@ -52,7 +51,7 @@ function getDispatcher(emit, socketMap, socketKey) {
|
|
|
52
51
|
};
|
|
53
52
|
}
|
|
54
53
|
exports.getDispatcher = getDispatcher;
|
|
55
|
-
function runMethod(app, connection, path, method, args) {
|
|
54
|
+
async function runMethod(app, connection, path, method, args) {
|
|
56
55
|
const trace = `method '${method}' on service '${path}'`;
|
|
57
56
|
const methodArgs = args.slice(0);
|
|
58
57
|
const callback = typeof methodArgs[methodArgs.length - 1] === 'function'
|
|
@@ -62,36 +61,32 @@ function runMethod(app, connection, path, method, args) {
|
|
|
62
61
|
debug(`Error in ${trace}`, error);
|
|
63
62
|
callback(normalizeError(error));
|
|
64
63
|
};
|
|
65
|
-
|
|
66
|
-
const _run = () => {
|
|
64
|
+
try {
|
|
67
65
|
const lookup = app.lookup(path);
|
|
68
|
-
// No valid service was found
|
|
69
|
-
// just like a REST route would
|
|
66
|
+
// No valid service was found throw a NotFound error
|
|
70
67
|
if (lookup === null) {
|
|
71
|
-
|
|
68
|
+
throw new errors_1.NotFound(`Service '${path}' not found`);
|
|
72
69
|
}
|
|
73
70
|
const { service, params: route = {} } = lookup;
|
|
71
|
+
const { methods } = (0, feathers_1.getServiceOptions)(service);
|
|
74
72
|
// Only service methods are allowed
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return Promise.reject(new errors_1.MethodNotAllowed(`Method '${method}' not allowed on service '${path}'`));
|
|
73
|
+
if (!methods.includes(method)) {
|
|
74
|
+
throw new errors_1.MethodNotAllowed(`Method '${method}' not allowed on service '${path}'`);
|
|
78
75
|
}
|
|
79
|
-
const position = exports.paramsPositions[method];
|
|
76
|
+
const position = exports.paramsPositions[method] !== undefined ? exports.paramsPositions[method] : exports.DEFAULT_PARAMS_POSITION;
|
|
80
77
|
const query = methodArgs[position] || {};
|
|
81
|
-
// `params` have to be re-mapped to the query
|
|
82
|
-
// and added with the route
|
|
78
|
+
// `params` have to be re-mapped to the query and added with the route
|
|
83
79
|
const params = Object.assign({ query, route, connection }, connection);
|
|
80
|
+
// `params` is always the last parameter. Error if we got more arguments.
|
|
81
|
+
if (methodArgs.length > (position + 1)) {
|
|
82
|
+
throw new errors_1.BadRequest(`Too many arguments for '${method}' method`);
|
|
83
|
+
}
|
|
84
84
|
methodArgs[position] = params;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
_run().then((hook) => {
|
|
91
|
-
const result = hook.dispatch || hook.result;
|
|
92
|
-
debug(`Returned successfully ${trace}`, result);
|
|
93
|
-
callback(null, result);
|
|
94
|
-
}).catch((hook) => handleError(hook.type === 'error' ? hook.error : hook));
|
|
85
|
+
const ctx = (0, feathers_1.createContext)(service, method);
|
|
86
|
+
const returnedCtx = await service[method](...methodArgs, ctx);
|
|
87
|
+
const result = returnedCtx.dispatch || returnedCtx.result;
|
|
88
|
+
debug(`Returned successfully ${trace}`, result);
|
|
89
|
+
callback(null, result);
|
|
95
90
|
}
|
|
96
91
|
catch (error) {
|
|
97
92
|
handleError(error);
|
package/lib/socket/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/socket/utils.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/socket/utils.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAkG;AAClG,+CAA4E;AAC5E,iDAAkD;AAClD,6DAAqC;AAIrC,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,+BAA+B,CAAC,CAAC;AAE9C,QAAA,uBAAuB,GAAG,CAAC,CAAC;AAE5B,QAAA,eAAe,GAA8B;IACxD,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,SAAgB,cAAc,CAAE,CAAM;IACpC,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC;IACjD,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE3C,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAC1C,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,OAAO,MAAM,CAAC,KAAK,CAAC;KACrB;IAED,OAAO,MAAM,CAAC,IAAI,CAAC;IAEnB,OAAO,MAAM,CAAC;AAChB,CAAC;AAjBD,wCAiBC;AAED,SAAgB,aAAa,CAAE,IAAY,EAAE,SAA2C,EAAE,SAAe;IACvG,OAAO,UAAU,KAAa,EAAE,OAAwB,EAAE,OAAoB,EAAE,IAAU;QACxF,KA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tE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,UAAU,CAAC,CAAC;QAEvE,yEAAyE;QACzE,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE;YACtC,MAAM,IAAI,mBAAU,CAAC,2BAA2B,MAAM,UAAU,CAAC,CAAC;SACnE;QAED,UAAU,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;QAE9B,MAAM,GAAG,GAAG,IAAA,wBAAa,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAgB,MAAO,OAAe,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,EAAE,GAAG,CAAC,CAAC;QACpF,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,MAAM,CAAC;QAE1D,KAAK,CAAC,yBAAyB,KAAK,EAAE,EAAE,MAAM,CAAC,CAAC;QAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;KACxB;IAAC,OAAO,KAAU,EAAE;QACnB,WAAW,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC;AAlDD,8BAkDC"}
|
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-pre.
|
|
4
|
+
"version": "5.0.0-pre.15",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"url": "https://github.com/feathersjs/feathers/issues"
|
|
29
29
|
},
|
|
30
30
|
"engines": {
|
|
31
|
-
"node": ">=
|
|
31
|
+
"node": ">= 12"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"prepublish": "npm run compile",
|
|
@@ -52,21 +52,19 @@
|
|
|
52
52
|
"*.js"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
56
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
57
|
-
"
|
|
58
|
-
"lodash": "^4.17.
|
|
59
|
-
"radix-router": "^3.0.1"
|
|
55
|
+
"@feathersjs/commons": "^5.0.0-pre.15",
|
|
56
|
+
"@feathersjs/errors": "^5.0.0-pre.15",
|
|
57
|
+
"@feathersjs/feathers": "^5.0.0-pre.15",
|
|
58
|
+
"lodash": "^4.17.21"
|
|
60
59
|
},
|
|
61
60
|
"devDependencies": {
|
|
62
|
-
"@
|
|
63
|
-
"@types/
|
|
64
|
-
"@types/
|
|
65
|
-
"
|
|
66
|
-
"mocha": "^8.2.1",
|
|
61
|
+
"@types/lodash": "^4.14.176",
|
|
62
|
+
"@types/mocha": "^9.0.0",
|
|
63
|
+
"@types/node": "^16.11.6",
|
|
64
|
+
"mocha": "^9.1.3",
|
|
67
65
|
"shx": "^0.3.3",
|
|
68
|
-
"ts-node": "^
|
|
69
|
-
"typescript": "^4.
|
|
66
|
+
"ts-node": "^10.4.0",
|
|
67
|
+
"typescript": "^4.4.4"
|
|
70
68
|
},
|
|
71
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "8008bf4f8529a2a40b6a2f976c1f43ae13675693"
|
|
72
70
|
}
|
|
@@ -43,7 +43,7 @@ export class Channel extends EventEmitter {
|
|
|
43
43
|
|
|
44
44
|
join (...connections: RealTimeConnection[]) {
|
|
45
45
|
connections.forEach(connection => {
|
|
46
|
-
if (this.connections.indexOf(connection) === -1) {
|
|
46
|
+
if (connection && this.connections.indexOf(connection) === -1) {
|
|
47
47
|
this.connections.push(connection);
|
|
48
48
|
}
|
|
49
49
|
});
|
|
@@ -48,8 +48,7 @@ export class CombinedChannel extends Channel {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
private callChildren (method: string, connections: RealTimeConnection[]) {
|
|
51
|
-
|
|
52
|
-
this.children.forEach(child => child[method](...connections));
|
|
51
|
+
this.children.forEach((child: any) => child[method](...connections));
|
|
53
52
|
this.refresh();
|
|
54
53
|
|
|
55
54
|
return this;
|
package/src/channels/index.ts
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Application, FeathersService, getServiceOptions } from '@feathersjs/feathers';
|
|
2
|
+
import { createDebug } from '@feathersjs/commons';
|
|
2
3
|
import { compact, flattenDeep, noop } from 'lodash';
|
|
3
4
|
import { Channel, RealTimeConnection } from './channel/base';
|
|
4
5
|
import { CombinedChannel } from './channel/combined';
|
|
5
6
|
import { channelMixin, publishMixin, keys, PublishMixin, Event, Publisher } from './mixins';
|
|
6
|
-
import
|
|
7
|
+
import EventEmitter from 'events';
|
|
7
8
|
|
|
8
|
-
const debug =
|
|
9
|
+
const debug = createDebug('@feathersjs/transport-commons/channels');
|
|
9
10
|
const { CHANNELS } = keys;
|
|
10
11
|
|
|
11
12
|
declare module '@feathersjs/feathers/lib/declarations' {
|
|
12
|
-
interface ServiceAddons<
|
|
13
|
-
publish (publisher: Publisher<
|
|
14
|
-
publish (event: Event, publisher: Publisher<
|
|
13
|
+
interface ServiceAddons<A, S> extends EventEmitter { // eslint-disable-line
|
|
14
|
+
publish (publisher: Publisher<ServiceGenericType<S>, A, this>): this;
|
|
15
|
+
publish (event: Event, publisher: Publisher<ServiceGenericType<S>, A, this>): this;
|
|
15
16
|
|
|
16
|
-
registerPublisher (publisher: Publisher<
|
|
17
|
-
registerPublisher (event: Event, publisher: Publisher<
|
|
17
|
+
registerPublisher (publisher: Publisher<ServiceGenericType<S>, A, this>): this;
|
|
18
|
+
registerPublisher (event: Event, publisher: Publisher<ServiceGenericType<S>, A, this>): this;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
interface Application<
|
|
21
|
+
interface Application<Services, Settings> { // eslint-disable-line
|
|
21
22
|
channels: string[];
|
|
22
23
|
|
|
23
|
-
channel (name: string[]): Channel;
|
|
24
|
+
channel (name: string | string[]): Channel;
|
|
24
25
|
channel (...names: string[]): Channel;
|
|
25
26
|
|
|
26
|
-
publish<T> (publisher: Publisher<T>): this;
|
|
27
|
-
publish<T> (event: Event, publisher: Publisher<T>): this;
|
|
27
|
+
publish<T> (publisher: Publisher<T, this>): this;
|
|
28
|
+
publish<T> (event: Event, publisher: Publisher<T, this>): this;
|
|
28
29
|
|
|
29
|
-
registerPublisher<T> (publisher: Publisher<T>): this;
|
|
30
|
-
registerPublisher<T> (event: Event, publisher: Publisher<T>): this;
|
|
30
|
+
registerPublisher<T> (publisher: Publisher<T, this>): this;
|
|
31
|
+
registerPublisher<T> (event: Event, publisher: Publisher<T, this>): this;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
interface Params {
|
|
@@ -50,15 +51,16 @@ export function channels () {
|
|
|
50
51
|
}
|
|
51
52
|
});
|
|
52
53
|
|
|
53
|
-
app.mixins.push((service:
|
|
54
|
-
|
|
54
|
+
app.mixins.push((service: FeathersService, path: string) => {
|
|
55
|
+
const { serviceEvents } = getServiceOptions(service);
|
|
56
|
+
|
|
57
|
+
if (typeof service.publish === 'function') {
|
|
55
58
|
return;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
Object.assign(service, publishMixin());
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
service._serviceEvents.forEach((event: string) => {
|
|
63
|
+
serviceEvents.forEach((event: string) => {
|
|
62
64
|
service.on(event, function (data, hook) {
|
|
63
65
|
if (!hook) {
|
|
64
66
|
// Fake hook for custom events
|
|
@@ -100,7 +102,7 @@ export function channels () {
|
|
|
100
102
|
debug('No connections to publish to');
|
|
101
103
|
}
|
|
102
104
|
}).catch(logError);
|
|
103
|
-
} catch (error) {
|
|
105
|
+
} catch (error: any) {
|
|
104
106
|
logError(error);
|
|
105
107
|
}
|
|
106
108
|
});
|
package/src/channels/mixins.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
2
|
-
import
|
|
2
|
+
import { Application, HookContext, getServiceOptions } from '@feathersjs/feathers';
|
|
3
|
+
import { createDebug } from '@feathersjs/commons';
|
|
3
4
|
import { Channel } from './channel/base';
|
|
4
5
|
import { CombinedChannel } from './channel/combined';
|
|
5
|
-
import { HookContext } from '@feathersjs/feathers';
|
|
6
6
|
|
|
7
|
-
const debug =
|
|
7
|
+
const debug = createDebug('@feathersjs/transport-commons:channels/mixins');
|
|
8
8
|
const PUBLISHERS = Symbol('@feathersjs/transport-commons/publishers');
|
|
9
9
|
const CHANNELS = Symbol('@feathersjs/transport-commons/channels');
|
|
10
10
|
const ALL_EVENTS = Symbol('@feathersjs/transport-commons/all-events');
|
|
@@ -63,7 +63,7 @@ export function channelMixin () {
|
|
|
63
63
|
|
|
64
64
|
export type Event = string|(typeof ALL_EVENTS);
|
|
65
65
|
|
|
66
|
-
export type Publisher<T = any> = (data: T, context: HookContext<
|
|
66
|
+
export type Publisher<T = any, A = Application, S = any> = (data: T, context: HookContext<A, S>) => Channel | Channel[] | void | Promise<Channel | Channel[] | void>;
|
|
67
67
|
|
|
68
68
|
export interface PublishMixin<T = any> {
|
|
69
69
|
[PUBLISHERS]: { [ALL_EVENTS]?: Publisher<T>, [key: string]: Publisher<T> };
|
|
@@ -87,8 +87,9 @@ export function publishMixin () {
|
|
|
87
87
|
event = ALL_EVENTS;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
const { serviceEvents } = getServiceOptions(this);
|
|
91
|
+
|
|
92
|
+
if (event !== ALL_EVENTS && !serviceEvents.includes(event)) {
|
|
92
93
|
throw new Error(`'${event.toString()}' is not a valid service event`);
|
|
93
94
|
}
|
|
94
95
|
|