Type

Also known as "Domain".

The default built-in types are:

See Field.def for information on type-specific Field options.

When creating your own types, they will get automatically registered with Tyranid via the new Tyr.Type() constructor.

static

byName: { type name: Type }

This contains a dictionary of the supported Tyranid types.

instance

compare(field: Field, a: any, b: any): number

This compares two values of this type and returns a negative (a < b), zero (a == b), or positive (a > b) number suitable for sorting comparators.

compile(compiler: Compiler, path: string, field: Field): void

Any schema validation can be done inside this method. For example, ArrayTypes verify that the field has a valid "of" property.

create(field: Field): any

This creates a new value for the given type. Usually this will return undefined but if

there is a defaultValue specified for the field, then that value will be returned.

This can also be useful if a custom type needs to have a certain structure guaranteed to be present.

def

This defines the structure of a type and is the argument that is passed into the Type constructor when you want to define your own types.

In the table below, TType refers to the TypeScript type for this Type.

Object StructureTypeDefaultNotes
{
compare:(field: Field, a: TType, b: TType) => number Comparator to use for members of this type. Must be isomorphic.
compile:(compiler, field: Field) => void Callback called when parsing fields using your type. This should be used to validate any properties that your type adds to Fields.
fromClient:(field: Field, value: string) => TType Method used to when reading values from the client onto the server.
fromString:(s: string) => TType Comparator to use for members of this type. Must be isomorphic.
format:(field: Field, value: TType) => string Method used to convert values of this Type to a display string.
matches:(path: Path, where, document: Document) => boolean Returns whether this type matches the given where clause.
name:stringrequired The name of this type.
query:(path: Path, where, query: Mongo query) => void Applies any where clause set on a Field for this type.
typescript:string The name of the TypeScript type to use for this type (this defines TType).
validate:(field: Field, value: string) => void This method should throw a UserError if this field does not validate.
width:integer This provides the default width in pixels for fields of this type when displayed in a table.
Developer Documentation
note:stringnoneContains developer-facing documentation about this type (only visible in the Tyranid console).
}
fromString(str: string): any

This method will be used by Tyranid to coerce strings to this data type.

fromClient(field: Field, value: any): any

This method will be used by Tyranid to convert incoming data from the client into server objects. For example, MongoId types will convert client-side MongoID strings into server-side ObjectId objects.

fromClientQuery(field: Field, value: any): any

This method will be used by Tyranid to convert incoming query data from the client into server query objects. For example, MongoId types will convert client-side MongoID strings into server-side ObjectId objects.

format(field: Field, value: any): string

This returns a formatted version of this value for display.

matches(path: Path, where: any, doc: Document | object): boolean

This returns true if the given doc's property given by path matches the where.

name: string

Contains the name of this type.

query(path: Path, where: any, query: object): void

This updates the passed in MongoDB-style query with the given where.

sortValue(path: Path, value: any): any

This returns the sortValue to use in sorting comparisons.

toClient(field: Field, value: any): any

This method will be used by Tyranid to convert server data into JSON suitable for the client. For example, MongoId types will convert server-side ObjectIds into client-side MongoID strings.

validate(field: Field, value: any): UserError

This is used by Tyranid to validate fields of this type.

width?: number

This returns the default with for this fields of this type when displayed in a table.