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

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 (150) hide show
  1. package/README.md +136 -45
  2. package/dist/chunk-DMFVAZI2.js +16 -0
  3. package/dist/chunk-DMFVAZI2.js.map +1 -0
  4. package/dist/chunk-FMM5LVJW.js +833 -0
  5. package/dist/chunk-FMM5LVJW.js.map +1 -0
  6. package/dist/{chunk-S2JEDVWH.js → chunk-LRILEVKC.js} +6113 -6489
  7. package/dist/chunk-LRILEVKC.js.map +1 -0
  8. package/dist/chunk-SP234IY4.js +1363 -0
  9. package/dist/chunk-SP234IY4.js.map +1 -0
  10. package/dist/chunk-VUWNJXLJ.js +52 -0
  11. package/dist/chunk-VUWNJXLJ.js.map +1 -0
  12. package/dist/chunk-ZPRKWPEP.js +511 -0
  13. package/dist/chunk-ZPRKWPEP.js.map +1 -0
  14. package/dist/definition-BaHNPZol.d.ts +4639 -0
  15. package/dist/diagnostics-B0lgnuZ6.d.ts +65 -0
  16. package/dist/index.d.ts +3553 -1
  17. package/dist/index.js +1045 -6
  18. package/dist/index.js.map +1 -1
  19. package/dist/model-BHro6yXu.d.ts +288 -0
  20. package/dist/react.d.ts +32 -0
  21. package/dist/react.js +80 -0
  22. package/dist/react.js.map +1 -0
  23. package/dist/reducer.d.ts +1194 -79
  24. package/dist/reducer.js +4326 -121
  25. package/dist/reducer.js.map +1 -1
  26. package/dist/testing.d.ts +518 -564
  27. package/dist/testing.js +2448 -915
  28. package/dist/testing.js.map +1 -1
  29. package/dist/types-DimqnJBq.d.ts +86 -0
  30. package/package.json +26 -131
  31. package/dist/HandView-Bi2lxzQP.d.ts +0 -79
  32. package/dist/ResourceCounter-BFxJknqp.d.ts +0 -98
  33. package/dist/ThemeProvider-CElaL2ik.d.ts +0 -99
  34. package/dist/attributes-DbvyMbXw.d.ts +0 -68
  35. package/dist/browser-interaction.d.ts +0 -910
  36. package/dist/browser-interaction.js +0 -119
  37. package/dist/browser-interaction.js.map +0 -1
  38. package/dist/chunk-32PFKDV7.js +0 -11705
  39. package/dist/chunk-32PFKDV7.js.map +0 -1
  40. package/dist/chunk-3BAD4VC2.js +0 -263
  41. package/dist/chunk-3BAD4VC2.js.map +0 -1
  42. package/dist/chunk-3SKDNDPG.js +0 -104
  43. package/dist/chunk-3SKDNDPG.js.map +0 -1
  44. package/dist/chunk-5YV2WHJ4.js +0 -25
  45. package/dist/chunk-5YV2WHJ4.js.map +0 -1
  46. package/dist/chunk-ANRB4XKA.js +0 -90
  47. package/dist/chunk-ANRB4XKA.js.map +0 -1
  48. package/dist/chunk-BI4G3PM2.js +0 -1864
  49. package/dist/chunk-BI4G3PM2.js.map +0 -1
  50. package/dist/chunk-EVCLTY4Q.js +0 -935
  51. package/dist/chunk-EVCLTY4Q.js.map +0 -1
  52. package/dist/chunk-GDPKTBUR.js +0 -564
  53. package/dist/chunk-GDPKTBUR.js.map +0 -1
  54. package/dist/chunk-H6VDGFL5.js +0 -2903
  55. package/dist/chunk-H6VDGFL5.js.map +0 -1
  56. package/dist/chunk-LR3ZTWQF.js +0 -5960
  57. package/dist/chunk-LR3ZTWQF.js.map +0 -1
  58. package/dist/chunk-PF7L4BMG.js +0 -117
  59. package/dist/chunk-PF7L4BMG.js.map +0 -1
  60. package/dist/chunk-PN5O6GG2.js +0 -32
  61. package/dist/chunk-PN5O6GG2.js.map +0 -1
  62. package/dist/chunk-PZ5AY32C.js +0 -10
  63. package/dist/chunk-PZ5AY32C.js.map +0 -1
  64. package/dist/chunk-S2JEDVWH.js.map +0 -1
  65. package/dist/chunk-T3ZKNUZ7.js +0 -1
  66. package/dist/chunk-T3ZKNUZ7.js.map +0 -1
  67. package/dist/chunk-UGH54WZ2.js +0 -223
  68. package/dist/chunk-UGH54WZ2.js.map +0 -1
  69. package/dist/chunk-VCDWP5VL.js +0 -746
  70. package/dist/chunk-VCDWP5VL.js.map +0 -1
  71. package/dist/chunk-VDXOF4FW.js +0 -69
  72. package/dist/chunk-VDXOF4FW.js.map +0 -1
  73. package/dist/chunk-WHR5UW3F.js +0 -1988
  74. package/dist/chunk-WHR5UW3F.js.map +0 -1
  75. package/dist/chunk-Y75CFE77.js +0 -17
  76. package/dist/chunk-Y75CFE77.js.map +0 -1
  77. package/dist/chunk-Z7QCREWI.js +0 -3435
  78. package/dist/chunk-Z7QCREWI.js.map +0 -1
  79. package/dist/chunk-ZZGN2ATS.js +0 -1941
  80. package/dist/chunk-ZZGN2ATS.js.map +0 -1
  81. package/dist/components-gAbIz7hK.d.ts +0 -1284
  82. package/dist/definitions-BgmV_GhC.d.ts +0 -300
  83. package/dist/diagnostics-DIi3ina7.d.ts +0 -50
  84. package/dist/digest.d.ts +0 -8
  85. package/dist/game-CsZScpcn.d.ts +0 -763
  86. package/dist/hex-board-view-aKkblDp6.d.ts +0 -1228
  87. package/dist/index-CcT9Q7N7.d.ts +0 -193
  88. package/dist/index.d-DjzoK7zn.d.ts +0 -2101
  89. package/dist/package-set.d.ts +0 -13
  90. package/dist/package-set.js +0 -12
  91. package/dist/package-set.js.map +0 -1
  92. package/dist/player-state-Cqpyeql0.d.ts +0 -371
  93. package/dist/plugin-runtime-contract.d.ts +0 -17
  94. package/dist/plugin-runtime-contract.js +0 -92
  95. package/dist/plugin-runtime-contract.js.map +0 -1
  96. package/dist/primitive-props-BNHDkgd7.d.ts +0 -16
  97. package/dist/protocol-dYgafTYY.d.ts +0 -314
  98. package/dist/reducer/advanced.d.ts +0 -82
  99. package/dist/reducer/advanced.js +0 -51
  100. package/dist/reducer/advanced.js.map +0 -1
  101. package/dist/reducer-contract.d.ts +0 -11
  102. package/dist/reducer-contract.js +0 -16
  103. package/dist/reducer-contract.js.map +0 -1
  104. package/dist/reference-games/index.d.ts +0 -31
  105. package/dist/reference-games/index.js +0 -48
  106. package/dist/reference-games/index.js.map +0 -1
  107. package/dist/runtime/primitives.d.ts +0 -250
  108. package/dist/runtime/primitives.js +0 -189
  109. package/dist/runtime/primitives.js.map +0 -1
  110. package/dist/runtime/runtime-api.d.ts +0 -2
  111. package/dist/runtime/runtime-api.js +0 -1
  112. package/dist/runtime/runtime-api.js.map +0 -1
  113. package/dist/runtime/workspace-contract.d.ts +0 -392
  114. package/dist/runtime/workspace-contract.js +0 -28
  115. package/dist/runtime/workspace-contract.js.map +0 -1
  116. package/dist/runtime-RJ5orDJU.d.ts +0 -1699
  117. package/dist/runtime-api-Bz5pwNU_.d.ts +0 -296
  118. package/dist/runtime-json-CQ9QbLZ5.d.ts +0 -5
  119. package/dist/runtime.d.ts +0 -83
  120. package/dist/runtime.js +0 -242
  121. package/dist/runtime.js.map +0 -1
  122. package/dist/schema.d.ts +0 -379
  123. package/dist/stale-contract-artifact-error-XLaweZtF.d.ts +0 -18
  124. package/dist/testing-compiler.d.ts +0 -37
  125. package/dist/testing-compiler.js +0 -272
  126. package/dist/testing-compiler.js.map +0 -1
  127. package/dist/testing-runtime.d.ts +0 -119
  128. package/dist/testing-runtime.js +0 -212
  129. package/dist/testing-runtime.js.map +0 -1
  130. package/dist/types-DJj5MJkl.d.ts +0 -256
  131. package/dist/types-DR7DoB1x.d.ts +0 -28
  132. package/dist/types-JWCYHmu7.d.ts +0 -122
  133. package/dist/types.d.ts +0 -1958
  134. package/dist/types.js +0 -14
  135. package/dist/types.js.map +0 -1
  136. package/dist/ui/components.d.ts +0 -17
  137. package/dist/ui/components.js +0 -216
  138. package/dist/ui/components.js.map +0 -1
  139. package/dist/ui/defaults.d.ts +0 -19
  140. package/dist/ui/defaults.js +0 -104
  141. package/dist/ui/defaults.js.map +0 -1
  142. package/dist/ui/player-state.d.ts +0 -2
  143. package/dist/ui/player-state.js +0 -1
  144. package/dist/ui/player-state.js.map +0 -1
  145. package/dist/ui/plugin-styles.css +0 -2
  146. package/dist/ui-contract-GTUPkf8z.d.ts +0 -1168
  147. package/dist/ui.d.ts +0 -317
  148. package/dist/ui.js +0 -277
  149. package/dist/ui.js.map +0 -1
  150. package/dist/views-BpuWcOyN.d.ts +0 -1641
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @dreamboard-games/sdk
2
2
 
