Options
All
  • Public
  • Public/Protected
  • All
Menu

Class OAuth2TokenModel

Hierarchy

Implements

Index

Constructors

constructor

Properties

awareOfContainerLifecycle

awareOfContainerLifecycle: true = true

Protected Readonly bus

bus: Bus<Event>

clientId

clientId: string

expires

expires: Date

issued

issued: Date

Protected Readonly logging

logging: Logging

Protected oauth2TokenId

oauth2TokenId: number

Protected Optional originalSourceRow

originalSourceRow: QueryRow

The original row fetched from the database.

relationCache

relationCache: Collection<{ accessor: string | symbol; relation: Relation<OAuth2TokenModel, any, any> }> = ...

Cache of relation instances by property accessor. This is used by the @Relation() decorator to cache Relation instances.

Optional scope

scope: string

Protected scopes

scopes: Collection<{ accessor: string | Instantiable<Scope>; scope: ScopeClosure }> = ...

Protected subscribers

subscribers: Collection<BusSubscriber<ModelEvent<OAuth2TokenModel>>> = ...

Local listeners subscribed to events on this bus.

Protected subscriptions

subscriptions: Collection<BusInternalSubscription> = ...

Optional userId

userId: string

Readonly uuid

uuid: string = ...

Protected with

with: keyof OAuth2TokenModel[] = []

Relations that should be eager-loaded by default.

Static Protected Readonly CREATED_AT

CREATED_AT: null | string = 'created_at'

Optionally, the timestamp field set on creation.

Static Protected Readonly UPDATED_AT

UPDATED_AT: null | string = 'updated_at'

Optionally, the timestamp field set op update.

Static Protected appends

appends: string[] = []

Array of additional fields on the class that should be included in the object serializations.

Static Protected connection

connection: string = 'default'

The name of the connection this model should run through.

Static key

key: string = 'oauth2_token_id'

The name of the column that uniquely identifies this model.

Static Protected masks

masks: string[] = []

Array of fields on the class that should be excluded from the object serializations.

Static Protected populateKeyOnInsert

populateKeyOnInsert: boolean = false

If false (default), the primary key will be excluded from INSERTs.

Static table

table: string = 'oauth2_tokens'

The name of the table this model is stored in.

Static Protected timestamps

timestamps: boolean = true

If true, the CREATED_AT and UPDATED_AT columns will be automatically set.

Accessors

Private appClassApplication

id

  • get id(): string

Protected isDirtyCheck

  • get isDirtyCheck(): (field: ModelField) => boolean
  • Get a wrapped function that compares whether the given model field on the current instance differs from the originally fetched value.

    Used to filter for dirty fields.

    Returns (field: ModelField) => boolean

Methods

all

Protected app

assume

  • Similar to assumeFromSource, but instead of mapping database fields to model properties, this function assumes the object contains a mapping of model properties to the values of those properties.

    Only properties with @Field() annotations will be set.

    Parameters

    • object: {}
      • [key: string]: any

    Returns Promise<OAuth2TokenModel>

assumeFromSource

  • Given a row from the database, set the properties on this model that correspond to fields on that database.

    The row maps database fields to values, and the values are set for the properties that they correspond to based on the model's @Field() annotations.

    Parameters

    Returns Promise<OAuth2TokenModel>

belongsToMany

  • Create the inverse of a one-to-many relation. Should be called from a method on the model:

    example
    class MyModel extends Model<MyModel> {
        @Related()
        public otherModels() {
            return this.hasMany(MyOtherModel)
        }
    }
    
    class MyOtherModel extends Model<MyOtherModel> {
        @Related()
        public myModels() {
            return this.belongsToMany(MyModel, 'otherModels')
        }
    }
    

    Type parameters

    Parameters

    Returns HasMany<OAuth2TokenModel, T2>

belongsToOne

  • Create the inverse of a one-to-one relation. Should be called from a method on the model:

    example
    class MyModel extends Model<MyModel> {
        @Related()
        public otherModel() {
            return this.hasOne(MyOtherModel)
        }
    }
    
    class MyOtherModel extends Model<MyOtherModel> {
        @Related()
        public myModel() {
            return this.belongsToOne(MyModel, 'otherModel')
        }
    }
    

    Type parameters

    Parameters

    Returns HasOne<OAuth2TokenModel, T2>

