@astrojs/db 0.9.6 → 0.9.8

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.
@@ -1853,23 +1853,36 @@ export declare const columnsSchema: z.ZodRecord<z.ZodString, z.ZodDiscriminatedU
1853
1853
  default?: unknown;
1854
1854
  };
1855
1855
  }>]>>;
1856
+ type ForeignKeysInput = {
1857
+ columns: MaybeArray<string>;
1858
+ references: () => MaybeArray<Omit<z.input<typeof referenceableColumnSchema>, 'references'>>;
1859
+ };
1860
+ type ForeignKeysOutput = Omit<ForeignKeysInput, 'references'> & {
1861
+ references: MaybeArray<Omit<z.output<typeof referenceableColumnSchema>, 'references'>>;
1862
+ };
1863
+ export declare const resolvedIndexSchema: z.ZodObject<{
1864
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
1865
+ unique: z.ZodOptional<z.ZodBoolean>;
1866
+ }, "strip", z.ZodTypeAny, {
1867
+ on: (string | string[]) & (string | string[] | undefined);
1868
+ unique?: boolean | undefined;
1869
+ }, {
1870
+ on: (string | string[]) & (string | string[] | undefined);
1871
+ unique?: boolean | undefined;
1872
+ }>;
1856
1873
  export declare const indexSchema: z.ZodObject<{
1857
1874
  on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
1858
1875
  unique: z.ZodOptional<z.ZodBoolean>;
1876
+ name: z.ZodOptional<z.ZodString>;
1859
1877
  }, "strip", z.ZodTypeAny, {
1860
1878
  on: (string | string[]) & (string | string[] | undefined);
1861
1879
  unique?: boolean | undefined;
1880
+ name?: string | undefined;
1862
1881
  }, {
1863
1882
  on: (string | string[]) & (string | string[] | undefined);
1864
1883
  unique?: boolean | undefined;
1884
+ name?: string | undefined;
1865
1885
  }>;
1866
- type ForeignKeysInput = {
1867
- columns: MaybeArray<string>;
1868
- references: () => MaybeArray<Omit<z.input<typeof referenceableColumnSchema>, 'references'>>;
1869
- };
1870
- type ForeignKeysOutput = Omit<ForeignKeysInput, 'references'> & {
1871
- references: MaybeArray<Omit<z.output<typeof referenceableColumnSchema>, 'references'>>;
1872
- };
1873
1886
  export declare const tableSchema: z.ZodObject<{
1874
1887
  columns: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
1875
1888
  type: z.ZodLiteral<"boolean">;
@@ -2241,7 +2254,19 @@ export declare const tableSchema: z.ZodObject<{
2241
2254
  default?: unknown;
2242
2255
  };
2243
2256
  }>]>>;
2244
- indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
2257
+ indexes: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodObject<{
2258
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
2259
+ unique: z.ZodOptional<z.ZodBoolean>;
2260
+ name: z.ZodOptional<z.ZodString>;
2261
+ }, "strip", z.ZodTypeAny, {
2262
+ on: (string | string[]) & (string | string[] | undefined);
2263
+ unique?: boolean | undefined;
2264
+ name?: string | undefined;
2265
+ }, {
2266
+ on: (string | string[]) & (string | string[] | undefined);
2267
+ unique?: boolean | undefined;
2268
+ name?: string | undefined;
2269
+ }>, "many">, z.ZodRecord<z.ZodString, z.ZodObject<{
2245
2270
  on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
2246
2271
  unique: z.ZodOptional<z.ZodBoolean>;
2247
2272
  }, "strip", z.ZodTypeAny, {
@@ -2250,7 +2275,7 @@ export declare const tableSchema: z.ZodObject<{
2250
2275
  }, {
2251
2276
  on: (string | string[]) & (string | string[] | undefined);
2252
2277
  unique?: boolean | undefined;
2253
- }>>>;
2278
+ }>>]>>;
2254
2279
  foreignKeys: z.ZodOptional<z.ZodArray<z.ZodType<ForeignKeysOutput, ZodTypeDef, ForeignKeysInput>, "many">>;
2255
2280
  deprecated: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
2256
2281
  }, "strip", z.ZodTypeAny, {
@@ -2337,7 +2362,11 @@ export declare const tableSchema: z.ZodObject<{
2337
2362
  default?: unknown;
2338
2363
  };
2339
2364
  }>;
