@dreamboard-games/sdk 0.5.0-alpha.3 → 0.5.0-alpha.30

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 (40) hide show
  1. package/README.md +344 -21
  2. package/dist/board-element-DXLPBVk-.d.ts +13 -0
  3. package/dist/{chunk-LRILEVKC.js → chunk-63GWNBZX.js} +2763 -2327
  4. package/dist/chunk-63GWNBZX.js.map +1 -0
  5. package/dist/{chunk-SP234IY4.js → chunk-BVWJS3AB.js} +752 -343
  6. package/dist/chunk-BVWJS3AB.js.map +1 -0
  7. package/dist/{chunk-ZPRKWPEP.js → chunk-CWANHA4C.js} +284 -138
  8. package/dist/chunk-CWANHA4C.js.map +1 -0
  9. package/dist/chunk-CZRPUWCT.js +1602 -0
  10. package/dist/chunk-CZRPUWCT.js.map +1 -0
  11. package/dist/{chunk-FMM5LVJW.js → chunk-IEMZ26FI.js} +192 -383
  12. package/dist/chunk-IEMZ26FI.js.map +1 -0
  13. package/dist/{diagnostics-B0lgnuZ6.d.ts → diagnostics-D3mzqjxL.d.ts} +2 -3
  14. package/dist/extract-Bi6_tzUr.d.ts +6899 -0
  15. package/dist/index.d.ts +2058 -385
  16. package/dist/index.js +1260 -288
  17. package/dist/index.js.map +1 -1
  18. package/dist/react.d.ts +153 -8
  19. package/dist/react.js +1396 -30
  20. package/dist/react.js.map +1 -1
  21. package/dist/reducer.d.ts +592 -776
  22. package/dist/reducer.js +4617 -4055
  23. package/dist/reducer.js.map +1 -1
  24. package/dist/shortcuts-CuQXWAMv.d.ts +824 -0
  25. package/dist/testing.d.ts +59 -53
  26. package/dist/testing.js +335 -190
  27. package/dist/testing.js.map +1 -1
  28. package/dist/types-BlvVQ9WL.d.ts +125 -0
  29. package/package.json +17 -17
  30. package/dist/chunk-DMFVAZI2.js +0 -16
  31. package/dist/chunk-DMFVAZI2.js.map +0 -1
  32. package/dist/chunk-FMM5LVJW.js.map +0 -1
  33. package/dist/chunk-LRILEVKC.js.map +0 -1
  34. package/dist/chunk-SP234IY4.js.map +0 -1
  35. package/dist/chunk-VUWNJXLJ.js +0 -52
  36. package/dist/chunk-VUWNJXLJ.js.map +0 -1
  37. package/dist/chunk-ZPRKWPEP.js.map +0 -1
  38. package/dist/definition-BaHNPZol.d.ts +0 -4639
  39. package/dist/model-BHro6yXu.d.ts +0 -288
  40. package/dist/types-DimqnJBq.d.ts +0 -86
