@tanstack/db
Version:
A reactive client store for building super fast apps on sync
1 lines • 2.72 kB
Source Map (JSON)
{"version":3,"file":"live-query-adapter.cjs","sources":["../../src/live-query-adapter.ts"],"sourcesContent":["import type { Collection } from './collection/index.js'\nimport type { CollectionStatus } from './types.js'\n\n/**\n * Shared helpers for the first-party framework adapters (`@tanstack/react-db`,\n * `@tanstack/vue-db`, `@tanstack/svelte-db`, `@tanstack/solid-db`,\n * `@tanstack/angular-db`).\n *\n * These centralize small pieces of logic every adapter used to duplicate, so\n * they stay consistent across frameworks. They are intended for the official\n * adapters; treat them as unstable for external use.\n */\n\n/**\n * Structural check for a live-query/`Collection` instance.\n *\n * Uses duck typing rather than `instanceof CollectionImpl` on purpose: adapters\n * and core can resolve to different copies of `@tanstack/db` (dual-package /\n * multi-realm), where `instanceof` gives false negatives. The three methods\n * below uniquely identify a Collection.\n */\nexport function isCollection(\n value: unknown,\n): value is Collection<any, any, any> {\n return (\n typeof value === `object` &&\n value !== null &&\n typeof (value as any).subscribeChanges === `function` &&\n typeof (value as any).startSyncImmediate === `function` &&\n typeof (value as any).id === `string`\n )\n}\n\n/** Whether a collection yields a single result (`findOne`) rather than an array. */\nexport function isSingleResultCollection(\n collection: Collection<any, any, any>,\n): boolean {\n return (\n (collection.config as { singleResult?: boolean } | undefined)\n ?.singleResult === true\n )\n}\n\n/** The derived boolean status flags every adapter exposes for a query. */\nexport interface LiveQueryStatusFlags {\n isLoading: boolean\n isReady: boolean\n isIdle: boolean\n isError: boolean\n isCleanedUp: boolean\n}\n\n/**\n * Derive the boolean status flags from a collection status. Adapters represent\n * a disabled query separately (with `isReady: true`); this covers the real\n * `CollectionStatus` values.\n */\nexport function getLiveQueryStatusFlags(\n status: CollectionStatus,\n): LiveQueryStatusFlags {\n return {\n isLoading: status === `loading`,\n isReady: status === `ready`,\n isIdle: status === `idle`,\n isError: status === `error`,\n isCleanedUp: status === `cleaned-up`,\n }\n}\n"],"names":[],"mappings":";;AAqBO,SAAS,aACd,OACoC;AACpC,SACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAc,qBAAqB,cAC3C,OAAQ,MAAc,uBAAuB,cAC7C,OAAQ,MAAc,OAAO;AAEjC;AAGO,SAAS,yBACd,YACS;AACT,SACG,WAAW,QACR,iBAAiB;AAEzB;AAgBO,SAAS,wBACd,QACsB;AACtB,SAAO;AAAA,IACL,WAAW,WAAW;AAAA,IACtB,SAAS,WAAW;AAAA,IACpB,QAAQ,WAAW;AAAA,IACnB,SAAS,WAAW;AAAA,IACpB,aAAa,WAAW;AAAA,EAAA;AAE5B;;;;"}