@astrojs/db 0.3.5 → 0.3.6-nightly-01234567890

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 (49) hide show
  1. package/dist/cli/bin.d.ts +2 -0
  2. package/dist/cli/commands/deploy/index.d.ts +1 -0
  3. package/dist/cli/commands/diff/index.d.ts +4 -0
  4. package/dist/cli/commands/run/index.d.ts +1 -0
  5. package/dist/cli/commands/snapshot/index.d.ts +4 -0
  6. package/dist/cli/queries.d.ts +1 -1
  7. package/dist/cli/sync/queries.d.ts +1 -1
  8. package/dist/cli/util.d.ts +34 -0
  9. package/dist/config.d.ts +46 -170
  10. package/dist/core/cli/commands/link/index.js +7 -3
  11. package/dist/core/cli/commands/push/index.js +3 -3
  12. package/dist/core/cli/migration-queries.d.ts +4 -4
  13. package/dist/core/cli/migration-queries.js +73 -73
  14. package/dist/core/cli/migrations.js +15 -7
  15. package/dist/core/errors.js +7 -3
  16. package/dist/core/integration/file-url.js +2 -1
  17. package/dist/core/integration/index.js +106 -57
  18. package/dist/core/integration/typegen.d.ts +3 -3
  19. package/dist/core/integration/typegen.js +8 -8
  20. package/dist/core/integration/vite-plugin-db.d.ts +14 -9
  21. package/dist/core/integration/vite-plugin-db.js +15 -12
  22. package/dist/core/integration/vite-plugin-inject-env-ts.d.ts +4 -2
  23. package/dist/core/integration/vite-plugin-inject-env-ts.js +8 -4
  24. package/dist/core/queries.d.ts +12 -12
  25. package/dist/core/queries.js +49 -46
  26. package/dist/core/types.d.ts +232 -231
  27. package/dist/core/types.js +56 -55
  28. package/dist/core/utils.js +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +4 -4
  31. package/dist/integration.d.ts +1 -1
  32. package/dist/internal.d.ts +11 -11
  33. package/dist/runtime/db-client.d.ts +9 -4
  34. package/dist/runtime/db-client.js +11 -7
  35. package/dist/runtime/index.d.ts +7 -7
  36. package/dist/runtime/index.js +27 -29
  37. package/dist/runtime/types.d.ts +7 -7
  38. package/dist/types.d.ts +46 -164
  39. package/dist/utils-runtime.d.ts +1 -0
  40. package/dist/vite-plugin-db.d.ts +3 -3
  41. package/package.json +13 -15
  42. package/LICENSE +0 -59
  43. package/components/Renderer.astro +0 -14
  44. package/components/astro-env.d.ts +0 -1
  45. package/components/index.ts +0 -2
  46. package/components/tsconfig.json +0 -7
  47. package/dist/cli/seed.d.ts +0 -6
  48. package/dist/file-url-integration.d.ts +0 -2
  49. package/dist/root.d.ts +0 -3
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1 @@
1
+ export declare function cmd(): Promise<void>;
@@ -0,0 +1,4 @@
1
+ import type { AstroConfig } from 'astro';
2
+ export declare function cmd({}: {
3
+ config: Pick<AstroConfig, 'db'>;
4
+ }): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function cmd(): Promise<void>;
@@ -0,0 +1,4 @@
1
+ import type { AstroConfig } from 'astro';
2
+ export declare function cmd({ config }: {
3
+ config: Pick<AstroConfig, 'db'>;
4
+ }): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import type { DBCollection, DBSnapshot } from '../types.js';
2
2
  interface PromptResponses {
3
3
  allowDataLoss: boolean;
4
- columnRenames: Record<string, string | false>;
4
+ fieldRenames: Record<string, string | false>;
5
5
  collectionRenames: Record<string, string | false>;
6
6
  }
