@rocicorp/zero 0.3.2024102502 → 0.3.2024102800

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/out/{chunk-2RUT5EQV.js → chunk-F5QR3K72.js} +2 -7
  2. package/out/chunk-F5QR3K72.js.map +7 -0
  3. package/out/chunk-HARIWJ2J.js +8 -0
  4. package/out/{chunk-2RUT5EQV.js.map → chunk-HARIWJ2J.js.map} +1 -1
  5. package/out/chunk-NKGIR6IA.js +1 -0
  6. package/out/chunk-NKGIR6IA.js.map +7 -0
  7. package/out/chunk-RCVGGCMG.js +288 -0
  8. package/out/chunk-RCVGGCMG.js.map +7 -0
  9. package/out/internal.js +9 -0
  10. package/out/internal.js.map +7 -0
  11. package/out/react.js +5 -4
  12. package/out/react.js.map +2 -2
  13. package/out/replicache/src/version.d.ts.map +1 -1
  14. package/out/replicache/src/version.js +2 -1
  15. package/out/replicache/src/version.js.map +1 -1
  16. package/out/solid.js +84 -0
  17. package/out/solid.js.map +7 -0
  18. package/out/zero/src/internal.d.ts +2 -0
  19. package/out/zero/src/internal.d.ts.map +1 -0
  20. package/out/zero/src/solid.d.ts +2 -0
  21. package/out/zero/src/solid.d.ts.map +1 -0
  22. package/out/zero-cache/src/config/config-query.d.ts +2 -2
  23. package/out/zero-cache/src/config/config-query.d.ts.map +1 -1
  24. package/out/zero-cache/src/config/config-query.js +1 -1
  25. package/out/zero-cache/src/config/config-query.js.map +1 -1
  26. package/out/zero-cache/src/server/life-cycle.d.ts +2 -0
  27. package/out/zero-cache/src/server/life-cycle.d.ts.map +1 -1
  28. package/out/zero-cache/src/server/life-cycle.js +37 -21
  29. package/out/zero-cache/src/server/life-cycle.js.map +1 -1
  30. package/out/zero-cache/src/server/main.js +2 -7
  31. package/out/zero-cache/src/server/main.js.map +1 -1
  32. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.d.ts.map +1 -1
  33. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.js +9 -1
  34. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.js.map +1 -1
  35. package/out/zero-cache/src/services/dispatcher/dispatcher.d.ts +2 -2
  36. package/out/zero-cache/src/services/dispatcher/dispatcher.d.ts.map +1 -1
  37. package/out/zero-cache/src/services/dispatcher/dispatcher.js +1 -0
  38. package/out/zero-cache/src/services/dispatcher/dispatcher.js.map +1 -1
  39. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  40. package/out/zero-cache/src/services/view-syncer/view-syncer.js +10 -4
  41. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  42. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  43. package/out/zero-client/src/client/query-manager.js +2 -5
  44. package/out/zero-client/src/client/query-manager.js.map +1 -1
  45. package/out/zero-client/src/client/version.d.ts.map +1 -1
  46. package/out/zero-client/src/client/version.js +2 -1
  47. package/out/zero-client/src/client/version.js.map +1 -1
  48. package/out/zero-internal/src/mod.d.ts +8 -0
  49. package/out/zero-internal/src/mod.d.ts.map +1 -0
  50. package/out/zero-protocol/src/ast-hash.d.ts +3 -0
  51. package/out/zero-protocol/src/ast-hash.d.ts.map +1 -0
  52. package/out/zero-protocol/src/ast-hash.js +14 -0
  53. package/out/zero-protocol/src/ast-hash.js.map +1 -0
  54. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  55. package/out/zero-protocol/src/ast.js +8 -1
  56. package/out/zero-protocol/src/ast.js.map +1 -1
  57. package/out/zero-react/src/use-query.d.ts.map +1 -1
  58. package/out/zero-solid/src/mod.d.ts +2 -0
  59. package/out/zero-solid/src/mod.d.ts.map +1 -0
  60. package/out/zero-solid/src/solid-view.d.ts +10 -0
  61. package/out/zero-solid/src/solid-view.d.ts.map +1 -0
  62. package/out/zero-solid/src/use-query.d.ts +4 -0
  63. package/out/zero-solid/src/use-query.d.ts.map +1 -0
  64. package/out/zero.js +445 -673
  65. package/out/zero.js.map +4 -4
  66. package/out/zql/src/zql/ivm/array-view.d.ts +1 -10
  67. package/out/zql/src/zql/ivm/array-view.d.ts.map +1 -1
  68. package/out/zql/src/zql/ivm/array-view.js +2 -158
  69. package/out/zql/src/zql/ivm/array-view.js.map +1 -1
  70. package/out/zql/src/zql/ivm/view-apply-change.d.ts +5 -0
  71. package/out/zql/src/zql/ivm/view-apply-change.d.ts.map +1 -0
  72. package/out/zql/src/zql/ivm/view-apply-change.js +156 -0
  73. package/out/zql/src/zql/ivm/view-apply-change.js.map +1 -0
  74. package/out/zql/src/zql/ivm/view.d.ts +15 -0
  75. package/out/zql/src/zql/ivm/view.d.ts.map +1 -0
  76. package/out/zql/src/zql/ivm/view.js +2 -0
  77. package/out/zql/src/zql/ivm/view.js.map +1 -0
  78. package/out/zql/src/zql/query/query-impl.d.ts +11 -12
  79. package/out/zql/src/zql/query/query-impl.d.ts.map +1 -1
  80. package/out/zql/src/zql/query/query-impl.js +51 -37
  81. package/out/zql/src/zql/query/query-impl.js.map +1 -1
  82. package/out/zql/src/zql/query/query-internal.d.ts +11 -0
  83. package/out/zql/src/zql/query/query-internal.d.ts.map +1 -0
  84. package/out/zql/src/zql/query/query-internal.js +2 -0
  85. package/out/zql/src/zql/query/query-internal.js.map +1 -0
  86. package/out/zql/src/zql/query/query.d.ts +0 -2
  87. package/out/zql/src/zql/query/query.d.ts.map +1 -1
  88. package/package.json +9 -1
package/out/zero.js CHANGED
@@ -1,74 +1,28 @@
1
1
  import {
2
- __export,
3
- __reExport,
4
2
  hasOwn
5
- } from "./chunk-2RUT5EQV.js";
3
+ } from "./chunk-HARIWJ2J.js";
4
+ import {
5
+ applyChange,
6
+ assert,
7
+ assertArray,
8
+ assertBoolean,
9
+ assertNotNull,
10
+ assertNotUndefined,
11
+ assertNumber,
12
+ assertObject,
13
+ assertString,
14
+ must,
15
+ throwInvalidType,
16
+ unreachable
17
+ } from "./chunk-RCVGGCMG.js";
18
+ import {
19
+ __export,
20
+ __reExport
21
+ } from "./chunk-F5QR3K72.js";
6
22
 
7
23
  // ../replicache/src/mod.ts
8
24
  import { consoleLogSink as consoleLogSink3 } from "@rocicorp/logger";
9
25
 
10
- // ../shared/src/asserts.ts
11
- function assert(b, msg = "Assertion failed") {
12
- if (!b) {
13
- throw new Error(msg);
14
- }
15
- }
16
- function assertString(v2) {
17
- assertType(v2, "string");
18
- }
19
- function assertNumber(v2) {
20
- assertType(v2, "number");
21
- }
22
- function assertBoolean(v2) {
23
- assertType(v2, "boolean");
24
- }
25
- function assertType(v2, t2) {
26
- if (typeof v2 !== t2) {
27
- throwInvalidType(v2, t2);
28
- }
29
- }
30
- function assertObject(v2) {
31
- if (v2 === null) {
32
- throwInvalidType(v2, "object");
33
- }
34
- assertType(v2, "object");
35
- }
36
- function assertArray(v2) {
37
- if (!Array.isArray(v2)) {
38
- throwInvalidType(v2, "array");
39
- }
40
- }
41
- function invalidType(v2, t2) {
42
- let s = "Invalid type: ";
43
- if (v2 === null || v2 === void 0) {
44
- s += v2;
45
- } else {
46
- s += `${typeof v2} \`${v2}\``;
47
- }
48
- return s + `, expected ${t2}`;
49
- }
50
- function throwInvalidType(v2, t2) {
51
- throw new Error(invalidType(v2, t2));
52
- }
53
- function assertNotNull(v2) {
54
- if (v2 === null) {
55
- throw new Error("Expected non-null value");
56
- }
57
- }
58
- function assertUndefined(v2, msg = "Expected undefined value") {
59
- if (v2 !== void 0) {
60
- throw new Error(msg);
61
- }
62
- }
63
- function assertNotUndefined(v2, msg = "Expected non undefined value") {
64
- if (v2 === void 0) {
65
- throw new Error(msg);
66
- }
67
- }
68
- function unreachable(_) {
69
- throw new Error("Unreachable");
70
- }
71
-
72
26
  // ../shared/src/config.ts
73
27
  var isProd = process.env.NODE_ENV === "production";
74
28
 
