@anfenn/dync 1.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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +212 -0
  3. package/dist/capacitor.cjs +228 -0
  4. package/dist/capacitor.cjs.map +1 -0
  5. package/dist/capacitor.d.cts +62 -0
  6. package/dist/capacitor.d.ts +62 -0
  7. package/dist/capacitor.js +9 -0
  8. package/dist/capacitor.js.map +1 -0
  9. package/dist/chunk-LGHOZECP.js +3884 -0
  10. package/dist/chunk-LGHOZECP.js.map +1 -0
  11. package/dist/chunk-SQB6E7V2.js +191 -0
  12. package/dist/chunk-SQB6E7V2.js.map +1 -0
  13. package/dist/dexie-Bv-fV10P.d.cts +444 -0
  14. package/dist/dexie-DJFApKsM.d.ts +444 -0
  15. package/dist/dexie.cjs +381 -0
  16. package/dist/dexie.cjs.map +1 -0
  17. package/dist/dexie.d.cts +3 -0
  18. package/dist/dexie.d.ts +3 -0
  19. package/dist/dexie.js +343 -0
  20. package/dist/dexie.js.map +1 -0
  21. package/dist/expoSqlite.cjs +98 -0
  22. package/dist/expoSqlite.cjs.map +1 -0
  23. package/dist/expoSqlite.d.cts +17 -0
  24. package/dist/expoSqlite.d.ts +17 -0
  25. package/dist/expoSqlite.js +61 -0
  26. package/dist/expoSqlite.js.map +1 -0
  27. package/dist/index.cjs +3916 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +8 -0
  30. package/dist/index.d.ts +8 -0
  31. package/dist/index.js +20 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/index.shared-CPIge2ZM.d.ts +234 -0
  34. package/dist/index.shared-YSn6c01d.d.cts +234 -0
  35. package/dist/node.cjs +126 -0
  36. package/dist/node.cjs.map +1 -0
  37. package/dist/node.d.cts +80 -0
  38. package/dist/node.d.ts +80 -0
  39. package/dist/node.js +89 -0
  40. package/dist/node.js.map +1 -0
  41. package/dist/react/index.cjs +1754 -0
  42. package/dist/react/index.cjs.map +1 -0
  43. package/dist/react/index.d.cts +40 -0
  44. package/dist/react/index.d.ts +40 -0
  45. package/dist/react/index.js +78 -0
  46. package/dist/react/index.js.map +1 -0
  47. package/dist/types-CSbIAfu2.d.cts +46 -0
  48. package/dist/types-CSbIAfu2.d.ts +46 -0
  49. package/dist/wa-sqlite.cjs +318 -0
  50. package/dist/wa-sqlite.cjs.map +1 -0
  51. package/dist/wa-sqlite.d.cts +175 -0
  52. package/dist/wa-sqlite.d.ts +175 -0
  53. package/dist/wa-sqlite.js +281 -0
  54. package/dist/wa-sqlite.js.map +1 -0
  55. package/package.json +171 -0
  56. package/src/addVisibilityChangeListener.native.ts +33 -0
  57. package/src/addVisibilityChangeListener.ts +24 -0
  58. package/src/capacitor.ts +4 -0
  59. package/src/core/StateManager.ts +272 -0
  60. package/src/core/firstLoad.ts +332 -0
  61. package/src/core/pullOperations.ts +212 -0
  62. package/src/core/pushOperations.ts +290 -0
  63. package/src/core/tableEnhancers.ts +457 -0
  64. package/src/core/types.ts +3 -0
  65. package/src/createLocalId.native.ts +8 -0
  66. package/src/createLocalId.ts +6 -0
  67. package/src/dexie.ts +2 -0
  68. package/src/expoSqlite.ts +2 -0
  69. package/src/helpers.ts +87 -0
  70. package/src/index.native.ts +28 -0
  71. package/src/index.shared.ts +613 -0
  72. package/src/index.ts +28 -0
  73. package/src/logger.ts +26 -0
  74. package/src/node.ts +4 -0
  75. package/src/react/index.ts +2 -0
  76. package/src/react/useDync.ts +156 -0
  77. package/src/storage/dexie/DexieAdapter.ts +72 -0
  78. package/src/storage/dexie/DexieQueryContext.ts +14 -0
  79. package/src/storage/dexie/DexieStorageCollection.ts +124 -0
  80. package/src/storage/dexie/DexieStorageTable.ts +123 -0
  81. package/src/storage/dexie/DexieStorageWhereClause.ts +103 -0
  82. package/src/storage/dexie/helpers.ts +1 -0
  83. package/src/storage/dexie/index.ts +7 -0
  84. package/src/storage/memory/MemoryAdapter.ts +55 -0
  85. package/src/storage/memory/MemoryCollection.ts +215 -0
  86. package/src/storage/memory/MemoryQueryContext.ts +14 -0
  87. package/src/storage/memory/MemoryTable.ts +336 -0
  88. package/src/storage/memory/MemoryWhereClause.ts +134 -0
  89. package/src/storage/memory/index.ts +7 -0
  90. package/src/storage/memory/types.ts +24 -0
  91. package/src/storage/sqlite/SQLiteAdapter.ts +564 -0
  92. package/src/storage/sqlite/SQLiteCollection.ts +294 -0
  93. package/src/storage/sqlite/SQLiteTable.ts +604 -0
  94. package/src/storage/sqlite/SQLiteWhereClause.ts +341 -0
  95. package/src/storage/sqlite/SqliteQueryContext.ts +30 -0
  96. package/src/storage/sqlite/drivers/BetterSqlite3Driver.ts +156 -0
  97. package/src/storage/sqlite/drivers/CapacitorFastSqlDriver.ts +114 -0
  98. package/src/storage/sqlite/drivers/CapacitorSQLiteDriver.ts +137 -0
  99. package/src/storage/sqlite/drivers/ExpoSQLiteDriver.native.ts +67 -0
  100. package/src/storage/sqlite/drivers/WaSqliteDriver.ts +537 -0
  101. package/src/storage/sqlite/drivers/wa-sqlite-vfs.d.ts +46 -0
  102. package/src/storage/sqlite/helpers.ts +144 -0
  103. package/src/storage/sqlite/index.ts +11 -0
  104. package/src/storage/sqlite/schema.ts +44 -0
  105. package/src/storage/sqlite/types.ts +164 -0
  106. package/src/storage/types.ts +112 -0
  107. package/src/types.ts +186 -0
  108. package/src/wa-sqlite.ts +4 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Adam Fennell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,212 @@
