Back to Pocketbase

Interface BaseRecordProxy

static/jsvm/interfaces/core.BaseRecordProxy.html

latest24.8 KB
Original Source

Interface BaseRecordProxy

BaseRecordProxy implements the [RecordProxy] interface and it is intended to be used as embed to custom user provided Record proxy structs.

Hierarchy

Index

Methods

baseFilesPathclonecollectioncustomDatadbExportemailemailVisibilityexpandexpandedAllexpandedOnefieldsDatafindFileFieldByFilefreshgetgetBoolgetDateTimegetFloatgetGeoPointgetIntgetRawgetStringgetStringSlicegetUnsavedFilesgetUploadedFileshidehookTagsignoreEmailVisibilityignoreUnchangedFieldsisNewisSuperuserlastSavedPKloadmarkAsNewmarkAsNotNewmarshalJSONmergeExpandnewAuthTokennewEmailChangeTokennewFileTokennewPasswordResetTokennewStaticAuthTokennewVerificationTokenoriginalpkpostScanproxyRecordpublicExportrefreshTokenKeyreplaceModifierssetsetEmailsetEmailVisibilitysetExpandsetIfFieldExistssetPasswordsetProxyRecordsetRandomPasswordsetRawsetTokenKeysetVerifiedtableNametokenKeyunhideunmarshalJSONunmarshalJSONFieldvalidatePasswordverifiedwithCustomData

Properties

id

Methods

baseFilesPath

  • baseFilesPath(): string

BaseFilesPath returns the storage dir path used by the record.

Returns string

clone

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.

Returns core.Record

collection

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.

Returns core.Collection

customData

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.

Returns _TygojaDict

dbExport

DBExport implements the [DBExporter] interface and returns a key-value map with the data to be persisted when saving the Record in the database.

Parameters

app: App

Returns _TygojaDict

email

  • email(): string

Email returns the "email" record field value (usually available with Auth collections).

Returns string

emailVisibility

  • emailVisibility(): boolean

Verified returns the "emailVisibility" record field value (usually available with Auth collections).

Returns boolean

expand

Expand returns a shallow copy of the current Record model expand data (if any).

Returns _TygojaDict

expandedAll

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.

Parameters

relField: string

Returns core.Record[]

expandedOne

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.

Parameters

relField: string

Returns core.Record

fieldsData

FieldsData returns a shallow copy ONLY of the collection's fields record's data.

Returns _TygojaDict

findFileFieldByFile

FindFileFieldByFile returns the first file type field for which any of the record's data contains the provided filename.

Parameters

filename: string

Returns core.FileField

fresh

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).

Returns core.Record

get

  • get(key): any

Get returns a normalized single record model data value for "key".

Parameters

key: string

Returns any

getBool

  • getBool(key): boolean

GetBool returns the data value for "key" as a bool.

Parameters

key: string

Returns boolean

getDateTime

GetDateTime returns the data value for "key" as a DateTime instance.

Parameters

key: string

Returns types.DateTime

getFloat

  • getFloat(key): number

GetFloat returns the data value for "key" as a float64.

Parameters

key: string

Returns number

getGeoPoint

GetGeoPoint returns the data value for "key" as a GeoPoint instance.

Parameters

key: string

Returns GeoPoint

getInt

  • getInt(key): number

GetInt returns the data value for "key" as an int.

Parameters

key: string

Returns number

getRaw

  • getRaw(key): any

Parameters

key: string

Returns any

getString

  • getString(key): string

GetString returns the data value for "key" as a string.

Parameters

key: string

Returns string

getStringSlice

  • getStringSlice(key): string[]

GetStringSlice returns the data value for "key" as a slice of non-zero unique strings.

Parameters

key: string

Returns string[]

getUnsavedFiles

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

Parameters

key: string

Returns filesystem.File[]

getUploadedFiles

Deprecated: replaced with GetUnsavedFiles.

Parameters

key: string

Returns filesystem.File[]

hide

Hide hides the specified fields from the public safe serialization of the record.

Parameters

Rest ...fieldNames: string[]

Returns core.Record

hookTags

  • hookTags(): string[]

HookTags returns the hook tags associated with the current record.

Returns string[]

ignoreEmailVisibility

IgnoreEmailVisibility toggles the flag to ignore the auth record email visibility check.

Parameters

state: boolean

Returns core.Record

ignoreUnchangedFields

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).

Parameters

state: boolean

Returns core.Record

isNew

  • isNew(): boolean

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

Returns boolean

isSuperuser

  • isSuperuser(): boolean

IsSuperuser returns whether the current record is a superuser, aka. whether the record is from the _superusers collection.

