@webority-technologies/mobile-core 0.0.1 → 0.0.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.
Files changed (146) hide show
  1. package/README.md +22 -1
  2. package/lib/commonjs/api/baseUrl.js +34 -0
  3. package/lib/commonjs/api/curl.js +109 -0
  4. package/lib/commonjs/api/publicClient.js +11 -20
  5. package/lib/commonjs/api/retry.js +75 -0
  6. package/lib/commonjs/api/userClient.js +46 -22
  7. package/lib/commonjs/auth/authStore.js +101 -33
  8. package/lib/commonjs/auth/jwt.js +32 -8
  9. package/lib/commonjs/config/index.js +2 -1
  10. package/lib/commonjs/deepLink/index.js +286 -0
  11. package/lib/commonjs/download/adapters/expoFs.js +100 -0
  12. package/lib/commonjs/download/adapters/shared.js +13 -0
  13. package/lib/commonjs/download/index.js +272 -0
  14. package/lib/commonjs/formatters/date.js +1 -1
  15. package/lib/commonjs/formatters/index.js +6 -0
  16. package/lib/commonjs/formatters/phone.js +103 -15
  17. package/lib/commonjs/geolocation/adapters/expoLocation.js +126 -0
  18. package/lib/commonjs/geolocation/index.js +339 -0
  19. package/lib/commonjs/index.js +133 -48
  20. package/lib/commonjs/initSDK.js +23 -2
  21. package/lib/commonjs/initUserAuth.js +2 -1
  22. package/lib/commonjs/logger/index.js +159 -5
  23. package/lib/commonjs/network/index.js +6 -0
  24. package/lib/commonjs/network/networkStatus.js +50 -15
  25. package/lib/commonjs/permissions/index.js +24 -1
  26. package/lib/commonjs/sqlite/adapters/expo.js +53 -0
  27. package/lib/commonjs/sqlite/adapters/op.js +43 -0
  28. package/lib/commonjs/sqlite/adapters/rows.js +33 -0
  29. package/lib/commonjs/sqlite/adapters/storage.js +50 -0
  30. package/lib/commonjs/sqlite/adapters/sync.js +45 -0
  31. package/lib/commonjs/sqlite/index.js +610 -0
  32. package/lib/commonjs/sqlite/nitro.js +17 -0
  33. package/lib/commonjs/sqlite/op.js +18 -0
  34. package/lib/commonjs/sqlite/quick.js +14 -0
  35. package/lib/commonjs/sqlite/storage.js +14 -0
  36. package/lib/commonjs/storage/index.js +40 -19
  37. package/lib/commonjs/types/globals.d.js +6 -0
  38. package/lib/commonjs/utils/imageCompression.js +51 -14
  39. package/lib/commonjs/utils/index.js +6 -0
  40. package/lib/commonjs/versionCheck/index.js +28 -4
  41. package/lib/module/api/baseUrl.js +30 -0
  42. package/lib/module/api/curl.js +104 -0
  43. package/lib/module/api/publicClient.js +11 -20
  44. package/lib/module/api/retry.js +69 -0
  45. package/lib/module/api/userClient.js +45 -21
  46. package/lib/module/auth/authStore.js +99 -32
  47. package/lib/module/auth/jwt.js +32 -8
  48. package/lib/module/config/index.js +2 -1
  49. package/lib/module/deepLink/index.js +280 -0
  50. package/lib/module/download/adapters/expoFs.js +95 -0
  51. package/lib/module/download/adapters/shared.js +8 -0
  52. package/lib/module/download/index.js +264 -0
  53. package/lib/module/formatters/date.js +1 -1
  54. package/lib/module/formatters/index.js +1 -1
  55. package/lib/module/formatters/phone.js +99 -13
  56. package/lib/module/geolocation/adapters/expoLocation.js +121 -0
  57. package/lib/module/geolocation/index.js +332 -0
  58. package/lib/module/index.js +28 -11
  59. package/lib/module/initSDK.js +23 -2
  60. package/lib/module/initUserAuth.js +2 -1
  61. package/lib/module/logger/index.js +156 -4
  62. package/lib/module/network/index.js +1 -1
  63. package/lib/module/network/networkStatus.js +47 -14
  64. package/lib/module/permissions/index.js +22 -0
  65. package/lib/module/sqlite/adapters/expo.js +48 -0
  66. package/lib/module/sqlite/adapters/op.js +38 -0
  67. package/lib/module/sqlite/adapters/rows.js +28 -0
  68. package/lib/module/sqlite/adapters/storage.js +46 -0
  69. package/lib/module/sqlite/adapters/sync.js +41 -0
  70. package/lib/module/sqlite/index.js +600 -0
  71. package/lib/module/sqlite/nitro.js +12 -0
  72. package/lib/module/sqlite/op.js +13 -0
  73. package/lib/module/sqlite/quick.js +9 -0
  74. package/lib/module/sqlite/storage.js +9 -0
  75. package/lib/module/storage/index.js +37 -18
  76. package/lib/module/types/globals.d.js +10 -0
  77. package/lib/module/utils/imageCompression.js +49 -13
  78. package/lib/module/utils/index.js +1 -1
  79. package/lib/module/versionCheck/index.js +27 -4
  80. package/lib/typescript/commonjs/api/baseUrl.d.ts +20 -0
  81. package/lib/typescript/commonjs/api/curl.d.ts +18 -0
  82. package/lib/typescript/commonjs/api/retry.d.ts +27 -0
  83. package/lib/typescript/commonjs/api/userClient.d.ts +11 -0
  84. package/lib/typescript/commonjs/auth/authStore.d.ts +29 -6
  85. package/lib/typescript/commonjs/config/index.d.ts +6 -0
  86. package/lib/typescript/commonjs/deepLink/index.d.ts +54 -0
  87. package/lib/typescript/commonjs/download/adapters/expoFs.d.ts +45 -0
  88. package/lib/typescript/commonjs/download/adapters/shared.d.ts +3 -0
  89. package/lib/typescript/commonjs/download/index.d.ts +76 -0
  90. package/lib/typescript/commonjs/formatters/index.d.ts +2 -1
  91. package/lib/typescript/commonjs/formatters/phone.d.ts +16 -1
  92. package/lib/typescript/commonjs/geolocation/adapters/expoLocation.d.ts +42 -0
  93. package/lib/typescript/commonjs/geolocation/index.d.ts +89 -0
  94. package/lib/typescript/commonjs/index.d.ts +30 -13
  95. package/lib/typescript/commonjs/initSDK.d.ts +32 -0
  96. package/lib/typescript/commonjs/logger/index.d.ts +39 -0
  97. package/lib/typescript/commonjs/network/index.d.ts +2 -2
  98. package/lib/typescript/commonjs/network/networkStatus.d.ts +16 -0
  99. package/lib/typescript/commonjs/permissions/index.d.ts +35 -0
  100. package/lib/typescript/commonjs/sqlite/adapters/expo.d.ts +30 -0
  101. package/lib/typescript/commonjs/sqlite/adapters/op.d.ts +27 -0
  102. package/lib/typescript/commonjs/sqlite/adapters/rows.d.ts +7 -0
  103. package/lib/typescript/commonjs/sqlite/adapters/storage.d.ts +30 -0
  104. package/lib/typescript/commonjs/sqlite/adapters/sync.d.ts +31 -0
  105. package/lib/typescript/commonjs/sqlite/index.d.ts +121 -0
  106. package/lib/typescript/commonjs/sqlite/nitro.d.ts +7 -0
  107. package/lib/typescript/commonjs/sqlite/op.d.ts +8 -0
  108. package/lib/typescript/commonjs/sqlite/quick.d.ts +4 -0
  109. package/lib/typescript/commonjs/sqlite/storage.d.ts +4 -0
  110. package/lib/typescript/commonjs/storage/index.d.ts +24 -2
  111. package/lib/typescript/commonjs/utils/imageCompression.d.ts +17 -0
  112. package/lib/typescript/commonjs/utils/index.d.ts +2 -2
  113. package/lib/typescript/module/api/baseUrl.d.ts +20 -0
  114. package/lib/typescript/module/api/curl.d.ts +18 -0
  115. package/lib/typescript/module/api/retry.d.ts +27 -0
  116. package/lib/typescript/module/api/userClient.d.ts +11 -0
  117. package/lib/typescript/module/auth/authStore.d.ts +29 -6
  118. package/lib/typescript/module/config/index.d.ts +6 -0
  119. package/lib/typescript/module/deepLink/index.d.ts +54 -0
  120. package/lib/typescript/module/download/adapters/expoFs.d.ts +45 -0
  121. package/lib/typescript/module/download/adapters/shared.d.ts +3 -0
  122. package/lib/typescript/module/download/index.d.ts +76 -0
  123. package/lib/typescript/module/formatters/index.d.ts +2 -1
  124. package/lib/typescript/module/formatters/phone.d.ts +16 -1
  125. package/lib/typescript/module/geolocation/adapters/expoLocation.d.ts +42 -0
  126. package/lib/typescript/module/geolocation/index.d.ts +89 -0
  127. package/lib/typescript/module/index.d.ts +30 -13
  128. package/lib/typescript/module/initSDK.d.ts +32 -0
  129. package/lib/typescript/module/logger/index.d.ts +39 -0
  130. package/lib/typescript/module/network/index.d.ts +2 -2
  131. package/lib/typescript/module/network/networkStatus.d.ts +16 -0
  132. package/lib/typescript/module/permissions/index.d.ts +35 -0
  133. package/lib/typescript/module/sqlite/adapters/expo.d.ts +30 -0
  134. package/lib/typescript/module/sqlite/adapters/op.d.ts +27 -0
  135. package/lib/typescript/module/sqlite/adapters/rows.d.ts +7 -0
  136. package/lib/typescript/module/sqlite/adapters/storage.d.ts +30 -0
  137. package/lib/typescript/module/sqlite/adapters/sync.d.ts +31 -0
  138. package/lib/typescript/module/sqlite/index.d.ts +121 -0
  139. package/lib/typescript/module/sqlite/nitro.d.ts +7 -0
  140. package/lib/typescript/module/sqlite/op.d.ts +8 -0
  141. package/lib/typescript/module/sqlite/quick.d.ts +4 -0
  142. package/lib/typescript/module/sqlite/storage.d.ts +4 -0
  143. package/lib/typescript/module/storage/index.d.ts +24 -2
  144. package/lib/typescript/module/utils/imageCompression.d.ts +17 -0
  145. package/lib/typescript/module/utils/index.d.ts +2 -2
  146. package/package.json +102 -14
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "getNetworkStatus", {
15
15
  return _networkStatus.getNetworkStatus;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "setNetworkStatusImplementation", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _networkStatus.setNetworkStatusImplementation;
22
+ }
23
+ });
18
24
  Object.defineProperty(exports, "useNetworkStatus", {
19
25
  enumerable: true,
20
26
  get: function () {
@@ -3,29 +3,64 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useNetworkStatus = exports.getNetworkStatus = exports.addNetworkStatusListener = void 0;
6
+ exports.useNetworkStatus = exports.setNetworkStatusImplementation = exports.getNetworkStatus = exports.addNetworkStatusListener = void 0;
7
+ var ExpoNetwork = _interopRequireWildcard(require("expo-network"));
7
8
  var _react = require("react");
8
9
  var _index = require("../logger/index.js");
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
9
11
  const DEFAULT_STATUS = {
10
12
  isConnected: true,
11
13
  isInternetReachable: null,
12
14
  type: 'unknown'
13
15
  };
14
- let netInfo = null;
15
- let resolved = false;
16
- const resolveNetInfo = () => {
17
- if (resolved) {
18
- return netInfo;
19
- }
20
- resolved = true;
21
- try {
22
- const mod = require('@react-native-community/netinfo');
23
- netInfo = mod.default ?? mod;
24
- } catch {
25
- _index.Logger.warn('[network] @react-native-community/netinfo is not installed; ' + 'useNetworkStatus() will report a default "online" status.');
26
- netInfo = null;
16
+ /**
17
+ * expo-network is imported directly, not resolved through a seam.
18
+ *
19
+ * `expo` is a REQUIRED peer of this package, so every consumer has the Expo
20
+ * modules by construction and the static-require problem that forced the old
21
+ * injection design does not arise. An app wires nothing: connectivity works
22
+ * because the library uses Expo, which is the point of the Expo-first policy.
23
+ * One backend also means one behaviour, rather than each app choosing.
24
+ */
25
+ let override = null;
26
+
27
+ /**
28
+ * Replace the backend. Intended for TESTS and for the showcase, which uses it
29
+ * to reach error paths that a healthy device never takes; it is not the way an
30
+ * app is meant to configure the library. Pass `null` to restore expo-network.
31
+ */
32
+ const setNetworkStatusImplementation = impl => {
33
+ override = impl;
34
+ };
35
+ exports.setNetworkStatusImplementation = setNetworkStatusImplementation;
36
+ const resolveNetInfo = () => override ?? expoNetworkBackend;
37
+
38
+ /**
39
+ * expo-network in the shape this module already speaks.
40
+ *
41
+ * The conversion is not cosmetic: expo reports its type as an UPPERCASE enum
42
+ * where this module's vocabulary is lowercase, marks every field optional, and
43
+ * returns an EventSubscription where an unsubscribe function is expected.
44
+ */
45
+ const expoNetworkBackend = {
46
+ fetch: async () => {
47
+ const state = await ExpoNetwork.getNetworkStateAsync();
48
+ return {
49
+ isConnected: state?.isConnected !== false,
50
+ isInternetReachable: state?.isInternetReachable ?? null,
51
+ type: state?.type ? String(state.type).toLowerCase() : undefined
52
+ };
53
+ },
54
+ addEventListener: cb => {
55
+ const subscription = ExpoNetwork.addNetworkStateListener(state => {
56
+ cb({
57
+ isConnected: state?.isConnected !== false,
58
+ isInternetReachable: state?.isInternetReachable ?? null,
59
+ type: state?.type ? String(state.type).toLowerCase() : undefined
60
+ });
61
+ });
62
+ return () => subscription.remove();
27
63
  }
28
- return netInfo;
29
64
  };
30
65
  const normalize = state => {
31
66
  if (!state) {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Permissions = void 0;
6
+ exports.setPermissionsImplementation = exports.Permissions = void 0;
7
7
  var _reactNative = require("react-native");
8
8
  var _index = require("../logger/index.js");
9
9
  // Android only — legacy WRITE_EXTERNAL_STORAGE
@@ -24,6 +24,29 @@ const resolveModule = () => {
24
24
  }
25
25
  return permsModule;
26
26
  };
27
+
28
+ /**
29
+ * Inject a custom permissions implementation at runtime.
30
+ * Pass `null` to reset to the default lazily-resolved native module.
31
+ *
32
+ * `resolved` goes FALSE on null, never true. Marking it resolved with a null
33
+ * backend would permanently disable permissions: the resolver short-circuits and the
34
+ * real module is never loaded again, which contradicts this function's own
35
+ * documented contract. That exact bug shipped once, in the storage seam.
36
+ *
37
+ * THIS MODULE IS THE EXPO-FIRST EXCEPTION, and deliberately keeps the old
38
+ * shape. Expo ships no permissions package: each module carries its own
39
+ * (expo-location's requestForegroundPermissionsAsync, expo-image-picker's, and
40
+ * so on), so there is no single object to adapt and the library must not guess
41
+ * which Expo modules an app installed. react-native-permissions stays, behind
42
+ * this module's own import path so an app that never asks for permissions
43
+ * never names the package to Metro.
44
+ */
45
+ const setPermissionsImplementation = impl => {
46
+ permsModule = impl;
47
+ resolved = impl !== null;
48
+ };
49
+ exports.setPermissionsImplementation = setPermissionsImplementation;
27
50
  const mapToNative = kind => {
28
51
  const m = resolveModule();
29
52
  if (!m) {
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.adaptExpoSqlite = void 0;
7
+ /**
8
+ * expo-sqlite. Shape verified against 57.0.2 rather than assumed, and it is the
9
+ * one driver that cannot share an adapter with the others: expo splits reads
10
+ * from writes. `getAllAsync` yields rows but no change count, `runAsync` yields
11
+ * `{ changes, lastInsertRowId }` but no rows, and SqliteResultSet needs all
12
+ * three from one call. `prepareAsync` + `executeAsync` is the only call that
13
+ * returns both, so every statement goes through it rather than being routed by
14
+ * sniffing the SQL for a leading SELECT.
15
+ *
16
+ * The REQUIRE lives in the driver entry point beside this file, never here.
17
+ */
18
+
19
+ const adaptExpoSqlite = mod => ({
20
+ // expo takes the directory as a third positional argument rather than an
21
+ // option, so `location` cannot be passed through the options object.
22
+ open: async (name, options) => {
23
+ const db = await mod.openDatabaseAsync(name, undefined, options?.location);
24
+ return {
25
+ execute: async (sql, params) => {
26
+ const statement = await db.prepareAsync(sql);
27
+ try {
28
+ const result = await statement.executeAsync(params ? [...params] : []);
29
+ // Safe on a write: expo returns [] when the statement produced no
30
+ // first row rather than stepping the statement a second time.
31
+ const rows = await result.getAllAsync();
32
+ return {
33
+ rows,
34
+ rowsAffected: result.changes,
35
+ // expo always reports lastInsertRowId, so unlike the other drivers
36
+ // this is never undefined. It is the connection's last insert rowid,
37
+ // which is only meaningful immediately after an INSERT.
38
+ insertId: result.lastInsertRowId
39
+ };
40
+ } finally {
41
+ // A statement left unfinalised holds a native handle for the life of
42
+ // the connection, and the core executes one per call.
43
+ await statement.finalizeAsync();
44
+ }
45
+ },
46
+ close: async () => {
47
+ await db.closeAsync();
48
+ }
49
+ };
50
+ }
51
+ });
52
+ exports.adaptExpoSqlite = adaptExpoSqlite;
53
+ //# sourceMappingURL=expo.js.map
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.adaptOpSqlite = void 0;
7
+ /**
8
+ * @op-engineering/op-sqlite. Shape verified against 18.1.4 rather than assumed:
9
+ * `open({ name, location })` is synchronous and returns a DB whose `execute` is
10
+ * ASYNC, and whose `rows` is already a plain array of objects rather than the
11
+ * `{ _array, item() }` shape the older drivers use. Both differences are why it
12
+ * cannot share the sync adapter.
13
+ *
14
+ * The REQUIRE lives in the driver entry point beside this file, never here.
15
+ */
16
+
17
+ const adaptOpSqlite = mod => ({
18
+ open: async (name, options) => {
19
+ const db = mod.open({
20
+ name,
21
+ location: options?.location
22
+ });
23
+ return {
24
+ execute: async (sql, params) => {
25
+ const result = await db.execute(sql, params ? [...params] : undefined);
26
+ return {
27
+ rows: result.rows ?? [],
28
+ rowsAffected: result.rowsAffected ?? 0,
29
+ insertId: result.insertId
30
+ };
31
+ },
32
+ close: async () => {
33
+ if (db.closeAsync) {
34
+ await db.closeAsync();
35
+ return;
36
+ }
37
+ db.close();
38
+ }
39
+ };
40
+ }
41
+ });
42
+ exports.adaptOpSqlite = adaptOpSqlite;
43
+ //# sourceMappingURL=op.js.map
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rowsToArray = void 0;
7
+ /**
8
+ * Row shapes differ per driver: a plain array, `{ _array, length, item() }`, or
9
+ * `{ length, item() }` alone. Every adapter normalises to a plain array here so
10
+ * nothing driver-specific escapes into the Db layer.
11
+ */
12
+ const rowsToArray = rows => {
13
+ if (Array.isArray(rows)) {
14
+ return rows;
15
+ }
16
+ const shaped = rows;
17
+ if (!shaped) {
18
+ return [];
19
+ }
20
+ if (Array.isArray(shaped._array)) {
21
+ return shaped._array;
22
+ }
23
+ if (typeof shaped.item === 'function' && typeof shaped.length === 'number') {
24
+ const out = [];
25
+ for (let i = 0; i < shaped.length; i += 1) {
26
+ out.push(shaped.item(i));
27
+ }
28
+ return out;
29
+ }
30
+ return [];
31
+ };
32
+ exports.rowsToArray = rowsToArray;
33
+ //# sourceMappingURL=rows.js.map
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.adaptSqliteStorage = void 0;
7
+ var _rows = require("./rows.js");
8
+ /** react-native-sqlite-storage: callback-based by default, promise-based once
9
+ * `enablePromise(true)` is called; `executeSql` resolves an array whose first
10
+ * element is the result set. */
11
+
12
+ /**
13
+ * Adapt an already-required `react-native-sqlite-storage` module. Exported for
14
+ * the same reason as the filesystem adapters: the library cannot name a package
15
+ * the app did not install without breaking the app's bundle.
16
+ */
17
+ const adaptSqliteStorage = mod => ({
18
+ open: async (name, options) => {
19
+ // This is a GLOBAL side effect, not a per-connection setting: the vendor
20
+ // implements it by rewriting SQLitePlugin and SQLiteFactory prototype
21
+ // methods. An app that also uses react-native-sqlite-storage directly in
22
+ // callback mode will find its own callbacks converted to promises from the
23
+ // moment this adapter opens a database. Unavoidable, since the adapter
24
+ // cannot work otherwise, and worth knowing before mixing the two.
25
+ mod.enablePromise(true);
26
+ const db = await mod.openDatabase({
27
+ name,
28
+ location: options?.location ?? 'default'
29
+ });
30
+ return {
31
+ execute: async (sql, params) => {
32
+ const [result] = await db.executeSql(sql, params ? [...params] : undefined);
33
+ return {
34
+ rows: (0, _rows.rowsToArray)(result.rows),
35
+ rowsAffected: result.rowsAffected ?? 0,
36
+ insertId: result.insertId
37
+ };
38
+ },
39
+ // Not `() => db.close()`: in promise mode this driver resolves the
40
+ // success-callback ARGUMENTS array rather than void, so returning it
41
+ // directly would make SqliteDatabase.close() resolve an array while
42
+ // typed as void. Awaiting and discarding makes the type honest.
43
+ close: async () => {
44
+ await db.close();
45
+ }
46
+ };
47
+ }
48
+ });
49
+ exports.adaptSqliteStorage = adaptSqliteStorage;
50
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.adaptSyncSqlite = void 0;
7
+ var _rows = require("./rows.js");
8
+ /**
9
+ * nitro-sqlite and quick-sqlite share one synchronous shape, so one adapter
10
+ * serves both. The REQUIRE lives in the driver entry points beside this file,
11
+ * never here and never in the core: Metro resolves requires statically, so a
12
+ * package named anywhere reachable becomes mandatory for every consumer.
13
+ */
14
+
15
+ /** Shape shared by react-native-nitro-sqlite and react-native-quick-sqlite: a
16
+ * synchronous `open({ name, location })` whose `db.execute()` and `db.close()`
17
+ * are also synchronous. Both are wrapped in Promise.resolve to fit SqliteDriver. */
18
+
19
+ /**
20
+ * Adapt an already-required nitro-sqlite or quick-sqlite module. Both expose the
21
+ * same synchronous shape. Exported so an app on quick-sqlite can inject it.
22
+ */
23
+ const adaptSyncSqlite = mod => ({
24
+ open: async (name, options) => {
25
+ const db = mod.open({
26
+ name,
27
+ location: options?.location
28
+ });
29
+ return {
30
+ execute: async (sql, params) => {
31
+ const result = db.execute(sql, params ? [...params] : undefined);
32
+ return {
33
+ rows: (0, _rows.rowsToArray)(result.rows),
34
+ rowsAffected: result.rowsAffected ?? 0,
35
+ insertId: result.insertId
36
+ };
37
+ },
38
+ close: async () => {
39
+ db.close();
40
+ }
41
+ };
42
+ }
43
+ });
44
+ exports.adaptSyncSqlite = adaptSyncSqlite;
45
+ //# sourceMappingURL=sync.js.map