@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 Parameter | Default type |
|---|---|
T | AnyObject |
Constructors
Constructor
new SchemaValidator<
T>(schema,name,extraFormats,checkUndeclaredKeys):SchemaValidator<T>
Defined in: packages/core-utils/src/schemas.ts:242
Parameters
| Parameter | Type | Default value |
|---|---|---|
schema | TF.Schema<T> | undefined |
name | string | undefined |
extraFormats | Format[] | [] |
checkUndeclaredKeys | CheckUndeclaredKeys | 'warn' |
Returns
SchemaValidator<T>
Properties
| Property | Type | Default value | Defined in |
|---|---|---|---|
argsMap | Record<string, { argName: string; format: TF.ConvictFormat; }> | {} | packages/core-utils/src/schemas.ts:239 |
checkUndeclaredKeys | CheckUndeclaredKeys | undefined | packages/core-utils/src/schemas.ts:237 |
envMap | Record<string, { envName: string; format: TF.ConvictFormat; }> | {} | packages/core-utils/src/schemas.ts:238 |
inputSchema | TF.Schema<T> | undefined | packages/core-utils/src/schemas.ts:235 |
logger | Logger | undefined | packages/core-utils/src/schemas.ts:240 |
name | string | undefined | packages/core-utils/src/schemas.ts:234 |
zodSchema | ZodType<T> | undefined | packages/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
| Parameter | Type | Description |
|---|---|---|
schemaObj | SchemaObj | The schema object to convert |
key | PropertyKey | The 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
| Parameter | Type | Description |
|---|---|---|
schema | TF.Schema<T> | A convict style schema |
parentKey | PropertyKey | Property 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
| Parameter | Type | Description |
|---|---|---|
key | PropertyKey | The name of the property that uses the schemaObj |
convictFormatValue | ConvictFormat | A 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
| Parameter | Type |
|---|---|
format | ConvictFormat | 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
| Parameter | Type |
|---|---|
format | ConvictFormat |
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
| Parameter | Type |
|---|---|
type | ZodType |
defaultVal | any |
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
| Parameter | Type |
|---|---|
schema | ZodType |
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
| Parameter | Type | Description |
|---|---|---|
config | any | A configuration to validate |
Returns
T
A valid object of type T