@tanstack/db
Version:
A reactive client store for building super fast apps on sync
1 lines • 2.86 kB
Source Map (JSON)
{"version":3,"file":"equality-conjunct.cjs","names":["normalizeValue","isVirtualPropName"],"sources":["../../../src/query/equality-conjunct.ts"],"sourcesContent":["import { normalizeValue } from '../utils/comparison.js'\nimport { isVirtualPropName } from '../virtual-props.js'\nimport type { BasicExpression, PropRef } from './ir.js'\n\ntype Row = Record<string, unknown>\n\n/** An `eq(field, literal)` conjunct on a row's own field. */\nexport type EqualityConjunct = { path: Array<string>; literalKey: string }\n\n// Typed so that 1, '1', and true stay distinct.\nexport function equalityKey(value: unknown): string | undefined {\n const normalized = normalizeValue(value)\n const type = typeof normalized\n return type === `string` || type === `number` || type === `boolean`\n ? `${type}:${String(normalized)}`\n : undefined\n}\n\nexport function readPath(row: Row, path: Array<string>): unknown {\n try {\n let value: unknown = row\n for (const segment of path) value = (value as Row | undefined)?.[segment]\n return value\n } catch {\n // The full predicate treats a throwing read as false.\n return undefined\n }\n}\n\n/**\n * The `eq(field, literal)` conjunct `expression` is, with the field's path in\n * the row as `rowPath` gives it, or undefined for any other expression.\n */\nexport function equalityConjunct(\n expression: BasicExpression,\n rowPath: (ref: PropRef) => Array<string> | undefined,\n): EqualityConjunct | undefined {\n if (expression.type !== `func` || expression.name !== `eq`) return undefined\n const args = expression.args\n if (args.length !== 2) return undefined\n const left = args[0]!\n const right = args[1]!\n const ref = left.type === `ref` ? left : right\n const literal = left.type === `val` ? left : right\n if (ref.type !== `ref` || literal.type !== `val`) return undefined\n const path = rowPath(ref)\n if (!path?.length || isVirtualPropName(path[0]!)) return undefined\n const literalKey = equalityKey(literal.value)\n return literalKey === undefined ? undefined : { path, literalKey }\n}\n"],"mappings":";;AAUA,SAAgB,YAAY,OAAoC;CAC9D,MAAM,aAAaA,mBAAAA,eAAe,KAAK;CACvC,MAAM,OAAO,OAAO;CACpB,OAAO,SAAS,YAAY,SAAS,YAAY,SAAS,YACtD,GAAG,KAAA,GAAQ,OAAO,UAAU,MAC5B,KAAA;AACN;AAEA,SAAgB,SAAS,KAAU,MAA8B;CAC/D,IAAI;EACF,IAAI,QAAiB;EACrB,KAAA,MAAW,WAAW,MAAM,QAAS,QAA4B;EACjE,OAAO;CACT,QAAQ;EAEN;CACF;AACF;AAMA,SAAgB,iBACd,YACA,SAC8B;CAC9B,IAAI,WAAW,SAAS,UAAU,WAAW,SAAS,MAAM,OAAO,KAAA;CACnE,MAAM,OAAO,WAAW;CACxB,IAAI,KAAK,WAAW,GAAG,OAAO,KAAA;CAC9B,MAAM,OAAO,KAAK;CAClB,MAAM,QAAQ,KAAK;CACnB,MAAM,MAAM,KAAK,SAAS,QAAQ,OAAO;CACzC,MAAM,UAAU,KAAK,SAAS,QAAQ,OAAO;CAC7C,IAAI,IAAI,SAAS,SAAS,QAAQ,SAAS,OAAO,OAAO,KAAA;CACzD,MAAM,OAAO,QAAQ,GAAG;CACxB,IAAI,CAAC,MAAM,UAAUC,sBAAAA,kBAAkB,KAAK,EAAG,GAAG,OAAO,KAAA;CACzD,MAAM,aAAa,YAAY,QAAQ,KAAK;CAC5C,OAAO,eAAe,KAAA,IAAY,KAAA,IAAY;EAAE;EAAM;CAAW;AACnE"}