@quazardous/quarkernel 2.2.4 → 2.3.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.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { C as ContextMerger } from './index-BDf1xZi6.cjs';
2
- export { D as CircularDependencyError, b as Composition, E as CompositionEventName, q as CompositionFactory, f as CompositionOptions, e as ConflictInfo, s as ContextMergerFunction, h as EventData, u as EventDataType, i as EventMap, g as EventName, t as EventNames, p as EventStack, r as IComposition, j as IKernel, I as IKernelEvent, k as IListenerContext, a as Kernel, K as KernelEvent, o as KernelOptions, L as ListenerContext, n as ListenerEntry, l as ListenerFunction, m as ListenerOptions, F as MaxListenersExceededError, M as MissingDependencyError, P as PredicateFunction, U as UnbindFunction, d as createComposition, c as createKernel, H as defineMachine, y as isContextMerger, z as isContextMergerFunction, v as isEventName, B as isKernelEvent, w as isListenerFunction, A as isListenerOptions, x as isPredicateFunction, G as useMachine } from './index-BDf1xZi6.cjs';
3
- export { A as ActionFunction, k as AfterDef, h as BehaviorFn, i as BehaviorHelpers, B as BehaviorMachine, j as BuiltInHelpers, C as CreateMachineConfig, F as FSMEventData, G as GuardFunction, a as Machine, M as MachineConfig, b as MachineSnapshot, d as SendOptions, g as StateConfig, e as StateName, S as StateNode, T as TransitionDef, f as TransitionEvent, c as createMachine } from './create-machine-CYsscHPX.cjs';
1
+ import { C as ContextMerger } from './index-KSnUuM2s.cjs';
2
+ export { D as CircularDependencyError, b as Composition, E as CompositionEventName, q as CompositionFactory, f as CompositionOptions, e as ConflictInfo, s as ContextMergerFunction, h as EventData, u as EventDataType, i as EventMap, g as EventName, t as EventNames, p as EventStack, r as IComposition, j as IKernel, I as IKernelEvent, k as IListenerContext, a as Kernel, K as KernelEvent, o as KernelOptions, L as ListenerContext, n as ListenerEntry, l as ListenerFunction, m as ListenerOptions, F as MaxListenersExceededError, M as MissingDependencyError, P as PredicateFunction, U as UnbindFunction, d as createComposition, c as createKernel, H as defineMachine, y as isContextMerger, z as isContextMergerFunction, v as isEventName, B as isKernelEvent, w as isListenerFunction, A as isListenerOptions, x as isPredicateFunction, G as useMachine } from './index-KSnUuM2s.cjs';
3
+ export { A as ActionFunction, k as AfterDef, h as BehaviorFn, i as BehaviorHelpers, B as BehaviorMachine, j as BuiltInHelpers, C as CreateMachineConfig, F as FSMEventData, G as GuardFunction, a as Machine, M as MachineConfig, b as MachineSnapshot, d as SendOptions, g as StateConfig, e as StateName, S as StateNode, T as TransitionDef, f as TransitionEvent, c as createMachine } from './create-machine-SGkCnU0g.cjs';
4
4
  export { ImportOptions, XStateConfigWithActions, XStateMachineConfig, formatStateCentricCode, fromXState, toXStateFormat } from './xstate.cjs';
5
5
 
