@imqueue/rpc 2.0.26 → 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.
- package/.github/workflows/build.yml +49 -5
- package/.oxfmtrc.json +9 -0
- package/.oxlintrc.json +37 -0
- package/README.md +68 -0
- package/package.json +21 -58
- package/scripts/strip-comment-coverage.mjs +464 -0
- package/src/IMQCache.d.ts +10 -9
- package/src/IMQCache.js +16 -22
- package/src/IMQClient.d.ts +21 -16
- package/src/IMQClient.js +407 -271
- package/src/IMQDelay.d.ts +14 -0
- package/src/IMQDelay.js +26 -5
- package/src/IMQLock.d.ts +17 -15
- package/src/IMQLock.js +36 -36
- package/src/IMQMetadata.d.ts +8 -0
- package/src/IMQMetadata.js +8 -0
- package/src/IMQRPCDescription.d.ts +2 -2
- package/src/IMQRPCDescription.js +2 -2
- package/src/IMQRPCError.d.ts +7 -7
- package/src/IMQRPCError.js +7 -8
- package/src/IMQRPCOptions.d.ts +27 -3
- package/src/IMQRPCOptions.js +17 -3
- package/src/IMQRPCRequest.d.ts +1 -1
- package/src/IMQRPCResponse.d.ts +1 -1
- package/src/IMQRequestContext.d.ts +25 -0
- package/src/IMQRequestContext.js +57 -0
- package/src/IMQService.d.ts +4 -4
- package/src/IMQService.js +303 -217
- package/src/cache/ICache.d.ts +53 -0
- package/src/cache/RedisCache.d.ts +28 -25
- package/src/cache/RedisCache.js +104 -61
- package/src/decorators/cache.d.ts +12 -0
- package/src/decorators/cache.js +56 -41
- package/src/decorators/classType.d.ts +43 -0
- package/src/decorators/classType.js +83 -0
- package/src/decorators/expose.d.ts +5 -31
- package/src/decorators/expose.js +118 -134
- package/src/decorators/index.d.ts +2 -0
- package/src/decorators/index.js +4 -0
- package/src/decorators/indexed.d.ts +23 -0
- package/src/decorators/indexed.js +22 -13
- package/src/decorators/lock.d.ts +10 -11
- package/src/decorators/lock.js +63 -56
- package/src/decorators/logged.d.ts +11 -9
- package/src/decorators/logged.js +47 -40
- package/src/decorators/metadata.d.ts +24 -0
- package/src/decorators/metadata.js +45 -0
- package/src/decorators/property.d.ts +7 -57
- package/src/decorators/property.js +112 -83
- package/src/decorators/remote.d.ts +7 -7
- package/src/decorators/remote.js +19 -13
- package/src/helpers/fs.d.ts +13 -13
- package/src/helpers/fs.js +19 -19
- package/src/helpers/os-uuid.d.ts +2 -1
- package/src/helpers/os-uuid.js +86 -3
- package/src/helpers/pid.d.ts +19 -9
- package/src/helpers/pid.js +33 -33
- package/src/helpers/signature.d.ts +9 -7
- package/src/helpers/signature.js +80 -10
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/tsconfig.json +18 -14
- package/typedoc.json +19 -0
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Coverage post-processor
|
|
3
|
+
*
|
|
4
|
+
* I'm Queue Software Project
|
|
5
|
+
* Copyright (C) 2025 imqueue.com <support@imqueue.com>
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*
|
|
20
|
+
* If you want to use this code in a closed source (commercial) project, you can
|
|
21
|
+
* purchase a proprietary commercial license. Please contact us at
|
|
22
|
+
* <support@imqueue.com> to get commercial licensing options.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Node's built-in coverage (`--experimental-test-coverage --enable-source-maps`)
|
|
27
|
+
* reports every non-code line of a `.ts` source as uncovered, because comment
|
|
28
|
+
* and blank lines have no source-map mappings and therefore fall outside every
|
|
29
|
+
* covered V8 byte-range. That paints the license header and each JSDoc block
|
|
30
|
+
* red in the HTML report and pushes per-file line% far below reality.
|
|
31
|
+
*
|
|
32
|
+
* Node's reporter also emits records that the (strict) genhtml LCOV 2.x tool
|
|
33
|
+
* rejects — function entries with `undefined` line numbers or synthetic,
|
|
34
|
+
* duplicated names (`<instance_members_initializer>`, and decorated methods all
|
|
35
|
+
* mis-named `has`/`get`), plus `BRDA:undefined,...` branch records. Left in,
|
|
36
|
+
* they produce a wall of warnings and a fatal "unexpected category" error.
|
|
37
|
+
*
|
|
38
|
+
* This script rewrites an lcov file in place: it drops the `DA`/`BRDA` records
|
|
39
|
+
* for lines that contain no executable code (comments and blank lines), drops
|
|
40
|
+
* all function records and malformed branch records, then recomputes the
|
|
41
|
+
* `LF`/`LH`/`BRF`/`BRH` totals. It uses the TypeScript scanner (already a dev
|
|
42
|
+
* dependency) to locate comments reliably — comment markers inside strings,
|
|
43
|
+
* template literals and regexes are not misdetected. The result renders in
|
|
44
|
+
* genhtml with accurate line + branch coverage and no warnings or errors.
|
|
45
|
+
*/
|
|
46
|
+
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
47
|
+
import ts from 'typescript';
|
|
48
|
+
|
|
49
|
+
const lcovPath = process.argv[2] || 'coverage/lcov.info';
|
|
50
|
+
|
|
51
|
+
if (!existsSync(lcovPath)) {
|
|
52
|
+
console.warn(`strip-comment-coverage: ${lcovPath} not found, skipping`);
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the set of 1-based line numbers in the given source that hold no
|
|
58
|
+
* executable code — i.e. blank lines and lines whose only content is a comment.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} text
|
|
61
|
+
* @returns {Set<number>}
|
|
62
|
+
*/
|
|
63
|
+
function nonCodeLines(text) {
|
|
64
|
+
const commentChars = new Uint8Array(text.length);
|
|
65
|
+
// Collect every comment range from the parsed tree. A standalone
|
|
66
|
+
// ts.createScanner is unreliable here — without parser context it can
|
|
67
|
+
// mis-scan a stray `/` as a regex literal and swallow the comments inside
|
|
68
|
+
// it — so walk all tokens and take their leading/trailing comment trivia,
|
|
69
|
+
// which every comment in the file belongs to.
|
|
70
|
+
const sf = ts.createSourceFile('x.ts', text, ts.ScriptTarget.Latest, true);
|
|
71
|
+
const seen = new Set();
|
|
72
|
+
const mark = pos => {
|
|
73
|
+
for (const get of [
|
|
74
|
+
ts.getLeadingCommentRanges,
|
|
75
|
+
ts.getTrailingCommentRanges,
|
|
76
|
+
]) {
|
|
77
|
+
for (const range of get(text, pos) || []) {
|
|
78
|
+
const key = `${range.pos}:${range.end}`;
|
|
79
|
+
|
|
80
|
+
if (seen.has(key)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
seen.add(key);
|
|
85
|
+
|
|
86
|
+
for (let i = range.pos; i < range.end; i++) {
|
|
87
|
+
commentChars[i] = 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const visit = node => {
|
|
93
|
+
mark(node.getFullStart());
|
|
94
|
+
node.getChildren(sf).forEach(visit);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
visit(sf);
|
|
98
|
+
|
|
99
|
+
const lines = text.split('\n');
|
|
100
|
+
const result = new Set();
|
|
101
|
+
let pos = 0;
|
|
102
|
+
|
|
103
|
+
for (let ln = 0; ln < lines.length; ln++) {
|
|
104
|
+
const line = lines[ln];
|
|
105
|
+
let hasCode = false;
|
|
106
|
+
|
|
107
|
+
for (let i = 0; i < line.length; i++) {
|
|
108
|
+
const ch = line[i];
|
|
109
|
+
|
|
110
|
+
if (ch === ' ' || ch === '\t' || ch === '\r') {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!commentChars[pos + i]) {
|
|
115
|
+
hasCode = true;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!hasCode) {
|
|
121
|
+
result.add(ln + 1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
pos += line.length + 1; // account for the split '\n'
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Returns the set of 1-based lines that carry no coverable executable code of
|
|
132
|
+
* their own yet Node's source-mapped coverage mis-reports as uncovered
|
|
133
|
+
* (the mapping lands outside the covered byte-range, especially under
|
|
134
|
+
* `nodenext` output). These are:
|
|
135
|
+
* - imports (compile to a `require` that always runs on load);
|
|
136
|
+
* - module-scope variable declarations (`const`/`let`/`var`) — the whole
|
|
137
|
+
* statement if its initializer has no function body, otherwise just the
|
|
138
|
+
* declaration line so real bodies keep their coverage;
|
|
139
|
+
* - class declaration headers and type-only property fields (no initializer).
|
|
140
|
+
* Method/accessor/constructor bodies are never touched, so genuinely unreached
|
|
141
|
+
* code still shows up.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} text
|
|
144
|
+
* @returns {Set<number>}
|
|
145
|
+
*/
|
|
146
|
+
function importLines(text) {
|
|
147
|
+
const sf = ts.createSourceFile(
|
|
148
|
+
'x.ts',
|
|
149
|
+
text,
|
|
150
|
+
ts.ScriptTarget.Latest,
|
|
151
|
+
false,
|
|
152
|
+
);
|
|
153
|
+
const result = new Set();
|
|
154
|
+
const lineAt = pos => sf.getLineAndCharacterOfPosition(pos).line;
|
|
155
|
+
const addRange = (start, end) => {
|
|
156
|
+
for (let line = lineAt(start); line <= lineAt(end); line++) {
|
|
157
|
+
result.add(line + 1);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const hasFunction = node => {
|
|
161
|
+
let found = false;
|
|
162
|
+
const walk = n => {
|
|
163
|
+
if (found) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (
|
|
168
|
+
ts.isFunctionExpression(n) ||
|
|
169
|
+
ts.isArrowFunction(n) ||
|
|
170
|
+
ts.isFunctionDeclaration(n) ||
|
|
171
|
+
ts.isMethodDeclaration(n)
|
|
172
|
+
) {
|
|
173
|
+
found = true;
|
|
174
|
+
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
n.forEachChild(walk);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
walk(node);
|
|
182
|
+
|
|
183
|
+
return found;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
for (const stmt of sf.statements) {
|
|
187
|
+
if (
|
|
188
|
+
ts.isImportDeclaration(stmt) ||
|
|
189
|
+
ts.isImportEqualsDeclaration(stmt)
|
|
190
|
+
) {
|
|
191
|
+
addRange(stmt.getStart(sf), stmt.getEnd());
|
|
192
|
+
} else if (ts.isVariableStatement(stmt)) {
|
|
193
|
+
if (hasFunction(stmt)) {
|
|
194
|
+
result.add(lineAt(stmt.getStart(sf)) + 1);
|
|
195
|
+
} else {
|
|
196
|
+
addRange(stmt.getStart(sf), stmt.getEnd());
|
|
197
|
+
}
|
|
198
|
+
} else if (ts.isClassDeclaration(stmt)) {
|
|
199
|
+
// class header (`class X extends Y {`): everything up to the first
|
|
200
|
+
// member, or the whole thing for an empty class
|
|
201
|
+
const headerEnd = stmt.members.length
|
|
202
|
+
? stmt.members[0].getStart(sf)
|
|
203
|
+
: stmt.getEnd();
|
|
204
|
+
|
|
205
|
+
addRange(stmt.getStart(sf), headerEnd);
|
|
206
|
+
// the closing brace line emits no coverable code either
|
|
207
|
+
result.add(lineAt(stmt.getEnd()) + 1);
|
|
208
|
+
|
|
209
|
+
// type-only fields (definite-assignment / uninitialized) emit no JS
|
|
210
|
+
for (const member of stmt.members) {
|
|
211
|
+
if (
|
|
212
|
+
ts.isPropertyDeclaration(member) &&
|
|
213
|
+
!member.initializer
|
|
214
|
+
) {
|
|
215
|
+
addRange(member.getStart(sf), member.getEnd());
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const B64 =
|
|
225
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
226
|
+
const B64MAP = new Map([...B64].map((c, i) => [c, i]));
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Decodes one base64 VLQ source-map segment into its integer fields.
|
|
230
|
+
*
|
|
231
|
+
* @param {string} seg
|
|
232
|
+
* @returns {number[]}
|
|
233
|
+
*/
|
|
234
|
+
function decodeVLQ(seg) {
|
|
235
|
+
const out = [];
|
|
236
|
+
let shift = 0;
|
|
237
|
+
let value = 0;
|
|
238
|
+
|
|
239
|
+
for (const ch of seg) {
|
|
240
|
+
const digit = B64MAP.get(ch);
|
|
241
|
+
|
|
242
|
+
if (digit === undefined) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
value += (digit & 31) << shift;
|
|
247
|
+
|
|
248
|
+
if (digit & 32) {
|
|
249
|
+
shift += 5;
|
|
250
|
+
} else {
|
|
251
|
+
out.push(value & 1 ? -(value >> 1) : value >> 1);
|
|
252
|
+
value = 0;
|
|
253
|
+
shift = 0;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Returns the set of 1-based source lines that produced generated JavaScript,
|
|
262
|
+
* read from the file's `.js.map`. These are exactly the coverable lines — every
|
|
263
|
+
* other line (comments, blanks, type-only declarations, interfaces) emits no
|
|
264
|
+
* code and can never be executed. Returns null when no source map is present.
|
|
265
|
+
*
|
|
266
|
+
* @param {string} sourceFile - path of the .ts source (e.g. src/RedisQueue.ts)
|
|
267
|
+
* @returns {Set<number> | null}
|
|
268
|
+
*/
|
|
269
|
+
function emittedLines(sourceFile) {
|
|
270
|
+
const mapPath = sourceFile.replace(/\.ts$/, '.js.map');
|
|
271
|
+
|
|
272
|
+
if (!existsSync(mapPath)) {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
let map;
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
map = JSON.parse(readFileSync(mapPath, 'utf8'));
|
|
280
|
+
} catch {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (typeof map.mappings !== 'string') {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const lines = new Set();
|
|
289
|
+
let srcIndex = 0;
|
|
290
|
+
let srcLine = 0;
|
|
291
|
+
|
|
292
|
+
for (const group of map.mappings.split(';')) {
|
|
293
|
+
for (const seg of group.split(',')) {
|
|
294
|
+
if (!seg) {
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const fields = decodeVLQ(seg);
|
|
299
|
+
|
|
300
|
+
// [genCol, srcIndex, srcLine, srcCol, nameIndex]; <4 fields = no
|
|
301
|
+
// source position for this segment
|
|
302
|
+
if (fields.length >= 4) {
|
|
303
|
+
srcIndex += fields[1];
|
|
304
|
+
srcLine += fields[2];
|
|
305
|
+
|
|
306
|
+
if (srcIndex === 0) {
|
|
307
|
+
lines.add(srcLine + 1); // map lines are 0-based
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return lines;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const coverableCache = new Map();
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Resolves how to filter a source file's line records:
|
|
320
|
+
* - `{ mode: 'keep', set }` — keep only lines in `set` (source-map driven);
|
|
321
|
+
* - `{ mode: 'drop', set }` — drop lines in `set` (comment-scanner fallback).
|
|
322
|
+
*
|
|
323
|
+
* @param {string} sourceFile
|
|
324
|
+
* @returns {{ mode: 'keep' | 'drop', set: Set<number> }}
|
|
325
|
+
*/
|
|
326
|
+
function coverableInfo(sourceFile) {
|
|
327
|
+
if (coverableCache.has(sourceFile)) {
|
|
328
|
+
return coverableCache.get(sourceFile);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const emitted = sourceFile ? emittedLines(sourceFile) : null;
|
|
332
|
+
let info;
|
|
333
|
+
|
|
334
|
+
if (emitted && existsSync(sourceFile)) {
|
|
335
|
+
// A line is coverable only if it emitted JS (has a source-map mapping)
|
|
336
|
+
// AND is not a comment/blank AND is not an import statement. The comment
|
|
337
|
+
// check is required because `removeComments: false` keeps license/JSDoc
|
|
338
|
+
// comments in the output, so they carry mappings too; the mapping check
|
|
339
|
+
// drops type-only lines (interfaces, type aliases) which emit nothing;
|
|
340
|
+
// the import check drops the mis-mapped import artifact.
|
|
341
|
+
const text = readFileSync(sourceFile, 'utf8');
|
|
342
|
+
const nonCode = nonCodeLines(text);
|
|
343
|
+
const imports = importLines(text);
|
|
344
|
+
const keep = new Set(
|
|
345
|
+
[...emitted].filter(
|
|
346
|
+
line => !nonCode.has(line) && !imports.has(line),
|
|
347
|
+
),
|
|
348
|
+
);
|
|
349
|
+
info = { mode: 'keep', set: keep };
|
|
350
|
+
} else if (sourceFile && existsSync(sourceFile)) {
|
|
351
|
+
const text = readFileSync(sourceFile, 'utf8');
|
|
352
|
+
const skip = nonCodeLines(text);
|
|
353
|
+
|
|
354
|
+
for (const line of importLines(text)) {
|
|
355
|
+
skip.add(line);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
info = { mode: 'drop', set: skip };
|
|
359
|
+
} else {
|
|
360
|
+
info = { mode: 'drop', set: new Set() };
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
coverableCache.set(sourceFile, info);
|
|
364
|
+
|
|
365
|
+
return info;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
let strippedLines = 0;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Rewrites a single lcov record so that genhtml accepts it without warnings or
|
|
372
|
+
* errors. It:
|
|
373
|
+
* - drops DA/BRDA entries on non-code (comment/blank) lines;
|
|
374
|
+
* - drops all function records (FN/FNDA/FNF/FNH) — Node's source-mapped
|
|
375
|
+
* function detection is unreliable here (undefined line numbers, mis-named
|
|
376
|
+
* and duplicated entries), which genhtml rejects, so line + branch coverage
|
|
377
|
+
* is kept instead;
|
|
378
|
+
* - drops malformed branch records such as `BRDA:undefined,...`;
|
|
379
|
+
* - recomputes the LF/LH/BRF/BRH totals.
|
|
380
|
+
*
|
|
381
|
+
* @param {string[]} recordLines - record body, excluding the end_of_record line
|
|
382
|
+
* @returns {string}
|
|
383
|
+
*/
|
|
384
|
+
function processRecord(recordLines) {
|
|
385
|
+
const sfLine = recordLines.find(line => line.startsWith('SF:'));
|
|
386
|
+
const sourceFile = sfLine ? sfLine.slice(3).trim() : '';
|
|
387
|
+
const info = coverableInfo(sourceFile);
|
|
388
|
+
|
|
389
|
+
// true when a source line produces no executable code and must be dropped
|
|
390
|
+
const drop = n => (info.mode === 'keep' ? !info.set.has(n) : info.set.has(n));
|
|
391
|
+
|
|
392
|
+
let lf = 0;
|
|
393
|
+
let lh = 0;
|
|
394
|
+
let brf = 0;
|
|
395
|
+
let brh = 0;
|
|
396
|
+
|
|
397
|
+
const kept = recordLines.filter(line => {
|
|
398
|
+
// drop all function records — unreliable under source maps
|
|
399
|
+
if (/^(FN:|FNDA:|FNF:|FNH:)/.test(line)) {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const da = line.match(/^DA:(\d+),(\d+)/);
|
|
404
|
+
|
|
405
|
+
if (da) {
|
|
406
|
+
if (drop(+da[1])) {
|
|
407
|
+
strippedLines++;
|
|
408
|
+
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
lf++;
|
|
413
|
+
|
|
414
|
+
if (+da[2] > 0) {
|
|
415
|
+
lh++;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (line.startsWith('BRDA:')) {
|
|
422
|
+
const brda = line.match(/^BRDA:(\d+),\d+,\d+,(\d+|-)$/);
|
|
423
|
+
|
|
424
|
+
// drop malformed (e.g. BRDA:undefined,...) or non-code branches
|
|
425
|
+
if (!brda || drop(+brda[1])) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
brf++;
|
|
430
|
+
|
|
431
|
+
if (brda[2] !== '-' && +brda[2] > 0) {
|
|
432
|
+
brh++;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// drop the old totals — they are recomputed below
|
|
439
|
+
return !/^(LF|LH|BRF|BRH):/.test(line);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
return (
|
|
443
|
+
`${kept.join('\n')}\n` +
|
|
444
|
+
`LF:${lf}\nLH:${lh}\nBRF:${brf}\nBRH:${brh}\nend_of_record\n`
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const output = [];
|
|
449
|
+
let record = [];
|
|
450
|
+
|
|
451
|
+
for (const line of readFileSync(lcovPath, 'utf8').split('\n')) {
|
|
452
|
+
if (line === 'end_of_record') {
|
|
453
|
+
output.push(processRecord(record));
|
|
454
|
+
record = [];
|
|
455
|
+
} else if (line !== '') {
|
|
456
|
+
record.push(line);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
writeFileSync(lcovPath, output.join(''));
|
|
461
|
+
console.info(
|
|
462
|
+
`strip-comment-coverage: removed ${strippedLines} comment/blank line ` +
|
|
463
|
+
`entries from ${lcovPath}`,
|
|
464
|
+
);
|
package/src/IMQCache.d.ts
CHANGED
|
@@ -31,31 +31,32 @@ export declare class IMQCache {
|
|
|
31
31
|
[name: string]: ICache;
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
-
* Registers given cache adapter
|
|
34
|
+
* Registers the given cache adapter.
|
|
35
35
|
*
|
|
36
|
-
* @param {
|
|
37
|
-
*
|
|
36
|
+
* @param {ICacheAdapter | string} adapter - adapter name, class or
|
|
37
|
+
* instance
|
|
38
|
+
* @param {any} [options] - adapter-specific options
|
|
38
39
|
* @returns {IMQCache}
|
|
39
40
|
*/
|
|
40
41
|
static register(adapter: ICacheAdapter | string, options?: any): typeof IMQCache;
|
|
41
42
|
/**
|
|
42
|
-
* Overrides existing adapter options with the given
|
|
43
|
+
* Overrides existing adapter options with the given ones.
|
|
43
44
|
*
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {any} options - adapter
|
|
45
|
+
* @param {ICacheAdapter | string} adapter - adapter to apply options to
|
|
46
|
+
* @param {any} options - adapter-specific options
|
|
46
47
|
* @returns {IMQCache}
|
|
47
48
|
*/
|
|
48
49
|
static apply(adapter: ICacheAdapter | string, options: any): typeof IMQCache;
|
|
49
50
|
/**
|
|
50
|
-
* Initializes all registered cache adapters
|
|
51
|
+
* Initializes all registered cache adapters.
|
|
51
52
|
*
|
|
52
53
|
* @returns {Promise<any>}
|
|
53
54
|
*/
|
|
54
55
|
static init(): Promise<any>;
|
|
55
56
|
/**
|
|
56
|
-
* Returns registered cache adapter by its given name or class
|
|
57
|
+
* Returns a registered cache adapter by its given name or class.
|
|
57
58
|
*
|
|
58
|
-
* @param {
|
|
59
|
+
* @param {ICacheAdapter} adapter - adapter name, class or instance
|
|
59
60
|
* @returns {ICache} - adapter instance
|
|
60
61
|
*/
|
|
61
62
|
static get(adapter: ICacheAdapter): ICache;
|
package/src/IMQCache.js
CHANGED
|
@@ -5,23 +5,24 @@ exports.IMQCache = void 0;
|
|
|
5
5
|
* Generic cache registry
|
|
6
6
|
*/
|
|
7
7
|
class IMQCache {
|
|
8
|
+
static options = {};
|
|
9
|
+
static adapters = {};
|
|
8
10
|
/**
|
|
9
|
-
* Registers given cache adapter
|
|
11
|
+
* Registers the given cache adapter.
|
|
10
12
|
*
|
|
11
|
-
* @param {
|
|
12
|
-
*
|
|
13
|
+
* @param {ICacheAdapter | string} adapter - adapter name, class or
|
|
14
|
+
* instance
|
|
15
|
+
* @param {any} [options] - adapter-specific options
|
|
13
16
|
* @returns {IMQCache}
|
|
14
17
|
*/
|
|
15
18
|
static register(adapter, options) {
|
|
16
19
|
const self = IMQCache;
|
|
17
20
|
if (typeof adapter === 'string') {
|
|
18
|
-
// istanbul ignore else
|
|
19
21
|
if (!self.adapters[adapter]) {
|
|
20
|
-
self.adapters[adapter] = new (require(`${__dirname}/cache/${adapter}.js`)[adapter])();
|
|
22
|
+
self.adapters[adapter] = (new (require(`${__dirname}/cache/${adapter}.js`)[adapter])());
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
else {
|
|
24
|
-
// istanbul ignore else
|
|
25
26
|
if (!self.adapters[adapter.name]) {
|
|
26
27
|
if (typeof adapter === 'function') {
|
|
27
28
|
self.adapters[adapter.name] =
|
|
@@ -37,10 +38,10 @@ class IMQCache {
|
|
|
37
38
|
return self;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
* Overrides existing adapter options with the given
|
|
41
|
+
* Overrides existing adapter options with the given ones.
|
|
41
42
|
*
|
|
42
|
-
* @param {
|
|
43
|
-
* @param {any} options - adapter
|
|
43
|
+
* @param {ICacheAdapter | string} adapter - adapter to apply options to
|
|
44
|
+
* @param {any} options - adapter-specific options
|
|
44
45
|
* @returns {IMQCache}
|
|
45
46
|
*/
|
|
46
47
|
static apply(adapter, options) {
|
|
@@ -48,15 +49,13 @@ class IMQCache {
|
|
|
48
49
|
if (!options) {
|
|
49
50
|
return self;
|
|
50
51
|
}
|
|
51
|
-
const name = typeof adapter === 'string'
|
|
52
|
-
? adapter
|
|
53
|
-
: adapter.name;
|
|
52
|
+
const name = typeof adapter === 'string' ? adapter : adapter.name;
|
|
54
53
|
let opts = self.options[name] || {};
|
|
55
|
-
self.options[name] =
|
|
54
|
+
self.options[name] = { ...opts, ...options };
|
|
56
55
|
return self;
|
|
57
56
|
}
|
|
58
57
|
/**
|
|
59
|
-
* Initializes all registered cache adapters
|
|
58
|
+
* Initializes all registered cache adapters.
|
|
60
59
|
*
|
|
61
60
|
* @returns {Promise<any>}
|
|
62
61
|
*/
|
|
@@ -64,7 +63,6 @@ class IMQCache {
|
|
|
64
63
|
const self = IMQCache;
|
|
65
64
|
const promises = [];
|
|
66
65
|
for (let adapter of Object.keys(self.adapters)) {
|
|
67
|
-
// istanbul ignore else
|
|
68
66
|
if (!self.adapters[adapter].ready) {
|
|
69
67
|
promises.push(self.adapters[adapter].init(self.options[adapter]));
|
|
70
68
|
}
|
|
@@ -73,18 +71,14 @@ class IMQCache {
|
|
|
73
71
|
return self;
|
|
74
72
|
}
|
|
75
73
|
/**
|
|
76
|
-
* Returns registered cache adapter by its given name or class
|
|
74
|
+
* Returns a registered cache adapter by its given name or class.
|
|
77
75
|
*
|
|
78
|
-
* @param {
|
|
76
|
+
* @param {ICacheAdapter} adapter - adapter name, class or instance
|
|
79
77
|
* @returns {ICache} - adapter instance
|
|
80
78
|
*/
|
|
81
79
|
static get(adapter) {
|
|
82
|
-
return IMQCache.adapters[typeof adapter === 'string'
|
|
83
|
-
? adapter
|
|
84
|
-
: adapter.name];
|
|
80
|
+
return IMQCache.adapters[typeof adapter === 'string' ? adapter : adapter.name];
|
|
85
81
|
}
|
|
86
82
|
}
|
|
87
83
|
exports.IMQCache = IMQCache;
|
|
88
|
-
IMQCache.options = {};
|
|
89
|
-
IMQCache.adapters = {};
|
|
90
84
|
//# sourceMappingURL=IMQCache.js.map
|
package/src/IMQClient.d.ts
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { JsonObject } from '@imqueue/core';
|
|
25
25
|
import { IMQClientOptions, IMQRPCResponse, IMQRPCRequest, IMQDelay, Description } from '.';
|
|
26
|
-
import { EventEmitter } from 'events';
|
|
26
|
+
import { EventEmitter } from 'node:events';
|
|
27
27
|
/**
|
|
28
28
|
* Class IMQClient - base abstract class for service clients.
|
|
29
29
|
*/
|
|
@@ -37,13 +37,16 @@ export declare abstract class IMQClient extends EventEmitter {
|
|
|
37
37
|
private readonly baseName;
|
|
38
38
|
private readonly imq;
|
|
39
39
|
private readonly subscriptionImq;
|
|
40
|
-
private static singleImq
|
|
40
|
+
private static singleImq?;
|
|
41
|
+
private static singleImqRefs;
|
|
42
|
+
private static maxListenersBumped;
|
|
43
|
+
private destroyed;
|
|
44
|
+
private readonly signalHandlers;
|
|
41
45
|
private readonly logger;
|
|
42
46
|
private resolvers;
|
|
43
47
|
/**
|
|
44
48
|
* Class constructor
|
|
45
49
|
*
|
|
46
|
-
* @constructor
|
|
47
50
|
* @param {Partial<IMQClientOptions>} options
|
|
48
51
|
* @param {string} serviceName
|
|
49
52
|
* @param {string} name
|
|
@@ -54,7 +57,6 @@ export declare abstract class IMQClient extends EventEmitter {
|
|
|
54
57
|
/**
|
|
55
58
|
* Sends call to remote service method
|
|
56
59
|
*
|
|
57
|
-
* @access protected
|
|
58
60
|
* @param {...any[]} args
|
|
59
61
|
* @template T
|
|
60
62
|
* @returns {Promise<T>}
|
|
@@ -102,10 +104,11 @@ export declare abstract class IMQClient extends EventEmitter {
|
|
|
102
104
|
/**
|
|
103
105
|
* Returns service description metadata.
|
|
104
106
|
*
|
|
105
|
-
* @param {IMQDelay} delay
|
|
107
|
+
* @param {IMQDelay} [_delay] - optional delivery delay; forwarded to the
|
|
108
|
+
* service through `arguments` by the `@remote` decorator
|
|
106
109
|
* @returns {Promise<Description>}
|
|
107
110
|
*/
|
|
108
|
-
describe(
|
|
111
|
+
describe(_delay?: IMQDelay): Promise<Description>;
|
|
109
112
|
/**
|
|
110
113
|
* Creates client for a service with the given name
|
|
111
114
|
*
|
|
@@ -116,20 +119,22 @@ export declare abstract class IMQClient extends EventEmitter {
|
|
|
116
119
|
static create(name: string, options?: Partial<IMQClientOptions>): Promise<any>;
|
|
117
120
|
}
|
|
118
121
|
/**
|
|
119
|
-
* Builds
|
|
122
|
+
* Builds a call resolver that resolves the pending promise and then runs the
|
|
123
|
+
* optional after-call hook.
|
|
120
124
|
*
|
|
121
|
-
* @param {(
|
|
122
|
-
* @param {IMQRPCRequest} req
|
|
123
|
-
* @param {IMQClient} client -
|
|
124
|
-
* @return {(data: any, res: IMQRPCResponse) => void} - hook-
|
|
125
|
+
* @param {(data: any) => void} resolve - the underlying promise resolver
|
|
126
|
+
* @param {IMQRPCRequest} req - the originating request message
|
|
127
|
+
* @param {IMQClient} client - the client the call belongs to
|
|
128
|
+
* @return {(data: any, res: IMQRPCResponse) => void} - a hook-aware resolver
|
|
125
129
|
*/
|
|
126
130
|
export declare function imqCallResolver(resolve: (data: any) => void, req: IMQRPCRequest, client: IMQClient): (data: any, res: IMQRPCResponse) => void;
|
|
127
131
|
/**
|
|
128
|
-
* Builds
|
|
132
|
+
* Builds a call rejector that rejects the pending promise and then runs the
|
|
133
|
+
* optional after-call hook.
|
|
129
134
|
*
|
|
130
|
-
* @param {(err: any) => void} reject -
|
|
131
|
-
* @param {IMQRPCRequest} req -
|
|
132
|
-
* @param {IMQClient} client -
|
|
133
|
-
* @return {(err: any) => void} - hook-
|
|
135
|
+
* @param {(err: any) => void} reject - the underlying promise rejector
|
|
136
|
+
* @param {IMQRPCRequest} req - the originating request message
|
|
137
|
+
* @param {IMQClient} client - the client the call belongs to
|
|
138
|
+
* @return {(err: any, res?: IMQRPCResponse) => void} - a hook-aware rejector
|
|
134
139
|
*/
|
|
135
140
|
export declare function imqCallRejector(reject: (err: any) => void, req: IMQRPCRequest, client: IMQClient): (err: any, res?: IMQRPCResponse) => void;
|