Skip to main content

Class: MixedType

Mixed type supports any Object types, you can change the value to anything else, it can be represented in the following ways:

Options

  • required flag to define if the field is mandatory
  • validator that will be applied to the field a validation function, validation object or string with the name of the custom validator
  • default that will define the initial value of the field, this option allows a value or a function
  • immutable that will define this field as immutable. Ottoman prevents you from changing immutable fields if the schema as configure like strict

Example

const schema = new Schema({
inline: Schema.Types.Mixed,
types: { type: Schema.Types.Mixed, required: true },
obj: Object,
empty: {},
});

schema.fields.inline instanceof MixedType; // true
schema.fields.types instanceof MixedType; // true
schema.fields.obj instanceof MixedType; // true
schema.fields.empty instanceof MixedType; // true

const data = {
inline: { name: 'george' },
types: {
email: 'george@gmail.com',
},
obj: 'Hello',
empty: { hello: 'hello' },
};

const result = validate(data, schema);
console.log(result);

// Output!!!
// {
// "inline": {
// "name": "george"
// },
// "types": {
// "email": "george@gmail.com"
// },
// "obj": "Hello",
// "empty": {
// "hello": "hello"
// }
// }

Hierarchy

Constructors

constructor

new MixedType(name, options?)

Parameters

NameType
namestring
options?CoreTypeOptions

Overrides

CoreType.constructor

Defined in

schema/types/mixed-type.ts:57

Properties

name

name: string

Inherited from

CoreType.name

Defined in

schema/interfaces/schema.types.ts:51


options

Optional options: CoreTypeOptions

Inherited from

CoreType.options

Defined in

schema/types/core-type.ts:23


typeName

typeName: string

Inherited from

CoreType.typeName

Defined in

schema/interfaces/schema.types.ts:51


sName

Static sName: string = 'Mixed'

Overrides

CoreType.sName

Defined in

schema/types/mixed-type.ts:61

Accessors

default

get default(): unknown

Returns

unknown

Inherited from

CoreType.default

Defined in

schema/types/core-type.ts:39


required

get required(): boolean | RequiredOption | RequiredFunction

Returns

boolean | RequiredOption | RequiredFunction

Inherited from

CoreType.required

Defined in

schema/types/core-type.ts:31


validator

get validator(): undefined | string | ValidatorFunction | ValidatorOption

Returns

undefined | string | ValidatorFunction | ValidatorOption

Inherited from

CoreType.validator

Defined in

schema/types/core-type.ts:35

Methods

buildDefault

buildDefault(): unknown

Returns

unknown

Inherited from

CoreType.buildDefault

Defined in

schema/types/core-type.ts:43


cast

cast(value, strategy): unknown

Parameters

NameType
valueunknown
strategyany

Returns

unknown

Overrides

CoreType.cast

Defined in

schema/types/mixed-type.ts:63


checkRequired

checkRequired(): string | void

Returns

string | void

Inherited from

CoreType.checkRequired

Defined in

schema/types/core-type.ts:62


checkValidator

checkValidator(value): void

Parameters

NameType
valueunknown

Returns

void

Inherited from

CoreType.checkValidator

Defined in

schema/types/core-type.ts:71


isEmpty

isEmpty(value): boolean

Parameters

NameType
valueunknown

Returns

boolean

Inherited from

CoreType.isEmpty

Defined in

schema/types/core-type.ts:75


isStrictStrategy

isStrictStrategy(strategy): boolean

Parameters

NameType
strategyVALIDATION_STRATEGY

Returns

boolean

Inherited from

CoreType.isStrictStrategy

Defined in

schema/types/core-type.ts:79


validate

validate(value, strict?): unknown

Parameters

NameTypeDefault value
valueunknownundefined
strictbooleantrue

Returns

unknown

Inherited from

CoreType.validate

Defined in

schema/types/core-type.ts:52