@rocicorp/zero 0.17.2025030600 → 0.17.2025030601
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-XXZWDMNW.js → chunk-EENFDWT4.js} +164 -220
- package/out/chunk-EENFDWT4.js.map +7 -0
- package/out/replicache/src/replicache-impl.d.ts +1 -2
- package/out/replicache/src/replicache-impl.d.ts.map +1 -1
- package/out/replicache/src/subscriptions.d.ts +2 -1
- package/out/replicache/src/subscriptions.d.ts.map +1 -1
- package/out/replicache/src/sync/patch.d.ts +1 -1
- package/out/replicache/src/sync/patch.d.ts.map +1 -1
- package/out/replicache/src/sync/pull.d.ts +0 -2
- package/out/replicache/src/sync/pull.d.ts.map +1 -1
- package/out/solid.js +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 +36 -51
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-client/src/client/context.d.ts +1 -1
- package/out/zero-client/src/client/context.d.ts.map +1 -1
- package/out/zero-client/src/client/crud.d.ts +1 -1
- package/out/zero-client/src/client/crud.d.ts.map +1 -1
- package/out/zero-client/src/client/custom.d.ts +2 -3
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/ivm-branch.d.ts +48 -0
- package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -0
- package/out/zero.js +1 -1
- package/package.json +1 -1
- package/out/chunk-XXZWDMNW.js.map +0 -7
- package/out/zero-client/src/client/ivm-source-repo.d.ts +0 -43
- package/out/zero-client/src/client/ivm-source-repo.d.ts.map +0 -1
|
@@ -3661,7 +3661,7 @@ async function* scanForHash(expectedRootHash, getRootHash, hash2, fromKey, readN
|
|
|
3661
3661
|
}
|
|
3662
3662
|
}
|
|
3663
3663
|
async function allEntriesAsDiff(map, op) {
|
|
3664
|
-
const
|
|
3664
|
+
const diff3 = [];
|
|
3665
3665
|
const make = op === "add" ? (entry) => ({
|
|
3666
3666
|
op: "add",
|
|
3667
3667
|
key: entry[0],
|
|
@@ -3672,9 +3672,9 @@ async function allEntriesAsDiff(map, op) {
|
|
|
3672
3672
|
oldValue: entry[1]
|
|
3673
3673
|
});
|
|
3674
3674
|
for await (const entry of map.entries()) {
|
|
3675
|
-
|
|
3675
|
+
diff3.push(make(entry));
|
|
3676
3676
|
}
|
|
3677
|
-
return
|
|
3677
|
+
return diff3;
|
|
3678
3678
|
}
|
|
3679
3679
|
|
|
3680
3680
|
// ../replicache/src/db/index-operation-enum.ts
|
|
@@ -3843,10 +3843,6 @@ async function readFromHead(name, dagRead, formatVersion) {
|
|
|
3843
3843
|
const commit = await commitFromHead(name, dagRead);
|
|
3844
3844
|
return readFromCommit(commit, dagRead, formatVersion);
|
|
3845
3845
|
}
|
|
3846
|
-
async function readFromHash(hash2, dagRead, formatVersion) {
|
|
3847
|
-
const commit = await commitFromHash(hash2, dagRead);
|
|
3848
|
-
return readFromCommit(commit, dagRead, formatVersion);
|
|
3849
|
-
}
|
|
3850
3846
|
function readFromCommit(commit, dagRead, formatVersion) {
|
|
3851
3847
|
const indexes = readIndexesForRead(commit, dagRead, formatVersion);
|
|
3852
3848
|
const map = new BTreeRead(dagRead, formatVersion, commit.valueHash);
|
|
@@ -4391,6 +4387,13 @@ var DiffsMap = class extends Map {
|
|
|
4391
4387
|
return super.set(key, value);
|
|
4392
4388
|
}
|
|
4393
4389
|
};
|
|
4390
|
+
async function diff2(oldHash, newHash, read, diffConfig, formatVersion) {
|
|
4391
|
+
const [oldCommit, newCommit] = await Promise.all([
|
|
4392
|
+
commitFromHash(oldHash, read),
|
|
4393
|
+
commitFromHash(newHash, read)
|
|
4394
|
+
]);
|
|
4395
|
+
return diffCommits(oldCommit, newCommit, read, diffConfig, formatVersion);
|
|
4396
|
+
}
|
|
4394
4397
|
async function diffCommits(oldCommit, newCommit, read, diffConfig, formatVersion) {
|
|
4395
4398
|
const diffsMap = new DiffsMap();
|
|
4396
4399
|
if (!diffConfig.shouldComputeDiffs()) {
|
|
@@ -5053,29 +5056,10 @@ var CookieMismatch = 2;
|
|
|
5053
5056
|
|
|
5054
5057
|
// ../replicache/src/sync/patch.ts
|
|
5055
5058
|
async function apply(lc, dbWrite, patch) {
|
|
5056
|
-
const ret = [];
|
|
5057
|
-
function pushChangeOrAdd(key, oldValue, newValue) {
|
|
5058
|
-
if (oldValue === void 0) {
|
|
5059
|
-
ret.push({
|
|
5060
|
-
op: "add",
|
|
5061
|
-
key,
|
|
5062
|
-
newValue
|
|
5063
|
-
});
|
|
5064
|
-
} else {
|
|
5065
|
-
ret.push({
|
|
5066
|
-
op: "change",
|
|
5067
|
-
key,
|
|
5068
|
-
oldValue,
|
|
5069
|
-
newValue
|
|
5070
|
-
});
|
|
5071
|
-
}
|
|
5072
|
-
}
|
|
5073
5059
|
for (const p of patch) {
|
|
5074
5060
|
switch (p.op) {
|
|
5075
5061
|
case "put": {
|
|
5076
|
-
const existing = await dbWrite.get(p.key);
|
|
5077
5062
|
const frozen = deepFreeze(p.value);
|
|
5078
|
-
pushChangeOrAdd(p.key, existing, frozen);
|
|
5079
5063
|
await dbWrite.put(lc, p.key, frozen);
|
|
5080
5064
|
break;
|
|
5081
5065
|
}
|
|
@@ -5097,7 +5081,6 @@ async function apply(lc, dbWrite, patch) {
|
|
|
5097
5081
|
addToEntries(p.merge);
|
|
5098
5082
|
}
|
|
5099
5083
|
const frozen = deepFreeze(Object.fromEntries(entries));
|
|
5100
|
-
pushChangeOrAdd(p.key, existing, frozen);
|
|
5101
5084
|
await dbWrite.put(lc, p.key, frozen);
|
|
5102
5085
|
break;
|
|
5103
5086
|
}
|
|
@@ -5107,22 +5090,13 @@ async function apply(lc, dbWrite, patch) {
|
|
|
5107
5090
|
continue;
|
|
5108
5091
|
}
|
|
5109
5092
|
await dbWrite.del(lc, p.key);
|
|
5110
|
-
ret.push({
|
|
5111
|
-
op: "del",
|
|
5112
|
-
key: p.key,
|
|
5113
|
-
oldValue: existing
|
|
5114
|
-
});
|
|
5115
5093
|
break;
|
|
5116
5094
|
}
|
|
5117
5095
|
case "clear":
|
|
5118
5096
|
await dbWrite.clear();
|
|
5119
|
-
ret.push({
|
|
5120
|
-
op: "clear"
|
|
5121
|
-
});
|
|
5122
5097
|
break;
|
|
5123
5098
|
}
|
|
5124
5099
|
}
|
|
5125
|
-
return ret;
|
|
5126
5100
|
}
|
|
5127
5101
|
|
|
5128
5102
|
// ../replicache/src/sync/pull-error.ts
|
|
@@ -5289,11 +5263,10 @@ function handlePullResponseV1(lc, store, expectedBaseCookie, response, clientID,
|
|
|
5289
5263
|
clientID,
|
|
5290
5264
|
formatVersion
|
|
5291
5265
|
);
|
|
5292
|
-
|
|
5266
|
+
await apply(lc, dbWrite, response.patch);
|
|
5293
5267
|
return {
|
|
5294
5268
|
type: Applied,
|
|
5295
|
-
syncHead: await dbWrite.commit(SYNC_HEAD_NAME)
|
|
5296
|
-
diffs
|
|
5269
|
+
syncHead: await dbWrite.commit(SYNC_HEAD_NAME)
|
|
5297
5270
|
};
|
|
5298
5271
|
});
|
|
5299
5272
|
}
|
|
@@ -6774,8 +6747,8 @@ var SubscriptionImpl = class {
|
|
|
6774
6747
|
return this.#body(tx);
|
|
6775
6748
|
}
|
|
6776
6749
|
matches(diffs) {
|
|
6777
|
-
for (const [indexName,
|
|
6778
|
-
if (diffMatchesSubscription(this.#keys, this.#scans, indexName,
|
|
6750
|
+
for (const [indexName, diff3] of diffs) {
|
|
6751
|
+
if (diffMatchesSubscription(this.#keys, this.#scans, indexName, diff3)) {
|
|
6779
6752
|
return true;
|
|
6780
6753
|
}
|
|
6781
6754
|
}
|
|
@@ -6815,7 +6788,7 @@ var WatchSubscription = class {
|
|
|
6815
6788
|
}
|
|
6816
6789
|
invoke(tx, kind, diffs) {
|
|
6817
6790
|
const invoke = async (indexName, prefix, compareKey, convertInternalDiff) => {
|
|
6818
|
-
let
|
|
6791
|
+
let diff3;
|
|
6819
6792
|
if (kind === InitialRun) {
|
|
6820
6793
|
if (!this.#initialValuesInFirstDiff) {
|
|
6821
6794
|
return void 0;
|
|
@@ -6829,17 +6802,17 @@ var WatchSubscription = class {
|
|
|
6829
6802
|
newValue: entry[1]
|
|
6830
6803
|
});
|
|
6831
6804
|
}
|
|
6832
|
-
|
|
6805
|
+
diff3 = newDiff2;
|
|
6833
6806
|
} else {
|
|
6834
6807
|
assert(diffs);
|
|
6835
6808
|
const maybeDiff = diffs.get(indexName ?? "") ?? [];
|
|
6836
|
-
|
|
6809
|
+
diff3 = convertInternalDiff(maybeDiff);
|
|
6837
6810
|
}
|
|
6838
6811
|
const newDiff = [];
|
|
6839
|
-
const { length } =
|
|
6840
|
-
for (let i = diffBinarySearch(
|
|
6841
|
-
if (compareKey(
|
|
6842
|
-
newDiff.push(
|
|
6812
|
+
const { length } = diff3;
|
|
6813
|
+
for (let i = diffBinarySearch(diff3, prefix, compareKey); i < length; i++) {
|
|
6814
|
+
if (compareKey(diff3[i]).startsWith(prefix)) {
|
|
6815
|
+
newDiff.push(diff3[i]);
|
|
6843
6816
|
} else {
|
|
6844
6817
|
break;
|
|
6845
6818
|
}
|
|
@@ -6850,29 +6823,29 @@ var WatchSubscription = class {
|
|
|
6850
6823
|
return invoke(
|
|
6851
6824
|
this.#indexName,
|
|
6852
6825
|
this.#prefix,
|
|
6853
|
-
(
|
|
6826
|
+
(diff3) => diff3.key[0],
|
|
6854
6827
|
(internalDiff) => convertDiffValues(internalDiff, decodeIndexKey)
|
|
6855
6828
|
);
|
|
6856
6829
|
}
|
|
6857
6830
|
return invoke(
|
|
6858
6831
|
void 0,
|
|
6859
6832
|
this.#prefix,
|
|
6860
|
-
(
|
|
6833
|
+
(diff3) => diff3.key,
|
|
6861
6834
|
(internalDiff) => convertDiffValues(internalDiff, (k) => k)
|
|
6862
6835
|
);
|
|
6863
6836
|
}
|
|
6864
6837
|
matches(diffs) {
|
|
6865
|
-
const
|
|
6866
|
-
if (
|
|
6838
|
+
const diff3 = diffs.get(this.#indexName ?? "");
|
|
6839
|
+
if (diff3 === void 0) {
|
|
6867
6840
|
return false;
|
|
6868
6841
|
}
|
|
6869
|
-
return watcherMatchesDiff(
|
|
6842
|
+
return watcherMatchesDiff(diff3, this.#prefix, this.#indexName);
|
|
6870
6843
|
}
|
|
6871
6844
|
updateDeps(_keys, _scans) {
|
|
6872
6845
|
}
|
|
6873
6846
|
};
|
|
6874
|
-
function convertDiffValues(
|
|
6875
|
-
return
|
|
6847
|
+
function convertDiffValues(diff3, convertKey) {
|
|
6848
|
+
return diff3.map((op) => {
|
|
6876
6849
|
const key = convertKey(op.key);
|
|
6877
6850
|
switch (op.op) {
|
|
6878
6851
|
case "add":
|
|
@@ -6991,23 +6964,23 @@ var SubscriptionsManagerImpl = class {
|
|
|
6991
6964
|
return false;
|
|
6992
6965
|
}
|
|
6993
6966
|
};
|
|
6994
|
-
function diffMatchesSubscription(keys, scans, indexName,
|
|
6967
|
+
function diffMatchesSubscription(keys, scans, indexName, diff3) {
|
|
6995
6968
|
if (indexName === "") {
|
|
6996
|
-
for (const diffEntry of
|
|
6969
|
+
for (const diffEntry of diff3) {
|
|
6997
6970
|
if (keys.has(diffEntry.key)) {
|
|
6998
6971
|
return true;
|
|
6999
6972
|
}
|
|
7000
6973
|
}
|
|
7001
6974
|
}
|
|
7002
6975
|
for (const scanInfo of scans) {
|
|
7003
|
-
if (scanInfoMatchesDiff(scanInfo, indexName,
|
|
6976
|
+
if (scanInfoMatchesDiff(scanInfo, indexName, diff3)) {
|
|
7004
6977
|
return true;
|
|
7005
6978
|
}
|
|
7006
6979
|
}
|
|
7007
6980
|
return false;
|
|
7008
6981
|
}
|
|
7009
|
-
function scanInfoMatchesDiff(scanInfo, changeIndexName,
|
|
7010
|
-
for (const diffEntry of
|
|
6982
|
+
function scanInfoMatchesDiff(scanInfo, changeIndexName, diff3) {
|
|
6983
|
+
for (const diffEntry of diff3) {
|
|
7011
6984
|
if (scanInfoMatchesKey(scanInfo, changeIndexName, diffEntry.key)) {
|
|
7012
6985
|
return true;
|
|
7013
6986
|
}
|
|
@@ -7069,18 +7042,18 @@ function* subscriptionsForDiffs(subscriptions, diffs) {
|
|
|
7069
7042
|
}
|
|
7070
7043
|
}
|
|
7071
7044
|
}
|
|
7072
|
-
function watcherMatchesDiff(
|
|
7045
|
+
function watcherMatchesDiff(diff3, prefix, indexName) {
|
|
7073
7046
|
if (prefix === "") {
|
|
7074
7047
|
return true;
|
|
7075
7048
|
}
|
|
7076
7049
|
const compareKey = indexName ? (diffOp) => decodeIndexKey(diffOp.key)[0] : (diffOp) => diffOp.key;
|
|
7077
|
-
const i = diffBinarySearch(
|
|
7078
|
-
return i <
|
|
7050
|
+
const i = diffBinarySearch(diff3, prefix, compareKey);
|
|
7051
|
+
return i < diff3.length && compareKey(diff3[i]).startsWith(prefix);
|
|
7079
7052
|
}
|
|
7080
|
-
function diffBinarySearch(
|
|
7053
|
+
function diffBinarySearch(diff3, prefix, compareKey) {
|
|
7081
7054
|
return binarySearch(
|
|
7082
|
-
|
|
7083
|
-
(i) => compareUTF82(prefix, compareKey(
|
|
7055
|
+
diff3.length,
|
|
7056
|
+
(i) => compareUTF82(prefix, compareKey(diff3[i]))
|
|
7084
7057
|
);
|
|
7085
7058
|
}
|
|
7086
7059
|
|
|
@@ -7832,7 +7805,7 @@ var ReplicacheImpl = class {
|
|
|
7832
7805
|
*
|
|
7833
7806
|
* @experimental This method is under development and its semantics will change.
|
|
7834
7807
|
*/
|
|
7835
|
-
async poke(poke
|
|
7808
|
+
async poke(poke) {
|
|
7836
7809
|
await this.#ready;
|
|
7837
7810
|
const { clientID } = this;
|
|
7838
7811
|
const requestID = newRequestID(clientID);
|
|
@@ -7856,7 +7829,6 @@ var ReplicacheImpl = class {
|
|
|
7856
7829
|
);
|
|
7857
7830
|
switch (result.type) {
|
|
7858
7831
|
case Applied:
|
|
7859
|
-
await pullApplied(this.memdag, result.syncHead, result.diffs);
|
|
7860
7832
|
await this.maybeEndPull(result.syncHead, requestID);
|
|
7861
7833
|
break;
|
|
7862
7834
|
case CookieMismatch:
|
|
@@ -13265,101 +13237,15 @@ function sourceNameFromKey(key) {
|
|
|
13265
13237
|
return key.slice(ENTITIES_KEY_PREFIX.length, slash);
|
|
13266
13238
|
}
|
|
13267
13239
|
|
|
13268
|
-
// ../zero-client/src/client/ivm-
|
|
13269
|
-
var IVMSourceRepo = class {
|
|
13270
|
-
#main;
|
|
13271
|
-
#tables;
|
|
13272
|
-
/**
|
|
13273
|
-
* Sync is lazily created when the first response from the server is received.
|
|
13274
|
-
*/
|
|
13275
|
-
#sync;
|
|
13276
|
-
/**
|
|
13277
|
-
* Rebase is created when the sync head is advanced and points to a fork
|
|
13278
|
-
* of the sync head. This is used to rebase optimistic mutations.
|
|
13279
|
-
*/
|
|
13280
|
-
#rebase;
|
|
13281
|
-
constructor(tables) {
|
|
13282
|
-
this.#main = new IVMSourceBranch(tables);
|
|
13283
|
-
this.#tables = tables;
|
|
13284
|
-
}
|
|
13285
|
-
get main() {
|
|
13286
|
-
return this.#main;
|
|
13287
|
-
}
|
|
13288
|
-
/**
|
|
13289
|
-
* Used for reads in `zero.TransactionImpl`.
|
|
13290
|
-
* Writes in `zero.TransactionImpl` also get applied to the rebase branch.
|
|
13291
|
-
*
|
|
13292
|
-
* The rebase branch is always forked off of the sync branch when a rebase begins.
|
|
13293
|
-
*/
|
|
13294
|
-
get rebase() {
|
|
13295
|
-
return must(this.#rebase, "rebase branch does not exist!");
|
|
13296
|
-
}
|
|
13297
|
-
advanceSyncHead = async (store, syncHeadHash, patches) => {
|
|
13298
|
-
if (this.#sync === void 0) {
|
|
13299
|
-
await withRead(store, async (dagRead) => {
|
|
13300
|
-
const syncSources = new IVMSourceBranch(this.#tables);
|
|
13301
|
-
const read = await readFromHash(
|
|
13302
|
-
syncHeadHash,
|
|
13303
|
-
dagRead,
|
|
13304
|
-
Latest
|
|
13305
|
-
);
|
|
13306
|
-
for await (const entry of read.map.scan(ENTITIES_KEY_PREFIX)) {
|
|
13307
|
-
if (!entry[0].startsWith(ENTITIES_KEY_PREFIX)) {
|
|
13308
|
-
break;
|
|
13309
|
-
}
|
|
13310
|
-
const name = sourceNameFromKey(entry[0]);
|
|
13311
|
-
const source = must(syncSources.getSource(name));
|
|
13312
|
-
source.push({
|
|
13313
|
-
type: "add",
|
|
13314
|
-
row: entry[1]
|
|
13315
|
-
});
|
|
13316
|
-
}
|
|
13317
|
-
this.#sync = syncSources;
|
|
13318
|
-
});
|
|
13319
|
-
} else {
|
|
13320
|
-
for (const patch of patches) {
|
|
13321
|
-
if (patch.op === "clear") {
|
|
13322
|
-
this.#sync.clear();
|
|
13323
|
-
continue;
|
|
13324
|
-
}
|
|
13325
|
-
const { key } = patch;
|
|
13326
|
-
if (!key.startsWith(ENTITIES_KEY_PREFIX)) {
|
|
13327
|
-
continue;
|
|
13328
|
-
}
|
|
13329
|
-
const name = sourceNameFromKey(key);
|
|
13330
|
-
const source = must(this.#sync.getSource(name));
|
|
13331
|
-
switch (patch.op) {
|
|
13332
|
-
case "del":
|
|
13333
|
-
source.push({
|
|
13334
|
-
type: "remove",
|
|
13335
|
-
row: patch.oldValue
|
|
13336
|
-
});
|
|
13337
|
-
break;
|
|
13338
|
-
case "add":
|
|
13339
|
-
source.push({
|
|
13340
|
-
type: "add",
|
|
13341
|
-
row: patch.newValue
|
|
13342
|
-
});
|
|
13343
|
-
break;
|
|
13344
|
-
case "change":
|
|
13345
|
-
source.push({
|
|
13346
|
-
type: "edit",
|
|
13347
|
-
row: patch.newValue,
|
|
13348
|
-
oldRow: patch.oldValue
|
|
13349
|
-
});
|
|
13350
|
-
break;
|
|
13351
|
-
}
|
|
13352
|
-
}
|
|
13353
|
-
}
|
|
13354
|
-
this.#rebase = must(this.#sync).fork();
|
|
13355
|
-
};
|
|
13356
|
-
};
|
|
13240
|
+
// ../zero-client/src/client/ivm-branch.ts
|
|
13357
13241
|
var IVMSourceBranch = class _IVMSourceBranch {
|
|
13358
13242
|
#sources;
|
|
13359
13243
|
#tables;
|
|
13360
|
-
|
|
13244
|
+
hash;
|
|
13245
|
+
constructor(tables, hash2, sources = /* @__PURE__ */ new Map()) {
|
|
13361
13246
|
this.#tables = tables;
|
|
13362
13247
|
this.#sources = sources;
|
|
13248
|
+
this.hash = hash2;
|
|
13363
13249
|
}
|
|
13364
13250
|
getSource(name) {
|
|
13365
13251
|
if (this.#sources.has(name)) {
|
|
@@ -13373,20 +13259,46 @@ var IVMSourceBranch = class _IVMSourceBranch {
|
|
|
13373
13259
|
clear() {
|
|
13374
13260
|
this.#sources.clear();
|
|
13375
13261
|
}
|
|
13262
|
+
/**
|
|
13263
|
+
* Mutates the current branch, advancing it to the new head
|
|
13264
|
+
* by applying the given diffs.
|
|
13265
|
+
*/
|
|
13266
|
+
advance(expectedHead, newHead, diffs) {
|
|
13267
|
+
assert(
|
|
13268
|
+
this.hash === expectedHead,
|
|
13269
|
+
() => `Expected head must match the main head. Got: ${this.hash}, expected: ${expectedHead}`
|
|
13270
|
+
);
|
|
13271
|
+
applyDiffs(diffs, this);
|
|
13272
|
+
this.hash = newHead;
|
|
13273
|
+
}
|
|
13274
|
+
/**
|
|
13275
|
+
* Fork the branch and patch it up to match the desired head.
|
|
13276
|
+
*/
|
|
13277
|
+
async forkToHead(store, expectedHead, desiredHead) {
|
|
13278
|
+
const fork = this.fork();
|
|
13279
|
+
assert(
|
|
13280
|
+
expectedHead === fork.hash,
|
|
13281
|
+
() => `Expected head must match the main head. Got: ${expectedHead}, expected: ${fork.hash}`
|
|
13282
|
+
);
|
|
13283
|
+
if (fork.hash === desiredHead) {
|
|
13284
|
+
return fork;
|
|
13285
|
+
}
|
|
13286
|
+
await patchBranch(desiredHead, store, fork);
|
|
13287
|
+
fork.hash = desiredHead;
|
|
13288
|
+
return fork;
|
|
13289
|
+
}
|
|
13376
13290
|
/**
|
|
13377
13291
|
* Creates a new IVMSourceBranch that is a copy of the current one.
|
|
13378
13292
|
* This is a cheap operation since the b-trees are shared until a write is performed
|
|
13379
13293
|
* and then only the modified nodes are copied.
|
|
13380
13294
|
*
|
|
13381
|
-
*
|
|
13382
|
-
*
|
|
13383
|
-
* 2. We need to create `main` at startup.
|
|
13384
|
-
* 3. We need to create a new `sync` head because we got a new server snapshot.
|
|
13385
|
-
* The old `sync` head is forked and the new server snapshot is applied to the fork.
|
|
13295
|
+
* IVM branches are forked when we need to rebase mutations.
|
|
13296
|
+
* The mutations modify the fork rather than original branch.
|
|
13386
13297
|
*/
|
|
13387
13298
|
fork() {
|
|
13388
13299
|
return new _IVMSourceBranch(
|
|
13389
13300
|
this.#tables,
|
|
13301
|
+
this.hash,
|
|
13390
13302
|
new Map(
|
|
13391
13303
|
wrapIterable(this.#sources.entries()).map(([name, source]) => [
|
|
13392
13304
|
name,
|
|
@@ -13396,6 +13308,61 @@ var IVMSourceBranch = class _IVMSourceBranch {
|
|
|
13396
13308
|
);
|
|
13397
13309
|
}
|
|
13398
13310
|
};
|
|
13311
|
+
async function patchBranch(desiredHead, store, fork) {
|
|
13312
|
+
const diffs = await computeDiffs(must(fork.hash), desiredHead, store);
|
|
13313
|
+
if (!diffs) {
|
|
13314
|
+
return;
|
|
13315
|
+
}
|
|
13316
|
+
applyDiffs(diffs, fork);
|
|
13317
|
+
}
|
|
13318
|
+
async function computeDiffs(startHash, endHash, store) {
|
|
13319
|
+
const readFn = (dagRead) => diff2(
|
|
13320
|
+
startHash,
|
|
13321
|
+
endHash,
|
|
13322
|
+
dagRead,
|
|
13323
|
+
{
|
|
13324
|
+
shouldComputeDiffs: () => true,
|
|
13325
|
+
shouldComputeDiffsForIndex(_name) {
|
|
13326
|
+
return false;
|
|
13327
|
+
}
|
|
13328
|
+
},
|
|
13329
|
+
Latest
|
|
13330
|
+
);
|
|
13331
|
+
const diffs = await withRead(store, readFn);
|
|
13332
|
+
return diffs.get("");
|
|
13333
|
+
}
|
|
13334
|
+
function applyDiffs(diffs, branch) {
|
|
13335
|
+
for (let i = diffBinarySearch(diffs, ENTITIES_KEY_PREFIX, (diff3) => diff3.key); i < diffs.length; i++) {
|
|
13336
|
+
const diff3 = diffs[i];
|
|
13337
|
+
const { key } = diff3;
|
|
13338
|
+
if (!key.startsWith(ENTITIES_KEY_PREFIX)) {
|
|
13339
|
+
break;
|
|
13340
|
+
}
|
|
13341
|
+
const name = sourceNameFromKey(key);
|
|
13342
|
+
const source = must(branch.getSource(name));
|
|
13343
|
+
switch (diff3.op) {
|
|
13344
|
+
case "del":
|
|
13345
|
+
source.push({
|
|
13346
|
+
type: "remove",
|
|
13347
|
+
row: diff3.oldValue
|
|
13348
|
+
});
|
|
13349
|
+
break;
|
|
13350
|
+
case "add":
|
|
13351
|
+
source.push({
|
|
13352
|
+
type: "add",
|
|
13353
|
+
row: diff3.newValue
|
|
13354
|
+
});
|
|
13355
|
+
break;
|
|
13356
|
+
case "change":
|
|
13357
|
+
source.push({
|
|
13358
|
+
type: "edit",
|
|
13359
|
+
row: diff3.newValue,
|
|
13360
|
+
oldRow: diff3.oldValue
|
|
13361
|
+
});
|
|
13362
|
+
break;
|
|
13363
|
+
}
|
|
13364
|
+
}
|
|
13365
|
+
}
|
|
13399
13366
|
|
|
13400
13367
|
// ../zero-client/src/client/context.ts
|
|
13401
13368
|
var ZeroContext = class {
|
|
@@ -13444,40 +13411,40 @@ var ZeroContext = class {
|
|
|
13444
13411
|
processChanges(changes) {
|
|
13445
13412
|
this.batchViewUpdates(() => {
|
|
13446
13413
|
try {
|
|
13447
|
-
for (const
|
|
13448
|
-
const { key } =
|
|
13414
|
+
for (const diff3 of changes) {
|
|
13415
|
+
const { key } = diff3;
|
|
13449
13416
|
assert(key.startsWith(ENTITIES_KEY_PREFIX));
|
|
13450
13417
|
const name = sourceNameFromKey(key);
|
|
13451
13418
|
const source = this.getSource(name);
|
|
13452
13419
|
if (!source) {
|
|
13453
13420
|
continue;
|
|
13454
13421
|
}
|
|
13455
|
-
switch (
|
|
13422
|
+
switch (diff3.op) {
|
|
13456
13423
|
case "del":
|
|
13457
|
-
assert(typeof
|
|
13424
|
+
assert(typeof diff3.oldValue === "object");
|
|
13458
13425
|
source.push({
|
|
13459
13426
|
type: "remove",
|
|
13460
|
-
row:
|
|
13427
|
+
row: diff3.oldValue
|
|
13461
13428
|
});
|
|
13462
13429
|
break;
|
|
13463
13430
|
case "add":
|
|
13464
|
-
assert(typeof
|
|
13431
|
+
assert(typeof diff3.newValue === "object");
|
|
13465
13432
|
source.push({
|
|
13466
13433
|
type: "add",
|
|
13467
|
-
row:
|
|
13434
|
+
row: diff3.newValue
|
|
13468
13435
|
});
|
|
13469
13436
|
break;
|
|
13470
13437
|
case "change":
|
|
13471
|
-
assert(typeof
|
|
13472
|
-
assert(typeof
|
|
13438
|
+
assert(typeof diff3.newValue === "object");
|
|
13439
|
+
assert(typeof diff3.oldValue === "object");
|
|
13473
13440
|
source.push({
|
|
13474
13441
|
type: "edit",
|
|
13475
|
-
row:
|
|
13476
|
-
oldRow:
|
|
13442
|
+
row: diff3.newValue,
|
|
13443
|
+
oldRow: diff3.oldValue
|
|
13477
13444
|
});
|
|
13478
13445
|
break;
|
|
13479
13446
|
default:
|
|
13480
|
-
unreachable(
|
|
13447
|
+
unreachable(diff3);
|
|
13481
13448
|
}
|
|
13482
13449
|
}
|
|
13483
13450
|
} finally {
|
|
@@ -13713,23 +13680,13 @@ async function deleteImpl(tx, arg, schema, ivmBranch) {
|
|
|
13713
13680
|
|
|
13714
13681
|
// ../zero-client/src/client/custom.ts
|
|
13715
13682
|
var TransactionImpl = class {
|
|
13716
|
-
constructor(repTx, schema
|
|
13683
|
+
constructor(repTx, schema) {
|
|
13717
13684
|
must(repTx.reason === "initial" || repTx.reason === "rebase");
|
|
13718
13685
|
this.clientID = repTx.clientID;
|
|
13719
13686
|
this.mutationID = repTx.mutationID;
|
|
13720
13687
|
this.reason = repTx.reason === "initial" ? "optimistic" : "rebase";
|
|
13721
|
-
this.mutate = makeSchemaCRUD(
|
|
13722
|
-
|
|
13723
|
-
repTx,
|
|
13724
|
-
// Mutators do not write to the main IVM sources during optimistic mutations
|
|
13725
|
-
// so we pass undefined here.
|
|
13726
|
-
// ExperimentalWatch handles updating main.
|
|
13727
|
-
this.reason === "optimistic" ? void 0 : ivmSourceRepo.rebase
|
|
13728
|
-
);
|
|
13729
|
-
this.query = makeSchemaQuery(
|
|
13730
|
-
schema,
|
|
13731
|
-
this.reason === "optimistic" ? ivmSourceRepo.main : ivmSourceRepo.rebase
|
|
13732
|
-
);
|
|
13688
|
+
this.mutate = makeSchemaCRUD(schema, repTx);
|
|
13689
|
+
this.query = {};
|
|
13733
13690
|
}
|
|
13734
13691
|
clientID;
|
|
13735
13692
|
mutationID;
|
|
@@ -13738,33 +13695,20 @@ var TransactionImpl = class {
|
|
|
13738
13695
|
mutate;
|
|
13739
13696
|
query;
|
|
13740
13697
|
};
|
|
13741
|
-
function makeReplicacheMutator(mutator, schema
|
|
13698
|
+
function makeReplicacheMutator(mutator, schema) {
|
|
13742
13699
|
return (repTx, args) => {
|
|
13743
|
-
const tx = new TransactionImpl(repTx, schema
|
|
13700
|
+
const tx = new TransactionImpl(repTx, schema);
|
|
13744
13701
|
return mutator(tx, args);
|
|
13745
13702
|
};
|
|
13746
13703
|
}
|
|
13747
|
-
function
|
|
13748
|
-
const rv = {};
|
|
13749
|
-
const context = new ZeroContext(
|
|
13750
|
-
ivmBranch,
|
|
13751
|
-
() => () => {
|
|
13752
|
-
},
|
|
13753
|
-
(applyViewUpdates) => applyViewUpdates()
|
|
13754
|
-
);
|
|
13755
|
-
for (const name of Object.keys(schema.tables)) {
|
|
13756
|
-
rv[name] = newQuery(context, schema, name);
|
|
13757
|
-
}
|
|
13758
|
-
return rv;
|
|
13759
|
-
}
|
|
13760
|
-
function makeSchemaCRUD(schema, tx, ivmBranch) {
|
|
13704
|
+
function makeSchemaCRUD(schema, tx) {
|
|
13761
13705
|
const mutate = {};
|
|
13762
13706
|
for (const [name] of Object.entries(schema.tables)) {
|
|
13763
|
-
mutate[name] = makeTableCRUD(schema, name, tx
|
|
13707
|
+
mutate[name] = makeTableCRUD(schema, name, tx);
|
|
13764
13708
|
}
|
|
13765
13709
|
return mutate;
|
|
13766
13710
|
}
|
|
13767
|
-
function makeTableCRUD(schema, tableName, tx
|
|
13711
|
+
function makeTableCRUD(schema, tableName, tx) {
|
|
13768
13712
|
const table2 = must(schema.tables[tableName]);
|
|
13769
13713
|
const { primaryKey } = table2;
|
|
13770
13714
|
return {
|
|
@@ -13772,25 +13716,25 @@ function makeTableCRUD(schema, tableName, tx, ivmBranch) {
|
|
|
13772
13716
|
tx,
|
|
13773
13717
|
{ op: "insert", tableName, primaryKey, value },
|
|
13774
13718
|
schema,
|
|
13775
|
-
|
|
13719
|
+
void 0
|
|
13776
13720
|
),
|
|
13777
13721
|
upsert: (value) => upsertImpl(
|
|
13778
13722
|
tx,
|
|
13779
13723
|
{ op: "upsert", tableName, primaryKey, value },
|
|
13780
13724
|
schema,
|
|
13781
|
-
|
|
13725
|
+
void 0
|
|
13782
13726
|
),
|
|
13783
13727
|
update: (value) => updateImpl(
|
|
13784
13728
|
tx,
|
|
13785
13729
|
{ op: "update", tableName, primaryKey, value },
|
|
13786
13730
|
schema,
|
|
13787
|
-
|
|
13731
|
+
void 0
|
|
13788
13732
|
),
|
|
13789
13733
|
delete: (id) => deleteImpl(
|
|
13790
13734
|
tx,
|
|
13791
13735
|
{ op: "delete", tableName, primaryKey, value: id },
|
|
13792
13736
|
schema,
|
|
13793
|
-
|
|
13737
|
+
void 0
|
|
13794
13738
|
)
|
|
13795
13739
|
};
|
|
13796
13740
|
}
|
|
@@ -14094,7 +14038,7 @@ function makeMessage(message, context, logLevel) {
|
|
|
14094
14038
|
}
|
|
14095
14039
|
|
|
14096
14040
|
// ../zero-client/src/client/version.ts
|
|
14097
|
-
var version2 = "0.17.
|
|
14041
|
+
var version2 = "0.17.2025030601";
|
|
14098
14042
|
|
|
14099
14043
|
// ../zero-client/src/client/log-options.ts
|
|
14100
14044
|
var LevelFilterLogSink = class {
|
|
@@ -14407,8 +14351,8 @@ var QueryManager = class {
|
|
|
14407
14351
|
this.#recentQueriesMaxSize = recentQueriesMaxSize;
|
|
14408
14352
|
this.#send = send2;
|
|
14409
14353
|
experimentalWatch(
|
|
14410
|
-
(
|
|
14411
|
-
for (const diffOp of
|
|
14354
|
+
(diff3) => {
|
|
14355
|
+
for (const diffOp of diff3) {
|
|
14412
14356
|
const queryHash = diffOp.key.substring(GOT_QUERIES_KEY_PREFIX.length);
|
|
14413
14357
|
switch (diffOp.op) {
|
|
14414
14358
|
case "add":
|
|
@@ -15059,7 +15003,7 @@ var Zero = class {
|
|
|
15059
15003
|
#enableAnalytics;
|
|
15060
15004
|
#pokeHandler;
|
|
15061
15005
|
#queryManager;
|
|
15062
|
-
#
|
|
15006
|
+
#ivmMain;
|
|
15063
15007
|
#clientToServer;
|
|
15064
15008
|
#deleteClientsManager;
|
|
15065
15009
|
/**
|
|
@@ -15191,14 +15135,14 @@ var Zero = class {
|
|
|
15191
15135
|
const replicacheMutators = {
|
|
15192
15136
|
[CRUD_MUTATION_NAME]: makeCRUDMutator(schema)
|
|
15193
15137
|
};
|
|
15194
|
-
this.#
|
|
15138
|
+
this.#ivmMain = new IVMSourceBranch(schema.tables);
|
|
15195
15139
|
for (const [namespace, mutatorsForNamespace] of Object.entries(
|
|
15196
15140
|
options.mutators ?? {}
|
|
15197
15141
|
)) {
|
|
15198
15142
|
for (const [name, mutator] of Object.entries(
|
|
15199
15143
|
mutatorsForNamespace
|
|
15200
15144
|
)) {
|
|
15201
|
-
replicacheMutators[customMutatorKey(namespace, name)] = makeReplicacheMutator(mutator, schema
|
|
15145
|
+
replicacheMutators[customMutatorKey(namespace, name)] = makeReplicacheMutator(mutator, schema);
|
|
15202
15146
|
}
|
|
15203
15147
|
}
|
|
15204
15148
|
this.storageKey = storageKey ?? "";
|
|
@@ -15292,12 +15236,12 @@ var Zero = class {
|
|
|
15292
15236
|
this.#lc
|
|
15293
15237
|
);
|
|
15294
15238
|
this.#zeroContext = new ZeroContext(
|
|
15295
|
-
this.#
|
|
15239
|
+
this.#ivmMain,
|
|
15296
15240
|
(ast, ttl, gotCallback) => this.#queryManager.add(ast, ttl, gotCallback),
|
|
15297
15241
|
batchViewUpdates
|
|
15298
15242
|
);
|
|
15299
15243
|
rep.experimentalWatch(
|
|
15300
|
-
(
|
|
15244
|
+
(diff3) => this.#zeroContext.processChanges(diff3),
|
|
15301
15245
|
{
|
|
15302
15246
|
prefix: ENTITIES_KEY_PREFIX,
|
|
15303
15247
|
initialValuesInFirstDiff: true
|
|
@@ -15314,7 +15258,7 @@ var Zero = class {
|
|
|
15314
15258
|
});
|
|
15315
15259
|
this.#metrics.tags.push(`version:${this.version}`);
|
|
15316
15260
|
this.#pokeHandler = new PokeHandler(
|
|
15317
|
-
(poke) => this.#rep.poke(poke
|
|
15261
|
+
(poke) => this.#rep.poke(poke),
|
|
15318
15262
|
() => this.#onPokeError(),
|
|
15319
15263
|
rep.clientID,
|
|
15320
15264
|
schema,
|
|
@@ -16298,4 +16242,4 @@ export {
|
|
|
16298
16242
|
escapeLike,
|
|
16299
16243
|
Zero
|
|
16300
16244
|
};
|
|
16301
|
-
//# sourceMappingURL=chunk-
|
|
16245
|
+
//# sourceMappingURL=chunk-EENFDWT4.js.map
|