Skip to content
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

Closed
wants to merge 13 commits into from
Closed

Conversation

travis
Copy link
Contributor

@travis travis commented Jun 27, 2022

Add functions for serializing a note body as RDF:

Screen Shot 2022-06-27 at 4 52 48 PM

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 an id parameter to individual elements in the Slate JSON (which Plate does by default for some elements). The rdf:List format is better for this than rdf:Seq because rdf:Seq requires predicate names like rdf:_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 to solid-client in the future per inrupt/solid-client-js#1648

travis added 5 commits June 24, 2022 20:55
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
Copy link
Contributor

@ianconsolata ianconsolata left a 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",
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor

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') {
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I tried this and got:
Screen Shot 2022-06-29 at 12 13 15 PM

looks like addUrl doesn't accept a NamedNode?

travis added 8 commits June 27, 2022 21:40
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
@ianconsolata
Copy link
Contributor

Close this PR now that v1 exists? or change this PR to merge v1 into main?

@travis travis closed this Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants