astro 4.9.2 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/client.d.ts +8 -0
  2. package/components/Picture.astro +2 -1
  3. package/config.d.ts +6 -0
  4. package/config.mjs +1 -0
  5. package/dist/@types/astro.d.ts +124 -0
  6. package/dist/assets/utils/proxy.js +1 -1
  7. package/dist/cli/add/babel.d.ts +1 -1
  8. package/dist/cli/install-package.d.ts +1 -1
  9. package/dist/cli/install-package.js +1 -1
  10. package/dist/config/index.js +2 -2
  11. package/dist/container/index.d.ts +11 -15
  12. package/dist/container/index.js +29 -27
  13. package/dist/container/pipeline.d.ts +1 -0
  14. package/dist/container/pipeline.js +8 -1
  15. package/dist/content/types-generator.js +5 -5
  16. package/dist/content/utils.d.ts +2 -3
  17. package/dist/content/utils.js +3 -4
  18. package/dist/content/vite-plugin-content-virtual-mod.d.ts +1 -1
  19. package/dist/core/app/pipeline.d.ts +2 -1
  20. package/dist/core/app/pipeline.js +44 -19
  21. package/dist/core/app/types.d.ts +1 -0
  22. package/dist/core/base-pipeline.d.ts +15 -3
  23. package/dist/core/base-pipeline.js +10 -1
  24. package/dist/core/build/generate.js +14 -4
  25. package/dist/core/build/pipeline.d.ts +2 -1
  26. package/dist/core/build/pipeline.js +31 -19
  27. package/dist/core/build/plugins/plugin-content.js +2 -1
  28. package/dist/core/build/plugins/plugin-manifest.js +2 -1
  29. package/dist/core/config/config.js +1 -1
  30. package/dist/core/config/schema.d.ts +644 -0
  31. package/dist/core/config/schema.js +5 -1
  32. package/dist/core/config/settings.js +1 -0
  33. package/dist/core/constants.d.ts +1 -1
  34. package/dist/core/constants.js +2 -2
  35. package/dist/core/create-vite.js +2 -0
  36. package/dist/core/dev/dev.js +1 -1
  37. package/dist/core/errors/errors-data.d.ts +61 -1
  38. package/dist/core/errors/errors-data.js +39 -0
  39. package/dist/core/logger/core.d.ts +1 -1
  40. package/dist/core/messages.js +2 -2
  41. package/dist/core/render-context.d.ts +1 -0
  42. package/dist/core/render-context.js +74 -57
  43. package/dist/core/routing/astro-designed-error-pages.d.ts +8 -1
  44. package/dist/core/routing/astro-designed-error-pages.js +29 -12
  45. package/dist/env/config.d.ts +9 -0
  46. package/dist/env/config.js +17 -0
  47. package/dist/env/constants.d.ts +11 -0
  48. package/dist/env/constants.js +21 -0
  49. package/dist/env/runtime.d.ts +6 -0
  50. package/dist/env/runtime.js +21 -0
  51. package/dist/env/schema.d.ts +387 -0
  52. package/dist/env/schema.js +113 -0
  53. package/dist/env/validators.d.ts +13 -0
  54. package/dist/env/validators.js +57 -0
  55. package/dist/env/vite-plugin-env.d.ts +11 -0
  56. package/dist/env/vite-plugin-env.js +174 -0
  57. package/dist/integrations/features-validation.js +9 -1
  58. package/dist/jsx/server.js +2 -1
  59. package/dist/runtime/server/render/astro/render.js +15 -1
  60. package/dist/runtime/server/util.js +1 -1
  61. package/dist/virtual-modules/container.d.ts +16 -0
  62. package/dist/virtual-modules/container.js +18 -0
  63. package/dist/virtual-modules/env-setup.d.ts +1 -0
  64. package/dist/virtual-modules/env-setup.js +4 -0
  65. package/dist/vite-plugin-astro-server/pipeline.d.ts +3 -2
  66. package/dist/vite-plugin-astro-server/pipeline.js +34 -20
  67. package/dist/vite-plugin-astro-server/plugin.js +1 -0
  68. package/dist/vite-plugin-astro-server/response.d.ts +0 -6
  69. package/dist/vite-plugin-astro-server/response.js +0 -13
  70. package/dist/vite-plugin-astro-server/route.js +2 -1
  71. package/dist/vite-plugin-inject-env-ts/index.js +46 -38
  72. package/package.json +19 -20
  73. package/templates/env/module.mjs +18 -0
  74. package/templates/env/types.d.ts +20 -0
  75. /package/{content-module.template.mjs → templates/content/module.mjs} +0 -0
  76. /package/{content-types.template.d.ts → templates/content/types.d.ts} +0 -0
