@requence/service 1.0.0-alpha.0 → 1.0.0-alpha.2
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 +0 -16
- package/build/chunk-0x9092n4.js +95 -0
- package/build/chunk-0x9092n4.js.map +12 -0
- package/build/cli.js +23 -13
- package/build/cli.js.map +3 -3
- package/build/index.js +175 -201
- package/build/index.js.map +14 -14
- package/build/types/helpers/src/createRemotePromise.d.ts +7 -0
- package/build/types/helpers/src/createRemotePromise.d.ts.map +1 -0
- package/build/types/helpers/src/index.d.ts +6 -6
- package/build/types/helpers/src/index.d.ts.map +1 -1
- package/build/types/helpers/src/utils.d.ts +0 -3
- package/build/types/helpers/src/utils.d.ts.map +1 -1
- package/build/types/service/src/{connections/createAmqpConnection.d.ts → createAmqpConnection.d.ts} +8 -7
- package/build/types/service/src/createAmqpConnection.d.ts.map +1 -0
- package/build/types/service/src/helpers.d.ts +16 -16
- package/build/types/service/src/index.d.ts +4 -3
- package/build/types/service/src/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/build/chunk-2exhyr7n.js +0 -234
- package/build/chunk-2exhyr7n.js.map +0 -14
- package/build/types/helpers/src/service.d.ts +0 -156
- package/build/types/helpers/src/service.d.ts.map +0 -1
- package/build/types/helpers/src/task.d.ts +0 -49
- package/build/types/helpers/src/task.d.ts.map +0 -1
- package/build/types/service/src/connections/createAmqpConnection.d.ts.map +0 -1
package/build/index.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
clone,
|
|
3
|
-
createObjectProxy,
|
|
4
|
-
deobfuscate,
|
|
5
|
-
obfuscate
|
|
6
|
-
} from "./chunk-
|
|
2
|
+
clone,
|
|
3
|
+
createObjectProxy,
|
|
4
|
+
deobfuscate,
|
|
5
|
+
obfuscate
|
|
6
|
+
} from "./chunk-0x9092n4.js";
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
|
-
import {readFileSync} from "node:fs";
|
|
10
|
-
import {z as z8} from "zod";
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
|
+
import { z as z8 } from "zod";
|
|
11
11
|
|
|
12
12
|
// ../helpers/src/context/context.ts
|
|
13
|
-
import {z} from "zod";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
var contextSchema = z.object({
|
|
15
|
+
input: z.any(),
|
|
16
|
+
meta: z.any(),
|
|
17
|
+
tenant: z.object({ name: z.string() }),
|
|
18
|
+
data: z.record(z.string(), z.any()),
|
|
19
|
+
errors: z.record(z.string(), z.string()),
|
|
20
|
+
dates: z.record(z.string(), z.string().datetime())
|
|
21
|
+
});
|
|
14
22
|
function isRecord(data) {
|
|
15
23
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
16
24
|
}
|
|
25
|
+
var internalKey = Symbol.for("internal");
|
|
17
26
|
function getInternalContext(contextHelper) {
|
|
18
27
|
return contextHelper[internalKey];
|
|
19
28
|
}
|
|
@@ -53,9 +62,6 @@ function createContextHelper(context, nodes) {
|
|
|
53
62
|
getInput() {
|
|
54
63
|
return context.input;
|
|
55
64
|
},
|
|
56
|
-
getTenantName() {
|
|
57
|
-
return context.tenant.name;
|
|
58
|
-
},
|
|
59
65
|
getMeta() {
|
|
60
66
|
return context.meta;
|
|
61
67
|
},
|
|
@@ -87,24 +93,16 @@ function createContextHelper(context, nodes) {
|
|
|
87
93
|
if (!nodeIds) {
|
|
88
94
|
return null;
|
|
89
95
|
}
|
|
90
|
-
return nodeIds.map((nodeId) => results.get(nodeId)?.error).filter((str) => typeof str === "string").join(
|
|
96
|
+
return nodeIds.map((nodeId) => results.get(nodeId)?.error).filter((str) => typeof str === "string").join(`
|
|
97
|
+
`);
|
|
91
98
|
}
|
|
92
99
|
};
|
|
93
100
|
}
|
|
94
|
-
var contextSchema = z.object({
|
|
95
|
-
input: z.any(),
|
|
96
|
-
meta: z.any(),
|
|
97
|
-
tenant: z.object({ name: z.string() }),
|
|
98
|
-
data: z.record(z.string(), z.any()),
|
|
99
|
-
errors: z.record(z.string(), z.string()),
|
|
100
|
-
dates: z.record(z.string(), z.string().datetime())
|
|
101
|
-
});
|
|
102
|
-
var internalKey = Symbol.for("internal");
|
|
103
101
|
// ../helpers/src/protocol/command.ts
|
|
104
|
-
import {z as z5} from "zod";
|
|
102
|
+
import { z as z5 } from "zod";
|
|
105
103
|
|
|
106
104
|
// ../helpers/src/protocol/nodes.ts
|
|
107
|
-
import {ZodError, z as z4} from "zod";
|
|
105
|
+
import { ZodError, z as z4 } from "zod";
|
|
108
106
|
|
|
109
107
|
// ../helpers/src/protocol/getNodeOutputs.ts
|
|
110
108
|
function getNodeOutputs(node, outputName) {
|
|
@@ -240,10 +238,10 @@ function identifyNode(nodeId, getNode) {
|
|
|
240
238
|
}
|
|
241
239
|
|
|
242
240
|
// ../helpers/src/protocol/node.ts
|
|
243
|
-
import {z as z3} from "zod";
|
|
241
|
+
import { z as z3 } from "zod";
|
|
244
242
|
|
|
245
243
|
// ../helpers/src/protocol/jsonSchema.ts
|
|
246
|
-
import {z as z2} from "zod";
|
|
244
|
+
import { z as z2 } from "zod";
|
|
247
245
|
var jsonSchema7Schema = z2.lazy(() => z2.object({
|
|
248
246
|
$id: z2.string().optional(),
|
|
249
247
|
$schema: z2.string().optional(),
|
|
@@ -306,37 +304,6 @@ var jsonSchema7ObjectSchema = z2.object({
|
|
|
306
304
|
});
|
|
307
305
|
|
|
308
306
|
// ../helpers/src/protocol/node.ts
|
|
309
|
-
function validateOutputs(outputs, ctx) {
|
|
310
|
-
const exitOutputs = new Set(outputs.filter((output) => output.exit).map((output) => output.default ? "__default__" : output.name));
|
|
311
|
-
outputs.filter((output) => !output.exit).forEach((output) => {
|
|
312
|
-
const name = output.default ? "__default__" : output.name;
|
|
313
|
-
if (exitOutputs.has(name)) {
|
|
314
|
-
ctx.addIssue({
|
|
315
|
-
code: "custom",
|
|
316
|
-
message: output.default ? `default exit output cannot be mixed with target output "${output.target}"` : `named exit output "${name}" cannot be mixed with target output "${output.target}"`
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
const targets = new Map;
|
|
321
|
-
outputs.forEach((output) => {
|
|
322
|
-
const name = output.default ? "__default__" : output.name;
|
|
323
|
-
const target = output.exit ? "__exit__" : output.target;
|
|
324
|
-
if (!targets.has(name)) {
|
|
325
|
-
targets.set(name, new Set);
|
|
326
|
-
}
|
|
327
|
-
const knownTargets = targets.get(name);
|
|
328
|
-
if (knownTargets.has(target)) {
|
|
329
|
-
ctx.addIssue({
|
|
330
|
-
code: "custom",
|
|
331
|
-
message: [
|
|
332
|
-
output.default ? "duplicate default output" : `duplicate named output "${name}"`,
|
|
333
|
-
output.exit ? "for exit" : `for target "${target}"`
|
|
334
|
-
].join(" ")
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
knownTargets.add(target);
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
307
|
var outputDefinitionSchema = z3.object({
|
|
341
308
|
schema: jsonSchema7Schema.nullable().optional()
|
|
342
309
|
}).and(z3.union([
|
|
@@ -382,6 +349,37 @@ var outputSchema = z3.union([z3.string().min(1), outputDefinitionSchema]).transf
|
|
|
382
349
|
}
|
|
383
350
|
return output;
|
|
384
351
|
});
|
|
352
|
+
function validateOutputs(outputs, ctx) {
|
|
353
|
+
const exitOutputs = new Set(outputs.filter((output) => output.exit).map((output) => output.default ? "__default__" : output.name));
|
|
354
|
+
outputs.filter((output) => !output.exit).forEach((output) => {
|
|
355
|
+
const name = output.default ? "__default__" : output.name;
|
|
356
|
+
if (exitOutputs.has(name)) {
|
|
357
|
+
ctx.addIssue({
|
|
358
|
+
code: "custom",
|
|
359
|
+
message: output.default ? `default exit output cannot be mixed with target output "${output.target}"` : `named exit output "${name}" cannot be mixed with target output "${output.target}"`
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
const targets = new Map;
|
|
364
|
+
outputs.forEach((output) => {
|
|
365
|
+
const name = output.default ? "__default__" : output.name;
|
|
366
|
+
const target = output.exit ? "__exit__" : output.target;
|
|
367
|
+
if (!targets.has(name)) {
|
|
368
|
+
targets.set(name, new Set);
|
|
369
|
+
}
|
|
370
|
+
const knownTargets = targets.get(name);
|
|
371
|
+
if (knownTargets.has(target)) {
|
|
372
|
+
ctx.addIssue({
|
|
373
|
+
code: "custom",
|
|
374
|
+
message: [
|
|
375
|
+
output.default ? "duplicate default output" : `duplicate named output "${name}"`,
|
|
376
|
+
output.exit ? "for exit" : `for target "${target}"`
|
|
377
|
+
].join(" ")
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
knownTargets.add(target);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
385
383
|
var defaultOutputsSchema = z3.array(defaultOutputSchema).default([]).superRefine(validateOutputs);
|
|
386
384
|
var outputsSchema = z3.array(outputSchema).default([]).superRefine(validateOutputs);
|
|
387
385
|
var idSchema = z3.string().uuid().default(() => crypto.randomUUID());
|
|
@@ -400,8 +398,9 @@ var serviceNodeSchema = z3.object({
|
|
|
400
398
|
inputSchema: jsonSchema7ObjectSchema.nullable().optional(),
|
|
401
399
|
id: idSchema,
|
|
402
400
|
name: z3.string(),
|
|
403
|
-
version: z3.string()
|
|
401
|
+
version: z3.string(),
|
|
404
402
|
configuration: z3.any().optional(),
|
|
403
|
+
configurationSchema: jsonSchema7Schema.nullable().optional(),
|
|
405
404
|
alias: z3.string().optional(),
|
|
406
405
|
ttl: z3.number().int().min(1).optional(),
|
|
407
406
|
retry: z3.number().int().min(1).optional(),
|
|
@@ -460,24 +459,24 @@ var nodesSchema = z4.array(nodeSchema).transform((nodes) => {
|
|
|
460
459
|
const names = new Map;
|
|
461
460
|
let entryNode = null;
|
|
462
461
|
let firstNodeId = null;
|
|
463
|
-
for (const
|
|
464
|
-
if (
|
|
465
|
-
entryNode =
|
|
462
|
+
for (const node of nodes) {
|
|
463
|
+
if (node.type === "entry") {
|
|
464
|
+
entryNode = node;
|
|
466
465
|
}
|
|
467
|
-
if ((
|
|
468
|
-
firstNodeId =
|
|
466
|
+
if ((node.type === "service" || node.type === "logic") && !firstNodeId) {
|
|
467
|
+
firstNodeId = node.id;
|
|
469
468
|
}
|
|
470
|
-
if ("alias" in
|
|
471
|
-
if (!aliases.has(
|
|
472
|
-
aliases.set(
|
|
469
|
+
if ("alias" in node && node.alias) {
|
|
470
|
+
if (!aliases.has(node.alias)) {
|
|
471
|
+
aliases.set(node.alias, []);
|
|
473
472
|
}
|
|
474
|
-
aliases.get(
|
|
473
|
+
aliases.get(node.alias).push(node.id);
|
|
475
474
|
}
|
|
476
|
-
if ("name" in
|
|
477
|
-
if (!names.has(
|
|
478
|
-
names.set(
|
|
475
|
+
if ("name" in node && node.name) {
|
|
476
|
+
if (!names.has(node.name)) {
|
|
477
|
+
names.set(node.name, []);
|
|
479
478
|
}
|
|
480
|
-
names.get(
|
|
479
|
+
names.get(node.name).push(node.id);
|
|
481
480
|
}
|
|
482
481
|
}
|
|
483
482
|
if (!entryNode && firstNodeId) {
|
|
@@ -496,15 +495,15 @@ var nodesSchema = z4.array(nodeSchema).transform((nodes) => {
|
|
|
496
495
|
}
|
|
497
496
|
return identifier;
|
|
498
497
|
};
|
|
499
|
-
return nodes.map((
|
|
500
|
-
|
|
498
|
+
return nodes.map((node) => {
|
|
499
|
+
node.output = node.output.map((output) => ("target" in output) ? {
|
|
501
500
|
...output,
|
|
502
501
|
target: resolveOutput(output.target)
|
|
503
502
|
} : output);
|
|
504
|
-
if ("subject" in
|
|
505
|
-
|
|
503
|
+
if ("subject" in node) {
|
|
504
|
+
node.subject = resolveOutput(node.subject);
|
|
506
505
|
}
|
|
507
|
-
return
|
|
506
|
+
return node;
|
|
508
507
|
});
|
|
509
508
|
}).transform((nodes) => {
|
|
510
509
|
const { getInputs, getNode } = createNodeMaps(nodes);
|
|
@@ -512,28 +511,28 @@ var nodesSchema = z4.array(nodeSchema).transform((nodes) => {
|
|
|
512
511
|
const nodeIds = new Set;
|
|
513
512
|
const catchSubjects = new Map;
|
|
514
513
|
const identify = (nodeId) => identifyNode(nodeId, getNode);
|
|
515
|
-
for (const
|
|
516
|
-
if (nodeIds.has(
|
|
514
|
+
for (const node of nodes) {
|
|
515
|
+
if (nodeIds.has(node.id)) {
|
|
517
516
|
throw new NodesError("id is not unique", {
|
|
518
|
-
id:
|
|
517
|
+
id: node.id
|
|
519
518
|
});
|
|
520
519
|
}
|
|
521
|
-
nodeIds.add(
|
|
522
|
-
if ("alias" in
|
|
523
|
-
if (nodeAliases.has(
|
|
520
|
+
nodeIds.add(node.id);
|
|
521
|
+
if ("alias" in node && node.alias) {
|
|
522
|
+
if (nodeAliases.has(node.alias)) {
|
|
524
523
|
throw new NodesError("alias is not unique", {
|
|
525
|
-
alias:
|
|
524
|
+
alias: node.alias
|
|
526
525
|
});
|
|
527
526
|
}
|
|
528
|
-
nodeAliases.add(
|
|
527
|
+
nodeAliases.add(node.alias);
|
|
529
528
|
}
|
|
530
|
-
if (
|
|
531
|
-
if (catchSubjects.has(
|
|
529
|
+
if (node.type === "catch") {
|
|
530
|
+
if (catchSubjects.has(node.subject)) {
|
|
532
531
|
throw new NodesError("only one catch node per service allowed", {
|
|
533
|
-
id:
|
|
532
|
+
id: node.subject
|
|
534
533
|
});
|
|
535
534
|
}
|
|
536
|
-
catchSubjects.set(
|
|
535
|
+
catchSubjects.set(node.subject, node);
|
|
537
536
|
}
|
|
538
537
|
}
|
|
539
538
|
if (!getNode("__entry__")) {
|
|
@@ -542,21 +541,21 @@ var nodesSchema = z4.array(nodeSchema).transform((nodes) => {
|
|
|
542
541
|
if (getInputs("__exit__").length === 0) {
|
|
543
542
|
throw new NodesError("no path leads to exit");
|
|
544
543
|
}
|
|
545
|
-
for (const catchNode of nodes.filter((
|
|
544
|
+
for (const catchNode of nodes.filter((node) => node.type === "catch")) {
|
|
546
545
|
if (!getNode(catchNode.subject)) {
|
|
547
546
|
throw new NodesError("catch node has invalid subject", {
|
|
548
547
|
id: catchNode.subject
|
|
549
548
|
});
|
|
550
549
|
}
|
|
551
550
|
}
|
|
552
|
-
for (const
|
|
553
|
-
if (
|
|
554
|
-
const inputs = getInputs(
|
|
551
|
+
for (const node of nodes) {
|
|
552
|
+
if (node.type === "or") {
|
|
553
|
+
const inputs = getInputs(node);
|
|
555
554
|
if (!inputs || inputs.length < 2) {
|
|
556
555
|
throw new NodesError("or nodes need at least 2 inputs");
|
|
557
556
|
}
|
|
558
557
|
}
|
|
559
|
-
for (const targetNodeId of getNodeOutputs(
|
|
558
|
+
for (const targetNodeId of getNodeOutputs(node)) {
|
|
560
559
|
if (targetNodeId !== "__exit__" && !getNode(targetNodeId)) {
|
|
561
560
|
throw new NodesError("missing node", {
|
|
562
561
|
id: targetNodeId
|
|
@@ -578,8 +577,8 @@ var nodesSchema = z4.array(nodeSchema).transform((nodes) => {
|
|
|
578
577
|
}
|
|
579
578
|
for (const possiblePath of possiblePaths) {
|
|
580
579
|
for (const pathSegment of possiblePath) {
|
|
581
|
-
const
|
|
582
|
-
if (
|
|
580
|
+
const node = pathSegment === "__exit__" ? null : getNode(pathSegment);
|
|
581
|
+
if (node?.type === "catch" && possiblePath.includes(node.subject)) {
|
|
583
582
|
throw new NodesError("Unresolvable, inputs needs both catch and subject", {
|
|
584
583
|
path: possiblePath.map(identify)
|
|
585
584
|
});
|
|
@@ -606,7 +605,7 @@ var createNodesSchema = z5.object({
|
|
|
606
605
|
});
|
|
607
606
|
var commandSchema = z5.union([abortSchema, createNodesSchema]);
|
|
608
607
|
// ../helpers/src/protocol/update.ts
|
|
609
|
-
import {z as z6} from "zod";
|
|
608
|
+
import { z as z6 } from "zod";
|
|
610
609
|
var baseUpdateSchema = z6.object({
|
|
611
610
|
timestamp: z6.number().int().transform((int) => new Date(int))
|
|
612
611
|
});
|
|
@@ -668,22 +667,11 @@ var updateSchema = z6.discriminatedUnion("type", [
|
|
|
668
667
|
taskErrorUpdateSchema,
|
|
669
668
|
taskFinishedUpdateSchema
|
|
670
669
|
]);
|
|
671
|
-
// src/
|
|
672
|
-
import {connect} from "amqp-connection-manager";
|
|
673
|
-
import
|
|
674
|
-
import {z as z7} from "zod";
|
|
670
|
+
// src/createAmqpConnection.ts
|
|
671
|
+
import { connect } from "amqp-connection-manager";
|
|
672
|
+
import { z as z7 } from "zod";
|
|
675
673
|
|
|
676
674
|
// src/helpers.ts
|
|
677
|
-
function isOutputValue(value) {
|
|
678
|
-
return value !== null && typeof value === "object" && OUTPUT_VALUE in value;
|
|
679
|
-
}
|
|
680
|
-
function unwrapResult(result) {
|
|
681
|
-
if (isOutputValue(result)) {
|
|
682
|
-
return { value: result.value, outputName: result[OUTPUT_VALUE] };
|
|
683
|
-
}
|
|
684
|
-
return { value: result, outputName: null };
|
|
685
|
-
}
|
|
686
|
-
|
|
687
675
|
class RetryError extends Error {
|
|
688
676
|
delay;
|
|
689
677
|
constructor(delay) {
|
|
@@ -695,6 +683,15 @@ class RetryError extends Error {
|
|
|
695
683
|
class AbortError extends Error {
|
|
696
684
|
}
|
|
697
685
|
var OUTPUT_VALUE = Symbol("output_value");
|
|
686
|
+
function isOutputValue(value) {
|
|
687
|
+
return value !== null && typeof value === "object" && OUTPUT_VALUE in value;
|
|
688
|
+
}
|
|
689
|
+
function unwrapResult(result) {
|
|
690
|
+
if (isOutputValue(result)) {
|
|
691
|
+
return { value: result.value, outputName: result[OUTPUT_VALUE] };
|
|
692
|
+
}
|
|
693
|
+
return { value: result, outputName: null };
|
|
694
|
+
}
|
|
698
695
|
function createExtendedContextHelper(options) {
|
|
699
696
|
const contextHelper = createContextHelper(options.context, options.nodes);
|
|
700
697
|
const internalContext = getInternalContext(contextHelper);
|
|
@@ -741,10 +738,7 @@ function createExtendedContextHelper(options) {
|
|
|
741
738
|
});
|
|
742
739
|
}
|
|
743
740
|
|
|
744
|
-
// src/
|
|
745
|
-
function isMessageHandlerGenerator(handler) {
|
|
746
|
-
return handler.constructor.name === "GeneratorFunction" || handler.constructor.name === "AsyncGeneratorFunction";
|
|
747
|
-
}
|
|
741
|
+
// src/createAmqpConnection.ts
|
|
748
742
|
var messageKeySchema = z7.string().transform((str) => deobfuscate(str)).pipe(z7.array(z7.string().uuid()).length(3)).transform((arr) => ({
|
|
749
743
|
taskId: arr[0],
|
|
750
744
|
serviceId: arr[1],
|
|
@@ -772,6 +766,9 @@ var payloadSchema = z7.object({ content: z7.instanceof(Buffer) }).transform((msg
|
|
|
772
766
|
state: z7.record(z7.any())
|
|
773
767
|
})
|
|
774
768
|
}));
|
|
769
|
+
function isMessageHandlerGenerator(handler) {
|
|
770
|
+
return handler.constructor.name === "GeneratorFunction" || handler.constructor.name === "AsyncGeneratorFunction";
|
|
771
|
+
}
|
|
775
772
|
var activeMessages = new Set;
|
|
776
773
|
function createConnection({
|
|
777
774
|
url,
|
|
@@ -780,7 +777,7 @@ function createConnection({
|
|
|
780
777
|
silent = false,
|
|
781
778
|
connectionTimeout
|
|
782
779
|
}, messageHandler) {
|
|
783
|
-
const queue = url.username
|
|
780
|
+
const queue = `${url.username}@${version}`;
|
|
784
781
|
const exchange = url.username;
|
|
785
782
|
const connection = connect(url.toString());
|
|
786
783
|
const connectedPromise = new Promise((resolve, reject) => {
|
|
@@ -836,36 +833,9 @@ function createConnection({
|
|
|
836
833
|
try {
|
|
837
834
|
let deferred = false;
|
|
838
835
|
let deferredReason = null;
|
|
839
|
-
const {
|
|
840
|
-
messageId,
|
|
841
|
-
serviceId,
|
|
842
|
-
taskId,
|
|
843
|
-
version: expectedVersion
|
|
844
|
-
} = headerSchema.parse(message);
|
|
836
|
+
const { messageId, serviceId, taskId } = headerSchema.parse(message);
|
|
845
837
|
activeMessages.add(messageId);
|
|
846
838
|
removeActiveMessage = () => activeMessages.delete(messageId);
|
|
847
|
-
if (!semver.satisfies(version, expectedVersion)) {
|
|
848
|
-
let expirationDate = message.properties.headers?.["original-expiration-date"] ?? null;
|
|
849
|
-
if (!expirationDate && message.properties.expiration) {
|
|
850
|
-
expirationDate = String(Date.now() + parseInt(message.properties.expiration));
|
|
851
|
-
}
|
|
852
|
-
if (expirationDate && Date.now() > parseInt(expirationDate)) {
|
|
853
|
-
channel.nack(message, false, false);
|
|
854
|
-
return;
|
|
855
|
-
}
|
|
856
|
-
const properties = {
|
|
857
|
-
...message.properties,
|
|
858
|
-
headers: {
|
|
859
|
-
...message.properties.headers,
|
|
860
|
-
"version-mismatch": version,
|
|
861
|
-
"original-expiration-date": expirationDate
|
|
862
|
-
},
|
|
863
|
-
expiration: 0
|
|
864
|
-
};
|
|
865
|
-
channel.publish(`${exchange}-retry`, "retry", message.content, properties);
|
|
866
|
-
channel.ack(message);
|
|
867
|
-
return;
|
|
868
|
-
}
|
|
869
839
|
const payload = payloadSchema.parse(message);
|
|
870
840
|
let acked = false;
|
|
871
841
|
const ack = () => {
|
|
@@ -920,13 +890,15 @@ function createConnection({
|
|
|
920
890
|
console.warn("returning a value in a deferred message resets the deferred status");
|
|
921
891
|
}
|
|
922
892
|
const { value, outputName } = unwrapResult(result);
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
893
|
+
if (!done || typeof value !== "undefined") {
|
|
894
|
+
publish({
|
|
895
|
+
messageId,
|
|
896
|
+
taskId,
|
|
897
|
+
serviceId,
|
|
898
|
+
data: value,
|
|
899
|
+
outputName
|
|
900
|
+
});
|
|
901
|
+
}
|
|
930
902
|
if (done) {
|
|
931
903
|
break;
|
|
932
904
|
}
|
|
@@ -949,14 +921,14 @@ function createConnection({
|
|
|
949
921
|
});
|
|
950
922
|
}
|
|
951
923
|
}
|
|
952
|
-
publish({
|
|
924
|
+
setImmediate(() => publish({
|
|
953
925
|
messageId,
|
|
954
926
|
taskId,
|
|
955
927
|
serviceId,
|
|
956
928
|
data: deferredReason,
|
|
957
929
|
deferred,
|
|
958
930
|
done: !deferred
|
|
959
|
-
});
|
|
931
|
+
}));
|
|
960
932
|
} catch (error) {
|
|
961
933
|
if (error instanceof RetryError) {
|
|
962
934
|
const properties = {
|
|
@@ -1005,61 +977,63 @@ function createConnection({
|
|
|
1005
977
|
}
|
|
1006
978
|
});
|
|
1007
979
|
const api = {
|
|
1008
|
-
close: () =>
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
const { taskId, serviceId, messageId } = messageKeySchema.parse(messageKey);
|
|
1012
|
-
if (activeMessages.has(messageId)) {
|
|
1013
|
-
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1014
|
-
}
|
|
1015
|
-
publish({
|
|
1016
|
-
messageId,
|
|
1017
|
-
taskId,
|
|
1018
|
-
serviceId,
|
|
1019
|
-
data,
|
|
1020
|
-
outputName
|
|
1021
|
-
});
|
|
980
|
+
close: async () => {
|
|
981
|
+
await channel.close();
|
|
982
|
+
await connection.close();
|
|
1022
983
|
},
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
984
|
+
open: () => connectedPromise.then(() => api),
|
|
985
|
+
async act(messageKey, actor) {
|
|
986
|
+
await actor({
|
|
987
|
+
sendToOutput(outputName, data) {
|
|
988
|
+
const { taskId: taskId2, serviceId: serviceId2, messageId: messageId2 } = messageKeySchema.parse(messageKey);
|
|
989
|
+
if (activeMessages.has(messageId2)) {
|
|
990
|
+
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
991
|
+
}
|
|
992
|
+
publish({
|
|
993
|
+
messageId: messageId2,
|
|
994
|
+
taskId: taskId2,
|
|
995
|
+
serviceId: serviceId2,
|
|
996
|
+
data,
|
|
997
|
+
outputName
|
|
998
|
+
});
|
|
999
|
+
},
|
|
1000
|
+
send(data) {
|
|
1001
|
+
const { taskId: taskId2, serviceId: serviceId2, messageId: messageId2 } = messageKeySchema.parse(messageKey);
|
|
1002
|
+
if (activeMessages.has(messageId2)) {
|
|
1003
|
+
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1004
|
+
}
|
|
1005
|
+
publish({
|
|
1006
|
+
messageId: messageId2,
|
|
1007
|
+
taskId: taskId2,
|
|
1008
|
+
serviceId: serviceId2,
|
|
1009
|
+
data
|
|
1010
|
+
});
|
|
1011
|
+
},
|
|
1012
|
+
abort(error) {
|
|
1013
|
+
const { taskId: taskId2, serviceId: serviceId2, messageId: messageId2 } = messageKeySchema.parse(messageKey);
|
|
1014
|
+
if (activeMessages.has(messageId2)) {
|
|
1015
|
+
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1016
|
+
}
|
|
1017
|
+
channel.publish(`${exchange}-retry`, "requeue", error instanceof Error ? error.message : error, {
|
|
1018
|
+
correlationId: messageId2,
|
|
1019
|
+
expiration: 0,
|
|
1020
|
+
priority: 0,
|
|
1021
|
+
contentType: "text/plain",
|
|
1022
|
+
headers: {
|
|
1023
|
+
taskId: taskId2,
|
|
1024
|
+
serviceId: serviceId2,
|
|
1025
|
+
abort: true
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1033
1029
|
});
|
|
1034
|
-
},
|
|
1035
|
-
end(messageKey) {
|
|
1036
1030
|
const { taskId, serviceId, messageId } = messageKeySchema.parse(messageKey);
|
|
1037
|
-
|
|
1038
|
-
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1039
|
-
}
|
|
1040
|
-
publish({
|
|
1031
|
+
setImmediate(() => publish({
|
|
1041
1032
|
messageId,
|
|
1042
1033
|
taskId,
|
|
1043
1034
|
serviceId,
|
|
1044
1035
|
done: true
|
|
1045
|
-
});
|
|
1046
|
-
},
|
|
1047
|
-
abort(messageKey, error) {
|
|
1048
|
-
const { taskId, serviceId, messageId } = messageKeySchema.parse(messageKey);
|
|
1049
|
-
if (activeMessages.has(messageId)) {
|
|
1050
|
-
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1051
|
-
}
|
|
1052
|
-
channel.publish(`${exchange}-retry`, "requeue", error instanceof Error ? error.message : error, {
|
|
1053
|
-
correlationId: messageId,
|
|
1054
|
-
expiration: 0,
|
|
1055
|
-
priority: 0,
|
|
1056
|
-
contentType: "text/plain",
|
|
1057
|
-
headers: {
|
|
1058
|
-
taskId,
|
|
1059
|
-
serviceId,
|
|
1060
|
-
abort: true
|
|
1061
|
-
}
|
|
1062
|
-
});
|
|
1036
|
+
}));
|
|
1063
1037
|
}
|
|
1064
1038
|
};
|
|
1065
1039
|
return api;
|
|
@@ -1091,7 +1065,7 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
1091
1065
|
}
|
|
1092
1066
|
const key = options.serviceKey ?? process.env.REQUENCE_SERVICE_KEY ?? JSON.parse(readFileSync("package.json", "utf-8")).requence?.serviceKey;
|
|
1093
1067
|
if (!key) {
|
|
1094
|
-
throw Error("No service key found");
|
|
1068
|
+
throw new Error("No service key found");
|
|
1095
1069
|
}
|
|
1096
1070
|
const parts = deobfuscate(key);
|
|
1097
1071
|
if (parts.length < 2 || parts[0] !== "service") {
|
|
@@ -1107,5 +1081,5 @@ export {
|
|
|
1107
1081
|
createService as default
|
|
1108
1082
|
};
|
|
1109
1083
|
|
|
1110
|
-
//# debugId=
|
|
1084
|
+
//# debugId=8A6F0759E8DF605064756E2164756E21
|
|
1111
1085
|
//# sourceMappingURL=index.js.map
|