Skip to content

OperationBuilder

Fluent builder for v2 write operations. Get one with client.ops() (or new OperationBuilder()), queue operations, then pass it to client.commit.apply, commit.validate or commit.applyStreaming, or call OperationBuilder.commit.

Every add and revise states its Shapes in exactly one way: shapes, shapeless, or (revise only) keepShapes. Shape names are bare: a write always certifies under each Shape’s head version. Anything else is refused as it is queued, with a WriteOperationError (a WarmHubError with code VALIDATION_ERROR and the operation’s index), before any request. A whole-batch refusal (see OperationBuilder.commit) is a WriteOperationError too, with no index.

await client.commit.apply('org', 'repo', 'seed', client.ops()
.add('acme', { shapes: ['Deal'], data: { company: 'Acme' } }))
// keepShapes reads the committed Thing, so it cannot follow an add of the
// same name in one submission: revise in a later request.
await client.commit.apply('org', 'repo', 'update', client.ops()
.revise('acme', { keepShapes: true, data: { company: 'Acme 2' } }))

https://docs.warmhub.ai/sdk/write-methods/

new OperationBuilder(options?): OperationBuilder

Create an empty builder. Pass known Shape definitions to validate data locally as operations are queued.

OperationBuilderOptions

OperationBuilder

get operations(): readonly OperationBuilderOp[]

The queued operations, read-only.

readonly OperationBuilderOp[]


get size(): number

The number of queued operations.

number

add(name, input): this

Queue an add of the Thing name. State its Shapes with shapes or shapeless. A Shape itself is the Thing shapeName('X') with shapes: [].

string

AddInput

this


revise(name, input): this

Queue a revise of the Thing name. State its Shapes with shapes, shapeless, or keepShapes (which reads the current set and version at submit and sends the version as expectedVersion). keepShapes sends the Shapes bare, so the revise re-certifies under each Shape’s head version.

keepShapes pins the version it read; a cross-process resubmit of the same submissionId can conflict; explicit shapes is the retry-safe form.

string

ReviseInput

this


retract(name, input?): this

Queue a retract of name.

string

RetractInput = {}

this


restore(durableId, input?): this

Queue a restore of a retracted Thing, named by its durable ID: several retracted Things can share a name.

string

RestoreInput = {}

this


rename(name, newName): this

Queue a rename of name to newName, both full names. A Shape renames to a Shape: rename(shapeName('A'), shapeName('B')).

string

string

this


reaffirm(name, input): this

Queue a reaffirm: edit the assertion’s affirmation snapshot without changing its data. add and remove compose in one operation.

string

ReaffirmInput

this


has(name): boolean

Whether an add of name is queued.

string

boolean


validate(): ValidationResult

Check the batch as a whole without contacting the server: empty batches, a name added twice, a revise after a retract. Returns { valid, errors, warnings }. Per-operation refusals already threw when the operation was queued.

ValidationResult


commit(params): Promise<OperationSubmitResult>

Validate, submit, and seal the builder. Equivalent to passing the builder to client.commit.apply, but single-use: a success or a PartialStreamSubmissionError seals it.

{ readonly clientFlags?: readonly string[]; stream: { append(input: StreamAppendInput): Promise<StreamAppendResult>; }; thing?: { getMany(orgName: string, repoName: string, wrefs: string[]): Promise<Pick<ThingGetManyResult, 'items' | 'missing'>>; }; }

WarmHub client or compatible stream client used for submission.

string

string

string

Optional wref identifying the actor on whose behalf the write is made.

string

Optional commit message.

number

Maximum operations per stream append.

string

Caller-managed stream identity for observability and diagnostic correlation.

string

Caller-managed UUID shared by every chunk.

boolean

Return the writer’s own repository-sequence acknowledgement.

false | RetryPolicyOptions

Retry policy for transient first-chunk failures, or false to disable automatic retry.

Promise<OperationSubmitResult>