aifsmjs 0.5.5 → 0.5.6

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.
Files changed (58) hide show
  1. package/README.md +8 -4
  2. package/README_ZHTW.md +7 -5
  3. package/dist/chunk-2MME5V4F.cjs +384 -0
  4. package/dist/chunk-2MME5V4F.cjs.map +1 -0
  5. package/dist/chunk-3B2USJ3H.cjs +18 -0
  6. package/dist/chunk-3B2USJ3H.cjs.map +1 -0
  7. package/dist/chunk-A7U7QQL5.js +52 -0
  8. package/dist/chunk-A7U7QQL5.js.map +1 -0
  9. package/dist/chunk-CDK25FTD.cjs +59 -0
  10. package/dist/chunk-CDK25FTD.cjs.map +1 -0
  11. package/dist/chunk-FHTQ7LSQ.cjs +21 -0
  12. package/dist/chunk-FHTQ7LSQ.cjs.map +1 -0
  13. package/dist/chunk-I354FONA.cjs +153 -0
  14. package/dist/chunk-I354FONA.cjs.map +1 -0
  15. package/dist/chunk-JKZAOPQC.js +16 -0
  16. package/dist/chunk-JKZAOPQC.js.map +1 -0
  17. package/dist/chunk-NEJYZAKR.js +19 -0
  18. package/dist/chunk-NEJYZAKR.js.map +1 -0
  19. package/dist/chunk-PZ5AY32C.js +9 -0
  20. package/dist/chunk-PZ5AY32C.js.map +1 -0
  21. package/dist/chunk-Q7SFCCGT.cjs +11 -0
  22. package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
  23. package/dist/chunk-VZCSHTOI.js +374 -0
  24. package/dist/chunk-VZCSHTOI.js.map +1 -0
  25. package/dist/chunk-ZLQ7HZCE.js +142 -0
  26. package/dist/chunk-ZLQ7HZCE.js.map +1 -0
  27. package/dist/effects/index.cjs +8 -14
  28. package/dist/effects/index.cjs.map +1 -1
  29. package/dist/effects/index.js +5 -14
  30. package/dist/effects/index.js.map +1 -1
  31. package/dist/guards/index.cjs +9 -13
  32. package/dist/guards/index.cjs.map +1 -1
  33. package/dist/guards/index.js +8 -12
  34. package/dist/guards/index.js.map +1 -1
  35. package/dist/index.cjs +101 -591
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.js +5 -571
  38. package/dist/index.js.map +1 -1
  39. package/dist/inspect/index.cjs +2 -0
  40. package/dist/inspect/index.cjs.map +1 -1
  41. package/dist/inspect/index.js +2 -0
  42. package/dist/inspect/index.js.map +1 -1
  43. package/dist/pbt/index.cjs +26 -525
  44. package/dist/pbt/index.cjs.map +1 -1
  45. package/dist/pbt/index.d.cts +7 -3
  46. package/dist/pbt/index.d.ts +7 -3
  47. package/dist/pbt/index.js +12 -511
  48. package/dist/pbt/index.js.map +1 -1
  49. package/dist/replay/index.cjs +9 -195
  50. package/dist/replay/index.cjs.map +1 -1
  51. package/dist/replay/index.js +5 -198
  52. package/dist/replay/index.js.map +1 -1
  53. package/dist/timer/index.cjs +30 -9
  54. package/dist/timer/index.cjs.map +1 -1
  55. package/dist/timer/index.js +30 -9
  56. package/dist/timer/index.js.map +1 -1
  57. package/llms-full.txt +159 -8
  58. package/package.json +5 -3
@@ -1,17 +1,8 @@
1
1
  'use strict';
2
2
 
3
- // src/effects/enqueuer.ts
4
- function createEnqueuer(sink) {
5
- return Object.freeze({
6
- effect(type, payload) {
7
- if (payload === void 0) {
8
- sink.push(Object.freeze({ type }));
9
- } else {
10
- sink.push(Object.freeze({ type, payload }));
11
- }
12
- }
13
- });
14
- }
3
+ var chunk3B2USJ3H_cjs = require('../chunk-3B2USJ3H.cjs');
4
+ var chunkCDK25FTD_cjs = require('../chunk-CDK25FTD.cjs');
5
+ require('../chunk-Q7SFCCGT.cjs');
15
6
 
16
7
  // src/effects/dispatcher.ts
17
8
  var NEVER_SIGNAL;
@@ -28,12 +19,15 @@ function runEffects(effects, handlers, args) {
28
19
  const h = handlers[eff.type];
29
20
  if (!h) continue;
30
21
  const r = h(eff, handlerArgs);
31
- if (r instanceof Promise) promises.push(r);
22
+ if (chunkCDK25FTD_cjs.isThenable(r)) promises.push(Promise.resolve(r));
32
23
  }
33
24
  return promises;
34
25
  }
35
26
 
36
- exports.createEnqueuer = createEnqueuer;
27
+ Object.defineProperty(exports, "createEnqueuer", {
28
+ enumerable: true,
29
+ get: function () { return chunk3B2USJ3H_cjs.createEnqueuer; }
30
+ });
37
31
  exports.runEffects = runEffects;
38
32
  //# sourceMappingURL=index.cjs.map
