@feathersjs/transport-commons 5.0.0-pre.2 → 5.0.0-pre.22

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.
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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
- const routes = new router_1.Router();
21
- Object.assign(app, {
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
- app.routes.insert(path, service);
35
- app.routes.insert(`${path}/:__id`, service);
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;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,qCAAkC;AAclC,2CAAyB;AAElB,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,GAAgB,EAAE,EAAE;IAChD,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE;QACpC,OAAO;KACR;IAED,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IAE5B,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;QACjB,MAAM;QACN,MAAM,CAAqB,IAAY;YACrC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAExC,IAAI,MAAM,KAAK,IAAI,EAAE;gBACnB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;gBAEzC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;aAC5B;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC,CAAC;IAEH,qDAAqD;IACrD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAqB,EAAE,IAAY,EAAE,EAAE;QACtD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA3BW,QAAA,OAAO,WA2BlB"}
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,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
11
12
  data?: T;
12
13
  children: {
13
14
  [key: string]: RouteNode;
14
15
  };
15
- placeholder?: RouteNode;
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>;
@@ -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 (path.length === 0) {
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 [current, ...rest] = path;
20
+ const current = path[this.depth];
21
+ const nextDepth = this.depth + 1;
17
22
  if (current.startsWith(':')) {
18
- const { placeholder } = this;
19
- const name = current.substring(1);
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
- this.placeholder = new RouteNode(name);
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 this.placeholder.insert(rest, data);
30
+ return placeholder.insert(path, data);
27
31
  }
28
- this.children[current] = this.children[current] || new RouteNode(current);
29
- return this.children[current].insert(rest, data);
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 === 0) {
33
- return Object.assign(Object.assign({}, info), { data: this.data });
37
+ if (path.length === this.depth) {
38
+ return this.data === undefined ? null : {
39
+ ...info,
40
+ data: this.data
41
+ };
34
42
  }
35
- const [current, ...rest] = path;
43
+ const current = path[this.depth];
36
44
  const child = this.children[current];
37
45
  if (child) {
38
- return child.lookup(rest, info);
46
+ return child.lookup(path, info);
39
47
  }
40
- if (this.placeholder) {
41
- info.params[this.placeholder.name] = current;
42
- return this.placeholder.lookup(rest, info);
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 = new RouteNode('');
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;AACnD,+CAAgD;AAUhD,MAAa,SAAS;IAKpB,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAHhC,aAAQ,GAAiC,EAAE,CAAC;IAGT,CAAC;IAEpC,MAAM,CAAE,IAAc,EAAE,IAAO;QAC7B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,IAAI,CAAC,IAAI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ED,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"}
@@ -1,15 +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
4
  const feathers_1 = require("@feathersjs/feathers");
8
- const debug_1 = __importDefault(require("debug"));
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 = debug_1.default('@feathersjs/transport-commons');
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
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":";;;;;;AAAA,mDAA8E;AAC9E,kDAA0B;AAC1B,0CAAuC;AACvC,wCAAqC;AACrC,mCAAmD;AAGnD,MAAM,KAAK,GAAG,eAAK,CAAC,+BAA+B,CAAC,CAAC;AAUrD,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,mBAAQ,EAAE,CAAC,CAAC;QAC1B,GAAG,CAAC,SAAS,CAAC,iBAAO,EAAE,CAAC,CAAC;QAEzB,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,qBAAa,CAAC,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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xC,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"}
@@ -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 debug = debug_1.default('@feathersjs/transport-commons');
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
- return __awaiter(this, void 0, void 0, function* () {
65
- const trace = `method '${method}' on service '${path}'`;
66
- const methodArgs = args.slice(0);
67
- const callback = typeof methodArgs[methodArgs.length - 1] === 'function'
68
- ? methodArgs.pop() : function () { };
69
- debug(`Running ${trace}`, connection, args);
70
- const handleError = (error) => {
71
- debug(`Error in ${trace}`, error);
72
- callback(normalizeError(error));
73
- };
74
- try {
75
- const lookup = app.lookup(path);
76
- // No valid service was found throw a NotFound error
77
- if (lookup === null) {
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
- catch (error) {
102
- handleError(error);
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
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/socket/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,6DAAqC;AACrC,+CAA4E;AAC5E,mDAAkG;AAIlG,MAAM,K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AgB,CAAC,WAAW,MAAM,6BAA6B,IAAI,GAAG,CAAC,CAAC;SACnF;QAED,MAAM,QAAQ,GAAG,uBAAe,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,uBAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,+BAAuB,CAAC;QAC3G,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;QACtD,sEAAsE;QACtE,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.2",
4
+ "version": "5.0.0-pre.22",
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 compile && npm run mocha",
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.2",
56
- "@feathersjs/errors": "^5.0.0-pre.2",
57
- "debug": "^4.3.1",
56
+ "@feathersjs/commons": "^5.0.0-pre.22",
57
+ "@feathersjs/errors": "^5.0.0-pre.22",
58
+ "@feathersjs/feathers": "^5.0.0-pre.22",
59
+ "encodeurl": "^1.0.2",
58
60
  "lodash": "^4.17.21"
59
61
  },
60
62
  "devDependencies": {
61
- "@feathersjs/feathers": "^5.0.0-pre.2",
62
- "@types/debug": "^4.1.5",
63
- "@types/mocha": "^8.2.2",
64
- "@types/node": "^14.14.37",
65
- "mocha": "^8.3.2",
66
- "shx": "^0.3.3",
67
- "ts-node": "^9.1.1",
68
- "typescript": "^4.2.3"
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": "6e1f888dc5b612d2d77653177622e3f66245a0fb"
72
+ "gitHead": "e452e02063e6d8943a9cae2315ab585bc4f82fb6"
71
73
  }
@@ -1,34 +1,34 @@
1
- import Debug from 'debug';
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 = Debug('@feathersjs/transport-commons/channels');
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>>): this;
15
- publish (event: Event, publisher: Publisher<ServiceGenericType<S>>): this;
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>>): this;
18
- registerPublisher (event: Event, publisher: Publisher<ServiceGenericType<S>>): this;
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<ServiceTypes, AppSettings> { // eslint-disable-line
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<any>, path: string) => {
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 }
@@ -1,10 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
2
- import Debug from 'debug';
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 = Debug('@feathersjs/transport-commons:channels/mixins');
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<T>) => Channel | Channel[] | void | Promise<Channel | Channel[] | void>;
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 = Debug('@feathersjs/transport-commons/client');
5
+ const debug = createDebug('@feathersjs/transport-commons/client');
6
6
 
7
7
  const namespacedEmitterMethods = [
8
8
  'addListener',