ldkit 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +113 -3
- package/esm/library/decoder.js +0 -5
- package/esm/library/namespaces/dbo.js +3650 -0
- package/esm/library/namespaces/dc.js +22 -0
- package/esm/library/namespaces/foaf.js +70 -0
- package/esm/library/namespaces/gr.js +176 -0
- package/esm/library/namespaces/mod.js +7 -2
- package/esm/library/namespaces/sioc.js +106 -0
- package/esm/library/resource/resource.js +4 -4
- package/package.json +1 -1
- package/script/library/decoder.js +0 -5
- package/script/library/namespaces/dbo.js +3652 -0
- package/script/library/namespaces/dc.js +24 -0
- package/script/library/namespaces/foaf.js +72 -0
- package/script/library/namespaces/gr.js +178 -0
- package/script/library/namespaces/mod.js +15 -5
- package/script/library/namespaces/sioc.js +108 -0
- package/script/library/resource/resource.js +4 -4
- package/types/library/namespaces/dbo.d.ts +3649 -0
- package/types/library/namespaces/dc.d.ts +21 -0
- package/types/library/namespaces/dcterms.d.ts +18 -18
- package/types/library/namespaces/foaf.d.ts +69 -0
- package/types/library/namespaces/gr.d.ts +175 -0
- package/types/library/namespaces/mod.d.ts +7 -2
- package/types/library/namespaces/rdf.d.ts +2 -2
- package/types/library/namespaces/rdfs.d.ts +4 -4
- package/types/library/namespaces/schema.d.ts +261 -261
- package/types/library/namespaces/sioc.d.ts +105 -0
- package/types/library/namespaces/skos.d.ts +3 -3
- package/types/library/namespaces/xsd.d.ts +3 -3
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,117 @@
|
|
|
1
|
-
# LDkit
|
|
1
|
+
# LDkit - Linked Data for TypeScript developers.
|
|
2
2
|
|
|
3
|
-
Linked Data query toolkit for TypeScript developers.
|
|
3
|
+
**LDkit** is **Linked Data** query toolkit for **TypeScript** developers. It
|
|
4
|
+
provides ORM-like abstraction over [RDF](https://www.w3.org/RDF/) datasources.
|
|
5
|
+
You define the data model and then you can retrieve or update data without any
|
|
6
|
+
extra hustle. LDkit will generate SPARQL queries, retrieves RDF data and
|
|
7
|
+
converts them to TypeScript native types.
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
## 💣 Key Features
|
|
6
10
|
|
|
11
|
+
- Next-generation ORM-like [RDF](https://www.w3.org/RDF/) abstraction.
|
|
12
|
+
- Retrieve and update data using reusable data models.
|
|
13
|
+
- Compatible with [Comunica](https://comunica.dev) query engine (you can even
|
|
14
|
+
write your own!).
|
|
15
|
+
- 10+ popular ontologies included.
|
|
16
|
+
- First class TypeScript support, best in class developer experience.
|
|
17
|
+
- Runs in browser, [Deno](https://deno.land) and [Node](nodejs.org).
|
|
18
|
+
- ...and more!
|
|
19
|
+
|
|
20
|
+
## 📖 Documentation
|
|
21
|
+
|
|
22
|
+
The [documentation](https://ldkit.io/docs) and examples are available on
|
|
7
23
|
[ldkit.io](https://ldkit.io).
|
|
24
|
+
|
|
25
|
+
## 🚀 Getting Started
|
|
26
|
+
|
|
27
|
+
If you are using Node, then you can install LDkit using your favourite package
|
|
28
|
+
manager.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm i ldkit
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For Deno environment, you can import LDkit like this:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import * as ldkit from "https://deno.land/x/ldkit/mod.ts";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Set up RDF source and create data schema
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { type Context, createResource } from "ldkit";
|
|
44
|
+
import { dbo, rdfs, xsd } from "ldkit/namespaces";
|
|
45
|
+
|
|
46
|
+
// Create a context for query engine
|
|
47
|
+
const context: Context = {
|
|
48
|
+
sources: ["https://dbpedia.org/sparql"], // SPARQL endpoint
|
|
49
|
+
language: "en", // Preferred language
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Create a schema
|
|
53
|
+
const PersonSchema = {
|
|
54
|
+
"@type": dbo.Person,
|
|
55
|
+
name: rdfs.label,
|
|
56
|
+
abstract: dbo.abstract,
|
|
57
|
+
birthDate: {
|
|
58
|
+
"@id": dbo.birthDate,
|
|
59
|
+
"@type": xsd.date,
|
|
60
|
+
},
|
|
61
|
+
} as const;
|
|
62
|
+
|
|
63
|
+
// Create a resource using the data schema and context above
|
|
64
|
+
const Person = createResource(PersonSchema, context);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### List all available data
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
// List all persons
|
|
71
|
+
const persons = await Person.find();
|
|
72
|
+
for (const person of persons) {
|
|
73
|
+
console.log(person.name); // string
|
|
74
|
+
console.log(person.birthDate); // Date
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Get total count of all persons
|
|
78
|
+
const count = await Person.count();
|
|
79
|
+
console.log(count); // number
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Get a particular entity
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
// Get a particular person identified by IRI
|
|
86
|
+
const ada = await Person.findByIri("http://dbpedia.org/resource/Ada_Lovelace");
|
|
87
|
+
console.log(ada?.name); // string "Ada Lovelace"
|
|
88
|
+
console.log(ada?.birthDate); // Date object of 1815-12-10
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Data manipulation - insert, update and delete
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// Insert a new person
|
|
95
|
+
Person.insert({
|
|
96
|
+
$id: "http://dbpedia.org/resource/Alan_Turing",
|
|
97
|
+
name: "Alan Turing",
|
|
98
|
+
birthDate: new Date("1912-06-23"),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Modify a person's name
|
|
102
|
+
Person.update({
|
|
103
|
+
$id: "http://dbpedia.org/resource/Alan_Turing",
|
|
104
|
+
name: "Not Alan Turing",
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Delete a person
|
|
108
|
+
Person.delete("http://dbpedia.org/resource/Alan_Turing");
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
More complex examples can be found in [documentation](https://ldkit.io/docs).
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
[MIT License](./LICENSE.md)
|
|
116
|
+
|
|
117
|
+
Copyright © 2021-present [Karel Klima](https://karelklima.com)
|
package/esm/library/decoder.js
CHANGED
|
@@ -48,14 +48,9 @@ class Decoder {
|
|
|
48
48
|
decode() {
|
|
49
49
|
const output = [];
|
|
50
50
|
for (const [iri, properties] of this.graph) {
|
|
51
|
-
console.warn("IRI", iri);
|
|
52
51
|
if (properties.has(rdf.type)) {
|
|
53
52
|
const types = properties.get(rdf.type);
|
|
54
53
|
for (const type of types) {
|
|
55
|
-
console.warn("TYPE", type.value);
|
|
56
|
-
if (type.value === ldkit.Resource) {
|
|
57
|
-
console.warn("FOUND", type);
|
|
58
|
-
}
|
|
59
54
|
if (type.termType === "NamedNode" && type.value === ldkit.Resource) {
|
|
60
55
|
output.push(this.decodeNode(iri, this.schema));
|
|
61
56
|
}
|