boot

  • boot(values?: {}): void
  • Initialize the model's properties from the given values and do any other initial setup.

    values can optionally be an object mapping model properties to the values of those properties. Only properties with @Field() annotations will be set.

    Parameters

    • Optional values: {}
      • [key: string]: unknown

    Returns void

Protected callSubscribers

Protected container

count

  • count(): Promise<number>

delete

  • delete(): Promise<void>

dirtyToQueryRow

  • Get a query row mapping database columns to values for properties on this model that (1) have @Field() annotations and (2) have been modified since the record was fetched from the database or created.

    Returns QueryRow

down

  • down(): Promise<void>

exists

  • exists(): boolean

fresh

  • Fetch a fresh instance of this record from the database.

    This returns a NEW instance of the SAME record by matching on the primary key. It does NOT change the current instance of the record.

    Returns Promise<undefined | Model<OAuth2TokenModel>>

getBoundMethod

  • getBoundMethod(methodName: string): (...args: any[]) => any
  • Get the method with the given name from this class, bound to this class.

    Parameters

    • methodName: string

    Returns (...args: any[]) => any

    function

      • (...args: any[]): any
      • Parameters

        • Rest ...args: any[]

        Returns any

getDirtyFields

  • getDirtyFields(): string[]

Protected getLoadedDatabaseFields

  • getLoadedDatabaseFields(): string[]

getOriginalValues

  • getOriginalValues(): undefined | QueryRow

Protected getRelation

hasMany

  • hasMany<T2>(related: Instantiable<T2>, foreignKeyOverride?: "delete" | "relationCache" | "boot" | "assumeFromSource" | "assume" | "key" | "exists" | "timestamps" | "query" | "all" | "count" | "qualify" | "qualifyKey" | "keyName" | "toQueryRow" | "dirtyToQueryRow" | "getOriginalValues" | "only" | "isDirty" | "isClean" | "wasChanged" | "getDirtyFields" | "touch" | "save" | "toObject" | "toJSON" | "fresh" | "refresh" | "populate" | "is" | "isNot" | "hasOne" | "hasMany" | "belongsToOne" | "belongsToMany" | "getRelation" | "awareOfContainerLifecycle" | "uuid" | "push" | "pipe" | "subscribe" | "up" | "isConnected" | "down" | "onContainerRelease" | "getBoundMethod" | "userId" | "id" | "clientId" | "issued" | "expires" | "scope", localKeyOverride?: keyof T2 & string): HasMany<OAuth2TokenModel, T2>
  • Create a new one-to-one relation instance. Should be called from a method on the model:

    example
    class MyModel extends Model<MyModel> {
        @Related()
        public otherModels() {
            return this.hasMany(MyOtherModel)
        }
    }
    

    Type parameters

    Parameters

    • related: Instantiable<T2>
    • Optional foreignKeyOverride: "delete" | "relationCache" | "boot" | "assumeFromSource" | "assume" | "key" | "exists" | "timestamps" | "query" | "all" | "count" | "qualify" | "qualifyKey" | "keyName" | "toQueryRow" | "dirtyToQueryRow" | "getOriginalValues" | "only" | "isDirty" | "isClean" | "wasChanged" | "getDirtyFields" | "touch" | "save" | "toObject" | "toJSON" | "fresh" | "refresh" | "populate" | "is" | "isNot" | "hasOne" | "hasMany" | "belongsToOne" | "belongsToMany" | "getRelation" | "awareOfContainerLifecycle" | "uuid" | "push" | "pipe" | "subscribe" | "up" | "isConnected" | "down" | "onContainerRelease" | "getBoundMethod" | "userId" | "id" | "clientId" | "issued" | "expires" | "scope"
    • Optional localKeyOverride: keyof T2 & string

    Returns HasMany<OAuth2TokenModel, T2>

