@dreamboard-games/sdk 0.3.0-alpha.1 → 0.4.0-alpha.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.
Files changed (56) hide show
  1. package/REFERENCE.md +19935 -0
  2. package/dist/{chunk-3RQEICD3.js → chunk-2LDZ5C3T.js} +2 -2
  3. package/dist/chunk-3OZMHZK3.js +40 -0
  4. package/dist/chunk-3OZMHZK3.js.map +1 -0
  5. package/dist/{chunk-TXXLS3OI.js → chunk-4G7552LO.js} +3 -3
  6. package/dist/{chunk-P7VMTJ5D.js → chunk-MNKDSGIA.js} +2 -2
  7. package/dist/{chunk-P7VMTJ5D.js.map → chunk-MNKDSGIA.js.map} +1 -1
  8. package/dist/{chunk-W6SGFWXH.js → chunk-NBAEEHAU.js} +101 -60
  9. package/dist/chunk-NBAEEHAU.js.map +1 -0
  10. package/dist/{chunk-ADYH6PVT.js → chunk-P7F4L2FF.js} +49 -25
  11. package/dist/chunk-P7F4L2FF.js.map +1 -0
  12. package/dist/{chunk-QZ6X4B5P.js → chunk-Q5O7GPVY.js} +1 -1
  13. package/dist/{chunk-QZ6X4B5P.js.map → chunk-Q5O7GPVY.js.map} +1 -1
  14. package/dist/chunk-U5KBV2BA.js +2654 -0
  15. package/dist/chunk-U5KBV2BA.js.map +1 -0
  16. package/dist/{chunk-Y2AFYBMB.js → chunk-Y6Y2YABD.js} +9 -5
  17. package/dist/chunk-Y6Y2YABD.js.map +1 -0
  18. package/dist/codegen.d.ts +44 -51
  19. package/dist/codegen.js +1 -1
  20. package/dist/{index.d-BGqVifr_.d.ts → index.d-BL3bT5lt.d.ts} +82 -3
  21. package/dist/index.js +1 -1
  22. package/dist/package-set.d.ts +2 -2
  23. package/dist/package-set.js +1 -1
  24. package/dist/reducer/advanced.d.ts +78 -0
  25. package/dist/reducer/advanced.js +139 -0
  26. package/dist/reducer/advanced.js.map +1 -0
  27. package/dist/reducer-contract.d.ts +1 -1
  28. package/dist/reducer-contract.js +2 -2
  29. package/dist/reducer.d.ts +363 -3263
  30. package/dist/reducer.js +2778 -4081
  31. package/dist/reducer.js.map +1 -1
  32. package/dist/runtime/primitives.d.ts +3 -3
  33. package/dist/runtime/primitives.js +3 -3
  34. package/dist/runtime/runtime-api.d.ts +1 -1
  35. package/dist/runtime/workspace-contract.d.ts +18 -4
  36. package/dist/runtime/workspace-contract.js +4 -4
  37. package/dist/{runtime-api-tGL3ArsB.d.ts → runtime-api-BXd70c2e.d.ts} +6 -0
  38. package/dist/runtime.d.ts +2 -2
  39. package/dist/runtime.js +85 -20
  40. package/dist/runtime.js.map +1 -1
  41. package/dist/stale-contract-artifact-error-BelRiIDR.d.ts +66 -0
  42. package/dist/testing.d.ts +59 -5
  43. package/dist/testing.js +170 -6
  44. package/dist/testing.js.map +1 -1
  45. package/dist/types.d.ts +112 -119
  46. package/dist/ui/components.js +1 -1
  47. package/dist/ui/plugin-styles.css +2 -250
  48. package/dist/{ui-contract-SctM4ibF.d.ts → ui-contract-BUC6iS3s.d.ts} +1 -1
  49. package/dist/ui.js +2 -2
  50. package/dist/views-B0hlW6IT.d.ts +3153 -0
  51. package/package.json +18 -10
  52. package/dist/chunk-ADYH6PVT.js.map +0 -1
  53. package/dist/chunk-W6SGFWXH.js.map +0 -1
  54. package/dist/chunk-Y2AFYBMB.js.map +0 -1
  55. /package/dist/{chunk-3RQEICD3.js.map → chunk-2LDZ5C3T.js.map} +0 -0
  56. /package/dist/{chunk-TXXLS3OI.js.map → chunk-4G7552LO.js.map} +0 -0
package/dist/reducer.d.ts CHANGED
@@ -1,3182 +1,69 @@
1
1
  import { z } from 'zod';
2
- import { CardCollection, ViewCard, ViewSlotOccupant } from './types.js';
3
- import { a as ReducerBundleContract } from './index.d-BGqVifr_.js';
2
+ import { aD as GeneratedManifestContractLike, dt as RuntimeTableRecord, ek as StateDefinition, dB as SchemaLike, bk as ManifestContractOf, l as BaseGameStateOfContract, ax as ErrorCodeOfContract, bz as PhaseDefinition, eL as ViewDefinition, bm as ManifestIdSchema, ce as ReducerManifestContract, ca as ReducerGameContract, aW as InputCollector, X as CollectorState, bW as PlayerIdOfState, eu as TableQueriesOfState, ag as DerivedResolver, eJ as ValidationIssue, ev as TargetKind, b1 as InputSelectionDescriptor, a_ as InputDomainDescriptor, y as BoardTargetDomainDescriptor, s as BoardInputCollectorMeta, K as CardIdOfState, bj as ManifestContract, es as TableOfState, g as AnyInteractionSpec, d as AnyCardActionSpec, aq as EffectMap, dC as ScopedPhaseState, eh as StageMap, bR as PhaseZoneList, F as CardActionMap, dU as SetupSelectionOfManifest, eF as TiledVertexIdOfTable, er as TableOfManifest, ex as TiledBoardIdOfTable, ez as TiledEdgeIdOfTable, eD as TiledSpaceIdOfTable, J as CardIdOfManifest, bD as PhaseMapOf, eN as ViewMapOf, cc as ReducerGameDefinition, eo as StaticViewDefinition, ay as ExactManifestContractOf, bG as PhaseNameOfContract, bc as InteractionSpec, bZ as PlayerZoneIdOfManifest, G as CardActionSpec, ba as InteractionRule, b7 as InteractionMap, bL as PhaseSchemasOfContract, j as AnySchema, a3 as ContinuationCallable, as as EffectRollDieDefinition, at as EffectShuffleDefinition, au as EffectShufflePlayerZoneDefinition, ej as StageSpec, et as TableQueries, cb as ReducerGameContractLike, q as BoardIdOfTable, o as BoardContainerIdOfTable } from './views-B0hlW6IT.js';
3
+ export { w as BoardRef, af as DerivedDefinition, aB as FrameworkErrorCodes, aC as GameStateOf, aV as InitialStateCallbacks, bs as Op, bv as PerPlayer, bw as PerPlayerBoardRef, bx as PerPlayerSchemaOptions, bU as PlayerId, c7 as ReducerAccept, c8 as ReducerEdit, cf as ReducerOps, cg as ReducerReject, ch as ReducerResult, cl as ReducerStateBase, cn as ReducerTransaction, co as ReducerValidationResult, cN as RotatePlayerZoneArgs, dV as SharedBoardRef, ew as TerminalOutcome, eS as asPlayerId, eU as boardRef, eV as boardRefKey, eW as boardRefSchema, eY as createDerivedResolver, f0 as createReducerEdit, f1 as createReducerOps, f2 as createReducerTransaction, f3 as defineDerived, f5 as isPerPlayer, f6 as isPerPlayerBoardRef, f7 as isPlayerId, f8 as isSharedBoardRef, fa as parseBoardRefKey, fb as perPlayer, fc as perPlayerBoardRef, fd as perPlayerEntries, fe as perPlayerGet, ff as perPlayerHas, fg as perPlayerKeys, fh as perPlayerMap, fi as perPlayerRequire, fj as perPlayerSchema, fk as perPlayerSet, fl as perPlayerSize, fm as perPlayerValues, fn as pipe, fp as sharedBoardRef } from './views-B0hlW6IT.js';
4
+ import { a as ReducerBundleContract } from './index.d-BL3bT5lt.js';
5
+ import { a as ReducerDiagnosticsSink } from './stale-contract-artifact-error-BelRiIDR.js';
6
+ export { D as DispatchTraceSummaryEntry, R as ReducerDiagnosticEvent, S as StaleContractArtifactError, b as StaleContractArtifactErrorOptions, c as StaleContractArtifactKind, i as isStaleContractArtifactError, n as noopDiagnosticsSink } from './stale-contract-artifact-error-BelRiIDR.js';
7
+ import './types.js';
4
8
 