@@ -1,288 +0,0 @@
1
- import { z } from 'zod';
2
- import { Store } from '@tanstack/store';
3
- import { aY as ViewOfDefinition, a6 as PhaseNamesOfDefinition, O as InteractionIdOfDefinitionPhase, av as RuntimeJson, g as ClientParamsOfInteractionOfDefinition, u as InputDomain, G as GameEvent } from './definition-BaHNPZol.js';
4
- import { g as SourceSnapshot, h as SourceState, I as InteractionDescriptor, i as SubmitResult, G as GameSource } from './types-DimqnJBq.js';
5
-
6
- type PhaseName<G> = [PhaseNamesOfDefinition<G>] extends [never] ? string : PhaseNamesOfDefinition<G>;
7
- type InteractionKey<G> = unknown extends G ? string : [PhaseNamesOfDefinition<G>] extends [never] ? string : {
8
- [P in PhaseNamesOfDefinition<G>]: `${P}.${InteractionIdOfDefinitionPhase<G, P>}`;
9
- }[PhaseNamesOfDefinition<G>];
10
- type InteractionParams<G, K extends InteractionKey<G>> = unknown extends G ? Record<string, RuntimeJson> : K extends `${infer P}.${infer I}` ? P extends PhaseNamesOfDefinition<G> ? I extends InteractionIdOfDefinitionPhase<G, P> ? ClientParamsOfInteractionOfDefinition<G, P, I> : never : Record<string, RuntimeJson> : Record<string, RuntimeJson>;
11
- type InputKey<G, K extends InteractionKey<G>> = keyof InteractionParams<G, K> & string;
12
- type IdOf<G, K extends string> = G extends {
13
- contract: {
14
- manifest: {
15
- ids: Record<K, infer Schema extends z.ZodType>;
16
- };
17
- };
18
- } ? z.output<Schema> & string : string;
19
- type ViewOf<G> = [ViewOfDefinition<G>] extends [never] ? unknown : ViewOfDefinition<G>;
20
- type Drafts<G> = Readonly<Partial<{
21
- [K in InteractionKey<G>]: Readonly<Partial<InteractionParams<G, K>>>;
22
- }>>;
23
- interface LocalState<G> {
24
- readonly drafts: Drafts<G>;
25
- readonly activeInteraction: InteractionKey<G> | null;
26
- }
27
- interface Feature {
28
- readonly root?: object;
29
- readonly interaction?: object;
30
- readonly input?: object;
31
- readonly zone?: object;
32
- readonly card?: object;
33
- readonly board?: object;
34
- readonly dispose?: () => void;
35
- }
36
- type Features = Readonly<Record<string, Feature>>;
37
- type Intersection<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never;
38
- type Hook<F extends Features, H extends keyof Feature> = keyof F extends never ? Record<never, never> : Intersection<{
39
- [K in keyof F]: F[K] extends Record<H, infer A> ? A : Record<never, never>;
40
- }[keyof F]>;
41
- interface BoardBase<G, K extends IdOf<G, "boardId"> = IdOf<G, "boardId">> {
42
- readonly id: K;
43
- readonly game: CoreInstance<G>;
44
- readonly data: Readonly<object>;
45
- }
46
- type Board<G, F extends Features, K extends IdOf<G, "boardId"> = IdOf<G, "boardId">> = BoardBase<G, K> & Hook<F, "board"> & {
47
- readonly game: GameInstance<G, F>;
48
- };
49
- interface BoardCollection<G, F extends Features = Record<never, never>> {
50
- get<K extends IdOf<G, "boardId">>(id: K): Board<G, F, K> | undefined;
51
- getAll(): readonly Board<G, F>[];
52
- }
53
- type RootHooks<G, F extends Features> = {
54
- [K in keyof Hook<F, "root">]: Hook<F, "root">[K] extends BoardCollection<G> ? BoardCollection<G, F> : Hook<F, "root">[K];
55
- };
56
- interface FeatureContext<G> {
57
- createBoard<K extends IdOf<G, "boardId">, Data extends object>(id: K, data: Data): BoardBase<G, K> & {
58
- readonly data: Readonly<Data>;
59
- };
60
- routeTarget(kind: "card" | "space" | "edge" | "vertex" | "tile", id: string, options?: {
61
- interaction?: InteractionKey<G>;
62
- boardId?: IdOf<G, "boardId">;
63
- }): void;
64
- routeCardDrop(cardId: IdOf<G, "cardId">, target: {
65
- kind: "space" | "edge" | "vertex" | "tile";
66
- id: string;
67
- boardId?: IdOf<G, "boardId">;
68
- interaction?: InteractionKey<G>;
69
- }): void;
70
- invalidate(): void;
71
- }
72
- interface NativeEvent {
73
- preventDefault(): void;
74
- }
75
- interface FieldEvent {
76
- readonly currentTarget: {
77
- readonly value: string;
78
- readonly valueAsNumber?: number;
79
- };
80
- }
81
- type ActionProps = {
82
- readonly onClick: (event?: NativeEvent) => void;
83
- readonly disabled: boolean;
84
- readonly type: "button";
85
- readonly [key: `data-${string}`]: string | number | boolean | undefined;
86
- };
87
- interface Player<G> {
88
- readonly id: IdOf<G, "playerId">;
89
- readonly index: number;
90
- readonly name: string;
91
- readonly color?: string;
92
- readonly isMe: boolean;
93
- readonly game: CoreInstance<G>;
94
- }
95
- interface Phase<G> {
96
- readonly current: PhaseName<G> | null;
97
- is(name: PhaseName<G>): boolean;
98
- switch<R>(routes: {
99
- [P in PhaseName<G>]: () => R;
100
- }): R | null;
101
- }
102
- interface Turn<G> {
103
- readonly activePlayerIds: readonly IdOf<G, "playerId">[];
104
- readonly currentPlayerId: IdOf<G, "playerId"> | null;
105
- readonly order: readonly IdOf<G, "playerId">[];
106
- readonly isMine: boolean;
107
- }
108
- interface InputBase<G, K extends InteractionKey<G>, N extends InputKey<G, K>> {
109
- readonly key: N;
110
- readonly kind: string;
111
- readonly game: CoreInstance<G>;
112
- readonly interaction: InteractionBase<G, K>;
113
- getDomain(): InputDomain;
114
- getValue(): InteractionParams<G, K>[N] | undefined;
115
- setValue(value: Exclude<InteractionParams<G, K>[N], undefined>): void;
116
- clear(): void;
117
- getIsReady(): boolean;
118
- getEligibleTargets(): readonly RuntimeJson[];
119
- getIsEligible(value: RuntimeJson): boolean;
120
- getIsSelected(value: RuntimeJson): boolean;
121
- getSelectHandler(value: RuntimeJson): () => void;
122
- getTargetProps(value: RuntimeJson): ActionProps;
123
- getFieldProps(): {
124
- value: InteractionParams<G, K>[N] | "";
125
- disabled: boolean;
126
- onChange(event: FieldEvent): void;
127
- readonly [key: `data-${string}`]: string | number | boolean | undefined;
128
- };
129
- }
130
- type Input<G, F extends Features, K extends InteractionKey<G>, N extends InputKey<G, K>> = Omit<InputBase<G, K, N>, "interaction" | "game"> & Hook<F, "input"> & {
131
- readonly game: GameInstance<G, F>;
132
- readonly interaction: Interaction<G, F, K>;
133
- };
134
- interface InteractionBase<G, K extends InteractionKey<G>> {
135
- readonly key: K;
136
- readonly id: string;
137
- readonly phase: PhaseName<G>;
138
- readonly label: string;
139
- readonly help?: string;
140
- readonly kind: "inputs" | "steps";
141
- readonly game: CoreInstance<G>;
142
- getAvailability(): InteractionDescriptor["availability"];
143
- getIsAvailable(): boolean;
144
- getUnavailableReason(): string | null;
145
- getStep(): InteractionDescriptor["step"] | null;
146
- getStepIndex(): number | null;
147
- getIsReady(): boolean;
148
- getMissingInputs(): readonly string[];
149
- getStatus(): "open" | "submitting" | "submitted";
150
- submit(): Promise<SubmitResult>;
151
- cancel(): Promise<SubmitResult>;
152
- reset(): void;
153
- activate(): void;
154
- getSubmitHandler(): (event?: NativeEvent) => void;
155
- getSubmitProps(): ActionProps;
156
- }
157
- type Interaction<G, F extends Features, K extends InteractionKey<G>> = InteractionBase<G, K> & Hook<F, "interaction"> & {
158
- readonly game: GameInstance<G, F>;
159
- getInput<N extends InputKey<G, K>>(key: N): Input<G, F, K, N> | undefined;
160
- getInputs(): readonly Input<G, F, K, InputKey<G, K>>[];
161
- };
162
- type ReadonlyData<T> = T extends readonly (infer Item)[] ? readonly ReadonlyData<Item>[] : T extends object ? {
163
- readonly [K in keyof T]: ReadonlyData<T[K]>;
164
- } : T;
165
- type CardDataOf<G, K extends string> = G extends {
166
- contract: {
167
- manifest: {
168
- tableSchema: infer Schema extends z.ZodType;
169
- };
170
- };
171
- } ? z.output<Schema> extends {
172
- cards: infer Cards;
173
- } ? K extends keyof Cards ? ReadonlyData<Cards[K]> : never : never : Readonly<Record<string, RuntimeJson>>;
174
- interface CardBase<G, K extends IdOf<G, "cardId"> = IdOf<G, "cardId">> {
175
- readonly id: K;
176
- readonly zone: IdOf<G, "zoneId">;
177
- readonly index: number;
178
- readonly view: CardDataOf<G, K> | null;
179
- readonly hidden: boolean;
180
- readonly game: CoreInstance<G>;
181
- getInteractions(): readonly InteractionBase<G, InteractionKey<G>>[];
182
- getIsEligible(): boolean;
183
- getIsSelected(): boolean;
184
- getCanSelect(): boolean;
185
- select(options?: {
186
- interaction?: InteractionKey<G>;
187
- }): void;
188
- getSelectHandler(options?: {
189
- interaction?: InteractionKey<G>;
190
- }): () => void;
191
- getProps(options?: {
192
- interaction?: InteractionKey<G>;
193
- }): ActionProps;
194
- }
195
- type Card<G, F extends Features, K extends IdOf<G, "cardId"> = IdOf<G, "cardId">> = Omit<CardBase<G, K>, "getInteractions" | "game"> & Hook<F, "card"> & {
196
- readonly game: GameInstance<G, F>;
197
- getInteractions(): readonly Interaction<G, F, InteractionKey<G>>[];
198
- };
199
- interface ZoneBase<G> {
200
- readonly id: IdOf<G, "zoneId">;
201
- readonly count: number;
202
- readonly game: CoreInstance<G>;
203
- getIsEmpty(): boolean;
204
- }
205
- type Zone<G, F extends Features> = ZoneBase<G> & Hook<F, "zone"> & {
206
- readonly game: GameInstance<G, F>;
207
- getCards(options?: {
208
- sort?: (a: Card<G, F>, b: Card<G, F>) => number;
209
- }): readonly Card<G, F>[];
210
- getCard<K extends IdOf<G, "cardId">>(id: K): Card<G, F, K> | undefined;
211
- };
212
- interface ReadModel<G, F extends Features = Record<never, never>> {
213
- readonly snapshot: SourceSnapshot | null;
214
- readonly view: ViewOf<G> | null;
215
- readonly version: number | null;
216
- readonly connection: SourceState["connection"];
217
- readonly request: SourceState["request"];
218
- readonly state: LocalState<G>;
219
- readonly phase: Phase<G>;
220
- readonly turn: Turn<G>;
221
- readonly me: {
222
- readonly id: IdOf<G, "playerId">;
223
- readonly player: Player<G>;
224
- getCanAct(): boolean;
225
- } | null;
226
- readonly players: {
227
- get(id: IdOf<G, "playerId">): Player<G> | undefined;
228
- getAll(): readonly Player<G>[];
229
- next(id: IdOf<G, "playerId">): Player<G> | undefined;
230
- readonly order: readonly IdOf<G, "playerId">[];
231
- };
232
- readonly interactions: {
233
- get<K extends InteractionKey<G>>(key: K): Interaction<G, F, K> | undefined;
234
- list(): readonly Interaction<G, F, InteractionKey<G>>[];
235
- listAvailable(): readonly Interaction<G, F, InteractionKey<G>>[];
236
- };
237
- readonly inputs: {
238
- get<K extends InteractionKey<G>, N extends InputKey<G, K>>(interaction: K, input: N): Input<G, F, K, N> | undefined;
239
- };
240
- readonly zones: {
241
- get(id: IdOf<G, "zoneId">): Zone<G, F> | undefined;
242
- getAll(): readonly Zone<G, F>[];
243
- };
244
- readonly cards: {
245
- get<K extends IdOf<G, "cardId">>(id: K): Card<G, F, K> | undefined;
246
- };
247
- readonly events: {
248
- readonly recent: readonly GameEvent[];
249
- };
250
- }
251
- interface InstanceOptions<G, S extends GameSource = GameSource> {
252
- readonly source: S;
253
- readonly initialState?: Partial<LocalState<G>>;
254
- readonly state?: Partial<LocalState<G>>;
255
- readonly onDraftsChange?: (drafts: Drafts<G>) => void;
256
- readonly onActiveInteractionChange?: (key: InteractionKey<G> | null) => void;
257
- readonly onError?: (error: unknown) => void;
258
- readonly coverage?: Readonly<Record<InteractionKey<G>, unknown>>;
259
- readonly debug?: boolean;
260
- }
261
- type CoreInstance<G> = ReadModel<G> & {
262
- readonly store: Pick<Store<ReadModel<G>>, "get" | "subscribe">;
263
- getSnapshot(): ReadModel<G>;
264
- getOptions(): InstanceOptions<G>;
265
- setOptions(options: InstanceOptions<G>): void;
266
- subscribe(listener: () => void): () => void;
267
- dispose(): void;
268
- assertCoverage(): void;
269
- inspect(): ReadModel<G>;
270
- };
271
- type GameSnapshot<G, F extends Features = Record<never, never>> = ReadModel<G, F> & RootHooks<G, F>;
272
- type GameInstance<G, F extends Features = Record<never, never>, S extends GameSource = GameSource> = Omit<CoreInstance<G>, keyof ReadModel<G> | "store" | "getSnapshot" | "getOptions" | "setOptions" | "inspect"> & ReadModel<G, F> & RootHooks<G, F> & {
273
- readonly store: Pick<Store<GameSnapshot<G, F>>, "get" | "subscribe">;
274
- getSnapshot(): GameSnapshot<G, F>;
275
- inspect(): GameSnapshot<G, F>;
276
- getOptions(): InstanceOptions<G, S>;
277
- setOptions(options: InstanceOptions<G, S>): void;
278
- } & (S extends {
279
- apply(action: infer A): infer R;
280
- } ? {
281
- apply(action: A): R;
282
- } : Record<never, never>) & (S extends {
283
- explore(...args: infer A): infer R;
284
- } ? {
285
- explore(...args: A): R;
286
- } : Record<never, never>);
287
-
288
- export type { ActionProps as A, Board as B, Card as C, Drafts as D, Feature as F, GameInstance as G, Hook as H, IdOf as I, LocalState as L, NativeEvent as N, Phase as P, ReadModel as R, Turn as T, ViewOf as V, Zone as Z, BoardBase as a, BoardCollection as b, CardBase as c, CardDataOf as d, CoreInstance as e, FeatureContext as f, Features as g, FieldEvent as h, GameSnapshot as i, Input as j, InputBase as k, InputKey as l, InstanceOptions as m, Interaction as n, InteractionBase as o, InteractionKey as p, InteractionParams as q, PhaseName as r, Player as s, ReadonlyData as t, ZoneBase as u };
@@ -1,86 +0,0 @@
1
- import { Store } from '@tanstack/store';
2
- import { L as InteractionDescriptor$1, G as GameEvent, aI as SimultaneousPhaseProjection, aH as SeatProjectionBundle, d as BoardStaticProjection, av as RuntimeJson } from './definition-BaHNPZol.js';
3
-
4
- type PlayerId = string;
5
- interface GameplayBasis {
6
- readonly version: number;
7
- readonly actionSetVersion: string;
8
- readonly perspectivePlayerId: PlayerId;
9
- }
10
- interface PluginPlayerSummary {
11
- readonly playerId: PlayerId;
12
- readonly displayName: string;
13
- readonly color?: string;
14
- }
15
- interface PluginSessionDescriptor {
16
- readonly sessionId: string;
17
- /** Turn order is the order of this array. */
18
- readonly players: readonly PluginPlayerSummary[];
19
- }
20
-
21
- type InteractionDescriptor<Interaction extends string = string> = Omit<InteractionDescriptor$1, "interactionKey"> & {
22
- readonly interactionKey: Interaction;
23
- };
24
- type ActionInteractionDescriptor<Interaction extends string = string> = InteractionDescriptor<Interaction>;
25
- interface ZoneHandlesSnapshot<Interaction extends string = string> {
26
- readonly cardIds: readonly string[];
27
- readonly cardViewsById: Readonly<Record<string, string>>;
28
- readonly playableByCardId: Readonly<Record<string, readonly InteractionDescriptor<Interaction>[]>>;
29
- }
30
- type ReadonlyProjection<Value> = Value extends readonly (infer Item)[] ? readonly ReadonlyProjection<Item>[] : Value extends object ? {
31
- readonly [Key in keyof Value]: ReadonlyProjection<Value[Key]>;
32
- } : Value;
33
- type SimultaneousPhaseSnapshot = ReadonlyProjection<SimultaneousPhaseProjection>;
34
-
35
- interface PluginGameplayFrame<View = unknown, Phase extends string = string, Interaction extends string = string> {
36
- /** Latest committed public display-event batch. Reading a snapshot does not replay notifications. */
37
- readonly events: readonly GameEvent[];
38
- readonly basis: GameplayBasis;
39
- readonly view: View | null;
40
- readonly flow: {
41
- readonly currentPhase: Phase | null;
42
- readonly activePlayers: readonly PlayerId[];
43
- readonly simultaneousPhase: SimultaneousPhaseSnapshot | null;
44
- };
45
- readonly availableInteractions: ReadonlyArray<InteractionDescriptor<Interaction>>;
46
- readonly zones: Readonly<Record<string, ZoneHandlesSnapshot<Interaction>>>;
47
- }
48
- type ReducerSeatProjectionBundle = ReadonlyProjection<SeatProjectionBundle>;
49
- type ReducerBoardStaticProjection = Readonly<BoardStaticProjection>;
50
-
51
- interface SourceSnapshot {
52
- readonly me: string;
53
- readonly players: readonly PluginPlayerSummary[];
54
- readonly frame: Omit<PluginGameplayFrame, "basis">;
55
- readonly version: number;
56
- }
57
- type SubmitResult = {
58
- readonly accepted: true;
59
- } | {
60
- readonly accepted: false;
61
- readonly errorCode: string;
62
- readonly message?: string;
63
- };
64
- interface SourceState {
65
- readonly snapshot: SourceSnapshot | null;
66
- readonly connection: "connecting" | "ready" | "recovering" | "closed";
67
- readonly request: {
68
- readonly interactionId: string;
69
- readonly operation: "submit" | "cancel";
70
- readonly phase: "awaiting-result" | "awaiting-frame";
71
- } | null;
72
- }
73
- interface GameSource {
74
- readonly store: Pick<Store<SourceState>, "get" | "subscribe">;
75
- dispose(): void;
76
- }
77
- interface CommandSource extends GameSource {
78
- submit(interactionId: string, params: RuntimeJson): Promise<SubmitResult>;
79
- cancel(interactionId: string): Promise<SubmitResult>;
80
- }
81
- /** Testing-owned sources can add local actions without widening hosted sources. */
82
- interface ApplySource<Action, Result = void> extends GameSource {
83
- apply(action: Action): Result;
84
- }
85
-
86
- export type { ActionInteractionDescriptor as A, CommandSource as C, GameSource as G, InteractionDescriptor as I, PlayerId as P, ReducerBoardStaticProjection as R, SimultaneousPhaseSnapshot as S, ZoneHandlesSnapshot as Z, ApplySource as a, GameplayBasis as b, PluginGameplayFrame as c, PluginPlayerSummary as d, PluginSessionDescriptor as e, ReducerSeatProjectionBundle as f, SourceSnapshot as g, SourceState as h, SubmitResult as i };