@spooky-sync/core 1.0.0-beta.1 → 1.0.0-beta.11
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/AGENTS.md +4 -3
- package/dist/index.d.ts +170 -9
- package/dist/index.js +5398 -2968
- package/dist/rows-worker.d.ts +1 -0
- package/dist/rows-worker.js +2731 -0
- package/dist/sqlite-open.js +1 -1
- package/dist/sqlite-worker.js +1 -1
- package/dist/types.d.ts +131 -13
- package/package.json +9 -4
- package/scripts/check-worker-entries.mjs +15 -2
- package/skills/sp00ky-core/SKILL.md +2 -0
- package/src/client/bucket-handle.ts +21 -1
- package/src/client/eager-paint.test.ts +82 -0
- package/src/client/services.ts +4 -1
- package/src/client/sp00ky-client.test.ts +143 -1
- package/src/client/sp00ky-client.ts +158 -19
- package/src/index.ts +9 -0
- package/src/kernel/effects.ts +12 -2
- package/src/kernel/interpreter.test.ts +17 -0
- package/src/kernel/interpreter.ts +5 -2
- package/src/modules/channel/hub.test.ts +223 -0
- package/src/modules/channel/hub.ts +355 -0
- package/src/modules/channel/index.ts +358 -14
- package/src/modules/channel/room.test.ts +340 -0
- package/src/modules/channel/room.ts +367 -0
- package/src/modules/channel/rooms.fixture.ts +383 -0
- package/src/modules/channel/share.test.ts +535 -0
- package/src/modules/channel/webrtc.ts +2 -2
- package/src/modules/devtools/storage-info.ts +4 -3
- package/src/query/materialize.saga.test.ts +16 -0
- package/src/query/materialize.saga.ts +7 -26
- package/src/query/materialize.ts +79 -3
- package/src/query/register.saga.test.ts +61 -0
- package/src/query/register.saga.ts +39 -2
- package/src/services/database/cache-engine.ts +17 -3
- package/src/services/database/engine-factory.ts +7 -0
- package/src/services/database/index.ts +1 -0
- package/src/services/database/rows-cache-engine.test.ts +1584 -0
- package/src/services/database/rows-cache-engine.ts +1203 -0
- package/src/services/database/rows-exec.integration.test.ts +589 -0
- package/src/services/database/rows-exec.ts +1027 -0
- package/src/services/database/rows-prewarm.ts +251 -0
- package/src/services/database/rows-store.test.ts +635 -0
- package/src/services/database/rows-store.ts +1208 -0
- package/src/services/database/rows-transport.fixture.ts +151 -0
- package/src/services/database/rows-worker.ts +607 -0
- package/src/services/database/rows-yield.test.ts +141 -0
- package/src/services/database/rows-yield.ts +92 -0
- package/src/services/database/sqlite-cache-engine.test.ts +22 -1
- package/src/services/database/sqlite-cache-engine.ts +55 -34
- package/src/services/database/sqlite-transport.ts +7 -5
- package/src/services/tabs/support.ts +6 -4
- package/src/types.ts +41 -6
- package/tsdown.config.ts +42 -1
- package/vitest.config.ts +4 -0
package/src/query/materialize.ts
CHANGED
|
@@ -3,6 +3,10 @@ import type { RecordId } from 'surrealdb';
|
|
|
3
3
|
import type { Effect } from '../kernel/effects';
|
|
4
4
|
import { fx } from '../kernel/effects';
|
|
5
5
|
import { encodeRecordId, parseRecordIdString } from '../utils/index';
|
|
6
|
+
import type { QueryEntry } from '../state/client-state';
|
|
7
|
+
import type { Overlay } from '../state/selectors';
|
|
8
|
+
import { viewKeyInput } from './hash';
|
|
9
|
+
import { buildRenderIds, paintsCold, resolveMembership } from './render-set';
|
|
6
10
|
import { buildIdSetPlan, buildIdSetSurql, buildWindowMaterialization } from './window-query';
|
|
7
11
|
|
|
8
12
|
export interface MaterializeSource {
|
|
@@ -18,18 +22,90 @@ export const isWindowed = (surql: string): boolean => buildWindowMaterialization
|
|
|
18
22
|
* with the overlay applied); `null` means "no membership yet, scan the local
|
|
19
23
|
* store with the query's own predicate".
|
|
20
24
|
*/
|
|
21
|
-
export function materializeEffect(src: MaterializeSource, ids: string[] | null): Effect {
|
|
25
|
+
export function materializeEffect(src: MaterializeSource, ids: string[] | null, paintKey?: string): Effect {
|
|
22
26
|
if (ids !== null) {
|
|
23
27
|
const parsed = ids.map((id) => parseRecordIdString(id));
|
|
24
|
-
if (src.plan) return fx.local.select(buildIdSetPlan(src.plan, parsed), src.params);
|
|
28
|
+
if (src.plan) return fx.local.select(buildIdSetPlan(src.plan, parsed), src.params, paintKey);
|
|
25
29
|
const idSet = buildIdSetSurql(src.surql);
|
|
26
30
|
if (idSet) return fx.local.query(idSet.query, { ...src.params, __win: parsed });
|
|
27
31
|
return fx.local.query(src.surql, src.params);
|
|
28
32
|
}
|
|
29
|
-
if (src.plan) return fx.local.select(src.plan, src.params);
|
|
33
|
+
if (src.plan) return fx.local.select(src.plan, src.params, paintKey);
|
|
30
34
|
return fx.local.query(src.surql, src.params);
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
/**
|
|
38
|
+
* The peek that goes with {@link materializeEffect}: what the read named
|
|
39
|
+
* `paintKey` answered in an earlier page load, for a store that kept it.
|
|
40
|
+
* It takes the plan, since only a query that has one can be painted: no
|
|
41
|
+
* paint cache covers raw SurrealQL.
|
|
42
|
+
*/
|
|
43
|
+
export function paintEffect(plan: QueryPlan, params: Record<string, unknown>, ids: string[] | null, paintKey: string): Effect {
|
|
44
|
+
const read = ids === null ? plan : buildIdSetPlan(plan, ids.map((id) => parseRecordIdString(id)));
|
|
45
|
+
return fx.local.peekSelect(read, params, paintKey);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The name a query's render read goes by in the store's paint cache. Built
|
|
50
|
+
* from what a page knows the moment it has the query (its text and its
|
|
51
|
+
* parameters), not from a digest that takes a turn of the event loop: a
|
|
52
|
+
* component asks for these rows while it renders, before the client is open.
|
|
53
|
+
*
|
|
54
|
+
* A cold scan is kept under a name of its own. Its rows are filtered before
|
|
55
|
+
* they show (`RenderRead.shows`), by what the client only knows once it is
|
|
56
|
+
* open; the rows of a membership render show as read. So a caller without
|
|
57
|
+
* the client's state (`Sp00kyClient.peekQuery`) asks for the membership name
|
|
58
|
+
* alone, and never paints a row a cold render would have hidden.
|
|
59
|
+
*/
|
|
60
|
+
export const paintKeyOf = (src: Pick<MaterializeSource, 'surql' | 'params'>, ids: string[] | null): string =>
|
|
61
|
+
viewKeyInput(src) + (ids === null ? '\ncold' : '');
|
|
62
|
+
|
|
63
|
+
/** What one render of a query reads, and which of the rows it gets back may show. */
|
|
64
|
+
export interface RenderRead {
|
|
65
|
+
/** The render set, or `null` for a scan with the query's own predicate. */
|
|
66
|
+
ids: string[] | null;
|
|
67
|
+
shows(rows: Record<string, unknown>[]): Record<string, unknown>[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Membership (or a cold scan) with the outbox overlay applied. `known` is the
|
|
72
|
+
* set of ids some durable view vouches for: before the server has answered
|
|
73
|
+
* (`cold`) only those bodies paint (see `paintsCold`).
|
|
74
|
+
*/
|
|
75
|
+
export function renderRead(
|
|
76
|
+
entry: Pick<QueryEntry, 'def' | 'lifecycle' | 'remoteArray' | 'localArray'>,
|
|
77
|
+
ov: Overlay,
|
|
78
|
+
known: ReadonlySet<string>
|
|
79
|
+
): RenderRead {
|
|
80
|
+
const isWindow = isWindowed(entry.def.surql);
|
|
81
|
+
const paints = (id: string | null) => id === null || paintsCold(id, known, ov);
|
|
82
|
+
const coldWindow = entry.lifecycle.phase === 'cold' && isWindow;
|
|
83
|
+
const membership = resolveMembership({
|
|
84
|
+
phase: entry.lifecycle.phase,
|
|
85
|
+
remoteArray: entry.remoteArray,
|
|
86
|
+
localArray: coldWindow ? entry.localArray.filter(([id]) => paints(id)) : entry.localArray,
|
|
87
|
+
isWindow,
|
|
88
|
+
});
|
|
89
|
+
const ids = membership
|
|
90
|
+
? buildRenderIds(membership, entry.localArray, ov, {
|
|
91
|
+
hasExplicitOrder: (entry.def.plan?.orderBy?.length ?? 0) > 0,
|
|
92
|
+
isWindow,
|
|
93
|
+
})
|
|
94
|
+
: null;
|
|
95
|
+
return {
|
|
96
|
+
ids,
|
|
97
|
+
// A peer's delete leaves the row in the store until it is confirmed, so
|
|
98
|
+
// the predicate scan must drop it here (an own delete removed it already).
|
|
99
|
+
shows: (rows) =>
|
|
100
|
+
ids !== null
|
|
101
|
+
? rows
|
|
102
|
+
: rows.filter((row) => {
|
|
103
|
+
const key = rowKey(row);
|
|
104
|
+
return paints(key) && !(key !== null && ov.deletes.has(key));
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
33
109
|
/** Rows out of either read effect's result. */
|
|
34
110
|
export function rowsFromResult(effect: Effect, result: unknown): Record<string, unknown>[] {
|
|
35
111
|
if (effect.kind === 'local.select') return (result as Record<string, unknown>[] | undefined) ?? [];
|
|
@@ -38,6 +38,67 @@ describe('registerLocal', () => {
|
|
|
38
38
|
expect(reg).toMatchObject({ plan: { queryHash: hash, tableName: 'thing', ttl: '10m' } });
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
+
describe('painting from the last page load', () => {
|
|
42
|
+
const plan = { table: 'thing' } as any;
|
|
43
|
+
const planned = { ...input, plan };
|
|
44
|
+
const viewRow = () => ({ ids: [['thing:1', 2], ['thing:2', 1]], confirmed: true });
|
|
45
|
+
|
|
46
|
+
it('is born with the rows the store kept for this query, neither notified nor answered', async () => {
|
|
47
|
+
const painted = [{ id: 'thing:1', n: 1 }, { id: 'thing:2', n: 2 }];
|
|
48
|
+
const out = await runPure(registerLocal(env, planned), {
|
|
49
|
+
handlers: { 'local.getById': viewRow, 'ssp.register': sspOk, 'local.peekSelect': () => painted },
|
|
50
|
+
});
|
|
51
|
+
const entry = out.state.queries.get(out.result)!;
|
|
52
|
+
expect(entry.records).toEqual(painted);
|
|
53
|
+
expect(entry.lifecycle.phase).toBe('cached');
|
|
54
|
+
expect(entry.lifecycle.notified).toBe(false);
|
|
55
|
+
expect(entry.lifecycle.answered).toBe(false);
|
|
56
|
+
// The render that answers still runs: the query is dirty like any new one.
|
|
57
|
+
expect(out.state.dirty.has(out.result)).toBe(true);
|
|
58
|
+
// The peek names the read after the query (its text and parameters, which a
|
|
59
|
+
// page has before the client is open) and asks for the render set.
|
|
60
|
+
const peek = out.log.find((e) => e.kind === 'local.peekSelect') as any;
|
|
61
|
+
expect(peek.paintKey).toBe(JSON.stringify({ surql: input.surql, params: input.params }));
|
|
62
|
+
expect(peek.plan.ids.map((id: RecordId) => String(id.id))).toEqual(['1', '2']);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('paints nothing when the store kept nothing, has no peek, or the peek throws', async () => {
|
|
66
|
+
for (const peek of [() => null, () => [], undefined, () => { throw new Error('storage'); }]) {
|
|
67
|
+
const out = await runPure(registerLocal(env, planned), {
|
|
68
|
+
handlers: { 'local.getById': viewRow, 'ssp.register': sspOk, ...(peek ? { 'local.peekSelect': peek } : {}) },
|
|
69
|
+
});
|
|
70
|
+
expect(out.state.queries.get(out.result)!.records).toEqual([]);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('does not peek for a query without a plan', async () => {
|
|
75
|
+
const out = await runPure(registerLocal(env, input), {
|
|
76
|
+
handlers: { 'local.getById': viewRow, 'ssp.register': sspOk, 'local.peekSelect': () => [{ id: 'thing:1' }] },
|
|
77
|
+
});
|
|
78
|
+
expect(out.log.some((e) => e.kind === 'local.peekSelect')).toBe(false);
|
|
79
|
+
expect(out.state.queries.get(out.result)!.records).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('cold: shows of a kept scan only the rows a view vouches for', async () => {
|
|
83
|
+
// No view row for this query: a predicate scan. `thing:1` is vouched for by another query's view.
|
|
84
|
+
const out = await runPure(registerLocal(env, planned), {
|
|
85
|
+
state: { ...emptyState({ tabId: 't' }), views: new Map([['other', ['thing:1']]]) },
|
|
86
|
+
handlers: {
|
|
87
|
+
'local.getById': () => null,
|
|
88
|
+
'ssp.register': sspOk,
|
|
89
|
+
'local.peekSelect': () => [{ id: 'thing:1' }, { id: 'thing:orphan' }],
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
const entry = out.state.queries.get(out.result)!;
|
|
93
|
+
expect(entry.lifecycle.phase).toBe('cold');
|
|
94
|
+
expect(entry.records).toEqual([{ id: 'thing:1' }]);
|
|
95
|
+
const peek = out.log.find((e) => e.kind === 'local.peekSelect') as any;
|
|
96
|
+
expect(peek.plan.ids).toBeUndefined();
|
|
97
|
+
// A scan's copy has a name of its own: it is not what a closed client may paint.
|
|
98
|
+
expect(peek.paintKey).toBe(`${JSON.stringify({ surql: input.surql, params: input.params })}\ncold`);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
41
102
|
it('cached: a durable view row seeds membership; unconfirmed empty stays cold; a failing read is cold', async () => {
|
|
42
103
|
const cached = await runPure(registerLocal(env, input), {
|
|
43
104
|
handlers: { 'local.getById': () => ({ ids: [['thing:1', 2]], confirmed: false }), 'ssp.register': sspOk },
|
|
@@ -9,15 +9,19 @@ import type { ClientState, QueryEntry } from '../state/client-state';
|
|
|
9
9
|
import { emptyTelemetry } from '../state/client-state';
|
|
10
10
|
import { seedLifecycle } from '../state/lifecycle';
|
|
11
11
|
import * as R from '../state/reducers';
|
|
12
|
-
import { desiredRegistrations } from '../state/selectors';
|
|
12
|
+
import { desiredRegistrations, overlay, vouched } from '../state/selectors';
|
|
13
|
+
import type { Overlay } from '../state/selectors';
|
|
13
14
|
import { parseDuration } from '../utils/index';
|
|
14
15
|
import type { SagaEnv } from './env';
|
|
15
16
|
import { listRefTable } from './env';
|
|
16
17
|
import { queryHashInput, viewKeyInput } from './hash';
|
|
17
18
|
import { FAILED, isResolvedBefore, parseViewRow, snapshotFromSingle } from './membership';
|
|
18
19
|
import { applyMembership, applySubqueryChildren, markMembershipDirty } from './membership.saga';
|
|
20
|
+
import { paintEffect, paintKeyOf, renderRead } from './materialize';
|
|
19
21
|
import * as sql from './sql';
|
|
20
22
|
|
|
23
|
+
const NONE: ReadonlySet<string> = new Set();
|
|
24
|
+
|
|
21
25
|
export interface RegisterInput {
|
|
22
26
|
tableName: string;
|
|
23
27
|
surql: string;
|
|
@@ -31,7 +35,39 @@ export interface RegisterInput {
|
|
|
31
35
|
* row, build the SSP local view and publish the entry. Returns as soon as the
|
|
32
36
|
* entry exists (the first paint comes from `materialize`); the remote
|
|
33
37
|
* registration is dispatched, never awaited.
|
|
38
|
+
*
|
|
39
|
+
* Where the local store kept what this query's render read in an earlier page
|
|
40
|
+
* load (the row store's paint cache), the entry is born holding those rows,
|
|
41
|
+
* so the first subscriber renders them at once and never an empty list. They
|
|
42
|
+
* are rows to paint from, not a result: the entry is neither notified nor
|
|
43
|
+
* answered by them, and `materialize` runs as for any new query and replaces
|
|
44
|
+
* them when its read says otherwise.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* The rows `materialize` is about to read for a new entry, as the store
|
|
48
|
+
* remembers them from the last page load: the same render set, the same
|
|
49
|
+
* read, the same rule for what may show. `null` when the store keeps none.
|
|
34
50
|
*/
|
|
51
|
+
function* paintedRows(entry: QueryEntry): Saga<Record<string, unknown>[] | null> {
|
|
52
|
+
const plan = entry.def.plan;
|
|
53
|
+
if (!plan) return null;
|
|
54
|
+
const [ov, known] = (yield fx.state.read((s) => [overlay(s), entry.lifecycle.phase === 'cold' ? vouched(s) : NONE])) as [
|
|
55
|
+
Overlay,
|
|
56
|
+
ReadonlySet<string>,
|
|
57
|
+
];
|
|
58
|
+
const read = renderRead(entry, ov, known);
|
|
59
|
+
try {
|
|
60
|
+
const rows = (yield paintEffect(plan, entry.def.params, read.ids, paintKeyOf(entry.def, read.ids))) as
|
|
61
|
+
| Record<string, unknown>[]
|
|
62
|
+
| null
|
|
63
|
+
| undefined;
|
|
64
|
+
return Array.isArray(rows) && rows.length > 0 ? read.shows(rows) : null;
|
|
65
|
+
} catch {
|
|
66
|
+
// Painting early is a bonus: the render that follows does not depend on it.
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
35
71
|
export function* registerLocal(env: SagaEnv, input: RegisterInput): Saga<QueryHash> {
|
|
36
72
|
const sessionId = (yield fx.state.read((s) => s.sessionId)) as string | null;
|
|
37
73
|
const hash = (yield fx.hash(queryHashInput(input, sessionId))) as string;
|
|
@@ -90,7 +126,8 @@ export function* registerLocal(env: SagaEnv, input: RegisterInput): Saga<QueryHa
|
|
|
90
126
|
viewLostRetryAt: null,
|
|
91
127
|
telemetry: { ...emptyTelemetry(), registrationTimings: reg.timings },
|
|
92
128
|
};
|
|
93
|
-
yield
|
|
129
|
+
const painted = yield* paintedRows(entry);
|
|
130
|
+
yield fx.state.update(R.putQuery(painted ? { ...entry, records: painted } : entry));
|
|
94
131
|
yield fx.dispatch({ type: 'EnsureRegistered' });
|
|
95
132
|
return hash;
|
|
96
133
|
} finally {
|
|
@@ -76,7 +76,7 @@ export interface LocalCacheEngine extends RowFetcher {
|
|
|
76
76
|
* Materialize a query, including its `.related()` tree (via §3
|
|
77
77
|
* decomposition). Params bind `where` `paramRef`s and any windowing id-set.
|
|
78
78
|
*/
|
|
79
|
-
select(plan: QueryPlan, params?: Record<string, unknown
|
|
79
|
+
select(plan: QueryPlan, params?: Record<string, unknown>, opts?: { paintKey?: string }): Promise<Row[]>;
|
|
80
80
|
|
|
81
81
|
/** Fetch rows by primary id, preserving `ids` order; missing ids are skipped. */
|
|
82
82
|
selectByIds(table: string, ids: Id[], opts?: { select?: string[]; orderBy?: OrderBy }): Promise<Row[]>;
|
|
@@ -125,7 +125,7 @@ export interface LocalStore extends LocalCacheEngine {
|
|
|
125
125
|
/** Which built-in backend this is. OPTIONAL: absent (custom engines) is
|
|
126
126
|
* reported as `'custom'` by DevTools. More robust than `instanceof` for
|
|
127
127
|
* engines constructed outside this package. */
|
|
128
|
-
readonly engineKind?: 'surrealdb' | 'sqlite';
|
|
128
|
+
readonly engineKind?: 'surrealdb' | 'sqlite' | 'rows';
|
|
129
129
|
/** Engine-specific storage numbers for DevTools (DB file size, per-table
|
|
130
130
|
* row counts). OPTIONAL: only engines with something to report implement it. */
|
|
131
131
|
getStorageDiagnostics?(opts?: { tableCounts?: boolean }): Promise<EngineStorageDiagnostics>;
|
|
@@ -167,6 +167,20 @@ export interface LocalStore extends LocalCacheEngine {
|
|
|
167
167
|
* readable by follower tabs over the port transport. OPTIONAL: an engine
|
|
168
168
|
* without it primes from `scanVersions` alone.
|
|
169
169
|
*/
|
|
170
|
+
/**
|
|
171
|
+
* What `select(plan, params)` / `selectByIds` answered the last time the app
|
|
172
|
+
* asked at startup, SYNCHRONOUSLY and before the store is open, or `null`.
|
|
173
|
+
* Something to paint from; the read itself stays the answer and must follow.
|
|
174
|
+
* OPTIONAL: only an engine that keeps such a copy (`'rows'`) has them.
|
|
175
|
+
*/
|
|
176
|
+
peekSelect?(plan: QueryPlan, params?: Record<string, unknown>, opts?: { paintKey?: string }): Row[] | null;
|
|
177
|
+
/**
|
|
178
|
+
* The bucket `connect` is about to be called with, told ahead: a store that
|
|
179
|
+
* keeps rows to paint from can then answer {@link peekSelect} before it is
|
|
180
|
+
* open. Ignored by a store that keeps none.
|
|
181
|
+
*/
|
|
182
|
+
expectBucket?(bucketId: string): void;
|
|
183
|
+
peekByIds?(table: string, ids: Id[], opts?: { select?: string[]; orderBy?: OrderBy }): Row[] | null;
|
|
170
184
|
getSnapshot?(key: string): Promise<StoredSnapshot | null>;
|
|
171
185
|
putSnapshot?(key: string, bytes: Uint8Array, meta: SnapshotMeta): Promise<void>;
|
|
172
186
|
deleteSnapshot?(key: string): Promise<void>;
|
|
@@ -190,7 +204,7 @@ export interface StoredSnapshot {
|
|
|
190
204
|
}
|
|
191
205
|
|
|
192
206
|
/** Selected local cache backend. Mirrors the `persistenceClient` config pattern. */
|
|
193
|
-
export type LocalEngineChoice = 'surrealdb' | 'sqlite' | LocalStore;
|
|
207
|
+
export type LocalEngineChoice = 'surrealdb' | 'sqlite' | 'rows' | LocalStore;
|
|
194
208
|
|
|
195
209
|
/** Thrown when relation decomposition nests past {@link MAX_RELATION_DEPTH} —
|
|
196
210
|
* a guard against a cyclic schema producing unbounded fan-out. */
|
|
@@ -3,6 +3,7 @@ import type { Logger } from '../logger/index';
|
|
|
3
3
|
import type { LocalEngineChoice, LocalStore } from './cache-engine';
|
|
4
4
|
import { SurrealCacheEngine } from './surreal-cache-engine';
|
|
5
5
|
import { SqliteCacheEngine } from './sqlite-cache-engine';
|
|
6
|
+
import { RowsCacheEngine } from './rows-cache-engine';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Build the local cache engine for the given `localEngine` config choice.
|
|
@@ -11,6 +12,8 @@ import { SqliteCacheEngine } from './sqlite-cache-engine';
|
|
|
11
12
|
* `LocalDatabaseService`; the historical behavior, verbatim).
|
|
12
13
|
* - `'sqlite'` → {@link SqliteCacheEngine} (SQLite-WASM Worker + OPFS). Backs
|
|
13
14
|
* `this.local` through the SurrealQL-vocabulary shim + verb surface.
|
|
15
|
+
* - `'rows'` → {@link RowsCacheEngine} (sp00ky's own row store in a Worker, on
|
|
16
|
+
* OPFS). Same verbs and same answers as `'sqlite'`, without SQLite.
|
|
14
17
|
* - a custom object → used as-is (must satisfy {@link LocalStore}).
|
|
15
18
|
*/
|
|
16
19
|
export function createLocalEngine(
|
|
@@ -28,6 +31,10 @@ export function createLocalEngine(
|
|
|
28
31
|
const useOpfs = (config.store ?? 'memory') !== 'memory';
|
|
29
32
|
return new SqliteCacheEngine(config, logger, { useOpfs, shared: opts.shared });
|
|
30
33
|
}
|
|
34
|
+
if (choice === 'rows') {
|
|
35
|
+
const useOpfs = (config.store ?? 'memory') !== 'memory';
|
|
36
|
+
return new RowsCacheEngine(config, logger, { useOpfs, shared: opts.shared });
|
|
37
|
+
}
|
|
31
38
|
// Custom engine instance — trust it to satisfy LocalStore.
|
|
32
39
|
return choice as unknown as LocalStore;
|
|
33
40
|
}
|
|
@@ -7,6 +7,7 @@ export * from './events/index';
|
|
|
7
7
|
export * from './cache-engine';
|
|
8
8
|
export * from './surreal-cache-engine';
|
|
9
9
|
export * from './sqlite-cache-engine';
|
|
10
|
+
export * from './rows-cache-engine';
|
|
10
11
|
export * from './relation-resolver';
|
|
11
12
|
export * from './plan-render';
|
|
12
13
|
export { createLocalEngine } from './engine-factory';
|