5
- /**
6
- * Opaque brand applied to a runtime player identifier.
7
- *
8
- * Generators produce a workspace-specific `PlayerId` alias (e.g.
9
- * `Brand<string, "PlayerId">` in `shared/manifest-contract.ts`). Authors
10
- * obtain `PlayerId` values only through:
11
- * - `q.player.order()` / `q.player.current()` (reducer queries),
12
- * - engine-injected callback arguments (actions, phases, prompts),
13
- * - `perPlayerKeys(...)` / entries iteration,
14
- * - `asPlayerId(raw)` as an explicit escape hatch (e.g. ingress parsing).
15
- *
16
- * The brand is a phantom type: at runtime a `PlayerId` is just a string.
17
- * Do not JSON-serialize the brand marker; it exists purely at the type
18
- * level to block accidental literal comparisons such as
19
- * `playerId === "player-1"`.
20
- */
21
- type PlayerId = Brand<string, "PlayerId">;
22
- /**
23
- * Explicit conversion from a raw string to a branded `PlayerId`.
24
- *
25
- * Use at trust boundaries only (wire ingress, tests, fixtures). Inside
26
- * reducer logic, obtain `PlayerId` values from the engine instead of
27
- * constructing them yourself.
28
- */
29
- declare function asPlayerId(raw: string): PlayerId;
30
- /**
31
- * Type guard that narrows `unknown` to `PlayerId` when the value is a
32
- * non-empty string. Does not validate against a specific player roster;
33
- * use `perPlayerSchema`/ingress parsing for that.
34
- */
35
- declare function isPlayerId(value: unknown): value is PlayerId;
36
- /**
37
- * A runtime-accurate per-player map.
38
- *
39
- * `PerPlayer<Value>` is an opaque, ordered container whose entries are
40
- * exactly the players that exist at runtime (the seats passed to
41
- * `initialize`).
42
- *
43
- * The `__perPlayer` discriminator keeps the structural type nominal-ish
44
- * without depending on a symbol (symbols do not round-trip through JSON,
45
- * which this shape must).
46
- *
47
- * Construct with `perPlayer(ids, init)` and read with the accessors in
48
- * this module; do not reach into `entries` directly unless you need
49
- * ordered iteration.
50
- */
51
- interface PerPlayer<Value, Id extends PlayerId = PlayerId> {
52
- readonly __perPlayer: true;
53
- readonly entries: ReadonlyArray<readonly [Id, Value]>;
54
- }
55
- /**
56
- * Construct a `PerPlayer<Value>` with one entry per `id` in `ids`.
57
- *
58
- * `ids` is treated as the authoritative runtime seat list: the returned
59
- * `PerPlayer` contains exactly `ids.length` entries, in the same order.
60
- * Duplicate ids throw.
61
- */
62
- declare function perPlayer<Value, Id extends PlayerId = PlayerId>(ids: readonly Id[], init: (id: Id, index: number) => Value): PerPlayer<Value, Id>;
63
- /** Ordered list of seat ids present in the `PerPlayer`. */
64
- declare function perPlayerKeys<Id extends PlayerId>(value: PerPlayer<unknown, Id>): Id[];
65
- /** Ordered list of values present in the `PerPlayer`. */
66
- declare function perPlayerValues<Value>(value: PerPlayer<Value, PlayerId>): Value[];
67
- /**
68
- * Ordered `[id, value]` pairs. Returns the backing array as-is; callers
69
- * must not mutate it.
70
- */
71
- declare function perPlayerEntries<Value, Id extends PlayerId>(value: PerPlayer<Value, Id>): ReadonlyArray<readonly [Id, Value]>;
72
- /** Number of seats in the `PerPlayer`. */
73
- declare function perPlayerSize(value: PerPlayer<unknown, PlayerId>): number;
74
- /** Whether `id` has a value. */
75
- declare function perPlayerHas<Id extends PlayerId>(value: PerPlayer<unknown, Id>, id: Id): boolean;
76
- /** Lookup with no fallback; returns `undefined` for missing seats. */
77
- declare function perPlayerGet<Value, Id extends PlayerId>(value: PerPlayer<Value, Id>, id: Id): Value | undefined;
78
- /**
79
- * Lookup that throws if `id` is not present.
80
- *
81
- * Use when the caller has already established (via `q.player.order()`,
82
- * an action context, etc.) that `id` is an active runtime seat.
83
- */
84
- declare function perPlayerRequire<Value, Id extends PlayerId>(value: PerPlayer<Value, Id>, id: Id): Value;
85
- /**
86
- * Return a new `PerPlayer` with `id`'s value replaced (or added if the
87
- * id is not present). Preserves entry order; new entries are appended.
88
- */
89
- declare function perPlayerSet<Value, Id extends PlayerId>(value: PerPlayer<Value, Id>, id: Id, next: Value): PerPlayer<Value, Id>;
90
- /**
91
- * Return a new `PerPlayer` where each value is replaced by `f(value, id)`.
92
- * Seat order is preserved.
93
- */
94
- declare function perPlayerMap<Value, Next, Id extends PlayerId>(value: PerPlayer<Value, Id>, f: (v: Value, id: Id, index: number) => Next): PerPlayer<Next, Id>;
95
- /**
96
- * Structural check for a `PerPlayer` without a Zod schema. Useful in
97
- * debug paths and as a fast pre-filter before schema validation.
98
- */
99
- declare function isPerPlayer(value: unknown): value is PerPlayer<unknown>;
100
- /**
101
- * Options accepted by `perPlayerSchema`.
102
- *
103
- * Setting `players` locks the schema to an exact seat list: parse fails
104
- * if the input is missing any seat or has an unknown id. Leaving
105
- * `players` unset yields a schema that accepts any non-empty string as
106
- * a key, which is the right default for generic SDK types.
107
- *
108
- * `playerIdSchema` lets callers feed a manifest-scoped Zod id schema in
109
- * so parse errors carry the same message as other branded ids.
110
- */
111
- type PerPlayerSchemaOptions<Id extends PlayerId> = {
112
- readonly playerIdSchema?: z.ZodType<Id>;
113
- readonly players?: readonly Id[];
114
- };
115
- /**
116
- * Build a Zod schema that validates a wire-shaped `PerPlayer<Value>`.
117
- *
118
- * When `options.players` is supplied the schema enforces that entries
119
- * match that exact set (same cardinality, same ids, any order). This is
120
- * the mechanism that catches the class of bug where a 3-player session
121
- * produced a view shape the old `Record<PlayerId, T>` type claimed had
122
- * a `player-4` key.
123
- */
124
- declare function perPlayerSchema<Value, Id extends PlayerId = PlayerId>(valueSchema: z.ZodType<Value>, options?: PerPlayerSchemaOptions<Id>): z.ZodType<PerPlayer<Value, Id>>;
125
- /**
126
- * Reference to a board by its authored `baseId`, plus an optional seat
127
- * for per-player boards.
128
- *
129
- * Replaces the old generated `"ring:player-1" | "ring:player-2" | ...`
130
- * flat unions whose keys pretended to be static but were actually
131
- * derived from `maxPlayers` and therefore misaligned with the runtime
132
- * seat list.
133
- *
134
- * The discriminant is the *presence* of `seat`, not a `scope` field, so
135
- * authors can destructure and pass the ref directly without needing a
136
- * discriminator check for shared boards.
137
- */
138
- type BoardRef<BaseId extends string = string, Id extends PlayerId = PlayerId> = SharedBoardRef<BaseId> | PerPlayerBoardRef<BaseId, Id>;
139
- interface SharedBoardRef<BaseId extends string = string> {
140
- readonly baseId: BaseId;
141
- readonly seat?: undefined;
142
- }
143
- interface PerPlayerBoardRef<BaseId extends string = string, Id extends PlayerId = PlayerId> {
144
- readonly baseId: BaseId;
145
- readonly seat: Id;
146
- }
147
- /** Construct a shared board ref. */
148
- declare function sharedBoardRef<BaseId extends string>(baseId: BaseId): SharedBoardRef<BaseId>;
149
- /** Construct a per-player board ref. */
150
- declare function perPlayerBoardRef<BaseId extends string, Id extends PlayerId>(baseId: BaseId, seat: Id): PerPlayerBoardRef<BaseId, Id>;
151
- /**
152
- * Construct a `BoardRef` without knowing the scope ahead of time. Pass
153
- * `seat` for per-player boards; omit for shared boards.
154
- */
155
- declare function boardRef<BaseId extends string, Id extends PlayerId>(baseId: BaseId, seat?: Id): BoardRef<BaseId, Id>;
156
- /** Stable string key for Maps/Records keyed by a `BoardRef`. */
157
- declare function boardRefKey(ref: BoardRef): string;
158
- /**
159
- * Inverse of `boardRefKey`. Parses `"base"` as a shared ref and
160
- * `"base:player-N"` as a per-player ref. Returns `null` for malformed
161
- * input.
162
- */
163
- declare function parseBoardRefKey(key: string): BoardRef | null;
164
- /**
165
- * Zod schema for a `BoardRef` with free-form base and seat ids.
166
- *
167
- * Feed a manifest-scoped `baseIdSchema` and `playerIdSchema` to bind
168
- * the ref to a specific workspace.
169
- */
170
- declare function boardRefSchema<BaseId extends string = string, Id extends PlayerId = PlayerId>(options?: {
171
- readonly baseIdSchema?: z.ZodType<BaseId>;
172
- readonly playerIdSchema?: z.ZodType<Id>;
173
- }): z.ZodType<BoardRef<BaseId, Id>>;
174
- /** True when `ref` targets a shared board (no seat). */
175
- declare function isSharedBoardRef<BaseId extends string>(ref: BoardRef<BaseId, PlayerId>): ref is SharedBoardRef<BaseId>;
176
- /** True when `ref` targets a per-player board (has a seat). */
177
- declare function isPerPlayerBoardRef<BaseId extends string, Id extends PlayerId>(ref: BoardRef<BaseId, Id>): ref is PerPlayerBoardRef<BaseId, Id>;
178
-
179
- type RuntimeScalar = boolean | number | string | null;
180
- interface RuntimeRecord {
181
- [key: string]: RuntimePayload | undefined;
182
- }
183
- type RuntimePayload = RuntimeScalar | RuntimePayload[] | RuntimeRecord;
184
- type SchemaLike<Output> = z.ZodType<Output>;
185
- type AnySchema = z.ZodTypeAny;
186
- type StringKeyOf<T> = Extract<keyof T, string>;
187
- type Brand<Value, Name extends string> = Value & {
188
- readonly __brand: Name;
189
- };
190
- type RuntimeHandVisibilityMode = "all" | "ownerOnly" | "public" | "hidden";
191
- type RuntimeDeckMap = Record<string, string[]>;
192
- type RuntimeHandMap = Record<string, PerPlayer<string[]>>;
193
- type RuntimeZoneMap = {
194
- shared: Record<string, string[]>;
195
- perPlayer: Record<string, PerPlayer<string[]>>;
196
- visibility: Record<string, RuntimeHandVisibilityMode>;
197
- cardSetIdsByZoneId?: Record<string, readonly string[]>;
198
- };
199
- type RuntimeOwnerMap = Record<string, string | null>;
200
- type RuntimeResourceMap = PerPlayer<RuntimeRecord>;
201
- type RuntimeBoardSpaceState = {
202
- id: string;
203
- name?: string | null;
204
- typeId?: string | null;
205
- fields: RuntimeRecord;
206
- zoneId?: string | null;
207
- };
208
- type RuntimeBoardRelationState = {
209
- id?: string | null;
210
- typeId: string;
211
- fromSpaceId: string;
212
- toSpaceId: string;
213
- directed: boolean;
214
- fields: RuntimeRecord;
215
- };
216
- type RuntimeBoardContainerState = {
217
- id: string;
218
- name: string;
219
- host: {
220
- type: "board";
221
- } | {
222
- type: "space";
223
- spaceId: string;
224
- };
225
- allowedCardSetIds?: readonly string[];
226
- zoneId: string;
227
- fields: RuntimeRecord;
228
- };
229
- type RuntimeBoardCompatibilityState = {
230
- spaces: Record<string, RuntimeBoardSpaceState>;
231
- relations: RuntimeBoardRelationState[];
232
- containers: Record<string, RuntimeBoardContainerState>;
233
- };
234
- type RuntimeBoardBaseState = {
235
- id: string;
236
- baseId?: string;
237
- layout: "generic" | "hex" | "square";
238
- typeId?: string | null;
239
- scope: "shared" | "perPlayer";
240
- playerId?: string | null;
241
- templateId?: string | null;
242
- fields: RuntimeRecord;
243
- };
244
- type RuntimeGenericBoardState = RuntimeBoardBaseState & {
245
- layout: "generic";
246
- } & RuntimeBoardCompatibilityState;
247
- type RuntimeHexSpaceState = RuntimeBoardSpaceState & {
248
- q: number;
249
- r: number;
250
- };
251
- type RuntimeSquareSpaceState = RuntimeBoardSpaceState & {
252
- row: number;
253
- col: number;
254
- };
255
- type RuntimeTiledEdgeState = {
256
- id: string;
257
- spaceIds: readonly string[];
258
- typeId?: string | null;
259
- label?: string | null;
260
- ownerId?: string | null;
261
- fields: RuntimeRecord;
262
- };
263
- type RuntimeTiledVertexState = {
264
- id: string;
265
- spaceIds: readonly string[];
266
- typeId?: string | null;
267
- label?: string | null;
268
- ownerId?: string | null;
269
- fields: RuntimeRecord;
270
- };
271
- type RuntimeHexEdgeState = RuntimeTiledEdgeState;
272
- type RuntimeHexVertexState = RuntimeTiledVertexState;
273
- type RuntimeSquareEdgeState = RuntimeTiledEdgeState;
274
- type RuntimeSquareVertexState = RuntimeTiledVertexState;
275
- type RuntimeHexOrientation = "pointy-top" | "flat-top";
276
- type RuntimeTiledBoardBaseState = RuntimeBoardBaseState & {
277
- layout: "hex" | "square";
278
- relations: RuntimeBoardRelationState[];
279
- containers: Record<string, RuntimeBoardContainerState>;
280
- edges: RuntimeTiledEdgeState[];
281
- vertices: RuntimeTiledVertexState[];
282
- };
283
- type RuntimeHexBoardState = RuntimeTiledBoardBaseState & {
284
- layout: "hex";
285
- spaces: Record<string, RuntimeHexSpaceState>;
286
- orientation: RuntimeHexOrientation;
287
- edges: RuntimeHexEdgeState[];
288
- vertices: RuntimeHexVertexState[];
289
- };
290
- type RuntimeSquareBoardState = RuntimeTiledBoardBaseState & {
291
- layout: "square";
292
- spaces: Record<string, RuntimeSquareSpaceState>;
293
- edges: RuntimeSquareEdgeState[];
294
- vertices: RuntimeSquareVertexState[];
295
- };
296
- type RuntimeTiledBoardState = RuntimeHexBoardState | RuntimeSquareBoardState;
297
- type RuntimeBoardState = RuntimeGenericBoardState | RuntimeTiledBoardState;
298
- type RuntimeBoardCollections = {
299
- byId: Record<string, RuntimeBoardState>;
300
- hex: Record<string, RuntimeHexBoardState>;
301
- square: Record<string, RuntimeSquareBoardState>;
302
- /** Structured board buckets used by manifest table schemas (empty when unused). */
303
- network: Record<string, RuntimeRecord>;
304
- track: Record<string, RuntimeRecord>;
305
- };
306
- type RuntimeCardVisibility = {
307
- faceUp: boolean;
308
- visibleTo?: string[] | null;
309
- };
310
- type RuntimeCardData = {
311
- componentType?: string;
312
- id: string;
313
- cardSetId: string;
314
- cardType: string;
315
- name?: string;
316
- text?: string;
317
- properties: RuntimeRecord;
318
- };
319
- type RuntimePieceData = {
320
- componentType?: string;
321
- id: string;
322
- pieceTypeId: string;
323
- pieceName?: string | null;
324
- ownerId?: string | null;
325
- properties: RuntimeRecord;
326
- };
327
- type RuntimeDieData = {
328
- componentType?: string;
329
- id: string;
330
- dieTypeId: string;
331
- dieName?: string | null;
332
- ownerId?: string | null;
333
- sides: number;
334
- value?: number | null;
335
- properties: RuntimeRecord;
336
- };
337
- type RuntimeSlotHostRef = {
338
- kind: "piece";
339
- id: string;
340
- } | {
341
- kind: "die";
342
- id: string;
343
- };
344
- type RuntimeComponentLocation = {
345
- type: "Detached";
346
- } | {
347
- type: "InDeck";
348
- deckId: string;
349
- playedBy: string | null;
350
- position?: number | null;
351
- } | {
352
- type: "InHand";
353
- handId: string;
354
- playerId: string;
355
- position?: number | null;
356
- } | {
357
- type: "InZone";
358
- zoneId: string;
359
- playedBy?: string | null;
360
- position?: number | null;
361
- } | {
362
- type: "OnSpace";
363
- boardId: string;
364
- spaceId: string;
365
- position?: number | null;
366
- } | {
367
- type: "InContainer";
368
- boardId: string;
369
- containerId: string;
370
- position?: number | null;
371
- } | {
372
- type: "OnEdge";
373
- boardId: string;
374
- edgeId: string;
375
- position?: number | null;
376
- } | {
377
- type: "OnVertex";
378
- boardId: string;
379
- vertexId: string;
380
- position?: number | null;
381
- } | {
382
- type: "InSlot";
383
- host: RuntimeSlotHostRef;
384
- slotId: string;
385
- position?: number | null;
386
- };
387
- type RuntimeComponentLocationMap = Record<string, RuntimeComponentLocation>;
388
- type RuntimeVisibilityMap = Record<string, RuntimeCardVisibility>;
389
- type RuntimeTableRecord = {
390
- playerOrder: string[];
391
- zones: RuntimeZoneMap;
392
- decks: RuntimeDeckMap;
393
- hands: RuntimeHandMap;
394
- handVisibility: Record<string, RuntimeHandVisibilityMode>;
395
- cards: Record<string, RuntimeCardData>;
396
- pieces: Record<string, RuntimePieceData>;
397
- componentLocations: RuntimeComponentLocationMap;
398
- ownerOfCard: RuntimeOwnerMap;
399
- visibility: RuntimeVisibilityMap;
400
- resources: RuntimeResourceMap;
401
- boards: RuntimeBoardCollections;
402
- dice: Record<string, RuntimeDieData>;
403
- };
404
-
405
- type TableOfState<State> = State extends {
406
- table: infer Table;
407
- } ? Table : never;
408
- type TableOfManifest<Manifest> = Manifest extends GeneratedManifestContractLike<infer Table> ? Table : never;
409
- type PhaseNameOfState<State> = State extends {
410
- flow: {
411
- currentPhase: infer PhaseName;
412
- };
413
- } ? Extract<PhaseName, string> : never;
414
- type PhaseNameOfManifest<Manifest> = Manifest extends {
415
- literals: {
416
- phaseNames: readonly (infer PhaseName)[];
417
- };
418
- } ? Extract<PhaseName, string> : never;
419
- type PlayerIdOfTable<Table> = Table extends {
420
- playerOrder: readonly (infer PlayerId)[];
421
- } ? Extract<PlayerId, string> : never;
422
- type PlayerIdOfManifest<Manifest> = Manifest extends {
423
- literals: {
424
- playerIds: readonly (infer PlayerId)[];
425
- };
426
- } ? Extract<PlayerId, string> : string;
427
- type PlayerIdOfState<State> = PlayerIdOfTable<TableOfState<State>>;
428
- /**
429
- * Manifest-declared resource id union for a runtime table.
430
- *
431
- * Derived from the shape of `table.resources`, which the generated
432
- * manifest contract seeds as `PerPlayer<Record<ResourceId, number>>`.
433
- * The helper peeks inside the `PerPlayer` wrapper to surface the
434
- * resource-id keys without forcing callers to remember the wrapper.
435
- */
436
- type ResourceIdOfTable<Table> = Table extends {
437
- resources: infer Resources;
438
- } ? ValueOfPerPlayer<Resources> extends infer PerPlayerValue ? PerPlayerValue extends Record<string, unknown> ? StringKeyOf<PerPlayerValue> : never : never : never;
439
- /**
440
- * Per-player balance shape for a runtime table. Strips the `PerPlayer`
441
- * wrapper around `table.resources` so callers receive the manifest-typed
442
- * record directly (e.g. `Record<ResourceId, number>`).
443
- */
444
- type ResourceBalancesOfTable<Table> = Table extends {
445
- resources: infer Resources;
446
- } ? ValueOfPerPlayer<Resources> extends infer PerPlayerValue ? PerPlayerValue extends Record<string, unknown> ? PerPlayerValue : never : never : never;
447
- /**
448
- * Per-player resource counts: a partial `Record<ResourceId, number>`.
449
- *
450
- * Used as the input shape for {@link ReducerOps.addResources},
451
- * {@link ReducerOps.spendResources}, and {@link ReducerOps.transferResources}.
452
- */
453
- type ResourceAmountsOfTable<Table> = Partial<Record<ResourceIdOfTable<Table>, number>>;
454
- type PhaseStateOfState<State> = State extends {
455
- phase: infer PhaseState;
456
- } ? PhaseState : never;
457
- type PublicStateOfState<State> = State extends {
458
- publicState: infer PublicState;
459
- } ? PublicState : never;
460
- type HiddenStateOfState<State> = State extends {
461
- hiddenState: infer HiddenState;
462
- } ? HiddenState : never;
463
- type PrivateStateOfState<State> = State extends {
464
- privateState: Record<string, infer PrivateState>;
465
- } ? PrivateState : never;
466
- type DeckIdOfTable<Table> = Table extends {
467
- decks: infer Decks;
468
- } ? StringKeyOf<Decks> : never;
469
- type HandIdOfTable<Table> = Table extends {
470
- hands: infer Hands;
471
- } ? StringKeyOf<Hands> : never;
472
- type CardIdOfTable<Table> = Table extends {
473
- cards: infer Cards;
474
- } ? StringKeyOf<Cards> : never;
475
- type CardTypeOfTable<Table> = Table extends {
476
- cards: Record<string, {
477
- cardType: infer CardType;
478
- }>;
479
- } ? Extract<CardType, string> : string;
480
- type DeckIdOfState<State> = DeckIdOfTable<TableOfState<State>>;
481
- type HandIdOfState<State> = HandIdOfTable<TableOfState<State>>;
482
- type CardIdOfState<State> = CardIdOfTable<TableOfState<State>>;
483
- type CardTypeOfState<State> = CardTypeOfTable<TableOfState<State>>;
484
- type CardIdOfManifest<Manifest> = Manifest extends {
485
- literals: {
486
- cardIds: readonly (infer CardId)[];
487
- };
488
- } ? Extract<CardId, string> : string;
489
- type SharedZoneIdOfTable<Table> = DeckIdOfTable<Table>;
490
- type PlayerZoneIdOfTable<Table> = HandIdOfTable<Table>;
491
- type BoardMapOfTable<Table> = Table extends {
492
- boards: {
493
- byId: infer Boards;
494
- };
495
- } ? Boards : never;
496
- type BoardIdOfTable<Table> = StringKeyOf<BoardMapOfTable<Table>>;
497
- type BoardStateOfTable<Table, BoardId extends BoardIdOfTable<Table>> = BoardMapOfTable<Table>[BoardId];
498
- type BoardTypeIdOfTable<Table> = BoardStateOfTable<Table, BoardIdOfTable<Table>> extends {
499
- typeId?: infer BoardTypeId | null;
500
- } ? Extract<BoardTypeId, string> : never;
501
- type TiledBoardIdOfTable<Table> = {
502
- [BoardId in BoardIdOfTable<Table>]: BoardStateOfTable<Table, BoardId> extends {
503
- layout: "hex" | "square";
504
- } ? BoardId : never;
505
- }[BoardIdOfTable<Table>];
506
- type TiledBoardStateOfTable<Table, BoardId extends TiledBoardIdOfTable<Table>> = BoardStateOfTable<Table, BoardId> extends infer BoardState ? BoardState extends {
507
- layout: "hex" | "square";
508
- spaces: Record<string, unknown>;
509
- edges: readonly {
510
- id: string;
511
- }[];
512
- vertices: readonly {
513
- id: string;
514
- }[];
515
- } ? BoardState : never : never;
516
- type HexBoardIdOfTable<Table> = {
517
- [BoardId in BoardIdOfTable<Table>]: BoardStateOfTable<Table, BoardId> extends {
518
- layout: "hex";
519
- } ? BoardId : never;
520
- }[BoardIdOfTable<Table>];
521
- type HexBoardStateOfTable<Table, BoardId extends HexBoardIdOfTable<Table>> = BoardStateOfTable<Table, BoardId> extends infer BoardState ? BoardState extends {
522
- layout: "hex";
523
- spaces: Record<string, unknown>;
524
- edges: readonly {
525
- id: string;
526
- }[];
527
- vertices: readonly {
528
- id: string;
529
- }[];
530
- } ? BoardState : never : never;
531
- type SquareBoardIdOfTable<Table> = {
532
- [BoardId in BoardIdOfTable<Table>]: BoardStateOfTable<Table, BoardId> extends {
533
- layout: "square";
534
- } ? BoardId : never;
535
- }[BoardIdOfTable<Table>];
536
- type SquareBoardStateOfTable<Table, BoardId extends SquareBoardIdOfTable<Table>> = BoardStateOfTable<Table, BoardId> extends infer BoardState ? BoardState extends {
537
- layout: "square";
538
- spaces: Record<string, unknown>;
539
- edges: readonly {
540
- id: string;
541
- }[];
542
- vertices: readonly {
543
- id: string;
544
- }[];
545
- } ? BoardState : never : never;
546
- type SpaceIdOfTable<Table, BoardId extends BoardIdOfTable<Table>> = BoardStateOfTable<Table, BoardId> extends {
547
- spaces: infer Spaces;
548
- } ? StringKeyOf<Spaces> : never;
549
- type SpaceTypeIdOfTable<Table, BoardId extends BoardIdOfTable<Table>> = BoardStateOfTable<Table, BoardId> extends {
550
- spaces: infer Spaces extends Record<string, unknown>;
551
- } ? Spaces[StringKeyOf<Spaces>] extends {
552
- typeId?: infer SpaceTypeId | null;
553
- } ? Extract<SpaceTypeId, string> : never : never;
554
- type BoardContainerIdOfTable<Table, BoardId extends BoardIdOfTable<Table>> = BoardStateOfTable<Table, BoardId> extends {
555
- containers: infer Containers;
556
- } ? StringKeyOf<Containers> : never;
557
- type RelationTypeIdOfTable<Table, BoardId extends BoardIdOfTable<Table>> = BoardStateOfTable<Table, BoardId> extends {
558
- relations: readonly (infer Relation)[];
559
- } ? Relation extends {
560
- typeId: infer RelationTypeId;
561
- } ? Extract<RelationTypeId, string> : never : never;
562
- type TiledSpaceIdOfTable<Table, BoardId extends TiledBoardIdOfTable<Table>> = TiledBoardStateOfTable<Table, BoardId> extends {
563
- spaces: infer Spaces;
564
- } ? StringKeyOf<Spaces> : never;
565
- type HexSpaceIdOfTable<Table, BoardId extends HexBoardIdOfTable<Table>> = HexBoardStateOfTable<Table, BoardId> extends {
566
- spaces: infer Spaces;
567
- } ? StringKeyOf<Spaces> : never;
568
- type SquareSpaceIdOfTable<Table, BoardId extends SquareBoardIdOfTable<Table>> = SquareBoardStateOfTable<Table, BoardId> extends {
569
- spaces: infer Spaces;
570
- } ? StringKeyOf<Spaces> : never;
571
- type HexSpaceTypeIdOfTable<Table, BoardId extends HexBoardIdOfTable<Table>> = HexBoardStateOfTable<Table, BoardId> extends {
572
- spaces: infer Spaces extends Record<string, unknown>;
573
- } ? Spaces[StringKeyOf<Spaces>] extends {
574
- typeId?: infer SpaceTypeId | null;
575
- } ? Extract<SpaceTypeId, string> : never : never;
576
- type SquareSpaceTypeIdOfTable<Table, BoardId extends SquareBoardIdOfTable<Table>> = SquareBoardStateOfTable<Table, BoardId> extends {
577
- spaces: infer Spaces extends Record<string, unknown>;
578
- } ? Spaces[StringKeyOf<Spaces>] extends {
579
- typeId?: infer SpaceTypeId | null;
580
- } ? Extract<SpaceTypeId, string> : never : never;
581
- type TiledEdgeIdOfTable<Table, BoardId extends TiledBoardIdOfTable<Table>> = TiledBoardStateOfTable<Table, BoardId> extends {
582
- edges: readonly (infer Edge)[];
583
- } ? Edge extends {
584
- id: infer EdgeId;
585
- } ? Extract<EdgeId, string> : never : never;
586
- type HexEdgeIdOfTable<Table, BoardId extends HexBoardIdOfTable<Table>> = HexBoardStateOfTable<Table, BoardId> extends {
587
- edges: readonly (infer Edge)[];
588
- } ? Edge extends {
589
- id: infer EdgeId;
590
- } ? Extract<EdgeId, string> : never : never;
591
- type SquareEdgeIdOfTable<Table, BoardId extends SquareBoardIdOfTable<Table>> = SquareBoardStateOfTable<Table, BoardId> extends {
592
- edges: readonly (infer Edge)[];
593
- } ? Edge extends {
594
- id: infer EdgeId;
595
- } ? Extract<EdgeId, string> : never : never;
596
- /**
597
- * Edge record on a tiled board narrowed to a specific `EdgeId` literal.
598
- *
599
- * The generated board state stores edges as a single array element type
600
- * `{ id: <union-of-edge-ids>, spaceIds, typeId, fields, ... }`. Looking up an
601
- * edge by id should return a record whose `id` is narrowed to the literal
602
- * that was requested, not the entire edge-id union.
603
- */
604
- type TiledEdgeStateOfTable<Table, BoardId extends TiledBoardIdOfTable<Table>, EdgeId extends TiledEdgeIdOfTable<Table, BoardId>> = TiledBoardStateOfTable<Table, BoardId> extends {
605
- edges: readonly (infer Edge)[];
606
- } ? Edge extends {
607
- id: string;
608
- } ? Omit<Edge, "id"> & {
609
- id: EdgeId;
610
- } : never : never;
611
- type TiledEdgeTypeIdOfTable<Table, BoardId extends TiledBoardIdOfTable<Table>> = TiledBoardStateOfTable<Table, BoardId> extends {
612
- edges: readonly (infer Edge)[];
613
- } ? Edge extends {
614
- typeId?: infer EdgeTypeId | null;
615
- } ? Extract<EdgeTypeId, string> : never : never;
616
- type HexEdgeTypeIdOfTable<Table, BoardId extends HexBoardIdOfTable<Table>> = HexBoardStateOfTable<Table, BoardId> extends {
617
- edges: readonly (infer Edge)[];
618
- } ? Edge extends {
619
- typeId?: infer EdgeTypeId | null;
620
- } ? Extract<EdgeTypeId, string> : never : never;
621
- type SquareEdgeTypeIdOfTable<Table, BoardId extends SquareBoardIdOfTable<Table>> = SquareBoardStateOfTable<Table, BoardId> extends {
622
- edges: readonly (infer Edge)[];
623
- } ? Edge extends {
624
- typeId?: infer EdgeTypeId | null;
625
- } ? Extract<EdgeTypeId, string> : never : never;
626
- type TiledVertexIdOfTable<Table, BoardId extends TiledBoardIdOfTable<Table>> = TiledBoardStateOfTable<Table, BoardId> extends {
627
- vertices: readonly (infer Vertex)[];
628
- } ? Vertex extends {
629
- id: infer VertexId;
630
- } ? Extract<VertexId, string> : never : never;
631
- type HexVertexIdOfTable<Table, BoardId extends HexBoardIdOfTable<Table>> = HexBoardStateOfTable<Table, BoardId> extends {
632
- vertices: readonly (infer Vertex)[];
633
- } ? Vertex extends {
634
- id: infer VertexId;
635
- } ? Extract<VertexId, string> : never : never;
636
- type SquareVertexIdOfTable<Table, BoardId extends SquareBoardIdOfTable<Table>> = SquareBoardStateOfTable<Table, BoardId> extends {
637
- vertices: readonly (infer Vertex)[];
638
- } ? Vertex extends {
639
- id: infer VertexId;
640
- } ? Extract<VertexId, string> : never : never;
641
- /**
642
- * Vertex record on a tiled board narrowed to a specific `VertexId` literal.
643
- * See {@link TiledEdgeStateOfTable} for rationale.
644
- */
645
- type TiledVertexStateOfTable<Table, BoardId extends TiledBoardIdOfTable<Table>, VertexId extends TiledVertexIdOfTable<Table, BoardId>> = TiledBoardStateOfTable<Table, BoardId> extends {
646
- vertices: readonly (infer Vertex)[];
647
- } ? Vertex extends {
648
- id: string;
649
- } ? Omit<Vertex, "id"> & {
650
- id: VertexId;
651
- } : never : never;
652
- type TiledVertexTypeIdOfTable<Table, BoardId extends TiledBoardIdOfTable<Table>> = TiledBoardStateOfTable<Table, BoardId> extends {
653
- vertices: readonly (infer Vertex)[];
654
- } ? Vertex extends {
655
- typeId?: infer VertexTypeId | null;
656
- } ? Extract<VertexTypeId, string> : never : never;
657
- type HexVertexTypeIdOfTable<Table, BoardId extends HexBoardIdOfTable<Table>> = HexBoardStateOfTable<Table, BoardId> extends {
658
- vertices: readonly (infer Vertex)[];
659
- } ? Vertex extends {
660
- typeId?: infer VertexTypeId | null;
661
- } ? Extract<VertexTypeId, string> : never : never;
662
- type SquareVertexTypeIdOfTable<Table, BoardId extends SquareBoardIdOfTable<Table>> = SquareBoardStateOfTable<Table, BoardId> extends {
663
- vertices: readonly (infer Vertex)[];
664
- } ? Vertex extends {
665
- typeId?: infer VertexTypeId | null;
666
- } ? Extract<VertexTypeId, string> : never : never;
667
- type TiledSpaceMap<Table, BoardId extends TiledBoardIdOfTable<Table>, Value> = Partial<Record<TiledSpaceIdOfTable<Table, BoardId>, Value>>;
668
- type TiledEdgeMap<Table, BoardId extends TiledBoardIdOfTable<Table>, Value> = Partial<Record<TiledEdgeIdOfTable<Table, BoardId>, Value>>;
669
- type TiledVertexMap<Table, BoardId extends TiledBoardIdOfTable<Table>, Value> = Partial<Record<TiledVertexIdOfTable<Table, BoardId>, Value>>;
670
- type ComponentIdOfTable<Table> = Table extends {
671
- componentLocations: infer ComponentLocations;
672
- } ? StringKeyOf<ComponentLocations> : never;
673
- type SharedZoneIdOfManifest<Manifest> = Manifest extends {
674
- literals: {
675
- sharedZoneIds: readonly (infer ZoneId)[];
676
- };
677
- } ? Extract<ZoneId, string> : string;
678
- type PlayerZoneIdOfManifest<Manifest> = Manifest extends {
679
- literals: {
680
- playerZoneIds: readonly (infer ZoneId)[];
681
- };
682
- } ? Extract<ZoneId, string> : string;
683
- type SharedZoneIdOfState<State> = DeckIdOfState<State>;
684
- type PlayerZoneIdOfState<State> = HandIdOfState<State>;
685
- type BoardIdOfManifest<Manifest> = Manifest extends {
686
- literals: {
687
- boardIds: readonly (infer BoardId)[];
688
- };
689
- } ? Extract<BoardId, string> : string;
690
- type BoardLayoutOfManifest<Manifest> = Manifest extends {
691
- literals: {
692
- boardLayouts: readonly (infer BoardLayout)[];
693
- };
694
- } ? Extract<BoardLayout, string> : "generic" | "hex" | "square";
695
- type BoardTypeIdOfManifest<Manifest> = Manifest extends {
696
- literals: {
697
- boardTypeIds: readonly (infer BoardTypeId)[];
698
- };
699
- } ? Extract<BoardTypeId, string> : string;
700
- type BoardBaseIdOfManifest<Manifest> = Manifest extends {
701
- literals: {
702
- boardBaseIds: readonly (infer BoardBaseId)[];
703
- };
704
- } ? Extract<BoardBaseId, string> : string;
705
- type RelationTypeIdOfManifest<Manifest> = Manifest extends {
706
- literals: {
707
- relationTypeIds: readonly (infer RelationTypeId)[];
708
- };
709
- } ? Extract<RelationTypeId, string> : string;
710
- type BoardContainerIdOfManifest<Manifest> = Manifest extends {
711
- literals: {
712
- boardContainerIds: readonly (infer ContainerId)[];
713
- };
714
- } ? Extract<ContainerId, string> : string;
715
- type EdgeTypeIdOfManifest<Manifest> = Manifest extends {
716
- literals: {
717
- edgeTypeIds: readonly (infer EdgeTypeId)[];
718
- };
719
- } ? Extract<EdgeTypeId, string> : string;
720
- type VertexTypeIdOfManifest<Manifest> = Manifest extends {
721
- literals: {
722
- vertexTypeIds: readonly (infer VertexTypeId)[];
723
- };
724
- } ? Extract<VertexTypeId, string> : string;
725
- type SpaceIdOfManifest<Manifest> = Manifest extends {
726
- literals: {
727
- spaceIds: readonly (infer SpaceId)[];
728
- };
729
- } ? Extract<SpaceId, string> : string;
730
- type SpaceTypeIdOfManifest<Manifest> = Manifest extends {
731
- literals: {
732
- spaceTypeIds: readonly (infer SpaceTypeId)[];
733
- };
734
- } ? Extract<SpaceTypeId, string> : string;
735
- type PieceIdOfManifest<Manifest> = Manifest extends {
736
- literals: {
737
- pieceIds: readonly (infer PieceId)[];
738
- };
739
- } ? Extract<PieceId, string> : string;
740
- type DieIdOfManifest<Manifest> = Manifest extends {
741
- literals: {
742
- dieIds: readonly (infer DieId)[];
743
- };
744
- } ? Extract<DieId, string> : string;
745
- type ManifestOf<Source> = Source extends {
746
- contract: infer Contract;
747
- } ? ManifestOf<Contract> : Source extends {
748
- manifest: infer Manifest;
749
- } ? Manifest : never;
750
- type SetupOptionIdOfManifest<Manifest> = Manifest extends {
751
- literals: {
752
- setupOptionIds: readonly (infer SetupOptionId)[];
753
- };
754
- } ? Extract<SetupOptionId, string> : string;
755
- type SetupProfileIdOfManifest<Manifest> = Manifest extends {
756
- literals: {
757
- setupProfileIds: readonly (infer SetupProfileId)[];
758
- };
759
- } ? Extract<SetupProfileId, string> : string;
760
- type SetupSelectionInputOfManifest<Manifest> = {
761
- profileId: SetupProfileIdOfManifest<Manifest>;
762
- optionValues?: Partial<Record<SetupOptionIdOfManifest<Manifest>, string>>;
763
- };
764
- type SetupSelectionOfManifest<Manifest> = {
765
- profileId: SetupProfileIdOfManifest<Manifest>;
766
- optionValues: Record<SetupOptionIdOfManifest<Manifest>, string | null>;
767
- };
768
- type RuntimeSetupSelectionInput<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = SetupSelectionInputOfManifest<Manifest>;
769
- type RuntimeSetupSelection<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = SetupSelectionOfManifest<Manifest>;
770
- type StateDefinitionOfContract<Contract> = Contract extends {
771
- state: infer StateDefinitionValue;
772
- } ? StateDefinitionValue : never;
773
- type PhaseSchemasOfContract<Contract> = Contract extends {
774
- phases: infer Phases extends Record<string, SchemaLike<object>>;
775
- } ? Phases : Record<PhaseNameOfManifest<ManifestOf<Contract>>, SchemaLike<object>>;
776
- type PhaseStateMapOfContract<Contract> = {
777
- [Name in keyof PhaseSchemasOfContract<Contract> & string]: z.infer<PhaseSchemasOfContract<Contract>[Name]>;
778
- };
779
- type PublicSchemaOfContract<Contract> = StateDefinitionOfContract<Contract> extends StateDefinition<infer PublicSchema, infer _PrivateSchema, infer _HiddenSchema> ? PublicSchema : never;
780
- type PrivateSchemaOfContract<Contract> = StateDefinitionOfContract<Contract> extends StateDefinition<infer _PublicSchema, infer PrivateSchema, infer _HiddenSchema> ? PrivateSchema : never;
781
- type HiddenSchemaOfContract<Contract> = StateDefinitionOfContract<Contract> extends StateDefinition<infer _PublicSchema, infer _PrivateSchema, infer HiddenSchema> ? HiddenSchema : never;
782
- type PhaseNameOfContract<Contract> = keyof PhaseSchemasOfContract<Contract> extends string ? keyof PhaseSchemasOfContract<Contract> & string : PhaseNameOfManifest<ManifestOf<Contract>>;
783
- type ManifestContractOf<Contract> = ManifestContract<TableOfManifest<ManifestOf<Contract>>>;
784
- type ExactManifestContractOf<Contract> = ManifestOf<Contract> & GeneratedManifestContractLike<TableOfManifest<ManifestOf<Contract>>>;
785
- type PhaseNameOf<Source> = Source extends {
786
- flow: {
787
- currentPhase: infer PhaseName;
788
- };
789
- } ? Extract<PhaseName, string> : PhaseNameOfContract<Source>;
790
- type DeckCardsOfTable<Table, DeckId extends DeckIdOfTable<Table>> = Table extends {
791
- decks: infer Decks extends Record<string, readonly unknown[]>;
792
- } ? Decks[DeckId] : never;
793
- type ValueOfPerPlayer<T> = T extends {
794
- readonly entries: ReadonlyArray<readonly [unknown, infer Value]>;
795
- } ? Value : never;
796
- type HandCardsOfTable<Table, HandId extends HandIdOfTable<Table>> = Table extends {
797
- hands: infer Hands extends Record<string, unknown>;
798
- } ? HandId extends keyof Hands ? ValueOfPerPlayer<Hands[HandId]> extends infer Value ? Value extends readonly unknown[] ? Value : never : never : never : never;
799
- type CardIdOfDeck<Table, DeckId extends DeckIdOfTable<Table>> = DeckCardsOfTable<Table, DeckId>[number];
800
- type CardIdOfHand<Table, HandId extends HandIdOfTable<Table>> = HandCardsOfTable<Table, HandId>[number];
801
- type CompatibleHandIdForDeck<Table, DeckId extends DeckIdOfTable<Table>> = {
802
- [CandidateHandId in HandIdOfTable<Table>]: Extract<CardIdOfDeck<Table, DeckId>, CardIdOfHand<Table, CandidateHandId>> extends never ? never : CandidateHandId;
803
- }[HandIdOfTable<Table>];
804
- type CompatibleCardIdForHandAndDeck<Table, HandId extends HandIdOfTable<Table>, DeckId extends DeckIdOfTable<Table>> = Extract<CardIdOfHand<Table, HandId>, CardIdOfDeck<Table, DeckId>>;
805
- type CompatibleCardIdForTwoPlayerZones<Table, FromZoneId extends HandIdOfTable<Table>, ToZoneId extends HandIdOfTable<Table>> = Extract<CardIdOfHand<Table, FromZoneId>, CardIdOfHand<Table, ToZoneId>>;
806
-
807
- type BoardRecord<Table extends RuntimeTableRecord, BoardId extends BoardIdOfTable<Table>> = Table["boards"]["byId"][BoardId];
808
- type TiledBoardRecord<Table extends RuntimeTableRecord, BoardId extends TiledBoardIdOfTable<Table>> = Extract<BoardRecord<Table, BoardId>, {
809
- layout: "hex" | "square";
810
- }>;
811
- type ViewCardOfTable<Table extends RuntimeTableRecord, CardId extends CardIdOfTable<Table>> = CardId extends CardIdOfTable<Table> ? ViewCard<CardId & string, Table["cards"][CardId]["cardType"] & string, Extract<Table["cards"][CardId]["properties"], Record<string, unknown>>> : never;
812
- type CardsByIdOfTable<Table extends RuntimeTableRecord, CardIds extends readonly CardIdOfTable<Table>[]> = Readonly<{
813
- [Id in CardIds[number]]: ViewCardOfTable<Table, Id> | undefined;
814
- }>;
815
- type DeckCardsForZone<Table extends RuntimeTableRecord, ZoneId extends DeckIdOfTable<Table>> = ZoneId extends infer Each extends DeckIdOfTable<Table> ? DeckCardsOfTable<Table, Each> : never;
816
- type HandCardsForZone<Table extends RuntimeTableRecord, ZoneId extends HandIdOfTable<Table>> = ZoneId extends infer Each extends HandIdOfTable<Table> ? HandCardsOfTable<Table, Each> : never;
817
- type CardCollectionOfTable<Table extends RuntimeTableRecord> = CardCollection<CardIdOfTable<Table> & string, ViewCardOfTable<Table, CardIdOfTable<Table>>>;
818
- type SlotOccupantOfTable<Table extends RuntimeTableRecord> = ViewSlotOccupant<ComponentIdOfTable<Table> & string, PlayerIdOfTable<Table> & string, string, Record<string, unknown>>;
819
- type SlotOccupantsOfTable<Table extends RuntimeTableRecord> = ReadonlyArray<SlotOccupantOfTable<Table>>;
820
- type SlotOccupantsBySlotIdOfTable<Table extends RuntimeTableRecord> = Readonly<Record<string, SlotOccupantsOfTable<Table>>>;
821
- type ComponentLocationOfTable<Table, ComponentId extends ComponentIdOfTable<Table>> = Table extends {
822
- componentLocations: infer ComponentLocations extends Record<string, unknown>;
823
- } ? ComponentLocations[ComponentId] : never;
824
- type ComponentDataOfTable<Table, ComponentId extends ComponentIdOfTable<Table>> = Table extends {
825
- cards: infer Cards extends Record<string, unknown>;
826
- pieces: infer Pieces extends Record<string, unknown>;
827
- dice: infer Dice extends Record<string, unknown>;
828
- } ? ComponentId extends keyof Cards ? Cards[ComponentId] : ComponentId extends keyof Pieces ? Pieces[ComponentId] : ComponentId extends keyof Dice ? Dice[ComponentId] : never : never;
829
- type ComponentLocationByTypeOfTable<Table, ComponentId extends ComponentIdOfTable<Table>, Type extends RuntimeComponentLocation["type"]> = Extract<ComponentLocationOfTable<Table, ComponentId>, {
830
- type: Type;
831
- }>;
832
- type ResolvedDeckLocation<Table extends RuntimeTableRecord, ComponentId extends ComponentIdOfTable<Table>> = {
833
- [DeckId in DeckIdOfTable<Table>]: {
834
- componentId: ComponentId;
835
- deckId: DeckId;
836
- cards: DeckCardsOfTable<Table, DeckId>;
837
- location: ComponentLocationByTypeOfTable<Table, ComponentId, "InDeck"> & {
838
- deckId: DeckId;
839
- };
840
- };
841
- }[DeckIdOfTable<Table>];
842
- type ResolvedHandLocation<Table extends RuntimeTableRecord, ComponentId extends ComponentIdOfTable<Table>> = {
843
- [HandId in HandIdOfTable<Table>]: {
844
- [PlayerId in PlayerIdOfTable<Table>]: {
845
- componentId: ComponentId;
846
- handId: HandId;
847
- playerId: PlayerId;
848
- cards: HandCardsOfTable<Table, HandId>;
849
- location: ComponentLocationByTypeOfTable<Table, ComponentId, "InHand"> & {
850
- handId: HandId;
851
- playerId: PlayerId;
852
- };
853
- };
854
- }[PlayerIdOfTable<Table>];
855
- }[HandIdOfTable<Table>];
856
- type ResolvedZoneLocation<Table extends RuntimeTableRecord, ComponentId extends ComponentIdOfTable<Table>> = ComponentLocationByTypeOfTable<Table, ComponentId, "InZone"> extends infer Location ? Location extends {
857
- type: "InZone";
858
- zoneId: infer ZoneId extends string;
859
- } ? {
860
- componentId: ComponentId;
861
- zoneId: ZoneId;
862
- location: Location;
863
- } : never : never;
864
- type ResolvedSpaceLocation<Table extends RuntimeTableRecord, ComponentId extends ComponentIdOfTable<Table>> = {
865
- [BoardId in BoardIdOfTable<Table>]: {
866
- [SpaceId in SpaceIdOfTable<Table, BoardId>]: {
867
- componentId: ComponentId;
868
- boardId: BoardId;
869
- board: BoardRecord<Table, BoardId>;
870
- spaceId: SpaceId;
871
- space: Table["boards"]["byId"][BoardId]["spaces"][SpaceId];
872
- location: ComponentLocationByTypeOfTable<Table, ComponentId, "OnSpace"> & {
873
- boardId: BoardId;
874
- spaceId: SpaceId;
875
- };
876
- };
877
- }[SpaceIdOfTable<Table, BoardId>];
878
- }[BoardIdOfTable<Table>];
879
- type ResolvedContainerLocation<Table extends RuntimeTableRecord, ComponentId extends ComponentIdOfTable<Table>> = {
880
- [BoardId in BoardIdOfTable<Table>]: {
881
- [ContainerId in BoardContainerIdOfTable<Table, BoardId>]: {
882
- componentId: ComponentId;
883
- boardId: BoardId;
884
- board: BoardRecord<Table, BoardId>;
885
- containerId: ContainerId;
886
- container: Table["boards"]["byId"][BoardId]["containers"][ContainerId];
887
- location: ComponentLocationByTypeOfTable<Table, ComponentId, "InContainer"> & {
888
- boardId: BoardId;
889
- containerId: ContainerId;
890
- };
891
- };
892
- }[BoardContainerIdOfTable<Table, BoardId>];
893
- }[BoardIdOfTable<Table>];
894
- type ResolvedEdgeLocation<Table extends RuntimeTableRecord, ComponentId extends ComponentIdOfTable<Table>> = {
895
- [BoardId in TiledBoardIdOfTable<Table>]: {
896
- [EdgeId in TiledEdgeIdOfTable<Table, BoardId>]: {
897
- componentId: ComponentId;
898
- boardId: BoardId;
899
- board: TiledBoardRecord<Table, BoardId>;
900
- edgeId: EdgeId;
901
- edge: Extract<Table["boards"]["byId"][BoardId], {
902
- layout: "hex" | "square";
903
- }>["edges"][number];
904
- location: ComponentLocationByTypeOfTable<Table, ComponentId, "OnEdge"> & {
905
- boardId: BoardId;
906
- edgeId: EdgeId;
907
- };
908
- };
909
- }[TiledEdgeIdOfTable<Table, BoardId>];
910
- }[TiledBoardIdOfTable<Table>];
911
- type ResolvedVertexLocation<Table extends RuntimeTableRecord, ComponentId extends ComponentIdOfTable<Table>> = {
912
- [BoardId in TiledBoardIdOfTable<Table>]: {
913
- [VertexId in TiledVertexIdOfTable<Table, BoardId>]: {
914
- componentId: ComponentId;
915
- boardId: BoardId;
916
- board: TiledBoardRecord<Table, BoardId>;
917
- vertexId: VertexId;
918
- vertex: Extract<Table["boards"]["byId"][BoardId], {
919
- layout: "hex" | "square";
920
- }>["vertices"][number];
921
- location: ComponentLocationByTypeOfTable<Table, ComponentId, "OnVertex"> & {
922
- boardId: BoardId;
923
- vertexId: VertexId;
924
- };
925
- };
926
- }[TiledVertexIdOfTable<Table, BoardId>];
927
- }[TiledBoardIdOfTable<Table>];
928
- type ResolvedSlotLocation<Table extends RuntimeTableRecord, ComponentId extends ComponentIdOfTable<Table>> = ComponentLocationByTypeOfTable<Table, ComponentId, "InSlot"> extends infer Location ? Location extends {
929
- type: "InSlot";
930
- host: infer Host extends RuntimeSlotHostRef;
931
- slotId: infer SlotId extends string;
932
- } ? {
933
- componentId: ComponentId;
934
- host: Host;
935
- slotId: SlotId;
936
- location: Location;
937
- } : never : never;
938
- type TableQueries<Table extends RuntimeTableRecord> = {
939
- board: {
940
- get: <BoardId extends BoardIdOfTable<Table>>(boardId: BoardId) => BoardRecord<Table, BoardId>;
941
- hex: <BoardId extends HexBoardIdOfTable<Table>>(boardId: BoardId) => Extract<BoardRecord<Table, BoardId>, {
942
- layout: "hex";
943
- }>;
944
- square: <BoardId extends SquareBoardIdOfTable<Table>>(boardId: BoardId) => Extract<BoardRecord<Table, BoardId>, {
945
- layout: "square";
946
- }>;
947
- tiled: <BoardId extends TiledBoardIdOfTable<Table>>(boardId: BoardId) => TiledBoardRecord<Table, BoardId>;
948
- space: <BoardId extends BoardIdOfTable<Table>, SpaceId extends SpaceIdOfTable<Table, BoardId>>(boardId: BoardId, spaceId: SpaceId) => Table["boards"]["byId"][BoardId]["spaces"][SpaceId];
949
- hexSpace: <BoardId extends HexBoardIdOfTable<Table>, SpaceId extends HexSpaceIdOfTable<Table, BoardId>>(boardId: BoardId, spaceId: SpaceId) => Extract<Table["boards"]["byId"][BoardId], {
950
- layout: "hex";
951
- }>["spaces"][SpaceId];
952
- squareSpace: <BoardId extends SquareBoardIdOfTable<Table>, SpaceId extends SquareSpaceIdOfTable<Table, BoardId>>(boardId: BoardId, spaceId: SpaceId) => Extract<Table["boards"]["byId"][BoardId], {
953
- layout: "square";
954
- }>["spaces"][SpaceId];
955
- container: <BoardId extends BoardIdOfTable<Table>, ContainerId extends BoardContainerIdOfTable<Table, BoardId>>(boardId: BoardId, containerId: ContainerId) => Table["boards"]["byId"][BoardId]["containers"][ContainerId];
956
- edge: <BoardId extends TiledBoardIdOfTable<Table>, EdgeId extends TiledEdgeIdOfTable<Table, BoardId>>(boardId: BoardId, edgeId: EdgeId) => TiledEdgeStateOfTable<Table, BoardId, EdgeId>;
957
- vertex: <BoardId extends TiledBoardIdOfTable<Table>, VertexId extends TiledVertexIdOfTable<Table, BoardId>>(boardId: BoardId, vertexId: VertexId) => TiledVertexStateOfTable<Table, BoardId, VertexId>;
958
- byType: <TypeId extends BoardTypeIdOfTable<Table>>(typeId: TypeId) => BoardIdOfTable<Table>[];
959
- spacesByType: <BoardId extends BoardIdOfTable<Table>, TypeId extends SpaceTypeIdOfTable<Table, BoardId>>(boardId: BoardId, typeId: TypeId) => SpaceIdOfTable<Table, BoardId>[];
960
- edgesByType: <BoardId extends TiledBoardIdOfTable<Table>, TypeId extends TiledEdgeTypeIdOfTable<Table, BoardId>>(boardId: BoardId, typeId: TypeId) => TiledEdgeIdOfTable<Table, BoardId>[];
961
- verticesByType: <BoardId extends TiledBoardIdOfTable<Table>, TypeId extends TiledVertexTypeIdOfTable<Table, BoardId>>(boardId: BoardId, typeId: TypeId) => TiledVertexIdOfTable<Table, BoardId>[];
962
- adjacentSpaces: <BoardId extends BoardIdOfTable<Table>, SpaceId extends SpaceIdOfTable<Table, BoardId>>(boardId: BoardId, spaceId: SpaceId) => SpaceIdOfTable<Table, BoardId>[];
963
- relatedSpaces: <BoardId extends BoardIdOfTable<Table>, SpaceId extends SpaceIdOfTable<Table, BoardId>, TypeId extends RelationTypeIdOfTable<Table, BoardId>>(boardId: BoardId, spaceId: SpaceId, relationTypeId: TypeId) => SpaceIdOfTable<Table, BoardId>[];
964
- incidentEdges: <BoardId extends TiledBoardIdOfTable<Table>, VertexId extends TiledVertexIdOfTable<Table, BoardId>>(boardId: BoardId, vertexId: VertexId) => TiledEdgeIdOfTable<Table, BoardId>[];
965
- incidentVertices: <BoardId extends TiledBoardIdOfTable<Table>, EdgeId extends TiledEdgeIdOfTable<Table, BoardId>>(boardId: BoardId, edgeId: EdgeId) => TiledVertexIdOfTable<Table, BoardId>[];
966
- spaceEdges: <BoardId extends TiledBoardIdOfTable<Table>>(boardId: BoardId, spaceId: SpaceIdOfTable<Table, BoardId>) => TiledEdgeIdOfTable<Table, BoardId>[];
967
- spaceVertices: <BoardId extends TiledBoardIdOfTable<Table>>(boardId: BoardId, spaceId: SpaceIdOfTable<Table, BoardId>) => TiledVertexIdOfTable<Table, BoardId>[];
968
- spaceDistance: <BoardId extends BoardIdOfTable<Table>, SpaceId extends SpaceIdOfTable<Table, BoardId>>(boardId: BoardId, fromSpaceId: SpaceId, toSpaceId: SpaceId) => number;
969
- hexSpaceAt: <BoardId extends HexBoardIdOfTable<Table>>(boardId: BoardId, q: number, r: number) => Extract<Table["boards"]["byId"][BoardId], {
970
- layout: "hex";
971
- }>["spaces"][HexSpaceIdOfTable<Table, BoardId>] | undefined;
972
- squareSpaceAt: <BoardId extends SquareBoardIdOfTable<Table>>(boardId: BoardId, row: number, col: number) => Extract<Table["boards"]["byId"][BoardId], {
973
- layout: "square";
974
- }>["spaces"][SquareSpaceIdOfTable<Table, BoardId>] | undefined;
975
- squareNeighbors: <BoardId extends SquareBoardIdOfTable<Table>, SpaceId extends SquareSpaceIdOfTable<Table, BoardId>>(boardId: BoardId, spaceId: SpaceId, options?: {
976
- mode?: "orthogonal" | "diagonal" | "all";
977
- }) => SquareSpaceIdOfTable<Table, BoardId>[];
978
- squareDistance: <BoardId extends SquareBoardIdOfTable<Table>, SpaceId extends SquareSpaceIdOfTable<Table, BoardId>>(boardId: BoardId, fromSpaceId: SpaceId, toSpaceId: SpaceId, options?: {
979
- metric?: "manhattan" | "chebyshev";
980
- }) => number;
981
- spaceOccupants: <BoardId extends BoardIdOfTable<Table>, SpaceId extends SpaceIdOfTable<Table, BoardId>>(boardId: BoardId, spaceId: SpaceId) => ComponentIdOfTable<Table>[];
982
- containerOccupants: <BoardId extends BoardIdOfTable<Table>, ContainerId extends BoardContainerIdOfTable<Table, BoardId>>(boardId: BoardId, containerId: ContainerId) => ComponentIdOfTable<Table>[];
983
- edgeOccupants: <BoardId extends TiledBoardIdOfTable<Table>, EdgeId extends TiledEdgeIdOfTable<Table, BoardId>>(boardId: BoardId, edgeId: EdgeId) => ComponentIdOfTable<Table>[];
984
- vertexOccupants: <BoardId extends TiledBoardIdOfTable<Table>, VertexId extends TiledVertexIdOfTable<Table, BoardId>>(boardId: BoardId, vertexId: VertexId) => ComponentIdOfTable<Table>[];
985
- };
986
- zone: {
987
- sharedCards: <ZoneId extends DeckIdOfTable<Table>>(zoneId: ZoneId) => DeckCardsForZone<Table, ZoneId>;
988
- sharedCardCollection: <ZoneId extends DeckIdOfTable<Table>>(zoneId: ZoneId) => CardCollectionOfTable<Table>;
989
- allSharedCards: () => {
990
- readonly [Z in DeckIdOfTable<Table>]: DeckCardsOfTable<Table, Z>;
991
- };
992
- playerCards: <PlayerId extends PlayerIdOfTable<Table>, ZoneId extends HandIdOfTable<Table>>(playerId: PlayerId, zoneId: ZoneId) => HandCardsForZone<Table, ZoneId>;
993
- playerCardCollection: <PlayerId extends PlayerIdOfTable<Table>, ZoneId extends HandIdOfTable<Table>>(playerId: PlayerId, zoneId: ZoneId) => CardCollectionOfTable<Table>;
994
- allPlayerCards: <ZoneId extends HandIdOfTable<Table>>(zoneId: ZoneId) => {
995
- readonly [P in PlayerIdOfTable<Table>]: HandCardsOfTable<Table, ZoneId>;
996
- };
997
- };
998
- card: {
999
- get: <CardId extends CardIdOfTable<Table>>(cardId: CardId) => ViewCardOfTable<Table, CardId>;
1000
- byIds: <CardIds extends readonly CardIdOfTable<Table>[]>(cardIds: CardIds) => CardsByIdOfTable<Table, CardIds>;
1001
- owner: <CardId extends CardIdOfTable<Table>>(cardId: CardId) => Table["ownerOfCard"][CardId];
1002
- visibility: <CardId extends CardIdOfTable<Table>>(cardId: CardId) => Table["visibility"][CardId];
1003
- };
1004
- slot: {
1005
- occupants: (host: RuntimeSlotHostRef, slotId: string) => SlotOccupantsOfTable<Table>;
1006
- occupantsByHost: (host: RuntimeSlotHostRef) => SlotOccupantsBySlotIdOfTable<Table>;
1007
- pieceOccupants: (hostId: string, slotId: string) => SlotOccupantsOfTable<Table>;
1008
- pieceOccupantsByHost: (hostId: string) => SlotOccupantsBySlotIdOfTable<Table>;
1009
- dieOccupants: (hostId: string, slotId: string) => SlotOccupantsOfTable<Table>;
1010
- dieOccupantsByHost: (hostId: string) => SlotOccupantsBySlotIdOfTable<Table>;
1011
- };
1012
- player: {
1013
- /** Seating order from the manifest / setup profile. */
1014
- order: () => Table["playerOrder"];
1015
- /**
1016
- * Next player id in seating order after `playerId`, wrapping around to
1017
- * the first seat. Returns `null` when `playerId` is unknown or the
1018
- * order is empty. Convenient for "whose turn is next" logic.
1019
- */
1020
- nextInOrder: (playerId: PlayerIdOfTable<Table>) => PlayerIdOfTable<Table> | null;
1021
- /** All resource balances for a player, as the manifest-typed record. */
1022
- resources: <PlayerId extends PlayerIdOfTable<Table>>(playerId: PlayerId) => ResourceBalancesOfTable<Table>;
1023
- /** Balance of a single resource; returns `0` when unset. */
1024
- resource: (playerId: PlayerIdOfTable<Table>, resourceId: ResourceIdOfTable<Table>) => number;
1025
- /**
1026
- * Sum of every resource amount held by a player (e.g. "total cards in
1027
- * hand" checks). Returns `0` for unknown players or empty balances.
1028
- */
1029
- resourceTotal: (playerId: PlayerIdOfTable<Table>) => number;
1030
- /** `true` when the player can pay every non-zero amount in `amounts`. */
1031
- canAfford: (playerId: PlayerIdOfTable<Table>, amounts: ResourceAmountsOfTable<Table>) => boolean;
1032
- /** Shortfall per resource when the player cannot afford `amounts`. */
1033
- missingResources: (playerId: PlayerIdOfTable<Table>, amounts: ResourceAmountsOfTable<Table>) => Partial<Record<ResourceIdOfTable<Table>, number>>;
1034
- };
1035
- component: {
1036
- data: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ComponentDataOfTable<Table, ComponentId> | undefined;
1037
- location: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ComponentLocationOfTable<Table, ComponentId> | undefined;
1038
- deck: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ResolvedDeckLocation<Table, ComponentId> | null;
1039
- hand: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ResolvedHandLocation<Table, ComponentId> | null;
1040
- zone: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ResolvedZoneLocation<Table, ComponentId> | null;
1041
- space: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ResolvedSpaceLocation<Table, ComponentId> | null;
1042
- container: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ResolvedContainerLocation<Table, ComponentId> | null;
1043
- edge: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ResolvedEdgeLocation<Table, ComponentId> | null;
1044
- vertex: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ResolvedVertexLocation<Table, ComponentId> | null;
1045
- slot: <ComponentId extends ComponentIdOfTable<Table>>(componentId: ComponentId) => ResolvedSlotLocation<Table, ComponentId> | null;
1046
- };
1047
- };
1048
- type TableQueriesOfState<State extends {
1049
- table: RuntimeTableRecord;
1050
- }> = TableQueries<TableOfState<State>>;
1051
-
1052
- declare const manifestIdSchemaBrand: unique symbol;
1053
- type ManifestIdSchema<Output = unknown> = z.ZodType<Output> & {
1054
- readonly [manifestIdSchemaBrand]: true;
1055
- };
1056
- type ManifestLiterals<PlayerId extends string, DeckId extends string, HandId extends string, CardId extends string, PhaseName extends string = string> = {
1057
- playerIds: readonly PlayerId[];
1058
- phaseNames: readonly PhaseName[];
1059
- boardLayouts: readonly ("generic" | "hex" | "square")[];
1060
- setupOptionIds: readonly string[];
1061
- setupProfileIds: readonly string[];
1062
- cardSetIds: readonly string[];
1063
- cardTypes: readonly string[];
1064
- deckIds: readonly DeckId[];
1065
- handIds: readonly HandId[];
1066
- sharedZoneIds: readonly DeckId[];
1067
- playerZoneIds: readonly HandId[];
1068
- zoneIds: readonly (DeckId | HandId)[];
1069
- cardIds: readonly CardId[];
1070
- resourceIds: readonly string[];
1071
- resourcePresentationById?: Record<string, {
1072
- label: string;
1073
- icon?: string | null;
1074
- }>;
1075
- pieceTypeIds: readonly string[];
1076
- pieceIds: readonly string[];
1077
- dieTypeIds: readonly string[];
1078
- dieIds: readonly string[];
1079
- boardTemplateIds: readonly string[];
1080
- boardTypeIds: readonly string[];
1081
- boardBaseIds: readonly string[];
1082
- boardIds: readonly string[];
1083
- boardContainerIds: readonly string[];
1084
- relationTypeIds: readonly string[];
1085
- edgeIds: readonly string[];
1086
- edgeTypeIds: readonly string[];
1087
- vertexIds: readonly string[];
1088
- vertexTypeIds: readonly string[];
1089
- spaceIds: readonly string[];
1090
- spaceTypeIds: readonly string[];
1091
- handVisibilityById: Record<HandId, RuntimeHandVisibilityMode>;
1092
- zoneVisibilityById: Record<DeckId | HandId, RuntimeHandVisibilityMode>;
1093
- setupChoiceIdsByOptionId: Record<string, readonly string[]>;
1094
- cardSetIdByCardId: Record<CardId, string>;
1095
- cardTypeByCardId: Record<CardId, string>;
1096
- cardSetIdsBySharedZoneId: Record<DeckId, readonly string[]>;
1097
- cardSetIdsByPlayerZoneId: Record<HandId, readonly string[]>;
1098
- };
1099
- type ManifestIds<PlayerId extends string, DeckId extends string, HandId extends string, CardId extends string, PhaseName extends string = string> = {
1100
- playerId: z.ZodType<PlayerId>;
1101
- phaseName: z.ZodType<PhaseName>;
1102
- boardLayout: AnySchema;
1103
- setupOptionId: AnySchema;
1104
- setupProfileId: AnySchema;
1105
- cardSetId: AnySchema;
1106
- cardType: AnySchema;
1107
- cardId: z.ZodType<CardId>;
1108
- deckId: z.ZodType<DeckId>;
1109
- handId: z.ZodType<HandId>;
1110
- sharedZoneId: AnySchema;
1111
- playerZoneId: AnySchema;
1112
- zoneId: AnySchema;
1113
- resourceId: AnySchema;
1114
- pieceTypeId: AnySchema;
1115
- pieceId: AnySchema;
1116
- dieId: AnySchema;
1117
- dieTypeId: AnySchema;
1118
- boardTypeId: AnySchema;
1119
- boardId: AnySchema;
1120
- boardBaseId: AnySchema;
1121
- boardContainerId: AnySchema;
1122
- relationTypeId: AnySchema;
1123
- edgeId: AnySchema;
1124
- edgeTypeId: AnySchema;
1125
- vertexId: AnySchema;
1126
- vertexTypeId: AnySchema;
1127
- spaceId: AnySchema;
1128
- spaceTypeId: AnySchema;
1129
- };
1130
- type ManifestDefaults<Table extends RuntimeTableRecord> = {
1131
- zones: (playerIds?: readonly string[]) => Table["zones"];
1132
- decks: (playerIds?: readonly string[]) => Table["decks"];
1133
- hands: (playerIds?: readonly string[]) => Table["hands"];
1134
- handVisibility: (playerIds?: readonly string[]) => Table["handVisibility"];
1135
- ownerOfCard: (playerIds?: readonly string[]) => Table["ownerOfCard"];
1136
- visibility: (playerIds?: readonly string[]) => Table["visibility"];
1137
- resources: (playerIds?: readonly string[]) => Table["resources"];
1138
- };
1139
- type StaticBoards<Table extends RuntimeTableRecord> = Pick<Table["boards"], "byId" | "hex" | "square">;
1140
- type SetupOptionChoiceMetadata = {
1141
- id: string;
1142
- label: string;
1143
- description?: string | null;
1144
- };
1145
- type SetupOptionMetadata = {
1146
- id: string;
1147
- name: string;
1148
- description?: string | null;
1149
- choices: readonly SetupOptionChoiceMetadata[];
1150
- };
1151
- type SetupProfileMetadata = {
1152
- id: string;
1153
- name: string;
1154
- description?: string | null;
1155
- optionValues?: Record<string, string> | null;
1156
- };
1157
- type ReducerManifestContract<Table extends RuntimeTableRecord, PhaseName extends string, PlayerId extends string, DeckId extends string, HandId extends string, CardId extends string> = {
1158
- literals: ManifestLiterals<PlayerId, DeckId, HandId, CardId, PhaseName>;
1159
- ids: ManifestIds<PlayerId, DeckId, HandId, CardId, PhaseName>;
1160
- defaults: ManifestDefaults<Table>;
1161
- staticBoards?: StaticBoards<Table>;
1162
- setupOptionsById: Record<string, SetupOptionMetadata>;
1163
- setupChoiceIdsByOptionId: Record<string, readonly string[]>;
1164
- setupProfilesById: Record<string, SetupProfileMetadata>;
1165
- tableSchema: z.ZodType<Table>;
1166
- runtimeSchema: AnySchema;
1167
- createGameStateSchema: (config: {
1168
- phaseNameSchema: AnySchema;
1169
- publicSchema: AnySchema;
1170
- privateSchema: AnySchema;
1171
- hiddenSchema: AnySchema;
1172
- phasesSchema: AnySchema;
1173
- }) => AnySchema;
1174
- };
1175
- type GeneratedManifestContractLike<Table extends RuntimeTableRecord = RuntimeTableRecord, PhaseName extends string = string, PlayerId extends string = string, DeckId extends string = string, HandId extends string = string, CardId extends string = string> = ReducerManifestContract<Table, PhaseName, PlayerId, DeckId, HandId, CardId>;
1176
- type ManifestContract<Table extends RuntimeTableRecord> = ReducerManifestContract<Table, string, PlayerIdOfTable<Table>, DeckIdOfTable<Table>, HandIdOfTable<Table>, CardIdOfTable<Table>>;
1177
- declare function markManifestScopedSchema<Schema extends z.ZodTypeAny>(schema: Schema): Schema & ManifestIdSchema<z.infer<Schema>>;
1178
- declare function createManifestStringLiteralSchema<Values extends readonly string[]>(values: Values): ManifestIdSchema<Values[number] extends never ? string : Values[number]>;
1179
- declare function assumeManifestSchema<Output>(schema: z.ZodTypeAny): z.ZodType<Output>;
1180
- declare function cloneManifestDefault<Value>(value: Value): Value;
1181
- declare function resolveManifestPlayerIds<PlayerId extends string>(manifestPlayerIds: readonly PlayerId[], playerIds: readonly string[] | undefined): readonly PlayerId[];
1182
- declare function createManifestRuntimeSchema<PhaseNameSchema extends z.ZodTypeAny, PlayerId extends string, SetupProfileId extends string>({ phaseNameSchema, playerIdSchema, setupProfileIdSchema, }: {
1183
- phaseNameSchema: PhaseNameSchema;
1184
- playerIdSchema: z.ZodType<PlayerId>;
1185
- setupProfileIdSchema: z.ZodType<SetupProfileId>;
1186
- }): z.ZodObject<{
1187
- prompts: z.ZodDefault<z.ZodArray<z.ZodObject<{
1188
- id: z.ZodString;
1189
- promptId: z.ZodString;
1190
- to: z.ZodType<PlayerId, unknown, z.core.$ZodTypeInternals<PlayerId, unknown>>;
1191
- title: z.ZodOptional<z.ZodString>;
1192
- payload: z.ZodOptional<z.ZodUnknown>;
1193
- options: z.ZodOptional<z.ZodArray<z.ZodObject<{
1194
- id: z.ZodString;
1195
- label: z.ZodString;
1196
- }, z.core.$strip>>>;
1197
- resume: z.ZodObject<{
1198
- id: z.ZodString;
1199
- data: z.ZodUnknown;
1200
- }, z.core.$strip>;
1201
- }, z.core.$strip>>>;
1202
- rng: z.ZodDefault<z.ZodObject<{
1203
- seed: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
1204
- cursor: z.ZodDefault<z.ZodNumber>;
1205
- trace: z.ZodDefault<z.ZodArray<z.ZodString>>;
1206
- }, z.core.$strip>>;
1207
- setup: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1208
- profileId: z.ZodType<SetupProfileId, unknown, z.core.$ZodTypeInternals<SetupProfileId, unknown>>;
1209
- optionValues: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>>;
1210
- }, z.core.$strip>>>;
1211
- simultaneous: z.ZodDefault<z.ZodObject<{
1212
- current: z.ZodNullable<z.ZodObject<{
1213
- phaseName: PhaseNameSchema;
1214
- actors: z.ZodArray<z.ZodType<PlayerId, unknown, z.core.$ZodTypeInternals<PlayerId, unknown>>>;
1215
- submissions: z.ZodRecord<z.ZodString, z.ZodObject<{
1216
- interactionId: z.ZodString;
1217
- params: z.ZodUnknown;
1218
- }, z.core.$strip>>;
1219
- }, z.core.$strip>>;
1220
- }, z.core.$strip>>;
1221
- lastTransition: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1222
- from: PhaseNameSchema;
1223
- to: PhaseNameSchema;
1224
- }, z.core.$strip>>>;
1225
- nextInstanceId: z.ZodDefault<z.ZodNumber>;
1226
- }, z.core.$strip>;
1227
- declare function createManifestGameStateSchema<Table extends RuntimeTableRecord, PhaseNameSchema extends z.ZodTypeAny, PublicSchema extends z.ZodTypeAny, PrivateSchema extends z.ZodTypeAny, HiddenSchema extends z.ZodTypeAny, PhasesSchema extends z.ZodTypeAny, PlayerId extends string, SetupProfileId extends string>({ tableSchema, playerIdSchema, setupProfileIdSchema, phaseNameSchema, publicSchema, privateSchema, hiddenSchema, phasesSchema, }: {
1228
- tableSchema: z.ZodType<Table>;
1229
- playerIdSchema: z.ZodType<PlayerId>;
1230
- setupProfileIdSchema: z.ZodType<SetupProfileId>;
1231
- phaseNameSchema: PhaseNameSchema;
1232
- publicSchema: PublicSchema;
1233
- privateSchema: PrivateSchema;
1234
- hiddenSchema: HiddenSchema;
1235
- phasesSchema: PhasesSchema;
1236
- }): z.ZodObject<{
1237
- table: z.ZodType<Table, unknown, z.core.$ZodTypeInternals<Table, unknown>>;
1238
- public: PublicSchema;
1239
- private: z.ZodRecord<z.ZodString, PrivateSchema>;
1240
- hidden: HiddenSchema;
1241
- flow: z.ZodObject<{
1242
- currentPhase: PhaseNameSchema;
1243
- turn: z.ZodNumber;
1244
- round: z.ZodNumber;
1245
- activePlayers: z.ZodArray<z.ZodType<PlayerId, unknown, z.core.$ZodTypeInternals<PlayerId, unknown>>>;
1246
- }, z.core.$strip>;
1247
- phase: PhasesSchema;
1248
- runtime: z.ZodObject<{
1249
- prompts: z.ZodDefault<z.ZodArray<z.ZodObject<{
1250
- id: z.ZodString;
1251
- promptId: z.ZodString;
1252
- to: z.ZodType<PlayerId, unknown, z.core.$ZodTypeInternals<PlayerId, unknown>>;
1253
- title: z.ZodOptional<z.ZodString>;
1254
- payload: z.ZodOptional<z.ZodUnknown>;
1255
- options: z.ZodOptional<z.ZodArray<z.ZodObject<{
1256
- id: z.ZodString;
1257
- label: z.ZodString;
1258
- }, z.core.$strip>>>;
1259
- resume: z.ZodObject<{
1260
- id: z.ZodString;
1261
- data: z.ZodUnknown;
1262
- }, z.core.$strip>;
1263
- }, z.core.$strip>>>;
1264
- rng: z.ZodDefault<z.ZodObject<{
1265
- seed: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
1266
- cursor: z.ZodDefault<z.ZodNumber>;
1267
- trace: z.ZodDefault<z.ZodArray<z.ZodString>>;
1268
- }, z.core.$strip>>;
1269
- setup: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1270
- profileId: z.ZodType<SetupProfileId, unknown, z.core.$ZodTypeInternals<SetupProfileId, unknown>>;
1271
- optionValues: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>>;
1272
- }, z.core.$strip>>>;
1273
- simultaneous: z.ZodDefault<z.ZodObject<{
1274
- current: z.ZodNullable<z.ZodObject<{
1275
- phaseName: PhaseNameSchema;
1276
- actors: z.ZodArray<z.ZodType<PlayerId, unknown, z.core.$ZodTypeInternals<PlayerId, unknown>>>;
1277
- submissions: z.ZodRecord<z.ZodString, z.ZodObject<{
1278
- interactionId: z.ZodString;
1279
- params: z.ZodUnknown;
1280
- }, z.core.$strip>>;
1281
- }, z.core.$strip>>;
1282
- }, z.core.$strip>>;
1283
- lastTransition: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1284
- from: PhaseNameSchema;
1285
- to: PhaseNameSchema;
1286
- }, z.core.$strip>>>;
1287
- nextInstanceId: z.ZodDefault<z.ZodNumber>;
1288
- }, z.core.$strip>;
1289
- }, z.core.$strip>;
1290
- type StateDefinition<PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>> = {
1291
- public: PublicSchema;
1292
- private: PrivateSchema;
1293
- hidden: HiddenSchema;
1294
- };
1295
- type InitContext<Table extends RuntimeTableRecord, Manifest extends ReducerManifestContract<Table, string, string, string, string, string> = ManifestContract<Table>> = {
1296
- manifest: Manifest;
1297
- table: Table;
1298
- playerIds: PlayerIdOfTable<Table>[];
1299
- rngSeed?: number | null;
1300
- setup: SetupSelectionOfManifest<Manifest> | null;
1301
- q: TableQueriesOfState<{
1302
- table: Table;
1303
- }>;
1304
- };
1305
- type SetupBootstrapSharedZoneRef<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = {
1306
- type: "sharedZone";
1307
- zoneId: SharedZoneIdOfManifest<Manifest>;
1308
- };
1309
- type SetupBootstrapPerPlayerZoneRef<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = {
1310
- type: "playerZone";
1311
- zoneId: PlayerZoneIdOfManifest<Manifest>;
1312
- playerId: PlayerIdOfManifest<Manifest>;
1313
- };
1314
- type SetupBootstrapSharedBoardContainerRef<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = {
1315
- type: "sharedBoardContainer";
1316
- boardId: BoardBaseIdOfManifest<Manifest>;
1317
- containerId: BoardContainerIdOfManifest<Manifest>;
1318
- };
1319
- type SetupBootstrapPerPlayerBoardContainerRef<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = {
1320
- type: "playerBoardContainer";
1321
- boardId: BoardBaseIdOfManifest<Manifest>;
1322
- playerId: PlayerIdOfManifest<Manifest>;
1323
- containerId: BoardContainerIdOfManifest<Manifest>;
1324
- };
1325
- type SetupBootstrapSharedBoardSpaceRef<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = {
1326
- type: "sharedBoardSpace";
1327
- boardId: BoardBaseIdOfManifest<Manifest>;
1328
- spaceId: SpaceIdOfManifest<Manifest>;
1329
- };
1330
- type SetupBootstrapPerPlayerBoardSpaceRef<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = {
1331
- type: "playerBoardSpace";
1332
- boardId: BoardBaseIdOfManifest<Manifest>;
1333
- playerId: PlayerIdOfManifest<Manifest>;
1334
- spaceId: SpaceIdOfManifest<Manifest>;
1335
- };
1336
- type SetupBootstrapContainerRef<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = SetupBootstrapSharedZoneRef<Manifest> | SetupBootstrapPerPlayerZoneRef<Manifest> | SetupBootstrapSharedBoardContainerRef<Manifest> | SetupBootstrapPerPlayerBoardContainerRef<Manifest>;
1337
- type SetupBootstrapDestinationRef<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = SetupBootstrapContainerRef<Manifest> | SetupBootstrapSharedBoardSpaceRef<Manifest> | SetupBootstrapPerPlayerBoardSpaceRef<Manifest>;
1338
- type SetupBootstrapPerPlayerContainerTemplateRef<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = {
1339
- type: "playerZone";
1340
- zoneId: PlayerZoneIdOfManifest<Manifest>;
1341
- } | {
1342
- type: "playerBoardContainer";
1343
- boardId: BoardBaseIdOfManifest<Manifest>;
1344
- containerId: BoardContainerIdOfManifest<Manifest>;
1345
- };
1346
- type SetupBootstrapStep<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = {
1347
- type: "shuffle";
1348
- container: SetupBootstrapContainerRef<Manifest>;
1349
- } | {
1350
- type: "move";
1351
- from: SetupBootstrapContainerRef<Manifest>;
1352
- to: SetupBootstrapDestinationRef<Manifest>;
1353
- count?: number;
1354
- componentIds?: readonly (CardIdOfManifest<Manifest> | PieceIdOfManifest<Manifest> | DieIdOfManifest<Manifest>)[];
1355
- } | {
1356
- type: "deal";
1357
- from: SetupBootstrapSharedZoneRef<Manifest> | SetupBootstrapSharedBoardContainerRef<Manifest>;
1358
- to: SetupBootstrapPerPlayerContainerTemplateRef<Manifest>;
1359
- count: number;
1360
- playerIds?: readonly PlayerIdOfManifest<Manifest>[];
1361
- };
1362
- type SetupProfileDefinition<PhaseName extends string = string, Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike> = {
1363
- initialPhase?: PhaseName;
1364
- bootstrap?: readonly SetupBootstrapStep<Manifest>[];
1365
- };
1366
-
1367
- type FlowInstruction<PhaseName extends string> = {
1368
- kind: "flow.transition";
1369
- to: PhaseName;
1370
- };
1371
- type EngineRollDieInstruction = {
1372
- kind: "engine.rollDie";
1373
- dieId: string;
1374
- continuation?: AnyContinuationToken;
1375
- };
1376
- type EngineShuffleSharedZoneInstruction<DeckId extends string> = {
1377
- kind: "engine.shuffleSharedZone";
1378
- zoneId: DeckId;
1379
- continuation?: AnyContinuationToken;
1380
- };
1381
- type EngineShufflePlayerZoneInstruction<PlayerZoneId extends string, PlayerId extends string> = {
1382
- kind: "engine.shufflePlayerZone";
1383
- zoneId: PlayerZoneId;
1384
- playerId: PlayerId;
1385
- continuation?: AnyContinuationToken;
1386
- };
1387
- type EngineInstruction<DeckId extends string, PlayerZoneId extends string = string, PlayerId extends string = string> = EngineRollDieInstruction | EngineShuffleSharedZoneInstruction<DeckId> | EngineShufflePlayerZoneInstruction<PlayerZoneId, PlayerId>;
1388
- type RuntimeInstruction<PhaseName extends string, DeckId extends string, PlayerZoneId extends string = string, PlayerId extends string = string> = FlowInstruction<PhaseName> | EngineInstruction<DeckId, PlayerZoneId, PlayerId>;
1389
- type RuntimeInstructionForState<State> = RuntimeInstruction<PhaseNameOfState<State>, DeckIdOfState<State>, PlayerZoneIdOfState<State>, PlayerIdOfState<State>>;
1390
-
1391
- type ContinuationToken<Data = RuntimePayload, ContinuationId extends string = string, Response = RuntimePayload> = {
1392
- id: ContinuationId;
1393
- data: Data;
1394
- readonly __responseType?: Response;
1395
- };
1396
- type ContinuationResponseOf<Token> = Token extends ContinuationToken<any, string, infer Response> ? Response : never;
1397
- type AnyContinuationToken = ContinuationToken<RuntimePayload, string, RuntimePayload>;
1398
- /**
1399
- * Declarative choice option. Retained as the shape used by prompt-kind
1400
- * interactions' `options` field (see `InteractionSpec.options` in
1401
- * `model/spec.ts`). Independent of any specific prompt authoring API.
1402
- */
1403
- type ChoiceOption<OptionId extends string = string> = {
1404
- id: OptionId;
1405
- label: string;
1406
- };
1407
- type RuntimePhaseState = object;
1408
- type PhaseAccessor<PhaseStates extends Record<string, object>, CurrentPhase extends keyof PhaseStates & string = keyof PhaseStates & string> = {
1409
- get<PhaseName extends keyof PhaseStates & string>(phaseName: PhaseName): CurrentPhase extends PhaseName ? PhaseStates[PhaseName] : PhaseStates[PhaseName] | null;
1410
- };
1411
- type FlowState<PhaseName extends string, PlayerId extends string> = {
1412
- currentPhase: PhaseName;
1413
- turn: number;
1414
- round: number;
1415
- activePlayers: PlayerId[];
1416
- };
1417
- type RuntimeRngState = {
1418
- seed?: number | null;
1419
- cursor: number;
1420
- trace: string[];
1421
- };
1422
- type RuntimeSimultaneousSubmission = {
1423
- interactionId: string;
1424
- params: RuntimePayload;
1425
- };
1426
- type RuntimeSimultaneousState<PhaseName extends string, PlayerId extends string> = {
1427
- current: {
1428
- phaseName: PhaseName;
1429
- actors: PlayerId[];
1430
- submissions: Partial<Record<PlayerId, RuntimeSimultaneousSubmission>>;
1431
- } | null;
1432
- };
1433
- /**
1434
- * Marker tag attached by `defineEffect` to every effect spec. `fx.effect`
1435
- * uses `type` to dispatch to the right wire-effect builder.
1436
- */
1437
- type EffectTypeTag = "rollDie" | "shuffleSharedZone" | "shufflePlayerZone";
1438
- /**
1439
- * Structural shape of the objects produced by `defineEffect`, as seen by
1440
- * the `fx.effect` dispatcher. The public, per-type effect definitions live
1441
- * in `model/spec.ts`.
1442
- */
1443
- type EffectSpecLike<ContextSchema extends AnySchema = AnySchema> = {
1444
- type: EffectTypeTag;
1445
- id: string;
1446
- contextSchema?: ContextSchema;
1447
- /**
1448
- * Opaque authoring-time continuation callable. The runtime only needs its
1449
- * `id`; the heterogeneously-typed `(data) => ...` signature is erased
1450
- * here. The `data` parameter is typed as `never` so that this structural
1451
- * upper bound is assignable-from every concrete per-effect continuation
1452
- * (function parameters are contravariant — a specific `(data: T) => R`
1453
- * is assignable to `(data: X) => R` only when `X <: T`, and `never <: T`
1454
- * holds for every `T`).
1455
- */
1456
- __continuation?: ((data: never) => unknown) & {
1457
- id: string;
1458
- };
1459
- };
1460
- /**
1461
- * Options accepted by `fx.effect(effect, options)`, specialized by
1462
- * `effect.type`.
1463
- */
1464
- type EffectContextValue<Effect extends EffectSpecLike> = NonNullable<Effect["contextSchema"]> extends AnySchema ? z.infer<NonNullable<Effect["contextSchema"]>> : undefined;
1465
- type EffectInvokeOptions<Effect extends EffectSpecLike, State extends {
1466
- table: RuntimeTableRecord;
1467
- flow: {
1468
- currentPhase: string;
1469
- };
1470
- }> = Effect["type"] extends "rollDie" ? {
1471
- dieId: StringKeyOf<TableOfState<State>["dice"]>;
1472
- context?: EffectContextValue<Effect>;
1473
- } : Effect["type"] extends "shuffleSharedZone" ? {
1474
- zoneId: DeckIdOfState<State>;
1475
- context?: EffectContextValue<Effect>;
1476
- } : Effect["type"] extends "shufflePlayerZone" ? {
1477
- zoneId: PlayerZoneIdOfState<State>;
1478
- playerId: PlayerIdOfState<State>;
1479
- context?: EffectContextValue<Effect>;
1480
- } : never;
1481
- type EffectInstructionForState<Effect extends EffectSpecLike, State extends {
1482
- table: RuntimeTableRecord;
1483
- flow: {
1484
- currentPhase: string;
1485
- };
1486
- }> = Effect["type"] extends "rollDie" ? EngineRollDieInstruction : Effect["type"] extends "shuffleSharedZone" ? EngineShuffleSharedZoneInstruction<DeckIdOfState<State>> : Effect["type"] extends "shufflePlayerZone" ? EngineShufflePlayerZoneInstruction<PlayerZoneIdOfState<State>, PlayerIdOfState<State>> : never;
1487
- type ReducerFx<State extends {
1488
- table: RuntimeTableRecord;
1489
- flow: {
1490
- currentPhase: string;
1491
- };
1492
- }> = {
1493
- transition: <To extends PhaseNameOfState<State>>(to: To) => FlowInstruction<To>;
1494
- /**
1495
- * Invoke an engine-side resumable effect authored via `defineEffect`.
1496
- * The returned runtime instruction is consumed by the engine; if the effect
1497
- * has a `reduce`, its continuation is delivered back as a typed input.
1498
- */
1499
- effect: <Effect extends EffectSpecLike>(effect: Effect, options: EffectInvokeOptions<Effect, State>) => EffectInstructionForState<Effect, State>;
1500
- };
1501
- type RuntimeState<PhaseName extends string, PlayerId extends string, Setup extends RuntimeSetupSelection = RuntimeSetupSelection> = {
1502
- rng: RuntimeRngState;
1503
- setup: Setup | null;
1504
- simultaneous: RuntimeSimultaneousState<PhaseName, PlayerId>;
1505
- lastTransition: {
1506
- from: PhaseName;
1507
- to: PhaseName;
1508
- } | null;
1509
- };
1510
- type ReducerRuntimeStateForState<State extends {
1511
- table: RuntimeTableRecord;
1512
- flow: {
1513
- currentPhase: string;
1514
- };
1515
- }, Setup extends RuntimeSetupSelection = RuntimeSetupSelection> = RuntimeState<PhaseNameOfState<State>, PlayerIdOfState<State>, Setup>;
1516
- type ReducerGameState<Table extends RuntimeTableRecord, PublicState extends object, PrivateState extends object, HiddenState extends object, PhaseState extends RuntimePhaseState, PhaseName extends string, PhaseStates extends Record<PhaseName, object> = Record<PhaseName, PhaseState>> = {
1517
- table: Table;
1518
- publicState: PublicState;
1519
- privateState: Record<PlayerIdOfTable<Table>, PrivateState>;
1520
- hiddenState: HiddenState;
1521
- flow: FlowState<PhaseName, PlayerIdOfTable<Table>>;
1522
- phase: PhaseState & PhaseAccessor<PhaseStates>;
1523
- };
1524
- type ReducerValidationResult = {
1525
- valid: true;
1526
- } | {
1527
- valid: false;
1528
- errorCode: string;
1529
- message?: string;
1530
- };
1531
- type ReducerReject = {
1532
- type: "reject";
1533
- errorCode: string;
1534
- message?: string;
1535
- };
1536
- type ReducerAccept<State> = {
1537
- type: "accept";
1538
- state: State;
1539
- instructions?: RuntimeInstructionForState<State>[];
1540
- };
1541
- type ReducerResult<State> = ReducerAccept<State> | ReducerReject;
1542
-
1543
- /**
1544
- * State composition primitives.
1545
- *
1546
- * `pipe` threads a seed state through a sequence of `State -> State`
1547
- * transformations, left to right. It is the preferred way to compose curried
1548
- * writers (the `ops.*` namespace) in reducers:
1549
- *
1550
- * return accept(
1551
- * pipe(state,
1552
- * ops.spendPlayerResources({ playerId, resources: cost }),
1553
- * ops.placePieceOnVertex({ boardId, vertexId, pieceId, ownerId: playerId }),
1554
- * ),
1555
- * );
1556
- */
1557
- /**
1558
- * A state-preserving transformation.
1559
- *
1560
- * `Op<State>` is polymorphic in the exact input subtype — given a state `S`
1561
- * that extends `State`, it returns the same `S`. This lets curried writers
1562
- * from `ops.*` and author-written helpers thread through phase-scoped `pipe`
1563
- * calls without losing the narrowed phase state type.
1564
- */
1565
- type Op<State> = <S extends State>(state: S) => S;
1566
- declare function pipe<State>(state: State, ...ops: ReadonlyArray<Op<NoInfer<State>>>): State;
1567
-
1568
- /**
1569
- * Curried state writers for use with `pipe`.
1570
- *
1571
- * Each entry in the returned `ops` namespace is a curried transformation
1572
- * `(args) => (state) => state` that can be composed with `pipe`:
1573
- *
1574
- * const ops = createReducerOps<GameState>();
1575
- *
1576
- * return accept(
1577
- * pipe(state,
1578
- * ops.setActivePlayers([playerId]),
1579
- * ops.moveCardFromPlayerZoneToSharedZone({
1580
- * playerId,
1581
- * fromZoneId: "things-hand",
1582
- * toZoneId: "ring-1",
1583
- * cardId: "a-dog",
1584
- * }),
1585
- * ),
1586
- * );
1587
- *
1588
- * The factory binds all ops to a specific `State` type so that ID arguments
1589
- * (deck ids, card ids, etc.) are checked against the manifest-derived table
1590
- * shape of the game.
1591
- */
1592
-
1593
- /**
1594
- * Minimum shape required for any state targeted by reducer ops.
1595
- *
1596
- * All curried writers operate on a game state with a `table` field.
1597
- */
1598
- type ReducerStateBase = {
1599
- table: RuntimeTableRecord;
1600
- };
1601
- type PipeTable<State extends ReducerStateBase> = TableOfState<State>;
1602
- /**
1603
- * A shallow patch for a slice of state. Either a partial object to merge
1604
- * over the previous value, or a functional updater `(prev) => next`.
1605
- */
1606
- type StatePatch<T> = Partial<T> | ((prev: T) => T);
1607
- /**
1608
- * Curried writer namespace for a specific game state type.
1609
- *
1610
- * Created via {@link createReducerOps}.
1611
- */
1612
- interface ReducerOps<State extends ReducerStateBase> {
1613
- /** Set the list of players whose turn is currently active. */
1614
- setActivePlayers(activePlayers: ReadonlyArray<PlayerIdOfState<State>>): Op<State>;
1615
- /**
1616
- * Advance `flow.activePlayers` to the single next seat in `playerOrder`.
1617
- *
1618
- * Uses `state.flow.activePlayers[0]` as the current seat (or the first
1619
- * seat in `playerOrder` when `activePlayers` is empty) and sets
1620
- * `activePlayers` to `[q.player.nextInOrder(current)]`. No-op when the
1621
- * player order is empty.
1622
- */
1623
- advanceActivePlayer(): Op<State>;
1624
- /**
1625
- * Update the current phase's local state.
1626
- *
1627
- * Accepts either a `Partial<PhaseState>` which is shallow-merged into the
1628
- * previous value, or a functional updater `(prev) => next` which must
1629
- * return a complete `PhaseState`.
1630
- */
1631
- patchPhaseState(patch: StatePatch<PhaseStateOfState<State>>): Op<State>;
1632
- /**
1633
- * Update `state.publicState`.
1634
- *
1635
- * Accepts either a `Partial<PublicState>` which is shallow-merged into the
1636
- * previous value, or a functional updater `(prev) => next` which must
1637
- * return a complete `PublicState`.
1638
- */
1639
- patchPublicState(patch: StatePatch<PublicStateOfState<State>>): Op<State>;
1640
- /**
1641
- * Update `state.hiddenState`.
1642
- *
1643
- * Accepts either a `Partial<HiddenState>` or a functional updater.
1644
- */
1645
- patchHiddenState(patch: StatePatch<HiddenStateOfState<State>>): Op<State>;
1646
- /**
1647
- * Update a single player's entry in `state.privateState`.
1648
- *
1649
- * Accepts either a `Partial<PrivateState>` or a functional updater.
1650
- */
1651
- patchPlayerPrivateState(args: {
1652
- playerId: PlayerIdOfState<State>;
1653
- patch: StatePatch<PrivateStateOfState<State>>;
1654
- }): Op<State>;
1655
- /**
1656
- * Append a card to a shared zone (deck). Defaults to placing the card at the
1657
- * bottom; pass `position: "top"` for top-of-deck placement (e.g. Bureaucrat-style).
1658
- */
1659
- addCardToSharedZone<DeckId extends SharedZoneIdOfTable<PipeTable<State>>>(args: {
1660
- deckId: DeckId;
1661
- cardId: DeckCardsOfTable<PipeTable<State>, DeckId>[number];
1662
- playedBy?: PlayerIdOfTable<PipeTable<State>> | null;
1663
- position?: "top" | "bottom";
1664
- }): Op<State>;
1665
- /** Remove a card from a shared zone (deck). */
1666
- removeCardFromSharedZone<DeckId extends DeckIdOfTable<PipeTable<State>>>(args: {
1667
- deckId: DeckId;
1668
- cardId: DeckCardsOfTable<PipeTable<State>, DeckId>[number];
1669
- }): Op<State>;
1670
- /**
1671
- * Move a card between two shared zones (decks). Defaults to placing the card
1672
- * at the bottom of the destination; pass `position: "top"` for top placement.
1673
- */
1674
- moveCardBetweenSharedZones<FromZoneId extends SharedZoneIdOfTable<PipeTable<State>>, ToZoneId extends SharedZoneIdOfTable<PipeTable<State>>>(args: {
1675
- fromZoneId: FromZoneId;
1676
- toZoneId: ToZoneId;
1677
- cardId: DeckCardsOfTable<PipeTable<State>, FromZoneId>[number];
1678
- playedBy?: PlayerIdOfTable<PipeTable<State>> | null;
1679
- position?: "top" | "bottom";
1680
- }): Op<State>;
1681
- /**
1682
- * Draw the top `count` cards from one perPlayer zone into another for the
1683
- * same player (e.g. deck → hand at the start of a turn). Companion to
1684
- * {@link dealCardsToPlayerZone} for the perPlayer → perPlayer case. Stops
1685
- * silently if the source runs out before `count` is reached.
1686
- */
1687
- dealCardsBetweenPlayerZones<FromZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, ToZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
1688
- playerId: PlayerId;
1689
- fromZoneId: FromZoneId;
1690
- toZoneId: ToZoneId;
1691
- count: number;
1692
- }): Op<State>;
1693
- /**
1694
- * Move a card between two perPlayer zones owned by the same player (e.g.
1695
- * hand → in-play → discard). Owner is preserved; visibility is recomputed
1696
- * from the destination zone.
1697
- */
1698
- moveCardBetweenPlayerZones<FromZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, ToZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
1699
- playerId: PlayerId;
1700
- fromZoneId: FromZoneId;
1701
- toZoneId: ToZoneId;
1702
- cardId: CompatibleCardIdForTwoPlayerZones<PipeTable<State>, FromZoneId, ToZoneId>;
1703
- position?: "top" | "bottom";
1704
- }): Op<State>;
1705
- /**
1706
- * Move a card from a player zone (hand) to a shared zone (deck). Defaults to
1707
- * placing the card at the bottom; pass `position: "top"` to topdeck.
1708
- */
1709
- moveCardFromPlayerZoneToSharedZone<FromZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, ToZoneId extends SharedZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
1710
- playerId: PlayerId;
1711
- fromZoneId: FromZoneId;
1712
- toZoneId: ToZoneId;
1713
- cardId: CompatibleCardIdForHandAndDeck<PipeTable<State>, FromZoneId, ToZoneId>;
1714
- playedBy?: PlayerIdOfTable<PipeTable<State>> | null;
1715
- position?: "top" | "bottom";
1716
- }): Op<State>;
1717
- /**
1718
- * Move a named card from a shared zone (supply pile, deck) to a perPlayer
1719
- * zone (e.g. discard). The "gain" verb in deck-builders. Distinct from
1720
- * {@link dealCardsToPlayerZone}, which draws unspecified top-N cards from a
1721
- * deck. Owner flips to the receiving player; visibility is recomputed.
1722
- */
1723
- moveCardFromSharedZoneToPlayerZone<FromZoneId extends SharedZoneIdOfTable<PipeTable<State>>, ToZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
1724
- playerId: PlayerId;
1725
- fromZoneId: FromZoneId;
1726
- toZoneId: ToZoneId;
1727
- cardId: CompatibleCardIdForHandAndDeck<PipeTable<State>, ToZoneId, FromZoneId>;
1728
- position?: "top" | "bottom";
1729
- }): Op<State>;
1730
- /**
1731
- * Deal the top `count` cards from a shared deck into a player's hand zone.
1732
- *
1733
- * This op does not consume RNG. If the deck needs to be random, shuffle it
1734
- * first with `fx.shuffleSharedZone(...)`, then deal from the shuffled deck
1735
- * inside the same reducer via this op.
1736
- */
1737
- dealCardsToPlayerZone<FromZoneId extends DeckIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>, ToZoneId extends CompatibleHandIdForDeck<PipeTable<State>, FromZoneId> & HandIdOfTable<PipeTable<State>>>(args: {
1738
- fromZoneId: FromZoneId;
1739
- playerId: PlayerId;
1740
- toZoneId: ToZoneId;
1741
- count: number;
1742
- }): Op<State>;
1743
- /**
1744
- * Atomically rotate cards in a per-player zone around the table.
1745
- *
1746
- * Defaults to rotating every card currently in `zoneId` for every player in
1747
- * turn order. Pass `players` to use a smaller explicit order, or
1748
- * `cardIdsByPlayer` to rotate only selected cards such as Hearts passes.
1749
- */
1750
- rotatePlayerZone<ZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
1751
- zoneId: ZoneId;
1752
- direction: "left" | "right";
1753
- players?: readonly PlayerId[];
1754
- cardIdsByPlayer?: Partial<Record<PlayerId, readonly CardIdOfTable<PipeTable<State>>[]>>;
1755
- position?: "top" | "bottom";
1756
- }): Op<State>;
1757
- /** Move a component onto a board space. */
1758
- moveComponentToSpace<BoardId extends BoardIdOfTable<PipeTable<State>>, SpaceId extends SpaceIdOfTable<PipeTable<State>, BoardId>, ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
1759
- componentId: ComponentId;
1760
- boardId: BoardId;
1761
- spaceId: SpaceId;
1762
- }): Op<State>;
1763
- /** Move a component into a board container. */
1764
- moveComponentToContainer<BoardId extends BoardIdOfTable<PipeTable<State>>, ContainerId extends BoardContainerIdOfTable<PipeTable<State>, BoardId>, ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
1765
- componentId: ComponentId;
1766
- boardId: BoardId;
1767
- containerId: ContainerId;
1768
- }): Op<State>;
1769
- /** Move a component onto a tiled board edge. */
1770
- moveComponentToEdge<BoardId extends TiledBoardIdOfTable<PipeTable<State>>, EdgeId extends TiledEdgeIdOfTable<PipeTable<State>, BoardId>, ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
1771
- componentId: ComponentId;
1772
- boardId: BoardId;
1773
- edgeId: EdgeId;
1774
- }): Op<State>;
1775
- /** Move a component onto a tiled board vertex. */
1776
- moveComponentToVertex<BoardId extends TiledBoardIdOfTable<PipeTable<State>>, VertexId extends TiledVertexIdOfTable<PipeTable<State>, BoardId>, ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
1777
- componentId: ComponentId;
1778
- boardId: BoardId;
1779
- vertexId: VertexId;
1780
- }): Op<State>;
1781
- /** Move a component back to the detached pool. */
1782
- moveComponentToDetached<ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
1783
- componentId: ComponentId;
1784
- }): Op<State>;
1785
- /**
1786
- * Credit the specified resources to a player.
1787
- *
1788
- * Amounts must be non-negative; use {@link spendResources} for deductions
1789
- * so that affordability is checked explicitly.
1790
- *
1791
- * pipe(
1792
- * state,
1793
- * ops.addResources({ playerId, amounts: { wood: 1, brick: 1 } }),
1794
- * )
1795
- */
1796
- addResources(args: {
1797
- playerId: PlayerIdOfTable<PipeTable<State>>;
1798
- amounts: ResourceAmountsOfTable<PipeTable<State>>;
1799
- }): Op<State>;
1800
- /**
1801
- * Debit the specified resources from a player.
1802
- *
1803
- * Throws when the player cannot afford the full cost — gate with
1804
- * `q.player.canAfford(...)` in your `validate` step before invoking.
1805
- *
1806
- * pipe(
1807
- * state,
1808
- * ops.spendResources({ playerId, amounts: COST_DEV_CARD }),
1809
- * ops.dealCardsToPlayerZone({ ... }),
1810
- * )
1811
- */
1812
- spendResources(args: {
1813
- playerId: PlayerIdOfTable<PipeTable<State>>;
1814
- amounts: ResourceAmountsOfTable<PipeTable<State>>;
1815
- }): Op<State>;
1816
- /**
1817
- * Transfer the specified resources from one player to another.
1818
- *
1819
- * Throws when the source cannot afford the full amount. On success the
1820
- * destination gains exactly what the source loses.
1821
- */
1822
- transferResources(args: {
1823
- fromPlayerId: PlayerIdOfTable<PipeTable<State>>;
1824
- toPlayerId: PlayerIdOfTable<PipeTable<State>>;
1825
- amounts: ResourceAmountsOfTable<PipeTable<State>>;
1826
- }): Op<State>;
1827
- /**
1828
- * Overwrite a single resource balance for a player. Prefer
1829
- * {@link addResources} / {@link spendResources} — use this only when the
1830
- * new balance is an absolute (e.g. scripted setup).
1831
- */
1832
- setResource(args: {
1833
- playerId: PlayerIdOfTable<PipeTable<State>>;
1834
- resourceId: ResourceIdOfTable<PipeTable<State>>;
1835
- amount: number;
1836
- }): Op<State>;
1837
- }
1838
- /**
1839
- * Create the `ops.*` namespace specialised to a game state.
1840
- *
1841
- * Call this once (typically in a shared reducer-support module) and reuse the
1842
- * resulting object across phases:
1843
- *
1844
- * export const ops = createReducerOps<GameState>();
1845
- */
1846
- declare function createReducerOps<State extends ReducerStateBase>(): ReducerOps<State>;
1847
-
1848
- type RotatePlayerZoneArgs<State extends {
1849
- table: RuntimeTableRecord;
1850
- }, ZoneId extends PlayerZoneIdOfTable<TableOfState<State>> = PlayerZoneIdOfTable<TableOfState<State>>, PlayerId extends PlayerIdOfTable<TableOfState<State>> = PlayerIdOfTable<TableOfState<State>>> = {
1851
- zoneId: ZoneId;
1852
- direction: "left" | "right";
1853
- players?: readonly PlayerId[];
1854
- cardIdsByPlayer?: Partial<Record<PlayerId, readonly CardIdOfTable<TableOfState<State>>[]>>;
1855
- position?: "top" | "bottom";
1856
- };
1857
- type TransactionMethods<State extends {
1858
- table: RuntimeTableRecord;
1859
- }> = {
1860
- [Key in Exclude<keyof ReducerOps<State>, "moveComponentToSpace">]: ReducerOps<State>[Key] extends (...args: infer Args) => Op<State> ? (...args: Args) => State : never;
1861
- } & {
1862
- moveComponentToSpace<BoardId extends BoardIdOfTable<TableOfState<State>>, SpaceId extends SpaceIdOfTable<TableOfState<State>, BoardId>, ComponentId extends ComponentIdOfTable<TableOfState<State>>>(args: {
1863
- componentId: ComponentId;
1864
- boardId: BoardId;
1865
- spaceId: SpaceId;
1866
- }): State;
1867
- };
1868
- type ReducerTransaction<State extends {
1869
- table: RuntimeTableRecord;
1870
- }> = TransactionMethods<State> & {
1871
- readonly state: State;
1872
- readonly q: TableQueriesOfState<State>;
1873
- apply(op: Op<State>): State;
1874
- rotatePlayerZone<ZoneId extends PlayerZoneIdOfTable<TableOfState<State>>, PlayerId extends PlayerIdOfTable<TableOfState<State>>>(args: RotatePlayerZoneArgs<State, ZoneId, PlayerId>): State;
1875
- };
1876
- type ReducerEdit<State extends {
1877
- table: RuntimeTableRecord;
1878
- }> = <DraftState extends State>(state: DraftState) => ReducerTransaction<DraftState>;
1879
- declare function createReducerTransaction<State extends {
1880
- table: RuntimeTableRecord;
1881
- }>(initialState: State, ops?: ReducerOps<State>): ReducerTransaction<State>;
1882
- declare function createReducerEdit<State extends {
1883
- table: RuntimeTableRecord;
1884
- }>(ops?: ReducerOps<State>): ReducerEdit<State>;
1885
-
1886
- type ReducerGameContract<Table extends RuntimeTableRecord, Manifest extends ReducerManifestContract<Table, string, string, string, string, string>, PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>, Phases extends Record<string, SchemaLike<object>>> = {
1887
- manifest: Manifest;
1888
- state: StateDefinition<PublicSchema, PrivateSchema, HiddenSchema>;
1889
- phases: Phases;
1890
- /** Derived from `phases`; retained as an internal runtime convenience. */
1891
- phaseNames: readonly string[];
1892
- };
1893
- type BaseGameStateOfContract<Contract> = ReducerGameState<TableOfManifest<ManifestContractOf<Contract>>, z.infer<PublicSchemaOfContract<Contract>>, z.infer<PrivateSchemaOfContract<Contract>>, z.infer<HiddenSchemaOfContract<Contract>>, PhaseStateMapOfContract<Contract>[PhaseNameOfContract<Contract>], PhaseNameOfContract<Contract>, PhaseStateMapOfContract<Contract>>;
1894
- /**
1895
- * Heterogeneous phase map for a contract. Each phase carries its own local
1896
- * `PhaseStateSchema` plus authoring-time Actions/Flows/Interactions/
1897
- * Stages/Zones maps. The registries are bound to the contract's base state +
1898
- * manifest so the runtime can iterate them through a single index type
1899
- * without reaching for `any`.
1900
- */
1901
- type PhaseMapOf<Contract> = {
1902
- [Name in PhaseNameOfContract<Contract>]: PhaseDefinition<SchemaLike<object>, BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>, Record<string, InputCollector>, EffectMap<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>>, InteractionMap<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>>, StageMap<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>>, PhaseZoneList<ManifestContractOf<Contract>>, CardActionMap<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>>>;
1903
- };
1904
- type PhaseStateOfDefinitions<Definitions extends Record<string, PhaseDefinition<SchemaLike<object>, any, any, Record<string, InputCollector>, EffectMap<any, any>, InteractionMap<any, any>, StageMap<any, any>, PhaseZoneList<any>, CardActionMap<any, any>>>> = {
1905
- [Name in keyof Definitions & string]: Definitions[Name] extends PhaseDefinition<infer PhaseStateSchema, infer _State, infer _Manifest> ? z.infer<PhaseStateSchema> : never;
1906
- }[keyof Definitions & string];
1907
- type ResolvedGameStateOf<Contract, Definitions extends PhaseMapOf<Contract>> = {
1908
- [Name in keyof Definitions & string]: ReducerGameState<TableOfManifest<ManifestContractOf<Contract>>, z.infer<PublicSchemaOfContract<Contract>>, z.infer<PrivateSchemaOfContract<Contract>>, z.infer<HiddenSchemaOfContract<Contract>>, Definitions[Name] extends PhaseDefinition<infer PhaseStateSchema, infer _State, infer _Manifest> ? z.infer<PhaseStateSchema> : never, PhaseNameOfContract<Contract>> & {
1909
- flow: ReducerGameState<TableOfManifest<ManifestContractOf<Contract>>, z.infer<PublicSchemaOfContract<Contract>>, z.infer<PrivateSchemaOfContract<Contract>>, z.infer<HiddenSchemaOfContract<Contract>>, PhaseStateOfDefinitions<Definitions>, PhaseNameOfContract<Contract>>["flow"] & {
1910
- currentPhase: Name;
1911
- };
1912
- };
1913
- }[keyof Definitions & string];
1914
- type ViewMapOf<Contract> = Record<string, ViewDefinition<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>, unknown>>;
1915
- type PhasesOfDefinition<Definition> = Definition extends {
1916
- phases: infer Definitions extends Record<string, unknown>;
1917
- } ? Definitions : never;
1918
- type ViewsOfDefinition<Definition> = Definition extends {
1919
- views?: infer Views;
1920
- } ? NonNullable<Views> : never;
1921
- type NonNeverKeys<Registry> = {
1922
- [Key in keyof Registry]-?: [Registry[Key]] extends [never] ? never : Key;
1923
- }[keyof Registry];
1924
- type ViewNamesOfDefinition<Definition> = NonNeverKeys<ViewsOfDefinition<Definition>> & string;
1925
- type ViewDefinitionByName<Definition, ViewName extends ViewNamesOfDefinition<Definition>> = ViewsOfDefinition<Definition>[ViewName];
1926
- type ViewOfDefinition<Definition, ViewName extends ViewNamesOfDefinition<Definition>> = ViewDefinitionByName<Definition, ViewName> extends ViewDefinition<infer _State, infer _Manifest, infer Projection> ? Projection : never;
1927
- type PhaseNamesOfDefinition<Definition> = keyof PhasesOfDefinition<Definition> & string;
1928
- type PhaseDefinitionByName<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseName extends keyof PhasesOfDefinition<Definition> & string ? PhasesOfDefinition<Definition>[PhaseName] : never;
1929
- type EffectsOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
1930
- effects?: infer Effects;
1931
- } ? Effects extends Record<string, unknown> ? Effects[keyof Effects & string] : never : never;
1932
- type EffectIdsOfDefinition<Definition> = EffectsOfDefinition<Definition> extends infer Effect ? Effect extends {
1933
- id: infer Id;
1934
- } ? Extract<Id, string> : never : never;
1935
- type GameStateOf<Source> = Source extends ReducerGameDefinition<infer Contract, infer Definitions, infer _Views> ? ResolvedGameStateOf<Contract, Definitions> : Source extends ReducerGameContract<any, any, any, any, any, any> ? BaseGameStateOfContract<Source> : never;
1936
- /**
1937
- * Public structural upper bound for a reducer game contract.
1938
- *
1939
- * The `manifest` slot is intentionally erased with `any` because concrete
1940
- * manifests bind per-contract branded literals (e.g. `PlayerId` unions with
1941
- * specific string literals). Using a ground `ManifestContract<...>` type
1942
- * here would prevent assignability from contract-bound manifests in a
1943
- * contravariant position.
1944
- */
1945
- type ReducerGameContractLike = {
1946
- manifest: any;
1947
- state: StateDefinition<SchemaLike<object>, SchemaLike<object>, SchemaLike<object>>;
1948
- };
1949
- type InitialStateContextOf<Contract extends ReducerGameContractLike> = InitContext<TableOfManifest<ManifestOf<Contract>>, ExactManifestContractOf<Contract>>;
1950
- type InitialStateCallbacks<Contract extends ReducerGameContractLike> = {
1951
- public?: (ctx: InitialStateContextOf<Contract>) => z.infer<PublicSchemaOfContract<Contract>>;
1952
- private?: (ctx: InitialStateContextOf<Contract> & {
1953
- playerId: PlayerIdOfTable<TableOfManifest<ManifestOf<Contract>>>;
1954
- }) => z.infer<PrivateSchemaOfContract<Contract>>;
1955
- hidden?: (ctx: InitialStateContextOf<Contract>) => z.infer<HiddenSchemaOfContract<Contract>>;
1956
- };
1957
- type ReducerGameDefinition<Contract extends ReducerGameContractLike, Definitions extends PhaseMapOf<Contract>, Views extends ViewMapOf<Contract> = Record<string, never>> = {
1958
- contract: Contract;
1959
- initial?: InitialStateCallbacks<NoInfer<Contract>>;
1960
- initialPhase?: keyof Definitions & string;
1961
- setupProfiles?: Record<string, SetupProfileDefinition<keyof Definitions & string, ExactManifestContractOf<Contract>>>;
1962
- phases: Definitions;
1963
- views?: Views;
1964
- /**
1965
- * Optional session-scoped static projection. Authored via
1966
- * {@link StaticViewDefinition}; computed once per reducer session from the
1967
- * manifest + setup profile and cached by the host. The client merges the
1968
- * cached payload into every seat view, so the per-tick `projectSeatsDynamic`
1969
- * call no longer needs to re-serialize static board topology.
1970
- */
1971
- staticView?: StaticViewDefinition<ExactManifestContractOf<NoInfer<Contract>>, unknown>;
1972
- };
1973
- type InteractionRegistriesOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
1974
- interactions?: infer Interactions;
1975
- } ? NonNullable<Interactions> : never;
1976
- type SimultaneousSubmitRegistriesOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
1977
- submit?: infer Submit;
1978
- } ? {
1979
- submit: NonNullable<Submit>;
1980
- } : never;
1981
- type CardActionRegistriesOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
1982
- cardActions?: infer CardActions;
1983
- } ? NonNullable<CardActions> : never;
1984
- type InteractionIdOfDefinition<Definition> = InteractionRegistriesOfDefinition<Definition> extends infer Interactions ? SimultaneousSubmitRegistriesOfDefinition<Definition> extends infer Submit ? CardActionRegistriesOfDefinition<Definition> extends infer CardActions ? Interactions extends Record<string, unknown> ? CardActions extends Record<string, unknown> ? Submit extends Record<string, unknown> ? (NonNeverKeys<Interactions> & string) | (NonNeverKeys<CardActions> & string) | (NonNeverKeys<Submit> & string) : (NonNeverKeys<Interactions> & string) | (NonNeverKeys<CardActions> & string) : Submit extends Record<string, unknown> ? (NonNeverKeys<Interactions> & string) | (NonNeverKeys<Submit> & string) : NonNeverKeys<Interactions> & string : CardActions extends Record<string, unknown> ? Submit extends Record<string, unknown> ? (NonNeverKeys<CardActions> & string) | (NonNeverKeys<Submit> & string) : NonNeverKeys<CardActions> & string : Submit extends Record<string, unknown> ? NonNeverKeys<Submit> & string : never : never : never : never;
1985
- type InteractionRegistryOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
1986
- interactions?: infer Interactions;
1987
- } ? NonNullable<Interactions> : Record<string, never>;
1988
- type SimultaneousSubmitRegistryOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
1989
- submit?: infer Submit;
1990
- } ? {
1991
- submit: NonNullable<Submit>;
1992
- } : Record<string, never>;
1993
- type CardActionRegistryOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
1994
- cardActions?: infer CardActions;
1995
- } ? NonNullable<CardActions> : Record<string, never>;
1996
- type NonNeverRegistryValue<Registry, Key extends string> = Registry extends Record<string, unknown> ? Key extends keyof Registry ? [Registry[Key]] extends [never] ? never : Registry[Key] : never : never;
1997
- type InteractionIdOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = InteractionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Interactions ? SimultaneousSubmitRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Submit ? CardActionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer CardActions ? Interactions extends Record<string, unknown> ? CardActions extends Record<string, unknown> ? Submit extends Record<string, unknown> ? (NonNeverKeys<Interactions> & string) | (NonNeverKeys<CardActions> & string) | (NonNeverKeys<Submit> & string) : (NonNeverKeys<Interactions> & string) | (NonNeverKeys<CardActions> & string) : Submit extends Record<string, unknown> ? (NonNeverKeys<Interactions> & string) | (NonNeverKeys<Submit> & string) : NonNeverKeys<Interactions> & string : CardActions extends Record<string, unknown> ? Submit extends Record<string, unknown> ? (NonNeverKeys<CardActions> & string) | (NonNeverKeys<Submit> & string) : NonNeverKeys<CardActions> & string : Submit extends Record<string, unknown> ? NonNeverKeys<Submit> & string : never : never : never : never;
1998
- type InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>> = InteractionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Interactions ? Interactions extends Record<string, unknown> ? NonNeverRegistryValue<Interactions, InteractionId> extends infer InteractionSpec ? [InteractionSpec] extends [never] ? CardActionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer CardActions ? NonNeverRegistryValue<CardActions, InteractionId> extends infer CardActionSpec ? [CardActionSpec] extends [never] ? SimultaneousSubmitRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Submit ? NonNeverRegistryValue<Submit, InteractionId> : never : CardActionSpec : never : never : InteractionSpec : never : never : never;
1999
- type CollectorKindsOf<Collectors> = Collectors extends Record<string, InputCollector> ? Collectors[keyof Collectors] extends infer Collector ? Collector extends {
2000
- kind: infer Kind extends string;
2001
- } ? Kind : never : never : never;
2002
- type CollectorKeysWithKind<Collectors, Kind extends string> = Collectors extends Record<string, InputCollector> ? {
2003
- [K in keyof Collectors]: Collectors[K] extends {
2004
- kind: infer CollectorKind;
2005
- } ? Extract<CollectorKind, Kind> extends never ? never : K : never;
2006
- }[keyof Collectors] : never;
2007
- type CardCollectorZoneIds<Collector> = Collector extends {
2008
- kind: "card";
2009
- meta: infer Meta;
2010
- } ? Meta extends {
2011
- readonly zoneIds: infer ZoneIds extends readonly string[];
2012
- } ? ZoneIds[number] : Meta extends {
2013
- readonly zoneId: infer ZoneId extends string;
2014
- } ? ZoneId : never : never;
2015
- type CollectorCardZoneIds<Collectors, Input extends string> = Collectors extends Record<string, InputCollector> ? Input extends keyof Collectors ? CardCollectorZoneIds<Collectors[Input]> : never : never;
2016
- type InteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, Kind extends string> = {
2017
- [InteractionId in InteractionIdOfDefinitionPhase<Definition, PhaseName>]: InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends InteractionSpec<infer Collectors, infer _State, infer _Manifest> ? Extract<CollectorKindsOf<Collectors>, Kind> extends never ? never : InteractionId : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends CardActionSpec<infer Collectors, infer _State, infer _Manifest> ? Extract<"card" | CollectorKindsOf<Collectors>, Kind> extends never ? never : InteractionId : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends SimultaneousSubmitSpec<infer Collectors, infer _State, infer _Manifest> ? Extract<CollectorKindsOf<Collectors>, Kind> extends never ? never : InteractionId : never;
2018
- }[InteractionIdOfDefinitionPhase<Definition, PhaseName>];
2019
- type QualifiedInteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, Kind extends string> = InteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName, Kind> extends infer InteractionId extends string ? `${PhaseName}.${InteractionId}` : never;
2020
- type PromptInteractionKeyOfDefinition<Definition> = {
2021
- [PhaseName in PhaseNamesOfDefinition<Definition>]: QualifiedInteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName, "prompt">;
2022
- }[PhaseNamesOfDefinition<Definition>];
2023
- type BoardInteractionKeyOfDefinition<Definition> = {
2024
- [PhaseName in PhaseNamesOfDefinition<Definition>]: QualifiedInteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName, "board-edge" | "board-space" | "board-tile" | "board-vertex">;
2025
- }[PhaseNamesOfDefinition<Definition>];
2026
- type CardInteractionKeyOfDefinition<Definition> = {
2027
- [PhaseName in PhaseNamesOfDefinition<Definition>]: QualifiedInteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName, "card">;
2028
- }[PhaseNamesOfDefinition<Definition>];
2029
- type InputKeysWithCollectorKindOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>, Kind extends string> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends InteractionSpec<infer Collectors, infer _State, infer _Manifest> ? CollectorKeysWithKind<Collectors, Kind> & string : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends CardActionSpec<infer Collectors, infer _State, infer _Manifest> ? (Extract<"card", Kind> extends never ? never : "cardId") | (CollectorKeysWithKind<Collectors, Kind> & string) : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends SimultaneousSubmitSpec<infer Collectors, infer _State, infer _Manifest> ? CollectorKeysWithKind<Collectors, Kind> & string : never;
2030
- type CardInputZoneIdsOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>, Input extends string> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends InteractionSpec<infer Collectors, infer _State, infer _Manifest> ? CollectorCardZoneIds<Collectors, Input> : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends CardActionSpec<infer Collectors, infer _State, infer _Manifest> ? Input extends "cardId" ? InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends {
2031
- readonly playFrom: infer PlayFrom extends string;
2032
- } ? PlayFrom : never : CollectorCardZoneIds<Collectors, Input> : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends SimultaneousSubmitSpec<infer Collectors, infer _State, infer _Manifest> ? CollectorCardZoneIds<Collectors, Input> : never;
2033
- type ParamsOfInteractionOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends InteractionSpec<infer Collectors, infer _State, infer _Manifest> ? Collectors extends Record<string, InputCollector> ? {
2034
- [K in keyof Collectors]: Collectors[K] extends InputCollector<infer S, infer _S2> ? S extends SchemaLike<infer V> ? V : never : never;
2035
- } : never : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends CardActionSpec<infer Collectors, infer _State, infer _Manifest> ? Collectors extends Record<string, InputCollector> ? {
2036
- cardId: string;
2037
- } & {
2038
- [K in keyof Collectors]: Collectors[K] extends InputCollector<infer S, infer _S2> ? S extends SchemaLike<infer V> ? V : never : never;
2039
- } : {
2040
- cardId: string;
2041
- } : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends SimultaneousSubmitSpec<infer Collectors, infer _State, infer _Manifest> ? Collectors extends Record<string, InputCollector> ? {
2042
- [K in keyof Collectors]: Collectors[K] extends InputCollector<infer S, infer _S2> ? S extends SchemaLike<infer V> ? V : never : never;
2043
- } : never : never;
2044
- /**
2045
- * Client-facing params shape for an interaction. Omits engine-sampled
2046
- * collectors (`rngInput.*`) — clients never supply those fields; the
2047
- * trusted reducer bundle fills them during `submitInteraction`.
2048
- *
2049
- * This is the type that drives `submit(playerId, id, params)`,
2050
- * `handle.submit(params)`, and the generated `InteractionParams` surface
2051
- * in `shared/generated/ui-contract.ts`. The `reduce`-input counterpart is
2052
- * {@link ParamsOfInteractionOfDefinition}, which includes every field
2053
- * because the engine has already filled the sampled ones by then.
2054
- */
2055
- type ClientParamsOfInteractionOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends InteractionSpec<infer Collectors, infer _State, infer _Manifest> ? Collectors extends Record<string, InputCollector> ? {
2056
- [K in keyof Collectors as Collectors[K] extends InputCollector<infer _S, infer _S2> & {
2057
- kind: "rng";
2058
- } ? never : K]: Collectors[K] extends InputCollector<infer S, infer _S2> ? S extends SchemaLike<infer V> ? V : never : never;
2059
- } : never : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends CardActionSpec<infer Collectors, infer _State, infer _Manifest> ? Collectors extends Record<string, InputCollector> ? {
2060
- cardId: string;
2061
- } & {
2062
- [K in keyof Collectors as Collectors[K] extends InputCollector<infer _S, infer _S2> & {
2063
- kind: "rng";
2064
- } ? never : K]: Collectors[K] extends InputCollector<infer S, infer _S2> ? S extends SchemaLike<infer V> ? V : never : never;
2065
- } : {
2066
- cardId: string;
2067
- } : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends SimultaneousSubmitSpec<infer Collectors, infer _State, infer _Manifest> ? Collectors extends Record<string, InputCollector> ? {
2068
- [K in keyof Collectors as Collectors[K] extends InputCollector<infer _S, infer _S2> & {
2069
- kind: "rng";
2070
- } ? never : K]: Collectors[K] extends InputCollector<infer S, infer _S2> ? S extends SchemaLike<infer V> ? V : never : never;
2071
- } : never : never;
2072
- type DefaultedClientCollectorKeys<Collectors extends Record<string, InputCollector>> = {
2073
- [K in keyof Collectors]: Collectors[K] extends InputCollector<infer _S, infer _S2> & {
2074
- kind: "rng";
2075
- } ? never : Collectors[K] extends {
2076
- readonly defaultValue: unknown;
2077
- } ? K : never;
2078
- }[keyof Collectors];
2079
- type DefaultedClientParamKeysOfInteractionOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends InteractionSpec<infer Collectors, infer _State, infer _Manifest> ? Collectors extends Record<string, InputCollector> ? DefaultedClientCollectorKeys<Collectors> & string : never : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends CardActionSpec<infer Collectors, infer _State, infer _Manifest> ? Collectors extends Record<string, InputCollector> ? DefaultedClientCollectorKeys<Collectors> & string : never : InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends SimultaneousSubmitSpec<infer Collectors, infer _State, infer _Manifest> ? Collectors extends Record<string, InputCollector> ? DefaultedClientCollectorKeys<Collectors> & string : never : never;
2080
- type StageRegistryOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
2081
- stages?: infer Stages;
2082
- } ? NonNullable<Stages> : Record<string, never>;
2083
- type StageNamesOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = StageRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Stages ? Stages extends Record<string, unknown> ? NonNeverKeys<Stages> & string : never : never;
2084
- type ZoneRegistriesOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
2085
- zones?: infer Zones;
2086
- } ? NonNullable<Zones> : never;
2087
- type ZoneIdsOfDefinition<Definition> = ZoneRegistriesOfDefinition<Definition> extends infer Zones ? Zones extends readonly (infer ZoneId)[] ? Extract<ZoneId, string> : never : never;
2088
- type ZoneListOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
2089
- zones?: infer Zones;
2090
- } ? NonNullable<Zones> : readonly [];
2091
- type PlayableInteractionsOfZoneOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, ZoneId extends string> = ZoneListOfDefinitionPhase<Definition, PhaseName> extends readonly (infer From)[] ? Extract<From, ZoneId> extends never ? never : CardActionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer CardActions ? CardActions extends Record<string, unknown> ? {
2092
- [ActionId in keyof CardActions & string]: CardActions[ActionId] extends {
2093
- playFrom: infer PlayFrom extends string;
2094
- } ? Extract<PlayFrom, ZoneId> extends never ? never : ActionId : never;
2095
- }[keyof CardActions & string] : never : never : never;
2096
-
2097
- /**
2098
- * A freestanding, memoized projection of immutable game state.
2099
- *
2100
- * Use `defineDerived` for values that are pure functions of component
2101
- * locations, zone contents, resources, or other state fields - and are
2102
- * consumed from multiple reducer or view call sites, or whose compute cost
2103
- * is non-trivial (graph walks, aggregate reductions).
2104
- *
2105
- * Do NOT cache derived values in `publicState`. State fields should be
2106
- * inputs to derivations, not mirrors of them.
2107
- */
2108
- type DerivedDefinition<Contract, Value> = {
2109
- /** Optional label for debugging. Does not affect caching. */
2110
- readonly name?: string;
2111
- readonly compute: (ctx: {
2112
- readonly state: BaseGameStateOfContract<Contract>;
2113
- readonly q: TableQueriesOfState<BaseGameStateOfContract<Contract>>;
2114
- readonly derived: DerivedResolver;
2115
- }) => Value;
2116
- };
2117
- /**
2118
- * Resolves a `DerivedDefinition` to its value. Callers do not need to know
2119
- * about memoization - the resolver handles caching internally.
2120
- */
2121
- type DerivedResolver = <Value>(def: DerivedDefinition<never, Value>) => Value;
2122
- /**
2123
- * Author-facing factory for creating a derived value tied to a game
2124
- * contract. Usage:
2125
- *
2126
- * ```ts
2127
- * export const longestRoad = defineDerived<GameContract>()({
2128
- * name: "longestRoad",
2129
- * compute: ({ q, derived }) => computeLongestRoad(q),
2130
- * });
2131
- * ```
2132
- */
2133
- declare function defineDerived<Contract>(): <Value>(def: {
2134
- name?: string;
2135
- compute: (ctx: {
2136
- state: BaseGameStateOfContract<Contract>;
2137
- q: TableQueriesOfState<BaseGameStateOfContract<Contract>>;
2138
- derived: DerivedResolver;
2139
- }) => Value;
2140
- }) => DerivedDefinition<Contract, Value>;
2141
- /**
2142
- * Creates a resolver scoped to a single state snapshot. Each engine tick
2143
- * and each view projection call creates its own resolver; cache lifetime
2144
- * ends with the call. Cache key is the `DerivedDefinition` identity (the
2145
- * object reference).
2146
- *
2147
- * Re-entry on an in-flight definition throws a readable error.
2148
- */
2149
- declare function createDerivedResolver<State extends {
2150
- table: RuntimeTableRecord;
2151
- }>(state: State, options?: {
2152
- q?: TableQueriesOfState<State>;
2153
- }): DerivedResolver;
2154
-
2155
- type StaticBoardsOfManifest<Manifest> = Manifest extends {
2156
- staticBoards?: infer StaticBoards;
2157
- } ? NonNullable<StaticBoards> : {
2158
- byId: Record<string, never>;
2159
- hex: Record<string, never>;
2160
- square: Record<string, never>;
2161
- };
2162
- type StaticBoardMapOfManifest<Manifest> = StaticBoardsOfManifest<Manifest> extends {
2163
- byId: infer Boards;
2164
- } ? Boards : Record<string, never>;
2165
- type StaticHexBoardMapOfManifest<Manifest> = StaticBoardsOfManifest<Manifest> extends {
2166
- hex: infer Boards;
2167
- } ? Boards : Record<string, never>;
2168
- type StaticSquareBoardMapOfManifest<Manifest> = StaticBoardsOfManifest<Manifest> extends {
2169
- square: infer Boards;
2170
- } ? Boards : Record<string, never>;
2171
- type StaticViewQueries<Manifest extends ManifestContract<RuntimeTableRecord>> = {
2172
- board: {
2173
- get: <BoardId extends StringKeyOf<StaticBoardMapOfManifest<Manifest>>>(boardId: BoardId) => StaticBoardMapOfManifest<Manifest>[BoardId];
2174
- hex: <BoardId extends StringKeyOf<StaticHexBoardMapOfManifest<Manifest>>>(boardId: BoardId) => StaticHexBoardMapOfManifest<Manifest>[BoardId];
2175
- square: <BoardId extends StringKeyOf<StaticSquareBoardMapOfManifest<Manifest>>>(boardId: BoardId) => StaticSquareBoardMapOfManifest<Manifest>[BoardId];
2176
- };
2177
- };
2178
- type ContinuationSourceKind = "effect";
2179
- type ResumableEffectKind = "rollDie" | "shuffleSharedZone" | "shufflePlayerZone";
2180
- type RollDieContinuationResponse = {
2181
- dieId: string;
2182
- value: number;
2183
- };
2184
- type ShuffleSharedZoneContinuationResponse = {
2185
- zoneId: string;
2186
- orderedCardIds: readonly string[];
2187
- };
2188
- type ShufflePlayerZoneContinuationResponse = {
2189
- zoneId: string;
2190
- playerId: string;
2191
- orderedCardIds: readonly string[];
2192
- };
2193
- type EffectContinuationResponse<Kind extends ResumableEffectKind> = Kind extends "rollDie" ? RollDieContinuationResponse : Kind extends "shuffleSharedZone" ? ShuffleSharedZoneContinuationResponse : Kind extends "shufflePlayerZone" ? ShufflePlayerZoneContinuationResponse : never;
2194
- type EffectContinuationInput<DataSchema extends AnySchema, Kind extends ResumableEffectKind = ResumableEffectKind> = {
2195
- source: "effect";
2196
- effectKind: Kind;
2197
- data: z.infer<DataSchema>;
2198
- response: EffectContinuationResponse<Kind>;
2199
- };
2200
- type ContinuationInput<DataSchema extends AnySchema> = EffectContinuationInput<DataSchema, ResumableEffectKind>;
2201
- type ContinuationInputForSource<DataSchema extends AnySchema, EffectType extends ResumableEffectKind = ResumableEffectKind> = EffectContinuationInput<DataSchema, EffectType>;
2202
- type PhaseEnterContext = {
2203
- event: "initialize" | "transition";
2204
- };
2205
- type BivariantCallback<Args, Result> = {
2206
- bivarianceHack(args: Args): Result;
2207
- }["bivarianceHack"];
2208
- type ActionContext<State extends {
2209
- table: RuntimeTableRecord;
2210
- flow: {
2211
- currentPhase: string;
2212
- };
2213
- }, Manifest extends ManifestContract<TableOfState<State>>> = {
2214
- currentPhase: PhaseNameOfState<State>;
2215
- manifest: Manifest;
2216
- playerOrder: PlayerIdOfState<State>[];
2217
- activePlayers: PlayerIdOfState<State>[];
2218
- runtime: Omit<ReducerRuntimeStateForState<State>, "rng">;
2219
- setup: SetupSelectionOfManifest<Manifest> | null;
2220
- };
2221
- type ValidationIssue = {
2222
- errorCode: string;
2223
- message?: string;
2224
- };
2225
- type RuntimeHelpers<State extends {
2226
- table: RuntimeTableRecord;
2227
- flow: {
2228
- currentPhase: string;
2229
- };
2230
- }> = {
2231
- accept(state: State, instructions?: RuntimeInstructionForState<State>[]): ReducerAccept<State>;
2232
- reject: (errorCode: string, message?: string) => ReducerReject;
2233
- fx: ReducerFx<State>;
2234
- ops: ReducerOps<State>;
2235
- edit<DraftState extends State>(state: DraftState): ReducerTransaction<DraftState>;
2236
- q: TableQueriesOfState<State>;
2237
- derived: DerivedResolver;
2238
- };
2239
- type RandomHelpers = {
2240
- subset<const Values extends readonly unknown[]>(options: {
2241
- from: Values;
2242
- count: number;
2243
- }): readonly Values[number][];
2244
- };
2245
- type MutationRuntimeHelpers = {
2246
- random: RandomHelpers;
2247
- };
2248
- type PhaseEnterArgs<State extends {
2249
- table: RuntimeTableRecord;
2250
- flow: {
2251
- currentPhase: string;
2252
- };
2253
- }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & RuntimeHelpers<State> & MutationRuntimeHelpers & PhaseEnterContext & {
2254
- state: State;
2255
- };
2256
- type ActorSelectorArgs<State extends {
2257
- table: RuntimeTableRecord;
2258
- flow: {
2259
- currentPhase: string;
2260
- };
2261
- }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & RuntimeHelpers<State> & {
2262
- state: State;
2263
- };
2264
- type ActorSelection<State extends {
2265
- table: RuntimeTableRecord;
2266
- flow: {
2267
- currentPhase: string;
2268
- };
2269
- }> = PlayerIdOfState<State> | readonly PlayerIdOfState<State>[] | null | undefined;
2270
- type ActorSelector<State extends {
2271
- table: RuntimeTableRecord;
2272
- flow: {
2273
- currentPhase: string;
2274
- };
2275
- }, Manifest extends ManifestContract<TableOfState<State>>> = BivariantCallback<ActorSelectorArgs<State, Manifest>, ActorSelection<State>>;
2276
- type ContinuationReduceArgs<DataSchema extends AnySchema, State extends {
2277
- table: RuntimeTableRecord;
2278
- flow: {
2279
- currentPhase: string;
2280
- };
2281
- }, Manifest extends ManifestContract<TableOfState<State>>, EffectType extends ResumableEffectKind = ResumableEffectKind> = ActionContext<State, Manifest> & RuntimeHelpers<State> & MutationRuntimeHelpers & {
2282
- state: State;
2283
- input: ContinuationInputForSource<DataSchema, EffectType>;
2284
- };
2285
- type ScopedPhaseState<State extends {
2286
- table: RuntimeTableRecord;
2287
- flow: {
2288
- currentPhase: string;
2289
- };
2290
- phase: object;
2291
- }, PhaseState extends object> = State & {
2292
- phase: PhaseState;
2293
- };
2294
- type ContinuationCallable<DataSchema extends AnySchema, State extends {
2295
- table: RuntimeTableRecord;
2296
- flow: {
2297
- currentPhase: string;
2298
- };
2299
- }, Manifest extends ManifestContract<TableOfState<State>>, ContinuationId extends string = string, EffectType extends ResumableEffectKind = ResumableEffectKind> = ((data: z.infer<DataSchema>) => ContinuationToken<z.infer<DataSchema>, ContinuationId, EffectContinuationResponse<EffectType>>) & {
2300
- id: ContinuationId;
2301
- source: "effect";
2302
- dataSchema: DataSchema;
2303
- responseSchema: AnySchema;
2304
- effectKind?: EffectType;
2305
- reduce: BivariantCallback<ContinuationReduceArgs<DataSchema, State, Manifest, EffectType>, ReducerResult<State>>;
2306
- };
2307
- type EffectContinuationCallable<DataSchema extends AnySchema, State extends {
2308
- table: RuntimeTableRecord;
2309
- flow: {
2310
- currentPhase: string;
2311
- };
2312
- }, Manifest extends ManifestContract<TableOfState<State>>, ContinuationId extends string = string, Kind extends ResumableEffectKind = ResumableEffectKind> = ContinuationCallable<DataSchema, State, Manifest, ContinuationId, Kind>;
2313
-
2314
- /**
2315
- * `rollDie` effect. Resolves a `rollDie` wire effect. `reduce` / `context`
2316
- * are both optional so authors can fire-and-forget a die roll without
2317
- * observing the result.
2318
- */
2319
- type EffectRollDieDefinition<Id extends string, ContextSchema extends AnySchema, State extends {
2320
- table: RuntimeTableRecord;
2321
- flow: {
2322
- currentPhase: string;
2323
- };
2324
- }, Manifest extends ManifestContract<TableOfState<State>>> = {
2325
- readonly type: "rollDie";
2326
- readonly id: Id;
2327
- readonly contextSchema?: ContextSchema;
2328
- readonly __continuation?: EffectContinuationCallable<ContextSchema, State, Manifest, Id, "rollDie">;
2329
- };
2330
- /**
2331
- * `shuffleSharedZone` effect. Resolves a `shuffleSharedZone` wire effect.
2332
- * `reduce` / `context` are both optional.
2333
- */
2334
- type EffectShuffleDefinition<Id extends string, ContextSchema extends AnySchema, State extends {
2335
- table: RuntimeTableRecord;
2336
- flow: {
2337
- currentPhase: string;
2338
- };
2339
- }, Manifest extends ManifestContract<TableOfState<State>>> = {
2340
- readonly type: "shuffleSharedZone";
2341
- readonly id: Id;
2342
- readonly contextSchema?: ContextSchema;
2343
- readonly __continuation?: EffectContinuationCallable<ContextSchema, State, Manifest, Id, "shuffleSharedZone">;
2344
- };
2345
- /**
2346
- * `shufflePlayerZone` effect. Resolves a `shufflePlayerZone` wire effect for
2347
- * a single player's perPlayer zone (e.g. deck-builder reshuffle of discard
2348
- * into deck). `reduce` / `context` are both optional.
2349
- */
2350
- type EffectShufflePlayerZoneDefinition<Id extends string, ContextSchema extends AnySchema, State extends {
2351
- table: RuntimeTableRecord;
2352
- flow: {
2353
- currentPhase: string;
2354
- };
2355
- }, Manifest extends ManifestContract<TableOfState<State>>> = {
2356
- readonly type: "shufflePlayerZone";
2357
- readonly id: Id;
2358
- readonly contextSchema?: ContextSchema;
2359
- readonly __continuation?: EffectContinuationCallable<ContextSchema, State, Manifest, Id, "shufflePlayerZone">;
2360
- };
2361
- /**
2362
- * Discriminated union of every `defineEffect` output.
2363
- */
2364
- type EffectDefinition<State extends {
2365
- table: RuntimeTableRecord;
2366
- flow: {
2367
- currentPhase: string;
2368
- };
2369
- }, Manifest extends ManifestContract<TableOfState<State>>> = EffectRollDieDefinition<string, AnySchema, State, Manifest> | EffectShuffleDefinition<string, AnySchema, State, Manifest> | EffectShufflePlayerZoneDefinition<string, AnySchema, State, Manifest>;
2370
- type EffectMap<State extends {
2371
- table: RuntimeTableRecord;
2372
- flow: {
2373
- currentPhase: string;
2374
- };
2375
- }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, EffectDefinition<State, Manifest>>;
2376
-
2377
- type InputCollectorKind = "form" | "board-vertex" | "board-edge" | "board-tile" | "board-space" | "card" | "prompt" | "rng";
2378
- type TargetKind = "edge" | "vertex" | "space" | "tile" | "card";
2379
- type BoardInputCollectorKind = Exclude<InputCollectorKind, "form" | "card" | "prompt" | "rng">;
2380
- type CardInputCollectorMeta = {
2381
- readonly zoneId: string;
2382
- readonly zoneIds?: readonly string[];
2383
- readonly targetKind: "card";
2384
- };
2385
- type BoardInputCollectorMeta = {
2386
- readonly targetKind: TargetKind;
2387
- readonly boardId: string;
2388
- readonly valueKind?: "board-id" | "player-board-space";
2389
- };
2390
- type PromptInputCollectorMeta = {
2391
- readonly options: (state: unknown, playerId: unknown, q: unknown) => ReadonlyArray<{
2392
- id: unknown;
2393
- label?: string;
2394
- }>;
2395
- readonly eligibleOptions: (state: unknown, playerId: unknown, q: unknown) => ReadonlyArray<{
2396
- id: unknown;
2397
- label?: string;
2398
- }>;
2399
- };
2400
- type RngInputCollectorMeta = {
2401
- readonly rng: "d6";
2402
- readonly count: number;
2403
- } | {
2404
- readonly rng: "coin";
2405
- };
2406
- type InputCollectorMetaForKind<Kind extends InputCollectorKind> = Kind extends "card" ? CardInputCollectorMeta : Kind extends BoardInputCollectorKind ? BoardInputCollectorMeta : Kind extends "prompt" ? PromptInputCollectorMeta | undefined : Kind extends "rng" ? RngInputCollectorMeta : never;
2407
- type InputSelectionDescriptor = {
2408
- readonly mode: "single";
2409
- } | {
2410
- readonly mode: "many";
2411
- readonly min: number;
2412
- readonly max?: number;
2413
- readonly distinct?: boolean;
2414
- };
2415
- type InputDomainResolverDescriptor = {
2416
- readonly interactionKey?: string;
2417
- readonly inputKey: string;
2418
- };
2419
- type InputDomainDependencyCase<Domain extends InputDomainDescriptor = InputDomainDescriptor> = {
2420
- when: Record<string, string>;
2421
- domain: Domain;
2422
- };
2423
- type EagerInputDomainDependencies<Domain extends InputDomainDescriptor = InputDomainDescriptor> = {
2424
- readonly mode: "eager";
2425
- readonly dependentCases: readonly InputDomainDependencyCase<Domain>[];
2426
- };
2427
- type LazyInputDomainDependencies = {
2428
- readonly mode: "lazy";
2429
- readonly dependsOn: readonly string[];
2430
- readonly resolver: InputDomainResolverDescriptor;
2431
- };
2432
- type CardTargetDomainDescriptor = ResolvedCardTargetDomainDescriptor | LazyCardTargetDomainDescriptor;
2433
- type ResolvedCardTargetDomainDescriptor = {
2434
- readonly type: "cardTarget";
2435
- readonly projection: "resolved";
2436
- readonly targetKind: "card";
2437
- readonly zoneIds: readonly string[];
2438
- readonly eligibleTargets: readonly string[];
2439
- readonly selection?: InputSelectionDescriptor;
2440
- readonly dependencies?: EagerInputDomainDependencies<ResolvedCardTargetDomainDescriptor>;
2441
- };
2442
- type LazyCardTargetDomainDescriptor = {
2443
- readonly type: "cardTarget";
2444
- readonly projection: "lazy";
2445
- readonly targetKind: "card";
2446
- readonly zoneIds: readonly string[];
2447
- readonly eligibleTargets?: never;
2448
- readonly selection?: InputSelectionDescriptor;
2449
- readonly dependencies: LazyInputDomainDependencies;
2450
- };
2451
- type BoardTargetDomainDescriptor = ResolvedBoardTargetDomainDescriptor | LazyBoardTargetDomainDescriptor;
2452
- type ResolvedBoardTargetDomainDescriptor = {
2453
- readonly type: "boardTarget";
2454
- readonly projection: "resolved";
2455
- readonly targetKind: Exclude<TargetKind, "card">;
2456
- readonly boardId: string;
2457
- readonly valueKind?: "board-id" | "player-board-space";
2458
- readonly eligibleTargets: readonly string[];
2459
- readonly selection?: InputSelectionDescriptor;
2460
- readonly dependencies?: EagerInputDomainDependencies<ResolvedBoardTargetDomainDescriptor>;
2461
- };
2462
- type LazyBoardTargetDomainDescriptor = {
2463
- readonly type: "boardTarget";
2464
- readonly projection: "lazy";
2465
- readonly targetKind: Exclude<TargetKind, "card">;
2466
- readonly boardId: string;
2467
- readonly valueKind?: "board-id" | "player-board-space";
2468
- readonly eligibleTargets?: never;
2469
- readonly selection?: InputSelectionDescriptor;
2470
- readonly dependencies: LazyInputDomainDependencies;
2471
- };
2472
- type ResourceMapDomainDescriptor = {
2473
- type: "resourceMap";
2474
- resources: Array<{
2475
- resourceId: string;
2476
- label?: string;
2477
- icon?: string;
2478
- min: number;
2479
- max: number;
2480
- }>;
2481
- selection?: InputSelectionDescriptor;
2482
- };
2483
- type BoundedNumberDomainDescriptor = {
2484
- type: "boundedNumber";
2485
- min: number;
2486
- max: number;
2487
- step?: number;
2488
- selection?: InputSelectionDescriptor;
2489
- };
2490
- type ChoiceDomainDescriptor = {
2491
- type: "choice";
2492
- choices: Array<{
2493
- value: string | null;
2494
- label: string;
2495
- icon?: string;
2496
- badge?: string;
2497
- description?: string;
2498
- disabled?: boolean;
2499
- disabledReason?: string;
2500
- }>;
2501
- selection?: InputSelectionDescriptor;
2502
- dependencies?: EagerInputDomainDependencies<ChoiceDomainDescriptor>;
2503
- };
2504
- type ChoiceListDomainDescriptor = {
2505
- type: "choiceList";
2506
- choices: Array<{
2507
- value: string;
2508
- label: string;
2509
- icon?: string;
2510
- badge?: string;
2511
- description?: string;
2512
- disabled?: boolean;
2513
- disabledReason?: string;
2514
- }>;
2515
- min?: number;
2516
- max?: number;
2517
- selection?: InputSelectionDescriptor;
2518
- dependencies?: EagerInputDomainDependencies<ChoiceListDomainDescriptor>;
2519
- };
2520
- type InputDomainDescriptor = CardTargetDomainDescriptor | BoardTargetDomainDescriptor | ResourceMapDomainDescriptor | BoundedNumberDomainDescriptor | ChoiceDomainDescriptor | ChoiceListDomainDescriptor;
2521
- type DomainProjector<Domain extends InputDomainDescriptor> = (state: CollectorState, playerId: string, q: unknown, derived: DerivedResolver, values?: Readonly<Record<string, unknown>>) => Domain;
2522
- type InputDomainForCollectorKind<Kind extends InputCollectorKind> = Kind extends "card" ? CardTargetDomainDescriptor : Kind extends BoardInputCollectorKind ? BoardTargetDomainDescriptor : Exclude<InputDomainDescriptor, CardTargetDomainDescriptor | BoardTargetDomainDescriptor>;
2523
- /**
2524
- * Base state shape every collector is generic over. Collectors that need
2525
- * narrowed ids (card / player) use `PlayerIdOfState<State>` etc. to thread
2526
- * the manifest's branded types.
2527
- */
2528
- type CollectorState = {
2529
- table: RuntimeTableRecord;
2530
- flow: {
2531
- currentPhase: string;
2532
- };
2533
- };
2534
- /**
2535
- * An input collector declares:
2536
- * - a Zod schema for the parameter value the interaction expects. The
2537
- * schema's `z.infer` feeds `ParamsOf<Collectors>`, so downstream
2538
- * `reduce({ input: { params } })` sees branded ids from `cardInput` /
2539
- * `boardInput` without a second declaration.
2540
- * - an optional `eligibleTargets(state, playerId, q)` hook that the runtime
2541
- * calls to enumerate server-authoritative valid values. The hook receives
2542
- * the same `q` table-queries helper that `validate` / `reduce` see, so
2543
- * board/card/prompt collectors can reuse whatever board-graph or zone
2544
- * lookups they already use for validation without rebuilding them from
2545
- * raw state. Each collector helper narrows the return type to its own
2546
- * branded id (`CardIdOfState<State>` for `cardInput`, the caller-supplied
2547
- * `Id extends string` for `boardInput.*`, etc.). At the generic interface
2548
- * level we keep inputs weak (`CollectorState`, `string`, `unknown`) and
2549
- * the return `ReadonlyArray<unknown>` so the runtime can treat all
2550
- * collectors uniformly; per-helper signatures provide the author-facing
2551
- * strong typing.
2552
- * - optional `meta` for collector-kind-specific routing (e.g. `cardInput`
2553
- * stores the `zoneId` the card must come from).
2554
- *
2555
- * Collectors without meaningful eligibility (`form`, `rng`) leave
2556
- * `eligibleTargets` undefined.
2557
- */
2558
- type InputCollectorMetaSlot<Kind extends InputCollectorKind> = [
2559
- InputCollectorMetaForKind<Kind>
2560
- ] extends [never] ? {
2561
- readonly meta?: never;
2562
- } : undefined extends InputCollectorMetaForKind<Kind> ? {
2563
- readonly meta?: Exclude<InputCollectorMetaForKind<Kind>, undefined>;
2564
- } : {
2565
- readonly meta: InputCollectorMetaForKind<Kind>;
2566
- };
2567
- type InputCollectorBase<Schema extends SchemaLike<unknown> = SchemaLike<unknown>, State extends CollectorState = CollectorState, Kind extends InputCollectorKind = InputCollectorKind> = {
2568
- readonly kind: Kind;
2569
- readonly schema: Schema;
2570
- readonly defaultValue?: z.infer<Schema>;
2571
- readonly selection?: InputSelectionDescriptor;
2572
- readonly eligibleTargets?: (state: CollectorState, playerId: string, q: unknown, values?: Readonly<Record<string, unknown>>) => ReadonlyArray<unknown>;
2573
- readonly validateTarget?: (state: CollectorState, playerId: string, q: unknown, targetId: unknown, values?: Readonly<Record<string, unknown>>) => ValidationIssue | null | undefined;
2574
- readonly dependsOn?: readonly string[];
2575
- readonly resolveDefaultValue?: (state: CollectorState, playerId: string, q: unknown, derived: DerivedResolver, domain: InputDomainDescriptor) => z.infer<Schema> | undefined;
2576
- } & (Kind extends "rng" ? {
2577
- readonly domain?: never;
2578
- } : Kind extends "card" | BoardInputCollectorKind ? {
2579
- readonly domain: DomainProjector<InputDomainForCollectorKind<Kind>>;
2580
- } : {
2581
- readonly domain?: DomainProjector<InputDomainForCollectorKind<Kind>>;
2582
- }) & InputCollectorMetaSlot<Kind>;
2583
- type InputCollector<Schema extends SchemaLike<unknown> = SchemaLike<unknown>, State extends CollectorState = CollectorState, Kind extends InputCollectorKind = InputCollectorKind> = Kind extends InputCollectorKind ? InputCollectorBase<Schema, State, Kind> : never;
2584
- type ParamsOf<Collectors extends Record<string, InputCollector>> = {
2585
- [K in keyof Collectors]: Collectors[K] extends InputCollector<infer S> ? S extends SchemaLike<infer V> ? V : never : never;
2586
- };
2587
- type EngineSampledCollectorKeys<Collectors extends Record<string, InputCollector>> = {
2588
- [K in keyof Collectors]: Collectors[K] extends InputCollector & {
2589
- kind: "rng";
2590
- } ? K : never;
2591
- }[keyof Collectors];
2592
- type ClientParamsOf<Collectors extends Record<string, InputCollector>> = {
2593
- [K in keyof Collectors as K extends EngineSampledCollectorKeys<Collectors> ? never : K]: Collectors[K] extends InputCollector<infer S> ? S extends SchemaLike<infer V> ? V : never : never;
2594
- };
2595
-
2596
- type InteractionReduceInput<Collectors extends Record<string, InputCollector>, State extends {
2597
- table: RuntimeTableRecord;
2598
- flow: {
2599
- currentPhase: string;
2600
- };
2601
- }> = {
2602
- playerId: PlayerIdOfState<State>;
2603
- params: ParamsOf<Collectors>;
2604
- };
2605
- type InteractionValidateArgs<Collectors extends Record<string, InputCollector>, State extends {
2606
- table: RuntimeTableRecord;
2607
- flow: {
2608
- currentPhase: string;
2609
- };
2610
- }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & RuntimeHelpers<State> & {
2611
- state: State;
2612
- input: InteractionReduceInput<Collectors, State>;
2613
- };
2614
- type InteractionReduceArgs<Collectors extends Record<string, InputCollector>, State extends {
2615
- table: RuntimeTableRecord;
2616
- flow: {
2617
- currentPhase: string;
2618
- };
2619
- }, Manifest extends ManifestContract<TableOfState<State>>> = InteractionValidateArgs<Collectors, State, Manifest> & MutationRuntimeHelpers;
2620
- type InteractionAvailabilityArgs<State extends {
2621
- table: RuntimeTableRecord;
2622
- flow: {
2623
- currentPhase: string;
2624
- };
2625
- }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & RuntimeHelpers<State> & {
2626
- state: State;
2627
- input: {
2628
- playerId: PlayerIdOfState<State>;
2629
- };
2630
- };
2631
- type InteractionRuleValidationResult = boolean | ValidationIssue | null | undefined;
2632
- type InteractionRule<Collectors extends Record<string, InputCollector> = Record<string, InputCollector>, State extends {
2633
- table: RuntimeTableRecord;
2634
- flow: {
2635
- currentPhase: string;
2636
- };
2637
- } = {
2638
- table: RuntimeTableRecord;
2639
- flow: {
2640
- currentPhase: string;
2641
- };
2642
- }, Manifest extends ManifestContract<TableOfState<State>> = ManifestContract<TableOfState<State>>> = {
2643
- /**
2644
- * Stable rule id for diagnostics and tests. Rule ids are author-owned and
2645
- * should be unique within one interaction.
2646
- */
2647
- id: string;
2648
- /**
2649
- * Error code used when the rule fails. The same code is used for descriptor
2650
- * availability and submit-time validation unless `validate` returns a
2651
- * specific ValidationIssue.
2652
- */
2653
- errorCode: string;
2654
- message?: string;
2655
- /**
2656
- * Projection-time rule. Runs without submitted params, so UI descriptors can
2657
- * reflect action availability before the user clicks.
2658
- */
2659
- available?: BivariantCallback<InteractionAvailabilityArgs<State, Manifest>, boolean>;
2660
- /**
2661
- * Submit-time rule. Runs with parsed params and may return false, a concrete
2662
- * ValidationIssue, null, or undefined.
2663
- */
2664
- validate?: BivariantCallback<InteractionValidateArgs<Collectors, State, Manifest>, InteractionRuleValidationResult>;
2665
- };
2666
- type InteractionCommitPolicy = {
2667
- mode: "manual";
2668
- } | {
2669
- mode: "autoWhenReady";
2670
- };
2671
- type HasManyInputCollector<Collectors extends Record<string, InputCollector>> = Extract<Collectors[keyof Collectors], {
2672
- readonly selection: {
2673
- readonly mode: "many";
2674
- };
2675
- }> extends never ? false : true;
2676
- type InteractionCommitPolicyFor<Collectors extends Record<string, InputCollector>> = HasManyInputCollector<Collectors> extends true ? {
2677
- mode: "manual";
2678
- } : InteractionCommitPolicy;
2679
- /**
2680
- * Projection-level interaction kind, derived by the trusted bundle from
2681
- * collector shape:
2682
- *
2683
- * - `"action"`: any interaction whose inputs are ordinary collectors
2684
- * (`formInput`, `cardInput`).
2685
- * - `"prompt"`: any interaction whose inputs include a `promptInput`
2686
- * collector. Prompt descriptors carry addressed-player context and options
2687
- * so UI primitives can render response controls without reducer-owned
2688
- * placement metadata.
2689
- *
2690
- * Authors never set this directly — the `promptInput(...)` collector is
2691
- * the single source of truth for prompt semantics. See {@link promptInput}
2692
- * and {@link InteractionDescriptor.kind}.
2693
- */
2694
- type InteractionKind = "action" | "prompt";
2695
- type InteractionToArgs<State extends {
2696
- table: RuntimeTableRecord;
2697
- flow: {
2698
- currentPhase: string;
2699
- };
2700
- }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & {
2701
- state: State;
2702
- };
2703
- type InteractionSpec<Collectors extends Record<string, InputCollector> = Record<string, InputCollector>, State extends {
2704
- table: RuntimeTableRecord;
2705
- flow: {
2706
- currentPhase: string;
2707
- };
2708
- } = {
2709
- table: RuntimeTableRecord;
2710
- flow: {
2711
- currentPhase: string;
2712
- };
2713
- }, Manifest extends ManifestContract<TableOfState<State>> = ManifestContract<TableOfState<State>>> = {
2714
- inputs: Collectors;
2715
- paramsSchema?: SchemaLike<ClientParamsOf<Collectors>>;
2716
- /** @internal Phase-local step gates are attached by `defineStepPhase`. */
2717
- __steps?: readonly string[];
2718
- /**
2719
- * Draft commit policy. The input collectors still own value shape and
2720
- * validation; this only controls whether a ready draft may be submitted
2721
- * automatically by SDK controls.
2722
- *
2723
- * Multi-value collectors created with `many(...)` are always manual draft
2724
- * interactions. They represent a selection set that should be committed by
2725
- * explicit player intent, so `autoWhenReady` is intentionally not accepted.
2726
- */
2727
- commit?: InteractionCommitPolicyFor<Collectors>;
2728
- /**
2729
- * Addressed-player selector, used by prompt-kind interactions. When
2730
- * present, the trusted bundle only emits this descriptor for players in
2731
- * the returned set (or the single player, if a scalar is returned). Use
2732
- * to thread e.g. `state.publicState.knowerPlayerId` through without
2733
- * having to manage `activePlayers`. `undefined` / empty returns fall back
2734
- * to the standard `activePlayers` gating used by action-kind interactions.
2735
- */
2736
- to?: BivariantCallback<InteractionToArgs<State, Manifest>, PlayerIdOfState<State> | ReadonlyArray<PlayerIdOfState<State>> | null | undefined>;
2737
- /**
2738
- * Explicit actor selector. Overrides the phase-level actor for this
2739
- * interaction. Prefer this over `to` for new non-prompt interactions; `to`
2740
- * remains the prompt/addressee shorthand.
2741
- */
2742
- actor?: ActorSelector<State, Manifest>;
2743
- /**
2744
- * Descriptor visibility policy. `all` keeps non-actors visible but disabled;
2745
- * `actorsOnly` suppresses descriptors for seats that cannot act.
2746
- */
2747
- visibility?: "all" | "actorsOnly";
2748
- errorCodes?: readonly string[];
2749
- cost?: BivariantCallback<InteractionValidateArgs<Collectors, State, Manifest>, Readonly<Record<string, number>>>;
2750
- rules?: readonly InteractionRule<NoInfer<Collectors>, State, Manifest>[];
2751
- reduce: BivariantCallback<InteractionReduceArgs<Collectors, State, Manifest>, ReducerResult<State>>;
2752
- };
2753
- type CardActionSpec<Collectors extends Record<string, InputCollector> = Record<string, InputCollector>, State extends {
2754
- table: RuntimeTableRecord;
2755
- flow: {
2756
- currentPhase: string;
2757
- };
2758
- } = {
2759
- table: RuntimeTableRecord;
2760
- flow: {
2761
- currentPhase: string;
2762
- };
2763
- }, Manifest extends ManifestContract<TableOfState<State>> = ManifestContract<TableOfState<State>>, PlayFrom extends PlayerZoneIdOfManifest<Manifest> = PlayerZoneIdOfManifest<Manifest>> = {
2764
- cardType: CardTypeOfState<State>;
2765
- playFrom: PlayFrom;
2766
- inputs?: Collectors;
2767
- paramsSchema?: SchemaLike<Record<string, unknown>>;
2768
- /** @internal Phase-local step gates are attached by `defineStepPhase`. */
2769
- __steps?: readonly string[];
2770
- /**
2771
- * Draft commit policy. Card clicks still mutate the draft first;
2772
- * `autoWhenReady` submits only once the full interaction draft validates.
2773
- * Multi-value collectors created with `many(...)` are always manual draft
2774
- * interactions and cannot opt into `autoWhenReady`.
2775
- */
2776
- commit?: InteractionCommitPolicyFor<Collectors>;
2777
- actor?: ActorSelector<State, Manifest>;
2778
- visibility?: "all" | "actorsOnly";
2779
- errorCodes?: readonly string[];
2780
- cost?: BivariantCallback<InteractionValidateArgs<Collectors & {
2781
- cardId: InputCollector<SchemaLike<CardIdOfState<State>>>;
2782
- }, State, Manifest>, Readonly<Record<string, number>>>;
2783
- rules?: readonly InteractionRule<NoInfer<Collectors & {
2784
- cardId: InputCollector<SchemaLike<CardIdOfState<State>>>;
2785
- }>, State, Manifest>[];
2786
- reduce: BivariantCallback<InteractionReduceArgs<Collectors & {
2787
- cardId: InputCollector<SchemaLike<CardIdOfState<State>>>;
2788
- }, State, Manifest>, ReducerResult<State>>;
2789
- };
2790
- type AnyCardActionSpec<State extends {
2791
- table: RuntimeTableRecord;
2792
- flow: {
2793
- currentPhase: string;
2794
- };
2795
- }, Manifest extends ManifestContract<TableOfState<State>>> = CardActionSpec<Record<string, InputCollector>, State, Manifest>;
2796
- type CardActionMap<State extends {
2797
- table: RuntimeTableRecord;
2798
- flow: {
2799
- currentPhase: string;
2800
- };
2801
- }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, AnyCardActionSpec<State, Manifest>>;
2802
- /**
2803
- * Type-safe erasure of {@link InteractionSpec} used by the runtime when it
2804
- * stores heterogeneous interactions in a single map. The collectors generic
2805
- * is erased to the structural upper bound (`Record<string, InputCollector>`)
2806
- * so that lookups and metadata helpers can iterate collectors without
2807
- * committing to a specific authoring-time shape.
2808
- */
2809
- type AnyInteractionSpec<State extends {
2810
- table: RuntimeTableRecord;
2811
- flow: {
2812
- currentPhase: string;
2813
- };
2814
- }, Manifest extends ManifestContract<TableOfState<State>>> = InteractionSpec<Record<string, InputCollector>, State, Manifest>;
2815
- type InteractionMap<State extends {
2816
- table: RuntimeTableRecord;
2817
- flow: {
2818
- currentPhase: string;
2819
- };
2820
- }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, AnyInteractionSpec<State, Manifest>>;
2821
- type StageSpec<State extends {
2822
- table: RuntimeTableRecord;
2823
- flow: {
2824
- currentPhase: string;
2825
- };
2826
- }, Manifest extends ManifestContract<TableOfState<State>>> = {
2827
- when?: BivariantCallback<ActionContext<State, Manifest> & {
2828
- state: State;
2829
- }, boolean>;
2830
- onEnter?: BivariantCallback<PhaseEnterArgs<State, Manifest>, ReducerResult<State> | void>;
2831
- onExit?: BivariantCallback<PhaseEnterArgs<State, Manifest>, ReducerResult<State> | void>;
2832
- allow: readonly string[];
2833
- };
2834
- type StageMap<State extends {
2835
- table: RuntimeTableRecord;
2836
- flow: {
2837
- currentPhase: string;
2838
- };
2839
- }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, StageSpec<State, Manifest>>;
2840
- type PhaseZoneList<Manifest extends ManifestContract<RuntimeTableRecord>> = readonly PlayerZoneIdOfManifest<Manifest>[];
2841
-
2842
- type SimultaneousSubmission<Collectors extends Record<string, InputCollector>, State extends {
2843
- table: RuntimeTableRecord;
2844
- flow: {
2845
- currentPhase: string;
2846
- };
2847
- }> = {
2848
- playerId: PlayerIdOfState<State>;
2849
- params: ParamsOf<Collectors>;
2850
- };
2851
- type SimultaneousResolveArgs<Collectors extends Record<string, InputCollector>, State extends {
2852
- table: RuntimeTableRecord;
2853
- flow: {
2854
- currentPhase: string;
2855
- };
2856
- }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & RuntimeHelpers<State> & MutationRuntimeHelpers & {
2857
- state: State;
2858
- submissions: Record<PlayerIdOfState<State>, SimultaneousSubmission<Collectors, State>>;
2859
- submittedPlayerIds: PlayerIdOfState<State>[];
2860
- waitingPlayerIds: PlayerIdOfState<State>[];
2861
- };
2862
- type SimultaneousSubmitSpec<Collectors extends Record<string, InputCollector> = Record<string, InputCollector>, State extends {
2863
- table: RuntimeTableRecord;
2864
- flow: {
2865
- currentPhase: string;
2866
- };
2867
- } = {
2868
- table: RuntimeTableRecord;
2869
- flow: {
2870
- currentPhase: string;
2871
- };
2872
- }, Manifest extends ManifestContract<TableOfState<State>> = ManifestContract<TableOfState<State>>> = Omit<InteractionSpec<Collectors, State, Manifest>, "reduce"> & {
2873
- /**
2874
- * Optional compatibility slot for callers that reuse `defineInteraction`.
2875
- * The simultaneous phase barrier stores submissions and invokes the
2876
- * phase-level `resolve`; this per-submission reducer is intentionally
2877
- * ignored when present.
2878
- */
2879
- reduce?: InteractionSpec<Collectors, State, Manifest>["reduce"];
2880
- };
2881
-
2882
- type PhaseDefinitionCommon<PhaseStateSchema extends SchemaLike<object>, State extends {
2883
- table: RuntimeTableRecord;
2884
- flow: {
2885
- currentPhase: string;
2886
- };
2887
- phase: object;
2888
- }, Manifest extends ManifestContract<TableOfState<State>>> = {
2889
- name?: string;
2890
- state: PhaseStateSchema;
2891
- initialState?: (ctx: {
2892
- manifest: Manifest;
2893
- state: State;
2894
- playerIds: PlayerIdOfState<State>[];
2895
- setup: SetupSelectionOfManifest<Manifest> | null;
2896
- }) => z.infer<PhaseStateSchema>;
2897
- enter?: BivariantCallback<PhaseEnterArgs<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>, ReducerResult<ScopedPhaseState<State, z.infer<PhaseStateSchema>>> | void>;
2898
- };
2899
- type AutoPhaseDefinition<PhaseStateSchema extends SchemaLike<object>, State extends {
2900
- table: RuntimeTableRecord;
2901
- flow: {
2902
- currentPhase: string;
2903
- };
2904
- phase: object;
2905
- }, Manifest extends ManifestContract<TableOfState<State>>> = PhaseDefinitionCommon<PhaseStateSchema, State, Manifest> & {
2906
- kind: "auto";
2907
- actor?: never;
2908
- actors?: never;
2909
- submit?: never;
2910
- canResubmit?: never;
2911
- resolve?: never;
2912
- effects?: never;
2913
- interactions?: never;
2914
- stages?: never;
2915
- zones?: never;
2916
- cardActions?: never;
2917
- };
2918
- type PlayerPhaseDefinition<PhaseStateSchema extends SchemaLike<object>, State extends {
2919
- table: RuntimeTableRecord;
2920
- flow: {
2921
- currentPhase: string;
2922
- };
2923
- phase: object;
2924
- }, Manifest extends ManifestContract<TableOfState<State>>, Effects extends EffectMap<State, Manifest> = Record<string, never>, Interactions extends InteractionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Zones extends PhaseZoneList<Manifest> = readonly [], CardActions extends CardActionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>> = PhaseDefinitionCommon<PhaseStateSchema, State, Manifest> & {
2925
- kind: "player";
2926
- /**
2927
- * Default actor selector for interactions in this phase. When omitted the
2928
- * runtime falls back to `flow.activePlayers`, preserving the existing turn
2929
- * ownership model. Returning multiple players models simultaneous actors.
2930
- */
2931
- actor?: ActorSelector<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>;
2932
- actors?: never;
2933
- submit?: never;
2934
- canResubmit?: never;
2935
- resolve?: never;
2936
- effects?: Effects;
2937
- interactions?: Interactions;
2938
- stages?: Stages;
2939
- zones?: Zones;
2940
- cardActions?: CardActions;
2941
- };
2942
- type SimultaneousPlayerPhaseDefinition<PhaseStateSchema extends SchemaLike<object>, State extends {
2943
- table: RuntimeTableRecord;
2944
- flow: {
2945
- currentPhase: string;
2946
- };
2947
- phase: object;
2948
- }, Manifest extends ManifestContract<TableOfState<State>>, SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<State, Manifest> = Record<string, never>, Interactions extends InteractionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Zones extends PhaseZoneList<Manifest> = readonly [], CardActions extends CardActionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>> = PhaseDefinitionCommon<PhaseStateSchema, State, Manifest> & {
2949
- kind: "simultaneousPlayer";
2950
- actor?: never;
2951
- /**
2952
- * Actor selector for `kind: "simultaneousPlayer"` phases. This is an alias
2953
- * of `actor` with wording that matches simultaneous submission semantics.
2954
- */
2955
- actors: ActorSelector<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>;
2956
- /**
2957
- * Canonical sealed submission interaction for simultaneous phases. It is
2958
- * projected like a normal interaction, but the trusted runtime stores the
2959
- * parsed params until every actor has submitted, then calls `resolve`.
2960
- */
2961
- submit: SimultaneousSubmitSpec<SubmitCollectors, ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>;
2962
- /**
2963
- * When false or omitted, each actor can submit once per simultaneous
2964
- * barrier. Set true to allow replacing the sealed submission before every
2965
- * required actor has submitted.
2966
- */
2967
- canResubmit?: boolean;
2968
- /**
2969
- * Batch resolver invoked once all simultaneous actors have submitted. The
2970
- * submitted params are passed together so game state mutates from one
2971
- * deterministic base state instead of one player at a time.
2972
- */
2973
- resolve: BivariantCallback<SimultaneousResolveArgs<SubmitCollectors, ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>, ReducerResult<ScopedPhaseState<State, z.infer<PhaseStateSchema>>>>;
2974
- effects?: Effects;
2975
- interactions?: Interactions;
2976
- stages?: Stages;
2977
- zones?: Zones;
2978
- cardActions?: CardActions;
2979
- };
2980
- type PhaseDefinition<PhaseStateSchema extends SchemaLike<object>, State extends {
2981
- table: RuntimeTableRecord;
2982
- flow: {
2983
- currentPhase: string;
2984
- };
2985
- phase: object;
2986
- }, Manifest extends ManifestContract<TableOfState<State>>, SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<State, Manifest> = Record<string, never>, Interactions extends InteractionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Zones extends PhaseZoneList<Manifest> = readonly [], CardActions extends CardActionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>> = AutoPhaseDefinition<PhaseStateSchema, State, Manifest> | PlayerPhaseDefinition<PhaseStateSchema, State, Manifest, Effects, Interactions, Stages, Zones, CardActions> | SimultaneousPlayerPhaseDefinition<PhaseStateSchema, State, Manifest, SubmitCollectors, Effects, Interactions, Stages, Zones, CardActions>;
2987
-
2988
- type ViewDefinition<State extends {
2989
- table: RuntimeTableRecord;
2990
- flow: {
2991
- currentPhase: string;
2992
- };
2993
- }, Manifest extends ManifestContract<TableOfState<State>>, Projection = unknown> = {
2994
- project: (args: ActionContext<State, Manifest> & RuntimeHelpers<State> & {
2995
- state: State;
2996
- playerId: PlayerIdOfState<State>;
2997
- runtime: State extends {
2998
- runtime: infer RuntimeStateValue;
2999
- } ? RuntimeStateValue : never;
3000
- }) => Projection;
3001
- };
3002
- /**
3003
- * Session-scoped, once-per-init view. The `project` callback receives only
3004
- * the authored manifest — the mutable-state helpers (`state`, `playerId`,
3005
- * `runtime`, `fx`, `ops`, `accept`, `reject`, `q`) that `ViewDefinition.project`
3006
- * exposes are structurally absent, so an author cannot accidentally project
3007
- * per-tick state into the payload. The host calls this once per reducer
3008
- * session, caches the result, and merges it back into every seat view on
3009
- * the client. Moving static board topology here is what lets the adapter
3010
- * skip the ~87% of `projectSeatsDynamic` wall time that used to re-serialize
3011
- * manifest-sourced fields on every input.
3012
- */
3013
- type StaticViewDefinition<Manifest extends ManifestContract<RuntimeTableRecord>, Projection = unknown> = {
3014
- project: (args: {
3015
- manifest: Manifest;
3016
- q: StaticViewQueries<Manifest>;
3017
- }) => Projection;
3018
- };
3019
-
3020
- /**
3021
- * Structural upper bound for reducer game contracts accepted by the
3022
- * authoring-level `define*` factories. The `manifest` slot admits any
3023
- * contract-generated manifest shape (tables, players, decks, etc. vary per
3024
- * contract); `state` is pinned to the base {@link StateDefinition} so the
3025
- * authoring helpers can infer public/private/hidden schemas from it.
3026
- */
3027
9
  type AnyReducerGameContract = {
3028
- manifest: ManifestContract<RuntimeTableRecord>;
10
+ manifest: GeneratedManifestContractLike<RuntimeTableRecord>;
3029
11
  state: StateDefinition<SchemaLike<object>, SchemaLike<object>, SchemaLike<object>>;
3030
12
  };
