@cadenza.io/core 3.13.2 → 3.14.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.mjs CHANGED
@@ -42,11 +42,227 @@ function formatTimestamp(timestamp) {
42
42
 
43
43
  // src/engine/SignalBroker.ts
44
44
  import { v4 as uuid } from "uuid";
45
+
46
+ // node_modules/lodash-es/isObject.js
47
+ function isObject(value) {
48
+ var type = typeof value;
49
+ return value != null && (type == "object" || type == "function");
50
+ }
51
+ var isObject_default = isObject;
52
+
53
+ // node_modules/lodash-es/_freeGlobal.js
54
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
55
+ var freeGlobal_default = freeGlobal;
56
+
57
+ // node_modules/lodash-es/_root.js
58
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
59
+ var root = freeGlobal_default || freeSelf || Function("return this")();
60
+ var root_default = root;
61
+
62
+ // node_modules/lodash-es/now.js
63
+ var now = function() {
64
+ return root_default.Date.now();
65
+ };
66
+ var now_default = now;
67
+
68
+ // node_modules/lodash-es/_trimmedEndIndex.js
69
+ var reWhitespace = /\s/;
70
+ function trimmedEndIndex(string) {
71
+ var index = string.length;
72
+ while (index-- && reWhitespace.test(string.charAt(index))) {
73
+ }
74
+ return index;
75
+ }
76
+ var trimmedEndIndex_default = trimmedEndIndex;
77
+
78
+ // node_modules/lodash-es/_baseTrim.js
79
+ var reTrimStart = /^\s+/;
80
+ function baseTrim(string) {
81
+ return string ? string.slice(0, trimmedEndIndex_default(string) + 1).replace(reTrimStart, "") : string;
82
+ }
83
+ var baseTrim_default = baseTrim;
84
+
85
+ // node_modules/lodash-es/_Symbol.js
86
+ var Symbol2 = root_default.Symbol;
87
+ var Symbol_default = Symbol2;
88
+
89
+ // node_modules/lodash-es/_getRawTag.js
90
+ var objectProto = Object.prototype;
91
+ var hasOwnProperty = objectProto.hasOwnProperty;
92
+ var nativeObjectToString = objectProto.toString;
93
+ var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
94
+ function getRawTag(value) {
95
+ var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
96
+ try {
97
+ value[symToStringTag] = void 0;
98
+ var unmasked = true;
99
+ } catch (e) {
100
+ }
101
+ var result = nativeObjectToString.call(value);
102
+ if (unmasked) {
103
+ if (isOwn) {
104
+ value[symToStringTag] = tag;
105
+ } else {
106
+ delete value[symToStringTag];
107
+ }
108
+ }
109
+ return result;
110
+ }
111
+ var getRawTag_default = getRawTag;
112
+
113
+ // node_modules/lodash-es/_objectToString.js
114
+ var objectProto2 = Object.prototype;
115
+ var nativeObjectToString2 = objectProto2.toString;
116
+ function objectToString(value) {
117
+ return nativeObjectToString2.call(value);
118
+ }
119
+ var objectToString_default = objectToString;
120
+
121
+ // node_modules/lodash-es/_baseGetTag.js
122
+ var nullTag = "[object Null]";
123
+ var undefinedTag = "[object Undefined]";
124
+ var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
125
+ function baseGetTag(value) {
126
+ if (value == null) {
127
+ return value === void 0 ? undefinedTag : nullTag;
128
+ }
129
+ return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
130
+ }
131
+ var baseGetTag_default = baseGetTag;
132
+
133
+ // node_modules/lodash-es/isObjectLike.js
134
+ function isObjectLike(value) {
135
+ return value != null && typeof value == "object";
136
+ }
137
+ var isObjectLike_default = isObjectLike;
138
+
139
+ // node_modules/lodash-es/isSymbol.js
140
+ var symbolTag = "[object Symbol]";
141
+ function isSymbol(value) {
142
+ return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
143
+ }
144
+ var isSymbol_default = isSymbol;
145
+
146
+ // node_modules/lodash-es/toNumber.js
147
+ var NAN = 0 / 0;
148
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
149
+ var reIsBinary = /^0b[01]+$/i;
150
+ var reIsOctal = /^0o[0-7]+$/i;
151
+ var freeParseInt = parseInt;
152
+ function toNumber(value) {
153
+ if (typeof value == "number") {
154
+ return value;
155
+ }
156
+ if (isSymbol_default(value)) {
157
+ return NAN;
158
+ }
159
+ if (isObject_default(value)) {
160
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
161
+ value = isObject_default(other) ? other + "" : other;
162
+ }
163
+ if (typeof value != "string") {
164
+ return value === 0 ? value : +value;
165
+ }
166
+ value = baseTrim_default(value);
167
+ var isBinary = reIsBinary.test(value);
168
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
169
+ }
170
+ var toNumber_default = toNumber;
171
+
172
+ // node_modules/lodash-es/debounce.js
173
+ var FUNC_ERROR_TEXT = "Expected a function";
174
+ var nativeMax = Math.max;
175
+ var nativeMin = Math.min;
176
+ function debounce(func, wait, options) {
177
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
178
+ if (typeof func != "function") {
179
+ throw new TypeError(FUNC_ERROR_TEXT);
180
+ }
181
+ wait = toNumber_default(wait) || 0;
182
+ if (isObject_default(options)) {
183
+ leading = !!options.leading;
184
+ maxing = "maxWait" in options;
185
+ maxWait = maxing ? nativeMax(toNumber_default(options.maxWait) || 0, wait) : maxWait;
186
+ trailing = "trailing" in options ? !!options.trailing : trailing;
187
+ }
188
+ function invokeFunc(time) {
189
+ var args = lastArgs, thisArg = lastThis;
190
+ lastArgs = lastThis = void 0;
191
+ lastInvokeTime = time;
192
+ result = func.apply(thisArg, args);
193
+ return result;
194
+ }
195
+ function leadingEdge(time) {
196
+ lastInvokeTime = time;
197
+ timerId = setTimeout(timerExpired, wait);
198
+ return leading ? invokeFunc(time) : result;
199
+ }
200
+ function remainingWait(time) {
201
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
202
+ return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
203
+ }
204
+ function shouldInvoke(time) {
205
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
206
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
207
+ }
208
+ function timerExpired() {
209
+ var time = now_default();
210
+ if (shouldInvoke(time)) {
211
+ return trailingEdge(time);
212
+ }
213
+ timerId = setTimeout(timerExpired, remainingWait(time));
214
+ }
215
+ function trailingEdge(time) {
216
+ timerId = void 0;
217
+ if (trailing && lastArgs) {
218
+ return invokeFunc(time);
219
+ }
220
+ lastArgs = lastThis = void 0;
221
+ return result;
222
+ }
223
+ function cancel() {
224
+ if (timerId !== void 0) {
225
+ clearTimeout(timerId);
226
+ }
227
+ lastInvokeTime = 0;
228
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
229
+ }
230
+ function flush() {
231
+ return timerId === void 0 ? result : trailingEdge(now_default());
232
+ }
233
+ function debounced() {
234
+ var time = now_default(), isInvoking = shouldInvoke(time);
235
+ lastArgs = arguments;
236
+ lastThis = this;
237
+ lastCallTime = time;
238
+ if (isInvoking) {
239
+ if (timerId === void 0) {
240
+ return leadingEdge(lastCallTime);
241
+ }
242
+ if (maxing) {
243
+ clearTimeout(timerId);
244
+ timerId = setTimeout(timerExpired, wait);
245
+ return invokeFunc(lastCallTime);
246
+ }
247
+ }
248
+ if (timerId === void 0) {
249
+ timerId = setTimeout(timerExpired, wait);
250
+ }
251
+ return result;
252
+ }
253
+ debounced.cancel = cancel;
254
+ debounced.flush = flush;
255
+ return debounced;
256
+ }
257
+ var debounce_default = debounce;
258
+
259
+ // src/engine/SignalBroker.ts
45
260
  var SignalBroker = class _SignalBroker {
46
261
  // execId -> emitted signals
47
262
  constructor() {
48
263
  this.debug = false;
49
264
  this.verbose = false;
265
+ this.debouncedEmitters = /* @__PURE__ */ new Map();
50
266
  // TODO: Signals should be a class with a the observers, registered flag and other data.
51
267
  this.signalObservers = /* @__PURE__ */ new Map();
52
268
  this.emitStacks = /* @__PURE__ */ new Map();
@@ -133,15 +349,15 @@ var SignalBroker = class _SignalBroker {
133
349
  }
134
350
  }));
