blank project

This commit is contained in:
root
2025-10-17 20:17:33 +00:00
commit 14b2d53e8e
9366 changed files with 1515019 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 `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 CLIENT_VIRTUAL_MODULE_ID = "astro:env/client";
export declare const RESOLVED_CLIENT_VIRTUAL_MODULE_ID: string;
export declare const SERVER_VIRTUAL_MODULE_ID = "astro:env/server";
export declare const RESOLVED_SERVER_VIRTUAL_MODULE_ID: string;
/** Used to serialize the schema */
export declare const INTERNAL_VIRTUAL_MODULE_ID = "virtual:astro:env/internal";
export declare const RESOLVED_INTERNAL_VIRTUAL_MODULE_ID: string;
export declare const ENV_TYPES_FILE = "env.d.ts";
export declare const MODULE_TEMPLATE_URL: URL;

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

@@ -0,0 +1,19 @@
const CLIENT_VIRTUAL_MODULE_ID = "astro:env/client";
const RESOLVED_CLIENT_VIRTUAL_MODULE_ID = "\0" + CLIENT_VIRTUAL_MODULE_ID;
const SERVER_VIRTUAL_MODULE_ID = "astro:env/server";
const RESOLVED_SERVER_VIRTUAL_MODULE_ID = "\0" + SERVER_VIRTUAL_MODULE_ID;
const INTERNAL_VIRTUAL_MODULE_ID = "virtual:astro:env/internal";
const RESOLVED_INTERNAL_VIRTUAL_MODULE_ID = "\0" + INTERNAL_VIRTUAL_MODULE_ID;
const ENV_TYPES_FILE = "env.d.ts";
const PKG_BASE = new URL("../../", import.meta.url);
const MODULE_TEMPLATE_URL = new URL("templates/env.mjs", PKG_BASE);
export {
CLIENT_VIRTUAL_MODULE_ID,
ENV_TYPES_FILE,
INTERNAL_VIRTUAL_MODULE_ID,
MODULE_TEMPLATE_URL,
RESOLVED_CLIENT_VIRTUAL_MODULE_ID,
RESOLVED_INTERNAL_VIRTUAL_MODULE_ID,
RESOLVED_SERVER_VIRTUAL_MODULE_ID,
SERVER_VIRTUAL_MODULE_ID
};

12
node_modules/astro/dist/env/env-loader.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import type { AstroConfig } from '../types/public/index.js';
interface EnvLoaderOptions {
mode: string;
config: AstroConfig;
useStatic: boolean;
}
export declare const createEnvLoader: (options: EnvLoaderOptions) => {
get: () => Record<string, string>;
getPrivateEnv: () => Record<string, string>;
};
export type EnvLoader = ReturnType<typeof createEnvLoader>;
export {};

51
node_modules/astro/dist/env/env-loader.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
import { fileURLToPath } from "node:url";
import { loadEnv } from "vite";
const isValidIdentifierRe = /^[_$a-zA-Z][\w$]*$/;
function getPrivateEnv({
fullEnv,
viteConfig,
useStatic
}) {
let envPrefixes = ["PUBLIC_"];
if (viteConfig.envPrefix) {
envPrefixes = Array.isArray(viteConfig.envPrefix) ? viteConfig.envPrefix : [viteConfig.envPrefix];
}
const privateEnv = {};
for (const key in fullEnv) {
if (!isValidIdentifierRe.test(key) || envPrefixes.some((prefix) => key.startsWith(prefix))) {
continue;
}
if (!useStatic && typeof process.env[key] !== "undefined") {
let value = process.env[key];
if (typeof value !== "string") {
value = `${value}`;
}
if (value === "0" || value === "1" || value === "true" || value === "false") {
privateEnv[key] = value;
} else {
privateEnv[key] = `process.env.${key}`;
}
} else {
privateEnv[key] = JSON.stringify(fullEnv[key]);
}
}
return privateEnv;
}
function getEnv({ mode, config, useStatic }) {
const loaded = loadEnv(mode, config.vite.envDir ?? fileURLToPath(config.root), "");
const privateEnv = getPrivateEnv({ fullEnv: loaded, viteConfig: config.vite, useStatic });
return { loaded, privateEnv };
}
const createEnvLoader = (options) => {
let { loaded, privateEnv } = getEnv(options);
return {
get: () => {
({ loaded, privateEnv } = getEnv(options));
return loaded;
},
getPrivateEnv: () => privateEnv
};
};
export {
createEnvLoader
};

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 { getEnvFieldType, validateEnvVariable } from './validators.js';
export type GetEnv = (key: string) => string | undefined;
type OnSetGetEnv = () => void;
export declare function setGetEnv(fn: GetEnv): 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 { getEnvFieldType, validateEnvVariable } from "./validators.js";
let _getEnv = (key) => process.env[key];
function setGetEnv(fn) {
_getEnv = fn;
_onSetGetEnv();
}
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
};

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

@@ -0,0 +1,383 @@
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;
optional?: boolean | undefined;
url?: boolean | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
max?: number | undefined;
min?: number | undefined;
}, {
type: "string";
length?: number | undefined;
includes?: string | undefined;
optional?: boolean | undefined;
url?: boolean | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
max?: number | undefined;
min?: 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";
optional?: boolean | undefined;
default?: number | undefined;
max?: number | undefined;
min?: number | undefined;
gt?: number | undefined;
lt?: number | undefined;
int?: boolean | undefined;
}, {
type: "number";
optional?: boolean | undefined;
default?: number | undefined;
max?: number | undefined;
min?: 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";
optional?: boolean | undefined;
default?: boolean | undefined;
}, {
type: "boolean";
optional?: boolean | undefined;
default?: 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[];
optional?: boolean | undefined;
default?: string | undefined;
}, {
type: "enum";
values: string[];
optional?: boolean | undefined;
default?: string | 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;
optional?: boolean | undefined;
url?: boolean | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
max?: number | undefined;
min?: number | undefined;
}, {
type: "string";
length?: number | undefined;
includes?: string | undefined;
optional?: boolean | undefined;
url?: boolean | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
max?: number | undefined;
min?: 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";
optional?: boolean | undefined;
default?: number | undefined;
max?: number | undefined;
min?: number | undefined;
gt?: number | undefined;
lt?: number | undefined;
int?: boolean | undefined;
}, {
type: "number";
optional?: boolean | undefined;
default?: number | undefined;
max?: number | undefined;
min?: 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";
optional?: boolean | undefined;
default?: boolean | undefined;
}, {
type: "boolean";
optional?: boolean | undefined;
default?: 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[];
optional?: boolean | undefined;
default?: string | undefined;
}, {
type: "enum";
values: string[];
optional?: boolean | undefined;
default?: string | undefined;
}>, {
type: "enum";
values: string[];
optional?: boolean | undefined;
default?: string | undefined;
}, {
type: "enum";
values: string[];
optional?: boolean | undefined;
default?: string | undefined;
}>]>;
export type EnvFieldType = z.infer<typeof EnvFieldType>;
declare const EnvFieldMetadata: z.ZodEffects<z.ZodType<{
context: "client";
access: "public";
} | {
context: "server";
access: "public";
} | {
context: "server";
access: "secret";
}, z.ZodTypeDef, {
context: "client";
access: "public";
} | {
context: "server";
access: "public";
} | {
context: "server";
access: "secret";
}>, {
context: "client";
access: "public";
} | {
context: "server";
access: "public";
} | {
context: "server";
access: "secret";
}, {
context: "client";
access: "public";
} | {
context: "server";
access: "public";
} | {
context: "server";
access: "secret";
}>;
export declare const EnvSchema: z.ZodRecord<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>, z.ZodIntersection<z.ZodEffects<z.ZodType<{
context: "client";
access: "public";
} | {
context: "server";
access: "public";
} | {
context: "server";
access: "secret";
}, z.ZodTypeDef, {
context: "client";
access: "public";
} | {
context: "server";
access: "public";
} | {
context: "server";
access: "secret";
}>, {
context: "client";
access: "public";
} | {
context: "server";
access: "public";
} | {
context: "server";
access: "secret";
}, {
context: "client";
access: "public";
} | {
context: "server";
access: "public";
} | {
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;
optional?: boolean | undefined;
url?: boolean | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
max?: number | undefined;
min?: number | undefined;
}, {
type: "string";
length?: number | undefined;
includes?: string | undefined;
optional?: boolean | undefined;
url?: boolean | undefined;
endsWith?: string | undefined;
startsWith?: string | undefined;
default?: string | undefined;
max?: number | undefined;
min?: 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";
optional?: boolean | undefined;
default?: number | undefined;
max?: number | undefined;
min?: number | undefined;
gt?: number | undefined;
lt?: number | undefined;
int?: boolean | undefined;
}, {
type: "number";
optional?: boolean | undefined;
default?: number | undefined;
max?: number | undefined;
min?: 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";
optional?: boolean | undefined;
default?: boolean | undefined;
}, {
type: "boolean";
optional?: boolean | undefined;
default?: 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[];
optional?: boolean | undefined;
default?: string | undefined;
}, {
type: "enum";
values: string[];
optional?: boolean | undefined;
default?: string | undefined;
}>, {
type: "enum";
values: string[];
optional?: boolean | undefined;
default?: string | undefined;
}, {
type: "enum";
values: string[];
optional?: boolean | undefined;
default?: string | 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 {};

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

@@ -0,0 +1,99 @@
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 EnvFieldMetadata = z.custom().superRefine((data, ctx) => {
const result = _EnvFieldMetadata.safeParse(data);
if (result.success) {
return;
}
for (const issue of result.error.issues) {
if (issue.code === z.ZodIssueCode.invalid_union) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `**Invalid combination** of "access" and "context" options:
Secret client variables are not supported. Please review the configuration of \`env.schema.${ctx.path.at(-1)}\`.
Learn more at https://docs.astro.build/en/guides/environment-variables/#variable-types`,
path: ["context", "access"]
});
} else {
ctx.addIssue(issue);
}
}
});
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 { type GetEnv, setGetEnv } 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
};

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

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

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

