@20baht/live 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +132 -2
- package/dist/browser.d.ts +164 -0
- package/dist/browser.js +404 -0
- package/dist/elysia.d.ts +268 -0
- package/dist/elysia.js +118 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/live.d.ts +81 -0
- package/dist/live.js +393 -0
- package/dist/pg.d.ts +81 -0
- package/dist/pg.js +214 -0
- package/dist/protocol.d.ts +112 -0
- package/dist/protocol.js +122 -0
- package/dist/source.d.ts +17 -0
- package/dist/source.js +24 -0
- package/dist/topics.d.ts +10 -0
- package/dist/topics.js +25 -0
- package/package.json +86 -4
package/dist/browser.js
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { applyPatch, requestKey, requestTarget, stableJson, } from './protocol.js';
|
|
2
|
+
export class LiveMutationError extends Error {
|
|
3
|
+
constructor(status, body) {
|
|
4
|
+
super(`the write answered ${status}`);
|
|
5
|
+
this.status = status;
|
|
6
|
+
this.body = body;
|
|
7
|
+
this.name = 'LiveMutationError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const GUESS = Symbol('guess');
|
|
11
|
+
export function guess(subscription, apply) {
|
|
12
|
+
return { [GUESS]: { handle: subscription, apply: apply } };
|
|
13
|
+
}
|
|
14
|
+
const browserEnvironment = () => ({
|
|
15
|
+
fetch: (url, init) => globalThis.fetch(url, init),
|
|
16
|
+
setTimeout: (run, ms) => globalThis.setTimeout(run, ms),
|
|
17
|
+
clearTimeout: (handle) => {
|
|
18
|
+
globalThis.clearTimeout(handle);
|
|
19
|
+
},
|
|
20
|
+
onWake: (wake) => {
|
|
21
|
+
if (typeof window === 'undefined')
|
|
22
|
+
return () => undefined;
|
|
23
|
+
const visible = () => {
|
|
24
|
+
if (document.visibilityState === 'visible')
|
|
25
|
+
wake();
|
|
26
|
+
};
|
|
27
|
+
window.addEventListener('online', wake);
|
|
28
|
+
document.addEventListener('visibilitychange', visible);
|
|
29
|
+
return () => {
|
|
30
|
+
window.removeEventListener('online', wake);
|
|
31
|
+
document.removeEventListener('visibilitychange', visible);
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
uuid: () => crypto.randomUUID(),
|
|
35
|
+
});
|
|
36
|
+
const MIN_BACKOFF = 1000;
|
|
37
|
+
const MAX_BACKOFF = 60_000;
|
|
38
|
+
export function createLiveClient(options) {
|
|
39
|
+
const env = { ...browserEnvironment(), ...options.environment };
|
|
40
|
+
const base = options.base ?? options.url.replace(/\/[^/]*\/?$/, '');
|
|
41
|
+
const debounceMs = options.debounceMs ?? 20;
|
|
42
|
+
const settleMs = options.settleMs ?? 5000;
|
|
43
|
+
const wires = new Map();
|
|
44
|
+
let nextId = 0;
|
|
45
|
+
let connection;
|
|
46
|
+
let pending;
|
|
47
|
+
let retry;
|
|
48
|
+
let backoff = MIN_BACKOFF;
|
|
49
|
+
let closed = false;
|
|
50
|
+
const view = (wire) => {
|
|
51
|
+
let data = wire.body;
|
|
52
|
+
for (const layer of wire.layers)
|
|
53
|
+
if (data !== undefined)
|
|
54
|
+
data = layer.apply(data);
|
|
55
|
+
return { status: wire.status, data, error: wire.error, pending: wire.layers.length > 0 };
|
|
56
|
+
};
|
|
57
|
+
const notify = (wire) => {
|
|
58
|
+
const state = view(wire);
|
|
59
|
+
for (const listener of [...wire.listeners])
|
|
60
|
+
listener(state);
|
|
61
|
+
};
|
|
62
|
+
const setStatus = (status) => {
|
|
63
|
+
for (const wire of wires.values()) {
|
|
64
|
+
if (wire.status === status || (status === 'connecting' && wire.body !== undefined))
|
|
65
|
+
continue;
|
|
66
|
+
wire.status = status;
|
|
67
|
+
notify(wire);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const schedule = (ms = debounceMs) => {
|
|
71
|
+
env.clearTimeout(pending);
|
|
72
|
+
pending = env.setTimeout(() => {
|
|
73
|
+
void connect();
|
|
74
|
+
}, ms);
|
|
75
|
+
};
|
|
76
|
+
const again = () => {
|
|
77
|
+
env.clearTimeout(retry);
|
|
78
|
+
retry = env.setTimeout(() => {
|
|
79
|
+
void connect();
|
|
80
|
+
}, backoff);
|
|
81
|
+
backoff = Math.min(backoff * 2, MAX_BACKOFF);
|
|
82
|
+
};
|
|
83
|
+
const connect = async () => {
|
|
84
|
+
env.clearTimeout(retry);
|
|
85
|
+
connection?.abort();
|
|
86
|
+
connection = undefined;
|
|
87
|
+
if (closed || wires.size === 0)
|
|
88
|
+
return;
|
|
89
|
+
const abort = new AbortController();
|
|
90
|
+
connection = abort;
|
|
91
|
+
setStatus('connecting');
|
|
92
|
+
const subscriptions = [...wires.values()].map((wire) => ({
|
|
93
|
+
id: wire.id,
|
|
94
|
+
...wire.request,
|
|
95
|
+
...(wire.version === undefined ? {} : { version: wire.version }),
|
|
96
|
+
}));
|
|
97
|
+
let response;
|
|
98
|
+
try {
|
|
99
|
+
response = await env.fetch(options.url, {
|
|
100
|
+
method: 'POST',
|
|
101
|
+
headers: await headersWith({
|
|
102
|
+
'content-type': 'application/json',
|
|
103
|
+
accept: 'text/event-stream',
|
|
104
|
+
}),
|
|
105
|
+
body: JSON.stringify({ subscriptions }),
|
|
106
|
+
credentials: options.credentials ?? 'include',
|
|
107
|
+
signal: abort.signal,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
if (abort.signal.aborted)
|
|
112
|
+
return;
|
|
113
|
+
setStatus('offline');
|
|
114
|
+
again();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!response.ok || response.body === null) {
|
|
118
|
+
if (response.status === 401)
|
|
119
|
+
await options.onUnauthorized?.();
|
|
120
|
+
setStatus('offline');
|
|
121
|
+
again();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const ended = await read(response.body, abort.signal);
|
|
125
|
+
if (abort.signal.aborted)
|
|
126
|
+
return;
|
|
127
|
+
if (ended === 'unauthorized' || ended === 'signed-out')
|
|
128
|
+
await options.onUnauthorized?.();
|
|
129
|
+
if (ended === 'caller-changed')
|
|
130
|
+
schedule(0);
|
|
131
|
+
else {
|
|
132
|
+
setStatus('offline');
|
|
133
|
+
again();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const read = async (body, signal) => {
|
|
137
|
+
const reader = body.getReader();
|
|
138
|
+
const decoder = new TextDecoder();
|
|
139
|
+
let buffer = '';
|
|
140
|
+
try {
|
|
141
|
+
for (;;) {
|
|
142
|
+
const { value, done } = await reader.read();
|
|
143
|
+
if (done)
|
|
144
|
+
return undefined;
|
|
145
|
+
buffer += decoder.decode(value, { stream: true });
|
|
146
|
+
let cut = buffer.indexOf('\n\n');
|
|
147
|
+
while (cut !== -1) {
|
|
148
|
+
const frame = parseFrame(buffer.slice(0, cut));
|
|
149
|
+
buffer = buffer.slice(cut + 2);
|
|
150
|
+
if (frame?.event === 'end')
|
|
151
|
+
return frame.data.reason;
|
|
152
|
+
if (frame !== undefined && !signal.aborted)
|
|
153
|
+
apply(frame);
|
|
154
|
+
cut = buffer.indexOf('\n\n');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const apply = (frame) => {
|
|
163
|
+
const wire = wires.get(frame.data.id);
|
|
164
|
+
if (wire === undefined)
|
|
165
|
+
return;
|
|
166
|
+
backoff = MIN_BACKOFF;
|
|
167
|
+
switch (frame.event) {
|
|
168
|
+
case 'snapshot':
|
|
169
|
+
wire.body = frame.data.body;
|
|
170
|
+
wire.version = frame.data.version;
|
|
171
|
+
break;
|
|
172
|
+
case 'patch': {
|
|
173
|
+
const { key, rows, upsert, remove, order, rest } = frame.data;
|
|
174
|
+
const list = (rows === undefined ? wire.body : wire.body[rows]);
|
|
175
|
+
const next = applyPatch(list, { upsert, remove, ...(order === undefined ? {} : { order }) }, key);
|
|
176
|
+
wire.body = rows === undefined ? next : { ...rest, [rows]: next };
|
|
177
|
+
wire.version = frame.data.version;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case 'unchanged':
|
|
181
|
+
wire.version = frame.data.version;
|
|
182
|
+
break;
|
|
183
|
+
case 'error':
|
|
184
|
+
wire.status = 'error';
|
|
185
|
+
wire.error = { status: frame.data.status, body: frame.data.body };
|
|
186
|
+
notify(wire);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
wire.status = 'live';
|
|
190
|
+
wire.error = undefined;
|
|
191
|
+
wire.layers = wire.layers.filter((layer) => !layer.answered);
|
|
192
|
+
notify(wire);
|
|
193
|
+
};
|
|
194
|
+
const headersWith = async (extra) => {
|
|
195
|
+
const headers = new Headers(await options.headers?.());
|
|
196
|
+
for (const [name, value] of Object.entries(extra))
|
|
197
|
+
headers.set(name, value);
|
|
198
|
+
return headers;
|
|
199
|
+
};
|
|
200
|
+
const stopWaking = env.onWake(() => {
|
|
201
|
+
if (connection !== undefined && retry === undefined)
|
|
202
|
+
return;
|
|
203
|
+
backoff = MIN_BACKOFF;
|
|
204
|
+
schedule(0);
|
|
205
|
+
});
|
|
206
|
+
const handleOf = new WeakMap();
|
|
207
|
+
const subscribe = (request, listener) => {
|
|
208
|
+
const key = requestKey(request);
|
|
209
|
+
let wire = [...wires.values()].find((w) => requestKey(w.request) === key);
|
|
210
|
+
if (wire === undefined) {
|
|
211
|
+
nextId += 1;
|
|
212
|
+
wire = {
|
|
213
|
+
id: `s${nextId}`,
|
|
214
|
+
request,
|
|
215
|
+
version: undefined,
|
|
216
|
+
body: undefined,
|
|
217
|
+
status: 'connecting',
|
|
218
|
+
error: undefined,
|
|
219
|
+
layers: [],
|
|
220
|
+
listeners: new Set(),
|
|
221
|
+
handles: 0,
|
|
222
|
+
};
|
|
223
|
+
wires.set(wire.id, wire);
|
|
224
|
+
schedule();
|
|
225
|
+
}
|
|
226
|
+
const held = wire;
|
|
227
|
+
held.handles += 1;
|
|
228
|
+
const mine = new Set();
|
|
229
|
+
const listen = (fn) => {
|
|
230
|
+
const wrapped = fn;
|
|
231
|
+
mine.add(wrapped);
|
|
232
|
+
held.listeners.add(wrapped);
|
|
233
|
+
return () => {
|
|
234
|
+
mine.delete(wrapped);
|
|
235
|
+
held.listeners.delete(wrapped);
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
if (listener !== undefined)
|
|
239
|
+
listen(listener);
|
|
240
|
+
let open = true;
|
|
241
|
+
const handle = {
|
|
242
|
+
state: () => view(held),
|
|
243
|
+
listen,
|
|
244
|
+
close: () => {
|
|
245
|
+
if (!open)
|
|
246
|
+
return;
|
|
247
|
+
open = false;
|
|
248
|
+
for (const fn of mine)
|
|
249
|
+
held.listeners.delete(fn);
|
|
250
|
+
held.handles -= 1;
|
|
251
|
+
if (held.handles === 0) {
|
|
252
|
+
wires.delete(held.id);
|
|
253
|
+
schedule();
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
handleOf.set(handle, held);
|
|
258
|
+
return handle;
|
|
259
|
+
};
|
|
260
|
+
const mutate = async (request, mutateOptions = {}) => {
|
|
261
|
+
const id = env.uuid();
|
|
262
|
+
const touched = [];
|
|
263
|
+
for (const { [GUESS]: { handle, apply }, } of mutateOptions.optimistic ?? []) {
|
|
264
|
+
const wire = handleOf.get(handle);
|
|
265
|
+
if (wire === undefined)
|
|
266
|
+
continue;
|
|
267
|
+
const layer = { id, apply, answered: false };
|
|
268
|
+
wire.layers.push(layer);
|
|
269
|
+
touched.push({ wire, layer });
|
|
270
|
+
notify(wire);
|
|
271
|
+
}
|
|
272
|
+
const takeOff = () => {
|
|
273
|
+
for (const { wire, layer } of touched) {
|
|
274
|
+
const before = wire.layers.length;
|
|
275
|
+
wire.layers = wire.layers.filter((l) => l !== layer);
|
|
276
|
+
if (wire.layers.length !== before)
|
|
277
|
+
notify(wire);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
let response;
|
|
281
|
+
try {
|
|
282
|
+
const headers = await headersWith({ 'idempotency-key': id });
|
|
283
|
+
const init = {
|
|
284
|
+
method: request.method,
|
|
285
|
+
headers,
|
|
286
|
+
credentials: options.credentials ?? 'include',
|
|
287
|
+
};
|
|
288
|
+
if (request.body !== undefined) {
|
|
289
|
+
headers.set('content-type', 'application/json');
|
|
290
|
+
init.body = JSON.stringify(request.body);
|
|
291
|
+
}
|
|
292
|
+
response = await env.fetch(`${base}${requestTarget({ ...request, method: 'POST' })}`, init);
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
takeOff();
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
const answer = await bodyOf(response);
|
|
299
|
+
if (!response.ok) {
|
|
300
|
+
takeOff();
|
|
301
|
+
throw new LiveMutationError(response.status, answer);
|
|
302
|
+
}
|
|
303
|
+
for (const { layer } of touched)
|
|
304
|
+
layer.answered = true;
|
|
305
|
+
if (touched.length > 0)
|
|
306
|
+
env.setTimeout(takeOff, settleMs);
|
|
307
|
+
return answer;
|
|
308
|
+
};
|
|
309
|
+
return {
|
|
310
|
+
subscribe,
|
|
311
|
+
mutate,
|
|
312
|
+
close: () => {
|
|
313
|
+
closed = true;
|
|
314
|
+
stopWaking();
|
|
315
|
+
env.clearTimeout(pending);
|
|
316
|
+
env.clearTimeout(retry);
|
|
317
|
+
connection?.abort();
|
|
318
|
+
wires.clear();
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function parseFrame(block) {
|
|
323
|
+
let event = '';
|
|
324
|
+
let data = '';
|
|
325
|
+
for (const line of block.split('\n')) {
|
|
326
|
+
if (line.startsWith('event: '))
|
|
327
|
+
event = line.slice(7);
|
|
328
|
+
else if (line.startsWith('data: '))
|
|
329
|
+
data += line.slice(6);
|
|
330
|
+
}
|
|
331
|
+
if (event === '')
|
|
332
|
+
return undefined;
|
|
333
|
+
try {
|
|
334
|
+
return { event, data: JSON.parse(data) };
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async function bodyOf(response) {
|
|
341
|
+
const text = await response.text();
|
|
342
|
+
if (text === '')
|
|
343
|
+
return undefined;
|
|
344
|
+
try {
|
|
345
|
+
return JSON.parse(text);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
return text;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const REGISTRY = Symbol.for('@20baht/live/clients');
|
|
352
|
+
export function liveClient(options) {
|
|
353
|
+
const holder = globalThis;
|
|
354
|
+
const registry = holder[REGISTRY] ?? new Map();
|
|
355
|
+
holder[REGISTRY] = registry;
|
|
356
|
+
const found = registry.get(options.url);
|
|
357
|
+
if (found !== undefined)
|
|
358
|
+
return found;
|
|
359
|
+
const client = createLiveClient(options);
|
|
360
|
+
registry.set(options.url, client);
|
|
361
|
+
return client;
|
|
362
|
+
}
|
|
363
|
+
export function rebase(base, local, incoming) {
|
|
364
|
+
const same = (a, b) => stableJson(a) === stableJson(b);
|
|
365
|
+
const value = {};
|
|
366
|
+
const conflicts = [];
|
|
367
|
+
for (const key of new Set([
|
|
368
|
+
...Object.keys(base),
|
|
369
|
+
...Object.keys(local),
|
|
370
|
+
...Object.keys(incoming),
|
|
371
|
+
])) {
|
|
372
|
+
const mine = !same(local[key], base[key]);
|
|
373
|
+
const theirs = !same(incoming[key], base[key]);
|
|
374
|
+
const chosen = mine ? local[key] : incoming[key];
|
|
375
|
+
if (chosen !== undefined)
|
|
376
|
+
value[key] = chosen;
|
|
377
|
+
if (mine && theirs && !same(local[key], incoming[key])) {
|
|
378
|
+
conflicts.push({ key, local: local[key], server: incoming[key] });
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return { value: value, base: incoming, conflicts };
|
|
382
|
+
}
|
|
383
|
+
export function fillPath(path, params = {}) {
|
|
384
|
+
return path.replace(/:(\w+)\??/g, (_match, name) => {
|
|
385
|
+
const value = params[name];
|
|
386
|
+
if (value === undefined)
|
|
387
|
+
throw new Error(`live: ${path} needs the parameter "${name}"`);
|
|
388
|
+
return encodeURIComponent(value);
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
export function typedLive(client) {
|
|
392
|
+
const toRequest = (method, path, input = {}) => ({
|
|
393
|
+
method,
|
|
394
|
+
path: fillPath(path, input.params),
|
|
395
|
+
...(input.query === undefined ? {} : { query: input.query }),
|
|
396
|
+
...(input.body === undefined ? {} : { body: input.body }),
|
|
397
|
+
});
|
|
398
|
+
return {
|
|
399
|
+
subscribe: (method, path, input) => client.subscribe(toRequest(method, path, input)),
|
|
400
|
+
request: (method, path, input) => toRequest(method, path, input),
|
|
401
|
+
mutate: client.mutate,
|
|
402
|
+
close: client.close,
|
|
403
|
+
};
|
|
404
|
+
}
|
package/dist/elysia.d.ts
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { Elysia } from 'elysia';
|
|
2
|
+
import type { Caller, Live, Runner } from './live.js';
|
|
3
|
+
/** What a live route's `topics` and `share` are handed when it runs for a stream. */
|
|
4
|
+
export interface LiveRouteContext<C extends Caller | null> {
|
|
5
|
+
params: Record<string, string>;
|
|
6
|
+
query: Record<string, string | undefined>;
|
|
7
|
+
body: unknown;
|
|
8
|
+
/** The stream's caller, as `createLive`'s `caller` port said (null without one). */
|
|
9
|
+
caller: C;
|
|
10
|
+
}
|
|
11
|
+
/** The `live` route option. */
|
|
12
|
+
export interface LiveRoute<C extends Caller | null> {
|
|
13
|
+
/** The topics the answer depends on, worked out on the server from the request and its caller. */
|
|
14
|
+
topics: (context: LiveRouteContext<C>) => readonly string[];
|
|
15
|
+
/** The row key: frames after the first become patches of the rows that changed. */
|
|
16
|
+
key?: string | undefined;
|
|
17
|
+
/** The answer's key holding the rows, when the answer is not itself the list (`'rows'`). */
|
|
18
|
+
rows?: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Share one run across callers: the same request with the same share key is run once, with
|
|
21
|
+
* one caller's credentials, and its answer goes to all of them. Only for an answer that is the
|
|
22
|
+
* same for everyone with that key (spec 09 §5).
|
|
23
|
+
*/
|
|
24
|
+
share?: ((context: LiveRouteContext<C>) => string) | undefined;
|
|
25
|
+
}
|
|
26
|
+
type HookList = {
|
|
27
|
+
fn?: unknown;
|
|
28
|
+
}[] | {
|
|
29
|
+
fn?: unknown;
|
|
30
|
+
} | undefined;
|
|
31
|
+
interface RouteLike {
|
|
32
|
+
method: string;
|
|
33
|
+
path: string;
|
|
34
|
+
hooks?: {
|
|
35
|
+
beforeHandle?: HookList;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
interface AppLike {
|
|
39
|
+
handle: (request: Request) => Promise<Response>;
|
|
40
|
+
routes: readonly RouteLike[];
|
|
41
|
+
}
|
|
42
|
+
export interface LivePluginOptions<Path extends string = '/live'> {
|
|
43
|
+
/** Where the stream is served. Default `/live`; health is `<path>/health`. */
|
|
44
|
+
path?: Path | undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The `live` route option and the stream's routes. Use it in the root app and in every module
|
|
48
|
+
* whose routes are live (Elysia applies it once per hub), then `bindLive(live, app)` once the app
|
|
49
|
+
* is built.
|
|
50
|
+
*
|
|
51
|
+
* const app = new Elysia()
|
|
52
|
+
* .use(livePlugin(live))
|
|
53
|
+
* .get('/boards/:id/issues', ({ params }) => issues(params.id), {
|
|
54
|
+
* live: { topics: ({ params }) => [`board_issues@board_id=${params.id}`], key: 'id' },
|
|
55
|
+
* })
|
|
56
|
+
* bindLive(live, app)
|
|
57
|
+
*/
|
|
58
|
+
export declare function livePlugin<C extends Caller | null, Path extends string = '/live'>(live: Live<C>, options?: LivePluginOptions<Path>): Elysia<"", {
|
|
59
|
+
decorator: {};
|
|
60
|
+
store: {};
|
|
61
|
+
derive: {};
|
|
62
|
+
resolve: {};
|
|
63
|
+
}, {
|
|
64
|
+
typebox: {};
|
|
65
|
+
error: {};
|
|
66
|
+
}, {
|
|
67
|
+
schema: {};
|
|
68
|
+
standaloneSchema: {};
|
|
69
|
+
macro: Partial<{
|
|
70
|
+
readonly live: LiveRoute<C>;
|
|
71
|
+
}>;
|
|
72
|
+
macroFn: {
|
|
73
|
+
readonly live: (route: LiveRoute<C>) => {
|
|
74
|
+
readonly beforeHandle: (context: {
|
|
75
|
+
request: Request;
|
|
76
|
+
params?: unknown;
|
|
77
|
+
query?: unknown;
|
|
78
|
+
body?: unknown;
|
|
79
|
+
}) => void;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
parser: {};
|
|
83
|
+
response: {};
|
|
84
|
+
}, {} & import("elysia").CreateEden<import("elysia/types").JoinPath<"", Path>, {
|
|
85
|
+
post: {
|
|
86
|
+
body: {};
|
|
87
|
+
params: import("elysia/types").IsNever<keyof import("elysia/types").IntersectIfObject<import("elysia").ResolvePath<import("elysia/types").JoinPath<"", Path>>, unknown>> extends true ? import("elysia").ResolvePath<Path> : import("elysia/types").IntersectIfObject<import("elysia").ResolvePath<import("elysia/types").JoinPath<"", Path>>, unknown> extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
88
|
+
query: {};
|
|
89
|
+
headers: {};
|
|
90
|
+
response: import("elysia").ComposeElysiaResponse<import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<Partial<{
|
|
91
|
+
readonly live: LiveRoute<C>;
|
|
92
|
+
}> & import("elysia").InputSchema<never>, {}, import("elysia/types").JoinPath<"", Path>>, {}> & {
|
|
93
|
+
return: unknown;
|
|
94
|
+
}, ({ request, body }: {
|
|
95
|
+
body: unknown;
|
|
96
|
+
query: Record<string, string>;
|
|
97
|
+
params: undefined extends import("elysia/types").IntersectIfObject<import("elysia").ResolvePath<import("elysia/types").JoinPath<"", Path>>, unknown> ? Record<string, string> : import("elysia/types").IntersectIfObject<import("elysia").ResolvePath<import("elysia/types").JoinPath<"", Path>>, unknown> extends infer T_2 ? T_2 extends import("elysia/types").IntersectIfObject<import("elysia").ResolvePath<import("elysia/types").JoinPath<"", Path>>, unknown> ? T_2 extends object ? { [K_2 in keyof T_2]: T_2[K_2]; } : T_2 : never : never;
|
|
98
|
+
headers: Record<string, string | undefined>;
|
|
99
|
+
cookie: Record<string, import("elysia").Cookie<unknown>>;
|
|
100
|
+
server: import("elysia/universal/server").Server | null;
|
|
101
|
+
redirect: import("elysia").redirect;
|
|
102
|
+
set: {
|
|
103
|
+
headers: import("elysia").HTTPHeaders;
|
|
104
|
+
status?: number | keyof import("elysia").StatusMap;
|
|
105
|
+
redirect?: string;
|
|
106
|
+
cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
|
|
107
|
+
};
|
|
108
|
+
path: string;
|
|
109
|
+
route: string;
|
|
110
|
+
request: Request;
|
|
111
|
+
store: {};
|
|
112
|
+
status: <const Code extends number | keyof import("elysia").StatusMap, const T_3 = Code extends 401 | 200 | 100 | 500 | 403 | 300 | 404 | 503 | 400 | 101 | 102 | 103 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 301 | 302 | 303 | 304 | 307 | 308 | 402 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 501 | 502 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
|
|
113
|
+
readonly 100: "Continue";
|
|
114
|
+
readonly 101: "Switching Protocols";
|
|
115
|
+
readonly 102: "Processing";
|
|
116
|
+
readonly 103: "Early Hints";
|
|
117
|
+
readonly 200: "OK";
|
|
118
|
+
readonly 201: "Created";
|
|
119
|
+
readonly 202: "Accepted";
|
|
120
|
+
readonly 203: "Non-Authoritative Information";
|
|
121
|
+
readonly 204: "No Content";
|
|
122
|
+
readonly 205: "Reset Content";
|
|
123
|
+
readonly 206: "Partial Content";
|
|
124
|
+
readonly 207: "Multi-Status";
|
|
125
|
+
readonly 208: "Already Reported";
|
|
126
|
+
readonly 300: "Multiple Choices";
|
|
127
|
+
readonly 301: "Moved Permanently";
|
|
128
|
+
readonly 302: "Found";
|
|
129
|
+
readonly 303: "See Other";
|
|
130
|
+
readonly 304: "Not Modified";
|
|
131
|
+
readonly 307: "Temporary Redirect";
|
|
132
|
+
readonly 308: "Permanent Redirect";
|
|
133
|
+
readonly 400: "Bad Request";
|
|
134
|
+
readonly 401: "Unauthorized";
|
|
135
|
+
readonly 402: "Payment Required";
|
|
136
|
+
readonly 403: "Forbidden";
|
|
137
|
+
readonly 404: "Not Found";
|
|
138
|
+
readonly 405: "Method Not Allowed";
|
|
139
|
+
readonly 406: "Not Acceptable";
|
|
140
|
+
readonly 407: "Proxy Authentication Required";
|
|
141
|
+
readonly 408: "Request Timeout";
|
|
142
|
+
readonly 409: "Conflict";
|
|
143
|
+
readonly 410: "Gone";
|
|
144
|
+
readonly 411: "Length Required";
|
|
145
|
+
readonly 412: "Precondition Failed";
|
|
146
|
+
readonly 413: "Payload Too Large";
|
|
147
|
+
readonly 414: "URI Too Long";
|
|
148
|
+
readonly 415: "Unsupported Media Type";
|
|
149
|
+
readonly 416: "Range Not Satisfiable";
|
|
150
|
+
readonly 417: "Expectation Failed";
|
|
151
|
+
readonly 418: "I'm a teapot";
|
|
152
|
+
readonly 420: "Enhance Your Calm";
|
|
153
|
+
readonly 421: "Misdirected Request";
|
|
154
|
+
readonly 422: "Unprocessable Content";
|
|
155
|
+
readonly 423: "Locked";
|
|
156
|
+
readonly 424: "Failed Dependency";
|
|
157
|
+
readonly 425: "Too Early";
|
|
158
|
+
readonly 426: "Upgrade Required";
|
|
159
|
+
readonly 428: "Precondition Required";
|
|
160
|
+
readonly 429: "Too Many Requests";
|
|
161
|
+
readonly 431: "Request Header Fields Too Large";
|
|
162
|
+
readonly 451: "Unavailable For Legal Reasons";
|
|
163
|
+
readonly 500: "Internal Server Error";
|
|
164
|
+
readonly 501: "Not Implemented";
|
|
165
|
+
readonly 502: "Bad Gateway";
|
|
166
|
+
readonly 503: "Service Unavailable";
|
|
167
|
+
readonly 504: "Gateway Timeout";
|
|
168
|
+
readonly 505: "HTTP Version Not Supported";
|
|
169
|
+
readonly 506: "Variant Also Negotiates";
|
|
170
|
+
readonly 507: "Insufficient Storage";
|
|
171
|
+
readonly 508: "Loop Detected";
|
|
172
|
+
readonly 510: "Not Extended";
|
|
173
|
+
readonly 511: "Network Authentication Required";
|
|
174
|
+
}[Code] : Code>(code: Code, response?: T_3) => import("elysia").ElysiaCustomStatusResponse<Code, T_3, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
|
|
175
|
+
readonly Continue: 100;
|
|
176
|
+
readonly "Switching Protocols": 101;
|
|
177
|
+
readonly Processing: 102;
|
|
178
|
+
readonly "Early Hints": 103;
|
|
179
|
+
readonly OK: 200;
|
|
180
|
+
readonly Created: 201;
|
|
181
|
+
readonly Accepted: 202;
|
|
182
|
+
readonly "Non-Authoritative Information": 203;
|
|
183
|
+
readonly "No Content": 204;
|
|
184
|
+
readonly "Reset Content": 205;
|
|
185
|
+
readonly "Partial Content": 206;
|
|
186
|
+
readonly "Multi-Status": 207;
|
|
187
|
+
readonly "Already Reported": 208;
|
|
188
|
+
readonly "Multiple Choices": 300;
|
|
189
|
+
readonly "Moved Permanently": 301;
|
|
190
|
+
readonly Found: 302;
|
|
191
|
+
readonly "See Other": 303;
|
|
192
|
+
readonly "Not Modified": 304;
|
|
193
|
+
readonly "Temporary Redirect": 307;
|
|
194
|
+
readonly "Permanent Redirect": 308;
|
|
195
|
+
readonly "Bad Request": 400;
|
|
196
|
+
readonly Unauthorized: 401;
|
|
197
|
+
readonly "Payment Required": 402;
|
|
198
|
+
readonly Forbidden: 403;
|
|
199
|
+
readonly "Not Found": 404;
|
|
200
|
+
readonly "Method Not Allowed": 405;
|
|
201
|
+
readonly "Not Acceptable": 406;
|
|
202
|
+
readonly "Proxy Authentication Required": 407;
|
|
203
|
+
readonly "Request Timeout": 408;
|
|
204
|
+
readonly Conflict: 409;
|
|
205
|
+
readonly Gone: 410;
|
|
206
|
+
readonly "Length Required": 411;
|
|
207
|
+
readonly "Precondition Failed": 412;
|
|
208
|
+
readonly "Payload Too Large": 413;
|
|
209
|
+
readonly "URI Too Long": 414;
|
|
210
|
+
readonly "Unsupported Media Type": 415;
|
|
211
|
+
readonly "Range Not Satisfiable": 416;
|
|
212
|
+
readonly "Expectation Failed": 417;
|
|
213
|
+
readonly "I'm a teapot": 418;
|
|
214
|
+
readonly "Enhance Your Calm": 420;
|
|
215
|
+
readonly "Misdirected Request": 421;
|
|
216
|
+
readonly "Unprocessable Content": 422;
|
|
217
|
+
readonly Locked: 423;
|
|
218
|
+
readonly "Failed Dependency": 424;
|
|
219
|
+
readonly "Too Early": 425;
|
|
220
|
+
readonly "Upgrade Required": 426;
|
|
221
|
+
readonly "Precondition Required": 428;
|
|
222
|
+
readonly "Too Many Requests": 429;
|
|
223
|
+
readonly "Request Header Fields Too Large": 431;
|
|
224
|
+
readonly "Unavailable For Legal Reasons": 451;
|
|
225
|
+
readonly "Internal Server Error": 500;
|
|
226
|
+
readonly "Not Implemented": 501;
|
|
227
|
+
readonly "Bad Gateway": 502;
|
|
228
|
+
readonly "Service Unavailable": 503;
|
|
229
|
+
readonly "Gateway Timeout": 504;
|
|
230
|
+
readonly "HTTP Version Not Supported": 505;
|
|
231
|
+
readonly "Variant Also Negotiates": 506;
|
|
232
|
+
readonly "Insufficient Storage": 507;
|
|
233
|
+
readonly "Loop Detected": 508;
|
|
234
|
+
readonly "Not Extended": 510;
|
|
235
|
+
readonly "Network Authentication Required": 511;
|
|
236
|
+
}[Code] : Code>;
|
|
237
|
+
}) => Response | Promise<Response>, {}> extends infer T_1 ? { [K_1 in keyof T_1]: T_1[K_1]; } : never;
|
|
238
|
+
};
|
|
239
|
+
}> & import("elysia").CreateEden<import("elysia/types").JoinPath<"", `${Path}/health`>, {
|
|
240
|
+
get: {
|
|
241
|
+
body: {};
|
|
242
|
+
params: import("elysia/types").IsNever<keyof import("elysia/types").IntersectIfObject<import("elysia").ResolvePath<import("elysia/types").JoinPath<"", `${Path}/health`>>, unknown>> extends true ? import("elysia").ResolvePath<`${Path}/health`> : import("elysia/types").IntersectIfObject<import("elysia").ResolvePath<import("elysia/types").JoinPath<"", `${Path}/health`>>, unknown> extends infer T_2 ? { [K_2 in keyof T_2]: T_2[K_2]; } : never;
|
|
243
|
+
query: {};
|
|
244
|
+
headers: {};
|
|
245
|
+
response: import("elysia").ComposeElysiaResponse<import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<Partial<{
|
|
246
|
+
readonly live: LiveRoute<C>;
|
|
247
|
+
}> & import("elysia").InputSchema<never>, {}, import("elysia/types").JoinPath<"", `${Path}/health`>>, {}> & {
|
|
248
|
+
return: unknown;
|
|
249
|
+
}, () => import("./live.js").LiveHealth, {}> extends infer T_3 ? { [K_3 in keyof T_3]: T_3[K_3]; } : never;
|
|
250
|
+
};
|
|
251
|
+
}>, {
|
|
252
|
+
derive: {};
|
|
253
|
+
resolve: {};
|
|
254
|
+
schema: {};
|
|
255
|
+
standaloneSchema: {};
|
|
256
|
+
response: {};
|
|
257
|
+
}, {
|
|
258
|
+
derive: {};
|
|
259
|
+
resolve: {};
|
|
260
|
+
schema: {};
|
|
261
|
+
standaloneSchema: {};
|
|
262
|
+
response: {};
|
|
263
|
+
}>;
|
|
264
|
+
/** Tell the hub which app its live routes are in. Call it once the app is built. */
|
|
265
|
+
export declare function bindLive<C extends Caller | null>(live: Live<C>, app: AppLike): void;
|
|
266
|
+
/** Runs a route through `app.handle`, refusing any not marked live by this hub. */
|
|
267
|
+
export declare function appRunner(app: AppLike, marks: WeakSet<object>): Runner;
|
|
268
|
+
export {};
|