135
351
  return {
136
- __signals: processedSignals,
352
+ signals: processedSignals,
137
353
  ...ctx
138
354
  };
139
355
  });
140
356
  this.registerSignalTask = Cadenza.createMetaTask(
141
357
  "Register signal",
142
358
  (ctx) => {
143
- const { __signalName } = ctx;
144
- this.signalObservers.get(__signalName).registered = true;
359
+ const { signalName } = ctx;
360
+ this.signalObservers.get(signalName).registered = true;
145
361
  }
146
362
  ).doOn("meta.signal.registered");
147
363
  }
@@ -210,20 +426,20 @@ var SignalBroker = class _SignalBroker {
210
426
  }
211
427
  const emit = () => this.emit(signal, context);
212
428
  if (leading) {
213
- const now = Date.now();
429
+ const now2 = Date.now();
214
430
  const start = startDateTime?.getTime();
215
- if (!start || start <= now) {
431
+ if (!start || start <= now2) {
216
432
  emit();
217
433
  }
218
434
  }
219
435
  let firstDelay = intervalMs;
220
436
  if (startDateTime) {
221
437
  let slot = startDateTime.getTime();
222
- const now = Date.now();
223
- while (slot < now) {
438
+ const now2 = Date.now();
439
+ while (slot < now2) {
224
440
  slot += intervalMs;
225
441
  }
226
- firstDelay = slot - now;
442
+ firstDelay = slot - now2;
227
443
  }
228
444
  let timer = null;
229
445
  let stopped = false;
@@ -240,6 +456,19 @@ var SignalBroker = class _SignalBroker {
240
456
  }
241
457
  };
242
458
  }
