Collection model class.

const collection = new Collection({
type: "base",
name: "article",
listRule: "@request.auth.id != '' || status = 'public'",
viewRule: "@request.auth.id != '' || status = 'public'",
deleteRule: "@request.auth.id != ''",
fields: [
{
name: "title",
type: "text",
required: true,
min: 6,
max: 100,
},
{
name: "description",
type: "text",
},
]
})

Hierarchy

Implements

Constructors

Methods

  • AddIndex adds a new index into the current collection.

    If the collection has an existing index matching the new name it will be replaced with the new one.

    Parameters

    • name: string
    • unique: boolean
    • columnsExpr: string
    • optWhereExpr: string

    Returns void

  • GetIndex returns s single Collection index expression by its name.

    Parameters

    • name: string

    Returns string

  • IntegrityChecks toggles the current collection integrity checks (ex. checking references on delete).

    Parameters

    • enable: boolean

    Returns void

  • IsNew indicates what type of db query (insert or update) should be used with the model instance.

    Returns boolean

  • LastSavedPK returns the last saved primary key of the model.

    Its value is updated to the latest PK value after MarkAsNotNew() or PostScan() calls.

    Returns any

  • MarkAsNew clears the pk field and marks the current model as "new" (aka. forces m.IsNew() to be true).

    Returns void

  • MarkAsNew set the pk field to the Id value and marks the current model as NOT "new" (aka. forces m.IsNew() to be false).

    Returns void

  • MarshalJSON implements the [json.Marshaler] interface.

    Note that non-type related fields are ignored from the serialization (ex. for "view" colections the "auth" fields are skipped).

    Returns string | number[]

  • PostScan implements the [dbx.PostScanner] interface to auto unmarshal the raw serialized options into the concrete type specific fields.

    Returns void

  • RemoveIndex removes a single index with the specified name from the current collection.

    Parameters

    • name: string

    Returns void

  • String returns a string representation of the current collection.

    Returns string

  • UnmarshalJSON implements the [json.Unmarshaler] interface.

    For new/"blank" Collection models it replaces the model with a factory instance and then unmarshal the provided data one on top of it.

    Parameters

    • b: string | number[]

    Returns void

Properties

authAlert: AuthAlertConfig

AuthAlert defines options related to the auth alerts on new device login.

authRule?: string

AuthRule could be used to specify additional record constraints applied after record authentication and right before returning the auth token response to the client.

For example, to allow only verified users you could set it to "verified = true".

Set it to empty string to allow any Auth collection record to authenticate.

Set it to nil to disallow authentication altogether for the collection (that includes password, OAuth2, etc.).

authToken: TokenConfig
confirmEmailChangeTemplate: EmailTemplate
createRule?: string
created: types.DateTime
deleteRule?: string
emailChangeToken: TokenConfig
fileToken: TokenConfig
id: string

Id is the primary key of the model. It is usually autogenerated by the parent model implementation.

indexes: JSONArray<string>
listRule?: string
manageRule?: string

ManageRule gives admin-like permissions to allow fully managing the auth record(s), eg. changing the password without requiring to enter the old one, directly updating the verified state and email, etc.

This rule is executed in addition to the Create and Update API rules.

MFA defines options related to the Multi-factor authentication (MFA).

name: string
oauth2: OAuth2Config

OAuth2 specifies whether OAuth2 auth is enabled for the collection and which OAuth2 providers are allowed.

OTP defines options related to the One-time password authentication (OTP).

passwordAuth: PasswordAuthConfig

PasswordAuth defines options related to the collection password authentication.

passwordResetToken: TokenConfig
rawOptions: JSONRaw

RawOptions represents the raw serialized collection option loaded from the DB. NB! This field shouldn't be modified manually. It is automatically updated with the collection type specific option before save.

resetPasswordTemplate: EmailTemplate
system: boolean

System prevents the collection rename, deletion and rules change. It is used primarily for internal purposes for collections like "_superusers", "_externalAuths", etc.

type: "base" | "view" | "auth"
updateRule?: string
updated: types.DateTime
verificationTemplate: EmailTemplate
verificationToken: TokenConfig
viewQuery: string
viewRule?: string

Generated using TypeDoc