@quereus/plugin-react-native-leveldb 0.3.1 → 0.4.1
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/README.md +239 -194
- package/dist/src/plugin.d.ts +7 -1
- package/dist/src/plugin.d.ts.map +1 -1
- package/dist/src/plugin.js +40 -2
- package/dist/src/plugin.js.map +1 -1
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -1,194 +1,239 @@
|
|
|
1
|
-
# @quereus/plugin-react-native-leveldb
|
|
2
|
-
|
|
3
|
-
LevelDB storage plugin for Quereus on React Native. Provides fast, persistent storage for mobile iOS and Android applications using the [`@quereus/store`](../quereus-store/) module.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Fast**: LevelDB offers excellent read/write performance, significantly faster than AsyncStorage
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await db
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
await
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
1
|
+
# @quereus/plugin-react-native-leveldb
|
|
2
|
+
|
|
3
|
+
LevelDB storage plugin for Quereus on React Native. Provides fast, persistent storage for mobile iOS and Android applications using the [`@quereus/store`](../quereus-store/) module.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Fast**: LevelDB offers excellent read/write performance, significantly faster than AsyncStorage
|
|
8
|
+
- **Transaction isolation**: Read-your-own-writes and snapshot isolation by default
|
|
9
|
+
- **Synchronous API**: Uses rn-leveldb's synchronous, blocking APIs
|
|
10
|
+
- **Binary data**: Full support for binary keys and values via ArrayBuffers
|
|
11
|
+
- **Sorted keys**: Efficient range queries with ordered iteration
|
|
12
|
+
- **Persistent**: Data survives app restarts
|
|
13
|
+
- **Atomic batch writes**: Uses native LevelDB WriteBatch for atomic multi-key operations
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @quereus/plugin-react-native-leveldb @quereus/store @quereus/isolation rn-leveldb
|
|
19
|
+
|
|
20
|
+
# Don't forget to link native modules
|
|
21
|
+
cd ios && pod install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Required Polyfills
|
|
25
|
+
|
|
26
|
+
React Native apps typically need a few runtime polyfills for Quereus and its plugins:
|
|
27
|
+
|
|
28
|
+
- **`structuredClone`** - Quereus uses it internally for deep cloning operations
|
|
29
|
+
- **`TextEncoder` / `TextDecoder`** - Used by store plugins for binary data encoding
|
|
30
|
+
- **`Symbol.asyncIterator`** - Required for async-iterable support (for-await-of loops, async generators)
|
|
31
|
+
- Quereus uses async iterables extensively for query results and data streaming
|
|
32
|
+
- While Hermes has a workaround for AsyncGenerator objects, the `Symbol.asyncIterator` symbol itself must exist
|
|
33
|
+
- Without it, you'll get `ReferenceError: Can't find variable: Symbol` when checking for async iterables
|
|
34
|
+
|
|
35
|
+
**The plugin automatically checks for these polyfills** and throws a clear error message with installation instructions if any are missing.
|
|
36
|
+
|
|
37
|
+
You can use packages like `core-js` or provide your own implementations:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install core-js text-encoding
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then in your app's entry point:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import 'core-js/features/structured-clone';
|
|
47
|
+
import 'text-encoding';
|
|
48
|
+
|
|
49
|
+
// Ensure Symbol.asyncIterator exists
|
|
50
|
+
if (typeof Symbol.asyncIterator === 'undefined') {
|
|
51
|
+
(Symbol as any).asyncIterator = Symbol.for('Symbol.asyncIterator');
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
### With registerPlugin (Recommended)
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { LevelDB, LevelDBWriteBatch } from 'rn-leveldb';
|
|
61
|
+
import { Database, registerPlugin } from '@quereus/quereus';
|
|
62
|
+
import leveldbPlugin from '@quereus/plugin-react-native-leveldb/plugin';
|
|
63
|
+
|
|
64
|
+
const db = new Database();
|
|
65
|
+
await registerPlugin(db, leveldbPlugin, {
|
|
66
|
+
openFn: (name, createIfMissing, errorIfExists) => new LevelDB(name, createIfMissing, errorIfExists),
|
|
67
|
+
WriteBatch: LevelDBWriteBatch,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await db.exec(`
|
|
71
|
+
create table users (id integer primary key, name text)
|
|
72
|
+
using store
|
|
73
|
+
`);
|
|
74
|
+
|
|
75
|
+
// Full transaction isolation enabled by default
|
|
76
|
+
await db.exec('BEGIN');
|
|
77
|
+
await db.exec(`insert into users (id, name) values (1, 'Alice')`);
|
|
78
|
+
const user = await db.get('select * from users where id = 1'); // Sees uncommitted insert
|
|
79
|
+
await db.exec('COMMIT');
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Disabling Isolation
|
|
83
|
+
|
|
84
|
+
If you need maximum performance and don't require read-your-own-writes within transactions:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
await registerPlugin(db, leveldbPlugin, {
|
|
88
|
+
openFn: (name, createIfMissing, errorIfExists) => new LevelDB(name, createIfMissing, errorIfExists),
|
|
89
|
+
WriteBatch: LevelDBWriteBatch,
|
|
90
|
+
isolation: false // Disable isolation layer
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Direct Usage with Provider
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { LevelDB, LevelDBWriteBatch } from 'rn-leveldb';
|
|
98
|
+
import { Database } from '@quereus/quereus';
|
|
99
|
+
import { createReactNativeLevelDBProvider } from '@quereus/plugin-react-native-leveldb';
|
|
100
|
+
import { createIsolatedStoreModule } from '@quereus/store';
|
|
101
|
+
|
|
102
|
+
const db = new Database();
|
|
103
|
+
const provider = createReactNativeLevelDBProvider({
|
|
104
|
+
openFn: (name, createIfMissing, errorIfExists) => new LevelDB(name, createIfMissing, errorIfExists),
|
|
105
|
+
WriteBatch: LevelDBWriteBatch,
|
|
106
|
+
});
|
|
107
|
+
const storeModule = new StoreModule(provider);
|
|
108
|
+
db.registerModule('store', storeModule);
|
|
109
|
+
|
|
110
|
+
await db.exec(`
|
|
111
|
+
create table users (id integer primary key, name text)
|
|
112
|
+
using store
|
|
113
|
+
`);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## API
|
|
117
|
+
|
|
118
|
+
### ReactNativeLevelDBStore
|
|
119
|
+
|
|
120
|
+
Low-level KVStore implementation:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { LevelDB, LevelDBWriteBatch } from 'rn-leveldb';
|
|
124
|
+
import { ReactNativeLevelDBStore } from '@quereus/plugin-react-native-leveldb';
|
|
125
|
+
|
|
126
|
+
// Open using the factory function
|
|
127
|
+
const openFn = (name, createIfMissing, errorIfExists) => new LevelDB(name, createIfMissing, errorIfExists);
|
|
128
|
+
const store = ReactNativeLevelDBStore.open(openFn, LevelDBWriteBatch, 'mystore');
|
|
129
|
+
|
|
130
|
+
await store.put(key, value);
|
|
131
|
+
const data = await store.get(key);
|
|
132
|
+
await store.delete(key);
|
|
133
|
+
|
|
134
|
+
// Range iteration
|
|
135
|
+
for await (const { key, value } of store.iterate({ gte: startKey, lt: endKey })) {
|
|
136
|
+
console.log(key, value);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Atomic batch writes (uses native LevelDB WriteBatch)
|
|
140
|
+
const batch = store.batch();
|
|
141
|
+
batch.put(key1, value1);
|
|
142
|
+
batch.put(key2, value2);
|
|
143
|
+
batch.delete(key3);
|
|
144
|
+
await batch.write();
|
|
145
|
+
|
|
146
|
+
await store.close();
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### ReactNativeLevelDBProvider
|
|
150
|
+
|
|
151
|
+
Factory for managing multiple stores:
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { LevelDB, LevelDBWriteBatch } from 'rn-leveldb';
|
|
155
|
+
import { createReactNativeLevelDBProvider } from '@quereus/plugin-react-native-leveldb';
|
|
156
|
+
|
|
157
|
+
const provider = createReactNativeLevelDBProvider({
|
|
158
|
+
openFn: (name, createIfMissing, errorIfExists) => new LevelDB(name, createIfMissing, errorIfExists),
|
|
159
|
+
WriteBatch: LevelDBWriteBatch,
|
|
160
|
+
databaseName: 'myapp',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const userStore = await provider.getStore('main', 'users');
|
|
164
|
+
const catalogStore = await provider.getCatalogStore();
|
|
165
|
+
|
|
166
|
+
await provider.closeStore('main', 'users');
|
|
167
|
+
await provider.closeAll();
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Configuration
|
|
171
|
+
|
|
172
|
+
### Plugin Settings
|
|
173
|
+
|
|
174
|
+
| Setting | Type | Default | Description |
|
|
175
|
+
|---------|------|---------|-------------|
|
|
176
|
+
| `openFn` | function | **required** | Factory function: `(name, createIfMissing, errorIfExists) => LevelDB` |
|
|
177
|
+
| `WriteBatch` | constructor | **required** | LevelDBWriteBatch constructor from rn-leveldb |
|
|
178
|
+
| `databaseName` | string | `'quereus'` | Base name prefix for all LevelDB databases |
|
|
179
|
+
| `createIfMissing` | boolean | `true` | Create databases if they don't exist |
|
|
180
|
+
| `moduleName` | string | `'store'` | Name to register the virtual table module under |
|
|
181
|
+
|
|
182
|
+
## Example with Transactions
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { LevelDB, LevelDBWriteBatch } from 'rn-leveldb';
|
|
186
|
+
import { Database, registerPlugin } from '@quereus/quereus';
|
|
187
|
+
import leveldbPlugin from '@quereus/plugin-react-native-leveldb/plugin';
|
|
188
|
+
|
|
189
|
+
const db = new Database();
|
|
190
|
+
await registerPlugin(db, leveldbPlugin, {
|
|
191
|
+
openFn: (name, createIfMissing, errorIfExists) => new LevelDB(name, createIfMissing, errorIfExists),
|
|
192
|
+
WriteBatch: LevelDBWriteBatch,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
await db.exec(`create table accounts (id integer primary key, balance real) using store`);
|
|
196
|
+
|
|
197
|
+
await db.exec('begin');
|
|
198
|
+
try {
|
|
199
|
+
await db.exec(`update accounts set balance = balance - 100 where id = 1`);
|
|
200
|
+
await db.exec(`update accounts set balance = balance + 100 where id = 2`);
|
|
201
|
+
await db.exec('commit');
|
|
202
|
+
} catch (e) {
|
|
203
|
+
await db.exec('rollback');
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Why LevelDB?
|
|
209
|
+
|
|
210
|
+
rn-leveldb provides significant performance advantages over other React Native storage options:
|
|
211
|
+
|
|
212
|
+
| Storage Solution | Operations/sec | Notes |
|
|
213
|
+
|------------------|----------------|-------|
|
|
214
|
+
| rn-leveldb | ~50,000 | Synchronous, blocking API |
|
|
215
|
+
| AsyncStorage | ~2,000 | JSON serialization overhead |
|
|
216
|
+
| react-native-sqlite-storage | ~5,000 | Full SQL parsing overhead |
|
|
217
|
+
|
|
218
|
+
LevelDB is ideal for Quereus because:
|
|
219
|
+
- **Sorted keys**: Natural fit for the StoreModule's index-organized storage
|
|
220
|
+
- **Binary support**: No JSON serialization needed for keys/values
|
|
221
|
+
- **Range scans**: Efficient ordered iteration for query execution
|
|
222
|
+
|
|
223
|
+
## Peer Dependencies
|
|
224
|
+
|
|
225
|
+
This plugin requires:
|
|
226
|
+
- `@quereus/quereus` ^0.24.0
|
|
227
|
+
- `@quereus/store` ^0.3.5
|
|
228
|
+
- `rn-leveldb` ^3.11.0
|
|
229
|
+
|
|
230
|
+
## Related Packages
|
|
231
|
+
|
|
232
|
+
- [`@quereus/store`](../quereus-store/) - Core storage module (StoreModule, StoreTable)
|
|
233
|
+
- [`@quereus/plugin-leveldb`](../quereus-plugin-leveldb/) - LevelDB plugin for Node.js
|
|
234
|
+
- [`@quereus/plugin-indexeddb`](../quereus-plugin-indexeddb/) - IndexedDB plugin for browsers
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
MIT
|
|
239
|
+
|
package/dist/src/plugin.d.ts
CHANGED
|
@@ -37,6 +37,12 @@ export interface ReactNativeLevelDBPluginConfig {
|
|
|
37
37
|
* @default 'store'
|
|
38
38
|
*/
|
|
39
39
|
moduleName?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Enable transaction isolation (read-your-own-writes, snapshot isolation).
|
|
42
|
+
* When true, wraps the store module with an isolation layer.
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
isolation?: boolean;
|
|
40
46
|
}
|
|
41
47
|
/**
|
|
42
48
|
* Register the React Native LevelDB plugin with a database.
|
|
@@ -62,7 +68,7 @@ export interface ReactNativeLevelDBPluginConfig {
|
|
|
62
68
|
export default function register(_db: Database, config?: Record<string, SqlValue>): {
|
|
63
69
|
vtables: {
|
|
64
70
|
name: string;
|
|
65
|
-
module: StoreModule;
|
|
71
|
+
module: import("@quereus/isolation").IsolationModule | StoreModule;
|
|
66
72
|
}[];
|
|
67
73
|
};
|
|
68
74
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/src/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAA6B,MAAM,gBAAgB,CAAC;AAExE,OAAO,KAAK,EAAE,aAAa,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAgD9E;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC9C;;;;OAIG;IACH,MAAM,EAAE,aAAa,CAAC;IAEtB;;;OAGG;IACH,UAAU,EAAE,4BAA4B,CAAC;IAEzC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC/B,GAAG,EAAE,QAAQ,EACb,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAM;;;;;EA+CrC"}
|
package/dist/src/plugin.js
CHANGED
|
@@ -4,8 +4,41 @@
|
|
|
4
4
|
* Registers a StoreModule backed by LevelDB for React Native mobile environments.
|
|
5
5
|
* Uses rn-leveldb for native LevelDB bindings.
|
|
6
6
|
*/
|
|
7
|
-
import { StoreModule } from '@quereus/store';
|
|
7
|
+
import { StoreModule, createIsolatedStoreModule } from '@quereus/store';
|
|
8
8
|
import { ReactNativeLevelDBProvider } from './provider.js';
|
|
9
|
+
/**
|
|
10
|
+
* Check for required React Native polyfills and throw a helpful error if any are missing.
|
|
11
|
+
*/
|
|
12
|
+
function checkRequiredPolyfills() {
|
|
13
|
+
const missing = [];
|
|
14
|
+
// Check for structuredClone
|
|
15
|
+
if (typeof structuredClone === 'undefined') {
|
|
16
|
+
missing.push('structuredClone (used internally by Quereus)\n' +
|
|
17
|
+
' Install: npm install core-js\n' +
|
|
18
|
+
' Import: import \'core-js/features/structured-clone\';');
|
|
19
|
+
}
|
|
20
|
+
// Check for TextEncoder/TextDecoder
|
|
21
|
+
if (typeof TextEncoder === 'undefined' || typeof TextDecoder === 'undefined') {
|
|
22
|
+
missing.push('TextEncoder/TextDecoder (used by store plugins for binary data)\n' +
|
|
23
|
+
' Install: npm install text-encoding\n' +
|
|
24
|
+
' Import: import \'text-encoding\';');
|
|
25
|
+
}
|
|
26
|
+
// Check for Symbol.asyncIterator
|
|
27
|
+
if (typeof Symbol.asyncIterator === 'undefined') {
|
|
28
|
+
missing.push('Symbol.asyncIterator (required for async-iterable support)\n' +
|
|
29
|
+
' Quereus uses async generators and for-await-of loops extensively.\n' +
|
|
30
|
+
' While Hermes has special handling for AsyncGenerator objects, the symbol must exist.\n' +
|
|
31
|
+
' Add to your app entry point:\n' +
|
|
32
|
+
' if (typeof Symbol.asyncIterator === \'undefined\') {\n' +
|
|
33
|
+
' (Symbol as any).asyncIterator = Symbol.for(\'Symbol.asyncIterator\');\n' +
|
|
34
|
+
' }');
|
|
35
|
+
}
|
|
36
|
+
if (missing.length > 0) {
|
|
37
|
+
throw new Error('@quereus/plugin-react-native-leveldb requires the following polyfills:\n\n' +
|
|
38
|
+
missing.map((msg, i) => `${i + 1}. ${msg}`).join('\n\n') +
|
|
39
|
+
'\n\nFor more details, see: https://github.com/yourorg/quereus/tree/main/packages/quereus-plugin-react-native-leveldb#required-polyfills');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
9
42
|
/**
|
|
10
43
|
* Register the React Native LevelDB plugin with a database.
|
|
11
44
|
*
|
|
@@ -28,6 +61,8 @@ import { ReactNativeLevelDBProvider } from './provider.js';
|
|
|
28
61
|
* ```
|
|
29
62
|
*/
|
|
30
63
|
export default function register(_db, config = {}) {
|
|
64
|
+
// Check for required polyfills first
|
|
65
|
+
checkRequiredPolyfills();
|
|
31
66
|
// The LevelDB open function must be provided
|
|
32
67
|
const openFn = config.openFn;
|
|
33
68
|
if (!openFn) {
|
|
@@ -43,13 +78,16 @@ export default function register(_db, config = {}) {
|
|
|
43
78
|
const databaseName = config.databaseName ?? 'quereus';
|
|
44
79
|
const createIfMissing = config.createIfMissing !== false;
|
|
45
80
|
const moduleName = config.moduleName ?? 'store';
|
|
81
|
+
const isolation = config.isolation ?? true;
|
|
46
82
|
const provider = new ReactNativeLevelDBProvider({
|
|
47
83
|
openFn,
|
|
48
84
|
WriteBatch,
|
|
49
85
|
databaseName,
|
|
50
86
|
createIfMissing,
|
|
51
87
|
});
|
|
52
|
-
const storeModule =
|
|
88
|
+
const storeModule = isolation
|
|
89
|
+
? createIsolatedStoreModule({ provider })
|
|
90
|
+
: new StoreModule(provider);
|
|
53
91
|
return {
|
|
54
92
|
vtables: [
|
|
55
93
|
{
|
package/dist/src/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAG3D;;GAEG;AACH,SAAS,sBAAsB;IAC9B,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,4BAA4B;IAC5B,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE,CAAC;QAC5C,OAAO,CAAC,IAAI,CACX,gDAAgD;YAChD,kCAAkC;YAClC,yDAAyD,CACzD,CAAC;IACH,CAAC;IAED,oCAAoC;IACpC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE,CAAC;QAC9E,OAAO,CAAC,IAAI,CACX,mEAAmE;YACnE,wCAAwC;YACxC,qCAAqC,CACrC,CAAC;IACH,CAAC;IAED,iCAAiC;IACjC,IAAI,OAAO,MAAM,CAAC,aAAa,KAAK,WAAW,EAAE,CAAC;QACjD,OAAO,CAAC,IAAI,CACX,8DAA8D;YAC9D,uEAAuE;YACvE,0FAA0F;YAC1F,kCAAkC;YAClC,0DAA0D;YAC1D,6EAA6E;YAC7E,KAAK,CACL,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACd,4EAA4E;YAC5E,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;YACxD,yIAAyI,CACzI,CAAC;IACH,CAAC;AACF,CAAC;AA6CD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC/B,GAAa,EACb,SAAmC,EAAE;IAErC,qCAAqC;IACrC,sBAAsB,EAAE,CAAC;IAEzB,6CAA6C;IAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAkC,CAAC;IACzD,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACd,oEAAoE;YACpE,wIAAwI,CACxI,CAAC;IACH,CAAC;IAED,8CAA8C;IAC9C,MAAM,UAAU,GAAG,MAAM,CAAC,UAAqD,CAAC;IAChF,IAAI,CAAC,UAAU,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACd,uEAAuE;YACvE,uEAAuE,CACvE,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAI,MAAM,CAAC,YAAuB,IAAI,SAAS,CAAC;IAClE,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,KAAK,KAAK,CAAC;IACzD,MAAM,UAAU,GAAI,MAAM,CAAC,UAAqB,IAAI,OAAO,CAAC;IAC5D,MAAM,SAAS,GAAI,MAAM,CAAC,SAAqB,IAAI,IAAI,CAAC;IAExD,MAAM,QAAQ,GAAG,IAAI,0BAA0B,CAAC;QAC/C,MAAM;QACN,UAAU;QACV,YAAY;QACZ,eAAe;KACf,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,SAAS;QAC5B,CAAC,CAAC,yBAAyB,CAAC,EAAE,QAAQ,EAAE,CAAC;QACzC,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;IAE7B,OAAO;QACN,OAAO,EAAE;YACR;gBACC,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,WAAW;aACnB;SACD;KACD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quereus/plugin-react-native-leveldb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native LevelDB storage plugin for Quereus - mobile persistent storage",
|
|
6
6
|
"keywords": [
|
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@quereus/
|
|
45
|
-
"@quereus/
|
|
44
|
+
"@quereus/isolation": "^0.2.0",
|
|
45
|
+
"@quereus/quereus": "^0.13.0",
|
|
46
|
+
"@quereus/store": "^0.6.0",
|
|
46
47
|
"rn-leveldb": "^3.11.0"
|
|
47
48
|
},
|
|
48
49
|
"engines": {
|
|
@@ -68,6 +69,13 @@
|
|
|
68
69
|
"type": "string",
|
|
69
70
|
"default": "store",
|
|
70
71
|
"help": "Name to register the virtual table module under"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"key": "isolation",
|
|
75
|
+
"label": "Transaction Isolation",
|
|
76
|
+
"type": "boolean",
|
|
77
|
+
"default": true,
|
|
78
|
+
"help": "Enable transaction isolation (read-your-own-writes, snapshot isolation)"
|
|
71
79
|
}
|
|
72
80
|
]
|
|
73
81
|
},
|
|
@@ -78,6 +86,7 @@
|
|
|
78
86
|
"test": "cd ../.. && node --import ./packages/quereus-plugin-react-native-leveldb/register.mjs node_modules/mocha/bin/mocha.js \"packages/quereus-plugin-react-native-leveldb/test/**/*.spec.ts\" --colors"
|
|
79
87
|
},
|
|
80
88
|
"devDependencies": {
|
|
89
|
+
"@quereus/isolation": "*",
|
|
81
90
|
"@quereus/quereus": "*",
|
|
82
91
|
"@quereus/store": "*",
|
|
83
92
|
"@types/chai": "^5.2.2",
|