ldkit 1.1.0 → 2.1.0

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.
Files changed (152) hide show
  1. package/README.md +15 -5
  2. package/esm/library/decoder.js +20 -30
  3. package/esm/library/encoder.js +33 -17
  4. package/esm/library/engine/mod.js +2 -2
  5. package/esm/library/engine/query_engine.js +40 -0
  6. package/esm/library/engine/query_engine_proxy.js +8 -8
  7. package/esm/library/engine/types.js +1 -0
  8. package/esm/library/lens/lens.js +416 -27
  9. package/esm/library/lens/mod.js +1 -1
  10. package/esm/library/lens/query_builder.js +86 -52
  11. package/esm/library/lens/search_helper.js +142 -0
  12. package/esm/library/lens/update_helper.js +157 -0
  13. package/esm/library/namespace.js +36 -0
  14. package/esm/library/options.js +50 -0
  15. package/esm/library/schema/data_types.js +3 -38
  16. package/esm/library/schema/search.js +1 -0
  17. package/esm/library/schema/utils.js +31 -6
  18. package/esm/library/sparql/mod.js +2 -1
  19. package/esm/library/sparql/sparql_expression_builders.js +18 -0
  20. package/esm/library/sparql/sparql_query_builders.js +65 -0
  21. package/esm/library/sparql/sparql_shared_builders.js +1 -0
  22. package/esm/library/sparql/sparql_tag.js +27 -1
  23. package/esm/library/sparql/sparql_update_builders.js +70 -0
  24. package/esm/library/sparql/stringify.js +3 -4
  25. package/esm/mod.js +4 -4
  26. package/esm/{library/namespaces → namespaces}/dbo.js +7 -2
  27. package/esm/{library/namespaces → namespaces}/dc.js +7 -2
  28. package/esm/{library/namespaces → namespaces}/dcterms.js +7 -2
  29. package/esm/{library/namespaces → namespaces}/foaf.js +7 -2
  30. package/esm/{library/namespaces → namespaces}/gr.js +7 -2
  31. package/esm/namespaces/ldkit.js +11 -0
  32. package/esm/namespaces/owl.js +91 -0
  33. package/{script/library → esm}/namespaces/rdf.js +7 -4
  34. package/{script/library → esm}/namespaces/rdfs.js +7 -4
  35. package/esm/{library/namespaces → namespaces}/schema.js +7 -2
  36. package/esm/{library/namespaces → namespaces}/sioc.js +7 -2
  37. package/{script/library → esm}/namespaces/skos.js +7 -4
  38. package/{script/library → esm}/namespaces/xsd.js +7 -4
  39. package/esm/namespaces.js +30 -1
  40. package/esm/rdf.js +14 -1
  41. package/esm/sparql.js +13 -0
  42. package/package.json +8 -8
  43. package/script/library/decoder.js +25 -38
  44. package/script/library/encoder.js +38 -24
  45. package/script/library/engine/mod.js +16 -5
  46. package/script/library/engine/query_engine.js +40 -0
  47. package/script/library/engine/query_engine_proxy.js +7 -7
  48. package/script/library/engine/types.js +2 -0
  49. package/script/library/lens/lens.js +417 -29
  50. package/script/library/lens/mod.js +15 -4
  51. package/script/library/lens/query_builder.js +87 -56
  52. package/script/library/lens/search_helper.js +146 -0
  53. package/script/library/lens/update_helper.js +161 -0
  54. package/script/library/namespace.js +40 -0
  55. package/script/library/options.js +56 -0
  56. package/script/library/schema/data_types.js +3 -41
  57. package/script/library/schema/search.js +2 -0
  58. package/script/library/schema/utils.js +33 -11
  59. package/script/library/sparql/mod.js +17 -3
  60. package/script/library/sparql/sparql_expression_builders.js +22 -0
  61. package/script/library/sparql/sparql_query_builders.js +65 -0
  62. package/script/library/sparql/sparql_shared_builders.js +3 -1
  63. package/script/library/sparql/sparql_tag.js +30 -7
  64. package/script/library/sparql/sparql_update_builders.js +70 -0
  65. package/script/library/sparql/stringify.js +4 -8
  66. package/script/mod.js +20 -11
  67. package/script/{library/namespaces → namespaces}/dbo.js +8 -2
  68. package/script/{library/namespaces → namespaces}/dc.js +8 -2
  69. package/script/{library/namespaces → namespaces}/dcterms.js +8 -2
  70. package/script/{library/namespaces → namespaces}/foaf.js +8 -2
  71. package/script/{library/namespaces → namespaces}/gr.js +8 -2
  72. package/script/namespaces/ldkit.js +14 -0
  73. package/script/namespaces/owl.js +94 -0
  74. package/{esm/library → script}/namespaces/rdf.js +10 -2
  75. package/{esm/library → script}/namespaces/rdfs.js +10 -2
  76. package/script/{library/namespaces → namespaces}/schema.js +8 -2
  77. package/script/{library/namespaces → namespaces}/sioc.js +8 -2
  78. package/{esm/library → script}/namespaces/skos.js +10 -2
  79. package/{esm/library → script}/namespaces/xsd.js +10 -2
  80. package/script/namespaces.js +44 -1
  81. package/script/rdf.js +20 -15
  82. package/script/sparql.js +13 -0
  83. package/types/library/decoder.d.ts +4 -3
  84. package/types/library/encoder.d.ts +5 -3
  85. package/types/library/engine/mod.d.ts +2 -2
  86. package/types/library/engine/query_engine.d.ts +50 -9
  87. package/types/library/engine/query_engine_proxy.d.ts +4 -3
  88. package/types/library/engine/types.d.ts +23 -0
  89. package/types/library/lens/lens.d.ts +401 -24
  90. package/types/library/lens/mod.d.ts +1 -1
  91. package/types/library/lens/query_builder.d.ts +11 -11
  92. package/types/library/lens/search_helper.d.ts +21 -0
  93. package/types/library/lens/types.d.ts +5 -2
  94. package/types/library/lens/update_helper.d.ts +23 -0
  95. package/types/library/namespace.d.ts +41 -0
  96. package/types/library/options.d.ts +70 -0
  97. package/types/library/rdf.d.ts +8 -15
  98. package/types/library/schema/data_types.d.ts +44 -37
  99. package/types/library/schema/interface.d.ts +75 -20
  100. package/types/library/schema/mod.d.ts +4 -2
  101. package/types/library/schema/schema.d.ts +23 -16
  102. package/types/library/schema/search.d.ts +20 -0
  103. package/types/library/schema/utils.d.ts +3 -3
  104. package/types/library/sparql/mod.d.ts +2 -1
  105. package/types/library/sparql/sparql_expression_builders.d.ts +19 -0
  106. package/types/library/sparql/sparql_query_builders.d.ts +68 -3
  107. package/types/library/sparql/sparql_shared_builders.d.ts +1 -0
  108. package/types/library/sparql/sparql_tag.d.ts +29 -1
  109. package/types/library/sparql/sparql_update_builders.d.ts +68 -0
  110. package/types/mod.d.ts +5 -6
  111. package/types/namespaces/dbo.d.ts +10 -0
  112. package/types/namespaces/dc.d.ts +10 -0
  113. package/types/namespaces/dcterms.d.ts +10 -0
  114. package/types/namespaces/foaf.d.ts +10 -0
  115. package/types/namespaces/gr.d.ts +10 -0
  116. package/types/namespaces/ldkit.d.ts +10 -0
  117. package/types/namespaces/owl.d.ts +10 -0
  118. package/types/namespaces/rdf.d.ts +10 -0
  119. package/types/namespaces/rdfs.d.ts +10 -0
  120. package/types/namespaces/schema.d.ts +10 -0
  121. package/types/namespaces/sioc.d.ts +10 -0
  122. package/types/namespaces/skos.d.ts +10 -0
  123. package/types/namespaces/xsd.d.ts +10 -0
  124. package/types/namespaces.d.ts +30 -1
  125. package/types/rdf.d.ts +14 -1
  126. package/types/sparql.d.ts +13 -0
  127. package/esm/library/global.js +0 -25
  128. package/esm/library/lens/query_helper.js +0 -102
  129. package/esm/library/namespaces/ldkit.js +0 -6
  130. package/esm/library/namespaces/mod.js +0 -13
  131. package/esm/library/namespaces/namespace.js +0 -11
  132. package/script/library/global.js +0 -32
  133. package/script/library/lens/query_helper.js +0 -106
  134. package/script/library/namespaces/ldkit.js +0 -8
  135. package/script/library/namespaces/mod.js +0 -32
  136. package/script/library/namespaces/namespace.js +0 -15
  137. package/types/library/global.d.ts +0 -5
  138. package/types/library/lens/query_helper.d.ts +0 -19
  139. package/types/library/namespaces/dbo.d.ts +0 -3649
  140. package/types/library/namespaces/dc.d.ts +0 -21
  141. package/types/library/namespaces/dcterms.d.ts +0 -104
  142. package/types/library/namespaces/foaf.d.ts +0 -69
  143. package/types/library/namespaces/gr.d.ts +0 -175
  144. package/types/library/namespaces/ldkit.d.ts +0 -7
  145. package/types/library/namespaces/mod.d.ts +0 -13
  146. package/types/library/namespaces/namespace.d.ts +0 -15
  147. package/types/library/namespaces/rdf.d.ts +0 -28
  148. package/types/library/namespaces/rdfs.d.ts +0 -21
  149. package/types/library/namespaces/schema.d.ts +0 -2697
  150. package/types/library/namespaces/sioc.d.ts +0 -105
  151. package/types/library/namespaces/skos.d.ts +0 -38
  152. package/types/library/namespaces/xsd.d.ts +0 -56
