Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'jsonld' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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) => {
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')
}
})
})
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')
})
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)
})
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)
})
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)
})
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)
})
})
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')
})
}
}
// 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]);
}
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;