local-lite 0.1.1 → 0.1.2

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.
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultNetworkStatusProvider = void 0;
4
+ const dynamic_js_1 = require("../../utils/dynamic.js");
5
+ const NETINFO_PKG = ['@react-native-community', 'netinfo'].join('/');
4
6
  class DefaultNetworkStatusProvider {
5
7
  _isOnline = true;
6
8
  listeners = new Set();
@@ -9,7 +11,7 @@ class DefaultNetworkStatusProvider {
9
11
  this._isOnline = initialOnline;
10
12
  // 1. Try React Native NetInfo if available in environment
11
13
  try {
12
- const NetInfo = require('@react-native-community/netinfo');
14
+ const NetInfo = (0, dynamic_js_1.safeDynamicRequire)(NETINFO_PKG);
13
15
  const netInfoInstance = NetInfo?.default || NetInfo;
14
16
  if (netInfoInstance && typeof netInfoInstance.addEventListener === 'function') {
15
17
  netInfoInstance
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createFirebaseStorageUploader = exports.FirestoreAdapter = exports.FirestoreRemoteAdapter = void 0;
4
+ const dynamic_js_1 = require("../../utils/dynamic.js");
4
5
  const logger_js_1 = require("../../utils/logger.js");
5
6
  const firebase_js_1 = require("../../storage/firebase.js");
6
7
  Object.defineProperty(exports, "createFirebaseStorageUploader", { enumerable: true, get: function () { return firebase_js_1.createFirebaseStorageUploader; } });
@@ -68,8 +69,9 @@ class FirestoreRemoteAdapter {
68
69
  return this.firestoreModule;
69
70
  }
70
71
  try {
71
- const dynamicImport = new Function('moduleName', 'return import(moduleName)');
72
- this.firestoreModule = await dynamicImport('firebase/firestore');
72
+ const FIRESTORE_PKG = ['firebase', 'firestore'].join('/');
73
+ this.firestoreModule =
74
+ (0, dynamic_js_1.safeDynamicRequire)(FIRESTORE_PKG) ?? (await (0, dynamic_js_1.safeDynamicImport)(FIRESTORE_PKG));
73
75
  return this.firestoreModule;
74
76
  }
75
77
  catch {
@@ -50,10 +50,20 @@ class TableManager {
50
50
  const keys = Object.keys(rowData);
51
51
  if (keys.length === 0)
52
52
  return;
53
- // Use atomic SQLite UPSERT (INSERT ... ON CONFLICT DO UPDATE) for both INSERT and UPDATE.
54
- // Handles missing rows, existing rows, and partial updates in a single SQL round-trip,
55
- // completely eliminating the redundant SELECT 1 pre-check on every mutation!
53
+ // Use atomic SQLite UPSERT (INSERT ... ON CONFLICT DO UPDATE) for INSERT,
54
+ // and direct UPDATE when updating an existing row so omitted NOT NULL columns do not fail.
56
55
  const updateKeys = keys.filter((k) => k !== primaryKey);
56
+ if (operation === 'UPDATE' && updateKeys.length > 0) {
57
+ const existing = await TableManager.fetchRow(tx, tableName, rowId, primaryKey, options);
58
+ if (existing) {
59
+ const setClause = updateKeys
60
+ .map((k) => `${(0, sql_js_1.escapeIdentifier)(k)} = ?`)
61
+ .join(', ');
62
+ const setValues = [...updateKeys.map((k) => rowData[k]), rowId];
63
+ await tx.execute(`UPDATE ${safeTable} SET ${setClause} WHERE ${safePk} = ?`, setValues);
64
+ return;
65
+ }
66
+ }
57
67
  const cols = keys.map((k) => (0, sql_js_1.escapeIdentifier)(k)).join(', ');
58
68
  const placeholders = keys.map(() => '?').join(', ');
59
69
  const values = keys.map((k) => rowData[k]);
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeFileDriver = exports.MemoryFileDriver = void 0;
4
+ const dynamic_js_1 = require("../utils/dynamic.js");
5
+ const NODE_FS_PROMISES_PKG = ['node:fs', 'promises'].join('/');
6
+ const NODE_PATH_PKG = ['node', 'path'].join(':');
4
7
  /**
5
8
  * Universal in-memory driver (ideal for tests, memory caches, and browser storage fallback).
6
9
  */
@@ -35,8 +38,12 @@ class NodeFileDriver {
35
38
  }
36
39
  async getFs() {
37
40
  try {
38
- const fs = await import('node:fs/promises');
39
- const path = await import('node:path');
41
+ const fs = (0, dynamic_js_1.safeDynamicRequire)(NODE_FS_PROMISES_PKG) ??
42
+ (await (0, dynamic_js_1.safeDynamicImport)(NODE_FS_PROMISES_PKG));
43
+ const path = (0, dynamic_js_1.safeDynamicRequire)(NODE_PATH_PKG) ?? (await (0, dynamic_js_1.safeDynamicImport)(NODE_PATH_PKG));
44
+ if (!fs || !path) {
45
+ throw new Error('Node fs/path unavailable');
46
+ }
40
47
  return { fs, path };
41
48
  }
42
49
  catch {
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExpoFileDriver = void 0;
4
4
  exports.bytesToBase64 = bytesToBase64;
5
5
  exports.base64ToBytes = base64ToBytes;
6
+ const dynamic_js_1 = require("../utils/dynamic.js");
7
+ const EXPO_FILE_SYSTEM_PKG = ['expo', 'file', 'system'].join('-');
6
8
  /**
7
9
  * Universal binary <-> base64 utilities compatible with Node, Browser, and React Native (Hermes).
8
10
  */
@@ -54,11 +56,13 @@ class ExpoFileDriver {
54
56
  async resolveClasses() {
55
57
  if (!this.FileClass || !this.DirectoryClass || !this.PathsObj) {
56
58
  try {
57
- // @ts-ignore
58
- const mod = await import('expo-file-system');
59
- this.FileClass = this.FileClass ?? mod.File;
60
- this.DirectoryClass = this.DirectoryClass ?? mod.Directory;
61
- this.PathsObj = this.PathsObj ?? mod.Paths;
59
+ const mod = (0, dynamic_js_1.safeDynamicRequire)(EXPO_FILE_SYSTEM_PKG) ??
60
+ (await (0, dynamic_js_1.safeDynamicImport)(EXPO_FILE_SYSTEM_PKG));
61
+ if (mod) {
62
+ this.FileClass = this.FileClass ?? mod.File;
63
+ this.DirectoryClass = this.DirectoryClass ?? mod.Directory;
64
+ this.PathsObj = this.PathsObj ?? mod.Paths;
65
+ }
62
66
  }
63
67
  catch (error) {
64
68
  if (!this.FileClass) {
@@ -8,6 +8,23 @@ exports.safeDynamicImport = safeDynamicImport;
8
8
  */
9
9
  function safeDynamicRequire(pkgName) {
10
10
  try {
11
+ if (pkgName === 'react-native') {
12
+ return require('react-native');
13
+ }
14
+ if (pkgName === 'expo-sqlite') {
15
+ return require('expo-sqlite');
16
+ }
17
+ if (pkgName === 'expo-file-system') {
18
+ return require('expo-file-system');
19
+ }
20
+ if (pkgName === '@react-native-community/netinfo') {
21
+ return require('@react-native-community/netinfo');
22
+ }
23
+ // In Metro bundler (__r), calling require(variableString) triggers Metro's
24
+ // unknownModuleError console.error before throwing. Skip non-literal require in Metro.
25
+ if (typeof globalThis !== 'undefined' && typeof globalThis.__r === 'function') {
26
+ return undefined;
27
+ }
11
28
  const req = typeof __non_webpack_require__ !== 'undefined'
12
29
  ? __non_webpack_require__
13
30
  : typeof require === 'function'
@@ -21,6 +38,13 @@ function safeDynamicRequire(pkgName) {
21
38
  }
22
39
  async function safeDynamicImport(pkgName) {
23
40
  try {
41
+ const syncMod = safeDynamicRequire(pkgName);
42
+ if (syncMod !== undefined) {
43
+ return syncMod;
44
+ }
45
+ if (typeof globalThis !== 'undefined' && typeof globalThis.__r === 'function') {
46
+ return undefined;
47
+ }
24
48
  // Metro's AST worker rejects `import(dynamicVariable)` with "Invalid call at line ...: import(...)".
25
49
  // Evaluating via new Function bypasses the bundler AST parser entirely while working in Node/browser.
26
50
  const dynamicImport = new Function('specifier', 'return import(specifier);');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "local-lite",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Never let a lost connection break a promise. Local-first sync that faithfully keeps data safe until you're back online.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",