3
+ [Guides and API reference](../../docs/index.md) · [Registry](../../registry/README.md) · [Examples](../../examples/reference-games/README.md)
4
+
3
5
  The public TypeScript SDK for authoring, testing, and rendering Dreamboard
4
6
  games. Install this package rather than any of the repository's unpublished
5
7
  workspace inputs.
@@ -8,33 +10,15 @@ workspace inputs.
8
10
  pnpm add @dreamboard-games/sdk
9
11
  ```
10
12
 
11
- The package's declarations and export map are the API authority. Supported
12
- imports include the root module and explicit subpaths for authoring, runtime,
13
- reducer contracts, testing, browser interaction, UI, and reference-game
14
- metadata. Import only subpaths present in the installed package's `exports`
15
- field.
13
+ The package declarations and export map are the API authority. There are four entry points:
16
14
 
17
- ```ts
18
- import { DREAMBOARD_SDK_VERSION } from "@dreamboard-games/sdk";
19
- import type { ReducerWire } from "@dreamboard-games/sdk/reducer-contract";
20
- import {
21
- REFERENCE_GAME_MANIFEST_SCHEMA_VERSION,
22
- parseReferenceGameManifest,
23
- type ReferenceGameManifest,
24
- } from "@dreamboard-games/sdk/reference-games";
25
-
26
- const manifest: ReferenceGameManifest = parseReferenceGameManifest(input);
27
- console.log(REFERENCE_GAME_MANIFEST_SCHEMA_VERSION, manifest.id);
28
- ```
15
+ - `@dreamboard-games/sdk`: framework-free instances, sources, features and canonical host protocol schemas.
16
+ - `@dreamboard-games/sdk/react`: typed React provider, selector hook and subscription component.
17
+ - `@dreamboard-games/sdk/reducer`: game authoring, manifest compilation, execution and trusted worker admission.
18
+ - `@dreamboard-games/sdk/testing`: browser-safe local/scenario sources, replay, inspection and bounded exploration.
29
19
 
30
- Reference-game manifests use schema V5. They describe the game workspace,
31
- teaching purpose, mechanics, UI patterns, and substantive rights metadata.
32
-
33
- Include the packaged stylesheet when using SDK UI components:
34
-
35
- ```ts
36
- import "@dreamboard-games/sdk/ui/plugin-styles.css";
37
- ```
20
+ UI components are source-owned registry items installed into your application.
21
+ The SDK contains no styled components or stylesheet.
38
22
 
39
23
  ## Game authoring
40
24
 
@@ -45,14 +29,19 @@ codes. The returned value is three things at once:
45
29
  - the **type leaf**: `typeof game.types.State`, `.ErrorCode`, `.PlayerId`,
46
30
  `.Queries`, `.Tx` (phantom carriers; reading them at runtime throws),
47
31
  - the **factory namespace**: `game.phase(name)`, `phase.define`,
48
- `phase.interaction`, `phase.inputs.*`, `game.views.*`,
49
- - the **assembler**: `game.assemble({ initial, initialPhase, phases, views })`.
32
+ `phase.interaction`, `phase.inputs.*`, `game.view`,
33
+ - the **assembler**: `game.assemble({ initial, initialPhase, phases, view })`.
50
34
 
51
35
  Mutation callbacks (`enter`, `reduce`, `resolve`) receive an open transaction
52
36
  `tx`. Mutate through it and finish with a bare `return` (accept), or with
53
37
  `tx.transition(name)`, `tx.endGame(outcome)`, or `tx.reject(code)`. Events go
54
38
  through `tx.emit(...)`. `state` is the read-only snapshot the callback started
55
- from; `tx.state` is the current draft.
39
+ from; `tx.state` is the current draft. The transaction clones its table once;
40
+ all card, component, resource, and state-slice updates use that draft. Use
41
+ `tx.q` when a query must observe an earlier mutation in the same callback.
42
+ State patch callbacks return a replacement slice without mutating their input.
43
+ The former `ops`, `pipe`, flat `setActivePlayers`, and `tx.apply` APIs are removed;
44
+ call the named transaction methods directly.
56
45
 
57
46
  ```ts
