How to use jsonld - 10 common examples

To help you get started, we’ve selected a few jsonld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / jsonld / jsonld-tests.ts View on Github external
const docNQuads =
   `_:  "Manu Sporny" .
    _:   .
    _:   .`;

const context = {
    name: "http://schema.org/name",
    homepage: {"@id": "http://schema.org/url", "@type": "@id"},
    image: {"@id": "http://schema.org/image", "@type": "@id"}
  };

const baseUrl = 'http://schema.org';

const frame = doc;

const docRDF = jsonld.toRDF(doc);

let count = 0;
function log(doc: object|string) {
    count++;
    // Uncomment if testing with node.js
    if (typeof doc === 'object') {
        // console.log(count + ": " + JSON.stringify(doc) + "\n");
    } else {
        // console.log(doc);
    }
}

/**
 * compact() test
 */
jsonld.compact(doc, context, (err, compDoc) => {
github wikibus / Alcaeus / tests / Resources / ApiDocumentation-spec.ts View on Github external
it('should reject if entrypoint missing', async () => {
            // given
            const apiDoc = Object.assign({}, Documentations.classWithOperation)
            delete apiDoc.entrypoint
            const expanded = await jsonld.compact(apiDoc, {})
            const docs = new ApiDocumentation(fakeAlcaeusResources(expanded))
            alcaeus.loadResource.returns(Promise.resolve(null))

            // when
            try {
                docs.loadEntrypoint()
                    .then(() => {
                        throw new Error('Operation should not succeed')
                    })
            } catch (e) {
                throw new Error('Should not throw unhandled exception')
            }
        })
    })
github wikibus / Alcaeus / tests / Resources / DocumentedResource-spec.ts View on Github external
it('should use hydra:description for title property', async () => {
        // given
        const compacted = await jsonld.compact(hydraDescriptionJsonLd, {})

        // when
        const op = new DocumentedResource(compacted)

        // then
        expect(op.description).toBe('The longer description')
    })
github wikibus / Alcaeus / tests / Resources / Class-spec.ts View on Github external
it('should return operations', async () => {
            // then
            const compacted = await jsonld.compact(hydraClass, {})

            // when
            const clas = new Class(compacted)

            // then
            expect(clas.supportedOperations.length).toBe(1)
        })
github wikibus / Alcaeus / tests / Resources / RdfProperty-spec.ts View on Github external
it('should link to domain', async () => {
        // given
        const compacted = await jsonld.compact(testProperty, {})

        // when
        const property = new RdfProperty(compacted)

        // then
        expect(property.domain!['@id']).toBe(xsd.integer)
    })
github wikibus / Alcaeus / tests / Resources / SupportedOperation-spec.ts View on Github external
it('should return false for GET operation', async () => {
            // given
            const operation = {
                '@context': Context,
                'method': 'GET',
            }

            const compacted = await jsonld.compact(operation, {})

            // when
            const op = new SupportedOperation(compacted)

            // then
            expect(op.requiresInput).toBe(false)
        })
github wikibus / Alcaeus / tests / Resources / ApiDocumentation-spec.ts View on Github external
it('should return only unique value', async () => {
            // given
            const expanded = await jsonld.compact(Documentations.classWithOperation, {})
            const docs = new ApiDocumentation(fakeAlcaeusResources(expanded))

            // when
            const ops = docs.getOperations('http://example.com/api#UndomcumentedClass')

            // then
            expect(_.isArray(ops)).toBe(true)
            expect(ops.length).toBe(0)
        })
    })
github wikibus / Alcaeus / tests / Resources / SupportedOperation-spec.ts View on Github external
it('should expose operation method', async () => {
        // given
        const compacted = await jsonld.compact(operationJsonLd, {})

        // wehen
        const op = new SupportedOperation(compacted)

        // then
        expect(op.method).toBe('TRACE')
    })
github digitalbazaar / vc-js / tests / 10-verify.spec.js View on Github external
}
  }
  // target not found
  if(!found) {
    const err = new Error('Not Found');
    err.httpStatusCode = 404;
    err.status = 404;
    throw err;
  }

  const context = [
    constants.DID_CONTEXT_URL,
    constants.VERES_ONE_CONTEXT_URL
  ];
  // frame target
  const framed = await jsonld.frame(
    filtered, {'@context': context, id: target}, {embed: '@always'});

  return Object.assign({'@context': context}, framed['@graph'][0]);
}
github digitalbazaar / vc-js / tests / 10-verify.spec.js View on Github external
async function _pluckDidNode(did, target, didDocument) {
  // flatten to isolate target
  jsonld.documentLoader = testLoader.documentLoader.bind(testLoader);
  const flattened = await jsonld.flatten(didDocument);
  // filter out non-DID nodes and find target
  let found = false;
  const filtered = [];
  for(const node of flattened) {
    const id = node['@id'];
    if(id === target) {
      filtered.push(node);
      found = true;
      break;
    }
  }
  // target not found
  if(!found) {
    const err = new Error('Not Found');
    err.httpStatusCode = 404;
    err.status = 404;