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.
- package/README.md +8 -4
- package/README_ZHTW.md +7 -5
- package/dist/chunk-2MME5V4F.cjs +384 -0
- package/dist/chunk-2MME5V4F.cjs.map +1 -0
- package/dist/chunk-3B2USJ3H.cjs +18 -0
- package/dist/chunk-3B2USJ3H.cjs.map +1 -0
- package/dist/chunk-A7U7QQL5.js +52 -0
- package/dist/chunk-A7U7QQL5.js.map +1 -0
- package/dist/chunk-CDK25FTD.cjs +59 -0
- package/dist/chunk-CDK25FTD.cjs.map +1 -0
- package/dist/chunk-FHTQ7LSQ.cjs +21 -0
- package/dist/chunk-FHTQ7LSQ.cjs.map +1 -0
- package/dist/chunk-I354FONA.cjs +153 -0
- package/dist/chunk-I354FONA.cjs.map +1 -0
- package/dist/chunk-JKZAOPQC.js +16 -0
- package/dist/chunk-JKZAOPQC.js.map +1 -0
- package/dist/chunk-NEJYZAKR.js +19 -0
- package/dist/chunk-NEJYZAKR.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +11 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/chunk-VZCSHTOI.js +374 -0
- package/dist/chunk-VZCSHTOI.js.map +1 -0
- package/dist/chunk-ZLQ7HZCE.js +142 -0
- package/dist/chunk-ZLQ7HZCE.js.map +1 -0
- package/dist/effects/index.cjs +8 -14
- package/dist/effects/index.cjs.map +1 -1
- package/dist/effects/index.js +5 -14
- package/dist/effects/index.js.map +1 -1
- package/dist/guards/index.cjs +9 -13
- package/dist/guards/index.cjs.map +1 -1
- package/dist/guards/index.js +8 -12
- package/dist/guards/index.js.map +1 -1
- package/dist/index.cjs +101 -591
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -571
- package/dist/index.js.map +1 -1
- package/dist/inspect/index.cjs +2 -0
- package/dist/inspect/index.cjs.map +1 -1
- package/dist/inspect/index.js +2 -0
- package/dist/inspect/index.js.map +1 -1
- package/dist/pbt/index.cjs +26 -525
- package/dist/pbt/index.cjs.map +1 -1
- package/dist/pbt/index.d.cts +7 -3
- package/dist/pbt/index.d.ts +7 -3
- package/dist/pbt/index.js +12 -511
- package/dist/pbt/index.js.map +1 -1
- package/dist/replay/index.cjs +9 -195
- package/dist/replay/index.cjs.map +1 -1
- package/dist/replay/index.js +5 -198
- package/dist/replay/index.js.map +1 -1
- package/dist/timer/index.cjs +30 -9
- package/dist/timer/index.cjs.map +1 -1
- package/dist/timer/index.js +30 -9
- package/dist/timer/index.js.map +1 -1
- package/llms-full.txt +159 -8
- package/package.json +5 -3
package/dist/effects/index.cjs
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
22
|
+
if (chunkCDK25FTD_cjs.isThenable(r)) promises.push(Promise.resolve(r));
|
|
32
23
|
}
|
|
33
24
|
return promises;
|
|
34
25
|
}
|
|
35
26
|
|
|
36
|
-
exports
|
|
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/
|
|
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"]}
|
package/dist/effects/index.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
20
|
+
if (isThenable(r)) promises.push(Promise.resolve(r));
|
|
30
21
|
}
|
|
31
22
|
return promises;
|
|
32
23
|
}
|
|
33
24
|
|
|
34
|
-
export {
|
|
25
|
+
export { runEffects };
|
|
35
26
|
//# sourceMappingURL=index.js.map
|
|
36
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/effects/
|
|
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"]}
|
package/dist/guards/index.cjs
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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/
|
|
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"]}
|
package/dist/guards/index.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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) => {
|
package/dist/guards/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
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"]}
|