Skip to content

Commit

Permalink
Moved EnvSchema record key schema to dedicated EnvSchemaKey schema
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Lefebvre <[email protected]>
  • Loading branch information
NuroDev and florian-lefebvre authored Jul 9, 2024
1 parent 1dd85a3 commit e7e6126
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/astro/src/env/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ const EnvFieldMetadata = z.union([
SecretServerEnvFieldMetadata,
]);

const KEY_REGEX = /^[A-Z0-9_]+$/;
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.',
});

export const EnvSchema = z.record(
z
.string()
.min(1)
.refine(([firstChar]) => isNaN(Number.parseInt(firstChar)), {
message: 'A valid variable name cannot start with a number.',
})
.refine((str) => KEY_REGEX.test(str), {
message: 'A valid variable name can only contain uppercase letters, numbers and underscores.',
}),
EnvSchemaKey
z.intersection(EnvFieldMetadata, EnvFieldType)
);

Expand Down

0 comments on commit e7e6126

Please sign in to comment.