@gonvex/client 0.5.2-staging.2 → 0.5.2-staging.21
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/README.md +68 -2
- package/dist/browser-upgrades.d.ts +19 -0
- package/dist/browser-upgrades.js +157 -0
- package/dist/browser-upgrades.js.map +1 -0
- package/dist/client-upgrades.d.ts +26 -0
- package/dist/client-upgrades.js +41 -0
- package/dist/client-upgrades.js.map +1 -0
- package/dist/control.d.ts +2 -0
- package/dist/control.js +1 -0
- package/dist/control.js.map +1 -1
- package/dist/index.d.ts +348 -9
- package/dist/index.js +1576 -192
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-read-view.d.ts +24 -0
- package/dist/indexeddb-read-view.js +164 -0
- package/dist/indexeddb-read-view.js.map +1 -0
- package/dist/indexeddb-replica.d.ts +41 -3
- package/dist/indexeddb-replica.js +405 -111
- package/dist/indexeddb-replica.js.map +1 -1
- package/dist/local-replica.d.ts +127 -4
- package/dist/local-replica.js +836 -85
- package/dist/local-replica.js.map +1 -1
- package/dist/outbox.d.ts +118 -10
- package/dist/outbox.js +391 -89
- package/dist/outbox.js.map +1 -1
- package/dist/paged-read-view.d.ts +13 -0
- package/dist/paged-read-view.js +60 -0
- package/dist/paged-read-view.js.map +1 -0
- package/dist/query-expression.d.ts +39 -2
- package/dist/query-expression.js +106 -5
- package/dist/query-expression.js.map +1 -1
- package/dist/replica-integrity.d.ts +2 -0
- package/dist/replica-integrity.js +10 -0
- package/dist/replica-integrity.js.map +1 -1
- package/dist/replica-record.d.ts +14 -0
- package/dist/replica-record.js +46 -0
- package/dist/replica-record.js.map +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Table, type IndexableType } from 'dexie';
|
|
2
|
+
import type { DataScalar, JsonObject } from '@gonvex/module-sdk';
|
|
3
|
+
import type { ReducerReadView } from '@gonvex/local-runtime/portable';
|
|
4
|
+
export type EntityRecord = {
|
|
5
|
+
scope: string;
|
|
6
|
+
entity: string;
|
|
7
|
+
id: string;
|
|
8
|
+
value: string;
|
|
9
|
+
lookupKeys?: IndexableType[];
|
|
10
|
+
authority?: import('./replica-record.js').ReplicaRecordVersion;
|
|
11
|
+
sequence?: number;
|
|
12
|
+
deleted?: boolean;
|
|
13
|
+
};
|
|
14
|
+
import { type ReadCoverage } from '@gonvex/local-runtime/read-view';
|
|
15
|
+
export type { ReadCoverage } from '@gonvex/local-runtime/read-view';
|
|
16
|
+
export declare const encodeReadKey: (value: DataScalar) => [number, string | number];
|
|
17
|
+
/** Secondary keys live on disk alongside the record, not in another row cache.
|
|
18
|
+
* Large text/JSON stays unindexed; a residual predicate can still examine it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function entityRecord(scope: string, entity: string, id: string, row: JsonObject): EntityRecord;
|
|
21
|
+
/** Must be used inside the storage adapter's transaction. Cursor iteration keeps
|
|
22
|
+
* unrelated records off the JS heap; bounded reads retain at most limit rows.
|
|
23
|
+
*/
|
|
24
|
+
export declare function indexedDBReadView(entities: Table<EntityRecord, [string, string, string]>, scope: string, coverage: ReadCoverage): ReducerReadView;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { compileDataRead, orderedDataRead, matchesDataPredicate } from '@gonvex/module-sdk';
|
|
2
|
+
import { primaryReadKeys, readIsCovered } from '@gonvex/local-runtime/read-view';
|
|
3
|
+
export const encodeReadKey = (value) => {
|
|
4
|
+
if (value === null)
|
|
5
|
+
return [0, 0];
|
|
6
|
+
if (typeof value === 'boolean')
|
|
7
|
+
return [1, Number(value)];
|
|
8
|
+
if (typeof value === 'number')
|
|
9
|
+
return [2, value];
|
|
10
|
+
return [3, value];
|
|
11
|
+
};
|
|
12
|
+
/** Secondary keys live on disk alongside the record, not in another row cache.
|
|
13
|
+
* Large text/JSON stays unindexed; a residual predicate can still examine it.
|
|
14
|
+
*/
|
|
15
|
+
export function entityRecord(scope, entity, id, row) {
|
|
16
|
+
const lookupKeys = [];
|
|
17
|
+
// Avoid temporary entry, flatMap and spread arrays for every column of each
|
|
18
|
+
// persisted row. Keep the same on-disk index encoding and residual reads.
|
|
19
|
+
for (const column of Object.keys(row)) {
|
|
20
|
+
const value = row[column];
|
|
21
|
+
let type;
|
|
22
|
+
let key;
|
|
23
|
+
// SQL equality never selects NULL; isNull reads already use a residual scan.
|
|
24
|
+
// Indexing every absent optional field only duplicates disk/native allocations.
|
|
25
|
+
if (typeof value === 'boolean') {
|
|
26
|
+
type = 1;
|
|
27
|
+
key = Number(value);
|
|
28
|
+
}
|
|
29
|
+
else if (typeof value === 'number' && Number.isFinite(value)) {
|
|
30
|
+
type = 2;
|
|
31
|
+
key = value;
|
|
32
|
+
}
|
|
33
|
+
else if (typeof value === 'string' && value.length <= 256) {
|
|
34
|
+
type = 3;
|
|
35
|
+
key = value;
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
continue;
|
|
39
|
+
lookupKeys.push([scope, entity, column, type, key]);
|
|
40
|
+
}
|
|
41
|
+
return { scope, entity, id, value: JSON.stringify(row), lookupKeys };
|
|
42
|
+
}
|
|
43
|
+
function equality(predicate) {
|
|
44
|
+
if (!predicate)
|
|
45
|
+
return;
|
|
46
|
+
if ('and' in predicate)
|
|
47
|
+
return predicate.and.map(equality).find(Boolean);
|
|
48
|
+
if ('or' in predicate)
|
|
49
|
+
return;
|
|
50
|
+
if (predicate.transform)
|
|
51
|
+
return;
|
|
52
|
+
if (predicate.op === 'eq' && (typeof predicate.value !== 'string' || predicate.value.length <= 256))
|
|
53
|
+
return { column: predicate.column, op: 'eq', value: predicate.value };
|
|
54
|
+
if (predicate.op === 'in' && predicate.values.every(value => typeof value !== 'string' || value.length <= 256))
|
|
55
|
+
return predicate;
|
|
56
|
+
}
|
|
57
|
+
function compare(read, a, b) {
|
|
58
|
+
for (const order of read.orderBy ?? []) {
|
|
59
|
+
const sortValue = (row) => {
|
|
60
|
+
const value = row[order.column];
|
|
61
|
+
if (order.transform !== 'numericSuffix' || value == null)
|
|
62
|
+
return value;
|
|
63
|
+
if (typeof value !== 'string')
|
|
64
|
+
throw new Error('Numeric suffix requires text');
|
|
65
|
+
const suffix = value.match(/[0-9]+$/)?.[0];
|
|
66
|
+
return suffix === undefined ? null : BigInt(suffix);
|
|
67
|
+
};
|
|
68
|
+
const left = sortValue(a), right = sortValue(b);
|
|
69
|
+
if (left === right)
|
|
70
|
+
continue;
|
|
71
|
+
const direction = order.direction === 'desc' ? -1 : 1;
|
|
72
|
+
const nullFirst = (order.nulls ?? (direction === 1 ? 'last' : 'first')) === 'first';
|
|
73
|
+
if (left == null)
|
|
74
|
+
return nullFirst ? -1 : 1;
|
|
75
|
+
if (right == null)
|
|
76
|
+
return nullFirst ? 1 : -1;
|
|
77
|
+
if (typeof left !== typeof right || typeof left === 'object')
|
|
78
|
+
throw new Error(`Incompatible ordering for ${order.column}`);
|
|
79
|
+
return (left < right ? -1 : 1) * direction;
|
|
80
|
+
}
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
/** Must be used inside the storage adapter's transaction. Cursor iteration keeps
|
|
84
|
+
* unrelated records off the JS heap; bounded reads retain at most limit rows.
|
|
85
|
+
*/
|
|
86
|
+
export function indexedDBReadView(entities, scope, coverage) {
|
|
87
|
+
return {
|
|
88
|
+
async select(read, excludedRowIds = []) {
|
|
89
|
+
read = orderedDataRead({ ...read, key: read.key ?? coverage[read.table]?.key });
|
|
90
|
+
compileDataRead(read);
|
|
91
|
+
const known = coverage[read.table];
|
|
92
|
+
const excluded = new Set(excludedRowIds);
|
|
93
|
+
const key = known?.key ?? '_id';
|
|
94
|
+
const restriction = equality(read.where);
|
|
95
|
+
let candidates;
|
|
96
|
+
const primaryKeys = primaryReadKeys(read, key);
|
|
97
|
+
const exactKey = restriction?.op === 'eq' && restriction.column === key && typeof restriction.value === 'string';
|
|
98
|
+
if (exactKey) {
|
|
99
|
+
candidates = entities.where('[scope+entity+id]').equals([scope, read.table, String(restriction.value)]);
|
|
100
|
+
}
|
|
101
|
+
else if (primaryKeys) {
|
|
102
|
+
candidates = entities.where('[scope+entity+id]').anyOf(primaryKeys.map(id => [scope, read.table, id]));
|
|
103
|
+
}
|
|
104
|
+
else if (restriction) {
|
|
105
|
+
const values = restriction.op === 'eq' ? [restriction.value] : restriction.values;
|
|
106
|
+
const keys = values.filter(value => value !== null).map(value => [scope, read.table, restriction.column, ...encodeReadKey(value)]);
|
|
107
|
+
candidates = entities.where('lookupKeys').anyOf(keys).distinct();
|
|
108
|
+
}
|
|
109
|
+
else
|
|
110
|
+
candidates = entities.where('[scope+entity]').equals([scope, read.table]);
|
|
111
|
+
const result = [];
|
|
112
|
+
const foundPrimary = new Set();
|
|
113
|
+
let fieldsComplete = true;
|
|
114
|
+
const required = new Set(read.columns ?? known?.columns ?? []);
|
|
115
|
+
const requirePredicate = (predicate) => {
|
|
116
|
+
if ('and' in predicate)
|
|
117
|
+
predicate.and.forEach(requirePredicate);
|
|
118
|
+
else if ('or' in predicate)
|
|
119
|
+
predicate.or.forEach(requirePredicate);
|
|
120
|
+
else
|
|
121
|
+
required.add(predicate.column);
|
|
122
|
+
};
|
|
123
|
+
if (read.where)
|
|
124
|
+
requirePredicate(read.where);
|
|
125
|
+
for (const order of read.orderBy ?? [])
|
|
126
|
+
required.add(order.column);
|
|
127
|
+
if (read.limit !== 0)
|
|
128
|
+
await candidates.until(() => !read.orderBy?.length && read.limit !== undefined && result.length >= read.limit).each(record => {
|
|
129
|
+
if (record.deleted || excluded.has(record.id))
|
|
130
|
+
return;
|
|
131
|
+
const row = JSON.parse(record.value);
|
|
132
|
+
if (primaryKeys)
|
|
133
|
+
foundPrimary.add(record.id);
|
|
134
|
+
if ([...required].some(column => !Object.hasOwn(row, column)))
|
|
135
|
+
fieldsComplete = false;
|
|
136
|
+
if (read.where && !matchesDataPredicate(row, read.where))
|
|
137
|
+
return;
|
|
138
|
+
if (read.orderBy?.length && read.limit !== undefined) {
|
|
139
|
+
// Retain a bounded ordered candidate set, never sort a full collection.
|
|
140
|
+
let low = 0, high = result.length;
|
|
141
|
+
while (low < high) {
|
|
142
|
+
const mid = (low + high) >>> 1;
|
|
143
|
+
if (compare(read, result[mid], row) <= 0)
|
|
144
|
+
low = mid + 1;
|
|
145
|
+
else
|
|
146
|
+
high = mid;
|
|
147
|
+
}
|
|
148
|
+
if (low < read.limit) {
|
|
149
|
+
result.splice(low, 0, row);
|
|
150
|
+
if (result.length > read.limit)
|
|
151
|
+
result.pop();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else
|
|
155
|
+
result.push(row);
|
|
156
|
+
});
|
|
157
|
+
if (read.orderBy?.length && read.limit === undefined)
|
|
158
|
+
result.sort((a, b) => compare(read, a, b));
|
|
159
|
+
const complete = read.limit === 0 || fieldsComplete && (readIsCovered(known, read) || (primaryKeys !== undefined && primaryKeys.every(id => excluded.has(id) || foundPrimary.has(id))));
|
|
160
|
+
return { rows: read.columns ? result.map(row => Object.fromEntries(read.columns.map(column => [column, row[column] ?? null]))) : result, complete };
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=indexeddb-read-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexeddb-read-view.js","sourceRoot":"","sources":["../src/indexeddb-read-view.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAK5F,OAAO,EAAE,eAAe,EAAE,aAAa,EAAqB,MAAM,iCAAiC,CAAC;AAEpG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAiB,EAA6B,EAAE;IAC5E,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClC,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,IAAI,OAAO,KA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,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;QACvJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,15 +1,53 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type ReadCoverage } from './indexeddb-read-view.js';
|
|
2
|
+
import type { ReducerReadView } from '@gonvex/local-runtime/portable';
|
|
3
|
+
import type { LocalReplicaStorage, ReplicaScope, ReplicaSnapshot, ReplicaTransaction, ReplicaWindow, ReplicaRow, ReplicaStorageChanges } from "./local-replica.js";
|
|
2
4
|
/** Atomic normalized web persistence for the Gonvex Local Replica. */
|
|
3
5
|
export declare class IndexedDBLocalReplicaStorage implements LocalReplicaStorage {
|
|
4
6
|
private readonly database;
|
|
5
7
|
private initialized?;
|
|
8
|
+
private readonly channel?;
|
|
9
|
+
private readonly peers;
|
|
6
10
|
constructor(name?: string);
|
|
11
|
+
subscribePeer(listener: (scope: string) => void): () => void;
|
|
12
|
+
private nextSequence;
|
|
13
|
+
private versionedRecord;
|
|
14
|
+
private writeEntity;
|
|
15
|
+
private writeRows;
|
|
16
|
+
private writeRowEntries;
|
|
17
|
+
private writeWindows;
|
|
18
|
+
private saveCursor;
|
|
19
|
+
private acceptEpoch;
|
|
20
|
+
private pruneRows;
|
|
21
|
+
readChanges(scope: string, afterSequence: number, interest?: {
|
|
22
|
+
rows: Record<string, string[]>;
|
|
23
|
+
windows: string[];
|
|
24
|
+
availableRows: number;
|
|
25
|
+
availableBytes: number;
|
|
26
|
+
maxRows: number;
|
|
27
|
+
maxBytes: number;
|
|
28
|
+
}): Promise<ReplicaStorageChanges>;
|
|
7
29
|
private initialize;
|
|
30
|
+
withReadView<T>(scope: string, coverage: ReadCoverage, run: (view: ReducerReadView) => Promise<T>): Promise<T>;
|
|
31
|
+
listScopes(): Promise<string[]>;
|
|
32
|
+
loadSession(scope: string): Promise<import("./local-replica.js").LocalReplicaSession | undefined>;
|
|
33
|
+
saveSession(scope: string, session: import("./local-replica.js").LocalReplicaSession | undefined): Promise<void>;
|
|
8
34
|
load(scope?: ReplicaScope): Promise<ReplicaSnapshot | undefined>;
|
|
35
|
+
loadWorkingSet(scope: string, budget: {
|
|
36
|
+
maxRows: number;
|
|
37
|
+
maxBytes: number;
|
|
38
|
+
}): Promise<ReplicaSnapshot | undefined>;
|
|
39
|
+
loadEntityRows(scope: string, entity: string, ids: readonly string[]): Promise<Array<{
|
|
40
|
+
id: string;
|
|
41
|
+
row: ReplicaRow;
|
|
42
|
+
}>>;
|
|
43
|
+
loadWindowRows(scope: string, signature: string): Promise<{
|
|
44
|
+
window: ReplicaWindow;
|
|
45
|
+
rows: ReplicaRow[];
|
|
46
|
+
} | undefined>;
|
|
9
47
|
applyTransaction(transaction: ReplicaTransaction, _snapshot: ReplicaSnapshot, scope?: ReplicaScope): Promise<void>;
|
|
10
48
|
advanceWatermark(windows: readonly ReplicaWindow[], cursor: ReplicaSnapshot["cursor"], scope?: ReplicaScope): Promise<void>;
|
|
11
|
-
replaceWindow(window: ReplicaWindow, snapshot: ReplicaSnapshot, scope?: ReplicaScope): Promise<void>;
|
|
12
|
-
applyWindowDelta(window: ReplicaWindow,
|
|
49
|
+
replaceWindow(window: ReplicaWindow, snapshot: ReplicaSnapshot, scope?: ReplicaScope, projection?: readonly ReplicaRow[]): Promise<void>;
|
|
50
|
+
applyWindowDelta(window: ReplicaWindow, delta: {
|
|
13
51
|
upserts: ReplicaRow[];
|
|
14
52
|
deleted: string[];
|
|
15
53
|
}, snapshot: ReplicaSnapshot, scope?: ReplicaScope): Promise<void>;
|