39
33
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/effects/enqueuer.ts","../../src/effects/dispatcher.ts"],"names":[],"mappings":";;;AAUO,SAAS,eAAe,IAAA,EAAuD;AACpF,EAAA,OAAO,OAAO,MAAA,CAAO;AAAA,IACnB,MAAA,CAAO,MAAc,OAAA,EAAmB;AACtC,MAAA,IAAI,YAAY,MAAA,EAAW;AACzB,QAAA,IAAA,CAAK,KAAK,MAAA,CAAO,MAAA,CAAO,EAAE,IAAA,EAAM,CAAC,CAAA;AAAA,MACnC,CAAA,MAAO;AACL,QAAA,IAAA,CAAK,KAAK,MAAA,CAAO,MAAA,CAAO,EAAE,IAAA,EAAM,OAAA,EAAS,CAAC,CAAA;AAAA,MAC5C;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;AChBA,IAAI,YAAA;AACJ,SAAS,WAAA,GAA2B;AAClC,EAAA,IAAI,CAAC,YAAA,EAAc,YAAA,GAAe,IAAI,iBAAgB,CAAE,MAAA;AACxD,EAAA,OAAO,YAAA;AACT;AAgBO,SAAS,UAAA,CACd,OAAA,EACA,QAAA,EACA,IAAA,EAC0B;AAC1B,EAAA,IAAI,CAAC,QAAA,IAAY,OAAA,CAAQ,MAAA,KAAW,CAAA,SAAU,EAAC;AAC/C,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,MAAA,IAAU,WAAA,EAAY;AAC1C,EAAA,MAAM,WAAA,GAAc,EAAE,OAAA,EAAS,IAAA,CAAK,SAAS,KAAA,EAAO,IAAA,CAAK,OAAO,MAAA,EAAO;AACvE,EAAA,MAAM,WAA4B,EAAC;AACnC,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAAA,MAAM,CAAA,GAAI,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA;AAC3B,IAAA,IAAI,CAAC,CAAA,EAAG;AACR,IAAA,MAAM,CAAA,GAAI,CAAA,CAAE,GAAA,EAAK,WAAW,CAAA;AAC5B,IAAA,IAAI,CAAA,YAAa,OAAA,EAAS,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA;AAAA,EAC3C;AACA,EAAA,OAAO,QAAA;AACT","file":"index.cjs","sourcesContent":["import type { Enqueuer } from \"../fsm/types.js\";\n\n/**\n * Build a closure-based Enqueuer that pushes effects into the supplied sink.\n * Each `step()` invocation creates one such enqueuer and discards it\n * afterwards; the sink is the effects array later returned to the caller.\n *\n * Lives in `effects/` because the Enqueuer concept is the effects-domain API\n * — `step()` imports it from here.\n */\nexport function createEnqueuer(sink: { type: string; payload?: unknown }[]): Enqueuer {\n return Object.freeze({\n effect(type: string, payload?: unknown) {\n if (payload === undefined) {\n sink.push(Object.freeze({ type }));\n } else {\n sink.push(Object.freeze({ type, payload }));\n }\n },\n });\n}\n","import type { Effect, EffectHandler } from \"../fsm/types.js\";\n\n// Lazily-built never-aborting signal for callers who don't supply one. Reused\n// across runEffects() invocations to avoid allocating a controller per call.\nlet NEVER_SIGNAL: AbortSignal | undefined;\nfunction neverSignal(): AbortSignal {\n if (!NEVER_SIGNAL) NEVER_SIGNAL = new AbortController().signal;\n return NEVER_SIGNAL;\n}\n\n/**\n * Dispatch a batch of effects through the supplied handler map. Effects whose\n * `type` has no handler are silently skipped (the runtime treats unhandled\n * effects as informational).\n *\n * Returns the array of Promise results (if any handler is async) so callers\n * can `await Promise.all(...)` when they need flushing — the default runtime\n * is fire-and-forget and discards them.\n *\n * Each handler receives an `AbortSignal`. When called from `createRuntime`,\n * the signal is the runtime's own controller. Stand-alone callers may omit\n * `args.signal` (a never-aborting placeholder is supplied) or pass their own\n * (e.g. `AbortSignal.timeout(5000)`, `AbortSignal.any([...])`).\n */\nexport function runEffects<Ctx, Evt>(\n effects: readonly Effect[],\n handlers: Readonly<Record<string, EffectHandler<Ctx, Evt>>> | undefined,\n args: { context: Ctx; event: Evt; signal?: AbortSignal },\n): readonly Promise<void>[] {\n if (!handlers || effects.length === 0) return [];\n const signal = args.signal ?? neverSignal();\n const handlerArgs = { context: args.context, event: args.event, signal };\n const promises: Promise<void>[] = [];\n for (const eff of effects) {\n const h = handlers[eff.type];\n if (!h) continue;\n const r = h(eff, handlerArgs);\n if (r instanceof Promise) promises.push(r);\n }\n return promises;\n}\n"]}
1
+ {"version":3,"sources":["../../src/effects/dispatcher.ts"],"names":["isThenable"],"mappings":";;;;;;;AAKA,IAAI,YAAA;AACJ,SAAS,WAAA,GAA2B;AAClC,EAAA,IAAI,CAAC,YAAA,EAAc,YAAA,GAAe,IAAI,iBAAgB,CAAE,MAAA;AACxD,EAAA,OAAO,YAAA;AACT;AAgBO,SAAS,UAAA,CACd,OAAA,EACA,QAAA,EACA,IAAA,EAC0B;AAC1B,EAAA,IAAI,CAAC,QAAA,IAAY,OAAA,CAAQ,MAAA,KAAW,CAAA,SAAU,EAAC;AAC/C,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,MAAA,IAAU,WAAA,EAAY;AAC1C,EAAA,MAAM,WAAA,GAAc,EAAE,OAAA,EAAS,IAAA,CAAK,SAAS,KAAA,EAAO,IAAA,CAAK,OAAO,MAAA,EAAO;AACvE,EAAA,MAAM,WAA4B,EAAC;AACnC,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAAA,MAAM,CAAA,GAAI,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA;AAC3B,IAAA,IAAI,CAAC,CAAA,EAAG;AACR,IAAA,MAAM,CAAA,GAAI,CAAA,CAAE,GAAA,EAAK,WAAW,CAAA;AAI5B,IAAA,IAAIA,4BAAA,CAAW,CAAC,CAAA,EAAG,QAAA,CAAS,KAAK,OAAA,CAAQ,OAAA,CAAQ,CAAC,CAAC,CAAA;AAAA,EACrD;AACA,EAAA,OAAO,QAAA;AACT","file":"index.cjs","sourcesContent":["import { isThenable } from \"../fsm/evaluator.js\";\nimport type { Effect, EffectHandler } from \"../fsm/types.js\";\n\n// Lazily-built never-aborting signal for callers who don't supply one. Reused\n// across runEffects() invocations to avoid allocating a controller per call.\nlet NEVER_SIGNAL: AbortSignal | undefined;\nfunction neverSignal(): AbortSignal {\n if (!NEVER_SIGNAL) NEVER_SIGNAL = new AbortController().signal;\n return NEVER_SIGNAL;\n}\n\n/**\n * Dispatch a batch of effects through the supplied handler map. Effects whose\n * `type` has no handler are silently skipped (the runtime treats unhandled\n * effects as informational).\n *\n * Returns the array of Promise results (if any handler is async) so callers\n * can `await Promise.all(...)` when they need flushing — the default runtime\n * is fire-and-forget and discards them.\n *\n * Each handler receives an `AbortSignal`. When called from `createRuntime`,\n * the signal is the runtime's own controller. Stand-alone callers may omit\n * `args.signal` (a never-aborting placeholder is supplied) or pass their own\n * (e.g. `AbortSignal.timeout(5000)`, `AbortSignal.any([...])`).\n */\nexport function runEffects<Ctx, Evt>(\n effects: readonly Effect[],\n handlers: Readonly<Record<string, EffectHandler<Ctx, Evt>>> | undefined,\n args: { context: Ctx; event: Evt; signal?: AbortSignal },\n): readonly Promise<void>[] {\n if (!handlers || effects.length === 0) return [];\n const signal = args.signal ?? neverSignal();\n const handlerArgs = { context: args.context, event: args.event, signal };\n const promises: Promise<void>[] = [];\n for (const eff of effects) {\n const h = handlers[eff.type];\n if (!h) continue;\n const r = h(eff, handlerArgs);\n // isThenable (not instanceof Promise) so cross-realm Promises and\n // user-defined PromiseLike results are also awaitable by callers;\n // Promise.resolve() normalises them to a real Promise (FSM-B-03).\n if (isThenable(r)) promises.push(Promise.resolve(r));\n }\n return promises;\n}\n"]}
@@ -1,15 +1,6 @@
1
- // src/effects/enqueuer.ts
2
- function createEnqueuer(sink) {
3
- return Object.freeze({
4
- effect(type, payload) {
5
- if (payload === void 0) {
6
- sink.push(Object.freeze({ type }));
7
- } else {
8
- sink.push(Object.freeze({ type, payload }));
9
- }
10
- }
11
- });
12
- }
1
+ export { createEnqueuer } from '../chunk-JKZAOPQC.js';
2
+ import { isThenable } from '../chunk-A7U7QQL5.js';
3
+ import '../chunk-PZ5AY32C.js';
13
4
 
