local-lite 2.0.6 → 3.0.0

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 (82) hide show
  1. package/README.md +0 -30
  2. package/dist/adapters/local/index.d.ts +1 -0
  3. package/dist/adapters/local/index.js +1 -0
  4. package/dist/adapters/local/sqlite-wasm.d.ts +25 -0
  5. package/dist/adapters/local/sqlite-wasm.js +55 -0
  6. package/dist/adapters/remote/convex.d.ts +1 -1
  7. package/dist/adapters/remote/convex.js +25 -3
  8. package/dist/adapters/remote/demo.d.ts +3 -3
  9. package/dist/adapters/remote/demo.js +11 -3
  10. package/dist/adapters/remote/firestore.d.ts +1 -1
  11. package/dist/adapters/remote/firestore.js +57 -91
  12. package/dist/adapters/remote/index.d.ts +2 -1
  13. package/dist/adapters/remote/index.js +1 -0
  14. package/dist/adapters/remote/postgres.d.ts +37 -0
  15. package/dist/adapters/remote/postgres.js +119 -0
  16. package/dist/adapters/remote/self-hosted.d.ts +12 -0
  17. package/dist/adapters/remote/self-hosted.js +55 -4
  18. package/dist/adapters/remote/supabase.d.ts +1 -1
  19. package/dist/adapters/remote/supabase.js +22 -5
  20. package/dist/auth/apple.js +0 -6
  21. package/dist/auth/github.js +0 -3
  22. package/dist/auth/google.js +0 -3
  23. package/dist/auth/identity.d.ts +0 -5
  24. package/dist/auth/identity.js +0 -3
  25. package/dist/auth/microsoft.js +0 -3
  26. package/dist/auth/unified.d.ts +5 -5
  27. package/dist/auth/unified.js +1 -1
  28. package/dist/config/index.d.ts +0 -12
  29. package/dist/config/index.js +3 -26
  30. package/dist/config/types.d.ts +3 -2
  31. package/dist/core/audit.d.ts +52 -0
  32. package/dist/core/audit.js +153 -0
  33. package/dist/core/client.d.ts +4 -0
  34. package/dist/core/client.js +7 -0
  35. package/dist/core/conflict.d.ts +24 -0
  36. package/dist/core/conflict.js +77 -0
  37. package/dist/core/field-encryption.d.ts +25 -0
  38. package/dist/core/field-encryption.js +128 -0
  39. package/dist/core/index.d.ts +2 -0
  40. package/dist/core/index.js +2 -0
  41. package/dist/core/query-builder.d.ts +51 -0
  42. package/dist/core/query-builder.js +278 -35
  43. package/dist/core/query.js +6 -1
  44. package/dist/core/types.d.ts +2 -1
  45. package/dist/devtools/BenchmarkModal.js +285 -1
  46. package/dist/email/index.d.ts +1 -1
  47. package/dist/email/index.js +2 -2
  48. package/dist/index.d.ts +2 -27
  49. package/dist/index.js +2 -27
  50. package/dist/presence/index.d.ts +45 -0
  51. package/dist/presence/index.js +142 -0
  52. package/dist/reactive/event-emitter.d.ts +10 -1
  53. package/dist/reactive/event-emitter.js +44 -1
  54. package/dist/reactive/live-query.d.ts +18 -0
  55. package/dist/reactive/live-query.js +71 -0
  56. package/dist/schema/index.d.ts +1 -0
  57. package/dist/schema/index.js +1 -0
  58. package/dist/schema/typed.d.ts +38 -0
  59. package/dist/schema/typed.js +33 -0
  60. package/dist/server/dashboard.d.ts +2 -0
  61. package/dist/server/dashboard.js +1272 -1044
  62. package/dist/solid/index.d.ts +24 -0
  63. package/dist/solid/index.js +35 -0
  64. package/dist/storage/firebase.d.ts +3 -3
  65. package/dist/storage/firebase.js +40 -94
  66. package/dist/svelte/index.d.ts +15 -0
  67. package/dist/svelte/index.js +27 -0
  68. package/dist/testing/index.d.ts +22 -0
  69. package/dist/testing/index.js +74 -0
  70. package/dist/vue/index.d.ts +27 -0
  71. package/dist/vue/index.js +37 -0
  72. package/package.json +46 -9
  73. package/dist/kv/index.d.ts +0 -3
  74. package/dist/kv/index.js +0 -19
  75. package/dist/kv/manager.d.ts +0 -52
  76. package/dist/kv/manager.js +0 -167
  77. package/dist/kv/store.d.ts +0 -13
  78. package/dist/kv/store.js +0 -85
  79. package/dist/kv/types.d.ts +0 -27
  80. package/dist/kv/types.js +0 -2
  81. package/dist/react/kv.d.ts +0 -9
  82. package/dist/react/kv.js +0 -53