2340
- indexes?: Record<string, {
2365
+ indexes?: {
2366
+ on: (string | string[]) & (string | string[] | undefined);
2367
+ unique?: boolean | undefined;
2368
+ name?: string | undefined;
2369
+ }[] | Record<string, {
2341
2370
  on: (string | string[]) & (string | string[] | undefined);
2342
2371
  unique?: boolean | undefined;
2343
2372
  }> | undefined;
@@ -2433,7 +2462,11 @@ export declare const tableSchema: z.ZodObject<{
2433
2462
  default?: unknown;
2434
2463
  };
2435
2464
  }>;
2436
- indexes?: Record<string, {
2465
+ indexes?: {
2466
+ on: (string | string[]) & (string | string[] | undefined);
2467
+ unique?: boolean | undefined;
2468
+ name?: string | undefined;
2469
+ }[] | Record<string, {
2437
2470
  on: (string | string[]) & (string | string[] | undefined);
2438
2471
  unique?: boolean | undefined;
2439
2472
  }> | undefined;
@@ -2811,7 +2844,19 @@ export declare const tablesSchema: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOb
2811
2844
  default?: unknown;
2812
2845
  };
2813
2846
  }>]>>;
2814
- indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
2847
+ indexes: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodObject<{
2848
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
2849
+ unique: z.ZodOptional<z.ZodBoolean>;
2850
+ name: z.ZodOptional<z.ZodString>;
2851
+ }, "strip", z.ZodTypeAny, {
2852
+ on: (string | string[]) & (string | string[] | undefined);
2853
+ unique?: boolean | undefined;
2854
+ name?: string | undefined;
2855
+ }, {
2856
+ on: (string | string[]) & (string | string[] | undefined);
2857
+ unique?: boolean | undefined;
2858
+ name?: string | undefined;
2859
+ }>, "many">, z.ZodRecord<z.ZodString, z.ZodObject<{
2815
2860
  on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
2816
2861
  unique: z.ZodOptional<z.ZodBoolean>;
2817
2862
  }, "strip", z.ZodTypeAny, {
@@ -2820,7 +2865,7 @@ export declare const tablesSchema: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOb
2820
2865
  }, {
2821
2866
  on: (string | string[]) & (string | string[] | undefined);
2822
2867
  unique?: boolean | undefined;
2823
- }>>>;
2868
+ }>>]>>;
2824
2869
  foreignKeys: z.ZodOptional<z.ZodArray<z.ZodType<ForeignKeysOutput, ZodTypeDef, ForeignKeysInput>, "many">>;
2825
2870
  deprecated: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
2826
2871
  }, "strip", z.ZodTypeAny, {
@@ -2907,7 +2952,11 @@ export declare const tablesSchema: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOb
2907
2952
  default?: unknown;
2908
2953
  };
2909
2954
  }>;
2910
- indexes?: Record<string, {
2955
+ indexes?: {
2956
+ on: (string | string[]) & (string | string[] | undefined);
2957
+ unique?: boolean | undefined;
2958
+ name?: string | undefined;
2959
+ }[] | Record<string, {
2911
2960
  on: (string | string[]) & (string | string[] | undefined);
2912
2961
  unique?: boolean | undefined;
2913
2962
  }> | undefined;
@@ -3003,7 +3052,11 @@ export declare const tablesSchema: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOb
3003
3052
  default?: unknown;
3004
3053
  };
3005
3054
  }>;
3006
- indexes?: Record<string, {
3055
+ indexes?: {
3056
+ on: (string | string[]) & (string | string[] | undefined);
3057
+ unique?: boolean | undefined;
3058
+ name?: string | undefined;
3059
+ }[] | Record<string, {
3007
3060
  on: (string | string[]) & (string | string[] | undefined);
3008
3061
  unique?: boolean | undefined;
3009
3062
  }> | undefined;
@@ -3093,13 +3146,17 @@ export declare const tablesSchema: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOb
3093
3146
  default?: unknown;
3094
3147
  };
3095
3148
  }>;
3096
- indexes?: Record<string, {
3149
+ indexes?: {
3150
+ on: (string | string[]) & (string | string[] | undefined);
3151
+ unique?: boolean | undefined;
3152
+ name?: string | undefined;
3153
+ }[] | Record<string, {
3097
3154
  on: (string | string[]) & (string | string[] | undefined);
3098
3155
  unique?: boolean | undefined;
3099
3156
  }> | undefined;
3100
3157
  foreignKeys?: ForeignKeysOutput[] | undefined;
3101
3158
  }>, unknown>;
