static/jsvm/interfaces/core.MFA.html
MFA defines a Record proxy for working with the mfas collection.
baseFilesPathclonecollectioncollectionRefcreatedcustomDatadbExportemailemailVisibilityexpandexpandedAllexpandedOnefieldsDatafindFileFieldByFilefreshgetgetBoolgetDateTimegetFloatgetGeoPointgetIntgetRawgetStringgetStringSlicegetUnsavedFilesgetUploadedFileshasExpiredhidehookTagsignoreEmailVisibilityignoreUnchangedFieldsisNewisSuperuserlastSavedPKloadmarkAsNewmarkAsNotNewmarshalJSONmergeExpandmethodnewAuthTokennewEmailChangeTokennewFileTokennewPasswordResetTokennewStaticAuthTokennewVerificationTokenoriginalpkpostScanpreValidateproxyRecordpublicExportrecordRefrefreshTokenKeyreplaceModifierssetsetCollectionRefsetEmailsetEmailVisibilitysetExpandsetIfFieldExistssetMethodsetPasswordsetProxyRecordsetRandomPasswordsetRawsetRecordRefsetTokenKeysetVerifiedtableNametokenKeyunhideunmarshalJSONunmarshalJSONFieldupdatedvalidatePasswordverifiedwithCustomData
BaseFilesPath returns the storage dir path used by the record.
Clone returns a shallow copy of the current record model with all of its collection and unknown fields data, expand and flags copied.
use [Record.Fresh()] instead if you want a copy with only the latest collection fields data and everything else reset to the defaults.
Collection returns the Collection model associated with the current Record model.
NB! The returned collection is only for read purposes and it shouldn't be modified because it could have unintended side-effects on other Record models from the same collection.
CollectionRef returns the "collectionRef" field value.
Created returns the "created" record field value.
CustomData returns a shallow copy ONLY of the custom record fields data, aka. fields that are neither defined by the collection, nor special system ones.
Note that custom fields prefixed with "@pbInternal" are always skipped.
DBExport implements the [DBExporter] interface and returns a key-value map with the data to be persisted when saving the Record in the database.
Email returns the "email" record field value (usually available with Auth collections).
Verified returns the "emailVisibility" record field value (usually available with Auth collections).
Expand returns a shallow copy of the current Record model expand data (if any).
ExpandedAll retrieves a slice of relation Records from the already loaded expand data of the current model.
If the requested expand relation is single, this method normalizes the return result and will wrap the single model as a slice.
Returns nil slice if there is no such expand relation loaded.
ExpandedOne retrieves a single relation Record from the already loaded expand data of the current model.
If the requested expand relation is multiple, this method returns only first available Record from the expanded relation.
Returns nil if there is no such expand relation loaded.
FieldsData returns a shallow copy ONLY of the collection's fields record's data.
FindFileFieldByFile returns the first file type field for which any of the record's data contains the provided filename.
Fresh returns a shallow copy of the current record model populated with its LATEST data state and everything else reset to the defaults (aka. no expand, no unknown fields and with default visibility flags).
Get returns a normalized single record model data value for "key".
GetBool returns the data value for "key" as a bool.
GetDateTime returns the data value for "key" as a DateTime instance.
GetFloat returns the data value for "key" as a float64.
GetGeoPoint returns the data value for "key" as a GeoPoint instance.
GetInt returns the data value for "key" as an int.
GetString returns the data value for "key" as a string.
GetStringSlice returns the data value for "key" as a slice of non-zero unique strings.
GetUnsavedFiles returns the uploaded files for the provided "file" field key, (aka. the current [*filesystem.File] values) so that you can apply further validations or modifications (including changing the file name or content before persisting).
Example:
files := record.GetUnsavedFiles("documents") for _, f := range files { f.Name = "doc_" + f.Name // add a prefix to each file name } app.Save(record) // the files are pointers so the applied changes will transparently reflect on the record valueCopy
Deprecated: replaced with GetUnsavedFiles.
HasExpired checks if the mfa is expired, aka. whether it has been more than maxElapsed time since its creation.
Hide hides the specified fields from the public safe serialization of the record.
Rest ...fieldNames: string[]HookTags returns the hook tags associated with the current record.
IgnoreEmailVisibility toggles the flag to ignore the auth record email visibility check.
IgnoreUnchangedFields toggles the flag to ignore the unchanged fields from the DB export for the UPDATE SQL query.
This could be used if you want to save only the record fields that you've changed without overwrite other untouched fields in case of concurrent update.
Note that the fields change comparison is based on the current fields against m.Original() (aka. if you have performed save on the same Record instance multiple times you may have to refetch it, so that m.Original() could reflect the last saved change).
IsNew indicates what type of db query (insert or update) should be used with the model instance.
IsSuperuser returns whether the current record is a superuser, aka. whether the record is from the _superusers collection.
LastSavedPK returns the last saved primary key of the model.
Its value is updated to the latest PK value after MarkAsNotNew() or PostScan() calls.
Load bulk loads the provided data into the current Record model.
MarkAsNew clears the pk field and marks the current model as "new" (aka. forces m.IsNew() to be true).
MarkAsNew set the pk field to the Id value and marks the current model as NOT "new" (aka. forces m.IsNew() to be false).
MarshalJSON implements the [json.Marshaler] interface.
Only the data exported by PublicExport() will be serialized.
MergeExpand merges recursively the provided expand data into the current model's expand (if any).
Note that if an expanded prop with the same key is a slice (old or new expand) then both old and new records will be merged into a new slice (aka. a :merge: [b,c] => [a,b,c]). Otherwise the "old" expanded record will be replace with the "new" one (aka. a :merge: aNew => aNew).
Method returns the "method" record field value.
NewAuthToken generates and returns a new record authentication token.
NewEmailChangeToken generates and returns a new auth record change email request token.
NewFileToken generates and returns a new record private file access token.
NewPasswordResetToken generates and returns a new auth record password reset request token.
NewStaticAuthToken generates and returns a new static record authentication token.
Static auth tokens are similar to the regular auth tokens, but are non-refreshable and support custom duration.
Zero or negative duration will fallback to the duration from the auth collection settings.
NewVerificationToken generates and returns a new record verification token.
Original returns a shallow copy of the current record model populated with its ORIGINAL db data state (aka. right after PostScan()) and everything else reset to the defaults.
If record was created using NewRecord() the original will be always a blank record (until PostScan() is invoked).
PostScan implements the [dbx.PostScanner] interface.
It essentially refreshes/updates the current Record original state as if the model was fetched from the databases for the first time.
Or in other words, it means that m.Original().FieldsData() will have the same values as m.Record().FieldsData().
PreValidate implements the [PreValidator] interface and checks whether the proxy is properly loaded.
ProxyRecord returns the proxied Record model.
PublicExport exports only the record fields that are safe to be public.
To export unknown data fields you need to set record.WithCustomData(true).
For auth records, to force the export of the email field you need to set record.IgnoreEmailVisibility(true).
RecordRef returns the "recordRef" record field value.
RefreshTokenKey generates and sets a new random auth record "tokenKey".
ReplaceModifiers returns a new map with applied modifier values based on the current record and the specified data.
The resolved modifier keys will be removed.
Multiple modifiers will be applied one after another, while reusing the previous base key value result (ex. 1; -5; +2 => -2).
Note that because Go doesn't guaranteed the iteration order of maps, we would explicitly apply shorter keys first for a more consistent and reproducible behavior.
Example usage:
newData := record.ReplaceModifiers(data) // record: {"field": 10} // data: {"field+": 5} // result: {"field": 15}Copy
Set sets the provided key-value data pair into the current Record model.
If the record collection has field with name matching the provided "key", the value will be further normalized according to the field setter(s).
SetCollectionRef updates the "collectionRef" record field value.
SetEmail sets the "email" record field value (usually available with Auth collections).
SetEmailVisibility sets the "emailVisibility" record field value (usually available with Auth collections).
SetExpand replaces the current Record's expand with the provided expand arg data (shallow copied).
SetIfFieldExists sets the provided key-value data pair into the current Record model ONLY if key is existing Collection field name/modifier.
This method does nothing if key is not a known Collection field name/modifier.
On success returns the matched Field, otherwise - nil.
To set any key-value, including custom/unknown fields, use the [Record.Set] method.
SetMethod updates the "method" record field value.
SetPassword sets the "password" record field value (usually available with Auth collections).
SetProxyRecord loads the specified record model into the current proxy.
SetRandomPassword sets the "password" auth record field to a random autogenerated value.
The autogenerated password is ~30 characters and it is set directly as hash, aka. the field plain password value validators (length, pattern, etc.) are ignored (this is usually used as part of the auto created OTP or OAuth2 user flows).
Set sets the provided key-value data pair into the current Record model directly as it is WITHOUT NORMALIZATIONS.
See also [Record.Set].
SetRecordRef updates the "recordRef" record field value.
SetTokenKey sets the "tokenKey" record field value (usually available with Auth collections).
SetVerified sets the "verified" record field value (usually available with Auth collections).
TableName returns the table name associated with the current Record model.
TokenKey returns the "tokenKey" record field value (usually available with Auth collections).
Unhide forces to unhide the specified fields from the public safe serialization of the record (even when the collection field itself is marked as hidden).
Rest ...fieldNames: string[]UnmarshalJSON implements the [json.Unmarshaler] interface.
Retrieves the "key" json field value and unmarshals it into "result".
Example
result := struct { FirstName string `json:"first_name"` }{} err := m.UnmarshalJSONField("my_field_name", &result)Copy
Updated returns the "updated" record field value.
ValidatePassword validates a plain password against the "password" record field.
Returns false if the password is incorrect.
Verified returns the "verified" record field value (usually available with Auth collections).
WithCustomData toggles the export/serialization of custom data fields (false by default).
id: string
Id is the primary key of the model. It is usually autogenerated by the parent model implementation.
OSLightDark
Generated using TypeDoc