@aftertext/player 0.1.1 → 0.4.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/README.md +38 -1
- package/dist/document-fingerprint.d.ts +12 -0
- package/dist/document-fingerprint.d.ts.map +1 -0
- package/dist/document-fingerprint.js +188 -0
- package/dist/document-fingerprint.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/restore-player.d.ts +28 -0
- package/dist/restore-player.d.ts.map +1 -0
- package/dist/restore-player.js +224 -0
- package/dist/restore-player.js.map +1 -0
- package/dist/snapshot-current.d.ts +51 -0
- package/dist/snapshot-current.d.ts.map +1 -0
- package/dist/snapshot-current.js +115 -0
- package/dist/snapshot-current.js.map +1 -0
- package/dist/snapshot-player.d.ts +17 -0
- package/dist/snapshot-player.d.ts.map +1 -0
- package/dist/snapshot-player.js +32 -0
- package/dist/snapshot-player.js.map +1 -0
- package/dist/snapshot-runtime-state.d.ts +35 -0
- package/dist/snapshot-runtime-state.d.ts.map +1 -0
- package/dist/snapshot-runtime-state.js +168 -0
- package/dist/snapshot-runtime-state.js.map +1 -0
- package/dist/snapshot-types.d.ts +86 -0
- package/dist/snapshot-types.d.ts.map +1 -0
- package/dist/snapshot-types.js +128 -0
- package/dist/snapshot-types.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { boundedArrayLength, isPlainRecord } from "./snapshot-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Exhaustive, compile-time-checked lookup of every current
|
|
4
|
+
* `RuntimeExecutionErrorKind` (docs/CORE_SPEC.md Section 33.8): the
|
|
5
|
+
* `satisfies` constraint means a future kind added to the union without a
|
|
6
|
+
* matching entry here fails to compile, rather than silently being
|
|
7
|
+
* accepted or rejected as a decode runtime surprise.
|
|
8
|
+
*/
|
|
9
|
+
const RUNTIME_EXECUTION_ERROR_KINDS = {
|
|
10
|
+
"unknown-identifier": true,
|
|
11
|
+
"type-mismatch": true,
|
|
12
|
+
"division-by-zero": true,
|
|
13
|
+
"invalid-arithmetic-result": true,
|
|
14
|
+
"empty-choice": true,
|
|
15
|
+
"invalid-choice-selection": true,
|
|
16
|
+
"invalid-scene-target": true,
|
|
17
|
+
"step-limit-exceeded": true,
|
|
18
|
+
"unknown-builtin": true,
|
|
19
|
+
"invalid-variant-reference": true,
|
|
20
|
+
"invalid-execution-block": true
|
|
21
|
+
};
|
|
22
|
+
function isRuntimeExecutionErrorKind(value) {
|
|
23
|
+
return Object.hasOwn(RUNTIME_EXECUTION_ERROR_KINDS, value);
|
|
24
|
+
}
|
|
25
|
+
/** Compile-time exhaustiveness guard — see `document-fingerprint.ts`'s identical `unhandledVariant` for the rationale. */
|
|
26
|
+
function unhandledResultType(value) {
|
|
27
|
+
throw new Error(`snapshot-current: unhandled ExecutionResult variant: ${JSON.stringify(value)}`);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Encodes `current` as an opaque `JsonValue` (docs/CORE_SPEC.md Section
|
|
31
|
+
* 33.7). `current === null` means `PlayerState` was created but has never
|
|
32
|
+
* advanced — encoded as `"notStarted"`, the same uniform sentinel every
|
|
33
|
+
* other no-structural-position kind uses (Section 33.4's uniform-capture
|
|
34
|
+
* principle, extended here to the current descriptor itself).
|
|
35
|
+
*/
|
|
36
|
+
export function encodeCurrent(current) {
|
|
37
|
+
if (current === null)
|
|
38
|
+
return { type: "notStarted" };
|
|
39
|
+
if (current.type === "content")
|
|
40
|
+
return { type: "content" };
|
|
41
|
+
if (current.type === "dialogue")
|
|
42
|
+
return { type: "dialogue" };
|
|
43
|
+
if (current.type === "presentation")
|
|
44
|
+
return { type: "presentation" };
|
|
45
|
+
if (current.type === "choice") {
|
|
46
|
+
return { type: "choice", items: current.items.map((item) => ({ text: item.text, target: item.target })) };
|
|
47
|
+
}
|
|
48
|
+
if (current.type === "navigation")
|
|
49
|
+
return { type: "navigation", from: current.from, to: current.to };
|
|
50
|
+
if (current.type === "completed")
|
|
51
|
+
return { type: "completed" };
|
|
52
|
+
if (current.type === "error")
|
|
53
|
+
return { type: "error", kind: current.error.kind, message: current.error.message };
|
|
54
|
+
return unhandledResultType(current);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reads `value` by index up to its own freshly-captured, re-bounded
|
|
58
|
+
* `.length` rather than with `for...of`: a `for...of` loop consults
|
|
59
|
+
* `Symbol.iterator`, so a caller-supplied array Proxy with a short
|
|
60
|
+
* `.length` but a custom iterator that yields indefinitely would
|
|
61
|
+
* otherwise loop forever here — indexed access never invokes it. The
|
|
62
|
+
* length is re-bounded via `boundedArrayLength` here too, independent
|
|
63
|
+
* of whatever `isJsonValue`'s own earlier pass over this same value
|
|
64
|
+
* saw: a live Proxy can answer a `.length` read differently each time
|
|
65
|
+
* it is asked, so this function's own read must stand on its own
|
|
66
|
+
* rather than trust an earlier pass's result for the same property.
|
|
67
|
+
*/
|
|
68
|
+
function decodeChoiceItems(value) {
|
|
69
|
+
if (!Array.isArray(value))
|
|
70
|
+
return undefined;
|
|
71
|
+
const length = boundedArrayLength(value);
|
|
72
|
+
if (length === undefined)
|
|
73
|
+
return undefined;
|
|
74
|
+
const items = [];
|
|
75
|
+
for (let i = 0; i < length; i++) {
|
|
76
|
+
const raw = value[i];
|
|
77
|
+
if (!isPlainRecord(raw))
|
|
78
|
+
return undefined;
|
|
79
|
+
const { text, target } = raw;
|
|
80
|
+
if (typeof text !== "string" || typeof target !== "string")
|
|
81
|
+
return undefined;
|
|
82
|
+
items.push({ text, target });
|
|
83
|
+
}
|
|
84
|
+
return items;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Validates and decodes an opaque `current` value (docs/CORE_SPEC.md
|
|
88
|
+
* Section 33.8) — `value` is untrusted JSON-compatible data, not trusted
|
|
89
|
+
* internal state. Returns `undefined` for any malformed shape; never
|
|
90
|
+
* throws.
|
|
91
|
+
*/
|
|
92
|
+
export function decodeCurrent(value) {
|
|
93
|
+
if (!isPlainRecord(value))
|
|
94
|
+
return undefined;
|
|
95
|
+
const type = value.type;
|
|
96
|
+
if (type === "notStarted" || type === "content" || type === "dialogue" || type === "presentation" || type === "completed") {
|
|
97
|
+
return { type };
|
|
98
|
+
}
|
|
99
|
+
if (type === "navigation") {
|
|
100
|
+
const { from, to } = value;
|
|
101
|
+
return typeof from === "string" && typeof to === "string" ? { type: "navigation", from, to } : undefined;
|
|
102
|
+
}
|
|
103
|
+
if (type === "choice") {
|
|
104
|
+
const items = decodeChoiceItems(value.items);
|
|
105
|
+
return items ? { type: "choice", items } : undefined;
|
|
106
|
+
}
|
|
107
|
+
if (type === "error") {
|
|
108
|
+
const { kind, message } = value;
|
|
109
|
+
return typeof kind === "string" && isRuntimeExecutionErrorKind(kind) && typeof message === "string"
|
|
110
|
+
? { type: "error", kind, message }
|
|
111
|
+
: undefined;
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=snapshot-current.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-current.js","sourceRoot":"","sources":["../src/snapshot-current.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAoBxE;;;;;;GAMG;AACH,MAAM,6BAA6B,GAAG;IACpC,oBAAoB,EAAE,IAAI;IAC1B,eAAe,EAAE,IAAI;IACrB,kBAAkB,EAAE,IAAI;IACxB,2BAA2B,EAAE,IAAI;IACjC,cAAc,EAAE,IAAI;IACpB,0BAA0B,EAAE,IAAI;IAChC,sBAAsB,EAAE,IAAI;IAC5B,qBAAqB,EAAE,IAAI;IAC3B,iBAAiB,EAAE,IAAI;IACvB,2BAA2B,EAAE,IAAI;IACjC,yBAAyB,EAAE,IAAI;CACkB,CAAC;AAEpD,SAAS,2BAA2B,CAAC,KAAa;IAChD,O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,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QAC1H,OAAO,EAAE,IAAI,EAAE,CAAC;IAClB,CAAC;IACD,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QAC1B,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;QAC3B,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3G,CAAC;IACD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC7C,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,CAAC;IACD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;QAChC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,2BAA2B,CAAC,IAAI,CAAC,IAAI,OAAO,OAAO,KAAK,QAAQ;YACjG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;YAClC,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { StoryDocument } from "@aftertext/compiler";
|
|
2
|
+
import type { PlayerState } from "./player-state.js";
|
|
3
|
+
import type { PlayerSnapshot } from "./snapshot-types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Takes a snapshot of `player` (docs/CORE_SPEC.md Section 33.6). Pure, no
|
|
6
|
+
* mutation. `runtimeState` may share object identity with the live
|
|
7
|
+
* `PlayerState` it was taken from — this is intentional and consistent
|
|
8
|
+
* with this codebase's existing immutable-by-convention policy (Section
|
|
9
|
+
* 33.6); nothing here deep-clones it.
|
|
10
|
+
*
|
|
11
|
+
* `position` is derived via Runtime's own `toCursorPosition` for every
|
|
12
|
+
* kind that has a structural position (content/dialogue/presentation/
|
|
13
|
+
* choice/error); `notStarted`/`navigation`/`completed` have none and use
|
|
14
|
+
* the shared opaque `NO_POSITION` sentinel instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare function snapshotPlayer(document: StoryDocument, player: PlayerState): PlayerSnapshot;
|
|
17
|
+
//# sourceMappingURL=snapshot-player.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-player.d.ts","sourceRoot":"","sources":["../src/snapshot-player.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAa,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOrE;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,GAAG,cAAc,CAc3F"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { toCursorPosition } from "@aftertext/runtime";
|
|
2
|
+
import { computeDocumentFingerprint } from "./document-fingerprint.js";
|
|
3
|
+
import { encodeCurrent } from "./snapshot-current.js";
|
|
4
|
+
const FORMAT_VERSION = 1;
|
|
5
|
+
/** The shared opaque sentinel for a current kind with no structural position (docs/CORE_SPEC.md Section 33.7). */
|
|
6
|
+
const NO_POSITION = { kind: "none" };
|
|
7
|
+
/**
|
|
8
|
+
* Takes a snapshot of `player` (docs/CORE_SPEC.md Section 33.6). Pure, no
|
|
9
|
+
* mutation. `runtimeState` may share object identity with the live
|
|
10
|
+
* `PlayerState` it was taken from — this is intentional and consistent
|
|
11
|
+
* with this codebase's existing immutable-by-convention policy (Section
|
|
12
|
+
* 33.6); nothing here deep-clones it.
|
|
13
|
+
*
|
|
14
|
+
* `position` is derived via Runtime's own `toCursorPosition` for every
|
|
15
|
+
* kind that has a structural position (content/dialogue/presentation/
|
|
16
|
+
* choice/error); `notStarted`/`navigation`/`completed` have none and use
|
|
17
|
+
* the shared opaque `NO_POSITION` sentinel instead.
|
|
18
|
+
*/
|
|
19
|
+
export function snapshotPlayer(document, player) {
|
|
20
|
+
const resultType = player.current?.type;
|
|
21
|
+
const position = resultType === undefined || resultType === "navigation" || resultType === "completed"
|
|
22
|
+
? NO_POSITION
|
|
23
|
+
: toCursorPosition(player.runtimeState, player.cursor);
|
|
24
|
+
return {
|
|
25
|
+
formatVersion: FORMAT_VERSION,
|
|
26
|
+
documentFingerprint: computeDocumentFingerprint(document),
|
|
27
|
+
runtimeState: player.runtimeState,
|
|
28
|
+
position,
|
|
29
|
+
current: encodeCurrent(player.current)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=snapshot-player.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-player.js","sourceRoot":"","sources":["../src/snapshot-player.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAItD,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,kHAAkH;AAClH,MAAM,WAAW,GAAc,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,QAAuB,EAAE,MAAmB;IACzE,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC;IACxC,MAAM,QAAQ,GACZ,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,YAAY,IAAI,UAAU,KAAK,WAAW;QACnF,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAE3D,OAAO;QACL,aAAa,EAAE,cAAc;QAC7B,mBAAmB,EAAE,0BAA0B,CAAC,QAAQ,CAAC;QACzD,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,QAAQ;QACR,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC;KACvC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { StoryDocument } from "@aftertext/compiler";
|
|
2
|
+
import type { RuntimeState } from "@aftertext/runtime";
|
|
3
|
+
/**
|
|
4
|
+
* A one-call-scoped ephemeral index of `document`'s real scene ids and
|
|
5
|
+
* every Variant's real branch ids (docs/CORE_SPEC.md Section 33.8).
|
|
6
|
+
* Built once per `restorePlayer` call, discarded when it returns — this
|
|
7
|
+
* is ordinary local-variable work, not a forbidden module-level mutable
|
|
8
|
+
* cache, identical in kind to any other local built fresh inside one
|
|
9
|
+
* function call.
|
|
10
|
+
*/
|
|
11
|
+
export interface DocumentIndex {
|
|
12
|
+
readonly sceneIds: ReadonlySet<string>;
|
|
13
|
+
readonly variantBranches: ReadonlyMap<string, ReadonlySet<string>>;
|
|
14
|
+
}
|
|
15
|
+
export declare function buildDocumentIndex(document: StoryDocument): DocumentIndex;
|
|
16
|
+
type Validated<T> = {
|
|
17
|
+
readonly ok: true;
|
|
18
|
+
readonly value: T;
|
|
19
|
+
} | {
|
|
20
|
+
readonly ok: false;
|
|
21
|
+
readonly reason: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function validateRuntimeState(index: DocumentIndex, value: unknown): Validated<RuntimeState>;
|
|
24
|
+
/**
|
|
25
|
+
* Whether `runtimeState` equals exactly what `createPlayer(document)`
|
|
26
|
+
* would itself produce (docs/CORE_SPEC.md Section 33.8) — required for a
|
|
27
|
+
* `"not started"` snapshot. Uses ordinary `===` (not `Object.is`) so
|
|
28
|
+
* `-0`/`0` compare equal, matching every other numeric comparison in this
|
|
29
|
+
* codebase's expression semantics (Section 17.8).
|
|
30
|
+
*/
|
|
31
|
+
export declare function isFreshRuntimeState(document: StoryDocument, runtimeState: RuntimeState): boolean;
|
|
32
|
+
/** A genuine `completed` result always has a `visitedScenes` entry for the current scene (docs/CORE_SPEC.md Section 33.8). */
|
|
33
|
+
export declare function hasVisitedCurrentScene(runtimeState: RuntimeState): boolean;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=snapshot-runtime-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-runtime-state.d.ts","sourceRoot":"","sources":["../src/snapshot-runtime-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,KAAK,EAAgC,YAAY,EAA2D,MAAM,oBAAoB,CAAC;AAG9I;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CACpE;AAaD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,CAIzE;AAMD,KAAK,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAiG/G,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,CASlG;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAKhG;AASD,8HAA8H;AAC9H,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAE1E"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { isPlainRecord } from "./snapshot-types.js";
|
|
2
|
+
function collectVariantBranches(blocks, into) {
|
|
3
|
+
for (const block of blocks) {
|
|
4
|
+
if (block.type === "Variant") {
|
|
5
|
+
into.set(block.id, new Set(block.branches.map((branch) => branch.branchId)));
|
|
6
|
+
for (const branch of block.branches)
|
|
7
|
+
collectVariantBranches(branch.blocks, into);
|
|
8
|
+
}
|
|
9
|
+
else if (block.type === "Conditional") {
|
|
10
|
+
for (const branch of block.branches)
|
|
11
|
+
collectVariantBranches(branch.blocks, into);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function buildDocumentIndex(document) {
|
|
16
|
+
const variantBranches = new Map();
|
|
17
|
+
for (const scene of document.scenes)
|
|
18
|
+
collectVariantBranches(scene.blocks, variantBranches);
|
|
19
|
+
return { sceneIds: new Set(document.scenes.map((scene) => scene.id)), variantBranches };
|
|
20
|
+
}
|
|
21
|
+
function isPositiveFiniteInteger(value) {
|
|
22
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
23
|
+
}
|
|
24
|
+
function ok(value) {
|
|
25
|
+
return { ok: true, value };
|
|
26
|
+
}
|
|
27
|
+
function fail(reason) {
|
|
28
|
+
return { ok: false, reason };
|
|
29
|
+
}
|
|
30
|
+
/** Every value must be exactly `string | boolean | null | <finite number>` (docs/CORE_SPEC.md Section 33.6, 33.8) — `-0` is finite and passes. */
|
|
31
|
+
function isFiniteStoryValue(value) {
|
|
32
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
33
|
+
return true;
|
|
34
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
35
|
+
}
|
|
36
|
+
function validateStoryState(value) {
|
|
37
|
+
if (!isPlainRecord(value))
|
|
38
|
+
return fail("story is not a plain object.");
|
|
39
|
+
const entries = [];
|
|
40
|
+
for (const key of Object.keys(value)) {
|
|
41
|
+
const entry = value[key];
|
|
42
|
+
if (!isFiniteStoryValue(entry))
|
|
43
|
+
return fail(`story.${key} is not a string/boolean/null/finite number.`);
|
|
44
|
+
entries.push([key, entry]);
|
|
45
|
+
}
|
|
46
|
+
return ok(Object.fromEntries(entries));
|
|
47
|
+
}
|
|
48
|
+
function validateVisitedScenes(index, value) {
|
|
49
|
+
if (!isPlainRecord(value))
|
|
50
|
+
return fail("reader.visitedScenes is not a plain object.");
|
|
51
|
+
const entries = [];
|
|
52
|
+
for (const sceneId of Object.keys(value)) {
|
|
53
|
+
if (!index.sceneIds.has(sceneId))
|
|
54
|
+
return fail(`visitedScenes has an unknown scene id "${sceneId}".`);
|
|
55
|
+
const entry = value[sceneId];
|
|
56
|
+
if (!isPlainRecord(entry))
|
|
57
|
+
return fail(`visitedScenes.${sceneId} is not a plain object.`);
|
|
58
|
+
const visitCount = entry.visitCount;
|
|
59
|
+
if (!isPositiveFiniteInteger(visitCount)) {
|
|
60
|
+
return fail(`visitedScenes.${sceneId}.visitCount is not a positive finite integer.`);
|
|
61
|
+
}
|
|
62
|
+
entries.push([sceneId, { visitCount }]);
|
|
63
|
+
}
|
|
64
|
+
return ok(Object.fromEntries(entries));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validates one `seenVariants` entry (docs/CORE_SPEC.md Section 33.8):
|
|
68
|
+
* both branch ids must belong to *this* Variant (never a foreign one),
|
|
69
|
+
* `seenCount` a positive finite integer, and `seenCount === 1` requires
|
|
70
|
+
* `firstSeenBranchId === lastSeenBranchId` — the converse is NOT required
|
|
71
|
+
* (a later count may legitimately return to the same branch).
|
|
72
|
+
*/
|
|
73
|
+
function validateVariantMemory(branchIds, entry) {
|
|
74
|
+
if (!isPlainRecord(entry))
|
|
75
|
+
return fail("not a plain object.");
|
|
76
|
+
const { firstSeenBranchId, lastSeenBranchId, seenCount } = entry;
|
|
77
|
+
if (typeof firstSeenBranchId !== "string" || !branchIds.has(firstSeenBranchId)) {
|
|
78
|
+
return fail("firstSeenBranchId does not belong to this Variant.");
|
|
79
|
+
}
|
|
80
|
+
if (typeof lastSeenBranchId !== "string" || !branchIds.has(lastSeenBranchId)) {
|
|
81
|
+
return fail("lastSeenBranchId does not belong to this Variant.");
|
|
82
|
+
}
|
|
83
|
+
if (!isPositiveFiniteInteger(seenCount))
|
|
84
|
+
return fail("seenCount is not a positive finite integer.");
|
|
85
|
+
if (seenCount === 1 && firstSeenBranchId !== lastSeenBranchId) {
|
|
86
|
+
return fail("seenCount is 1 but firstSeenBranchId differs from lastSeenBranchId.");
|
|
87
|
+
}
|
|
88
|
+
return ok({ firstSeenBranchId, lastSeenBranchId, seenCount });
|
|
89
|
+
}
|
|
90
|
+
function validateSeenVariants(index, value) {
|
|
91
|
+
if (!isPlainRecord(value))
|
|
92
|
+
return fail("reader.seenVariants is not a plain object.");
|
|
93
|
+
const entries = [];
|
|
94
|
+
for (const variantId of Object.keys(value)) {
|
|
95
|
+
const branchIds = index.variantBranches.get(variantId);
|
|
96
|
+
if (!branchIds)
|
|
97
|
+
return fail(`seenVariants has an unknown Variant id "${variantId}".`);
|
|
98
|
+
const validated = validateVariantMemory(branchIds, value[variantId]);
|
|
99
|
+
if (!validated.ok)
|
|
100
|
+
return fail(`seenVariants.${variantId}: ${validated.reason}`);
|
|
101
|
+
entries.push([variantId, validated.value]);
|
|
102
|
+
}
|
|
103
|
+
return ok(Object.fromEntries(entries));
|
|
104
|
+
}
|
|
105
|
+
function validateReaderState(index, value) {
|
|
106
|
+
if (!isPlainRecord(value))
|
|
107
|
+
return fail("reader is not a plain object.");
|
|
108
|
+
const visitedScenes = validateVisitedScenes(index, value.visitedScenes);
|
|
109
|
+
if (!visitedScenes.ok)
|
|
110
|
+
return visitedScenes;
|
|
111
|
+
const seenVariants = validateSeenVariants(index, value.seenVariants);
|
|
112
|
+
if (!seenVariants.ok)
|
|
113
|
+
return seenVariants;
|
|
114
|
+
return ok({ visitedScenes: visitedScenes.value, seenVariants: seenVariants.value });
|
|
115
|
+
}
|
|
116
|
+
/** `navigation.sceneId` must name a real scene regardless of `current.type` (docs/CORE_SPEC.md Section 33.8 step 4 — a universal check, not conditioned on suspension kind). */
|
|
117
|
+
function validateNavigationState(index, value) {
|
|
118
|
+
if (!isPlainRecord(value))
|
|
119
|
+
return fail("navigation is not a plain object.");
|
|
120
|
+
const sceneId = value.sceneId;
|
|
121
|
+
if (typeof sceneId !== "string")
|
|
122
|
+
return fail("navigation is not a valid NavigationState.");
|
|
123
|
+
if (!index.sceneIds.has(sceneId))
|
|
124
|
+
return fail(`navigation.sceneId "${sceneId}" does not exist.`);
|
|
125
|
+
return ok({ sceneId });
|
|
126
|
+
}
|
|
127
|
+
export function validateRuntimeState(index, value) {
|
|
128
|
+
if (!isPlainRecord(value))
|
|
129
|
+
return fail("runtimeState is not a plain object.");
|
|
130
|
+
const story = validateStoryState(value.story);
|
|
131
|
+
if (!story.ok)
|
|
132
|
+
return story;
|
|
133
|
+
const reader = validateReaderState(index, value.reader);
|
|
134
|
+
if (!reader.ok)
|
|
135
|
+
return reader;
|
|
136
|
+
const navigation = validateNavigationState(index, value.navigation);
|
|
137
|
+
if (!navigation.ok)
|
|
138
|
+
return navigation;
|
|
139
|
+
return ok({ story: story.value, reader: reader.value, navigation: navigation.value });
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Whether `runtimeState` equals exactly what `createPlayer(document)`
|
|
143
|
+
* would itself produce (docs/CORE_SPEC.md Section 33.8) — required for a
|
|
144
|
+
* `"not started"` snapshot. Uses ordinary `===` (not `Object.is`) so
|
|
145
|
+
* `-0`/`0` compare equal, matching every other numeric comparison in this
|
|
146
|
+
* codebase's expression semantics (Section 17.8).
|
|
147
|
+
*/
|
|
148
|
+
export function isFreshRuntimeState(document, runtimeState) {
|
|
149
|
+
if (runtimeState.navigation.sceneId !== document.entryScene)
|
|
150
|
+
return false;
|
|
151
|
+
if (Object.keys(runtimeState.reader.visitedScenes).length !== 0)
|
|
152
|
+
return false;
|
|
153
|
+
if (Object.keys(runtimeState.reader.seenVariants).length !== 0)
|
|
154
|
+
return false;
|
|
155
|
+
return storyEqualsInitialState(runtimeState.story, document.initialState);
|
|
156
|
+
}
|
|
157
|
+
function storyEqualsInitialState(story, initialState) {
|
|
158
|
+
const storyKeys = Object.keys(story);
|
|
159
|
+
const initialKeys = Object.keys(initialState);
|
|
160
|
+
if (storyKeys.length !== initialKeys.length)
|
|
161
|
+
return false;
|
|
162
|
+
return initialKeys.every((key) => Object.hasOwn(story, key) && story[key] === initialState[key]);
|
|
163
|
+
}
|
|
164
|
+
/** A genuine `completed` result always has a `visitedScenes` entry for the current scene (docs/CORE_SPEC.md Section 33.8). */
|
|
165
|
+
export function hasVisitedCurrentScene(runtimeState) {
|
|
166
|
+
return Object.hasOwn(runtimeState.reader.visitedScenes, runtimeState.navigation.sceneId);
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=snapshot-runtime-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-runtime-state.js","sourceRoot":"","sources":["../src/snapshot-runtime-state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAepD,SAAS,sBAAsB,CAAC,MAA6B,EAAE,IAA8B;IAC3F,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MA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from "@aftertext/runtime";
|
|
2
|
+
import type { PlayerState } from "./player-state.js";
|
|
3
|
+
/**
|
|
4
|
+
* Runtime-local recursive JSON-compatible value alias (docs/CORE_SPEC.md
|
|
5
|
+
* Section 33.6). This is the one Player owns as named public API — unlike
|
|
6
|
+
* Runtime's own private `JsonValue` (`@aftertext/runtime`'s package
|
|
7
|
+
* `exports` boundary keeps it unexported), Player's `snapshotPlayer`/
|
|
8
|
+
* `restorePlayer` are the public encode/decode boundary a host actually
|
|
9
|
+
* calls, so this alias is genuinely public.
|
|
10
|
+
*/
|
|
11
|
+
export type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
|
|
12
|
+
readonly [key: string]: JsonValue;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A serializable, JSON-compatible snapshot of one `PlayerState` (docs/
|
|
16
|
+
* CORE_SPEC.md Section 33.6). `position`/`current` are public storage
|
|
17
|
+
* fields but semantically opaque — only `@aftertext/player` interprets
|
|
18
|
+
* their internal shape; consumers must store/round-trip them verbatim and
|
|
19
|
+
* never depend on their structure.
|
|
20
|
+
*/
|
|
21
|
+
export interface PlayerSnapshot {
|
|
22
|
+
readonly formatVersion: 1;
|
|
23
|
+
readonly documentFingerprint: string;
|
|
24
|
+
readonly runtimeState: RuntimeState;
|
|
25
|
+
readonly position: JsonValue;
|
|
26
|
+
readonly current: JsonValue;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A small, closed taxonomy (docs/CORE_SPEC.md Section 33.8) — no
|
|
30
|
+
* diagnostic-code infrastructure. `reason` is optional on the two kinds
|
|
31
|
+
* the spec describes as "may carry a human-readable reason"; the
|
|
32
|
+
* implementation populates it on every actual rejection path, but the
|
|
33
|
+
* type itself does not require it.
|
|
34
|
+
*/
|
|
35
|
+
export type PlayerRestoreError = {
|
|
36
|
+
readonly kind: "unsupportedFormatVersion";
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: "documentMismatch";
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "malformedSnapshot";
|
|
41
|
+
readonly reason?: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: "unresolvablePosition";
|
|
44
|
+
readonly reason?: string;
|
|
45
|
+
};
|
|
46
|
+
export type RestorePlayerResult = {
|
|
47
|
+
readonly ok: true;
|
|
48
|
+
readonly state: PlayerState;
|
|
49
|
+
} | {
|
|
50
|
+
readonly ok: false;
|
|
51
|
+
readonly error: PlayerRestoreError;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Captures `value.length` exactly once and returns it only if it is a
|
|
55
|
+
* genuine array length — a nonnegative integer — within
|
|
56
|
+
* `MAX_JSON_ARRAY_LENGTH`, or `undefined` otherwise — the one place
|
|
57
|
+
* this package reads an untrusted array's `.length`. Checking only the
|
|
58
|
+
* upper bound is not enough: a Proxy's `length` trap can return a
|
|
59
|
+
* negative number (or `NaN`, or a non-integer), which would pass an
|
|
60
|
+
* upper-bound-only check and then make every caller's `for (let i = 0;
|
|
61
|
+
* i < length; i++)` loop below run zero iterations — silently treating
|
|
62
|
+
* a malformed array as validly *empty* rather than rejecting it.
|
|
63
|
+
* Checking the length and then separately calling a built-in like
|
|
64
|
+
* `.every()` is also not equivalent: `.every()` performs its own
|
|
65
|
+
* internal `Get(array, "length")`, a second read a live Proxy can
|
|
66
|
+
* answer differently from the first (small enough to pass this check,
|
|
67
|
+
* then enormous), so every caller here iterates by index up to the
|
|
68
|
+
* value this function returns instead of ever calling `.every()`/
|
|
69
|
+
* `for...of` on the array itself.
|
|
70
|
+
*/
|
|
71
|
+
export declare function boundedArrayLength(value: readonly unknown[]): number | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Validates that `value` is entirely JSON-compatible (docs/CORE_SPEC.md
|
|
74
|
+
* Section 33.6, 33.8): only `null`, `string`, `boolean`, a finite number,
|
|
75
|
+
* an array of valid `JsonValue`s, or a plain record of valid `JsonValue`s.
|
|
76
|
+
* Rejects `undefined`, `NaN`/`Infinity`/`-Infinity`, `bigint`, `symbol`,
|
|
77
|
+
* functions, and any object whose prototype is not `Object.prototype` or
|
|
78
|
+
* `null` (so a `Date`/`Map`/`Set`/class instance is never mistaken for a
|
|
79
|
+
* JSON record merely because it has enumerable fields). Never throws and
|
|
80
|
+
* never does exponential work, even on a cyclic, pathologically deep, or
|
|
81
|
+
* heavily-shared (DAG-shaped) input — see `MAX_JSON_VALUE_DEPTH`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function isJsonValue(value: unknown): value is JsonValue;
|
|
84
|
+
/** Whether `value` is a plain, untrusted-input-safe record — the `unknown`-input counterpart of `isJsonValue`'s own record check. */
|
|
85
|
+
export declare function isPlainRecord(value: unknown): value is Readonly<Record<string, unknown>>;
|
|
86
|
+
//# sourceMappingURL=snapshot-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-types.d.ts","sourceRoot":"","sources":["../src/snapshot-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,SAAS,EAAE,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAExH;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;IAC1B,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,0BAA0B,CAAA;CAAE,GAC7C;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,GACrC;IAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAChE;IAAE,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AA+D/D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,GAAG,SAAS,CAGhF;AAyBD;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;AAED,qIAAqI;AACrI,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAExF"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether `value` is itself a plain `{}`/`Object.create(null)`-style
|
|
3
|
+
* record — never a class instance, `Date`, `Map`, `Set`, or other object
|
|
4
|
+
* with a non-ordinary prototype (docs/CORE_SPEC.md Section 33.8's
|
|
5
|
+
* prototype-safety requirement extends to validation, not only
|
|
6
|
+
* reconstruction: an enumerable-looking class instance must never be
|
|
7
|
+
* treated as untrusted JSON data merely because it has fields).
|
|
8
|
+
*/
|
|
9
|
+
function hasOrdinaryRecordPrototype(value) {
|
|
10
|
+
const prototype = Object.getPrototypeOf(value);
|
|
11
|
+
return prototype === Object.prototype || prototype === null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Caps how deeply `isJsonValue` will recurse into nested arrays/records
|
|
15
|
+
* (docs/CORE_SPEC.md Section 33.8): `restorePlayer`'s `snapshot` parameter
|
|
16
|
+
* is `unknown`, not merely "whatever `JSON.parse` can produce" — a caller
|
|
17
|
+
* may hand it any JS value, including a self-referential object a real
|
|
18
|
+
* JSON document could never express. Without a depth cap, validating such
|
|
19
|
+
* a value (or an extremely deeply nested but acyclic one) recurses once
|
|
20
|
+
* per level and eventually throws `RangeError: Maximum call stack size
|
|
21
|
+
* exceeded` instead of returning the `{ok:false}` this public boundary
|
|
22
|
+
* promises for every malformed input (never a thrown exception). No
|
|
23
|
+
* legitimate `position`/`current` payload this package ever produces
|
|
24
|
+
* nests anywhere near this deep, so the cap costs nothing for real data.
|
|
25
|
+
*
|
|
26
|
+
* The depth cap alone does not bound total *work*: a value can be a DAG
|
|
27
|
+
* rather than a tree (the same child object referenced by many parents,
|
|
28
|
+
* e.g. repeatedly wrapping one shared child as `[child, child]`), which
|
|
29
|
+
* stays within the depth cap while the naive walk below re-validates that
|
|
30
|
+
* shared subtree once per path to it — exponential in the number of
|
|
31
|
+
* wrapping levels. `memo` records each object's already-computed result
|
|
32
|
+
* (only once fully resolved, never for a call cut short by the depth
|
|
33
|
+
* cap, so a node later reached again via a shallower path is still
|
|
34
|
+
* evaluated correctly on its own terms) so a shared reference is walked
|
|
35
|
+
* at most once, bounding total work by the number of distinct objects in
|
|
36
|
+
* the graph rather than the number of paths to them.
|
|
37
|
+
*
|
|
38
|
+
* Neither the depth cap nor memoization bounds a single array's own
|
|
39
|
+
* *length*: `Array.isArray(value)` accepts a sparse array like
|
|
40
|
+
* `new Array(0xffffffff)`, and `.every()` still performs one
|
|
41
|
+
* `HasProperty` check per index up to that length — billions of
|
|
42
|
+
* synchronous checks for one shallow, memory-cheap array, hanging
|
|
43
|
+
* `restorePlayer` before the depth cap or memo ever come into play
|
|
44
|
+
* (both only limit work *below* a node, not the cost of scanning the
|
|
45
|
+
* node itself). `MAX_JSON_ARRAY_LENGTH` rejects any array claiming to be
|
|
46
|
+
* larger than this — chosen purely to stop a sparse-array length lie
|
|
47
|
+
* from costing a meaningful amount of synchronous time (still a few
|
|
48
|
+
* milliseconds of `.every()` even at this size), never to approximate
|
|
49
|
+
* "how many Choice items a document could reasonably have": the
|
|
50
|
+
* compiler's own `parseChoice` imposes no item-count limit at all, so
|
|
51
|
+
* any cap here lower than this would reject a `snapshotPlayer`/
|
|
52
|
+
* `restorePlayer` round trip for a legitimately authored (if unusually
|
|
53
|
+
* large) Choice. A real, attacker-independent Choice this large would
|
|
54
|
+
* still be handled correctly — `choiceItemsAreValidSubsequence`'s own
|
|
55
|
+
* early reject bounds its DP table by the *authored* list's length,
|
|
56
|
+
* which this constant does not touch.
|
|
57
|
+
*/
|
|
58
|
+
const MAX_JSON_VALUE_DEPTH = 64;
|
|
59
|
+
const MAX_JSON_ARRAY_LENGTH = 1_000_000;
|
|
60
|
+
/**
|
|
61
|
+
* Captures `value.length` exactly once and returns it only if it is a
|
|
62
|
+
* genuine array length — a nonnegative integer — within
|
|
63
|
+
* `MAX_JSON_ARRAY_LENGTH`, or `undefined` otherwise — the one place
|
|
64
|
+
* this package reads an untrusted array's `.length`. Checking only the
|
|
65
|
+
* upper bound is not enough: a Proxy's `length` trap can return a
|
|
66
|
+
* negative number (or `NaN`, or a non-integer), which would pass an
|
|
67
|
+
* upper-bound-only check and then make every caller's `for (let i = 0;
|
|
68
|
+
* i < length; i++)` loop below run zero iterations — silently treating
|
|
69
|
+
* a malformed array as validly *empty* rather than rejecting it.
|
|
70
|
+
* Checking the length and then separately calling a built-in like
|
|
71
|
+
* `.every()` is also not equivalent: `.every()` performs its own
|
|
72
|
+
* internal `Get(array, "length")`, a second read a live Proxy can
|
|
73
|
+
* answer differently from the first (small enough to pass this check,
|
|
74
|
+
* then enormous), so every caller here iterates by index up to the
|
|
75
|
+
* value this function returns instead of ever calling `.every()`/
|
|
76
|
+
* `for...of` on the array itself.
|
|
77
|
+
*/
|
|
78
|
+
export function boundedArrayLength(value) {
|
|
79
|
+
const length = value.length;
|
|
80
|
+
return Number.isInteger(length) && length >= 0 && length <= MAX_JSON_ARRAY_LENGTH ? length : undefined;
|
|
81
|
+
}
|
|
82
|
+
function isJsonValueAtDepth(value, depth, memo) {
|
|
83
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
84
|
+
return true;
|
|
85
|
+
if (typeof value === "number")
|
|
86
|
+
return Number.isFinite(value);
|
|
87
|
+
if (typeof value !== "object")
|
|
88
|
+
return false;
|
|
89
|
+
const cached = memo.get(value);
|
|
90
|
+
if (cached !== undefined)
|
|
91
|
+
return cached;
|
|
92
|
+
if (depth >= MAX_JSON_VALUE_DEPTH)
|
|
93
|
+
return false;
|
|
94
|
+
const result = Array.isArray(value)
|
|
95
|
+
? isJsonArrayAtDepth(value, depth, memo)
|
|
96
|
+
: hasOrdinaryRecordPrototype(value) && Object.values(value).every((item) => isJsonValueAtDepth(item, depth + 1, memo));
|
|
97
|
+
memo.set(value, result);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
function isJsonArrayAtDepth(value, depth, memo) {
|
|
101
|
+
const length = boundedArrayLength(value);
|
|
102
|
+
if (length === undefined)
|
|
103
|
+
return false;
|
|
104
|
+
for (let i = 0; i < length; i++) {
|
|
105
|
+
if (!isJsonValueAtDepth(value[i], depth + 1, memo))
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Validates that `value` is entirely JSON-compatible (docs/CORE_SPEC.md
|
|
112
|
+
* Section 33.6, 33.8): only `null`, `string`, `boolean`, a finite number,
|
|
113
|
+
* an array of valid `JsonValue`s, or a plain record of valid `JsonValue`s.
|
|
114
|
+
* Rejects `undefined`, `NaN`/`Infinity`/`-Infinity`, `bigint`, `symbol`,
|
|
115
|
+
* functions, and any object whose prototype is not `Object.prototype` or
|
|
116
|
+
* `null` (so a `Date`/`Map`/`Set`/class instance is never mistaken for a
|
|
117
|
+
* JSON record merely because it has enumerable fields). Never throws and
|
|
118
|
+
* never does exponential work, even on a cyclic, pathologically deep, or
|
|
119
|
+
* heavily-shared (DAG-shaped) input — see `MAX_JSON_VALUE_DEPTH`.
|
|
120
|
+
*/
|
|
121
|
+
export function isJsonValue(value) {
|
|
122
|
+
return isJsonValueAtDepth(value, 0, new Map());
|
|
123
|
+
}
|
|
124
|
+
/** Whether `value` is a plain, untrusted-input-safe record — the `unknown`-input counterpart of `isJsonValue`'s own record check. */
|
|
125
|
+
export function isPlainRecord(value) {
|
|
126
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && hasOrdinaryRecordPrototype(value);
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=snapshot-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-types.js","sourceRoot":"","sources":["../src/snapshot-types.ts"],"names":[],"mappings":"AA6CA;;;;;;;GAOG;AACH,SAAS,0BAA0B,CAAC,KAAa;IAC/C,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAyB;IAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,OAAO,MAAM,CAAC,SAAS,CA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KAAK,CAAC;IACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;IACnE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,kBAAkB,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;AACjD,CAAC;AAED,qIAAqI;AACrI,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,0BAA0B,CAAC,KAAK,CAAC,CAAC;AACnH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aftertext/player",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "AfterText headless Player Core: a thin, pure application layer over @aftertext/runtime for threading an active play session.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"test": "vitest run"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@aftertext/compiler": "^0.
|
|
34
|
-
"@aftertext/runtime": "^0.
|
|
33
|
+
"@aftertext/compiler": "^0.4.0",
|
|
34
|
+
"@aftertext/runtime": "^0.4.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^22.7.5",
|