58
47
  // app/game-model.ts — the model, bound once
@@ -114,8 +103,11 @@ export default play.define({
114
103
  });
115
104
  tx.patchPhaseState({ leadCardId: input.params.cardId });
116
105
  const next = q.player.nextInOrder(input.playerId);
117
- if (next) tx.setActivePlayers([next]);
118
- if (q.zone.playerCards(input.playerId, "hand").length === 0) {
106
+ if (next) {
107
+ tx.patchPublicState({ currentPlayerId: next });
108
+ tx.setActivePlayers([next]);
109
+ }
110
+ if (tx.q.zone.playerCards(input.playerId, "hand").length === 0) {
119
111
  return tx.transition("setup");
120
112
  }
121
113
  },
@@ -124,6 +116,42 @@ export default play.define({
124
116
  });
125
117
  ```
126
118
 
119
+ Dependent choices use `phase.steps()` instead of `inputs`. Each accepted command
120
+ commits exactly one current value. Factories receive only earlier parsed
121
+ `selected` values; descriptors expose only the current input. The final commit
122
+ runs complete-parameter validation and the reducer once. Use explicit `null`
123
+ for a no-target choice, and `many(...)` for one atomic multi-selection.
124
+
125
+ ```ts
126
+ const choose = play.interaction({
127
+ steps: play
128
+ .steps()
129
+ .input(
130
+ "kind",
131
+ play.inputs.form.choice({
132
+ choices: [{ value: "single", label: "Single" }],
133
+ defaultValue: () => undefined,
134
+ }),
135
+ )
136
+ .input("count", ({ selected }) =>
137
+ play.inputs.form.number({
138
+ min: 1,
139
+ max: selected.kind === "single" ? 1 : 3,
140
+ defaultValue: 1,
141
+ }),
142
+ ),
143
+ reduce({ input }) {
144
+ // input.params contains both kind and count here.
145
+ },
146
+ });
147
+ ```
148
+
149
+ `rules.available` controls action eligibility; `rules.validate` checks a final
150
+ submission. Accepted state changes reconcile pending prefixes, while phase
151
+ entry clears them. A rejected final submission keeps the prior prefix. The
152
+ actor can cancel an unsealed prefix with `interaction.cancel`, using the same
153
+ transport basis and action identity as submission.
154
+
127
155
  ```ts
