@tanstack/db-sqlite-persistence-core 0.4.4 → 0.4.5
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/README.md +14 -6
- package/dist/cjs/index.cjs +5 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/persisted.cjs +12 -10
- package/dist/cjs/persisted.cjs.map +1 -1
- package/dist/cjs/persisted.d.cts +7 -1
- package/dist/cjs/remote-subset-wire.cjs +100 -73
- package/dist/cjs/remote-subset-wire.cjs.map +1 -1
- package/dist/cjs/remote-subset-wire.d.cts +2 -0
- package/dist/cjs/sqlite-core-adapter.cjs +136 -28
- package/dist/cjs/sqlite-core-adapter.cjs.map +1 -1
- package/dist/cjs/sqlite-value.cjs +51 -0
- package/dist/cjs/sqlite-value.cjs.map +1 -1
- package/dist/cjs/sqlite-value.d.cts +12 -0
- package/dist/esm/index.js +8 -3
- package/dist/esm/persisted.d.ts +7 -1
- package/dist/esm/persisted.js +14 -12
- package/dist/esm/persisted.js.map +1 -1
- package/dist/esm/remote-subset-wire.d.ts +2 -0
- package/dist/esm/remote-subset-wire.js +101 -74
- package/dist/esm/remote-subset-wire.js.map +1 -1
- package/dist/esm/sqlite-core-adapter.js +138 -30
- package/dist/esm/sqlite-core-adapter.js.map +1 -1
- package/dist/esm/sqlite-value.d.ts +12 -0
- package/dist/esm/sqlite-value.js +53 -2
- package/dist/esm/sqlite-value.js.map +1 -1
- package/package.json +4 -3
- package/src/persisted.ts +31 -16
- package/src/remote-subset-wire.ts +149 -79
- package/src/sqlite-core-adapter.ts +221 -34
- package/src/sqlite-value.ts +98 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-subset-wire.js","sources":["../../src/remote-subset-wire.ts"],"sourcesContent":["import { IR } from '@tanstack/db'\nimport type { LoadSubsetOptions } from '@tanstack/db'\n\nexport type RemoteSubsetWirePrimitive =\n undefined | null | boolean | string | number | bigint\n\nexport type RemoteSubsetWireTypedArray =\n | Int8Array\n | Uint8Array\n | Uint8ClampedArray\n | Int16Array\n | Uint16Array\n | Int32Array\n | Uint32Array\n | Float32Array\n | Float64Array\n | BigInt64Array\n | BigUint64Array\n\nexport type RemoteSubsetWireRecord = {\n [key: string]: RemoteSubsetWireValue\n}\n\n/** Values whose complete semantics survive a coordinator transport boundary. */\nexport type RemoteSubsetWireValue =\n | RemoteSubsetWirePrimitive\n | Date\n | RegExp\n | ArrayBuffer\n | DataView\n | RemoteSubsetWireTypedArray\n | Array<RemoteSubsetWireValue>\n | Map<RemoteSubsetWireValue, RemoteSubsetWireValue>\n | Set<RemoteSubsetWireValue>\n | RemoteSubsetWireRecord\n\nexport type RemoteSubsetWireExpression =\n | { type: `ref`; path: Array<string>; sourceAlias?: string }\n | { type: `val`; value: RemoteSubsetWireValue }\n | {\n type: `func`\n name: string\n args: Array<RemoteSubsetWireExpression>\n }\n\nexport type RemoteSubsetWireCompareOptions = {\n direction: `asc` | `desc`\n nulls: `first` | `last`\n} & (\n | { stringSort?: `lexical` }\n | {\n stringSort?: `locale`\n locale?: string\n localeOptions?: RemoteSubsetWireRecord\n }\n)\n\nexport type RemoteSubsetWireOrderByClause = {\n expression: RemoteSubsetWireExpression\n compareOptions: RemoteSubsetWireCompareOptions\n}\n\nexport type RemoteSubsetWireCursor = {\n whereFrom: RemoteSubsetWireExpression\n whereCurrent: RemoteSubsetWireExpression\n lastKey?: string | number\n}\n\n/** The complete data portion transported by a remote-subset request. */\nexport type TransportedLoadSubsetOptions = {\n where?: RemoteSubsetWireExpression\n orderBy?: Array<RemoteSubsetWireOrderByClause>\n limit?: number\n cursor?: RemoteSubsetWireCursor\n offset?: number\n}\n\nexport class RemoteSubsetWireValueError extends TypeError {\n override readonly name = `RemoteSubsetWireValueError`\n\n constructor(\n readonly path: string,\n reason: string,\n ) {\n super(`Unsupported remote subset wire value at ${path}: ${reason}`)\n }\n}\n\ntype ProjectionState = {\n expressions: WeakMap<object, RemoteSubsetWireExpression>\n expressionArrays: WeakMap<object, Array<RemoteSubsetWireExpression>>\n stringArrays: WeakMap<object, Array<string>>\n orderByArrays: WeakMap<object, Array<RemoteSubsetWireOrderByClause>>\n orderByClauses: WeakMap<object, RemoteSubsetWireOrderByClause>\n compareOptions: WeakMap<object, RemoteSubsetWireCompareOptions>\n cursors: WeakMap<object, RemoteSubsetWireCursor>\n wireValues: WeakMap<object, RemoteSubsetWireValue>\n}\n\ntype DataProperty = {\n present: boolean\n value?: unknown\n}\n\ntype TypedArrayConstructor = {\n readonly prototype: RemoteSubsetWireTypedArray\n new (\n buffer: ArrayBuffer,\n byteOffset?: number,\n length?: number,\n ): RemoteSubsetWireTypedArray\n}\n\nconst typedArrayConstructors: ReadonlyArray<TypedArrayConstructor> = [\n Int8Array,\n Uint8Array,\n Uint8ClampedArray,\n Int16Array,\n Uint16Array,\n Int32Array,\n Uint32Array,\n Float32Array,\n Float64Array,\n BigInt64Array,\n BigUint64Array,\n]\n\nconst NativeDate = Date\nconst identifierPattern = /^[A-Za-z_$][A-Za-z0-9_$]*$/\n\n/**\n * Projects one live subset request into the exact coordinator wire domain.\n * Validation happens before callers choose a local-leader or transported path.\n */\nexport function toTransportedLoadSubsetOptions(\n options: LoadSubsetOptions,\n): TransportedLoadSubsetOptions {\n assertPlainContainer(options, `options`)\n assertAllowedProperties(options, `options`, [\n `where`,\n `orderBy`,\n `limit`,\n `cursor`,\n `offset`,\n `signal`,\n `subscription`,\n ])\n\n const state: ProjectionState = {\n expressions: new WeakMap(),\n expressionArrays: new WeakMap(),\n stringArrays: new WeakMap(),\n orderByArrays: new WeakMap(),\n orderByClauses: new WeakMap(),\n compareOptions: new WeakMap(),\n cursors: new WeakMap(),\n wireValues: new WeakMap(),\n }\n const projected: TransportedLoadSubsetOptions = {}\n const where = readDataProperty(options, `where`, `options.where`)\n const orderBy = readDataProperty(options, `orderBy`, `options.orderBy`)\n const limit = readDataProperty(options, `limit`, `options.limit`)\n const cursor = readDataProperty(options, `cursor`, `options.cursor`)\n const offset = readDataProperty(options, `offset`, `options.offset`)\n\n if (where.present && where.value !== undefined) {\n projected.where = projectExpression(where.value, `options.where`, state)\n }\n if (orderBy.present && orderBy.value !== undefined) {\n projected.orderBy = projectOrderBy(orderBy.value, `options.orderBy`, state)\n }\n if (limit.present && limit.value !== undefined) {\n projected.limit = projectNumber(limit.value, `options.limit`)\n }\n if (cursor.present && cursor.value !== undefined) {\n projected.cursor = projectCursor(cursor.value, `options.cursor`, state)\n }\n if (offset.present && offset.value !== undefined) {\n projected.offset = projectNumber(offset.value, `options.offset`)\n }\n\n return projected\n}\n\n/** Adds live lifecycle references only to an already validated local request. */\nexport function toProcessLocalLoadSubsetOptions(\n options: LoadSubsetOptions,\n transported = toTransportedLoadSubsetOptions(options),\n): TransportedLoadSubsetOptions &\n Pick<LoadSubsetOptions, `signal` | `subscription`> {\n const projected = {\n ...transported,\n } as TransportedLoadSubsetOptions &\n Pick<LoadSubsetOptions, `signal` | `subscription`>\n const signal = readDataProperty(options, `signal`, `options.signal`)\n const subscription = readDataProperty(\n options,\n `subscription`,\n `options.subscription`,\n )\n\n if (signal.present) {\n projected.signal = signal.value as LoadSubsetOptions[`signal`]\n }\n if (subscription.present) {\n projected.subscription =\n subscription.value as LoadSubsetOptions[`subscription`]\n }\n\n return projected\n}\n\nfunction projectExpression(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireExpression {\n const object = requireObject(value, path)\n const existing = state.expressions.get(object)\n if (existing) return existing\n\n const type = readDataProperty(object, `type`, `${path}.type`)\n if (!type.present || typeof type.value !== `string`) {\n throw new RemoteSubsetWireValueError(`${path}.type`, describe(type.value))\n }\n\n switch (type.value) {\n case `ref`: {\n assertExpressionPrototype(object, path, IR.PropRef.prototype)\n assertAllowedProperties(object, path, [`type`, `path`, `sourceAlias`])\n const projected: Extract<RemoteSubsetWireExpression, { type: `ref` }> = {\n type: `ref`,\n path: [],\n }\n state.expressions.set(object, projected)\n const sourcePath = readRequiredDataProperty(\n object,\n `path`,\n `${path}.path`,\n )\n projected.path = projectStringArray(sourcePath, `${path}.path`, state)\n const sourceAlias = readDataProperty(\n object,\n `sourceAlias`,\n `${path}.sourceAlias`,\n )\n if (sourceAlias.present) {\n if (\n typeof sourceAlias.value !== `string` ||\n projected.path[0] !== sourceAlias.value\n ) {\n throw new RemoteSubsetWireValueError(\n `${path}.sourceAlias`,\n `source alias must match the first path segment`,\n )\n }\n projected.sourceAlias = sourceAlias.value\n }\n return projected\n }\n case `val`: {\n assertExpressionPrototype(object, path, IR.Value.prototype)\n assertAllowedProperties(object, path, [`type`, `value`])\n const projected: Extract<RemoteSubsetWireExpression, { type: `val` }> = {\n type: `val`,\n value: undefined,\n }\n state.expressions.set(object, projected)\n const sourceValue = readRequiredDataProperty(\n object,\n `value`,\n `${path}.value`,\n )\n projected.value = projectWireValue(sourceValue, `${path}.value`, state)\n return projected\n }\n case `func`: {\n assertExpressionPrototype(object, path, IR.Func.prototype)\n assertAllowedProperties(object, path, [`type`, `name`, `args`])\n const projected = {\n type: `func`,\n name: ``,\n args: [] as Array<RemoteSubsetWireExpression>,\n } satisfies RemoteSubsetWireExpression\n state.expressions.set(object, projected)\n const name = readRequiredDataProperty(object, `name`, `${path}.name`)\n if (typeof name !== `string`) {\n throw new RemoteSubsetWireValueError(`${path}.name`, describe(name))\n }\n projected.name = name\n const args = readRequiredDataProperty(object, `args`, `${path}.args`)\n projected.args = projectExpressionArray(args, `${path}.args`, state)\n return projected\n }\n default:\n throw new RemoteSubsetWireValueError(`${path}.type`, String(type.value))\n }\n}\n\nfunction projectExpressionArray(\n value: unknown,\n path: string,\n state: ProjectionState,\n): Array<RemoteSubsetWireExpression> {\n const array = requireArray(value, path)\n const existing = state.expressionArrays.get(array)\n if (existing) return existing\n assertArrayShape(array, path)\n const projected = new Array<RemoteSubsetWireExpression>(array.length)\n state.expressionArrays.set(array, projected)\n for (let index = 0; index < array.length; index++) {\n if (!(index in array)) {\n throw new RemoteSubsetWireValueError(\n `${path}[${index}]`,\n `missing expression`,\n )\n }\n projected[index] = projectExpression(\n array[index],\n `${path}[${index}]`,\n state,\n )\n }\n return projected\n}\n\nfunction projectStringArray(\n value: unknown,\n path: string,\n state: ProjectionState,\n): Array<string> {\n const array = requireArray(value, path)\n const existing = state.stringArrays.get(array)\n if (existing) return existing\n assertArrayShape(array, path)\n const projected = new Array<string>(array.length)\n state.stringArrays.set(array, projected)\n for (let index = 0; index < array.length; index++) {\n const entry = array[index]\n if (!(index in array) || typeof entry !== `string`) {\n throw new RemoteSubsetWireValueError(`${path}[${index}]`, describe(entry))\n }\n projected[index] = entry\n }\n return projected\n}\n\nfunction projectOrderBy(\n value: unknown,\n path: string,\n state: ProjectionState,\n): Array<RemoteSubsetWireOrderByClause> {\n const array = requireArray(value, path)\n const existing = state.orderByArrays.get(array)\n if (existing) return existing\n assertArrayShape(array, path)\n const projected = new Array<RemoteSubsetWireOrderByClause>(array.length)\n state.orderByArrays.set(array, projected)\n\n for (let index = 0; index < array.length; index++) {\n const clausePath = `${path}[${index}]`\n const clause = requirePlainRecord(array[index], clausePath)\n const existingClause = state.orderByClauses.get(clause)\n if (existingClause) {\n projected[index] = existingClause\n continue\n }\n assertAllowedProperties(clause, clausePath, [\n `expression`,\n `compareOptions`,\n ])\n const projectedClause = {\n expression: undefined as unknown as RemoteSubsetWireExpression,\n compareOptions: undefined as unknown as RemoteSubsetWireCompareOptions,\n }\n projected[index] = projectedClause\n state.orderByClauses.set(clause, projectedClause)\n projectedClause.expression = projectExpression(\n readRequiredDataProperty(\n clause,\n `expression`,\n `${clausePath}.expression`,\n ),\n `${clausePath}.expression`,\n state,\n )\n projectedClause.compareOptions = projectCompareOptions(\n readRequiredDataProperty(\n clause,\n `compareOptions`,\n `${clausePath}.compareOptions`,\n ),\n `${clausePath}.compareOptions`,\n state,\n )\n }\n return projected\n}\n\nfunction projectCompareOptions(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireCompareOptions {\n const source = requirePlainRecord(value, path)\n const existing = state.compareOptions.get(source)\n if (existing) return existing\n assertAllowedProperties(source, path, [\n `direction`,\n `nulls`,\n `stringSort`,\n `locale`,\n `localeOptions`,\n ])\n const projected: {\n direction?: `asc` | `desc`\n nulls?: `first` | `last`\n stringSort?: `lexical` | `locale`\n locale?: string\n localeOptions?: RemoteSubsetWireRecord\n } = {}\n\n const direction = readRequiredDataProperty(\n source,\n `direction`,\n `${path}.direction`,\n )\n if (direction !== `asc` && direction !== `desc`) {\n throw new RemoteSubsetWireValueError(\n `${path}.direction`,\n describe(direction),\n )\n }\n projected.direction = direction\n\n const nulls = readRequiredDataProperty(source, `nulls`, `${path}.nulls`)\n if (nulls !== `first` && nulls !== `last`) {\n throw new RemoteSubsetWireValueError(`${path}.nulls`, describe(nulls))\n }\n projected.nulls = nulls\n\n const stringSort = readDataProperty(\n source,\n `stringSort`,\n `${path}.stringSort`,\n )\n if (stringSort.present && stringSort.value !== undefined) {\n if (stringSort.value !== `lexical` && stringSort.value !== `locale`) {\n throw new RemoteSubsetWireValueError(\n `${path}.stringSort`,\n describe(stringSort.value),\n )\n }\n projected.stringSort = stringSort.value\n }\n if (projected.stringSort !== `lexical`) {\n const locale = readDataProperty(source, `locale`, `${path}.locale`)\n if (locale.present && locale.value !== undefined) {\n if (typeof locale.value !== `string`) {\n throw new RemoteSubsetWireValueError(\n `${path}.locale`,\n describe(locale.value),\n )\n }\n projected.locale = locale.value\n }\n const localeOptions = readDataProperty(\n source,\n `localeOptions`,\n `${path}.localeOptions`,\n )\n if (localeOptions.present && localeOptions.value !== undefined) {\n projected.localeOptions = projectWireRecord(\n localeOptions.value,\n `${path}.localeOptions`,\n state,\n )\n }\n }\n const result = projected as RemoteSubsetWireCompareOptions\n state.compareOptions.set(source, result)\n return result\n}\n\nfunction projectCursor(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireCursor {\n const source = requirePlainRecord(value, path)\n const existing = state.cursors.get(source)\n if (existing) return existing\n assertAllowedProperties(source, path, [\n `whereFrom`,\n `whereCurrent`,\n `lastKey`,\n ])\n const projected: RemoteSubsetWireCursor = {\n whereFrom: undefined as unknown as RemoteSubsetWireExpression,\n whereCurrent: undefined as unknown as RemoteSubsetWireExpression,\n }\n state.cursors.set(source, projected)\n projected.whereFrom = projectExpression(\n readRequiredDataProperty(source, `whereFrom`, `${path}.whereFrom`),\n `${path}.whereFrom`,\n state,\n )\n projected.whereCurrent = projectExpression(\n readRequiredDataProperty(source, `whereCurrent`, `${path}.whereCurrent`),\n `${path}.whereCurrent`,\n state,\n )\n const lastKey = readDataProperty(source, `lastKey`, `${path}.lastKey`)\n if (lastKey.present && lastKey.value !== undefined) {\n if (\n typeof lastKey.value !== `string` &&\n typeof lastKey.value !== `number`\n ) {\n throw new RemoteSubsetWireValueError(\n `${path}.lastKey`,\n describe(lastKey.value),\n )\n }\n projected.lastKey = lastKey.value\n }\n return projected\n}\n\nfunction projectWireValue(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireValue {\n if (\n value === undefined ||\n value === null ||\n typeof value === `boolean` ||\n typeof value === `string` ||\n typeof value === `number` ||\n typeof value === `bigint`\n ) {\n return value\n }\n if (typeof value !== `object`) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n\n const existing = state.wireValues.get(value)\n if (existing) return existing\n\n if (\n typeof SharedArrayBuffer !== `undefined` &&\n value instanceof SharedArrayBuffer\n ) {\n throw new RemoteSubsetWireValueError(path, `SharedArrayBuffer`)\n }\n if (value instanceof NativeDate) {\n assertExactPrototype(value, NativeDate.prototype, path)\n assertNoOwnProperties(value, path)\n const projected = new NativeDate(value.getTime())\n state.wireValues.set(value, projected)\n return projected\n }\n if (value instanceof RegExp) {\n assertExactPrototype(value, RegExp.prototype, path)\n assertRegExpShape(value, path)\n const projected = new RegExp(value.source, value.flags)\n state.wireValues.set(value, projected)\n return projected\n }\n if (value instanceof ArrayBuffer) {\n assertExactPrototype(value, ArrayBuffer.prototype, path)\n assertNoOwnProperties(value, path)\n assertFixedArrayBuffer(value, path)\n let projected: ArrayBuffer\n try {\n projected = value.slice(0)\n } catch {\n throw new RemoteSubsetWireValueError(path, `detached ArrayBuffer`)\n }\n state.wireValues.set(value, projected)\n return projected\n }\n if (value instanceof DataView) {\n assertExactPrototype(value, DataView.prototype, path)\n assertNoOwnProperties(value, path)\n let byteOffset: number\n let byteLength: number\n let buffer: ArrayBufferLike\n try {\n byteOffset = value.byteOffset\n byteLength = value.byteLength\n buffer = value.buffer\n } catch {\n throw new RemoteSubsetWireValueError(path, `detached DataView`)\n }\n const projectedBuffer = projectWireValue(buffer, path, state)\n if (!(projectedBuffer instanceof ArrayBuffer)) {\n throw new RemoteSubsetWireValueError(path, `shared DataView buffer`)\n }\n const projected = new DataView(projectedBuffer, byteOffset, byteLength)\n state.wireValues.set(value, projected)\n return projected\n }\n\n const typedArrayConstructor = getTypedArrayConstructor(value)\n if (typedArrayConstructor) {\n const typedArray = value as RemoteSubsetWireTypedArray\n assertTypedArrayShape(typedArray, path)\n let byteOffset: number\n let length: number\n let buffer: ArrayBufferLike\n try {\n byteOffset = typedArray.byteOffset\n length = typedArray.length\n buffer = typedArray.buffer\n } catch {\n throw new RemoteSubsetWireValueError(path, `detached typed array`)\n }\n if (!(buffer instanceof ArrayBuffer)) {\n throw new RemoteSubsetWireValueError(path, `shared typed-array buffer`)\n }\n const projectedBuffer = projectWireValue(buffer, path, state)\n if (!(projectedBuffer instanceof ArrayBuffer)) {\n throw new RemoteSubsetWireValueError(path, `shared typed-array buffer`)\n }\n let projected: RemoteSubsetWireTypedArray\n try {\n projected = new typedArrayConstructor(projectedBuffer, byteOffset, length)\n } catch {\n throw new RemoteSubsetWireValueError(path, `detached typed array`)\n }\n state.wireValues.set(value, projected)\n return projected\n }\n if (ArrayBuffer.isView(value)) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n if (Array.isArray(value)) return projectWireArray(value, path, state)\n if (value instanceof Map) return projectWireMap(value, path, state)\n if (value instanceof Set) return projectWireSet(value, path, state)\n return projectWireRecord(value, path, state)\n}\n\nfunction projectWireArray(\n value: Array<unknown>,\n path: string,\n state: ProjectionState,\n): Array<RemoteSubsetWireValue> {\n assertArrayShape(value, path)\n const projected = new Array<RemoteSubsetWireValue>(value.length)\n state.wireValues.set(value, projected)\n for (let index = 0; index < value.length; index++) {\n if (index in value) {\n projected[index] = projectWireValue(\n value[index],\n `${path}[${index}]`,\n state,\n )\n }\n }\n return projected\n}\n\nfunction projectWireMap(\n value: Map<unknown, unknown>,\n path: string,\n state: ProjectionState,\n): Map<RemoteSubsetWireValue, RemoteSubsetWireValue> {\n assertExactPrototype(value, Map.prototype, path)\n assertNoOwnProperties(value, path)\n const projected = new Map<RemoteSubsetWireValue, RemoteSubsetWireValue>()\n state.wireValues.set(value, projected)\n let index = 0\n for (const [key, entry] of value) {\n projected.set(\n projectWireValue(key, `${path}.entries[${index}].key`, state),\n projectWireValue(entry, `${path}.entries[${index}].value`, state),\n )\n index++\n }\n return projected\n}\n\nfunction projectWireSet(\n value: Set<unknown>,\n path: string,\n state: ProjectionState,\n): Set<RemoteSubsetWireValue> {\n assertExactPrototype(value, Set.prototype, path)\n assertNoOwnProperties(value, path)\n const projected = new Set<RemoteSubsetWireValue>()\n state.wireValues.set(value, projected)\n let index = 0\n for (const entry of value) {\n projected.add(projectWireValue(entry, `${path}.values[${index}]`, state))\n index++\n }\n return projected\n}\n\nfunction projectWireRecord(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireRecord {\n const source = requirePlainRecord(value, path)\n const existing = state.wireValues.get(source)\n if (existing) return existing as RemoteSubsetWireRecord\n const projected: RemoteSubsetWireRecord = {}\n state.wireValues.set(source, projected)\n\n for (const key of ownKeys(source, path)) {\n const childPath = propertyPath(path, key)\n if (typeof key === `symbol`) {\n throw new RemoteSubsetWireValueError(childPath, `symbol property key`)\n }\n const descriptor = Object.getOwnPropertyDescriptor(source, key)\n if (!descriptor || !descriptor.enumerable || !(`value` in descriptor)) {\n throw new RemoteSubsetWireValueError(childPath, `non-data property`)\n }\n Object.defineProperty(projected, key, {\n value: projectWireValue(descriptor.value, childPath, state),\n enumerable: true,\n writable: true,\n configurable: true,\n })\n }\n return projected\n}\n\nfunction projectNumber(value: unknown, path: string): number {\n if (typeof value !== `number` || !Number.isSafeInteger(value) || value < 0) {\n throw new RemoteSubsetWireValueError(path, `non-negative safe integer`)\n }\n return value\n}\n\nfunction readRequiredDataProperty(\n value: object,\n key: string,\n path: string,\n): unknown {\n const property = readDataProperty(value, key, path)\n if (!property.present) {\n throw new RemoteSubsetWireValueError(path, `missing property`)\n }\n return property.value\n}\n\nfunction readDataProperty(\n value: object,\n key: string,\n path: string,\n): DataProperty {\n let descriptor: PropertyDescriptor | undefined\n try {\n descriptor = Object.getOwnPropertyDescriptor(value, key)\n } catch {\n throw new RemoteSubsetWireValueError(path, `unreadable property`)\n }\n if (!descriptor) return { present: false }\n if (!descriptor.enumerable || !(`value` in descriptor)) {\n throw new RemoteSubsetWireValueError(path, `non-data property`)\n }\n return { present: true, value: descriptor.value }\n}\n\nfunction assertAllowedProperties(\n value: object,\n path: string,\n allowed: ReadonlyArray<string>,\n): void {\n const allowedSet = new Set(allowed)\n for (const key of ownKeys(value, path)) {\n if (typeof key === `symbol` || !allowedSet.has(key)) {\n throw new RemoteSubsetWireValueError(propertyPath(path, key), `property`)\n }\n readDataProperty(value, key, propertyPath(path, key))\n }\n}\n\nfunction assertPlainContainer(value: object, path: string): void {\n assertExactPrototype(value, Object.prototype, path)\n}\n\nfunction assertExpressionPrototype(\n value: object,\n path: string,\n expressionPrototype: object,\n): void {\n let prototype: object | null\n try {\n prototype = Object.getPrototypeOf(value)\n } catch {\n throw new RemoteSubsetWireValueError(path, `unreadable prototype`)\n }\n if (prototype !== Object.prototype && prototype !== expressionPrototype) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n}\n\nfunction assertExactPrototype(\n value: object,\n expected: object,\n path: string,\n): void {\n let prototype: object | null\n try {\n prototype = Object.getPrototypeOf(value)\n } catch {\n throw new RemoteSubsetWireValueError(path, `unreadable prototype`)\n }\n if (prototype !== expected) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n}\n\nfunction assertNoOwnProperties(value: object, path: string): void {\n const keys = ownKeys(value, path)\n if (keys.length > 0) {\n throw new RemoteSubsetWireValueError(\n propertyPath(path, keys[0]!),\n `property`,\n )\n }\n}\n\nfunction assertFixedArrayBuffer(value: ArrayBuffer, path: string): void {\n if ((value as ArrayBuffer & { readonly resizable?: boolean }).resizable) {\n throw new RemoteSubsetWireValueError(path, `resizable ArrayBuffer`)\n }\n}\n\nfunction assertRegExpShape(value: RegExp, path: string): void {\n const keys = ownKeys(value, path)\n for (const key of keys) {\n if (key !== `lastIndex`) {\n throw new RemoteSubsetWireValueError(propertyPath(path, key), `property`)\n }\n }\n const descriptor = Object.getOwnPropertyDescriptor(value, `lastIndex`)\n if (!descriptor || !(`value` in descriptor) || descriptor.value !== 0) {\n throw new RemoteSubsetWireValueError(\n `${path}.lastIndex`,\n `RegExp lastIndex must be 0`,\n )\n }\n}\n\nfunction assertTypedArrayShape(\n value: RemoteSubsetWireTypedArray,\n path: string,\n): void {\n const keys = ownKeys(value, path)\n for (const key of keys) {\n if (typeof key !== `string` || !isCanonicalArrayIndex(key, value.length)) {\n throw new RemoteSubsetWireValueError(propertyPath(path, key), `property`)\n }\n }\n}\n\nfunction assertArrayShape(value: Array<unknown>, path: string): void {\n assertExactPrototype(value, Array.prototype, path)\n const keys = ownKeys(value, path)\n for (const key of keys) {\n if (\n key !== `length` &&\n (typeof key !== `string` || !isCanonicalArrayIndex(key, value.length))\n ) {\n throw new RemoteSubsetWireValueError(propertyPath(path, key), `property`)\n }\n if (key !== `length`) {\n readDataProperty(value, key, propertyPath(path, key))\n }\n }\n}\n\nfunction isCanonicalArrayIndex(key: string, length: number): boolean {\n if (!/^(0|[1-9][0-9]*)$/.test(key)) return false\n const index = Number(key)\n return Number.isSafeInteger(index) && index >= 0 && index < length\n}\n\nfunction getTypedArrayConstructor(\n value: object,\n): TypedArrayConstructor | undefined {\n let prototype: object | null\n try {\n prototype = Object.getPrototypeOf(value)\n } catch {\n return undefined\n }\n return typedArrayConstructors.find(\n (constructor) => prototype === constructor.prototype,\n )\n}\n\nfunction requireArray(value: unknown, path: string): Array<unknown> {\n if (!Array.isArray(value)) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n return value\n}\n\nfunction requireObject(value: unknown, path: string): object {\n if (value === null || typeof value !== `object`) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n return value\n}\n\nfunction requirePlainRecord(\n value: unknown,\n path: string,\n): Record<string, unknown> {\n const object = requireObject(value, path)\n assertExactPrototype(object, Object.prototype, path)\n return object as Record<string, unknown>\n}\n\nfunction ownKeys(value: object, path: string): Array<string | symbol> {\n try {\n return Reflect.ownKeys(value)\n } catch {\n throw new RemoteSubsetWireValueError(path, `unreadable properties`)\n }\n}\n\nfunction propertyPath(path: string, key: string | symbol): string {\n if (typeof key === `symbol`) return `${path}[${String(key)}]`\n return identifierPattern.test(key)\n ? `${path}.${key}`\n : `${path}[${JSON.stringify(key)}]`\n}\n\nfunction describe(value: unknown): string {\n if (value === null) return `null`\n if (typeof value !== `object`) return typeof value\n return `object`\n}\n"],"names":[],"mappings":";AA6EO,MAAM,mCAAmC,UAAU;AAAA,EAGxD,YACW,MACT,QACA;AACA,UAAM,2CAA2C,IAAI,KAAK,MAAM,EAAE;AAHzD,SAAA,OAAA;AAHX,SAAkB,OAAO;AAAA,EAOzB;AACF;AA2BA,MAAM,yBAA+D;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,aAAa;AACnB,MAAM,oBAAoB;AAMnB,SAAS,+BACd,SAC8B;AAC9B,uBAAqB,SAAS,SAAS;AACvC,0BAAwB,SAAS,WAAW;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,SAAS,cAAc,OAAgB,MAAsB;AAC3D,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAC/C,UAAM,IAAI,2BAA2B,MAAM,SAAS,KAAK,CAAC;AAAA,EAC5D;AACA,SAAO;AACT;AAEA,SAAS,mBACP,OACA,MACyB;AACzB,QAAM,SAAS,cAAc,OAAO,IAAI;AACxC,uBAAqB,QAAQ,OAAO,WAAW,IAAI;AACnD,SAAO;AACT;AAEA,SAAS,QAAQ,OAAe,MAAsC;AACpE,MAAI;AACF,WAAO,QAAQ,QAAQ,KAAK;AAAA,EAC9B,QAAQ;AACN,UAAM,IAAI,2BAA2B,MAAM,uBAAuB;AAAA,EACpE;AACF;AAEA,SAAS,aAAa,MAAc,KAA8B;AAChE,MAAI,OAAO,QAAQ,SAAU,QAAO,GAAG,IAAI,IAAI,OAAO,GAAG,CAAC;AAC1D,SAAO,kBAAkB,KAAK,GAAG,IAC7B,GAAG,IAAI,IAAI,GAAG,KACd,GAAG,IAAI,IAAI,KAAK,UAAU,GAAG,CAAC;AACpC;AAEA,SAAS,SAAS,OAAwB;AACxC,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,OAAO,UAAU,SAAU,QAAO,OAAO;AAC7C,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"remote-subset-wire.js","sources":["../../src/remote-subset-wire.ts"],"sourcesContent":["import { IR } from '@tanstack/db'\nimport type { LoadSubsetOptions } from '@tanstack/db'\n\nexport type RemoteSubsetWirePrimitive =\n undefined | null | boolean | string | number | bigint\n\nexport type RemoteSubsetWireTypedArray =\n | Int8Array\n | Uint8Array\n | Uint8ClampedArray\n | Int16Array\n | Uint16Array\n | Int32Array\n | Uint32Array\n | Float32Array\n | Float64Array\n | BigInt64Array\n | BigUint64Array\n\nexport type RemoteSubsetWireRecord = {\n [key: string]: RemoteSubsetWireValue\n}\n\n/** Values whose complete semantics survive a coordinator transport boundary. */\nexport type RemoteSubsetWireValue =\n | RemoteSubsetWirePrimitive\n | Date\n | RegExp\n | ArrayBuffer\n | DataView\n | RemoteSubsetWireTypedArray\n | Array<RemoteSubsetWireValue>\n | Map<RemoteSubsetWireValue, RemoteSubsetWireValue>\n | Set<RemoteSubsetWireValue>\n | RemoteSubsetWireRecord\n\nexport type RemoteSubsetWireExpression =\n | { type: `ref`; path: Array<string>; sourceAlias?: string }\n | { type: `val`; value: RemoteSubsetWireValue }\n | {\n type: `func`\n name: string\n args: Array<RemoteSubsetWireExpression>\n }\n\nexport type RemoteSubsetWireCompareOptions = {\n direction: `asc` | `desc`\n nulls: `first` | `last`\n} & (\n | { stringSort?: `lexical` }\n | {\n stringSort?: `locale`\n locale?: string\n localeOptions?: RemoteSubsetWireRecord\n }\n)\n\nexport type RemoteSubsetWireOrderByClause = {\n expression: RemoteSubsetWireExpression\n compareOptions: RemoteSubsetWireCompareOptions\n}\n\nexport type RemoteSubsetWireCursor = {\n whereFrom: RemoteSubsetWireExpression\n whereCurrent: RemoteSubsetWireExpression\n lastKey?: string | number\n}\n\n/** The complete data portion transported by a remote-subset request. */\nexport type TransportedLoadSubsetOptions = {\n where?: RemoteSubsetWireExpression\n orderBy?: Array<RemoteSubsetWireOrderByClause>\n limit?: number\n cursor?: RemoteSubsetWireCursor\n offset?: number\n}\n\nexport class RemoteSubsetWireValueError extends TypeError {\n override readonly name = `RemoteSubsetWireValueError`\n\n constructor(\n readonly path: string,\n reason: string,\n ) {\n super(`Unsupported remote subset wire value at ${path}: ${reason}`)\n }\n}\n\ntype ProjectionState = {\n validateOnly: boolean\n expressions: WeakMap<object, RemoteSubsetWireExpression>\n expressionArrays: WeakMap<object, Array<RemoteSubsetWireExpression>>\n stringArrays: WeakMap<object, Array<string>>\n orderByArrays: WeakMap<object, Array<RemoteSubsetWireOrderByClause>>\n orderByClauses: WeakMap<object, RemoteSubsetWireOrderByClause>\n compareOptions: WeakMap<object, RemoteSubsetWireCompareOptions>\n cursors: WeakMap<object, RemoteSubsetWireCursor>\n wireValues: WeakMap<object, RemoteSubsetWireValue>\n}\n\ntype DataProperty = {\n present: boolean\n value?: unknown\n}\n\ntype TypedArrayConstructor = {\n readonly prototype: RemoteSubsetWireTypedArray\n new (\n buffer: ArrayBuffer,\n byteOffset?: number,\n length?: number,\n ): RemoteSubsetWireTypedArray\n}\n\nconst typedArrayConstructors: ReadonlyArray<TypedArrayConstructor> = [\n Int8Array,\n Uint8Array,\n Uint8ClampedArray,\n Int16Array,\n Uint16Array,\n Int32Array,\n Uint32Array,\n Float32Array,\n Float64Array,\n BigInt64Array,\n BigUint64Array,\n]\n\nconst NativeDate = Date\nconst identifierPattern = /^[A-Za-z_$][A-Za-z0-9_$]*$/\n\n/**\n * Projects one live subset request into the exact coordinator wire domain.\n * Validation happens before callers choose a local-leader or transported path.\n */\nexport function toTransportedLoadSubsetOptions(\n options: LoadSubsetOptions,\n): TransportedLoadSubsetOptions {\n return visitLoadSubsetOptions(options, false)\n}\n\n/** Checks wire admission without constructing a detached request snapshot. */\nexport function validateRemoteSubsetOptions(options: LoadSubsetOptions): void {\n visitLoadSubsetOptions(options, true)\n}\n\n// Both modes run the same admission checks. Validation retains input nodes only\n// as cycle markers; it never writes to them or returns them to a caller.\nfunction visitLoadSubsetOptions(\n options: LoadSubsetOptions,\n validateOnly: boolean,\n): TransportedLoadSubsetOptions {\n assertPlainContainer(options, `options`)\n assertAllowedProperties(options, `options`, [\n `where`,\n `orderBy`,\n `limit`,\n `cursor`,\n `offset`,\n `signal`,\n `subscription`,\n ])\n\n const state: ProjectionState = {\n validateOnly,\n expressions: new WeakMap(),\n expressionArrays: new WeakMap(),\n stringArrays: new WeakMap(),\n orderByArrays: new WeakMap(),\n orderByClauses: new WeakMap(),\n compareOptions: new WeakMap(),\n cursors: new WeakMap(),\n wireValues: new WeakMap(),\n }\n const projected: TransportedLoadSubsetOptions = validateOnly\n ? (options as TransportedLoadSubsetOptions)\n : {}\n const where = readDataProperty(options, `where`, `options.where`)\n const orderBy = readDataProperty(options, `orderBy`, `options.orderBy`)\n const limit = readDataProperty(options, `limit`, `options.limit`)\n const cursor = readDataProperty(options, `cursor`, `options.cursor`)\n const offset = readDataProperty(options, `offset`, `options.offset`)\n\n if (where.present && where.value !== undefined) {\n const result = projectExpression(where.value, `options.where`, state)\n if (!state.validateOnly) projected.where = result\n }\n if (orderBy.present && orderBy.value !== undefined) {\n const result = projectOrderBy(orderBy.value, `options.orderBy`, state)\n if (!state.validateOnly) projected.orderBy = result\n }\n if (limit.present && limit.value !== undefined) {\n const result = projectNumber(limit.value, `options.limit`)\n if (!state.validateOnly) projected.limit = result\n }\n if (cursor.present && cursor.value !== undefined) {\n const result = projectCursor(cursor.value, `options.cursor`, state)\n if (!state.validateOnly) projected.cursor = result\n }\n if (offset.present && offset.value !== undefined) {\n const result = projectNumber(offset.value, `options.offset`)\n if (!state.validateOnly) projected.offset = result\n }\n\n return projected\n}\n\n/** Adds live lifecycle references only to an already validated local request. */\nexport function toProcessLocalLoadSubsetOptions(\n options: LoadSubsetOptions,\n transported = toTransportedLoadSubsetOptions(options),\n): TransportedLoadSubsetOptions &\n Pick<LoadSubsetOptions, `signal` | `subscription`> {\n const projected = {\n ...transported,\n } as TransportedLoadSubsetOptions &\n Pick<LoadSubsetOptions, `signal` | `subscription`>\n const signal = readDataProperty(options, `signal`, `options.signal`)\n const subscription = readDataProperty(\n options,\n `subscription`,\n `options.subscription`,\n )\n\n if (signal.present) {\n projected.signal = signal.value as LoadSubsetOptions[`signal`]\n }\n if (subscription.present) {\n projected.subscription =\n subscription.value as LoadSubsetOptions[`subscription`]\n }\n\n return projected\n}\n\nfunction projectExpression(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireExpression {\n const object = requireObject(value, path)\n const existing = state.expressions.get(object)\n if (existing) return existing\n\n const type = readDataProperty(object, `type`, `${path}.type`)\n if (!type.present || typeof type.value !== `string`) {\n throw new RemoteSubsetWireValueError(`${path}.type`, describe(type.value))\n }\n\n switch (type.value) {\n case `ref`: {\n assertExpressionPrototype(object, path, IR.PropRef.prototype)\n assertAllowedProperties(object, path, [`type`, `path`, `sourceAlias`])\n const projected: Extract<RemoteSubsetWireExpression, { type: `ref` }> =\n state.validateOnly\n ? (object as Extract<RemoteSubsetWireExpression, { type: `ref` }>)\n : { type: `ref`, path: [] }\n state.expressions.set(object, projected)\n const sourcePath = readRequiredDataProperty(\n object,\n `path`,\n `${path}.path`,\n )\n const result = projectStringArray(sourcePath, `${path}.path`, state)\n if (!state.validateOnly) projected.path = result\n const sourceAlias = readDataProperty(\n object,\n `sourceAlias`,\n `${path}.sourceAlias`,\n )\n if (sourceAlias.present) {\n if (\n typeof sourceAlias.value !== `string` ||\n result[0] !== sourceAlias.value\n ) {\n throw new RemoteSubsetWireValueError(\n `${path}.sourceAlias`,\n `source alias must match the first path segment`,\n )\n }\n if (!state.validateOnly) projected.sourceAlias = sourceAlias.value\n }\n return projected\n }\n case `val`: {\n assertExpressionPrototype(object, path, IR.Value.prototype)\n assertAllowedProperties(object, path, [`type`, `value`])\n const projected: Extract<RemoteSubsetWireExpression, { type: `val` }> =\n state.validateOnly\n ? (object as Extract<RemoteSubsetWireExpression, { type: `val` }>)\n : { type: `val`, value: undefined }\n state.expressions.set(object, projected)\n const sourceValue = readRequiredDataProperty(\n object,\n `value`,\n `${path}.value`,\n )\n const result = projectWireValue(sourceValue, `${path}.value`, state)\n if (!state.validateOnly) projected.value = result\n return projected\n }\n case `func`: {\n assertExpressionPrototype(object, path, IR.Func.prototype)\n assertAllowedProperties(object, path, [`type`, `name`, `args`])\n const projected: Extract<RemoteSubsetWireExpression, { type: `func` }> =\n state.validateOnly\n ? (object as Extract<RemoteSubsetWireExpression, { type: `func` }>)\n : { type: `func`, name: ``, args: [] }\n state.expressions.set(object, projected)\n const name = readRequiredDataProperty(object, `name`, `${path}.name`)\n if (typeof name !== `string`) {\n throw new RemoteSubsetWireValueError(`${path}.name`, describe(name))\n }\n if (!state.validateOnly) projected.name = name\n const args = readRequiredDataProperty(object, `args`, `${path}.args`)\n const result = projectExpressionArray(args, `${path}.args`, state)\n if (!state.validateOnly) projected.args = result\n return projected\n }\n default:\n throw new RemoteSubsetWireValueError(`${path}.type`, String(type.value))\n }\n}\n\nfunction projectExpressionArray(\n value: unknown,\n path: string,\n state: ProjectionState,\n): Array<RemoteSubsetWireExpression> {\n const array = requireArray(value, path)\n const existing = state.expressionArrays.get(array)\n if (existing) return existing\n assertArrayShape(array, path)\n const projected = state.validateOnly\n ? (array as Array<RemoteSubsetWireExpression>)\n : new Array<RemoteSubsetWireExpression>(array.length)\n state.expressionArrays.set(array, projected)\n for (let index = 0; index < array.length; index++) {\n if (!(index in array)) {\n throw new RemoteSubsetWireValueError(\n `${path}[${index}]`,\n `missing expression`,\n )\n }\n const result = projectExpression(array[index], `${path}[${index}]`, state)\n if (!state.validateOnly) projected[index] = result\n }\n return projected\n}\n\nfunction projectStringArray(\n value: unknown,\n path: string,\n state: ProjectionState,\n): Array<string> {\n const array = requireArray(value, path)\n const existing = state.stringArrays.get(array)\n if (existing) return existing\n assertArrayShape(array, path)\n const projected = state.validateOnly\n ? (array as Array<string>)\n : new Array<string>(array.length)\n state.stringArrays.set(array, projected)\n for (let index = 0; index < array.length; index++) {\n const entry = array[index]\n if (!(index in array) || typeof entry !== `string`) {\n throw new RemoteSubsetWireValueError(`${path}[${index}]`, describe(entry))\n }\n if (!state.validateOnly) projected[index] = entry\n }\n return projected\n}\n\nfunction projectOrderBy(\n value: unknown,\n path: string,\n state: ProjectionState,\n): Array<RemoteSubsetWireOrderByClause> {\n const array = requireArray(value, path)\n const existing = state.orderByArrays.get(array)\n if (existing) return existing\n assertArrayShape(array, path)\n const projected = state.validateOnly\n ? (array as Array<RemoteSubsetWireOrderByClause>)\n : new Array<RemoteSubsetWireOrderByClause>(array.length)\n state.orderByArrays.set(array, projected)\n\n for (let index = 0; index < array.length; index++) {\n const clausePath = `${path}[${index}]`\n const clause = requirePlainRecord(array[index], clausePath)\n const existingClause = state.orderByClauses.get(clause)\n if (existingClause) {\n if (!state.validateOnly) projected[index] = existingClause\n continue\n }\n assertAllowedProperties(clause, clausePath, [\n `expression`,\n `compareOptions`,\n ])\n const projectedClause = state.validateOnly\n ? (clause as RemoteSubsetWireOrderByClause)\n : {\n expression: undefined as unknown as RemoteSubsetWireExpression,\n compareOptions:\n undefined as unknown as RemoteSubsetWireCompareOptions,\n }\n if (!state.validateOnly) projected[index] = projectedClause\n state.orderByClauses.set(clause, projectedClause)\n const expression = projectExpression(\n readRequiredDataProperty(\n clause,\n `expression`,\n `${clausePath}.expression`,\n ),\n `${clausePath}.expression`,\n state,\n )\n const compareOptions = projectCompareOptions(\n readRequiredDataProperty(\n clause,\n `compareOptions`,\n `${clausePath}.compareOptions`,\n ),\n `${clausePath}.compareOptions`,\n state,\n )\n if (!state.validateOnly) {\n projectedClause.expression = expression\n projectedClause.compareOptions = compareOptions\n }\n }\n return projected\n}\n\nfunction projectCompareOptions(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireCompareOptions {\n const source = requirePlainRecord(value, path)\n const existing = state.compareOptions.get(source)\n if (existing) return existing\n assertAllowedProperties(source, path, [\n `direction`,\n `nulls`,\n `stringSort`,\n `locale`,\n `localeOptions`,\n ])\n const projected: {\n direction?: `asc` | `desc`\n nulls?: `first` | `last`\n stringSort?: `lexical` | `locale`\n locale?: string\n localeOptions?: RemoteSubsetWireRecord\n } = state.validateOnly ? source : {}\n\n const direction = readRequiredDataProperty(\n source,\n `direction`,\n `${path}.direction`,\n )\n if (direction !== `asc` && direction !== `desc`) {\n throw new RemoteSubsetWireValueError(\n `${path}.direction`,\n describe(direction),\n )\n }\n if (!state.validateOnly) projected.direction = direction\n\n const nulls = readRequiredDataProperty(source, `nulls`, `${path}.nulls`)\n if (nulls !== `first` && nulls !== `last`) {\n throw new RemoteSubsetWireValueError(`${path}.nulls`, describe(nulls))\n }\n if (!state.validateOnly) projected.nulls = nulls\n\n const stringSort = readDataProperty(\n source,\n `stringSort`,\n `${path}.stringSort`,\n )\n if (stringSort.present && stringSort.value !== undefined) {\n if (stringSort.value !== `lexical` && stringSort.value !== `locale`) {\n throw new RemoteSubsetWireValueError(\n `${path}.stringSort`,\n describe(stringSort.value),\n )\n }\n if (!state.validateOnly) projected.stringSort = stringSort.value\n }\n if (projected.stringSort !== `lexical`) {\n const locale = readDataProperty(source, `locale`, `${path}.locale`)\n if (locale.present && locale.value !== undefined) {\n if (typeof locale.value !== `string`) {\n throw new RemoteSubsetWireValueError(\n `${path}.locale`,\n describe(locale.value),\n )\n }\n if (!state.validateOnly) projected.locale = locale.value\n }\n const localeOptions = readDataProperty(\n source,\n `localeOptions`,\n `${path}.localeOptions`,\n )\n if (localeOptions.present && localeOptions.value !== undefined) {\n const result = projectWireRecord(\n localeOptions.value,\n `${path}.localeOptions`,\n state,\n )\n if (!state.validateOnly) projected.localeOptions = result\n }\n }\n const result = projected as RemoteSubsetWireCompareOptions\n state.compareOptions.set(source, result)\n return result\n}\n\nfunction projectCursor(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireCursor {\n const source = requirePlainRecord(value, path)\n const existing = state.cursors.get(source)\n if (existing) return existing\n assertAllowedProperties(source, path, [\n `whereFrom`,\n `whereCurrent`,\n `lastKey`,\n ])\n const projected: RemoteSubsetWireCursor = state.validateOnly\n ? (source as RemoteSubsetWireCursor)\n : {\n whereFrom: undefined as unknown as RemoteSubsetWireExpression,\n whereCurrent: undefined as unknown as RemoteSubsetWireExpression,\n }\n state.cursors.set(source, projected)\n const whereFrom = projectExpression(\n readRequiredDataProperty(source, `whereFrom`, `${path}.whereFrom`),\n `${path}.whereFrom`,\n state,\n )\n const whereCurrent = projectExpression(\n readRequiredDataProperty(source, `whereCurrent`, `${path}.whereCurrent`),\n `${path}.whereCurrent`,\n state,\n )\n if (!state.validateOnly) {\n projected.whereFrom = whereFrom\n projected.whereCurrent = whereCurrent\n }\n const lastKey = readDataProperty(source, `lastKey`, `${path}.lastKey`)\n if (lastKey.present && lastKey.value !== undefined) {\n if (\n typeof lastKey.value !== `string` &&\n typeof lastKey.value !== `number`\n ) {\n throw new RemoteSubsetWireValueError(\n `${path}.lastKey`,\n describe(lastKey.value),\n )\n }\n if (!state.validateOnly) projected.lastKey = lastKey.value\n }\n return projected\n}\n\nfunction projectWireValue(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireValue {\n if (\n value === undefined ||\n value === null ||\n typeof value === `boolean` ||\n typeof value === `string` ||\n typeof value === `number` ||\n typeof value === `bigint`\n ) {\n return value\n }\n if (typeof value !== `object`) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n\n const existing = state.wireValues.get(value)\n if (existing) return existing\n\n if (\n typeof SharedArrayBuffer !== `undefined` &&\n value instanceof SharedArrayBuffer\n ) {\n throw new RemoteSubsetWireValueError(path, `SharedArrayBuffer`)\n }\n if (value instanceof NativeDate) {\n assertExactPrototype(value, NativeDate.prototype, path)\n assertNoOwnProperties(value, path)\n const time = value.getTime()\n const projected = state.validateOnly ? value : new NativeDate(time)\n state.wireValues.set(value, projected)\n return projected\n }\n if (value instanceof RegExp) {\n assertExactPrototype(value, RegExp.prototype, path)\n assertRegExpShape(value, path)\n const { source, flags } = value\n const projected = state.validateOnly ? value : new RegExp(source, flags)\n state.wireValues.set(value, projected)\n return projected\n }\n if (value instanceof ArrayBuffer) {\n assertExactPrototype(value, ArrayBuffer.prototype, path)\n assertNoOwnProperties(value, path)\n assertFixedArrayBuffer(value, path)\n let projected: ArrayBuffer\n try {\n if (state.validateOnly) {\n // A zero-length view checks detachment without copying the backing bytes.\n new Uint8Array(value, 0, 0)\n projected = value\n } else {\n projected = value.slice(0)\n }\n } catch {\n throw new RemoteSubsetWireValueError(path, `detached ArrayBuffer`)\n }\n state.wireValues.set(value, projected)\n return projected\n }\n if (value instanceof DataView) {\n assertExactPrototype(value, DataView.prototype, path)\n assertNoOwnProperties(value, path)\n let byteOffset: number\n let byteLength: number\n let buffer: ArrayBufferLike\n try {\n byteOffset = value.byteOffset\n byteLength = value.byteLength\n buffer = value.buffer\n } catch {\n throw new RemoteSubsetWireValueError(path, `detached DataView`)\n }\n const projectedBuffer = projectWireValue(buffer, path, state)\n if (!(projectedBuffer instanceof ArrayBuffer)) {\n throw new RemoteSubsetWireValueError(path, `shared DataView buffer`)\n }\n const projected = state.validateOnly\n ? value\n : new DataView(projectedBuffer, byteOffset, byteLength)\n state.wireValues.set(value, projected)\n return projected\n }\n\n const typedArrayConstructor = getTypedArrayConstructor(value)\n if (typedArrayConstructor) {\n const typedArray = value as RemoteSubsetWireTypedArray\n assertTypedArrayShape(typedArray, path)\n let byteOffset: number\n let length: number\n let buffer: ArrayBufferLike\n try {\n byteOffset = typedArray.byteOffset\n length = typedArray.length\n buffer = typedArray.buffer\n } catch {\n throw new RemoteSubsetWireValueError(path, `detached typed array`)\n }\n if (!(buffer instanceof ArrayBuffer)) {\n throw new RemoteSubsetWireValueError(path, `shared typed-array buffer`)\n }\n const projectedBuffer = projectWireValue(buffer, path, state)\n if (!(projectedBuffer instanceof ArrayBuffer)) {\n throw new RemoteSubsetWireValueError(path, `shared typed-array buffer`)\n }\n let projected: RemoteSubsetWireTypedArray\n try {\n projected = state.validateOnly\n ? typedArray\n : new typedArrayConstructor(projectedBuffer, byteOffset, length)\n } catch {\n throw new RemoteSubsetWireValueError(path, `detached typed array`)\n }\n state.wireValues.set(value, projected)\n return projected\n }\n if (ArrayBuffer.isView(value)) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n if (Array.isArray(value)) return projectWireArray(value, path, state)\n if (value instanceof Map) return projectWireMap(value, path, state)\n if (value instanceof Set) return projectWireSet(value, path, state)\n return projectWireRecord(value, path, state)\n}\n\nfunction projectWireArray(\n value: Array<unknown>,\n path: string,\n state: ProjectionState,\n): Array<RemoteSubsetWireValue> {\n assertArrayShape(value, path)\n const projected = state.validateOnly\n ? (value as Array<RemoteSubsetWireValue>)\n : new Array<RemoteSubsetWireValue>(value.length)\n state.wireValues.set(value, projected)\n for (let index = 0; index < value.length; index++) {\n if (index in value) {\n const result = projectWireValue(value[index], `${path}[${index}]`, state)\n if (!state.validateOnly) projected[index] = result\n }\n }\n return projected\n}\n\nfunction projectWireMap(\n value: Map<unknown, unknown>,\n path: string,\n state: ProjectionState,\n): Map<RemoteSubsetWireValue, RemoteSubsetWireValue> {\n assertExactPrototype(value, Map.prototype, path)\n assertNoOwnProperties(value, path)\n const projected = state.validateOnly\n ? (value as Map<RemoteSubsetWireValue, RemoteSubsetWireValue>)\n : new Map<RemoteSubsetWireValue, RemoteSubsetWireValue>()\n state.wireValues.set(value, projected)\n let index = 0\n for (const [key, entry] of value) {\n const projectedKey = projectWireValue(\n key,\n `${path}.entries[${index}].key`,\n state,\n )\n const projectedValue = projectWireValue(\n entry,\n `${path}.entries[${index}].value`,\n state,\n )\n if (!state.validateOnly) projected.set(projectedKey, projectedValue)\n index++\n }\n return projected\n}\n\nfunction projectWireSet(\n value: Set<unknown>,\n path: string,\n state: ProjectionState,\n): Set<RemoteSubsetWireValue> {\n assertExactPrototype(value, Set.prototype, path)\n assertNoOwnProperties(value, path)\n const projected = state.validateOnly\n ? (value as Set<RemoteSubsetWireValue>)\n : new Set<RemoteSubsetWireValue>()\n state.wireValues.set(value, projected)\n let index = 0\n for (const entry of value) {\n const result = projectWireValue(entry, `${path}.values[${index}]`, state)\n if (!state.validateOnly) projected.add(result)\n index++\n }\n return projected\n}\n\nfunction projectWireRecord(\n value: unknown,\n path: string,\n state: ProjectionState,\n): RemoteSubsetWireRecord {\n const source = requirePlainRecord(value, path)\n const existing = state.wireValues.get(source)\n if (existing) return existing as RemoteSubsetWireRecord\n const projected: RemoteSubsetWireRecord = state.validateOnly\n ? (source as RemoteSubsetWireRecord)\n : {}\n state.wireValues.set(source, projected)\n\n for (const key of ownKeys(source, path)) {\n const childPath = propertyPath(path, key)\n if (typeof key === `symbol`) {\n throw new RemoteSubsetWireValueError(childPath, `symbol property key`)\n }\n const descriptor = Object.getOwnPropertyDescriptor(source, key)\n if (!descriptor || !descriptor.enumerable || !(`value` in descriptor)) {\n throw new RemoteSubsetWireValueError(childPath, `non-data property`)\n }\n const result = projectWireValue(descriptor.value, childPath, state)\n if (!state.validateOnly) {\n Object.defineProperty(projected, key, {\n value: result,\n enumerable: true,\n writable: true,\n configurable: true,\n })\n }\n }\n return projected\n}\n\nfunction projectNumber(value: unknown, path: string): number {\n if (typeof value !== `number` || !Number.isSafeInteger(value) || value < 0) {\n throw new RemoteSubsetWireValueError(path, `non-negative safe integer`)\n }\n return value\n}\n\nfunction readRequiredDataProperty(\n value: object,\n key: string,\n path: string,\n): unknown {\n const property = readDataProperty(value, key, path)\n if (!property.present) {\n throw new RemoteSubsetWireValueError(path, `missing property`)\n }\n return property.value\n}\n\nfunction readDataProperty(\n value: object,\n key: string,\n path: string,\n): DataProperty {\n let descriptor: PropertyDescriptor | undefined\n try {\n descriptor = Object.getOwnPropertyDescriptor(value, key)\n } catch {\n throw new RemoteSubsetWireValueError(path, `unreadable property`)\n }\n if (!descriptor) return { present: false }\n if (!descriptor.enumerable || !(`value` in descriptor)) {\n throw new RemoteSubsetWireValueError(path, `non-data property`)\n }\n return { present: true, value: descriptor.value }\n}\n\nfunction assertAllowedProperties(\n value: object,\n path: string,\n allowed: ReadonlyArray<string>,\n): void {\n const allowedSet = new Set(allowed)\n for (const key of ownKeys(value, path)) {\n if (typeof key === `symbol` || !allowedSet.has(key)) {\n throw new RemoteSubsetWireValueError(propertyPath(path, key), `property`)\n }\n readDataProperty(value, key, propertyPath(path, key))\n }\n}\n\nfunction assertPlainContainer(value: object, path: string): void {\n assertExactPrototype(value, Object.prototype, path)\n}\n\nfunction assertExpressionPrototype(\n value: object,\n path: string,\n expressionPrototype: object,\n): void {\n let prototype: object | null\n try {\n prototype = Object.getPrototypeOf(value)\n } catch {\n throw new RemoteSubsetWireValueError(path, `unreadable prototype`)\n }\n if (prototype !== Object.prototype && prototype !== expressionPrototype) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n}\n\nfunction assertExactPrototype(\n value: object,\n expected: object,\n path: string,\n): void {\n let prototype: object | null\n try {\n prototype = Object.getPrototypeOf(value)\n } catch {\n throw new RemoteSubsetWireValueError(path, `unreadable prototype`)\n }\n if (prototype !== expected) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n}\n\nfunction assertNoOwnProperties(value: object, path: string): void {\n const keys = ownKeys(value, path)\n if (keys.length > 0) {\n throw new RemoteSubsetWireValueError(\n propertyPath(path, keys[0]!),\n `property`,\n )\n }\n}\n\nfunction assertFixedArrayBuffer(value: ArrayBuffer, path: string): void {\n if ((value as ArrayBuffer & { readonly resizable?: boolean }).resizable) {\n throw new RemoteSubsetWireValueError(path, `resizable ArrayBuffer`)\n }\n}\n\nfunction assertRegExpShape(value: RegExp, path: string): void {\n const keys = ownKeys(value, path)\n for (const key of keys) {\n if (key !== `lastIndex`) {\n throw new RemoteSubsetWireValueError(propertyPath(path, key), `property`)\n }\n }\n const descriptor = Object.getOwnPropertyDescriptor(value, `lastIndex`)\n if (!descriptor || !(`value` in descriptor) || descriptor.value !== 0) {\n throw new RemoteSubsetWireValueError(\n `${path}.lastIndex`,\n `RegExp lastIndex must be 0`,\n )\n }\n}\n\nfunction assertTypedArrayShape(\n value: RemoteSubsetWireTypedArray,\n path: string,\n): void {\n const keys = ownKeys(value, path)\n for (const key of keys) {\n if (typeof key !== `string` || !isCanonicalArrayIndex(key, value.length)) {\n throw new RemoteSubsetWireValueError(propertyPath(path, key), `property`)\n }\n }\n}\n\nfunction assertArrayShape(value: Array<unknown>, path: string): void {\n assertExactPrototype(value, Array.prototype, path)\n const keys = ownKeys(value, path)\n for (const key of keys) {\n if (\n key !== `length` &&\n (typeof key !== `string` || !isCanonicalArrayIndex(key, value.length))\n ) {\n throw new RemoteSubsetWireValueError(propertyPath(path, key), `property`)\n }\n if (key !== `length`) {\n readDataProperty(value, key, propertyPath(path, key))\n }\n }\n}\n\nfunction isCanonicalArrayIndex(key: string, length: number): boolean {\n if (!/^(0|[1-9][0-9]*)$/.test(key)) return false\n const index = Number(key)\n return Number.isSafeInteger(index) && index >= 0 && index < length\n}\n\nfunction getTypedArrayConstructor(\n value: object,\n): TypedArrayConstructor | undefined {\n let prototype: object | null\n try {\n prototype = Object.getPrototypeOf(value)\n } catch {\n return undefined\n }\n return typedArrayConstructors.find(\n (constructor) => prototype === constructor.prototype,\n )\n}\n\nfunction requireArray(value: unknown, path: string): Array<unknown> {\n if (!Array.isArray(value)) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n return value\n}\n\nfunction requireObject(value: unknown, path: string): object {\n if (value === null || typeof value !== `object`) {\n throw new RemoteSubsetWireValueError(path, describe(value))\n }\n return value\n}\n\nfunction requirePlainRecord(\n value: unknown,\n path: string,\n): Record<string, unknown> {\n const object = requireObject(value, path)\n assertExactPrototype(object, Object.prototype, path)\n return object as Record<string, unknown>\n}\n\nfunction ownKeys(value: object, path: string): Array<string | symbol> {\n try {\n return Reflect.ownKeys(value)\n } catch {\n throw new RemoteSubsetWireValueError(path, `unreadable properties`)\n }\n}\n\nfunction propertyPath(path: string, key: string | symbol): string {\n if (typeof key === `symbol`) return `${path}[${String(key)}]`\n return identifierPattern.test(key)\n ? `${path}.${key}`\n : `${path}[${JSON.stringify(key)}]`\n}\n\nfunction describe(value: unknown): string {\n if (value === null) return `null`\n if (typeof value !== `object`) return typeof value\n return `object`\n}\n"],"names":["result"],"mappings":";AA6EO,MAAM,mCAAmC,UAAU;AAAA,EAGxD,YACW,MACT,QACA;AACA,UAAM,2CAA2C,IAAI,KAAK,MAAM,EAAE;AAHzD,SAAA,OAAA;AAHX,SAAkB,OAAO;AAAA,EAOzB;AACF;AA4BA,MAAM,yBAA+D;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,aAAa;AACnB,MAAM,oBAAoB;AAMnB,SAAS,+BACd,SAC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Predicate, compileSingleRowExpression, compareTemporalValues } from "@tanstack/db";
|
|
2
2
|
import { InvalidPersistedCollectionConfigError, InvalidPersistedStorageKeyEncodingError } from "./errors.js";
|
|
3
3
|
import { encodePersistedStorageKey, createPersistedTableName, decodePersistedStorageKey, SQLITE_DRIVER_SHARED_LOGICAL_SCHEDULING_KEY } from "./persisted.js";
|
|
4
|
-
import { assertSQLiteBigIntInRange, PERSISTED_TYPE_TAG, PERSISTED_VALUE_TAG, serializeSQLiteBigInt } from "./sqlite-value.js";
|
|
4
|
+
import { serializeSQLiteTemporal, sqliteTemporalIdentity, assertSQLiteBigIntInRange, sqliteTemporalKind, PERSISTED_TYPE_TAG, PERSISTED_VALUE_TAG, reviveSQLiteTemporal, serializeSQLiteBigInt } from "./sqlite-value.js";
|
|
5
5
|
const REPLACEMENT_BATCH_SIZE = 125;
|
|
6
6
|
class SharedPersistenceScheduler {
|
|
7
7
|
constructor() {
|
|
@@ -115,7 +115,10 @@ const persistedTaggedValueTypes = /* @__PURE__ */ new Set([
|
|
|
115
115
|
`date`,
|
|
116
116
|
`nan`,
|
|
117
117
|
`infinity`,
|
|
118
|
-
`-infinity
|
|
118
|
+
`-infinity`,
|
|
119
|
+
`string`,
|
|
120
|
+
`Temporal.Instant`,
|
|
121
|
+
`Temporal.PlainDate`
|
|
119
122
|
]);
|
|
120
123
|
const orderByObjectIds = /* @__PURE__ */ new WeakMap();
|
|
121
124
|
let nextOrderByObjectId = 1;
|
|
@@ -153,6 +156,8 @@ function encodePersistedJsonValue(value) {
|
|
|
153
156
|
if (typeof value === `bigint`) {
|
|
154
157
|
return serializeSQLiteBigInt(value);
|
|
155
158
|
}
|
|
159
|
+
const temporal = serializeSQLiteTemporal(value);
|
|
160
|
+
if (temporal) return temporal;
|
|
156
161
|
if (value instanceof Date) {
|
|
157
162
|
return {
|
|
158
163
|
[PERSISTED_TYPE_TAG]: `date`,
|
|
@@ -192,6 +197,12 @@ function encodePersistedJsonValue(value) {
|
|
|
192
197
|
encodedRecord[key] = encodedValue;
|
|
193
198
|
}
|
|
194
199
|
}
|
|
200
|
+
if (typeof recordValue[PERSISTED_TYPE_TAG] === `string`) {
|
|
201
|
+
encodedRecord[PERSISTED_TYPE_TAG] = {
|
|
202
|
+
[PERSISTED_TYPE_TAG]: `string`,
|
|
203
|
+
[PERSISTED_VALUE_TAG]: recordValue[PERSISTED_TYPE_TAG]
|
|
204
|
+
};
|
|
205
|
+
}
|
|
195
206
|
return encodedRecord;
|
|
196
207
|
}
|
|
197
208
|
return value;
|
|
@@ -202,6 +213,14 @@ function decodePersistedJsonValue(value) {
|
|
|
202
213
|
}
|
|
203
214
|
if (isPersistedTaggedValue(value)) {
|
|
204
215
|
switch (value[PERSISTED_TYPE_TAG]) {
|
|
216
|
+
case `string`:
|
|
217
|
+
return value[PERSISTED_VALUE_TAG];
|
|
218
|
+
case `Temporal.Instant`:
|
|
219
|
+
case `Temporal.PlainDate`:
|
|
220
|
+
return reviveSQLiteTemporal(
|
|
221
|
+
value[PERSISTED_TYPE_TAG],
|
|
222
|
+
value[PERSISTED_VALUE_TAG]
|
|
223
|
+
);
|
|
205
224
|
case `bigint`:
|
|
206
225
|
return BigInt(value[PERSISTED_VALUE_TAG]);
|
|
207
226
|
case `date`: {
|
|
@@ -261,7 +280,8 @@ function toSqliteParameterValue(value) {
|
|
|
261
280
|
if (value instanceof Date) {
|
|
262
281
|
return value.toISOString();
|
|
263
282
|
}
|
|
264
|
-
|
|
283
|
+
const temporal = serializeSQLiteTemporal(value);
|
|
284
|
+
return temporal?.order ?? serializePersistedRowValue(value);
|
|
265
285
|
}
|
|
266
286
|
function toSqliteLiteral(value) {
|
|
267
287
|
if (value === null) {
|
|
@@ -270,6 +290,9 @@ function toSqliteLiteral(value) {
|
|
|
270
290
|
if (typeof value === `number`) {
|
|
271
291
|
return Number.isFinite(value) ? String(value) : `NULL`;
|
|
272
292
|
}
|
|
293
|
+
if (value.includes(`\0`)) {
|
|
294
|
+
return `json_extract(${toSqliteLiteral(JSON.stringify(value))}, '$')`;
|
|
295
|
+
}
|
|
273
296
|
return `'${value.replace(/'/g, `''`)}'`;
|
|
274
297
|
}
|
|
275
298
|
function toSqliteExpressionLiteral(value) {
|
|
@@ -345,6 +368,9 @@ function compareOrderByValues(left, right, compareOptions) {
|
|
|
345
368
|
if (left instanceof Date && right instanceof Date) {
|
|
346
369
|
return left.getTime() - right.getTime();
|
|
347
370
|
}
|
|
371
|
+
if (sqliteTemporalKind(left) && sqliteTemporalKind(right)) {
|
|
372
|
+
return compareTemporalValues(left, right);
|
|
373
|
+
}
|
|
348
374
|
const leftIsObject = typeof left === `object`;
|
|
349
375
|
const rightIsObject = typeof right === `object`;
|
|
350
376
|
if (leftIsObject || rightIsObject) {
|
|
@@ -451,16 +477,23 @@ function compileRefExpressionSql(jsonPath) {
|
|
|
451
477
|
const typePathSql = toSqliteLiteral(typePath);
|
|
452
478
|
const taggedValuePathSql = toSqliteLiteral(taggedValuePath);
|
|
453
479
|
const jsonPathSql = toSqliteLiteral(jsonPath);
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
480
|
+
const typeSql = `json_extract(value, ${typePathSql})`;
|
|
481
|
+
const orderPathSql = toSqliteLiteral(`${jsonPath}.order`);
|
|
482
|
+
const sql = `(CASE ${typeSql}
|
|
457
483
|
WHEN 'bigint' THEN CAST(json_extract(value, ${taggedValuePathSql}) AS NUMERIC)
|
|
458
484
|
WHEN 'date' THEN json_extract(value, ${taggedValuePathSql})
|
|
485
|
+
WHEN 'string' THEN json_extract(value, ${taggedValuePathSql})
|
|
486
|
+
WHEN 'Temporal.Instant' THEN json_extract(value, ${orderPathSql})
|
|
487
|
+
WHEN 'Temporal.PlainDate' THEN json_extract(value, ${orderPathSql})
|
|
459
488
|
WHEN 'nan' THEN NULL
|
|
460
489
|
WHEN 'infinity' THEN NULL
|
|
461
490
|
WHEN '-infinity' THEN NULL
|
|
462
491
|
ELSE json_extract(value, ${jsonPathSql})
|
|
463
|
-
END)
|
|
492
|
+
END)`;
|
|
493
|
+
return {
|
|
494
|
+
supported: true,
|
|
495
|
+
sql,
|
|
496
|
+
identitySql: `(CASE WHEN ${typeSql} IN ('Temporal.Instant', 'Temporal.PlainDate') THEN ${typeSql} || ':' || json_extract(value, ${taggedValuePathSql}) ELSE ${sql} END)`,
|
|
464
497
|
params: [],
|
|
465
498
|
valueKind: `unknown`
|
|
466
499
|
};
|
|
@@ -488,6 +521,11 @@ function decodeStoredSqliteRows(storedRows) {
|
|
|
488
521
|
function stableStringify(value) {
|
|
489
522
|
return serializePersistedRowValue(value);
|
|
490
523
|
}
|
|
524
|
+
function joinSqlDisjunction(parts) {
|
|
525
|
+
if (parts.length === 1) return parts[0];
|
|
526
|
+
const middle = Math.floor(parts.length / 2);
|
|
527
|
+
return `(${joinSqlDisjunction(parts.slice(0, middle))} OR ${joinSqlDisjunction(parts.slice(middle))})`;
|
|
528
|
+
}
|
|
491
529
|
function argumentCompilationContext(parentName, argumentIndex, argument, parentContext) {
|
|
492
530
|
if (parentContext === `index-expression`) return `index-expression`;
|
|
493
531
|
switch (parentName) {
|
|
@@ -517,7 +555,7 @@ function hasUnpairedSurrogate(value) {
|
|
|
517
555
|
return /[\uD800-\uDFFF]/u.test(value);
|
|
518
556
|
}
|
|
519
557
|
function isSafeEqualityLiteral(value) {
|
|
520
|
-
return typeof value === `string` || typeof value === `boolean` || typeof value === `bigint
|
|
558
|
+
return typeof value === `string` || typeof value === `boolean` || typeof value === `bigint` || sqliteTemporalKind(value) !== void 0;
|
|
521
559
|
}
|
|
522
560
|
function isSafeCoalesceOperand(expression) {
|
|
523
561
|
return expression?.type === `func` && expression.name === `coalesce` && expression.args.length === 2 && expression.args[0]?.type === `ref` && expression.args[1]?.type === `val` && isSafeEqualityLiteral(expression.args[1].value) && !(typeof expression.args[1].value === `string` && hasUnpairedSurrogate(expression.args[1].value));
|
|
@@ -531,12 +569,16 @@ function compileSqlExpression(expression, context = `predicate`) {
|
|
|
531
569
|
params: [JSON.stringify(expression.value)]
|
|
532
570
|
};
|
|
533
571
|
}
|
|
534
|
-
const
|
|
572
|
+
const temporal = serializeSQLiteTemporal(expression.value);
|
|
573
|
+
const value = temporal?.order ?? toSqliteParameterValue(expression.value);
|
|
535
574
|
return {
|
|
575
|
+
identitySql: temporal ? toSqliteLiteral(sqliteTemporalIdentity(temporal)) : void 0,
|
|
536
576
|
supported: true,
|
|
537
|
-
sql: context === `index-expression` ? toSqliteExpressionLiteral(
|
|
538
|
-
|
|
539
|
-
|
|
577
|
+
sql: context === `index-expression` ? toSqliteExpressionLiteral(
|
|
578
|
+
typeof expression.value === `bigint` ? expression.value : value
|
|
579
|
+
) : `?`,
|
|
580
|
+
params: context === `predicate` ? [value] : [],
|
|
581
|
+
valueKind: getLiteralValueKind(expression.value)
|
|
540
582
|
};
|
|
541
583
|
}
|
|
542
584
|
if (expression.type === `ref`) {
|
|
@@ -551,14 +593,17 @@ function compileSqlExpression(expression, context = `predicate`) {
|
|
|
551
593
|
};
|
|
552
594
|
}
|
|
553
595
|
if (jsonPaths.length === 1) return compileRefExpressionSql(jsonPaths[0]);
|
|
596
|
+
const variants = jsonPaths.map(compileRefExpressionSql);
|
|
554
597
|
return {
|
|
555
598
|
supported: true,
|
|
556
|
-
|
|
599
|
+
identitySql: `COALESCE(${variants.map((variant) => variant.identitySql).join(`, `)})`,
|
|
600
|
+
sql: `COALESCE(${variants.map((variant) => variant.sql).join(`, `)})`,
|
|
557
601
|
params: [],
|
|
558
602
|
valueKind: `unknown`
|
|
559
603
|
};
|
|
560
604
|
}
|
|
561
|
-
const
|
|
605
|
+
const args = expression.name === `in` ? expression.args.slice(0, 1) : expression.args;
|
|
606
|
+
const compiledArgs = args.map(
|
|
562
607
|
(arg, index) => compileSqlExpression(
|
|
563
608
|
arg,
|
|
564
609
|
argumentCompilationContext(expression.name, index, arg, context)
|
|
@@ -595,18 +640,22 @@ function compileSqlExpression(expression, context = `predicate`) {
|
|
|
595
640
|
lt: `<`,
|
|
596
641
|
lte: `<=`
|
|
597
642
|
};
|
|
643
|
+
const comparison = compileComparisonSql(
|
|
644
|
+
operatorByName[expression.name],
|
|
645
|
+
expression.args[0],
|
|
646
|
+
expression.args[1],
|
|
647
|
+
argSql[0],
|
|
648
|
+
argSql[1],
|
|
649
|
+
valueKind,
|
|
650
|
+
getCompiledValueKind(compiledArgs[0]),
|
|
651
|
+
getCompiledValueKind(compiledArgs[1])
|
|
652
|
+
);
|
|
653
|
+
const needsIdentity = expression.name === `eq` && expression.args.every(
|
|
654
|
+
(arg) => arg.type !== `val` || sqliteTemporalKind(arg.value) || context === `index-expression` && typeof arg.value === `string`
|
|
655
|
+
);
|
|
598
656
|
return {
|
|
599
657
|
supported: true,
|
|
600
|
-
sql:
|
|
601
|
-
operatorByName[expression.name],
|
|
602
|
-
expression.args[0],
|
|
603
|
-
expression.args[1],
|
|
604
|
-
argSql[0],
|
|
605
|
-
argSql[1],
|
|
606
|
-
valueKind,
|
|
607
|
-
getCompiledValueKind(compiledArgs[0]),
|
|
608
|
-
getCompiledValueKind(compiledArgs[1])
|
|
609
|
-
),
|
|
658
|
+
sql: needsIdentity ? `(${comparison} AND (${compiledArgs[0].identitySql ?? argSql[0]} = ${compiledArgs[1].identitySql ?? argSql[1]}))` : comparison,
|
|
610
659
|
params
|
|
611
660
|
};
|
|
612
661
|
}
|
|
@@ -651,19 +700,33 @@ function compileSqlExpression(expression, context = `predicate`) {
|
|
|
651
700
|
if (!leftSql) {
|
|
652
701
|
return { supported: false, sql: ``, params: [] };
|
|
653
702
|
}
|
|
703
|
+
const values = listValue.map((value) => {
|
|
704
|
+
const temporal = serializeSQLiteTemporal(value);
|
|
705
|
+
return {
|
|
706
|
+
value: typeof value === `bigint` ? assertSQLiteBigIntInRange(value) : temporal?.order ?? toSqliteParameterValue(value),
|
|
707
|
+
identity: temporal ? sqliteTemporalIdentity(temporal) : void 0
|
|
708
|
+
};
|
|
709
|
+
});
|
|
710
|
+
let identity = ``;
|
|
711
|
+
if (listValue.some(
|
|
712
|
+
(value) => sqliteTemporalKind(value) || context === `index-expression` && typeof value === `string`
|
|
713
|
+
)) {
|
|
714
|
+
const leftIdentity = compiledArgs[0]?.identitySql ?? leftSql;
|
|
715
|
+
identity = context === `index-expression` ? ` AND (${joinSqlDisjunction(values.map(({ value, identity: nativeIdentity }) => `(${leftSql} = ${toSqliteExpressionLiteral(value)} AND ${leftIdentity} = ${toSqliteExpressionLiteral(nativeIdentity ?? value)})`))})` : ` AND ((${leftSql}, ${leftIdentity}) IN (VALUES ${[...new Set(values.map(({ value, identity: nativeIdentity }) => `(${toSqliteExpressionLiteral(value)}, ${toSqliteExpressionLiteral(nativeIdentity ?? value)})`))].join(`, `)}))`;
|
|
716
|
+
}
|
|
654
717
|
if (context === `index-expression`) {
|
|
655
718
|
return {
|
|
656
719
|
supported: true,
|
|
657
|
-
sql: `(${leftSql} IN (${
|
|
720
|
+
sql: `(${leftSql} IN (${values.map(({ value }) => toSqliteExpressionLiteral(value)).join(`, `)})${identity})`,
|
|
658
721
|
params: leftParams
|
|
659
722
|
};
|
|
660
723
|
}
|
|
661
|
-
const jsonList = `[${
|
|
662
|
-
(value) => typeof value === `bigint` ? assertSQLiteBigIntInRange(value).toString() : JSON.stringify(
|
|
724
|
+
const jsonList = `[${values.map(
|
|
725
|
+
({ value }) => typeof value === `bigint` ? assertSQLiteBigIntInRange(value).toString() : JSON.stringify(value)
|
|
663
726
|
).join(`,`)}]`;
|
|
664
727
|
return {
|
|
665
728
|
supported: true,
|
|
666
|
-
sql: `(${leftSql} IN (SELECT value FROM json_each(?)))`,
|
|
729
|
+
sql: `(${leftSql} IN (SELECT value FROM json_each(?))${identity})`,
|
|
667
730
|
params: [...leftParams, jsonList]
|
|
668
731
|
};
|
|
669
732
|
}
|
|
@@ -691,7 +754,12 @@ function compileSqlExpression(expression, context = `predicate`) {
|
|
|
691
754
|
case `concat`:
|
|
692
755
|
return { supported: true, sql: `(${argSql.join(` || `)})`, params };
|
|
693
756
|
case `coalesce`:
|
|
694
|
-
return {
|
|
757
|
+
return {
|
|
758
|
+
supported: true,
|
|
759
|
+
sql: `COALESCE(${argSql.join(`, `)})`,
|
|
760
|
+
identitySql: `COALESCE(${compiledArgs.map((arg) => arg.identitySql ?? arg.sql).join(`, `)})`,
|
|
761
|
+
params
|
|
762
|
+
};
|
|
695
763
|
case `add`:
|
|
696
764
|
return { supported: true, sql: `(${argSql[0]} + ${argSql[1]})`, params };
|
|
697
765
|
case `subtract`:
|
|
@@ -728,6 +796,31 @@ function compileSqlExpression(expression, context = `predicate`) {
|
|
|
728
796
|
};
|
|
729
797
|
}
|
|
730
798
|
}
|
|
799
|
+
function nativeComparisonRef(expression) {
|
|
800
|
+
if (expression.type !== `func` || expression.args.length !== 2)
|
|
801
|
+
return void 0;
|
|
802
|
+
const [left, right] = expression.args;
|
|
803
|
+
if (expression.name === `in`) {
|
|
804
|
+
return left?.type === `ref` && right?.type === `val` && Array.isArray(right.value) && right.value.length > 0 && right.value.every((value) => sqliteTemporalKind(value)) ? left : void 0;
|
|
805
|
+
}
|
|
806
|
+
if (![`eq`, `gt`, `gte`, `lt`, `lte`].includes(expression.name))
|
|
807
|
+
return void 0;
|
|
808
|
+
if (left?.type === `ref` && right?.type === `val` && sqliteTemporalKind(right.value))
|
|
809
|
+
return left;
|
|
810
|
+
if (right?.type === `ref` && left?.type === `val` && sqliteTemporalKind(left.value))
|
|
811
|
+
return right;
|
|
812
|
+
return void 0;
|
|
813
|
+
}
|
|
814
|
+
function compileNativeRefGuard(ref) {
|
|
815
|
+
const paths = createJsonPathVariants(
|
|
816
|
+
IR.getPropRefPropertyPath(ref).map(String)
|
|
817
|
+
);
|
|
818
|
+
const kinds = paths.map(
|
|
819
|
+
(path) => `json_extract(value, ${toSqliteLiteral(`${path}.${PERSISTED_TYPE_TAG}`)})`
|
|
820
|
+
);
|
|
821
|
+
const kind = kinds.length === 1 ? kinds[0] : `COALESCE(${kinds.join(`, `)})`;
|
|
822
|
+
return `${kind} IN ('Temporal.Instant', 'Temporal.PlainDate')`;
|
|
823
|
+
}
|
|
731
824
|
function compileSafeSqlPrefilter(expression, compiled) {
|
|
732
825
|
const direct = () => {
|
|
733
826
|
const candidate = compiled ?? compileSqlExpression(expression);
|
|
@@ -758,7 +851,22 @@ function compileSafeSqlPrefilter(expression, compiled) {
|
|
|
758
851
|
compiled ??= compileSqlExpression(expression);
|
|
759
852
|
if (!compiled.supported) return void 0;
|
|
760
853
|
const [left, right] = expression.args;
|
|
854
|
+
if (expression.name === `not` && expression.args.length === 1 && left && nativeComparisonRef(left)) {
|
|
855
|
+
return { ...compiled, sql: `COALESCE(${compiled.sql}, 1)` };
|
|
856
|
+
}
|
|
761
857
|
if (expression.args.length === 2) {
|
|
858
|
+
const nativeRef = nativeComparisonRef(expression);
|
|
859
|
+
if (nativeRef) {
|
|
860
|
+
if (expression.name === `eq` || expression.name === `in`) return compiled;
|
|
861
|
+
const fieldSql = compileSqlExpression(nativeRef, `index-expression`).sql;
|
|
862
|
+
return { ...compiled, sql: `(${compiled.sql} OR ${fieldSql} IS NULL)` };
|
|
863
|
+
}
|
|
864
|
+
if (expression.name === `eq` && left?.type === `ref` && right?.type === `ref`) {
|
|
865
|
+
return {
|
|
866
|
+
...compiled,
|
|
867
|
+
sql: `(CASE WHEN ${compileNativeRefGuard(left)} AND ${compileNativeRefGuard(right)} THEN ${compiled.sql} ELSE 1 END)`
|
|
868
|
+
};
|
|
869
|
+
}
|
|
762
870
|
if ([`gt`, `gte`, `lt`, `lte`].includes(expression.name) && (left?.type === `ref` || right?.type === `ref`)) {
|
|
763
871
|
const field = left?.type === `ref` ? left : right?.type === `ref` ? right : void 0;
|
|
764
872
|
const literal = field === left ? right : left;
|