Docmaps-Project / docmaps

Extensible protocol for document history metadata exchange, to enable trustworthy, rapid, open science, by and for preprint science communities.
MIT License
15 stars 1 forks source link

fix(ts-sdk): Enable framing to work with single-step docmaps #120

Closed ships closed 11 months ago

ships commented 11 months ago

Description

The JSON-LD Framing algorithm accepts a frame that we have been supplying by default to consumers of this library. This PR fixes issue with the default frame so that it is more generic.

It turns out that the default frame fails to serialize Docmaps that have only one step to date, because Framing is designed for both filtering and shaping. The keys in a frame can be supplied iwth values to "select" on. By providing shape information in the steps' next-step and previous-step sub-frames, we implicitly tell the framing algorithm to "only match Steps if they have one of these keys" because otherwise the frame for "hasStep" finds no matches. There is no way to specify subframes but "allow zero matching properties".

However, we can circumvent this limitation by disabling requireAll, which allows matching if ANY property is present and matching, while still enforcing the shaping-related rules when those keys are there. This we match on properties all steps are guaranteed to have. The only such property is @id (even though this should be a blank node id).

Related Issues

List any issues that are related to this pull request, such as bug reports or feature requests.

Checklist

Additional Information

see info about @requireAll . It is unclear what the default value is so I specify it manually as false.

the omitEmpty is probably a good thing anyway and makes the fromNullable usages unnecessary.