Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.

This commit is contained in:
becarta
2025-05-23 12:43:00 +02:00
parent f40db0f5c9
commit a544759a3b
11127 changed files with 1647032 additions and 0 deletions

10
node_modules/astro/dist/env/config.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import type { BooleanField, BooleanFieldInput, EnumField, EnumFieldInput, NumberField, NumberFieldInput, StringField, StringFieldInput } from './schema.js';
/**
* Return a valid env field to use in this Astro config for `experimental.env.schema`.
*/
export declare const envField: {
string: (options: StringFieldInput) => StringField;
number: (options: NumberFieldInput) => NumberField;
boolean: (options: BooleanFieldInput) => BooleanField;
enum: <T extends string>(options: EnumFieldInput<T>) => EnumField;
};

21
node_modules/astro/dist/env/config.js generated vendored Normal file
View File

@@ -0,0 +1,21 @@
const envField = {
string: (options) => ({
...options,
type: "string"
}),
number: (options) => ({
...options,
type: "number"
}),
boolean: (options) => ({
...options,
type: "boolean"
}),
enum: (options) => ({
...options,
type: "enum"
})
};
export {
envField
};

9
node_modules/astro/dist/env/constants.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
export declare const VIRTUAL_MODULES_IDS: {
client: string;
server: string;
internal: string;
};
export declare const VIRTUAL_MODULES_IDS_VALUES: Set<string>;
export declare const ENV_TYPES_FILE = "env.d.ts";
export declare const MODULE_TEMPLATE_URL: URL;
export declare const TYPES_TEMPLATE_URL: URL;

17
node_modules/astro/dist/env/constants.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
const VIRTUAL_MODULES_IDS = {
client: "astro:env/client",
server: "astro:env/server",
internal: "virtual:astro:env/internal"
};
const VIRTUAL_MODULES_IDS_VALUES = new Set(Object.values(VIRTUAL_MODULES_IDS));
const ENV_TYPES_FILE = "env.d.ts";
const PKG_BASE = new URL("../../", import.meta.url);
const MODULE_TEMPLATE_URL = new URL("templates/env/module.mjs", PKG_BASE);
const TYPES_TEMPLATE_URL = new URL("templates/env/types.d.ts", PKG_BASE);
export {
ENV_TYPES_FILE,
MODULE_TEMPLATE_URL,
TYPES_TEMPLATE_URL,
VIRTUAL_MODULES_IDS,
VIRTUAL_MODULES_IDS_VALUES
};

7
node_modules/astro/dist/env/errors.d.ts generated vendored Normal file
View File

@@ -0,0 +1,7 @@
import type { ValidationResultErrors } from './validators.js';
export interface InvalidVariable {
key: string;
type: string;
errors: ValidationResultErrors;
}
export declare function invalidVariablesToError(invalid: Array<InvalidVariable>): string[];

16
node_modules/astro/dist/env/errors.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
function invalidVariablesToError(invalid) {
const _errors = [];
for (const { key, type, errors } of invalid) {
if (errors[0] === "missing") {
_errors.push(`${key} is missing`);
} else if (errors[0] === "type") {
_errors.push(`${key}'s type is invalid, expected: ${type}`);
} else {
_errors.push(`The following constraints for ${key} are not met: ${errors.join(", ")}`);
}
}
return _errors;
}
export {
invalidVariablesToError
};

9
node_modules/astro/dist/env/runtime.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
import { AstroError } from '../core/errors/index.js';
import type { ValidationResultInvalid } from './validators.js';
export { validateEnvVariable, getEnvFieldType } from './validators.js';
export type GetEnv = (key: string) => string | undefined;
type OnSetGetEnv = (reset: boolean) => void;
export declare function setGetEnv(fn: GetEnv, reset?: boolean): void;
export declare function setOnSetGetEnv(fn: OnSetGetEnv): void;
export declare function getEnv(...args: Parameters<GetEnv>): string | undefined;
export declare function createInvalidVariablesError(key: string, type: string, result: ValidationResultInvalid): AstroError;

