@altertable/data-app 0.72.0 → 0.74.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 +130 -181
- package/README.md +3 -4
- package/REFERENCE.md +35 -345
- 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/diagnostics-BTZSlNtW.js +967 -0
- package/dist/chunks/diagnostics-BTZSlNtW.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/operation-CSM9UmO3.js +134 -0
- package/dist/chunks/operation-CSM9UmO3.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 +273 -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 +240 -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 +36 -39
- 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 +77 -128
- 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/diagnostics.md +45 -0
- package/docs/embed.md +86 -55
- package/docs/formatting-and-appearance.md +17 -38
- package/docs/hosted-apps.md +7 -14
- 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 +2 -27
- 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 +93 -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 -2
- 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
|
@@ -1,742 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MessageRoutingError2,
|
|
3
|
-
defineDataQueryRoute2,
|
|
4
|
-
sqlQueryRoute2
|
|
5
|
-
} from "./index-zp78caex.js";
|
|
6
|
-
|
|
7
|
-
// packages/data-app/src/core/uuid.ts
|
|
8
|
-
function randomUuid2() {
|
|
9
|
-
if (typeof crypto.randomUUID === "function")
|
|
10
|
-
return crypto.randomUUID();
|
|
11
|
-
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
12
|
-
bytes[6] = bytes[6] & 15 | 64;
|
|
13
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
14
|
-
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
|
15
|
-
return [
|
|
16
|
-
hex.slice(0, 4),
|
|
17
|
-
hex.slice(4, 6),
|
|
18
|
-
hex.slice(6, 8),
|
|
19
|
-
hex.slice(8, 10),
|
|
20
|
-
hex.slice(10)
|
|
21
|
-
].map((part) => part.join("")).join("-");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// packages/data-app/src/client/transport.ts
|
|
25
|
-
var errorBrand = Symbol.for("@altertable/data-app/DataAppError");
|
|
26
|
-
|
|
27
|
-
class DataAppError2 extends Error {
|
|
28
|
-
code;
|
|
29
|
-
requestId;
|
|
30
|
-
[errorBrand] = true;
|
|
31
|
-
static [Symbol.hasInstance](value) {
|
|
32
|
-
return value instanceof Error && value[errorBrand] === true;
|
|
33
|
-
}
|
|
34
|
-
constructor(message, code, requestId) {
|
|
35
|
-
super(message);
|
|
36
|
-
this.code = code;
|
|
37
|
-
this.requestId = requestId;
|
|
38
|
-
this.name = "DataAppError";
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function createHttpTransport2({
|
|
42
|
-
endpoint = "/api/data",
|
|
43
|
-
fetch: request = globalThis.fetch
|
|
44
|
-
} = {}) {
|
|
45
|
-
async function requestData(operation, input, signal) {
|
|
46
|
-
const response = await request(`${endpoint.replace(/\/$/, "")}/${encodeURIComponent(operation)}`, {
|
|
47
|
-
method: "POST",
|
|
48
|
-
headers: { "content-type": "application/json" },
|
|
49
|
-
body: JSON.stringify(input),
|
|
50
|
-
signal
|
|
51
|
-
});
|
|
52
|
-
try {
|
|
53
|
-
return { status: response.status, body: await response.json() };
|
|
54
|
-
} catch (error) {
|
|
55
|
-
if (signal?.aborted)
|
|
56
|
-
throw error;
|
|
57
|
-
throw new DataAppError2(response.ok ? "The data response was invalid." : "Could not load data.", response.ok ? "invalid_response" : "request_failed");
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return requestData;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// packages/data-app/src/core/logger.ts
|
|
64
|
-
function isLogEntry(value) {
|
|
65
|
-
if (!value || typeof value !== "object")
|
|
66
|
-
return false;
|
|
67
|
-
const entry = value;
|
|
68
|
-
return (entry.method === "log" || entry.method === "info" || entry.method === "warn" || entry.method === "error") && Array.isArray(entry.args) && entry.args.length <= 128;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// packages/data-app/src/core/bridge.ts
|
|
72
|
-
var BRIDGE = "altertable:data-app";
|
|
73
|
-
var PARENT_PARAM2 = "__altertable_parent";
|
|
74
|
-
var MAX_PENDING2 = 128;
|
|
75
|
-
var REQUEST_TIMEOUT_MS2 = 60000;
|
|
76
|
-
function validId2(value) {
|
|
77
|
-
return typeof value === "string" && /^[a-zA-Z0-9_-]{1,128}$/.test(value);
|
|
78
|
-
}
|
|
79
|
-
function event({
|
|
80
|
-
wire,
|
|
81
|
-
from,
|
|
82
|
-
session,
|
|
83
|
-
parse
|
|
84
|
-
}) {
|
|
85
|
-
return { wire, from, session, parse };
|
|
86
|
-
}
|
|
87
|
-
function id(fields) {
|
|
88
|
-
if (!validId2(fields.id))
|
|
89
|
-
throw new Error("Invalid request ID.");
|
|
90
|
-
return fields.id;
|
|
91
|
-
}
|
|
92
|
-
function string(fields, key) {
|
|
93
|
-
const value = fields[key];
|
|
94
|
-
if (typeof value !== "string")
|
|
95
|
-
throw new Error(`Invalid ${key}.`);
|
|
96
|
-
return value;
|
|
97
|
-
}
|
|
98
|
-
function empty() {
|
|
99
|
-
return {};
|
|
100
|
-
}
|
|
101
|
-
var bridgeProtocol = {
|
|
102
|
-
channel: BRIDGE,
|
|
103
|
-
version: 1,
|
|
104
|
-
events: {
|
|
105
|
-
connect: event({
|
|
106
|
-
wire: "bridge:connect",
|
|
107
|
-
from: "host",
|
|
108
|
-
session: "none",
|
|
109
|
-
parse: empty
|
|
110
|
-
}),
|
|
111
|
-
ready: event({
|
|
112
|
-
wire: "bridge:ready",
|
|
113
|
-
from: "app",
|
|
114
|
-
session: "none",
|
|
115
|
-
parse: empty
|
|
116
|
-
}),
|
|
117
|
-
initialize: event({
|
|
118
|
-
wire: "bridge:initialize",
|
|
119
|
-
from: "host",
|
|
120
|
-
session: "establish",
|
|
121
|
-
parse: (fields) => ({ state: fields.state })
|
|
122
|
-
}),
|
|
123
|
-
request: event({
|
|
124
|
-
wire: "bridge:request",
|
|
125
|
-
from: "app",
|
|
126
|
-
session: "current",
|
|
127
|
-
parse: (fields) => {
|
|
128
|
-
const route = string(fields, "route");
|
|
129
|
-
if (!route || route.length > 256)
|
|
130
|
-
throw new Error("Invalid message route.");
|
|
131
|
-
return { id: id(fields), route, payload: fields.payload };
|
|
132
|
-
}
|
|
133
|
-
}),
|
|
134
|
-
result: event({
|
|
135
|
-
wire: "bridge:result",
|
|
136
|
-
from: "host",
|
|
137
|
-
session: "current",
|
|
138
|
-
parse: (fields) => {
|
|
139
|
-
if (!Object.hasOwn(fields, "response"))
|
|
140
|
-
throw new Error("Missing response.");
|
|
141
|
-
return { id: id(fields), response: fields.response };
|
|
142
|
-
}
|
|
143
|
-
}),
|
|
144
|
-
error: event({
|
|
145
|
-
wire: "bridge:error",
|
|
146
|
-
from: "host",
|
|
147
|
-
session: "current",
|
|
148
|
-
parse: (fields) => {
|
|
149
|
-
if (fields.requestId !== undefined && typeof fields.requestId !== "string")
|
|
150
|
-
throw new Error("Invalid requestId.");
|
|
151
|
-
return {
|
|
152
|
-
id: id(fields),
|
|
153
|
-
code: string(fields, "code"),
|
|
154
|
-
message: string(fields, "message"),
|
|
155
|
-
...fields.requestId === undefined ? {} : { requestId: fields.requestId }
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}),
|
|
159
|
-
cancel: event({
|
|
160
|
-
wire: "bridge:cancel",
|
|
161
|
-
from: "app",
|
|
162
|
-
session: "current",
|
|
163
|
-
parse: (fields) => ({ id: id(fields) })
|
|
164
|
-
}),
|
|
165
|
-
disconnect: event({
|
|
166
|
-
wire: "bridge:disconnect",
|
|
167
|
-
from: "app",
|
|
168
|
-
session: "current",
|
|
169
|
-
parse: empty
|
|
170
|
-
}),
|
|
171
|
-
scriptLoad: event({
|
|
172
|
-
wire: "script:load",
|
|
173
|
-
from: "host",
|
|
174
|
-
session: "current",
|
|
175
|
-
parse: (fields) => ({ javascript: string(fields, "javascript") })
|
|
176
|
-
}),
|
|
177
|
-
stateUpdate: event({
|
|
178
|
-
wire: "state:update",
|
|
179
|
-
from: "host",
|
|
180
|
-
session: "current",
|
|
181
|
-
parse: (fields) => ({ state: fields.state })
|
|
182
|
-
}),
|
|
183
|
-
runtimeLog: event({
|
|
184
|
-
wire: "runtime:log",
|
|
185
|
-
from: "app",
|
|
186
|
-
session: "current",
|
|
187
|
-
parse: (fields) => {
|
|
188
|
-
if (!isLogEntry(fields.payload))
|
|
189
|
-
throw new Error("Invalid log entry.");
|
|
190
|
-
return { payload: fields.payload };
|
|
191
|
-
}
|
|
192
|
-
}),
|
|
193
|
-
runtimeReady: event({
|
|
194
|
-
wire: "runtime:ready",
|
|
195
|
-
from: "app",
|
|
196
|
-
session: "current",
|
|
197
|
-
parse: empty
|
|
198
|
-
}),
|
|
199
|
-
runtimeError: event({
|
|
200
|
-
wire: "runtime:error",
|
|
201
|
-
from: "app",
|
|
202
|
-
session: "current",
|
|
203
|
-
parse: empty
|
|
204
|
-
})
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
function bridgeMessageMetadata(message) {
|
|
208
|
-
const metadata = { type: message.type };
|
|
209
|
-
if ("id" in message)
|
|
210
|
-
metadata.id = message.id;
|
|
211
|
-
if (message.type === "bridge:request") {
|
|
212
|
-
metadata.route = message.route;
|
|
213
|
-
const payload = message.payload;
|
|
214
|
-
if (message.route === "data:query" && payload && typeof payload === "object" && "operation" in payload && typeof payload.operation === "string")
|
|
215
|
-
metadata.operation = payload.operation.slice(0, 256);
|
|
216
|
-
}
|
|
217
|
-
if (message.type === "bridge:error")
|
|
218
|
-
metadata.error = {
|
|
219
|
-
code: message.code,
|
|
220
|
-
message: message.message,
|
|
221
|
-
...message.requestId === undefined ? {} : { requestId: message.requestId }
|
|
222
|
-
};
|
|
223
|
-
return metadata;
|
|
224
|
-
}
|
|
225
|
-
var byWire = new Map;
|
|
226
|
-
for (const name of Object.keys(bridgeProtocol.events)) {
|
|
227
|
-
const wire = bridgeProtocol.events[name].wire;
|
|
228
|
-
if (byWire.has(wire))
|
|
229
|
-
throw new Error(`Duplicate bridge event: ${wire}`);
|
|
230
|
-
byWire.set(wire, name);
|
|
231
|
-
}
|
|
232
|
-
function bridgeEventName(wire) {
|
|
233
|
-
return byWire.get(wire);
|
|
234
|
-
}
|
|
235
|
-
function parseBridgeEnvelope(value) {
|
|
236
|
-
if (!value || typeof value !== "object")
|
|
237
|
-
return;
|
|
238
|
-
const fields = value;
|
|
239
|
-
if (fields.channel !== BRIDGE || fields.version !== bridgeProtocol.version || typeof fields.type !== "string" || typeof fields.documentId !== "string" || !fields.documentId || fields.documentId.length > 128 || fields.sessionId !== undefined && !validId2(fields.sessionId) || fields.token !== undefined && typeof fields.token !== "string")
|
|
240
|
-
return;
|
|
241
|
-
return fields;
|
|
242
|
-
}
|
|
243
|
-
function parseBridgePayload(envelope, definition) {
|
|
244
|
-
try {
|
|
245
|
-
return {
|
|
246
|
-
channel: BRIDGE,
|
|
247
|
-
version: bridgeProtocol.version,
|
|
248
|
-
documentId: envelope.documentId,
|
|
249
|
-
...envelope.sessionId === undefined ? {} : { sessionId: envelope.sessionId },
|
|
250
|
-
...envelope.token === undefined ? {} : { token: envelope.token },
|
|
251
|
-
type: definition.wire,
|
|
252
|
-
...definition.parse(envelope)
|
|
253
|
-
};
|
|
254
|
-
} catch {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
function parseBridgeMessage(value) {
|
|
259
|
-
const envelope = parseBridgeEnvelope(value);
|
|
260
|
-
if (!envelope)
|
|
261
|
-
return;
|
|
262
|
-
const name = bridgeEventName(envelope.type);
|
|
263
|
-
if (!name)
|
|
264
|
-
return;
|
|
265
|
-
const definition = bridgeProtocol.events[name];
|
|
266
|
-
if (definition.session !== "none" && envelope.sessionId === undefined)
|
|
267
|
-
return;
|
|
268
|
-
return parseBridgePayload(envelope, definition);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// packages/data-app/src/core/bridge-endpoint.ts
|
|
272
|
-
function createBridgeEndpoint2({
|
|
273
|
-
role,
|
|
274
|
-
origin,
|
|
275
|
-
source,
|
|
276
|
-
opaque,
|
|
277
|
-
context,
|
|
278
|
-
post,
|
|
279
|
-
diagnostic,
|
|
280
|
-
invalidRequest,
|
|
281
|
-
handlers
|
|
282
|
-
}) {
|
|
283
|
-
let disposed = false;
|
|
284
|
-
function drop(reason, type) {
|
|
285
|
-
diagnostic?.({
|
|
286
|
-
direction: "drop",
|
|
287
|
-
reason,
|
|
288
|
-
...typeof type === "string" ? { type: type.slice(0, 64) } : {}
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
function send(name, payload) {
|
|
292
|
-
if (disposed)
|
|
293
|
-
throw new Error("The bridge endpoint has closed.");
|
|
294
|
-
const definition = bridgeProtocol.events[name];
|
|
295
|
-
const current = context();
|
|
296
|
-
const message = parseBridgeMessage({
|
|
297
|
-
...payload,
|
|
298
|
-
channel: bridgeProtocol.channel,
|
|
299
|
-
version: bridgeProtocol.version,
|
|
300
|
-
type: definition.wire,
|
|
301
|
-
documentId: name === "connect" ? "host" : current.documentId,
|
|
302
|
-
sessionId: current.sessionId,
|
|
303
|
-
token: opaque ? current.token : undefined
|
|
304
|
-
});
|
|
305
|
-
if (!message || opaque && !validId2(current.token))
|
|
306
|
-
throw new Error("The bridge is not ready to send this event.");
|
|
307
|
-
diagnostic?.({ direction: "send", ...bridgeMessageMetadata(message) });
|
|
308
|
-
if (disposed)
|
|
309
|
-
return;
|
|
310
|
-
post(message);
|
|
311
|
-
}
|
|
312
|
-
function receive(event) {
|
|
313
|
-
const peer = source();
|
|
314
|
-
if (disposed || !peer || event.origin !== origin || event.source !== peer)
|
|
315
|
-
return;
|
|
316
|
-
const envelope = parseBridgeEnvelope(event.data);
|
|
317
|
-
if (!envelope) {
|
|
318
|
-
const data = event.data;
|
|
319
|
-
if (data && typeof data === "object" && "channel" in data && data.channel === bridgeProtocol.channel)
|
|
320
|
-
drop("invalid_envelope", "type" in data ? data.type : undefined);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
const current = context();
|
|
324
|
-
const connecting = role === "app" && envelope.type === bridgeProtocol.events.connect.wire;
|
|
325
|
-
if (opaque && (connecting ? !validId2(envelope.token) : !current.token || envelope.token !== current.token))
|
|
326
|
-
return drop("token_mismatch", envelope.type);
|
|
327
|
-
const name = bridgeEventName(envelope.type);
|
|
328
|
-
if (!name)
|
|
329
|
-
return drop("unexpected_type", envelope.type);
|
|
330
|
-
const definition = bridgeProtocol.events[name];
|
|
331
|
-
if (definition.from === role)
|
|
332
|
-
return drop("unexpected_type", envelope.type);
|
|
333
|
-
if (definition.session === "establish") {
|
|
334
|
-
if (envelope.documentId !== current.documentId || envelope.sessionId === undefined)
|
|
335
|
-
return drop("session_mismatch", envelope.type);
|
|
336
|
-
} else if (definition.session === "current") {
|
|
337
|
-
if (!current.sessionId || envelope.sessionId !== current.sessionId || envelope.documentId !== current.documentId)
|
|
338
|
-
return drop("session_mismatch", envelope.type);
|
|
339
|
-
}
|
|
340
|
-
const message = parseBridgePayload(envelope, definition);
|
|
341
|
-
if (!message) {
|
|
342
|
-
drop("invalid_payload", envelope.type);
|
|
343
|
-
if (role === "host" && name === "request" && validId2(envelope.id))
|
|
344
|
-
invalidRequest?.(envelope.id);
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
diagnostic?.({ direction: "receive", ...bridgeMessageMetadata(message) });
|
|
348
|
-
if (disposed)
|
|
349
|
-
return;
|
|
350
|
-
const handler = handlers[name];
|
|
351
|
-
handler(message);
|
|
352
|
-
}
|
|
353
|
-
return {
|
|
354
|
-
send,
|
|
355
|
-
receive,
|
|
356
|
-
dispose() {
|
|
357
|
-
disposed = true;
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// packages/data-app/src/client/messages.ts
|
|
363
|
-
function createMessageClient2(routes, transport) {
|
|
364
|
-
return {
|
|
365
|
-
async request(route, payload, { signal } = {}) {
|
|
366
|
-
signal?.throwIfAborted();
|
|
367
|
-
if (!Object.hasOwn(routes, route))
|
|
368
|
-
throw new MessageRoutingError2("unknown_route", "Unknown message route.");
|
|
369
|
-
const contract = routes[route];
|
|
370
|
-
let input;
|
|
371
|
-
try {
|
|
372
|
-
input = contract.input(payload);
|
|
373
|
-
} catch {
|
|
374
|
-
throw new MessageRoutingError2("invalid_payload", "Invalid message payload.");
|
|
375
|
-
}
|
|
376
|
-
const response = await transport({ route, payload: input }, signal);
|
|
377
|
-
signal?.throwIfAborted();
|
|
378
|
-
try {
|
|
379
|
-
return contract.output(response, input);
|
|
380
|
-
} catch (error) {
|
|
381
|
-
if (error instanceof MessageRoutingError2)
|
|
382
|
-
throw error;
|
|
383
|
-
throw new MessageRoutingError2("invalid_response", "Invalid message response.");
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// packages/data-app/src/client/logger.ts
|
|
390
|
-
function createBridgeLogger(enabled, send) {
|
|
391
|
-
function resolve(args) {
|
|
392
|
-
if (args.length === 1 && typeof args[0] === "function") {
|
|
393
|
-
const value = args[0]();
|
|
394
|
-
return Array.isArray(value) ? value : [value];
|
|
395
|
-
}
|
|
396
|
-
return args.map((arg) => typeof arg === "function" ? arg() : arg);
|
|
397
|
-
}
|
|
398
|
-
function write(method, args) {
|
|
399
|
-
if (!enabled())
|
|
400
|
-
return;
|
|
401
|
-
try {
|
|
402
|
-
send({ method, args: resolve(args) });
|
|
403
|
-
} catch {}
|
|
404
|
-
}
|
|
405
|
-
return {
|
|
406
|
-
log: (...args) => write("log", args),
|
|
407
|
-
info: (...args) => write("info", args),
|
|
408
|
-
warn: (...args) => write("warn", args),
|
|
409
|
-
error: (...args) => write("error", args)
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
var diagnosticLabels = {
|
|
413
|
-
send: "Sending message to parent",
|
|
414
|
-
receive: "Received message from parent",
|
|
415
|
-
drop: "Ignored message from parent"
|
|
416
|
-
};
|
|
417
|
-
function logBridgeDiagnostic(logger, { direction, ...metadata }) {
|
|
418
|
-
if (metadata.type === "runtime:log")
|
|
419
|
-
return;
|
|
420
|
-
logger.log(diagnosticLabels[direction], metadata);
|
|
421
|
-
}
|
|
422
|
-
function describeError(error) {
|
|
423
|
-
if (error instanceof Error)
|
|
424
|
-
return {
|
|
425
|
-
name: error.name,
|
|
426
|
-
message: error.message,
|
|
427
|
-
...error.stack ? { stack: error.stack } : {}
|
|
428
|
-
};
|
|
429
|
-
return { message: String(error) };
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// packages/data-app/src/client/iframe.ts
|
|
433
|
-
function rethrowDataMessageError(error) {
|
|
434
|
-
if (error instanceof MessageRoutingError2)
|
|
435
|
-
throw new DataAppError2(error.message, error.code, error.requestId);
|
|
436
|
-
throw error;
|
|
437
|
-
}
|
|
438
|
-
function createIframeTransport2({
|
|
439
|
-
parentOrigin,
|
|
440
|
-
window: frame = window,
|
|
441
|
-
timeoutMs = REQUEST_TIMEOUT_MS2,
|
|
442
|
-
mode = "url",
|
|
443
|
-
loadScript
|
|
444
|
-
}) {
|
|
445
|
-
if (new URL(parentOrigin).origin !== parentOrigin)
|
|
446
|
-
throw new Error("Expected an exact parent origin.");
|
|
447
|
-
const documentId = randomUuid2();
|
|
448
|
-
let token;
|
|
449
|
-
let sessionId;
|
|
450
|
-
let disposed = false;
|
|
451
|
-
const pending = new Map;
|
|
452
|
-
let hostState;
|
|
453
|
-
const stateListeners = new Set;
|
|
454
|
-
const logger = createBridgeLogger(() => !disposed && !!sessionId && !!hostState && typeof hostState === "object" && ("logging" in hostState) && hostState.logging === true, (entry) => send("runtimeLog", { payload: entry }));
|
|
455
|
-
const endpoint = createBridgeEndpoint2({
|
|
456
|
-
role: "app",
|
|
457
|
-
origin: parentOrigin,
|
|
458
|
-
source: () => frame.parent,
|
|
459
|
-
opaque: mode === "bundle",
|
|
460
|
-
context: () => ({ documentId, sessionId, token }),
|
|
461
|
-
post(message) {
|
|
462
|
-
frame.parent.postMessage(message, parentOrigin);
|
|
463
|
-
},
|
|
464
|
-
diagnostic: (event) => logBridgeDiagnostic(logger, event),
|
|
465
|
-
handlers: {
|
|
466
|
-
connect(message) {
|
|
467
|
-
if (mode === "bundle")
|
|
468
|
-
token = message.token;
|
|
469
|
-
send("ready", {});
|
|
470
|
-
},
|
|
471
|
-
initialize(message) {
|
|
472
|
-
if (sessionId && sessionId !== message.sessionId) {
|
|
473
|
-
if (pending.size)
|
|
474
|
-
logger.warn("Preview reconnected; rejecting pending requests", {
|
|
475
|
-
count: pending.size
|
|
476
|
-
});
|
|
477
|
-
for (const entry of pending.values())
|
|
478
|
-
entry.reject(new DataAppError2("The preview reconnected. Retry the request.", "bridge_reset"));
|
|
479
|
-
}
|
|
480
|
-
const first = !sessionId;
|
|
481
|
-
sessionId = message.sessionId;
|
|
482
|
-
receiveState(message.state);
|
|
483
|
-
if (first)
|
|
484
|
-
for (const entry of pending.values())
|
|
485
|
-
entry.start();
|
|
486
|
-
if (disposed)
|
|
487
|
-
return;
|
|
488
|
-
if (mode === "url")
|
|
489
|
-
send("runtimeReady", {});
|
|
490
|
-
},
|
|
491
|
-
stateUpdate(message) {
|
|
492
|
-
receiveState(message.state);
|
|
493
|
-
},
|
|
494
|
-
scriptLoad(message) {
|
|
495
|
-
if (mode === "bundle")
|
|
496
|
-
loadScript?.(message.javascript);
|
|
497
|
-
},
|
|
498
|
-
result(message) {
|
|
499
|
-
pending.get(message.id)?.resolve(message.response);
|
|
500
|
-
},
|
|
501
|
-
error(message) {
|
|
502
|
-
pending.get(message.id)?.reject(new MessageRoutingError2(message.code, message.message, message.requestId));
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
const send = endpoint.send;
|
|
507
|
-
const receive = endpoint.receive;
|
|
508
|
-
function receiveState(state) {
|
|
509
|
-
hostState = state;
|
|
510
|
-
for (const listener of stateListeners)
|
|
511
|
-
listener(state);
|
|
512
|
-
}
|
|
513
|
-
frame.addEventListener("message", receive);
|
|
514
|
-
function requestMessage(message, signal) {
|
|
515
|
-
return new Promise((resolve, reject) => {
|
|
516
|
-
if (disposed)
|
|
517
|
-
return reject(new DataAppError2("The preview has closed.", "bridge_closed"));
|
|
518
|
-
if (signal?.aborted)
|
|
519
|
-
return reject(signal.reason);
|
|
520
|
-
if (pending.size >= MAX_PENDING2)
|
|
521
|
-
return reject(new DataAppError2("Too many pending data requests.", "bridge_busy"));
|
|
522
|
-
const id = randomUuid2();
|
|
523
|
-
let sent = false;
|
|
524
|
-
function cleanup() {
|
|
525
|
-
clearTimeout(timer);
|
|
526
|
-
signal?.removeEventListener("abort", abort);
|
|
527
|
-
pending.delete(id);
|
|
528
|
-
}
|
|
529
|
-
function abort() {
|
|
530
|
-
if (sent)
|
|
531
|
-
send("cancel", { id });
|
|
532
|
-
cleanup();
|
|
533
|
-
reject(signal?.reason);
|
|
534
|
-
}
|
|
535
|
-
const timer = setTimeout(() => {
|
|
536
|
-
logger.warn("Message request timed out", {
|
|
537
|
-
id,
|
|
538
|
-
route: message.route,
|
|
539
|
-
timeoutMs,
|
|
540
|
-
sent
|
|
541
|
-
});
|
|
542
|
-
if (sent)
|
|
543
|
-
send("cancel", { id });
|
|
544
|
-
cleanup();
|
|
545
|
-
reject(new DataAppError2(sessionId ? "The data request timed out." : "The preview shell is unavailable. Reload the preview.", sessionId ? "timeout" : "bridge_unavailable"));
|
|
546
|
-
}, timeoutMs);
|
|
547
|
-
const entry = {
|
|
548
|
-
start() {
|
|
549
|
-
if (sent)
|
|
550
|
-
return;
|
|
551
|
-
try {
|
|
552
|
-
send("request", {
|
|
553
|
-
id,
|
|
554
|
-
route: message.route,
|
|
555
|
-
payload: message.payload
|
|
556
|
-
});
|
|
557
|
-
sent = true;
|
|
558
|
-
} catch {
|
|
559
|
-
cleanup();
|
|
560
|
-
reject(new DataAppError2("The message payload could not be sent.", "invalid_payload"));
|
|
561
|
-
}
|
|
562
|
-
},
|
|
563
|
-
resolve(value) {
|
|
564
|
-
cleanup();
|
|
565
|
-
resolve(value);
|
|
566
|
-
},
|
|
567
|
-
reject(error) {
|
|
568
|
-
cleanup();
|
|
569
|
-
reject(error);
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
pending.set(id, entry);
|
|
573
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
574
|
-
if (sessionId)
|
|
575
|
-
entry.start();
|
|
576
|
-
else if (mode === "url" || token)
|
|
577
|
-
send("ready", {});
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
const messages = createMessageClient2({ "data:query": defineDataQueryRoute2(), "data:sql": sqlQueryRoute2 }, requestMessage);
|
|
581
|
-
function queryOperation(operation, input, signal) {
|
|
582
|
-
return messages.request("data:query", { operation, input }, { signal }).catch(rethrowDataMessageError);
|
|
583
|
-
}
|
|
584
|
-
function disconnect() {
|
|
585
|
-
if (sessionId)
|
|
586
|
-
send("disconnect", {});
|
|
587
|
-
sessionId = undefined;
|
|
588
|
-
for (const entry of pending.values())
|
|
589
|
-
entry.reject(new DataAppError2("The preview has closed.", "bridge_closed"));
|
|
590
|
-
}
|
|
591
|
-
function resume(event) {
|
|
592
|
-
if (event.persisted && (mode === "url" || token))
|
|
593
|
-
send("ready", {});
|
|
594
|
-
}
|
|
595
|
-
function dispose() {
|
|
596
|
-
if (disposed)
|
|
597
|
-
return;
|
|
598
|
-
disconnect();
|
|
599
|
-
disposed = true;
|
|
600
|
-
endpoint.dispose();
|
|
601
|
-
frame.removeEventListener("message", receive);
|
|
602
|
-
frame.removeEventListener("pagehide", disconnect);
|
|
603
|
-
frame.removeEventListener("pageshow", resume);
|
|
604
|
-
stateListeners.clear();
|
|
605
|
-
}
|
|
606
|
-
frame.addEventListener("pagehide", disconnect);
|
|
607
|
-
frame.addEventListener("pageshow", resume);
|
|
608
|
-
if (mode === "url")
|
|
609
|
-
send("ready", {});
|
|
610
|
-
return {
|
|
611
|
-
logger,
|
|
612
|
-
request: requestMessage,
|
|
613
|
-
transport: queryOperation,
|
|
614
|
-
lakehouse: {
|
|
615
|
-
queryAll(statement, { limit, signal, params }) {
|
|
616
|
-
return messages.request("data:sql", { statement, limit, ...params === undefined ? {} : { params } }, { signal }).catch(rethrowDataMessageError);
|
|
617
|
-
}
|
|
618
|
-
},
|
|
619
|
-
dispose,
|
|
620
|
-
mode,
|
|
621
|
-
snapshot() {
|
|
622
|
-
return hostState;
|
|
623
|
-
},
|
|
624
|
-
subscribe(listener) {
|
|
625
|
-
stateListeners.add(listener);
|
|
626
|
-
return () => {
|
|
627
|
-
stateListeners.delete(listener);
|
|
628
|
-
};
|
|
629
|
-
},
|
|
630
|
-
ready() {
|
|
631
|
-
if (!disposed && sessionId)
|
|
632
|
-
send("runtimeReady", {});
|
|
633
|
-
},
|
|
634
|
-
fail(cause) {
|
|
635
|
-
if (disposed || !sessionId)
|
|
636
|
-
return;
|
|
637
|
-
if (cause !== undefined)
|
|
638
|
-
logger.error(() => ["Data app failed", describeError(cause)]);
|
|
639
|
-
send("runtimeError", {});
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
var bridgeKey = Symbol.for("altertable.localFrameBridge");
|
|
644
|
-
var installedKey = Symbol.for("altertable.installedTransport");
|
|
645
|
-
function localFrameBridge2(window2) {
|
|
646
|
-
const activeWindow = window2 ?? (typeof globalThis.window === "undefined" ? undefined : globalThis.window);
|
|
647
|
-
if (!activeWindow)
|
|
648
|
-
return;
|
|
649
|
-
const frame = activeWindow;
|
|
650
|
-
if (frame[bridgeKey])
|
|
651
|
-
return frame[bridgeKey];
|
|
652
|
-
const parentOrigin = new URL(frame.location.href).searchParams.get(PARENT_PARAM2) ?? "";
|
|
653
|
-
if (!parentOrigin)
|
|
654
|
-
return;
|
|
655
|
-
async function connect(parentOrigin) {
|
|
656
|
-
try {
|
|
657
|
-
const response = await frame.fetch("/__altertable/parent", {
|
|
658
|
-
signal: AbortSignal.timeout(5000)
|
|
659
|
-
});
|
|
660
|
-
const config = await response.json();
|
|
661
|
-
if (!response.ok || config.origin !== parentOrigin || frame.parent === frame)
|
|
662
|
-
throw new Error("Invalid local parent configuration.");
|
|
663
|
-
if (frame[installedKey])
|
|
664
|
-
return frame[installedKey];
|
|
665
|
-
if (frame[bridgeKey] !== proxy)
|
|
666
|
-
throw new Error("Preview transport owner changed.");
|
|
667
|
-
const bridge = createIframeTransport2({ parentOrigin, window: frame });
|
|
668
|
-
frame[bridgeKey] = bridge;
|
|
669
|
-
frame[installedKey] = bridge;
|
|
670
|
-
return bridge;
|
|
671
|
-
} catch {
|
|
672
|
-
throw new DataAppError2("The preview shell could not be verified. Open the URL printed by altertable app dev.", "bridge_unavailable");
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
let connection;
|
|
676
|
-
function getConnection() {
|
|
677
|
-
const installed = frame[installedKey];
|
|
678
|
-
if (installed)
|
|
679
|
-
return Promise.resolve(installed);
|
|
680
|
-
if (!connection) {
|
|
681
|
-
const attempt = connect(parentOrigin);
|
|
682
|
-
connection = attempt;
|
|
683
|
-
attempt.catch(() => {
|
|
684
|
-
if (connection === attempt)
|
|
685
|
-
connection = undefined;
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
return connection;
|
|
689
|
-
}
|
|
690
|
-
const proxy = {
|
|
691
|
-
async transport(operation, input, signal) {
|
|
692
|
-
signal?.throwIfAborted();
|
|
693
|
-
const attempt = getConnection();
|
|
694
|
-
let abort;
|
|
695
|
-
try {
|
|
696
|
-
const bridge = signal ? await Promise.race([
|
|
697
|
-
attempt,
|
|
698
|
-
new Promise((_, reject) => {
|
|
699
|
-
const requestSignal = signal;
|
|
700
|
-
function handleAbort() {
|
|
701
|
-
reject(requestSignal.reason);
|
|
702
|
-
}
|
|
703
|
-
abort = handleAbort;
|
|
704
|
-
requestSignal.addEventListener("abort", handleAbort, {
|
|
705
|
-
once: true
|
|
706
|
-
});
|
|
707
|
-
})
|
|
708
|
-
]) : await attempt;
|
|
709
|
-
signal?.throwIfAborted();
|
|
710
|
-
return bridge.transport(operation, input, signal);
|
|
711
|
-
} finally {
|
|
712
|
-
if (abort)
|
|
713
|
-
signal?.removeEventListener("abort", abort);
|
|
714
|
-
}
|
|
715
|
-
},
|
|
716
|
-
connect: getConnection
|
|
717
|
-
};
|
|
718
|
-
frame[bridgeKey] = proxy;
|
|
719
|
-
getConnection().catch(() => {});
|
|
720
|
-
return proxy;
|
|
721
|
-
}
|
|
722
|
-
function installDataAppTransport2(bridge, frame = window) {
|
|
723
|
-
const target = frame;
|
|
724
|
-
if (target[installedKey])
|
|
725
|
-
throw new Error("A data app transport is already installed.");
|
|
726
|
-
target[bridgeKey] = bridge;
|
|
727
|
-
target[installedKey] = bridge;
|
|
728
|
-
return () => {
|
|
729
|
-
if (target[bridgeKey] === bridge)
|
|
730
|
-
delete target[bridgeKey];
|
|
731
|
-
if (target[installedKey] === bridge)
|
|
732
|
-
delete target[installedKey];
|
|
733
|
-
bridge.dispose();
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
function getDataAppTransport2(frame = window) {
|
|
737
|
-
return frame[installedKey];
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
export { randomUuid2, DataAppError2, createHttpTransport2, PARENT_PARAM2, MAX_PENDING2, REQUEST_TIMEOUT_MS2, validId2, createBridgeEndpoint2, createMessageClient2, createIframeTransport2, localFrameBridge2, installDataAppTransport2, getDataAppTransport2 };
|
|
741
|
-
|
|
742
|
-
//# debugId=6665DCD3D64F122164756E2164756E21
|