3102
- export declare const dbConfigSchema: z.ZodObject<{
3159
+ export declare const dbConfigSchema: z.ZodEffects<z.ZodObject<{
3103
3160
  tables: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodObject<{
3104
3161
  columns: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
3105
3162
  type: z.ZodLiteral<"boolean">;
@@ -3471,7 +3528,19 @@ export declare const dbConfigSchema: z.ZodObject<{
3471
3528
  default?: unknown;
3472
3529
  };
3473
3530
  }>]>>;
3474
- indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
3531
+ indexes: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodObject<{
3532
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
3533
+ unique: z.ZodOptional<z.ZodBoolean>;
3534
+ name: z.ZodOptional<z.ZodString>;
3535
+ }, "strip", z.ZodTypeAny, {
3536
+ on: (string | string[]) & (string | string[] | undefined);
3537
+ unique?: boolean | undefined;
3538
+ name?: string | undefined;
3539
+ }, {
3540
+ on: (string | string[]) & (string | string[] | undefined);
3541
+ unique?: boolean | undefined;
3542
+ name?: string | undefined;
3543
+ }>, "many">, z.ZodRecord<z.ZodString, z.ZodObject<{
3475
3544
  on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
3476
3545
  unique: z.ZodOptional<z.ZodBoolean>;
3477
3546
  }, "strip", z.ZodTypeAny, {
@@ -3480,7 +3549,7 @@ export declare const dbConfigSchema: z.ZodObject<{
3480
3549
  }, {
3481
3550
  on: (string | string[]) & (string | string[] | undefined);
3482
3551
  unique?: boolean | undefined;
3483
- }>>>;
3552
+ }>>]>>;
3484
3553
  foreignKeys: z.ZodOptional<z.ZodArray<z.ZodType<ForeignKeysOutput, ZodTypeDef, ForeignKeysInput>, "many">>;
3485
3554
  deprecated: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
3486
3555
  }, "strip", z.ZodTypeAny, {
@@ -3567,7 +3636,11 @@ export declare const dbConfigSchema: z.ZodObject<{
3567
3636
  default?: unknown;
3568
3637
  };
3569
3638
  }>;
3570
- indexes?: Record<string, {
3639
+ indexes?: {
3640
+ on: (string | string[]) & (string | string[] | undefined);
3641
+ unique?: boolean | undefined;
3642
+ name?: string | undefined;
3643
+ }[] | Record<string, {
3571
3644
  on: (string | string[]) & (string | string[] | undefined);
3572
3645
  unique?: boolean | undefined;
3573
3646
  }> | undefined;
@@ -3663,7 +3736,11 @@ export declare const dbConfigSchema: z.ZodObject<{
3663
3736
  default?: unknown;
3664
3737
  };
3665
3738
  }>;
3666
- indexes?: Record<string, {
3739
+ indexes?: {
3740
+ on: (string | string[]) & (string | string[] | undefined);
3741
+ unique?: boolean | undefined;
3742
+ name?: string | undefined;
3743
+ }[] | Record<string, {
3667
3744
  on: (string | string[]) & (string | string[] | undefined);
3668
3745
  unique?: boolean | undefined;
3669
3746
  }> | undefined;
@@ -3753,7 +3830,11 @@ export declare const dbConfigSchema: z.ZodObject<{
3753
3830
  default?: unknown;
3754
3831
  };
3755
3832
  }>;
3756
- indexes?: Record<string, {
3833
+ indexes?: {
3834
+ on: (string | string[]) & (string | string[] | undefined);
3835
+ unique?: boolean | undefined;
3836
+ name?: string | undefined;
3837
+ }[] | Record<string, {
3757
3838
  on: (string | string[]) & (string | string[] | undefined);
3758
3839
  unique?: boolean | undefined;
3759
3840
  }> | undefined;
@@ -3844,7 +3925,11 @@ export declare const dbConfigSchema: z.ZodObject<{
3844
3925
  default?: unknown;
3845
3926
  };
3846
3927
  }>;
