Skip to main content
The slideshowSave procedure writes a full array of Slideshow objects to the filesystem under the given dataset ID. It returns the new digest of the saved state, which you can use to detect staleness on the next save.

Request

POST /rpc/slideshowSave

Input

datasetId
string
required
The dataset to write to. Must be a non-empty string and must not be "all". This identifies the file or directory on disk where the slideshows will be persisted.
slideshows
Slideshow[]
required
The full array of slideshows to save. The entire array is written atomically — partial updates are not supported. See the Slideshow type reference for the complete shape.
expectedDigest
string
An optional staleness guard. If provided, the server compares this value against the current on-disk digest before writing. If they differ — meaning another write happened since you last loaded — the save may be rejected.Pass the digest value returned by a previous slideshowLoad or slideshowSave call to enable this check. Omit it to skip staleness detection and always overwrite.

Response

success
true
required
Always true on a successful save. Errors are returned as ORPC error responses, not as success: false.
digest
string
required
A content-based digest of the saved state. Store this value and pass it as expectedDigest on the next save to prevent overwriting concurrent changes.
path
string
required
The filesystem path where the data was written.

Examples

import { createORPCClient } from "@orpc/client";
import { RPCLink } from "@orpc/client/fetch";
import type { AppRouter } from "@slides/api/routers/index";

const client = createORPCClient<AppRouter>(
  new RPCLink({ url: "http://localhost:3000/rpc" })
);

// Load slideshows
const loaded = await client.slideshowLoad({ datasetId: "my-project" });

// Save and capture the returned digest for future staleness checks
const firstSave = await client.slideshowSave({
  datasetId: "my-project",
  slideshows: loaded.slideshows,
});
const savedDigest = firstSave.digest; // store this for the next save

// Later: modify and save again with staleness protection
const updatedSlideshows = loaded.slideshows.map((sw) => ({
  ...sw,
  title: sw.title + " (updated)",
}));

const result = await client.slideshowSave({
  datasetId: "my-project",
  slideshows: updatedSlideshows,
  expectedDigest: savedDigest, // reject if another save happened since
});

console.log(result.success); // true
console.log(result.digest);  // store for next save
console.log(result.path);    // e.g. "/data/my-project.json"

Example response

{
  "success": true,
  "digest": "sha256:a3f8c2...",
  "path": "/data/my-project.json"
}

Staleness protection

The expectedDigest field implements optimistic concurrency control. The workflow is:
  1. Call slideshowLoad to get the current data.
  2. Call slideshowSave to save, and capture the digest from the response.
  3. On the next save, pass that digest as expectedDigest.
  4. If another client saved in the meantime, the digests will differ and the save is rejected.
  5. On rejection, reload the latest data, re-apply your changes, and save again.
Omitting expectedDigest disables staleness detection. Your save will always overwrite whatever is currently on disk. Only omit it when you are certain you hold the latest version.

Build docs developers (and LLMs) love