Skip to main content

Rail Deck is being prepared for an invitation-only Alpha. Check current availability

Developer documentation

Layout state

Read a decoded snapshot with account and layout scope, cancellation and a bounded timeout.

Source 0.1.0 Private source package

How the calls fit together

Keep scope and freshness with each observation. Reconnecting must not restore authority or replay movement input.

JavaScript examples

Supply your configured client. Each call awaits a decoded result; errors pass to your caller. These identifiers and values are fictional. Use selected development records and review every change before running it. Opening this page sends no API requests.

See the complete TypeScript workflow · Explore the Node starter

currentState.getLayoutSnapshot

Loads the latest known layout current-state snapshot.

const result = await client.currentState.getLayoutSnapshot(
  "account-1",
  "layout-1",
  {}
);
TypeScript parameters and return type
accountId · required
RailDeckIdentifier

Account that owns the layout.

layoutId · required
RailDeckIdentifier

Layout to load.

requestOptions · optional
RailDeckRequestControlOptions

Optional cancellation and timeout controls.

Returns Promise<RailDeckLayoutCurrentStateResponseV1>.

Example evidence: Retained SDK transport fixture.

Download all TypeScript method examples

JavaScript calls and TypeScript downloads are checked through the real SDK using local response fixtures. This verifies the calls and decoding for those fixtures.

Handle errors and uncertain outcomes

Choose another feature

The complete TypeScript workflow

Follow how the calls fit together, including the review and recovery steps. Supply your configured client and explicitly selected development records. Importing the download performs no requests; mutations are never retried automatically.

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

Information reviewed .