@astrojs/db 0.8.4 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_internal/core/errors.d.ts +2 -0
- package/dist/core/cli/commands/execute/index.js +15 -4
- package/dist/core/cli/print-help.js +1 -1
- package/dist/core/errors.d.ts +2 -0
- package/dist/core/errors.js +11 -3
- package/dist/core/integration/index.js +3 -3
- package/dist/core/integration/typegen.d.ts +3 -1
- package/dist/core/integration/typegen.js +9 -3
- package/dist/core/integration/vite-plugin-db.js +1 -1
- package/dist/core/integration/vite-plugin-inject-env-ts.js +1 -1
- package/dist/core/load-file.d.ts +1 -1
- package/dist/core/load-file.js +4 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +2 -2
|
@@ -6,7 +6,9 @@ export declare const RENAME_COLUMN_ERROR: (oldSelector: string, newSelector: str
|
|
|
6
6
|
export declare const FILE_NOT_FOUND_ERROR: (path: string) => string;
|
|
7
7
|
export declare const SHELL_QUERY_MISSING_ERROR: string;
|
|
8
8
|
export declare const SEED_ERROR: (error: string) => string;
|
|
9
|
+
export declare const EXEC_ERROR: (error: string) => string;
|
|
9
10
|
export declare const SEED_DEFAULT_EXPORT_ERROR: (fileName: string) => string;
|
|
11
|
+
export declare const EXEC_DEFAULT_EXPORT_ERROR: (fileName: string) => string;
|
|
10
12
|
export declare const REFERENCE_DNE_ERROR: (columnName: string) => string;
|
|
11
13
|
export declare const FOREIGN_KEY_DNE_ERROR: (tableName: string) => string;
|
|
12
14
|
export declare const FOREIGN_KEY_REFERENCES_LENGTH_ERROR: (tableName: string) => string;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
+
import { LibsqlError } from "@libsql/client";
|
|
3
|
+
import { green } from "kleur/colors";
|
|
2
4
|
import {
|
|
5
|
+
EXEC_DEFAULT_EXPORT_ERROR,
|
|
6
|
+
EXEC_ERROR,
|
|
3
7
|
FILE_NOT_FOUND_ERROR,
|
|
4
|
-
MISSING_EXECUTE_PATH_ERROR
|
|
5
|
-
SEED_DEFAULT_EXPORT_ERROR
|
|
8
|
+
MISSING_EXECUTE_PATH_ERROR
|
|
6
9
|
} from "../../../errors.js";
|
|
7
10
|
import {
|
|
8
11
|
getLocalVirtualModContents,
|
|
@@ -44,10 +47,18 @@ async function cmd({
|
|
|
44
47
|
const { code } = await bundleFile({ virtualModContents, root: astroConfig.root, fileUrl });
|
|
45
48
|
const mod = await importBundledFile({ code, root: astroConfig.root });
|
|
46
49
|
if (typeof mod.default !== "function") {
|
|
47
|
-
console.error(
|
|
50
|
+
console.error(EXEC_DEFAULT_EXPORT_ERROR);
|
|
48
51
|
process.exit(1);
|
|
49
52
|
}
|
|
50
|
-
|
|
53
|
+
try {
|
|
54
|
+
await mod.default();
|
|
55
|
+
console.info(`${green("\u2714")} File run successfully.`);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
if (e instanceof LibsqlError) {
|
|
58
|
+
throw new Error(EXEC_ERROR(e.message));
|
|
59
|
+
}
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
51
62
|
}
|
|
52
63
|
export {
|
|
53
64
|
cmd
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ export declare const RENAME_COLUMN_ERROR: (oldSelector: string, newSelector: str
|
|
|
6
6
|
export declare const FILE_NOT_FOUND_ERROR: (path: string) => string;
|
|
7
7
|
export declare const SHELL_QUERY_MISSING_ERROR: string;
|
|
8
8
|
export declare const SEED_ERROR: (error: string) => string;
|
|
9
|
+
export declare const EXEC_ERROR: (error: string) => string;
|
|
9
10
|
export declare const SEED_DEFAULT_EXPORT_ERROR: (fileName: string) => string;
|
|
11
|
+
export declare const EXEC_DEFAULT_EXPORT_ERROR: (fileName: string) => string;
|
|
10
12
|
export declare const REFERENCE_DNE_ERROR: (columnName: string) => string;
|
|
11
13
|
export declare const FOREIGN_KEY_DNE_ERROR: (tableName: string) => string;
|
|
12
14
|
export declare const FOREIGN_KEY_REFERENCES_LENGTH_ERROR: (tableName: string) => string;
|
package/dist/core/errors.js
CHANGED
|
@@ -34,10 +34,16 @@ const SEED_ERROR = (error) => {
|
|
|
34
34
|
|
|
35
35
|
${error}`;
|
|
36
36
|
};
|
|
37
|
-
const
|
|
38
|
-
return red(
|
|
37
|
+
const EXEC_ERROR = (error) => {
|
|
38
|
+
return `${red(`Error while executing file:`)}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
${error}`;
|
|
41
|
+
};
|
|
42
|
+
const SEED_DEFAULT_EXPORT_ERROR = (fileName) => {
|
|
43
|
+
return SEED_ERROR(`Missing default function export in ${bold(fileName)}`);
|
|
44
|
+
};
|
|
45
|
+
const EXEC_DEFAULT_EXPORT_ERROR = (fileName) => {
|
|
46
|
+
return EXEC_ERROR(`Missing default function export in ${bold(fileName)}`);
|
|
41
47
|
};
|
|
42
48
|
const REFERENCE_DNE_ERROR = (columnName) => {
|
|
43
49
|
return `Column ${bold(
|
|
@@ -65,6 +71,8 @@ const INTEGRATION_TABLE_CONFLICT_ERROR = (integrationName, tableName, isUserConf
|
|
|
65
71
|
Another integration already added a table named ${bold(tableName)}`;
|
|
66
72
|
};
|
|
67
73
|
export {
|
|
74
|
+
EXEC_DEFAULT_EXPORT_ERROR,
|
|
75
|
+
EXEC_ERROR,
|
|
68
76
|
FILE_NOT_FOUND_ERROR,
|
|
69
77
|
FOREIGN_KEY_DNE_ERROR,
|
|
70
78
|
FOREIGN_KEY_REFERENCES_EMPTY_ERROR,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
2
|
import { dirname } from "path";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
|
-
import { mkdir,
|
|
4
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
5
5
|
import { blue, yellow } from "kleur/colors";
|
|
6
6
|
import parseArgs from "yargs-parser";
|
|
7
7
|
import { CONFIG_FILE_NAMES, DB_PATH } from "../consts.js";
|
|
@@ -9,7 +9,7 @@ import { resolveDbConfig } from "../load-file.js";
|
|
|
9
9
|
import { getManagedAppTokenOrExit } from "../tokens.js";
|
|
10
10
|
import { getDbDirectoryUrl } from "../utils.js";
|
|
11
11
|
import { fileURLIntegration } from "./file-url.js";
|
|
12
|
-
import {
|
|
12
|
+
import { typegenInternal } from "./typegen.js";
|
|
13
13
|
import { vitePluginDb } from "./vite-plugin-db.js";
|
|
14
14
|
import { vitePluginInjectEnvTs } from "./vite-plugin-inject-env-ts.js";
|
|
15
15
|
function astroDBIntegration() {
|
|
@@ -76,7 +76,7 @@ function astroDBIntegration() {
|
|
|
76
76
|
await mkdir(dirname(fileURLToPath(localDbUrl)), { recursive: true });
|
|
77
77
|
await writeFile(localDbUrl, "");
|
|
78
78
|
}
|
|
79
|
-
await
|
|
79
|
+
await typegenInternal({ tables: tables.get() ?? {}, root: config.root });
|
|
80
80
|
},
|
|
81
81
|
"astro:server:start": async ({ logger }) => {
|
|
82
82
|
setTimeout(() => {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { AstroConfig } from 'astro';
|
|
1
2
|
import type { DBTables } from '../types.js';
|
|
2
|
-
export declare function typegen(
|
|
3
|
+
export declare function typegen(astroConfig: Pick<AstroConfig, 'root' | 'integrations'>): Promise<void>;
|
|
4
|
+
export declare function typegenInternal({ tables, root }: {
|
|
3
5
|
tables: DBTables;
|
|
4
6
|
root: URL;
|
|
5
7
|
}): Promise<void>;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
3
|
import { DB_TYPES_FILE, RUNTIME_IMPORT } from "../consts.js";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { resolveDbConfig } from "../load-file.js";
|
|
5
|
+
async function typegen(astroConfig) {
|
|
6
|
+
const { dbConfig } = await resolveDbConfig(astroConfig);
|
|
7
|
+
await typegenInternal({ tables: dbConfig.tables, root: astroConfig.root });
|
|
8
|
+
}
|
|
9
|
+
async function typegenInternal({ tables, root }) {
|
|
10
|
+
const content = `// This file is generated by Astro DB
|
|
6
11
|
declare module 'astro:db' {
|
|
7
12
|
export const db: import(${RUNTIME_IMPORT}).SqliteDB;
|
|
8
13
|
export const dbUrl: string;
|
|
@@ -26,5 +31,6 @@ function generateTableType(name, collection) {
|
|
|
26
31
|
return tableType;
|
|
27
32
|
}
|
|
28
33
|
export {
|
|
29
|
-
typegen
|
|
34
|
+
typegen,
|
|
35
|
+
typegenInternal
|
|
30
36
|
};
|
|
@@ -94,7 +94,7 @@ function getStudioVirtualModContents({
|
|
|
94
94
|
return `
|
|
95
95
|
import {asDrizzleTable, createRemoteDatabaseClient} from ${RUNTIME_IMPORT};
|
|
96
96
|
|
|
97
|
-
export const db = await createRemoteDatabaseClient(${JSON.stringify(
|
|
97
|
+
export const db = await createRemoteDatabaseClient(process.env.ASTRO_STUDIO_APP_TOKEN ?? ${JSON.stringify(
|
|
98
98
|
appToken
|
|
99
99
|
// Respect runtime env for user overrides in SSR
|
|
100
100
|
)}, import.meta.env.ASTRO_STUDIO_REMOTE_DB_URL ?? ${JSON.stringify(getRemoteDatabaseUrl())});
|
|
@@ -33,7 +33,7 @@ async function setUpEnvTs({
|
|
|
33
33
|
typesEnvContents = `${dbTypeReference}
|
|
34
34
|
${typesEnvContents}`;
|
|
35
35
|
await writeFile(envTsPath, typesEnvContents, "utf-8");
|
|
36
|
-
logger.info(
|
|
36
|
+
logger.info(`Added ${bold(envTsPathRelativetoRoot)} types`);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
package/dist/core/load-file.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AstroConfig } from 'astro';
|
|
|
2
2
|
/**
|
|
3
3
|
* Load a user’s `astro:db` configuration file and additional configuration files provided by integrations.
|
|
4
4
|
*/
|
|
5
|
-
export declare function resolveDbConfig({ root, integrations }: AstroConfig): Promise<{
|
|
5
|
+
export declare function resolveDbConfig({ root, integrations, }: Pick<AstroConfig, 'root' | 'integrations'>): Promise<{
|
|
6
6
|
/** Resolved `astro:db` config, including tables added by integrations. */
|
|
7
7
|
dbConfig: {
|
|
8
8
|
tables: Record<string, {
|
package/dist/core/load-file.js
CHANGED
|
@@ -11,7 +11,10 @@ import { dbConfigSchema } from "./schemas.js";
|
|
|
11
11
|
import {} from "./types.js";
|
|
12
12
|
import { getDbDirectoryUrl } from "./utils.js";
|
|
13
13
|
const isDbIntegration = (integration) => "astro:db:setup" in integration.hooks;
|
|
14
|
-
async function resolveDbConfig({
|
|
14
|
+
async function resolveDbConfig({
|
|
15
|
+
root,
|
|
16
|
+
integrations
|
|
17
|
+
}) {
|
|
15
18
|
const { mod, dependencies } = await loadUserConfigFile(root);
|
|
16
19
|
const userDbConfig = dbConfigSchema.parse(mod?.default ?? {}, { errorMap });
|
|
17
20
|
const dbConfig = { tables: userDbConfig.tables ?? {} };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/db",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"mocha": "^10.2.0",
|
|
81
81
|
"typescript": "^5.2.2",
|
|
82
82
|
"vite": "^5.1.4",
|
|
83
|
-
"astro": "4.5.
|
|
83
|
+
"astro": "4.5.5",
|
|
84
84
|
"astro-scripts": "0.0.14"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|