3847
- indexes?: Record<string, {
3928
+ indexes?: {
3929
+ on: (string | string[]) & (string | string[] | undefined);
3930
+ unique?: boolean | undefined;
3931
+ name?: string | undefined;
3932
+ }[] | Record<string, {
3848
3933
  on: (string | string[]) & (string | string[] | undefined);
3849
3934
  unique?: boolean | undefined;
3850
3935
  }> | undefined;
@@ -3852,5 +3937,98 @@ export declare const dbConfigSchema: z.ZodObject<{
3852
3937
  }> | undefined;
3853
3938
  }, {
3854
3939
  tables?: unknown;
3940
+ }>, {
3941
+ tables: Record<string, {
3942
+ indexes: Record<string, {
3943
+ on: (string | string[]) & (string | string[] | undefined);
3944
+ unique?: boolean | undefined;
3945
+ }>;
3946
+ deprecated: boolean;
3947
+ columns: Record<string, {
3948
+ type: "boolean";
3949
+ schema: {
3950
+ optional: boolean;
3951
+ unique: boolean;
3952
+ deprecated: boolean;
3953
+ name?: string | undefined;
3954
+ label?: string | undefined;
3955
+ collection?: string | undefined;
3956
+ default?: boolean | SerializedSQL | undefined;
3957
+ };
3958
+ } | {
3959
+ type: "number";
3960
+ schema: ({
3961
+ unique: boolean;
3962
+ deprecated: boolean;
3963
+ name?: string | undefined;
3964
+ label?: string | undefined;
3965
+ collection?: string | undefined;
3966
+ } & {
3967
+ optional: boolean;
3968
+ primaryKey: false;
3969
+ default?: number | SerializedSQL | undefined;
3970
+ } & any) | ({
3971
+ unique: boolean;
3972
+ deprecated: boolean;
3973
+ name?: string | undefined;
3974
+ label?: string | undefined;
3975
+ collection?: string | undefined;
3976
+ } & {
3977
+ primaryKey: true;
3978
+ optional?: false | undefined;
3979
+ default?: undefined;
3980
+ } & any);
3981
+ } | {
3982
+ type: "text";
3983
+ schema: ({
3984
+ unique: boolean;
3985
+ deprecated: boolean;
3986
+ name?: string | undefined;
3987
+ label?: string | undefined;
3988
+ collection?: string | undefined;
3989
+ default?: string | SerializedSQL | undefined;
3990
+ multiline?: boolean | undefined;
3991
+ } & {
3992
+ optional: boolean;
3993
+ primaryKey: false;
3994
+ } & any) | ({
3995
+ unique: boolean;
3996
+ deprecated: boolean;
3997
+ name?: string | undefined;
3998
+ label?: string | undefined;
3999
+ collection?: string | undefined;
4000
+ default?: string | SerializedSQL | undefined;
4001
+ multiline?: boolean | undefined;
4002
+ } & {
4003
+ primaryKey: true;
4004
+ optional?: false | undefined;
4005
+ } & any);
4006
+ } | {
4007
+ type: "date";
4008
+ schema: {
4009
+ optional: boolean;
4010
+ unique: boolean;
4011
+ deprecated: boolean;
4012
+ name?: string | undefined;
4013
+ label?: string | undefined;
4014
+ collection?: string | undefined;
4015
+ default?: string | SerializedSQL | undefined;
4016
+ };
4017
+ } | {
4018
+ type: "json";
4019
+ schema: {
4020
+ optional: boolean;
4021
+ unique: boolean;
4022
+ deprecated: boolean;
4023
+ name?: string | undefined;
4024
+ label?: string | undefined;
4025
+ collection?: string | undefined;
4026
+ default?: unknown;
4027
+ };
4028
+ }>;
4029
+ foreignKeys?: ForeignKeysOutput[] | undefined;
4030
+ }>;
4031
+ }, {
4032
+ tables?: unknown;
3855
4033
  }>;
3856
4034
  export {};
@@ -1,7 +1,7 @@
1
1
  import type { AstroIntegration } from 'astro';
2
2
  import type { z } from 'zod';
3
- import type { MaybeArray, booleanColumnSchema, columnSchema, columnsSchema, dateColumnSchema, dbConfigSchema, indexSchema, jsonColumnSchema, numberColumnOptsSchema, numberColumnSchema, referenceableColumnSchema, tableSchema, textColumnOptsSchema, textColumnSchema } from './schemas.js';
4
- export type Indexes = Record<string, z.infer<typeof indexSchema>>;
3
+ import type { MaybeArray, booleanColumnSchema, columnSchema, columnsSchema, dateColumnSchema, dbConfigSchema, indexSchema, jsonColumnSchema, numberColumnOptsSchema, numberColumnSchema, referenceableColumnSchema, resolvedIndexSchema, tableSchema, textColumnOptsSchema, textColumnSchema } from './schemas.js';
4
+ export type ResolvedIndexes = z.output<typeof dbConfigSchema>['tables'][string]['indexes'];
5
5
  export type BooleanColumn = z.infer<typeof booleanColumnSchema>;
6
6
  export type BooleanColumnInput = z.input<typeof booleanColumnSchema>;
7
7
  export type NumberColumn = z.infer<typeof numberColumnSchema>;
