@astrojs/db 0.3.5 → 0.4.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.
Files changed (61) hide show
  1. package/dist/core/cli/commands/link/index.js +7 -3
  2. package/dist/core/cli/commands/push/index.js +3 -3
  3. package/dist/core/cli/migration-queries.d.ts +4 -4
  4. package/dist/core/cli/migration-queries.js +73 -73
  5. package/dist/core/cli/migrations.js +15 -7
  6. package/dist/core/errors.js +7 -3
  7. package/dist/core/integration/file-url.js +2 -1
  8. package/dist/core/integration/index.js +106 -57
  9. package/dist/core/integration/typegen.d.ts +3 -3
  10. package/dist/core/integration/typegen.js +8 -8
  11. package/dist/core/integration/vite-plugin-db.d.ts +14 -9
  12. package/dist/core/integration/vite-plugin-db.js +15 -12
  13. package/dist/core/integration/vite-plugin-inject-env-ts.d.ts +4 -2
  14. package/dist/core/integration/vite-plugin-inject-env-ts.js +8 -4
  15. package/dist/core/queries.d.ts +12 -12
  16. package/dist/core/queries.js +49 -46
  17. package/dist/core/types.d.ts +232 -231
  18. package/dist/core/types.js +56 -55
  19. package/dist/core/utils.js +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +4 -4
  22. package/dist/runtime/db-client.d.ts +9 -4
  23. package/dist/runtime/db-client.js +11 -7
  24. package/dist/runtime/index.d.ts +7 -7
  25. package/dist/runtime/index.js +27 -29
  26. package/dist/runtime/types.d.ts +7 -7
  27. package/package.json +3 -5
  28. package/components/Renderer.astro +0 -14
  29. package/components/astro-env.d.ts +0 -1
  30. package/components/index.ts +0 -2
  31. package/components/tsconfig.json +0 -7
  32. package/dist/cli/commands/push/index.d.ts +0 -6
  33. package/dist/cli/commands/shell/index.d.ts +0 -6
  34. package/dist/cli/commands/sync/index.d.ts +0 -6
  35. package/dist/cli/commands/verify/index.d.ts +0 -6
  36. package/dist/cli/index.d.ts +0 -6
  37. package/dist/cli/queries.d.ts +0 -18
  38. package/dist/cli/seed.d.ts +0 -6
  39. package/dist/cli/sync/admin.d.ts +0 -33
  40. package/dist/cli/sync/index.d.ts +0 -1
  41. package/dist/cli/sync/migrate.d.ts +0 -1
  42. package/dist/cli/sync/queries.d.ts +0 -19
  43. package/dist/cli/sync/remote-db.d.ts +0 -1
  44. package/dist/config.d.ts +0 -1374
  45. package/dist/consts.d.ts +0 -7
  46. package/dist/core/cli/commands/sync/index.d.ts +0 -6
  47. package/dist/error-map.d.ts +0 -6
  48. package/dist/errors.d.ts +0 -3
  49. package/dist/file-url-integration.d.ts +0 -2
  50. package/dist/integration.d.ts +0 -2
  51. package/dist/internal-drizzle.d.ts +0 -1
  52. package/dist/internal.d.ts +0 -47
  53. package/dist/load-astro-config.d.ts +0 -6
  54. package/dist/migrations.d.ts +0 -12
  55. package/dist/root.d.ts +0 -3
  56. package/dist/typegen.d.ts +0 -5
  57. package/dist/types.d.ts +0 -1604
  58. package/dist/utils-runtime.d.ts +0 -1
  59. package/dist/utils.d.ts +0 -59
  60. package/dist/vite-plugin-db.d.ts +0 -19
  61. package/dist/vite-plugin-inject-env-ts.d.ts +0 -9
@@ -11,25 +11,25 @@ const sqlSchema = z.instanceof(SQL).transform(
11
11
  sql: sqlite.sqlToQuery(sqlObj).sql
12
12
  })
13
13
  );