14
5
  // src/effects/dispatcher.ts
15
6
  var NEVER_SIGNAL;
@@ -26,11 +17,11 @@ function runEffects(effects, handlers, args) {
26
17
  const h = handlers[eff.type];
27
18
  if (!h) continue;
28
19
  const r = h(eff, handlerArgs);
29
- if (r instanceof Promise) promises.push(r);
20
+ if (isThenable(r)) promises.push(Promise.resolve(r));
30
21
  }
31
22
  return promises;
32
23
  }
33
24
 
34
- export { createEnqueuer, runEffects };
25
+ export { runEffects };
35
26
  //# sourceMappingURL=index.js.map
36
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/effects/enqueuer.ts","../../src/effects/dispatcher.ts"],"names":[],"mappings":";AAUO,SAAS,eAAe,IAAA,EAAuD;AACpF,EAAA,OAAO,OAAO,MAAA,CAAO;AAAA,IACnB,MAAA,CAAO,MAAc,OAAA,EAAmB;AACtC,MAAA,IAAI,YAAY,MAAA,EAAW;AACzB,QAAA,IAAA,CAAK,KAAK,MAAA,CAAO,MAAA,CAAO,EAAE,IAAA,EAAM,CAAC,CAAA;AAAA,MACnC,CAAA,MAAO;AACL,QAAA,IAAA,CAAK,KAAK,MAAA,CAAO,MAAA,CAAO,EAAE,IAAA,EAAM,OAAA,EAAS,CAAC,CAAA;AAAA,MAC5C;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;AChBA,IAAI,YAAA;AACJ,SAAS,WAAA,GAA2B;AAClC,EAAA,IAAI,CAAC,YAAA,EAAc,YAAA,GAAe,IAAI,iBAAgB,CAAE,MAAA;AACxD,EAAA,OAAO,YAAA;AACT;AAgBO,SAAS,UAAA,CACd,OAAA,EACA,QAAA,EACA,IAAA,EAC0B;AAC1B,EAAA,IAAI,CAAC,QAAA,IAAY,OAAA,CAAQ,MAAA,KAAW,CAAA,SAAU,EAAC;AAC/C,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,MAAA,IAAU,WAAA,EAAY;AAC1C,EAAA,MAAM,WAAA,GAAc,EAAE,OAAA,EAAS,IAAA,CAAK,SAAS,KAAA,EAAO,IAAA,CAAK,OAAO,MAAA,EAAO;AACvE,EAAA,MAAM,WAA4B,EAAC;AACnC,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAAA,MAAM,CAAA,GAAI,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA;AAC3B,IAAA,IAAI,CAAC,CAAA,EAAG;AACR,IAAA,MAAM,CAAA,GAAI,CAAA,CAAE,GAAA,EAAK,WAAW,CAAA;AAC5B,IAAA,IAAI,CAAA,YAAa,OAAA,EAAS,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA;AAAA,EAC3C;AACA,EAAA,OAAO,QAAA;AACT","file":"index.js","sourcesContent":["import type { Enqueuer } from \"../fsm/types.js\";\n\n/**\n * Build a closure-based Enqueuer that pushes effects into the supplied sink.\n * Each `step()` invocation creates one such enqueuer and discards it\n * afterwards; the sink is the effects array later returned to the caller.\n *\n * Lives in `effects/` because the Enqueuer concept is the effects-domain API\n * — `step()` imports it from here.\n */\nexport function createEnqueuer(sink: { type: string; payload?: unknown }[]): Enqueuer {\n return Object.freeze({\n effect(type: string, payload?: unknown) {\n if (payload === undefined) {\n sink.push(Object.freeze({ type }));\n } else {\n sink.push(Object.freeze({ type, payload }));\n }\n },\n });\n}\n","import type { Effect, EffectHandler } from \"../fsm/types.js\";\n\n// Lazily-built never-aborting signal for callers who don't supply one. Reused\n// across runEffects() invocations to avoid allocating a controller per call.\nlet NEVER_SIGNAL: AbortSignal | undefined;\nfunction neverSignal(): AbortSignal {\n if (!NEVER_SIGNAL) NEVER_SIGNAL = new AbortController().signal;\n return NEVER_SIGNAL;\n}\n\n/**\n * Dispatch a batch of effects through the supplied handler map. Effects whose\n * `type` has no handler are silently skipped (the runtime treats unhandled\n * effects as informational).\n *\n * Returns the array of Promise results (if any handler is async) so callers\n * can `await Promise.all(...)` when they need flushing — the default runtime\n * is fire-and-forget and discards them.\n *\n * Each handler receives an `AbortSignal`. When called from `createRuntime`,\n * the signal is the runtime's own controller. Stand-alone callers may omit\n * `args.signal` (a never-aborting placeholder is supplied) or pass their own\n * (e.g. `AbortSignal.timeout(5000)`, `AbortSignal.any([...])`).\n */\nexport function runEffects<Ctx, Evt>(\n effects: readonly Effect[],\n handlers: Readonly<Record<string, EffectHandler<Ctx, Evt>>> | undefined,\n args: { context: Ctx; event: Evt; signal?: AbortSignal },\n): readonly Promise<void>[] {\n if (!handlers || effects.length === 0) return [];\n const signal = args.signal ?? neverSignal();\n const handlerArgs = { context: args.context, event: args.event, signal };\n const promises: Promise<void>[] = [];\n for (const eff of effects) {\n const h = handlers[eff.type];\n if (!h) continue;\n const r = h(eff, handlerArgs);\n if (r instanceof Promise) promises.push(r);\n }\n return promises;\n}\n"]}
1
+ {"version":3,"sources":["../../src/effects/dispatcher.ts"],"names":[],"mappings":";;;;;AAKA,IAAI,YAAA;AACJ,SAAS,WAAA,GAA2B;AAClC,EAAA,IAAI,CAAC,YAAA,EAAc,YAAA,GAAe,IAAI,iBAAgB,CAAE,MAAA;AACxD,EAAA,OAAO,YAAA;AACT;AAgBO,SAAS,UAAA,CACd,OAAA,EACA,QAAA,EACA,IAAA,EAC0B;AAC1B,EAAA,IAAI,CAAC,QAAA,IAAY,OAAA,CAAQ,MAAA,KAAW,CAAA,SAAU,EAAC;AAC/C,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,MAAA,IAAU,WAAA,EAAY;AAC1C,EAAA,MAAM,WAAA,GAAc,EAAE,OAAA,EAAS,IAAA,CAAK,SAAS,KAAA,EAAO,IAAA,CAAK,OAAO,MAAA,EAAO;AACvE,EAAA,MAAM,WAA4B,EAAC;AACnC,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAAA,MAAM,CAAA,GAAI,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA;AAC3B,IAAA,IAAI,CAAC,CAAA,EAAG;AACR,IAAA,MAAM,CAAA,GAAI,CAAA,CAAE,GAAA,EAAK,WAAW,CAAA;AAI5B,IAAA,IAAI,UAAA,CAAW,CAAC,CAAA,EAAG,QAAA,CAAS,KAAK,OAAA,CAAQ,OAAA,CAAQ,CAAC,CAAC,CAAA;AAAA,EACrD;AACA,EAAA,OAAO,QAAA;AACT","file":"index.js","sourcesContent":["import { isThenable } from \"../fsm/evaluator.js\";\nimport type { Effect, EffectHandler } from \"../fsm/types.js\";\n\n// Lazily-built never-aborting signal for callers who don't supply one. Reused\n// across runEffects() invocations to avoid allocating a controller per call.\nlet NEVER_SIGNAL: AbortSignal | undefined;\nfunction neverSignal(): AbortSignal {\n if (!NEVER_SIGNAL) NEVER_SIGNAL = new AbortController().signal;\n return NEVER_SIGNAL;\n}\n\n/**\n * Dispatch a batch of effects through the supplied handler map. Effects whose\n * `type` has no handler are silently skipped (the runtime treats unhandled\n * effects as informational).\n *\n * Returns the array of Promise results (if any handler is async) so callers\n * can `await Promise.all(...)` when they need flushing — the default runtime\n * is fire-and-forget and discards them.\n *\n * Each handler receives an `AbortSignal`. When called from `createRuntime`,\n * the signal is the runtime's own controller. Stand-alone callers may omit\n * `args.signal` (a never-aborting placeholder is supplied) or pass their own\n * (e.g. `AbortSignal.timeout(5000)`, `AbortSignal.any([...])`).\n */\nexport function runEffects<Ctx, Evt>(\n effects: readonly Effect[],\n handlers: Readonly<Record<string, EffectHandler<Ctx, Evt>>> | undefined,\n args: { context: Ctx; event: Evt; signal?: AbortSignal },\n): readonly Promise<void>[] {\n if (!handlers || effects.length === 0) return [];\n const signal = args.signal ?? neverSignal();\n const handlerArgs = { context: args.context, event: args.event, signal };\n const promises: Promise<void>[] = [];\n for (const eff of effects) {\n const h = handlers[eff.type];\n if (!h) continue;\n const r = h(eff, handlerArgs);\n // isThenable (not instanceof Promise) so cross-realm Promises and\n // user-defined PromiseLike results are also awaitable by callers;\n // Promise.resolve() normalises them to a real Promise (FSM-B-03).\n if (isThenable(r)) promises.push(Promise.resolve(r));\n }\n return promises;\n}\n"]}
@@ -1,21 +1,17 @@
1
1
  'use strict';
