@cadenza.io/core 1.6.0 → 1.7.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 +19 -4
- package/dist/index.d.ts +19 -4
- package/dist/index.js +127 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -3
package/dist/index.d.mts
CHANGED
|
@@ -155,7 +155,9 @@ declare abstract class GraphLayer extends ExecutionChain implements Graph {
|
|
|
155
155
|
protected nodes: GraphNode[];
|
|
156
156
|
private executionTime;
|
|
157
157
|
private executionStart;
|
|
158
|
+
protected debug: boolean;
|
|
158
159
|
constructor(index: number);
|
|
160
|
+
setDebug(value: boolean): void;
|
|
159
161
|
abstract execute(context?: GraphContext): unknown;
|
|
160
162
|
get hasPreceding(): boolean;
|
|
161
163
|
getNumberOfNodes(): number;
|
|
@@ -199,7 +201,9 @@ declare class GraphNode extends SignalEmitter implements Graph {
|
|
|
199
201
|
private failed;
|
|
200
202
|
private errored;
|
|
201
203
|
destroyed: boolean;
|
|
202
|
-
|
|
204
|
+
protected debug: boolean;
|
|
205
|
+
constructor(task: Task, context: GraphContext, routineExecId: string, prevNodes?: GraphNode[], debug?: boolean);
|
|
206
|
+
setDebug(value: boolean): void;
|
|
203
207
|
isUnique(): boolean;
|
|
204
208
|
isMeta(): boolean;
|
|
205
209
|
isProcessed(): boolean;
|
|
@@ -491,6 +495,8 @@ declare abstract class GraphBuilder {
|
|
|
491
495
|
graph: GraphLayer | undefined;
|
|
492
496
|
topLayerIndex: number;
|
|
493
497
|
layers: GraphLayer[];
|
|
498
|
+
debug: boolean;
|
|
499
|
+
setDebug(value: boolean): void;
|
|
494
500
|
getResult(): GraphLayer;
|
|
495
501
|
compose(): void;
|
|
496
502
|
addNode(node: GraphNode): void;
|
|
@@ -605,6 +611,9 @@ declare class SignalBroker {
|
|
|
605
611
|
* @returns The broker instance.
|
|
606
612
|
*/
|
|
607
613
|
static get instance(): SignalBroker;
|
|
614
|
+
private debug;
|
|
615
|
+
setDebug(value: boolean): void;
|
|
616
|
+
protected sanitizeSignalName(signalName: string): void;
|
|
608
617
|
protected runner: GraphRunner | undefined;
|
|
609
618
|
protected metaRunner: GraphRunner | undefined;
|
|
610
619
|
getSignalsTask: Task | undefined;
|
|
@@ -641,7 +650,6 @@ declare class SignalBroker {
|
|
|
641
650
|
* @param context The payload.
|
|
642
651
|
* @edge Fire-and-forget; guards against loops per execId (from context.__graphExecId).
|
|
643
652
|
* @edge For distribution, SignalTask can prefix and proxy remote.
|
|
644
|
-
* @throws Error on detected loop.
|
|
645
653
|
*/
|
|
646
654
|
emit(signal: string, context?: AnyObject): void;
|
|
647
655
|
execute(signal: string, context: AnyObject): boolean;
|
|
@@ -652,7 +660,6 @@ declare class SignalBroker {
|
|
|
652
660
|
* @returns Array of signals.
|
|
653
661
|
*/
|
|
654
662
|
listObservedSignals(): string[];
|
|
655
|
-
private getRunner;
|
|
656
663
|
reset(): void;
|
|
657
664
|
}
|
|
658
665
|
|
|
@@ -685,17 +692,22 @@ declare class GraphRegistry {
|
|
|
685
692
|
interface DebounceOptions {
|
|
686
693
|
leading?: boolean;
|
|
687
694
|
trailing?: boolean;
|
|
695
|
+
maxWait?: number;
|
|
688
696
|
}
|
|
689
697
|
declare class DebounceTask extends Task {
|
|
690
698
|
private readonly debounceTime;
|
|
691
699
|
private leading;
|
|
692
700
|
private trailing;
|
|
701
|
+
private maxWait;
|
|
693
702
|
private timer;
|
|
703
|
+
private maxTimer;
|
|
704
|
+
private hasLaterCall;
|
|
694
705
|
private lastResolve;
|
|
695
706
|
private lastReject;
|
|
696
707
|
private lastContext;
|
|
697
708
|
private lastTimeout;
|
|
698
|
-
|
|
709
|
+
private lastProgressCallback;
|
|
710
|
+
constructor(name: string, task: TaskFunction, description?: string, debounceTime?: number, leading?: boolean, trailing?: boolean, maxWait?: number, concurrency?: number, timeout?: number, register?: boolean, isUnique?: boolean, isMeta?: boolean, inputSchema?: SchemaDefinition | undefined, validateInputSchema?: boolean, outputSchema?: SchemaDefinition | undefined, validateOutputSchema?: boolean);
|
|
699
711
|
private executeFunction;
|
|
700
712
|
private debouncedTrigger;
|
|
701
713
|
execute(context: GraphContext, progressCallback: (progress: number) => void): TaskResult;
|
|
@@ -733,17 +745,20 @@ interface TaskOptions {
|
|
|
733
745
|
outputSchema?: SchemaDefinition;
|
|
734
746
|
validateOutputContext?: boolean;
|
|
735
747
|
}
|
|
748
|
+
type CadenzaMode = "dev" | "debug" | "production";
|
|
736
749
|
declare class Cadenza {
|
|
737
750
|
static broker: SignalBroker;
|
|
738
751
|
static runner: GraphRunner;
|
|
739
752
|
static metaRunner: GraphRunner;
|
|
740
753
|
static registry: GraphRegistry;
|
|
741
754
|
protected static isBootstrapped: boolean;
|
|
755
|
+
protected static mode: CadenzaMode;
|
|
742
756
|
protected static bootstrap(): void;
|
|
743
757
|
static get runStrategy(): {
|
|
744
758
|
PARALLEL: GraphAsyncRun;
|
|
745
759
|
SEQUENTIAL: GraphStandardRun;
|
|
746
760
|
};
|
|
761
|
+
static setMode(mode: CadenzaMode): void;
|
|
747
762
|
/**
|
|
748
763
|
* Validates a name for uniqueness and non-emptiness.
|
|
749
764
|
* @param name The name to validate.
|
package/dist/index.d.ts
CHANGED
|
@@ -155,7 +155,9 @@ declare abstract class GraphLayer extends ExecutionChain implements Graph {
|
|
|
155
155
|
protected nodes: GraphNode[];
|
|
156
156
|
private executionTime;
|
|
157
157
|
private executionStart;
|
|
158
|
+
protected debug: boolean;
|
|
158
159
|
constructor(index: number);
|
|
160
|
+
setDebug(value: boolean): void;
|
|
159
161
|
abstract execute(context?: GraphContext): unknown;
|
|
160
162
|
get hasPreceding(): boolean;
|
|
161
163
|
getNumberOfNodes(): number;
|
|
@@ -199,7 +201,9 @@ declare class GraphNode extends SignalEmitter implements Graph {
|
|
|
199
201
|
private failed;
|
|
200
202
|
private errored;
|
|
201
203
|
destroyed: boolean;
|
|
202
|
-
|
|
204
|
+
protected debug: boolean;
|
|
205
|
+
constructor(task: Task, context: GraphContext, routineExecId: string, prevNodes?: GraphNode[], debug?: boolean);
|
|
206
|
+
setDebug(value: boolean): void;
|
|
203
207
|
isUnique(): boolean;
|
|
204
208
|
isMeta(): boolean;
|
|
205
209
|
isProcessed(): boolean;
|
|
@@ -491,6 +495,8 @@ declare abstract class GraphBuilder {
|
|
|
491
495
|
graph: GraphLayer | undefined;
|
|
492
496
|
topLayerIndex: number;
|
|
493
497
|
layers: GraphLayer[];
|
|
498
|
+
debug: boolean;
|
|
499
|
+
setDebug(value: boolean): void;
|
|
494
500
|
getResult(): GraphLayer;
|
|
495
501
|
compose(): void;
|
|
496
502
|
addNode(node: GraphNode): void;
|
|
@@ -605,6 +611,9 @@ declare class SignalBroker {
|
|
|
605
611
|
* @returns The broker instance.
|
|
606
612
|
*/
|
|
607
613
|
static get instance(): SignalBroker;
|
|
614
|
+
private debug;
|
|
615
|
+
setDebug(value: boolean): void;
|
|
616
|
+
protected sanitizeSignalName(signalName: string): void;
|
|
608
617
|
protected runner: GraphRunner | undefined;
|
|
609
618
|
protected metaRunner: GraphRunner | undefined;
|
|
610
619
|
getSignalsTask: Task | undefined;
|
|
@@ -641,7 +650,6 @@ declare class SignalBroker {
|
|
|
641
650
|
* @param context The payload.
|
|
642
651
|
* @edge Fire-and-forget; guards against loops per execId (from context.__graphExecId).
|
|
643
652
|
* @edge For distribution, SignalTask can prefix and proxy remote.
|
|
644
|
-
* @throws Error on detected loop.
|
|
645
653
|
*/
|
|
646
654
|
emit(signal: string, context?: AnyObject): void;
|
|
647
655
|
execute(signal: string, context: AnyObject): boolean;
|
|
@@ -652,7 +660,6 @@ declare class SignalBroker {
|
|
|
652
660
|
* @returns Array of signals.
|
|
653
661
|
*/
|
|
654
662
|
listObservedSignals(): string[];
|
|
655
|
-
private getRunner;
|
|
656
663
|
reset(): void;
|
|
657
664
|
}
|
|
658
665
|
|
|
@@ -685,17 +692,22 @@ declare class GraphRegistry {
|
|
|
685
692
|
interface DebounceOptions {
|
|
686
693
|
leading?: boolean;
|
|
687
694
|
trailing?: boolean;
|
|
695
|
+
maxWait?: number;
|
|
688
696
|
}
|
|
689
697
|
declare class DebounceTask extends Task {
|
|
690
698
|
private readonly debounceTime;
|
|
691
699
|
private leading;
|
|
692
700
|
private trailing;
|
|
701
|
+
private maxWait;
|
|
693
702
|
private timer;
|
|
703
|
+
private maxTimer;
|
|
704
|
+
private hasLaterCall;
|
|
694
705
|
private lastResolve;
|
|
695
706
|
private lastReject;
|
|
696
707
|
private lastContext;
|
|
697
708
|
private lastTimeout;
|
|
698
|
-
|
|
709
|
+
private lastProgressCallback;
|
|
710
|
+
constructor(name: string, task: TaskFunction, description?: string, debounceTime?: number, leading?: boolean, trailing?: boolean, maxWait?: number, concurrency?: number, timeout?: number, register?: boolean, isUnique?: boolean, isMeta?: boolean, inputSchema?: SchemaDefinition | undefined, validateInputSchema?: boolean, outputSchema?: SchemaDefinition | undefined, validateOutputSchema?: boolean);
|
|
699
711
|
private executeFunction;
|
|
700
712
|
private debouncedTrigger;
|
|
701
713
|
execute(context: GraphContext, progressCallback: (progress: number) => void): TaskResult;
|
|
@@ -733,17 +745,20 @@ interface TaskOptions {
|
|
|
733
745
|
outputSchema?: SchemaDefinition;
|
|
734
746
|
validateOutputContext?: boolean;
|
|
735
747
|
}
|
|
748
|
+
type CadenzaMode = "dev" | "debug" | "production";
|
|
736
749
|
declare class Cadenza {
|
|
737
750
|
static broker: SignalBroker;
|
|
738
751
|
static runner: GraphRunner;
|
|
739
752
|
static metaRunner: GraphRunner;
|
|
740
753
|
static registry: GraphRegistry;
|
|
741
754
|
protected static isBootstrapped: boolean;
|
|
755
|
+
protected static mode: CadenzaMode;
|
|
742
756
|
protected static bootstrap(): void;
|
|
743
757
|
static get runStrategy(): {
|
|
744
758
|
PARALLEL: GraphAsyncRun;
|
|
745
759
|
SEQUENTIAL: GraphStandardRun;
|
|
746
760
|
};
|
|
761
|
+
static setMode(mode: CadenzaMode): void;
|
|
747
762
|
/**
|
|
748
763
|
* Validates a name for uniqueness and non-emptiness.
|
|
749
764
|
* @param name The name to validate.
|
package/dist/index.js
CHANGED
|
@@ -38,9 +38,10 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
38
|
var SignalBroker = class _SignalBroker {
|
|
39
39
|
// execId -> emitted signals
|
|
40
40
|
constructor() {
|
|
41
|
+
this.debug = false;
|
|
41
42
|
this.signalObservers = /* @__PURE__ */ new Map();
|
|
42
43
|
this.emitStacks = /* @__PURE__ */ new Map();
|
|
43
|
-
this.addSignal("meta.
|
|
44
|
+
this.addSignal("meta.signal_broker.added");
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* Singleton instance for signal management.
|
|
@@ -52,6 +53,25 @@ var SignalBroker = class _SignalBroker {
|
|
|
52
53
|
}
|
|
53
54
|
return this.instance_;
|
|
54
55
|
}
|
|
56
|
+
setDebug(value) {
|
|
57
|
+
this.debug = value;
|
|
58
|
+
}
|
|
59
|
+
sanitizeSignalName(signalName) {
|
|
60
|
+
if (signalName.length > 100) {
|
|
61
|
+
throw new Error("Signal name must be less than 100 characters");
|
|
62
|
+
}
|
|
63
|
+
if (signalName.includes(" ")) {
|
|
64
|
+
throw new Error("Signal name must not contain spaces");
|
|
65
|
+
}
|
|
66
|
+
if (signalName.includes("\\")) {
|
|
67
|
+
throw new Error("Signal name must not contain backslashes");
|
|
68
|
+
}
|
|
69
|
+
if (/[A-Z]/.test(signalName.split(".").slice(1).join("."))) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"Signal name must not contain uppercase letters in the middle of the signal name. It is only allowed in the first part of the signal name."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
55
75
|
/**
|
|
56
76
|
* Initializes with runners.
|
|
57
77
|
* @param runner Standard runner for user signals.
|
|
@@ -62,7 +82,7 @@ var SignalBroker = class _SignalBroker {
|
|
|
62
82
|
this.metaRunner = metaRunner;
|
|
63
83
|
}
|
|
64
84
|
init() {
|
|
65
|
-
Cadenza.
|
|
85
|
+
Cadenza.createDebounceMetaTask(
|
|
66
86
|
"Execute and clear queued signals",
|
|
67
87
|
() => {
|
|
68
88
|
for (const [id, signals] of this.emitStacks.entries()) {
|
|
@@ -74,8 +94,10 @@ var SignalBroker = class _SignalBroker {
|
|
|
74
94
|
}
|
|
75
95
|
return true;
|
|
76
96
|
},
|
|
77
|
-
"Executes queued signals and clears the stack"
|
|
78
|
-
|
|
97
|
+
"Executes queued signals and clears the stack",
|
|
98
|
+
500,
|
|
99
|
+
{ maxWait: 1e4 }
|
|
100
|
+
).doOn("meta.process_signal_queue_requested");
|
|
79
101
|
this.getSignalsTask = Cadenza.createMetaTask("Get signals", (ctx) => {
|
|
80
102
|
return {
|
|
81
103
|
__signals: Array.from(this.signalObservers.keys()),
|
|
@@ -114,10 +136,9 @@ var SignalBroker = class _SignalBroker {
|
|
|
114
136
|
* @param context The payload.
|
|
115
137
|
* @edge Fire-and-forget; guards against loops per execId (from context.__graphExecId).
|
|
116
138
|
* @edge For distribution, SignalTask can prefix and proxy remote.
|
|
117
|
-
* @throws Error on detected loop.
|
|
118
139
|
*/
|
|
119
140
|
emit(signal, context = {}) {
|
|
120
|
-
const execId = context.
|
|
141
|
+
const execId = context.__routineExecId || "global";
|
|
121
142
|
if (!this.emitStacks.has(execId)) this.emitStacks.set(execId, /* @__PURE__ */ new Map());
|
|
122
143
|
const stack = this.emitStacks.get(execId);
|
|
123
144
|
stack.set(signal, context);
|
|
@@ -126,6 +147,7 @@ var SignalBroker = class _SignalBroker {
|
|
|
126
147
|
executed = this.execute(signal, context);
|
|
127
148
|
} finally {
|
|
128
149
|
if (executed) stack.delete(signal);
|
|
150
|
+
if (stack.size === 0) this.emitStacks.delete(execId);
|
|
129
151
|
}
|
|
130
152
|
}
|
|
131
153
|
execute(signal, context) {
|
|
@@ -136,11 +158,17 @@ var SignalBroker = class _SignalBroker {
|
|
|
136
158
|
const parent = parts.slice(0, i).join(".");
|
|
137
159
|
executed = executed || this.executeListener(parent + ".*", context);
|
|
138
160
|
}
|
|
161
|
+
if (this.debug) {
|
|
162
|
+
console.log(
|
|
163
|
+
`Emitted signal ${signal} with context ${JSON.stringify(context)}`,
|
|
164
|
+
executed ? "\u2705" : "\u274C"
|
|
165
|
+
);
|
|
166
|
+
}
|
|
139
167
|
return executed;
|
|
140
168
|
}
|
|
141
169
|
executeListener(signal, context) {
|
|
142
170
|
const obs = this.signalObservers.get(signal);
|
|
143
|
-
const runner =
|
|
171
|
+
const runner = signal.startsWith("meta") ? this.metaRunner : this.runner;
|
|
144
172
|
if (obs && obs.tasks.size && runner) {
|
|
145
173
|
obs.fn(runner, Array.from(obs.tasks), context);
|
|
146
174
|
return true;
|
|
@@ -149,13 +177,15 @@ var SignalBroker = class _SignalBroker {
|
|
|
149
177
|
}
|
|
150
178
|
addSignal(signal) {
|
|
151
179
|
if (!this.signalObservers.has(signal)) {
|
|
180
|
+
this.sanitizeSignalName(signal);
|
|
152
181
|
this.signalObservers.set(signal, {
|
|
153
182
|
fn: (runner, tasks, context) => runner.run(tasks, context),
|
|
154
183
|
tasks: /* @__PURE__ */ new Set()
|
|
155
184
|
});
|
|
156
|
-
this.emit("meta.
|
|
185
|
+
this.emit("meta.signal_broker.added", { __signalName: signal });
|
|
157
186
|
}
|
|
158
187
|
}
|
|
188
|
+
// TODO schedule signals
|
|
159
189
|
/**
|
|
160
190
|
* Lists all observed signals.
|
|
161
191
|
* @returns Array of signals.
|
|
@@ -163,9 +193,6 @@ var SignalBroker = class _SignalBroker {
|
|
|
163
193
|
listObservedSignals() {
|
|
164
194
|
return Array.from(this.signalObservers.keys());
|
|
165
195
|
}
|
|
166
|
-
getRunner(signal) {
|
|
167
|
-
return signal.startsWith("meta") ? this.metaRunner : this.runner;
|
|
168
|
-
}
|
|
169
196
|
reset() {
|
|
170
197
|
this.emitStacks.clear();
|
|
171
198
|
this.signalObservers.clear();
|
|
@@ -612,7 +639,7 @@ var SignalEmitter = class {
|
|
|
612
639
|
|
|
613
640
|
// src/graph/execution/GraphNode.ts
|
|
614
641
|
var GraphNode = class _GraphNode extends SignalEmitter {
|
|
615
|
-
constructor(task, context, routineExecId, prevNodes = []) {
|
|
642
|
+
constructor(task, context, routineExecId, prevNodes = [], debug = false) {
|
|
616
643
|
super(task.isMeta);
|
|
617
644
|
this.divided = false;
|
|
618
645
|
this.splitGroupId = "";
|
|
@@ -626,12 +653,17 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
626
653
|
this.failed = false;
|
|
627
654
|
this.errored = false;
|
|
628
655
|
this.destroyed = false;
|
|
656
|
+
this.debug = false;
|
|
629
657
|
this.task = task;
|
|
630
658
|
this.context = context;
|
|
631
659
|
this.previousNodes = prevNodes;
|
|
632
660
|
this.id = (0, import_uuid3.v4)();
|
|
633
661
|
this.routineExecId = routineExecId;
|
|
634
662
|
this.splitGroupId = routineExecId;
|
|
663
|
+
this.debug = debug;
|
|
664
|
+
}
|
|
665
|
+
setDebug(value) {
|
|
666
|
+
this.debug = value;
|
|
635
667
|
}
|
|
636
668
|
isUnique() {
|
|
637
669
|
return this.task.isUnique;
|
|
@@ -703,6 +735,9 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
703
735
|
if (this.previousNodes.length === 0) {
|
|
704
736
|
this.emit("meta.node.started_routine_execution", memento);
|
|
705
737
|
}
|
|
738
|
+
if (this.debug) {
|
|
739
|
+
this.log();
|
|
740
|
+
}
|
|
706
741
|
this.emit("meta.node.started", memento);
|
|
707
742
|
return this.executionStart;
|
|
708
743
|
}
|
|
@@ -728,7 +763,6 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
728
763
|
}
|
|
729
764
|
execute() {
|
|
730
765
|
if (!this.divided && !this.processing) {
|
|
731
|
-
this.start();
|
|
732
766
|
this.processing = true;
|
|
733
767
|
const inputValidation = this.task.validateInput(
|
|
734
768
|
this.context.getContext()
|
|
@@ -899,7 +933,13 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
899
933
|
return this;
|
|
900
934
|
}
|
|
901
935
|
clone() {
|
|
902
|
-
return new _GraphNode(
|
|
936
|
+
return new _GraphNode(
|
|
937
|
+
this.task,
|
|
938
|
+
this.context,
|
|
939
|
+
this.routineExecId,
|
|
940
|
+
[this],
|
|
941
|
+
this.debug
|
|
942
|
+
);
|
|
903
943
|
}
|
|
904
944
|
consume(node) {
|
|
905
945
|
this.context = this.context.combine(node.context);
|
|
@@ -995,7 +1035,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
995
1035
|
};
|
|
996
1036
|
}
|
|
997
1037
|
log() {
|
|
998
|
-
console.log(this.task.name, this.context.getContext(), this.
|
|
1038
|
+
console.log(this.task.name, this.context.getContext(), this.routineExecId);
|
|
999
1039
|
}
|
|
1000
1040
|
};
|
|
1001
1041
|
|
|
@@ -1851,6 +1891,7 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
1851
1891
|
});
|
|
1852
1892
|
const ctx = new GraphContext(context || {});
|
|
1853
1893
|
const routineExecId = (_a = context.__routineExecId) != null ? _a : (0, import_uuid6.v4)();
|
|
1894
|
+
context.__routineExecId = routineExecId;
|
|
1854
1895
|
const data = {
|
|
1855
1896
|
__routineExecId: routineExecId,
|
|
1856
1897
|
__routineName: routineName,
|
|
@@ -1866,7 +1907,9 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
1866
1907
|
};
|
|
1867
1908
|
this.emit("meta.runner.added_tasks", data);
|
|
1868
1909
|
allTasks.forEach(
|
|
1869
|
-
(task) => this.currentRun.addNode(
|
|
1910
|
+
(task) => this.currentRun.addNode(
|
|
1911
|
+
new GraphNode(task, ctx, routineExecId, [], this.debug)
|
|
1912
|
+
)
|
|
1870
1913
|
);
|
|
1871
1914
|
}
|
|
1872
1915
|
/**
|
|
@@ -1897,9 +1940,6 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
1897
1940
|
return this.reset();
|
|
1898
1941
|
}
|
|
1899
1942
|
reset() {
|
|
1900
|
-
if (this.debug) {
|
|
1901
|
-
this.currentRun.log();
|
|
1902
|
-
}
|
|
1903
1943
|
this.isRunning = false;
|
|
1904
1944
|
const lastRun = this.currentRun;
|
|
1905
1945
|
if (!this.debug) {
|
|
@@ -1936,7 +1976,7 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
1936
1976
|
|
|
1937
1977
|
// src/graph/definition/DebounceTask.ts
|
|
1938
1978
|
var DebounceTask = class extends Task {
|
|
1939
|
-
constructor(name, task, description = "", debounceTime = 1e3, leading = false, trailing = true, concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, inputSchema = void 0, validateInputSchema = false, outputSchema = void 0, validateOutputSchema = false) {
|
|
1979
|
+
constructor(name, task, description = "", debounceTime = 1e3, leading = false, trailing = true, maxWait = 0, concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, inputSchema = void 0, validateInputSchema = false, outputSchema = void 0, validateOutputSchema = false) {
|
|
1940
1980
|
super(
|
|
1941
1981
|
name,
|
|
1942
1982
|
task,
|
|
@@ -1953,15 +1993,19 @@ var DebounceTask = class extends Task {
|
|
|
1953
1993
|
validateOutputSchema
|
|
1954
1994
|
);
|
|
1955
1995
|
this.timer = null;
|
|
1996
|
+
this.maxTimer = null;
|
|
1997
|
+
this.hasLaterCall = false;
|
|
1956
1998
|
this.lastResolve = null;
|
|
1957
1999
|
this.lastReject = null;
|
|
1958
2000
|
this.lastContext = null;
|
|
1959
2001
|
this.lastTimeout = null;
|
|
2002
|
+
this.lastProgressCallback = null;
|
|
1960
2003
|
this.debounceTime = debounceTime;
|
|
1961
2004
|
this.leading = leading;
|
|
1962
2005
|
this.trailing = trailing;
|
|
2006
|
+
this.maxWait = maxWait;
|
|
1963
2007
|
}
|
|
1964
|
-
executeFunction(
|
|
2008
|
+
executeFunction() {
|
|
1965
2009
|
if (this.lastTimeout) {
|
|
1966
2010
|
clearTimeout(this.lastTimeout);
|
|
1967
2011
|
}
|
|
@@ -1969,7 +2013,7 @@ var DebounceTask = class extends Task {
|
|
|
1969
2013
|
try {
|
|
1970
2014
|
result = this.taskFunction(
|
|
1971
2015
|
this.lastContext.getClonedContext(),
|
|
1972
|
-
|
|
2016
|
+
this.lastProgressCallback
|
|
1973
2017
|
);
|
|
1974
2018
|
} catch (error) {
|
|
1975
2019
|
if (this.lastResolve) {
|
|
@@ -1987,21 +2031,46 @@ var DebounceTask = class extends Task {
|
|
|
1987
2031
|
}
|
|
1988
2032
|
debouncedTrigger(resolve, reject, context, timeout, progressCallback) {
|
|
1989
2033
|
const callNow = this.leading && this.timer === null;
|
|
2034
|
+
const isNewBurst = this.timer === null;
|
|
1990
2035
|
if (this.timer !== null) {
|
|
1991
2036
|
clearTimeout(this.timer);
|
|
2037
|
+
this.timer = null;
|
|
1992
2038
|
}
|
|
1993
2039
|
this.lastResolve = resolve;
|
|
1994
2040
|
this.lastReject = reject;
|
|
1995
2041
|
this.lastContext = context;
|
|
1996
2042
|
this.lastTimeout = timeout;
|
|
2043
|
+
this.lastProgressCallback = progressCallback;
|
|
2044
|
+
if (!callNow) {
|
|
2045
|
+
this.hasLaterCall = true;
|
|
2046
|
+
}
|
|
1997
2047
|
this.timer = setTimeout(() => {
|
|
1998
2048
|
this.timer = null;
|
|
1999
|
-
if (this.trailing) {
|
|
2000
|
-
this.executeFunction(
|
|
2049
|
+
if (this.trailing && this.hasLaterCall) {
|
|
2050
|
+
this.executeFunction();
|
|
2051
|
+
this.hasLaterCall = false;
|
|
2052
|
+
}
|
|
2053
|
+
if (this.maxTimer) {
|
|
2054
|
+
clearTimeout(this.maxTimer);
|
|
2055
|
+
this.maxTimer = null;
|
|
2001
2056
|
}
|
|
2002
2057
|
}, this.debounceTime);
|
|
2003
2058
|
if (callNow) {
|
|
2004
|
-
this.executeFunction(
|
|
2059
|
+
this.executeFunction();
|
|
2060
|
+
this.hasLaterCall = false;
|
|
2061
|
+
}
|
|
2062
|
+
if (this.maxWait > 0 && isNewBurst) {
|
|
2063
|
+
this.maxTimer = setTimeout(() => {
|
|
2064
|
+
this.maxTimer = null;
|
|
2065
|
+
if (this.trailing && this.hasLaterCall) {
|
|
2066
|
+
if (this.timer) {
|
|
2067
|
+
clearTimeout(this.timer);
|
|
2068
|
+
this.timer = null;
|
|
2069
|
+
}
|
|
2070
|
+
this.executeFunction();
|
|
2071
|
+
this.hasLaterCall = false;
|
|
2072
|
+
}
|
|
2073
|
+
}, this.maxWait);
|
|
2005
2074
|
}
|
|
2006
2075
|
}
|
|
2007
2076
|
execute(context, progressCallback) {
|
|
@@ -2135,8 +2204,15 @@ var GraphLayer = class _GraphLayer extends ExecutionChain {
|
|
|
2135
2204
|
this.nodes = [];
|
|
2136
2205
|
this.executionTime = 0;
|
|
2137
2206
|
this.executionStart = 0;
|
|
2207
|
+
this.debug = false;
|
|
2138
2208
|
this.index = index;
|
|
2139
2209
|
}
|
|
2210
|
+
setDebug(value) {
|
|
2211
|
+
this.debug = value;
|
|
2212
|
+
for (const node of this.nodes) {
|
|
2213
|
+
node.setDebug(value);
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2140
2216
|
get hasPreceding() {
|
|
2141
2217
|
return !!this.previous && this.previous instanceof _GraphLayer;
|
|
2142
2218
|
}
|
|
@@ -2266,6 +2342,10 @@ var GraphBuilder = class {
|
|
|
2266
2342
|
constructor() {
|
|
2267
2343
|
this.topLayerIndex = 0;
|
|
2268
2344
|
this.layers = [];
|
|
2345
|
+
this.debug = false;
|
|
2346
|
+
}
|
|
2347
|
+
setDebug(value) {
|
|
2348
|
+
this.debug = value;
|
|
2269
2349
|
}
|
|
2270
2350
|
getResult() {
|
|
2271
2351
|
return this.graph;
|
|
@@ -2311,7 +2391,9 @@ var GraphBuilder = class {
|
|
|
2311
2391
|
}
|
|
2312
2392
|
}
|
|
2313
2393
|
createLayer(index) {
|
|
2314
|
-
|
|
2394
|
+
const layer = new SyncGraphLayer(index);
|
|
2395
|
+
layer.setDebug(this.debug);
|
|
2396
|
+
return layer;
|
|
2315
2397
|
}
|
|
2316
2398
|
getLayer(layerIndex) {
|
|
2317
2399
|
return this.layers[layerIndex - this.topLayerIndex];
|
|
@@ -2523,7 +2605,9 @@ var GraphAsyncQueueBuilder = class extends GraphBuilder {
|
|
|
2523
2605
|
}
|
|
2524
2606
|
}
|
|
2525
2607
|
createLayer(index) {
|
|
2526
|
-
|
|
2608
|
+
const layer = new AsyncGraphLayer(index);
|
|
2609
|
+
layer.setDebug(this.debug);
|
|
2610
|
+
return layer;
|
|
2527
2611
|
}
|
|
2528
2612
|
};
|
|
2529
2613
|
|
|
@@ -2567,6 +2651,10 @@ var Cadenza = class {
|
|
|
2567
2651
|
this.runner = new GraphRunner();
|
|
2568
2652
|
this.metaRunner = new GraphRunner(true);
|
|
2569
2653
|
this.broker.bootstrap(this.runner, this.metaRunner);
|
|
2654
|
+
if (this.mode === "debug" || this.mode === "dev") {
|
|
2655
|
+
this.broker.setDebug(true);
|
|
2656
|
+
this.runner.setDebug(true);
|
|
2657
|
+
}
|
|
2570
2658
|
this.registry = GraphRegistry.instance;
|
|
2571
2659
|
this.broker.init();
|
|
2572
2660
|
this.runner.init();
|
|
@@ -2578,6 +2666,14 @@ var Cadenza = class {
|
|
|
2578
2666
|
SEQUENTIAL: new GraphStandardRun()
|
|
2579
2667
|
};
|
|
2580
2668
|
}
|
|
2669
|
+
static setMode(mode) {
|
|
2670
|
+
this.mode = mode;
|
|
2671
|
+
this.bootstrap();
|
|
2672
|
+
if (mode === "debug" || mode === "dev") {
|
|
2673
|
+
this.broker.setDebug(true);
|
|
2674
|
+
this.runner.setDebug(true);
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2581
2677
|
/**
|
|
2582
2678
|
* Validates a name for uniqueness and non-emptiness.
|
|
2583
2679
|
* @param name The name to validate.
|
|
@@ -2769,6 +2865,7 @@ var Cadenza = class {
|
|
|
2769
2865
|
register: true,
|
|
2770
2866
|
leading: false,
|
|
2771
2867
|
trailing: true,
|
|
2868
|
+
maxWait: 0,
|
|
2772
2869
|
isUnique: false,
|
|
2773
2870
|
isMeta: false,
|
|
2774
2871
|
inputSchema: void 0,
|
|
@@ -2785,6 +2882,7 @@ var Cadenza = class {
|
|
|
2785
2882
|
debounceTime,
|
|
2786
2883
|
options.leading,
|
|
2787
2884
|
options.trailing,
|
|
2885
|
+
options.maxWait,
|
|
2788
2886
|
options.concurrency,
|
|
2789
2887
|
options.timeout,
|
|
2790
2888
|
options.register,
|
|
@@ -2811,6 +2909,7 @@ var Cadenza = class {
|
|
|
2811
2909
|
register: true,
|
|
2812
2910
|
leading: false,
|
|
2813
2911
|
trailing: true,
|
|
2912
|
+
maxWait: 0,
|
|
2814
2913
|
isUnique: false,
|
|
2815
2914
|
isMeta: false,
|
|
2816
2915
|
inputSchema: void 0,
|
|
@@ -2941,6 +3040,7 @@ var Cadenza = class {
|
|
|
2941
3040
|
}
|
|
2942
3041
|
};
|
|
2943
3042
|
Cadenza.isBootstrapped = false;
|
|
3043
|
+
Cadenza.mode = "production";
|
|
2944
3044
|
|
|
2945
3045
|
// src/graph/definition/SignalTask.ts
|
|
2946
3046
|
var SignalTask = class extends Task {
|