@requence/service 1.0.0-alpha.3 → 1.0.0-alpha.31

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