storeTargetExists
storeTargetExists(
storePath,backendOverride?,env?):Promise<boolean>
Defined in: packages/client/src/store-path.ts:377
Does either backend a browser boot could own for a plain storePath ALREADY exist? The fresh-target gate for a restore (ADR-0035 decision 6) — restore refuses a target that is already there. Per backend:
- memory (
backendOverride === "memory") — a scheme-selected memory store is fresh by construction: it lives only for the instance about to be created, so there is nothing to collide with. Alwaysfalse(the sanctioned test/ephemeral lane never blocks a restore). file://(Bun/Node) — filesystem existence of the datadir directory.node:fsis imported DYNAMICALLY inside this branch, never at module top level, so a browser bundle (which only ever hits theidb://branch below) never pullsnode:fsin. Relative paths resolve against the working directory, exactly as PGlite’s filesystem backend and resolveStoreDataDir do.opfs://(browser, placement probe granted) — existence of the store DIRECTORY atpgxsinkit/stores/<identity>(opfsStoreDirectoryPath), walked vianavigator.storage.getDirectory()and agetDirectoryHandlechain with{ create: false }. This is ONLY the fresh-target gate; it is emphatically NOT commitment authority — a store directory without a commitment marker is an uncommitted CANDIDATE, and deciding that is the store meta record’s phase machine (plan step 2), never this function.navigator.storage/getDirectoryabsent → best-effortfalse(mirrors the idbdatabases()stance — never fabricate a positive). ANotFoundErroranywhere in the chain →false; any OTHER error propagates (a genuine failure the restore caller must see). A missing OPFS directory does not finish a granted browser check: IDB is also probed, because a predecessor or fixed-placement store may still own the same public path.idb://(browser/worker) —indexedDB.databases()enumerated for the store’s database name (storeIndexedDbDatabaseName). BEST-EFFORT:databases()is unavailable on some engines (older Firefox, certain worker contexts); when absent we CANNOT prove existence, so we reportfalseand let the restore proceed rather than fabricate a result — a real overlay collision would still surface as a PGlite-level boot failure. We never fake a positive.
Parameters
Section titled “Parameters”storePath
Section titled “storePath”string
backendOverride?
Section titled “backendOverride?”"memory"
StoreEnv = ...
Returns
Section titled “Returns”Promise<boolean>