@dreamboard-games/sdk 0.4.0-alpha.7 → 0.4.0-alpha.8

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 (49) hide show
  1. package/REFERENCE.md +153 -51
  2. package/dist/authoring/index.js +2 -2
  3. package/dist/{chunk-52DH7VQF.js → chunk-2TAKLJJD.js} +5 -2
  4. package/dist/{chunk-52DH7VQF.js.map → chunk-2TAKLJJD.js.map} +1 -1
  5. package/dist/{chunk-TGMXBRKY.js → chunk-3BLN5POZ.js} +5 -3
  6. package/dist/chunk-3BLN5POZ.js.map +1 -0
  7. package/dist/{chunk-RKGJ64UN.js → chunk-44N3T2A5.js} +2 -2
  8. package/dist/{chunk-IU6KGPY7.js → chunk-5CQIJHGF.js} +6 -2
  9. package/dist/{chunk-IU6KGPY7.js.map → chunk-5CQIJHGF.js.map} +1 -1
  10. package/dist/{chunk-5IHU5CUK.js → chunk-IYX5OO2K.js} +12 -22
  11. package/dist/chunk-IYX5OO2K.js.map +1 -0
  12. package/dist/{chunk-Q322XCY2.js → chunk-VTK4TIXC.js} +3 -3
  13. package/dist/{chunk-KYEWGZ2Y.js → chunk-VTNEWMWJ.js} +2 -2
  14. package/dist/{chunk-KYEWGZ2Y.js.map → chunk-VTNEWMWJ.js.map} +1 -1
  15. package/dist/{chunk-3QIZKXJ2.js → chunk-XV27IQHA.js} +3 -3
  16. package/dist/{chunk-NO537WSS.js → chunk-YGQTL63W.js} +2 -2
  17. package/dist/{chunk-VLG4YST5.js → chunk-ZYONCTZ2.js} +2 -2
  18. package/dist/codegen.js +1 -1
  19. package/dist/{index.d-DMASeF6M.d.ts → index.d-C0PKOVbh.d.ts} +25 -4
  20. package/dist/index.js +2 -2
  21. package/dist/package-set.d.ts +2 -2
  22. package/dist/package-set.js +2 -2
  23. package/dist/{protocol-835hEGne.d.ts → protocol-nS2ojsGr.d.ts} +5 -0
  24. package/dist/reducer/advanced.d.ts +2 -2
  25. package/dist/reducer-contract.d.ts +1 -1
  26. package/dist/reducer-contract.js +2 -2
  27. package/dist/reducer.d.ts +23 -20
  28. package/dist/reducer.js +131 -84
  29. package/dist/reducer.js.map +1 -1
  30. package/dist/runtime/primitives.js +3 -3
  31. package/dist/runtime/workspace-contract.js +4 -4
  32. package/dist/runtime.d.ts +3 -3
  33. package/dist/runtime.js +9 -9
  34. package/dist/testing-runtime.d.ts +2 -2
  35. package/dist/testing-runtime.js +2 -2
  36. package/dist/testing.d.ts +5 -5
  37. package/dist/testing.js +4 -4
  38. package/dist/{types-DcADVHe9.d.ts → types-B_3pObUV.d.ts} +1 -1
  39. package/dist/{types-aI4V9CWe.d.ts → types-CTeN_QAk.d.ts} +1 -1
  40. package/dist/types.d.ts +4 -0
  41. package/dist/{views-32rSsfeU.d.ts → views-Qx-EHBP8.d.ts} +27 -10
  42. package/package.json +1 -2
  43. package/dist/chunk-5IHU5CUK.js.map +0 -1
  44. package/dist/chunk-TGMXBRKY.js.map +0 -1
  45. /package/dist/{chunk-RKGJ64UN.js.map → chunk-44N3T2A5.js.map} +0 -0
  46. /package/dist/{chunk-Q322XCY2.js.map → chunk-VTK4TIXC.js.map} +0 -0
  47. /package/dist/{chunk-3QIZKXJ2.js.map → chunk-XV27IQHA.js.map} +0 -0
  48. /package/dist/{chunk-NO537WSS.js.map → chunk-YGQTL63W.js.map} +0 -0
  49. /package/dist/{chunk-VLG4YST5.js.map → chunk-ZYONCTZ2.js.map} +0 -0