3031
- type PhaseStateInput = SchemaLike<object> | object;
3032
- type InferPhaseState<Input extends PhaseStateInput> = Input extends SchemaLike<infer Output> ? Output extends object ? Output : object : Input extends object ? Input : object;
3033
- type ContractState<Contract extends AnyReducerGameContract> = BaseGameStateOfContract<Contract>;
3034
- type ContractManifest<Contract extends AnyReducerGameContract> = ManifestContractOf<Contract>;
3035
- type ReducerPhaseDefinition<Contract extends AnyReducerGameContract, PhaseStateSchema extends SchemaLike<object>> = PhaseDefinition<PhaseStateSchema, ContractState<Contract>, ContractManifest<Contract>>;
3036
- type ReducerViewDefinition<Contract extends AnyReducerGameContract, Projection = unknown> = ViewDefinition<ContractState<Contract>, ContractManifest<Contract>, Projection>;
3037
-
3038
- type ManifestIdSchemasOf<Ids extends Record<string, SchemaLike<unknown>>> = {
3039
- readonly [Key in keyof Ids]: Ids[Key] extends SchemaLike<infer Output> ? Ids[Key] & ManifestIdSchema<Output> : Ids[Key];
3040
- };
3041
-
3042
- /**
3043
- * Narrows a manifest's `literals.phaseNames` and `ids.phaseName` to the
3044
- * author-supplied phase-name tuple. Lets `defineGameContract` override the
3045
- * codegen-emitted `phaseNames: readonly string[]` / `phaseName: z.string()`
3046
- * placeholders so `PhaseNameOfContract<Contract>` resolves to a literal
3047
- * union and flows through `fx.transition`, `PhaseMapOf`, and the flow
3048
- * state's `currentPhase`.
3049
- */
3050
- type NarrowManifestPhaseNames<Manifest, PhaseNames extends readonly string[]> = Omit<Manifest, "literals" | "ids"> & {
3051
- literals: Manifest extends {
3052
- literals: infer L;
3053
- } ? Omit<L, "phaseNames"> & {
3054
- phaseNames: PhaseNames;
3055
- } : {
3056
- phaseNames: PhaseNames;
3057
- };
3058
- ids: Manifest extends {
3059
- ids: infer I;
3060
- } ? Omit<I, "phaseName"> & {
3061
- phaseName: z.ZodType<PhaseNames[number]>;
3062
- } : {
3063
- phaseName: z.ZodType<PhaseNames[number]>;
3064
- };
3065
- };
3066
- type ReducerGameContractInput<Table extends RuntimeTableRecord, Manifest extends ReducerManifestContract<Table, string, string, string, string, string>, PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>, Phases extends Record<string, SchemaLike<object>>> = {
3067
- manifest: Manifest;
3068
- state: StateDefinition<PublicSchema, PrivateSchema, HiddenSchema>;
3069
- phases: Phases;
3070
- };
3071
- declare function defineGameContract<Table extends RuntimeTableRecord, const Manifest extends ReducerManifestContract<Table, string, string, string, string, string>, PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>, const Phases extends Record<string, SchemaLike<object>>>(definition: ReducerGameContractInput<Table, Manifest, PublicSchema, PrivateSchema, HiddenSchema, Phases>): ReducerGameContract<Table, NarrowManifestPhaseNames<Manifest, readonly (keyof Phases & string)[]>, PublicSchema, PrivateSchema, HiddenSchema, Phases> & {
3072
- readonly phases: Phases;
3073
- readonly phaseNames: readonly (keyof Phases & string)[];
3074
- /**
3075
- * Ergonomic shortcut to the manifest-backed Zod id schemas. Equivalent to
3076
- * `definition.manifest.ids`. Prefer `gameContract.schemas.playerId` etc.
3077
- * over re-importing the generated `ids` namespace so that every authored
3078
- * schema is anchored to the same SDK-guided source.
3079
- */
3080
- readonly schemas: ManifestIdSchemasOf<NarrowManifestPhaseNames<Manifest, readonly (keyof Phases & string)[]>["ids"]>;
3081
- };
3082
-
3083
- type EffectRollDieInput<Contract extends AnyReducerGameContract, Id extends string, ContextSchema extends AnySchema> = {
3084
- type: "rollDie";
3085
- id: Id;
3086
- context?: ContextSchema;
3087
- reduce?: ContinuationCallable<ContextSchema, ContractState<Contract>, ContractManifest<Contract>, Id, "rollDie">["reduce"];
3088
- };
3089
- type EffectShuffleInput<Contract extends AnyReducerGameContract, Id extends string, ContextSchema extends AnySchema> = {
3090
- type: "shuffleSharedZone";
3091
- id: Id;
3092
- context?: ContextSchema;
3093
- reduce?: ContinuationCallable<ContextSchema, ContractState<Contract>, ContractManifest<Contract>, Id, "shuffleSharedZone">["reduce"];
3094
- };
3095
- type EffectShufflePlayerZoneInput<Contract extends AnyReducerGameContract, Id extends string, ContextSchema extends AnySchema> = {
3096
- type: "shufflePlayerZone";
3097
- id: Id;
3098
- context?: ContextSchema;
3099
- reduce?: ContinuationCallable<ContextSchema, ContractState<Contract>, ContractManifest<Contract>, Id, "shufflePlayerZone">["reduce"];
3100
- };
3101
- declare function defineEffect<Contract extends AnyReducerGameContract>(): {
3102
- <Id extends string, ContextSchema extends AnySchema = z.ZodObject<Record<string, never>, z.core.$strip>>(definition: EffectRollDieInput<Contract, Id, ContextSchema>): EffectRollDieDefinition<Id, ContextSchema, ContractState<Contract>, ContractManifest<Contract>>;
3103
- <Id extends string, ContextSchema extends AnySchema = z.ZodObject<Record<string, never>, z.core.$strip>>(definition: EffectShuffleInput<Contract, Id, ContextSchema>): EffectShuffleDefinition<Id, ContextSchema, ContractState<Contract>, ContractManifest<Contract>>;
3104
- <Id extends string, ContextSchema extends AnySchema = z.ZodObject<Record<string, never>, z.core.$strip>>(definition: EffectShufflePlayerZoneInput<Contract, Id, ContextSchema>): EffectShufflePlayerZoneDefinition<Id, ContextSchema, ContractState<Contract>, ContractManifest<Contract>>;
3105
- };
3106
-
3107
- declare function defineGame<const Contract extends AnyReducerGameContract, Definitions extends PhaseMapOf<Contract>, Views extends ViewMapOf<Contract> = Record<string, never>>(definition: {
3108
- contract: Contract;
3109
- } & Omit<ReducerGameDefinition<NoInfer<Contract>, Definitions, Views>, "contract">): ReducerGameDefinition<Contract, Definitions, Views>;
3110
-
3111
- declare function defineInteraction<Contract extends AnyReducerGameContract, PhaseState extends PhaseStateInput = SchemaLike<object>>(): <Collectors extends Record<string, InputCollector>>(definition: InteractionSpec<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>>) => InteractionSpec<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>>;
3112
- declare function defineInteractionRule<Contract extends AnyReducerGameContract, PhaseState extends PhaseStateInput = SchemaLike<object>>(): <Collectors extends Record<string, InputCollector> = Record<string, InputCollector>>(definition: InteractionRule<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>>) => InteractionRule<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>>;
3113
- declare function defineCardAction<Contract extends AnyReducerGameContract, PhaseState extends PhaseStateInput>(): <Collectors extends Record<string, InputCollector> = Record<string, never>, const PlayFrom extends PlayerZoneIdOfManifest<ContractManifest<Contract>> = PlayerZoneIdOfManifest<ContractManifest<Contract>>>(definition: CardActionSpec<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>, PlayFrom>) => CardActionSpec<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>, PlayFrom>;
3114
-
3115
- type StepPhaseState<PhaseStateSchema extends SchemaLike<object>, Steps extends readonly string[]> = z.infer<PhaseStateSchema> & {
3116
- step: Steps[number];
3117
- };
3118
- type StepPhaseInteractionEntry<Step extends string, Interaction> = {
3119
- steps: readonly Step[];
3120
- interaction: Interaction;
3121
- };
3122
- type StepPhaseCardActionEntry<Step extends string, Action> = {
3123
- steps: readonly Step[];
3124
- action: Action;
3125
- };
3126
- type StepPhaseInteractionMap<Step extends string, State extends {
3127
- table: RuntimeTableRecord;
3128
- flow: {
3129
- currentPhase: string;
3130
- };
3131
- }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, StepPhaseInteractionEntry<Step, AnyInteractionSpec<State, Manifest>>>;
3132
- type StepPhaseCardActionMap<Step extends string, State extends {
3133
- table: RuntimeTableRecord;
3134
- flow: {
3135
- currentPhase: string;
3136
- };
3137
- }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, StepPhaseCardActionEntry<Step, AnyCardActionSpec<State, Manifest>>>;
3138
- type UnwrappedStepInteractions<State extends {
3139
- table: RuntimeTableRecord;
3140
- flow: {
3141
- currentPhase: string;
3142
- };
3143
- }, Manifest extends ManifestContract<TableOfState<State>>, Interactions extends Record<string, StepPhaseInteractionEntry<string, AnyInteractionSpec<State, Manifest>>>> = {
3144
- [Key in keyof Interactions]: Interactions[Key]["interaction"];
3145
- };
3146
- type UnwrappedStepCardActions<State extends {
3147
- table: RuntimeTableRecord;
3148
- flow: {
3149
- currentPhase: string;
3150
- };
3151
- }, Manifest extends ManifestContract<TableOfState<State>>, CardActions extends Record<string, StepPhaseCardActionEntry<string, AnyCardActionSpec<State, Manifest>>>> = {
3152
- [Key in keyof CardActions]: CardActions[Key]["action"];
13
+ type PhaseStateInput = SchemaLike<object> | object;
14
+ type InferPhaseState<Input extends PhaseStateInput> = Input extends SchemaLike<infer Output> ? Output extends object ? Output : object : Input extends object ? Input : object;
15
+ type ContractState<Contract extends AnyReducerGameContract> = BaseGameStateOfContract<Contract>;
16
+ type ContractManifest<Contract extends AnyReducerGameContract> = ManifestContractOf<Contract>;
17
+ type ContractErrorCode<Contract extends AnyReducerGameContract> = ErrorCodeOfContract<Contract>;
18
+ type ReducerPhaseDefinition<Contract extends AnyReducerGameContract, PhaseStateSchema extends SchemaLike<object>> = PhaseDefinition<PhaseStateSchema, ContractState<Contract>, ContractManifest<Contract>>;
19
+ type ReducerViewDefinition<Contract extends AnyReducerGameContract, Projection = unknown> = ViewDefinition<ContractState<Contract>, ContractManifest<Contract>, Projection>;
20
+
21
+ type ManifestIdSchemasOf<Ids extends Record<string, SchemaLike<unknown>>> = {
22
+ readonly [Key in keyof Ids]: Ids[Key] extends SchemaLike<infer Output> ? Ids[Key] & ManifestIdSchema<Output> : Ids[Key];
3153
23
  };
3154
- declare function definePhase<Contract extends AnyReducerGameContract>(): <PhaseStateSchema extends SchemaLike<object>, SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<ContractState<Contract>, ContractManifest<Contract>> = Record<string, never>, Interactions extends Record<string, AnyInteractionSpec<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>>> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>> = Record<string, never>, const Zones extends PhaseZoneList<ContractManifest<Contract>> = readonly [], CardActions extends CardActionMap<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>> = Record<string, never>>(definition: PhaseDefinition<PhaseStateSchema, ContractState<Contract>, ContractManifest<Contract>, SubmitCollectors, Effects, Interactions, Stages, Zones, CardActions>) => PhaseDefinition<PhaseStateSchema, ContractState<Contract>, ContractManifest<Contract>, SubmitCollectors, Effects, Interactions, Stages, Zones, CardActions>;
3155
- declare function defineStepPhase<Contract extends AnyReducerGameContract>(): <const Steps extends readonly [string, ...string[]], PhaseStateSchema extends SchemaLike<object>, SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<ContractState<Contract>, ContractManifest<Contract>> = Record<string, never>, Interactions extends StepPhaseInteractionMap<Steps[number], ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>> = Record<string, never>, const Zones extends PhaseZoneList<ContractManifest<Contract>> = readonly [], CardActions extends StepPhaseCardActionMap<Steps[number], ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>> = Record<string, never>>(definition: Omit<PhaseDefinition<PhaseStateSchema, ContractState<Contract>, ContractManifest<Contract>, SubmitCollectors, Effects, UnwrappedStepInteractions<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>, Interactions>, Stages, Zones, UnwrappedStepCardActions<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>, CardActions>>, "state" | "initialState" | "interactions" | "cardActions"> & {
3156
- steps: Steps;
3157
- state: PhaseStateSchema;
3158
- initialState?: (ctx: {
3159
- manifest: ContractManifest<Contract>;
3160
- state: ContractState<Contract>;
3161
- playerIds: PlayerIdOfState<ContractState<Contract>>[];
3162
- setup: SetupSelectionOfManifest<ContractManifest<Contract>> | null;
3163
- }) => z.infer<PhaseStateSchema>;
3164
- interactions?: Interactions;
3165
- cardActions?: CardActions;
3166
- }) => PhaseDefinition<SchemaLike<StepPhaseState<PhaseStateSchema, Steps>>, ContractState<Contract>, ContractManifest<Contract>, SubmitCollectors, Effects, UnwrappedStepInteractions<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>, Interactions>, Stages, Zones, UnwrappedStepCardActions<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>, CardActions>>;
3167
24
 
3168
- declare function defineView<Contract extends AnyReducerGameContract>(): <Projection>(definition: ViewDefinition<ContractState<Contract>, ContractManifest<Contract>, Projection>) => ViewDefinition<ContractState<Contract>, ContractManifest<Contract>, Projection>;
3169
25
  /**
3170
- * Factory for the session-scoped static view (see {@link StaticViewDefinition}).
3171
- * Kept separate from {@link defineView} because the argument shape is
3172
- * structurally different: it exposes only the manifest and generated static
3173
- * queries, with no `state`, `playerId`, `runtime`, `fx`, `ops`, or
3174
- * `accept/reject`. That shape is what prevents authors from accidentally
3175
- * projecting per-tick state into the once-per-session payload.
26
+ * Narrows a manifest's `literals.phaseNames` and `ids.phaseName` to the
27
+ * author-supplied phase-name tuple. Lets `defineGameContract` override the
28
+ * codegen-emitted `phaseNames: readonly string[]` / `phaseName: z.string()`
29
+ * placeholders so `PhaseNameOfContract<Contract>` resolves to a literal
30
+ * union and flows through `fx.transition`, `PhaseMapOf`, and the flow
31
+ * state's `currentPhase`.
3176
32
  */
3177
- declare function defineStaticView<Contract extends AnyReducerGameContract>(): <Projection>(definition: StaticViewDefinition<ExactManifestContractOf<Contract>, Projection>) => StaticViewDefinition<ExactManifestContractOf<Contract>, Projection>;
3178
- declare function defineStage<Contract extends AnyReducerGameContract>(): (definition: StageSpec<ContractState<Contract>, ContractManifest<Contract>>) => StageSpec<ContractState<Contract>, ContractManifest<Contract>>;
3179
- declare function definePhaseStage<Contract extends AnyReducerGameContract, PhaseStateSchema extends SchemaLike<object>>(): (definition: StageSpec<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>>) => StageSpec<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>>;
33
+ type NarrowManifestPhaseNames<Manifest, PhaseNames extends readonly string[]> = Manifest & {
34
+ literals: Manifest extends {
35
+ literals: infer L;
36
+ } ? Omit<L, "phaseNames"> & {
37
+ phaseNames: PhaseNames;
38
+ } : {
39
+ phaseNames: PhaseNames;
40
+ };
41
+ ids: Manifest extends {
42
+ ids: infer I;
43
+ } ? Omit<I, "phaseName"> & {
44
+ phaseName: z.ZodType<PhaseNames[number]>;
45
+ } : {
46
+ phaseName: z.ZodType<PhaseNames[number]>;
47
+ };
48
+ };
49
+ type ReducerGameContractInput<Table extends RuntimeTableRecord, Manifest extends ReducerManifestContract<Table, string, string, string, string, string>, PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>, Phases extends Record<string, SchemaLike<object>>, Errors extends Record<string, string> | undefined = undefined> = {
50
+ manifest: Manifest;
51
+ state: StateDefinition<PublicSchema, PrivateSchema, HiddenSchema>;
52
+ phases: Phases;
53
+ errors?: Errors;
54
+ };
55
+ declare function defineGameContract<Table extends RuntimeTableRecord, const Manifest extends ReducerManifestContract<Table, string, string, string, string, string>, PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>, const Phases extends Record<string, SchemaLike<object>>, const Errors extends Record<string, string> | undefined = undefined>(definition: ReducerGameContractInput<Table, Manifest, PublicSchema, PrivateSchema, HiddenSchema, Phases, Errors>): ReducerGameContract<Table, NarrowManifestPhaseNames<Manifest, readonly (keyof Phases & string)[]>, PublicSchema, PrivateSchema, HiddenSchema, Phases, Errors> & {
56
+ readonly phases: Phases;
57
+ readonly errors: Errors;
58
+ readonly phaseNames: readonly (keyof Phases & string)[];
59
+ /**
60
+ * Ergonomic shortcut to the manifest-backed Zod id schemas. Equivalent to
61
+ * `definition.manifest.ids`. Prefer `gameContract.schemas.playerId` etc.
62
+ * over re-importing the generated `ids` namespace so that every authored
63
+ * schema is anchored to the same SDK-guided source.
64
+ */
65
+ readonly schemas: ManifestIdSchemasOf<NarrowManifestPhaseNames<Manifest, readonly (keyof Phases & string)[]>["ids"]>;
66
+ };
3180
67
 
3181
68
  type InputFieldRef<Key extends string = string, Value = unknown, Collector extends InputCollector = InputCollector> = {
3182
69
  readonly key: Key;
@@ -3212,6 +99,15 @@ type DomainContext<State extends CollectorState, Values extends Readonly<Record<
3212
99
  };
3213
100
  type ManifestFormInputSchema = ManifestIdSchema<unknown> | z.ZodOptional<ManifestIdSchema<unknown>> | z.ZodNullable<ManifestIdSchema<unknown>>;
3214
101
  type DomainNumber<State extends CollectorState> = number | ((context: DomainContext<State>) => number);
102
+ type ResourceMapInputOptions<State extends CollectorState> = {
103
+ resources: ReadonlyArray<{
104
+ resourceId: string;
105
+ label?: string;
106
+ icon?: string;
107
+ min?: DomainNumber<State>;
108
+ max: DomainNumber<State>;
109
+ }>;
110
+ };
3215
111
  type ChoiceValue = string | null;
3216
112
  type DomainChoice<Value extends ChoiceValue, State extends CollectorState> = {
3217
113
  value: Value;
@@ -3251,23 +147,8 @@ declare function baseFormInput<Schema extends ManifestFormInputSchema & SchemaLi
3251
147
  }): InputCollector<Schema, State, "form"> & {
3252
148
  readonly defaultValue: z.infer<Schema>;
3253
149
  };
