@warmhub/sdk-ts 0.140.0

Changed

A resumed repository export now sends the formatVersion of the header the download opened with, and the server refuses a resume whose format is not the one it writes: HTTP 412 client-incompatible with the message "Restart the export; a resume must use the format it started with." A download started before a server upgrade that changes the export format can no longer be silently finished under its old header; the resume fails and the export must be restarted.

A resume of a file that holds only the header (interrupted before the first row) sends no cursor, so the server cannot check it; the session now compares the new header's format to the saved one and raises RepositoryExportError (header_invalid) with the same restart message rather than appending new-format rows under the old header.

Upgrade with the server. An older SDK sends no formatVersion on a resume, so a server with this change refuses every resume from it, not only cross-format ones. Upgrade the SDK in the same release as the server.

Added

isAllStreamOperationsFailedError(error) reports whether a thrown value is an all-failed stream error. Unlike error instanceof AllStreamOperationsFailedError, it also recognizes the error after toWarmHubError normalization and when a different copy of the SDK threw it.

Breaking

NAME_TAKEN names the holder by durable id only and offers no replacement name

What it was. A name_taken error's details.takenBy was { shape, durableId }, details.suggestedName could carry a replacement name, and the message said by a <Shape> Thing and for example "<name>".

What it is now. details.takenBy is { durableId }; shape is removed. details.suggestedName is removed and no example name appears in the message or hint. The message names no Shape: Name "acme" is already taken in this repository by another Thing; choose another name. A caller who cannot read the holder still gets no takenBy and no by another Thing. The name_taken decoder in the streaming submission protocol requires only takenBy.durableId.

Why it breaks. This is a client-visible breaking change, accepted. Released sdk-ts 0.135.0 to 0.139.0 decode takenBy with shape required, so they refuse a name_taken result from a server that carries this change. It lands before the v2 floor release (0.140.0), so no v2 client sees shape.

Migration. Read the holder's Shapes with get on details.takenBy.durableId; a Thing can have several Shapes or none. Choose the replacement name yourself.

// Before
const { takenBy, suggestedName } = details
console.log(takenBy?.shape, suggestedName)

// After
const holder = details.takenBy && (await client.thing.get(org, repo, details.takenBy.durableId))

Added

The restore operation and OperationBuilder.restore() make a retracted Thing active again, by its durable ID. Pass newName to restore it under another name.

In these notes, "old grammar" means the reference form used before this release (Deal/acme, operations with kind), and "new grammar" the form this release introduces (acme, operations with shapes).

Breaking

Write operations take name and shapes

What it was. Operations carried kind, an add name spelled Shape/name, a top-level about, or collection type/members, and the SDK converted them.

What it is now. Operation, AddOperation, ReviseOperation, RetractOperation, ReaffirmOperation and RenameOperation keep their names but have the new shape. An add or revise requires name, shapes and data. kind and shape are typed never. The new WriteOperation type is one operation of that form.

Migration.

// Before
await client.commit.apply('acme', 'world', 'seed', [
  { operation: 'add', kind: 'thing', name: 'Deal/acme', data: { company: 'Acme' } },
])

// After
await client.commit.apply('acme', 'world', 'seed', [
  { operation: 'add', name: 'acme', shapes: ['Deal'], data: { company: 'Acme' } },
])

Old-grammar operations are refused before any request

What it was. The SDK converted old-grammar operations.

What it is now. An operation with kind, shape, wref, declaredShapes, about, collection type or members, or with no operation, is refused with a WriteOperationError before anything is sent. The message shows a suggested new form, with data values replaced by "...". Names and about targets are copied as written, so check them: a suggested name: 'Deal/acme' would address a Thing literally named Deal/acme. An add or revise with no shapes is refused with a message that it states no Shapes.

Old-grammar input no longer type-checks, so it reaches this refusal only through a cast.

Migration.

// Before: converted and sent
await client.commit.apply('acme', 'world', 'rate', [
  { operation: 'add', kind: 'assertion', name: 'Rating/r1', about: 'Deal/acme', data: { score: 5 } },
])

// After
await client.commit.apply('acme', 'world', 'rate', [
  { operation: 'add', name: 'r1', shapes: ['Rating'], data: { about: 'acme', score: 5 } },
])

Other operations refused locally:

OperationBuilder methods take the name first

What it was. add({ name, data }), revise({ name, data }), retract(target), reaffirm({ name, kind, ... }); no rename.

What it is now.

Method After
add add(name, { shapes | shapeless, data, ... })
revise revise(name, { shapes | shapeless | keepShapes, data, ... })
retract retract(name, { reason? })
reaffirm reaffirm(name, { add?, remove? })
rename rename(name, newName) (new)

Each add and revise states its Shapes in exactly one way: shapes: [...], shapeless: true, or (revise only) keepShapes: true. The builder refuses zero ways or more than one, keepShapes on an add, shapeless on a hub/shapes/X name, and shapes: [] on a non-Shape name (spell that shapeless: true).

Migration.

// Before
import { OperationBuilder } from '@warmhub/sdk-ts'
const ob = new OperationBuilder()
ob.add({ name: 'Deal/acme', data: { company: 'Acme' } })
ob.retract('Deal/old')
await ob.commit({ client, orgName: 'acme', repoName: 'world', message: 'seed' })