2
2
 
3
- // src/fsm/evaluator.ts
4
- var UnknownGuardError = class extends Error {
5
- guardName;
6
- constructor(guardName) {
7
- super(`aifsmjs: guard "${guardName}" not found in implementations.guards`);
8
- this.name = "UnknownGuardError";
9
- this.guardName = guardName;
10
- }
11
- };
3
+ var chunkCDK25FTD_cjs = require('../chunk-CDK25FTD.cjs');
4
+ require('../chunk-Q7SFCCGT.cjs');
12
5
 
13
6
  // src/guards/index.ts
14
7
  function resolveItem(item, args) {
15
- if (typeof item === "function") return item(args);
16
- const fn = args.guards?.[item];
17
- if (!fn) throw new UnknownGuardError(item);
18
- return fn(args);
8
+ const fn = typeof item === "function" ? item : args.guards?.[item];
9
+ if (!fn) throw new chunkCDK25FTD_cjs.UnknownGuardError(item);
10
+ const result = fn(args);
11
+ if (chunkCDK25FTD_cjs.isThenable(result)) {
12
+ throw new chunkCDK25FTD_cjs.AsyncGuardError(typeof item === "string" ? item : fn.name || "<inline>");
13
+ }
14
+ return result;
19
15
  }
20
16
  function and(items) {
21
17
  return (args) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fsm/evaluator.ts","../../src/guards/index.ts"],"names":[],"mappings":";;;AAEO,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAClC,SAAA;AAAA,EACT,YAAY,SAAA,EAAmB;AAC7B,IAAA,KAAA,CAAM,CAAA,gBAAA,EAAmB,SAAS,CAAA,qCAAA,CAAuC,CAAA;AACzE,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AACF,CAAA;;;ACNA,SAAS,WAAA,CAAsB,MAA0B,IAAA,EAAoC;AAC3F,EAAA,IAAI,OAAO,IAAA,KAAS,UAAA,EAAY,OAAO,KAAK,IAAI,CAAA;AAChD,EAAA,MAAM,EAAA,GAAK,IAAA,CAAK,MAAA,GAAS,IAAI,CAAA;AAC7B,EAAA,IAAI,CAAC,EAAA,EAAI,MAAM,IAAI,kBAAkB,IAAI,CAAA;AACzC,EAAA,OAAO,GAAG,IAAI,CAAA;AAChB;AAGO,SAAS,IAAc,KAAA,EAAuD;AACnF,EAAA,OAAO,CAAC,IAAA,KAAS;AACf,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,IAAI,CAAC,WAAA,CAAY,IAAA,EAAM,IAAI,GAAG,OAAO,KAAA;AAAA,IACvC;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA;AACF;AAGO,SAAS,GAAa,KAAA,EAAuD;AAClF,EAAA,OAAO,CAAC,IAAA,KAAS;AACf,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,IAAI,WAAA,CAAY,IAAA,EAAM,IAAI,CAAA,EAAG,OAAO,IAAA;AAAA,IACtC;AACA,IAAA,OAAO,KAAA;AAAA,EACT,CAAA;AACF;AAGO,SAAS,IAAc,IAAA,EAA2C;AACvE,EAAA,OAAO,CAAC,IAAA,KAAS,CAAC,WAAA,CAAY,MAAM,IAAI,CAAA;AAC1C;AAQO,SAAS,WAAqB,MAAA,EAA4C;AAC/E,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAY,MAAM,CAAA;AAClC,EAAA,OAAO,CAAC,EAAE,KAAA,EAAM,KAAM,OAAO,KAAA,KAAU,QAAA,IAAY,GAAA,CAAI,GAAA,CAAI,KAAK,CAAA;AAClE","file":"index.cjs","sourcesContent":["import type { Guard, GuardRef, Implementations } from \"./types.js\";\n\nexport class UnknownGuardError extends Error {\n readonly guardName: string;\n constructor(guardName: string) {\n super(`aifsmjs: guard \"${guardName}\" not found in implementations.guards`);\n this.name = \"UnknownGuardError\";\n this.guardName = guardName;\n }\n}\n\nexport class AsyncGuardError extends Error {\n readonly guardName: string;\n constructor(guardName: string) {\n super(\n `aifsmjs: guard \"${guardName}\" must be sync; received a Promise. Async guards break determinism and replay. Move I/O into an effect.`,\n );\n this.name = \"AsyncGuardError\";\n this.guardName = guardName;\n }\n}\n\n/**\n * Detect declared-async guards at definition time. Catches the common case of\n * `async (args) => ...` inline guards. Combinator builders or arrow returns of\n * a Promise still slip past — those are caught at `evalGuard` runtime via\n * the `isThenable` check.\n *\n * Caveat: this relies on `Function.prototype.constructor.name === \"AsyncFunction\"`,\n * which is reliable in ES2017+ runtimes. If your bundler transpiles `async`\n * to generator-based code (e.g. ES5 / very old TypeScript targets), this\n * check returns `false` for those forms — the runtime `evalGuard` thenable\n * check still catches them.\n */\nexport function isAsyncGuardFn(fn: unknown): boolean {\n if (typeof fn !== \"function\") return false;\n return fn.constructor?.name === \"AsyncFunction\";\n}\n\n/**\n * Detect a thenable (PromiseLike) — anything with a callable `then`. Used in\n * place of `instanceof Promise` so cross-realm Promises (iframe / worker /\n * vm context) and user-defined thenables are also rejected.\n */\nfunction isThenable(x: unknown): x is PromiseLike<unknown> {\n return (\n x !== null &&\n (typeof x === \"object\" || typeof x === \"function\") &&\n typeof (x as { then?: unknown }).then === \"function\"\n );\n}\n\n/**\n * Resolve a guard ref to a Guard function. String refs are looked up in the\n * implementations map; inline functions are returned as-is.\n */\nexport function resolveGuard<Ctx, Evt>(\n ref: GuardRef<Ctx, Evt>,\n impl: Implementations<Ctx, Evt>,\n): Guard<Ctx, Evt> {\n if (typeof ref === \"function\") return ref;\n const fn = impl.guards?.[ref];\n if (!fn) throw new UnknownGuardError(ref);\n return fn;\n}\n\n/**\n * Evaluate a guard ref against (context, event). Guards must be sync and pure;\n * TypeScript blocks declared-async signatures at compile time, but JS callers\n * or casts can still slip through. This function checks two ways:\n * 1. Inline AsyncFunction (declared `async`) → throw AsyncGuardError.\n * 2. Return value is a Promise → throw AsyncGuardError.\n * Both throws are user errors; they would otherwise silently pass the guard\n * (Promise is truthy) and break determinism.\n *\n * The optional `value` argument is the current state value, threaded so the\n * `stateIn` combinator and similar predicates can introspect it.\n */\nexport function evalGuard<Ctx, Evt>(\n ref: GuardRef<Ctx, Evt>,\n context: Ctx,\n event: Evt,\n impl: Implementations<Ctx, Evt>,\n value?: string,\n): boolean {\n const fn = resolveGuard(ref, impl);\n // Function.prototype.name is \"\" for anonymous arrows — use `||` not `??`\n // so the empty string falls back to \"<inline>\" for readable error messages.\n const guardName = typeof ref === \"string\" ? ref : fn.name || \"<inline>\";\n if (isAsyncGuardFn(fn)) {\n throw new AsyncGuardError(guardName);\n }\n // Build args while honouring exactOptionalPropertyTypes: omit fields that\n // would otherwise be assigned `undefined`.\n type Args = {\n context: Ctx;\n event: Evt;\n guards?: Readonly<Record<string, Guard<Ctx, Evt>>>;\n value?: string;\n };\n const args: Args = { context, event };\n const guardsMap = impl.guards;\n if (guardsMap) args.guards = guardsMap;\n if (value !== undefined) args.value = value;\n const result = fn(args);\n // TS narrows `result` to boolean from Guard's return type, but a JS caller\n // or a cast can slip a Promise / PromiseLike through. We accept anything\n // thenable (native Promise, cross-realm Promise, user-defined thenable),\n // not just same-realm `instanceof Promise`.\n if (isThenable(result)) {\n throw new AsyncGuardError(guardName);\n }\n return result;\n}\n","import { UnknownGuardError } from \"../fsm/evaluator.js\";\nimport type { Guard, GuardArgs, GuardRef } from \"../fsm/types.js\";\n\nfunction resolveItem<Ctx, Evt>(item: GuardRef<Ctx, Evt>, args: GuardArgs<Ctx, Evt>): boolean {\n if (typeof item === \"function\") return item(args);\n const fn = args.guards?.[item];\n if (!fn) throw new UnknownGuardError(item);\n return fn(args);\n}\n\n/** Logical AND over guards. Short-circuits on the first `false`. */\nexport function and<Ctx, Evt>(items: readonly GuardRef<Ctx, Evt>[]): Guard<Ctx, Evt> {\n return (args) => {\n for (const item of items) {\n if (!resolveItem(item, args)) return false;\n }\n return true;\n };\n}\n\n/** Logical OR over guards. Short-circuits on the first `true`. */\nexport function or<Ctx, Evt>(items: readonly GuardRef<Ctx, Evt>[]): Guard<Ctx, Evt> {\n return (args) => {\n for (const item of items) {\n if (resolveItem(item, args)) return true;\n }\n return false;\n };\n}\n\n/** Logical NOT. */\nexport function not<Ctx, Evt>(item: GuardRef<Ctx, Evt>): Guard<Ctx, Evt> {\n return (args) => !resolveItem(item, args);\n}\n\n/**\n * Predicate that passes when the current state value is one of the listed\n * states. Reads `args.value`, which `evalGuard` threads from the live\n * snapshot. When called outside of `evalGuard` (e.g. unit tests), `value` is\n * `undefined` and the guard returns `false`.\n */\nexport function stateIn<Ctx, Evt>(...states: readonly string[]): Guard<Ctx, Evt> {\n const set = new Set<string>(states);\n return ({ value }) => typeof value === \"string\" && set.has(value);\n}\n"]}
