@rocicorp/zero 0.13.2025020400 → 0.13.2025020402
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 +2 -2
- package/out/{chunk-RC3FUXOA.js → chunk-ADFMUREC.js} +1092 -928
- package/out/chunk-ADFMUREC.js.map +7 -0
- package/out/{chunk-ZVLXEWWB.js → chunk-Q6D7EOS6.js} +1 -1
- package/out/{chunk-ZVLXEWWB.js.map → chunk-Q6D7EOS6.js.map} +2 -2
- package/out/chunk-ULOTOBTC.js +1 -0
- package/out/react.js +44 -3
- package/out/react.js.map +3 -3
- package/out/replicache/src/patch-operation.d.ts +1 -1
- package/out/replicache/src/patch-operation.d.ts.map +1 -1
- package/out/solid.js +112 -37
- package/out/solid.js.map +2 -2
- package/out/zero-advanced/src/mod.d.ts +1 -1
- package/out/zero-advanced/src/mod.d.ts.map +1 -1
- package/out/zero-cache/src/auth/load-schema.d.ts +1 -1
- package/out/zero-cache/src/auth/load-schema.d.ts.map +1 -1
- package/out/zero-cache/src/auth/load-schema.js +8 -1
- package/out/zero-cache/src/auth/load-schema.js.map +1 -1
- package/out/zero-client/src/client/context.d.ts +2 -2
- package/out/zero-client/src/client/context.d.ts.map +1 -1
- package/out/zero-client/src/client/custom.d.ts +9 -2
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/ivm-source-repo.d.ts +34 -0
- package/out/zero-client/src/client/ivm-source-repo.d.ts.map +1 -0
- package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
- package/out/zero-client/src/client/zero-poke-handler.d.ts +2 -9
- package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-protocol/src/ast.d.ts +3 -4
- package/out/zero-protocol/src/ast.d.ts.map +1 -1
- package/out/zero-protocol/src/ast.js +10 -56
- package/out/zero-protocol/src/ast.js.map +1 -1
- package/out/zero-protocol/src/push.d.ts +2 -0
- package/out/zero-protocol/src/push.d.ts.map +1 -1
- package/out/zero-protocol/src/push.js +24 -0
- package/out/zero-protocol/src/push.js.map +1 -1
- package/out/zero-schema/src/builder/schema-builder.d.ts +1 -0
- package/out/zero-schema/src/builder/schema-builder.d.ts.map +1 -1
- package/out/zero-schema/src/builder/schema-builder.js +49 -0
- package/out/zero-schema/src/builder/schema-builder.js.map +1 -1
- package/out/zero-schema/src/mod.d.ts +5 -0
- package/out/zero-schema/src/mod.d.ts.map +1 -0
- package/out/zero-schema/src/name-mapper.d.ts +23 -0
- package/out/zero-schema/src/name-mapper.d.ts.map +1 -0
- package/out/zero-schema/src/name-mapper.js +77 -0
- package/out/zero-schema/src/name-mapper.js.map +1 -0
- package/out/zero-schema/src/permissions.d.ts.map +1 -1
- package/out/zero-solid/src/solid-view.d.ts +3 -2
- package/out/zero-solid/src/solid-view.d.ts.map +1 -1
- package/out/zero.js +2 -2
- package/out/zql/src/ivm/memory-source.d.ts +3 -1
- package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
- package/out/zql/src/ivm/memory-source.js +6 -2
- package/out/zql/src/ivm/memory-source.js.map +1 -1
- package/out/zql/src/ivm/view-apply-change.d.ts +34 -2
- package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
- package/out/zql/src/ivm/view-apply-change.js.map +1 -1
- package/package.json +1 -1
- package/out/chunk-5JO5DB4D.js +0 -50
- package/out/chunk-5JO5DB4D.js.map +0 -7
- package/out/chunk-ALG35NEG.js +0 -1
- package/out/chunk-RC3FUXOA.js.map +0 -7
- /package/out/{chunk-ALG35NEG.js.map → chunk-ULOTOBTC.js.map} +0 -0
|
@@ -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 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 assertUndefined,\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 type {Change} from './change.ts';\nimport {drainStreams, type Comparator} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Entry, EntryList, Format} from './view.ts';\n\nexport function applyChange(\n parentEntry: Entry,\n change: Change,\n schema: SourceSchema,\n relationship: string,\n format: Format,\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 );\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 );\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 assertUndefined(\n parentEntry[relationship],\n 'single output already exists',\n );\n parentEntry[relationship] = newEntry;\n } else {\n const view = getChildEntryList(parentEntry, relationship);\n const {pos, found} = binarySearch(view, newEntry, schema.compareRows);\n assert(!found, 'node already exists');\n // @ts-expect-error view is readonly\n view.splice(pos, 0, newEntry);\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 newEntry[relationship] = newView;\n for (const node of children()) {\n applyChange(\n newEntry,\n {type: 'add', node},\n childSchema,\n relationship,\n childFormat,\n );\n }\n }\n break;\n }\n case 'remove': {\n if (singular) {\n assertObject(parentEntry[relationship]);\n parentEntry[relationship] = undefined;\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 // @ts-expect-error view is readonly\n view.splice(pos, 1);\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 );\n }\n break;\n }\n case 'edit': {\n if (singular) {\n assertObject(parentEntry[relationship]);\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 view[pos] = makeEntryPreserveRelationships(\n change.node.row,\n view[pos],\n schema.relationships,\n );\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 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);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aAAa,MAAY;AACvC,aAAW,UAAU,OAAO,OAAO,KAAK,aAAa,GAAG;AACtD,eAAWA,SAAQ,OAAO,GAAG;AAC3B,mBAAaA,KAAI;AAAA,IACnB;AAAA,EACF;AACF;;;
|
|
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 assertUndefined,\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\nexport function applyChange(\n parentEntry: Entry,\n change: ViewChange,\n schema: SourceSchema,\n relationship: string,\n format: Format,\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 );\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 );\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 assertUndefined(\n parentEntry[relationship],\n 'single output already exists',\n );\n parentEntry[relationship] = newEntry;\n } else {\n const view = getChildEntryList(parentEntry, relationship);\n const {pos, found} = binarySearch(view, newEntry, schema.compareRows);\n assert(!found, 'node already exists');\n // @ts-expect-error view is readonly\n view.splice(pos, 0, newEntry);\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 newEntry[relationship] = newView;\n for (const node of children()) {\n applyChange(\n newEntry,\n {type: 'add', node},\n childSchema,\n relationship,\n childFormat,\n );\n }\n }\n break;\n }\n case 'remove': {\n if (singular) {\n assertObject(parentEntry[relationship]);\n parentEntry[relationship] = undefined;\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 // @ts-expect-error view is readonly\n view.splice(pos, 1);\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 );\n }\n break;\n }\n case 'edit': {\n if (singular) {\n assertObject(parentEntry[relationship]);\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 view[pos] = makeEntryPreserveRelationships(\n change.node.row,\n view[pos],\n schema.relationships,\n );\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 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,MA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AACxC,WAAO,EAAE,gBAAgB,MAAM,6BAA6B;AAC5D,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
6
|
"names": ["node", "relationship", "pos", "found"]
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-ULOTOBTC.js.map
|
package/out/react.js
CHANGED
|
@@ -1,12 +1,53 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-HARIWJ2J.js";
|
|
2
|
+
hasOwn
|
|
3
|
+
} from "./chunk-HARIWJ2J.js";
|
|
5
4
|
import "./chunk-424PT5DM.js";
|
|
6
5
|
|
|
7
6
|
// ../zero-react/src/use-query.tsx
|
|
8
7
|
import { useSyncExternalStore } from "react";
|
|
9
8
|
|
|
9
|
+
// ../shared/src/deep-clone.ts
|
|
10
|
+
function deepClone(value) {
|
|
11
|
+
const seen = [];
|
|
12
|
+
return internalDeepClone(value, seen);
|
|
13
|
+
}
|
|
14
|
+
function internalDeepClone(value, seen) {
|
|
15
|
+
switch (typeof value) {
|
|
16
|
+
case "boolean":
|
|
17
|
+
case "number":
|
|
18
|
+
case "string":
|
|
19
|
+
case "undefined":
|
|
20
|
+
return value;
|
|
21
|
+
case "object": {
|
|
22
|
+
if (value === null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (seen.includes(value)) {
|
|
26
|
+
throw new Error("Cyclic object");
|
|
27
|
+
}
|
|
28
|
+
seen.push(value);
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
const rv = value.map((v) => internalDeepClone(v, seen));
|
|
31
|
+
seen.pop();
|
|
32
|
+
return rv;
|
|
33
|
+
}
|
|
34
|
+
const obj = {};
|
|
35
|
+
for (const k in value) {
|
|
36
|
+
if (hasOwn(value, k)) {
|
|
37
|
+
const v = value[k];
|
|
38
|
+
if (v !== void 0) {
|
|
39
|
+
obj[k] = internalDeepClone(v, seen);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
seen.pop();
|
|
44
|
+
return obj;
|
|
45
|
+
}
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`Invalid type: ${typeof value}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
10
51
|
// ../zero-react/src/use-zero.tsx
|
|
11
52
|
import { createContext, useContext } from "react";
|
|
12
53
|
import { jsx } from "react/jsx-runtime";
|
package/out/react.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../zero-react/src/use-query.tsx", "../../zero-react/src/use-zero.tsx"],
|
|
4
|
-
"sourcesContent": ["import {useSyncExternalStore} from 'react';\nimport {deepClone} from '../../shared/src/deep-clone.ts';\nimport type {Immutable} from '../../shared/src/immutable.ts';\nimport type {ReadonlyJSONValue} from '../../shared/src/json.ts';\nimport type {Schema} from '../../zero-schema/src/builder/schema-builder.ts';\nimport type {AdvancedQuery} from '../../zql/src/query/query-internal.ts';\nimport type {HumanReadable, Query} from '../../zql/src/query/query.ts';\nimport type {ResultType, TypedView} from '../../zql/src/query/typed-view.ts';\nimport {useZero} from './use-zero.tsx';\n\nexport type QueryResultDetails = Readonly<{\n type: ResultType;\n}>;\n\nexport type QueryResult<TReturn> = readonly [\n HumanReadable<TReturn>,\n QueryResultDetails,\n];\n\nexport function useQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n q: Query<TSchema, TTable, TReturn>,\n enable: boolean = true,\n): QueryResult<TReturn> {\n const z = useZero();\n const view = viewStore.getView(\n z.clientID,\n q as AdvancedQuery<TSchema, TTable, TReturn>,\n enable,\n );\n // https://react.dev/reference/react/useSyncExternalStore\n return useSyncExternalStore(\n view.subscribeReactInternals,\n view.getSnapshot,\n view.getSnapshot,\n );\n}\n\nconst emptyArray: unknown[] = [];\nconst disabledSubscriber = () => () => {};\n\nconst resultTypeUnknown = {type: 'unknown'} as const;\nconst resultTypeComplete = {type: 'complete'} as const;\n\nconst emptySnapshotSingularUnknown = [undefined, resultTypeUnknown] as const;\nconst emptySnapshotSingularComplete = [undefined, resultTypeComplete] as const;\nconst emptySnapshotPluralUnknown = [emptyArray, resultTypeUnknown] as const;\nconst emptySnapshotPluralComplete = [emptyArray, resultTypeComplete] as const;\n\nfunction getDefaultSnapshot<TReturn>(singular: boolean): QueryResult<TReturn> {\n return (\n singular ? emptySnapshotSingularUnknown : emptySnapshotPluralUnknown\n ) as QueryResult<TReturn>;\n}\n\n/**\n * Returns a new snapshot or one of the empty predefined ones. Returning the\n * predefined ones is important to prevent unnecessary re-renders in React.\n */\nfunction getSnapshot<TReturn>(\n singular: boolean,\n data: HumanReadable<TReturn>,\n resultType: string,\n): QueryResult<TReturn> {\n if (singular && data === undefined) {\n return (resultType === 'complete'\n ? emptySnapshotSingularComplete\n : emptySnapshotSingularUnknown) as unknown as QueryResult<TReturn>;\n }\n\n if (!singular && (data as unknown[]).length === 0) {\n return (\n resultType === 'complete'\n ? emptySnapshotPluralComplete\n : emptySnapshotPluralUnknown\n ) as QueryResult<TReturn>;\n }\n\n return [\n data,\n resultType === 'complete' ? resultTypeComplete : resultTypeUnknown,\n ];\n}\n\ndeclare const TESTING: boolean;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ViewWrapperAny = ViewWrapper<any, any, any>;\n\nconst allViews = new WeakMap<ViewStore, Map<string, ViewWrapperAny>>();\n\nexport function getAllViewsSizeForTesting(store: ViewStore): number {\n if (TESTING) {\n return allViews.get(store)?.size ?? 0;\n }\n return 0;\n}\n\n/**\n * A global store of all active views.\n *\n * React subscribes and unsubscribes to these views\n * via `useSyncExternalStore`.\n *\n * Managing views through `useEffect` or `useLayoutEffect` causes\n * inconsistencies because effects run after render.\n *\n * For example, if useQuery used use*Effect in the component below:\n * ```ts\n * function Foo({issueID}) {\n * const issue = useQuery(z.query.issue.where('id', issueID).one());\n * if (issue?.id !== undefined && issue.id !== issueID) {\n * console.log('MISMATCH!', issue.id, issueID);\n * }\n * }\n * ```\n *\n * `MISMATCH` will be printed whenever the `issueID` prop changes.\n *\n * This is because the component will render once with\n * the old state returned from `useQuery`. Then the effect inside\n * `useQuery` will run. The component will render again with the new\n * state. This inconsistent transition can cause unexpected results.\n *\n * Emulating `useEffect` via `useState` and `if` causes resource leaks.\n * That is:\n *\n * ```ts\n * function useQuery(q) {\n * const [oldHash, setOldHash] = useState();\n * if (hash(q) !== oldHash) {\n * // make new view\n * }\n *\n * useEffect(() => {\n * return () => view.destroy();\n * }, []);\n * }\n * ```\n *\n * I'm not sure why but in strict mode the cleanup function\n * fails to be called for the first instance of the view and only\n * cleans up later instances.\n *\n * Swapping `useState` to `useRef` has similar problems.\n */\nexport class ViewStore {\n #views = new Map<string, ViewWrapperAny>();\n\n constructor() {\n if (TESTING) {\n allViews.set(this, this.#views);\n }\n }\n\n getView<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n >(\n clientID: string,\n query: AdvancedQuery<TSchema, TTable, TReturn>,\n enabled: boolean,\n ): {\n getSnapshot: () => QueryResult<TReturn>;\n subscribeReactInternals: (internals: () => void) => () => void;\n } {\n if (!enabled) {\n return {\n getSnapshot: () => getDefaultSnapshot(query.format.singular),\n subscribeReactInternals: disabledSubscriber,\n };\n }\n\n const hash = query.hash() + clientID;\n let existing = this.#views.get(hash);\n if (!existing) {\n existing = new ViewWrapper(\n query,\n view => {\n const lastView = this.#views.get(hash);\n // I don't think this can happen\n // but lets guard against it so we don't\n // leak resources.\n if (lastView && lastView !== view) {\n throw new Error('View already exists');\n }\n this.#views.set(hash, view);\n },\n () => {\n this.#views.delete(hash);\n },\n ) as ViewWrapper<TSchema, TTable, TReturn>;\n this.#views.set(hash, existing);\n }\n return existing as ViewWrapper<TSchema, TTable, TReturn>;\n }\n}\n\nconst viewStore = new ViewStore();\n\n/**\n * This wraps and ref counts a view.\n *\n * The only signal we have from React as to whether or not it is\n * done with a view is when it calls `unsubscribe`.\n *\n * In non-strict-mode we can clean up the view as soon\n * as the listener count goes to 0.\n *\n * In strict-mode, the listener count will go to 0 then a\n * new listener for the same view is immediately added back.\n *\n * This is why the `onMaterialized` and `onDematerialized` callbacks exist --\n * they allow a view which React is still referencing to be added\n * back into the store when React re-subscribes to it.\n *\n * This wrapper also exists to deal with the various\n * `useSyncExternalStore` caveats that cause excessive\n * re-renders and materializations.\n *\n * See: https://react.dev/reference/react/useSyncExternalStore#caveats\n * Especially:\n * 1. The store snapshot returned by getSnapshot must be immutable. If the underlying store has mutable data, return a new immutable snapshot if the data has changed. Otherwise, return a cached last snapshot.\n * 2. If a different subscribe function is passed during a re-render, React will re-subscribe to the store using the newly passed subscribe function. You can prevent this by declaring subscribe outside the component.\n */\nclass ViewWrapper<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n> {\n #view: TypedView<HumanReadable<TReturn>> | undefined;\n readonly #onDematerialized;\n readonly #onMaterialized;\n readonly #query: AdvancedQuery<TSchema, TTable, TReturn>;\n #snapshot: QueryResult<TReturn>;\n #reactInternals: Set<() => void>;\n\n constructor(\n query: AdvancedQuery<TSchema, TTable, TReturn>,\n onMaterialized: (view: ViewWrapper<TSchema, TTable, TReturn>) => void,\n onDematerialized: () => void,\n ) {\n this.#snapshot = getDefaultSnapshot(query.format.singular);\n this.#onMaterialized = onMaterialized;\n this.#onDematerialized = onDematerialized;\n this.#reactInternals = new Set();\n this.#query = query;\n this.#materializeIfNeeded();\n }\n\n #onData = (\n snap: Immutable<HumanReadable<TReturn>>,\n resultType: ResultType,\n ) => {\n const data =\n snap === undefined\n ? snap\n : (deepClone(snap as ReadonlyJSONValue) as HumanReadable<TReturn>);\n this.#snapshot = getSnapshot(this.#query.format.singular, data, resultType);\n for (const internals of this.#reactInternals) {\n internals();\n }\n };\n\n #materializeIfNeeded = () => {\n if (this.#view) {\n return;\n }\n\n this.#view = this.#query.materialize();\n this.#view.addListener(this.#onData);\n\n this.#onMaterialized(this);\n };\n\n getSnapshot = () => this.#snapshot;\n\n subscribeReactInternals = (internals: () => void): (() => void) => {\n this.#reactInternals.add(internals);\n this.#materializeIfNeeded();\n return () => {\n this.#reactInternals.delete(internals);\n\n // only schedule a cleanup task if we have no listeners left\n if (this.#reactInternals.size === 0) {\n setTimeout(() => {\n // Someone re-registered a listener on this view before the timeout elapsed.\n // This happens often in strict-mode which forces a component\n // to mount, unmount, remount.\n if (this.#reactInternals.size > 0) {\n return;\n }\n // We already destroyed the view\n if (this.#view === undefined) {\n return;\n }\n this.#view?.destroy();\n this.#view = undefined;\n this.#onDematerialized();\n }, 10);\n }\n };\n };\n}\n", "import {createContext, useContext} from 'react';\nimport type {Zero} from '../../zero-client/src/client/zero.ts';\nimport type {Schema} from '../../zero-schema/src/builder/schema-builder.ts';\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst ZeroContext = createContext<unknown | undefined>(undefined);\n\nexport function useZero<S extends Schema>(): Zero<S> {\n const zero = useContext(ZeroContext);\n if (zero === undefined) {\n throw new Error('useZero must be used within a ZeroProvider');\n }\n return zero as Zero<S>;\n}\n\nexport function createUseZero<S extends Schema>() {\n return () => useZero<S>();\n}\n\nexport function ZeroProvider<S extends Schema>({\n children,\n zero,\n}: {\n children: React.ReactNode;\n zero: Zero<S>;\n}) {\n return <ZeroContext.Provider value={zero}>{children}</ZeroContext.Provider>;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../zero-react/src/use-query.tsx", "../../shared/src/deep-clone.ts", "../../zero-react/src/use-zero.tsx"],
|
|
4
|
+
"sourcesContent": ["import {useSyncExternalStore} from 'react';\nimport {deepClone} from '../../shared/src/deep-clone.ts';\nimport type {Immutable} from '../../shared/src/immutable.ts';\nimport type {ReadonlyJSONValue} from '../../shared/src/json.ts';\nimport type {Schema} from '../../zero-schema/src/builder/schema-builder.ts';\nimport type {AdvancedQuery} from '../../zql/src/query/query-internal.ts';\nimport type {HumanReadable, Query} from '../../zql/src/query/query.ts';\nimport type {ResultType, TypedView} from '../../zql/src/query/typed-view.ts';\nimport {useZero} from './use-zero.tsx';\n\nexport type QueryResultDetails = Readonly<{\n type: ResultType;\n}>;\n\nexport type QueryResult<TReturn> = readonly [\n HumanReadable<TReturn>,\n QueryResultDetails,\n];\n\nexport function useQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n q: Query<TSchema, TTable, TReturn>,\n enable: boolean = true,\n): QueryResult<TReturn> {\n const z = useZero();\n const view = viewStore.getView(\n z.clientID,\n q as AdvancedQuery<TSchema, TTable, TReturn>,\n enable,\n );\n // https://react.dev/reference/react/useSyncExternalStore\n return useSyncExternalStore(\n view.subscribeReactInternals,\n view.getSnapshot,\n view.getSnapshot,\n );\n}\n\nconst emptyArray: unknown[] = [];\nconst disabledSubscriber = () => () => {};\n\nconst resultTypeUnknown = {type: 'unknown'} as const;\nconst resultTypeComplete = {type: 'complete'} as const;\n\nconst emptySnapshotSingularUnknown = [undefined, resultTypeUnknown] as const;\nconst emptySnapshotSingularComplete = [undefined, resultTypeComplete] as const;\nconst emptySnapshotPluralUnknown = [emptyArray, resultTypeUnknown] as const;\nconst emptySnapshotPluralComplete = [emptyArray, resultTypeComplete] as const;\n\nfunction getDefaultSnapshot<TReturn>(singular: boolean): QueryResult<TReturn> {\n return (\n singular ? emptySnapshotSingularUnknown : emptySnapshotPluralUnknown\n ) as QueryResult<TReturn>;\n}\n\n/**\n * Returns a new snapshot or one of the empty predefined ones. Returning the\n * predefined ones is important to prevent unnecessary re-renders in React.\n */\nfunction getSnapshot<TReturn>(\n singular: boolean,\n data: HumanReadable<TReturn>,\n resultType: string,\n): QueryResult<TReturn> {\n if (singular && data === undefined) {\n return (resultType === 'complete'\n ? emptySnapshotSingularComplete\n : emptySnapshotSingularUnknown) as unknown as QueryResult<TReturn>;\n }\n\n if (!singular && (data as unknown[]).length === 0) {\n return (\n resultType === 'complete'\n ? emptySnapshotPluralComplete\n : emptySnapshotPluralUnknown\n ) as QueryResult<TReturn>;\n }\n\n return [\n data,\n resultType === 'complete' ? resultTypeComplete : resultTypeUnknown,\n ];\n}\n\ndeclare const TESTING: boolean;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ViewWrapperAny = ViewWrapper<any, any, any>;\n\nconst allViews = new WeakMap<ViewStore, Map<string, ViewWrapperAny>>();\n\nexport function getAllViewsSizeForTesting(store: ViewStore): number {\n if (TESTING) {\n return allViews.get(store)?.size ?? 0;\n }\n return 0;\n}\n\n/**\n * A global store of all active views.\n *\n * React subscribes and unsubscribes to these views\n * via `useSyncExternalStore`.\n *\n * Managing views through `useEffect` or `useLayoutEffect` causes\n * inconsistencies because effects run after render.\n *\n * For example, if useQuery used use*Effect in the component below:\n * ```ts\n * function Foo({issueID}) {\n * const issue = useQuery(z.query.issue.where('id', issueID).one());\n * if (issue?.id !== undefined && issue.id !== issueID) {\n * console.log('MISMATCH!', issue.id, issueID);\n * }\n * }\n * ```\n *\n * `MISMATCH` will be printed whenever the `issueID` prop changes.\n *\n * This is because the component will render once with\n * the old state returned from `useQuery`. Then the effect inside\n * `useQuery` will run. The component will render again with the new\n * state. This inconsistent transition can cause unexpected results.\n *\n * Emulating `useEffect` via `useState` and `if` causes resource leaks.\n * That is:\n *\n * ```ts\n * function useQuery(q) {\n * const [oldHash, setOldHash] = useState();\n * if (hash(q) !== oldHash) {\n * // make new view\n * }\n *\n * useEffect(() => {\n * return () => view.destroy();\n * }, []);\n * }\n * ```\n *\n * I'm not sure why but in strict mode the cleanup function\n * fails to be called for the first instance of the view and only\n * cleans up later instances.\n *\n * Swapping `useState` to `useRef` has similar problems.\n */\nexport class ViewStore {\n #views = new Map<string, ViewWrapperAny>();\n\n constructor() {\n if (TESTING) {\n allViews.set(this, this.#views);\n }\n }\n\n getView<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n >(\n clientID: string,\n query: AdvancedQuery<TSchema, TTable, TReturn>,\n enabled: boolean,\n ): {\n getSnapshot: () => QueryResult<TReturn>;\n subscribeReactInternals: (internals: () => void) => () => void;\n } {\n if (!enabled) {\n return {\n getSnapshot: () => getDefaultSnapshot(query.format.singular),\n subscribeReactInternals: disabledSubscriber,\n };\n }\n\n const hash = query.hash() + clientID;\n let existing = this.#views.get(hash);\n if (!existing) {\n existing = new ViewWrapper(\n query,\n view => {\n const lastView = this.#views.get(hash);\n // I don't think this can happen\n // but lets guard against it so we don't\n // leak resources.\n if (lastView && lastView !== view) {\n throw new Error('View already exists');\n }\n this.#views.set(hash, view);\n },\n () => {\n this.#views.delete(hash);\n },\n ) as ViewWrapper<TSchema, TTable, TReturn>;\n this.#views.set(hash, existing);\n }\n return existing as ViewWrapper<TSchema, TTable, TReturn>;\n }\n}\n\nconst viewStore = new ViewStore();\n\n/**\n * This wraps and ref counts a view.\n *\n * The only signal we have from React as to whether or not it is\n * done with a view is when it calls `unsubscribe`.\n *\n * In non-strict-mode we can clean up the view as soon\n * as the listener count goes to 0.\n *\n * In strict-mode, the listener count will go to 0 then a\n * new listener for the same view is immediately added back.\n *\n * This is why the `onMaterialized` and `onDematerialized` callbacks exist --\n * they allow a view which React is still referencing to be added\n * back into the store when React re-subscribes to it.\n *\n * This wrapper also exists to deal with the various\n * `useSyncExternalStore` caveats that cause excessive\n * re-renders and materializations.\n *\n * See: https://react.dev/reference/react/useSyncExternalStore#caveats\n * Especially:\n * 1. The store snapshot returned by getSnapshot must be immutable. If the underlying store has mutable data, return a new immutable snapshot if the data has changed. Otherwise, return a cached last snapshot.\n * 2. If a different subscribe function is passed during a re-render, React will re-subscribe to the store using the newly passed subscribe function. You can prevent this by declaring subscribe outside the component.\n */\nclass ViewWrapper<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n> {\n #view: TypedView<HumanReadable<TReturn>> | undefined;\n readonly #onDematerialized;\n readonly #onMaterialized;\n readonly #query: AdvancedQuery<TSchema, TTable, TReturn>;\n #snapshot: QueryResult<TReturn>;\n #reactInternals: Set<() => void>;\n\n constructor(\n query: AdvancedQuery<TSchema, TTable, TReturn>,\n onMaterialized: (view: ViewWrapper<TSchema, TTable, TReturn>) => void,\n onDematerialized: () => void,\n ) {\n this.#snapshot = getDefaultSnapshot(query.format.singular);\n this.#onMaterialized = onMaterialized;\n this.#onDematerialized = onDematerialized;\n this.#reactInternals = new Set();\n this.#query = query;\n this.#materializeIfNeeded();\n }\n\n #onData = (\n snap: Immutable<HumanReadable<TReturn>>,\n resultType: ResultType,\n ) => {\n const data =\n snap === undefined\n ? snap\n : (deepClone(snap as ReadonlyJSONValue) as HumanReadable<TReturn>);\n this.#snapshot = getSnapshot(this.#query.format.singular, data, resultType);\n for (const internals of this.#reactInternals) {\n internals();\n }\n };\n\n #materializeIfNeeded = () => {\n if (this.#view) {\n return;\n }\n\n this.#view = this.#query.materialize();\n this.#view.addListener(this.#onData);\n\n this.#onMaterialized(this);\n };\n\n getSnapshot = () => this.#snapshot;\n\n subscribeReactInternals = (internals: () => void): (() => void) => {\n this.#reactInternals.add(internals);\n this.#materializeIfNeeded();\n return () => {\n this.#reactInternals.delete(internals);\n\n // only schedule a cleanup task if we have no listeners left\n if (this.#reactInternals.size === 0) {\n setTimeout(() => {\n // Someone re-registered a listener on this view before the timeout elapsed.\n // This happens often in strict-mode which forces a component\n // to mount, unmount, remount.\n if (this.#reactInternals.size > 0) {\n return;\n }\n // We already destroyed the view\n if (this.#view === undefined) {\n return;\n }\n this.#view?.destroy();\n this.#view = undefined;\n this.#onDematerialized();\n }, 10);\n }\n };\n };\n}\n", "import {hasOwn} from './has-own.ts';\nimport type {JSONValue, ReadonlyJSONValue} from './json.ts';\n\nexport function deepClone(value: ReadonlyJSONValue): JSONValue {\n const seen: Array<ReadonlyJSONValue> = [];\n return internalDeepClone(value, seen);\n}\n\nexport function internalDeepClone(\n value: ReadonlyJSONValue,\n seen: Array<ReadonlyJSONValue>,\n): JSONValue {\n switch (typeof value) {\n case 'boolean':\n case 'number':\n case 'string':\n case 'undefined':\n return value;\n case 'object': {\n if (value === null) {\n return null;\n }\n if (seen.includes(value)) {\n throw new Error('Cyclic object');\n }\n seen.push(value);\n if (Array.isArray(value)) {\n const rv = value.map(v => internalDeepClone(v, seen));\n seen.pop();\n return rv;\n }\n\n const obj: JSONValue = {};\n\n for (const k in value) {\n if (hasOwn(value, k)) {\n const v = (value as Record<string, ReadonlyJSONValue>)[k];\n if (v !== undefined) {\n obj[k] = internalDeepClone(v, seen);\n }\n }\n }\n seen.pop();\n return obj;\n }\n\n default:\n throw new Error(`Invalid type: ${typeof value}`);\n }\n}\n", "import {createContext, useContext} from 'react';\nimport type {Zero} from '../../zero-client/src/client/zero.ts';\nimport type {Schema} from '../../zero-schema/src/builder/schema-builder.ts';\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst ZeroContext = createContext<unknown | undefined>(undefined);\n\nexport function useZero<S extends Schema>(): Zero<S> {\n const zero = useContext(ZeroContext);\n if (zero === undefined) {\n throw new Error('useZero must be used within a ZeroProvider');\n }\n return zero as Zero<S>;\n}\n\nexport function createUseZero<S extends Schema>() {\n return () => useZero<S>();\n}\n\nexport function ZeroProvider<S extends Schema>({\n children,\n zero,\n}: {\n children: React.ReactNode;\n zero: Zero<S>;\n}) {\n return <ZeroContext.Provider value={zero}>{children}</ZeroContext.Provider>;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;AAAA,SAAQ,4BAA2B;;;ACG5B,SAAS,UAAU,OAAqC;AAC7D,QAAM,OAAiC,CAAC;AACxC,SAAO,kBAAkB,OAAO,IAAI;AACtC;AAEO,SAAS,kBACd,OACA,MACW;AACX,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;A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AA,UACF;AACA,eAAK,OAAO,QAAQ;AACpB,eAAK,QAAQ;AACb,eAAK,kBAAkB;AAAA,QACzB,GAAG,EAAE;AAAA,MACP;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,7 +7,7 @@ export type PatchOperationInternal = {
|
|
|
7
7
|
readonly op: 'update';
|
|
8
8
|
readonly key: string;
|
|
9
9
|
readonly merge?: ReadonlyJSONObject | undefined;
|
|
10
|
-
readonly constrain?: string[] | undefined;
|
|
10
|
+
readonly constrain?: readonly string[] | undefined;
|
|
11
11
|
} | {
|
|
12
12
|
readonly op: 'del';
|
|
13
13
|
readonly key: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-operation.d.ts","sourceRoot":"","sources":["../../../../replicache/src/patch-operation.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAGvB,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,sBAAsB,GAC9B;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;CACnC,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"patch-operation.d.ts","sourceRoot":"","sources":["../../../../replicache/src/patch-operation.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAGvB,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,sBAAsB,GAC9B;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;CACnC,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;CACpD,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;CACtB,CAAC;AAEN;;;GAGG;AACH,MAAM,MAAM,cAAc,GACtB;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;CACnC,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;CACtB,CAAC;AAEN,wBAAgB,qBAAqB,CACnC,CAAC,EAAE,OAAO,GACT,OAAO,CAAC,CAAC,IAAI,sBAAsB,EAAE,CAKvC"}
|
package/out/solid.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Zero
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
deepClone
|
|
6
|
-
} from "./chunk-5JO5DB4D.js";
|
|
3
|
+
} from "./chunk-ADFMUREC.js";
|
|
7
4
|
import "./chunk-HARIWJ2J.js";
|
|
8
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-ULOTOBTC.js";
|
|
9
6
|
import {
|
|
10
7
|
applyChange
|
|
11
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-Q6D7EOS6.js";
|
|
12
9
|
import "./chunk-424PT5DM.js";
|
|
13
10
|
|
|
14
11
|
// ../zero-solid/src/create-zero.ts
|
|
@@ -27,69 +24,147 @@ import { createMemo, onCleanup } from "solid-js";
|
|
|
27
24
|
// ../zero-solid/src/solid-view.ts
|
|
28
25
|
import {
|
|
29
26
|
createStore,
|
|
30
|
-
|
|
27
|
+
produce
|
|
31
28
|
} from "solid-js/store";
|
|
32
|
-
import { createSignal } from "solid-js";
|
|
33
29
|
var complete = { type: "complete" };
|
|
34
30
|
var unknown = { type: "unknown" };
|
|
35
31
|
var SolidView = class {
|
|
36
32
|
#input;
|
|
37
33
|
#format;
|
|
38
34
|
#onDestroy;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
#state;
|
|
36
|
+
#setState;
|
|
37
|
+
// Optimization: if the store is currently empty we build up
|
|
38
|
+
// the view on a plain old JS object stored at #builderRoot, and return
|
|
39
|
+
// that for the new state on transaction commit. This avoids building up
|
|
40
|
+
// large views from scratch via solid produce. The proxy object used by
|
|
41
|
+
// solid produce is slow and in this case we don't care about solid tracking
|
|
42
|
+
// the fine grained changes (everything has changed, it's all new). For a
|
|
43
|
+
// test case with a view with 3000 rows, each row having 2 children, this
|
|
44
|
+
// optimization reduced #applyChanges time from 743ms to 133ms.
|
|
45
|
+
#builderRoot;
|
|
46
|
+
#pendingChanges = [];
|
|
45
47
|
constructor(input, onTransactionCommit, format, onDestroy, queryComplete) {
|
|
46
48
|
this.#input = input;
|
|
47
49
|
onTransactionCommit(this.#onTransactionCommit);
|
|
48
50
|
this.#format = format;
|
|
49
51
|
this.#onDestroy = onDestroy;
|
|
50
|
-
this.#root = { "": format.singular ? void 0 : [] };
|
|
51
52
|
input.setOutput(this);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
node
|
|
58
|
-
},
|
|
59
|
-
this.#input.getSchema(),
|
|
60
|
-
"",
|
|
61
|
-
this.#format
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
[this.#rootStore, this.#setRootStore] = createStore(
|
|
65
|
-
deepClone(this.#root)
|
|
53
|
+
const initialRoot = this.#createEmptyRoot();
|
|
54
|
+
this.#applyChangesToRoot(
|
|
55
|
+
input.fetch({}),
|
|
56
|
+
(node) => ({ type: "add", node }),
|
|
57
|
+
initialRoot
|
|
66
58
|
);
|
|
67
|
-
|
|
59
|
+
[this.#state, this.#setState] = createStore([
|
|
60
|
+
initialRoot,
|
|
68
61
|
queryComplete === true ? complete : unknown
|
|
69
|
-
);
|
|
70
|
-
|
|
62
|
+
]);
|
|
63
|
+
if (isEmptyRoot(initialRoot)) {
|
|
64
|
+
this.#builderRoot = this.#createEmptyRoot();
|
|
65
|
+
}
|
|
71
66
|
if (queryComplete !== true) {
|
|
72
67
|
void queryComplete.then(() => {
|
|
73
|
-
|
|
68
|
+
this.#setState((oldState) => [oldState[0], complete]);
|
|
74
69
|
});
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
get data() {
|
|
78
|
-
return this.#
|
|
73
|
+
return this.#state[0][""];
|
|
79
74
|
}
|
|
80
75
|
get resultDetails() {
|
|
81
|
-
return this.#
|
|
76
|
+
return this.#state[1];
|
|
82
77
|
}
|
|
83
78
|
destroy() {
|
|
84
79
|
this.#onDestroy();
|
|
85
80
|
}
|
|
86
81
|
#onTransactionCommit = () => {
|
|
87
|
-
this.#
|
|
82
|
+
const builderRoot = this.#builderRoot;
|
|
83
|
+
if (builderRoot) {
|
|
84
|
+
if (!isEmptyRoot(builderRoot)) {
|
|
85
|
+
this.#setState((oldState) => [builderRoot, oldState[1]]);
|
|
86
|
+
this.#builderRoot = void 0;
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
try {
|
|
90
|
+
this.#applyChanges(this.#pendingChanges, (c) => c);
|
|
91
|
+
} finally {
|
|
92
|
+
this.#pendingChanges = [];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
88
95
|
};
|
|
89
96
|
push(change) {
|
|
90
|
-
|
|
97
|
+
if (this.#builderRoot) {
|
|
98
|
+
this.#applyChangeToRoot(change, this.#builderRoot);
|
|
99
|
+
} else {
|
|
100
|
+
this.#pendingChanges.push(materializeRelationships(change));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
#applyChanges(changes, mapper) {
|
|
104
|
+
this.#setState(
|
|
105
|
+
produce((draftState) => {
|
|
106
|
+
this.#applyChangesToRoot(changes, mapper, draftState[0]);
|
|
107
|
+
if (isEmptyRoot(draftState[0])) {
|
|
108
|
+
this.#builderRoot = this.#createEmptyRoot();
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
#applyChangesToRoot(changes, mapper, root) {
|
|
114
|
+
for (const change of changes) {
|
|
115
|
+
this.#applyChangeToRoot(mapper(change), root);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
#applyChangeToRoot(change, root) {
|
|
119
|
+
applyChange(root, change, this.#input.getSchema(), "", this.#format);
|
|
120
|
+
}
|
|
121
|
+
#createEmptyRoot() {
|
|
122
|
+
return {
|
|
123
|
+
"": this.#format.singular ? void 0 : []
|
|
124
|
+
};
|
|
91
125
|
}
|
|
92
126
|
};
|
|
127
|
+
function materializeRelationships(change) {
|
|
128
|
+
switch (change.type) {
|
|
129
|
+
case "add":
|
|
130
|
+
return { type: "add", node: materializeNodeRelationships(change.node) };
|
|
131
|
+
case "remove":
|
|
132
|
+
return { type: "remove", node: materializeNodeRelationships(change.node) };
|
|
133
|
+
case "child":
|
|
134
|
+
return {
|
|
135
|
+
type: "child",
|
|
136
|
+
node: { row: change.node.row },
|
|
137
|
+
child: {
|
|
138
|
+
relationshipName: change.child.relationshipName,
|
|
139
|
+
change: materializeRelationships(change.child.change)
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
case "edit":
|
|
143
|
+
return {
|
|
144
|
+
type: "edit",
|
|
145
|
+
node: { row: change.node.row },
|
|
146
|
+
oldNode: { row: change.oldNode.row }
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function materializeNodeRelationships(node) {
|
|
151
|
+
const relationships = {};
|
|
152
|
+
for (const relationship in node.relationships) {
|
|
153
|
+
const materialized = [];
|
|
154
|
+
for (const n of node.relationships[relationship]()) {
|
|
155
|
+
materialized.push(materializeNodeRelationships(n));
|
|
156
|
+
}
|
|
157
|
+
relationships[relationship] = () => materialized;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
row: node.row,
|
|
161
|
+
relationships
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function isEmptyRoot(entry) {
|
|
165
|
+
const data = entry[""];
|
|
166
|
+
return data === void 0 || Array.isArray(data) && data.length === 0;
|
|
167
|
+
}
|
|
93
168
|
function solidViewFactory(_query, input, format, onDestroy, onTransactionCommit, queryComplete) {
|
|
94
169
|
return new SolidView(
|
|
95
170
|
input,
|
package/out/solid.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../zero-solid/src/create-zero.ts", "../../zero-solid/src/use-query.ts", "../../zero-solid/src/solid-view.ts"],
|
|
4
|
-
"sourcesContent": ["import {batch} from 'solid-js';\nimport type {ZeroAdvancedOptions} from '../../zero/src/advanced.ts';\nimport {Zero, type Schema, type ZeroOptions} from '../../zero/src/zero.ts';\n\nexport function createZero<S extends Schema>(options: ZeroOptions<S>): Zero<S> {\n const opts: ZeroAdvancedOptions<S> = {\n ...options,\n batchViewUpdates: batch,\n };\n return new Zero(opts);\n}\n", "import {createMemo, onCleanup, type Accessor} from 'solid-js';\nimport type {\n AdvancedQuery,\n HumanReadable,\n Query,\n} from '../../zero/src/advanced.ts';\nimport type {Schema} from '../../zero/src/zero.ts';\nimport {solidViewFactory, type QueryResultDetails} from './solid-view.ts';\n\nexport type QueryResult<TReturn> = readonly [\n Accessor<HumanReadable<TReturn>>,\n Accessor<QueryResultDetails>,\n];\n\nexport function useQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(querySignal: () => Query<TSchema, TTable, TReturn>): QueryResult<TReturn> {\n // Wrap in in createMemo to ensure a new view is created if the querySignal changes.\n const view = createMemo(() => {\n const query = querySignal();\n const view = (query as AdvancedQuery<TSchema, TTable, TReturn>).materialize(\n solidViewFactory,\n );\n\n onCleanup(() => {\n view.destroy();\n });\n return view;\n });\n\n return [() => view().data, () => view().resultDetails];\n}\n", "import {\n createStore,\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import {batch} from 'solid-js';\nimport type {ZeroAdvancedOptions} from '../../zero/src/advanced.ts';\nimport {Zero, type Schema, type ZeroOptions} from '../../zero/src/zero.ts';\n\nexport function createZero<S extends Schema>(options: ZeroOptions<S>): Zero<S> {\n const opts: ZeroAdvancedOptions<S> = {\n ...options,\n batchViewUpdates: batch,\n };\n return new Zero(opts);\n}\n", "import {createMemo, onCleanup, type Accessor} from 'solid-js';\nimport type {\n AdvancedQuery,\n HumanReadable,\n Query,\n} from '../../zero/src/advanced.ts';\nimport type {Schema} from '../../zero/src/zero.ts';\nimport {solidViewFactory, type QueryResultDetails} from './solid-view.ts';\n\nexport type QueryResult<TReturn> = readonly [\n Accessor<HumanReadable<TReturn>>,\n Accessor<QueryResultDetails>,\n];\n\nexport function useQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(querySignal: () => Query<TSchema, TTable, TReturn>): QueryResult<TReturn> {\n // Wrap in in createMemo to ensure a new view is created if the querySignal changes.\n const view = createMemo(() => {\n const query = querySignal();\n const view = (query as AdvancedQuery<TSchema, TTable, TReturn>).materialize(\n solidViewFactory,\n );\n\n onCleanup(() => {\n view.destroy();\n });\n return view;\n });\n\n return [() => view().data, () => view().resultDetails];\n}\n", "import {\n createStore,\n produce,\n type SetStoreFunction,\n type Store,\n} from 'solid-js/store';\nimport {\n applyChange,\n type Change,\n type Entry,\n type Format,\n type HumanReadable,\n type Input,\n type Output,\n type Query,\n type ViewFactory,\n} from '../../zero-advanced/src/mod.js';\nimport type {Schema} from '../../zero-schema/src/mod.js';\nimport type {ResultType} from '../../zql/src/query/typed-view.js';\nimport type {Node} from '../../zql/src/ivm/data.ts';\nimport type {ViewChange} from '../../zql/src/ivm/view-apply-change.ts';\nimport type {Stream} from '../../zql/src/ivm/stream.ts';\n\nexport type QueryResultDetails = {\n readonly type: ResultType;\n};\n\ntype State = [Entry, QueryResultDetails];\n\nconst complete = {type: 'complete'} as const;\nconst unknown = {type: 'unknown'} as const;\n\nexport class SolidView<V> implements Output {\n readonly #input: Input;\n readonly #format: Format;\n readonly #onDestroy: () => void;\n\n #state: Store<State>;\n #setState: SetStoreFunction<State>;\n\n // Optimization: if the store is currently empty we build up\n // the view on a plain old JS object stored at #builderRoot, and return\n // that for the new state on transaction commit. This avoids building up\n // large views from scratch via solid produce. The proxy object used by\n // solid produce is slow and in this case we don't care about solid tracking\n // the fine grained changes (everything has changed, it's all new). For a\n // test case with a view with 3000 rows, each row having 2 children, this\n // optimization reduced #applyChanges time from 743ms to 133ms.\n #builderRoot: Entry | undefined;\n #pendingChanges: ViewChange[] = [];\n\n constructor(\n input: Input,\n onTransactionCommit: (cb: () => void) => void,\n format: Format,\n onDestroy: () => void,\n queryComplete: true | Promise<true>,\n ) {\n this.#input = input;\n onTransactionCommit(this.#onTransactionCommit);\n this.#format = format;\n this.#onDestroy = onDestroy;\n input.setOutput(this);\n\n const initialRoot = this.#createEmptyRoot();\n this.#applyChangesToRoot(\n input.fetch({}),\n node => ({type: 'add', node}),\n initialRoot,\n );\n [this.#state, this.#setState] = createStore<State>([\n initialRoot,\n queryComplete === true ? complete : unknown,\n ]);\n if (isEmptyRoot(initialRoot)) {\n this.#builderRoot = this.#createEmptyRoot();\n }\n\n if (queryComplete !== true) {\n void queryComplete.then(() => {\n this.#setState(oldState => [oldState[0], complete]);\n });\n }\n }\n\n get data(): V {\n return this.#state[0][''] as V;\n }\n\n get resultDetails(): QueryResultDetails {\n return this.#state[1];\n }\n\n destroy(): void {\n this.#onDestroy();\n }\n\n #onTransactionCommit = () => {\n const builderRoot = this.#builderRoot;\n if (builderRoot) {\n if (!isEmptyRoot(builderRoot)) {\n this.#setState(oldState => [builderRoot, oldState[1]]);\n this.#builderRoot = undefined;\n }\n } else {\n try {\n this.#applyChanges(this.#pendingChanges, c => c);\n } finally {\n this.#pendingChanges = [];\n }\n }\n };\n\n push(change: Change): void {\n // Delay updating the solid store state until the transaction commit\n // (because each update of the solid store is quite expensive). If\n // this.#builderRoot is defined apply the changes to it (we are building\n // from an empty root), otherwise queue the changes to be applied\n // using produce at the end of the transaction but read the relationships\n // now as they are only valid to read when the push is received.\n if (this.#builderRoot) {\n this.#applyChangeToRoot(change, this.#builderRoot);\n } else {\n this.#pendingChanges.push(materializeRelationships(change));\n }\n }\n\n #applyChanges<T>(changes: Iterable<T>, mapper: (v: T) => ViewChange): void {\n this.#setState(\n produce((draftState: State) => {\n this.#applyChangesToRoot<T>(changes, mapper, draftState[0]);\n if (isEmptyRoot(draftState[0])) {\n this.#builderRoot = this.#createEmptyRoot();\n }\n }),\n );\n }\n\n #applyChangesToRoot<T>(\n changes: Iterable<T>,\n mapper: (v: T) => ViewChange,\n root: Entry,\n ) {\n for (const change of changes) {\n this.#applyChangeToRoot(mapper(change), root);\n }\n }\n\n #applyChangeToRoot(change: ViewChange, root: Entry) {\n applyChange(root, change, this.#input.getSchema(), '', this.#format);\n }\n\n #createEmptyRoot(): Entry {\n return {\n '': this.#format.singular ? undefined : [],\n };\n }\n}\n\nfunction materializeRelationships(change: Change): ViewChange {\n switch (change.type) {\n case 'add':\n return {type: 'add', node: materializeNodeRelationships(change.node)};\n case 'remove':\n return {type: 'remove', node: materializeNodeRelationships(change.node)};\n case 'child':\n return {\n type: 'child',\n node: {row: change.node.row},\n child: {\n relationshipName: change.child.relationshipName,\n change: materializeRelationships(change.child.change),\n },\n };\n case 'edit':\n return {\n type: 'edit',\n node: {row: change.node.row},\n oldNode: {row: change.oldNode.row},\n };\n }\n}\n\nfunction materializeNodeRelationships(node: Node): Node {\n const relationships: Record<string, () => Stream<Node>> = {};\n for (const relationship in node.relationships) {\n const materialized: Node[] = [];\n for (const n of node.relationships[relationship]()) {\n materialized.push(materializeNodeRelationships(n));\n }\n relationships[relationship] = () => materialized;\n }\n return {\n row: node.row,\n relationships,\n };\n}\n\nfunction isEmptyRoot(entry: Entry) {\n const data = entry[''];\n return data === undefined || (Array.isArray(data) && data.length === 0);\n}\n\nexport function solidViewFactory<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n _query: Query<TSchema, TTable, TReturn>,\n input: Input,\n format: Format,\n onDestroy: () => void,\n onTransactionCommit: (cb: () => void) => void,\n queryComplete: true | Promise<true>,\n) {\n return new SolidView<HumanReadable<TReturn>>(\n input,\n onTransactionCommit,\n format,\n onDestroy,\n queryComplete,\n );\n}\n\nsolidViewFactory satisfies ViewFactory<Schema, string, unknown, unknown>;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAAA,SAAQ,aAAY;AAIb,SAAS,WAA6B,SAAkC;AAC7E,QAAM,OAA+B;AAAA,IACnC,GAAG;AAAA,IACH,kBAAkB;AAAA,EACpB;AACA,SAAO,IAAI,KAAK,IAAI;AACtB;;;ACVA,SAAQ,YAAY,iBAA+B;;;ACAnD;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAwBP,IAAM,WAAW,EAAC,MAAM,WAAU;AAClC,IAAM,UAAU,EAAC,MAAM,UAAS;AAEzB,IAAM,YAAN,MAAqC;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EAET;AAAA,EACA;AAAA;AAA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,MACF;AAAA,IACF,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA,QACN,MAAM,EAAC,KAAK,OAAO,KAAK,IAAG;AAAA,QAC3B,SAAS,EAAC,KAAK,OAAO,QAAQ,IAAG;AAAA,MACnC;AAAA,EACJ;AACF;AAEA,SAAS,6BAA6B,MAAkB;AACtD,QAAM,gBAAoD,CAAC;AAC3D,aAAW,gBAAgB,KAAK,eAAe;AAC7C,UAAM,eAAuB,CAAC;AAC9B,eAAW,KAAK,KAAK,cAAc,YAAY,EAAE,GAAG;AAClD,mBAAa,KAAK,6BAA6B,CAAC,CAAC;AAAA,IACnD;AACA,kBAAc,YAAY,IAAI,MAAM;AAAA,EACtC;AACA,SAAO;AAAA,IACL,KAAK,KAAK;AAAA,IACV;AAAA,EACF;AACF;AAEA,SAAS,YAAY,OAAc;AACjC,QAAM,OAAO,MAAM,EAAE;AACrB,SAAO,SAAS,UAAc,MAAM,QAAQ,IAAI,KAAK,KAAK,WAAW;AACvE;AAEO,SAAS,iBAKd,QACA,OACA,QACA,WACA,qBACA,eACA;AACA,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;ADhNO,SAAS,SAId,aAA0E;AAE1E,QAAM,OAAO,WAAW,MAAM;AAC5B,UAAM,QAAQ,YAAY;AAC1B,UAAMA,QAAQ,MAAkD;AAAA,MAC9D;AAAA,IACF;AAEA,cAAU,MAAM;AACd,MAAAA,MAAK,QAAQ;AAAA,IACf,CAAC;AACD,WAAOA;AAAA,EACT,CAAC;AAED,SAAO,CAAC,MAAM,KAAK,EAAE,MAAM,MAAM,KAAK,EAAE,aAAa;AACvD;",
|
|
6
6
|
"names": ["view"]
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@ export type { ZeroAdvancedOptions } from '../../zero-client/src/client/options.t
|
|
|
2
2
|
export type { TableSchema } from '../../zero-schema/src/table-schema.ts';
|
|
3
3
|
export type { Change } from '../../zql/src/ivm/change.ts';
|
|
4
4
|
export type { Input, Output } from '../../zql/src/ivm/operator.ts';
|
|
5
|
-
export { applyChange } from '../../zql/src/ivm/view-apply-change.ts';
|
|
5
|
+
export { applyChange, type ViewChange, } from '../../zql/src/ivm/view-apply-change.ts';
|
|
6
6
|
export type { Entry, Format, View, ViewFactory } from '../../zql/src/ivm/view.ts';
|
|
7
7
|
export type { AdvancedQuery } from '../../zql/src/query/query-internal.ts';
|
|
8
8
|
export type { HumanReadable, Query } from '../../zql/src/query/query.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../zero-advanced/src/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,mBAAmB,EAAC,MAAM,yCAAyC,CAAC;AACjF,YAAY,EAAC,WAAW,EAAC,MAAM,uCAAuC,CAAC;AACvE,YAAY,EAAC,MAAM,EAAC,MAAM,6BAA6B,CAAC;AACxD,YAAY,EAAC,KAAK,EAAE,MAAM,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../zero-advanced/src/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,mBAAmB,EAAC,MAAM,yCAAyC,CAAC;AACjF,YAAY,EAAC,WAAW,EAAC,MAAM,uCAAuC,CAAC;AACvE,YAAY,EAAC,MAAM,EAAC,MAAM,6BAA6B,CAAC;AACxD,YAAY,EAAC,KAAK,EAAE,MAAM,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,EACL,WAAW,EACX,KAAK,UAAU,GAChB,MAAM,wCAAwC,CAAC;AAChD,YAAY,EAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAChF,YAAY,EAAC,aAAa,EAAC,MAAM,uCAAuC,CAAC;AACzE,YAAY,EAAC,aAAa,EAAE,KAAK,EAAC,MAAM,8BAA8B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Schema } from '../../../zero-schema/src/builder/schema-builder.ts';
|
|
2
2
|
import { type PermissionsConfig } from '../../../zero-schema/src/compiled-permissions.ts';
|
|
3
3
|
import type { ZeroConfig } from '../config/zero-config.ts';
|
|
4
4
|
export declare function getSchema(config: ZeroConfig): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-schema.d.ts","sourceRoot":"","sources":["../../../../../zero-cache/src/auth/load-schema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"load-schema.d.ts","sourceRoot":"","sources":["../../../../../zero-cache/src/auth/load-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,MAAM,EACZ,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAC,KAAK,iBAAiB,EAAC,MAAM,kDAAkD,CAAC;AAExF,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AASzD,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC,CAuBD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { mapSchemaToServer, } from "../../../zero-schema/src/builder/schema-builder.js";
|
|
3
4
|
import {} from "../../../zero-schema/src/compiled-permissions.js";
|
|
4
5
|
import { parseSchema } from "../../../zero-schema/src/schema-config.js";
|
|
5
6
|
let loadedSchema;
|
|
@@ -13,7 +14,13 @@ export function getSchema(config) {
|
|
|
13
14
|
}
|
|
14
15
|
const fileContent = await readFile(path.resolve(config.schema.file), 'utf-8');
|
|
15
16
|
return parseSchema(fileContent, config.schema.file);
|
|
16
|
-
})()
|
|
17
|
+
})().then(({ schema, permissions }) => ({
|
|
18
|
+
// The schema includes serverName fields but is structured with client
|
|
19
|
+
// names. Remap it into the server namespace.
|
|
20
|
+
schema: mapSchemaToServer(schema),
|
|
21
|
+
// Permissions are already compiled with server names
|
|
22
|
+
permissions,
|
|
23
|
+
}));
|
|
17
24
|
return loadedSchema;
|
|
18
25
|
}
|
|
19
26
|
//# sourceMappingURL=load-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-schema.js","sourceRoot":"","sources":["../../../../../zero-cache/src/auth/load-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"load-schema.js","sourceRoot":"","sources":["../../../../../zero-cache/src/auth/load-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,iBAAiB,GAElB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAwB,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAC,WAAW,EAAC,MAAM,2CAA2C,CAAC;AAGtE,IAAI,YAKS,CAAC;AAEd,MAAM,UAAU,SAAS,CAAC,MAAkB;IAI1C,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,YAAY,GAAG,CAAC,KAAK,IAAI,EAAE;QACzB,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACvB,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,QAAQ,CAChC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAChC,OAAO,CACR,CAAC;QACF,OAAO,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAC,MAAM,EAAE,WAAW,EAAC,EAAE,EAAE,CAAC,CAAC;QACpC,sEAAsE;QACtE,6CAA6C;QAC7C,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC;QACjC,qDAAqD;QACrD,WAAW;KACZ,CAAC,CAAC,CAAC;IAEJ,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { NoIndexDiff } from '../../../replicache/src/btree/node.ts';
|
|
2
2
|
import type { AST } from '../../../zero-protocol/src/ast.ts';
|
|
3
|
-
import type { TableSchema } from '../../../zero-schema/src/table-schema.ts';
|
|
4
3
|
import type { Storage } from '../../../zql/src/ivm/operator.ts';
|
|
5
4
|
import type { Source } from '../../../zql/src/ivm/source.ts';
|
|
6
5
|
import type { CommitListener, GotCallback, QueryDelegate } from '../../../zql/src/query/query-impl.ts';
|
|
6
|
+
import type { IVMSourceBranch } from './ivm-source-repo.ts';
|
|
7
7
|
export type AddQuery = (ast: AST, gotCallback?: GotCallback | undefined) => () => void;
|
|
8
8
|
/**
|
|
9
9
|
* ZeroContext glues together zql and Replicache. It listens to changes in
|
|
@@ -13,7 +13,7 @@ export type AddQuery = (ast: AST, gotCallback?: GotCallback | undefined) => () =
|
|
|
13
13
|
export declare class ZeroContext implements QueryDelegate {
|
|
14
14
|
#private;
|
|
15
15
|
readonly staticQueryParameters: undefined;
|
|
16
|
-
constructor(
|
|
16
|
+
constructor(mainSources: IVMSourceBranch, addQuery: AddQuery, batchViewUpdates: (applyViewUpdates: () => void) => void);
|
|
17
17
|
getSource(name: string): Source | undefined;
|
|
18
18
|
addServerQuery(ast: AST, gotCallback?: GotCallback | undefined): () => void;
|
|
19
19
|
createStorage(): Storage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uCAAuC,CAAC;AAEvE,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uCAAuC,CAAC;AAEvE,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,mCAAmC,CAAC;AAG3D,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,kCAAkC,CAAC;AAC9D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,gCAAgC,CAAC;AAC3D,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACd,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AAG1D,MAAM,MAAM,QAAQ,GAAG,CACrB,GAAG,EAAE,GAAG,EACR,WAAW,CAAC,EAAE,WAAW,GAAG,SAAS,KAClC,MAAM,IAAI,CAAC;AAEhB;;;;GAIG;AACH,qBAAa,WAAY,YAAW,aAAa;;IAU/C,QAAQ,CAAC,qBAAqB,YAAa;gBAGzC,WAAW,EAAE,eAAe,EAC5B,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,MAAM,IAAI,KAAK,IAAI;IAO1D,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI3C,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,SAAS,SAjCrD,IAAI;IAqCb,aAAa,IAAI,OAAO;IAIxB,mBAAmB,CAAC,EAAE,EAAE,cAAc,GAAG,MAAM,IAAI;IAOnD,gBAAgB,CAAC,CAAC,EAAE,gBAAgB,EAAE,MAAM,CAA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