@imqueue/rpc 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/.github/workflows/build.yml +49 -5
  2. package/.oxfmtrc.json +9 -0
  3. package/.oxlintrc.json +37 -0
  4. package/README.md +68 -0
  5. package/package.json +21 -58
  6. package/scripts/strip-comment-coverage.mjs +464 -0
  7. package/src/IMQCache.d.ts +10 -9
  8. package/src/IMQCache.js +16 -22
  9. package/src/IMQClient.d.ts +21 -16
  10. package/src/IMQClient.js +407 -271
  11. package/src/IMQDelay.d.ts +14 -0
  12. package/src/IMQDelay.js +26 -5
  13. package/src/IMQLock.d.ts +17 -15
  14. package/src/IMQLock.js +36 -36
  15. package/src/IMQMetadata.d.ts +8 -0
  16. package/src/IMQMetadata.js +8 -0
  17. package/src/IMQRPCDescription.d.ts +2 -2
  18. package/src/IMQRPCDescription.js +2 -2
  19. package/src/IMQRPCError.d.ts +7 -7
  20. package/src/IMQRPCError.js +7 -8
  21. package/src/IMQRPCOptions.d.ts +27 -3
  22. package/src/IMQRPCOptions.js +17 -3
  23. package/src/IMQRPCRequest.d.ts +1 -1
  24. package/src/IMQRPCResponse.d.ts +1 -1
  25. package/src/IMQRequestContext.js +1 -2
  26. package/src/IMQService.d.ts +3 -4
  27. package/src/IMQService.js +302 -220
  28. package/src/cache/ICache.d.ts +53 -0
  29. package/src/cache/RedisCache.d.ts +30 -25
  30. package/src/cache/RedisCache.js +104 -61
  31. package/src/decorators/cache.d.ts +12 -0
  32. package/src/decorators/cache.js +56 -41
  33. package/src/decorators/classType.d.ts +43 -0
  34. package/src/decorators/classType.js +83 -0
  35. package/src/decorators/expose.d.ts +5 -31
  36. package/src/decorators/expose.js +118 -134
  37. package/src/decorators/index.d.ts +2 -0
  38. package/src/decorators/index.js +4 -0
  39. package/src/decorators/indexed.d.ts +23 -0
  40. package/src/decorators/indexed.js +22 -13
  41. package/src/decorators/lock.d.ts +10 -11
  42. package/src/decorators/lock.js +63 -56
  43. package/src/decorators/logged.d.ts +11 -9
  44. package/src/decorators/logged.js +47 -40
  45. package/src/decorators/metadata.d.ts +24 -0
  46. package/src/decorators/metadata.js +45 -0
  47. package/src/decorators/property.d.ts +7 -57
  48. package/src/decorators/property.js +112 -83
  49. package/src/decorators/remote.d.ts +7 -7
  50. package/src/decorators/remote.js +19 -13
  51. package/src/helpers/fs.d.ts +13 -13
  52. package/src/helpers/fs.js +19 -19
  53. package/src/helpers/os-uuid.d.ts +2 -1
  54. package/src/helpers/os-uuid.js +86 -3
  55. package/src/helpers/pid.d.ts +19 -9
  56. package/src/helpers/pid.js +33 -33
  57. package/src/helpers/signature.d.ts +9 -7
  58. package/src/helpers/signature.js +80 -10
  59. package/src/index.d.ts +0 -1
  60. package/src/index.js +0 -1
  61. package/tsconfig.json +18 -14
  62. package/typedoc.json +19 -0
@@ -1,17 +1,60 @@
1
- name: Node.js CI
1
+ name: Build
2
2
 
3
3
  on:
4
4
  push:
5
+ branches: [master]
6
+ tags: ['*']
5
7
  pull_request:
6
8
 
9
+ permissions:
10
+ contents: read
11
+
12
+ concurrency:
13
+ group: ${{ github.workflow }}-${{ github.ref }}
14
+ cancel-in-progress: true
15
+
7
16
  jobs:
8
- build:
17
+ quality:
18
+ name: Lint & format
9
19
  runs-on: ubuntu-latest
20
+ timeout-minutes: 10
21
+ steps:
22
+ - name: Checkout repository
23
+ uses: actions/checkout@v4
24
+
25
+ - name: Use Node.js
26
+ uses: actions/setup-node@v4
27
+ with:
28
+ node-version: 24.x
29
+ cache: npm
30
+
31
+ - name: Install dependencies
32
+ run: npm ci
33
+
34
+ - name: Check formatting
35
+ run: npm run format:check
10
36
 
37
+ - name: Lint
38
+ run: npm run lint
39
+
40
+ test:
41
+ name: Test (Node ${{ matrix.node-version }})
42
+ runs-on: ubuntu-latest
43
+ timeout-minutes: 15
11
44
  strategy:
45
+ fail-fast: false
12
46
  matrix:
