@astrojs/db 0.18.3 → 0.19.0-alpha.1

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.
@@ -2,5 +2,5 @@
2
2
  * This is a modified version of Astro's error map. source:
3
3
  * https://github.com/withastro/astro/blob/main/packages/astro/src/content/error-map.ts
4
4
  */
5
- import type { z } from 'astro/zod';
5
+ import type { z } from 'zod/v3';
6
6
  export declare const errorMap: z.ZodErrorMap;
@@ -1,5 +1,5 @@
1
1
  import { SQL } from 'drizzle-orm';
2
- import { type ZodTypeDef, z } from 'zod';
2
+ import { type ZodTypeDef, z } from 'zod/v3';
3
3
  import { type SerializedSQL } from '../runtime/types.js';
4
4
  import type { NumberColumn, TextColumn } from './types.js';
5
5
  export type MaybeArray<T> = T | T[];
@@ -1,4 +1,4 @@
1
- import type { z } from 'zod';
1
+ import type { z } from 'zod/v3';
2
2
  import type { booleanColumnSchema, columnSchema, columnsSchema, dateColumnSchema, dbConfigSchema, indexSchema, jsonColumnSchema, MaybeArray, numberColumnOptsSchema, numberColumnSchema, referenceableColumnSchema, resolvedIndexSchema, tableSchema, textColumnOptsSchema, textColumnSchema } from './schemas.js';
3
3
  export type ResolvedIndexes = z.output<typeof dbConfigSchema>['tables'][string]['indexes'];
4
4
  export type BooleanColumn = z.infer<typeof booleanColumnSchema>;
