@astrojs/db 0.19.0 → 0.20.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/_internal/core/integration/error-map.d.ts +2 -6
- package/dist/_internal/core/schemas.d.ts +334 -1913
- package/dist/_internal/core/types.d.ts +1 -1
- package/dist/core/cli/commands/push/index.js +5 -6
- package/dist/core/cli/print-help.js +1 -1
- package/dist/core/db-client/utils.js +3 -3
- package/dist/core/integration/error-map.d.ts +2 -6
- package/dist/core/integration/error-map.js +67 -43
- package/dist/core/integration/file-url.js +5 -2
- package/dist/core/integration/index.d.ts +4 -15
- package/dist/core/integration/index.js +23 -23
- package/dist/core/integration/vite-plugin-db-client.js +19 -11
- package/dist/core/integration/vite-plugin-db.js +43 -35
- package/dist/core/load-file.d.ts +13 -13
- package/dist/core/load-file.js +2 -2
- package/dist/core/queries.d.ts +4 -4
- package/dist/core/schemas.d.ts +506 -2085
- package/dist/core/schemas.js +22 -17
- package/dist/core/types.d.ts +1 -1
- package/package.json +7 -8
package/dist/core/schemas.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SQL } from "drizzle-orm";
|
|
2
2
|
import { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core";
|
|
3
|
-
import
|
|
3
|
+
import * as z from "zod/v4";
|
|
4
4
|
import { SERIALIZED_SQL_KEY } from "../runtime/types.js";
|
|
5
5
|
import { errorMap } from "./integration/error-map.js";
|
|
6
6
|
import { mapObject } from "./utils.js";
|
|
@@ -46,7 +46,7 @@ const numberColumnBaseSchema = baseColumnSchema.omit({ optional: true }).and(
|
|
|
46
46
|
);
|
|
47
47
|
const numberColumnOptsSchema = numberColumnBaseSchema.and(
|
|
48
48
|
z.object({
|
|
49
|
-
references: z.function(
|
|
49
|
+
references: z.function({ output: z.lazy(() => numberColumnSchema) }).optional().transform((fn) => fn?.())
|
|
50
50
|
})
|
|
51
51
|
);
|
|
52
52
|
const numberColumnSchema = z.object({
|
|
@@ -76,7 +76,7 @@ const textColumnBaseSchema = baseColumnSchema.omit({ optional: true }).extend({
|
|
|
76
76
|
);
|
|
77
77
|
const textColumnOptsSchema = textColumnBaseSchema.and(
|
|
78
78
|
z.object({
|
|
79
|
-
references: z.function(
|
|
79
|
+
references: z.function({ output: z.lazy(() => textColumnSchema) }).optional().transform((fn) => fn?.())
|
|
80
80
|
})
|
|
81
81
|
);
|
|
82
82
|
const textColumnSchema = z.object({
|
|
@@ -107,16 +107,18 @@ const columnSchema = z.discriminatedUnion("type", [
|
|
|
107
107
|
jsonColumnSchema
|
|
108
108
|
]);
|
|
109
109
|
const referenceableColumnSchema = z.union([textColumnSchema, numberColumnSchema]);
|
|
110
|
-
const columnsSchema = z.record(columnSchema);
|
|
110
|
+
const columnsSchema = z.record(z.string(), columnSchema);
|
|
111
111
|
const foreignKeysSchema = z.object({
|
|
112
112
|
columns: z.string().or(z.array(z.string())),
|
|
113
|
-
references: z.function(
|
|
113
|
+
references: z.function({
|
|
114
|
+
output: z.lazy(() => referenceableColumnSchema.or(z.array(referenceableColumnSchema)))
|
|
115
|
+
}).transform((fn) => fn())
|
|
114
116
|
});
|
|
115
117
|
const resolvedIndexSchema = z.object({
|
|
116
118
|
on: z.string().or(z.array(z.string())),
|
|
117
119
|
unique: z.boolean().optional()
|
|
118
120
|
});
|
|
119
|
-
const legacyIndexesSchema = z.record(resolvedIndexSchema);
|
|
121
|
+
const legacyIndexesSchema = z.record(z.string(), resolvedIndexSchema);
|
|
120
122
|
const indexSchema = z.object({
|
|
121
123
|
on: z.string().or(z.array(z.string())),
|
|
122
124
|
unique: z.boolean().optional(),
|
|
@@ -129,18 +131,21 @@ const tableSchema = z.object({
|
|
|
129
131
|
foreignKeys: z.array(foreignKeysSchema).optional(),
|
|
130
132
|
deprecated: z.boolean().optional().default(false)
|
|
131
133
|
});
|
|
132
|
-
const tablesSchema = z.preprocess(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
table
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
column.
|
|
139
|
-
|
|
134
|
+
const tablesSchema = z.preprocess(
|
|
135
|
+
(rawTables) => {
|
|
136
|
+
const tables = z.record(z.string(), z.any()).parse(rawTables, { error: errorMap });
|
|
137
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
138
|
+
table.getName = () => tableName;
|
|
139
|
+
const { columns } = z.object({ columns: z.record(z.string(), z.any()) }).parse(table, { error: errorMap });
|
|
140
|
+
for (const [columnName, column] of Object.entries(columns)) {
|
|
141
|
+
column.schema.name = columnName;
|
|
142
|
+
column.schema.collection = tableName;
|
|
143
|
+
}
|
|
140
144
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
return rawTables;
|
|
146
|
+
},
|
|
147
|
+
z.record(z.string(), tableSchema)
|
|
148
|
+
);
|
|
144
149
|
const dbConfigSchema = z.object({
|
|
145
150
|
tables: tablesSchema.optional()
|
|
146
151
|
}).transform(({ tables = {}, ...config }) => {
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type * as z from 'zod/v4';
|
|
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>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Add libSQL support to your Astro site",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -63,24 +63,23 @@
|
|
|
63
63
|
"astro-integration"
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
|
+
"@clack/prompts": "^1.0.1",
|
|
66
67
|
"@libsql/client": "^0.17.0",
|
|
67
68
|
"deep-diff": "^1.0.2",
|
|
68
69
|
"drizzle-orm": "^0.42.0",
|
|
69
70
|
"nanoid": "^5.1.6",
|
|
70
71
|
"piccolore": "^0.1.3",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"zod": "^3.25.76"
|
|
72
|
+
"yargs-parser": "^22.0.0",
|
|
73
|
+
"zod": "^4.3.6"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/deep-diff": "^1.0.5",
|
|
77
|
-
"@types/prompts": "^2.4.9",
|
|
78
77
|
"@types/yargs-parser": "^21.0.3",
|
|
79
|
-
"cheerio": "1.
|
|
78
|
+
"cheerio": "1.2.0",
|
|
80
79
|
"expect-type": "^1.3.0",
|
|
81
80
|
"typescript": "^5.9.3",
|
|
82
|
-
"vite": "^
|
|
83
|
-
"astro": "
|
|
81
|
+
"vite": "^7.3.1",
|
|
82
|
+
"astro": "6.0.0",
|
|
84
83
|
"astro-scripts": "0.0.14"
|
|
85
84
|
},
|
|
86
85
|
"scripts": {
|