local-lite 0.0.11 → 0.0.14
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 +49 -3
- package/dist/auth/apple.d.ts +91 -0
- package/dist/auth/apple.js +264 -0
- package/dist/auth/github.d.ts +72 -0
- package/dist/auth/github.js +284 -0
- package/dist/auth/google.d.ts +75 -0
- package/dist/auth/google.js +323 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +20 -0
- package/dist/auth/microsoft.d.ts +76 -0
- package/dist/auth/microsoft.js +310 -0
- package/dist/backups/encryption.d.ts +18 -0
- package/dist/backups/encryption.js +122 -0
- package/dist/backups/index.d.ts +2 -0
- package/dist/backups/index.js +11 -1
- package/dist/backups/onedrive.d.ts +22 -0
- package/dist/backups/onedrive.js +114 -0
- package/dist/core/client.d.ts +2 -0
- package/dist/core/client.js +3 -0
- package/dist/core/conflict.d.ts +8 -1
- package/dist/core/conflict.js +75 -0
- package/dist/core/maintenance.d.ts +66 -0
- package/dist/core/maintenance.js +157 -0
- package/dist/core/sync-worker.js +1 -1
- package/dist/core/types.d.ts +34 -4
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/react/auth.d.ts +46 -0
- package/dist/react/auth.js +365 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/utils/portability.d.ts +73 -0
- package/dist/utils/portability.js +276 -0
- package/package.json +6 -1
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useOneDriveAuth = void 0;
|
|
4
|
+
exports.useGoogleAuth = useGoogleAuth;
|
|
5
|
+
exports.useMicrosoftAuth = useMicrosoftAuth;
|
|
6
|
+
exports.useGitHubAuth = useGitHubAuth;
|
|
7
|
+
exports.useAppleAuth = useAppleAuth;
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
function useGoogleAuth(client) {
|
|
10
|
+
const [user, setUser] = (0, react_1.useState)(null);
|
|
11
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
12
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
13
|
+
(0, react_1.useEffect)(() => {
|
|
14
|
+
if (!client) {
|
|
15
|
+
setUser(null);
|
|
16
|
+
setLoading(false);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let isMounted = true;
|
|
20
|
+
client
|
|
21
|
+
.getUser()
|
|
22
|
+
.then(currentUser => {
|
|
23
|
+
if (isMounted) {
|
|
24
|
+
setUser(currentUser);
|
|
25
|
+
setLoading(false);
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
.catch(err => {
|
|
29
|
+
if (isMounted) {
|
|
30
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
31
|
+
setLoading(false);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
35
|
+
if (isMounted) {
|
|
36
|
+
setUser(updatedUser);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return () => {
|
|
40
|
+
isMounted = false;
|
|
41
|
+
unsubscribe();
|
|
42
|
+
};
|
|
43
|
+
}, [client]);
|
|
44
|
+
const signIn = (0, react_1.useCallback)(async () => {
|
|
45
|
+
if (!client)
|
|
46
|
+
throw new Error('GoogleAuthClient is not initialized.');
|
|
47
|
+
setError(null);
|
|
48
|
+
setLoading(true);
|
|
49
|
+
try {
|
|
50
|
+
const res = await client.signIn();
|
|
51
|
+
setUser(res);
|
|
52
|
+
return res;
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
56
|
+
setError(e);
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
setLoading(false);
|
|
61
|
+
}
|
|
62
|
+
}, [client]);
|
|
63
|
+
const signOut = (0, react_1.useCallback)(async () => {
|
|
64
|
+
if (!client)
|
|
65
|
+
return;
|
|
66
|
+
setError(null);
|
|
67
|
+
setLoading(true);
|
|
68
|
+
try {
|
|
69
|
+
await client.signOut();
|
|
70
|
+
setUser(null);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
74
|
+
setError(e);
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
setLoading(false);
|
|
79
|
+
}
|
|
80
|
+
}, [client]);
|
|
81
|
+
const refetchUser = (0, react_1.useCallback)(async () => {
|
|
82
|
+
if (!client)
|
|
83
|
+
return null;
|
|
84
|
+
const res = await client.getUser();
|
|
85
|
+
setUser(res);
|
|
86
|
+
return res;
|
|
87
|
+
}, [client]);
|
|
88
|
+
return {
|
|
89
|
+
user,
|
|
90
|
+
isSignedIn: Boolean(user),
|
|
91
|
+
loading,
|
|
92
|
+
error,
|
|
93
|
+
signIn,
|
|
94
|
+
signOut,
|
|
95
|
+
refetchUser,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function useMicrosoftAuth(client) {
|
|
99
|
+
const [user, setUser] = (0, react_1.useState)(null);
|
|
100
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
101
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
102
|
+
(0, react_1.useEffect)(() => {
|
|
103
|
+
if (!client) {
|
|
104
|
+
setUser(null);
|
|
105
|
+
setLoading(false);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
let isMounted = true;
|
|
109
|
+
client
|
|
110
|
+
.getUser()
|
|
111
|
+
.then(currentUser => {
|
|
112
|
+
if (isMounted) {
|
|
113
|
+
setUser(currentUser);
|
|
114
|
+
setLoading(false);
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
.catch(err => {
|
|
118
|
+
if (isMounted) {
|
|
119
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
120
|
+
setLoading(false);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
124
|
+
if (isMounted) {
|
|
125
|
+
setUser(updatedUser);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return () => {
|
|
129
|
+
isMounted = false;
|
|
130
|
+
unsubscribe();
|
|
131
|
+
};
|
|
132
|
+
}, [client]);
|
|
133
|
+
const signIn = (0, react_1.useCallback)(async () => {
|
|
134
|
+
if (!client)
|
|
135
|
+
throw new Error('MicrosoftAuthClient is not initialized.');
|
|
136
|
+
setError(null);
|
|
137
|
+
setLoading(true);
|
|
138
|
+
try {
|
|
139
|
+
const res = await client.signIn();
|
|
140
|
+
setUser(res);
|
|
141
|
+
return res;
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
145
|
+
setError(e);
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
setLoading(false);
|
|
150
|
+
}
|
|
151
|
+
}, [client]);
|
|
152
|
+
const signOut = (0, react_1.useCallback)(async () => {
|
|
153
|
+
if (!client)
|
|
154
|
+
return;
|
|
155
|
+
setError(null);
|
|
156
|
+
setLoading(true);
|
|
157
|
+
try {
|
|
158
|
+
await client.signOut();
|
|
159
|
+
setUser(null);
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
163
|
+
setError(e);
|
|
164
|
+
throw e;
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
setLoading(false);
|
|
168
|
+
}
|
|
169
|
+
}, [client]);
|
|
170
|
+
const refetchUser = (0, react_1.useCallback)(async () => {
|
|
171
|
+
if (!client)
|
|
172
|
+
return null;
|
|
173
|
+
const res = await client.getUser();
|
|
174
|
+
setUser(res);
|
|
175
|
+
return res;
|
|
176
|
+
}, [client]);
|
|
177
|
+
return {
|
|
178
|
+
user,
|
|
179
|
+
isSignedIn: Boolean(user),
|
|
180
|
+
loading,
|
|
181
|
+
error,
|
|
182
|
+
signIn,
|
|
183
|
+
signOut,
|
|
184
|
+
refetchUser,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
exports.useOneDriveAuth = useMicrosoftAuth;
|
|
188
|
+
function useGitHubAuth(client) {
|
|
189
|
+
const [user, setUser] = (0, react_1.useState)(null);
|
|
190
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
191
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
192
|
+
(0, react_1.useEffect)(() => {
|
|
193
|
+
if (!client) {
|
|
194
|
+
setUser(null);
|
|
195
|
+
setLoading(false);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
let isMounted = true;
|
|
199
|
+
client
|
|
200
|
+
.getUser()
|
|
201
|
+
.then(currentUser => {
|
|
202
|
+
if (isMounted) {
|
|
203
|
+
setUser(currentUser);
|
|
204
|
+
setLoading(false);
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
.catch(err => {
|
|
208
|
+
if (isMounted) {
|
|
209
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
210
|
+
setLoading(false);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
214
|
+
if (isMounted) {
|
|
215
|
+
setUser(updatedUser);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
return () => {
|
|
219
|
+
isMounted = false;
|
|
220
|
+
unsubscribe();
|
|
221
|
+
};
|
|
222
|
+
}, [client]);
|
|
223
|
+
const signIn = (0, react_1.useCallback)(async () => {
|
|
224
|
+
if (!client)
|
|
225
|
+
throw new Error('GitHubAuthClient is not initialized.');
|
|
226
|
+
setError(null);
|
|
227
|
+
setLoading(true);
|
|
228
|
+
try {
|
|
229
|
+
const res = await client.signIn();
|
|
230
|
+
setUser(res);
|
|
231
|
+
return res;
|
|
232
|
+
}
|
|
233
|
+
catch (err) {
|
|
234
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
235
|
+
setError(e);
|
|
236
|
+
throw e;
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
setLoading(false);
|
|
240
|
+
}
|
|
241
|
+
}, [client]);
|
|
242
|
+
const signOut = (0, react_1.useCallback)(async () => {
|
|
243
|
+
if (!client)
|
|
244
|
+
return;
|
|
245
|
+
setError(null);
|
|
246
|
+
setLoading(true);
|
|
247
|
+
try {
|
|
248
|
+
await client.signOut();
|
|
249
|
+
setUser(null);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
253
|
+
setError(e);
|
|
254
|
+
throw e;
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
setLoading(false);
|
|
258
|
+
}
|
|
259
|
+
}, [client]);
|
|
260
|
+
const refetchUser = (0, react_1.useCallback)(async () => {
|
|
261
|
+
if (!client)
|
|
262
|
+
return null;
|
|
263
|
+
const res = await client.getUser();
|
|
264
|
+
setUser(res);
|
|
265
|
+
return res;
|
|
266
|
+
}, [client]);
|
|
267
|
+
return {
|
|
268
|
+
user,
|
|
269
|
+
isSignedIn: Boolean(user),
|
|
270
|
+
loading,
|
|
271
|
+
error,
|
|
272
|
+
signIn,
|
|
273
|
+
signOut,
|
|
274
|
+
refetchUser,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function useAppleAuth(client) {
|
|
278
|
+
const [user, setUser] = (0, react_1.useState)(null);
|
|
279
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
280
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
281
|
+
(0, react_1.useEffect)(() => {
|
|
282
|
+
if (!client) {
|
|
283
|
+
setUser(null);
|
|
284
|
+
setLoading(false);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
let isMounted = true;
|
|
288
|
+
client
|
|
289
|
+
.getUser()
|
|
290
|
+
.then(currentUser => {
|
|
291
|
+
if (isMounted) {
|
|
292
|
+
setUser(currentUser);
|
|
293
|
+
setLoading(false);
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
.catch(err => {
|
|
297
|
+
if (isMounted) {
|
|
298
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
299
|
+
setLoading(false);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
303
|
+
if (isMounted) {
|
|
304
|
+
setUser(updatedUser);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
return () => {
|
|
308
|
+
isMounted = false;
|
|
309
|
+
unsubscribe();
|
|
310
|
+
};
|
|
311
|
+
}, [client]);
|
|
312
|
+
const signIn = (0, react_1.useCallback)(async (nativeCredential) => {
|
|
313
|
+
if (!client)
|
|
314
|
+
throw new Error('AppleAuthClient is not initialized.');
|
|
315
|
+
setError(null);
|
|
316
|
+
setLoading(true);
|
|
317
|
+
try {
|
|
318
|
+
const res = await client.signIn(nativeCredential);
|
|
319
|
+
setUser(res);
|
|
320
|
+
return res;
|
|
321
|
+
}
|
|
322
|
+
catch (err) {
|
|
323
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
324
|
+
setError(e);
|
|
325
|
+
throw e;
|
|
326
|
+
}
|
|
327
|
+
finally {
|
|
328
|
+
setLoading(false);
|
|
329
|
+
}
|
|
330
|
+
}, [client]);
|
|
331
|
+
const signOut = (0, react_1.useCallback)(async () => {
|
|
332
|
+
if (!client)
|
|
333
|
+
return;
|
|
334
|
+
setError(null);
|
|
335
|
+
setLoading(true);
|
|
336
|
+
try {
|
|
337
|
+
await client.signOut();
|
|
338
|
+
setUser(null);
|
|
339
|
+
}
|
|
340
|
+
catch (err) {
|
|
341
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
342
|
+
setError(e);
|
|
343
|
+
throw e;
|
|
344
|
+
}
|
|
345
|
+
finally {
|
|
346
|
+
setLoading(false);
|
|
347
|
+
}
|
|
348
|
+
}, [client]);
|
|
349
|
+
const refetchUser = (0, react_1.useCallback)(async () => {
|
|
350
|
+
if (!client)
|
|
351
|
+
return null;
|
|
352
|
+
const res = await client.getUser();
|
|
353
|
+
setUser(res);
|
|
354
|
+
return res;
|
|
355
|
+
}, [client]);
|
|
356
|
+
return {
|
|
357
|
+
user,
|
|
358
|
+
isSignedIn: Boolean(user),
|
|
359
|
+
loading,
|
|
360
|
+
error,
|
|
361
|
+
signIn,
|
|
362
|
+
signOut,
|
|
363
|
+
refetchUser,
|
|
364
|
+
};
|
|
365
|
+
}
|
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -594,3 +594,4 @@ __exportStar(require("./BenchmarkModal.js"), exports);
|
|
|
594
594
|
var SyncInspector_js_1 = require("./SyncInspector.js");
|
|
595
595
|
Object.defineProperty(exports, "SyncInspector", { enumerable: true, get: function () { return SyncInspector_js_1.SyncInspector; } });
|
|
596
596
|
Object.defineProperty(exports, "SyncIndicator", { enumerable: true, get: function () { return SyncInspector_js_1.SyncIndicator; } });
|
|
597
|
+
__exportStar(require("./auth.js"), exports);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { LocalFirstClient } from '../core/client.js';
|
|
2
|
+
export interface ExportJsonOptions {
|
|
3
|
+
/** Pretty-print JSON with 2-space indentation. Default: false */
|
|
4
|
+
pretty?: boolean;
|
|
5
|
+
/** Explicit list of tables to export. If not specified, exports all registered tables. */
|
|
6
|
+
tables?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface JsonExportData {
|
|
9
|
+
version: number;
|
|
10
|
+
exportedAt: string;
|
|
11
|
+
tables: Record<string, Array<Record<string, any>>>;
|
|
12
|
+
}
|
|
13
|
+
export interface ImportJsonOptions {
|
|
14
|
+
/**
|
|
15
|
+
* 'merge' (default): updates existing rows and inserts new rows using primary key.
|
|
16
|
+
* 'replace': deletes all rows in the table before inserting the imported data.
|
|
17
|
+
*/
|
|
18
|
+
mode?: 'merge' | 'replace';
|
|
19
|
+
/**
|
|
20
|
+
* Whether to skip queueing outbox mutations for remote sync.
|
|
21
|
+
* When true, imported data is only stored in local SQLite without triggering sync pushes.
|
|
22
|
+
* Default: false.
|
|
23
|
+
*/
|
|
24
|
+
skipOutbox?: boolean;
|
|
25
|
+
/** Whitelist of tables to import. If specified, any tables in JSON not in this list are ignored. */
|
|
26
|
+
tables?: string[];
|
|
27
|
+
}
|
|
28
|
+
export interface ExportCsvOptions {
|
|
29
|
+
/** Columns to export in order. If omitted, uses all columns from the table. */
|
|
30
|
+
columns?: string[];
|
|
31
|
+
/** Field delimiter. Default: ',' */
|
|
32
|
+
delimiter?: string;
|
|
33
|
+
/** Whether to output the first row as column headers. Default: true */
|
|
34
|
+
includeHeader?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface ImportCsvOptions {
|
|
37
|
+
/** 'merge' (default) or 'replace' */
|
|
38
|
+
mode?: 'merge' | 'replace';
|
|
39
|
+
/** Whether to skip queueing outbox records. Default: false */
|
|
40
|
+
skipOutbox?: boolean;
|
|
41
|
+
/** Field delimiter. Default: ',' */
|
|
42
|
+
delimiter?: string;
|
|
43
|
+
/** Whether the first line contains header columns. Default: true */
|
|
44
|
+
hasHeader?: boolean;
|
|
45
|
+
/** Explicit column names if CSV has no header. */
|
|
46
|
+
columns?: string[];
|
|
47
|
+
}
|
|
48
|
+
export interface ImportSummary {
|
|
49
|
+
tables: string[];
|
|
50
|
+
rowCounts: Record<string, number>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Robust RFC-4180 CSV parser supporting multiline fields and escaped quotes.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseCsv(text: string, delimiter?: string): string[][];
|
|
56
|
+
/**
|
|
57
|
+
* Exports SQLite tables to a structured JSON string.
|
|
58
|
+
*/
|
|
59
|
+
export declare function exportTablesToJson(client: LocalFirstClient, tables?: string[], options?: ExportJsonOptions): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Imports tables from a JSON export string into the database.
|
|
62
|
+
*/
|
|
63
|
+
export declare function importTablesFromJson(client: LocalFirstClient, jsonString: string, options?: ImportJsonOptions): Promise<ImportSummary>;
|
|
64
|
+
/**
|
|
65
|
+
* Exports a single SQLite table to an RFC-4180 CSV string.
|
|
66
|
+
*/
|
|
67
|
+
export declare function exportTableToCsv(client: LocalFirstClient, tableName: string, options?: ExportCsvOptions): Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Imports an RFC-4180 CSV string into a SQLite table.
|
|
70
|
+
*/
|
|
71
|
+
export declare function importTableFromCsv(client: LocalFirstClient, tableName: string, csvString: string, options?: ImportCsvOptions): Promise<{
|
|
72
|
+
rowCount: number;
|
|
73
|
+
}>;
|