Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RelatedManager<T>

Type parameters

Hierarchy

  • RelatedManager

Index

Constructors

constructor

Properties

_resources

_resources: Record<string, InstanceType<T>>

batchSize

batchSize: number = Infinity

When sending this.resolve(), only send out the first n requests where n is this.batchSize. You can call this.all() to recursively get all objects

deferred

deferred: function[] = []

Deferred promises when this.resolve() hits the max requests in this.batchSize

many

many: boolean = false

primaryKeys

primaryKeys: string[]

List of stringified Primary Keys, even if this.value is a list of objects, or Resource instances

resolved

resolved: boolean = false

Is true when resolve() is called and first page of results loads up to this.batchSize objects

to

to: T

value

Accessors

length

  • get length(): number

resource

  • get resource(): InstanceType<T>
  • Getter -- Same as manager.resources except returns first node

    Returns InstanceType<T>

resources

  • get resources(): InstanceType<T>[]
  • Getter -- get this._resources but make sure we've actually retrieved the objects first Throws AttributeError if this.resolve() hasn't finished

    Returns InstanceType<T>[]

Methods

add

  • add(resource: InstanceType<T>): void
  • Add a resource to the manager

    Parameters

    • resource: InstanceType<T>

      Resource instance

    Returns void

all

  • all(options?: DetailOpts): Promise<InstanceType<T>[]>
  • Calls pending functions in this.deferred until it's empty. Runs this.resolve() first if it hasn't been ran yet

    Parameters

    Returns Promise<InstanceType<T>[]>

canAutoResolve

  • canAutoResolve(): boolean

fromValue

  • fromValue<T>(this: InstanceType<T>, value: any): InstanceType<T>
  • Create a copy of this except with new value(s)

    Type parameters

    Parameters

    • this: InstanceType<T>
    • value: any

    Returns InstanceType<T>

getAllLoaded

  • getAllLoaded(): InstanceType<T>[]
  • Get all loaded resources relevant to this relation Like manager.resources getter except it won't throw an AttributeError and will return with any loaded resources if its ID is listed in this.primaryKeys

    Returns InstanceType<T>[]

getIdFromObject

  • getIdFromObject(object: any): string
  • Get unique key property from object literal and turn it into a string

    Parameters

    • object: any

      Object

    Returns string

getIdFromResource

  • getIdFromResource(resource: InstanceType<T>): string
  • Get unique key from resource instance

    Parameters

    • resource: InstanceType<T>

      Resource

    Returns string

getOne

  • getOne(id: string | number, options?: DetailOpts): Promise<InstanceType<T>>
  • Get a single resource from the endpoint given an ID

    Parameters

    • id: string | number

      String | Number

    • Optional options: DetailOpts

    Returns Promise<InstanceType<T>>

getOneAtIndex

  • getOneAtIndex(index: number): Promise<InstanceType<T>>
  • Same as getOne but allow lookup by index

    Parameters

    • index: number

      Number

    Returns Promise<InstanceType<T>>

getPrimaryKeys

  • getPrimaryKeys(): string[]
  • Get the current value and the content type and turn it into a list of primary keys

    Returns string[]

    String

getValueContentType

  • getValueContentType(): any
  • Return a constructor so we can guess the content type. For example, if an object literal is passed, this function should return Object, and it's likely one single object literal representing attributes. If the constructor is an Array, then all we know is that there are many of these sub items (in which case, we're taking the first node of that array and using that node to guess). If it's a Number, then it's likely that it's just a primary key. If it's a Resource instance, it should return Resource. Etc.

    Returns any

    Function

hasValues

  • hasValues(): boolean
  • Check if values exist on manager

    Returns boolean

next

  • next(options?: DetailOpts): Promise<InstanceType<T>[]>

resolve

  • resolve(options?: DetailOpts): Promise<InstanceType<T>[]>
  • Primary function of the RelatedManager -- get some objects (this.primaryKeys) related to some other Resource (this.to instance). Load the first n objects (this.batchSize) and set this.resolved = true. Subsequent calls may be required to get all objects in this.primaryKeys because there is an inherent limit to how many requests that can be made at one time. If you want to remove this limit, set this.batchSize to Infinity

    Parameters

    Returns Promise<InstanceType<T>[]>

resolveFromObjectValue

  • resolveFromObjectValue(): boolean

toJSON

  • toJSON(): any

toString

  • toString(): string

Generated using TypeDoc