@requence/task 1.0.0-alpha.21 → 1.0.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/build/{chunk-xdx5gf9h.js → chunk-y4v98p2s.js} +20 -5
- package/build/{chunk-xdx5gf9h.js.map → chunk-y4v98p2s.js.map} +2 -2
- package/build/cli.js +643 -137
- package/build/cli.js.map +27 -16
- package/build/index.js +194 -236
- package/build/index.js.map +12 -13
- package/build/types/helpers/src/files/fileObject.d.ts +2 -12
- package/build/types/helpers/src/files/fileObject.d.ts.map +1 -1
- package/build/types/helpers/src/files/mapOutput.d.ts +1 -1
- package/build/types/helpers/src/files/mapOutput.d.ts.map +1 -1
- package/build/types/helpers/src/files/streamObject.d.ts +2 -10
- package/build/types/helpers/src/files/streamObject.d.ts.map +1 -1
- package/build/types/helpers/src/index.d.ts +1 -0
- package/build/types/helpers/src/index.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/validate.d.ts +1 -0
- package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/zod.d.ts +4 -12
- package/build/types/helpers/src/jsonschema/zod.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/NodeTree.d.ts +504 -0
- package/build/types/helpers/src/protocol/NodeTree.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/NodesError.d.ts +5 -0
- package/build/types/helpers/src/protocol/NodesError.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/command.d.ts +373 -1954
- package/build/types/helpers/src/protocol/command.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/index.d.ts +5 -7
- package/build/types/helpers/src/protocol/index.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/nodeOptions.d.ts +16 -0
- package/build/types/helpers/src/protocol/nodeOptions.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/nodeType.d.ts +283 -0
- package/build/types/helpers/src/protocol/nodeType.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/targetNodes.d.ts +253 -0
- package/build/types/helpers/src/protocol/targetNodes.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/treeNodes.d.ts +606 -0
- package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/update.d.ts +182 -17892
- package/build/types/helpers/src/protocol/update.d.ts.map +1 -1
- package/build/types/helpers/src/utils/mapData.d.ts +4 -0
- package/build/types/helpers/src/utils/mapData.d.ts.map +1 -1
- package/build/types/helpers/src/utils/matchSchema.d.ts +1 -1
- package/build/types/helpers/src/utils/matchSchema.d.ts.map +1 -1
- package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts +2 -0
- package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts.map +1 -0
- package/build/types/helpers/src/utils/types.d.ts +4 -0
- package/build/types/helpers/src/utils/types.d.ts.map +1 -0
- package/build/types/task/src/createTask.d.ts.map +1 -1
- package/build/types/task/src/types.d.ts +114 -5103
- package/build/types/task/src/types.d.ts.map +1 -1
- package/build/types/task/src/watchTasks.d.ts +3 -1
- package/build/types/task/src/watchTasks.d.ts.map +1 -1
- package/package.json +2 -2
- package/build/types/helpers/src/context/context.d.ts +0 -156
- package/build/types/helpers/src/context/context.d.ts.map +0 -1
- package/build/types/helpers/src/context/index.d.ts +0 -2
- package/build/types/helpers/src/context/index.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/createNodeMaps.d.ts +0 -10
- package/build/types/helpers/src/protocol/createNodeMaps.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/getCycles.d.ts +0 -3
- package/build/types/helpers/src/protocol/getCycles.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/getNodeOutputs.d.ts +0 -4
- package/build/types/helpers/src/protocol/getNodeOutputs.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/getPossiblePaths.d.ts +0 -9
- package/build/types/helpers/src/protocol/getPossiblePaths.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/identifyNode.d.ts +0 -4
- package/build/types/helpers/src/protocol/identifyNode.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/node.d.ts +0 -1014
- package/build/types/helpers/src/protocol/node.d.ts.map +0 -1
- package/build/types/helpers/src/protocol/nodes.d.ts +0 -801
- package/build/types/helpers/src/protocol/nodes.d.ts.map +0 -1
- package/build/types/task/src/utils/mapOutput.d.ts +0 -2
- package/build/types/task/src/utils/mapOutput.d.ts.map +0 -1
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
deobfuscate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-y4v98p2s.js";
|
|
4
4
|
|
|
5
5
|
// ../helpers/src/utils/createRemotePromise.ts
|
|
6
6
|
function createRemotePromise(onAwait) {
|
|
@@ -78,8 +78,8 @@ function callbackToAsyncIterable(...args) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// ../helpers/src/utils/isRecord.ts
|
|
81
|
-
import { z } from "zod";
|
|
82
|
-
var recordSchema = z.record(z.unknown());
|
|
81
|
+
import { z } from "zod/v4";
|
|
82
|
+
var recordSchema = z.record(z.string(), z.unknown());
|
|
83
83
|
function isRecord(data) {
|
|
84
84
|
return recordSchema.safeParse(data).success;
|
|
85
85
|
}
|
|
@@ -94,54 +94,73 @@ function resolve(value, onResolve) {
|
|
|
94
94
|
function notUndefined(value, fallback) {
|
|
95
95
|
return resolve(value, (resolvedValue) => typeof resolvedValue === "undefined" ? fallback : resolvedValue);
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
class AbortMapData extends Error {
|
|
99
|
+
}
|
|
97
100
|
function mapData(data, visitors) {
|
|
101
|
+
let aborted = false;
|
|
98
102
|
const traverseData = (data2, path) => {
|
|
99
|
-
if (
|
|
100
|
-
return
|
|
101
|
-
if (resolvedData) {
|
|
102
|
-
return resolvedData;
|
|
103
|
-
}
|
|
104
|
-
const items = data2.map((item, index) => traverseData(item, [...path, index]));
|
|
105
|
-
if (items.some((item) => item instanceof Promise)) {
|
|
106
|
-
return Promise.all(items);
|
|
107
|
-
}
|
|
108
|
-
return items;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (data2 === null) {
|
|
112
|
-
return notUndefined(visitors.Null?.(data2, path), data2);
|
|
103
|
+
if (aborted) {
|
|
104
|
+
return data2;
|
|
113
105
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
106
|
+
try {
|
|
107
|
+
if (Array.isArray(data2)) {
|
|
108
|
+
return resolve(visitors.Array?.(data2, path), (resolvedData) => {
|
|
109
|
+
if (resolvedData) {
|
|
110
|
+
return resolvedData;
|
|
111
|
+
}
|
|
112
|
+
const items = data2.map((item, index) => traverseData(item, [...path, index]));
|
|
113
|
+
if (items.some((item) => item instanceof Promise)) {
|
|
114
|
+
return Promise.all(items);
|
|
115
|
+
}
|
|
116
|
+
return items;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (data2 === null) {
|
|
120
|
+
return notUndefined(visitors.Null?.(data2, path), data2);
|
|
121
|
+
}
|
|
122
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data2)) {
|
|
123
|
+
return notUndefined(visitors.Buffer?.(data2, path), data2);
|
|
124
|
+
}
|
|
125
|
+
if (typeof data2 === "string") {
|
|
126
|
+
return notUndefined(visitors.String?.(data2, path), data2);
|
|
127
|
+
}
|
|
128
|
+
if (typeof data2 === "number") {
|
|
129
|
+
return notUndefined(visitors.Number?.(data2, path), data2);
|
|
130
|
+
}
|
|
131
|
+
if (typeof data2 === "symbol") {
|
|
132
|
+
return notUndefined(visitors.Symbol?.(data2, path), data2);
|
|
133
|
+
}
|
|
134
|
+
if (isRecord(data2)) {
|
|
135
|
+
return resolve(visitors.Object?.(structuredClone(data2), path), (resolvedData) => {
|
|
136
|
+
const nextData = resolvedData ?? data2;
|
|
137
|
+
const entries = Object.entries(nextData).map(([key, value]) => [
|
|
138
|
+
key,
|
|
139
|
+
traverseData(value, [...path, key])
|
|
140
|
+
]);
|
|
141
|
+
if (entries.some(([, value]) => value instanceof Promise)) {
|
|
142
|
+
return Promise.all(entries.map(([key, value]) => Promise.resolve().then(() => value).then((resolvedValue) => [key, resolvedValue]))).then((entries2) => Object.fromEntries(entries2));
|
|
143
|
+
}
|
|
144
|
+
return Object.fromEntries(entries);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (typeof data2 === "object" && data2) {
|
|
148
|
+
return notUndefined(visitors.Object?.(data2, path), data2);
|
|
149
|
+
}
|
|
150
|
+
return data2;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (error instanceof AbortMapData) {
|
|
153
|
+
aborted = true;
|
|
154
|
+
return data2;
|
|
155
|
+
}
|
|
156
|
+
throw error;
|
|
137
157
|
}
|
|
138
|
-
return data2;
|
|
139
158
|
};
|
|
140
159
|
return traverseData(data, []);
|
|
141
160
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
161
|
+
mapData.abort = () => {
|
|
162
|
+
throw new AbortMapData;
|
|
163
|
+
};
|
|
145
164
|
|
|
146
165
|
// ../helpers/src/files/mapOutput.ts
|
|
147
166
|
async function upload(uploadUrl, body, signal, contentType) {
|
|
@@ -370,7 +389,7 @@ class RequenceStream {
|
|
|
370
389
|
}
|
|
371
390
|
|
|
372
391
|
// ../helpers/src/files/streamObject.ts
|
|
373
|
-
import { z as z2 } from "zod";
|
|
392
|
+
import { z as z2 } from "zod/v4";
|
|
374
393
|
var streamObjectSchema = z2.object({
|
|
375
394
|
mime: z2.string(),
|
|
376
395
|
url: z2.string().url(),
|
|
@@ -387,7 +406,7 @@ function toStreamObject(streamInfo) {
|
|
|
387
406
|
}
|
|
388
407
|
|
|
389
408
|
// ../helpers/src/files/fileObject.ts
|
|
390
|
-
import { z as z3 } from "zod";
|
|
409
|
+
import { z as z3 } from "zod/v4";
|
|
391
410
|
var fileObjectSchema = z3.object({
|
|
392
411
|
size: z3.number().int().positive(),
|
|
393
412
|
mime: z3.string(),
|
|
@@ -404,16 +423,7 @@ function isFileObject(data) {
|
|
|
404
423
|
return fileObjectSchema.safeParse(data).success;
|
|
405
424
|
}
|
|
406
425
|
|
|
407
|
-
// ../helpers/src/
|
|
408
|
-
var contextSchema = z4.object({
|
|
409
|
-
input: z4.any(),
|
|
410
|
-
meta: z4.any(),
|
|
411
|
-
tenant: z4.object({ name: z4.string() }),
|
|
412
|
-
data: z4.record(z4.string(), z4.any()),
|
|
413
|
-
errors: z4.record(z4.string(), z4.string()),
|
|
414
|
-
dates: z4.record(z4.string(), z4.string().datetime())
|
|
415
|
-
});
|
|
416
|
-
var internalKey = Symbol.for("internal");
|
|
426
|
+
// ../helpers/src/utils/resolveRequenceTypes.ts
|
|
417
427
|
function resolveRequenceTypes(data) {
|
|
418
428
|
return mapData(data, {
|
|
419
429
|
Object(obj) {
|
|
@@ -426,81 +436,6 @@ function resolveRequenceTypes(data) {
|
|
|
426
436
|
}
|
|
427
437
|
});
|
|
428
438
|
}
|
|
429
|
-
function createContextHelper(context, nodes) {
|
|
430
|
-
const input = resolveRequenceTypes(context.input);
|
|
431
|
-
const meta = resolveRequenceTypes(context.meta);
|
|
432
|
-
const results = new Map(nodes.map((node) => [
|
|
433
|
-
node.id,
|
|
434
|
-
{
|
|
435
|
-
node,
|
|
436
|
-
executionDate: node.id in context.dates ? new Date(context.dates[node.id]) : null,
|
|
437
|
-
data: resolveRequenceTypes(context.data[node.id] ?? null),
|
|
438
|
-
error: context.errors[node.id] ?? null
|
|
439
|
-
}
|
|
440
|
-
]));
|
|
441
|
-
const lookUpMap = new Map;
|
|
442
|
-
for (const node of nodes) {
|
|
443
|
-
const alias = typeof node.meta?.mapAlias === "string" ? node.meta.mapAlias : ("alias" in node) && node.alias;
|
|
444
|
-
if (alias) {
|
|
445
|
-
if (lookUpMap.has(alias)) {
|
|
446
|
-
lookUpMap.get(alias).push(node.id);
|
|
447
|
-
} else {
|
|
448
|
-
lookUpMap.set(alias, [node.id]);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
const name = typeof node.meta?.mapName === "string" ? node.meta.mapName : node.type === "service" && node.name;
|
|
452
|
-
if (name) {
|
|
453
|
-
if (lookUpMap.has(name)) {
|
|
454
|
-
lookUpMap.get(name).push(node.id);
|
|
455
|
-
} else {
|
|
456
|
-
lookUpMap.set(name, [node.id]);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return {
|
|
461
|
-
[internalKey]: {
|
|
462
|
-
results
|
|
463
|
-
},
|
|
464
|
-
getInput() {
|
|
465
|
-
return input;
|
|
466
|
-
},
|
|
467
|
-
getMeta() {
|
|
468
|
-
return meta;
|
|
469
|
-
},
|
|
470
|
-
getData(alias) {
|
|
471
|
-
if (alias) {
|
|
472
|
-
const nodeIds = lookUpMap.get(alias);
|
|
473
|
-
if (!nodeIds) {
|
|
474
|
-
return null;
|
|
475
|
-
}
|
|
476
|
-
const uniqueNodeIds = Array.from(new Set(nodeIds));
|
|
477
|
-
const combinedData = uniqueNodeIds.map((nodeId) => results.get(nodeId)?.data).filter(Boolean);
|
|
478
|
-
if (combinedData.length === 0) {
|
|
479
|
-
return null;
|
|
480
|
-
}
|
|
481
|
-
if (combinedData.length === 1) {
|
|
482
|
-
return combinedData[0];
|
|
483
|
-
}
|
|
484
|
-
if (combinedData.every(isRecord)) {
|
|
485
|
-
return combinedData.reduce((acc, data) => ({ ...acc, ...data }), {});
|
|
486
|
-
}
|
|
487
|
-
return combinedData;
|
|
488
|
-
}
|
|
489
|
-
return Array.from(results.values()).filter((result) => result.executionDate && isRecord(result.data)).toSorted((a, b) => a.executionDate.getTime() - b.executionDate.getTime()).reduce((acc, result) => ({
|
|
490
|
-
...acc,
|
|
491
|
-
...result.data
|
|
492
|
-
}), isRecord(input) ? input : {});
|
|
493
|
-
},
|
|
494
|
-
getError(alias) {
|
|
495
|
-
const nodeIds = lookUpMap.get(alias);
|
|
496
|
-
if (!nodeIds) {
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
499
|
-
return nodeIds.map((nodeId) => results.get(nodeId)?.error).filter((str) => typeof str === "string").join(`
|
|
500
|
-
`);
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
439
|
|
|
505
440
|
// src/createTask.ts
|
|
506
441
|
import { EventSource } from "eventsource";
|
|
@@ -553,71 +488,54 @@ async function abortTask(options) {
|
|
|
553
488
|
}
|
|
554
489
|
|
|
555
490
|
// src/types.ts
|
|
556
|
-
import { z as
|
|
557
|
-
var
|
|
558
|
-
id:
|
|
559
|
-
type:
|
|
560
|
-
alias:
|
|
561
|
-
service: z5.object({
|
|
562
|
-
id: z5.string().uuid(),
|
|
563
|
-
name: z5.string(),
|
|
564
|
-
version: z5.string()
|
|
565
|
-
}).optional()
|
|
491
|
+
import { z as z4 } from "zod/v4";
|
|
492
|
+
var nodeInfoSchema = z4.object({
|
|
493
|
+
id: z4.uuid(),
|
|
494
|
+
type: z4.literal("service"),
|
|
495
|
+
alias: z4.string().optional()
|
|
566
496
|
});
|
|
567
|
-
var
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
logic: z5.object({
|
|
572
|
-
language: z5.enum(["typescript", "javascript", "python"])
|
|
573
|
-
}).optional()
|
|
574
|
-
});
|
|
575
|
-
var nodeInfoSchema = z5.discriminatedUnion("type", [
|
|
576
|
-
serviceNodeInfoSchema,
|
|
577
|
-
logicNodeInfoSchema
|
|
578
|
-
]);
|
|
579
|
-
var baseUpdate = z5.object({
|
|
580
|
-
timestamp: z5.coerce.date(),
|
|
581
|
-
taskId: z5.string().uuid(),
|
|
582
|
-
updateId: z5.string().uuid(),
|
|
583
|
-
context: contextSchema,
|
|
584
|
-
nodes: z5.custom((data) => Array.isArray(data))
|
|
497
|
+
var baseUpdate = z4.object({
|
|
498
|
+
timestamp: z4.coerce.date(),
|
|
499
|
+
taskId: z4.uuid(),
|
|
500
|
+
updateId: z4.uuid()
|
|
585
501
|
});
|
|
586
502
|
var taskStartUpdateSchema = baseUpdate.extend({
|
|
587
|
-
type:
|
|
503
|
+
type: z4.literal("taskStart"),
|
|
504
|
+
input: z4.unknown()
|
|
588
505
|
});
|
|
589
506
|
var taskErrorUpdateSchema = baseUpdate.extend({
|
|
590
|
-
type:
|
|
591
|
-
|
|
507
|
+
type: z4.literal("taskError"),
|
|
508
|
+
reason: z4.string().optional()
|
|
592
509
|
});
|
|
593
510
|
var taskEndUpdateSchema = baseUpdate.extend({
|
|
594
|
-
type:
|
|
511
|
+
type: z4.literal("taskEnd"),
|
|
512
|
+
result: z4.record(z4.string(), z4.any())
|
|
595
513
|
});
|
|
596
514
|
var nodeStartUpdateSchema = baseUpdate.extend({
|
|
597
|
-
type:
|
|
515
|
+
type: z4.literal("nodeStart"),
|
|
598
516
|
node: nodeInfoSchema
|
|
599
517
|
});
|
|
600
518
|
var nodeUpdateUpdateSchema = baseUpdate.extend({
|
|
601
|
-
type:
|
|
519
|
+
type: z4.literal("nodeUpdate"),
|
|
602
520
|
node: nodeInfoSchema,
|
|
603
|
-
data:
|
|
604
|
-
output:
|
|
521
|
+
data: z4.unknown(),
|
|
522
|
+
output: z4.union([z4.null(), z4.string()])
|
|
605
523
|
});
|
|
606
524
|
var nodeErrorUpdateSchema = baseUpdate.extend({
|
|
607
|
-
type:
|
|
525
|
+
type: z4.literal("nodeError"),
|
|
608
526
|
node: nodeInfoSchema,
|
|
609
|
-
error:
|
|
527
|
+
error: z4.string()
|
|
610
528
|
});
|
|
611
529
|
var nodeDeferUpdateSchema = baseUpdate.extend({
|
|
612
|
-
type:
|
|
530
|
+
type: z4.literal("nodeDefer"),
|
|
613
531
|
node: nodeInfoSchema,
|
|
614
|
-
reason:
|
|
532
|
+
reason: z4.string().optional()
|
|
615
533
|
});
|
|
616
534
|
var nodeEndUpdateSchema = baseUpdate.extend({
|
|
617
|
-
type:
|
|
535
|
+
type: z4.literal("nodeEnd"),
|
|
618
536
|
node: nodeInfoSchema
|
|
619
537
|
});
|
|
620
|
-
var updateSchema =
|
|
538
|
+
var updateSchema = z4.discriminatedUnion("type", [
|
|
621
539
|
taskStartUpdateSchema,
|
|
622
540
|
taskErrorUpdateSchema,
|
|
623
541
|
taskEndUpdateSchema,
|
|
@@ -627,21 +545,7 @@ var updateSchema = z5.discriminatedUnion("type", [
|
|
|
627
545
|
nodeDeferUpdateSchema,
|
|
628
546
|
nodeEndUpdateSchema
|
|
629
547
|
]);
|
|
630
|
-
var eventSchema =
|
|
631
|
-
|
|
632
|
-
// src/utils/mapOutput.ts
|
|
633
|
-
function mapOutput2(data) {
|
|
634
|
-
return mapData(data, {
|
|
635
|
-
Object(obj) {
|
|
636
|
-
if (isFileObject(obj)) {
|
|
637
|
-
return RequenceFile.fromFileObject(obj);
|
|
638
|
-
}
|
|
639
|
-
if (isStreamObject(obj)) {
|
|
640
|
-
return RequenceStream.fromStreamObject(obj);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
}
|
|
548
|
+
var eventSchema = z4.object({ type: z4.string(), data: z4.string() }).transform((event) => ({ type: event.type, ...JSON.parse(event.data) })).pipe(updateSchema);
|
|
645
549
|
|
|
646
550
|
// src/createTask.ts
|
|
647
551
|
class TaskError extends Error {
|
|
@@ -665,23 +569,15 @@ function createTask(options, onUpdate) {
|
|
|
665
569
|
const payload = await payloadPromise;
|
|
666
570
|
if (!payload.urls) {
|
|
667
571
|
resultPromise.resolve({
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
},
|
|
674
|
-
getError(_alias) {
|
|
572
|
+
input: options.input,
|
|
573
|
+
taskId: payload.taskId,
|
|
574
|
+
taskUrl: "",
|
|
575
|
+
result: null,
|
|
576
|
+
getNodeData(_alias) {
|
|
675
577
|
return null;
|
|
676
578
|
},
|
|
677
|
-
|
|
579
|
+
getNodeError(_alias) {
|
|
678
580
|
return null;
|
|
679
|
-
},
|
|
680
|
-
getTaskId() {
|
|
681
|
-
return payload.taskId;
|
|
682
|
-
},
|
|
683
|
-
getTaskUrl() {
|
|
684
|
-
return "";
|
|
685
581
|
}
|
|
686
582
|
});
|
|
687
583
|
return;
|
|
@@ -704,6 +600,7 @@ function createTask(options, onUpdate) {
|
|
|
704
600
|
"nodeError",
|
|
705
601
|
"nodeEnd"
|
|
706
602
|
];
|
|
603
|
+
const taskStorage = { input: null, data: {}, errors: {}, result: null };
|
|
707
604
|
taskEvents.forEach((taskEvent) => {
|
|
708
605
|
eventSource.addEventListener(taskEvent, (event) => {
|
|
709
606
|
const updateResult = eventSchema.safeParse(event);
|
|
@@ -713,38 +610,58 @@ function createTask(options, onUpdate) {
|
|
|
713
610
|
return;
|
|
714
611
|
}
|
|
715
612
|
const update = updateResult.data;
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
613
|
+
switch (update.type) {
|
|
614
|
+
case "taskStart": {
|
|
615
|
+
taskStorage.input = resolveRequenceTypes(update.input);
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
case "nodeUpdate": {
|
|
619
|
+
if (update.node.id) {
|
|
620
|
+
taskStorage.data[update.node.id] = resolveRequenceTypes(update.data);
|
|
621
|
+
}
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
case "nodeError": {
|
|
625
|
+
if (update.node.id) {
|
|
626
|
+
taskStorage.errors[update.node.id] = update.error;
|
|
627
|
+
}
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
case "taskEnd": {
|
|
631
|
+
taskStorage.result = resolveRequenceTypes(update.result);
|
|
632
|
+
eventSource.close();
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
case "taskError": {
|
|
636
|
+
eventSource.close();
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
723
639
|
}
|
|
640
|
+
const context = {
|
|
641
|
+
taskId: update.taskId,
|
|
642
|
+
input: taskStorage.input,
|
|
643
|
+
getNodeData(alias) {
|
|
644
|
+
return taskStorage.data[alias] ?? null;
|
|
645
|
+
},
|
|
646
|
+
getNodeError(alias) {
|
|
647
|
+
return taskStorage.errors[alias] ?? null;
|
|
648
|
+
},
|
|
649
|
+
result: taskStorage.result
|
|
650
|
+
};
|
|
724
651
|
const contextUpdate = {
|
|
725
652
|
...update,
|
|
726
|
-
context
|
|
653
|
+
context
|
|
727
654
|
};
|
|
728
655
|
if (contextUpdate.type === "taskEnd") {
|
|
729
656
|
resultPromise.resolve({
|
|
730
|
-
...
|
|
731
|
-
|
|
732
|
-
return payload.taskId;
|
|
733
|
-
},
|
|
734
|
-
getTaskUrl() {
|
|
735
|
-
return payload.urls?.show ?? "";
|
|
736
|
-
}
|
|
657
|
+
...context,
|
|
658
|
+
taskUrl: payload.urls?.show ?? ""
|
|
737
659
|
});
|
|
738
660
|
}
|
|
739
661
|
if (contextUpdate.type === "taskError") {
|
|
740
|
-
resultPromise.reject(new TaskError(contextUpdate.
|
|
662
|
+
resultPromise.reject(new TaskError(contextUpdate.reason ?? "Task failed", options.taskTemplate));
|
|
741
663
|
}
|
|
742
|
-
|
|
743
|
-
...contextUpdate,
|
|
744
|
-
output: contextUpdate.output === "__default__" ? null : contextUpdate.output,
|
|
745
|
-
data: mapOutput2(contextUpdate.data)
|
|
746
|
-
} : contextUpdate;
|
|
747
|
-
taskUpdateHandlers.forEach((handler) => handler(extendedUpdate));
|
|
664
|
+
taskUpdateHandlers.forEach((handler) => handler(contextUpdate));
|
|
748
665
|
});
|
|
749
666
|
});
|
|
750
667
|
};
|
|
@@ -861,6 +778,7 @@ function watchTasks(options) {
|
|
|
861
778
|
"nodeError",
|
|
862
779
|
"nodeEnd"
|
|
863
780
|
];
|
|
781
|
+
const taskStorage = new Map;
|
|
864
782
|
taskEvents.forEach((taskEvent) => {
|
|
865
783
|
eventSource.addEventListener(taskEvent, (event) => {
|
|
866
784
|
const updateResult = eventSchema.safeParse(event);
|
|
@@ -869,21 +787,61 @@ function watchTasks(options) {
|
|
|
869
787
|
throw new Error("invalid update");
|
|
870
788
|
}
|
|
871
789
|
const update = updateResult.data;
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
790
|
+
if (!taskStorage.has(update.taskId)) {
|
|
791
|
+
taskStorage.set(update.taskId, {
|
|
792
|
+
input: null,
|
|
793
|
+
data: {},
|
|
794
|
+
errors: {},
|
|
795
|
+
result: null,
|
|
796
|
+
incomplete: true
|
|
797
|
+
});
|
|
876
798
|
}
|
|
799
|
+
const storageEntry = taskStorage.get(update.taskId);
|
|
800
|
+
switch (update.type) {
|
|
801
|
+
case "taskStart": {
|
|
802
|
+
storageEntry.input = resolveRequenceTypes(update.input);
|
|
803
|
+
storageEntry.incomplete = false;
|
|
804
|
+
break;
|
|
805
|
+
}
|
|
806
|
+
case "nodeUpdate": {
|
|
807
|
+
if (update.node.alias) {
|
|
808
|
+
storageEntry.data[update.node.alias] = resolveRequenceTypes(update.data);
|
|
809
|
+
}
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
case "nodeError": {
|
|
813
|
+
if (update.node.alias) {
|
|
814
|
+
storageEntry.errors[update.node.alias] = update.error;
|
|
815
|
+
}
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
case "taskEnd": {
|
|
819
|
+
storageEntry.result = resolveRequenceTypes(update.result);
|
|
820
|
+
taskStorage.delete(update.taskId);
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
case "taskError": {
|
|
824
|
+
taskStorage.delete(update.taskId);
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const context = {
|
|
829
|
+
taskId: update.taskId,
|
|
830
|
+
input: storageEntry.input,
|
|
831
|
+
getNodeData(alias) {
|
|
832
|
+
return storageEntry.data[alias] ?? null;
|
|
833
|
+
},
|
|
834
|
+
getNodeError(alias) {
|
|
835
|
+
return storageEntry.errors[alias] ?? null;
|
|
836
|
+
},
|
|
837
|
+
result: storageEntry.result
|
|
838
|
+
};
|
|
877
839
|
const contextUpdate = {
|
|
878
840
|
...update,
|
|
879
|
-
context
|
|
841
|
+
context,
|
|
842
|
+
incomplete: storageEntry.incomplete
|
|
880
843
|
};
|
|
881
|
-
|
|
882
|
-
...contextUpdate,
|
|
883
|
-
output: contextUpdate.output === "__default__" ? null : contextUpdate.output,
|
|
884
|
-
data: mapOutput2(contextUpdate.data)
|
|
885
|
-
} : contextUpdate;
|
|
886
|
-
taskUpdateHandlers.forEach((handler) => handler(extendedUpdate));
|
|
844
|
+
taskUpdateHandlers.forEach((handler) => handler(contextUpdate));
|
|
887
845
|
});
|
|
888
846
|
});
|
|
889
847
|
const stopWatching = () => {
|
|
@@ -899,5 +857,5 @@ export {
|
|
|
899
857
|
RequenceFile
|
|
900
858
|
};
|
|
901
859
|
|
|
902
|
-
//# debugId=
|
|
860
|
+
//# debugId=D44324C24B98459964756E2164756E21
|
|
903
861
|
//# sourceMappingURL=index.js.map
|