{"version":3,"file":"dexie-react-hooks.mjs","sources":["../src/useObservable.ts","../src/useLiveQuery.ts","../src/usePermissions.ts","../src/useDocument.ts","../src/usePromise.ts","../src/useSuspendingObservable.ts","../src/useSuspendingLiveQuery.ts"],"sourcesContent":["import React from 'react';\nexport interface InteropableObservable<T> {\n  subscribe(\n    onNext: (x: T) => any,\n    onError?: (error: any) => any\n  ): AnySubscription;\n  getValue?(): T; // For BehaviorSubject\n  hasValue?(): boolean; // For liveQuery observable returning false until a value is available\n}\n\nexport type AnySubscription = { unsubscribe(): any } | (() => any);\n\nexport function useObservable<T, TDefault>(\n  observable: InteropableObservable<T>\n): T | undefined;\nexport function useObservable<T, TDefault>(\n  observable: InteropableObservable<T>,\n  defaultResult: TDefault\n): T | TDefault;\nexport function useObservable<T>(\n  observableFactory: () => InteropableObservable<T>,\n  deps?: any[]\n): T | undefined;\nexport function useObservable<T, TDefault>(\n  observableFactory: () => InteropableObservable<T>,\n  deps: any[],\n  defaultResult: TDefault\n): T | TDefault;\nexport function useObservable<T, TDefault>(\n  observableFactory:\n    | InteropableObservable<T>\n    | (() => InteropableObservable<T>),\n  arg2?: any,\n  arg3?: any\n) {\n  // Resolve vars from overloading variants of this function:\n  let deps: any[];\n  let defaultResult: TDefault;\n  if (typeof observableFactory === 'function') {\n    deps = arg2 || [];\n    defaultResult = arg3;\n  } else {\n    deps = [];\n    defaultResult = arg2;\n  }\n\n  // Create a ref that keeps the state we need\n  const monitor = React.useRef({\n    hasResult: false,\n    result: defaultResult as T | TDefault,\n    error: null as any,\n  });\n  // We control when component should rerender. Make triggerUpdate\n  // as examplified on React's docs at:\n  // https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate\n  const [_, triggerUpdate] = React.useReducer((x) => x + 1, 0);\n\n  // Memoize the observable based on deps\n  const observable = React.useMemo(() => {\n    // Make it remember previous subscription's default value when\n    // resubscribing.\n    const observable =\n      typeof observableFactory === 'function'\n        ? observableFactory()\n        : observableFactory;\n    if (!observable || typeof observable.subscribe !== 'function') {\n      if (observableFactory === observable) {\n        throw new TypeError(\n          `Given argument to useObservable() was neither a valid observable nor a function.`\n        );\n      } else {\n        throw new TypeError(\n          `Observable factory given to useObservable() did not return a valid observable.`\n        );\n      }\n    }\n\n    if (!monitor.current.hasResult &&\n        typeof window !== 'undefined' // Don't do this in SSR\n       ) {\n      // Optimize for BehaviorSubject and other observables implementing getValue():\n      if (typeof observable.hasValue !== 'function' || observable.hasValue()) {\n        if (typeof observable.getValue === 'function') {\n          monitor.current.result = observable.getValue();\n          monitor.current.hasResult = true;\n        } else {\n          // Find out if the observable has a current value: try get it by subscribing and\n          // unsubscribing synchronously\n          const subscription = observable.subscribe((val) => {\n            monitor.current.result = val;\n            monitor.current.hasResult = true;\n          });\n          // Unsubscribe directly. We only needed any synchronous value if it was possible.\n          if (typeof subscription === 'function') {\n            subscription();\n          } else {\n            subscription.unsubscribe();\n          }\n        }\n      }\n    }\n    return observable;\n  }, deps);\n\n  // Integrate with react devtools:\n  React.useDebugValue(monitor.current.result);\n\n  // Subscribe to the observable\n  React.useEffect(() => {\n    const subscription = observable.subscribe(\n      (val) => {\n        const { current } = monitor;\n        if (current.error !== null || current.result !== val) {\n          current.error = null;\n          current.result = val;\n          current.hasResult = true;\n          triggerUpdate();\n        }\n      },\n      (err) => {\n        const { current } = monitor;\n        if (current.error !== err) {\n          current.error = err;\n          triggerUpdate();\n        }\n      }\n    );\n    return typeof subscription === 'function'\n      ? subscription // Support observables that return unsubscribe directly\n      : subscription.unsubscribe.bind(subscription);\n  }, deps);\n\n  // Throw if observable has emitted error so that\n  // an ErrorBoundrary can catch it\n  if (monitor.current.error) throw monitor.current.error;\n\n  // Return the current result\n  return monitor.current.result;\n}\n","import { Dexie } from 'dexie';\nimport { useObservable } from './useObservable';\n\nexport function useLiveQuery<T>(\n  querier: () => Promise<T> | T,\n  deps?: any[]\n): T | undefined;\nexport function useLiveQuery<T, TDefault>(\n  querier: () => Promise<T> | T,\n  deps: any[],\n  defaultResult: TDefault\n): T | TDefault;\nexport function useLiveQuery<T, TDefault>(\n  querier: () => Promise<T> | T,\n  deps?: any[],\n  defaultResult?: TDefault\n): T | TDefault {\n  return useObservable(\n    () => Dexie.liveQuery(querier),\n    deps || [],\n    defaultResult as TDefault\n  );\n}\n","import { Dexie } from 'dexie';\nimport { useObservable } from './useObservable';\n//import type { KeyPaths, TableProp } from 'dexie'; // Issue #1725 - not compatible with dexie@3.\n// Workaround: provide these types inline for now. When dexie 4 stable is out, we can use the types from dexie@4.\nexport type KeyPaths<T> = {\n  [P in keyof T]: \n    P extends string \n      ? T[P] extends Array<infer K>\n        ? K extends object // only drill into the array element if it's an object\n          ? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<K>}` \n          : P | `${P}.${number}`\n        : T[P] extends (...args: any[]) => any // Method\n           ? never \n          : T[P] extends object \n            ? P | `${P}.${KeyPaths<T[P]>}` \n            : P \n      : never;\n}[keyof T];\nexport type TableProp<DX extends Dexie> = {\n  [K in keyof DX]: DX[K] extends {schema: any, get: any, put: any, add: any, where: any} ? K : never;\n}[keyof DX] & string;\n\n\ninterface DexieCloudEntity {\n  table(): string;\n  realmId: string;\n  owner: string;\n}\n\nexport interface PermissionChecker<T, TableName extends string> {\n  add(...tableNames: TableName[]): boolean;\n  update(...props: KeyPaths<T>[]): boolean;\n  delete(): boolean;\n}\n\nexport function usePermissions<T extends DexieCloudEntity>(\n  entity: T\n): PermissionChecker<\n  T,\n  T extends { table: () => infer TableName } ? TableName : string\n>;\nexport function usePermissions<\n  TDB extends Dexie,\n  T\n>(db: TDB, table: TableProp<TDB>, obj: T): PermissionChecker<T, TableProp<TDB>>;\nexport function usePermissions(\n  firstArg:\n    | Dexie\n    | {\n        realmId?: string;\n        owner?: string;\n        table?: () => string;\n        readonly db?: Dexie;\n      },\n  table?: string,\n  obj?: { realmId?: string; owner?: string }\n) {\n  if (!firstArg)\n    throw new TypeError(\n      `Invalid arguments to usePermissions(): undefined or null`\n    );\n  let db: Dexie;\n  if (arguments.length >= 3) {\n    if (!('transaction' in firstArg)) {\n      // Using ducktyping instead of instanceof in case there are multiple Dexie modules in app.\n      // First arg is  ensures first arg is a Dexie instance\n      throw new TypeError(\n        `Invalid arguments to usePermission(db, table, obj): 1st arg must be a Dexie instance`\n      );\n    }\n    if (typeof table !== 'string')\n      throw new TypeError(\n        `Invalid arguments to usePermission(db, table, obj): 2nd arg must be string`\n      );\n    if (!obj || typeof obj !== 'object')\n      throw new TypeError(\n        `Invalid arguments to usePermission(db, table, obj): 3rd arg must be an object`\n      );\n    db = firstArg;\n  } else {\n    if (firstArg instanceof Dexie)\n      throw new TypeError(\n        `Invalid arguments to usePermission(db, table, obj): Missing table and obj arguments.`\n      );\n\n    if (\n      typeof firstArg.table === 'function' &&\n      typeof firstArg.db === 'object'\n    ) {\n      db = firstArg.db!;\n      obj = firstArg;\n      table = firstArg.table();\n    } else {\n      throw new TypeError(\n        `Invalid arguments to usePermissions(). ` +\n          `Expected usePermissions(entity: DexieCloudEntity) or ` +\n          `usePermissions(db: Dexie, table: string, obj: DexieCloudObject)`\n      );\n    }\n  }\n  if (!('cloud' in db))\n    throw new Error(\n      `usePermissions() is only for Dexie Cloud but there's no dexie-cloud-addon active in given db.`\n    );\n  if (!('permissions' in (db as any).cloud))\n    throw new Error(`usePermissions() requires a newer version of dexie-cloud-addon. Please upgrade it.`)\n  return useObservable(\n    // @ts-ignore\n    () => db.cloud.permissions(obj, table),\n    [obj.realmId, obj.owner, table]\n  );\n}\n","import { Dexie } from 'dexie';\nimport React from 'react';\n\n// Using import('y-dexie') and import('yjs') to not break the build if y-dexie or yjs are not installed.\n// (these two libries are truly optional and not listed in neither peerDependencies nor optionalDependencies)\n// We want the compiler to not complain about missing imports, so we use type imports.\n// Runtime, we will detect if y-dexie is available and use it via Dexie['DexieYProvider'].\n\ntype DexieYProvider = import('y-dexie').DexieYProvider;\ntype DexieYProviderConstructor = typeof import('y-dexie').DexieYProvider;\ntype YDoc = import('yjs').Doc;\n\nconst gracePeriod = 100 // 100 ms = grace period to optimize for unload/reload scenarios\n\nconst fr = typeof FinalizationRegistry !== 'undefined' && new FinalizationRegistry((doc: YDoc) => {\n  // If coming here, react effect never ran. This is a fallback cleanup mechanism.\n  const DexieYProvider = Dexie['DexieYProvider'] as DexieYProviderConstructor;\n  if (DexieYProvider) DexieYProvider.release(doc);\n});\n\nexport function useDocument(\n  doc: YDoc | null | undefined\n): DexieYProvider | null {\n  if (!fr) throw new TypeError('FinalizationRegistry not supported.');\n  const providerRef = React.useRef<DexieYProvider | null>(null);\n  const DexieYProvider = Dexie['DexieYProvider'] as DexieYProviderConstructor;\n  if (!DexieYProvider) {\n    throw new Error('DexieYProvider is not available. Make sure `y-dexie` is installed and imported.');\n  }\n  let unregisterToken: object | undefined = undefined;\n  if (doc) {\n    if (doc !== providerRef.current?.doc) {\n      providerRef.current = DexieYProvider.load(doc, { gracePeriod });\n      unregisterToken = Object.create(null);\n      fr.register(providerRef, doc, unregisterToken);\n    }\n  } else if (providerRef.current?.doc) {\n    providerRef.current = null;\n  }\n  React.useEffect(() => {\n    if (doc) {\n      // Doc is set or changed. Unregister provider from FinalizationRegistry\n      // and instead take over from here to release the doc when component is unmounted\n      // or when doc is changed. What we're doing here is to avoid relying on FinalizationRegistry\n      // in all the normal cases and instead rely on React's lifecycle to release the doc.\n      // But there can be situations when react never calls this effect and therefore, we\n      // need to rely on FinalizationRegistry to release the doc as a fallback.\n      // We cannot wait with loading the document until the effect happens, because the doc\n      // could have been destroyed in the meantime.\n      if (unregisterToken) fr.unregister(unregisterToken);\n      let provider = DexieYProvider.for(doc);\n      if (provider) {\n        return () => {\n          DexieYProvider.release(doc);\n        }\n      } else {\n        // Maybe the doc was destroyed in the meantime.\n        // Can not happen if React and FinalizationRegistry works as we expect them to.\n        // Except if a user had called DexieYProvider.release() on the doc\n        throw new Error(`FATAL. DexieYProvider.release() has been called somewhere in application code, making us lose the document.`);\n      }\n    }\n  }, [doc, unregisterToken]);\n  return providerRef.current;\n}\n","import * as React from 'react';\n\n/** {@link React.use} if supported, else fallback */\nconst reactUse = Reflect.get(React, 'use');\n\nexport const usePromise: <T>(promise: PromiseLike<T>) => T =\n  reactUse ?? fallbackUsePromise;\n\n/** Fallback for `React.use` with promise */\nfunction fallbackUsePromise<T>(promise: PromiseLike<T>): T {\n  const state = PROMISE_STATE_MAP.get(promise);\n\n  if (!state) {\n    PROMISE_STATE_MAP.set(promise, { status: 'pending' });\n    promise.then(\n      (value) => {\n        PROMISE_STATE_MAP.set(promise, { status: 'fulfilled', value });\n      },\n      (reason) => {\n        PROMISE_STATE_MAP.set(promise, { status: 'rejected', reason });\n      }\n    );\n    throw promise;\n  }\n\n  switch (state.status) {\n    case 'pending':\n      throw promise;\n    case 'rejected':\n      throw state.reason;\n    case 'fulfilled':\n      return state.value;\n  }\n}\n\nconst PROMISE_STATE_MAP = new WeakMap<\n  PromiseLike<any>,\n  PromiseSettledResult<any> | { status: 'pending' }\n>();\n","import { Observer, Subscribable, Unsubscribable } from 'dexie';\nimport * as React from 'react';\nimport { usePromise } from './usePromise';\n\nconst observableCache = new Map<React.DependencyList, Subscribable<any>>();\nconst promiseCache = new WeakMap<Subscribable<any>, Promise<any>>();\nconst valueCache = new WeakMap<Subscribable<any>, any>();\n\nconst CLEANUP_DELAY = 3000; // Time to wait before cleaning up unused observables\n\n/**\n * Subscribes to an observable and returns the latest value.\n * Suspends until the first value is received.\n *\n * Calls with the same cache key will reuse the same observable.\n * Cache key must be globally unique.\n */\nexport function useSuspendingObservable<T>(\n  getObservable: (() => Subscribable<T>) | Subscribable<T>,\n  cacheKey: React.DependencyList\n): T {\n  let observable: Subscribable<T> | undefined;\n\n  // Try to find an existing observable for this cache key\n  for (const [key, value] of observableCache) {\n    if (\n      key.length === cacheKey.length &&\n      key.every((k, i) => Object.is(k, cacheKey[i]))\n    ) {\n      observable = value;\n      break;\n    }\n  }\n\n  // If no observable was found, create a new one\n  if (!observable) {\n    // Create a multicast observable which subscribes to source at most once.\n    const source =\n      typeof getObservable === 'function' ? getObservable() : getObservable;\n    let subscription: Unsubscribable | undefined;\n    const observers = new Set<Observer<T>>();\n    let timeout: ReturnType<typeof setTimeout> | undefined;\n    const newObservable: Subscribable<T> = {\n      subscribe: (observer) => {\n        observers.add(observer);\n        // Cancel the cleanup timer if it's running\n        if (timeout != null) {\n          clearTimeout(timeout);\n          timeout = undefined;\n        }\n        // If this is the first subscriber, subscribe to the source observable\n        if (!subscription) {\n          subscription = source.subscribe({\n            next: (val) => {\n              valueCache.set(newObservable, val);\n              // Clone observers in case the list changes during emission\n              for (const obs of new Set(observers)) obs.next?.(val);\n            },\n            error: (err) => {\n              const lastObservers = new Set(observers);\n              handleFinalize();\n              for (const obs of lastObservers) obs.error?.(err);\n            },\n            complete: () => {\n              const lastObservers = new Set(observers);\n              handleFinalize();\n              for (const obs of lastObservers) obs.complete?.();\n            },\n          });\n        }\n        // Otherwise, emit the current value to the new subscriber if any\n        else if (valueCache.has(newObservable)) {\n          observer.next?.(valueCache.get(newObservable)!);\n        }\n        // Return the unsubscriber\n        return {\n          unsubscribe: () => {\n            if (!observers.has(observer)) return;\n            observers.delete(observer);\n            // If this was the last subscriber, schedule cleanup\n            if (observers.size === 0) scheduleCleanup();\n          },\n        };\n        function handleFinalize() {\n          // Reset this observable to the initial state\n          subscription = undefined;\n          observers.clear();\n          valueCache.delete(newObservable);\n          promiseCache.delete(newObservable);\n          // Schedule cleanup in case nobody subscribes again\n          scheduleCleanup();\n        }\n        function scheduleCleanup() {\n          if (timeout != null) return; // Cleanup already scheduled\n          timeout = setTimeout(() => {\n            // Unsubscribe source if any\n            subscription?.unsubscribe();\n            subscription = undefined;\n            // Remove this observable from cache\n            for (const [key, value] of observableCache) {\n              if (value === newObservable) {\n                observableCache.delete(key);\n                break;\n              }\n            }\n          }, CLEANUP_DELAY);\n        }\n      },\n    };\n    observable = newObservable;\n    observableCache.set(cacheKey, newObservable);\n  }\n\n  // Get or initialize promise for first value\n  let promise = promiseCache.get(observable);\n  if (!promise) {\n    promise = new Promise<T>((resolve, reject) => {\n      const subscription = observable.subscribe({\n        next: (val) => {\n          resolve(val);\n          // Unsubscribe in next tick because subscription might not be assigned yet\n          queueMicrotask(() => subscription.unsubscribe());\n        },\n        error: (err) => reject(err),\n      });\n    });\n    promiseCache.set(observable, promise);\n  }\n\n  const initialValue = usePromise(promise);\n\n  const value = React.useRef<T>(initialValue);\n  const [error, setError] = React.useState<unknown>();\n  const rerender = React.useReducer((x) => x + 1, 0)[1];\n\n  // Set the value immediately on every render.\n  // This avoids waiting for effect to run.\n  value.current = valueCache.has(observable)\n    ? valueCache.get(observable)!\n    : initialValue;\n\n  // Subscribe to live updates until the source observable changes.\n  React.useEffect(() => {\n    const subscription = observable.subscribe({\n      next: (val) => {\n        if (!Object.is(val, value.current)) {\n          value.current = val;\n          rerender();\n        }\n      },\n      error: (err) => setError(err),\n    });\n    return () => subscription.unsubscribe();\n  }, [observable]);\n\n  if (error) throw error;\n  return value.current;\n}\n","import { Dexie } from 'dexie';\nimport { useSuspendingObservable } from './useSuspendingObservable';\n\n/**\n * Observe IndexedDB data in your React component. Make the component re-render when the observed data changes.\n *\n * Suspends until first value is available.\n * \n * Cache key must be globally unique.\n */\nexport function useSuspendingLiveQuery<T>(\n  querier: () => Promise<T> | T,\n  cacheKey: React.DependencyList\n): T {\n  return useSuspendingObservable(\n    () => Dexie.liveQuery(querier),\n    ['dexie', ...cacheKey]\n  );\n}\n"],"names":["React"],"mappings":";;;;SA4BgB,aAAa,CAC3B,iBAEoC,EACpC,IAAU,EACV,IAAU,EAAA;;AAGV,IAAA,IAAI,IAAW;AACf,IAAA,IAAI,aAAuB;AAC3B,IAAA,IAAI,OAAO,iBAAiB,KAAK,UAAU,EAAE;AAC3C,QAAA,IAAI,GAAG,IAAI,IAAI,EAAE;QACjB,aAAa,GAAG,IAAI;IACtB;SAAO;QACL,IAAI,GAAG,EAAE;QACT,aAAa,GAAG,IAAI;IACtB;;AAGA,IAAA,MAAM,OA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