@cadenza.io/core 3.12.4 → 3.13.0
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 +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +74 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -424,7 +424,7 @@ var SignalBroker = class _SignalBroker {
|
|
|
424
424
|
};
|
|
425
425
|
|
|
426
426
|
// src/engine/GraphRunner.ts
|
|
427
|
-
import { v4 as
|
|
427
|
+
import { v4 as uuid6 } from "uuid";
|
|
428
428
|
|
|
429
429
|
// src/engine/GraphRun.ts
|
|
430
430
|
import { v4 as uuid2 } from "uuid";
|
|
@@ -1279,6 +1279,9 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
1279
1279
|
};
|
|
1280
1280
|
}
|
|
1281
1281
|
this.emit(signal, data);
|
|
1282
|
+
if (!this.task.emitsSignals.has(signal)) {
|
|
1283
|
+
this.task.attachSignal(signal);
|
|
1284
|
+
}
|
|
1282
1285
|
}
|
|
1283
1286
|
/**
|
|
1284
1287
|
* Emits metrics with additional metadata describing the task execution and context.
|
|
@@ -1304,6 +1307,9 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
1304
1307
|
};
|
|
1305
1308
|
}
|
|
1306
1309
|
this.emitMetrics(signal, data);
|
|
1310
|
+
if (!this.task.emitsSignals.has(signal)) {
|
|
1311
|
+
this.task.attachSignal(signal);
|
|
1312
|
+
}
|
|
1307
1313
|
}
|
|
1308
1314
|
/**
|
|
1309
1315
|
* Updates the progress of a task and emits metrics with associated metadata.
|
|
@@ -1923,6 +1929,9 @@ var GraphRoutine = class extends SignalEmitter {
|
|
|
1923
1929
|
}
|
|
1924
1930
|
};
|
|
1925
1931
|
|
|
1932
|
+
// src/graph/definition/Task.ts
|
|
1933
|
+
import { v4 as uuid5 } from "uuid";
|
|
1934
|
+
|
|
1926
1935
|
// src/graph/iterators/TaskIterator.ts
|
|
1927
1936
|
var TaskIterator = class {
|
|
1928
1937
|
constructor(task) {
|
|
@@ -1955,7 +1964,7 @@ var TaskIterator = class {
|
|
|
1955
1964
|
};
|
|
1956
1965
|
|
|
1957
1966
|
// src/graph/definition/Task.ts
|
|
1958
|
-
var Task = class extends SignalEmitter {
|
|
1967
|
+
var Task = class _Task extends SignalEmitter {
|
|
1959
1968
|
/**
|
|
1960
1969
|
* Constructs an instance of the task with the specified properties and configuration options.
|
|
1961
1970
|
*
|
|
@@ -2007,12 +2016,14 @@ var Task = class extends SignalEmitter {
|
|
|
2007
2016
|
this.destroyed = false;
|
|
2008
2017
|
this.register = true;
|
|
2009
2018
|
this.registered = false;
|
|
2019
|
+
this.registeredSignals = /* @__PURE__ */ new Set();
|
|
2020
|
+
this.taskMapRegistration = /* @__PURE__ */ new Set();
|
|
2010
2021
|
this.emitsSignals = /* @__PURE__ */ new Set();
|
|
2011
2022
|
this.signalsToEmitAfter = /* @__PURE__ */ new Set();
|
|
2012
2023
|
this.signalsToEmitOnFail = /* @__PURE__ */ new Set();
|
|
2013
2024
|
this.observedSignals = /* @__PURE__ */ new Set();
|
|
2014
2025
|
this.name = name;
|
|
2015
|
-
this.taskFunction = task
|
|
2026
|
+
this.taskFunction = task;
|
|
2016
2027
|
this.description = description;
|
|
2017
2028
|
this.concurrency = concurrency;
|
|
2018
2029
|
this.timeout = timeout;
|
|
@@ -2066,6 +2077,41 @@ var Task = class extends SignalEmitter {
|
|
|
2066
2077
|
});
|
|
2067
2078
|
}
|
|
2068
2079
|
}
|
|
2080
|
+
clone(traverse = false, includeSignals = false) {
|
|
2081
|
+
const clonedTask = new _Task(
|
|
2082
|
+
`${this.name} (clone ${uuid5().slice(0, 8)})`,
|
|
2083
|
+
this.taskFunction,
|
|
2084
|
+
this.description,
|
|
2085
|
+
this.concurrency,
|
|
2086
|
+
this.timeout,
|
|
2087
|
+
this.register,
|
|
2088
|
+
this.isUnique,
|
|
2089
|
+
this.isMeta,
|
|
2090
|
+
this.isSubMeta,
|
|
2091
|
+
this.isHidden,
|
|
2092
|
+
this.getTag,
|
|
2093
|
+
this.inputContextSchema,
|
|
2094
|
+
this.validateInputContext,
|
|
2095
|
+
this.outputContextSchema,
|
|
2096
|
+
this.validateOutputContext,
|
|
2097
|
+
this.retryCount,
|
|
2098
|
+
this.retryDelay,
|
|
2099
|
+
this.retryDelayMax,
|
|
2100
|
+
this.retryDelayFactor
|
|
2101
|
+
);
|
|
2102
|
+
if (includeSignals) {
|
|
2103
|
+
clonedTask.doOn(...this.observedSignals);
|
|
2104
|
+
clonedTask.emits(...this.signalsToEmitAfter);
|
|
2105
|
+
clonedTask.emitsOnFail(...this.signalsToEmitOnFail);
|
|
2106
|
+
clonedTask.emitsSignals = new Set(Array.from(this.emitsSignals));
|
|
2107
|
+
}
|
|
2108
|
+
if (traverse) {
|
|
2109
|
+
this.mapNext((t) => {
|
|
2110
|
+
clonedTask.then(t.clone(traverse, includeSignals));
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
return clonedTask;
|
|
2114
|
+
}
|
|
2069
2115
|
/**
|
|
2070
2116
|
* Retrieves the tag associated with the instance.
|
|
2071
2117
|
* Can be overridden by subclasses.
|
|
@@ -2527,6 +2573,10 @@ var Task = class extends SignalEmitter {
|
|
|
2527
2573
|
doOn(...signals) {
|
|
2528
2574
|
signals.forEach((signal) => {
|
|
2529
2575
|
if (this.observedSignals.has(signal)) return;
|
|
2576
|
+
if (this.emitsSignals.has(signal))
|
|
2577
|
+
throw new Error(
|
|
2578
|
+
`Detected signal loop for task ${this.name}. Signal name: ${signal}`
|
|
2579
|
+
);
|
|
2530
2580
|
Cadenza.broker.observe(signal, this);
|
|
2531
2581
|
this.observedSignals.add(signal);
|
|
2532
2582
|
if (this.register) {
|
|
@@ -2549,6 +2599,10 @@ var Task = class extends SignalEmitter {
|
|
|
2549
2599
|
*/
|
|
2550
2600
|
emits(...signals) {
|
|
2551
2601
|
signals.forEach((signal) => {
|
|
2602
|
+
if (this.observedSignals.has(signal))
|
|
2603
|
+
throw new Error(
|
|
2604
|
+
`Detected signal loop for task ${this.name}. Signal name: ${signal}`
|
|
2605
|
+
);
|
|
2552
2606
|
this.signalsToEmitAfter.add(signal);
|
|
2553
2607
|
this.attachSignal(signal);
|
|
2554
2608
|
});
|
|
@@ -3027,9 +3081,9 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
3027
3081
|
const isSubMeta = allTasks.some((t) => t.isSubMeta) || !!context.__isSubMeta;
|
|
3028
3082
|
context.__isSubMeta = isSubMeta;
|
|
3029
3083
|
const isNewTrace = !context.__routineExecId && !context.__metadata?.__executionTraceId && !context.__executionTraceId;
|
|
3030
|
-
const executionTraceId = context.__metadata?.__executionTraceId ?? context.__executionTraceId ??
|
|
3084
|
+
const executionTraceId = context.__metadata?.__executionTraceId ?? context.__executionTraceId ?? uuid6();
|
|
3031
3085
|
context.__executionTraceId = executionTraceId;
|
|
3032
|
-
const routineExecId = context.__routineExecId ??
|
|
3086
|
+
const routineExecId = context.__routineExecId ?? uuid6();
|
|
3033
3087
|
context.__routineExecId = routineExecId;
|
|
3034
3088
|
const ctx = new GraphContext(context || {});
|
|
3035
3089
|
if (!isSubMeta) {
|
|
@@ -4220,6 +4274,21 @@ var Cadenza = class {
|
|
|
4220
4274
|
static emit(event, data = {}) {
|
|
4221
4275
|
this.broker?.emit(event, data);
|
|
4222
4276
|
}
|
|
4277
|
+
static schedule(taskName, context, timeoutMs, exactDateTime) {
|
|
4278
|
+
this.broker?.schedule(taskName, context, timeoutMs, exactDateTime);
|
|
4279
|
+
}
|
|
4280
|
+
static throttle(taskName, context, intervalMs, leading = false, startDateTime) {
|
|
4281
|
+
this.broker?.throttle(
|
|
4282
|
+
taskName,
|
|
4283
|
+
context,
|
|
4284
|
+
intervalMs,
|
|
4285
|
+
leading,
|
|
4286
|
+
startDateTime
|
|
4287
|
+
);
|
|
4288
|
+
}
|
|
4289
|
+
static get(taskName) {
|
|
4290
|
+
return this.registry?.tasks.get(taskName);
|
|
4291
|
+
}
|
|
4223
4292
|
/**
|
|
4224
4293
|
* Creates and registers a new task with the specified parameters and options.
|
|
4225
4294
|
* Tasks are the basic building blocks of Cadenza graphs and are responsible for executing logic.
|