32
node_modules/astro/dist/env/runtime.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
import { AstroError, AstroErrorData } from "../core/errors/index.js";
import { invalidVariablesToError } from "./errors.js";
import { validateEnvVariable, getEnvFieldType } from "./validators.js";
let _getEnv = (key) => process.env[key];
function setGetEnv(fn, reset = false) {
_getEnv = fn;
_onSetGetEnv(reset);
}
let _onSetGetEnv = () => {
};
function setOnSetGetEnv(fn) {
_onSetGetEnv = fn;
}
function getEnv(...args) {
return _getEnv(...args);
}
function createInvalidVariablesError(key, type, result) {
return new AstroError({
...AstroErrorData.EnvInvalidVariables,
message: AstroErrorData.EnvInvalidVariables.message(
invalidVariablesToError([{ key, type, errors: result.errors }])
)
});
}
export {
createInvalidVariablesError,
getEnv,
getEnvFieldType,
setGetEnv,
setOnSetGetEnv,
validateEnvVariable
};

365
node_modules/astro/dist/env/schema.d.ts generated vendored Normal file
View File

@@ -0,0 +1,365 @@
import { z } from 'zod';
declare const StringSchema: z.ZodObject<{
type: z.ZodLiteral<"string">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodString>;
max: z.ZodOptional<z.ZodNumber>;
min: z.ZodOptional<z.ZodNumber>;
length: z.ZodOptional<z.ZodNumber>;
url: z.ZodOptional<z.ZodBoolean>;
includes: z.ZodOptional<z.ZodString>;
startsWith: z.ZodOptional<z.ZodString>;
endsWith: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
type: "string";
length?: number | undefined;
includes?: string | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
url?: boolean | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
}, {
type: "string";
length?: number | undefined;
includes?: string | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
url?: boolean | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
}>;
export type StringSchema = z.infer<typeof StringSchema>;
declare const NumberSchema: z.ZodObject<{
type: z.ZodLiteral<"number">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodNumber>;
gt: z.ZodOptional<z.ZodNumber>;
min: z.ZodOptional<z.ZodNumber>;
lt: z.ZodOptional<z.ZodNumber>;
max: z.ZodOptional<z.ZodNumber>;
int: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
type: "number";
default?: number | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
gt?: number | undefined;
lt?: number | undefined;
int?: boolean | undefined;
}, {
type: "number";
default?: number | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
gt?: number | undefined;
lt?: number | undefined;
int?: boolean | undefined;
}>;
export type NumberSchema = z.infer<typeof NumberSchema>;
declare const BooleanSchema: z.ZodObject<{
type: z.ZodLiteral<"boolean">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
type: "boolean";
default?: boolean | undefined;
optional?: boolean | undefined;
}, {
type: "boolean";
default?: boolean | undefined;
optional?: boolean | undefined;
}>;
declare const EnumSchema: z.ZodObject<{
type: z.ZodLiteral<"enum">;
values: z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}>;
export type EnumSchema = z.infer<typeof EnumSchema>;
declare const EnvFieldType: z.ZodUnion<[z.ZodObject<{
type: z.ZodLiteral<"string">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodString>;
max: z.ZodOptional<z.ZodNumber>;
min: z.ZodOptional<z.ZodNumber>;
length: z.ZodOptional<z.ZodNumber>;
url: z.ZodOptional<z.ZodBoolean>;
includes: z.ZodOptional<z.ZodString>;
startsWith: z.ZodOptional<z.ZodString>;
endsWith: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
type: "string";
length?: number | undefined;
includes?: string | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
url?: boolean | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
}, {
type: "string";
length?: number | undefined;
includes?: string | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
url?: boolean | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
}>, z.ZodObject<{
type: z.ZodLiteral<"number">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodNumber>;
gt: z.ZodOptional<z.ZodNumber>;
min: z.ZodOptional<z.ZodNumber>;
lt: z.ZodOptional<z.ZodNumber>;
max: z.ZodOptional<z.ZodNumber>;
int: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
type: "number";
default?: number | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
gt?: number | undefined;
lt?: number | undefined;
int?: boolean | undefined;
}, {
type: "number";
default?: number | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
gt?: number | undefined;
lt?: number | undefined;
int?: boolean | undefined;
}>, z.ZodObject<{
type: z.ZodLiteral<"boolean">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
type: "boolean";
default?: boolean | undefined;
optional?: boolean | undefined;
}, {
type: "boolean";
default?: boolean | undefined;
optional?: boolean | undefined;
}>, z.ZodEffects<z.ZodObject<{
type: z.ZodLiteral<"enum">;
values: z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}>, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}>]>;
export type EnvFieldType = z.infer<typeof EnvFieldType>;
declare const EnvFieldMetadata: z.ZodUnion<[z.ZodObject<{
context: z.ZodLiteral<"client">;
access: z.ZodLiteral<"public">;
}, "strip", z.ZodTypeAny, {
context: "client";
access: "public";
}, {
context: "client";
access: "public";
}>, z.ZodObject<{
context: z.ZodLiteral<"server">;
access: z.ZodLiteral<"public">;
}, "strip", z.ZodTypeAny, {
context: "server";
access: "public";
}, {
context: "server";
access: "public";
}>, z.ZodObject<{
context: z.ZodLiteral<"server">;
access: z.ZodLiteral<"secret">;
}, "strip", z.ZodTypeAny, {
context: "server";
access: "secret";
}, {
context: "server";
access: "secret";
}>]>;
export declare const EnvSchema: z.ZodRecord<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>, z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
context: z.ZodLiteral<"client">;
access: z.ZodLiteral<"public">;
}, "strip", z.ZodTypeAny, {
context: "client";
access: "public";
}, {
context: "client";
access: "public";
}>, z.ZodObject<{
context: z.ZodLiteral<"server">;
access: z.ZodLiteral<"public">;
}, "strip", z.ZodTypeAny, {
context: "server";
access: "public";
}, {
context: "server";
access: "public";
}>, z.ZodObject<{
context: z.ZodLiteral<"server">;
access: z.ZodLiteral<"secret">;
}, "strip", z.ZodTypeAny, {
context: "server";
access: "secret";
}, {
context: "server";
access: "secret";
}>]>, z.ZodUnion<[z.ZodObject<{
type: z.ZodLiteral<"string">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodString>;
max: z.ZodOptional<z.ZodNumber>;
min: z.ZodOptional<z.ZodNumber>;
length: z.ZodOptional<z.ZodNumber>;
url: z.ZodOptional<z.ZodBoolean>;
includes: z.ZodOptional<z.ZodString>;
startsWith: z.ZodOptional<z.ZodString>;
endsWith: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
type: "string";
length?: number | undefined;
includes?: string | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
url?: boolean | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
}, {
type: "string";
length?: number | undefined;
includes?: string | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
url?: boolean | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
}>, z.ZodObject<{
type: z.ZodLiteral<"number">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodNumber>;
gt: z.ZodOptional<z.ZodNumber>;
min: z.ZodOptional<z.ZodNumber>;
lt: z.ZodOptional<z.ZodNumber>;
max: z.ZodOptional<z.ZodNumber>;
int: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
type: "number";
default?: number | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
gt?: number | undefined;
lt?: number | undefined;
int?: boolean | undefined;
}, {
type: "number";
default?: number | undefined;
optional?: boolean | undefined;
min?: number | undefined;
max?: number | undefined;
gt?: number | undefined;
lt?: number | undefined;
int?: boolean | undefined;
}>, z.ZodObject<{
type: z.ZodLiteral<"boolean">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
type: "boolean";
default?: boolean | undefined;
optional?: boolean | undefined;
}, {
type: "boolean";
default?: boolean | undefined;
optional?: boolean | undefined;
}>, z.ZodEffects<z.ZodObject<{
type: z.ZodLiteral<"enum">;
values: z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">;
optional: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}>, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}, {
type: "enum";
values: string[];
default?: string | undefined;
optional?: boolean | undefined;
}>]>>>;
type Prettify<T> = {
[K in keyof T]: T[K];
} & {};
export type EnvSchema = z.infer<typeof EnvSchema>;
type _Field<T extends z.ZodType> = Prettify<z.infer<typeof EnvFieldMetadata & T>>;
type _FieldInput<T extends z.ZodType, TKey extends string = 'type'> = Prettify<z.infer<typeof EnvFieldMetadata> & Omit<z.infer<T>, TKey>>;
export type StringField = _Field<typeof StringSchema>;
export type StringFieldInput = _FieldInput<typeof StringSchema>;
export type NumberField = _Field<typeof NumberSchema>;
export type NumberFieldInput = _FieldInput<typeof NumberSchema>;
export type BooleanField = _Field<typeof BooleanSchema>;
export type BooleanFieldInput = _FieldInput<typeof BooleanSchema>;
export type EnumField = _Field<typeof EnumSchema>;
export type EnumFieldInput<T extends string> = Prettify<_FieldInput<typeof EnumSchema, 'type' | 'values' | 'default'> & {
values: Array<T>;
default?: NoInfer<T> | undefined;
}>;
export {};

