Repository navigation
Conversation
An id is readable and written in the case of its kind: PascalCase for what is drawn or defined, snake_case for what is read as a value. It holds 32 characters at most and is never a word code reads as something else. `validateEntityId` says whether a text is an id of a kind and why not, `formatEntityId` writes any text as one, `uniqueEntityId` numbers an id a net already has, and `newEntityId` gives the id a new entity starts with. Nothing uses them yet.
…ments Places, transitions, component instances, fusions, token types, differential equations and components take a PascalCase id. Parameters, metrics, scenarios, token attributes and scenario parameters take a snake_case id. The id is what structure and code both refer to, and no object keeps a name beside it except a parameter, whose name stays as a label. - An id is unique within its net, across kinds. A document with an invalid or shared id is reported by checkEntityIds, is not valid for checkSDCPN and does not build a simulation. - renameEntity changes an id and rewrites every arc, reference and piece of code that names it. - A document saved before this change is detected by its shape and migrated on load: names become ids in the case of their kind, collisions are numbered, and code that read a name is rewritten. The file format version stays 1. - Compiled artifacts of a component's item are keyed by component and item, and a token type is resolved in the net that holds the place, since two nets can each hold an object of one id.
… a new dimension at dimension_1
Every field that edited a name edits the id through one rename, which the selection and the open net follow. Id problems are listed in Diagnostics and keep a simulation from starting.
The migration cut a name over 32 characters mid-word and numbered the ids that collided. Each such id is replaced by whole words through Core's rename, so arcs, references and code follow, and the descriptions that cite a renamed parameter name it by its new id.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
Comment on lines
+190
to
+193
| return new RegExp( | ||
| `(?:\\.|["'\`])${escaped}(?![A-Za-z0-9_$])|(?<![A-Za-z0-9_$.])${escaped}\\s*[:,}]`, | ||
| "u", | ||
| ).test(code); |
Comment on lines
+190
to
+193
| return new RegExp( | ||
| `(?:\\.|["'\`])${escaped}(?![A-Za-z0-9_$])|(?<![A-Za-z0-9_$.])${escaped}\\s*[:,}]`, | ||
| "u", | ||
| ).test(code); |
| tokens.push({ kind: "other", from, to: position }); | ||
| } else if (wordStart.test(char)) { | ||
| let index = position + 1; | ||
| while (index < code.length && wordPart.test(code[index]!)) { |
| }); | ||
| } else if (/[0-9]/u.test(char)) { | ||
| let index = position + 1; | ||
| while (index < code.length && /[0-9A-Za-z_.]/u.test(code[index]!)) { |
| jsx && | ||
| char === "<" && | ||
| (code[position + 1] === ">" || | ||
| wordStart.test(code[position + 1] ?? "")) && |
| return false; | ||
| } | ||
| index += 1; | ||
| while (index < code.length && wordPart.test(code[index]!)) { |
|
|
||
| /** A name as a property after a dot, or in brackets where it is no identifier. */ | ||
| const asMember = (name: string, quote = '"'): string => | ||
| identifier.test(name) ? `.${name}` : `[${quote}${name}${quote}]`; |
Comment on lines
+215
to
+221
| const formatted = formatEntityId(kind, desired); | ||
| const isFree = (candidate: string) => | ||
| !taken.has(candidate) && !isReservedEntityId(candidate); | ||
| if (isFree(formatted)) { | ||
| return formatted; | ||
| } | ||
| const numbered = /^(.*?)(_?)(\d+)$/u.exec(formatted); |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Caution
Breaking file format change
Each object of a net has one readable
idand noname. A parameter keepsnameand losesvariableName.Files and stored documents in the older shape load and are migrated.
A build without this PR rejects a file saved by this one.
Summary
Before this PR, each object of a net had an
idand aname. Arcs, scenarios and selections referenced the id, a UUID. Code read the name. A parameter had a third one,variableName.This PR gives each object one id that arcs, references and code all read. An id is at most 32 characters, in the case of its kind, and unique within its net. Renaming an object rewrites every arc, reference and piece of code that names it. A net with a duplicate or malformed id does not run, and Diagnostics lists the problem. A document's own id stays a UUID.
RawMaterialinfection_rateFile format
idholds whatnameheld, in the case of the kind, andnameis gone from every object but a parameter. A parameter'sidholds whatvariableNameheld. A dimension hasidin place ofelementIdandname, and a scenario parameter hasidin place ofidentifier. Arcs, initial states, parameter overrides and code name an object by itsid.Example: one net saved by a build without this PR, then by this one
Loading: older files are migrated, and a build without this PR rejects new ones
versionstays1Links
Changes
Ids: one case per kind, 32 characters, unique within a net
Rename: one mutation changes an id and everything that names it
renameEntitymutationChecks: a net with an id problem does not run
checkEntityIdslists duplicate and malformed ids of a documentMigration: older documents get ids from their names on load
migrateLegacyEntityIdsruns for files, stored documents and Actual mode recordingsmigrateSDCPNis exported for hosts that store documentsEditor: ids on the canvas and in every list, edited in an ID field
renameEntitygetItemTypetakes the net it looks inBrunch agent, flow nets and website: move to ids, with a rename tool
renameEntitymutation and apetrinaut_rename_entitytoolquery_basisselects an object by its id aloneKnown issues
More: scenario parameters, libraries, manifests, fusions
metadata.idstable of a flow net as it wasNext steps
Test coverage
Core: grammar, uniqueness, rename, migration, file round trip
validation/entity-id.test.ts,validation/check-entity-ids.test.ts:document/entity-ids.test.ts,document/rewrite-code-references.test.ts:file-format/legacy/migrate-legacy-entity-ids.test.ts:file-format/parse-sdcpn-file.test.ts,serialize-sdcpn.test.ts,sdcpn-input.test.ts:clipboard/paste.test.ts:main:Editor and dependents: rename hook, diagnostics, Brunch, flow nets
react/editing/use-rename-entity.test.tsx:diagnostics/entity-id-diagnostics.test.tsx,entity-id-selection.test.ts:views/Notebook/notebook-view.test.tsx:@hashintel/brunch-agent,@apps/brunch-agent,@apps/petrinaut-website,@local/flow-petri-netand the Brunch integration tests, moved to idsHow to test
Rename: an id changes everywhere, a bad one is refused
RawMaterialStock> Enterraw material> EnterBadProduct> EnterOlder file: a net saved before this PR opens with ids
Duplicate id: the net does not run
id