slapflow 1.1.0 → 1.2.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.cjs CHANGED
@@ -20,14 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ BUILTIN_ACTIONS: () => BUILTIN_ACTIONS,
24
+ BUILTIN_ACTION_NAMES: () => BUILTIN_ACTION_NAMES,
25
+ BUILTIN_CONDITIONS: () => BUILTIN_CONDITIONS,
26
+ BUILTIN_CONDITION_NAMES: () => BUILTIN_CONDITION_NAMES,
23
27
  PubSub: () => PubSub,
24
28
  catchError: () => catchError,
25
- createActionsRegistry: () => createActionsRegistry,
26
- createConditionsRegistry: () => createConditionsRegistry,
27
29
  createFlow: () => createFlow,
28
30
  createMemoryTraceSink: () => createMemoryTraceSink,
29
31
  createPubSub: () => createPubSub,
30
32
  createWS: () => createWS,
33
+ createWebSocket: () => createWebSocket,
31
34
  defineConfig: () => defineConfig,
32
35
  defineErrorReporter: () => defineErrorReporter
33
36
  });
@@ -36,9 +39,6 @@ module.exports = __toCommonJS(index_exports);
36
39
  // src/helpers/config/defineConfig.ts
37
40
  var defineConfig = (config) => config;
38
41
 
39
- // src/helpers/trace/cloneData.ts
40
- var cloneData = (data) => ({ ...data });
41
-
42
42
  // src/helpers/trace/createMemoryTraceSink.ts
43
43
  var createMemoryTraceSink = () => {
44
44
  const items = [];
@@ -50,22 +50,9 @@ var createMemoryTraceSink = () => {
50
50
  };
51
51
  };
52
52
 
53
- // src/helpers/errors/slapError.ts
54
- var slapError = (code, message, extras = {}) => ({ code, message, ...extras });
55
-
56
53
  // src/helpers/errors/defineErrorReporter.ts
57
54
  var defineErrorReporter = (handlers) => typeof handlers === "function" ? handlers : handlers.report;
58
55
 
59
- // src/errors.ts
60
- var SyncAsyncError = class extends Error {
61
- slapError;
62
- constructor(error) {
63
- super(error.message);
64
- this.name = "SyncAsyncError";
65
- this.slapError = error;
66
- }
67
- };
68
-
69
56
  // src/helpers/ids/createId.ts
70
57
  var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
71
58
  var idLength = 12;
@@ -105,7 +92,7 @@ var serializeError = (error) => ({
105
92
  error: error instanceof Error ? error.message : String(error)
106
93
  });
107
94
 
