@astrojs/db 0.9.7 → 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.
- package/dist/_internal/core/schemas.d.ts +201 -23
- package/dist/_internal/core/types.d.ts +10 -4
- package/dist/_internal/core/utils.d.ts +20 -0
- package/dist/core/cli/migration-queries.d.ts +3 -3
- package/dist/core/cli/print-help.js +1 -1
- package/dist/core/load-file.d.ts +4 -4
- package/dist/core/schemas.d.ts +201 -23
- package/dist/core/schemas.js +40 -5
- package/dist/core/types.d.ts +10 -4
- package/dist/core/utils.d.ts +5 -0
- package/dist/core/utils.js +7 -1
- package/package.json +2 -2
|
@@ -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.
|
|
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?:
|
|
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?:
|
|
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.
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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.
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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
|
|
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,
|
|
24
|
+
schema: Record<string, ResolvedDBTable>;
|
|
23
25
|
version: string;
|
|
24
26
|
};
|
|
25
27
|
export type DBConfigInput = z.input<typeof dbConfigSchema>;
|
|
@@ -32,12 +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,
|
|
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
|
}
|
|
43
|
+
/** @deprecated */
|
|
44
|
+
interface LegacyIndexConfig<TColumns extends ColumnsConfig> extends z.input<typeof resolvedIndexSchema> {
|
|
45
|
+
on: MaybeArray<Extract<keyof TColumns, string>>;
|
|
46
|
+
}
|
|
41
47
|
export type NumberColumnOpts = z.input<typeof numberColumnOptsSchema>;
|
|
42
48
|
export type TextColumnOpts = z.input<typeof textColumnOptsSchema>;
|
|
43
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
|
|
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;
|
|
@@ -9,8 +9,8 @@ export declare function getMigrationQueries({ oldSnapshot, newSnapshot, reset, }
|
|
|
9
9
|
}>;
|
|
10
10
|
export declare function getTableChangeQueries({ tableName, oldTable, newTable, }: {
|
|
11
11
|
tableName: string;
|
|
12
|
-
oldTable:
|
|
13
|
-
newTable:
|
|
12
|
+
oldTable: ResolvedDBTable;
|
|
13
|
+
newTable: ResolvedDBTable;
|
|
14
14
|
}): Promise<{
|
|
15
15
|
queries: string[];
|
|
16
16
|
confirmations: string[];
|
package/dist/core/load-file.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export declare function resolveDbConfig({ root, integrations, }: Pick<AstroConfi
|
|
|
6
6
|
/** Resolved `astro:db` config, including tables added by integrations. */
|
|
7
7
|
dbConfig: {
|
|
8
8
|
tables: Record<string, {
|
|
9
|
+
indexes: Record<string, {
|
|
10
|
+
on: (string | string[]) & (string | string[] | undefined);
|
|
11
|
+
unique?: boolean | undefined;
|
|
12
|
+
}>;
|
|
9
13
|
deprecated: boolean;
|
|
10
14
|
columns: Record<string, {
|
|
11
15
|
type: "boolean";
|
|
@@ -97,10 +101,6 @@ export declare function resolveDbConfig({ root, integrations, }: Pick<AstroConfi
|
|
|
97
101
|
default?: unknown;
|
|
98
102
|
};
|
|
99
103
|
}>;
|
|
100
|
-
indexes?: Record<string, {
|
|
101
|
-
on: (string | string[]) & (string | string[] | undefined);
|
|
102
|
-
unique?: boolean | undefined;
|
|
103
|
-
}> | undefined;
|
|
104
104
|
foreignKeys?: (Omit<{
|
|
105
105
|
columns: import("./schemas.js").MaybeArray<string>;
|
|
106
106
|
references: () => import("./schemas.js").MaybeArray<Omit<{
|
package/dist/core/schemas.d.ts
CHANGED
|
@@ -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.
|
|
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?:
|
|
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?:
|
|
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.
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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.
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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 {};
|
package/dist/core/schemas.js
CHANGED
|
@@ -3,6 +3,7 @@ import { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { SERIALIZED_SQL_KEY } from "../runtime/types.js";
|
|
5
5
|
import { errorMap } from "./integration/error-map.js";
|
|
6
|
+
import { mapObject } from "./utils.js";
|
|
6
7
|
const sqlite = new SQLiteAsyncDialect();
|
|
7
8
|
const sqlSchema = z.instanceof(SQL).transform(
|
|
8
9
|
(sqlObj) => ({
|
|
@@ -105,23 +106,31 @@ const columnSchema = z.discriminatedUnion("type", [
|
|
|
105
106
|
]);
|
|
106
107
|
const referenceableColumnSchema = z.union([textColumnSchema, numberColumnSchema]);
|
|
107
108
|
const columnsSchema = z.record(columnSchema);
|
|
108
|
-
const indexSchema = z.object({
|
|
109
|
-
on: z.string().or(z.array(z.string())),
|
|
110
|
-
unique: z.boolean().optional()
|
|
111
|
-
});
|
|
112
109
|
const foreignKeysSchema = z.object({
|
|
113
110
|
columns: z.string().or(z.array(z.string())),
|
|
114
111
|
references: z.function().returns(z.lazy(() => referenceableColumnSchema.or(z.array(referenceableColumnSchema)))).transform((fn) => fn())
|
|
115
112
|
});
|
|
113
|
+
const resolvedIndexSchema = z.object({
|
|
114
|
+
on: z.string().or(z.array(z.string())),
|
|
115
|
+
unique: z.boolean().optional()
|
|
116
|
+
});
|
|
117
|
+
const legacyIndexesSchema = z.record(resolvedIndexSchema);
|
|
118
|
+
const indexSchema = z.object({
|
|
119
|
+
on: z.string().or(z.array(z.string())),
|
|
120
|
+
unique: z.boolean().optional(),
|
|
121
|
+
name: z.string().optional()
|
|
122
|
+
});
|
|
123
|
+
const indexesSchema = z.array(indexSchema);
|
|
116
124
|
const tableSchema = z.object({
|
|
117
125
|
columns: columnsSchema,
|
|
118
|
-
indexes:
|
|
126
|
+
indexes: indexesSchema.or(legacyIndexesSchema).optional(),
|
|
119
127
|
foreignKeys: z.array(foreignKeysSchema).optional(),
|
|
120
128
|
deprecated: z.boolean().optional().default(false)
|
|
121
129
|
});
|
|
122
130
|
const tablesSchema = z.preprocess((rawTables) => {
|
|
123
131
|
const tables = z.record(z.any()).parse(rawTables, { errorMap });
|
|
124
132
|
for (const [tableName, table] of Object.entries(tables)) {
|
|
133
|
+
table.getName = () => tableName;
|
|
125
134
|
const { columns } = z.object({ columns: z.record(z.any()) }).parse(table, { errorMap });
|
|
126
135
|
for (const [columnName, column] of Object.entries(columns)) {
|
|
127
136
|
column.schema.name = columnName;
|
|
@@ -132,6 +141,31 @@ const tablesSchema = z.preprocess((rawTables) => {
|
|
|
132
141
|
}, z.record(tableSchema));
|
|
133
142
|
const dbConfigSchema = z.object({
|
|
134
143
|
tables: tablesSchema.optional()
|
|
144
|
+
}).transform(({ tables = {}, ...config }) => {
|
|
145
|
+
return {
|
|
146
|
+
...config,
|
|
147
|
+
tables: mapObject(tables, (tableName, table) => {
|
|
148
|
+
const { indexes = {} } = table;
|
|
149
|
+
if (!Array.isArray(indexes)) {
|
|
150
|
+
return { ...table, indexes };
|
|
151
|
+
}
|
|
152
|
+
const resolvedIndexes = {};
|
|
153
|
+
for (const index of indexes) {
|
|
154
|
+
if (index.name) {
|
|
155
|
+
const { name: name2, ...rest } = index;
|
|
156
|
+
resolvedIndexes[index.name] = rest;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const indexOn = Array.isArray(index.on) ? index.on.sort().join("_") : index.on;
|
|
160
|
+
const name = tableName + "_" + indexOn + "_idx";
|
|
161
|
+
resolvedIndexes[name] = index;
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
...table,
|
|
165
|
+
indexes: resolvedIndexes
|
|
166
|
+
};
|
|
167
|
+
})
|
|
168
|
+
};
|
|
135
169
|
});
|
|
136
170
|
export {
|
|
137
171
|
booleanColumnSchema,
|
|
@@ -144,6 +178,7 @@ export {
|
|
|
144
178
|
numberColumnOptsSchema,
|
|
145
179
|
numberColumnSchema,
|
|
146
180
|
referenceableColumnSchema,
|
|
181
|
+
resolvedIndexSchema,
|
|
147
182
|
tableSchema,
|
|
148
183
|
tablesSchema,
|
|
149
184
|
textColumnOptsSchema,
|
package/dist/core/types.d.ts
CHANGED
|
@@ -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
|
|
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,
|
|
24
|
+
schema: Record<string, ResolvedDBTable>;
|
|
23
25
|
version: string;
|
|
24
26
|
};
|
|
25
27
|
export type DBConfigInput = z.input<typeof dbConfigSchema>;
|
|
@@ -32,12 +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,
|
|
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
|
}
|
|
43
|
+
/** @deprecated */
|
|
44
|
+
interface LegacyIndexConfig<TColumns extends ColumnsConfig> extends z.input<typeof resolvedIndexSchema> {
|
|
45
|
+
on: MaybeArray<Extract<keyof TColumns, string>>;
|
|
46
|
+
}
|
|
41
47
|
export type NumberColumnOpts = z.input<typeof numberColumnOptsSchema>;
|
|
42
48
|
export type TextColumnOpts = z.input<typeof textColumnOptsSchema>;
|
|
43
49
|
export type AstroDbIntegration = AstroIntegration & {
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -13,3 +13,8 @@ export type Result<T> = {
|
|
|
13
13
|
success: false;
|
|
14
14
|
data: unknown;
|
|
15
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>;
|
package/dist/core/utils.js
CHANGED
|
@@ -17,10 +17,16 @@ function getDbDirectoryUrl(root) {
|
|
|
17
17
|
function defineDbIntegration(integration) {
|
|
18
18
|
return integration;
|
|
19
19
|
}
|
|
20
|
+
function mapObject(item, callback) {
|
|
21
|
+
return Object.fromEntries(
|
|
22
|
+
Object.entries(item).map(([key, value]) => [key, callback(key, value)])
|
|
23
|
+
);
|
|
24
|
+
}
|
|
20
25
|
export {
|
|
21
26
|
defineDbIntegration,
|
|
22
27
|
getAstroStudioEnv,
|
|
23
28
|
getAstroStudioUrl,
|
|
24
29
|
getDbDirectoryUrl,
|
|
25
|
-
getRemoteDatabaseUrl
|
|
30
|
+
getRemoteDatabaseUrl,
|
|
31
|
+
mapObject
|
|
26
32
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/db",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"mocha": "^10.2.0",
|
|
82
82
|
"typescript": "^5.2.2",
|
|
83
83
|
"vite": "^5.1.4",
|
|
84
|
-
"astro": "4.5.
|
|
84
|
+
"astro": "4.5.12",
|
|
85
85
|
"astro-scripts": "0.0.14"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|