Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace API

The namespace API is dedicated to the definition of the core system APIs used by AntOS and its applications. The following core APIs are defined:

  • The AntOS announcement system
  • Virtual File system
  • Virtual Database
  • Low-level REST based client-server communication
  • Dependencies management
  • System utilities

These APIs are considered as middle-ware that abstracts the client-server communication and provide the application layer with a standardized APIs for file/database access, system events handling (announcement), automatic dependencies resolving, etc.

Index

Variables

BASE_URI

BASE_URI: string = `${HOST}${loc.pathname}`

The base URI of the server-side API

HOST

HOST: string = loc.hostname + (loc.port ? `:${loc.port}` : "")

The host name of the server-side

REST

REST: string = `${loc.protocol}//${BASE_URI}`

The base REST URI of the server-side API

lang

lang: GenericObject<string>

Placeholder of the current system locale dictionary, the system uses this dictionary to translate all translatable texts to the current locale language

Const searchHandle

searchHandle: GenericObject<(text: string) => any[]>

Placeholder for all global search handles registered to the system. These callbacks will be called when user performs the search operation in the spotlight UI.

Applications can define their own search handle to provide the spotlight UI with additional search results

Const shared

shared: GenericObject<boolean>

Placeholder to store all loaded shared libraries. Once a shared library is firstly loaded, its identity will be stored in this variable. Based on this information, in the next use of the library, the system knows that the library is already loaded and ready to use.

A shared library can be a javascript or a CSS file.

Functions

apigateway

  • An apigateway allows client side to execute a custom server-side script and get back the result. This gateway is particularly useful in case of performing a task that is not provided by the core API

    export

    Parameters

    • d: GenericObject<any>

      execution indication, provided only when ws is false otherwise, d should be written directly to the websocket stream as JSON object. Two possible formats of d:

      execute an server-side script file:
      
      {
       path: [VFS path],
       parameters: [parameters of the server-side script]
      }
      
      or, execute directly a snippet of server-side script:
      
      { code: [server-side script code snippet as string] }
      
    • ws: boolean

      flag indicate whether to use websocket for the connection to the gateway API. In case of streaming data, the websocket is preferred

    Returns Promise<any>

    a promise on the result object (any)

blob

  • blob(p: string): Promise<ArrayBuffer>
  • REST-based API.

    Perform a GET request and read back the data in ArrayBuffer (binary) format. This is useful for binary data reading

    export

    Parameters

    • p: string

      resource URI

    Returns Promise<ArrayBuffer>

    a promise on the returned binary data

get

  • get(p: string, t?: string): Promise<any>
  • Perform an REST GET request

    export

    Parameters

    • p: string

      the URI of the request

    • Default value t: string = undefined

    Returns Promise<any>

    a Promise on the requested data

getClipboard

  • getClipboard(): Promise<any>
  • Get the clipboard data

    export

    Returns Promise<any>

    Promise on the clipboard data

libready

  • libready(l: string): boolean
  • Helper function to verify whether a shared library is loaded and ready to use

    export

    Parameters

    • l: string

      path to the library

    Returns boolean

loaded

  • loaded(q: number, p: string, m: string): void
  • Helper function to trigger the global loaded event: This event should be triggered in the end of a heavy task that has previously triggered the loading event

    export

    Parameters

    • q: number

      the message id of the corresponding loading event

    • p: string

      the message string

    • m: string

      message status (OK of FAIL)

    Returns void

loading

  • loading(q: number, p: string): void
  • Helper function to trigger the global loading event. This event should be triggered in the beginning of a heavy task

    export

    Parameters

    • q: number

      message id, see mid

    • p: string

      message string

    Returns void

mid

  • mid(): number

onsearch

  • onsearch(name: string, fn: (text: string) => any[]): void
  • Register a search handle to the global searchHandle

    export

    Parameters

    • name: string

      handle name string

    • fn: (text: string) => any[]

      search handle

        • (text: string): any[]
        • Parameters

          • text: string

          Returns any[]

    Returns void

post

  • post(p: string, d: any): Promise<any>
  • REST-based API.

    Perform a POST request to the server. Data exchanged is in application/json

    export

    Parameters

    • p: string

      the server URI

    • d: any

      data object that will be converted to JSON

    Returns Promise<any>

    a promise on the result data

require

  • require(libs: string[]): Promise<void>
  • Synchronously load a list of shared libraries

    export

    Parameters

    • libs: string[]

      list of shared libraries

    Returns Promise<void>

requires

  • requires(l: string, force?: boolean): Promise<void>
  • Load a shared library if not ready

    export

    Parameters

    • l: string

      VFS path to the library

    • Default value force: boolean = false

      force reload library

    Returns Promise<void>

    a promise on the result data

resource

  • resource(r: string): Promise<any>
  • REST-based API

    Get the content of a global asset resource stored in os://resources/

    export

    Parameters

    • r: string

      relative path to the resource

    Returns Promise<any>

    promise on the returned content

saveblob

  • saveblob(name: string, b: any): void
  • REST-based API.

    Download a file

    export

    Parameters

    • name: string

      file name

    • b: any

      file content

    Returns void

script

  • script(p: string): Promise<any>
  • REST-based API

    Perform a GET operation and executed the returned content as javascript

    export

    Parameters

    • p: string

      URI resource

    Returns Promise<any>

    promise on the executed content

search

  • search(text: string): any[]
  • Perform the global search operation when user enter text in spotlight.

    This function will call all the search handles stored in searchHandle and build the search result based on output of these handle

    export

    Parameters

    • text: string

      text to search

    Returns any[]

setClipboard

  • setClipboard(v: string): boolean
  • Set value to the system clipboard

    export

    Parameters

    • v: string

      clipboard value

    Returns boolean

setLocale

  • setLocale(name: string): Promise<any>
  • Set the current system locale: This function will find and load the locale dictionary definition file in the system asset resource, then trigger the global event systemlocalechange to translated all translatable text to the target language

    export

    Parameters

    • name: string

      locale name, e.g. en_GB

    Returns Promise<any>

setting

switcher

  • switcher(...args: string[]): any
  • A switcher object is a special object in which each object's property is a boolean option. All object's properties are mutual exclusive. It means that when a property is set to true, all other properties will be reset to false.

    Example:

    let view = API.switcher("tree", "list", "icon")
    view.tree = true // view.list = false and view.icon = false
    view.list = true // view.tree = false and view.icon = false
    
    export

    Parameters

    • Rest ...args: string[]

    Returns any

throwe

  • Return an error Object: AntOS use this function to collect information (stack trace) from user reported error.

    export

    Parameters

    Returns Error

upload

  • upload(p: string, d: string): Promise<any>
  • REST-based API.

    Send file to server

    export

    Parameters

    • p: string

      resource URI

    • d: string

      VFS path of the destination file

    Returns Promise<any>