hasOne

  • hasOne<T2>(related: Instantiable<T2>, foreignKeyOverride?: "delete" | "relationCache" | "boot" | "assumeFromSource" | "assume" | "key" | "exists" | "timestamps" | "query" | "all" | "count" | "qualify" | "qualifyKey" | "keyName" | "toQueryRow" | "dirtyToQueryRow" | "getOriginalValues" | "only" | "isDirty" | "isClean" | "wasChanged" | "getDirtyFields" | "touch" | "save" | "toObject" | "toJSON" | "fresh" | "refresh" | "populate" | "is" | "isNot" | "hasOne" | "hasMany" | "belongsToOne" | "belongsToMany" | "getRelation" | "awareOfContainerLifecycle" | "uuid" | "push" | "pipe" | "subscribe" | "up" | "isConnected" | "down" | "onContainerRelease" | "getBoundMethod" | "userId" | "id" | "clientId" | "issued" | "expires" | "scope", localKeyOverride?: keyof T2 & string): HasOne<OAuth2TokenModel, T2>
  • Create a new one-to-one relation instance. Should be called from a method on the model:

    example
    class MyModel extends Model<MyModel> {
        @Related()
        public otherModel() {
            return this.hasOne(MyOtherModel)
        }
    }
    

    Type parameters

    Parameters

    • related: Instantiable<T2>
    • Optional foreignKeyOverride: "delete" | "relationCache" | "boot" | "assumeFromSource" | "assume" | "key" | "exists" | "timestamps" | "query" | "all" | "count" | "qualify" | "qualifyKey" | "keyName" | "toQueryRow" | "dirtyToQueryRow" | "getOriginalValues" | "only" | "isDirty" | "isClean" | "wasChanged" | "getDirtyFields" | "touch" | "save" | "toObject" | "toJSON" | "fresh" | "refresh" | "populate" | "is" | "isNot" | "hasOne" | "hasMany" | "belongsToOne" | "belongsToMany" | "getRelation" | "awareOfContainerLifecycle" | "uuid" | "push" | "pipe" | "subscribe" | "up" | "isConnected" | "down" | "onContainerRelease" | "getBoundMethod" | "userId" | "id" | "clientId" | "issued" | "expires" | "scope"
    • Optional localKeyOverride: keyof T2 & string

    Returns HasOne<OAuth2TokenModel, T2>

Protected hasScope

Protected initialize

  • initialize(): void

is

  • is(other: Model<any>): boolean
  • Returns true if the other model refers to the same database record as this instance.

    This is done by comparing the qualified primary keys.

    Parameters

    Returns boolean

isClean

  • isClean(): boolean
  • Returns true if none of the fields on this model have been modified since they were fetched from the database (and all exist in the database).

    Only fields with @Field() annotations are checked.

    Returns boolean

isConnected

  • isConnected(): boolean

isDirty

  • isDirty(): boolean
  • Returns true if any of the fields on this model have been modified since they were fetched from the database (or ones that were never saved to the database).

    Only fields with @Field() annotations are checked.

    Returns boolean

isNot

  • isNot(other: Model<any>): boolean

key

  • key(): string

keyName

  • keyName(): string

Protected make

  • make<T>(target: any, ...parameters: any[]): T
  • Call the make() method on the global container.

    Type parameters

    • T

    Parameters

    • target: any
    • Rest ...parameters: any[]

    Returns T

Protected namedScope

onContainerRelease

