@rocicorp/zero 0.3.2024102600 → 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 (53) hide show
  1. package/out/react.js +3 -3
  2. package/out/react.js.map +2 -2
  3. package/out/solid.js +3 -1
  4. package/out/solid.js.map +2 -2
  5. package/out/zero-cache/src/config/config-query.d.ts +1 -1
  6. package/out/zero-cache/src/config/config-query.d.ts.map +1 -1
  7. package/out/zero-cache/src/config/config-query.js +1 -1
  8. package/out/zero-cache/src/config/config-query.js.map +1 -1
  9. package/out/zero-cache/src/server/life-cycle.d.ts +2 -1
  10. package/out/zero-cache/src/server/life-cycle.d.ts.map +1 -1
  11. package/out/zero-cache/src/server/life-cycle.js +29 -14
  12. package/out/zero-cache/src/server/life-cycle.js.map +1 -1
  13. package/out/zero-cache/src/server/main.js +2 -9
  14. package/out/zero-cache/src/server/main.js.map +1 -1
  15. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.d.ts.map +1 -1
  16. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.js +9 -1
  17. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.js.map +1 -1
  18. package/out/zero-cache/src/services/dispatcher/dispatcher.d.ts +2 -2
  19. package/out/zero-cache/src/services/dispatcher/dispatcher.d.ts.map +1 -1
  20. package/out/zero-cache/src/services/dispatcher/dispatcher.js +1 -0
  21. package/out/zero-cache/src/services/dispatcher/dispatcher.js.map +1 -1
  22. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  23. package/out/zero-client/src/client/query-manager.js +2 -5
  24. package/out/zero-client/src/client/query-manager.js.map +1 -1
  25. package/out/zero-internal/src/mod.d.ts +1 -0
  26. package/out/zero-internal/src/mod.d.ts.map +1 -1
  27. package/out/zero-protocol/src/ast-hash.d.ts +3 -0
  28. package/out/zero-protocol/src/ast-hash.d.ts.map +1 -0
  29. package/out/zero-protocol/src/ast-hash.js +14 -0
  30. package/out/zero-protocol/src/ast-hash.js.map +1 -0
  31. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  32. package/out/zero-protocol/src/ast.js +8 -1
  33. package/out/zero-protocol/src/ast.js.map +1 -1
  34. package/out/zero-react/src/use-query.d.ts.map +1 -1
  35. package/out/zero-solid/src/use-query.d.ts +1 -2
  36. package/out/zero-solid/src/use-query.d.ts.map +1 -1
  37. package/out/zero.js +426 -400
  38. package/out/zero.js.map +4 -4
  39. package/out/zql/src/zql/query/query-impl.d.ts +10 -10
  40. package/out/zql/src/zql/query/query-impl.d.ts.map +1 -1
  41. package/out/zql/src/zql/query/query-impl.js +50 -41
  42. package/out/zql/src/zql/query/query-impl.js.map +1 -1
  43. package/out/zql/src/zql/query/query-internal.d.ts +11 -0
  44. package/out/zql/src/zql/query/query-internal.d.ts.map +1 -0
  45. package/out/zql/src/zql/query/query-internal.js +2 -0
  46. package/out/zql/src/zql/query/query-internal.js.map +1 -0
  47. package/out/zql/src/zql/query/query.d.ts +0 -2
  48. package/out/zql/src/zql/query/query.d.ts.map +1 -1
  49. package/package.json +1 -1
  50. package/out/zero-cache/src/server/task-state-watcher.d.ts +0 -14
  51. package/out/zero-cache/src/server/task-state-watcher.d.ts.map +0 -1
  52. package/out/zero-cache/src/server/task-state-watcher.js +0 -75
  53. package/out/zero-cache/src/server/task-state-watcher.js.map +0 -1
