Files & blobs (data plane)
Read and write files from the TypeScript SDK: safe writes that detect conflicts, reads, directory operations, publishing lasting copies, and search.
Records are small and unchangeable, and they carry the coordination. Files hold everything else: documents, images, datasets and build outputs. They live in a per-namespace file area and are addressed by path. The TypeScript SDK exposes all of this under client.data.
import { Client, Identity } from "@syncropel/sdk";
const client = new Client({
endpoint: "https://your-workspace.syncropel.app",
identity: Identity.static("did:example:my-app"),
apiKey: process.env.SYNCROPEL_TOKEN,
});
// Write a file, read it back.
const { contentHash } = await client.data.write({
path: "/files/notes.md",
data: "# Meeting notes\n\n- ship the data-plane guide",
contentType: "text/markdown",
});
const text = await client.data.readText("/files/notes.md");How writing differs from emitting
File methods handle errors differently from the record methods (emit, query). A record emit returns { success: false } on network trouble so a UI never crashes. A file write that hits a quota, a conflict or a bad path throws, because a lost write must never look like a success. It raises SyncropelDataError, which you catch and handle.
Writing a file
client.data.write does the whole write in one call, uploading large files in chunks, and returns the stored content hash.
const result = await client.data.write({
path: "/files/report.pdf",
data: pdfBytes, // Uint8Array | ArrayBuffer | string
contentType: "application/pdf", // optional; inferred from the path otherwise
});
// result.contentHash: checksum (SHA-256) of the stored bytes
// result.sizeBytes: bytes writtendata accepts a string (encoded UTF-8), a Uint8Array, or an ArrayBuffer. Large files are uploaded in chunks automatically.
Safe edits (conflict detection)
To avoid overwriting a change made at the same time (another tab, or an agent writing the same file), pass expectedHash:
// 1. Get the current file's hash.
const { contentHash } = await client.data.stat("/files/notes.md");
// 2. Write only if the file is still what we read.
try {
await client.data.write({
path: "/files/notes.md",
data: edited,
expectedHash: contentHash, // only write if unchanged
});
} catch (e) {
if (e instanceof SyncropelDataError && e.isConflict) {
// Someone wrote first. e.currentHash is the file's actual hash now.
// Reload, re-apply the edit, and retry.
}
}expectedHash works three ways:
| Value | Behaviour |
|---|---|
| omitted | The last write wins and overwrites. |
| a hash string | Write only if the file's current hash matches. |
null | Create only: fails if the path already exists. |
On a conflict the write throws SyncropelDataError with isConflict === true, expectedHash (what you expected), and currentHash (the file's real hash): everything you need to offer a reload-or-overwrite prompt.
Reading
const bytes = await client.data.read("/files/report.pdf"); // Uint8Array
const text = await client.data.readText("/files/notes.md"); // UTF-8 string
// Or resolve a short-lived URL (e.g. to hand to an <img> or a download):
const { blobUrl, expiresIn } = await client.data.readUrl("/files/cover.png");Directory operations
const { entries, cursor } = await client.data.list("/files", { limit: 100 });
for (const e of entries) {
console.log(e.kind, e.path, e.size_bytes);
}
const info = await client.data.stat("/files/notes.md");
// info.kind, sizeBytes, contentHash, mtime, contentType, pinState, provenance
await client.data.mkdir("/files/reports");
await client.data.mv("/files/notes.md", "/files/reports/notes.md");
await client.data.rm("/files/reports", { recursive: true });stat returns provenance: who created the file and when (see Provenance below). It's null for files with no recorded author.
Publishing durable artifacts
A file under /files is working storage that you can edit. Publishing makes a lasting, unchangeable copy that you can reference by its hash:
const { contentHash, pinState } = await client.data.publish("/files/report.pdf");
// The published copy is kept permanently; the original /files path stays editable.Finding materials
materials searches your files and returns details only, not file contents. It suits a picker or a search box:
const hits = await client.data.materials({ q: "budget", limit: 20 });
// get one file's details without fetching its contents:
const node = await client.data.node("/files/reports/q3.md");Provenance ("made by you")
Every file records who made it and when. A file you create through the SDK or the API shows you as its author. stat().provenance carries it:
const { provenance } = await client.data.stat("/files/notes.md");
// provenance: { actor, work_thread, goal_summary, clock, content_hash } | nullFor a feed across many files (a "recently made by" view), use client.data.provenance().
Quota and limits
const { used, quota } = await client.data.usage(); // bytes
const caps = await client.data.capabilities(); // limits and chunk sizeError handling
import { SyncropelDataError } from "@syncropel/sdk";
try {
await client.data.write({ path: "/files/x", data, expectedHash });
} catch (e) {
if (e instanceof SyncropelDataError) {
// e.status: HTTP status (e.g. 409, 403, 507)
// e.code: error code (e.g. "precondition_failed", "quota_exceeded")
// e.detail: human-readable detail
// e.isConflict: true for a compare-and-swap / create-only conflict (409)
// e.expectedHash / e.currentHash: set on a conflict
}
}Reads (read, list, stat, …) throw the same SyncropelDataError on a real error, so a missing file or a permission denial is reported instead of quietly returning nothing.
Types
@syncropel/sdk exports the data-plane types: WriteOptions, WriteResult, ListResult, ListEntry, StatResult, MaterialProvenance, ReadUrlResult, PublishResult, UsageResult, and SyncropelDataError.
What's next
- TypeScript SDK: records, threads, and the rest of the client.
- Files: how files work in Syncropel.
TypeScript SDK
Use Syncropel from JavaScript or TypeScript: add records, query threads, and keep your app running through network errors. Works in Node, Deno, Bun, edge runtimes and browsers.
Python SDK
Use Syncropel from Python: add records, query threads, and keep your app running through network errors.