@tanstack/db
Version:
A reactive client store for building super fast apps on sync
1 lines • 24.2 kB
Source Map (JSON)
{"version":3,"file":"live-query-options.cjs","names":["InvalidPoolOptionError","isFailedStatus","BaseQueryBuilder","isCollection","collectSourceRefs","requireCollectionSource","LIVE_QUERY_INTERNAL","getStableQueryBuilderHash","getStringCollationIdentity","getBuilderFromConfig","getStableValueHash","getQueryIdentity","UnhashableQueryIRError","createLiveQueryCollection","codedMessage","config","identity"],"sources":["../../src/live-query-options.ts"],"sourcesContent":["import { BaseQueryBuilder } from './query/builder/index.js'\nimport { collectSourceRefs, requireCollectionSource } from './query/ir.js'\nimport { isCollection, isFailedStatus } from './live-query-primitives.js'\nimport {\n DEFAULT_GC_TIME_MS,\n UNSUBSCRIBED_GC_FLOOR_MS,\n} from './collection/lifecycle.js'\nimport { createLiveQueryCollection } from './query/live-query-collection.js'\nimport { LIVE_QUERY_INTERNAL } from './query/live/internal.js'\nimport { getBuilderFromConfig } from './query/live/collection-registry.js'\nimport {\n getQueryIdentity,\n getStableQueryBuilderHash,\n getStableValueHash,\n} from './query/ir-stable-identity.js'\nimport { getStringCollationIdentity } from './query/runtime-reference-identity.js'\nimport { codedMessage, devBuild } from './error-message.js'\nimport { InvalidPoolOptionError, UnhashableQueryIRError } from './errors.js'\nimport type { Collection, CollectionImpl } from './collection/index.js'\nimport type { CollectionOptions, DbClient } from './client.js'\nimport type { PooledLiveQueries } from './query/pooled-live-query.js'\nimport type {\n Context,\n InitialQueryBuilder,\n LiveQueryCollectionConfig,\n LiveQueryHookConfig,\n QueryBuilder,\n} from './query/index.js'\n\n/**\n * A hook config's pool: `pooledLiveQueries` or nothing. Any other value, such\n * as the removed boolean form, contradicts the hook contract, so every reader\n * rejects it the same way, whatever the config's other options. An adapter\n * that reads the pool from its own options, as Angular does, checks it here.\n */\nexport function configPool(config: object): PooledLiveQueries | undefined {\n const { pool } = config as { pool?: unknown }\n if (\n pool !== undefined &&\n typeof (pool as Partial<PooledLiveQueries> | null)\n ?.createPooledLiveQuery !== `function`\n )\n throw new InvalidPoolOptionError()\n return pool as PooledLiveQueries | undefined\n}\n\nexport type LiveQueryKey = ReadonlyArray<unknown>\n\nexport type LiveQueryOptions = LiveQueryCollectionConfig<any> & {\n queryKey?: LiveQueryKey\n}\n\nexport type DeferredLiveQueryCollections = Set<\n CollectionImpl<any, string | number, any, any, any>\n>\n\n/**\n * Release the sync starts a rejected query input deferred, then rethrow its\n * rejection. A framework hook calls this around its own render work, so a\n * query the hook rejects leaves no source deferred and a later reader can\n * start it. A render that throws after the hook returns, such as in a sibling\n * hook, is not a rejection of this input: like any render that never commits,\n * it releases its deferral through `releaseDeferredOnReclaim` when garbage\n * collection reclaims its live query. As for a\n * `DbClient` preload, the rejection wins over a source whose resumed start\n * fails; that source records its own failure.\n */\nexport function rejectLiveQueryInput(\n collections: DeferredLiveQueryCollections | undefined,\n rejection: unknown,\n): never {\n try {\n if (collections) resumeDeferredLiveQueryCollections(collections)\n } catch {\n // Report the rejection, not a later start failure.\n }\n throw rejection\n}\n\n/**\n * Release a render's deferred sync starts when the live query it built is\n * reclaimed. A render that commits releases them first, when it subscribes.\n * A render that never commits, because a sibling threw or it suspended, leaves\n * its live query unsubscribed until garbage collection cleans it up; that\n * cleanup releases the starts, so a direct reader's demand, made before or\n * after, then starts the sources. A live query that garbage collection never\n * reclaims, because its config disables GC or does not start its sync,\n * releases after the unsubscribed GC floor instead. Releases only the starts\n * deferred so far, not ones a later render of the same hook defers. Pass only\n * a live query the render built, and call the returned function when the\n * render commits, so a committed hook keeps no listener, timer, or copied\n * sources.\n */\nexport function releaseDeferredOnReclaim(\n liveQuery: Pick<Collection<any, any, any>, `once` | `config` | `status`>,\n deferredCollections: DeferredLiveQueryCollections,\n): (() => void) | undefined {\n if (deferredCollections.size === 0) return undefined\n const pending: DeferredLiveQueryCollections = new Set(deferredCollections)\n const release = () => {\n try {\n resumeDeferredLiveQueryCollections(pending)\n } catch {\n // A source whose resumed start fails records its own failure.\n }\n }\n // The lifecycle's own rule: GC reclaims only a started collection with a\n // finite, positive gcTime.\n const gcTime = liveQuery.config.gcTime ?? DEFAULT_GC_TIME_MS\n if (gcTime > 0 && Number.isFinite(gcTime) && liveQuery.status !== `idle`) {\n return liveQuery.once(`status:cleaned-up`, release)\n }\n const timer = setTimeout(release, UNSUBSCRIBED_GC_FLOOR_MS)\n return () => clearTimeout(timer)\n}\n\n/** Release every deferred source, then report the first startup failure. */\nexport function resumeDeferredLiveQueryCollections(\n collections: DeferredLiveQueryCollections,\n reportSourceErrors = false,\n): void {\n const pending = Array.from(collections)\n collections.clear()\n let firstFailure: { error: unknown } | undefined\n for (const collection of pending) {\n try {\n collection._resumeSyncStart()\n // An explicit preload owns source failure reporting even when graph\n // demand already released the gate. Ordinary hooks read the status.\n if (reportSourceErrors && isFailedStatus(collection.status)) {\n throw collection._lifecycle.getSyncError()\n }\n } catch (error) {\n firstFailure ??= { error }\n }\n }\n if (firstFailure) throw firstFailure.error\n}\n\ntype PreparedLiveQueryConfigInput = Omit<\n LiveQueryHookConfig<Context>,\n `query`\n> & {\n query:\n | QueryBuilder<Context>\n | ((q: InitialQueryBuilder) => QueryBuilder<Context> | undefined | null)\n queryKey?: LiveQueryKey\n client?: DbClient\n}\n\nexport function prepareLiveQueryValue(\n value: unknown,\n dbClient: DbClient | undefined,\n deferredCollections?: DeferredLiveQueryCollections,\n): unknown {\n if (typeof value === `function`) {\n return prepareLiveQueryValue(\n value(new BaseQueryBuilder() as InitialQueryBuilder),\n dbClient,\n deferredCollections,\n )\n }\n\n if (value instanceof BaseQueryBuilder) {\n return value._bindCollectionSources(\n dbClient\n ? (options) => {\n const config = options as CollectionOptions<\n any,\n string | number,\n any,\n any\n >\n const collection = (\n deferredCollections\n ? dbClient._materializeCollectionForRender(config)\n : dbClient.collection(config)\n ) as CollectionImpl<any, string | number, any, any, any>\n if (deferredCollections && collection._deferSyncStart())\n deferredCollections.add(collection)\n return collection\n }\n : undefined,\n )\n }\n\n if (\n value &&\n typeof value === `object` &&\n !isCollection(value) &&\n `query` in value\n ) {\n const pool = configPool(value)\n const {\n query,\n queryKey: _queryKey,\n client: _client,\n pool: _pool,\n ...config\n } = value as PreparedLiveQueryConfigInput\n\n const preparedQuery = prepareLiveQueryValue(\n query,\n dbClient,\n deferredCollections,\n )\n\n if (preparedQuery === undefined || preparedQuery === null) {\n return preparedQuery\n }\n\n return {\n ...config,\n // A DbClient query never pools, so its identity must not depend on\n // pool: a server preload and a client hook must hash alike.\n ...(pool && !dbClient ? { pool } : {}),\n query: preparedQuery,\n }\n }\n\n return value\n}\n\n/** Concrete source objects in query-position order for a prepared value. */\nexport function getPreparedLiveQuerySources(\n value: unknown,\n onUnboundDescriptor?: (alias: string) => never,\n): Array<Collection> {\n if (isCollection(value)) return [value]\n const query = queryConfig(value)?.query ?? value\n if (query instanceof BaseQueryBuilder) {\n return collectSourceRefs(query._getQuery()).map((source) =>\n source.type === `descriptorRef` && onUnboundDescriptor\n ? onUnboundDescriptor(source.alias)\n : requireCollectionSource(source),\n )\n }\n return isCollection(query) ? [query] : []\n}\n\n/** Local row behavior, kept separate from the portable query identity. */\nexport type LiveQueryRowOptions = readonly [getKey: unknown, schema: unknown]\n\nexport function getLiveQueryRowOptions(value: unknown): LiveQueryRowOptions {\n if (isCollection(value)) {\n const { config } = value\n const internal = config.utils?.[LIVE_QUERY_INTERNAL] as\n { hasCustomGetKey?: boolean } | undefined\n return [\n internal?.hasCustomGetKey ? config.getKey : undefined,\n config.schema,\n ]\n }\n const config = value as\n { getKey?: unknown; schema?: unknown } | null | undefined\n return [config?.getKey, config?.schema]\n}\n\nexport function getPreparedLiveQueryIdentity(\n value: unknown,\n pool?: PooledLiveQueries,\n): unknown {\n if (isCollection(value)) return [`collection`, value.id]\n if (value instanceof BaseQueryBuilder) {\n // A pooled query's fields and literals identify its rows without\n // canonicalizing its whole IR on every render.\n const pooled = pool?.getPooledQueryIdentity(value)\n return pooled === undefined\n ? [`query`, getStableQueryBuilderHash(value)]\n : [`pooled`, pooled]\n }\n if (value && typeof value === `object` && `query` in value) {\n const config = value as LiveQueryCollectionConfig<any>\n return [\n // getKey and schema bind for this query identity. Inline options must\n // not turn a normal framework render into a new Collection.\n `config`,\n getPreparedLiveQueryIdentity(config.query, configPool(config)),\n [`singleResult`, config.singleResult === true],\n [\n `defaultStringCollation`,\n getStringCollationIdentity(config.defaultStringCollation),\n ],\n ]\n }\n if (value === undefined || value === null) return [`disabled`]\n return [`value`, value]\n}\n\nexport function getLiveQueryHash(\n preparedValue: unknown,\n queryKey?: LiveQueryKey,\n): string {\n if (queryKey?.length) {\n const query = queryConfig(preparedValue)?.query\n const ir = isCollection(preparedValue)\n ? getBuilderFromConfig(preparedValue.config)?.getWindow()\n : query instanceof BaseQueryBuilder\n ? query._getQuery()\n : undefined\n const identity: Array<unknown> = [`queryKey`, queryKey]\n if (ir && (ir.limit !== undefined || (ir.offset ?? 0) !== 0))\n identity.push({ limit: ir.limit, offset: ir.offset ?? 0 })\n return getStableValueHash(identity, `queryKey`)\n }\n const identity = isCollection(preparedValue)\n ? [`collection`, preparedValue.id]\n : [`derived`, getPreparedLiveQueryIdentity(preparedValue)]\n\n return getStableValueHash(identity, `queryKey`)\n}\n\n// Each entry belongs to one framework binding or an unclaimed retry resource.\n// DbClient snapshots remain separate; peers never share a mutable window owner.\nconst resolvedQueryValues = new WeakMap<\n object,\n { collection: object; config: NonNullable<ReturnType<typeof queryConfig>> }\n>()\n\nfunction queryConfig(\n value: unknown,\n): (Record<string, unknown> & { query?: unknown }) | undefined {\n return value instanceof BaseQueryBuilder\n ? { query: value }\n : value && typeof value === `object`\n ? (value as Record<string, unknown>)\n : undefined\n}\n\nfunction moveExistingWindow(\n after: ReturnType<typeof queryConfig>,\n previous: Collection<object, string | number, {}> | null | undefined,\n owner: object | undefined,\n) {\n if (\n !previous ||\n (previous.status !== `ready` && previous.status !== `loading`)\n )\n return\n const retained = owner && resolvedQueryValues.get(owner)\n if (!retained || retained.collection !== previous) return\n const before = retained.config\n if (\n !(before.query instanceof BaseQueryBuilder) ||\n !(after?.query instanceof BaseQueryBuilder)\n )\n return\n const oldQuery = before.query._getQuery()\n const query = after.query._getQuery()\n const limit = query.limit\n const offset = query.offset ?? 0\n // Adding/removing the outer limit, findOne, and opaque plans keep their\n // ordinary compilation path. A move needs a finite ordered target window.\n if (\n after.singleResult === true ||\n query.singleResult ||\n !query.orderBy?.length ||\n oldQuery.limit === undefined ||\n limit === undefined ||\n !Number.isSafeInteger(limit) ||\n limit < 0 ||\n !Number.isSafeInteger(offset) ||\n offset < 0\n )\n return\n const keys = Object.keys(before)\n if (\n keys.length !== Object.keys(after).length ||\n keys.some((key) => key !== `query` && before[key] !== after[key])\n )\n return\n // IR source IDs establish semantic identity, but a keyed query may legally\n // swap the object under an ID. Reuse must preserve the exact source objects.\n const sources = getPreparedLiveQuerySources(before)\n const nextSources = getPreparedLiveQuerySources(after)\n if (\n sources.length !== nextSources.length ||\n sources.some((source, index) => source !== nextSources[index])\n )\n return\n try {\n if (\n getQueryIdentity({ ...oldQuery, limit: undefined, offset: undefined }) !==\n getQueryIdentity({ ...query, limit: undefined, offset: undefined })\n )\n return\n } catch (error) {\n if (error instanceof UnhashableQueryIRError) return\n throw error\n }\n const builder = getBuilderFromConfig(previous.config)\n if (!builder) return\n return () => {\n // A framework can commit synchronously from a Collection publication\n // callback. Move after that publication, while this remains the binding's\n // last resolved result and a consumer still asks for it.\n queueMicrotask(() => {\n if (\n resolvedQueryValues.get(owner)?.collection !== previous ||\n previous.subscriberCount === 0\n )\n return\n const result = builder.setWindow({ offset, limit })\n // The Collection reports request failures through its health tree. A\n // superseded move or unmount can reject its waiter without a hook caller.\n if (result !== true) void result.catch(() => {})\n })\n }\n}\n\n/**\n * Resolve an adapter's query value to what its observer watches: `null` for a\n * disabled query, an existing Collection with sync started, or a live query.\n * A query builder whose shape a shared partition can serve gets a pooled view\n * instead of its own live-query Collection.\n */\nexport function resolveLiveQueryValue(\n value: unknown,\n {\n gcTime,\n pool,\n startSync = true,\n previousCollection,\n windowOwner,\n onWindowChange,\n }: {\n gcTime?: number\n // `false` keeps a hook that cannot pool, such as a Suspense or DbClient\n // query, from pooling even when its config passes `pooledLiveQueries`.\n // A pool here has passed `configPool`.\n pool?: PooledLiveQueries | false\n startSync?: boolean\n /** @internal undefined skips window tracking; null starts an owned result. */\n previousCollection?: Collection<object, string | number, {}> | null\n /** @internal Identity of one framework binding; never shared by peers. */\n windowOwner?: object\n /** @internal React/Preact defer mutation until their render commits. */\n onWindowChange?: (move: () => void) => void\n } = {},\n): Collection<any, any, any> | null {\n if (previousCollection !== undefined)\n value = prepareLiveQueryValue(value, undefined)\n const input = queryConfig(value)\n const move = moveExistingWindow(input, previousCollection, windowOwner)\n if (move) {\n if (onWindowChange) onWindowChange(move)\n else move()\n return previousCollection!\n }\n if (value === undefined || value === null) return null\n if (isCollection(value)) {\n value.startSyncImmediate()\n return value\n }\n if (input) {\n const requested = configPool(input)\n const { pool: _pool, ...given } = input as LiveQueryHookConfig<any>\n const pooling = pool === false ? undefined : (requested ?? pool)\n // A pooled view needs the built query. Build a query function once and\n // compile the same builder if the partition cannot serve it.\n const built =\n pooling && typeof given.query === `function`\n ? given.query(new BaseQueryBuilder() as InitialQueryBuilder)\n : undefined\n const config =\n built instanceof BaseQueryBuilder ? { ...given, query: built } : given\n // A query and lifetime alone can pool; other options shape a Collection.\n const pooled =\n pooling &&\n config.query instanceof BaseQueryBuilder &&\n Object.keys(config).every((key) => key === `query` || key === `gcTime`)\n ? pooling.createPooledLiveQuery(config.query, {\n gcTime: config.gcTime ?? gcTime,\n })\n : undefined\n const collection =\n pooled ??\n createLiveQueryCollection({\n ...config,\n startSync: config.startSync ?? startSync,\n gcTime: config.gcTime ?? gcTime,\n })\n if (previousCollection !== undefined && windowOwner)\n resolvedQueryValues.set(windowOwner, { collection, config: input })\n return collection\n }\n throw new Error(\n devBuild() && process.env.NODE_ENV !== `production`\n ? `A live query must be a QueryBuilder, LiveQueryCollectionConfig, Collection,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