package/out/zero.js CHANGED
@@ -1003,13 +1003,13 @@ var Chunk = class {
1003
1003
  * chunk.
1004
1004
  */
1005
1005
  meta;
1006
- constructor(hash2, data, refs) {
1006
+ constructor(hash, data, refs) {
1007
1007
  assert(
1008
- !refs.includes(hash2),
1008
+ !refs.includes(hash),
1009
1009
  "Chunk cannot reference itself"
1010
1010
  );
1011
1011
  assertDeepFrozen(data);
1012
- this.hash = hash2;
1012
+ this.hash = hash;
1013
1013
  this.data = data;
1014
1014
  this.meta = refs;
1015
1015
  }
@@ -1026,8 +1026,8 @@ function assertRefs(v2) {
1026
1026
  }
1027
1027
  }
1028
1028
  function createChunk(data, refs, chunkHasher) {
1029
- const hash2 = chunkHasher();
1030
- return new Chunk(hash2, data, refs);
1029
+ const hash = chunkHasher();
1030
+ return new Chunk(hash, data, refs);
1031
1031
  }
1032
1032
  function throwChunkHasher() {
1033
1033
  throw new Error("unexpected call to compute chunk hash");
@@ -1071,7 +1071,7 @@ var RefCountUpdates = class {
1071
1071
  await Promise.all(
1072
1072
  Array.from(
1073
1073
  this.#putChunks.values(),
1074
- (hash2) => this.#ensureRefCountLoaded(hash2)
1074
+ (hash) => this.#ensureRefCountLoaded(hash)
1075
1075
  )
1076
1076
  );
1077
1077
  if (this.#isLazyDelegate) {
@@ -1080,9 +1080,9 @@ var RefCountUpdates = class {
1080
1080
  let refCountsUpdated;
1081
1081
  do {
1082
1082
  refCountsUpdated = false;
1083
- for (const hash2 of this.#putChunks.values()) {
1084
- if (!this.#delegate.areRefsCounted(hash2) && !this.#refsCounted.has(hash2) && this.#refCountUpdates.get(hash2) !== 0) {
1085
- 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);
1086
1086
  refCountsUpdated = true;
1087
1087
  break;
1088
1088
  }
@@ -1093,67 +1093,67 @@ var RefCountUpdates = class {
1093
1093
  await this.#changeRefCount(o, -1);
1094
1094
  }
1095
1095
  if (!isProd) {
1096
- for (const [hash2, update] of this.#refCountUpdates) {
1096
+ for (const [hash, update] of this.#refCountUpdates) {
1097
1097
  assert(
1098
1098
  update >= 0,
1099
- `ref count update must be non-negative. ${hash2}:${update}`
1099
+ `ref count update must be non-negative. ${hash}:${update}`
1100
1100
  );
1101
1101
  }
1102
1102
  }
1103
1103
  return this.#refCountUpdates;
1104
1104
  }
1105
- async #changeRefCount(hash2, delta) {
1106
- await this.#ensureRefCountLoaded(hash2);
1107
- if (this.#updateRefCount(hash2, delta)) {
1108
- 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);
1109
1109
  }
1110
1110
  }
1111
- async #updateRefsCounts(hash2, delta) {
1112
- if (hash2 === emptyHash) {
1111
+ async #updateRefsCounts(hash, delta) {
1112
+ if (hash === emptyHash) {
1113
1113
  return;
1114
1114
  }
1115
- const refs = await this.#delegate.getRefs(hash2);
1115
+ const refs = await this.#delegate.getRefs(hash);
1116
1116
  if (!isProd) {
1117
1117
  assert(
1118
- refs || this.#isLazyDelegate && !this.#putChunks.has(hash2),
1118
+ refs || this.#isLazyDelegate && !this.#putChunks.has(hash),
1119
1119
  "refs must be defined"
1120
1120
  );
1121
1121
  }
1122
1122
  if (refs !== void 0) {
1123
- this.#refsCounted?.add(hash2);
1123
+ this.#refsCounted?.add(hash);
1124
1124
  const ps = refs.map((ref) => this.#changeRefCount(ref, delta));
1125
1125
  await Promise.all(ps);
1126
1126
  }
1127
1127
  }
1128
- #ensureRefCountLoaded(hash2) {
1129
- let p = this.#loadedRefCountPromises.get(hash2);
1128
+ #ensureRefCountLoaded(hash) {
1129
+ let p = this.#loadedRefCountPromises.get(hash);
1130
1130
  if (p === void 0) {
1131
1131
  p = (async () => {
1132
- const value = await this.#delegate.getRefCount(hash2) || 0;
1133
- this.#refCountUpdates.set(hash2, value);
1132
+ const value = await this.#delegate.getRefCount(hash) || 0;
1133
+ this.#refCountUpdates.set(hash, value);
1134
1134
  return value;
1135
1135
  })();
1136
- this.#loadedRefCountPromises.set(hash2, p);
1136
+ this.#loadedRefCountPromises.set(hash, p);
1137
1137
  }
1138
1138
  return p;
1139
1139
  }
1140
- #updateRefCount(hash2, delta) {
1141
- const oldCount = this.#refCountUpdates.get(hash2);
1140
+ #updateRefCount(hash, delta) {
1141
+ const oldCount = this.#refCountUpdates.get(hash);
1142
1142
  assertNumber(oldCount);
1143
- this.#refCountUpdates.set(hash2, oldCount + delta);
1143
+ this.#refCountUpdates.set(hash, oldCount + delta);
1144
1144
  return oldCount === 0 && delta === 1 || oldCount === 1 && delta === -1;
1145
1145
  }
1146
1146
  };
1147
1147
 
1148
1148
  // ../replicache/src/dag/key.ts
1149
- function chunkDataKey(hash2) {
1150
- return `c/${hash2}/d`;
1149
+ function chunkDataKey(hash) {
1150
+ return `c/${hash}/d`;
1151
1151
  }
1152
- function chunkMetaKey(hash2) {
1153
- return `c/${hash2}/m`;
1152
+ function chunkMetaKey(hash) {
1153
+ return `c/${hash}/m`;
1154
1154
  }
1155
- function chunkRefCountKey(hash2) {
1156
- return `c/${hash2}/r`;
1155
+ function chunkRefCountKey(hash) {
1156
+ return `c/${hash}/r`;
1157
1157
  }
1158
1158
  function headKey(name) {
1159
1159
  return `h/${name}`;
@@ -1163,22 +1163,22 @@ function headKey(name) {
1163
1163
  var ChunkNotFoundError = class extends Error {
1164
1164
  name = "ChunkNotFoundError";
1165
1165
  hash;
1166
- constructor(hash2) {
1167
- super(`Chunk not found ${hash2}`);
1168
- this.hash = hash2;
1166
+ constructor(hash) {
1167
+ super(`Chunk not found ${hash}`);
1168
+ this.hash = hash;
1169
1169
  }
1170
1170
  };
1171
- async function mustGetChunk(store, hash2) {
1172
- const chunk = await store.getChunk(hash2);
1171
+ async function mustGetChunk(store, hash) {
1172
+ const chunk = await store.getChunk(hash);
1173
1173
  if (chunk) {
1174
1174
  return chunk;
1175
1175
  }
1176
- throw new ChunkNotFoundError(hash2);
1176
+ throw new ChunkNotFoundError(hash);
1177
1177
  }
1178
1178
  async function mustGetHeadHash(name, store) {
1179
- const hash2 = await store.getHead(name);
1180
- assert(hash2, `Missing head ${name}`);
1181
- return hash2;
1179
+ const hash = await store.getHead(name);
1180
+ assert(hash, `Missing head ${name}`);
1181
+ return hash;
1182
1182
  }
1183
1183
 
1184
1184
  // ../replicache/src/dag/store-impl.ts
@@ -1212,15 +1212,15 @@ var ReadImpl2 = class {
1212
1212
  this._tx = kv;
1213
1213
  this.assertValidHash = assertValidHash;
1214
1214
  }
1215
- hasChunk(hash2) {
1216
- return this._tx.has(chunkDataKey(hash2));
1215
+ hasChunk(hash) {
1216
+ return this._tx.has(chunkDataKey(hash));
1217
1217
  }
1218
- async getChunk(hash2) {
1219
- const data = await this._tx.get(chunkDataKey(hash2));
1218
+ async getChunk(hash) {
1219
+ const data = await this._tx.get(chunkDataKey(hash));
1220
1220
  if (data === void 0) {
1221
1221
  return void 0;
1222
1222
  }
1223
- const refsVal = await this._tx.get(chunkMetaKey(hash2));
1223
+ const refsVal = await this._tx.get(chunkMetaKey(hash));
1224
1224
  let refs;
1225
1225
  if (refsVal !== void 0) {
1226
1226
  assertRefs(refsVal);
@@ -1228,10 +1228,10 @@ var ReadImpl2 = class {
1228
1228
  } else {
1229
1229
  refs = [];
1230
1230
  }
1231
- return new Chunk(hash2, data, refs);
1231
+ return new Chunk(hash, data, refs);
1232
1232
  }
1233
- mustGetChunk(hash2) {
1234
- return mustGetChunk(this, hash2);
1233
+ mustGetChunk(hash) {
1234
+ return mustGetChunk(this, hash);
1235
1235
  }
1236
1236
  async getHead(name) {
1237
1237
  const data = await this._tx.get(headKey(name));
@@ -1261,41 +1261,41 @@ var WriteImpl2 = class extends ReadImpl2 {
1261
1261
  return this._tx;
1262
1262
  }
1263
1263
  async putChunk(c) {
1264
- const { hash: hash2, data, meta } = c;
1265
- this.assertValidHash(hash2);
1266
- const key = chunkDataKey(hash2);
1264
+ const { hash, data, meta } = c;
1265
+ this.assertValidHash(hash);
1266
+ const key = chunkDataKey(hash);
1267
1267
  const p1 = this._tx.put(key, data);
1268
1268
  let p2;
1269
1269
  if (meta.length > 0) {
1270
1270
  for (const h of meta) {
1271
1271
  this.assertValidHash(h);
1272
1272
  }
1273
- p2 = this._tx.put(chunkMetaKey(hash2), meta);
1273
+ p2 = this._tx.put(chunkMetaKey(hash), meta);
1274
1274
  }
1275
- this.#putChunks.add(hash2);
1275
+ this.#putChunks.add(hash);
1276
1276
  await p1;
1277
1277
  await p2;
1278
1278
  }
1279
- setHead(name, hash2) {
1280
- return this.#setHead(name, hash2);
1279
+ setHead(name, hash) {
1280
+ return this.#setHead(name, hash);
1281
1281
  }
1282
1282
  removeHead(name) {
1283
1283
  return this.#setHead(name, void 0);
1284
1284
  }
1285
- async #setHead(name, hash2) {
1285
+ async #setHead(name, hash) {
1286
1286
  const oldHash = await this.getHead(name);
1287
1287
  const hk = headKey(name);
1288
1288
  let p1;
1289
- if (hash2 === void 0) {
1289
+ if (hash === void 0) {
1290
1290
  p1 = this._tx.del(hk);
1291
1291
  } else {
1292
- p1 = this._tx.put(hk, hash2);
1292
+ p1 = this._tx.put(hk, hash);
1293
1293
  }
1294
1294
  const v2 = this.#changedHeads.get(name);
1295
1295
  if (v2 === void 0) {
1296
- this.#changedHeads.set(name, { new: hash2, old: oldHash });
1296
+ this.#changedHeads.set(name, { new: hash, old: oldHash });
1297
1297
  } else {
1298
- v2.new = hash2;
1298
+ v2.new = hash;
1299
1299
  }
1300
1300
  await p1;
1301
1301
  }
@@ -1308,8 +1308,8 @@ var WriteImpl2 = class extends ReadImpl2 {
1308
1308
  await this.#applyRefCountUpdates(refCountUpdates);
1309
1309
  await this._tx.commit();
1310
1310
  }
1311
- async getRefCount(hash2) {
1312
- const value = await this._tx.get(chunkRefCountKey(hash2));
1311
+ async getRefCount(hash) {
1312
+ const value = await this._tx.get(chunkRefCountKey(hash));
1313
1313
  if (value === void 0) {
1314
1314
  return void 0;
1315
1315
  }
@@ -1321,8 +1321,8 @@ var WriteImpl2 = class extends ReadImpl2 {
1321
1321
  }
1322
1322
  return value;
1323
1323
  }
1324
- async getRefs(hash2) {
1325
- const meta = await this._tx.get(chunkMetaKey(hash2));
1324
+ async getRefs(hash) {
1325
+ const meta = await this._tx.get(chunkMetaKey(hash));
1326
1326
  if (meta === void 0) {
1327
1327
  return [];
1328
1328
  }
@@ -1331,23 +1331,23 @@ var WriteImpl2 = class extends ReadImpl2 {
1331
1331
  }
1332
1332
  async #applyRefCountUpdates(refCountCache) {
1333
1333
  const ps = [];
1334
- for (const [hash2, count] of refCountCache) {
1334
+ for (const [hash, count] of refCountCache) {
1335
1335
  if (count === 0) {
1336
- ps.push(this.#removeAllRelatedKeys(hash2));
1336
+ ps.push(this.#removeAllRelatedKeys(hash));
1337
1337
  } else {
1338
- const refCountKey = chunkRefCountKey(hash2);
1338
+ const refCountKey = chunkRefCountKey(hash);
1339
1339
  ps.push(this._tx.put(refCountKey, count));
1340
1340
  }
1341
1341
  }
1342
1342
  await Promise.all(ps);
1343
1343
  }
1344
- async #removeAllRelatedKeys(hash2) {
1344
+ async #removeAllRelatedKeys(hash) {
1345
1345
  await Promise.all([
1346
- this._tx.del(chunkDataKey(hash2)),
1347
- this._tx.del(chunkMetaKey(hash2)),
1348
- this._tx.del(chunkRefCountKey(hash2))
1346
+ this._tx.del(chunkDataKey(hash)),
1347
+ this._tx.del(chunkMetaKey(hash)),
1348
+ this._tx.del(chunkRefCountKey(hash))
1349
1349
  ]);
1350
- this.#putChunks.delete(hash2);
1350
+ this.#putChunks.delete(hash);
1351
1351
  }
1352
1352
  release() {
1353
1353
  this._tx.release();
@@ -2105,28 +2105,28 @@ var LazyRead = class {
2105
2105
  this.#release = release;
2106
2106
  this.assertValidHash = assertValidHash;
2107
2107
  }
2108
- isMemOnlyChunkHash(hash2) {
2109
- return this._memOnlyChunks.has(hash2);
2108
+ isMemOnlyChunkHash(hash) {
2109
+ return this._memOnlyChunks.has(hash);
2110
2110
  }
2111
- async hasChunk(hash2) {
2112
- return await this.getChunk(hash2) !== void 0;
2111
+ async hasChunk(hash) {
2112
+ return await this.getChunk(hash) !== void 0;
2113
2113
  }
2114
- async getChunk(hash2) {
2115
- const memOnlyChunk = this._memOnlyChunks.get(hash2);
2114
+ async getChunk(hash) {
2115
+ const memOnlyChunk = this._memOnlyChunks.get(hash);
2116
2116
  if (memOnlyChunk !== void 0) {
2117
2117
  return memOnlyChunk;
2118
2118
  }
2119
- let chunk = this._sourceChunksCache.get(hash2);
2119
+ let chunk = this._sourceChunksCache.get(hash);
2120
2120
  if (chunk === void 0) {
2121
- chunk = await (await this._getSourceRead()).getChunk(hash2);
2121
+ chunk = await (await this._getSourceRead()).getChunk(hash);
2122
2122
  if (chunk !== void 0) {
2123
2123
  this._sourceChunksCache.put(chunk);
2124
2124
  }
2125
2125
  }
2126
2126
  return chunk;
2127
2127
  }
2128
- mustGetChunk(hash2) {
2129
- return mustGetChunk(this, hash2);
2128
+ mustGetChunk(hash) {
2129
+ return mustGetChunk(this, hash);
2130
2130
  }
2131
2131
  getHead(name) {
2132
2132
  return Promise.resolve(this._heads.get(name));
@@ -2176,54 +2176,54 @@ var LazyWrite = class extends LazyRead {
2176
2176
  return chunk;
2177
2177
  };
2178
2178
  putChunk(c, size) {
2179
- const { hash: hash2, meta } = c;
2180
- this.assertValidHash(hash2);
2179
+ const { hash, meta } = c;
2180
+ this.assertValidHash(hash);
2181
2181
  if (meta.length > 0) {
2182
2182
  for (const h of meta) {
2183
2183
  this.assertValidHash(h);
2184
2184
  }
2185
2185
  }
2186
- if (this.#createdChunks.has(hash2) || this.isMemOnlyChunkHash(hash2)) {
2187
- this._pendingMemOnlyChunks.set(hash2, c);
2186
+ if (this.#createdChunks.has(hash) || this.isMemOnlyChunkHash(hash)) {
2187
+ this._pendingMemOnlyChunks.set(hash, c);
2188
2188
  } else {
2189
- this._pendingCachedChunks.set(hash2, { chunk: c, size: size ?? -1 });
2189
+ this._pendingCachedChunks.set(hash, { chunk: c, size: size ?? -1 });
2190
2190
  }
2191
2191
  return promiseVoid;
2192
2192
  }
2193
- async setHead(name, hash2) {
2194
- await this.#setHead(name, hash2);
2193
+ async setHead(name, hash) {
2194
+ await this.#setHead(name, hash);
2195
2195
  }
2196
2196
  async removeHead(name) {
2197
2197
  await this.#setHead(name, void 0);
2198
2198
  }
2199
- async #setHead(name, hash2) {
2199
+ async #setHead(name, hash) {
2200
2200
  const oldHash = await this.getHead(name);
2201
2201
  const v2 = this._pendingHeadChanges.get(name);
2202
2202
  if (v2 === void 0) {
2203
- this._pendingHeadChanges.set(name, { new: hash2, old: oldHash });
2203
+ this._pendingHeadChanges.set(name, { new: hash, old: oldHash });
2204
2204
  } else {
2205
- v2.new = hash2;
2205
+ v2.new = hash;
2206
2206
  }
2207
2207
  }
2208
- isMemOnlyChunkHash(hash2) {
2209
- return this._pendingMemOnlyChunks.has(hash2) || super.isMemOnlyChunkHash(hash2);
2208
+ isMemOnlyChunkHash(hash) {
2209
+ return this._pendingMemOnlyChunks.has(hash) || super.isMemOnlyChunkHash(hash);
2210
2210
  }
2211
- async getChunk(hash2) {
2212
- const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash2);
2211
+ async getChunk(hash) {
2212
+ const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash);
2213
2213
  if (pendingMemOnlyChunk !== void 0) {
2214
2214
  return pendingMemOnlyChunk;
2215
2215
  }
2216
- const memOnlyChunk = this._memOnlyChunks.get(hash2);
2216
+ const memOnlyChunk = this._memOnlyChunks.get(hash);
2217
2217
  if (memOnlyChunk !== void 0) {
2218
2218
  return memOnlyChunk;
2219
2219
  }
2220
- const pendingCachedChunk = this._pendingCachedChunks.get(hash2);
2220
+ const pendingCachedChunk = this._pendingCachedChunks.get(hash);
2221
2221
  if (pendingCachedChunk !== void 0) {
2222
2222
  return pendingCachedChunk.chunk;
2223
2223
  }
2224
- let chunk = this._sourceChunksCache.get(hash2);
2224
+ let chunk = this._sourceChunksCache.get(hash);
2225
2225
  if (chunk === void 0) {
2226
- chunk = await (await this._getSourceRead()).getChunk(hash2);
2226
+ chunk = await (await this._getSourceRead()).getChunk(hash);
2227
2227
  if (chunk !== void 0) {
2228
2228
  this._pendingCachedChunks.set(chunk.hash, { chunk, size: -1 });
2229
2229
  }
@@ -2249,21 +2249,21 @@ var LazyWrite = class extends LazyRead {
2249
2249
  pendingChunks,
2250
2250
  this
2251
2251
  );
2252
- for (const [hash2, count] of refCountUpdates) {
2253
- if (this.isMemOnlyChunkHash(hash2)) {
2252
+ for (const [hash, count] of refCountUpdates) {
2253
+ if (this.isMemOnlyChunkHash(hash)) {
2254
2254
  if (count === 0) {
2255
- this.#refCounts.delete(hash2);
2256
- this._memOnlyChunks.delete(hash2);
2257
- this.#refs.delete(hash2);
2255
+ this.#refCounts.delete(hash);
2256
+ this._memOnlyChunks.delete(hash);
2257
+ this.#refs.delete(hash);
2258
2258
  } else {
2259
- this.#refCounts.set(hash2, count);
2260
- const chunk = this._pendingMemOnlyChunks.get(hash2);
2259
+ this.#refCounts.set(hash, count);
2260
+ const chunk = this._pendingMemOnlyChunks.get(hash);
2261
2261
  if (chunk) {
2262
- this.#refs.set(hash2, chunk.meta);
2263
- this._memOnlyChunks.set(hash2, chunk);
2262
+ this.#refs.set(hash, chunk.meta);
2263
+ this._memOnlyChunks.set(hash, chunk);
2264
2264
  }
2265
2265
  }
2266
- refCountUpdates.delete(hash2);
2266
+ refCountUpdates.delete(hash);
2267
2267
  }
2268
2268
  }
2269
2269
  this._sourceChunksCache.updateForCommit(
@@ -2282,26 +2282,26 @@ var LazyWrite = class extends LazyRead {
2282
2282
  this._pendingHeadChanges.clear();
2283
2283
  this.release();
2284
2284
  }
2285
- getRefCount(hash2) {
2286
- return this.#refCounts.get(hash2);
2285
+ getRefCount(hash) {
2286
+ return this.#refCounts.get(hash);
2287
2287
  }
2288
- getRefs(hash2) {
2289
- const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash2);
2288
+ getRefs(hash) {
2289
+ const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash);
2290
2290
  if (pendingMemOnlyChunk) {
2291
2291
  return pendingMemOnlyChunk.meta;
2292
2292
  }
2293
- const memOnlyChunk = this._memOnlyChunks.get(hash2);
2293
+ const memOnlyChunk = this._memOnlyChunks.get(hash);
2294
2294
  if (memOnlyChunk) {
2295
2295
  return memOnlyChunk.meta;
2296
2296
  }
2297
- const pendingCachedChunk = this._pendingCachedChunks.get(hash2);
2297
+ const pendingCachedChunk = this._pendingCachedChunks.get(hash);
2298
2298
  if (pendingCachedChunk !== void 0) {
2299
2299
  return pendingCachedChunk.chunk.meta;
2300
2300
  }
2301
- return this.#refs.get(hash2);
2301
+ return this.#refs.get(hash);
2302
2302
  }
2303
- areRefsCounted(hash2) {
2304
- return this.#refs.has(hash2);
2303
+ areRefsCounted(hash) {
2304
+ return this.#refs.has(hash);
2305
2305
  }
2306
2306
  chunksPersisted(chunkHashes) {
2307
2307
  const chunksToCache = [];
@@ -2335,37 +2335,37 @@ var ChunksCache = class {
2335
2335
  this.#refCounts = refCounts;
2336
2336
  this.#refs = refs;
2337
2337
  }
2338
- get(hash2) {
2339
- const cacheEntry = this.cacheEntries.get(hash2);
2338
+ get(hash) {
2339
+ const cacheEntry = this.cacheEntries.get(hash);
2340
2340
  if (cacheEntry) {
2341
- this.cacheEntries.delete(hash2);
2342
- this.cacheEntries.set(hash2, cacheEntry);
2341
+ this.cacheEntries.delete(hash);
2342
+ this.cacheEntries.set(hash, cacheEntry);
2343
2343
  }
2344
2344
  return cacheEntry?.chunk;
2345
2345
  }
2346
- getWithoutUpdatingLRU(hash2) {
2347
- return this.cacheEntries.get(hash2)?.chunk;
2346
+ getWithoutUpdatingLRU(hash) {
2347
+ return this.cacheEntries.get(hash)?.chunk;
2348
2348
  }
2349
2349
  put(chunk) {
2350
- const { hash: hash2 } = chunk;
2351
- const oldCacheEntry = this.cacheEntries.get(hash2);
2350
+ const { hash } = chunk;
2351
+ const oldCacheEntry = this.cacheEntries.get(hash);
2352
2352
  if (oldCacheEntry) {
2353
- this.cacheEntries.delete(hash2);
2354
- this.cacheEntries.set(hash2, oldCacheEntry);
2353
+ this.cacheEntries.delete(hash);
2354
+ this.cacheEntries.set(hash, oldCacheEntry);
2355
2355
  return;
2356
2356
  }
2357
- const refCount = this.#refCounts.get(hash2);
2357
+ const refCount = this.#refCounts.get(hash);
2358
2358
  if (refCount === void 0 || refCount < 1) {
2359
2359
  return;
2360
2360
  }
2361
2361
  if (!this.#cacheChunk(chunk)) {
2362
2362
  return;
2363
2363
  }
2364
- if (!this.#refs.has(hash2)) {
2364
+ if (!this.#refs.has(hash)) {
2365
2365
  for (const refHash of chunk.meta) {
2366
2366
  this.#refCounts.set(refHash, (this.#refCounts.get(refHash) || 0) + 1);
2367
2367
  }
2368
- this.#refs.set(hash2, chunk.meta);
2368
+ this.#refs.set(hash, chunk.meta);
2369
2369
  }
2370
2370
  this.#ensureCacheSizeLimit();
2371
2371
  }
@@ -2390,40 +2390,40 @@ var ChunksCache = class {
2390
2390
  return true;
2391
2391
  }
2392
2392
  #evict(cacheEntry) {
2393
- const { hash: hash2 } = cacheEntry.chunk;
2393
+ const { hash } = cacheEntry.chunk;
2394
2394
  this.#size -= cacheEntry.size;
2395
- this.cacheEntries.delete(hash2);
2395
+ this.cacheEntries.delete(hash);
2396
2396
  }
2397
- #deleteEntryByHash(hash2) {
2398
- this.#refCounts.delete(hash2);
2399
- this.#refs.delete(hash2);
2400
- 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);
2401
2401
  if (cacheEntry) {
2402
2402
  this.#size -= cacheEntry.size;
2403
- this.cacheEntries.delete(hash2);
2403
+ this.cacheEntries.delete(hash);
2404
2404
  }
2405
2405
  }
2406
2406
  updateForCommit(chunksToPut, refCountUpdates) {
2407
- for (const [hash2, count] of refCountUpdates) {
2407
+ for (const [hash, count] of refCountUpdates) {
2408
2408
  if (count === 0) {
2409
2409
  if (!this.#evictsAndDeletesSuspended) {
2410
- this.#deleteEntryByHash(hash2);
2410
+ this.#deleteEntryByHash(hash);
2411
2411
  } else {
2412
- this.#refCounts.set(hash2, 0);
2413
- this.#suspendedDeletes.push(hash2);
2412
+ this.#refCounts.set(hash, 0);
2413
+ this.#suspendedDeletes.push(hash);
2414
2414
  }
2415
2415
  } else {
2416
- this.#refCounts.set(hash2, count);
2417
- const chunkAndSize = chunksToPut.get(hash2);
2416
+ this.#refCounts.set(hash, count);
2417
+ const chunkAndSize = chunksToPut.get(hash);
2418
2418
  if (chunkAndSize) {
2419
2419
  const { chunk, size } = chunkAndSize;
2420
- const oldCacheEntry = this.cacheEntries.get(hash2);
2420
+ const oldCacheEntry = this.cacheEntries.get(hash);
2421
2421
  if (oldCacheEntry) {
2422
- this.cacheEntries.delete(hash2);
2423
- this.cacheEntries.set(hash2, oldCacheEntry);
2422
+ this.cacheEntries.delete(hash);
2423
+ this.cacheEntries.set(hash, oldCacheEntry);
2424
2424
  } else {
2425
2425
  this.#cacheChunk(chunk, size !== -1 ? size : void 0);
2426
- this.#refs.set(hash2, chunk.meta);
2426
+ this.#refs.set(hash, chunk.meta);
2427
2427
  }
2428
2428
  }
2429
2429
  }
@@ -2442,9 +2442,9 @@ var ChunksCache = class {
2442
2442
  return await fn();
2443
2443
  } finally {
2444
2444
  this.#evictsAndDeletesSuspended = false;
2445
- for (const hash2 of this.#suspendedDeletes) {
2446
- if (this.#refCounts.get(hash2) === 0) {
2447
- this.#deleteEntryByHash(hash2);
2445
+ for (const hash of this.#suspendedDeletes) {
2446
+ if (this.#refCounts.get(hash) === 0) {
2447
+ this.#deleteEntryByHash(hash);
2448
2448
  }
2449
2449
  }
2450
2450
  this.#ensureCacheSizeLimit();
@@ -2554,15 +2554,15 @@ async function localMutationsGreaterThan(commit, mutationIDLimits, dagRead) {
2554
2554
  return commits;
2555
2555
  }
2556
2556
  async function baseSnapshotFromHead(name, dagRead) {
2557
- const hash2 = await dagRead.getHead(name);
2558
- assert(hash2, `Missing head ${name}`);
2559
- return baseSnapshotFromHash(hash2, dagRead);
2557
+ const hash = await dagRead.getHead(name);
2558
+ assert(hash, `Missing head ${name}`);
2559
+ return baseSnapshotFromHash(hash, dagRead);
2560
2560
  }
2561
- async function baseSnapshotHashFromHash(hash2, dagRead) {
2562
- return (await baseSnapshotFromHash(hash2, dagRead)).chunk.hash;
2561
+ async function baseSnapshotHashFromHash(hash, dagRead) {
2562
+ return (await baseSnapshotFromHash(hash, dagRead)).chunk.hash;
2563
2563
  }
2564
- async function baseSnapshotFromHash(hash2, dagRead) {
2565
- const commit = await commitFromHash(hash2, dagRead);
2564
+ async function baseSnapshotFromHash(hash, dagRead) {
2565
+ const commit = await commitFromHash(hash, dagRead);
2566
2566
  return baseSnapshotFromCommit(commit, dagRead);
2567
2567
  }
2568
2568
  async function baseSnapshotFromCommit(commit, dagRead) {
@@ -2606,13 +2606,13 @@ async function commitChain(fromCommitHash, dagRead) {
2606
2606
  commits.push(commit);
2607
2607
  return commits;
2608
2608
  }
2609
- async function commitFromHash(hash2, dagRead) {
2610
- const chunk = await dagRead.mustGetChunk(hash2);
2609
+ async function commitFromHash(hash, dagRead) {
2610
+ const chunk = await dagRead.mustGetChunk(hash);
2611
2611
  return fromChunk(chunk);
2612
2612
  }
2613
2613
  async function commitFromHead(name, dagRead) {
2614
- const hash2 = await mustGetHeadHash(name, dagRead);
2615
- return commitFromHash(hash2, dagRead);
2614
+ const hash = await mustGetHeadHash(name, dagRead);
2615
+ return commitFromHash(hash, dagRead);
2616
2616
  }
2617
2617
  function assertIndexChangeMeta(v2) {
2618
2618
  assertNumber(v2.lastMutationID);
@@ -2904,8 +2904,8 @@ function makeNodeChunkData(level, entries, formatVersion) {
2904
2904
  formatVersion >= V7 ? entries : entries.map((e) => e.slice(0, 2))
2905
2905
  ]);
2906
2906
  }
2907
- async function findLeaf(key, hash2, source, expectedRootHash) {
2908
- const node = await source.getNode(hash2);
2907
+ async function findLeaf(key, hash, source, expectedRootHash) {
2908
+ const node = await source.getNode(hash);
2909
2909
  if (expectedRootHash !== source.rootHash) {
2910
2910
  return findLeaf(key, source.rootHash, source, source.rootHash);
2911
2911
  }
@@ -2969,9 +2969,9 @@ var NodeImpl = class {
2969
2969
  hash;
2970
2970
  isMutable;
2971
2971
  #childNodeSize = -1;
2972
- constructor(entries, hash2, isMutable) {
2972
+ constructor(entries, hash, isMutable) {
2973
2973
  this.entries = entries;
2974
- this.hash = hash2;
2974
+ this.hash = hash;
2975
2975
  this.isMutable = isMutable;
2976
2976
  }
2977
2977
  maxKey() {
@@ -3050,8 +3050,8 @@ function readonlySplice(array9, start, deleteCount, ...items) {
3050
3050
  }
3051
3051
  var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
3052
3052
  level;
3053
- constructor(entries, hash2, level, isMutable) {
3054
- super(entries, hash2, isMutable);
3053
+ constructor(entries, hash, level, isMutable) {
3054
+ super(entries, hash, isMutable);
3055
3055
  this.level = level;
3056
3056
  }
3057
3057
  async set(key, value, entrySize, tree) {
@@ -3083,8 +3083,8 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
3083
3083
  let startIndex;
3084
3084
  let removeCount;
3085
3085
  if (i > 0) {
3086
- const hash2 = thisEntries[i - 1][1];
3087
- const previousSibling = await tree.getNode(hash2);
3086
+ const hash = thisEntries[i - 1][1];
3087
+ const previousSibling = await tree.getNode(hash);
3088
3088
  values = joinIterables(
3089
3089
  previousSibling.entries,
3090
3090
  childNode.entries
@@ -3092,8 +3092,8 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
3092
3092
  startIndex = i - 1;
3093
3093
  removeCount = 2;
3094
3094
  } else if (i < thisEntries.length - 1) {
3095
- const hash2 = thisEntries[i + 1][1];
3096
- const nextSibling = await tree.getNode(hash2);
3095
+ const hash = thisEntries[i + 1][1];
3096
+ const nextSibling = await tree.getNode(hash);
3097
3097
  values = joinIterables(
3098
3098
  childNode.entries,
3099
3099
  nextSibling.entries
@@ -3207,15 +3207,15 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
3207
3207
  return new DataNodeImpl(entries, newRandomHash(), true);
3208
3208
  }
3209
3209
  };
3210
- function newNodeImpl(entries, hash2, level, isMutable) {
3210
+ function newNodeImpl(entries, hash, level, isMutable) {
3211
3211
  if (level === 0) {
3212
3212
  return new DataNodeImpl(
3213
3213
  entries,
3214
- hash2,
3214
+ hash,
3215
3215
  isMutable
3216
3216
  );
3217
3217
  }
3218
- return new InternalNodeImpl(entries, hash2, level, isMutable);
3218
+ return new InternalNodeImpl(entries, hash, level, isMutable);
3219
3219
  }
3220
3220
  function isDataNodeImpl(node) {
3221
3221
  return node.level === 0;
@@ -3361,15 +3361,15 @@ var BTreeRead = class {
3361
3361
  this.getEntrySize = getEntrySize;
3362
3362
  this.chunkHeaderSize = chunkHeaderSize;
3363
3363
  }
3364
- async getNode(hash2) {
3365
- if (hash2 === emptyHash) {
3364
+ async getNode(hash) {
3365
+ if (hash === emptyHash) {
3366
3366
  return emptyDataNodeImpl;
3367
3367
  }
3368
- const cached = this._cache.get(hash2);
3368
+ const cached = this._cache.get(hash);
3369
3369
  if (cached) {
3370
3370
  return cached;
3371
3371
  }
3372
- const chunk = await this._dagRead.mustGetChunk(hash2);
3372
+ const chunk = await this._dagRead.mustGetChunk(hash);
3373
3373
  const data = parseBTreeNode(
3374
3374
  chunk.data,
3375
3375
  this._formatVersion,
@@ -3377,11 +3377,11 @@ var BTreeRead = class {
3377
3377
  );
3378
3378
  const impl = newNodeImpl(
3379
3379
  data[NODE_ENTRIES],
3380
- hash2,
3380
+ hash,
3381
3381
  data[NODE_LEVEL],
3382
3382
  false
3383
3383
  );
3384
- this._cache.set(hash2, impl);
3384
+ this._cache.set(hash, impl);
3385
3385
  return impl;
3386
3386
  }
3387
3387
  async get(key) {
@@ -3415,15 +3415,15 @@ var BTreeRead = class {
3415
3415
  () => this.rootHash,
3416
3416
  this.rootHash,
3417
3417
  fromKey,
3418
- async (hash2) => {
3419
- const cached = await this.getNode(hash2);
3418
+ async (hash) => {
3419
+ const cached = await this.getNode(hash);
3420
3420
  if (cached) {
3421
3421
  return [
3422
3422
  cached.level,
3423
3423
  cached.isMutable ? cached.entries.slice() : cached.entries
3424
3424
  ];
3425
3425
  }
3426
- const chunk = await this._dagRead.mustGetChunk(hash2);
3426
+ const chunk = await this._dagRead.mustGetChunk(hash);
3427
3427
  return parseBTreeNode(
3428
3428
  chunk.data,
3429
3429
  this._formatVersion,
@@ -3547,11 +3547,11 @@ function* diffEntries(lastEntries, currentEntries) {
3547
3547
  };
3548
3548
  }
3549
3549
  }
3550
- async function* scanForHash(expectedRootHash, getRootHash, hash2, fromKey, readNode) {
3551
- if (hash2 === emptyHash) {
3550
+ async function* scanForHash(expectedRootHash, getRootHash, hash, fromKey, readNode) {
3551
+ if (hash === emptyHash) {
3552
3552
  return;
3553
3553
  }
3554
- const data = await readNode(hash2);
3554
+ const data = await readNode(hash);
3555
3555
  const entries = data[NODE_ENTRIES];
3556
3556
  let i = 0;
3557
3557
  if (fromKey) {
@@ -4260,10 +4260,10 @@ var BTreeWrite = class extends BTreeRead {
4260
4260
  });
4261
4261
  }
4262
4262
  };
4263
- function gatherNewChunks(hash2, newChunks, createChunk2, modified, formatVersion) {
4264
- const node = modified.get(hash2);
4263
+ function gatherNewChunks(hash, newChunks, createChunk2, modified, formatVersion) {
4264
+ const node = modified.get(hash);
4265
4265
  if (node === void 0) {
4266
- return hash2;
4266
+ return hash;
4267
4267
  }
4268
4268
  if (isDataNodeImpl(node)) {
4269
4269
  const chunk2 = createChunk2(toChunkData(node, formatVersion), []);
@@ -4938,16 +4938,16 @@ function clientGroupMapToChunkData(clientGroups, dagWrite) {
4938
4938
  }
4939
4939
  return deepFreeze(chunkData);
4940
4940
  }
4941
- async function getClientGroupsAtHash(hash2, dagRead) {
4942
- const chunk = await dagRead.getChunk(hash2);
4941
+ async function getClientGroupsAtHash(hash, dagRead) {
4942
+ const chunk = await dagRead.getChunk(hash);
4943
4943
  return chunkDataToClientGroupMap(chunk?.data);
4944
4944
  }
4945
4945
  async function getClientGroups(dagRead) {
4946
- const hash2 = await dagRead.getHead(CLIENT_GROUPS_HEAD_NAME);
4947
- if (!hash2) {
4946
+ const hash = await dagRead.getHead(CLIENT_GROUPS_HEAD_NAME);
4947
+ if (!hash) {
4948
4948
  return /* @__PURE__ */ new Map();
4949
4949
  }
4950
- return getClientGroupsAtHash(hash2, dagRead);
4950
+ return getClientGroupsAtHash(hash, dagRead);
4951
4951
  }
4952
4952
  async function setClientGroups(clientGroups, dagWrite) {
4953
4953
  const currClientGroups = await getClientGroups(dagWrite);
@@ -5204,14 +5204,14 @@ function clientMapToChunkData(clients, dagWrite) {
5204
5204
  return deepFreeze(Object.fromEntries(clients));
5205
5205
  }
5206
5206
  async function getClients(dagRead) {
5207
- const hash2 = await dagRead.getHead(CLIENTS_HEAD_NAME);
5208
- return getClientsAtHash(hash2, dagRead);
5207
+ const hash = await dagRead.getHead(CLIENTS_HEAD_NAME);
5208
+ return getClientsAtHash(hash, dagRead);
5209
5209
  }
5210
- async function getClientsAtHash(hash2, dagRead) {
5211
- if (!hash2) {
5210
+ async function getClientsAtHash(hash, dagRead) {
5211
+ if (!hash) {
5212
5212
  return /* @__PURE__ */ new Map();
5213
5213
  }
5214
- const chunk = await dagRead.getChunk(hash2);
5214
+ const chunk = await dagRead.getChunk(hash);
5215
5215
  return chunkDataToClientMap(chunk?.data);
5216
5216
  }
5217
5217
  var ClientStateNotFoundError = class extends Error {
@@ -5402,8 +5402,8 @@ function getRefsForClients(clients) {
5402
5402
  const refs = /* @__PURE__ */ new Set();
5403
5403
  for (const client of clients.values()) {
5404
5404
  if (isClientV6(client)) {
5405
- for (const hash2 of client.refreshHashes) {
5406
- refs.add(hash2);
5405
+ for (const hash of client.refreshHashes) {
5406
+ refs.add(hash);
5407
5407
  }
5408
5408
  if (client.persistHash) {
5409
5409
  refs.add(client.persistHash);
@@ -9181,6 +9181,158 @@ async function anyPendingMutationsInClientGroups(perdag) {
9181
9181
  // ../zql/src/zql/query/query-impl.ts
9182
9182
  import { resolver as resolver7 } from "@rocicorp/resolver";
9183
9183
 
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;
9330
+ }
9331
+ const hash = h64(JSON.stringify(normalized)).toString(36);
9332
+ hashCache.set(normalized, hash);
9333
+ return hash;
9334
+ }
9335
+
9184
9336
  // ../zql/src/zql/ivm/maybe-split-and-push-edit-change.ts
9185
9337
  function maybeSplitAndPushEditChange(change, predicate, output) {
9186
9338
  const oldWasPresent = predicate(change.oldRow);
@@ -9261,7 +9413,7 @@ var Filter = class {
9261
9413
  };
9262
9414
 
9263
9415
  // ../zql/src/zql/ivm/data.ts
9264
- import { compareUTF8 as compareUTF83 } from "compare-utf8";
9416
+ import { compareUTF8 as compareUTF84 } from "compare-utf8";
9265
9417
  function compareValues(a, b) {
9266
9418
  a = normalizeUndefined(a);
9267
9419
  b = normalizeUndefined(b);
@@ -9284,7 +9436,7 @@ function compareValues(a, b) {
9284
9436
  }
9285
9437
  if (typeof a === "string") {
9286
9438
  assertString(b);
9287
- return compareUTF83(a, b);
9439
+ return compareUTF84(a, b);
9288
9440
  }
9289
9441
  throw new Error(`Unsupported type: ${a}`);
9290
9442
  }
@@ -10599,15 +10751,22 @@ var AbstractQuery = class {
10599
10751
  #ast;
10600
10752
  #schema;
10601
10753
  #format;
10754
+ #hash = "";
10602
10755
  constructor(schema, ast, format) {
10603
- this.#ast = ast ?? {
10604
- table: schema.tableName
10605
- };
10756
+ this.#ast = ast;
10606
10757
  this.#format = format ?? { singular: false, relationships: {} };
10607
10758
  this.#schema = schema;
10608
10759
  }
10609
- get ast() {
10610
- 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;
10611
10770
  }
10612
10771
  select(..._fields) {
10613
10772
  return this._newQuery(this.#schema, this.#ast, this.#format);
@@ -10654,7 +10813,7 @@ var AbstractQuery = class {
10654
10813
  childField: related1.dest.field,
10655
10814
  op: "="
10656
10815
  },
10657
- subquery: addPrimaryKeysToAst(destSchema, sq.ast)
10816
+ subquery: addPrimaryKeysToAst(destSchema, sq.#ast)
10658
10817
  }
10659
10818
  ]
10660
10819
  },
@@ -10662,7 +10821,7 @@ var AbstractQuery = class {
10662
10821
  ...this.#format,
10663
10822
  relationships: {
10664
10823
  ...this.#format.relationships,
10665
- [relationship]: sq.format
10824
+ [relationship]: sq.#format
10666
10825
  }
10667
10826
  }
10668
10827
  );
@@ -10704,7 +10863,7 @@ var AbstractQuery = class {
10704
10863
  op: "="
10705
10864
  },
10706
10865
  hidden: true,
10707
- subquery: addPrimaryKeysToAst(destSchema, sq.ast)
10866
+ subquery: addPrimaryKeysToAst(destSchema, sq.#ast)
10708
10867
  }
10709
10868
  ]
10710
10869
  }
@@ -10715,7 +10874,7 @@ var AbstractQuery = class {
10715
10874
  ...this.#format,
10716
10875
  relationships: {
10717
10876
  ...this.#format.relationships,
10718
- [relationship]: sq.format
10877
+ [relationship]: sq.#format
10719
10878
  }
10720
10879
  }
10721
10880
  );
@@ -10786,42 +10945,46 @@ var AbstractQuery = class {
10786
10945
  this.#format
10787
10946
  );
10788
10947
  }
10948
+ #completedAST;
10789
10949
  _completeAst() {
10790
- const finalOrderBy = addPrimaryKeys(this.#schema, this.#ast.orderBy);
10791
- if (this.#ast.start) {
10792
- const { row } = this.#ast.start;
10793
- const narrowedRow = {};
10794
- for (const [field] of finalOrderBy) {
10795
- 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
+ };
10796
10971
  }
10797
- return {
10798
- ...this.#ast,
10799
- start: {
10800
- ...this.#ast.start,
10801
- row: narrowedRow
10802
- },
10803
- orderBy: finalOrderBy
10804
- };
10805
10972
  }
10806
- return {
10807
- ...this.#ast,
10808
- orderBy: addPrimaryKeys(this.#schema, this.#ast.orderBy)
10809
- };
10973
+ return this.#completedAST;
10810
10974
  }
10811
10975
  };
10976
+ var astForTestingSymbol = Symbol();
10812
10977
  var QueryImpl = class extends AbstractQuery {
10813
10978
  #delegate;
10814
- #format;
10815
- constructor(delegate, schema, ast, format) {
10979
+ #ast;
10980
+ constructor(delegate, schema, ast = { table: schema.tableName }, format) {
10816
10981
  super(schema, ast, format);
10817
- this.#format = format ?? { singular: false, relationships: {} };
10818
10982
  this.#delegate = delegate;
10983
+ this.#ast = ast;
10819
10984
  }
10820
- get format() {
10821
- return this.#format;
10822
- }
10823
- get singular() {
10824
- return this.#format.singular;
10985
+ // Not part of Query or QueryInternal interface
10986
+ get [astForTestingSymbol]() {
10987
+ return this.#ast;
10825
10988
  }
10826
10989
  _newQuery(schema, ast, format) {
10827
10990
  return newQueryWithDetails(this.#delegate, schema, ast, format);
@@ -10830,8 +10993,6 @@ var QueryImpl = class extends AbstractQuery {
10830
10993
  const ast = this._completeAst();
10831
10994
  const removeServerQuery = this.#delegate.addServerQuery(ast);
10832
10995
  const input = buildPipeline(ast, this.#delegate, void 0);
10833
- const schema = input.getSchema();
10834
- assertOrderingIncludesPK(schema.sort, schema.primaryKey);
10835
10996
  let removeCommitObserver;
10836
10997
  const onDestroy = () => {
10837
10998
  input.destroy();
@@ -10841,7 +11002,7 @@ var QueryImpl = class extends AbstractQuery {
10841
11002
  const view = (factory ?? arrayViewFactory)(
10842
11003
  this,
10843
11004
  input,
10844
- this.#format,
11005
+ this.format,
10845
11006
  onDestroy,
10846
11007
  (cb) => {
10847
11008
  removeCommitObserver = this.#delegate.onTransactionCommit(cb);
@@ -10902,134 +11063,6 @@ function escapeLike(val) {
10902
11063
  import { LogContext as LogContext3 } from "@rocicorp/logger";
10903
11064
  import { resolver as resolver8 } from "@rocicorp/resolver";
10904
11065
 
10905
- // ../zero-protocol/src/ast.ts
10906
- import { compareUTF8 as compareUTF84 } from "compare-utf8";
10907
- var selectorSchema = valita_exports.string();
10908
- var orderingElementSchema = readonly(
10909
- valita_exports.tuple([selectorSchema, valita_exports.union(valita_exports.literal("asc"), valita_exports.literal("desc"))])
10910
- );
10911
- var orderingSchema = readonlyArray(orderingElementSchema);
10912
- var primitiveSchema = valita_exports.union(
10913
- valita_exports.string(),
10914
- valita_exports.number(),
10915
- valita_exports.boolean(),
10916
- valita_exports.null()
10917
- );
10918
- var equalityOpsSchema = valita_exports.union(valita_exports.literal("="), valita_exports.literal("!="));
10919
- var orderOpsSchema = valita_exports.union(
10920
- valita_exports.literal("<"),
10921
- valita_exports.literal(">"),
10922
- valita_exports.literal("<="),
10923
- valita_exports.literal(">=")
10924
- );
10925
- var likeOpsSchema = valita_exports.union(
10926
- valita_exports.literal("LIKE"),
10927
- valita_exports.literal("NOT LIKE"),
10928
- valita_exports.literal("ILIKE"),
10929
- valita_exports.literal("NOT ILIKE")
10930
- );
10931
- var inOpsSchema = valita_exports.union(valita_exports.literal("IN"), valita_exports.literal("NOT IN"));
10932
- var simpleOperatorSchema = valita_exports.union(
10933
- equalityOpsSchema,
10934
- orderOpsSchema,
10935
- likeOpsSchema,
10936
- inOpsSchema
10937
- );
10938
- var simpleConditionSchema = valita_exports.object({
10939
- type: valita_exports.literal("simple"),
10940
- op: simpleOperatorSchema,
10941
- field: selectorSchema,
10942
- value: valita_exports.union(
10943
- valita_exports.string(),
10944
- valita_exports.number(),
10945
- valita_exports.boolean(),
10946
- readonlyArray(valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean())),
10947
- valita_exports.object({
10948
- type: valita_exports.literal("static"),
10949
- anchor: valita_exports.union(valita_exports.literal("authData"), valita_exports.literal("preMutationRow")),
10950
- field: valita_exports.string()
10951
- })
10952
- )
10953
- });
10954
- var conditionSchema = simpleConditionSchema;
10955
- var correlatedSubquerySchemaOmitSubquery = valita_exports.object({
10956
- correlation: valita_exports.object({
10957
- parentField: valita_exports.string(),
10958
- childField: valita_exports.string(),
10959
- op: valita_exports.literal("=")
10960
- }),
10961
- hidden: valita_exports.boolean().optional()
10962
- });
10963
- var correlatedSubquerySchema = correlatedSubquerySchemaOmitSubquery.extend({
10964
- subquery: valita_exports.lazy(() => astSchema)
10965
- });
10966
- var astSchema = valita_exports.object({
10967
- schema: valita_exports.string().optional(),
10968
- table: valita_exports.string(),
10969
- alias: valita_exports.string().optional(),
10970
- where: readonlyArray(conditionSchema).optional(),
10971
- related: readonlyArray(correlatedSubquerySchema).optional(),
10972
- limit: valita_exports.number().optional(),
10973
- orderBy: orderingSchema.optional(),
10974
- start: valita_exports.object({
10975
- row: valita_exports.record(
10976
- valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean(), valita_exports.null(), valita_exports.undefined())
10977
- ),
10978
- exclusive: valita_exports.boolean()
10979
- }).optional()
10980
- });
10981
- function normalizeAST(ast) {
10982
- return {
10983
- schema: ast.schema,
10984
- table: ast.table,
10985
- alias: ast.alias,
10986
- where: ast.where ? sortedWhere(ast.where) : void 0,
10987
- related: ast.related ? sortedRelated(
10988
- ast.related.map(
10989
- (r) => ({
10990
- correlation: {
10991
- parentField: r.correlation.parentField,
10992
- childField: r.correlation.childField,
10993
- op: r.correlation.op
10994
- },
10995
- hidden: r.hidden,
10996
- subquery: normalizeAST(r.subquery)
10997
- })
10998
- )
10999
- ) : void 0,
11000
- start: ast.start,
11001
- limit: ast.limit,
11002
- orderBy: ast.orderBy
11003
- };
11004
- }
11005
- function sortedWhere(where) {
11006
- return [...where].sort(cmpCondition);
11007
- }
11008
- function sortedRelated(related) {
11009
- return related.sort(cmpRelated);
11010
- }
11011
- function cmpCondition(a, b) {
11012
- 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
11013
- // sense, but is technically possible. Assume the values are of the same type and
11014
- // sort by their String forms.
11015
- compareUTF8MaybeNull(String(a.value), String(b.value));
11016
- }
11017
- function cmpRelated(a, b) {
11018
- return compareUTF84(must(a.subquery.alias), must(b.subquery.alias));
11019
- }
11020
- function compareUTF8MaybeNull(a, b) {
11021
- if (a !== null && b !== null) {
11022
- return compareUTF84(a, b);
11023
- }
11024
- if (b !== null) {
11025
- return -1;
11026
- }
11027
- if (a !== null) {
11028
- return 1;
11029
- }
11030
- return 0;
11031
- }
11032
-
11033
11066
  // ../zero-protocol/src/queries-patch.ts
11034
11067
  var putOpSchema = valita_exports.object({
11035
11068
  op: valita_exports.literal("put"),
@@ -13489,10 +13522,6 @@ function reverseString(str) {
13489
13522
  return reversed;
13490
13523
  }
13491
13524
 
13492
- // ../shared/src/xxhash.ts
13493
- import xxhash from "xxhash-wasm";
13494
- var { create64, h32, h64 } = await xxhash();
13495
-
13496
13525
  // ../shared/src/h64-with-reverse.ts
13497
13526
  function h64WithReverse(str) {
13498
13527
  const forward = h64(str);
@@ -13509,14 +13538,14 @@ var ENTITIES_KEY_PREFIX = "e/";
13509
13538
  function toClientsKey(clientID) {
13510
13539
  return CLIENTS_KEY_PREFIX + clientID;
13511
13540
  }
13512
- function toDesiredQueriesKey(clientID, hash2) {
13513
- return DESIRED_QUERIES_KEY_PREFIX + clientID + "/" + hash2;
13541
+ function toDesiredQueriesKey(clientID, hash) {
13542
+ return DESIRED_QUERIES_KEY_PREFIX + clientID + "/" + hash;
13514
13543
  }
13515
13544
  function desiredQueriesPrefixForClient(clientID) {
13516
13545
  return DESIRED_QUERIES_KEY_PREFIX + clientID + "/";
13517
13546
  }
13518
- function toGotQueriesKey(hash2) {
13519
- return GOT_QUERIES_KEY_PREFIX + hash2;
13547
+ function toGotQueriesKey(hash) {
13548
+ return GOT_QUERIES_KEY_PREFIX + hash;
13520
13549
  }
13521
13550
  function toPrimaryKeyString(tableName, primaryKey, value) {
13522
13551
  if (primaryKey.length === 1) {
@@ -14046,7 +14075,7 @@ function makeMessage(message, context, logLevel) {
14046
14075
  }
14047
14076
 
14048
14077
  // ../zero-client/src/client/version.ts
14049
- var version2 = "0.3.2024102600+0464d7";
14078
+ var version2 = "0.3.2024102800+3110cf";
14050
14079
 
14051
14080
  // ../zero-client/src/client/log-options.ts
14052
14081
  var LevelFilterLogSink = class {
@@ -14415,26 +14444,26 @@ var QueryManager = class {
14415
14444
  existingQueryHashes.add(key.substring(prefix.length, key.length));
14416
14445
  }
14417
14446
  const patch = /* @__PURE__ */ new Map();
14418
- for (const hash2 of existingQueryHashes) {
14419
- if (!this.#queries.has(hash2)) {
14420
- 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 });
14421
14450
  }
14422
14451
  }
14423
- for (const [hash2, { normalized }] of this.#queries) {
14424
- if (!existingQueryHashes.has(hash2)) {
14425
- 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 });
14426
14455
  }
14427
14456
  }
14428
14457
  if (lastPatch) {
14429
- for (const [hash2, { op }] of lastPatch) {
14430
- if (op === "put" && !patch.has(hash2)) {
14431
- 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 });
14432
14461
  }
14433
14462
  }
14434
- for (const [hash2, { op }] of patch) {
14435
- const lastPatchOp = lastPatch.get(hash2);
14463
+ for (const [hash, { op }] of patch) {
14464
+ const lastPatchOp = lastPatch.get(hash);
14436
14465
  if (lastPatchOp && lastPatchOp.op === op) {
14437
- patch.delete(hash2);
14466
+ patch.delete(hash);
14438
14467
  }
14439
14468
  }
14440
14469
  }
@@ -14442,7 +14471,7 @@ var QueryManager = class {
14442
14471
  }
14443
14472
  add(ast, gotCallback) {
14444
14473
  const normalized = normalizeAST(ast);
14445
- const astHash = hash(normalized);
14474
+ const astHash = hashOfAST(normalized);
14446
14475
  let entry = this.#queries.get(astHash);
14447
14476
  if (!entry) {
14448
14477
  entry = {
@@ -14492,9 +14521,6 @@ var QueryManager = class {
14492
14521
  return true;
14493
14522
  }
14494
14523
  };
14495
- function hash(normalized) {
14496
- return h64(JSON.stringify(normalized)).toString(36);
14497
- }
14498
14524
 
14499
14525
  // ../zero-client/src/client/reload-error-handler.ts
14500
14526
  var RELOAD_REASON_STORAGE_KEY = "_zeroReloadReason";
@@ -14746,7 +14772,7 @@ function mergePokes(pokeBuffer, schema) {
14746
14772
  ...queriesPatch.map(
14747
14773
  (op) => queryPatchOpToReplicachePatchOp(
14748
14774
  op,
14749
- (hash2) => toDesiredQueriesKey(clientID, hash2)
14775
+ (hash) => toDesiredQueriesKey(clientID, hash)
14750
14776
  )
14751
14777
  )
14752
14778
  );