@rocicorp/zero 0.9.2024121900 → 0.9.2024122300
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-3L5FRWGX.js → chunk-NYJROCBH.js} +256 -252
- package/out/chunk-NYJROCBH.js.map +7 -0
- package/out/react.js +6 -2
- package/out/react.js.map +2 -2
- package/out/replicache/src/mod.d.ts +1 -0
- package/out/replicache/src/mod.d.ts.map +1 -1
- package/out/shared/src/hash.d.ts +4 -0
- package/out/shared/src/hash.d.ts.map +1 -0
- package/out/shared/src/hash.js +16 -0
- package/out/shared/src/hash.js.map +1 -0
- package/out/solid.js +1 -1
- package/out/zero/src/zero-cache-dev.js +1 -1
- package/out/zero/src/zero-cache-dev.js.map +1 -1
- package/out/zero-cache/src/db/migration.d.ts.map +1 -1
- package/out/zero-cache/src/db/migration.js +0 -1
- package/out/zero-cache/src/db/migration.js.map +1 -1
- package/out/zero-cache/src/server/life-cycle.d.ts +1 -0
- package/out/zero-cache/src/server/life-cycle.d.ts.map +1 -1
- package/out/zero-cache/src/server/life-cycle.js +15 -7
- package/out/zero-cache/src/server/life-cycle.js.map +1 -1
- package/out/zero-cache/src/server/main.d.ts.map +1 -1
- package/out/zero-cache/src/server/main.js +1 -0
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/multi/main.d.ts.map +1 -1
- package/out/zero-cache/src/server/multi/main.js +1 -0
- package/out/zero-cache/src/server/multi/main.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +1 -0
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +34 -2
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +7 -0
- package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/pg/change-source.js +1 -1
- package/out/zero-cache/src/services/change-streamer/pg/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/init.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/init.js +11 -2
- package/out/zero-cache/src/services/change-streamer/pg/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/dispatcher/sync-dispatcher.js +1 -1
- package/out/zero-cache/src/services/dispatcher/sync-dispatcher.js.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.d.ts +2 -2
- package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.js +5 -2
- package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
- package/out/zero-cache/src/services/replicator/replicator.js +1 -1
- package/out/zero-cache/src/services/replicator/replicator.js.map +1 -1
- package/out/zero-cache/src/services/running-state.d.ts.map +1 -1
- package/out/zero-cache/src/services/running-state.js +2 -6
- package/out/zero-cache/src/services/running-state.js.map +1 -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 +5 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +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 +5 -2
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/row-key.js +2 -2
- package/out/zero-cache/src/types/row-key.js.map +1 -1
- package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/workers/syncer.js +2 -2
- package/out/zero-cache/src/workers/syncer.js.map +1 -1
- package/out/zero-client/src/client/server-option.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.d.ts +5 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/mod.d.ts +1 -1
- package/out/zero-client/src/mod.d.ts.map +1 -1
- package/out/zero-protocol/src/ast-hash.js +1 -1
- package/out/zero-protocol/src/ast-hash.js.map +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts +1 -1
- package/out/zero-protocol/src/protocol-version.js +1 -1
- package/out/zero-react/src/use-query.d.ts.map +1 -1
- package/out/zero.js +1 -1
- package/package.json +3 -3
- package/out/chunk-3L5FRWGX.js.map +0 -7
- package/out/shared/src/h64-with-reverse.d.ts +0 -6
- package/out/shared/src/h64-with-reverse.d.ts.map +0 -1
- package/out/shared/src/h64-with-reverse.js +0 -13
- package/out/shared/src/h64-with-reverse.js.map +0 -1
- package/out/shared/src/reverse-string.d.ts +0 -2
- package/out/shared/src/reverse-string.d.ts.map +0 -1
- package/out/shared/src/reverse-string.js +0 -8
- package/out/shared/src/reverse-string.js.map +0 -1
- package/out/shared/src/xxhash.d.ts +0 -3
- package/out/shared/src/xxhash.d.ts.map +0 -1
- package/out/shared/src/xxhash.js +0 -4
- package/out/shared/src/xxhash.js.map +0 -1
|
@@ -1443,13 +1443,13 @@ var Chunk = class {
|
|
|
1443
1443
|
* chunk.
|
|
1444
1444
|
*/
|
|
1445
1445
|
meta;
|
|
1446
|
-
constructor(
|
|
1446
|
+
constructor(hash2, data, refs) {
|
|
1447
1447
|
assert(
|
|
1448
|
-
!refs.includes(
|
|
1448
|
+
!refs.includes(hash2),
|
|
1449
1449
|
"Chunk cannot reference itself"
|
|
1450
1450
|
);
|
|
1451
1451
|
assertDeepFrozen(data);
|
|
1452
|
-
this.hash =
|
|
1452
|
+
this.hash = hash2;
|
|
1453
1453
|
this.data = data;
|
|
1454
1454
|
this.meta = refs;
|
|
1455
1455
|
}
|
|
@@ -1466,8 +1466,8 @@ function assertRefs(v2) {
|
|
|
1466
1466
|
}
|
|
1467
1467
|
}
|
|
1468
1468
|
function createChunk(data, refs, chunkHasher) {
|
|
1469
|
-
const
|
|
1470
|
-
return new Chunk(
|
|
1469
|
+
const hash2 = chunkHasher();
|
|
1470
|
+
return new Chunk(hash2, data, refs);
|
|
1471
1471
|
}
|
|
1472
1472
|
function throwChunkHasher() {
|
|
1473
1473
|
throw new Error("unexpected call to compute chunk hash");
|
|
@@ -1755,7 +1755,7 @@ var RefCountUpdates = class {
|
|
|
1755
1755
|
await Promise.all(
|
|
1756
1756
|
Array.from(
|
|
1757
1757
|
this.#putChunks.values(),
|
|
1758
|
-
(
|
|
1758
|
+
(hash2) => this.#ensureRefCountLoaded(hash2)
|
|
1759
1759
|
)
|
|
1760
1760
|
);
|
|
1761
1761
|
if (this.#isLazyDelegate) {
|
|
@@ -1764,9 +1764,9 @@ var RefCountUpdates = class {
|
|
|
1764
1764
|
let refCountsUpdated;
|
|
1765
1765
|
do {
|
|
1766
1766
|
refCountsUpdated = false;
|
|
1767
|
-
for (const
|
|
1768
|
-
if (!this.#delegate.areRefsCounted(
|
|
1769
|
-
await this.#updateRefsCounts(
|
|
1767
|
+
for (const hash2 of this.#putChunks.values()) {
|
|
1768
|
+
if (!this.#delegate.areRefsCounted(hash2) && !this.#refsCounted.has(hash2) && this.#refCountUpdates.get(hash2) !== 0) {
|
|
1769
|
+
await this.#updateRefsCounts(hash2, 1);
|
|
1770
1770
|
refCountsUpdated = true;
|
|
1771
1771
|
break;
|
|
1772
1772
|
}
|
|
@@ -1777,54 +1777,54 @@ var RefCountUpdates = class {
|
|
|
1777
1777
|
await this.#changeRefCount(o, -1);
|
|
1778
1778
|
}
|
|
1779
1779
|
if (!isProd) {
|
|
1780
|
-
for (const [
|
|
1780
|
+
for (const [hash2, update] of this.#refCountUpdates) {
|
|
1781
1781
|
assert(
|
|
1782
1782
|
update >= 0,
|
|
1783
|
-
`ref count update must be non-negative. ${
|
|
1783
|
+
`ref count update must be non-negative. ${hash2}:${update}`
|
|
1784
1784
|
);
|
|
1785
1785
|
}
|
|
1786
1786
|
}
|
|
1787
1787
|
return this.#refCountUpdates;
|
|
1788
1788
|
}
|
|
1789
|
-
async #changeRefCount(
|
|
1790
|
-
await this.#ensureRefCountLoaded(
|
|
1791
|
-
if (this.#updateRefCount(
|
|
1792
|
-
await this.#updateRefsCounts(
|
|
1789
|
+
async #changeRefCount(hash2, delta) {
|
|
1790
|
+
await this.#ensureRefCountLoaded(hash2);
|
|
1791
|
+
if (this.#updateRefCount(hash2, delta)) {
|
|
1792
|
+
await this.#updateRefsCounts(hash2, delta);
|
|
1793
1793
|
}
|
|
1794
1794
|
}
|
|
1795
|
-
async #updateRefsCounts(
|
|
1796
|
-
if (
|
|
1795
|
+
async #updateRefsCounts(hash2, delta) {
|
|
1796
|
+
if (hash2 === emptyHash) {
|
|
1797
1797
|
return;
|
|
1798
1798
|
}
|
|
1799
|
-
const refs = await this.#delegate.getRefs(
|
|
1799
|
+
const refs = await this.#delegate.getRefs(hash2);
|
|
1800
1800
|
if (!isProd) {
|
|
1801
1801
|
assert(
|
|
1802
|
-
refs || this.#isLazyDelegate && !this.#putChunks.has(
|
|
1802
|
+
refs || this.#isLazyDelegate && !this.#putChunks.has(hash2),
|
|
1803
1803
|
"refs must be defined"
|
|
1804
1804
|
);
|
|
1805
1805
|
}
|
|
1806
1806
|
if (refs !== void 0) {
|
|
1807
|
-
this.#refsCounted?.add(
|
|
1807
|
+
this.#refsCounted?.add(hash2);
|
|
1808
1808
|
const ps = refs.map((ref) => this.#changeRefCount(ref, delta));
|
|
1809
1809
|
await Promise.all(ps);
|
|
1810
1810
|
}
|
|
1811
1811
|
}
|
|
1812
|
-
#ensureRefCountLoaded(
|
|
1813
|
-
let p = this.#loadedRefCountPromises.get(
|
|
1812
|
+
#ensureRefCountLoaded(hash2) {
|
|
1813
|
+
let p = this.#loadedRefCountPromises.get(hash2);
|
|
1814
1814
|
if (p === void 0) {
|
|
1815
1815
|
p = (async () => {
|
|
1816
|
-
const value = await this.#delegate.getRefCount(
|
|
1817
|
-
this.#refCountUpdates.set(
|
|
1816
|
+
const value = await this.#delegate.getRefCount(hash2) || 0;
|
|
1817
|
+
this.#refCountUpdates.set(hash2, value);
|
|
1818
1818
|
return value;
|
|
1819
1819
|
})();
|
|
1820
|
-
this.#loadedRefCountPromises.set(
|
|
1820
|
+
this.#loadedRefCountPromises.set(hash2, p);
|
|
1821
1821
|
}
|
|
1822
1822
|
return p;
|
|
1823
1823
|
}
|
|
1824
|
-
#updateRefCount(
|
|
1825
|
-
const oldCount = this.#refCountUpdates.get(
|
|
1824
|
+
#updateRefCount(hash2, delta) {
|
|
1825
|
+
const oldCount = this.#refCountUpdates.get(hash2);
|
|
1826
1826
|
assertNumber(oldCount);
|
|
1827
|
-
this.#refCountUpdates.set(
|
|
1827
|
+
this.#refCountUpdates.set(hash2, oldCount + delta);
|
|
1828
1828
|
return oldCount === 0 && delta === 1 || oldCount === 1 && delta === -1;
|
|
1829
1829
|
}
|
|
1830
1830
|
};
|
|
@@ -1833,22 +1833,22 @@ var RefCountUpdates = class {
|
|
|
1833
1833
|
var ChunkNotFoundError = class extends Error {
|
|
1834
1834
|
name = "ChunkNotFoundError";
|
|
1835
1835
|
hash;
|
|
1836
|
-
constructor(
|
|
1837
|
-
super(`Chunk not found ${
|
|
1838
|
-
this.hash =
|
|
1836
|
+
constructor(hash2) {
|
|
1837
|
+
super(`Chunk not found ${hash2}`);
|
|
1838
|
+
this.hash = hash2;
|
|
1839
1839
|
}
|
|
1840
1840
|
};
|
|
1841
|
-
async function mustGetChunk(store,
|
|
1842
|
-
const chunk = await store.getChunk(
|
|
1841
|
+
async function mustGetChunk(store, hash2) {
|
|
1842
|
+
const chunk = await store.getChunk(hash2);
|
|
1843
1843
|
if (chunk) {
|
|
1844
1844
|
return chunk;
|
|
1845
1845
|
}
|
|
1846
|
-
throw new ChunkNotFoundError(
|
|
1846
|
+
throw new ChunkNotFoundError(hash2);
|
|
1847
1847
|
}
|
|
1848
1848
|
async function mustGetHeadHash(name, store) {
|
|
1849
|
-
const
|
|
1850
|
-
assert(
|
|
1851
|
-
return
|
|
1849
|
+
const hash2 = await store.getHead(name);
|
|
1850
|
+
assert(hash2, `Missing head ${name}`);
|
|
1851
|
+
return hash2;
|
|
1852
1852
|
}
|
|
1853
1853
|
|
|
1854
1854
|
// ../replicache/src/dag/lazy-store.ts
|
|
@@ -2002,28 +2002,28 @@ var LazyRead = class {
|
|
|
2002
2002
|
this.#release = release;
|
|
2003
2003
|
this.assertValidHash = assertValidHash;
|
|
2004
2004
|
}
|
|
2005
|
-
isMemOnlyChunkHash(
|
|
2006
|
-
return this._memOnlyChunks.has(
|
|
2005
|
+
isMemOnlyChunkHash(hash2) {
|
|
2006
|
+
return this._memOnlyChunks.has(hash2);
|
|
2007
2007
|
}
|
|
2008
|
-
async hasChunk(
|
|
2009
|
-
return await this.getChunk(
|
|
2008
|
+
async hasChunk(hash2) {
|
|
2009
|
+
return await this.getChunk(hash2) !== void 0;
|
|
2010
2010
|
}
|
|
2011
|
-
async getChunk(
|
|
2012
|
-
const memOnlyChunk = this._memOnlyChunks.get(
|
|
2011
|
+
async getChunk(hash2) {
|
|
2012
|
+
const memOnlyChunk = this._memOnlyChunks.get(hash2);
|
|
2013
2013
|
if (memOnlyChunk !== void 0) {
|
|
2014
2014
|
return memOnlyChunk;
|
|
2015
2015
|
}
|
|
2016
|
-
let chunk = this._sourceChunksCache.get(
|
|
2016
|
+
let chunk = this._sourceChunksCache.get(hash2);
|
|
2017
2017
|
if (chunk === void 0) {
|
|
2018
|
-
chunk = await (await this._getSourceRead()).getChunk(
|
|
2018
|
+
chunk = await (await this._getSourceRead()).getChunk(hash2);
|
|
2019
2019
|
if (chunk !== void 0) {
|
|
2020
2020
|
this._sourceChunksCache.put(chunk);
|
|
2021
2021
|
}
|
|
2022
2022
|
}
|
|
2023
2023
|
return chunk;
|
|
2024
2024
|
}
|
|
2025
|
-
mustGetChunk(
|
|
2026
|
-
return mustGetChunk(this,
|
|
2025
|
+
mustGetChunk(hash2) {
|
|
2026
|
+
return mustGetChunk(this, hash2);
|
|
2027
2027
|
}
|
|
2028
2028
|
getHead(name) {
|
|
2029
2029
|
return Promise.resolve(this._heads.get(name));
|
|
@@ -2073,54 +2073,54 @@ var LazyWrite = class extends LazyRead {
|
|
|
2073
2073
|
return chunk;
|
|
2074
2074
|
};
|
|
2075
2075
|
putChunk(c, size) {
|
|
2076
|
-
const { hash, meta } = c;
|
|
2077
|
-
this.assertValidHash(
|
|
2076
|
+
const { hash: hash2, meta } = c;
|
|
2077
|
+
this.assertValidHash(hash2);
|
|
2078
2078
|
if (meta.length > 0) {
|
|
2079
2079
|
for (const h of meta) {
|
|
2080
2080
|
this.assertValidHash(h);
|
|
2081
2081
|
}
|
|
2082
2082
|
}
|
|
2083
|
-
if (this.#createdChunks.has(
|
|
2084
|
-
this._pendingMemOnlyChunks.set(
|
|
2083
|
+
if (this.#createdChunks.has(hash2) || this.isMemOnlyChunkHash(hash2)) {
|
|
2084
|
+
this._pendingMemOnlyChunks.set(hash2, c);
|
|
2085
2085
|
} else {
|
|
2086
|
-
this._pendingCachedChunks.set(
|
|
2086
|
+
this._pendingCachedChunks.set(hash2, { chunk: c, size: size ?? -1 });
|
|
2087
2087
|
}
|
|
2088
2088
|
return promiseVoid;
|
|
2089
2089
|
}
|
|
2090
|
-
async setHead(name,
|
|
2091
|
-
await this.#setHead(name,
|
|
2090
|
+
async setHead(name, hash2) {
|
|
2091
|
+
await this.#setHead(name, hash2);
|
|
2092
2092
|
}
|
|
2093
2093
|
async removeHead(name) {
|
|
2094
2094
|
await this.#setHead(name, void 0);
|
|
2095
2095
|
}
|
|
2096
|
-
async #setHead(name,
|
|
2096
|
+
async #setHead(name, hash2) {
|
|
2097
2097
|
const oldHash = await this.getHead(name);
|
|
2098
2098
|
const v2 = this._pendingHeadChanges.get(name);
|
|
2099
2099
|
if (v2 === void 0) {
|
|
2100
|
-
this._pendingHeadChanges.set(name, { new:
|
|
2100
|
+
this._pendingHeadChanges.set(name, { new: hash2, old: oldHash });
|
|
2101
2101
|
} else {
|
|
2102
|
-
v2.new =
|
|
2102
|
+
v2.new = hash2;
|
|
2103
2103
|
}
|
|
2104
2104
|
}
|
|
2105
|
-
isMemOnlyChunkHash(
|
|
2106
|
-
return this._pendingMemOnlyChunks.has(
|
|
2105
|
+
isMemOnlyChunkHash(hash2) {
|
|
2106
|
+
return this._pendingMemOnlyChunks.has(hash2) || super.isMemOnlyChunkHash(hash2);
|
|
2107
2107
|
}
|
|
2108
|
-
async getChunk(
|
|
2109
|
-
const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(
|
|
2108
|
+
async getChunk(hash2) {
|
|
2109
|
+
const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash2);
|
|
2110
2110
|
if (pendingMemOnlyChunk !== void 0) {
|
|
2111
2111
|
return pendingMemOnlyChunk;
|
|
2112
2112
|
}
|
|
2113
|
-
const memOnlyChunk = this._memOnlyChunks.get(
|
|
2113
|
+
const memOnlyChunk = this._memOnlyChunks.get(hash2);
|
|
2114
2114
|
if (memOnlyChunk !== void 0) {
|
|
2115
2115
|
return memOnlyChunk;
|
|
2116
2116
|
}
|
|
2117
|
-
const pendingCachedChunk = this._pendingCachedChunks.get(
|
|
2117
|
+
const pendingCachedChunk = this._pendingCachedChunks.get(hash2);
|
|
2118
2118
|
if (pendingCachedChunk !== void 0) {
|
|
2119
2119
|
return pendingCachedChunk.chunk;
|
|
2120
2120
|
}
|
|
2121
|
-
let chunk = this._sourceChunksCache.get(
|
|
2121
|
+
let chunk = this._sourceChunksCache.get(hash2);
|
|
2122
2122
|
if (chunk === void 0) {
|
|
2123
|
-
chunk = await (await this._getSourceRead()).getChunk(
|
|
2123
|
+
chunk = await (await this._getSourceRead()).getChunk(hash2);
|
|
2124
2124
|
if (chunk !== void 0) {
|
|
2125
2125
|
this._pendingCachedChunks.set(chunk.hash, { chunk, size: -1 });
|
|
2126
2126
|
}
|
|
@@ -2146,21 +2146,21 @@ var LazyWrite = class extends LazyRead {
|
|
|
2146
2146
|
pendingChunks,
|
|
2147
2147
|
this
|
|
2148
2148
|
);
|
|
2149
|
-
for (const [
|
|
2150
|
-
if (this.isMemOnlyChunkHash(
|
|
2149
|
+
for (const [hash2, count] of refCountUpdates) {
|
|
2150
|
+
if (this.isMemOnlyChunkHash(hash2)) {
|
|
2151
2151
|
if (count === 0) {
|
|
2152
|
-
this.#refCounts.delete(
|
|
2153
|
-
this._memOnlyChunks.delete(
|
|
2154
|
-
this.#refs.delete(
|
|
2152
|
+
this.#refCounts.delete(hash2);
|
|
2153
|
+
this._memOnlyChunks.delete(hash2);
|
|
2154
|
+
this.#refs.delete(hash2);
|
|
2155
2155
|
} else {
|
|
2156
|
-
this.#refCounts.set(
|
|
2157
|
-
const chunk = this._pendingMemOnlyChunks.get(
|
|
2156
|
+
this.#refCounts.set(hash2, count);
|
|
2157
|
+
const chunk = this._pendingMemOnlyChunks.get(hash2);
|
|
2158
2158
|
if (chunk) {
|
|
2159
|
-
this.#refs.set(
|
|
2160
|
-
this._memOnlyChunks.set(
|
|
2159
|
+
this.#refs.set(hash2, chunk.meta);
|
|
2160
|
+
this._memOnlyChunks.set(hash2, chunk);
|
|
2161
2161
|
}
|
|
2162
2162
|
}
|
|
2163
|
-
refCountUpdates.delete(
|
|
2163
|
+
refCountUpdates.delete(hash2);
|
|
2164
2164
|
}
|
|
2165
2165
|
}
|
|
2166
2166
|
this._sourceChunksCache.updateForCommit(
|
|
@@ -2179,26 +2179,26 @@ var LazyWrite = class extends LazyRead {
|
|
|
2179
2179
|
this._pendingHeadChanges.clear();
|
|
2180
2180
|
this.release();
|
|
2181
2181
|
}
|
|
2182
|
-
getRefCount(
|
|
2183
|
-
return this.#refCounts.get(
|
|
2182
|
+
getRefCount(hash2) {
|
|
2183
|
+
return this.#refCounts.get(hash2);
|
|
2184
2184
|
}
|
|
2185
|
-
getRefs(
|
|
2186
|
-
const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(
|
|
2185
|
+
getRefs(hash2) {
|
|
2186
|
+
const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash2);
|
|
2187
2187
|
if (pendingMemOnlyChunk) {
|
|
2188
2188
|
return pendingMemOnlyChunk.meta;
|
|
2189
2189
|
}
|
|
2190
|
-
const memOnlyChunk = this._memOnlyChunks.get(
|
|
2190
|
+
const memOnlyChunk = this._memOnlyChunks.get(hash2);
|
|
2191
2191
|
if (memOnlyChunk) {
|
|
2192
2192
|
return memOnlyChunk.meta;
|
|
2193
2193
|
}
|
|
2194
|
-
const pendingCachedChunk = this._pendingCachedChunks.get(
|
|
2194
|
+
const pendingCachedChunk = this._pendingCachedChunks.get(hash2);
|
|
2195
2195
|
if (pendingCachedChunk !== void 0) {
|
|
2196
2196
|
return pendingCachedChunk.chunk.meta;
|
|
2197
2197
|
}
|
|
2198
|
-
return this.#refs.get(
|
|
2198
|
+
return this.#refs.get(hash2);
|
|
2199
2199
|
}
|
|
2200
|
-
areRefsCounted(
|
|
2201
|
-
return this.#refs.has(
|
|
2200
|
+
areRefsCounted(hash2) {
|
|
2201
|
+
return this.#refs.has(hash2);
|
|
2202
2202
|
}
|
|
2203
2203
|
chunksPersisted(chunkHashes) {
|
|
2204
2204
|
const chunksToCache = [];
|
|
@@ -2232,37 +2232,37 @@ var ChunksCache = class {
|
|
|
2232
2232
|
this.#refCounts = refCounts;
|
|
2233
2233
|
this.#refs = refs;
|
|
2234
2234
|
}
|
|
2235
|
-
get(
|
|
2236
|
-
const cacheEntry = this.cacheEntries.get(
|
|
2235
|
+
get(hash2) {
|
|
2236
|
+
const cacheEntry = this.cacheEntries.get(hash2);
|
|
2237
2237
|
if (cacheEntry) {
|
|
2238
|
-
this.cacheEntries.delete(
|
|
2239
|
-
this.cacheEntries.set(
|
|
2238
|
+
this.cacheEntries.delete(hash2);
|
|
2239
|
+
this.cacheEntries.set(hash2, cacheEntry);
|
|
2240
2240
|
}
|
|
2241
2241
|
return cacheEntry?.chunk;
|
|
2242
2242
|
}
|
|
2243
|
-
getWithoutUpdatingLRU(
|
|
2244
|
-
return this.cacheEntries.get(
|
|
2243
|
+
getWithoutUpdatingLRU(hash2) {
|
|
2244
|
+
return this.cacheEntries.get(hash2)?.chunk;
|
|
2245
2245
|
}
|
|
2246
2246
|
put(chunk) {
|
|
2247
|
-
const { hash } = chunk;
|
|
2248
|
-
const oldCacheEntry = this.cacheEntries.get(
|
|
2247
|
+
const { hash: hash2 } = chunk;
|
|
2248
|
+
const oldCacheEntry = this.cacheEntries.get(hash2);
|
|
2249
2249
|
if (oldCacheEntry) {
|
|
2250
|
-
this.cacheEntries.delete(
|
|
2251
|
-
this.cacheEntries.set(
|
|
2250
|
+
this.cacheEntries.delete(hash2);
|
|
2251
|
+
this.cacheEntries.set(hash2, oldCacheEntry);
|
|
2252
2252
|
return;
|
|
2253
2253
|
}
|
|
2254
|
-
const refCount = this.#refCounts.get(
|
|
2254
|
+
const refCount = this.#refCounts.get(hash2);
|
|
2255
2255
|
if (refCount === void 0 || refCount < 1) {
|
|
2256
2256
|
return;
|
|
2257
2257
|
}
|
|
2258
2258
|
if (!this.#cacheChunk(chunk)) {
|
|
2259
2259
|
return;
|
|
2260
2260
|
}
|
|
2261
|
-
if (!this.#refs.has(
|
|
2261
|
+
if (!this.#refs.has(hash2)) {
|
|
2262
2262
|
for (const refHash of chunk.meta) {
|
|
2263
2263
|
this.#refCounts.set(refHash, (this.#refCounts.get(refHash) || 0) + 1);
|
|
2264
2264
|
}
|
|
2265
|
-
this.#refs.set(
|
|
2265
|
+
this.#refs.set(hash2, chunk.meta);
|
|
2266
2266
|
}
|
|
2267
2267
|
this.#ensureCacheSizeLimit();
|
|
2268
2268
|
}
|
|
@@ -2287,40 +2287,40 @@ var ChunksCache = class {
|
|
|
2287
2287
|
return true;
|
|
2288
2288
|
}
|
|
2289
2289
|
#evict(cacheEntry) {
|
|
2290
|
-
const { hash } = cacheEntry.chunk;
|
|
2290
|
+
const { hash: hash2 } = cacheEntry.chunk;
|
|
2291
2291
|
this.#size -= cacheEntry.size;
|
|
2292
|
-
this.cacheEntries.delete(
|
|
2292
|
+
this.cacheEntries.delete(hash2);
|
|
2293
2293
|
}
|
|
2294
|
-
#deleteEntryByHash(
|
|
2295
|
-
this.#refCounts.delete(
|
|
2296
|
-
this.#refs.delete(
|
|
2297
|
-
const cacheEntry = this.cacheEntries.get(
|
|
2294
|
+
#deleteEntryByHash(hash2) {
|
|
2295
|
+
this.#refCounts.delete(hash2);
|
|
2296
|
+
this.#refs.delete(hash2);
|
|
2297
|
+
const cacheEntry = this.cacheEntries.get(hash2);
|
|
2298
2298
|
if (cacheEntry) {
|
|
2299
2299
|
this.#size -= cacheEntry.size;
|
|
2300
|
-
this.cacheEntries.delete(
|
|
2300
|
+
this.cacheEntries.delete(hash2);
|
|
2301
2301
|
}
|
|
2302
2302
|
}
|
|
2303
2303
|
updateForCommit(chunksToPut, refCountUpdates) {
|
|
2304
|
-
for (const [
|
|
2304
|
+
for (const [hash2, count] of refCountUpdates) {
|
|
2305
2305
|
if (count === 0) {
|
|
2306
2306
|
if (!this.#evictsAndDeletesSuspended) {
|
|
2307
|
-
this.#deleteEntryByHash(
|
|
2307
|
+
this.#deleteEntryByHash(hash2);
|
|
2308
2308
|
} else {
|
|
2309
|
-
this.#refCounts.set(
|
|
2310
|
-
this.#suspendedDeletes.push(
|
|
2309
|
+
this.#refCounts.set(hash2, 0);
|
|
2310
|
+
this.#suspendedDeletes.push(hash2);
|
|
2311
2311
|
}
|
|
2312
2312
|
} else {
|
|
2313
|
-
this.#refCounts.set(
|
|
2314
|
-
const chunkAndSize = chunksToPut.get(
|
|
2313
|
+
this.#refCounts.set(hash2, count);
|
|
2314
|
+
const chunkAndSize = chunksToPut.get(hash2);
|
|
2315
2315
|
if (chunkAndSize) {
|
|
2316
2316
|
const { chunk, size } = chunkAndSize;
|
|
2317
|
-
const oldCacheEntry = this.cacheEntries.get(
|
|
2317
|
+
const oldCacheEntry = this.cacheEntries.get(hash2);
|
|
2318
2318
|
if (oldCacheEntry) {
|
|
2319
|
-
this.cacheEntries.delete(
|
|
2320
|
-
this.cacheEntries.set(
|
|
2319
|
+
this.cacheEntries.delete(hash2);
|
|
2320
|
+
this.cacheEntries.set(hash2, oldCacheEntry);
|
|
2321
2321
|
} else {
|
|
2322
2322
|
this.#cacheChunk(chunk, size !== -1 ? size : void 0);
|
|
2323
|
-
this.#refs.set(
|
|
2323
|
+
this.#refs.set(hash2, chunk.meta);
|
|
2324
2324
|
}
|
|
2325
2325
|
}
|
|
2326
2326
|
}
|
|
@@ -2339,9 +2339,9 @@ var ChunksCache = class {
|
|
|
2339
2339
|
return await fn();
|
|
2340
2340
|
} finally {
|
|
2341
2341
|
this.#evictsAndDeletesSuspended = false;
|
|
2342
|
-
for (const
|
|
2343
|
-
if (this.#refCounts.get(
|
|
2344
|
-
this.#deleteEntryByHash(
|
|
2342
|
+
for (const hash2 of this.#suspendedDeletes) {
|
|
2343
|
+
if (this.#refCounts.get(hash2) === 0) {
|
|
2344
|
+
this.#deleteEntryByHash(hash2);
|
|
2345
2345
|
}
|
|
2346
2346
|
}
|
|
2347
2347
|
this.#ensureCacheSizeLimit();
|
|
@@ -2350,14 +2350,14 @@ var ChunksCache = class {
|
|
|
2350
2350
|
};
|
|
2351
2351
|
|
|
2352
2352
|
// ../replicache/src/dag/key.ts
|
|
2353
|
-
function chunkDataKey(
|
|
2354
|
-
return `c/${
|
|
2353
|
+
function chunkDataKey(hash2) {
|
|
2354
|
+
return `c/${hash2}/d`;
|
|
2355
2355
|
}
|
|
2356
|
-
function chunkMetaKey(
|
|
2357
|
-
return `c/${
|
|
2356
|
+
function chunkMetaKey(hash2) {
|
|
2357
|
+
return `c/${hash2}/m`;
|
|
2358
2358
|
}
|
|
2359
|
-
function chunkRefCountKey(
|
|
2360
|
-
return `c/${
|
|
2359
|
+
function chunkRefCountKey(hash2) {
|
|
2360
|
+
return `c/${hash2}/r`;
|
|
2361
2361
|
}
|
|
2362
2362
|
function headKey(name) {
|
|
2363
2363
|
return `h/${name}`;
|
|
@@ -2394,15 +2394,15 @@ var ReadImpl3 = class {
|
|
|
2394
2394
|
this._tx = kv;
|
|
2395
2395
|
this.assertValidHash = assertValidHash;
|
|
2396
2396
|
}
|
|
2397
|
-
hasChunk(
|
|
2398
|
-
return this._tx.has(chunkDataKey(
|
|
2397
|
+
hasChunk(hash2) {
|
|
2398
|
+
return this._tx.has(chunkDataKey(hash2));
|
|
2399
2399
|
}
|
|
2400
|
-
async getChunk(
|
|
2401
|
-
const data = await this._tx.get(chunkDataKey(
|
|
2400
|
+
async getChunk(hash2) {
|
|
2401
|
+
const data = await this._tx.get(chunkDataKey(hash2));
|
|
2402
2402
|
if (data === void 0) {
|
|
2403
2403
|
return void 0;
|
|
2404
2404
|
}
|
|
2405
|
-
const refsVal = await this._tx.get(chunkMetaKey(
|
|
2405
|
+
const refsVal = await this._tx.get(chunkMetaKey(hash2));
|
|
2406
2406
|
let refs;
|
|
2407
2407
|
if (refsVal !== void 0) {
|
|
2408
2408
|
assertRefs(refsVal);
|
|
@@ -2410,10 +2410,10 @@ var ReadImpl3 = class {
|
|
|
2410
2410
|
} else {
|
|
2411
2411
|
refs = [];
|
|
2412
2412
|
}
|
|
2413
|
-
return new Chunk(
|
|
2413
|
+
return new Chunk(hash2, data, refs);
|
|
2414
2414
|
}
|
|
2415
|
-
mustGetChunk(
|
|
2416
|
-
return mustGetChunk(this,
|
|
2415
|
+
mustGetChunk(hash2) {
|
|
2416
|
+
return mustGetChunk(this, hash2);
|
|
2417
2417
|
}
|
|
2418
2418
|
async getHead(name) {
|
|
2419
2419
|
const data = await this._tx.get(headKey(name));
|
|
@@ -2443,41 +2443,41 @@ var WriteImpl3 = class extends ReadImpl3 {
|
|
|
2443
2443
|
return this._tx;
|
|
2444
2444
|
}
|
|
2445
2445
|
async putChunk(c) {
|
|
2446
|
-
const { hash, data, meta } = c;
|
|
2447
|
-
this.assertValidHash(
|
|
2448
|
-
const key = chunkDataKey(
|
|
2446
|
+
const { hash: hash2, data, meta } = c;
|
|
2447
|
+
this.assertValidHash(hash2);
|
|
2448
|
+
const key = chunkDataKey(hash2);
|
|
2449
2449
|
const p1 = this._tx.put(key, data);
|
|
2450
2450
|
let p2;
|
|
2451
2451
|
if (meta.length > 0) {
|
|
2452
2452
|
for (const h of meta) {
|
|
2453
2453
|
this.assertValidHash(h);
|
|
2454
2454
|
}
|
|
2455
|
-
p2 = this._tx.put(chunkMetaKey(
|
|
2455
|
+
p2 = this._tx.put(chunkMetaKey(hash2), meta);
|
|
2456
2456
|
}
|
|
2457
|
-
this.#putChunks.add(
|
|
2457
|
+
this.#putChunks.add(hash2);
|
|
2458
2458
|
await p1;
|
|
2459
2459
|
await p2;
|
|
2460
2460
|
}
|
|
2461
|
-
setHead(name,
|
|
2462
|
-
return this.#setHead(name,
|
|
2461
|
+
setHead(name, hash2) {
|
|
2462
|
+
return this.#setHead(name, hash2);
|
|
2463
2463
|
}
|
|
2464
2464
|
removeHead(name) {
|
|
2465
2465
|
return this.#setHead(name, void 0);
|
|
2466
2466
|
}
|
|
2467
|
-
async #setHead(name,
|
|
2467
|
+
async #setHead(name, hash2) {
|
|
2468
2468
|
const oldHash = await this.getHead(name);
|
|
2469
2469
|
const hk = headKey(name);
|
|
2470
2470
|
let p1;
|
|
2471
|
-
if (
|
|
2471
|
+
if (hash2 === void 0) {
|
|
2472
2472
|
p1 = this._tx.del(hk);
|
|
2473
2473
|
} else {
|
|
2474
|
-
p1 = this._tx.put(hk,
|
|
2474
|
+
p1 = this._tx.put(hk, hash2);
|
|
2475
2475
|
}
|
|
2476
2476
|
const v2 = this.#changedHeads.get(name);
|
|
2477
2477
|
if (v2 === void 0) {
|
|
2478
|
-
this.#changedHeads.set(name, { new:
|
|
2478
|
+
this.#changedHeads.set(name, { new: hash2, old: oldHash });
|
|
2479
2479
|
} else {
|
|
2480
|
-
v2.new =
|
|
2480
|
+
v2.new = hash2;
|
|
2481
2481
|
}
|
|
2482
2482
|
await p1;
|
|
2483
2483
|
}
|
|
@@ -2490,8 +2490,8 @@ var WriteImpl3 = class extends ReadImpl3 {
|
|
|
2490
2490
|
await this.#applyRefCountUpdates(refCountUpdates);
|
|
2491
2491
|
await this._tx.commit();
|
|
2492
2492
|
}
|
|
2493
|
-
async getRefCount(
|
|
2494
|
-
const value = await this._tx.get(chunkRefCountKey(
|
|
2493
|
+
async getRefCount(hash2) {
|
|
2494
|
+
const value = await this._tx.get(chunkRefCountKey(hash2));
|
|
2495
2495
|
if (value === void 0) {
|
|
2496
2496
|
return void 0;
|
|
2497
2497
|
}
|
|
@@ -2503,8 +2503,8 @@ var WriteImpl3 = class extends ReadImpl3 {
|
|
|
2503
2503
|
}
|
|
2504
2504
|
return value;
|
|
2505
2505
|
}
|
|
2506
|
-
async getRefs(
|
|
2507
|
-
const meta = await this._tx.get(chunkMetaKey(
|
|
2506
|
+
async getRefs(hash2) {
|
|
2507
|
+
const meta = await this._tx.get(chunkMetaKey(hash2));
|
|
2508
2508
|
if (meta === void 0) {
|
|
2509
2509
|
return [];
|
|
2510
2510
|
}
|
|
@@ -2513,23 +2513,23 @@ var WriteImpl3 = class extends ReadImpl3 {
|
|
|
2513
2513
|
}
|
|
2514
2514
|
async #applyRefCountUpdates(refCountCache) {
|
|
2515
2515
|
const ps = [];
|
|
2516
|
-
for (const [
|
|
2516
|
+
for (const [hash2, count] of refCountCache) {
|
|
2517
2517
|
if (count === 0) {
|
|
2518
|
-
ps.push(this.#removeAllRelatedKeys(
|
|
2518
|
+
ps.push(this.#removeAllRelatedKeys(hash2));
|
|
2519
2519
|
} else {
|
|
2520
|
-
const refCountKey = chunkRefCountKey(
|
|
2520
|
+
const refCountKey = chunkRefCountKey(hash2);
|
|
2521
2521
|
ps.push(this._tx.put(refCountKey, count));
|
|
2522
2522
|
}
|
|
2523
2523
|
}
|
|
2524
2524
|
await Promise.all(ps);
|
|
2525
2525
|
}
|
|
2526
|
-
async #removeAllRelatedKeys(
|
|
2526
|
+
async #removeAllRelatedKeys(hash2) {
|
|
2527
2527
|
await Promise.all([
|
|
2528
|
-
this._tx.del(chunkDataKey(
|
|
2529
|
-
this._tx.del(chunkMetaKey(
|
|
2530
|
-
this._tx.del(chunkRefCountKey(
|
|
2528
|
+
this._tx.del(chunkDataKey(hash2)),
|
|
2529
|
+
this._tx.del(chunkMetaKey(hash2)),
|
|
2530
|
+
this._tx.del(chunkRefCountKey(hash2))
|
|
2531
2531
|
]);
|
|
2532
|
-
this.#putChunks.delete(
|
|
2532
|
+
this.#putChunks.delete(hash2);
|
|
2533
2533
|
}
|
|
2534
2534
|
release() {
|
|
2535
2535
|
this._tx.release();
|
|
@@ -2638,15 +2638,15 @@ async function localMutationsGreaterThan(commit, mutationIDLimits, dagRead) {
|
|
|
2638
2638
|
return commits;
|
|
2639
2639
|
}
|
|
2640
2640
|
async function baseSnapshotFromHead(name, dagRead) {
|
|
2641
|
-
const
|
|
2642
|
-
assert(
|
|
2643
|
-
return baseSnapshotFromHash(
|
|
2641
|
+
const hash2 = await dagRead.getHead(name);
|
|
2642
|
+
assert(hash2, `Missing head ${name}`);
|
|
2643
|
+
return baseSnapshotFromHash(hash2, dagRead);
|
|
2644
2644
|
}
|
|
2645
|
-
async function baseSnapshotHashFromHash(
|
|
2646
|
-
return (await baseSnapshotFromHash(
|
|
2645
|
+
async function baseSnapshotHashFromHash(hash2, dagRead) {
|
|
2646
|
+
return (await baseSnapshotFromHash(hash2, dagRead)).chunk.hash;
|
|
2647
2647
|
}
|
|
2648
|
-
async function baseSnapshotFromHash(
|
|
2649
|
-
const commit = await commitFromHash(
|
|
2648
|
+
async function baseSnapshotFromHash(hash2, dagRead) {
|
|
2649
|
+
const commit = await commitFromHash(hash2, dagRead);
|
|
2650
2650
|
return baseSnapshotFromCommit(commit, dagRead);
|
|
2651
2651
|
}
|
|
2652
2652
|
async function baseSnapshotFromCommit(commit, dagRead) {
|
|
@@ -2690,13 +2690,13 @@ async function commitChain(fromCommitHash, dagRead) {
|
|
|
2690
2690
|
commits.push(commit);
|
|
2691
2691
|
return commits;
|
|
2692
2692
|
}
|
|
2693
|
-
async function commitFromHash(
|
|
2694
|
-
const chunk = await dagRead.mustGetChunk(
|
|
2693
|
+
async function commitFromHash(hash2, dagRead) {
|
|
2694
|
+
const chunk = await dagRead.mustGetChunk(hash2);
|
|
2695
2695
|
return fromChunk(chunk);
|
|
2696
2696
|
}
|
|
2697
2697
|
async function commitFromHead(name, dagRead) {
|
|
2698
|
-
const
|
|
2699
|
-
return commitFromHash(
|
|
2698
|
+
const hash2 = await mustGetHeadHash(name, dagRead);
|
|
2699
|
+
return commitFromHash(hash2, dagRead);
|
|
2700
2700
|
}
|
|
2701
2701
|
function assertIndexChangeMeta(v2) {
|
|
2702
2702
|
assertNumber(v2.lastMutationID);
|
|
@@ -2988,8 +2988,8 @@ function makeNodeChunkData(level, entries, formatVersion) {
|
|
|
2988
2988
|
formatVersion >= V7 ? entries : entries.map((e) => e.slice(0, 2))
|
|
2989
2989
|
]);
|
|
2990
2990
|
}
|
|
2991
|
-
async function findLeaf(key,
|
|
2992
|
-
const node = await source.getNode(
|
|
2991
|
+
async function findLeaf(key, hash2, source, expectedRootHash) {
|
|
2992
|
+
const node = await source.getNode(hash2);
|
|
2993
2993
|
if (expectedRootHash !== source.rootHash) {
|
|
2994
2994
|
return findLeaf(key, source.rootHash, source, source.rootHash);
|
|
2995
2995
|
}
|
|
@@ -3053,9 +3053,9 @@ var NodeImpl = class {
|
|
|
3053
3053
|
hash;
|
|
3054
3054
|
isMutable;
|
|
3055
3055
|
#childNodeSize = -1;
|
|
3056
|
-
constructor(entries,
|
|
3056
|
+
constructor(entries, hash2, isMutable) {
|
|
3057
3057
|
this.entries = entries;
|
|
3058
|
-
this.hash =
|
|
3058
|
+
this.hash = hash2;
|
|
3059
3059
|
this.isMutable = isMutable;
|
|
3060
3060
|
}
|
|
3061
3061
|
maxKey() {
|
|
@@ -3134,8 +3134,8 @@ function readonlySplice(array10, start, deleteCount, ...items) {
|
|
|
3134
3134
|
}
|
|
3135
3135
|
var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
|
|
3136
3136
|
level;
|
|
3137
|
-
constructor(entries,
|
|
3138
|
-
super(entries,
|
|
3137
|
+
constructor(entries, hash2, level, isMutable) {
|
|
3138
|
+
super(entries, hash2, isMutable);
|
|
3139
3139
|
this.level = level;
|
|
3140
3140
|
}
|
|
3141
3141
|
async set(key, value, entrySize, tree) {
|
|
@@ -3167,8 +3167,8 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
|
|
|
3167
3167
|
let startIndex;
|
|
3168
3168
|
let removeCount;
|
|
3169
3169
|
if (i > 0) {
|
|
3170
|
-
const
|
|
3171
|
-
const previousSibling = await tree.getNode(
|
|
3170
|
+
const hash2 = thisEntries[i - 1][1];
|
|
3171
|
+
const previousSibling = await tree.getNode(hash2);
|
|
3172
3172
|
values = joinIterables(
|
|
3173
3173
|
previousSibling.entries,
|
|
3174
3174
|
childNode.entries
|
|
@@ -3176,8 +3176,8 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
|
|
|
3176
3176
|
startIndex = i - 1;
|
|
3177
3177
|
removeCount = 2;
|
|
3178
3178
|
} else if (i < thisEntries.length - 1) {
|
|
3179
|
-
const
|
|
3180
|
-
const nextSibling = await tree.getNode(
|
|
3179
|
+
const hash2 = thisEntries[i + 1][1];
|
|
3180
|
+
const nextSibling = await tree.getNode(hash2);
|
|
3181
3181
|
values = joinIterables(
|
|
3182
3182
|
childNode.entries,
|
|
3183
3183
|
nextSibling.entries
|
|
@@ -3291,15 +3291,15 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
|
|
|
3291
3291
|
return new DataNodeImpl(entries, newRandomHash(), true);
|
|
3292
3292
|
}
|
|
3293
3293
|
};
|
|
3294
|
-
function newNodeImpl(entries,
|
|
3294
|
+
function newNodeImpl(entries, hash2, level, isMutable) {
|
|
3295
3295
|
if (level === 0) {
|
|
3296
3296
|
return new DataNodeImpl(
|
|
3297
3297
|
entries,
|
|
3298
|
-
|
|
3298
|
+
hash2,
|
|
3299
3299
|
isMutable
|
|
3300
3300
|
);
|
|
3301
3301
|
}
|
|
3302
|
-
return new InternalNodeImpl(entries,
|
|
3302
|
+
return new InternalNodeImpl(entries, hash2, level, isMutable);
|
|
3303
3303
|
}
|
|
3304
3304
|
function isDataNodeImpl(node) {
|
|
3305
3305
|
return node.level === 0;
|
|
@@ -3445,15 +3445,15 @@ var BTreeRead = class {
|
|
|
3445
3445
|
this.getEntrySize = getEntrySize;
|
|
3446
3446
|
this.chunkHeaderSize = chunkHeaderSize;
|
|
3447
3447
|
}
|
|
3448
|
-
async getNode(
|
|
3449
|
-
if (
|
|
3448
|
+
async getNode(hash2) {
|
|
3449
|
+
if (hash2 === emptyHash) {
|
|
3450
3450
|
return emptyDataNodeImpl;
|
|
3451
3451
|
}
|
|
3452
|
-
const cached = this._cache.get(
|
|
3452
|
+
const cached = this._cache.get(hash2);
|
|
3453
3453
|
if (cached) {
|
|
3454
3454
|
return cached;
|
|
3455
3455
|
}
|
|
3456
|
-
const chunk = await this._dagRead.mustGetChunk(
|
|
3456
|
+
const chunk = await this._dagRead.mustGetChunk(hash2);
|
|
3457
3457
|
const data = parseBTreeNode(
|
|
3458
3458
|
chunk.data,
|
|
3459
3459
|
this._formatVersion,
|
|
@@ -3461,11 +3461,11 @@ var BTreeRead = class {
|
|
|
3461
3461
|
);
|
|
3462
3462
|
const impl = newNodeImpl(
|
|
3463
3463
|
data[NODE_ENTRIES],
|
|
3464
|
-
|
|
3464
|
+
hash2,
|
|
3465
3465
|
data[NODE_LEVEL],
|
|
3466
3466
|
false
|
|
3467
3467
|
);
|
|
3468
|
-
this._cache.set(
|
|
3468
|
+
this._cache.set(hash2, impl);
|
|
3469
3469
|
return impl;
|
|
3470
3470
|
}
|
|
3471
3471
|
async get(key) {
|
|
@@ -3499,15 +3499,15 @@ var BTreeRead = class {
|
|
|
3499
3499
|
() => this.rootHash,
|
|
3500
3500
|
this.rootHash,
|
|
3501
3501
|
fromKey,
|
|
3502
|
-
async (
|
|
3503
|
-
const cached = await this.getNode(
|
|
3502
|
+
async (hash2) => {
|
|
3503
|
+
const cached = await this.getNode(hash2);
|
|
3504
3504
|
if (cached) {
|
|
3505
3505
|
return [
|
|
3506
3506
|
cached.level,
|
|
3507
3507
|
cached.isMutable ? cached.entries.slice() : cached.entries
|
|
3508
3508
|
];
|
|
3509
3509
|
}
|
|
3510
|
-
const chunk = await this._dagRead.mustGetChunk(
|
|
3510
|
+
const chunk = await this._dagRead.mustGetChunk(hash2);
|
|
3511
3511
|
return parseBTreeNode(
|
|
3512
3512
|
chunk.data,
|
|
3513
3513
|
this._formatVersion,
|
|
@@ -3631,11 +3631,11 @@ function* diffEntries(lastEntries, currentEntries) {
|
|
|
3631
3631
|
};
|
|
3632
3632
|
}
|
|
3633
3633
|
}
|
|
3634
|
-
async function* scanForHash(expectedRootHash, getRootHash,
|
|
3635
|
-
if (
|
|
3634
|
+
async function* scanForHash(expectedRootHash, getRootHash, hash2, fromKey, readNode) {
|
|
3635
|
+
if (hash2 === emptyHash) {
|
|
3636
3636
|
return;
|
|
3637
3637
|
}
|
|
3638
|
-
const data = await readNode(
|
|
3638
|
+
const data = await readNode(hash2);
|
|
3639
3639
|
const entries = data[NODE_ENTRIES];
|
|
3640
3640
|
let i = 0;
|
|
3641
3641
|
if (fromKey) {
|
|
@@ -4329,10 +4329,10 @@ var BTreeWrite = class extends BTreeRead {
|
|
|
4329
4329
|
});
|
|
4330
4330
|
}
|
|
4331
4331
|
};
|
|
4332
|
-
function gatherNewChunks(
|
|
4333
|
-
const node = modified.get(
|
|
4332
|
+
function gatherNewChunks(hash2, newChunks, createChunk2, modified, formatVersion) {
|
|
4333
|
+
const node = modified.get(hash2);
|
|
4334
4334
|
if (node === void 0) {
|
|
4335
|
-
return
|
|
4335
|
+
return hash2;
|
|
4336
4336
|
}
|
|
4337
4337
|
if (isDataNodeImpl(node)) {
|
|
4338
4338
|
const chunk2 = createChunk2(toChunkData(node, formatVersion), []);
|
|
@@ -5018,16 +5018,16 @@ function clientGroupMapToChunkData(clientGroups, dagWrite) {
|
|
|
5018
5018
|
}
|
|
5019
5019
|
return deepFreeze(chunkData);
|
|
5020
5020
|
}
|
|
5021
|
-
async function getClientGroupsAtHash(
|
|
5022
|
-
const chunk = await dagRead.getChunk(
|
|
5021
|
+
async function getClientGroupsAtHash(hash2, dagRead) {
|
|
5022
|
+
const chunk = await dagRead.getChunk(hash2);
|
|
5023
5023
|
return chunkDataToClientGroupMap(chunk?.data);
|
|
5024
5024
|
}
|
|
5025
5025
|
async function getClientGroups(dagRead) {
|
|
5026
|
-
const
|
|
5027
|
-
if (!
|
|
5026
|
+
const hash2 = await dagRead.getHead(CLIENT_GROUPS_HEAD_NAME);
|
|
5027
|
+
if (!hash2) {
|
|
5028
5028
|
return /* @__PURE__ */ new Map();
|
|
5029
5029
|
}
|
|
5030
|
-
return getClientGroupsAtHash(
|
|
5030
|
+
return getClientGroupsAtHash(hash2, dagRead);
|
|
5031
5031
|
}
|
|
5032
5032
|
async function setClientGroups(clientGroups, dagWrite) {
|
|
5033
5033
|
const currClientGroups = await getClientGroups(dagWrite);
|
|
@@ -5284,14 +5284,14 @@ function clientMapToChunkData(clients, dagWrite) {
|
|
|
5284
5284
|
return deepFreeze(Object.fromEntries(clients));
|
|
5285
5285
|
}
|
|
5286
5286
|
async function getClients(dagRead) {
|
|
5287
|
-
const
|
|
5288
|
-
return getClientsAtHash(
|
|
5287
|
+
const hash2 = await dagRead.getHead(CLIENTS_HEAD_NAME);
|
|
5288
|
+
return getClientsAtHash(hash2, dagRead);
|
|
5289
5289
|
}
|
|
5290
|
-
async function getClientsAtHash(
|
|
5291
|
-
if (!
|
|
5290
|
+
async function getClientsAtHash(hash2, dagRead) {
|
|
5291
|
+
if (!hash2) {
|
|
5292
5292
|
return /* @__PURE__ */ new Map();
|
|
5293
5293
|
}
|
|
5294
|
-
const chunk = await dagRead.getChunk(
|
|
5294
|
+
const chunk = await dagRead.getChunk(hash2);
|
|
5295
5295
|
return chunkDataToClientMap(chunk?.data);
|
|
5296
5296
|
}
|
|
5297
5297
|
var ClientStateNotFoundError = class extends Error {
|
|
@@ -5482,8 +5482,8 @@ function getRefsForClients(clients) {
|
|
|
5482
5482
|
const refs = /* @__PURE__ */ new Set();
|
|
5483
5483
|
for (const client of clients.values()) {
|
|
5484
5484
|
if (isClientV6(client)) {
|
|
5485
|
-
for (const
|
|
5486
|
-
refs.add(
|
|
5485
|
+
for (const hash2 of client.refreshHashes) {
|
|
5486
|
+
refs.add(hash2);
|
|
5487
5487
|
}
|
|
5488
5488
|
if (client.persistHash) {
|
|
5489
5489
|
refs.add(client.persistHash);
|
|
@@ -9683,9 +9683,17 @@ function filterFalse(conditions) {
|
|
|
9683
9683
|
// ../zql/src/query/query-impl.ts
|
|
9684
9684
|
import { resolver as resolver7 } from "@rocicorp/resolver";
|
|
9685
9685
|
|
|
9686
|
-
// ../shared/src/
|
|
9687
|
-
import
|
|
9688
|
-
var
|
|
9686
|
+
// ../shared/src/hash.ts
|
|
9687
|
+
import { xxHash32 } from "js-xxhash";
|
|
9688
|
+
var h64 = (s) => hash(s, 2);
|
|
9689
|
+
var h128 = (s) => hash(s, 4);
|
|
9690
|
+
function hash(str, words) {
|
|
9691
|
+
let hash2 = 0n;
|
|
9692
|
+
for (let i = 0; i < words; i++) {
|
|
9693
|
+
hash2 = (hash2 << 32n) + BigInt(xxHash32(str, i));
|
|
9694
|
+
}
|
|
9695
|
+
return hash2;
|
|
9696
|
+
}
|
|
9689
9697
|
|
|
9690
9698
|
// ../zero-protocol/src/ast.ts
|
|
9691
9699
|
import { compareUTF8 as compareUTF83 } from "compare-utf8";
|
|
@@ -9965,9 +9973,9 @@ function hashOfAST(ast) {
|
|
|
9965
9973
|
if (cached) {
|
|
9966
9974
|
return cached;
|
|
9967
9975
|
}
|
|
9968
|
-
const
|
|
9969
|
-
hashCache.set(normalized,
|
|
9970
|
-
return
|
|
9976
|
+
const hash2 = h64(JSON.stringify(normalized)).toString(36);
|
|
9977
|
+
hashCache.set(normalized, hash2);
|
|
9978
|
+
return hash2;
|
|
9971
9979
|
}
|
|
9972
9980
|
|
|
9973
9981
|
// ../zql/src/ivm/change.ts
|
|
@@ -11890,8 +11898,8 @@ var AbstractQuery = class {
|
|
|
11890
11898
|
hash() {
|
|
11891
11899
|
if (!this.#hash) {
|
|
11892
11900
|
const ast = this._completeAst();
|
|
11893
|
-
const
|
|
11894
|
-
this.#hash =
|
|
11901
|
+
const hash2 = hashOfAST(ast);
|
|
11902
|
+
this.#hash = hash2;
|
|
11895
11903
|
}
|
|
11896
11904
|
return this.#hash;
|
|
11897
11905
|
}
|
|
@@ -12742,7 +12750,7 @@ var upstreamSchema = valita_exports.union(
|
|
|
12742
12750
|
);
|
|
12743
12751
|
|
|
12744
12752
|
// ../zero-protocol/src/protocol-version.ts
|
|
12745
|
-
var PROTOCOL_VERSION =
|
|
12753
|
+
var PROTOCOL_VERSION = 3;
|
|
12746
12754
|
|
|
12747
12755
|
// ../zero-client/src/util/nanoid.ts
|
|
12748
12756
|
function nanoid(size = 21) {
|
|
@@ -14846,23 +14854,6 @@ var MemoryStorage = class {
|
|
|
14846
14854
|
}
|
|
14847
14855
|
};
|
|
14848
14856
|
|
|
14849
|
-
// ../shared/src/reverse-string.ts
|
|
14850
|
-
function reverseString(str) {
|
|
14851
|
-
let reversed = "";
|
|
14852
|
-
for (let i = str.length - 1; i >= 0; i--) {
|
|
14853
|
-
reversed += str[i];
|
|
14854
|
-
}
|
|
14855
|
-
return reversed;
|
|
14856
|
-
}
|
|
14857
|
-
|
|
14858
|
-
// ../shared/src/h64-with-reverse.ts
|
|
14859
|
-
function h64WithReverse(str) {
|
|
14860
|
-
const forward = h64(str);
|
|
14861
|
-
const backward = h64(reverseString(str));
|
|
14862
|
-
const full = (forward << 64n) + backward;
|
|
14863
|
-
return full.toString(36);
|
|
14864
|
-
}
|
|
14865
|
-
|
|
14866
14857
|
// ../zero-client/src/client/keys.ts
|
|
14867
14858
|
var CLIENTS_KEY_PREFIX = "c/";
|
|
14868
14859
|
var DESIRED_QUERIES_KEY_PREFIX = "d/";
|
|
@@ -14871,14 +14862,14 @@ var ENTITIES_KEY_PREFIX = "e/";
|
|
|
14871
14862
|
function toClientsKey(clientID) {
|
|
14872
14863
|
return CLIENTS_KEY_PREFIX + clientID;
|
|
14873
14864
|
}
|
|
14874
|
-
function toDesiredQueriesKey(clientID,
|
|
14875
|
-
return DESIRED_QUERIES_KEY_PREFIX + clientID + "/" +
|
|
14865
|
+
function toDesiredQueriesKey(clientID, hash2) {
|
|
14866
|
+
return DESIRED_QUERIES_KEY_PREFIX + clientID + "/" + hash2;
|
|
14876
14867
|
}
|
|
14877
14868
|
function desiredQueriesPrefixForClient(clientID) {
|
|
14878
14869
|
return DESIRED_QUERIES_KEY_PREFIX + clientID + "/";
|
|
14879
14870
|
}
|
|
14880
|
-
function toGotQueriesKey(
|
|
14881
|
-
return GOT_QUERIES_KEY_PREFIX +
|
|
14871
|
+
function toGotQueriesKey(hash2) {
|
|
14872
|
+
return GOT_QUERIES_KEY_PREFIX + hash2;
|
|
14882
14873
|
}
|
|
14883
14874
|
function toPrimaryKeyString(tableName, primaryKey, value) {
|
|
14884
14875
|
if (primaryKey.length === 1) {
|
|
@@ -14886,7 +14877,7 @@ function toPrimaryKeyString(tableName, primaryKey, value) {
|
|
|
14886
14877
|
}
|
|
14887
14878
|
const values = primaryKey.map((k) => parse(value[k], primaryKeyValueSchema));
|
|
14888
14879
|
const str = JSON.stringify(values);
|
|
14889
|
-
const idSegment =
|
|
14880
|
+
const idSegment = h128(str);
|
|
14890
14881
|
return ENTITIES_KEY_PREFIX + tableName + "/" + idSegment;
|
|
14891
14882
|
}
|
|
14892
14883
|
|
|
@@ -15454,7 +15445,7 @@ function makeMessage(message, context, logLevel) {
|
|
|
15454
15445
|
}
|
|
15455
15446
|
|
|
15456
15447
|
// ../zero-client/src/client/version.ts
|
|
15457
|
-
var version2 = "0.9.
|
|
15448
|
+
var version2 = "0.9.2024122300+b69fce";
|
|
15458
15449
|
|
|
15459
15450
|
// ../zero-client/src/client/log-options.ts
|
|
15460
15451
|
var LevelFilterLogSink = class {
|
|
@@ -15802,26 +15793,26 @@ var QueryManager = class {
|
|
|
15802
15793
|
existingQueryHashes.add(key.substring(prefix.length, key.length));
|
|
15803
15794
|
}
|
|
15804
15795
|
const patch = /* @__PURE__ */ new Map();
|
|
15805
|
-
for (const
|
|
15806
|
-
if (!this.#queries.has(
|
|
15807
|
-
patch.set(
|
|
15796
|
+
for (const hash2 of existingQueryHashes) {
|
|
15797
|
+
if (!this.#queries.has(hash2)) {
|
|
15798
|
+
patch.set(hash2, { op: "del", hash: hash2 });
|
|
15808
15799
|
}
|
|
15809
15800
|
}
|
|
15810
|
-
for (const [
|
|
15811
|
-
if (!existingQueryHashes.has(
|
|
15812
|
-
patch.set(
|
|
15801
|
+
for (const [hash2, { normalized }] of this.#queries) {
|
|
15802
|
+
if (!existingQueryHashes.has(hash2)) {
|
|
15803
|
+
patch.set(hash2, { op: "put", hash: hash2, ast: normalized });
|
|
15813
15804
|
}
|
|
15814
15805
|
}
|
|
15815
15806
|
if (lastPatch) {
|
|
15816
|
-
for (const [
|
|
15817
|
-
if (op === "put" && !patch.has(
|
|
15818
|
-
patch.set(
|
|
15807
|
+
for (const [hash2, { op }] of lastPatch) {
|
|
15808
|
+
if (op === "put" && !patch.has(hash2)) {
|
|
15809
|
+
patch.set(hash2, { op: "del", hash: hash2 });
|
|
15819
15810
|
}
|
|
15820
15811
|
}
|
|
15821
|
-
for (const [
|
|
15822
|
-
const lastPatchOp = lastPatch.get(
|
|
15812
|
+
for (const [hash2, { op }] of patch) {
|
|
15813
|
+
const lastPatchOp = lastPatch.get(hash2);
|
|
15823
15814
|
if (lastPatchOp && lastPatchOp.op === op) {
|
|
15824
|
-
patch.delete(
|
|
15815
|
+
patch.delete(hash2);
|
|
15825
15816
|
}
|
|
15826
15817
|
}
|
|
15827
15818
|
}
|
|
@@ -16045,6 +16036,13 @@ function validateServerParam(paramName, server) {
|
|
|
16045
16036
|
return urlString;
|
|
16046
16037
|
}
|
|
16047
16038
|
function getServer(server) {
|
|
16039
|
+
const WS = getBrowserGlobal("WebSocket");
|
|
16040
|
+
if (!WS) {
|
|
16041
|
+
console.warn(
|
|
16042
|
+
"Zero started in an unsupported environment, no data will be synced."
|
|
16043
|
+
);
|
|
16044
|
+
return null;
|
|
16045
|
+
}
|
|
16048
16046
|
if (server === void 0 || server === null) {
|
|
16049
16047
|
console.warn(
|
|
16050
16048
|
"Zero starting up with no server URL. This is supported for unit testing and prototyping, but no data will be synced."
|
|
@@ -16220,7 +16218,7 @@ function mergePokes(pokeBuffer, schema) {
|
|
|
16220
16218
|
...queriesPatch.map(
|
|
16221
16219
|
(op) => queryPatchOpToReplicachePatchOp(
|
|
16222
16220
|
op,
|
|
16223
|
-
(
|
|
16221
|
+
(hash2) => toDesiredQueriesKey(clientID, hash2)
|
|
16224
16222
|
)
|
|
16225
16223
|
)
|
|
16226
16224
|
);
|
|
@@ -16625,6 +16623,12 @@ var Zero = class {
|
|
|
16625
16623
|
}
|
|
16626
16624
|
return createLogOptions(options);
|
|
16627
16625
|
}
|
|
16626
|
+
/**
|
|
16627
|
+
* The server URL that this Zero instance is configured with.
|
|
16628
|
+
*/
|
|
16629
|
+
get server() {
|
|
16630
|
+
return this.#server;
|
|
16631
|
+
}
|
|
16628
16632
|
/**
|
|
16629
16633
|
* The name of the IndexedDB database in which the data of this
|
|
16630
16634
|
* instance of Zero is stored.
|
|
@@ -17472,4 +17476,4 @@ export {
|
|
|
17472
17476
|
escapeLike,
|
|
17473
17477
|
Zero
|
|
17474
17478
|
};
|
|
17475
|
-
//# sourceMappingURL=chunk-
|
|
17479
|
+
//# sourceMappingURL=chunk-NYJROCBH.js.map
|