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,415 @@
1
- import type { Context, IQueryEngine, Iri, RDF } from "../rdf.js";
2
- import { type SchemaInterface, type SchemaInterfaceIdentity, type SchemaPrototype } from "../schema/mod.js";
3
- import type { Entity } from "./types.js";
1
+ import type { IRI, RDF } from "../rdf.js";
2
+ import { type Options } from "../options.js";
3
+ import { type Identity, type Schema, type SchemaInterface, type SchemaSearchInterface, type SchemaUpdateInterface } from "../schema/mod.js";
4
+ import type { Entity, Unite } from "./types.js";
4
5
  /**
5
- * Lens lets you query and update RDF data via data schema using TypeScript native data types.
6
+ * Creates an instance of Lens that lets you query and update RDF data
7
+ * via data schema using TypeScript native data types.
6
8
  *
7
- * https://ldkit.io/docs/components/lens
9
+ * In order to create a Lens instance, you need to provide a data schema
10
+ * that describes the data model which serves to translate data between
11
+ * Linked Data and TypeScript native types (see {@link Schema} for details).
8
12
  *
9
- * @param schema data schema which extends `SchemaPrototype`
10
- * @param context optional `Context` - contains LDkit and query engine configuration
11
- * @param engine optional Query Engine
12
- * @returns Lens instance
13
+ * You can also pass a set of options for LDkit and a query engine that
14
+ * specify the data source, preferred language, etc. (see {@link Options} for details).
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { createLens, type Options } from "ldkit";
19
+ * import { dbo, rdfs, xsd } from "ldkit/namespaces";
20
+ *
21
+ * // Create options for query engine
22
+ * const options: Options = {
23
+ * sources: ["https://dbpedia.org/sparql"], // SPARQL endpoint
24
+ * language: "en", // Preferred language
25
+ * };
26
+ *
27
+ * // Create a schema
28
+ * const PersonSchema = {
29
+ * "@type": dbo.Person,
30
+ * name: rdfs.label,
31
+ * abstract: dbo.abstract,
32
+ * birthDate: {
33
+ * "@id": dbo.birthDate,
34
+ * "@type": xsd.date,
35
+ * },
36
+ * } as const;
37
+ *
38
+ * // Create a resource using the data schema and options above
39
+ * const Persons = createLens(PersonSchema, options);
40
+ *
41
+ * // List some persons
42
+ * const persons = await Persons.find({ take: 10 });
43
+ * for (const person of persons) {
44
+ * console.log(person.name); // string
45
+ * console.log(person.birthDate); // Date
46
+ * }
47
+ *
48
+ * // Get a particular person identified by IRI
49
+ * const ada = await Persons.findByIri("http://dbpedia.org/resource/Ada_Lovelace");
50
+ * console.log(ada?.name); // string "Ada Lovelace"
51
+ * console.log(ada?.birthDate); // Date object of 1815-12-10
52
+ * ```
53
+ *
54
+ * @param schema data schema which extends {@link Schema}
55
+ * @param options optional {@link Options} - contains LDkit and query engine configuration
56
+ * @returns Lens instance that provides interface to Linked Data based on the schema
13
57
  */
14
- export declare const createLens: <T extends SchemaPrototype>(schema: T, context?: Context, engine?: IQueryEngine) => Lens<T, SchemaInterface<T>>;
58
+ export declare function createLens<T extends Schema>(schema: T, options?: Options): Lens<T>;
15
59
  /**
16
- * @deprecated
17
- * Use `createLens` instead
60
+ * Lens provides an interface to Linked Data based on the data schema.
61
+ *
62
+ * For the best developer experience, use the {@link createLens} function to create the instance.
18
63
  */
