mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(schemas,core): enable min string length guard (#3850)
enable min string length guard to all non-null string typed field in Guards
This commit is contained in:
parent
7144163530
commit
21d1fa42c7
2 changed files with 7 additions and 1 deletions
|
@ -65,6 +65,7 @@ export const generateSchema = ({ name, fields }: TableWithType) => {
|
|||
`const guard: Guard<${modelName}> = z.object({`,
|
||||
|
||||
...fields.map(
|
||||
// eslint-disable-next-line complexity
|
||||
({ name, type, isArray, isEnum, nullable, tsType, isString, maxLength, hasDefaultValue }) => {
|
||||
if (tsType) {
|
||||
return ` ${camelcase(name)}: ${camelcase(tsType)}Guard${conditionalString(
|
||||
|
@ -73,6 +74,11 @@ export const generateSchema = ({ name, fields }: TableWithType) => {
|
|||
}
|
||||
|
||||
return ` ${camelcase(name)}: z.${isEnum ? `nativeEnum(${type})` : `${type}()`}${
|
||||
// Non-nullable strings should have a min length of 1
|
||||
conditionalString(
|
||||
isString && !(nullable || hasDefaultValue || name === tenantId) && `.min(1)`
|
||||
)
|
||||
}${
|
||||
// String types value in DB should have a max length
|
||||
conditionalString(isString && maxLength && `.max(${maxLength})`)
|
||||
}${conditionalString(isArray && '.array()')}${conditionalString(
|
||||
|
|
|
@ -22,7 +22,7 @@ export const buildDemoAppDataForTenant = (tenantId: string): Application => ({
|
|||
tenantId,
|
||||
id: demoAppApplicationId,
|
||||
name: 'Live Preview',
|
||||
secret: '',
|
||||
secret: 'N/A',
|
||||
description: 'Preview for Sign-in Experience.',
|
||||
type: ApplicationType.SPA,
|
||||
oidcClientMetadata: { redirectUris: [], postLogoutRedirectUris: [] },
|
||||
|
|
Loading…
Reference in a new issue