only

  • Return an object of only the given properties on this model.

    example

    Assume a is an instance of some model A with the given fields.

    const a = new A({ field1: 'field1 value', field2: 'field2 value', id: 123 })
    
    a.only('field1', 'id)  // => {field1: 'field1 value', id: 123}
    

    Parameters

    • Rest ...fields: string[]

    Returns QueryRow

pipe

populate

  • Populates an instance of the model with the same database fields that are set on this model, with the exclusion of the primary key.

    Useful for inserting copies of records.

    example

    Assume a record, a, is an instance of some model A with the given fields.

    const a = A.find(123)  // => A{id: 123, name: 'some_name', other_field: 'a value'}
    
    const b = a.populate(new A)  // => A{name: 'some_name', other_field: 'a value'}
    

    Parameters

    Returns Promise<OAuth2TokenModel>

push

qualify

  • qualify(column: string): string
  • Given the name of a column, return the qualified name of the column as it could appear in a query.

    example
    modelInstance.qualify('id')  // => 'model_table_name.id'
    

    Parameters

    • column: string

    Returns string

qualifyKey

  • qualifyKey(): string
  • Return the qualified name of the column corresponding to the model's primary key.

    example
    class A extends Model<A> {
        protected static table = 'table_a'
        protected static key = 'a_id'
    }
    
    const a = new A()
    a.qualifyKey()  // => 'table_a.a_id'
    

    Returns string

query

  • Get a new query builder that yields instances of this model, pre-configured with this model's QuerySource, connection, and fields.

    example
    await user.query()
     .where('name', 'LIKE', 'John Doe')
     .update({ username: 'jdoe' })
    

    Returns ModelBuilder<OAuth2TokenModel>

refresh

  • refresh(): Promise<void>
  • Re-load the currently-loaded database fields from the table.

    Overwrites any un-persisted changes in the current instance.

    Returns Promise<void>

save

  • Persist the model into the database. If the model already exists, perform an update on its fields. Otherwise, insert a new row with its fields.

    Passing the withoutTimestamps will prevent the configured CREATED_AT/UPDATED_AT timestamps from being updated.

    Parameters

    • __namedParameters: { withoutTimestamps: any } = {}

    Returns Promise<Model<OAuth2TokenModel>>

Protected setFieldFromObject

  • setFieldFromObject(thisFieldName: string | symbol, objectFieldName: string, object: QueryRow): void

Protected shouldBroadcast

subscribe

timestamps

  • timestamps(): { created?: Date; updated?: Date }
  • Get normalized values of the configured CREATED_AT/UPDATED_AT fields for this model.

    example
    user.timestamps()  // => {updated: Date, created: Date}
    

    Returns { created?: Date; updated?: Date }

    • Optional created?: Date
    • Optional updated?: Date

toJSON

toObject

toQueryRow

  • Cast the model to the base QueryRow object. The resultant object maps DATABASE fields to values, NOT MODEL fields to values.

    Only fields with @Field() annotations will be included.

    Returns QueryRow

touch

up

  • up(): Promise<void>

wasChanged

  • wasChanged(field: string): boolean
  • Returns true if the given field has changed since this model was fetched from the database, or if the given field never existed in the database.

    Parameters

    • field: string

    Returns boolean

Protected withScope

Static connectionName

  • connectionName(): string

Static findByKey

  • findByKey<T2>(key: ModelKey): Promise<undefined | T2>
  • Find the first instance of this model where the primary key matches key.

    example
    const user = await UserModel.findByKey(45)
    

    Type parameters

    Parameters

    Returns Promise<undefined | T2>

Static getCanonicalResolver

  • getCanonicalResolver(): undefined | string

Static getConnection

Static getFullyQualifiedCanonicalResolver

  • getFullyQualifiedCanonicalResolver(): undefined | string

Static propertyToColumn

  • propertyToColumn(modelKey: string): string
  • Given the name of a property on the model with a @Field() annotation, return the unqualified name of the database column it corresponds to.

    Parameters

    • modelKey: string

    Returns string

Static qualify

  • qualify(column: string): string
  • Given the name of a column, return the qualified name of the column as it could appear in a query.

    example
    SomeModel.qualify('col_name')  // => 'model_table_name.col_name'
    

    Parameters

    • column: string

    Returns string

Static qualifyKey

  • qualifyKey(): string
  • Return the qualified name of the column corresponding to the model's primary key.

    example
    class A extends Model<A> {
        protected static table = 'table_a'
        protected static key = 'a_id'
    }
    
    A.qualifyKey()  // => 'table_a.a_id'
    

    Returns string

Static query

  • Get a new query builder that yields instances of this model, pre-configured with this model's QuerySource, connection, and fields.

    example
    const user = await UserModel.query<UserModel>().where('name', 'LIKE', 'John Doe').first()
    

    Type parameters

    Returns ModelBuilder<T2>

Static querySource

  • Get the QuerySource object for this model as it should be applied to query builders.

    This sets the alias for the model table equal to the table name itself, so it can be referenced explicitly in queries if necessary.

    Returns QuerySource

Static setCanonicalResolver

  • setCanonicalResolver(fullyQualifiedResolver: string, unqualifiedResolver: string): void

Static tableName

  • tableName(): string
Extollo Logo

extollo (v. latin) - to lift up, to elevate

Extollo is a free & libre application framework in TypeScript.