@feathersjs/transport-commons 5.0.0-pre.2 → 5.0.0-pre.20
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 +184 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/lib/channels/index.d.ts +13 -11
- package/lib/channels/index.js +11 -11
- package/lib/channels/index.js.map +1 -1
- package/lib/channels/mixins.d.ts +2 -2
- package/lib/channels/mixins.js +4 -7
- package/lib/channels/mixins.js.map +1 -1
- package/lib/client.js +3 -6
- package/lib/client.js.map +1 -1
- package/lib/http.d.ts +35 -0
- package/lib/http.js +77 -0
- package/lib/http.js.map +1 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.js +27 -1
- package/lib/index.js.map +1 -1
- package/lib/routing/index.d.ts +9 -4
- package/lib/routing/index.js +20 -16
- package/lib/routing/index.js.map +1 -1
- package/lib/routing/router.d.ts +5 -3
- package/lib/routing/router.js +35 -23
- package/lib/routing/router.js.map +1 -1
- package/lib/socket/index.js +7 -10
- package/lib/socket/index.js.map +1 -1
- package/lib/socket/utils.js +43 -54
- package/lib/socket/utils.js.map +1 -1
- package/package.json +17 -15
- package/src/channels/index.ts +17 -15
- package/src/channels/mixins.ts +4 -4
- package/src/client.ts +2 -2
- package/src/http.ts +95 -0
- package/src/index.ts +10 -2
- package/src/routing/index.ts +28 -23
- package/src/routing/router.ts +33 -22
- package/src/socket/index.ts +2 -2
- package/src/socket/utils.ts +6 -6
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,26 @@ 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
|
-
|
|
21
|
-
|
|
22
|
-
routes,
|
|
23
|
-
lookup(path) {
|
|
24
|
-
const result = this.routes.lookup(path);
|
|
25
|
-
if (result !== null) {
|
|
26
|
-
const { params, data: service } = result;
|
|
27
|
-
return { params, service };
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
33
|
+
app.routes = new router_1.Router();
|
|
34
|
+
app.lookup = lookup;
|
|
32
35
|
// Add a mixin that registers a service on the router
|
|
33
|
-
app.mixins.push((service, path) => {
|
|
34
|
-
|
|
35
|
-
app.routes.insert(
|
|
36
|
+
app.mixins.push((service, path, options) => {
|
|
37
|
+
const { routeParams: params = {} } = options;
|
|
38
|
+
app.routes.insert(path, { service, params });
|
|
39
|
+
app.routes.insert(`${path}/:__id`, { service, params });
|
|
36
40
|
});
|
|
37
41
|
};
|
|
38
42
|
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,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"}
|
package/lib/routing/router.d.ts
CHANGED
|
@@ -8,17 +8,19 @@ export interface LookupResult<T> extends LookupData {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class RouteNode<T = any> {
|
|
10
10
|
name: string;
|
|
11
|
+
depth: number;
|
|
11
12
|
data?: T;
|
|
12
13
|
children: {
|
|
13
14
|
[key: string]: RouteNode;
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
-
constructor(name: string);
|
|
16
|
+
placeholders: RouteNode[];
|
|
17
|
+
constructor(name: string, depth: number);
|
|
17
18
|
insert(path: string[], data: T): RouteNode<T>;
|
|
18
19
|
lookup(path: string[], info: LookupData): LookupResult<T> | null;
|
|
19
20
|
}
|
|
20
|
-
export declare class Router<T> {
|
|
21
|
+
export declare class Router<T = any> {
|
|
21
22
|
root: RouteNode<T>;
|
|
23
|
+
constructor(root?: RouteNode<T>);
|
|
22
24
|
getPath(path: string): string[];
|
|
23
25
|
insert(path: string, data: T): RouteNode<T>;
|
|
24
26
|
lookup(path: string): LookupResult<T>;
|
package/lib/routing/router.js
CHANGED
|
@@ -2,55 +2,67 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Router = exports.RouteNode = void 0;
|
|
4
4
|
const commons_1 = require("@feathersjs/commons");
|
|
5
|
-
const errors_1 = require("@feathersjs/errors");
|
|
6
5
|
class RouteNode {
|
|
7
|
-
constructor(name) {
|
|
6
|
+
constructor(name, depth) {
|
|
8
7
|
this.name = name;
|
|
8
|
+
this.depth = depth;
|
|
9
9
|
this.children = {};
|
|
10
|
+
this.placeholders = [];
|
|
10
11
|
}
|
|
11
12
|
insert(path, data) {
|
|
12
|
-
if (
|
|
13
|
+
if (this.depth === path.length) {
|
|
14
|
+
if (this.data !== undefined) {
|
|
15
|
+
throw new Error(`Path ${path.join('/')} already exists`);
|
|
16
|
+
}
|
|
13
17
|
this.data = data;
|
|
14
18
|
return this;
|
|
15
19
|
}
|
|
16
|
-
const
|
|
20
|
+
const current = path[this.depth];
|
|
21
|
+
const nextDepth = this.depth + 1;
|
|
17
22
|
if (current.startsWith(':')) {
|
|
18
|
-
|
|
19
|
-
const
|
|
23
|
+
// Insert a placeholder node like /messages/:id
|
|
24
|
+
const placeholderName = current.substring(1);
|
|
25
|
+
let placeholder = this.placeholders.find(p => p.name === placeholderName);
|
|
20
26
|
if (!placeholder) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
else if (placeholder.name !== name) {
|
|
24
|
-
throw new errors_1.BadRequest(`Can not add route with placeholder ':${name}' because placeholder ':${placeholder.name}' already exists`);
|
|
27
|
+
placeholder = new RouteNode(placeholderName, nextDepth);
|
|
28
|
+
this.placeholders.push(placeholder);
|
|
25
29
|
}
|
|
26
|
-
return
|
|
30
|
+
return placeholder.insert(path, data);
|
|
27
31
|
}
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
const child = this.children[current] || new RouteNode(current, nextDepth);
|
|
33
|
+
this.children[current] = child;
|
|
34
|
+
return child.insert(path, data);
|
|
30
35
|
}
|
|
31
36
|
lookup(path, info) {
|
|
32
|
-
if (path.length ===
|
|
33
|
-
return
|
|
37
|
+
if (path.length === this.depth) {
|
|
38
|
+
return this.data === undefined ? null : {
|
|
39
|
+
...info,
|
|
40
|
+
data: this.data
|
|
41
|
+
};
|
|
34
42
|
}
|
|
35
|
-
const
|
|
43
|
+
const current = path[this.depth];
|
|
36
44
|
const child = this.children[current];
|
|
37
45
|
if (child) {
|
|
38
|
-
return child.lookup(
|
|
46
|
+
return child.lookup(path, info);
|
|
39
47
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
}
|
|
43
55
|
}
|
|
44
56
|
return null;
|
|
45
57
|
}
|
|
46
58
|
}
|
|
47
59
|
exports.RouteNode = RouteNode;
|
|
48
60
|
class Router {
|
|
49
|
-
constructor() {
|
|
50
|
-
this.root =
|
|
61
|
+
constructor(root = new RouteNode('', 0)) {
|
|
62
|
+
this.root = root;
|
|
51
63
|
}
|
|
52
64
|
getPath(path) {
|
|
53
|
-
return commons_1.stripSlashes(path).split('/');
|
|
65
|
+
return (0, commons_1.stripSlashes)(path).split('/');
|
|
54
66
|
}
|
|
55
67
|
insert(path, data) {
|
|
56
68
|
return this.root.insert(this.getPath(path), data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/routing/router.ts"],"names":[],"mappings":";;;AAAA,iDAAmD;
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/routing/router.ts"],"names":[],"mappings":";;;AAAA,iDAAmD;AAUnD,MAAa,SAAS;IAKpB,YAAoB,IAAY,EAAS,KAAa;QAAlC,SAAI,GAAJ,IAAI,CAAQ;QAAS,UAAK,GAAL,KAAK,CAAQ;QAHtD,aAAQ,GAAiC,EAAE,CAAC;QAC5C,iBAAY,GAAgB,EAAE,CAAC;IAE0B,CAAC;IAE1D,MAAM,CAAE,IAAc,EAAE,IAAO;QAC7B,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,MAAM,EAAE;YAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;gBAC3B,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;aAC1D;YAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,OAAO,IAAI,CAAC;SACb;QAED,MAAM,OAAO,GAAG,IAAI,CAAC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return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.socket = void 0;
|
|
7
4
|
const feathers_1 = require("@feathersjs/feathers");
|
|
8
|
-
const
|
|
5
|
+
const commons_1 = require("@feathersjs/commons");
|
|
9
6
|
const channels_1 = require("../channels");
|
|
10
7
|
const routing_1 = require("../routing");
|
|
11
8
|
const utils_1 = require("./utils");
|
|
12
|
-
const debug =
|
|
9
|
+
const debug = (0, commons_1.createDebug)('@feathersjs/transport-commons');
|
|
13
10
|
function socket({ done, emit, socketMap, socketKey, getParams }) {
|
|
14
11
|
return (app) => {
|
|
15
12
|
const leaveChannels = (connection) => {
|
|
@@ -18,9 +15,9 @@ function socket({ done, emit, socketMap, socketKey, getParams }) {
|
|
|
18
15
|
app.channel(app.channels).leave(connection);
|
|
19
16
|
}
|
|
20
17
|
};
|
|
21
|
-
app.configure(channels_1.channels());
|
|
22
|
-
app.configure(routing_1.routing());
|
|
23
|
-
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));
|
|
24
21
|
app.on('disconnect', leaveChannels);
|
|
25
22
|
app.on('logout', (_authResult, params) => {
|
|
26
23
|
const { connection } = params;
|
|
@@ -33,13 +30,13 @@ function socket({ done, emit, socketMap, socketKey, getParams }) {
|
|
|
33
30
|
// `socket.emit('methodName', 'serviceName', ...args)` handlers
|
|
34
31
|
done.then(provider => provider.on('connection', (connection) => {
|
|
35
32
|
const methodHandlers = Object.keys(app.services).reduce((result, name) => {
|
|
36
|
-
const { methods } = feathers_1.getServiceOptions(app.service(name));
|
|
33
|
+
const { methods } = (0, feathers_1.getServiceOptions)(app.service(name));
|
|
37
34
|
methods.forEach(method => {
|
|
38
35
|
if (!result[method]) {
|
|
39
36
|
result[method] = (...args) => {
|
|
40
37
|
const path = args.shift();
|
|
41
38
|
debug(`Got '${method}' call for service '${path}'`);
|
|
42
|
-
utils_1.runMethod(app, getParams(connection), path, method, args);
|
|
39
|
+
(0, utils_1.runMethod)(app, getParams(connection), path, method, args);
|
|
43
40
|
};
|
|
44
41
|
}
|
|
45
42
|
});
|
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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ACF;gBACH,CAAC,CAAC,CAAC;gBAEH,OAAO,MAAM,CAAC;YAChB,CAAC,EAAE,EAAS,CAAC,CAAC;YAEd,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CACxC,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CACxC,CAAC;QACJ,CAAC,CAAC,CAAC,CAAC;IACN,CAAC,CAAC;AACJ,CAAC;AApDD,wBAoDC"}
|
package/lib/socket/utils.js
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
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
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.runMethod = exports.getDispatcher = exports.normalizeError = exports.paramsPositions = exports.DEFAULT_PARAMS_POSITION = void 0;
|
|
16
|
-
const debug_1 = __importDefault(require("debug"));
|
|
17
|
-
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
18
|
-
const errors_1 = require("@feathersjs/errors");
|
|
19
7
|
const feathers_1 = require("@feathersjs/feathers");
|
|
20
|
-
const
|
|
8
|
+
const errors_1 = require("@feathersjs/errors");
|
|
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');
|
|
21
12
|
exports.DEFAULT_PARAMS_POSITION = 1;
|
|
22
13
|
exports.paramsPositions = {
|
|
23
14
|
find: 0,
|
|
@@ -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,46 @@ 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
|
-
throw new errors_1.NotFound(`Service '${path}' not found`);
|
|
79
|
-
}
|
|
80
|
-
const { service, params: route = {} } = lookup;
|
|
81
|
-
const { methods } = feathers_1.getServiceOptions(service);
|
|
82
|
-
// Only service methods are allowed
|
|
83
|
-
if (!methods.includes(method)) {
|
|
84
|
-
throw new errors_1.MethodNotAllowed(`Method '${method}' not allowed on service '${path}'`);
|
|
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 = typeof methodArgs[methodArgs.length - 1] === 'function'
|
|
58
|
+
? methodArgs.pop() : function () { };
|
|
59
|
+
debug(`Running ${trace}`, connection, args);
|
|
60
|
+
const handleError = (error) => {
|
|
61
|
+
debug(`Error in ${trace}`, error);
|
|
62
|
+
callback(normalizeError(error));
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
const lookup = app.lookup(path);
|
|
66
|
+
// No valid service was found throw a NotFound error
|
|
67
|
+
if (lookup === null) {
|
|
68
|
+
throw new errors_1.NotFound(`Service '${path}' not found`);
|
|
100
69
|
}
|
|
101
|
-
|
|
102
|
-
|
|
70
|
+
const { service, params: route = {} } = lookup;
|
|
71
|
+
const { methods } = (0, feathers_1.getServiceOptions)(service);
|
|
72
|
+
// Only service methods are allowed
|
|
73
|
+
if (!methods.includes(method)) {
|
|
74
|
+
throw new errors_1.MethodNotAllowed(`Method '${method}' not allowed on service '${path}'`);
|
|
103
75
|
}
|
|
104
|
-
|
|
76
|
+
const position = exports.paramsPositions[method] !== undefined ? exports.paramsPositions[method] : exports.DEFAULT_PARAMS_POSITION;
|
|
77
|
+
const query = Object.assign({}, methodArgs[position]);
|
|
78
|
+
// `params` have to be re-mapped to the query and added with the route
|
|
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
|
+
methodArgs[position] = params;
|
|
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);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
handleError(error);
|
|
93
|
+
}
|
|
105
94
|
}
|
|
106
95
|
exports.runMethod = runMethod;
|
|
107
96
|
//# 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,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,M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C,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.20",
|
|
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",
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"scripts": {
|
|
34
35
|
"prepublish": "npm run compile",
|
|
35
36
|
"compile": "shx rm -rf lib/ && tsc",
|
|
36
|
-
"test": "npm run
|
|
37
|
+
"test": "npm run mocha",
|
|
37
38
|
"mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
|
|
38
39
|
},
|
|
39
40
|
"directories": {
|
|
@@ -52,20 +53,21 @@
|
|
|
52
53
|
"*.js"
|
|
53
54
|
],
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
56
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
57
|
-
"
|
|
56
|
+
"@feathersjs/commons": "^5.0.0-pre.20",
|
|
57
|
+
"@feathersjs/errors": "^5.0.0-pre.20",
|
|
58
|
+
"@feathersjs/feathers": "^5.0.0-pre.20",
|
|
59
|
+
"encodeurl": "^1.0.2",
|
|
58
60
|
"lodash": "^4.17.21"
|
|
59
61
|
},
|
|
60
62
|
"devDependencies": {
|
|
61
|
-
"@
|
|
62
|
-
"@types/
|
|
63
|
-
"@types/mocha": "^
|
|
64
|
-
"@types/node": "^
|
|
65
|
-
"mocha": "^
|
|
66
|
-
"shx": "^0.3.
|
|
67
|
-
"ts-node": "^
|
|
68
|
-
"typescript": "^4.
|
|
63
|
+
"@types/encodeurl": "^1.0.0",
|
|
64
|
+
"@types/lodash": "^4.14.182",
|
|
65
|
+
"@types/mocha": "^9.1.1",
|
|
66
|
+
"@types/node": "^17.0.31",
|
|
67
|
+
"mocha": "^10.0.0",
|
|
68
|
+
"shx": "^0.3.4",
|
|
69
|
+
"ts-node": "^10.7.0",
|
|
70
|
+
"typescript": "^4.6.4"
|
|
69
71
|
},
|
|
70
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "54de749a0b392c7da726c668002b50cafaca530c"
|
|
71
73
|
}
|
package/src/channels/index.ts
CHANGED
|
@@ -1,34 +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 { Application, FeathersService, getServiceOptions } from '@feathersjs/feathers';
|
|
7
7
|
import EventEmitter from 'events';
|
|
8
8
|
|
|
9
|
-
const debug =
|
|
9
|
+
const debug = createDebug('@feathersjs/transport-commons/channels');
|
|
10
10
|
const { CHANNELS } = keys;
|
|
11
11
|
|
|
12
12
|
declare module '@feathersjs/feathers/lib/declarations' {
|
|
13
13
|
interface ServiceAddons<A, S> extends EventEmitter { // eslint-disable-line
|
|
14
|
-
publish (publisher: Publisher<ServiceGenericType<S
|
|
15
|
-
publish (event: Event, publisher: Publisher<ServiceGenericType<S
|
|
14
|
+
publish (publisher: Publisher<ServiceGenericType<S>, A, this>): this;
|
|
15
|
+
publish (event: Event, publisher: Publisher<ServiceGenericType<S>, A, this>): this;
|
|
16
16
|
|
|
17
|
-
registerPublisher (publisher: Publisher<ServiceGenericType<S
|
|
18
|
-
registerPublisher (event: Event, publisher: Publisher<ServiceGenericType<S
|
|
17
|
+
registerPublisher (publisher: Publisher<ServiceGenericType<S>, A, this>): this;
|
|
18
|
+
registerPublisher (event: Event, publisher: Publisher<ServiceGenericType<S>, A, this>): this;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
interface Application<
|
|
21
|
+
interface Application<Services, Settings> { // eslint-disable-line
|
|
22
22
|
channels: string[];
|
|
23
23
|
|
|
24
|
-
channel (name: string[]): Channel;
|
|
24
|
+
channel (name: string | string[]): Channel;
|
|
25
25
|
channel (...names: string[]): Channel;
|
|
26
26
|
|
|
27
|
-
publish<T> (publisher: Publisher<T>): this;
|
|
28
|
-
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;
|
|
29
29
|
|
|
30
|
-
registerPublisher<T> (publisher: Publisher<T>): this;
|
|
31
|
-
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;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
interface Params {
|
|
@@ -51,7 +51,7 @@ export function channels () {
|
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
app.mixins.push((service: FeathersService
|
|
54
|
+
app.mixins.push((service: FeathersService, path: string) => {
|
|
55
55
|
const { serviceEvents } = getServiceOptions(service);
|
|
56
56
|
|
|
57
57
|
if (typeof service.publish === 'function') {
|
|
@@ -102,7 +102,7 @@ export function channels () {
|
|
|
102
102
|
debug('No connections to publish to');
|
|
103
103
|
}
|
|
104
104
|
}).catch(logError);
|
|
105
|
-
} catch (error) {
|
|
105
|
+
} catch (error: any) {
|
|
106
106
|
logError(error);
|
|
107
107
|
}
|
|
108
108
|
});
|
|
@@ -110,3 +110,5 @@ export function channels () {
|
|
|
110
110
|
});
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
export { Channel, CombinedChannel, RealTimeConnection }
|
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, getServiceOptions } 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> };
|
package/src/client.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Debug from 'debug';
|
|
2
1
|
import { convert } from '@feathersjs/errors';
|
|
2
|
+
import { createDebug } from '@feathersjs/commons';
|
|
3
3
|
import { Id, NullableId, Params, ServiceInterface } from '@feathersjs/feathers';
|
|
4
4
|
|
|
5
|
-
const debug =
|
|
5
|
+
const debug = createDebug('@feathersjs/transport-commons/client');
|
|
6
6
|
|
|
7
7
|
const namespacedEmitterMethods = [
|
|
8
8
|
'addListener',
|