@altertable/data-app 0.59.1 → 0.61.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/CONTRIBUTING.md +9 -0
- package/README.md +6 -0
- package/dist/bootstrap.js +19 -19
- package/dist/chunks/{contract-tqrf3ykr.js → contract-7gpsee0v.js} +15 -15
- package/dist/chunks/contract-7gpsee0v.js.map +11 -0
- package/dist/chunks/{contract-mb5nfzwg.js → contract-d9skd1n7.js} +21 -21
- package/dist/chunks/contract-d9skd1n7.js.map +12 -0
- package/dist/chunks/{contract-jksbmt5q.js → contract-ehk50k7e.js} +3 -3
- package/dist/chunks/{contract-jksbmt5q.js.map → contract-ehk50k7e.js.map} +2 -2
- package/dist/chunks/{contract-tkkc28tg.js → contract-zr4s2g7m.js} +5 -5
- package/dist/chunks/{contract-tkkc28tg.js.map → contract-zr4s2g7m.js.map} +2 -2
- package/dist/client/index.js +3 -3
- package/dist/core/contract.js +1 -1
- package/dist/embed/index.js +3 -3
- package/dist/local.js.map +1 -1
- package/dist/react/embed/index.js +2 -2
- package/dist/react/index.js +3 -3
- package/dist/server.js.map +1 -1
- package/dist/types/core/messages.d.ts +2 -2
- package/docs/client.md +1 -1
- package/docs/contract.md +7 -5
- package/docs/embed.md +9 -1
- package/docs/releasing.md +5 -0
- package/docs/starter-agent-instructions.md +4 -2
- package/package.json +7 -3
- package/dist/chunks/contract-mb5nfzwg.js.map +0 -12
- package/dist/chunks/contract-tqrf3ykr.js.map +0 -11
package/CONTRIBUTING.md
CHANGED
|
@@ -17,6 +17,9 @@ bun run check
|
|
|
17
17
|
`src/server` owns request handling and the local Bun adapter, and `src/react` owns
|
|
18
18
|
React bindings; `src/react/embed` provides hosts without app UI dependencies.
|
|
19
19
|
Components and their styles live together in `src/react/ui`.
|
|
20
|
+
`examples/starter` is the runnable CLI starter port, using public package imports.
|
|
21
|
+
Its workspace dependency points to the built repository package; keep its app-owned
|
|
22
|
+
configuration and agent guidance usable when copied into another project.
|
|
20
23
|
`docs` describes each public entry. `scripts` builds and checks the published
|
|
21
24
|
artifact. Workflow validation lives in `scripts/check-workflows.sh`, and release
|
|
22
25
|
helpers live in `scripts/release`. Generated `dist` files are ignored; edit source
|
|
@@ -45,6 +48,11 @@ consumers.
|
|
|
45
48
|
|
|
46
49
|
## Checks
|
|
47
50
|
|
|
51
|
+
Run `bun run build` before individual typecheck, lint, or browser checks. Browser
|
|
52
|
+
fixtures import the public package exports and need the generated declarations
|
|
53
|
+
in `dist`. `bun run check` builds first, including on a fresh checkout.
|
|
54
|
+
Release Please owns `CHANGELOG.md`; formatting excludes its generated output.
|
|
55
|
+
|
|
48
56
|
| Command | Purpose |
|
|
49
57
|
| ------------------------- | ------------------------------------------------ |
|
|
50
58
|
| `bun run typecheck` | Validate source, tests, and scripts |
|
|
@@ -53,6 +61,7 @@ consumers.
|
|
|
53
61
|
| `bun run test` | Run contract, transport, and component tests |
|
|
54
62
|
| `bun run build` | Emit ESM, declarations, and the React stylesheet |
|
|
55
63
|
| `bun run test:package` | Check the built npm archive as a consumer |
|
|
64
|
+
| `bun run test:starter` | Typecheck, lint, and build the starter |
|
|
56
65
|
| `bun run test:browser` | Test embedding against built exports in Chromium |
|
|
57
66
|
| `bun run check:workflows` | Validate workflows and shell scripts |
|
|
58
67
|
| `bun run check` | Run all required checks |
|
package/README.md
CHANGED
|
@@ -48,6 +48,12 @@ The package ships these docs alongside its built JavaScript and declarations.
|
|
|
48
48
|
For agent-assisted work, direct your agent to
|
|
49
49
|
`node_modules/@altertable/data-app/AGENTS.md`.
|
|
50
50
|
|
|
51
|
+
## Starter example
|
|
52
|
+
|
|
53
|
+
The [runnable starter](https://github.com/altertable-ai/data-app/tree/main/examples/starter) includes app configuration,
|
|
54
|
+
server operations, a React connectivity screen, and agent instructions.
|
|
55
|
+
Use it as the starting point for an app that consumes the public package.
|
|
56
|
+
|
|
51
57
|
## Development
|
|
52
58
|
|
|
53
59
|
```fish
|
package/dist/bootstrap.js
CHANGED
|
@@ -148,20 +148,20 @@
|
|
|
148
148
|
if (event.origin !== parentOrigin || event.source !== frame.parent || !isBridgeMessage(event.data))
|
|
149
149
|
return;
|
|
150
150
|
const message = event.data;
|
|
151
|
-
if (message.type === "connect") {
|
|
151
|
+
if (message.type === "bridge:connect") {
|
|
152
152
|
if (mode === "bundle") {
|
|
153
153
|
if (!validId(message.token))
|
|
154
154
|
return;
|
|
155
155
|
token = message.token;
|
|
156
156
|
}
|
|
157
|
-
send({ type: "ready" });
|
|
157
|
+
send({ type: "bridge:ready" });
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
if (mode === "bundle" && (!token || message.token !== token))
|
|
161
161
|
return;
|
|
162
162
|
if (message.documentId !== documentId)
|
|
163
163
|
return;
|
|
164
|
-
if (message.type === "initialize" && validId(message.sessionId)) {
|
|
164
|
+
if (message.type === "bridge:initialize" && validId(message.sessionId)) {
|
|
165
165
|
if (sessionId && sessionId !== message.sessionId) {
|
|
166
166
|
for (const entry of pending.values())
|
|
167
167
|
entry.reject(new DataAppError("The preview reconnected. Retry the request.", "bridge_reset"));
|
|
@@ -173,16 +173,16 @@
|
|
|
173
173
|
entry.start();
|
|
174
174
|
receiveState(message.state);
|
|
175
175
|
if (mode === "url")
|
|
176
|
-
send({ type: "runtime
|
|
176
|
+
send({ type: "runtime:ready" });
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
179
|
if (!sessionId || message.sessionId !== sessionId)
|
|
180
180
|
return;
|
|
181
|
-
if (message.type === "state") {
|
|
181
|
+
if (message.type === "state:update") {
|
|
182
182
|
receiveState(message.state);
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
|
-
if (message.type === "script
|
|
185
|
+
if (message.type === "script:load" && mode === "bundle" && typeof message.javascript === "string") {
|
|
186
186
|
loadScript?.(message.javascript);
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
@@ -191,9 +191,9 @@
|
|
|
191
191
|
const entry = pending.get(message.id);
|
|
192
192
|
if (!entry)
|
|
193
193
|
return;
|
|
194
|
-
if (message.type === "result" && "response" in message) {
|
|
194
|
+
if (message.type === "bridge:result" && "response" in message) {
|
|
195
195
|
entry.resolve(message.response);
|
|
196
|
-
} else if (message.type === "error" && typeof message.code === "string" && typeof message.message === "string") {
|
|
196
|
+
} else if (message.type === "bridge:error" && typeof message.code === "string" && typeof message.message === "string") {
|
|
197
197
|
entry.reject(new MessageRoutingError(message.code, message.message, typeof message.requestId === "string" ? message.requestId : undefined));
|
|
198
198
|
}
|
|
199
199
|
}
|
|
@@ -215,13 +215,13 @@
|
|
|
215
215
|
}
|
|
216
216
|
function abort() {
|
|
217
217
|
if (sent)
|
|
218
|
-
send({ type: "cancel", id });
|
|
218
|
+
send({ type: "bridge:cancel", id });
|
|
219
219
|
cleanup();
|
|
220
220
|
reject(signal?.reason);
|
|
221
221
|
}
|
|
222
222
|
const timer = setTimeout(() => {
|
|
223
223
|
if (sent)
|
|
224
|
-
send({ type: "cancel", id });
|
|
224
|
+
send({ type: "bridge:cancel", id });
|
|
225
225
|
cleanup();
|
|
226
226
|
reject(new DataAppError(sessionId ? "The data request timed out." : "The preview shell is unavailable. Reload the preview.", sessionId ? "timeout" : "bridge_unavailable"));
|
|
227
227
|
}, timeoutMs);
|
|
@@ -231,7 +231,7 @@
|
|
|
231
231
|
return;
|
|
232
232
|
try {
|
|
233
233
|
send({
|
|
234
|
-
type: "request",
|
|
234
|
+
type: "bridge:request",
|
|
235
235
|
id,
|
|
236
236
|
route: message.route,
|
|
237
237
|
payload: message.payload
|
|
@@ -256,13 +256,13 @@
|
|
|
256
256
|
if (sessionId)
|
|
257
257
|
entry.start();
|
|
258
258
|
else
|
|
259
|
-
send({ type: "ready" });
|
|
259
|
+
send({ type: "bridge:ready" });
|
|
260
260
|
});
|
|
261
261
|
}
|
|
262
|
-
const messages = createMessageClient({ "data
|
|
262
|
+
const messages = createMessageClient({ "data:query": defineDataQueryRoute() }, requestMessage);
|
|
263
263
|
async function queryData(operation, input, signal) {
|
|
264
264
|
try {
|
|
265
|
-
return await messages.request("data
|
|
265
|
+
return await messages.request("data:query", { operation, input }, { signal });
|
|
266
266
|
} catch (error) {
|
|
267
267
|
if (error instanceof MessageRoutingError)
|
|
268
268
|
throw new DataAppError(error.message, error.code, error.requestId);
|
|
@@ -270,14 +270,14 @@
|
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
function disconnect() {
|
|
273
|
-
send({ type: "disconnect" });
|
|
273
|
+
send({ type: "bridge:disconnect" });
|
|
274
274
|
sessionId = undefined;
|
|
275
275
|
for (const entry of pending.values())
|
|
276
276
|
entry.reject(new DataAppError("The preview has closed.", "bridge_closed"));
|
|
277
277
|
}
|
|
278
278
|
function resume(event) {
|
|
279
279
|
if (event.persisted)
|
|
280
|
-
send({ type: "ready" });
|
|
280
|
+
send({ type: "bridge:ready" });
|
|
281
281
|
}
|
|
282
282
|
function dispose() {
|
|
283
283
|
if (disposed)
|
|
@@ -292,7 +292,7 @@
|
|
|
292
292
|
frame.addEventListener("pagehide", disconnect);
|
|
293
293
|
frame.addEventListener("pageshow", resume);
|
|
294
294
|
if (mode === "url")
|
|
295
|
-
send({ type: "ready" });
|
|
295
|
+
send({ type: "bridge:ready" });
|
|
296
296
|
return {
|
|
297
297
|
request: requestMessage,
|
|
298
298
|
transport: queryData,
|
|
@@ -308,10 +308,10 @@
|
|
|
308
308
|
};
|
|
309
309
|
},
|
|
310
310
|
ready() {
|
|
311
|
-
send({ type: "runtime
|
|
311
|
+
send({ type: "runtime:ready" });
|
|
312
312
|
},
|
|
313
313
|
fail() {
|
|
314
|
-
send({ type: "runtime
|
|
314
|
+
send({ type: "runtime:error" });
|
|
315
315
|
}
|
|
316
316
|
};
|
|
317
317
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MessageRoutingError2
|
|
3
|
-
} from "./contract-
|
|
3
|
+
} from "./contract-ehk50k7e.js";
|
|
4
4
|
import {
|
|
5
5
|
BRIDGE,
|
|
6
6
|
PARENT_PARAM,
|
|
@@ -47,7 +47,7 @@ function attachDataAppBridge2({
|
|
|
47
47
|
}, targetOrigin);
|
|
48
48
|
}
|
|
49
49
|
function error(id, code, message, requestId) {
|
|
50
|
-
send({ type: "error", id, code, message, requestId });
|
|
50
|
+
send({ type: "bridge:error", id, code, message, requestId });
|
|
51
51
|
}
|
|
52
52
|
async function request(message) {
|
|
53
53
|
const id = message.id;
|
|
@@ -79,7 +79,7 @@ function attachDataAppBridge2({
|
|
|
79
79
|
try {
|
|
80
80
|
const response = await onMessage({ route: message.route, payload: message.payload }, { signal: controller.signal });
|
|
81
81
|
if (pending.get(id) === controller)
|
|
82
|
-
send({ type: "result", id, response });
|
|
82
|
+
send({ type: "bridge:result", id, response });
|
|
83
83
|
} catch (failure) {
|
|
84
84
|
if (pending.get(id) === controller) {
|
|
85
85
|
if (failure instanceof MessageRoutingError2)
|
|
@@ -100,7 +100,7 @@ function attachDataAppBridge2({
|
|
|
100
100
|
if (connection.type === "opaque" && message.token !== token)
|
|
101
101
|
return;
|
|
102
102
|
onDiagnostic?.({ direction: "receive", type: message.type });
|
|
103
|
-
if (message.type === "ready") {
|
|
103
|
+
if (message.type === "bridge:ready") {
|
|
104
104
|
if (message.documentId !== documentId) {
|
|
105
105
|
cancelAll();
|
|
106
106
|
documentId = message.documentId;
|
|
@@ -108,25 +108,25 @@ function attachDataAppBridge2({
|
|
|
108
108
|
}
|
|
109
109
|
onStatusChange?.("connected");
|
|
110
110
|
send({
|
|
111
|
-
type: "initialize",
|
|
111
|
+
type: "bridge:initialize",
|
|
112
112
|
state: { search: host.location.search, hash: host.location.hash }
|
|
113
113
|
});
|
|
114
114
|
if (javascript !== undefined)
|
|
115
|
-
send({ type: "script
|
|
115
|
+
send({ type: "script:load", javascript });
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
if (!sessionId || message.sessionId !== sessionId || message.documentId !== documentId)
|
|
119
119
|
return;
|
|
120
|
-
if (message.type === "runtime
|
|
120
|
+
if (message.type === "runtime:ready")
|
|
121
121
|
onStatusChange?.("ready");
|
|
122
|
-
else if (message.type === "runtime
|
|
122
|
+
else if (message.type === "runtime:error")
|
|
123
123
|
onStatusChange?.("failed");
|
|
124
|
-
else if (message.type === "request")
|
|
124
|
+
else if (message.type === "bridge:request")
|
|
125
125
|
request(message);
|
|
126
|
-
else if (message.type === "cancel" && validId(message.id)) {
|
|
126
|
+
else if (message.type === "bridge:cancel" && validId(message.id)) {
|
|
127
127
|
pending.get(message.id)?.abort();
|
|
128
128
|
pending.delete(message.id);
|
|
129
|
-
} else if (message.type === "disconnect") {
|
|
129
|
+
} else if (message.type === "bridge:disconnect") {
|
|
130
130
|
cancelAll();
|
|
131
131
|
documentId = undefined;
|
|
132
132
|
sessionId = undefined;
|
|
@@ -135,7 +135,7 @@ function attachDataAppBridge2({
|
|
|
135
135
|
}
|
|
136
136
|
function navigate() {
|
|
137
137
|
send({
|
|
138
|
-
type: "state",
|
|
138
|
+
type: "state:update",
|
|
139
139
|
state: { search: host.location.search, hash: host.location.hash }
|
|
140
140
|
});
|
|
141
141
|
}
|
|
@@ -146,7 +146,7 @@ function attachDataAppBridge2({
|
|
|
146
146
|
documentId = undefined;
|
|
147
147
|
sessionId = undefined;
|
|
148
148
|
onStatusChange?.("connecting");
|
|
149
|
-
send({ type: "connect", documentId: "host" });
|
|
149
|
+
send({ type: "bridge:connect", documentId: "host" });
|
|
150
150
|
}
|
|
151
151
|
function dispose() {
|
|
152
152
|
cancelAll();
|
|
@@ -160,7 +160,7 @@ function attachDataAppBridge2({
|
|
|
160
160
|
host.addEventListener("popstate", navigate);
|
|
161
161
|
host.addEventListener("pagehide", cancelAll);
|
|
162
162
|
onStatusChange?.("connecting");
|
|
163
|
-
send({ type: "connect", documentId: "host" });
|
|
163
|
+
send({ type: "bridge:connect", documentId: "host" });
|
|
164
164
|
return dispose;
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -229,4 +229,4 @@ function attachDataAppShell2({
|
|
|
229
229
|
|
|
230
230
|
export { attachDataAppBridge2, attachDataAppShell2 };
|
|
231
231
|
|
|
232
|
-
//# debugId=
|
|
232
|
+
//# debugId=2962A017228A422764756E2164756E21
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/embed/host.ts", "../src/embed/shell.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n BRIDGE,\n MAX_PENDING,\n REQUEST_TIMEOUT_MS,\n isBridgeMessage,\n validId,\n type BridgeMessage,\n} from '@/src/core/bridge';\n\nimport {\n MessageRoutingError,\n type MessageDispatcher,\n} from '@/src/core/messages';\n\nexport type DataAppConnection =\n | { type: 'origin'; origin: string }\n | { type: 'opaque'; token: string };\nexport type DataAppStatus =\n | 'connecting'\n | 'connected'\n | 'ready'\n | 'failed'\n | 'disconnected';\nexport type DataAppDiagnostic = { direction: 'send' | 'receive'; type: string };\n\n/** The bridge owns delivery and cancellation; the routed handler owns validation, authorization and execution. */\nexport function attachDataAppBridge({\n iframe,\n connection,\n javascript,\n onStatusChange,\n onDiagnostic,\n onMessage,\n window: host = window,\n}: {\n iframe: HTMLIFrameElement;\n connection: DataAppConnection;\n javascript?: string;\n onStatusChange?: (status: DataAppStatus) => void;\n onDiagnostic?: (event: DataAppDiagnostic) => void;\n onMessage: MessageDispatcher;\n window?: Window;\n}) {\n const frameOrigin = connection.type === 'origin' ? connection.origin : 'null';\n if (\n connection.type === 'origin' &&\n new URL(frameOrigin).origin !== frameOrigin\n )\n throw new Error('Expected an exact frame origin.');\n if (connection.type === 'opaque' && !validId(connection.token))\n throw new Error('Invalid sandbox token.');\n let token = connection.type === 'opaque' ? connection.token : undefined;\n const targetOrigin = connection.type === 'opaque' ? '*' : frameOrigin;\n let documentId: string | undefined;\n let sessionId: string | undefined;\n const pending = new Map<string, AbortController>();\n\n function cancelAll() {\n for (const controller of pending.values()) controller.abort();\n pending.clear();\n }\n\n function send(message: Partial<BridgeMessage>) {\n onDiagnostic?.({ direction: 'send', type: message.type ?? 'unknown' });\n iframe.contentWindow?.postMessage(\n {\n channel: BRIDGE,\n version: 1,\n documentId,\n sessionId,\n ...(connection.type === 'opaque' ? { token } : {}),\n ...message,\n },\n targetOrigin\n );\n }\n\n function error(\n id: string,\n code: string,\n message: string,\n requestId?: string\n ) {\n send({ type: 'bridge:error', id, code, message, requestId });\n }\n\n async function request(message: BridgeMessage) {\n const id = message.id;\n if (!validId(id) || pending.has(id)) return;\n if (pending.size >= MAX_PENDING)\n return error(id, 'bridge_busy', 'Too many pending data requests.');\n if (\n typeof message.route !== 'string' ||\n !message.route ||\n message.route.length > 256\n )\n return error(id, 'invalid_message', 'Invalid message route.');\n try {\n const body = JSON.stringify(message.payload);\n if (\n message.payload !== undefined &&\n (typeof body !== 'string' || body.length > 16_384)\n )\n throw new Error('Invalid payload');\n } catch {\n return error(\n id,\n 'invalid_payload',\n 'The message payload is invalid or too large.'\n );\n }\n const controller = new AbortController();\n pending.set(id, controller);\n const timer = setTimeout(() => {\n if (pending.get(id) !== controller) return;\n pending.delete(id);\n controller.abort();\n error(id, 'timeout', 'The data request timed out.');\n }, REQUEST_TIMEOUT_MS);\n controller.signal.addEventListener('abort', () => clearTimeout(timer), {\n once: true,\n });\n try {\n const response = await onMessage(\n { route: message.route, payload: message.payload },\n { signal: controller.signal }\n );\n if (pending.get(id) === controller)\n send({ type: 'bridge:result', id, response });\n } catch (failure) {\n if (pending.get(id) === controller) {\n if (failure instanceof MessageRoutingError)\n error(id, failure.code, failure.message, failure.requestId);\n else\n error(\n id,\n 'request_failed',\n 'The message request failed. Retry the request.'\n );\n }\n } finally {\n clearTimeout(timer);\n if (pending.get(id) === controller) pending.delete(id);\n }\n }\n\n function receive(event: MessageEvent) {\n if (\n event.origin !== frameOrigin ||\n event.source !== iframe.contentWindow ||\n !isBridgeMessage(event.data)\n )\n return;\n const message = event.data;\n if (connection.type === 'opaque' && message.token !== token) return;\n onDiagnostic?.({ direction: 'receive', type: message.type });\n if (message.type === 'bridge:ready') {\n if (message.documentId !== documentId) {\n cancelAll();\n documentId = message.documentId;\n sessionId = crypto.randomUUID();\n }\n onStatusChange?.('connected');\n send({\n type: 'bridge:initialize',\n state: { search: host.location.search, hash: host.location.hash },\n });\n if (javascript !== undefined) send({ type: 'script:load', javascript });\n\n return;\n }\n if (\n !sessionId ||\n message.sessionId !== sessionId ||\n message.documentId !== documentId\n )\n return;\n if (message.type === 'runtime:ready') onStatusChange?.('ready');\n else if (message.type === 'runtime:error') onStatusChange?.('failed');\n else if (message.type === 'bridge:request') void request(message);\n else if (message.type === 'bridge:cancel' && validId(message.id)) {\n pending.get(message.id)?.abort();\n pending.delete(message.id);\n } else if (message.type === 'bridge:disconnect') {\n cancelAll();\n documentId = undefined;\n sessionId = undefined;\n onStatusChange?.('disconnected');\n }\n }\n\n function navigate() {\n send({\n type: 'state:update',\n state: { search: host.location.search, hash: host.location.hash },\n });\n }\n\n function load() {\n if (connection.type === 'opaque') token = crypto.randomUUID();\n cancelAll();\n documentId = undefined;\n sessionId = undefined;\n onStatusChange?.('connecting');\n send({ type: 'bridge:connect', documentId: 'host' });\n }\n\n function dispose() {\n cancelAll();\n iframe.removeEventListener('load', load);\n host.removeEventListener('message', receive);\n host.removeEventListener('popstate', navigate);\n host.removeEventListener('pagehide', cancelAll);\n }\n\n iframe.addEventListener('load', load);\n host.addEventListener('message', receive);\n host.addEventListener('popstate', navigate);\n host.addEventListener('pagehide', cancelAll);\n // Reconnect an already-loaded iframe when its host bridge mounts again.\n onStatusChange?.('connecting');\n send({ type: 'bridge:connect', documentId: 'host' });\n\n return dispose;\n}\n",
|
|
6
|
+
"import { PARENT_PARAM } from '@/src/core/bridge';\nimport type { MessageDispatcher } from '@/src/core/messages';\nimport {\n attachDataAppBridge,\n type DataAppStatus,\n type DataAppDiagnostic,\n} from '@/src/embed/host';\n\nexport type DataAppSource =\n | { type: 'url'; url: string }\n | {\n type: 'bundle';\n bootstrapUrl: string;\n javascript: string;\n revision: string;\n };\nexport type DataAppShellOptions = {\n iframe: HTMLIFrameElement;\n source: DataAppSource;\n onMessage: MessageDispatcher;\n onStatusChange?: (status: DataAppStatus) => void;\n onDiagnostic?: (event: DataAppDiagnostic) => void;\n startupTimeoutMs?: number;\n};\n\n/** Owns loading and sandbox policy. Dispose before replacing the source or retrying. */\nexport function attachDataAppShell({\n iframe,\n source,\n onMessage,\n onStatusChange,\n onDiagnostic,\n startupTimeoutMs = 30_000,\n}: DataAppShellOptions) {\n const host = iframe.ownerDocument.defaultView;\n if (!host) throw new Error('The iframe requires a host window.');\n const url = new URL(\n source.type === 'url' ? source.url : source.bootstrapUrl,\n host.location.href\n );\n if (!/^https?:$/.test(url.protocol))\n throw new Error('Data apps require an HTTP(S) URL.');\n const opaque = source.type === 'bundle';\n if (!opaque && url.origin === host.location.origin)\n throw new Error('URL data apps require a separate origin from the shell.');\n iframe.setAttribute(\n 'sandbox',\n opaque\n ? 'allow-scripts'\n : 'allow-scripts allow-same-origin allow-downloads allow-popups allow-popups-to-escape-sandbox'\n );\n iframe.referrerPolicy = 'no-referrer';\n if (!opaque) url.searchParams.set(PARENT_PARAM, host.location.origin);\n let timer: ReturnType<typeof setTimeout> | undefined;\n let failed = false;\n\n function status(value: DataAppStatus) {\n if (value === 'connecting') failed = false;\n if (failed && value !== 'connecting') return;\n clearTimeout(timer);\n if (value === 'connecting' || value === 'connected')\n timer = setTimeout(() => {\n failed = true;\n disposeBridge();\n onStatusChange?.('failed');\n }, startupTimeoutMs);\n if (value === 'failed') {\n failed = true;\n disposeBridge();\n }\n onStatusChange?.(value);\n }\n\n const disposeBridge = attachDataAppBridge({\n iframe,\n connection: opaque\n ? { type: 'opaque', token: crypto.randomUUID() }\n : { type: 'origin', origin: url.origin },\n javascript: opaque ? source.javascript : undefined,\n onMessage,\n onStatusChange: status,\n onDiagnostic,\n window: host,\n });\n\n function error() {\n return status('failed');\n }\n\n iframe.addEventListener('error', error);\n iframe.src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AAAA,IACzC,YAAY,SAAS,OAAO,aAAa;AAAA,IACzC;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AAAA,EAED,SAAS,KAAK,GAAG;AAAA,IACf,OAAO,OAAO,QAAQ;AAAA;AAAA,EAGxB,OAAO,iBAAiB,SAAS,KAAK;AAAA,EACtC,OAAO,MAAM,IAAI;AAAA,EAEjB,OAAO,MAAM;AAAA,IACX,aAAa,KAAK;AAAA,IAClB,OAAO,oBAAoB,SAAS,KAAK;AAAA,IACzC,cAAc;AAAA;AAAA;",
|
|
9
|
+
"debugId": "2962A017228A422764756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MessageRoutingError2,
|
|
3
3
|
defineDataQueryRoute2
|
|
4
|
-
} from "./contract-
|
|
4
|
+
} from "./contract-ehk50k7e.js";
|
|
5
5
|
import {
|
|
6
6
|
BRIDGE,
|
|
7
7
|
PARENT_PARAM,
|
|
@@ -106,20 +106,20 @@ function createIframeTransport2({
|
|
|
106
106
|
if (event.origin !== parentOrigin || event.source !== frame.parent || !isBridgeMessage(event.data))
|
|
107
107
|
return;
|
|
108
108
|
const message = event.data;
|
|
109
|
-
if (message.type === "connect") {
|
|
109
|
+
if (message.type === "bridge:connect") {
|
|
110
110
|
if (mode === "bundle") {
|
|
111
111
|
if (!validId(message.token))
|
|
112
112
|
return;
|
|
113
113
|
token = message.token;
|
|
114
114
|
}
|
|
115
|
-
send({ type: "ready" });
|
|
115
|
+
send({ type: "bridge:ready" });
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
if (mode === "bundle" && (!token || message.token !== token))
|
|
119
119
|
return;
|
|
120
120
|
if (message.documentId !== documentId)
|
|
121
121
|
return;
|
|
122
|
-
if (message.type === "initialize" && validId(message.sessionId)) {
|
|
122
|
+
if (message.type === "bridge:initialize" && validId(message.sessionId)) {
|
|
123
123
|
if (sessionId && sessionId !== message.sessionId) {
|
|
124
124
|
for (const entry of pending.values())
|
|
125
125
|
entry.reject(new DataAppError2("The preview reconnected. Retry the request.", "bridge_reset"));
|
|
@@ -131,16 +131,16 @@ function createIframeTransport2({
|
|
|
131
131
|
entry.start();
|
|
132
132
|
receiveState(message.state);
|
|
133
133
|
if (mode === "url")
|
|
134
|
-
send({ type: "runtime
|
|
134
|
+
send({ type: "runtime:ready" });
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
137
|
if (!sessionId || message.sessionId !== sessionId)
|
|
138
138
|
return;
|
|
139
|
-
if (message.type === "state") {
|
|
139
|
+
if (message.type === "state:update") {
|
|
140
140
|
receiveState(message.state);
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
|
-
if (message.type === "script
|
|
143
|
+
if (message.type === "script:load" && mode === "bundle" && typeof message.javascript === "string") {
|
|
144
144
|
loadScript?.(message.javascript);
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
@@ -149,9 +149,9 @@ function createIframeTransport2({
|
|
|
149
149
|
const entry = pending.get(message.id);
|
|
150
150
|
if (!entry)
|
|
151
151
|
return;
|
|
152
|
-
if (message.type === "result" && "response" in message) {
|
|
152
|
+
if (message.type === "bridge:result" && "response" in message) {
|
|
153
153
|
entry.resolve(message.response);
|
|
154
|
-
} else if (message.type === "error" && typeof message.code === "string" && typeof message.message === "string") {
|
|
154
|
+
} else if (message.type === "bridge:error" && typeof message.code === "string" && typeof message.message === "string") {
|
|
155
155
|
entry.reject(new MessageRoutingError2(message.code, message.message, typeof message.requestId === "string" ? message.requestId : undefined));
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -173,13 +173,13 @@ function createIframeTransport2({
|
|
|
173
173
|
}
|
|
174
174
|
function abort() {
|
|
175
175
|
if (sent)
|
|
176
|
-
send({ type: "cancel", id });
|
|
176
|
+
send({ type: "bridge:cancel", id });
|
|
177
177
|
cleanup();
|
|
178
178
|
reject(signal?.reason);
|
|
179
179
|
}
|
|
180
180
|
const timer = setTimeout(() => {
|
|
181
181
|
if (sent)
|
|
182
|
-
send({ type: "cancel", id });
|
|
182
|
+
send({ type: "bridge:cancel", id });
|
|
183
183
|
cleanup();
|
|
184
184
|
reject(new DataAppError2(sessionId ? "The data request timed out." : "The preview shell is unavailable. Reload the preview.", sessionId ? "timeout" : "bridge_unavailable"));
|
|
185
185
|
}, timeoutMs);
|
|
@@ -189,7 +189,7 @@ function createIframeTransport2({
|
|
|
189
189
|
return;
|
|
190
190
|
try {
|
|
191
191
|
send({
|
|
192
|
-
type: "request",
|
|
192
|
+
type: "bridge:request",
|
|
193
193
|
id,
|
|
194
194
|
route: message.route,
|
|
195
195
|
payload: message.payload
|
|
@@ -214,13 +214,13 @@ function createIframeTransport2({
|
|
|
214
214
|
if (sessionId)
|
|
215
215
|
entry.start();
|
|
216
216
|
else
|
|
217
|
-
send({ type: "ready" });
|
|
217
|
+
send({ type: "bridge:ready" });
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
|
-
const messages = createMessageClient2({ "data
|
|
220
|
+
const messages = createMessageClient2({ "data:query": defineDataQueryRoute2() }, requestMessage);
|
|
221
221
|
async function queryData(operation, input, signal) {
|
|
222
222
|
try {
|
|
223
|
-
return await messages.request("data
|
|
223
|
+
return await messages.request("data:query", { operation, input }, { signal });
|
|
224
224
|
} catch (error) {
|
|
225
225
|
if (error instanceof MessageRoutingError2)
|
|
226
226
|
throw new DataAppError2(error.message, error.code, error.requestId);
|
|
@@ -228,14 +228,14 @@ function createIframeTransport2({
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
function disconnect() {
|
|
231
|
-
send({ type: "disconnect" });
|
|
231
|
+
send({ type: "bridge:disconnect" });
|
|
232
232
|
sessionId = undefined;
|
|
233
233
|
for (const entry of pending.values())
|
|
234
234
|
entry.reject(new DataAppError2("The preview has closed.", "bridge_closed"));
|
|
235
235
|
}
|
|
236
236
|
function resume(event) {
|
|
237
237
|
if (event.persisted)
|
|
238
|
-
send({ type: "ready" });
|
|
238
|
+
send({ type: "bridge:ready" });
|
|
239
239
|
}
|
|
240
240
|
function dispose() {
|
|
241
241
|
if (disposed)
|
|
@@ -250,7 +250,7 @@ function createIframeTransport2({
|
|
|
250
250
|
frame.addEventListener("pagehide", disconnect);
|
|
251
251
|
frame.addEventListener("pageshow", resume);
|
|
252
252
|
if (mode === "url")
|
|
253
|
-
send({ type: "ready" });
|
|
253
|
+
send({ type: "bridge:ready" });
|
|
254
254
|
return {
|
|
255
255
|
request: requestMessage,
|
|
256
256
|
transport: queryData,
|
|
@@ -266,10 +266,10 @@ function createIframeTransport2({
|
|
|
266
266
|
};
|
|
267
267
|
},
|
|
268
268
|
ready() {
|
|
269
|
-
send({ type: "runtime
|
|
269
|
+
send({ type: "runtime:ready" });
|
|
270
270
|
},
|
|
271
271
|
fail() {
|
|
272
|
-
send({ type: "runtime
|
|
272
|
+
send({ type: "runtime:error" });
|
|
273
273
|
}
|
|
274
274
|
};
|
|
275
275
|
}
|
|
@@ -372,4 +372,4 @@ function getDataAppTransport2(frame = window) {
|
|
|
372
372
|
|
|
373
373
|
export { DataAppError2, createHttpTransport2, createMessageClient2, createIframeTransport2, localFrameBridge, installDataAppTransport2, getDataAppTransport2 };
|
|
374
374
|
|
|
375
|
-
//# debugId=
|
|
375
|
+
//# debugId=8A923FD5B245BF3C64756E2164756E21
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client/transport.ts", "../src/client/messages.ts", "../src/client/iframe.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { TransportResponse } from '@/src/core/bridge';\n\nexport type DataTransport = (\n operation: string,\n input: unknown,\n signal?: AbortSignal\n) => Promise<TransportResponse>;\n\n// A bootstrap and its app may bundle independent copies in the same window.\nconst errorBrand = Symbol.for('@altertable/data-app/DataAppError');\n\nexport class DataAppError extends Error {\n readonly [errorBrand] = true;\n\n static [Symbol.hasInstance](value: unknown): boolean {\n return (\n value instanceof Error &&\n (value as { [errorBrand]?: unknown })[errorBrand] === true\n );\n }\n\n constructor(\n message: string,\n public readonly code: string,\n public readonly requestId?: string\n ) {\n super(message);\n this.name = 'DataAppError';\n }\n}\n\nexport function createHttpTransport({\n endpoint = '/api/data',\n fetch: request = globalThis.fetch,\n}: {\n endpoint?: string;\n fetch?: typeof fetch;\n} = {}): DataTransport {\n async function requestData(\n operation: string,\n input: unknown,\n signal?: AbortSignal\n ): Promise<TransportResponse> {\n const response = await request(\n `${endpoint.replace(/\\/$/, '')}/${encodeURIComponent(operation)}`,\n {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(input),\n signal,\n }\n );\n try {\n return { status: response.status, body: await response.json() };\n } catch (error) {\n if (signal?.aborted) throw error;\n throw new DataAppError(\n response.ok ? 'The data response was invalid.' : 'Could not load data.',\n response.ok ? 'invalid_response' : 'request_failed'\n );\n }\n }\n\n return requestData;\n}\n",
|
|
6
|
+
"import {\n MessageRoutingError,\n type MessageInput,\n type MessageOutput,\n type MessageRoutes,\n type MessageTransport,\n} from '@/src/core/messages';\n\n/** Both ends validate using the same contracts; the transport owns delivery and cancellation. */\nexport function createMessageClient<const Routes extends MessageRoutes>(\n routes: Routes,\n transport: MessageTransport\n) {\n return {\n async request<\n Name extends keyof Routes & string,\n const Input extends MessageInput<NoInfer<Routes[Name]>>,\n >(\n route: Name,\n payload: Input,\n { signal }: { signal?: AbortSignal } = {}\n ): Promise<MessageOutput<Routes[Name], Input>> {\n signal?.throwIfAborted();\n if (!Object.hasOwn(routes, route))\n throw new MessageRoutingError(\n 'unknown_route',\n 'Unknown message route.'\n );\n const contract = routes[route]!;\n let input: unknown;\n try {\n input = contract.input(payload);\n } catch {\n throw new MessageRoutingError(\n 'invalid_payload',\n 'Invalid message payload.'\n );\n }\n const response = await transport({ route, payload: input }, signal);\n signal?.throwIfAborted();\n try {\n return contract.output(response, input as never) as MessageOutput<\n Routes[Name],\n Input\n >;\n } catch (error) {\n if (error instanceof MessageRoutingError) throw error;\n throw new MessageRoutingError(\n 'invalid_response',\n 'Invalid message response.'\n );\n }\n },\n };\n}\n",
|
|
7
|
+
"import {\n BRIDGE,\n PARENT_PARAM,\n MAX_PENDING,\n REQUEST_TIMEOUT_MS,\n isBridgeMessage,\n validId,\n type BridgeMessage,\n type TransportResponse,\n} from '@/src/core/bridge';\nimport {\n defineDataQueryRoute,\n MessageRoutingError,\n type RoutedMessage,\n} from '@/src/core/messages';\nimport { createMessageClient } from '@/src/client/messages';\nimport { DataAppError } from '@/src/client/transport';\n\ntype Pending = {\n start: () => void;\n reject: (error: unknown) => void;\n resolve: (value: unknown) => void;\n};\n\n/** One bridge per document, shared by all clients and retained across module hot replacement. */\nexport function createIframeTransport({\n parentOrigin,\n window: frame = window,\n timeoutMs = REQUEST_TIMEOUT_MS,\n mode = 'url',\n loadScript,\n}: {\n parentOrigin: string;\n window?: Window;\n timeoutMs?: number;\n mode?: 'url' | 'bundle';\n loadScript?: (javascript: string) => void;\n}) {\n if (new URL(parentOrigin).origin !== parentOrigin)\n throw new Error('Expected an exact parent origin.');\n const documentId = crypto.randomUUID();\n let token: string | undefined;\n let sessionId: string | undefined;\n let disposed = false;\n const pending = new Map<string, Pending>();\n let hostState: unknown;\n const stateListeners = new Set<(state: unknown) => void>();\n\n function send(message: Partial<BridgeMessage>) {\n frame.parent.postMessage(\n { channel: BRIDGE, version: 1, documentId, sessionId, token, ...message },\n parentOrigin\n );\n }\n\n function receiveState(state: unknown) {\n hostState = state;\n for (const listener of stateListeners) listener(state);\n }\n\n function receive(event: MessageEvent) {\n if (\n event.origin !== parentOrigin ||\n event.source !== frame.parent ||\n !isBridgeMessage(event.data)\n )\n return;\n const message = event.data;\n if (message.type === 'bridge:connect') {\n if (mode === 'bundle') {\n if (!validId(message.token)) return;\n token = message.token;\n }\n send({ type: 'bridge:ready' });\n\n return;\n }\n if (mode === 'bundle' && (!token || message.token !== token)) return;\n if (message.documentId !== documentId) return;\n if (message.type === 'bridge:initialize' && validId(message.sessionId)) {\n if (sessionId && sessionId !== message.sessionId) {\n for (const entry of pending.values())\n entry.reject(\n new DataAppError(\n 'The preview reconnected. Retry the request.',\n 'bridge_reset'\n )\n );\n }\n const first = !sessionId;\n sessionId = message.sessionId;\n if (first) for (const entry of pending.values()) entry.start();\n receiveState(message.state);\n if (mode === 'url') send({ type: 'runtime:ready' });\n\n return;\n }\n if (!sessionId || message.sessionId !== sessionId) return;\n if (message.type === 'state:update') {\n receiveState(message.state);\n\n return;\n }\n if (\n message.type === 'script:load' &&\n mode === 'bundle' &&\n typeof message.javascript === 'string'\n ) {\n loadScript?.(message.javascript);\n\n return;\n }\n if (typeof message.id !== 'string') return;\n const entry = pending.get(message.id);\n if (!entry) return;\n if (message.type === 'bridge:result' && 'response' in message) {\n entry.resolve(message.response);\n } else if (\n message.type === 'bridge:error' &&\n typeof message.code === 'string' &&\n typeof message.message === 'string'\n ) {\n entry.reject(\n new MessageRoutingError(\n message.code,\n message.message,\n typeof message.requestId === 'string' ? message.requestId : undefined\n )\n );\n }\n }\n\n frame.addEventListener('message', receive);\n\n function requestMessage(\n message: RoutedMessage,\n signal?: AbortSignal\n ): Promise<unknown> {\n return new Promise((resolve, reject) => {\n if (disposed)\n return reject(\n new DataAppError('The preview has closed.', 'bridge_closed')\n );\n if (signal?.aborted) return reject(signal.reason);\n if (pending.size >= MAX_PENDING)\n return reject(\n new DataAppError('Too many pending data requests.', 'bridge_busy')\n );\n const id = crypto.randomUUID();\n let sent = false;\n\n function cleanup() {\n clearTimeout(timer);\n signal?.removeEventListener('abort', abort);\n pending.delete(id);\n }\n\n function abort() {\n if (sent) send({ type: 'bridge:cancel', id });\n cleanup();\n reject(signal?.reason);\n }\n\n const timer = setTimeout(() => {\n if (sent) send({ type: 'bridge:cancel', id });\n cleanup();\n reject(\n new DataAppError(\n sessionId\n ? 'The data request timed out.'\n : 'The preview shell is unavailable. Reload the preview.',\n sessionId ? 'timeout' : 'bridge_unavailable'\n )\n );\n }, timeoutMs);\n const entry: Pending = {\n start() {\n if (sent) return;\n try {\n send({\n type: 'bridge:request',\n id,\n route: message.route,\n payload: message.payload,\n });\n sent = true;\n } catch {\n cleanup();\n reject(\n new DataAppError(\n 'The message payload could not be sent.',\n 'invalid_payload'\n )\n );\n }\n },\n resolve(value) {\n cleanup();\n resolve(value);\n },\n reject(error) {\n cleanup();\n reject(error);\n },\n };\n pending.set(id, entry);\n signal?.addEventListener('abort', abort, { once: true });\n if (sessionId) entry.start();\n else send({ type: 'bridge:ready' });\n });\n }\n\n const messages = createMessageClient(\n { 'data:query': defineDataQueryRoute() },\n requestMessage\n );\n\n async function queryData(\n operation: string,\n input: unknown,\n signal?: AbortSignal\n ): Promise<TransportResponse> {\n try {\n return await messages.request(\n 'data:query',\n { operation, input },\n { signal }\n );\n } catch (error) {\n if (error instanceof MessageRoutingError)\n throw new DataAppError(error.message, error.code, error.requestId);\n throw error;\n }\n }\n\n function disconnect() {\n send({ type: 'bridge:disconnect' });\n sessionId = undefined;\n for (const entry of pending.values())\n entry.reject(\n new DataAppError('The preview has closed.', 'bridge_closed')\n );\n }\n\n function resume(event: PageTransitionEvent) {\n if (event.persisted) send({ type: 'bridge:ready' });\n }\n\n function dispose() {\n if (disposed) return;\n disconnect();\n disposed = true;\n frame.removeEventListener('message', receive);\n frame.removeEventListener('pagehide', disconnect);\n frame.removeEventListener('pageshow', resume);\n stateListeners.clear();\n }\n\n frame.addEventListener('pagehide', disconnect);\n frame.addEventListener('pageshow', resume);\n if (mode === 'url') send({ type: 'bridge:ready' });\n\n return {\n request: requestMessage,\n transport: queryData,\n dispose,\n mode,\n snapshot() {\n return hostState;\n },\n subscribe(listener: (state: unknown) => void) {\n stateListeners.add(listener);\n\n return () => {\n stateListeners.delete(listener);\n };\n },\n ready() {\n send({ type: 'runtime:ready' });\n },\n fail() {\n send({ type: 'runtime:error' });\n },\n };\n}\n\nexport type IframeTransport = ReturnType<typeof createIframeTransport>;\n\nconst bridgeKey = Symbol.for('altertable.localFrameBridge');\nconst installedKey = Symbol.for('altertable.installedTransport');\ntype LocalBridge = Pick<\n ReturnType<typeof createIframeTransport>,\n 'transport'\n> & { connect?: () => Promise<ReturnType<typeof createIframeTransport>> };\ntype FrameWindow = Window & {\n [bridgeKey]?: LocalBridge;\n [installedKey]?: ReturnType<typeof createIframeTransport>;\n};\n\n/** The URL opts into local preview; only same-origin server configuration establishes trust. */\nexport function localFrameBridge(window?: Window): LocalBridge | undefined {\n const activeWindow =\n window ??\n (typeof globalThis.window === 'undefined' ? undefined : globalThis.window);\n if (!activeWindow) return undefined;\n const frame = activeWindow as FrameWindow;\n if (frame[bridgeKey]) return frame[bridgeKey];\n const parentOrigin =\n new URL(frame.location.href).searchParams.get(PARENT_PARAM) ?? '';\n if (!parentOrigin) return undefined;\n\n async function connect(parentOrigin: string) {\n try {\n const response = await frame.fetch('/__altertable/parent', {\n signal: AbortSignal.timeout(5000),\n });\n const config = (await response.json()) as { origin?: unknown };\n if (\n !response.ok ||\n config.origin !== parentOrigin ||\n frame.parent === frame\n )\n throw new Error('Invalid local parent configuration.');\n // Another owner can install a trusted bridge while configuration is pending.\n if (frame[installedKey]) return frame[installedKey];\n if (frame[bridgeKey] !== proxy)\n throw new Error('Preview transport owner changed.');\n const bridge = createIframeTransport({ parentOrigin, window: frame });\n frame[bridgeKey] = bridge;\n frame[installedKey] = bridge;\n\n return bridge;\n } catch {\n throw new DataAppError(\n 'The preview shell could not be verified. Open the URL printed by altertable app dev.',\n 'bridge_unavailable'\n );\n }\n }\n\n let connection: Promise<ReturnType<typeof createIframeTransport>> | undefined;\n\n function getConnection() {\n const installed = frame[installedKey];\n if (installed) return Promise.resolve(installed);\n if (!connection) {\n const attempt = connect(parentOrigin);\n connection = attempt;\n // Clear only this failed attempt; retained proxy references can explicitly retry.\n void attempt.catch(() => {\n if (connection === attempt) connection = undefined;\n });\n }\n\n return connection;\n }\n\n const proxy: LocalBridge = {\n async transport(operation, input, signal) {\n signal?.throwIfAborted();\n const attempt = getConnection();\n let abort: (() => void) | undefined;\n try {\n const bridge = signal\n ? await Promise.race([\n attempt,\n new Promise<never>((_, reject) => {\n const requestSignal = signal;\n\n function handleAbort() {\n reject(requestSignal.reason);\n }\n\n abort = handleAbort;\n requestSignal.addEventListener('abort', handleAbort, {\n once: true,\n });\n }),\n ])\n : await attempt;\n signal?.throwIfAborted();\n\n return bridge.transport(operation, input, signal);\n } finally {\n if (abort) signal?.removeEventListener('abort', abort);\n }\n },\n connect: getConnection,\n };\n frame[bridgeKey] = proxy;\n // Static mounting still verifies eagerly, without an unhandled rejection.\n void getConnection().catch(() => {});\n\n return proxy;\n}\n\n/** Install an explicitly trusted transport for hosted apps and their URL-backed controls. */\nexport function installDataAppTransport(\n bridge: ReturnType<typeof createIframeTransport>,\n frame: Window = window\n) {\n const target = frame as FrameWindow;\n if (target[installedKey])\n throw new Error('A data app transport is already installed.');\n target[bridgeKey] = bridge;\n target[installedKey] = bridge;\n\n return () => {\n if (target[bridgeKey] === bridge) delete target[bridgeKey];\n if (target[installedKey] === bridge) delete target[installedKey];\n bridge.dispose();\n };\n}\n\n/** The bootstrap installs this before executing app code. URL apps can install an explicit connection. */\nexport function getDataAppTransport(frame: Window = window) {\n return (frame as FrameWindow)[installedKey];\n}\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";;;;;;;;;;;;;;AASA,IAAM,aAAa,OAAO,IAAI,mCAAmC;AAAA;AAE1D,MAAM,sBAAqB,MAAM;AAAA,EAYpB;AAAA,EACA;AAAA,GAZR,cAAc;AAAA,UAEhB,OAAO,YAAY,CAAC,OAAyB;AAAA,IACnD,OACE,iBAAiB,SAChB,MAAqC,gBAAgB;AAAA;AAAA,EAI1D,WAAW,CACT,SACgB,MACA,WAChB;AAAA,IACA,MAAM,OAAO;AAAA,IAHG;AAAA,IACA;AAAA,IAGhB,KAAK,OAAO;AAAA;AAEhB;AAEO,SAAS,oBAAmB;AAAA,EACjC,WAAW;AAAA,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AAW,OAAO,MAAM;AAAA,gBAChD;AAAA,QACA,IAAI;AAAA,UAAO,QAAQ,oBAAoB,SAAS,KAAK;AAAA;AAAA;AAAA,IAGzD,SAAS;AAAA,EACX;AAAA,EACA,MAAM,aAAa;AAAA,EAEd,cAAc,EAAE,MAAM,MAAM,EAAE;AAAA,EAEnC,OAAO;AAAA;AAIF,SAAS,wBAAuB,CACrC,QACA,QAAgB,QAChB;AAAA,EACA,MAAM,SAAS;AAAA,EACf,IAAI,OAAO;AAAA,IACT,MAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D,OAAO,aAAa;AAAA,EACpB,OAAO,gBAAgB;AAAA,EAEvB,OAAO,MAAM;AAAA,IACX,IAAI,OAAO,eAAe;AAAA,MAAQ,OAAO,OAAO;AAAA,IAChD,IAAI,OAAO,kBAAkB;AAAA,MAAQ,OAAO,OAAO;AAAA,IACnD,OAAO,QAAQ;AAAA;AAAA;AAKZ,SAAS,oBAAmB,CAAC,QAAgB,QAAQ;AAAA,EAC1D,OAAQ,MAAsB;AAAA;",
|
|
10
|
+
"debugId": "8A923FD5B245BF3C64756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
|
@@ -124,10 +124,10 @@ var navigationUpdateRoute2 = /* @__PURE__ */ defineMessageRoute2({
|
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
var dataAppRoutes2 = {
|
|
127
|
-
"data
|
|
128
|
-
"navigation
|
|
127
|
+
"data:query": /* @__PURE__ */ defineDataQueryRoute2(),
|
|
128
|
+
"navigation:update": navigationUpdateRoute2
|
|
129
129
|
};
|
|
130
130
|
|
|
131
131
|
export { MessageRoutingError2, defineMessageRoute2, createMessageRouter2, defineDataQueryRoute2, navigationUpdateRoute2, dataAppRoutes2 };
|
|
132
132
|
|
|
133
|
-
//# debugId=
|
|
133
|
+
//# debugId=294B82BAC69F23DB64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/core/messages.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { TransportResponse } from '@/src/core/bridge';\nimport type { DisclosedQuery } from '@/src/core/contract';\n\nexport type MessageContext = { signal: AbortSignal };\nexport type RoutedMessage = { route: string; payload: unknown };\nexport type MessageDispatcher = (\n message: unknown,\n context: MessageContext\n) => Promise<unknown>;\nexport type MessageTransport = (\n message: RoutedMessage,\n signal?: AbortSignal\n) => Promise<unknown>;\nexport type MessageRoute<Input, Output> = {\n input: (value: unknown) => Input;\n output: (value: unknown, input: Input) => Output;\n};\nexport type MessageRoutes = Record<\n string,\n {\n input: (value: unknown) => unknown;\n output: (value: unknown, input: never) => unknown;\n }\n>;\nexport type MessageInput<Route extends MessageRoutes[string]> = ReturnType<\n Route['input']\n>;\nexport type MessageHandlers<Routes extends MessageRoutes> = {\n [Name in keyof Routes]: (\n payload: MessageInput<Routes[Name]>,\n context: MessageContext\n ) =>\n | ReturnType<Routes[Name]['output']>\n | Promise<ReturnType<Routes[Name]['output']>>;\n};\n\n// A bootstrap and its app may bundle independent copies in the same window.\nconst errorBrand = Symbol.for('@altertable/data-app/MessageRoutingError');\n\n/** Only these deliberate, public failures cross the message boundary. Other errors stay private. */\nexport class MessageRoutingError extends Error {\n readonly [errorBrand] = true;\n\n static [Symbol.hasInstance](value: unknown): boolean {\n return (\n value instanceof Error &&\n (value as { [errorBrand]?: unknown })[errorBrand] === true\n );\n }\n\n constructor(\n public readonly code: string,\n message: string,\n public readonly requestId?: string\n ) {\n super(message);\n this.name = 'MessageRoutingError';\n }\n}\n\nexport function defineMessageRoute<Input, Output>(\n route: MessageRoute<Input, Output>\n): MessageRoute<Input, Output> {\n return route;\n}\n\n/** Contracts are shared; handlers are supplied by the host and never belong in the app bundle. */\nexport function createMessageRouter<const Routes extends MessageRoutes>(\n routes: Routes,\n handlers: MessageHandlers<NoInfer<Routes>>\n) {\n const registered = new Map(\n Object.entries(routes).map(([name, contract]) => {\n const handler = handlers[name];\n if (!name || name.length > 256 || typeof handler !== 'function')\n throw new Error(\n 'Each message route requires a handler and a bounded name.'\n );\n\n return [name, { contract, handler }] as const;\n })\n );\n\n async function dispatch(\n value: unknown,\n context: MessageContext\n ): Promise<unknown> {\n if (\n !value ||\n typeof value !== 'object' ||\n typeof (value as RoutedMessage).route !== 'string'\n )\n throw new MessageRoutingError(\n 'invalid_message',\n 'Invalid routed message.'\n );\n const message = value as RoutedMessage;\n const entry = registered.get(message.route);\n if (!entry)\n throw new MessageRoutingError('unknown_route', 'Unknown message route.');\n let payload: unknown;\n try {\n payload = entry.contract.input(message.payload);\n } catch {\n throw new MessageRoutingError(\n 'invalid_payload',\n 'Invalid message payload.'\n );\n }\n context.signal.throwIfAborted();\n let result: unknown;\n try {\n result = await entry.handler(payload as never, context);\n } catch (error) {\n if (context.signal.aborted) throw context.signal.reason;\n if (error instanceof MessageRoutingError) throw error;\n throw new MessageRoutingError(\n 'request_failed',\n 'The message request failed. Retry the request.'\n );\n }\n context.signal.throwIfAborted();\n try {\n return entry.contract.output(result, payload as never);\n } catch (error) {\n if (error instanceof MessageRoutingError) throw error;\n throw new MessageRoutingError(\n 'invalid_response',\n 'Invalid message response.'\n );\n }\n }\n\n return { dispatch };\n}\n\nexport type OperationContracts = Record<\n string,\n {\n input: (value: unknown) => unknown;\n output: (value: unknown) => unknown;\n }\n>;\nexport type DataQueryInput<Operations extends OperationContracts> = {\n [Name in keyof Operations & string]: {\n operation: Name;\n input: ReturnType<Operations[Name]['input']>;\n };\n}[keyof Operations & string];\nexport type DataQueryBody<Output> = {\n data: Output;\n requestId: string;\n queriedAt: string;\n queryIds: string[];\n queries?: DisclosedQuery[];\n};\nexport type DataQueryRoute<Operations extends OperationContracts> =\n MessageRoute<DataQueryInput<Operations>, TransportResponse> & {\n operations: Operations | undefined;\n };\nexport type MessageOutput<Route extends MessageRoutes[string], Input> =\n Route extends DataQueryRoute<infer Operations>\n ? Input extends { operation: infer Name extends keyof Operations }\n ? {\n status: number;\n body: DataQueryBody<ReturnType<Operations[Name]['output']>>;\n }\n : never\n : ReturnType<Route['output']>;\n\n/** Omit contracts only in generic hosts such as the CLI shell, where Bun validates operations. */\nexport function defineDataQueryRoute<\n Operations extends OperationContracts = OperationContracts,\n>(operations?: Operations): DataQueryRoute<Operations> {\n return {\n operations,\n input(value) {\n if (!value || typeof value !== 'object')\n throw new Error('Invalid query.');\n const request = value as { operation?: unknown; input?: unknown };\n if (\n typeof request.operation !== 'string' ||\n !request.operation ||\n request.operation.length > 256 ||\n request.operation.includes('/')\n )\n throw new Error('Invalid operation.');\n const operation =\n operations && Object.hasOwn(operations, request.operation)\n ? operations[request.operation]\n : undefined;\n if (operations && !operation) throw new Error('Unknown operation.');\n\n return {\n operation: request.operation,\n input: operation ? operation.input(request.input) : request.input,\n } as DataQueryInput<Operations>;\n },\n output(value, input) {\n if (!value || typeof value !== 'object')\n throw new Error('Invalid data response.');\n const response = value as TransportResponse;\n if (\n !Number.isInteger(response.status) ||\n response.status < 100 ||\n response.status > 599 ||\n !response.body ||\n typeof response.body !== 'object'\n )\n throw new Error('Invalid data response.');\n const body = response.body as DataQueryBody<unknown> & {\n error?: { code?: unknown; message?: unknown; requestId?: unknown };\n };\n if (response.status < 200 || response.status >= 300) {\n const failure = body.error;\n throw new MessageRoutingError(\n typeof failure?.code === 'string' ? failure.code : 'request_failed',\n typeof failure?.message === 'string'\n ? failure.message\n : 'Could not load data.',\n typeof failure?.requestId === 'string' ? failure.requestId : undefined\n );\n }\n if (\n !('data' in body) ||\n typeof body.requestId !== 'string' ||\n typeof body.queriedAt !== 'string' ||\n !Array.isArray(body.queryIds) ||\n !body.queryIds.every(id => typeof id === 'string')\n )\n throw new Error('Invalid data envelope.');\n if (\n body.queries !== undefined &&\n (!Array.isArray(body.queries) ||\n !body.queries.every(\n query =>\n query &&\n typeof query === 'object' &&\n typeof query.name === 'string' &&\n typeof query.statement === 'string' &&\n (query.queryId === undefined || typeof query.queryId === 'string')\n ))\n )\n throw new Error('Invalid query evidence.');\n const operation = operations?.[input.operation];\n\n return {\n status: response.status,\n body: {\n ...body,\n data: operation ? operation.output(body.data) : body.data,\n },\n };\n },\n };\n}\n\nexport type NavigationUpdate = {\n search: string;\n hash: string;\n mode: 'push' | 'replace';\n title?: string;\n};\nexport const navigationUpdateRoute = /* @__PURE__ */ defineMessageRoute({\n input(value: unknown): NavigationUpdate {\n if (!value || typeof value !== 'object')\n throw new Error('Invalid navigation.');\n const input = value as NavigationUpdate;\n if (\n typeof input.search !== 'string' ||\n input.search.length > 16_384 ||\n (input.search !== '' && !input.search.startsWith('?')) ||\n typeof input.hash !== 'string' ||\n input.hash.length > 4096 ||\n (input.hash !== '' && !input.hash.startsWith('#')) ||\n (input.mode !== 'push' && input.mode !== 'replace') ||\n (input.title !== undefined &&\n (typeof input.title !== 'string' || input.title.length > 512))\n )\n throw new Error('Invalid navigation.');\n\n return {\n search: input.search,\n hash: input.hash,\n mode: input.mode,\n ...(input.title === undefined ? {} : { title: input.title }),\n };\n },\n output(value: unknown): null {\n if (value !== null) throw new Error('Invalid navigation response.');\n\n return null;\n },\n});\nexport const dataAppRoutes = {\n 'data
|
|
5
|
+
"import type { TransportResponse } from '@/src/core/bridge';\nimport type { DisclosedQuery } from '@/src/core/contract';\n\nexport type MessageContext = { signal: AbortSignal };\nexport type RoutedMessage = { route: string; payload: unknown };\nexport type MessageDispatcher = (\n message: unknown,\n context: MessageContext\n) => Promise<unknown>;\nexport type MessageTransport = (\n message: RoutedMessage,\n signal?: AbortSignal\n) => Promise<unknown>;\nexport type MessageRoute<Input, Output> = {\n input: (value: unknown) => Input;\n output: (value: unknown, input: Input) => Output;\n};\nexport type MessageRoutes = Record<\n string,\n {\n input: (value: unknown) => unknown;\n output: (value: unknown, input: never) => unknown;\n }\n>;\nexport type MessageInput<Route extends MessageRoutes[string]> = ReturnType<\n Route['input']\n>;\nexport type MessageHandlers<Routes extends MessageRoutes> = {\n [Name in keyof Routes]: (\n payload: MessageInput<Routes[Name]>,\n context: MessageContext\n ) =>\n | ReturnType<Routes[Name]['output']>\n | Promise<ReturnType<Routes[Name]['output']>>;\n};\n\n// A bootstrap and its app may bundle independent copies in the same window.\nconst errorBrand = Symbol.for('@altertable/data-app/MessageRoutingError');\n\n/** Only these deliberate, public failures cross the message boundary. Other errors stay private. */\nexport class MessageRoutingError extends Error {\n readonly [errorBrand] = true;\n\n static [Symbol.hasInstance](value: unknown): boolean {\n return (\n value instanceof Error &&\n (value as { [errorBrand]?: unknown })[errorBrand] === true\n );\n }\n\n constructor(\n public readonly code: string,\n message: string,\n public readonly requestId?: string\n ) {\n super(message);\n this.name = 'MessageRoutingError';\n }\n}\n\nexport function defineMessageRoute<Input, Output>(\n route: MessageRoute<Input, Output>\n): MessageRoute<Input, Output> {\n return route;\n}\n\n/** Contracts are shared; handlers are supplied by the host and never belong in the app bundle. */\nexport function createMessageRouter<const Routes extends MessageRoutes>(\n routes: Routes,\n handlers: MessageHandlers<NoInfer<Routes>>\n) {\n const registered = new Map(\n Object.entries(routes).map(([name, contract]) => {\n const handler = handlers[name];\n if (!name || name.length > 256 || typeof handler !== 'function')\n throw new Error(\n 'Each message route requires a handler and a bounded name.'\n );\n\n return [name, { contract, handler }] as const;\n })\n );\n\n async function dispatch(\n value: unknown,\n context: MessageContext\n ): Promise<unknown> {\n if (\n !value ||\n typeof value !== 'object' ||\n typeof (value as RoutedMessage).route !== 'string'\n )\n throw new MessageRoutingError(\n 'invalid_message',\n 'Invalid routed message.'\n );\n const message = value as RoutedMessage;\n const entry = registered.get(message.route);\n if (!entry)\n throw new MessageRoutingError('unknown_route', 'Unknown message route.');\n let payload: unknown;\n try {\n payload = entry.contract.input(message.payload);\n } catch {\n throw new MessageRoutingError(\n 'invalid_payload',\n 'Invalid message payload.'\n );\n }\n context.signal.throwIfAborted();\n let result: unknown;\n try {\n result = await entry.handler(payload as never, context);\n } catch (error) {\n if (context.signal.aborted) throw context.signal.reason;\n if (error instanceof MessageRoutingError) throw error;\n throw new MessageRoutingError(\n 'request_failed',\n 'The message request failed. Retry the request.'\n );\n }\n context.signal.throwIfAborted();\n try {\n return entry.contract.output(result, payload as never);\n } catch (error) {\n if (error instanceof MessageRoutingError) throw error;\n throw new MessageRoutingError(\n 'invalid_response',\n 'Invalid message response.'\n );\n }\n }\n\n return { dispatch };\n}\n\nexport type OperationContracts = Record<\n string,\n {\n input: (value: unknown) => unknown;\n output: (value: unknown) => unknown;\n }\n>;\nexport type DataQueryInput<Operations extends OperationContracts> = {\n [Name in keyof Operations & string]: {\n operation: Name;\n input: ReturnType<Operations[Name]['input']>;\n };\n}[keyof Operations & string];\nexport type DataQueryBody<Output> = {\n data: Output;\n requestId: string;\n queriedAt: string;\n queryIds: string[];\n queries?: DisclosedQuery[];\n};\nexport type DataQueryRoute<Operations extends OperationContracts> =\n MessageRoute<DataQueryInput<Operations>, TransportResponse> & {\n operations: Operations | undefined;\n };\nexport type MessageOutput<Route extends MessageRoutes[string], Input> =\n Route extends DataQueryRoute<infer Operations>\n ? Input extends { operation: infer Name extends keyof Operations }\n ? {\n status: number;\n body: DataQueryBody<ReturnType<Operations[Name]['output']>>;\n }\n : never\n : ReturnType<Route['output']>;\n\n/** Omit contracts only in generic hosts such as the CLI shell, where Bun validates operations. */\nexport function defineDataQueryRoute<\n Operations extends OperationContracts = OperationContracts,\n>(operations?: Operations): DataQueryRoute<Operations> {\n return {\n operations,\n input(value) {\n if (!value || typeof value !== 'object')\n throw new Error('Invalid query.');\n const request = value as { operation?: unknown; input?: unknown };\n if (\n typeof request.operation !== 'string' ||\n !request.operation ||\n request.operation.length > 256 ||\n request.operation.includes('/')\n )\n throw new Error('Invalid operation.');\n const operation =\n operations && Object.hasOwn(operations, request.operation)\n ? operations[request.operation]\n : undefined;\n if (operations && !operation) throw new Error('Unknown operation.');\n\n return {\n operation: request.operation,\n input: operation ? operation.input(request.input) : request.input,\n } as DataQueryInput<Operations>;\n },\n output(value, input) {\n if (!value || typeof value !== 'object')\n throw new Error('Invalid data response.');\n const response = value as TransportResponse;\n if (\n !Number.isInteger(response.status) ||\n response.status < 100 ||\n response.status > 599 ||\n !response.body ||\n typeof response.body !== 'object'\n )\n throw new Error('Invalid data response.');\n const body = response.body as DataQueryBody<unknown> & {\n error?: { code?: unknown; message?: unknown; requestId?: unknown };\n };\n if (response.status < 200 || response.status >= 300) {\n const failure = body.error;\n throw new MessageRoutingError(\n typeof failure?.code === 'string' ? failure.code : 'request_failed',\n typeof failure?.message === 'string'\n ? failure.message\n : 'Could not load data.',\n typeof failure?.requestId === 'string' ? failure.requestId : undefined\n );\n }\n if (\n !('data' in body) ||\n typeof body.requestId !== 'string' ||\n typeof body.queriedAt !== 'string' ||\n !Array.isArray(body.queryIds) ||\n !body.queryIds.every(id => typeof id === 'string')\n )\n throw new Error('Invalid data envelope.');\n if (\n body.queries !== undefined &&\n (!Array.isArray(body.queries) ||\n !body.queries.every(\n query =>\n query &&\n typeof query === 'object' &&\n typeof query.name === 'string' &&\n typeof query.statement === 'string' &&\n (query.queryId === undefined || typeof query.queryId === 'string')\n ))\n )\n throw new Error('Invalid query evidence.');\n const operation = operations?.[input.operation];\n\n return {\n status: response.status,\n body: {\n ...body,\n data: operation ? operation.output(body.data) : body.data,\n },\n };\n },\n };\n}\n\nexport type NavigationUpdate = {\n search: string;\n hash: string;\n mode: 'push' | 'replace';\n title?: string;\n};\nexport const navigationUpdateRoute = /* @__PURE__ */ defineMessageRoute({\n input(value: unknown): NavigationUpdate {\n if (!value || typeof value !== 'object')\n throw new Error('Invalid navigation.');\n const input = value as NavigationUpdate;\n if (\n typeof input.search !== 'string' ||\n input.search.length > 16_384 ||\n (input.search !== '' && !input.search.startsWith('?')) ||\n typeof input.hash !== 'string' ||\n input.hash.length > 4096 ||\n (input.hash !== '' && !input.hash.startsWith('#')) ||\n (input.mode !== 'push' && input.mode !== 'replace') ||\n (input.title !== undefined &&\n (typeof input.title !== 'string' || input.title.length > 512))\n )\n throw new Error('Invalid navigation.');\n\n return {\n search: input.search,\n hash: input.hash,\n mode: input.mode,\n ...(input.title === undefined ? {} : { title: input.title }),\n };\n },\n output(value: unknown): null {\n if (value !== null) throw new Error('Invalid navigation response.');\n\n return null;\n },\n});\nexport const dataAppRoutes = {\n 'data:query': /* @__PURE__ */ defineDataQueryRoute(),\n 'navigation:update': navigationUpdateRoute,\n};\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAqCA,IAAM,aAAa,OAAO,IAAI,0CAA0C;AAAA;AAGjE,MAAM,6BAA4B,MAAM;AAAA,EAW3B;AAAA,EAEA;AAAA,GAZR,cAAc;AAAA,UAEhB,OAAO,YAAY,CAAC,OAAyB;AAAA,IACnD,OACE,iBAAiB,SAChB,MAAqC,gBAAgB;AAAA;AAAA,EAI1D,WAAW,CACO,MAChB,SACgB,WAChB;AAAA,IACA,MAAM,OAAO;AAAA,IAJG;AAAA,IAEA;AAAA,IAGhB,KAAK,OAAO;AAAA;AAEhB;AAEO,SAAS,mBAAiC,CAC/C,OAC6B;AAAA,EAC7B,OAAO;AAAA;AAIF,SAAS,oBAAuD,CACrE,QACA,UACA;AAAA,EACA,MAAM,aAAa,IAAI,IACrB,OAAO,QAAQ,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc;AAAA,IAC/C,MAAM,UAAU,SAAS;AAAA,IACzB,IAAI,CAAC,QAAQ,KAAK,SAAS,OAAO,OAAO,YAAY;AAAA,MACnD,MAAM,IAAI,MACR,2DACF;AAAA,IAEF,OAAO,CAAC,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,GACpC,CACH;AAAA,EAEA,eAAe,QAAQ,CACrB,OACA,SACkB;AAAA,IAClB,IACE,CAAC,SACD,OAAO,UAAU,YACjB,OAAQ,MAAwB,UAAU;AAAA,MAE1C,MAAM,IAAI,qBACR,mBACA,yBACF;AAAA,IACF,MAAM,UAAU;AAAA,IAChB,MAAM,QAAQ,WAAW,IAAI,QAAQ,KAAK;AAAA,IAC1C,IAAI,CAAC;AAAA,MACH,MAAM,IAAI,qBAAoB,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