[go: up one dir, main page]

LDkit

LDkit

Linked Data query toolkit
for TypeScript developers

npm i ldkit

1. Create data schema

Specify entities to retrieve and their properties. Various data types, optional properties, arrays and language annotated literals are supported.

import { dbo, rdfs, xsd } from "ldkit/namespaces";

const PersonSchema = {
  "@type": dbo.Person,
  name: rdfs.label,
  abstract: dbo.abstract,
  birthDate: {
    "@id": dbo.birthDate,
    "@type": xsd.date,
  },
} as const;

2. Set up data source

Use a SPARQL query endpoint, or any other RDF data source.

import { type Options, setGlobalOptions } from "ldkit";

const options = {
  sources: ["https://dbpedia.org/sparql"],
} satisfies Options;

setGlobalOptions(options);

3. Fetch data!

Convert data Schema to a Lens and fetch data with one line of code. Data gets transformed from RDF to native TypeScript automatically.

import { createLens } from "ldkit";

const Persons = createLens(PersonSchema);

const adaIri = "http://dbpedia.org/resource/Ada_Lovelace";
const ada = await Persons.findByIri(adaIri);

console.log(ada.name); // Ada Lovelace
console.log(ada.birthDate); // Date object of 1815-12-10

Read the documentation

Next-gen RDF abstraction

Query RDF data from any source effortlessly.

First class TypeScript

Best in class developer experience. Fully typed workflow.

Deploy anywhere

LDkit runs in browser, Deno and Node.

RDF/JS compliant

Compatible or built upon all the popular RDF/JS libraries