459
+ debounce(signal, context, delayMs = 500) {
460
+ let debouncedEmitter = this.debouncedEmitters.get(signal);
461
+ if (!debouncedEmitter) {
462
+ this.debouncedEmitters.set(
463
+ signal,
464
+ debounce_default((ctx) => {
465
+ this.emit(signal, ctx);
466
+ }, delayMs)
467
+ );
468
+ debouncedEmitter = this.debouncedEmitters.get(signal);
469
+ }
470
+ debouncedEmitter(context);
471
+ }
243
472
  /**
244
473
  * Emits a signal with the specified context, triggering any associated handlers for that signal.
245
474
  *
@@ -407,7 +636,7 @@ var SignalBroker = class _SignalBroker {
407
636
  return;
408
637
  }
409
638
  }
410
- this.emit("meta.signal_broker.added", { __signalName: _signal });
639
+ this.emit("meta.signal_broker.added", { signalName: _signal });
411
640
  }
412
641
  }
413
642
  /**
@@ -2383,6 +2612,7 @@ var Task = class _Task extends SignalEmitter {
2383
2612
  */
2384
2613
  doAfter(...tasks) {
2385
2614
  for (const pred of tasks) {
2615
+ if (!pred) continue;
2386
2616
  if (this.predecessorTasks.has(pred)) continue;
2387
2617
  pred.nextTasks.add(this);
2388
2618
  this.predecessorTasks.add(pred);
@@ -2413,6 +2643,7 @@ var Task = class _Task extends SignalEmitter {
2413
2643
  */
2414
2644
  then(...tasks) {
2415
2645
  for (const next of tasks) {
2646
+ if (!next) continue;
2416
2647
  if (this.nextTasks.has(next)) continue;
2417
2648
  this.nextTasks.add(next);
2418
2649
  next.predecessorTasks.add(this);
@@ -4286,6 +4517,9 @@ var Cadenza = class {
4286
4517
  startDateTime
4287
4518
  );
4288
4519
  }
4520
+ static debounce(signalName, context, delayMs) {
4521
+ this.broker?.debounce(signalName, context, delayMs);
4522
+ }
4289
4523
  static get(taskName) {
4290
4524
  return this.registry?.tasks.get(taskName);
4291
4525
  }