80
node_modules/astro/dist/env/schema.js generated vendored Normal file
View File

@@ -0,0 +1,80 @@
import { z } from "zod";
const StringSchema = z.object({
type: z.literal("string"),
optional: z.boolean().optional(),
default: z.string().optional(),
max: z.number().optional(),
min: z.number().min(0).optional(),
length: z.number().optional(),
url: z.boolean().optional(),
includes: z.string().optional(),
startsWith: z.string().optional(),
endsWith: z.string().optional()
});
const NumberSchema = z.object({
type: z.literal("number"),
optional: z.boolean().optional(),
default: z.number().optional(),
gt: z.number().optional(),
min: z.number().optional(),
lt: z.number().optional(),
max: z.number().optional(),
int: z.boolean().optional()
});
const BooleanSchema = z.object({
type: z.literal("boolean"),
optional: z.boolean().optional(),
default: z.boolean().optional()
});
const EnumSchema = z.object({
type: z.literal("enum"),
values: z.array(
// We use "'" for codegen so it can't be passed here
z.string().refine((v) => !v.includes("'"), {
message: `The "'" character can't be used as an enum value`
})
),
optional: z.boolean().optional(),
default: z.string().optional()
});
const EnvFieldType = z.union([
StringSchema,
NumberSchema,
BooleanSchema,
EnumSchema.superRefine((schema, ctx) => {
if (schema.default) {
if (!schema.values.includes(schema.default)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The default value "${schema.default}" must be one of the specified values: ${schema.values.join(", ")}.`
});
}
}
})
]);
const PublicClientEnvFieldMetadata = z.object({
context: z.literal("client"),
access: z.literal("public")
});
const PublicServerEnvFieldMetadata = z.object({
context: z.literal("server"),
access: z.literal("public")
});
const SecretServerEnvFieldMetadata = z.object({
context: z.literal("server"),
access: z.literal("secret")
});
const EnvFieldMetadata = z.union([
PublicClientEnvFieldMetadata,
PublicServerEnvFieldMetadata,
SecretServerEnvFieldMetadata
]);
const EnvSchemaKey = z.string().min(1).refine(([firstChar]) => isNaN(Number.parseInt(firstChar)), {
message: "A valid variable name cannot start with a number."
}).refine((str) => /^[A-Z0-9_]+$/.test(str), {
message: "A valid variable name can only contain uppercase letters, numbers and underscores."
});
const EnvSchema = z.record(EnvSchemaKey, z.intersection(EnvFieldMetadata, EnvFieldType));
export {
EnvSchema
};

1
node_modules/astro/dist/env/setup.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export { setGetEnv, type GetEnv } from './runtime.js';

4
node_modules/astro/dist/env/setup.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
import { setGetEnv } from "./runtime.js";
export {
setGetEnv
};

3
node_modules/astro/dist/env/sync.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
import fsMod from 'node:fs';
import type { AstroSettings } from '../@types/astro.js';
export declare function syncAstroEnv(settings: AstroSettings, fs?: typeof fsMod): void;

29
node_modules/astro/dist/env/sync.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
import fsMod from "node:fs";
import { TYPES_TEMPLATE_URL } from "./constants.js";
import { getEnvFieldType } from "./validators.js";
function syncAstroEnv(settings, fs = fsMod) {
if (!settings.config.experimental.env) {
return;
}
const schema = settings.config.experimental.env.schema ?? {};
let client = "";
let server = "";
for (const [key, options] of Object.entries(schema)) {
const str = `export const ${key}: ${getEnvFieldType(options)};
`;
if (options.context === "client") {
client += str;
} else {
server += str;
}
}
const template = fs.readFileSync(TYPES_TEMPLATE_URL, "utf-8");
const content = template.replace("// @@CLIENT@@", client).replace("// @@SERVER@@", server);
settings.injectedTypes.push({
filename: "astro/env.d.ts",
content
});
}
export {
syncAstroEnv
};

15
node_modules/astro/dist/env/validators.d.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
import type { EnvFieldType } from './schema.js';
export type ValidationResultValue = EnvFieldType['default'];
export type ValidationResultErrors = ['missing'] | ['type'] | Array<string>;
interface ValidationResultValid {
ok: true;
value: ValidationResultValue;
}
export interface ValidationResultInvalid {
ok: false;
errors: ValidationResultErrors;
}
type ValidationResult = ValidationResultValid | ValidationResultInvalid;
export declare function getEnvFieldType(options: EnvFieldType): string;
export declare function validateEnvVariable(value: string | undefined, options: EnvFieldType): ValidationResult;
export {};

145
node_modules/astro/dist/env/validators.js generated vendored Normal file
View File

@@ -0,0 +1,145 @@
function getEnvFieldType(options) {
const optional = options.optional ? options.default !== void 0 ? false : true : false;
let type;
if (options.type === "enum") {
type = options.values.map((v) => `'${v}'`).join(" | ");
} else {
type = options.type;
}
return `${type}${optional ? " | undefined" : ""}`;
}
const stringValidator = ({ max, min, length, url, includes, startsWith, endsWith }) => (input) => {
if (typeof input !== "string") {
return {
ok: false,
errors: ["type"]
};
}
const errors = [];
if (max !== void 0 && !(input.length <= max)) {
errors.push("max");
}
if (min !== void 0 && !(input.length >= min)) {
errors.push("min");
}
if (length !== void 0 && !(input.length === length)) {
errors.push("length");
}
if (url !== void 0 && !URL.canParse(input)) {
errors.push("url");
}
if (includes !== void 0 && !input.includes(includes)) {
errors.push("includes");
}
if (startsWith !== void 0 && !input.startsWith(startsWith)) {
errors.push("startsWith");
}
if (endsWith !== void 0 && !input.endsWith(endsWith)) {
errors.push("endsWith");
}
if (errors.length > 0) {
return {
ok: false,
errors
};
}
return {
ok: true,
value: input
};
};
const numberValidator = ({ gt, min, lt, max, int }) => (input) => {
const num = parseFloat(input ?? "");
if (isNaN(num)) {
return {
ok: false,
errors: ["type"]
};
}
const errors = [];
if (gt !== void 0 && !(num > gt)) {
errors.push("gt");
}
if (min !== void 0 && !(num >= min)) {
errors.push("min");
}
if (lt !== void 0 && !(num < lt)) {
errors.push("lt");
}
if (max !== void 0 && !(num <= max)) {
errors.push("max");
}
if (int !== void 0) {
const isInt = Number.isInteger(num);
if (!(int ? isInt : !isInt)) {
errors.push("int");
}
}
if (errors.length > 0) {
return {
ok: false,
errors
};
}
return {
ok: true,
value: num
};
};
const booleanValidator = (input) => {
const bool = input === "true" ? true : input === "false" ? false : void 0;
if (typeof bool !== "boolean") {
return {
ok: false,
errors: ["type"]
};
}
return {
ok: true,
value: bool
};
};
const enumValidator = ({ values }) => (input) => {
if (!(typeof input === "string" ? values.includes(input) : false)) {
return {
ok: false,
errors: ["type"]
};
}
return {
ok: true,
value: input
};
};
function selectValidator(options) {
switch (options.type) {
case "string":
return stringValidator(options);
case "number":
return numberValidator(options);
case "boolean":
return booleanValidator;
case "enum":
return enumValidator(options);
}
}
function validateEnvVariable(value, options) {
const isOptional = options.optional || options.default !== void 0;
if (isOptional && value === void 0) {
return {
ok: true,
value: options.default
};
}
if (!isOptional && value === void 0) {
return {
ok: false,
errors: ["missing"]
};
}
return selectValidator(options)(value);
}
export {
getEnvFieldType,
validateEnvVariable
};

11
node_modules/astro/dist/env/vite-plugin-env.d.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
import type fsMod from 'node:fs';
import { type Plugin } from 'vite';
import type { AstroSettings } from '../@types/astro.js';
interface AstroEnvVirtualModPluginParams {
settings: AstroSettings;
mode: 'dev' | 'build' | string;
fs: typeof fsMod;
sync: boolean;
}
export declare function astroEnv({ settings, mode, fs, sync, }: AstroEnvVirtualModPluginParams): Plugin | undefined;
export {};

135
node_modules/astro/dist/env/vite-plugin-env.js generated vendored Normal file
View File

@@ -0,0 +1,135 @@
import { fileURLToPath } from "node:url";
import { loadEnv } from "vite";
import { AstroError, AstroErrorData } from "../core/errors/index.js";
import {
MODULE_TEMPLATE_URL,
VIRTUAL_MODULES_IDS,
VIRTUAL_MODULES_IDS_VALUES
} from "./constants.js";
import { invalidVariablesToError } from "./errors.js";
import { getEnvFieldType, validateEnvVariable } from "./validators.js";
function astroEnv({
settings,
mode,
fs,
sync
}) {
if (!settings.config.experimental.env) {
return;
}
const schema = settings.config.experimental.env.schema ?? {};
let templates = null;
return {
name: "astro-env-plugin",
enforce: "pre",
buildStart() {
const loadedEnv = loadEnv(
mode === "dev" ? "development" : "production",
fileURLToPath(settings.config.root),
""
);
for (const [key, value] of Object.entries(loadedEnv)) {
if (value !== void 0) {
process.env[key] = value;
}
}
const validatedVariables = validatePublicVariables({
schema,
loadedEnv,
validateSecrets: settings.config.experimental.env?.validateSecrets ?? false,
sync
});
templates = {
...getTemplates(schema, fs, validatedVariables),
internal: `export const schema = ${JSON.stringify(schema)};`
};
},
buildEnd() {
templates = null;
},
resolveId(id) {
if (VIRTUAL_MODULES_IDS_VALUES.has(id)) {
return resolveVirtualModuleId(id);
}
},
load(id, options) {
if (id === resolveVirtualModuleId(VIRTUAL_MODULES_IDS.client)) {
return templates.client;
}
if (id === resolveVirtualModuleId(VIRTUAL_MODULES_IDS.server)) {
if (options?.ssr) {
return templates.server;
}
throw new AstroError({
...AstroErrorData.ServerOnlyModule,
message: AstroErrorData.ServerOnlyModule.message(VIRTUAL_MODULES_IDS.server)
});
}
if (id === resolveVirtualModuleId(VIRTUAL_MODULES_IDS.internal)) {
return templates.internal;
}
}
};
}
function resolveVirtualModuleId(id) {
return `\0${id}`;
}
function validatePublicVariables({
schema,
loadedEnv,
validateSecrets,
sync
}) {
const valid = [];
const invalid = [];
for (const [key, options] of Object.entries(schema)) {
const variable = loadedEnv[key] === "" ? void 0 : loadedEnv[key];
if (options.access === "secret" && !validateSecrets) {
continue;
}
const result = validateEnvVariable(variable, options);
const type = getEnvFieldType(options);
if (!result.ok) {
invalid.push({ key, type, errors: result.errors });
} else if (options.access === "public") {
valid.push({ key, value: result.value, type, context: options.context });
}
}
if (invalid.length > 0 && !sync) {
throw new AstroError({
...AstroErrorData.EnvInvalidVariables,
message: AstroErrorData.EnvInvalidVariables.message(invalidVariablesToError(invalid))
});
}
return valid;
}
function getTemplates(schema, fs, validatedVariables) {
let client = "";
let server = fs.readFileSync(MODULE_TEMPLATE_URL, "utf-8");
let onSetGetEnv = "";
for (const { key, value, context } of validatedVariables) {
const str = `export const ${key} = ${JSON.stringify(value)};`;
if (context === "client") {
client += str;
} else {
server += str;
}
}
for (const [key, options] of Object.entries(schema)) {
if (!(options.context === "server" && options.access === "secret")) {
continue;
}
server += `export let ${key} = _internalGetSecret(${JSON.stringify(key)});
`;
onSetGetEnv += `${key} = reset ? undefined : _internalGetSecret(${JSON.stringify(key)});
`;
}
server = server.replace("// @@ON_SET_GET_ENV@@", onSetGetEnv);
return {
client,
server
};
}
export {
astroEnv
};