@rocicorp/zero 0.17.2025030601 → 0.17.2025030701

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 (73) hide show
  1. package/out/advanced.js +1 -1
  2. package/out/{chunk-Q6D7EOS6.js → chunk-6XQK3UTJ.js} +52 -21
  3. package/out/chunk-6XQK3UTJ.js.map +7 -0
  4. package/out/{chunk-EENFDWT4.js → chunk-YKI43S5O.js} +46 -22
  5. package/out/chunk-YKI43S5O.js.map +7 -0
  6. package/out/replicache/src/db/rebase.d.ts +3 -2
  7. package/out/replicache/src/db/rebase.d.ts.map +1 -1
  8. package/out/replicache/src/persist/refresh.d.ts.map +1 -1
  9. package/out/replicache/src/replicache-impl.d.ts +7 -1
  10. package/out/replicache/src/replicache-impl.d.ts.map +1 -1
  11. package/out/replicache/src/replicache-options.d.ts +51 -0
  12. package/out/replicache/src/replicache-options.d.ts.map +1 -1
  13. package/out/replicache/src/transactions.d.ts +4 -1
  14. package/out/replicache/src/transactions.d.ts.map +1 -1
  15. package/out/solid.js +25 -4
  16. package/out/solid.js.map +2 -2
  17. package/out/zero-advanced/src/mod.d.ts +3 -0
  18. package/out/zero-advanced/src/mod.d.ts.map +1 -1
  19. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  20. package/out/zero-cache/src/services/change-source/pg/change-source.js +9 -4
  21. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  22. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts +0 -11
  23. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts.map +1 -1
  24. package/out/zero-cache/src/services/change-source/protocol/current/data.js +12 -3
  25. package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
  26. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +0 -15
  27. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
  28. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +0 -5
  29. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
  30. package/out/zero-cache/src/services/replicator/change-processor.d.ts.map +1 -1
  31. package/out/zero-cache/src/services/replicator/change-processor.js +68 -33
  32. package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
  33. package/out/zero-cache/src/services/replicator/schema/change-log.d.ts +2 -2
  34. package/out/zero-cache/src/services/replicator/schema/change-log.d.ts.map +1 -1
  35. package/out/zero-cache/src/services/replicator/schema/change-log.js +3 -2
  36. package/out/zero-cache/src/services/replicator/schema/change-log.js.map +1 -1
  37. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  38. package/out/zero-cache/src/services/view-syncer/cvr-store.js +4 -6
  39. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  40. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  41. package/out/zero-cache/src/services/view-syncer/cvr.js +3 -2
  42. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  43. package/out/zero-cache/src/services/view-syncer/schema/cvr.d.ts.map +1 -1
  44. package/out/zero-cache/src/services/view-syncer/schema/cvr.js +0 -4
  45. package/out/zero-cache/src/services/view-syncer/schema/cvr.js.map +1 -1
  46. package/out/zero-cache/src/services/view-syncer/schema/init.d.ts.map +1 -1
  47. package/out/zero-cache/src/services/view-syncer/schema/init.js +6 -0
  48. package/out/zero-cache/src/services/view-syncer/schema/init.js.map +1 -1
  49. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  50. package/out/zero-cache/src/services/view-syncer/view-syncer.js +9 -13
  51. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  52. package/out/zero-cache/src/types/lite.d.ts +4 -1
  53. package/out/zero-cache/src/types/lite.d.ts.map +1 -1
  54. package/out/zero-cache/src/types/lite.js +10 -5
  55. package/out/zero-cache/src/types/lite.js.map +1 -1
  56. package/out/zero-client/src/client/custom.d.ts +11 -2
  57. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  58. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  59. package/out/zero-solid/src/solid-view.d.ts +1 -2
  60. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  61. package/out/zero.js +2 -2
  62. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  63. package/out/zql/src/ivm/array-view.js +3 -2
  64. package/out/zql/src/ivm/array-view.js.map +1 -1
  65. package/out/zql/src/ivm/view-apply-change.d.ts +9 -1
  66. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  67. package/out/zql/src/ivm/view-apply-change.js +56 -14
  68. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  69. package/out/zql/src/ivm/view.d.ts +1 -1
  70. package/out/zql/src/ivm/view.d.ts.map +1 -1
  71. package/package.json +3 -3
  72. package/out/chunk-EENFDWT4.js.map +0 -7
  73. package/out/chunk-Q6D7EOS6.js.map +0 -7
package/out/advanced.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./chunk-ULOTOBTC.js";
2
2
  import {
3
3
  applyChange
4
- } from "./chunk-Q6D7EOS6.js";
4
+ } from "./chunk-6XQK3UTJ.js";
5
5
  import "./chunk-424PT5DM.js";
6
6
  export {
7
7
  applyChange
@@ -47,11 +47,6 @@ function assertNotNull(v) {
47
47
  throw new Error("Expected non-null value");
48
48
  }
49
49
  }
50
- function assertUndefined(v, msg = "Expected undefined value") {
51
- if (v !== void 0) {
52
- throw new Error(msg);
53
- }
54
- }
55
50
  function unreachable(_) {
56
51
  throw new Error("Unreachable");
57
52
  }
