# 5.8 Assembly and connections

> Contract 2.0.0 · package sha256 `a857eca95b35921109faf997094bb4192f12527d9d0fcd4be7e97f06425bad6e` · generated from `examples/section-5/5.08-assembly-and-connections.ts` by `services/onsite-scripter/scripts/build-contract-docs.mjs`; edit the source, not this file.

Imports: values (`has`, `validate`, the `Holo*Error` classes, the pure helpers) from `@holostep-configurators/runtime-client`, types from `@holostep-configurators/runtime-client/contract`, `/math` and `/testing` names from those entries; `boot` from the runtime module the root's `loadRuntimeAtFloor` resolves to. A type your page defines is your app's: declare it there, never import it from the package.

```ts
import type { Connection, DeepReadonly, IModelNode, SceneModel, Session } from '@holostep-configurators/runtime-client/contract';
declare const session: Session;
declare const signal: AbortSignal;
declare const assetBaseUrl: string;
declare const element: IModelNode;                                  // the new element, with its nodeId
declare const anchorId: string;                                     // the element it attaches to
declare function withElement(model: DeepReadonly<SceneModel>, element: IModelNode): SceneModel;
declare function price(connections: readonly Connection[]): void;
const r = await session.transaction(async (tx) => {
  const model = tx.getSceneModel();
  if (!model) throw new Error('no model yet');                         // null before the first model: guard, never `!`
  await tx.setSceneModel(withElement(model, element), { assetBaseUrl });   // staged and loaded, hidden
  const a = await tx.assembly.attach(element.nodeId, { from: 'mp-left', to: { node: anchorId, connector: 'mp-right' } });
  if (!a.attached) throw new Error(a.reason);                          // 'occupied', 'rejected', …; everything rolls back
  return tx.assembly.connections();
}, { undo: 'Add element', expectRevision: session.revision, origin: 'golf-ui' });
if (r.outcome === 'committed') price(r.value);                         // the union narrows: no `!`
```

Back to [the examples](README.md) · [llms.txt](../llms.txt)
