local-lite 0.0.10 → 0.0.11
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/adapters/remote/demo.d.ts +10 -0
- package/dist/adapters/remote/demo.js +21 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +2 -1
- package/dist/config/resolve-local.js +5 -11
- package/dist/config/resolve-remote.d.ts +1 -1
- package/dist/config/resolve-remote.js +16 -19
- package/dist/config/types.d.ts +7 -0
- package/dist/core/sync-worker.js +1 -0
- package/dist/utils/dynamic.d.ts +6 -0
- package/dist/utils/dynamic.js +32 -0
- package/package.json +1 -1
|
@@ -19,3 +19,13 @@ export declare class MemoryDemoRemoteAdapter implements RemoteDBAdapter {
|
|
|
19
19
|
emitLiveChanges(changes: DeltaChanges): void;
|
|
20
20
|
clear(): void;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Built-in No-Op Remote Adapter for local-only / offline operation.
|
|
24
|
+
* Acknowledges all local outbox pushes with 0 latency, performs no remote pulls,
|
|
25
|
+
* and maintains zero cloud backend connections.
|
|
26
|
+
*/
|
|
27
|
+
export declare class NoopRemoteAdapter implements RemoteDBAdapter {
|
|
28
|
+
pushChanges(_operations: SyncOperation[]): Promise<boolean>;
|
|
29
|
+
fetchChanges(_sinceTimestamp: number): Promise<DeltaChanges>;
|
|
30
|
+
subscribeToLiveChanges(_callback: (changes: DeltaChanges) => void): () => void;
|
|
31
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MemoryDemoRemoteAdapter = void 0;
|
|
3
|
+
exports.NoopRemoteAdapter = exports.MemoryDemoRemoteAdapter = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Built-in In-Memory Demo Remote Adapter.
|
|
6
6
|
* Useful for prototyping, offline testing, and previewing without a live backend.
|
|
@@ -47,3 +47,23 @@ class MemoryDemoRemoteAdapter {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
exports.MemoryDemoRemoteAdapter = MemoryDemoRemoteAdapter;
|
|
50
|
+
/**
|
|
51
|
+
* Built-in No-Op Remote Adapter for local-only / offline operation.
|
|
52
|
+
* Acknowledges all local outbox pushes with 0 latency, performs no remote pulls,
|
|
53
|
+
* and maintains zero cloud backend connections.
|
|
54
|
+
*/
|
|
55
|
+
class NoopRemoteAdapter {
|
|
56
|
+
async pushChanges(_operations) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
async fetchChanges(_sinceTimestamp) {
|
|
60
|
+
return {
|
|
61
|
+
timestamp: Date.now(),
|
|
62
|
+
changes: [],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
subscribeToLiveChanges(_callback) {
|
|
66
|
+
return () => { };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.NoopRemoteAdapter = NoopRemoteAdapter;
|
package/dist/config/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { NodeSQLiteAdapter } from '../adapters/local/node-sqlite.js';
|
|
|
13
13
|
export { SupabaseRemoteAdapter } from '../adapters/remote/supabase.js';
|
|
14
14
|
export { ConvexRemoteAdapter } from '../adapters/remote/convex.js';
|
|
15
15
|
export { FirestoreRemoteAdapter } from '../adapters/remote/firestore.js';
|
|
16
|
-
export { MemoryDemoRemoteAdapter } from '../adapters/remote/demo.js';
|
|
16
|
+
export { MemoryDemoRemoteAdapter, NoopRemoteAdapter } from '../adapters/remote/demo.js';
|
|
17
17
|
/**
|
|
18
18
|
* Type-safe configuration helper function (similar to defineConfig in Vite/Tailwind).
|
|
19
19
|
*/
|
package/dist/config/index.js
CHANGED
|
@@ -14,7 +14,7 @@ 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.MemoryDemoRemoteAdapter = exports.FirestoreRemoteAdapter = exports.ConvexRemoteAdapter = exports.SupabaseRemoteAdapter = exports.NodeSQLiteAdapter = exports.SqlJsAdapter = exports.LibSQLAdapter = exports.BetterSQLite3Adapter = exports.OpSQLiteAdapter = exports.ExpoSQLiteAdapter = exports.LocalFirstClient = exports.resolveRemoteAdapter = exports.resolveLocalAdapter = void 0;
|
|
17
|
+
exports.NoopRemoteAdapter = exports.MemoryDemoRemoteAdapter = exports.FirestoreRemoteAdapter = exports.ConvexRemoteAdapter = exports.SupabaseRemoteAdapter = exports.NodeSQLiteAdapter = exports.SqlJsAdapter = exports.LibSQLAdapter = exports.BetterSQLite3Adapter = exports.OpSQLiteAdapter = exports.ExpoSQLiteAdapter = exports.LocalFirstClient = 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");
|
|
@@ -51,6 +51,7 @@ var firestore_js_1 = require("../adapters/remote/firestore.js");
|
|
|
51
51
|
Object.defineProperty(exports, "FirestoreRemoteAdapter", { enumerable: true, get: function () { return firestore_js_1.FirestoreRemoteAdapter; } });
|
|
52
52
|
var demo_js_1 = require("../adapters/remote/demo.js");
|
|
53
53
|
Object.defineProperty(exports, "MemoryDemoRemoteAdapter", { enumerable: true, get: function () { return demo_js_1.MemoryDemoRemoteAdapter; } });
|
|
54
|
+
Object.defineProperty(exports, "NoopRemoteAdapter", { enumerable: true, get: function () { return demo_js_1.NoopRemoteAdapter; } });
|
|
54
55
|
/**
|
|
55
56
|
* Type-safe configuration helper function (similar to defineConfig in Vite/Tailwind).
|
|
56
57
|
*/
|
|
@@ -7,6 +7,8 @@ const better_sqlite3_js_1 = require("../adapters/local/better-sqlite3.js");
|
|
|
7
7
|
const libsql_js_1 = require("../adapters/local/libsql.js");
|
|
8
8
|
const sql_js_js_1 = require("../adapters/local/sql-js.js");
|
|
9
9
|
const node_sqlite_js_1 = require("../adapters/local/node-sqlite.js");
|
|
10
|
+
const dynamic_js_1 = require("../utils/dynamic.js");
|
|
11
|
+
const EXPO_SQLITE_PKG = ['expo', 'sqlite'].join('-');
|
|
10
12
|
/**
|
|
11
13
|
* Resolves or instantiates the appropriate LocalDBAdapter based on the provided configuration.
|
|
12
14
|
* Auto-detects Expo SQLite, OP-SQLite, better-sqlite3, LibSQL, sql.js, and Node.js built-in sqlite.
|
|
@@ -51,19 +53,11 @@ async function resolveLocalAdapter(config) {
|
|
|
51
53
|
// 9. Auto-open by name using expo-sqlite if available
|
|
52
54
|
if (typeof rawDb === 'string' || config.databaseName) {
|
|
53
55
|
const dbName = typeof rawDb === 'string' ? rawDb : (config.databaseName ?? 'local_lite.db');
|
|
54
|
-
let expoSqlite;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
expoSqlite = require('expo-sqlite');
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
// ignore
|
|
56
|
+
let expoSqlite = (0, dynamic_js_1.safeDynamicRequire)(EXPO_SQLITE_PKG);
|
|
57
|
+
if (!expoSqlite) {
|
|
58
|
+
expoSqlite = await (0, dynamic_js_1.safeDynamicImport)(EXPO_SQLITE_PKG);
|
|
62
59
|
}
|
|
63
60
|
try {
|
|
64
|
-
if (!expoSqlite) {
|
|
65
|
-
expoSqlite = await import('expo-sqlite');
|
|
66
|
-
}
|
|
67
61
|
if (expoSqlite && typeof expoSqlite.openDatabaseAsync === 'function') {
|
|
68
62
|
const expoDb = await expoSqlite.openDatabaseAsync(dbName);
|
|
69
63
|
return new expo_sqlite_js_1.ExpoSQLiteAdapter(expoDb);
|
|
@@ -2,6 +2,6 @@ import { RemoteDBAdapter } from '../adapters/remote/index.js';
|
|
|
2
2
|
import { LocalLiteConfig } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Resolves or instantiates the appropriate RemoteDBAdapter based on the provided configuration.
|
|
5
|
-
* Supports Supabase, Convex, Firebase / Firestore, in-memory demo adapter, or custom adapters.
|
|
5
|
+
* Supports Supabase, Convex, Firebase / Firestore, in-memory demo adapter, local-only mode, or custom adapters.
|
|
6
6
|
*/
|
|
7
7
|
export declare function resolveRemoteAdapter(config: LocalLiteConfig): Promise<RemoteDBAdapter>;
|
|
@@ -5,9 +5,13 @@ const supabase_js_1 = require("../adapters/remote/supabase.js");
|
|
|
5
5
|
const convex_js_1 = require("../adapters/remote/convex.js");
|
|
6
6
|
const firestore_js_1 = require("../adapters/remote/firestore.js");
|
|
7
7
|
const demo_js_1 = require("../adapters/remote/demo.js");
|
|
8
|
+
const dynamic_js_1 = require("../utils/dynamic.js");
|
|
9
|
+
// Construct dynamically to prevent Metro, Webpack, and Rollup from treating
|
|
10
|
+
// optional peer dependencies as unconditional build-time dependencies.
|
|
11
|
+
const SUPABASE_PKG = ['@supabase', 'supabase-js'].join('/');
|
|
8
12
|
/**
|
|
9
13
|
* Resolves or instantiates the appropriate RemoteDBAdapter based on the provided configuration.
|
|
10
|
-
* Supports Supabase, Convex, Firebase / Firestore, in-memory demo adapter, or custom adapters.
|
|
14
|
+
* Supports Supabase, Convex, Firebase / Firestore, in-memory demo adapter, local-only mode, or custom adapters.
|
|
11
15
|
*/
|
|
12
16
|
async function resolveRemoteAdapter(config) {
|
|
13
17
|
// 1. Explicit custom remote adapter
|
|
@@ -53,34 +57,27 @@ async function resolveRemoteAdapter(config) {
|
|
|
53
57
|
}
|
|
54
58
|
// 5. Supabase with URL + anonKey (lazy dynamic import)
|
|
55
59
|
if (config.supabase?.url && config.supabase?.anonKey) {
|
|
56
|
-
let supabaseModule;
|
|
57
|
-
// In CommonJS / React Native Metro environments, synchronous require avoids async chunk split failure
|
|
58
|
-
try {
|
|
59
|
-
if (typeof require === 'function') {
|
|
60
|
-
supabaseModule = require('@supabase/supabase-js');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// ignore
|
|
65
|
-
}
|
|
60
|
+
let supabaseModule = (0, dynamic_js_1.safeDynamicRequire)(SUPABASE_PKG);
|
|
66
61
|
if (!supabaseModule && typeof globalThis?.supabase?.createClient === 'function') {
|
|
67
62
|
supabaseModule = globalThis.supabase;
|
|
68
63
|
}
|
|
69
64
|
if (!supabaseModule) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
throw new Error('To initialize Supabase from url and anonKey, please install @supabase/supabase-js or provide a pre-configured client to config.supabase.client');
|
|
75
|
-
}
|
|
65
|
+
supabaseModule = await (0, dynamic_js_1.safeDynamicImport)(SUPABASE_PKG);
|
|
66
|
+
}
|
|
67
|
+
if (!supabaseModule) {
|
|
68
|
+
throw new Error('To initialize Supabase from url and anonKey, please install @supabase/supabase-js or provide a pre-configured client to config.supabase.client');
|
|
76
69
|
}
|
|
77
70
|
const createClientFn = supabaseModule.createClient || supabaseModule.default?.createClient;
|
|
78
71
|
const supabaseClient = createClientFn(config.supabase.url, config.supabase.anonKey);
|
|
79
72
|
return new supabase_js_1.SupabaseRemoteAdapter(supabaseClient, getSupabaseOptions());
|
|
80
73
|
}
|
|
81
|
-
// 6.
|
|
74
|
+
// 6. Local-only standalone mode
|
|
75
|
+
if (config.localOnly === true) {
|
|
76
|
+
return new demo_js_1.NoopRemoteAdapter();
|
|
77
|
+
}
|
|
78
|
+
// 7. Explicitly selected demo backend only; never acknowledge writes into a temporary backend implicitly.
|
|
82
79
|
if (config.inMemoryRemote === true) {
|
|
83
80
|
return new demo_js_1.MemoryDemoRemoteAdapter(300);
|
|
84
81
|
}
|
|
85
|
-
throw new Error('No remote adapter configured. Please specify config.supabase, config.convex, config.firebase, or config.remote. For
|
|
82
|
+
throw new Error('No remote adapter configured. Please specify config.supabase, config.convex, config.firebase, or config.remote. For local-only use, set config.localOnly: true. For demos, set config.inMemoryRemote: true.');
|
|
86
83
|
}
|
package/dist/config/types.d.ts
CHANGED
|
@@ -120,6 +120,13 @@ export interface LocalLiteConfig {
|
|
|
120
120
|
* Default: false
|
|
121
121
|
*/
|
|
122
122
|
inMemoryRemote?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Run purely local-only without requiring any remote cloud backend.
|
|
125
|
+
* Disables cloud sync pushes and pulls while preserving all local SQLite features,
|
|
126
|
+
* schema management, outbox tracking, and transactions.
|
|
127
|
+
* Default: false
|
|
128
|
+
*/
|
|
129
|
+
localOnly?: boolean;
|
|
123
130
|
/**
|
|
124
131
|
* Conflict resolution strategy. Default: 'last-write-wins'
|
|
125
132
|
*/
|
package/dist/core/sync-worker.js
CHANGED
|
@@ -7,6 +7,7 @@ const outbox_store_js_1 = require("./outbox-store.js");
|
|
|
7
7
|
const meta_store_js_1 = require("./meta-store.js");
|
|
8
8
|
const table_manager_js_1 = require("./table-manager.js");
|
|
9
9
|
const logger_js_1 = require("../utils/logger.js");
|
|
10
|
+
const REACT_NATIVE_PKG = ['react', 'native'].join('-');
|
|
10
11
|
/** Maximum outbox records sent per push cycle. */
|
|
11
12
|
const PUSH_BATCH_SIZE = 50;
|
|
12
13
|
/** Maximum incoming delta changes applied in a single database transaction. */
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely loads an optional dependency at runtime without triggering
|
|
3
|
+
* ahead-of-time static analysis in bundlers like Metro, Webpack, or Rollup.
|
|
4
|
+
*/
|
|
5
|
+
export declare function safeDynamicRequire(pkgName: string): any;
|
|
6
|
+
export declare function safeDynamicImport(pkgName: string): Promise<any>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeDynamicRequire = safeDynamicRequire;
|
|
4
|
+
exports.safeDynamicImport = safeDynamicImport;
|
|
5
|
+
/**
|
|
6
|
+
* Safely loads an optional dependency at runtime without triggering
|
|
7
|
+
* ahead-of-time static analysis in bundlers like Metro, Webpack, or Rollup.
|
|
8
|
+
*/
|
|
9
|
+
function safeDynamicRequire(pkgName) {
|
|
10
|
+
try {
|
|
11
|
+
const req = typeof __non_webpack_require__ !== 'undefined'
|
|
12
|
+
? __non_webpack_require__
|
|
13
|
+
: typeof require === 'function'
|
|
14
|
+
? require
|
|
15
|
+
: undefined;
|
|
16
|
+
return req ? req(pkgName) : undefined;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function safeDynamicImport(pkgName) {
|
|
23
|
+
try {
|
|
24
|
+
// Metro's AST worker rejects `import(dynamicVariable)` with "Invalid call at line ...: import(...)".
|
|
25
|
+
// Evaluating via new Function bypasses the bundler AST parser entirely while working in Node/browser.
|
|
26
|
+
const dynamicImport = new Function('specifier', 'return import(specifier);');
|
|
27
|
+
return await dynamicImport(pkgName);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
package/package.json
CHANGED