@cadenza.io/core 3.15.4 → 3.15.8

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/dist/index.d.mts CHANGED
@@ -46,17 +46,6 @@ declare class GraphContext {
46
46
  * @returns Frozen metadata object.
47
47
  */
48
48
  getMetadata(): AnyObject;
49
- /**
50
- * Clones this context (new instance).
51
- * @returns New GraphContext.
52
- */
53
- clone(): GraphContext;
54
- /**
55
- * Creates new context from data (via registry).
56
- * @param context New data.
57
- * @returns New GraphContext.
58
- */
59
- mutate(context: AnyObject): GraphContext;
60
49
  /**
61
50
  * Combines the current GraphContext with another GraphContext, merging their user data
62
51
  * and full context into a new GraphContext instance.
@@ -814,7 +803,6 @@ declare class Task extends SignalEmitter implements Graph {
814
803
  layerIndex: number;
815
804
  progressWeight: number;
816
805
  nextTasks: Set<Task>;
817
- onFailTasks: Set<Task>;
818
806
  predecessorTasks: Set<Task>;
819
807
  destroyed: boolean;
820
808
  register: boolean;
@@ -989,10 +977,9 @@ declare class Task extends SignalEmitter implements Graph {
989
977
  * Maps over the next set of tasks or failed tasks if specified, applying the provided callback function.
990
978
  *
991
979
  * @param {Function} callback A function that will be called with each task, transforming the task as needed. It receives a single parameter of type Task.
992
- * @param {boolean} [failed=false] A boolean that determines whether to map over the failed tasks (true) or the next tasks (false).
993
980
  * @return {any[]} An array of transformed tasks resulting from applying the callback function.
994
981
  */
995
- mapNext(callback: (task: Task) => any, failed?: boolean): any[];
982
+ mapNext(callback: (task: Task) => any): any[];
996
983
  /**
997
984
  * Maps through each task in the set of predecessor tasks and applies the provided callback function.
998
985
  *
@@ -1527,12 +1514,6 @@ declare class SignalBroker {
1527
1514
  * @return {void} This method does not return any value.
1528
1515
  */
1529
1516
  addSignal(signal: string): void;
1530
- /**
1531
- * Lists all observed signals.
1532
- * @returns Array of signals.
1533
- */
1534
- listObservedSignals(): string[];
1535
- listEmittedSignals(): string[];
1536
1517
  reset(): void;
1537
1518
  }
1538
1519
 
package/dist/index.d.ts CHANGED
@@ -46,17 +46,6 @@ declare class GraphContext {
46
46
  * @returns Frozen metadata object.
47
47
  */
48
48
  getMetadata(): AnyObject;
49
- /**
50
- * Clones this context (new instance).
51
- * @returns New GraphContext.
52
- */
53
- clone(): GraphContext;
54
- /**
55
- * Creates new context from data (via registry).
56
- * @param context New data.
57
- * @returns New GraphContext.
58
- */
59
- mutate(context: AnyObject): GraphContext;
60
49
  /**
61
50
  * Combines the current GraphContext with another GraphContext, merging their user data
62
51
  * and full context into a new GraphContext instance.
@@ -814,7 +803,6 @@ declare class Task extends SignalEmitter implements Graph {
814
803
  layerIndex: number;
815
804
  progressWeight: number;
816
805
  nextTasks: Set<Task>;
817
- onFailTasks: Set<Task>;
818
806
  predecessorTasks: Set<Task>;
819
807
  destroyed: boolean;
820
808
  register: boolean;
@@ -989,10 +977,9 @@ declare class Task extends SignalEmitter implements Graph {
989
977
  * Maps over the next set of tasks or failed tasks if specified, applying the provided callback function.
990
978
  *
991
979
  * @param {Function} callback A function that will be called with each task, transforming the task as needed. It receives a single parameter of type Task.
992
- * @param {boolean} [failed=false] A boolean that determines whether to map over the failed tasks (true) or the next tasks (false).
993
980
  * @return {any[]} An array of transformed tasks resulting from applying the callback function.
994
981
  */
995
- mapNext(callback: (task: Task) => any, failed?: boolean): any[];
982
+ mapNext(callback: (task: Task) => any): any[];
996
983
  /**
997
984
  * Maps through each task in the set of predecessor tasks and applies the provided callback function.
998
985
  *
@@ -1527,12 +1514,6 @@ declare class SignalBroker {
1527
1514
  * @return {void} This method does not return any value.
1528
1515
  */
1529
1516
  addSignal(signal: string): void;
1530
- /**
1531
- * Lists all observed signals.
1532
- * @returns Array of signals.
1533
- */
1534
- listObservedSignals(): string[];
1535
- listEmittedSignals(): string[];
1536
1517
  reset(): void;
1537
1518
  }