1
+ ## Dync
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@anfenn/dync.svg)](https://www.npmjs.com/package/@anfenn/dync)
4
+
5
+ A complete React offline-first data layer with sync engine for any local storage (IndexedDB, Sqlite, etc.), and any backend (Restful, GraphQL, Supabase, etc.) in a Website, PWA, CapacitorJs, React Native, or Electron app.
6
+
7
+ Start with a Website or PWA using IndexedDB, sync with your existing REST API, and later ship native apps with encrypted SQLite - without changing a line of code.
8
+
9
+ ## Why Dync?
10
+
11
+ 1. Frictionless upgrade path from an offline-first PWA targeting IndexedDB, to when:
12
+
13
+ **A)** Full text search is required on many records (IndexedDB doesn't support this so will do a full table scan in the JS VM, which is slow on many records)
14
+
15
+ **_and/or_**
16
+
17
+ **B)** Encryption is required (Browsers can't store the encryption key securely)
18
+
19
+ ... you can simply add CapacitorJs or move to React Native which have sqlite & secure enclave storage, and only change the adapter Dync uses
20
+
21
+ 2. Write once, run anywhere (Web, CapacitorJs, React Native, Electron & Node) with no code changes and native storage performance
22
+ 3. Completely free and open source
23
+
24
+ <br>See first-hand in this fully working example: [examples/react-capacitor](examples/react-capacitor)
25
+
26
+ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-done).
27
+
28
+ ## Goals
29
+
30
+ - Persist SQL or NoSQL data locally and sync some or all tables to a backend
31
+ - Storage agnostic. Comes with `Memory`, `IndexedDB` and `Sqlite` adapters (for CapacitorJs & React Native), and extendable with your own custom adapters
32
+ - Lazy loaded data keeps it in native storage, allowing low memory and fast app response, even with >100K records
33
+ - Fast React Native Sqlite access via JSI
34
+ - Dexie.js style collection based api, with query() escape hatch, and native storage performance e.g.:
35
+ - `db.myTable.add()` | `.update()` | `.where('myField').equals(42).first()`
36
+ - `db.query()` is only intended to retrieve records, any mutations will be ignored by the sync engine:
37
+ ```js
38
+ db.query(async (ctx) => {
39
+ if (ctx instanceof DexieQueryContext) {
40
+ return await ctx.table('items').where('value').equals('dexie-test');
41
+ } else if (ctx instanceof SqliteQueryContext) {
42
+ return await ctx.queryRows('SELECT * FROM items WHERE value = ?', ['sqlite-test']);
43
+ }
44
+ });
45
+ ```
46
+
47
+ - Sync some or all tables with any backend in 2 ways:
48
+ - Option 1: Map remote api CRUD urls to a local collection:
49
+
50
+ ```ts
51
+ const db = makeDync(
52
+ ...,
53
+ {
54
+ // Only add an entry here for tables that should be synced
55
+ items: {
56
+ add: (item) => fetch('/api/items'),
57
+ update: (id, changes) => fetch(`/api/items/${id}`),
58
+ remove: (id) => fetch(`/api/items/${id}`),
59
+ list: (since) => fetch(`/api/items?since=${since}`),
60
+ },
61
+ },
62
+ );
63
+ ```
64
+
65
+ - Option 2: Batch sync to remote /push & /pull endpoints:
66
+
67
+ ```ts
68
+ const db = makeDync(
69
+ ...,
70
+ {
71
+ syncTables: ['items'], // Only add tables to this array that should be synced
72
+ push: (changes) => fetch('/api/sync/push'),
73
+ pull: (since) => fetch(`/api/sync/pull?since=${since}`),
74
+ },
75
+ );
76
+ ```
77
+
78
+ See [examples/shared/api.ts](examples/shared/api.ts) for a fully documented example of these two options.
79
+
80
+ - Full conflict resolution: `local-wins`, `remote-wins` or with `try-shallow-merge` the user can resolve with:
81
+
82
+ ```ts
83
+ const { syncState, db } = useDync();
84
+ syncState.conflicts; // Record<id, Conflict> Use to show user conflicts
85
+ db.sync.resolveConflict(id, true);
86
+ ```
87
+
88
+ - Optional first load data download before periodic sync is enabled
89
+ - Missing remote record on update strategy: `ignore` | `delete-local-record` | `insert-remote-record`
90
+ - Reactive updates when data changes via `useLiveQuery()` React hook:
91
+
92
+ ```ts
93
+ useLiveQuery(async (db) => {
94
+ const items = await db.items.toArray();
95
+ setItems(items);
96
+ }, []);
97
+ ```
98
+
99
+ - Sqlite schema migration
100
+ - "It just works" philosophy
101
+ - Modern and always free (MIT)
102
+
103
+ ## Non-Goals
104
+
105
+ - IndexedDB & SQL unified query language:
106
+ - Using IndexedDB functions or raw SQL will always be more expressive independently
107
+ - No need to learn another api when you might only need one storage type
108
+ - Would greatly increase complexity of this library
109
+
110
+ ## Hasn't this already been done?
111
+
112
+ Many times, with varying degrees of functionality, compatibility, and cost.
113
+
114
+ Dync aims to be a performant, multi-platform, modern and always free alternative.
115
+
116
+ This is how Dync compares to other multi-platform sync engines:
117
+
118
+ **_Legend:_**
119
+
120
+ - _**SQLite:** Used natively by an installed Capacitor, React Native, Electron or Node app_
121
+ - _**WA-SQLite:** Official SQLite compiled to WebAssembly that runs in the browser. Persists to IndexedDB or OPFS depending on VFS configuration (see [SQLite vs WA-SQLite](#sqlite-vs-wa-sqlite))_
122
+
123
+ | Library | Installed Components | IndexedDB | SQLite | WA-SQLite | Any Backend | CRUD Sync | Batch Sync | Conflict Resolution | Platforms | Notes |
124
+ | --------------------------------------------------------------------- | -------------------- | --------- | ---------- | ---------- | ------------------------ | --------- | ---------- | ------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
125
+ | [**Dync**](https://github.com/anfen/dync) | Client | ✅ | ✅ Free | ✅ Free | ✅ | ✅ | ✅ | ✅ | Web, Capacitor, RN, Electron, Node | |
126
+ | [**RxDB**](https://github.com/pubkey/rxdb) | Client | ✅ | 💰 Premium | 💰 Premium | ✅ | ❌ | ✅ | ✅ | Web, Capacitor, RN, Electron, Node | |
127
+ | [**WatermelonDB**](https://github.com/Nozbe/WatermelonDB) | Client | ✅ | ✅ Free | ❌ | ✅ | ❌ | ✅ | ❌ | Web, RN, Node | ⚠️ Not Vite compatible<br>⚠️ Uses legacy JS proposals |
128
+ | [**Legend State**](https://github.com/LegendApp/legend-state) | Client | ✅ | ✅ Free | ❌ | ✅ | ✅ | ❌ | ❌ | Web, RN | ⚠️ [Data loss bugs as of 01/01/2026](https://github.com/LegendApp/legend-state/issues/547)<br>⚠️ Confusing observables based React api |
129
+ | [**SignalDB**](https://github.com/maxnowack/signaldb) | Client | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ | Web | |
130
+ | [**TanStack DB**](https://github.com/TanStack/db) | Client | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | Web, RN | In-memory only<br>Integrates with RxDB/PowerSync/Electric for persistence |
131
+ | [**Dexie.js**](https://github.com/dexie/Dexie.js) | Client | ✅ | ❌ | ❌ | ❌ Dexie cloud only | ❌ | ✅ | ❌ | Web, Capacitor, RN, Electron | |
132
+ | [**PouchDB**](https://github.com/pouchdb/pouchdb) | Client | ✅ | ❌ | ❌ | ❌ CouchDB only | ❌ | ✅ | ✅ | Web, Electron, Node | |
133
+ | [**TinyBase**](https://github.com/tinyplex/tinybase) | Client | ✅ | ✅ Free | ✅ Free | ❌ Client-to-client only | ❌ | ✅ | ✅ | Web, RN, Electron, Node | |
134
+ | [**ElectricSQL**](https://github.com/electric-sql/electric) | Client & Server | ❌ | ✅ Free | ✅ Free | ❌ Postgres only | ❌ | ✅ | ✅ | Web, RN, Electron, Node | |
135
+ | [**PowerSync**](https://github.com/powersync-ja/powersync-js) | Client & Server | ❌ | ✅ Free | ✅ Free | ❌ PowerSync server only | ❌ | ✅ | ✅ | Web, Capacitor, RN, Electron, Node | |
136
+ | [**InstantDB**](https://github.com/instantdb/instant) | Client | ✅ | ❌ | ❌ | ❌ InstantDB cloud only | ❌ | ✅ | ✅ | Web, RN | |
137
+ | [**Firebase/Firestore**](https://github.com/firebase/firebase-js-sdk) | Client | ✅ | ❌ | ❌ | ❌ Firebase cloud only | ❌ | ✅ | ✅ | Web, iOS, Android, RN, Flutter, Node | |
138
+
139
+ ## Examples
140
+
141
+ Both are fully commented and can be run in the browser and natively on iOS/Android without code change:
142
+
143
+ 1. **React + Capacitor**: [examples/react-capacitor](examples/react-capacitor) - IndexedDB in the browser, SQLite natively
144
+ 2. **React Native + Expo SQLite**: [examples/react-native-expo-sqlite](examples/react-native-expo-sqlite) - WA-SQLite in the browser, SQLite natively
145
+
146
+ ## Design
147
+
148
+ ### Server Requirements
149
+
150
+ Your server records **must** have these fields. If it does but they're named differently, rename them in your client's [api.ts](examples/shared/api.ts) using the included `changeKeysFrom()` & `changeKeysTo()` helpers:
151
+
152
+ | Field | Description |
153
+ | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
154
+ | `id` | Unique identifier (any datatype). Can be assigned by client or server. |
155
+ | `updated_at` | Server-assigned **millisecond** timestamp (e.g. via db trigger or API layer). The client never sends this as client clocks are unreliable. Ensure precision doesn't exceed milliseconds (like PostgreSQL's microsecond timestamptz), otherwise updates may be ignored. |
156
+ | `deleted` | Boolean for soft deletes. Allows other clients to sync deletions to their local store. |
157
+
158
+ ### Client Records
159
+
160
+ Dync auto-injects these fields into your local table schema:
161
+
162
+ | Field | Description |
163
+ | ------------ | --------------------------------------------------------------------------------------------------------------------------------- |
164
+ | `_localId` | Stable local identifier, never sent to the server. Ideal for React keys. Generate with `createLocalId()` or use any unique value. |
165
+ | `id` | Unique identifier (any datatype). Can be assigned by client or server. |
166
+ | `updated_at` | Assigned from the server's `updated_at` after sync. You may set it optimistically, but it's always overwritten on sync. |
167
+
168
+ Note: `deleted` doesn't exist on the client, as it's removed during sync.
169
+
170
+ ## SQLite vs WA-SQLite
171
+
172
+ **SQLite** runs natively in Capacitor, React Native, Electron, and Node apps via platform-specific drivers.
173
+
174
+ **WA-SQLite** is SQLite compiled to WebAssembly, enabling SQL in the browser. It persists data to IndexedDB or OPFS depending on the Virtual File System (VFS) you choose.
175
+
176
+ ### When to use WA-SQLite
177
+
178
+ - You need SQL queries in a web app (full-text search, complex joins, etc.)
179
+ - Your dataset is too large for efficient IndexedDB queries
180
+ - You want the same SQLite schema across web and native apps
181
+ - You don't need encryption, as browsers can't securely store the encryption key
182
+ - You're happy for a larger runtime memory footprint
183
+
184
+ ### WA-SQLite VFS Options
185
+
186
+ Choose a VFS based on your app's requirements. See [`WaSqliteDriverOptions`](src/storage/sqlite/drivers/WaSqliteDriver.ts) for configuration.
187
+
188
+ | VFS | Context | Multi-Tab | Durability | Performance | Best For |
189
+ | ----------------------- | ------- | --------- | ---------- | ----------- | ------------------------------------- |
190
+ | **IDBBatchAtomicVFS** | Any | ✅ | ✅ Full | Good | General use, maximum compatibility |
191
+ | **IDBMirrorVFS** | Any | ✅ | ⚠️ Async | Fast | Small databases, performance critical |
192
+ | **OPFSCoopSyncVFS** | Worker | ✅ | ✅ Full | Good | Multi-tab apps needing OPFS |
193
+ | **AccessHandlePoolVFS** | Worker | ❌ | ✅ Full | Best | Single-tab apps, maximum performance |
194
+
195
+ **Notes:**
196
+
197
+ - **IDBBatchAtomicVFS** (default) is recommended for most apps - works in main thread and has full durability
198
+ - **IDBMirrorVFS** keeps data in memory and mirrors to IndexedDB asynchronously - fast but may lose recent writes on crash
199
+ - **OPFS VFS types** require a Web Worker context and are not supported on Safari/iOS
200
+
201
+ ```ts
202
+ import { WaSqliteDriver, SQLiteAdapter } from '@anfenn/dync/wa-sqlite';
203
+
204
+ const driver = new WaSqliteDriver('mydb', {
205
+ vfs: 'IDBBatchAtomicVFS', // or 'IDBMirrorVFS', 'OPFSCoopSyncVFS', 'AccessHandlePoolVFS'
206
+ });
207
+ const adapter = new SQLiteAdapter(driver);
208
+ ```
209
+
210
+ ## Community
211
+
212
+ PRs are welcome! [pnpm](https://pnpm.io) is used as a package manager. Run `pnpm install` to install local dependencies. Thank you for contributing!
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/capacitor.ts
31
+ var capacitor_exports = {};
32
+ __export(capacitor_exports, {
33
+ CapacitorFastSqlDriver: () => CapacitorFastSqlDriver,
34
+ CapacitorSQLiteDriver: () => CapacitorSQLiteDriver
35
+ });
36
+ module.exports = __toCommonJS(capacitor_exports);
37
+
38
+ // src/storage/sqlite/drivers/CapacitorSQLiteDriver.ts
39
+ var sqliteModuleCache = null;
40
+ async function getSqliteModule() {
41
+ if (!sqliteModuleCache) {
42
+ sqliteModuleCache = await import("@capacitor-community/sqlite");
43
+ }
44
+ return sqliteModuleCache;
45
+ }
46
+ var CapacitorSQLiteDriver = class {
47
+ type = "CapacitorSQLiteDriver";
48
+ connectionFactory;
49
+ config;
50
+ db;
51
+ openPromise;
52
+ opened = false;
53
+ name;
54
+ constructor(databaseName, config = {}) {
55
+ this.name = databaseName;
56
+ this.config = config;
57
+ }
58
+ async getConnectionFactory() {
59
+ if (!this.connectionFactory) {
60
+ const { CapacitorSQLite, SQLiteConnection } = await getSqliteModule();
61
+ this.connectionFactory = new SQLiteConnection(CapacitorSQLite);
62
+ }
63
+ return this.connectionFactory;
64
+ }
65
+ async ensureDb() {
66
+ if (!this.db) {
67
+ const connectionFactory = await this.getConnectionFactory();
68
+ const readonly = this.config.readonly ?? false;
69
+ const existsResult = await connectionFactory.isConnection(this.name, readonly);
70
+ if (existsResult.result) {
71
+ this.db = await connectionFactory.retrieveConnection(this.name, readonly);
72
+ } else {
73
+ await connectionFactory.closeConnection(this.name, readonly).catch(() => {
74
+ });
75
+ this.db = await connectionFactory.createConnection(
76
+ this.name,
77
+ this.config.encrypted ?? false,
78
+ this.config.mode ?? "no-encryption",
79
+ this.config.version ?? 1,
80
+ readonly
81
+ );
82
+ }
83
+ this.opened = false;
84
+ }
85
+ return this.db;
86
+ }
87
+ async open() {
88
+ if (this.opened) return;
89
+ if (this.openPromise) return this.openPromise;
90
+ this.openPromise = (async () => {
91
+ const connectionFactory = await this.getConnectionFactory();
92
+ if (this.config.getEncryptionKey) {
93
+ const { result: isStored } = await connectionFactory.isSecretStored();
94
+ if (!isStored) {
95
+ const key = this.config.getEncryptionKey();
96
+ if (!key && this.config.encrypted) {
97
+ throw new Error("CapacitorSQLiteDriverOptions.encrypted=true but no encryption key was provided (getEncryptionKey).");
98
+ }
99
+ await connectionFactory.setEncryptionSecret(key);
100
+ }
101
+ }
102
+ const db = await this.ensureDb();
103
+ await db.open();
104
+ this.opened = true;
105
+ })();
106
+ try {
107
+ await this.openPromise;
108
+ } finally {
109
+ this.openPromise = void 0;
110
+ }
111
+ }
112
+ async close() {
113
+ if (!this.db) return;
114
+ await this.db.close();
115
+ const connectionFactory = await this.getConnectionFactory();
116
+ await connectionFactory.closeConnection(this.name, this.config.readonly ?? false);
117
+ this.db = void 0;
118
+ this.opened = false;
119
+ this.openPromise = void 0;
120
+ }
121
+ async execute(statement) {
122
+ await this.open();
123
+ const db = await this.ensureDb();
124
+ await db.execute(statement, false);
125
+ }
126
+ async run(statement, values = []) {
127
+ await this.open();
128
+ const db = await this.ensureDb();
129
+ const result = await db.run(statement, values, false, "no");
130
+ const changes = result?.changes?.changes ?? result?.changes ?? 0;
131
+ const lastId = result?.changes?.lastId ?? void 0;
132
+ return { changes, lastId };
133
+ }
134
+ async query(statement, values = []) {
135
+ await this.open();
136
+ const db = await this.ensureDb();
137
+ const result = await db.query(statement, values, true);
138
+ if (Array.isArray(result?.values) && result.values.length > 0 && !Array.isArray(result.values[0])) {
139
+ const columns = Object.keys(result.values[0]);
140
+ const rows = result.values.map((row) => columns.map((column) => row[column]));
141
+ return { columns, values: rows };
142
+ }
143
+ return { columns: result?.columns ?? [], values: result?.values ?? [] };
144
+ }
145
+ };
146
+
147
+ // src/storage/sqlite/drivers/CapacitorFastSqlDriver.ts
148
+ var fastSqlModuleCache = null;
149
+ async function getFastSqlModule() {
150
+ if (!fastSqlModuleCache) {
151
+ fastSqlModuleCache = await import("@capgo/capacitor-fast-sql");
152
+ }
153
+ return fastSqlModuleCache;
154
+ }
155
+ var CapacitorFastSqlDriver = class {
156
+ type = "CapacitorFastSqlDriver";
157
+ options;
158
+ db;
159
+ openPromise;
160
+ opened = false;
161
+ name;
162
+ constructor(databaseName, options = {}) {
163
+ this.name = databaseName;
164
+ this.options = options;
165
+ }
166
+ async open() {
167
+ if (this.opened) return;
168
+ if (this.openPromise) return this.openPromise;
169
+ this.openPromise = (async () => {
170
+ if (!this.db) {
171
+ const { FastSQL } = await getFastSqlModule();
172
+ const encryptionKey = this.options.getEncryptionKey?.();
173
+ if (!encryptionKey && this.options.encrypted) {
174
+ throw new Error("FastSqlDriverOptions.encrypted=true but no encryption key was provided (getEncryptionKey).");
175
+ }
176
+ this.db = await FastSQL.connect({
177
+ database: this.name,
178
+ encrypted: this.options.encrypted,
179
+ encryptionKey,
180
+ readOnly: this.options.readonly
181
+ });
182
+ this.opened = true;
183
+ }
184
+ })();
185
+ try {
186
+ await this.openPromise;
187
+ } finally {
188
+ this.openPromise = void 0;
189
+ }
190
+ }
191
+ async close() {
192
+ if (this.db) {
193
+ const { FastSQL } = await getFastSqlModule();
194
+ await FastSQL.disconnect(this.name);
195
+ this.db = void 0;
196
+ this.opened = false;
197
+ this.openPromise = void 0;
198
+ }
199
+ }
200
+ async execute(statement) {
201
+ await this.open();
202
+ await this.db.execute(statement);
203
+ }
204
+ async run(statement, values = []) {
205
+ await this.open();
206
+ const result = await this.db.run(statement, values);
207
+ return {
208
+ changes: result.rowsAffected,
209
+ lastId: result.insertId
210
+ };
211
+ }
212
+ async query(statement, values = []) {
213
+ await this.open();
214
+ const rows = await this.db.query(statement, values);
215
+ if (!rows.length) {
216
+ return { columns: [], values: [] };
217
+ }
218
+ const columns = Object.keys(rows[0]);
219
+ const resultValues = rows.map((row) => columns.map((col) => row[col]));
220
+ return { columns, values: resultValues };
221
+ }
222
+ };
223
+ // Annotate the CommonJS export names for ESM import in node:
224
+ 0 && (module.exports = {
225
+ CapacitorFastSqlDriver,
226
+ CapacitorSQLiteDriver
227
+ });
228
+ //# sourceMappingURL=capacitor.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/capacitor.ts","../src/storage/sqlite/drivers/CapacitorSQLiteDriver.ts","../src/storage/sqlite/drivers/CapacitorFastSqlDriver.ts"],"sourcesContent":["// Capacitor SQLite Drivers\n// Import this entry point only in Capacitor/native builds\nexport { CapacitorSQLiteDriver } from './storage/sqlite/drivers/CapacitorSQLiteDriver';\nexport { CapacitorFastSqlDriver, type FastSqlDriverOptions } from './storage/sqlite/drivers/CapacitorFastSqlDriver';\n","import type { SQLiteConnection, SQLiteDBConnection } from '@capacitor-community/sqlite';\nimport type { SQLiteDatabaseDriver, SQLiteRunResult, SQLiteQueryResult } from '../types';\n\n// Lazily loaded module cache to avoid top-level imports that break web bundlers\nlet sqliteModuleCache: typeof import('@capacitor-community/sqlite') | null = null;\n\nasync function getSqliteModule(): Promise<typeof import('@capacitor-community/sqlite')> {\n if (!sqliteModuleCache) {\n sqliteModuleCache = await import('@capacitor-community/sqlite');\n }\n return sqliteModuleCache;\n}\n\nexport interface CapacitorSQLiteDriverOptions {\n encrypted?: boolean;\n getEncryptionKey?: () => string;\n readonly?: boolean;\n mode?: string;\n version?: number;\n}\n\nexport class CapacitorSQLiteDriver implements SQLiteDatabaseDriver {\n readonly type = 'CapacitorSQLiteDriver';\n private connectionFactory?: SQLiteConnection;\n private readonly config: CapacitorSQLiteDriverOptions;\n private db?: SQLiteDBConnection;\n private openPromise?: Promise<void>;\n private opened = false;\n readonly name: string;\n\n constructor(databaseName: string, config: CapacitorSQLiteDriverOptions = {}) {\n this.name = databaseName;\n this.config = config;\n }\n\n private async getConnectionFactory(): Promise<SQLiteConnection> {\n if (!this.connectionFactory) {\n const { CapacitorSQLite, SQLiteConnection } = await getSqliteModule();\n this.connectionFactory = new SQLiteConnection(CapacitorSQLite);\n }\n return this.connectionFactory;\n }\n\n private async ensureDb(): Promise<SQLiteDBConnection> {\n if (!this.db) {\n const connectionFactory = await this.getConnectionFactory();\n const readonly = this.config.readonly ?? false;\n\n // Check if a connection already exists (e.g., after page reload)\n const existsResult = await connectionFactory.isConnection(this.name, readonly);\n if (existsResult.result) {\n // Connection exists - retrieve it instead of creating a new one\n this.db = await connectionFactory.retrieveConnection(this.name, readonly);\n } else {\n // Close any stale native connection (e.g., after page reload) before creating\n await connectionFactory.closeConnection(this.name, readonly).catch(() => {});\n this.db = await connectionFactory.createConnection(\n this.name,\n this.config.encrypted ?? false,\n this.config.mode ?? 'no-encryption',\n this.config.version ?? 1,\n readonly,\n );\n }\n\n // New/retrieved connection means we need to (re)open it.\n this.opened = false;\n }\n return this.db;\n }\n\n async open(): Promise<void> {\n if (this.opened) return;\n if (this.openPromise) return this.openPromise;\n\n this.openPromise = (async () => {\n const connectionFactory = await this.getConnectionFactory();\n // Set encryption secret if provided and not already stored (must be done before opening)\n if (this.config.getEncryptionKey) {\n const { result: isStored } = await connectionFactory.isSecretStored();\n if (!isStored) {\n const key = this.config.getEncryptionKey();\n if (!key && this.config.encrypted) {\n throw new Error('CapacitorSQLiteDriverOptions.encrypted=true but no encryption key was provided (getEncryptionKey).');\n }\n await connectionFactory.setEncryptionSecret(key);\n }\n }\n const db = await this.ensureDb();\n await db.open();\n this.opened = true;\n })();\n\n try {\n await this.openPromise;\n } finally {\n this.openPromise = undefined;\n }\n }\n\n async close(): Promise<void> {\n if (!this.db) return;\n await this.db.close();\n const connectionFactory = await this.getConnectionFactory();\n await connectionFactory.closeConnection(this.name, this.config.readonly ?? false);\n this.db = undefined;\n this.opened = false;\n this.openPromise = undefined;\n }\n\n async execute(statement: string): Promise<void> {\n await this.open();\n const db = await this.ensureDb();\n await db.execute(statement, false);\n }\n\n async run(statement: string, values: any[] = []): Promise<SQLiteRunResult> {\n await this.open();\n const db = await this.ensureDb();\n const result = await db.run(statement, values, false, 'no');\n const changes = (result as any)?.changes?.changes ?? (result as any)?.changes ?? 0;\n const lastId = (result as any)?.changes?.lastId ?? undefined;\n return { changes, lastId };\n }\n\n async query(statement: string, values: any[] = []): Promise<SQLiteQueryResult> {\n await this.open();\n const db = await this.ensureDb();\n const result: any = await db.query(statement, values, true);\n if (Array.isArray(result?.values) && result.values.length > 0 && !Array.isArray(result.values[0])) {\n const columns = Object.keys(result.values[0]);\n const rows = result.values.map((row: Record<string, any>) => columns.map((column) => row[column]));\n return { columns, values: rows };\n }\n return { columns: result?.columns ?? [], values: result?.values ?? [] };\n }\n}\n","import type { SQLConnection, SQLValue } from '@capgo/capacitor-fast-sql';\n\nimport type { SQLiteDatabaseDriver, SQLiteRunResult, SQLiteQueryResult } from '../types';\n\nexport interface FastSqlDriverOptions {\n encrypted?: boolean;\n getEncryptionKey?: () => string;\n readonly?: boolean;\n}\n\n// Lazily loaded module cache to avoid top-level imports that break web bundlers\nlet fastSqlModuleCache: typeof import('@capgo/capacitor-fast-sql') | null = null;\n\nasync function getFastSqlModule(): Promise<typeof import('@capgo/capacitor-fast-sql')> {\n if (!fastSqlModuleCache) {\n fastSqlModuleCache = await import('@capgo/capacitor-fast-sql');\n }\n return fastSqlModuleCache;\n}\n\n/**\n * SQLiteDatabaseDriver implementation for @capgo/capacitor-fast-sql plugin.\n *\n * This driver provides a compatible interface with the existing SQLiteAdapter\n * while using the Capgo Fast SQL plugin which offers better performance through\n * a local HTTP server approach that bypasses Capacitor's bridge.\n * \n * Update your AndroidManifest.xml to allow cleartext traffic:\n * <application\n ...\n android:usesCleartextTraffic=\"true\">\n\n Requires Capacitor HTTP plugin to prevent CORS, as FastSql server runs on localhost:9000, not Capacitor's localhost\n */\nexport class CapacitorFastSqlDriver implements SQLiteDatabaseDriver {\n readonly type = 'CapacitorFastSqlDriver';\n private readonly options: FastSqlDriverOptions;\n private db?: SQLConnection;\n private openPromise?: Promise<void>;\n private opened = false;\n readonly name: string;\n\n constructor(databaseName: string, options: FastSqlDriverOptions = {}) {\n this.name = databaseName;\n this.options = options;\n }\n\n async open(): Promise<void> {\n if (this.opened) return;\n if (this.openPromise) return this.openPromise;\n\n this.openPromise = (async () => {\n if (!this.db) {\n const { FastSQL } = await getFastSqlModule();\n const encryptionKey = this.options.getEncryptionKey?.();\n if (!encryptionKey && this.options.encrypted) {\n throw new Error('FastSqlDriverOptions.encrypted=true but no encryption key was provided (getEncryptionKey).');\n }\n this.db = await FastSQL.connect({\n database: this.name,\n encrypted: this.options.encrypted,\n encryptionKey,\n readOnly: this.options.readonly,\n });\n this.opened = true;\n }\n })();\n\n try {\n await this.openPromise;\n } finally {\n this.openPromise = undefined;\n }\n }\n\n async close(): Promise<void> {\n if (this.db) {\n const { FastSQL } = await getFastSqlModule();\n await FastSQL.disconnect(this.name);\n this.db = undefined;\n this.opened = false;\n this.openPromise = undefined;\n }\n }\n\n async execute(statement: string): Promise<void> {\n await this.open();\n await this.db!.execute(statement);\n }\n\n async run(statement: string, values: any[] = []): Promise<SQLiteRunResult> {\n await this.open();\n const result = await this.db!.run(statement, values as SQLValue[]);\n return {\n changes: result.rowsAffected,\n lastId: result.insertId,\n };\n }\n\n async query(statement: string, values: any[] = []): Promise<SQLiteQueryResult> {\n await this.open();\n const rows = await this.db!.query(statement, values as SQLValue[]);\n\n // Convert array of objects to columns + values format expected by adapter\n if (!rows.length) {\n return { columns: [], values: [] };\n }\n\n const columns = Object.keys(rows[0]!);\n const resultValues = rows.map((row) => columns.map((col) => (row as Record<string, any>)[col]));\n\n return { columns, values: resultValues };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,IAAI,oBAAyE;AAE7E,eAAe,kBAAyE;AACpF,MAAI,CAAC,mBAAmB;AACpB,wBAAoB,MAAM,OAAO,6BAA6B;AAAA,EAClE;AACA,SAAO;AACX;AAUO,IAAM,wBAAN,MAA4D;AAAA,EACtD,OAAO;AAAA,EACR;AAAA,EACS;AAAA,EACT;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACR;AAAA,EAET,YAAY,cAAsB,SAAuC,CAAC,GAAG;AACzE,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAClB;AAAA,EAEA,MAAc,uBAAkD;AAC5D,QAAI,CAAC,KAAK,mBAAmB;AACzB,YAAM,EAAE,iBAAiB,iBAAiB,IAAI,MAAM,gBAAgB;AACpE,WAAK,oBAAoB,IAAI,iBAAiB,eAAe;AAAA,IACjE;AACA,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,MAAc,WAAwC;AAClD,QAAI,CAAC,KAAK,IAAI;AACV,YAAM,oBAAoB,MAAM,KAAK,qBAAqB;AAC1D,YAAM,WAAW,KAAK,OAAO,YAAY;AAGzC,YAAM,eAAe,MAAM,kBAAkB,aAAa,KAAK,M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M,KAAK,KAAK;AAChB,UAAM,SAAS,MAAM,KAAK,GAAI,IAAI,WAAW,MAAoB;AACjE,WAAO;AAAA,MACH,SAAS,OAAO;AAAA,MAChB,QAAQ,OAAO;AAAA,IACnB;AAAA,EACJ;AAAA,EAEA,MAAM,MAAM,WAAmB,SAAgB,CAAC,GAA+B;AAC3E,UAAM,KAAK,KAAK;AAChB,UAAM,OAAO,MAAM,KAAK,GAAI,MAAM,WAAW,MAAoB;AAGjE,QAAI,CAAC,KAAK,QAAQ;AACd,aAAO,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,EAAE;AAAA,IACrC;AAEA,UAAM,UAAU,OAAO,KAAK,KAAK,CAAC,CAAE;AACpC,UAAM,eAAe,KAAK,IAAI,CAAC,QAAQ,QAAQ,IAAI,CAAC,QAAS,IAA4B,GAAG,CAAC,CAAC;AAE9F,WAAO,EAAE,SAAS,QAAQ,aAAa;AAAA,EAC3C;AACJ;","names":[]}
@@ -0,0 +1,62 @@
1
+ import { S as SQLiteDatabaseDriver, a as SQLiteRunResult, b as SQLiteQueryResult } from './types-CSbIAfu2.cjs';
2
+
3
+ interface CapacitorSQLiteDriverOptions {
4
+ encrypted?: boolean;
5
+ getEncryptionKey?: () => string;
6
+ readonly?: boolean;
7
+ mode?: string;
8
+ version?: number;
9
+ }
10
+ declare class CapacitorSQLiteDriver implements SQLiteDatabaseDriver {
11
+ readonly type = "CapacitorSQLiteDriver";
12
+ private connectionFactory?;
13
+ private readonly config;
14
+ private db?;
15
+ private openPromise?;
16
+ private opened;
17
+ readonly name: string;
18
+ constructor(databaseName: string, config?: CapacitorSQLiteDriverOptions);
19
+ private getConnectionFactory;
20
+ private ensureDb;
21
+ open(): Promise<void>;
22
+ close(): Promise<void>;
23
+ execute(statement: string): Promise<void>;
24
+ run(statement: string, values?: any[]): Promise<SQLiteRunResult>;
25
+ query(statement: string, values?: any[]): Promise<SQLiteQueryResult>;
26
+ }
27
+
28
+ interface FastSqlDriverOptions {
29
+ encrypted?: boolean;
30
+ getEncryptionKey?: () => string;
31
+ readonly?: boolean;
32
+ }
33
+ /**
34
+ * SQLiteDatabaseDriver implementation for @capgo/capacitor-fast-sql plugin.
35
+ *
36
+ * This driver provides a compatible interface with the existing SQLiteAdapter
37
+ * while using the Capgo Fast SQL plugin which offers better performance through
38
+ * a local HTTP server approach that bypasses Capacitor's bridge.
39
+ *
40
+ * Update your AndroidManifest.xml to allow cleartext traffic:
41
+ * <application
42
+ ...
43
+ android:usesCleartextTraffic="true">
44
+
45
+ Requires Capacitor HTTP plugin to prevent CORS, as FastSql server runs on localhost:9000, not Capacitor's localhost
46
+ */
47
+ declare class CapacitorFastSqlDriver implements SQLiteDatabaseDriver {
48
+ readonly type = "CapacitorFastSqlDriver";
49
+ private readonly options;
50
+ private db?;
51
+ private openPromise?;
52
+ private opened;
53
+ readonly name: string;
54
+ constructor(databaseName: string, options?: FastSqlDriverOptions);
55
+ open(): Promise<void>;
56
+ close(): Promise<void>;
57
+ execute(statement: string): Promise<void>;
58
+ run(statement: string, values?: any[]): Promise<SQLiteRunResult>;
59
+ query(statement: string, values?: any[]): Promise<SQLiteQueryResult>;
60
+ }
61
+
62
+ export { CapacitorFastSqlDriver, CapacitorSQLiteDriver, type FastSqlDriverOptions };
@@ -0,0 +1,62 @@
1
+ import { S as SQLiteDatabaseDriver, a as SQLiteRunResult, b as SQLiteQueryResult } from './types-CSbIAfu2.js';
2
+
3
+ interface CapacitorSQLiteDriverOptions {
4
+ encrypted?: boolean;
5
+ getEncryptionKey?: () => string;
6
+ readonly?: boolean;
7
+ mode?: string;
8
+ version?: number;
9
+ }
10
+ declare class CapacitorSQLiteDriver implements SQLiteDatabaseDriver {
11
+ readonly type = "CapacitorSQLiteDriver";
12
+ private connectionFactory?;
13
+ private readonly config;
14
+ private db?;
15
+ private openPromise?;
16
+ private opened;
17
+ readonly name: string;
18
+ constructor(databaseName: string, config?: CapacitorSQLiteDriverOptions);
19
+ private getConnectionFactory;
20
+ private ensureDb;
21
+ open(): Promise<void>;
22
+ close(): Promise<void>;
23
+ execute(statement: string): Promise<void>;
24
+ run(statement: string, values?: any[]): Promise<SQLiteRunResult>;
25
+ query(statement: string, values?: any[]): Promise<SQLiteQueryResult>;
26
+ }
27
+
28
+ interface FastSqlDriverOptions {
29
+ encrypted?: boolean;
30
+ getEncryptionKey?: () => string;
31
+ readonly?: boolean;
32
+ }
33
+ /**
34
+ * SQLiteDatabaseDriver implementation for @capgo/capacitor-fast-sql plugin.
35
+ *
36
+ * This driver provides a compatible interface with the existing SQLiteAdapter
37
+ * while using the Capgo Fast SQL plugin which offers better performance through
38
+ * a local HTTP server approach that bypasses Capacitor's bridge.
39
+ *
40
+ * Update your AndroidManifest.xml to allow cleartext traffic:
41
+ * <application
42
+ ...
43
+ android:usesCleartextTraffic="true">
44
+
45
+ Requires Capacitor HTTP plugin to prevent CORS, as FastSql server runs on localhost:9000, not Capacitor's localhost
46
+ */
47
+ declare class CapacitorFastSqlDriver implements SQLiteDatabaseDriver {
48
+ readonly type = "CapacitorFastSqlDriver";
49
+ private readonly options;
50
+ private db?;
51
+ private openPromise?;
52
+ private opened;
53
+ readonly name: string;
54
+ constructor(databaseName: string, options?: FastSqlDriverOptions);
55
+ open(): Promise<void>;
56
+ close(): Promise<void>;
57
+ execute(statement: string): Promise<void>;
58
+ run(statement: string, values?: any[]): Promise<SQLiteRunResult>;
59
+ query(statement: string, values?: any[]): Promise<SQLiteQueryResult>;
60
+ }
61
+
62
+ export { CapacitorFastSqlDriver, CapacitorSQLiteDriver, type FastSqlDriverOptions };
@@ -0,0 +1,9 @@
1
+ import {
2
+ CapacitorFastSqlDriver,
3
+ CapacitorSQLiteDriver
4
+ } from "./chunk-SQB6E7V2.js";
5
+ export {
6
+ CapacitorFastSqlDriver,
7
+ CapacitorSQLiteDriver
8
+ };
9
+ //# sourceMappingURL=capacitor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}