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
|
@@ -29,6 +29,14 @@ export interface SelfHostedRemoteAdapterOptions {
|
|
|
29
29
|
* Polling interval in milliseconds for live change detection. Default: 5000.
|
|
30
30
|
*/
|
|
31
31
|
pollIntervalMs?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Optional WebSocket URL for instant push delta notifications (falls back to polling if omitted or disconnected).
|
|
34
|
+
*/
|
|
35
|
+
wsUrl?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Optional WebSocket constructor override (defaults to globalThis.WebSocket).
|
|
38
|
+
*/
|
|
39
|
+
WebSocketImpl?: typeof WebSocket;
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
42
|
* Universal client remote adapter for self-hosted local-lite sync backends.
|
|
@@ -45,6 +53,9 @@ export declare class SelfHostedRemoteAdapter implements RemoteDBAdapter {
|
|
|
45
53
|
private activeSubscribers;
|
|
46
54
|
private pollTimer?;
|
|
47
55
|
private lastPollCursor;
|
|
56
|
+
private wsUrl?;
|
|
57
|
+
private WebSocketImpl?;
|
|
58
|
+
private ws?;
|
|
48
59
|
constructor(options: SelfHostedRemoteAdapterOptions);
|
|
49
60
|
private getRequestHeaders;
|
|
50
61
|
/**
|
|
@@ -59,6 +70,7 @@ export declare class SelfHostedRemoteAdapter implements RemoteDBAdapter {
|
|
|
59
70
|
* Subscribes to live server changes via periodic polling.
|
|
60
71
|
*/
|
|
61
72
|
subscribeToLiveChanges(callback: (changes: DeltaChanges) => void, scope?: Record<string, any> | (() => Record<string, any> | Promise<Record<string, any>>)): () => void;
|
|
73
|
+
private connectWebSocket;
|
|
62
74
|
private startPolling;
|
|
63
75
|
setSyncScope(scope?: Record<string, any> | (() => Record<string, any> | Promise<Record<string, any>>)): void;
|
|
64
76
|
/**
|
|
@@ -16,6 +16,9 @@ class SelfHostedRemoteAdapter {
|
|
|
16
16
|
activeSubscribers = new Set();
|
|
17
17
|
pollTimer;
|
|
18
18
|
lastPollCursor = 0;
|
|
19
|
+
wsUrl;
|
|
20
|
+
WebSocketImpl;
|
|
21
|
+
ws;
|
|
19
22
|
constructor(options) {
|
|
20
23
|
if (!options.url) {
|
|
21
24
|
throw new Error("A valid 'url' is required for SelfHostedRemoteAdapter.");
|
|
@@ -26,6 +29,8 @@ class SelfHostedRemoteAdapter {
|
|
|
26
29
|
this.customHeaders = options.headers ?? {};
|
|
27
30
|
this.fetchFn = options.fetch || globalThis.fetch;
|
|
28
31
|
this.pollIntervalMs = options.pollIntervalMs ?? 5000;
|
|
32
|
+
this.wsUrl = options.wsUrl;
|
|
33
|
+
this.WebSocketImpl = options.WebSocketImpl ?? globalThis.WebSocket;
|
|
29
34
|
if (!this.fetchFn) {
|
|
30
35
|
throw new Error('A global or configured fetch function is required for SelfHostedRemoteAdapter.');
|
|
31
36
|
}
|
|
@@ -101,14 +106,60 @@ class SelfHostedRemoteAdapter {
|
|
|
101
106
|
this.syncScope = scope;
|
|
102
107
|
}
|
|
103
108
|
this.activeSubscribers.add(callback);
|
|
104
|
-
if (
|
|
109
|
+
if (this.wsUrl && typeof this.WebSocketImpl === 'function') {
|
|
110
|
+
if (!this.ws) {
|
|
111
|
+
this.connectWebSocket();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (!this.pollTimer) {
|
|
105
115
|
this.startPolling();
|
|
106
116
|
}
|
|
107
117
|
return () => {
|
|
108
118
|
this.activeSubscribers.delete(callback);
|
|
109
|
-
if (this.activeSubscribers.size === 0
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
if (this.activeSubscribers.size === 0) {
|
|
120
|
+
if (this.pollTimer) {
|
|
121
|
+
clearInterval(this.pollTimer);
|
|
122
|
+
this.pollTimer = undefined;
|
|
123
|
+
}
|
|
124
|
+
if (this.ws) {
|
|
125
|
+
try {
|
|
126
|
+
this.ws.close();
|
|
127
|
+
}
|
|
128
|
+
catch { }
|
|
129
|
+
this.ws = undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
connectWebSocket() {
|
|
135
|
+
if (!this.wsUrl || typeof this.WebSocketImpl !== 'function')
|
|
136
|
+
return;
|
|
137
|
+
const urlWithAuth = this.token
|
|
138
|
+
? `${this.wsUrl}${this.wsUrl.includes('?') ? '&' : '?'}token=${encodeURIComponent(this.token)}`
|
|
139
|
+
: this.wsUrl;
|
|
140
|
+
const socket = new this.WebSocketImpl(urlWithAuth);
|
|
141
|
+
this.ws = socket;
|
|
142
|
+
socket.onmessage = (event) => {
|
|
143
|
+
try {
|
|
144
|
+
const parsed = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
|
|
145
|
+
const changes = parsed?.changes ?? parsed;
|
|
146
|
+
if (changes && typeof changes === 'object') {
|
|
147
|
+
for (const subscriber of this.activeSubscribers) {
|
|
148
|
+
try {
|
|
149
|
+
subscriber(changes);
|
|
150
|
+
}
|
|
151
|
+
catch { }
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch { }
|
|
156
|
+
};
|
|
157
|
+
socket.onclose = () => {
|
|
158
|
+
if (this.ws === socket) {
|
|
159
|
+
this.ws = undefined;
|
|
160
|
+
}
|
|
161
|
+
if (this.activeSubscribers.size > 0 && !this.pollTimer) {
|
|
162
|
+
this.startPolling();
|
|
112
163
|
}
|
|
113
164
|
};
|
|
114
165
|
}
|
|
@@ -100,7 +100,7 @@ export declare class SupabaseRemoteAdapter implements RemoteDBAdapter {
|
|
|
100
100
|
/**
|
|
101
101
|
* Pushes outbox operations to Supabase.
|
|
102
102
|
*/
|
|
103
|
-
pushChanges(operations: SyncOperation[]): Promise<
|
|
103
|
+
pushChanges(operations: SyncOperation[]): Promise<PushResult>;
|
|
104
104
|
/**
|
|
105
105
|
* Fetches delta changes from Supabase since a given timestamp.
|
|
106
106
|
* Reads updated records and checks `deleted: true` to propagate soft deletes.
|
|
@@ -104,12 +104,16 @@ class SupabaseRemoteAdapter {
|
|
|
104
104
|
*/
|
|
105
105
|
async pushChanges(operations) {
|
|
106
106
|
if (!operations || operations.length === 0) {
|
|
107
|
-
return true;
|
|
107
|
+
return { success: true, successfulIds: [], failedIds: [] };
|
|
108
108
|
}
|
|
109
109
|
const client = this.getClient();
|
|
110
110
|
if (!client) {
|
|
111
111
|
this.logger.debug('Supabase client is not available; skipping remote push.');
|
|
112
|
-
return
|
|
112
|
+
return {
|
|
113
|
+
success: false,
|
|
114
|
+
successfulIds: [],
|
|
115
|
+
failedIds: operations.map((op) => op.id),
|
|
116
|
+
};
|
|
113
117
|
}
|
|
114
118
|
// 1. If custom RPC is configured, perform atomic batch RPC
|
|
115
119
|
if (this.pushRpcName) {
|
|
@@ -125,9 +129,18 @@ class SupabaseRemoteAdapter {
|
|
|
125
129
|
});
|
|
126
130
|
if (error) {
|
|
127
131
|
this.logger.error((0, logger_js_1.formatSupabaseError)(error, { operation: 'batch_rpc' }));
|
|
128
|
-
return
|
|
132
|
+
return {
|
|
133
|
+
success: false,
|
|
134
|
+
successfulIds: [],
|
|
135
|
+
failedIds: operations.map((op) => op.id),
|
|
136
|
+
errors: { _batch: error.message || String(error) },
|
|
137
|
+
};
|
|
129
138
|
}
|
|
130
|
-
return
|
|
139
|
+
return {
|
|
140
|
+
success: true,
|
|
141
|
+
successfulIds: operations.map((op) => op.id),
|
|
142
|
+
failedIds: [],
|
|
143
|
+
};
|
|
131
144
|
}
|
|
132
145
|
// 2. Direct table operations with consecutive batching and per-operation tracking
|
|
133
146
|
const successfulIds = [];
|
|
@@ -423,7 +436,11 @@ class SupabaseRemoteAdapter {
|
|
|
423
436
|
i++;
|
|
424
437
|
}
|
|
425
438
|
if (failedIds.length === 0) {
|
|
426
|
-
return
|
|
439
|
+
return {
|
|
440
|
+
success: true,
|
|
441
|
+
successfulIds,
|
|
442
|
+
failedIds: [],
|
|
443
|
+
};
|
|
427
444
|
}
|
|
428
445
|
return {
|
|
429
446
|
success: false,
|
package/dist/auth/apple.js
CHANGED
|
@@ -145,13 +145,10 @@ class AppleAuthClient {
|
|
|
145
145
|
const canonicalId = (0, identity_js_1.resolveUnifiedUserId)({ id, email, emailVerified: Boolean(claims.email_verified ?? true) }, 'apple');
|
|
146
146
|
const user = {
|
|
147
147
|
id: canonicalId,
|
|
148
|
-
userId: canonicalId,
|
|
149
148
|
email,
|
|
150
149
|
emailVerified: Boolean(claims.email_verified ?? true),
|
|
151
150
|
name,
|
|
152
|
-
displayName: name,
|
|
153
151
|
avatarUrl: null,
|
|
154
|
-
picture: null,
|
|
155
152
|
provider: 'apple',
|
|
156
153
|
providerAccountId: id,
|
|
157
154
|
givenName,
|
|
@@ -183,13 +180,10 @@ class AppleAuthClient {
|
|
|
183
180
|
const canonicalId = (0, identity_js_1.resolveUnifiedUserId)({ id: rawId, email: finalEmail, emailVerified: true }, 'apple');
|
|
184
181
|
const user = {
|
|
185
182
|
id: canonicalId,
|
|
186
|
-
userId: canonicalId,
|
|
187
183
|
email: finalEmail,
|
|
188
184
|
emailVerified: true,
|
|
189
185
|
name: resolvedName,
|
|
190
|
-
displayName: resolvedName,
|
|
191
186
|
avatarUrl: null,
|
|
192
|
-
picture: null,
|
|
193
187
|
provider: 'apple',
|
|
194
188
|
providerAccountId: rawId,
|
|
195
189
|
givenName: resolvedGivenName,
|
package/dist/auth/github.js
CHANGED
|
@@ -226,16 +226,13 @@ class GitHubAuthClient {
|
|
|
226
226
|
const avatarUrl = raw.avatar_url || null;
|
|
227
227
|
return {
|
|
228
228
|
id,
|
|
229
|
-
userId: id,
|
|
230
229
|
login: raw.login,
|
|
231
230
|
name,
|
|
232
|
-
displayName: name,
|
|
233
231
|
email: normalizedEmail,
|
|
234
232
|
emailVerified: true,
|
|
235
233
|
provider: 'github',
|
|
236
234
|
providerAccountId: rawId,
|
|
237
235
|
avatarUrl,
|
|
238
|
-
picture: avatarUrl,
|
|
239
236
|
bio: raw.bio,
|
|
240
237
|
company: raw.company,
|
|
241
238
|
location: raw.location,
|
package/dist/auth/google.js
CHANGED
|
@@ -240,13 +240,10 @@ class GoogleAuthClient {
|
|
|
240
240
|
const avatarUrl = raw.picture || null;
|
|
241
241
|
return {
|
|
242
242
|
id,
|
|
243
|
-
userId: id,
|
|
244
243
|
email,
|
|
245
244
|
emailVerified,
|
|
246
245
|
name,
|
|
247
|
-
displayName: name,
|
|
248
246
|
avatarUrl,
|
|
249
|
-
picture: avatarUrl,
|
|
250
247
|
provider: 'google',
|
|
251
248
|
providerAccountId: sub,
|
|
252
249
|
givenName: raw.given_name,
|
package/dist/auth/identity.d.ts
CHANGED
|
@@ -7,20 +7,15 @@ export type SupportedAuthProvider = 'google' | 'github' | 'microsoft' | 'apple'
|
|
|
7
7
|
export interface AuthUser {
|
|
8
8
|
/** Canonical deterministic UUID across all providers with the same verified email */
|
|
9
9
|
id: string;
|
|
10
|
-
/** Alias for id to ensure compatibility with session records and sync workers */
|
|
11
|
-
userId: string;
|
|
12
10
|
email: string;
|
|
13
11
|
emailVerified: boolean;
|
|
14
12
|
name: string;
|
|
15
|
-
displayName: string;
|
|
16
13
|
avatarUrl?: string | null;
|
|
17
|
-
picture?: string | null;
|
|
18
14
|
provider: SupportedAuthProvider;
|
|
19
15
|
providerAccountId: string;
|
|
20
16
|
rawProfile?: Record<string, any>;
|
|
21
17
|
createdAt?: number;
|
|
22
18
|
}
|
|
23
|
-
export type UnifiedAuthUser = AuthUser;
|
|
24
19
|
export interface IdentityResolverOptions {
|
|
25
20
|
namespace?: string;
|
|
26
21
|
requireVerifiedEmail?: boolean;
|
package/dist/auth/identity.js
CHANGED
|
@@ -52,13 +52,10 @@ function createUnifiedAuthUser(rawUser, provider, options) {
|
|
|
52
52
|
: null;
|
|
53
53
|
return {
|
|
54
54
|
id,
|
|
55
|
-
userId: id,
|
|
56
55
|
email,
|
|
57
56
|
emailVerified,
|
|
58
57
|
name,
|
|
59
|
-
displayName: name,
|
|
60
58
|
avatarUrl,
|
|
61
|
-
picture: avatarUrl,
|
|
62
59
|
provider,
|
|
63
60
|
providerAccountId,
|
|
64
61
|
rawProfile: rawUser,
|
package/dist/auth/microsoft.js
CHANGED
|
@@ -246,13 +246,10 @@ class MicrosoftAuthClient {
|
|
|
246
246
|
const name = raw.displayName || email || 'Microsoft User';
|
|
247
247
|
return {
|
|
248
248
|
id,
|
|
249
|
-
userId: id,
|
|
250
249
|
email,
|
|
251
250
|
emailVerified: true,
|
|
252
251
|
name,
|
|
253
|
-
displayName: name,
|
|
254
252
|
avatarUrl: null,
|
|
255
|
-
picture: null,
|
|
256
253
|
provider: 'microsoft',
|
|
257
254
|
providerAccountId: sub,
|
|
258
255
|
givenName: raw.givenName,
|
package/dist/auth/unified.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { MicrosoftAuthClient } from './microsoft.js';
|
|
|
4
4
|
import { AppleAuthClient } from './apple.js';
|
|
5
5
|
import { LocalAuthEngine } from './local.js';
|
|
6
6
|
import { SessionManager, SessionRecord } from './session.js';
|
|
7
|
-
import { SupportedAuthProvider,
|
|
7
|
+
import { SupportedAuthProvider, AuthUser } from './identity.js';
|
|
8
8
|
export interface UnifiedAuthConfig {
|
|
9
9
|
google?: GoogleAuthClient;
|
|
10
10
|
github?: GitHubAuthClient;
|
|
@@ -23,7 +23,7 @@ export interface UnifiedAuthConfig {
|
|
|
23
23
|
*/
|
|
24
24
|
emailNamespace?: string;
|
|
25
25
|
}
|
|
26
|
-
export type AuthStateChangeListener = (user:
|
|
26
|
+
export type AuthStateChangeListener = (user: AuthUser | null) => void;
|
|
27
27
|
/**
|
|
28
28
|
* High-level orchestrator that unifies multiple OAuth providers (Google, GitHub,
|
|
29
29
|
* Microsoft, Apple) and local auth into a single consistent user identity model.
|
|
@@ -49,15 +49,15 @@ export declare class UnifiedAuthManager {
|
|
|
49
49
|
/**
|
|
50
50
|
* Authenticates using the specified provider and automatically establishes a unified session.
|
|
51
51
|
*/
|
|
52
|
-
signIn(provider: SupportedAuthProvider, credentials?: any): Promise<
|
|
52
|
+
signIn(provider: SupportedAuthProvider, credentials?: any): Promise<AuthUser | null>;
|
|
53
53
|
/**
|
|
54
54
|
* Retrieves the currently authenticated unified user.
|
|
55
55
|
*/
|
|
56
|
-
getUser(): Promise<
|
|
56
|
+
getUser(): Promise<AuthUser | null>;
|
|
57
57
|
/**
|
|
58
58
|
* Retrieves the active SQLite session record.
|
|
59
59
|
*/
|
|
60
|
-
getSession(): Promise<SessionRecord<
|
|
60
|
+
getSession(): Promise<SessionRecord<AuthUser> | null>;
|
|
61
61
|
/**
|
|
62
62
|
* Checks whether there is an active session or signed-in provider.
|
|
63
63
|
*/
|
package/dist/auth/unified.js
CHANGED
package/dist/config/index.d.ts
CHANGED
|
@@ -3,18 +3,6 @@ import { LocalLiteConfig } from './types.js';
|
|
|
3
3
|
export * from './types.js';
|
|
4
4
|
export { resolveLocalAdapter } from './resolve-local.js';
|
|
5
5
|
export { resolveRemoteAdapter } from './resolve-remote.js';
|
|
6
|
-
export { LocalFirstClient } from '../core/client.js';
|
|
7
|
-
export { ExpoSQLiteAdapter } from '../adapters/local/expo-sqlite.js';
|
|
8
|
-
export { OpSQLiteAdapter } from '../adapters/local/op-sqlite.js';
|
|
9
|
-
export { BetterSQLite3Adapter } from '../adapters/local/better-sqlite3.js';
|
|
10
|
-
export { LibSQLAdapter } from '../adapters/local/libsql.js';
|
|
11
|
-
export { SqlJsAdapter } from '../adapters/local/sql-js.js';
|
|
12
|
-
export { NodeSQLiteAdapter } from '../adapters/local/node-sqlite.js';
|
|
13
|
-
export { SupabaseRemoteAdapter } from '../adapters/remote/supabase.js';
|
|
14
|
-
export { ConvexRemoteAdapter } from '../adapters/remote/convex.js';
|
|
15
|
-
export { FirestoreRemoteAdapter } from '../adapters/remote/firestore.js';
|
|
16
|
-
export { SelfHostedRemoteAdapter } from '../adapters/remote/self-hosted.js';
|
|
17
|
-
export type { RemoteDBAdapter } from '../adapters/remote/index.js';
|
|
18
6
|
/**
|
|
19
7
|
* Type-safe configuration helper function (similar to defineConfig in Vite/Tailwind).
|
|
20
8
|
*/
|
package/dist/config/index.js
CHANGED
|
@@ -14,11 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.resolveRemoteAdapter = exports.resolveLocalAdapter = void 0;
|
|
18
18
|
exports.defineSyncConfig = defineSyncConfig;
|
|
19
19
|
exports.createSyncClient = createSyncClient;
|
|
20
20
|
const client_js_1 = require("../core/client.js");
|
|
21
21
|
const index_js_1 = require("../adapters/network/index.js");
|
|
22
|
+
const index_js_2 = require("../email/index.js");
|
|
22
23
|
const resolve_local_js_1 = require("./resolve-local.js");
|
|
23
24
|
const resolve_remote_js_1 = require("./resolve-remote.js");
|
|
24
25
|
// Export all config types
|
|
@@ -28,29 +29,6 @@ var resolve_local_js_2 = require("./resolve-local.js");
|
|
|
28
29
|
Object.defineProperty(exports, "resolveLocalAdapter", { enumerable: true, get: function () { return resolve_local_js_2.resolveLocalAdapter; } });
|
|
29
30
|
var resolve_remote_js_2 = require("./resolve-remote.js");
|
|
30
31
|
Object.defineProperty(exports, "resolveRemoteAdapter", { enumerable: true, get: function () { return resolve_remote_js_2.resolveRemoteAdapter; } });
|
|
31
|
-
// Re-export adapters and core client for convenience
|
|
32
|
-
var client_js_2 = require("../core/client.js");
|
|
33
|
-
Object.defineProperty(exports, "LocalFirstClient", { enumerable: true, get: function () { return client_js_2.LocalFirstClient; } });
|
|
34
|
-
var expo_sqlite_js_1 = require("../adapters/local/expo-sqlite.js");
|
|
35
|
-
Object.defineProperty(exports, "ExpoSQLiteAdapter", { enumerable: true, get: function () { return expo_sqlite_js_1.ExpoSQLiteAdapter; } });
|
|
36
|
-
var op_sqlite_js_1 = require("../adapters/local/op-sqlite.js");
|
|
37
|
-
Object.defineProperty(exports, "OpSQLiteAdapter", { enumerable: true, get: function () { return op_sqlite_js_1.OpSQLiteAdapter; } });
|
|
38
|
-
var better_sqlite3_js_1 = require("../adapters/local/better-sqlite3.js");
|
|
39
|
-
Object.defineProperty(exports, "BetterSQLite3Adapter", { enumerable: true, get: function () { return better_sqlite3_js_1.BetterSQLite3Adapter; } });
|
|
40
|
-
var libsql_js_1 = require("../adapters/local/libsql.js");
|
|
41
|
-
Object.defineProperty(exports, "LibSQLAdapter", { enumerable: true, get: function () { return libsql_js_1.LibSQLAdapter; } });
|
|
42
|
-
var sql_js_js_1 = require("../adapters/local/sql-js.js");
|
|
43
|
-
Object.defineProperty(exports, "SqlJsAdapter", { enumerable: true, get: function () { return sql_js_js_1.SqlJsAdapter; } });
|
|
44
|
-
var node_sqlite_js_1 = require("../adapters/local/node-sqlite.js");
|
|
45
|
-
Object.defineProperty(exports, "NodeSQLiteAdapter", { enumerable: true, get: function () { return node_sqlite_js_1.NodeSQLiteAdapter; } });
|
|
46
|
-
var supabase_js_1 = require("../adapters/remote/supabase.js");
|
|
47
|
-
Object.defineProperty(exports, "SupabaseRemoteAdapter", { enumerable: true, get: function () { return supabase_js_1.SupabaseRemoteAdapter; } });
|
|
48
|
-
var convex_js_1 = require("../adapters/remote/convex.js");
|
|
49
|
-
Object.defineProperty(exports, "ConvexRemoteAdapter", { enumerable: true, get: function () { return convex_js_1.ConvexRemoteAdapter; } });
|
|
50
|
-
var firestore_js_1 = require("../adapters/remote/firestore.js");
|
|
51
|
-
Object.defineProperty(exports, "FirestoreRemoteAdapter", { enumerable: true, get: function () { return firestore_js_1.FirestoreRemoteAdapter; } });
|
|
52
|
-
var self_hosted_js_1 = require("../adapters/remote/self-hosted.js");
|
|
53
|
-
Object.defineProperty(exports, "SelfHostedRemoteAdapter", { enumerable: true, get: function () { return self_hosted_js_1.SelfHostedRemoteAdapter; } });
|
|
54
32
|
/**
|
|
55
33
|
* Type-safe configuration helper function (similar to defineConfig in Vite/Tailwind).
|
|
56
34
|
*/
|
|
@@ -101,8 +79,7 @@ async function createSyncClient(config) {
|
|
|
101
79
|
if (config.email.transport || config.email.provider === 'nodemailer') {
|
|
102
80
|
throw new Error("Nodemailer email delivery is server-only. Import 'local-lite/server' and register createNodemailerHandler from your server runtime.");
|
|
103
81
|
}
|
|
104
|
-
const
|
|
105
|
-
const emailHandler = createEmailHandler({
|
|
82
|
+
const emailHandler = (0, index_js_2.createEmailHandler)({
|
|
106
83
|
provider: config.email.provider,
|
|
107
84
|
transport: config.email.transport,
|
|
108
85
|
apiKey: config.email.apiKey,
|
package/dist/config/types.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export interface ConvexConfigOptions {
|
|
|
49
49
|
}
|
|
50
50
|
export interface FirebaseConfigOptions {
|
|
51
51
|
/**
|
|
52
|
-
* Firestore database instance (from modular firebase/firestore
|
|
52
|
+
* Firestore database instance (from modular `firebase/firestore` v11+ SDK).
|
|
53
53
|
*/
|
|
54
54
|
firestore: any;
|
|
55
55
|
/**
|
|
@@ -77,8 +77,9 @@ export interface EmailConfig {
|
|
|
77
77
|
* - 'sendgrid': Direct HTTP dispatch to SendGrid API.
|
|
78
78
|
* - 'postmark': Direct HTTP dispatch to Postmark API.
|
|
79
79
|
* - 'http': Custom HTTP endpoint or webhook.
|
|
80
|
+
* - 'preview': Local in-memory DevMailbox for development and testing.
|
|
80
81
|
*/
|
|
81
|
-
provider?: 'nodemailer' | 'resend' | 'sendgrid' | 'postmark' | 'http' | 'custom';
|
|
82
|
+
provider?: 'nodemailer' | 'resend' | 'sendgrid' | 'postmark' | 'http' | 'preview' | 'custom';
|
|
82
83
|
/**
|
|
83
84
|
* Transport configuration for Nodemailer:
|
|
84
85
|
* - A Nodemailer Transporter instance (e.g. from nodemailer.createTransport(...))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { LocalDBAdapter } from '../adapters/local/index.js';
|
|
2
|
+
import type { SyncOp } from './types.js';
|
|
3
|
+
export interface AuditEntry {
|
|
4
|
+
id: string;
|
|
5
|
+
tableName: string;
|
|
6
|
+
rowId: string;
|
|
7
|
+
operation: SyncOp;
|
|
8
|
+
before: Record<string, any> | null;
|
|
9
|
+
after: Record<string, any> | null;
|
|
10
|
+
actor?: string | null;
|
|
11
|
+
createdAt: number;
|
|
12
|
+
undone: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface AuditClientLike {
|
|
15
|
+
db: LocalDBAdapter;
|
|
16
|
+
getPrimaryKey(): string;
|
|
17
|
+
insert(tableName: string, payload: Record<string, any>, options?: any): Promise<any>;
|
|
18
|
+
update(tableName: string, rowId: string, payload: Record<string, any>, options?: any): Promise<any>;
|
|
19
|
+
delete(tableName: string, rowId: string, options?: any): Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Local row-level audit log and undo/redo manager backed by `_audit_log`.
|
|
23
|
+
*/
|
|
24
|
+
export declare class AuditManager {
|
|
25
|
+
private db;
|
|
26
|
+
private initialized;
|
|
27
|
+
constructor(db: LocalDBAdapter);
|
|
28
|
+
initialize(): Promise<void>;
|
|
29
|
+
record(params: {
|
|
30
|
+
tableName: string;
|
|
31
|
+
rowId: string;
|
|
32
|
+
operation: SyncOp;
|
|
33
|
+
before?: Record<string, any> | null;
|
|
34
|
+
after?: Record<string, any> | null;
|
|
35
|
+
actor?: string | null;
|
|
36
|
+
createdAt?: number;
|
|
37
|
+
}): Promise<AuditEntry>;
|
|
38
|
+
getHistory(options?: {
|
|
39
|
+
tableName?: string;
|
|
40
|
+
rowId?: string;
|
|
41
|
+
limit?: number;
|
|
42
|
+
includeUndone?: boolean;
|
|
43
|
+
}): Promise<AuditEntry[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Reverts the most recent active audit entry on the provided client.
|
|
46
|
+
*/
|
|
47
|
+
undo(client: AuditClientLike): Promise<AuditEntry | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Re-applies the most recently undone audit entry on the provided client.
|
|
50
|
+
*/
|
|
51
|
+
redo(client: AuditClientLike): Promise<AuditEntry | null>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuditManager = void 0;
|
|
4
|
+
const uuid_js_1 = require("../utils/uuid.js");
|
|
5
|
+
/**
|
|
6
|
+
* Local row-level audit log and undo/redo manager backed by `_audit_log`.
|
|
7
|
+
*/
|
|
8
|
+
class AuditManager {
|
|
9
|
+
db;
|
|
10
|
+
initialized = false;
|
|
11
|
+
constructor(db) {
|
|
12
|
+
this.db = db;
|
|
13
|
+
}
|
|
14
|
+
async initialize() {
|
|
15
|
+
if (this.initialized)
|
|
16
|
+
return;
|
|
17
|
+
await this.db.execute(`
|
|
18
|
+
CREATE TABLE IF NOT EXISTS _audit_log (
|
|
19
|
+
id TEXT PRIMARY KEY,
|
|
20
|
+
table_name TEXT NOT NULL,
|
|
21
|
+
row_id TEXT NOT NULL,
|
|
22
|
+
operation TEXT NOT NULL,
|
|
23
|
+
before_json TEXT,
|
|
24
|
+
after_json TEXT,
|
|
25
|
+
actor TEXT,
|
|
26
|
+
created_at INTEGER NOT NULL,
|
|
27
|
+
undone INTEGER NOT NULL DEFAULT 0
|
|
28
|
+
)
|
|
29
|
+
`);
|
|
30
|
+
await this.db.execute(`CREATE INDEX IF NOT EXISTS idx_audit_log_table_row ON _audit_log (table_name, row_id, created_at DESC)`);
|
|
31
|
+
this.initialized = true;
|
|
32
|
+
}
|
|
33
|
+
async record(params) {
|
|
34
|
+
await this.initialize();
|
|
35
|
+
const id = (0, uuid_js_1.generateUUID)();
|
|
36
|
+
const createdAt = params.createdAt ?? Date.now();
|
|
37
|
+
await this.db.execute(`INSERT INTO _audit_log (id, table_name, row_id, operation, before_json, after_json, actor, created_at, undone)
|
|
38
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0)`, [
|
|
39
|
+
id,
|
|
40
|
+
params.tableName,
|
|
41
|
+
params.rowId,
|
|
42
|
+
params.operation,
|
|
43
|
+
params.before ? JSON.stringify(params.before) : null,
|
|
44
|
+
params.after ? JSON.stringify(params.after) : null,
|
|
45
|
+
params.actor ?? null,
|
|
46
|
+
createdAt,
|
|
47
|
+
]);
|
|
48
|
+
return {
|
|
49
|
+
id,
|
|
50
|
+
tableName: params.tableName,
|
|
51
|
+
rowId: params.rowId,
|
|
52
|
+
operation: params.operation,
|
|
53
|
+
before: params.before ?? null,
|
|
54
|
+
after: params.after ?? null,
|
|
55
|
+
actor: params.actor ?? null,
|
|
56
|
+
createdAt,
|
|
57
|
+
undone: false,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async getHistory(options) {
|
|
61
|
+
await this.initialize();
|
|
62
|
+
const where = [];
|
|
63
|
+
const params = [];
|
|
64
|
+
if (options?.tableName) {
|
|
65
|
+
where.push('table_name = ?');
|
|
66
|
+
params.push(options.tableName);
|
|
67
|
+
}
|
|
68
|
+
if (options?.rowId) {
|
|
69
|
+
where.push('row_id = ?');
|
|
70
|
+
params.push(options.rowId);
|
|
71
|
+
}
|
|
72
|
+
if (!options?.includeUndone) {
|
|
73
|
+
where.push('undone = 0');
|
|
74
|
+
}
|
|
75
|
+
const whereSql = where.length > 0 ? `WHERE ${where.join(' AND ')}` : '';
|
|
76
|
+
const limitSql = typeof options?.limit === 'number' ? `LIMIT ${Math.max(1, options.limit)}` : '';
|
|
77
|
+
const rows = await this.db.execute(`SELECT * FROM _audit_log ${whereSql} ORDER BY created_at DESC, rowid DESC ${limitSql}`, params);
|
|
78
|
+
return rows.map((r) => ({
|
|
79
|
+
id: r.id,
|
|
80
|
+
tableName: r.table_name,
|
|
81
|
+
rowId: r.row_id,
|
|
82
|
+
operation: r.operation,
|
|
83
|
+
before: r.before_json ? JSON.parse(r.before_json) : null,
|
|
84
|
+
after: r.after_json ? JSON.parse(r.after_json) : null,
|
|
85
|
+
actor: r.actor ?? null,
|
|
86
|
+
createdAt: Number(r.created_at),
|
|
87
|
+
undone: r.undone === 1 || r.undone === true,
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Reverts the most recent active audit entry on the provided client.
|
|
92
|
+
*/
|
|
93
|
+
async undo(client) {
|
|
94
|
+
await this.initialize();
|
|
95
|
+
const [latest] = await this.getHistory({ limit: 1, includeUndone: false });
|
|
96
|
+
if (!latest)
|
|
97
|
+
return null;
|
|
98
|
+
if (latest.operation === 'INSERT') {
|
|
99
|
+
await client.delete(latest.tableName, latest.rowId);
|
|
100
|
+
}
|
|
101
|
+
else if (latest.operation === 'UPDATE' && latest.before) {
|
|
102
|
+
await client.update(latest.tableName, latest.rowId, latest.before);
|
|
103
|
+
}
|
|
104
|
+
else if (latest.operation === 'DELETE' && latest.before) {
|
|
105
|
+
await client.insert(latest.tableName, {
|
|
106
|
+
...latest.before,
|
|
107
|
+
[client.getPrimaryKey()]: latest.rowId,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
await this.db.execute(`UPDATE _audit_log SET undone = 1 WHERE id = ?`, [
|
|
111
|
+
latest.id,
|
|
112
|
+
]);
|
|
113
|
+
return { ...latest, undone: true };
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Re-applies the most recently undone audit entry on the provided client.
|
|
117
|
+
*/
|
|
118
|
+
async redo(client) {
|
|
119
|
+
await this.initialize();
|
|
120
|
+
const rows = await this.db.execute(`SELECT * FROM _audit_log WHERE undone = 1 ORDER BY created_at ASC, rowid ASC LIMIT 1`);
|
|
121
|
+
if (!rows || rows.length === 0)
|
|
122
|
+
return null;
|
|
123
|
+
const r = rows[0];
|
|
124
|
+
const entry = {
|
|
125
|
+
id: r.id,
|
|
126
|
+
tableName: r.table_name,
|
|
127
|
+
rowId: r.row_id,
|
|
128
|
+
operation: r.operation,
|
|
129
|
+
before: r.before_json ? JSON.parse(r.before_json) : null,
|
|
130
|
+
after: r.after_json ? JSON.parse(r.after_json) : null,
|
|
131
|
+
actor: r.actor ?? null,
|
|
132
|
+
createdAt: Number(r.created_at),
|
|
133
|
+
undone: true,
|
|
134
|
+
};
|
|
135
|
+
if (entry.operation === 'INSERT' && entry.after) {
|
|
136
|
+
await client.insert(entry.tableName, {
|
|
137
|
+
...entry.after,
|
|
138
|
+
[client.getPrimaryKey()]: entry.rowId,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else if (entry.operation === 'UPDATE' && entry.after) {
|
|
142
|
+
await client.update(entry.tableName, entry.rowId, entry.after);
|
|
143
|
+
}
|
|
144
|
+
else if (entry.operation === 'DELETE') {
|
|
145
|
+
await client.delete(entry.tableName, entry.rowId);
|
|
146
|
+
}
|
|
147
|
+
await this.db.execute(`UPDATE _audit_log SET undone = 0 WHERE id = ?`, [
|
|
148
|
+
entry.id,
|
|
149
|
+
]);
|
|
150
|
+
return { ...entry, undone: false };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.AuditManager = AuditManager;
|
package/dist/core/client.d.ts
CHANGED
|
@@ -358,6 +358,10 @@ export declare class LocalFirstClient {
|
|
|
358
358
|
* Permanently clears failed mutations (removes poison-pill outbox records).
|
|
359
359
|
*/
|
|
360
360
|
clearFailedMutations(ids?: string[]): Promise<number>;
|
|
361
|
+
/**
|
|
362
|
+
* Edits the JSON payload of a queued or failed outbox mutation (useful for fixing poison-pill items before retry).
|
|
363
|
+
*/
|
|
364
|
+
editOutboxMutationPayload(id: string, payload: Record<string, any>): Promise<void>;
|
|
361
365
|
/**
|
|
362
366
|
* Retrieves the persisted last_synced_at timestamp cursor (in ms).
|
|
363
367
|
*/
|
package/dist/core/client.js
CHANGED
|
@@ -1255,6 +1255,13 @@ class LocalFirstClient {
|
|
|
1255
1255
|
}
|
|
1256
1256
|
return count;
|
|
1257
1257
|
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Edits the JSON payload of a queued or failed outbox mutation (useful for fixing poison-pill items before retry).
|
|
1260
|
+
*/
|
|
1261
|
+
async editOutboxMutationPayload(id, payload) {
|
|
1262
|
+
await outbox_store_js_1.OutboxStore.updatePayload(this.db, id, payload, Date.now());
|
|
1263
|
+
this.events.emit('sync_outbox', { operation: 'UPDATE', rowId: id });
|
|
1264
|
+
}
|
|
1258
1265
|
/**
|
|
1259
1266
|
* Retrieves the persisted last_synced_at timestamp cursor (in ms).
|
|
1260
1267
|
*/
|