{"version":3,"file":"include-functions.cjs","names":["ToArrayWrapper","includesRuntime","MaterializeWrapper","IncludeWrapper"],"sources":["../../../../src/query/builder/include-functions.ts"],"sourcesContent":["import { includesRuntime } from '../live/includes-runtime.js'\nimport {\n  IncludeWrapper,\n  MaterializeWrapper,\n  ToArrayWrapper,\n} from './functions.js'\nimport type { SingleResult } from '../../types.js'\nimport type { BaseQueryBuilder, QueryBuilder } from './index.js'\nimport type { Context, GetInlineResult } from './types.js'\n\n// The include functions carry the include materializer. They live apart from\n// the expression functions, which core modules import, so only apps that\n// include subqueries bundle it.\n\nexport function toArray<TContext extends Context>(\n  query: QueryBuilder<TContext>,\n): ToArrayWrapper<GetInlineResult<TContext>> {\n  return new ToArrayWrapper(query, includesRuntime)\n}\n\n/**\n * Materialize an includes subquery into a plain value on the parent row.\n *\n * - For multi-row subqueries, the parent receives an `Array<T>` snapshot\n *   (equivalent to `toArray()`).\n * - For `findOne()` subqueries, the parent receives a single `T | undefined`\n *   value — `undefined` when no child matches.\n *\n * The snapshot updates reactively: parent rows re-emit when the underlying\n * children change.\n *\n * @example\n * ```ts\n * // Multi-row: produces Array<Issue> on each project\n * select(({ p }) => ({\n *   ...p,\n *   issues: materialize(\n *     q.from({ i: issues }).where(({ i }) => eq(i.projectId, p.id)),\n *   ),\n * }))\n *\n * // Singleton: produces Author | undefined on each post\n * select(({ p }) => ({\n *   ...p,\n *   author: materialize(\n *     q.from({ a: authors }).where(({ a }) => eq(a.id, p.authorId)).findOne(),\n *   ),\n * }))\n * ```\n */\nexport function materialize<TContext extends Context>(\n  query: QueryBuilder<TContext>,\n): MaterializeWrapper<\n  GetInlineResult<TContext>,\n  TContext extends SingleResult ? true : false\n> {\n  return new MaterializeWrapper(query, includesRuntime)\n}\n\n/**\n * Includes a correlated subquery as a live child Collection on each parent\n * row. Use `toArray()` or `materialize()` for inline values instead.\n *\n * @example\n * ```ts\n * select(({ p }) => ({\n *   ...p,\n *   issues: include(\n *     q.from({ i: issues }).where(({ i }) => eq(i.projectId, p.id)),\n *   ),\n * }))\n * ```\n */\nexport function include<TContext extends Context>(\n  query: QueryBuilder<TContext>,\n): IncludeWrapper<TContext> {\n  // Every QueryBuilder is a BaseQueryBuilder; the public type hides internals.\n  return new IncludeWrapper(\n    query as unknown as BaseQueryBuilder<any>,\n    includesRuntime,\n  )\n}\n"],"mappings":";;AAcA,SAAgB,QACd,OAC2C;CAC3C,OAAO,IAAIA,kBAAAA,eAAe,OAAOC,yBAAAA,eAAe;AAClD;AAgCA,SAAgB,YACd,OAIA;CACA,OAAO,IAAIC,kBAAAA,mBAAmB,OAAOD,yBAAAA,eAAe;AACtD;AAgBA,SAAgB,QACd,OAC0B;CAE1B,OAAO,IAAIE,kBAAAA,eACT,OACAF,yBAAAA,eACF;AACF"}