@altertable/data-app 0.71.0 → 0.73.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/AGENTS.md +5 -61
- package/CONTRIBUTING.md +93 -173
- package/README.md +3 -3
- package/REFERENCE.md +30 -341
- package/dist/chunks/contract-BeLPJwlO.js +558 -0
- package/dist/chunks/contract-BeLPJwlO.js.map +1 -0
- package/dist/chunks/contract-Di8SP74I.js +462 -0
- package/dist/chunks/contract-Di8SP74I.js.map +1 -0
- package/dist/chunks/format-BdFlv_xa.js +148 -0
- package/dist/chunks/format-BdFlv_xa.js.map +1 -0
- package/dist/chunks/iframe-C3uCZEXh.js +809 -0
- package/dist/chunks/iframe-C3uCZEXh.js.map +1 -0
- package/dist/chunks/operation-CBxhjNhK.js +131 -0
- package/dist/chunks/operation-CBxhjNhK.js.map +1 -0
- package/dist/chunks/request-body-H1qPmmTN.js +50 -0
- package/dist/chunks/request-body-H1qPmmTN.js.map +1 -0
- package/dist/client/index.js +253 -285
- package/dist/client/index.js.map +1 -13
- package/dist/core/appearance.js +171 -162
- package/dist/core/appearance.js.map +1 -10
- package/dist/core/config.js +49 -11
- package/dist/core/config.js.map +1 -9
- package/dist/core/contract.js +3 -73
- package/dist/core/format.js +1 -26
- package/dist/index.js +1 -12
- package/dist/internal.js +352 -397
- package/dist/internal.js.map +1 -15
- package/dist/server/index.js +85 -97
- package/dist/server/index.js.map +1 -10
- package/dist/types/chunks/appearance.d.ts +45 -0
- package/dist/types/chunks/contract.d.ts +720 -0
- package/dist/types/chunks/index.d.ts +189 -0
- package/dist/types/client/index.d.ts +3 -13
- package/dist/types/core/appearance.d.ts +2 -42
- package/dist/types/core/config.d.ts +44 -48
- package/dist/types/core/contract.d.ts +2 -114
- package/dist/types/core/format.d.ts +44 -17
- package/dist/types/index.d.ts +3 -3
- package/dist/types/internal.d.ts +312 -22
- package/dist/types/server/index.d.ts +15 -4
- package/docs/app-authoring.md +72 -112
- package/docs/client.md +29 -63
- package/docs/composition.md +44 -75
- package/docs/contract.md +60 -100
- package/docs/data-context.md +35 -61
- package/docs/embed.md +83 -55
- package/docs/formatting-and-appearance.md +17 -38
- package/docs/hosted-apps.md +12 -15
- package/docs/layout.md +30 -47
- package/docs/local-data-apps.md +7 -7
- package/docs/react-embed.md +20 -26
- package/docs/react.md +10 -27
- package/docs/server-bun.md +3 -28
- package/docs/server.md +6 -12
- package/docs/stories-and-export.md +38 -40
- package/docs/styling.md +14 -22
- package/docs/ui-quality.md +5 -5
- package/docs/ui.md +68 -70
- package/docs/variables.md +142 -254
- package/docs/views.md +85 -116
- package/docs/widgets.md +100 -153
- package/docs/worker.md +15 -27
- package/package.json +3 -3
- package/dist/chunks/index-5a27erdg.js +0 -54
- package/dist/chunks/index-5a27erdg.js.map +0 -10
- package/dist/chunks/index-9yxr7nmm.js +0 -742
- package/dist/chunks/index-9yxr7nmm.js.map +0 -17
- package/dist/chunks/index-j5q5n3ra.js +0 -151
- package/dist/chunks/index-j5q5n3ra.js.map +0 -10
- package/dist/chunks/index-q75zm3a7.js +0 -153
- package/dist/chunks/index-q75zm3a7.js.map +0 -11
- package/dist/chunks/index-vhaec7m5.js +0 -30
- package/dist/chunks/index-vhaec7m5.js.map +0 -10
- package/dist/chunks/index-zp78caex.js +0 -1047
- package/dist/chunks/index-zp78caex.js.map +0 -19
- package/dist/core/contract.js.map +0 -9
- package/dist/core/format.js.map +0 -9
- package/dist/index.js.map +0 -9
- package/dist/types/client/annotations.d.ts +0 -27
- package/dist/types/client/data-client.d.ts +0 -43
- package/dist/types/client/download.d.ts +0 -5
- package/dist/types/client/iframe.d.ts +0 -59
- package/dist/types/client/location.d.ts +0 -13
- package/dist/types/client/logger.d.ts +0 -14
- package/dist/types/client/messages.d.ts +0 -7
- package/dist/types/client/navigation.d.ts +0 -15
- package/dist/types/client/transport.d.ts +0 -15
- package/dist/types/core/annotations.d.ts +0 -99
- package/dist/types/core/bridge-endpoint.d.ts +0 -21
- package/dist/types/core/bridge.d.ts +0 -172
- package/dist/types/core/data-view.d.ts +0 -46
- package/dist/types/core/date-format.d.ts +0 -24
- package/dist/types/core/date-range.d.ts +0 -20
- package/dist/types/core/dimension-source.d.ts +0 -64
- package/dist/types/core/dimension.d.ts +0 -71
- package/dist/types/core/facets.d.ts +0 -13
- package/dist/types/core/filters.d.ts +0 -45
- package/dist/types/core/invariant.d.ts +0 -2
- package/dist/types/core/keys.d.ts +0 -2
- package/dist/types/core/logger.d.ts +0 -12
- package/dist/types/core/messages.d.ts +0 -62
- package/dist/types/core/navigation.d.ts +0 -11
- package/dist/types/core/operation-types.d.ts +0 -80
- package/dist/types/core/operation.d.ts +0 -20
- package/dist/types/core/presentation.d.ts +0 -9
- package/dist/types/core/queries.d.ts +0 -84
- package/dist/types/core/reading.d.ts +0 -17
- package/dist/types/core/uuid.d.ts +0 -2
- package/dist/types/core/variables.d.ts +0 -133
- package/dist/types/server/handler.d.ts +0 -13
- package/dist/types/server/request-body.d.ts +0 -4
- package/examples/starter-data-app/index.tsx +0 -193
- package/examples/starter-local-data-app/.bun-version +0 -1
- package/examples/starter-local-data-app/.node-version +0 -1
- package/examples/starter-local-data-app/.oxfmtrc.json +0 -4
- package/examples/starter-local-data-app/.oxlintrc.json +0 -33
- package/examples/starter-local-data-app/AGENTS.md +0 -22
- package/examples/starter-local-data-app/README.md +0 -56
- package/examples/starter-local-data-app/app.ts +0 -28
- package/examples/starter-local-data-app/bunfig.toml +0 -2
- package/examples/starter-local-data-app/package.json +0 -35
- package/examples/starter-local-data-app/src/App.tsx +0 -8
- package/examples/starter-local-data-app/src/assets.d.ts +0 -1
- package/examples/starter-local-data-app/src/data-context.ts +0 -21
- package/examples/starter-local-data-app/src/favicon.svg +0 -13
- package/examples/starter-local-data-app/src/index.html +0 -14
- package/examples/starter-local-data-app/src/main.tsx +0 -7
- package/examples/starter-local-data-app/src/operations.ts +0 -6
- package/examples/starter-local-data-app/src/server.ts +0 -6
- package/examples/starter-local-data-app/tsconfig.json +0 -21
|
@@ -0,0 +1,809 @@
|
|
|
1
|
+
import { f as defineDataQueryRoute, h as sqlQueryRoute, l as MessageRoutingError, s as isAnnotationPresentation } from "./contract-Di8SP74I.js";
|
|
2
|
+
//#region src/core/uuid.ts
|
|
3
|
+
/** Opaque documents can lack randomUUID even when cryptographic randomness is available. */
|
|
4
|
+
function randomUuid() {
|
|
5
|
+
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
6
|
+
const bytes = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
7
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
8
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
9
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
|
10
|
+
return [
|
|
11
|
+
hex.slice(0, 4),
|
|
12
|
+
hex.slice(4, 6),
|
|
13
|
+
hex.slice(6, 8),
|
|
14
|
+
hex.slice(8, 10),
|
|
15
|
+
hex.slice(10)
|
|
16
|
+
].map((part) => part.join("")).join("-");
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/core/logger.ts
|
|
20
|
+
function isLogEntry(value) {
|
|
21
|
+
if (!value || typeof value !== "object") return false;
|
|
22
|
+
const entry = value;
|
|
23
|
+
return (entry.method === "log" || entry.method === "info" || entry.method === "warn" || entry.method === "error") && Array.isArray(entry.args) && entry.args.length <= 128;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/core/bridge.ts
|
|
27
|
+
/** Data app delivery protocol. IDs identify a document, a shell session, and an individual call. */
|
|
28
|
+
const BRIDGE = "altertable:data-app";
|
|
29
|
+
const PARENT_PARAM = "__altertable_parent";
|
|
30
|
+
/** Bound pending requests in the client and host independently.
|
|
31
|
+
* The host enforces its own limit because frames can send messages directly. */
|
|
32
|
+
const MAX_PENDING = 128;
|
|
33
|
+
const REQUEST_TIMEOUT_MS = 6e4;
|
|
34
|
+
function validId(value) {
|
|
35
|
+
return typeof value === "string" && /^[a-zA-Z0-9_-]{1,128}$/.test(value);
|
|
36
|
+
}
|
|
37
|
+
function event({ wire, from, session, parse }) {
|
|
38
|
+
return {
|
|
39
|
+
wire,
|
|
40
|
+
from,
|
|
41
|
+
session,
|
|
42
|
+
parse
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function id(fields) {
|
|
46
|
+
if (!validId(fields.id)) throw new Error("Invalid request ID.");
|
|
47
|
+
return fields.id;
|
|
48
|
+
}
|
|
49
|
+
function string(fields, key) {
|
|
50
|
+
const value = fields[key];
|
|
51
|
+
if (typeof value !== "string") throw new Error(`Invalid ${key}.`);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
function length(fields, key) {
|
|
55
|
+
const value = fields[key];
|
|
56
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw new Error(`Invalid ${key}.`);
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
function empty() {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
/** Parsers project known fields; opaque values are validated by their owning route or adapter. */
|
|
63
|
+
const bridgeProtocol = {
|
|
64
|
+
channel: BRIDGE,
|
|
65
|
+
version: 1,
|
|
66
|
+
events: {
|
|
67
|
+
connect: event({
|
|
68
|
+
wire: "bridge:connect",
|
|
69
|
+
from: "host",
|
|
70
|
+
session: "none",
|
|
71
|
+
parse: empty
|
|
72
|
+
}),
|
|
73
|
+
ready: event({
|
|
74
|
+
wire: "bridge:ready",
|
|
75
|
+
from: "app",
|
|
76
|
+
session: "none",
|
|
77
|
+
parse: empty
|
|
78
|
+
}),
|
|
79
|
+
initialize: event({
|
|
80
|
+
wire: "bridge:initialize",
|
|
81
|
+
from: "host",
|
|
82
|
+
session: "establish",
|
|
83
|
+
parse: (fields) => ({ state: fields.state })
|
|
84
|
+
}),
|
|
85
|
+
request: event({
|
|
86
|
+
wire: "bridge:request",
|
|
87
|
+
from: "app",
|
|
88
|
+
session: "current",
|
|
89
|
+
parse: (fields) => {
|
|
90
|
+
const route = string(fields, "route");
|
|
91
|
+
if (!route || route.length > 256) throw new Error("Invalid message route.");
|
|
92
|
+
return {
|
|
93
|
+
id: id(fields),
|
|
94
|
+
route,
|
|
95
|
+
payload: fields.payload
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
result: event({
|
|
100
|
+
wire: "bridge:result",
|
|
101
|
+
from: "host",
|
|
102
|
+
session: "current",
|
|
103
|
+
parse: (fields) => {
|
|
104
|
+
if (!Object.hasOwn(fields, "response")) throw new Error("Missing response.");
|
|
105
|
+
return {
|
|
106
|
+
id: id(fields),
|
|
107
|
+
response: fields.response
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
error: event({
|
|
112
|
+
wire: "bridge:error",
|
|
113
|
+
from: "host",
|
|
114
|
+
session: "current",
|
|
115
|
+
parse: (fields) => {
|
|
116
|
+
if (fields.requestId !== void 0 && typeof fields.requestId !== "string") throw new Error("Invalid requestId.");
|
|
117
|
+
return {
|
|
118
|
+
id: id(fields),
|
|
119
|
+
code: string(fields, "code"),
|
|
120
|
+
message: string(fields, "message"),
|
|
121
|
+
...fields.requestId === void 0 ? {} : { requestId: fields.requestId }
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
cancel: event({
|
|
126
|
+
wire: "bridge:cancel",
|
|
127
|
+
from: "app",
|
|
128
|
+
session: "current",
|
|
129
|
+
parse: (fields) => ({ id: id(fields) })
|
|
130
|
+
}),
|
|
131
|
+
disconnect: event({
|
|
132
|
+
wire: "bridge:disconnect",
|
|
133
|
+
from: "app",
|
|
134
|
+
session: "current",
|
|
135
|
+
parse: empty
|
|
136
|
+
}),
|
|
137
|
+
scriptLoad: event({
|
|
138
|
+
wire: "script:load",
|
|
139
|
+
from: "host",
|
|
140
|
+
session: "current",
|
|
141
|
+
parse: (fields) => ({ javascript: string(fields, "javascript") })
|
|
142
|
+
}),
|
|
143
|
+
stateUpdate: event({
|
|
144
|
+
wire: "state:update",
|
|
145
|
+
from: "host",
|
|
146
|
+
session: "current",
|
|
147
|
+
parse: (fields) => ({ state: fields.state })
|
|
148
|
+
}),
|
|
149
|
+
runtimeLog: event({
|
|
150
|
+
wire: "runtime:log",
|
|
151
|
+
from: "app",
|
|
152
|
+
session: "current",
|
|
153
|
+
parse: (fields) => {
|
|
154
|
+
if (!isLogEntry(fields.payload)) throw new Error("Invalid log entry.");
|
|
155
|
+
return { payload: fields.payload };
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
158
|
+
runtimeReady: event({
|
|
159
|
+
wire: "runtime:ready",
|
|
160
|
+
from: "app",
|
|
161
|
+
session: "current",
|
|
162
|
+
parse: empty
|
|
163
|
+
}),
|
|
164
|
+
runtimeError: event({
|
|
165
|
+
wire: "runtime:error",
|
|
166
|
+
from: "app",
|
|
167
|
+
session: "current",
|
|
168
|
+
parse: empty
|
|
169
|
+
}),
|
|
170
|
+
/** Content height in CSS pixels; hosts apply it only to content-sized frames. */
|
|
171
|
+
runtimeResize: event({
|
|
172
|
+
wire: "runtime:resize",
|
|
173
|
+
from: "app",
|
|
174
|
+
session: "current",
|
|
175
|
+
parse: (fields) => ({ height: length(fields, "height") })
|
|
176
|
+
}),
|
|
177
|
+
/** CSS pixels of a content-sized frame hidden above and below the parent's visible area. */
|
|
178
|
+
viewportUpdate: event({
|
|
179
|
+
wire: "viewport:update",
|
|
180
|
+
from: "host",
|
|
181
|
+
session: "current",
|
|
182
|
+
parse: (fields) => ({
|
|
183
|
+
top: length(fields, "top"),
|
|
184
|
+
bottom: length(fields, "bottom")
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
function bridgeMessageMetadata(message) {
|
|
190
|
+
const metadata = { type: message.type };
|
|
191
|
+
if ("id" in message) metadata.id = message.id;
|
|
192
|
+
if (message.type === "bridge:request") {
|
|
193
|
+
metadata.route = message.route;
|
|
194
|
+
const payload = message.payload;
|
|
195
|
+
if (message.route === "data:query" && payload && typeof payload === "object" && "operation" in payload && typeof payload.operation === "string") metadata.operation = payload.operation.slice(0, 256);
|
|
196
|
+
}
|
|
197
|
+
if (message.type === "bridge:error") metadata.error = {
|
|
198
|
+
code: message.code,
|
|
199
|
+
message: message.message,
|
|
200
|
+
...message.requestId === void 0 ? {} : { requestId: message.requestId }
|
|
201
|
+
};
|
|
202
|
+
return metadata;
|
|
203
|
+
}
|
|
204
|
+
const byWire = /* @__PURE__ */ new Map();
|
|
205
|
+
for (const name of Object.keys(bridgeProtocol.events)) {
|
|
206
|
+
const wire = bridgeProtocol.events[name].wire;
|
|
207
|
+
if (byWire.has(wire)) throw new Error(`Duplicate bridge event: ${wire}`);
|
|
208
|
+
byWire.set(wire, name);
|
|
209
|
+
}
|
|
210
|
+
function bridgeEventName(wire) {
|
|
211
|
+
return byWire.get(wire);
|
|
212
|
+
}
|
|
213
|
+
/** Envelope parsing precedes authentication; event-specific fields remain untrusted. */
|
|
214
|
+
function parseBridgeEnvelope(value) {
|
|
215
|
+
if (!value || typeof value !== "object") return;
|
|
216
|
+
const fields = value;
|
|
217
|
+
if (fields.channel !== BRIDGE || fields.version !== bridgeProtocol.version || typeof fields.type !== "string" || typeof fields.documentId !== "string" || !fields.documentId || fields.documentId.length > 128 || fields.sessionId !== void 0 && !validId(fields.sessionId) || fields.token !== void 0 && typeof fields.token !== "string") return;
|
|
218
|
+
return fields;
|
|
219
|
+
}
|
|
220
|
+
/** Project event fields after the caller has checked envelope eligibility. */
|
|
221
|
+
function parseBridgePayload(envelope, definition) {
|
|
222
|
+
try {
|
|
223
|
+
return {
|
|
224
|
+
channel: BRIDGE,
|
|
225
|
+
version: bridgeProtocol.version,
|
|
226
|
+
documentId: envelope.documentId,
|
|
227
|
+
...envelope.sessionId === void 0 ? {} : { sessionId: envelope.sessionId },
|
|
228
|
+
...envelope.token === void 0 ? {} : { token: envelope.token },
|
|
229
|
+
type: definition.wire,
|
|
230
|
+
...definition.parse(envelope)
|
|
231
|
+
};
|
|
232
|
+
} catch {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function parseBridgeMessage(value) {
|
|
237
|
+
const envelope = parseBridgeEnvelope(value);
|
|
238
|
+
if (!envelope) return;
|
|
239
|
+
const name = bridgeEventName(envelope.type);
|
|
240
|
+
if (!name) return;
|
|
241
|
+
const definition = bridgeProtocol.events[name];
|
|
242
|
+
if (definition.session !== "none" && envelope.sessionId === void 0) return;
|
|
243
|
+
return parseBridgePayload(envelope, definition);
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/core/bridge-endpoint.ts
|
|
247
|
+
/** The connection owns IDs and token rotation; callers can only supply event payloads. */
|
|
248
|
+
function createBridgeEndpoint({ role, origin, source, opaque, context, post, diagnostic, invalidRequest, handlers }) {
|
|
249
|
+
let disposed = false;
|
|
250
|
+
function drop(reason, type) {
|
|
251
|
+
diagnostic?.({
|
|
252
|
+
direction: "drop",
|
|
253
|
+
reason,
|
|
254
|
+
...typeof type === "string" ? { type: type.slice(0, 64) } : {}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function send(name, payload) {
|
|
258
|
+
if (disposed) throw new Error("The bridge endpoint has closed.");
|
|
259
|
+
const definition = bridgeProtocol.events[name];
|
|
260
|
+
const current = context();
|
|
261
|
+
const message = parseBridgeMessage({
|
|
262
|
+
...payload,
|
|
263
|
+
channel: bridgeProtocol.channel,
|
|
264
|
+
version: bridgeProtocol.version,
|
|
265
|
+
type: definition.wire,
|
|
266
|
+
documentId: name === "connect" ? "host" : current.documentId,
|
|
267
|
+
sessionId: current.sessionId,
|
|
268
|
+
token: opaque ? current.token : void 0
|
|
269
|
+
});
|
|
270
|
+
if (!message || opaque && !validId(current.token)) throw new Error("The bridge is not ready to send this event.");
|
|
271
|
+
diagnostic?.({
|
|
272
|
+
direction: "send",
|
|
273
|
+
...bridgeMessageMetadata(message)
|
|
274
|
+
});
|
|
275
|
+
if (disposed) return;
|
|
276
|
+
post(message);
|
|
277
|
+
}
|
|
278
|
+
function receive(event) {
|
|
279
|
+
const peer = source();
|
|
280
|
+
if (disposed || !peer || event.origin !== origin || event.source !== peer) return;
|
|
281
|
+
const envelope = parseBridgeEnvelope(event.data);
|
|
282
|
+
if (!envelope) {
|
|
283
|
+
const data = event.data;
|
|
284
|
+
if (data && typeof data === "object" && "channel" in data && data.channel === bridgeProtocol.channel) drop("invalid_envelope", "type" in data ? data.type : void 0);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const current = context();
|
|
288
|
+
const connecting = role === "app" && envelope.type === bridgeProtocol.events.connect.wire;
|
|
289
|
+
if (opaque && (connecting ? !validId(envelope.token) : !current.token || envelope.token !== current.token)) return drop("token_mismatch", envelope.type);
|
|
290
|
+
const name = bridgeEventName(envelope.type);
|
|
291
|
+
if (!name) return drop("unexpected_type", envelope.type);
|
|
292
|
+
const definition = bridgeProtocol.events[name];
|
|
293
|
+
if (definition.from === role) return drop("unexpected_type", envelope.type);
|
|
294
|
+
if (definition.session === "establish") {
|
|
295
|
+
if (envelope.documentId !== current.documentId || envelope.sessionId === void 0) return drop("session_mismatch", envelope.type);
|
|
296
|
+
} else if (definition.session === "current") {
|
|
297
|
+
if (!current.sessionId || envelope.sessionId !== current.sessionId || envelope.documentId !== current.documentId) return drop("session_mismatch", envelope.type);
|
|
298
|
+
}
|
|
299
|
+
const message = parseBridgePayload(envelope, definition);
|
|
300
|
+
if (!message) {
|
|
301
|
+
drop("invalid_payload", envelope.type);
|
|
302
|
+
if (role === "host" && name === "request" && validId(envelope.id)) invalidRequest?.(envelope.id);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
diagnostic?.({
|
|
306
|
+
direction: "receive",
|
|
307
|
+
...bridgeMessageMetadata(message)
|
|
308
|
+
});
|
|
309
|
+
if (disposed) return;
|
|
310
|
+
const handler = handlers[name];
|
|
311
|
+
handler(message);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
send,
|
|
315
|
+
receive,
|
|
316
|
+
dispose() {
|
|
317
|
+
disposed = true;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/core/presentation.ts
|
|
323
|
+
function isDataAppPresentation(value) {
|
|
324
|
+
if (!value || typeof value !== "object") return false;
|
|
325
|
+
const presentation = value;
|
|
326
|
+
return (presentation.surface === "embedded" || presentation.surface === "standalone") && (presentation.theme === "light" || presentation.theme === "dark") && (presentation.annotations === void 0 || isAnnotationPresentation(presentation.annotations)) && (presentation.sizing === void 0 || presentation.sizing === "frame" || presentation.sizing === "content");
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/client/frame-sizing.ts
|
|
330
|
+
/** Reports the document height to a parent that sizes the iframe to its content.
|
|
331
|
+
* Sizing applies only while the parent requests it and a UI owner whose styles support it
|
|
332
|
+
* has opted in, so older app styles under a newer bootstrap stay frame-sized.
|
|
333
|
+
* The root attribute and inset properties let fixed overlays stay within the parent's visible area. */
|
|
334
|
+
function createFrameSizing(document, report) {
|
|
335
|
+
const root = document.documentElement;
|
|
336
|
+
const frame = document.defaultView;
|
|
337
|
+
let observer;
|
|
338
|
+
let reported;
|
|
339
|
+
let requested = false;
|
|
340
|
+
let owners = 0;
|
|
341
|
+
let viewport;
|
|
342
|
+
function measure() {
|
|
343
|
+
const height = Math.ceil(root.getBoundingClientRect().height);
|
|
344
|
+
if (height === reported && height !== frame?.innerHeight) return;
|
|
345
|
+
reported = height;
|
|
346
|
+
report(height);
|
|
347
|
+
}
|
|
348
|
+
function stop() {
|
|
349
|
+
observer?.disconnect();
|
|
350
|
+
observer = void 0;
|
|
351
|
+
frame?.removeEventListener("resize", measure);
|
|
352
|
+
reported = void 0;
|
|
353
|
+
delete root.dataset.atblFrameSizing;
|
|
354
|
+
root.style.removeProperty("--atbl-frame-inset-top");
|
|
355
|
+
root.style.removeProperty("--atbl-frame-inset-bottom");
|
|
356
|
+
}
|
|
357
|
+
function applyViewport() {
|
|
358
|
+
if (!observer || !viewport) return;
|
|
359
|
+
root.style.setProperty("--atbl-frame-inset-top", `${viewport.top}px`);
|
|
360
|
+
root.style.setProperty("--atbl-frame-inset-bottom", `${viewport.bottom}px`);
|
|
361
|
+
}
|
|
362
|
+
function sync() {
|
|
363
|
+
if (!requested || !owners) return stop();
|
|
364
|
+
if (observer) return;
|
|
365
|
+
root.dataset.atblFrameSizing = "content";
|
|
366
|
+
observer = new (document.defaultView ?? globalThis).ResizeObserver(measure);
|
|
367
|
+
observer.observe(root);
|
|
368
|
+
frame?.addEventListener("resize", measure);
|
|
369
|
+
applyViewport();
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
/** A new session starts with a parent that has not received the current height. */
|
|
373
|
+
update(state, session) {
|
|
374
|
+
const presentation = state && typeof state === "object" && "presentation" in state ? state.presentation : void 0;
|
|
375
|
+
requested = isDataAppPresentation(presentation) && presentation.sizing === "content";
|
|
376
|
+
if (!requested) viewport = void 0;
|
|
377
|
+
if (session === "new") reported = void 0;
|
|
378
|
+
if (observer && requested) measure();
|
|
379
|
+
sync();
|
|
380
|
+
},
|
|
381
|
+
support() {
|
|
382
|
+
owners++;
|
|
383
|
+
sync();
|
|
384
|
+
let released = false;
|
|
385
|
+
return () => {
|
|
386
|
+
if (released) return;
|
|
387
|
+
released = true;
|
|
388
|
+
owners--;
|
|
389
|
+
sync();
|
|
390
|
+
};
|
|
391
|
+
},
|
|
392
|
+
viewport(top, bottom) {
|
|
393
|
+
if (!requested) return;
|
|
394
|
+
viewport = {
|
|
395
|
+
top,
|
|
396
|
+
bottom
|
|
397
|
+
};
|
|
398
|
+
applyViewport();
|
|
399
|
+
},
|
|
400
|
+
dispose() {
|
|
401
|
+
requested = false;
|
|
402
|
+
viewport = void 0;
|
|
403
|
+
owners = 0;
|
|
404
|
+
stop();
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/client/logger.ts
|
|
410
|
+
/** Lazy arguments run in the iframe; only resolved values cross the bridge. */
|
|
411
|
+
function createBridgeLogger(enabled, send) {
|
|
412
|
+
function resolve(args) {
|
|
413
|
+
if (args.length === 1 && typeof args[0] === "function") {
|
|
414
|
+
const value = args[0]();
|
|
415
|
+
return Array.isArray(value) ? value : [value];
|
|
416
|
+
}
|
|
417
|
+
return args.map((arg) => typeof arg === "function" ? arg() : arg);
|
|
418
|
+
}
|
|
419
|
+
function write(method, args) {
|
|
420
|
+
if (!enabled()) return;
|
|
421
|
+
try {
|
|
422
|
+
send({
|
|
423
|
+
method,
|
|
424
|
+
args: resolve(args)
|
|
425
|
+
});
|
|
426
|
+
} catch {}
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
log: (...args) => write("log", args),
|
|
430
|
+
info: (...args) => write("info", args),
|
|
431
|
+
warn: (...args) => write("warn", args),
|
|
432
|
+
error: (...args) => write("error", args)
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
const diagnosticLabels = {
|
|
436
|
+
send: "Sending message to parent",
|
|
437
|
+
receive: "Received message from parent",
|
|
438
|
+
drop: "Ignored message from parent"
|
|
439
|
+
};
|
|
440
|
+
/** Log only delivery metadata; payloads and session credentials stay private. */
|
|
441
|
+
function logBridgeDiagnostic(logger, { direction, ...metadata }) {
|
|
442
|
+
if (metadata.type === "runtime:log" || metadata.type === "runtime:resize" || metadata.type === "viewport:update") return;
|
|
443
|
+
logger.log(diagnosticLabels[direction], metadata);
|
|
444
|
+
}
|
|
445
|
+
/** Error instances do not survive every logger, so only their text crosses the bridge. */
|
|
446
|
+
function describeError(error) {
|
|
447
|
+
if (error instanceof Error) return {
|
|
448
|
+
name: error.name,
|
|
449
|
+
message: error.message,
|
|
450
|
+
...error.stack ? { stack: error.stack } : {}
|
|
451
|
+
};
|
|
452
|
+
return { message: String(error) };
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region src/client/messages.ts
|
|
456
|
+
/** Both ends validate using the same contracts; the transport owns delivery and cancellation. */
|
|
457
|
+
function createMessageClient(routes, transport) {
|
|
458
|
+
return { async request(route, payload, { signal } = {}) {
|
|
459
|
+
signal?.throwIfAborted();
|
|
460
|
+
if (!Object.hasOwn(routes, route)) throw new MessageRoutingError("unknown_route", "Unknown message route.");
|
|
461
|
+
const contract = routes[route];
|
|
462
|
+
let input;
|
|
463
|
+
try {
|
|
464
|
+
input = contract.input(payload);
|
|
465
|
+
} catch {
|
|
466
|
+
throw new MessageRoutingError("invalid_payload", "Invalid message payload.");
|
|
467
|
+
}
|
|
468
|
+
const response = await transport({
|
|
469
|
+
route,
|
|
470
|
+
payload: input
|
|
471
|
+
}, signal);
|
|
472
|
+
signal?.throwIfAborted();
|
|
473
|
+
try {
|
|
474
|
+
return contract.output(response, input);
|
|
475
|
+
} catch (error) {
|
|
476
|
+
if (error instanceof MessageRoutingError) throw error;
|
|
477
|
+
throw new MessageRoutingError("invalid_response", "Invalid message response.");
|
|
478
|
+
}
|
|
479
|
+
} };
|
|
480
|
+
}
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region src/client/transport.ts
|
|
483
|
+
const errorBrand = Symbol.for("@altertable/data-app/DataAppError");
|
|
484
|
+
var DataAppError = class extends Error {
|
|
485
|
+
code;
|
|
486
|
+
requestId;
|
|
487
|
+
[errorBrand] = true;
|
|
488
|
+
static [Symbol.hasInstance](value) {
|
|
489
|
+
return value instanceof Error && value[errorBrand] === true;
|
|
490
|
+
}
|
|
491
|
+
constructor(message, code, requestId) {
|
|
492
|
+
super(message);
|
|
493
|
+
this.code = code;
|
|
494
|
+
this.requestId = requestId;
|
|
495
|
+
this.name = "DataAppError";
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
function createHttpTransport({ endpoint = "/api/data", fetch: request = globalThis.fetch } = {}) {
|
|
499
|
+
async function requestData(operation, input, signal) {
|
|
500
|
+
const response = await request(`${endpoint.replace(/\/$/, "")}/${encodeURIComponent(operation)}`, {
|
|
501
|
+
method: "POST",
|
|
502
|
+
headers: { "content-type": "application/json" },
|
|
503
|
+
body: JSON.stringify(input),
|
|
504
|
+
signal
|
|
505
|
+
});
|
|
506
|
+
try {
|
|
507
|
+
return {
|
|
508
|
+
status: response.status,
|
|
509
|
+
body: await response.json()
|
|
510
|
+
};
|
|
511
|
+
} catch (error) {
|
|
512
|
+
if (signal?.aborted) throw error;
|
|
513
|
+
throw new DataAppError(response.ok ? "The data response was invalid." : "Could not load data.", response.ok ? "invalid_response" : "request_failed");
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return requestData;
|
|
517
|
+
}
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/client/iframe.ts
|
|
520
|
+
/** Data clients expose one error type for HTTP and message delivery. */
|
|
521
|
+
function rethrowDataMessageError(error) {
|
|
522
|
+
if (error instanceof MessageRoutingError) throw new DataAppError(error.message, error.code, error.requestId);
|
|
523
|
+
throw error;
|
|
524
|
+
}
|
|
525
|
+
/** One bridge per document, shared by all clients and retained across module hot replacement. */
|
|
526
|
+
function createIframeTransport({ parentOrigin, window: frame = window, timeoutMs = REQUEST_TIMEOUT_MS, mode = "url", loadScript }) {
|
|
527
|
+
if (new URL(parentOrigin).origin !== parentOrigin) throw new Error("Expected an exact parent origin.");
|
|
528
|
+
const documentId = randomUuid();
|
|
529
|
+
let token;
|
|
530
|
+
let sessionId;
|
|
531
|
+
let disposed = false;
|
|
532
|
+
const pending = /* @__PURE__ */ new Map();
|
|
533
|
+
let hostState;
|
|
534
|
+
const stateListeners = /* @__PURE__ */ new Set();
|
|
535
|
+
const logger = createBridgeLogger(() => !disposed && !!sessionId && !!hostState && typeof hostState === "object" && "logging" in hostState && hostState.logging === true, (entry) => send("runtimeLog", { payload: entry }));
|
|
536
|
+
const endpoint = createBridgeEndpoint({
|
|
537
|
+
role: "app",
|
|
538
|
+
origin: parentOrigin,
|
|
539
|
+
source: () => frame.parent,
|
|
540
|
+
opaque: mode === "bundle",
|
|
541
|
+
context: () => ({
|
|
542
|
+
documentId,
|
|
543
|
+
sessionId,
|
|
544
|
+
token
|
|
545
|
+
}),
|
|
546
|
+
post(message) {
|
|
547
|
+
frame.parent.postMessage(message, parentOrigin);
|
|
548
|
+
},
|
|
549
|
+
diagnostic: (event) => logBridgeDiagnostic(logger, event),
|
|
550
|
+
handlers: {
|
|
551
|
+
connect(message) {
|
|
552
|
+
if (mode === "bundle") token = message.token;
|
|
553
|
+
send("ready", {});
|
|
554
|
+
},
|
|
555
|
+
initialize(message) {
|
|
556
|
+
if (sessionId && sessionId !== message.sessionId) {
|
|
557
|
+
if (pending.size) logger.warn("Preview reconnected; rejecting pending requests", { count: pending.size });
|
|
558
|
+
for (const entry of pending.values()) entry.reject(new DataAppError("The preview reconnected. Retry the request.", "bridge_reset"));
|
|
559
|
+
}
|
|
560
|
+
const first = !sessionId;
|
|
561
|
+
sessionId = message.sessionId;
|
|
562
|
+
receiveState(message.state, "new");
|
|
563
|
+
if (first) for (const entry of pending.values()) entry.start();
|
|
564
|
+
if (disposed) return;
|
|
565
|
+
if (mode === "url") send("runtimeReady", {});
|
|
566
|
+
},
|
|
567
|
+
stateUpdate(message) {
|
|
568
|
+
receiveState(message.state, "current");
|
|
569
|
+
},
|
|
570
|
+
viewportUpdate(message) {
|
|
571
|
+
frameSizing.viewport(message.top, message.bottom);
|
|
572
|
+
},
|
|
573
|
+
scriptLoad(message) {
|
|
574
|
+
if (mode === "bundle") loadScript?.(message.javascript);
|
|
575
|
+
},
|
|
576
|
+
result(message) {
|
|
577
|
+
pending.get(message.id)?.resolve(message.response);
|
|
578
|
+
},
|
|
579
|
+
error(message) {
|
|
580
|
+
pending.get(message.id)?.reject(new MessageRoutingError(message.code, message.message, message.requestId));
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
const send = endpoint.send;
|
|
585
|
+
const receive = endpoint.receive;
|
|
586
|
+
const frameSizing = createFrameSizing(frame.document, (height) => {
|
|
587
|
+
if (!disposed && sessionId) send("runtimeResize", { height });
|
|
588
|
+
});
|
|
589
|
+
function receiveState(state, session) {
|
|
590
|
+
hostState = state;
|
|
591
|
+
frameSizing.update(state, session);
|
|
592
|
+
for (const listener of stateListeners) listener(state);
|
|
593
|
+
}
|
|
594
|
+
frame.addEventListener("message", receive);
|
|
595
|
+
function requestMessage(message, signal) {
|
|
596
|
+
return new Promise((resolve, reject) => {
|
|
597
|
+
if (disposed) return reject(new DataAppError("The preview has closed.", "bridge_closed"));
|
|
598
|
+
if (signal?.aborted) return reject(signal.reason);
|
|
599
|
+
if (pending.size >= 128) return reject(new DataAppError("Too many pending data requests.", "bridge_busy"));
|
|
600
|
+
const id = randomUuid();
|
|
601
|
+
let sent = false;
|
|
602
|
+
function cleanup() {
|
|
603
|
+
clearTimeout(timer);
|
|
604
|
+
signal?.removeEventListener("abort", abort);
|
|
605
|
+
pending.delete(id);
|
|
606
|
+
}
|
|
607
|
+
function abort() {
|
|
608
|
+
if (sent) send("cancel", { id });
|
|
609
|
+
cleanup();
|
|
610
|
+
reject(signal?.reason);
|
|
611
|
+
}
|
|
612
|
+
const timer = setTimeout(() => {
|
|
613
|
+
logger.warn("Message request timed out", {
|
|
614
|
+
id,
|
|
615
|
+
route: message.route,
|
|
616
|
+
timeoutMs,
|
|
617
|
+
sent
|
|
618
|
+
});
|
|
619
|
+
if (sent) send("cancel", { id });
|
|
620
|
+
cleanup();
|
|
621
|
+
reject(new DataAppError(sessionId ? "The data request timed out." : "The preview shell is unavailable. Reload the preview.", sessionId ? "timeout" : "bridge_unavailable"));
|
|
622
|
+
}, timeoutMs);
|
|
623
|
+
const entry = {
|
|
624
|
+
start() {
|
|
625
|
+
if (sent) return;
|
|
626
|
+
try {
|
|
627
|
+
send("request", {
|
|
628
|
+
id,
|
|
629
|
+
route: message.route,
|
|
630
|
+
payload: message.payload
|
|
631
|
+
});
|
|
632
|
+
sent = true;
|
|
633
|
+
} catch {
|
|
634
|
+
cleanup();
|
|
635
|
+
reject(new DataAppError("The message payload could not be sent.", "invalid_payload"));
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
resolve(value) {
|
|
639
|
+
cleanup();
|
|
640
|
+
resolve(value);
|
|
641
|
+
},
|
|
642
|
+
reject(error) {
|
|
643
|
+
cleanup();
|
|
644
|
+
reject(error);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
pending.set(id, entry);
|
|
648
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
649
|
+
if (sessionId) entry.start();
|
|
650
|
+
else if (mode === "url" || token) send("ready", {});
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
const messages = createMessageClient({
|
|
654
|
+
"data:query": defineDataQueryRoute(),
|
|
655
|
+
"data:sql": sqlQueryRoute
|
|
656
|
+
}, requestMessage);
|
|
657
|
+
function queryOperation(operation, input, signal) {
|
|
658
|
+
return messages.request("data:query", {
|
|
659
|
+
operation,
|
|
660
|
+
input
|
|
661
|
+
}, { signal }).catch(rethrowDataMessageError);
|
|
662
|
+
}
|
|
663
|
+
function disconnect() {
|
|
664
|
+
if (sessionId) send("disconnect", {});
|
|
665
|
+
sessionId = void 0;
|
|
666
|
+
for (const entry of pending.values()) entry.reject(new DataAppError("The preview has closed.", "bridge_closed"));
|
|
667
|
+
}
|
|
668
|
+
function resume(event) {
|
|
669
|
+
if (event.persisted && (mode === "url" || token)) send("ready", {});
|
|
670
|
+
}
|
|
671
|
+
function dispose() {
|
|
672
|
+
if (disposed) return;
|
|
673
|
+
disconnect();
|
|
674
|
+
disposed = true;
|
|
675
|
+
endpoint.dispose();
|
|
676
|
+
frameSizing.dispose();
|
|
677
|
+
frame.removeEventListener("message", receive);
|
|
678
|
+
frame.removeEventListener("pagehide", disconnect);
|
|
679
|
+
frame.removeEventListener("pageshow", resume);
|
|
680
|
+
stateListeners.clear();
|
|
681
|
+
}
|
|
682
|
+
frame.addEventListener("pagehide", disconnect);
|
|
683
|
+
frame.addEventListener("pageshow", resume);
|
|
684
|
+
if (mode === "url") send("ready", {});
|
|
685
|
+
return {
|
|
686
|
+
logger,
|
|
687
|
+
request: requestMessage,
|
|
688
|
+
transport: queryOperation,
|
|
689
|
+
lakehouse: { queryAll(statement, { limit, signal, params }) {
|
|
690
|
+
return messages.request("data:sql", {
|
|
691
|
+
statement,
|
|
692
|
+
limit,
|
|
693
|
+
...params === void 0 ? {} : { params }
|
|
694
|
+
}, { signal }).catch(rethrowDataMessageError);
|
|
695
|
+
} },
|
|
696
|
+
dispose,
|
|
697
|
+
mode,
|
|
698
|
+
snapshot() {
|
|
699
|
+
return hostState;
|
|
700
|
+
},
|
|
701
|
+
subscribe(listener) {
|
|
702
|
+
stateListeners.add(listener);
|
|
703
|
+
return () => {
|
|
704
|
+
stateListeners.delete(listener);
|
|
705
|
+
};
|
|
706
|
+
},
|
|
707
|
+
ready() {
|
|
708
|
+
if (!disposed && sessionId) send("runtimeReady", {});
|
|
709
|
+
},
|
|
710
|
+
/** The UI owner calls this once its styles support content sizing; the parent's
|
|
711
|
+
* `sizing: 'content'` presentation then applies until the returned release runs. */
|
|
712
|
+
supportContentSizing() {
|
|
713
|
+
return frameSizing.support();
|
|
714
|
+
},
|
|
715
|
+
/** Reports a fatal app failure; the cause reaches the host logger only. */
|
|
716
|
+
fail(cause) {
|
|
717
|
+
if (disposed || !sessionId) return;
|
|
718
|
+
if (cause !== void 0) logger.error(() => ["Data app failed", describeError(cause)]);
|
|
719
|
+
send("runtimeError", {});
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
const bridgeKey = Symbol.for("altertable.localFrameBridge");
|
|
724
|
+
const installedKey = Symbol.for("altertable.installedTransport");
|
|
725
|
+
/** The URL opts into local preview; only same-origin server configuration establishes trust. */
|
|
726
|
+
function localFrameBridge(window) {
|
|
727
|
+
const activeWindow = window ?? (typeof globalThis.window === "undefined" ? void 0 : globalThis.window);
|
|
728
|
+
if (!activeWindow) return void 0;
|
|
729
|
+
const frame = activeWindow;
|
|
730
|
+
if (frame[bridgeKey]) return frame[bridgeKey];
|
|
731
|
+
const parentOrigin = new URL(frame.location.href).searchParams.get("__altertable_parent") ?? "";
|
|
732
|
+
if (!parentOrigin) return void 0;
|
|
733
|
+
async function connect(parentOrigin) {
|
|
734
|
+
try {
|
|
735
|
+
const response = await frame.fetch("/__altertable/parent", { signal: AbortSignal.timeout(5e3) });
|
|
736
|
+
const config = await response.json();
|
|
737
|
+
if (!response.ok || config.origin !== parentOrigin || frame.parent === frame) throw new Error("Invalid local parent configuration.");
|
|
738
|
+
if (frame[installedKey]) return frame[installedKey];
|
|
739
|
+
if (frame[bridgeKey] !== proxy) throw new Error("Preview transport owner changed.");
|
|
740
|
+
const bridge = createIframeTransport({
|
|
741
|
+
parentOrigin,
|
|
742
|
+
window: frame
|
|
743
|
+
});
|
|
744
|
+
frame[bridgeKey] = bridge;
|
|
745
|
+
frame[installedKey] = bridge;
|
|
746
|
+
return bridge;
|
|
747
|
+
} catch {
|
|
748
|
+
throw new DataAppError("The preview shell could not be verified. Open the URL printed by altertable app dev.", "bridge_unavailable");
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
let connection;
|
|
752
|
+
function getConnection() {
|
|
753
|
+
const installed = frame[installedKey];
|
|
754
|
+
if (installed) return Promise.resolve(installed);
|
|
755
|
+
if (!connection) {
|
|
756
|
+
const attempt = connect(parentOrigin);
|
|
757
|
+
connection = attempt;
|
|
758
|
+
attempt.catch(() => {
|
|
759
|
+
if (connection === attempt) connection = void 0;
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
return connection;
|
|
763
|
+
}
|
|
764
|
+
const proxy = {
|
|
765
|
+
async transport(operation, input, signal) {
|
|
766
|
+
signal?.throwIfAborted();
|
|
767
|
+
const attempt = getConnection();
|
|
768
|
+
let abort;
|
|
769
|
+
try {
|
|
770
|
+
const bridge = signal ? await Promise.race([attempt, new Promise((_, reject) => {
|
|
771
|
+
const requestSignal = signal;
|
|
772
|
+
function handleAbort() {
|
|
773
|
+
reject(requestSignal.reason);
|
|
774
|
+
}
|
|
775
|
+
abort = handleAbort;
|
|
776
|
+
requestSignal.addEventListener("abort", handleAbort, { once: true });
|
|
777
|
+
})]) : await attempt;
|
|
778
|
+
signal?.throwIfAborted();
|
|
779
|
+
return bridge.transport(operation, input, signal);
|
|
780
|
+
} finally {
|
|
781
|
+
if (abort) signal?.removeEventListener("abort", abort);
|
|
782
|
+
}
|
|
783
|
+
},
|
|
784
|
+
connect: getConnection
|
|
785
|
+
};
|
|
786
|
+
frame[bridgeKey] = proxy;
|
|
787
|
+
getConnection().catch(() => {});
|
|
788
|
+
return proxy;
|
|
789
|
+
}
|
|
790
|
+
/** Install an explicitly trusted transport for hosted apps and their URL-backed controls. */
|
|
791
|
+
function installDataAppTransport(bridge, frame = window) {
|
|
792
|
+
const target = frame;
|
|
793
|
+
if (target[installedKey]) throw new Error("A data app transport is already installed.");
|
|
794
|
+
target[bridgeKey] = bridge;
|
|
795
|
+
target[installedKey] = bridge;
|
|
796
|
+
return () => {
|
|
797
|
+
if (target[bridgeKey] === bridge) delete target[bridgeKey];
|
|
798
|
+
if (target[installedKey] === bridge) delete target[installedKey];
|
|
799
|
+
bridge.dispose();
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
/** The bootstrap installs this before executing app code. URL apps can install an explicit connection. */
|
|
803
|
+
function getDataAppTransport(frame = window) {
|
|
804
|
+
return frame[installedKey];
|
|
805
|
+
}
|
|
806
|
+
//#endregion
|
|
807
|
+
export { DataAppError as a, isDataAppPresentation as c, PARENT_PARAM as d, REQUEST_TIMEOUT_MS as f, localFrameBridge as i, createBridgeEndpoint as l, randomUuid as m, getDataAppTransport as n, createHttpTransport as o, validId as p, installDataAppTransport as r, createMessageClient as s, createIframeTransport as t, MAX_PENDING as u };
|
|
808
|
+
|
|
809
|
+
//# sourceMappingURL=iframe-C3uCZEXh.js.map
|