@@ -27,7 +27,7 @@ function printHelp({
27
27
  message.push(
28
28
  linebreak(),
29
29
  ` ${colors.bgGreen(colors.black(` ${commandName} `))} ${colors.green(
30
- `v${"0.18.3"}`
30
+ `v${"0.19.0-alpha.1"}`
31
31
  )} ${headline}`
32
32
  );
33
33
  }
@@ -1,4 +1,4 @@
1
- import z from "zod";
1
+ import z from "zod/v3";
2
2
  const rawLibSQLOptions = z.record(z.string());
3
3
  const parseNumber = (value) => z.coerce.number().parse(value);
4
4
  const parseBoolean = (value) => z.coerce.boolean().parse(value);
@@ -2,5 +2,5 @@
2
2
  * This is a modified version of Astro's error map. source:
3
3
  * https://github.com/withastro/astro/blob/main/packages/astro/src/content/error-map.ts
4
4
  */
5
- import type { z } from 'astro/zod';
5
+ import type { z } from 'zod/v3';
6
6
  export declare const errorMap: z.ZodErrorMap;
@@ -1,5 +1,5 @@
1
1
  import type { AstroIntegration } from 'astro';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  declare const astroDBConfigSchema: z.ZodDefault<z.ZodOptional<z.ZodObject<{
4
4
  /**
5
5
  * Sets the mode of the underlying `@libsql/client` connection.
@@ -9,7 +9,7 @@ import {
9
9
  mergeConfig
10
10
  } from "vite";
11
11
  import parseArgs from "yargs-parser";
12
- import { z } from "zod";
12
+ import { z } from "zod/v3";
13
13
  import { AstroDbError, isDbError } from "../../runtime/utils.js";
14
14
  import { CONFIG_FILE_NAMES, DB_PATH, VIRTUAL_MODULE_ID } from "../consts.js";
15
15
  import { EXEC_DEFAULT_EXPORT_ERROR, EXEC_ERROR } from "../errors.js";
@@ -117,8 +117,9 @@ function astroDBIntegration(options) {
117
117
  });
118
118
  },
119
119
  "astro:server:setup": async ({ server, logger }) => {
120
+ const environment = server.environments.ssr;
120
121
  seedHandler.execute = async (fileUrl) => {
121
- await executeSeedFile({ fileUrl, viteServer: server });
122
+ await executeSeedFile({ fileUrl, environment });
122
123
  };
123
124
  const filesToWatch = [
124
125
  ...CONFIG_FILE_NAMES.map((c) => new URL(c, getDbDirectoryUrl(root))),
@@ -130,20 +131,18 @@ function astroDBIntegration(options) {
130
131
  server.restart();
131
132
  }
132
133
  });
133
- setTimeout(() => {
134
- logger.info(
135
- connectToRemote ? "Connected to remote database." : "New local database created."
136
- );
137
- if (connectToRemote) return;
138
- const localSeedPaths = SEED_DEV_FILE_NAME.map(
139
- (name) => new URL(name, getDbDirectoryUrl(root))
140
- );
141
- if (seedFiles.get().length || localSeedPaths.find((path) => existsSync(path))) {
142
- server.ssrLoadModule(VIRTUAL_MODULE_ID).catch((e) => {
143
- logger.error(e instanceof Error ? e.message : String(e));
144
- });
145
- }
146
- }, 100);
134
+ logger.info(
135
+ connectToRemote ? "Connected to remote database." : "New local database created."
136
+ );
137
+ if (connectToRemote) return;
138
+ const localSeedPaths = SEED_DEV_FILE_NAME.map(
139
+ (name) => new URL(name, getDbDirectoryUrl(root))
140
+ );
141
+ if (seedFiles.get().length || localSeedPaths.find((path) => existsSync(path))) {
142
+ await environment.runner.import(VIRTUAL_MODULE_ID).catch((e) => {
143
+ logger.error(e instanceof Error ? e.message : String(e));
144
+ });
145
+ }
147
146
  },
148
147
  "astro:build:start": async ({ logger }) => {
149
148
  if (!connectToRemote && !databaseFileEnvDefined() && finalBuildOutput === "server") {
@@ -157,8 +156,9 @@ function astroDBIntegration(options) {
157
156
  },
158
157
  "astro:build:setup": async ({ vite }) => {
159
158
  tempViteServer = await getTempViteServer({ viteConfig: vite });
159
+ const environment = tempViteServer.environments.ssr;
160
160
  seedHandler.execute = async (fileUrl) => {
161
- await executeSeedFile({ fileUrl, viteServer: tempViteServer });
161
+ await executeSeedFile({ fileUrl, environment });
162
162
  };
163
163
  },
164
164
  "astro:build:done": async ({}) => {
@@ -176,10 +176,10 @@ function integration(options) {
176
176
  }
177
177
  async function executeSeedFile({
178
178
  fileUrl,
179
- viteServer
179
+ environment
180
180
  }) {
181
181
  const pathname = decodeURIComponent(fileUrl.pathname);
182
- const mod = await viteServer.ssrLoadModule(pathname);
182
+ const mod = await environment.runner.import(pathname);
183
183
  if (typeof mod.default !== "function") {
184
184
  throw new AstroDbError(EXEC_DEFAULT_EXPORT_ERROR(fileURLToPath(fileUrl)));
185
185
  }
@@ -201,8 +201,8 @@ async function getTempViteServer({ viteConfig }) {
201
201
  logLevel: "silent"
202
202
  })
203
203
  );
204
- const hotSend = tempViteServer.hot.send;
205
- tempViteServer.hot.send = (payload) => {
204
+ const hotSend = tempViteServer.environments.client.hot.send;
205
+ tempViteServer.environments.client.hot.send = (payload) => {
206
206
  if (payload.type === "error") {
207
207
  throw payload.err;
208
208
  }
@@ -18,10 +18,10 @@ export declare function resolveDbConfig({ root, integrations, }: Pick<AstroConfi
18
18
  optional: boolean;
19
19
  unique: boolean;
20
20
  deprecated: boolean;
21
- default?: boolean | import("../runtime/types.js").SerializedSQL | undefined;
22
21
  name?: string | undefined;
23
22
  label?: string | undefined;
24
23
  collection?: string | undefined;
24
+ default?: boolean | import("../runtime/types.js").SerializedSQL | undefined;
25
25
  };
26
26
  } | {
27
27
  type: "number";
@@ -37,8 +37,8 @@ export declare function resolveDbConfig({ root, integrations, }: Pick<AstroConfi
37
37
  default?: number | import("../runtime/types.js").SerializedSQL | undefined;
38
38
  } | {
39
39
  primaryKey: true;
40
- default?: undefined;
41
40
  optional?: false | undefined;
41
+ default?: undefined;
42
42
  })) & {
43
43
  references?: import("./types.js").NumberColumn;
44
44
  };
@@ -47,10 +47,10 @@ export declare function resolveDbConfig({ root, integrations, }: Pick<AstroConfi
47
47
  schema: ({
48
48
  unique: boolean;
49
49
  deprecated: boolean;
50
- default?: string | import("../runtime/types.js").SerializedSQL | undefined;
51
50
  name?: string | undefined;
52
51
  label?: string | undefined;
53
52
  collection?: string | undefined;
53
+ default?: string | import("../runtime/types.js").SerializedSQL | undefined;
54
54
  multiline?: boolean | undefined;
55
55
  enum?: [string, ...string[]] | undefined;
56
56
  } & ({
@@ -68,10 +68,10 @@ export declare function resolveDbConfig({ root, integrations, }: Pick<AstroConfi
68
68
  optional: boolean;
69
69
  unique: boolean;
70
70
  deprecated: boolean;
71
- default?: string | import("../runtime/types.js").SerializedSQL | undefined;
72
71
  name?: string | undefined;
73
72
  label?: string | undefined;
74
73
  collection?: string | undefined;
74
+ default?: string | import("../runtime/types.js").SerializedSQL | undefined;
75
75
  };
76
76
  } | {
77
77
  type: "json";
@@ -79,17 +79,17 @@ export declare function resolveDbConfig({ root, integrations, }: Pick<AstroConfi
79
79
  optional: boolean;
80
80
  unique: boolean;
81
81
  deprecated: boolean;
82
- default?: unknown;
83
82
  name?: string | undefined;
84
83
  label?: string | undefined;
85
84
  collection?: string | undefined;
85
+ default?: unknown;
86
86
  };
87
87
  }>;
88
88
  foreignKeys?: (Omit<{
89
89
  columns: import("./schemas.js").MaybeArray<string>;
90
- references: () => import("./schemas.js").MaybeArray<Omit<import("zod").input<typeof import("./schemas.js").referenceableColumnSchema>, "references">>;
90
+ references: () => import("./schemas.js").MaybeArray<Omit<import("zod/v3").input<typeof import("./schemas.js").referenceableColumnSchema>, "references">>;
91
91
  }, "references"> & {
92
- references: import("./schemas.js").MaybeArray<Omit<import("zod").output<typeof import("./schemas.js").referenceableColumnSchema>, "references">>;
92
+ references: import("./schemas.js").MaybeArray<Omit<import("zod/v3").output<typeof import("./schemas.js").referenceableColumnSchema>, "references">>;
93
93
  })[] | undefined;
94
94
  }>;
95
95
  };
@@ -19,8 +19,8 @@ export declare function getReferencesConfig(column: DBColumn): {
19
19
  default?: number | import("../runtime/types.js").SerializedSQL | undefined;
20
20
  } | {
21
21
  primaryKey: true;
22
- default?: undefined;
23
22
  optional?: false | undefined;
23
+ default?: undefined;
24
24
  })) & {
25
25
  references?: NumberColumn;
26
26
  };
@@ -29,10 +29,10 @@ export declare function getReferencesConfig(column: DBColumn): {
29
29
  schema: ({
30
30
  unique: boolean;
31
31
  deprecated: boolean;
32
- default?: string | import("../runtime/types.js").SerializedSQL | undefined;
33
32
  name?: string | undefined;
34
33
  label?: string | undefined;
35
34
  collection?: string | undefined;
35
+ default?: string | import("../runtime/types.js").SerializedSQL | undefined;
36
36
  multiline?: boolean | undefined;
37
37
  enum?: [string, ...string[]] | undefined;
38
38
  } & ({