local-lite 2.0.7 → 3.0.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/README.md +8 -30
- package/dist/adapters/local/index.d.ts +1 -0
- package/dist/adapters/local/index.js +1 -0
- package/dist/adapters/local/sqlite-wasm.d.ts +25 -0
- package/dist/adapters/local/sqlite-wasm.js +55 -0
- package/dist/adapters/remote/convex.d.ts +1 -1
- package/dist/adapters/remote/convex.js +25 -3
- package/dist/adapters/remote/demo.d.ts +3 -3
- package/dist/adapters/remote/demo.js +11 -3
- package/dist/adapters/remote/firestore.d.ts +1 -1
- package/dist/adapters/remote/firestore.js +57 -91
- package/dist/adapters/remote/index.d.ts +2 -1
- package/dist/adapters/remote/index.js +1 -0
- package/dist/adapters/remote/postgres.d.ts +37 -0
- package/dist/adapters/remote/postgres.js +119 -0
- package/dist/adapters/remote/self-hosted.d.ts +12 -0
- package/dist/adapters/remote/self-hosted.js +55 -4
- package/dist/adapters/remote/supabase.d.ts +1 -1
- package/dist/adapters/remote/supabase.js +22 -5
- package/dist/auth/apple.js +0 -6
- package/dist/auth/github.js +0 -3
- package/dist/auth/google.js +0 -3
- package/dist/auth/identity.d.ts +0 -5
- package/dist/auth/identity.js +0 -3
- package/dist/auth/microsoft.js +0 -3
- package/dist/auth/unified.d.ts +5 -5
- package/dist/auth/unified.js +1 -1
- package/dist/config/index.d.ts +0 -12
- package/dist/config/index.js +3 -26
- package/dist/config/types.d.ts +3 -2
- package/dist/core/audit.d.ts +52 -0
- package/dist/core/audit.js +153 -0
- package/dist/core/client.d.ts +4 -0
- package/dist/core/client.js +7 -0
- package/dist/core/conflict.d.ts +24 -0
- package/dist/core/conflict.js +77 -0
- package/dist/core/field-encryption.d.ts +25 -0
- package/dist/core/field-encryption.js +128 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +2 -0
- package/dist/core/query-builder.d.ts +51 -0
- package/dist/core/query-builder.js +278 -35
- package/dist/core/query.js +6 -1
- package/dist/core/types.d.ts +2 -1
- package/dist/devtools/BenchmarkModal.js +285 -1
- package/dist/email/index.d.ts +1 -1
- package/dist/email/index.js +2 -2
- package/dist/index.d.ts +2 -27
- package/dist/index.js +2 -27
- package/dist/presence/index.d.ts +45 -0
- package/dist/presence/index.js +142 -0
- package/dist/reactive/event-emitter.d.ts +10 -1
- package/dist/reactive/event-emitter.js +44 -1
- package/dist/reactive/live-query.d.ts +18 -0
- package/dist/reactive/live-query.js +71 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/schema/typed.d.ts +38 -0
- package/dist/schema/typed.js +33 -0
- package/dist/server/dashboard.d.ts +2 -0
- package/dist/server/dashboard.js +182 -2
- package/dist/solid/index.d.ts +24 -0
- package/dist/solid/index.js +35 -0
- package/dist/storage/firebase.d.ts +3 -3
- package/dist/storage/firebase.js +40 -94
- package/dist/svelte/index.d.ts +15 -0
- package/dist/svelte/index.js +27 -0
- package/dist/testing/index.d.ts +22 -0
- package/dist/testing/index.js +74 -0
- package/dist/vue/index.d.ts +27 -0
- package/dist/vue/index.js +37 -0
- package/package.json +46 -9
- package/skills/local-lite-auth/SKILL.md +1 -1
- package/skills/local-lite-custom-adapter/SKILL.md +7 -4
- package/skills/local-lite-react/SKILL.md +1 -1
- package/skills/local-lite-setup/SKILL.md +3 -2
- package/skills/local-lite-upgrade/SKILL.md +16 -0
- package/dist/kv/index.d.ts +0 -3
- package/dist/kv/index.js +0 -19
- package/dist/kv/manager.d.ts +0 -52
- package/dist/kv/manager.js +0 -167
- package/dist/kv/store.d.ts +0 -13
- package/dist/kv/store.js +0 -85
- package/dist/kv/types.d.ts +0 -27
- package/dist/kv/types.js +0 -2
- package/dist/react/kv.d.ts +0 -9
- package/dist/react/kv.js +0 -53
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.liveQuery = liveQuery;
|
|
4
|
+
exports.syncStatusStore = syncStatusStore;
|
|
5
|
+
const live_query_js_1 = require("../reactive/live-query.js");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Svelte-compatible Readable store (`$store` reactive) backed by a live local-lite query.
|
|
8
|
+
*/
|
|
9
|
+
function liveQuery(client, tableName, options) {
|
|
10
|
+
return {
|
|
11
|
+
subscribe(run) {
|
|
12
|
+
run({ data: [], loading: true, error: null });
|
|
13
|
+
const { dispose } = (0, live_query_js_1.subscribeLiveQuery)(client, tableName, options, run);
|
|
14
|
+
return dispose;
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a Svelte-compatible Readable store tracking `client.syncWorker` status.
|
|
20
|
+
*/
|
|
21
|
+
function syncStatusStore(client) {
|
|
22
|
+
return {
|
|
23
|
+
subscribe(run) {
|
|
24
|
+
return (0, live_query_js_1.subscribeSyncStatus)(client, run);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { LocalFirstClient, LocalFirstClientConfig } from '../core/client.js';
|
|
2
|
+
import { MemoryDemoRemoteAdapter } from '../adapters/remote/demo.js';
|
|
3
|
+
import { DefaultNetworkStatusProvider } from '../adapters/network/index.js';
|
|
4
|
+
export interface CreateTestClientOptions extends Partial<Omit<LocalFirstClientConfig, 'local'>> {
|
|
5
|
+
tables?: string[];
|
|
6
|
+
online?: boolean;
|
|
7
|
+
remoteLatencyMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface TestClientHandle {
|
|
10
|
+
client: LocalFirstClient;
|
|
11
|
+
remote: MemoryDemoRemoteAdapter;
|
|
12
|
+
network: DefaultNetworkStatusProvider;
|
|
13
|
+
simulateOffline: () => void;
|
|
14
|
+
simulateOnline: () => void;
|
|
15
|
+
flushOutbox: () => Promise<void>;
|
|
16
|
+
injectRemoteChange: (tableName: string, rowId: string, payload: Record<string, any>, operation?: 'INSERT' | 'UPDATE' | 'DELETE') => Promise<void>;
|
|
17
|
+
dispose: () => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates an isolated in-memory `LocalFirstClient` with controllable network and remote state for deterministic tests.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTestClient(options?: CreateTestClientOptions): Promise<TestClientHandle>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTestClient = createTestClient;
|
|
4
|
+
const node_sqlite_1 = require("node:sqlite");
|
|
5
|
+
const client_js_1 = require("../core/client.js");
|
|
6
|
+
const node_sqlite_js_1 = require("../adapters/local/node-sqlite.js");
|
|
7
|
+
const demo_js_1 = require("../adapters/remote/demo.js");
|
|
8
|
+
const index_js_1 = require("../adapters/network/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* Creates an isolated in-memory `LocalFirstClient` with controllable network and remote state for deterministic tests.
|
|
11
|
+
*/
|
|
12
|
+
async function createTestClient(options = {}) {
|
|
13
|
+
const raw = new node_sqlite_1.DatabaseSync(':memory:');
|
|
14
|
+
const local = new node_sqlite_js_1.NodeSQLiteAdapter(raw);
|
|
15
|
+
const remote = options.remote ??
|
|
16
|
+
new demo_js_1.MemoryDemoRemoteAdapter(options.remoteLatencyMs ?? 0);
|
|
17
|
+
const injectedChanges = [];
|
|
18
|
+
if (!options.remote) {
|
|
19
|
+
const origFetch = remote.fetchChanges.bind(remote);
|
|
20
|
+
remote.fetchChanges = async (sinceTimestamp) => {
|
|
21
|
+
const base = await origFetch(sinceTimestamp);
|
|
22
|
+
const pending = injectedChanges.filter((c) => c.timestamp > sinceTimestamp);
|
|
23
|
+
return {
|
|
24
|
+
...base,
|
|
25
|
+
timestamp: Date.now(),
|
|
26
|
+
changes: [...(base.changes ?? []), ...pending],
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const network = options.network ??
|
|
31
|
+
new index_js_1.DefaultNetworkStatusProvider(options.online ?? true);
|
|
32
|
+
const client = new client_js_1.LocalFirstClient({
|
|
33
|
+
...options,
|
|
34
|
+
local,
|
|
35
|
+
remote,
|
|
36
|
+
network,
|
|
37
|
+
tables: options.tables ?? ['todos'],
|
|
38
|
+
autoSchema: options.autoSchema ?? true,
|
|
39
|
+
autoStart: options.autoStart ?? false,
|
|
40
|
+
logger: options.logger ?? false,
|
|
41
|
+
});
|
|
42
|
+
await client.initialize();
|
|
43
|
+
return {
|
|
44
|
+
client,
|
|
45
|
+
remote,
|
|
46
|
+
network,
|
|
47
|
+
simulateOffline() {
|
|
48
|
+
network.setOnline(false);
|
|
49
|
+
},
|
|
50
|
+
simulateOnline() {
|
|
51
|
+
network.setOnline(true);
|
|
52
|
+
},
|
|
53
|
+
async flushOutbox() {
|
|
54
|
+
await client.syncWorker.pushLocalChanges();
|
|
55
|
+
await client.syncWorker.pullRemoteChanges();
|
|
56
|
+
},
|
|
57
|
+
async injectRemoteChange(tableName, rowId, payload, operation = 'UPDATE') {
|
|
58
|
+
const ts = Date.now() + 1000;
|
|
59
|
+
const change = {
|
|
60
|
+
tableName,
|
|
61
|
+
rowId,
|
|
62
|
+
operation,
|
|
63
|
+
timestamp: ts,
|
|
64
|
+
payload: operation === 'DELETE' ? null : payload,
|
|
65
|
+
};
|
|
66
|
+
injectedChanges.push(change);
|
|
67
|
+
remote.emitLiveChanges({ timestamp: ts, changes: [change] });
|
|
68
|
+
},
|
|
69
|
+
async dispose() {
|
|
70
|
+
client.stop();
|
|
71
|
+
raw.close();
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LocalFirstClient } from '../core/client.js';
|
|
2
|
+
import { QueryOptions, SyncStatusEvent } from '../core/types.js';
|
|
3
|
+
export interface VueRef<T> {
|
|
4
|
+
value: T;
|
|
5
|
+
}
|
|
6
|
+
export interface VueCompositionApi {
|
|
7
|
+
ref<T>(initial: T): VueRef<T>;
|
|
8
|
+
onUnmounted?: (fn: () => void) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Vue 3 composable for live local-lite queries.
|
|
12
|
+
* Pass `{ ref, onUnmounted }` from `'vue'` to avoid bundling Vue inside `local-lite`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useLiveQuery<T = any>(client: LocalFirstClient, tableName: string, options: QueryOptions | undefined, vue: VueCompositionApi): {
|
|
15
|
+
data: VueRef<T[]>;
|
|
16
|
+
loading: VueRef<boolean>;
|
|
17
|
+
error: VueRef<Error | null>;
|
|
18
|
+
refresh: () => Promise<void>;
|
|
19
|
+
dispose: () => void;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Vue 3 composable for tracking `client.syncWorker` status.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useSyncStatus(client: LocalFirstClient, vue: VueCompositionApi): {
|
|
25
|
+
status: VueRef<SyncStatusEvent>;
|
|
26
|
+
dispose: () => void;
|
|
27
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLiveQuery = useLiveQuery;
|
|
4
|
+
exports.useSyncStatus = useSyncStatus;
|
|
5
|
+
const live_query_js_1 = require("../reactive/live-query.js");
|
|
6
|
+
/**
|
|
7
|
+
* Vue 3 composable for live local-lite queries.
|
|
8
|
+
* Pass `{ ref, onUnmounted }` from `'vue'` to avoid bundling Vue inside `local-lite`.
|
|
9
|
+
*/
|
|
10
|
+
function useLiveQuery(client, tableName, options, vue) {
|
|
11
|
+
const data = vue.ref([]);
|
|
12
|
+
const loading = vue.ref(true);
|
|
13
|
+
const error = vue.ref(null);
|
|
14
|
+
const { refresh, dispose } = (0, live_query_js_1.subscribeLiveQuery)(client, tableName, options, (state) => {
|
|
15
|
+
data.value = state.data;
|
|
16
|
+
loading.value = state.loading;
|
|
17
|
+
error.value = state.error;
|
|
18
|
+
});
|
|
19
|
+
vue.onUnmounted?.(dispose);
|
|
20
|
+
return { data, loading, error, refresh, dispose };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Vue 3 composable for tracking `client.syncWorker` status.
|
|
24
|
+
*/
|
|
25
|
+
function useSyncStatus(client, vue) {
|
|
26
|
+
const status = vue.ref({
|
|
27
|
+
isOnline: true,
|
|
28
|
+
isPushing: false,
|
|
29
|
+
isPulling: false,
|
|
30
|
+
pendingCount: 0,
|
|
31
|
+
});
|
|
32
|
+
const dispose = (0, live_query_js_1.subscribeSyncStatus)(client, (next) => {
|
|
33
|
+
status.value = next;
|
|
34
|
+
});
|
|
35
|
+
vue.onUnmounted?.(dispose);
|
|
36
|
+
return { status, dispose };
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "local-lite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Never let a lost connection break a promise. Local-first sync that faithfully keeps data safe until you're back online.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -121,6 +121,16 @@
|
|
|
121
121
|
"import": "./dist/adapters/local/node-sqlite.js",
|
|
122
122
|
"default": "./dist/adapters/local/node-sqlite.js"
|
|
123
123
|
},
|
|
124
|
+
"./sqlite-wasm": {
|
|
125
|
+
"types": "./dist/adapters/local/sqlite-wasm.d.ts",
|
|
126
|
+
"import": "./dist/adapters/local/sqlite-wasm.js",
|
|
127
|
+
"default": "./dist/adapters/local/sqlite-wasm.js"
|
|
128
|
+
},
|
|
129
|
+
"./postgres": {
|
|
130
|
+
"types": "./dist/adapters/remote/postgres.d.ts",
|
|
131
|
+
"import": "./dist/adapters/remote/postgres.js",
|
|
132
|
+
"default": "./dist/adapters/remote/postgres.js"
|
|
133
|
+
},
|
|
124
134
|
"./core": {
|
|
125
135
|
"types": "./dist/core/index.d.ts",
|
|
126
136
|
"import": "./dist/core/index.js",
|
|
@@ -170,27 +180,54 @@
|
|
|
170
180
|
"types": "./dist/payments/server.d.ts",
|
|
171
181
|
"import": "./dist/payments/server.js",
|
|
172
182
|
"default": "./dist/payments/server.js"
|
|
183
|
+
},
|
|
184
|
+
"./svelte": {
|
|
185
|
+
"types": "./dist/svelte/index.d.ts",
|
|
186
|
+
"import": "./dist/svelte/index.js",
|
|
187
|
+
"default": "./dist/svelte/index.js"
|
|
188
|
+
},
|
|
189
|
+
"./vue": {
|
|
190
|
+
"types": "./dist/vue/index.d.ts",
|
|
191
|
+
"import": "./dist/vue/index.js",
|
|
192
|
+
"default": "./dist/vue/index.js"
|
|
193
|
+
},
|
|
194
|
+
"./solid": {
|
|
195
|
+
"types": "./dist/solid/index.d.ts",
|
|
196
|
+
"import": "./dist/solid/index.js",
|
|
197
|
+
"default": "./dist/solid/index.js"
|
|
198
|
+
},
|
|
199
|
+
"./testing": {
|
|
200
|
+
"types": "./dist/testing/index.d.ts",
|
|
201
|
+
"import": "./dist/testing/index.js",
|
|
202
|
+
"default": "./dist/testing/index.js"
|
|
203
|
+
},
|
|
204
|
+
"./presence": {
|
|
205
|
+
"types": "./dist/presence/index.d.ts",
|
|
206
|
+
"import": "./dist/presence/index.js",
|
|
207
|
+
"default": "./dist/presence/index.js"
|
|
173
208
|
}
|
|
174
209
|
},
|
|
175
210
|
"scripts": {
|
|
176
211
|
"build": "tsc",
|
|
212
|
+
"docs": "node scripts/serve-docs.mjs",
|
|
213
|
+
"example": "npm run --prefix example dev",
|
|
177
214
|
"test": "vitest run",
|
|
178
215
|
"test:watch": "vitest",
|
|
179
216
|
"test:package": "node scripts/package-smoke.mjs",
|
|
180
217
|
"prepublishOnly": "npm run test && npm run build && npm run test:package"
|
|
181
218
|
},
|
|
182
219
|
"peerDependencies": {
|
|
183
|
-
"@libsql/client": "
|
|
184
|
-
"@op-engineering/op-sqlite": "
|
|
185
|
-
"@supabase/supabase-js": "
|
|
186
|
-
"better-sqlite3": "
|
|
187
|
-
"convex": ">=1.
|
|
220
|
+
"@libsql/client": ">=0.14.0",
|
|
221
|
+
"@op-engineering/op-sqlite": ">=10.0.0",
|
|
222
|
+
"@supabase/supabase-js": ">=2.45.0",
|
|
223
|
+
"better-sqlite3": ">=11.0.0",
|
|
224
|
+
"convex": ">=1.15.0",
|
|
188
225
|
"expo-file-system": ">=58.0.0",
|
|
189
226
|
"expo-sqlite": ">=58.0.0",
|
|
190
|
-
"firebase": ">=
|
|
227
|
+
"firebase": ">=11.0.0",
|
|
191
228
|
"nodemailer": ">=6.9.0",
|
|
192
229
|
"react": ">=18.0.0",
|
|
193
|
-
"sql.js": "
|
|
230
|
+
"sql.js": ">=1.10.0"
|
|
194
231
|
},
|
|
195
232
|
"peerDependenciesMeta": {
|
|
196
233
|
"nodemailer": {
|
|
@@ -233,7 +270,7 @@
|
|
|
233
270
|
"@types/react": "^19.3.0",
|
|
234
271
|
"@types/uuid": "^11.0.0",
|
|
235
272
|
"expo-sqlite": "^58.0.17",
|
|
236
|
-
"nodemailer": "^10.
|
|
273
|
+
"nodemailer": "^10.6.0",
|
|
237
274
|
"react": "^19.3.1",
|
|
238
275
|
"typescript": "^7.0.2",
|
|
239
276
|
"vitest": "^5.1.0"
|
|
@@ -206,7 +206,7 @@ export const unifiedAuth = new UnifiedAuthManager({
|
|
|
206
206
|
|
|
207
207
|
// Sign in with any provider - user sessions and local tables link seamlessly
|
|
208
208
|
const user = await unifiedAuth.signIn('google');
|
|
209
|
-
console.log('Unified Canonical User ID:', user.
|
|
209
|
+
console.log('Unified Canonical User ID:', user.id);
|
|
210
210
|
|
|
211
211
|
// Listen to unified state changes
|
|
212
212
|
const unsubscribe = unifiedAuth.onAuthStateChange((user) => {
|
|
@@ -9,7 +9,7 @@ Implement `RemoteDBAdapter` (exported from `local-lite`, with `SyncOperation`, `
|
|
|
9
9
|
|
|
10
10
|
## Contract
|
|
11
11
|
|
|
12
|
-
- `pushChanges(operations): Promise<
|
|
12
|
+
- `pushChanges(operations): Promise<PushResult>`
|
|
13
13
|
- Must be idempotent: the client retries after failures, so applying the same operation twice must be safe.
|
|
14
14
|
- Return `false` (or a failing `PushResult`) or reject on failure so operations stay in the outbox. Never report success for operations that were not stored.
|
|
15
15
|
- `fetchChanges(sinceTimestamp, scope?): Promise<DeltaChanges>`
|
|
@@ -27,16 +27,19 @@ Implement `RemoteDBAdapter` (exported from `local-lite`, with `SyncOperation`, `
|
|
|
27
27
|
## Skeleton
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
|
-
import type { RemoteDBAdapter, SyncOperation, DeltaChanges } from 'local-lite';
|
|
30
|
+
import type { RemoteDBAdapter, SyncOperation, DeltaChanges, PushResult } from 'local-lite/core';
|
|
31
31
|
|
|
32
32
|
export class MyAdapter implements RemoteDBAdapter {
|
|
33
|
-
async pushChanges(operations: SyncOperation[]): Promise<
|
|
33
|
+
async pushChanges(operations: SyncOperation[]): Promise<PushResult> {
|
|
34
34
|
const res = await fetch('/sync/push', {
|
|
35
35
|
method: 'POST',
|
|
36
36
|
headers: { 'Content-Type': 'application/json' },
|
|
37
37
|
body: JSON.stringify({ operations }),
|
|
38
38
|
});
|
|
39
|
-
|
|
39
|
+
if (!res.ok) {
|
|
40
|
+
return { success: false, successfulIds: [], failedIds: operations.map((op) => op.id) };
|
|
41
|
+
}
|
|
42
|
+
return { success: true, successfulIds: operations.map((op) => op.id), failedIds: [] };
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
async fetchChanges(since: number, scope?: Record<string, any>): Promise<DeltaChanges> {
|
|
@@ -32,7 +32,7 @@ Comprehensive guide to building reactive, offline-first user interfaces using `l
|
|
|
32
32
|
import React, { useMemo } from 'react';
|
|
33
33
|
import { FlatList, Text, View } from 'react-native';
|
|
34
34
|
import { useLiveQuery } from 'local-lite/react';
|
|
35
|
-
import type { LocalFirstClient } from 'local-lite
|
|
35
|
+
import type { LocalFirstClient } from 'local-lite';
|
|
36
36
|
|
|
37
37
|
interface Todo {
|
|
38
38
|
id: string;
|
|
@@ -70,7 +70,8 @@ Create a singleton client configuration with `defineSyncConfig` and `createSyncC
|
|
|
70
70
|
|
|
71
71
|
```typescript
|
|
72
72
|
import * as SQLite from 'expo-sqlite';
|
|
73
|
-
import { defineSyncConfig, createSyncClient
|
|
73
|
+
import { defineSyncConfig, createSyncClient } from 'local-lite/config';
|
|
74
|
+
import type { LocalFirstClient } from 'local-lite';
|
|
74
75
|
|
|
75
76
|
export const syncConfig = defineSyncConfig({
|
|
76
77
|
// 1. Local Database instance or factory
|
|
@@ -177,7 +178,7 @@ import React, { useState, useEffect } from 'react';
|
|
|
177
178
|
import { View, Text, Button } from 'react-native';
|
|
178
179
|
import { useLiveQuery, useSyncStatus, useLocalAuth } from 'local-lite/react';
|
|
179
180
|
import { getSyncClient } from './sync.config';
|
|
180
|
-
import type { LocalFirstClient } from 'local-lite
|
|
181
|
+
import type { LocalFirstClient } from 'local-lite';
|
|
181
182
|
|
|
182
183
|
export function App() {
|
|
183
184
|
const [client, setClient] = useState<LocalFirstClient | null>(null);
|
|
@@ -7,6 +7,22 @@ description: Review a codebase that uses the local-lite npm package for code tha
|
|
|
7
7
|
|
|
8
8
|
Checklist and automated review instructions for upgrading apps to the latest version of `local-lite`.
|
|
9
9
|
|
|
10
|
+
## 0. Upgrade Checklist (3.0.0 Breaking Changes)
|
|
11
|
+
|
|
12
|
+
* **Trimmed Root & Config Barrels**:
|
|
13
|
+
- `'local-lite'` now exports only `core`, `config`, `schema`, and `utils` (`uuid`, `sql`, `portability`).
|
|
14
|
+
- `'local-lite/config'` no longer re-exports `LocalFirstClient` or provider adapters.
|
|
15
|
+
- **Action**: Move React hooks to `'local-lite/react'`, auth to `'local-lite/auth'`, feature modules (`actions`, `backups`, `keys`, `kv-store`, `search`, `storage`, `scheduler`, `payments`) to `'local-lite/<module>'`, and adapters to `'local-lite/<adapter>'`.
|
|
16
|
+
* **Firebase Modular SDK v11+ Only**:
|
|
17
|
+
- Removed v8/compat `.collection()`, `.batch()`, `.ref()`, `.put()`, and `.save()` branches from `FirestoreRemoteAdapter` and `createFirebaseStorageUploader`.
|
|
18
|
+
- **Action**: Pass modular `firebase/firestore` and `firebase/storage` (`firebase >= 11.0.0`) instances/modules.
|
|
19
|
+
* **Strict `RemoteDBAdapter.pushChanges(): Promise<PushResult>`**:
|
|
20
|
+
- Returning `boolean` from `pushChanges()` is no longer supported.
|
|
21
|
+
- **Action**: Return `{ success, successfulIds, failedIds, errors? }` from all custom remote adapters.
|
|
22
|
+
* **Canonical `AuthUser` Shape (`local-lite/auth`)**:
|
|
23
|
+
- Removed `userId`, `displayName`, `picture`, and `UnifiedAuthUser` aliases.
|
|
24
|
+
- **Action**: Replace with `id`, `name`, `avatarUrl`, and `AuthUser`.
|
|
25
|
+
|
|
10
26
|
## 1. Upgrade Checklist (2.0.0 & Legacy Migrations)
|
|
11
27
|
|
|
12
28
|
Search the codebase for each affected pattern and apply the migration:
|
package/dist/kv/index.d.ts
DELETED
package/dist/kv/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types.js"), exports);
|
|
18
|
-
__exportStar(require("./store.js"), exports);
|
|
19
|
-
__exportStar(require("./manager.js"), exports);
|
package/dist/kv/manager.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { DBExecutable } from '../core/schema-manager.js';
|
|
2
|
-
import { EventEmitter } from '../reactive/event-emitter.js';
|
|
3
|
-
import { KVRecord, KVSetOptions, KVSetSecretOptions, KVStoreOptions } from './types.js';
|
|
4
|
-
export declare class KVManager {
|
|
5
|
-
private db;
|
|
6
|
-
private tableName;
|
|
7
|
-
private events?;
|
|
8
|
-
constructor(db: DBExecutable, eventsOrOptions?: EventEmitter | KVStoreOptions, options?: KVStoreOptions);
|
|
9
|
-
initialize(): Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Sets a value in the key-value store with optional TTL.
|
|
12
|
-
* Emits an event on the event emitter if configured.
|
|
13
|
-
*/
|
|
14
|
-
set(key: string, value: any, options?: KVSetOptions): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Retrieves the value for a key, returning defaultValue if not found or expired.
|
|
17
|
-
*/
|
|
18
|
-
get<T = any>(key: string, defaultValue?: T): Promise<T | undefined>;
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves the full KVRecord metadata for a key.
|
|
21
|
-
*/
|
|
22
|
-
getRecord(key: string): Promise<KVRecord | null>;
|
|
23
|
-
/**
|
|
24
|
-
* Checks whether a non-expired key exists in the store.
|
|
25
|
-
*/
|
|
26
|
-
has(key: string): Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* Removes a key from the store.
|
|
29
|
-
* Emits an event on the event emitter if configured.
|
|
30
|
-
*/
|
|
31
|
-
delete(key: string): Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* Lists all non-expired keys, optionally filtered by a prefix.
|
|
34
|
-
*/
|
|
35
|
-
keys(prefix?: string): Promise<string[]>;
|
|
36
|
-
/**
|
|
37
|
-
* Clears all stored key-value pairs.
|
|
38
|
-
*/
|
|
39
|
-
clear(): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Stores an encrypted secret using AES-256-GCM + PBKDF2 passphrase encryption.
|
|
42
|
-
*/
|
|
43
|
-
setSecret(key: string, secretValue: any, options: KVSetSecretOptions): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Decrypts and retrieves a stored secret.
|
|
46
|
-
*/
|
|
47
|
-
getSecret<T = any>(key: string, passphrase: string, defaultValue?: T): Promise<T | undefined>;
|
|
48
|
-
/**
|
|
49
|
-
* Purges all expired keys immediately.
|
|
50
|
-
*/
|
|
51
|
-
pruneExpired(): Promise<number>;
|
|
52
|
-
}
|
package/dist/kv/manager.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KVManager = void 0;
|
|
4
|
-
const encryption_js_1 = require("../backups/encryption.js");
|
|
5
|
-
const signed_token_js_1 = require("../keys/signed-token.js");
|
|
6
|
-
const store_js_1 = require("./store.js");
|
|
7
|
-
class KVManager {
|
|
8
|
-
db;
|
|
9
|
-
tableName;
|
|
10
|
-
events;
|
|
11
|
-
constructor(db, eventsOrOptions, options) {
|
|
12
|
-
this.db = db;
|
|
13
|
-
let opts = {};
|
|
14
|
-
if (eventsOrOptions &&
|
|
15
|
-
typeof eventsOrOptions.emit === 'function') {
|
|
16
|
-
this.events = eventsOrOptions;
|
|
17
|
-
opts = options || {};
|
|
18
|
-
}
|
|
19
|
-
else if (eventsOrOptions) {
|
|
20
|
-
opts = eventsOrOptions;
|
|
21
|
-
}
|
|
22
|
-
this.tableName = opts.tableName ?? store_js_1.DEFAULT_KV_TABLE;
|
|
23
|
-
}
|
|
24
|
-
async initialize() {
|
|
25
|
-
await store_js_1.KVStore.ensureSchema(this.db, this.tableName);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Sets a value in the key-value store with optional TTL.
|
|
29
|
-
* Emits an event on the event emitter if configured.
|
|
30
|
-
*/
|
|
31
|
-
async set(key, value, options = {}) {
|
|
32
|
-
const now = Date.now();
|
|
33
|
-
const expiresAt = options.expiresAt !== undefined
|
|
34
|
-
? options.expiresAt
|
|
35
|
-
: options.ttlMs !== undefined
|
|
36
|
-
? now + options.ttlMs
|
|
37
|
-
: null;
|
|
38
|
-
let type;
|
|
39
|
-
let valueStr;
|
|
40
|
-
if (typeof value === 'string') {
|
|
41
|
-
type = 'string';
|
|
42
|
-
valueStr = value;
|
|
43
|
-
}
|
|
44
|
-
else if (typeof value === 'number') {
|
|
45
|
-
type = 'number';
|
|
46
|
-
valueStr = String(value);
|
|
47
|
-
}
|
|
48
|
-
else if (typeof value === 'boolean') {
|
|
49
|
-
type = 'boolean';
|
|
50
|
-
valueStr = value ? '1' : '0';
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
type = 'json';
|
|
54
|
-
valueStr = JSON.stringify(value ?? null);
|
|
55
|
-
}
|
|
56
|
-
await store_js_1.KVStore.set(this.db, this.tableName, key, valueStr, type, now, expiresAt);
|
|
57
|
-
this.events?.emit(this.tableName, { operation: 'SET', key, value });
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Retrieves the value for a key, returning defaultValue if not found or expired.
|
|
61
|
-
*/
|
|
62
|
-
async get(key, defaultValue) {
|
|
63
|
-
const record = await store_js_1.KVStore.get(this.db, this.tableName, key);
|
|
64
|
-
if (!record)
|
|
65
|
-
return defaultValue;
|
|
66
|
-
if (record.expiresAt && record.expiresAt <= Date.now()) {
|
|
67
|
-
// Lazy deletion of expired key
|
|
68
|
-
store_js_1.KVStore.delete(this.db, this.tableName, key).catch(() => { });
|
|
69
|
-
return defaultValue;
|
|
70
|
-
}
|
|
71
|
-
return record.value;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Retrieves the full KVRecord metadata for a key.
|
|
75
|
-
*/
|
|
76
|
-
async getRecord(key) {
|
|
77
|
-
const record = await store_js_1.KVStore.get(this.db, this.tableName, key);
|
|
78
|
-
if (!record)
|
|
79
|
-
return null;
|
|
80
|
-
if (record.expiresAt && record.expiresAt <= Date.now()) {
|
|
81
|
-
store_js_1.KVStore.delete(this.db, this.tableName, key).catch(() => { });
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
return record;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Checks whether a non-expired key exists in the store.
|
|
88
|
-
*/
|
|
89
|
-
async has(key) {
|
|
90
|
-
const val = await this.get(key);
|
|
91
|
-
return val !== undefined;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Removes a key from the store.
|
|
95
|
-
* Emits an event on the event emitter if configured.
|
|
96
|
-
*/
|
|
97
|
-
async delete(key) {
|
|
98
|
-
await store_js_1.KVStore.delete(this.db, this.tableName, key);
|
|
99
|
-
this.events?.emit(this.tableName, { operation: 'DELETE', key });
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Lists all non-expired keys, optionally filtered by a prefix.
|
|
103
|
-
*/
|
|
104
|
-
async keys(prefix) {
|
|
105
|
-
return store_js_1.KVStore.listKeys(this.db, this.tableName, prefix);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Clears all stored key-value pairs.
|
|
109
|
-
*/
|
|
110
|
-
async clear() {
|
|
111
|
-
await store_js_1.KVStore.clear(this.db, this.tableName);
|
|
112
|
-
this.events?.emit(this.tableName, { operation: 'CLEAR' });
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Stores an encrypted secret using AES-256-GCM + PBKDF2 passphrase encryption.
|
|
116
|
-
*/
|
|
117
|
-
async setSecret(key, secretValue, options) {
|
|
118
|
-
if (!options.passphrase) {
|
|
119
|
-
throw new Error('Passphrase is required to store encrypted secret.');
|
|
120
|
-
}
|
|
121
|
-
const strValue = typeof secretValue === 'string'
|
|
122
|
-
? secretValue
|
|
123
|
-
: JSON.stringify(secretValue);
|
|
124
|
-
const plainBytes = new TextEncoder().encode(strValue);
|
|
125
|
-
const encryptedBytes = await (0, encryption_js_1.encryptBackupData)(plainBytes, options.passphrase);
|
|
126
|
-
const encryptedBase64 = (0, signed_token_js_1.base64UrlEncode)(encryptedBytes);
|
|
127
|
-
const now = Date.now();
|
|
128
|
-
const expiresAt = options.expiresAt !== undefined
|
|
129
|
-
? options.expiresAt
|
|
130
|
-
: options.ttlMs !== undefined
|
|
131
|
-
? now + options.ttlMs
|
|
132
|
-
: null;
|
|
133
|
-
await store_js_1.KVStore.set(this.db, this.tableName, key, encryptedBase64, 'encrypted', now, expiresAt);
|
|
134
|
-
this.events?.emit(this.tableName, { operation: 'SET_SECRET', key });
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Decrypts and retrieves a stored secret.
|
|
138
|
-
*/
|
|
139
|
-
async getSecret(key, passphrase, defaultValue) {
|
|
140
|
-
const record = await store_js_1.KVStore.get(this.db, this.tableName, key);
|
|
141
|
-
if (!record)
|
|
142
|
-
return defaultValue;
|
|
143
|
-
if (record.expiresAt && record.expiresAt <= Date.now()) {
|
|
144
|
-
store_js_1.KVStore.delete(this.db, this.tableName, key).catch(() => { });
|
|
145
|
-
return defaultValue;
|
|
146
|
-
}
|
|
147
|
-
if (record.type !== 'encrypted') {
|
|
148
|
-
return record.value;
|
|
149
|
-
}
|
|
150
|
-
const encryptedBytes = (0, signed_token_js_1.base64UrlDecode)(record.value);
|
|
151
|
-
const decryptedBytes = await (0, encryption_js_1.decryptBackupData)(encryptedBytes, passphrase);
|
|
152
|
-
const text = new TextDecoder().decode(decryptedBytes);
|
|
153
|
-
try {
|
|
154
|
-
return JSON.parse(text);
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
return text;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Purges all expired keys immediately.
|
|
162
|
-
*/
|
|
163
|
-
async pruneExpired() {
|
|
164
|
-
return store_js_1.KVStore.pruneExpired(this.db, this.tableName);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
exports.KVManager = KVManager;
|
package/dist/kv/store.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { DBExecutable } from '../core/schema-manager.js';
|
|
2
|
-
import { KVRecord } from './types.js';
|
|
3
|
-
export declare const DEFAULT_KV_TABLE = "_local_kv";
|
|
4
|
-
export declare function mapKVRow(r: any): KVRecord;
|
|
5
|
-
export declare class KVStore {
|
|
6
|
-
static ensureSchema(db: DBExecutable, tableName?: string): Promise<void>;
|
|
7
|
-
static set(db: DBExecutable, tableName: string | undefined, key: string, valueStr: string, type: string, now: number, expiresAt: number | null): Promise<void>;
|
|
8
|
-
static get(db: DBExecutable, tableName: string | undefined, key: string): Promise<KVRecord | null>;
|
|
9
|
-
static delete(db: DBExecutable, tableName: string | undefined, key: string): Promise<boolean>;
|
|
10
|
-
static listKeys(db: DBExecutable, tableName?: string, prefix?: string): Promise<string[]>;
|
|
11
|
-
static clear(db: DBExecutable, tableName?: string): Promise<void>;
|
|
12
|
-
static pruneExpired(db: DBExecutable, tableName?: string): Promise<number>;
|
|
13
|
-
}
|