OperationBuilder
Fluent builder for composing, validating, and submitting WarmHub commit operations.
Use this when a caller needs to build a batch incrementally, run local preflight checks, optionally validate data against known shapes, and submit through the SDK stream-append path with continuation and retry options.
The builder is not a promise — there is no build() method, and await cb
alone will not submit anything. Finalize the batch by calling
await cb.commit({ client, orgName, repoName, ... }), which validates,
submits, and seals the builder in one step. Reusing a sealed builder throws.
Example
Section titled “Example”const cb = new OperationBuilder();cb .add({ name: "Sensor/temp-1", data: { location: "A" } }) .revise({ name: "Sensor/temp-1", data: { location: "B" } });const result = await cb.commit({ client, orgName: "acme", repoName: "world" });https://docs.warmhub.ai/sdk/write-methods/
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new OperationBuilder(
options?):OperationBuilder
Create an empty operation builder.
Pass known shape definitions when you want local data validation before submitting operations.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”OperationBuilder
Accessors
Section titled “Accessors”operations
Section titled “operations”Get Signature
Section titled “Get Signature”get operations(): readonly
OperationBuilderOp[]
Return the queued operations.
The returned array is read-only; use add, revise, and retract to modify the builder.
Returns
Section titled “Returns”readonly OperationBuilderOp[]
Get Signature
Section titled “Get Signature”get size():
number
Return the number of queued operations.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”add(
op):this
Add a shape, thing, assertion, or collection operation.
For things and assertions, names use Shape/localName. Supplying about makes the operation an assertion. Supplying collection type and members makes it a collection. Otherwise the builder infers kind from the name.
Set kind: 'thing' explicitly for hierarchical thing names that would otherwise look like assertion paths.
Parameters
Section titled “Parameters”Omit<AddOp, 'operation'> | AddOp
Returns
Section titled “Returns”this
revise()
Section titled “revise()”revise(
op):this
Add a revise operation.
The target can be supplied as name or wref. When shape definitions were provided to the constructor, revise data is validated locally before the operation is queued.
Parameters
Section titled “Parameters”Omit<ReviseOp, 'operation'> | ReviseOp
Returns
Section titled “Returns”this
retract()
Section titled “retract()”retract(
target):this
Add a retract operation.
Pass a wref string shorthand or an object with a target name, optional kind safety hint, and optional reason.
Parameters
Section titled “Parameters”target
Section titled “target”string | { name: string; kind?: "shape" | "thing" | "assertion" | "collection"; reason?: string; leaseId?: string; }
Returns
Section titled “Returns”this
has(
name):boolean
Return whether this builder has queued an add operation for a name.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
validate()
Section titled “validate()”validate():
ValidationResult
Run client-side validation without contacting the server.
Validation checks for empty commits, duplicate adds, missing revise targets, revise-after-retract patterns, local shape-data errors when shapes were provided, and the same preflight diagnostics used before commit submission.
Returns a ValidationResult object ({ valid, errors, warnings }) —
not a boolean. Read result.valid to gate submission, and iterate
result.errors for blocking diagnostics or result.warnings for
informational ones.
Returns
Section titled “Returns”Example
Section titled “Example”const cb = new OperationBuilder();cb.add({ name: "Location/cave", data: { x: 0, y: 0 } });const result = cb.validate();if (!result.valid) { for (const err of result.errors) { console.error(`op ${err.operationIndex}: ${err.code} — ${err.message}`); } throw new Error("validation failed");}for (const warn of result.warnings) console.warn(warn.message);commit()
Section titled “commit()”commit(
params):Promise<OperationSubmitResult>
Validate, submit, and seal the builder.
A successful call submits operations through the same stream path as client.commit.apply and makes the builder single-use. Validation failures throw before any server request is made. Ambiguous multi-chunk failures surface as PartialStreamSubmissionError; deterministic all-failed batches surface as AllStreamOperationsFailedError with per-op failure data.
Parameters
Section titled “Parameters”params
Section titled “params”client
Section titled “client”{ stream: { append(input: StreamAppendInput): Promise<StreamAppendResult>; }; }
WarmHub client or compatible stream client used for submission.
orgName
Section titled “orgName”string
repoName
Section titled “repoName”string
committer?
Section titled “committer?”string
Optional wref identifying the actor on whose behalf the write is made.
message?
Section titled “message?”string
Optional commit message.
chunkSize?
Section titled “chunkSize?”number
Maximum operations per stream append.
streamId?
Section titled “streamId?”string
Advanced continuation hook for caller-managed streams.
allocatedTokens?
Section titled “allocatedTokens?”object[]
Advanced continuation hook for $N / #N token allocation state.
retry?
Section titled “retry?”false | RetryPolicyOptions
Retry policy for transient first-chunk failures, or false to disable automatic retry.
Returns
Section titled “Returns”Promise<OperationSubmitResult>
Hit a problem or have a question? Get in touch.