13
- node-version: [lts/*]
14
-
47
+ node-version: [22.x, 24.x]
48
+ services:
49
+ redis:
50
+ image: redis:7
51
+ ports:
52
+ - 6379:6379
53
+ options: >-
54
+ --health-cmd "redis-cli ping"
55
+ --health-interval 10s
56
+ --health-timeout 5s
57
+ --health-retries 5
15
58
  steps:
16
59
  - name: Checkout repository
17
60
  uses: actions/checkout@v4
@@ -20,9 +63,10 @@ jobs:
20
63
  uses: actions/setup-node@v4
21
64
  with:
22
65
  node-version: ${{ matrix.node-version }}
66
+ cache: npm
23
67
 
24
68
  - name: Install dependencies
25
- run: npm install
69
+ run: npm ci
26
70
 
27
71
  - name: Run tests
28
72
  run: npm test
package/.oxfmtrc.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "singleQuote": true,
3
+ "tabWidth": 4,
4
+ "printWidth": 80,
5
+ "semi": true,
6
+ "trailingComma": "all",
7
+ "arrowParens": "avoid",
8
+ "bracketSpacing": true
9
+ }
package/.oxlintrc.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "./node_modules/oxlint/configuration_schema.json",
3
+ "categories": {
4
+ "correctness": "error"
5
+ },
6
+ "rules": {
7
+ "no-debugger": "error",
8
+ "no-console": ["warn", { "allow": ["warn", "error", "info"] }],
9
+ "no-unused-vars": "warn",
10
+ "no-unused-expressions": [
11
+ "error",
12
+ { "allowShortCircuit": true, "allowTernary": true }
13
+ ]
14
+ },
15
+ "overrides": [
16
+ {
17
+ "files": ["test/**"],
18
+ "rules": {
19
+ "no-unused-expressions": "off",
20
+ "no-async-promise-executor": "off",
21
+ "no-useless-catch": "off",
22
+ "unicorn/no-new-array": "off",
23
+ "unicorn/prefer-string-starts-ends-with": "off",
24
+ "unicorn/no-unnecessary-await": "off",
25
+ "no-unused-vars": "off"
26
+ }
27
+ }
28
+ ],
29
+ "ignorePatterns": [
30
+ "**/*.js",
31
+ "**/*.d.ts",
32
+ "docs/",
33
+ "coverage/",
34
+ ".nyc_output/",
35
+ "node_modules/"
36
+ ]
37
+ }
package/README.md CHANGED
@@ -179,6 +179,74 @@ import { hello } from './clients/Hello';
179
179
  In this case all complex types defined within service implementation
180
180
  will be available under imported namespace of the client.
181
181
 
182
+ ## Complex Types
183
+
184
+ To expose complex (object) types as service method arguments or return values,
185
+ annotate the class with `@classType()` and its fields with `@property()`:
186
+
187
+ ~~~typescript
188
+ import { classType, property, expose, IMQService } from '@imqueue/rpc';
189
+
190
+ @classType()
191
+ class Address {
192
+ @property('string')
193
+ country: string;
194
+
195
+ @property('string', true)
196
+ zipCode?: string; // optional
197
+ }
198
+
199
+ @classType()
200
+ class User {
201
+ @property('string')
202
+ firstName: string;
203
+
204
+ @property('Array<Address>', true)
205
+ addresses?: Address[];
206
+ }
207
+
208
+ class UserService extends IMQService {
209
+ /**
210
+ * Persists the given user
211
+ *
212
+ * @param {User} user - user to save
213
+ * @returns {Promise<boolean>}
214
+ */
215
+ @expose()
216
+ public async save(user: User): Promise<boolean> {
217
+ // User and Address are now exposed to generated clients
218
+ return true;
219
+ }
220
+ }
221
+ ~~~
222
+
223
+ The `@classType()` class decorator is **required** on every class that uses
224
+ `@property()` — without it the type will not be registered and will not appear
225
+ in generated clients. (Indexed types use `@indexed()`, which registers `@property`
226
+ fields as well.)
227
+
228
+ ## Requirements
229
+
230
+ This package uses **standard (TC39) decorators**. Consuming projects must set,
231
+ in their `tsconfig.json`:
232
+
233
+ ~~~json
234
+ {
235
+ "compilerOptions": {
236
+ "experimentalDecorators": false,
237
+ "removeComments": false,
238
+ "lib": ["es2023", "esnext.decorators"]
239
+ }
240
+ }
241
+ ~~~
242
+
243
+ Because standard decorators provide no runtime type reflection (there is no
244
+ `emitDecoratorMetadata`), the RPC layer derives argument and return types from
245
+ **JSDoc**. Therefore **every exposed method must be documented with JSDoc**
246
+ `@param`/`@returns` tags carrying the types (as shown in the examples above),
247
+ and `removeComments` must remain `false` so those comments survive compilation.
248
+ Undocumented parameters fall back to `any` in generated clients.
249
+
182
250
  ## Notes
183
251
 
184
252
  For image containers builds assign machine UUID in `/etc/machine-id` and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imqueue/rpc",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "RPC-like client-service implementation over messaging queue",
5
5
  "keywords": [
6
6
  "redis",
@@ -13,10 +13,18 @@
13
13
  "message-queue"
14
14
  ],
