@instantdb/admin 0.22.139-experimental.streams.22079869443.1 → 0.22.139
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/dist/commonjs/index.d.ts +2 -42
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +18 -251
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +2 -42
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +19 -252
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +54 -399
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
|
-
import { tx, lookup, i, id, InstantAPIError, setInstantWarningsEnabled, type InstantIssue, type TransactionChunk, type AuthToken, type User, type Query, type QueryResponse, type InstaQLResponse, type InstaQLParams, type ValidQuery, type InstaQLFields, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type BackwardsCompatibleSchema, type IInstantDatabase, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type InstantUnknownSchemaDef, type LinksDef, type RoomsOf, type RoomsDef, type PresenceOf, type RoomHandle, type ResolveAttrs, type ValueTypes, type InstantSchemaDef, type InstantUnknownSchema, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type InstantRules, type UpdateParams, type CreateParams, type LinkParams, type RuleParams, type FileOpts, type UploadFileResponse, type DeleteFileResponse, createInstantRouteHandler
|
|
2
|
+
import { tx, lookup, i, id, InstantAPIError, setInstantWarningsEnabled, type InstantIssue, type TransactionChunk, type AuthToken, type User, type Query, type QueryResponse, type InstaQLResponse, type InstaQLParams, type ValidQuery, type InstaQLFields, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type BackwardsCompatibleSchema, type IInstantDatabase, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type InstantUnknownSchemaDef, type LinksDef, type RoomsOf, type RoomsDef, type PresenceOf, type RoomHandle, type ResolveAttrs, type ValueTypes, type InstantSchemaDef, type InstantUnknownSchema, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type InstantRules, type UpdateParams, type CreateParams, type LinkParams, type RuleParams, type FileOpts, type UploadFileResponse, type DeleteFileResponse, createInstantRouteHandler } from '@instantdb/core';
|
|
3
3
|
import { SubscribeQueryCallback, SubscribeQueryResponse, SubscribeQueryPayload, SubscriptionReadyState } from './subscribe.ts';
|
|
4
4
|
type DebugCheckResult = {
|
|
5
5
|
/** The ID of the record. */
|
|
@@ -25,9 +25,6 @@ export type InstantConfig<Schema extends InstantSchemaDef<any, any, any>, UseDat
|
|
|
25
25
|
schema?: Schema;
|
|
26
26
|
useDateObjects: UseDates;
|
|
27
27
|
disableValidation?: boolean;
|
|
28
|
-
verbose?: boolean;
|
|
29
|
-
WritableStream?: WritableStreamCtor;
|
|
30
|
-
ReadableStream?: ReadableStreamCtor;
|
|
31
28
|
};
|
|
32
29
|
type InstantConfigFilled<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean> = InstantConfig<Schema, UseDates> & {
|
|
33
30
|
apiURI: string;
|
|
@@ -353,41 +350,6 @@ declare class Storage {
|
|
|
353
350
|
*/
|
|
354
351
|
getDownloadUrl: (pathname: string) => Promise<string>;
|
|
355
352
|
}
|
|
356
|
-
type CreateReadStreamOpts = {
|
|
357
|
-
clientId?: string | null | undefined;
|
|
358
|
-
streamId?: string | null | undefined;
|
|
359
|
-
byteOffset?: number | null | undefined;
|
|
360
|
-
};
|
|
361
|
-
type CreateWriteStreamOpts = {
|
|
362
|
-
clientId: string;
|
|
363
|
-
};
|
|
364
|
-
/**
|
|
365
|
-
* Functions to manage streams.
|
|
366
|
-
*/
|
|
367
|
-
declare class Streams {
|
|
368
|
-
#private;
|
|
369
|
-
constructor(ensureInstantStream: () => InstantStream);
|
|
370
|
-
/**
|
|
371
|
-
* Creates a new ReadableStream for the given clientId.
|
|
372
|
-
*
|
|
373
|
-
* @example
|
|
374
|
-
* const stream = db.streams.createReadStream({clientId: clientId})
|
|
375
|
-
* for await (const chunk of stream) {
|
|
376
|
-
* console.log(chunk);
|
|
377
|
-
* }
|
|
378
|
-
*/
|
|
379
|
-
createReadStream: (opts: CreateReadStreamOpts) => ReadableStream<string>;
|
|
380
|
-
/**
|
|
381
|
-
* Creates a new WritableStream for the given clientId.
|
|
382
|
-
*
|
|
383
|
-
* @example
|
|
384
|
-
* const writeStream = db.streams.createWriteStream({clientId: clientId})
|
|
385
|
-
* const writer = writeStream.getWriter();
|
|
386
|
-
* writer.write('Hello world');
|
|
387
|
-
* writer.close();
|
|
388
|
-
*/
|
|
389
|
-
createWriteStream: (opts: CreateWriteStreamOpts) => InstantWritableStream<string>;
|
|
390
|
-
}
|
|
391
353
|
type AdminQueryOpts = {
|
|
392
354
|
ruleParams?: RuleParams;
|
|
393
355
|
fetchOpts?: RequestInit;
|
|
@@ -402,11 +364,9 @@ type AdminQueryOpts = {
|
|
|
402
364
|
* const db = init({ appId: "my-app-id", adminToken: "my-admin-token" })
|
|
403
365
|
*/
|
|
404
366
|
declare class InstantAdminDatabase<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean = false, Config extends InstantConfig<Schema, UseDates> = InstantConfig<Schema, UseDates>> {
|
|
405
|
-
#private;
|
|
406
367
|
config: InstantConfigFilled<Schema, UseDates>;
|
|
407
368
|
auth: Auth;
|
|
408
369
|
storage: Storage;
|
|
409
|
-
streams: Streams;
|
|
410
370
|
rooms: Rooms<Schema>;
|
|
411
371
|
impersonationOpts?: ImpersonationOpts;
|
|
412
372
|
tx: import("@instantdb/core").TxChunk<NonNullable<Schema>>;
|
|
@@ -553,5 +513,5 @@ declare class InstantAdminDatabase<Schema extends InstantSchemaDef<any, any, any
|
|
|
553
513
|
origin?: string | null | undefined;
|
|
554
514
|
}) => Promise<DebugTransactResult>;
|
|
555
515
|
}
|
|
556
|
-
export { init, init_experimental, id, tx, lookup, i, createInstantRouteHandler, InstantAPIError, setInstantWarningsEnabled, type Config, type ImpersonationOpts, type TransactionChunk, type DebugCheckResult, type InstantAdminDatabase, type User, type InstaQLParams, type ValidQuery, type Query, type QueryResponse, type InstaQLResponse, type InstantQuery, type InstantUnknownSchemaDef, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type IInstantDatabase, type InstantObject, type InstantEntity, type BackwardsCompatibleSchema, type InstaQLFields, type SubscribeQueryCallback, type SubscribeQueryResponse, type SubscribeQueryPayload, type SubscriptionReadyState, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type RoomsOf, type PresenceOf, type RoomsDef, type RoomHandle, type ValueTypes, type InstantSchemaDef, type InstantUnknownSchema, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type InstantRules, type CreateParams, type UpdateParams, type LinkParams, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type DeleteManyFileResponse, type
|
|
516
|
+
export { init, init_experimental, id, tx, lookup, i, createInstantRouteHandler, InstantAPIError, setInstantWarningsEnabled, type Config, type ImpersonationOpts, type TransactionChunk, type DebugCheckResult, type InstantAdminDatabase, type User, type InstaQLParams, type ValidQuery, type Query, type QueryResponse, type InstaQLResponse, type InstantQuery, type InstantUnknownSchemaDef, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type IInstantDatabase, type InstantObject, type InstantEntity, type BackwardsCompatibleSchema, type InstaQLFields, type SubscribeQueryCallback, type SubscribeQueryResponse, type SubscribeQueryPayload, type SubscriptionReadyState, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type RoomsOf, type PresenceOf, type RoomsDef, type RoomHandle, type ValueTypes, type InstantSchemaDef, type InstantUnknownSchema, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type InstantRules, type CreateParams, type UpdateParams, type LinkParams, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type DeleteManyFileResponse, type InstantIssue, };
|
|
557
517
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EACL,EAAE,EACF,MAAM,EAEN,CAAC,EACD,EAAE,EAGF,eAAe,EACf,yBAAyB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EAGd,KAAK,IAAI,EACT,KAAK,KAAK,EAGV,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EAGrB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAA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,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EAGf,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAG3B,KAAK,YAAY,GAClB,CAAC"}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -17,7 +17,6 @@ Object.defineProperty(exports, "createInstantRouteHandler", { enumerable: true,
|
|
|
17
17
|
const version_ts_1 = __importDefault(require("./version.js"));
|
|
18
18
|
const subscribe_ts_1 = require("./subscribe.js");
|
|
19
19
|
const cookie_1 = require("cookie");
|
|
20
|
-
const eventsource_1 = require("eventsource");
|
|
21
20
|
function configWithDefaults(config) {
|
|
22
21
|
const defaultConfig = {
|
|
23
22
|
apiURI: 'https://api.instantdb.com',
|
|
@@ -119,62 +118,6 @@ async function jsonFetch(input, init) {
|
|
|
119
118
|
}
|
|
120
119
|
return jsonReject((x) => Promise.reject(x), res);
|
|
121
120
|
}
|
|
122
|
-
function makeEventSourceWrapper(opts) {
|
|
123
|
-
return class EventSourceWrapper {
|
|
124
|
-
source;
|
|
125
|
-
static OPEN = eventsource_1.EventSource.OPEN;
|
|
126
|
-
static CONNECTING = eventsource_1.EventSource.CONNECTING;
|
|
127
|
-
static CLOSED = eventsource_1.EventSource.CLOSED;
|
|
128
|
-
url;
|
|
129
|
-
constructor(url) {
|
|
130
|
-
this.url = url;
|
|
131
|
-
this.source = this.#createEventSource(url);
|
|
132
|
-
}
|
|
133
|
-
get onopen() {
|
|
134
|
-
return this.source.onopen;
|
|
135
|
-
}
|
|
136
|
-
set onopen(fn) {
|
|
137
|
-
this.source.onopen = fn;
|
|
138
|
-
}
|
|
139
|
-
get onmessage() {
|
|
140
|
-
return this.source.onmessage;
|
|
141
|
-
}
|
|
142
|
-
set onmessage(fn) {
|
|
143
|
-
this.source.onmessage = fn;
|
|
144
|
-
}
|
|
145
|
-
get onerror() {
|
|
146
|
-
return this.source.onerror;
|
|
147
|
-
}
|
|
148
|
-
set onerror(fn) {
|
|
149
|
-
this.source.onerror = fn;
|
|
150
|
-
}
|
|
151
|
-
get readyState() {
|
|
152
|
-
return this.source.readyState;
|
|
153
|
-
}
|
|
154
|
-
close() {
|
|
155
|
-
this.source.close();
|
|
156
|
-
}
|
|
157
|
-
#createEventSource(url) {
|
|
158
|
-
const es = new eventsource_1.EventSource(url, {
|
|
159
|
-
fetch(input, init) {
|
|
160
|
-
return fetch(input, {
|
|
161
|
-
...init,
|
|
162
|
-
method: 'POST',
|
|
163
|
-
headers: opts.headers,
|
|
164
|
-
body: JSON.stringify({
|
|
165
|
-
'inference?': opts.inference,
|
|
166
|
-
versions: {
|
|
167
|
-
'@instantdb/admin': version_ts_1.default,
|
|
168
|
-
'@instantdb/core': core_1.version,
|
|
169
|
-
},
|
|
170
|
-
}),
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
return es;
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
121
|
/**
|
|
179
122
|
*
|
|
180
123
|
* The first step: init your application!
|
|
@@ -243,7 +186,7 @@ class Rooms {
|
|
|
243
186
|
this.config = config;
|
|
244
187
|
}
|
|
245
188
|
async getPresence(roomType, roomId) {
|
|
246
|
-
const res = await jsonFetch(`${this.config.apiURI}/admin/rooms/presence?
|
|
189
|
+
const res = await jsonFetch(`${this.config.apiURI}/admin/rooms/presence?room-type=${String(roomType)}&room-id=${roomId}`, {
|
|
247
190
|
method: 'GET',
|
|
248
191
|
headers: authorizedHeaders(this.config),
|
|
249
192
|
});
|
|
@@ -270,7 +213,7 @@ class Auth {
|
|
|
270
213
|
* @see https://instantdb.com/docs/backend#custom-magic-codes
|
|
271
214
|
*/
|
|
272
215
|
generateMagicCode = async (email) => {
|
|
273
|
-
return jsonFetch(`${this.config.apiURI}/admin/magic_code
|
|
216
|
+
return jsonFetch(`${this.config.apiURI}/admin/magic_code`, {
|
|
274
217
|
method: 'POST',
|
|
275
218
|
headers: authorizedHeaders(this.config),
|
|
276
219
|
body: JSON.stringify({ email }),
|
|
@@ -287,7 +230,7 @@ class Auth {
|
|
|
287
230
|
* @see https://instantdb.com/docs/backend#custom-magic-codes
|
|
288
231
|
*/
|
|
289
232
|
sendMagicCode = async (email) => {
|
|
290
|
-
return jsonFetch(`${this.config.apiURI}/admin/send_magic_code
|
|
233
|
+
return jsonFetch(`${this.config.apiURI}/admin/send_magic_code`, {
|
|
291
234
|
method: 'POST',
|
|
292
235
|
headers: authorizedHeaders(this.config),
|
|
293
236
|
body: JSON.stringify({ email }),
|
|
@@ -303,7 +246,7 @@ class Auth {
|
|
|
303
246
|
* @see https://instantdb.com/docs/backend#custom-magic-codes
|
|
304
247
|
*/
|
|
305
248
|
verifyMagicCode = async (email, code) => {
|
|
306
|
-
const { user } = await jsonFetch(`${this.config.apiURI}/admin/verify_magic_code
|
|
249
|
+
const { user } = await jsonFetch(`${this.config.apiURI}/admin/verify_magic_code`, {
|
|
307
250
|
method: 'POST',
|
|
308
251
|
headers: authorizedHeaders(this.config),
|
|
309
252
|
body: JSON.stringify({ email, code }),
|
|
@@ -312,7 +255,7 @@ class Auth {
|
|
|
312
255
|
};
|
|
313
256
|
async createToken(input) {
|
|
314
257
|
const body = typeof input === 'string' ? { email: input } : input;
|
|
315
|
-
const ret = await jsonFetch(`${this.config.apiURI}/admin/refresh_tokens
|
|
258
|
+
const ret = await jsonFetch(`${this.config.apiURI}/admin/refresh_tokens`, {
|
|
316
259
|
method: 'POST',
|
|
317
260
|
headers: authorizedHeaders(this.config),
|
|
318
261
|
body: JSON.stringify(body),
|
|
@@ -336,7 +279,7 @@ class Auth {
|
|
|
336
279
|
* @see https://instantdb.com/docs/backend#custom-endpoints
|
|
337
280
|
*/
|
|
338
281
|
verifyToken = async (token) => {
|
|
339
|
-
const res = await jsonFetch(`${this.config.apiURI}/runtime/auth/verify_refresh_token
|
|
282
|
+
const res = await jsonFetch(`${this.config.apiURI}/runtime/auth/verify_refresh_token`, {
|
|
340
283
|
method: 'POST',
|
|
341
284
|
headers: { 'content-type': 'application/json' },
|
|
342
285
|
body: JSON.stringify({
|
|
@@ -363,7 +306,7 @@ class Auth {
|
|
|
363
306
|
const qs = Object.entries(params)
|
|
364
307
|
.map(([k, v]) => `${k}=${encodeURIComponent(v)}`)
|
|
365
308
|
.join('&');
|
|
366
|
-
const response = await jsonFetch(`${this.config.apiURI}/admin/users
|
|
309
|
+
const response = await jsonFetch(`${this.config.apiURI}/admin/users?${qs}`, {
|
|
367
310
|
method: 'GET',
|
|
368
311
|
headers: authorizedHeaders(this.config),
|
|
369
312
|
});
|
|
@@ -387,7 +330,7 @@ class Auth {
|
|
|
387
330
|
*/
|
|
388
331
|
deleteUser = async (params) => {
|
|
389
332
|
const qs = Object.entries(params).map(([k, v]) => `${k}=${v}`);
|
|
390
|
-
const response = await jsonFetch(`${this.config.apiURI}/admin/users
|
|
333
|
+
const response = await jsonFetch(`${this.config.apiURI}/admin/users?${qs}`, {
|
|
391
334
|
method: 'DELETE',
|
|
392
335
|
headers: authorizedHeaders(this.config),
|
|
393
336
|
});
|
|
@@ -399,7 +342,7 @@ class Auth {
|
|
|
399
342
|
// accept email strings. Eventually we can remove this
|
|
400
343
|
const params = typeof input === 'string' ? { email: input } : input;
|
|
401
344
|
const config = this.config;
|
|
402
|
-
await jsonFetch(`${config.apiURI}/admin/sign_out
|
|
345
|
+
await jsonFetch(`${config.apiURI}/admin/sign_out`, {
|
|
403
346
|
method: 'POST',
|
|
404
347
|
headers: authorizedHeaders(config),
|
|
405
348
|
body: JSON.stringify(params),
|
|
@@ -484,7 +427,7 @@ class Storage {
|
|
|
484
427
|
body: file,
|
|
485
428
|
...(duplex && { duplex }),
|
|
486
429
|
};
|
|
487
|
-
return jsonFetch(`${this.config.apiURI}/admin/storage/upload
|
|
430
|
+
return jsonFetch(`${this.config.apiURI}/admin/storage/upload`, options);
|
|
488
431
|
};
|
|
489
432
|
/**
|
|
490
433
|
* Deletes a file by its path name (e.g. "photos/demo.png").
|
|
@@ -494,7 +437,7 @@ class Storage {
|
|
|
494
437
|
* await db.storage.delete("photos/demo.png");
|
|
495
438
|
*/
|
|
496
439
|
delete = async (pathname) => {
|
|
497
|
-
return jsonFetch(`${this.config.apiURI}/admin/storage/files?
|
|
440
|
+
return jsonFetch(`${this.config.apiURI}/admin/storage/files?filename=${encodeURIComponent(pathname)}`, {
|
|
498
441
|
method: 'DELETE',
|
|
499
442
|
headers: authorizedHeaders(this.config, this.impersonationOpts),
|
|
500
443
|
});
|
|
@@ -507,7 +450,7 @@ class Storage {
|
|
|
507
450
|
* await db.storage.deleteMany(["images/1.png", "images/2.png", "images/3.png"]);
|
|
508
451
|
*/
|
|
509
452
|
deleteMany = async (pathnames) => {
|
|
510
|
-
return jsonFetch(`${this.config.apiURI}/admin/storage/files/delete
|
|
453
|
+
return jsonFetch(`${this.config.apiURI}/admin/storage/files/delete`, {
|
|
511
454
|
method: 'POST',
|
|
512
455
|
headers: authorizedHeaders(this.config, this.impersonationOpts),
|
|
513
456
|
body: JSON.stringify({ filenames: pathnames }),
|
|
@@ -518,7 +461,7 @@ class Storage {
|
|
|
518
461
|
* instead
|
|
519
462
|
*/
|
|
520
463
|
upload = async (pathname, file, metadata = {}) => {
|
|
521
|
-
const { data: presignedUrl } = await jsonFetch(`${this.config.apiURI}/admin/storage/signed-upload-url
|
|
464
|
+
const { data: presignedUrl } = await jsonFetch(`${this.config.apiURI}/admin/storage/signed-upload-url`, {
|
|
522
465
|
method: 'POST',
|
|
523
466
|
headers: authorizedHeaders(this.config),
|
|
524
467
|
body: JSON.stringify({
|
|
@@ -544,7 +487,7 @@ class Storage {
|
|
|
544
487
|
* const files = await db.query({ $files: {}})
|
|
545
488
|
*/
|
|
546
489
|
list = async () => {
|
|
547
|
-
const { data } = await jsonFetch(`${this.config.apiURI}/admin/storage/files
|
|
490
|
+
const { data } = await jsonFetch(`${this.config.apiURI}/admin/storage/files`, {
|
|
548
491
|
method: 'GET',
|
|
549
492
|
headers: authorizedHeaders(this.config),
|
|
550
493
|
});
|
|
@@ -572,46 +515,6 @@ class Storage {
|
|
|
572
515
|
return data;
|
|
573
516
|
};
|
|
574
517
|
}
|
|
575
|
-
/**
|
|
576
|
-
* Functions to manage streams.
|
|
577
|
-
*/
|
|
578
|
-
class Streams {
|
|
579
|
-
#ensureInstantStream;
|
|
580
|
-
constructor(ensureInstantStream) {
|
|
581
|
-
this.#ensureInstantStream = ensureInstantStream;
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Creates a new ReadableStream for the given clientId.
|
|
585
|
-
*
|
|
586
|
-
* @example
|
|
587
|
-
* const stream = db.streams.createReadStream({clientId: clientId})
|
|
588
|
-
* for await (const chunk of stream) {
|
|
589
|
-
* console.log(chunk);
|
|
590
|
-
* }
|
|
591
|
-
*/
|
|
592
|
-
createReadStream = (opts) => {
|
|
593
|
-
return this.#ensureInstantStream().createReadStream(opts);
|
|
594
|
-
};
|
|
595
|
-
/**
|
|
596
|
-
* Creates a new WritableStream for the given clientId.
|
|
597
|
-
*
|
|
598
|
-
* @example
|
|
599
|
-
* const writeStream = db.streams.createWriteStream({clientId: clientId})
|
|
600
|
-
* const writer = writeStream.getWriter();
|
|
601
|
-
* writer.write('Hello world');
|
|
602
|
-
* writer.close();
|
|
603
|
-
*/
|
|
604
|
-
createWriteStream = (opts) => {
|
|
605
|
-
return this.#ensureInstantStream().createWriteStream(opts);
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
function createLogger(isEnabled) {
|
|
609
|
-
return {
|
|
610
|
-
info: isEnabled ? (...args) => console.info(...args) : () => { },
|
|
611
|
-
debug: isEnabled ? (...args) => console.debug(...args) : () => { },
|
|
612
|
-
error: isEnabled ? (...args) => console.error(...args) : () => { },
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
518
|
/**
|
|
616
519
|
*
|
|
617
520
|
* The first step: init your application!
|
|
@@ -625,21 +528,14 @@ class InstantAdminDatabase {
|
|
|
625
528
|
config;
|
|
626
529
|
auth;
|
|
627
530
|
storage;
|
|
628
|
-
streams;
|
|
629
531
|
rooms;
|
|
630
532
|
impersonationOpts;
|
|
631
|
-
#sseConnection = null;
|
|
632
|
-
#sseBackoff = 0;
|
|
633
|
-
#instantStream = null;
|
|
634
|
-
#log;
|
|
635
533
|
tx = (0, core_1.txInit)();
|
|
636
534
|
constructor(_config) {
|
|
637
535
|
this.config = instantConfigWithDefaults(_config);
|
|
638
536
|
this.auth = new Auth(this.config);
|
|
639
537
|
this.storage = new Storage(this.config, this.impersonationOpts);
|
|
640
|
-
this.streams = new Streams(this.#ensureInstantStream.bind(this));
|
|
641
538
|
this.rooms = new Rooms(this.config);
|
|
642
|
-
this.#log = createLogger(!!this.config.verbose);
|
|
643
539
|
}
|
|
644
540
|
/**
|
|
645
541
|
* Sometimes you want to scope queries to a specific user.
|
|
@@ -682,7 +578,7 @@ class InstantAdminDatabase {
|
|
|
682
578
|
}
|
|
683
579
|
const fetchOpts = opts.fetchOpts || {};
|
|
684
580
|
const fetchOptsHeaders = fetchOpts['headers'] || {};
|
|
685
|
-
return jsonFetch(`${this.config.apiURI}/admin/query
|
|
581
|
+
return jsonFetch(`${this.config.apiURI}/admin/query`, {
|
|
686
582
|
...fetchOpts,
|
|
687
583
|
method: 'POST',
|
|
688
584
|
headers: {
|
|
@@ -777,7 +673,7 @@ class InstantAdminDatabase {
|
|
|
777
673
|
if (!this.config.disableValidation) {
|
|
778
674
|
(0, core_1.validateTransactions)(inputChunks, this.config.schema);
|
|
779
675
|
}
|
|
780
|
-
return jsonFetch(`${this.config.apiURI}/admin/transact
|
|
676
|
+
return jsonFetch(`${this.config.apiURI}/admin/transact`, {
|
|
781
677
|
method: 'POST',
|
|
782
678
|
headers: authorizedHeaders(this.config, this.impersonationOpts),
|
|
783
679
|
body: JSON.stringify({
|
|
@@ -818,7 +714,7 @@ class InstantAdminDatabase {
|
|
|
818
714
|
if (opts?.origin) {
|
|
819
715
|
body['origin-override'] = opts.origin;
|
|
820
716
|
}
|
|
821
|
-
const response = await jsonFetch(`${this.config.apiURI}/admin/query_perms_check
|
|
717
|
+
const response = await jsonFetch(`${this.config.apiURI}/admin/query_perms_check`, {
|
|
822
718
|
method: 'POST',
|
|
823
719
|
headers: authorizedHeaders(this.config, this.impersonationOpts),
|
|
824
720
|
body: JSON.stringify(body),
|
|
@@ -859,140 +755,11 @@ class InstantAdminDatabase {
|
|
|
859
755
|
if (opts?.origin) {
|
|
860
756
|
body['origin-override'] = opts.origin;
|
|
861
757
|
}
|
|
862
|
-
return jsonFetch(`${this.config.apiURI}/admin/transact_perms_check
|
|
758
|
+
return jsonFetch(`${this.config.apiURI}/admin/transact_perms_check`, {
|
|
863
759
|
method: 'POST',
|
|
864
760
|
headers: authorizedHeaders(this.config, this.impersonationOpts),
|
|
865
761
|
body: JSON.stringify(body),
|
|
866
762
|
});
|
|
867
763
|
};
|
|
868
|
-
#setupSSEConnection() {
|
|
869
|
-
if (this.#sseConnection) {
|
|
870
|
-
this.#sseConnection.close();
|
|
871
|
-
}
|
|
872
|
-
const headers = {
|
|
873
|
-
...authorizedHeaders(this.config, this.impersonationOpts),
|
|
874
|
-
};
|
|
875
|
-
const inference = !!this.config.schema;
|
|
876
|
-
const ES = makeEventSourceWrapper({ headers, inference });
|
|
877
|
-
const conn = new core_1.SSEConnection(ES, `${this.config.apiURI}/admin/sse?app_id=${this.config.appId}`, `${this.config.apiURI}/admin/sse/push?app_id=${this.config.appId}`);
|
|
878
|
-
conn.onopen = this.#onopen;
|
|
879
|
-
conn.onmessage = this.#onmessage;
|
|
880
|
-
conn.onclose = this.#onclose;
|
|
881
|
-
conn.onerror = this.#onerror;
|
|
882
|
-
this.#sseConnection = conn;
|
|
883
|
-
return conn;
|
|
884
|
-
}
|
|
885
|
-
#ensureSSEConnection() {
|
|
886
|
-
return this.#sseConnection || this.#setupSSEConnection();
|
|
887
|
-
}
|
|
888
|
-
#trySend(eventId, msg) {
|
|
889
|
-
const sseConnection = this.#ensureSSEConnection();
|
|
890
|
-
this.#log.info('[send]', eventId, msg, {
|
|
891
|
-
isOpen: sseConnection.isOpen(),
|
|
892
|
-
});
|
|
893
|
-
if (sseConnection.isOpen()) {
|
|
894
|
-
sseConnection.send({ 'client-event-id': eventId, ...msg });
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
#setupInstantStream() {
|
|
898
|
-
this.#ensureSSEConnection();
|
|
899
|
-
const instantStream = new core_1.InstantStream({
|
|
900
|
-
WStream: this.config.WritableStream || WritableStream,
|
|
901
|
-
RStream: this.config.ReadableStream || ReadableStream,
|
|
902
|
-
trySend: (eventId, msg) => {
|
|
903
|
-
this.#trySend(eventId, msg);
|
|
904
|
-
},
|
|
905
|
-
log: this.#log,
|
|
906
|
-
});
|
|
907
|
-
this.#instantStream = instantStream;
|
|
908
|
-
return instantStream;
|
|
909
|
-
}
|
|
910
|
-
#ensureInstantStream() {
|
|
911
|
-
return this.#instantStream || this.#setupInstantStream();
|
|
912
|
-
}
|
|
913
|
-
#onopen = (e) => {
|
|
914
|
-
if (e.target !== this.#sseConnection) {
|
|
915
|
-
this.#log.info('[socket][open]', e.target.id, 'skip; this is no longer the current transport');
|
|
916
|
-
return;
|
|
917
|
-
}
|
|
918
|
-
this.#log.info('[socket][open]', e.target.id);
|
|
919
|
-
this.#sseBackoff = 0;
|
|
920
|
-
this.#instantStream?.onConnectionStatusChange('authenticated');
|
|
921
|
-
};
|
|
922
|
-
#onclose = (e) => {
|
|
923
|
-
if (e.target !== this.#sseConnection) {
|
|
924
|
-
this.#log.info('[socket][close]', e.target.id, 'skip; this is no longer the current transport');
|
|
925
|
-
return;
|
|
926
|
-
}
|
|
927
|
-
this.#log.info('[socket][close]', e.target.id);
|
|
928
|
-
this.#instantStream?.onConnectionStatusChange('closed');
|
|
929
|
-
if (this.#sseConnection) {
|
|
930
|
-
this.#sseConnection = null;
|
|
931
|
-
if (!this.#connectionIsIdle()) {
|
|
932
|
-
// We didn't remove the sse connection, and we have streams we care about, so let's try again
|
|
933
|
-
setTimeout(() => this.#ensureSSEConnection(), this.#sseBackoff);
|
|
934
|
-
this.#sseBackoff = Math.min(15000, Math.max(this.#sseBackoff, 500) * 2);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
};
|
|
938
|
-
#onerror = (e) => {
|
|
939
|
-
if (e.target !== this.#sseConnection) {
|
|
940
|
-
this.#log.info('[socket][error]', e.target.id, 'skip; this is no longer the current transport');
|
|
941
|
-
return;
|
|
942
|
-
}
|
|
943
|
-
this.#log.info('[socket][error]', e.target.id);
|
|
944
|
-
this.#instantStream?.onConnectionStatusChange('closed');
|
|
945
|
-
};
|
|
946
|
-
#connectionIsIdle() {
|
|
947
|
-
return !this.#instantStream || !this.#instantStream.hasActiveStreams();
|
|
948
|
-
}
|
|
949
|
-
#maybeShutdownConnection() {
|
|
950
|
-
if (this.#sseConnection && this.#connectionIsIdle()) {
|
|
951
|
-
const conn = this.#sseConnection;
|
|
952
|
-
this.#log.info('cleaning up unused socket', conn.id);
|
|
953
|
-
this.#sseConnection = null;
|
|
954
|
-
conn.close();
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
#onmessage = (e) => {
|
|
958
|
-
if (e.target !== this.#sseConnection) {
|
|
959
|
-
this.#log.info('[socket][message]', e.target.id, 'skip; this is no longer the current transport');
|
|
960
|
-
return;
|
|
961
|
-
}
|
|
962
|
-
const msg = e.message;
|
|
963
|
-
this.#log.info('[receive]', msg);
|
|
964
|
-
switch (msg.op) {
|
|
965
|
-
case 'start-stream-ok': {
|
|
966
|
-
this.#instantStream?.onStartStreamOk(msg);
|
|
967
|
-
break;
|
|
968
|
-
}
|
|
969
|
-
case 'stream-flushed': {
|
|
970
|
-
this.#instantStream?.onStreamFlushed(msg);
|
|
971
|
-
break;
|
|
972
|
-
}
|
|
973
|
-
case 'append-failed': {
|
|
974
|
-
this.#instantStream?.onAppendFailed(msg);
|
|
975
|
-
break;
|
|
976
|
-
}
|
|
977
|
-
case 'stream-append': {
|
|
978
|
-
this.#instantStream?.onStreamAppend(msg);
|
|
979
|
-
break;
|
|
980
|
-
}
|
|
981
|
-
case 'error': {
|
|
982
|
-
switch (msg['original-event']?.op) {
|
|
983
|
-
case 'start-stream':
|
|
984
|
-
case 'append-stream':
|
|
985
|
-
case 'subscribe-stream':
|
|
986
|
-
case 'unsubscribe-stream': {
|
|
987
|
-
this.#instantStream?.onRecieveError(msg);
|
|
988
|
-
break;
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
break;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
// Closes the connection if we don't have any items pending
|
|
995
|
-
this.#maybeShutdownConnection();
|
|
996
|
-
};
|
|
997
764
|
}
|
|
998
765
|
//# sourceMappingURL=index.js.map
|