@instantdb/core 0.22.139 → 0.22.140
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/Connection.d.ts +2 -1
- package/dist/commonjs/Connection.d.ts.map +1 -1
- package/dist/commonjs/Connection.js +6 -2
- package/dist/commonjs/Connection.js.map +1 -1
- package/dist/commonjs/Reactor.d.ts +12 -0
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +63 -18
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/Stream.d.ts +112 -0
- package/dist/commonjs/Stream.d.ts.map +1 -0
- package/dist/commonjs/Stream.js +708 -0
- package/dist/commonjs/Stream.js.map +1 -0
- package/dist/commonjs/index.d.ts +41 -2
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +41 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/Connection.d.ts +2 -1
- package/dist/esm/Connection.d.ts.map +1 -1
- package/dist/esm/Connection.js +6 -2
- package/dist/esm/Connection.js.map +1 -1
- package/dist/esm/Reactor.d.ts +12 -0
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +53 -9
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/Stream.d.ts +112 -0
- package/dist/esm/Stream.d.ts.map +1 -0
- package/dist/esm/Stream.js +701 -0
- package/dist/esm/Stream.js.map +1 -0
- package/dist/esm/index.d.ts +41 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +42 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/standalone/index.js +2203 -1604
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Connection.ts +6 -2
- package/src/Reactor.js +56 -10
- package/src/Stream.ts +1016 -0
- package/src/index.ts +71 -1
- package/tsconfig.json +2 -1
package/src/index.ts
CHANGED
|
@@ -121,7 +121,11 @@ import type {
|
|
|
121
121
|
|
|
122
122
|
import { InstantAPIError, type InstantIssue } from './utils/fetch.js';
|
|
123
123
|
import { InstantError } from './InstantError.ts';
|
|
124
|
-
import {
|
|
124
|
+
import {
|
|
125
|
+
SSEConnection,
|
|
126
|
+
EventSourceType,
|
|
127
|
+
type EventSourceConstructor,
|
|
128
|
+
} from './Connection.ts';
|
|
125
129
|
import { CallbackEventType as SyncTableCallbackEventType } from './SyncTable.ts';
|
|
126
130
|
import type {
|
|
127
131
|
SyncTableCallback,
|
|
@@ -132,6 +136,12 @@ import type {
|
|
|
132
136
|
LoadFromStorage as SyncTableLoadFromStorage,
|
|
133
137
|
SetupError as SyncTableSetupError,
|
|
134
138
|
} from './SyncTable.ts';
|
|
139
|
+
import {
|
|
140
|
+
InstantStream,
|
|
141
|
+
InstantWritableStream,
|
|
142
|
+
ReadableStreamCtor,
|
|
143
|
+
WritableStreamCtor,
|
|
144
|
+
} from './Stream.ts';
|
|
135
145
|
|
|
136
146
|
const defaultOpenDevtool = true;
|
|
137
147
|
|
|
@@ -167,6 +177,8 @@ export type InstantConfig<
|
|
|
167
177
|
useDateObjects: UseDates;
|
|
168
178
|
disableValidation?: boolean;
|
|
169
179
|
Store?: StoreInterfaceClass;
|
|
180
|
+
WritableStream?: WritableStreamCtor;
|
|
181
|
+
ReadableStream?: ReadableStreamCtor;
|
|
170
182
|
};
|
|
171
183
|
|
|
172
184
|
export type ConfigWithSchema<S extends InstantGraph<any, any>> = Config & {
|
|
@@ -521,6 +533,51 @@ class Storage {
|
|
|
521
533
|
};
|
|
522
534
|
}
|
|
523
535
|
|
|
536
|
+
type CreateReadStreamOpts = {
|
|
537
|
+
clientId?: string | null | undefined;
|
|
538
|
+
streamId?: string | null | undefined;
|
|
539
|
+
byteOffset?: number | null | undefined;
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
type CreateWriteStreamOpts = {
|
|
543
|
+
clientId: string;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Functions to manage streams.
|
|
548
|
+
*/
|
|
549
|
+
class Streams {
|
|
550
|
+
constructor(private db: Reactor) {}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Creates a new ReadableStream for the given clientId.
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* const stream = db.streams.createReadStream({clientId: clientId})
|
|
557
|
+
* for await (const chunk of stream) {
|
|
558
|
+
* console.log(chunk);
|
|
559
|
+
* }
|
|
560
|
+
*/
|
|
561
|
+
createReadStream = (opts: CreateReadStreamOpts): ReadableStream<string> => {
|
|
562
|
+
return this.db.createReadStream(opts);
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Creates a new WritableStream for the given clientId.
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* const writeStream = db.streams.createWriteStream({clientId: clientId})
|
|
570
|
+
* const writer = writeStream.getWriter();
|
|
571
|
+
* writer.write('Hello world');
|
|
572
|
+
* writer.close();
|
|
573
|
+
*/
|
|
574
|
+
createWriteStream = (
|
|
575
|
+
opts: CreateWriteStreamOpts,
|
|
576
|
+
): InstantWritableStream<string> => {
|
|
577
|
+
return this.db.createWriteStream(opts);
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
|
|
524
581
|
// util
|
|
525
582
|
|
|
526
583
|
function coerceQuery(o: any) {
|
|
@@ -536,6 +593,7 @@ class InstantCoreDatabase<
|
|
|
536
593
|
public _reactor: Reactor<RoomsOf<Schema>>;
|
|
537
594
|
public auth: Auth;
|
|
538
595
|
public storage: Storage;
|
|
596
|
+
public streams: Streams;
|
|
539
597
|
|
|
540
598
|
public tx = txInit<Schema>();
|
|
541
599
|
|
|
@@ -543,6 +601,7 @@ class InstantCoreDatabase<
|
|
|
543
601
|
this._reactor = reactor;
|
|
544
602
|
this.auth = new Auth(this._reactor);
|
|
545
603
|
this.storage = new Storage(this._reactor);
|
|
604
|
+
this.streams = new Streams(this._reactor);
|
|
546
605
|
}
|
|
547
606
|
|
|
548
607
|
/**
|
|
@@ -939,6 +998,7 @@ export {
|
|
|
939
998
|
InstantCoreDatabase,
|
|
940
999
|
Auth,
|
|
941
1000
|
Storage,
|
|
1001
|
+
Streams,
|
|
942
1002
|
version,
|
|
943
1003
|
InstantError,
|
|
944
1004
|
|
|
@@ -1036,8 +1096,18 @@ export {
|
|
|
1036
1096
|
type DeleteFileResponse,
|
|
1037
1097
|
|
|
1038
1098
|
// SSE
|
|
1099
|
+
SSEConnection,
|
|
1039
1100
|
type EventSourceType,
|
|
1040
1101
|
type FrameworkConfig,
|
|
1102
|
+
type EventSourceConstructor,
|
|
1103
|
+
|
|
1104
|
+
// streams
|
|
1105
|
+
InstantStream,
|
|
1106
|
+
type WritableStreamCtor,
|
|
1107
|
+
type ReadableStreamCtor,
|
|
1108
|
+
type CreateReadStreamOpts,
|
|
1109
|
+
type CreateWriteStreamOpts,
|
|
1110
|
+
type InstantWritableStream,
|
|
1041
1111
|
|
|
1042
1112
|
// sync table types
|
|
1043
1113
|
type SyncTableCallback,
|