@rocicorp/zero 0.24.2025090402 → 0.24.2025091200
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/out/{chunk-P6JME3HC.js → chunk-6XNI6IVJ.js} +233 -135
- package/out/chunk-6XNI6IVJ.js.map +7 -0
- package/out/chunk-ASRS2LFV.js +35 -0
- package/out/chunk-ASRS2LFV.js.map +7 -0
- package/out/{chunk-G442PJSB.js → chunk-K5ZSWG54.js} +343 -327
- package/out/chunk-K5ZSWG54.js.map +7 -0
- package/out/{chunk-4NLQ25GZ.js → chunk-KXV3BZ4U.js} +3 -3
- package/out/{inspector-4ALIZXAU.js → inspector-ZZSIUMBB.js} +36 -6
- package/out/inspector-ZZSIUMBB.js.map +7 -0
- package/out/react-native.js +276 -278
- package/out/react-native.js.map +4 -4
- package/out/react.js +98 -35
- package/out/react.js.map +2 -2
- package/out/replicache/src/connection-loop.d.ts.map +1 -1
- package/out/replicache/src/deleted-clients.d.ts +17 -10
- package/out/replicache/src/deleted-clients.d.ts.map +1 -1
- package/out/replicache/src/kv/expo-sqlite/store.d.ts +11 -0
- package/out/replicache/src/kv/expo-sqlite/store.d.ts.map +1 -0
- package/out/replicache/src/kv/idb-store.d.ts.map +1 -1
- package/out/replicache/src/kv/mem-store.d.ts.map +1 -1
- package/out/replicache/src/kv/op-sqlite/store.d.ts +14 -0
- package/out/replicache/src/kv/op-sqlite/store.d.ts.map +1 -0
- package/out/replicache/src/kv/op-sqlite/types.d.ts +13 -0
- package/out/replicache/src/kv/op-sqlite/types.d.ts.map +1 -0
- package/out/replicache/src/kv/read-impl.d.ts.map +1 -1
- package/out/replicache/src/kv/sqlite-store.d.ts +37 -63
- package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -1
- package/out/replicache/src/kv/throw-if-closed.d.ts +12 -0
- package/out/replicache/src/kv/throw-if-closed.d.ts.map +1 -0
- package/out/replicache/src/kv/write-impl-base.d.ts.map +1 -1
- package/out/replicache/src/kv/write-impl.d.ts.map +1 -1
- package/out/replicache/src/persist/client-gc.d.ts.map +1 -1
- package/out/replicache/src/persist/client-group-gc.d.ts +2 -3
- package/out/replicache/src/persist/client-group-gc.d.ts.map +1 -1
- package/out/replicache/src/persist/clients.d.ts +2 -1
- package/out/replicache/src/persist/clients.d.ts.map +1 -1
- package/out/replicache/src/persist/collect-idb-databases.d.ts.map +1 -1
- package/out/replicache/src/replicache-impl.d.ts.map +1 -1
- package/out/solid.js +65 -20
- package/out/solid.js.map +3 -3
- package/out/zero/package.json +1 -1
- package/out/zero/src/zero-cache-dev.js +4 -0
- package/out/zero/src/zero-cache-dev.js.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
- package/out/zero-cache/src/config/normalize.d.ts +1 -0
- package/out/zero-cache/src/config/normalize.d.ts.map +1 -1
- package/out/zero-cache/src/config/normalize.js +6 -0
- package/out/zero-cache/src/config/normalize.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +11 -0
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +53 -1
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/custom-queries/transform-query.d.ts.map +1 -1
- package/out/zero-cache/src/custom-queries/transform-query.js +4 -0
- package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
- package/out/zero-cache/src/server/anonymous-otel-start.d.ts +1 -0
- package/out/zero-cache/src/server/anonymous-otel-start.d.ts.map +1 -1
- package/out/zero-cache/src/server/anonymous-otel-start.js +41 -2
- package/out/zero-cache/src/server/anonymous-otel-start.js.map +1 -1
- package/out/zero-cache/src/server/inspector-delegate.d.ts +9 -0
- package/out/zero-cache/src/server/inspector-delegate.d.ts.map +1 -1
- package/out/zero-cache/src/server/inspector-delegate.js +18 -0
- package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
- package/out/zero-cache/src/server/otel-diag-logger.d.ts +16 -0
- package/out/zero-cache/src/server/otel-diag-logger.d.ts.map +1 -0
- package/out/zero-cache/src/server/otel-diag-logger.js +76 -0
- package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -0
- package/out/zero-cache/src/server/otel-start.d.ts.map +1 -1
- package/out/zero-cache/src/server/otel-start.js +13 -13
- package/out/zero-cache/src/server/otel-start.js.map +1 -1
- package/out/zero-cache/src/server/reaper.js +5 -1
- package/out/zero-cache/src/server/reaper.js.map +1 -1
- package/out/zero-cache/src/server/syncer.js +3 -3
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/services/analyze.d.ts +1 -1
- package/out/zero-cache/src/services/analyze.d.ts.map +1 -1
- package/out/zero-cache/src/services/analyze.js +6 -6
- package/out/zero-cache/src/services/analyze.js.map +1 -1
- package/out/zero-cache/src/services/heapz.d.ts +1 -1
- package/out/zero-cache/src/services/heapz.d.ts.map +1 -1
- package/out/zero-cache/src/services/heapz.js +2 -2
- package/out/zero-cache/src/services/heapz.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.d.ts +12 -4
- package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
- package/out/zero-cache/src/services/statz.d.ts +1 -1
- package/out/zero-cache/src/services/statz.d.ts.map +1 -1
- package/out/zero-cache/src/services/statz.js +3 -3
- package/out/zero-cache/src/services/statz.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts +7 -1
- package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-purger.js +17 -8
- package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +0 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js +6 -19
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts +0 -1
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js +19 -8
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +30 -7
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-client/src/client/active-clients-manager.d.ts +2 -1
- package/out/zero-client/src/client/active-clients-manager.d.ts.map +1 -1
- package/out/zero-client/src/client/delete-clients-manager.d.ts +3 -3
- package/out/zero-client/src/client/delete-clients-manager.d.ts.map +1 -1
- package/out/zero-client/src/client/inspector/inspector.d.ts.map +1 -1
- package/out/zero-client/src/client/query-manager.d.ts +2 -0
- package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.d.ts +2 -2
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-protocol/src/down.d.ts +5 -0
- package/out/zero-protocol/src/down.d.ts.map +1 -1
- package/out/zero-protocol/src/inspect-down.d.ts +17 -0
- package/out/zero-protocol/src/inspect-down.d.ts.map +1 -1
- package/out/zero-protocol/src/inspect-down.js +5 -1
- package/out/zero-protocol/src/inspect-down.js.map +1 -1
- package/out/zero-protocol/src/inspect-up.d.ts +39 -10
- package/out/zero-protocol/src/inspect-up.d.ts.map +1 -1
- package/out/zero-protocol/src/inspect-up.js +10 -3
- package/out/zero-protocol/src/inspect-up.js.map +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
- package/out/zero-protocol/src/protocol-version.js +2 -1
- package/out/zero-protocol/src/protocol-version.js.map +1 -1
- package/out/zero-protocol/src/up.d.ts +10 -1
- package/out/zero-protocol/src/up.d.ts.map +1 -1
- package/out/zero-react/src/use-query.d.ts +20 -3
- package/out/zero-react/src/use-query.d.ts.map +1 -1
- package/out/zero-react-native/src/mod.d.ts +2 -2
- package/out/zero-react-native/src/mod.d.ts.map +1 -1
- package/out/zero-solid/src/solid-view.d.ts +24 -5
- package/out/zero-solid/src/solid-view.d.ts.map +1 -1
- package/out/zero-solid/src/use-query.d.ts.map +1 -1
- package/out/zero.js +4 -4
- package/out/zql/src/ivm/array-view.d.ts +2 -1
- package/out/zql/src/ivm/array-view.d.ts.map +1 -1
- package/out/zql/src/ivm/array-view.js +16 -5
- package/out/zql/src/ivm/array-view.js.map +1 -1
- package/out/zql/src/ivm/view.d.ts +2 -1
- package/out/zql/src/ivm/view.d.ts.map +1 -1
- package/out/zql/src/query/query-delegate.d.ts +2 -1
- package/out/zql/src/query/query-delegate.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.js +17 -5
- package/out/zql/src/query/query-impl.js.map +1 -1
- package/out/zql/src/query/typed-view.d.ts +3 -2
- package/out/zql/src/query/typed-view.d.ts.map +1 -1
- package/out/{zero-cache/src/services/view-syncer → zqlite/src}/database-storage.d.ts +2 -2
- package/out/zqlite/src/database-storage.d.ts.map +1 -0
- package/out/{zero-cache/src/services/view-syncer → zqlite/src}/database-storage.js +1 -1
- package/out/zqlite/src/database-storage.js.map +1 -0
- package/package.json +1 -1
- package/out/chunk-G442PJSB.js.map +0 -7
- package/out/chunk-MKB4RXL3.js +0 -15
- package/out/chunk-MKB4RXL3.js.map +0 -7
- package/out/chunk-P6JME3HC.js.map +0 -7
- package/out/inspector-4ALIZXAU.js.map +0 -7
- package/out/replicache/src/expo/store.d.ts +0 -4
- package/out/replicache/src/expo/store.d.ts.map +0 -1
- package/out/zero-cache/src/services/view-syncer/database-storage.d.ts.map +0 -1
- package/out/zero-cache/src/services/view-syncer/database-storage.js.map +0 -1
- /package/out/{chunk-4NLQ25GZ.js.map → chunk-KXV3BZ4U.js.map} +0 -0
package/out/react-native.js
CHANGED
|
@@ -1,341 +1,339 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-
|
|
2
|
+
throwIfStoreClosed,
|
|
3
|
+
throwIfTransactionClosed
|
|
4
|
+
} from "./chunk-ASRS2LFV.js";
|
|
5
5
|
import {
|
|
6
6
|
deepFreeze
|
|
7
7
|
} from "./chunk-SGW2EIVJ.js";
|
|
8
8
|
import "./chunk-424PT5DM.js";
|
|
9
9
|
|
|
10
|
-
// ../replicache/src/expo/store.ts
|
|
10
|
+
// ../replicache/src/kv/expo-sqlite/store.ts
|
|
11
11
|
import {
|
|
12
12
|
deleteDatabaseSync,
|
|
13
13
|
openDatabaseSync
|
|
14
14
|
} from "expo-sqlite";
|
|
15
15
|
|
|
16
16
|
// ../replicache/src/kv/sqlite-store.ts
|
|
17
|
-
import {
|
|
18
|
-
var getTransactionPreparedStatements = (db) => ({
|
|
19
|
-
begin: db.prepare("BEGIN"),
|
|
20
|
-
beginImmediate: db.prepare("BEGIN IMMEDIATE"),
|
|
21
|
-
commit: db.prepare("COMMIT"),
|
|
22
|
-
rollback: db.prepare("ROLLBACK")
|
|
23
|
-
});
|
|
24
|
-
var getRWPreparedStatements = (db) => ({
|
|
25
|
-
get: db.prepare("SELECT value FROM entry WHERE key = ?"),
|
|
26
|
-
put: db.prepare("INSERT OR REPLACE INTO entry (key, value) VALUES (?, ?)"),
|
|
27
|
-
del: db.prepare("DELETE FROM entry WHERE key = ?")
|
|
28
|
-
});
|
|
29
|
-
var SQLiteReadConnectionManager = class {
|
|
30
|
-
#pool = [];
|
|
31
|
-
#nextIndex = 0;
|
|
32
|
-
#rwLock;
|
|
33
|
-
constructor(name, manager, rwLock, opts) {
|
|
34
|
-
if (opts.readPoolSize <= 1) {
|
|
35
|
-
throw new Error("readPoolSize must be greater than 1");
|
|
36
|
-
}
|
|
37
|
-
this.#rwLock = rwLock;
|
|
38
|
-
for (let i = 0; i < opts.readPoolSize; i++) {
|
|
39
|
-
const { preparedStatements } = manager.open(name, opts);
|
|
40
|
-
this.#pool.push({
|
|
41
|
-
lock: new Lock(),
|
|
42
|
-
preparedStatements
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Acquire a round-robin read connection from the pool.
|
|
48
|
-
*
|
|
49
|
-
* The returned `release` callback **must** be invoked once the caller is done
|
|
50
|
-
* using the prepared statements, otherwise other readers may be blocked
|
|
51
|
-
* indefinitely.
|
|
52
|
-
*/
|
|
53
|
-
async acquire() {
|
|
54
|
-
const slot = this.#nextIndex;
|
|
55
|
-
this.#nextIndex = (this.#nextIndex + 1) % this.#pool.length;
|
|
56
|
-
const entry = this.#pool[slot];
|
|
57
|
-
const releaseRWLock = await this.#rwLock.read();
|
|
58
|
-
const releaseLock = await entry.lock.lock();
|
|
59
|
-
return {
|
|
60
|
-
preparedStatements: entry.preparedStatements,
|
|
61
|
-
release: () => {
|
|
62
|
-
releaseRWLock();
|
|
63
|
-
releaseLock();
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
var SQLiteWriteConnectionManager = class {
|
|
69
|
-
#rwLock;
|
|
70
|
-
#preparedStatements;
|
|
71
|
-
constructor(name, manager, rwLock, opts) {
|
|
72
|
-
const { preparedStatements } = manager.open(name, opts);
|
|
73
|
-
this.#preparedStatements = preparedStatements;
|
|
74
|
-
this.#rwLock = rwLock;
|
|
75
|
-
}
|
|
76
|
-
async acquire() {
|
|
77
|
-
const release = await this.#rwLock.write();
|
|
78
|
-
return { preparedStatements: this.#preparedStatements, release };
|
|
79
|
-
}
|
|
80
|
-
};
|
|
17
|
+
import { RWLock } from "@rocicorp/lock";
|
|
81
18
|
var SQLiteStore = class {
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#writeConnectionManager;
|
|
85
|
-
#readConnectionManager;
|
|
86
|
-
#rwLock = new RWLock();
|
|
19
|
+
#filename;
|
|
20
|
+
#entry;
|
|
87
21
|
#closed = false;
|
|
88
|
-
constructor(name,
|
|
89
|
-
this.#
|
|
90
|
-
this.#
|
|
91
|
-
this.#writeConnectionManager = new SQLiteWriteConnectionManager(
|
|
92
|
-
name,
|
|
93
|
-
dbm,
|
|
94
|
-
this.#rwLock,
|
|
95
|
-
opts
|
|
96
|
-
);
|
|
97
|
-
this.#readConnectionManager = new SQLiteReadConnectionManager(
|
|
98
|
-
name,
|
|
99
|
-
dbm,
|
|
100
|
-
this.#rwLock,
|
|
101
|
-
opts
|
|
102
|
-
);
|
|
22
|
+
constructor(name, create, opts) {
|
|
23
|
+
this.#filename = safeFilename(name);
|
|
24
|
+
this.#entry = getOrCreateEntry(name, create, opts);
|
|
103
25
|
}
|
|
104
26
|
async read() {
|
|
105
|
-
|
|
106
|
-
|
|
27
|
+
throwIfStoreClosed(this);
|
|
28
|
+
const entry = this.#entry;
|
|
29
|
+
const { db, lock, preparedStatements } = entry;
|
|
30
|
+
const release = await lock.read();
|
|
31
|
+
if (entry.activeReaders === 0) {
|
|
32
|
+
db.execSync("BEGIN");
|
|
33
|
+
}
|
|
34
|
+
entry.activeReaders++;
|
|
35
|
+
return new SQLiteStoreRead(() => {
|
|
36
|
+
entry.activeReaders--;
|
|
37
|
+
if (entry.activeReaders === 0) {
|
|
38
|
+
db.execSync("COMMIT");
|
|
39
|
+
}
|
|
40
|
+
release();
|
|
41
|
+
}, preparedStatements);
|
|
107
42
|
}
|
|
108
43
|
async write() {
|
|
109
|
-
|
|
110
|
-
|
|
44
|
+
throwIfStoreClosed(this);
|
|
45
|
+
const { lock, db, preparedStatements } = this.#entry;
|
|
46
|
+
const release = await lock.write();
|
|
47
|
+
db.execSync("BEGIN IMMEDIATE");
|
|
48
|
+
return new SQLiteWrite(release, db, preparedStatements);
|
|
111
49
|
}
|
|
112
|
-
close() {
|
|
113
|
-
|
|
50
|
+
async close() {
|
|
51
|
+
if (this.#closed) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const { lock, db } = this.#entry;
|
|
55
|
+
const writeRelease = await lock.write();
|
|
56
|
+
decrementStoreRefCount(this.#filename, db);
|
|
114
57
|
this.#closed = true;
|
|
115
|
-
|
|
58
|
+
writeRelease();
|
|
116
59
|
}
|
|
117
60
|
get closed() {
|
|
118
61
|
return this.#closed;
|
|
119
62
|
}
|
|
120
63
|
};
|
|
121
|
-
|
|
122
|
-
|
|
64
|
+
function safeFilename(name) {
|
|
65
|
+
return name.replace(/[^a-zA-Z0-9]/g, "_");
|
|
66
|
+
}
|
|
67
|
+
function setupDatabase(delegate, opts) {
|
|
68
|
+
delegate.execSync(`PRAGMA busy_timeout = ${opts?.busyTimeout ?? 200}`);
|
|
69
|
+
delegate.execSync(`PRAGMA journal_mode = '${opts?.journalMode ?? "WAL"}'`);
|
|
70
|
+
delegate.execSync(`PRAGMA synchronous = '${opts?.synchronous ?? "NORMAL"}'`);
|
|
71
|
+
delegate.execSync(
|
|
72
|
+
`PRAGMA read_uncommitted = ${Boolean(opts?.readUncommitted)}`
|
|
73
|
+
);
|
|
74
|
+
delegate.execSync(`
|
|
75
|
+
CREATE TABLE IF NOT EXISTS entry (
|
|
76
|
+
key TEXT PRIMARY KEY,
|
|
77
|
+
value TEXT NOT NULL
|
|
78
|
+
) WITHOUT ROWID
|
|
79
|
+
`);
|
|
80
|
+
return {
|
|
81
|
+
has: delegate.prepare(`SELECT 1 FROM entry WHERE key = ? LIMIT 1`),
|
|
82
|
+
get: delegate.prepare("SELECT value FROM entry WHERE key = ?"),
|
|
83
|
+
put: delegate.prepare(
|
|
84
|
+
"INSERT OR REPLACE INTO entry (key, value) VALUES (?, ?)"
|
|
85
|
+
),
|
|
86
|
+
del: delegate.prepare("DELETE FROM entry WHERE key = ?")
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
var SQLiteStoreRead = class {
|
|
123
90
|
#release;
|
|
124
91
|
#closed = false;
|
|
125
|
-
|
|
126
|
-
|
|
92
|
+
#preparedStatements;
|
|
93
|
+
constructor(release, preparedStatements) {
|
|
127
94
|
this.#release = release;
|
|
95
|
+
this.#preparedStatements = preparedStatements;
|
|
128
96
|
}
|
|
129
|
-
has(key) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
get(key) {
|
|
134
|
-
const unsafeValue = this.#getSql(key);
|
|
135
|
-
if (unsafeValue === void 0) return promiseUndefined;
|
|
136
|
-
const parsedValue = JSON.parse(unsafeValue);
|
|
137
|
-
const frozenValue = deepFreeze(parsedValue);
|
|
138
|
-
return Promise.resolve(frozenValue);
|
|
97
|
+
async has(key) {
|
|
98
|
+
throwIfTransactionClosed(this);
|
|
99
|
+
const value = await this.#preparedStatements.has.firstValue([key]);
|
|
100
|
+
return value !== void 0;
|
|
139
101
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
102
|
+
async get(key) {
|
|
103
|
+
throwIfTransactionClosed(this);
|
|
104
|
+
const value = await this.#preparedStatements.get.firstValue([key]);
|
|
105
|
+
if (!value) {
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
const parsedValue = JSON.parse(value);
|
|
109
|
+
return deepFreeze(parsedValue);
|
|
144
110
|
}
|
|
145
|
-
|
|
146
|
-
this.#closed
|
|
147
|
-
|
|
111
|
+
release() {
|
|
112
|
+
if (!this.#closed) {
|
|
113
|
+
this.#closed = true;
|
|
114
|
+
this.#release();
|
|
115
|
+
}
|
|
148
116
|
}
|
|
149
117
|
get closed() {
|
|
150
118
|
return this.#closed;
|
|
151
119
|
}
|
|
152
120
|
};
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
121
|
+
var SQLiteWrite = class {
|
|
122
|
+
#release;
|
|
123
|
+
#dbDelegate;
|
|
124
|
+
#preparedStatements;
|
|
125
|
+
#committed = false;
|
|
126
|
+
#closed = false;
|
|
127
|
+
constructor(release, dbDelegate, preparedStatements) {
|
|
128
|
+
this.#release = release;
|
|
129
|
+
this.#dbDelegate = dbDelegate;
|
|
130
|
+
this.#preparedStatements = preparedStatements;
|
|
157
131
|
}
|
|
158
|
-
|
|
159
|
-
this
|
|
160
|
-
this.
|
|
132
|
+
async has(key) {
|
|
133
|
+
throwIfTransactionClosed(this);
|
|
134
|
+
const value = await this.#preparedStatements.has.firstValue([key]);
|
|
135
|
+
return value !== void 0;
|
|
161
136
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
137
|
+
async get(key) {
|
|
138
|
+
throwIfTransactionClosed(this);
|
|
139
|
+
const value = await this.#preparedStatements.get.firstValue([key]);
|
|
140
|
+
if (!value) {
|
|
141
|
+
return void 0;
|
|
142
|
+
}
|
|
143
|
+
const parsedValue = JSON.parse(value);
|
|
144
|
+
return deepFreeze(parsedValue);
|
|
168
145
|
}
|
|
169
|
-
put(key, value) {
|
|
170
|
-
this
|
|
171
|
-
|
|
146
|
+
async put(key, value) {
|
|
147
|
+
throwIfTransactionClosed(this);
|
|
148
|
+
await this.#preparedStatements.put.exec([key, JSON.stringify(value)]);
|
|
172
149
|
}
|
|
173
|
-
del(key) {
|
|
174
|
-
this
|
|
175
|
-
|
|
150
|
+
async del(key) {
|
|
151
|
+
throwIfTransactionClosed(this);
|
|
152
|
+
await this.#preparedStatements.del.exec([key]);
|
|
176
153
|
}
|
|
177
|
-
|
|
178
|
-
|
|
154
|
+
// eslint-disable-next-line require-await
|
|
155
|
+
async commit() {
|
|
156
|
+
throwIfTransactionClosed(this);
|
|
157
|
+
this.#dbDelegate.execSync("COMMIT");
|
|
179
158
|
this.#committed = true;
|
|
180
|
-
return promiseVoid;
|
|
181
159
|
}
|
|
182
160
|
release() {
|
|
183
|
-
if (!this.#
|
|
184
|
-
this
|
|
161
|
+
if (!this.#closed) {
|
|
162
|
+
this.#closed = true;
|
|
163
|
+
if (!this.#committed) {
|
|
164
|
+
this.#dbDelegate.execSync("ROLLBACK");
|
|
165
|
+
}
|
|
166
|
+
this.#release();
|
|
185
167
|
}
|
|
186
|
-
|
|
168
|
+
}
|
|
169
|
+
get closed() {
|
|
170
|
+
return this.#closed;
|
|
187
171
|
}
|
|
188
172
|
};
|
|
189
|
-
|
|
190
|
-
|
|
173
|
+
var stores = /* @__PURE__ */ new Map();
|
|
174
|
+
function getOrCreateEntry(name, create, opts) {
|
|
175
|
+
const filename = safeFilename(name);
|
|
176
|
+
const entry = stores.get(filename);
|
|
177
|
+
if (entry) {
|
|
178
|
+
entry.refCount++;
|
|
179
|
+
return entry;
|
|
180
|
+
}
|
|
181
|
+
const dbDelegate = create(filename, opts);
|
|
182
|
+
const preparedStatements = setupDatabase(dbDelegate, opts);
|
|
183
|
+
const lock = new RWLock();
|
|
184
|
+
const newEntry = {
|
|
185
|
+
lock,
|
|
186
|
+
db: dbDelegate,
|
|
187
|
+
refCount: 1,
|
|
188
|
+
activeReaders: 0,
|
|
189
|
+
preparedStatements
|
|
190
|
+
};
|
|
191
|
+
stores.set(filename, newEntry);
|
|
192
|
+
return newEntry;
|
|
191
193
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
clearAllStoresForTesting() {
|
|
201
|
-
for (const [name] of this.#dbInstances) {
|
|
202
|
-
this.destroy(name);
|
|
194
|
+
function decrementStoreRefCount(filename, dbDelegate) {
|
|
195
|
+
const entry = stores.get(filename);
|
|
196
|
+
if (entry) {
|
|
197
|
+
entry.refCount--;
|
|
198
|
+
if (entry.refCount <= 0) {
|
|
199
|
+
dbDelegate.close();
|
|
200
|
+
stores.delete(filename);
|
|
203
201
|
}
|
|
204
202
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const rwPreparedStatements = getRWPreparedStatements(newDb);
|
|
233
|
-
const preparedStatements = {
|
|
234
|
-
...txPreparedStatements,
|
|
235
|
-
...rwPreparedStatements
|
|
236
|
-
};
|
|
237
|
-
this.#dbInstances.set(name, {
|
|
238
|
-
instances: [
|
|
239
|
-
...dbInstance?.instances ?? [],
|
|
240
|
-
{ db: newDb, preparedStatements, state: OPEN }
|
|
241
|
-
]
|
|
242
|
-
});
|
|
243
|
-
return {
|
|
244
|
-
db: newDb,
|
|
245
|
-
preparedStatements
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
#closeDBInstance(name) {
|
|
249
|
-
const dbInstance = this.#dbInstances.get(name);
|
|
250
|
-
if (dbInstance) {
|
|
251
|
-
for (const instance of dbInstance.instances) {
|
|
252
|
-
if (instance.state === CLOSED) {
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
for (const stmt of Object.values(instance.preparedStatements)) {
|
|
256
|
-
stmt.finalize();
|
|
257
|
-
}
|
|
258
|
-
instance.db.close();
|
|
259
|
-
instance.state = CLOSED;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return dbInstance;
|
|
203
|
+
}
|
|
204
|
+
function dropStore(name, createDelegate) {
|
|
205
|
+
const filename = safeFilename(name);
|
|
206
|
+
const entry = stores.get(filename);
|
|
207
|
+
if (entry) {
|
|
208
|
+
entry.db.close();
|
|
209
|
+
stores.delete(filename);
|
|
210
|
+
}
|
|
211
|
+
const tempDelegate = createDelegate(filename);
|
|
212
|
+
tempDelegate.destroy();
|
|
213
|
+
return Promise.resolve();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ../replicache/src/kv/expo-sqlite/store.ts
|
|
217
|
+
function dropExpoSQLiteStore(name) {
|
|
218
|
+
return dropStore(name, (filename) => new ExpoSQLiteDatabase(filename));
|
|
219
|
+
}
|
|
220
|
+
function expoSQLiteStoreProvider(opts) {
|
|
221
|
+
return {
|
|
222
|
+
create: (name) => new SQLiteStore(name, (name2) => new ExpoSQLiteDatabase(name2), opts),
|
|
223
|
+
drop: dropExpoSQLiteStore
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
var ExpoSQLitePreparedStatement = class {
|
|
227
|
+
#statement;
|
|
228
|
+
constructor(statement) {
|
|
229
|
+
this.#statement = statement;
|
|
263
230
|
}
|
|
264
|
-
|
|
265
|
-
this.#
|
|
231
|
+
async firstValue(params) {
|
|
232
|
+
const result = await this.#statement.executeForRawResultAsync(params);
|
|
233
|
+
const row = await result.getFirstAsync();
|
|
234
|
+
return row === null ? void 0 : row[0];
|
|
266
235
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
dbInstance?.instances[0].db.destroy();
|
|
270
|
-
this.#dbInstances.delete(name);
|
|
236
|
+
async exec(params) {
|
|
237
|
+
await this.#statement.executeForRawResultAsync(params);
|
|
271
238
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
239
|
+
};
|
|
240
|
+
var ExpoSQLiteDatabase = class {
|
|
241
|
+
#db;
|
|
242
|
+
#filename;
|
|
243
|
+
#statements = /* @__PURE__ */ new Set();
|
|
244
|
+
constructor(filename) {
|
|
245
|
+
this.#filename = filename;
|
|
246
|
+
this.#db = openDatabaseSync(filename);
|
|
247
|
+
}
|
|
248
|
+
close() {
|
|
249
|
+
for (const stmt of this.#statements) {
|
|
250
|
+
stmt.finalizeSync();
|
|
282
251
|
}
|
|
252
|
+
this.#db.closeSync();
|
|
253
|
+
}
|
|
254
|
+
destroy() {
|
|
255
|
+
deleteDatabaseSync(this.#filename);
|
|
256
|
+
}
|
|
257
|
+
prepare(sql) {
|
|
258
|
+
const statement = this.#db.prepareSync(sql);
|
|
259
|
+
this.#statements.add(statement);
|
|
260
|
+
return new ExpoSQLitePreparedStatement(statement);
|
|
261
|
+
}
|
|
262
|
+
execSync(sql) {
|
|
263
|
+
this.#db.execSync(sql);
|
|
283
264
|
}
|
|
284
265
|
};
|
|
285
266
|
|
|
286
|
-
// ../replicache/src/
|
|
287
|
-
|
|
267
|
+
// ../replicache/src/kv/op-sqlite/types.ts
|
|
268
|
+
import { open as openDB } from "@op-engineering/op-sqlite";
|
|
269
|
+
var open = openDB;
|
|
270
|
+
|
|
271
|
+
// ../replicache/src/kv/op-sqlite/store.ts
|
|
272
|
+
function dropOpSQLiteStore(name) {
|
|
273
|
+
return dropStore(
|
|
274
|
+
name,
|
|
275
|
+
(filename, opts) => new OpSQLiteDatabase(filename, opts)
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
function opSQLiteStoreProvider(opts) {
|
|
288
279
|
return {
|
|
289
|
-
create: (name) =>
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (!closed) {
|
|
296
|
-
db.closeSync();
|
|
297
|
-
closed = true;
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
return {
|
|
301
|
-
close,
|
|
302
|
-
destroy() {
|
|
303
|
-
close();
|
|
304
|
-
deleteDatabaseSync(fileName);
|
|
305
|
-
},
|
|
306
|
-
prepare(sql) {
|
|
307
|
-
const stmt = db.prepareSync(sql);
|
|
308
|
-
return {
|
|
309
|
-
run: (...params) => {
|
|
310
|
-
stmt.executeSync(params);
|
|
311
|
-
},
|
|
312
|
-
all: (...params) => {
|
|
313
|
-
const result = stmt.executeSync(params);
|
|
314
|
-
return result.getAllSync();
|
|
315
|
-
},
|
|
316
|
-
finalize: () => stmt.finalizeSync()
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
return new SQLiteStore(name, expoDbManagerInstance, {
|
|
323
|
-
// we default to 3 read connections for mobile devices
|
|
324
|
-
readPoolSize: 3,
|
|
325
|
-
busyTimeout: 200,
|
|
326
|
-
synchronous: "NORMAL",
|
|
327
|
-
readUncommitted: false,
|
|
328
|
-
journalMode: "WAL",
|
|
329
|
-
...opts
|
|
330
|
-
});
|
|
331
|
-
},
|
|
332
|
-
drop: (name) => {
|
|
333
|
-
deleteDatabaseSync(safeFilename(name));
|
|
334
|
-
return Promise.resolve();
|
|
335
|
-
}
|
|
280
|
+
create: (name) => new SQLiteStore(
|
|
281
|
+
name,
|
|
282
|
+
(name2, options) => new OpSQLiteDatabase(name2, options),
|
|
283
|
+
opts
|
|
284
|
+
),
|
|
285
|
+
drop: dropOpSQLiteStore
|
|
336
286
|
};
|
|
337
287
|
}
|
|
288
|
+
var OpSQLitePreparedStatement = class {
|
|
289
|
+
#db;
|
|
290
|
+
#sql;
|
|
291
|
+
constructor(db, sql) {
|
|
292
|
+
this.#db = db;
|
|
293
|
+
this.#sql = sql;
|
|
294
|
+
}
|
|
295
|
+
async firstValue(params) {
|
|
296
|
+
const rows = await this.#db.executeRaw(this.#sql, params);
|
|
297
|
+
return rows[0]?.[0];
|
|
298
|
+
}
|
|
299
|
+
async exec(params) {
|
|
300
|
+
await this.#db.executeRaw(this.#sql, params);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
var OpSQLiteDatabase = class {
|
|
304
|
+
#db;
|
|
305
|
+
#filename;
|
|
306
|
+
constructor(filename, opts) {
|
|
307
|
+
this.#filename = filename;
|
|
308
|
+
const openOpts = { name: filename };
|
|
309
|
+
if (opts?.location) {
|
|
310
|
+
openOpts.location = opts.location;
|
|
311
|
+
}
|
|
312
|
+
if (opts?.encryptionKey) {
|
|
313
|
+
openOpts.encryptionKey = opts.encryptionKey;
|
|
314
|
+
}
|
|
315
|
+
this.#db = open(openOpts);
|
|
316
|
+
}
|
|
317
|
+
close() {
|
|
318
|
+
this.#db.close();
|
|
319
|
+
}
|
|
320
|
+
destroy() {
|
|
321
|
+
try {
|
|
322
|
+
const tempDb = open({ name: this.#filename });
|
|
323
|
+
tempDb.delete();
|
|
324
|
+
tempDb.close();
|
|
325
|
+
} catch (error) {
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
prepare(sql) {
|
|
329
|
+
return new OpSQLitePreparedStatement(this.#db, sql);
|
|
330
|
+
}
|
|
331
|
+
execSync(sql) {
|
|
332
|
+
this.#db.executeRawSync(sql, []);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
338
335
|
export {
|
|
339
|
-
expoSQLiteStoreProvider
|
|
336
|
+
expoSQLiteStoreProvider,
|
|
337
|
+
opSQLiteStoreProvider
|
|
340
338
|
};
|
|
341
339
|
//# sourceMappingURL=react-native.js.map
|