@requence/service 1.0.0-alpha.17 → 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 +12 -0
- package/build/index.js +192 -826
- 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 +2 -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 +198 -3044
- 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 +4 -4
- 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
|
-
}
|
|
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
393
|
}
|
|
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
396
|
|
|
825
|
-
//
|
|
826
|
-
|
|
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
|
-
|
|
974
|
-
// ../helpers/src/protocol/command.ts
|
|
975
|
-
var abortSchema = z7.object({
|
|
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,15 +412,15 @@ 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");
|
|
1013
421
|
function isOutputValue(value) {
|
|
1014
422
|
return value !== null && typeof value === "object" && OUTPUT_VALUE in value;
|
|
1015
423
|
}
|
|
1016
|
-
function isRecord2(data) {
|
|
1017
|
-
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
1018
|
-
}
|
|
1019
424
|
async function unwrapResult(result, options, onDone) {
|
|
1020
425
|
if (isOutputValue(result)) {
|
|
1021
426
|
return {
|
|
@@ -1029,28 +434,10 @@ async function unwrapResult(result, options, onDone) {
|
|
|
1029
434
|
};
|
|
1030
435
|
}
|
|
1031
436
|
function createContextHelper(options) {
|
|
1032
|
-
const nodes = new Map(options.nodes.map((node) => [
|
|
1033
|
-
node.id,
|
|
1034
|
-
Object.assign(node, {
|
|
1035
|
-
executionDate: node.id in options.context.dates ? new Date(options.context.dates[node.id]) : null,
|
|
1036
|
-
data: options.context.data[node.id] ?? null,
|
|
1037
|
-
error: options.context.errors[node.id] ?? null
|
|
1038
|
-
})
|
|
1039
|
-
]));
|
|
1040
437
|
return {
|
|
1041
438
|
taskId: options.taskId,
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
},
|
|
1045
|
-
getMeta() {
|
|
1046
|
-
return options.context.meta;
|
|
1047
|
-
},
|
|
1048
|
-
getData() {
|
|
1049
|
-
return Array.from(nodes.values()).filter((result) => result.executionDate && isRecord2(result.data)).toSorted((a, b) => a.executionDate.getTime() - b.executionDate.getTime()).reduce((acc, result) => ({
|
|
1050
|
-
...acc,
|
|
1051
|
-
...result.data
|
|
1052
|
-
}), isRecord2(options.context.input) ? { ...options.context.input } : {});
|
|
1053
|
-
},
|
|
439
|
+
input: resolveRequenceTypes(options.input),
|
|
440
|
+
configuration: resolveRequenceTypes(options.configuration),
|
|
1054
441
|
toOutput(name, value) {
|
|
1055
442
|
return {
|
|
1056
443
|
[OUTPUT_VALUE]: name,
|
|
@@ -1058,20 +445,6 @@ function createContextHelper(options) {
|
|
|
1058
445
|
};
|
|
1059
446
|
},
|
|
1060
447
|
defer: options.onDefer,
|
|
1061
|
-
getConfiguration() {
|
|
1062
|
-
const result = nodes.get(options.serviceId);
|
|
1063
|
-
if (result?.type === "service") {
|
|
1064
|
-
return result.configuration ?? null;
|
|
1065
|
-
}
|
|
1066
|
-
return null;
|
|
1067
|
-
},
|
|
1068
|
-
getNode() {
|
|
1069
|
-
return nodes.get(options.serviceId);
|
|
1070
|
-
},
|
|
1071
|
-
getNodes() {
|
|
1072
|
-
return Array.from(nodes.values());
|
|
1073
|
-
},
|
|
1074
|
-
state: createObjectProxy(options.state, options.onStateChange),
|
|
1075
448
|
debug: {
|
|
1076
449
|
log(...data) {
|
|
1077
450
|
options.onLog("log", data);
|
|
@@ -1091,6 +464,9 @@ function createContextHelper(options) {
|
|
|
1091
464
|
},
|
|
1092
465
|
abort(reason) {
|
|
1093
466
|
throw new AbortError(reason);
|
|
467
|
+
},
|
|
468
|
+
skip() {
|
|
469
|
+
throw new SkipError;
|
|
1094
470
|
}
|
|
1095
471
|
};
|
|
1096
472
|
}
|
|
@@ -1110,34 +486,31 @@ function mapInput(data) {
|
|
|
1110
486
|
}
|
|
1111
487
|
|
|
1112
488
|
// src/createAmqpConnection.ts
|
|
1113
|
-
var messageKeySchema =
|
|
489
|
+
var messageKeySchema = z4.string().transform((str) => deobfuscate(str)).pipe(z4.tuple([z4.uuid(), z4.uuid()]).rest(z4.string())).transform((arr) => ({
|
|
1114
490
|
taskId: arr[0],
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
streamUrl: arr[4] || undefined
|
|
491
|
+
messageId: arr[1],
|
|
492
|
+
uploadUrl: arr[2] || undefined,
|
|
493
|
+
streamUrl: arr[3] || undefined
|
|
1119
494
|
}));
|
|
1120
|
-
var headerSchema =
|
|
1121
|
-
properties:
|
|
1122
|
-
correlationId:
|
|
1123
|
-
headers:
|
|
1124
|
-
version:
|
|
1125
|
-
taskId:
|
|
1126
|
-
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()
|
|
1127
501
|
})
|
|
1128
502
|
})
|
|
1129
503
|
}).transform((msg) => ({
|
|
1130
504
|
version: msg.properties.headers.version,
|
|
1131
505
|
messageId: msg.properties.correlationId,
|
|
1132
|
-
taskId: msg.properties.headers.taskId
|
|
1133
|
-
serviceId: msg.properties.headers.serviceId
|
|
506
|
+
taskId: msg.properties.headers.taskId
|
|
1134
507
|
}));
|
|
1135
|
-
var payloadSchema =
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
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()
|
|
1141
514
|
})
|
|
1142
515
|
}));
|
|
1143
516
|
function isMessageHandlerGenerator(handler) {
|
|
@@ -1199,50 +572,30 @@ function createConnection({
|
|
|
1199
572
|
});
|
|
1200
573
|
};
|
|
1201
574
|
channel.consume(queue, async (message) => {
|
|
1202
|
-
if (message.properties.headers?.abort || message.properties.headers?.exception) {
|
|
1203
|
-
channel.nack(message, false, false);
|
|
1204
|
-
return;
|
|
1205
|
-
}
|
|
1206
575
|
const donePromises = [];
|
|
1207
576
|
let removeActiveMessage = () => {};
|
|
577
|
+
let acked = false;
|
|
578
|
+
const ack = () => {
|
|
579
|
+
if (!acked) {
|
|
580
|
+
acked = true;
|
|
581
|
+
channel.ack(message);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
1208
584
|
try {
|
|
1209
585
|
let deferred = false;
|
|
1210
586
|
let deferredReason = null;
|
|
1211
|
-
const { messageId,
|
|
587
|
+
const { messageId, taskId } = headerSchema.parse(message);
|
|
1212
588
|
activeMessages.add(messageId);
|
|
1213
589
|
removeActiveMessage = () => activeMessages.delete(messageId);
|
|
1214
590
|
const payload = payloadSchema.parse(message);
|
|
1215
|
-
let acked = false;
|
|
1216
|
-
const ack = () => {
|
|
1217
|
-
if (!acked) {
|
|
1218
|
-
acked = true;
|
|
1219
|
-
channel.ack(message);
|
|
1220
|
-
}
|
|
1221
|
-
};
|
|
1222
|
-
let immediateUpdateState;
|
|
1223
591
|
const extendedContext = createContextHelper({
|
|
1224
|
-
serviceId,
|
|
1225
|
-
context: mapInput(payload.context),
|
|
1226
|
-
nodes: mapInput(payload.meta.nodes),
|
|
1227
592
|
taskId,
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
clearImmediate(immediateUpdateState);
|
|
1231
|
-
immediateUpdateState = setImmediate(() => {
|
|
1232
|
-
publish({
|
|
1233
|
-
messageId,
|
|
1234
|
-
taskId,
|
|
1235
|
-
serviceId,
|
|
1236
|
-
data: clone(newState),
|
|
1237
|
-
state: true
|
|
1238
|
-
});
|
|
1239
|
-
});
|
|
1240
|
-
},
|
|
593
|
+
input: mapInput(payload.input),
|
|
594
|
+
configuration: mapInput(payload.configuration),
|
|
1241
595
|
onLog(debugMethod, data) {
|
|
1242
596
|
publish({
|
|
1243
597
|
messageId,
|
|
1244
598
|
taskId,
|
|
1245
|
-
serviceId,
|
|
1246
599
|
data,
|
|
1247
600
|
debugMethod,
|
|
1248
601
|
debug: true
|
|
@@ -1252,7 +605,7 @@ function createConnection({
|
|
|
1252
605
|
deferred = true;
|
|
1253
606
|
deferredReason = reason || null;
|
|
1254
607
|
ack();
|
|
1255
|
-
return obfuscate(taskId,
|
|
608
|
+
return obfuscate(taskId, messageId, payload.options.uploadUrl ?? "", payload.options.streamUrl ?? "");
|
|
1256
609
|
}
|
|
1257
610
|
});
|
|
1258
611
|
if (isMessageHandlerGenerator(messageHandler)) {
|
|
@@ -1266,12 +619,11 @@ function createConnection({
|
|
|
1266
619
|
}
|
|
1267
620
|
const donePromise = createRemotePromise();
|
|
1268
621
|
donePromises.push(donePromise);
|
|
1269
|
-
const { value, outputName } = await unwrapResult(result, payload.
|
|
622
|
+
const { value, outputName } = await unwrapResult(result, payload.options, donePromise.resolve);
|
|
1270
623
|
if (!done || typeof value !== "undefined") {
|
|
1271
624
|
publish({
|
|
1272
625
|
messageId,
|
|
1273
626
|
taskId,
|
|
1274
|
-
serviceId,
|
|
1275
627
|
data: value,
|
|
1276
628
|
outputName
|
|
1277
629
|
});
|
|
@@ -1285,7 +637,7 @@ function createConnection({
|
|
|
1285
637
|
ack();
|
|
1286
638
|
const donePromise = createRemotePromise();
|
|
1287
639
|
donePromises.push(donePromise);
|
|
1288
|
-
const { value, outputName } = await unwrapResult(result, payload.
|
|
640
|
+
const { value, outputName } = await unwrapResult(result, payload.options, donePromise.resolve);
|
|
1289
641
|
if (deferred && value) {
|
|
1290
642
|
console.warn("returning a value in a deferred message resets the deferred status");
|
|
1291
643
|
deferred = false;
|
|
@@ -1294,7 +646,6 @@ function createConnection({
|
|
|
1294
646
|
publish({
|
|
1295
647
|
messageId,
|
|
1296
648
|
taskId,
|
|
1297
|
-
serviceId,
|
|
1298
649
|
data: value,
|
|
1299
650
|
outputName
|
|
1300
651
|
});
|
|
@@ -1307,34 +658,49 @@ function createConnection({
|
|
|
1307
658
|
publish({
|
|
1308
659
|
messageId,
|
|
1309
660
|
taskId,
|
|
1310
|
-
serviceId,
|
|
1311
661
|
data: deferredReason,
|
|
1312
662
|
deferred,
|
|
1313
663
|
done: !deferred
|
|
1314
664
|
});
|
|
1315
665
|
});
|
|
1316
666
|
} catch (error) {
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
|
|
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
|
+
}
|
|
1324
678
|
return;
|
|
1325
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
|
+
}
|
|
1326
690
|
if (error instanceof AbortError && error.message.length > 0) {
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
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
|
+
}
|
|
1338
704
|
return;
|
|
1339
705
|
}
|
|
1340
706
|
if (error instanceof Error) {
|
|
@@ -1342,20 +708,24 @@ function createConnection({
|
|
|
1342
708
|
console.error(`Encountered an error inside service handler:`);
|
|
1343
709
|
console.error(error);
|
|
1344
710
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
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
|
+
}
|
|
1356
724
|
return;
|
|
1357
725
|
}
|
|
1358
|
-
|
|
726
|
+
if (!acked) {
|
|
727
|
+
channel.nack(message, false, false);
|
|
728
|
+
}
|
|
1359
729
|
} finally {
|
|
1360
730
|
removeActiveMessage();
|
|
1361
731
|
}
|
|
@@ -1367,7 +737,7 @@ function createConnection({
|
|
|
1367
737
|
},
|
|
1368
738
|
open: () => connectedPromise.then(() => api),
|
|
1369
739
|
async act(messageKey, actor) {
|
|
1370
|
-
const { taskId,
|
|
740
|
+
const { taskId, messageId, ...options } = messageKeySchema.parse(messageKey);
|
|
1371
741
|
if (activeMessages.has(messageId)) {
|
|
1372
742
|
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1373
743
|
}
|
|
@@ -1379,7 +749,6 @@ function createConnection({
|
|
|
1379
749
|
publish({
|
|
1380
750
|
messageId,
|
|
1381
751
|
taskId,
|
|
1382
|
-
serviceId,
|
|
1383
752
|
data: await mapOutput({
|
|
1384
753
|
value: data,
|
|
1385
754
|
options,
|
|
@@ -1394,7 +763,6 @@ function createConnection({
|
|
|
1394
763
|
publish({
|
|
1395
764
|
messageId,
|
|
1396
765
|
taskId,
|
|
1397
|
-
serviceId,
|
|
1398
766
|
data: await mapOutput({
|
|
1399
767
|
value: data,
|
|
1400
768
|
options,
|
|
@@ -1403,14 +771,13 @@ function createConnection({
|
|
|
1403
771
|
});
|
|
1404
772
|
},
|
|
1405
773
|
abort(error) {
|
|
1406
|
-
channel.publish(`${exchange}-retry`, "
|
|
774
|
+
channel.publish(`${exchange}-retry`, "operator", error instanceof Error ? error.message : error, {
|
|
1407
775
|
correlationId: messageId,
|
|
1408
776
|
expiration: 0,
|
|
1409
777
|
priority: 0,
|
|
1410
778
|
contentType: "text/plain",
|
|
1411
779
|
headers: {
|
|
1412
780
|
taskId,
|
|
1413
|
-
serviceId,
|
|
1414
781
|
abort: true
|
|
1415
782
|
}
|
|
1416
783
|
});
|
|
@@ -1421,7 +788,6 @@ function createConnection({
|
|
|
1421
788
|
publish({
|
|
1422
789
|
messageId,
|
|
1423
790
|
taskId,
|
|
1424
|
-
serviceId,
|
|
1425
791
|
done: true
|
|
1426
792
|
});
|
|
1427
793
|
});
|
|
@@ -1431,16 +797,16 @@ function createConnection({
|
|
|
1431
797
|
}
|
|
1432
798
|
|
|
1433
799
|
// src/index.ts
|
|
1434
|
-
var connectionOptionsSchema =
|
|
1435
|
-
url:
|
|
1436
|
-
|
|
1437
|
-
|
|
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")
|
|
1438
804
|
]),
|
|
1439
|
-
version:
|
|
1440
|
-
silent:
|
|
1441
|
-
prefetch:
|
|
1442
|
-
connectionTimeout:
|
|
1443
|
-
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()
|
|
1444
810
|
});
|
|
1445
811
|
function createService(optionsOrVersion, optionalMessageHandler) {
|
|
1446
812
|
let options;
|
|
@@ -1478,5 +844,5 @@ export {
|
|
|
1478
844
|
RequenceFile
|
|
1479
845
|
};
|
|
1480
846
|
|
|
1481
|
-
//# debugId=
|
|
847
|
+
//# debugId=C95DB017F5DE792D64756E2164756E21
|
|
1482
848
|
//# sourceMappingURL=index.js.map
|