@astrojs/db 0.12.0 → 0.13.0
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/core/cli/commands/execute/index.d.ts +2 -2
- package/dist/core/cli/commands/login/index.d.ts +2 -2
- package/dist/core/cli/commands/push/index.d.ts +2 -2
- package/dist/core/cli/commands/shell/index.d.ts +2 -2
- package/dist/core/cli/commands/verify/index.d.ts +2 -2
- package/dist/core/cli/index.d.ts +2 -2
- package/dist/core/cli/print-help.js +1 -1
- package/dist/core/cli/types.d.ts +5 -0
- package/dist/core/cli/types.js +0 -0
- package/dist/core/integration/index.js +10 -8
- package/dist/core/integration/typegen.d.ts +1 -6
- package/dist/core/integration/typegen.js +4 -16
- package/dist/core/queries.js +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/runtime/db-client.js +3 -3
- package/package.json +6 -11
- package/dist/core/integration/vite-plugin-inject-env-ts.d.ts +0 -11
- package/dist/core/integration/vite-plugin-inject-env-ts.js +0 -52
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AstroConfig } from 'astro';
|
|
2
|
-
import type { Arguments } from 'yargs-parser';
|
|
3
2
|
import type { DBConfig } from '../../../types.js';
|
|
3
|
+
import type { YargsArguments } from '../../types.js';
|
|
4
4
|
export declare function cmd({ astroConfig, dbConfig, flags, }: {
|
|
5
5
|
astroConfig: AstroConfig;
|
|
6
6
|
dbConfig: DBConfig;
|
|
7
|
-
flags:
|
|
7
|
+
flags: YargsArguments;
|
|
8
8
|
}): Promise<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AstroConfig } from 'astro';
|
|
2
|
-
import type { Arguments } from 'yargs-parser';
|
|
3
2
|
import type { DBConfig } from '../../../types.js';
|
|
3
|
+
import type { YargsArguments } from '../../types.js';
|
|
4
4
|
export declare function cmd({ flags, }: {
|
|
5
5
|
astroConfig: AstroConfig;
|
|
6
6
|
dbConfig: DBConfig;
|
|
7
|
-
flags:
|
|
7
|
+
flags: YargsArguments;
|
|
8
8
|
}): Promise<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AstroConfig } from 'astro';
|
|
2
|
-
import type { Arguments } from 'yargs-parser';
|
|
3
2
|
import { type DBConfig } from '../../../types.js';
|
|
3
|
+
import type { YargsArguments } from '../../types.js';
|
|
4
4
|
export declare function cmd({ dbConfig, flags, }: {
|
|
5
5
|
astroConfig: AstroConfig;
|
|
6
6
|
dbConfig: DBConfig;
|
|
7
|
-
flags:
|
|
7
|
+
flags: YargsArguments;
|
|
8
8
|
}): Promise<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AstroConfig } from 'astro';
|
|
2
|
-
import type { Arguments } from 'yargs-parser';
|
|
3
2
|
import type { DBConfigInput } from '../../../types.js';
|
|
3
|
+
import type { YargsArguments } from '../../types.js';
|
|
4
4
|
export declare function cmd({ flags, astroConfig, }: {
|
|
5
5
|
dbConfig: DBConfigInput;
|
|
6
6
|
astroConfig: AstroConfig;
|
|
7
|
-
flags:
|
|
7
|
+
flags: YargsArguments;
|
|
8
8
|
}): Promise<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AstroConfig } from 'astro';
|
|
2
|
-
import type { Arguments } from 'yargs-parser';
|
|
3
2
|
import type { DBConfig } from '../../../types.js';
|
|
3
|
+
import type { YargsArguments } from '../../types.js';
|
|
4
4
|
export declare function cmd({ dbConfig, flags, }: {
|
|
5
5
|
astroConfig: AstroConfig;
|
|
6
6
|
dbConfig: DBConfig;
|
|
7
|
-
flags:
|
|
7
|
+
flags: YargsArguments;
|
|
8
8
|
}): Promise<void>;
|
package/dist/core/cli/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AstroConfig } from 'astro';
|
|
2
|
-
import type {
|
|
2
|
+
import type { YargsArguments } from './types.js';
|
|
3
3
|
export declare function cli({ flags, config: astroConfig, }: {
|
|
4
|
-
flags:
|
|
4
|
+
flags: YargsArguments;
|
|
5
5
|
config: AstroConfig;
|
|
6
6
|
}): Promise<void>;
|
|
File without changes
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
2
3
|
import { dirname } from "path";
|
|
3
4
|
import { fileURLToPath } from "url";
|
|
4
5
|
import { getManagedAppTokenOrExit } from "@astrojs/studio";
|
|
@@ -10,7 +11,6 @@ import {
|
|
|
10
11
|
loadEnv,
|
|
11
12
|
mergeConfig
|
|
12
13
|
} from "vite";
|
|
13
|
-
import parseArgs from "yargs-parser";
|
|
14
14
|
import { AstroDbError } from "../../runtime/utils.js";
|
|
15
15
|
import { CONFIG_FILE_NAMES, DB_PATH } from "../consts.js";
|
|
16
16
|
import { EXEC_DEFAULT_EXPORT_ERROR, EXEC_ERROR } from "../errors.js";
|
|
@@ -18,12 +18,11 @@ import { resolveDbConfig } from "../load-file.js";
|
|
|
18
18
|
import { SEED_DEV_FILE_NAME } from "../queries.js";
|
|
19
19
|
import { getDbDirectoryUrl } from "../utils.js";
|
|
20
20
|
import { fileURLIntegration } from "./file-url.js";
|
|
21
|
-
import {
|
|
21
|
+
import { getDtsContent } from "./typegen.js";
|
|
22
22
|
import {
|
|
23
23
|
resolved,
|
|
24
24
|
vitePluginDb
|
|
25
25
|
} from "./vite-plugin-db.js";
|
|
26
|
-
import { vitePluginInjectEnvTs } from "./vite-plugin-inject-env-ts.js";
|
|
27
26
|
function astroDBIntegration() {
|
|
28
27
|
let connectToStudio = false;
|
|
29
28
|
let configFileDependencies = [];
|
|
@@ -57,8 +56,8 @@ function astroDBIntegration() {
|
|
|
57
56
|
output = config.output;
|
|
58
57
|
if (command === "preview") return;
|
|
59
58
|
let dbPlugin = void 0;
|
|
60
|
-
const args = parseArgs(
|
|
61
|
-
connectToStudio = process.env.ASTRO_INTERNAL_TEST_REMOTE || args
|
|
59
|
+
const args = parseArgs({ strict: false });
|
|
60
|
+
connectToStudio = !!process.env.ASTRO_INTERNAL_TEST_REMOTE || !!args.values.remote;
|
|
62
61
|
if (connectToStudio) {
|
|
63
62
|
appToken = await getManagedAppTokenOrExit();
|
|
64
63
|
dbPlugin = vitePluginDb({
|
|
@@ -85,11 +84,11 @@ function astroDBIntegration() {
|
|
|
85
84
|
updateConfig({
|
|
86
85
|
vite: {
|
|
87
86
|
assetsInclude: [DB_PATH],
|
|
88
|
-
plugins: [dbPlugin
|
|
87
|
+
plugins: [dbPlugin]
|
|
89
88
|
}
|
|
90
89
|
});
|
|
91
90
|
},
|
|
92
|
-
"astro:config:done": async ({ config }) => {
|
|
91
|
+
"astro:config:done": async ({ config, injectTypes }) => {
|
|
93
92
|
if (command === "preview") return;
|
|
94
93
|
const { dbConfig, dependencies, integrationSeedPaths } = await resolveDbConfig(config);
|
|
95
94
|
tables.get = () => dbConfig.tables;
|
|
@@ -100,7 +99,10 @@ function astroDBIntegration() {
|
|
|
100
99
|
await mkdir(dirname(fileURLToPath(localDbUrl)), { recursive: true });
|
|
101
100
|
await writeFile(localDbUrl, "");
|
|
102
101
|
}
|
|
103
|
-
|
|
102
|
+
injectTypes({
|
|
103
|
+
filename: "db.d.ts",
|
|
104
|
+
content: getDtsContent(tables.get() ?? {})
|
|
105
|
+
});
|
|
104
106
|
},
|
|
105
107
|
"astro:server:setup": async ({ server, logger }) => {
|
|
106
108
|
seedHandler.execute = async (fileUrl) => {
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import type { AstroConfig } from 'astro';
|
|
2
1
|
import type { DBTables } from '../types.js';
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function typegenInternal({ tables, root }: {
|
|
5
|
-
tables: DBTables;
|
|
6
|
-
root: URL;
|
|
7
|
-
}): Promise<void>;
|
|
2
|
+
export declare function getDtsContent(tables: DBTables): string;
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { DB_TYPES_FILE, RUNTIME_IMPORT } from "../consts.js";
|
|
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 }) {
|
|
1
|
+
import { RUNTIME_IMPORT } from "../consts.js";
|
|
2
|
+
function getDtsContent(tables) {
|
|
10
3
|
const content = `// This file is generated by Astro DB
|
|
11
4
|
declare module 'astro:db' {
|
|
12
5
|
${Object.entries(tables).map(([name, table]) => generateTableType(name, table)).join("\n")}
|
|
13
6
|
}
|
|
14
7
|
`;
|
|
15
|
-
|
|
16
|
-
if (!existsSync(dotAstroDir)) {
|
|
17
|
-
await mkdir(dotAstroDir);
|
|
18
|
-
}
|
|
19
|
-
await writeFile(new URL(DB_TYPES_FILE, dotAstroDir), content);
|
|
8
|
+
return content;
|
|
20
9
|
}
|
|
21
10
|
function generateTableType(name, table) {
|
|
22
11
|
const sanitizedColumnsList = Object.entries(table.columns).filter(([, val]) => !val.schema.deprecated);
|
|
@@ -28,6 +17,5 @@ function generateTableType(name, table) {
|
|
|
28
17
|
return tableType;
|
|
29
18
|
}
|
|
30
19
|
export {
|
|
31
|
-
|
|
32
|
-
typegenInternal
|
|
20
|
+
getDtsContent
|
|
33
21
|
};
|
package/dist/core/queries.js
CHANGED
|
@@ -143,7 +143,7 @@ function getDefaultValueSql(columnName, column) {
|
|
|
143
143
|
let stringified = "";
|
|
144
144
|
try {
|
|
145
145
|
stringified = JSON.stringify(column.schema.default);
|
|
146
|
-
} catch
|
|
146
|
+
} catch {
|
|
147
147
|
console.log(
|
|
148
148
|
`Invalid default value for column ${bold(
|
|
149
149
|
columnName
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -53,7 +53,7 @@ function createRemoteDatabaseClient(appToken, remoteDbURL) {
|
|
|
53
53
|
try {
|
|
54
54
|
const json = await res.json();
|
|
55
55
|
remoteResult = remoteResultSchema.parse(json);
|
|
56
|
-
} catch
|
|
56
|
+
} catch {
|
|
57
57
|
throw new DetailedLibsqlError({
|
|
58
58
|
message: await getUnexpectedResponseMessage(res),
|
|
59
59
|
code: KNOWN_ERROR_CODES.SQL_QUERY_FAILED
|
|
@@ -103,7 +103,7 @@ function createRemoteDatabaseClient(appToken, remoteDbURL) {
|
|
|
103
103
|
try {
|
|
104
104
|
const json = await res.json();
|
|
105
105
|
remoteResults = z.array(remoteResultSchema).parse(json);
|
|
106
|
-
} catch
|
|
106
|
+
} catch {
|
|
107
107
|
throw new DetailedLibsqlError({
|
|
108
108
|
message: await getUnexpectedResponseMessage(res),
|
|
109
109
|
code: KNOWN_ERROR_CODES.SQL_QUERY_FAILED
|
|
@@ -148,7 +148,7 @@ async function parseRemoteError(response) {
|
|
|
148
148
|
let error;
|
|
149
149
|
try {
|
|
150
150
|
error = errorSchema.parse(await response.clone().json()).error;
|
|
151
|
-
} catch
|
|
151
|
+
} catch {
|
|
152
152
|
return new DetailedLibsqlError({
|
|
153
153
|
message: await getUnexpectedResponseMessage(response),
|
|
154
154
|
code: KNOWN_ERROR_CODES.SQL_QUERY_FAILED
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Add libSQL and Astro Studio support to your Astro site",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -62,9 +62,8 @@
|
|
|
62
62
|
"astro-integration"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@libsql/client": "^0.
|
|
65
|
+
"@libsql/client": "^0.9.0",
|
|
66
66
|
"async-listen": "^3.0.1",
|
|
67
|
-
"ci-info": "^4.0.0",
|
|
68
67
|
"deep-diff": "^1.0.2",
|
|
69
68
|
"drizzle-orm": "^0.31.2",
|
|
70
69
|
"github-slugger": "^2.0.0",
|
|
@@ -74,20 +73,16 @@
|
|
|
74
73
|
"ora": "^8.0.1",
|
|
75
74
|
"prompts": "^2.4.2",
|
|
76
75
|
"strip-ansi": "^7.1.0",
|
|
77
|
-
"yargs-parser": "^21.1.1",
|
|
78
76
|
"zod": "^3.23.8",
|
|
79
77
|
"@astrojs/studio": "0.1.1"
|
|
80
78
|
},
|
|
81
79
|
"devDependencies": {
|
|
82
|
-
"@types/chai": "^4.3.16",
|
|
83
80
|
"@types/deep-diff": "^1.0.5",
|
|
84
|
-
"@types/diff": "^5.2.1",
|
|
85
81
|
"@types/prompts": "^2.4.9",
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"astro": "4.12.0",
|
|
82
|
+
"cheerio": "1.0.0",
|
|
83
|
+
"typescript": "^5.5.4",
|
|
84
|
+
"vite": "^5.4.0",
|
|
85
|
+
"astro": "4.14.0",
|
|
91
86
|
"astro-scripts": "0.0.14"
|
|
92
87
|
},
|
|
93
88
|
"scripts": {
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AstroIntegrationLogger } from 'astro';
|
|
2
|
-
import type { VitePlugin } from '../utils.js';
|
|
3
|
-
export declare function vitePluginInjectEnvTs({ srcDir, root }: {
|
|
4
|
-
srcDir: URL;
|
|
5
|
-
root: URL;
|
|
6
|
-
}, logger: AstroIntegrationLogger): VitePlugin;
|
|
7
|
-
export declare function setUpEnvTs({ srcDir, root, logger, }: {
|
|
8
|
-
srcDir: URL;
|
|
9
|
-
root: URL;
|
|
10
|
-
logger: AstroIntegrationLogger;
|
|
11
|
-
}): Promise<void>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { bold } from "kleur/colors";
|
|
6
|
-
import { normalizePath } from "vite";
|
|
7
|
-
import { DB_TYPES_FILE } from "../consts.js";
|
|
8
|
-
function vitePluginInjectEnvTs({ srcDir, root }, logger) {
|
|
9
|
-
return {
|
|
10
|
-
name: "db-inject-env-ts",
|
|
11
|
-
enforce: "post",
|
|
12
|
-
async config() {
|
|
13
|
-
await setUpEnvTs({ srcDir, root, logger });
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
async function setUpEnvTs({
|
|
18
|
-
srcDir,
|
|
19
|
-
root,
|
|
20
|
-
logger
|
|
21
|
-
}) {
|
|
22
|
-
const envTsPath = getEnvTsPath({ srcDir });
|
|
23
|
-
const envTsPathRelativetoRoot = normalizePath(
|
|
24
|
-
path.relative(fileURLToPath(root), fileURLToPath(envTsPath))
|
|
25
|
-
);
|
|
26
|
-
if (existsSync(envTsPath)) {
|
|
27
|
-
let typesEnvContents = await readFile(envTsPath, "utf-8");
|
|
28
|
-
const dotAstroDir = new URL(".astro/", root);
|
|
29
|
-
if (!existsSync(dotAstroDir)) return;
|
|
30
|
-
const dbTypeReference = getDBTypeReference({ srcDir, dotAstroDir });
|
|
31
|
-
if (!typesEnvContents.includes(dbTypeReference)) {
|
|
32
|
-
typesEnvContents = `${dbTypeReference}
|
|
33
|
-
${typesEnvContents}`;
|
|
34
|
-
await writeFile(envTsPath, typesEnvContents, "utf-8");
|
|
35
|
-
logger.info(`Added ${bold(envTsPathRelativetoRoot)} types`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function getDBTypeReference({ srcDir, dotAstroDir }) {
|
|
40
|
-
const dbTypesFile = new URL(DB_TYPES_FILE, dotAstroDir);
|
|
41
|
-
const contentTypesRelativeToSrcDir = normalizePath(
|
|
42
|
-
path.relative(fileURLToPath(srcDir), fileURLToPath(dbTypesFile))
|
|
43
|
-
);
|
|
44
|
-
return `/// <reference path=${JSON.stringify(contentTypesRelativeToSrcDir)} />`;
|
|
45
|
-
}
|
|
46
|
-
function getEnvTsPath({ srcDir }) {
|
|
47
|
-
return new URL("env.d.ts", srcDir);
|
|
48
|
-
}
|
|
49
|
-
export {
|
|
50
|
-
setUpEnvTs,
|
|
51
|
-
vitePluginInjectEnvTs
|
|
52
|
-
};
|