@@ -1049,13 +1003,13 @@ var Chunk = class {
1049
1003
  * chunk.
1050
1004
  */
1051
1005
  meta;
1052
- constructor(hash2, data, refs) {
1006
+ constructor(hash, data, refs) {
1053
1007
  assert(
1054
- !refs.includes(hash2),
1008
+ !refs.includes(hash),
1055
1009
  "Chunk cannot reference itself"
1056
1010
  );
1057
1011
  assertDeepFrozen(data);
1058
- this.hash = hash2;
1012
+ this.hash = hash;
1059
1013
  this.data = data;
1060
1014
  this.meta = refs;
1061
1015
  }
@@ -1072,8 +1026,8 @@ function assertRefs(v2) {
1072
1026
  }
1073
1027
  }
1074
1028
  function createChunk(data, refs, chunkHasher) {
1075
- const hash2 = chunkHasher();
1076
- return new Chunk(hash2, data, refs);
1029
+ const hash = chunkHasher();
1030
+ return new Chunk(hash, data, refs);
1077
1031
  }
1078
1032
  function throwChunkHasher() {
1079
1033
  throw new Error("unexpected call to compute chunk hash");
@@ -1117,7 +1071,7 @@ var RefCountUpdates = class {
1117
1071
  await Promise.all(
1118
1072
  Array.from(
1119
1073
  this.#putChunks.values(),
1120
- (hash2) => this.#ensureRefCountLoaded(hash2)
1074
+ (hash) => this.#ensureRefCountLoaded(hash)
1121
1075
  )
1122
1076
  );
1123
1077
  if (this.#isLazyDelegate) {
@@ -1126,9 +1080,9 @@ var RefCountUpdates = class {
1126
1080
  let refCountsUpdated;
1127
1081
  do {
1128
1082
  refCountsUpdated = false;
1129
- for (const hash2 of this.#putChunks.values()) {
1130
- if (!this.#delegate.areRefsCounted(hash2) && !this.#refsCounted.has(hash2) && this.#refCountUpdates.get(hash2) !== 0) {
1131
- await this.#updateRefsCounts(hash2, 1);
1083
+ for (const hash of this.#putChunks.values()) {
1084
+ if (!this.#delegate.areRefsCounted(hash) && !this.#refsCounted.has(hash) && this.#refCountUpdates.get(hash) !== 0) {
1085
+ await this.#updateRefsCounts(hash, 1);
1132
1086
  refCountsUpdated = true;
1133
1087
  break;
1134
1088
  }
@@ -1139,67 +1093,67 @@ var RefCountUpdates = class {
1139
1093
  await this.#changeRefCount(o, -1);
1140
1094
  }
1141
1095
  if (!isProd) {
1142
- for (const [hash2, update] of this.#refCountUpdates) {
1096
+ for (const [hash, update] of this.#refCountUpdates) {
1143
1097
  assert(
1144
1098
  update >= 0,
1145
- `ref count update must be non-negative. ${hash2}:${update}`
1099
+ `ref count update must be non-negative. ${hash}:${update}`
1146
1100
  );
1147
1101
  }
1148
1102
  }
1149
1103
  return this.#refCountUpdates;
1150
1104
  }
1151
- async #changeRefCount(hash2, delta) {
1152
- await this.#ensureRefCountLoaded(hash2);
1153
- if (this.#updateRefCount(hash2, delta)) {
1154
- await this.#updateRefsCounts(hash2, delta);
1105
+ async #changeRefCount(hash, delta) {
1106
+ await this.#ensureRefCountLoaded(hash);
1107
+ if (this.#updateRefCount(hash, delta)) {
1108
+ await this.#updateRefsCounts(hash, delta);
1155
1109
  }
1156
1110
  }
1157
- async #updateRefsCounts(hash2, delta) {
1158
- if (hash2 === emptyHash) {
1111
+ async #updateRefsCounts(hash, delta) {
1112
+ if (hash === emptyHash) {
1159
1113
  return;
1160
1114
  }
1161
- const refs = await this.#delegate.getRefs(hash2);
1115
+ const refs = await this.#delegate.getRefs(hash);
1162
1116
  if (!isProd) {
1163
1117
  assert(
1164
- refs || this.#isLazyDelegate && !this.#putChunks.has(hash2),
1118
+ refs || this.#isLazyDelegate && !this.#putChunks.has(hash),
1165
1119
  "refs must be defined"
1166
1120
  );
1167
1121
  }
1168
1122
  if (refs !== void 0) {
1169
- this.#refsCounted?.add(hash2);
1123
+ this.#refsCounted?.add(hash);
1170
1124
  const ps = refs.map((ref) => this.#changeRefCount(ref, delta));
1171
1125
  await Promise.all(ps);
1172
1126
  }
1173
1127
  }
1174
- #ensureRefCountLoaded(hash2) {
1175
- let p = this.#loadedRefCountPromises.get(hash2);
1128
+ #ensureRefCountLoaded(hash) {
1129
+ let p = this.#loadedRefCountPromises.get(hash);
1176
1130
  if (p === void 0) {
1177
1131
  p = (async () => {
1178
- const value = await this.#delegate.getRefCount(hash2) || 0;
1179
- this.#refCountUpdates.set(hash2, value);
1132
+ const value = await this.#delegate.getRefCount(hash) || 0;
1133
+ this.#refCountUpdates.set(hash, value);
1180
1134
  return value;
1181
1135
  })();
1182
- this.#loadedRefCountPromises.set(hash2, p);
1136
+ this.#loadedRefCountPromises.set(hash, p);
1183
1137
  }
1184
1138
  return p;
1185
1139
  }
1186
- #updateRefCount(hash2, delta) {
1187
- const oldCount = this.#refCountUpdates.get(hash2);
1140
+ #updateRefCount(hash, delta) {
1141
+ const oldCount = this.#refCountUpdates.get(hash);
1188
1142
  assertNumber(oldCount);
1189
- this.#refCountUpdates.set(hash2, oldCount + delta);
1143
+ this.#refCountUpdates.set(hash, oldCount + delta);
1190
1144
  return oldCount === 0 && delta === 1 || oldCount === 1 && delta === -1;
1191
1145
  }
1192
1146
  };
1193
1147
 
1194
1148
  // ../replicache/src/dag/key.ts
1195
- function chunkDataKey(hash2) {
1196
- return `c/${hash2}/d`;
1149
+ function chunkDataKey(hash) {
1150
+ return `c/${hash}/d`;
1197
1151
  }
1198
- function chunkMetaKey(hash2) {
1199
- return `c/${hash2}/m`;
1152
+ function chunkMetaKey(hash) {
1153
+ return `c/${hash}/m`;
1200
1154
  }
1201
- function chunkRefCountKey(hash2) {
1202
- return `c/${hash2}/r`;
1155
+ function chunkRefCountKey(hash) {
1156
+ return `c/${hash}/r`;
1203
1157
  }
1204
1158
  function headKey(name) {
1205
1159
  return `h/${name}`;
@@ -1209,22 +1163,22 @@ function headKey(name) {
1209
1163
  var ChunkNotFoundError = class extends Error {
1210
1164
  name = "ChunkNotFoundError";
1211
1165
  hash;
1212
- constructor(hash2) {
1213
- super(`Chunk not found ${hash2}`);
1214
- this.hash = hash2;
1166
+ constructor(hash) {
1167
+ super(`Chunk not found ${hash}`);
1168
+ this.hash = hash;
1215
1169
  }
1216
1170
  };
1217
- async function mustGetChunk(store, hash2) {
1218
- const chunk = await store.getChunk(hash2);
1171
+ async function mustGetChunk(store, hash) {
1172
+ const chunk = await store.getChunk(hash);
1219
1173
  if (chunk) {
1220
1174
  return chunk;
1221
1175
  }
1222
- throw new ChunkNotFoundError(hash2);
1176
+ throw new ChunkNotFoundError(hash);
1223
1177
  }
1224
1178
  async function mustGetHeadHash(name, store) {
1225
- const hash2 = await store.getHead(name);
1226
- assert(hash2, `Missing head ${name}`);
1227
- return hash2;
1179
+ const hash = await store.getHead(name);
1180
+ assert(hash, `Missing head ${name}`);
1181
+ return hash;
1228
1182
  }
1229
1183
 
1230
1184
  // ../replicache/src/dag/store-impl.ts
@@ -1258,15 +1212,15 @@ var ReadImpl2 = class {
1258
1212
  this._tx = kv;
1259
1213
  this.assertValidHash = assertValidHash;
1260
1214
  }
1261
- hasChunk(hash2) {
1262
- return this._tx.has(chunkDataKey(hash2));
1215
+ hasChunk(hash) {
1216
+ return this._tx.has(chunkDataKey(hash));
1263
1217
  }
1264
- async getChunk(hash2) {
1265
- const data = await this._tx.get(chunkDataKey(hash2));
1218
+ async getChunk(hash) {
1219
+ const data = await this._tx.get(chunkDataKey(hash));
1266
1220
  if (data === void 0) {
1267
1221
  return void 0;
1268
1222
  }
1269
- const refsVal = await this._tx.get(chunkMetaKey(hash2));
1223
+ const refsVal = await this._tx.get(chunkMetaKey(hash));
1270
1224
  let refs;
1271
1225
  if (refsVal !== void 0) {
1272
1226
  assertRefs(refsVal);
@@ -1274,10 +1228,10 @@ var ReadImpl2 = class {
1274
1228
  } else {
1275
1229
  refs = [];
1276
1230
  }
1277
- return new Chunk(hash2, data, refs);
1231
+ return new Chunk(hash, data, refs);
1278
1232
  }
1279
- mustGetChunk(hash2) {
1280
- return mustGetChunk(this, hash2);
1233
+ mustGetChunk(hash) {
1234
+ return mustGetChunk(this, hash);
1281
1235
  }
1282
1236
  async getHead(name) {
1283
1237
  const data = await this._tx.get(headKey(name));
@@ -1307,41 +1261,41 @@ var WriteImpl2 = class extends ReadImpl2 {
1307
1261
  return this._tx;
1308
1262
  }
1309
1263
  async putChunk(c) {
1310
- const { hash: hash2, data, meta } = c;
1311
- this.assertValidHash(hash2);
1312
- const key = chunkDataKey(hash2);
1264
+ const { hash, data, meta } = c;
1265
+ this.assertValidHash(hash);
1266
+ const key = chunkDataKey(hash);
1313
1267
  const p1 = this._tx.put(key, data);
1314
1268
  let p2;
1315
1269
  if (meta.length > 0) {
1316
1270
  for (const h of meta) {
1317
1271
  this.assertValidHash(h);
1318
1272
  }
1319
- p2 = this._tx.put(chunkMetaKey(hash2), meta);
1273
+ p2 = this._tx.put(chunkMetaKey(hash), meta);
1320
1274
  }
1321
- this.#putChunks.add(hash2);
1275
+ this.#putChunks.add(hash);
1322
1276
  await p1;
1323
1277
  await p2;
1324
1278
  }
1325
- setHead(name, hash2) {
1326
- return this.#setHead(name, hash2);
1279
+ setHead(name, hash) {
1280
+ return this.#setHead(name, hash);
1327
1281
  }
1328
1282
  removeHead(name) {
1329
1283
  return this.#setHead(name, void 0);
1330
1284
  }
1331
- async #setHead(name, hash2) {
1285
+ async #setHead(name, hash) {
1332
1286
  const oldHash = await this.getHead(name);
1333
1287
  const hk = headKey(name);
1334
1288
  let p1;
1335
- if (hash2 === void 0) {
1289
+ if (hash === void 0) {
1336
1290
  p1 = this._tx.del(hk);
1337
1291
  } else {
1338
- p1 = this._tx.put(hk, hash2);
1292
+ p1 = this._tx.put(hk, hash);
1339
1293
  }
1340
1294
  const v2 = this.#changedHeads.get(name);
1341
1295
  if (v2 === void 0) {
1342
- this.#changedHeads.set(name, { new: hash2, old: oldHash });
1296
+ this.#changedHeads.set(name, { new: hash, old: oldHash });
1343
1297
  } else {
1344
- v2.new = hash2;
1298
+ v2.new = hash;
1345
1299
  }
1346
1300
  await p1;
1347
1301
  }
@@ -1354,8 +1308,8 @@ var WriteImpl2 = class extends ReadImpl2 {
1354
1308
  await this.#applyRefCountUpdates(refCountUpdates);
1355
1309
  await this._tx.commit();
1356
1310
  }
1357
- async getRefCount(hash2) {
1358
- const value = await this._tx.get(chunkRefCountKey(hash2));
1311
+ async getRefCount(hash) {
1312
+ const value = await this._tx.get(chunkRefCountKey(hash));
1359
1313
  if (value === void 0) {
1360
1314
  return void 0;
1361
1315
  }
@@ -1367,8 +1321,8 @@ var WriteImpl2 = class extends ReadImpl2 {
1367
1321
  }
1368
1322
  return value;
1369
1323
  }
1370
- async getRefs(hash2) {
1371
- const meta = await this._tx.get(chunkMetaKey(hash2));
1324
+ async getRefs(hash) {
1325
+ const meta = await this._tx.get(chunkMetaKey(hash));
1372
1326
  if (meta === void 0) {
1373
1327
  return [];
1374
1328
  }
@@ -1377,23 +1331,23 @@ var WriteImpl2 = class extends ReadImpl2 {
1377
1331
  }
1378
1332
  async #applyRefCountUpdates(refCountCache) {
1379
1333
  const ps = [];
1380
- for (const [hash2, count] of refCountCache) {
1334
+ for (const [hash, count] of refCountCache) {
1381
1335
  if (count === 0) {
1382
- ps.push(this.#removeAllRelatedKeys(hash2));
1336
+ ps.push(this.#removeAllRelatedKeys(hash));
1383
1337
  } else {
1384
- const refCountKey = chunkRefCountKey(hash2);
1338
+ const refCountKey = chunkRefCountKey(hash);
1385
1339
  ps.push(this._tx.put(refCountKey, count));
1386
1340
  }
1387
1341
  }
1388
1342
  await Promise.all(ps);
1389
1343
  }
1390
- async #removeAllRelatedKeys(hash2) {
1344
+ async #removeAllRelatedKeys(hash) {
1391
1345
  await Promise.all([
1392
- this._tx.del(chunkDataKey(hash2)),
1393
- this._tx.del(chunkMetaKey(hash2)),
1394
- this._tx.del(chunkRefCountKey(hash2))
1346
+ this._tx.del(chunkDataKey(hash)),
1347
+ this._tx.del(chunkMetaKey(hash)),
1348
+ this._tx.del(chunkRefCountKey(hash))
1395
1349
  ]);
1396
- this.#putChunks.delete(hash2);
1350
+ this.#putChunks.delete(hash);
1397
1351
  }
1398
1352
  release() {
1399
1353
  this._tx.release();
@@ -2151,28 +2105,28 @@ var LazyRead = class {
2151
2105
  this.#release = release;
2152
2106
  this.assertValidHash = assertValidHash;
2153
2107
  }
2154
- isMemOnlyChunkHash(hash2) {
2155
- return this._memOnlyChunks.has(hash2);
2108
+ isMemOnlyChunkHash(hash) {
2109
+ return this._memOnlyChunks.has(hash);
2156
2110
  }
2157
- async hasChunk(hash2) {
2158
- return await this.getChunk(hash2) !== void 0;
2111
+ async hasChunk(hash) {
2112
+ return await this.getChunk(hash) !== void 0;
2159
2113
  }
2160
- async getChunk(hash2) {
2161
- const memOnlyChunk = this._memOnlyChunks.get(hash2);
2114
+ async getChunk(hash) {
2115
+ const memOnlyChunk = this._memOnlyChunks.get(hash);
2162
2116
  if (memOnlyChunk !== void 0) {
2163
2117
  return memOnlyChunk;
2164
2118
  }
2165
- let chunk = this._sourceChunksCache.get(hash2);
2119
+ let chunk = this._sourceChunksCache.get(hash);
2166
2120
  if (chunk === void 0) {
2167
- chunk = await (await this._getSourceRead()).getChunk(hash2);
2121
+ chunk = await (await this._getSourceRead()).getChunk(hash);
2168
2122
  if (chunk !== void 0) {
2169
2123
  this._sourceChunksCache.put(chunk);
2170
2124
  }
2171
2125
  }
2172
2126
  return chunk;
2173
2127
  }
2174
- mustGetChunk(hash2) {
2175
- return mustGetChunk(this, hash2);
2128
+ mustGetChunk(hash) {
2129
+ return mustGetChunk(this, hash);
2176
2130
  }
2177
2131
  getHead(name) {
2178
2132
  return Promise.resolve(this._heads.get(name));
@@ -2222,54 +2176,54 @@ var LazyWrite = class extends LazyRead {
2222
2176
  return chunk;
2223
2177
  };
2224
2178
  putChunk(c, size) {
2225
- const { hash: hash2, meta } = c;
2226
- this.assertValidHash(hash2);
2179
+ const { hash, meta } = c;
2180
+ this.assertValidHash(hash);
2227
2181
  if (meta.length > 0) {
2228
2182
  for (const h of meta) {
2229
2183
  this.assertValidHash(h);
2230
2184
  }
2231
2185
  }
2232
- if (this.#createdChunks.has(hash2) || this.isMemOnlyChunkHash(hash2)) {
2233
- this._pendingMemOnlyChunks.set(hash2, c);
2186
+ if (this.#createdChunks.has(hash) || this.isMemOnlyChunkHash(hash)) {
2187
+ this._pendingMemOnlyChunks.set(hash, c);
2234
2188
  } else {
2235
- this._pendingCachedChunks.set(hash2, { chunk: c, size: size ?? -1 });
2189
+ this._pendingCachedChunks.set(hash, { chunk: c, size: size ?? -1 });
2236
2190
  }
2237
2191
  return promiseVoid;
2238
2192
  }
2239
- async setHead(name, hash2) {
2240
- await this.#setHead(name, hash2);
2193
+ async setHead(name, hash) {
2194
+ await this.#setHead(name, hash);
2241
2195
  }
2242
2196
  async removeHead(name) {
2243
2197
  await this.#setHead(name, void 0);
2244
2198
  }
2245
- async #setHead(name, hash2) {
2199
+ async #setHead(name, hash) {
2246
2200
  const oldHash = await this.getHead(name);
2247
2201
  const v2 = this._pendingHeadChanges.get(name);
2248
2202
  if (v2 === void 0) {
2249
- this._pendingHeadChanges.set(name, { new: hash2, old: oldHash });
2203
+ this._pendingHeadChanges.set(name, { new: hash, old: oldHash });
2250
2204
  } else {
2251
- v2.new = hash2;
2205
+ v2.new = hash;
2252
2206
  }
2253
2207
  }
2254
- isMemOnlyChunkHash(hash2) {
2255
- return this._pendingMemOnlyChunks.has(hash2) || super.isMemOnlyChunkHash(hash2);
2208
+ isMemOnlyChunkHash(hash) {
2209
+ return this._pendingMemOnlyChunks.has(hash) || super.isMemOnlyChunkHash(hash);
2256
2210
  }
2257
- async getChunk(hash2) {
2258
- const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash2);
2211
+ async getChunk(hash) {
2212
+ const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash);
2259
2213
  if (pendingMemOnlyChunk !== void 0) {
2260
2214
  return pendingMemOnlyChunk;
2261
2215
  }
2262
- const memOnlyChunk = this._memOnlyChunks.get(hash2);
2216
+ const memOnlyChunk = this._memOnlyChunks.get(hash);
2263
2217
  if (memOnlyChunk !== void 0) {
2264
2218
  return memOnlyChunk;
2265
2219
  }
2266
- const pendingCachedChunk = this._pendingCachedChunks.get(hash2);
2220
+ const pendingCachedChunk = this._pendingCachedChunks.get(hash);
2267
2221
  if (pendingCachedChunk !== void 0) {
2268
2222
  return pendingCachedChunk.chunk;
2269
2223
  }
2270
- let chunk = this._sourceChunksCache.get(hash2);
2224
+ let chunk = this._sourceChunksCache.get(hash);
2271
2225
  if (chunk === void 0) {
2272
- chunk = await (await this._getSourceRead()).getChunk(hash2);
2226
+ chunk = await (await this._getSourceRead()).getChunk(hash);
2273
2227
  if (chunk !== void 0) {
2274
2228
  this._pendingCachedChunks.set(chunk.hash, { chunk, size: -1 });
2275
2229
  }
@@ -2295,21 +2249,21 @@ var LazyWrite = class extends LazyRead {
2295
2249
  pendingChunks,
2296
2250
  this
2297
2251
  );
2298
- for (const [hash2, count] of refCountUpdates) {
2299
- if (this.isMemOnlyChunkHash(hash2)) {
2252
+ for (const [hash, count] of refCountUpdates) {
2253
+ if (this.isMemOnlyChunkHash(hash)) {
2300
2254
  if (count === 0) {
2301
- this.#refCounts.delete(hash2);
2302
- this._memOnlyChunks.delete(hash2);
2303
- this.#refs.delete(hash2);
2255
+ this.#refCounts.delete(hash);
2256
+ this._memOnlyChunks.delete(hash);
2257
+ this.#refs.delete(hash);
2304
2258
  } else {
2305
- this.#refCounts.set(hash2, count);
2306
- const chunk = this._pendingMemOnlyChunks.get(hash2);
2259
+ this.#refCounts.set(hash, count);
2260
+ const chunk = this._pendingMemOnlyChunks.get(hash);
2307
2261
  if (chunk) {
2308
- this.#refs.set(hash2, chunk.meta);
2309
- this._memOnlyChunks.set(hash2, chunk);
2262
+ this.#refs.set(hash, chunk.meta);
2263
+ this._memOnlyChunks.set(hash, chunk);
2310
2264
  }
2311
2265
  }
2312
- refCountUpdates.delete(hash2);
2266
+ refCountUpdates.delete(hash);
2313
2267
  }
2314
2268
  }
2315
2269
  this._sourceChunksCache.updateForCommit(
@@ -2328,26 +2282,26 @@ var LazyWrite = class extends LazyRead {
2328
2282
  this._pendingHeadChanges.clear();
2329
2283
  this.release();
2330
2284
  }
2331
- getRefCount(hash2) {
2332
- return this.#refCounts.get(hash2);
2285
+ getRefCount(hash) {
2286
+ return this.#refCounts.get(hash);
2333
2287
  }
2334
- getRefs(hash2) {
2335
- const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash2);
2288
+ getRefs(hash) {
2289
+ const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash);
2336
2290
  if (pendingMemOnlyChunk) {
2337
2291
  return pendingMemOnlyChunk.meta;
2338
2292
  }
2339
- const memOnlyChunk = this._memOnlyChunks.get(hash2);
2293
+ const memOnlyChunk = this._memOnlyChunks.get(hash);
2340
2294
  if (memOnlyChunk) {
2341
2295
  return memOnlyChunk.meta;
2342
2296
  }
2343
- const pendingCachedChunk = this._pendingCachedChunks.get(hash2);
2297
+ const pendingCachedChunk = this._pendingCachedChunks.get(hash);
2344
2298
  if (pendingCachedChunk !== void 0) {
2345
2299
  return pendingCachedChunk.chunk.meta;
2346
2300
  }
2347
- return this.#refs.get(hash2);
2301
+ return this.#refs.get(hash);
2348
2302
  }
2349
- areRefsCounted(hash2) {
2350
- return this.#refs.has(hash2);
2303
+ areRefsCounted(hash) {
2304
+ return this.#refs.has(hash);
2351
2305
  }
2352
2306
  chunksPersisted(chunkHashes) {
2353
2307
  const chunksToCache = [];
@@ -2381,37 +2335,37 @@ var ChunksCache = class {
2381
2335
  this.#refCounts = refCounts;
2382
2336
  this.#refs = refs;
2383
2337
  }
2384
- get(hash2) {
2385
- const cacheEntry = this.cacheEntries.get(hash2);
2338
+ get(hash) {
2339
+ const cacheEntry = this.cacheEntries.get(hash);
2386
2340
  if (cacheEntry) {
2387
- this.cacheEntries.delete(hash2);
2388
- this.cacheEntries.set(hash2, cacheEntry);
2341
+ this.cacheEntries.delete(hash);
2342
+ this.cacheEntries.set(hash, cacheEntry);
2389
2343
  }
2390
2344
  return cacheEntry?.chunk;
2391
2345
  }
2392
- getWithoutUpdatingLRU(hash2) {
2393
- return this.cacheEntries.get(hash2)?.chunk;
2346
+ getWithoutUpdatingLRU(hash) {
2347
+ return this.cacheEntries.get(hash)?.chunk;
2394
2348
  }
2395
2349
  put(chunk) {
2396
- const { hash: hash2 } = chunk;
2397
- const oldCacheEntry = this.cacheEntries.get(hash2);
2350
+ const { hash } = chunk;
2351
+ const oldCacheEntry = this.cacheEntries.get(hash);
2398
2352
  if (oldCacheEntry) {
2399
- this.cacheEntries.delete(hash2);
2400
- this.cacheEntries.set(hash2, oldCacheEntry);
2353
+ this.cacheEntries.delete(hash);
2354
+ this.cacheEntries.set(hash, oldCacheEntry);
2401
2355
  return;
2402
2356
  }
2403
- const refCount = this.#refCounts.get(hash2);
2357
+ const refCount = this.#refCounts.get(hash);
2404
2358
  if (refCount === void 0 || refCount < 1) {
2405
2359
  return;
2406
2360
  }
2407
2361
  if (!this.#cacheChunk(chunk)) {
2408
2362
  return;
2409
2363
  }
2410
- if (!this.#refs.has(hash2)) {
2364
+ if (!this.#refs.has(hash)) {
2411
2365
  for (const refHash of chunk.meta) {
2412
2366
  this.#refCounts.set(refHash, (this.#refCounts.get(refHash) || 0) + 1);
2413
2367
  }
2414
- this.#refs.set(hash2, chunk.meta);
2368
+ this.#refs.set(hash, chunk.meta);
2415
2369
  }
2416
2370
  this.#ensureCacheSizeLimit();
2417
2371
  }
@@ -2436,40 +2390,40 @@ var ChunksCache = class {
2436
2390
  return true;
2437
2391
  }
2438
2392
  #evict(cacheEntry) {
2439
- const { hash: hash2 } = cacheEntry.chunk;
2393
+ const { hash } = cacheEntry.chunk;
2440
2394
  this.#size -= cacheEntry.size;
2441
- this.cacheEntries.delete(hash2);
2395
+ this.cacheEntries.delete(hash);
2442
2396
  }
2443
- #deleteEntryByHash(hash2) {
2444
- this.#refCounts.delete(hash2);
2445
- this.#refs.delete(hash2);
2446
- const cacheEntry = this.cacheEntries.get(hash2);
2397
+ #deleteEntryByHash(hash) {
2398
+ this.#refCounts.delete(hash);
2399
+ this.#refs.delete(hash);
2400
+ const cacheEntry = this.cacheEntries.get(hash);
2447
2401
  if (cacheEntry) {
2448
2402
  this.#size -= cacheEntry.size;
2449
- this.cacheEntries.delete(hash2);
2403
+ this.cacheEntries.delete(hash);
2450
2404
  }
2451
2405
  }
2452
2406
  updateForCommit(chunksToPut, refCountUpdates) {
2453
- for (const [hash2, count] of refCountUpdates) {
2407
+ for (const [hash, count] of refCountUpdates) {
2454
2408
  if (count === 0) {
2455
2409
  if (!this.#evictsAndDeletesSuspended) {
2456
- this.#deleteEntryByHash(hash2);
2410
+ this.#deleteEntryByHash(hash);
2457
2411
  } else {
2458
- this.#refCounts.set(hash2, 0);
2459
- this.#suspendedDeletes.push(hash2);
2412
+ this.#refCounts.set(hash, 0);
2413
+ this.#suspendedDeletes.push(hash);
2460
2414
  }
2461
2415
  } else {
2462
- this.#refCounts.set(hash2, count);
2463
- const chunkAndSize = chunksToPut.get(hash2);
2416
+ this.#refCounts.set(hash, count);
2417
+ const chunkAndSize = chunksToPut.get(hash);
2464
2418
  if (chunkAndSize) {
2465
2419
  const { chunk, size } = chunkAndSize;
2466
- const oldCacheEntry = this.cacheEntries.get(hash2);
2420
+ const oldCacheEntry = this.cacheEntries.get(hash);
2467
2421
  if (oldCacheEntry) {
2468
- this.cacheEntries.delete(hash2);
2469
- this.cacheEntries.set(hash2, oldCacheEntry);
2422
+ this.cacheEntries.delete(hash);
2423
+ this.cacheEntries.set(hash, oldCacheEntry);
2470
2424
  } else {
2471
2425
  this.#cacheChunk(chunk, size !== -1 ? size : void 0);
2472
- this.#refs.set(hash2, chunk.meta);
2426
+ this.#refs.set(hash, chunk.meta);
2473
2427
  }
2474
2428
  }
2475
2429
  }
@@ -2488,9 +2442,9 @@ var ChunksCache = class {
2488
2442
  return await fn();
2489
2443
  } finally {
2490
2444
  this.#evictsAndDeletesSuspended = false;
2491
- for (const hash2 of this.#suspendedDeletes) {
2492
- if (this.#refCounts.get(hash2) === 0) {
2493
- this.#deleteEntryByHash(hash2);
2445
+ for (const hash of this.#suspendedDeletes) {
2446
+ if (this.#refCounts.get(hash) === 0) {
2447
+ this.#deleteEntryByHash(hash);
2494
2448
  }
2495
2449
  }
2496
2450
  this.#ensureCacheSizeLimit();
@@ -2600,15 +2554,15 @@ async function localMutationsGreaterThan(commit, mutationIDLimits, dagRead) {
2600
2554
  return commits;
2601
2555
  }
2602
2556
  async function baseSnapshotFromHead(name, dagRead) {
2603
- const hash2 = await dagRead.getHead(name);
2604
- assert(hash2, `Missing head ${name}`);
2605
- return baseSnapshotFromHash(hash2, dagRead);
2557
+ const hash = await dagRead.getHead(name);
2558
+ assert(hash, `Missing head ${name}`);
2559
+ return baseSnapshotFromHash(hash, dagRead);
2606
2560
  }
2607
- async function baseSnapshotHashFromHash(hash2, dagRead) {
2608
- return (await baseSnapshotFromHash(hash2, dagRead)).chunk.hash;
2561
+ async function baseSnapshotHashFromHash(hash, dagRead) {
2562
+ return (await baseSnapshotFromHash(hash, dagRead)).chunk.hash;
2609
2563
  }
2610
- async function baseSnapshotFromHash(hash2, dagRead) {
2611
- const commit = await commitFromHash(hash2, dagRead);
2564
+ async function baseSnapshotFromHash(hash, dagRead) {
2565
+ const commit = await commitFromHash(hash, dagRead);
2612
2566
  return baseSnapshotFromCommit(commit, dagRead);
2613
2567
  }
2614
2568
  async function baseSnapshotFromCommit(commit, dagRead) {
@@ -2652,13 +2606,13 @@ async function commitChain(fromCommitHash, dagRead) {
2652
2606
  commits.push(commit);
2653
2607
  return commits;
2654
2608
  }
2655
- async function commitFromHash(hash2, dagRead) {
2656
- const chunk = await dagRead.mustGetChunk(hash2);
2609
+ async function commitFromHash(hash, dagRead) {
2610
+ const chunk = await dagRead.mustGetChunk(hash);
2657
2611
  return fromChunk(chunk);
2658
2612
  }
2659
2613
  async function commitFromHead(name, dagRead) {
2660
- const hash2 = await mustGetHeadHash(name, dagRead);
2661
- return commitFromHash(hash2, dagRead);
2614
+ const hash = await mustGetHeadHash(name, dagRead);
2615
+ return commitFromHash(hash, dagRead);
2662
2616
  }
2663
2617
  function assertIndexChangeMeta(v2) {
2664
2618
  assertNumber(v2.lastMutationID);
@@ -2950,8 +2904,8 @@ function makeNodeChunkData(level, entries, formatVersion) {
2950
2904
  formatVersion >= V7 ? entries : entries.map((e) => e.slice(0, 2))
2951
2905
  ]);
2952
2906
  }
2953
- async function findLeaf(key, hash2, source, expectedRootHash) {
2954
- const node = await source.getNode(hash2);
2907
+ async function findLeaf(key, hash, source, expectedRootHash) {
2908
+ const node = await source.getNode(hash);
2955
2909
  if (expectedRootHash !== source.rootHash) {
2956
2910
  return findLeaf(key, source.rootHash, source, source.rootHash);
2957
2911
  }
@@ -3015,9 +2969,9 @@ var NodeImpl = class {
3015
2969
  hash;
3016
2970
  isMutable;
3017
2971
  #childNodeSize = -1;
3018
- constructor(entries, hash2, isMutable) {
2972
+ constructor(entries, hash, isMutable) {
3019
2973
  this.entries = entries;
3020
- this.hash = hash2;
2974
+ this.hash = hash;
3021
2975
  this.isMutable = isMutable;
3022
2976
  }
3023
2977
  maxKey() {
@@ -3096,8 +3050,8 @@ function readonlySplice(array9, start, deleteCount, ...items) {
3096
3050
  }
3097
3051
  var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
3098
3052
  level;
3099
- constructor(entries, hash2, level, isMutable) {
3100
- super(entries, hash2, isMutable);
3053
+ constructor(entries, hash, level, isMutable) {
3054
+ super(entries, hash, isMutable);
3101
3055
  this.level = level;
3102
3056
  }
3103
3057
  async set(key, value, entrySize, tree) {
@@ -3129,8 +3083,8 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
3129
3083
  let startIndex;
3130
3084
  let removeCount;
3131
3085
  if (i > 0) {
3132
- const hash2 = thisEntries[i - 1][1];
3133
- const previousSibling = await tree.getNode(hash2);
3086
+ const hash = thisEntries[i - 1][1];
3087
+ const previousSibling = await tree.getNode(hash);
3134
3088
  values = joinIterables(
3135
3089
  previousSibling.entries,
3136
3090
  childNode.entries
@@ -3138,8 +3092,8 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
3138
3092
  startIndex = i - 1;
3139
3093
  removeCount = 2;
3140
3094
  } else if (i < thisEntries.length - 1) {
3141
- const hash2 = thisEntries[i + 1][1];
3142
- const nextSibling = await tree.getNode(hash2);
3095
+ const hash = thisEntries[i + 1][1];
3096
+ const nextSibling = await tree.getNode(hash);
3143
3097
  values = joinIterables(
3144
3098
  childNode.entries,
3145
3099
  nextSibling.entries
@@ -3253,15 +3207,15 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
3253
3207
  return new DataNodeImpl(entries, newRandomHash(), true);
3254
3208
  }
3255
3209
  };
3256
- function newNodeImpl(entries, hash2, level, isMutable) {
3210
+ function newNodeImpl(entries, hash, level, isMutable) {
3257
3211
  if (level === 0) {
3258
3212
  return new DataNodeImpl(
3259
3213
  entries,
3260
- hash2,
3214
+ hash,
3261
3215
  isMutable
3262
3216
  );
3263
3217
  }
3264
- return new InternalNodeImpl(entries, hash2, level, isMutable);
3218
+ return new InternalNodeImpl(entries, hash, level, isMutable);
3265
3219
  }
3266
3220
  function isDataNodeImpl(node) {
3267
3221
  return node.level === 0;
@@ -3407,15 +3361,15 @@ var BTreeRead = class {
3407
3361
  this.getEntrySize = getEntrySize;
3408
3362
  this.chunkHeaderSize = chunkHeaderSize;
3409
3363
  }
3410
- async getNode(hash2) {
3411
- if (hash2 === emptyHash) {
3364
+ async getNode(hash) {
3365
+ if (hash === emptyHash) {
3412
3366
  return emptyDataNodeImpl;
3413
3367
  }
3414
- const cached = this._cache.get(hash2);
3368
+ const cached = this._cache.get(hash);
3415
3369
  if (cached) {
3416
3370
  return cached;
3417
3371
  }
3418
- const chunk = await this._dagRead.mustGetChunk(hash2);
3372
+ const chunk = await this._dagRead.mustGetChunk(hash);
3419
3373
  const data = parseBTreeNode(
3420
3374
  chunk.data,
3421
3375
  this._formatVersion,
@@ -3423,11 +3377,11 @@ var BTreeRead = class {
3423
3377
  );
3424
3378
  const impl = newNodeImpl(
3425
3379
  data[NODE_ENTRIES],
3426
- hash2,
3380
+ hash,
3427
3381
  data[NODE_LEVEL],
3428
3382
  false
3429
3383
  );
3430
- this._cache.set(hash2, impl);
3384
+ this._cache.set(hash, impl);
3431
3385
  return impl;
3432
3386
  }
3433
3387
  async get(key) {
@@ -3461,15 +3415,15 @@ var BTreeRead = class {
3461
3415
  () => this.rootHash,
3462
3416
  this.rootHash,
3463
3417
  fromKey,
3464
- async (hash2) => {
3465
- const cached = await this.getNode(hash2);
3418
+ async (hash) => {
3419
+ const cached = await this.getNode(hash);
3466
3420
  if (cached) {
3467
3421
  return [
3468
3422
  cached.level,
3469
3423
  cached.isMutable ? cached.entries.slice() : cached.entries
3470
3424
  ];
3471
3425
  }
3472
- const chunk = await this._dagRead.mustGetChunk(hash2);
3426
+ const chunk = await this._dagRead.mustGetChunk(hash);
3473
3427
  return parseBTreeNode(
3474
3428
  chunk.data,
3475
3429
  this._formatVersion,
@@ -3593,11 +3547,11 @@ function* diffEntries(lastEntries, currentEntries) {
3593
3547
  };
3594
3548
  }
3595
3549
  }
3596
- async function* scanForHash(expectedRootHash, getRootHash, hash2, fromKey, readNode) {
3597
- if (hash2 === emptyHash) {
3550
+ async function* scanForHash(expectedRootHash, getRootHash, hash, fromKey, readNode) {
3551
+ if (hash === emptyHash) {
3598
3552
  return;
3599
3553
  }
3600
- const data = await readNode(hash2);
3554
+ const data = await readNode(hash);
3601
3555
  const entries = data[NODE_ENTRIES];
3602
3556
  let i = 0;
3603
3557
  if (fromKey) {
@@ -4306,10 +4260,10 @@ var BTreeWrite = class extends BTreeRead {
4306
4260
  });
4307
4261
  }
4308
4262
  };
4309
- function gatherNewChunks(hash2, newChunks, createChunk2, modified, formatVersion) {
4310
- const node = modified.get(hash2);
4263
+ function gatherNewChunks(hash, newChunks, createChunk2, modified, formatVersion) {
4264
+ const node = modified.get(hash);
4311
4265
  if (node === void 0) {
4312
- return hash2;
4266
+ return hash;
4313
4267
  }
4314
4268
  if (isDataNodeImpl(node)) {
4315
4269
  const chunk2 = createChunk2(toChunkData(node, formatVersion), []);
@@ -4984,16 +4938,16 @@ function clientGroupMapToChunkData(clientGroups, dagWrite) {
4984
4938
  }
4985
4939
  return deepFreeze(chunkData);
4986
4940
  }
4987
- async function getClientGroupsAtHash(hash2, dagRead) {
4988
- const chunk = await dagRead.getChunk(hash2);
4941
+ async function getClientGroupsAtHash(hash, dagRead) {
4942
+ const chunk = await dagRead.getChunk(hash);
4989
4943
  return chunkDataToClientGroupMap(chunk?.data);
4990
4944
  }
4991
4945
  async function getClientGroups(dagRead) {
4992
- const hash2 = await dagRead.getHead(CLIENT_GROUPS_HEAD_NAME);
4993
- if (!hash2) {
4946
+ const hash = await dagRead.getHead(CLIENT_GROUPS_HEAD_NAME);
4947
+ if (!hash) {
4994
4948
  return /* @__PURE__ */ new Map();
4995
4949
  }
4996
- return getClientGroupsAtHash(hash2, dagRead);
4950
+ return getClientGroupsAtHash(hash, dagRead);
4997
4951
  }
4998
4952
  async function setClientGroups(clientGroups, dagWrite) {
4999
4953
  const currClientGroups = await getClientGroups(dagWrite);
@@ -5250,14 +5204,14 @@ function clientMapToChunkData(clients, dagWrite) {
5250
5204
  return deepFreeze(Object.fromEntries(clients));
5251
5205
  }
5252
5206
  async function getClients(dagRead) {
5253
- const hash2 = await dagRead.getHead(CLIENTS_HEAD_NAME);
5254
- return getClientsAtHash(hash2, dagRead);
5207
+ const hash = await dagRead.getHead(CLIENTS_HEAD_NAME);
5208
+ return getClientsAtHash(hash, dagRead);
5255
5209
  }
5256
- async function getClientsAtHash(hash2, dagRead) {
5257
- if (!hash2) {
5210
+ async function getClientsAtHash(hash, dagRead) {
5211
+ if (!hash) {
5258
5212
  return /* @__PURE__ */ new Map();
5259
5213
  }
5260
- const chunk = await dagRead.getChunk(hash2);
5214
+ const chunk = await dagRead.getChunk(hash);
5261
5215
  return chunkDataToClientMap(chunk?.data);
5262
5216
  }
5263
5217
  var ClientStateNotFoundError = class extends Error {
@@ -5448,8 +5402,8 @@ function getRefsForClients(clients) {
5448
5402
  const refs = /* @__PURE__ */ new Set();
5449
5403
  for (const client of clients.values()) {
5450
5404
  if (isClientV6(client)) {
5451
- for (const hash2 of client.refreshHashes) {
5452
- refs.add(hash2);
5405
+ for (const hash of client.refreshHashes) {
5406
+ refs.add(hash);
5453
5407
  }
5454
5408
  if (client.persistHash) {
5455
5409
  refs.add(client.persistHash);
@@ -9227,12 +9181,156 @@ async function anyPendingMutationsInClientGroups(perdag) {
9227
9181
  // ../zql/src/zql/query/query-impl.ts
9228
9182
  import { resolver as resolver7 } from "@rocicorp/resolver";
9229
9183
 
9230
- // ../shared/src/must.ts
9231
- function must(v2, msg) {
9232
- if (v2 == null) {
9233
- throw new Error(msg ?? `Unexpected ${v2} value`);
9184
+ // ../shared/src/xxhash.ts
9185
+ import xxhash from "xxhash-wasm";
9186
+ var { create64, h32, h64 } = await xxhash();
9187
+
9188
+ // ../zero-protocol/src/ast.ts
9189
+ import { compareUTF8 as compareUTF83 } from "compare-utf8";
9190
+ var selectorSchema = valita_exports.string();
9191
+ var orderingElementSchema = readonly(
9192
+ valita_exports.tuple([selectorSchema, valita_exports.union(valita_exports.literal("asc"), valita_exports.literal("desc"))])
9193
+ );
9194
+ var orderingSchema = readonlyArray(orderingElementSchema);
9195
+ var primitiveSchema = valita_exports.union(
9196
+ valita_exports.string(),
9197
+ valita_exports.number(),
9198
+ valita_exports.boolean(),
9199
+ valita_exports.null()
9200
+ );
9201
+ var equalityOpsSchema = valita_exports.union(valita_exports.literal("="), valita_exports.literal("!="));
9202
+ var orderOpsSchema = valita_exports.union(
9203
+ valita_exports.literal("<"),
9204
+ valita_exports.literal(">"),
9205
+ valita_exports.literal("<="),
9206
+ valita_exports.literal(">=")
9207
+ );
9208
+ var likeOpsSchema = valita_exports.union(
9209
+ valita_exports.literal("LIKE"),
9210
+ valita_exports.literal("NOT LIKE"),
9211
+ valita_exports.literal("ILIKE"),
9212
+ valita_exports.literal("NOT ILIKE")
9213
+ );
9214
+ var inOpsSchema = valita_exports.union(valita_exports.literal("IN"), valita_exports.literal("NOT IN"));
9215
+ var simpleOperatorSchema = valita_exports.union(
9216
+ equalityOpsSchema,
9217
+ orderOpsSchema,
9218
+ likeOpsSchema,
9219
+ inOpsSchema
9220
+ );
9221
+ var simpleConditionSchema = valita_exports.object({
9222
+ type: valita_exports.literal("simple"),
9223
+ op: simpleOperatorSchema,
9224
+ field: selectorSchema,
9225
+ value: valita_exports.union(
9226
+ valita_exports.string(),
9227
+ valita_exports.number(),
9228
+ valita_exports.boolean(),
9229
+ readonlyArray(valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean())),
9230
+ valita_exports.object({
9231
+ type: valita_exports.literal("static"),
9232
+ anchor: valita_exports.union(valita_exports.literal("authData"), valita_exports.literal("preMutationRow")),
9233
+ field: valita_exports.string()
9234
+ })
9235
+ )
9236
+ });
9237
+ var conditionSchema = simpleConditionSchema;
9238
+ var correlatedSubquerySchemaOmitSubquery = valita_exports.object({
9239
+ correlation: valita_exports.object({
9240
+ parentField: valita_exports.string(),
9241
+ childField: valita_exports.string(),
9242
+ op: valita_exports.literal("=")
9243
+ }),
9244
+ hidden: valita_exports.boolean().optional()
9245
+ });
9246
+ var correlatedSubquerySchema = correlatedSubquerySchemaOmitSubquery.extend({
9247
+ subquery: valita_exports.lazy(() => astSchema)
9248
+ });
9249
+ var astSchema = valita_exports.object({
9250
+ schema: valita_exports.string().optional(),
9251
+ table: valita_exports.string(),
9252
+ alias: valita_exports.string().optional(),
9253
+ where: readonlyArray(conditionSchema).optional(),
9254
+ related: readonlyArray(correlatedSubquerySchema).optional(),
9255
+ limit: valita_exports.number().optional(),
9256
+ orderBy: orderingSchema.optional(),
9257
+ start: valita_exports.object({
9258
+ row: valita_exports.record(
9259
+ valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean(), valita_exports.null(), valita_exports.undefined())
9260
+ ),
9261
+ exclusive: valita_exports.boolean()
9262
+ }).optional()
9263
+ });
9264
+ var normalizeCache = /* @__PURE__ */ new WeakMap();
9265
+ function normalizeAST(ast) {
9266
+ const cached = normalizeCache.get(ast);
9267
+ if (cached) {
9268
+ return cached;
9269
+ }
9270
+ const normalized = {
9271
+ schema: ast.schema,
9272
+ table: ast.table,
9273
+ alias: ast.alias,
9274
+ where: ast.where ? sortedWhere(ast.where) : void 0,
9275
+ related: ast.related ? sortedRelated(
9276
+ ast.related.map(
9277
+ (r) => ({
9278
+ correlation: {
9279
+ parentField: r.correlation.parentField,
9280
+ childField: r.correlation.childField,
9281
+ op: r.correlation.op
9282
+ },
9283
+ hidden: r.hidden,
9284
+ subquery: normalizeAST(r.subquery)
9285
+ })
9286
+ )
9287
+ ) : void 0,
9288
+ start: ast.start,
9289
+ limit: ast.limit,
9290
+ orderBy: ast.orderBy
9291
+ };
9292
+ normalizeCache.set(ast, normalized);
9293
+ return normalized;
9294
+ }
9295
+ function sortedWhere(where) {
9296
+ return [...where].sort(cmpCondition);
9297
+ }
9298
+ function sortedRelated(related) {
9299
+ return related.sort(cmpRelated);
9300
+ }
9301
+ function cmpCondition(a, b) {
9302
+ return compareUTF8MaybeNull(a.field, b.field) || compareUTF8MaybeNull(a.op, b.op) || // Comparing the same field with the same op more than once doesn't make logical
9303
+ // sense, but is technically possible. Assume the values are of the same type and
9304
+ // sort by their String forms.
9305
+ compareUTF8MaybeNull(String(a.value), String(b.value));
9306
+ }
9307
+ function cmpRelated(a, b) {
9308
+ return compareUTF83(must(a.subquery.alias), must(b.subquery.alias));
9309
+ }
9310
+ function compareUTF8MaybeNull(a, b) {
9311
+ if (a !== null && b !== null) {
9312
+ return compareUTF83(a, b);
9313
+ }
9314
+ if (b !== null) {
9315
+ return -1;
9316
+ }
9317
+ if (a !== null) {
9318
+ return 1;
9319
+ }
9320
+ return 0;
9321
+ }
9322
+
9323
+ // ../zero-protocol/src/ast-hash.ts
9324
+ var hashCache = /* @__PURE__ */ new WeakMap();
9325
+ function hashOfAST(ast) {
9326
+ const normalized = normalizeAST(ast);
9327
+ const cached = hashCache.get(normalized);
9328
+ if (cached) {
9329
+ return cached;
9234
9330
  }
9235
- return v2;
9331
+ const hash = h64(JSON.stringify(normalized)).toString(36);
9332
+ hashCache.set(normalized, hash);
9333
+ return hash;
9236
9334
  }
9237
9335
 
9238
9336
  // ../zql/src/zql/ivm/maybe-split-and-push-edit-change.ts
@@ -9315,7 +9413,7 @@ var Filter = class {
9315
9413
  };
9316
9414
 
9317
9415
  // ../zql/src/zql/ivm/data.ts
9318
- import { compareUTF8 as compareUTF83 } from "compare-utf8";
9416
+ import { compareUTF8 as compareUTF84 } from "compare-utf8";
9319
9417
  function compareValues(a, b) {
9320
9418
  a = normalizeUndefined(a);
9321
9419
  b = normalizeUndefined(b);
@@ -9338,7 +9436,7 @@ function compareValues(a, b) {
9338
9436
  }
9339
9437
  if (typeof a === "string") {
9340
9438
  assertString(b);
9341
- return compareUTF83(a, b);
9439
+ return compareUTF84(a, b);
9342
9440
  }
9343
9441
  throw new Error(`Unsupported type: ${a}`);
9344
9442
  }
@@ -10437,7 +10535,6 @@ var ArrayView = class {
10437
10535
  this.#format = format;
10438
10536
  this.#input.setOutput(this);
10439
10537
  this.#root = { "": format.singular ? void 0 : [] };
10440
- assertOrderingIncludesPK(this.#schema.sort, this.#schema.primaryKey);
10441
10538
  this.#hydrate();
10442
10539
  }
10443
10540
  get data() {
@@ -10457,7 +10554,6 @@ var ArrayView = class {
10457
10554
  }
10458
10555
  }
10459
10556
  destroy() {
10460
- this.#input.destroy();
10461
10557
  this.onDestroy?.();
10462
10558
  }
10463
10559
  #hydrate() {
@@ -10485,207 +10581,6 @@ var ArrayView = class {
10485
10581
  this.#fireListeners();
10486
10582
  }
10487
10583
  };
10488
- function applyChange(parentEntry, change, schema, relationship, format) {
10489
- if (schema.isHidden) {
10490
- switch (change.type) {
10491
- case "add":
10492
- case "remove":
10493
- for (const [relationship2, children] of Object.entries(
10494
- change.node.relationships
10495
- )) {
10496
- const childSchema = must(schema.relationships[relationship2]);
10497
- for (const node of children) {
10498
- applyChange(
10499
- parentEntry,
10500
- { type: change.type, node },
10501
- childSchema,
10502
- relationship2,
10503
- format
10504
- );
10505
- }
10506
- }
10507
- return;
10508
- case "edit":
10509
- return;
10510
- case "child": {
10511
- const childSchema = must(
10512
- schema.relationships[change.child.relationshipName]
10513
- );
10514
- applyChange(
10515
- parentEntry,
10516
- change.child.change,
10517
- childSchema,
10518
- relationship,
10519
- format
10520
- );
10521
- return;
10522
- }
10523
- default:
10524
- unreachable(change);
10525
- }
10526
- }
10527
- const { singular, relationships: childFormats } = format;
10528
- switch (change.type) {
10529
- case "add": {
10530
- const newEntry = {
10531
- ...change.node.row
10532
- };
10533
- if (singular) {
10534
- assertUndefined(
10535
- parentEntry[relationship],
10536
- "single output already exists"
10537
- );
10538
- parentEntry[relationship] = newEntry;
10539
- } else {
10540
- const view = parentEntry[relationship];
10541
- assertArray(view);
10542
- const { pos, found } = binarySearch3(view, newEntry, schema.compareRows);
10543
- assert(!found, "node already exists");
10544
- view.splice(pos, 0, newEntry);
10545
- }
10546
- for (const [relationship2, children] of Object.entries(
10547
- change.node.relationships
10548
- )) {
10549
- const childSchema = must(schema.relationships[relationship2]);
10550
- const childFormat = must(childFormats[relationship2]);
10551
- const newView = childFormat.singular ? void 0 : [];
10552
- newEntry[relationship2] = newView;
10553
- for (const node of children) {
10554
- applyChange(
10555
- newEntry,
10556
- { type: "add", node },
10557
- childSchema,
10558
- relationship2,
10559
- childFormat
10560
- );
10561
- }
10562
- }
10563
- break;
10564
- }
10565
- case "remove": {
10566
- if (singular) {
10567
- assertObject(parentEntry[relationship]);
10568
- parentEntry[relationship] = void 0;
10569
- } else {
10570
- assertArray(parentEntry[relationship]);
10571
- const view = parentEntry[relationship];
10572
- const { pos, found } = binarySearch3(
10573
- view,
10574
- change.node.row,
10575
- schema.compareRows
10576
- );
10577
- assert(found, "node does not exist");
10578
- view.splice(pos, 1);
10579
- }
10580
- break;
10581
- }
10582
- case "child": {
10583
- let existing;
10584
- if (singular) {
10585
- assertObject(parentEntry[relationship]);
10586
- existing = parentEntry[relationship];
10587
- } else {
10588
- assertArray(parentEntry[relationship]);
10589
- const list = parentEntry[relationship];
10590
- const { pos, found } = binarySearch3(list, change.row, schema.compareRows);
10591
- assert(found, "node does not exist");
10592
- existing = list[pos];
10593
- }
10594
- const childSchema = must(
10595
- schema.relationships[change.child.relationshipName]
10596
- );
10597
- const childFormat = must(
10598
- format.relationships[change.child.relationshipName]
10599
- );
10600
- applyChange(
10601
- existing,
10602
- change.child.change,
10603
- childSchema,
10604
- change.child.relationshipName,
10605
- childFormat
10606
- );
10607
- break;
10608
- }
10609
- case "edit": {
10610
- if (singular) {
10611
- assertObject(parentEntry[relationship]);
10612
- parentEntry[relationship] = {
10613
- ...parentEntry[relationship],
10614
- ...change.row
10615
- };
10616
- } else {
10617
- assertArray(parentEntry[relationship]);
10618
- const view = parentEntry[relationship];
10619
- if (schema.compareRows(change.oldRow, change.row) === 0) {
10620
- const { pos, found } = binarySearch3(
10621
- view,
10622
- change.oldRow,
10623
- schema.compareRows
10624
- );
10625
- assert(found, "node does not exists");
10626
- view[pos] = makeEntryPreserveRelationships(
10627
- change.row,
10628
- view[pos],
10629
- schema.relationships
10630
- );
10631
- } else {
10632
- const { pos, found } = binarySearch3(
10633
- view,
10634
- change.oldRow,
10635
- schema.compareRows
10636
- );
10637
- assert(found, "node does not exists");
10638
- const oldEntry = view[pos];
10639
- view.splice(pos, 1);
10640
- {
10641
- const { pos: pos2, found: found2 } = binarySearch3(
10642
- view,
10643
- change.row,
10644
- schema.compareRows
10645
- );
10646
- assert(!found2, "node already exists");
10647
- view.splice(
10648
- pos2,
10649
- 0,
10650
- makeEntryPreserveRelationships(
10651
- change.row,
10652
- oldEntry,
10653
- schema.relationships
10654
- )
10655
- );
10656
- }
10657
- }
10658
- }
10659
- break;
10660
- }
10661
- default:
10662
- unreachable(change);
10663
- }
10664
- }
10665
- function binarySearch3(view, target, comparator) {
10666
- let low = 0;
10667
- let high = view.length - 1;
10668
- while (low <= high) {
10669
- const mid = low + high >>> 1;
10670
- const comparison = comparator(view[mid], target);
10671
- if (comparison < 0) {
10672
- low = mid + 1;
10673
- } else if (comparison > 0) {
10674
- high = mid - 1;
10675
- } else {
10676
- return { pos: mid, found: true };
10677
- }
10678
- }
10679
- return { pos: low, found: false };
10680
- }
10681
- function makeEntryPreserveRelationships(row, entry, relationships) {
10682
- const result = { ...row };
10683
- for (const relationship in relationships) {
10684
- assert(!(relationship in row), "Relationship already exists");
10685
- result[relationship] = entry[relationship];
10686
- }
10687
- return result;
10688
- }
10689
10584
 
10690
10585
  // ../shared/src/sorted-entries.ts
10691
10586
  function sortedEntries(object16) {
@@ -10856,15 +10751,22 @@ var AbstractQuery = class {
10856
10751
  #ast;
10857
10752
  #schema;
10858
10753
  #format;
10754
+ #hash = "";
10859
10755
  constructor(schema, ast, format) {
10860
- this.#ast = ast ?? {
10861
- table: schema.tableName
10862
- };
10756
+ this.#ast = ast;
10863
10757
  this.#format = format ?? { singular: false, relationships: {} };
10864
10758
  this.#schema = schema;
10865
10759
  }
10866
- get ast() {
10867
- return this.#ast;
10760
+ get format() {
10761
+ return this.#format;
10762
+ }
10763
+ hash() {
10764
+ if (!this.#hash) {
10765
+ const ast = this._completeAst();
10766
+ const hash = hashOfAST(ast);
10767
+ this.#hash = hash;
10768
+ }
10769
+ return this.#hash;
10868
10770
  }
10869
10771
  select(..._fields) {
10870
10772
  return this._newQuery(this.#schema, this.#ast, this.#format);
@@ -10911,7 +10813,7 @@ var AbstractQuery = class {
10911
10813
  childField: related1.dest.field,
10912
10814
  op: "="
10913
10815
  },
10914
- subquery: addPrimaryKeysToAst(destSchema, sq.ast)
10816
+ subquery: addPrimaryKeysToAst(destSchema, sq.#ast)
10915
10817
  }
10916
10818
  ]
10917
10819
  },
@@ -10919,7 +10821,7 @@ var AbstractQuery = class {
10919
10821
  ...this.#format,
10920
10822
  relationships: {
10921
10823
  ...this.#format.relationships,
10922
- [relationship]: sq.format
10824
+ [relationship]: sq.#format
10923
10825
  }
10924
10826
  }
10925
10827
  );
@@ -10961,7 +10863,7 @@ var AbstractQuery = class {
10961
10863
  op: "="
10962
10864
  },
10963
10865
  hidden: true,
10964
- subquery: addPrimaryKeysToAst(destSchema, sq.ast)
10866
+ subquery: addPrimaryKeysToAst(destSchema, sq.#ast)
10965
10867
  }
10966
10868
  ]
10967
10869
  }
@@ -10972,7 +10874,7 @@ var AbstractQuery = class {
10972
10874
  ...this.#format,
10973
10875
  relationships: {
10974
10876
  ...this.#format.relationships,
10975
- [relationship]: sq.format
10877
+ [relationship]: sq.#format
10976
10878
  }
10977
10879
  }
10978
10880
  );
@@ -11043,42 +10945,46 @@ var AbstractQuery = class {
11043
10945
  this.#format
11044
10946
  );
11045
10947
  }
10948
+ #completedAST;
11046
10949
  _completeAst() {
11047
- const finalOrderBy = addPrimaryKeys(this.#schema, this.#ast.orderBy);
11048
- if (this.#ast.start) {
11049
- const { row } = this.#ast.start;
11050
- const narrowedRow = {};
11051
- for (const [field] of finalOrderBy) {
11052
- narrowedRow[field] = row[field];
10950
+ if (!this.#completedAST) {
10951
+ const finalOrderBy = addPrimaryKeys(this.#schema, this.#ast.orderBy);
10952
+ if (this.#ast.start) {
10953
+ const { row } = this.#ast.start;
10954
+ const narrowedRow = {};
10955
+ for (const [field] of finalOrderBy) {
10956
+ narrowedRow[field] = row[field];
10957
+ }
10958
+ this.#completedAST = {
10959
+ ...this.#ast,
10960
+ start: {
10961
+ ...this.#ast.start,
10962
+ row: narrowedRow
10963
+ },
10964
+ orderBy: finalOrderBy
10965
+ };
10966
+ } else {
10967
+ this.#completedAST = {
10968
+ ...this.#ast,
10969
+ orderBy: addPrimaryKeys(this.#schema, this.#ast.orderBy)
10970
+ };
11053
10971
  }
11054
- return {
11055
- ...this.#ast,
11056
- start: {
11057
- ...this.#ast.start,
11058
- row: narrowedRow
11059
- },
11060
- orderBy: finalOrderBy
11061
- };
11062
10972
  }
11063
- return {
11064
- ...this.#ast,
11065
- orderBy: addPrimaryKeys(this.#schema, this.#ast.orderBy)
11066
- };
10973
+ return this.#completedAST;
11067
10974
  }
11068
10975
  };
10976
+ var astForTestingSymbol = Symbol();
11069
10977
  var QueryImpl = class extends AbstractQuery {
11070
10978
  #delegate;
11071
- #format;
11072
- constructor(delegate, schema, ast, format) {
10979
+ #ast;
10980
+ constructor(delegate, schema, ast = { table: schema.tableName }, format) {
11073
10981
  super(schema, ast, format);
11074
- this.#format = format ?? { singular: false, relationships: {} };
11075
10982
  this.#delegate = delegate;
10983
+ this.#ast = ast;
11076
10984
  }
11077
- get format() {
11078
- return this.#format;
11079
- }
11080
- get singular() {
11081
- return this.#format.singular;
10985
+ // Not part of Query or QueryInternal interface
10986
+ get [astForTestingSymbol]() {
10987
+ return this.#ast;
11082
10988
  }
11083
10989
  _newQuery(schema, ast, format) {
11084
10990
  return newQueryWithDetails(this.#delegate, schema, ast, format);
@@ -11089,13 +10995,14 @@ var QueryImpl = class extends AbstractQuery {
11089
10995
  const input = buildPipeline(ast, this.#delegate, void 0);
11090
10996
  let removeCommitObserver;
11091
10997
  const onDestroy = () => {
10998
+ input.destroy();
11092
10999
  removeCommitObserver?.();
11093
11000
  removeServerQuery();
11094
11001
  };
11095
- const view = (factory ?? defaultMaterializeFactory)(
11002
+ const view = (factory ?? arrayViewFactory)(
11096
11003
  this,
11097
11004
  input,
11098
- this.#format,
11005
+ this.format,
11099
11006
  onDestroy,
11100
11007
  (cb) => {
11101
11008
  removeCommitObserver = this.#delegate.onTransactionCommit(cb);
@@ -11138,7 +11045,7 @@ function addPrimaryKeysToAst(schema, ast) {
11138
11045
  orderBy: addPrimaryKeys(schema, ast.orderBy)
11139
11046
  };
11140
11047
  }
11141
- function defaultMaterializeFactory(_query, input, format, onDestroy, onTransactionCommit) {
11048
+ function arrayViewFactory(_query, input, format, onDestroy, onTransactionCommit) {
11142
11049
  const v2 = new ArrayView(input, format);
11143
11050
  v2.onDestroy = onDestroy;
11144
11051
  onTransactionCommit(() => {
@@ -11156,134 +11063,6 @@ function escapeLike(val) {
11156
11063
  import { LogContext as LogContext3 } from "@rocicorp/logger";
11157
11064
  import { resolver as resolver8 } from "@rocicorp/resolver";
11158
11065
 
11159
- // ../zero-protocol/src/ast.ts
11160
- import { compareUTF8 as compareUTF84 } from "compare-utf8";
11161
- var selectorSchema = valita_exports.string();
11162
- var orderingElementSchema = readonly(
11163
- valita_exports.tuple([selectorSchema, valita_exports.union(valita_exports.literal("asc"), valita_exports.literal("desc"))])
11164
- );
11165
- var orderingSchema = readonlyArray(orderingElementSchema);
11166
- var primitiveSchema = valita_exports.union(
11167
- valita_exports.string(),
11168
- valita_exports.number(),
11169
- valita_exports.boolean(),
11170
- valita_exports.null()
11171
- );
11172
- var equalityOpsSchema = valita_exports.union(valita_exports.literal("="), valita_exports.literal("!="));
11173
- var orderOpsSchema = valita_exports.union(
11174
- valita_exports.literal("<"),
11175
- valita_exports.literal(">"),
11176
- valita_exports.literal("<="),
11177
- valita_exports.literal(">=")
11178
- );
11179
- var likeOpsSchema = valita_exports.union(
11180
- valita_exports.literal("LIKE"),
11181
- valita_exports.literal("NOT LIKE"),
11182
- valita_exports.literal("ILIKE"),
11183
- valita_exports.literal("NOT ILIKE")
11184
- );
11185
- var inOpsSchema = valita_exports.union(valita_exports.literal("IN"), valita_exports.literal("NOT IN"));
11186
- var simpleOperatorSchema = valita_exports.union(
11187
- equalityOpsSchema,
11188
- orderOpsSchema,
11189
- likeOpsSchema,
11190
- inOpsSchema
11191
- );
11192
- var simpleConditionSchema = valita_exports.object({
11193
- type: valita_exports.literal("simple"),
11194
- op: simpleOperatorSchema,
11195
- field: selectorSchema,
11196
- value: valita_exports.union(
11197
- valita_exports.string(),
11198
- valita_exports.number(),
11199
- valita_exports.boolean(),
11200
- readonlyArray(valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean())),
11201
- valita_exports.object({
11202
- type: valita_exports.literal("static"),
11203
- anchor: valita_exports.union(valita_exports.literal("authData"), valita_exports.literal("preMutationRow")),
11204
- field: valita_exports.string()
11205
- })
11206
- )
11207
- });
11208
- var conditionSchema = simpleConditionSchema;
11209
- var correlatedSubquerySchemaOmitSubquery = valita_exports.object({
11210
- correlation: valita_exports.object({
11211
- parentField: valita_exports.string(),
11212
- childField: valita_exports.string(),
11213
- op: valita_exports.literal("=")
11214
- }),
11215
- hidden: valita_exports.boolean().optional()
11216
- });
11217
- var correlatedSubquerySchema = correlatedSubquerySchemaOmitSubquery.extend({
11218
- subquery: valita_exports.lazy(() => astSchema)
11219
- });
11220
- var astSchema = valita_exports.object({
11221
- schema: valita_exports.string().optional(),
11222
- table: valita_exports.string(),
11223
- alias: valita_exports.string().optional(),
11224
- where: readonlyArray(conditionSchema).optional(),
11225
- related: readonlyArray(correlatedSubquerySchema).optional(),
11226
- limit: valita_exports.number().optional(),
11227
- orderBy: orderingSchema.optional(),
11228
- start: valita_exports.object({
11229
- row: valita_exports.record(
11230
- valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean(), valita_exports.null(), valita_exports.undefined())
11231
- ),
11232
- exclusive: valita_exports.boolean()
11233
- }).optional()
11234
- });
11235
- function normalizeAST(ast) {
11236
- return {
11237
- schema: ast.schema,
11238
- table: ast.table,
11239
- alias: ast.alias,
11240
- where: ast.where ? sortedWhere(ast.where) : void 0,
11241
- related: ast.related ? sortedRelated(
11242
- ast.related.map(
11243
- (r) => ({
11244
- correlation: {
11245
- parentField: r.correlation.parentField,
11246
- childField: r.correlation.childField,
11247
- op: r.correlation.op
11248
- },
11249
- hidden: r.hidden,
11250
- subquery: normalizeAST(r.subquery)
11251
- })
11252
- )
11253
- ) : void 0,
11254
- start: ast.start,
11255
- limit: ast.limit,
11256
- orderBy: ast.orderBy
11257
- };
11258
- }
11259
- function sortedWhere(where) {
11260
- return [...where].sort(cmpCondition);
11261
- }
11262
- function sortedRelated(related) {
11263
- return related.sort(cmpRelated);
11264
- }
11265
- function cmpCondition(a, b) {
11266
- return compareUTF8MaybeNull(a.field, b.field) || compareUTF8MaybeNull(a.op, b.op) || // Comparing the same field with the same op more than once doesn't make logical
11267
- // sense, but is technically possible. Assume the values are of the same type and
11268
- // sort by their String forms.
11269
- compareUTF8MaybeNull(String(a.value), String(b.value));
11270
- }
11271
- function cmpRelated(a, b) {
11272
- return compareUTF84(must(a.subquery.alias), must(b.subquery.alias));
11273
- }
11274
- function compareUTF8MaybeNull(a, b) {
11275
- if (a !== null && b !== null) {
11276
- return compareUTF84(a, b);
11277
- }
11278
- if (b !== null) {
11279
- return -1;
11280
- }
11281
- if (a !== null) {
11282
- return 1;
11283
- }
11284
- return 0;
11285
- }
11286
-
11287
11066
  // ../zero-protocol/src/queries-patch.ts
11288
11067
  var putOpSchema = valita_exports.object({
11289
11068
  op: valita_exports.literal("put"),
@@ -13743,10 +13522,6 @@ function reverseString(str) {
13743
13522
  return reversed;
13744
13523
  }
13745
13524
 
13746
- // ../shared/src/xxhash.ts
13747
- import xxhash from "xxhash-wasm";
13748
- var { create64, h32, h64 } = await xxhash();
13749
-
13750
13525
  // ../shared/src/h64-with-reverse.ts
13751
13526
  function h64WithReverse(str) {
13752
13527
  const forward = h64(str);
@@ -13763,14 +13538,14 @@ var ENTITIES_KEY_PREFIX = "e/";
13763
13538
  function toClientsKey(clientID) {
13764
13539
  return CLIENTS_KEY_PREFIX + clientID;
13765
13540
  }
13766
- function toDesiredQueriesKey(clientID, hash2) {
13767
- return DESIRED_QUERIES_KEY_PREFIX + clientID + "/" + hash2;
13541
+ function toDesiredQueriesKey(clientID, hash) {
13542
+ return DESIRED_QUERIES_KEY_PREFIX + clientID + "/" + hash;
13768
13543
  }
13769
13544
  function desiredQueriesPrefixForClient(clientID) {
13770
13545
  return DESIRED_QUERIES_KEY_PREFIX + clientID + "/";
13771
13546
  }
13772
- function toGotQueriesKey(hash2) {
13773
- return GOT_QUERIES_KEY_PREFIX + hash2;
13547
+ function toGotQueriesKey(hash) {
13548
+ return GOT_QUERIES_KEY_PREFIX + hash;
13774
13549
  }
13775
13550
  function toPrimaryKeyString(tableName, primaryKey, value) {
13776
13551
  if (primaryKey.length === 1) {
@@ -14300,7 +14075,7 @@ function makeMessage(message, context, logLevel) {
14300
14075
  }
14301
14076
 
14302
14077
  // ../zero-client/src/client/version.ts
14303
- var version2 = "0.0.0";
14078
+ var version2 = "0.3.2024102800+3110cf";
14304
14079
 
14305
14080
  // ../zero-client/src/client/log-options.ts
14306
14081
  var LevelFilterLogSink = class {
@@ -14669,26 +14444,26 @@ var QueryManager = class {
14669
14444
  existingQueryHashes.add(key.substring(prefix.length, key.length));
14670
14445
  }
14671
14446
  const patch = /* @__PURE__ */ new Map();
14672
- for (const hash2 of existingQueryHashes) {
14673
- if (!this.#queries.has(hash2)) {
14674
- patch.set(hash2, { op: "del", hash: hash2 });
14447
+ for (const hash of existingQueryHashes) {
14448
+ if (!this.#queries.has(hash)) {
14449
+ patch.set(hash, { op: "del", hash });
14675
14450
  }
14676
14451
  }
14677
- for (const [hash2, { normalized }] of this.#queries) {
14678
- if (!existingQueryHashes.has(hash2)) {
14679
- patch.set(hash2, { op: "put", hash: hash2, ast: normalized });
14452
+ for (const [hash, { normalized }] of this.#queries) {
14453
+ if (!existingQueryHashes.has(hash)) {
14454
+ patch.set(hash, { op: "put", hash, ast: normalized });
14680
14455
  }
14681
14456
  }
14682
14457
  if (lastPatch) {
14683
- for (const [hash2, { op }] of lastPatch) {
14684
- if (op === "put" && !patch.has(hash2)) {
14685
- patch.set(hash2, { op: "del", hash: hash2 });
14458
+ for (const [hash, { op }] of lastPatch) {
14459
+ if (op === "put" && !patch.has(hash)) {
14460
+ patch.set(hash, { op: "del", hash });
14686
14461
  }
14687
14462
  }
14688
- for (const [hash2, { op }] of patch) {
14689
- const lastPatchOp = lastPatch.get(hash2);
14463
+ for (const [hash, { op }] of patch) {
14464
+ const lastPatchOp = lastPatch.get(hash);
14690
14465
  if (lastPatchOp && lastPatchOp.op === op) {
14691
- patch.delete(hash2);
14466
+ patch.delete(hash);
14692
14467
  }
14693
14468
  }
14694
14469
  }
@@ -14696,7 +14471,7 @@ var QueryManager = class {
14696
14471
  }
14697
14472
  add(ast, gotCallback) {
14698
14473
  const normalized = normalizeAST(ast);
14699
- const astHash = hash(normalized);
14474
+ const astHash = hashOfAST(normalized);
14700
14475
  let entry = this.#queries.get(astHash);
14701
14476
  if (!entry) {
14702
14477
  entry = {
@@ -14746,9 +14521,6 @@ var QueryManager = class {
14746
14521
  return true;
14747
14522
  }
14748
14523
  };
14749
- function hash(normalized) {
14750
- return h64(JSON.stringify(normalized)).toString(36);
14751
- }
14752
14524
 
14753
14525
  // ../zero-client/src/client/reload-error-handler.ts
14754
14526
  var RELOAD_REASON_STORAGE_KEY = "_zeroReloadReason";
@@ -15000,7 +14772,7 @@ function mergePokes(pokeBuffer, schema) {
15000
14772
  ...queriesPatch.map(
15001
14773
  (op) => queryPatchOpToReplicachePatchOp(
15002
14774
  op,
15003
- (hash2) => toDesiredQueriesKey(clientID, hash2)
14775
+ (hash) => toDesiredQueriesKey(clientID, hash)
15004
14776
  )
15005
14777
  )
15006
14778
  );