-
Notifications
You must be signed in to change notification settings - Fork 0
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
Experimental note body serialization #1
Conversation
mock out fetch enough to get tests working and avoid calling my pod
don't hardcode properties, just pull out everything we can find
developing from the testfile made sense for a while, but this is much better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RDF:list seems right to me too. Looks great! I think this is still WIP based on our chats, though most of the library is still WIP until we get it into Garden. Feel free to merge if you want, or lemme know if you do another pass and want me to take another look.
package.json
Outdated
@@ -44,6 +44,7 @@ | |||
} | |||
], | |||
"devDependencies": { | |||
"@ontologies/core": "^2.0.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why dev deps for this one but not the others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oo I think this is a good catch, thx!
src/note.ts
Outdated
import {arrayToThings, thingsToArray} from "./collections" | ||
|
||
const noteNSUrl = "https://mysilio.garden/ontologies/note#" | ||
const noteNS = createNS(noteNSUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use @rdf-esm/namespace
for this:
import namespace from '@rdf-esm/namespace
See src/vocab
for example usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter much which one we use, I don't think, because they both build NamedNodes. I think I even came across the @ontologies one, might be by the same guy?
for (const pred in thing.predicates) { | ||
const [, key] = pred.split(noteNSUrl) | ||
if (key) { | ||
if (key === 'children') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not instead test to see if pred === childrenPred.value
or pred === noteNS('children').value
?
To me that reads a little cleaner than splitting on the predicate namespace.
const obj: any = {} | ||
for (const pred in thing.predicates) { | ||
const [, key] = pred.split(noteNSUrl) | ||
if (key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed the if (key)
-- when would key not exist? If the predicate isn't in our NS? That might explain why you match on key below instead of the predicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yep! this is expecting that there might be other predicates on the thing and trying to only deal with things in our NS. I'm really not sure about this particular part of the approach - at the very least I need to double check that my namespaces make sense before shipping this, will take another look at this tomorrow!
src/note.ts
Outdated
const thing = createThing({ name: (o.id ? `${o.id}` : `el-${path.join("-")}`) }) | ||
const otherThings = Object.keys(o).reduce((m: Thing[], k: string) => { | ||
const [mThing, ...mRest] = m; | ||
const [thing, ...restOfThings] = addKeyValToThing(mThing, noteNS(k).value, o[k], path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like all the places you use this in the downstream function are Inrupt fns. Those all actually take NamedNodes as well as URLStrings for the predicates, so you don't have to do noteNS(k).value
here, you could just do noteNS(k)
if you wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move vocab-related stuff into vocab.ts and move away from Ontola (ie, @ontologies) libraries there's a subtle incompatibility between the `@ontologies` version of `NamedNode` and the "standard" (ie, rdfjs-base https://github.com/rdfjs-base) versions - the `@ontologies` version doesn't require an `equals` method, so trying to pass `NamedNodes` from that library to the Inrupt libraries doesn't work. Trying to switch would be a big lift for not much work and potentially make us less compatible with `solid-client-js` so I opted to use `@rdfjs/namespace`. Unfortunately the most recent versions of the `@rdfjs` libraries have been converted to ESM modules and are not transpiled to an older version of JS like most NPM libraries, which makes Jest choke at the moment, so I'm following the lead of `solid-client-js` and requiring an older version of this lib. The RDF ecosystem is a smoking wasteland of incompatibility and pain! A real shame because RDF is awesome!
I wanted to use @size-limit/preset-small-lib but there's some weird dependency problem and I don't have the spoons for another trek through npm hell - for now just bump the size limit above the 268k/229k filesizes we have now to get the build working
hoping this fixes the weird build issues I'm seeing
this was originally in garden, moving here to preserve, not ready to merge
use rollup to build the various types of files we need
* create spaces file if it doesn't exist * add MY.Garden.Item type to items
Close this PR now that |
Add functions for serializing a note body as RDF:
Use an
rdf:List
Collection as the format - we'd like to minimize changes during save, and this allows us to keep content subject URLs consistent by adding anid
parameter to individual elements in the Slate JSON (which Plate does by default for some elements). Therdf:List
format is better for this thanrdf:Seq
becauserdf:Seq
requires predicate names likerdf:_1, rdf:_2
to indicate position in the list, which would cause cascading updates for things later in a content array structure.The functions in
collections.ts
are totally abstract and I'm interested in porting them tosolid-client
in the future per inrupt/solid-client-js#1648