@@ -0,0 +1,18 @@
1
+ import type { LocalFirstClient } from '../core/client.js';
2
+ import type { QueryOptions, SyncStatusEvent } from '../core/types.js';
3
+ export interface LiveQueryState<T> {
4
+ data: T[];
5
+ loading: boolean;
6
+ error: Error | null;
7
+ }
8
+ /**
9
+ * Framework-agnostic live query subscription helper shared by Svelte, Vue, and Solid bindings.
10
+ */
11
+ export declare function subscribeLiveQuery<T = any>(client: LocalFirstClient, tableName: string, options: QueryOptions | undefined, onUpdate: (state: LiveQueryState<T>) => void): {
12
+ refresh: () => Promise<void>;
13
+ dispose: () => void;
14
+ };
15
+ /**
16
+ * Framework-agnostic sync status subscription helper shared by Svelte, Vue, and Solid bindings.
17
+ */
18
+ export declare function subscribeSyncStatus(client: LocalFirstClient, onUpdate: (status: SyncStatusEvent) => void): () => void;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.subscribeLiveQuery = subscribeLiveQuery;
4
+ exports.subscribeSyncStatus = subscribeSyncStatus;
5
+ /**
6
+ * Framework-agnostic live query subscription helper shared by Svelte, Vue, and Solid bindings.
7
+ */
8
+ function subscribeLiveQuery(client, tableName, options, onUpdate) {
9
+ let active = true;
10
+ let current = { data: [], loading: true, error: null };
11
+ const refresh = async () => {
12
+ try {
13
+ const rows = await client
14
+ .from(tableName)
15
+ .applyOptions(options)
16
+ .execute();
17
+ if (!active)
18
+ return;
19
+ current = { data: rows, loading: false, error: null };
20
+ onUpdate(current);
21
+ }
22
+ catch (err) {
23
+ if (!active)
24
+ return;
25
+ current = {
26
+ ...current,
27
+ loading: false,
28
+ error: err instanceof Error ? err : new Error(String(err)),
29
+ };
30
+ onUpdate(current);
31
+ }
32
+ };
33
+ void refresh();
34
+ const unsubTable = client.events.on(tableName, () => {
35
+ void refresh();
36
+ });
37
+ const unsubReset = client.events.on('reset', () => {
38
+ void refresh();
39
+ });
40
+ return {
41
+ refresh,
42
+ dispose() {
43
+ active = false;
44
+ unsubTable();
45
+ unsubReset();
46
+ },
47
+ };
48
+ }
49
+ /**
50
+ * Framework-agnostic sync status subscription helper shared by Svelte, Vue, and Solid bindings.
51
+ */
52
+ function subscribeSyncStatus(client, onUpdate) {
53
+ onUpdate({
54
+ isOnline: true,
55
+ isPushing: false,
56
+ isPulling: false,
57
+ pendingCount: 0,
58
+ });
59
+ void client
60
+ .getMetrics()
61
+ .then((m) => onUpdate({
62
+ isOnline: m.isOnline,
63
+ isPushing: m.isPushing,
64
+ isPulling: m.isPulling,
65
+ pendingCount: m.outboxPendingCount,
66
+ }))
67
+ .catch(() => { });
68
+ return client.events.on('sync:status', (next) => {
69
+ onUpdate(next);
70
+ });
71
+ }
@@ -1 +1,2 @@
1
1
  export * from './generator.js';
