@astrojs/db 0.7.2 → 0.8.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.
- package/dist/_internal/core/errors.d.ts +14 -0
- package/dist/_internal/core/integration/error-map.d.ts +6 -0
- package/dist/_internal/core/schemas.d.ts +3856 -0
- package/dist/_internal/core/types.d.ts +55 -0
- package/dist/_internal/runtime/config.d.ts +148 -0
- package/dist/_internal/runtime/db-client.d.ts +5 -0
- package/dist/_internal/runtime/index.d.ts +31 -0
- package/dist/_internal/runtime/queries.d.ts +71 -0
- package/dist/_internal/runtime/seed-local.d.ts +10 -0
- package/dist/_internal/runtime/types.d.ts +69 -0
- package/dist/core/cli/migration-queries.js +1 -2
- package/dist/core/cli/print-help.js +1 -1
- package/dist/core/integration/typegen.js +1 -2
- package/dist/core/load-file.d.ts +3 -3
- package/dist/core/load-file.js +2 -1
- package/dist/core/schemas.d.ts +3856 -0
- package/dist/core/schemas.js +151 -0
- package/dist/core/types.d.ts +2 -3855
- package/dist/core/types.js +0 -143
- package/dist/core/utils.js +1 -1
- package/package.json +11 -3
- package/virtual.d.ts +31 -7
package/dist/core/types.js
CHANGED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { SQL } from "drizzle-orm";
|
|
2
|
-
import { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import { SERIALIZED_SQL_KEY } from "../runtime/types.js";
|
|
5
|
-
import { errorMap } from "./integration/error-map.js";
|
|
6
|
-
const sqlite = new SQLiteAsyncDialect();
|
|
7
|
-
const sqlSchema = z.instanceof(SQL).transform(
|
|
8
|
-
(sqlObj) => ({
|
|
9
|
-
[SERIALIZED_SQL_KEY]: true,
|
|
10
|
-
sql: sqlite.sqlToQuery(sqlObj).sql
|
|
11
|
-
})
|
|
12
|
-
);
|
|
13
|
-
const baseColumnSchema = z.object({
|
|
14
|
-
label: z.string().optional(),
|
|
15
|
-
optional: z.boolean().optional().default(false),
|
|
16
|
-
unique: z.boolean().optional().default(false),
|
|
17
|
-
deprecated: z.boolean().optional().default(false),
|
|
18
|
-
// Defined when `defineReadableTable()` is called
|
|
19
|
-
name: z.string().optional(),
|
|
20
|
-
// TODO: rename to `tableName`. Breaking schema change
|
|
21
|
-
collection: z.string().optional()
|
|
22
|
-
});
|
|
23
|
-
const booleanColumnSchema = z.object({
|
|
24
|
-
type: z.literal("boolean"),
|
|
25
|
-
schema: baseColumnSchema.extend({
|
|
26
|
-
default: z.union([z.boolean(), sqlSchema]).optional()
|
|
27
|
-
})
|
|
28
|
-
});
|
|
29
|
-
const numberColumnBaseSchema = baseColumnSchema.omit({ optional: true }).and(
|
|
30
|
-
z.union([
|
|
31
|
-
z.object({
|
|
32
|
-
primaryKey: z.literal(false).optional().default(false),
|
|
33
|
-
optional: baseColumnSchema.shape.optional,
|
|
34
|
-
default: z.union([z.number(), sqlSchema]).optional()
|
|
35
|
-
}),
|
|
36
|
-
z.object({
|
|
37
|
-
// `integer primary key` uses ROWID as the default value.
|
|
38
|
-
// `optional` and `default` do not have an effect,
|
|
39
|
-
// so disable these config options for primary keys.
|
|
40
|
-
primaryKey: z.literal(true),
|
|
41
|
-
optional: z.literal(false).optional(),
|
|
42
|
-
default: z.literal(void 0).optional()
|
|
43
|
-
})
|
|
44
|
-
])
|
|
45
|
-
);
|
|
46
|
-
const numberColumnOptsSchema = numberColumnBaseSchema.and(
|
|
47
|
-
z.object({
|
|
48
|
-
references: z.function().returns(z.lazy(() => numberColumnSchema)).optional().transform((fn) => fn?.())
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
const numberColumnSchema = z.object({
|
|
52
|
-
type: z.literal("number"),
|
|
53
|
-
schema: numberColumnOptsSchema
|
|
54
|
-
});
|
|
55
|
-
const textColumnBaseSchema = baseColumnSchema.omit({ optional: true }).extend({
|
|
56
|
-
default: z.union([z.string(), sqlSchema]).optional(),
|
|
57
|
-
multiline: z.boolean().optional()
|
|
58
|
-
}).and(
|
|
59
|
-
z.union([
|
|
60
|
-
z.object({
|
|
61
|
-
primaryKey: z.literal(false).optional().default(false),
|
|
62
|
-
optional: baseColumnSchema.shape.optional
|
|
63
|
-
}),
|
|
64
|
-
z.object({
|
|
65
|
-
// text primary key allows NULL values.
|
|
66
|
-
// NULL values bypass unique checks, which could
|
|
67
|
-
// lead to duplicate URLs per record in Astro Studio.
|
|
68
|
-
// disable `optional` for primary keys.
|
|
69
|
-
primaryKey: z.literal(true),
|
|
70
|
-
optional: z.literal(false).optional()
|
|
71
|
-
})
|
|
72
|
-
])
|
|
73
|
-
);
|
|
74
|
-
const textColumnOptsSchema = textColumnBaseSchema.and(
|
|
75
|
-
z.object({
|
|
76
|
-
references: z.function().returns(z.lazy(() => textColumnSchema)).optional().transform((fn) => fn?.())
|
|
77
|
-
})
|
|
78
|
-
);
|
|
79
|
-
const textColumnSchema = z.object({
|
|
80
|
-
type: z.literal("text"),
|
|
81
|
-
schema: textColumnOptsSchema
|
|
82
|
-
});
|
|
83
|
-
const dateColumnSchema = z.object({
|
|
84
|
-
type: z.literal("date"),
|
|
85
|
-
schema: baseColumnSchema.extend({
|
|
86
|
-
default: z.union([
|
|
87
|
-
sqlSchema,
|
|
88
|
-
// transform to ISO string for serialization
|
|
89
|
-
z.date().transform((d) => d.toISOString())
|
|
90
|
-
]).optional()
|
|
91
|
-
})
|
|
92
|
-
});
|
|
93
|
-
const jsonColumnSchema = z.object({
|
|
94
|
-
type: z.literal("json"),
|
|
95
|
-
schema: baseColumnSchema.extend({
|
|
96
|
-
default: z.unknown().optional()
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
const columnSchema = z.union([
|
|
100
|
-
booleanColumnSchema,
|
|
101
|
-
numberColumnSchema,
|
|
102
|
-
textColumnSchema,
|
|
103
|
-
dateColumnSchema,
|
|
104
|
-
jsonColumnSchema
|
|
105
|
-
]);
|
|
106
|
-
const referenceableColumnSchema = z.union([textColumnSchema, numberColumnSchema]);
|
|
107
|
-
const columnsSchema = z.record(columnSchema);
|
|
108
|
-
const indexSchema = z.object({
|
|
109
|
-
on: z.string().or(z.array(z.string())),
|
|
110
|
-
unique: z.boolean().optional()
|
|
111
|
-
});
|
|
112
|
-
const foreignKeysSchema = z.object({
|
|
113
|
-
columns: z.string().or(z.array(z.string())),
|
|
114
|
-
references: z.function().returns(z.lazy(() => referenceableColumnSchema.or(z.array(referenceableColumnSchema)))).transform((fn) => fn())
|
|
115
|
-
});
|
|
116
|
-
const tableSchema = z.object({
|
|
117
|
-
columns: columnsSchema,
|
|
118
|
-
indexes: z.record(indexSchema).optional(),
|
|
119
|
-
foreignKeys: z.array(foreignKeysSchema).optional(),
|
|
120
|
-
deprecated: z.boolean().optional().default(false)
|
|
121
|
-
});
|
|
122
|
-
const tablesSchema = z.preprocess((rawTables) => {
|
|
123
|
-
const tables = z.record(z.any()).parse(rawTables, { errorMap });
|
|
124
|
-
for (const [tableName, table] of Object.entries(tables)) {
|
|
125
|
-
const { columns } = z.object({ columns: z.record(z.any()) }).parse(table, { errorMap });
|
|
126
|
-
for (const [columnName, column] of Object.entries(columns)) {
|
|
127
|
-
column.schema.name = columnName;
|
|
128
|
-
column.schema.collection = tableName;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return rawTables;
|
|
132
|
-
}, z.record(tableSchema));
|
|
133
|
-
const dbConfigSchema = z.object({
|
|
134
|
-
tables: tablesSchema.optional()
|
|
135
|
-
});
|
|
136
|
-
export {
|
|
137
|
-
columnSchema,
|
|
138
|
-
dbConfigSchema,
|
|
139
|
-
indexSchema,
|
|
140
|
-
referenceableColumnSchema,
|
|
141
|
-
tableSchema,
|
|
142
|
-
tablesSchema
|
|
143
|
-
};
|
package/dist/core/utils.js
CHANGED
|
@@ -9,7 +9,7 @@ function getRemoteDatabaseUrl() {
|
|
|
9
9
|
}
|
|
10
10
|
function getAstroStudioUrl() {
|
|
11
11
|
const env = getAstroStudioEnv();
|
|
12
|
-
return env.ASTRO_STUDIO_URL || "https://
|
|
12
|
+
return env.ASTRO_STUDIO_URL || "https://studio.astro.build";
|
|
13
13
|
}
|
|
14
14
|
function getDbDirectoryUrl(root) {
|
|
15
15
|
return new URL("db/", root);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
"./dist/runtime/config.js": {
|
|
24
24
|
"import": "./dist/runtime/config.js"
|
|
25
25
|
},
|
|
26
|
+
"./types": {
|
|
27
|
+
"types": "./dist/core/types.d.ts",
|
|
28
|
+
"import": "./dist/core/types.js"
|
|
29
|
+
},
|
|
26
30
|
"./package.json": "./package.json"
|
|
27
31
|
},
|
|
28
32
|
"typesVersions": {
|
|
@@ -30,6 +34,9 @@
|
|
|
30
34
|
".": [
|
|
31
35
|
"./index.d.ts"
|
|
32
36
|
],
|
|
37
|
+
"types": [
|
|
38
|
+
"./dist/types.d.ts"
|
|
39
|
+
],
|
|
33
40
|
"utils": [
|
|
34
41
|
"./dist/utils.d.ts"
|
|
35
42
|
],
|
|
@@ -73,11 +80,12 @@
|
|
|
73
80
|
"mocha": "^10.2.0",
|
|
74
81
|
"typescript": "^5.2.2",
|
|
75
82
|
"vite": "^5.1.4",
|
|
76
|
-
"astro": "4.5.
|
|
83
|
+
"astro": "4.5.2",
|
|
77
84
|
"astro-scripts": "0.0.14"
|
|
78
85
|
},
|
|
79
86
|
"scripts": {
|
|
80
|
-
"
|
|
87
|
+
"types:config": "tsc -p ./tsconfig.config-types.json",
|
|
88
|
+
"build": "astro-scripts build \"src/**/*.ts\" && tsc && pnpm types:config",
|
|
81
89
|
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
|
82
90
|
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
83
91
|
"test": "mocha --exit --timeout 20000 \"test/*.js\" \"test/unit/**/*.js\"",
|
package/virtual.d.ts
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
declare module 'astro:db' {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
2
|
+
type RuntimeConfig = typeof import('./dist/_internal/runtime/config.js');
|
|
3
|
+
|
|
4
|
+
export const sql: RuntimeConfig['sql'];
|
|
5
|
+
export const NOW: RuntimeConfig['NOW'];
|
|
6
|
+
export const TRUE: RuntimeConfig['TRUE'];
|
|
7
|
+
export const FALSE: RuntimeConfig['FALSE'];
|
|
8
|
+
export const column: RuntimeConfig['column'];
|
|
9
|
+
export const defineDb: RuntimeConfig['defineDb'];
|
|
10
|
+
export const defineTable: RuntimeConfig['defineTable'];
|
|
11
|
+
|
|
12
|
+
export const eq: RuntimeConfig['eq'];
|
|
13
|
+
export const gt: RuntimeConfig['gt'];
|
|
14
|
+
export const gte: RuntimeConfig['gte'];
|
|
15
|
+
export const lt: RuntimeConfig['lt'];
|
|
16
|
+
export const lte: RuntimeConfig['lte'];
|
|
17
|
+
export const ne: RuntimeConfig['ne'];
|
|
18
|
+
export const isNull: RuntimeConfig['isNull'];
|
|
19
|
+
export const isNotNull: RuntimeConfig['isNotNull'];
|
|
20
|
+
export const inArray: RuntimeConfig['inArray'];
|
|
21
|
+
export const notInArray: RuntimeConfig['notInArray'];
|
|
22
|
+
export const exists: RuntimeConfig['exists'];
|
|
23
|
+
export const notExists: RuntimeConfig['notExists'];
|
|
24
|
+
export const between: RuntimeConfig['between'];
|
|
25
|
+
export const notBetween: RuntimeConfig['notBetween'];
|
|
26
|
+
export const like: RuntimeConfig['like'];
|
|
27
|
+
export const notIlike: RuntimeConfig['notIlike'];
|
|
28
|
+
export const not: RuntimeConfig['not'];
|
|
29
|
+
export const asc: RuntimeConfig['asc'];
|
|
30
|
+
export const desc: RuntimeConfig['desc'];
|
|
31
|
+
export const and: RuntimeConfig['and'];
|
|
32
|
+
export const or: RuntimeConfig['or'];
|
|
9
33
|
}
|