@dreamboard-games/sdk 0.5.0-alpha.3 → 0.5.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -2
- package/dist/board-target-B0QG6OYx.d.ts +8 -0
- package/dist/chunk-3JXUL4VN.js +139 -0
- package/dist/chunk-3JXUL4VN.js.map +1 -0
- package/dist/{chunk-LRILEVKC.js → chunk-C77SYIVT.js} +82 -109
- package/dist/chunk-C77SYIVT.js.map +1 -0
- package/dist/{chunk-SP234IY4.js → chunk-OOFMBCFF.js} +178 -203
- package/dist/chunk-OOFMBCFF.js.map +1 -0
- package/dist/{chunk-ZPRKWPEP.js → chunk-UG2Q4NLG.js} +108 -29
- package/dist/chunk-UG2Q4NLG.js.map +1 -0
- package/dist/{chunk-FMM5LVJW.js → chunk-XU6WJW6K.js} +26 -12
- package/dist/chunk-XU6WJW6K.js.map +1 -0
- package/dist/{diagnostics-B0lgnuZ6.d.ts → diagnostics-B8d5aLad.d.ts} +2 -2
- package/dist/{definition-BaHNPZol.d.ts → extract-gVKcB8Og.d.ts} +484 -387
- package/dist/index.d.ts +404 -175
- package/dist/index.js +266 -215
- package/dist/index.js.map +1 -1
- package/dist/model-vdpLHrxh.d.ts +432 -0
- package/dist/react.d.ts +35 -7
- package/dist/react.js +136 -8
- package/dist/react.js.map +1 -1
- package/dist/reducer.d.ts +169 -118
- package/dist/reducer.js +206 -328
- package/dist/reducer.js.map +1 -1
- package/dist/testing.d.ts +5 -3
- package/dist/testing.js +9 -6
- package/dist/testing.js.map +1 -1
- package/dist/{types-DimqnJBq.d.ts → types-Bj5ZLTUV.d.ts} +38 -10
- package/package.json +19 -16
- package/dist/chunk-FMM5LVJW.js.map +0 -1
- package/dist/chunk-LRILEVKC.js.map +0 -1
- package/dist/chunk-SP234IY4.js.map +0 -1
- package/dist/chunk-VUWNJXLJ.js +0 -52
- package/dist/chunk-VUWNJXLJ.js.map +0 -1
- package/dist/chunk-ZPRKWPEP.js.map +0 -1
- package/dist/model-BHro6yXu.d.ts +0 -288
package/dist/model-BHro6yXu.d.ts
DELETED
|
@@ -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 };
|