Migrating a plugin to named references¶
Concepts, slots, interfaces and models are no longer written as text. Where a plugin used to pass "invoiceLine" it now passes the thing itself, and a name that
resolves to nothing is an error you see as you type. Nothing is deprecated first: the pre-1.0 stability policy allows the
break, and an old call fails with an error that names the fix.
In short
- A call into the model API (
model.nodes,node.set, ...) refuses a concept or slot written as text. In a script writemodel.resolve("concept", "invoiceLine"); in the Model Console writeconcept.invoiceLine; in TypeScript useConceptRefandSlotRef. - In a concept file, a slot is typed with the class or interface itself:
ChildSlot({ type: IExpression }),Ref({ target: Symbol }). - Three codemods do the common rewrites. Run each without
--writefirst. - A concept you rename declares
renamedFrom; saved models upgrade on open and a model from a newer language is refused.
What the error says¶
A call that still passes text fails at once, and the message gives the replacement:
| You wrote | The error tells you to write |
|---|---|
model.nodes("invoiceLine") |
concept.invoiceLine in the console, or model.resolve("concept", "invoiceLine") in a script |
node.set("content", v) |
concept.<concept>/content in the console, or model.resolve("slot", "<concept>/content") in a script |
model.countBy("concept"), select("price") |
concept (the node's concept) or concept.<concept>/<slot>, or a function in a script |
A refactoring or a migration written as a decorated method is a script: node.set(model.resolve("slot", "formText/content"), content + word).
A reference that names nothing is flagged in the editor, with a quick fix that suggests the nearest names.
Concept files¶
Type a slot with the identifier, imported like any other binding. A concept of the same plugin comes from its sibling file, an interface from languages/interfaces.js
or the platform's src/concept-interfaces.ts:
import { IExpression } from "../../../src/concept-interfaces.ts";
import { Transition } from "./transition.concept.js";
export class State extends Concept() {
transitions = ChildSlot({ type: Transition, cardinality: "0..n" });
condition = ChildSlot({ type: IExpression });
}
An engine kind word stays a string ("name", "code", "string", "number", "boolean", "symbol"), and so does a concept of another plugin, because a plugin may not import
a sibling plugin's files. upgradeOnEquals, upgradeOnRepeat and reshapeOnEquals.toHead take a class the same way.
A class's head is its head field, a head() method, or its class name with the first letter lowered; the identifier and the string name the same concept, so a saved language
and your goldens do not change.
The codemods¶
| Command | Rewrites |
|---|---|
node scripts/codemod-slot-type-identifiers.mjs [--write] <plugin> |
type: "IExpression" and the legacy "expression"/"statement" words to the interface identifier, with the import |
node scripts/codemod-slot-concept-identifiers.mjs [--write] <plugin> |
type: "transition", target: "symbol"-style concept names to the class of the same plugin, with the import |
node scripts/codemod-strict-references.mjs [--write] <file>... |
calls into the model API in test files that pass text, to the cref/sref/conceptKey helpers of tests/test-utils.mjs |
Each is idempotent. The third does not touch program text inside a string (a console line, a generator script): the parser sees a string there, so migrate that by hand.
tests/test-no-string-names-in-api-calls.mjs and tests/test-no-string-slot-concept-types.mjs fail on what is left.
Renaming a concept¶
Declare the old heads on the class and bump the language version; the upgrade needs no hand-written step:
export class Add extends Concept() {
renamedFrom = ["plus", { head: "sum", version: 3 }];
}
An entry without a version applies to any older model; one with a version runs with that version's step. A program that still writes concept.plus gets
it was renamed to "add" in version 3; write concept.add. Other changes to a saved shape (a name that became a node, a string that became a reference) are a migrations
entry with a transform, and a language version bump.
Saved models¶
A generator script saved with a quoted concept (model.nodes("invoiceLine")) is upgraded the same way: when the mapping's source language has that concept, the string becomes the reference; a name it does not have stays text and is flagged.
A model written before your change is upgraded when it opens. The Messages pane records it once (the language, the versions, the files); the file changes on the first save, as
one diff, and npm run strukts -- migrate --project-dir <dir> does the same headlessly (it reports by default; --write applies it, --check exits non-zero while a root is still pending). A model saved by a newer version of a language than the one installed is
refused with Update the language to open it; it is never guessed at.