@requence/task 1.0.0-alpha.20 → 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.
Files changed (73) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/{chunk-4r30g3ha.js → chunk-y4v98p2s.js} +20 -5
  3. package/build/{chunk-4r30g3ha.js.map → chunk-y4v98p2s.js.map} +2 -2
  4. package/build/cli.js +643 -137
  5. package/build/cli.js.map +27 -16
  6. package/build/index.js +202 -240
  7. package/build/index.js.map +12 -12
  8. package/build/types/helpers/src/files/fileObject.d.ts +16 -0
  9. package/build/types/helpers/src/files/fileObject.d.ts.map +1 -0
  10. package/build/types/helpers/src/files/index.d.ts +2 -43
  11. package/build/types/helpers/src/files/index.d.ts.map +1 -1
  12. package/build/types/helpers/src/files/mapOutput.d.ts +1 -1
  13. package/build/types/helpers/src/files/mapOutput.d.ts.map +1 -1
  14. package/build/types/helpers/src/files/streamObject.d.ts +14 -0
  15. package/build/types/helpers/src/files/streamObject.d.ts.map +1 -0
  16. package/build/types/helpers/src/index.d.ts +1 -0
  17. package/build/types/helpers/src/index.d.ts.map +1 -1
  18. package/build/types/helpers/src/jsonschema/validate.d.ts +1 -0
  19. package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -1
  20. package/build/types/helpers/src/jsonschema/zod.d.ts +4 -12
  21. package/build/types/helpers/src/jsonschema/zod.d.ts.map +1 -1
  22. package/build/types/helpers/src/protocol/NodeTree.d.ts +504 -0
  23. package/build/types/helpers/src/protocol/NodeTree.d.ts.map +1 -0
  24. package/build/types/helpers/src/protocol/NodesError.d.ts +5 -0
  25. package/build/types/helpers/src/protocol/NodesError.d.ts.map +1 -0
  26. package/build/types/helpers/src/protocol/command.d.ts +373 -1954
  27. package/build/types/helpers/src/protocol/command.d.ts.map +1 -1
  28. package/build/types/helpers/src/protocol/index.d.ts +5 -7
  29. package/build/types/helpers/src/protocol/index.d.ts.map +1 -1
  30. package/build/types/helpers/src/protocol/nodeOptions.d.ts +16 -0
  31. package/build/types/helpers/src/protocol/nodeOptions.d.ts.map +1 -0
  32. package/build/types/helpers/src/protocol/nodeType.d.ts +283 -0
  33. package/build/types/helpers/src/protocol/nodeType.d.ts.map +1 -0
  34. package/build/types/helpers/src/protocol/targetNodes.d.ts +253 -0
  35. package/build/types/helpers/src/protocol/targetNodes.d.ts.map +1 -0
  36. package/build/types/helpers/src/protocol/treeNodes.d.ts +606 -0
  37. package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -0
  38. package/build/types/helpers/src/protocol/update.d.ts +182 -17892
  39. package/build/types/helpers/src/protocol/update.d.ts.map +1 -1
  40. package/build/types/helpers/src/utils/mapData.d.ts +4 -0
  41. package/build/types/helpers/src/utils/mapData.d.ts.map +1 -1
  42. package/build/types/helpers/src/utils/matchSchema.d.ts +1 -1
  43. package/build/types/helpers/src/utils/matchSchema.d.ts.map +1 -1
  44. package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts +2 -0
  45. package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts.map +1 -0
  46. package/build/types/helpers/src/utils/types.d.ts +4 -0
  47. package/build/types/helpers/src/utils/types.d.ts.map +1 -0
  48. package/build/types/task/src/createTask.d.ts.map +1 -1
  49. package/build/types/task/src/types.d.ts +114 -5103
  50. package/build/types/task/src/types.d.ts.map +1 -1
  51. package/build/types/task/src/watchTasks.d.ts +3 -1
  52. package/build/types/task/src/watchTasks.d.ts.map +1 -1
  53. package/package.json +2 -2
  54. package/build/types/helpers/src/context/context.d.ts +0 -156
  55. package/build/types/helpers/src/context/context.d.ts.map +0 -1
  56. package/build/types/helpers/src/context/index.d.ts +0 -2
  57. package/build/types/helpers/src/context/index.d.ts.map +0 -1
  58. package/build/types/helpers/src/protocol/createNodeMaps.d.ts +0 -10
  59. package/build/types/helpers/src/protocol/createNodeMaps.d.ts.map +0 -1
  60. package/build/types/helpers/src/protocol/getCycles.d.ts +0 -3
  61. package/build/types/helpers/src/protocol/getCycles.d.ts.map +0 -1
  62. package/build/types/helpers/src/protocol/getNodeOutputs.d.ts +0 -4
  63. package/build/types/helpers/src/protocol/getNodeOutputs.d.ts.map +0 -1
  64. package/build/types/helpers/src/protocol/getPossiblePaths.d.ts +0 -9
  65. package/build/types/helpers/src/protocol/getPossiblePaths.d.ts.map +0 -1
  66. package/build/types/helpers/src/protocol/identifyNode.d.ts +0 -4
  67. package/build/types/helpers/src/protocol/identifyNode.d.ts.map +0 -1
  68. package/build/types/helpers/src/protocol/node.d.ts +0 -1014
  69. package/build/types/helpers/src/protocol/node.d.ts.map +0 -1
  70. package/build/types/helpers/src/protocol/nodes.d.ts +0 -801
  71. package/build/types/helpers/src/protocol/nodes.d.ts.map +0 -1
  72. package/build/types/task/src/utils/mapOutput.d.ts +0 -2
  73. 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-4r30g3ha.js";
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,57 +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 (Array.isArray(data2)) {
100
- return resolve(visitors.Array?.(data2, path), (resolvedData) => {
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);
113
- }
114
- if (typeof Buffer !== "undefined" && Buffer.isBuffer(data2)) {
115
- return notUndefined(visitors.Buffer?.(data2, path), data2);
116
- }
117
- if (typeof data2 === "string") {
118
- return notUndefined(visitors.String?.(data2, path), data2);
103
+ if (aborted) {
104
+ return data2;
119
105
  }
120
- if (typeof data2 === "number") {
121
- return notUndefined(visitors.Number?.(data2, path), data2);
122
- }
123
- if (isRecord(data2)) {
124
- return resolve(visitors.Object?.(data2, path), (resolvedData) => {
125
- if (resolvedData) {
126
- return resolvedData;
127
- }
128
- const entries = Object.entries(data2).map(([key, value]) => [
129
- key,
130
- traverseData(value, [...path, key])
131
- ]);
132
- if (entries.some(([, value]) => value instanceof Promise)) {
133
- return Promise.all(entries.map(([key, value]) => Promise.resolve().then(() => value).then((resolvedValue) => [key, resolvedValue]))).then((entries2) => Object.fromEntries(entries2));
134
- }
135
- return Object.fromEntries(entries);
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
- // ../helpers/src/context/context.ts
144
- import { z as z3 } from "zod";
145
-
146
- // ../helpers/src/files/index.ts
147
- import { z as z2 } from "zod";
161
+ mapData.abort = () => {
162
+ throw new AbortMapData;
163
+ };
148
164
 
149
165
  // ../helpers/src/files/mapOutput.ts
150
166
  async function upload(uploadUrl, body, signal, contentType) {
@@ -251,6 +267,7 @@ async function mapOutput(params) {
251
267
  Promise.allSettled(streamPromises).then(() => params.onDone?.());
252
268
  return mapped;
253
269
  }
270
+
254
271
  // ../helpers/src/files/RequenceFile.ts
255
272
  class RequenceFile {
256
273
  #data;
@@ -309,6 +326,7 @@ class RequenceFile {
309
326
  return `RequenceFile<${this.mimeType}>`;
310
327
  }
311
328
  }
329
+
312
330
  // ../helpers/src/files/RequenceStream.ts
313
331
  class RequenceStream {
314
332
  #data;
@@ -370,47 +388,42 @@ class RequenceStream {
370
388
  }
371
389
  }
372
390
 
373
- // ../helpers/src/files/index.ts
374
- var fileObjectSchema = z2.object({
375
- size: z2.number().int().positive(),
376
- mime: z2.string(),
377
- url: z2.string().url(),
378
- __REQUENCE_type: z2.literal("RequenceFile")
379
- });
380
- function toFileObject(fileInfo) {
381
- return {
382
- ...fileInfo,
383
- __REQUENCE_type: "RequenceFile"
384
- };
385
- }
386
- function isFileObject(data) {
387
- return fileObjectSchema.safeParse(data).success;
388
- }
391
+ // ../helpers/src/files/streamObject.ts
392
+ import { z as z2 } from "zod/v4";
389
393
  var streamObjectSchema = z2.object({
390
394
  mime: z2.string(),
391
395
  url: z2.string().url(),
392
396
  __REQUENCE_type: z2.literal("RequenceStream")
393
397
  });
398
+ function isStreamObject(data) {
399
+ return streamObjectSchema.safeParse(data).success;
400
+ }
394
401
  function toStreamObject(streamInfo) {
395
402
  return {
396
403
  ...streamInfo,
397
404
  __REQUENCE_type: "RequenceStream"
398
405
  };
399
406
  }
400
- function isStreamObject(data) {
401
- return streamObjectSchema.safeParse(data).success;
402
- }
403
407
 
404
- // ../helpers/src/context/context.ts
405
- var contextSchema = z3.object({
406
- input: z3.any(),
407
- meta: z3.any(),
408
- tenant: z3.object({ name: z3.string() }),
409
- data: z3.record(z3.string(), z3.any()),
410
- errors: z3.record(z3.string(), z3.string()),
411
- dates: z3.record(z3.string(), z3.string().datetime())
408
+ // ../helpers/src/files/fileObject.ts
409
+ import { z as z3 } from "zod/v4";
410
+ var fileObjectSchema = z3.object({
411
+ size: z3.number().int().positive(),
412
+ mime: z3.string(),
413
+ url: z3.string().url(),
414
+ __REQUENCE_type: z3.literal("RequenceFile")
412
415
  });
413
- var internalKey = Symbol.for("internal");
416
+ function toFileObject(fileInfo) {
417
+ return {
418
+ ...fileInfo,
419
+ __REQUENCE_type: "RequenceFile"
420
+ };
421
+ }
422
+ function isFileObject(data) {
423
+ return fileObjectSchema.safeParse(data).success;
424
+ }
425
+
426
+ // ../helpers/src/utils/resolveRequenceTypes.ts
414
427
  function resolveRequenceTypes(data) {
415
428
  return mapData(data, {
416
429
  Object(obj) {
@@ -423,81 +436,6 @@ function resolveRequenceTypes(data) {
423
436
  }
424
437
  });
425
438
  }
426
- function createContextHelper(context, nodes) {
427
- const input = resolveRequenceTypes(context.input);
428
- const meta = resolveRequenceTypes(context.meta);
429
- const results = new Map(nodes.map((node) => [
430
- node.id,
431
- {
432
- node,
433
- executionDate: node.id in context.dates ? new Date(context.dates[node.id]) : null,
434
- data: resolveRequenceTypes(context.data[node.id] ?? null),
435
- error: context.errors[node.id] ?? null
436
- }
437
- ]));
438
- const lookUpMap = new Map;
439
- for (const node of nodes) {
440
- const alias = typeof node.meta?.mapAlias === "string" ? node.meta.mapAlias : ("alias" in node) && node.alias;
441
- if (alias) {
442
- if (lookUpMap.has(alias)) {
443
- lookUpMap.get(alias).push(node.id);
444
- } else {
445
- lookUpMap.set(alias, [node.id]);
446
- }
447
- }
448
- const name = typeof node.meta?.mapName === "string" ? node.meta.mapName : node.type === "service" && node.name;
449
- if (name) {
450
- if (lookUpMap.has(name)) {
451
- lookUpMap.get(name).push(node.id);
452
- } else {
453
- lookUpMap.set(name, [node.id]);
454
- }
455
- }
456
- }
457
- return {
458
- [internalKey]: {
459
- results
460
- },
461
- getInput() {
462
- return input;
463
- },
464
- getMeta() {
465
- return meta;
466
- },
467
- getData(alias) {
468
- if (alias) {
469
- const nodeIds = lookUpMap.get(alias);
470
- if (!nodeIds) {
471
- return null;
472
- }
473
- const uniqueNodeIds = Array.from(new Set(nodeIds));
474
- const combinedData = uniqueNodeIds.map((nodeId) => results.get(nodeId)?.data).filter(Boolean);
475
- if (combinedData.length === 0) {
476
- return null;
477
- }
478
- if (combinedData.length === 1) {
479
- return combinedData[0];
480
- }
481
- if (combinedData.every(isRecord)) {
482
- return combinedData.reduce((acc, data) => ({ ...acc, ...data }), {});
483
- }
484
- return combinedData;
485
- }
486
- return Array.from(results.values()).filter((result) => result.executionDate && isRecord(result.data)).toSorted((a, b) => a.executionDate.getTime() - b.executionDate.getTime()).reduce((acc, result) => ({
487
- ...acc,
488
- ...result.data
489
- }), isRecord(input) ? input : {});
490
- },
491
- getError(alias) {
492
- const nodeIds = lookUpMap.get(alias);
493
- if (!nodeIds) {
494
- return null;
495
- }
496
- return nodeIds.map((nodeId) => results.get(nodeId)?.error).filter((str) => typeof str === "string").join(`
497
- `);
498
- }
499
- };
500
- }
501
439
 
502
440
  // src/createTask.ts
503
441
  import { EventSource } from "eventsource";
@@ -550,45 +488,28 @@ async function abortTask(options) {
550
488
  }
551
489
 
552
490
  // src/types.ts
553
- import { z as z4 } from "zod";
554
- var serviceNodeInfoSchema = z4.object({
555
- id: z4.string().uuid(),
491
+ import { z as z4 } from "zod/v4";
492
+ var nodeInfoSchema = z4.object({
493
+ id: z4.uuid(),
556
494
  type: z4.literal("service"),
557
- alias: z4.string().optional(),
558
- service: z4.object({
559
- id: z4.string().uuid(),
560
- name: z4.string(),
561
- version: z4.string()
562
- }).optional()
563
- });
564
- var logicNodeInfoSchema = z4.object({
565
- id: z4.string().uuid(),
566
- type: z4.literal("logic"),
567
- alias: z4.string().optional(),
568
- logic: z4.object({
569
- language: z4.enum(["typescript", "javascript", "python"])
570
- }).optional()
495
+ alias: z4.string().optional()
571
496
  });
572
- var nodeInfoSchema = z4.discriminatedUnion("type", [
573
- serviceNodeInfoSchema,
574
- logicNodeInfoSchema
575
- ]);
576
497
  var baseUpdate = z4.object({
577
498
  timestamp: z4.coerce.date(),
578
- taskId: z4.string().uuid(),
579
- updateId: z4.string().uuid(),
580
- context: contextSchema,
581
- nodes: z4.custom((data) => Array.isArray(data))
499
+ taskId: z4.uuid(),
500
+ updateId: z4.uuid()
582
501
  });
583
502
  var taskStartUpdateSchema = baseUpdate.extend({
584
- type: z4.literal("taskStart")
503
+ type: z4.literal("taskStart"),
504
+ input: z4.unknown()
585
505
  });
586
506
  var taskErrorUpdateSchema = baseUpdate.extend({
587
507
  type: z4.literal("taskError"),
588
- error: z4.string()
508
+ reason: z4.string().optional()
589
509
  });
590
510
  var taskEndUpdateSchema = baseUpdate.extend({
591
- type: z4.literal("taskEnd")
511
+ type: z4.literal("taskEnd"),
512
+ result: z4.record(z4.string(), z4.any())
592
513
  });
593
514
  var nodeStartUpdateSchema = baseUpdate.extend({
594
515
  type: z4.literal("nodeStart"),
@@ -626,20 +547,6 @@ var updateSchema = z4.discriminatedUnion("type", [
626
547
  ]);
627
548
  var eventSchema = z4.object({ type: z4.string(), data: z4.string() }).transform((event) => ({ type: event.type, ...JSON.parse(event.data) })).pipe(updateSchema);
628
549
 
629
- // src/utils/mapOutput.ts
630
- function mapOutput3(data) {
631
- return mapData(data, {
632
- Object(obj) {
633
- if (isFileObject(obj)) {
634
- return RequenceFile.fromFileObject(obj);
635
- }
636
- if (isStreamObject(obj)) {
637
- return RequenceStream.fromStreamObject(obj);
638
- }
639
- }
640
- });
641
- }
642
-
643
550
  // src/createTask.ts
644
551
  class TaskError extends Error {
645
552
  taskTemplate;
@@ -662,23 +569,15 @@ function createTask(options, onUpdate) {
662
569
  const payload = await payloadPromise;
663
570
  if (!payload.urls) {
664
571
  resultPromise.resolve({
665
- getInput() {
666
- return options.input;
667
- },
668
- getMeta() {
669
- return options.meta;
670
- },
671
- getError(_alias) {
572
+ input: options.input,
573
+ taskId: payload.taskId,
574
+ taskUrl: "",
575
+ result: null,
576
+ getNodeData(_alias) {
672
577
  return null;
673
578
  },
674
- getData(_alias) {
579
+ getNodeError(_alias) {
675
580
  return null;
676
- },
677
- getTaskId() {
678
- return payload.taskId;
679
- },
680
- getTaskUrl() {
681
- return "";
682
581
  }
683
582
  });
684
583
  return;
@@ -701,6 +600,7 @@ function createTask(options, onUpdate) {
701
600
  "nodeError",
702
601
  "nodeEnd"
703
602
  ];
603
+ const taskStorage = { input: null, data: {}, errors: {}, result: null };
704
604
  taskEvents.forEach((taskEvent) => {
705
605
  eventSource.addEventListener(taskEvent, (event) => {
706
606
  const updateResult = eventSchema.safeParse(event);
@@ -710,43 +610,64 @@ function createTask(options, onUpdate) {
710
610
  return;
711
611
  }
712
612
  const update = updateResult.data;
713
- if (update.type === "taskEnd" || update.type === "taskError") {
714
- eventSource.close();
715
- }
716
- const context = update.context;
717
- if (update.type === "nodeUpdate") {
718
- context.dates[update.node.id] = update.timestamp.toISOString();
719
- context.data[update.node.id] = update.data;
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
+ }
720
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
+ };
721
651
  const contextUpdate = {
722
652
  ...update,
723
- context: createContextHelper(context, update.nodes)
653
+ context
724
654
  };
725
655
  if (contextUpdate.type === "taskEnd") {
726
656
  resultPromise.resolve({
727
- ...contextUpdate.context,
728
- getTaskId() {
729
- return payload.taskId;
730
- },
731
- getTaskUrl() {
732
- return payload.urls?.show ?? "";
733
- }
657
+ ...context,
658
+ taskUrl: payload.urls?.show ?? ""
734
659
  });
735
660
  }
736
661
  if (contextUpdate.type === "taskError") {
737
- resultPromise.reject(new TaskError(contextUpdate.error, options.taskTemplate));
662
+ resultPromise.reject(new TaskError(contextUpdate.reason ?? "Task failed", options.taskTemplate));
738
663
  }
739
- const extendedUpdate = contextUpdate.type === "nodeUpdate" ? {
740
- ...contextUpdate,
741
- output: contextUpdate.output === "__default__" ? null : contextUpdate.output,
742
- data: mapOutput3(contextUpdate.data)
743
- } : contextUpdate;
744
- taskUpdateHandlers.forEach((handler) => handler(extendedUpdate));
664
+ taskUpdateHandlers.forEach((handler) => handler(contextUpdate));
745
665
  });
746
666
  });
747
667
  };
748
668
  const taskMetaPromise = createRemotePromise();
749
669
  const resultPromise = createRemotePromise(startMonitoring);
670
+ taskMetaPromise.catch(() => {});
750
671
  (async () => {
751
672
  const prepareResponse = await fetch(prepareUrl, {
752
673
  method: "POST",
@@ -857,6 +778,7 @@ function watchTasks(options) {
857
778
  "nodeError",
858
779
  "nodeEnd"
859
780
  ];
781
+ const taskStorage = new Map;
860
782
  taskEvents.forEach((taskEvent) => {
861
783
  eventSource.addEventListener(taskEvent, (event) => {
862
784
  const updateResult = eventSchema.safeParse(event);
@@ -865,21 +787,61 @@ function watchTasks(options) {
865
787
  throw new Error("invalid update");
866
788
  }
867
789
  const update = updateResult.data;
868
- const context = update.context;
869
- if (update.type === "nodeUpdate") {
870
- context.dates[update.node.id] = update.timestamp.toISOString();
871
- context.data[update.node.id] = update.data;
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
+ });
872
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
+ };
873
839
  const contextUpdate = {
874
840
  ...update,
875
- context: createContextHelper(context, update.nodes)
841
+ context,
842
+ incomplete: storageEntry.incomplete
876
843
  };
877
- const extendedUpdate = contextUpdate.type === "nodeUpdate" ? {
878
- ...contextUpdate,
879
- output: contextUpdate.output === "__default__" ? null : contextUpdate.output,
880
- data: mapOutput3(contextUpdate.data)
881
- } : contextUpdate;
882
- taskUpdateHandlers.forEach((handler) => handler(extendedUpdate));
844
+ taskUpdateHandlers.forEach((handler) => handler(contextUpdate));
883
845
  });
884
846
  });
885
847
  const stopWatching = () => {
@@ -895,5 +857,5 @@ export {
895
857
  RequenceFile
896
858
  };
897
859
 
898
- //# debugId=1ABBB576345EB61164756E2164756E21
860
+ //# debugId=D44324C24B98459964756E2164756E21
899
861
  //# sourceMappingURL=index.js.map