@requence/service 1.0.0-alpha.13 → 1.0.0-alpha.14
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/chunk-6w7td62p.js +56 -0
- package/build/chunk-6w7td62p.js.map +10 -0
- package/build/cli.js +1 -1
- package/build/index.js +330 -164
- package/build/index.js.map +12 -7
- package/build/types/helpers/src/files/mapOutput.d.ts +4 -1
- package/build/types/helpers/src/files/mapOutput.d.ts.map +1 -1
- package/build/types/helpers/src/index.d.ts +8 -6
- package/build/types/helpers/src/index.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/update.d.ts +8 -8
- package/build/types/helpers/src/utils/callbackToAsyncIterator.d.ts +3 -0
- package/build/types/helpers/src/utils/callbackToAsyncIterator.d.ts.map +1 -0
- package/build/types/helpers/src/utils/clone.d.ts +3 -0
- package/build/types/helpers/src/utils/clone.d.ts.map +1 -0
- package/build/types/helpers/src/utils/createObjectProxy.d.ts +2 -0
- package/build/types/helpers/src/utils/createObjectProxy.d.ts.map +1 -0
- package/build/types/helpers/src/{createRemotePromise.d.ts → utils/createRemotePromise.d.ts} +1 -1
- package/build/types/helpers/src/utils/createRemotePromise.d.ts.map +1 -0
- package/build/types/helpers/src/utils/isRecord.d.ts +2 -0
- package/build/types/helpers/src/utils/isRecord.d.ts.map +1 -0
- package/build/types/helpers/src/{utils.d.ts → utils/mapData.d.ts} +1 -5
- package/build/types/helpers/src/utils/mapData.d.ts.map +1 -0
- package/build/types/helpers/src/utils/matchSchema.d.ts +4 -0
- package/build/types/helpers/src/utils/matchSchema.d.ts.map +1 -0
- package/build/types/helpers/src/utils/obfuscate.d.ts.map +1 -0
- package/build/types/service/src/createAmqpConnection.d.ts.map +1 -1
- package/build/types/service/src/helpers.d.ts +1 -1
- package/build/types/service/src/helpers.d.ts.map +1 -1
- package/package.json +1 -1
- package/build/chunk-fa95vcc4.js +0 -156
- package/build/chunk-fa95vcc4.js.map +0 -13
- package/build/types/helpers/src/clone.d.ts +0 -3
- package/build/types/helpers/src/clone.d.ts.map +0 -1
- package/build/types/helpers/src/createObjectProxy.d.ts +0 -2
- package/build/types/helpers/src/createObjectProxy.d.ts.map +0 -1
- package/build/types/helpers/src/createRemotePromise.d.ts.map +0 -1
- package/build/types/helpers/src/obfuscate.d.ts.map +0 -1
- package/build/types/helpers/src/utils.d.ts.map +0 -1
- /package/build/types/helpers/src/{obfuscate.d.ts → utils/obfuscate.d.ts} +0 -0
package/build/index.js
CHANGED
|
@@ -1,25 +1,158 @@
|
|
|
1
1
|
import {
|
|
2
|
-
clone,
|
|
3
|
-
createObjectProxy,
|
|
4
2
|
deobfuscate,
|
|
5
|
-
mapData,
|
|
6
3
|
obfuscate
|
|
7
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6w7td62p.js";
|
|
8
5
|
|
|
9
6
|
// src/index.ts
|
|
10
7
|
import { readFileSync } from "node:fs";
|
|
11
|
-
|
|
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
|
+
// ../helpers/src/utils/createRemotePromise.ts
|
|
52
|
+
function createRemotePromise(onAwait) {
|
|
53
|
+
let resolvePromise;
|
|
54
|
+
let rejectPromise;
|
|
55
|
+
const internalPromise = new Promise((resolve, reject) => {
|
|
56
|
+
resolvePromise = resolve;
|
|
57
|
+
rejectPromise = reject;
|
|
58
|
+
});
|
|
59
|
+
let isAwaited = false;
|
|
60
|
+
const wrappedPromise = new Proxy(internalPromise, {
|
|
61
|
+
get(target, property) {
|
|
62
|
+
if (property === "then" || property === "catch" || property === "finally") {
|
|
63
|
+
if (!isAwaited && onAwait) {
|
|
64
|
+
isAwaited = true;
|
|
65
|
+
onAwait(resolvePromise, rejectPromise);
|
|
66
|
+
}
|
|
67
|
+
return target[property].bind(target);
|
|
68
|
+
}
|
|
69
|
+
return target[property];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return Object.assign(wrappedPromise, {
|
|
73
|
+
resolve: resolvePromise,
|
|
74
|
+
reject: rejectPromise,
|
|
75
|
+
promise: wrappedPromise
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ../helpers/src/utils/isRecord.ts
|
|
80
|
+
import { z } from "zod";
|
|
81
|
+
var recordSchema = z.record(z.unknown());
|
|
82
|
+
function isRecord(data) {
|
|
83
|
+
return recordSchema.safeParse(data).success;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ../helpers/src/utils/mapData.ts
|
|
87
|
+
function resolve(value, onResolve) {
|
|
88
|
+
if (value instanceof Promise) {
|
|
89
|
+
return Promise.resolve().then(() => value).then(onResolve);
|
|
90
|
+
}
|
|
91
|
+
return onResolve(value);
|
|
92
|
+
}
|
|
93
|
+
function notUndefined(value, fallback) {
|
|
94
|
+
return resolve(value, (resolvedValue) => typeof resolvedValue === "undefined" ? fallback : resolvedValue);
|
|
95
|
+
}
|
|
96
|
+
function mapData(data, visitors) {
|
|
97
|
+
const traverseData = (data2, path) => {
|
|
98
|
+
if (Array.isArray(data2)) {
|
|
99
|
+
return resolve(visitors.Array?.(data2, path), (resolvedData) => {
|
|
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
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (data2 === null) {
|
|
111
|
+
return notUndefined(visitors.Null?.(data2, path), data2);
|
|
112
|
+
}
|
|
113
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data2)) {
|
|
114
|
+
return notUndefined(visitors.Buffer?.(data2, path), data2);
|
|
115
|
+
}
|
|
116
|
+
if (typeof data2 === "string") {
|
|
117
|
+
return notUndefined(visitors.String?.(data2, path), data2);
|
|
118
|
+
}
|
|
119
|
+
if (typeof data2 === "number") {
|
|
120
|
+
return notUndefined(visitors.Number?.(data2, path), data2);
|
|
121
|
+
}
|
|
122
|
+
if (isRecord(data2)) {
|
|
123
|
+
return resolve(visitors.Object?.(data2, path), (resolvedData) => {
|
|
124
|
+
if (resolvedData) {
|
|
125
|
+
return resolvedData;
|
|
126
|
+
}
|
|
127
|
+
const entries = Object.entries(data2).map(([key, value]) => [
|
|
128
|
+
key,
|
|
129
|
+
traverseData(value, [...path, key])
|
|
130
|
+
]);
|
|
131
|
+
if (entries.some(([, value]) => value instanceof Promise)) {
|
|
132
|
+
return Promise.all(entries.map(([key, value]) => Promise.resolve().then(() => value).then((resolvedValue) => [key, resolvedValue]))).then((entries2) => Object.fromEntries(entries2));
|
|
133
|
+
}
|
|
134
|
+
return Object.fromEntries(entries);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return data2;
|
|
138
|
+
};
|
|
139
|
+
return traverseData(data, []);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/index.ts
|
|
143
|
+
import { z as z9 } from "zod";
|
|
12
144
|
|
|
13
145
|
// ../helpers/src/context/context.ts
|
|
14
|
-
import { z as
|
|
146
|
+
import { z as z3 } from "zod";
|
|
15
147
|
|
|
16
148
|
// ../helpers/src/files/index.ts
|
|
17
|
-
import { z } from "zod";
|
|
149
|
+
import { z as z2 } from "zod";
|
|
18
150
|
|
|
19
151
|
// ../helpers/src/files/mapOutput.ts
|
|
20
|
-
async function upload(uploadUrl, body, contentType) {
|
|
152
|
+
async function upload(uploadUrl, body, signal, contentType) {
|
|
21
153
|
const uploadResponse = await fetch(uploadUrl, {
|
|
22
154
|
method: "POST",
|
|
155
|
+
signal,
|
|
23
156
|
headers: contentType ? {
|
|
24
157
|
"Content-Type": contentType
|
|
25
158
|
} : {},
|
|
@@ -31,7 +164,7 @@ async function upload(uploadUrl, body, contentType) {
|
|
|
31
164
|
}
|
|
32
165
|
return toFileObject(data);
|
|
33
166
|
}
|
|
34
|
-
async function stream(streamUrl, stream2, contentType) {
|
|
167
|
+
async function stream(streamUrl, stream2, signal, contentType) {
|
|
35
168
|
const [testStream, dataStream] = stream2.tee();
|
|
36
169
|
const reader = testStream.getReader();
|
|
37
170
|
const dataPromise = reader.read().then(({ done: done2 }) => {
|
|
@@ -42,6 +175,7 @@ async function stream(streamUrl, stream2, contentType) {
|
|
|
42
175
|
});
|
|
43
176
|
const streamResponse = await fetch(streamUrl, {
|
|
44
177
|
method: "POST",
|
|
178
|
+
signal,
|
|
45
179
|
headers: contentType ? { "Content-Type": contentType } : {}
|
|
46
180
|
});
|
|
47
181
|
const data = await streamResponse.json();
|
|
@@ -52,36 +186,37 @@ async function stream(streamUrl, stream2, contentType) {
|
|
|
52
186
|
await dataPromise;
|
|
53
187
|
const done = fetch(url, {
|
|
54
188
|
method: "POST",
|
|
189
|
+
signal,
|
|
55
190
|
duplex: "half",
|
|
56
191
|
body: dataStream
|
|
57
192
|
});
|
|
58
193
|
return [toStreamObject({ mime, url }), done];
|
|
59
194
|
}
|
|
60
|
-
async function mapOutput(
|
|
195
|
+
async function mapOutput(params) {
|
|
61
196
|
const streamPromises = [];
|
|
62
|
-
const mapped = await mapData(value, {
|
|
197
|
+
const mapped = await mapData(params.value, {
|
|
63
198
|
async Object(obj) {
|
|
64
199
|
if (obj instanceof Blob || obj instanceof RequenceFile) {
|
|
65
200
|
if (obj instanceof RequenceFile && obj.fileObject) {
|
|
66
201
|
return obj.fileObject;
|
|
67
202
|
}
|
|
68
|
-
if (
|
|
203
|
+
if (params.options.uploadUrl) {
|
|
69
204
|
try {
|
|
70
205
|
if (obj instanceof Blob) {
|
|
71
|
-
return await upload(
|
|
206
|
+
return await upload(params.options.uploadUrl, obj, params.signal, obj.type);
|
|
72
207
|
}
|
|
73
208
|
if (obj instanceof RequenceFile) {
|
|
74
|
-
return await upload(
|
|
209
|
+
return await upload(params.options.uploadUrl, await obj.blob(), params.signal, obj.mimeType);
|
|
75
210
|
}
|
|
76
211
|
} catch (error) {
|
|
77
212
|
if (!(error instanceof Error)) {
|
|
78
213
|
throw error;
|
|
79
214
|
}
|
|
80
|
-
|
|
215
|
+
params.onFail?.(error);
|
|
81
216
|
return null;
|
|
82
217
|
}
|
|
83
218
|
} else {
|
|
84
|
-
|
|
219
|
+
params.onSkip?.();
|
|
85
220
|
return null;
|
|
86
221
|
}
|
|
87
222
|
}
|
|
@@ -89,15 +224,15 @@ async function mapOutput(value, nodeOptions, eventHandlers) {
|
|
|
89
224
|
if (obj instanceof RequenceStream && obj.streamObject) {
|
|
90
225
|
return obj.streamObject;
|
|
91
226
|
}
|
|
92
|
-
if (
|
|
227
|
+
if (params.options.streamUrl) {
|
|
93
228
|
try {
|
|
94
229
|
if (obj instanceof Response && obj.body) {
|
|
95
|
-
const [streamObject, streamPromise] = await stream(
|
|
230
|
+
const [streamObject, streamPromise] = await stream(params.options.streamUrl, obj.body, params.signal, obj.headers.get("Content-Type"));
|
|
96
231
|
streamPromises.push(streamPromise);
|
|
97
232
|
return streamObject;
|
|
98
233
|
}
|
|
99
234
|
if (obj instanceof RequenceStream) {
|
|
100
|
-
const [streamObject, streamPromise] = await stream(
|
|
235
|
+
const [streamObject, streamPromise] = await stream(params.options.streamUrl, obj.stream(), params.signal, obj.mimeType);
|
|
101
236
|
streamPromises.push(streamPromise);
|
|
102
237
|
return streamObject;
|
|
103
238
|
}
|
|
@@ -105,17 +240,17 @@ async function mapOutput(value, nodeOptions, eventHandlers) {
|
|
|
105
240
|
if (!(error instanceof Error)) {
|
|
106
241
|
throw error;
|
|
107
242
|
}
|
|
108
|
-
|
|
243
|
+
params.onFail?.(error);
|
|
109
244
|
return null;
|
|
110
245
|
}
|
|
111
246
|
} else {
|
|
112
|
-
|
|
247
|
+
params.onSkip?.();
|
|
113
248
|
return null;
|
|
114
249
|
}
|
|
115
250
|
}
|
|
116
251
|
}
|
|
117
252
|
});
|
|
118
|
-
Promise.allSettled(streamPromises).then(() =>
|
|
253
|
+
Promise.allSettled(streamPromises).then(() => params.onDone?.());
|
|
119
254
|
return mapped;
|
|
120
255
|
}
|
|
121
256
|
// ../helpers/src/files/isValidMimeType.ts
|
|
@@ -261,11 +396,11 @@ class RequenceStream {
|
|
|
261
396
|
}
|
|
262
397
|
|
|
263
398
|
// ../helpers/src/files/index.ts
|
|
264
|
-
var fileObjectSchema =
|
|
265
|
-
size:
|
|
266
|
-
mime:
|
|
267
|
-
url:
|
|
268
|
-
__REQUENCE_type:
|
|
399
|
+
var fileObjectSchema = z2.object({
|
|
400
|
+
size: z2.number().int().positive(),
|
|
401
|
+
mime: z2.string(),
|
|
402
|
+
url: z2.string().url(),
|
|
403
|
+
__REQUENCE_type: z2.literal("RequenceFile")
|
|
269
404
|
});
|
|
270
405
|
function toFileObject(fileInfo) {
|
|
271
406
|
return {
|
|
@@ -276,10 +411,10 @@ function toFileObject(fileInfo) {
|
|
|
276
411
|
function isFileObject(data) {
|
|
277
412
|
return fileObjectSchema.safeParse(data).success;
|
|
278
413
|
}
|
|
279
|
-
var streamObjectSchema =
|
|
280
|
-
mime:
|
|
281
|
-
url:
|
|
282
|
-
__REQUENCE_type:
|
|
414
|
+
var streamObjectSchema = z2.object({
|
|
415
|
+
mime: z2.string(),
|
|
416
|
+
url: z2.string().url(),
|
|
417
|
+
__REQUENCE_type: z2.literal("RequenceStream")
|
|
283
418
|
});
|
|
284
419
|
function toStreamObject(streamInfo) {
|
|
285
420
|
return {
|
|
@@ -292,21 +427,21 @@ function isStreamObject(data) {
|
|
|
292
427
|
}
|
|
293
428
|
|
|
294
429
|
// ../helpers/src/context/context.ts
|
|
295
|
-
var contextSchema =
|
|
296
|
-
input:
|
|
297
|
-
meta:
|
|
298
|
-
tenant:
|
|
299
|
-
data:
|
|
300
|
-
errors:
|
|
301
|
-
dates:
|
|
430
|
+
var contextSchema = z3.object({
|
|
431
|
+
input: z3.any(),
|
|
432
|
+
meta: z3.any(),
|
|
433
|
+
tenant: z3.object({ name: z3.string() }),
|
|
434
|
+
data: z3.record(z3.string(), z3.any()),
|
|
435
|
+
errors: z3.record(z3.string(), z3.string()),
|
|
436
|
+
dates: z3.record(z3.string(), z3.string().datetime())
|
|
302
437
|
});
|
|
303
438
|
var internalKey = Symbol.for("internal");
|
|
304
439
|
|
|
305
440
|
// ../helpers/src/protocol/command.ts
|
|
306
|
-
import { z as
|
|
441
|
+
import { z as z7 } from "zod";
|
|
307
442
|
|
|
308
443
|
// ../helpers/src/protocol/nodes.ts
|
|
309
|
-
import { ZodError, z as
|
|
444
|
+
import { ZodError, z as z6 } from "zod";
|
|
310
445
|
|
|
311
446
|
// ../helpers/src/protocol/getNodeOutputs.ts
|
|
312
447
|
function getNodeOutputs(node, outputName) {
|
|
@@ -442,10 +577,10 @@ function identifyNode(nodeId, getNode) {
|
|
|
442
577
|
}
|
|
443
578
|
|
|
444
579
|
// ../helpers/src/protocol/node.ts
|
|
445
|
-
import { z as
|
|
580
|
+
import { z as z5 } from "zod";
|
|
446
581
|
|
|
447
582
|
// ../helpers/src/jsonschema/zod.ts
|
|
448
|
-
import { z as
|
|
583
|
+
import { z as z4 } from "zod";
|
|
449
584
|
|
|
450
585
|
// ../helpers/src/jsonschema/validate.ts
|
|
451
586
|
import {
|
|
@@ -539,42 +674,42 @@ class Ajv extends BaseAjv {
|
|
|
539
674
|
}
|
|
540
675
|
|
|
541
676
|
// ../helpers/src/jsonschema/zod.ts
|
|
542
|
-
var jsonSchema7Schema =
|
|
677
|
+
var jsonSchema7Schema = z4.custom((value) => {
|
|
543
678
|
const ajv = new Ajv;
|
|
544
679
|
return ajv.validateSchema(value);
|
|
545
680
|
}, { message: "Invalid json schema" });
|
|
546
|
-
var jsonSchema7ObjectSchema =
|
|
547
|
-
type:
|
|
681
|
+
var jsonSchema7ObjectSchema = z4.object({
|
|
682
|
+
type: z4.literal("object")
|
|
548
683
|
}).and(jsonSchema7Schema);
|
|
549
|
-
var jsonSchema7NullSchema =
|
|
550
|
-
type:
|
|
684
|
+
var jsonSchema7NullSchema = z4.object({
|
|
685
|
+
type: z4.literal("null")
|
|
551
686
|
});
|
|
552
687
|
|
|
553
688
|
// ../helpers/src/protocol/node.ts
|
|
554
|
-
var outputDefinitionSchema =
|
|
689
|
+
var outputDefinitionSchema = z5.object({
|
|
555
690
|
schema: jsonSchema7Schema.nullable().optional()
|
|
556
|
-
}).and(
|
|
557
|
-
|
|
558
|
-
default:
|
|
559
|
-
name:
|
|
691
|
+
}).and(z5.union([
|
|
692
|
+
z5.object({
|
|
693
|
+
default: z5.literal(false).default(false),
|
|
694
|
+
name: z5.string().min(1)
|
|
560
695
|
}),
|
|
561
|
-
|
|
562
|
-
default:
|
|
696
|
+
z5.object({
|
|
697
|
+
default: z5.literal(true).default(true)
|
|
563
698
|
})
|
|
564
|
-
])).and(
|
|
565
|
-
|
|
566
|
-
exit:
|
|
567
|
-
target:
|
|
699
|
+
])).and(z5.union([
|
|
700
|
+
z5.object({
|
|
701
|
+
exit: z5.literal(false).default(false),
|
|
702
|
+
target: z5.string().min(1)
|
|
568
703
|
}),
|
|
569
|
-
|
|
704
|
+
z5.object({ exit: z5.literal(true) })
|
|
570
705
|
]));
|
|
571
|
-
var defaultOutputSchema =
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
default:
|
|
576
|
-
exit:
|
|
577
|
-
target:
|
|
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)
|
|
578
713
|
})
|
|
579
714
|
]).transform((output) => {
|
|
580
715
|
if (typeof output === "string") {
|
|
@@ -586,7 +721,7 @@ var defaultOutputSchema = z4.union([
|
|
|
586
721
|
}
|
|
587
722
|
return output;
|
|
588
723
|
});
|
|
589
|
-
var outputSchema =
|
|
724
|
+
var outputSchema = z5.union([z5.string().min(1), outputDefinitionSchema]).transform((output) => {
|
|
590
725
|
if (typeof output === "string") {
|
|
591
726
|
return {
|
|
592
727
|
default: true,
|
|
@@ -627,59 +762,59 @@ function validateOutputs(outputs, ctx) {
|
|
|
627
762
|
knownTargets.add(target);
|
|
628
763
|
});
|
|
629
764
|
}
|
|
630
|
-
var defaultOutputsSchema =
|
|
631
|
-
var outputsSchema =
|
|
632
|
-
var idSchema =
|
|
633
|
-
var metaSchema =
|
|
634
|
-
var entryNodeSchema =
|
|
635
|
-
type:
|
|
636
|
-
id:
|
|
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__"),
|
|
637
772
|
output: defaultOutputsSchema,
|
|
638
773
|
inputSchema: jsonSchema7Schema.default({ type: "null" }),
|
|
639
774
|
metaSchema: jsonSchema7Schema.default({ type: "null" }),
|
|
640
775
|
meta: metaSchema
|
|
641
776
|
});
|
|
642
|
-
var serviceNodeSchema =
|
|
643
|
-
type:
|
|
777
|
+
var serviceNodeSchema = z5.object({
|
|
778
|
+
type: z5.literal("service"),
|
|
644
779
|
output: outputsSchema,
|
|
645
|
-
inputSchema:
|
|
780
|
+
inputSchema: z5.union([jsonSchema7ObjectSchema, jsonSchema7NullSchema]).default({ type: "null" }),
|
|
646
781
|
id: idSchema,
|
|
647
|
-
name:
|
|
648
|
-
version:
|
|
649
|
-
configuration:
|
|
782
|
+
name: z5.string(),
|
|
783
|
+
version: z5.string(),
|
|
784
|
+
configuration: z5.any().optional(),
|
|
650
785
|
configurationSchema: jsonSchema7Schema.default({ type: "null" }),
|
|
651
|
-
alias:
|
|
652
|
-
ttl:
|
|
653
|
-
retry:
|
|
654
|
-
retryDelay:
|
|
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(),
|
|
655
790
|
meta: metaSchema
|
|
656
791
|
});
|
|
657
|
-
var catchNodeSchema =
|
|
658
|
-
type:
|
|
792
|
+
var catchNodeSchema = z5.object({
|
|
793
|
+
type: z5.literal("catch"),
|
|
659
794
|
output: outputsSchema,
|
|
660
795
|
id: idSchema,
|
|
661
|
-
subject:
|
|
796
|
+
subject: z5.string(),
|
|
662
797
|
meta: metaSchema
|
|
663
798
|
});
|
|
664
|
-
var logicNodeSchema =
|
|
665
|
-
type:
|
|
666
|
-
alias:
|
|
799
|
+
var logicNodeSchema = z5.object({
|
|
800
|
+
type: z5.literal("logic"),
|
|
801
|
+
alias: z5.string().optional(),
|
|
667
802
|
output: outputsSchema,
|
|
668
803
|
id: idSchema,
|
|
669
|
-
script:
|
|
670
|
-
concurrency:
|
|
671
|
-
language:
|
|
672
|
-
maxExecutionTime:
|
|
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),
|
|
673
808
|
meta: metaSchema
|
|
674
809
|
});
|
|
675
|
-
var orNodeSchema =
|
|
810
|
+
var orNodeSchema = z5.object({
|
|
676
811
|
id: idSchema,
|
|
677
|
-
type:
|
|
678
|
-
alias:
|
|
812
|
+
type: z5.literal("or"),
|
|
813
|
+
alias: z5.string().optional(),
|
|
679
814
|
output: outputsSchema,
|
|
680
815
|
meta: metaSchema
|
|
681
816
|
});
|
|
682
|
-
var nodeSchema =
|
|
817
|
+
var nodeSchema = z5.discriminatedUnion("type", [
|
|
683
818
|
entryNodeSchema,
|
|
684
819
|
serviceNodeSchema,
|
|
685
820
|
catchNodeSchema,
|
|
@@ -692,7 +827,7 @@ class NodesError extends ZodError {
|
|
|
692
827
|
constructor(message, params, path = []) {
|
|
693
828
|
super([
|
|
694
829
|
{
|
|
695
|
-
code:
|
|
830
|
+
code: z6.ZodIssueCode.custom,
|
|
696
831
|
message,
|
|
697
832
|
path,
|
|
698
833
|
params
|
|
@@ -700,7 +835,7 @@ class NodesError extends ZodError {
|
|
|
700
835
|
]);
|
|
701
836
|
}
|
|
702
837
|
}
|
|
703
|
-
var nodesSchema =
|
|
838
|
+
var nodesSchema = z6.array(nodeSchema).transform((nodes) => {
|
|
704
839
|
const aliases = new Map;
|
|
705
840
|
const names = new Map;
|
|
706
841
|
let entryNode = null;
|
|
@@ -837,27 +972,27 @@ var nodesSchema = z5.array(nodeSchema).transform((nodes) => {
|
|
|
837
972
|
});
|
|
838
973
|
|
|
839
974
|
// ../helpers/src/protocol/command.ts
|
|
840
|
-
var abortSchema =
|
|
841
|
-
type:
|
|
842
|
-
reason:
|
|
975
|
+
var abortSchema = z7.object({
|
|
976
|
+
type: z7.literal("ABORT"),
|
|
977
|
+
reason: z7.string().optional()
|
|
843
978
|
});
|
|
844
|
-
var nodeOptionsSchema =
|
|
845
|
-
maxExecutions:
|
|
846
|
-
uploadUrl:
|
|
847
|
-
streamUrl:
|
|
979
|
+
var nodeOptionsSchema = z7.object({
|
|
980
|
+
maxExecutions: z7.number().int().min(0).optional().default(10),
|
|
981
|
+
uploadUrl: z7.string().optional(),
|
|
982
|
+
streamUrl: z7.string().optional()
|
|
848
983
|
});
|
|
849
|
-
var createNodesSchema =
|
|
850
|
-
type:
|
|
984
|
+
var createNodesSchema = z7.object({
|
|
985
|
+
type: z7.literal("CREATE_NODES"),
|
|
851
986
|
nodes: nodesSchema,
|
|
852
|
-
input:
|
|
853
|
-
meta:
|
|
987
|
+
input: z7.any(),
|
|
988
|
+
meta: z7.any(),
|
|
854
989
|
options: nodeOptionsSchema
|
|
855
990
|
});
|
|
856
|
-
var commandSchema =
|
|
991
|
+
var commandSchema = z7.union([abortSchema, createNodesSchema]);
|
|
857
992
|
|
|
858
993
|
// src/createAmqpConnection.ts
|
|
859
994
|
import { connect } from "amqp-connection-manager";
|
|
860
|
-
import { z as
|
|
995
|
+
import { z as z8 } from "zod";
|
|
861
996
|
|
|
862
997
|
// src/helpers.ts
|
|
863
998
|
class RetryError extends Error {
|
|
@@ -874,17 +1009,20 @@ var OUTPUT_VALUE = Symbol("output_value");
|
|
|
874
1009
|
function isOutputValue(value) {
|
|
875
1010
|
return value !== null && typeof value === "object" && OUTPUT_VALUE in value;
|
|
876
1011
|
}
|
|
877
|
-
function
|
|
1012
|
+
function isRecord2(data) {
|
|
878
1013
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
879
1014
|
}
|
|
880
|
-
async function unwrapResult(result, options) {
|
|
1015
|
+
async function unwrapResult(result, options, onDone) {
|
|
881
1016
|
if (isOutputValue(result)) {
|
|
882
1017
|
return {
|
|
883
|
-
value: await mapOutput(result.value, options),
|
|
1018
|
+
value: await mapOutput({ value: result.value, options, onDone }),
|
|
884
1019
|
outputName: result[OUTPUT_VALUE]
|
|
885
1020
|
};
|
|
886
1021
|
}
|
|
887
|
-
return {
|
|
1022
|
+
return {
|
|
1023
|
+
value: await mapOutput({ value: result, options, onDone }),
|
|
1024
|
+
outputName: null
|
|
1025
|
+
};
|
|
888
1026
|
}
|
|
889
1027
|
function createContextHelper(options) {
|
|
890
1028
|
const nodes = new Map(options.nodes.map((node) => [
|
|
@@ -904,10 +1042,10 @@ function createContextHelper(options) {
|
|
|
904
1042
|
return options.context.meta;
|
|
905
1043
|
},
|
|
906
1044
|
getData() {
|
|
907
|
-
return Array.from(nodes.values()).filter((result) => result.executionDate &&
|
|
1045
|
+
return Array.from(nodes.values()).filter((result) => result.executionDate && isRecord2(result.data)).toSorted((a, b) => a.executionDate.getTime() - b.executionDate.getTime()).reduce((acc, result) => ({
|
|
908
1046
|
...acc,
|
|
909
1047
|
...result.data
|
|
910
|
-
}),
|
|
1048
|
+
}), isRecord2(options.context.input) ? { ...options.context.input } : {});
|
|
911
1049
|
},
|
|
912
1050
|
toOutput(name, value) {
|
|
913
1051
|
return {
|
|
@@ -968,18 +1106,20 @@ function mapInput(data) {
|
|
|
968
1106
|
}
|
|
969
1107
|
|
|
970
1108
|
// src/createAmqpConnection.ts
|
|
971
|
-
var messageKeySchema =
|
|
1109
|
+
var messageKeySchema = z8.string().transform((str) => deobfuscate(str)).pipe(z8.tuple([z8.string().uuid(), z8.string().uuid(), z8.string().uuid()]).rest(z8.string())).transform((arr) => ({
|
|
972
1110
|
taskId: arr[0],
|
|
973
1111
|
serviceId: arr[1],
|
|
974
|
-
messageId: arr[2]
|
|
1112
|
+
messageId: arr[2],
|
|
1113
|
+
uploadUrl: arr[3] || undefined,
|
|
1114
|
+
streamUrl: arr[4] || undefined
|
|
975
1115
|
}));
|
|
976
|
-
var headerSchema =
|
|
977
|
-
properties:
|
|
978
|
-
correlationId:
|
|
979
|
-
headers:
|
|
980
|
-
version:
|
|
981
|
-
taskId:
|
|
982
|
-
serviceId:
|
|
1116
|
+
var headerSchema = z8.object({
|
|
1117
|
+
properties: z8.object({
|
|
1118
|
+
correlationId: z8.string().uuid(),
|
|
1119
|
+
headers: z8.object({
|
|
1120
|
+
version: z8.string(),
|
|
1121
|
+
taskId: z8.string().uuid(),
|
|
1122
|
+
serviceId: z8.string().uuid()
|
|
983
1123
|
})
|
|
984
1124
|
})
|
|
985
1125
|
}).transform((msg) => ({
|
|
@@ -988,11 +1128,11 @@ var headerSchema = z7.object({
|
|
|
988
1128
|
taskId: msg.properties.headers.taskId,
|
|
989
1129
|
serviceId: msg.properties.headers.serviceId
|
|
990
1130
|
}));
|
|
991
|
-
var payloadSchema =
|
|
1131
|
+
var payloadSchema = z8.object({ content: z8.instanceof(Buffer) }).transform((msg) => JSON.parse(msg.content.toString())).pipe(z8.object({
|
|
992
1132
|
context: contextSchema,
|
|
993
|
-
meta:
|
|
1133
|
+
meta: z8.object({
|
|
994
1134
|
nodes: nodesSchema,
|
|
995
|
-
state:
|
|
1135
|
+
state: z8.record(z8.any()),
|
|
996
1136
|
options: nodeOptionsSchema
|
|
997
1137
|
})
|
|
998
1138
|
}));
|
|
@@ -1010,7 +1150,7 @@ function createConnection({
|
|
|
1010
1150
|
const queue = `${url.username}@${version}`;
|
|
1011
1151
|
const exchange = url.username;
|
|
1012
1152
|
const connection = connect(url.toString());
|
|
1013
|
-
const connectedPromise = new Promise((
|
|
1153
|
+
const connectedPromise = new Promise((resolve2, reject) => {
|
|
1014
1154
|
const unsubscribe = () => {
|
|
1015
1155
|
clearTimeout(timeout);
|
|
1016
1156
|
connection.removeListener("connect", handleConnect);
|
|
@@ -1021,7 +1161,7 @@ function createConnection({
|
|
|
1021
1161
|
}, connectionTimeout);
|
|
1022
1162
|
const handleConnect = () => {
|
|
1023
1163
|
unsubscribe();
|
|
1024
|
-
|
|
1164
|
+
resolve2();
|
|
1025
1165
|
};
|
|
1026
1166
|
const handleConnectFailed = ({ err }) => {
|
|
1027
1167
|
unsubscribe();
|
|
@@ -1058,6 +1198,7 @@ function createConnection({
|
|
|
1058
1198
|
channel.nack(message, false, false);
|
|
1059
1199
|
return;
|
|
1060
1200
|
}
|
|
1201
|
+
const donePromises = [];
|
|
1061
1202
|
let removeActiveMessage = () => {
|
|
1062
1203
|
};
|
|
1063
1204
|
try {
|
|
@@ -1107,7 +1248,7 @@ function createConnection({
|
|
|
1107
1248
|
deferred = true;
|
|
1108
1249
|
deferredReason = reason || null;
|
|
1109
1250
|
ack();
|
|
1110
|
-
return obfuscate(taskId, serviceId, messageId);
|
|
1251
|
+
return obfuscate(taskId, serviceId, messageId, payload.meta.options.uploadUrl ?? "", payload.meta.options.streamUrl ?? "");
|
|
1111
1252
|
}
|
|
1112
1253
|
});
|
|
1113
1254
|
if (isMessageHandlerGenerator(messageHandler)) {
|
|
@@ -1119,7 +1260,9 @@ function createConnection({
|
|
|
1119
1260
|
deferred = false;
|
|
1120
1261
|
console.warn("returning a value in a deferred message resets the deferred status");
|
|
1121
1262
|
}
|
|
1122
|
-
const
|
|
1263
|
+
const donePromise = createRemotePromise();
|
|
1264
|
+
donePromises.push(donePromise);
|
|
1265
|
+
const { value, outputName } = await unwrapResult(result, payload.meta.options, donePromise.resolve);
|
|
1123
1266
|
if (!done || typeof value !== "undefined") {
|
|
1124
1267
|
publish({
|
|
1125
1268
|
messageId,
|
|
@@ -1136,7 +1279,9 @@ function createConnection({
|
|
|
1136
1279
|
} else {
|
|
1137
1280
|
const result = await messageHandler(extendedContext);
|
|
1138
1281
|
ack();
|
|
1139
|
-
const
|
|
1282
|
+
const donePromise = createRemotePromise();
|
|
1283
|
+
donePromises.push(donePromise);
|
|
1284
|
+
const { value, outputName } = await unwrapResult(result, payload.meta.options, donePromise.resolve);
|
|
1140
1285
|
if (deferred && value) {
|
|
1141
1286
|
console.warn("returning a value in a deferred message resets the deferred status");
|
|
1142
1287
|
deferred = false;
|
|
@@ -1151,14 +1296,19 @@ function createConnection({
|
|
|
1151
1296
|
});
|
|
1152
1297
|
}
|
|
1153
1298
|
}
|
|
1154
|
-
setImmediate(() =>
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1299
|
+
setImmediate(async () => {
|
|
1300
|
+
if (!deferred) {
|
|
1301
|
+
await Promise.allSettled(donePromises);
|
|
1302
|
+
}
|
|
1303
|
+
publish({
|
|
1304
|
+
messageId,
|
|
1305
|
+
taskId,
|
|
1306
|
+
serviceId,
|
|
1307
|
+
data: deferredReason,
|
|
1308
|
+
deferred,
|
|
1309
|
+
done: !deferred
|
|
1310
|
+
});
|
|
1311
|
+
});
|
|
1162
1312
|
} catch (error) {
|
|
1163
1313
|
if (error instanceof RetryError) {
|
|
1164
1314
|
const properties = {
|
|
@@ -1213,26 +1363,39 @@ function createConnection({
|
|
|
1213
1363
|
},
|
|
1214
1364
|
open: () => connectedPromise.then(() => api),
|
|
1215
1365
|
async act(messageKey, actor) {
|
|
1216
|
-
const { taskId, serviceId, messageId } = messageKeySchema.parse(messageKey);
|
|
1366
|
+
const { taskId, serviceId, messageId, ...options } = messageKeySchema.parse(messageKey);
|
|
1217
1367
|
if (activeMessages.has(messageId)) {
|
|
1218
1368
|
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1219
1369
|
}
|
|
1370
|
+
const donePromises = [];
|
|
1220
1371
|
await actor({
|
|
1221
|
-
sendToOutput(outputName, data) {
|
|
1372
|
+
async sendToOutput(outputName, data) {
|
|
1373
|
+
const donePromise = createRemotePromise();
|
|
1374
|
+
donePromises.push(donePromise);
|
|
1222
1375
|
publish({
|
|
1223
1376
|
messageId,
|
|
1224
1377
|
taskId,
|
|
1225
1378
|
serviceId,
|
|
1226
|
-
data
|
|
1379
|
+
data: await mapOutput({
|
|
1380
|
+
value: data,
|
|
1381
|
+
options,
|
|
1382
|
+
onDone: donePromise.resolve
|
|
1383
|
+
}),
|
|
1227
1384
|
outputName
|
|
1228
1385
|
});
|
|
1229
1386
|
},
|
|
1230
|
-
send(data) {
|
|
1387
|
+
async send(data) {
|
|
1388
|
+
const donePromise = createRemotePromise();
|
|
1389
|
+
donePromises.push(donePromise);
|
|
1231
1390
|
publish({
|
|
1232
1391
|
messageId,
|
|
1233
1392
|
taskId,
|
|
1234
1393
|
serviceId,
|
|
1235
|
-
data
|
|
1394
|
+
data: await mapOutput({
|
|
1395
|
+
value: data,
|
|
1396
|
+
options,
|
|
1397
|
+
onDone: donePromise.resolve
|
|
1398
|
+
})
|
|
1236
1399
|
});
|
|
1237
1400
|
},
|
|
1238
1401
|
abort(error) {
|
|
@@ -1249,27 +1412,30 @@ function createConnection({
|
|
|
1249
1412
|
});
|
|
1250
1413
|
}
|
|
1251
1414
|
});
|
|
1252
|
-
setImmediate(() =>
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1415
|
+
setImmediate(async () => {
|
|
1416
|
+
await Promise.allSettled(donePromises);
|
|
1417
|
+
publish({
|
|
1418
|
+
messageId,
|
|
1419
|
+
taskId,
|
|
1420
|
+
serviceId,
|
|
1421
|
+
done: true
|
|
1422
|
+
});
|
|
1423
|
+
});
|
|
1258
1424
|
}
|
|
1259
1425
|
};
|
|
1260
1426
|
return api;
|
|
1261
1427
|
}
|
|
1262
1428
|
|
|
1263
1429
|
// src/index.ts
|
|
1264
|
-
var connectionOptionsSchema =
|
|
1265
|
-
url:
|
|
1266
|
-
|
|
1267
|
-
|
|
1430
|
+
var connectionOptionsSchema = z9.object({
|
|
1431
|
+
url: z9.union([
|
|
1432
|
+
z9.string().regex(/^amqps?:\/\/(.+):(.+)@(.+)$/).transform((str) => new URL(str)),
|
|
1433
|
+
z9.instanceof(URL).refine((url) => url.protocol.match(/^amqps?:/), "Wrong protocol")
|
|
1268
1434
|
]),
|
|
1269
|
-
version:
|
|
1270
|
-
silent:
|
|
1271
|
-
prefetch:
|
|
1272
|
-
connectionTimeout:
|
|
1435
|
+
version: z9.string(),
|
|
1436
|
+
silent: z9.boolean().optional(),
|
|
1437
|
+
prefetch: z9.number().int().optional(),
|
|
1438
|
+
connectionTimeout: z9.number().positive().default(3000)
|
|
1273
1439
|
});
|
|
1274
1440
|
function createService(optionsOrVersion, optionalMessageHandler) {
|
|
1275
1441
|
let options;
|
|
@@ -1303,5 +1469,5 @@ export {
|
|
|
1303
1469
|
RequenceFile
|
|
1304
1470
|
};
|
|
1305
1471
|
|
|
1306
|
-
//# debugId=
|
|
1472
|
+
//# debugId=41E805E9FDA0F22664756E2164756E21
|
|
1307
1473
|
//# sourceMappingURL=index.js.map
|