@requence/service 1.0.0-alpha.18 → 1.0.0-alpha.19
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 +6 -0
- package/build/index.js +192 -823
- package/build/index.js.map +12 -23
- package/build/types/helpers/src/files/fileObject.d.ts +16 -0
- package/build/types/helpers/src/files/fileObject.d.ts.map +1 -0
- package/build/types/helpers/src/files/index.d.ts +2 -43
- package/build/types/helpers/src/files/index.d.ts.map +1 -1
- package/build/types/helpers/src/files/mapOutput.d.ts +1 -1
- package/build/types/helpers/src/files/mapOutput.d.ts.map +1 -1
- package/build/types/helpers/src/files/streamObject.d.ts +14 -0
- package/build/types/helpers/src/files/streamObject.d.ts.map +1 -0
- package/build/types/helpers/src/index.d.ts +1 -0
- package/build/types/helpers/src/index.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/validate.d.ts +1 -0
- package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/zod.d.ts +4 -12
- package/build/types/helpers/src/jsonschema/zod.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/NodeTree.d.ts +504 -0
- package/build/types/helpers/src/protocol/NodeTree.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/NodesError.d.ts +5 -0
- package/build/types/helpers/src/protocol/NodesError.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/command.d.ts +373 -1954
- package/build/types/helpers/src/protocol/command.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/index.d.ts +5 -7
- package/build/types/helpers/src/protocol/index.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/nodeOptions.d.ts +16 -0
- package/build/types/helpers/src/protocol/nodeOptions.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/nodeType.d.ts +283 -0
- package/build/types/helpers/src/protocol/nodeType.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/targetNodes.d.ts +253 -0
- package/build/types/helpers/src/protocol/targetNodes.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/treeNodes.d.ts +606 -0
- package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/update.d.ts +182 -17892
- package/build/types/helpers/src/protocol/update.d.ts.map +1 -1
- package/build/types/helpers/src/utils/mapData.d.ts +4 -0
- package/build/types/helpers/src/utils/mapData.d.ts.map +1 -1
- package/build/types/helpers/src/utils/matchSchema.d.ts +1 -1
- package/build/types/helpers/src/utils/matchSchema.d.ts.map +1 -1
- package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts +2 -0
- package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts.map +1 -0
- package/build/types/helpers/src/utils/types.d.ts +4 -0
- package/build/types/helpers/src/utils/types.d.ts.map +1 -0
- package/build/types/service/src/createAmqpConnection.d.ts +4 -6
- package/build/types/service/src/createAmqpConnection.d.ts.map +1 -1
- package/build/types/service/src/helpers.d.ts +8 -68
- package/build/types/service/src/helpers.d.ts.map +1 -1
- package/package.json +2 -2
- package/build/types/helpers/src/context/context.d.ts +0 -156
- package/build/types/helpers/src/context/context.d.ts.map +0 -1
- package/build/types/helpers/src/context/index.d.ts +0 -2
- package/build/types/helpers/src/context/index.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/createNodeMaps.d.ts +0 -10
- package/build/types/helpers/src/protocol/createNodeMaps.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/getCycles.d.ts +0 -3
- package/build/types/helpers/src/protocol/getCycles.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/getNodeOutputs.d.ts +0 -4
- package/build/types/helpers/src/protocol/getNodeOutputs.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/getPossiblePaths.d.ts +0 -9
- package/build/types/helpers/src/protocol/getPossiblePaths.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/identifyNode.d.ts +0 -4
- package/build/types/helpers/src/protocol/identifyNode.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/node.d.ts +0 -1014
- package/build/types/helpers/src/protocol/node.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/nodes.d.ts +0 -801
- package/build/types/helpers/src/protocol/nodes.d.ts.map +0 -1
package/build/index.js
CHANGED
|
@@ -6,48 +6,6 @@ import {
|
|
|
6
6
|
// src/index.ts
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
|
|
9
|
-
// ../helpers/src/utils/clone.ts
|
|
10
|
-
var CLONE_SYMBOL = Symbol("original");
|
|
11
|
-
function clone(data) {
|
|
12
|
-
if (typeof data !== "object" || data === null) {
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
const target = data[CLONE_SYMBOL];
|
|
16
|
-
if (target) {
|
|
17
|
-
return clone(target);
|
|
18
|
-
}
|
|
19
|
-
if (Array.isArray(data)) {
|
|
20
|
-
return data.map(clone);
|
|
21
|
-
}
|
|
22
|
-
return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, clone(value)]));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// ../helpers/src/utils/createObjectProxy.ts
|
|
26
|
-
function createObjectProxy(obj, onChange) {
|
|
27
|
-
return new Proxy(obj, {
|
|
28
|
-
set(target, property, newValue) {
|
|
29
|
-
const result = Reflect.set(target, property, newValue);
|
|
30
|
-
onChange(target);
|
|
31
|
-
return result;
|
|
32
|
-
},
|
|
33
|
-
deleteProperty(target, property) {
|
|
34
|
-
const result = Reflect.deleteProperty(target, property);
|
|
35
|
-
onChange(target);
|
|
36
|
-
return result;
|
|
37
|
-
},
|
|
38
|
-
get(target, property, receiver) {
|
|
39
|
-
if (property === CLONE_SYMBOL) {
|
|
40
|
-
return target;
|
|
41
|
-
}
|
|
42
|
-
const result = Reflect.get(target, property, receiver);
|
|
43
|
-
if (typeof result === "object" && result !== null) {
|
|
44
|
-
return createObjectProxy(result, () => onChange(target));
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
9
|
// ../helpers/src/utils/createRemotePromise.ts
|
|
52
10
|
function createRemotePromise(onAwait) {
|
|
53
11
|
let resolvePromise;
|
|
@@ -77,8 +35,8 @@ function createRemotePromise(onAwait) {
|
|
|
77
35
|
}
|
|
78
36
|
|
|
79
37
|
// ../helpers/src/utils/isRecord.ts
|
|
80
|
-
import { z } from "zod";
|
|
81
|
-
var recordSchema = z.record(z.unknown());
|
|
38
|
+
import { z } from "zod/v4";
|
|
39
|
+
var recordSchema = z.record(z.string(), z.unknown());
|
|
82
40
|
function isRecord(data) {
|
|
83
41
|
return recordSchema.safeParse(data).success;
|
|
84
42
|
}
|
|
@@ -93,60 +51,73 @@ function resolve(value, onResolve) {
|
|
|
93
51
|
function notUndefined(value, fallback) {
|
|
94
52
|
return resolve(value, (resolvedValue) => typeof resolvedValue === "undefined" ? fallback : resolvedValue);
|
|
95
53
|
}
|
|
54
|
+
|
|
55
|
+
class AbortMapData extends Error {
|
|
56
|
+
}
|
|
96
57
|
function mapData(data, visitors) {
|
|
58
|
+
let aborted = false;
|
|
97
59
|
const traverseData = (data2, path) => {
|
|
98
|
-
if (
|
|
99
|
-
return
|
|
100
|
-
if (resolvedData) {
|
|
101
|
-
return resolvedData;
|
|
102
|
-
}
|
|
103
|
-
const items = data2.map((item, index) => traverseData(item, [...path, index]));
|
|
104
|
-
if (items.some((item) => item instanceof Promise)) {
|
|
105
|
-
return Promise.all(items);
|
|
106
|
-
}
|
|
107
|
-
return items;
|
|
108
|
-
});
|
|
60
|
+
if (aborted) {
|
|
61
|
+
return data2;
|
|
109
62
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
63
|
+
try {
|
|
64
|
+
if (Array.isArray(data2)) {
|
|
65
|
+
return resolve(visitors.Array?.(data2, path), (resolvedData) => {
|
|
66
|
+
if (resolvedData) {
|
|
67
|
+
return resolvedData;
|
|
68
|
+
}
|
|
69
|
+
const items = data2.map((item, index) => traverseData(item, [...path, index]));
|
|
70
|
+
if (items.some((item) => item instanceof Promise)) {
|
|
71
|
+
return Promise.all(items);
|
|
72
|
+
}
|
|
73
|
+
return items;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (data2 === null) {
|
|
77
|
+
return notUndefined(visitors.Null?.(data2, path), data2);
|
|
78
|
+
}
|
|
79
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data2)) {
|
|
80
|
+
return notUndefined(visitors.Buffer?.(data2, path), data2);
|
|
81
|
+
}
|
|
82
|
+
if (typeof data2 === "string") {
|
|
83
|
+
return notUndefined(visitors.String?.(data2, path), data2);
|
|
84
|
+
}
|
|
85
|
+
if (typeof data2 === "number") {
|
|
86
|
+
return notUndefined(visitors.Number?.(data2, path), data2);
|
|
87
|
+
}
|
|
88
|
+
if (typeof data2 === "symbol") {
|
|
89
|
+
return notUndefined(visitors.Symbol?.(data2, path), data2);
|
|
90
|
+
}
|
|
91
|
+
if (isRecord(data2)) {
|
|
92
|
+
return resolve(visitors.Object?.(structuredClone(data2), path), (resolvedData) => {
|
|
93
|
+
const nextData = resolvedData ?? data2;
|
|
94
|
+
const entries = Object.entries(nextData).map(([key, value]) => [
|
|
95
|
+
key,
|
|
96
|
+
traverseData(value, [...path, key])
|
|
97
|
+
]);
|
|
98
|
+
if (entries.some(([, value]) => value instanceof Promise)) {
|
|
99
|
+
return Promise.all(entries.map(([key, value]) => Promise.resolve().then(() => value).then((resolvedValue) => [key, resolvedValue]))).then((entries2) => Object.fromEntries(entries2));
|
|
100
|
+
}
|
|
101
|
+
return Object.fromEntries(entries);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (typeof data2 === "object" && data2) {
|
|
105
|
+
return notUndefined(visitors.Object?.(data2, path), data2);
|
|
106
|
+
}
|
|
107
|
+
return data2;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (error instanceof AbortMapData) {
|
|
110
|
+
aborted = true;
|
|
111
|
+
return data2;
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
136
114
|
}
|
|
137
|
-
return data2;
|
|
138
115
|
};
|
|
139
116
|
return traverseData(data, []);
|
|
140
117
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// ../helpers/src/context/context.ts
|
|
146
|
-
import { z as z3 } from "zod";
|
|
147
|
-
|
|
148
|
-
// ../helpers/src/files/index.ts
|
|
149
|
-
import { z as z2 } from "zod";
|
|
118
|
+
mapData.abort = () => {
|
|
119
|
+
throw new AbortMapData;
|
|
120
|
+
};
|
|
150
121
|
|
|
151
122
|
// ../helpers/src/files/mapOutput.ts
|
|
152
123
|
async function upload(uploadUrl, body, signal, contentType) {
|
|
@@ -253,29 +224,7 @@ async function mapOutput(params) {
|
|
|
253
224
|
Promise.allSettled(streamPromises).then(() => params.onDone?.());
|
|
254
225
|
return mapped;
|
|
255
226
|
}
|
|
256
|
-
|
|
257
|
-
import { extension } from "mime-types";
|
|
258
|
-
function isValidMimeType(fileInfo, accept) {
|
|
259
|
-
const ext = fileInfo.ext ?? (extension(fileInfo.mime) || "???");
|
|
260
|
-
const mimeType = fileInfo.mime.toLowerCase().split(";")[0].trim();
|
|
261
|
-
const acceptTypes = accept.split(",").map((type) => type.toLowerCase().split(";")[0].trim());
|
|
262
|
-
return acceptTypes.some((acceptedType) => {
|
|
263
|
-
if (acceptedType === "*/*") {
|
|
264
|
-
return true;
|
|
265
|
-
}
|
|
266
|
-
if (acceptedType.endsWith("/*")) {
|
|
267
|
-
const baseType = acceptedType.split("/")[0];
|
|
268
|
-
return mimeType.startsWith(baseType + "/");
|
|
269
|
-
}
|
|
270
|
-
if (acceptedType.includes("/")) {
|
|
271
|
-
return mimeType === acceptedType;
|
|
272
|
-
}
|
|
273
|
-
if (acceptedType.startsWith(".")) {
|
|
274
|
-
return ext.toLowerCase().endsWith(acceptedType);
|
|
275
|
-
}
|
|
276
|
-
return false;
|
|
277
|
-
});
|
|
278
|
-
}
|
|
227
|
+
|
|
279
228
|
// ../helpers/src/files/RequenceFile.ts
|
|
280
229
|
class RequenceFile {
|
|
281
230
|
#data;
|
|
@@ -334,6 +283,7 @@ class RequenceFile {
|
|
|
334
283
|
return `RequenceFile<${this.mimeType}>`;
|
|
335
284
|
}
|
|
336
285
|
}
|
|
286
|
+
|
|
337
287
|
// ../helpers/src/files/RequenceStream.ts
|
|
338
288
|
class RequenceStream {
|
|
339
289
|
#data;
|
|
@@ -395,608 +345,63 @@ class RequenceStream {
|
|
|
395
345
|
}
|
|
396
346
|
}
|
|
397
347
|
|
|
398
|
-
// ../helpers/src/files/
|
|
399
|
-
|
|
400
|
-
size: z2.number().int().positive(),
|
|
401
|
-
mime: z2.string(),
|
|
402
|
-
url: z2.string().url(),
|
|
403
|
-
__REQUENCE_type: z2.literal("RequenceFile")
|
|
404
|
-
});
|
|
405
|
-
function toFileObject(fileInfo) {
|
|
406
|
-
return {
|
|
407
|
-
...fileInfo,
|
|
408
|
-
__REQUENCE_type: "RequenceFile"
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
function isFileObject(data) {
|
|
412
|
-
return fileObjectSchema.safeParse(data).success;
|
|
413
|
-
}
|
|
348
|
+
// ../helpers/src/files/streamObject.ts
|
|
349
|
+
import { z as z2 } from "zod/v4";
|
|
414
350
|
var streamObjectSchema = z2.object({
|
|
415
351
|
mime: z2.string(),
|
|
416
352
|
url: z2.string().url(),
|
|
417
353
|
__REQUENCE_type: z2.literal("RequenceStream")
|
|
418
354
|
});
|
|
355
|
+
function isStreamObject(data) {
|
|
356
|
+
return streamObjectSchema.safeParse(data).success;
|
|
357
|
+
}
|
|
419
358
|
function toStreamObject(streamInfo) {
|
|
420
359
|
return {
|
|
421
360
|
...streamInfo,
|
|
422
361
|
__REQUENCE_type: "RequenceStream"
|
|
423
362
|
};
|
|
424
363
|
}
|
|
425
|
-
function isStreamObject(data) {
|
|
426
|
-
return streamObjectSchema.safeParse(data).success;
|
|
427
|
-
}
|
|
428
364
|
|
|
429
|
-
// ../helpers/src/
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
dates: z3.record(z3.string(), z3.string().datetime())
|
|
365
|
+
// ../helpers/src/files/fileObject.ts
|
|
366
|
+
import { z as z3 } from "zod/v4";
|
|
367
|
+
var fileObjectSchema = z3.object({
|
|
368
|
+
size: z3.number().int().positive(),
|
|
369
|
+
mime: z3.string(),
|
|
370
|
+
url: z3.string().url(),
|
|
371
|
+
__REQUENCE_type: z3.literal("RequenceFile")
|
|
437
372
|
});
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
// ../helpers/src/protocol/command.ts
|
|
441
|
-
import { z as z7 } from "zod";
|
|
442
|
-
|
|
443
|
-
// ../helpers/src/protocol/nodes.ts
|
|
444
|
-
import { ZodError, z as z6 } from "zod";
|
|
445
|
-
|
|
446
|
-
// ../helpers/src/protocol/getNodeOutputs.ts
|
|
447
|
-
function getNodeOutputs(node, outputName) {
|
|
448
|
-
const outputs = !outputName ? node.output : outputName === "__default__" ? node.output.filter((o) => o.default) : node.output.filter((o) => ("name" in o) && o.name === outputName);
|
|
449
|
-
const outputTargets = new Set;
|
|
450
|
-
for (const output of outputs) {
|
|
451
|
-
if (output.exit) {
|
|
452
|
-
outputTargets.add("__exit__");
|
|
453
|
-
} else {
|
|
454
|
-
outputTargets.add(output.target);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
return Array.from(outputTargets);
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// ../helpers/src/protocol/createNodeMaps.ts
|
|
461
|
-
function createNodeMaps(nodes) {
|
|
462
|
-
const nodesByIdMap = new Map;
|
|
463
|
-
const nodesByNameOrAlias = new Map;
|
|
464
|
-
const inputsNodeMap = new Map([
|
|
465
|
-
["__exit__", []]
|
|
466
|
-
]);
|
|
467
|
-
for (const node of nodes) {
|
|
468
|
-
nodesByIdMap.set(node.id, node);
|
|
469
|
-
if ("alias" in node && node.alias) {
|
|
470
|
-
nodesByNameOrAlias.set(node.alias, node);
|
|
471
|
-
}
|
|
472
|
-
if ("name" in node && node.name) {
|
|
473
|
-
nodesByNameOrAlias.set(node.name, node);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
for (const node of nodes) {
|
|
477
|
-
for (const outputNodeId of getNodeOutputs(node)) {
|
|
478
|
-
if (!inputsNodeMap.has(outputNodeId)) {
|
|
479
|
-
inputsNodeMap.set(outputNodeId, []);
|
|
480
|
-
}
|
|
481
|
-
inputsNodeMap.get(outputNodeId).push(node);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
373
|
+
function toFileObject(fileInfo) {
|
|
484
374
|
return {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return inputsNodeMap.get(node) ?? [];
|
|
488
|
-
}
|
|
489
|
-
if (node.type === "catch" || node.type === "entry") {
|
|
490
|
-
return [];
|
|
491
|
-
}
|
|
492
|
-
return inputsNodeMap.get(node.id) ?? [];
|
|
493
|
-
},
|
|
494
|
-
getNode(nodeId) {
|
|
495
|
-
return nodesByIdMap.get(nodeId);
|
|
496
|
-
},
|
|
497
|
-
lookupNode(nameOrAlias) {
|
|
498
|
-
return nodesByNameOrAlias.get(nameOrAlias);
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// ../helpers/src/protocol/getPossiblePaths.ts
|
|
504
|
-
function getPossiblePaths({
|
|
505
|
-
getInputs,
|
|
506
|
-
getNode,
|
|
507
|
-
onMissingInputs
|
|
508
|
-
}) {
|
|
509
|
-
const sets = new Set;
|
|
510
|
-
const followPath = (nodeId, set2) => {
|
|
511
|
-
if (nodeId === "__entry__") {
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
const node = nodeId !== "__exit__" ? getNode(nodeId) : null;
|
|
515
|
-
const isOrNode = node?.type === "or";
|
|
516
|
-
const inputNodes = getInputs(nodeId);
|
|
517
|
-
if (node && node.type !== "catch" && inputNodes.length === 0) {
|
|
518
|
-
onMissingInputs?.(node, Array.from(set2).toReversed());
|
|
519
|
-
}
|
|
520
|
-
for (const inputNode of inputNodes) {
|
|
521
|
-
let usedSet = set2;
|
|
522
|
-
if (isOrNode) {
|
|
523
|
-
usedSet = new Set(set2);
|
|
524
|
-
sets.add(usedSet);
|
|
525
|
-
}
|
|
526
|
-
const inputNodeId = inputNode.id;
|
|
527
|
-
if (inputNode.type !== "or") {
|
|
528
|
-
if (usedSet.has(inputNodeId)) {
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
usedSet.add(inputNodeId);
|
|
532
|
-
}
|
|
533
|
-
followPath(inputNodeId, usedSet);
|
|
534
|
-
}
|
|
535
|
-
if (isOrNode) {
|
|
536
|
-
sets.delete(set2);
|
|
537
|
-
}
|
|
375
|
+
...fileInfo,
|
|
376
|
+
__REQUENCE_type: "RequenceFile"
|
|
538
377
|
};
|
|
539
|
-
const set = new Set(["__exit__"]);
|
|
540
|
-
sets.add(set);
|
|
541
|
-
followPath("__exit__", set);
|
|
542
|
-
return Array.from(sets, (set2) => Array.from(set2).toReversed());
|
|
543
378
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
function identifyNode(nodeId, getNode) {
|
|
547
|
-
if (nodeId === "__entry__") {
|
|
548
|
-
return "ENTRY";
|
|
549
|
-
}
|
|
550
|
-
if (nodeId === "__exit__") {
|
|
551
|
-
return "EXIT";
|
|
552
|
-
}
|
|
553
|
-
if (typeof nodeId === "symbol") {
|
|
554
|
-
return String(nodeId);
|
|
555
|
-
}
|
|
556
|
-
const node = getNode(nodeId);
|
|
557
|
-
if (!node) {
|
|
558
|
-
return `Unknown[${nodeId}]`;
|
|
559
|
-
}
|
|
560
|
-
switch (node.type) {
|
|
561
|
-
case "service": {
|
|
562
|
-
return `Service[${node.alias || node.name}]`;
|
|
563
|
-
}
|
|
564
|
-
case "catch": {
|
|
565
|
-
return `Catch[${identifyNode(node.subject, getNode)}]`;
|
|
566
|
-
}
|
|
567
|
-
case "logic": {
|
|
568
|
-
return `Logic[${node.alias || node.id}]`;
|
|
569
|
-
}
|
|
570
|
-
case "entry": {
|
|
571
|
-
return "ENTRY";
|
|
572
|
-
}
|
|
573
|
-
case "or": {
|
|
574
|
-
return `OR[${node.alias || node.id}]`;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
379
|
+
function isFileObject(data) {
|
|
380
|
+
return fileObjectSchema.safeParse(data).success;
|
|
577
381
|
}
|
|
578
382
|
|
|
579
|
-
// ../helpers/src/
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
// ../helpers/src/jsonschema/validate.ts
|
|
586
|
-
import {
|
|
587
|
-
Ajv as BaseAjv
|
|
588
|
-
} from "ajv";
|
|
589
|
-
var acceptKeyword = {
|
|
590
|
-
keyword: "accept",
|
|
591
|
-
type: "object",
|
|
592
|
-
metaSchema: {
|
|
593
|
-
type: "string",
|
|
594
|
-
pattern: "^\\s*(?:(?:\\w+/\\*|\\w+/[-+.\\w]+|\\*/\\*))(?:\\s*,\\s*(?:(?:\\w+/\\*|\\w+/[-+.\\w]+|\\*/\\*)))*\\s*$"
|
|
595
|
-
}
|
|
596
|
-
};
|
|
597
|
-
var acceptKeywordEnforced = {
|
|
598
|
-
...acceptKeyword,
|
|
599
|
-
compile: (accept) => function validate(data) {
|
|
600
|
-
const errors = validate.errors = [];
|
|
601
|
-
if (isFileObject(data) || isStreamObject(data)) {
|
|
602
|
-
if (!isValidMimeType(data, accept)) {
|
|
603
|
-
errors.push({ message: `must be of type ${accept}` });
|
|
604
|
-
return false;
|
|
383
|
+
// ../helpers/src/utils/resolveRequenceTypes.ts
|
|
384
|
+
function resolveRequenceTypes(data) {
|
|
385
|
+
return mapData(data, {
|
|
386
|
+
Object(obj) {
|
|
387
|
+
if (isFileObject(obj)) {
|
|
388
|
+
return RequenceFile.fromFileObject(obj);
|
|
605
389
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
return false;
|
|
609
|
-
}
|
|
610
|
-
return true;
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
var requenceTypeKeywords = {
|
|
614
|
-
keyword: "requenceType",
|
|
615
|
-
metaSchema: {
|
|
616
|
-
enum: ["file", "stream"]
|
|
617
|
-
}
|
|
618
|
-
};
|
|
619
|
-
var instanceOfKeyword = {
|
|
620
|
-
keyword: "instanceOf",
|
|
621
|
-
schemaType: "string",
|
|
622
|
-
compile: (schema) => function validate(data) {
|
|
623
|
-
const errors = validate.errors = [];
|
|
624
|
-
if (typeof data !== "object" || !data || !("constructor" in data)) {
|
|
625
|
-
errors.push({ message: "not a object" });
|
|
626
|
-
return false;
|
|
627
|
-
}
|
|
628
|
-
if (data.constructor.name !== schema) {
|
|
629
|
-
errors.push({ message: `must be instanceof ${schema}` });
|
|
630
|
-
return false;
|
|
631
|
-
}
|
|
632
|
-
return true;
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
var maxByteLengthKeyword = {
|
|
636
|
-
keyword: "maxByteLength",
|
|
637
|
-
type: "object",
|
|
638
|
-
metaSchema: {
|
|
639
|
-
type: "integer",
|
|
640
|
-
minimum: 0
|
|
641
|
-
}
|
|
642
|
-
};
|
|
643
|
-
var maxByteLengthKeywordEnforced = {
|
|
644
|
-
...maxByteLengthKeyword,
|
|
645
|
-
compile: (maxByteLength) => function validate(data) {
|
|
646
|
-
const errors = validate.errors = [];
|
|
647
|
-
if (isFileObject(data)) {
|
|
648
|
-
if (data.size > maxByteLength) {
|
|
649
|
-
errors.push({
|
|
650
|
-
message: `file size must by lower tan ${maxByteLength}`
|
|
651
|
-
});
|
|
652
|
-
return false;
|
|
390
|
+
if (isStreamObject(obj)) {
|
|
391
|
+
return RequenceStream.fromStreamObject(obj);
|
|
653
392
|
}
|
|
654
|
-
} else {
|
|
655
|
-
errors.push({ message: "invalid file type" });
|
|
656
|
-
return false;
|
|
657
393
|
}
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
class Ajv extends BaseAjv {
|
|
663
|
-
constructor(options) {
|
|
664
|
-
super({
|
|
665
|
-
...options,
|
|
666
|
-
keywords: [
|
|
667
|
-
options?.enforeFileKeywords ? acceptKeywordEnforced : acceptKeyword,
|
|
668
|
-
options?.enforeFileKeywords ? maxByteLengthKeywordEnforced : maxByteLengthKeyword,
|
|
669
|
-
requenceTypeKeywords,
|
|
670
|
-
instanceOfKeyword
|
|
671
|
-
]
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// ../helpers/src/jsonschema/zod.ts
|
|
677
|
-
var jsonSchema7Schema = z4.custom((value) => {
|
|
678
|
-
const ajv = new Ajv;
|
|
679
|
-
return ajv.validateSchema(value);
|
|
680
|
-
}, { message: "Invalid json schema" });
|
|
681
|
-
var jsonSchema7ObjectSchema = z4.object({
|
|
682
|
-
type: z4.literal("object")
|
|
683
|
-
}).and(jsonSchema7Schema);
|
|
684
|
-
var jsonSchema7NullSchema = z4.object({
|
|
685
|
-
type: z4.literal("null")
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
// ../helpers/src/protocol/node.ts
|
|
689
|
-
var outputDefinitionSchema = z5.object({
|
|
690
|
-
schema: jsonSchema7Schema.nullable().optional()
|
|
691
|
-
}).and(z5.union([
|
|
692
|
-
z5.object({
|
|
693
|
-
default: z5.literal(false).default(false),
|
|
694
|
-
name: z5.string().min(1)
|
|
695
|
-
}),
|
|
696
|
-
z5.object({
|
|
697
|
-
default: z5.literal(true).default(true)
|
|
698
|
-
})
|
|
699
|
-
])).and(z5.union([
|
|
700
|
-
z5.object({
|
|
701
|
-
exit: z5.literal(false).default(false),
|
|
702
|
-
target: z5.string().min(1)
|
|
703
|
-
}),
|
|
704
|
-
z5.object({ exit: z5.literal(true) })
|
|
705
|
-
]));
|
|
706
|
-
var defaultOutputSchema = z5.union([
|
|
707
|
-
z5.string().min(1),
|
|
708
|
-
z5.object({ default: z5.literal(true).default(true), exit: z5.literal(true) }),
|
|
709
|
-
z5.object({
|
|
710
|
-
default: z5.literal(true).default(true),
|
|
711
|
-
exit: z5.literal(false).default(false),
|
|
712
|
-
target: z5.string().min(1)
|
|
713
|
-
})
|
|
714
|
-
]).transform((output) => {
|
|
715
|
-
if (typeof output === "string") {
|
|
716
|
-
return {
|
|
717
|
-
default: true,
|
|
718
|
-
exit: false,
|
|
719
|
-
target: output
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
return output;
|
|
723
|
-
});
|
|
724
|
-
var outputSchema = z5.union([z5.string().min(1), outputDefinitionSchema]).transform((output) => {
|
|
725
|
-
if (typeof output === "string") {
|
|
726
|
-
return {
|
|
727
|
-
default: true,
|
|
728
|
-
exit: false,
|
|
729
|
-
target: output
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
return output;
|
|
733
|
-
});
|
|
734
|
-
function validateOutputs(outputs, ctx) {
|
|
735
|
-
const exitOutputs = new Set(outputs.filter((output) => output.exit).map((output) => output.default ? "__default__" : output.name));
|
|
736
|
-
outputs.filter((output) => !output.exit).forEach((output) => {
|
|
737
|
-
const name = output.default ? "__default__" : output.name;
|
|
738
|
-
if (exitOutputs.has(name)) {
|
|
739
|
-
ctx.addIssue({
|
|
740
|
-
code: "custom",
|
|
741
|
-
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}"`
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
const targets = new Map;
|
|
746
|
-
outputs.forEach((output) => {
|
|
747
|
-
const name = output.default ? "__default__" : output.name;
|
|
748
|
-
const target = output.exit ? "__exit__" : output.target;
|
|
749
|
-
if (!targets.has(name)) {
|
|
750
|
-
targets.set(name, new Set);
|
|
751
|
-
}
|
|
752
|
-
const knownTargets = targets.get(name);
|
|
753
|
-
if (knownTargets.has(target)) {
|
|
754
|
-
ctx.addIssue({
|
|
755
|
-
code: "custom",
|
|
756
|
-
message: [
|
|
757
|
-
output.default ? "duplicate default output" : `duplicate named output "${name}"`,
|
|
758
|
-
output.exit ? "for exit" : `for target "${target}"`
|
|
759
|
-
].join(" ")
|
|
760
|
-
});
|
|
761
|
-
}
|
|
762
|
-
knownTargets.add(target);
|
|
763
394
|
});
|
|
764
395
|
}
|
|
765
|
-
var defaultOutputsSchema = z5.array(defaultOutputSchema).default([]).superRefine(validateOutputs);
|
|
766
|
-
var outputsSchema = z5.array(outputSchema).default([]).superRefine(validateOutputs);
|
|
767
|
-
var idSchema = z5.string().uuid().default(() => crypto.randomUUID());
|
|
768
|
-
var metaSchema = z5.record(z5.any()).optional();
|
|
769
|
-
var entryNodeSchema = z5.object({
|
|
770
|
-
type: z5.literal("entry"),
|
|
771
|
-
id: z5.literal("__entry__").default("__entry__"),
|
|
772
|
-
output: defaultOutputsSchema,
|
|
773
|
-
inputSchema: jsonSchema7Schema.default({ type: "null" }),
|
|
774
|
-
metaSchema: jsonSchema7Schema.default({ type: "null" }),
|
|
775
|
-
meta: metaSchema
|
|
776
|
-
});
|
|
777
|
-
var serviceNodeSchema = z5.object({
|
|
778
|
-
type: z5.literal("service"),
|
|
779
|
-
output: outputsSchema,
|
|
780
|
-
inputSchema: z5.union([jsonSchema7ObjectSchema, jsonSchema7NullSchema]).default({ type: "null" }),
|
|
781
|
-
id: idSchema,
|
|
782
|
-
name: z5.string(),
|
|
783
|
-
version: z5.string(),
|
|
784
|
-
configuration: z5.any().optional(),
|
|
785
|
-
configurationSchema: jsonSchema7Schema.default({ type: "null" }),
|
|
786
|
-
alias: z5.string().optional(),
|
|
787
|
-
ttl: z5.number().int().min(1).optional(),
|
|
788
|
-
retry: z5.number().int().min(1).optional(),
|
|
789
|
-
retryDelay: z5.number().int().min(100).optional(),
|
|
790
|
-
meta: metaSchema
|
|
791
|
-
});
|
|
792
|
-
var catchNodeSchema = z5.object({
|
|
793
|
-
type: z5.literal("catch"),
|
|
794
|
-
output: outputsSchema,
|
|
795
|
-
id: idSchema,
|
|
796
|
-
subject: z5.string(),
|
|
797
|
-
meta: metaSchema
|
|
798
|
-
});
|
|
799
|
-
var logicNodeSchema = z5.object({
|
|
800
|
-
type: z5.literal("logic"),
|
|
801
|
-
alias: z5.string().optional(),
|
|
802
|
-
output: outputsSchema,
|
|
803
|
-
id: idSchema,
|
|
804
|
-
script: z5.string(),
|
|
805
|
-
concurrency: z5.boolean().default(true),
|
|
806
|
-
language: z5.enum(["javascript", "python", "typescript"]).default("javascript"),
|
|
807
|
-
maxExecutionTime: z5.number().int().min(0).default(1000),
|
|
808
|
-
meta: metaSchema
|
|
809
|
-
});
|
|
810
|
-
var orNodeSchema = z5.object({
|
|
811
|
-
id: idSchema,
|
|
812
|
-
type: z5.literal("or"),
|
|
813
|
-
alias: z5.string().optional(),
|
|
814
|
-
output: outputsSchema,
|
|
815
|
-
meta: metaSchema
|
|
816
|
-
});
|
|
817
|
-
var nodeSchema = z5.discriminatedUnion("type", [
|
|
818
|
-
entryNodeSchema,
|
|
819
|
-
serviceNodeSchema,
|
|
820
|
-
catchNodeSchema,
|
|
821
|
-
logicNodeSchema,
|
|
822
|
-
orNodeSchema
|
|
823
|
-
]);
|
|
824
|
-
|
|
825
|
-
// ../helpers/src/protocol/nodes.ts
|
|
826
|
-
class NodesError extends ZodError {
|
|
827
|
-
constructor(message, params, path = []) {
|
|
828
|
-
super([
|
|
829
|
-
{
|
|
830
|
-
code: z6.ZodIssueCode.custom,
|
|
831
|
-
message,
|
|
832
|
-
path,
|
|
833
|
-
params
|
|
834
|
-
}
|
|
835
|
-
]);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
var nodesSchema = z6.array(nodeSchema).transform((nodes) => {
|
|
839
|
-
const aliases = new Map;
|
|
840
|
-
const names = new Map;
|
|
841
|
-
let entryNode = null;
|
|
842
|
-
let firstNodeId = null;
|
|
843
|
-
for (const node of nodes) {
|
|
844
|
-
if (node.type === "entry") {
|
|
845
|
-
entryNode = node;
|
|
846
|
-
}
|
|
847
|
-
if ((node.type === "service" || node.type === "logic") && !firstNodeId) {
|
|
848
|
-
firstNodeId = node.id;
|
|
849
|
-
}
|
|
850
|
-
if ("alias" in node && node.alias) {
|
|
851
|
-
if (!aliases.has(node.alias)) {
|
|
852
|
-
aliases.set(node.alias, []);
|
|
853
|
-
}
|
|
854
|
-
aliases.get(node.alias).push(node.id);
|
|
855
|
-
}
|
|
856
|
-
if ("name" in node && node.name) {
|
|
857
|
-
if (!names.has(node.name)) {
|
|
858
|
-
names.set(node.name, []);
|
|
859
|
-
}
|
|
860
|
-
names.get(node.name).push(node.id);
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
if (!entryNode && firstNodeId) {
|
|
864
|
-
nodes.unshift({
|
|
865
|
-
type: "entry",
|
|
866
|
-
id: "__entry__",
|
|
867
|
-
inputSchema: { type: "null" },
|
|
868
|
-
metaSchema: { type: "null" },
|
|
869
|
-
output: [{ default: true, exit: false, target: firstNodeId }]
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
const resolveOutput = (identifier) => {
|
|
873
|
-
if (aliases.get(identifier)?.length === 1) {
|
|
874
|
-
return aliases.get(identifier)[0];
|
|
875
|
-
}
|
|
876
|
-
if (names.get(identifier)?.length === 1) {
|
|
877
|
-
return names.get(identifier)[0];
|
|
878
|
-
}
|
|
879
|
-
return identifier;
|
|
880
|
-
};
|
|
881
|
-
return nodes.map((node) => {
|
|
882
|
-
node.output = node.output.map((output) => ("target" in output) ? {
|
|
883
|
-
...output,
|
|
884
|
-
target: resolveOutput(output.target)
|
|
885
|
-
} : output);
|
|
886
|
-
if ("subject" in node) {
|
|
887
|
-
node.subject = resolveOutput(node.subject);
|
|
888
|
-
}
|
|
889
|
-
return node;
|
|
890
|
-
});
|
|
891
|
-
}).transform((nodes) => {
|
|
892
|
-
const { getInputs, getNode } = createNodeMaps(nodes);
|
|
893
|
-
const nodeAliases = new Set;
|
|
894
|
-
const nodeIds = new Set;
|
|
895
|
-
const catchSubjects = new Map;
|
|
896
|
-
const identify = (nodeId) => identifyNode(nodeId, getNode);
|
|
897
|
-
for (const node of nodes) {
|
|
898
|
-
if (nodeIds.has(node.id)) {
|
|
899
|
-
throw new NodesError("id is not unique", {
|
|
900
|
-
id: node.id
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
nodeIds.add(node.id);
|
|
904
|
-
if ("alias" in node && node.alias) {
|
|
905
|
-
if (nodeAliases.has(node.alias)) {
|
|
906
|
-
throw new NodesError("alias is not unique", {
|
|
907
|
-
alias: node.alias
|
|
908
|
-
});
|
|
909
|
-
}
|
|
910
|
-
nodeAliases.add(node.alias);
|
|
911
|
-
}
|
|
912
|
-
if (node.type === "catch") {
|
|
913
|
-
if (catchSubjects.has(node.subject)) {
|
|
914
|
-
throw new NodesError("only one catch node per service allowed", {
|
|
915
|
-
id: node.subject
|
|
916
|
-
});
|
|
917
|
-
}
|
|
918
|
-
catchSubjects.set(node.subject, node);
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
if (!getNode("__entry__")) {
|
|
922
|
-
throw new NodesError("missing entry node");
|
|
923
|
-
}
|
|
924
|
-
if (getInputs("__exit__").length === 0) {
|
|
925
|
-
throw new NodesError("no path leads to exit");
|
|
926
|
-
}
|
|
927
|
-
for (const catchNode of nodes.filter((node) => node.type === "catch")) {
|
|
928
|
-
if (!getNode(catchNode.subject)) {
|
|
929
|
-
throw new NodesError("catch node has invalid subject", {
|
|
930
|
-
id: catchNode.subject
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
for (const node of nodes) {
|
|
935
|
-
if (node.type === "or") {
|
|
936
|
-
const inputs = getInputs(node);
|
|
937
|
-
if (!inputs || inputs.length < 2) {
|
|
938
|
-
throw new NodesError("or nodes need at least 2 inputs");
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
for (const targetNodeId of getNodeOutputs(node)) {
|
|
942
|
-
if (targetNodeId !== "__exit__" && !getNode(targetNodeId)) {
|
|
943
|
-
throw new NodesError("missing node", {
|
|
944
|
-
id: targetNodeId
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
const possiblePaths = getPossiblePaths({
|
|
950
|
-
getInputs,
|
|
951
|
-
getNode,
|
|
952
|
-
onMissingInputs: (_node, path) => {
|
|
953
|
-
throw new NodesError("no path from entry to node", {
|
|
954
|
-
path: path.map(identify)
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
if (possiblePaths.every((possiblePath) => !possiblePath.includes("__entry__"))) {
|
|
959
|
-
throw new NodesError("no path from entry to exit");
|
|
960
|
-
}
|
|
961
|
-
for (const possiblePath of possiblePaths) {
|
|
962
|
-
for (const pathSegment of possiblePath) {
|
|
963
|
-
const node = pathSegment === "__exit__" ? null : getNode(pathSegment);
|
|
964
|
-
if (node?.type === "catch" && possiblePath.includes(node.subject)) {
|
|
965
|
-
throw new NodesError("Unresolvable, inputs needs both catch and subject", {
|
|
966
|
-
path: possiblePath.map(identify)
|
|
967
|
-
});
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return nodes;
|
|
972
|
-
});
|
|
973
396
|
|
|
974
|
-
//
|
|
975
|
-
|
|
976
|
-
type: z7.literal("ABORT"),
|
|
977
|
-
reason: z7.string().optional()
|
|
978
|
-
});
|
|
979
|
-
var nodeOptionsSchema = z7.object({
|
|
980
|
-
maxExecutions: z7.number().int().min(0).optional().default(10),
|
|
981
|
-
compliance: z7.enum(["mcp-tool"]).nullable().default(null),
|
|
982
|
-
exitEarly: z7.boolean().optional(),
|
|
983
|
-
uploadUrl: z7.string().optional(),
|
|
984
|
-
streamUrl: z7.string().optional()
|
|
985
|
-
});
|
|
986
|
-
var createNodesSchema = z7.object({
|
|
987
|
-
type: z7.literal("CREATE_NODES"),
|
|
988
|
-
nodes: nodesSchema,
|
|
989
|
-
input: z7.any(),
|
|
990
|
-
meta: z7.any(),
|
|
991
|
-
options: nodeOptionsSchema
|
|
992
|
-
});
|
|
993
|
-
var commandSchema = z7.union([abortSchema, createNodesSchema]);
|
|
397
|
+
// src/index.ts
|
|
398
|
+
import { z as z5 } from "zod/v4";
|
|
994
399
|
|
|
995
400
|
// src/createAmqpConnection.ts
|
|
996
401
|
import {
|
|
997
402
|
connect
|
|
998
403
|
} from "amqp-connection-manager";
|
|
999
|
-
import { z as
|
|
404
|
+
import { z as z4 } from "zod/v4";
|
|
1000
405
|
|
|
1001
406
|
// src/helpers.ts
|
|
1002
407
|
class RetryError extends Error {
|
|
@@ -1007,6 +412,9 @@ class RetryError extends Error {
|
|
|
1007
412
|
}
|
|
1008
413
|
}
|
|
1009
414
|
|
|
415
|
+
class SkipError extends Error {
|
|
416
|
+
}
|
|
417
|
+
|
|
1010
418
|
class AbortError extends Error {
|
|
1011
419
|
}
|
|
1012
420
|
var OUTPUT_VALUE = Symbol("output_value");
|
|
@@ -1026,28 +434,10 @@ async function unwrapResult(result, options, onDone) {
|
|
|
1026
434
|
};
|
|
1027
435
|
}
|
|
1028
436
|
function createContextHelper(options) {
|
|
1029
|
-
const nodes = new Map(options.nodes.map((node) => [
|
|
1030
|
-
node.id,
|
|
1031
|
-
Object.assign(node, {
|
|
1032
|
-
executionDate: node.id in options.context.dates ? new Date(options.context.dates[node.id]) : null,
|
|
1033
|
-
data: options.context.data[node.id] ?? null,
|
|
1034
|
-
error: options.context.errors[node.id] ?? null
|
|
1035
|
-
})
|
|
1036
|
-
]));
|
|
1037
437
|
return {
|
|
1038
438
|
taskId: options.taskId,
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
},
|
|
1042
|
-
getMeta() {
|
|
1043
|
-
return options.context.meta;
|
|
1044
|
-
},
|
|
1045
|
-
getData() {
|
|
1046
|
-
return Array.from(nodes.values()).filter((result) => result.executionDate && isRecord(result.data)).toSorted((a, b) => a.executionDate.getTime() - b.executionDate.getTime()).reduce((acc, result) => ({
|
|
1047
|
-
...acc,
|
|
1048
|
-
...result.data
|
|
1049
|
-
}), isRecord(options.context.input) ? { ...options.context.input } : {});
|
|
1050
|
-
},
|
|
439
|
+
input: resolveRequenceTypes(options.input),
|
|
440
|
+
configuration: resolveRequenceTypes(options.configuration),
|
|
1051
441
|
toOutput(name, value) {
|
|
1052
442
|
return {
|
|
1053
443
|
[OUTPUT_VALUE]: name,
|
|
@@ -1055,20 +445,6 @@ function createContextHelper(options) {
|
|
|
1055
445
|
};
|
|
1056
446
|
},
|
|
1057
447
|
defer: options.onDefer,
|
|
1058
|
-
getConfiguration() {
|
|
1059
|
-
const result = nodes.get(options.serviceId);
|
|
1060
|
-
if (result?.type === "service") {
|
|
1061
|
-
return result.configuration ?? null;
|
|
1062
|
-
}
|
|
1063
|
-
return null;
|
|
1064
|
-
},
|
|
1065
|
-
getNode() {
|
|
1066
|
-
return nodes.get(options.serviceId);
|
|
1067
|
-
},
|
|
1068
|
-
getNodes() {
|
|
1069
|
-
return Array.from(nodes.values());
|
|
1070
|
-
},
|
|
1071
|
-
state: createObjectProxy(options.state, options.onStateChange),
|
|
1072
448
|
debug: {
|
|
1073
449
|
log(...data) {
|
|
1074
450
|
options.onLog("log", data);
|
|
@@ -1088,6 +464,9 @@ function createContextHelper(options) {
|
|
|
1088
464
|
},
|
|
1089
465
|
abort(reason) {
|
|
1090
466
|
throw new AbortError(reason);
|
|
467
|
+
},
|
|
468
|
+
skip() {
|
|
469
|
+
throw new SkipError;
|
|
1091
470
|
}
|
|
1092
471
|
};
|
|
1093
472
|
}
|
|
@@ -1107,34 +486,31 @@ function mapInput(data) {
|
|
|
1107
486
|
}
|
|
1108
487
|
|
|
1109
488
|
// src/createAmqpConnection.ts
|
|
1110
|
-
var messageKeySchema =
|
|
489
|
+
var messageKeySchema = z4.string().transform((str) => deobfuscate(str)).pipe(z4.tuple([z4.uuid(), z4.uuid()]).rest(z4.string())).transform((arr) => ({
|
|
1111
490
|
taskId: arr[0],
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
streamUrl: arr[4] || undefined
|
|
491
|
+
messageId: arr[1],
|
|
492
|
+
uploadUrl: arr[2] || undefined,
|
|
493
|
+
streamUrl: arr[3] || undefined
|
|
1116
494
|
}));
|
|
1117
|
-
var headerSchema =
|
|
1118
|
-
properties:
|
|
1119
|
-
correlationId:
|
|
1120
|
-
headers:
|
|
1121
|
-
version:
|
|
1122
|
-
taskId:
|
|
1123
|
-
serviceId: z8.string().uuid()
|
|
495
|
+
var headerSchema = z4.object({
|
|
496
|
+
properties: z4.object({
|
|
497
|
+
correlationId: z4.uuid(),
|
|
498
|
+
headers: z4.object({
|
|
499
|
+
version: z4.string(),
|
|
500
|
+
taskId: z4.uuid()
|
|
1124
501
|
})
|
|
1125
502
|
})
|
|
1126
503
|
}).transform((msg) => ({
|
|
1127
504
|
version: msg.properties.headers.version,
|
|
1128
505
|
messageId: msg.properties.correlationId,
|
|
1129
|
-
taskId: msg.properties.headers.taskId
|
|
1130
|
-
serviceId: msg.properties.headers.serviceId
|
|
506
|
+
taskId: msg.properties.headers.taskId
|
|
1131
507
|
}));
|
|
1132
|
-
var payloadSchema =
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
508
|
+
var payloadSchema = z4.object({ content: z4.instanceof(Buffer) }).transform((msg) => JSON.parse(msg.content.toString())).pipe(z4.object({
|
|
509
|
+
input: z4.unknown(),
|
|
510
|
+
configuration: z4.unknown(),
|
|
511
|
+
options: z4.object({
|
|
512
|
+
uploadUrl: z4.url().optional(),
|
|
513
|
+
streamUrl: z4.url().optional()
|
|
1138
514
|
})
|
|
1139
515
|
}));
|
|
1140
516
|
function isMessageHandlerGenerator(handler) {
|
|
@@ -1196,50 +572,30 @@ function createConnection({
|
|
|
1196
572
|
});
|
|
1197
573
|
};
|
|
1198
574
|
channel.consume(queue, async (message) => {
|
|
1199
|
-
if (message.properties.headers?.abort || message.properties.headers?.exception) {
|
|
1200
|
-
channel.nack(message, false, false);
|
|
1201
|
-
return;
|
|
1202
|
-
}
|
|
1203
575
|
const donePromises = [];
|
|
1204
576
|
let removeActiveMessage = () => {};
|
|
577
|
+
let acked = false;
|
|
578
|
+
const ack = () => {
|
|
579
|
+
if (!acked) {
|
|
580
|
+
acked = true;
|
|
581
|
+
channel.ack(message);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
1205
584
|
try {
|
|
1206
585
|
let deferred = false;
|
|
1207
586
|
let deferredReason = null;
|
|
1208
|
-
const { messageId,
|
|
587
|
+
const { messageId, taskId } = headerSchema.parse(message);
|
|
1209
588
|
activeMessages.add(messageId);
|
|
1210
589
|
removeActiveMessage = () => activeMessages.delete(messageId);
|
|
1211
590
|
const payload = payloadSchema.parse(message);
|
|
1212
|
-
let acked = false;
|
|
1213
|
-
const ack = () => {
|
|
1214
|
-
if (!acked) {
|
|
1215
|
-
acked = true;
|
|
1216
|
-
channel.ack(message);
|
|
1217
|
-
}
|
|
1218
|
-
};
|
|
1219
|
-
let immediateUpdateState;
|
|
1220
591
|
const extendedContext = createContextHelper({
|
|
1221
|
-
serviceId,
|
|
1222
|
-
context: mapInput(payload.context),
|
|
1223
|
-
nodes: mapInput(payload.meta.nodes),
|
|
1224
592
|
taskId,
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
clearImmediate(immediateUpdateState);
|
|
1228
|
-
immediateUpdateState = setImmediate(() => {
|
|
1229
|
-
publish({
|
|
1230
|
-
messageId,
|
|
1231
|
-
taskId,
|
|
1232
|
-
serviceId,
|
|
1233
|
-
data: clone(newState),
|
|
1234
|
-
state: true
|
|
1235
|
-
});
|
|
1236
|
-
});
|
|
1237
|
-
},
|
|
593
|
+
input: mapInput(payload.input),
|
|
594
|
+
configuration: mapInput(payload.configuration),
|
|
1238
595
|
onLog(debugMethod, data) {
|
|
1239
596
|
publish({
|
|
1240
597
|
messageId,
|
|
1241
598
|
taskId,
|
|
1242
|
-
serviceId,
|
|
1243
599
|
data,
|
|
1244
600
|
debugMethod,
|
|
1245
601
|
debug: true
|
|
@@ -1249,7 +605,7 @@ function createConnection({
|
|
|
1249
605
|
deferred = true;
|
|
1250
606
|
deferredReason = reason || null;
|
|
1251
607
|
ack();
|
|
1252
|
-
return obfuscate(taskId,
|
|
608
|
+
return obfuscate(taskId, messageId, payload.options.uploadUrl ?? "", payload.options.streamUrl ?? "");
|
|
1253
609
|
}
|
|
1254
610
|
});
|
|
1255
611
|
if (isMessageHandlerGenerator(messageHandler)) {
|
|
@@ -1263,12 +619,11 @@ function createConnection({
|
|
|
1263
619
|
}
|
|
1264
620
|
const donePromise = createRemotePromise();
|
|
1265
621
|
donePromises.push(donePromise);
|
|
1266
|
-
const { value, outputName } = await unwrapResult(result, payload.
|
|
622
|
+
const { value, outputName } = await unwrapResult(result, payload.options, donePromise.resolve);
|
|
1267
623
|
if (!done || typeof value !== "undefined") {
|
|
1268
624
|
publish({
|
|
1269
625
|
messageId,
|
|
1270
626
|
taskId,
|
|
1271
|
-
serviceId,
|
|
1272
627
|
data: value,
|
|
1273
628
|
outputName
|
|
1274
629
|
});
|
|
@@ -1282,7 +637,7 @@ function createConnection({
|
|
|
1282
637
|
ack();
|
|
1283
638
|
const donePromise = createRemotePromise();
|
|
1284
639
|
donePromises.push(donePromise);
|
|
1285
|
-
const { value, outputName } = await unwrapResult(result, payload.
|
|
640
|
+
const { value, outputName } = await unwrapResult(result, payload.options, donePromise.resolve);
|
|
1286
641
|
if (deferred && value) {
|
|
1287
642
|
console.warn("returning a value in a deferred message resets the deferred status");
|
|
1288
643
|
deferred = false;
|
|
@@ -1291,7 +646,6 @@ function createConnection({
|
|
|
1291
646
|
publish({
|
|
1292
647
|
messageId,
|
|
1293
648
|
taskId,
|
|
1294
|
-
serviceId,
|
|
1295
649
|
data: value,
|
|
1296
650
|
outputName
|
|
1297
651
|
});
|
|
@@ -1304,34 +658,49 @@ function createConnection({
|
|
|
1304
658
|
publish({
|
|
1305
659
|
messageId,
|
|
1306
660
|
taskId,
|
|
1307
|
-
serviceId,
|
|
1308
661
|
data: deferredReason,
|
|
1309
662
|
deferred,
|
|
1310
663
|
done: !deferred
|
|
1311
664
|
});
|
|
1312
665
|
});
|
|
1313
666
|
} catch (error) {
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
|
|
667
|
+
const assertNack = (message2) => {
|
|
668
|
+
if (acked) {
|
|
669
|
+
console.error(message2);
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
return true;
|
|
673
|
+
};
|
|
674
|
+
if (error instanceof SkipError) {
|
|
675
|
+
if (assertNack("data already send, cannot skip")) {
|
|
676
|
+
channel.nack(message);
|
|
677
|
+
}
|
|
1321
678
|
return;
|
|
1322
679
|
}
|
|
680
|
+
if (error instanceof RetryError) {
|
|
681
|
+
if (assertNack("data already send, cannot retry")) {
|
|
682
|
+
const properties = {
|
|
683
|
+
...message.properties,
|
|
684
|
+
expiration: error.delay || 1000
|
|
685
|
+
};
|
|
686
|
+
channel.publish(`${exchange}-retry`, "retry", message.content, properties);
|
|
687
|
+
ack();
|
|
688
|
+
}
|
|
689
|
+
}
|
|
1323
690
|
if (error instanceof AbortError && error.message.length > 0) {
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
691
|
+
if (assertNack("data already send, cannot abort")) {
|
|
692
|
+
channel.publish(`${exchange}-retry`, "operator", error.message, {
|
|
693
|
+
...message.properties,
|
|
694
|
+
expiration: 0,
|
|
695
|
+
priority: 0,
|
|
696
|
+
contentType: "text/plain",
|
|
697
|
+
headers: {
|
|
698
|
+
...message.properties.headers,
|
|
699
|
+
abort: true
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
ack();
|
|
703
|
+
}
|
|
1335
704
|
return;
|
|
1336
705
|
}
|
|
1337
706
|
if (error instanceof Error) {
|
|
@@ -1339,20 +708,24 @@ function createConnection({
|
|
|
1339
708
|
console.error(`Encountered an error inside service handler:`);
|
|
1340
709
|
console.error(error);
|
|
1341
710
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
711
|
+
if (!acked) {
|
|
712
|
+
channel.publish(`${exchange}-retry`, "operator", message.content, {
|
|
713
|
+
...message.properties,
|
|
714
|
+
expiration: 0,
|
|
715
|
+
priority: 0,
|
|
716
|
+
headers: {
|
|
717
|
+
...message.properties.headers,
|
|
718
|
+
exception: true,
|
|
719
|
+
"error-message": error.message || "error in service handler"
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
channel.ack(message);
|
|
723
|
+
}
|
|
1353
724
|
return;
|
|
1354
725
|
}
|
|
1355
|
-
|
|
726
|
+
if (!acked) {
|
|
727
|
+
channel.nack(message, false, false);
|
|
728
|
+
}
|
|
1356
729
|
} finally {
|
|
1357
730
|
removeActiveMessage();
|
|
1358
731
|
}
|
|
@@ -1364,7 +737,7 @@ function createConnection({
|
|
|
1364
737
|
},
|
|
1365
738
|
open: () => connectedPromise.then(() => api),
|
|
1366
739
|
async act(messageKey, actor) {
|
|
1367
|
-
const { taskId,
|
|
740
|
+
const { taskId, messageId, ...options } = messageKeySchema.parse(messageKey);
|
|
1368
741
|
if (activeMessages.has(messageId)) {
|
|
1369
742
|
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1370
743
|
}
|
|
@@ -1376,7 +749,6 @@ function createConnection({
|
|
|
1376
749
|
publish({
|
|
1377
750
|
messageId,
|
|
1378
751
|
taskId,
|
|
1379
|
-
serviceId,
|
|
1380
752
|
data: await mapOutput({
|
|
1381
753
|
value: data,
|
|
1382
754
|
options,
|
|
@@ -1391,7 +763,6 @@ function createConnection({
|
|
|
1391
763
|
publish({
|
|
1392
764
|
messageId,
|
|
1393
765
|
taskId,
|
|
1394
|
-
serviceId,
|
|
1395
766
|
data: await mapOutput({
|
|
1396
767
|
value: data,
|
|
1397
768
|
options,
|
|
@@ -1400,14 +771,13 @@ function createConnection({
|
|
|
1400
771
|
});
|
|
1401
772
|
},
|
|
1402
773
|
abort(error) {
|
|
1403
|
-
channel.publish(`${exchange}-retry`, "
|
|
774
|
+
channel.publish(`${exchange}-retry`, "operator", error instanceof Error ? error.message : error, {
|
|
1404
775
|
correlationId: messageId,
|
|
1405
776
|
expiration: 0,
|
|
1406
777
|
priority: 0,
|
|
1407
778
|
contentType: "text/plain",
|
|
1408
779
|
headers: {
|
|
1409
780
|
taskId,
|
|
1410
|
-
serviceId,
|
|
1411
781
|
abort: true
|
|
1412
782
|
}
|
|
1413
783
|
});
|
|
@@ -1418,7 +788,6 @@ function createConnection({
|
|
|
1418
788
|
publish({
|
|
1419
789
|
messageId,
|
|
1420
790
|
taskId,
|
|
1421
|
-
serviceId,
|
|
1422
791
|
done: true
|
|
1423
792
|
});
|
|
1424
793
|
});
|
|
@@ -1428,16 +797,16 @@ function createConnection({
|
|
|
1428
797
|
}
|
|
1429
798
|
|
|
1430
799
|
// src/index.ts
|
|
1431
|
-
var connectionOptionsSchema =
|
|
1432
|
-
url:
|
|
1433
|
-
|
|
1434
|
-
|
|
800
|
+
var connectionOptionsSchema = z5.object({
|
|
801
|
+
url: z5.union([
|
|
802
|
+
z5.string().regex(/^amqps?:\/\/(.+):(.+)@(.+)$/).transform((str) => new URL(str)),
|
|
803
|
+
z5.instanceof(URL).refine((url) => url.protocol.match(/^amqps?:/), "Wrong protocol")
|
|
1435
804
|
]),
|
|
1436
|
-
version:
|
|
1437
|
-
silent:
|
|
1438
|
-
prefetch:
|
|
1439
|
-
connectionTimeout:
|
|
1440
|
-
connectionOptions:
|
|
805
|
+
version: z5.string(),
|
|
806
|
+
silent: z5.boolean().optional(),
|
|
807
|
+
prefetch: z5.number().int().optional(),
|
|
808
|
+
connectionTimeout: z5.number().positive().default(3000),
|
|
809
|
+
connectionOptions: z5.any()
|
|
1441
810
|
});
|
|
1442
811
|
function createService(optionsOrVersion, optionalMessageHandler) {
|
|
1443
812
|
let options;
|
|
@@ -1475,5 +844,5 @@ export {
|
|
|
1475
844
|
RequenceFile
|
|
1476
845
|
};
|
|
1477
846
|
|
|
1478
|
-
//# debugId=
|
|
847
|
+
//# debugId=C95DB017F5DE792D64756E2164756E21
|
|
1479
848
|
//# sourceMappingURL=index.js.map
|