@@ -0,0 +1,33 @@
import { ENV_TYPES_FILE } from "./constants.js";
import { getEnvFieldType } from "./validators.js";
function syncAstroEnv(settings) {
let client = "";
let server = "";
for (const [key, options] of Object.entries(settings.config.env.schema)) {
const str = ` export const ${key}: ${getEnvFieldType(options)};
`;
if (options.context === "client") {
client += str;
} else {
server += str;
}
}
let content = "";
if (client !== "") {
content = `declare module 'astro:env/client' {
${client}}`;
}
if (server !== "") {
content += `declare module 'astro:env/server' {
${server}}`;
}
if (content !== "") {
settings.injectedTypes.push({
filename: ENV_TYPES_FILE,
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
};

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

@@ -0,0 +1,10 @@
import type { Plugin } from 'vite';
import type { AstroSettings } from '../types/astro.js';
import type { EnvLoader } from './env-loader.js';
interface AstroEnvPluginParams {
settings: AstroSettings;
sync: boolean;
envLoader: EnvLoader;
}
export declare function astroEnv({ settings, sync, envLoader }: AstroEnvPluginParams): Plugin;
export {};

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

@@ -0,0 +1,149 @@
import { readFileSync } from "node:fs";
import { AstroError, AstroErrorData } from "../core/errors/index.js";
import {
CLIENT_VIRTUAL_MODULE_ID,
INTERNAL_VIRTUAL_MODULE_ID,
MODULE_TEMPLATE_URL,
RESOLVED_CLIENT_VIRTUAL_MODULE_ID,
RESOLVED_INTERNAL_VIRTUAL_MODULE_ID,
RESOLVED_SERVER_VIRTUAL_MODULE_ID,
SERVER_VIRTUAL_MODULE_ID
} from "./constants.js";
import { invalidVariablesToError } from "./errors.js";
import { getEnvFieldType, validateEnvVariable } from "./validators.js";
function astroEnv({ settings, sync, envLoader }) {
const { schema, validateSecrets } = settings.config.env;
let isDev;
let templates = null;
function ensureTemplateAreLoaded() {
if (templates !== null) {
return;
}
const loadedEnv = envLoader.get();
if (!isDev) {
for (const [key, value] of Object.entries(loadedEnv)) {
if (value !== void 0) {
process.env[key] = value;
}
}
}
const validatedVariables = validatePublicVariables({
schema,
loadedEnv,
validateSecrets,
sync
});
templates = {
...getTemplates(schema, validatedVariables, isDev ? loadedEnv : null),
internal: `export const schema = ${JSON.stringify(schema)};`
};
}
return {
name: "astro-env-plugin",
enforce: "pre",
config(_, { command }) {
isDev = command !== "build";
},
buildStart() {
ensureTemplateAreLoaded();
},
buildEnd() {
templates = null;
},
resolveId(id) {
if (id === CLIENT_VIRTUAL_MODULE_ID) {
return RESOLVED_CLIENT_VIRTUAL_MODULE_ID;
}
if (id === SERVER_VIRTUAL_MODULE_ID) {
return RESOLVED_SERVER_VIRTUAL_MODULE_ID;
}
if (id === INTERNAL_VIRTUAL_MODULE_ID) {
return RESOLVED_INTERNAL_VIRTUAL_MODULE_ID;
}
},
load(id, options) {
if (id === RESOLVED_CLIENT_VIRTUAL_MODULE_ID) {
ensureTemplateAreLoaded();
return { code: templates.client };
}
if (id === RESOLVED_SERVER_VIRTUAL_MODULE_ID) {
if (options?.ssr) {
ensureTemplateAreLoaded();
return { code: templates.server };
}
throw new AstroError({
...AstroErrorData.ServerOnlyModule,
message: AstroErrorData.ServerOnlyModule.message(SERVER_VIRTUAL_MODULE_ID)
});
}
if (id === RESOLVED_INTERNAL_VIRTUAL_MODULE_ID) {
ensureTemplateAreLoaded();
return { code: templates.internal };
}
}
};
}
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, validatedVariables, loadedEnv) {
let client = "";
let server = 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} = _internalGetSecret(${JSON.stringify(key)});
`;
}
server = server.replace("// @@ON_SET_GET_ENV@@", onSetGetEnv);
if (loadedEnv) {
server = server.replace("// @@GET_ENV@@", `return (${JSON.stringify(loadedEnv)})[key];`);
} else {
server = server.replace("// @@GET_ENV@@", "return _getEnv(key);");
}
return {
client,
server
};
}
export {
astroEnv
};

View File

@@ -0,0 +1,7 @@
import type * as vite from 'vite';
import type { EnvLoader } from './env-loader.js';
interface EnvPluginOptions {
envLoader: EnvLoader;
}
export declare function importMetaEnv({ envLoader }: EnvPluginOptions): vite.Plugin;
export {};

View File

@@ -0,0 +1,114 @@
import { transform } from "esbuild";
import MagicString from "magic-string";
import { createFilter, isCSSRequest } from "vite";
const importMetaEnvOnlyRe = /\bimport\.meta\.env\b(?!\.)/;
function getReferencedPrivateKeys(source, privateEnv) {
const references = /* @__PURE__ */ new Set();
for (const key in privateEnv) {
if (source.includes(key)) {
references.add(key);
}
}
return references;
}
async function replaceDefine(code, id, define, config) {
const replacementMarkers = {};
const env = define["import.meta.env"];
if (env) {
const marker = `__astro_import_meta_env${"_".repeat(
env.length - 23
)}`;
replacementMarkers[marker] = env;
define = { ...define, "import.meta.env": marker };
}
const esbuildOptions = config.esbuild || {};
const result = await transform(code, {
loader: "js",
charset: esbuildOptions.charset ?? "utf8",
platform: "neutral",
define,
sourcefile: id,
sourcemap: config.command === "build" ? !!config.build.sourcemap : true
});
for (const marker in replacementMarkers) {
result.code = result.code.replaceAll(marker, replacementMarkers[marker]);
}
return {
code: result.code,
map: result.map || null
};
}
function importMetaEnv({ envLoader }) {
let privateEnv;
let defaultDefines;
let isDev;
let devImportMetaEnvPrepend;
let viteConfig;
const filter = createFilter(null, ["**/*.html", "**/*.htm", "**/*.json"]);
return {
name: "astro:vite-plugin-env",
config(_, { command }) {
isDev = command !== "build";
},
configResolved(resolvedConfig) {
viteConfig = resolvedConfig;
const viteDefinePluginIndex = resolvedConfig.plugins.findIndex(
(p) => p.name === "vite:define"
);
if (viteDefinePluginIndex !== -1) {
const myPluginIndex = resolvedConfig.plugins.findIndex(
(p) => p.name === "astro:vite-plugin-env"
);
if (myPluginIndex !== -1) {
const myPlugin = resolvedConfig.plugins[myPluginIndex];
resolvedConfig.plugins.splice(viteDefinePluginIndex, 0, myPlugin);
resolvedConfig.plugins.splice(myPluginIndex, 1);
}
}
},
transform(source, id, options) {
if (!options?.ssr || !source.includes("import.meta.env") || !filter(id) || isCSSRequest(id) || viteConfig.assetsInclude(id)) {
return;
}
privateEnv ??= envLoader.getPrivateEnv();
if (isDev) {
const s = new MagicString(source);
if (!devImportMetaEnvPrepend) {
devImportMetaEnvPrepend = `Object.assign(import.meta.env,{`;
for (const key in privateEnv) {
devImportMetaEnvPrepend += `${key}:${privateEnv[key]},`;
}
devImportMetaEnvPrepend += "});";
}
s.prepend(devImportMetaEnvPrepend);
return {
code: s.toString(),
map: s.generateMap({ hires: "boundary" })
};
}
if (!defaultDefines) {
defaultDefines = {};
for (const key in privateEnv) {
defaultDefines[`import.meta.env.${key}`] = privateEnv[key];
}
}
let defines = defaultDefines;
if (importMetaEnvOnlyRe.test(source)) {
const references = getReferencedPrivateKeys(source, privateEnv);
let replacement = `(Object.assign(import.meta.env,{`;
for (const key of references.values()) {
replacement += `${key}:${privateEnv[key]},`;
}
replacement += "}))";
defines = {
...defaultDefines,
"import.meta.env": replacement
};
}
return replaceDefine(source, id, defines, viteConfig);
}
};
}
export {
importMetaEnv
};