@astrojs/db 0.1.4 → 0.1.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/consts.d.ts +1 -0
- package/dist/consts.js +3 -1
- package/dist/integration.js +7 -2
- package/dist/vite-plugin-db.js +17 -4
- package/package.json +1 -1
package/dist/consts.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export declare const INTERNAL_MOD_IMPORT: string;
|
|
|
3
3
|
export declare const DRIZZLE_MOD_IMPORT: string;
|
|
4
4
|
export declare const DB_TYPES_FILE = "db-types.d.ts";
|
|
5
5
|
export declare const VIRTUAL_MODULE_ID = "astro:db";
|
|
6
|
+
export declare const DB_PATH = ".astro/content.db";
|
|
6
7
|
export declare function getLocalDbUrl(root: URL): URL;
|
package/dist/consts.js
CHANGED
|
@@ -6,10 +6,12 @@ const INTERNAL_MOD_IMPORT = JSON.stringify(`${PACKAGE_NAME}/internal`);
|
|
|
6
6
|
const DRIZZLE_MOD_IMPORT = JSON.stringify(`${PACKAGE_NAME}/internal-drizzle`);
|
|
7
7
|
const DB_TYPES_FILE = "db-types.d.ts";
|
|
8
8
|
const VIRTUAL_MODULE_ID = "astro:db";
|
|
9
|
+
const DB_PATH = ".astro/content.db";
|
|
9
10
|
function getLocalDbUrl(root) {
|
|
10
|
-
return new URL(
|
|
11
|
+
return new URL(DB_PATH, root);
|
|
11
12
|
}
|
|
12
13
|
export {
|
|
14
|
+
DB_PATH,
|
|
13
15
|
DB_TYPES_FILE,
|
|
14
16
|
DRIZZLE_MOD_IMPORT,
|
|
15
17
|
INTERNAL_MOD_IMPORT,
|
package/dist/integration.js
CHANGED
|
@@ -3,7 +3,7 @@ import { vitePluginInjectEnvTs } from "./vite-plugin-inject-env-ts.js";
|
|
|
3
3
|
import { typegen } from "./typegen.js";
|
|
4
4
|
import { existsSync } from "fs";
|
|
5
5
|
import { mkdir, rm, writeFile } from "fs/promises";
|
|
6
|
-
import { getLocalDbUrl } from "./consts.js";
|
|
6
|
+
import { getLocalDbUrl, DB_PATH } from "./consts.js";
|
|
7
7
|
import { createLocalDatabaseClient, setupDbTables } from "./internal.js";
|
|
8
8
|
import { astroConfigWithDbSchema } from "./config.js";
|
|
9
9
|
import { getAstroStudioEnv } from "./utils.js";
|
|
@@ -36,7 +36,11 @@ function integration() {
|
|
|
36
36
|
logger.error(appTokenError);
|
|
37
37
|
process.exit(0);
|
|
38
38
|
}
|
|
39
|
-
dbPlugin = vitePluginDb({
|
|
39
|
+
dbPlugin = vitePluginDb({
|
|
40
|
+
connectToStudio: true,
|
|
41
|
+
collections,
|
|
42
|
+
appToken
|
|
43
|
+
});
|
|
40
44
|
} else {
|
|
41
45
|
const dbUrl = getLocalDbUrl(config.root);
|
|
42
46
|
if (existsSync(dbUrl)) {
|
|
@@ -61,6 +65,7 @@ function integration() {
|
|
|
61
65
|
}
|
|
62
66
|
updateConfig({
|
|
63
67
|
vite: {
|
|
68
|
+
assetsInclude: [DB_PATH],
|
|
64
69
|
plugins: [dbPlugin, vitePluginInjectEnvTs(config)]
|
|
65
70
|
}
|
|
66
71
|
});
|
package/dist/vite-plugin-db.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { DRIZZLE_MOD_IMPORT, INTERNAL_MOD_IMPORT, VIRTUAL_MODULE_ID } from "./consts.js";
|
|
1
|
+
import { DRIZZLE_MOD_IMPORT, INTERNAL_MOD_IMPORT, VIRTUAL_MODULE_ID, DB_PATH } from "./consts.js";
|
|
2
|
+
import fs from "node:fs";
|
|
2
3
|
const resolvedVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
|
|
3
4
|
function vitePluginDb(params) {
|
|
4
5
|
return {
|
|
@@ -16,6 +17,16 @@ function vitePluginDb(params) {
|
|
|
16
17
|
return getStudioVirtualModContents(params);
|
|
17
18
|
}
|
|
18
19
|
return getVirtualModContents(params);
|
|
20
|
+
},
|
|
21
|
+
async buildEnd() {
|
|
22
|
+
if ("dbUrl" in params) {
|
|
23
|
+
const data = await fs.promises.readFile(new URL(params.dbUrl));
|
|
24
|
+
this.emitFile({
|
|
25
|
+
fileName: "content.db",
|
|
26
|
+
source: data,
|
|
27
|
+
type: "asset"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
19
30
|
}
|
|
20
31
|
};
|
|
21
32
|
}
|
|
@@ -26,11 +37,13 @@ function getVirtualModContents({
|
|
|
26
37
|
return `
|
|
27
38
|
import { collectionToTable, createLocalDatabaseClient } from ${INTERNAL_MOD_IMPORT};
|
|
28
39
|
|
|
29
|
-
|
|
40
|
+
const params = ${JSON.stringify({
|
|
30
41
|
collections,
|
|
31
|
-
dbUrl,
|
|
32
42
|
seeding: false
|
|
33
|
-
})}
|
|
43
|
+
})};
|
|
44
|
+
|
|
45
|
+
params.dbUrl = new URL(${JSON.stringify(DB_PATH)}, 'file://' + process.cwd() + '/');
|
|
46
|
+
export const db = await createLocalDatabaseClient(params);
|
|
34
47
|
|
|
35
48
|
export * from ${DRIZZLE_MOD_IMPORT};
|
|
36
49
|
|