Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Polar<Query, Resource>

Create and manage an instance of the Polar runtime.

Type parameters

  • Query

  • Resource

Hierarchy

Index

Constructors

constructor

  • new Polar<Query, Resource>(opts?: Options): Polar<Query, Resource>

Methods

clearRules

  • clearRules(): void
  • Clear rules from the Polar KB, but retain all registered classes and constants.

    Returns void

free

  • free(): void
  • Free the underlying WASM instance.

    Invariant: ensure that you do not do anything else with an instance after calling free() on it.

    This should not be something you need to do during the course of regular usage. It's generally only useful for scenarios where large numbers of instances are spun up and not cleanly reaped by the GC, such as during a long-running test process in 'watch' mode.

    Returns void

getFfi

  • getFfi(): Polar

getHost

  • getHost(): Host<Query, Resource>

loadFile

  • loadFile(filename: string): Promise<void>

loadFiles

  • loadFiles(filenames: string[]): Promise<void>
  • Load Polar policy files.

    Parameters

    • filenames: string[]

    Returns Promise<void>

loadStr

  • loadStr(contents: string, filename?: string): Promise<void>
  • Load a Polar policy string.

    Parameters

    • contents: string
    • Optional filename: string

    Returns Promise<void>

query

queryRule

queryRuleOnce

  • queryRuleOnce(name: string, ...args: unknown[]): Promise<boolean>
  • Query for a Polar rule, returning true if there are any results.

    Parameters

    • name: string
    • Rest ...args: unknown[]

    Returns Promise<boolean>

registerClass

  • Register a JavaScript class for use in Polar policies.

    Parameters

    • cls: Class<unknown>

      The class to register.

    • Optional params: ClassParams

      An optional object with extra parameters.

    Returns void

registerConstant

  • registerConstant(value: unknown, name: string): void
  • Register a JavaScript value for use in Polar policies.

    Parameters

    • value: unknown
    • name: string

    Returns void

repl

  • repl(files?: string[]): Promise<void>
  • Start a REPL session.

    Parameters

    • Optional files: string[]

    Returns Promise<void>