1
+ {"version":3,"sources":["../../src/guards/index.ts"],"names":["UnknownGuardError","isThenable","AsyncGuardError"],"mappings":";;;;;;AAGA,SAAS,WAAA,CAAsB,MAA0B,IAAA,EAAoC;AAC3F,EAAA,MAAM,KAAK,OAAO,IAAA,KAAS,aAAa,IAAA,GAAO,IAAA,CAAK,SAAS,IAAI,CAAA;AACjE,EAAA,IAAI,CAAC,EAAA,EAAI,MAAM,IAAIA,oCAAkB,IAAc,CAAA;AACnD,EAAA,MAAM,MAAA,GAAS,GAAG,IAAI,CAAA;AAItB,EAAA,IAAIC,4BAAA,CAAW,MAAM,CAAA,EAAG;AAGtB,IAAA,MAAM,IAAIC,kCAAgB,OAAO,IAAA,KAAS,WAAW,IAAA,GAAO,EAAA,CAAG,QAAQ,UAAU,CAAA;AAAA,EACnF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,IAAc,KAAA,EAAuD;AACnF,EAAA,OAAO,CAAC,IAAA,KAAS;AACf,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,IAAI,CAAC,WAAA,CAAY,IAAA,EAAM,IAAI,GAAG,OAAO,KAAA;AAAA,IACvC;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA;AACF;AAGO,SAAS,GAAa,KAAA,EAAuD;AAClF,EAAA,OAAO,CAAC,IAAA,KAAS;AACf,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,IAAI,WAAA,CAAY,IAAA,EAAM,IAAI,CAAA,EAAG,OAAO,IAAA;AAAA,IACtC;AACA,IAAA,OAAO,KAAA;AAAA,EACT,CAAA;AACF;AAGO,SAAS,IAAc,IAAA,EAA2C;AACvE,EAAA,OAAO,CAAC,IAAA,KAAS,CAAC,WAAA,CAAY,MAAM,IAAI,CAAA;AAC1C;AAQO,SAAS,WAAqB,MAAA,EAA4C;AAC/E,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAY,MAAM,CAAA;AAClC,EAAA,OAAO,CAAC,EAAE,KAAA,EAAM,KAAM,OAAO,KAAA,KAAU,QAAA,IAAY,GAAA,CAAI,GAAA,CAAI,KAAK,CAAA;AAClE","file":"index.cjs","sourcesContent":["import { AsyncGuardError, UnknownGuardError, isThenable } from \"../fsm/evaluator.js\";\nimport type { Guard, GuardArgs, GuardRef } from \"../fsm/types.js\";\n\nfunction resolveItem<Ctx, Evt>(item: GuardRef<Ctx, Evt>, args: GuardArgs<Ctx, Evt>): boolean {\n const fn = typeof item === \"function\" ? item : args.guards?.[item];\n if (!fn) throw new UnknownGuardError(item as string);\n const result = fn(args);\n // Mirror evalGuard's safety net: a guard that returns a thenable breaks\n // determinism. Checked here too so a thenable nested inside and/or/not is\n // rejected rather than coerced truthy by the combinator (FSM-S-01).\n if (isThenable(result)) {\n // Function.prototype.name is \"\" for anonymous arrows — fall back to\n // \"<inline>\" so the message stays readable (matches evalGuard).\n throw new AsyncGuardError(typeof item === \"string\" ? item : fn.name || \"<inline>\");\n }\n return result;\n}\n\n/** Logical AND over guards. Short-circuits on the first `false`. */\nexport function and<Ctx, Evt>(items: readonly GuardRef<Ctx, Evt>[]): Guard<Ctx, Evt> {\n return (args) => {\n for (const item of items) {\n if (!resolveItem(item, args)) return false;\n }\n return true;\n };\n}\n\n/** Logical OR over guards. Short-circuits on the first `true`. */\nexport function or<Ctx, Evt>(items: readonly GuardRef<Ctx, Evt>[]): Guard<Ctx, Evt> {\n return (args) => {\n for (const item of items) {\n if (resolveItem(item, args)) return true;\n }\n return false;\n };\n}\n\n/** Logical NOT. */\nexport function not<Ctx, Evt>(item: GuardRef<Ctx, Evt>): Guard<Ctx, Evt> {\n return (args) => !resolveItem(item, args);\n}\n\n/**\n * Predicate that passes when the current state value is one of the listed\n * states. Reads `args.value`, which `evalGuard` threads from the live\n * snapshot. When called outside of `evalGuard` (e.g. unit tests), `value` is\n * `undefined` and the guard returns `false`.\n */\nexport function stateIn<Ctx, Evt>(...states: readonly string[]): Guard<Ctx, Evt> {\n const set = new Set<string>(states);\n return ({ value }) => typeof value === \"string\" && set.has(value);\n}\n"]}
@@ -1,19 +1,15 @@
1
- // src/fsm/evaluator.ts
2
- var UnknownGuardError = class extends Error {
3
- guardName;
4
- constructor(guardName) {
5
- super(`aifsmjs: guard "${guardName}" not found in implementations.guards`);
6
- this.name = "UnknownGuardError";
7
- this.guardName = guardName;
8
- }
9
- };
1
+ import { UnknownGuardError, isThenable, AsyncGuardError } from '../chunk-A7U7QQL5.js';
2
+ import '../chunk-PZ5AY32C.js';
10
3
 
