Class: MixedType
Defined in: schema/types/mixed-type.ts:56
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"
// }
// }
Extends
Constructors
Constructor
new MixedType(
name
,options?
):MixedType
Defined in: schema/types/mixed-type.ts:57
Parameters
name
string
options?
CoreTypeOptions
Returns
MixedType
Overrides
Properties
name
name:
string
Defined in: schema/interfaces/schema.types.ts:51
Inherited from
options?
optional
options:CoreTypeOptions
Defined in: schema/types/core-type.ts:23
Inherited from
typeName
typeName:
string
Defined in: schema/interfaces/schema.types.ts:51
Inherited from
sName
static
sName:string
='Mixed'
Defined in: schema/types/mixed-type.ts:61
Overrides
Accessors
default
Get Signature
get default():
unknown
Defined in: schema/types/core-type.ts:39
Returns
unknown
Inherited from
required
Get Signature
get required():
boolean
|RequiredOption
|RequiredFunction
Defined in: schema/types/core-type.ts:31
Returns
boolean
| RequiredOption
| RequiredFunction
Inherited from
validator
Get Signature
get validator():
undefined
|string
|ValidatorFunction
|ValidatorOption
Defined in: schema/types/core-type.ts:35
Returns
undefined
| string
| ValidatorFunction
| ValidatorOption
Inherited from
Methods
buildDefault()
buildDefault():
unknown
Defined in: schema/types/core-type.ts:43
Returns
unknown
Inherited from
cast()
cast(
value
,strategy
):unknown
Defined in: schema/types/mixed-type.ts:63
Parameters
value
unknown
strategy
any
Returns
unknown
Overrides
checkRequired()
checkRequired():
string
|void
Defined in: schema/types/core-type.ts:62
Returns
string
| void
Inherited from
checkValidator()
checkValidator(
value
):void
Defined in: schema/types/core-type.ts:71
Parameters
value
unknown
Returns
void
Inherited from
isEmpty()
isEmpty(
value
):boolean
Defined in: schema/types/core-type.ts:75
Parameters
value
unknown
Returns
boolean
Inherited from
isStrictStrategy()
isStrictStrategy(
strategy
):boolean
Defined in: schema/types/core-type.ts:79
Parameters
strategy
Returns
boolean
Inherited from
validate()
validate(
value
,strict
):unknown
Defined in: schema/types/core-type.ts:52
Parameters
value
unknown
strict
boolean
= true
Returns
unknown