RecordType
Public Class
Table of Contents
A record type is a type that can be stored in a record store. It is created with createRecordType
.
Signature
class RecordType<
R extends UnknownRecord,
RequiredProperties extends keyof Omit<R, 'id' | 'typeName'>
> {}
References
Constructor
Public Constructor
Constructs a new instance of the RecordType
class
Parameters
Name | Description |
---|---|
|
|
|
|
References
Exclude, OmitMeta, Migrations, StoreValidator, RecordScope
Properties
createDefaultProperties
Public Readonly Property
Signature
readonly createDefaultProperties: () => Exclude<
OmitMeta<R>,
RequiredProperties
>
References
isInstance
Public Property
Check whether a record is an instance of this record type.
Example
const result = recordType.isInstance(someRecord)
Parameters
Name | Description |
---|---|
| The record to check. |
Signature
isInstance: (record?: UnknownRecord) => record is R
References
migrations
Public Readonly Property
Signature
readonly migrations: Migrations
References
scope
Public Readonly Property
Signature
readonly scope: RecordScope
References
typeName
Public Readonly Property
The unique type associated with this record.
Signature
readonly typeName: R['typeName']
validator
Public Readonly Property
Signature
readonly validator:
| {
validate: (r: unknown) => R
}
| StoreValidator<R>
References
Methods
clone()
Public Method
Clone a record of this type.
Parameters
Name | Description |
---|---|
|
The record to clone. |
Returns
R
The cloned record.
create()
Public Method
Create a new record of this type.
Parameters
Name | Description |
---|---|
|
The properties of the record. |
Returns
R
The new record.
References
createCustomId()
Public Method
Create a new ID for this record type based on the given ID.
Example
const id = recordType.createCustomId('myId')
Parameters
Name | Description |
---|---|
|
The ID to base the new ID on. |
Returns
IdOf<R>
The new ID.
References
createId()
Public Method
Create a new ID for this record type.
Example
const id = recordType.createId()
Parameters
Name | Description |
---|---|
(optional) |
|
Returns
IdOf<R>
The new ID.
References
isId()
Public Method
Check whether an id is an id of this type.
Example
const result = recordType.isIn('someId')
Parameters
Name | Description |
---|---|
(optional) |
The id to check. |
Returns
id is IdOf<R>
Whether the id is an id of this type.
References
parseId()
Public Method
Takes an id like user:123
and returns the part after the colon 123
Parameters
Name | Description |
---|---|
|
The id |
Returns
string
References
validate()
Public Method
Check that the passed in record passes the validations for this type. Returns its input correctly typed if it does, but throws an error otherwise.
Parameters
Name | Description |
---|---|
|
|
Returns
R
withDefaultProperties()
Public Method
Create a new RecordType that has the same type name as this RecordType and includes the given default properties.
Example
const authorType = createRecordType('author', () => ({ living: true }))
const deadAuthorType = authorType.withDefaultProperties({ living: false })
Parameters
Name | Description |
---|---|
|
|
Returns
RecordType<R, Exclude<RequiredProperties, keyof DefaultProps>>
The new RecordType.
References
Omit, Partial, RecordType, Exclude