liwi-resources-direct-client
v15.2.0
Published
direct client implementation for liwi
Readme
About
In-process TransportClient: calls the resources server directly, with no network, encoding or serialization. Use it when client code runs in the same process as the server — server-side rendering, scripts, tests.
Install
npm install --save liwi-resources-direct-clientUsage
import { createDirectTransportClient } from "liwi-resources-direct-client";
import { resourcesServerService } from "./resources/index.ts";
const transportClient = createDirectTransportClient({
resourcesServerService,
authenticatedUser: user ?? null,
});
const tasksService = createTasksServiceClient(transportClient);
const { result } = await tasksService.queries
.queryAll({ limit: 20, page: 1 })
.fetch((queryResult) => queryResult);API
createDirectTransportClient({ resourcesServerService, authenticatedUser })
Returns a TransportClient wired to createMessageHandler(resourcesServerService, authenticatedUser, false).
resourcesServerService— theResourcesServerServiceholding the resources.authenticatedUser— passed to every query and operation asloggedInUser; usenullwhen anonymous.
connect() is a no-op, listenStateChange() never fires (the connection is always usable), and close() releases the handler.
Limitations
Subscriptions are disabled: the message handler is created with allowSubscriptions: false, so subscribe / fetchAndSubscribe fail with Subscriptions not allowed (the error is passed to the subscription callback), and stop() / cancel() are no-ops. Fetch queries and operations only. For live updates use the websocket client.
