{"version":3,"file":"inject-is-restoring.mjs","sources":["../src/inject-is-restoring.ts"],"sourcesContent":["import {\n  InjectionToken,\n  Injector,\n  assertInInjectionContext,\n  inject,\n  signal,\n} from '@angular/core'\nimport type { Provider, Signal } from '@angular/core'\n\n/**\n * Internal token used to track isRestoring state, accessible in public API through `injectIsRestoring` and set via `provideIsRestoring`\n */\nconst IS_RESTORING = new InjectionToken('', {\n  // Default value when not provided\n  factory: () => signal(false).asReadonly(),\n})\n\ninterface InjectIsRestoringOptions {\n  /**\n   * The `Injector` to use to get the isRestoring signal.\n   *\n   * If this is not provided, the current injection context will be used instead (via `inject`).\n   */\n  injector?: Injector\n}\n\n/**\n * Injects a signal that tracks whether a restore (e.g. from a persisted client, wired up via\n * `provideIsRestoring`) is currently in progress. `injectQuery` and friends also check this internally to\n * avoid race conditions between the restore and initializing queries.\n * @param options - Additional configuration\n * @returns A readonly `Signal<boolean>` — `true` while a restore is in progress, `false` otherwise (the\n * default when no `provideIsRestoring` provider is registered).\n */\nexport function injectIsRestoring(options?: InjectIsRestoringOptions) {\n  !options?.injector && assertInInjectionContext(injectIsRestoring)\n  const injector = options?.injector ?? inject(Injector)\n  return injector.get(IS_RESTORING)\n}\n\n/**\n * Registers a provider for the restore state read by `injectIsRestoring`. Wire this up wherever you drive a\n * restore yourself — e.g. a persist-client integration — so `injectQuery` and friends can defer subscribing\n * to their observer (avoiding a race with the restore) until the restore signal flips back to `false`.\n * @param isRestoring - A readonly `Signal<boolean>` that tracks the restore state.\n * @returns A provider for the `isRestoring` signal.\n */\nexport function provideIsRestoring(isRestoring: Signal<boolean>): Provider {\n  return {\n    provide: IS_RESTORING,\n    useValue: isRestoring,\n  }\n}\n"],"names":[],"mappings":";AAYA,MAAM,eAAe,IAAI,eAAe,IAAI;AAAA;AAAA,EAE1C,SAAS,MAAM,OAAO,KAAK,EAAE,WAAA;AAC/B,CAAC;AAmBM,SAAS,kBAAkB,SAAoC;AACpE,IAAC,mCAAS,aAAY,yBAAyB,iBAAiB;AAChE,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AACrD,SAAO,SAAS,IAAI,YAAY;AAClC;AASO,SAAS,mBAAmB,aAAwC;AACzE,SAAO;AAAA,IACL,SAAS;AAAA,IACT,UAAU;AAAA,EAAA;AAEd;"}