import { PaginatedResult } from '@ably/chat'; import { jsonRpc, jsonRpcBlocking } from './jsonrpc'; // TODO: rework RpcPaginatedResult into multiplie non-generic classes for each generic used in the SDK client. // this is needed so that UTS request to an adapter is definitively tied to the underlying data stored, so we know if we can serialize it. export class RpcPaginatedResult implements PaginatedResult { private readonly _instanceId: string; constructor(instanceId: string) { this._instanceId = instanceId; } get items(): T[] { const { response } = jsonRpcBlocking.request('PaginatedResult#items', { refId: this._instanceId }); return response; } hasNext(): boolean { const { response } = jsonRpcBlocking.request('PaginatedResult.hasNext', { refId: this._instanceId }); return response; } isLast(): boolean { const { response } = jsonRpcBlocking.request('PaginatedResult.isLast', { refId: this._instanceId }); return response; } async next(): Promise | null> { const { response } = await jsonRpc.request('PaginatedResult.next', { refId: this._instanceId }); return response; } async first(): Promise> { const { response } = await jsonRpc.request('PaginatedResult.first', { refId: this._instanceId }); return response; } async current(): Promise> { const { response } = await jsonRpc.request('PaginatedResult.current', { refId: this._instanceId }); return response; } }