Outside React
Build an LDKit lens with createTypedLens outside a component.
What it is
createTypedLens returns the LDKit lens the React hooks use. In a component, those hooks are on
Schemas and LDKit.
Import
import { createTypedLens } from "@manta-eu/react/engine";
Example
import { createTypedLens } from "@manta-eu/react/engine";
import { YourSchema } from "./.ldkit/your-namespace";
const lens = createTypedLens(YourSchema, {
sparqlEndpoint: "https://app.hiremanta.com/d/your-datastore/sparql",
});
const entities = await lens.find();
The fetch sends cookies (credentials: "include") and any headers you pass.
Request
createTypedLens(schema, {
sparqlEndpoint, // string, required
language, // string, optional
logQuery, // (query: string) => void, optional
headers, // Record<string, string>, optional
});
sparqlEndpoint is the SPARQL URL. For a datastore on the default API that URL is
https://app.hiremanta.com/d/<datastore-id>/sparql. headers can carry x-manta-datastore when the endpoint is the
deployment’s /sparql path.
Response
The return value is LDKit’s Lens<S>. A read resolves to entities of the schema, each with $id and the schema’s
properties.
lens.find({ where?, take?, skip? }); // Promise<entity[]>
lens.findOne(where?); // Promise<entity | null>
lens.findByIri(iri); // Promise<entity | null>
lens.findByIris(iris); // Promise<entity[]>
lens.count({ where?, max? }); // Promise<number>
find() with no take uses LDKit’s default limit of 1000. count() with no max counts every match. The lens also has
query, insert, insertData, update, delete, and deleteData.