UNPKG

@matthew.ngo/react-filter-pilot

Version:

Powerful filtering, pagination, and sorting for React with TanStack Query integration

1 lines 4.53 kB
{"version":3,"sources":["../../src/compat/tanstack-query.ts"],"names":["normalizeQueryOptions","options","normalized","__name","detectTanStackQueryVersion","QueryClient","createQueryOptions","baseOptions","version","cacheTime","rest","gcTime","createInfiniteQueryOptions","queryOptions"],"mappings":";AAiBO,IAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,YAAA,CAAA,IAAA,CAAA,CAAA,CAAA,SAASA,CAAsBC,CAAAA,CAAAA,CAAiD,CACrF,MAAMC,EAAa,CAAE,GAAGD,CAAQ,CAAA,CAGhC,OAAIC,CAAAA,CAAW,MAAW,GAAA,MAAA,EAAaA,EAAW,SAAc,GAAA,MAAA,GAC9DA,CAAW,CAAA,MAAA,CAASA,CAAW,CAAA,SAAA,CAAA,CAI7BA,CAAW,CAAA,SAAA,GAAc,QAAaA,CAAW,CAAA,MAAA,GAAW,MAC9DA,GAAAA,CAAAA,CAAW,SAAYA,CAAAA,CAAAA,CAAW,MAG7BA,CAAAA,CAAAA,CACT,CAdgBC,CAAAH,CAAAA,CAAAA,CAAA,uBAmBT,CAAA,CAAA,SAASI,CAAoD,EAAA,CAClE,GAAI,CAGF,KAAM,CAAE,WAAA,CAAAC,CAAY,CAAA,CAAI,OAAQ,CAAA,uBAAuB,CAMvD,CAAA,OAAI,WAHW,IAAIA,CAAAA,EAGK,CAAA,iBAAA,EAAoB,CAAA,OAAA,EAAW,EAAC,CAAA,CAC/C,IAGF,GACT,CAAA,KAAQ,CACN,OAAO,SACT,CACF,CAlBgBF,CAAAC,CAAAA,CAAAA,CAAA,8BAuBT,SAASE,CAAAA,CACdC,CACAC,CAAAA,CAAAA,CAAiCJ,CAA2B,EAAA,CACvD,CACL,MAAMF,EAAaF,CAAsBO,CAAAA,CAAW,CAEpD,CAAA,GAAIC,CAAY,GAAA,GAAA,CAAK,CAEnB,KAAM,CAAE,SAAAC,CAAAA,CAAAA,CAAW,GAAGC,CAAK,CAAIR,CAAAA,CAAAA,CAC/B,OAAOQ,CACT,SAAWF,CAAY,GAAA,GAAA,CAAK,CAE1B,KAAM,CAAE,MAAAG,CAAAA,CAAAA,CAAQ,GAAGD,CAAK,EAAIR,CAC5B,CAAA,OAAOQ,CACT,CAGA,OAAOR,CACT,CAlBgBC,CAAAA,CAAAG,EAAA,oBAuBT,CAAA,CAAA,SAASM,CACdL,CAAAA,CAAAA,CACAC,CAAiCJ,CAAAA,CAAAA,EAC5B,CAAA,CACL,MAAMS,CAAeP,CAAAA,CAAAA,CAAmBC,CAAaC,CAAAA,CAAO,CAG5D,CAAA,OAAIA,CAAY,GAAA,GAAA,CAEP,CACL,GAAGK,CAAAA,CACH,gBAAkBN,CAAAA,CAAAA,CAAY,kBAAoB,IACpD,CAAA,CAIKM,CACT,CAjBgBV,EAAAS,CAAA,CAAA,4BAAA,CAAA","file":"tanstack-query.cjs","sourcesContent":["/**\n * Compatibility layer for TanStack Query v4 and v5\n * \n * This file provides helpers to ensure the package works with both versions\n */\n\n// Type to handle both v4 (cacheTime) and v5 (gcTime) naming\nexport interface QueryOptionsCompat {\n staleTime?: number;\n cacheTime?: number; // v4\n gcTime?: number; // v5\n [key: string]: any;\n}\n\n/**\n * Normalize query options for compatibility\n */\nexport function normalizeQueryOptions(options: QueryOptionsCompat): QueryOptionsCompat {\n const normalized = { ...options };\n \n // If gcTime is not provided but cacheTime is, use cacheTime as gcTime (for v5)\n if (normalized.gcTime === undefined && normalized.cacheTime !== undefined) {\n normalized.gcTime = normalized.cacheTime;\n }\n \n // If cacheTime is not provided but gcTime is, use gcTime as cacheTime (for v4)\n if (normalized.cacheTime === undefined && normalized.gcTime !== undefined) {\n normalized.cacheTime = normalized.gcTime;\n }\n \n return normalized;\n}\n\n/**\n * Helper to detect TanStack Query version\n */\nexport function detectTanStackQueryVersion(): '4' | '5' | 'unknown' {\n try {\n // This is a simplified detection - in a real implementation,\n // you might check the actual package version\n const { QueryClient } = require('@tanstack/react-query');\n \n // v5 has different method signatures\n const client = new QueryClient();\n \n // Check for v5-specific methods or properties\n if ('gcTime' in (client.getDefaultOptions().queries || {})) {\n return '5';\n }\n \n return '4';\n } catch {\n return 'unknown';\n }\n}\n\n/**\n * Create version-specific query options\n */\nexport function createQueryOptions(\n baseOptions: QueryOptionsCompat,\n version: '4' | '5' | 'unknown' = detectTanStackQueryVersion()\n): any {\n const normalized = normalizeQueryOptions(baseOptions);\n \n if (version === '5') {\n // For v5, prefer gcTime\n const { cacheTime, ...rest } = normalized;\n return rest;\n } else if (version === '4') {\n // For v4, prefer cacheTime\n const { gcTime, ...rest } = normalized;\n return rest;\n }\n \n // For unknown version, include both\n return normalized;\n}\n\n/**\n * Version-agnostic infinite query options\n */\nexport function createInfiniteQueryOptions(\n baseOptions: any,\n version: '4' | '5' | 'unknown' = detectTanStackQueryVersion()\n): any {\n const queryOptions = createQueryOptions(baseOptions, version);\n \n // Handle differences in infinite query options between versions\n if (version === '5') {\n // v5 specific adjustments\n return {\n ...queryOptions,\n initialPageParam: baseOptions.initialPageParam ?? null,\n };\n }\n \n // v4 format\n return queryOptions;\n}"]}