@fabricorg/platform 1.1.0 → 1.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/CHANGELOG.md +77 -0
- package/README.md +20 -7
- package/dist/adapters/index.cjs +18 -6
- package/dist/adapters/index.d.cts +76 -1
- package/dist/adapters/index.d.ts +76 -1
- package/dist/adapters/index.js +1 -1
- package/dist/{chunk-YZKUEC2J.cjs → chunk-3BGFHSSK.cjs} +4 -4
- package/dist/{chunk-YZKUEC2J.cjs.map → chunk-3BGFHSSK.cjs.map} +1 -1
- package/dist/{chunk-OWSSGFNY.js → chunk-7GAWSUOG.js} +22 -3
- package/dist/chunk-7GAWSUOG.js.map +1 -0
- package/dist/{chunk-A2VTSATF.cjs → chunk-7HPNONN7.cjs} +7 -6
- package/dist/chunk-7HPNONN7.cjs.map +1 -0
- package/dist/{chunk-IFMZPLM4.js → chunk-AWP6JDD5.js} +3 -3
- package/dist/{chunk-IFMZPLM4.js.map → chunk-AWP6JDD5.js.map} +1 -1
- package/dist/{chunk-M5FGWXT3.cjs → chunk-CXR6KEKQ.cjs} +11 -10
- package/dist/chunk-CXR6KEKQ.cjs.map +1 -0
- package/dist/{chunk-3ZW5USXF.js → chunk-DTY3CHQZ.js} +24 -5
- package/dist/chunk-DTY3CHQZ.js.map +1 -0
- package/dist/{chunk-6T6F3TNQ.cjs → chunk-G6WXP5ZZ.cjs} +13 -12
- package/dist/chunk-G6WXP5ZZ.cjs.map +1 -0
- package/dist/chunk-IFW43ELT.cjs +331 -0
- package/dist/chunk-IFW43ELT.cjs.map +1 -0
- package/dist/{chunk-J5LS5BSI.js → chunk-JG35DT2G.js} +11 -10
- package/dist/chunk-JG35DT2G.js.map +1 -0
- package/dist/{chunk-53YJK3LK.js → chunk-KADDDQHO.js} +6 -5
- package/dist/chunk-KADDDQHO.js.map +1 -0
- package/dist/{chunk-NPVIFZQV.cjs → chunk-N2BBUKCX.cjs} +26 -4
- package/dist/chunk-N2BBUKCX.cjs.map +1 -0
- package/dist/{chunk-ANPJYXBK.cjs → chunk-TBS2S5AX.cjs} +8 -2
- package/dist/chunk-TBS2S5AX.cjs.map +1 -0
- package/dist/{chunk-WAI4UNWQ.cjs → chunk-WI7CWNYI.cjs} +22 -2
- package/dist/chunk-WI7CWNYI.cjs.map +1 -0
- package/dist/{chunk-3OWMPDBD.js → chunk-Y2PJLRIY.js} +8 -2
- package/dist/chunk-Y2PJLRIY.js.map +1 -0
- package/dist/chunk-ZAEVQSB5.js +326 -0
- package/dist/chunk-ZAEVQSB5.js.map +1 -0
- package/dist/{chunk-ETONSTUW.js → chunk-ZOOGUUY4.js} +4 -3
- package/dist/chunk-ZOOGUUY4.js.map +1 -0
- package/dist/governance/index.cjs +4 -4
- package/dist/governance/index.d.cts +4 -0
- package/dist/governance/index.d.ts +4 -0
- package/dist/governance/index.js +1 -1
- package/dist/index.cjs +62 -42
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +8 -8
- package/dist/manifest/index.cjs +10 -10
- package/dist/manifest/index.d.cts +1 -0
- package/dist/manifest/index.d.ts +1 -0
- package/dist/manifest/index.js +4 -4
- package/dist/modules/index.cjs +11 -11
- package/dist/modules/index.d.cts +2 -0
- package/dist/modules/index.d.ts +2 -0
- package/dist/modules/index.js +3 -3
- package/dist/objects/index.cjs +8 -4
- package/dist/objects/index.d.cts +11 -1
- package/dist/objects/index.d.ts +11 -1
- package/dist/objects/index.js +1 -1
- package/dist/projections/index.cjs +5 -5
- package/dist/projections/index.d.cts +9 -1
- package/dist/projections/index.d.ts +9 -1
- package/dist/projections/index.js +1 -1
- package/dist/state-machines/index.cjs +7 -3
- package/dist/state-machines/index.d.cts +10 -1
- package/dist/state-machines/index.d.ts +10 -1
- package/dist/state-machines/index.js +1 -1
- package/dist/testing/index.cjs +5 -5
- package/dist/testing/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-3OWMPDBD.js.map +0 -1
- package/dist/chunk-3ZW5USXF.js.map +0 -1
- package/dist/chunk-53YJK3LK.js.map +0 -1
- package/dist/chunk-6T6F3TNQ.cjs.map +0 -1
- package/dist/chunk-A2VTSATF.cjs.map +0 -1
- package/dist/chunk-ANPJYXBK.cjs.map +0 -1
- package/dist/chunk-CBY6GRJP.cjs +0 -140
- package/dist/chunk-CBY6GRJP.cjs.map +0 -1
- package/dist/chunk-ETONSTUW.js.map +0 -1
- package/dist/chunk-J5LS5BSI.js.map +0 -1
- package/dist/chunk-M5FGWXT3.cjs.map +0 -1
- package/dist/chunk-NETLRKDS.js +0 -136
- package/dist/chunk-NETLRKDS.js.map +0 -1
- package/dist/chunk-NPVIFZQV.cjs.map +0 -1
- package/dist/chunk-OWSSGFNY.js.map +0 -1
- package/dist/chunk-WAI4UNWQ.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,82 @@
|
|
|
1
1
|
# @fabricorg/platform
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9b2e55b: Close what a fourth review found: each earlier fix closed one instance of a class and left its
|
|
8
|
+
siblings.
|
|
9
|
+
|
|
10
|
+
**Replay disposition is now exhaustive over `ActionStatus`.** The previous fix enumerated the two
|
|
11
|
+
statuses that looked like refusals, so `failed`, `validation_failed` and `waiting_for_approval` fell
|
|
12
|
+
through and were deleted from the queue and reported to the operator as applied — the same bug the
|
|
13
|
+
fix set out to kill, one layer in. Any returned outcome now means the platform holds the invocation,
|
|
14
|
+
so the capture leaves the queue either way; what differs is whether a person needs to hear about it.
|
|
15
|
+
An undeterminable adapter outcome is reported as `unknown` rather than `refused`, because the effect
|
|
16
|
+
may well have happened. `isSettledReplayFailure` learned the refusals the sibling commit introduced,
|
|
17
|
+
including a capture rejected for age, which can never come good.
|
|
18
|
+
|
|
19
|
+
**A replay without `capturedAt` is refused.** It was reachable only through an untyped cast, so
|
|
20
|
+
omitting it skipped the age check entirely and stamped receipt time into durable capture evidence.
|
|
21
|
+
|
|
22
|
+
**A capability can name a namespaced port.** `definePort` required a dot and the manifest validator
|
|
23
|
+
forbade one, so no real capability could name a defined port and the certification gate was
|
|
24
|
+
unreachable. Certification is also checked structurally rather than by the presence of a property, so
|
|
25
|
+
a hand-written claim no longer satisfies the gate that exists to demand evidence, and a port
|
|
26
|
+
requirement narrows its candidates as each constraint is applied.
|
|
27
|
+
|
|
28
|
+
**`assertPortSuiteHasTeeth` names every vacuous check** rather than returning on the first one that
|
|
29
|
+
bites, and a reference port is actually run through it. The payments control asserts its result, so
|
|
30
|
+
an adapter that never charges no longer certifies. The capability-reference grammar matches the
|
|
31
|
+
platform's own view-name rule instead of being stricter than it, and ambiguity is counted by
|
|
32
|
+
occurrence across views and intents rather than by comparing names within one contract.
|
|
33
|
+
|
|
34
|
+
## 1.2.0
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- ef4e3eb: Classify adapter outcomes: add additive `AdapterOutcomeKind` (`success`, `transient_failure`,
|
|
39
|
+
`permanent_failure`, `timeout`, `ambiguous`) and `AdapterOutcomeEvidence` to the portable adapter
|
|
40
|
+
contract. The retry layer now retries only transient idempotent outcomes; permanent failures,
|
|
41
|
+
timeouts, and ambiguous results are never retried. Ambiguous outcomes are routed to
|
|
42
|
+
`reconciliation_required` with durable `ExternalReconciliation` evidence and an
|
|
43
|
+
`AdapterInvocationAmbiguous` lifecycle event. Add deadline and cancellation context to
|
|
44
|
+
`AdapterExecutionContext`. Backward compatible: adapters that omit `outcome` behave as before.
|
|
45
|
+
- 293561d: Close adapter and saga correctness gaps: deliver actual deadline and AbortSignal context to adapters, require the governed Host to classify thrown adapter failures before retrying, reject contradictory successful ambiguous outcomes, reserve parent lifecycle identity prefixes, and provide a durable Platform Host parent lifecycle adapter tested through public store seams. Direct `executeWithAdapterRetry` callers retain the prior idempotent retry default when they omit a classifier.
|
|
46
|
+
- 9a145a3: Add assembly and initiating SDUI release digests to durable governance runtime
|
|
47
|
+
evidence. Hosts can attach both through trusted configuration, including a
|
|
48
|
+
per-submission release resolver, and validate digest shape before creating the
|
|
49
|
+
invocation. Composition-bound hosts verify their assembly lockfile against the
|
|
50
|
+
exact loaded capability artifacts before accepting submissions.
|
|
51
|
+
- b932767: Add portable parameter schemas and validation for projection views. Projection snapshot keys now
|
|
52
|
+
include a canonical parameter identity, generated capability and experience contracts preserve view
|
|
53
|
+
parameter schemas, and compatible snapshots continue through the explicit `upgradeSnapshot` seam.
|
|
54
|
+
- fb14d67: Execute state guards with trusted Host context, correct filtered-ledger replay semantics, make
|
|
55
|
+
dispatcher failure retryable, fail closed for unsafe saga and non-idempotent recovery paths, preserve
|
|
56
|
+
outbox consistency, and bound and redact OPA HTTP failures.
|
|
57
|
+
|
|
58
|
+
### Additional release notes
|
|
59
|
+
|
|
60
|
+
### Minor Changes
|
|
61
|
+
|
|
62
|
+
- Add additive adapter outcome classification (`AdapterOutcomeKind`: `success`, `transient_failure`,
|
|
63
|
+
`permanent_failure`, `timeout`, `ambiguous`) and `AdapterOutcomeEvidence`. The retry layer retries
|
|
64
|
+
only transient idempotent outcomes. Add deadline and cancellation context to
|
|
65
|
+
`AdapterExecutionContext`. Backward compatible: adapters that omit `outcome` behave as before.
|
|
66
|
+
- Add `signal?: AbortSignal` to `AdapterExecutionContext` so the host can deliver a real
|
|
67
|
+
cancellation signal to adapters. Add `classifyThrownError` to `ExecuteWithRetryOptions`:
|
|
68
|
+
thrown errors are never retried without explicit classification (fail safe). Add
|
|
69
|
+
`assertAdapterOutcomeConsistency` to reject contradictory results where `success` is true
|
|
70
|
+
but the explicit `outcome` is a non-success kind.
|
|
71
|
+
- Add guard-aware state transition evaluation that fails closed on guard denial or exceptions.
|
|
72
|
+
- Clarify that projection `sequence` is a global ledger cursor and add optional
|
|
73
|
+
`subjectSequence` for sources that can prove subject-local continuity.
|
|
74
|
+
- Add portable JSON Schema validation for projection parameters and expose
|
|
75
|
+
`ViewContract.parameterSchema` for parameterized view variants.
|
|
76
|
+
- Add optional module `version` and compiler `manifestDigest` identity for
|
|
77
|
+
assembly-verified runtime registration, plus durable assembly and initiating
|
|
78
|
+
release digests in `GovernanceRuntimeEvidence`.
|
|
79
|
+
|
|
3
80
|
## 1.1.0
|
|
4
81
|
|
|
5
82
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ That's what this package gives you. Nothing more.
|
|
|
44
44
|
| `@fabricorg/platform` | Re-exports everything below |
|
|
45
45
|
| `@fabricorg/platform/actions` | `ActionDefinition`, `ActionContext`, `SagaImplementation` |
|
|
46
46
|
| `@fabricorg/platform/policies` | `PolicyEvaluator`, `PolicyContext`, code/data/hybrid evaluation |
|
|
47
|
-
| `@fabricorg/platform/state-machines` | `StateMachineDefinition`,
|
|
47
|
+
| `@fabricorg/platform/state-machines` | `StateMachineDefinition`, structural and guard-aware transition evaluation |
|
|
48
48
|
| `@fabricorg/platform/events` | `AssetEventEnvelope`, `EventTypeRegistry` |
|
|
49
49
|
| `@fabricorg/platform/projections` | Replay/snapshot framework |
|
|
50
50
|
| `@fabricorg/platform/adapters` | `AdapterRegistry`, retry + circuit-breaker |
|
|
@@ -57,10 +57,12 @@ That's what this package gives you. Nothing more.
|
|
|
57
57
|
| `@fabricorg/platform/objects` | Shared object-type contracts |
|
|
58
58
|
| `@fabricorg/platform/testing` | In-memory adapter registry, fake `ActionContext`, deterministic IDs |
|
|
59
59
|
|
|
60
|
-
Modules may publish versioned `ViewContract`s.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
Modules may publish versioned `ViewContract`s. A view may also declare a portable `parameterSchema`;
|
|
61
|
+
ProjectionHost validates those inputs and keeps each canonical parameter identity in a separate
|
|
62
|
+
snapshot. `replayView` filters declared event schema versions and requires an explicit
|
|
63
|
+
`upgradeSnapshot` function before resuming an older compatible snapshot; manifests serialize the
|
|
64
|
+
logical shape, parameter schema, and metadata but never executable functions or initial state.
|
|
65
|
+
Physical stores remain adapter concerns.
|
|
64
66
|
|
|
65
67
|
## Composing a vertical
|
|
66
68
|
|
|
@@ -105,9 +107,9 @@ An entity schema does not validate arbitrary writes through `TDb`. Persisted-rec
|
|
|
105
107
|
Every `invokeAction(id, params)` call goes through:
|
|
106
108
|
|
|
107
109
|
1. **`evaluatePolicies`** — every policy registered for the action runs (code/data/hybrid). A single `block` halts the invocation. Policies may return `guidance` (`factsUsed` + typed `correctiveActions`) so hosts can show exactly why a block happened and what the operator can do next. Corrective actions declare `kind: "invoke_action" | "navigate" | "manual"` so UIs do not guess whether a remediation is executable.
|
|
108
|
-
2. **State-machine validation** — if the action's target entity is bound to a state machine, the requested transition
|
|
110
|
+
2. **State-machine validation** — if the action's target entity is bound to a state machine, the Host reads authoritative state at the mutation boundary, validates the requested transition, and executes its guard with trusted entity, actor, parameter, invocation, and database context. A false or throwing guard fails closed.
|
|
109
111
|
3. **Handler** — `actionDef.handler(ctx, params)` runs inside a single `TDb` transaction. Handler parses its own input via its `schema` (single source of truth).
|
|
110
|
-
4. **Adapters** — for each `actionDef.adapterSteps`, the registered implementation runs via `executeWithAdapterRetry` (idempotent retry, exponential backoff, circuit breaker).
|
|
112
|
+
4. **Adapters** — for each `actionDef.adapterSteps`, the registered implementation runs via `executeWithAdapterRetry` (idempotent retry, exponential backoff, circuit breaker). Adapters may classify outcomes as `success`, `transient_failure`, `permanent_failure`, `timeout`, or `ambiguous`; only transient idempotent outcomes are retried. Ambiguous outcomes are routed to `reconciliation_required` with durable evidence.
|
|
111
113
|
5. **Events** — domain events are appended; projections derive read models on next replay.
|
|
112
114
|
6. **Completion** — invocation status is marked, telemetry emitted.
|
|
113
115
|
|
|
@@ -136,6 +138,17 @@ export const ingestSaga: SagaImplementation = async (ctx, runChild) => {
|
|
|
136
138
|
|
|
137
139
|
Your worker maps action IDs to implementations. The platform dispatches generically — no platform code references vertical action IDs.
|
|
138
140
|
|
|
141
|
+
`PlatformHost` does not execute a `kind: "saga"` definition as an atomic handler. Configure a
|
|
142
|
+
durable dispatcher and map the action to its saga implementation in the workflow worker. Direct
|
|
143
|
+
execution fails closed so a handlerless saga cannot be recorded as completed.
|
|
144
|
+
|
|
145
|
+
## Projection sequence semantics
|
|
146
|
+
|
|
147
|
+
`ReplayableAssetEvent.sequence` is the ordering cursor of the complete tenant/space ledger. A view
|
|
148
|
+
usually filters that ledger by event type and subject, so gaps in this global cursor do not prove
|
|
149
|
+
that subject events are missing. Event sources that can guarantee contiguous per-subject ordering
|
|
150
|
+
may also provide `subjectSequence`; only that explicit sequence is used for missing-event warnings.
|
|
151
|
+
|
|
139
152
|
## Portability boundary
|
|
140
153
|
|
|
141
154
|
The repository Boundary Guard scans source and packed artifacts and fails CI if any of these leak in:
|
package/dist/adapters/index.cjs
CHANGED
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkN2BBUKCX_cjs = require('../chunk-N2BBUKCX.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "AdapterRegistry", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkN2BBUKCX_cjs.AdapterRegistry; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "MissingAdapterRegistrationError", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkN2BBUKCX_cjs.MissingAdapterRegistrationError; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "assertAdapterOutcomeConsistency", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkN2BBUKCX_cjs.assertAdapterOutcomeConsistency; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "classifyAdapterOutcome", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunkN2BBUKCX_cjs.classifyAdapterOutcome; }
|
|
14
22
|
});
|
|
15
23
|
Object.defineProperty(exports, "executeWithAdapterRetry", {
|
|
16
24
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkN2BBUKCX_cjs.executeWithAdapterRetry; }
|
|
18
26
|
});
|
|
19
27
|
Object.defineProperty(exports, "getRetryDelayMs", {
|
|
20
28
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
29
|
+
get: function () { return chunkN2BBUKCX_cjs.getRetryDelayMs; }
|
|
22
30
|
});
|
|
23
31
|
Object.defineProperty(exports, "resolveAdapterRetryPolicy", {
|
|
24
32
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
33
|
+
get: function () { return chunkN2BBUKCX_cjs.resolveAdapterRetryPolicy; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "shouldRetryAdapterOutcome", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return chunkN2BBUKCX_cjs.shouldRetryAdapterOutcome; }
|
|
26
38
|
});
|
|
27
39
|
//# sourceMappingURL=index.cjs.map
|
|
28
40
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -7,11 +7,51 @@ interface AdapterExecutionContext {
|
|
|
7
7
|
causationId?: string;
|
|
8
8
|
attempt: number;
|
|
9
9
|
maxAttempts: number;
|
|
10
|
+
/** Epoch-millis deadline after which the adapter should abandon the call. */
|
|
11
|
+
deadlineMs?: number;
|
|
12
|
+
/** Set by the host when the invocation has been cancelled; adapters should stop work. */
|
|
13
|
+
cancelled?: boolean;
|
|
14
|
+
/** Non-secret reason the invocation was cancelled. */
|
|
15
|
+
cancellationReason?: string;
|
|
16
|
+
/**
|
|
17
|
+
* AbortSignal the host aborts when the deadline expires or the invocation is
|
|
18
|
+
* cancelled. Adapters should propagate this to underlying HTTP/database
|
|
19
|
+
* clients so in-flight work is abandoned rather than left dangling.
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Additive classification of an adapter outcome so the retry layer can
|
|
25
|
+
* distinguish retryable transient failures from permanent rejections,
|
|
26
|
+
* timeouts, and ambiguous results that require manual reconciliation.
|
|
27
|
+
*
|
|
28
|
+
* When `outcome` is absent on an {@link AdapterExecutionResult}, the retry
|
|
29
|
+
* layer treats a non-success result as `transient_failure` for backward
|
|
30
|
+
* compatibility.
|
|
31
|
+
*/
|
|
32
|
+
type AdapterOutcomeKind = "success" | "transient_failure" | "permanent_failure" | "timeout" | "ambiguous";
|
|
33
|
+
/**
|
|
34
|
+
* Durable, non-secret evidence attached to a classified adapter outcome.
|
|
35
|
+
* Used by the host to record reconciliation evidence when an adapter returns
|
|
36
|
+
* an ambiguous result whose external effect may or may not have been applied.
|
|
37
|
+
*/
|
|
38
|
+
interface AdapterOutcomeEvidence {
|
|
39
|
+
kind: AdapterOutcomeKind;
|
|
40
|
+
reason?: string;
|
|
41
|
+
/** Opaque, non-secret reference to external operation state for reconciliation. */
|
|
42
|
+
externalReference?: string;
|
|
43
|
+
/** Whether the external effect may have been applied (true for ambiguous/timeout). */
|
|
44
|
+
effectMayHaveApplied?: boolean;
|
|
45
|
+
observedAt: Date | string;
|
|
10
46
|
}
|
|
11
47
|
interface AdapterExecutionResult {
|
|
12
48
|
success: boolean;
|
|
13
49
|
correlationId?: string;
|
|
14
50
|
error?: string;
|
|
51
|
+
/** Additive outcome classification. Omitted = infer from `success`. */
|
|
52
|
+
outcome?: AdapterOutcomeKind;
|
|
53
|
+
/** Durable evidence for ambiguous or timeout outcomes requiring reconciliation. */
|
|
54
|
+
outcomeEvidence?: AdapterOutcomeEvidence;
|
|
15
55
|
}
|
|
16
56
|
type AdapterExecutor = (input: Record<string, unknown>, context: AdapterExecutionContext) => Promise<AdapterExecutionResult>;
|
|
17
57
|
interface AdapterRetryPolicy {
|
|
@@ -64,6 +104,20 @@ interface ExecuteWithRetryOptions<T> {
|
|
|
64
104
|
execute: (attempt: number, maxAttempts: number) => Promise<T>;
|
|
65
105
|
isSuccessful: (result: T) => boolean;
|
|
66
106
|
getError: (result: T) => string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Optional outcome classifier. When provided, the retry layer retries only
|
|
109
|
+
* `transient_failure` outcomes (and only when the policy is idempotent).
|
|
110
|
+
* `permanent_failure`, `timeout`, and `ambiguous` outcomes are never retried.
|
|
111
|
+
* When omitted, all non-success results are treated as transient (backward compatible).
|
|
112
|
+
*/
|
|
113
|
+
classifyOutcome?: (result: T) => AdapterOutcomeKind;
|
|
114
|
+
/**
|
|
115
|
+
* Optional classifier for errors thrown by the execute callback (not returned
|
|
116
|
+
* as results). When provided, the retry layer retries only `transient_failure`
|
|
117
|
+
* classifications. When omitted, thrown errors are never retried — the caller
|
|
118
|
+
* must explicitly opt into retrying a thrown failure by classifying it.
|
|
119
|
+
*/
|
|
120
|
+
classifyThrownError?: (error: unknown) => AdapterOutcomeKind;
|
|
67
121
|
sleep?: (delayMs: number) => Promise<void>;
|
|
68
122
|
onAttempt?: (attempt: AdapterAttempt<T>) => Promise<void> | void;
|
|
69
123
|
}
|
|
@@ -78,6 +132,27 @@ declare class AdapterRegistry {
|
|
|
78
132
|
}
|
|
79
133
|
declare function resolveAdapterRetryPolicy(policy: AdapterRetryPolicy | undefined, defaultIdempotent: boolean): ResolvedAdapterRetryPolicy;
|
|
80
134
|
declare function getRetryDelayMs(attempt: number, policy: ResolvedAdapterRetryPolicy): number;
|
|
135
|
+
/**
|
|
136
|
+
* Classify an {@link AdapterExecutionResult} into an {@link AdapterOutcomeKind}.
|
|
137
|
+
* When `outcome` is explicitly set, it is returned directly, after rejecting a
|
|
138
|
+
* contradictory result where `success` is true but the outcome is non-success.
|
|
139
|
+
* Otherwise a successful result maps to `success` and a failed result maps to
|
|
140
|
+
* `transient_failure` (the historical default).
|
|
141
|
+
*/
|
|
142
|
+
declare function classifyAdapterOutcome(result: AdapterExecutionResult): AdapterOutcomeKind;
|
|
143
|
+
/**
|
|
144
|
+
* Determine whether an outcome kind is retryable. Only `transient_failure`
|
|
145
|
+
* is retryable, and only when the adapter policy is idempotent. Permanent
|
|
146
|
+
* failures, timeouts, and ambiguous outcomes are never retried.
|
|
147
|
+
*/
|
|
148
|
+
declare function shouldRetryAdapterOutcome(kind: AdapterOutcomeKind, idempotent: boolean): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Reject a contradictory adapter result where `success` is true but the
|
|
151
|
+
* explicit `outcome` is a non-success kind. A successful result claiming an
|
|
152
|
+
* ambiguous, permanent, timeout, or transient outcome is a programming
|
|
153
|
+
* error — the adapter cannot have both succeeded and require reconciliation.
|
|
154
|
+
*/
|
|
155
|
+
declare function assertAdapterOutcomeConsistency(result: AdapterExecutionResult): void;
|
|
81
156
|
declare function executeWithAdapterRetry<T>(options: ExecuteWithRetryOptions<T>): Promise<T>;
|
|
82
157
|
|
|
83
|
-
export { type AdapterAttempt, type AdapterCircuitBreakerConfig, type AdapterExecutionContext, type AdapterExecutionResult, type AdapterExecutor, type AdapterImplementation, AdapterRegistry, type AdapterRetryPolicy, type ExecuteWithRetryOptions, MissingAdapterRegistrationError, type ResolvedAdapterRetryPolicy, executeWithAdapterRetry, getRetryDelayMs, resolveAdapterRetryPolicy };
|
|
158
|
+
export { type AdapterAttempt, type AdapterCircuitBreakerConfig, type AdapterExecutionContext, type AdapterExecutionResult, type AdapterExecutor, type AdapterImplementation, type AdapterOutcomeEvidence, type AdapterOutcomeKind, AdapterRegistry, type AdapterRetryPolicy, type ExecuteWithRetryOptions, MissingAdapterRegistrationError, type ResolvedAdapterRetryPolicy, assertAdapterOutcomeConsistency, classifyAdapterOutcome, executeWithAdapterRetry, getRetryDelayMs, resolveAdapterRetryPolicy, shouldRetryAdapterOutcome };
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -7,11 +7,51 @@ interface AdapterExecutionContext {
|
|
|
7
7
|
causationId?: string;
|
|
8
8
|
attempt: number;
|
|
9
9
|
maxAttempts: number;
|
|
10
|
+
/** Epoch-millis deadline after which the adapter should abandon the call. */
|
|
11
|
+
deadlineMs?: number;
|
|
12
|
+
/** Set by the host when the invocation has been cancelled; adapters should stop work. */
|
|
13
|
+
cancelled?: boolean;
|
|
14
|
+
/** Non-secret reason the invocation was cancelled. */
|
|
15
|
+
cancellationReason?: string;
|
|
16
|
+
/**
|
|
17
|
+
* AbortSignal the host aborts when the deadline expires or the invocation is
|
|
18
|
+
* cancelled. Adapters should propagate this to underlying HTTP/database
|
|
19
|
+
* clients so in-flight work is abandoned rather than left dangling.
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Additive classification of an adapter outcome so the retry layer can
|
|
25
|
+
* distinguish retryable transient failures from permanent rejections,
|
|
26
|
+
* timeouts, and ambiguous results that require manual reconciliation.
|
|
27
|
+
*
|
|
28
|
+
* When `outcome` is absent on an {@link AdapterExecutionResult}, the retry
|
|
29
|
+
* layer treats a non-success result as `transient_failure` for backward
|
|
30
|
+
* compatibility.
|
|
31
|
+
*/
|
|
32
|
+
type AdapterOutcomeKind = "success" | "transient_failure" | "permanent_failure" | "timeout" | "ambiguous";
|
|
33
|
+
/**
|
|
34
|
+
* Durable, non-secret evidence attached to a classified adapter outcome.
|
|
35
|
+
* Used by the host to record reconciliation evidence when an adapter returns
|
|
36
|
+
* an ambiguous result whose external effect may or may not have been applied.
|
|
37
|
+
*/
|
|
38
|
+
interface AdapterOutcomeEvidence {
|
|
39
|
+
kind: AdapterOutcomeKind;
|
|
40
|
+
reason?: string;
|
|
41
|
+
/** Opaque, non-secret reference to external operation state for reconciliation. */
|
|
42
|
+
externalReference?: string;
|
|
43
|
+
/** Whether the external effect may have been applied (true for ambiguous/timeout). */
|
|
44
|
+
effectMayHaveApplied?: boolean;
|
|
45
|
+
observedAt: Date | string;
|
|
10
46
|
}
|
|
11
47
|
interface AdapterExecutionResult {
|
|
12
48
|
success: boolean;
|
|
13
49
|
correlationId?: string;
|
|
14
50
|
error?: string;
|
|
51
|
+
/** Additive outcome classification. Omitted = infer from `success`. */
|
|
52
|
+
outcome?: AdapterOutcomeKind;
|
|
53
|
+
/** Durable evidence for ambiguous or timeout outcomes requiring reconciliation. */
|
|
54
|
+
outcomeEvidence?: AdapterOutcomeEvidence;
|
|
15
55
|
}
|
|
16
56
|
type AdapterExecutor = (input: Record<string, unknown>, context: AdapterExecutionContext) => Promise<AdapterExecutionResult>;
|
|
17
57
|
interface AdapterRetryPolicy {
|
|
@@ -64,6 +104,20 @@ interface ExecuteWithRetryOptions<T> {
|
|
|
64
104
|
execute: (attempt: number, maxAttempts: number) => Promise<T>;
|
|
65
105
|
isSuccessful: (result: T) => boolean;
|
|
66
106
|
getError: (result: T) => string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Optional outcome classifier. When provided, the retry layer retries only
|
|
109
|
+
* `transient_failure` outcomes (and only when the policy is idempotent).
|
|
110
|
+
* `permanent_failure`, `timeout`, and `ambiguous` outcomes are never retried.
|
|
111
|
+
* When omitted, all non-success results are treated as transient (backward compatible).
|
|
112
|
+
*/
|
|
113
|
+
classifyOutcome?: (result: T) => AdapterOutcomeKind;
|
|
114
|
+
/**
|
|
115
|
+
* Optional classifier for errors thrown by the execute callback (not returned
|
|
116
|
+
* as results). When provided, the retry layer retries only `transient_failure`
|
|
117
|
+
* classifications. When omitted, thrown errors are never retried — the caller
|
|
118
|
+
* must explicitly opt into retrying a thrown failure by classifying it.
|
|
119
|
+
*/
|
|
120
|
+
classifyThrownError?: (error: unknown) => AdapterOutcomeKind;
|
|
67
121
|
sleep?: (delayMs: number) => Promise<void>;
|
|
68
122
|
onAttempt?: (attempt: AdapterAttempt<T>) => Promise<void> | void;
|
|
69
123
|
}
|
|
@@ -78,6 +132,27 @@ declare class AdapterRegistry {
|
|
|
78
132
|
}
|
|
79
133
|
declare function resolveAdapterRetryPolicy(policy: AdapterRetryPolicy | undefined, defaultIdempotent: boolean): ResolvedAdapterRetryPolicy;
|
|
80
134
|
declare function getRetryDelayMs(attempt: number, policy: ResolvedAdapterRetryPolicy): number;
|
|
135
|
+
/**
|
|
136
|
+
* Classify an {@link AdapterExecutionResult} into an {@link AdapterOutcomeKind}.
|
|
137
|
+
* When `outcome` is explicitly set, it is returned directly, after rejecting a
|
|
138
|
+
* contradictory result where `success` is true but the outcome is non-success.
|
|
139
|
+
* Otherwise a successful result maps to `success` and a failed result maps to
|
|
140
|
+
* `transient_failure` (the historical default).
|
|
141
|
+
*/
|
|
142
|
+
declare function classifyAdapterOutcome(result: AdapterExecutionResult): AdapterOutcomeKind;
|
|
143
|
+
/**
|
|
144
|
+
* Determine whether an outcome kind is retryable. Only `transient_failure`
|
|
145
|
+
* is retryable, and only when the adapter policy is idempotent. Permanent
|
|
146
|
+
* failures, timeouts, and ambiguous outcomes are never retried.
|
|
147
|
+
*/
|
|
148
|
+
declare function shouldRetryAdapterOutcome(kind: AdapterOutcomeKind, idempotent: boolean): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Reject a contradictory adapter result where `success` is true but the
|
|
151
|
+
* explicit `outcome` is a non-success kind. A successful result claiming an
|
|
152
|
+
* ambiguous, permanent, timeout, or transient outcome is a programming
|
|
153
|
+
* error — the adapter cannot have both succeeded and require reconciliation.
|
|
154
|
+
*/
|
|
155
|
+
declare function assertAdapterOutcomeConsistency(result: AdapterExecutionResult): void;
|
|
81
156
|
declare function executeWithAdapterRetry<T>(options: ExecuteWithRetryOptions<T>): Promise<T>;
|
|
82
157
|
|
|
83
|
-
export { type AdapterAttempt, type AdapterCircuitBreakerConfig, type AdapterExecutionContext, type AdapterExecutionResult, type AdapterExecutor, type AdapterImplementation, AdapterRegistry, type AdapterRetryPolicy, type ExecuteWithRetryOptions, MissingAdapterRegistrationError, type ResolvedAdapterRetryPolicy, executeWithAdapterRetry, getRetryDelayMs, resolveAdapterRetryPolicy };
|
|
158
|
+
export { type AdapterAttempt, type AdapterCircuitBreakerConfig, type AdapterExecutionContext, type AdapterExecutionResult, type AdapterExecutor, type AdapterImplementation, type AdapterOutcomeEvidence, type AdapterOutcomeKind, AdapterRegistry, type AdapterRetryPolicy, type ExecuteWithRetryOptions, MissingAdapterRegistrationError, type ResolvedAdapterRetryPolicy, assertAdapterOutcomeConsistency, classifyAdapterOutcome, executeWithAdapterRetry, getRetryDelayMs, resolveAdapterRetryPolicy, shouldRetryAdapterOutcome };
|
package/dist/adapters/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AdapterRegistry, MissingAdapterRegistrationError, executeWithAdapterRetry, getRetryDelayMs, resolveAdapterRetryPolicy } from '../chunk-
|
|
1
|
+
export { AdapterRegistry, MissingAdapterRegistrationError, assertAdapterOutcomeConsistency, classifyAdapterOutcome, executeWithAdapterRetry, getRetryDelayMs, resolveAdapterRetryPolicy, shouldRetryAdapterOutcome } from '../chunk-DTY3CHQZ.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkN2BBUKCX_cjs = require('./chunk-N2BBUKCX.cjs');
|
|
4
4
|
|
|
5
5
|
// testing/index.ts
|
|
6
6
|
function createFakeActionContext(options = {}) {
|
|
@@ -17,7 +17,7 @@ function createFakeActionContext(options = {}) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
function createInMemoryAdapterRegistry() {
|
|
20
|
-
return new
|
|
20
|
+
return new chunkN2BBUKCX_cjs.AdapterRegistry();
|
|
21
21
|
}
|
|
22
22
|
function createDeterministicIdFactory(prefix = "test") {
|
|
23
23
|
let sequence = 0;
|
|
@@ -27,5 +27,5 @@ function createDeterministicIdFactory(prefix = "test") {
|
|
|
27
27
|
exports.createDeterministicIdFactory = createDeterministicIdFactory;
|
|
28
28
|
exports.createFakeActionContext = createFakeActionContext;
|
|
29
29
|
exports.createInMemoryAdapterRegistry = createInMemoryAdapterRegistry;
|
|
30
|
-
//# sourceMappingURL=chunk-
|
|
31
|
-
//# sourceMappingURL=chunk-
|
|
30
|
+
//# sourceMappingURL=chunk-3BGFHSSK.cjs.map
|
|
31
|
+
//# sourceMappingURL=chunk-3BGFHSSK.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../testing/index.ts"],"names":["AdapterRegistry"],"mappings":";;;;;AAeO,SAAS,uBAAA,CACf,OAAA,GAAyC,EAAC,EACrB;AACrB,EAAA,OAAO;AAAA,IACN,kBAAA,EAAoB,QAAQ,kBAAA,IAAsB,UAAA;AAAA,IAClD,QAAA,EAAU,QAAQ,QAAA,IAAY,aAAA;AAAA,IAC9B,OAAA,EAAS,QAAQ,OAAA,IAAW,YAAA;AAAA,IAC5B,OAAA,EAAS,QAAQ,OAAA,IAAW,YAAA;AAAA,IAC5B,SAAA,EAAW,QAAQ,SAAA,IAAa,QAAA;AAAA,IAChC,aAAA,EAAe,QAAQ,aAAA,IAAiB,WAAA;AAAA,IACxC,aAAa,OAAA,CAAQ,WAAA;AAAA,IACrB,EAAA,EAAI,OAAA,CAAQ,EAAA,IAAO,EAAC;AAAA,IACpB,QAAA,EAAU,OAAA,CAAQ,QAAA,IAAY;AAAC,GAChC;AACD;AAEO,SAAS,6BAAA,GAAiD;AAChE,EAAA,OAAO,IAAIA,iCAAA,EAAgB;AAC5B;AAEO,SAAS,4BAAA,CAA6B,SAAS,MAAA,EAAsB;AAC3E,EAAA,IAAI,QAAA,GAAW,CAAA;AACf,EAAA,OAAO,MAAM,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,MAAA,CAAO,EAAE,QAAQ,CAAA,CAAE,QAAA,CAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CAAA;AAC9D","file":"chunk-
|
|
1
|
+
{"version":3,"sources":["../testing/index.ts"],"names":["AdapterRegistry"],"mappings":";;;;;AAeO,SAAS,uBAAA,CACf,OAAA,GAAyC,EAAC,EACrB;AACrB,EAAA,OAAO;AAAA,IACN,kBAAA,EAAoB,QAAQ,kBAAA,IAAsB,UAAA;AAAA,IAClD,QAAA,EAAU,QAAQ,QAAA,IAAY,aAAA;AAAA,IAC9B,OAAA,EAAS,QAAQ,OAAA,IAAW,YAAA;AAAA,IAC5B,OAAA,EAAS,QAAQ,OAAA,IAAW,YAAA;AAAA,IAC5B,SAAA,EAAW,QAAQ,SAAA,IAAa,QAAA;AAAA,IAChC,aAAA,EAAe,QAAQ,aAAA,IAAiB,WAAA;AAAA,IACxC,aAAa,OAAA,CAAQ,WAAA;AAAA,IACrB,EAAA,EAAI,OAAA,CAAQ,EAAA,IAAO,EAAC;AAAA,IACpB,QAAA,EAAU,OAAA,CAAQ,QAAA,IAAY;AAAC,GAChC;AACD;AAEO,SAAS,6BAAA,GAAiD;AAChE,EAAA,OAAO,IAAIA,iCAAA,EAAgB;AAC5B;AAEO,SAAS,4BAAA,CAA6B,SAAS,MAAA,EAAsB;AAC3E,EAAA,IAAI,QAAA,GAAW,CAAA;AACf,EAAA,OAAO,MAAM,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,MAAA,CAAO,EAAE,QAAQ,CAAA,CAAE,QAAA,CAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CAAA;AAC9D","file":"chunk-3BGFHSSK.cjs","sourcesContent":["import { AdapterRegistry } from \"../adapters\";\nimport type { ActionContext, ActorType } from \"../actions\";\n\nexport interface FakeActionContextOptions<TDb = Record<string, never>> {\n\tactionInvocationId?: string;\n\ttenantId?: string;\n\tspaceId?: string;\n\tactorId?: string;\n\tactorType?: ActorType;\n\tcorrelationId?: string;\n\tcausationId?: string;\n\tdb?: TDb;\n\tservices?: Record<string, unknown>;\n}\n\nexport function createFakeActionContext<TDb = Record<string, never>>(\n\toptions: FakeActionContextOptions<TDb> = {},\n): ActionContext<TDb> {\n\treturn {\n\t\tactionInvocationId: options.actionInvocationId ?? \"act_test\",\n\t\ttenantId: options.tenantId ?? \"tenant-test\",\n\t\tspaceId: options.spaceId ?? \"space-test\",\n\t\tactorId: options.actorId ?? \"actor-test\",\n\t\tactorType: options.actorType ?? \"system\",\n\t\tcorrelationId: options.correlationId ?? \"corr-test\",\n\t\tcausationId: options.causationId,\n\t\tdb: options.db ?? ({} as TDb),\n\t\tservices: options.services ?? {},\n\t};\n}\n\nexport function createInMemoryAdapterRegistry(): AdapterRegistry {\n\treturn new AdapterRegistry();\n}\n\nexport function createDeterministicIdFactory(prefix = \"test\"): () => string {\n\tlet sequence = 0;\n\treturn () => `${prefix}_${String(++sequence).padStart(6, \"0\")}`;\n}\n"]}
|
|
@@ -8,6 +8,25 @@ function validateStateMachineTransition(sm, entityType, from, to, actionId) {
|
|
|
8
8
|
const transitionExists = sm.transitions.some((transition) => transition.from === from && transition.to === to && transition.causedByAction === actionId);
|
|
9
9
|
return transitionExists ? { valid: true } : { valid: false, error: `Transition from "${from}" to "${to}" via action "${actionId}" is not defined for entity type "${entityType}".` };
|
|
10
10
|
}
|
|
11
|
+
async function evaluateStateMachineTransition(sm, entityType, from, to, actionId, context) {
|
|
12
|
+
const structural = validateStateMachineTransition(sm, entityType, from, to, actionId);
|
|
13
|
+
if (!structural.valid) return structural;
|
|
14
|
+
const transition = sm.transitions.find(
|
|
15
|
+
(candidate) => candidate.from === from && candidate.to === to && candidate.causedByAction === actionId
|
|
16
|
+
);
|
|
17
|
+
if (!transition?.guard) return structural;
|
|
18
|
+
try {
|
|
19
|
+
return await transition.guard(context) ? structural : {
|
|
20
|
+
valid: false,
|
|
21
|
+
error: `Guard rejected transition from "${from}" to "${to}" via action "${actionId}" for entity type "${entityType}".`
|
|
22
|
+
};
|
|
23
|
+
} catch {
|
|
24
|
+
return {
|
|
25
|
+
valid: false,
|
|
26
|
+
error: `Guard failed while evaluating transition from "${from}" to "${to}" via action "${actionId}" for entity type "${entityType}".`
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
11
30
|
function createStateMachineRegistry(definitions = []) {
|
|
12
31
|
const machines = /* @__PURE__ */ new Map();
|
|
13
32
|
const register = (definition) => {
|
|
@@ -40,6 +59,6 @@ function createStateMachineRegistry(definitions = []) {
|
|
|
40
59
|
};
|
|
41
60
|
}
|
|
42
61
|
|
|
43
|
-
export { createStateMachineRegistry, validateStateMachineTransition };
|
|
44
|
-
//# sourceMappingURL=chunk-
|
|
45
|
-
//# sourceMappingURL=chunk-
|
|
62
|
+
export { createStateMachineRegistry, evaluateStateMachineTransition, validateStateMachineTransition };
|
|
63
|
+
//# sourceMappingURL=chunk-7GAWSUOG.js.map
|
|
64
|
+
//# sourceMappingURL=chunk-7GAWSUOG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../state-machines/engine.ts"],"names":[],"mappings":";AAgCO,SAAS,8BAAA,CACf,EAAA,EACA,UAAA,EACA,IAAA,EACA,IACA,QAAA,EACqC;AACrC,EAAA,IAAI,CAAC,IAAI,OAAO,EAAE,OAAO,KAAA,EAAO,KAAA,EAAO,CAAA,6CAAA,EAAgD,UAAU,CAAA,EAAA,CAAA,EAAK;AACtG,EAAA,MAAM,OAAA,GAAU,EAAA,CAAG,MAAA,CAAO,IAAI,CAAA;AAC9B,EAAA,IAAI,CAAC,OAAA,EAAS,OAAO,EAAE,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,CAAA,OAAA,EAAU,IAAI,CAAA,mDAAA,EAAsD,UAAU,CAAA,EAAA,CAAA,EAAK;AAC/H,EAAA,MAAM,KAAA,GAAQ,EAAA,CAAG,MAAA,CAAO,EAAE,CAAA;AAC1B,EAAA,IAAI,CAAC,KAAA,EAAO,OAAO,EAAE,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,CAAA,OAAA,EAAU,EAAE,CAAA,mDAAA,EAAsD,UAAU,CAAA,EAAA,CAAA,EAAK;AAC3H,EAAA,MAAM,gBAAA,GAAmB,EAAA,CAAG,WAAA,CAAY,IAAA,CAAK,CAAC,UAAA,KAAe,UAAA,CAAW,IAAA,KAAS,IAAA,IAAQ,UAAA,CAAW,EAAA,KAAO,EAAA,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cAAA,EAAgB,CAAA,CAAE,gBAAe,CAAE,CAAA;AAAA,IAC5D,CAAA;AAAA,IACA,UAAA,CAAW,YAAY,KAAA,EAAO;AAC/B,MAAA,MAAM,EAAA,GAAK,QAAA,CAAS,GAAA,CAAI,UAAU,CAAA;AAClC,MAAA,IAAI,CAAC,EAAA,EAAI;AACR,QAAA,OAAO,MAAA;AAAA,MACR;AACA,MAAA,OAAO,EAAA,CAAG,MAAA,CAAO,KAAK,CAAA,EAAG,UAAA;AAAA,IACxB;AAAA,GACD;AACD","file":"chunk-7GAWSUOG.js","sourcesContent":["import type { StateClass, StateDefinition } from \"./index\";\n\nexport interface StateMachineDefinition {\n\tentityType: string;\n\tstates: Record<string, StateDefinition>;\n\ttransitions: Array<{\n\t\tfrom: string;\n\t\tto: string;\n\t\tcausedByAction: string;\n\t\tguard?: (ctx: TransitionContext) => boolean | Promise<boolean>;\n\t}>;\n}\n\nexport type StateMachineDatabaseClient = unknown;\n\nexport interface TransitionContext<TDb = StateMachineDatabaseClient> {\n\tentity: Record<string, unknown>;\n\tactionInvocationId: string;\n\tactorId: string;\n\tparameters: unknown;\n\tdb: TDb;\n}\n\nexport interface StateMachineRegistry {\n\tregister(definition: StateMachineDefinition): void;\n\tregisterIfMissing(definition: StateMachineDefinition): void;\n\tresolve(entityType: string): StateMachineDefinition | undefined;\n\tvalidateTransition(entityType: string, from: string, to: string, actionId: string): { valid: boolean; error?: string };\n\tallowedTransitions(entityType: string, from: string): Array<{ to: string; causedByAction: string }>;\n\tstateClass(entityType: string, state: string): StateClass | undefined;\n}\n\nexport function validateStateMachineTransition(\n\tsm: StateMachineDefinition | undefined,\n\tentityType: string,\n\tfrom: string,\n\tto: string,\n\tactionId: string,\n): { valid: boolean; error?: string } {\n\tif (!sm) return { valid: false, error: `No state machine registered for entity type \"${entityType}\".` };\n\tconst fromDef = sm.states[from];\n\tif (!fromDef) return { valid: false, error: `State \"${from}\" does not exist in state machine for entity type \"${entityType}\".` };\n\tconst toDef = sm.states[to];\n\tif (!toDef) return { valid: false, error: `State \"${to}\" does not exist in state machine for entity type \"${entityType}\".` };\n\tconst transitionExists = sm.transitions.some((transition) => transition.from === from && transition.to === to && transition.causedByAction === actionId);\n\treturn transitionExists\n\t\t? { valid: true }\n\t\t: { valid: false, error: `Transition from \"${from}\" to \"${to}\" via action \"${actionId}\" is not defined for entity type \"${entityType}\".` };\n}\n\n/**\n * Validates a transition and evaluates its declared guard against trusted Host\n * context. Callers must construct `context.entity` from authoritative state,\n * never from action parameters.\n */\nexport async function evaluateStateMachineTransition<TDb = StateMachineDatabaseClient>(\n\tsm: StateMachineDefinition | undefined,\n\tentityType: string,\n\tfrom: string,\n\tto: string,\n\tactionId: string,\n\tcontext: TransitionContext<TDb>,\n): Promise<{ valid: boolean; error?: string }> {\n\tconst structural = validateStateMachineTransition(sm, entityType, from, to, actionId);\n\tif (!structural.valid) return structural;\n\tconst transition = sm!.transitions.find(\n\t\t(candidate) =>\n\t\t\tcandidate.from === from &&\n\t\t\tcandidate.to === to &&\n\t\t\tcandidate.causedByAction === actionId,\n\t);\n\tif (!transition?.guard) return structural;\n\ttry {\n\t\treturn await transition.guard(context)\n\t\t\t? structural\n\t\t\t: {\n\t\t\t\t\tvalid: false,\n\t\t\t\t\terror: `Guard rejected transition from \"${from}\" to \"${to}\" via action \"${actionId}\" for entity type \"${entityType}\".`,\n\t\t\t\t};\n\t} catch {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `Guard failed while evaluating transition from \"${from}\" to \"${to}\" via action \"${actionId}\" for entity type \"${entityType}\".`,\n\t\t};\n\t}\n}\n\nexport function createStateMachineRegistry(definitions: readonly StateMachineDefinition[] = []): StateMachineRegistry {\n\tconst machines = new Map<string, StateMachineDefinition>();\n\tconst register = (definition: StateMachineDefinition): void => {\n\t\tif (machines.has(definition.entityType)) throw new Error(`State machine for entity type \"${definition.entityType}\" is already registered.`);\n\t\tmachines.set(definition.entityType, definition);\n\t};\n\tconst validateTransition = (entityType: string, from: string, to: string, actionId: string) =>\n\t\tvalidateStateMachineTransition(machines.get(entityType), entityType, from, to, actionId);\n\tfor (const definition of definitions) register(definition);\n\treturn {\n\t\tregister,\n\t\tregisterIfMissing(definition) {\n\t\t\tif (!machines.has(definition.entityType)) register(definition);\n\t\t},\n\t\tresolve: (entityType) => machines.get(entityType),\n\t\tvalidateTransition,\n\t\tallowedTransitions(entityType, from) {\n\tconst sm = machines.get(entityType);\n\tif (!sm) {\n\t\treturn [];\n\t}\n\treturn sm.transitions\n\t\t.filter((t) => t.from === from)\n\t\t.map((t) => ({ to: t.to, causedByAction: t.causedByAction }));\n\t\t},\n\t\tstateClass(entityType, state) {\n\tconst sm = machines.get(entityType);\n\tif (!sm) {\n\t\treturn undefined;\n\t}\n\treturn sm.states[state]?.stateClass;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkG6WXP5ZZ_cjs = require('./chunk-G6WXP5ZZ.cjs');
|
|
4
4
|
|
|
5
5
|
// manifest/index.ts
|
|
6
6
|
var MODULE_MANIFEST_VERSION = 2;
|
|
@@ -32,7 +32,7 @@ function isRecord(value) {
|
|
|
32
32
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
33
33
|
}
|
|
34
34
|
function exportDependency(dependency) {
|
|
35
|
-
const namespace =
|
|
35
|
+
const namespace = chunkG6WXP5ZZ_cjs.getModuleDependencyNamespace(dependency);
|
|
36
36
|
if (typeof dependency === "string") {
|
|
37
37
|
return { namespace };
|
|
38
38
|
}
|
|
@@ -45,7 +45,7 @@ function exportObjectType(objectType) {
|
|
|
45
45
|
if (typeof objectType === "string") {
|
|
46
46
|
return { type: objectType };
|
|
47
47
|
}
|
|
48
|
-
const normalized = { type:
|
|
48
|
+
const normalized = { type: chunkG6WXP5ZZ_cjs.getObjectTypeName(objectType) };
|
|
49
49
|
if (objectType.displayName !== void 0) normalized.displayName = objectType.displayName;
|
|
50
50
|
if (objectType.idPrefix !== void 0) normalized.idPrefix = objectType.idPrefix;
|
|
51
51
|
if (objectType.schema !== void 0) normalized.schema = cloneJson(objectType.schema);
|
|
@@ -72,7 +72,7 @@ function exportEventType(eventType) {
|
|
|
72
72
|
return { eventType, schemaVersion: 1 };
|
|
73
73
|
}
|
|
74
74
|
const normalized = {
|
|
75
|
-
eventType:
|
|
75
|
+
eventType: chunkG6WXP5ZZ_cjs.getEventTypeName(eventType),
|
|
76
76
|
schemaVersion: eventType.schemaVersion
|
|
77
77
|
};
|
|
78
78
|
if (eventType.description !== void 0) normalized.description = eventType.description;
|
|
@@ -191,6 +191,7 @@ function exportView(view) {
|
|
|
191
191
|
scope: view.scope,
|
|
192
192
|
snapshotVersion: view.snapshotVersion
|
|
193
193
|
};
|
|
194
|
+
if (view.parameterSchema !== void 0) output.parameterSchema = cloneJson(view.parameterSchema);
|
|
194
195
|
if (view.compatibleSnapshotVersions) output.compatibleSnapshotVersions = [...view.compatibleSnapshotVersions];
|
|
195
196
|
if (view.usage) output.usage = cloneJson(view.usage);
|
|
196
197
|
return output;
|
|
@@ -231,5 +232,5 @@ exports.exportModuleManifestBundle = exportModuleManifestBundle;
|
|
|
231
232
|
exports.isJsonSchemaExportableValidator = isJsonSchemaExportableValidator;
|
|
232
233
|
exports.normalizeModuleManifest = normalizeModuleManifest;
|
|
233
234
|
exports.normalizeModuleManifestBundle = normalizeModuleManifestBundle;
|
|
234
|
-
//# sourceMappingURL=chunk-
|
|
235
|
-
//# sourceMappingURL=chunk-
|
|
235
|
+
//# sourceMappingURL=chunk-7HPNONN7.cjs.map
|
|
236
|
+
//# sourceMappingURL=chunk-7HPNONN7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../manifest/index.ts"],"names":["getModuleDependencyNamespace","getObjectTypeName","getEventTypeName"],"mappings":";;;;;AA8BO,IAAM,uBAAA,GAA0B;AAkKhC,SAAS,wBACf,QAAA,EACi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AAS,OAAA,CAAQ,GAAA,CAAI,oBAAoB;AAAA,GAC1C;AACD","file":"chunk-7HPNONN7.cjs","sourcesContent":["import type {\n\tActionExecutionContract,\n\tActionDefinition,\n\tAdapterStepRetryPolicy,\n\tSchemaValidator,\n} from \"../actions\";\nimport {\n\tgetEventTypeName,\n\tgetModuleDependencyNamespace,\n\tgetObjectTypeName,\n\ttype FabricModule,\n\ttype CapabilityMetadata,\n\ttype DeclarativeInvariant,\n\ttype ModuleDependency,\n\ttype ModuleDependencyInput,\n\ttype ObjectRelationDefinition,\n} from \"../modules\";\nimport type { JsonValue, PortableJsonSchema } from \"../objects\";\nimport type {\n\tDataPolicyDefinition,\n\tPolicyFallbackDefinition,\n\tPolicyKind,\n} from \"../policies\";\nimport type { StateDefinition, StateMachineDefinition } from \"../state-machines\";\nimport type { ViewContract } from \"../projections\";\n\n/**\n * Version of the module manifest contract. Bump when the serialized shape\n * changes in a way consumers must detect.\n */\nexport const MODULE_MANIFEST_VERSION = 2 as const;\n\nexport interface ModuleManifestObjectType {\n\ttype: string;\n\tdisplayName?: string;\n\tidPrefix?: string;\n\tschema?: PortableJsonSchema;\n\tsemantics?: Record<string, JsonValue>;\n\trelations?: ObjectRelationDefinition[];\n\tinvariants?: DeclarativeInvariant[];\n}\n\nexport interface ModuleManifestIdPrefix {\n\tprefix: string;\n\tname: string;\n}\n\nexport interface ModuleManifestEventType {\n\teventType: string;\n\tschemaVersion: number;\n\tdescription?: string;\n\tschema?: PortableJsonSchema;\n}\n\nexport interface ModuleManifestActionStateMachine {\n\tentityType: string;\n\t/** Present only when the binding declares a static target state. */\n\ttargetState?: string;\n}\n\nexport interface ModuleManifestAdapterStep {\n\tadapterType: string;\n\toperation: string;\n\tretryPolicy?: AdapterStepRetryPolicy;\n}\n\nexport interface ModuleManifestAction {\n\tactionId: string;\n\tversion: number;\n\tkind: \"atomic\" | \"saga\";\n\tidempotent: boolean;\n\tmutatesDomain: boolean;\n\temitsEvents: string[];\n\tpolicies?: string[];\n\trequiredRoles?: string[];\n\trequiredPermissions?: string[];\n\teventPhase?: \"before_adapters\" | \"after_adapters\";\n\texecution?: ActionExecutionContract;\n\t/**\n\t * JSON Schema for the action parameters, present only when the action's\n\t * `schema` validator implements {@link JsonSchemaExportableValidator}.\n\t */\n\tparameterSchema?: unknown;\n\tparameterSchemaFormat?: \"json-schema\";\n\tresultSchema?: unknown;\n\tresultSchemaFormat?: \"json-schema\";\n\tstateMachine?: ModuleManifestActionStateMachine;\n\tadapterSteps?: ModuleManifestAdapterStep[];\n}\n\nexport interface ModuleManifestCodePolicy {\n\ttype: \"code\";\n\tpolicyId: string;\n\tversion: number;\n\tpreviewSafe?: boolean;\n}\n\nexport interface ModuleManifestDataPolicy {\n\ttype: \"data\";\n\tpolicyId: string;\n\tpolicyVersion: number;\n\tkind: PolicyKind;\n\tdataDefinition?: DataPolicyDefinition;\n\tcodeEvaluatorPolicyId?: string;\n\tfallback?: PolicyFallbackDefinition;\n}\n\nexport type ModuleManifestPolicy = ModuleManifestCodePolicy | ModuleManifestDataPolicy;\n\nexport interface ModuleManifestStateMachineTransition {\n\tfrom: string;\n\tto: string;\n\tcausedByAction: string;\n\t/** `true` when the transition declares a guard function. The guard itself is never serialized. */\n\thasGuard: boolean;\n}\n\nexport interface ModuleManifestStateMachine {\n\tentityType: string;\n\t/** States in declaration order (`Object.values` order of the definition record). */\n\tstates: StateDefinition[];\n\ttransitions: ModuleManifestStateMachineTransition[];\n}\n\nexport interface ModuleManifestView {\n\tname: string;\n\tversion: string;\n\tshape: PortableJsonSchema;\n\tparameterSchema?: PortableJsonSchema;\n\tconsumes: Array<{ eventType: string; schemaVersions: number[] }>;\n\tscope: \"tenant-space\";\n\tsnapshotVersion: number;\n\tcompatibleSnapshotVersions?: number[];\n\tusage?: ViewContract[\"usage\"];\n}\n\n/**\n * Stable, JSON-serializable description of a {@link FabricModule}'s ontology:\n * object types, subject types, id prefixes, event types, actions, policies,\n * and state machines. Intended for downstream tooling (semantics exporters,\n * docs generators, tool generators) that cannot consume live module code.\n *\n * The manifest contains definitions only — never raw parameter values,\n * secrets, or runtime data. Function fields (`handler`, `evaluate`, `guard`,\n * dynamic `targetState`, adapter `getInput`) are never serialized.\n */\nexport interface ModuleManifest {\n\tmanifestVersion: typeof MODULE_MANIFEST_VERSION;\n\tnamespace: string;\n\tversion?: string;\n\tdisplayName?: string;\n\tdescription?: string;\n\tcapability?: CapabilityMetadata;\n\tdependencies: ModuleDependency[];\n\tobjectTypes: ModuleManifestObjectType[];\n\tsubjectTypes: string[];\n\tidPrefixes: ModuleManifestIdPrefix[];\n\teventTypes: ModuleManifestEventType[];\n\tactions: ModuleManifestAction[];\n\tpolicies: ModuleManifestPolicy[];\n\tstateMachines: ModuleManifestStateMachine[];\n\tviews: ModuleManifestView[];\n}\n\nexport interface ModuleManifestBundle {\n\tmanifestVersion: typeof MODULE_MANIFEST_VERSION;\n\t/** Manifests in the input module order. */\n\tmodules: ModuleManifest[];\n}\n\n/** Manifest v1 remains accepted by v2 readers; missing v2 fields normalize to absence. */\nexport type ModuleManifestObjectTypeV1 = Omit<\n\tModuleManifestObjectType,\n\t\"schema\" | \"semantics\" | \"relations\" | \"invariants\"\n>;\nexport type ModuleManifestActionV1 = Omit<\n\tModuleManifestAction,\n\t\"resultSchema\" | \"resultSchemaFormat\"\n>;\nexport type ModuleManifestV1 = Omit<\n\tModuleManifest,\n\t\"manifestVersion\" | \"objectTypes\" | \"actions\" | \"views\"\n> & {\n\tmanifestVersion: 1;\n\tobjectTypes: ModuleManifestObjectTypeV1[];\n\tactions: ModuleManifestActionV1[];\n};\nexport type ModuleManifestBundleV1 = Omit<ModuleManifestBundle, \"manifestVersion\" | \"modules\"> & {\n\tmanifestVersion: 1;\n\tmodules: ModuleManifestV1[];\n};\n\nexport function normalizeModuleManifest(\n\tmanifest: ModuleManifest | ModuleManifestV1,\n): ModuleManifest {\n\tconst version: number = manifest.manifestVersion;\n\tif (version !== 1 && version !== MODULE_MANIFEST_VERSION) {\n\t\tthrow new Error(`Unsupported module manifest version: ${String(version)}`);\n\t}\n\treturn {\n\t\t...manifest,\n\t\tmanifestVersion: MODULE_MANIFEST_VERSION,\n\t\tviews: \"views\" in manifest && Array.isArray(manifest.views) ? manifest.views : [],\n\t};\n}\n\nexport function normalizeModuleManifestBundle(\n\tbundle: ModuleManifestBundle | ModuleManifestBundleV1,\n): ModuleManifestBundle {\n\tconst version: number = bundle.manifestVersion;\n\tif (version !== 1 && version !== MODULE_MANIFEST_VERSION) {\n\t\tthrow new Error(`Unsupported module manifest bundle version: ${String(version)}`);\n\t}\n\treturn {\n\t\tmanifestVersion: MODULE_MANIFEST_VERSION,\n\t\tmodules: bundle.modules.map((manifest) => normalizeModuleManifest(manifest)),\n\t};\n}\n\n/**\n * A {@link SchemaValidator} that can also export its parameter schema as JSON\n * Schema (for example a Zod 4 schema via `z.toJSONSchema`). Keeps the platform\n * zero-dependency while letting schema-bearing actions flow into manifests.\n */\nexport interface JsonSchemaExportableValidator extends SchemaValidator {\n\ttoJSONSchema(): Record<string, unknown>;\n}\n\nexport function isJsonSchemaExportableValidator(\n\tschema: SchemaValidator,\n): schema is JsonSchemaExportableValidator {\n\treturn (\n\t\ttypeof (schema as Partial<JsonSchemaExportableValidator>).toJSONSchema === \"function\"\n\t);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction exportDependency(dependency: ModuleDependencyInput): ModuleDependency {\n\tconst namespace = getModuleDependencyNamespace(dependency);\n\tif (typeof dependency === \"string\") {\n\t\treturn { namespace };\n\t}\n\tconst normalized: ModuleDependency = { namespace };\n\tif (dependency.version !== undefined) normalized.version = dependency.version;\n\tif (dependency.optional !== undefined) normalized.optional = dependency.optional;\n\treturn normalized;\n}\n\nfunction exportObjectType(\n\tobjectType: NonNullable<FabricModule[\"objectTypes\"]>[number],\n): ModuleManifestObjectType {\n\tif (typeof objectType === \"string\") {\n\t\treturn { type: objectType };\n\t}\n\tconst normalized: ModuleManifestObjectType = { type: getObjectTypeName(objectType) };\n\tif (objectType.displayName !== undefined) normalized.displayName = objectType.displayName;\n\tif (objectType.idPrefix !== undefined) normalized.idPrefix = objectType.idPrefix;\n\tif (objectType.schema !== undefined) normalized.schema = cloneJson(objectType.schema);\n\tif (objectType.semantics !== undefined) normalized.semantics = cloneJson(objectType.semantics);\n\tif (objectType.relations !== undefined) {\n\t\tnormalized.relations = objectType.relations.map((relation) => ({ ...relation }));\n\t}\n\tif (objectType.invariants !== undefined) {\n\t\tnormalized.invariants = objectType.invariants.map((invariant) => ({ ...invariant }));\n\t}\n\treturn normalized;\n}\n\nfunction cloneJson<T>(value: T): T {\n\tif (Array.isArray(value)) return value.map((item) => cloneJson(item)) as T;\n\tif (value !== null && typeof value === \"object\") {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(value as Record<string, unknown>).map(([key, child]) => [key, cloneJson(child)]),\n\t\t) as T;\n\t}\n\treturn value;\n}\n\nfunction exportEventType(\n\teventType: NonNullable<FabricModule[\"eventTypes\"]>[number],\n): ModuleManifestEventType {\n\tif (typeof eventType === \"string\") {\n\t\t// String registrations carry no explicit schema version; the events\n\t\t// registry treats the bare name as the initial version of the type.\n\t\treturn { eventType, schemaVersion: 1 };\n\t}\n\tconst normalized: ModuleManifestEventType = {\n\t\teventType: getEventTypeName(eventType),\n\t\tschemaVersion: eventType.schemaVersion,\n\t};\n\tif (eventType.description !== undefined) normalized.description = eventType.description;\n\tif (eventType.schema !== undefined) normalized.schema = cloneJson(eventType.schema);\n\treturn normalized;\n}\n\nfunction exportAction(action: ActionDefinition): ModuleManifestAction {\n\tconst manifest: ModuleManifestAction = {\n\t\tactionId: action.actionId,\n\t\tversion: action.version,\n\t\tkind: action.kind ?? \"atomic\",\n\t\tidempotent: action.idempotent,\n\t\tmutatesDomain: action.mutatesDomain,\n\t\temitsEvents: [...action.emitsEvents],\n\t};\n\n\tif (action.policies !== undefined) manifest.policies = [...action.policies];\n\tif (action.requiredRoles !== undefined) manifest.requiredRoles = [...action.requiredRoles];\n\tif (action.requiredPermissions !== undefined) {\n\t\tmanifest.requiredPermissions = [...action.requiredPermissions];\n\t}\n\tif (action.eventPhase !== undefined) manifest.eventPhase = action.eventPhase;\n\tif (action.execution !== undefined) manifest.execution = cloneJson(action.execution);\n\n\tif (isJsonSchemaExportableValidator(action.schema)) {\n\t\ttry {\n\t\t\tmanifest.parameterSchema = action.schema.toJSONSchema();\n\t\t\tmanifest.parameterSchemaFormat = \"json-schema\";\n\t\t} catch {\n\t\t\t// Runtime-valid schemas that cannot be represented portably remain executable;\n\t\t\t// build-time consumers see the schema as unavailable rather than crashing export.\n\t\t}\n\t}\n\tif (action.resultSchema && isJsonSchemaExportableValidator(action.resultSchema)) {\n\t\ttry {\n\t\t\tmanifest.resultSchema = action.resultSchema.toJSONSchema();\n\t\t\tmanifest.resultSchemaFormat = \"json-schema\";\n\t\t} catch {\n\t\t\t// See parameter-schema behavior above.\n\t\t}\n\t}\n\n\tif (action.stateMachine !== undefined) {\n\t\tconst binding: ModuleManifestActionStateMachine = {\n\t\t\tentityType: action.stateMachine.entityType,\n\t\t};\n\t\tif (typeof action.stateMachine.targetState === \"string\") {\n\t\t\tbinding.targetState = action.stateMachine.targetState;\n\t\t}\n\t\tmanifest.stateMachine = binding;\n\t}\n\n\tif (action.adapterSteps !== undefined) {\n\t\tmanifest.adapterSteps = action.adapterSteps.map((step) => {\n\t\t\tconst exported: ModuleManifestAdapterStep = {\n\t\t\t\tadapterType: step.adapterType,\n\t\t\t\toperation: step.operation,\n\t\t\t};\n\t\t\tif (step.retryPolicy !== undefined) exported.retryPolicy = { ...step.retryPolicy };\n\t\t\treturn exported;\n\t\t});\n\t}\n\n\treturn manifest;\n}\n\nfunction exportPolicy(policy: unknown): ModuleManifestPolicy | undefined {\n\tif (!isRecord(policy) || typeof policy.policyId !== \"string\") {\n\t\treturn undefined;\n\t}\n\n\t// Code evaluator: identified by its `evaluate` function (never serialized).\n\tif (typeof policy.evaluate === \"function\") {\n\t\tconst exported: ModuleManifestCodePolicy = {\n\t\t\ttype: \"code\",\n\t\t\tpolicyId: policy.policyId,\n\t\t\tversion: typeof policy.version === \"number\" ? policy.version : 1,\n\t\t};\n\t\tif (typeof policy.previewSafe === \"boolean\") exported.previewSafe = policy.previewSafe;\n\t\treturn exported;\n\t}\n\n\t// Declarative runtime policy definition: pure data, serialized as-is.\n\tif (typeof policy.kind === \"string\" && typeof policy.policyVersion === \"number\") {\n\t\tconst exported: ModuleManifestDataPolicy = {\n\t\t\ttype: \"data\",\n\t\t\tpolicyId: policy.policyId,\n\t\t\tpolicyVersion: policy.policyVersion,\n\t\t\tkind: policy.kind as PolicyKind,\n\t\t};\n\t\tif (isRecord(policy.dataDefinition)) {\n\t\t\texported.dataDefinition = policy.dataDefinition as unknown as DataPolicyDefinition;\n\t\t}\n\t\tif (typeof policy.codeEvaluatorPolicyId === \"string\") {\n\t\t\texported.codeEvaluatorPolicyId = policy.codeEvaluatorPolicyId;\n\t\t}\n\t\tif (isRecord(policy.fallback)) {\n\t\t\texported.fallback = policy.fallback as unknown as PolicyFallbackDefinition;\n\t\t}\n\t\treturn exported;\n\t}\n\n\t// Unknown policy shape: omit rather than guess.\n\treturn undefined;\n}\n\nfunction exportStateMachine(machine: unknown): ModuleManifestStateMachine | undefined {\n\tif (\n\t\t!isRecord(machine) ||\n\t\ttypeof machine.entityType !== \"string\" ||\n\t\t!isRecord(machine.states) ||\n\t\t!Array.isArray(machine.transitions)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst definition = machine as unknown as StateMachineDefinition;\n\treturn {\n\t\tentityType: definition.entityType,\n\t\tstates: Object.values(definition.states),\n\t\ttransitions: definition.transitions.map((transition) => ({\n\t\t\tfrom: transition.from,\n\t\t\tto: transition.to,\n\t\t\tcausedByAction: transition.causedByAction,\n\t\t\thasGuard: typeof transition.guard === \"function\",\n\t\t})),\n\t};\n}\n\nfunction exportView(view: ViewContract): ModuleManifestView {\n\tconst output: ModuleManifestView = {\n\t\tname: view.name,\n\t\tversion: view.version,\n\t\tshape: cloneJson(view.shape),\n\t\tconsumes: view.consumes.map((consumption) => ({\n\t\t\teventType: consumption.eventType,\n\t\t\tschemaVersions: [...consumption.schemaVersions],\n\t\t})),\n\t\tscope: view.scope,\n\t\tsnapshotVersion: view.snapshotVersion,\n\t};\n\tif (view.parameterSchema !== undefined) output.parameterSchema = cloneJson(view.parameterSchema);\n\tif (view.compatibleSnapshotVersions) output.compatibleSnapshotVersions = [...view.compatibleSnapshotVersions];\n\tif (view.usage) output.usage = cloneJson(view.usage);\n\treturn output;\n}\n\n/**\n * Export a stable, JSON-serializable manifest of a module's ontology.\n *\n * This is a pure function of the module object: it does not read or mutate the\n * global module/action/policy/state-machine registries, and the module does\n * not need to be registered first. Declaration order is preserved everywhere\n * (nothing is sorted), so the same module object always produces a\n * byte-identical `JSON.stringify` result.\n *\n * The manifest contains definitions only — never raw parameter values,\n * secrets, or runtime data. Function fields are elided (`handler`,\n * policy `evaluate`, transition `guard` → `hasGuard`, dynamic `targetState`,\n * adapter `getInput`).\n */\nexport function exportModuleManifest(module: FabricModule<unknown>): ModuleManifest {\n\tconst manifest: ModuleManifest = {\n\t\tmanifestVersion: MODULE_MANIFEST_VERSION,\n\t\tnamespace: module.namespace,\n\t\tdependencies: (module.dependencies ?? []).map(exportDependency),\n\t\tobjectTypes: (module.objectTypes ?? []).map(exportObjectType),\n\t\tsubjectTypes: [...(module.subjectTypes ?? [])],\n\t\tidPrefixes: (module.idPrefixes ?? []).map((registration) => ({\n\t\t\tprefix: registration.prefix,\n\t\t\tname: registration.name,\n\t\t})),\n\t\teventTypes: (module.eventTypes ?? []).map(exportEventType),\n\t\tactions: (module.actions ?? []).map(exportAction),\n\t\tpolicies: (module.policies ?? [])\n\t\t\t.map(exportPolicy)\n\t\t\t.filter((policy): policy is ModuleManifestPolicy => policy !== undefined),\n\t\tstateMachines: (module.stateMachines ?? [])\n\t\t\t.map(exportStateMachine)\n\t\t\t.filter((machine): machine is ModuleManifestStateMachine => machine !== undefined),\n\t\tviews: (module.views ?? []).map(exportView),\n\t};\n\n\tif (module.version !== undefined) manifest.version = module.version;\n\tif (module.displayName !== undefined) manifest.displayName = module.displayName;\n\tif (module.description !== undefined) manifest.description = module.description;\n\tif (module.capability !== undefined) manifest.capability = cloneJson(module.capability);\n\n\treturn manifest;\n}\n\n/**\n * Export manifests for a set of modules, preserving the input order.\n * Like {@link exportModuleManifest}, this is pure and registry-free.\n */\nexport function exportModuleManifestBundle(\n\tmodules: FabricModule<unknown>[],\n): ModuleManifestBundle {\n\treturn {\n\t\tmanifestVersion: MODULE_MANIFEST_VERSION,\n\t\tmodules: modules.map(exportModuleManifest),\n\t};\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdapterRegistry } from './chunk-
|
|
1
|
+
import { AdapterRegistry } from './chunk-DTY3CHQZ.js';
|
|
2
2
|
|
|
3
3
|
// testing/index.ts
|
|
4
4
|
function createFakeActionContext(options = {}) {
|
|
@@ -23,5 +23,5 @@ function createDeterministicIdFactory(prefix = "test") {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export { createDeterministicIdFactory, createFakeActionContext, createInMemoryAdapterRegistry };
|
|
26
|
-
//# sourceMappingURL=chunk-
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
26
|
+
//# sourceMappingURL=chunk-AWP6JDD5.js.map
|
|
27
|
+
//# sourceMappingURL=chunk-AWP6JDD5.js.map
|