@@ -18,8 +18,10 @@ export type DBColumnInput = DateColumnInput | BooleanColumnInput | NumberColumnI
18
18
  export type DBColumns = z.infer<typeof columnsSchema>;
19
19
  export type DBTable = z.infer<typeof tableSchema>;
20
20
  export type DBTables = Record<string, DBTable>;
21
+ export type ResolvedDBTables = z.output<typeof dbConfigSchema>['tables'];
22
+ export type ResolvedDBTable = z.output<typeof dbConfigSchema>['tables'][string];
21
23
  export type DBSnapshot = {
22
- schema: Record<string, DBTable>;
24
+ schema: Record<string, ResolvedDBTable>;
23
25
  version: string;
24
26
  };
25
27
  export type DBConfigInput = z.input<typeof dbConfigSchema>;
@@ -32,14 +34,16 @@ export interface TableConfig<TColumns extends ColumnsConfig = ColumnsConfig> ext
32
34
  columns: MaybeArray<Extract<keyof TColumns, string>>;
33
35
  references: () => MaybeArray<z.input<typeof referenceableColumnSchema>>;
34
36
  }>;
35
- indexes?: Record<string, IndexConfig<TColumns>>;
37
+ indexes?: Array<IndexConfig<TColumns>> | Record<string, LegacyIndexConfig<TColumns>>;
36
38
  deprecated?: boolean;
37
39
  }
38
40
  interface IndexConfig<TColumns extends ColumnsConfig> extends z.input<typeof indexSchema> {
39
41
  on: MaybeArray<Extract<keyof TColumns, string>>;
40
42
  }
41
- /** @deprecated Use `TableConfig` instead */
42
- export type ResolvedCollectionConfig<TColumns extends ColumnsConfig = ColumnsConfig> = TableConfig<TColumns>;
43
+ /** @deprecated */
44
+ interface LegacyIndexConfig<TColumns extends ColumnsConfig> extends z.input<typeof resolvedIndexSchema> {
45
+ on: MaybeArray<Extract<keyof TColumns, string>>;
46
+ }
43
47
  export type NumberColumnOpts = z.input<typeof numberColumnOptsSchema>;
44
48
  export type TextColumnOpts = z.input<typeof textColumnOptsSchema>;
45
49
  export type AstroDbIntegration = AstroIntegration & {
@@ -0,0 +1,20 @@
1
+ import type { AstroConfig, AstroIntegration } from 'astro';
2
+ import type { AstroDbIntegration } from './types.js';
3
+ export type VitePlugin = Required<AstroConfig['vite']>['plugins'][number];
4
+ export declare function getAstroStudioEnv(envMode?: string): Record<`ASTRO_STUDIO_${string}`, string>;
5
+ export declare function getRemoteDatabaseUrl(): string;
6
+ export declare function getAstroStudioUrl(): string;
7
+ export declare function getDbDirectoryUrl(root: URL | string): URL;
8
+ export declare function defineDbIntegration(integration: AstroDbIntegration): AstroIntegration;
9
+ export type Result<T> = {
10
+ success: true;
11
+ data: T;
12
+ } | {
13
+ success: false;
14
+ data: unknown;
15
+ };
16
+ /**
17
+ * Map an object's values to a new set of values
18
+ * while preserving types.
19
+ */
20
+ export declare function mapObject<T, U = T>(item: Record<string, T>, callback: (key: string, value: T) => U): Record<string, U>;
@@ -1,4 +1,4 @@
1
- import { type DBConfig, type DBSnapshot, type DBTable } from '../types.js';
1
+ import { type DBConfig, type DBSnapshot, type ResolvedDBTable } from '../types.js';
2
2
  export declare function getMigrationQueries({ oldSnapshot, newSnapshot, reset, }: {
3
3
  oldSnapshot: DBSnapshot;
4
4
  newSnapshot: DBSnapshot;
@@ -7,10 +7,10 @@ export declare function getMigrationQueries({ oldSnapshot, newSnapshot, reset, }
7
7
  queries: string[];
8
8
  confirmations: string[];
9
9
  }>;
10
- export declare function getCollectionChangeQueries({ collectionName, oldCollection, newCollection, }: {
11
- collectionName: string;
12
- oldCollection: DBTable;
13
- newCollection: DBTable;
10
+ export declare function getTableChangeQueries({ tableName, oldTable, newTable, }: {
11
+ tableName: string;
12
+ oldTable: ResolvedDBTable;
13
+ newTable: ResolvedDBTable;
14
14
  }): Promise<{
15
15
  queries: string[];
16
16
  confirmations: string[];