@requence/service 1.0.0-alpha.2 → 1.0.0-alpha.20
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 +103 -0
- package/build/{chunk-0x9092n4.js → chunk-6w7td62p.js} +5 -44
- package/build/chunk-6w7td62p.js.map +10 -0
- package/build/cli.js +22 -11
- package/build/cli.js.map +3 -3
- package/build/index.js +534 -775
- package/build/index.js.map +16 -16
- package/build/types/helpers/src/files/RequenceFile.d.ts +40 -0
- package/build/types/helpers/src/files/RequenceFile.d.ts.map +1 -0
- package/build/types/helpers/src/files/RequenceStream.d.ts +32 -0
- package/build/types/helpers/src/files/RequenceStream.d.ts.map +1 -0
- 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 +7 -0
- package/build/types/helpers/src/files/index.d.ts.map +1 -0
- package/build/types/helpers/src/files/isValidMimeType.d.ts +5 -0
- package/build/types/helpers/src/files/isValidMimeType.d.ts.map +1 -0
- package/build/types/helpers/src/files/mapOutput.d.ts +10 -0
- package/build/types/helpers/src/files/mapOutput.d.ts.map +1 -0
- 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/files/types.d.ts +4 -0
- package/build/types/helpers/src/files/types.d.ts.map +1 -0
- package/build/types/helpers/src/index.d.ts +9 -6
- package/build/types/helpers/src/index.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/mapSchema.d.ts +20 -0
- package/build/types/helpers/src/jsonschema/mapSchema.d.ts.map +1 -0
- package/build/types/helpers/src/jsonschema/types.d.ts +11 -0
- package/build/types/helpers/src/jsonschema/types.d.ts.map +1 -0
- package/build/types/helpers/src/jsonschema/validate.d.ts +29 -0
- package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -0
- package/build/types/helpers/src/jsonschema/zod.d.ts +12 -0
- package/build/types/helpers/src/jsonschema/zod.d.ts.map +1 -0
- 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/command.d.ts +414 -0
- package/build/types/helpers/src/protocol/command.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/helpers.d.ts +5 -0
- package/build/types/helpers/src/protocol/helpers.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/index.d.ts +8 -0
- package/build/types/helpers/src/protocol/index.d.ts.map +1 -0
- 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 +241 -0
- package/build/types/helpers/src/protocol/update.d.ts.map +1 -0
- 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/mapData.d.ts +17 -0
- package/build/types/helpers/src/utils/mapData.d.ts.map +1 -0
- package/build/types/helpers/src/{utils.d.ts → utils/matchSchema.d.ts} +2 -2
- 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/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 +17 -18
- package/build/types/service/src/createAmqpConnection.d.ts.map +1 -1
- package/build/types/service/src/helpers.d.ts +13 -88
- package/build/types/service/src/helpers.d.ts.map +1 -1
- package/build/types/service/src/index.d.ts +7 -5
- package/build/types/service/src/index.d.ts.map +1 -1
- package/build/types/service/src/mapInput.d.ts +2 -0
- package/build/types/service/src/mapInput.d.ts.map +1 -0
- package/package.json +7 -8
- package/build/chunk-0x9092n4.js.map +0 -12
- 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,675 +1,407 @@
|
|
|
1
1
|
import {
|
|
2
|
-
clone,
|
|
3
|
-
createObjectProxy,
|
|
4
2
|
deobfuscate,
|
|
5
3
|
obfuscate
|
|
6
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6w7td62p.js";
|
|
7
5
|
|
|
8
6
|
// src/index.ts
|
|
9
|
-
import
|
|
10
|
-
import { z as z8 } from "zod";
|
|
7
|
+
import fs from "node:fs";
|
|
11
8
|
|
|
12
|
-
// ../helpers/src/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return contextHelper[internalKey];
|
|
28
|
-
}
|
|
29
|
-
function createContextHelper(context, nodes) {
|
|
30
|
-
const results = new Map(nodes.map((node) => [
|
|
31
|
-
node.id,
|
|
32
|
-
{
|
|
33
|
-
node,
|
|
34
|
-
executionDate: node.id in context.dates ? new Date(context.dates[node.id]) : null,
|
|
35
|
-
data: context.data[node.id] ?? null,
|
|
36
|
-
error: context.errors[node.id] ?? null
|
|
37
|
-
}
|
|
38
|
-
]));
|
|
39
|
-
const lookUpMap = new Map;
|
|
40
|
-
for (const node of nodes) {
|
|
41
|
-
const alias = typeof node.meta?.mapAlias === "string" ? node.meta.mapAlias : ("alias" in node) && node.alias;
|
|
42
|
-
if (alias) {
|
|
43
|
-
if (lookUpMap.has(alias)) {
|
|
44
|
-
lookUpMap.get(alias).push(node.id);
|
|
45
|
-
} else {
|
|
46
|
-
lookUpMap.set(alias, [node.id]);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const name = typeof node.meta?.mapName === "string" ? node.meta.mapName : node.type === "service" && node.name;
|
|
50
|
-
if (name) {
|
|
51
|
-
if (lookUpMap.has(name)) {
|
|
52
|
-
lookUpMap.get(name).push(node.id);
|
|
53
|
-
} else {
|
|
54
|
-
lookUpMap.set(name, [node.id]);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
[internalKey]: {
|
|
60
|
-
results
|
|
61
|
-
},
|
|
62
|
-
getInput() {
|
|
63
|
-
return context.input;
|
|
64
|
-
},
|
|
65
|
-
getMeta() {
|
|
66
|
-
return context.meta;
|
|
67
|
-
},
|
|
68
|
-
getData(alias) {
|
|
69
|
-
if (alias) {
|
|
70
|
-
const nodeIds = lookUpMap.get(alias);
|
|
71
|
-
if (!nodeIds) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
const combinedData = nodeIds.map((nodeId) => results.get(nodeId)?.data).filter(Boolean);
|
|
75
|
-
if (combinedData.length === 0) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
if (combinedData.length === 1) {
|
|
79
|
-
return combinedData[0];
|
|
80
|
-
}
|
|
81
|
-
if (combinedData.every(isRecord)) {
|
|
82
|
-
return combinedData.reduce((acc, data) => ({ ...acc, ...data }), {});
|
|
9
|
+
// ../helpers/src/utils/createRemotePromise.ts
|
|
10
|
+
function createRemotePromise(onAwait) {
|
|
11
|
+
let resolvePromise;
|
|
12
|
+
let rejectPromise;
|
|
13
|
+
const internalPromise = new Promise((resolve, reject) => {
|
|
14
|
+
resolvePromise = resolve;
|
|
15
|
+
rejectPromise = reject;
|
|
16
|
+
});
|
|
17
|
+
let isAwaited = false;
|
|
18
|
+
const wrappedPromise = new Proxy(internalPromise, {
|
|
19
|
+
get(target, property) {
|
|
20
|
+
if (property === "then" || property === "catch" || property === "finally") {
|
|
21
|
+
if (!isAwaited && onAwait) {
|
|
22
|
+
isAwaited = true;
|
|
23
|
+
onAwait(resolvePromise, rejectPromise);
|
|
83
24
|
}
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
return Array.from(results.values()).filter((result) => result.executionDate && isRecord(result.data)).toSorted((a, b) => a.executionDate.getTime() - b.executionDate.getTime()).reduce((acc, result) => ({
|
|
87
|
-
...acc,
|
|
88
|
-
...result.data
|
|
89
|
-
}), isRecord(context.input) ? { ...context.input } : {});
|
|
90
|
-
},
|
|
91
|
-
getError(alias) {
|
|
92
|
-
const nodeIds = lookUpMap.get(alias);
|
|
93
|
-
if (!nodeIds) {
|
|
94
|
-
return null;
|
|
25
|
+
return target[property].bind(target);
|
|
95
26
|
}
|
|
96
|
-
return
|
|
97
|
-
`);
|
|
27
|
+
return target[property];
|
|
98
28
|
}
|
|
99
|
-
};
|
|
29
|
+
});
|
|
30
|
+
return Object.assign(wrappedPromise, {
|
|
31
|
+
resolve: resolvePromise,
|
|
32
|
+
reject: rejectPromise,
|
|
33
|
+
promise: wrappedPromise
|
|
34
|
+
});
|
|
100
35
|
}
|
|
101
|
-
// ../helpers/src/protocol/command.ts
|
|
102
|
-
import { z as z5 } from "zod";
|
|
103
36
|
|
|
104
|
-
// ../helpers/src/
|
|
105
|
-
import {
|
|
37
|
+
// ../helpers/src/utils/isRecord.ts
|
|
38
|
+
import { z } from "zod/v4";
|
|
39
|
+
var recordSchema = z.record(z.string(), z.unknown());
|
|
40
|
+
function isRecord(data) {
|
|
41
|
+
return recordSchema.safeParse(data).success;
|
|
42
|
+
}
|
|
106
43
|
|
|
107
|
-
// ../helpers/src/
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
for (const output of outputs) {
|
|
112
|
-
if (output.exit) {
|
|
113
|
-
outputTargets.add("__exit__");
|
|
114
|
-
} else {
|
|
115
|
-
outputTargets.add(output.target);
|
|
116
|
-
}
|
|
44
|
+
// ../helpers/src/utils/mapData.ts
|
|
45
|
+
function resolve(value, onResolve) {
|
|
46
|
+
if (value instanceof Promise) {
|
|
47
|
+
return Promise.resolve().then(() => value).then(onResolve);
|
|
117
48
|
}
|
|
118
|
-
return
|
|
49
|
+
return onResolve(value);
|
|
50
|
+
}
|
|
51
|
+
function notUndefined(value, fallback) {
|
|
52
|
+
return resolve(value, (resolvedValue) => typeof resolvedValue === "undefined" ? fallback : resolvedValue);
|
|
119
53
|
}
|
|
120
54
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
for (const node of nodes) {
|
|
129
|
-
nodesByIdMap.set(node.id, node);
|
|
130
|
-
if ("alias" in node && node.alias) {
|
|
131
|
-
nodesByNameOrAlias.set(node.alias, node);
|
|
132
|
-
}
|
|
133
|
-
if ("name" in node && node.name) {
|
|
134
|
-
nodesByNameOrAlias.set(node.name, node);
|
|
55
|
+
class AbortMapData extends Error {
|
|
56
|
+
}
|
|
57
|
+
function mapData(data, visitors) {
|
|
58
|
+
let aborted = false;
|
|
59
|
+
const traverseData = (data2, path) => {
|
|
60
|
+
if (aborted) {
|
|
61
|
+
return data2;
|
|
135
62
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
+
});
|
|
141
75
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
getInputs(node) {
|
|
147
|
-
if (typeof node === "string") {
|
|
148
|
-
return inputsNodeMap.get(node) ?? [];
|
|
76
|
+
if (data2 === null) {
|
|
77
|
+
return notUndefined(visitors.Null?.(data2, path), data2);
|
|
149
78
|
}
|
|
150
|
-
if (
|
|
151
|
-
return
|
|
79
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data2)) {
|
|
80
|
+
return notUndefined(visitors.Buffer?.(data2, path), data2);
|
|
152
81
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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;
|
|
160
114
|
}
|
|
161
115
|
};
|
|
116
|
+
return traverseData(data, []);
|
|
162
117
|
}
|
|
118
|
+
mapData.abort = () => {
|
|
119
|
+
throw new AbortMapData;
|
|
120
|
+
};
|
|
163
121
|
|
|
164
|
-
// ../helpers/src/
|
|
165
|
-
function
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
122
|
+
// ../helpers/src/files/mapOutput.ts
|
|
123
|
+
async function upload(uploadUrl, body, signal, contentType) {
|
|
124
|
+
const uploadResponse = await fetch(uploadUrl, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
signal,
|
|
127
|
+
headers: contentType ? {
|
|
128
|
+
"Content-Type": contentType
|
|
129
|
+
} : {},
|
|
130
|
+
body
|
|
131
|
+
});
|
|
132
|
+
const data = await uploadResponse.json();
|
|
133
|
+
if (!data || typeof data !== "object") {
|
|
134
|
+
throw new Error("invalid upload response");
|
|
135
|
+
}
|
|
136
|
+
return toFileObject(data);
|
|
137
|
+
}
|
|
138
|
+
async function stream(streamUrl, stream2, signal, contentType) {
|
|
139
|
+
const [testStream, dataStream] = stream2.tee();
|
|
140
|
+
const reader = testStream.getReader();
|
|
141
|
+
const dataPromise = reader.read().then(({ done: done2 }) => {
|
|
142
|
+
if (done2) {
|
|
143
|
+
throw new Error("No streaming date received");
|
|
144
|
+
}
|
|
145
|
+
reader.cancel();
|
|
146
|
+
});
|
|
147
|
+
const streamResponse = await fetch(streamUrl, {
|
|
148
|
+
method: "POST",
|
|
149
|
+
signal,
|
|
150
|
+
headers: contentType ? { "Content-Type": contentType } : {}
|
|
151
|
+
});
|
|
152
|
+
const data = await streamResponse.json();
|
|
153
|
+
if (!data || typeof data !== "object") {
|
|
154
|
+
throw new Error("invalid stream response");
|
|
155
|
+
}
|
|
156
|
+
const { mime, url } = data;
|
|
157
|
+
await dataPromise;
|
|
158
|
+
const done = fetch(url, {
|
|
159
|
+
method: "POST",
|
|
160
|
+
signal,
|
|
161
|
+
duplex: "half",
|
|
162
|
+
body: dataStream
|
|
163
|
+
});
|
|
164
|
+
return [toStreamObject({ mime, url }), done];
|
|
165
|
+
}
|
|
166
|
+
async function mapOutput(params) {
|
|
167
|
+
const streamPromises = [];
|
|
168
|
+
const mapped = await mapData(params.value, {
|
|
169
|
+
async Object(obj) {
|
|
170
|
+
if (obj instanceof Blob || obj instanceof RequenceFile) {
|
|
171
|
+
if (obj instanceof RequenceFile && obj.fileObject) {
|
|
172
|
+
return obj.fileObject;
|
|
173
|
+
}
|
|
174
|
+
if (params.options.uploadUrl) {
|
|
175
|
+
try {
|
|
176
|
+
if (obj instanceof Blob) {
|
|
177
|
+
return await upload(params.options.uploadUrl, obj, params.signal, obj.type);
|
|
178
|
+
}
|
|
179
|
+
if (obj instanceof RequenceFile) {
|
|
180
|
+
return await upload(params.options.uploadUrl, await obj.blob(), params.signal, obj.mimeType);
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (!(error instanceof Error)) {
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
params.onFail?.(error);
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
params.onSkip?.();
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
186
193
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
194
|
+
if (obj instanceof Response || obj instanceof RequenceStream) {
|
|
195
|
+
if (obj instanceof RequenceStream && obj.streamObject) {
|
|
196
|
+
return obj.streamObject;
|
|
197
|
+
}
|
|
198
|
+
if (params.options.streamUrl) {
|
|
199
|
+
try {
|
|
200
|
+
if (obj instanceof Response && obj.body) {
|
|
201
|
+
const [streamObject, streamPromise] = await stream(params.options.streamUrl, obj.body, params.signal, obj.headers.get("Content-Type"));
|
|
202
|
+
streamPromises.push(streamPromise);
|
|
203
|
+
return streamObject;
|
|
204
|
+
}
|
|
205
|
+
if (obj instanceof RequenceStream) {
|
|
206
|
+
const [streamObject, streamPromise] = await stream(params.options.streamUrl, obj.stream(), params.signal, obj.mimeType);
|
|
207
|
+
streamPromises.push(streamPromise);
|
|
208
|
+
return streamObject;
|
|
209
|
+
}
|
|
210
|
+
} catch (error) {
|
|
211
|
+
if (!(error instanceof Error)) {
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
params.onFail?.(error);
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
params.onSkip?.();
|
|
219
|
+
return null;
|
|
191
220
|
}
|
|
192
|
-
usedSet.add(inputNodeId);
|
|
193
221
|
}
|
|
194
|
-
followPath(inputNodeId, usedSet);
|
|
195
|
-
}
|
|
196
|
-
if (isOrNode) {
|
|
197
|
-
sets.delete(set2);
|
|
198
222
|
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
followPath("__exit__", set);
|
|
203
|
-
return Array.from(sets, (set2) => Array.from(set2).toReversed());
|
|
223
|
+
});
|
|
224
|
+
Promise.allSettled(streamPromises).then(() => params.onDone?.());
|
|
225
|
+
return mapped;
|
|
204
226
|
}
|
|
205
227
|
|
|
206
|
-
// ../helpers/src/
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
228
|
+
// ../helpers/src/files/RequenceFile.ts
|
|
229
|
+
class RequenceFile {
|
|
230
|
+
#data;
|
|
231
|
+
#file = null;
|
|
232
|
+
constructor(blobParts, options) {
|
|
233
|
+
this.#data = new Blob(blobParts, options);
|
|
210
234
|
}
|
|
211
|
-
|
|
212
|
-
|
|
235
|
+
static fromFileObject(file) {
|
|
236
|
+
const instance = new this([], { type: "x/x" });
|
|
237
|
+
instance.#file = file;
|
|
238
|
+
return instance;
|
|
213
239
|
}
|
|
214
|
-
|
|
215
|
-
return
|
|
240
|
+
get fileObject() {
|
|
241
|
+
return this.#file;
|
|
216
242
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return `Unknown[${nodeId}]`;
|
|
243
|
+
get size() {
|
|
244
|
+
return this.#file?.size ?? this.#data.size;
|
|
220
245
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
246
|
+
get mimeType() {
|
|
247
|
+
return this.#file?.mime ?? this.#data.type;
|
|
248
|
+
}
|
|
249
|
+
get mainMimeType() {
|
|
250
|
+
return this.mimeType.split("/")[0];
|
|
251
|
+
}
|
|
252
|
+
get subMimeType() {
|
|
253
|
+
return this.mimeType.split("/")[1];
|
|
254
|
+
}
|
|
255
|
+
async text() {
|
|
256
|
+
if (this.#file) {
|
|
257
|
+
return fetch(this.#file.url).then((response) => response.text());
|
|
227
258
|
}
|
|
228
|
-
|
|
229
|
-
|
|
259
|
+
return this.#data.text();
|
|
260
|
+
}
|
|
261
|
+
async json() {
|
|
262
|
+
if (this.#file) {
|
|
263
|
+
return fetch(this.#file.url).then((response) => response.json());
|
|
230
264
|
}
|
|
231
|
-
|
|
232
|
-
|
|
265
|
+
return JSON.parse(await this.text());
|
|
266
|
+
}
|
|
267
|
+
async blob() {
|
|
268
|
+
if (this.#file) {
|
|
269
|
+
return fetch(this.#file.url).then((response) => response.blob());
|
|
233
270
|
}
|
|
234
|
-
|
|
235
|
-
|
|
271
|
+
return this.#data;
|
|
272
|
+
}
|
|
273
|
+
async arrayBuffer() {
|
|
274
|
+
if (this.#file) {
|
|
275
|
+
return fetch(this.#file.url).then((response) => response.arrayBuffer());
|
|
236
276
|
}
|
|
277
|
+
return this.#data.arrayBuffer();
|
|
237
278
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
// ../helpers/src/protocol/node.ts
|
|
241
|
-
import { z as z3 } from "zod";
|
|
242
|
-
|
|
243
|
-
// ../helpers/src/protocol/jsonSchema.ts
|
|
244
|
-
import { z as z2 } from "zod";
|
|
245
|
-
var jsonSchema7Schema = z2.lazy(() => z2.object({
|
|
246
|
-
$id: z2.string().optional(),
|
|
247
|
-
$schema: z2.string().optional(),
|
|
248
|
-
$ref: z2.string().optional(),
|
|
249
|
-
title: z2.string().optional(),
|
|
250
|
-
description: z2.string().optional(),
|
|
251
|
-
type: z2.union([
|
|
252
|
-
z2.literal("string"),
|
|
253
|
-
z2.literal("number"),
|
|
254
|
-
z2.literal("integer"),
|
|
255
|
-
z2.literal("boolean"),
|
|
256
|
-
z2.literal("object"),
|
|
257
|
-
z2.literal("array"),
|
|
258
|
-
z2.literal("null")
|
|
259
|
-
]).optional(),
|
|
260
|
-
enum: z2.array(z2.union([z2.string(), z2.number(), z2.boolean(), z2.null()])).optional(),
|
|
261
|
-
const: z2.union([z2.string(), z2.number(), z2.boolean(), z2.null()]).optional(),
|
|
262
|
-
multipleOf: z2.number().positive().optional(),
|
|
263
|
-
maximum: z2.number().optional(),
|
|
264
|
-
exclusiveMaximum: z2.number().optional(),
|
|
265
|
-
minimum: z2.number().optional(),
|
|
266
|
-
exclusiveMinimum: z2.number().optional(),
|
|
267
|
-
maxLength: z2.number().int().nonnegative().optional(),
|
|
268
|
-
minLength: z2.number().int().nonnegative().optional(),
|
|
269
|
-
pattern: z2.string().optional(),
|
|
270
|
-
additionalItems: z2.boolean().optional(),
|
|
271
|
-
items: z2.union([z2.lazy(() => jsonSchema7Schema), z2.array(jsonSchema7Schema)]).optional(),
|
|
272
|
-
maxItems: z2.number().int().nonnegative().optional(),
|
|
273
|
-
minItems: z2.number().int().nonnegative().optional(),
|
|
274
|
-
uniqueItems: z2.boolean().optional(),
|
|
275
|
-
contains: z2.lazy(() => jsonSchema7Schema).optional(),
|
|
276
|
-
maxProperties: z2.number().int().nonnegative().optional(),
|
|
277
|
-
minProperties: z2.number().int().nonnegative().optional(),
|
|
278
|
-
required: z2.array(z2.string()).optional(),
|
|
279
|
-
properties: z2.record(jsonSchema7Schema).optional(),
|
|
280
|
-
patternProperties: z2.record(jsonSchema7Schema).optional(),
|
|
281
|
-
additionalProperties: z2.union([z2.boolean(), z2.lazy(() => jsonSchema7Schema)]).optional(),
|
|
282
|
-
dependencies: z2.record(z2.union([z2.array(z2.string()), jsonSchema7Schema])).optional(),
|
|
283
|
-
propertyNames: z2.lazy(() => jsonSchema7Schema).optional(),
|
|
284
|
-
if: z2.lazy(() => jsonSchema7Schema).optional(),
|
|
285
|
-
then: z2.lazy(() => jsonSchema7Schema).optional(),
|
|
286
|
-
else: z2.lazy(() => jsonSchema7Schema).optional(),
|
|
287
|
-
allOf: z2.array(jsonSchema7Schema).optional(),
|
|
288
|
-
anyOf: z2.array(jsonSchema7Schema).optional(),
|
|
289
|
-
oneOf: z2.array(jsonSchema7Schema).optional(),
|
|
290
|
-
not: z2.lazy(() => jsonSchema7Schema).optional(),
|
|
291
|
-
definitions: z2.record(jsonSchema7Schema).optional(),
|
|
292
|
-
format: z2.string().optional(),
|
|
293
|
-
contentMediaType: z2.string().optional(),
|
|
294
|
-
contentEncoding: z2.string().optional()
|
|
295
|
-
}));
|
|
296
|
-
var jsonSchema7ObjectSchema = z2.object({
|
|
297
|
-
type: z2.literal("object"),
|
|
298
|
-
properties: z2.record(jsonSchema7Schema),
|
|
299
|
-
required: z2.array(z2.string()).optional(),
|
|
300
|
-
description: z2.string().optional(),
|
|
301
|
-
maxProperties: z2.number().int().nonnegative().optional(),
|
|
302
|
-
minProperties: z2.number().int().nonnegative().optional(),
|
|
303
|
-
additionalProperties: z2.boolean().optional()
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
// ../helpers/src/protocol/node.ts
|
|
307
|
-
var outputDefinitionSchema = z3.object({
|
|
308
|
-
schema: jsonSchema7Schema.nullable().optional()
|
|
309
|
-
}).and(z3.union([
|
|
310
|
-
z3.object({
|
|
311
|
-
default: z3.literal(false).default(false),
|
|
312
|
-
name: z3.string().min(1)
|
|
313
|
-
}),
|
|
314
|
-
z3.object({
|
|
315
|
-
default: z3.literal(true).default(true)
|
|
316
|
-
})
|
|
317
|
-
])).and(z3.union([
|
|
318
|
-
z3.object({
|
|
319
|
-
exit: z3.literal(false).default(false),
|
|
320
|
-
target: z3.string().min(1)
|
|
321
|
-
}),
|
|
322
|
-
z3.object({ exit: z3.literal(true) })
|
|
323
|
-
]));
|
|
324
|
-
var defaultOutputSchema = z3.union([
|
|
325
|
-
z3.string().min(1),
|
|
326
|
-
z3.object({ default: z3.literal(true).default(true), exit: z3.literal(true) }),
|
|
327
|
-
z3.object({
|
|
328
|
-
default: z3.literal(true).default(true),
|
|
329
|
-
exit: z3.literal(false).default(false),
|
|
330
|
-
target: z3.string().min(1)
|
|
331
|
-
})
|
|
332
|
-
]).transform((output) => {
|
|
333
|
-
if (typeof output === "string") {
|
|
334
|
-
return {
|
|
335
|
-
default: true,
|
|
336
|
-
exit: false,
|
|
337
|
-
target: output
|
|
338
|
-
};
|
|
279
|
+
toString() {
|
|
280
|
+
return `RequenceFile<${this.mimeType}>`;
|
|
339
281
|
}
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
var outputSchema = z3.union([z3.string().min(1), outputDefinitionSchema]).transform((output) => {
|
|
343
|
-
if (typeof output === "string") {
|
|
344
|
-
return {
|
|
345
|
-
default: true,
|
|
346
|
-
exit: false,
|
|
347
|
-
target: output
|
|
348
|
-
};
|
|
282
|
+
toJSON() {
|
|
283
|
+
return `RequenceFile<${this.mimeType}>`;
|
|
349
284
|
}
|
|
350
|
-
return output;
|
|
351
|
-
});
|
|
352
|
-
function validateOutputs(outputs, ctx) {
|
|
353
|
-
const exitOutputs = new Set(outputs.filter((output) => output.exit).map((output) => output.default ? "__default__" : output.name));
|
|
354
|
-
outputs.filter((output) => !output.exit).forEach((output) => {
|
|
355
|
-
const name = output.default ? "__default__" : output.name;
|
|
356
|
-
if (exitOutputs.has(name)) {
|
|
357
|
-
ctx.addIssue({
|
|
358
|
-
code: "custom",
|
|
359
|
-
message: output.default ? `default exit output cannot be mixed with target output "${output.target}"` : `named exit output "${name}" cannot be mixed with target output "${output.target}"`
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
const targets = new Map;
|
|
364
|
-
outputs.forEach((output) => {
|
|
365
|
-
const name = output.default ? "__default__" : output.name;
|
|
366
|
-
const target = output.exit ? "__exit__" : output.target;
|
|
367
|
-
if (!targets.has(name)) {
|
|
368
|
-
targets.set(name, new Set);
|
|
369
|
-
}
|
|
370
|
-
const knownTargets = targets.get(name);
|
|
371
|
-
if (knownTargets.has(target)) {
|
|
372
|
-
ctx.addIssue({
|
|
373
|
-
code: "custom",
|
|
374
|
-
message: [
|
|
375
|
-
output.default ? "duplicate default output" : `duplicate named output "${name}"`,
|
|
376
|
-
output.exit ? "for exit" : `for target "${target}"`
|
|
377
|
-
].join(" ")
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
knownTargets.add(target);
|
|
381
|
-
});
|
|
382
285
|
}
|
|
383
|
-
var defaultOutputsSchema = z3.array(defaultOutputSchema).default([]).superRefine(validateOutputs);
|
|
384
|
-
var outputsSchema = z3.array(outputSchema).default([]).superRefine(validateOutputs);
|
|
385
|
-
var idSchema = z3.string().uuid().default(() => crypto.randomUUID());
|
|
386
|
-
var metaSchema = z3.record(z3.any()).optional();
|
|
387
|
-
var entryNodeSchema = z3.object({
|
|
388
|
-
type: z3.literal("entry"),
|
|
389
|
-
id: z3.literal("__entry__").default("__entry__"),
|
|
390
|
-
output: defaultOutputsSchema,
|
|
391
|
-
inputSchema: jsonSchema7Schema.nullable().optional(),
|
|
392
|
-
metaSchema: jsonSchema7Schema.nullable().optional(),
|
|
393
|
-
meta: metaSchema
|
|
394
|
-
});
|
|
395
|
-
var serviceNodeSchema = z3.object({
|
|
396
|
-
type: z3.literal("service"),
|
|
397
|
-
output: outputsSchema,
|
|
398
|
-
inputSchema: jsonSchema7ObjectSchema.nullable().optional(),
|
|
399
|
-
id: idSchema,
|
|
400
|
-
name: z3.string(),
|
|
401
|
-
version: z3.string(),
|
|
402
|
-
configuration: z3.any().optional(),
|
|
403
|
-
configurationSchema: jsonSchema7Schema.nullable().optional(),
|
|
404
|
-
alias: z3.string().optional(),
|
|
405
|
-
ttl: z3.number().int().min(1).optional(),
|
|
406
|
-
retry: z3.number().int().min(1).optional(),
|
|
407
|
-
retryDelay: z3.number().int().min(100).optional(),
|
|
408
|
-
meta: metaSchema
|
|
409
|
-
});
|
|
410
|
-
var catchNodeSchema = z3.object({
|
|
411
|
-
type: z3.literal("catch"),
|
|
412
|
-
output: outputsSchema,
|
|
413
|
-
id: idSchema,
|
|
414
|
-
subject: z3.string(),
|
|
415
|
-
meta: metaSchema
|
|
416
|
-
});
|
|
417
|
-
var logicNodeSchema = z3.object({
|
|
418
|
-
type: z3.literal("logic"),
|
|
419
|
-
alias: z3.string().optional(),
|
|
420
|
-
inputSchema: jsonSchema7ObjectSchema.nullable().optional(),
|
|
421
|
-
output: outputsSchema,
|
|
422
|
-
id: idSchema,
|
|
423
|
-
script: z3.string(),
|
|
424
|
-
concurrency: z3.boolean().default(true),
|
|
425
|
-
language: z3.enum(["javascript", "python", "typescript"]).default("javascript"),
|
|
426
|
-
maxExecutionTime: z3.number().int().min(0).default(200),
|
|
427
|
-
meta: metaSchema
|
|
428
|
-
});
|
|
429
|
-
var orNodeSchema = z3.object({
|
|
430
|
-
id: idSchema,
|
|
431
|
-
type: z3.literal("or"),
|
|
432
|
-
alias: z3.string().optional(),
|
|
433
|
-
output: outputsSchema,
|
|
434
|
-
meta: metaSchema
|
|
435
|
-
});
|
|
436
|
-
var nodeSchema = z3.discriminatedUnion("type", [
|
|
437
|
-
entryNodeSchema,
|
|
438
|
-
serviceNodeSchema,
|
|
439
|
-
catchNodeSchema,
|
|
440
|
-
logicNodeSchema,
|
|
441
|
-
orNodeSchema
|
|
442
|
-
]);
|
|
443
286
|
|
|
444
|
-
// ../helpers/src/
|
|
445
|
-
class
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
params
|
|
453
|
-
}
|
|
454
|
-
]);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
var nodesSchema = z4.array(nodeSchema).transform((nodes) => {
|
|
458
|
-
const aliases = new Map;
|
|
459
|
-
const names = new Map;
|
|
460
|
-
let entryNode = null;
|
|
461
|
-
let firstNodeId = null;
|
|
462
|
-
for (const node of nodes) {
|
|
463
|
-
if (node.type === "entry") {
|
|
464
|
-
entryNode = node;
|
|
465
|
-
}
|
|
466
|
-
if ((node.type === "service" || node.type === "logic") && !firstNodeId) {
|
|
467
|
-
firstNodeId = node.id;
|
|
468
|
-
}
|
|
469
|
-
if ("alias" in node && node.alias) {
|
|
470
|
-
if (!aliases.has(node.alias)) {
|
|
471
|
-
aliases.set(node.alias, []);
|
|
472
|
-
}
|
|
473
|
-
aliases.get(node.alias).push(node.id);
|
|
474
|
-
}
|
|
475
|
-
if ("name" in node && node.name) {
|
|
476
|
-
if (!names.has(node.name)) {
|
|
477
|
-
names.set(node.name, []);
|
|
478
|
-
}
|
|
479
|
-
names.get(node.name).push(node.id);
|
|
480
|
-
}
|
|
287
|
+
// ../helpers/src/files/RequenceStream.ts
|
|
288
|
+
class RequenceStream {
|
|
289
|
+
#data;
|
|
290
|
+
#stream = null;
|
|
291
|
+
#options;
|
|
292
|
+
constructor(stream2, options) {
|
|
293
|
+
this.#data = stream2;
|
|
294
|
+
this.#options = options;
|
|
481
295
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
type: "
|
|
485
|
-
id: "__entry__",
|
|
486
|
-
output: [{ default: true, exit: false, target: firstNodeId }]
|
|
296
|
+
static fromStreamObject(stream2) {
|
|
297
|
+
const instance = new this(null, {
|
|
298
|
+
type: "x/x"
|
|
487
299
|
});
|
|
300
|
+
instance.#stream = stream2;
|
|
301
|
+
return instance;
|
|
488
302
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return aliases.get(identifier)[0];
|
|
492
|
-
}
|
|
493
|
-
if (names.get(identifier)?.length === 1) {
|
|
494
|
-
return names.get(identifier)[0];
|
|
495
|
-
}
|
|
496
|
-
return identifier;
|
|
497
|
-
};
|
|
498
|
-
return nodes.map((node) => {
|
|
499
|
-
node.output = node.output.map((output) => ("target" in output) ? {
|
|
500
|
-
...output,
|
|
501
|
-
target: resolveOutput(output.target)
|
|
502
|
-
} : output);
|
|
503
|
-
if ("subject" in node) {
|
|
504
|
-
node.subject = resolveOutput(node.subject);
|
|
505
|
-
}
|
|
506
|
-
return node;
|
|
507
|
-
});
|
|
508
|
-
}).transform((nodes) => {
|
|
509
|
-
const { getInputs, getNode } = createNodeMaps(nodes);
|
|
510
|
-
const nodeAliases = new Set;
|
|
511
|
-
const nodeIds = new Set;
|
|
512
|
-
const catchSubjects = new Map;
|
|
513
|
-
const identify = (nodeId) => identifyNode(nodeId, getNode);
|
|
514
|
-
for (const node of nodes) {
|
|
515
|
-
if (nodeIds.has(node.id)) {
|
|
516
|
-
throw new NodesError("id is not unique", {
|
|
517
|
-
id: node.id
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
nodeIds.add(node.id);
|
|
521
|
-
if ("alias" in node && node.alias) {
|
|
522
|
-
if (nodeAliases.has(node.alias)) {
|
|
523
|
-
throw new NodesError("alias is not unique", {
|
|
524
|
-
alias: node.alias
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
nodeAliases.add(node.alias);
|
|
528
|
-
}
|
|
529
|
-
if (node.type === "catch") {
|
|
530
|
-
if (catchSubjects.has(node.subject)) {
|
|
531
|
-
throw new NodesError("only one catch node per service allowed", {
|
|
532
|
-
id: node.subject
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
catchSubjects.set(node.subject, node);
|
|
536
|
-
}
|
|
303
|
+
get streamObject() {
|
|
304
|
+
return this.#stream;
|
|
537
305
|
}
|
|
538
|
-
|
|
539
|
-
|
|
306
|
+
get mimeType() {
|
|
307
|
+
return this.#stream?.mime ?? this.#options.type;
|
|
540
308
|
}
|
|
541
|
-
|
|
542
|
-
|
|
309
|
+
get mainMimeType() {
|
|
310
|
+
return this.mimeType.split("/")[0];
|
|
543
311
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
throw new NodesError("catch node has invalid subject", {
|
|
547
|
-
id: catchNode.subject
|
|
548
|
-
});
|
|
549
|
-
}
|
|
312
|
+
get subMimeType() {
|
|
313
|
+
return this.mimeType.split("/")[1];
|
|
550
314
|
}
|
|
551
|
-
|
|
552
|
-
if (
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
315
|
+
stream() {
|
|
316
|
+
if (this.#stream) {
|
|
317
|
+
const { readable, writable } = new TransformStream;
|
|
318
|
+
fetch(this.#stream.url).then((response) => response.body?.pipeTo(writable));
|
|
319
|
+
return readable;
|
|
557
320
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
321
|
+
return this.#data;
|
|
322
|
+
}
|
|
323
|
+
asyncIterable() {
|
|
324
|
+
const reader = this.stream().getReader();
|
|
325
|
+
return {
|
|
326
|
+
[Symbol.asyncIterator]() {
|
|
327
|
+
return {
|
|
328
|
+
async next() {
|
|
329
|
+
return reader.read();
|
|
330
|
+
},
|
|
331
|
+
async return() {
|
|
332
|
+
reader.cancel();
|
|
333
|
+
reader.releaseLock();
|
|
334
|
+
return { done: true, value: null };
|
|
335
|
+
}
|
|
336
|
+
};
|
|
563
337
|
}
|
|
564
|
-
}
|
|
338
|
+
};
|
|
565
339
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
getNode,
|
|
569
|
-
onMissingInputs: (_node, path) => {
|
|
570
|
-
throw new NodesError("no path from entry to node", {
|
|
571
|
-
path: path.map(identify)
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
if (possiblePaths.every((possiblePath) => !possiblePath.includes("__entry__"))) {
|
|
576
|
-
throw new NodesError("no path from entry to exit");
|
|
340
|
+
toString() {
|
|
341
|
+
return `RequenceStream<${this.mimeType}>`;
|
|
577
342
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
const node = pathSegment === "__exit__" ? null : getNode(pathSegment);
|
|
581
|
-
if (node?.type === "catch" && possiblePath.includes(node.subject)) {
|
|
582
|
-
throw new NodesError("Unresolvable, inputs needs both catch and subject", {
|
|
583
|
-
path: possiblePath.map(identify)
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
}
|
|
343
|
+
toJSON() {
|
|
344
|
+
return `RequenceStream<${this.mimeType}>`;
|
|
587
345
|
}
|
|
588
|
-
|
|
589
|
-
});
|
|
346
|
+
}
|
|
590
347
|
|
|
591
|
-
// ../helpers/src/
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
maxExecutions: z5.number().int().min(0).optional().default(10)
|
|
598
|
-
});
|
|
599
|
-
var createNodesSchema = z5.object({
|
|
600
|
-
type: z5.literal("CREATE_NODES"),
|
|
601
|
-
nodes: nodesSchema,
|
|
602
|
-
input: z5.any(),
|
|
603
|
-
meta: z5.any(),
|
|
604
|
-
options: nodeOptionsSchema
|
|
605
|
-
});
|
|
606
|
-
var commandSchema = z5.union([abortSchema, createNodesSchema]);
|
|
607
|
-
// ../helpers/src/protocol/update.ts
|
|
608
|
-
import { z as z6 } from "zod";
|
|
609
|
-
var baseUpdateSchema = z6.object({
|
|
610
|
-
timestamp: z6.number().int().transform((int) => new Date(int))
|
|
611
|
-
});
|
|
612
|
-
var baseNodeUpdateSchema = baseUpdateSchema.extend({
|
|
613
|
-
nodeId: z6.string().uuid()
|
|
614
|
-
});
|
|
615
|
-
var nodeStartUpdateSchema = baseNodeUpdateSchema.extend({
|
|
616
|
-
type: z6.literal("NODE_START"),
|
|
617
|
-
context: contextSchema
|
|
618
|
-
});
|
|
619
|
-
var nodeErrorUpdateSchema = baseNodeUpdateSchema.extend({
|
|
620
|
-
type: z6.literal("NODE_ERROR"),
|
|
621
|
-
error: z6.string(),
|
|
622
|
-
context: contextSchema
|
|
623
|
-
});
|
|
624
|
-
var nodeUpdateSchema = baseNodeUpdateSchema.extend({
|
|
625
|
-
type: z6.literal("NODE_UPDATE"),
|
|
626
|
-
output: z6.string(),
|
|
627
|
-
data: z6.unknown(),
|
|
628
|
-
context: contextSchema
|
|
629
|
-
});
|
|
630
|
-
var nodeFinishedUpdateSchema = baseNodeUpdateSchema.extend({
|
|
631
|
-
type: z6.literal("NODE_FINISHED"),
|
|
632
|
-
context: contextSchema
|
|
633
|
-
});
|
|
634
|
-
var nodeDebugUpdateSchema = baseNodeUpdateSchema.extend({
|
|
635
|
-
type: z6.literal("NODE_DEBUG"),
|
|
636
|
-
severity: z6.enum(["log", "info", "warn", "error"]),
|
|
637
|
-
data: z6.unknown(),
|
|
638
|
-
context: contextSchema
|
|
639
|
-
});
|
|
640
|
-
var nodeDeferUpdateSchema = baseNodeUpdateSchema.extend({
|
|
641
|
-
type: z6.literal("NODE_DEFER"),
|
|
642
|
-
data: z6.unknown(),
|
|
643
|
-
context: contextSchema
|
|
644
|
-
});
|
|
645
|
-
var taskStartUpdateSchema = baseUpdateSchema.extend({
|
|
646
|
-
type: z6.literal("TASK_START"),
|
|
647
|
-
nodes: nodesSchema,
|
|
648
|
-
context: contextSchema
|
|
649
|
-
});
|
|
650
|
-
var taskErrorUpdateSchema = baseUpdateSchema.extend({
|
|
651
|
-
type: z6.literal("TASK_ERROR"),
|
|
652
|
-
reason: z6.string().optional(),
|
|
653
|
-
context: contextSchema
|
|
348
|
+
// ../helpers/src/files/streamObject.ts
|
|
349
|
+
import { z as z2 } from "zod/v4";
|
|
350
|
+
var streamObjectSchema = z2.object({
|
|
351
|
+
mime: z2.string(),
|
|
352
|
+
url: z2.string().url(),
|
|
353
|
+
__REQUENCE_type: z2.literal("RequenceStream")
|
|
654
354
|
});
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
355
|
+
function isStreamObject(data) {
|
|
356
|
+
return streamObjectSchema.safeParse(data).success;
|
|
357
|
+
}
|
|
358
|
+
function toStreamObject(streamInfo) {
|
|
359
|
+
return {
|
|
360
|
+
...streamInfo,
|
|
361
|
+
__REQUENCE_type: "RequenceStream"
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
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")
|
|
658
372
|
});
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
373
|
+
function toFileObject(fileInfo) {
|
|
374
|
+
return {
|
|
375
|
+
...fileInfo,
|
|
376
|
+
__REQUENCE_type: "RequenceFile"
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function isFileObject(data) {
|
|
380
|
+
return fileObjectSchema.safeParse(data).success;
|
|
381
|
+
}
|
|
382
|
+
|
|
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);
|
|
389
|
+
}
|
|
390
|
+
if (isStreamObject(obj)) {
|
|
391
|
+
return RequenceStream.fromStreamObject(obj);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/index.ts
|
|
398
|
+
import { z as z5 } from "zod/v4";
|
|
399
|
+
|
|
670
400
|
// src/createAmqpConnection.ts
|
|
671
|
-
import {
|
|
672
|
-
|
|
401
|
+
import {
|
|
402
|
+
connect
|
|
403
|
+
} from "amqp-connection-manager";
|
|
404
|
+
import { z as z4 } from "zod/v4";
|
|
673
405
|
|
|
674
406
|
// src/helpers.ts
|
|
675
407
|
class RetryError extends Error {
|
|
@@ -680,23 +412,32 @@ class RetryError extends Error {
|
|
|
680
412
|
}
|
|
681
413
|
}
|
|
682
414
|
|
|
415
|
+
class SkipError extends Error {
|
|
416
|
+
}
|
|
417
|
+
|
|
683
418
|
class AbortError extends Error {
|
|
684
419
|
}
|
|
685
420
|
var OUTPUT_VALUE = Symbol("output_value");
|
|
686
421
|
function isOutputValue(value) {
|
|
687
422
|
return value !== null && typeof value === "object" && OUTPUT_VALUE in value;
|
|
688
423
|
}
|
|
689
|
-
function unwrapResult(result) {
|
|
424
|
+
async function unwrapResult(result, options, onDone) {
|
|
690
425
|
if (isOutputValue(result)) {
|
|
691
|
-
return {
|
|
426
|
+
return {
|
|
427
|
+
value: await mapOutput({ value: result.value, options, onDone }),
|
|
428
|
+
outputName: result[OUTPUT_VALUE]
|
|
429
|
+
};
|
|
692
430
|
}
|
|
693
|
-
return {
|
|
431
|
+
return {
|
|
432
|
+
value: await mapOutput({ value: result, options, onDone }),
|
|
433
|
+
outputName: null
|
|
434
|
+
};
|
|
694
435
|
}
|
|
695
|
-
function
|
|
696
|
-
|
|
697
|
-
const internalContext = getInternalContext(contextHelper);
|
|
698
|
-
return Object.assign(contextHelper, {
|
|
436
|
+
function createContextHelper(options) {
|
|
437
|
+
return {
|
|
699
438
|
taskId: options.taskId,
|
|
439
|
+
input: resolveRequenceTypes(options.input),
|
|
440
|
+
configuration: resolveRequenceTypes(options.configuration),
|
|
700
441
|
toOutput(name, value) {
|
|
701
442
|
return {
|
|
702
443
|
[OUTPUT_VALUE]: name,
|
|
@@ -704,17 +445,6 @@ function createExtendedContextHelper(options) {
|
|
|
704
445
|
};
|
|
705
446
|
},
|
|
706
447
|
defer: options.onDefer,
|
|
707
|
-
getConfiguration() {
|
|
708
|
-
const result = internalContext.results.get(options.serviceId);
|
|
709
|
-
if (result?.node.type === "service") {
|
|
710
|
-
return result.node.configuration ?? null;
|
|
711
|
-
}
|
|
712
|
-
return null;
|
|
713
|
-
},
|
|
714
|
-
getNode() {
|
|
715
|
-
return internalContext.results.get(options.serviceId).node;
|
|
716
|
-
},
|
|
717
|
-
state: createObjectProxy(options.state, options.onStateChange),
|
|
718
448
|
debug: {
|
|
719
449
|
log(...data) {
|
|
720
450
|
options.onLog("log", data);
|
|
@@ -734,36 +464,53 @@ function createExtendedContextHelper(options) {
|
|
|
734
464
|
},
|
|
735
465
|
abort(reason) {
|
|
736
466
|
throw new AbortError(reason);
|
|
467
|
+
},
|
|
468
|
+
skip() {
|
|
469
|
+
throw new SkipError;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// src/mapInput.ts
|
|
475
|
+
function mapInput(data) {
|
|
476
|
+
return mapData(data, {
|
|
477
|
+
Object(obj) {
|
|
478
|
+
if (isFileObject(obj)) {
|
|
479
|
+
return RequenceFile.fromFileObject(obj);
|
|
480
|
+
}
|
|
481
|
+
if (isStreamObject(obj)) {
|
|
482
|
+
return RequenceStream.fromStreamObject(obj);
|
|
483
|
+
}
|
|
737
484
|
}
|
|
738
485
|
});
|
|
739
486
|
}
|
|
740
487
|
|
|
741
488
|
// src/createAmqpConnection.ts
|
|
742
|
-
var messageKeySchema =
|
|
489
|
+
var messageKeySchema = z4.string().transform((str) => deobfuscate(str)).pipe(z4.tuple([z4.uuid(), z4.uuid()]).rest(z4.string())).transform((arr) => ({
|
|
743
490
|
taskId: arr[0],
|
|
744
|
-
|
|
745
|
-
|
|
491
|
+
messageId: arr[1],
|
|
492
|
+
uploadUrl: arr[2] || undefined,
|
|
493
|
+
streamUrl: arr[3] || undefined
|
|
746
494
|
}));
|
|
747
|
-
var headerSchema =
|
|
748
|
-
properties:
|
|
749
|
-
correlationId:
|
|
750
|
-
headers:
|
|
751
|
-
version:
|
|
752
|
-
taskId:
|
|
753
|
-
serviceId: z7.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()
|
|
754
501
|
})
|
|
755
502
|
})
|
|
756
503
|
}).transform((msg) => ({
|
|
757
504
|
version: msg.properties.headers.version,
|
|
758
505
|
messageId: msg.properties.correlationId,
|
|
759
|
-
taskId: msg.properties.headers.taskId
|
|
760
|
-
serviceId: msg.properties.headers.serviceId
|
|
506
|
+
taskId: msg.properties.headers.taskId
|
|
761
507
|
}));
|
|
762
|
-
var payloadSchema =
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
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()
|
|
767
514
|
})
|
|
768
515
|
}));
|
|
769
516
|
function isMessageHandlerGenerator(handler) {
|
|
@@ -775,12 +522,13 @@ function createConnection({
|
|
|
775
522
|
version,
|
|
776
523
|
prefetch = 1,
|
|
777
524
|
silent = false,
|
|
778
|
-
connectionTimeout
|
|
525
|
+
connectionTimeout,
|
|
526
|
+
connectionOptions
|
|
779
527
|
}, messageHandler) {
|
|
780
528
|
const queue = `${url.username}@${version}`;
|
|
781
529
|
const exchange = url.username;
|
|
782
|
-
const connection = connect(url.toString());
|
|
783
|
-
const connectedPromise = new Promise((
|
|
530
|
+
const connection = connect(url.toString(), { connectionOptions });
|
|
531
|
+
const connectedPromise = new Promise((resolve2, reject) => {
|
|
784
532
|
const unsubscribe = () => {
|
|
785
533
|
clearTimeout(timeout);
|
|
786
534
|
connection.removeListener("connect", handleConnect);
|
|
@@ -791,7 +539,7 @@ function createConnection({
|
|
|
791
539
|
}, connectionTimeout);
|
|
792
540
|
const handleConnect = () => {
|
|
793
541
|
unsubscribe();
|
|
794
|
-
|
|
542
|
+
resolve2();
|
|
795
543
|
};
|
|
796
544
|
const handleConnectFailed = ({ err }) => {
|
|
797
545
|
unsubscribe();
|
|
@@ -824,50 +572,30 @@ function createConnection({
|
|
|
824
572
|
});
|
|
825
573
|
};
|
|
826
574
|
channel.consume(queue, async (message) => {
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
575
|
+
const donePromises = [];
|
|
576
|
+
let removeActiveMessage = () => {};
|
|
577
|
+
let acked = false;
|
|
578
|
+
const ack = () => {
|
|
579
|
+
if (!acked) {
|
|
580
|
+
acked = true;
|
|
581
|
+
channel.ack(message);
|
|
582
|
+
}
|
|
832
583
|
};
|
|
833
584
|
try {
|
|
834
585
|
let deferred = false;
|
|
835
586
|
let deferredReason = null;
|
|
836
|
-
const { messageId,
|
|
587
|
+
const { messageId, taskId } = headerSchema.parse(message);
|
|
837
588
|
activeMessages.add(messageId);
|
|
838
589
|
removeActiveMessage = () => activeMessages.delete(messageId);
|
|
839
590
|
const payload = payloadSchema.parse(message);
|
|
840
|
-
|
|
841
|
-
const ack = () => {
|
|
842
|
-
if (!acked) {
|
|
843
|
-
acked = true;
|
|
844
|
-
channel.ack(message);
|
|
845
|
-
}
|
|
846
|
-
};
|
|
847
|
-
let immediateUpdateState;
|
|
848
|
-
const extendedContext = createExtendedContextHelper({
|
|
849
|
-
serviceId,
|
|
850
|
-
context: payload.context,
|
|
851
|
-
nodes: payload.meta.nodes,
|
|
591
|
+
const extendedContext = createContextHelper({
|
|
852
592
|
taskId,
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
clearImmediate(immediateUpdateState);
|
|
856
|
-
immediateUpdateState = setImmediate(() => {
|
|
857
|
-
publish({
|
|
858
|
-
messageId,
|
|
859
|
-
taskId,
|
|
860
|
-
serviceId,
|
|
861
|
-
data: clone(newState),
|
|
862
|
-
state: true
|
|
863
|
-
});
|
|
864
|
-
});
|
|
865
|
-
},
|
|
593
|
+
input: mapInput(payload.input),
|
|
594
|
+
configuration: mapInput(payload.configuration),
|
|
866
595
|
onLog(debugMethod, data) {
|
|
867
596
|
publish({
|
|
868
597
|
messageId,
|
|
869
598
|
taskId,
|
|
870
|
-
serviceId,
|
|
871
599
|
data,
|
|
872
600
|
debugMethod,
|
|
873
601
|
debug: true
|
|
@@ -877,7 +605,7 @@ function createConnection({
|
|
|
877
605
|
deferred = true;
|
|
878
606
|
deferredReason = reason || null;
|
|
879
607
|
ack();
|
|
880
|
-
return obfuscate(taskId,
|
|
608
|
+
return obfuscate(taskId, messageId, payload.options.uploadUrl ?? "", payload.options.streamUrl ?? "");
|
|
881
609
|
}
|
|
882
610
|
});
|
|
883
611
|
if (isMessageHandlerGenerator(messageHandler)) {
|
|
@@ -889,12 +617,13 @@ function createConnection({
|
|
|
889
617
|
deferred = false;
|
|
890
618
|
console.warn("returning a value in a deferred message resets the deferred status");
|
|
891
619
|
}
|
|
892
|
-
const
|
|
620
|
+
const donePromise = createRemotePromise();
|
|
621
|
+
donePromises.push(donePromise);
|
|
622
|
+
const { value, outputName } = await unwrapResult(result, payload.options, donePromise.resolve);
|
|
893
623
|
if (!done || typeof value !== "undefined") {
|
|
894
624
|
publish({
|
|
895
625
|
messageId,
|
|
896
626
|
taskId,
|
|
897
|
-
serviceId,
|
|
898
627
|
data: value,
|
|
899
628
|
outputName
|
|
900
629
|
});
|
|
@@ -906,7 +635,9 @@ function createConnection({
|
|
|
906
635
|
} else {
|
|
907
636
|
const result = await messageHandler(extendedContext);
|
|
908
637
|
ack();
|
|
909
|
-
const
|
|
638
|
+
const donePromise = createRemotePromise();
|
|
639
|
+
donePromises.push(donePromise);
|
|
640
|
+
const { value, outputName } = await unwrapResult(result, payload.options, donePromise.resolve);
|
|
910
641
|
if (deferred && value) {
|
|
911
642
|
console.warn("returning a value in a deferred message resets the deferred status");
|
|
912
643
|
deferred = false;
|
|
@@ -915,42 +646,59 @@ function createConnection({
|
|
|
915
646
|
publish({
|
|
916
647
|
messageId,
|
|
917
648
|
taskId,
|
|
918
|
-
serviceId,
|
|
919
649
|
data: value,
|
|
920
650
|
outputName
|
|
921
651
|
});
|
|
922
652
|
}
|
|
923
653
|
}
|
|
924
|
-
setImmediate(() =>
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
654
|
+
setImmediate(async () => {
|
|
655
|
+
if (!deferred) {
|
|
656
|
+
await Promise.allSettled(donePromises);
|
|
657
|
+
}
|
|
658
|
+
publish({
|
|
659
|
+
messageId,
|
|
660
|
+
taskId,
|
|
661
|
+
data: deferredReason,
|
|
662
|
+
deferred,
|
|
663
|
+
done: !deferred
|
|
664
|
+
});
|
|
665
|
+
});
|
|
932
666
|
} catch (error) {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
|
|
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
|
+
}
|
|
940
678
|
return;
|
|
941
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
|
+
}
|
|
942
690
|
if (error instanceof AbortError && error.message.length > 0) {
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
|
|
691
|
+
if (assertNack("data already send, cannot abort")) {
|
|
692
|
+
channel.publish(`${exchange}-retry`, "operator", error.message, {
|
|
693
|
+
...message.properties,
|
|
694
|
+
contentType: "text/plain",
|
|
695
|
+
headers: {
|
|
696
|
+
...message.properties.headers,
|
|
697
|
+
abort: true
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
ack();
|
|
701
|
+
}
|
|
954
702
|
return;
|
|
955
703
|
}
|
|
956
704
|
if (error instanceof Error) {
|
|
@@ -958,20 +706,22 @@ function createConnection({
|
|
|
958
706
|
console.error(`Encountered an error inside service handler:`);
|
|
959
707
|
console.error(error);
|
|
960
708
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
|
|
709
|
+
if (!acked) {
|
|
710
|
+
channel.publish(`${exchange}-retry`, "operator", message.content, {
|
|
711
|
+
...message.properties,
|
|
712
|
+
headers: {
|
|
713
|
+
...message.properties.headers,
|
|
714
|
+
exception: true,
|
|
715
|
+
"error-message": error.message || "error in service handler"
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
channel.ack(message);
|
|
719
|
+
}
|
|
972
720
|
return;
|
|
973
721
|
}
|
|
974
|
-
|
|
722
|
+
if (!acked) {
|
|
723
|
+
channel.nack(message, false, false);
|
|
724
|
+
}
|
|
975
725
|
} finally {
|
|
976
726
|
removeActiveMessage();
|
|
977
727
|
}
|
|
@@ -983,73 +733,76 @@ function createConnection({
|
|
|
983
733
|
},
|
|
984
734
|
open: () => connectedPromise.then(() => api),
|
|
985
735
|
async act(messageKey, actor) {
|
|
736
|
+
const { taskId, messageId, ...options } = messageKeySchema.parse(messageKey);
|
|
737
|
+
if (activeMessages.has(messageId)) {
|
|
738
|
+
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
739
|
+
}
|
|
740
|
+
const donePromises = [];
|
|
986
741
|
await actor({
|
|
987
|
-
sendToOutput(outputName, data) {
|
|
988
|
-
const
|
|
989
|
-
|
|
990
|
-
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
991
|
-
}
|
|
742
|
+
async sendToOutput(outputName, data) {
|
|
743
|
+
const donePromise = createRemotePromise();
|
|
744
|
+
donePromises.push(donePromise);
|
|
992
745
|
publish({
|
|
993
|
-
messageId
|
|
994
|
-
taskId
|
|
995
|
-
|
|
996
|
-
|
|
746
|
+
messageId,
|
|
747
|
+
taskId,
|
|
748
|
+
data: await mapOutput({
|
|
749
|
+
value: data,
|
|
750
|
+
options,
|
|
751
|
+
onDone: donePromise.resolve
|
|
752
|
+
}),
|
|
997
753
|
outputName
|
|
998
754
|
});
|
|
999
755
|
},
|
|
1000
|
-
send(data) {
|
|
1001
|
-
const
|
|
1002
|
-
|
|
1003
|
-
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1004
|
-
}
|
|
756
|
+
async send(data) {
|
|
757
|
+
const donePromise = createRemotePromise();
|
|
758
|
+
donePromises.push(donePromise);
|
|
1005
759
|
publish({
|
|
1006
|
-
messageId
|
|
1007
|
-
taskId
|
|
1008
|
-
|
|
1009
|
-
|
|
760
|
+
messageId,
|
|
761
|
+
taskId,
|
|
762
|
+
data: await mapOutput({
|
|
763
|
+
value: data,
|
|
764
|
+
options,
|
|
765
|
+
onDone: donePromise.resolve
|
|
766
|
+
})
|
|
1010
767
|
});
|
|
1011
768
|
},
|
|
1012
769
|
abort(error) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
throw new Error("Cannot send deferred message while callback handler is still running");
|
|
1016
|
-
}
|
|
1017
|
-
channel.publish(`${exchange}-retry`, "requeue", error instanceof Error ? error.message : error, {
|
|
1018
|
-
correlationId: messageId2,
|
|
770
|
+
channel.publish(`${exchange}-retry`, "operator", error instanceof Error ? error.message : error, {
|
|
771
|
+
correlationId: messageId,
|
|
1019
772
|
expiration: 0,
|
|
1020
773
|
priority: 0,
|
|
1021
774
|
contentType: "text/plain",
|
|
1022
775
|
headers: {
|
|
1023
|
-
taskId
|
|
1024
|
-
serviceId: serviceId2,
|
|
776
|
+
taskId,
|
|
1025
777
|
abort: true
|
|
1026
778
|
}
|
|
1027
779
|
});
|
|
1028
780
|
}
|
|
1029
781
|
});
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
782
|
+
setImmediate(async () => {
|
|
783
|
+
await Promise.allSettled(donePromises);
|
|
784
|
+
publish({
|
|
785
|
+
messageId,
|
|
786
|
+
taskId,
|
|
787
|
+
done: true
|
|
788
|
+
});
|
|
789
|
+
});
|
|
1037
790
|
}
|
|
1038
791
|
};
|
|
1039
792
|
return api;
|
|
1040
793
|
}
|
|
1041
794
|
|
|
1042
795
|
// src/index.ts
|
|
1043
|
-
var
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
z8.instanceof(URL).refine((url) => url.protocol.match(/^amqps?:/), "Wrong protocol")
|
|
796
|
+
var connectionOptionsSchema = z5.object({
|
|
797
|
+
url: z5.union([
|
|
798
|
+
z5.string().regex(/^amqps?:\/\/(.+):(.+)@(.+)$/).transform((str) => new URL(str)),
|
|
799
|
+
z5.instanceof(URL).refine((url) => url.protocol.match(/^amqps?:/), "Wrong protocol")
|
|
1048
800
|
]),
|
|
1049
|
-
version:
|
|
1050
|
-
silent:
|
|
1051
|
-
prefetch:
|
|
1052
|
-
connectionTimeout:
|
|
801
|
+
version: z5.string(),
|
|
802
|
+
silent: z5.boolean().optional(),
|
|
803
|
+
prefetch: z5.number().int().optional(),
|
|
804
|
+
connectionTimeout: z5.number().positive().default(3000),
|
|
805
|
+
connectionOptions: z5.any()
|
|
1053
806
|
});
|
|
1054
807
|
function createService(optionsOrVersion, optionalMessageHandler) {
|
|
1055
808
|
let options;
|
|
@@ -1063,11 +816,15 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
1063
816
|
options = optionsOrVersion;
|
|
1064
817
|
messageHandler = optionalMessageHandler;
|
|
1065
818
|
}
|
|
1066
|
-
|
|
1067
|
-
if (!
|
|
819
|
+
let token = options.accessToken ?? process.env.REQUENCE_SERVICE_ACCESS_TOKEN ?? process.env.REQUENCE_ACCESS_TOKEN;
|
|
820
|
+
if (!token) {
|
|
821
|
+
const pkgJson = JSON.parse(fs.readFileSync("package.json", "utf-8"));
|
|
822
|
+
token = pkgJson.requence?.service?.accessToken ?? pkgJson.requence?.accessToken;
|
|
823
|
+
}
|
|
824
|
+
if (!token) {
|
|
1068
825
|
throw new Error("No service key found");
|
|
1069
826
|
}
|
|
1070
|
-
const parts = deobfuscate(
|
|
827
|
+
const parts = deobfuscate(token);
|
|
1071
828
|
if (parts.length < 2 || parts[0] !== "service") {
|
|
1072
829
|
throw new Error("Invalid service key");
|
|
1073
830
|
}
|
|
@@ -1078,8 +835,10 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
1078
835
|
return createConnection(connectionOptionsSchema.parse(connectionOptions), messageHandler);
|
|
1079
836
|
}
|
|
1080
837
|
export {
|
|
1081
|
-
createService
|
|
838
|
+
createService,
|
|
839
|
+
RequenceStream,
|
|
840
|
+
RequenceFile
|
|
1082
841
|
};
|
|
1083
842
|
|
|
1084
|
-
//# debugId=
|
|
843
|
+
//# debugId=EA149A6603814F0764756E2164756E21
|
|
1085
844
|
//# sourceMappingURL=index.js.map
|