local-lite 0.0.3 → 0.0.5

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.
Files changed (63) hide show
  1. package/README.md +421 -362
  2. package/dist/adapters/local/better-sqlite3.d.ts +2 -0
  3. package/dist/adapters/local/better-sqlite3.js +46 -25
  4. package/dist/adapters/local/expo-sqlite.d.ts +5 -1
  5. package/dist/adapters/local/expo-sqlite.js +40 -7
  6. package/dist/adapters/local/index.d.ts +1 -0
  7. package/dist/adapters/local/node-sqlite.d.ts +2 -0
  8. package/dist/adapters/local/node-sqlite.js +45 -22
  9. package/dist/adapters/local/op-sqlite.d.ts +1 -0
  10. package/dist/adapters/local/op-sqlite.js +6 -0
  11. package/dist/adapters/local/sql-js.d.ts +1 -0
  12. package/dist/adapters/local/sql-js.js +5 -0
  13. package/dist/adapters/network/index.js +33 -0
  14. package/dist/adapters/remote/convex.d.ts +2 -2
  15. package/dist/adapters/remote/convex.js +8 -12
  16. package/dist/adapters/remote/demo.d.ts +1 -1
  17. package/dist/adapters/remote/demo.js +3 -0
  18. package/dist/adapters/remote/firestore.d.ts +3 -2
  19. package/dist/adapters/remote/firestore.js +69 -46
  20. package/dist/adapters/remote/index.d.ts +6 -4
  21. package/dist/adapters/remote/supabase.d.ts +34 -6
  22. package/dist/adapters/remote/supabase.js +340 -79
  23. package/dist/config/index.js +7 -10
  24. package/dist/config/resolve-local.js +12 -1
  25. package/dist/config/resolve-remote.js +33 -28
  26. package/dist/config/types.d.ts +30 -5
  27. package/dist/core/client.d.ts +133 -5
  28. package/dist/core/client.js +431 -46
  29. package/dist/core/index.d.ts +15 -0
  30. package/dist/core/index.js +30 -0
  31. package/dist/core/outbox-store.d.ts +8 -4
  32. package/dist/core/outbox-store.js +84 -65
  33. package/dist/core/query-builder.d.ts +119 -0
  34. package/dist/core/query-builder.js +372 -0
  35. package/dist/core/query.d.ts +8 -0
  36. package/dist/core/query.js +37 -0
  37. package/dist/core/schema-manager.d.ts +9 -0
  38. package/dist/core/schema-manager.js +103 -0
  39. package/dist/core/sync-worker.d.ts +38 -1
  40. package/dist/core/sync-worker.js +351 -104
  41. package/dist/core/table-manager.js +26 -29
  42. package/dist/core/types.d.ts +8 -0
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.js +2 -0
  45. package/dist/react/BenchmarkModal.d.ts +32 -0
  46. package/dist/react/BenchmarkModal.js +777 -0
  47. package/dist/react/SyncInspector.d.ts +31 -0
  48. package/dist/react/SyncInspector.js +585 -0
  49. package/dist/react/index.d.ts +89 -18
  50. package/dist/react/index.js +450 -105
  51. package/dist/react/runner.d.ts +7 -0
  52. package/dist/react/runner.js +42 -0
  53. package/dist/react/status.d.ts +24 -0
  54. package/dist/react/status.js +123 -0
  55. package/dist/react/theme.d.ts +18 -0
  56. package/dist/react/theme.js +46 -0
  57. package/dist/schema/generator.d.ts +49 -0
  58. package/dist/schema/generator.js +209 -0
  59. package/dist/schema/index.d.ts +1 -0
  60. package/dist/schema/index.js +17 -0
  61. package/dist/utils/logger.d.ts +4 -0
  62. package/dist/utils/logger.js +20 -0
  63. package/package.json +143 -133
@@ -1,6 +1,10 @@
1
- import { LocalFirstClient } from '../core/client.js';
2
- import { QueryOptions, SyncMetrics } from '../core/types.js';
1
+ import { LocalFirstClient, TransactionalClient } from '../core/client.js';
2
+ import { BatchMutation, MutateOptions, QueryOptions } from '../core/types.js';
3
3
  export type LiveQueryFn<T> = (client: LocalFirstClient) => Promise<T[]> | T[];
