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