2
+ export * from './typed.js';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./generator.js"), exports);
18
+ __exportStar(require("./typed.js"), exports);
@@ -0,0 +1,38 @@
1
+ import type { LocalFirstClient } from '../core/client.js';
2
+ import type { QueryOptions, WhereFilter } from '../core/types.js';
3
+ export type ColumnTypeTag = 'string' | 'number' | 'boolean' | 'json' | 'string?' | 'number?' | 'boolean?' | 'json?';
4
+ export type InferColumnType<T extends ColumnTypeTag> = T extends 'string' ? string : T extends 'number' ? number : T extends 'boolean' ? boolean : T extends 'json' ? Record<string, any> | any[] : T extends 'string?' ? string | null : T extends 'number?' ? number | null : T extends 'boolean?' ? boolean | null : T extends 'json?' ? Record<string, any> | any[] | null : unknown;
5
+ export type SchemaDefinition = Record<string, Record<string, ColumnTypeTag>>;
6
+ export type InferTableRow<TCols extends Record<string, ColumnTypeTag>> = {
7
+ [K in keyof TCols]: InferColumnType<TCols[K]>;
8
+ };
9
+ export type InferSchema<TSchema extends SchemaDefinition> = {
10
+ [T in keyof TSchema]: InferTableRow<TSchema[T]>;
11
+ };
12
+ /**
13
+ * Defines a declarative schema dictionary for compile-time TypeScript row inference.
14
+ */
15
+ export declare function defineTypedSchema<TSchema extends SchemaDefinition>(schema: TSchema): TSchema;
16
+ export interface TypedQueryBuilder<TRow extends Record<string, any>> {
17
+ select<K extends keyof TRow & string>(...columns: K[]): TypedQueryBuilder<Pick<TRow, K>>;
18
+ where(filter: Partial<Record<keyof TRow & string, any>> | WhereFilter): TypedQueryBuilder<TRow>;
19
+ orderBy(column: keyof TRow & string, direction?: 'asc' | 'desc' | 'ASC' | 'DESC'): TypedQueryBuilder<TRow>;
20
+ limit(count: number): TypedQueryBuilder<TRow>;
21
+ offset(count: number): TypedQueryBuilder<TRow>;
22
+ distinct(enabled?: boolean): TypedQueryBuilder<TRow>;
23
+ execute(): Promise<TRow[]>;
24
+ first(): Promise<TRow | null>;
25
+ count(): Promise<number>;
26
+ }
27
+ export interface TypedLocalFirstClient<TSchema extends SchemaDefinition> {
28
+ readonly raw: LocalFirstClient;
29
+ from<T extends keyof TSchema & string>(tableName: T): TypedQueryBuilder<InferTableRow<TSchema[T]>>;
30
+ findById<T extends keyof TSchema & string>(tableName: T, id: string, options?: Pick<QueryOptions, 'includeDeleted'>): Promise<InferTableRow<TSchema[T]> | null>;
31
+ insert<T extends keyof TSchema & string>(tableName: T, payload: Partial<InferTableRow<TSchema[T]>> & Record<string, any>): Promise<string>;
32
+ update<T extends keyof TSchema & string>(tableName: T, id: string, payload: Partial<InferTableRow<TSchema[T]>>): Promise<void>;
33
+ delete<T extends keyof TSchema & string>(tableName: T, id: string): Promise<void>;
34
+ }
35
+ /**
36
+ * Wraps a `LocalFirstClient` with strict TypeScript table and column inference derived from `defineTypedSchema()`.
37
+ */
38
+ export declare function createTypedClient<TSchema extends SchemaDefinition>(client: LocalFirstClient, _schema?: TSchema): TypedLocalFirstClient<TSchema>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineTypedSchema = defineTypedSchema;
4
+ exports.createTypedClient = createTypedClient;
5
+ /**
6
+ * Defines a declarative schema dictionary for compile-time TypeScript row inference.
7
+ */
8
+ function defineTypedSchema(schema) {
9
+ return schema;
10
+ }
11
+ /**
12
+ * Wraps a `LocalFirstClient` with strict TypeScript table and column inference derived from `defineTypedSchema()`.
13
+ */
14
+ function createTypedClient(client, _schema) {
15
+ return {
16
+ raw: client,
17
+ from(tableName) {
18
+ return client.from(tableName);
19
+ },
20
+ findById(tableName, id, options) {
21
+ return client.findById(tableName, id, options);
22
+ },
23
+ insert(tableName, payload) {
24
+ return client.insert(tableName, payload);
25
+ },
26
+ update(tableName, id, payload) {
27
+ return client.update(tableName, id, payload);
28
+ },
29
+ async delete(tableName, id) {
30
+ await client.delete(tableName, id);
31
+ },
32
+ };
33
+ }
@@ -6,6 +6,8 @@ export interface DashboardHandlerOptions {
6
6
  readOnly?: boolean;
7
7
  /** Optional bearer/query token required to access the dashboard and its APIs. */
8
8
  authToken?: string;
9
+ /** Require local-lite user login to access dashboard APIs. Defaults to true. */
10
+ requireAuth?: boolean;
9
11
  /** Base path if mounted under a sub-path (e.g. '/_dashboard'). Defaults to ''. */
10
12
  basePath?: string;
11
13
  }