Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Host<Query, Resource>

Translator between Polar and JavaScript.

internal

Type parameters

  • Query

  • Resource

Hierarchy

  • Host

Index

Constructors

constructor

  • new Host<Query, Resource>(ffiPolar: Polar, opts: HostOpts): Host<Query, Resource>
  • internal

    Type parameters

    • Query

    • Resource

    Parameters

    Returns Host<Query, Resource>

Properties

adapter

adapter: Adapter<Query, Resource>

types

types: HostTypes

Methods

cacheClass

  • Store a JavaScript class in the class cache.

    internal

    Parameters

    • cls: Class<unknown>

      Class to cache.

    • Optional params: ClassParams

      Optional parameters.

    Returns string

cacheInstance

  • cacheInstance(instance: unknown, id?: number): number
  • Store a JavaScript instance in the instance cache, fetching a new instance ID from the Polar VM if an ID is not provided.

    internal

    Parameters

    • instance: unknown
    • Optional id: number

    Returns number

externalOp

  • externalOp(op: "Eq" | "Geq" | "Gt" | "Leq" | "Lt" | "Neq", leftTerm: PolarTerm, rightTerm: PolarTerm): Promise<boolean>
  • Check if the given instances conform to the operator.

    internal

    Parameters

    Returns Promise<boolean>

getInstance

  • getInstance(id: number): unknown
  • Fetch a JavaScript instance from the instance cache.

    Public for the test suite.

    internal

    Parameters

    • id: number

    Returns unknown

getType

  • getType<Type>(cls?: string | Type): undefined | UserType<Type, any>
  • Get user type for cls.

    Type parameters

    Parameters

    • Optional cls: string | Type

      Class or class name.

    Returns undefined | UserType<Type, any>

hasInstance

  • hasInstance(id: number): boolean
  • Check if an instance exists in the instance cache.

    internal

    Parameters

    • id: number

    Returns boolean

instances

  • instances(): unknown[]
  • Return cached instances.

    Only used by the test suite.

    internal

    Returns unknown[]

isSubclass

  • isSubclass(left: string, right: string): boolean
  • Check if the left class is a subclass of the right class.

    internal

    Parameters

    • left: string
    • right: string

    Returns boolean

isSubspecializer

  • isSubspecializer(id: number, left: string, right: string): Promise<boolean>
  • Check if the left class is more specific than the right class with respect to the given instance.

    internal

    Parameters

    • id: number
    • left: string
    • right: string

    Returns Promise<boolean>

isa

  • isa(polarInstance: PolarTerm, name: string): Promise<boolean>
  • Check if the given instance is an instance of a particular class.

    internal

    Parameters

    Returns Promise<boolean>

isaWithPath

  • isaWithPath(baseTag: string, path: PolarTerm[], classTag: string): Promise<boolean>
  • Check if a sequence of field accesses on the given class is an instance of another class.

    internal

    Parameters

    • baseTag: string
    • path: PolarTerm[]
    • classTag: string

    Returns Promise<boolean>

makeInstance

  • makeInstance(name: string, fields: PolarTerm[], id: number): Promise<void>
  • Construct a JavaScript instance and store it in the instance cache.

    internal

    Parameters

    • name: string
    • fields: PolarTerm[]
    • id: number

    Returns Promise<void>

registerMros

  • registerMros(): void
  • Register the MROs of all registered classes.

    Returns void

serializeTypes

  • serializeTypes(): obj<unknown>

toJs

  • Turn a Polar term from the Polar VM into a JavaScript value.

    internal

    Parameters

    Returns Promise<unknown>

toPolar

  • Turn a JavaScript value into a Polar term that's ready to be sent to the Polar VM.

    internal

    Parameters

    • v: unknown

    Returns PolarTerm

Static clone

  • clone<Query, Resource>(host: Host<Query, Resource>, opts: Partial<HostOpts>): Host<Query, Resource>
  • Shallow clone a host to extend its state for the duration of a particular query without modifying the longer-lived Polar host state.

    internal

    Type parameters

    • Query

    • Resource

    Parameters

    Returns Host<Query, Resource>