4
+ /**
5
+ * Clears the in-memory live query cache.
6
+ */
7
+ export declare function clearLiveQueryCache(): void;
4
8
  /**
5
9
  * Hook to execute a live reactive table query that automatically re-runs
6
10
  * whenever the table is mutated locally or via incoming remote delta.
@@ -24,25 +28,92 @@ export declare function useLiveQuery<T = any>(client: LocalFirstClient | null |
24
28
  refetch: () => Promise<void>;
25
29
  loading: boolean;
26
30
  };
27
- export interface UseSyncStatusResult {
28
- isOnline: boolean;
29
- isPushing: boolean;
30
- isPulling: boolean;
31
- isSyncing: boolean;
32
- pendingCount: number;
33
- pendingRecords: any[];
34
- lastSyncedAt: number | null;
35
- refresh: () => Promise<void>;
31
+ export type MultiQuerySpec<T = any> = string | (QueryOptions & {
32
+ table?: string;
33
+ }) | LiveQueryFn<T>;
34
+ export type MultiQueryInput = Array<string | (QueryOptions & {
35
+ table: string;
36
+ })> | Record<string, MultiQuerySpec>;
37
+ export interface UseLiveQueriesResult<T extends Record<string, any[]>> {
38
+ data: T;
39
+ loading: boolean;
40
+ refetch: () => Promise<void>;
36
41
  }
37
42
  /**
38
- * Consolidated hook that tracks real-time sync connectivity, sync worker activity
39
- * (pushing/pulling/syncing), and pending items in the local SQLite outbox queue.
43
+ * Reactive multi-table live query hook that loads data from multiple tables concurrently.
44
+ *
45
+ * Benefits:
46
+ * - Parallel fetching: queries SQLite tables concurrently via Promise.all.
47
+ * - Single atomic React commit: coalesces multiple table results into a single state update,
48
+ * preventing cascading re-renders and UI freezing.
49
+ * - Multi-table event coordination: listens to mutations across all requested tables,
50
+ * coalescing updates so downstream calculations only run once.
51
+ * - Zero-latency cache read-through: returns instant cached rows on mount.
52
+ *
53
+ * Usage with dictionary:
54
+ * ```ts
55
+ * const { data, loading } = useLiveQueries(client, {
56
+ * projects: 'projects',
57
+ * tasks: { where: { project_id: '123' }, orderBy: 'created_at' },
58
+ * tags: { table: 'labels' }
59
+ * });
60
+ * // data.projects, data.tasks, data.tags
61
+ * ```
62
+ *
63
+ * Usage with array:
64
+ * ```ts
65
+ * const { data, loading } = useLiveQueries(client, ['projects', 'tasks', 'tags']);
66
+ * // data.projects, data.tasks, data.tags
67
+ * ```
40
68
  */
41
- export declare function useSyncStatus(client: LocalFirstClient | null | undefined): UseSyncStatusResult;
69
+ export declare function useLiveQueries<T extends Record<string, any[]> = Record<string, any[]>>(client: LocalFirstClient | null | undefined, queries: MultiQueryInput): UseLiveQueriesResult<T>;
42
70
  /**
43
- * Hook that provides real-time sync telemetry and engine performance metrics.
71
+ * Reactive hook to query a single record by primary key with 0ms cache read-through.
72
+ * Automatically re-renders only when this specific row or table changes.
44
73
  */
45
- export declare function useSyncMetrics(client: LocalFirstClient | null | undefined, pollIntervalMs?: number): {
46
- metrics: SyncMetrics | null;
47
- refresh: () => Promise<void>;
74
+ export declare function useLiveRow<T = any>(client: LocalFirstClient | null | undefined, tableName: string, rowId: string | null | undefined, options?: {
75
+ includeDeleted?: boolean;
76
+ }): {
77
+ data: T | null;
78
+ refetch: () => Promise<void>;
79
+ loading: boolean;
48
80
  };
81
+ export interface InfiniteQueryOptions extends QueryOptions {
82
+ pageSize?: number;
83
+ }
84
+ export interface UseLiveInfiniteQueryResult<T> {
85
+ data: T[];
86
+ loading: boolean;
87
+ isFetchingNextPage: boolean;
88
+ hasNextPage: boolean;
89
+ fetchNextPage: () => Promise<void>;
90
+ refetch: () => Promise<void>;
91
+ }
92
+ /**
93
+ * Reactive infinite query hook that progressively loads pages of records
94
+ * with live updates when underlying table rows are inserted, updated, or synced.
95
+ */
96
+ export declare function useLiveInfiniteQuery<T = any>(client: LocalFirstClient | null | undefined, tableName: string, options?: InfiniteQueryOptions): UseLiveInfiniteQueryResult<T>;
97
+ export interface UseMutationsResult<TTable extends string = string> {
98
+ client: LocalFirstClient | null | undefined;
99
+ insert: <T extends Record<string, any> = Record<string, any>>(tableName: TTable | (string & {}), payload: T, options?: MutateOptions) => Promise<string | undefined>;
100
+ insertMany: <T extends Record<string, any> = Record<string, any>>(tableName: TTable | (string & {}), records: T[], options?: MutateOptions) => Promise<string[] | undefined>;
101
+ update: <T extends Record<string, any> = Record<string, any>>(tableName: TTable | (string & {}), rowId: string, payload: Partial<T>, options?: MutateOptions) => Promise<void>;
102
+ updateMany: <T extends Record<string, any> = Record<string, any>>(tableName: TTable | (string & {}), updates: Array<{
103
+ id: string;
104
+ payload: Partial<T>;
105
+ }>, options?: MutateOptions) => Promise<void>;
106
+ delete: (tableName: TTable | (string & {}), rowId: string, options?: MutateOptions) => Promise<void>;
107
+ batch: (mutations: BatchMutation[]) => Promise<string[] | undefined>;
108
+ transaction: <T>(action: (txClient: TransactionalClient) => Promise<T>) => Promise<T | undefined>;
109
+ }
110
+ /**
111
+ * Universal mutations hook providing memoized, null-safe helpers for database operations.
112
+ */
113
+ export declare function useMutations<TTable extends string = string>(client: LocalFirstClient | null | undefined): UseMutationsResult<TTable>;
114
+ export * from './runner.js';
115
+ export * from './status.js';
116
+ export * from './theme.js';
117
+ export * from './BenchmarkModal.js';
118
+ export { SyncInspector, SyncIndicator } from './SyncInspector.js';
119
+ export type { SyncInspectorProps, SyncIndicatorProps } from './SyncInspector.js';