UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

1 lines • 23.3 kB
{"version":3,"file":"ir.cjs","names":["codedMessage","isRefProxy"],"sources":["../../../src/query/ir.ts"],"sourcesContent":["import { codedMessage, devBuild } from '../error-message.js'\nimport { isRefProxy } from './builder/ref-proxy-identity.js'\n\n/*\nThis is the intermediate representation of the query.\n*/\n\nimport type { CompareOptions } from './builder/types'\nimport type { Collection, CollectionImpl } from '../collection/index.js'\nimport type { CollectionOptionsIdentity } from '../collection-options.js'\nimport type { NamespacedRow } from '../types'\n\nimport type { Grouping } from './compiler/grouping.js'\nimport type { IncludesRuntime } from './live/includes-runtime.js'\n\nexport interface QueryIR {\n from: From\n select?: Select\n join?: Join\n where?: Array<Where>\n groupBy?: GroupBy\n // groupKeys supplies the grouping compiler when no aggregate does.\n grouping?: Grouping\n having?: Array<Having>\n orderBy?: OrderBy\n limit?: Limit\n offset?: Offset\n distinct?: true\n singleResult?: true\n\n // Functional variants\n fnSelect?: (row: NamespacedRow) => any\n fnWhere?: Array<(row: NamespacedRow) => any>\n fnHaving?: Array<(row: NamespacedRow) => any>\n}\n\nexport type IncludesMaterialization =\n `collection` | `array` | `singleton` | `concat`\n\nexport const INCLUDES_SCALAR_FIELD = `__includes_scalar__`\n\nexport type CollectionSourceRef = CollectionRef | DescriptorRef\n\nexport type From = CollectionSourceRef | QueryRef | UnionFrom | UnionAll\n\nexport type Select = {\n [alias: string]:\n BasicExpression | Aggregate | Select | IncludesSubquery | ConditionalSelect\n}\n\nexport type Join = Array<JoinClause>\n\nexport interface JoinClause {\n from: CollectionSourceRef | QueryRef\n type: `left` | `right` | `inner` | `outer` | `full` | `cross`\n on: BasicExpression<boolean>\n}\n\nexport type Where =\n | BasicExpression<boolean>\n | { expression: BasicExpression<boolean>; residual?: boolean }\n\nexport type GroupBy = Array<BasicExpression>\n\nexport type Having = Where\n\nexport type OrderBy = Array<OrderByClause>\n\nexport type OrderByClause = {\n expression: BasicExpression\n compareOptions: CompareOptions\n}\n\nexport type OrderByDirection = `asc` | `desc`\n\nexport type Limit = number\n\nexport type Offset = number\n\nlet nextCollectionSourceId = 0\nlet nextLexicalBindingId = 0\n\n/* Expressions */\n\nabstract class BaseExpression<T = any> {\n public abstract type: string\n /** @internal - Type brand for TypeScript inference */\n declare readonly __returnType: T\n}\n\nexport class CollectionRef extends BaseExpression {\n public type = `collectionRef` as const\n // Not an own property, so structural identity and hashing ignore it.\n readonly #sourceId = `source-${++nextCollectionSourceId}`\n declare public collection: CollectionImpl\n public alias: string\n readonly #bindingId: string\n constructor(\n collection: CollectionImpl<any, string | number, any, any, any>,\n alias: string,\n bindingId?: string,\n ) {\n super()\n this.collection = collection as CollectionImpl\n this.alias = alias\n this.#bindingId = bindingId ?? `binding-${++nextLexicalBindingId}`\n }\n\n /** Opaque runtime identity; aliases are lexical names only. */\n get sourceId(): string {\n return this.#sourceId\n }\n\n get bindingId(): string {\n return this.#bindingId\n }\n}\n\nexport class DescriptorRef extends BaseExpression {\n public type = `descriptorRef` as const\n readonly #sourceId = `source-${++nextCollectionSourceId}`\n readonly #bindingId: string\n constructor(\n public descriptor: CollectionOptionsIdentity<any, any, any, any, any>,\n public alias: string,\n bindingId?: string,\n ) {\n super()\n this.#bindingId = bindingId ?? `binding-${++nextLexicalBindingId}`\n }\n\n /** Opaque runtime identity for this unbound source placement. */\n get sourceId(): string {\n return this.#sourceId\n }\n\n get bindingId(): string {\n return this.#bindingId\n }\n}\n\n/** A descriptor must bind to a DbClient before a Collection is required. */\nexport function requireCollectionSource(source: DescriptorRef): never\nexport function requireCollectionSource(\n source: CollectionSourceRef,\n): CollectionImpl\nexport function requireCollectionSource(\n source: CollectionSourceRef,\n): CollectionImpl {\n if (source.type === `descriptorRef`) {\n throw new Error(\n devBuild() && process.env.NODE_ENV !== `production`\n ? `Collection descriptor \"${source.alias}\" requires a DbClient when the query is consumed. Bind the query through a client-aware API or use a concrete Collection.`\n : codedMessage(113, { alias: source.alias }),\n )\n }\n return source.collection\n}\n\nexport class QueryRef extends BaseExpression {\n public type = `queryRef` as const\n readonly #bindingId: string\n constructor(\n public query: QueryIR,\n public alias: string,\n bindingId?: string,\n ) {\n super()\n this.#bindingId = bindingId ?? `binding-${++nextLexicalBindingId}`\n }\n\n get bindingId(): string {\n return this.#bindingId\n }\n}\n\nexport class UnionFrom extends BaseExpression {\n public type = `unionFrom` as const\n constructor(public sources: Array<CollectionSourceRef | QueryRef>) {\n super()\n }\n\n get alias(): string {\n return this.sources[0]?.alias ?? ``\n }\n}\n\nexport class UnionAll extends BaseExpression {\n public type = `unionAll` as const\n /**\n * Result-level UNION ALL. Downstream query clauses see the union result row\n * shape, not the branch source aliases. Optimizers may push safe operations\n * into branches, but compiler phases should treat this as a derived relation\n * unless they are explicitly handling branch lowering.\n */\n constructor(public queries: Array<QueryIR>) {\n super()\n }\n\n get alias(): string {\n return ``\n }\n}\n\nexport class PropRef<T = any> extends BaseExpression<T> {\n public type = `ref` as const\n declare public readonly sourceAlias?: string\n declare public readonly bindingId?: string\n constructor(\n public path: Array<string>, // path to the property in the collection, with the alias as the first element\n sourceAlias?: string,\n bindingId?: string,\n ) {\n super()\n // Present only when given, so unqualified refs keep their shape.\n if (sourceAlias !== undefined) {\n ;(this as { sourceAlias?: string }).sourceAlias = sourceAlias\n }\n if (bindingId !== undefined) {\n // Preserve structural IR equality and optional record compatibility.\n Object.defineProperty(this, `bindingId`, {\n value: bindingId,\n enumerable: false,\n })\n }\n }\n}\n\n/** Returns an explicitly declared source alias without inferring from the path. */\nexport function getPropRefSourceAlias(ref: PropRef): string | undefined {\n return ref.sourceAlias !== undefined && ref.path[0] === ref.sourceAlias\n ? ref.sourceAlias\n : undefined\n}\n\n/** Returns the property path after removing only explicit source qualification. */\nexport function getPropRefPropertyPath(ref: PropRef): Array<string> {\n return getPropRefSourceAlias(ref) === undefined ? ref.path : ref.path.slice(1)\n}\n\nexport class Value<T = any> extends BaseExpression<T> {\n public type = `val` as const\n constructor(\n public value: T, // any js value\n ) {\n super()\n }\n}\n\nexport class Func<T = any> extends BaseExpression<T> {\n public type = `func` as const\n constructor(\n public name: string, // such as eq, gt, lt, upper, lower, etc.\n public args: Array<BasicExpression>,\n ) {\n super()\n }\n}\n\n// This is the basic expression type that is used in the majority of expression\n// builder callbacks (select, where, groupBy, having, orderBy, etc.)\n// it doesn't include aggregate functions as those are only used in the select clause\nexport type BasicExpression<T = any> = PropRef<T> | Value<T> | Func<T>\n\nexport class Aggregate<T = any> extends BaseExpression<T> {\n public type = `agg` as const\n constructor(\n public name: string, // such as count, avg, sum, min, max, etc.\n public args: Array<BasicExpression>,\n // The aggregate function brings the grouping compiler with it.\n public grouping: Grouping,\n ) {\n super()\n }\n}\n\n/** Collect refs from an IR expression, including aggregate arguments. */\nexport function collectPropRefs(\n expression: BasicExpression | Aggregate,\n): Array<PropRef> {\n if (expression.type === `ref`) return [expression]\n return expression.type === `func` || expression.type === `agg`\n ? expression.args.flatMap(collectPropRefs)\n : []\n}\n\nexport class IncludesSubquery extends BaseExpression {\n public type = `includesSubquery` as const\n constructor(\n public query: QueryIR, // Child query (correlation WHERE removed)\n public correlationField: PropRef, // Parent-side ref (e.g., project.id)\n public childCorrelationField: PropRef, // Child-side ref (e.g., issue.projectId)\n public fieldName: string, // Result field name (e.g., \"issues\")\n // The include value brings the materializer that publishes it.\n public runtime: IncludesRuntime,\n public parentFilters?: Array<Where>, // WHERE clauses referencing parent aliases (applied post-join)\n public parentProjection?: Array<PropRef>, // Parent field refs used anywhere in the child plan\n public materialization: IncludesMaterialization = `collection`,\n public scalarField?: string,\n ) {\n super()\n }\n}\n\nexport type ConditionalSelectBranch = {\n condition: BasicExpression\n value: SelectValueExpression\n}\n\nexport type SelectValueExpression =\n BasicExpression | Aggregate | Select | IncludesSubquery | ConditionalSelect\n\nexport class ConditionalSelect extends BaseExpression {\n public type = `conditionalSelect` as const\n constructor(\n public branches: Array<ConditionalSelectBranch>,\n public defaultValue?: SelectValueExpression,\n ) {\n super()\n }\n}\n\n/** Distinguish compiler expressions from user objects with IR-like fields. */\nexport function isBasicOrAggregateExpression(\n value: unknown,\n): value is BasicExpression | Aggregate {\n return (\n value instanceof Aggregate ||\n value instanceof Func ||\n value instanceof PropRef ||\n value instanceof Value\n )\n}\n\nexport function isExpressionLike(value: unknown): boolean {\n return (\n isBasicOrAggregateExpression(value) ||\n value instanceof ConditionalSelect ||\n value instanceof IncludesSubquery\n )\n}\n\n/** Returns each lexical Collection or descriptor source in a query tree once. */\nexport function collectSourceRefs(\n query: QueryIR,\n /** Receives the IDs of sources first reached through an include. */\n includeSourceIds?: Set<string>,\n): Array<CollectionSourceRef> {\n const sources: Array<CollectionSourceRef> = []\n const seen = new Set<string>()\n let includeDepth = 0\n\n const visitSource = (source: QueryIR[`from`]): void => {\n if (source.type === `collectionRef` || source.type === `descriptorRef`) {\n if (!seen.has(source.sourceId)) {\n seen.add(source.sourceId)\n sources.push(source)\n if (includeDepth > 0) includeSourceIds?.add(source.sourceId)\n }\n } else if (source.type === `queryRef`) {\n visitQuery(source.query)\n } else if (source.type === `unionFrom`) {\n source.sources.forEach(visitSource)\n } else {\n source.queries.forEach(visitQuery)\n }\n }\n\n const visitSelectValue = (value: any): void => {\n if (value instanceof IncludesSubquery) {\n includeDepth++\n visitQuery(value.query)\n includeDepth--\n } else if (value instanceof ConditionalSelect) {\n value.branches.forEach((branch) => visitSelectValue(branch.value))\n if (value.defaultValue !== undefined) {\n visitSelectValue(value.defaultValue)\n }\n } else if (\n value !== null &&\n typeof value === `object` &&\n !Array.isArray(value) &&\n !isExpressionLike(value) &&\n !isRefProxy(value)\n ) {\n Object.values(value).forEach(visitSelectValue)\n }\n }\n\n const visitQuery = (current: QueryIR): void => {\n visitSource(current.from)\n current.join?.forEach(({ from }) => visitSource(from))\n if (current.select) Object.values(current.select).forEach(visitSelectValue)\n }\n\n visitQuery(query)\n return sources\n}\n\n/** Returns concrete Collection sources after requiring client binding. */\nexport function collectCollectionSources(query: QueryIR): Array<CollectionRef> {\n return collectSourceRefs(query).map((source) =>\n source.type === `descriptorRef` ? requireCollectionSource(source) : source,\n )\n}\n\n/**\n * Helper functions for working with Where clauses\n */\n\n/**\n * Extract the expression from a Where clause\n */\nexport function getWhereExpression(where: Where): BasicExpression<boolean> {\n return typeof where === `object` && `expression` in where\n ? where.expression\n : where\n}\n\n/**\n * Extract the expression from a HAVING clause\n * HAVING clauses can contain aggregates, unlike regular WHERE clauses\n */\nexport function getHavingExpression(\n having: Having,\n): BasicExpression | Aggregate {\n return typeof having === `object` && `expression` in having\n ? having.expression\n : having\n}\n\n/**\n * Check if a Where clause is marked as residual\n */\nexport function isResidualWhere(where: Where): boolean {\n return (\n typeof where === `object` &&\n `expression` in where &&\n where.residual === true\n )\n}\n\n/**\n * Create a residual Where clause from an expression\n */\nexport function createResidualWhere(\n expression: BasicExpression<boolean>,\n): Where {\n return { expression, residual: true }\n}\n\n/** Sources declared by a FROM clause. UnionAll branches own their sources. */\nexport function getFromSources(\n from: From,\n): Array<CollectionSourceRef | QueryRef> {\n if (from.type === `unionFrom`) return from.sources\n if (from.type === `unionAll`) return []\n return [from]\n}\n\nfunction getRefFromAlias(\n query: QueryIR,\n alias: string,\n bindingId?: string,\n): CollectionSourceRef | QueryRef | void {\n for (const source of getFromSources(query.from)) {\n if (\n source.alias === alias &&\n (bindingId === undefined || source.bindingId === bindingId)\n ) {\n return source\n }\n }\n\n for (const join of query.join || []) {\n if (\n join.from.alias === alias &&\n (bindingId === undefined || join.from.bindingId === bindingId)\n ) {\n return join.from\n }\n }\n}\n\n/**\n * Follows the given reference in a query\n * until its finds the root field the reference points to.\n * @returns The collection, its alias, and the path to the root field in this collection.\n * `alias` is the alias under which the resolved collection is referenced in the\n * query it was reached from (when the ref crosses into a joined source). It is\n * left undefined when the ref simply resolves to a field on the passed-in\n * `collection`, in which case the caller already knows the alias.\n */\nexport function followRef(\n query: QueryIR,\n ref: PropRef<any>,\n collection: Collection,\n): {\n collection: Collection\n path: Array<string>\n alias?: string\n sourceId?: string\n} | void {\n const explicitAlias = getPropRefSourceAlias(ref)\n if (explicitAlias !== undefined) {\n const aliasRef = getRefFromAlias(query, explicitAlias, ref.bindingId)\n if (!aliasRef) return\n\n const propertyPath = getPropRefPropertyPath(ref)\n if (aliasRef.type === `queryRef`) {\n return followRef(aliasRef.query, new PropRef(propertyPath), collection)\n }\n\n return {\n collection: requireCollectionSource(aliasRef),\n path: propertyPath,\n alias: explicitAlias,\n sourceId: aliasRef.sourceId,\n }\n }\n\n if (ref.path.length === 0) {\n return\n }\n\n if (ref.path.length === 1) {\n // This field should be part of this collection\n const field = ref.path[0]!\n // is it part of the select clause?\n if (query.select) {\n const selectedField = query.select[field]\n if (selectedField) {\n // A computed projection has no source field that can satisfy a\n // source-level lookup or ordered acquisition.\n return selectedField.type === `ref`\n ? followRef(query, selectedField, collection)\n : undefined\n }\n }\n\n // Without a projection for this field, it belongs to the source row.\n const from = getFromSources(query.from)[0]\n if (from?.type === `queryRef`) {\n return followRef(from.query, new PropRef([field]), collection)\n }\n if (from?.type !== `collectionRef`) return\n return {\n collection,\n path: [field],\n alias: from.alias,\n sourceId: from.sourceId,\n }\n }\n\n if (ref.path.length > 1) {\n // This is a nested field\n const [alias, ...rest] = ref.path\n const aliasRef = getRefFromAlias(query, alias!, ref.bindingId)\n if (!aliasRef) {\n return\n }\n\n if (aliasRef.type === `queryRef`) {\n return followRef(aliasRef.query, new PropRef(rest), collection)\n } else {\n // This is a reference to a collection\n // we can't follow it further\n // so the field must be on the collection itself.\n // Report the alias too: when the ref crossed a join, this is the source\n // that actually holds the field (which may differ from the from clause).\n return {\n collection: requireCollectionSource(aliasRef),\n path: rest,\n alias,\n sourceId: aliasRef.sourceId,\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,wBAAwB;AAwCrC,IAAI,yBAAyB;AAC7B,IAAI,uBAAuB;AAI3B,IAAe,iBAAf,MAAuC,CAIvC;AAEA,IAAa,gBAAb,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