# Class: EmbedType
EmbedType
will allow declaration of path as another schema, set type to the sub-schema's instance.
# 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 userSchema = new Schema({
name: String,
email: Schema.Types.String,
createAt: Date,
});
const schema = new Schema({
...
user: userSchema
});
2
3
4
5
6
7
8
9
10
You can also use a JavaScript plain Object as value for an EmbedType
.
Therefore the below example will behave the same as the example above.
const schema = new Schema({
...
user: {
name: String,
email: String,
createAt: Date,
}
});
2
3
4
5
6
7
8
tip
EmbedType
will allow you to easily reuse existing schemas into new ones using composition.
# Hierarchy
↳ CoreType
↳ EmbedType
# Constructors
# constructor
+ new EmbedType(name
: string, schema
: Schema, options?
: CoreTypeOptions): EmbedType
Overrides CoreType.constructor
Parameters:
Name | Type |
---|---|
name | string |
schema | Schema |
options? | CoreTypeOptions |
Returns: EmbedType
# Properties
# name
• name: string
Inherited from IOttomanType.name
# Optional
options
• options? : CoreTypeOptions
Inherited from CoreType.options
# schema
• schema: Schema
# typeName
• typeName: string
Inherited from IOttomanType.typeName
# Static
sName
▪ sName: string = "Embed"
# Accessors
# default
• get default(): unknown
Inherited from CoreType.default
Returns: unknown
# required
• get required(): boolean | RequiredOption | RequiredFunction
Inherited from CoreType.required
Returns: boolean | RequiredOption | RequiredFunction
# validator
• get validator(): ValidatorOption | ValidatorFunction | string | undefined
Inherited from CoreType.validator
Returns: ValidatorOption | ValidatorFunction | string | undefined
# Methods
# buildDefault
▸ buildDefault(): unknown
Inherited from CoreType.buildDefault
Returns: unknown
# cast
▸ cast(value
: unknown, strategy
: CAST_STRATEGY): unknown
Overrides IOttomanType.cast
Parameters:
Name | Type | Default |
---|---|---|
value | unknown | - |
strategy | CAST_STRATEGY | CAST_STRATEGY.DEFAULT_OR_DROP |
Returns: unknown
# checkRequired
▸ checkRequired(): string | void
Inherited from CoreType.checkRequired
Returns: string | void
# checkValidator
▸ checkValidator(value
: unknown): void
Inherited from CoreType.checkValidator
Parameters:
Name | Type |
---|---|
value | unknown |
Returns: void
# isEmpty
▸ isEmpty(value
: unknown): boolean
Inherited from CoreType.isEmpty
Parameters:
Name | Type |
---|---|
value | unknown |
Returns: boolean
# isStrictStrategy
▸ isStrictStrategy(strategy
: VALIDATION_STRATEGY): boolean
Inherited from CoreType.isStrictStrategy
Parameters:
Name | Type |
---|---|
strategy | VALIDATION_STRATEGY |
Returns: boolean
# validate
▸ validate(value
: unknown, strategy
: any): any
Parameters:
Name | Type |
---|---|
value | unknown |
strategy | any |
Returns: any