digitalbazaar / cborld

A Javascript CBOR-LD processor for web browsers and Node.js apps.
https://json-ld.github.io/cbor-ld-spec/
BSD 3-Clause "New" or "Revised" License
21 stars 17 forks source link

`@vocab` not implemented #56

Closed OR13 closed 3 months ago

OR13 commented 2 years ago
import { encode, documentLoader } from "@digitalbazaar/cborld";

const documentLoader = (iri: string) => {
  if (iri === "https://www.w3.org/ns/activitystreams") {
    return {
      document: {
        "@context": {
          "@version": 1.1,
          "@vocab": "https://www.w3.org/ns/activitystreams#",
        },
      },
    };
  }
  console.log(iri);
  throw new Error("iri not supported");
};

const jsonldDocument = {
  "@context": "https://www.w3.org/ns/activitystreams",
  type: "Note",
  summary: "CBOR-LD",
  content: "CBOR-LD is awesome!",
};

it("can compress linked data", async () => {
  const cborldBytes = await encode({ jsonldDocument, documentLoader });
  console.log(cborldBytes);
});

ERR_UNKNOWN_CBORLD_TERM: Unknown term 'content' was detected in the JSON-LD input.

dlongley commented 2 years ago

Yeah, @vocab isn't currently supported, but I expect that we'll want to figure out if we can support it in some way (i.e., either with or without compression for keys that depend on it).

msporny commented 2 years ago

Looks like we're throwing here... when we shouldn't be (when @vocab is used): https://github.com/digitalbazaar/cborld/commit/b93b15ff9ab9abf30edeb91163f25a330384f958#diff-e4a9d890818b54410ff95248f37a9769a93e2f409ec7fb3c090c4c1db48b062eR124-R128

We should detect when @vocab is active and NOT throw... just leave the term as-is (string).

OR13 commented 2 years ago

I made an ipld middleware that will convert from a context that has a vocab to one that does not, and it works... but its pretty hacky... https://github.com/OR13/binary-linked-data/blob/main/deeply-nested-sadness.test.js

dlongley commented 2 years ago

@msporny,

We should detect when @vocab is active and NOT throw... just leave the term as-is (string).

At present, all terms must be transformed to term IDs (integers), so there's no "leaving a term as-is (string)". We would have to explore whether that approach is viable.

dlongley commented 3 months ago

Since 7.x all terms that do not have their own term definitions in the context will "pass through" (be left as a string), so this is now covered, closing.