7
7
  export declare function getMigrationQueries({ oldSnapshot, newSnapshot, promptResponses, }: {
@@ -1,7 +1,7 @@
1
1
  import type { DBCollection, DBCollections } from '../../types.js';
2
2
  interface PromptResponses {
3
3
  allowDataLoss: boolean;
4
- columnRenames: Record<string, string | false>;
4
+ fieldRenames: Record<string, string | false>;
5
5
  collectionRenames: Record<string, string | false>;
6
6
  }
7
7
  export declare function getMigrationQueries({ oldCollections, newCollections, promptResponses, }: {
@@ -0,0 +1,34 @@
1
+ export declare function createRemoteDbClient(appToken: string): import("drizzle-orm/sqlite-proxy").SqliteRemoteDatabase<Record<string, never>>;
2
+ export declare const STUDIO_ADMIN_TABLE = "ReservedAstroStudioAdmin";
3
+ export declare const STUDIO_ADMIN_TABLE_ROW_ID = "admin";
4
+ export declare const adminTable: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
5
+ name: "ReservedAstroStudioAdmin";
6
+ schema: undefined;
7
+ columns: {
8
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
9
+ name: "id";
10
+ tableName: "ReservedAstroStudioAdmin";
11
+ dataType: "string";
12
+ columnType: "SQLiteText";
13
+ data: string;
14
+ driverParam: string;
15
+ notNull: true;
16
+ hasDefault: false;
17
+ enumValues: [string, ...string[]];
18
+ baseColumn: never;
19
+ }, object>;
20
+ collections: import("drizzle-orm/sqlite-core").SQLiteColumn<{
21
+ name: "collections";
22
+ tableName: "ReservedAstroStudioAdmin";
23
+ dataType: "string";
24
+ columnType: "SQLiteText";
25
+ data: string;
26
+ driverParam: string;
27
+ notNull: true;
28
+ hasDefault: false;
29
+ enumValues: [string, ...string[]];
30
+ baseColumn: never;
31
+ }, object>;
32
+ };
33
+ dialect: "sqlite";
34
+ }>;
package/dist/config.d.ts CHANGED
@@ -1,18 +1,19 @@
1
1
  import type { SQLiteInsertValue } from 'drizzle-orm/sqlite-core';
2
2
  import type { SqliteDB, Table } from './internal.js';
3
3
  import type { MaybeArray, collectionSchema } from './types.js';
4
- import { type BooleanColumn, type DBColumnInput, type DateColumnInput, type JsonColumn, type NumberColumn, type TextColumn, type indexSchema, type MaybePromise } from './types.js';
4
+ import { type BooleanField, type DBFieldInput, type DateFieldInput, type JsonField, type NumberField, type TextField, type MaybePromise } from './types.js';
5
5
  import { z } from 'zod';
6
+ export type DBFieldsConfig = z.input<typeof collectionSchema>['fields'];
6
7
  export type DBDataContext = {
7
8
  db: SqliteDB;
8
- seed<TColumns extends ColumnsConfig>(collection: ResolvedCollectionConfig<TColumns>, data: MaybeArray<SQLiteInsertValue<Table<string,
9
- /** TODO: true type inference */ Record<Extract<keyof TColumns, string>, ColumnsConfig[number]>>>>): Promise<any> /** TODO: type output */;
9
+ seed<TFields extends DBFieldsConfig>(collection: ResolvedCollectionConfig<TFields>, data: MaybeArray<SQLiteInsertValue<Table<string,
10
+ /** TODO: true type inference */ Record<Extract<keyof TFields, string>, DBFieldsConfig[number]>>>>): Promise<any> /** TODO: type output */;
10
11
  mode: 'dev' | 'build';
11
12
  };
12
13
  export declare const dbConfigSchema: z.ZodObject<{
13
14
  studio: z.ZodOptional<z.ZodBoolean>;
14
15
  collections: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
15
- columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
16
+ fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
16
17
  label: z.ZodOptional<z.ZodString>;
17
18
  optional: z.ZodOptional<z.ZodBoolean>;
18
19
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -112,21 +113,11 @@ export declare const dbConfigSchema: z.ZodObject<{
112
113
  unique?: boolean | undefined;
113
114
  default?: unknown;
114
115
  }>]>>;
115
- indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
116
- on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
117
- unique: z.ZodOptional<z.ZodBoolean>;
118
- }, "strip", z.ZodTypeAny, {
119
- on: (string | string[]) & (string | string[] | undefined);
120
- unique?: boolean | undefined;
121
- }, {
122
- on: (string | string[]) & (string | string[] | undefined);
123
- unique?: boolean | undefined;
124
- }>>>;
116
+ writable: z.ZodLiteral<false>;
125
117
  table: z.ZodAny;
126
118
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
127
- writable: z.ZodLiteral<false>;
128
119
  }, "strip", z.ZodTypeAny, {
129
- columns: Record<string, {
120
+ fields: Record<string, {
130
121
  type: "boolean";
131
122
  label?: string | undefined;
132
123
  optional?: boolean | undefined;
@@ -161,14 +152,10 @@ export declare const dbConfigSchema: z.ZodObject<{
161
152
  default?: unknown;
162
153
  }>;
163
154
  writable: false;
164
- indexes?: Record<string, {
165
- on: (string | string[]) & (string | string[] | undefined);
166
- unique?: boolean | undefined;
167
- }> | undefined;
168
155
  table?: any;
169
156
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
170
157
  }, {
171
- columns: Record<string, {
158
+ fields: Record<string, {
172
159
  type: "boolean";
173
160
  label?: string | undefined;
174
161
  optional?: boolean | undefined;
@@ -203,14 +190,10 @@ export declare const dbConfigSchema: z.ZodObject<{
203
190
  default?: unknown;
204
191
  }>;
205
192
  writable: false;
206
- indexes?: Record<string, {
207
- on: (string | string[]) & (string | string[] | undefined);
208
- unique?: boolean | undefined;
209
- }> | undefined;
210
193
  table?: any;
211
194
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
212
195
  }>, z.ZodObject<{
213
- columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
196
+ fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
214
197
  label: z.ZodOptional<z.ZodString>;
215
198
  optional: z.ZodOptional<z.ZodBoolean>;
216
199
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -310,21 +293,11 @@ export declare const dbConfigSchema: z.ZodObject<{
310
293
  unique?: boolean | undefined;
311
294
  default?: unknown;
312
295
  }>]>>;
313
- indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
314
- on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
315
- unique: z.ZodOptional<z.ZodBoolean>;
316
- }, "strip", z.ZodTypeAny, {
317
- on: (string | string[]) & (string | string[] | undefined);
318
- unique?: boolean | undefined;
319
- }, {
320
- on: (string | string[]) & (string | string[] | undefined);
321
- unique?: boolean | undefined;
322
- }>>>;
296
+ writable: z.ZodLiteral<true>;
323
297
  table: z.ZodAny;
324
298
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
325
- writable: z.ZodLiteral<true>;
326
299
  }, "strip", z.ZodTypeAny, {
327
- columns: Record<string, {
300
+ fields: Record<string, {
328
301
  type: "boolean";
329
302
  label?: string | undefined;
330
303
  optional?: boolean | undefined;
@@ -359,14 +332,10 @@ export declare const dbConfigSchema: z.ZodObject<{
359
332
  default?: unknown;
360
333
  }>;
361
334
  writable: true;
362
- indexes?: Record<string, {
363
- on: (string | string[]) & (string | string[] | undefined);
364
- unique?: boolean | undefined;
365
- }> | undefined;
366
335
  table?: any;
367
336
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
368
337
  }, {
369
- columns: Record<string, {
338
+ fields: Record<string, {
370
339
  type: "boolean";
371
340
  label?: string | undefined;
372
341
  optional?: boolean | undefined;
@@ -401,10 +370,6 @@ export declare const dbConfigSchema: z.ZodObject<{
401
370
  default?: unknown;
402
371
  }>;
403
372
  writable: true;
404
- indexes?: Record<string, {
405
- on: (string | string[]) & (string | string[] | undefined);
406
- unique?: boolean | undefined;
407
- }> | undefined;
408
373
  table?: any;
409
374
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
410
375
  }>]>>>;
@@ -412,7 +377,7 @@ export declare const dbConfigSchema: z.ZodObject<{
412
377
  }, "strip", z.ZodTypeAny, {
413
378
  studio?: boolean | undefined;
414
379
  collections?: Record<string, {
415
- columns: Record<string, {
380
+ fields: Record<string, {
416
381
  type: "boolean";
417
382
  label?: string | undefined;
418
383
  optional?: boolean | undefined;
@@ -447,14 +412,10 @@ export declare const dbConfigSchema: z.ZodObject<{
447
412
  default?: unknown;
448
413
  }>;
449
414
  writable: false;
450
- indexes?: Record<string, {
451
- on: (string | string[]) & (string | string[] | undefined);
452
- unique?: boolean | undefined;
453
- }> | undefined;
454
415
  table?: any;
455
416
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
456
417
  } | {
457
- columns: Record<string, {
418
+ fields: Record<string, {
458
419
  type: "boolean";
459
420
  label?: string | undefined;
460
421
  optional?: boolean | undefined;
@@ -489,10 +450,6 @@ export declare const dbConfigSchema: z.ZodObject<{
489
450
  default?: unknown;
490
451
  }>;
491
452
  writable: true;
492
- indexes?: Record<string, {
493
- on: (string | string[]) & (string | string[] | undefined);
494
- unique?: boolean | undefined;
495
- }> | undefined;
496
453
  table?: any;
497
454
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
498
455
  }> | undefined;
@@ -500,7 +457,7 @@ export declare const dbConfigSchema: z.ZodObject<{
500
457
  }, {
501
458
  studio?: boolean | undefined;
502
459
  collections?: Record<string, {
503
- columns: Record<string, {
460
+ fields: Record<string, {
504
461
  type: "boolean";
505
462
  label?: string | undefined;
506
463
  optional?: boolean | undefined;
@@ -535,14 +492,10 @@ export declare const dbConfigSchema: z.ZodObject<{
535
492
  default?: unknown;
536
493
  }>;
537
494
  writable: false;
538
- indexes?: Record<string, {
539
- on: (string | string[]) & (string | string[] | undefined);
540
- unique?: boolean | undefined;
541
- }> | undefined;
542
495
  table?: any;
543
496
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
544
497
  } | {
545
- columns: Record<string, {
498
+ fields: Record<string, {
546
499
  type: "boolean";
547
500
  label?: string | undefined;
548
501
  optional?: boolean | undefined;
@@ -577,10 +530,6 @@ export declare const dbConfigSchema: z.ZodObject<{
577
530
  default?: unknown;
578
531
  }>;
579
532
  writable: true;
580
- indexes?: Record<string, {
581
- on: (string | string[]) & (string | string[] | undefined);
582
- unique?: boolean | undefined;
583
- }> | undefined;
584
533
  table?: any;
585
534
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
586
535
  }> | undefined;
@@ -593,7 +542,7 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
593
542
  db: z.ZodOptional<z.ZodObject<{
594
543
  studio: z.ZodOptional<z.ZodBoolean>;
595
544
  collections: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
596
- columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
545
+ fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
597
546
  label: z.ZodOptional<z.ZodString>;
598
547
  optional: z.ZodOptional<z.ZodBoolean>;
599
548
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -693,21 +642,11 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
693
642
  unique?: boolean | undefined;
694
643
  default?: unknown;
695
644
  }>]>>;
696
- indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
697
- on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
698
- unique: z.ZodOptional<z.ZodBoolean>;
699
- }, "strip", z.ZodTypeAny, {
700
- on: (string | string[]) & (string | string[] | undefined);
701
- unique?: boolean | undefined;
702
- }, {
703
- on: (string | string[]) & (string | string[] | undefined);
704
- unique?: boolean | undefined;
705
- }>>>;
645
+ writable: z.ZodLiteral<false>;
706
646
  table: z.ZodAny;
707
647
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
708
- writable: z.ZodLiteral<false>;
709
648
  }, "strip", z.ZodTypeAny, {
710
- columns: Record<string, {
649
+ fields: Record<string, {
711
650
  type: "boolean";
712
651
  label?: string | undefined;
713
652
  optional?: boolean | undefined;
@@ -742,14 +681,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
742
681
  default?: unknown;
743
682
  }>;
744
683
  writable: false;
745
- indexes?: Record<string, {
746
- on: (string | string[]) & (string | string[] | undefined);
747
- unique?: boolean | undefined;
748
- }> | undefined;
749
684
  table?: any;
750
685
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
751
686
  }, {
752
- columns: Record<string, {
687
+ fields: Record<string, {
753
688
  type: "boolean";
754
689
  label?: string | undefined;
755
690
  optional?: boolean | undefined;
@@ -784,14 +719,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
784
719
  default?: unknown;
785
720
  }>;
786
721
  writable: false;
787
- indexes?: Record<string, {
788
- on: (string | string[]) & (string | string[] | undefined);
789
- unique?: boolean | undefined;
790
- }> | undefined;
791
722
  table?: any;
792
723
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
793
724
  }>, z.ZodObject<{
794
- columns: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
725
+ fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
795
726
  label: z.ZodOptional<z.ZodString>;
796
727
  optional: z.ZodOptional<z.ZodBoolean>;
797
728
  unique: z.ZodOptional<z.ZodBoolean>;
@@ -891,21 +822,11 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
891
822
  unique?: boolean | undefined;
892
823
  default?: unknown;
893
824
  }>]>>;
894
- indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
895
- on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
896
- unique: z.ZodOptional<z.ZodBoolean>;
897
- }, "strip", z.ZodTypeAny, {
898
- on: (string | string[]) & (string | string[] | undefined);
899
- unique?: boolean | undefined;
900
- }, {
901
- on: (string | string[]) & (string | string[] | undefined);
902
- unique?: boolean | undefined;
903
- }>>>;
825
+ writable: z.ZodLiteral<true>;
904
826
  table: z.ZodAny;
905
827
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
906
- writable: z.ZodLiteral<true>;
907
828
  }, "strip", z.ZodTypeAny, {
908
- columns: Record<string, {
829
+ fields: Record<string, {
909
830
  type: "boolean";
910
831
  label?: string | undefined;
911
832
  optional?: boolean | undefined;
@@ -940,14 +861,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
940
861
  default?: unknown;
941
862
  }>;
942
863
  writable: true;
943
- indexes?: Record<string, {
944
- on: (string | string[]) & (string | string[] | undefined);
945
- unique?: boolean | undefined;
946
- }> | undefined;
947
864
  table?: any;
948
865
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
949
866
  }, {
950
- columns: Record<string, {
867
+ fields: Record<string, {
951
868
  type: "boolean";
952
869
  label?: string | undefined;
953
870
  optional?: boolean | undefined;
@@ -982,10 +899,6 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
982
899
  default?: unknown;
983
900
  }>;
984
901
  writable: true;
985
- indexes?: Record<string, {
986
- on: (string | string[]) & (string | string[] | undefined);
987
- unique?: boolean | undefined;
988
- }> | undefined;
989
902
  table?: any;
990
903
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
991
904
  }>]>>>;
@@ -993,7 +906,7 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
993
906
  }, "strip", z.ZodTypeAny, {
994
907
  studio?: boolean | undefined;
995
908
  collections?: Record<string, {
996
- columns: Record<string, {
909
+ fields: Record<string, {
997
910
  type: "boolean";
998
911
  label?: string | undefined;
999
912
  optional?: boolean | undefined;
@@ -1028,14 +941,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1028
941
  default?: unknown;
1029
942
  }>;
1030
943
  writable: false;
1031
- indexes?: Record<string, {
1032
- on: (string | string[]) & (string | string[] | undefined);
1033
- unique?: boolean | undefined;
1034
- }> | undefined;
1035
944
  table?: any;
1036
945
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1037
946
  } | {
1038
- columns: Record<string, {
947
+ fields: Record<string, {
1039
948
  type: "boolean";
1040
949
  label?: string | undefined;
1041
950
  optional?: boolean | undefined;
@@ -1070,10 +979,6 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1070
979
  default?: unknown;
1071
980
  }>;
1072
981
  writable: true;
1073
- indexes?: Record<string, {
1074
- on: (string | string[]) & (string | string[] | undefined);
1075
- unique?: boolean | undefined;
1076
- }> | undefined;
1077
982
  table?: any;
1078
983
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1079
984
  }> | undefined;
@@ -1081,7 +986,7 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1081
986
  }, {
1082
987
  studio?: boolean | undefined;
1083
988
  collections?: Record<string, {
1084
- columns: Record<string, {
989
+ fields: Record<string, {
1085
990
  type: "boolean";
1086
991
  label?: string | undefined;
1087
992
  optional?: boolean | undefined;
@@ -1116,14 +1021,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1116
1021
  default?: unknown;
1117
1022
  }>;
1118
1023
  writable: false;
1119
- indexes?: Record<string, {
1120
- on: (string | string[]) & (string | string[] | undefined);
1121
- unique?: boolean | undefined;
1122
- }> | undefined;
1123
1024
  table?: any;
1124
1025
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1125
1026
  } | {
1126
- columns: Record<string, {
1027
+ fields: Record<string, {
1127
1028
  type: "boolean";
1128
1029
  label?: string | undefined;
1129
1030
  optional?: boolean | undefined;
@@ -1158,10 +1059,6 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1158
1059
  default?: unknown;
1159
1060
  }>;
1160
1061
  writable: true;
1161
- indexes?: Record<string, {
1162
- on: (string | string[]) & (string | string[] | undefined);
1163
- unique?: boolean | undefined;
1164
- }> | undefined;
1165
1062
  table?: any;
1166
1063
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1167
1064
  }> | undefined;
@@ -1171,7 +1068,7 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1171
1068
  db?: {
1172
1069
  studio?: boolean | undefined;
1173
1070
  collections?: Record<string, {
1174
- columns: Record<string, {
1071
+ fields: Record<string, {
1175
1072
  type: "boolean";
1176
1073
  label?: string | undefined;
1177
1074
  optional?: boolean | undefined;
@@ -1206,14 +1103,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1206
1103
  default?: unknown;
1207
1104
  }>;
1208
1105
  writable: false;
1209
- indexes?: Record<string, {
1210
- on: (string | string[]) & (string | string[] | undefined);
1211
- unique?: boolean | undefined;
1212
- }> | undefined;
1213
1106
  table?: any;
1214
1107
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1215
1108
  } | {
1216
- columns: Record<string, {
1109
+ fields: Record<string, {
1217
1110
  type: "boolean";
1218
1111
  label?: string | undefined;
1219
1112
  optional?: boolean | undefined;
@@ -1248,10 +1141,6 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1248
1141
  default?: unknown;
1249
1142
  }>;
1250
1143
  writable: true;
1251
- indexes?: Record<string, {
1252
- on: (string | string[]) & (string | string[] | undefined);
1253
- unique?: boolean | undefined;
1254
- }> | undefined;
1255
1144
  table?: any;
1256
1145
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1257
1146
  }> | undefined;
@@ -1261,7 +1150,7 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1261
1150
  db?: {
1262
1151
  studio?: boolean | undefined;
1263
1152
  collections?: Record<string, {
1264
- columns: Record<string, {
1153
+ fields: Record<string, {
1265
1154
  type: "boolean";
1266
1155
  label?: string | undefined;
1267
1156
  optional?: boolean | undefined;
@@ -1296,14 +1185,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1296
1185
  default?: unknown;
1297
1186
  }>;
1298
1187
  writable: false;
1299
- indexes?: Record<string, {
1300
- on: (string | string[]) & (string | string[] | undefined);
1301
- unique?: boolean | undefined;
1302
- }> | undefined;
1303
1188
  table?: any;
1304
1189
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1305
1190
  } | {
1306
- columns: Record<string, {
1191
+ fields: Record<string, {
1307
1192
  type: "boolean";
1308
1193
  label?: string | undefined;
1309
1194
  optional?: boolean | undefined;
@@ -1338,37 +1223,28 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1338
1223
  default?: unknown;
1339
1224
  }>;
1340
1225
  writable: true;
1341
- indexes?: Record<string, {
1342
- on: (string | string[]) & (string | string[] | undefined);
1343
- unique?: boolean | undefined;
1344
- }> | undefined;
1345
1226
  table?: any;
1346
1227
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1347
1228
  }> | undefined;
1348
1229
  data?: ((...args: unknown[]) => void | Promise<void>) | undefined;
1349
1230
  } | undefined;
1350
1231
  }>;
1351
- export type ColumnsConfig = z.input<typeof collectionSchema>['columns'];
1352
- interface CollectionConfig<TColumns extends ColumnsConfig> extends Pick<z.input<typeof collectionSchema>, 'columns' | 'indexes'> {
1353
- columns: TColumns;
1354
- indexes?: Record<string, IndexConfig<TColumns>>;
1355
- }
1356
- interface IndexConfig<TColumns extends ColumnsConfig> extends z.input<typeof indexSchema> {
1357
- on: MaybeArray<Extract<keyof TColumns, string>>;
1358
- }
1359
- export type ResolvedCollectionConfig<TColumns extends ColumnsConfig = ColumnsConfig, Writable extends boolean = boolean> = CollectionConfig<TColumns> & {
1232
+ type CollectionConfig<TFields extends DBFieldsConfig> = {
1233
+ fields: TFields;
1234
+ };
1235
+ export type ResolvedCollectionConfig<TFields extends DBFieldsConfig = DBFieldsConfig, Writable extends boolean = boolean> = CollectionConfig<TFields> & {
1360
1236
  writable: Writable;
1361
- table: Table<string, TColumns>;
1237
+ table: Table<string, TFields>;
1362
1238
  };
1363
- export declare function defineCollection<TColumns extends ColumnsConfig>(userConfig: CollectionConfig<TColumns>): ResolvedCollectionConfig<TColumns, false>;
1364
- export declare function defineWritableCollection<TColumns extends ColumnsConfig>(userConfig: CollectionConfig<TColumns>): ResolvedCollectionConfig<TColumns, true>;
1239
+ export declare function defineCollection<TFields extends DBFieldsConfig>(userConfig: CollectionConfig<TFields>): ResolvedCollectionConfig<TFields, false>;
1240
+ export declare function defineWritableCollection<TFields extends DBFieldsConfig>(userConfig: CollectionConfig<TFields>): ResolvedCollectionConfig<TFields, true>;
1365
1241
  export type AstroConfigWithDB = z.infer<typeof astroConfigWithDbSchema>;
1366
- type ColumnOpts<T extends DBColumnInput> = Omit<T, 'type'>;
1367
- export declare const column: {
1368
- number(opts?: ColumnOpts<NumberColumn>): NumberColumn;
1369
- boolean(opts?: ColumnOpts<BooleanColumn>): BooleanColumn;
1370
- text(opts?: ColumnOpts<TextColumn>): TextColumn;
1371
- date(opts?: ColumnOpts<DateColumnInput>): DateColumnInput;
1372
- json(opts?: ColumnOpts<JsonColumn>): JsonColumn;
1242
+ type FieldOpts<T extends DBFieldInput> = Omit<T, 'type'>;
1243
+ export declare const field: {
1244
+ number(opts?: FieldOpts<NumberField>): NumberField;
1245
+ boolean(opts?: FieldOpts<BooleanField>): BooleanField;
1246
+ text(opts?: FieldOpts<TextField>): TextField;
1247
+ date(opts?: FieldOpts<DateFieldInput>): DateFieldInput;
1248
+ json(opts?: FieldOpts<JsonField>): JsonField;
1373
1249
  };
1374
1250
  export {};
@@ -27,12 +27,16 @@ async function cmd({ flags }) {
27
27
  });
28
28
  if (!response.ok) {
29
29
  if (response.status === 401) {
30
- console.error(`${bgRed("Unauthorized")}
30
+ console.error(
31
+ `${bgRed("Unauthorized")}
31
32
 
32
33
  Are you logged in?
33
- Run ${cyan("astro db login")} to authenticate and then try linking again.
34
+ Run ${cyan(
35
+ "astro db login"
36
+ )} to authenticate and then try linking again.
34
37
 
35
- `);
38
+ `
39
+ );
36
40
  process.exit(1);
37
41
  }
38
42
  console.error(`Failed to link project: ${response.status} ${response.statusText}`);
@@ -6,7 +6,7 @@ import { red } from "kleur/colors";
6
6
  import prompts from "prompts";
7
7
  import { recreateTables, seedData } from "../../../queries.js";
8
8
  import { getManagedAppTokenOrExit } from "../../../tokens.js";
9
- import { collectionsSchema } from "../../../types.js";
9
+ import { tablesSchema } from "../../../types.js";
10
10
  import { getRemoteDatabaseUrl } from "../../../utils.js";
11
11
  import { getMigrationQueries } from "../../migration-queries.js";
12
12
  import {
@@ -112,9 +112,9 @@ async function pushData({
112
112
  const libsqlClient = createClient({ url: ":memory:" });
113
113
  await recreateTables({
114
114
  db: drizzleLibsql(libsqlClient),
115
- collections: collectionsSchema.parse(config.db.collections ?? {})
115
+ tables: tablesSchema.parse(config.db.tables ?? {})
116
116
  });
117
- for (const [collectionName, { writable }] of Object.entries(config.db.collections ?? {})) {
117
+ for (const [collectionName, { writable }] of Object.entries(config.db.tables ?? {})) {
118
118
  if (!writable) {
119
119
  queries.push({
120
120
  sql: `DELETE FROM ${sqlite.escapeName(collectionName)}`,
@@ -1,8 +1,8 @@
1
- import { type DBCollection, type DBSnapshot } from '../types.js';
1
+ import { type DBTable, type DBSnapshot } from '../types.js';
2
2
  /** Dependency injected for unit testing */
3
3
  type AmbiguityResponses = {
4
4
  collectionRenames: Record<string, string>;
5
- fieldRenames: {
5
+ columnRenames: {
6
6
  [collectionName: string]: Record<string, string>;
7
7
  };
8
8
  };
@@ -16,8 +16,8 @@ export declare function getMigrationQueries({ oldSnapshot, newSnapshot, ambiguit
16
16
  }>;
17
17
  export declare function getCollectionChangeQueries({ collectionName, oldCollection, newCollection, ambiguityResponses, }: {
18
18
  collectionName: string;
19
- oldCollection: DBCollection;
20
- newCollection: DBCollection;
19
+ oldCollection: DBTable;
20
+ newCollection: DBTable;
21
21
  ambiguityResponses?: AmbiguityResponses;
22
22
  }): Promise<{
23
23
  queries: string[];