From d0afc622909ce62e956be088c60dbd7d57d8aa0c Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 1 Apr 2024 17:01:02 -0400 Subject: [PATCH 1/3] refactor: rename "config" file to "virtual" --- packages/db/package.json | 8 ++++---- packages/db/src/core/consts.ts | 2 +- packages/db/src/core/integration/vite-plugin-db.ts | 8 ++++---- packages/db/src/runtime/{config.ts => virtual.ts} | 0 packages/db/tsconfig.json | 2 +- .../{tsconfig.config-types.json => tsconfig.virtual.json} | 4 ++-- packages/db/virtual.d.ts | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) rename packages/db/src/runtime/{config.ts => virtual.ts} (100%) rename packages/db/{tsconfig.config-types.json => tsconfig.virtual.json} (78%) diff --git a/packages/db/package.json b/packages/db/package.json index b1b097ad8e23..75735cbdb0f7 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -20,8 +20,8 @@ "types": "./dist/runtime/index.d.ts", "import": "./dist/runtime/index.js" }, - "./dist/runtime/config.js": { - "import": "./dist/runtime/config.js" + "./dist/runtime/virtual.js": { + "import": "./dist/runtime/virtual.js" }, "./types": { "types": "./dist/core/types.d.ts", @@ -55,8 +55,8 @@ "astro-integration" ], "scripts": { - "types:config": "tsc -p ./tsconfig.config-types.json", - "build": "astro-scripts build \"src/**/*.ts\" && tsc && pnpm types:config", + "types:virtual": "tsc -p ./tsconfig.virtual.json", + "build": "astro-scripts build \"src/**/*.ts\" && tsc && pnpm types:virtual", "build:ci": "astro-scripts build \"src/**/*.ts\"", "dev": "astro-scripts dev \"src/**/*.ts\"", "test": "mocha --exit --timeout 20000 \"test/*.js\" \"test/unit/**/*.js\"", diff --git a/packages/db/src/core/consts.ts b/packages/db/src/core/consts.ts index 3ba7b43d74ae..c37f1b99dc43 100644 --- a/packages/db/src/core/consts.ts +++ b/packages/db/src/core/consts.ts @@ -6,7 +6,7 @@ export const PACKAGE_NAME = JSON.parse( export const RUNTIME_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime`); -export const RUNTIME_CONFIG_IMPORT = JSON.stringify(`${PACKAGE_NAME}/dist/runtime/config.js`); +export const RUNTIME_VIRTUAL_IMPORT = JSON.stringify(`${PACKAGE_NAME}/dist/runtime/virtual.js`); export const DB_TYPES_FILE = 'db-types.d.ts'; diff --git a/packages/db/src/core/integration/vite-plugin-db.ts b/packages/db/src/core/integration/vite-plugin-db.ts index 769070976b98..b61086dadc0e 100644 --- a/packages/db/src/core/integration/vite-plugin-db.ts +++ b/packages/db/src/core/integration/vite-plugin-db.ts @@ -1,7 +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_IMPORT, VIRTUAL_MODULE_ID } from '../consts.js'; +import { DB_PATH, RUNTIME_VIRTUAL_IMPORT, RUNTIME_IMPORT, VIRTUAL_MODULE_ID } from '../consts.js'; import type { DBTables } from '../types.js'; import { type VitePlugin, getDbDirectoryUrl, getRemoteDatabaseUrl } from '../utils.js'; @@ -79,7 +79,7 @@ export function vitePluginDb(params: VitePluginDBParams): VitePlugin { } export function getConfigVirtualModContents() { - return `export * from ${RUNTIME_CONFIG_IMPORT}`; + return `export * from ${RUNTIME_VIRTUAL_IMPORT}`; } export function getLocalVirtualModContents({ @@ -132,7 +132,7 @@ ${ : '' } -export * from ${RUNTIME_CONFIG_IMPORT}; +export * from ${RUNTIME_VIRTUAL_IMPORT}; ${getStringifiedTableExports(tables)}`; } @@ -166,7 +166,7 @@ import {asDrizzleTable, createRemoteDatabaseClient} from ${RUNTIME_IMPORT}; export const db = await createRemoteDatabaseClient(${appTokenArg()}, ${dbUrlArg()}); -export * from ${RUNTIME_CONFIG_IMPORT}; +export * from ${RUNTIME_VIRTUAL_IMPORT}; ${getStringifiedTableExports(tables)} `; diff --git a/packages/db/src/runtime/config.ts b/packages/db/src/runtime/virtual.ts similarity index 100% rename from packages/db/src/runtime/config.ts rename to packages/db/src/runtime/virtual.ts diff --git a/packages/db/tsconfig.json b/packages/db/tsconfig.json index 96407d1d114a..7592ad8a1774 100644 --- a/packages/db/tsconfig.json +++ b/packages/db/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.base.json", "include": ["src"], - "exclude": ["src/runtime/config.ts"], + "exclude": ["src/runtime/virtual.ts"], "compilerOptions": { "outDir": "./dist" } diff --git a/packages/db/tsconfig.config-types.json b/packages/db/tsconfig.virtual.json similarity index 78% rename from packages/db/tsconfig.config-types.json rename to packages/db/tsconfig.virtual.json index f21f8445d573..41d2aef4a11b 100644 --- a/packages/db/tsconfig.config-types.json +++ b/packages/db/tsconfig.virtual.json @@ -1,11 +1,11 @@ { // We want to avoid defineTable() and defineDb() import hints // from the runtime config export instead of astro:db. - // We exclude runtime/config from the base types, + // We exclude runtime/virtual from the base types, // and generate to a separate _internal/ directory // for our virtual module (virtual.d.ts) to reference. "extends": "../../tsconfig.base.json", - "files": ["./src/runtime/config.ts"], + "files": ["./src/runtime/virtual.ts"], "compilerOptions": { "outDir": "./dist/_internal" } diff --git a/packages/db/virtual.d.ts b/packages/db/virtual.d.ts index bea4990a0efa..efe9e8387d30 100644 --- a/packages/db/virtual.d.ts +++ b/packages/db/virtual.d.ts @@ -1,7 +1,7 @@ declare module 'astro:db' { - type RuntimeConfig = typeof import('./dist/_internal/runtime/config.js'); + type RuntimeConfig = typeof import('./dist/_internal/runtime/virtual.js'); - export const db: import('./dist/_internal/runtime/config.js').Database; + export const db: import('./dist/_internal/runtime/virtual.js').Database; export const dbUrl: string; export const sql: RuntimeConfig['sql']; From d70a21cf3bf466fdce44980b14f9bedb1db938f4 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 1 Apr 2024 17:04:10 -0400 Subject: [PATCH 2/3] chore: changeset --- .changeset/plenty-owls-wait.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/plenty-owls-wait.md diff --git a/.changeset/plenty-owls-wait.md b/.changeset/plenty-owls-wait.md new file mode 100644 index 000000000000..4a34636bd4f1 --- /dev/null +++ b/.changeset/plenty-owls-wait.md @@ -0,0 +1,5 @@ +--- +"@astrojs/db": minor +--- + +Rename internal import from `runtime/config` to `runtime/virtual` From 4cf23fe86e241a008c55879f625a8ffb1bd2cee7 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Tue, 2 Apr 2024 17:53:29 -0400 Subject: [PATCH 3/3] fix(test): config import --- packages/db/test/unit/column-queries.test.js | 2 +- packages/db/test/unit/index-queries.test.js | 2 +- packages/db/test/unit/reference-queries.test.js | 2 +- packages/db/test/unit/reset-queries.test.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/db/test/unit/column-queries.test.js b/packages/db/test/unit/column-queries.test.js index 68b018aecc17..ef4ac9693716 100644 --- a/packages/db/test/unit/column-queries.test.js +++ b/packages/db/test/unit/column-queries.test.js @@ -6,7 +6,7 @@ import { } from '../../dist/core/cli/migration-queries.js'; import { MIGRATION_VERSION } from '../../dist/core/consts.js'; import { tableSchema } from '../../dist/core/schemas.js'; -import { NOW, column, defineTable } from '../../dist/runtime/config.js'; +import { NOW, column, defineTable } from '../../dist/runtime/virtual.js'; const TABLE_NAME = 'Users'; diff --git a/packages/db/test/unit/index-queries.test.js b/packages/db/test/unit/index-queries.test.js index 5af1b8489c8a..ce0894d27453 100644 --- a/packages/db/test/unit/index-queries.test.js +++ b/packages/db/test/unit/index-queries.test.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import { getTableChangeQueries } from '../../dist/core/cli/migration-queries.js'; import { dbConfigSchema, tableSchema } from '../../dist/core/schemas.js'; -import { column } from '../../dist/runtime/config.js'; +import { column } from '../../dist/runtime/virtual.js'; const userInitial = tableSchema.parse({ columns: { diff --git a/packages/db/test/unit/reference-queries.test.js b/packages/db/test/unit/reference-queries.test.js index 2321ef507d66..76f6341e164c 100644 --- a/packages/db/test/unit/reference-queries.test.js +++ b/packages/db/test/unit/reference-queries.test.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import { getTableChangeQueries } from '../../dist/core/cli/migration-queries.js'; import { tablesSchema } from '../../dist/core/schemas.js'; -import { column, defineTable } from '../../dist/runtime/config.js'; +import { column, defineTable } from '../../dist/runtime/virtual.js'; const BaseUser = defineTable({ columns: { diff --git a/packages/db/test/unit/reset-queries.test.js b/packages/db/test/unit/reset-queries.test.js index 4d74e01482d7..4e91d1d8d7ed 100644 --- a/packages/db/test/unit/reset-queries.test.js +++ b/packages/db/test/unit/reset-queries.test.js @@ -3,7 +3,7 @@ import { describe, it } from 'mocha'; import { getMigrationQueries } from '../../dist/core/cli/migration-queries.js'; import { MIGRATION_VERSION } from '../../dist/core/consts.js'; import { tableSchema } from '../../dist/core/schemas.js'; -import { column, defineTable } from '../../dist/runtime/config.js'; +import { column, defineTable } from '../../dist/runtime/virtual.js'; const TABLE_NAME = 'Users';