@phibac/sdk 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 +202 -0
- package/README.md +53 -2
- package/dist/auth.d.ts +104 -0
- package/dist/auth.js +343 -0
- package/dist/auth.js.map +1 -0
- package/dist/brand.d.ts +7 -0
- package/dist/brand.js +8 -0
- package/dist/brand.js.map +1 -0
- package/dist/cache.d.ts +170 -0
- package/dist/cache.js +293 -0
- package/dist/cache.js.map +1 -0
- package/dist/collection.d.ts +119 -0
- package/dist/collection.js +511 -0
- package/dist/collection.js.map +1 -0
- package/dist/dpop.d.ts +50 -0
- package/dist/dpop.js +105 -0
- package/dist/dpop.js.map +1 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.js +55 -0
- package/dist/errors.js.map +1 -0
- package/dist/files.d.ts +25 -0
- package/dist/files.js +65 -0
- package/dist/files.js.map +1 -0
- package/dist/http.d.ts +53 -0
- package/dist/http.js +130 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +209 -0
- package/dist/index.js.map +1 -0
- package/dist/live.d.ts +116 -0
- package/dist/live.js +448 -0
- package/dist/live.js.map +1 -0
- package/dist/queue.d.ts +103 -0
- package/dist/queue.js +397 -0
- package/dist/queue.js.map +1 -0
- package/package.json +45 -4
- package/src/auth.ts +371 -0
- package/src/brand.ts +8 -0
- package/src/cache.ts +379 -0
- package/src/collection.ts +533 -0
- package/src/dpop.ts +132 -0
- package/src/errors.ts +61 -0
- package/src/files.ts +60 -0
- package/src/http.ts +154 -0
- package/src/index.ts +238 -0
- package/src/live.ts +434 -0
- package/src/queue.ts +419 -0
package/dist/cache.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// The local cache: records and the offline write queue in IndexedDB, so
|
|
2
|
+
// reads are instant and writes work offline. Everything is partitioned by
|
|
3
|
+
// server origin, app and user, so another user signing in on the same
|
|
4
|
+
// browser never sees the previous user's records.
|
|
5
|
+
import { openDB } from "idb";
|
|
6
|
+
// ---- identifiers ----
|
|
7
|
+
let lastMs = 0;
|
|
8
|
+
let lastSeq = 0;
|
|
9
|
+
/**
|
|
10
|
+
* uuidv7 returns a new lower-case UUIDv7 (RFC 9562): a 48-bit Unix
|
|
11
|
+
* millisecond timestamp, version 7, 12 bits of rand_a used as a counter so
|
|
12
|
+
* IDs made in the same millisecond still sort in creation order, the RFC
|
|
13
|
+
* 4122 variant, and 62 random bits from crypto.getRandomValues.
|
|
14
|
+
*/
|
|
15
|
+
export function uuidv7() {
|
|
16
|
+
const b = crypto.getRandomValues(new Uint8Array(16));
|
|
17
|
+
let ms = Date.now();
|
|
18
|
+
let seq;
|
|
19
|
+
if (ms <= lastMs) {
|
|
20
|
+
ms = lastMs;
|
|
21
|
+
seq = lastSeq + 1;
|
|
22
|
+
if (seq > 0xfff) {
|
|
23
|
+
ms++;
|
|
24
|
+
seq = 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
seq = (b[6] << 4) & 0x7ff; // random start, leaving room to count up
|
|
29
|
+
}
|
|
30
|
+
lastMs = ms;
|
|
31
|
+
lastSeq = seq;
|
|
32
|
+
for (let i = 5; i >= 0; i--) {
|
|
33
|
+
b[i] = ms % 256;
|
|
34
|
+
ms = Math.floor(ms / 256);
|
|
35
|
+
}
|
|
36
|
+
b[6] = 0x70 | (seq >> 8);
|
|
37
|
+
b[7] = seq & 0xff;
|
|
38
|
+
b[8] = 0x80 | (b[8] & 0x3f);
|
|
39
|
+
const h = Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
40
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
41
|
+
}
|
|
42
|
+
/** The cache's IndexedDB database, separate from the sign-in database "pb". */
|
|
43
|
+
export const CACHE_DB = "pb-cache";
|
|
44
|
+
const CACHE_DB_VERSION = 1;
|
|
45
|
+
// ---- state helpers ----
|
|
46
|
+
/** merge applies patch to base shallowly; null removes a key, undefined is ignored. */
|
|
47
|
+
export function merge(base, patch) {
|
|
48
|
+
const out = { ...base };
|
|
49
|
+
for (const [k, v] of Object.entries(patch)) {
|
|
50
|
+
if (v === null)
|
|
51
|
+
delete out[k];
|
|
52
|
+
else if (v !== undefined)
|
|
53
|
+
out[k] = v;
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* fold computes the local state: ops (this record's queued writes, in
|
|
59
|
+
* order) applied to the server state. null when nothing is queued.
|
|
60
|
+
*/
|
|
61
|
+
export function fold(server, deleted, ops) {
|
|
62
|
+
if (ops.length === 0)
|
|
63
|
+
return null;
|
|
64
|
+
let data = server && !deleted ? server.data : null;
|
|
65
|
+
let createdAt = server?.createdAt ?? ops[0].at;
|
|
66
|
+
let updatedAt = server?.updatedAt ?? ops[0].at;
|
|
67
|
+
for (const s of ops) {
|
|
68
|
+
const input = (s.op.input.data ?? {});
|
|
69
|
+
if (s.op.kind === "create") {
|
|
70
|
+
data = { ...input };
|
|
71
|
+
createdAt = s.at;
|
|
72
|
+
}
|
|
73
|
+
else if (s.op.kind === "update") {
|
|
74
|
+
// An update of a record the server deleted (and no queued create)
|
|
75
|
+
// leaves no record, not one made of the patch alone.
|
|
76
|
+
data = data === null ? null : merge(data, input);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
data = null;
|
|
80
|
+
}
|
|
81
|
+
updatedAt = s.at;
|
|
82
|
+
}
|
|
83
|
+
return { data, createdAt, updatedAt };
|
|
84
|
+
}
|
|
85
|
+
/** recordId is the global record ID pb://<userId>/<collection>/<rkey>. */
|
|
86
|
+
export function recordId(userId, collection, rkey) {
|
|
87
|
+
return `pb://${userId}/${collection}/${rkey}`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* view is what the app sees of an entry: the local state with status
|
|
91
|
+
* "pending" while writes are queued (rev = the server rev it is based on,
|
|
92
|
+
* 0 for a new record), else the server state "synced"; null when the
|
|
93
|
+
* record is deleted or unknown.
|
|
94
|
+
*/
|
|
95
|
+
export function view(e, userId) {
|
|
96
|
+
if (!e)
|
|
97
|
+
return null;
|
|
98
|
+
const id = recordId(userId, e.collection, e.rkey);
|
|
99
|
+
if (e.local) {
|
|
100
|
+
if (e.local.data === null)
|
|
101
|
+
return null;
|
|
102
|
+
return {
|
|
103
|
+
id,
|
|
104
|
+
collection: e.collection,
|
|
105
|
+
rkey: e.rkey,
|
|
106
|
+
data: e.local.data,
|
|
107
|
+
rev: e.server?.rev ?? 0,
|
|
108
|
+
status: "pending",
|
|
109
|
+
createdAt: e.local.createdAt,
|
|
110
|
+
updatedAt: e.local.updatedAt,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (!e.server || e.deleted)
|
|
114
|
+
return null;
|
|
115
|
+
const s = e.server;
|
|
116
|
+
return { id, collection: e.collection, rkey: e.rkey, data: s.data, rev: s.rev, status: "synced", createdAt: s.createdAt, updatedAt: s.updatedAt };
|
|
117
|
+
}
|
|
118
|
+
/** opRecordKey identifies the record an op writes. */
|
|
119
|
+
export const opKey = (op) => `${op.collection}\u0000${op.rkey}`;
|
|
120
|
+
// ---- the cache ----
|
|
121
|
+
/**
|
|
122
|
+
* Cache is one partition (server origin, app, user) of the cache database.
|
|
123
|
+
* It keeps one connection open until close(); onChange is called with the
|
|
124
|
+
* collections whose records changed after every committed write.
|
|
125
|
+
*/
|
|
126
|
+
export class Cache {
|
|
127
|
+
db;
|
|
128
|
+
part;
|
|
129
|
+
onChange = () => { };
|
|
130
|
+
constructor(db, part) {
|
|
131
|
+
this.db = db;
|
|
132
|
+
this.part = part;
|
|
133
|
+
// Let a newer version of the SDK in another tab upgrade the database.
|
|
134
|
+
db.addEventListener("versionchange", () => db.close());
|
|
135
|
+
}
|
|
136
|
+
static async open(part) {
|
|
137
|
+
const db = await openDB(CACHE_DB, CACHE_DB_VERSION, {
|
|
138
|
+
upgrade(db) {
|
|
139
|
+
const records = db.createObjectStore("records", { keyPath: ["part", "collection", "rkey"] });
|
|
140
|
+
records.createIndex("coll", ["part", "collection"]);
|
|
141
|
+
const queue = db.createObjectStore("queue", { keyPath: "seq", autoIncrement: true });
|
|
142
|
+
queue.createIndex("part", "part");
|
|
143
|
+
queue.createIndex("rec", ["part", "op.collection", "op.rkey"]);
|
|
144
|
+
db.createObjectStore("meta", { keyPath: ["part", "key"] });
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
return new Cache(db, part);
|
|
148
|
+
}
|
|
149
|
+
close() {
|
|
150
|
+
this.db.close();
|
|
151
|
+
}
|
|
152
|
+
// ---- reads ----
|
|
153
|
+
async entry(collection, rkey) {
|
|
154
|
+
return this.db.get("records", [this.part, collection, rkey]);
|
|
155
|
+
}
|
|
156
|
+
async entries(collection) {
|
|
157
|
+
return this.db.getAllFromIndex("records", "coll", [this.part, collection]);
|
|
158
|
+
}
|
|
159
|
+
/** queued returns this partition's queued writes in order. */
|
|
160
|
+
async queued() {
|
|
161
|
+
return this.db.getAllFromIndex("queue", "part", this.part);
|
|
162
|
+
}
|
|
163
|
+
async queueLength() {
|
|
164
|
+
return this.db.countFromIndex("queue", "part", this.part);
|
|
165
|
+
}
|
|
166
|
+
async lastRev(collection) {
|
|
167
|
+
return (await this.db.get("meta", [this.part, `rev:${collection}`]))?.value ?? 0;
|
|
168
|
+
}
|
|
169
|
+
async setLastRev(collection, rev) {
|
|
170
|
+
await this.db.put("meta", { part: this.part, key: `rev:${collection}`, value: rev });
|
|
171
|
+
}
|
|
172
|
+
// ---- writes ----
|
|
173
|
+
/**
|
|
174
|
+
* write runs fn in one readwrite transaction over all stores and reports
|
|
175
|
+
* the collections fn marked as changed once it has committed.
|
|
176
|
+
*/
|
|
177
|
+
async write(fn) {
|
|
178
|
+
const tx = this.db.transaction(["records", "queue", "meta"], "readwrite");
|
|
179
|
+
const w = new Writer(tx, this.part);
|
|
180
|
+
let out;
|
|
181
|
+
try {
|
|
182
|
+
out = await fn(w);
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
try {
|
|
186
|
+
tx.abort();
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
// already finished
|
|
190
|
+
}
|
|
191
|
+
await tx.done.catch(() => undefined);
|
|
192
|
+
throw e;
|
|
193
|
+
}
|
|
194
|
+
await tx.done;
|
|
195
|
+
if (w.changed.size > 0)
|
|
196
|
+
this.onChange(w.changed);
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
/** clear removes this partition's records, queue and positions. */
|
|
200
|
+
async clear() {
|
|
201
|
+
await this.write(async (w) => {
|
|
202
|
+
const tx = w.tx;
|
|
203
|
+
for (const k of await tx.objectStore("records").getAllKeys()) {
|
|
204
|
+
if (k[0] === this.part) {
|
|
205
|
+
w.changed.add(k[1]);
|
|
206
|
+
await tx.objectStore("records").delete(k);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (const k of await tx.objectStore("queue").index("part").getAllKeys(this.part)) {
|
|
210
|
+
await tx.objectStore("queue").delete(k);
|
|
211
|
+
}
|
|
212
|
+
for (const k of await tx.objectStore("meta").getAllKeys()) {
|
|
213
|
+
if (k[0] === this.part)
|
|
214
|
+
await tx.objectStore("meta").delete(k);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** Writer is the cache inside one transaction. */
|
|
220
|
+
export class Writer {
|
|
221
|
+
tx;
|
|
222
|
+
part;
|
|
223
|
+
changed = new Set();
|
|
224
|
+
constructor(tx, part) {
|
|
225
|
+
this.tx = tx;
|
|
226
|
+
this.part = part;
|
|
227
|
+
}
|
|
228
|
+
entry(collection, rkey) {
|
|
229
|
+
return this.tx.objectStore("records").get([this.part, collection, rkey]);
|
|
230
|
+
}
|
|
231
|
+
/** newEntry is an entry for a record this device has never seen. */
|
|
232
|
+
newEntry(collection, rkey) {
|
|
233
|
+
return { part: this.part, collection, rkey, server: null, rev: 0, deleted: false, local: null };
|
|
234
|
+
}
|
|
235
|
+
/** opsFor returns the queued writes of one record, in order. */
|
|
236
|
+
opsFor(collection, rkey) {
|
|
237
|
+
return this.tx.objectStore("queue").index("rec").getAll([this.part, collection, rkey]);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* save stores e with its local state recomputed from its queued writes.
|
|
241
|
+
* An entry with nothing to remember (no server state, not deleted,
|
|
242
|
+
* nothing queued) is removed instead.
|
|
243
|
+
*/
|
|
244
|
+
async save(e) {
|
|
245
|
+
e.local = fold(e.server, e.deleted, await this.opsFor(e.collection, e.rkey));
|
|
246
|
+
this.changed.add(e.collection);
|
|
247
|
+
if (!e.server && !e.deleted && !e.local && e.rev === 0) {
|
|
248
|
+
await this.tx.objectStore("records").delete([this.part, e.collection, e.rkey]);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
await this.tx.objectStore("records").put(e);
|
|
252
|
+
}
|
|
253
|
+
async enqueue(op, at) {
|
|
254
|
+
await this.tx.objectStore("queue").add({ part: this.part, op, at });
|
|
255
|
+
}
|
|
256
|
+
async dequeue(seq) {
|
|
257
|
+
await this.tx.objectStore("queue").delete(seq);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* applyServer records a server state of a record (from a write result,
|
|
261
|
+
* a query, the changes feed or the live connection) if it is newer than
|
|
262
|
+
* what the cache has. record null means the record is deleted on the
|
|
263
|
+
* server. versions, when given, hides records of other majors. Queued
|
|
264
|
+
* local writes stay applied on top. A record hidden by versions is taken
|
|
265
|
+
* again at the same rev (the versions read may have widened). A deleted
|
|
266
|
+
* record is taken again only from a newer state (a restore from its
|
|
267
|
+
* history); a change at or below the rev already seen never brings it
|
|
268
|
+
* back. Returns whether anything changed.
|
|
269
|
+
*/
|
|
270
|
+
async applyServer(collection, rkey, rev, record, versions) {
|
|
271
|
+
const e = (await this.entry(collection, rkey)) ?? this.newEntry(collection, rkey);
|
|
272
|
+
if (rev < e.rev || (rev === e.rev && (e.deleted || e.server !== null)))
|
|
273
|
+
return false;
|
|
274
|
+
if (rev === e.rev && (record === null || (versions && !versions.includes(record.schemaMajor))))
|
|
275
|
+
return false;
|
|
276
|
+
e.rev = rev;
|
|
277
|
+
if (record === null) {
|
|
278
|
+
e.deleted = true;
|
|
279
|
+
e.server = null;
|
|
280
|
+
}
|
|
281
|
+
else if (versions && !versions.includes(record.schemaMajor)) {
|
|
282
|
+
e.deleted = false;
|
|
283
|
+
e.server = null;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
e.deleted = false;
|
|
287
|
+
e.server = record;
|
|
288
|
+
}
|
|
289
|
+
await this.save(e);
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,0EAA0E;AAC1E,sEAAsE;AACtE,kDAAkD;AAClD,OAAO,EAAE,MAAM,EAA0D,MAAM,KAAK,CAAC;AAGrF,wBAAwB;AAExB,IAAI,MAAM,GAAG,CAAC,CAAC;AACf,IAAI,OAAO,GAAG,CAAC,CAAC;AAEhB;;;;;GAKG;AACH,MAAM,UAAU,MAAM;IACpB,MAAM,CAAC,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACpB,IAAI,GAAW,CAAC;IAChB,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;QACjB,EAAE,GAAG,MAAM,CAAC;QACZ,GAAG,GAAG,OAAO,GAAG,CAAC,CAAC;QAClB,IAAI,GAAG,GAAG,KAAK,EAAE,CAAC;YAChB,EAAE,EAAE,CAAC;YACL,GAAG,GAAG,CAAC,CAAC;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CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7G,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;QACZ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;YACjB,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC;QAClB,CAAC;aAAM,IAAI,QAAQ,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9D,CAAC,CAAC,OAAO,GAAG,KAAK,CAAC;YAClB,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,CAAC,CAAC,OAAO,GAAG,KAAK,CAAC;YAClB,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC;QACpB,CAAC;QACD,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { type Cache, type CacheEntry } from "./cache.js";
|
|
2
|
+
import { PbError } from "./errors.js";
|
|
3
|
+
import type { Collection, PbRecord, Query } from "./index.js";
|
|
4
|
+
import type { Live } from "./live.js";
|
|
5
|
+
import { type Flusher, type Net } from "./queue.js";
|
|
6
|
+
/** Bus calls the listeners of a collection when its cached records change. */
|
|
7
|
+
export declare class Bus {
|
|
8
|
+
private readonly listeners;
|
|
9
|
+
on(collection: string, fn: () => void): () => void;
|
|
10
|
+
emit(collections: Iterable<string>): void;
|
|
11
|
+
}
|
|
12
|
+
/** Ctx is what a collection needs from the backend it belongs to. */
|
|
13
|
+
export interface Ctx {
|
|
14
|
+
userId: string;
|
|
15
|
+
/** The server's origin, the only origin consent messages are accepted from. */
|
|
16
|
+
origin: string;
|
|
17
|
+
cache: Cache;
|
|
18
|
+
net: Net;
|
|
19
|
+
flusher: Flusher;
|
|
20
|
+
live: Live;
|
|
21
|
+
bus: Bus;
|
|
22
|
+
/** The majors to write, by collection (connect's schemaMajors). */
|
|
23
|
+
schemaMajors: Record<string, number>;
|
|
24
|
+
/** The consent request in flight in this backend (one popup at a time). */
|
|
25
|
+
consent: {
|
|
26
|
+
current: {
|
|
27
|
+
collection: string;
|
|
28
|
+
promise: Promise<boolean>;
|
|
29
|
+
} | null;
|
|
30
|
+
};
|
|
31
|
+
/** Throws unauthorized once the backend has signed out. */
|
|
32
|
+
check(): void;
|
|
33
|
+
}
|
|
34
|
+
type Op = "==" | "!=" | "<" | "<=" | ">" | ">=" | "in";
|
|
35
|
+
interface Filter {
|
|
36
|
+
field: string;
|
|
37
|
+
op: Op;
|
|
38
|
+
value: unknown;
|
|
39
|
+
}
|
|
40
|
+
interface Order {
|
|
41
|
+
field: string;
|
|
42
|
+
desc: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The most records Query.get() returns without limit(), online and offline
|
|
46
|
+
* alike (sent to the server as the limit). limit(n) returns up to n.
|
|
47
|
+
*/
|
|
48
|
+
export declare const DEFAULT_QUERY_LIMIT = 500;
|
|
49
|
+
export declare class CollectionImpl<T> implements Collection<T> {
|
|
50
|
+
readonly ctx: Ctx;
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly opts: {
|
|
53
|
+
versions?: number[];
|
|
54
|
+
schemaMajor?: number;
|
|
55
|
+
};
|
|
56
|
+
constructor(ctx: Ctx, name: string, opts: {
|
|
57
|
+
versions?: number[];
|
|
58
|
+
schemaMajor?: number;
|
|
59
|
+
});
|
|
60
|
+
private major;
|
|
61
|
+
/** fresh brings the cache up to date from the server now, when it can (see Live.fresh). */
|
|
62
|
+
fresh(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* visible is what this handle shows of an entry: its view, hidden when
|
|
65
|
+
* the handle declared versions and the server state is of another major
|
|
66
|
+
* (another handle on the same collection may read more majors).
|
|
67
|
+
*/
|
|
68
|
+
visible(e: CacheEntry | undefined): PbRecord<T> | null;
|
|
69
|
+
/** enqueue applies op to the cache and queues it, in one transaction; check may refuse it first. */
|
|
70
|
+
private enqueue;
|
|
71
|
+
private newOp;
|
|
72
|
+
create(data: T): Promise<PbRecord<T>>;
|
|
73
|
+
/** existing makes sure the cache knows rkey, then returns why it cannot be written, if so. */
|
|
74
|
+
private refuse;
|
|
75
|
+
update(rkey: string, patch: Partial<T>): Promise<PbRecord<T>>;
|
|
76
|
+
delete(rkey: string): Promise<void>;
|
|
77
|
+
/** get reads the cache at once; the collection is caught up in the background (Live.ensure). */
|
|
78
|
+
get(rkey: string): Promise<PbRecord<T> | null>;
|
|
79
|
+
/** list reads the whole collection from the cache at once, oldest first. */
|
|
80
|
+
list(): Promise<PbRecord<T>[]>;
|
|
81
|
+
where(field: string, op: Op, value: unknown): Query<T>;
|
|
82
|
+
orderBy(field: string, dir?: "asc" | "desc"): Query<T>;
|
|
83
|
+
/** subscribe follows the whole collection (like list(), no default limit). */
|
|
84
|
+
subscribe(cb: (records: PbRecord<T>[]) => void): () => void;
|
|
85
|
+
requestAccess(): Promise<boolean>;
|
|
86
|
+
private askConsent;
|
|
87
|
+
}
|
|
88
|
+
export declare class QueryImpl<T> implements Query<T> {
|
|
89
|
+
private readonly coll;
|
|
90
|
+
private readonly filters;
|
|
91
|
+
private readonly order?;
|
|
92
|
+
private readonly max?;
|
|
93
|
+
constructor(coll: CollectionImpl<T>, filters?: Filter[], order?: Order | undefined, max?: number | undefined);
|
|
94
|
+
where(field: string, op: Op, value: unknown): Query<T>;
|
|
95
|
+
orderBy(field: string, dir?: "asc" | "desc"): Query<T>;
|
|
96
|
+
limit(n: number): Query<T>;
|
|
97
|
+
/**
|
|
98
|
+
* get runs the query on the server when the device is online (all pages
|
|
99
|
+
* up to the limit, merged into the cache) and on the cache when it is
|
|
100
|
+
* offline or the server cannot be reached. Queued local writes are
|
|
101
|
+
* reflected either way.
|
|
102
|
+
*/
|
|
103
|
+
get(): Promise<PbRecord<T>[]>;
|
|
104
|
+
private params;
|
|
105
|
+
private remote;
|
|
106
|
+
/** local evaluates the query over the cache, cut at max (the query's limit by default). */
|
|
107
|
+
local(max?: number): Promise<PbRecord<T>[]>;
|
|
108
|
+
private finish;
|
|
109
|
+
/**
|
|
110
|
+
* subscribe calls cb with the query's result over the cache now and again
|
|
111
|
+
* after every change to the collection's cached records: local writes,
|
|
112
|
+
* queue results, live changes and catch-up. While subscribed the cache is
|
|
113
|
+
* kept current by the live connection.
|
|
114
|
+
*/
|
|
115
|
+
subscribe(cb: (records: PbRecord<T>[]) => void): () => void;
|
|
116
|
+
}
|
|
117
|
+
/** signedOut is the error for any use of a backend after signOut(). */
|
|
118
|
+
export declare function signedOut(): PbError;
|
|
119
|
+
export {};
|