19
- export declare const createResource: <T extends SchemaPrototype>(schema: T, context?: Context, engine?: IQueryEngine) => Lens<T, SchemaInterface<T>>;
20
- export declare class Lens<S extends SchemaPrototype, I = SchemaInterface<S>> {
64
+ export declare class Lens<T extends Schema> {
21
65
  private readonly schema;
22
- private readonly context;
66
+ private readonly options;
23
67
  private readonly engine;
24
68
  private readonly queryBuilder;
25
- constructor(schema: S, context?: Context, engine?: IQueryEngine);
69
+ constructor(schema: T, options?: Options);
26
70
  private decode;
27
- count(): Promise<number>;
28
- query(sparqlConstructQuery: string): Promise<I[]>;
29
- find(where?: string | RDF.Quad[], limit?: number): Promise<I[]>;
30
- findByIri(iri: Iri): Promise<I | undefined>;
31
- findByIris(iris: Iri[]): Promise<I[]>;
71
+ private log;
72
+ /**
73
+ * Returns the total number of entities corresponding to the data schema.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * import { createLens } from "ldkit";
78
+ * import { schema } from "ldkit/namespaces";
79
+ *
80
+ * // Create a schema
81
+ * const PersonSchema = {
82
+ * "@type": schema.Person,
83
+ * name: schema.name,
84
+ * } as const;
85
+ *
86
+ * // Create a resource using the data schema above
87
+ * const Persons = createLens(PersonSchema);
88
+ *
89
+ * // Count all persons
90
+ * const count = await Persons.count(); // number
91
+ * ```
92
+ *
93
+ * @returns total number of entities corresponding to the data schema
94
+ */
95
+ count(max?: number): Promise<number>;
96
+ /**
97
+ * Find entities with a custom SPARQL query.
98
+ *
99
+ * The query must be a CONSTRUCT query, and the root nodes must be of type `ldkit:Resource`.
100
+ * So that the decoder can decode the results, the query must also return all properties
101
+ * according to the data schema.
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * import { createLens } from "ldkit";
106
+ * import { ldkit, schema } from "ldkit/namespaces";
107
+ * import { CONSTRUCT } from "ldkit/sparql";
108
+ *
109
+ * // Create a schema
110
+ * const PersonSchema = {
111
+ * "@type": schema.Person,
112
+ * name: schema.name,
113
+ * } as const;
114
+ *
115
+ * // Create a resource using the data schema above
116
+ * const Persons = createLens(PersonSchema);
117
+ *
118
+ * // Query to find all persons named "Doe"
119
+ * const query = CONSTRUCT`?s a <${ldkit.Resource}>; <${schema.name}> ?name`
120
+ * .WHERE`?s <${schema.name}> ?name; <${schema.familyName}> "Doe"`.build();
121
+ *
122
+ * // Find all persons that match the custom query
123
+ * const doePersons = await Persons.query(query);
124
+ * ```
125
+ *
126
+ * @param sparqlConstructQuery CONSTRUCT SPARQL query
127
+ * @returns Found entities
128
+ */
129
+ query(sparqlConstructQuery: string): Promise<Unite<SchemaInterface<T>>[]>;
130
+ /**
131
+ * Find entities that match the given search criteria.
132
+ *
133
+ * The search criteria is a JSON object that may contain properties from the data schema.
134
+ * In addition you can specify how many results to return and how many to skip
135
+ * for pagination purposes.
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * import { createLens } from "ldkit";
140
+ * import { schema } from "ldkit/namespaces";
141
+ *
142
+ * // Create a schema
143
+ * const PersonSchema = {
144
+ * "@type": schema.Person,
145
+ * name: schema.name,
146
+ * } as const;
147
+ *
148
+ * // Create a resource using the data schema above
149
+ * const Persons = createLens(PersonSchema);
150
+ *
151
+ * // Find 100 persons with name that starts with "Ada"
152
+ * const persons = await Persons.find({
153
+ * where: {
154
+ * name: { $strStarts: "Ada" },
155
+ * },
156
+ * take: 100,
157
+ * });
158
+ * ```
159
+ *
160
+ * @param options Search criteria and pagination options
161
+ * @returns entities that match the given search criteria
162
+ */
163
+ find(options?: {
164
+ where?: SchemaSearchInterface<T> | string | RDF.Quad[];
165
+ take?: number;
166
+ skip?: number;
167
+ }): Promise<Unite<SchemaInterface<T>>[]>;
168
+ /**
169
+ * Find one entity that matches the given search criteria.
170
+ *
171
+ * The search criteria is a JSON object that may contain properties from the data schema.
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * import { createLens } from "ldkit";
176
+ * import { schema } from "ldkit/namespaces";
177
+ *
178
+ * // Create a schema
179
+ * const PersonSchema = {
180
+ * "@type": schema.Person,
181
+ * name: schema.name,
182
+ * } as const;
183
+ *
184
+ * // Create a resource using the data schema above
185
+ * const Persons = createLens(PersonSchema);
186
+ *
187
+ * // Find one person with name that starts with "Ada"
188
+ * const person = await Persons.findOne({
189
+ * name: { $strStarts: "Ada" },
190
+ * });
191
+ * ```
192
+ *
193
+ * @param options Search criteria and pagination options
194
+ * @returns entities that match the given search criteria
195
+ */
196
+ findOne(where?: SchemaSearchInterface<T>): Promise<Unite<SchemaInterface<T>> | null>;
197
+ /**
198
+ * Find a single entity that matches the given IRI.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * import { createLens } from "ldkit";
203
+ * import { schema } from "ldkit/namespaces";
204
+ *
205
+ * // Create a schema
206
+ * const PersonSchema = {
207
+ * "@type": schema.Person,
208
+ * name: schema.name,
209
+ * } as const;
210
+ *
211
+ * // Create a resource using the data schema above
212
+ * const Persons = createLens(PersonSchema);
213
+ *
214
+ * // Get a particular person identified by IRI
215
+ * const ada = await Persons.findByIri("http://dbpedia.org/resource/Ada_Lovelace");
216
+ * console.log(ada?.name); // string "Ada Lovelace"
217
+ * ```
218
+ *
219
+ * @param iri IRI of the entity to find
220
+ * @returns Entity if found, null otherwise
221
+ */
222
+ findByIri(iri: IRI): Promise<Unite<SchemaInterface<T>> | null>;
223
+ /**
224
+ * Find entities that match the given IRIs.
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * import { createLens } from "ldkit";
229
+ * import { schema } from "ldkit/namespaces";
230
+ *
231
+ * // Create a schema
232
+ * const PersonSchema = {
233
+ * "@type": schema.Person,
234
+ * name: schema.name,
235
+ * } as const;
236
+ *
237
+ * // Create a resource using the data schema above
238
+ * const Persons = createLens(PersonSchema);
239
+ *
240
+ * // Get specific persons identified by IRIs
241
+ * const matches = await Persons.findByIris([
242
+ * "http://dbpedia.org/resource/Ada_Lovelace",
243
+ * "http://dbpedia.org/resource/Alan_Turing"
244
+ * ]);
245
+ * console.log(matches[0].name); // string "Ada Lovelace"
246
+ * console.log(matches[1].name); // string "Alan Turing"
247
+ * ```
248
+ *
249
+ * @param iris IRIs of the entities to find
250
+ * @returns Array of found entities, empty array if there are no matches
251
+ */
252
+ findByIris(iris: IRI[]): Promise<Unite<SchemaInterface<T>>[]>;
32
253
  private updateQuery;
33
- insert(...entities: Entity<I>[]): Promise<void>;
254
+ /**
255
+ * Inserts one or more entities to the data store.
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * import { createLens } from "ldkit";
260
+ * import { schema } from "ldkit/namespaces";
261
+ *
262
+ * // Create a schema
263
+ * const PersonSchema = {
264
+ * "@type": schema.Person,
265
+ * name: schema.name,
266
+ * } as const;
267
+ *
268
+ * // Create a resource using the data schema above
269
+ * const Persons = createLens(PersonSchema);
270
+ *
271
+ * // Insert a new person
272
+ * await Persons.insert({
273
+ * $id: "http://example.org/Alan_Turing",
274
+ * name: "Alan Turing",
275
+ * });
276
+ * ```
277
+ *
278
+ * @param entities Entities to insert
279
+ * @returns Nothing
280
+ */
281
+ insert(...entities: Entity<SchemaInterface<T>>[]): Promise<void>;
282
+ /**
283
+ * Inserts raw RDF quads to the data store.
284
+ *
285
+ * This method is useful when you need to insert data that is not covered by the data schema.
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * import { createLens } from "ldkit";
290
+ * import { schema } from "ldkit/namespaces";
291
+ * import { DataFactory } from "ldkit/rdf";
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
+ * // Create a custom quad to insert
303
+ * const df = new DataFactory();
304
+ * const quad = df.quad(
305
+ * df.namedNode("http://example.org/Alan_Turing"),
306
+ * df.namedNode("http://schema.org/name"),
307
+ * df.literal("Alan Turing"),
308
+ * );
309
+ *
310
+ * // Insert the quad
311
+ * await Persons.insertData(quad);
312
+ * ```
313
+ *
314
+ * @param quads Quads to insert to the data store
315
+ * @returns Nothing
316
+ */
34
317
  insertData(...quads: RDF.Quad[]): Promise<void>;
35
- update(...entities: Entity<I>[]): Promise<void>;
36
- delete(...identities: SchemaInterfaceIdentity[] | Iri[]): Promise<void>;
318
+ /**
319
+ * Updates one or more entities in the data store.
320
+ *
321
+ * @example
322
+ * ```typescript
323
+ * import { createLens } from "ldkit";
324
+ * import { schema } from "ldkit/namespaces";
325
+ *
326
+ * // Create a schema
327
+ * const PersonSchema = {
328
+ * "@type": schema.Person,
329
+ * name: schema.name,
330
+ * } as const;
331
+ *
332
+ * // Create a resource using the data schema above
333
+ * const Persons = createLens(PersonSchema);
334
+ *
335
+ * // Update Alan Turing's name
336
+ * await Persons.update({
337
+ * $id: "http://example.org/Alan_Turing",
338
+ * name: "Not Alan Turing",
339
+ * });
340
+ * ```
341
+ *
342
+ * @param entities Partial entities to update
343
+ * @returns Nothing
344
+ */
345
+ update(...entities: SchemaUpdateInterface<T>[]): Promise<void>;
346
+ /**
347
+ * Deletes one or more entities from the data store.
348
+ *
349
+ * This method accepts IRIs of the entities to delete and attemps
350
+ * to delete all triples from the database that corresponds to
351
+ * the data schema. Other triples that are not covered by the data
352
+ * schema will not be deleted.
353
+ *
354
+ * If you need to have more control of what triples to delete,
355
+ * use {@link deleteData} instead.
356
+ *
357
+ * @example
358
+ * ```typescript
359
+ * import { createLens } from "ldkit";
360
+ * import { schema } from "ldkit/namespaces";
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
+ * // Delete a person
372
+ * await Persons.delete("http://example.org/Alan_Turing");
373
+ * ```
374
+ *
375
+ * @param identities Identities or IRIs of the entities to delete
376
+ * @returns Nothing
377
+ */
378
+ delete(...identities: Identity[] | IRI[]): Promise<void>;
379
+ /**
380
+ * Deletes raw RDF quads from the data store.
381
+ *
382
+ * This method is useful when you need to delete data that is not covered by the data schema.
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * import { createLens } from "ldkit";
387
+ * import { schema } from "ldkit/namespaces";
388
+ * import { DataFactory } from "ldkit/rdf";
389
+ *
390
+ * // Create a schema
391
+ * const PersonSchema = {
392
+ * "@type": schema.Person,
393
+ * name: schema.name,
394
+ * } as const;
395
+ *
396
+ * // Create a resource using the data schema and context above
397
+ * const Persons = createLens(PersonSchema);
398
+ *
399
+ * // Create a custom quad to insert
400
+ * const df = new DataFactory();
401
+ * const quad = df.quad(
402
+ * df.namedNode("http://example.org/Alan_Turing"),
403
+ * df.namedNode("http://schema.org/name"),
404
+ * df.literal("Alan Turing"),
405
+ * );
406
+ *
407
+ * // Delete the quad
408
+ * await Persons.deleteData(quad);
409
+ * ```
410
+ *
411
+ * @param quads Quads to delete from the data store
412
+ * @returns Nothing
413
+ */
37
414
  deleteData(...quads: RDF.Quad[]): Promise<void>;
38
415
  }
@@ -1 +1 @@
1
- export { createLens, createResource, type Lens } from "./lens.js";
1
+ export * from "./lens.js";
@@ -1,22 +1,22 @@
1
- import type { Schema } from "../schema/mod.js";
2
- import { type Context, type Iri, type RDF } from "../rdf.js";
3
- import type { Entity } from "./types.js";
1
+ import { type Options } from "../options.js";
2
+ import { type ExpandedSchema, type SearchSchema } from "../schema/mod.js";
3
+ import { type IRI, type RDF } from "../rdf.js";
4
+ import { type Entity } from "./types.js";
4
5
  export declare class QueryBuilder {
5
6
  private readonly schema;
6
- private readonly schemaProperties;
7
- private readonly context;
7
+ private readonly options;
8
8
  private readonly df;
9
- constructor(schema: Schema, context: Context);
9
+ constructor(schema: ExpandedSchema, options: Options);
10
10
  private getResourceSignature;
11
- private getTypesSignature;
12
11
  private entitiesToQuads;
13
12
  private getShape;
14
- countQuery(): string;
15
- getQuery(where?: string | RDF.Quad[], limit?: number): string;
16
- getByIrisQuery(iris: Iri[]): string;
13
+ countQuery(max?: number): string;
14
+ getQuery(where: string | RDF.Quad[] | undefined, limit: number, offset: number): string;
15
+ getSearchQuery(where: SearchSchema, limit: number, offset: number): string;
16
+ getByIrisQuery(iris: IRI[], where?: SearchSchema): string;
17
17
  insertQuery(entities: Entity[]): string;
18
18
  insertDataQuery(quads: RDF.Quad[]): string;
19
- deleteQuery: (iris: Iri[]) => string;
19
+ deleteQuery: (iris: IRI[]) => string;
20
20
  deleteDataQuery(quads: RDF.Quad[]): string;
21
21
  updateQuery(entities: Entity[]): string;
22
22
  }
@@ -0,0 +1,21 @@
1
+ import { type SparqlValue } from "../sparql/mod.js";
2
+ import { type ExpandedProperty, type SearchSchema } from "../schema/mod.js";
3
+ export declare class SearchHelper {
4
+ private readonly property;
5
+ private readonly propertyType;
6
+ private readonly varName;
7
+ private readonly searchSchema;
8
+ private df;
9
+ readonly sparqlValues: SparqlValue[];
10
+ constructor(property: ExpandedProperty, varName: string, searchSchema: SearchSchema);
11
+ process(): void;
12
+ private processOperators;
13
+ private processStringFunctions;
14
+ private processRegex;
15
+ private processLangMatches;
16
+ private processArrayFunctions;
17
+ private processFilter;
18
+ private addFilter;
19
+ private encode;
20
+ private isPlainObject;
21
+ }
@@ -1,5 +1,8 @@
1
- import type { SchemaInterfaceIdentity } from "../schema/mod.js";
2
- export type Entity<T extends unknown = Record<string, unknown>> = DeepPartial<T> & SchemaInterfaceIdentity;
1
+ import type { Identity } from "../schema/mod.js";
2
+ export type Entity<T extends unknown = Record<string, unknown>> = DeepPartial<T> & Identity;
3
3
  export type DeepPartial<T> = T extends Record<string, unknown> ? {
4
4
  [P in keyof T]?: DeepPartial<T[P]>;
5
5
  } : T;
6
+ export type Unite<T> = T extends Record<string, unknown> ? {
7
+ [Key in keyof T]: T[Key];
8
+ } : T;
@@ -0,0 +1,23 @@
1
+ import type { Options } from "../options.js";
2
+ import type { RDF } from "../rdf.js";
3
+ import { type SparqlValue } from "../sparql/mod.js";
4
+ import { type ExpandedSchema } from "../schema/mod.js";
5
+ import type { Entity } from "./types.js";
6
+ export declare class UpdateHelper {
7
+ private readonly schema;
8
+ private readonly properties;
9
+ private readonly options;
10
+ private variableCounter;
11
+ readonly deleteQuads: RDF.Quad[];
12
+ readonly insertQuads: RDF.Quad[];
13
+ readonly whereQuads: SparqlValue[];
14
+ constructor(schema: ExpandedSchema, options: Options, variableInitCounter?: number);
15
+ process(entity: Entity): void;
16
+ private processProperty;
17
+ private processSingleProperty;
18
+ private processArrayProperty;
19
+ private processArraySet;
20
+ private processArrayAddRemove;
21
+ private parseArrayUpdateConfig;
22
+ private encode;
23
+ }
@@ -0,0 +1,41 @@
1
+ /** Original type of namespace specification */
2
+ export type Namespace = {
3
+ iri: string;
4
+ prefix: string;
5
+ terms: readonly string[];
6
+ };
7
+ /** Resulting type of namespace providing access to all terms, prefix and IRI */
8
+ export type NamespaceInterface<NamespaceSpec extends Namespace> = {
9
+ [Term in NamespaceSpec["terms"][number]]: `${NamespaceSpec["prefix"]}${Term}`;
10
+ } & {
11
+ $prefix: NamespaceSpec["prefix"];
12
+ $iri: NamespaceSpec["iri"];
13
+ };
14
+ /**
15
+ * Creates a strongly typed container for Linked Data vocabulary to provide
16
+ * type safe access to all vocabulary terms as well as IDE autocompletion.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { createNamespace } from "ldkit";
21
+ *
22
+ * const onto = createNamespace(
23
+ * {
24
+ * iri: "http://www.example.com/ontology#",
25
+ * prefix: "onto:",
26
+ * terms: [
27
+ * "object",
28
+ * "predicate",
29
+ * "subject",
30
+ * ],
31
+ * } as const,
32
+ * );
33
+ *
34
+ * console.log(onto.subject); // prints http://www.example.com/ontology#subject
35
+ * console.log(onto.unknown); // TypeScript error! This term does not exist
36
+ * ```
37
+ *
38
+ * @param namespaceSpec Specification of the namespace
39
+ * @returns
40
+ */
41
+ export declare function createNamespace<N extends Namespace>(namespaceSpec: N): NamespaceInterface<N>;
@@ -0,0 +1,70 @@
1
+ import { type IQueryEngine, type QueryContext } from "./engine/mod.js";
2
+ /**
3
+ * LDkit options and query engine context
4
+ *
5
+ * LDkit-specific options are:
6
+ * - `engine` - a query engine to use for querying data sources
7
+ * - `language` - a preferred language for literals
8
+ * - `take` - a default number of results to take (limit of SELECT queries)
9
+ * - `logQuery` - a function that will be called for each SPARQL query
10
+ */
11
+ export type Options = {
12
+ engine?: IQueryEngine;
13
+ language?: string;
14
+ take?: number;
15
+ logQuery?: (query: string) => void;
16
+ } & Partial<QueryContext>;
17
+ /**
18
+ * Sets global configuration {@link Options} for LDkit that will be used
19
+ * by default in all queries, unless overridden in {@link Lens}.
20
+ *
21
+ * LDkit-specific options are:
22
+ * - `engine` - a query engine to use for querying data sources
23
+ * - `language` - a preferred language for literals
24
+ * - `take` - a default number of results to take (limit of SELECT queries)
25
+ * - `logQuery` - a function that will be called for each SPARQL query
26
+ *
27
+ * Default values for these options are:
28
+ * ```typescript
29
+ * const defaultOptions = {
30
+ * engine: new QueryEngine(),
31
+ * take: 1000,
32
+ * logQuery: () => {},
33
+ * };
34
+ * ```
35
+ * The default configuration uses built-in {@link QueryEngine}. Language is not set by default.
36
+ *
37
+ * @param options LDkit options and query engine context
38
+ */
39
+ export declare function setGlobalOptions(options: Options): void;
40
+ export declare function resolveOptions(options?: Options): {
41
+ engine: IQueryEngine;
42
+ language?: string | undefined;
43
+ take: number;
44
+ logQuery: (query: string) => void;
45
+ queryFormat?: import("@rdfjs/types").QueryFormat | undefined;
46
+ baseIRI?: string | undefined;
47
+ queryTimestamp?: Date | undefined;
48
+ sources?: [import("@comunica/types").QuerySourceUnidentified, ...import("@comunica/types").QuerySourceUnidentified[]] | undefined;
49
+ destination?: import("@comunica/types").IDataDestination | undefined;
50
+ initialBindings?: import("@rdfjs/types").Bindings | undefined;
51
+ log?: import("@comunica/types").Logger | undefined;
52
+ datetime?: Date | undefined;
53
+ httpProxyHandler?: import("@comunica/types").IProxyHandler | undefined;
54
+ lenient?: boolean | undefined;
55
+ httpIncludeCredentials?: boolean | undefined;
56
+ httpAuth?: string | undefined;
57
+ httpTimeout?: number | undefined;
58
+ httpBodyTimeout?: boolean | undefined;
59
+ httpRetryCount?: number | undefined;
60
+ httpRetryDelayFallback?: number | undefined;
61
+ httpRetryDelayLimit?: number | undefined;
62
+ fetch?: typeof fetch | undefined;
63
+ readOnly?: boolean | undefined;
64
+ extensionFunctionCreator?: ((functionNamedNode: import("@rdfjs/types").NamedNode<string>) => ((args: import("@rdfjs/types").Term[]) => Promise<import("@rdfjs/types").Term>) | undefined) | undefined;
65
+ functionArgumentsCache?: import("@comunica/types").FunctionArgumentsCache | undefined;
66
+ extensionFunctions?: Record<string, (args: import("@rdfjs/types").Term[]) => Promise<import("@rdfjs/types").Term>> | undefined;
67
+ explain?: import("@comunica/types").QueryExplainMode | undefined;
68
+ recoverBrokenLinks?: boolean | undefined;
69
+ };
70
+ export declare function resolveQueryContext(options: Options): QueryContext;