@astrojs/db 0.9.7 → 0.9.9
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/commands/execute/index.js +1 -1
- package/dist/core/cli/migration-queries.d.ts +3 -3
- package/dist/core/cli/print-help.js +1 -1
- package/dist/core/integration/index.js +44 -11
- package/dist/core/integration/vite-plugin-db.d.ts +4 -0
- package/dist/core/integration/vite-plugin-db.js +3 -3
- package/dist/core/integration/vite-plugin-inject-env-ts.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/dist/runtime/db-client.js +34 -20
- package/dist/runtime/errors.d.ts +0 -1
- package/dist/runtime/errors.js +2 -8
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/seed-local.js +5 -3
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +5 -0
- 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>;
|
|
@@ -48,7 +48,7 @@ async function cmd({
|
|
|
48
48
|
const { code } = await bundleFile({ virtualModContents, root: astroConfig.root, fileUrl });
|
|
49
49
|
const mod = await importBundledFile({ code, root: astroConfig.root });
|
|
50
50
|
if (typeof mod.default !== "function") {
|
|
51
|
-
console.error(EXEC_DEFAULT_EXPORT_ERROR);
|
|
51
|
+
console.error(EXEC_DEFAULT_EXPORT_ERROR(filePath));
|
|
52
52
|
process.exit(1);
|
|
53
53
|
}
|
|
54
54
|
try {
|
|
@@ -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[];
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
2
|
import { dirname } from "path";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
|
-
import { AstroError } from "astro/errors";
|
|
5
4
|
import { mkdir, writeFile } from "fs/promises";
|
|
6
5
|
import { blue, yellow } from "kleur/colors";
|
|
7
6
|
import { loadEnv } from "vite";
|
|
8
7
|
import parseArgs from "yargs-parser";
|
|
8
|
+
import { SEED_DEV_FILE_NAME } from "../../runtime/queries.js";
|
|
9
|
+
import { AstroDbError } from "../../utils.js";
|
|
9
10
|
import { CONFIG_FILE_NAMES, DB_PATH } from "../consts.js";
|
|
10
11
|
import { resolveDbConfig } from "../load-file.js";
|
|
11
12
|
import { getManagedAppTokenOrExit } from "../tokens.js";
|
|
12
13
|
import { getDbDirectoryUrl } from "../utils.js";
|
|
13
14
|
import { fileURLIntegration } from "./file-url.js";
|
|
14
15
|
import { typegenInternal } from "./typegen.js";
|
|
15
|
-
import { vitePluginDb } from "./vite-plugin-db.js";
|
|
16
|
+
import { resolved, vitePluginDb } from "./vite-plugin-db.js";
|
|
16
17
|
import { vitePluginInjectEnvTs } from "./vite-plugin-inject-env-ts.js";
|
|
17
18
|
function astroDBIntegration() {
|
|
18
19
|
let connectToStudio = false;
|
|
@@ -82,14 +83,7 @@ function astroDBIntegration() {
|
|
|
82
83
|
}
|
|
83
84
|
await typegenInternal({ tables: tables.get() ?? {}, root: config.root });
|
|
84
85
|
},
|
|
85
|
-
"astro:server:
|
|
86
|
-
setTimeout(() => {
|
|
87
|
-
logger.info(
|
|
88
|
-
connectToStudio ? "Connected to remote database." : "New local database created."
|
|
89
|
-
);
|
|
90
|
-
}, 100);
|
|
91
|
-
},
|
|
92
|
-
"astro:server:setup": async ({ server }) => {
|
|
86
|
+
"astro:server:setup": async ({ server, logger }) => {
|
|
93
87
|
const filesToWatch = [
|
|
94
88
|
...CONFIG_FILE_NAMES.map((c) => new URL(c, getDbDirectoryUrl(root))),
|
|
95
89
|
...configFileDependencies.map((c) => new URL(c, root))
|
|
@@ -100,12 +94,51 @@ function astroDBIntegration() {
|
|
|
100
94
|
server.restart();
|
|
101
95
|
}
|
|
102
96
|
});
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
logger.info(
|
|
99
|
+
connectToStudio ? "Connected to remote database." : "New local database created."
|
|
100
|
+
);
|
|
101
|
+
if (connectToStudio)
|
|
102
|
+
return;
|
|
103
|
+
const localSeedPaths = SEED_DEV_FILE_NAME.map(
|
|
104
|
+
(name) => new URL(name, getDbDirectoryUrl(root))
|
|
105
|
+
);
|
|
106
|
+
let seedInFlight = false;
|
|
107
|
+
if (seedFiles.get().length || localSeedPaths.find((path) => existsSync(path))) {
|
|
108
|
+
loadSeedModule();
|
|
109
|
+
}
|
|
110
|
+
const eagerReloadIntegrationSeedPaths = seedFiles.get().map((s) => typeof s === "string" && s.startsWith(".") ? new URL(s, root) : s).filter((s) => s instanceof URL);
|
|
111
|
+
const eagerReloadSeedPaths = [...eagerReloadIntegrationSeedPaths, ...localSeedPaths];
|
|
112
|
+
server.watcher.on("all", (event, relativeEntry) => {
|
|
113
|
+
if (event === "unlink" || event === "unlinkDir")
|
|
114
|
+
return;
|
|
115
|
+
const entry = new URL(relativeEntry, root);
|
|
116
|
+
if (eagerReloadSeedPaths.find((path) => entry.href === path.href)) {
|
|
117
|
+
loadSeedModule();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
function loadSeedModule() {
|
|
121
|
+
if (seedInFlight)
|
|
122
|
+
return;
|
|
123
|
+
seedInFlight = true;
|
|
124
|
+
const mod = server.moduleGraph.getModuleById(resolved.seedVirtual);
|
|
125
|
+
if (mod)
|
|
126
|
+
server.moduleGraph.invalidateModule(mod);
|
|
127
|
+
server.ssrLoadModule(resolved.seedVirtual).then(() => {
|
|
128
|
+
logger.info("Seeded database.");
|
|
129
|
+
}).catch((e) => {
|
|
130
|
+
logger.error(e instanceof Error ? e.message : String(e));
|
|
131
|
+
}).finally(() => {
|
|
132
|
+
seedInFlight = false;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}, 100);
|
|
103
136
|
},
|
|
104
137
|
"astro:build:start": async ({ logger }) => {
|
|
105
138
|
if (!connectToStudio && !databaseFileEnvDefined() && (output === "server" || output === "hybrid")) {
|
|
106
139
|
const message = `Attempting to build without the --remote flag or the ASTRO_DATABASE_FILE environment variable defined. You probably want to pass --remote to astro build.`;
|
|
107
140
|
const hint = "Learn more connecting to Studio: https://docs.astro.build/en/guides/astro-db/#connect-to-astro-studio";
|
|
108
|
-
throw new
|
|
141
|
+
throw new AstroDbError(message, hint);
|
|
109
142
|
}
|
|
110
143
|
logger.info("database: " + (connectToStudio ? yellow("remote") : blue("local database.")));
|
|
111
144
|
},
|
|
@@ -74,12 +74,11 @@ function getLocalVirtualModContents({
|
|
|
74
74
|
});
|
|
75
75
|
const dbUrl = new URL(DB_PATH, root);
|
|
76
76
|
return `
|
|
77
|
-
import { asDrizzleTable, createLocalDatabaseClient } from ${RUNTIME_IMPORT};
|
|
77
|
+
import { asDrizzleTable, createLocalDatabaseClient, normalizeDatabaseUrl } from ${RUNTIME_IMPORT};
|
|
78
78
|
${shouldSeed ? `import { seedLocal } from ${RUNTIME_IMPORT};` : ""}
|
|
79
79
|
${shouldSeed ? integrationSeedImportStatements.join("\n") : ""}
|
|
80
80
|
|
|
81
|
-
const dbUrl = import.meta.env.ASTRO_DATABASE_FILE
|
|
82
|
-
|
|
81
|
+
const dbUrl = normalizeDatabaseUrl(import.meta.env.ASTRO_DATABASE_FILE, ${JSON.stringify(dbUrl)});
|
|
83
82
|
export const db = createLocalDatabaseClient({ dbUrl });
|
|
84
83
|
|
|
85
84
|
${shouldSeed ? `await seedLocal({
|
|
@@ -130,5 +129,6 @@ export {
|
|
|
130
129
|
getConfigVirtualModContents,
|
|
131
130
|
getLocalVirtualModContents,
|
|
132
131
|
getStudioVirtualModContents,
|
|
132
|
+
resolved,
|
|
133
133
|
vitePluginDb
|
|
134
134
|
};
|
|
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { bold
|
|
5
|
+
import { bold } from "kleur/colors";
|
|
6
6
|
import { normalizePath } from "vite";
|
|
7
7
|
import { DB_TYPES_FILE } from "../consts.js";
|
|
8
8
|
function vitePluginInjectEnvTs({ srcDir, root }, logger) {
|
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<{
|