Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

An instance of a Client is a connection to a single perspective_server::Server, whether locally in-memory or remote over some transport like a WebSocket.

The browser and node.js libraries both support the websocket(url) constructor, which connects to a remote perspective_server::Server instance over a WebSocket transport.

In the browser, the worker() constructor creates a new Web Worker perspective_server::Server and returns a Client connected to it.

In node.js, a pre-instantied Client connected synhronously to a global singleton perspective_server::Server is the default module export.

§JavaScript Examples

Create a Web Worker perspective_server::Server in the browser and return a Client instance connected for it:

import perspective from "@finos/perspective";
const client = await perspective.worker();

Create a WebSocket connection to a remote perspective_server::Server:

import perspective from "@finos/perspective";
const client = await perspective.websocket("ws://locahost:8080/ws");

Access the synchronous client in node.js:

import { default as client } from "@finos/perspective";

Implementations§

Source§

impl Client

Source

pub fn __get_classname() -> &'static str

Source§

impl Client

Source§

impl Client

Source

pub fn get_client(&self) -> &Client

Source§

impl Client

Source

pub fn new(send_request: Function, close: Option<Function>) -> ApiResult<Self>

Source

pub fn new_proxy_session(&self, on_response: &Function) -> ProxySession

Source

pub async fn handle_response(&self, value: &JsValue) -> ApiResult<()>

Source

pub async fn handle_error( &self, error: String, reconnect: Option<Function>, ) -> ApiResult<()>

Source

pub async fn on_error(&self, callback: Function) -> ApiResult<u32>

Source

pub async fn table( &self, value: &JsTableInitData, options: Option<JsTableInitOptions>, ) -> ApiResult<Table>

Creates a new Table from either a schema or data.

The Client::table factory function can be initialized with either a schema (see Table::schema), or data in one of these formats:

  • Apache Arrow
  • CSV
  • JSON row-oriented
  • JSON column-oriented
  • NDJSON

When instantiated with data, the schema is inferred from this data. While this is convenient, inferrence is sometimes imperfect e.g. when the input is empty, null or ambiguous. For these cases, Client::table can first be instantiated with a explicit schema.

When instantiated with a schema, the resulting Table is empty but with known column names and column types. When subsqeuently populated with Table::update, these columns will be coerced to the schema’s type. This behavior can be useful when Client::table’s column type inferences doesn’t work.

The resulting Table is virtual, and invoking its methods dispatches events to the perspective_server::Server this Client connects to, where the data is stored and all calculation occurs.

§Arguments
  • arg - Either schema or initialization data.
  • options - Optional configuration which provides one of:
    • limit - The max number of rows the resulting Table can store.
    • index - The column name to use as an index column. If this Table is being instantiated by data, this column name must be present in the data.
    • name - The name of the table. This will be generated if it is not provided.
    • format - The explicit format of the input data, can be one of "json", "columns", "csv" or "arrow". This overrides language-specific type dispatch behavior, which allows stringified and byte array alternative inputs.
§JavaScript Examples

Load a CSV from a string:

const table = await client.table("x,y\n1,2\n3,4");

Load an Arrow from an ArrayBuffer:

import * as fs from "node:fs/promises";
const table2 = await client.table(await fs.readFile("superstore.arrow"));

Load a CSV from a UInt8Array (the default for this type is Arrow) using a format override:

const enc = new TextEncoder();
const table = await client.table(enc.encode("x,y\n1,2\n3,4"), {
    format: "csv",
});

Create a table with an index:

const table = await client.table(data, { index: "Row ID" });
Source

pub fn terminate(&self) -> ApiResult<JsValue>

Terminates this Client, cleaning up any crate::View handles the Client has open as well as its callbacks.

Source

pub async fn open_table(&self, entity_id: String) -> ApiResult<Table>

Opens a Table that is hosted on the perspective_server::Server that is connected to this Client.

The name property of TableInitOptions is used to identify each Table. Table names can be looked up for each Client via Client::get_hosted_table_names.

§JavaScript Examples

Get a virtual Table named “table_one” from this Client

const tables = await client.open_table("table_one");
Source

pub async fn get_hosted_table_names(&self) -> ApiResult<JsValue>

Retrieves the names of all tables that this client has access to.

name is a string identifier unique to the Table (per Client), which can be used in conjunction with Client::open_table to get a Table instance without the use of Client::table constructor directly (e.g., one created by another Client).

§JavaScript Examples
const tables = await client.get_hosted_table_names();
Source

pub async fn on_hosted_tables_update( &self, on_update_js: Function, ) -> ApiResult<u32>

Register a callback which is invoked whenever Client::table (on this Client) or Table::delete (on a Table belinging to this Client) are called.

Source

pub async fn remove_hosted_tables_update(&self, update_id: u32) -> ApiResult<()>

Remove a callback previously registered via Client::on_hosted_tables_update.

Source

pub async fn system_info(&self) -> ApiResult<JsSystemInfo>

Provides the SystemInfo struct, implementation-specific metadata about the [perspective_server::Server] runtime such as Memory and CPU usage.

For WebAssembly servers, this method includes the WebAssembly heap size.

§JavaScript Examples
const info = await client.system_info();

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<Client> for JsValue

Source§

fn from(value: Client) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for Client

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for Client

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for Client

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<Client>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for Client

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for Client

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl PartialEq for Client

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RefFromWasmAbi for Client

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<Client>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for Client

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<Client>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFrom<&JsValue> for Client

Source§

type Error = String

The type returned in the event of a conversion error.
Source§

fn try_from(js: &JsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFromJsValue for Client

Source§

type Error = JsValue

The type returned in the event of a conversion error.
Source§

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl VectorFromWasmAbi for Client

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Client]>

Source§

impl VectorIntoJsValue for Client

Source§

impl VectorIntoWasmAbi for Client

Source§

type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi

Source§

fn vector_into_abi(vector: Box<[Client]>) -> Self::Abi

Source§

impl WasmDescribe for Client

Source§

impl WasmDescribeVector for Client

Source§

impl SupportsConstructor for Client

Source§

impl SupportsInstanceProperty for Client

Source§

impl SupportsStaticProperty for Client

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !Send for Client

§

impl !Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more