diff options
author | 2024-04-02 21:07:28 +0530 | |
---|---|---|
committer | 2024-04-02 11:37:28 -0400 | |
commit | 713f99e849b26edb831ea6527b7103ad7a6b200f (patch) | |
tree | b96955c7198ca1ff0f61a8e0d865b0c357efb048 | |
parent | 51112ab3f1b134740e8307743bbb15cb0d8bdbb3 (diff) | |
download | astro-713f99e849b26edb831ea6527b7103ad7a6b200f.tar.gz astro-713f99e849b26edb831ea6527b7103ad7a6b200f.tar.zst astro-713f99e849b26edb831ea6527b7103ad7a6b200f.zip |
fix(db): isolate AstroDbError from core utils (#10646)
* fix(db): isolate AstroDbError from core utils
* add changeset
-rw-r--r-- | .changeset/dull-news-grab.md | 5 | ||||
-rw-r--r-- | packages/db/src/core/integration/index.ts | 2 | ||||
-rw-r--r-- | packages/db/src/runtime/db-client.ts | 3 | ||||
-rw-r--r-- | packages/db/src/runtime/seed-local.ts | 2 | ||||
-rw-r--r-- | packages/db/src/runtime/utils.ts | 6 | ||||
-rw-r--r-- | packages/db/src/utils.ts | 6 |
6 files changed, 14 insertions, 10 deletions
diff --git a/.changeset/dull-news-grab.md b/.changeset/dull-news-grab.md new file mode 100644 index 000000000..293dc6fc6 --- /dev/null +++ b/.changeset/dull-news-grab.md @@ -0,0 +1,5 @@ +--- +"@astrojs/db": patch +--- + +Fixes an issue astro:db could not be used on serverless platforms. diff --git a/packages/db/src/core/integration/index.ts b/packages/db/src/core/integration/index.ts index c6ebf6ff3..5c40c8521 100644 --- a/packages/db/src/core/integration/index.ts +++ b/packages/db/src/core/integration/index.ts @@ -7,7 +7,7 @@ import { blue, yellow } from 'kleur/colors'; import { loadEnv } from 'vite'; import parseArgs from 'yargs-parser'; import { SEED_DEV_FILE_NAME } from '../../runtime/queries.js'; -import { AstroDbError } from '../../utils.js'; +import { AstroDbError } from '../../runtime/utils.js'; import { CONFIG_FILE_NAMES, DB_PATH } from '../consts.js'; import { resolveDbConfig } from '../load-file.js'; import { type ManagedAppToken, getManagedAppTokenOrExit } from '../tokens.js'; diff --git a/packages/db/src/runtime/db-client.ts b/packages/db/src/runtime/db-client.ts index 7eddd6060..d52af72fc 100644 --- a/packages/db/src/runtime/db-client.ts +++ b/packages/db/src/runtime/db-client.ts @@ -4,8 +4,7 @@ import type { LibSQLDatabase } from 'drizzle-orm/libsql'; import { drizzle as drizzleLibsql } from 'drizzle-orm/libsql'; import { type SqliteRemoteDatabase, drizzle as drizzleProxy } from 'drizzle-orm/sqlite-proxy'; import { z } from 'zod'; -import { AstroDbError } from '../utils.js'; -import { safeFetch } from './utils.js'; +import { AstroDbError, safeFetch } from './utils.js'; const isWebContainer = !!process.versions?.webcontainer; diff --git a/packages/db/src/runtime/seed-local.ts b/packages/db/src/runtime/seed-local.ts index 83e3acad5..1d16204a5 100644 --- a/packages/db/src/runtime/seed-local.ts +++ b/packages/db/src/runtime/seed-local.ts @@ -3,7 +3,7 @@ import { type SQL, sql } from 'drizzle-orm'; import type { LibSQLDatabase } from 'drizzle-orm/libsql'; import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core'; import { type DBTables } from '../core/types.js'; -import { AstroDbError } from '../utils.js'; +import { AstroDbError } from './utils.js'; import { SEED_DEFAULT_EXPORT_ERROR } from './errors.js'; import { getCreateIndexQueries, getCreateTableQuery } from './queries.js'; diff --git a/packages/db/src/runtime/utils.ts b/packages/db/src/runtime/utils.ts index 29160b22d..ac6cfeda6 100644 --- a/packages/db/src/runtime/utils.ts +++ b/packages/db/src/runtime/utils.ts @@ -1,3 +1,5 @@ +import { AstroError } from 'astro/errors'; + /** * Small wrapper around fetch that throws an error if the response is not OK. Allows for custom error handling as well through the onNotOK callback. */ @@ -16,3 +18,7 @@ export async function safeFetch( return response; } + +export class AstroDbError extends AstroError { + name = 'Astro DB Error'; +} diff --git a/packages/db/src/utils.ts b/packages/db/src/utils.ts index 1e7b00b12..4e1a18685 100644 --- a/packages/db/src/utils.ts +++ b/packages/db/src/utils.ts @@ -1,8 +1,2 @@ -import { AstroError } from 'astro/errors'; - export { defineDbIntegration } from './core/utils.js'; export { asDrizzleTable } from './runtime/index.js'; - -export class AstroDbError extends AstroError { - name = 'Astro DB Error'; -} |