@minnowdb/core 0.7.0 → 0.7.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/dist/block-format/block.js +254 -325
- package/dist/block-format/checksum.js +30 -52
- package/dist/block-format/codecs.js +112 -125
- package/dist/block-format/column.js +187 -205
- package/dist/block-format/index.js +5 -1
- package/dist/block-format/physical.js +371 -387
- package/dist/block-format/types.js +4 -1
- package/dist/block-format/unicode.js +30 -39
- package/dist/date-value.js +67 -78
- package/dist/engine/artifact-cache.js +106 -116
- package/dist/engine/batch.js +36 -44
- package/dist/engine/buffered-writer.js +156 -158
- package/dist/engine/byte-estimates.js +20 -22
- package/dist/engine/cache-limits.js +24 -25
- package/dist/engine/cancellation.js +5 -3
- package/dist/engine/catalog.js +64 -73
- package/dist/engine/client.js +715 -780
- package/dist/engine/database.js +15941 -19313
- package/dist/engine/defaults.js +104 -111
- package/dist/engine/errors.js +113 -128
- package/dist/engine/fts.js +233 -280
- package/dist/engine/group-index.js +287 -321
- package/dist/engine/index.js +23 -12
- package/dist/engine/join-index.js +177 -186
- package/dist/engine/keyed-live.js +168 -173
- package/dist/engine/live-api.js +0 -1
- package/dist/engine/live-equal.js +32 -37
- package/dist/engine/live.js +603 -647
- package/dist/engine/memory.js +109 -111
- package/dist/engine/optimizer.d.ts +19 -1
- package/dist/engine/optimizer.js +2633 -2934
- package/dist/engine/point-read.js +122 -182
- package/dist/engine/query-api.js +12 -3
- package/dist/engine/query-cache.js +61 -69
- package/dist/engine/query.d.ts +6 -0
- package/dist/engine/query.js +8503 -9980
- package/dist/engine/result-wire.js +221 -252
- package/dist/engine/schema-wire.js +97 -112
- package/dist/engine/schema.js +1099 -1254
- package/dist/engine/sort-keys.js +315 -389
- package/dist/engine/sql-domains.js +646 -769
- package/dist/engine/sql-driver.js +0 -1
- package/dist/engine/sql-functions.js +1031 -1125
- package/dist/engine/sql-json.js +199 -218
- package/dist/engine/sql-semantics.js +572 -639
- package/dist/engine/typed-live.js +271 -293
- package/dist/engine/vector.js +4484 -5145
- package/dist/engine/worker-host.d.ts +8 -63
- package/dist/engine/worker-host.js +28 -1130
- package/dist/engine/worker-indexeddb.d.ts +1 -0
- package/dist/engine/worker-indexeddb.js +3 -0
- package/dist/engine/worker-memory.d.ts +1 -0
- package/dist/engine/worker-memory.js +3 -0
- package/dist/engine/worker-opfs.d.ts +1 -0
- package/dist/engine/worker-opfs.js +3 -0
- package/dist/engine/worker-server.d.ts +93 -0
- package/dist/engine/worker-server.js +999 -0
- package/dist/engine/worker-store-indexeddb.d.ts +2 -0
- package/dist/engine/worker-store-indexeddb.js +11 -0
- package/dist/engine/worker-store-memory.d.ts +2 -0
- package/dist/engine/worker-store-memory.js +6 -0
- package/dist/engine/worker-store-opfs.d.ts +2 -0
- package/dist/engine/worker-store-opfs.js +9 -0
- package/dist/engine/worker.js +0 -12
- package/dist/engine/write-block-planner.js +93 -100
- package/dist/plan/index.js +15 -16
- package/dist/plan/model.d.ts +6 -0
- package/dist/plan/model.js +20 -27
- package/dist/storage/index.js +0 -12
- package/dist/storage/indexeddb.js +11776 -13171
- package/dist/storage/memory.js +1198 -1241
- package/dist/storage/opfs/files.js +238 -295
- package/dist/storage/opfs/index.js +9 -3
- package/dist/storage/opfs/leader.js +4386 -4856
- package/dist/storage/opfs/rpc.js +223 -259
- package/dist/storage/opfs/snapshot-ledger.js +219 -260
- package/dist/storage/opfs/store.js +884 -1003
- package/dist/storage/persistence.js +59 -74
- package/dist/storage/snapshot-stream.js +788 -826
- package/dist/storage/snapshot.js +36 -37
- package/dist/storage/toolkit/extents.js +444 -520
- package/dist/storage/toolkit/index.js +28 -29
- package/dist/storage/toolkit/record-core.js +5792 -6377
- package/dist/storage/toolkit/sync-file.js +34 -42
- package/dist/storage/toolkit/wal.js +92 -127
- package/dist/storage/toolkit/wire.js +232 -256
- package/dist/storage/types.js +2948 -3250
- package/dist/testing/block-store-conformance.js +1556 -1629
- package/dist/testing/index.js +310 -291
- package/dist/testing/opfs-shim.js +280 -312
- package/dist/testing/simulator.js +496 -534
- package/dist/testing/sqllogictest.js +425 -365
- package/dist/transactions/index.js +1464 -1712
- package/dist/worker-protocol/index.js +70 -69
- package/package.json +20 -2
|
@@ -1,311 +1,289 @@
|
|
|
1
1
|
import { sameLiveValue } from "./live-equal.js";
|
|
2
2
|
function immutableRows(rows) {
|
|
3
|
-
|
|
4
|
-
// change the snapshot identity retained for exact suppression.
|
|
5
|
-
return Object.freeze([...rows]);
|
|
3
|
+
return Object.freeze([...rows]);
|
|
6
4
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!subscribed)
|
|
42
|
-
return;
|
|
43
|
-
subscribed = false;
|
|
44
|
-
this.#listeners.delete(registered);
|
|
45
|
-
if (this.#listeners.size === 0)
|
|
46
|
-
this.#stopObservation();
|
|
47
|
-
};
|
|
5
|
+
class LiveQuery {
|
|
6
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
7
|
+
#source;
|
|
8
|
+
#backend;
|
|
9
|
+
#onClose;
|
|
10
|
+
#snapshot = { status: "loading", rows: [] };
|
|
11
|
+
#subscription;
|
|
12
|
+
#observationGeneration = 0;
|
|
13
|
+
#queued;
|
|
14
|
+
#execution;
|
|
15
|
+
#executionAbort;
|
|
16
|
+
#invalidationSequence = 0;
|
|
17
|
+
#closed = false;
|
|
18
|
+
constructor(backend, source, onClose) {
|
|
19
|
+
this.#backend = backend;
|
|
20
|
+
this.#source = source;
|
|
21
|
+
this.#onClose = onClose;
|
|
22
|
+
}
|
|
23
|
+
getSnapshot = () => this.#snapshot;
|
|
24
|
+
subscribe = (listener) => {
|
|
25
|
+
if (this.#closed)
|
|
26
|
+
throw new Error("Live query is closed");
|
|
27
|
+
const registered = () => listener();
|
|
28
|
+
this.#listeners.add(registered);
|
|
29
|
+
if (this.#listeners.size === 1)
|
|
30
|
+
this.#startObservation();
|
|
31
|
+
let subscribed = true;
|
|
32
|
+
return () => {
|
|
33
|
+
if (!subscribed)
|
|
34
|
+
return;
|
|
35
|
+
subscribed = false;
|
|
36
|
+
this.#listeners.delete(registered);
|
|
37
|
+
if (this.#listeners.size === 0)
|
|
38
|
+
this.#stopObservation();
|
|
48
39
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
await this.#backend.refresh();
|
|
62
|
-
}
|
|
63
|
-
// A backend refresh normally invalidates observers itself. Only synthesize an execution
|
|
64
|
-
// when it did not, which preserves manual retry without running every refreshed query twice.
|
|
65
|
-
if (this.#invalidationSequence === sequence) {
|
|
66
|
-
const version = this.#snapshot.status === "loading" ? null : this.#snapshot.version;
|
|
67
|
-
this.#schedule({ manifestVersion: version, catalogEpoch: 0, initial: false });
|
|
68
|
-
}
|
|
69
|
-
await this.#waitForIdle();
|
|
40
|
+
};
|
|
41
|
+
async refresh() {
|
|
42
|
+
if (this.#closed)
|
|
43
|
+
throw new Error("Live query is closed");
|
|
44
|
+
const sequence = this.#invalidationSequence;
|
|
45
|
+
if (this.#listeners.size > 0) {
|
|
46
|
+
if (this.#subscription === void 0)
|
|
47
|
+
this.#startObservation();
|
|
48
|
+
const opening = this.#subscription;
|
|
49
|
+
if (opening !== void 0)
|
|
50
|
+
await opening.catch(() => void 0);
|
|
51
|
+
await this.#backend.refresh();
|
|
70
52
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.#closed = true;
|
|
75
|
-
this.#observationGeneration += 1;
|
|
76
|
-
this.#executionAbort?.abort(new Error("Live query is closed"));
|
|
77
|
-
const subscription = this.#subscription;
|
|
78
|
-
this.#subscription = undefined;
|
|
79
|
-
if (subscription !== undefined) {
|
|
80
|
-
void subscription.then((handle) => handle.close()).catch(() => undefined);
|
|
81
|
-
}
|
|
82
|
-
// Wake iterators before removing their listeners so a parked next() terminates.
|
|
83
|
-
this.#emit();
|
|
84
|
-
this.#listeners.clear();
|
|
85
|
-
this.#onClose?.();
|
|
53
|
+
if (this.#invalidationSequence === sequence) {
|
|
54
|
+
const version = this.#snapshot.status === "loading" ? null : this.#snapshot.version;
|
|
55
|
+
this.#schedule({ manifestVersion: version, catalogEpoch: 0, initial: false });
|
|
86
56
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return;
|
|
100
|
-
this.#setError(error, this.#currentVersion());
|
|
101
|
-
},
|
|
102
|
-
onComplete: () => {
|
|
103
|
-
if (generation !== this.#observationGeneration)
|
|
104
|
-
return;
|
|
105
|
-
this.#subscription = undefined;
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
this.#subscription = subscription;
|
|
109
|
-
subscription.catch((error) => {
|
|
110
|
-
if (generation !== this.#observationGeneration || this.#closed)
|
|
111
|
-
return;
|
|
112
|
-
this.#subscription = undefined;
|
|
113
|
-
this.#setError(error, this.#currentVersion());
|
|
114
|
-
});
|
|
57
|
+
await this.#waitForIdle();
|
|
58
|
+
}
|
|
59
|
+
close() {
|
|
60
|
+
if (this.#closed)
|
|
61
|
+
return;
|
|
62
|
+
this.#closed = true;
|
|
63
|
+
this.#observationGeneration += 1;
|
|
64
|
+
this.#executionAbort?.abort(new Error("Live query is closed"));
|
|
65
|
+
const subscription = this.#subscription;
|
|
66
|
+
this.#subscription = void 0;
|
|
67
|
+
if (subscription !== void 0) {
|
|
68
|
+
void subscription.then((handle) => handle.close()).catch(() => void 0);
|
|
115
69
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.#
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.#
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
70
|
+
this.#emit();
|
|
71
|
+
this.#listeners.clear();
|
|
72
|
+
this.#onClose?.();
|
|
73
|
+
}
|
|
74
|
+
#startObservation() {
|
|
75
|
+
if (this.#subscription !== void 0 || this.#closed)
|
|
76
|
+
return;
|
|
77
|
+
const generation = this.#observationGeneration += 1;
|
|
78
|
+
const subscription = this.#backend.observe(this.#source.query, {
|
|
79
|
+
onInvalidate: (invalidation) => {
|
|
80
|
+
if (generation !== this.#observationGeneration || this.#closed)
|
|
81
|
+
return;
|
|
82
|
+
this.#schedule(invalidation);
|
|
83
|
+
},
|
|
84
|
+
onError: (error) => {
|
|
85
|
+
if (generation !== this.#observationGeneration || this.#closed)
|
|
86
|
+
return;
|
|
87
|
+
this.#setError(error, this.#currentVersion());
|
|
88
|
+
},
|
|
89
|
+
onComplete: () => {
|
|
90
|
+
if (generation !== this.#observationGeneration)
|
|
91
|
+
return;
|
|
92
|
+
this.#subscription = void 0;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
this.#subscription = subscription;
|
|
96
|
+
subscription.catch((error) => {
|
|
97
|
+
if (generation !== this.#observationGeneration || this.#closed)
|
|
98
|
+
return;
|
|
99
|
+
this.#subscription = void 0;
|
|
100
|
+
this.#setError(error, this.#currentVersion());
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
#stopObservation() {
|
|
104
|
+
this.#observationGeneration += 1;
|
|
105
|
+
this.#executionAbort?.abort(new Error("Live query has no subscribers"));
|
|
106
|
+
const subscription = this.#subscription;
|
|
107
|
+
this.#subscription = void 0;
|
|
108
|
+
if (subscription !== void 0) {
|
|
109
|
+
void subscription.then((handle) => handle.close()).catch(() => void 0);
|
|
138
110
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
status: "ready",
|
|
170
|
-
rows,
|
|
171
|
-
version: invalidation.manifestVersion,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
this.#emit();
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
if (this.#executionWasCancelled(abort) || this.#hasQueuedInvalidation())
|
|
178
|
-
continue;
|
|
179
|
-
this.#setError(error, invalidation.manifestVersion);
|
|
180
|
-
}
|
|
181
|
-
finally {
|
|
182
|
-
if (this.#executionAbort === abort)
|
|
183
|
-
this.#executionAbort = undefined;
|
|
184
|
-
}
|
|
111
|
+
}
|
|
112
|
+
#schedule(invalidation) {
|
|
113
|
+
this.#invalidationSequence += 1;
|
|
114
|
+
this.#queued = invalidation;
|
|
115
|
+
if (this.#execution !== void 0)
|
|
116
|
+
return;
|
|
117
|
+
const execution = this.#drain();
|
|
118
|
+
this.#execution = execution;
|
|
119
|
+
void execution.finally(() => {
|
|
120
|
+
if (this.#execution === execution)
|
|
121
|
+
this.#execution = void 0;
|
|
122
|
+
if (this.#queued !== void 0 && !this.#closed)
|
|
123
|
+
this.#schedule(this.#queued);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async #drain() {
|
|
127
|
+
while (this.#queued !== void 0 && !this.#closed) {
|
|
128
|
+
const invalidation = this.#queued;
|
|
129
|
+
this.#queued = void 0;
|
|
130
|
+
const abort = new AbortController();
|
|
131
|
+
this.#executionAbort = abort;
|
|
132
|
+
try {
|
|
133
|
+
const rows = immutableRows(await this.#source.execute(abort.signal));
|
|
134
|
+
if (this.#executionWasCancelled(abort))
|
|
135
|
+
continue;
|
|
136
|
+
if (this.#hasQueuedInvalidation())
|
|
137
|
+
continue;
|
|
138
|
+
const previous = this.#snapshot.rows;
|
|
139
|
+
if (this.#snapshot.status === "ready" && this.#snapshot.version === invalidation.manifestVersion && sameLiveValue(previous, rows)) {
|
|
140
|
+
continue;
|
|
185
141
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
await execution;
|
|
199
|
-
if (this.#execution === undefined && this.#queued === undefined)
|
|
200
|
-
return;
|
|
142
|
+
if (sameLiveValue(previous, rows) && this.#snapshot.status !== "loading") {
|
|
143
|
+
this.#snapshot = {
|
|
144
|
+
status: "ready",
|
|
145
|
+
rows: previous,
|
|
146
|
+
version: invalidation.manifestVersion
|
|
147
|
+
};
|
|
148
|
+
} else {
|
|
149
|
+
this.#snapshot = {
|
|
150
|
+
status: "ready",
|
|
151
|
+
rows,
|
|
152
|
+
version: invalidation.manifestVersion
|
|
153
|
+
};
|
|
201
154
|
}
|
|
155
|
+
this.#emit();
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (this.#executionWasCancelled(abort) || this.#hasQueuedInvalidation())
|
|
158
|
+
continue;
|
|
159
|
+
this.#setError(error, invalidation.manifestVersion);
|
|
160
|
+
} finally {
|
|
161
|
+
if (this.#executionAbort === abort)
|
|
162
|
+
this.#executionAbort = void 0;
|
|
163
|
+
}
|
|
202
164
|
}
|
|
203
|
-
|
|
204
|
-
|
|
165
|
+
}
|
|
166
|
+
#executionWasCancelled(abort) {
|
|
167
|
+
return abort.signal.aborted || this.#closed;
|
|
168
|
+
}
|
|
169
|
+
#hasQueuedInvalidation() {
|
|
170
|
+
return this.#queued !== void 0;
|
|
171
|
+
}
|
|
172
|
+
async #waitForIdle() {
|
|
173
|
+
for (; ; ) {
|
|
174
|
+
const execution = this.#execution;
|
|
175
|
+
if (execution === void 0)
|
|
176
|
+
return;
|
|
177
|
+
await execution;
|
|
178
|
+
if (this.#execution === void 0 && this.#queued === void 0)
|
|
179
|
+
return;
|
|
205
180
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
181
|
+
}
|
|
182
|
+
#currentVersion() {
|
|
183
|
+
return this.#snapshot.status === "loading" ? null : this.#snapshot.version;
|
|
184
|
+
}
|
|
185
|
+
#setError(error, version) {
|
|
186
|
+
this.#snapshot = { status: "error", rows: this.#snapshot.rows, error, version };
|
|
187
|
+
this.#emit();
|
|
188
|
+
}
|
|
189
|
+
#emit() {
|
|
190
|
+
for (const listener of [...this.#listeners]) {
|
|
191
|
+
try {
|
|
192
|
+
listener();
|
|
193
|
+
} catch {
|
|
194
|
+
}
|
|
209
195
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
196
|
+
}
|
|
197
|
+
[Symbol.asyncIterator]() {
|
|
198
|
+
const inbox = {
|
|
199
|
+
latest: this.#snapshot,
|
|
200
|
+
hasLatest: true,
|
|
201
|
+
stopped: false,
|
|
202
|
+
notify: void 0
|
|
203
|
+
};
|
|
204
|
+
const wake = () => {
|
|
205
|
+
const notify = inbox.notify;
|
|
206
|
+
inbox.notify = void 0;
|
|
207
|
+
notify?.();
|
|
208
|
+
};
|
|
209
|
+
const unsubscribe = this.subscribe(() => {
|
|
210
|
+
inbox.latest = this.#snapshot;
|
|
211
|
+
inbox.hasLatest = true;
|
|
212
|
+
wake();
|
|
213
|
+
});
|
|
214
|
+
const done = { done: true, value: void 0 };
|
|
215
|
+
const read = async () => {
|
|
216
|
+
for (; ; ) {
|
|
217
|
+
if (inbox.stopped || this.#closed)
|
|
218
|
+
return done;
|
|
219
|
+
if (inbox.hasLatest) {
|
|
220
|
+
inbox.hasLatest = false;
|
|
221
|
+
return { done: false, value: inbox.latest };
|
|
218
222
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const inbox = {
|
|
222
|
-
latest: this.#snapshot,
|
|
223
|
-
hasLatest: true,
|
|
224
|
-
stopped: false,
|
|
225
|
-
notify: undefined,
|
|
226
|
-
};
|
|
227
|
-
const wake = () => {
|
|
228
|
-
const notify = inbox.notify;
|
|
229
|
-
inbox.notify = undefined;
|
|
230
|
-
notify?.();
|
|
231
|
-
};
|
|
232
|
-
const unsubscribe = this.subscribe(() => {
|
|
233
|
-
inbox.latest = this.#snapshot;
|
|
234
|
-
inbox.hasLatest = true;
|
|
235
|
-
wake();
|
|
223
|
+
await new Promise((resolve) => {
|
|
224
|
+
inbox.notify = resolve;
|
|
236
225
|
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
wake();
|
|
261
|
-
unsubscribe();
|
|
262
|
-
return done;
|
|
263
|
-
},
|
|
264
|
-
throw: async (error) => {
|
|
265
|
-
inbox.stopped = true;
|
|
266
|
-
wake();
|
|
267
|
-
unsubscribe();
|
|
268
|
-
throw error;
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
}
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
let queue = Promise.resolve();
|
|
229
|
+
return {
|
|
230
|
+
next: () => {
|
|
231
|
+
const result = queue.then(read, read);
|
|
232
|
+
queue = result.then(() => void 0, () => void 0);
|
|
233
|
+
return result;
|
|
234
|
+
},
|
|
235
|
+
return: async () => {
|
|
236
|
+
inbox.stopped = true;
|
|
237
|
+
wake();
|
|
238
|
+
unsubscribe();
|
|
239
|
+
return done;
|
|
240
|
+
},
|
|
241
|
+
throw: async (error) => {
|
|
242
|
+
inbox.stopped = true;
|
|
243
|
+
wake();
|
|
244
|
+
unsubscribe();
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
272
249
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
query.close();
|
|
305
|
-
this.#queries.clear();
|
|
306
|
-
await this.#backend.close();
|
|
307
|
-
}
|
|
250
|
+
class LiveQueryManager {
|
|
251
|
+
#backend;
|
|
252
|
+
#queries = /* @__PURE__ */ new Set();
|
|
253
|
+
#closed = false;
|
|
254
|
+
constructor(driver, options = {}) {
|
|
255
|
+
this.#backend = driver.liveQueries(options);
|
|
256
|
+
}
|
|
257
|
+
watch(source) {
|
|
258
|
+
if (this.#closed)
|
|
259
|
+
throw new Error("Live query manager is closed");
|
|
260
|
+
const query = new LiveQuery(this.#backend, source, () => {
|
|
261
|
+
this.#queries.delete(query);
|
|
262
|
+
});
|
|
263
|
+
this.#queries.add(query);
|
|
264
|
+
return query;
|
|
265
|
+
}
|
|
266
|
+
async refresh() {
|
|
267
|
+
if (this.#closed)
|
|
268
|
+
throw new Error("Live query manager is closed");
|
|
269
|
+
const failed = [...this.#queries].filter((query) => query.getSnapshot().status === "error");
|
|
270
|
+
await Promise.all([this.#backend.refresh(), ...failed.map((query) => query.refresh())]);
|
|
271
|
+
}
|
|
272
|
+
async close() {
|
|
273
|
+
if (this.#closed)
|
|
274
|
+
return;
|
|
275
|
+
this.#closed = true;
|
|
276
|
+
for (const query of [...this.#queries])
|
|
277
|
+
query.close();
|
|
278
|
+
this.#queries.clear();
|
|
279
|
+
await this.#backend.close();
|
|
280
|
+
}
|
|
308
281
|
}
|
|
309
|
-
|
|
310
|
-
|
|
282
|
+
function createLiveQueryManager(driver, options = {}) {
|
|
283
|
+
return new LiveQueryManager(driver, options);
|
|
311
284
|
}
|
|
285
|
+
export {
|
|
286
|
+
LiveQuery,
|
|
287
|
+
LiveQueryManager,
|
|
288
|
+
createLiveQueryManager
|
|
289
|
+
};
|