108
- // src/pubSub.ts
95
+ // src/createPubSub.ts
109
96
  var createPubSub = (options = {}) => {
110
97
  const subscribers = /* @__PURE__ */ new Map();
111
98
  const wildcardSubscribers = /* @__PURE__ */ new Map();
@@ -203,6 +190,16 @@ var createPubSub = (options = {}) => {
203
190
  };
204
191
  var PubSub = createPubSub();
205
192
 
193
+ // src/helpers/errors/syncAsyncError.ts
194
+ var SyncAsyncError = class extends Error {
195
+ slapError;
196
+ constructor(error) {
197
+ super(error.message);
198
+ this.name = "SyncAsyncError";
199
+ this.slapError = error;
200
+ }
201
+ };
202
+
206
203
  // src/helpers/actions/coreDelay.ts
207
204
  var coreDelay = async ({
208
205
  props,
@@ -239,10 +236,7 @@ var coreEmit = ({
239
236
  };
240
237
 
241
238
  // src/helpers/actions/coreFail.ts
242
- var coreFail = ({
243
- props,
244
- runtime
245
- }) => runtime.fail(String(props.reason ?? "failed"), props.data);
239
+ var coreFail = ({ props, runtime }) => runtime.fail(String(props.reason ?? "failed"), props.data);
246
240
 
247
241
  // src/helpers/retry/getRetryDelay.ts
248
242
  var getRetryDelay = (attempt, options) => {
@@ -449,10 +443,7 @@ var corePatch = ({
449
443
  };
450
444
 
451
445
  // src/helpers/actions/coreSet.ts
452
- var coreSet = ({
453
- props,
454
- runtime
455
- }) => {
446
+ var coreSet = ({ props, runtime }) => {
456
447
  const path = props.path;
457
448
  if (typeof path === "string") {
458
449
  runtime.set(path, props.value);
@@ -473,13 +464,10 @@ var coreSetData = ({
473
464
  };
474
465
 
475
466
  // src/helpers/actions/coreStop.ts
476
- var coreStop = ({
477
- props,
478
- runtime
479
- }) => runtime.stop(String(props.reason ?? "stopped"));
467
+ var coreStop = ({ props, runtime }) => runtime.stop(String(props.reason ?? "stopped"));
480
468
 
481
- // src/registry/actions.ts
482
- var createActionsRegistry = () => /* @__PURE__ */ new Map([
469
+ // src/helpers/actions/index.ts
470
+ var BUILTIN_ACTIONS = [
483
471
  ["core.noop", coreNoop],
484
472
  ["core.stop", coreStop],
485
473
  ["core.fail", coreFail],
@@ -493,7 +481,8 @@ var createActionsRegistry = () => /* @__PURE__ */ new Map([
493
481
  ["core.emit", coreEmit],
494
482
  ["core.patch", corePatch],
495
483
  ["core.delay", coreDelay]
496
- ]);
484
+ ];
485
+ var BUILTIN_ACTION_NAMES = new Set(BUILTIN_ACTIONS.map(([name]) => name));
497
486
 
498
487
  // src/helpers/conditions/changedCondition.ts
499
488
  var changedCondition = (_args, current, previous) => !Object.is(current, previous);
@@ -587,8 +576,8 @@ var typeIsCondition = (_args, value, expected) => {
587
576
  return expected === "string" || expected === "number" || expected === "boolean" ? typeof value === expected : false;
588
577
  };
589
578
 
590
- // src/registry/conditions.ts
591
- var createConditionsRegistry = () => /* @__PURE__ */ new Map([
579
+ // src/helpers/conditions/index.ts
580
+ var BUILTIN_CONDITIONS = [
592
581
  ["eq", eqCondition],
593
582
  ["neq", neqCondition],
594
583
  ["gt", gtCondition],
@@ -605,7 +594,8 @@ var createConditionsRegistry = () => /* @__PURE__ */ new Map([
605
594
  ["typeIs", typeIsCondition],
606
595
  ["changed", changedCondition],
607
596
  ["cooldownReady", cooldownReadyCondition]
608
- ]);
597
+ ];
598
+ var BUILTIN_CONDITION_NAMES = new Set(BUILTIN_CONDITIONS.map(([name]) => name));
609
599
 
610
600
  // src/helpers/runner/applyResult.ts
611
601
  var applyResult = (result, state, mergeData) => {
@@ -619,6 +609,9 @@ var applyResult = (result, state, mergeData) => {
619
609
  state.events.push(...result.events);
620
610
  };
621
611
 
612
+ // src/helpers/errors/slapError.ts
613
+ var slapError = (code, message, extras = {}) => ({ code, message, ...extras });
614
+
622
615
  // src/helpers/path/resolveValue.ts
623
616
  var import_objwalk3 = require("objwalk");
624
617
 
@@ -1057,7 +1050,7 @@ var executeNext = (item, depth, state, environment) => {
1057
1050
  const id = typeof item === "string" ? item : item.strategy;
1058
1051
  if (typeof item !== "string" && item.when) {
1059
1052
  const runtime = createRuntime(state);
1060
- const condition = evaluateCondition(item.when, environment.conditionsRegistry, { ...state, runtime, strategy: id });
1053
+ const condition = evaluateCondition(item.when, environment.registry.conditions, { ...state, runtime, strategy: id });
1061
1054
  if (!condition.ok) {
1062
1055
  return { status: "failed", error: condition.error, patches: [], events: [] };
1063
1056
  }
@@ -1309,6 +1302,9 @@ var normalizeActionResult = (raw) => {
1309
1302
  };
1310
1303
  };
1311
1304
 
1305
+ // src/helpers/trace/cloneData.ts
1306
+ var cloneData = (data) => ({ ...data });
1307
+
1312
1308
  // src/helpers/runner/pushTrace.ts
1313
1309
  var pushTrace = (state, step, depth, strategyId, strategy, status, props, dataBefore, startedAt, reason) => {
1314
1310
  state.traceSink?.push({
@@ -1491,7 +1487,7 @@ var executeStrategy = (id, extraProps, depth, state, environment) => {
1491
1487
  events: []
1492
1488
  };
1493
1489
  }
1494
- const action = environment.actionsRegistry.get(strategy.fn);
1490
+ const action = environment.registry.actions.get(strategy.fn);
1495
1491
  if (!action) {
1496
1492
  return {
1497
1493
  status: "failed",
@@ -1546,7 +1542,7 @@ var executeStrategy = (id, extraProps, depth, state, environment) => {
1546
1542
  const dataBefore = cloneData(state.data);
1547
1543
  const traceStep = state.stepCounter.current + 1;
1548
1544
  const startedAt = Date.now();
1549
- const condition = evaluateCondition(strategy.when, environment.conditionsRegistry, {
1545
+ const condition = evaluateCondition(strategy.when, environment.registry.conditions, {
1550
1546
  ...state,
1551
1547
  runtime,
1552
1548
  strategy: id
@@ -1860,7 +1856,12 @@ var validateCondition = (expression, strategy, path, conditionsRegistry, errors)
1860
1856
  const [operator, ...args] = expression;
1861
1857
  if (operator === "guard") {
1862
1858
  if (args.length !== 1 || typeof args[0] !== "string") {
1863
- errors.push({ code: "CONDITION_INVALID", message: "Guard reference must be a single string name", strategy, path });
1859
+ errors.push({
1860
+ code: "CONDITION_INVALID",
1861
+ message: "Guard reference must be a single string name",
1862
+ strategy,
1863
+ path
1864
+ });
1864
1865
  }
1865
1866
  return;
1866
1867
  }
@@ -1913,7 +1914,9 @@ var validateNextList = (config, list, path, strategy, conditionsRegistry, errors
1913
1914
  var isGuardRef = (expression) => Array.isArray(expression) && expression.length === 2 && expression[0] === "guard" && typeof expression[1] === "string";
1914
1915
  var resolveRef = (config, name, visiting, path) => {
1915
1916
  if (visiting.includes(name)) {
1916
- return { issue: { code: "GUARD_CYCLE", message: `Guard "${name}" is part of a reference cycle`, guard: name, path } };
1917
+ return {
1918
+ issue: { code: "GUARD_CYCLE", message: `Guard "${name}" is part of a reference cycle`, guard: name, path }
1919
+ };
1917
1920
  }
1918
1921
  const guard = config.guards?.[name];
1919
1922
  if (guard === void 0) {
@@ -2136,10 +2139,10 @@ var createRunCancellation = (source) => {
2136
2139
  };
2137
2140
  };
2138
2141
 
2139
- // src/helpers/runner/createRunner.ts
2142
+ // src/createRunner.ts
2140
2143
  var createRunner = (options = {}) => {
2141
- const actionsRegistry = createActionsRegistry();
2142
- const conditionsRegistry = createConditionsRegistry();
2144
+ const actionsRegistry = new Map(BUILTIN_ACTIONS);
2145
+ const conditionsRegistry = new Map(BUILTIN_CONDITIONS);
2143
2146
  const configRef = {};
2144
2147
  const timeout = options.timeout ?? options.timeoutMs;
2145
2148
  const runnerOptions = timeout === void 0 ? options : { ...options, timeout };
@@ -2149,19 +2152,24 @@ var createRunner = (options = {}) => {
2149
2152
  console.warn("timeoutMs is deprecated; use timeout. It will be removed in a future major release.");
2150
2153
  }
2151
2154
  const environment = {
2152
- actionsRegistry,
2153
- conditionsRegistry,
2155
+ registry: { actions: actionsRegistry, conditions: conditionsRegistry },
2154
2156
  configRef,
2155
2157
  options: runnerOptions,
2156
2158
  mergeData
2157
2159
  };
2158
2160
  const registerAction = (name, action) => {
2161
+ if (BUILTIN_ACTION_NAMES.has(name)) {
2162
+ throw new Error(`Cannot override built-in action "${name}"`);
2163
+ }
2159
2164
  actionsRegistry.set(name, action);
2160
2165
  };
2161
2166
  const registerActions = (items) => {
2162
2167
  Object.entries(items).forEach(([name, action]) => registerAction(name, action));
2163
2168
  };
2164
2169
  const registerCondition = (name, condition) => {
2170
+ if (BUILTIN_CONDITION_NAMES.has(name)) {
2171
+ throw new Error(`Cannot override built-in condition "${name}"`);
2172
+ }
2165
2173
  conditionsRegistry.set(name, condition);
2166
2174
  };
2167
2175
  const registerConditions = (items) => {
@@ -2258,7 +2266,7 @@ var parseDomBinding = (binding, prefix) => {
2258
2266
  return separator <= 0 || separator === source.length - 1 ? void 0 : { selector: source.slice(0, separator), eventType: source.slice(separator + 1) };
2259
2267
  };
2260
2268
 
2261
- // src/flow.ts
2269
+ // src/createFlow.ts
2262
2270
  var busBindingPrefix = "[bus] ";
2263
2271
  var domBindingPrefix = "[dom] ";
2264
2272
  var defaultMaxQueueSize = 50;
@@ -2499,10 +2507,11 @@ var createFlow = (definition, options) => {
2499
2507
  return { runner, start, stop };
2500
2508
  };
2501
2509
 
2502
- // src/ws.ts
2510
+ // src/createWS.ts
2503
2511
  var openState = 1;
2504
2512
  var maxSeenEvents = 1e3;
2505
2513
  var createWS = (options) => {
2514
+ console.warn("[slapflow] createWS is deprecated and will be removed soon. Use createWebSocket instead.");
2506
2515
  const inboundTopics = new Set(options.inboundTopics ?? []);
2507
2516
  const outboundTopics = new Set(options.outboundTopics ?? []);
2508
2517
  const seenEventIds = /* @__PURE__ */ new Set();
@@ -2666,7 +2675,150 @@ var createWS = (options) => {
2666
2675
  return { start, stop, reconnect, status: () => currentStatus };
2667
2676
  };
2668
2677
 
2669
- // src/catchError.ts
2678
+ // src/helpers/parsePayload.ts
2679
+ var parsePayload = (data) => {
2680
+ if (typeof data === "string") {
2681
+ try {
2682
+ return JSON.parse(data);
2683
+ } catch {
2684
+ return data;
2685
+ }
2686
+ }
2687
+ return data;
2688
+ };
2689
+
2690
+ // src/createWebSocket.ts
2691
+ var WebSocketConnection = class {
2692
+ constructor(options) {
2693
+ this.options = options;
2694
+ }
2695
+ options;
2696
+ _socket;
2697
+ _retryTimer;
2698
+ _retryAttempt = 0;
2699
+ _queue = [];
2700
+ _started = false;
2701
+ _status = "idle";
2702
+ start() {
2703
+ if (!this._started) {
2704
+ this._started = true;
2705
+ this.connect();
2706
+ }
2707
+ }
2708
+ stop() {
2709
+ this._started = false;
2710
+ this.clearTimer();
2711
+ this.clearQueue();
2712
+ const current = this._socket;
2713
+ this._socket = void 0;
2714
+ current?.close();
2715
+ this.setStatus("stopped");
2716
+ }
2717
+ reconnect() {
2718
+ if (this._started) {
2719
+ this.clearTimer();
2720
+ const current = this._socket;
2721
+ this._socket = void 0;
2722
+ current?.close();
2723
+ this.connect();
2724
+ }
2725
+ }
2726
+ status() {
2727
+ return this._status;
2728
+ }
2729
+ send(data) {
2730
+ if (this._socket?.readyState === WebSocket.OPEN) {
2731
+ this._socket.send(data);
2732
+ } else {
2733
+ this._queue.push(data);
2734
+ }
2735
+ }
2736
+ connect() {
2737
+ if (!this._started || this._socket) {
2738
+ return;
2739
+ }
2740
+ const { url, protocols } = this.options;
2741
+ const current = new WebSocket(url, protocols ?? []);
2742
+ this._socket = current;
2743
+ this.setStatus("connecting");
2744
+ current.addEventListener("open", () => this.onOpen(current));
2745
+ current.addEventListener("message", (event) => this.onMessage(current, event));
2746
+ current.addEventListener("close", (event) => this.onClose(current, event));
2747
+ current.addEventListener("error", (event) => this.onError(current, event));
2748
+ }
2749
+ onOpen(current) {
2750
+ if (this._socket === current) {
2751
+ this._retryAttempt = 0;
2752
+ this.setStatus("connected");
2753
+ this.flush();
2754
+ this.dispatch("open", { url: this.options.url });
2755
+ }
2756
+ }
2757
+ onMessage(current, event) {
2758
+ if (this._socket === current) {
2759
+ this.dispatch("message", parsePayload(event.data));
2760
+ }
2761
+ }
2762
+ onClose(current, event) {
2763
+ if (this._socket === current) {
2764
+ this._socket = void 0;
2765
+ this.dispatch("close", event);
2766
+ if (this._started) {
2767
+ this.retry();
2768
+ }
2769
+ }
2770
+ }
2771
+ onError(current, event) {
2772
+ if (this._socket === current) {
2773
+ this.dispatch("error", serializeError(event.error));
2774
+ }
2775
+ }
2776
+ dispatch(topic, parsed) {
2777
+ const { bus, origin } = this.options;
2778
+ bus.dispatch({
2779
+ id: createId(),
2780
+ topic,
2781
+ occurredAt: Date.now(),
2782
+ ...origin ? { origin } : {},
2783
+ parsed,
2784
+ serialized: JSON.stringify(parsed)
2785
+ });
2786
+ }
2787
+ flush() {
2788
+ if (this._socket && this._socket.readyState === WebSocket.OPEN) {
2789
+ for (const message of this._queue) {
2790
+ this._socket.send(message);
2791
+ }
2792
+ this.clearQueue();
2793
+ }
2794
+ }
2795
+ retry() {
2796
+ this.setStatus("reconnecting");
2797
+ this._retryTimer = setTimeout(
2798
+ () => {
2799
+ this._retryTimer = void 0;
2800
+ this.connect();
2801
+ },
2802
+ getRetryDelay(this._retryAttempt, this.options.reconnect ?? {})
2803
+ );
2804
+ this._retryAttempt = this._retryAttempt + 1;
2805
+ }
2806
+ setStatus(status) {
2807
+ this._status = status || "idle";
2808
+ }
2809
+ clearQueue() {
2810
+ this._queue = [];
2811
+ }
2812
+ clearTimer() {
2813
+ if (this._retryTimer) {
2814
+ clearTimeout(this._retryTimer);
2815
+ }
2816
+ this._retryTimer = void 0;
2817
+ }
2818
+ };
2819
+ var createWebSocket = (options) => new WebSocketConnection(options);
2820
+
2821
+ // src/helpers/catchError.ts
2670
2822
  var catchError = (callback) => new Promise((resolve, reject) => {
2671
2823
  try {
2672
2824
  resolve(callback());
@@ -2676,14 +2828,17 @@ var catchError = (callback) => new Promise((resolve, reject) => {
2676
2828
  });
2677
2829
  // Annotate the CommonJS export names for ESM import in node:
2678
2830
  0 && (module.exports = {
2831
+ BUILTIN_ACTIONS,
2832
+ BUILTIN_ACTION_NAMES,
2833
+ BUILTIN_CONDITIONS,
2834
+ BUILTIN_CONDITION_NAMES,
2679
2835
  PubSub,
2680
2836
  catchError,
2681
- createActionsRegistry,
2682
- createConditionsRegistry,
2683
2837
  createFlow,
2684
2838
  createMemoryTraceSink,
2685
2839
  createPubSub,
2686
2840
  createWS,
2841
+ createWebSocket,
2687
2842
  defineConfig,
2688
2843
  defineErrorReporter
2689
2844
  });
package/dist/index.d.cts CHANGED
@@ -148,6 +148,22 @@ type WS = {
148
148
  reconnect(): void;
149
149
  status(): WSStatus;
150
150
  };
151
+ type SocketEventTopic = 'open' | 'message' | 'close' | 'error';
152
+ type WebSocketOptions<TEvents extends object = EventMap> = {
153
+ url: string;
154
+ bus: Bus<TEvents>;
155
+ origin?: string;
156
+ protocols?: string | string[];
157
+ reconnect?: RetryOptions;
158
+ };
159
+ type WebSocketStatus = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'stopped';
160
+ type WSClient = {
161
+ start(): void;
162
+ stop(): void;
163
+ reconnect(): void;
164
+ status(): WebSocketStatus;
165
+ send(data: string): void;
166
+ };
151
167
  type BindingEventMap = Record<string, Input>;
152
168
  type BusBindingKey<TEvents extends object> = {
153
169
  [TEvent in EventName<TEvents>]: TEvents[TEvent] extends Input ? `[bus] ${TEvent}` : never;
@@ -374,14 +390,21 @@ declare const PubSub: Bus<EventMap>;
374
390
 
375
391
  declare const createFlow: <TContext, TPatch = unknown, TEvents extends object = BindingEventMap>(definition: FlowDefinition<TContext, TPatch, TEvents>, options: FlowOptions<TContext, TPatch, TEvents>) => Flow<TContext, TPatch>;
376
392
 
393
+ /**
394
+ * @deprecated Use `createWebSocket` instead. This adapter will be removed in a future release.
395
+ */
377
396
  declare const createWS: <TEvents extends object = EventMap>(options: WSOptions<TEvents>) => WS;
378
397
 
398
+ declare const createWebSocket: <TEvents extends object = EventMap>(options: WebSocketOptions<TEvents>) => WSClient;
399
+
379
400
  declare const catchError: <T>(callback: () => T | PromiseLike<T>) => Promise<T>;
380
401
 
381
402
  type ActionsRegistry<TContext, TPatch> = Map<string, Action<TContext, TPatch>>;
382
- declare const createActionsRegistry: <TContext, TPatch>() => ActionsRegistry<TContext, TPatch>;
403
+ declare const BUILTIN_ACTIONS: readonly [name: string, action: Action<unknown, unknown>][];
404
+ declare const BUILTIN_ACTION_NAMES: Set<string>;
383
405
 
384
406
  type ConditionsRegistry<TContext> = Map<string, ConditionFn<TContext>>;
385
- declare const createConditionsRegistry: <TContext>() => ConditionsRegistry<TContext>;
407
+ declare const BUILTIN_CONDITIONS: readonly [name: string, condition: ConditionFn<unknown>][];
408
+ declare const BUILTIN_CONDITION_NAMES: Set<string>;
386
409
 
387
- export { type Action, type ActionArgs, type ActionFail, type ActionResult, type ActionSkip, type ActionStop, type ActionSuccess, type ActionsRegistry, type BindingEventMap, type Bus, type BusBinding, type BusBindingKey, type BusBindings, type BusEmitOptions, type BusErrorEvent, type BusEvent, type BusOptions, type ConcurrencyMode, type ConcurrencyOptions, type ConditionExpression, type ConditionFn, type ConditionsRegistry, type Config, type DomBinding, type DomBindingKey, type DomBindings, type DomForm, type DomInput, type ErrorReporter, type ErrorReporterHandlers, type ErrorStage, type EventHandler, type EventMap, type EventName, type EventPattern, type ExpressionOperator, type FetchResponseType, type Flow, type FlowDefinition, type FlowOptions, type InactiveBinding, type Input, type Mode, type Next, type Props, PubSub, type QueueOverflow, type RetryOptions, type RunOptions, type RunResult, type Runner, type RunnerErrorEvent, type RunnerOptions, type Runtime, type SlapError, type SlapErrorEvent, type SlapEvent, type StartResult, type Strategy, type TraceEntry, type TraceSink, type ValidationIssue, type ValidationResult, type VariableValue, type Variables, type WS, type WSOptions, type WSRetryOptions, type WSSocket, type WSStatus, catchError, createActionsRegistry, createConditionsRegistry, createFlow, createMemoryTraceSink, createPubSub, createWS, defineConfig, defineErrorReporter };
410
+ export { type Action, type ActionArgs, type ActionFail, type ActionResult, type ActionSkip, type ActionStop, type ActionSuccess, type ActionsRegistry, BUILTIN_ACTIONS, BUILTIN_ACTION_NAMES, BUILTIN_CONDITIONS, BUILTIN_CONDITION_NAMES, type BindingEventMap, type Bus, type BusBinding, type BusBindingKey, type BusBindings, type BusEmitOptions, type BusErrorEvent, type BusEvent, type BusOptions, type ConcurrencyMode, type ConcurrencyOptions, type ConditionExpression, type ConditionFn, type ConditionsRegistry, type Config, type DomBinding, type DomBindingKey, type DomBindings, type DomForm, type DomInput, type ErrorReporter, type ErrorReporterHandlers, type ErrorStage, type EventHandler, type EventMap, type EventName, type EventPattern, type ExpressionOperator, type FetchResponseType, type Flow, type FlowDefinition, type FlowOptions, type InactiveBinding, type Input, type Mode, type Next, type Props, PubSub, type QueueOverflow, type RetryOptions, type RunOptions, type RunResult, type Runner, type RunnerErrorEvent, type RunnerOptions, type Runtime, type SlapError, type SlapErrorEvent, type SlapEvent, type SocketEventTopic, type StartResult, type Strategy, type TraceEntry, type TraceSink, type ValidationIssue, type ValidationResult, type VariableValue, type Variables, type WS, type WSClient, type WSOptions, type WSRetryOptions, type WSSocket, type WSStatus, type WebSocketOptions, type WebSocketStatus, catchError, createFlow, createMemoryTraceSink, createPubSub, createWS, createWebSocket, defineConfig, defineErrorReporter };
package/dist/index.d.ts CHANGED
@@ -148,6 +148,22 @@ type WS = {
148
148
  reconnect(): void;
149
149
  status(): WSStatus;
150
150
  };
151
+ type SocketEventTopic = 'open' | 'message' | 'close' | 'error';
152
+ type WebSocketOptions<TEvents extends object = EventMap> = {
153
+ url: string;
154
+ bus: Bus<TEvents>;
155
+ origin?: string;
156
+ protocols?: string | string[];
157
+ reconnect?: RetryOptions;
158
+ };
159
+ type WebSocketStatus = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'stopped';
160
+ type WSClient = {
161
+ start(): void;
162
+ stop(): void;
163
+ reconnect(): void;
164
+ status(): WebSocketStatus;
165
+ send(data: string): void;
166
+ };
151
167
  type BindingEventMap = Record<string, Input>;
152
168
  type BusBindingKey<TEvents extends object> = {
153
169
  [TEvent in EventName<TEvents>]: TEvents[TEvent] extends Input ? `[bus] ${TEvent}` : never;
@@ -374,14 +390,21 @@ declare const PubSub: Bus<EventMap>;
374
390
 
375
391
  declare const createFlow: <TContext, TPatch = unknown, TEvents extends object = BindingEventMap>(definition: FlowDefinition<TContext, TPatch, TEvents>, options: FlowOptions<TContext, TPatch, TEvents>) => Flow<TContext, TPatch>;
376
392
 
393
+ /**
394
+ * @deprecated Use `createWebSocket` instead. This adapter will be removed in a future release.
395
+ */
377
396
  declare const createWS: <TEvents extends object = EventMap>(options: WSOptions<TEvents>) => WS;
378
397
 
398
+ declare const createWebSocket: <TEvents extends object = EventMap>(options: WebSocketOptions<TEvents>) => WSClient;
399
+
379
400
  declare const catchError: <T>(callback: () => T | PromiseLike<T>) => Promise<T>;
380
401
 
381
402
  type ActionsRegistry<TContext, TPatch> = Map<string, Action<TContext, TPatch>>;
382
- declare const createActionsRegistry: <TContext, TPatch>() => ActionsRegistry<TContext, TPatch>;
403
+ declare const BUILTIN_ACTIONS: readonly [name: string, action: Action<unknown, unknown>][];
404
+ declare const BUILTIN_ACTION_NAMES: Set<string>;
383
405
 
384
406
  type ConditionsRegistry<TContext> = Map<string, ConditionFn<TContext>>;
385
- declare const createConditionsRegistry: <TContext>() => ConditionsRegistry<TContext>;
407
+ declare const BUILTIN_CONDITIONS: readonly [name: string, condition: ConditionFn<unknown>][];
408
+ declare const BUILTIN_CONDITION_NAMES: Set<string>;
386
409
 
387
- export { type Action, type ActionArgs, type ActionFail, type ActionResult, type ActionSkip, type ActionStop, type ActionSuccess, type ActionsRegistry, type BindingEventMap, type Bus, type BusBinding, type BusBindingKey, type BusBindings, type BusEmitOptions, type BusErrorEvent, type BusEvent, type BusOptions, type ConcurrencyMode, type ConcurrencyOptions, type ConditionExpression, type ConditionFn, type ConditionsRegistry, type Config, type DomBinding, type DomBindingKey, type DomBindings, type DomForm, type DomInput, type ErrorReporter, type ErrorReporterHandlers, type ErrorStage, type EventHandler, type EventMap, type EventName, type EventPattern, type ExpressionOperator, type FetchResponseType, type Flow, type FlowDefinition, type FlowOptions, type InactiveBinding, type Input, type Mode, type Next, type Props, PubSub, type QueueOverflow, type RetryOptions, type RunOptions, type RunResult, type Runner, type RunnerErrorEvent, type RunnerOptions, type Runtime, type SlapError, type SlapErrorEvent, type SlapEvent, type StartResult, type Strategy, type TraceEntry, type TraceSink, type ValidationIssue, type ValidationResult, type VariableValue, type Variables, type WS, type WSOptions, type WSRetryOptions, type WSSocket, type WSStatus, catchError, createActionsRegistry, createConditionsRegistry, createFlow, createMemoryTraceSink, createPubSub, createWS, defineConfig, defineErrorReporter };
410
+ export { type Action, type ActionArgs, type ActionFail, type ActionResult, type ActionSkip, type ActionStop, type ActionSuccess, type ActionsRegistry, BUILTIN_ACTIONS, BUILTIN_ACTION_NAMES, BUILTIN_CONDITIONS, BUILTIN_CONDITION_NAMES, type BindingEventMap, type Bus, type BusBinding, type BusBindingKey, type BusBindings, type BusEmitOptions, type BusErrorEvent, type BusEvent, type BusOptions, type ConcurrencyMode, type ConcurrencyOptions, type ConditionExpression, type ConditionFn, type ConditionsRegistry, type Config, type DomBinding, type DomBindingKey, type DomBindings, type DomForm, type DomInput, type ErrorReporter, type ErrorReporterHandlers, type ErrorStage, type EventHandler, type EventMap, type EventName, type EventPattern, type ExpressionOperator, type FetchResponseType, type Flow, type FlowDefinition, type FlowOptions, type InactiveBinding, type Input, type Mode, type Next, type Props, PubSub, type QueueOverflow, type RetryOptions, type RunOptions, type RunResult, type Runner, type RunnerErrorEvent, type RunnerOptions, type Runtime, type SlapError, type SlapErrorEvent, type SlapEvent, type SocketEventTopic, type StartResult, type Strategy, type TraceEntry, type TraceSink, type ValidationIssue, type ValidationResult, type VariableValue, type Variables, type WS, type WSClient, type WSOptions, type WSRetryOptions, type WSSocket, type WSStatus, type WebSocketOptions, type WebSocketStatus, catchError, createFlow, createMemoryTraceSink, createPubSub, createWS, createWebSocket, defineConfig, defineErrorReporter };