// After
import { createOperationEventRequestId } from '@warmhub/sdk-ts'

await client.shape.create('acme', 'world', 'Deal', { company: 'string' }, {
  eventRequestId: createOperationEventRequestId(),
})

await client.commit.apply(
  'acme',
  'world',
  'seed',
  client
    .ops()
    .add('acme', { shapes: ['Deal'], data: { company: 'Acme' } })
    .add('scratch', { shapeless: true, data: { note: 'free' } })
    .rename('scratch', 'scratch-2')
    .retract('old'),
)

// A later submission: keepShapes revises a Thing that already exists
await client.commit.apply(
  'acme',
  'world',
  'update',
  client.ops().revise('acme', { keepShapes: true, data: { company: 'Acme 2' } }),
)

A keepShapes revise of a Thing added or renamed earlier in the same submission is refused; state shapes instead.

Builder errors are WriteOperationError, raised when an operation is queued

What it was. Some refusals surfaced only at commit.

What it is now. A per-operation refusal throws at the .add(...) or .revise(...) call. Whole-batch refusals ("already submitted", "in flight") have operationIndex: undefined. The code is usually VALIDATION_ERROR; it can also be RESERVED_NAME, ILLEGAL_OP_SEQUENCE, a Shape-name check code, or (for keepShapes, at submit) NOT_FOUND.

Migration.

import { WriteOperationError, type AddInput } from '@warmhub/sdk-ts'

try {
  client.ops().add('acme', { data: {} } as AddInput) // no Shapes stated
} catch (e) {
  if (e instanceof WriteOperationError) console.log(e.code, e.operationIndex) // VALIDATION_ERROR 0
}

Every reference argument uses the new grammar

What it was. Read and write calls took Deal/acme, and a Shape was Deal.

What it is now. Pass the Thing name (acme) and hub/shapes/Deal for a Shape where any Thing can appear. An old spelling is looked up literally: a single read gets NOT_FOUND, and thing.getMany lists it in missing. Globs (match) match Thing names, and * does not cross /.

Migration.

// Before
await client.thing.get('acme', 'world', 'Deal/acme')
// After
await client.thing.get('acme', 'world', 'acme')

thing.rename takes full names

What it was. rename(org, repo, shapeName, oldName, newName, opts).

What it is now. rename(org, repo, name, newName, opts). A call in the old argument order is refused locally with VALIDATION_ERROR.

Migration.

// Before
await client.thing.rename('acme', 'world', 'Deal', 'acme', 'acme-corp', { eventRequestId })
// After
await client.thing.rename('acme', 'world', 'acme', 'acme-corp', { eventRequestId })

Read results drop shape, shapeName and validatedShape

What it was. Results carried a single Shape.

What it is now. Use declaredShapes (the Shapes the version states) and validatedShapes (the Shapes it satisfies, including composed ones). Both hold version-pinned names such as Deal@v3. The removal covers ThingDetail, ThingItem, thing.getMany items, thing.getWithLease, history versions and history's thing, refs items, component owned Things and view.evaluate items. SynthesizedRepoContent.shape becomes declaredShapes / validatedShapes.

ThingDetail allows extra keys, so detail.shapeName still compiles; it is undefined at run time. Search your code for these field names.

shape as an input filter (thing.head(org, repo, { shape: 'Deal' })) is unchanged.

Migration.

// Before
const shape = detail.shapeName
// After
const shapes = (detail.declaredShapes ?? []).map((w) => w.replace(/@v\d+$/, ''))

Token scopes use grants, on input and output

What it was. A scope entry carried allowedMatches and allowedShapes.

What it is now. Restrictions are a list of (paths, Shapes) pairs in grants.

Migration.

// Before
await client.token.create({ name: 'ci', scopes: [
  { resource: 'acme/world', permissions: ['read'], allowedMatches: ['Deal/**'] },
] })
// After
await client.token.create({ name: 'ci', scopes: [
  { resource: 'acme/world', permissions: ['read'],
    grants: [{ allowedMatches: ['**'], allowedShapes: { shapes: ['Deal'] } }] },
] })

Repository exports are format 6, and the delta fold needs formats

What it was. Exports were format 5, and applyRepositoryExportDelta(base, delta) returned rows keyed by durable id.

What it is now.

Migration.

// Before
const current = applyRepositoryExportDelta(base, delta)
// After
const current = applyRepositoryExportDelta(base, delta, {
  base: baseSession.header!.formatVersion,
  delta: deltaSession.header!.formatVersion,
})

stream.append takes new-grammar operations only

What it was. stream.append took the old operation form.

What it is now. It takes new-grammar operations and does not accept keepShapes (use createKeepShapesResolver). Its only local check is a pinned Shape; everything else is checked by the server.

Migration. Send { operation, name, shapes, data } operations.

Writes need a server running this release

What it was. The SDK wrote to any current server.

What it is now. Against an older server, writes fail the compatibility check with "@warmhub/sdk-ts requires write contract 3, but the backend provides 2."

Migration. Upgrade the SDK after the server.

Added

Behavior worth knowing

Changed

Removed