package/dist/reducer.js CHANGED
@@ -133,7 +133,7 @@ import {
133
133
  REDUCER_CONTRACT_VERSION,
134
134
  builders_exports,
135
135
  zod_exports
136
- } from "./chunk-TGMXBRKY.js";
136
+ } from "./chunk-3BLN5POZ.js";
137
137
  import {
138
138
  RuntimeJsonSchema,
139
139
  assertJsonWithinLimits
@@ -1316,9 +1316,17 @@ function defineStepPhase() {
1316
1316
  }
1317
1317
 
1318
1318
  // src/reducer/authoring/view-stage.ts
1319
- function defineView() {
1319
+ function defineSharedView() {
1320
1320
  return (definition) => definition;
1321
1321
  }
1322
+ function definePlayerView() {
1323
+ return (definition) => definition;
1324
+ }
1325
+ function defineEmptyView() {
1326
+ return {
1327
+ project: () => ({})
1328
+ };
1329
+ }
1322
1330
  function defineStaticView() {
1323
1331
  return (definition) => definition;
1324
1332
  }
@@ -1369,7 +1377,9 @@ function createContractAuthoring(contract) {
1369
1377
  return {
1370
1378
  contract,
1371
1379
  game: (definition) => defineGame({ contract, ...definition }),
1372
- view: (definition) => defineView()(definition),
1380
+ sharedView: (definition) => defineSharedView()(definition),
1381
+ playerView: (definition) => definePlayerView()(definition),
1382
+ emptyView: () => defineEmptyView(),
1373
1383
  staticView: (definition) => defineStaticView()(definition),
1374
1384
  phase: (name) => {
1375
1385
  const cached = phaseCache.get(name);
@@ -5598,23 +5608,25 @@ function createProjectionContext(options) {
5598
5608
 
5599
5609
  // src/reducer/bundle/trusted/projection-builder.ts
5600
5610
  function createProjectionBuilder(scope, interactions) {
5601
- function createDescriptorRegistry() {
5611
+ function createDescriptorRegistry(timing) {
5602
5612
  const byRef = {};
5603
5613
  const byHash = /* @__PURE__ */ new Map();
5604
5614
  return {
5605
5615
  add(descriptor, actorSeat) {
5606
- const enriched = descriptorWithBrowserReplayDigests(
5607
- descriptor,
5608
- actorSeat
5609
- );
5610
- const fingerprint = stableStringify(enriched);
5611
- const existing = byHash.get(fingerprint);
5612
- if (existing) return existing;
5613
- const base = typeof enriched.interactionId === "string" && enriched.interactionId.length > 0 ? enriched.interactionId : "interaction";
5614
- const ref = `${base}:${fnv1a64(fingerprint)}`;
5615
- byHash.set(fingerprint, ref);
5616
- byRef[ref] = enriched;
5617
- return ref;
5616
+ return measureProjectionTiming(timing, "descriptorHashMs", () => {
5617
+ const enriched = descriptorWithBrowserReplayDigests(
5618
+ descriptor,
5619
+ actorSeat
5620
+ );
5621
+ const fingerprint = stableStringify(enriched);
5622
+ const existing = byHash.get(fingerprint);
5623
+ if (existing) return existing;
5624
+ const base = typeof enriched.interactionId === "string" && enriched.interactionId.length > 0 ? enriched.interactionId : "interaction";
5625
+ const ref = `${base}:${fnv1a64(fingerprint)}`;
5626
+ byHash.set(fingerprint, ref);
5627
+ byRef[ref] = enriched;
5628
+ return ref;
5629
+ });
5618
5630
  },
5619
5631
  entries() {
5620
5632
  return byRef;
@@ -5772,12 +5784,20 @@ function createProjectionBuilder(scope, interactions) {
5772
5784
  pendingPlayerIds
5773
5785
  };
5774
5786
  }
5775
- function resolveViewFor(combinedState, playerId, viewId, projection) {
5776
- const views = scope.definition.views;
5777
- const view = views?.[viewId];
5778
- if (!view) {
5779
- return null;
5780
- }
5787
+ function resolveSharedViewFor(combinedState, projection) {
5788
+ const view = scope.definition.views.shared;
5789
+ const viewArgs = {
5790
+ ...scope.buildContext(combinedState),
5791
+ ...scope.runtimeHelpers,
5792
+ fx: projection.fx,
5793
+ q: projection.q,
5794
+ derived: projection.derived,
5795
+ state: projection.domainState
5796
+ };
5797
+ return view.project(viewArgs);
5798
+ }
5799
+ function resolvePlayerViewFor(combinedState, playerId, sharedView, projection) {
5800
+ const view = scope.definition.views.player;
5781
5801
  const viewArgs = {
5782
5802
  ...scope.buildContext(combinedState),
5783
5803
  ...scope.runtimeHelpers,
@@ -5785,14 +5805,14 @@ function createProjectionBuilder(scope, interactions) {
5785
5805
  q: projection.q,
5786
5806
  derived: projection.derived,
5787
5807
  state: projection.domainState,
5788
- playerId
5808
+ playerId,
5809
+ shared: sharedView
5789
5810
  };
5790
5811
  return view.project(viewArgs);
5791
5812
  }
5792
5813
  function projectSeatsDynamic({
5793
5814
  state,
5794
5815
  playerIds,
5795
- viewId = "player",
5796
5816
  projectionMode = "full"
5797
5817
  }) {
5798
5818
  const combinedState = scope.toCombinedState(state);
@@ -5800,57 +5820,105 @@ function createProjectionBuilder(scope, interactions) {
5800
5820
  combinedState,
5801
5821
  domainState: scope.toDomainState(combinedState)
5802
5822
  });
5803
- const registry = createDescriptorRegistry();
5823
+ const timing = createProjectionTimingMetadata();
5824
+ const registry = createDescriptorRegistry(timing);
5804
5825
  const seats = {};
5826
+ const sharedView = projectionMode === "full" ? measureProjectionTiming(
5827
+ timing,
5828
+ "resolveViewMs",
5829
+ () => resolveSharedViewFor(combinedState, projection)
5830
+ ) : void 0;
5805
5831
  for (const [actorSeat, playerId] of playerIds.entries()) {
5806
- const availableInteractionRefs = interactions.resolveAvailableInteractionsFor(combinedState, playerId, {
5807
- projection
5808
- }).map((descriptor) => registry.add(descriptor, actorSeat));
5809
- seats[playerId] = {
5810
- ...projectionMode === "full" ? {
5811
- view: resolveViewFor(combinedState, playerId, viewId, projection),
5812
- zones: resolveZoneHandlesFor(
5832
+ const availableInteractions = measureProjectionTiming(
5833
+ timing,
5834
+ "resolveAvailableInteractionsMs",
5835
+ () => interactions.resolveAvailableInteractionsFor(
5836
+ combinedState,
5837
+ playerId,
5838
+ {
5839
+ projection
5840
+ }
5841
+ )
5842
+ );
5843
+ const availableInteractionRefs = availableInteractions.map(
5844
+ (descriptor) => registry.add(descriptor, actorSeat)
5845
+ );
5846
+ const fullProjection = projectionMode === "full" ? {
5847
+ view: measureProjectionTiming(
5848
+ timing,
5849
+ "resolveViewMs",
5850
+ () => resolvePlayerViewFor(
5851
+ combinedState,
5852
+ playerId,
5853
+ sharedView,
5854
+ projection
5855
+ )
5856
+ ),
5857
+ zones: measureProjectionTiming(
5858
+ timing,
5859
+ "resolveZoneHandlesMs",
5860
+ () => resolveZoneHandlesFor(
5813
5861
  combinedState,
5814
5862
  playerId,
5815
5863
  actorSeat,
5816
5864
  projection,
5817
5865
  registry
5818
5866
  )
5819
- } : {},
5867
+ )
5868
+ } : {};
5869
+ seats[playerId] = {
5870
+ ...fullProjection,
5820
5871
  availableInteractionRefs
5821
5872
  };
5822
5873
  }
5823
- return {
5824
- currentStage: resolveCurrentStageFor(combinedState, projection),
5825
- stageSeats: resolveStageSeatsFor(state),
5826
- simultaneousPhase: resolveSimultaneousPhaseFor(state),
5827
- guidance: resolveGuidanceFor(combinedState),
5828
- recentEvents: [],
5829
- interactionsByRef: registry.entries(),
5830
- seats
5831
- };
5832
- }
5833
- function projectSeatViewDynamic({
5834
- state,
5835
- playerId,
5836
- viewId = "player"
5837
- }) {
5838
- const combinedState = scope.toCombinedState(state);
5839
- const projection = createProjectionContext({
5840
- combinedState,
5841
- domainState: scope.toDomainState(combinedState)
5842
- });
5843
- return resolveViewFor(combinedState, playerId, viewId, projection);
5874
+ return withProjectionTiming(
5875
+ {
5876
+ currentStage: resolveCurrentStageFor(combinedState, projection),
5877
+ stageSeats: resolveStageSeatsFor(state),
5878
+ simultaneousPhase: resolveSimultaneousPhaseFor(state),
5879
+ ...projectionMode === "full" ? { sharedView } : {},
5880
+ guidance: resolveGuidanceFor(combinedState),
5881
+ recentEvents: [],
5882
+ interactionsByRef: registry.entries(),
5883
+ seats
5884
+ },
5885
+ timing
5886
+ );
5844
5887
  }
5845
5888
  return {
5846
5889
  projectSeatsDynamic,
5847
- projectSeatViewDynamic,
5848
5890
  resolveCurrentStageFor,
5849
5891
  resolveStageSeatsFor,
5850
- resolveViewFor,
5892
+ resolvePlayerViewFor,
5893
+ resolveSharedViewFor,
5851
5894
  resolveZoneHandlesFor
5852
5895
  };
5853
5896
  }
5897
+ function createProjectionTimingMetadata() {
5898
+ return {
5899
+ resolveAvailableInteractionsMs: 0,
5900
+ resolveViewMs: 0,
5901
+ resolveZoneHandlesMs: 0,
5902
+ descriptorHashMs: 0
5903
+ };
5904
+ }
5905
+ function measureProjectionTiming(timing, field, block) {
5906
+ const startedAt = performance.now();
5907
+ try {
5908
+ return block();
5909
+ } finally {
5910
+ timing[field] += performance.now() - startedAt;
5911
+ }
5912
+ }
5913
+ function withProjectionTiming(projection, timing) {
5914
+ Object.defineProperty(projection, "timing", {
5915
+ value: timing,
5916
+ enumerable: false,
5917
+ configurable: false,
5918
+ writable: false
5919
+ });
5920
+ return projection;
5921
+ }
5854
5922
  function descriptorWithBrowserReplayDigests(descriptor, actorSeat) {
5855
5923
  const descriptorDigestValue = descriptor.descriptorDigest ?? interactionDescriptorDigest(descriptor);
5856
5924
  return {
@@ -6384,9 +6452,6 @@ function createTrustedReducerBundle(definition, options = {}) {
6384
6452
  },
6385
6453
  projectSeatsDynamic(input) {
6386
6454
  return projection.projectSeatsDynamic(input);
6387
- },
6388
- projectSeatViewDynamic(input) {
6389
- return projection.projectSeatViewDynamic(input);
6390
6455
  }
6391
6456
  };
6392
6457
  }
@@ -7234,30 +7299,17 @@ function createReducerBundle(definition, options = {}) {
7234
7299
  projectStatic() {
7235
7300
  return trustedBundle.projectStatic();
7236
7301
  },
7237
- /**
7238
- * Wire-side passthrough for per-tick seat projection. The seat views carry
7239
- * only the fields produced by `defineView`; static topology, when present,
7240
- * was served once via `projectStatic` and is re-merged on the client.
7241
- */
7242
7302
  projectSeatsDynamic({
7243
7303
  state,
7244
7304
  playerIds,
7245
- viewId = "player"
7305
+ projectionMode
7246
7306
  }) {
7247
7307
  const parsedState = parseTrustedState(state);
7248
7308
  const parsedPlayerIds = playerIds.map((pid) => codec.parsePlayerId(pid));
7249
7309
  return trustedBundle.projectSeatsDynamic({
7250
7310
  state: parsedState,
7251
7311
  playerIds: parsedPlayerIds,
7252
- viewId
7253
- });
7254
- },
7255
- projectSeatViewDynamic({ state, playerId, viewId = "player" }) {
7256
- const parsedState = parseTrustedState(state);
7257
- return trustedBundle.projectSeatViewDynamic({
7258
- state: parsedState,
7259
- playerId: parseRuntimePlayerId(playerId),
7260
- viewId
7312
+ projectionMode: projectionMode ?? void 0
7261
7313
  });
7262
7314
  },
7263
7315
  createInProcessRuntime() {
@@ -7307,21 +7359,14 @@ function createReducerBundle(definition, options = {}) {
7307
7359
  trace: toWireDispatchTrace(result)
7308
7360
  };
7309
7361
  },
7310
- projectSeatViewDynamic({ playerId, viewId = "player" }) {
7311
- return trustedBundle.projectSeatViewDynamic({
7312
- state: requireState(),
7313
- playerId: parseRuntimePlayerId(playerId),
7314
- viewId
7315
- });
7316
- },
7317
- projectSeatsDynamic({ playerIds, viewId = "player" }) {
7362
+ projectSeatsDynamic({ playerIds, projectionMode }) {
7318
7363
  const parsedPlayerIds = playerIds.map(
7319
7364
  (pid) => parseRuntimePlayerId(pid)
7320
7365
  );
7321
7366
  return trustedBundle.projectSeatsDynamic({
7322
7367
  state: requireState(),
7323
7368
  playerIds: parsedPlayerIds,
7324
- viewId
7369
+ projectionMode: projectionMode ?? void 0
7325
7370
  });
7326
7371
  },
7327
7372
  explainInteraction({ playerId, interactionId }) {
@@ -7376,6 +7421,7 @@ export {
7376
7421
  defineCardAction,
7377
7422
  defineDerived,
7378
7423
  defineEffect,
7424
+ defineEmptyView,
7379
7425
  defineGame,
7380
7426
  defineGameContract,
7381
7427
  defineInputs,
@@ -7383,10 +7429,11 @@ export {
7383
7429
  defineInteractionRule,
7384
7430
  definePhase,
7385
7431
  definePhaseStage,
7432
+ definePlayerView,
7433
+ defineSharedView,
7386
7434
  defineStage,
7387
7435
  defineStaticView,
7388
7436
  defineStepPhase,
7389
- defineView,
7390
7437
  formInput,
7391
7438
  gameEvent,
7392
7439
  isPerPlayer,