Skip to content

Migrating from src/api.ts to the workbench API

src/api.ts (the re-export barrel) and src/model-api.ts were removed when the workbench API landed. Nothing was deprecated first: the pre-1.0 policy in the stability policy allows a breaking change with a CHANGELOG entry, and this is it. This page maps what you used to import to where it is now.

What moved

Before Now
import { ModelNode, NodeList, Model, ProjectSummary, ConceptRef, buildSmodelScope, formatValue } from "src/model-api.ts" from "src/workbench-api/model-nodes.ts" (also re-exported by src/workbench-api/index.ts)
Anything else from src/api.ts The module that defines it, below
window.StruktJS.authoring Unchanged keys, plus workbench (the whole API)
The Model Console's model, node, root, roots, nodes, project Unchanged; the console also has workbench

What api.ts re-exported, and where it lives

Symbols Module
node, clone, reId, findById, isNode, isEmpty, EMPTY_HEAD, freshId, ... src/ast.ts
slotValue, descendants, ancestors, parent, isInstanceOf, ... src/model.ts
AstTree, AstNav, nav src/ast-nav.ts
walkNodes, walkConceptHierarchy src/tree-iteration.ts
stronglyConnectedComponents, findCycles, topologicalSort, ... src/graph-util.ts
matchPattern, headMatch, capture, assertStructure, ... src/pattern-match.ts
Language, registerLanguage, getLanguage, allLanguages src/workbench/languages.ts
BaseConcept, ChildSlot, Ref, Prop, conceptMetaFromClass, ... src/base-concept.ts
h, Fragment, Text, Grid, Diagram, Table, ... src/editor-jsx.ts
serializeNode, deserializeNode, hashNode, version store src/node-json.ts, src/node-versions.ts
runChecks, runGenerator*, Evaluator, runTypeChecks, getTypeAtNode, buildSymbolScopeMap, ... their own modules (checker, generator, evaluator, typesystem, scope), or better, the workbench

Calling the tools: through workbench

Where you used to import an engine function to run a tool, call the workbench instead. It adds capability checks, an audit trail, events and one transaction/undo model, and it works the same in a hook, a script, the console and the embed.

Before Now
runChecks(root, lang) workbench.checks.run({ root, lang })
runGenerator(root, lang, errors, files) workbench.generator.text({ root, lang })
runGeneratorPipeline(root, lang) workbench.generator.pipeline({ root, lang })
new Evaluator(lang, opts).evaluate(root) await workbench.run.run({ root, lang }) (a cancellable task)
runTypeChecks(root, lang) / getTypeAtNode(root, lang, id) workbench.types.check(...) / workbench.types.typeOf(id, ...)
parseSurface(text, ctx) / surfaceFromAst(node) workbench.surface.parse(text, { lang }) / workbench.surface.print(node, { lang })
findVariableUsages(root, name, lang) workbench.scope.variableUsages(name, { root, lang })
buildSmodelScope({ root, lang, ... }) workbench.model.of(roots, { lang }) / workbench.model.active()
Editing a model with an Editor and hand-managed undo workbench.transaction(() => { ... }), workbench.history

Inside a concept hook, ctx.workbench is already there. A hook of language L cannot modify L through it.

Things that behave differently now

  • The fluent ModelNode mutators (set, append, insertBefore/After, replaceWith, delete) edit a model that has no editor in place; they used to refuse. On a statement shown without its invisible ExpressionStatement wrapper, insertBefore/After, replaceWith and delete now act on the wrapper.
  • The API reports a host that lacks a feature with UnavailableError; it does not silently do nothing.
  • API calls are audited and evented. Internal read paths in the UI deliberately still import the engine directly (see the dogfooding ratchet in the design doc).