14
- const baseFieldSchema = z.object({
14
+ const baseColumnSchema = z.object({
15
15
  label: z.string().optional(),
16
16
  optional: z.boolean().optional().default(false),
17
17
  unique: z.boolean().optional().default(false),
18
- // Defined when `defineCollection()` is called
18
+ // Defined when `defineReadableTable()` is called
19
19
  name: z.string().optional(),
20
20
  collection: z.string().optional()
21
21
  });
22
- const booleanFieldSchema = z.object({
22
+ const booleanColumnSchema = z.object({
23
23
  type: z.literal("boolean"),
24
- schema: baseFieldSchema.extend({
24
+ schema: baseColumnSchema.extend({
25
25
  default: z.union([z.boolean(), sqlSchema]).optional()
26
26
  })
27
27
  });
28
- const numberFieldBaseSchema = baseFieldSchema.omit({ optional: true }).and(
28
+ const numberColumnBaseSchema = baseColumnSchema.omit({ optional: true }).and(
29
29
  z.union([
30
30
  z.object({
31
31
  primaryKey: z.literal(false).optional().default(false),
32
- optional: baseFieldSchema.shape.optional,
32
+ optional: baseColumnSchema.shape.optional,
33
33
  default: z.union([z.number(), sqlSchema]).optional()
34
34
  }),
35
35
  z.object({
@@ -42,23 +42,23 @@ const numberFieldBaseSchema = baseFieldSchema.omit({ optional: true }).and(
42
42
  })
43
43
  ])
44
44
  );
45
- const numberFieldOptsSchema = numberFieldBaseSchema.and(
45
+ const numberColumnOptsSchema = numberColumnBaseSchema.and(
46
46
  z.object({
47
- references: z.function().returns(z.lazy(() => numberFieldSchema)).optional().transform((fn) => fn?.())
47
+ references: z.function().returns(z.lazy(() => numberColumnSchema)).optional().transform((fn) => fn?.())
48
48
  })
49
49
  );
50
- const numberFieldSchema = z.object({
50
+ const numberColumnSchema = z.object({
51
51
  type: z.literal("number"),
52
- schema: numberFieldOptsSchema
52
+ schema: numberColumnOptsSchema
53
53
  });
54
- const textFieldBaseSchema = baseFieldSchema.omit({ optional: true }).extend({
54
+ const textColumnBaseSchema = baseColumnSchema.omit({ optional: true }).extend({
55
55
  default: z.union([z.string(), sqlSchema]).optional(),
56
56
  multiline: z.boolean().optional()
57
57
  }).and(
58
58
  z.union([
59
59
  z.object({
60
60
  primaryKey: z.literal(false).optional().default(false),
61
- optional: baseFieldSchema.shape.optional
61
+ optional: baseColumnSchema.shape.optional
62
62
  }),
63
63
  z.object({
64
64
  // text primary key allows NULL values.
@@ -70,18 +70,18 @@ const textFieldBaseSchema = baseFieldSchema.omit({ optional: true }).extend({
70
70
  })
71
71
  ])
72
72
  );
73
- const textFieldOptsSchema = textFieldBaseSchema.and(
73
+ const textColumnOptsSchema = textColumnBaseSchema.and(
74
74
  z.object({
75
- references: z.function().returns(z.lazy(() => textFieldSchema)).optional().transform((fn) => fn?.())
75
+ references: z.function().returns(z.lazy(() => textColumnSchema)).optional().transform((fn) => fn?.())
76
76
  })
77
77
  );
78
- const textFieldSchema = z.object({
78
+ const textColumnSchema = z.object({
79
79
  type: z.literal("text"),
80
- schema: textFieldOptsSchema
80
+ schema: textColumnOptsSchema
81
81
  });
82
- const dateFieldSchema = z.object({
82
+ const dateColumnSchema = z.object({
83
83
  type: z.literal("date"),
84
- schema: baseFieldSchema.extend({
84
+ schema: baseColumnSchema.extend({
85
85
  default: z.union([
86
86
  sqlSchema,
87
87
  // transform to ISO string for serialization
@@ -89,31 +89,31 @@ const dateFieldSchema = z.object({
89
89
  ]).optional()
90
90
  })
91
91
  });
92
- const jsonFieldSchema = z.object({
92
+ const jsonColumnSchema = z.object({
93
93
  type: z.literal("json"),
94
- schema: baseFieldSchema.extend({
94
+ schema: baseColumnSchema.extend({
95
95
  default: z.unknown().optional()
96
96
  })
97
97
  });
98
- const fieldSchema = z.union([
99
- booleanFieldSchema,
100
- numberFieldSchema,
101
- textFieldSchema,
102
- dateFieldSchema,
103
- jsonFieldSchema
98
+ const columnSchema = z.union([
99
+ booleanColumnSchema,
100
+ numberColumnSchema,
101
+ textColumnSchema,
102
+ dateColumnSchema,
103
+ jsonColumnSchema
104
104
  ]);
105
- const referenceableFieldSchema = z.union([textFieldSchema, numberFieldSchema]);
106
- const fieldsSchema = z.record(fieldSchema);
105
+ const referenceableColumnSchema = z.union([textColumnSchema, numberColumnSchema]);
106
+ const columnsSchema = z.record(columnSchema);
107
107
  const indexSchema = z.object({
108
108
  on: z.string().or(z.array(z.string())),
109
109
  unique: z.boolean().optional()
110
110
  });
111
111
  const foreignKeysSchema = z.object({
112
- fields: z.string().or(z.array(z.string())),
113
- references: z.function().returns(z.lazy(() => referenceableFieldSchema.or(z.array(referenceableFieldSchema)))).transform((fn) => fn())
112
+ columns: z.string().or(z.array(z.string())),
113
+ references: z.function().returns(z.lazy(() => referenceableColumnSchema.or(z.array(referenceableColumnSchema)))).transform((fn) => fn())
114
114
  });
115
115
  const baseCollectionSchema = z.object({
116
- fields: fieldsSchema,
116
+ columns: columnsSchema,
117
117
  indexes: z.record(indexSchema).optional(),
118
118
  foreignKeys: z.array(foreignKeysSchema).optional()
119
119
  });
@@ -124,17 +124,17 @@ const writableCollectionSchema = baseCollectionSchema.extend({
124
124
  writable: z.literal(true)
125
125
  });
126
126
  const collectionSchema = z.union([readableCollectionSchema, writableCollectionSchema]);
127
- const collectionsSchema = z.preprocess((rawCollections) => {
128
- const collections = z.record(z.any()).parse(rawCollections, { errorMap });
129
- for (const [collectionName, collection] of Object.entries(collections)) {
127
+ const tablesSchema = z.preprocess((rawCollections) => {
128
+ const tables = z.record(z.any()).parse(rawCollections, { errorMap });
129
+ for (const [collectionName, collection] of Object.entries(tables)) {
130
130
  collection.table = collectionToTable(
131
131
  collectionName,
132
132
  collectionSchema.parse(collection, { errorMap })
133
133
  );
134
- const { fields } = z.object({ fields: z.record(z.any()) }).parse(collection, { errorMap });
135
- for (const [fieldName, field2] of Object.entries(fields)) {
136
- field2.schema.name = fieldName;
137
- field2.schema.collection = collectionName;
134
+ const { columns } = z.object({ columns: z.record(z.any()) }).parse(collection, { errorMap });
135
+ for (const [columnName, column2] of Object.entries(columns)) {
136
+ column2.schema.name = columnName;
137
+ column2.schema.collection = collectionName;
138
138
  }
139
139
  }
140
140
  return rawCollections;
@@ -142,10 +142,11 @@ const collectionsSchema = z.preprocess((rawCollections) => {
142
142
  function defineData(fn) {
143
143
  return fn;
144
144
  }
145
+ const dbDataFn = z.function().returns(z.union([z.void(), z.promise(z.void())]));
145
146
  const dbConfigSchema = z.object({
146
147
  studio: z.boolean().optional(),
147
- collections: collectionsSchema.optional(),
148
- data: z.function().returns(z.union([z.void(), z.promise(z.void())])).optional(),
148
+ tables: tablesSchema.optional(),
149
+ data: z.union([dbDataFn, z.array(dbDataFn)]).optional(),
149
150
  unsafeWritable: z.boolean().optional().default(false)
150
151
  });
151
152
  const astroConfigWithDbSchema = z.object({
@@ -159,13 +160,13 @@ function baseDefineCollection(userConfig, writable) {
159
160
  table: null
160
161
  };
161
162
  }
162
- function defineCollection(userConfig) {
163
+ function defineReadableTable(userConfig) {
163
164
  return baseDefineCollection(userConfig, false);
164
165
  }
165
- function defineWritableCollection(userConfig) {
166
+ function defineWritableTable(userConfig) {
166
167
  return baseDefineCollection(userConfig, true);
167
168
  }
168
- function createField(type, schema) {
169
+ function createColumn(type, schema) {
169
170
  return {
170
171
  type,
171
172
  /**
@@ -174,35 +175,35 @@ function createField(type, schema) {
174
175
  schema
175
176
  };
176
177
  }
177
- const field = {
178
+ const column = {
178
179
  number: (opts = {}) => {
179
- return createField("number", opts);
180
+ return createColumn("number", opts);
180
181
  },
181
182
  boolean: (opts = {}) => {
182
- return createField("boolean", opts);
183
+ return createColumn("boolean", opts);
183
184
  },
184
185
  text: (opts = {}) => {
185
- return createField("text", opts);
186
+ return createColumn("text", opts);
186
187
  },
187
188
  date(opts = {}) {
188
- return createField("date", opts);
189
+ return createColumn("date", opts);
189
190
  },
190
191
  json(opts = {}) {
191
- return createField("json", opts);
192
+ return createColumn("json", opts);
192
193
  }
193
194
  };
194
195
  export {
195
196
  astroConfigWithDbSchema,
196
197
  collectionSchema,
197
- collectionsSchema,
198
+ column,
199
+ columnSchema,
198
200
  dbConfigSchema,
199
- defineCollection,
200
201
  defineData,
201
- defineWritableCollection,
202
- field,
203
- fieldSchema,
202
+ defineReadableTable,
203
+ defineWritableTable,
204
204
  indexSchema,
205
205
  readableCollectionSchema,
206
- referenceableFieldSchema,
206
+ referenceableColumnSchema,
207
+ tablesSchema,
207
208
  writableCollectionSchema
208
209
  };
@@ -5,7 +5,7 @@ function getAstroStudioEnv(envMode = "") {
5
5
  }
6
6
  function getRemoteDatabaseUrl() {
7
7
  const env = getAstroStudioEnv();
8
- return env.ASTRO_STUDIO_REMOTE_DB_URL || "https://studio-gateway.fly.dev";
8
+ return env.ASTRO_STUDIO_REMOTE_DB_URL || "https://db.services.astro.build";
9
9
  }
10
10
  function getAstroStudioUrl() {
11
11
  const env = getAstroStudioEnv();
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { defineCollection, defineWritableCollection, defineData, field } from './core/types.js';
1
+ export { defineReadableTable, defineWritableTable, defineData, column } from './core/types.js';
2
2
  export type { ResolvedCollectionConfig, DBDataContext } from './core/types.js';
3
3
  export { cli } from './core/cli/index.js';
4
4
  export { integration as default } from './core/integration/index.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineCollection, defineWritableCollection, defineData, field } from "./core/types.js";
1
+ import { defineReadableTable, defineWritableTable, defineData, column } from "./core/types.js";
2
2
  import { cli } from "./core/cli/index.js";
3
3
  import { integration } from "./core/integration/index.js";
4
4
  import { sql, NOW, TRUE, FALSE } from "./runtime/index.js";
@@ -7,10 +7,10 @@ export {
7
7
  NOW,
8
8
  TRUE,
9
9
  cli,
10
+ column,
10
11
  integration as default,
11
- defineCollection,
12
12
  defineData,
13
- defineWritableCollection,
14
- field,
13
+ defineReadableTable,
14
+ defineWritableTable,
15
15
  sql
16
16
  };
@@ -1,7 +1,12 @@
1
- import { type DBCollections } from '../core/types.js';
2
- export declare function createLocalDatabaseClient({ collections, dbUrl, seeding, }: {
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { type DBTables } from '../core/types.js';
3
+ import type { LibSQLDatabase } from 'drizzle-orm/libsql';
4
+ interface LocalDatabaseClient extends LibSQLDatabase, Disposable {
5
+ }
6
+ export declare function createLocalDatabaseClient({ tables, dbUrl, seeding, }: {
3
7
  dbUrl: string;
4
- collections: DBCollections;
8
+ tables: DBTables;
5
9
  seeding: boolean;
6
- }): Promise<import("drizzle-orm/libsql").LibSQLDatabase<Record<string, never>>>;
10
+ }): Promise<LocalDatabaseClient>;
7
11
  export declare function createRemoteDatabaseClient(appToken: string, remoteDbURL: string): import("drizzle-orm/sqlite-proxy").SqliteRemoteDatabase<Record<string, never>>;
12
+ export {};
@@ -7,34 +7,38 @@ import { z } from "zod";
7
7
  import { getTableName } from "drizzle-orm";
8
8
  const isWebContainer = !!process.versions?.webcontainer;
9
9
  async function createLocalDatabaseClient({
10
- collections,
10
+ tables,
11
11
  dbUrl,
12
12
  seeding
13
13
  }) {
14
14
  const url = isWebContainer ? "file:content.db" : dbUrl;
15
15
  const client = createClient({ url });
16
- const db = drizzleLibsql(client);
16
+ const db = Object.assign(drizzleLibsql(client), {
17
+ [Symbol.dispose || Symbol.for("Symbol.dispose")]() {
18
+ client.close();
19
+ }
20
+ });
17
21
  if (seeding)
18
22
  return db;
19
23
  const { insert: drizzleInsert, update: drizzleUpdate, delete: drizzleDelete } = db;
20
24
  return Object.assign(db, {
21
25
  insert(Table) {
22
- checkIfModificationIsAllowed(collections, Table);
26
+ checkIfModificationIsAllowed(tables, Table);
23
27
  return drizzleInsert.call(this, Table);
24
28
  },
25
29
  update(Table) {
26
- checkIfModificationIsAllowed(collections, Table);
30
+ checkIfModificationIsAllowed(tables, Table);
27
31
  return drizzleUpdate.call(this, Table);
28
32
  },
29
33
  delete(Table) {
30
- checkIfModificationIsAllowed(collections, Table);
34
+ checkIfModificationIsAllowed(tables, Table);
31
35
  return drizzleDelete.call(this, Table);
32
36
  }
33
37
  });
34
38
  }
35
- function checkIfModificationIsAllowed(collections, Table) {
39
+ function checkIfModificationIsAllowed(tables, Table) {
36
40
  const tableName = getTableName(Table);
37
- const collection = collections[tableName];
41
+ const collection = tables[tableName];
38
42
  if (!collection.writable) {
39
43
  throw new Error(`The [${tableName}] collection is read-only.`);
40
44
  }
@@ -1,15 +1,15 @@
1
1
  import type { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
2
- import { type DBCollection, type DBField } from '../core/types.js';
3
- import { type ColumnDataType, sql, SQL } from 'drizzle-orm';
2
+ import { type DBTable, type DBColumn } from '../core/types.js';
3
+ import { type ColumnDataType, sql } from 'drizzle-orm';
4
4
  export { sql };
5
5
  export type SqliteDB = SqliteRemoteDatabase;
6
6
  export type { Table } from './types.js';
7
7
  export { createRemoteDatabaseClient, createLocalDatabaseClient } from './db-client.js';
8
- export declare function hasPrimaryKey(field: DBField): boolean;
9
- export declare const NOW: SQL<unknown>;
10
- export declare const TRUE: SQL<unknown>;
11
- export declare const FALSE: SQL<unknown>;
12
- export declare function collectionToTable(name: string, collection: DBCollection): import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
8
+ export declare function hasPrimaryKey(column: DBColumn): boolean;
9
+ export declare const NOW: import("drizzle-orm").SQL<unknown>;
10
+ export declare const TRUE: import("drizzle-orm").SQL<unknown>;
11
+ export declare const FALSE: import("drizzle-orm").SQL<unknown>;
12
+ export declare function collectionToTable(name: string, collection: DBTable): import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
13
13
  name: string;
14
14
  schema: undefined;
15
15
  columns: {
@@ -1,5 +1,5 @@
1
1
  import {} from "../core/types.js";
2
- import { sql, SQL } from "drizzle-orm";
2
+ import { sql } from "drizzle-orm";
3
3
  import {
4
4
  customType,
5
5
  integer,
@@ -7,11 +7,10 @@ import {
7
7
  text,
8
8
  index
9
9
  } from "drizzle-orm/sqlite-core";
10
- import { z } from "zod";
11
10
  import { isSerializedSQL } from "./types.js";
12
11
  import { createRemoteDatabaseClient, createLocalDatabaseClient } from "./db-client.js";
13
- function hasPrimaryKey(field) {
14
- return "primaryKey" in field.schema && !!field.schema.primaryKey;
12
+ function hasPrimaryKey(column) {
13
+ return "primaryKey" in column.schema && !!column.schema.primaryKey;
15
14
  }
16
15
  const NOW = sql`CURRENT_TIMESTAMP`;
17
16
  const TRUE = sql`TRUE`;
@@ -24,7 +23,6 @@ const dateType = customType({
24
23
  return value.toISOString();
25
24
  },
26
25
  fromDriver(value) {
27
- console.log("driver", value);
28
26
  return new Date(value);
29
27
  }
30
28
  });
@@ -41,11 +39,11 @@ const jsonType = customType({
41
39
  });
42
40
  function collectionToTable(name, collection) {
43
41
  const columns = {};
44
- if (!Object.entries(collection.fields).some(([, field]) => hasPrimaryKey(field))) {
42
+ if (!Object.entries(collection.columns).some(([, column]) => hasPrimaryKey(column))) {
45
43
  columns["_id"] = integer("_id").primaryKey();
46
44
  }
47
- for (const [fieldName, field] of Object.entries(collection.fields)) {
48
- columns[fieldName] = columnMapper(fieldName, field);
45
+ for (const [columnName, column] of Object.entries(collection.columns)) {
46
+ columns[columnName] = columnMapper(columnName, column);
49
47
  }
50
48
  const table = sqliteTable(name, columns, (ormTable) => {
51
49
  const indexes = {};
@@ -63,48 +61,48 @@ function collectionToTable(name, collection) {
63
61
  function atLeastOne(arr) {
64
62
  return arr.length > 0;
65
63
  }
66
- function columnMapper(fieldName, field) {
64
+ function columnMapper(columnName, column) {
67
65
  let c;
68
- switch (field.type) {
66
+ switch (column.type) {
69
67
  case "text": {
70
- c = text(fieldName);
71
- if (field.schema.default !== void 0)
72
- c = c.default(handleSerializedSQL(field.schema.default));
73
- if (field.schema.primaryKey === true)
68
+ c = text(columnName);
69
+ if (column.schema.default !== void 0)
70
+ c = c.default(handleSerializedSQL(column.schema.default));
71
+ if (column.schema.primaryKey === true)
74
72
  c = c.primaryKey();
75
73
  break;
76
74
  }
77
75
  case "number": {
78
- c = integer(fieldName);
79
- if (field.schema.default !== void 0)
80
- c = c.default(handleSerializedSQL(field.schema.default));
81
- if (field.schema.primaryKey === true)
76
+ c = integer(columnName);
77
+ if (column.schema.default !== void 0)
78
+ c = c.default(handleSerializedSQL(column.schema.default));
79
+ if (column.schema.primaryKey === true)
82
80
  c = c.primaryKey();
83
81
  break;
84
82
  }
85
83
  case "boolean": {
86
- c = integer(fieldName, { mode: "boolean" });
87
- if (field.schema.default !== void 0)
88
- c = c.default(handleSerializedSQL(field.schema.default));
84
+ c = integer(columnName, { mode: "boolean" });
85
+ if (column.schema.default !== void 0)
86
+ c = c.default(handleSerializedSQL(column.schema.default));
89
87
  break;
90
88
  }
91
89
  case "json":
92
- c = jsonType(fieldName);
93
- if (field.schema.default !== void 0)
94
- c = c.default(field.schema.default);
90
+ c = jsonType(columnName);
91
+ if (column.schema.default !== void 0)
92
+ c = c.default(column.schema.default);
95
93
  break;
96
94
  case "date": {
97
- c = dateType(fieldName);
98
- if (field.schema.default !== void 0) {
99
- const def = handleSerializedSQL(field.schema.default);
95
+ c = dateType(columnName);
96
+ if (column.schema.default !== void 0) {
97
+ const def = handleSerializedSQL(column.schema.default);
100
98
  c = c.default(typeof def === "string" ? new Date(def) : def);
101
99
  }
102
100
  break;
103
101
  }
104
102
  }
105
- if (!field.schema.optional)
103
+ if (!column.schema.optional)
106
104
  c = c.notNull();
107
- if (field.schema.unique)
105
+ if (column.schema.unique)
108
106
  c = c.unique();
109
107
  return c;
110
108
  }
@@ -1,6 +1,6 @@
1
1
  import type { ColumnDataType, ColumnBaseConfig } from 'drizzle-orm';
2
2
  import type { SQLiteColumn, SQLiteTableWithColumns } from 'drizzle-orm/sqlite-core';
3
- import type { DBField, FieldsConfig } from '../core/types.js';
3
+ import type { DBColumn, ColumnsConfig } from '../core/types.js';
4
4
  type GeneratedConfig<T extends ColumnDataType = ColumnDataType> = Pick<ColumnBaseConfig<T, string>, 'name' | 'tableName' | 'notNull' | 'hasDefault'>;
5
5
  export type AstroText<T extends GeneratedConfig<'string'>> = SQLiteColumn<T & {
6
6
  data: string;
@@ -42,21 +42,21 @@ export type AstroJson<T extends GeneratedConfig<'custom'>> = SQLiteColumn<T & {
42
42
  enumValues: never;
43
43
  baseColumn: never;
44
44
  }>;
45
- export type Column<T extends DBField['type'], S extends GeneratedConfig> = T extends 'boolean' ? AstroBoolean<S> : T extends 'number' ? AstroNumber<S> : T extends 'text' ? AstroText<S> : T extends 'date' ? AstroDate<S> : T extends 'json' ? AstroJson<S> : never;
46
- export type Table<TTableName extends string, TFields extends FieldsConfig> = SQLiteTableWithColumns<{
45
+ export type Column<T extends DBColumn['type'], S extends GeneratedConfig> = T extends 'boolean' ? AstroBoolean<S> : T extends 'number' ? AstroNumber<S> : T extends 'text' ? AstroText<S> : T extends 'date' ? AstroDate<S> : T extends 'json' ? AstroJson<S> : never;
46
+ export type Table<TTableName extends string, TColumns extends ColumnsConfig> = SQLiteTableWithColumns<{
47
47
  name: TTableName;
48
48
  schema: undefined;
49
49
  dialect: 'sqlite';
50
50
  columns: {
51
- [K in Extract<keyof TFields, string>]: Column<TFields[K]['type'], {
51
+ [K in Extract<keyof TColumns, string>]: Column<TColumns[K]['type'], {
52
52
  tableName: TTableName;
53
53
  name: K;
54
- hasDefault: TFields[K]['schema'] extends {
54
+ hasDefault: TColumns[K]['schema'] extends {
55
55
  default: NonNullable<unknown>;
56
- } ? true : TFields[K]['schema'] extends {
56
+ } ? true : TColumns[K]['schema'] extends {
57
57
  primaryKey: true;
58
58
  } ? true : false;
59
- notNull: TFields[K]['schema']['optional'] extends true ? false : true;
59
+ notNull: TColumns[K]['schema']['optional'] extends true ? false : true;
60
60
  }>;
61
61
  };
62
62
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/db",
3
- "version": "0.3.5",
3
+ "version": "0.4.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,7 +12,6 @@
12
12
  "types": "./index.d.ts",
13
13
  "import": "./dist/index.js"
14
14
  },
15
- "./components": "./components/index.ts",
16
15
  "./runtime": {
17
16
  "types": "./dist/runtime/index.d.ts",
18
17
  "import": "./dist/runtime/index.js"
@@ -39,8 +38,7 @@
39
38
  "files": [
40
39
  "index.d.ts",
41
40
  "config-augment.d.ts",
42
- "dist",
43
- "components"
41
+ "dist"
44
42
  ],
45
43
  "keywords": [
46
44
  "withastro",
@@ -70,7 +68,7 @@
70
68
  "mocha": "^10.2.0",
71
69
  "typescript": "^5.2.2",
72
70
  "vite": "^4.4.11",
73
- "astro": "4.4.0",
71
+ "astro": "4.4.4",
74
72
  "astro-scripts": "0.0.14"
75
73
  },
76
74
  "scripts": {
@@ -1,14 +0,0 @@
1
- ---
2
- import { Renderer as MarkdocRenderer } from '@astrojs/markdoc/components';
3
- import { Markdoc } from '@astrojs/markdoc/config';
4
-
5
- interface Props {
6
- content: string;
7
- }
8
-
9
- const { content } = Astro.props;
10
-
11
- const ast = Markdoc.parse(content);
12
- ---
13
-
14
- <MarkdocRenderer stringifiedAst={JSON.stringify(ast)} config={{}} />
@@ -1 +0,0 @@
1
- /// <reference types="astro/client" />
@@ -1,2 +0,0 @@
1
- // @ts-expect-error: missing types
2
- export { default as Renderer } from './Renderer.astro';
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "astro/tsconfigs/strict",
3
- "include": ["."],
4
- "compilerOptions": {
5
- "strictNullChecks": true
6
- }
7
- }
@@ -1,6 +0,0 @@
1
- import type { AstroConfig } from 'astro';
2
- import type { Arguments } from 'yargs-parser';
3
- export declare function cmd({ config, flags }: {
4
- config: AstroConfig;
5
- flags: Arguments;
6
- }): Promise<void>;
@@ -1,6 +0,0 @@
1
- import type { AstroConfig } from 'astro';
2
- import type { Arguments } from 'yargs-parser';
3
- export declare function cmd({ config, flags }: {
4
- config: AstroConfig;
5
- flags: Arguments;
6
- }): Promise<void>;
@@ -1,6 +0,0 @@
1
- import type { AstroConfig } from 'astro';
2
- import type { Arguments } from 'yargs-parser';
3
- export declare function cmd({ config }: {
4
- config: AstroConfig;
5
- flags: Arguments;
6
- }): Promise<void>;
@@ -1,6 +0,0 @@
1
- import type { AstroConfig } from 'astro';
2
- import type { Arguments } from 'yargs-parser';
3
- export declare function cmd({ config }: {
4
- config: AstroConfig;
5
- flags: Arguments;
6
- }): Promise<void>;
@@ -1,6 +0,0 @@
1
- import type { AstroConfig } from 'astro';
2
- import type { Arguments } from 'yargs-parser';
3
- export declare function cli({ flags, config }: {
4
- flags: Arguments;
5
- config: AstroConfig;
6
- }): Promise<void>;
@@ -1,18 +0,0 @@
1
- import type { DBCollection, DBSnapshot } from '../types.js';
2
- interface PromptResponses {
3
- allowDataLoss: boolean;
4
- columnRenames: Record<string, string | false>;
5
- collectionRenames: Record<string, string | false>;
6
- }
7
- export declare function getMigrationQueries({ oldSnapshot, newSnapshot, promptResponses, }: {
8
- oldSnapshot: DBSnapshot;
9
- newSnapshot: DBSnapshot;
10
- promptResponses?: PromptResponses;
11
- }): Promise<string[]>;
12
- export declare function getCollectionChangeQueries({ collectionName, oldCollection, newCollection, promptResponses, }: {
13
- collectionName: string;
14
- oldCollection: DBCollection;
15
- newCollection: DBCollection;
16
- promptResponses?: PromptResponses;
17
- }): Promise<string[]>;
18
- export {};
@@ -1,6 +0,0 @@
1
- import type { DBCollections } from 'circle-rhyme-yes-measure';
2
- export declare function seed({ collections, projectId, appToken, }: {
3
- collections: DBCollections;
4
- projectId: string;
5
- appToken: string;
6
- }): Promise<void>;