ldkit 1.1.0 → 2.0.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 +5 -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 +414 -25
  9. package/esm/library/lens/mod.js +1 -1
  10. package/esm/library/lens/query_builder.js +81 -50
  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 +2 -2
  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 +415 -27
  50. package/script/library/lens/mod.js +15 -4
  51. package/script/library/lens/query_builder.js +82 -54
  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 +400 -23
  90. package/types/library/lens/mod.d.ts +1 -1
  91. package/types/library/lens/query_builder.d.ts +10 -10
  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 +72 -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,20 +1,13 @@
1
- import type * as RDF from "rdf-js";
1
+ import type * as RDF from "@rdfjs/types";
2
2
  export type { RDF };
3
3
  export { fromRdf, toRdf } from "rdf-literal";
4
4
  import { DataFactory, DefaultGraph } from "rdf-data-factory";
5
5
  export { DataFactory, DefaultGraph };
6
6
  export * as N3 from "n3";
7
- import type { IDataSource, IQueryContextCommon } from "@comunica/types";
8
- export type LDkitContext = {
9
- graph?: string;
10
- language?: string;
11
- };
12
- export type Context = LDkitContext & RDF.QueryStringContext & RDF.QuerySourceContext<IDataSource> & IQueryContextCommon;
13
- export type IQueryEngine = RDF.StringSparqlQueryable<RDF.SparqlResultSupport, Context>;
14
- export type Iri = string;
15
- export type Node = Map<Iri, RDF.Term[]>;
16
- export type Graph = Map<Iri, Node>;
17
- export declare const quadsToGraph: (quads: RDF.Quad[]) => Graph;
7
+ export type IRI = string;
8
+ export type Node = Map<IRI, RDF.Term[]>;
9
+ export type Graph = Map<IRI, Node>;
10
+ export declare const quadsToGraph: (quads: Iterable<RDF.Quad>) => Graph;
18
11
  export declare namespace RDFJSON {
19
12
  type Term = {
20
13
  type: "uri" | "literal" | "bnode";
@@ -23,7 +16,7 @@ export declare namespace RDFJSON {
23
16
  datatype?: string;
24
17
  };
25
18
  type Bindings = Record<string, Term>;
26
- type Triple = [Iri, Iri, Term];
19
+ type Triple = [IRI, IRI, Term];
27
20
  type SparqlResultsJsonFormat = {
28
21
  head: {
29
22
  vars?: string[];
@@ -33,7 +26,7 @@ export declare namespace RDFJSON {
33
26
  };
34
27
  boolean?: boolean;
35
28
  };
36
- type RdfJsonFormat = Record<Iri, Record<Iri, Term[]>>;
29
+ type RdfJsonFormat = Record<IRI, Record<IRI, Term[]>>;
37
30
  interface TermFactory {
38
31
  fromJson(jsonTerm: Term): RDF.Term;
39
32
  }
@@ -80,5 +73,5 @@ export declare class QuadFactory implements RDFJSON.QuadFactory {
80
73
  protected readonly dataFactory: RDF.DataFactory;
81
74
  protected readonly termFactory: RDFJSON.TermFactory;
82
75
  constructor(dataFactory?: RDF.DataFactory, termFactory?: RDFJSON.TermFactory);
83
- fromJson(jsonRdf: [Iri, Iri, RDFJSON.Term]): RDF.Quad;
76
+ fromJson(jsonRdf: [IRI, IRI, RDFJSON.Term]): RDF.Quad;
84
77
  }
@@ -1,39 +1,46 @@
1
- declare const SupportedDataTypesPrototype: {
2
- "xsd:dateTime": Date;
3
- "xsd:date": Date;
4
- "xsd:gDay": Date;
5
- "xsd:gMonthDay": Date;
6
- "xsd:gYear": Date;
7
- "xsd:gYearMonth": Date;
8
- "xsd:boolean": boolean;
9
- "xsd:double": number;
10
- "xsd:decimal": number;
11
- "xsd:float": number;
12
- "xsd:integer": number;
13
- "xsd:long": number;
14
- "xsd:int": number;
15
- "xsd:byte": number;
16
- "xsd:short": number;
17
- "xsd:negativeInteger": number;
18
- "xsd:nonNegativeInteger": number;
19
- "xsd:nonPositiveInteger": number;
20
- "xsd:positiveInteger": number;
21
- "xsd:unsignedByte": number;
22
- "xsd:unsignedInt": number;
23
- "xsd:unsignedLong": number;
24
- "xsd:unsignedShort": number;
25
- "xsd:string": string;
26
- "xsd:normalizedString": string;
27
- "xsd:anyURI": string;
28
- "xsd:base64Binary": string;
29
- "xsd:language": string;
30
- "xsd:Name": string;
31
- "xsd:NCName": string;
32
- "xsd:NMTOKEN": string;
33
- "xsd:token": string;
34
- "xsd:hexBinary": string;
35
- "rdf:langString": string;
1
+ import { xsd } from "../../namespaces/xsd.js";
2
+ import { rdf } from "../../namespaces/rdf.js";
3
+ import { ldkit } from "../../namespaces/ldkit.js";
4
+ import { type IRI } from "../rdf.js";
5
+ /** Map of supported RDF data types and their JavaScript native counterparts */
6
+ export type SupportedDataTypes = {
7
+ [xsd.dateTime]: Date;
8
+ [xsd.date]: Date;
9
+ [xsd.gDay]: Date;
10
+ [xsd.gMonthDay]: Date;
11
+ [xsd.gYear]: Date;
12
+ [xsd.gYearMonth]: Date;
13
+ [xsd.boolean]: boolean;
14
+ [xsd.double]: number;
15
+ [xsd.decimal]: number;
16
+ [xsd.float]: number;
17
+ [xsd.integer]: number;
18
+ [xsd.long]: number;
19
+ [xsd.int]: number;
20
+ [xsd.byte]: number;
21
+ [xsd.short]: number;
22
+ [xsd.negativeInteger]: number;
23
+ [xsd.nonNegativeInteger]: number;
24
+ [xsd.nonPositiveInteger]: number;
25
+ [xsd.positiveInteger]: number;
26
+ [xsd.unsignedByte]: number;
27
+ [xsd.unsignedInt]: number;
28
+ [xsd.unsignedLong]: number;
29
+ [xsd.unsignedShort]: number;
30
+ [xsd.string]: string;
31
+ [xsd.normalizedString]: string;
32
+ [xsd.anyURI]: string;
33
+ [xsd.base64Binary]: string;
34
+ [xsd.language]: string;
35
+ [xsd.Name]: string;
36
+ [xsd.NCName]: string;
37
+ [xsd.NMTOKEN]: string;
38
+ [xsd.token]: string;
39
+ [xsd.hexBinary]: string;
40
+ [rdf.langString]: string;
41
+ [xsd.time]: string;
42
+ [xsd.duration]: string;
43
+ [ldkit.IRI]: IRI;
36
44
  };
37
- export type SupportedDataTypes = typeof SupportedDataTypesPrototype;
45
+ /** List of supported native JavaScript types */
38
46
  export type SupportedNativeTypes = SupportedDataTypes[keyof SupportedDataTypes];
39
- export {};
@@ -1,32 +1,87 @@
1
+ import { IRI } from "../rdf.js";
1
2
  import type { SupportedDataTypes } from "./data_types.js";
2
- import type { PropertyPrototype, SchemaPrototype } from "./schema.js";
3
- type IsOptional<Property extends PropertyPrototype> = Property extends {
3
+ import type { Property, Schema } from "./schema.js";
4
+ import type { SearchFilters } from "./search.js";
5
+ type Unite<T> = T extends Record<string, unknown> ? {
6
+ [Key in keyof T]: T[Key];
7
+ } : T;
8
+ type IsOptional<T extends Property> = T extends {
4
9
  "@optional": true;
5
10
  } ? true : false;
6
- type IsArray<Property extends PropertyPrototype> = Property extends {
11
+ type IsArray<T extends Property> = T extends {
7
12
  "@array": true;
8
13
  } ? true : false;
9
- type IsMultilang<Property extends PropertyPrototype> = Property extends {
14
+ type IsMultilang<T extends Property> = T extends {
10
15
  "@multilang": true;
11
16
  } ? true : false;
12
- type ValidPropertyDefinition = PropertyPrototype | string;
13
- type ConvertPropertyType<T extends PropertyPrototype> = T extends {
14
- "@context": SchemaPrototype;
15
- } ? SchemaInterface<T["@context"]> : T extends {
17
+ type IsInverse<T extends Property> = T extends {
18
+ "@inverse": true;
19
+ } ? true : false;
20
+ type ValidPropertyDefinition = Property | string;
21
+ type ConvertPropertyType<T extends Property> = T extends {
16
22
  "@type": unknown;
17
23
  } ? T["@type"] extends keyof SupportedDataTypes ? SupportedDataTypes[T["@type"]] : never : string;
18
- type ConvertPropertyOptional<T extends PropertyPrototype> = IsOptional<T> extends true ? ConvertPropertyType<T> | undefined : ConvertPropertyType<T>;
19
- type ConvertPropertyArray<T extends PropertyPrototype> = IsArray<T> extends true ? ConvertPropertyType<T>[] : ConvertPropertyOptional<T>;
20
- type ConvertPropertyMultilang<T extends PropertyPrototype> = IsMultilang<T> extends true ? IsArray<T> extends true ? Record<string, ConvertPropertyType<T>[]> : Record<string, ConvertPropertyType<T>> : ConvertPropertyArray<T>;
21
- type ConvertPropertyObject<T extends PropertyPrototype> = ConvertPropertyMultilang<T>;
22
- type ConvertProperty<T extends ValidPropertyDefinition> = T extends PropertyPrototype ? ConvertPropertyObject<T> : string;
23
- export type SchemaInterfaceIdentity = {
24
- $id: string;
25
- };
26
- export type SchemaInterfaceType = {
27
- $type: string[];
24
+ type ConvertPropertySchema<T extends Property> = T extends {
25
+ "@schema": Schema;
26
+ } ? Unite<SchemaInterface<T["@schema"]>> : ConvertPropertyType<T>;
27
+ type ConvertPropertyOptional<T extends Property> = IsOptional<T> extends true ? ConvertPropertySchema<T> | null : ConvertPropertySchema<T>;
28
+ type ConvertPropertyArray<T extends Property> = IsArray<T> extends true ? ConvertPropertySchema<T>[] : ConvertPropertyOptional<T>;
29
+ type ConvertPropertyMultilang<T extends Property> = IsMultilang<T> extends true ? IsArray<T> extends true ? Record<string, ConvertPropertyType<T>[]> : Record<string, ConvertPropertyType<T>> : ConvertPropertyArray<T>;
30
+ type ConvertPropertyObject<T extends Property> = ConvertPropertyMultilang<T>;
31
+ type ConvertProperty<T extends ValidPropertyDefinition> = T extends Property ? ConvertPropertyObject<T> : string;
32
+ /** Object that contains IRI of an entity */
33
+ export type Identity = {
34
+ $id: IRI;
28
35
  };
29
- export type SchemaInterface<T extends SchemaPrototype> = {
36
+ /**
37
+ * Describes a data model of a data entity according to its schema,. as resolved
38
+ * by LDkit, i.e. the shape of data that LDkit returns when querying for entities.
39
+ *
40
+ * See {@link Lens.prototype.find} for usage example.
41
+ */
42
+ export type SchemaInterface<T extends Schema> = Identity & {
30
43
  [X in Exclude<keyof T, "@type">]: T[X] extends ValidPropertyDefinition ? ConvertProperty<T[X]> : never;
31
- } & SchemaInterfaceIdentity & SchemaInterfaceType;
44
+ };
45
+ type ConvertUpdatePropertySchema<T extends Property> = T extends {
46
+ "@schema": Schema;
47
+ } ? Unite<SchemaUpdateInterface<T["@schema"]>> : ConvertPropertyType<T>;
48
+ type ConvertUpdatePropertyOptional<T extends Property> = IsOptional<T> extends true ? ConvertPropertySchema<T> | null : ConvertUpdatePropertySchema<T>;
49
+ type CreateArrayUpdateInterface<T extends Property> = {
50
+ $set?: ConvertPropertyType<T>[];
51
+ $add?: ConvertPropertyType<T>[];
52
+ $remove?: ConvertPropertyType<T>[];
53
+ } | ConvertPropertyType<T>[];
54
+ type ConvertUpdatePropertyArray<T extends Property> = IsArray<T> extends true ? CreateArrayUpdateInterface<T> : ConvertUpdatePropertyOptional<T>;
55
+ type ConvertUpdatePropertyMultilang<T extends Property> = IsMultilang<T> extends true ? IsArray<T> extends true ? Record<string, CreateArrayUpdateInterface<T>> : Record<string, ConvertPropertyType<T>> : ConvertUpdatePropertyArray<T>;
56
+ type ConvertUpdatePropertyObject<T extends Property> = ConvertUpdatePropertyMultilang<T>;
57
+ type ConvertUpdateProperty<T extends ValidPropertyDefinition> = T extends Property ? ConvertUpdatePropertyObject<T> : string;
58
+ /**
59
+ * Describes a shape of data for updating an entity, according to its data schema.
60
+ *
61
+ * See {@link Lens.prototype.update} for usage example.
62
+ */
63
+ export type SchemaUpdateInterface<T extends Schema> = Identity & {
64
+ [X in Exclude<keyof T, "@type">]?: T[X] extends ValidPropertyDefinition ? ConvertUpdateProperty<T[X]> : never;
65
+ };
66
+ type ConvertSearchPropertySchema<T extends Property> = T extends {
67
+ "@schema": Schema;
68
+ } ? Unite<SchemaSearchInterfaceProperties<T["@schema"]>> : IsInverse<T> extends true ? never : SearchFilters<ConvertPropertyType<T>>;
69
+ type ConvertSearchProperty<T extends ValidPropertyDefinition> = T extends Property ? ConvertSearchPropertySchema<T> : SearchFilters<string>;
70
+ type InversePropertiesMap<T extends Schema> = {
71
+ [X in keyof T]: T[X] extends {
72
+ "@inverse": true;
73
+ } ? X : never;
74
+ };
75
+ type InverseProperties<T extends Schema> = InversePropertiesMap<T>[keyof InversePropertiesMap<T>];
76
+ type SchemaSearchInterfaceProperties<T extends Schema> = {
77
+ [X in Exclude<keyof T, "@type" | InverseProperties<T>>]?: T[X] extends ValidPropertyDefinition ? ConvertSearchProperty<T[X]> : never;
78
+ };
79
+ /**
80
+ * Describes a shape of data for updating an entity, according to its data schema.
81
+ *
82
+ * See {@link Lens.prototype.find} for usage example.
83
+ */
84
+ export type SchemaSearchInterface<T extends Schema> = {
85
+ $id?: IRI | IRI[];
86
+ } & SchemaSearchInterfaceProperties<T>;
32
87
  export {};
@@ -1,3 +1,5 @@
1
- export type { SchemaInterface, SchemaInterfaceIdentity, SchemaInterfaceType, } from "./interface.js";
2
- export type { Property, PropertyPrototype, Schema, SchemaPrototype, } from "./schema.js";
1
+ export type { SupportedDataTypes, SupportedNativeTypes } from "./data_types.js";
2
+ export type { Identity, SchemaInterface, SchemaSearchInterface, SchemaUpdateInterface, } from "./interface.js";
3
+ export type { ExpandedProperty, ExpandedSchema, Property, Schema, } from "./schema.js";
4
+ export type { SearchFilters, SearchSchema } from "./search.js";
3
5
  export { expandSchema, getSchemaProperties } from "./utils.js";
@@ -1,30 +1,37 @@
1
1
  import type { SupportedDataTypes } from "./data_types.js";
2
- type PropertyType = keyof SupportedDataTypes;
3
- export type PropertyPrototype = {
2
+ /**
3
+ * Data property prototype that describes RDF predicate of a data entity.
4
+ * Includes specification of other metadata, such as whether the property
5
+ * is optional, array, inverse, or whether it is a nested data entity, etc.
6
+ */
7
+ export type Property = {
4
8
  "@id": string;
5
- "@type"?: PropertyType;
6
- "@context"?: SchemaPrototype;
9
+ "@type"?: keyof SupportedDataTypes;
10
+ "@schema"?: Schema;
7
11
  "@optional"?: true;
8
12
  "@array"?: true;
9
13
  "@multilang"?: true;
14
+ "@inverse"?: true;
10
15
  };
11
- export type SchemaPrototypeProperties = {
12
- [key: string]: PropertyPrototype | string | readonly string[];
13
- };
14
- export type SchemaPrototypeType = {
15
- "@type": string | readonly string[];
16
+ /**
17
+ * Data schema prototype that describes a data entity. Includes an optional
18
+ * specification of RDF type and a map of RDF properties.
19
+ */
20
+ export type Schema = {
21
+ "@type"?: string | readonly string[];
22
+ } & {
23
+ [key: string]: Property | string | readonly string[];
16
24
  };
17
- export type SchemaPrototype = SchemaPrototypeProperties & SchemaPrototypeType;
18
- export type Property = {
25
+ export type ExpandedProperty = {
19
26
  "@id": string;
20
- "@type"?: PropertyType;
21
- "@context"?: Schema;
27
+ "@type"?: keyof SupportedDataTypes;
28
+ "@schema"?: ExpandedSchema;
22
29
  "@optional"?: true;
23
30
  "@array"?: true;
24
31
  "@multilang"?: true;
32
+ "@inverse"?: true;
25
33
  };
26
- export type Schema = {
27
- [key: string]: Property | string[];
34
+ export type ExpandedSchema = {
35
+ [key: string]: ExpandedProperty | string[];
28
36
  "@type": string[];
29
37
  };
30
- export {};
@@ -0,0 +1,20 @@
1
+ import { SparqlValue } from "../sparql/mod.js";
2
+ export type SearchFilters<T> = T | {
3
+ $equals?: T;
4
+ $not?: T;
5
+ $contains?: T;
6
+ $strStarts?: T;
7
+ $strEnds?: T;
8
+ $gt?: T;
9
+ $gte?: T;
10
+ $lt?: T;
11
+ $lte?: T;
12
+ $regex?: string;
13
+ $langMatches?: string;
14
+ $in?: T[];
15
+ $notIn?: T[];
16
+ $filter?: SparqlValue;
17
+ };
18
+ export type SearchSchema = {
19
+ [key: string]: SearchFilters<unknown> | SearchSchema;
20
+ };
@@ -1,3 +1,3 @@
1
- import type { Property, Schema, SchemaPrototype } from "./schema.js";
2
- export declare const expandSchema: (schemaPrototype: SchemaPrototype) => Schema;
3
- export declare const getSchemaProperties: (schema: Schema) => Record<string, Property>;
1
+ import type { ExpandedProperty, ExpandedSchema, Schema } from "./schema.js";
2
+ export declare const expandSchema: (schemaPrototype: Schema) => ExpandedSchema;
3
+ export declare const getSchemaProperties: (schema: ExpandedSchema) => Record<string, ExpandedProperty>;
@@ -1,3 +1,4 @@
1
- export { sparql, type SparqlValue } from "./sparql_tag.js";
1
+ export * from "./sparql_tag.js";
2
2
  export { ASK, CONSTRUCT, DESCRIBE, SELECT } from "./sparql_query_builders.js";
3
3
  export { DELETE, INSERT, WITH } from "./sparql_update_builders.js";
4
+ export * from "./sparql_expression_builders.js";
@@ -0,0 +1,19 @@
1
+ import { SparqlBuilder } from "./sparql_shared_builders.js";
2
+ import { type SparqlValue } from "./sparql_tag.js";
3
+ type Builders<T extends keyof SparqlExpressionBuilder> = Pick<SparqlExpressionBuilder, T>;
4
+ declare class SparqlExpressionBuilder extends SparqlBuilder {
5
+ OPTIONAL(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build">;
6
+ }
7
+ /**
8
+ * SPARQL OPTIONAL expression fluent interface
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { OPTIONAL } from "ldkit/sparql";
13
+ *
14
+ * const query = OPTIONAL`?s ?p ?o`.build();
15
+ * console.log(query); // OPTIONAL { ?s ?p ?o }
16
+ * ```
17
+ */
18
+ export declare const OPTIONAL: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">;
19
+ export {};
@@ -22,18 +22,83 @@ declare class SparqlQueryBuilder extends SparqlBuilder {
22
22
  ASK_WHERE(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build" | "GROUP_BY" | "ORDER_BY" | "LIMIT">;
23
23
  DESCRIBE(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build" | "FROM" | "FROM_NAMED" | "WHERE">;
24
24
  }
25
+ /**
26
+ * SPARQL SELECT query fluent interface
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * import { SELECT } from "ldkit/sparql";
31
+ *
32
+ * const query = SELECT`?s`.WHERE`?s ?p ?o`.ORDER_BY`?s`.LIMIT(100).build();
33
+ * console.log(query);
34
+ * // SELECT ?s WHERE { ?s ?p ?o } ORDER BY ?s LIMIT 100
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { SELECT } from "ldkit/sparql";
40
+ *
41
+ * const query = SELECT.DISTINCT`?s`.WHERE`?s ?p ?o`.build();
42
+ * console.log(query);
43
+ * // SELECT DISTINCT ?s WHERE { ?s ?p ?o }
44
+ * ```
45
+ */
25
46
  export declare const SELECT: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "FROM_NAMED" | "FROM">) & {
26
47
  DISTINCT: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "FROM_NAMED" | "FROM">;
27
48
  REDUCED: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "FROM_NAMED" | "FROM">;
28
49
  readonly ALL: Builders<"WHERE" | "FROM_NAMED" | "FROM">;
29
50
  };
51
+ /**
52
+ * SPARQL CONSTRUCT query fluent interface
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { CONSTRUCT } from "ldkit/sparql";
57
+ * import { DataFactory } from "ldkit/rdf";
58
+ *
59
+ * const df = new DataFactory();
60
+ * const sNode = df.namedNode("http://example.org/datasource");
61
+ * const pNode = df.namedNode("http://example.org/hasSubject");
62
+ *
63
+ * const query = CONSTRUCT`${sNode} ${pNode} ?s`.WHERE`?s ?p ?o`.build();
64
+ * console.log(query);
65
+ * // CONSTRUCT { <http://example.org/datasource> <http://example.org/hasSubject> ?s }
66
+ * // WHERE { ?s ?p ?o }
67
+ * ```
68
+ */
30
69
  export declare const CONSTRUCT: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE">) & {
31
- WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"LIMIT" | "ORDER_BY" | "GROUP_BY" | "build">;
70
+ WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build" | "LIMIT" | "ORDER_BY" | "GROUP_BY">;
32
71
  };
72
+ /**
73
+ * SPARQL ASK query fluent interface
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * import { ASK } from "ldkit/sparql";
78
+ *
79
+ * const query = ASK`?s ?p ?o`.build();
80
+ * console.log(query); // ASK { ?s ?p ?o }
81
+ * ```
82
+ */
33
83
  export declare const ASK: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">) & {
34
84
  FROM: (stringOrNamedNode: string | RDF.NamedNode<string>) => Builders<"WHERE" | "FROM_NAMED" | "FROM">;
35
85
  FROM_NAMED: (stringOrNamedNode: string | RDF.NamedNode<string>) => Builders<"WHERE" | "FROM_NAMED">;
36
- WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"LIMIT" | "ORDER_BY" | "GROUP_BY" | "build">;
86
+ WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build" | "LIMIT" | "ORDER_BY" | "GROUP_BY">;
37
87
  };
38
- export declare const DESCRIBE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "FROM_NAMED" | "FROM" | "build">;
88
+ /**
89
+ * SPARQL DESCRIBE query fluent interface
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * import { DESCRIBE } from "ldkit/sparql";
94
+ * import { DataFactory } from "ldkit/rdf";
95
+ *
96
+ * const df = new DataFactory();
97
+ * const node = df.namedNode("http://example.org/resource");
98
+ *
99
+ * const query = DESCRIBE`${node}`.build();
100
+ * console.log(query); // DESCRIBE <http://example.org/resource>
101
+ * ```
102
+ */
103
+ export declare const DESCRIBE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build" | "WHERE" | "FROM_NAMED" | "FROM">;
39
104
  export {};
@@ -2,6 +2,7 @@ import { DataFactory, RDF } from "../rdf.js";
2
2
  import { type SparqlValue } from "./sparql_tag.js";
3
3
  type Wrap = (keyword: string, value: string) => string;
4
4
  export declare const braces: Wrap;
5
+ export declare const bracesInline: Wrap;
5
6
  export declare const parentheses: Wrap;
6
7
  export declare abstract class SparqlBuilder {
7
8
  protected value: string;
@@ -1,3 +1,31 @@
1
1
  import { type RDF } from "../rdf.js";
2
- export type SparqlValue = RDF.Term | string | number | boolean | Date | Iterable<SparqlValue> | null | undefined;
2
+ /**
3
+ * Any value that can be used in LDkit SPARQL builders
4
+ */
5
+ export type SparqlValue = RDF.Term | string | number | boolean | Date | Iterable<SparqlValue> | {
6
+ build: () => string;
7
+ } | null | undefined;
8
+ /**
9
+ * A template tag for SPARQL queries or its parts. Automatically converts
10
+ * values to SPARQL literals and escapes strings as needed.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { sparql } from "ldkit/sparql";
15
+ * import { DataFactory } from "ldkit/rdf";
16
+ *
17
+ * const df = new DataFactory();
18
+ * const quad = df.quad(
19
+ * df.namedNode("http://example.org/s"),
20
+ * df.namedNode("http://example.org/p"),
21
+ * df.literal("o"),
22
+ * );
23
+ * const query = sparql`SELECT * WHERE { ${quad} }`;
24
+ * console.log(query); // SELECT * WHERE { <http://example.org/s> <http://example.org/p> "o" . }
25
+ * ```
26
+ *
27
+ * @param strings {TemplateStringsArray} template strings
28
+ * @param values {SparqlValue[]}
29
+ * @returns {string} SPARQL query or its part
30
+ */
3
31
  export declare const sparql: (strings: TemplateStringsArray, ...values: SparqlValue[]) => string;
@@ -10,13 +10,81 @@ declare class SparqlUpdateBuilder extends SparqlBuilder {
10
10
  INSERT_DATA(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build">;
11
11
  DELETE(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"INSERT" | "USING" | "USING_NAMED" | "WHERE">;
12
12
  DELETE_DATA(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build">;
13
+ DELETE_WHERE(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build">;
13
14
  WITH(stringOrNamedNode: string | RDF.NamedNode<string>): Builders<"INSERT" | "DELETE">;
14
15
  }
16
+ /**
17
+ * SPARQL INSERT query fluent interface
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { INSERT } from "ldkit/sparql";
22
+ * import { foaf } from "ldkit/namespaces";
23
+ * import { DataFactory } from "ldkit/rdf";
24
+ *
25
+ * const df = new DataFactory();
26
+ * const firstName = df.namedNode(foaf.firstName);
27
+ *
28
+ * const query = INSERT`?person ${firstName} "Paul"`
29
+ * .WHERE`?person ${firstName} "Jean"`
30
+ * .build();
31
+ * console.log(query);
32
+ * // INSERT { ?person <http://xmlns.com/foaf/0.1/firstName> "Paul" }
33
+ * // WHERE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
34
+ * ```
35
+ */
15
36
  export declare const INSERT: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "USING_NAMED" | "USING">) & {
16
37
  DATA: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">;
17
38
  };
39
+ /**
40
+ * SPARQL DELETE query fluent interface
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * import { DELETE } from "ldkit/sparql";
45
+ * import { foaf } from "ldkit/namespaces";
46
+ * import { DataFactory } from "ldkit/rdf";
47
+ *
48
+ * const df = new DataFactory();
49
+ * const firstName = df.namedNode(foaf.firstName);
50
+ *
51
+ * const query = DELETE`?person ${firstName} "Jean"`
52
+ * .INSERT`?person ${firstName} "Paul"`
53
+ * .WHERE`?person ${firstName} "Jean"`
54
+ * .build();
55
+ * console.log(query);
56
+ * // DELETE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
57
+ * // INSERT { ?person <http://xmlns.com/foaf/0.1/firstName> "Paul" }
58
+ * // WHERE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
59
+ * ```
60
+ */
18
61
  export declare const DELETE: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "USING_NAMED" | "USING" | "INSERT">) & {
19
62
  DATA: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">;
63
+ WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">;
20
64
  };
65
+ /**
66
+ * SPARQL WITH query fluent interface
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { DELETE } from "ldkit/sparql";
71
+ * import { foaf } from "ldkit/namespaces";
72
+ * import { DataFactory } from "ldkit/rdf";
73
+ *
74
+ * const df = new DataFactory();
75
+ * const firstName = df.namedNode(foaf.firstName);
76
+ * const graph = df.namedNode("http://example.org/graph");
77
+ *
78
+ * const query = WITH(graph).DELETE`?person ${firstName} "Jean"`
79
+ * .INSERT`?person ${firstName} "Paul"`
80
+ * .WHERE`?person ${firstName} "Jean"`
81
+ * .build();
82
+ * console.log(query);
83
+ * // WITH <http://example.org/graph>
84
+ * // DELETE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
85
+ * // INSERT { ?person <http://xmlns.com/foaf/0.1/firstName> "Paul" }
86
+ * // WHERE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
87
+ * ```
88
+ */
21
89
  export declare const WITH: (stringOrNamedNode: string | RDF.NamedNode<string>) => Builders<"INSERT" | "DELETE">;
22
90
  export {};
package/types/mod.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- export { type Context, type IQueryEngine } from "./library/rdf.js";
2
- export { setDefaultContext, setDefaultEngine } from "./library/global.js";
3
- export { type SchemaInterface } from "./library/schema/mod.js";
4
- export { createLens, createResource, type Lens } from "./library/lens/mod.js";
5
- export { createNamespace } from "./library/namespaces/namespace.js";
6
- export { QueryEngine } from "./library/engine/mod.js";
1
+ export { type Options, setGlobalOptions } from "./library/options.js";
2
+ export type { Identity, Property, Schema, SchemaInterface, SchemaSearchInterface, SchemaUpdateInterface, SupportedDataTypes, } from "./library/schema/mod.js";
3
+ export * from "./library/lens/mod.js";
4
+ export * from "./library/namespace.js";
5
+ export * from "./library/engine/mod.js";