Alcaeus
Alcaeus copied to clipboard
Question: What is the best method for retrieving supported properties from memberAssertion?
So, this might tie into my earlier question about apiDocumentation
(https://github.com/hypermedia-app/Alcaeus/issues/259). I'm currently attempting to map from memberAssertion
to supported properties
. How is this expected to be done in Alcaeus?
If I understood correctly, you'd want to do smth like finding the supported properties of types used in member assertion?
Here's an example using Alcaeus' object model
const client = require("[email protected]/node").Hydra
const { rdf } = require('@tpluscode/rdf-ns-builders')
const { representation: { root: collection } } = await client.loadResource('https://always-read-the-plaque.herokuapp.com/plaques');
const apiDoc = client.apiDocumentations[0].root
// find hydra:object of member assertions for rdf:type
const types = collection.memberAssertion
.filter(ma => ma.property.equals(rdf.type))
.map(ma => ma.object)
// create a map of [type URI, properties]
types.map(type => {
const typeResource = apiDoc.supportedClass.find(sc => sc.equals(type))
return [type.id, typeResource ? typeResource.supportedProperty : []]
})
This returns empty in the example because of subclassing. The supported class is a subclass of the type from member assertion
RunKit: https://runkit.com/embed/k03op2du1o4h
Alternatively you can use clownface. IT is a good way to traverse the graphs that way
const client = require("[email protected]/node").Hydra
const { rdf, hydra } = require('@tpluscode/rdf-ns-builders')
const { representation: { root: collection } } = await client.loadResource('https://always-read-the-plaque.herokuapp.com/plaques');
const apiDoc = client.apiDocumentations[0].root
let types = collection.pointer
.out(hydra.memberAssertion)
.has(hydra.property, rdf.type)
.out(hydra.object)
.terms
types.map(type => {
return [type, apiDoc.pointer
.node(type)
.out(hydra.supportedProperty)
.toArray()]
})
RunKit: https://runkit.com/embed/275daycyc1iz
Does this help? Could you explain some more, what is the usage scenario and desired outcome?