@@ -1,38 +1,82 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Lens = exports.createResource = exports.createLens = void 0;
4
- const global_js_1 = require("../global.js");
3
+ exports.Lens = exports.createLens = void 0;
4
+ const options_js_1 = require("../options.js");
5
5
  const mod_js_1 = require("../schema/mod.js");
6
6
  const decoder_js_1 = require("../decoder.js");
7
7
  const query_builder_js_1 = require("./query_builder.js");
8
8
  const query_engine_proxy_js_1 = require("../engine/query_engine_proxy.js");
9
9
  /**
10
- * Lens lets you query and update RDF data via data schema using TypeScript native data types.
10
+ * Creates an instance of Lens that lets you query and update RDF data
11
+ * via data schema using TypeScript native data types.
11
12
  *
12
- * https://ldkit.io/docs/components/lens
13
+ * In order to create a Lens instance, you need to provide a data schema
14
+ * that describes the data model which serves to translate data between
15
+ * Linked Data and TypeScript native types (see {@link Schema} for details).
13
16
  *
14
- * @param schema data schema which extends `SchemaPrototype`
15
- * @param context optional `Context` - contains LDkit and query engine configuration
16
- * @param engine optional Query Engine
17
- * @returns Lens instance
17
+ * You can also pass a set of options for LDkit and a query engine that
18
+ * specify the data source, preferred language, etc. (see {@link Options} for details).
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { createLens, type Options } from "ldkit";
23
+ * import { dbo, rdfs, xsd } from "ldkit/namespaces";
24
+ *
25
+ * // Create options for query engine
26
+ * const options: Options = {
27
+ * sources: ["https://dbpedia.org/sparql"], // SPARQL endpoint
28
+ * language: "en", // Preferred language
29
+ * };
30
+ *
31
+ * // Create a schema
32
+ * const PersonSchema = {
33
+ * "@type": dbo.Person,
34
+ * name: rdfs.label,
35
+ * abstract: dbo.abstract,
36
+ * birthDate: {
37
+ * "@id": dbo.birthDate,
38
+ * "@type": xsd.date,
39
+ * },
40
+ * } as const;
41
+ *
42
+ * // Create a resource using the data schema and options above
43
+ * const Persons = createLens(PersonSchema, options);
44
+ *
45
+ * // List some persons
46
+ * const persons = await Persons.find({ take: 10 });
47
+ * for (const person of persons) {
48
+ * console.log(person.name); // string
49
+ * console.log(person.birthDate); // Date
50
+ * }
51
+ *
52
+ * // Get a particular person identified by IRI
53
+ * const ada = await Persons.findByIri("http://dbpedia.org/resource/Ada_Lovelace");
54
+ * console.log(ada?.name); // string "Ada Lovelace"
55
+ * console.log(ada?.birthDate); // Date object of 1815-12-10
56
+ * ```
57
+ *
58
+ * @param schema data schema which extends {@link Schema}
59
+ * @param options optional {@link Options} - contains LDkit and query engine configuration
60
+ * @returns Lens instance that provides interface to Linked Data based on the schema
18
61
  */
