@rocicorp/zero 0.17.2025031400 → 0.17.2025031401
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/advanced.js +1 -1
- package/out/{chunk-7ARRNDLF.js → chunk-SVJISXWE.js} +49 -56
- package/out/{chunk-7ARRNDLF.js.map → chunk-SVJISXWE.js.map} +3 -3
- package/out/{chunk-RUSVENO2.js → chunk-UZE45UK4.js} +66 -53
- package/out/chunk-UZE45UK4.js.map +7 -0
- package/out/replicache/src/persist/refresh.d.ts.map +1 -1
- package/out/replicache/src/replicache-options.d.ts +1 -2
- package/out/replicache/src/replicache-options.d.ts.map +1 -1
- package/out/shared/src/custom-key-map.d.ts +2 -2
- package/out/shared/src/custom-key-map.d.ts.map +1 -1
- package/out/shared/src/custom-key-map.js.map +1 -1
- package/out/shared/src/custom-key-set.d.ts +2 -2
- package/out/shared/src/custom-key-set.d.ts.map +1 -1
- package/out/shared/src/custom-key-set.js.map +1 -1
- package/out/solid.js +2 -2
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts +1 -0
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js +4 -4
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +3 -2
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-client/src/client/custom.d.ts +9 -13
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/ivm-branch.d.ts +1 -2
- package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
- package/out/zero-client/src/client/zero-rep.d.ts +1 -2
- package/out/zero-client/src/client/zero-rep.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero.js +2 -2
- package/out/zql/src/ivm/schema.d.ts +2 -2
- package/out/zql/src/ivm/schema.d.ts.map +1 -1
- package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
- package/out/zql/src/ivm/view-apply-change.js +34 -54
- package/out/zql/src/ivm/view-apply-change.js.map +1 -1
- package/out/zql/src/query/query-impl.d.ts +1 -1
- package/out/zql/src/query/query-impl.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.js.map +1 -1
- package/out/zql/src/query/query.d.ts +1 -1
- package/out/zql/src/query/query.d.ts.map +1 -1
- package/package.json +4 -3
- package/out/chunk-RUSVENO2.js.map +0 -7
package/out/advanced.js
CHANGED
|
@@ -180,17 +180,12 @@ function applyChange(parentEntry, change, schema, relationship, format, refCount
|
|
|
180
180
|
refCountMap.set(newEntry, 1);
|
|
181
181
|
}
|
|
182
182
|
} else {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
rc = must(refCountMap.get(view[pos])) + 1;
|
|
190
|
-
refCountMap.delete(view[pos]);
|
|
191
|
-
}
|
|
192
|
-
view.splice(pos, deleteCount, newEntry);
|
|
193
|
-
refCountMap.set(newEntry, rc);
|
|
183
|
+
insertAndUpdateRefCount(
|
|
184
|
+
refCountMap,
|
|
185
|
+
getChildEntryList(parentEntry, relationship),
|
|
186
|
+
newEntry,
|
|
187
|
+
schema.compareRows
|
|
188
|
+
);
|
|
194
189
|
}
|
|
195
190
|
for (const [relationship2, children] of Object.entries(
|
|
196
191
|
change.node.relationships
|
|
@@ -227,20 +222,12 @@ function applyChange(parentEntry, change, schema, relationship, format, refCount
|
|
|
227
222
|
refCountMap.set(oldEntry, rc - 1);
|
|
228
223
|
}
|
|
229
224
|
} else {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
removeAndsUpdateRefCount(
|
|
226
|
+
refCountMap,
|
|
227
|
+
getChildEntryList(parentEntry, relationship),
|
|
233
228
|
change.node.row,
|
|
234
229
|
schema.compareRows
|
|
235
230
|
);
|
|
236
|
-
assert(found, "node does not exist");
|
|
237
|
-
const rc = must(refCountMap.get(view[pos]));
|
|
238
|
-
if (rc === 1) {
|
|
239
|
-
refCountMap.delete(view[pos]);
|
|
240
|
-
view.splice(pos, 1);
|
|
241
|
-
} else {
|
|
242
|
-
refCountMap.set(view[pos], rc - 1);
|
|
243
|
-
}
|
|
244
231
|
}
|
|
245
232
|
drainStreams(change.node);
|
|
246
233
|
break;
|
|
@@ -297,7 +284,7 @@ function applyChange(parentEntry, change, schema, relationship, format, refCount
|
|
|
297
284
|
change.oldNode.row,
|
|
298
285
|
schema.compareRows
|
|
299
286
|
);
|
|
300
|
-
assert(found, "node does not
|
|
287
|
+
assert(found, "node does not exist");
|
|
301
288
|
const rc = must(refCountMap.get(view[pos]));
|
|
302
289
|
refCountMap.delete(view[pos]);
|
|
303
290
|
view[pos] = makeEntryPreserveRelationships(
|
|
@@ -307,42 +294,23 @@ function applyChange(parentEntry, change, schema, relationship, format, refCount
|
|
|
307
294
|
);
|
|
308
295
|
refCountMap.set(view[pos], rc);
|
|
309
296
|
} else {
|
|
310
|
-
const
|
|
297
|
+
const oldEntry = removeAndsUpdateRefCount(
|
|
298
|
+
refCountMap,
|
|
311
299
|
view,
|
|
312
300
|
change.oldNode.row,
|
|
313
301
|
schema.compareRows
|
|
314
302
|
);
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
view,
|
|
327
|
-
change.node.row,
|
|
328
|
-
schema.compareRows
|
|
329
|
-
);
|
|
330
|
-
let rc2 = 1;
|
|
331
|
-
const newEntry = makeEntryPreserveRelationships(
|
|
332
|
-
change.node.row,
|
|
333
|
-
oldEntry,
|
|
334
|
-
format.relationships
|
|
335
|
-
);
|
|
336
|
-
let deleteCount = 0;
|
|
337
|
-
if (found2) {
|
|
338
|
-
deleteCount = 1;
|
|
339
|
-
const existing = view[pos2];
|
|
340
|
-
rc2 = must(refCountMap.get(existing)) + 1;
|
|
341
|
-
refCountMap.delete(existing);
|
|
342
|
-
}
|
|
343
|
-
view.splice(pos2, deleteCount, newEntry);
|
|
344
|
-
refCountMap.set(newEntry, rc2);
|
|
345
|
-
}
|
|
303
|
+
const newEntry = makeEntryPreserveRelationships(
|
|
304
|
+
change.node.row,
|
|
305
|
+
oldEntry,
|
|
306
|
+
format.relationships
|
|
307
|
+
);
|
|
308
|
+
insertAndUpdateRefCount(
|
|
309
|
+
refCountMap,
|
|
310
|
+
view,
|
|
311
|
+
newEntry,
|
|
312
|
+
schema.compareRows
|
|
313
|
+
);
|
|
346
314
|
}
|
|
347
315
|
}
|
|
348
316
|
break;
|
|
@@ -351,6 +319,31 @@ function applyChange(parentEntry, change, schema, relationship, format, refCount
|
|
|
351
319
|
unreachable(change);
|
|
352
320
|
}
|
|
353
321
|
}
|
|
322
|
+
function insertAndUpdateRefCount(refCountMap, view, newEntry, compareRows) {
|
|
323
|
+
const { pos, found } = binarySearch(view, newEntry, compareRows);
|
|
324
|
+
let deleteCount = 0;
|
|
325
|
+
let rc = 1;
|
|
326
|
+
if (found) {
|
|
327
|
+
deleteCount = 1;
|
|
328
|
+
rc = must(refCountMap.get(view[pos])) + 1;
|
|
329
|
+
refCountMap.delete(view[pos]);
|
|
330
|
+
}
|
|
331
|
+
view.splice(pos, deleteCount, newEntry);
|
|
332
|
+
refCountMap.set(newEntry, rc);
|
|
333
|
+
}
|
|
334
|
+
function removeAndsUpdateRefCount(refCountMap, view, target, compareRows) {
|
|
335
|
+
const { pos, found } = binarySearch(view, target, compareRows);
|
|
336
|
+
assert(found, "node does not exist");
|
|
337
|
+
const oldEntry = view[pos];
|
|
338
|
+
const rc = must(refCountMap.get(oldEntry));
|
|
339
|
+
if (rc === 1) {
|
|
340
|
+
refCountMap.delete(oldEntry);
|
|
341
|
+
view.splice(pos, 1);
|
|
342
|
+
} else {
|
|
343
|
+
refCountMap.set(oldEntry, rc - 1);
|
|
344
|
+
}
|
|
345
|
+
return oldEntry;
|
|
346
|
+
}
|
|
354
347
|
function binarySearch(view, target, comparator) {
|
|
355
348
|
let low = 0;
|
|
356
349
|
let high = view.length - 1;
|
|
@@ -405,4 +398,4 @@ export {
|
|
|
405
398
|
drainStreams,
|
|
406
399
|
applyChange
|
|
407
400
|
};
|
|
408
|
-
//# sourceMappingURL=chunk-
|
|
401
|
+
//# sourceMappingURL=chunk-SVJISXWE.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 throw new Error(typeof msg === 'string' ? msg : msg());\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 const existing = parentEntry[relationship];\n assertEntry(existing);\n const rc = must(refCountMap.get(existing));\n const newEntry = {\n ...existing,\n ...change.node.row,\n };\n refCountMap.set(newEntry, rc);\n refCountMap.delete(existing);\n // @ts-expect-error parentEntry is readonly\n parentEntry[relationship] = newEntry;\n } else {\n const view = parentEntry[relationship];\n assertEntryList(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 // @ts-expect-error view is readonly\n view[pos] = makeEntryPreserveRelationships(\n change.node.row,\n view[pos],\n format.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 const rc = must(refCountMap.get(oldEntry));\n if (rc === 1) {\n refCountMap.delete(oldEntry);\n // @ts-expect-error view is readonly\n view.splice(pos, 1);\n } else {\n refCountMap.set(oldEntry, rc - 1);\n }\n\n // Insert\n {\n const {pos, found} = binarySearch(\n view,\n change.node.row,\n schema.compareRows,\n );\n let rc = 1;\n const newEntry = makeEntryPreserveRelationships(\n change.node.row,\n oldEntry,\n format.relationships,\n );\n let deleteCount = 0;\n if (found) {\n // We changed a row to a row that already exists. The existing row\n // should increase its ref count.\n deleteCount = 1;\n const existing = view[pos];\n rc = must(refCountMap.get(existing)) + 1;\n refCountMap.delete(existing);\n }\n // @ts-expect-error view is readonly\n view.splice(pos, deleteCount, newEntry);\n refCountMap.set(newEntry, rc);\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]: Format},\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\nfunction assertEntryList(v: unknown): asserts v is EntryList {\n assertArray(v);\n}\n\nfunction assertEntry(v: unknown): asserts v is Entry {\n assertObject(v);\n}\n"],
|
|
5
|
-
"mappings": ";AAAO,SAAS,OACd,GACA,MAA+B,oBACpB;AACX,MAAI,CAAC,GAAG;AACN,UAAM,IAAI,MAAM,OAAO,QAAQ,WAAW,MAAM,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K;AACH,mBAAW,CAACC,eAAc,QAAQ,KAAK,OAAO;AAAA,UAC5C,OAAO,KAAK;AAAA,QACd,GAAG;AACD,gBAAM,cAAc,KAAK,OAAO,cAAcA,aAAY,CAAC;AAC3D,qBAAW,QAAQ,SAAS,GAAG;AAC7B;AAAA,cACE;AAAA,cACA,EAAC,MAAM,OAAO,MAAM,KAAI;AAAA,cACxB;AAAA,cACAA;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AACA;AAAA,MACF,KAAK;AAKH;AAAA,MACF,KAAK,SAAS;AACZ,cAAM,cAAc;AAAA,UAClB,OAAO,cAAc,OAAO,MAAM,gBAAgB;AAAA,QACpD;AACA;AAAA,UACE;AAAA,UACA,OAAO,MAAM;AAAA,UACb;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AACA;AAAA,MACF;AAAA,MACA;AACE,oBAAY,MAAM;AAAA,IACtB;AAAA,EACF;AAEA,QAAM,EAAC,UAAU,eAAe,aAAY,IAAI;AAChD,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,OAAO;AAEV,YAAM,WAAkB;AAAA,QACtB,GAAG,OAAO,KAAK;AAAA,MACjB;AACA,UAAI,UAAU;AACZ,cAAM,WAAW,YAAY,YAAY;AACzC,YAAI,aAAa,QAAW;AAC1B;AAAA,YACE,OAAO,YAAY,UAAU,QAAQ,MAAM;AAAA,YAC3C;AAAA,UACF;AAEA,gBAAM,KAAK,KAAK,YAAY,IAAI,QAAQ,CAAC;AACzC,sBAAY,OAAO,QAAQ;AAE3B,sBAAY,YAAY,IAAI;AAC5B,sBAAY,IAAI,UAAU,KAAK,CAAC;AAAA,QAClC,OAAO;AAEL,sBAAY,YAAY,IAAI;AAC5B,sBAAY,IAAI,UAAU,CAAC;AAAA,QAC7B;AAAA,MACF,OAAO;AACL,
|
|
6
|
-
"names": ["node", "relationship"
|
|
4
|
+
"sourcesContent": ["export function assert(\n b: unknown,\n msg: string | (() => string) = 'Assertion failed',\n): asserts b {\n if (!b) {\n throw new Error(typeof msg === 'string' ? msg : msg());\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 insertAndUpdateRefCount(\n refCountMap,\n getChildEntryList(parentEntry, relationship),\n newEntry,\n schema.compareRows,\n );\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 removeAndsUpdateRefCount(\n refCountMap,\n getChildEntryList(parentEntry, relationship),\n change.node.row,\n schema.compareRows,\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 const existing = parentEntry[relationship];\n assertEntry(existing);\n const rc = must(refCountMap.get(existing));\n const newEntry = {\n ...existing,\n ...change.node.row,\n };\n refCountMap.set(newEntry, rc);\n refCountMap.delete(existing);\n // @ts-expect-error parentEntry is readonly\n parentEntry[relationship] = newEntry;\n } else {\n const view = parentEntry[relationship];\n assertEntryList(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 exist');\n const rc = must(refCountMap.get(view[pos]));\n refCountMap.delete(view[pos]);\n // @ts-expect-error view is readonly\n view[pos] = makeEntryPreserveRelationships(\n change.node.row,\n view[pos],\n format.relationships,\n );\n refCountMap.set(view[pos], rc);\n } else {\n // Remove\n const oldEntry = removeAndsUpdateRefCount(\n refCountMap,\n view,\n change.oldNode.row,\n schema.compareRows,\n );\n\n // Insert\n const newEntry = makeEntryPreserveRelationships(\n change.node.row,\n oldEntry,\n format.relationships,\n );\n insertAndUpdateRefCount(\n refCountMap,\n view,\n newEntry,\n schema.compareRows,\n );\n }\n }\n break;\n }\n default:\n unreachable(change);\n }\n}\n\nfunction insertAndUpdateRefCount(\n refCountMap: RefCountMap,\n view: EntryList,\n newEntry: Entry,\n compareRows: Comparator,\n): void {\n const {pos, found} = binarySearch(view, newEntry, 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\nfunction removeAndsUpdateRefCount(\n refCountMap: RefCountMap,\n view: EntryList,\n target: Row,\n compareRows: Comparator,\n): Entry {\n const {pos, found} = binarySearch(view, target, compareRows);\n assert(found, 'node does not exist');\n const oldEntry = view[pos];\n const rc = must(refCountMap.get(oldEntry));\n if (rc === 1) {\n refCountMap.delete(oldEntry);\n // @ts-expect-error view is readonly\n view.splice(pos, 1);\n } else {\n refCountMap.set(oldEntry, rc - 1);\n }\n\n return oldEntry;\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]: Format},\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];\n assertArray(view);\n return view as EntryList;\n}\n\nfunction assertEntryList(v: unknown): asserts v is EntryList {\n assertArray(v);\n}\n\nfunction assertEntry(v: unknown): asserts v is Entry {\n assertObject(v);\n}\n"],
|
|
5
|
+
"mappings": ";AAAO,SAAS,OACd,GACA,MAA+B,oBACpB;AACX,MAAI,CAAC,GAAG;AACN,UAAM,IAAI,MAAM,OAAO,QAAQ,WAAW,MAAM,IAAI,CAAC;AAAA,EACvD;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,QA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
|
22
22
|
unreachable,
|
|
23
23
|
valuesEqual
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-SVJISXWE.js";
|
|
25
25
|
import {
|
|
26
26
|
__export,
|
|
27
27
|
__reExport
|
|
@@ -6315,7 +6315,7 @@ async function persistDD31(lc, clientID, memdag, perdag, mutators, closed, forma
|
|
|
6315
6315
|
return;
|
|
6316
6316
|
}
|
|
6317
6317
|
let memdagBaseSnapshotPersisted = false;
|
|
6318
|
-
const zeroDataForMemdagBaseSnapshot = getZeroData && await getZeroData(
|
|
6318
|
+
const zeroDataForMemdagBaseSnapshot = getZeroData && await getZeroData(memdagBaseSnapshot.chunk.hash);
|
|
6319
6319
|
await withWrite(perdag, async (perdagWrite) => {
|
|
6320
6320
|
const [mainClientGroup, latestPerdagMainClientGroupHeadCommit] = await getClientGroupInfo(perdagWrite, mainClientGroupID);
|
|
6321
6321
|
let newMainClientGroupHeadHash = latestPerdagMainClientGroupHeadCommit.chunk.hash;
|
|
@@ -6368,7 +6368,7 @@ async function persistDD31(lc, clientID, memdag, perdag, mutators, closed, forma
|
|
|
6368
6368
|
}
|
|
6369
6369
|
let zeroDataForPerdagHeadCommit;
|
|
6370
6370
|
if (!memdagBaseSnapshotPersisted) {
|
|
6371
|
-
zeroDataForPerdagHeadCommit = getZeroData && await getZeroData(
|
|
6371
|
+
zeroDataForPerdagHeadCommit = getZeroData && await getZeroData(newMainClientGroupHeadHash, {
|
|
6372
6372
|
openLazySourceRead: perdagWrite
|
|
6373
6373
|
});
|
|
6374
6374
|
}
|
|
@@ -6575,13 +6575,9 @@ async function refresh(lc, memdag, perdag, clientID, mutators, diffConfig, close
|
|
|
6575
6575
|
await Promise.all(ps);
|
|
6576
6576
|
let newMemdagHeadHash = perdagClientGroupHeadHash;
|
|
6577
6577
|
if (newMemdagMutations.length > 0) {
|
|
6578
|
-
const zeroData2 = await zero?.getTxData?.(
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
{
|
|
6582
|
-
openLazyRead: memdagWrite
|
|
6583
|
-
}
|
|
6584
|
-
);
|
|
6578
|
+
const zeroData2 = await zero?.getTxData?.(newMemdagHeadHash, {
|
|
6579
|
+
openLazyRead: memdagWrite
|
|
6580
|
+
});
|
|
6585
6581
|
for (let i = newMemdagMutations.length - 1; i >= 0; i--) {
|
|
6586
6582
|
newMemdagHeadHash = (await rebaseMutationAndPutCommit(
|
|
6587
6583
|
newMemdagMutations[i],
|
|
@@ -7624,7 +7620,7 @@ var ReplicacheImpl = class {
|
|
|
7624
7620
|
void this.#schedulePersist();
|
|
7625
7621
|
return;
|
|
7626
7622
|
}
|
|
7627
|
-
const zeroData2 = await this.#zero?.getTxData?.(
|
|
7623
|
+
const zeroData2 = await this.#zero?.getTxData?.(syncHead);
|
|
7628
7624
|
for (const mutation of replayMutations) {
|
|
7629
7625
|
if (this.#subscriptions.hasPendingSubscriptionRuns) {
|
|
7630
7626
|
await Promise.resolve();
|
|
@@ -8190,7 +8186,7 @@ var ReplicacheImpl = class {
|
|
|
8190
8186
|
clientID,
|
|
8191
8187
|
await dbWrite.getMutationID(),
|
|
8192
8188
|
"initial",
|
|
8193
|
-
await this.#zero?.getTxData(
|
|
8189
|
+
await this.#zero?.getTxData(headHash, {
|
|
8194
8190
|
openLazyRead: dagWrite
|
|
8195
8191
|
}),
|
|
8196
8192
|
dbWrite,
|
|
@@ -13686,14 +13682,7 @@ var IVMSourceBranch = class _IVMSourceBranch {
|
|
|
13686
13682
|
/**
|
|
13687
13683
|
* Fork the branch and patch it up to match the desired head.
|
|
13688
13684
|
*/
|
|
13689
|
-
async forkToHead(
|
|
13690
|
-
if (reason === "initial") {
|
|
13691
|
-
assert(
|
|
13692
|
-
this.hash === desiredHead,
|
|
13693
|
-
"main branch must be at desired head for `initial`"
|
|
13694
|
-
);
|
|
13695
|
-
return this;
|
|
13696
|
-
}
|
|
13685
|
+
async forkToHead(store, desiredHead, readOptions) {
|
|
13697
13686
|
const fork = this.fork();
|
|
13698
13687
|
if (fork.hash === desiredHead) {
|
|
13699
13688
|
return fork;
|
|
@@ -14114,12 +14103,7 @@ var TransactionImpl = class {
|
|
|
14114
14103
|
this.mutate = makeSchemaCRUD(
|
|
14115
14104
|
schema,
|
|
14116
14105
|
repTx,
|
|
14117
|
-
|
|
14118
|
-
// for `initial`. The IVM store will be updated via calls to `advance`
|
|
14119
|
-
// after the transaction has been committed to the Replicache b-tree.
|
|
14120
|
-
// Mutating the IVM store in the mutator would cause us to synchronously
|
|
14121
|
-
// notify listeners of IVM while we're inside of the Replicache DB transaction.
|
|
14122
|
-
repTx.reason === "initial" ? void 0 : must(
|
|
14106
|
+
must(
|
|
14123
14107
|
castedRepTx[zeroData],
|
|
14124
14108
|
"zero was not set on replicache internal options!"
|
|
14125
14109
|
)
|
|
@@ -14515,7 +14499,7 @@ function makeMessage(message, context, logLevel) {
|
|
|
14515
14499
|
}
|
|
14516
14500
|
|
|
14517
14501
|
// ../zero-client/src/client/version.ts
|
|
14518
|
-
var version2 = "0.17.
|
|
14502
|
+
var version2 = "0.17.2025031401";
|
|
14519
14503
|
|
|
14520
14504
|
// ../zero-client/src/client/log-options.ts
|
|
14521
14505
|
var LevelFilterLogSink = class {
|
|
@@ -15467,12 +15451,11 @@ var ZeroRep = class {
|
|
|
15467
15451
|
this.#store = store;
|
|
15468
15452
|
this.#context.processChanges(void 0, hash2, diffs);
|
|
15469
15453
|
}
|
|
15470
|
-
getTxData = (
|
|
15454
|
+
getTxData = (desiredHead, readOptions) => {
|
|
15471
15455
|
if (!this.#customMutatorsEnabled) {
|
|
15472
15456
|
return;
|
|
15473
15457
|
}
|
|
15474
15458
|
return this.#ivmMain.forkToHead(
|
|
15475
|
-
reason,
|
|
15476
15459
|
must(this.#store),
|
|
15477
15460
|
desiredHead,
|
|
15478
15461
|
readOptions
|
|
@@ -15673,19 +15656,45 @@ var Zero = class {
|
|
|
15673
15656
|
[CRUD_MUTATION_NAME]: makeCRUDMutator(schema)
|
|
15674
15657
|
};
|
|
15675
15658
|
this.#ivmMain = new IVMSourceBranch(schema.tables);
|
|
15659
|
+
function assertUnique(key) {
|
|
15660
|
+
assert(
|
|
15661
|
+
replicacheMutators[key] === void 0,
|
|
15662
|
+
`A mutator, or mutator namespace, has already been defined for ${key}`
|
|
15663
|
+
);
|
|
15664
|
+
}
|
|
15676
15665
|
const lc = new LogContext4(logOptions.logLevel, {}, logOptions.logSink);
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15680
|
-
for (const [name, mutator] of Object.entries(
|
|
15681
|
-
mutatorsForNamespace
|
|
15666
|
+
if (options.mutators) {
|
|
15667
|
+
for (const [namespaceOrKey, mutatorOrMutators] of Object.entries(
|
|
15668
|
+
options.mutators
|
|
15682
15669
|
)) {
|
|
15683
|
-
|
|
15684
|
-
|
|
15685
|
-
|
|
15686
|
-
|
|
15687
|
-
|
|
15688
|
-
|
|
15670
|
+
if (typeof mutatorOrMutators === "function") {
|
|
15671
|
+
const key = namespaceOrKey;
|
|
15672
|
+
assertUnique(key);
|
|
15673
|
+
replicacheMutators[key] = makeReplicacheMutator(
|
|
15674
|
+
lc,
|
|
15675
|
+
mutatorOrMutators,
|
|
15676
|
+
schema,
|
|
15677
|
+
slowMaterializeThreshold
|
|
15678
|
+
);
|
|
15679
|
+
continue;
|
|
15680
|
+
}
|
|
15681
|
+
if (typeof mutatorOrMutators === "object") {
|
|
15682
|
+
for (const [name, mutator] of Object.entries(mutatorOrMutators)) {
|
|
15683
|
+
const key = customMutatorKey(
|
|
15684
|
+
namespaceOrKey,
|
|
15685
|
+
name
|
|
15686
|
+
);
|
|
15687
|
+
assertUnique(key);
|
|
15688
|
+
replicacheMutators[key] = makeReplicacheMutator(
|
|
15689
|
+
lc,
|
|
15690
|
+
mutator,
|
|
15691
|
+
schema,
|
|
15692
|
+
slowMaterializeThreshold
|
|
15693
|
+
);
|
|
15694
|
+
}
|
|
15695
|
+
continue;
|
|
15696
|
+
}
|
|
15697
|
+
unreachable(mutatorOrMutators);
|
|
15689
15698
|
}
|
|
15690
15699
|
}
|
|
15691
15700
|
this.storageKey = storageKey ?? "";
|
|
@@ -15759,19 +15768,23 @@ var Zero = class {
|
|
|
15759
15768
|
if (options.mutators) {
|
|
15760
15769
|
mutate = {};
|
|
15761
15770
|
mutateBatch = void 0;
|
|
15762
|
-
|
|
15763
|
-
|
|
15764
|
-
options.mutators ?? {}
|
|
15765
|
-
)) {
|
|
15766
|
-
let existing = mutate[namespace];
|
|
15767
|
-
if (existing === void 0) {
|
|
15768
|
-
existing = {};
|
|
15769
|
-
mutate[namespace] = existing;
|
|
15770
|
-
}
|
|
15771
|
-
for (const name of Object.keys(
|
|
15772
|
-
mutatorsForNamespace
|
|
15771
|
+
for (const [namespaceOrKey, mutatorsOrMutator] of Object.entries(
|
|
15772
|
+
options.mutators
|
|
15773
15773
|
)) {
|
|
15774
|
-
|
|
15774
|
+
if (typeof mutatorsOrMutator === "function") {
|
|
15775
|
+
mutate[namespaceOrKey] = must(rep.mutate[namespaceOrKey]);
|
|
15776
|
+
continue;
|
|
15777
|
+
}
|
|
15778
|
+
let existing = mutate[namespaceOrKey];
|
|
15779
|
+
if (existing === void 0) {
|
|
15780
|
+
existing = {};
|
|
15781
|
+
mutate[namespaceOrKey] = existing;
|
|
15782
|
+
}
|
|
15783
|
+
for (const name of Object.keys(mutatorsOrMutator)) {
|
|
15784
|
+
existing[name] = must(
|
|
15785
|
+
rep.mutate[customMutatorKey(namespaceOrKey, name)]
|
|
15786
|
+
);
|
|
15787
|
+
}
|
|
15775
15788
|
}
|
|
15776
15789
|
}
|
|
15777
15790
|
this.mutate = mutate;
|
|
@@ -16791,4 +16804,4 @@ export {
|
|
|
16791
16804
|
escapeLike,
|
|
16792
16805
|
Zero
|
|
16793
16806
|
};
|
|
16794
|
-
//# sourceMappingURL=chunk-
|
|
16807
|
+
//# sourceMappingURL=chunk-UZE45UK4.js.map
|