@crowdedkingdoms/crowdyjs 17.14.0-dev.1 → 18.0.0-dev.1

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 (271) hide show
  1. package/MIGRATION.md +92 -1
  2. package/README.md +93 -162
  3. package/dist/crowdy-client.d.ts +12 -31
  4. package/dist/crowdy-client.d.ts.map +1 -1
  5. package/dist/crowdy-client.js +15 -37
  6. package/dist/crowdy-dsh/bridge.d.ts.map +1 -1
  7. package/dist/crowdy-dsh/bridge.js +3 -6
  8. package/dist/crowdy-studio/controller.d.ts +34 -59
  9. package/dist/crowdy-studio/controller.d.ts.map +1 -1
  10. package/dist/crowdy-studio/controller.js +96 -225
  11. package/dist/crowdy-studio/diagnostics.d.ts +3 -12
  12. package/dist/crowdy-studio/diagnostics.d.ts.map +1 -1
  13. package/dist/crowdy-studio/dom-shell.d.ts +2 -4
  14. package/dist/crowdy-studio/dom-shell.d.ts.map +1 -1
  15. package/dist/crowdy-studio/dom-shell.js +16 -49
  16. package/dist/crowdy-studio/embed/hud-layer.d.ts +1 -2
  17. package/dist/crowdy-studio/embed/hud-layer.d.ts.map +1 -1
  18. package/dist/crowdy-studio/embed/panel.d.ts +3 -13
  19. package/dist/crowdy-studio/embed/panel.d.ts.map +1 -1
  20. package/dist/crowdy-studio/embed/panel.js +3 -6
  21. package/dist/crowdy-studio/index.d.ts +1 -3
  22. package/dist/crowdy-studio/index.d.ts.map +1 -1
  23. package/dist/crowdy-studio/index.js +0 -2
  24. package/dist/crowdy-studio/models.d.ts +3 -4
  25. package/dist/crowdy-studio/models.d.ts.map +1 -1
  26. package/dist/crowdy-studio/starter-projects.d.ts +8 -12
  27. package/dist/crowdy-studio/starter-projects.d.ts.map +1 -1
  28. package/dist/crowdy-studio/starter-projects.js +12 -103
  29. package/dist/domains/appAccess.d.ts +14 -1
  30. package/dist/domains/appAccess.d.ts.map +1 -1
  31. package/dist/domains/appAccess.js +37 -1
  32. package/dist/domains/host.d.ts +3 -3
  33. package/dist/domains/host.js +3 -3
  34. package/dist/domains/marketplace.d.ts +9 -70
  35. package/dist/domains/marketplace.d.ts.map +1 -1
  36. package/dist/domains/marketplace.js +9 -120
  37. package/dist/domains/playerWallet.d.ts +6 -12
  38. package/dist/domains/playerWallet.d.ts.map +1 -1
  39. package/dist/domains/playerWallet.js +6 -21
  40. package/dist/errors.d.ts +7 -13
  41. package/dist/errors.d.ts.map +1 -1
  42. package/dist/errors.js +6 -10
  43. package/dist/generated/graphql.d.ts +141 -7083
  44. package/dist/generated/graphql.d.ts.map +1 -1
  45. package/dist/generated/graphql.js +5 -313
  46. package/dist/grid-mods/exec-client-halves.d.ts +19 -3
  47. package/dist/grid-mods/exec-client-halves.d.ts.map +1 -1
  48. package/dist/grid-mods/exec-client-halves.js +17 -2
  49. package/dist/grid-mods/grid-host-calls.d.ts +29 -17
  50. package/dist/grid-mods/grid-host-calls.d.ts.map +1 -1
  51. package/dist/grid-mods/grid-host-calls.js +40 -46
  52. package/dist/grid-mods/mod-runtime.d.ts +18 -11
  53. package/dist/grid-mods/mod-runtime.d.ts.map +1 -1
  54. package/dist/grid-mods/mod-runtime.js +4 -2
  55. package/dist/grid-scope.d.ts +0 -189
  56. package/dist/grid-scope.d.ts.map +1 -1
  57. package/dist/grid-scope.js +0 -70
  58. package/dist/index.d.ts +11 -17
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +10 -16
  61. package/dist/kit/actions.d.ts +5 -9
  62. package/dist/kit/actions.d.ts.map +1 -1
  63. package/dist/kit/actions.js +5 -9
  64. package/dist/kit/index.d.ts +2 -33
  65. package/dist/kit/index.d.ts.map +1 -1
  66. package/dist/kit/index.js +1 -32
  67. package/dist/kit/kit.d.ts +8 -208
  68. package/dist/kit/kit.d.ts.map +1 -1
  69. package/dist/kit/kit.js +5 -163
  70. package/dist/kit/social.d.ts +1 -3
  71. package/dist/kit/social.d.ts.map +1 -1
  72. package/dist/kit/social.js +1 -3
  73. package/dist/kit/wire.d.ts +16 -5
  74. package/dist/kit/wire.d.ts.map +1 -1
  75. package/dist/kit/wire.js +19 -5
  76. package/dist/live-coding/assets/browser-authoring-index.json +1 -1
  77. package/dist/live-coding/assets/manifest.json +1 -1
  78. package/dist/live-coding/browser-authoring-index.generated.d.ts.map +1 -1
  79. package/dist/live-coding/browser-authoring-index.generated.js +1496 -4386
  80. package/dist/live-coding/rust-analysis.d.ts.map +1 -1
  81. package/dist/live-coding/rust-analysis.js +30 -34
  82. package/dist/player-runtime/client-host-calls.d.ts +8 -0
  83. package/dist/player-runtime/client-host-calls.d.ts.map +1 -0
  84. package/dist/player-runtime/client-host-calls.js +28 -0
  85. package/dist/player-runtime/glue-runtime.d.ts +24 -20
  86. package/dist/player-runtime/glue-runtime.d.ts.map +1 -1
  87. package/dist/player-runtime/glue-runtime.js +26 -55
  88. package/dist/player-runtime/glue-sab.d.ts +2 -2
  89. package/dist/player-runtime/glue-sab.js +2 -2
  90. package/dist/player-runtime/player-code-broker.d.ts +70 -43
  91. package/dist/player-runtime/player-code-broker.d.ts.map +1 -1
  92. package/dist/player-runtime/player-code-broker.js +159 -64
  93. package/dist/player-runtime/player-glue-worker.d.ts +8 -9
  94. package/dist/player-runtime/player-glue-worker.d.ts.map +1 -1
  95. package/dist/player-runtime/player-glue-worker.js +26 -11
  96. package/dist/stores/inbox.d.ts +1 -1
  97. package/dist/stores/inbox.d.ts.map +1 -1
  98. package/dist/stores/index.d.ts +0 -11
  99. package/dist/stores/index.d.ts.map +1 -1
  100. package/dist/stores/index.js +0 -4
  101. package/dist/stores/session.d.ts +0 -2
  102. package/dist/stores/session.d.ts.map +1 -1
  103. package/package.json +1 -1
  104. package/dist/crowdy-studio/model-lint-log.d.ts +0 -76
  105. package/dist/crowdy-studio/model-lint-log.d.ts.map +0 -1
  106. package/dist/crowdy-studio/model-lint-log.js +0 -93
  107. package/dist/crowdy-studio/model-lint.d.ts +0 -61
  108. package/dist/crowdy-studio/model-lint.d.ts.map +0 -1
  109. package/dist/crowdy-studio/model-lint.js +0 -45
  110. package/dist/domains/compute.d.ts +0 -208
  111. package/dist/domains/compute.d.ts.map +0 -1
  112. package/dist/domains/compute.js +0 -274
  113. package/dist/domains/controlPlane.d.ts +0 -38
  114. package/dist/domains/controlPlane.d.ts.map +0 -1
  115. package/dist/domains/controlPlane.js +0 -43
  116. package/dist/domains/gameModel.d.ts +0 -1174
  117. package/dist/domains/gameModel.d.ts.map +0 -1
  118. package/dist/domains/gameModel.js +0 -1333
  119. package/dist/domains/playerCompute.d.ts +0 -91
  120. package/dist/domains/playerCompute.d.ts.map +0 -1
  121. package/dist/domains/playerCompute.js +0 -136
  122. package/dist/domains/playerModel.d.ts +0 -20
  123. package/dist/domains/playerModel.d.ts.map +0 -1
  124. package/dist/domains/playerModel.js +0 -54
  125. package/dist/kit/abilities.d.ts +0 -66
  126. package/dist/kit/abilities.d.ts.map +0 -1
  127. package/dist/kit/abilities.js +0 -71
  128. package/dist/kit/blueprints/combat.d.ts +0 -81
  129. package/dist/kit/blueprints/combat.d.ts.map +0 -1
  130. package/dist/kit/blueprints/combat.js +0 -357
  131. package/dist/kit/blueprints/core.d.ts +0 -222
  132. package/dist/kit/blueprints/core.d.ts.map +0 -1
  133. package/dist/kit/blueprints/core.js +0 -185
  134. package/dist/kit/blueprints/decks.d.ts +0 -50
  135. package/dist/kit/blueprints/decks.d.ts.map +0 -1
  136. package/dist/kit/blueprints/decks.js +0 -163
  137. package/dist/kit/blueprints/economy.d.ts +0 -88
  138. package/dist/kit/blueprints/economy.d.ts.map +0 -1
  139. package/dist/kit/blueprints/economy.js +0 -533
  140. package/dist/kit/blueprints/guild.d.ts +0 -51
  141. package/dist/kit/blueprints/guild.d.ts.map +0 -1
  142. package/dist/kit/blueprints/guild.js +0 -50
  143. package/dist/kit/blueprints/index.d.ts +0 -23
  144. package/dist/kit/blueprints/index.d.ts.map +0 -1
  145. package/dist/kit/blueprints/index.js +0 -22
  146. package/dist/kit/blueprints/inventory.d.ts +0 -84
  147. package/dist/kit/blueprints/inventory.d.ts.map +0 -1
  148. package/dist/kit/blueprints/inventory.js +0 -257
  149. package/dist/kit/blueprints/leaderboards.d.ts +0 -49
  150. package/dist/kit/blueprints/leaderboards.d.ts.map +0 -1
  151. package/dist/kit/blueprints/leaderboards.js +0 -126
  152. package/dist/kit/blueprints/liveops.d.ts +0 -42
  153. package/dist/kit/blueprints/liveops.d.ts.map +0 -1
  154. package/dist/kit/blueprints/liveops.js +0 -170
  155. package/dist/kit/blueprints/locks.d.ts +0 -82
  156. package/dist/kit/blueprints/locks.d.ts.map +0 -1
  157. package/dist/kit/blueprints/locks.js +0 -155
  158. package/dist/kit/blueprints/loot.d.ts +0 -90
  159. package/dist/kit/blueprints/loot.d.ts.map +0 -1
  160. package/dist/kit/blueprints/loot.js +0 -229
  161. package/dist/kit/blueprints/matches.d.ts +0 -84
  162. package/dist/kit/blueprints/matches.d.ts.map +0 -1
  163. package/dist/kit/blueprints/matches.js +0 -349
  164. package/dist/kit/blueprints/moderation.d.ts +0 -32
  165. package/dist/kit/blueprints/moderation.d.ts.map +0 -1
  166. package/dist/kit/blueprints/moderation.js +0 -140
  167. package/dist/kit/blueprints/npcs.d.ts +0 -78
  168. package/dist/kit/blueprints/npcs.d.ts.map +0 -1
  169. package/dist/kit/blueprints/npcs.js +0 -125
  170. package/dist/kit/blueprints/plots.d.ts +0 -63
  171. package/dist/kit/blueprints/plots.d.ts.map +0 -1
  172. package/dist/kit/blueprints/plots.js +0 -151
  173. package/dist/kit/blueprints/progression.d.ts +0 -68
  174. package/dist/kit/blueprints/progression.d.ts.map +0 -1
  175. package/dist/kit/blueprints/progression.js +0 -324
  176. package/dist/kit/blueprints/quests.d.ts +0 -72
  177. package/dist/kit/blueprints/quests.d.ts.map +0 -1
  178. package/dist/kit/blueprints/quests.js +0 -285
  179. package/dist/kit/blueprints/worldsim.d.ts +0 -91
  180. package/dist/kit/blueprints/worldsim.d.ts.map +0 -1
  181. package/dist/kit/blueprints/worldsim.js +0 -468
  182. package/dist/kit/combat.d.ts +0 -141
  183. package/dist/kit/combat.d.ts.map +0 -1
  184. package/dist/kit/combat.js +0 -196
  185. package/dist/kit/decks.d.ts +0 -157
  186. package/dist/kit/decks.d.ts.map +0 -1
  187. package/dist/kit/decks.js +0 -186
  188. package/dist/kit/director.d.ts +0 -88
  189. package/dist/kit/director.d.ts.map +0 -1
  190. package/dist/kit/director.js +0 -86
  191. package/dist/kit/economy.d.ts +0 -289
  192. package/dist/kit/economy.d.ts.map +0 -1
  193. package/dist/kit/economy.js +0 -427
  194. package/dist/kit/engine.d.ts +0 -48
  195. package/dist/kit/engine.d.ts.map +0 -1
  196. package/dist/kit/engine.js +0 -113
  197. package/dist/kit/features.d.ts +0 -60
  198. package/dist/kit/features.d.ts.map +0 -1
  199. package/dist/kit/features.js +0 -65
  200. package/dist/kit/instances.d.ts +0 -52
  201. package/dist/kit/instances.d.ts.map +0 -1
  202. package/dist/kit/instances.js +0 -60
  203. package/dist/kit/inventory.d.ts +0 -129
  204. package/dist/kit/inventory.d.ts.map +0 -1
  205. package/dist/kit/inventory.js +0 -200
  206. package/dist/kit/leaderboards.d.ts +0 -86
  207. package/dist/kit/leaderboards.d.ts.map +0 -1
  208. package/dist/kit/leaderboards.js +0 -133
  209. package/dist/kit/liveops.d.ts +0 -112
  210. package/dist/kit/liveops.d.ts.map +0 -1
  211. package/dist/kit/liveops.js +0 -183
  212. package/dist/kit/loot.d.ts +0 -128
  213. package/dist/kit/loot.d.ts.map +0 -1
  214. package/dist/kit/loot.js +0 -160
  215. package/dist/kit/matches.d.ts +0 -301
  216. package/dist/kit/matches.d.ts.map +0 -1
  217. package/dist/kit/matches.js +0 -458
  218. package/dist/kit/matchmaking.d.ts +0 -57
  219. package/dist/kit/matchmaking.d.ts.map +0 -1
  220. package/dist/kit/matchmaking.js +0 -59
  221. package/dist/kit/minigames.d.ts +0 -30
  222. package/dist/kit/minigames.d.ts.map +0 -1
  223. package/dist/kit/minigames.js +0 -38
  224. package/dist/kit/mobs.d.ts +0 -90
  225. package/dist/kit/mobs.d.ts.map +0 -1
  226. package/dist/kit/mobs.js +0 -98
  227. package/dist/kit/moderation.d.ts +0 -73
  228. package/dist/kit/moderation.d.ts.map +0 -1
  229. package/dist/kit/moderation.js +0 -103
  230. package/dist/kit/movement.d.ts +0 -78
  231. package/dist/kit/movement.d.ts.map +0 -1
  232. package/dist/kit/movement.js +0 -103
  233. package/dist/kit/notifications.d.ts +0 -45
  234. package/dist/kit/notifications.d.ts.map +0 -1
  235. package/dist/kit/notifications.js +0 -67
  236. package/dist/kit/npcs.d.ts +0 -226
  237. package/dist/kit/npcs.d.ts.map +0 -1
  238. package/dist/kit/npcs.js +0 -141
  239. package/dist/kit/objects.d.ts +0 -116
  240. package/dist/kit/objects.d.ts.map +0 -1
  241. package/dist/kit/objects.js +0 -119
  242. package/dist/kit/pets.d.ts +0 -85
  243. package/dist/kit/pets.d.ts.map +0 -1
  244. package/dist/kit/pets.js +0 -96
  245. package/dist/kit/plots.d.ts +0 -85
  246. package/dist/kit/plots.d.ts.map +0 -1
  247. package/dist/kit/plots.js +0 -113
  248. package/dist/kit/progression.d.ts +0 -181
  249. package/dist/kit/progression.d.ts.map +0 -1
  250. package/dist/kit/progression.js +0 -265
  251. package/dist/kit/quests.d.ts +0 -171
  252. package/dist/kit/quests.d.ts.map +0 -1
  253. package/dist/kit/quests.js +0 -237
  254. package/dist/kit/racing.d.ts +0 -85
  255. package/dist/kit/racing.d.ts.map +0 -1
  256. package/dist/kit/racing.js +0 -99
  257. package/dist/kit/shared.d.ts +0 -73
  258. package/dist/kit/shared.d.ts.map +0 -1
  259. package/dist/kit/shared.js +0 -101
  260. package/dist/kit/telemetry.d.ts +0 -66
  261. package/dist/kit/telemetry.d.ts.map +0 -1
  262. package/dist/kit/telemetry.js +0 -133
  263. package/dist/kit/territory.d.ts +0 -97
  264. package/dist/kit/territory.d.ts.map +0 -1
  265. package/dist/kit/territory.js +0 -114
  266. package/dist/kit/worldsim.d.ts +0 -263
  267. package/dist/kit/worldsim.d.ts.map +0 -1
  268. package/dist/kit/worldsim.js +0 -268
  269. package/dist/stores/model.d.ts +0 -81
  270. package/dist/stores/model.d.ts.map +0 -1
  271. package/dist/stores/model.js +0 -163
