-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Systematize types for documents and links between them #318
Comments
For compositional modeling, we will want to:
Do you have an idea of how this fits in with your proposal for links? |
I hadn't seen this when working on #332 but was thinking of doing a much less sophisticated version while working on that, so I'm glad it's coming to the fore from multiple directions.
|
Thanks both for these comments! I'm getting back to this now as I seek to pin down and then implement these changes before the v0.2 release. Responding to @olynch's comments:
Absolutely. My thinking for putting the
Thanks for this reminder. This is very important but was omitted in my first attempt in the OP. I will address this in my next attempt below. |
Responding to @KevinDCarlson's comments:
I'm on board with adding a name/title to the base I can't think of any other user-specified "universal" fields for documents. Can you?
It is not at all thought out. I was thinking that, even before getting to cross-repo references, it would be useful to have this in conjunction with your import/export functionality so that there is a record of where stuff came from. E.g., if you try to import a diagram pointing at model in
See my updated proposal below.
Right.
I was thinking that the source of the link is implicitly the document that contains the link declaration, while the target of the link is the document explicitly given in the link. Just like links in the World Wide Web! |
OK, here is v2 of my proposal: interface Document<T extends string> {
/** Unique identifier of the document ref in the database. */
"@id": UUID;
/** Type of the document, such as "model" or "analysis". */
"@type": T;
/** Human-readable name of document. */
name?: string;
}
/** A link between documents. */
interface Link<T extends string> {
/** Unique identifier of the target document. */
"@id": UUID;
/** Repository to which the target document belongs. */
"@repo": string;
/** Version of the target document.
If null, refers to the head snapshot of document and thus the linked document is "live."
*/
"@version": string | null;
/** Type of the link, such as "diagramIn" or "analysisOf" .*/
"@type": T;
} At this stage, I am imagining that versions are a thing that we will be (optionally) attached to snapshots of a document, but I'm not committing to what a version will be, besides being representable as a string. It could be another UUID, it could be a version number, it could be a "SemVer" string if we think that even makes sense in this context. |
What about publicity and permissions fields on a general document? Also, it seems a little funny that the document type and link types are just any stringy thing. Wouldn’t it be nicer to have them be terms of an enum we extend as needed, or is that inapplicable for some reason here? Are we anticipating user-generated new whole types of docs or links? I suppose if we implement a theory of document graphs, maybe users will be modifying this on their own, but it feels a little far-fetched… Otherwise I feel good! |
This information is stored in the database outside the JSON blob comprising the document, so there's no need to put it into the document itself. If anything, it's risky to do so since any information stored in two places can easily become inconsistent.
Good point, and I might do something like that while resolving this issue if it feels natural. Fortunately, though, whether the type fields are arbitrary strings or a TypeScript enum of allowed strings is a matter solely concerning the frontend type defs and does not affect how the data is stored as JSON in the DB. So I'm much less worried about pinning that down right now since we can change it later without touching the data itself. |
We now have several different kinds of documents, such as model documents, diagram documents, and analysis documents. All of these documents are JSON-able and stored as document
refs
in the database. Moreover, there can be links/references/foreign keys between them. For example, a diagram references the model that it is a diagram in. These links need not be at the top-level of the JSON. Soon models will be able to import other models using special cells in the notebook.In preparation for the v0.2 release, I would like to better systematize the notions of document and link in the hopes of avoiding breaking changes or ad hoc workarounds later.
In the original Node backend, @olynch had a notion of
extern
references in documents. I removed it when I rewrote the backend in Rust (#211) because we weren't using it for anything yet and so I wasn't sure whether/how I should re-implement it. However, it persists in the frontend type defs asExternRef
. I'd like to bring something like this back.Working design
Certain special JSON keys, prefixed by the
@
symbol, will be recognized by the backend and hoisted into a typed graph (actually, I would rather think of it as a model of some double theory) in the SQL DB. The objects will be documents:Before a document is stored in a JSONB column, these special keys will be stripped and stored in their own columns.
The arrows will be links:
The database will have a new
links
table into which the special keys are hoisted. Note that@type
here is the type of the link, not of the target document.For example, the document type for a diagram will look like:
with a typical instance:
Prior art
People have obviously thought about linking JSON before. In fact, I was rather annoyed that this wasn't properly standardized a decade ago. The best known candidates are:
The text was updated successfully, but these errors were encountered: