From 713f99e849b26edb831ea6527b7103ad7a6b200f Mon Sep 17 00:00:00 2001 From: Arsh <69170106+lilnasy@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:07:28 +0530 Subject: [PATCH] fix(db): isolate AstroDbError from core utils (#10646) * fix(db): isolate AstroDbError from core utils * add changeset --- .changeset/dull-news-grab.md | 5 +++++ packages/db/src/core/integration/index.ts | 2 +- packages/db/src/runtime/db-client.ts | 3 +-- packages/db/src/runtime/seed-local.ts | 2 +- packages/db/src/runtime/utils.ts | 6 ++++++ packages/db/src/utils.ts | 6 ------ 6 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 .changeset/dull-news-grab.md diff --git a/.changeset/dull-news-grab.md b/.changeset/dull-news-grab.md new file mode 100644 index 000000000000..293dc6fc6945 --- /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 c6ebf6ff3195..5c40c85214bf 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 7eddd60604e6..d52af72fce95 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 83e3acad5a53..1d16204a5407 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 29160b22df16..ac6cfeda6efb 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 1e7b00b12698..4e1a18685ebf 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'; -}