@astrojs/db 0.3.3 → 0.3.5

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.
@@ -13,8 +13,8 @@ const sqlSchema = z.instanceof(SQL).transform(
13
13
  );
14
14
  const baseFieldSchema = z.object({
15
15
  label: z.string().optional(),
16
- optional: z.boolean().optional(),
17
- unique: z.boolean().optional(),
16
+ optional: z.boolean().optional().default(false),
17
+ unique: z.boolean().optional().default(false),
18
18
  // Defined when `defineCollection()` is called
19
19
  name: z.string().optional(),
20
20
  collection: z.string().optional()
@@ -28,8 +28,8 @@ const booleanFieldSchema = z.object({
28
28
  const numberFieldBaseSchema = baseFieldSchema.omit({ optional: true }).and(
29
29
  z.union([
30
30
  z.object({
31
- primaryKey: z.literal(false).optional(),
32
- optional: z.boolean().optional(),
31
+ primaryKey: z.literal(false).optional().default(false),
32
+ optional: baseFieldSchema.shape.optional,
33
33
  default: z.union([z.number(), sqlSchema]).optional()
34
34
  }),
35
35
  z.object({
@@ -57,8 +57,8 @@ const textFieldBaseSchema = baseFieldSchema.omit({ optional: true }).extend({
57
57
  }).and(
58
58
  z.union([
59
59
  z.object({
60
- primaryKey: z.literal(false).optional(),
61
- optional: z.boolean().optional()
60
+ primaryKey: z.literal(false).optional().default(false),
61
+ optional: baseFieldSchema.shape.optional
62
62
  }),
63
63
  z.object({
64
64
  // text primary key allows NULL values.
@@ -84,9 +84,8 @@ const dateFieldSchema = z.object({
84
84
  schema: baseFieldSchema.extend({
85
85
  default: z.union([
86
86
  sqlSchema,
87
- // allow date-like defaults in user config,
88
- // transform to ISO string for D1 storage
89
- z.coerce.date().transform((d) => d.toISOString())
87
+ // transform to ISO string for serialization
88
+ z.date().transform((d) => d.toISOString())
90
89
  ]).optional()
91
90
  })
92
91
  });
@@ -146,7 +145,8 @@ function defineData(fn) {
146
145
  const dbConfigSchema = z.object({
147
146
  studio: z.boolean().optional(),
148
147
  collections: collectionsSchema.optional(),
149
- data: z.function().returns(z.union([z.void(), z.promise(z.void())])).optional()
148
+ data: z.function().returns(z.union([z.void(), z.promise(z.void())])).optional(),
149
+ unsafeWritable: z.boolean().optional().default(false)
150
150
  });
151
151
  const astroConfigWithDbSchema = z.object({
152
152
  db: dbConfigSchema.optional()
@@ -200,6 +200,7 @@ export {
200
200
  defineData,
201
201
  defineWritableCollection,
202
202
  field,
203
+ fieldSchema,
203
204
  indexSchema,
204
205
  readableCollectionSchema,
205
206
  referenceableFieldSchema,
@@ -1,12 +1,12 @@
1
1
  import type { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
2
- import { type BooleanField, type DBCollection, type DBCollections, type DBField, type DateField, type FieldType, type JsonField, type NumberField, type TextField } from './types.js';
2
+ import { type BooleanColumn, type DBCollection, type DBCollections, type DBColumn, type DateColumn, type ColumnType, type JsonColumn, type NumberColumn, type TextColumn } from './types.js';
3
3
  import { type SQL, type ColumnDataType } from 'drizzle-orm';
4
4
  import type { AstroIntegrationLogger } from 'astro';
5
5
  import type { DBUserConfig } from './config.js';
6
6
  export type SqliteDB = SqliteRemoteDatabase;
7
7
  export type { Table } from './types.js';
8
8
  export { createRemoteDatabaseClient } from './utils-runtime.js';
9
- export declare function hasPrimaryKey(field: DBField): boolean;
9
+ export declare function hasPrimaryKey(column: DBColumn): boolean;
10
10
  export declare function createLocalDatabaseClient({ collections, dbUrl, seeding, }: {
11
11
  dbUrl: string;
12
12
  collections: DBCollections;
@@ -21,11 +21,11 @@ export declare function setupDbTables({ db, data, collections, logger, mode, }:
21
21
  }): Promise<void>;
22
22
  export declare function getCreateTableQuery(collectionName: string, collection: DBCollection): string;
23
23
  export declare function getTableIndexQueries(collectionName: string, collection: DBCollection): SQL<unknown>[];
24
- export declare function schemaTypeToSqlType(type: FieldType): 'text' | 'integer';
25
- export declare function getModifiers(fieldName: string, field: DBField): string;
26
- type WithDefaultDefined<T extends DBField> = T & Required<Pick<T, 'default'>>;
27
- type DBFieldWithDefault = WithDefaultDefined<TextField> | WithDefaultDefined<DateField> | WithDefaultDefined<NumberField> | WithDefaultDefined<BooleanField> | WithDefaultDefined<JsonField>;
28
- export declare function hasDefault(field: DBField): field is DBFieldWithDefault;
24
+ export declare function schemaTypeToSqlType(type: ColumnType): 'text' | 'integer';
25
+ export declare function getModifiers(columnName: string, column: DBColumn): string;
26
+ type WithDefaultDefined<T extends DBColumn> = T & Required<Pick<T, 'default'>>;
27
+ type DBColumnWithDefault = WithDefaultDefined<TextColumn> | WithDefaultDefined<DateColumn> | WithDefaultDefined<NumberColumn> | WithDefaultDefined<BooleanColumn> | WithDefaultDefined<JsonColumn>;
28
+ export declare function hasDefault(column: DBColumn): column is DBColumnWithDefault;
29
29
  export declare function collectionToTable(name: string, collection: DBCollection, isJsonSerializable?: boolean): import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
30
30
  name: string;
31
31
  schema: undefined;
@@ -9,7 +9,7 @@ export declare function hasPrimaryKey(field: DBField): boolean;
9
9
  export declare const NOW: SQL<unknown>;
10
10
  export declare const TRUE: SQL<unknown>;
11
11
  export declare const FALSE: SQL<unknown>;
12
- export declare function collectionToTable(name: string, collection: DBCollection, isJsonSerializable?: boolean): import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
12
+ export declare function collectionToTable(name: string, collection: DBCollection): import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
13
13
  name: string;
14
14
  schema: undefined;
15
15
  columns: {
@@ -24,6 +24,7 @@ const dateType = customType({
24
24
  return value.toISOString();
25
25
  },
26
26
  fromDriver(value) {
27
+ console.log("driver", value);
27
28
  return new Date(value);
28
29
  }
29
30
  });
@@ -38,13 +39,13 @@ const jsonType = customType({
38
39
  return JSON.parse(value);
39
40
  }
40
41
  });
41
- function collectionToTable(name, collection, isJsonSerializable = true) {
42
+ function collectionToTable(name, collection) {
42
43
  const columns = {};
43
44
  if (!Object.entries(collection.fields).some(([, field]) => hasPrimaryKey(field))) {
44
45
  columns["_id"] = integer("_id").primaryKey();
45
46
  }
46
47
  for (const [fieldName, field] of Object.entries(collection.fields)) {
47
- columns[fieldName] = columnMapper(fieldName, field, isJsonSerializable);
48
+ columns[fieldName] = columnMapper(fieldName, field);
48
49
  }
49
50
  const table = sqliteTable(name, columns, (ormTable) => {
50
51
  const indexes = {};
@@ -62,7 +63,7 @@ function collectionToTable(name, collection, isJsonSerializable = true) {
62
63
  function atLeastOne(arr) {
63
64
  return arr.length > 0;
64
65
  }
65
- function columnMapper(fieldName, field, isJsonSerializable) {
66
+ function columnMapper(fieldName, field) {
66
67
  let c;
67
68
  switch (field.type) {
68
69
  case "text": {
@@ -93,23 +94,10 @@ function columnMapper(fieldName, field, isJsonSerializable) {
93
94
  c = c.default(field.schema.default);
94
95
  break;
95
96
  case "date": {
96
- if (isJsonSerializable) {
97
- c = text(fieldName);
98
- if (field.schema.default !== void 0) {
99
- c = c.default(handleSerializedSQL(field.schema.default));
100
- }
101
- } else {
102
- c = dateType(fieldName);
103
- if (field.schema.default !== void 0) {
104
- const def = handleSerializedSQL(field.schema.default);
105
- c = c.default(
106
- def instanceof SQL ? def : (
107
- // default comes pre-transformed to an ISO string for D1 storage.
108
- // parse back to a Date for Drizzle.
109
- z.coerce.date().parse(field.schema.default)
110
- )
111
- );
112
- }
97
+ c = dateType(fieldName);
98
+ if (field.schema.default !== void 0) {
99
+ const def = handleSerializedSQL(field.schema.default);
100
+ c = c.default(typeof def === "string" ? new Date(def) : def);
113
101
  }
114
102
  break;
115
103
  }
@@ -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 } from '../core/types.js';
3
+ import type { DBField, FieldsConfig } 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;
@@ -43,7 +43,7 @@ export type AstroJson<T extends GeneratedConfig<'custom'>> = SQLiteColumn<T & {
43
43
  baseColumn: never;
44
44
  }>;
45
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 Record<string, Pick<DBField, 'type' | 'schema'>>> = SQLiteTableWithColumns<{
46
+ export type Table<TTableName extends string, TFields extends FieldsConfig> = SQLiteTableWithColumns<{
47
47
  name: TTableName;
48
48
  schema: undefined;
49
49
  dialect: 'sqlite';
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ColumnDataType, ColumnBaseConfig } from 'drizzle-orm';
2
2
  import type { SQLiteColumn, SQLiteTableWithColumns } from 'drizzle-orm/sqlite-core';
3
3
  import { z } from 'zod';
4
- declare const booleanFieldSchema: z.ZodObject<{
4
+ declare const booleanColumnSchema: z.ZodObject<{
5
5
  label: z.ZodOptional<z.ZodString>;
6
6
  optional: z.ZodOptional<z.ZodBoolean>;
7
7
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -20,7 +20,7 @@ declare const booleanFieldSchema: z.ZodObject<{
20
20
  unique?: boolean | undefined;
21
21
  default?: boolean | undefined;
22
22
  }>;
23
- declare const numberFieldSchema: z.ZodObject<{
23
+ declare const numberColumnSchema: z.ZodObject<{
24
24
  label: z.ZodOptional<z.ZodString>;
25
25
  optional: z.ZodOptional<z.ZodBoolean>;
26
26
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -42,7 +42,7 @@ declare const numberFieldSchema: z.ZodObject<{
42
42
  default?: number | undefined;
43
43
  primaryKey?: boolean | undefined;
44
44
  }>;
45
- declare const textFieldSchema: z.ZodObject<{
45
+ declare const textColumnSchema: z.ZodObject<{
46
46
  label: z.ZodOptional<z.ZodString>;
47
47
  optional: z.ZodOptional<z.ZodBoolean>;
48
48
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -67,7 +67,7 @@ declare const textFieldSchema: z.ZodObject<{
67
67
  default?: string | undefined;
68
68
  primaryKey?: boolean | undefined;
69
69
  }>;
70
- declare const dateFieldSchema: z.ZodObject<{
70
+ declare const dateColumnSchema: z.ZodObject<{
71
71
  label: z.ZodOptional<z.ZodString>;
72
72
  optional: z.ZodOptional<z.ZodBoolean>;
73
73
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -86,7 +86,7 @@ declare const dateFieldSchema: z.ZodObject<{
86
86
  unique?: boolean | undefined;
87
87
  default?: Date | "now" | undefined;
88
88
  }>;
89
- declare const jsonFieldSchema: z.ZodObject<{
89
+ declare const jsonColumnSchema: z.ZodObject<{
90
90
  label: z.ZodOptional<z.ZodString>;
91
91
  optional: z.ZodOptional<z.ZodBoolean>;
92
92
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -105,7 +105,7 @@ declare const jsonFieldSchema: z.ZodObject<{
105
105
  unique?: boolean | undefined;
106
106
  default?: unknown;
107
107
  }>;
108
- declare const fieldSchema: z.ZodUnion<[z.ZodObject<{
108
+ declare const columnSchema: z.ZodUnion<[z.ZodObject<{
109
109
  label: z.ZodOptional<z.ZodString>;
110
110
  optional: z.ZodOptional<z.ZodBoolean>;
111
111
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -205,7 +205,7 @@ declare const fieldSchema: z.ZodUnion<[z.ZodObject<{
205
205
  unique?: boolean | undefined;
206
206
  default?: unknown;
207
207
  }>]>;
208
- declare const fieldsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
208
+ declare const columnsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
209
209
  label: z.ZodOptional<z.ZodString>;
210
210
  optional: z.ZodOptional<z.ZodBoolean>;
211
211
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -316,7 +316,7 @@ export declare const indexSchema: z.ZodObject<{
316
316
  unique?: boolean | undefined;
317
317
  }>;
318
318
  export declare const readableCollectionSchema: z.ZodObject<{
319
- fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
319
+ columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
320
320
  label: z.ZodOptional<z.ZodString>;
321
321
  optional: z.ZodOptional<z.ZodBoolean>;
322
322
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -430,7 +430,7 @@ export declare const readableCollectionSchema: z.ZodObject<{
430
430
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
431
431
  writable: z.ZodLiteral<false>;
432
432
  }, "strip", z.ZodTypeAny, {
433
- fields: Record<string, {
433
+ columns: Record<string, {
434
434
  type: "boolean";
435
435
  label?: string | undefined;
436
436
  optional?: boolean | undefined;
@@ -472,7 +472,7 @@ export declare const readableCollectionSchema: z.ZodObject<{
472
472
  table?: any;
473
473
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
474
474
  }, {
475
- fields: Record<string, {
475
+ columns: Record<string, {
476
476
  type: "boolean";
477
477
  label?: string | undefined;
478
478
  optional?: boolean | undefined;
@@ -515,7 +515,7 @@ export declare const readableCollectionSchema: z.ZodObject<{
515
515
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
516
516
  }>;
517
517
  export declare const writableCollectionSchema: z.ZodObject<{
518
- fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
518
+ columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
519
519
  label: z.ZodOptional<z.ZodString>;
520
520
  optional: z.ZodOptional<z.ZodBoolean>;
521
521
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -629,7 +629,7 @@ export declare const writableCollectionSchema: z.ZodObject<{
629
629
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
630
630
  writable: z.ZodLiteral<true>;
631
631
  }, "strip", z.ZodTypeAny, {
632
- fields: Record<string, {
632
+ columns: Record<string, {
633
633
  type: "boolean";
634
634
  label?: string | undefined;
635
635
  optional?: boolean | undefined;
@@ -671,7 +671,7 @@ export declare const writableCollectionSchema: z.ZodObject<{
671
671
  table?: any;
672
672
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
673
673
  }, {
674
- fields: Record<string, {
674
+ columns: Record<string, {
675
675
  type: "boolean";
676
676
  label?: string | undefined;
677
677
  optional?: boolean | undefined;
@@ -714,7 +714,7 @@ export declare const writableCollectionSchema: z.ZodObject<{
714
714
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
715
715
  }>;
716
716
  export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
717
- fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
717
+ columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
718
718
  label: z.ZodOptional<z.ZodString>;
719
719
  optional: z.ZodOptional<z.ZodBoolean>;
720
720
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -828,7 +828,7 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
828
828
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
829
829
  writable: z.ZodLiteral<false>;
830
830
  }, "strip", z.ZodTypeAny, {
831
- fields: Record<string, {
831
+ columns: Record<string, {
832
832
  type: "boolean";
833
833
  label?: string | undefined;
834
834
  optional?: boolean | undefined;
@@ -870,7 +870,7 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
870
870
  table?: any;
871
871
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
872
872
  }, {
873
- fields: Record<string, {
873
+ columns: Record<string, {
874
874
  type: "boolean";
875
875
  label?: string | undefined;
876
876
  optional?: boolean | undefined;
@@ -912,7 +912,7 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
912
912
  table?: any;
913
913
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
914
914
  }>, z.ZodObject<{
915
- fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
915
+ columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
916
916
  label: z.ZodOptional<z.ZodString>;
917
917
  optional: z.ZodOptional<z.ZodBoolean>;
918
918
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -1026,7 +1026,7 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
1026
1026
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
1027
1027
  writable: z.ZodLiteral<true>;
1028
1028
  }, "strip", z.ZodTypeAny, {
1029
- fields: Record<string, {
1029
+ columns: Record<string, {
1030
1030
  type: "boolean";
1031
1031
  label?: string | undefined;
1032
1032
  optional?: boolean | undefined;
@@ -1068,7 +1068,7 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
1068
1068
  table?: any;
1069
1069
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1070
1070
  }, {
1071
- fields: Record<string, {
1071
+ columns: Record<string, {
1072
1072
  type: "boolean";
1073
1073
  label?: string | undefined;
1074
1074
  optional?: boolean | undefined;
@@ -1111,7 +1111,7 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
1111
1111
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1112
1112
  }>]>;
1113
1113
  export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
1114
- fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
1114
+ columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
1115
1115
  label: z.ZodOptional<z.ZodString>;
1116
1116
  optional: z.ZodOptional<z.ZodBoolean>;
1117
1117
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -1225,7 +1225,7 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1225
1225
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
1226
1226
  writable: z.ZodLiteral<false>;
1227
1227
  }, "strip", z.ZodTypeAny, {
1228
- fields: Record<string, {
1228
+ columns: Record<string, {
1229
1229
  type: "boolean";
1230
1230
  label?: string | undefined;
1231
1231
  optional?: boolean | undefined;
@@ -1267,7 +1267,7 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1267
1267
  table?: any;
1268
1268
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1269
1269
  }, {
1270
- fields: Record<string, {
1270
+ columns: Record<string, {
1271
1271
  type: "boolean";
1272
1272
  label?: string | undefined;
1273
1273
  optional?: boolean | undefined;
@@ -1309,7 +1309,7 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1309
1309
  table?: any;
1310
1310
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1311
1311
  }>, z.ZodObject<{
1312
- fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
1312
+ columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
1313
1313
  label: z.ZodOptional<z.ZodString>;
1314
1314
  optional: z.ZodOptional<z.ZodBoolean>;
1315
1315
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -1423,7 +1423,7 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1423
1423
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
1424
1424
  writable: z.ZodLiteral<true>;
1425
1425
  }, "strip", z.ZodTypeAny, {
1426
- fields: Record<string, {
1426
+ columns: Record<string, {
1427
1427
  type: "boolean";
1428
1428
  label?: string | undefined;
1429
1429
  optional?: boolean | undefined;
@@ -1465,7 +1465,7 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1465
1465
  table?: any;
1466
1466
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1467
1467
  }, {
1468
- fields: Record<string, {
1468
+ columns: Record<string, {
1469
1469
  type: "boolean";
1470
1470
  label?: string | undefined;
1471
1471
  optional?: boolean | undefined;
@@ -1507,16 +1507,16 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1507
1507
  table?: any;
1508
1508
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1509
1509
  }>]>>;
1510
- export type BooleanField = z.infer<typeof booleanFieldSchema>;
1511
- export type NumberField = z.infer<typeof numberFieldSchema>;
1512
- export type TextField = z.infer<typeof textFieldSchema>;
1513
- export type DateField = z.infer<typeof dateFieldSchema>;
1514
- export type DateFieldInput = z.input<typeof dateFieldSchema>;
1515
- export type JsonField = z.infer<typeof jsonFieldSchema>;
1516
- export type FieldType = BooleanField['type'] | NumberField['type'] | TextField['type'] | DateField['type'] | JsonField['type'];
1517
- export type DBField = z.infer<typeof fieldSchema>;
1518
- export type DBFieldInput = DateFieldInput | BooleanField | NumberField | TextField | JsonField;
1519
- export type DBFields = z.infer<typeof fieldsSchema>;
1510
+ export type BooleanColumn = z.infer<typeof booleanColumnSchema>;
1511
+ export type NumberColumn = z.infer<typeof numberColumnSchema>;
1512
+ export type TextColumn = z.infer<typeof textColumnSchema>;
1513
+ export type DateColumn = z.infer<typeof dateColumnSchema>;
1514
+ export type DateColumnInput = z.input<typeof dateColumnSchema>;
1515
+ export type JsonColumn = z.infer<typeof jsonColumnSchema>;
1516
+ export type ColumnType = BooleanColumn['type'] | NumberColumn['type'] | TextColumn['type'] | DateColumn['type'] | JsonColumn['type'];
1517
+ export type DBColumn = z.infer<typeof columnSchema>;
1518
+ export type DBColumnInput = DateColumnInput | BooleanColumn | NumberColumn | TextColumn | JsonColumn;
1519
+ export type DBColumns = z.infer<typeof columnsSchema>;
1520
1520
  export type DBCollection = z.infer<typeof readableCollectionSchema | typeof writableCollectionSchema>;
1521
1521
  export type DBCollections = Record<string, DBCollection>;
1522
1522
  export type DBSnapshot = {
@@ -1583,8 +1583,8 @@ export type AstroId<T extends Pick<GeneratedConfig<'string'>, 'tableName'>> = SQ
1583
1583
  }>;
1584
1584
  export type MaybePromise<T> = T | Promise<T>;
1585
1585
  export type MaybeArray<T> = T | T[];
1586
- 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;
1587
- export type Table<TTableName extends string, TFields extends Record<string, Pick<DBField, 'type' | 'default' | 'optional'>>> = SQLiteTableWithColumns<{
1586
+ 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;
1587
+ export type Table<TTableName extends string, TColumns extends Record<string, Pick<DBColumn, 'type' | 'default' | 'optional'>>> = SQLiteTableWithColumns<{
1588
1588
  name: TTableName;
1589
1589
  schema: undefined;
1590
1590
  dialect: 'sqlite';
@@ -1593,11 +1593,11 @@ export type Table<TTableName extends string, TFields extends Record<string, Pick
1593
1593
  tableName: TTableName;
1594
1594
  }>;
1595
1595
  } & {
1596
- [K in Extract<keyof TFields, string>]: Column<TFields[K]['type'], {
1596
+ [K in Extract<keyof TColumns, string>]: Column<TColumns[K]['type'], {
1597
1597
  tableName: TTableName;
1598
1598
  name: K;
1599
- hasDefault: TFields[K]['default'] extends undefined ? false : true;
1600
- notNull: TFields[K]['optional'] extends true ? false : true;
1599
+ hasDefault: TColumns[K]['default'] extends undefined ? false : true;
1600
+ notNull: TColumns[K]['optional'] extends true ? false : true;
1601
1601
  }>;
1602
1602
  };
1603
1603
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/db",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -70,8 +70,8 @@
70
70
  "mocha": "^10.2.0",
71
71
  "typescript": "^5.2.2",
72
72
  "vite": "^4.4.11",
73
- "astro-scripts": "0.0.14",
74
- "astro": "4.2.4"
73
+ "astro": "4.4.0",
74
+ "astro-scripts": "0.0.14"
75
75
  },
76
76
  "scripts": {
77
77
  "build": "astro-scripts build \"src/**/*.ts\" && tsc",
File without changes