How to use the jsonld.promises.compact function in jsonld

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 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 wikibus / Alcaeus / tests / Resources / ApiDocumentation-spec.ts View on Github external
it('should return classes from documentation', (done: any) => {
            jsonld.compact(Documentations.classWithOperation, {}).then((expanded) => {
                const docs = new ApiDocumentation(fakeAlcaeusResources(expanded))

                expect(docs.classes.length).toBe(1)
                expect(docs.classes[0]['@id']).toBe('http://example.com/api#Class')
                done()
            }).catch(done.fail)
        })
github wikibus / Alcaeus / src / Resources.ts View on Github external
compact(context:any = null) {
        return jsonld.compact(this, context || Core.Context);
    }
}