@cadenza.io/core 3.16.4 → 3.17.1
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 +55 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1403,11 +1403,14 @@ declare class GraphRunner extends SignalEmitter {
|
|
|
1403
1403
|
interface EmitOptions {
|
|
1404
1404
|
squash?: boolean;
|
|
1405
1405
|
squashId?: string | null;
|
|
1406
|
+
groupId?: string | null;
|
|
1406
1407
|
mergeFunction?: ((oldContext: AnyObject, newContext: AnyObject) => AnyObject) | null;
|
|
1407
1408
|
debounce?: boolean;
|
|
1409
|
+
throttle?: boolean;
|
|
1408
1410
|
delayMs?: number;
|
|
1409
1411
|
schedule?: boolean;
|
|
1410
1412
|
exactDateTime?: Date | null;
|
|
1413
|
+
throttleBatch?: number;
|
|
1411
1414
|
}
|
|
1412
1415
|
/**
|
|
1413
1416
|
* This class manages signals and observers, enabling communication across different parts of an application.
|
|
@@ -1435,6 +1438,8 @@ declare class SignalBroker {
|
|
|
1435
1438
|
debouncedEmitters: Map<string, any>;
|
|
1436
1439
|
squashedEmitters: Map<string, any>;
|
|
1437
1440
|
squashedContexts: Map<string, any>;
|
|
1441
|
+
throttleEmitters: Map<string, any>;
|
|
1442
|
+
throttleQueues: Map<string, any>;
|
|
1438
1443
|
getSignalsTask: Task | undefined;
|
|
1439
1444
|
registerSignalTask: Task | undefined;
|
|
1440
1445
|
signalObservers: Map<string, {
|
|
@@ -1494,6 +1499,7 @@ declare class SignalBroker {
|
|
|
1494
1499
|
debounce(signal: string, context: any, options?: {
|
|
1495
1500
|
delayMs: number;
|
|
1496
1501
|
}): void;
|
|
1502
|
+
throttle(signal: string, context: any, options?: EmitOptions): void;
|
|
1497
1503
|
/**
|
|
1498
1504
|
* Aggregates and debounces multiple events with the same identifier to minimize redundant operations.
|
|
1499
1505
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1403,11 +1403,14 @@ declare class GraphRunner extends SignalEmitter {
|
|
|
1403
1403
|
interface EmitOptions {
|
|
1404
1404
|
squash?: boolean;
|
|
1405
1405
|
squashId?: string | null;
|
|
1406
|
+
groupId?: string | null;
|
|
1406
1407
|
mergeFunction?: ((oldContext: AnyObject, newContext: AnyObject) => AnyObject) | null;
|
|
1407
1408
|
debounce?: boolean;
|
|
1409
|
+
throttle?: boolean;
|
|
1408
1410
|
delayMs?: number;
|
|
1409
1411
|
schedule?: boolean;
|
|
1410
1412
|
exactDateTime?: Date | null;
|
|
1413
|
+
throttleBatch?: number;
|
|
1411
1414
|
}
|
|
1412
1415
|
/**
|
|
1413
1416
|
* This class manages signals and observers, enabling communication across different parts of an application.
|
|
@@ -1435,6 +1438,8 @@ declare class SignalBroker {
|
|
|
1435
1438
|
debouncedEmitters: Map<string, any>;
|
|
1436
1439
|
squashedEmitters: Map<string, any>;
|
|
1437
1440
|
squashedContexts: Map<string, any>;
|
|
1441
|
+
throttleEmitters: Map<string, any>;
|
|
1442
|
+
throttleQueues: Map<string, any>;
|
|
1438
1443
|
getSignalsTask: Task | undefined;
|
|
1439
1444
|
registerSignalTask: Task | undefined;
|
|
1440
1445
|
signalObservers: Map<string, {
|
|
@@ -1494,6 +1499,7 @@ declare class SignalBroker {
|
|
|
1494
1499
|
debounce(signal: string, context: any, options?: {
|
|
1495
1500
|
delayMs: number;
|
|
1496
1501
|
}): void;
|
|
1502
|
+
throttle(signal: string, context: any, options?: EmitOptions): void;
|
|
1497
1503
|
/**
|
|
1498
1504
|
* Aggregates and debounces multiple events with the same identifier to minimize redundant operations.
|
|
1499
1505
|
*
|
package/dist/index.js
CHANGED
|
@@ -1262,6 +1262,11 @@ var merge = createAssigner_default(function(object, source, srcIndex) {
|
|
|
1262
1262
|
});
|
|
1263
1263
|
var merge_default = merge;
|
|
1264
1264
|
|
|
1265
|
+
// src/utils/promise.ts
|
|
1266
|
+
function sleep(ms) {
|
|
1267
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1265
1270
|
// src/engine/SignalBroker.ts
|
|
1266
1271
|
var SignalBroker = class _SignalBroker {
|
|
1267
1272
|
constructor() {
|
|
@@ -1270,6 +1275,8 @@ var SignalBroker = class _SignalBroker {
|
|
|
1270
1275
|
this.debouncedEmitters = /* @__PURE__ */ new Map();
|
|
1271
1276
|
this.squashedEmitters = /* @__PURE__ */ new Map();
|
|
1272
1277
|
this.squashedContexts = /* @__PURE__ */ new Map();
|
|
1278
|
+
this.throttleEmitters = /* @__PURE__ */ new Map();
|
|
1279
|
+
this.throttleQueues = /* @__PURE__ */ new Map();
|
|
1273
1280
|
// TODO: Signals should be a class with a the observers, registered flag and other data.
|
|
1274
1281
|
this.signalObservers = /* @__PURE__ */ new Map();
|
|
1275
1282
|
this.emittedSignalsRegistry = /* @__PURE__ */ new Set();
|
|
@@ -1470,6 +1477,35 @@ var SignalBroker = class _SignalBroker {
|
|
|
1470
1477
|
}
|
|
1471
1478
|
debouncedEmitter(context);
|
|
1472
1479
|
}
|
|
1480
|
+
throttle(signal, context, options = { delayMs: 1e3 }) {
|
|
1481
|
+
let { groupId, delayMs = 300 } = options;
|
|
1482
|
+
if (!groupId) {
|
|
1483
|
+
groupId = signal;
|
|
1484
|
+
}
|
|
1485
|
+
if (!this.throttleQueues.has(groupId)) {
|
|
1486
|
+
this.throttleQueues.set(groupId, []);
|
|
1487
|
+
}
|
|
1488
|
+
const queue = this.throttleQueues.get(groupId);
|
|
1489
|
+
queue.push([signal, context]);
|
|
1490
|
+
if (!this.throttleEmitters.has(groupId)) {
|
|
1491
|
+
this.throttleEmitters.set(groupId, async () => {
|
|
1492
|
+
while (queue.length > 0) {
|
|
1493
|
+
let batchSize = options.throttleBatch ?? 1;
|
|
1494
|
+
if (batchSize > queue.length) {
|
|
1495
|
+
batchSize = queue.length;
|
|
1496
|
+
}
|
|
1497
|
+
for (let i = 0; i < batchSize; i++) {
|
|
1498
|
+
const [nextSignal, nextContext] = queue.shift();
|
|
1499
|
+
this.emit(nextSignal, nextContext);
|
|
1500
|
+
}
|
|
1501
|
+
await sleep(delayMs);
|
|
1502
|
+
}
|
|
1503
|
+
this.throttleEmitters.delete(groupId);
|
|
1504
|
+
this.throttleQueues.delete(groupId);
|
|
1505
|
+
});
|
|
1506
|
+
this.throttleEmitters.get(groupId)();
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1473
1509
|
/**
|
|
1474
1510
|
* Aggregates and debounces multiple events with the same identifier to minimize redundant operations.
|
|
1475
1511
|
*
|
|
@@ -1490,7 +1526,8 @@ var SignalBroker = class _SignalBroker {
|
|
|
1490
1526
|
this.squashedEmitters.set(
|
|
1491
1527
|
squashId,
|
|
1492
1528
|
debounce_default(() => {
|
|
1493
|
-
|
|
1529
|
+
options.squash = false;
|
|
1530
|
+
this.emit(signal, this.squashedContexts.get(squashId), options);
|
|
1494
1531
|
this.squashedEmitters.delete(squashId);
|
|
1495
1532
|
this.squashedContexts.delete(squashId);
|
|
1496
1533
|
}, delayMs ?? 300)
|
|
@@ -2094,11 +2131,6 @@ var SignalEmitter = class {
|
|
|
2094
2131
|
}
|
|
2095
2132
|
};
|
|
2096
2133
|
|
|
2097
|
-
// src/utils/promise.ts
|
|
2098
|
-
function sleep(ms) {
|
|
2099
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2100
|
-
}
|
|
2101
|
-
|
|
2102
2134
|
// src/graph/execution/GraphNode.ts
|
|
2103
2135
|
var GraphNode = class _GraphNode extends SignalEmitter {
|
|
2104
2136
|
constructor(task, context, routineExecId, prevNodes = [], debug = false, verbose = false) {
|
|
@@ -2403,7 +2435,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
2403
2435
|
},
|
|
2404
2436
|
filter: { uuid: this.id }
|
|
2405
2437
|
},
|
|
2406
|
-
{ squash: true, squashId: this.id }
|
|
2438
|
+
{ squash: true, squashId: this.id, delayMs: 0 }
|
|
2407
2439
|
);
|
|
2408
2440
|
if (this.graphDone()) {
|
|
2409
2441
|
const context2 = this.context.getFullContext();
|
|
@@ -2425,7 +2457,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
2425
2457
|
},
|
|
2426
2458
|
filter: { uuid: this.routineExecId }
|
|
2427
2459
|
},
|
|
2428
|
-
{ squash: true, squashId: this.routineExecId }
|
|
2460
|
+
{ squash: true, squashId: this.routineExecId, delayMs: 0 }
|
|
2429
2461
|
);
|
|
2430
2462
|
}
|
|
2431
2463
|
return end;
|
|
@@ -3288,26 +3320,22 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
3288
3320
|
}
|
|
3289
3321
|
});
|
|
3290
3322
|
}
|
|
3291
|
-
this.emitMetrics(
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
previousRoutineExecution: context.__localRoutineExecId ?? context.__metadata?.__routineExecId ?? null,
|
|
3303
|
-
created: formatTimestamp(Date.now())
|
|
3304
|
-
},
|
|
3305
|
-
__metadata: {
|
|
3306
|
-
__executionTraceId: executionTraceId
|
|
3307
|
-
}
|
|
3323
|
+
this.emitMetrics("meta.runner.added_tasks", {
|
|
3324
|
+
data: {
|
|
3325
|
+
uuid: routineExecId,
|
|
3326
|
+
name: routineName,
|
|
3327
|
+
routineVersion,
|
|
3328
|
+
isMeta,
|
|
3329
|
+
executionTraceId,
|
|
3330
|
+
context: ctx.getContext(),
|
|
3331
|
+
metaContext: ctx.getMetadata(),
|
|
3332
|
+
previousRoutineExecution: context.__localRoutineExecId ?? context.__metadata?.__routineExecId ?? null,
|
|
3333
|
+
created: formatTimestamp(Date.now())
|
|
3308
3334
|
},
|
|
3309
|
-
|
|
3310
|
-
|
|
3335
|
+
__metadata: {
|
|
3336
|
+
__executionTraceId: executionTraceId
|
|
3337
|
+
}
|
|
3338
|
+
});
|
|
3311
3339
|
}
|
|
3312
3340
|
allTasks.forEach(
|
|
3313
3341
|
(task) => this.currentRun.addNode(
|