128
156
  // app/game.ts — assembly
129
157
  import { game } from "./game-model";
@@ -138,16 +166,11 @@ export default game.assemble({
138
166
  },
139
167
  initialPhase: "setup",
140
168
  phases: { setup, play },
141
- views: {
142
- shared: game.views.empty(),
143
- player: game.views.player({
144
- project: ({ state, playerId, q }) => ({
145
- me: playerId,
146
- hand: q.zone.playerCards(playerId, "hand"),
147
- current: state.publicState.currentPlayerId,
148
- }),
149
- }),
150
- },
169
+ view: game.view(({ state, playerId, q }) => ({
170
+ me: playerId,
171
+ hand: q.zone.playerCards(playerId, "hand"),
172
+ current: state.publicState.currentPlayerId,
173
+ })),
151
174
  });
152
175
  ```
153
176
 
@@ -159,18 +182,28 @@ imports the assembled game, so there is no import cycle.
159
182
  New workspaces keep authored starter code in `app/game.ts` and `ui/App.tsx`.
160
183
  Import the manifest directly. `compileManifest(manifest)` provides inferred ID schemas,
161
184
  table schemas, fresh initial tables, and board metadata in memory. `createGame`
162
- also accepts the authored manifest directly. Bind UI primitives with
163
- `createGameUi(game)` from `@dreamboard-games/sdk/runtime/workspace-contract`.
185
+ also accepts the authored manifest directly. Bind a typed React hook with
186
+ `createGameHook<Game>()({ features, coverage })` from `@dreamboard-games/sdk/react`,
187
+ and pass a source to its `GameProvider`. The hosted UI imports `Game` only as a type;
188
+ `iframeSource()` supplies authoritative frames and handles commands.
164
189
  No authoring generation step or shared workspace files are needed.
165
190
 
166
191
  ## Reducer runner contract
167
192
 
168
193
  `createReducerBundle(game)` returns exactly the contract version and four
169
194
  operations: `boardStatic()`, `initialize(input)`, `dispatch({ state, input })`,
170
- and `project({ state, playerIds })`. The runner contract is `0.5.0`; hosts must
171
- require that exact version. Dispatch includes validation and effect execution. Initialization returns
195
+ and `project({ state, playerIds })`. The runner contract is `0.6.0`; hosts must
196
+ require that exact version. Dispatch includes validation, direct transaction mutations, and phase entry.
197
+ Initialization returns
172
198
  `{ state, terminal?, events? }`, preserving outcomes and events from initial
173
- phase entry and automatic continuations.
199
+ phase entry and returned transitions.
200
+
201
+ Mutation callbacks use `tx.roll(dieId)`, `tx.shuffle({ zoneId, playerId? })`, and
202
+ `tx.deal({ fromZoneId, toZoneId, playerId, count })` directly. Return
203
+ `tx.transition(phaseName)` to enter a phase, including reentering the current
204
+ phase. An unreturned outcome schedules no work. Entry chains are bounded to
205
+ 1,000 entries per dispatch. `tx.endGame(outcome, { transition })` enters the
206
+ final phase once; that entry must not return another transition.
174
207
 
175
208
  The authoritative state is explicit on every dispatch and projection. A host
176
209
  may retain a warm worker and SDK caches, but replaying the same state and input
@@ -182,3 +215,61 @@ owns the monotonically increasing version, perspective, and action-set identity.
182
215
  The plugin frame basis contains `version`, `actionSetVersion`, and
183
216
  `perspectivePlayerId`; it has no generation counter. Hosts merge the separately
184
217
  cached board static projection when materializing plugin gameplay frames.
218
+
219
+ ### Initialization options and actors
220
+
221
+ Declare lobby options once on `createGame({ options: z.strictObject({ ... }), ... })`.
222
+ The bundle accepts JSON-safe `options` at initialization, validates them with that
223
+ schema, persists the parsed values, and supplies them to initial state and phase
224
+ initializers. Without a schema, only `{}` is accepted. Options schemas must be
225
+ JSON-native: transforms, preprocessing, and coercion are rejected. Restored
226
+ sessions validate their stored options with the same schema.
227
+
228
+ Perform shuffle, deal, and other initialization mutations in an ordinary phase
229
+ entry callback. Setup profiles and bootstrap instructions are removed.
230
+ Interactions use `actor` to override their phase actor; only authorized seats
231
+ receive their input domains. Use ordinary form choices for responses and explicit
232
+ rules plus transaction resource mutations for affordability. Prompt collectors,
233
+ implicit costs, guidance metadata, and phase zone declarations are removed.
234
+
235
+ A game authors one `view` for each requested seat. Public and private fields
236
+ compose in that function; the transport never uses a seat view as a spectator
237
+ payload. Static boards come directly from the compiled manifest.
238
+
239
+ Use `memoize((input: SomeImmutableObject) => result)` for shared pure calculations.
240
+ It caches by object identity with a WeakMap, including `undefined` results. Pass
241
+ immutable snapshots (or stable immutable branches), not an open mutable transaction.
242
+ There is no injected derived-value resolver.
243
+
244
+ ## React adapter dependency
245
+
246
+ Framework-free consumers can import the package root without React. Applications
247
+ using `@dreamboard-games/sdk/react` must install the maintained React store adapter
248
+ alongside React:
249
+
250
+ ```sh
251
+ pnpm add @dreamboard-games/sdk react@^19 react-dom@^19 @tanstack/react-store@0.11.1
252
+ ```
253
+
254
+ `@tanstack/react-store` is an optional peer of the SDK so headless consumers do not
255
+ install the React adapter. The `/react` entry delegates selectors to that package;
256
+ the application bundler resolves its supported React subscription dependencies.
257
+
258
+ ## Local development and tests
259
+
260
+ `localSource(game, { players, seed, as, options })` executes the production reducer
261
+ and materializes the selected seat. `scenarioSource` starts from authored scenario
262
+ checkpoints. Keep these executable game imports in your local development entry;
263
+ the hosted entry uses only `iframeSource()` and type imports.
264
+
265
+ Local sources expose `inspect`, bounded `explore`, typed explicit-actor `apply`,
266
+ `switchSeat`, `checkpoint`, and validated `restore`. A JSON checkpoint preserves
267
+ pending selections and terminal state; restoring does not replay commands.
268
+ `createTestSource(snapshot)` supplies controlled frames and acknowledgements for
269
+ instance and React tests. Static and hosted sources do not expose `apply`.
270
+
271
+ Hosts import `assertReducerBundleContract`, `REDUCER_CONTRACT_VERSION`,
272
+ `ReducerWire` types and `ReducerWireZod` schemas from `/reducer`. Canonical iframe
273
+ and gameplay websocket schemas plus `materializePluginGameplayFrame` live at the
274
+ root. Materialize the seat projection with static board data before publishing it;
275
+ sources publish the canonical seat view and keep command bases private.
@@ -0,0 +1,16 @@
1
+ // src/headless/sources/immutable.ts
2
+ function immutableCopy(value) {
3
+ return freeze(structuredClone(value));
4
+ }
5
+ function freeze(value) {
6
+ if (value !== null && typeof value === "object") {
7
+ for (const child of Object.values(value)) freeze(child);
8
+ Object.freeze(value);
9
+ }
10
+ return value;
11
+ }
12
+
13
+ export {
14
+ immutableCopy
15
+ };
16
+ //# sourceMappingURL=chunk-DMFVAZI2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/headless/sources/immutable.ts"],"sourcesContent":["/** Source-owned snapshots and commands cannot be changed by their caller. */\nexport function immutableCopy<T>(value: T): T {\n return freeze(structuredClone(value));\n}\nfunction freeze<T>(value: T): T {\n if (value !== null && typeof value === \"object\") {\n for (const child of Object.values(value)) freeze(child);\n Object.freeze(value);\n }\n return value;\n}\n"],"mappings":";AACO,SAAS,cAAiB,OAAa;AAC5C,SAAO,OAAO,gBAAgB,KAAK,CAAC;AACtC;AACA,SAAS,OAAU,OAAa;AAC9B,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAC/C,eAAW,SAAS,OAAO,OAAO,KAAK,EAAG,QAAO,KAAK;AACtD,WAAO,OAAO,KAAK;AAAA,EACrB;AACA,SAAO;AACT;","names":[]}