{"version":3,"file":"order-by.cjs","names":["hasVirtualPropPath","compileExpression","makeComparator","defaultComparator","followRef","supportsOrderedIndexStructure","findIndexForField","supportsOrderedRange","collectCollectionSources","PropRef","getSourceAliasesFromExpression","getWhereExpression","isResidualWhere","deepEquals","groupedOrderByWithFractionalIndex","orderByWithFractionalIndex"],"sources":["../../../../src/query/compiler/order-by.ts"],"sourcesContent":["import {\n  groupedOrderByWithFractionalIndex,\n  orderByWithFractionalIndex,\n} from '@tanstack/db-ivm'\nimport { defaultComparator, makeComparator } from '../../utils/comparison.js'\nimport {\n  PropRef,\n  collectCollectionSources,\n  followRef,\n  getWhereExpression,\n  isResidualWhere,\n} from '../ir.js'\nimport { ensureIndexForField } from '../../indexes/auto-index.js'\nimport {\n  findIndexForField,\n  supportsOrderedIndexStructure,\n  supportsOrderedRange,\n} from '../../utils/index-optimization.js'\nimport { hasVirtualPropPath } from '../../virtual-props.js'\nimport { deepEquals } from '../../utils.js'\nimport { devBuild } from '../../error-message.js'\nimport { compileExpression } from './evaluators.js'\nimport { getSourceAliasesFromExpression } from './expressions.js'\nimport type { CompareOptions } from '../builder/types.js'\nimport type { WindowOptions } from './types.js'\nimport type { Grouping } from './grouping.js'\nimport type { CompiledSingleRowExpression } from './evaluators.js'\nimport type { OrderBy, OrderByClause, QueryIR, Select } from '../ir.js'\nimport type {\n  CollectionLike,\n  NamespacedAndKeyedStream,\n  NamespacedRow,\n} from '../../types.js'\nimport type {\n  IStreamBuilder,\n  KeyValue,\n  SetSizeCallback,\n} from '@tanstack/db-ivm'\nimport type { IndexReader } from '../../indexes/base-index.js'\nimport type { Collection } from '../../collection/index.js'\n\nexport type OrderByOptimizationInfo = {\n  sourceId: string\n  alias: string\n  orderBy: OrderBy\n  offset: number\n  limit: number\n  comparator: (\n    a: Record<string, unknown> | null | undefined,\n    b: Record<string, unknown> | null | undefined,\n  ) => number\n  /** Extracts the leading provider order value from a raw row. */\n  valueExtractorForRawRow: (row: Record<string, unknown>) => unknown\n  /** Index on the first orderBy column - used for lazy loading */\n  index?: IndexReader<string | number>\n  /**\n   * Rows the window still needs. Given the loader's settled boundary, a window\n   * row after it does not count: the graph may lack an earlier eligible row.\n   */\n  dataNeeded?: (boundary?: Record<string, unknown>) => number\n  /** Reads the source loader's synchronous request guard, when installed. */\n  isRequesting?: () => boolean\n  /**\n   * Whether a provider-ordered finite prefix is insufficient for the local\n   * plan, including when a custom local collation defines another order.\n   */\n  requiresFullSource: boolean\n  /** Whether the ordered source's installed rows are the whole source. */\n  sourceHoldsAllRows: boolean\n  /** Sources whose lazy demand must settle before a joined-filter page. */\n  joinedFilterSourceIds?: ReadonlyArray<string>\n}\n\nfunction warnOrderIndexFallback(\n  collection: Collection,\n  path: Array<string>,\n  options: CompareOptions,\n  index?: IndexReader<string | number>,\n): void {\n  if (devBuild() && process.env.NODE_ENV !== `production`) {\n    const field = path.join(`.`)\n    const prefix = `[TanStack DB]${collection.id ? ` [${collection.id}]` : ``} orderBy with limit`\n    if (options.stringSort === `custom`) {\n      console.warn(\n        `${prefix} uses a custom string comparator on \"${field}\". On-demand sources require a filtered full source request for local sorting. An index with the same compare function reference can sort installed rows, but cannot make provider pagination safe.`,\n      )\n      return\n    }\n    if (hasVirtualPropPath(path)) {\n      console.warn(\n        `${prefix} orders virtual field \"${field}\"; Collection indexes cannot cover virtual fields, so creating one will not enable ordered lazy loading.`,\n      )\n      return\n    }\n    if (index) return\n\n    const fieldIndexes = [...collection.indexes.values()].filter((candidate) =>\n      candidate.matchesField(path),\n    )\n    let detail: string\n    if (fieldIndexes.length === 0) {\n      detail = `requires an index on \"${field}\" for efficient lazy loading. Consider collection.createIndex((row) => row.${field}) or autoIndex: 'eager' with a defaultIndexType.`\n    } else if (\n      fieldIndexes.every(\n        (candidate) => !candidate.matchesCompareOptions(options),\n      )\n    ) {\n      detail = `found an index on \"${field}\", but none uses the query's compareOptions (nulls: \"${options.nulls}\", stringSort: \"${options.stringSort ?? `locale`}\"${options.stringSort === `locale` ? `, including the same locale and localeOptions` : ``}). After importing BasicIndex from '@tanstack/db', use collection.createIndex((row) => row.${field}, { indexType: BasicIndex, options: { compareOptions: { direction: \"asc\", nulls: \"${options.nulls}\", stringSort: \"${options.stringSort ?? `locale`}\" } } }). Match the query's nulls and string collation, including any locale and localeOptions. The index direction may differ.`\n    } else {\n      detail = `found an index on \"${field}\" with matching compareOptions, but none supports ordered lazy loading. Use an index with ordered range reads, one comparable value domain, and no custom comparator.`\n    }\n    console.warn(\n      `${prefix} ${detail} Local reads may scan or sort installed rows; an underfilled on-demand window may require a full-source request.`,\n    )\n  }\n}\n\n/**\n * Processes the ORDER BY clause\n * Works with the new structure that has both namespaced row data and $selected\n * Always uses fractional indexing and adds the index as __ordering_index to the result\n */\nexport function processOrderBy(\n  rawQuery: QueryIR,\n  pipeline: NamespacedAndKeyedStream,\n  orderByClause: Array<OrderByClause>,\n  selectClause: Select,\n  // The query's grouping compiler, if it has one, rewrites aggregates.\n  grouping: Grouping | undefined,\n  collection: Collection,\n  optimizableOrderByCollections: Record<string, OrderByOptimizationInfo>,\n  setWindowFn: (windowFn: (options: WindowOptions) => void) => void,\n  limit?: number,\n  offset?: number,\n  groupKeyFn?: (key: unknown, value: unknown) => unknown,\n): IStreamBuilder<KeyValue<unknown, [NamespacedRow, string]>> {\n  const compiledOrderBy = orderByClause.map((clause) => {\n    // Aggregate references read the SELECT result under $selected. A query\n    // without the grouping compiler has no aggregates.\n    const clauseWithoutAggregates = grouping\n      ? grouping.replaceAggregatesByRefs(\n          clause.expression,\n          selectClause,\n          `$selected`,\n        )\n      : clause.expression\n\n    return {\n      compiledExpression: compileExpression(clauseWithoutAggregates),\n      compare: makeComparator(buildCompareOptions(clause, collection)),\n    }\n  })\n  // The row holds source aliases and any projected aggregate under $selected.\n  const valueExtractor = (row: NamespacedRow & { $selected?: any }) => {\n    if (orderByClause.length > 1) {\n      return compiledOrderBy.map((compiled) => compiled.compiledExpression(row))\n    }\n    return orderByClause.length === 1\n      ? compiledOrderBy[0]!.compiledExpression(row)\n      : null\n  }\n\n  // Compile comparators once; each row comparison reads the same options.\n  const compare =\n    compiledOrderBy.length <= 1\n      ? (compiledOrderBy[0]?.compare ?? defaultComparator)\n      : (a: unknown, b: unknown) => {\n          const arrayA = a as Array<unknown>\n          const arrayB = b as Array<unknown>\n          for (let i = 0; i < compiledOrderBy.length; i++) {\n            const result = compiledOrderBy[i]!.compare(arrayA[i], arrayB[i])\n            if (result !== 0) return result\n          }\n          return arrayA.length - arrayB.length\n        }\n\n  let setSizeCallback: SetSizeCallback | undefined\n\n  let orderByOptimizationInfo: OrderByOptimizationInfo | undefined\n\n  // When there's a limit, create orderByOptimizationInfo for top-K source\n  // loading. Unbounded queries use subscription hints instead. A plan whose\n  // local semantics cannot be established from a provider prefix records\n  // requiresFullSource and issues one filtered full-source acquisition.\n  // We try to use an index on the FIRST orderBy column for lazy loading,\n  // even for multi-column orderBy (using wider bounds on first column).\n  // Skip this optimization when using grouped ordering (includes with limit),\n  // because the limit is per-group, not global — the child collection needs all data loaded.\n  if (\n    limit !== undefined &&\n    orderByClause.length > 0 &&\n    !groupKeyFn &&\n    rawQuery.from.type !== `unionFrom` &&\n    rawQuery.from.type !== `unionAll`\n  ) {\n    let index: IndexReader<string | number> | undefined\n    let followRefCollection: Collection | undefined\n    let orderByAlias: string = rawQuery.from.alias\n    let orderBySourceId: string | undefined\n\n    // Try to create/find an index on the FIRST orderBy column for lazy loading\n    const firstClause = orderByClause[0]!\n    const firstOrderByExpression = firstClause.expression\n\n    const followRefResult =\n      firstOrderByExpression.type === `ref`\n        ? followRef(rawQuery, firstOrderByExpression, collection)\n        : undefined\n    if (firstOrderByExpression.type === `ref` && followRefResult) {\n      followRefCollection = followRefResult.collection\n      orderBySourceId = followRefResult.sourceId\n      const fieldName = followRefResult.path[0]\n      // The query's first source defines implicit string collation for the\n      // whole order. Build the source index with that same resolved term so\n      // provider admission cannot disagree with emitted query order.\n      const compareOpts = buildCompareOptions(firstClause, collection)\n\n      if (fieldName) {\n        ensureIndexForField(\n          fieldName,\n          followRefResult.path,\n          followRefCollection,\n          compareOpts,\n          supportsOrderedIndexStructure,\n        )\n      }\n\n      index = findIndexForField(\n        followRefCollection,\n        followRefResult.path,\n        compareOpts,\n        supportsOrderedRange,\n      )\n\n      warnOrderIndexFallback(\n        followRefCollection,\n        followRefResult.path,\n        compareOpts,\n        index,\n      )\n\n      orderByAlias =\n        firstOrderByExpression.path.length > 1\n          ? String(firstOrderByExpression.path[0])\n          : rawQuery.from.alias\n      orderBySourceId ??= collectCollectionSources(rawQuery).find(\n        (source) =>\n          source.alias === orderByAlias &&\n          source.collection === followRefCollection,\n      )?.sourceId\n    }\n\n    if (orderBySourceId && followRefResult) {\n      const sourceOrderBy = resolveOrderBy(\n        orderByClause,\n        collection.compareOptions,\n      )\n      const sourceOrderIsDirect = orderByClause.every(({ expression }) => {\n        if (expression.type !== `ref`) return false\n        return (\n          followRef(rawQuery, expression, collection)?.sourceId ===\n          orderBySourceId\n        )\n      })\n      const extract = compileExpression(\n        new PropRef(followRefResult.path),\n        true,\n      ) as CompiledSingleRowExpression\n      const compareTerm = makeComparator(sourceOrderBy[0]!.compareOptions)\n      const compareSourceRows = (\n        a: Record<string, unknown> | null | undefined,\n        b: Record<string, unknown> | null | undefined,\n      ) => compareTerm(a ? extract(a) : a, b ? extract(b) : b)\n      const hasCrossAliasWhere =\n        rawQuery.where?.some((where) =>\n          [...getSourceAliasesFromExpression(getWhereExpression(where))].some(\n            (alias) => alias !== orderByAlias,\n          ),\n        ) ?? false\n      const joinedFilterSourceId =\n        hasCrossAliasWhere &&\n        rawQuery.join?.length === 1 &&\n        rawQuery.join[0]!.type === `left` &&\n        rawQuery.join[0]!.from.type === `collectionRef`\n          ? rawQuery.join[0]!.from.sourceId\n          : undefined\n\n      const info: OrderByOptimizationInfo = {\n        sourceId: orderBySourceId,\n        alias: orderByAlias,\n        offset: offset ?? 0,\n        limit,\n        comparator: compareSourceRows,\n        valueExtractorForRawRow: extract,\n        index,\n        orderBy: sourceOrderBy,\n        joinedFilterSourceIds: joinedFilterSourceId\n          ? [joinedFilterSourceId]\n          : undefined,\n        sourceHoldsAllRows:\n          followRefResult.collection.config.syncMode !== `on-demand`,\n        requiresFullSource:\n          sourceOrderBy.some(\n            ({ compareOptions }) => compareOptions.stringSort === `custom`,\n          ) ||\n          !sourceOrderIsDirect ||\n          rawQuery.from.type !== `collectionRef` ||\n          rawQuery.from.sourceId !== orderBySourceId ||\n          // Only a LEFT join keeps every root row of a bounded prefix and\n          // adds no row the prefix cannot place: inner and cross joins drop\n          // root rows, and right, full and outer joins add joined rows whose\n          // root match may sit past the prefix.\n          (rawQuery.join?.some(({ type }) => type !== `left`) ?? false) ||\n          (rawQuery.where?.some(isResidualWhere) ?? false) ||\n          (hasCrossAliasWhere && joinedFilterSourceId === undefined) ||\n          (rawQuery.fnWhere?.length ?? 0) > 0 ||\n          rawQuery.groupBy !== undefined ||\n          rawQuery.having !== undefined ||\n          rawQuery.fnHaving !== undefined ||\n          rawQuery.distinct === true,\n      }\n      orderByOptimizationInfo = info\n\n      // Ordered loading is owned by one lexical source. A collection can occur\n      // more than once in a query tree, so collection ID and alias are not\n      // sufficient identities here.\n      const previous = optimizableOrderByCollections[orderBySourceId]\n      // One lexical source can feed separate authored/source metadata views.\n      // Each top-K owns its own window. Acquisition must cover all windows,\n      // including moves made through a previously compiled root's callback.\n      // Keep these reads live: setWindowFn updates the individual info objects.\n      optimizableOrderByCollections[orderBySourceId] = previous\n        ? {\n            ...info,\n            joinedFilterSourceIds: [\n              ...new Set([\n                ...(previous.joinedFilterSourceIds ?? []),\n                ...(info.joinedFilterSourceIds ?? []),\n              ]),\n            ],\n            get offset() {\n              return Math.min(previous.offset, info.offset)\n            },\n            get limit() {\n              return (\n                Math.max(\n                  previous.offset + previous.limit,\n                  info.offset + info.limit,\n                ) - this.offset\n              )\n            },\n            // Plan shape is fixed at compilation; only window bounds move.\n            requiresFullSource:\n              !deepEquals(previous.orderBy, info.orderBy) ||\n              previous.requiresFullSource ||\n              info.requiresFullSource,\n            dataNeeded: (boundary) =>\n              Math.max(\n                previous.dataNeeded?.(boundary) ?? 0,\n                info.dataNeeded?.(boundary) ?? 0,\n              ),\n          }\n        : info\n\n      // loadMoreIfNeeded reads how many rows the window needs. Without an\n      // index, only an on-demand joined filter can leave the window short.\n      const needsCount =\n        joinedFilterSourceId !== undefined && !info.sourceHoldsAllRows\n      if (index || needsCount) {\n        setSizeCallback = (getSize) => {\n          info.dataNeeded = (boundary) => {\n            // Window rows at or before the boundary are a leading run of\n            // the window order.\n            const size = getSize(\n              boundary &&\n                ((row) =>\n                  compareSourceRows(\n                    (row as NamespacedRow)[orderByAlias],\n                    boundary,\n                  ) <= 0),\n            )\n            return Math.max(0, info.limit - size)\n          }\n        }\n      }\n    }\n  }\n\n  const options = {\n    limit,\n    offset,\n    comparator: compare,\n    setSizeCallback,\n    setWindowFn: (windowFn: (options: WindowOptions) => void) => {\n      // Keep demand calculations aligned with the operator's current window.\n      setWindowFn((window) => {\n        windowFn(window)\n        if (orderByOptimizationInfo) {\n          orderByOptimizationInfo.offset =\n            window.offset ?? orderByOptimizationInfo.offset\n          orderByOptimizationInfo.limit =\n            window.limit ?? orderByOptimizationInfo.limit\n        }\n      })\n    },\n  }\n  return pipeline.pipe(\n    groupKeyFn\n      ? groupedOrderByWithFractionalIndex(valueExtractor, {\n          ...options,\n          groupKeyFn,\n        })\n      : orderByWithFractionalIndex(valueExtractor, options),\n  )\n}\n\n/**\n * Builds a comparison configuration object that uses the values provided in the orderBy clause.\n * If no string sort configuration is provided it defaults to the collection's string sort configuration.\n * Multi-source FROM queries pass their first source collection here as the\n * documented default. Use explicit orderBy compare options when branches need\n * different string collation behavior.\n */\nexport function buildCompareOptions(\n  clause: OrderByClause,\n  collection: CollectionLike<any, any>,\n): CompareOptions {\n  return resolveCompareOptions(clause, collection.compareOptions)\n}\n\nfunction resolveOrderBy(\n  orderBy: OrderBy,\n  defaults: CollectionLike[`compareOptions`],\n): OrderBy {\n  return orderBy.map((clause) => ({\n    expression: clause.expression,\n    compareOptions: resolveCompareOptions(clause, defaults),\n  }))\n}\n\nfunction resolveCompareOptions(\n  clause: OrderByClause,\n  defaults: CollectionLike[`compareOptions`],\n): CompareOptions {\n  return clause.compareOptions.stringSort === undefined\n    ? {\n        ...defaults,\n        direction: clause.compareOptions.direction,\n        nulls: clause.compareOptions.nulls,\n      }\n    : clause.compareOptions\n}\n"],"mappings":";;;;;;;;;;AAyEA,SAAS,uBACP,YACA,MACA,SACA,OACM;CACN,IAAI,sCAAA,SAAS,KAAA,QAAA,IAAA,aAA8B,cAAc;EACvD,MAAM,QAAQ,KAAK,KAAK,GAAG;EAC3B,MAAM,SAAS,gBAAgB,WAAW,KAAK,KAAK,WAAW,GAAA,KAAQ,GAAA;EACvE,IAAI,QAAQ,eAAe,UAAU;GACnC,QAAQ,KACN,GAAG,OAAA,uCAA8C,MAAA,oMACnD;GACA;EACF;EACA,IAAIA,sBAAAA,mBAAmB,IAAI,GAAG;GAC5B,QAAQ,KACN,GAAG,OAAA,yBAAgC,MAAA,yGACrC;GACA;EACF;EACA,IAAI,OAAO;EAEX,MAAM,eAAe,CAAC,GAAG,WAAW,QAAQ,OAAO,CAAC,CAAA,CAAE,QAAQ,cAC5D,UAAU,aAAa,IAAI,CAC7B;EACA,IAAI;EACJ,IAAI,aAAa,WAAW,GAC1B,SAAS,yBAAyB,MAAA,6EAAmF,MAAA;OAAA,IAErH,aAAa,OACV,cAAc,CAAC,UAAU,sBAAsB,OAAO,CACzD,GAEA,SAAS,sBAAsB,MAAA,uDAA6D,QAAQ,MAAA,kBAAwB,QAAQ,cAAc,SAAA,GAAY,QAAQ,eAAe,WAAW,kDAAkD,GAAA,6FAAgG,MAAA,oFAA0F,QAAQ,MAAA,kBAAwB,QAAQ,cAAc,SAAA;OAEle,SAAS,sBAAsB,MAAA;EAEjC,QAAQ,KACN,GAAG,OAAA,GAAU,OAAA,iHACf;CACF;AACF;AAOA,SAAg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