11
4
  // src/guards/index.ts
12
5
  function resolveItem(item, args) {
13
- if (typeof item === "function") return item(args);
14
- const fn = args.guards?.[item];
6
+ const fn = typeof item === "function" ? item : args.guards?.[item];
15
7
  if (!fn) throw new UnknownGuardError(item);
16
- return fn(args);
8
+ const result = fn(args);
9
+ if (isThenable(result)) {
10
+ throw new AsyncGuardError(typeof item === "string" ? item : fn.name || "<inline>");
11
+ }
12
+ return result;
17
13
  }
18
14
  function and(items) {
19
15
  return (args) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fsm/evaluator.ts","../../src/guards/index.ts"],"names":[],"mappings":";AAEO,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAClC,SAAA;AAAA,EACT,YAAY,SAAA,EAAmB;AAC7B,IAAA,KAAA,CAAM,CAAA,gBAAA,EAAmB,SAAS,CAAA,qCAAA,CAAuC,CAAA;AACzE,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AACF,CAAA;;;ACNA,SAAS,WAAA,CAAsB,MAA0B,IAAA,EAAoC;AAC3F,EAAA,IAAI,OAAO,IAAA,KAAS,UAAA,EAAY,OAAO,KAAK,IAAI,CAAA;AAChD,EAAA,MAAM,EAAA,GAAK,IAAA,CAAK,MAAA,GAAS,IAAI,CAAA;AAC7B,EAAA,IAAI,CAAC,EAAA,EAAI,MAAM,IAAI,kBAAkB,IAAI,CAAA;AACzC,EAAA,OAAO,GAAG,IAAI,CAAA;AAChB;AAGO,SAAS,IAAc,KAAA,EAAuD;AACnF,EAAA,OAAO,CAAC,IAAA,KAAS;AACf,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,IAAI,CAAC,WAAA,CAAY,IAAA,EAAM,IAAI,GAAG,OAAO,KAAA;AAAA,IACvC;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA;AACF;AAGO,SAAS,GAAa,KAAA,EAAuD;AAClF,EAAA,OAAO,CAAC,IAAA,KAAS;AACf,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,IAAI,WAAA,CAAY,IAAA,EAAM,IAAI,CAAA,EAAG,OAAO,IAAA;AAAA,IACtC;AACA,IAAA,OAAO,KAAA;AAAA,EACT,CAAA;AACF;AAGO,SAAS,IAAc,IAAA,EAA2C;AACvE,EAAA,OAAO,CAAC,IAAA,KAAS,CAAC,WAAA,CAAY,MAAM,IAAI,CAAA;AAC1C;AAQO,SAAS,WAAqB,MAAA,EAA4C;AAC/E,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAY,MAAM,CAAA;AAClC,EAAA,OAAO,CAAC,EAAE,KAAA,EAAM,KAAM,OAAO,KAAA,KAAU,QAAA,IAAY,GAAA,CAAI,GAAA,CAAI,KAAK,CAAA;AAClE","file":"index.js","sourcesContent":["import type { Guard, GuardRef, Implementations } from \"./types.js\";\n\nexport class UnknownGuardError extends Error {\n readonly guardName: string;\n constructor(guardName: string) {\n super(`aifsmjs: guard \"${guardName}\" not found in implementations.guards`);\n this.name = \"UnknownGuardError\";\n this.guardName = guardName;\n }\n}\n\nexport class AsyncGuardError extends Error {\n readonly guardName: string;\n constructor(guardName: string) {\n super(\n `aifsmjs: guard \"${guardName}\" must be sync; received a Promise. Async guards break determinism and replay. Move I/O into an effect.`,\n );\n this.name = \"AsyncGuardError\";\n this.guardName = guardName;\n }\n}\n\n/**\n * Detect declared-async guards at definition time. Catches the common case of\n * `async (args) => ...` inline guards. Combinator builders or arrow returns of\n * a Promise still slip past — those are caught at `evalGuard` runtime via\n * the `isThenable` check.\n *\n * Caveat: this relies on `Function.prototype.constructor.name === \"AsyncFunction\"`,\n * which is reliable in ES2017+ runtimes. If your bundler transpiles `async`\n * to generator-based code (e.g. ES5 / very old TypeScript targets), this\n * check returns `false` for those forms — the runtime `evalGuard` thenable\n * check still catches them.\n */\nexport function isAsyncGuardFn(fn: unknown): boolean {\n if (typeof fn !== \"function\") return false;\n return fn.constructor?.name === \"AsyncFunction\";\n}\n\n/**\n * Detect a thenable (PromiseLike) — anything with a callable `then`. Used in\n * place of `instanceof Promise` so cross-realm Promises (iframe / worker /\n * vm context) and user-defined thenables are also rejected.\n */\nfunction isThenable(x: unknown): x is PromiseLike<unknown> {\n return (\n x !== null &&\n (typeof x === \"object\" || typeof x === \"function\") &&\n typeof (x as { then?: unknown }).then === \"function\"\n );\n}\n\n/**\n * Resolve a guard ref to a Guard function. String refs are looked up in the\n * implementations map; inline functions are returned as-is.\n */\nexport function resolveGuard<Ctx, Evt>(\n ref: GuardRef<Ctx, Evt>,\n impl: Implementations<Ctx, Evt>,\n): Guard<Ctx, Evt> {\n if (typeof ref === \"function\") return ref;\n const fn = impl.guards?.[ref];\n if (!fn) throw new UnknownGuardError(ref);\n return fn;\n}\n\n/**\n * Evaluate a guard ref against (context, event). Guards must be sync and pure;\n * TypeScript blocks declared-async signatures at compile time, but JS callers\n * or casts can still slip through. This function checks two ways:\n * 1. Inline AsyncFunction (declared `async`) → throw AsyncGuardError.\n * 2. Return value is a Promise → throw AsyncGuardError.\n * Both throws are user errors; they would otherwise silently pass the guard\n * (Promise is truthy) and break determinism.\n *\n * The optional `value` argument is the current state value, threaded so the\n * `stateIn` combinator and similar predicates can introspect it.\n */\nexport function evalGuard<Ctx, Evt>(\n ref: GuardRef<Ctx, Evt>,\n context: Ctx,\n event: Evt,\n impl: Implementations<Ctx, Evt>,\n value?: string,\n): boolean {\n const fn = resolveGuard(ref, impl);\n // Function.prototype.name is \"\" for anonymous arrows — use `||` not `??`\n // so the empty string falls back to \"<inline>\" for readable error messages.\n const guardName = typeof ref === \"string\" ? ref : fn.name || \"<inline>\";\n if (isAsyncGuardFn(fn)) {\n throw new AsyncGuardError(guardName);\n }\n // Build args while honouring exactOptionalPropertyTypes: omit fields that\n // would otherwise be assigned `undefined`.\n type Args = {\n context: Ctx;\n event: Evt;\n guards?: Readonly<Record<string, Guard<Ctx, Evt>>>;\n value?: string;\n };\n const args: Args = { context, event };\n const guardsMap = impl.guards;\n if (guardsMap) args.guards = guardsMap;\n if (value !== undefined) args.value = value;\n const result = fn(args);\n // TS narrows `result` to boolean from Guard's return type, but a JS caller\n // or a cast can slip a Promise / PromiseLike through. We accept anything\n // thenable (native Promise, cross-realm Promise, user-defined thenable),\n // not just same-realm `instanceof Promise`.\n if (isThenable(result)) {\n throw new AsyncGuardError(guardName);\n }\n return result;\n}\n","import { UnknownGuardError } from \"../fsm/evaluator.js\";\nimport type { Guard, GuardArgs, GuardRef } from \"../fsm/types.js\";\n\nfunction resolveItem<Ctx, Evt>(item: GuardRef<Ctx, Evt>, args: GuardArgs<Ctx, Evt>): boolean {\n if (typeof item === \"function\") return item(args);\n const fn = args.guards?.[item];\n if (!fn) throw new UnknownGuardError(item);\n return fn(args);\n}\n\n/** Logical AND over guards. Short-circuits on the first `false`. */\nexport function and<Ctx, Evt>(items: readonly GuardRef<Ctx, Evt>[]): Guard<Ctx, Evt> {\n return (args) => {\n for (const item of items) {\n if (!resolveItem(item, args)) return false;\n }\n return true;\n };\n}\n\n/** Logical OR over guards. Short-circuits on the first `true`. */\nexport function or<Ctx, Evt>(items: readonly GuardRef<Ctx, Evt>[]): Guard<Ctx, Evt> {\n return (args) => {\n for (const item of items) {\n if (resolveItem(item, args)) return true;\n }\n return false;\n };\n}\n\n/** Logical NOT. */\nexport function not<Ctx, Evt>(item: GuardRef<Ctx, Evt>): Guard<Ctx, Evt> {\n return (args) => !resolveItem(item, args);\n}\n\n/**\n * Predicate that passes when the current state value is one of the listed\n * states. Reads `args.value`, which `evalGuard` threads from the live\n * snapshot. When called outside of `evalGuard` (e.g. unit tests), `value` is\n * `undefined` and the guard returns `false`.\n */\nexport function stateIn<Ctx, Evt>(...states: readonly string[]): Guard<Ctx, Evt> {\n const set = new Set<string>(states);\n return ({ value }) => typeof value === \"string\" && set.has(value);\n}\n"]}