@@ -123,7 +118,7 @@ function drainStreams(node) {
123
118
  }
124
119
 
125
120
  // ../zql/src/ivm/view-apply-change.ts
126
- function applyChange(parentEntry, change, schema, relationship, format) {
121
+ function applyChange(parentEntry, change, schema, relationship, format, refCountMap) {
127
122
  if (schema.isHidden) {
128
123
  switch (change.type) {
129
124
  case "add":
@@ -138,7 +133,8 @@ function applyChange(parentEntry, change, schema, relationship, format) {
138
133
  { type: change.type, node },
139
134
  childSchema,
140
135
  relationship2,
141
- format
136
+ format,
137
+ refCountMap
142
138
  );
143
139
  }
144
140
  }
@@ -154,7 +150,8 @@ function applyChange(parentEntry, change, schema, relationship, format) {
154
150
  change.child.change,
155
151
  childSchema,
156
152
  relationship,
157
- format
153
+ format,
154
+ refCountMap
158
155
  );
159
156
  return;
160
157
  }
@@ -169,16 +166,32 @@ function applyChange(parentEntry, change, schema, relationship, format) {
169
166
  ...change.node.row
170
167
  };
171
168
  if (singular) {
172
- assertUndefined(
173
- parentEntry[relationship],
174
- "single output already exists"
175
- );
176
- parentEntry[relationship] = newEntry;
169
+ const oldEntry = parentEntry[relationship];
170
+ if (oldEntry !== void 0) {
171
+ assert(
172
+ schema.compareRows(oldEntry, newEntry) === 0,
173
+ "single output already exists"
174
+ );
175
+ const rc = must(refCountMap.get(oldEntry));
176
+ refCountMap.delete(oldEntry);
177
+ parentEntry[relationship] = newEntry;
178
+ refCountMap.set(newEntry, rc + 1);
179
+ } else {
180
+ parentEntry[relationship] = newEntry;
181
+ refCountMap.set(newEntry, 1);
182
+ }
177
183
  } else {
178
184
  const view = getChildEntryList(parentEntry, relationship);
179
185
  const { pos, found } = binarySearch(view, newEntry, schema.compareRows);
180
- assert(!found, "node already exists");
181
- view.splice(pos, 0, newEntry);
186
+ let deleteCount = 0;
187
+ let rc = 1;
188
+ if (found) {
189
+ deleteCount = 1;
190
+ rc = must(refCountMap.get(view[pos])) + 1;
191
+ refCountMap.delete(view[pos]);
192
+ }
193
+ view.splice(pos, deleteCount, newEntry);
194
+ refCountMap.set(newEntry, rc);
182
195
  }
183
196
  for (const [relationship2, children] of Object.entries(
184
197
  change.node.relationships
@@ -196,7 +209,8 @@ function applyChange(parentEntry, change, schema, relationship, format) {
196
209
  { type: "add", node },
197
210
  childSchema,
198
211
  relationship2,
199
- childFormat
212
+ childFormat,
213
+ refCountMap
200
214
  );
201
215
  }
202
216
  }
@@ -204,8 +218,15 @@ function applyChange(parentEntry, change, schema, relationship, format) {
204
218
  }
205
219
  case "remove": {
206
220
  if (singular) {
207
- assertObject(parentEntry[relationship]);
208
- parentEntry[relationship] = void 0;
221
+ const oldEntry = parentEntry[relationship];
222
+ assert(oldEntry !== void 0, "node does not exist");
223
+ const rc = must(refCountMap.get(oldEntry));
224
+ if (rc === 1) {
225
+ refCountMap.delete(oldEntry);
226
+ parentEntry[relationship] = void 0;
227
+ } else {
228
+ refCountMap.set(oldEntry, rc - 1);
229
+ }
209
230
  } else {
210
231
  const view = getChildEntryList(parentEntry, relationship);
211
232
  const { pos, found } = binarySearch(
@@ -214,7 +235,13 @@ function applyChange(parentEntry, change, schema, relationship, format) {
214
235
  schema.compareRows
215
236
  );
216
237
  assert(found, "node does not exist");
217
- view.splice(pos, 1);
238
+ const rc = must(refCountMap.get(view[pos]));
239
+ if (rc === 1) {
240
+ refCountMap.delete(view[pos]);
241
+ view.splice(pos, 1);
242
+ } else {
243
+ refCountMap.set(view[pos], rc - 1);
244
+ }
218
245
  }
219
246
  drainStreams(change.node);
220
247
  break;
@@ -244,7 +271,8 @@ function applyChange(parentEntry, change, schema, relationship, format) {
244
271
  change.child.change,
245
272
  childSchema,
246
273
  change.child.relationshipName,
247
- childFormat
274
+ childFormat,
275
+ refCountMap
248
276
  );
249
277
  }
250
278
  break;
@@ -266,11 +294,14 @@ function applyChange(parentEntry, change, schema, relationship, format) {
266
294
  schema.compareRows
267
295
  );
268
296
  assert(found, "node does not exists");
297
+ const rc = must(refCountMap.get(view[pos]));
298
+ refCountMap.delete(view[pos]);
269
299
  view[pos] = makeEntryPreserveRelationships(
270
300
  change.node.row,
271
301
  view[pos],
272
302
  schema.relationships
273
303
  );
304
+ refCountMap.set(view[pos], rc);
274
305
  } else {
275
306
  const { pos, found } = binarySearch(
276
307
  view,
@@ -353,4 +384,4 @@ export {
353
384
  drainStreams,
354
385
  applyChange
355
386
  };
356
- //# sourceMappingURL=chunk-Q6D7EOS6.js.map
387
+ //# sourceMappingURL=chunk-6XQK3UTJ.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../shared/src/asserts.ts", "../../shared/src/must.ts", "../../zql/src/ivm/data.ts", "../../zql/src/ivm/view-apply-change.ts"],
4
+ "sourcesContent": ["export function assert(\n b: unknown,\n msg: string | (() => string) = 'Assertion failed',\n): asserts b {\n if (!b) {\n const msgStr = typeof msg === 'string' ? msg : msg();\n throw new Error(msgStr);\n }\n}\n\nexport function assertString(v: unknown): asserts v is string {\n assertType(v, 'string');\n}\n\nexport function assertNumber(v: unknown): asserts v is number {\n assertType(v, 'number');\n}\n\nexport function assertBoolean(v: unknown): asserts v is boolean {\n assertType(v, 'boolean');\n}\n\nfunction assertType(v: unknown, t: string) {\n if (typeof v !== t) {\n throwInvalidType(v, t);\n }\n}\n\nexport function assertObject(v: unknown): asserts v is Record<string, unknown> {\n if (v === null) {\n throwInvalidType(v, 'object');\n }\n assertType(v, 'object');\n}\n\nexport function assertArray(v: unknown): asserts v is unknown[] {\n if (!Array.isArray(v)) {\n throwInvalidType(v, 'array');\n }\n}\n\nexport function invalidType(v: unknown, t: string): string {\n let s = 'Invalid type: ';\n if (v === null || v === undefined) {\n s += v;\n } else {\n s += `${typeof v} \\`${v}\\``;\n }\n return s + `, expected ${t}`;\n}\n\nexport function throwInvalidType(v: unknown, t: string): never {\n throw new Error(invalidType(v, t));\n}\n\nexport function assertNotNull<T>(v: T | null): asserts v is T {\n if (v === null) {\n throw new Error('Expected non-null value');\n }\n}\n\nexport function assertUndefined<T>(\n v: T | undefined,\n msg = 'Expected undefined value',\n): asserts v is T {\n if (v !== undefined) {\n throw new Error(msg);\n }\n}\n\nexport function assertNotUndefined<T>(\n v: T | undefined,\n msg = 'Expected non undefined value',\n): asserts v is T {\n if (v === undefined) {\n throw new Error(msg);\n }\n}\n\nexport function assertInstanceof<T>(\n v: unknown,\n t: new (...args: unknown[]) => T,\n): asserts v is T {\n if (!(v instanceof t)) {\n throw new Error(`Expected instanceof ${t.name}`);\n }\n}\n\nexport function assertUint8Array(v: unknown): asserts v is Uint8Array {\n assertInstanceof(v, Uint8Array);\n}\n\nexport function unreachable(): never;\nexport function unreachable(v: never): never;\nexport function unreachable(_?: never): never {\n throw new Error('Unreachable');\n}\n\nexport function notImplemented(): never {\n throw new Error('Not implemented');\n}\n", "export function must<T>(v: T | undefined | null, msg?: string): T {\n // eslint-disable-next-line eqeqeq\n if (v == null) {\n throw new Error(msg ?? `Unexpected ${v} value`);\n }\n return v;\n}\n", "import {compareUTF8} from 'compare-utf8';\nimport {\n assertBoolean,\n assertNumber,\n assertString,\n} from '../../../shared/src/asserts.ts';\nimport type {Ordering} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport type {Stream} from './stream.ts';\n\n/**\n * A row flowing through the pipeline, plus its relationships.\n * Relationships are generated lazily as read.\n */\nexport type Node = {\n row: Row;\n relationships: Record<string, () => Stream<Node>>;\n};\n\n/**\n * Compare two values. The values must be of the same type. This function\n * throws at runtime if the types differ.\n *\n * Note, this function considers `null === null` and\n * `undefined === undefined`. This is different than SQL. In join code,\n * null must be treated separately.\n *\n * See: https://github.com/rocicorp/mono/pull/2116/files#r1704811479\n *\n * @returns < 0 if a < b, 0 if a === b, > 0 if a > b\n */\nexport function compareValues(a: Value, b: Value): number {\n a = normalizeUndefined(a);\n b = normalizeUndefined(b);\n\n if (a === b) {\n return 0;\n }\n if (a === null) {\n return -1;\n }\n if (b === null) {\n return 1;\n }\n if (typeof a === 'boolean') {\n assertBoolean(b);\n return a ? 1 : -1;\n }\n if (typeof a === 'number') {\n assertNumber(b);\n return a - b;\n }\n if (typeof a === 'string') {\n assertString(b);\n // We compare all strings in Zero as UTF-8. This is the default on SQLite\n // and we need to match it. See:\n // https://blog.replicache.dev/blog/replicache-11-adventures-in-text-encoding.\n //\n // TODO: We could change this since SQLite supports UTF-16. Microbenchmark\n // to see if there's a big win.\n //\n // https://www.sqlite.org/c3ref/create_collation.html\n return compareUTF8(a, b);\n }\n throw new Error(`Unsupported type: ${a}`);\n}\n\nexport type NormalizedValue = Exclude<Value, undefined>;\n\n/**\n * We allow undefined to be passed for the convenience of developers, but we\n * treat it equivalently to null. It's better for perf to not create an copy\n * of input values, so we just normalize at use when necessary.\n */\nexport function normalizeUndefined(v: Value): NormalizedValue {\n return v ?? null;\n}\n\nexport type Comparator = (r1: Row, r2: Row) => number;\n\nexport function makeComparator(\n order: Ordering,\n reverse?: boolean | undefined,\n): Comparator {\n return (a, b) => {\n // Skip destructuring here since it is hot code.\n for (const ord of order) {\n const field = ord[0];\n const comp = compareValues(a[field], b[field]);\n if (comp !== 0) {\n const result = ord[1] === 'asc' ? comp : -comp;\n return reverse ? -result : result;\n }\n }\n return 0;\n };\n}\n\n/**\n * Determine if two values are equal. Note that unlike compareValues() above,\n * this function treats `null` as unequal to itself (and same for `undefined`).\n * This is required to make joins work correctly, but may not be the right\n * semantic for your application.\n */\nexport function valuesEqual(a: Value, b: Value): boolean {\n // eslint-disable-next-line eqeqeq\n if (a == null || b == null) {\n return false;\n }\n return a === b;\n}\n\nexport function drainStreams(node: Node) {\n for (const stream of Object.values(node.relationships)) {\n for (const node of stream()) {\n drainStreams(node);\n }\n }\n}\n", "import {\n assert,\n assertArray,\n assertObject,\n unreachable,\n} from '../../../shared/src/asserts.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport {drainStreams, type Comparator, type Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Entry, EntryList, Format} from './view.ts';\n\n/**\n * `applyChange` does not consume the `relationships` of `ChildChange#node`,\n * `EditChange#node` and `EditChange#oldNode`. The `ViewChange` type\n * documents and enforces this via the type system.\n */\nexport type ViewChange =\n | AddViewChange\n | RemoveViewChange\n | ChildViewChange\n | EditViewChange;\n\nexport type RowOnlyNode = {row: Row};\n\nexport type AddViewChange = {\n type: 'add';\n node: Node;\n};\n\nexport type RemoveViewChange = {\n type: 'remove';\n node: Node;\n};\n\ntype ChildViewChange = {\n type: 'child';\n node: RowOnlyNode;\n child: {\n relationshipName: string;\n change: ViewChange;\n };\n};\n\ntype EditViewChange = {\n type: 'edit';\n node: RowOnlyNode;\n oldNode: RowOnlyNode;\n};\n\n/**\n * This is a subset of WeakMap but restricted to what we need.\n */\nexport interface RefCountMap {\n get(entry: Entry): number | undefined;\n set(entry: Entry, refCount: number): void;\n delete(entry: Entry): boolean;\n}\n\nexport function applyChange(\n parentEntry: Entry,\n change: ViewChange,\n schema: SourceSchema,\n relationship: string,\n format: Format,\n refCountMap: RefCountMap,\n) {\n if (schema.isHidden) {\n switch (change.type) {\n case 'add':\n case 'remove':\n for (const [relationship, children] of Object.entries(\n change.node.relationships,\n )) {\n const childSchema = must(schema.relationships[relationship]);\n for (const node of children()) {\n applyChange(\n parentEntry,\n {type: change.type, node},\n childSchema,\n relationship,\n format,\n refCountMap,\n );\n }\n }\n return;\n case 'edit':\n // If hidden at this level it means that the hidden row was changed. If\n // the row was changed in such a way that it would change the\n // relationships then the edit would have been split into remove and\n // add.\n return;\n case 'child': {\n const childSchema = must(\n schema.relationships[change.child.relationshipName],\n );\n applyChange(\n parentEntry,\n change.child.change,\n childSchema,\n relationship,\n format,\n refCountMap,\n );\n return;\n }\n default:\n unreachable(change);\n }\n }\n\n const {singular, relationships: childFormats} = format;\n switch (change.type) {\n case 'add': {\n // TODO: Only create a new entry if we need to mutate the existing one.\n const newEntry: Entry = {\n ...change.node.row,\n };\n if (singular) {\n const oldEntry = parentEntry[relationship] as Entry | undefined;\n if (oldEntry !== undefined) {\n assert(\n schema.compareRows(oldEntry, newEntry) === 0,\n 'single output already exists',\n );\n // adding same again.\n const rc = must(refCountMap.get(oldEntry));\n refCountMap.delete(oldEntry);\n // @ts-expect-error parentEntry is readonly\n parentEntry[relationship] = newEntry;\n refCountMap.set(newEntry, rc + 1);\n } else {\n // @ts-expect-error parentEntry is readonly\n parentEntry[relationship] = newEntry;\n refCountMap.set(newEntry, 1);\n }\n } else {\n const view = getChildEntryList(parentEntry, relationship);\n const {pos, found} = binarySearch(view, newEntry, schema.compareRows);\n\n let deleteCount = 0;\n let rc = 1;\n if (found) {\n deleteCount = 1;\n rc = must(refCountMap.get(view[pos])) + 1;\n refCountMap.delete(view[pos]);\n }\n\n // @ts-expect-error view is readonly\n view.splice(pos, deleteCount, newEntry);\n refCountMap.set(newEntry, rc);\n }\n for (const [relationship, children] of Object.entries(\n change.node.relationships,\n )) {\n // TODO: Is there a flag to make TypeScript complain that dictionary access might be undefined?\n const childSchema = must(schema.relationships[relationship]);\n const childFormat = childFormats[relationship];\n if (childFormat === undefined) {\n continue;\n }\n\n const newView = childFormat.singular ? undefined : ([] as EntryList);\n // @ts-expect-error newEntry is readonly\n newEntry[relationship] = newView;\n for (const node of children()) {\n applyChange(\n newEntry,\n {type: 'add', node},\n childSchema,\n relationship,\n childFormat,\n refCountMap,\n );\n }\n }\n break;\n }\n case 'remove': {\n if (singular) {\n const oldEntry = parentEntry[relationship] as Entry | undefined;\n assert(oldEntry !== undefined, 'node does not exist');\n const rc = must(refCountMap.get(oldEntry));\n if (rc === 1) {\n refCountMap.delete(oldEntry);\n // @ts-expect-error parentEntry is readonly\n parentEntry[relationship] = undefined;\n } else {\n refCountMap.set(oldEntry, rc - 1);\n }\n } else {\n const view = getChildEntryList(parentEntry, relationship);\n const {pos, found} = binarySearch(\n view,\n change.node.row,\n schema.compareRows,\n );\n assert(found, 'node does not exist');\n const rc = must(refCountMap.get(view[pos]));\n if (rc === 1) {\n refCountMap.delete(view[pos]);\n // @ts-expect-error view is readonly\n view.splice(pos, 1);\n } else {\n refCountMap.set(view[pos], rc - 1);\n }\n }\n // Needed to ensure cleanup of operator state is fully done.\n drainStreams(change.node);\n break;\n }\n case 'child': {\n let existing: Entry;\n if (singular) {\n assertObject(parentEntry[relationship]);\n existing = parentEntry[relationship];\n } else {\n const view = getChildEntryList(parentEntry, relationship);\n const {pos, found} = binarySearch(\n view,\n change.node.row,\n schema.compareRows,\n );\n assert(found, 'node does not exist');\n existing = view[pos];\n }\n\n const childSchema = must(\n schema.relationships[change.child.relationshipName],\n );\n const childFormat = format.relationships[change.child.relationshipName];\n if (childFormat !== undefined) {\n applyChange(\n existing,\n change.child.change,\n childSchema,\n change.child.relationshipName,\n childFormat,\n refCountMap,\n );\n }\n break;\n }\n case 'edit': {\n if (singular) {\n assertObject(parentEntry[relationship]);\n // @ts-expect-error parentEntry is readonly\n parentEntry[relationship] = {\n ...parentEntry[relationship],\n ...change.node.row,\n };\n } else {\n const view = parentEntry[relationship] as EntryList | undefined;\n assertArray(view);\n // If the order changed due to the edit, we need to remove and reinsert.\n if (schema.compareRows(change.oldNode.row, change.node.row) === 0) {\n const {pos, found} = binarySearch(\n view,\n change.oldNode.row,\n schema.compareRows,\n );\n assert(found, 'node does not exists');\n const rc = must(refCountMap.get(view[pos]));\n refCountMap.delete(view[pos]);\n view[pos] = makeEntryPreserveRelationships(\n change.node.row,\n view[pos],\n schema.relationships,\n );\n refCountMap.set(view[pos], rc);\n } else {\n // Remove\n const {pos, found} = binarySearch(\n view,\n change.oldNode.row,\n schema.compareRows,\n );\n assert(found, 'node does not exists');\n const oldEntry = view[pos];\n view.splice(pos, 1);\n\n // Insert\n {\n const {pos, found} = binarySearch(\n view,\n change.node.row,\n schema.compareRows,\n );\n assert(!found, 'node already exists');\n view.splice(\n pos,\n 0,\n makeEntryPreserveRelationships(\n change.node.row,\n oldEntry,\n schema.relationships,\n ),\n );\n }\n }\n }\n break;\n }\n default:\n unreachable(change);\n }\n}\n\n// TODO: Do not return an object. It puts unnecessary pressure on the GC.\nfunction binarySearch(view: EntryList, target: Entry, comparator: Comparator) {\n let low = 0;\n let high = view.length - 1;\n while (low <= high) {\n const mid = (low + high) >>> 1;\n const comparison = comparator(view[mid] as Row, target as Row);\n if (comparison < 0) {\n low = mid + 1;\n } else if (comparison > 0) {\n high = mid - 1;\n } else {\n return {pos: mid, found: true};\n }\n }\n return {pos: low, found: false};\n}\n\nfunction makeEntryPreserveRelationships(\n row: Row,\n entry: Entry,\n relationships: {[key: string]: SourceSchema},\n): Entry {\n const result: Entry = {...row};\n for (const relationship in relationships) {\n assert(!(relationship in row), 'Relationship already exists');\n // @ts-expect-error entry is readonly\n result[relationship] = entry[relationship];\n }\n return result;\n}\n\nfunction getChildEntryList(\n parentEntry: Entry,\n relationship: string,\n): EntryList {\n const view = parentEntry[relationship] as unknown;\n assertArray(view);\n return view as EntryList;\n}\n"],
5
+ "mappings": ";AAAO,SAAS,OACd,GACA,MAA+B,oBACpB;AACX,MAAI,CAAC,GAAG;AACN,UAAM,SAAS,OAAO,QAAQ,WAAW,MAAM,IAAI;AACnD,UAAM,IAAI,MAAM,MAAM;AAAA,EACxB;AACF;AAEO,SAAS,aAAa,GAAiC;AAC5D,aAAW,GAAG,QAAQ;AACxB;AAEO,SAAS,aAAa,GAAiC;AAC5D,aAAW,GAAG,QAAQ;AACxB;AAEO,SAAS,cAAc,GAAkC;AAC9D,aAAW,GAAG,SAAS;AACzB;AAEA,SAAS,WAAW,GAAY,GAAW;AACzC,MAAI,OAAO,MAAM,GAAG;AAClB,qBAAiB,GAAG,CAAC;AAAA,EACvB;AACF;AAEO,SAAS,aAAa,GAAkD;AAC7E,MAAI,MAAM,MAAM;AACd,qBAAiB,GAAG,QAAQ;AAAA,EAC9B;AACA,aAAW,GAAG,QAAQ;AACxB;AAEO,SAAS,YAAY,GAAoC;AAC9D,MAAI,CAAC,MAAM,QAAQ,CAAC,GAAG;AACrB,qBAAiB,GAAG,OAAO;AAAA,EAC7B;AACF;AAEO,SAAS,YAAY,GAAY,GAAmB;AACzD,MAAI,IAAI;AACR,MAAI,MAAM,QAAQ,MAAM,QAAW;AACjC,SAAK;AAAA,EACP,OAAO;AACL,SAAK,GAAG,OAAO,CAAC,MAAM,CAAC;AAAA,EACzB;AACA,SAAO,IAAI,cAAc,CAAC;AAC5B;AAEO,SAAS,iBAAiB,GAAY,GAAkB;AAC7D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A,cACT;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AACA;AAAA,IACF;AAAA,IACA;AACE,kBAAY,MAAM;AAAA,EACtB;AACF;AAGA,SAAS,aAAa,MAAiB,QAAe,YAAwB;AAC5E,MAAI,MAAM;AACV,MAAI,OAAO,KAAK,SAAS;AACzB,SAAO,OAAO,MAAM;AAClB,UAAM,MAAO,MAAM,SAAU;AAC7B,UAAM,aAAa,WAAW,KAAK,GAAG,GAAU,MAAa;AAC7D,QAAI,aAAa,GAAG;AAClB,YAAM,MAAM;AAAA,IACd,WAAW,aAAa,GAAG;AACzB,aAAO,MAAM;AAAA,IACf,OAAO;AACL,aAAO,EAAC,KAAK,KAAK,OAAO,KAAI;AAAA,IAC/B;AAAA,EACF;AACA,SAAO,EAAC,KAAK,KAAK,OAAO,MAAK;AAChC;AAEA,SAAS,+BACP,KACA,OACA,eACO;AACP,QAAM,SAAgB,EAAC,GAAG,IAAG;AAC7B,aAAW,gBAAgB,eAAe;AACxC,WAAO,EAAE,gBAAgB,MAAM,6BAA6B;AAE5D,WAAO,YAAY,IAAI,MAAM,YAAY;AAAA,EAC3C;AACA,SAAO;AACT;AAEA,SAAS,kBACP,aACA,cACW;AACX,QAAM,OAAO,YAAY,YAAY;AACrC,cAAY,IAAI;AAChB,SAAO;AACT;",
6
+ "names": ["node", "relationship", "pos", "found"]
7
+ }
@@ -18,7 +18,7 @@ import {
18
18
  throwInvalidType,
19
19
  unreachable,
20
20
  valuesEqual
21
- } from "./chunk-Q6D7EOS6.js";
21
+ } from "./chunk-6XQK3UTJ.js";
22
22
  import {
23
23
  __export,
24
24
  __reExport
@@ -4162,13 +4162,16 @@ var SubscriptionTransactionWrapper = class {
4162
4162
  return this.#scans;
4163
4163
  }
4164
4164
  };
4165
+ var zeroData = Symbol();
4165
4166
  var WriteTransactionImpl = class extends ReadTransactionImpl {
4166
4167
  reason;
4167
4168
  mutationID;
4168
- constructor(clientID, mutationID, reason, dbWrite, lc, rpcName = "openWriteTransaction") {
4169
+ [zeroData];
4170
+ constructor(clientID, mutationID, reason, zData, dbWrite, lc, rpcName = "openWriteTransaction") {
4169
4171
  super(clientID, dbWrite, lc, rpcName);
4170
4172
  this.mutationID = mutationID;
4171
4173
  this.reason = reason;
4174
+ this[zeroData] = zData;
4172
4175
  }
4173
4176
  put(key, value) {
4174
4177
  return this.set(key, value);
@@ -4717,7 +4720,7 @@ async function createIndexBTree(lc, dagWrite, valueMap, prefix, jsonPointer, all
4717
4720
  }
4718
4721
 
4719
4722
  // ../replicache/src/db/rebase.ts
4720
- async function rebaseMutation(mutation, dagWrite, basisHash, mutators, lc, mutationClientID, formatVersion) {
4723
+ async function rebaseMutation(mutation, dagWrite, basisHash, mutators, lc, mutationClientID, formatVersion, zeroData2) {
4721
4724
  const localMeta = mutation.meta;
4722
4725
  const name = localMeta.mutatorName;
4723
4726
  if (isLocalMetaDD31(localMeta)) {
@@ -4760,13 +4763,14 @@ async function rebaseMutation(mutation, dagWrite, basisHash, mutators, lc, mutat
4760
4763
  mutationClientID,
4761
4764
  await dbWrite.getMutationID(),
4762
4765
  "rebase",
4766
+ zeroData2,
4763
4767
  dbWrite,
4764
4768
  lc
4765
4769
  );
4766
4770
  await mutatorImpl(tx, args);
4767
4771
  return dbWrite;
4768
4772
  }
4769
- async function rebaseMutationAndPutCommit(mutation, dagWrite, basis, mutators, lc, mutationClientID, formatVersion) {
4773
+ async function rebaseMutationAndPutCommit(mutation, dagWrite, basis, mutators, lc, mutationClientID, formatVersion, zeroData2) {
4770
4774
  const tx = await rebaseMutation(
4771
4775
  mutation,
4772
4776
  dagWrite,
@@ -4774,11 +4778,12 @@ async function rebaseMutationAndPutCommit(mutation, dagWrite, basis, mutators, l
4774
4778
  mutators,
4775
4779
  lc,
4776
4780
  mutationClientID,
4777
- formatVersion
4781
+ formatVersion,
4782
+ zeroData2
4778
4783
  );
4779
4784
  return tx.putCommit();
4780
4785
  }
4781
- async function rebaseMutationAndCommit(mutation, dagWrite, basis, headName, mutators, lc, mutationClientID, formatVersion) {
4786
+ async function rebaseMutationAndCommit(mutation, dagWrite, basis, headName, mutators, lc, mutationClientID, formatVersion, zeroData2) {
4782
4787
  const dbWrite = await rebaseMutation(
4783
4788
  mutation,
4784
4789
  dagWrite,
@@ -4786,7 +4791,8 @@ async function rebaseMutationAndCommit(mutation, dagWrite, basis, headName, muta
4786
4791
  mutators,
4787
4792
  lc,
4788
4793
  mutationClientID,
4789
- formatVersion
4794
+ formatVersion,
4795
+ zeroData2
4790
4796
  );
4791
4797
  return dbWrite.commit(headName);
4792
4798
  }
@@ -6383,7 +6389,8 @@ async function rebase(mutations, basis, write, mutators, mutationIDs, lc, format
6383
6389
  mutators,
6384
6390
  lc,
6385
6391
  meta.clientID,
6386
- formatVersion
6392
+ formatVersion,
6393
+ void 0
6387
6394
  )).chunk.hash;
6388
6395
  }
6389
6396
  }
@@ -6548,7 +6555,8 @@ async function refresh(lc, memdag, perdag, clientID, mutators, diffConfig, close
6548
6555
  mutators,
6549
6556
  lc,
6550
6557
  newMemdagMutations[i].meta.clientID,
6551
- formatVersion
6558
+ formatVersion,
6559
+ void 0
6552
6560
  )).chunk.hash;
6553
6561
  }
6554
6562
  const newMemdagHeadCommit = await commitFromHash(
@@ -7584,7 +7592,8 @@ var ReplicacheImpl = class {
7584
7592
  this.#mutatorRegistry,
7585
7593
  lc,
7586
7594
  isLocalMetaDD31(meta) ? meta.clientID : clientID,
7587
- Latest
7595
+ Latest,
7596
+ void 0
7588
7597
  )
7589
7598
  );
7590
7599
  }
@@ -8131,6 +8140,7 @@ var ReplicacheImpl = class {
8131
8140
  clientID,
8132
8141
  await dbWrite.getMutationID(),
8133
8142
  "initial",
8143
+ void 0,
8134
8144
  dbWrite,
8135
8145
  this.#lc
8136
8146
  );
@@ -10753,6 +10763,7 @@ var ArrayView = class {
10753
10763
  onDestroy;
10754
10764
  #dirty = false;
10755
10765
  #complete = false;
10766
+ #refCountMap = /* @__PURE__ */ new WeakMap();
10756
10767
  constructor(input, format = { singular: false, relationships: {} }, queryComplete = true) {
10757
10768
  this.#input = input;
10758
10769
  this.#schema = input.getSchema();
@@ -10802,14 +10813,22 @@ var ArrayView = class {
10802
10813
  { type: "add", node },
10803
10814
  this.#schema,
10804
10815
  "",
10805
- this.#format
10816
+ this.#format,
10817
+ this.#refCountMap
10806
10818
  );
10807
10819
  }
10808
10820
  this.flush();
10809
10821
  }
10810
10822
  push(change) {
10811
10823
  this.#dirty = true;
10812
- applyChange(this.#root, change, this.#schema, "", this.#format);
10824
+ applyChange(
10825
+ this.#root,
10826
+ change,
10827
+ this.#schema,
10828
+ "",
10829
+ this.#format,
10830
+ this.#refCountMap
10831
+ );
10813
10832
  }
10814
10833
  flush() {
10815
10834
  if (!this.#dirty) {
@@ -13681,11 +13700,16 @@ async function deleteImpl(tx, arg, schema, ivmBranch) {
13681
13700
  // ../zero-client/src/client/custom.ts
13682
13701
  var TransactionImpl = class {
13683
13702
  constructor(repTx, schema) {
13703
+ const castedRepTx = repTx;
13684
13704
  must(repTx.reason === "initial" || repTx.reason === "rebase");
13685
13705
  this.clientID = repTx.clientID;
13686
13706
  this.mutationID = repTx.mutationID;
13687
13707
  this.reason = repTx.reason === "initial" ? "optimistic" : "rebase";
13688
- this.mutate = makeSchemaCRUD(schema, repTx);
13708
+ this.mutate = makeSchemaCRUD(
13709
+ schema,
13710
+ repTx,
13711
+ castedRepTx[zeroData]
13712
+ );
13689
13713
  this.query = {};
13690
13714
  }
13691
13715
  clientID;
@@ -13701,14 +13725,14 @@ function makeReplicacheMutator(mutator, schema) {
13701
13725
  return mutator(tx, args);
13702
13726
  };
13703
13727
  }
13704
- function makeSchemaCRUD(schema, tx) {
13728
+ function makeSchemaCRUD(schema, tx, ivmBranch) {
13705
13729
  const mutate = {};
13706
13730
  for (const [name] of Object.entries(schema.tables)) {
13707
- mutate[name] = makeTableCRUD(schema, name, tx);
13731
+ mutate[name] = makeTableCRUD(schema, name, tx, ivmBranch);
13708
13732
  }
13709
13733
  return mutate;
13710
13734
  }
13711
- function makeTableCRUD(schema, tableName, tx) {
13735
+ function makeTableCRUD(schema, tableName, tx, ivmBranch) {
13712
13736
  const table2 = must(schema.tables[tableName]);
13713
13737
  const { primaryKey } = table2;
13714
13738
  return {
@@ -13716,25 +13740,25 @@ function makeTableCRUD(schema, tableName, tx) {
13716
13740
  tx,
13717
13741
  { op: "insert", tableName, primaryKey, value },
13718
13742
  schema,
13719
- void 0
13743
+ ivmBranch
13720
13744
  ),
13721
13745
  upsert: (value) => upsertImpl(
13722
13746
  tx,
13723
13747
  { op: "upsert", tableName, primaryKey, value },
13724
13748
  schema,
13725
- void 0
13749
+ ivmBranch
13726
13750
  ),
13727
13751
  update: (value) => updateImpl(
13728
13752
  tx,
13729
13753
  { op: "update", tableName, primaryKey, value },
13730
13754
  schema,
13731
- void 0
13755
+ ivmBranch
13732
13756
  ),
13733
13757
  delete: (id) => deleteImpl(
13734
13758
  tx,
13735
13759
  { op: "delete", tableName, primaryKey, value: id },
13736
13760
  schema,
13737
- void 0
13761
+ ivmBranch
13738
13762
  )
13739
13763
  };
13740
13764
  }
@@ -14038,7 +14062,7 @@ function makeMessage(message, context, logLevel) {
14038
14062
  }
14039
14063
 
14040
14064
  // ../zero-client/src/client/version.ts
14041
- var version2 = "0.17.2025030601";
14065
+ var version2 = "0.17.2025030701";
14042
14066
 
14043
14067
  // ../zero-client/src/client/log-options.ts
14044
14068
  var LevelFilterLogSink = class {
@@ -16242,4 +16266,4 @@ export {
16242
16266
  escapeLike,
16243
16267
  Zero
16244
16268
  };
16245
- //# sourceMappingURL=chunk-EENFDWT4.js.map
16269
+ //# sourceMappingURL=chunk-YKI43S5O.js.map