15
15
  "scripts": {
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",
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
- "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 }));\"",
16
+ "clean-compiled": "npm run clean-js && npm run clean-typedefs && npm run clean-maps",
17
+ "build:deps": "if [ -f ../core/package.json ]; then npm run build --prefix ../core; fi",
18
+ "build": "npm run build:deps && npm run clean-compiled && tsc",
19
+ "prepublishOnly": "npm run build",
20
+ "lint": "oxlint",
21
+ "format": "oxfmt \"index.ts\" \"debug.ts\" \"src/**/*.ts\" \"test/**/*.ts\"",
22
+ "format:check": "oxfmt --check \"index.ts\" \"debug.ts\" \"src/**/*.ts\" \"test/**/*.ts\"",
23
+ "test": "npm run build && node --test --test-timeout=15000 $(find test -name '*.spec.js')",
24
+ "test-coverage": "npm run build && node --enable-source-maps --test --experimental-test-coverage --test-timeout=15000 $(find test -name '*.spec.js')",
25
+ "test-lcov": "npm run build && mkdir -p coverage && node --enable-source-maps --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-timeout=15000 $(find test -name '*.spec.js'); node scripts/strip-comment-coverage.mjs coverage/lcov.info",
26
+ "test-coverage-html": "npm run test-lcov; genhtml coverage/lcov.info --output-directory coverage/html --ignore-errors inconsistent,corrupt,format,mismatch && echo \"Coverage report: file://$(pwd)/coverage/html/index.html\"",
27
+ "test-dev": "npm run test && npm run clean-js && npm run clean-typedefs && npm run clean-maps",
20
28
  "clean-typedefs": "find . -name '*.d.ts' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
21
29
  "clean-maps": "find . -name '*.js.map' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
22
30
  "clean-js": "find . -name '*.js' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
@@ -24,7 +32,7 @@
24
32
  "clean-doc": "rm -rf docs",
25
33
  "clean-benchmark": "rm -rf benchmark-result",
26
34
  "clean": "npm run clean-tests && npm run clean-typedefs && npm run clean-maps && npm run clean-js && npm run clean-doc && npm run clean-benchmark",
27
- "doc": "rm -rf docs && typedoc --excludePrivate --excludeExternals --hideGenerator --exclude \"**/+(debug|test|node_modules|docs|coverage|benchmark|.nyc_output)/**/*\" --out ./docs . && /usr/bin/env node -e \"import('open').then(open => open.default('file://`pwd`/docs/index.html', { wait: false }));\""
35
+ "doc": "typedoc && echo \"Docs generated: file://$(pwd)/docs/index.html\""
28
36
  },
29
37
  "repository": {
30
38
  "type": "git",
@@ -37,62 +45,17 @@
37
45
  "author": "imqueue.com <support@imqueue.com> (https://imqueue.com)",
38
46
  "license": "GPL-3.0-only",
39
47
  "dependencies": {
40
- "@imqueue/core": "^2.0.26",
41
- "@types/node": "^24.9.1",
42
- "acorn": "^8.15.0",
43
- "farmhash": "^5.0.1",
44
- "node-machine-id": "^1.1.12",
45
- "reflect-metadata": "^0.2.2",
46
- "typescript": "^5.9.3"
48
+ "@imqueue/core": "^3.0.0",
49
+ "typescript": "^6.0.3"
47
50
  },
48
51
  "devDependencies": {
49
- "@types/chai": "^5.2.2",
50
- "@types/mocha": "^10.0.10",
51
52
  "@types/mock-require": "^3.0.0",
52
- "@types/sinon": "^17.0.4",
53
- "chai": "^6.0.1",
54
- "coveralls-next": "^5.0.0",
55
- "minimist": "^1.2.8",
56
- "mocha": "^11.7.2",
57
- "mocha-lcov-reporter": "^1.3.0",
53
+ "@types/node": "^24.9.1",
58
54
  "mock-require": "^3.0.3",
59
- "nyc": "^17.1.0",
60
- "open": "^10.1.2",
61
- "sinon": "^21.0.0",
62
- "source-map-support": "^0.5.21",
63
- "ts-node": "^10.9.2",
64
- "typedoc": "^0.28.12"
55
+ "oxfmt": "0.57.0",
56
+ "oxlint": "1.72.0",
57
+ "typedoc": "^0.28.20"
65
58
  },
66
59
  "main": "index.js",
67
- "typescript": {
68
- "definitions": "index.d.ts"
69
- },
70
- "mocha": {
71
- "require": [
72
- "ts-node/register",
73
- "source-map-support/register"
74
- ],
75
- "recursive": true,
76
- "bail": true,
77
- "full-trace": true
78
- },
79
- "nyc": {
80
- "check-coverage": false,
81
- "extension": [
82
- ".ts"
83
- ],
84
- "exclude": [
85
- "**/*.d.ts",
86
- "**/test/**"
87
- ],
88
- "require": [
89
- "ts-node/register"
90
- ],
91
- "reporter": [
92
- "html",
93
- "text",
94
- "text-summary",
95
- "lcovonly"
96
- ]
97
- }
60
+ "types": "index.d.ts"
98
61
  }