@crowdedkingdoms/crowdyjs 17.6.0 → 17.7.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 (86) hide show
  1. package/MIGRATION.md +41 -0
  2. package/README.md +33 -0
  3. package/dist/client.d.ts +7 -0
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +2 -1
  6. package/dist/crowdy-client.d.ts +24 -0
  7. package/dist/crowdy-client.d.ts.map +1 -1
  8. package/dist/crowdy-client.js +16 -0
  9. package/dist/crowdy-dsh/bridge.d.ts +24 -1
  10. package/dist/crowdy-dsh/bridge.d.ts.map +1 -1
  11. package/dist/crowdy-dsh/bridge.js +32 -0
  12. package/dist/crowdy-dsh/index.d.ts +1 -1
  13. package/dist/crowdy-dsh/index.d.ts.map +1 -1
  14. package/dist/crowdy-dsh/protocol.d.ts +64 -1
  15. package/dist/crowdy-dsh/protocol.d.ts.map +1 -1
  16. package/dist/crowdy-dsh/protocol.js +8 -1
  17. package/dist/crowdy-studio/starter-projects.js +1 -1
  18. package/dist/default-origin.d.ts +6 -6
  19. package/dist/default-origin.d.ts.map +1 -1
  20. package/dist/default-origin.js +6 -6
  21. package/dist/domains/actors.d.ts +38 -17
  22. package/dist/domains/actors.d.ts.map +1 -1
  23. package/dist/domains/actors.js +38 -17
  24. package/dist/domains/crowdyStudio.js +1 -1
  25. package/dist/domains/grids.d.ts +30 -0
  26. package/dist/domains/grids.d.ts.map +1 -0
  27. package/dist/domains/grids.js +39 -0
  28. package/dist/domains/udp.d.ts +5 -1
  29. package/dist/domains/udp.d.ts.map +1 -1
  30. package/dist/domains/udp.js +5 -1
  31. package/dist/generated/graphql.d.ts +169 -9
  32. package/dist/generated/graphql.d.ts.map +1 -1
  33. package/dist/generated/graphql.js +13 -10
  34. package/dist/grid-mods/grid-host-calls.d.ts +70 -0
  35. package/dist/grid-mods/grid-host-calls.d.ts.map +1 -0
  36. package/dist/grid-mods/grid-host-calls.js +220 -0
  37. package/dist/grid-mods/index.d.ts +3 -0
  38. package/dist/grid-mods/index.d.ts.map +1 -0
  39. package/dist/grid-mods/index.js +2 -0
  40. package/dist/grid-mods/mod-runtime.d.ts +52 -0
  41. package/dist/grid-mods/mod-runtime.d.ts.map +1 -0
  42. package/dist/grid-mods/mod-runtime.js +55 -0
  43. package/dist/grid-program/host.d.ts +88 -0
  44. package/dist/grid-program/host.d.ts.map +1 -0
  45. package/dist/grid-program/host.js +231 -0
  46. package/dist/grid-program/index.d.ts +14 -0
  47. package/dist/grid-program/index.d.ts.map +1 -0
  48. package/dist/grid-program/index.js +13 -0
  49. package/dist/grid-program/program.d.ts +19 -0
  50. package/dist/grid-program/program.d.ts.map +1 -0
  51. package/dist/grid-program/program.js +154 -0
  52. package/dist/grid-program/protocol.d.ts +87 -0
  53. package/dist/grid-program/protocol.d.ts.map +1 -0
  54. package/dist/grid-program/protocol.js +17 -0
  55. package/dist/grid-scope.d.ts +296 -0
  56. package/dist/grid-scope.d.ts.map +1 -0
  57. package/dist/grid-scope.js +183 -0
  58. package/dist/index.d.ts +7 -2
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +7 -2
  61. package/dist/kit/matches.d.ts +1 -0
  62. package/dist/kit/matches.d.ts.map +1 -1
  63. package/dist/kit/npcs.d.ts.map +1 -1
  64. package/dist/kit/social.d.ts.map +1 -1
  65. package/dist/live-coding/assets/browser-authoring-index.json +1 -1
  66. package/dist/live-coding/assets/manifest.json +1 -1
  67. package/dist/live-coding/browser-authoring-index.generated.d.ts.map +1 -1
  68. package/dist/live-coding/browser-authoring-index.generated.js +118 -6
  69. package/dist/player-runtime/client-grid-event-bus.d.ts +37 -0
  70. package/dist/player-runtime/client-grid-event-bus.d.ts.map +1 -0
  71. package/dist/player-runtime/client-grid-event-bus.js +56 -0
  72. package/dist/player-runtime/glue-runtime.d.ts +4 -2
  73. package/dist/player-runtime/glue-runtime.d.ts.map +1 -1
  74. package/dist/player-runtime/glue-runtime.js +20 -23
  75. package/dist/player-runtime/host-catalog.generated.d.ts +16 -0
  76. package/dist/player-runtime/host-catalog.generated.d.ts.map +1 -0
  77. package/dist/player-runtime/host-catalog.generated.js +296 -0
  78. package/dist/player-runtime/player-code-broker.d.ts +38 -0
  79. package/dist/player-runtime/player-code-broker.d.ts.map +1 -1
  80. package/dist/player-runtime/player-code-broker.js +116 -35
  81. package/dist/player-runtime/player-glue-worker.d.ts.map +1 -1
  82. package/dist/player-runtime/player-glue-worker.js +5 -0
  83. package/dist/realtime.d.ts +7 -0
  84. package/dist/realtime.d.ts.map +1 -1
  85. package/dist/realtime.js +3 -1
  86. package/package.json +10 -3
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `@crowdedkingdoms/crowdyjs/grid-program` — player-authored JS that uses the
3
+ * full CrowdyJS SDK inside one grid (DN-10 §5).
4
+ *
5
+ * The program runs in a sandboxed, network-less iframe or worker and builds
6
+ * its client with {@link createGridProgramClient}. The page runs
7
+ * {@link hostGridProgram}, which relays that client's traffic with a
8
+ * grid-scoped token, so the server confines the program to the grid no
9
+ * matter what its code does.
10
+ */
11
+ export * from './protocol.js';
12
+ export { createGridProgramClient, type GridProgramClient, } from './program.js';
13
+ export { GridProgramHost, hostGridProgram, type GridProgramHostOptions, type HeldGridToken, } from './host.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/grid-program/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,uBAAuB,EACvB,KAAK,iBAAiB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,eAAe,EACf,KAAK,sBAAsB,EAC3B,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `@crowdedkingdoms/crowdyjs/grid-program` — player-authored JS that uses the
3
+ * full CrowdyJS SDK inside one grid (DN-10 §5).
4
+ *
5
+ * The program runs in a sandboxed, network-less iframe or worker and builds
6
+ * its client with {@link createGridProgramClient}. The page runs
7
+ * {@link hostGridProgram}, which relays that client's traffic with a
8
+ * grid-scoped token, so the server confines the program to the grid no
9
+ * matter what its code does.
10
+ */
11
+ export * from './protocol.js';
12
+ export { createGridProgramClient, } from './program.js';
13
+ export { GridProgramHost, hostGridProgram, } from './host.js';
@@ -0,0 +1,19 @@
1
+ import { type CrowdyClient } from '../crowdy-client.js';
2
+ import { type GridProgramPort } from './protocol.js';
3
+ import type { GridScope, GridBox } from '../grid-scope.js';
4
+ export interface GridProgramClient {
5
+ /** Real CrowdyJS; every request leaves through the host. */
6
+ client: CrowdyClient;
7
+ /** The grid, bound: `client.grid(appId, gridId, box)`. */
8
+ grid: GridScope;
9
+ appId: string;
10
+ gridId: string;
11
+ box: GridBox;
12
+ }
13
+ /**
14
+ * Build CrowdyJS inside a grid program. Waits for the host's `hello` (which
15
+ * names the app, the grid and its box), then returns a client whose HTTP and
16
+ * realtime ride the port. Call it once per program.
17
+ */
18
+ export declare function createGridProgramClient(port: GridProgramPort): Promise<GridProgramClient>;
19
+ //# sourceMappingURL=program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/grid-program/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAIL,KAAK,eAAe,EAGrB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAiI3D,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,MAAM,EAAE,YAAY,CAAC;IACrB,0DAA0D;IAC1D,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,OAAO,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAgC5B"}
@@ -0,0 +1,154 @@
1
+ import { createCrowdyClient } from '../crowdy-client.js';
2
+ import { GRID_PROGRAM_ORIGIN, GRID_PROGRAM_PLACEHOLDER_TOKEN, GRID_PROGRAM_WS_PROTOCOL, } from './protocol.js';
3
+ /**
4
+ * The program side of a grid program: real CrowdyJS whose network is a
5
+ * MessagePort. Everything it sends is relayed by `GridProgramHost` with a grid
6
+ * token; nothing here holds a credential.
7
+ */
8
+ class PortDemux {
9
+ constructor(port) {
10
+ this.port = port;
11
+ this.nextId = 1;
12
+ this.http = new Map();
13
+ this.sockets = new Map();
14
+ this.hello = new Promise((resolve) => (this.helloResolve = resolve));
15
+ port.addEventListener('message', (event) => this.onMessage(event.data));
16
+ port.start?.();
17
+ }
18
+ id() {
19
+ return this.nextId++;
20
+ }
21
+ send(message) {
22
+ this.port.postMessage(message);
23
+ }
24
+ fetchVia(body) {
25
+ const id = this.id();
26
+ return new Promise((resolve, reject) => {
27
+ this.http.set(id, { resolve, reject });
28
+ this.send({ t: 'http', id, body });
29
+ });
30
+ }
31
+ onMessage(raw) {
32
+ if (!raw || typeof raw !== 'object')
33
+ return;
34
+ const msg = raw;
35
+ switch (msg.t) {
36
+ case 'hello':
37
+ this.helloResolve(msg);
38
+ return;
39
+ case 'http-result': {
40
+ const pending = this.http.get(msg.id);
41
+ if (!pending)
42
+ return;
43
+ this.http.delete(msg.id);
44
+ pending.resolve(new Response(msg.body, {
45
+ status: msg.status,
46
+ headers: { 'content-type': 'application/json' },
47
+ }));
48
+ return;
49
+ }
50
+ case 'http-error': {
51
+ const pending = this.http.get(msg.id);
52
+ if (!pending)
53
+ return;
54
+ this.http.delete(msg.id);
55
+ pending.reject(new TypeError(msg.message));
56
+ return;
57
+ }
58
+ case 'ws-opened':
59
+ case 'ws-message':
60
+ case 'ws-closed':
61
+ case 'ws-error':
62
+ this.sockets.get(msg.sid)?.receive(msg);
63
+ return;
64
+ }
65
+ }
66
+ }
67
+ class PortWebSocketBase {
68
+ constructor() {
69
+ this.readyState = 0;
70
+ this.protocol = '';
71
+ this.onopen = null;
72
+ this.onclose = null;
73
+ this.onerror = null;
74
+ this.onmessage = null;
75
+ this.sid = 0;
76
+ }
77
+ open(protocols) {
78
+ const list = protocols === undefined ? [] : Array.isArray(protocols) ? protocols : [protocols];
79
+ this.sid = this.demux.id();
80
+ this.demux.sockets.set(this.sid, this);
81
+ this.demux.send({ t: 'ws-open', sid: this.sid, protocols: list });
82
+ }
83
+ send(data) {
84
+ if (this.readyState !== 1)
85
+ throw new Error('WebSocket is not open');
86
+ this.demux.send({ t: 'ws-send', sid: this.sid, data: String(data) });
87
+ }
88
+ close(code, reason) {
89
+ if (this.readyState >= 2)
90
+ return;
91
+ this.readyState = 2;
92
+ this.demux.send({ t: 'ws-close', sid: this.sid, code, reason });
93
+ }
94
+ receive(msg) {
95
+ switch (msg.t) {
96
+ case 'ws-opened':
97
+ this.readyState = 1;
98
+ this.protocol = msg.protocol;
99
+ this.onopen?.({});
100
+ return;
101
+ case 'ws-message':
102
+ this.onmessage?.({ data: msg.data });
103
+ return;
104
+ case 'ws-error':
105
+ this.onerror?.(new Error(msg.message));
106
+ return;
107
+ case 'ws-closed':
108
+ this.readyState = 3;
109
+ this.demux.sockets.delete(this.sid);
110
+ this.onclose?.({ code: msg.code, reason: msg.reason, wasClean: msg.code === 1000 });
111
+ return;
112
+ }
113
+ }
114
+ }
115
+ PortWebSocketBase.CONNECTING = 0;
116
+ PortWebSocketBase.OPEN = 1;
117
+ PortWebSocketBase.CLOSING = 2;
118
+ PortWebSocketBase.CLOSED = 3;
119
+ /**
120
+ * Build CrowdyJS inside a grid program. Waits for the host's `hello` (which
121
+ * names the app, the grid and its box), then returns a client whose HTTP and
122
+ * realtime ride the port. Call it once per program.
123
+ */
124
+ export async function createGridProgramClient(port) {
125
+ const demux = new PortDemux(port);
126
+ const hello = await demux.hello;
127
+ class PortWebSocket extends PortWebSocketBase {
128
+ constructor(_url, protocols) {
129
+ super();
130
+ this.demux = demux;
131
+ this.open(protocols ?? GRID_PROGRAM_WS_PROTOCOL);
132
+ }
133
+ }
134
+ const portFetch = ((_input, init) => demux.fetchVia(String(init?.body ?? '')));
135
+ const client = createCrowdyClient({
136
+ httpUrl: GRID_PROGRAM_ORIGIN,
137
+ wsUrl: GRID_PROGRAM_ORIGIN.replace(/^https/, 'wss'),
138
+ fetch: portFetch,
139
+ embeddedHost: false,
140
+ realtime: { webSocketImpl: PortWebSocket, binaryTransport: false },
141
+ });
142
+ client.session.setToken(GRID_PROGRAM_PLACEHOLDER_TOKEN, { persist: false });
143
+ const box = {
144
+ low: { x: BigInt(hello.low.x), y: BigInt(hello.low.y), z: BigInt(hello.low.z) },
145
+ high: { x: BigInt(hello.high.x), y: BigInt(hello.high.y), z: BigInt(hello.high.z) },
146
+ };
147
+ return {
148
+ client,
149
+ grid: client.grid(hello.appId, hello.gridId, box),
150
+ appId: hello.appId,
151
+ gridId: hello.gridId,
152
+ box,
153
+ };
154
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The MessagePort protocol between a GRID PROGRAM (player-authored JS running
3
+ * in a sandboxed, network-less iframe or worker) and the page that hosts it.
4
+ *
5
+ * The program runs real CrowdyJS. Its `fetch` and `WebSocket` are shims that
6
+ * turn every request into a message on this port; the host relays them to
7
+ * ck-api with a GRID-SCOPED token the program never sees. The program's reach
8
+ * is therefore exactly the grid token's reach (DN-10 §5), however hostile its
9
+ * code is.
10
+ */
11
+ export declare const GRID_PROGRAM_PROTOCOL_VERSION: 1;
12
+ /** Program -> host. */
13
+ export type GridProgramRequest = {
14
+ t: 'http';
15
+ id: number;
16
+ body: string;
17
+ } | {
18
+ t: 'ws-open';
19
+ sid: number;
20
+ protocols: string[];
21
+ } | {
22
+ t: 'ws-send';
23
+ sid: number;
24
+ data: string;
25
+ } | {
26
+ t: 'ws-close';
27
+ sid: number;
28
+ code?: number;
29
+ reason?: string;
30
+ };
31
+ /** Host -> program. */
32
+ export type GridProgramReply = {
33
+ t: 'hello';
34
+ v: typeof GRID_PROGRAM_PROTOCOL_VERSION;
35
+ appId: string;
36
+ gridId: string;
37
+ low: {
38
+ x: string;
39
+ y: string;
40
+ z: string;
41
+ };
42
+ high: {
43
+ x: string;
44
+ y: string;
45
+ z: string;
46
+ };
47
+ } | {
48
+ t: 'http-result';
49
+ id: number;
50
+ status: number;
51
+ body: string;
52
+ } | {
53
+ t: 'http-error';
54
+ id: number;
55
+ message: string;
56
+ } | {
57
+ t: 'ws-opened';
58
+ sid: number;
59
+ protocol: string;
60
+ } | {
61
+ t: 'ws-message';
62
+ sid: number;
63
+ data: string;
64
+ } | {
65
+ t: 'ws-closed';
66
+ sid: number;
67
+ code: number;
68
+ reason: string;
69
+ } | {
70
+ t: 'ws-error';
71
+ sid: number;
72
+ message: string;
73
+ };
74
+ /** The subset of MessagePort both sides use (a Worker or MessagePort fits). */
75
+ export interface GridProgramPort {
76
+ postMessage(message: unknown): void;
77
+ addEventListener(type: 'message', listener: (event: MessageEvent<unknown>) => void): void;
78
+ removeEventListener(type: 'message', listener: (event: MessageEvent<unknown>) => void): void;
79
+ start?(): void;
80
+ }
81
+ /** The only WebSocket subprotocol a grid program may speak. */
82
+ export declare const GRID_PROGRAM_WS_PROTOCOL = "graphql-transport-ws";
83
+ /** Placeholder origin the program's client is pointed at; never dialed. */
84
+ export declare const GRID_PROGRAM_ORIGIN = "https://grid-program.invalid";
85
+ /** Placeholder bearer the program's client sends; the host replaces it. */
86
+ export declare const GRID_PROGRAM_PLACEHOLDER_TOKEN = "grid-program";
87
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/grid-program/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,6BAA6B,EAAG,CAAU,CAAC;A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QAAQ,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,CAAC,EAAE,YAAY,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,CAAC,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7D;IAAE,CAAC,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,+EAA+E;AAC/E,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,gBAAgB,CACd,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,IAAI,GAC/C,IAAI,CAAC;IACR,mBAAmB,CACjB,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,IAAI,GAC/C,IAAI,CAAC;IACR,KAAK,CAAC,IAAI,IAAI,CAAC;CAChB;AAED,+DAA+D;AAC/D,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAE/D,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,iCAAiC,CAAC;AAElE,2EAA2E;AAC3E,eAAO,MAAM,8BAA8B,iBAAiB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The MessagePort protocol between a GRID PROGRAM (player-authored JS running
3
+ * in a sandboxed, network-less iframe or worker) and the page that hosts it.
4
+ *
5
+ * The program runs real CrowdyJS. Its `fetch` and `WebSocket` are shims that
6
+ * turn every request into a message on this port; the host relays them to
7
+ * ck-api with a GRID-SCOPED token the program never sees. The program's reach
8
+ * is therefore exactly the grid token's reach (DN-10 §5), however hostile its
9
+ * code is.
10
+ */
11
+ export const GRID_PROGRAM_PROTOCOL_VERSION = 1;
12
+ /** The only WebSocket subprotocol a grid program may speak. */
13
+ export const GRID_PROGRAM_WS_PROTOCOL = 'graphql-transport-ws';
14
+ /** Placeholder origin the program's client is pointed at; never dialed. */
15
+ export const GRID_PROGRAM_ORIGIN = 'https://grid-program.invalid';
16
+ /** Placeholder bearer the program's client sends; the host replaces it. */
17
+ export const GRID_PROGRAM_PLACEHOLDER_TOKEN = 'grid-program';
@@ -0,0 +1,296 @@
1
+ import type { GridsAPI, GridChannel, GridToken } from './domains/grids.js';
2
+ import type { GameModelAPI } from './domains/gameModel.js';
3
+ import type { PlayerModelAPI } from './domains/playerModel.js';
4
+ import type { PlayerComputeAPI } from './domains/playerCompute.js';
5
+ import type { ChannelsAPI } from './domains/channels.js';
6
+ import type { UdpAPI } from './domains/udp.js';
7
+ import type { MarketplaceAPI } from './domains/marketplace.js';
8
+ import type { GameModelCreateSessionMutationVariables, PlayerComputeDeployMutationVariables, PlayerModelCreateContainerMutationVariables, PlayerModelSetPropertyMutationVariables } from './generated/graphql.js';
9
+ /** A chunk address as CrowdyJS passes it on the wire (decimal strings). */
10
+ export interface GridChunk {
11
+ x: string | number | bigint;
12
+ y: string | number | bigint;
13
+ z: string | number | bigint;
14
+ }
15
+ export interface GridBox {
16
+ low: {
17
+ x: bigint;
18
+ y: bigint;
19
+ z: bigint;
20
+ };
21
+ high: {
22
+ x: bigint;
23
+ y: bigint;
24
+ z: bigint;
25
+ };
26
+ }
27
+ /** The domain clients a GridScope binds (a CrowdyClient satisfies this). */
28
+ export interface GridScopeClients {
29
+ grids: GridsAPI;
30
+ gameModel: GameModelAPI;
31
+ playerModel: PlayerModelAPI;
32
+ playerCompute: PlayerComputeAPI;
33
+ channels: ChannelsAPI;
34
+ udp: UdpAPI;
35
+ marketplace: MarketplaceAPI;
36
+ }
37
+ /** Thrown locally, before any request, when a call would leave the grid. */
38
+ export declare class GridScopeError extends Error {
39
+ constructor(message: string);
40
+ }
41
+ /**
42
+ * One grid, bound once (DN-10: grid scope is app scope intersected with grid
43
+ * confinement). Every method is the ordinary CrowdyJS call with the app and
44
+ * grid filled in, and — where the call addresses the world — a local check
45
+ * that it stays in the grid. The local check is UX; the server enforces the
46
+ * same rule for grid tokens, and grid-owner rules for everyone.
47
+ *
48
+ * Get one from `client.grid(appId, gridId)`. The box is learned from the
49
+ * first grid token minted (or passed in); world helpers need it.
50
+ */
51
+ export declare class GridScope {
52
+ private readonly clients;
53
+ readonly appId: string;
54
+ readonly gridId: string;
55
+ private box;
56
+ constructor(clients: GridScopeClients, appId: string, gridId: string, box?: GridBox);
57
+ /** The grid box, when known (after `mintToken`, or when passed in). */
58
+ get bounds(): GridBox | null;
59
+ /** Whether a chunk is inside the grid. False while the box is unknown. */
60
+ contains(chunk: GridChunk): boolean;
61
+ /** Throws GridScopeError unless the chunk is inside the (known) grid box. */
62
+ assertContains(chunk: GridChunk): void;
63
+ /** Mint a grid-scoped token for this grid; also learns the box. */
64
+ mintToken(ttlSeconds?: number): Promise<GridToken>;
65
+ /** Grid channels: the only channels this grid's modules may post into. */
66
+ readonly channels: {
67
+ list: () => Promise<GridChannel[]>;
68
+ create: (name: string, options?: {
69
+ description?: string;
70
+ membershipPolicy?: string;
71
+ membersCanSend?: boolean;
72
+ }) => Promise<{
73
+ __typename?: "Group";
74
+ groupId: string;
75
+ appId: string;
76
+ groupType: string;
77
+ name: string;
78
+ description: string | null;
79
+ ownerUserId: string | null;
80
+ membershipPolicy: string;
81
+ status: string;
82
+ defaultRoleId: string | null;
83
+ gridId: string | null;
84
+ createdAt: string;
85
+ }>;
86
+ join: (channelId: string) => Promise<{
87
+ __typename?: "GroupMember";
88
+ groupMemberId: string;
89
+ groupId: string;
90
+ userId: string;
91
+ status: string;
92
+ createdAt: string;
93
+ roles: Array<{
94
+ __typename?: "GroupRole";
95
+ groupRoleId: string;
96
+ roleName: string;
97
+ rank: number;
98
+ isSystem: boolean;
99
+ permissions: Array<string>;
100
+ }>;
101
+ }>;
102
+ leave: (channelId: string) => Promise<boolean>;
103
+ send: (channelId: string, uuid: string, payloadBase64: string) => Promise<boolean>;
104
+ };
105
+ /** Sessions hosted inside this grid (games within the game). */
106
+ readonly sessions: {
107
+ list: (options?: {
108
+ status?: string;
109
+ limit?: number;
110
+ }) => Promise<{
111
+ __typename?: "GmSession";
112
+ sessionId: string;
113
+ appId: string;
114
+ name: string | null;
115
+ status: string;
116
+ createdByUserId: string | null;
117
+ currentTurnUserId: string | null;
118
+ metadataJson: string;
119
+ admission: string;
120
+ maxParticipants: number | null;
121
+ participantCount: number;
122
+ hostUserId: string | null;
123
+ hostTerm: number;
124
+ revision: string;
125
+ endedAt: string | null;
126
+ endReason: string | null;
127
+ createdAt: string;
128
+ presence: string;
129
+ gridId: string | null;
130
+ seededContainerCount: number | null;
131
+ }[]>;
132
+ create: (input?: Omit<GameModelCreateSessionMutationVariables["input"], "appId" | "gridId">) => Promise<{
133
+ __typename?: "GmSession";
134
+ sessionId: string;
135
+ appId: string;
136
+ name: string | null;
137
+ status: string;
138
+ createdByUserId: string | null;
139
+ currentTurnUserId: string | null;
140
+ metadataJson: string;
141
+ admission: string;
142
+ maxParticipants: number | null;
143
+ participantCount: number;
144
+ hostUserId: string | null;
145
+ hostTerm: number;
146
+ revision: string;
147
+ endedAt: string | null;
148
+ endReason: string | null;
149
+ createdAt: string;
150
+ presence: string;
151
+ gridId: string | null;
152
+ seededContainerCount: number | null;
153
+ }>;
154
+ join: (sessionId: string, options?: {
155
+ role?: string;
156
+ actorUuid?: string;
157
+ }) => Promise<{
158
+ __typename?: "GmSessionParticipant";
159
+ sessionId: string;
160
+ userId: string;
161
+ role: string;
162
+ state: string;
163
+ incarnation: number;
164
+ actorUuid: string | null;
165
+ joinedAt: string;
166
+ leftAt: string | null;
167
+ leftReason: string | null;
168
+ }>;
169
+ leave: (sessionId: string, incarnation: number) => Promise<{
170
+ __typename?: "GmSessionParticipant";
171
+ sessionId: string;
172
+ userId: string;
173
+ role: string;
174
+ state: string;
175
+ incarnation: number;
176
+ actorUuid: string | null;
177
+ joinedAt: string;
178
+ leftAt: string | null;
179
+ leftReason: string | null;
180
+ }>;
181
+ };
182
+ /** The player-tier Game Model of this grid. */
183
+ readonly model: {
184
+ containers: () => Promise<{
185
+ __typename?: "PlayerModelContainer";
186
+ containerId: string;
187
+ appId: string;
188
+ gridId: string;
189
+ ownerUserId: string;
190
+ typeKey: string;
191
+ displayName: string | null;
192
+ stateJson: string;
193
+ propertiesJson: string;
194
+ createdAt: string;
195
+ updatedAt: string;
196
+ }[]>;
197
+ container: (containerId: string) => Promise<{
198
+ __typename?: "PlayerModelContainer";
199
+ containerId: string;
200
+ appId: string;
201
+ gridId: string;
202
+ ownerUserId: string;
203
+ typeKey: string;
204
+ displayName: string | null;
205
+ stateJson: string;
206
+ propertiesJson: string;
207
+ createdAt: string;
208
+ updatedAt: string;
209
+ } | null>;
210
+ create: (input: Omit<PlayerModelCreateContainerMutationVariables["input"], "appId" | "gridId">) => Promise<{
211
+ __typename?: "PlayerModelContainer";
212
+ containerId: string;
213
+ appId: string;
214
+ gridId: string;
215
+ ownerUserId: string;
216
+ typeKey: string;
217
+ displayName: string | null;
218
+ stateJson: string;
219
+ propertiesJson: string;
220
+ createdAt: string;
221
+ updatedAt: string;
222
+ }>;
223
+ set: (input: Omit<PlayerModelSetPropertyMutationVariables["input"], "appId" | "gridId">) => Promise<{
224
+ __typename?: "PlayerModelContainer";
225
+ containerId: string;
226
+ appId: string;
227
+ gridId: string;
228
+ ownerUserId: string;
229
+ typeKey: string;
230
+ displayName: string | null;
231
+ stateJson: string;
232
+ propertiesJson: string;
233
+ createdAt: string;
234
+ updatedAt: string;
235
+ }>;
236
+ delete: (containerId: string) => Promise<boolean>;
237
+ };
238
+ /** Player compute on this grid (SERVER/CLIENT modules). */
239
+ readonly compute: {
240
+ deploy: (input: Omit<PlayerComputeDeployMutationVariables["input"], "appId" | "gridId">) => Promise<{
241
+ __typename?: "PlayerWasmModuleVersion";
242
+ versionId: string;
243
+ moduleId: string;
244
+ versionNo: number;
245
+ target: import("./index.js").PlayerComputeTarget;
246
+ sourceFilesJson: string | null;
247
+ openSource: boolean;
248
+ compileStatus: string;
249
+ compileLog: string | null;
250
+ compiledSizeBytes: string | null;
251
+ projectId: string | null;
252
+ sourceRevision: string | null;
253
+ githubCommitSha: string | null;
254
+ createdAt: string;
255
+ }>;
256
+ invoke: (moduleName: string, exportName: string, params?: unknown) => Promise<{
257
+ __typename?: "PlayerComputeInvokeResult";
258
+ resultBase64: string;
259
+ resultJson: string | null;
260
+ fuelUsed: string;
261
+ durationUs: number;
262
+ }>;
263
+ clientMods: () => Promise<{
264
+ __typename?: "GridClientMod";
265
+ attachmentId: string;
266
+ listingId: string | null;
267
+ listingName: string;
268
+ versionId: string | null;
269
+ sourceKind: string;
270
+ authorKind: import("./generated/graphql.js").PlayerCodeOwnerKind;
271
+ authorRef: string;
272
+ serverVersionId: string | null;
273
+ clientVersionId: string | null;
274
+ clientArtifactHash: string;
275
+ gridId: string;
276
+ capabilitySummaryJson: string;
277
+ capabilityHash: string;
278
+ authorCapabilitySummaryJson: string;
279
+ authorCapabilityHash: string;
280
+ callerConsented: boolean;
281
+ callerTrustsAuthor: boolean;
282
+ }[]>;
283
+ };
284
+ /**
285
+ * Replication that ORIGINATES in the grid. Each send checks its chunk
286
+ * locally, then goes out as the ordinary udp call; reach still follows
287
+ * `distance`.
288
+ */
289
+ readonly send: {
290
+ actorUpdate: (input: Omit<Parameters<UdpAPI["sendActorUpdate"]>[0], "appId">) => Promise<boolean>;
291
+ voxelUpdate: (input: Omit<Parameters<UdpAPI["sendVoxelUpdate"]>[0], "appId">) => Promise<boolean>;
292
+ text: (input: Omit<Parameters<UdpAPI["sendTextPacket"]>[0], "appId">) => Promise<boolean>;
293
+ clientEvent: (input: Omit<Parameters<UdpAPI["sendClientEvent"]>[0], "appId">) => Promise<boolean>;
294
+ };
295
+ }
296
+ //# sourceMappingURL=grid-scope.d.ts.map
@@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