3254
- declare function resourceMapInput<State extends CollectorState = CollectorState>(options: {
3255
- resources: ReadonlyArray<{
3256
- resourceId: string;
3257
- label?: string;
3258
- icon?: string;
3259
- min?: DomainNumber<State>;
3260
- max: DomainNumber<State>;
3261
- }>;
3262
- }): InputCollector<z.ZodRecord<z.ZodString, z.ZodNumber>, State, "form">;
3263
- declare function resourceMapInput<State extends CollectorState = CollectorState>(options: {
3264
- resources: ReadonlyArray<{
3265
- resourceId: string;
3266
- label?: string;
3267
- icon?: string;
3268
- min?: DomainNumber<State>;
3269
- max: DomainNumber<State>;
3270
- }>;
150
+ declare function resourceMapInput<State extends CollectorState = CollectorState>(options: ResourceMapInputOptions<State>): InputCollector<z.ZodRecord<z.ZodString, z.ZodNumber>, State, "form">;
151
+ declare function resourceMapInput<State extends CollectorState = CollectorState>(options: ResourceMapInputOptions<State> & {
3271
152
  defaultValue: Record<string, number>;
3272
153
  }): InputCollector<z.ZodRecord<z.ZodString, z.ZodNumber>, State, "form"> & {
3273
154
  readonly defaultValue: Record<string, number>;
@@ -3340,11 +221,28 @@ type FormInputForState<State extends CollectorState> = {
3340
221
  }): InputCollector<Schema, State, "form"> & {
3341
222
  readonly defaultValue: z.infer<Schema>;
3342
223
  };
3343
- resourceMap(options: Parameters<typeof resourceMapInput<State>>[0]): ReturnType<typeof resourceMapInput<State>>;
224
+ resourceMap(options: ResourceMapInputOptions<State>): InputCollector<z.ZodRecord<z.ZodString, z.ZodNumber>, State, "form">;
225
+ resourceMap(options: ResourceMapInputOptions<State> & {
226
+ defaultValue: Record<string, number>;
227
+ }): InputCollector<z.ZodRecord<z.ZodString, z.ZodNumber>, State, "form"> & {
228
+ readonly defaultValue: Record<string, number>;
229
+ };
3344
230
  resourceChoices(options?: {
3345
231
  decorate?: ResourceMapChoiceDecorator<State>;
3346
232
  }): ResourceMapChoiceSource<State>;
3347
233
  number(options: Parameters<typeof numberInput<State>>[0]): ReturnType<typeof numberInput<State>>;
234
+ choice<Value extends ChoiceValue, const Dependencies extends readonly InputFieldRef<string, unknown>[]>(options: {
235
+ dependsOn: Dependencies;
236
+ choices: DependentDomainChoices<Value, State, Dependencies>;
237
+ defaultValue: Value;
238
+ }): InputCollector<SchemaLike<Value>, State, "form"> & {
239
+ readonly defaultValue: Value;
240
+ };
241
+ choice<Value extends ChoiceValue, const Dependencies extends readonly InputFieldRef<string, unknown>[]>(options: {
242
+ dependsOn: Dependencies;
243
+ choices: DependentDomainChoices<Value, State, Dependencies>;
244
+ defaultValue: ChoiceDefaultResolver<Value, State, DependencyValues<Dependencies>>;
245
+ }): InputCollector<SchemaLike<Value>, State, "form">;
3348
246
  choice<Value extends ChoiceValue>(options: {
3349
247
  choices: DomainChoices<Value, State>;
3350
248
  defaultValue: Value;
@@ -3637,12 +535,249 @@ type ManyInputCollector<Schema extends SchemaLike<unknown> = SchemaLike<unknown>
3637
535
  };
3638
536
  declare function many<Collector extends NonRngCollector>(collector: Collector, options: ManyOptions): ManyInputCollector<CollectorSchema<Collector>, CollectorStateOf<Collector>, CollectorKindOf<Collector>> & Pick<Collector, "meta">;
3639
537
 
538
+ type StepPhaseState<PhaseStateSchema extends SchemaLike<object>, Steps extends readonly string[]> = z.infer<PhaseStateSchema> & {
539
+ step: Steps[number];
540
+ };
541
+ type StepPhaseInteractionEntry<Step extends string, Interaction> = {
542
+ steps: readonly Step[];
543
+ interaction: Interaction;
544
+ };
545
+ type StepPhaseCardActionEntry<Step extends string, Action> = {
546
+ steps: readonly Step[];
547
+ action: Action;
548
+ };
549
+ type StepPhaseInteractionMap<Step extends string, State extends {
550
+ table: RuntimeTableRecord;
551
+ flow: {
552
+ currentPhase: string;
553
+ };
554
+ }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, StepPhaseInteractionEntry<Step, AnyInteractionSpec<State, Manifest>>>;
555
+ type StepPhaseCardActionMap<Step extends string, State extends {
556
+ table: RuntimeTableRecord;
557
+ flow: {
558
+ currentPhase: string;
559
+ };
560
+ }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, StepPhaseCardActionEntry<Step, AnyCardActionSpec<State, Manifest>>>;
561
+ type UnwrappedStepInteractions<State extends {
562
+ table: RuntimeTableRecord;
563
+ flow: {
564
+ currentPhase: string;
565
+ };
566
+ }, Manifest extends ManifestContract<TableOfState<State>>, Interactions extends Record<string, StepPhaseInteractionEntry<string, AnyInteractionSpec<State, Manifest>>>> = {
567
+ [Key in keyof Interactions]: Interactions[Key]["interaction"];
568
+ };
569
+ type UnwrappedStepCardActions<State extends {
570
+ table: RuntimeTableRecord;
571
+ flow: {
572
+ currentPhase: string;
573
+ };
574
+ }, Manifest extends ManifestContract<TableOfState<State>>, CardActions extends Record<string, StepPhaseCardActionEntry<string, AnyCardActionSpec<State, Manifest>>>> = {
575
+ [Key in keyof CardActions]: CardActions[Key]["action"];
576
+ };
577
+ declare function definePhase<Contract extends AnyReducerGameContract>(): <PhaseStateSchema extends SchemaLike<object>, SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<ContractState<Contract>, ContractManifest<Contract>> = Record<string, never>, Interactions extends Record<string, AnyInteractionSpec<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>>> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>> = Record<string, never>, const Zones extends PhaseZoneList<ContractManifest<Contract>> = readonly [], CardActions extends CardActionMap<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>> = Record<string, never>>(definition: PhaseDefinition<PhaseStateSchema, ContractState<Contract>, ContractManifest<Contract>, SubmitCollectors, Effects, Interactions, Stages, Zones, CardActions>) => PhaseDefinition<PhaseStateSchema, ContractState<Contract>, ContractManifest<Contract>, SubmitCollectors, Effects, Interactions, Stages, Zones, CardActions>;
578
+ declare function defineStepPhase<Contract extends AnyReducerGameContract>(): <const Steps extends readonly [string, ...string[]], PhaseStateSchema extends SchemaLike<object>, SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<ContractState<Contract>, ContractManifest<Contract>> = Record<string, never>, Interactions extends StepPhaseInteractionMap<Steps[number], ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>> = Record<string, never>, const Zones extends PhaseZoneList<ContractManifest<Contract>> = readonly [], CardActions extends StepPhaseCardActionMap<Steps[number], ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>> = Record<string, never>>(definition: Omit<PhaseDefinition<PhaseStateSchema, ContractState<Contract>, ContractManifest<Contract>, SubmitCollectors, Effects, UnwrappedStepInteractions<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>, Interactions>, Stages, Zones, UnwrappedStepCardActions<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>, CardActions>>, "state" | "initialState" | "interactions" | "cardActions"> & {
579
+ steps: Steps;
580
+ state: PhaseStateSchema;
581
+ initialState?: (ctx: {
582
+ manifest: ContractManifest<Contract>;
583
+ state: ContractState<Contract>;
584
+ playerIds: PlayerIdOfState<ContractState<Contract>>[];
585
+ setup: SetupSelectionOfManifest<ContractManifest<Contract>> | null;
586
+ }) => z.infer<PhaseStateSchema>;
587
+ interactions?: Interactions;
588
+ cardActions?: CardActions;
589
+ }) => PhaseDefinition<SchemaLike<StepPhaseState<PhaseStateSchema, Steps>>, ContractState<Contract>, ContractManifest<Contract>, SubmitCollectors, Effects, UnwrappedStepInteractions<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>, Interactions>, Stages, Zones, UnwrappedStepCardActions<ScopedPhaseState<ContractState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, ContractManifest<Contract>, CardActions>>;
590
+
591
+ type ContractWithPhases = AnyReducerGameContract & {
592
+ readonly phases: Record<string, SchemaLike<object>>;
593
+ };
594
+ type BoundState<Contract extends ContractWithPhases> = ContractState<Contract>;
595
+ type BoundManifest<Contract extends ContractWithPhases> = ContractManifest<Contract>;
596
+ type BoundTable<Contract extends ContractWithPhases> = TableOfManifest<BoundManifest<Contract>>;
597
+ type BoundPhaseState<Contract extends ContractWithPhases, PhaseStateSchema extends SchemaLike<object>> = ScopedPhaseState<BoundState<Contract>, z.infer<PhaseStateSchema>>;
598
+ type BoundFormInputs<Contract extends ContractWithPhases> = ReturnType<typeof formInput.forState<BoundState<Contract>>>;
599
+ type BoundBoardInputs<Contract extends ContractWithPhases> = {
600
+ vertex<Id extends string = TiledVertexIdOfTable<BoundTable<Contract>, TiledBoardIdOfTable<BoundTable<Contract>>>>(options: {
601
+ target: BoardTargetRule<BoundState<Contract>, Id>;
602
+ dependsOn?: readonly InputFieldRef<string, unknown>[];
603
+ }): InputCollector<z.ZodType<Id>, BoundState<Contract>, "board-vertex">;
604
+ edge<Id extends string = TiledEdgeIdOfTable<BoundTable<Contract>, TiledBoardIdOfTable<BoundTable<Contract>>>>(options: {
605
+ target: BoardTargetRule<BoundState<Contract>, Id>;
606
+ dependsOn?: readonly InputFieldRef<string, unknown>[];
607
+ }): InputCollector<z.ZodType<Id>, BoundState<Contract>, "board-edge">;
608
+ tile<Id extends string = string>(options: {
609
+ target: BoardTargetRule<BoundState<Contract>, Id>;
610
+ dependsOn?: readonly InputFieldRef<string, unknown>[];
611
+ }): InputCollector<z.ZodType<Id>, BoundState<Contract>, "board-tile">;
612
+ space<Id extends string = TiledSpaceIdOfTable<BoundTable<Contract>, TiledBoardIdOfTable<BoundTable<Contract>>>>(options: {
613
+ target: BoardTargetRule<BoundState<Contract>, Id>;
614
+ dependsOn?: readonly InputFieldRef<string, unknown>[];
615
+ }): InputCollector<z.ZodType<Id>, BoundState<Contract>, "board-space">;
616
+ playerSpace<BoardId extends string = string, SpaceId extends string = string, PlayerId extends string = PlayerIdOfState<BoundState<Contract>>>(options: {
617
+ target: BoardTargetRule<BoundState<Contract>, PlayerBoardSpaceTarget<BoardId, SpaceId, PlayerId>>;
618
+ dependsOn?: readonly InputFieldRef<string, unknown>[];
619
+ }): InputCollector<z.ZodType<PlayerBoardSpaceTarget<BoardId, SpaceId, PlayerId>>, BoundState<Contract>, "board-space">;
620
+ };
621
+ type BoundCardInput<Contract extends ContractWithPhases> = <Id extends string = CardIdOfManifest<BoundManifest<Contract>>, const ZoneIds extends readonly string[] = readonly string[]>(options: {
622
+ target: CardTargetRule<BoundState<Contract>, Id, ZoneIds>;
623
+ dependsOn?: readonly InputFieldRef<string, unknown>[];
624
+ }) => InputCollector<z.ZodType<Id>, BoundState<Contract>, "card"> & {
625
+ readonly meta: {
626
+ readonly zoneId: ZoneIds[number];
627
+ readonly zoneIds: ZoneIds;
628
+ readonly targetKind: "card";
629
+ };
630
+ };
631
+ type BoundPromptInput<Contract extends ContractWithPhases> = <Schema extends SchemaLike<unknown>>(options: {
632
+ schema: Schema;
633
+ target?: ChoiceTargetRule<BoundState<Contract>, Extract<Schema extends z.ZodType<infer Value> ? Value : never, string>>;
634
+ }) => InputCollector<Schema, BoundState<Contract>, "prompt">;
635
+ type BoundRngInputs<Contract extends ContractWithPhases> = {
636
+ d6(count?: number): ReturnType<typeof rngInput.d6<BoundState<Contract>>>;
637
+ coin(): ReturnType<typeof rngInput.coin<BoundState<Contract>>>;
638
+ };
639
+ type BoundChoiceTarget<Contract extends ContractWithPhases> = {
640
+ options<Id extends string>(options: ReadonlyArray<ChoiceTargetOption<Id>> | ChoiceOptionsFactory<BoundState<Contract>, Id>): ChoiceTargetBuilder<BoundState<Contract>, Id>;
641
+ };
642
+ type BoundBoardTarget<Contract extends ContractWithPhases> = {
643
+ edge<Id extends string = string>(boardId: string): BoardTargetBuilder<BoundState<Contract>, Id>;
644
+ vertex<Id extends string = string>(boardId: string): BoardTargetBuilder<BoundState<Contract>, Id>;
645
+ space<Id extends string = string>(boardId: string): BoardTargetBuilder<BoundState<Contract>, Id>;
646
+ tile<Id extends string = string>(boardId: string): BoardTargetBuilder<BoundState<Contract>, Id>;
647
+ playerSpace<BoardId extends string, SpaceId extends string, PlayerId extends string = PlayerIdOfState<BoundState<Contract>>>(boardId: BoardId): BoardTargetBuilder<BoundState<Contract>, PlayerBoardSpaceTarget<BoardId, SpaceId, PlayerId>>;
648
+ };
649
+ type BoundCardTarget<Contract extends ContractWithPhases> = {
650
+ zones<Id extends string = CardIdOfState<BoundState<Contract>>, const ZoneIds extends readonly string[] = readonly string[]>(zoneIds: ZoneIds): CardTargetBuilder<BoundState<Contract>, Id, ZoneIds>;
651
+ };
652
+ type BoundInputBuilders<Contract extends ContractWithPhases> = {
653
+ readonly board: BoundBoardInputs<Contract>;
654
+ readonly boardTarget: BoundBoardTarget<Contract>;
655
+ readonly card: BoundCardInput<Contract>;
656
+ readonly cardTarget: BoundCardTarget<Contract>;
657
+ readonly choiceTarget: BoundChoiceTarget<Contract>;
658
+ readonly form: BoundFormInputs<Contract>;
659
+ readonly prompt: BoundPromptInput<Contract>;
660
+ readonly rng: BoundRngInputs<Contract>;
661
+ };
662
+ type StepPhaseInput<Contract extends ContractWithPhases, PhaseStateSchema extends SchemaLike<object>, Steps extends readonly [string, ...string[]], SubmitCollectors extends Record<string, InputCollector>, Effects extends EffectMap<BoundState<Contract>, BoundManifest<Contract>>, Interactions extends StepPhaseInteractionMap<Steps[number], ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>>, Stages extends StageMap<ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>>, Zones extends PhaseZoneList<BoundManifest<Contract>>, CardActions extends StepPhaseCardActionMap<Steps[number], ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>>> = Omit<PhaseDefinition<PhaseStateSchema, BoundState<Contract>, BoundManifest<Contract>, SubmitCollectors, Effects, UnwrappedStepInteractions<ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>, Interactions>, Stages, Zones, UnwrappedStepCardActions<ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>, CardActions>>, "state" | "initialState" | "interactions" | "cardActions"> & {
663
+ steps: Steps;
664
+ state?: never;
665
+ initialState?: (ctx: {
666
+ manifest: BoundManifest<Contract>;
667
+ state: BoundState<Contract>;
668
+ playerIds: PlayerIdOfState<BoundState<Contract>>[];
669
+ setup: SetupSelectionOfManifest<BoundManifest<Contract>> | null;
670
+ }) => InferPhaseState<PhaseStateSchema>;
671
+ interactions?: Interactions;
672
+ cardActions?: CardActions;
673
+ };
674
+ type PhaseAuthoring<Contract extends ContractWithPhases, PhaseStateSchema extends SchemaLike<object>> = {
675
+ interaction<Collectors extends Record<string, InputCollector>>(spec: InteractionSpec<Collectors, BoundPhaseState<Contract, PhaseStateSchema>, BoundManifest<Contract>, ContractErrorCode<Contract>>): InteractionSpec<Collectors, BoundPhaseState<Contract, PhaseStateSchema>, BoundManifest<Contract>, ContractErrorCode<Contract>>;
676
+ cardAction<Collectors extends Record<string, InputCollector> = Record<string, never>, const PlayFrom extends PlayerZoneIdOfManifest<BoundManifest<Contract>> = PlayerZoneIdOfManifest<BoundManifest<Contract>>>(spec: CardActionSpec<Collectors, BoundPhaseState<Contract, PhaseStateSchema>, BoundManifest<Contract>, PlayFrom, ContractErrorCode<Contract>>): CardActionSpec<Collectors, BoundPhaseState<Contract, PhaseStateSchema>, BoundManifest<Contract>, PlayFrom, ContractErrorCode<Contract>>;
677
+ rule<Collectors extends Record<string, InputCollector> = Record<string, InputCollector>>(rule: InteractionRule<Collectors, BoundPhaseState<Contract, PhaseStateSchema>, BoundManifest<Contract>, ContractErrorCode<Contract>>): InteractionRule<Collectors, BoundPhaseState<Contract, PhaseStateSchema>, BoundManifest<Contract>, ContractErrorCode<Contract>>;
678
+ define<SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<BoundState<Contract>, BoundManifest<Contract>> = Record<string, never>, Interactions extends InteractionMap<BoundPhaseState<Contract, PhaseStateSchema>, BoundManifest<Contract>> = Record<string, never>, Stages extends StageMap<BoundPhaseState<Contract, PhaseStateSchema>, BoundManifest<Contract>> = Record<string, never>, const Zones extends PhaseZoneList<BoundManifest<Contract>> = readonly [], CardActions extends CardActionMap<BoundPhaseState<Contract, PhaseStateSchema>, BoundManifest<Contract>> = Record<string, never>>(definition: Omit<PhaseDefinition<PhaseStateSchema, BoundState<Contract>, BoundManifest<Contract>, SubmitCollectors, Effects, Interactions, Stages, Zones, CardActions>, "state">): PhaseDefinition<PhaseStateSchema, BoundState<Contract>, BoundManifest<Contract>, SubmitCollectors, Effects, Interactions, Stages, Zones, CardActions>;
679
+ stepPhase<const Steps extends readonly [string, ...string[]], SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<BoundState<Contract>, BoundManifest<Contract>> = Record<string, never>, Interactions extends StepPhaseInteractionMap<Steps[number], ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>> = Record<string, never>, const Zones extends PhaseZoneList<BoundManifest<Contract>> = readonly [], CardActions extends StepPhaseCardActionMap<Steps[number], ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>> = Record<string, never>>(definition: StepPhaseInput<Contract, PhaseStateSchema, Steps, SubmitCollectors, Effects, Interactions, Stages, Zones, CardActions>): PhaseDefinition<SchemaLike<StepPhaseState<PhaseStateSchema, Steps>>, BoundState<Contract>, BoundManifest<Contract>, SubmitCollectors, Effects, UnwrappedStepInteractions<ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>, Interactions>, Stages, Zones, UnwrappedStepCardActions<ScopedPhaseState<BoundState<Contract>, StepPhaseState<PhaseStateSchema, Steps>>, BoundManifest<Contract>, CardActions>>;
680
+ readonly inputs: BoundInputBuilders<Contract>;
681
+ };
682
+ type ContractAuthoring<Contract extends ContractWithPhases> = {
683
+ readonly contract: Contract;
684
+ game<Definitions extends PhaseMapOf<Contract>, Views extends ViewMapOf<Contract> = Record<string, never>>(definition: Omit<ReducerGameDefinition<Contract, Definitions, Views>, "contract">): ReducerGameDefinition<Contract, Definitions, Views>;
685
+ view<Projection>(definition: ViewDefinition<BoundState<Contract>, BoundManifest<Contract>, Projection>): ViewDefinition<BoundState<Contract>, BoundManifest<Contract>, Projection>;
686
+ staticView<Projection>(definition: StaticViewDefinition<ExactManifestContractOf<Contract>, Projection>): StaticViewDefinition<ExactManifestContractOf<Contract>, Projection>;
687
+ phase<Name extends PhaseNameOfContract<Contract>>(name: Name): PhaseAuthoring<Contract, PhaseSchemasOfContract<Contract>[Name]>;
688
+ };
689
+ declare function createContractAuthoring<const Contract extends ContractWithPhases>(contract: Contract): ContractAuthoring<Contract>;
690
+
691
+ type EffectRollDieInput<Contract extends AnyReducerGameContract, Id extends string, ContextSchema extends AnySchema> = {
692
+ type: "rollDie";
693
+ id: Id;
694
+ context?: ContextSchema;
695
+ reduce?: ContinuationCallable<ContextSchema, ContractState<Contract>, ContractManifest<Contract>, Id, "rollDie">["reduce"];
696
+ };
697
+ type EffectShuffleInput<Contract extends AnyReducerGameContract, Id extends string, ContextSchema extends AnySchema> = {
698
+ type: "shuffleSharedZone";
699
+ id: Id;
700
+ context?: ContextSchema;
701
+ reduce?: ContinuationCallable<ContextSchema, ContractState<Contract>, ContractManifest<Contract>, Id, "shuffleSharedZone">["reduce"];
702
+ };
703
+ type EffectShufflePlayerZoneInput<Contract extends AnyReducerGameContract, Id extends string, ContextSchema extends AnySchema> = {
704
+ type: "shufflePlayerZone";
705
+ id: Id;
706
+ context?: ContextSchema;
707
+ reduce?: ContinuationCallable<ContextSchema, ContractState<Contract>, ContractManifest<Contract>, Id, "shufflePlayerZone">["reduce"];
708
+ };
709
+ declare function defineEffect<Contract extends AnyReducerGameContract>(): {
710
+ <Id extends string, ContextSchema extends AnySchema = z.ZodObject<Record<string, never>, z.core.$strip>>(definition: EffectRollDieInput<Contract, Id, ContextSchema>): EffectRollDieDefinition<Id, ContextSchema, ContractState<Contract>, ContractManifest<Contract>>;
711
+ <Id extends string, ContextSchema extends AnySchema = z.ZodObject<Record<string, never>, z.core.$strip>>(definition: EffectShuffleInput<Contract, Id, ContextSchema>): EffectShuffleDefinition<Id, ContextSchema, ContractState<Contract>, ContractManifest<Contract>>;
712
+ <Id extends string, ContextSchema extends AnySchema = z.ZodObject<Record<string, never>, z.core.$strip>>(definition: EffectShufflePlayerZoneInput<Contract, Id, ContextSchema>): EffectShufflePlayerZoneDefinition<Id, ContextSchema, ContractState<Contract>, ContractManifest<Contract>>;
713
+ };
714
+
715
+ declare function defineGame<const Contract extends AnyReducerGameContract, Definitions extends PhaseMapOf<Contract>, Views extends ViewMapOf<Contract> = Record<string, never>>(definition: {
716
+ contract: Contract;
717
+ } & Omit<ReducerGameDefinition<NoInfer<Contract>, Definitions, Views>, "contract">): ReducerGameDefinition<Contract, Definitions, Views>;
718
+
719
+ declare function defineInteraction<Contract extends AnyReducerGameContract, PhaseState extends PhaseStateInput = SchemaLike<object>>(): <Collectors extends Record<string, InputCollector>>(definition: InteractionSpec<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>, ContractErrorCode<Contract>>) => InteractionSpec<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>, ContractErrorCode<Contract>>;
720
+ declare function defineInteractionRule<Contract extends AnyReducerGameContract, PhaseState extends PhaseStateInput = SchemaLike<object>>(): <Collectors extends Record<string, InputCollector> = Record<string, InputCollector>>(definition: InteractionRule<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>, ContractErrorCode<Contract>>) => InteractionRule<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>, ContractErrorCode<Contract>>;
721
+ declare function defineCardAction<Contract extends AnyReducerGameContract, PhaseState extends PhaseStateInput>(): <Collectors extends Record<string, InputCollector> = Record<string, never>, const PlayFrom extends PlayerZoneIdOfManifest<ContractManifest<Contract>> = PlayerZoneIdOfManifest<ContractManifest<Contract>>>(definition: CardActionSpec<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>, PlayFrom, ContractErrorCode<Contract>>) => CardActionSpec<Collectors, ScopedPhaseState<ContractState<Contract>, InferPhaseState<PhaseState>>, ContractManifest<Contract>, PlayFrom, ContractErrorCode<Contract>>;
722
+
723
+ declare function defineView<Contract extends AnyReducerGameContract>(): <Projection>(definition: ViewDefinition<ContractState<Contract>, ContractManifest<Contract>, Projection>) => ViewDefinition<ContractState<Contract>, ContractManifest<Contract>, Projection>;
724
+ /**
725
+ * Factory for the session-scoped static view (see {@link StaticViewDefinition}).
726
+ * Kept separate from {@link defineView} because the argument shape is
727
+ * structurally different: it exposes only the manifest and generated static
728
+ * queries, with no `state`, `playerId`, `runtime`, `fx`, `ops`, or
729
+ * `accept/reject`. That shape is what prevents authors from accidentally
730
+ * projecting per-tick state into the once-per-session payload.
731
+ */
732
+ declare function defineStaticView<Contract extends AnyReducerGameContract>(): <Projection>(definition: StaticViewDefinition<ExactManifestContractOf<Contract>, Projection>) => StaticViewDefinition<ExactManifestContractOf<Contract>, Projection>;
733
+ declare function defineStage<Contract extends AnyReducerGameContract>(): (definition: StageSpec<ContractState<Contract>, ContractManifest<Contract>>) => StageSpec<ContractState<Contract>, ContractManifest<Contract>>;
734
+ declare function definePhaseStage<Contract extends AnyReducerGameContract, PhaseStateSchema extends SchemaLike<object>>(): (definition: StageSpec<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>>) => StageSpec<ScopedPhaseState<ContractState<Contract>, z.infer<PhaseStateSchema>>, ContractManifest<Contract>>;
735
+
3640
736
  type SparseMap<Key extends string, Value> = Partial<Record<Key, Value>>;
3641
737
  type SparseCounts<Key extends string> = SparseMap<Key, number>;
3642
738
  declare function sparseMap<KeySchema extends z.ZodType<string>, ValueSchema extends z.ZodTypeAny>(keySchema: KeySchema, valueSchema: ValueSchema): z.ZodType<SparseMap<z.infer<KeySchema>, z.infer<ValueSchema>>>;
3643
739
  declare function sparseCounts<KeySchema extends z.ZodType<string>>(keySchema: KeySchema): z.ZodType<SparseCounts<z.infer<KeySchema>>>;
3644
740
  declare function normalizeCommandParams<Output>(schema: SchemaLike<Output>, input: unknown): Output;
3645
741
 
742
+ declare function createTableQueries<Table extends RuntimeTableRecord>(table: Table): TableQueries<Table>;
743
+ declare function createStateQueries<State extends {
744
+ table: RuntimeTableRecord;
745
+ }>(state: State): TableQueriesOfState<State>;
746
+
747
+ type InteractionExplanation = {
748
+ interactionId: string;
749
+ phase: string;
750
+ step: string | null;
751
+ availability: "available" | "notYourTurn" | "wrongPhase" | "wrongStep" | "blocked";
752
+ rules: ReadonlyArray<{
753
+ ruleId: string;
754
+ outcome: "passed" | "failed" | "notEvaluated";
755
+ errorCode?: string;
756
+ message?: string;
757
+ }>;
758
+ actor: {
759
+ required: readonly string[];
760
+ playerIsActor: boolean;
761
+ };
762
+ inputs: ReadonlyArray<{
763
+ key: string;
764
+ kind: string;
765
+ eligibleCount: number | "lazy";
766
+ }>;
767
+ };
768
+ type InteractionDiagnosticsMode = "verbose" | undefined;
769
+
770
+ type ReducerBundleOptions = {
771
+ /**
772
+ * Host-owned reducer diagnostics sink. Events are summarized and must not
773
+ * contain reducer state.
774
+ *
775
+ * The legacy `"verbose"` value is retained as an additive alias for
776
+ * descriptorDiagnostics while existing callers migrate.
777
+ */
778
+ diagnostics?: ReducerDiagnosticsSink | InteractionDiagnosticsMode;
779
+ descriptorDiagnostics?: InteractionDiagnosticsMode;
780
+ };
3646
781
  type ReducerBundle = ReducerBundleContract & {
3647
782
  createInProcessRuntime(): {
3648
783
  initialize(input: {
@@ -3692,6 +827,10 @@ type ReducerBundle = ReducerBundleContract & {
3692
827
  }>;
3693
828
  interactionsByRef: Record<string, unknown>;
3694
829
  };
830
+ explainInteraction(input: {
831
+ playerId: unknown;
832
+ interactionId: string;
833
+ }): InteractionExplanation;
3695
834
  snapshot(): unknown;
3696
835
  unsafeState(): unknown;
3697
836
  };
@@ -3700,81 +839,47 @@ type ReducerBundle = ReducerBundleContract & {
3700
839
  playerId: unknown;
3701
840
  viewId?: string;
3702
841
  }): unknown;
842
+ explainInteraction(input: {
843
+ state: unknown;
844
+ playerId: unknown;
845
+ interactionId: string;
846
+ }): InteractionExplanation;
3703
847
  };
3704
848
 
3705
- declare function createReducerBundle<Contract extends ReducerGameContractLike, Definitions extends PhaseMapOf<Contract>, Views extends ViewMapOf<Contract>>(definition: ReducerGameDefinition<Contract, Definitions, Views>): ReducerBundle;
849
+ declare function createReducerBundle<Contract extends ReducerGameContractLike, Definitions extends PhaseMapOf<Contract>, Views extends ViewMapOf<Contract>>(definition: ReducerGameDefinition<Contract, Definitions, Views>, options?: ReducerBundleOptions): ReducerBundle;
3706
850
 
3707
- type ClientParamSchema = {
3708
- safeParse: (value: unknown) => {
3709
- success: true;
3710
- data: Record<string, unknown>;
3711
- } | {
3712
- success: false;
3713
- error: {
3714
- issues: Array<{
3715
- path: PropertyKey[];
3716
- message: string;
3717
- }>;
3718
- };
3719
- };
851
+ type FingerprintableContract = ReducerGameContractLike & {
852
+ phases?: Record<string, z.ZodTypeAny>;
853
+ errors?: Record<string, string> | undefined;
3720
854
  };
3721
- type ClientParamSchemasByPhase = Readonly<Record<string, Readonly<Record<string, ClientParamSchema>>>>;
3722
- declare function createClientParamSchemasByPhase<Contract extends ReducerGameContractLike, Definitions extends PhaseMapOf<Contract>, Views extends ViewMapOf<Contract>>(definition: ReducerGameDefinition<Contract, Definitions, Views>): ClientParamSchemasByPhase;
3723
-
3724
- type StatefulBootstrapContext = {
3725
- table: RuntimeTableRecord;
3726
- runtime: {
3727
- rng: RuntimeRngState;
855
+ type FingerprintableDefinition = {
856
+ contract: FingerprintableContract;
857
+ phases?: Record<string, z.ZodTypeAny | {
858
+ state?: z.ZodTypeAny;
859
+ }>;
860
+ };
861
+ type ContractFingerprint = {
862
+ /** "cfp1:" + first 16 hex chars of sha256 over the canonical payload. */
863
+ value: string;
864
+ /** Component hashes that fed the final fingerprint. */
865
+ parts: {
866
+ manifest: string;
867
+ publicState: string;
868
+ privateState: string;
869
+ hiddenState: string;
870
+ phases: Record<string, string>;
871
+ errors: string;
3728
872
  };
3729
873
  };
3730
- declare function applySetupBootstrap<State extends StatefulBootstrapContext>(state: State, steps: readonly SetupBootstrapStep[]): State;
3731
-
3732
- declare function shuffle<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike>(container: SetupBootstrapContainerRef<Manifest>): SetupBootstrapStep<Manifest>;
3733
- declare function dealToPlayerZone<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike>({ from, zoneId, count, playerIds, }: {
3734
- from: Extract<SetupBootstrapContainerRef<Manifest>, {
3735
- type: "sharedZone" | "sharedBoardContainer";
3736
- }>;
3737
- zoneId: Extract<SetupBootstrapPerPlayerContainerTemplateRef<Manifest>, {
3738
- type: "playerZone";
3739
- }>["zoneId"];
3740
- count: number;
3741
- playerIds?: readonly PlayerIdOfManifest<Manifest>[];
3742
- }): SetupBootstrapStep<Manifest>;
3743
- declare function dealToPlayerBoardContainer<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike>({ from, boardId, containerId, count, playerIds, }: {
3744
- from: Extract<SetupBootstrapContainerRef<Manifest>, {
3745
- type: "sharedZone" | "sharedBoardContainer";
3746
- }>;
3747
- boardId: Extract<SetupBootstrapPerPlayerContainerTemplateRef<Manifest>, {
3748
- type: "playerBoardContainer";
3749
- }>["boardId"];
3750
- containerId: Extract<SetupBootstrapPerPlayerContainerTemplateRef<Manifest>, {
3751
- type: "playerBoardContainer";
3752
- }>["containerId"];
3753
- count: number;
3754
- playerIds?: readonly PlayerIdOfManifest<Manifest>[];
3755
- }): SetupBootstrapStep<Manifest>;
3756
- declare function seedSharedBoardContainer<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike>({ from, boardId, containerId, count, componentIds, }: {
3757
- from: SetupBootstrapContainerRef<Manifest>;
3758
- boardId: Extract<SetupBootstrapDestinationRef<Manifest>, {
3759
- type: "sharedBoardContainer";
3760
- }>["boardId"];
3761
- containerId: Extract<SetupBootstrapDestinationRef<Manifest>, {
3762
- type: "sharedBoardContainer";
3763
- }>["containerId"];
3764
- count?: number;
3765
- componentIds?: readonly (CardIdOfManifest<Manifest> | PieceIdOfManifest<Manifest> | DieIdOfManifest<Manifest>)[];
3766
- }): SetupBootstrapStep<Manifest>;
3767
- declare function seedSharedBoardSpace<Manifest extends GeneratedManifestContractLike = GeneratedManifestContractLike>({ from, boardId, spaceId, count, componentIds, }: {
3768
- from: SetupBootstrapContainerRef<Manifest>;
3769
- boardId: Extract<SetupBootstrapDestinationRef<Manifest>, {
3770
- type: "sharedBoardSpace";
3771
- }>["boardId"];
3772
- spaceId: Extract<SetupBootstrapDestinationRef<Manifest>, {
3773
- type: "sharedBoardSpace";
3774
- }>["spaceId"];
3775
- count?: number;
3776
- componentIds?: readonly (CardIdOfManifest<Manifest> | PieceIdOfManifest<Manifest> | DieIdOfManifest<Manifest>)[];
3777
- }): SetupBootstrapStep<Manifest>;
874
+ /**
875
+ * Compute a stable shape fingerprint for stale generated artifacts.
876
+ *
877
+ * The fingerprint intentionally tracks decoded shape, not semantic refinements:
878
+ * Zod schemas are converted with `unrepresentable: "any"`, so refinements and
879
+ * custom validators that do not affect the JSON shape do not invalidate stored
880
+ * sessions or generated base states.
881
+ */
882
+ declare function contractFingerprint(source: FingerprintableContract | FingerprintableDefinition): ContractFingerprint;
3778
883
 
3779
884
  declare function assertCardAllowedInContainer<Table extends RuntimeTableRecord, BoardId extends BoardIdOfTable<NoInfer<Table>>, ContainerId extends BoardContainerIdOfTable<NoInfer<Table>, BoardId>>(table: Table, boardId: BoardId, containerId: ContainerId, componentId: string): void;
3780
885
 
@@ -3784,9 +889,4 @@ declare function setActivePlayers<State extends {
3784
889
  };
3785
890
  }>(state: State, activePlayers: PlayerIdOfState<State>[]): State;
3786
891
 
3787
- declare function createTableQueries<Table extends RuntimeTableRecord>(table: Table): TableQueries<Table>;
3788
- declare function createStateQueries<State extends {
3789
- table: RuntimeTableRecord;
3790
- }>(state: State): TableQueriesOfState<State>;
3791
-
3792
- export { type ActionContext, type BoardBaseIdOfManifest, type BoardContainerIdOfManifest, type BoardContainerIdOfTable, type BoardIdOfManifest, type BoardIdOfTable, type BoardInteractionKeyOfDefinition, type BoardLayoutOfManifest, type BoardMapOfTable, type BoardRef, type BoardStateOfTable, type BoardTargetBuilder, type BoardTargetPredicate, type BoardTargetRule, type BoardTypeIdOfManifest, type BoardTypeIdOfTable, type BoundTargetRule, type CardIdOfDeck, type CardIdOfHand, type CardIdOfManifest, type CardIdOfState, type CardIdOfTable, type CardInputZoneIdsOfDefinition, type CardInteractionKeyOfDefinition, type CardTargetBuilder, type CardTargetPredicate, type CardTargetRule, type ChoiceOption, type ChoiceOptionsFactory, type ChoiceTargetBuilder, type ChoiceTargetOption, type ChoiceTargetPredicate, type ChoiceTargetRule, type ClientParamSchema, type ClientParamSchemasByPhase, type ClientParamsOf, type ClientParamsOfInteractionOfDefinition, type CompatibleCardIdForHandAndDeck, type CompatibleHandIdForDeck, type ComponentDataOfTable, type ComponentIdOfTable, type ComponentLocationByTypeOfTable, type ComponentLocationOfTable, type ContinuationCallable, type ContinuationInput, type ContinuationResponseOf, type ContinuationSourceKind, type ContinuationToken, type DeckCardsOfTable, type DeckIdOfState, type DeckIdOfTable, type DefaultedClientParamKeysOfInteractionOfDefinition, type DefinedInputs, type DependencyValues, type DerivedDefinition, type DerivedResolver, type DieIdOfManifest, type EdgeTypeIdOfManifest, type EffectContinuationCallable, type EffectContinuationInput, type EffectContinuationResponse, type EffectDefinition, type EffectIdsOfDefinition, type EffectMap, type EffectRollDieDefinition, type EffectShuffleDefinition, type GameStateOf, type HandCardsOfTable, type HandIdOfState, type HandIdOfTable, type HexBoardIdOfTable, type HexEdgeIdOfTable, type HexEdgeTypeIdOfTable, type HexSpaceIdOfTable, type HexSpaceTypeIdOfTable, type HexVertexIdOfTable, type HexVertexTypeIdOfTable, type InitContext, type InitialStateCallbacks, type InputCollector, type InputCollectorKind, type InputFieldRef, type InputKeysWithCollectorKindOfDefinition, type InteractionAvailabilityArgs, type InteractionIdOfDefinition, type InteractionIdOfDefinitionPhase, type InteractionKind, type InteractionMap, type InteractionRule, type InteractionSpec, type InteractionToArgs, type InteractionValidateArgs, type ManifestIdSchema, type ManifestOf, type ManyOptions, type Op, type ParamsOf, type ParamsOfInteractionOfDefinition, type PerPlayer, type PerPlayerBoardRef, type PerPlayerSchemaOptions, type PhaseDefinitionByName, type PhaseMapOf, type PhaseNameOf, type PhaseNamesOfDefinition, type PhaseZoneList, type PieceIdOfManifest, type PlayableInteractionsOfZoneOfDefinition, type PlayerBoardSpaceTarget, type PlayerId, type PlayerIdOfManifest, type PlayerIdOfState, type PlayerIdOfTable, type PlayerZoneIdOfManifest, type PlayerZoneIdOfState, type PlayerZoneIdOfTable, type PromptInteractionKeyOfDefinition, type ReducerAccept, type ReducerBundle, type ReducerEdit, type ReducerGameContract, type ReducerGameDefinition, type ReducerManifestContract, type ReducerOps, type ReducerPhaseDefinition, type ReducerReject, type ReducerResult, type ReducerStateBase, type ReducerTransaction, type ReducerValidationResult, type ReducerViewDefinition, type RelationTypeIdOfManifest, type RelationTypeIdOfTable, type ResolvedContainerLocation, type ResolvedDeckLocation, type ResolvedEdgeLocation, type ResolvedHandLocation, type ResolvedSlotLocation, type ResolvedSpaceLocation, type ResolvedVertexLocation, type ResolvedZoneLocation, type ResumableEffectKind, type RollDieContinuationResponse, type RotatePlayerZoneArgs, type RuntimeCardData, type RuntimeCardVisibility, type RuntimeComponentLocation, type RuntimeDieData, type RuntimeHandVisibilityMode, type RuntimePayload, type RuntimePieceData, type RuntimeRecord, type RuntimeSetupSelection, type RuntimeSetupSelectionInput, type RuntimeTableRecord, type RuntimeZoneMap, type SetupBootstrapContainerRef, type SetupBootstrapDestinationRef, type SetupBootstrapPerPlayerContainerTemplateRef, type SetupBootstrapStep, type SetupOptionChoiceMetadata, type SetupOptionIdOfManifest, type SetupOptionMetadata, type SetupProfileDefinition, type SetupProfileIdOfManifest, type SetupProfileMetadata, type SetupSelectionInputOfManifest, type SetupSelectionOfManifest, type SharedBoardRef, type SharedZoneIdOfManifest, type SharedZoneIdOfState, type SharedZoneIdOfTable, type ShuffleSharedZoneContinuationResponse, type SpaceIdOfManifest, type SpaceIdOfTable, type SpaceTypeIdOfManifest, type SpaceTypeIdOfTable, type SparseCounts, type SparseMap, type SquareBoardIdOfTable, type SquareEdgeIdOfTable, type SquareEdgeTypeIdOfTable, type SquareSpaceIdOfTable, type SquareSpaceTypeIdOfTable, type SquareVertexIdOfTable, type SquareVertexTypeIdOfTable, type StageMap, type StageNamesOfDefinitionPhase, type StageSpec, type StaticBoards, type StaticViewDefinition, type StaticViewQueries, type TableQueries, type TableQueriesOfState, type TargetContext, type TargetPredicate, type TargetPredicateArgs, type TargetRule, type TargetRuleBuilder, type TiledBoardIdOfTable, type TiledEdgeIdOfTable, type TiledEdgeMap, type TiledEdgeTypeIdOfTable, type TiledSpaceIdOfTable, type TiledSpaceMap, type TiledVertexIdOfTable, type TiledVertexMap, type TiledVertexTypeIdOfTable, type VertexTypeIdOfManifest, type ViewNamesOfDefinition, type ViewOfDefinition, type ZoneIdsOfDefinition, applySetupBootstrap, asPlayerId, assertCardAllowedInContainer, assumeManifestSchema, boardInput, boardRef, boardRefKey, boardRefSchema, boardTarget, cardInput, cardTarget, choiceTarget, cloneManifestDefault, createClientParamSchemasByPhase, createDerivedResolver, createManifestGameStateSchema, createManifestRuntimeSchema, createManifestStringLiteralSchema, createReducerBundle, createReducerEdit, createReducerOps, createReducerTransaction, createStateQueries, createTableQueries, dealToPlayerBoardContainer, dealToPlayerZone, defineCardAction, defineDerived, defineEffect, defineGame, defineGameContract, defineInputs, defineInteraction, defineInteractionRule, definePhase, definePhaseStage, defineStage, defineStaticView, defineStepPhase, defineView, formInput, isPerPlayer, isPerPlayerBoardRef, isPlayerId, isSharedBoardRef, many, markManifestScopedSchema, normalizeCommandParams, parseBoardRefKey, perPlayer, perPlayerBoardRef, perPlayerEntries, perPlayerGet, perPlayerHas, perPlayerKeys, perPlayerMap, perPlayerRequire, perPlayerSchema, perPlayerSet, perPlayerSize, perPlayerValues, pipe, promptInput, resolveManifestPlayerIds, rngInput, seedSharedBoardContainer, seedSharedBoardSpace, setActivePlayers, sharedBoardRef, shuffle, sparseCounts, sparseMap };
892
+ export { type BoardTargetBuilder, type BoardTargetPredicate, type BoardTargetRule, type BoundInputBuilders, type BoundTargetRule, type CardTargetBuilder, type CardTargetPredicate, type CardTargetRule, type ChoiceOptionsFactory, type ChoiceTargetBuilder, type ChoiceTargetOption, type ChoiceTargetPredicate, type ChoiceTargetRule, type ContractAuthoring, type ContractFingerprint, type ContractWithPhases, type DefinedInputs, type DependencyValues, DerivedResolver, ErrorCodeOfContract, type InputFieldRef, InteractionRule, type ManyOptions, type PhaseAuthoring, PhaseMapOf, type PlayerBoardSpaceTarget, type ReducerBundle, type ReducerBundleOptions, ReducerDiagnosticsSink, ReducerGameContract, ReducerGameDefinition, type ReducerPhaseDefinition, type ReducerViewDefinition, type SparseCounts, type SparseMap, TableQueries, TableQueriesOfState, type TargetContext, type TargetPredicate, type TargetPredicateArgs, type TargetRule, type TargetRuleBuilder, ValidationIssue, assertCardAllowedInContainer, boardInput, boardTarget, cardInput, cardTarget, choiceTarget, contractFingerprint, createContractAuthoring, createReducerBundle, createStateQueries, createTableQueries, defineCardAction, defineEffect, defineGame, defineGameContract, defineInputs, defineInteraction, defineInteractionRule, definePhase, definePhaseStage, defineStage, defineStaticView, defineStepPhase, defineView, formInput, many, normalizeCommandParams, promptInput, rngInput, setActivePlayers, sparseCounts, sparseMap };