@dreamboard-games/sdk 0.2.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.
- package/LICENSE.md +96 -0
- package/README.md +12 -0
- package/dist/HandView-ncJIVLhN.d.ts +193 -0
- package/dist/ResourceCounter-CTREyF73.d.ts +102 -0
- package/dist/ThemeProvider-fy0_QzgO.d.ts +99 -0
- package/dist/bundle-TIZcw8LB.d.ts +281 -0
- package/dist/cards-Sl3b40Mv.d.ts +13 -0
- package/dist/chunk-7YAHLYBR.js +481 -0
- package/dist/chunk-7YAHLYBR.js.map +1 -0
- package/dist/chunk-FDNZTDD6.js +8085 -0
- package/dist/chunk-FDNZTDD6.js.map +1 -0
- package/dist/chunk-GKKBPPSW.js +598 -0
- package/dist/chunk-GKKBPPSW.js.map +1 -0
- package/dist/chunk-I46YJSOD.js +1 -0
- package/dist/chunk-I46YJSOD.js.map +1 -0
- package/dist/chunk-KAELH4KC.js +104 -0
- package/dist/chunk-KAELH4KC.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-T3ZKNUZ7.js +1 -0
- package/dist/chunk-T3ZKNUZ7.js.map +1 -0
- package/dist/chunk-T52J5RMF.js +1 -0
- package/dist/chunk-T52J5RMF.js.map +1 -0
- package/dist/chunk-TDSWKVZ4.js +5401 -0
- package/dist/chunk-TDSWKVZ4.js.map +1 -0
- package/dist/chunk-U5C6BONG.js +34 -0
- package/dist/chunk-U5C6BONG.js.map +1 -0
- package/dist/chunk-VDXOF4FW.js +69 -0
- package/dist/chunk-VDXOF4FW.js.map +1 -0
- package/dist/chunk-VFTAA4WO.js +115 -0
- package/dist/chunk-VFTAA4WO.js.map +1 -0
- package/dist/chunk-WN74KVNY.js +17 -0
- package/dist/chunk-WN74KVNY.js.map +1 -0
- package/dist/chunk-WYPQ3GG5.js +10990 -0
- package/dist/chunk-WYPQ3GG5.js.map +1 -0
- package/dist/components-D5ZRE2Hl.d.ts +1451 -0
- package/dist/generated/runtime/primitives.d.ts +12 -0
- package/dist/generated/runtime/primitives.js +180 -0
- package/dist/generated/runtime/primitives.js.map +1 -0
- package/dist/generated/runtime-api.d.ts +3 -0
- package/dist/generated/runtime-api.js +2 -0
- package/dist/generated/runtime-api.js.map +1 -0
- package/dist/generated/runtime.d.ts +14 -0
- package/dist/generated/runtime.js +18 -0
- package/dist/generated/runtime.js.map +1 -0
- package/dist/generated/workspace-contract.d.ts +14 -0
- package/dist/generated/workspace-contract.js +14 -0
- package/dist/generated/workspace-contract.js.map +1 -0
- package/dist/hex-board-view-D_07hO6O.d.ts +933 -0
- package/dist/hex-color-MhOyuY-o.d.ts +8 -0
- package/dist/index-BwqPQtBu.d.ts +1433 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/reducer-bundle-abi.d.ts +1083 -0
- package/dist/infrastructure/reducer-bundle-abi.js +14 -0
- package/dist/infrastructure/reducer-bundle-abi.js.map +1 -0
- package/dist/infrastructure/workspace-codegen.d.ts +53 -0
- package/dist/infrastructure/workspace-codegen.js +44 -0
- package/dist/infrastructure/workspace-codegen.js.map +1 -0
- package/dist/manifest-contract-BNHVGFtU.d.ts +9 -0
- package/dist/package-set.d.ts +13 -0
- package/dist/package-set.js +12 -0
- package/dist/package-set.js.map +1 -0
- package/dist/primitive-props-DpKs-GCr.d.ts +11 -0
- package/dist/reducer.d.ts +3786 -0
- package/dist/reducer.js +8131 -0
- package/dist/reducer.js.map +1 -0
- package/dist/runtime/primitives.d.ts +226 -0
- package/dist/runtime/primitives.js +180 -0
- package/dist/runtime/primitives.js.map +1 -0
- package/dist/runtime/types/runtime-api.d.ts +1 -0
- package/dist/runtime/types/runtime-api.js +2 -0
- package/dist/runtime/types/runtime-api.js.map +1 -0
- package/dist/runtime/workspace-contract.d.ts +172 -0
- package/dist/runtime/workspace-contract.js +14 -0
- package/dist/runtime/workspace-contract.js.map +1 -0
- package/dist/runtime-api-3dshj6kK.d.ts +101 -0
- package/dist/runtime-api-DWxvTr-O.d.ts +379 -0
- package/dist/runtime.d.ts +58 -0
- package/dist/runtime.js +13 -0
- package/dist/runtime.js.map +1 -0
- package/dist/slots-1GPGihk8.d.ts +8 -0
- package/dist/testing.d.ts +149 -0
- package/dist/testing.js +513 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +496 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/components.d.ts +16 -0
- package/dist/ui/components.js +192 -0
- package/dist/ui/components.js.map +1 -0
- package/dist/ui/defaults.d.ts +19 -0
- package/dist/ui/defaults.js +104 -0
- package/dist/ui/defaults.js.map +1 -0
- package/dist/ui/plugin-styles.css +250 -0
- package/dist/ui/types/player-state.d.ts +365 -0
- package/dist/ui/types/player-state.js +1 -0
- package/dist/ui/types/player-state.js.map +1 -0
- package/dist/ui-contract-iQfTtUSL.d.ts +1161 -0
- package/dist/ui.d.ts +320 -0
- package/dist/ui.js +253 -0
- package/dist/ui.js.map +1 -0
- package/package.json +199 -0
- package/src/generated/reducer-contract/builders.ts +90 -0
- package/src/generated/reducer-contract/version.ts +9 -0
- package/src/generated/reducer-contract/wire.ts +100 -0
- package/src/generated/reducer-contract/zod.ts +101 -0
- package/src/generated/runtime/primitives.ts +2 -0
- package/src/generated/runtime-api.ts +5 -0
- package/src/generated/runtime.ts +35 -0
- package/src/generated/workspace-contract.ts +2 -0
- package/src/index.ts +7 -0
- package/src/infrastructure/reducer-bundle-abi.ts +8 -0
- package/src/infrastructure/reducer-contract/bundle.ts +37 -0
- package/src/infrastructure/workspace-codegen/hex-geometry.ts +69 -0
- package/src/infrastructure/workspace-codegen/index.ts +64 -0
- package/src/infrastructure/workspace-codegen/manifest-contract.ts +6632 -0
- package/src/infrastructure/workspace-codegen/manifest-validation.ts +795 -0
- package/src/infrastructure/workspace-codegen/ownership.ts +131 -0
- package/src/infrastructure/workspace-codegen/preset-card-sets.ts +169 -0
- package/src/infrastructure/workspace-codegen/seeds.ts +1705 -0
- package/src/infrastructure/workspace-codegen.ts +1 -0
- package/src/package-set.ts +19 -0
- package/src/reducer/authoring/contract.ts +157 -0
- package/src/reducer/authoring/effect.ts +224 -0
- package/src/reducer/authoring/game.ts +23 -0
- package/src/reducer/authoring/interaction.ts +98 -0
- package/src/reducer/authoring/phase.ts +300 -0
- package/src/reducer/authoring/types.ts +70 -0
- package/src/reducer/authoring/validation.ts +382 -0
- package/src/reducer/authoring/view-stage.ts +68 -0
- package/src/reducer/authoring.ts +29 -0
- package/src/reducer/bundle/ingress-bundle.ts +491 -0
- package/src/reducer/bundle/trusted/engine-instruction-resolver.ts +254 -0
- package/src/reducer/bundle/trusted/flow-instruction-resolver.ts +73 -0
- package/src/reducer/bundle/trusted/instruction-runner.ts +414 -0
- package/src/reducer/bundle/trusted/interaction-authorization.ts +137 -0
- package/src/reducer/bundle/trusted/interaction-collectors.ts +859 -0
- package/src/reducer/bundle/trusted/interaction-decision.ts +747 -0
- package/src/reducer/bundle/trusted/interaction-resolver.ts +95 -0
- package/src/reducer/bundle/trusted/interaction-types.ts +171 -0
- package/src/reducer/bundle/trusted/lifecycle-runner.ts +427 -0
- package/src/reducer/bundle/trusted/projection-builder.ts +356 -0
- package/src/reducer/bundle/trusted/projection-context.ts +39 -0
- package/src/reducer/bundle/trusted/rng-sampler.ts +150 -0
- package/src/reducer/bundle/trusted/runtime-registry.ts +120 -0
- package/src/reducer/bundle/trusted/runtime-scope.ts +336 -0
- package/src/reducer/bundle/trusted/simultaneous-player.ts +97 -0
- package/src/reducer/bundle/trusted/stage-resolver.ts +87 -0
- package/src/reducer/bundle/trusted/static-projection.ts +116 -0
- package/src/reducer/bundle/trusted/trusted-runtime-args.ts +97 -0
- package/src/reducer/bundle/trusted/trusted-runtime-result.ts +39 -0
- package/src/reducer/bundle/trusted/trusted-setup-profiles.ts +43 -0
- package/src/reducer/bundle/trusted/trusted-state-codec.ts +48 -0
- package/src/reducer/bundle/trusted-bundle.ts +97 -0
- package/src/reducer/bundle/types.ts +171 -0
- package/src/reducer/bundle.ts +2 -0
- package/src/reducer/client-param-schemas.ts +57 -0
- package/src/reducer/compose.ts +34 -0
- package/src/reducer/core/runtime-input.ts +30 -0
- package/src/reducer/core/runtime-instruction.ts +59 -0
- package/src/reducer/core/types.ts +62 -0
- package/src/reducer/definition-index.ts +277 -0
- package/src/reducer/derived.ts +106 -0
- package/src/reducer/effects.ts +92 -0
- package/src/reducer/engine/runtime-instruction-engine.ts +155 -0
- package/src/reducer/ingress/decode-runtime-input.ts +7 -0
- package/src/reducer/ingress/decode-session-state.ts +9 -0
- package/src/reducer/ingress/encode-session-state.ts +6 -0
- package/src/reducer/ingress/input-codec.ts +18 -0
- package/src/reducer/ingress/phase-schemas.ts +62 -0
- package/src/reducer/ingress/raw-types.ts +107 -0
- package/src/reducer/ingress/runtime-codec.ts +14 -0
- package/src/reducer/ingress/runtime-payload.ts +13 -0
- package/src/reducer/ingress/session-codec.ts +392 -0
- package/src/reducer/ingress/types.ts +6 -0
- package/src/reducer/inputs/boardInput.ts +217 -0
- package/src/reducer/inputs/boardTarget.ts +190 -0
- package/src/reducer/inputs/cardInput.ts +86 -0
- package/src/reducer/inputs/cardTarget.ts +101 -0
- package/src/reducer/inputs/choiceTarget.ts +104 -0
- package/src/reducer/inputs/defineInputs.ts +71 -0
- package/src/reducer/inputs/formInput.ts +809 -0
- package/src/reducer/inputs/many.ts +120 -0
- package/src/reducer/inputs/promptInput.ts +87 -0
- package/src/reducer/inputs/rngInput.ts +58 -0
- package/src/reducer/inputs/targetRule.ts +123 -0
- package/src/reducer/inputs.ts +41 -0
- package/src/reducer/model/definition.ts +1072 -0
- package/src/reducer/model/extract.ts +745 -0
- package/src/reducer/model/manifest.ts +570 -0
- package/src/reducer/model/queries.ts +641 -0
- package/src/reducer/model/runtime.ts +264 -0
- package/src/reducer/model/spec.ts +1386 -0
- package/src/reducer/model/table.ts +260 -0
- package/src/reducer/model.ts +7 -0
- package/src/reducer/ops.ts +1034 -0
- package/src/reducer/parse-utils.ts +28 -0
- package/src/reducer/per-player.ts +422 -0
- package/src/reducer/rng.ts +69 -0
- package/src/reducer/schema-helpers.ts +185 -0
- package/src/reducer/setup-bootstrap-helpers.ts +171 -0
- package/src/reducer/setup-bootstrap.ts +481 -0
- package/src/reducer/table-ops.ts +2671 -0
- package/src/reducer/table-queries.ts +372 -0
- package/src/reducer/transaction.ts +120 -0
- package/src/reducer.ts +314 -0
- package/src/runtime/primitives.ts +1 -0
- package/src/runtime/types/runtime-api.ts +1 -0
- package/src/runtime/workspace-contract.ts +32 -0
- package/src/runtime-internal/components/InteractionForm.tsx +1309 -0
- package/src/runtime-internal/components/PluginRuntime.tsx +103 -0
- package/src/runtime-internal/components/board/target-layer.ts +70 -0
- package/src/runtime-internal/context/ClientParamSchemaContext.tsx +44 -0
- package/src/runtime-internal/context/InteractionDraftContext.tsx +279 -0
- package/src/runtime-internal/context/PluginSessionContext.tsx +47 -0
- package/src/runtime-internal/context/PluginStateContext.tsx +262 -0
- package/src/runtime-internal/context/RuntimeContext.tsx +96 -0
- package/src/runtime-internal/defaults/components.tsx +409 -0
- package/src/runtime-internal/defaults/index.ts +11 -0
- package/src/runtime-internal/errors/ValidationError.ts +29 -0
- package/src/runtime-internal/hooks/useActivePlayers.ts +33 -0
- package/src/runtime-internal/hooks/useBoardInteractions.ts +665 -0
- package/src/runtime-internal/hooks/useGameSelector.ts +105 -0
- package/src/runtime-internal/hooks/useGameView.ts +9 -0
- package/src/runtime-internal/hooks/useInteractionByKey.ts +354 -0
- package/src/runtime-internal/hooks/useInteractionHandle.ts +438 -0
- package/src/runtime-internal/hooks/useIsMyTurn.ts +20 -0
- package/src/runtime-internal/hooks/useLobby.ts +76 -0
- package/src/runtime-internal/hooks/useMe.ts +48 -0
- package/src/runtime-internal/hooks/usePlayerInfo.ts +28 -0
- package/src/runtime-internal/hooks/usePlayerTurnOrder.ts +23 -0
- package/src/runtime-internal/hooks/usePluginRuntime.ts +147 -0
- package/src/runtime-internal/hooks/useSeatInbox.ts +61 -0
- package/src/runtime-internal/hooks/useSimultaneousPhase.ts +10 -0
- package/src/runtime-internal/index.ts +42 -0
- package/src/runtime-internal/internal.ts +43 -0
- package/src/runtime-internal/plugin-styles.css +250 -0
- package/src/runtime-internal/primitives/board.tsx +459 -0
- package/src/runtime-internal/primitives/dialog-lifecycle.ts +58 -0
- package/src/runtime-internal/primitives/dice.tsx +79 -0
- package/src/runtime-internal/primitives/game-ui-provider.tsx +35 -0
- package/src/runtime-internal/primitives/game.tsx +387 -0
- package/src/runtime-internal/primitives/hand-intent-adapter.ts +147 -0
- package/src/runtime-internal/primitives/hand-surface.tsx +594 -0
- package/src/runtime-internal/primitives/index.ts +196 -0
- package/src/runtime-internal/primitives/interaction-form-binding.tsx +56 -0
- package/src/runtime-internal/primitives/interaction-submit.ts +90 -0
- package/src/runtime-internal/primitives/interaction.tsx +987 -0
- package/src/runtime-internal/primitives/phase.tsx +43 -0
- package/src/runtime-internal/primitives/player-roster.tsx +302 -0
- package/src/runtime-internal/primitives/primitive-props.tsx +101 -0
- package/src/runtime-internal/primitives/prompt.tsx +255 -0
- package/src/runtime-internal/primitives/ui.tsx +60 -0
- package/src/runtime-internal/primitives/zone.tsx +791 -0
- package/src/runtime-internal/reducer.ts +30 -0
- package/src/runtime-internal/runtime/createPluginRuntimeAPI.ts +605 -0
- package/src/runtime-internal/types/plugin-state.ts +508 -0
- package/src/runtime-internal/types/reducer-state.ts +24 -0
- package/src/runtime-internal/types/runtime-api.ts +114 -0
- package/src/runtime-internal/ui-contract.ts +519 -0
- package/src/runtime-internal/utils/card-intent-adapter.ts +546 -0
- package/src/runtime-internal/utils/interaction-inputs.ts +492 -0
- package/src/runtime-internal/utils/interaction-labels.ts +23 -0
- package/src/runtime-internal/utils/interaction-router.ts +273 -0
- package/src/runtime-internal/utils/interaction-status.ts +74 -0
- package/src/runtime-internal/workspace-contract.ts +1170 -0
- package/src/runtime.ts +34 -0
- package/src/testing/create-expect-api.ts +352 -0
- package/src/testing/create-test-runtime.ts +381 -0
- package/src/testing/definitions.ts +127 -0
- package/src/testing/index.ts +3 -0
- package/src/testing.ts +1 -0
- package/src/type-stubs/manifest-contract.d.ts +42 -0
- package/src/type-stubs/manifest-contract.js +72 -0
- package/src/type-stubs/ui-contract.d.ts +5 -0
- package/src/type-stubs/ui-contract.js +1 -0
- package/src/types/authoring-card-properties.type-test.ts +266 -0
- package/src/types/authoring.ts +1282 -0
- package/src/types/cards.ts +19 -0
- package/src/types/contracts.ts +1550 -0
- package/src/types/generated-helpers.ts +35 -0
- package/src/types/index.ts +147 -0
- package/src/types/slots.ts +11 -0
- package/src/types.ts +1 -0
- package/src/ui/components/ActionButton.tsx +97 -0
- package/src/ui/components/ActionPanel.tsx +315 -0
- package/src/ui/components/Card.tsx +378 -0
- package/src/ui/components/CardDragSurface.tsx +1076 -0
- package/src/ui/components/ChromeSuppressionContext.tsx +70 -0
- package/src/ui/components/CostDisplay.tsx +145 -0
- package/src/ui/components/DiceRoller.tsx +581 -0
- package/src/ui/components/Drawer.tsx +180 -0
- package/src/ui/components/ErrorBoundary.tsx +275 -0
- package/src/ui/components/GameEndDisplay.tsx +398 -0
- package/src/ui/components/GameSkeleton.tsx +260 -0
- package/src/ui/components/Hand.tsx +468 -0
- package/src/ui/components/HandDock.tsx +299 -0
- package/src/ui/components/HandView.tsx +441 -0
- package/src/ui/components/MobileHandTray.tsx +381 -0
- package/src/ui/components/MoreActions.tsx +143 -0
- package/src/ui/components/PhaseIndicator.tsx +341 -0
- package/src/ui/components/PlayArea.tsx +146 -0
- package/src/ui/components/PrimaryActionButton.tsx +336 -0
- package/src/ui/components/PrimaryButton.tsx +45 -0
- package/src/ui/components/ResourceCounter.tsx +270 -0
- package/src/ui/components/StagingZone.tsx +134 -0
- package/src/ui/components/ThemedButton.tsx +113 -0
- package/src/ui/components/Toast.tsx +264 -0
- package/src/ui/components/board/HexGrid.tsx +1294 -0
- package/src/ui/components/board/NetworkGraph.tsx +476 -0
- package/src/ui/components/board/SlotSystem.tsx +388 -0
- package/src/ui/components/board/SquareGrid.tsx +1165 -0
- package/src/ui/components/board/TrackBoard.tsx +496 -0
- package/src/ui/components/board/ZoneMap.tsx +448 -0
- package/src/ui/components/board/hex-board-view.ts +123 -0
- package/src/ui/components/board/index.ts +142 -0
- package/src/ui/components/board/interaction-accessibility.ts +21 -0
- package/src/ui/components/board/target-layer.ts +66 -0
- package/src/ui/components/card-render-content.type-test.ts +27 -0
- package/src/ui/components/hand-layout-math.ts +163 -0
- package/src/ui/components/hand-pointer-engine.ts +413 -0
- package/src/ui/components/index.ts +245 -0
- package/src/ui/components.ts +1 -0
- package/src/ui/defaults/components.tsx +106 -0
- package/src/ui/defaults/index.ts +8 -0
- package/src/ui/defaults.ts +1 -0
- package/src/ui/errors/ValidationError.ts +29 -0
- package/src/ui/helpers/cards.ts +19 -0
- package/src/ui/helpers/track-board.ts +211 -0
- package/src/ui/hooks/useBoardTopology.ts +316 -0
- package/src/ui/hooks/useCards.ts +10 -0
- package/src/ui/hooks/useHandCardPointer.ts +381 -0
- package/src/ui/hooks/useHandLayout.ts +378 -0
- package/src/ui/hooks/useHandPresentation.ts +121 -0
- package/src/ui/hooks/useHexBoard.ts +74 -0
- package/src/ui/hooks/useHexGrid.ts +185 -0
- package/src/ui/hooks/useIsMobile.ts +35 -0
- package/src/ui/hooks/usePanZoom.ts +278 -0
- package/src/ui/hooks/useSquareBoard.ts +124 -0
- package/src/ui/hooks/useSquareGrid.ts +328 -0
- package/src/ui/index.ts +98 -0
- package/src/ui/internal/ui/alert.tsx +51 -0
- package/src/ui/internal/ui/button.tsx +58 -0
- package/src/ui/internal/ui/dialog.tsx +134 -0
- package/src/ui/internal/ui/input.tsx +21 -0
- package/src/ui/internal/ui/label.tsx +21 -0
- package/src/ui/internal/ui/select.tsx +129 -0
- package/src/ui/internal/ui/tooltip.tsx +54 -0
- package/src/ui/internal/ui/utils.ts +5 -0
- package/src/ui/plugin-styles.css +250 -0
- package/src/ui/primitives/dialog-lifecycle.ts +58 -0
- package/src/ui/primitives/dice.tsx +79 -0
- package/src/ui/primitives/primitive-props.tsx +101 -0
- package/src/ui/theme/ThemeProvider.tsx +252 -0
- package/src/ui/theme/board.ts +61 -0
- package/src/ui/theme/css-vars.ts +105 -0
- package/src/ui/theme/derive.ts +240 -0
- package/src/ui/theme/index.ts +61 -0
- package/src/ui/theme/presets/arcade.ts +261 -0
- package/src/ui/theme/presets/studio.ts +261 -0
- package/src/ui/theme/presets/tabletop.ts +266 -0
- package/src/ui/theme/tokens.ts +392 -0
- package/src/ui/types/hex-color.ts +20 -0
- package/src/ui/types/player-state.ts +463 -0
- package/src/ui/types/tiled-board.ts +785 -0
- package/src/ui/types/visual-state.ts +137 -0
- package/src/ui.ts +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { safeParseOrThrow } from "../parse-utils";
|
|
3
|
+
import type { RawRuntimeInput } from "./raw-types";
|
|
4
|
+
import { runtimePayloadSchema } from "./runtime-payload";
|
|
5
|
+
|
|
6
|
+
export function createRuntimeInputParser<PlayerId extends string>(
|
|
7
|
+
playerIdSchema: z.ZodType<PlayerId>,
|
|
8
|
+
): (rawInput: unknown) => RawRuntimeInput {
|
|
9
|
+
const rawRuntimeInputSchema = z.object({
|
|
10
|
+
kind: z.literal("interaction"),
|
|
11
|
+
playerId: playerIdSchema,
|
|
12
|
+
interactionId: z.string(),
|
|
13
|
+
params: runtimePayloadSchema.default({}),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return (rawInput: unknown) =>
|
|
17
|
+
safeParseOrThrow(rawRuntimeInputSchema, rawInput, "input");
|
|
18
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type {
|
|
3
|
+
BaseGameStateOfContract,
|
|
4
|
+
ManifestContractOf,
|
|
5
|
+
PhaseDefinition,
|
|
6
|
+
PhaseMapOf,
|
|
7
|
+
PhaseNameOfContract,
|
|
8
|
+
ReducerGameContractLike,
|
|
9
|
+
ReducerGameDefinition,
|
|
10
|
+
SchemaLike,
|
|
11
|
+
ViewMapOf,
|
|
12
|
+
} from "../model";
|
|
13
|
+
|
|
14
|
+
function createPhaseNameSchema<PhaseName extends string>(
|
|
15
|
+
phaseNames: readonly PhaseName[],
|
|
16
|
+
): z.ZodType<PhaseName> {
|
|
17
|
+
const allowed = new Set(phaseNames);
|
|
18
|
+
return z.custom<PhaseName>(
|
|
19
|
+
(value: unknown) =>
|
|
20
|
+
typeof value === "string" && allowed.has(value as PhaseName),
|
|
21
|
+
{ message: "Invalid phase name" },
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function collectIngressPhaseSchemas<
|
|
26
|
+
Contract extends ReducerGameContractLike,
|
|
27
|
+
Definitions extends PhaseMapOf<Contract>,
|
|
28
|
+
Views extends ViewMapOf<Contract>,
|
|
29
|
+
>(
|
|
30
|
+
definition: ReducerGameDefinition<Contract, Definitions, Views>,
|
|
31
|
+
): {
|
|
32
|
+
phaseEntries: Array<
|
|
33
|
+
[
|
|
34
|
+
PhaseNameOfContract<Contract>,
|
|
35
|
+
PhaseDefinition<
|
|
36
|
+
SchemaLike<object>,
|
|
37
|
+
BaseGameStateOfContract<Contract>,
|
|
38
|
+
ManifestContractOf<Contract>
|
|
39
|
+
>,
|
|
40
|
+
]
|
|
41
|
+
>;
|
|
42
|
+
phaseNames: PhaseNameOfContract<Contract>[];
|
|
43
|
+
phaseNameSchema: z.ZodType<PhaseNameOfContract<Contract>>;
|
|
44
|
+
} {
|
|
45
|
+
type PhaseName = PhaseNameOfContract<Contract>;
|
|
46
|
+
const phaseEntries = Object.entries(definition.phases) as Array<
|
|
47
|
+
[
|
|
48
|
+
PhaseName,
|
|
49
|
+
PhaseDefinition<
|
|
50
|
+
SchemaLike<object>,
|
|
51
|
+
BaseGameStateOfContract<Contract>,
|
|
52
|
+
ManifestContractOf<Contract>
|
|
53
|
+
>,
|
|
54
|
+
]
|
|
55
|
+
>;
|
|
56
|
+
const phaseNames = phaseEntries.map(([phaseName]) => phaseName);
|
|
57
|
+
return {
|
|
58
|
+
phaseEntries,
|
|
59
|
+
phaseNames,
|
|
60
|
+
phaseNameSchema: createPhaseNameSchema(phaseNames),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type * as Wire from "../../generated/reducer-contract/wire";
|
|
2
|
+
import type {
|
|
3
|
+
ManifestContract,
|
|
4
|
+
PlayerIdOfState,
|
|
5
|
+
ReducerSessionForConfig,
|
|
6
|
+
ReducerStateForConfig,
|
|
7
|
+
RuntimeSetupSelection,
|
|
8
|
+
RuntimeTableRecord,
|
|
9
|
+
SchemaLike,
|
|
10
|
+
} from "../model";
|
|
11
|
+
|
|
12
|
+
export type RawReducerFlowState = Wire.ReducerFlowState;
|
|
13
|
+
export type RawReducerRuntimeState = Wire.ReducerRuntimeState;
|
|
14
|
+
export type RawReducerSessionState = Wire.ReducerSessionState;
|
|
15
|
+
export type RawRuntimeInput = Wire.GameInput;
|
|
16
|
+
|
|
17
|
+
export type IngressRuntimeCodec<
|
|
18
|
+
Table extends RuntimeTableRecord,
|
|
19
|
+
Manifest extends ManifestContract<Table>,
|
|
20
|
+
PublicSchema extends SchemaLike<object>,
|
|
21
|
+
PrivateSchema extends SchemaLike<object>,
|
|
22
|
+
HiddenSchema extends SchemaLike<object>,
|
|
23
|
+
PhaseName extends string,
|
|
24
|
+
> = {
|
|
25
|
+
defaultRuntimeState: (
|
|
26
|
+
seed?: number | null,
|
|
27
|
+
setup?: RuntimeSetupSelection<Manifest> | null,
|
|
28
|
+
) => ReducerSessionForConfig<
|
|
29
|
+
Table,
|
|
30
|
+
PublicSchema,
|
|
31
|
+
PrivateSchema,
|
|
32
|
+
HiddenSchema,
|
|
33
|
+
PhaseName,
|
|
34
|
+
RuntimeSetupSelection<Manifest>
|
|
35
|
+
>["runtime"];
|
|
36
|
+
parseInitialTable: (
|
|
37
|
+
rawTable: ReducerStateForConfig<
|
|
38
|
+
Table,
|
|
39
|
+
PublicSchema,
|
|
40
|
+
PrivateSchema,
|
|
41
|
+
HiddenSchema,
|
|
42
|
+
PhaseName
|
|
43
|
+
>["table"],
|
|
44
|
+
playerIds?: readonly string[],
|
|
45
|
+
) => {
|
|
46
|
+
playerIds: PlayerIdOfState<
|
|
47
|
+
ReducerStateForConfig<
|
|
48
|
+
Table,
|
|
49
|
+
PublicSchema,
|
|
50
|
+
PrivateSchema,
|
|
51
|
+
HiddenSchema,
|
|
52
|
+
PhaseName
|
|
53
|
+
>
|
|
54
|
+
>[];
|
|
55
|
+
table: ReducerStateForConfig<
|
|
56
|
+
Table,
|
|
57
|
+
PublicSchema,
|
|
58
|
+
PrivateSchema,
|
|
59
|
+
HiddenSchema,
|
|
60
|
+
PhaseName
|
|
61
|
+
>["table"];
|
|
62
|
+
};
|
|
63
|
+
parseState: (
|
|
64
|
+
rawState: RawReducerSessionState,
|
|
65
|
+
) => ReducerSessionForConfig<
|
|
66
|
+
Table,
|
|
67
|
+
PublicSchema,
|
|
68
|
+
PrivateSchema,
|
|
69
|
+
HiddenSchema,
|
|
70
|
+
PhaseName
|
|
71
|
+
>;
|
|
72
|
+
serializeState: (
|
|
73
|
+
state: ReducerSessionForConfig<
|
|
74
|
+
Table,
|
|
75
|
+
PublicSchema,
|
|
76
|
+
PrivateSchema,
|
|
77
|
+
HiddenSchema,
|
|
78
|
+
PhaseName
|
|
79
|
+
>,
|
|
80
|
+
) => RawReducerSessionState;
|
|
81
|
+
parsePlayerId: (
|
|
82
|
+
rawPlayerId: string,
|
|
83
|
+
) => PlayerIdOfState<
|
|
84
|
+
ReducerStateForConfig<
|
|
85
|
+
Table,
|
|
86
|
+
PublicSchema,
|
|
87
|
+
PrivateSchema,
|
|
88
|
+
HiddenSchema,
|
|
89
|
+
PhaseName
|
|
90
|
+
>
|
|
91
|
+
>;
|
|
92
|
+
/**
|
|
93
|
+
* Validate the raw wire input against the unified `interaction` schema.
|
|
94
|
+
* Returns the schema-validated shape unchanged; downstream layers (the
|
|
95
|
+
* ingress bundle) are responsible for routing it onto the engine-internal
|
|
96
|
+
* action/continuation discriminator.
|
|
97
|
+
*/
|
|
98
|
+
parseInput: (rawInput: RawRuntimeInput) => RawRuntimeInput;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type UntrustedRuntimeTable = RuntimeTableRecord;
|
|
102
|
+
export type UntrustedReducerSessionState = RawReducerSessionState;
|
|
103
|
+
export type UntrustedRuntimeInput = RawRuntimeInput;
|
|
104
|
+
export type DecodedReducerSession<State> = {
|
|
105
|
+
state: State;
|
|
106
|
+
template?: UntrustedRuntimeTable;
|
|
107
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createIngressRuntimeCodec } from "./session-codec";
|
|
2
|
+
export { runtimePayloadSchema } from "./runtime-payload";
|
|
3
|
+
export { safeParseOrThrow } from "../parse-utils";
|
|
4
|
+
export type {
|
|
5
|
+
DecodedReducerSession,
|
|
6
|
+
IngressRuntimeCodec,
|
|
7
|
+
RawReducerFlowState,
|
|
8
|
+
RawReducerRuntimeState,
|
|
9
|
+
RawReducerSessionState,
|
|
10
|
+
RawRuntimeInput,
|
|
11
|
+
UntrustedReducerSessionState,
|
|
12
|
+
UntrustedRuntimeInput,
|
|
13
|
+
UntrustedRuntimeTable,
|
|
14
|
+
} from "./raw-types";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { RuntimePayload } from "../model";
|
|
3
|
+
|
|
4
|
+
export const runtimePayloadSchema: z.ZodType<RuntimePayload> = z.lazy(() =>
|
|
5
|
+
z.union([
|
|
6
|
+
z.boolean(),
|
|
7
|
+
z.number(),
|
|
8
|
+
z.string(),
|
|
9
|
+
z.null(),
|
|
10
|
+
z.array(runtimePayloadSchema),
|
|
11
|
+
z.record(z.string(), z.union([runtimePayloadSchema, z.undefined()])),
|
|
12
|
+
]),
|
|
13
|
+
);
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as ContractZod from "../../generated/reducer-contract/zod";
|
|
3
|
+
import { safeParseOrThrow } from "../parse-utils";
|
|
4
|
+
import type {
|
|
5
|
+
BaseGameSessionOfContract,
|
|
6
|
+
GameStateOf,
|
|
7
|
+
HiddenSchemaOfContract,
|
|
8
|
+
ManifestContractOf,
|
|
9
|
+
ManifestOf,
|
|
10
|
+
PhaseMapOf,
|
|
11
|
+
PhaseNameOfContract,
|
|
12
|
+
PlayerIdOfState,
|
|
13
|
+
PrivateSchemaOfContract,
|
|
14
|
+
PublicSchemaOfContract,
|
|
15
|
+
ReducerGameContractLike,
|
|
16
|
+
ReducerGameDefinition,
|
|
17
|
+
RuntimeSetupSelection,
|
|
18
|
+
TableOfManifest,
|
|
19
|
+
ViewMapOf,
|
|
20
|
+
} from "../model";
|
|
21
|
+
import type { IngressRuntimeCodec, RawReducerSessionState } from "./raw-types";
|
|
22
|
+
import { createRuntimeInputParser } from "./input-codec";
|
|
23
|
+
import { collectIngressPhaseSchemas } from "./phase-schemas";
|
|
24
|
+
|
|
25
|
+
const runtimePayloadSchema: z.ZodType<unknown> = z.lazy(() =>
|
|
26
|
+
z.union([
|
|
27
|
+
z.string(),
|
|
28
|
+
z.number(),
|
|
29
|
+
z.boolean(),
|
|
30
|
+
z.null(),
|
|
31
|
+
z.array(runtimePayloadSchema),
|
|
32
|
+
z.record(z.string(), runtimePayloadSchema),
|
|
33
|
+
]),
|
|
34
|
+
);
|
|
35
|
+
const runtimeRecordSchema = z.record(z.string(), runtimePayloadSchema);
|
|
36
|
+
const perPlayerSchema = <Value extends z.ZodTypeAny>(valueSchema: Value) =>
|
|
37
|
+
z
|
|
38
|
+
.object({
|
|
39
|
+
__perPlayer: z.literal(true),
|
|
40
|
+
entries: z.array(z.tuple([z.string(), valueSchema])),
|
|
41
|
+
})
|
|
42
|
+
.strict();
|
|
43
|
+
const runtimeComponentLocationSchema = z.discriminatedUnion("type", [
|
|
44
|
+
z.object({ type: z.literal("Detached") }).strict(),
|
|
45
|
+
z
|
|
46
|
+
.object({
|
|
47
|
+
type: z.literal("InDeck"),
|
|
48
|
+
deckId: z.string(),
|
|
49
|
+
playedBy: z.string().nullable(),
|
|
50
|
+
position: z.number().int().nullable().optional(),
|
|
51
|
+
})
|
|
52
|
+
.strict(),
|
|
53
|
+
z
|
|
54
|
+
.object({
|
|
55
|
+
type: z.literal("InHand"),
|
|
56
|
+
handId: z.string(),
|
|
57
|
+
playerId: z.string(),
|
|
58
|
+
position: z.number().int().nullable().optional(),
|
|
59
|
+
})
|
|
60
|
+
.strict(),
|
|
61
|
+
z
|
|
62
|
+
.object({
|
|
63
|
+
type: z.literal("InZone"),
|
|
64
|
+
zoneId: z.string(),
|
|
65
|
+
playedBy: z.string().nullable().optional(),
|
|
66
|
+
position: z.number().int().nullable().optional(),
|
|
67
|
+
})
|
|
68
|
+
.strict(),
|
|
69
|
+
z
|
|
70
|
+
.object({
|
|
71
|
+
type: z.literal("OnSpace"),
|
|
72
|
+
boardId: z.string(),
|
|
73
|
+
spaceId: z.string(),
|
|
74
|
+
position: z.number().int().nullable().optional(),
|
|
75
|
+
})
|
|
76
|
+
.strict(),
|
|
77
|
+
z
|
|
78
|
+
.object({
|
|
79
|
+
type: z.literal("InContainer"),
|
|
80
|
+
boardId: z.string(),
|
|
81
|
+
containerId: z.string(),
|
|
82
|
+
position: z.number().int().nullable().optional(),
|
|
83
|
+
})
|
|
84
|
+
.strict(),
|
|
85
|
+
z
|
|
86
|
+
.object({
|
|
87
|
+
type: z.literal("OnEdge"),
|
|
88
|
+
boardId: z.string(),
|
|
89
|
+
edgeId: z.string(),
|
|
90
|
+
position: z.number().int().nullable().optional(),
|
|
91
|
+
})
|
|
92
|
+
.strict(),
|
|
93
|
+
z
|
|
94
|
+
.object({
|
|
95
|
+
type: z.literal("OnVertex"),
|
|
96
|
+
boardId: z.string(),
|
|
97
|
+
vertexId: z.string(),
|
|
98
|
+
position: z.number().int().nullable().optional(),
|
|
99
|
+
})
|
|
100
|
+
.strict(),
|
|
101
|
+
z
|
|
102
|
+
.object({
|
|
103
|
+
type: z.literal("InSlot"),
|
|
104
|
+
host: z.union([
|
|
105
|
+
z.object({ kind: z.literal("piece"), id: z.string() }).strict(),
|
|
106
|
+
z.object({ kind: z.literal("die"), id: z.string() }).strict(),
|
|
107
|
+
]),
|
|
108
|
+
slotId: z.string(),
|
|
109
|
+
position: z.number().int().nullable().optional(),
|
|
110
|
+
})
|
|
111
|
+
.strict(),
|
|
112
|
+
]);
|
|
113
|
+
const currentRuntimeTableSchema = z
|
|
114
|
+
.object({
|
|
115
|
+
playerOrder: z.array(z.string()),
|
|
116
|
+
zones: z
|
|
117
|
+
.object({
|
|
118
|
+
shared: z.record(z.string(), z.array(z.string())),
|
|
119
|
+
perPlayer: z.record(z.string(), perPlayerSchema(z.array(z.string()))),
|
|
120
|
+
visibility: z.record(
|
|
121
|
+
z.string(),
|
|
122
|
+
z.enum(["all", "ownerOnly", "public", "hidden"]),
|
|
123
|
+
),
|
|
124
|
+
cardSetIdsByZoneId: z
|
|
125
|
+
.record(z.string(), z.array(z.string()))
|
|
126
|
+
.optional(),
|
|
127
|
+
})
|
|
128
|
+
.strict(),
|
|
129
|
+
decks: z.record(z.string(), z.array(z.string())),
|
|
130
|
+
hands: z.record(z.string(), perPlayerSchema(z.array(z.string()))),
|
|
131
|
+
handVisibility: z.record(
|
|
132
|
+
z.string(),
|
|
133
|
+
z.enum(["all", "ownerOnly", "public", "hidden"]),
|
|
134
|
+
),
|
|
135
|
+
cards: z.record(
|
|
136
|
+
z.string(),
|
|
137
|
+
z
|
|
138
|
+
.object({
|
|
139
|
+
componentType: z.string().optional(),
|
|
140
|
+
id: z.string(),
|
|
141
|
+
cardSetId: z.string(),
|
|
142
|
+
cardType: z.string(),
|
|
143
|
+
name: z.string().optional(),
|
|
144
|
+
text: z.string().optional(),
|
|
145
|
+
properties: runtimeRecordSchema,
|
|
146
|
+
})
|
|
147
|
+
.strict(),
|
|
148
|
+
),
|
|
149
|
+
pieces: z.record(
|
|
150
|
+
z.string(),
|
|
151
|
+
z
|
|
152
|
+
.object({
|
|
153
|
+
componentType: z.string().optional(),
|
|
154
|
+
id: z.string(),
|
|
155
|
+
pieceTypeId: z.string(),
|
|
156
|
+
pieceName: z.string().nullable().optional(),
|
|
157
|
+
ownerId: z.string().nullable().optional(),
|
|
158
|
+
properties: runtimeRecordSchema,
|
|
159
|
+
})
|
|
160
|
+
.strict(),
|
|
161
|
+
),
|
|
162
|
+
componentLocations: z.record(z.string(), runtimeComponentLocationSchema),
|
|
163
|
+
ownerOfCard: z.record(z.string(), z.string().nullable()),
|
|
164
|
+
visibility: z.record(
|
|
165
|
+
z.string(),
|
|
166
|
+
z
|
|
167
|
+
.object({
|
|
168
|
+
faceUp: z.boolean(),
|
|
169
|
+
visibleTo: z.array(z.string()).nullable().optional(),
|
|
170
|
+
})
|
|
171
|
+
.strict(),
|
|
172
|
+
),
|
|
173
|
+
resources: perPlayerSchema(runtimeRecordSchema),
|
|
174
|
+
boards: z
|
|
175
|
+
.object({
|
|
176
|
+
byId: z.record(z.string(), runtimeRecordSchema),
|
|
177
|
+
hex: z.record(z.string(), runtimeRecordSchema),
|
|
178
|
+
square: z.record(z.string(), runtimeRecordSchema),
|
|
179
|
+
network: z.record(z.string(), runtimeRecordSchema).optional(),
|
|
180
|
+
track: z.record(z.string(), runtimeRecordSchema).optional(),
|
|
181
|
+
})
|
|
182
|
+
.strict(),
|
|
183
|
+
dice: z.record(
|
|
184
|
+
z.string(),
|
|
185
|
+
z
|
|
186
|
+
.object({
|
|
187
|
+
componentType: z.string().optional(),
|
|
188
|
+
id: z.string(),
|
|
189
|
+
dieTypeId: z.string(),
|
|
190
|
+
dieName: z.string().nullable().optional(),
|
|
191
|
+
ownerId: z.string().nullable().optional(),
|
|
192
|
+
sides: z.number().int(),
|
|
193
|
+
value: z.number().int().nullable().optional(),
|
|
194
|
+
properties: runtimeRecordSchema,
|
|
195
|
+
})
|
|
196
|
+
.strict(),
|
|
197
|
+
),
|
|
198
|
+
})
|
|
199
|
+
.strict();
|
|
200
|
+
|
|
201
|
+
export function createIngressRuntimeCodec<
|
|
202
|
+
Contract extends ReducerGameContractLike,
|
|
203
|
+
Definitions extends PhaseMapOf<Contract>,
|
|
204
|
+
Views extends ViewMapOf<Contract>,
|
|
205
|
+
>(
|
|
206
|
+
definition: ReducerGameDefinition<Contract, Definitions, Views>,
|
|
207
|
+
): IngressRuntimeCodec<
|
|
208
|
+
TableOfManifest<ManifestOf<Contract>>,
|
|
209
|
+
ManifestContractOf<Contract>,
|
|
210
|
+
PublicSchemaOfContract<Contract>,
|
|
211
|
+
PrivateSchemaOfContract<Contract>,
|
|
212
|
+
HiddenSchemaOfContract<Contract>,
|
|
213
|
+
PhaseNameOfContract<Contract>
|
|
214
|
+
> {
|
|
215
|
+
type Definition = ReducerGameDefinition<Contract, Definitions, Views>;
|
|
216
|
+
type DomainState = GameStateOf<Definition>;
|
|
217
|
+
type State = BaseGameSessionOfContract<Contract>;
|
|
218
|
+
type Manifest = ManifestContractOf<Contract>;
|
|
219
|
+
type PhaseName = PhaseNameOfContract<Contract>;
|
|
220
|
+
type ReturnType = IngressRuntimeCodec<
|
|
221
|
+
TableOfManifest<ManifestOf<Contract>>,
|
|
222
|
+
Manifest,
|
|
223
|
+
PublicSchemaOfContract<Contract>,
|
|
224
|
+
PrivateSchemaOfContract<Contract>,
|
|
225
|
+
HiddenSchemaOfContract<Contract>,
|
|
226
|
+
PhaseName
|
|
227
|
+
>;
|
|
228
|
+
type PlayerId = PlayerIdOfState<DomainState>;
|
|
229
|
+
|
|
230
|
+
const { phaseNameSchema } = collectIngressPhaseSchemas(definition);
|
|
231
|
+
const playerIdSchema = definition.contract.manifest.ids
|
|
232
|
+
.playerId as z.ZodType<PlayerId>;
|
|
233
|
+
|
|
234
|
+
const flowSchema = z.object({
|
|
235
|
+
currentPhase: phaseNameSchema,
|
|
236
|
+
turn: z.number().int(),
|
|
237
|
+
round: z.number().int(),
|
|
238
|
+
activePlayers: z.array(playerIdSchema),
|
|
239
|
+
});
|
|
240
|
+
const runtimeStateSchema = z.object({
|
|
241
|
+
rng: z.object({
|
|
242
|
+
seed: z.number().int().nullable(),
|
|
243
|
+
cursor: z.number().int(),
|
|
244
|
+
trace: z.array(z.string()),
|
|
245
|
+
}),
|
|
246
|
+
setup: z
|
|
247
|
+
.object({
|
|
248
|
+
profileId: z.string(),
|
|
249
|
+
optionValues: z.record(z.string(), z.string().nullable()),
|
|
250
|
+
})
|
|
251
|
+
.nullable(),
|
|
252
|
+
simultaneous: z.object({
|
|
253
|
+
current: z
|
|
254
|
+
.object({
|
|
255
|
+
phaseName: phaseNameSchema,
|
|
256
|
+
actors: z.array(playerIdSchema),
|
|
257
|
+
submissions: z.record(
|
|
258
|
+
z.string(),
|
|
259
|
+
z.object({
|
|
260
|
+
interactionId: z.string(),
|
|
261
|
+
params: runtimePayloadSchema,
|
|
262
|
+
}),
|
|
263
|
+
),
|
|
264
|
+
})
|
|
265
|
+
.nullable(),
|
|
266
|
+
}),
|
|
267
|
+
lastTransition: z
|
|
268
|
+
.object({
|
|
269
|
+
from: phaseNameSchema,
|
|
270
|
+
to: phaseNameSchema,
|
|
271
|
+
})
|
|
272
|
+
.nullable(),
|
|
273
|
+
});
|
|
274
|
+
const parseRuntimeInput = createRuntimeInputParser(playerIdSchema);
|
|
275
|
+
|
|
276
|
+
// The return type uses branded/mapped types derived from the contract generic.
|
|
277
|
+
// TypeScript cannot verify that plain objects satisfy these deep mapped types,
|
|
278
|
+
// but the runtime Zod parsing ensures correctness.
|
|
279
|
+
return {
|
|
280
|
+
defaultRuntimeState(
|
|
281
|
+
seed: number | null = null,
|
|
282
|
+
setup: RuntimeSetupSelection<Manifest> | null = null,
|
|
283
|
+
) {
|
|
284
|
+
const runtimeState: State["runtime"] = {
|
|
285
|
+
rng: {
|
|
286
|
+
seed,
|
|
287
|
+
cursor: 0,
|
|
288
|
+
trace: [],
|
|
289
|
+
},
|
|
290
|
+
setup,
|
|
291
|
+
simultaneous: { current: null },
|
|
292
|
+
lastTransition: null,
|
|
293
|
+
};
|
|
294
|
+
return runtimeState;
|
|
295
|
+
},
|
|
296
|
+
parseInitialTable(rawTable: unknown, playerIds: string[] | undefined) {
|
|
297
|
+
const table = safeParseOrThrow(
|
|
298
|
+
currentRuntimeTableSchema,
|
|
299
|
+
rawTable,
|
|
300
|
+
"table",
|
|
301
|
+
) as unknown as TableOfManifest<ManifestOf<Contract>>;
|
|
302
|
+
return {
|
|
303
|
+
table,
|
|
304
|
+
playerIds: safeParseOrThrow(
|
|
305
|
+
z.array(playerIdSchema),
|
|
306
|
+
playerIds && playerIds.length > 0 ? playerIds : table.playerOrder,
|
|
307
|
+
"table.playerOrder",
|
|
308
|
+
),
|
|
309
|
+
};
|
|
310
|
+
},
|
|
311
|
+
parseState(rawState: RawReducerSessionState) {
|
|
312
|
+
const envelope = safeParseOrThrow(
|
|
313
|
+
ContractZod.ReducerSessionStateSchema,
|
|
314
|
+
rawState,
|
|
315
|
+
"state",
|
|
316
|
+
);
|
|
317
|
+
const table = safeParseOrThrow(
|
|
318
|
+
definition.contract.manifest.tableSchema,
|
|
319
|
+
envelope.domain.table,
|
|
320
|
+
"domain.table",
|
|
321
|
+
);
|
|
322
|
+
const playerIds = [...table.playerOrder] as PlayerId[];
|
|
323
|
+
const privateState = Object.fromEntries(
|
|
324
|
+
playerIds.map((playerId) => [
|
|
325
|
+
playerId,
|
|
326
|
+
safeParseOrThrow(
|
|
327
|
+
definition.contract.state.private,
|
|
328
|
+
envelope.domain.privateState[playerId] ?? {},
|
|
329
|
+
`privateState:${playerId}`,
|
|
330
|
+
),
|
|
331
|
+
]),
|
|
332
|
+
) as State["domain"]["privateState"];
|
|
333
|
+
const flow = safeParseOrThrow(
|
|
334
|
+
flowSchema,
|
|
335
|
+
{
|
|
336
|
+
currentPhase: envelope.domain.flow.currentPhase,
|
|
337
|
+
turn: envelope.domain.flow.turn,
|
|
338
|
+
round: envelope.domain.flow.round,
|
|
339
|
+
activePlayers: envelope.domain.flow.activePlayers,
|
|
340
|
+
},
|
|
341
|
+
"domain.flow",
|
|
342
|
+
);
|
|
343
|
+
const currentPhaseDefinition = definition.phases[flow.currentPhase];
|
|
344
|
+
if (!currentPhaseDefinition) {
|
|
345
|
+
throw new Error(`Unknown reducer phase '${flow.currentPhase}'.`);
|
|
346
|
+
}
|
|
347
|
+
const rawPhaseState = envelope.domain.phase;
|
|
348
|
+
const phase = safeParseOrThrow(
|
|
349
|
+
currentPhaseDefinition.state,
|
|
350
|
+
rawPhaseState ?? {},
|
|
351
|
+
`phase:${flow.currentPhase}`,
|
|
352
|
+
) as State["domain"]["phase"];
|
|
353
|
+
|
|
354
|
+
const parsedState: State = {
|
|
355
|
+
domain: {
|
|
356
|
+
table,
|
|
357
|
+
publicState: safeParseOrThrow(
|
|
358
|
+
definition.contract.state.public,
|
|
359
|
+
envelope.domain.publicState,
|
|
360
|
+
"domain.publicState",
|
|
361
|
+
) as State["domain"]["publicState"],
|
|
362
|
+
privateState,
|
|
363
|
+
hiddenState: safeParseOrThrow(
|
|
364
|
+
definition.contract.state.hidden,
|
|
365
|
+
envelope.domain.hiddenState,
|
|
366
|
+
"domain.hiddenState",
|
|
367
|
+
) as State["domain"]["hiddenState"],
|
|
368
|
+
flow,
|
|
369
|
+
phase,
|
|
370
|
+
},
|
|
371
|
+
runtime: safeParseOrThrow(
|
|
372
|
+
runtimeStateSchema,
|
|
373
|
+
envelope.runtime,
|
|
374
|
+
"runtime",
|
|
375
|
+
) as unknown as State["runtime"],
|
|
376
|
+
};
|
|
377
|
+
return parsedState;
|
|
378
|
+
},
|
|
379
|
+
serializeState(state: State) {
|
|
380
|
+
return {
|
|
381
|
+
domain: { ...state.domain },
|
|
382
|
+
runtime: state.runtime,
|
|
383
|
+
} as RawReducerSessionState;
|
|
384
|
+
},
|
|
385
|
+
parsePlayerId(rawPlayerId: string) {
|
|
386
|
+
return safeParseOrThrow(playerIdSchema, rawPlayerId, "playerId");
|
|
387
|
+
},
|
|
388
|
+
parseInput(rawInput: unknown) {
|
|
389
|
+
return parseRuntimeInput(rawInput);
|
|
390
|
+
},
|
|
391
|
+
} as unknown as ReturnType;
|
|
392
|
+
}
|