@roko-app/instant-admin 0.0.0-stage → 1.0.67-roko.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tshy/build.json +8 -0
- package/.tshy/commonjs.json +16 -0
- package/.tshy/esm.json +15 -0
- package/LICENSE +202 -0
- package/README.md +43 -2
- package/dist/commonjs/__types__/typeUtils.d.ts +20 -0
- package/dist/commonjs/__types__/typeUtils.d.ts.map +1 -0
- package/dist/commonjs/__types__/typeUtils.js +5 -0
- package/dist/commonjs/__types__/typeUtils.js.map +1 -0
- package/dist/commonjs/__types__/typesTests.d.ts +2 -0
- package/dist/commonjs/__types__/typesTests.d.ts.map +1 -0
- package/dist/commonjs/__types__/typesTests.js +88 -0
- package/dist/commonjs/__types__/typesTests.js.map +1 -0
- package/dist/commonjs/index.d.ts +608 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +1050 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/polyfill.d.ts +17 -0
- package/dist/commonjs/polyfill.d.ts.map +1 -0
- package/dist/commonjs/polyfill.js +26 -0
- package/dist/commonjs/polyfill.js.map +1 -0
- package/dist/commonjs/subscribe.d.ts +39 -0
- package/dist/commonjs/subscribe.d.ts.map +1 -0
- package/dist/commonjs/subscribe.js +306 -0
- package/dist/commonjs/subscribe.js.map +1 -0
- package/dist/commonjs/version.d.ts +3 -0
- package/dist/commonjs/version.d.ts.map +1 -0
- package/dist/commonjs/version.js +5 -0
- package/dist/commonjs/version.js.map +1 -0
- package/dist/esm/__types__/typeUtils.d.ts +20 -0
- package/dist/esm/__types__/typeUtils.d.ts.map +1 -0
- package/dist/esm/__types__/typeUtils.js +4 -0
- package/dist/esm/__types__/typeUtils.js.map +1 -0
- package/dist/esm/__types__/typesTests.d.ts +2 -0
- package/dist/esm/__types__/typesTests.d.ts.map +1 -0
- package/dist/esm/__types__/typesTests.js +86 -0
- package/dist/esm/__types__/typesTests.js.map +1 -0
- package/dist/esm/index.d.ts +608 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +1037 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/polyfill.d.ts +17 -0
- package/dist/esm/polyfill.d.ts.map +1 -0
- package/dist/esm/polyfill.js +22 -0
- package/dist/esm/polyfill.js.map +1 -0
- package/dist/esm/subscribe.d.ts +39 -0
- package/dist/esm/subscribe.d.ts.map +1 -0
- package/dist/esm/subscribe.js +300 -0
- package/dist/esm/subscribe.js.map +1 -0
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +44 -3
- package/src/__types__/typeUtils.ts +39 -0
- package/src/__types__/typesTests.ts +139 -0
- package/src/index.ts +1731 -0
- package/src/polyfill.ts +39 -0
- package/src/subscribe.ts +442 -0
- package/src/version.ts +3 -0
- package/tsconfig.dev.json +14 -0
- package/tsconfig.json +11 -0
- package/tsconfig.test.json +5 -0
package/src/polyfill.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// MessageEvent is not supported in the edge runtime, vercel
|
|
2
|
+
// defines its own MessageEvent that throws. There is no easy
|
|
3
|
+
// way to detect if MessageEvent is supported, so we just always
|
|
4
|
+
// polyfill by passing it in to eventsource.
|
|
5
|
+
export class MessageEventPolyfill<T = any> extends Event {
|
|
6
|
+
readonly data: T;
|
|
7
|
+
readonly origin: string;
|
|
8
|
+
readonly lastEventId: string;
|
|
9
|
+
readonly source: MessageEventSource | null;
|
|
10
|
+
readonly ports: ReadonlyArray<MessagePort>;
|
|
11
|
+
constructor(
|
|
12
|
+
type: string,
|
|
13
|
+
init?: {
|
|
14
|
+
data?: T;
|
|
15
|
+
origin?: string;
|
|
16
|
+
lastEventId?: string;
|
|
17
|
+
source?: MessageEventSource | null;
|
|
18
|
+
ports?: MessagePort[];
|
|
19
|
+
},
|
|
20
|
+
) {
|
|
21
|
+
super(type);
|
|
22
|
+
this.data = init?.data ?? (null as T);
|
|
23
|
+
this.origin = init?.origin ?? '';
|
|
24
|
+
this.lastEventId = init?.lastEventId ?? '';
|
|
25
|
+
this.source = init?.source ?? null;
|
|
26
|
+
this.ports = init?.ports ?? [];
|
|
27
|
+
}
|
|
28
|
+
/** @deprecated */
|
|
29
|
+
initMessageEvent(
|
|
30
|
+
_type: string,
|
|
31
|
+
_bubbles?: boolean,
|
|
32
|
+
_cancelable?: boolean,
|
|
33
|
+
_data?: any,
|
|
34
|
+
_origin?: string,
|
|
35
|
+
_lastEventId?: string,
|
|
36
|
+
_source?: MessageEventSource | null,
|
|
37
|
+
_ports?: MessagePort[],
|
|
38
|
+
) {}
|
|
39
|
+
}
|
package/src/subscribe.ts
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { EventSource } from '@instantdb/eventsource';
|
|
2
|
+
import version from './version.ts';
|
|
3
|
+
import {
|
|
4
|
+
id,
|
|
5
|
+
version as coreVersion,
|
|
6
|
+
InstantAPIError,
|
|
7
|
+
InstantConfig,
|
|
8
|
+
InstantSchemaDef,
|
|
9
|
+
InstaQLResponse,
|
|
10
|
+
ValidQuery,
|
|
11
|
+
PageInfoResponse,
|
|
12
|
+
} from '@instantdb/core';
|
|
13
|
+
import { MessageEventPolyfill } from './polyfill.ts';
|
|
14
|
+
|
|
15
|
+
export type SubscriptionReadyState = 'closed' | 'connecting' | 'open';
|
|
16
|
+
|
|
17
|
+
export type SubscribeQuerySessionInfo = {
|
|
18
|
+
machineId: string;
|
|
19
|
+
sessionId: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type SubscribeQueryPayload<
|
|
23
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
24
|
+
Q extends ValidQuery<Q, Schema>,
|
|
25
|
+
UseDates extends boolean = false,
|
|
26
|
+
> =
|
|
27
|
+
| {
|
|
28
|
+
type: 'ok';
|
|
29
|
+
data: InstaQLResponse<Schema, Q, UseDates>;
|
|
30
|
+
pageInfo: PageInfoResponse<Q> | undefined;
|
|
31
|
+
sessionInfo: SubscribeQuerySessionInfo | null;
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
type: 'error';
|
|
35
|
+
error: InstantAPIError;
|
|
36
|
+
readyState: SubscriptionReadyState;
|
|
37
|
+
isClosed: boolean;
|
|
38
|
+
sessionInfo: SubscribeQuerySessionInfo | null;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type SubscribeQueryCallback<
|
|
42
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
43
|
+
Q extends ValidQuery<Q, Schema>,
|
|
44
|
+
UseDates extends boolean = false,
|
|
45
|
+
> = (payload: SubscribeQueryPayload<Schema, Q, UseDates>) => void;
|
|
46
|
+
|
|
47
|
+
export interface SubscribeQueryResponse<
|
|
48
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
49
|
+
Q extends ValidQuery<Q, Schema>,
|
|
50
|
+
UseDates extends boolean = false,
|
|
51
|
+
> {
|
|
52
|
+
/** Stop the subscription and close the connection. */
|
|
53
|
+
close(): void;
|
|
54
|
+
|
|
55
|
+
/** Warns when attempting to iterate synchronously */
|
|
56
|
+
[Symbol.iterator](): never;
|
|
57
|
+
|
|
58
|
+
/** Async iterator of query payloads */
|
|
59
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<
|
|
60
|
+
SubscribeQueryPayload<Schema, Q, UseDates>
|
|
61
|
+
>;
|
|
62
|
+
|
|
63
|
+
/** Ready state of the connection */
|
|
64
|
+
readonly readyState: SubscriptionReadyState;
|
|
65
|
+
|
|
66
|
+
/** `true` if the connection is closed and no more payloads will be delivered */
|
|
67
|
+
readonly isClosed: boolean;
|
|
68
|
+
|
|
69
|
+
/** Debug info about the session. Will return null while the session is initializing. */
|
|
70
|
+
readonly sessionInfo: SubscribeQuerySessionInfo | null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function makeAsyncIterator<
|
|
74
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
75
|
+
Q extends ValidQuery<Q, Schema>,
|
|
76
|
+
UseDates extends boolean = false,
|
|
77
|
+
>(
|
|
78
|
+
subscribe: (cb: SubscribeQueryCallback<Schema, Q, UseDates>) => void,
|
|
79
|
+
subscribeOnClose: (cb: () => void) => void,
|
|
80
|
+
unsubscribe: (cb: SubscribeQueryCallback<Schema, Q, UseDates>) => void,
|
|
81
|
+
readyState: () => SubscriptionReadyState,
|
|
82
|
+
): AsyncGenerator<SubscribeQueryPayload<Schema, Q, UseDates>> {
|
|
83
|
+
let wakeup: (() => void) | null = null;
|
|
84
|
+
let closed = false;
|
|
85
|
+
|
|
86
|
+
const backlog: SubscribeQueryPayload<Schema, Q, UseDates>[] = [];
|
|
87
|
+
const handler: SubscribeQueryCallback<Schema, Q, UseDates> = (
|
|
88
|
+
data: SubscribeQueryPayload<Schema, Q, UseDates>,
|
|
89
|
+
): void => {
|
|
90
|
+
backlog.push(data);
|
|
91
|
+
if (backlog.length > 100) {
|
|
92
|
+
// Remove the oldest item to prevent the backlog
|
|
93
|
+
// from growing forever. This is okay for live queries,
|
|
94
|
+
// but we need some other machanism if we use this for
|
|
95
|
+
// event-based subscriptions.
|
|
96
|
+
backlog.shift();
|
|
97
|
+
}
|
|
98
|
+
if (wakeup) {
|
|
99
|
+
wakeup();
|
|
100
|
+
wakeup = null;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
subscribe(handler);
|
|
105
|
+
|
|
106
|
+
const done = (): Promise<{
|
|
107
|
+
done: true;
|
|
108
|
+
value: undefined;
|
|
109
|
+
}> => {
|
|
110
|
+
unsubscribe(handler);
|
|
111
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const onClose = () => {
|
|
115
|
+
closed = true;
|
|
116
|
+
if (wakeup) {
|
|
117
|
+
wakeup();
|
|
118
|
+
}
|
|
119
|
+
done();
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
subscribeOnClose(onClose);
|
|
123
|
+
|
|
124
|
+
const next = async (): Promise<
|
|
125
|
+
IteratorResult<SubscribeQueryPayload<Schema, Q, UseDates>, undefined>
|
|
126
|
+
> => {
|
|
127
|
+
while (true) {
|
|
128
|
+
if (readyState() === 'closed' || closed) {
|
|
129
|
+
return done();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const nextValue = backlog.shift();
|
|
133
|
+
if (nextValue) {
|
|
134
|
+
return { value: nextValue, done: false };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const p = new Promise<void>((resolve) => {
|
|
138
|
+
wakeup = resolve;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
await p;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
next,
|
|
147
|
+
return: done,
|
|
148
|
+
throw(error) {
|
|
149
|
+
unsubscribe(handler);
|
|
150
|
+
return Promise.reject(error);
|
|
151
|
+
},
|
|
152
|
+
[Symbol.asyncIterator]() {
|
|
153
|
+
return this;
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function esReadyState(es: EventSource): SubscriptionReadyState {
|
|
159
|
+
switch (es.readyState) {
|
|
160
|
+
case es.CLOSED: {
|
|
161
|
+
return 'closed';
|
|
162
|
+
}
|
|
163
|
+
case es.CONNECTING: {
|
|
164
|
+
return 'connecting';
|
|
165
|
+
}
|
|
166
|
+
case es.OPEN: {
|
|
167
|
+
return 'open';
|
|
168
|
+
}
|
|
169
|
+
default:
|
|
170
|
+
return 'connecting';
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function multiReadFetchResponse(r: Response) {
|
|
175
|
+
let p: null | Promise<string> = null;
|
|
176
|
+
return {
|
|
177
|
+
...r,
|
|
178
|
+
text() {
|
|
179
|
+
if (!p) {
|
|
180
|
+
p = r.text();
|
|
181
|
+
}
|
|
182
|
+
return p;
|
|
183
|
+
},
|
|
184
|
+
json() {
|
|
185
|
+
if (!p) {
|
|
186
|
+
p = r.text();
|
|
187
|
+
}
|
|
188
|
+
return p.then((x) => JSON.parse(x));
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type APIPageInfo = {
|
|
194
|
+
[etype: string]: {
|
|
195
|
+
'start-cursor': [string, string, any, number];
|
|
196
|
+
'end-cursor': [string, string, any, number];
|
|
197
|
+
'has-next-page?': boolean;
|
|
198
|
+
'has-previous-page?': boolean;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
function formatPageInfo(
|
|
203
|
+
pageInfo: APIPageInfo | null | undefined,
|
|
204
|
+
): PageInfoResponse<any> | undefined {
|
|
205
|
+
if (!pageInfo) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
const res: PageInfoResponse<any> = {};
|
|
209
|
+
|
|
210
|
+
for (const [k, v] of Object.entries(pageInfo)) {
|
|
211
|
+
res[k] = {
|
|
212
|
+
startCursor: v['start-cursor'],
|
|
213
|
+
endCursor: v['end-cursor'],
|
|
214
|
+
hasNextPage: v['has-next-page?'],
|
|
215
|
+
hasPreviousPage: v['has-previous-page?'],
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return res;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function subscribe<
|
|
223
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
224
|
+
Q extends ValidQuery<Q, Schema>,
|
|
225
|
+
UseDates extends boolean,
|
|
226
|
+
>(
|
|
227
|
+
query: Q,
|
|
228
|
+
cb: SubscribeQueryCallback<Schema, Q, UseDates> | undefined,
|
|
229
|
+
opts: { headers: HeadersInit; inference: boolean; apiURI: string },
|
|
230
|
+
): SubscribeQueryResponse<Schema, Q, UseDates> {
|
|
231
|
+
let fetchErrorResponse;
|
|
232
|
+
let closed = false;
|
|
233
|
+
|
|
234
|
+
// Stable id that will stay the same across reconnects,
|
|
235
|
+
// used for debugging
|
|
236
|
+
const localConnectionId = id();
|
|
237
|
+
|
|
238
|
+
const es = new EventSource(
|
|
239
|
+
`${opts.apiURI}/admin/subscribe-query?local_connection_id=${localConnectionId}`,
|
|
240
|
+
{
|
|
241
|
+
messageEvent: MessageEventPolyfill,
|
|
242
|
+
fetch(input, init) {
|
|
243
|
+
fetchErrorResponse = null;
|
|
244
|
+
return fetch(input, {
|
|
245
|
+
...init,
|
|
246
|
+
method: 'POST',
|
|
247
|
+
headers: opts.headers,
|
|
248
|
+
body: JSON.stringify({
|
|
249
|
+
query: query,
|
|
250
|
+
'inference?': opts.inference,
|
|
251
|
+
versions: {
|
|
252
|
+
'@instantdb/admin': version,
|
|
253
|
+
'@instantdb/core': coreVersion,
|
|
254
|
+
},
|
|
255
|
+
}),
|
|
256
|
+
}).then((r) => {
|
|
257
|
+
if (!r.ok) {
|
|
258
|
+
fetchErrorResponse = multiReadFetchResponse(r);
|
|
259
|
+
}
|
|
260
|
+
return r;
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const subscribers: SubscribeQueryCallback<Schema, Q, UseDates>[] = [];
|
|
267
|
+
const onCloseSubscribers: (() => void)[] = [];
|
|
268
|
+
|
|
269
|
+
const subscribe = (cb) => {
|
|
270
|
+
subscribers.push(cb);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const unsubscribe = (cb) => {
|
|
274
|
+
subscribers.splice(subscribers.indexOf(cb), 1);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const subscribeOnClose = (cb) => {
|
|
278
|
+
onCloseSubscribers.push(cb);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
if (cb) {
|
|
282
|
+
subscribe(cb);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let sessionParams: SubscribeQuerySessionInfo | null = null;
|
|
286
|
+
|
|
287
|
+
function deliver(result: SubscribeQueryPayload<Schema, Q, UseDates>) {
|
|
288
|
+
if (closed) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
for (const sub of subscribers) {
|
|
292
|
+
try {
|
|
293
|
+
sub(result);
|
|
294
|
+
} catch (e) {
|
|
295
|
+
console.error('Error in subscribeQuery callback', e);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function handleMessage(msg) {
|
|
301
|
+
switch (msg.op) {
|
|
302
|
+
case 'sse-init': {
|
|
303
|
+
const machineId = msg['machine-id'];
|
|
304
|
+
const sessionId = msg['session-id'];
|
|
305
|
+
sessionParams = { machineId, sessionId };
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case 'add-query-ok': {
|
|
309
|
+
deliver({
|
|
310
|
+
type: 'ok',
|
|
311
|
+
data: msg.result,
|
|
312
|
+
pageInfo: formatPageInfo(msg['result-meta']?.['page-info']),
|
|
313
|
+
sessionInfo: sessionParams,
|
|
314
|
+
});
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case 'refresh-ok': {
|
|
318
|
+
if (msg.computations.length) {
|
|
319
|
+
deliver({
|
|
320
|
+
type: 'ok',
|
|
321
|
+
data: msg.computations[0]['instaql-result'],
|
|
322
|
+
pageInfo: formatPageInfo(
|
|
323
|
+
msg.computations[0]['result-meta']?.['page-info'],
|
|
324
|
+
),
|
|
325
|
+
sessionInfo: sessionParams,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
case 'error': {
|
|
331
|
+
deliver({
|
|
332
|
+
type: 'error',
|
|
333
|
+
error: new InstantAPIError({ body: msg, status: msg.status }),
|
|
334
|
+
get readyState() {
|
|
335
|
+
return esReadyState(es);
|
|
336
|
+
},
|
|
337
|
+
get isClosed() {
|
|
338
|
+
return esReadyState(es) === 'closed';
|
|
339
|
+
},
|
|
340
|
+
sessionInfo: sessionParams,
|
|
341
|
+
});
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
es.onerror = (e) => {
|
|
348
|
+
if (fetchErrorResponse) {
|
|
349
|
+
fetchErrorResponse.text().then((t) => {
|
|
350
|
+
let body = { type: undefined, message: t };
|
|
351
|
+
try {
|
|
352
|
+
body = JSON.parse(t);
|
|
353
|
+
} catch (_e) {}
|
|
354
|
+
deliver({
|
|
355
|
+
type: 'error',
|
|
356
|
+
error: new InstantAPIError({
|
|
357
|
+
status: fetchErrorResponse.status,
|
|
358
|
+
body,
|
|
359
|
+
}),
|
|
360
|
+
get readyState() {
|
|
361
|
+
return esReadyState(es);
|
|
362
|
+
},
|
|
363
|
+
get isClosed() {
|
|
364
|
+
return esReadyState(es) === 'closed';
|
|
365
|
+
},
|
|
366
|
+
sessionInfo: sessionParams,
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
} else {
|
|
370
|
+
const deliverError = () => {
|
|
371
|
+
deliver({
|
|
372
|
+
type: 'error',
|
|
373
|
+
error: new InstantAPIError({
|
|
374
|
+
status: e.code || 500,
|
|
375
|
+
body: {
|
|
376
|
+
type: undefined,
|
|
377
|
+
message: e.message || 'Unknown error in subscribe query.',
|
|
378
|
+
},
|
|
379
|
+
}),
|
|
380
|
+
get readyState() {
|
|
381
|
+
return esReadyState(es);
|
|
382
|
+
},
|
|
383
|
+
get isClosed() {
|
|
384
|
+
return esReadyState(es) === 'closed';
|
|
385
|
+
},
|
|
386
|
+
sessionInfo: sessionParams,
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
if (es.readyState === EventSource.CLOSED) {
|
|
390
|
+
deliverError();
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
setTimeout(() => {
|
|
395
|
+
if (es.readyState !== EventSource.OPEN) {
|
|
396
|
+
deliverError();
|
|
397
|
+
}
|
|
398
|
+
}, 5000);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
es.onmessage = (e) => {
|
|
403
|
+
handleMessage(JSON.parse(e.data));
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const close = () => {
|
|
407
|
+
closed = true;
|
|
408
|
+
for (const sub of onCloseSubscribers) {
|
|
409
|
+
try {
|
|
410
|
+
sub();
|
|
411
|
+
} catch (e) {
|
|
412
|
+
console.error('Error in onClose callback', e);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
es.close();
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
return {
|
|
419
|
+
close: close,
|
|
420
|
+
[Symbol.iterator]: () => {
|
|
421
|
+
throw new Error(
|
|
422
|
+
'subscribeQuery does not support synchronous iteration. Use `for await` instead.',
|
|
423
|
+
);
|
|
424
|
+
},
|
|
425
|
+
get sessionInfo() {
|
|
426
|
+
return sessionParams;
|
|
427
|
+
},
|
|
428
|
+
get readyState() {
|
|
429
|
+
return esReadyState(es);
|
|
430
|
+
},
|
|
431
|
+
get isClosed() {
|
|
432
|
+
return esReadyState(es) === 'closed';
|
|
433
|
+
},
|
|
434
|
+
[Symbol.asyncIterator]: makeAsyncIterator.bind(
|
|
435
|
+
this,
|
|
436
|
+
subscribe,
|
|
437
|
+
subscribeOnClose,
|
|
438
|
+
unsubscribe,
|
|
439
|
+
() => 1,
|
|
440
|
+
),
|
|
441
|
+
};
|
|
442
|
+
}
|
package/src/version.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "es2022",
|
|
5
|
+
"target": "es2022",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
|
|
8
|
+
"outDir": "./dist/esm",
|
|
9
|
+
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationDir": "./dist/esm",
|
|
12
|
+
"incremental": true
|
|
13
|
+
}
|
|
14
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"],
|
|
4
|
+
"exclude": ["node_modules", "dist", "src/__types__"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"outDir": "dist/tsc",
|
|
7
|
+
"rewriteRelativeImportExtensions": true,
|
|
8
|
+
"rootDir": "src",
|
|
9
|
+
"strictNullChecks": true
|
|
10
|
+
}
|
|
11
|
+
}
|