@tanstack/db
Version:
A reactive client store for building super fast apps on sync
1 lines • 2.11 kB
Source Map (JSON)
{"version":3,"file":"collection-registry.cjs","names":["LIVE_QUERY_INTERNAL"],"sources":["../../../../src/query/live/collection-registry.ts"],"sourcesContent":["import { LIVE_QUERY_INTERNAL } from './internal.js'\nimport type { Collection } from '../../collection/index.js'\nimport type { CollectionConfigBuilder } from './collection-config-builder.js'\n\nconst collectionBuilderRegistry = new WeakMap<\n Collection<any, any, any>,\n CollectionConfigBuilder<any, any>\n>()\n\n/**\n * Retrieves the builder attached to a config object via its internal utils.\n *\n * @param config - The collection config object\n * @returns The attached builder, or `undefined` if none exists\n */\nexport function getBuilderFromConfig(\n config: object,\n): CollectionConfigBuilder<any, any> | undefined {\n return (config as any).utils?.[LIVE_QUERY_INTERNAL]?.getBuilder?.()\n}\n\n/**\n * Registers a builder for a collection in the global registry.\n * Used to detect when a live query depends on another live query,\n * enabling the scheduler to ensure parent queries run first.\n *\n * @param collection - The collection to register the builder for\n * @param builder - The builder that produces this collection\n */\nexport function registerCollectionBuilder(\n collection: Collection<any, any, any>,\n builder: CollectionConfigBuilder<any, any>,\n): void {\n collectionBuilderRegistry.set(collection, builder)\n}\n\n/**\n * Retrieves the builder registered for a collection.\n * Used to discover dependencies when a live query subscribes to another live query.\n *\n * @param collection - The collection to look up\n * @returns The registered builder, or `undefined` if none exists\n */\nexport function getCollectionBuilder(\n collection: Collection<any, any, any>,\n): CollectionConfigBuilder<any, any> | undefined {\n return collectionBuilderRegistry.get(collection)\n}\n"],"mappings":";AAIA,IAAM,4CAA4B,IAAI,QAGpC;AAQF,SAAgB,qBACd,QAC+C;CAC/C,OAAQ,OAAe,QAAQA,iBAAAA,oBAAAA,EAAsB,aAAa;AACpE;AAUA,SAAgB,0BACd,YACA,SACM;CACN,0BAA0B,IAAI,YAAY,OAAO;AACnD;AASA,SAAgB,qBACd,YAC+C;CAC/C,OAAO,0BAA0B,IAAI,UAAU;AACjD"}