@imqueue/rpc 2.0.6 → 2.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imqueue/rpc",
3
- "version": "2.0.6",
3
+ "version": "2.0.9",
4
4
  "description": "RPC-like client-service implementation over messaging queue",
5
5
  "keywords": [
6
6
  "redis",
@@ -14,10 +14,9 @@
14
14
  ],
15
15
  "scripts": {
16
16
  "prepublishOnly": "./node_modules/.bin/tsc",
17
- "test": "./node_modules/.bin/tsc && ./node_modules/.bin/nyc mocha && ./node_modules/.bin/nyc report --reporter=text-lcov && npm run test-coverage",
17
+ "test": "./node_modules/.bin/tsc && ./node_modules/.bin/nyc mocha && ./node_modules/.bin/nyc report --reporter=text-lcov",
18
18
  "test-fast": "./node_modules/.bin/tsc && ./node_modules/.bin/nyc mocha && /usr/bin/env node -e \"import('open').then(open => open.default('file://`pwd`/coverage/index.html', { wait: false }))\"",
19
19
  "test-local": "export COVERALLS_REPO_TOKEN=$IMQ_RPC_COVERALLS_TOKEN && npm test && /usr/bin/env node -e \"import('open').then(open => open.default('https://coveralls.io/github/imqueue/imq-rpc', { wait: false }));\"",
20
- "test-coverage": "cat ./coverage/lcov.info | CODECLIMATE_API_HOST=https://codebeat.co/webhooks/code_coverage CODECLIMATE_REPO_TOKEN=c2cc3954-6824-4cdf-8349-12bd9c31955a ./node_modules/.bin/codeclimate-test-reporter",
21
20
  "clean-typedefs": "find . -name '*.d.ts' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
22
21
  "clean-maps": "find . -name '*.js.map' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
23
22
  "clean-js": "find . -name '*.js' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
@@ -38,13 +37,13 @@
38
37
  "author": "imqueue.com <support@imqueue.com> (https://imqueue.com)",
39
38
  "license": "GPL-3.0-only",
40
39
  "dependencies": {
41
- "@imqueue/core": "^2.0.4",
42
- "@types/node": "^24.0.8",
40
+ "@imqueue/core": "^2.0.6",
41
+ "@types/node": "^24.2.1",
43
42
  "acorn": "^8.15.0",
44
43
  "farmhash": "^4.0.2",
45
44
  "node-machine-id": "^1.1.12",
46
45
  "reflect-metadata": "^0.2.2",
47
- "typescript": "^5.8.3"
46
+ "typescript": "^5.9.2"
48
47
  },
49
48
  "devDependencies": {
50
49
  "@types/chai": "^5.2.2",
@@ -52,8 +51,7 @@
52
51
  "@types/mock-require": "^3.0.0",
53
52
  "@types/sinon": "^17.0.4",
54
53
  "chai": "^5.2.0",
55
- "codeclimate-test-reporter": "^0.5.1",
56
- "coveralls-next": "^4.2.1",
54
+ "coveralls-next": "^5.0.0",
57
55
  "minimist": "^1.2.8",
58
56
  "mocha": "^11.7.1",
59
57
  "mocha-lcov-reporter": "^1.3.0",
@@ -63,7 +61,7 @@
63
61
  "sinon": "^21.0.0",
64
62
  "source-map-support": "^0.5.21",
65
63
  "ts-node": "^10.9.2",
66
- "typedoc": "^0.28.7"
64
+ "typedoc": "^0.28.10"
67
65
  },
68
66
  "main": "index.js",
69
67
  "typescript": {
package/src/IMQService.js CHANGED
@@ -41,7 +41,7 @@ const cluster = require('cluster');
41
41
  class Description {
42
42
  }
43
43
  exports.Description = Description;
44
- let serviceDescription = null;
44
+ const serviceDescriptions = new Map();
45
45
  /**
46
46
  * Returns collection of class methods metadata even those are inherited
47
47
  * from a chain of parent classes
@@ -134,7 +134,18 @@ class IMQService {
134
134
  response.error = (0, _1.IMQError)('IMQ_RPC_NO_METHOD', `Method ${this.name}.${method}() does not exist.`, new Error().stack, method, args);
135
135
  }
136
136
  else if (!description.service.methods[method]) {
137
- response.error = (0, _1.IMQError)('IMQ_RPC_NO_ACCESS', `Access to ${this.name}.${method}() denied!`, new Error().stack, method, args);
137
+ // Allow calling runtime-attached methods (own props) even if
138
+ // they are not present in the exposed service description.
139
+ // Deny access for prototype (class) methods not decorated with @expose.
140
+ const isOwn = Object.prototype.hasOwnProperty.call(this, method);
141
+ const value = this[method];
142
+ const proto = Object.getPrototypeOf(this);
143
+ const protoValue = proto && proto[method];
144
+ const isSameAsProto = typeof protoValue === 'function' && value === protoValue;
145
+ // Allow only truly dynamic own-instance functions (not the same as prototype)
146
+ if (!(isOwn && typeof value === 'function' && !isSameAsProto)) {
147
+ response.error = (0, _1.IMQError)('IMQ_RPC_NO_ACCESS', `Access to ${this.name}.${method}() denied!`, new Error().stack, method, args);
148
+ }
138
149
  }
139
150
  else if (!isValidArgsCount(description.service.methods[method].arguments, args)) {
140
151
  response.error = (0, _1.IMQError)('IMQ_RPC_INVALID_ARGS_COUNT', `Invalid args count for ${this.name}.${method}().`, new Error().stack, method, args);
@@ -218,16 +229,18 @@ class IMQService {
218
229
  * @returns {Promise<Description>}
219
230
  */
220
231
  describe() {
221
- if (!serviceDescription) {
222
- serviceDescription = {
232
+ let description = serviceDescriptions.get(this.name) || null;
233
+ if (!description) {
234
+ description = {
223
235
  service: {
224
236
  name: this.name,
225
237
  methods: getClassMethods(this.constructor.name)
226
238
  },
227
239
  types: _1.IMQRPCDescription.typesDescription
228
240
  };
241
+ serviceDescriptions.set(this.name, description);
229
242
  }
230
- return serviceDescription;
243
+ return description;
231
244
  }
232
245
  }
233
246
  exports.IMQService = IMQService;
@@ -16,10 +16,6 @@ exports.logged = logged;
16
16
  function logged(options) {
17
17
  return (target, methodName, descriptor) => {
18
18
  const original = descriptor.value;
19
- const logger = options && options.logger
20
- ? options.logger
21
- : options && options.error ? options :
22
- (this === null || this === void 0 ? void 0 : this.logger) || (target === null || target === void 0 ? void 0 : target.logger) || console;
23
19
  const level = (options &&
24
20
  options.level)
25
21
  ? options.level
@@ -28,9 +24,23 @@ function logged(options) {
28
24
  !options.doNotThrow;
29
25
  descriptor.value = async function (...args) {
30
26
  try {
31
- return original && await original.apply(this || target, args);
27
+ const ctx = (typeof this !== 'undefined' && this !== null)
28
+ ? this
29
+ : target;
30
+ if (original) {
31
+ return await original.apply(ctx, args);
32
+ }
32
33
  }
33
34
  catch (err) {
35
+ const logger = (options && options.logger)
36
+ ? options.logger
37
+ : (options && options.error)
38
+ ? options
39
+ : (this && this.logger)
40
+ ? this.logger
41
+ : (target && target.logger)
42
+ ? target.logger
43
+ : console;
34
44
  logger[level](err);
35
45
  if (doThrow) {
36
46
  throw err;
package/debug.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};