@@ -0,0 +1,387 @@
1
+ import { z } from 'zod';
2
+ declare const EnvFieldType: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
3
+ type: z.ZodLiteral<"string">;
4
+ optional: z.ZodOptional<z.ZodBoolean>;
5
+ default: z.ZodOptional<z.ZodString>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ type: "string";
8
+ default?: string | undefined;
9
+ optional?: boolean | undefined;
10
+ }, {
11
+ type: "string";
12
+ default?: string | undefined;
13
+ optional?: boolean | undefined;
14
+ }>, z.ZodObject<{
15
+ type: z.ZodLiteral<"number">;
16
+ optional: z.ZodOptional<z.ZodBoolean>;
17
+ default: z.ZodOptional<z.ZodNumber>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ type: "number";
20
+ default?: number | undefined;
21
+ optional?: boolean | undefined;
22
+ }, {
23
+ type: "number";
24
+ default?: number | undefined;
25
+ optional?: boolean | undefined;
26
+ }>, z.ZodObject<{
27
+ type: z.ZodLiteral<"boolean">;
28
+ optional: z.ZodOptional<z.ZodBoolean>;
29
+ default: z.ZodOptional<z.ZodBoolean>;
30
+ }, "strip", z.ZodTypeAny, {
31
+ type: "boolean";
32
+ default?: boolean | undefined;
33
+ optional?: boolean | undefined;
34
+ }, {
35
+ type: "boolean";
36
+ default?: boolean | undefined;
37
+ optional?: boolean | undefined;
38
+ }>]>;
39
+ export type EnvFieldType = z.infer<typeof EnvFieldType>;
40
+ export declare const EnvSchema: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
41
+ context: z.ZodLiteral<"client">;
42
+ access: z.ZodLiteral<"public">;
43
+ }, "strip", z.ZodTypeAny, {
44
+ context: "client";
45
+ access: "public";
46
+ }, {
47
+ context: "client";
48
+ access: "public";
49
+ }>, z.ZodObject<{
50
+ context: z.ZodLiteral<"server">;
51
+ access: z.ZodLiteral<"public">;
52
+ }, "strip", z.ZodTypeAny, {
53
+ context: "server";
54
+ access: "public";
55
+ }, {
56
+ context: "server";
57
+ access: "public";
58
+ }>, z.ZodObject<{
59
+ context: z.ZodLiteral<"server">;
60
+ access: z.ZodLiteral<"secret">;
61
+ }, "strip", z.ZodTypeAny, {
62
+ context: "server";
63
+ access: "secret";
64
+ }, {
65
+ context: "server";
66
+ access: "secret";
67
+ }>]>, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
68
+ type: z.ZodLiteral<"string">;
69
+ optional: z.ZodOptional<z.ZodBoolean>;
70
+ default: z.ZodOptional<z.ZodString>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ type: "string";
73
+ default?: string | undefined;
74
+ optional?: boolean | undefined;
75
+ }, {
76
+ type: "string";
77
+ default?: string | undefined;
78
+ optional?: boolean | undefined;
79
+ }>, z.ZodObject<{
80
+ type: z.ZodLiteral<"number">;
81
+ optional: z.ZodOptional<z.ZodBoolean>;
82
+ default: z.ZodOptional<z.ZodNumber>;
83
+ }, "strip", z.ZodTypeAny, {
84
+ type: "number";
85
+ default?: number | undefined;
86
+ optional?: boolean | undefined;
87
+ }, {
88
+ type: "number";
89
+ default?: number | undefined;
90
+ optional?: boolean | undefined;
91
+ }>, z.ZodObject<{
92
+ type: z.ZodLiteral<"boolean">;
93
+ optional: z.ZodOptional<z.ZodBoolean>;
94
+ default: z.ZodOptional<z.ZodBoolean>;
95
+ }, "strip", z.ZodTypeAny, {
96
+ type: "boolean";
97
+ default?: boolean | undefined;
98
+ optional?: boolean | undefined;
99
+ }, {
100
+ type: "boolean";
101
+ default?: boolean | undefined;
102
+ optional?: boolean | undefined;
103
+ }>]>>>, Record<string, ({
104
+ context: "client";
105
+ access: "public";
106
+ } | {
107
+ context: "server";
108
+ access: "public";
109
+ } | {
110
+ context: "server";
111
+ access: "secret";
112
+ }) & ({
113
+ type: "string";
114
+ default?: string | undefined;
115
+ optional?: boolean | undefined;
116
+ } | {
117
+ type: "number";
118
+ default?: number | undefined;
119
+ optional?: boolean | undefined;
120
+ } | {
121
+ type: "boolean";
122
+ default?: boolean | undefined;
123
+ optional?: boolean | undefined;
124
+ })>, Record<string, ({
125
+ context: "client";
126
+ access: "public";
127
+ } | {
128
+ context: "server";
129
+ access: "public";
130
+ } | {
131
+ context: "server";
132
+ access: "secret";
133
+ }) & ({
134
+ type: "string";
135
+ default?: string | undefined;
136
+ optional?: boolean | undefined;
137
+ } | {
138
+ type: "number";
139
+ default?: number | undefined;
140
+ optional?: boolean | undefined;
141
+ } | {
142
+ type: "boolean";
143
+ default?: boolean | undefined;
144
+ optional?: boolean | undefined;
145
+ })>>;
146
+ export type EnvSchema = z.infer<typeof EnvSchema>;
147
+ declare const StringField: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
148
+ context: z.ZodLiteral<"client">;
149
+ access: z.ZodLiteral<"public">;
150
+ }, "strip", z.ZodTypeAny, {
151
+ context: "client";
152
+ access: "public";
153
+ }, {
154
+ context: "client";
155
+ access: "public";
156
+ }>, z.ZodObject<{
157
+ context: z.ZodLiteral<"server">;
158
+ access: z.ZodLiteral<"public">;
159
+ }, "strip", z.ZodTypeAny, {
160
+ context: "server";
161
+ access: "public";
162
+ }, {
163
+ context: "server";
164
+ access: "public";
165
+ }>, z.ZodObject<{
166
+ context: z.ZodLiteral<"server">;
167
+ access: z.ZodLiteral<"secret">;
168
+ }, "strip", z.ZodTypeAny, {
169
+ context: "server";
170
+ access: "secret";
171
+ }, {
172
+ context: "server";
173
+ access: "secret";
174
+ }>]>, z.ZodObject<{
175
+ type: z.ZodLiteral<"string">;
176
+ optional: z.ZodOptional<z.ZodBoolean>;
177
+ default: z.ZodOptional<z.ZodString>;
178
+ }, "strip", z.ZodTypeAny, {
179
+ type: "string";
180
+ default?: string | undefined;
181
+ optional?: boolean | undefined;
182
+ }, {
183
+ type: "string";
184
+ default?: string | undefined;
185
+ optional?: boolean | undefined;
186
+ }>>;
187
+ export type StringField = z.infer<typeof StringField>;
188
+ export declare const StringFieldInput: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
189
+ context: z.ZodLiteral<"client">;
190
+ access: z.ZodLiteral<"public">;
191
+ }, "strip", z.ZodTypeAny, {
192
+ context: "client";
193
+ access: "public";
194
+ }, {
195
+ context: "client";
196
+ access: "public";
197
+ }>, z.ZodObject<{
198
+ context: z.ZodLiteral<"server">;
199
+ access: z.ZodLiteral<"public">;
200
+ }, "strip", z.ZodTypeAny, {
201
+ context: "server";
202
+ access: "public";
203
+ }, {
204
+ context: "server";
205
+ access: "public";
206
+ }>, z.ZodObject<{
207
+ context: z.ZodLiteral<"server">;
208
+ access: z.ZodLiteral<"secret">;
209
+ }, "strip", z.ZodTypeAny, {
210
+ context: "server";
211
+ access: "secret";
212
+ }, {
213
+ context: "server";
214
+ access: "secret";
215
+ }>]>, z.ZodObject<Omit<{
216
+ type: z.ZodLiteral<"string">;
217
+ optional: z.ZodOptional<z.ZodBoolean>;
218
+ default: z.ZodOptional<z.ZodString>;
219
+ }, "type">, "strip", z.ZodTypeAny, {
220
+ default?: string | undefined;
221
+ optional?: boolean | undefined;
222
+ }, {
223
+ default?: string | undefined;
224
+ optional?: boolean | undefined;
225
+ }>>;
226
+ export type StringFieldInput = z.infer<typeof StringFieldInput>;
227
+ declare const NumberField: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
228
+ context: z.ZodLiteral<"client">;
229
+ access: z.ZodLiteral<"public">;
230
+ }, "strip", z.ZodTypeAny, {
231
+ context: "client";
232
+ access: "public";
233
+ }, {
234
+ context: "client";
235
+ access: "public";
236
+ }>, z.ZodObject<{
237
+ context: z.ZodLiteral<"server">;
238
+ access: z.ZodLiteral<"public">;
239
+ }, "strip", z.ZodTypeAny, {
240
+ context: "server";
241
+ access: "public";
242
+ }, {
243
+ context: "server";
244
+ access: "public";
245
+ }>, z.ZodObject<{
246
+ context: z.ZodLiteral<"server">;
247
+ access: z.ZodLiteral<"secret">;
248
+ }, "strip", z.ZodTypeAny, {
249
+ context: "server";
250
+ access: "secret";
251
+ }, {
252
+ context: "server";
253
+ access: "secret";
254
+ }>]>, z.ZodObject<{
255
+ type: z.ZodLiteral<"number">;
256
+ optional: z.ZodOptional<z.ZodBoolean>;
257
+ default: z.ZodOptional<z.ZodNumber>;
258
+ }, "strip", z.ZodTypeAny, {
259
+ type: "number";
260
+ default?: number | undefined;
261
+ optional?: boolean | undefined;
262
+ }, {
263
+ type: "number";
264
+ default?: number | undefined;
265
+ optional?: boolean | undefined;
266
+ }>>;
267
+ export type NumberField = z.infer<typeof NumberField>;
268
+ export declare const NumberFieldInput: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
269
+ context: z.ZodLiteral<"client">;
270
+ access: z.ZodLiteral<"public">;
271
+ }, "strip", z.ZodTypeAny, {
272
+ context: "client";
273
+ access: "public";
274
+ }, {
275
+ context: "client";
276
+ access: "public";
277
+ }>, z.ZodObject<{
278
+ context: z.ZodLiteral<"server">;
279
+ access: z.ZodLiteral<"public">;
280
+ }, "strip", z.ZodTypeAny, {
281
+ context: "server";
282
+ access: "public";
283
+ }, {
284
+ context: "server";
285
+ access: "public";
286
+ }>, z.ZodObject<{
287
+ context: z.ZodLiteral<"server">;
288
+ access: z.ZodLiteral<"secret">;
289
+ }, "strip", z.ZodTypeAny, {
290
+ context: "server";
291
+ access: "secret";
292
+ }, {
293
+ context: "server";
294
+ access: "secret";
295
+ }>]>, z.ZodObject<Omit<{
296
+ type: z.ZodLiteral<"number">;
297
+ optional: z.ZodOptional<z.ZodBoolean>;
298
+ default: z.ZodOptional<z.ZodNumber>;
299
+ }, "type">, "strip", z.ZodTypeAny, {
300
+ default?: number | undefined;
301
+ optional?: boolean | undefined;
302
+ }, {
303
+ default?: number | undefined;
304
+ optional?: boolean | undefined;
305
+ }>>;
306
+ export type NumberFieldInput = z.infer<typeof NumberFieldInput>;
307
+ declare const BooleanField: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
308
+ context: z.ZodLiteral<"client">;
309
+ access: z.ZodLiteral<"public">;
310
+ }, "strip", z.ZodTypeAny, {
311
+ context: "client";
312
+ access: "public";
313
+ }, {
314
+ context: "client";
315
+ access: "public";
316
+ }>, z.ZodObject<{
317
+ context: z.ZodLiteral<"server">;
318
+ access: z.ZodLiteral<"public">;
319
+ }, "strip", z.ZodTypeAny, {
320
+ context: "server";
321
+ access: "public";
322
+ }, {
323
+ context: "server";
324
+ access: "public";
325
+ }>, z.ZodObject<{
326
+ context: z.ZodLiteral<"server">;
327
+ access: z.ZodLiteral<"secret">;
328
+ }, "strip", z.ZodTypeAny, {
329
+ context: "server";
330
+ access: "secret";
331
+ }, {
332
+ context: "server";
333
+ access: "secret";
334
+ }>]>, z.ZodObject<{
335
+ type: z.ZodLiteral<"boolean">;
336
+ optional: z.ZodOptional<z.ZodBoolean>;
337
+ default: z.ZodOptional<z.ZodBoolean>;
338
+ }, "strip", z.ZodTypeAny, {
339
+ type: "boolean";
340
+ default?: boolean | undefined;
341
+ optional?: boolean | undefined;
342
+ }, {
343
+ type: "boolean";
344
+ default?: boolean | undefined;
345
+ optional?: boolean | undefined;
346
+ }>>;
347
+ export type BooleanField = z.infer<typeof BooleanField>;
348
+ export declare const BooleanFieldInput: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
349
+ context: z.ZodLiteral<"client">;
350
+ access: z.ZodLiteral<"public">;
351
+ }, "strip", z.ZodTypeAny, {
352
+ context: "client";
353
+ access: "public";
354
+ }, {
355
+ context: "client";
356
+ access: "public";
357
+ }>, z.ZodObject<{
358
+ context: z.ZodLiteral<"server">;
359
+ access: z.ZodLiteral<"public">;
360
+ }, "strip", z.ZodTypeAny, {
361
+ context: "server";
362
+ access: "public";
363
+ }, {
364
+ context: "server";
365
+ access: "public";
366
+ }>, z.ZodObject<{
367
+ context: z.ZodLiteral<"server">;
368
+ access: z.ZodLiteral<"secret">;
369
+ }, "strip", z.ZodTypeAny, {
370
+ context: "server";
371
+ access: "secret";
372
+ }, {
373
+ context: "server";
374
+ access: "secret";
375
+ }>]>, z.ZodObject<Omit<{
376
+ type: z.ZodLiteral<"boolean">;
377
+ optional: z.ZodOptional<z.ZodBoolean>;
378
+ default: z.ZodOptional<z.ZodBoolean>;
379
+ }, "type">, "strip", z.ZodTypeAny, {
380
+ default?: boolean | undefined;
381
+ optional?: boolean | undefined;
382
+ }, {
383
+ default?: boolean | undefined;
384
+ optional?: boolean | undefined;
385
+ }>>;
386
+ export type BooleanFieldInput = z.infer<typeof BooleanFieldInput>;
387
+ export {};
@@ -0,0 +1,113 @@
1
+ import { z } from "zod";
2
+ import { PUBLIC_PREFIX } from "./constants.js";
3
+ const StringSchema = z.object({
4
+ type: z.literal("string"),
5
+ optional: z.boolean().optional(),
6
+ default: z.string().optional()
7
+ });
8
+ const NumberSchema = z.object({
9
+ type: z.literal("number"),
10
+ optional: z.boolean().optional(),
11
+ default: z.number().optional()
12
+ });
13
+ const BooleanSchema = z.object({
14
+ type: z.literal("boolean"),
15
+ optional: z.boolean().optional(),
16
+ default: z.boolean().optional()
17
+ });
18
+ const EnvFieldType = z.discriminatedUnion("type", [StringSchema, NumberSchema, BooleanSchema]);
19
+ const PublicClientEnvFieldMetadata = z.object({
20
+ context: z.literal("client"),
21
+ access: z.literal("public")
22
+ });
23
+ const PublicServerEnvFieldMetadata = z.object({
24
+ context: z.literal("server"),
25
+ access: z.literal("public")
26
+ });
27
+ const SecretServerEnvFieldMetadata = z.object({
28
+ context: z.literal("server"),
29
+ access: z.literal("secret")
30
+ });
31
+ const KEY_REGEX = /^[A-Z_]+$/;
32
+ const EnvSchema = z.record(
33
+ z.string().regex(KEY_REGEX, {
34
+ message: "A valid variable name can only contain uppercase letters and underscores."
35
+ }),
36
+ z.intersection(
37
+ z.union([
38
+ PublicClientEnvFieldMetadata,
39
+ PublicServerEnvFieldMetadata,
40
+ SecretServerEnvFieldMetadata
41
+ ]),
42
+ EnvFieldType
43
+ )
44
+ ).superRefine((schema, ctx) => {
45
+ for (const [key, value] of Object.entries(schema)) {
46
+ if (key.startsWith(PUBLIC_PREFIX) && value.access !== "public") {
47
+ ctx.addIssue({
48
+ code: z.ZodIssueCode.custom,
49
+ message: `An environment variable whose name is prefixed by "${PUBLIC_PREFIX}" must be public.`
50
+ });
51
+ }
52
+ if (value.access === "public" && !key.startsWith(PUBLIC_PREFIX)) {
53
+ ctx.addIssue({
54
+ code: z.ZodIssueCode.custom,
55
+ message: `An environment variable that is public must have a name prefixed by "${PUBLIC_PREFIX}".`
56
+ });
57
+ }
58
+ }
59
+ });
60
+ const StringField = z.intersection(
61
+ z.union([
62
+ PublicClientEnvFieldMetadata,
63
+ PublicServerEnvFieldMetadata,
64
+ SecretServerEnvFieldMetadata
65
+ ]),
66
+ StringSchema
67
+ );
68
+ const StringFieldInput = z.intersection(
69
+ z.union([
70
+ PublicClientEnvFieldMetadata,
71
+ PublicServerEnvFieldMetadata,
72
+ SecretServerEnvFieldMetadata
73
+ ]),
74
+ StringSchema.omit({ type: true })
75
+ );
76
+ const NumberField = z.intersection(
77
+ z.union([
78
+ PublicClientEnvFieldMetadata,
79
+ PublicServerEnvFieldMetadata,
80
+ SecretServerEnvFieldMetadata
81
+ ]),
82
+ NumberSchema
83
+ );
84
+ const NumberFieldInput = z.intersection(
85
+ z.union([
86
+ PublicClientEnvFieldMetadata,
87
+ PublicServerEnvFieldMetadata,
88
+ SecretServerEnvFieldMetadata
89
+ ]),
90
+ NumberSchema.omit({ type: true })
91
+ );
92
+ const BooleanField = z.intersection(
93
+ z.union([
94
+ PublicClientEnvFieldMetadata,
95
+ PublicServerEnvFieldMetadata,
96
+ SecretServerEnvFieldMetadata
97
+ ]),
98
+ BooleanSchema
99
+ );
100
+ const BooleanFieldInput = z.intersection(
101
+ z.union([
102
+ PublicClientEnvFieldMetadata,
103
+ PublicServerEnvFieldMetadata,
104
+ SecretServerEnvFieldMetadata
105
+ ]),
106
+ BooleanSchema.omit({ type: true })
107
+ );
108
+ export {
109
+ BooleanFieldInput,
110
+ EnvSchema,
111
+ NumberFieldInput,
112
+ StringFieldInput
113
+ };
@@ -0,0 +1,13 @@
1
+ import type { EnvFieldType } from './schema.js';
2
+ export type ValidationResultValue = EnvFieldType['default'];
3
+ type ValidationResult = {
4
+ ok: true;
5
+ type: string;
6
+ value: ValidationResultValue;
7
+ } | {
8
+ ok: false;
9
+ type: string;
10
+ };
11
+ export declare function getEnvFieldType(options: EnvFieldType): string;
12
+ export declare function validateEnvVariable(value: string | undefined, options: EnvFieldType): ValidationResult;
13
+ export {};
@@ -0,0 +1,57 @@
1
+ function getEnvFieldType(options) {
2
+ const optional = options.optional ? options.default !== void 0 ? false : true : false;
3
+ return `${options.type}${optional ? " | undefined" : ""}`;
4
+ }
5
+ const stringValidator = (input) => {
6
+ return {
7
+ valid: typeof input === "string",
8
+ parsed: input
9
+ };
10
+ };
11
+ const numberValidator = (input) => {
12
+ const num = parseFloat(input ?? "");
13
+ return {
14
+ valid: !isNaN(num),
15
+ parsed: num
16
+ };
17
+ };
18
+ const booleanValidator = (input) => {
19
+ const bool = input === "true" ? true : input === "false" ? false : void 0;
20
+ return {
21
+ valid: typeof bool === "boolean",
22
+ parsed: bool
23
+ };
24
+ };
25
+ function validateEnvVariable(value, options) {
26
+ const validator = {
27
+ string: stringValidator,
28
+ number: numberValidator,
29
+ boolean: booleanValidator
30
+ }[options.type];
31
+ const type = getEnvFieldType(options);
32
+ if (options.optional || options.default !== void 0) {
33
+ if (value === void 0) {
34
+ return {
35
+ ok: true,
36
+ value: options.default,
37
+ type
38
+ };
39
+ }
40
+ }
41
+ const { valid, parsed } = validator(value);
42
+ if (valid) {
43
+ return {
44
+ ok: true,
45
+ value: parsed,
46
+ type
47
+ };
48
+ }
49
+ return {
50
+ ok: false,
51
+ type
52
+ };
53
+ }
54
+ export {
55
+ getEnvFieldType,
56
+ validateEnvVariable
57
+ };
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type fsMod from 'node:fs';
3
+ import { type Plugin } from 'vite';
4
+ import type { AstroSettings } from '../@types/astro.js';
5
+ interface AstroEnvVirtualModPluginParams {
6
+ settings: AstroSettings;
7
+ mode: 'dev' | 'build' | string;
8
+ fs: typeof fsMod;
9
+ }
10
+ export declare function astroEnv({ settings, mode, fs, }: AstroEnvVirtualModPluginParams): Plugin | undefined;
11
+ export {};