Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db): isolate AstroDbError from core utils #10646

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-news-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

Fixes an issue astro:db could not be used on serverless platforms.
2 changes: 1 addition & 1 deletion packages/db/src/core/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 1 addition & 2 deletions packages/db/src/runtime/db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/runtime/seed-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I'm surprised this would cause an issue. utils.js is at the project root, not in the core directory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: Ah, I just noticed that root file exports the core db integration file. Guess I've found the edge case in our eslint rule barring core modules. Thanks for finding this!

import { AstroDbError } from './utils.js';
import { SEED_DEFAULT_EXPORT_ERROR } from './errors.js';
import { getCreateIndexQueries, getCreateTableQuery } from './queries.js';

Expand Down
6 changes: 6 additions & 0 deletions packages/db/src/runtime/utils.ts
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -16,3 +18,7 @@ export async function safeFetch(

return response;
}

export class AstroDbError extends AstroError {
name = 'Astro DB Error';
}
6 changes: 0 additions & 6 deletions packages/db/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
}
Loading