UNPKG

@pgxsinkit/pgwasm

Version:
127 lines (110 loc) • 4.53 kB
// @bun // packages/pgwasm/src/errors.ts class PgwasmError2 extends Error { name = "PgwasmError"; } class UnsupportedDataDirError2 extends PgwasmError2 { name = "UnsupportedDataDirError"; dataDir; constructor(dataDir, reason) { super(`Unsupported dataDir "${dataDir}": ${reason}`); this.dataDir = dataDir; } } class OpfsAhpRemovedError2 extends UnsupportedDataDirError2 { name = "OpfsAhpRemovedError"; replacement = "@pgxsinkit/pgwasm/opfs"; constructor(dataDir) { super(dataDir, "the opfs-ahp filesystem has been removed; the OPFS store is @pgxsinkit/pgwasm/opfs, passed in " + "explicitly as the `fs` option"); } } class UnsupportedFilesystemError2 extends PgwasmError2 { name = "UnsupportedFilesystemError"; kind; build; constructor(kind, build, supported) { super(`The "${build.name}" Postgres build does not support ${kind} storage (it supports: ${supported.join(", ")}).`); this.kind = kind; this.build = build.name; } } class CrossOriginIsolationRequiredError2 extends PgwasmError2 { name = "CrossOriginIsolationRequiredError"; constructor(build) { super(`The "${build.name}" Postgres build needs a cross-origin-isolated context (SharedArrayBuffer); serve the ` + "page with Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp."); } } class ExtensionBuildMismatchError2 extends PgwasmError2 { name = "ExtensionBuildMismatchError"; constructor(extension, extensionBuild, build) { super(`The "${extension}" extension was compiled for the "${extensionBuild}" Postgres build and cannot load into ` + `the "${build.name}" build.`); } } function describeRecorded(recorded) { return recorded === "unmarked" ? "an unmarked data directory (created before builds were recorded, by the C build)" : `the "${recorded.build}" Postgres build (data format ${recorded.dataFormat})`; } class BuildMismatchError2 extends PgwasmError2 { name = "BuildMismatchError"; expected; found; source; constructor(build, found, source) { const what = source === "backup" ? "This Store backup" : "This data directory"; super(`${what} was created by ${describeRecorded(found)} and cannot be opened with the "${build.name}" build. A ` + "store's Postgres build is fixed when it is created: open it with that build, or destroy the store and " + "re-sync it."); this.expected = { build: build.name, dataFormat: build.dataFormat }; this.found = found; this.source = source; } } class DataFormatMismatchError2 extends PgwasmError2 { name = "DataFormatMismatchError"; expected; found; source; constructor(build, found, source) { super(`This ${source === "backup" ? "Store backup" : "data directory"} is in data format ${found} of the ` + `"${build.name}" Postgres build; this release of the build reads format ${build.dataFormat}.`); this.expected = build.dataFormat; this.found = found; this.source = source; } } class BuildMarkerUnreadableError2 extends PgwasmError2 { name = "BuildMarkerUnreadableError"; raw; constructor(raw, reason) { super(`The data directory's build marker cannot be read (${reason}): ${JSON.stringify(raw)}`); this.raw = raw; } } class DataDirExistsError2 extends PgwasmError2 { name = "DataDirExistsError"; constructor() { super("The data directory already holds a database; a Store backup restores only into an empty one."); } } class BackupFormatError2 extends PgwasmError2 { name = "BackupFormatError"; } class StorageInUseError2 extends PgwasmError2 { name = "StorageInUseError"; constructor(message) { super(message); } } class PgwasmClosedError2 extends PgwasmError2 { name = "PgwasmClosedError"; constructor(state) { super(`pgwasm is ${state}`); } } class PgwasmFailedError2 extends PgwasmError2 { name = "PgwasmFailedError"; } class UnsupportedFeatureError2 extends PgwasmError2 { name = "UnsupportedFeatureError"; } function makeQueryError(data) { return Object.assign(data.error, { query: data.query, params: data.params, queryOptions: data.options }); } export { PgwasmError2, UnsupportedDataDirError2, OpfsAhpRemovedError2, UnsupportedFilesystemError2, CrossOriginIsolationRequiredError2, ExtensionBuildMismatchError2, BuildMismatchError2, DataFormatMismatchError2, BuildMarkerUnreadableError2, DataDirExistsError2, BackupFormatError2, StorageInUseError2, PgwasmClosedError2, PgwasmFailedError2, UnsupportedFeatureError2, makeQueryError }; //# debugId=36B843FDDE04140364756E2164756E21