1
+ {"version":3,"sources":["../../src/guards/index.ts"],"names":[],"mappings":";;;;AAGA,SAAS,WAAA,CAAsB,MAA0B,IAAA,EAAoC;AAC3F,EAAA,MAAM,KAAK,OAAO,IAAA,KAAS,aAAa,IAAA,GAAO,IAAA,CAAK,SAAS,IAAI,CAAA;AACjE,EAAA,IAAI,CAAC,EAAA,EAAI,MAAM,IAAI,kBAAkB,IAAc,CAAA;AACnD,EAAA,MAAM,MAAA,GAAS,GAAG,IAAI,CAAA;AAItB,EAAA,IAAI,UAAA,CAAW,MAAM,CAAA,EAAG;AAGtB,IAAA,MAAM,IAAI,gBAAgB,OAAO,IAAA,KAAS,WAAW,IAAA,GAAO,EAAA,CAAG,QAAQ,UAAU,CAAA;AAAA,EACnF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,IAAc,KAAA,EAAuD;AACnF,EAAA,OAAO,CAAC,IAAA,KAAS;AACf,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,IAAI,CAAC,WAAA,CAAY,IAAA,EAAM,IAAI,GAAG,OAAO,KAAA;AAAA,IACvC;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA;AACF;AAGO,SAAS,GAAa,KAAA,EAAuD;AAClF,EAAA,OAAO,CAAC,IAAA,KAAS;AACf,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,IAAI,WAAA,CAAY,IAAA,EAAM,IAAI,CAAA,EAAG,OAAO,IAAA;AAAA,IACtC;AACA,IAAA,OAAO,KAAA;AAAA,EACT,CAAA;AACF;AAGO,SAAS,IAAc,IAAA,EAA2C;AACvE,EAAA,OAAO,CAAC,IAAA,KAAS,CAAC,WAAA,CAAY,MAAM,IAAI,CAAA;AAC1C;AAQO,SAAS,WAAqB,MAAA,EAA4C;AAC/E,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAY,MAAM,CAAA;AAClC,EAAA,OAAO,CAAC,EAAE,KAAA,EAAM,KAAM,OAAO,KAAA,KAAU,QAAA,IAAY,GAAA,CAAI,GAAA,CAAI,KAAK,CAAA;AAClE","file":"index.js","sourcesContent":["import { AsyncGuardError, UnknownGuardError, isThenable } from \"../fsm/evaluator.js\";\nimport type { Guard, GuardArgs, GuardRef } from \"../fsm/types.js\";\n\nfunction resolveItem<Ctx, Evt>(item: GuardRef<Ctx, Evt>, args: GuardArgs<Ctx, Evt>): boolean {\n const fn = typeof item === \"function\" ? item : args.guards?.[item];\n if (!fn) throw new UnknownGuardError(item as string);\n const result = fn(args);\n // Mirror evalGuard's safety net: a guard that returns a thenable breaks\n // determinism. Checked here too so a thenable nested inside and/or/not is\n // rejected rather than coerced truthy by the combinator (FSM-S-01).\n if (isThenable(result)) {\n // Function.prototype.name is \"\" for anonymous arrows — fall back to\n // \"<inline>\" so the message stays readable (matches evalGuard).\n throw new AsyncGuardError(typeof item === \"string\" ? item : fn.name || \"<inline>\");\n }\n return result;\n}\n\n/** Logical AND over guards. Short-circuits on the first `false`. */\nexport function and<Ctx, Evt>(items: readonly GuardRef<Ctx, Evt>[]): Guard<Ctx, Evt> {\n return (args) => {\n for (const item of items) {\n if (!resolveItem(item, args)) return false;\n }\n return true;\n };\n}\n\n/** Logical OR over guards. Short-circuits on the first `true`. */\nexport function or<Ctx, Evt>(items: readonly GuardRef<Ctx, Evt>[]): Guard<Ctx, Evt> {\n return (args) => {\n for (const item of items) {\n if (resolveItem(item, args)) return true;\n }\n return false;\n };\n}\n\n/** Logical NOT. */\nexport function not<Ctx, Evt>(item: GuardRef<Ctx, Evt>): Guard<Ctx, Evt> {\n return (args) => !resolveItem(item, args);\n}\n\n/**\n * Predicate that passes when the current state value is one of the listed\n * states. Reads `args.value`, which `evalGuard` threads from the live\n * snapshot. When called outside of `evalGuard` (e.g. unit tests), `value` is\n * `undefined` and the guard returns `false`.\n */\nexport function stateIn<Ctx, Evt>(...states: readonly string[]): Guard<Ctx, Evt> {\n const set = new Set<string>(states);\n return ({ value }) => typeof value === \"string\" && set.has(value);\n}\n"]}