Skip to main content

@terascope/core-utils / schemas / SchemaValidator

Class: SchemaValidator<T>

Defined in: packages/core-utils/src/schemas.ts:233

Facade class used to validate convict style schemas using the Zod library

Type Parameters

Type ParameterDefault type
TAnyObject

Constructors

Constructor

new SchemaValidator<T>(schema, name, extraFormats, checkUndeclaredKeys): SchemaValidator<T>

Defined in: packages/core-utils/src/schemas.ts:242

Parameters

ParameterTypeDefault value
schemaTF.Schema<T>undefined
namestringundefined
extraFormatsFormat[][]
checkUndeclaredKeysCheckUndeclaredKeys'warn'

Returns

SchemaValidator<T>

Properties

PropertyTypeDefault valueDefined in
argsMapRecord<string, { argName: string; format: TF.ConvictFormat; }>{}packages/core-utils/src/schemas.ts:239
checkUndeclaredKeysCheckUndeclaredKeysundefinedpackages/core-utils/src/schemas.ts:237
envMapRecord<string, { envName: string; format: TF.ConvictFormat; }>{}packages/core-utils/src/schemas.ts:238
inputSchemaTF.Schema<T>undefinedpackages/core-utils/src/schemas.ts:235
loggerLoggerundefinedpackages/core-utils/src/schemas.ts:240
namestringundefinedpackages/core-utils/src/schemas.ts:234
zodSchemaZodType<T>undefinedpackages/core-utils/src/schemas.ts:236

Methods

_BaseSchemaObjToZod()

_BaseSchemaObjToZod(schemaObj, key): ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> | ZodPipe<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>, ZodTransform<any, unknown>>

Defined in: packages/core-utils/src/schemas.ts:397

Converts a convict style schema object to a zod schema

Parameters

ParameterTypeDescription
schemaObjSchemaObjThe schema object to convert
keyPropertyKeyThe name of the property that uses the schemaObj

Returns

ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> | ZodPipe<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>, ZodTransform<any, unknown>>

A Zod schema object


_convictStyleSchemaToZod()

_convictStyleSchemaToZod(schema, parentKey): ZodType<T, unknown, $ZodTypeInternals<T, unknown>> | ZodDefault<ZodAny>

Defined in: packages/core-utils/src/schemas.ts:362

convert a convict style schema to zod schema

Parameters

ParameterTypeDescription
schemaTF.Schema<T>A convict style schema
parentKeyPropertyKeyProperty name of a nested schema object or other identifier for the schema

Returns

ZodType<T, unknown, $ZodTypeInternals<T, unknown>> | ZodDefault<ZodAny>

A zod schema


_getBaseType()

_getBaseType(key, convictFormatValue): ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

Defined in: packages/core-utils/src/schemas.ts:505

Determines the base type that a full schema will be built on

Parameters

ParameterTypeDescription
keyPropertyKeyThe name of the property that uses the schemaObj
convictFormatValueConvictFormatA convict compatible format value

Returns

ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

The base type


_getCustomFormatFromName()

_getCustomFormatFromName(format): Format | null | undefined

Defined in: packages/core-utils/src/schemas.ts:610

Look up a custom format by name and return the format object

Parameters

ParameterType
formatConvictFormat | undefined

Returns

Format | null | undefined


_isCustomFormatName()

_isCustomFormatName(format): boolean

Defined in: packages/core-utils/src/schemas.ts:618

Determine if a format is the name of a custom format

Parameters

ParameterType
formatConvictFormat

Returns

boolean


_validateDefault()

_validateDefault(type, defaultVal): void

Defined in: packages/core-utils/src/schemas.ts:583

Run the default value against the created schema to ensure it is valid

Parameters

ParameterType
typeZodType
defaultValany

Returns

void


getSchemaObjectKeys()

getSchemaObjectKeys(schema): string[] | undefined

Defined in: packages/core-utils/src/schemas.ts:590

Unwrap the wrappers on base schema object and retrieve all keys

Parameters

ParameterType
schemaZodType

Returns

string[] | undefined


validate()

validate(config): T

Defined in: packages/core-utils/src/schemas.ts:279

Validate that a configuration conforms to the schema

Parameters

ParameterTypeDescription
configanyA configuration to validate

Returns

T

A valid object of type T