Conversation
The exported json has many features which we ignore in our import procedure because they don't (obviously) map to features of the basic Petri net models. ``` Per-place: colorId, dynamicsEnabled, differentialEquationId, visualizerCode, x, y Per-arc: weight Per-transition: lambdaType, lambdaCode, transitionKernelCode, x, y Top-level: types (token coloring), differentialEquations, parameters, version ```
| type: "model", | ||
| theory: "petri-net", | ||
| name: title, | ||
| version: currentVersion(), |
There was a problem hiding this comment.
A more future proof way would be to set this to "1" explicitly and call migrateDocument on the object before returning. That way we don't accidentally break this when bumping the schema.
There was a problem hiding this comment.
i don't have strong feelings about this, only to say that i hope that by the time the schema changes the way that we interop with petrinaut is not via parsing some fraction of their json schema and converting it to our notebook schema :)
epatters
left a comment
There was a problem hiding this comment.
Thanks, this is great. Just a few small comments below.
| } from "catlog-wasm"; | ||
|
|
||
| /** Detects a Petrinaut-exported JSON file. */ | ||
| export function isFromPetrinaut(data: unknown): boolean { |
There was a problem hiding this comment.
This is a typical use case for type predicates: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
So the signature of this function would become:
export function isFromPetrinaut(data: unknown): data is PetrinautFile {| } | ||
|
|
||
| /** Converts a Petrinaut-exported JSON file to a CatCoLab petri-net model document. */ | ||
| export function convertFromPetrinaut(data: unknown): Document { |
There was a problem hiding this comment.
With the above change, you can give this function the desired signature and avoid an explicit type in the function body:
export function convertFromPetrinaut(data: PetrinautFile): Document {| } | ||
|
|
||
| const cellOrder: string[] = []; | ||
| const cellContents: Record<string, NotebookCell<ModelJudgment>> = {}; |
There was a problem hiding this comment.
It's not too important, but I'd suggest using the helpers in NotebookUtils like newNotebook and appendCells instead of directly manipulating cellOrder/cellContents.
There was a problem hiding this comment.
I know this code isn't intended to stick around for a long time (famous last words), but this folder still feels like the wrong place for it. Perhaps src/model/ or src/stdlib/ instead?
The exported json has many features which we ignore in our import procedure because they don't (obviously) map to features of the basic Petri net models.