19
- const createLens = (schema, context, engine) => new Lens(schema, context, engine);
62
+ function createLens(schema, options) {
63
+ return new Lens(schema, options);
64
+ }
20
65
  exports.createLens = createLens;
21
66
  /**
22
- * @deprecated
23
- * Use `createLens` instead
67
+ * Lens provides an interface to Linked Data based on the data schema.
68
+ *
69
+ * For the best developer experience, use the {@link createLens} function to create the instance.
24
70
  */
25
- const createResource = (schema, context, engine) => new Lens(schema, context, engine);
26
- exports.createResource = createResource;
27
71
  class Lens {
28
- constructor(schema, context, engine) {
72
+ constructor(schema, options) {
29
73
  Object.defineProperty(this, "schema", {
30
74
  enumerable: true,
31
75
  configurable: true,
32
76
  writable: true,
33
77
  value: void 0
34
78
  });
35
- Object.defineProperty(this, "context", {
79
+ Object.defineProperty(this, "options", {
36
80
  enumerable: true,
37
81
  configurable: true,
38
82
  writable: true,
@@ -51,56 +95,365 @@ class Lens {
51
95
  value: void 0
52
96
  });
53
97
  this.schema = (0, mod_js_1.expandSchema)(schema);
54
- this.context = (0, global_js_1.resolveContext)(context);
55
- this.engine = new query_engine_proxy_js_1.QueryEngineProxy(this.context, engine);
56
- this.queryBuilder = new query_builder_js_1.QueryBuilder(this.schema, this.context);
98
+ this.options = (0, options_js_1.resolveOptions)(options);
99
+ const context = (0, options_js_1.resolveQueryContext)(this.options);
100
+ this.engine = new query_engine_proxy_js_1.QueryEngineProxy(this.options.engine, context);
101
+ this.queryBuilder = new query_builder_js_1.QueryBuilder(this.schema, this.options);
57
102
  }
58
103
  decode(graph) {
59
- return (0, decoder_js_1.decode)(graph, this.schema, this.context);
104
+ return (0, decoder_js_1.decode)(graph, this.schema, this.options);
60
105
  }
61
- async count() {
62
- const q = this.queryBuilder.countQuery();
63
- // TODO: console.log(q);
106
+ log(query) {
107
+ this.options.logQuery(query);
108
+ }
109
+ /**
110
+ * Returns the total number of entities corresponding to the data schema.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * import { createLens } from "ldkit";
115
+ * import { schema } from "ldkit/namespaces";
116
+ *
117
+ * // Create a schema
118
+ * const PersonSchema = {
119
+ * "@type": schema.Person,
120
+ * name: schema.name,
121
+ * } as const;
122
+ *
123
+ * // Create a resource using the data schema above
124
+ * const Persons = createLens(PersonSchema);
125
+ *
126
+ * // Count all persons
127
+ * const count = await Persons.count(); // number
128
+ * ```
129
+ *
130
+ * @returns total number of entities corresponding to the data schema
131
+ */
132
+ async count(max) {
133
+ const q = this.queryBuilder.countQuery(max);
134
+ this.log(q);
64
135
  const bindings = await this.engine.queryBindings(q);
65
136
  return parseInt(bindings[0].get("count").value);
66
137
  }
67
- //exists(entity: Identity) {}
138
+ /**
139
+ * Find entities with a custom SPARQL query.
140
+ *
141
+ * The query must be a CONSTRUCT query, and the root nodes must be of type `ldkit:Resource`.
142
+ * So that the decoder can decode the results, the query must also return all properties
143
+ * according to the data schema.
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * import { createLens } from "ldkit";
148
+ * import { ldkit, schema } from "ldkit/namespaces";
149
+ * import { CONSTRUCT } from "ldkit/sparql";
150
+ *
151
+ * // Create a schema
152
+ * const PersonSchema = {
153
+ * "@type": schema.Person,
154
+ * name: schema.name,
155
+ * } as const;
156
+ *
157
+ * // Create a resource using the data schema above
158
+ * const Persons = createLens(PersonSchema);
159
+ *
160
+ * // Query to find all persons named "Doe"
161
+ * const query = CONSTRUCT`?s a <${ldkit.Resource}>; <${schema.name}> ?name`
162
+ * .WHERE`?s <${schema.name}> ?name; <${schema.familyName}> "Doe"`.build();
163
+ *
164
+ * // Find all persons that match the custom query
165
+ * const doePersons = await Persons.query(query);
166
+ * ```
167
+ *
168
+ * @param sparqlConstructQuery CONSTRUCT SPARQL query
169
+ * @returns Found entities
170
+ */
68
171
  async query(sparqlConstructQuery) {
172
+ this.log(sparqlConstructQuery);
69
173
  const graph = await this.engine.queryGraph(sparqlConstructQuery);
70
174
  return this.decode(graph);
71
175
  }
72
- async find(where, limit) {
73
- const q = this.queryBuilder.getQuery(where, limit);
74
- // TODO: console.log(q);
176
+ /**
177
+ * Find entities that match the given search criteria.
178
+ *
179
+ * The search criteria is a JSON object that may contain properties from the data schema.
180
+ * In addition you can specify how many results to return and how many to skip
181
+ * for pagination purposes.
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * import { createLens } from "ldkit";
186
+ * import { schema } from "ldkit/namespaces";
187
+ *
188
+ * // Create a schema
189
+ * const PersonSchema = {
190
+ * "@type": schema.Person,
191
+ * name: schema.name,
192
+ * } as const;
193
+ *
194
+ * // Create a resource using the data schema above
195
+ * const Persons = createLens(PersonSchema);
196
+ *
197
+ * // Find 100 persons with name that starts with "Ada"
198
+ * const persons = await Persons.find({
199
+ * where: {
200
+ * name: { $strStarts: "Ada" },
201
+ * },
202
+ * take: 100,
203
+ * });
204
+ * ```
205
+ *
206
+ * @param options Search criteria and pagination options
207
+ * @returns entities that match the given search criteria
208
+ */
209
+ async find(options = {}) {
210
+ const { where, take, skip } = {
211
+ take: this.options.take,
212
+ skip: 0,
213
+ ...options,
214
+ };
215
+ const isRegularQuery = typeof where === "string" ||
216
+ typeof where === "undefined" || Array.isArray(where);
217
+ const q = isRegularQuery
218
+ ? this.queryBuilder.getQuery(where, take, skip)
219
+ : this.queryBuilder.getSearchQuery(where ?? {}, take, skip);
220
+ this.log(q);
75
221
  const graph = await this.engine.queryGraph(q);
76
222
  return this.decode(graph);
77
223
  }
224
+ /**
225
+ * Find one entity that matches the given search criteria.
226
+ *
227
+ * The search criteria is a JSON object that may contain properties from the data schema.
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * import { createLens } from "ldkit";
232
+ * import { schema } from "ldkit/namespaces";
233
+ *
234
+ * // Create a schema
235
+ * const PersonSchema = {
236
+ * "@type": schema.Person,
237
+ * name: schema.name,
238
+ * } as const;
239
+ *
240
+ * // Create a resource using the data schema above
241
+ * const Persons = createLens(PersonSchema);
242
+ *
243
+ * // Find one person with name that starts with "Ada"
244
+ * const person = await Persons.findOne({
245
+ * name: { $strStarts: "Ada" },
246
+ * });
247
+ * ```
248
+ *
249
+ * @param options Search criteria and pagination options
250
+ * @returns entities that match the given search criteria
251
+ */
252
+ async findOne(where) {
253
+ const results = await this.find({ where, take: 1 });
254
+ return results.length > 0 ? results[0] : null;
255
+ }
256
+ /**
257
+ * Find a single entity that matches the given IRI.
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * import { createLens } from "ldkit";
262
+ * import { schema } from "ldkit/namespaces";
263
+ *
264
+ * // Create a schema
265
+ * const PersonSchema = {
266
+ * "@type": schema.Person,
267
+ * name: schema.name,
268
+ * } as const;
269
+ *
270
+ * // Create a resource using the data schema above
271
+ * const Persons = createLens(PersonSchema);
272
+ *
273
+ * // Get a particular person identified by IRI
274
+ * const ada = await Persons.findByIri("http://dbpedia.org/resource/Ada_Lovelace");
275
+ * console.log(ada?.name); // string "Ada Lovelace"
276
+ * ```
277
+ *
278
+ * @param iri IRI of the entity to find
279
+ * @returns Entity if found, null otherwise
280
+ */
78
281
  async findByIri(iri) {
79
282
  const results = await this.findByIris([iri]);
80
- return results.length > 0 ? results[0] : undefined;
283
+ return results.length > 0 ? results[0] : null;
81
284
  }
285
+ /**
286
+ * Find entities that match the given IRIs.
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * import { createLens } from "ldkit";
291
+ * import { schema } from "ldkit/namespaces";
292
+ *
293
+ * // Create a schema
294
+ * const PersonSchema = {
295
+ * "@type": schema.Person,
296
+ * name: schema.name,
297
+ * } as const;
298
+ *
299
+ * // Create a resource using the data schema above
300
+ * const Persons = createLens(PersonSchema);
301
+ *
302
+ * // Get specific persons identified by IRIs
303
+ * const matches = await Persons.findByIris([
304
+ * "http://dbpedia.org/resource/Ada_Lovelace",
305
+ * "http://dbpedia.org/resource/Alan_Turing"
306
+ * ]);
307
+ * console.log(matches[0].name); // string "Ada Lovelace"
308
+ * console.log(matches[1].name); // string "Alan Turing"
309
+ * ```
310
+ *
311
+ * @param iris IRIs of the entities to find
312
+ * @returns Array of found entities, empty array if there are no matches
313
+ */
82
314
  async findByIris(iris) {
83
315
  const q = this.queryBuilder.getByIrisQuery(iris);
84
- // TODO: console.log(q);
316
+ this.log(q);
85
317
  const graph = await this.engine.queryGraph(q);
86
318
  return this.decode(graph);
87
319
  }
88
320
  updateQuery(query) {
89
- // TODO: console.log(query);
321
+ this.log(query);
90
322
  return this.engine.queryVoid(query);
91
323
  }
324
+ /**
325
+ * Inserts one or more entities to the data store.
326
+ *
327
+ * @example
328
+ * ```typescript
329
+ * import { createLens } from "ldkit";
330
+ * import { schema } from "ldkit/namespaces";
331
+ *
332
+ * // Create a schema
333
+ * const PersonSchema = {
334
+ * "@type": schema.Person,
335
+ * name: schema.name,
336
+ * } as const;
337
+ *
338
+ * // Create a resource using the data schema above
339
+ * const Persons = createLens(PersonSchema);
340
+ *
341
+ * // Insert a new person
342
+ * await Persons.insert({
343
+ * $id: "http://example.org/Alan_Turing",
344
+ * name: "Alan Turing",
345
+ * });
346
+ * ```
347
+ *
348
+ * @param entities Entities to insert
349
+ * @returns Nothing
350
+ */
92
351
  insert(...entities) {
93
352
  const q = this.queryBuilder.insertQuery(entities);
94
353
  return this.updateQuery(q);
95
354
  }
355
+ /**
356
+ * Inserts raw RDF quads to the data store.
357
+ *
358
+ * This method is useful when you need to insert data that is not covered by the data schema.
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * import { createLens } from "ldkit";
363
+ * import { schema } from "ldkit/namespaces";
364
+ * import { DataFactory } from "ldkit/rdf";
365
+ *
366
+ * // Create a schema
367
+ * const PersonSchema = {
368
+ * "@type": schema.Person,
369
+ * name: schema.name,
370
+ * } as const;
371
+ *
372
+ * // Create a resource using the data schema above
373
+ * const Persons = createLens(PersonSchema);
374
+ *
375
+ * // Create a custom quad to insert
376
+ * const df = new DataFactory();
377
+ * const quad = df.quad(
378
+ * df.namedNode("http://example.org/Alan_Turing"),
379
+ * df.namedNode("http://schema.org/name"),
380
+ * df.literal("Alan Turing"),
381
+ * );
382
+ *
383
+ * // Insert the quad
384
+ * await Persons.insertData(quad);
385
+ * ```
386
+ *
387
+ * @param quads Quads to insert to the data store
388
+ * @returns Nothing
389
+ */
96
390
  insertData(...quads) {
97
391
  const q = this.queryBuilder.insertDataQuery(quads);
98
392
  return this.updateQuery(q);
99
393
  }
394
+ /**
395
+ * Updates one or more entities in the data store.
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * import { createLens } from "ldkit";
400
+ * import { schema } from "ldkit/namespaces";
401
+ *
402
+ * // Create a schema
403
+ * const PersonSchema = {
404
+ * "@type": schema.Person,
405
+ * name: schema.name,
406
+ * } as const;
407
+ *
408
+ * // Create a resource using the data schema above
409
+ * const Persons = createLens(PersonSchema);
410
+ *
411
+ * // Update Alan Turing's name
412
+ * await Persons.update({
413
+ * $id: "http://example.org/Alan_Turing",
414
+ * name: "Not Alan Turing",
415
+ * });
416
+ * ```
417
+ *
418
+ * @param entities Partial entities to update
419
+ * @returns Nothing
420
+ */
100
421
  update(...entities) {
101
422
  const q = this.queryBuilder.updateQuery(entities);
102
423
  return this.updateQuery(q);
103
424
  }
425
+ /**
426
+ * Deletes one or more entities from the data store.
427
+ *
428
+ * This method accepts IRIs of the entities to delete and attemps
429
+ * to delete all triples from the database that corresponds to
430
+ * the data schema. Other triples that are not covered by the data
431
+ * schema will not be deleted.
432
+ *
433
+ * If you need to have more control of what triples to delete,
434
+ * use {@link deleteData} instead.
435
+ *
436
+ * @example
437
+ * ```typescript
438
+ * import { createLens } from "ldkit";
439
+ * import { schema } from "ldkit/namespaces";
440
+ *
441
+ * // Create a schema
442
+ * const PersonSchema = {
443
+ * "@type": schema.Person,
444
+ * name: schema.name,
445
+ * } as const;
446
+ *
447
+ * // Create a resource using the data schema above
448
+ * const Persons = createLens(PersonSchema);
449
+ *
450
+ * // Delete a person
451
+ * await Persons.delete("http://example.org/Alan_Turing");
452
+ * ```
453
+ *
454
+ * @param identities Identities or IRIs of the entities to delete
455
+ * @returns Nothing
456
+ */
104
457
  delete(...identities) {
105
458
  const iris = identities.map((identity) => {
106
459
  return typeof identity === "string" ? identity : identity.$id;
@@ -108,6 +461,41 @@ class Lens {
108
461
  const q = this.queryBuilder.deleteQuery(iris);
109
462
  return this.updateQuery(q);
110
463
  }
464
+ /**
465
+ * Deletes raw RDF quads from the data store.
466
+ *
467
+ * This method is useful when you need to delete data that is not covered by the data schema.
468
+ *
469
+ * @example
470
+ * ```typescript
471
+ * import { createLens } from "ldkit";
472
+ * import { schema } from "ldkit/namespaces";
473
+ * import { DataFactory } from "ldkit/rdf";
474
+ *
475
+ * // Create a schema
476
+ * const PersonSchema = {
477
+ * "@type": schema.Person,
478
+ * name: schema.name,
479
+ * } as const;
480
+ *
481
+ * // Create a resource using the data schema and context above
482
+ * const Persons = createLens(PersonSchema);
483
+ *
484
+ * // Create a custom quad to insert
485
+ * const df = new DataFactory();
486
+ * const quad = df.quad(
487
+ * df.namedNode("http://example.org/Alan_Turing"),
488
+ * df.namedNode("http://schema.org/name"),
489
+ * df.literal("Alan Turing"),
490
+ * );
491
+ *
492
+ * // Delete the quad
493
+ * await Persons.deleteData(quad);
494
+ * ```
495
+ *
496
+ * @param quads Quads to delete from the data store
497
+ * @returns Nothing
498
+ */
111
499
  deleteData(...quads) {
112
500
  const q = this.queryBuilder.deleteDataQuery(quads);
113
501
  return this.updateQuery(q);
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createResource = exports.createLens = void 0;
4
- var lens_js_1 = require("./lens.js");
5
- Object.defineProperty(exports, "createLens", { enumerable: true, get: function () { return lens_js_1.createLens; } });
6
- Object.defineProperty(exports, "createResource", { enumerable: true, get: function () { return lens_js_1.createResource; } });
17
+ __exportStar(require("./lens.js"), exports);