Returns boolean

lastSavedPK

  • lastSavedPK(): any

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

load

  • load(data): void

Load bulk loads the provided data into the current Record model.

Parameters

data: _TygojaDict

Returns void

markAsNew

  • markAsNew(): void

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

Returns void

markAsNotNew

  • markAsNotNew(): 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

  • marshalJSON(): string | number[]

MarshalJSON implements the [json.Marshaler] interface.

Only the data exported by PublicExport() will be serialized.

Returns string | number[]

mergeExpand

  • mergeExpand(expand): void

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).

Parameters

expand: _TygojaDict

Returns void

newAuthToken

  • newAuthToken(): string

NewAuthToken generates and returns a new record authentication token.

Returns string

newEmailChangeToken

  • newEmailChangeToken(newEmail): string

NewEmailChangeToken generates and returns a new auth record change email request token.

Parameters

newEmail: string

Returns string

newFileToken

  • newFileToken(): string

NewFileToken generates and returns a new record private file access token.

Returns string

newPasswordResetToken

  • newPasswordResetToken(): string

NewPasswordResetToken generates and returns a new auth record password reset request token.

Returns string

newStaticAuthToken

  • newStaticAuthToken(duration): string

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.

Parameters

duration: Duration

Returns string

newVerificationToken

  • newVerificationToken(): string

NewVerificationToken generates and returns a new record verification token.

Returns string

original

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).

Returns core.Record

pk

  • pk(): any

Returns any

postScan

  • postScan(): void

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().

Returns void

proxyRecord

ProxyRecord returns the proxied Record model.

Returns core.Record

publicExport

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).

Returns _TygojaDict

refreshTokenKey

  • refreshTokenKey(): void

RefreshTokenKey generates and sets a new random auth record "tokenKey".

Returns void

replaceModifiers

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

Parameters

data: _TygojaDict

Returns _TygojaDict

set

  • set(key, value): void

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).

Parameters

key: string
value: any

Returns void

setEmail

  • setEmail(email): void

SetEmail sets the "email" record field value (usually available with Auth collections).

Parameters

email: string

Returns void

setEmailVisibility

  • setEmailVisibility(visible): void

SetEmailVisibility sets the "emailVisibility" record field value (usually available with Auth collections).

Parameters

visible: boolean

Returns void

setExpand

  • setExpand(expand): void

SetExpand replaces the current Record's expand with the provided expand arg data (shallow copied).

Parameters

expand: _TygojaDict

Returns void

setIfFieldExists

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.

Parameters

key: string
value: any

Returns core.Field

setPassword

  • setPassword(password): void

SetPassword sets the "password" record field value (usually available with Auth collections).

Parameters

password: string

Returns void

setProxyRecord

  • setProxyRecord(record): void

SetProxyRecord loads the specified record model into the current proxy.

Parameters

record: core.Record

Returns void

setRandomPassword

  • setRandomPassword(): string

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).

Returns string

setRaw

  • setRaw(key, value): void

Set sets the provided key-value data pair into the current Record model directly as it is WITHOUT NORMALIZATIONS.

See also [Record.Set].

Parameters

key: string
value: any

Returns void

setTokenKey

  • setTokenKey(key): void

SetTokenKey sets the "tokenKey" record field value (usually available with Auth collections).

Parameters

key: string

Returns void

setVerified

  • setVerified(verified): void

SetVerified sets the "verified" record field value (usually available with Auth collections).

Parameters

verified: boolean

Returns void

tableName

  • tableName(): string

TableName returns the table name associated with the current Record model.

Returns string

tokenKey

  • tokenKey(): string

TokenKey returns the "tokenKey" record field value (usually available with Auth collections).

Returns string

unhide

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).

Parameters

Rest ...fieldNames: string[]

Returns core.Record

unmarshalJSON

  • unmarshalJSON(data): void

UnmarshalJSON implements the [json.Unmarshaler] interface.

Parameters

data: string | number[]

Returns void

unmarshalJSONField

  • unmarshalJSONField(key, result): void

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

Parameters

key: string
result: any

Returns void

validatePassword

  • validatePassword(password): boolean

ValidatePassword validates a plain password against the "password" record field.

Returns false if the password is incorrect.

Parameters

password: string

Returns boolean

verified

  • verified(): boolean

Verified returns the "verified" record field value (usually available with Auth collections).

Returns boolean

withCustomData

WithCustomData toggles the export/serialization of custom data fields (false by default).

Parameters

state: boolean

Returns core.Record

Properties

id

id: string

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

Settings

Member Visibility

  • Inherited

Theme

OSLightDark

On This Page

Generated using TypeDoc