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: drizzle vs. config runtime export conflict #10357

Merged
merged 3 commits into from
Mar 7, 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/chilly-cherries-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

Fix runtime export error when building with the node adapter
7 changes: 0 additions & 7 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
"types": "./dist/runtime/index.d.ts",
"import": "./dist/runtime/index.js"
},
"./runtime/drizzle": {
"types": "./dist/runtime/drizzle.d.ts",
"import": "./dist/runtime/drizzle.js"
},
"./runtime/config": {
"types": "./dist/runtime/config.d.ts",
"import": "./dist/runtime/config.js"
Expand All @@ -41,9 +37,6 @@
"runtime": [
"./dist/runtime/index.d.ts"
],
"runtime/drizzle": [
"./dist/runtime/drizzle.d.ts"
],
"runtime/config": [
"./dist/runtime/config.d.ts"
]
Expand Down
1 change: 0 additions & 1 deletion packages/db/src/core/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const PACKAGE_NAME = JSON.parse(
).name;

export const RUNTIME_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime`);
export const RUNTIME_DRIZZLE_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime/drizzle`);
export const RUNTIME_CONFIG_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime/config`);

export const DB_TYPES_FILE = 'db-types.d.ts';
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/core/integration/typegen.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { existsSync } from 'node:fs';
import { mkdir, writeFile } from 'node:fs/promises';
import { DB_TYPES_FILE, RUNTIME_DRIZZLE_IMPORT, RUNTIME_IMPORT } from '../consts.js';
import { DB_TYPES_FILE, RUNTIME_CONFIG_IMPORT, RUNTIME_IMPORT } from '../consts.js';
import type { DBTable, DBTables } from '../types.js';

export async function typegen({ tables, root }: { tables: DBTables; root: URL }) {
const content = `// This file is generated by \`studio sync\`
declare module 'astro:db' {
export const db: import(${RUNTIME_IMPORT}).SqliteDB;
export const dbUrl: string;
export * from ${RUNTIME_DRIZZLE_IMPORT};
export * from ${RUNTIME_CONFIG_IMPORT};

${Object.entries(tables)
.map(([name, collection]) => generateTableType(name, collection))
Expand Down
11 changes: 2 additions & 9 deletions packages/db/src/core/integration/vite-plugin-db.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { fileURLToPath } from 'node:url';
import { normalizePath } from 'vite';
import { SEED_DEV_FILE_NAME } from '../../runtime/queries.js';
import {
DB_PATH,
RUNTIME_CONFIG_IMPORT,
RUNTIME_DRIZZLE_IMPORT,
RUNTIME_IMPORT,
VIRTUAL_MODULE_ID,
} from '../consts.js';
import { DB_PATH, RUNTIME_CONFIG_IMPORT, RUNTIME_IMPORT, VIRTUAL_MODULE_ID } from '../consts.js';
import type { DBTables } from '../types.js';
import { type VitePlugin, getDbDirectoryUrl, getRemoteDatabaseUrl } from '../utils.js';

Expand Down Expand Up @@ -116,7 +110,6 @@ ${
: ''
}

export * from ${RUNTIME_DRIZZLE_IMPORT};
export * from ${RUNTIME_CONFIG_IMPORT};

${getStringifiedCollectionExports(tables)}`;
Expand All @@ -136,7 +129,7 @@ export const db = await createRemoteDatabaseClient(${JSON.stringify(
appToken
// Respect runtime env for user overrides in SSR
)}, import.meta.env.ASTRO_STUDIO_REMOTE_DB_URL ?? ${JSON.stringify(getRemoteDatabaseUrl())});
export * from ${RUNTIME_DRIZZLE_IMPORT};

export * from ${RUNTIME_CONFIG_IMPORT};

${getStringifiedCollectionExports(tables)}
Expand Down
27 changes: 26 additions & 1 deletion packages/db/src/runtime/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,29 @@ export function defineDB(userConfig: DBConfigInput) {
return userConfig;
}

export { sql, NOW, TRUE, FALSE } from './index.js';
export { NOW, TRUE, FALSE } from './index.js';

export {
sql,
eq,
gt,
gte,
lt,
lte,
ne,
isNull,
isNotNull,
inArray,
notInArray,
exists,
notExists,
between,
notBetween,
like,
notIlike,
not,
asc,
desc,
and,
or,
} from 'drizzle-orm';
Loading