Read a layout’s current state
Read a layout with JavaScript or the complete TypeScript workflow.
Source 0.1.0 Private source package
Read a layout snapshot
With an authenticated client configured for your integration, await the result. Replace these fictional account and layout identifiers with your selected development records. Errors pass to your caller; this read does not operate the railway.
const result = await client.currentState.getLayoutSnapshot(
"account-1",
"layout-1",
{}
);Start with one read
The JavaScript call below uses your configured integration client and selected account and layout. The optional TypeScript download adds a reusable helper with request controls. It targets private source 0.1.0.
To run the TypeScript download in the authorised source workspace, use Node.js 24.20.0 and the repository’s pinned TypeScript/tsx tools. Import readLayoutState and supply the client, accountId and layoutId. This toolchain is not an HTTP API requirement.
Callers own authentication and the AbortController. The helper sends one read with a 15-second timeout and returns the decoded response. It performs no writes, retries, logging or automatic recovery.
What its automated check covers
The check invokes this exact downloadable file through the actual SDK current-state client and decoder. It covers a valid scoped response, request cancellation, malformed response refusal and propagation of an API error. It uses a local fixture, not a live service or physical railway.
The complete TypeScript read workflow
import { decodeRailDeckRealtimeFrame, type RailDeckRealtimeSubscription } from '@raildeck/frontend-sdk/direct-integration';
import type { RailDeckDirectIntegrationClient } from '@raildeck/frontend-sdk/direct-integration';
type LayoutReader = Pick<RailDeckDirectIntegrationClient, 'currentState'>;
/**
* Reads one authorised layout without issuing or retrying a command.
* @param client - Configured integration client; the caller owns authentication.
* @param accountId - Authorised account that owns the layout.
* @param layoutId - Layout to observe within that account.
* @param signal - Caller-owned cancellation signal.
* @returns The SDK-decoded current-state response; errors propagate unchanged.
*/
export async function readLayoutState(
client: LayoutReader,
accountId: string,
layoutId: string,
signal: AbortSignal,
) {
return client.currentState.getLayoutSnapshot(accountId, layoutId, {
signal,
timeoutMs: 15_000,
});
}
/**
* Decode an incoming frame before it reaches a projection or command coordinator.
* @param frame - Untrusted text received by the caller's approved realtime transport.
* @param subscription - The account or layout authorised for this connection.
* @param receivedGeneration - Connection generation captured when receiving the frame.
* @param activeGeneration - The caller's current connection generation.
* @returns A decoded message or an explicit unsupported outcome; malformed frames throw.
*/
export function decodeIntegrationFrame(
frame: string,
subscription: RailDeckRealtimeSubscription,
receivedGeneration: number,
activeGeneration: number,
) {
return decodeRailDeckRealtimeFrame(frame, {
audience: 'direct-integration', subscription,
receivedSocketGeneration: receivedGeneration,
activeSocketGeneration: activeGeneration,
});
}
Download TypeScript example