mpb-localkit 1.4.16 → 1.4.18
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/dist/core/index.d.ts +470 -9
- package/dist/core/index.js +7 -1
- package/dist/core/index.js.map +1 -1
- package/dist/react/index.d.ts +344 -4
- package/dist/svelte/index.d.ts +365 -5
- package/dist/vue/index.d.ts +320 -2
- package/package.json +8 -4
package/dist/core/index.d.ts
CHANGED
|
@@ -1,21 +1,130 @@
|
|
|
1
|
-
import { ZodRawShape, ZodObject } from 'zod';
|
|
1
|
+
import { ZodRawShape, ZodObject, ZodTypeAny } from 'zod';
|
|
2
2
|
export { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
|
|
4
|
+
/** Metadata fields automatically added to every document */
|
|
5
|
+
interface Doc {
|
|
6
|
+
_id: string;
|
|
7
|
+
_collection: string;
|
|
8
|
+
_updatedAt: number;
|
|
9
|
+
_deleted: boolean;
|
|
10
|
+
_schemaVersion?: number;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** User document merged with metadata fields */
|
|
14
|
+
type WithMeta<T> = T & Doc;
|
|
15
|
+
interface CollectionOptions {
|
|
16
|
+
version?: number;
|
|
17
|
+
migrate?: (doc: Record<string, unknown>) => Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Descriptor produced by collection() — stores the Zod schema and collection name.
|
|
21
|
+
*
|
|
22
|
+
* TShape is the Zod raw shape; the inferred user-data type is CollectionDescriptor<TShape>['_inferredType'].
|
|
23
|
+
* The phantom `_inferredType` field drives downstream generic inference without a runtime value.
|
|
24
|
+
*/
|
|
25
|
+
interface CollectionDescriptor<TShape extends ZodRawShape = ZodRawShape> {
|
|
26
|
+
schema: ZodObject<TShape>;
|
|
27
|
+
collectionName: string;
|
|
28
|
+
version?: number;
|
|
29
|
+
migrate?: (doc: Record<string, unknown>) => Record<string, unknown>;
|
|
30
|
+
/** Phantom type — never set at runtime; carries z.infer<ZodObject<TShape>> for downstream generics */
|
|
31
|
+
readonly _inferredType: ZodObject<TShape>['_output'];
|
|
32
|
+
}
|
|
9
33
|
|
|
10
34
|
/**
|
|
11
35
|
* Wraps a Zod schema to create a typed collection descriptor.
|
|
12
36
|
* TypeScript infers the document type from the schema automatically.
|
|
13
37
|
*
|
|
38
|
+
* Compatible with both Zod v3 and Zod v4.
|
|
39
|
+
*
|
|
14
40
|
* @example
|
|
15
41
|
* const brews = collection(z.object({ style: z.string(), og: z.number() }))
|
|
16
42
|
* // brews._inferredType is { style: string; og: number }
|
|
17
43
|
*/
|
|
18
|
-
declare function collection<TShape extends ZodRawShape>(schema: ZodObject<TShape
|
|
44
|
+
declare function collection<TShape extends ZodRawShape>(schema: ZodObject<TShape> | ZodTypeAny, options?: CollectionOptions): CollectionDescriptor<TShape>;
|
|
45
|
+
|
|
46
|
+
interface QueryOptions<T> {
|
|
47
|
+
where?: WhereClause<T>;
|
|
48
|
+
sort?: Partial<Record<keyof T, 'asc' | 'desc'>>;
|
|
49
|
+
limit?: number;
|
|
50
|
+
offset?: number;
|
|
51
|
+
}
|
|
52
|
+
type WhereClause<T> = {
|
|
53
|
+
[K in keyof T]?: T[K] | {
|
|
54
|
+
$gt?: T[K];
|
|
55
|
+
$lt?: T[K];
|
|
56
|
+
$gte?: T[K];
|
|
57
|
+
$lte?: T[K];
|
|
58
|
+
$in?: T[K][];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** Key-value filter used by {@link StorageAdapter.getMany} to narrow results. */
|
|
63
|
+
type Filter = Record<string, unknown>;
|
|
64
|
+
/** Represents a single document change, used by sync to track modifications. */
|
|
65
|
+
interface Change {
|
|
66
|
+
/** Unique document identifier. */
|
|
67
|
+
id: string;
|
|
68
|
+
/** Name of the collection this change belongs to. */
|
|
69
|
+
collection: string;
|
|
70
|
+
/** The full document snapshot at the time of the change. */
|
|
71
|
+
doc: Doc;
|
|
72
|
+
/** Epoch timestamp (ms) when the document was last modified. */
|
|
73
|
+
updatedAt: number;
|
|
74
|
+
/** Whether this change represents a deletion. */
|
|
75
|
+
deleted: boolean;
|
|
76
|
+
}
|
|
77
|
+
interface StorageAdapter {
|
|
78
|
+
/**
|
|
79
|
+
* Retrieve a single document by ID.
|
|
80
|
+
* Returns `null` if the document is not found or has been soft-deleted.
|
|
81
|
+
*
|
|
82
|
+
* @param collection - The collection name.
|
|
83
|
+
* @param id - The document ID.
|
|
84
|
+
* @returns The document, or `null` if not found / deleted.
|
|
85
|
+
*/
|
|
86
|
+
get(collection: string, id: string): Promise<Doc | null>;
|
|
87
|
+
/**
|
|
88
|
+
* Return a document even if soft-deleted.
|
|
89
|
+
* Used by SyncEngine for conflict detection so it can compare local
|
|
90
|
+
* and remote versions of deleted documents.
|
|
91
|
+
*
|
|
92
|
+
* @param collection - The collection name.
|
|
93
|
+
* @param id - The document ID.
|
|
94
|
+
* @returns The document (including soft-deleted ones), or `null` if not found.
|
|
95
|
+
*/
|
|
96
|
+
getRaw?(collection: string, id: string): Promise<Doc | null>;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieve all non-deleted documents in a collection, optionally filtered.
|
|
99
|
+
*
|
|
100
|
+
* @param collection - The collection name.
|
|
101
|
+
* @param filter - Optional key-value filter to narrow results.
|
|
102
|
+
* @returns An array of matching documents.
|
|
103
|
+
*/
|
|
104
|
+
getMany(collection: string, filter?: Filter): Promise<Doc[]>;
|
|
105
|
+
/**
|
|
106
|
+
* Insert or update a document.
|
|
107
|
+
*
|
|
108
|
+
* @param collection - The collection name.
|
|
109
|
+
* @param id - The document ID.
|
|
110
|
+
* @param doc - The full document to store.
|
|
111
|
+
*/
|
|
112
|
+
put(collection: string, id: string, doc: Doc): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Soft-delete a document (sets `_deleted: true`).
|
|
115
|
+
*
|
|
116
|
+
* @param collection - The collection name.
|
|
117
|
+
* @param id - The document ID.
|
|
118
|
+
*/
|
|
119
|
+
delete(collection: string, id: string): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Return all documents modified after the given timestamp, for sync.
|
|
122
|
+
*
|
|
123
|
+
* @param timestamp - Epoch timestamp (ms). Only changes after this time are returned.
|
|
124
|
+
* @returns An array of changes since the given timestamp.
|
|
125
|
+
*/
|
|
126
|
+
getChangesSince(timestamp: number): Promise<Change[]>;
|
|
127
|
+
}
|
|
19
128
|
|
|
20
129
|
declare class IndexedDBAdapter implements StorageAdapter {
|
|
21
130
|
private dbName;
|
|
@@ -144,6 +253,120 @@ interface MigrationResult {
|
|
|
144
253
|
*/
|
|
145
254
|
declare function migrateToEncrypted(storage: StorageAdapter, encryptedStorage: EncryptedStorageAdapter): Promise<MigrationResult>;
|
|
146
255
|
|
|
256
|
+
type ConflictResolver = (local: Doc, remote: Doc) => Doc;
|
|
257
|
+
interface SyncTransport {
|
|
258
|
+
push(payload: PushPayload): Promise<number>;
|
|
259
|
+
pull(payload: PullPayload): Promise<Doc[]>;
|
|
260
|
+
setToken?(token: string | null): void;
|
|
261
|
+
destroy(): void;
|
|
262
|
+
}
|
|
263
|
+
type TransportType = 'http' | 'websocket' | 'auto';
|
|
264
|
+
interface SyncConfig {
|
|
265
|
+
endpoint: string;
|
|
266
|
+
interval: number;
|
|
267
|
+
enabled: boolean;
|
|
268
|
+
conflictResolver?: ConflictResolver;
|
|
269
|
+
transport?: SyncTransport | TransportType;
|
|
270
|
+
}
|
|
271
|
+
type SyncStatus = 'idle' | 'syncing' | 'error' | 'offline';
|
|
272
|
+
interface SyncResult {
|
|
273
|
+
pushed: number;
|
|
274
|
+
pulled: number;
|
|
275
|
+
conflicts: number;
|
|
276
|
+
error?: Error;
|
|
277
|
+
}
|
|
278
|
+
interface PushPayload {
|
|
279
|
+
changes: Change[];
|
|
280
|
+
lastSyncAt: number;
|
|
281
|
+
}
|
|
282
|
+
interface PullPayload {
|
|
283
|
+
since: number;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
interface SyncEventMap {
|
|
287
|
+
'sync:start': () => void;
|
|
288
|
+
'sync:complete': (result: SyncResult) => void;
|
|
289
|
+
'sync:error': (error: unknown) => void;
|
|
290
|
+
}
|
|
291
|
+
type SyncEventType = keyof SyncEventMap;
|
|
292
|
+
declare class SyncEngine {
|
|
293
|
+
private readonly storage;
|
|
294
|
+
private readonly config;
|
|
295
|
+
private status;
|
|
296
|
+
private lastSyncAt;
|
|
297
|
+
private lastSyncAtInitialized;
|
|
298
|
+
/** Typed listener map: values are SyncEventMap[E][] per event key. */
|
|
299
|
+
private readonly listenerMap;
|
|
300
|
+
private transport;
|
|
301
|
+
private readonly lastSyncKey;
|
|
302
|
+
constructor(storage: StorageAdapter, config: SyncConfig);
|
|
303
|
+
/**
|
|
304
|
+
* Return the current sync status.
|
|
305
|
+
*
|
|
306
|
+
* @returns The current {@link SyncStatus} (`'idle'`, `'syncing'`, `'error'`, or `'offline'`).
|
|
307
|
+
*/
|
|
308
|
+
getStatus(): SyncStatus;
|
|
309
|
+
/**
|
|
310
|
+
* Return the timestamp of the last successful sync.
|
|
311
|
+
*
|
|
312
|
+
* @returns Epoch timestamp (ms), or `0` if no sync has completed yet.
|
|
313
|
+
*/
|
|
314
|
+
getLastSyncAt(): number;
|
|
315
|
+
/**
|
|
316
|
+
* Set the bearer token used by the transport for authenticated requests.
|
|
317
|
+
*
|
|
318
|
+
* @param token - The bearer token string, or `null` to clear it.
|
|
319
|
+
*/
|
|
320
|
+
setToken(token: string | null): void;
|
|
321
|
+
/**
|
|
322
|
+
* Register a listener for sync events.
|
|
323
|
+
*
|
|
324
|
+
* @param event - The event type to listen for.
|
|
325
|
+
* @param listener - The callback to invoke when the event fires.
|
|
326
|
+
*/
|
|
327
|
+
on<E extends SyncEventType>(event: E, listener: SyncEventMap[E]): void;
|
|
328
|
+
/**
|
|
329
|
+
* Remove a previously registered sync event listener.
|
|
330
|
+
*
|
|
331
|
+
* @param event - The event type.
|
|
332
|
+
* @param listener - The callback to remove.
|
|
333
|
+
*/
|
|
334
|
+
off<E extends SyncEventType>(event: E, listener: SyncEventMap[E]): void;
|
|
335
|
+
/**
|
|
336
|
+
* Push local changes to the server.
|
|
337
|
+
*
|
|
338
|
+
* @returns The number of documents pushed.
|
|
339
|
+
*/
|
|
340
|
+
push(): Promise<number>;
|
|
341
|
+
/**
|
|
342
|
+
* Pull remote changes from the server. Applies conflict resolution for
|
|
343
|
+
* documents that exist both locally and remotely.
|
|
344
|
+
*
|
|
345
|
+
* @returns An object with `pulled` (total remote docs received) and `conflicts` (local-wins count).
|
|
346
|
+
*/
|
|
347
|
+
pull(): Promise<{
|
|
348
|
+
pulled: number;
|
|
349
|
+
conflicts: number;
|
|
350
|
+
}>;
|
|
351
|
+
/**
|
|
352
|
+
* Run a full push+pull sync cycle. Pushes local changes first, then pulls
|
|
353
|
+
* remote changes. Updates the last-sync timestamp on success.
|
|
354
|
+
*
|
|
355
|
+
* @returns A {@link SyncResult} with pushed, pulled, and conflicts counts.
|
|
356
|
+
*/
|
|
357
|
+
sync(): Promise<SyncResult>;
|
|
358
|
+
/**
|
|
359
|
+
* Clean up the transport (close WebSocket connections, etc.).
|
|
360
|
+
* Call this when the sync engine is no longer needed.
|
|
361
|
+
*/
|
|
362
|
+
destroy(): void;
|
|
363
|
+
private resolveTransport;
|
|
364
|
+
private setStatus;
|
|
365
|
+
private emit;
|
|
366
|
+
private loadLastSyncAt;
|
|
367
|
+
private saveLastSyncAt;
|
|
368
|
+
}
|
|
369
|
+
|
|
147
370
|
/**
|
|
148
371
|
* Last-Write-Wins conflict resolver.
|
|
149
372
|
* Compares _updatedAt timestamps; highest wins.
|
|
@@ -215,6 +438,35 @@ declare class AutoTransport implements SyncTransport {
|
|
|
215
438
|
destroy(): void;
|
|
216
439
|
}
|
|
217
440
|
|
|
441
|
+
interface User {
|
|
442
|
+
id: string;
|
|
443
|
+
email: string;
|
|
444
|
+
}
|
|
445
|
+
interface Credentials {
|
|
446
|
+
email: string;
|
|
447
|
+
password: string;
|
|
448
|
+
name?: string;
|
|
449
|
+
}
|
|
450
|
+
interface AuthAdapter {
|
|
451
|
+
signUp(credentials: Credentials): Promise<User>;
|
|
452
|
+
signIn(credentials: Credentials): Promise<User>;
|
|
453
|
+
signOut(): Promise<void>;
|
|
454
|
+
currentUser(): User | null;
|
|
455
|
+
getToken(): string | null;
|
|
456
|
+
/** Revalidate a cached session against the server. Returns null if invalid. */
|
|
457
|
+
revalidateSession?(): Promise<User | null>;
|
|
458
|
+
}
|
|
459
|
+
type SocialProvider = 'google' | 'github' | 'apple' | 'microsoft';
|
|
460
|
+
interface SocialAuthAdapter extends AuthAdapter {
|
|
461
|
+
signInWithSocial(provider: SocialProvider): Promise<User>;
|
|
462
|
+
}
|
|
463
|
+
interface OfflineSession {
|
|
464
|
+
user: User;
|
|
465
|
+
token: string;
|
|
466
|
+
expiresAt: number;
|
|
467
|
+
provider?: SocialProvider | 'email';
|
|
468
|
+
}
|
|
469
|
+
|
|
218
470
|
interface EmailPasswordAuthConfig {
|
|
219
471
|
endpoint: string;
|
|
220
472
|
}
|
|
@@ -344,6 +596,36 @@ declare class OfflineSessionAdapter implements AuthAdapter {
|
|
|
344
596
|
getToken(): string | null;
|
|
345
597
|
}
|
|
346
598
|
|
|
599
|
+
interface ErrorContext {
|
|
600
|
+
route?: string;
|
|
601
|
+
action?: string;
|
|
602
|
+
collection?: string;
|
|
603
|
+
online: boolean;
|
|
604
|
+
userAgent?: string;
|
|
605
|
+
}
|
|
606
|
+
interface ErrorSnapshot {
|
|
607
|
+
localStorageSize?: number;
|
|
608
|
+
pendingSyncCount?: number;
|
|
609
|
+
lastSyncAt?: number;
|
|
610
|
+
}
|
|
611
|
+
type ErrorType = 'unhandled_exception' | 'network_error' | 'sync_error' | 'validation_error' | 'runtime';
|
|
612
|
+
interface ErrorConfig {
|
|
613
|
+
enabled: boolean;
|
|
614
|
+
snapshot: boolean;
|
|
615
|
+
maxLocalErrors: number;
|
|
616
|
+
onError?: (error: ErrorEntry) => void;
|
|
617
|
+
webhookUrl?: string;
|
|
618
|
+
}
|
|
619
|
+
interface ErrorEntry extends Doc {
|
|
620
|
+
_collection: '_errors';
|
|
621
|
+
timestamp: number;
|
|
622
|
+
type: ErrorType;
|
|
623
|
+
message: string;
|
|
624
|
+
stack?: string;
|
|
625
|
+
context: ErrorContext;
|
|
626
|
+
snapshot?: ErrorSnapshot;
|
|
627
|
+
}
|
|
628
|
+
|
|
347
629
|
/**
|
|
348
630
|
* Low-level error tracker that persists errors to a StorageAdapter.
|
|
349
631
|
* Supports snapshot capture, webhook delivery with retry, and automatic pruning.
|
|
@@ -408,6 +690,168 @@ declare class ErrorManager {
|
|
|
408
690
|
getTracker(): ErrorTracker;
|
|
409
691
|
}
|
|
410
692
|
|
|
693
|
+
type AuthConfig = AuthAdapter | {
|
|
694
|
+
type: 'email-password';
|
|
695
|
+
endpoint: string;
|
|
696
|
+
} | {
|
|
697
|
+
type: 'better-auth';
|
|
698
|
+
/** Base URL of the Better Auth server (e.g. "https://api.example.com") */
|
|
699
|
+
baseURL: string;
|
|
700
|
+
};
|
|
701
|
+
interface SyncAPI {
|
|
702
|
+
push(): Promise<number>;
|
|
703
|
+
pull(): Promise<{
|
|
704
|
+
pulled: number;
|
|
705
|
+
conflicts: number;
|
|
706
|
+
}>;
|
|
707
|
+
start(): void;
|
|
708
|
+
stop(): void;
|
|
709
|
+
readonly status: SyncStatus;
|
|
710
|
+
}
|
|
711
|
+
interface ErrorTrackingConfig {
|
|
712
|
+
enabled?: boolean;
|
|
713
|
+
snapshot?: boolean;
|
|
714
|
+
maxLocalErrors?: number;
|
|
715
|
+
onError?: (error: ErrorEntry) => void;
|
|
716
|
+
}
|
|
717
|
+
interface AppConfig {
|
|
718
|
+
collections: Record<string, CollectionDescriptor<ZodRawShape>>;
|
|
719
|
+
sync?: Partial<SyncConfig>;
|
|
720
|
+
errorTracking?: ErrorTrackingConfig;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* A collection that supports reactive subscriptions.
|
|
725
|
+
* Compatible with React's `useSyncExternalStore` via `subscribe` + `getSnapshot`.
|
|
726
|
+
*/
|
|
727
|
+
interface ObservableCollection<T> extends Collection<T> {
|
|
728
|
+
/**
|
|
729
|
+
* Subscribe to collection changes. The listener is called whenever the
|
|
730
|
+
* in-memory snapshot is refreshed (after any mutation).
|
|
731
|
+
* Compatible with `useSyncExternalStore`.
|
|
732
|
+
*
|
|
733
|
+
* @param listener - Callback invoked on every snapshot change.
|
|
734
|
+
* @returns An unsubscribe function.
|
|
735
|
+
*/
|
|
736
|
+
subscribe(listener: () => void): () => void;
|
|
737
|
+
/**
|
|
738
|
+
* Get the current in-memory snapshot of all documents.
|
|
739
|
+
*
|
|
740
|
+
* @returns A read-only array of all non-deleted documents.
|
|
741
|
+
*/
|
|
742
|
+
getSnapshot(): ReadonlyArray<WithMeta<T>>;
|
|
743
|
+
}
|
|
744
|
+
interface Collection<T> {
|
|
745
|
+
/** The name of this collection. */
|
|
746
|
+
readonly name: string;
|
|
747
|
+
/**
|
|
748
|
+
* Create a new document, auto-generating `_id` and metadata fields
|
|
749
|
+
* (`_collection`, `_updatedAt`, `_deleted`).
|
|
750
|
+
*
|
|
751
|
+
* @param data - The user-defined fields for the document.
|
|
752
|
+
* @returns The created document with all metadata fields populated.
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* ```ts
|
|
756
|
+
* const todo = await todos.create({ title: 'Buy milk', done: false })
|
|
757
|
+
* console.log(todo._id) // auto-generated
|
|
758
|
+
* ```
|
|
759
|
+
*/
|
|
760
|
+
create(data: T): Promise<WithMeta<T>>;
|
|
761
|
+
/**
|
|
762
|
+
* Query documents with optional where, sort, limit, and offset filters.
|
|
763
|
+
*
|
|
764
|
+
* @param options - Optional query options (where, sort, limit, offset).
|
|
765
|
+
* @returns An array of matching documents.
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```ts
|
|
769
|
+
* const active = await todos.findMany({
|
|
770
|
+
* where: { done: { $eq: false } },
|
|
771
|
+
* sort: { field: 'title', direction: 'asc' },
|
|
772
|
+
* limit: 10,
|
|
773
|
+
* })
|
|
774
|
+
* ```
|
|
775
|
+
*/
|
|
776
|
+
findMany(options?: QueryOptions<T>): Promise<WithMeta<T>[]>;
|
|
777
|
+
/**
|
|
778
|
+
* Find a single document by ID. Returns `null` if not found.
|
|
779
|
+
*
|
|
780
|
+
* @param id - The document ID.
|
|
781
|
+
* @returns The document, or `null` if not found or deleted.
|
|
782
|
+
*/
|
|
783
|
+
findOne(id: string): Promise<WithMeta<T> | null>;
|
|
784
|
+
/**
|
|
785
|
+
* Partially update a document. Validates the merged result against the schema.
|
|
786
|
+
*
|
|
787
|
+
* @param id - The document ID.
|
|
788
|
+
* @param data - Partial fields to merge into the existing document.
|
|
789
|
+
* @returns The updated document.
|
|
790
|
+
* @throws If the document is not found or deleted.
|
|
791
|
+
*/
|
|
792
|
+
update(id: string, data: Partial<T>): Promise<WithMeta<T>>;
|
|
793
|
+
/**
|
|
794
|
+
* Soft-delete a document (sets `_deleted: true`).
|
|
795
|
+
*
|
|
796
|
+
* @param id - The document ID.
|
|
797
|
+
*/
|
|
798
|
+
delete(id: string): Promise<void>;
|
|
799
|
+
/**
|
|
800
|
+
* Count documents matching an optional query.
|
|
801
|
+
*
|
|
802
|
+
* @param options - Optional query options (where, sort, limit, offset).
|
|
803
|
+
* @returns The number of matching documents.
|
|
804
|
+
*/
|
|
805
|
+
count(options?: QueryOptions<T>): Promise<number>;
|
|
806
|
+
/**
|
|
807
|
+
* Check if a non-deleted document with the given ID exists.
|
|
808
|
+
*
|
|
809
|
+
* @param id - The document ID.
|
|
810
|
+
* @returns `true` if the document exists and is not deleted.
|
|
811
|
+
*/
|
|
812
|
+
exists(id: string): Promise<boolean>;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
interface AuthState {
|
|
816
|
+
user: User | null;
|
|
817
|
+
token: string | null;
|
|
818
|
+
isLoading: boolean;
|
|
819
|
+
}
|
|
820
|
+
interface SyncState {
|
|
821
|
+
status: SyncStatus;
|
|
822
|
+
lastSyncAt: number | null;
|
|
823
|
+
}
|
|
824
|
+
/** Observable auth wrapper — delegates to AuthAdapter and notifies React subscribers on state changes. */
|
|
825
|
+
declare class AuthStore implements AuthAdapter {
|
|
826
|
+
private readonly adapter;
|
|
827
|
+
private state;
|
|
828
|
+
private listeners;
|
|
829
|
+
constructor(adapter: AuthAdapter);
|
|
830
|
+
subscribe(listener: () => void): () => void;
|
|
831
|
+
getSnapshot(): AuthState;
|
|
832
|
+
private notify;
|
|
833
|
+
signUp(credentials: Credentials): Promise<User>;
|
|
834
|
+
signIn(credentials: Credentials): Promise<User>;
|
|
835
|
+
signOut(): Promise<void>;
|
|
836
|
+
currentUser(): User | null;
|
|
837
|
+
getToken(): string | null;
|
|
838
|
+
/**
|
|
839
|
+
* Revalidate a cached session against the server.
|
|
840
|
+
* Delegates to the inner adapter's `revalidateSession` if it supports it.
|
|
841
|
+
*
|
|
842
|
+
* @returns The revalidated user, or `null` if the session is invalid or the adapter does not support revalidation.
|
|
843
|
+
*/
|
|
844
|
+
revalidateSession(): Promise<User | null>;
|
|
845
|
+
}
|
|
846
|
+
/** Observable sync state — updated by the sync engine and read by useSync. */
|
|
847
|
+
declare class SyncStore {
|
|
848
|
+
private state;
|
|
849
|
+
private listeners;
|
|
850
|
+
subscribe(listener: () => void): () => void;
|
|
851
|
+
getSnapshot(): SyncState;
|
|
852
|
+
setStatus(status: SyncStatus, lastSyncAt?: number): void;
|
|
853
|
+
}
|
|
854
|
+
|
|
411
855
|
type ObservableInferredCollections<C extends Record<string, CollectionDescriptor<ZodRawShape>>> = {
|
|
412
856
|
[K in keyof C]: ObservableCollection<C[K]['_inferredType']>;
|
|
413
857
|
};
|
|
@@ -426,4 +870,21 @@ interface CreateAppConfig<C extends Record<string, CollectionDescriptor<ZodRawSh
|
|
|
426
870
|
}
|
|
427
871
|
declare function createApp<C extends Record<string, CollectionDescriptor<ZodRawShape>>>(config: CreateAppConfig<C>): App<C>;
|
|
428
872
|
|
|
429
|
-
|
|
873
|
+
/** Minimal QueryClient interface — avoids a hard dep on @tanstack/query-core */
|
|
874
|
+
interface MinimalQueryClient {
|
|
875
|
+
invalidateQueries(opts: {
|
|
876
|
+
queryKey: readonly unknown[];
|
|
877
|
+
}): Promise<void>;
|
|
878
|
+
}
|
|
879
|
+
declare const localkitKeys: {
|
|
880
|
+
all: readonly ["offlinekit"];
|
|
881
|
+
collection: (name: string) => readonly ["offlinekit", string];
|
|
882
|
+
collectionQuery: (name: string, opts: unknown) => readonly ["offlinekit", string, string];
|
|
883
|
+
};
|
|
884
|
+
declare function collectionQueryOptions<T>(collection: Collection<T>, queryOptions?: QueryOptions<T>): {
|
|
885
|
+
queryKey: readonly unknown[];
|
|
886
|
+
queryFn: () => Promise<WithMeta<T>[]>;
|
|
887
|
+
};
|
|
888
|
+
declare function subscribeToCollection<T>(collection: Collection<T>, queryClient: MinimalQueryClient): () => void;
|
|
889
|
+
|
|
890
|
+
export { type App, type AppConfig, type AuthAdapter, type AuthConfig, AutoTransport, type AutoTransportConfig, BetterAuthAdapter, type BetterAuthAdapterConfig, type BetterAuthClient, type Change, type Collection, type CollectionDescriptor, type CreateAppConfig, type Credentials, type Doc, EmailPasswordAuth, type EmailPasswordAuthConfig, EncryptedStorageAdapter, type EncryptionConfig, type ErrorContext, type ErrorEntry, type ErrorSnapshot, type ErrorTrackingConfig, type ErrorType, type Filter, HttpTransport, IndexedDBAdapter, type KeySpec, type KeychainConfig, MemoryAdapter, type MigrationResult, type OfflineSession, OfflineSessionAdapter, type PullPayload, type PushPayload, type QueryOptions, type ReEncryptResult, type SocialAuthAdapter, type SocialProvider, type StorageAdapter, type SyncConfig, SyncEngine, type SyncResult, type SyncStatus, type SyncTransport, type TransportType, type User, WebSocketTransport, type WebSocketTransportConfig, type WhereClause, type WithMeta, type WrapConfig, collection, collectionQueryOptions, createApp, encrypted, generateId, hashPassword, localkitKeys, migrateToEncrypted, reEncryptAll, resolveConflict, rewrapKey, setupFocusTrigger, setupIntervalTrigger, setupReconnectTrigger, subscribeToCollection };
|
package/dist/core/index.js
CHANGED
|
@@ -1184,7 +1184,13 @@ var BetterAuthAdapter = class {
|
|
|
1184
1184
|
return this.session?.user ?? null;
|
|
1185
1185
|
}
|
|
1186
1186
|
getToken() {
|
|
1187
|
-
|
|
1187
|
+
const token = this.session?.token ?? null;
|
|
1188
|
+
if (!token && this.session?.user) {
|
|
1189
|
+
console.warn(
|
|
1190
|
+
"[mpb-localkit] BetterAuthAdapter.getToken() returned null. Ensure the bearer plugin is enabled on your Better Auth server."
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
return token;
|
|
1188
1194
|
}
|
|
1189
1195
|
};
|
|
1190
1196
|
|