@@ -1,81 +0,0 @@
1
- /**
2
- * ContainerMirror — the client half of the platform's **notify-to-pull**
3
- * pattern for game-model state: keep typed snapshots of the containers you
4
- * care about, re-pull them on demand or whenever a bound channel pings
5
- * ("state changed"), and render straight from the cache.
6
- *
7
- * Model changes are pull-based on this platform (there is no model
8
- * subscription); functions declare channel/spatial notifications and clients
9
- * re-read. The Game Kit's match layer pings a per-match channel — bind the
10
- * mirror to that channel and every watched container refreshes itself.
11
- */
12
- import type { WorldSessionContext } from './session.js';
13
- /** A typed snapshot of one watched container. */
14
- export interface MirroredContainer<T = Record<string, unknown>> {
15
- readonly containerId: string;
16
- typeName: string;
17
- displayName: string;
18
- ownerUserId: string | null;
19
- /** The parsed, caller-visible properties. */
20
- value: T;
21
- /** Bumped on every refresh that changed the snapshot. */
22
- revision: number;
23
- /** Local time of the last refresh. */
24
- refreshedAt: number;
25
- }
26
- /** Options for {@link attachContainerMirror}. */
27
- export interface ContainerMirrorConfig {
28
- /** Clock override for tests. Defaults to `Date.now`. */
29
- now?: () => number;
30
- }
31
- /**
32
- * The SDK-managed **model mirror**: typed, cached snapshots of watched
33
- * game-model containers with coalesced refresh and channel-ping binding.
34
- * Reads are synchronous ({@link get}); {@link onChange} fires only when a
35
- * refresh actually changed the visible state.
36
- */
37
- export declare class ContainerMirror {
38
- private readonly ctx;
39
- private readonly watches;
40
- private readonly listeners;
41
- private readonly boundChannels;
42
- private readonly now;
43
- private refreshing;
44
- private refreshQueued;
45
- constructor(ctx: WorldSessionContext, config?: ContainerMirrorConfig);
46
- /**
47
- * Watch a container: fetches the initial snapshot and keeps it refreshable.
48
- * `parse` maps the visible properties object to your type (defaults to the
49
- * raw object).
50
- */
51
- watch<T = Record<string, unknown>>(containerId: string, parse?: (properties: Record<string, unknown>) => T): Promise<MirroredContainer<T>>;
52
- /** Stop watching a container (its snapshot is dropped). */
53
- unwatch(containerId: string): void;
54
- /** The current snapshot of a watched container (undefined before watch resolves). */
55
- get<T = Record<string, unknown>>(containerId: string): MirroredContainer<T> | undefined;
56
- /** Every watched snapshot. */
57
- list(): Array<MirroredContainer<unknown>>;
58
- /**
59
- * Subscribe to snapshot changes — every watched container, or one
60
- * `containerId`. Fires only when a refresh changed the visible state.
61
- * @returns off.
62
- */
63
- onChange(handler: (container: MirroredContainer<unknown>) => void, containerId?: string): () => void;
64
- /**
65
- * Bind a channel: any message on it triggers a coalesced {@link refreshAll}
66
- * — pair with model functions that declare channel notifications (e.g. the
67
- * Game Kit's `match_changed` pings).
68
- */
69
- bindToChannel(channelId: string): () => void;
70
- /** Re-pull one watched container now. */
71
- refresh(containerId: string): Promise<void>;
72
- /**
73
- * Re-pull every watched container. Concurrent calls coalesce: a refresh
74
- * requested while one is running queues exactly one follow-up pass (pings
75
- * can burst; state converges without stampeding the API).
76
- */
77
- refreshAll(): Promise<void>;
78
- }
79
- /** Attach a {@link ContainerMirror}. Prefer the `model` config key. */
80
- export declare function attachContainerMirror(ctx: WorldSessionContext, config?: ContainerMirrorConfig): ContainerMirror;
81
- //# sourceMappingURL=model.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/stores/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,iDAAiD;AACjD,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,6CAA6C;IAC7C,KAAK,EAAE,CAAC,CAAC;IACT,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,iDAAiD;AACjD,MAAM,WAAW,qBAAqB;IACpC,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AASD;;;;;GAKG;AACH,qBAAa,eAAe;IAYxB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAXtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAGrB;IACL,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IACnD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAS;gBAGX,GAAG,EAAE,mBAAmB,EACzC,MAAM,GAAE,qBAA0B;IAcpC;;;;OAIG;IACG,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,WAAW,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,GACjD,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAWhC,2DAA2D;IAC3D,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAIlC,qFAAqF;IACrF,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,GAAG,SAAS;IAMvF,8BAA8B;IAC9B,IAAI,IAAI,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAQzC;;;;OAIG;IACH,QAAQ,CACN,OAAO,EAAE,CAAC,SAAS,EAAE,iBAAiB,CAAC,OAAO,CAAC,KAAK,IAAI,EACxD,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,IAAI;IAMb;;;;OAIG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,IAAI;IAK5C,yCAAyC;IACnC,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDjD;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAqBlC;AAED,uEAAuE;AACvE,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,mBAAmB,EACxB,MAAM,GAAE,qBAA0B,GACjC,eAAe,CAEjB"}
@@ -1,163 +0,0 @@
1
- /**
2
- * ContainerMirror — the client half of the platform's **notify-to-pull**
3
- * pattern for game-model state: keep typed snapshots of the containers you
4
- * care about, re-pull them on demand or whenever a bound channel pings
5
- * ("state changed"), and render straight from the cache.
6
- *
7
- * Model changes are pull-based on this platform (there is no model
8
- * subscription); functions declare channel/spatial notifications and clients
9
- * re-read. The Game Kit's match layer pings a per-match channel — bind the
10
- * mirror to that channel and every watched container refreshes itself.
11
- */
12
- /**
13
- * The SDK-managed **model mirror**: typed, cached snapshots of watched
14
- * game-model containers with coalesced refresh and channel-ping binding.
15
- * Reads are synchronous ({@link get}); {@link onChange} fires only when a
16
- * refresh actually changed the visible state.
17
- */
18
- export class ContainerMirror {
19
- constructor(ctx, config = {}) {
20
- this.ctx = ctx;
21
- this.watches = new Map();
22
- this.listeners = new Set();
23
- this.boundChannels = new Set();
24
- this.refreshing = false;
25
- this.refreshQueued = false;
26
- this.now = config.now ?? Date.now;
27
- // One listener serves every bound channel: a ping means "model state
28
- // changed somewhere relevant" → coalesced refresh of all watches.
29
- ctx.onDispose(ctx.on('channelMessage', (notification) => {
30
- if (!this.boundChannels.has(String(notification.channelId)))
31
- return;
32
- void this.refreshAll();
33
- }));
34
- }
35
- /**
36
- * Watch a container: fetches the initial snapshot and keeps it refreshable.
37
- * `parse` maps the visible properties object to your type (defaults to the
38
- * raw object).
39
- */
40
- async watch(containerId, parse) {
41
- const entry = {
42
- parse: parse ?? ((props) => props),
43
- snapshot: null,
44
- lastSerialized: null,
45
- };
46
- this.watches.set(containerId, entry);
47
- await this.refresh(containerId);
48
- return entry.snapshot;
49
- }
50
- /** Stop watching a container (its snapshot is dropped). */
51
- unwatch(containerId) {
52
- this.watches.delete(containerId);
53
- }
54
- /** The current snapshot of a watched container (undefined before watch resolves). */
55
- get(containerId) {
56
- return (this.watches.get(containerId)?.snapshot ?? undefined);
57
- }
58
- /** Every watched snapshot. */
59
- list() {
60
- const out = [];
61
- for (const entry of this.watches.values()) {
62
- if (entry.snapshot)
63
- out.push(entry.snapshot);
64
- }
65
- return out;
66
- }
67
- /**
68
- * Subscribe to snapshot changes — every watched container, or one
69
- * `containerId`. Fires only when a refresh changed the visible state.
70
- * @returns off.
71
- */
72
- onChange(handler, containerId) {
73
- const entry = { containerId, handler };
74
- this.listeners.add(entry);
75
- return () => this.listeners.delete(entry);
76
- }
77
- /**
78
- * Bind a channel: any message on it triggers a coalesced {@link refreshAll}
79
- * — pair with model functions that declare channel notifications (e.g. the
80
- * Game Kit's `match_changed` pings).
81
- */
82
- bindToChannel(channelId) {
83
- this.boundChannels.add(String(channelId));
84
- return () => this.boundChannels.delete(String(channelId));
85
- }
86
- /** Re-pull one watched container now. */
87
- async refresh(containerId) {
88
- const entry = this.watches.get(containerId);
89
- if (!entry)
90
- return;
91
- const state = await this.ctx.client.gameModel.containerState({
92
- appId: this.ctx.appId,
93
- containerId,
94
- });
95
- let properties;
96
- try {
97
- properties = JSON.parse(state.propertiesJson);
98
- }
99
- catch {
100
- properties = {};
101
- }
102
- const serialized = `${state.displayName}|${state.propertiesJson}`;
103
- const changed = serialized !== entry.lastSerialized;
104
- entry.lastSerialized = serialized;
105
- if (!entry.snapshot) {
106
- entry.snapshot = {
107
- containerId,
108
- typeName: state.typeName,
109
- displayName: state.displayName,
110
- ownerUserId: state.ownerUserId != null ? String(state.ownerUserId) : null,
111
- value: entry.parse(properties),
112
- revision: 1,
113
- refreshedAt: this.now(),
114
- };
115
- }
116
- else {
117
- entry.snapshot.refreshedAt = this.now();
118
- if (changed) {
119
- entry.snapshot.typeName = state.typeName;
120
- entry.snapshot.displayName = state.displayName;
121
- entry.snapshot.ownerUserId =
122
- state.ownerUserId != null ? String(state.ownerUserId) : null;
123
- entry.snapshot.value = entry.parse(properties);
124
- entry.snapshot.revision += 1;
125
- }
126
- }
127
- if (changed) {
128
- for (const listener of [...this.listeners]) {
129
- if (listener.containerId === undefined ||
130
- listener.containerId === containerId) {
131
- listener.handler(entry.snapshot);
132
- }
133
- }
134
- }
135
- }
136
- /**
137
- * Re-pull every watched container. Concurrent calls coalesce: a refresh
138
- * requested while one is running queues exactly one follow-up pass (pings
139
- * can burst; state converges without stampeding the API).
140
- */
141
- async refreshAll() {
142
- if (this.refreshing) {
143
- this.refreshQueued = true;
144
- return;
145
- }
146
- this.refreshing = true;
147
- try {
148
- do {
149
- this.refreshQueued = false;
150
- await Promise.all([...this.watches.keys()].map((id) => this.refresh(id).catch(() => {
151
- // A failed pull keeps the previous snapshot; the next ping retries.
152
- })));
153
- } while (this.refreshQueued);
154
- }
155
- finally {
156
- this.refreshing = false;
157
- }
158
- }
159
- }
160
- /** Attach a {@link ContainerMirror}. Prefer the `model` config key. */
161
- export function attachContainerMirror(ctx, config = {}) {
162
- return new ContainerMirror(ctx, config);
163
- }