6
6
  /**
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { C as ContextMerger } from './index-BPMXiW32.js';
2
- export { D as CircularDependencyError, b as Composition, E as CompositionEventName, q as CompositionFactory, f as CompositionOptions, e as ConflictInfo, s as ContextMergerFunction, h as EventData, u as EventDataType, i as EventMap, g as EventName, t as EventNames, p as EventStack, r as IComposition, j as IKernel, I as IKernelEvent, k as IListenerContext, a as Kernel, K as KernelEvent, o as KernelOptions, L as ListenerContext, n as ListenerEntry, l as ListenerFunction, m as ListenerOptions, F as MaxListenersExceededError, M as MissingDependencyError, P as PredicateFunction, U as UnbindFunction, d as createComposition, c as createKernel, H as defineMachine, y as isContextMerger, z as isContextMergerFunction, v as isEventName, B as isKernelEvent, w as isListenerFunction, A as isListenerOptions, x as isPredicateFunction, G as useMachine } from './index-BPMXiW32.js';
3
- export { A as ActionFunction, k as AfterDef, h as BehaviorFn, i as BehaviorHelpers, B as BehaviorMachine, j as BuiltInHelpers, C as CreateMachineConfig, F as FSMEventData, G as GuardFunction, a as Machine, M as MachineConfig, b as MachineSnapshot, d as SendOptions, g as StateConfig, e as StateName, S as StateNode, T as TransitionDef, f as TransitionEvent, c as createMachine } from './create-machine-CYsscHPX.js';
1
+ import { C as ContextMerger } from './index-0UbjHkkt.js';
2
+ export { D as CircularDependencyError, b as Composition, E as CompositionEventName, q as CompositionFactory, f as CompositionOptions, e as ConflictInfo, s as ContextMergerFunction, h as EventData, u as EventDataType, i as EventMap, g as EventName, t as EventNames, p as EventStack, r as IComposition, j as IKernel, I as IKernelEvent, k as IListenerContext, a as Kernel, K as KernelEvent, o as KernelOptions, L as ListenerContext, n as ListenerEntry, l as ListenerFunction, m as ListenerOptions, F as MaxListenersExceededError, M as MissingDependencyError, P as PredicateFunction, U as UnbindFunction, d as createComposition, c as createKernel, H as defineMachine, y as isContextMerger, z as isContextMergerFunction, v as isEventName, B as isKernelEvent, w as isListenerFunction, A as isListenerOptions, x as isPredicateFunction, G as useMachine } from './index-0UbjHkkt.js';
3
+ export { A as ActionFunction, k as AfterDef, h as BehaviorFn, i as BehaviorHelpers, B as BehaviorMachine, j as BuiltInHelpers, C as CreateMachineConfig, F as FSMEventData, G as GuardFunction, a as Machine, M as MachineConfig, b as MachineSnapshot, d as SendOptions, g as StateConfig, e as StateName, S as StateNode, T as TransitionDef, f as TransitionEvent, c as createMachine } from './create-machine-SGkCnU0g.js';
4
4
  export { ImportOptions, XStateConfigWithActions, XStateMachineConfig, formatStateCentricCode, fromXState, toXStateFormat } from './xstate.js';
5
5
 
6
6
  /**
package/dist/index.js CHANGED
@@ -502,6 +502,39 @@ var Composition = class {
502
502
  onComposed(listener, options) {
503
503
  return this.kernel.on(COMPOSED_EVENT, listener, options);
504
504
  }
505
+ /**
506
+ * Wait for the next composition completion as a Promise
507
+ *
508
+ * @param options - Optional timeout configuration
509
+ * @returns Promise resolving with composed event data
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * // .then() receives: { sources, contexts, merged }
514
+ * const result = await composition.once();
515
+ * console.log(result.data.merged); // merged context from all sources
516
+ * console.log(result.data.sources); // ['event1', 'event2']
517
+ *
518
+ * // With timeout
519
+ * const result = await composition.once({ timeout: 5000 });
520
+ * ```
521
+ */
522
+ once(options) {
523
+ return new Promise((resolve, reject) => {
524
+ let timeoutId;
525
+ const listener = (event) => {
526
+ if (timeoutId) clearTimeout(timeoutId);
527
+ resolve(event);
528
+ };
529
+ const unbind = this.kernel.on(COMPOSED_EVENT, listener, { once: true });
530
+ if (options?.timeout) {
531
+ timeoutId = setTimeout(() => {
532
+ unbind();
533
+ reject(new Error(`composition.once() timed out after ${options.timeout}ms`));
534
+ }, options.timeout);
535
+ }
536
+ });
537
+ }
505
538
  /**
506
539
  * Remove a listener for composed events
507
540
  */
@@ -756,6 +789,42 @@ var Kernel = class _Kernel {
756
789
  }
757
790
  return () => this.off(event, listener);
758
791
  }
792
+ /**
793
+ * Wait for an event once (Promise-based)
794
+ *
795
+ * For callback style, use: `qk.on(event, listener, { once: true })`
796
+ *
797
+ * @param eventName - Event to wait for
798
+ * @param options - Optional timeout in ms
799
+ * @returns Promise resolving with the event
800
+ *
801
+ * @example
802
+ * ```typescript
803
+ * // .then() receives: IKernelEvent { name, data, context, timestamp }
804
+ * const event = await qk.once('user:loaded');
805
+ * console.log(event.data); // event payload
806
+ * console.log(event.context); // shared context
807
+ *
808
+ * // With timeout (rejects if event doesn't fire)
809
+ * const event = await qk.once('user:loaded', { timeout: 5000 });
810
+ * ```
811
+ */
812
+ once(eventName, options) {
813
+ return new Promise((resolve, reject) => {
814
+ let timeoutId;
815
+ const listener = (event) => {
816
+ if (timeoutId) clearTimeout(timeoutId);
817
+ resolve(event);
818
+ };
819
+ const unbind = this.on(eventName, listener, { once: true });
820
+ if (options?.timeout) {
821
+ timeoutId = setTimeout(() => {
822
+ unbind();
823
+ reject(new Error(`once('${String(eventName)}') timed out after ${options.timeout}ms`));
824
+ }, options.timeout);
825
+ }
826
+ });
827
+ }
759
828
  /**
760
829
  * Remove an event listener
761
830
  * If no listener provided, removes all listeners for the event
@@ -1412,6 +1481,37 @@ function useMachine(kernel, config) {
1412
1481
  history = [...snapshot2.history];
1413
1482
  }
1414
1483
  },
1484
+ waitFor(targetState, options) {
1485
+ if (currentState === targetState) {
1486
+ return Promise.resolve({
1487
+ state: currentState,
1488
+ context: structuredClone(context)
1489
+ });
1490
+ }
1491
+ return new Promise((resolve, reject) => {
1492
+ let timeoutId;
1493
+ const unbind = kernel.on(
1494
+ `${prefix}:enter:${targetState}`,
1495
+ (event) => {
1496
+ if (timeoutId) clearTimeout(timeoutId);
1497
+ unbind();
1498
+ resolve({
1499
+ state: targetState,
1500
+ from: event.data?.from,
1501
+ event: event.data?.event,
1502
+ context: structuredClone(context)
1503
+ });
1504
+ }
1505
+ );
1506
+ cleanupFns.push(unbind);
1507
+ if (options?.timeout) {
1508
+ timeoutId = setTimeout(() => {
1509
+ unbind();
1510
+ reject(new Error(`waitFor('${targetState}') timed out after ${options.timeout}ms`));
1511
+ }, options.timeout);
1512
+ }
1513
+ });
1514
+ },
1415
1515
  destroy() {
1416
1516
  for (const cleanup of cleanupFns) {
1417
1517
  cleanup();