UNPKG

@tanstack/react-db

Version:

React integration for @tanstack/db

1 lines • 1.39 kB
{"version":3,"file":"source-id-bindings.cjs","sources":["../../src/source-id-bindings.ts"],"sourcesContent":["import { getPreparedLiveQuerySources } from '@tanstack/db'\nimport type { DbClient } from '@tanstack/db'\n\n/**\n * Reports a descriptor source that no DbClient bound, naming the provider a\n * React tree needs. Returns `undefined` when a client can bind descriptors.\n */\nexport function getUnboundDescriptorReporter(\n client: DbClient | undefined,\n hookName: string,\n): ((alias: string) => never) | undefined {\n if (client) return undefined\n return (alias) => {\n throw new Error(\n `[${hookName}] Collection descriptor \"${alias}\" requires a DbClient when the query is consumed. Wrap this component in <DbProvider client={client}> or use a concrete Collection.`,\n )\n }\n}\n\nexport function getPreparedSources(\n preparedValue: unknown,\n client: DbClient | undefined,\n hookName: string,\n): Array<{ id: string }> {\n return getPreparedLiveQuerySources(\n preparedValue,\n getUnboundDescriptorReporter(client, hookName),\n )\n}\n"],"names":["getPreparedLiveQuerySources"],"mappings":";;;AAOO,SAAS,6BACd,QACA,UACwC;AACxC,MAAI,OAAQ,QAAO;AACnB,SAAO,CAAC,UAAU;AAChB,UAAM,IAAI;AAAA,MACR,IAAI,QAAQ,4BAA4B,KAAK;AAAA,IAAA;AAAA,EAEjD;AACF;AAEO,SAAS,mBACd,eACA,QACA,UACuB;AACvB,SAAOA,GAAAA;AAAAA,IACL;AAAA,IACA,6BAA6B,QAAQ,QAAQ;AAAA,EAAA;AAEjD;;;"}