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