Skip to content

Commit

Permalink
refactor: rename "config" file to "virtual" (#10638)
Browse files Browse the repository at this point in the history
* refactor: rename "config" file to "virtual"

* chore: changeset

* fix(test): config import
  • Loading branch information
bholmesdev authored Apr 2, 2024
1 parent 4f5dc14 commit f395ebc
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-owls-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": minor
---

Rename internal import from `runtime/config` to `runtime/virtual`
8 changes: 4 additions & 4 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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\"",
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/core/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
8 changes: 4 additions & 4 deletions packages/db/src/core/integration/vite-plugin-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
import type { AstroConfig } from 'astro';
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';

Expand Down Expand Up @@ -83,7 +83,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({
Expand Down Expand Up @@ -136,7 +136,7 @@ ${
: ''
}
export * from ${RUNTIME_CONFIG_IMPORT};
export * from ${RUNTIME_VIRTUAL_IMPORT};
${getStringifiedTableExports(tables)}`;
}
Expand Down Expand Up @@ -177,7 +177,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)}
`;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/db/test/unit/column-queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion packages/db/test/unit/index-queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/db/test/unit/reference-queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/db/test/unit/reset-queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion packages/db/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["src/runtime/config.ts"],
"exclude": ["src/runtime/virtual.ts"],
"compilerOptions": {
"outDir": "./dist"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/db/virtual.d.ts
Original file line number Diff line number Diff line change
@@ -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'];
Expand Down

0 comments on commit f395ebc

Please sign in to comment.