1538
1519
 
package/dist/index.js CHANGED
@@ -361,9 +361,12 @@ var SignalBroker = class _SignalBroker {
361
361
  */
362
362
  init() {
363
363
  this.getSignalsTask = Cadenza.createMetaTask("Get signals", (ctx) => {
364
- const uniqueSignals = Array.from(this.signalObservers.keys()).filter(
365
- (s) => !s.includes(":")
366
- );
364
+ const uniqueSignals = Array.from(
365
+ /* @__PURE__ */ new Set([
366
+ ...this.signalObservers.keys(),
367
+ ...this.emittedSignalsRegistry
368
+ ])
369
+ ).filter((s) => !s.includes(":"));
367
370
  const processedSignals = uniqueSignals.map((signal) => ({
368
371
  signal,
369
372
  data: {
@@ -654,16 +657,6 @@ var SignalBroker = class _SignalBroker {
654
657
  this.emit("meta.signal_broker.added", { signalName: _signal });
655
658
  }
656
659
  }
657
- /**
658
- * Lists all observed signals.
659
- * @returns Array of signals.
660
- */
661
- listObservedSignals() {
662
- return Array.from(this.signalObservers.keys());
663
- }
664
- listEmittedSignals() {
665
- return Array.from(this.emittedSignalsRegistry);
666
- }
667
660
  reset() {
668
661
  this.signalObservers.clear();
669
662
  this.emittedSignalsRegistry.clear();
@@ -975,21 +968,6 @@ var GraphContext = class _GraphContext {
975
968
  getMetadata() {
976
969
  return this.metadata;
977
970
  }
978
- /**
979
- * Clones this context (new instance).
980
- * @returns New GraphContext.
981
- */
982
- clone() {
983
- return this.mutate(this.fullContext);
984
- }
985
- /**
986
- * Creates new context from data (via registry).
987
- * @param context New data.
988
- * @returns New GraphContext.
989
- */
990
- mutate(context) {
991
- return new _GraphContext(context);
992
- }
993
971
  /**
994
972
  * Combines the current GraphContext with another GraphContext, merging their user data
995
973
  * and full context into a new GraphContext instance.
@@ -1231,18 +1209,27 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1231
1209
  this.layer = layer;
1232
1210
  layer.add(this);
1233
1211
  const context = this.context.getFullContext();
1212
+ let signalEmissionId = context.__signalEmissionId ?? null;
1213
+ delete context.__signalEmissionId;
1214
+ if (context.__signalEmission?.consumed === false && (!this.isMeta() || this.debug)) {
1215
+ signalEmissionId = context.__signalEmission.uuid;
1216
+ context.__signalEmission.consumed = true;
1217
+ context.__signalEmission.consumedBy = this.id;
1218
+ }
1234
1219
  const scheduledAt = Date.now();
1235
1220
  this.emitMetricsWithMetadata("meta.node.scheduled", {
1236
1221
  data: {
1237
1222
  uuid: this.id,
1238
1223
  routineExecutionId: this.routineExecId,
1239
1224
  executionTraceId: this.executionTraceId,
1240
- context: this.previousNodes.length === 0 ? this.context.id : this.context.export(),
1225
+ context: this.context.getContext(),
1226
+ metaContext: this.context.getMetadata(),
1241
1227
  taskName: this.task.name,
1242
1228
  taskVersion: this.task.version,
1243
1229
  isMeta: this.isMeta(),
1244
1230
  isScheduled: true,
1245
1231
  splitGroupId: this.splitGroupId,
1232
+ signalEmissionId,
1246
1233
  created: formatTimestamp(scheduledAt)
1247
1234
  }
1248
1235
  });
@@ -1270,30 +1257,14 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1270
1257
  },
1271
1258
  filter: {
1272
1259
  taskName: this.task.name,
1273
- taskVersion: this.task.version
1274
- },
1275
- ...context
1260
+ taskVersion: this.task.version,
1261
+ predecessorTaskName: context.__localTaskName,
1262
+ predecessorTaskVersion: context.__localTaskVersion
1263
+ }
1276
1264
  }
1277
1265
  );
1278
1266
  context.__previousTaskExecutionId = null;
1279
1267
  }
1280
- if (context.__signalEmission?.consumed === false && (!this.isMeta() || this.debug)) {
1281
- this.emitMetricsWithMetadata("meta.node.consumed_signal", {
1282
- data: {
1283
- signalEmissionId: context.__signalEmission.uuid,
1284
- signalName: context.__signalEmission.signalName,
1285
- signalTag: context.__signalEmission.signalTag,
1286
- taskName: this.task.name,
1287
- taskVersion: this.task.version,
1288
- taskExecutionId: this.id,
1289
- routineExecutionId: this.routineExecId,
1290
- executionTraceId: this.executionTraceId,
1291
- consumedAt: formatTimestamp(scheduledAt)
1292
- }
1293
- });
1294
- context.__signalEmission.consumed = true;
1295
- context.__signalEmission.consumedBy = this.id;
1296
- }
1297
1268
  }
1298
1269
  }
1299
1270
  /**
@@ -1363,7 +1334,8 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1363
1334
  data: {
1364
1335
  isRunning: false,
1365
1336
  isComplete: true,
1366
- resultContext: this.context.export(),
1337
+ resultContext: this.context.getContext(),
1338
+ metaResultContext: this.context.getMetadata(),
1367
1339
  errored: this.errored,
1368
1340
  failed: this.failed,
1369
1341
  errorMessage: context.__error,
@@ -1373,17 +1345,18 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1373
1345
  filter: { uuid: this.id }
1374
1346
  });
1375
1347
  if (this.graphDone()) {
1376
- const context2 = this.context.export();
1377
- if (context2.context.__isDeputy)
1348
+ const context2 = this.context.getFullContext();
1349
+ if (context2.__isDeputy)
1378
1350
  this.emitWithMetadata(
1379
1351
  `meta.node.graph_completed:${this.routineExecId}`,
1380
- context2.context
1352
+ context2
1381
1353
  );
1382
1354
  this.emitMetricsWithMetadata("meta.node.ended_routine_execution", {
1383
1355
  data: {
1384
1356
  isRunning: false,
1385
1357
  isComplete: true,
1386
- resultContext: this.context.id,
1358
+ resultContext: this.context.getContext(),
1359
+ metaResultContext: this.context.getMetadata(),
1387
1360
  progress: 1,
1388
1361
  ended: formatTimestamp(end)
1389
1362
  },
@@ -1747,14 +1720,6 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1747
1720
  return newNodes;
1748
1721
  }
1749
1722
  }
1750
- if (this.errored) {
1751
- newNodes.push(
1752
- ...this.task.mapNext(
1753
- (t) => this.clone().split((0, import_uuid4.v4)()).differentiate(t).migrate({ ...this.result }),
1754
- true
1755
- )
1756
- );
1757
- }
1758
1723
  this.divided = true;
1759
1724
  this.migrate({
1760
1725
  ...this.context.getFullContext(),
@@ -1802,19 +1767,20 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1802
1767
  const groupId = (0, import_uuid4.v4)();
1803
1768
  const newNodes = [];
1804
1769
  if (typeof result !== "boolean") {
1805
- const failed = result.failed !== void 0 && result.failed || result.error !== void 0;
1806
- newNodes.push(
1807
- ...this.task.mapNext((t) => {
1808
- const context = t.isUnique ? {
1809
- joinedContexts: [
1810
- { ...result, taskName: this.task.name, __nodeId: this.id }
1811
- ],
1812
- ...this.context.getMetadata()
1813
- } : { ...result, ...this.context.getMetadata() };
1814
- return this.clone().split(groupId).differentiate(t).migrate(context);
1815
- }, failed)
1816
- );
1817
- this.failed = failed;
1770
+ this.failed = result.failed !== void 0 && result.failed || result.error !== void 0;
1771
+ if (!this.failed) {
1772
+ newNodes.push(
1773
+ ...this.task.mapNext((t) => {
1774
+ const context = t.isUnique ? {
1775
+ joinedContexts: [
1776
+ { ...result, taskName: this.task.name, __nodeId: this.id }
1777
+ ],
1778
+ ...this.context.getMetadata()
1779
+ } : { ...result, ...this.context.getMetadata() };
1780
+ return this.clone().split(groupId).differentiate(t).migrate(context);
1781
+ })
1782
+ );
1783
+ }
1818
1784
  } else {
1819
1785
  const shouldContinue = result;
1820
1786
  if (shouldContinue) {
@@ -2231,7 +2197,6 @@ var GraphRunner = class extends SignalEmitter {
2231
2197
  context.__routineExecId = routineExecId;
2232
2198
  const ctx = new GraphContext(context || {});
2233
2199
  if (!isSubMeta) {
2234
- const contextData = ctx.export();
2235
2200
  if (isNewTrace) {
2236
2201
  this.emitMetrics("meta.runner.new_trace", {
2237
2202
  data: {
@@ -2241,7 +2206,8 @@ var GraphRunner = class extends SignalEmitter {
2241
2206
  issuer_id: context.__metadata?.__issuerId ?? context.__issuerId ?? null,
2242
2207
  issued_at: formatTimestamp(Date.now()),
2243
2208
  intent: context.__metadata?.__intent ?? context.__intent ?? null,
2244
- context: contextData,
2209
+ context: ctx.getContext(),
2210
+ metaContext: ctx.getMetadata(),
2245
2211
  is_meta: isMeta
2246
2212
  },
2247
2213
  __metadata: {
@@ -2256,7 +2222,8 @@ var GraphRunner = class extends SignalEmitter {
2256
2222
  routineVersion,
2257
2223
  isMeta,
2258
2224
  executionTraceId,
2259
- context: isNewTrace ? contextData.id : contextData,
2225
+ context: ctx.getContext(),
2226
+ metaContext: ctx.getMetadata(),
2260
2227
  previousRoutineExecution: context.__localRoutineExecId ?? context.__metadata?.__routineExecId ?? null,
2261
2228
  created: formatTimestamp(Date.now())
2262
2229
  },
@@ -2427,7 +2394,6 @@ var Task = class _Task extends SignalEmitter {
2427
2394
  this.layerIndex = 0;
2428
2395
  this.progressWeight = 0;
2429
2396
  this.nextTasks = /* @__PURE__ */ new Set();
2430
- this.onFailTasks = /* @__PURE__ */ new Set();
2431
2397
  this.predecessorTasks = /* @__PURE__ */ new Set();
2432
2398
  this.destroyed = false;
2433
2399
  this.register = true;
@@ -2508,9 +2474,13 @@ var Task = class _Task extends SignalEmitter {
2508
2474
  isMeta: this.isMeta,
2509
2475
  isSubMeta: this.isSubMeta,
2510
2476
  validateInputContext: this.validateInputContext,
2511
- validateOutputContext: this.validateOutputContext
2477
+ validateOutputContext: this.validateOutputContext,
2512
2478
  // inputContextSchemaId: this.inputContextSchema,
2513
2479
  // outputContextSchemaId: this.outputContextSchema,
2480
+ emitsSignals: Array.from(this.emitsSignals),
2481
+ signalsToEmitAfter: Array.from(this.signalsToEmitAfter),
2482
+ signalsToEmitOnFail: Array.from(this.signalsToEmitOnFail),
2483
+ observesSignals: Array.from(this.observedSignals)
2514
2484
  },
2515
2485
  taskInstance: this,
2516
2486
  __isSubMeta: this.isSubMeta
@@ -2886,10 +2856,6 @@ var Task = class _Task extends SignalEmitter {
2886
2856
  task.nextTasks.delete(this);
2887
2857
  this.predecessorTasks.delete(task);
2888
2858
  }
2889
- if (task.onFailTasks.has(this)) {
2890
- task.onFailTasks.delete(this);
2891
- this.predecessorTasks.delete(task);
2892
- }
2893
2859
  this.updateLayerFromPredecessors();
2894
2860
  }
2895
2861
  /**
@@ -2988,11 +2954,10 @@ var Task = class _Task extends SignalEmitter {
2988
2954
  * Maps over the next set of tasks or failed tasks if specified, applying the provided callback function.
2989
2955
  *
2990
2956
  * @param {Function} callback A function that will be called with each task, transforming the task as needed. It receives a single parameter of type Task.
2991
- * @param {boolean} [failed=false] A boolean that determines whether to map over the failed tasks (true) or the next tasks (false).
2992
2957
  * @return {any[]} An array of transformed tasks resulting from applying the callback function.
2993
2958
  */
2994
- mapNext(callback, failed = false) {
2995
- const tasks = failed ? Array.from(this.onFailTasks) : Array.from(this.nextTasks);
2959
+ mapNext(callback) {
2960
+ const tasks = Array.from(this.nextTasks);
2996
2961
  return tasks.map(callback);
2997
2962
  }
2998
2963
  /**
@@ -3079,13 +3044,20 @@ var Task = class _Task extends SignalEmitter {
3079
3044
  this.emitsSignals.add(signal);
3080
3045
  Cadenza.broker.registerEmittedSignal(signal);
3081
3046
  if (this.register) {
3082
- const isOnFail = this.signalsToEmitOnFail.has(signal);
3047
+ const data = {
3048
+ emitsSignals: Array.from(this.emitsSignals)
3049
+ };
3050
+ if (this.signalsToEmitAfter.has(signal)) {
3051
+ data.emitsSignalsAfter = Array.from(this.signalsToEmitAfter);
3052
+ }
3053
+ if (this.signalsToEmitOnFail.has(signal)) {
3054
+ data.emitsSignalsOnFail = Array.from(this.signalsToEmitOnFail);
3055
+ }
3083
3056
  this.emitWithMetadata("meta.task.attached_signal", {
3084
- data: {
3085
- signalName: signal.split(":")[0],
3086
- taskName: this.name,
3087
- taskVersion: this.version,
3088
- isOnFail
3057
+ data,
3058
+ filter: {
3059
+ name: this.name,
3060
+ version: this.version
3089
3061
  }
3090
3062
  });
3091
3063
  }
@@ -3232,10 +3204,8 @@ var Task = class _Task extends SignalEmitter {
3232
3204
  this.detachAllSignals();
3233
3205
  this.predecessorTasks.forEach((pred) => pred.nextTasks.delete(this));
3234
3206
  this.nextTasks.forEach((next) => next.predecessorTasks.delete(this));
3235
- this.onFailTasks.forEach((fail) => fail.predecessorTasks.delete(this));
3236
3207
  this.nextTasks.clear();
3237
3208
  this.predecessorTasks.clear();
3238
- this.onFailTasks.clear();
3239
3209
  this.destroyed = true;
3240
3210
  if (this.register) {
3241
3211
  this.emitMetricsWithMetadata("meta.task.destroyed", {
@@ -3278,7 +3248,6 @@ var Task = class _Task extends SignalEmitter {
3278
3248
  __outputSchema: this.outputContextSchema,
3279
3249
  __validateOutputContext: this.validateOutputContext,
3280
3250
  __nextTasks: Array.from(this.nextTasks).map((t) => t.name),
3281
- __onFailTasks: Array.from(this.onFailTasks).map((t) => t.name),
3282
3251
  __previousTasks: Array.from(this.predecessorTasks).map((t) => t.name)
3283
3252
  };
3284
3253
  }