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,12 +1,22 @@
1
- import xsd from "../namespaces/xsd.js";
1
+ import { rdf } from "../../namespaces/rdf.js";
2
+ import { xsd } from "../../namespaces/xsd.js";
2
3
  export const expandSchema = (schemaPrototype) => {
4
+ if (typeof schemaPrototype !== "object") {
5
+ throw new Error(`Invalid schema, expected object`);
6
+ }
7
+ if (Object.keys(schemaPrototype).length === 0) {
8
+ throw new Error(`Invalid schema, empty object, expected "@type" key or property definition`);
9
+ }
10
+ const expandShortcut = (value) => {
11
+ return value === "@type" ? rdf.type : value;
12
+ };
3
13
  const expandArray = (stringOrStrings) => {
4
14
  return Array.isArray(stringOrStrings) ? stringOrStrings : [stringOrStrings];
5
15
  };
6
16
  const expandSchemaProperty = (stringOrProperty) => {
7
17
  if (typeof stringOrProperty === "string") {
8
18
  return {
9
- "@id": stringOrProperty,
19
+ "@id": expandShortcut(stringOrProperty),
10
20
  "@type": xsd.string,
11
21
  };
12
22
  }
@@ -14,27 +24,34 @@ export const expandSchema = (schemaPrototype) => {
14
24
  if (!property["@id"]) {
15
25
  throw new Error(`Invalid schema, "@id" key for property missing`);
16
26
  }
27
+ if (property["@inverse"] && property["@multilang"]) {
28
+ throw new Error(`Invalid schema, "@inverse" property cannot be used with "@multilang"`);
29
+ }
17
30
  const validKeys = [
18
- "@context",
31
+ "@schema",
19
32
  "@id",
20
33
  "@type",
21
34
  "@array",
22
35
  "@optional",
23
36
  "@multilang",
37
+ "@inverse",
24
38
  ];
25
39
  const baseProperty = {
26
40
  "@id": "",
27
41
  };
28
42
  const expandedProperty = Object.keys(property).reduce((acc, key) => {
29
- if (key === "@context") {
43
+ if (key === "@schema") {
30
44
  acc[key] = expandSchema(property[key]);
31
45
  }
46
+ else if (key === "@id") {
47
+ acc[key] = expandShortcut(property[key]);
48
+ }
32
49
  else if (validKeys.includes(key)) {
33
50
  acc[key] = property[key];
34
51
  }
35
52
  return acc;
36
53
  }, baseProperty);
37
- if (!baseProperty["@type"] && !baseProperty["@context"]) {
54
+ if (!baseProperty["@type"] && !baseProperty["@schema"]) {
38
55
  baseProperty["@type"] = xsd.string;
39
56
  }
40
57
  return expandedProperty;
@@ -42,12 +59,20 @@ export const expandSchema = (schemaPrototype) => {
42
59
  const baseSchema = {
43
60
  "@type": [],
44
61
  };
62
+ const existingPropertyMap = {};
45
63
  return Object.keys(schemaPrototype).reduce((acc, key) => {
46
64
  if (key === "@type") {
47
65
  acc[key] = expandArray(schemaPrototype[key]);
48
66
  }
49
67
  else {
50
- acc[key] = expandSchemaProperty(schemaPrototype[key]);
68
+ const expandedProperty = expandSchemaProperty(schemaPrototype[key]);
69
+ if (existingPropertyMap[expandedProperty["@id"]]) {
70
+ throw new Error(`Invalid schema, duplicate property "${expandedProperty["@id"]}"`);
71
+ }
72
+ else {
73
+ existingPropertyMap[expandedProperty["@id"]] = true;
74
+ }
75
+ acc[key] = expandedProperty;
51
76
  }
52
77
  return acc;
53
78
  }, baseSchema);
@@ -1,3 +1,4 @@
1
- export { sparql } 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,18 @@
1
+ import { bracesInline, SparqlBuilder } from "./sparql_shared_builders.js";
2
+ class SparqlExpressionBuilder extends SparqlBuilder {
3
+ OPTIONAL(strings, ...values) {
4
+ return this.template(strings, values, "OPTIONAL", bracesInline);
5
+ }
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 const OPTIONAL = (strings, ...values) => new SparqlExpressionBuilder().OPTIONAL(strings, ...values);
@@ -55,6 +55,27 @@ class SparqlQueryBuilder extends SparqlBuilder {
55
55
  return this.template(strings, values, "DESCRIBE");
56
56
  }
57
57
  }
58
+ /**
59
+ * SPARQL SELECT query fluent interface
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * import { SELECT } from "ldkit/sparql";
64
+ *
65
+ * const query = SELECT`?s`.WHERE`?s ?p ?o`.ORDER_BY`?s`.LIMIT(100).build();
66
+ * console.log(query);
67
+ * // SELECT ?s WHERE { ?s ?p ?o } ORDER BY ?s LIMIT 100
68
+ * ```
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * import { SELECT } from "ldkit/sparql";
73
+ *
74
+ * const query = SELECT.DISTINCT`?s`.WHERE`?s ?p ?o`.build();
75
+ * console.log(query);
76
+ * // SELECT DISTINCT ?s WHERE { ?s ?p ?o }
77
+ * ```
78
+ */
58
79
  export const SELECT = Object.assign((strings, ...values) => new SparqlQueryBuilder().SELECT(strings, ...values), {
59
80
  DISTINCT: (strings, ...values) => new SparqlQueryBuilder().SELECT_DISTINCT(strings, ...values),
60
81
  REDUCED: (strings, ...values) => new SparqlQueryBuilder().SELECT_REDUCED(strings, ...values),
@@ -62,12 +83,56 @@ export const SELECT = Object.assign((strings, ...values) => new SparqlQueryBuild
62
83
  return new SparqlQueryBuilder().SELECT `*`;
63
84
  },
64
85
  });
86
+ /**
87
+ * SPARQL CONSTRUCT query fluent interface
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * import { CONSTRUCT } from "ldkit/sparql";
92
+ * import { DataFactory } from "ldkit/rdf";
93
+ *
94
+ * const df = new DataFactory();
95
+ * const sNode = df.namedNode("http://example.org/datasource");
96
+ * const pNode = df.namedNode("http://example.org/hasSubject");
97
+ *
98
+ * const query = CONSTRUCT`${sNode} ${pNode} ?s`.WHERE`?s ?p ?o`.build();
99
+ * console.log(query);
100
+ * // CONSTRUCT { <http://example.org/datasource> <http://example.org/hasSubject> ?s }
101
+ * // WHERE { ?s ?p ?o }
102
+ * ```
103
+ */
65
104
  export const CONSTRUCT = Object.assign((strings, ...values) => new SparqlQueryBuilder().CONSTRUCT(strings, ...values), {
66
105
  WHERE: (strings, ...values) => new SparqlQueryBuilder().CONSTRUCT_WHERE(strings, ...values),
67
106
  });
107
+ /**
108
+ * SPARQL ASK query fluent interface
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * import { ASK } from "ldkit/sparql";
113
+ *
114
+ * const query = ASK`?s ?p ?o`.build();
115
+ * console.log(query); // ASK { ?s ?p ?o }
116
+ * ```
117
+ */
68
118
  export const ASK = Object.assign((strings, ...values) => new SparqlQueryBuilder().ASK(strings, ...values), {
69
119
  FROM: (stringOrNamedNode) => new SparqlQueryBuilder().ASK_FROM(stringOrNamedNode),
70
120
  FROM_NAMED: (stringOrNamedNode) => new SparqlQueryBuilder().ASK_FROM_NAMED(stringOrNamedNode),
71
121
  WHERE: (strings, ...values) => new SparqlQueryBuilder().ASK_WHERE(strings, ...values),
72
122
  });
123
+ /**
124
+ * SPARQL DESCRIBE query fluent interface
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { DESCRIBE } from "ldkit/sparql";
129
+ * import { DataFactory } from "ldkit/rdf";
130
+ *
131
+ * const df = new DataFactory();
132
+ * const node = df.namedNode("http://example.org/resource");
133
+ *
134
+ * const query = DESCRIBE`${node}`.build();
135
+ * console.log(query); // DESCRIBE <http://example.org/resource>
136
+ * ```
137
+ */
73
138
  export const DESCRIBE = (strings, ...values) => new SparqlQueryBuilder().DESCRIBE(strings, ...values);
@@ -1,6 +1,7 @@
1
1
  import { DataFactory } from "../rdf.js";
2
2
  import { sparql } from "./sparql_tag.js";
3
3
  export const braces = (keyword, value) => `${keyword} {\n${value}\n}\n`;
4
+ export const bracesInline = (keyword, value) => `${keyword} { ${value} }`;
4
5
  export const parentheses = (keyword, value) => `${keyword} (${value})\n`;
5
6
  const none = (keyword, value) => `${keyword} ${value}\n`;
6
7
  export class SparqlBuilder {
@@ -1,6 +1,29 @@
1
1
  import { DataFactory } from "../rdf.js";
2
- import xsd from "../namespaces/xsd.js";
2
+ import { xsd } from "../../namespaces/xsd.js";
3
3
  import { stringify } from "./stringify.js";
4
+ /**
5
+ * A template tag for SPARQL queries or its parts. Automatically converts
6
+ * values to SPARQL literals and escapes strings as needed.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { sparql } from "ldkit/sparql";
11
+ * import { DataFactory } from "ldkit/rdf";
12
+ *
13
+ * const df = new DataFactory();
14
+ * const quad = df.quad(
15
+ * df.namedNode("http://example.org/s"),
16
+ * df.namedNode("http://example.org/p"),
17
+ * df.literal("o"),
18
+ * );
19
+ * const query = sparql`SELECT * WHERE { ${quad} }`;
20
+ * console.log(query); // SELECT * WHERE { <http://example.org/s> <http://example.org/p> "o" . }
21
+ * ```
22
+ *
23
+ * @param strings {TemplateStringsArray} template strings
24
+ * @param values {SparqlValue[]}
25
+ * @returns {string} SPARQL query or its part
26
+ */
4
27
  export const sparql = (strings, ...values) => {
5
28
  let counter = 0;
6
29
  let result = "";
@@ -40,6 +63,9 @@ const valueToString = (value) => {
40
63
  }
41
64
  return result;
42
65
  }
66
+ if ("build" in value) {
67
+ return value.build();
68
+ }
43
69
  if (value.termType) {
44
70
  return stringify(value);
45
71
  }
@@ -21,14 +21,84 @@ class SparqlUpdateBuilder extends SparqlBuilder {
21
21
  DELETE_DATA(strings, ...values) {
22
22
  return this.template(strings, values, "DELETE DATA", braces);
23
23
  }
24
+ DELETE_WHERE(strings, ...values) {
25
+ return this.template(strings, values, "DELETE WHERE", braces);
26
+ }
24
27
  WITH(stringOrNamedNode) {
25
28
  return this.namedNode(stringOrNamedNode, "WITH");
26
29
  }
27
30
  }
31
+ /**
32
+ * SPARQL INSERT query fluent interface
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * import { INSERT } from "ldkit/sparql";
37
+ * import { foaf } from "ldkit/namespaces";
38
+ * import { DataFactory } from "ldkit/rdf";
39
+ *
40
+ * const df = new DataFactory();
41
+ * const firstName = df.namedNode(foaf.firstName);
42
+ *
43
+ * const query = INSERT`?person ${firstName} "Paul"`
44
+ * .WHERE`?person ${firstName} "Jean"`
45
+ * .build();
46
+ * console.log(query);
47
+ * // INSERT { ?person <http://xmlns.com/foaf/0.1/firstName> "Paul" }
48
+ * // WHERE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
49
+ * ```
50
+ */
28
51
  export const INSERT = Object.assign((strings, ...values) => new SparqlUpdateBuilder().INSERT(strings, ...values), {
29
52
  DATA: (strings, ...values) => new SparqlUpdateBuilder().INSERT_DATA(strings, ...values),
30
53
  });
54
+ /**
55
+ * SPARQL DELETE query fluent interface
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * import { DELETE } from "ldkit/sparql";
60
+ * import { foaf } from "ldkit/namespaces";
61
+ * import { DataFactory } from "ldkit/rdf";
62
+ *
63
+ * const df = new DataFactory();
64
+ * const firstName = df.namedNode(foaf.firstName);
65
+ *
66
+ * const query = DELETE`?person ${firstName} "Jean"`
67
+ * .INSERT`?person ${firstName} "Paul"`
68
+ * .WHERE`?person ${firstName} "Jean"`
69
+ * .build();
70
+ * console.log(query);
71
+ * // DELETE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
72
+ * // INSERT { ?person <http://xmlns.com/foaf/0.1/firstName> "Paul" }
73
+ * // WHERE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
74
+ * ```
75
+ */
31
76
  export const DELETE = Object.assign((strings, ...values) => new SparqlUpdateBuilder().DELETE(strings, ...values), {
32
77
  DATA: (strings, ...values) => new SparqlUpdateBuilder().DELETE_DATA(strings, ...values),
78
+ WHERE: (strings, ...values) => new SparqlUpdateBuilder().DELETE_WHERE(strings, ...values),
33
79
  });
80
+ /**
81
+ * SPARQL WITH query fluent interface
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * import { DELETE } from "ldkit/sparql";
86
+ * import { foaf } from "ldkit/namespaces";
87
+ * import { DataFactory } from "ldkit/rdf";
88
+ *
89
+ * const df = new DataFactory();
90
+ * const firstName = df.namedNode(foaf.firstName);
91
+ * const graph = df.namedNode("http://example.org/graph");
92
+ *
93
+ * const query = WITH(graph).DELETE`?person ${firstName} "Jean"`
94
+ * .INSERT`?person ${firstName} "Paul"`
95
+ * .WHERE`?person ${firstName} "Jean"`
96
+ * .build();
97
+ * console.log(query);
98
+ * // WITH <http://example.org/graph>
99
+ * // DELETE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
100
+ * // INSERT { ?person <http://xmlns.com/foaf/0.1/firstName> "Paul" }
101
+ * // WHERE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
102
+ * ```
103
+ */
34
104
  export const WITH = (stringOrNamedNode) => new SparqlUpdateBuilder().WITH(stringOrNamedNode);
@@ -1,5 +1,5 @@
1
1
  import { DefaultGraph } from "../rdf.js";
2
- import xsd from "../namespaces/xsd.js";
2
+ import { xsd } from "../../namespaces/xsd.js";
3
3
  import { escape } from "./escape.js";
4
4
  export const blankNode = (term) => {
5
5
  return `_:${term.value}`;
@@ -12,9 +12,8 @@ export const variable = (term) => {
12
12
  };
13
13
  export const literal = (term) => {
14
14
  const datatype = term.datatype.value;
15
- if (datatype === xsd.integer || datatype === xsd.boolean ||
16
- datatype === xsd.decimal) {
17
- return term.value;
15
+ if (datatype === xsd.boolean) {
16
+ return term.value == "true" || term.value == "1" ? "true" : "false";
18
17
  }
19
18
  const value = `"${escape(term.value)}"`;
20
19
  if (term.language) {
package/esm/mod.js CHANGED
@@ -1,4 +1,4 @@
1
- export { setDefaultContext, setDefaultEngine } from "./library/global.js";
2
- export { createLens, createResource } from "./library/lens/mod.js";
3
- export { createNamespace } from "./library/namespaces/namespace.js";
4
- export { QueryEngine } from "./library/engine/mod.js";
1
+ export { setGlobalOptions } from "./library/options.js";
2
+ export * from "./library/lens/mod.js";
3
+ export * from "./library/namespace.js";
4
+ export * from "./library/engine/mod.js";
@@ -1,5 +1,10 @@
1
- import { createNamespace } from "./namespace.js";
2
- export default createNamespace({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * DBpedia Ontology
4
+ *
5
+ * `@dbo: <http://dbpedia.org/ontology/>`
6
+ */
7
+ export const dbo = createNamespace({
3
8
  iri: "http://dbpedia.org/ontology/",
4
9
  prefix: "dbo:",
5
10
  terms: [
@@ -1,5 +1,10 @@
1
- import { createNamespace } from "./namespace.js";
2
- export default createNamespace({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * Dublin Core Metadata Element Set, Version 1.1
4
+ *
5
+ * `@dc: <http://purl.org/dc/elements/1.1/>`,
6
+ */
7
+ export const dc = createNamespace({
3
8
  iri: "http://purl.org/dc/elements/1.1/",
4
9
  prefix: "dc:",
5
10
  terms: [
@@ -1,5 +1,10 @@
1
- import { createNamespace } from "./namespace.js";
2
- export default createNamespace({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * DCMI Metadata Terms
4
+ *
5
+ * `@dcterms: <http://purl.org/dc/terms/>`,
6
+ */
7
+ export const dcterms = createNamespace({
3
8
  iri: "http://purl.org/dc/terms/",
4
9
  prefix: "dcterms:",
5
10
  terms: [
@@ -1,5 +1,10 @@
1
- import { createNamespace } from "./namespace.js";
2
- export default createNamespace({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * The Friend of a Friend (FOAF) vocabulary, described using W3C RDF Schema and the Web Ontology Language.
4
+ *
5
+ * `@foaf: <http://xmlns.com/foaf/0.1/>`,
6
+ */
7
+ export const foaf = createNamespace({
3
8
  iri: "http://xmlns.com/foaf/0.1/",
4
9
  prefix: "foaf:",
5
10
  terms: [
@@ -1,5 +1,10 @@
1
- import { createNamespace } from "./namespace.js";
2
- export default createNamespace({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * GoodRelations Ontology
4
+ *
5
+ * `@gr: <http://purl.org/goodrelations/v1#>`,
6
+ */
7
+ export const gr = createNamespace({
3
8
  iri: "http://purl.org/goodrelations/v1#",
4
9
  prefix: "gr:",
5
10
  terms: [
@@ -0,0 +1,11 @@
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * LDkit Ontology
4
+ *
5
+ * `@ldkit: <http://ldkit.io/ontology/>`,
6
+ */
7
+ export const ldkit = createNamespace({
8
+ iri: "https://ldkit.io/ontology/",
9
+ prefix: "ldkit:",
10
+ terms: ["Resource", "IRI"],
11
+ });
@@ -0,0 +1,91 @@
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * OWL Web Ontology Language
4
+ *
5
+ * `@owl: <http://www.w3.org/2002/07/owl#>`,
6
+ */
7
+ export const owl = createNamespace({
8
+ iri: "http://www.w3.org/2002/07/owl#",
9
+ prefix: "owl:",
10
+ terms: [
11
+ "owl:AllDifferent",
12
+ "owl:AllDisjointClasses",
13
+ "owl:AllDisjointProperties",
14
+ "owl:allValuesFrom",
15
+ "owl:annotatedProperty",
16
+ "owl:annotatedSource",
17
+ "owl:annotatedTarget",
18
+ "owl:Annotation",
19
+ "owl:AnnotationProperty",
20
+ "owl:assertionProperty",
21
+ "owl:AsymmetricProperty",
22
+ "owl:Axiom",
23
+ "owl:backwardCompatibleWith",
24
+ "owl:bottomDataProperty",
25
+ "owl:bottomObjectProperty",
26
+ "owl:cardinality",
27
+ "owl:Class",
28
+ "owl:complementOf",
29
+ "owl:DataRange",
30
+ "owl:datatypeComplementOf",
31
+ "owl:DatatypeProperty",
32
+ "owl:deprecated",
33
+ "owl:DeprecatedClass",
34
+ "owl:DeprecatedProperty",
35
+ "owl:differentFrom",
36
+ "owl:disjointUnionOf",
37
+ "owl:disjointWith",
38
+ "owl:distinctMembers",
39
+ "owl:equivalentClass",
40
+ "owl:equivalentProperty",
41
+ "owl:FunctionalProperty",
42
+ "owl:hasKey",
43
+ "owl:hasSelf",
44
+ "owl:hasValue",
45
+ "owl:imports",
46
+ "owl:incompatibleWith",
47
+ "owl:intersectionOf",
48
+ "owl:InverseFunctionalProperty",
49
+ "owl:inverseOf",
50
+ "owl:IrreflexiveProperty",
51
+ "owl:maxCardinality",
52
+ "owl:maxQualifiedCardinality",
53
+ "owl:members",
54
+ "owl:minCardinality",
55
+ "owl:minQualifiedCardinality",
56
+ "owl:NamedIndividual",
57
+ "owl:NegativePropertyAssertion",
58
+ "owl:Nothing",
59
+ "owl:ObjectProperty",
60
+ "owl:onClass",
61
+ "owl:onDataRange",
62
+ "owl:onDatatype",
63
+ "owl:oneOf",
64
+ "owl:onProperty",
65
+ "owl:onProperties",
66
+ "owl:Ontology",
67
+ "owl:OntologyProperty",
68
+ "owl:priorVersion",
69
+ "owl:propertyChainAxiom",
70
+ "owl:propertyDisjointWith",
71
+ "owl:qualifiedCardinality",
72
+ "owl:rational",
73
+ "owl:real",
74
+ "owl:ReflexiveProperty",
75
+ "owl:Restriction",
76
+ "owl:sameAs",
77
+ "owl:someValuesFrom",
78
+ "owl:sourceIndividual",
79
+ "owl:SymmetricProperty",
80
+ "owl:targetIndividual",
81
+ "owl:targetValue",
82
+ "owl:Thing",
83
+ "owl:topDataProperty",
84
+ "owl:topObjectProperty",
85
+ "owl:TransitiveProperty",
86
+ "owl:unionOf",
87
+ "owl:versionInfo",
88
+ "owl:versionIRI",
89
+ "owl:withRestrictions",
90
+ ],
91
+ });
@@ -1,7 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const namespace_js_1 = require("./namespace.js");
4
- exports.default = (0, namespace_js_1.createNamespace)({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * The RDF Concepts Vocabulary (RDF)
4
+ *
5
+ * `@rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>`,
6
+ */
7
+ export const rdf = createNamespace({
5
8
  iri: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
6
9
  prefix: "rdf:",
7
10
  terms: [
@@ -1,7 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const namespace_js_1 = require("./namespace.js");
4
- exports.default = (0, namespace_js_1.createNamespace)({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * The RDF Schema vocabulary (RDFS)
4
+ *
5
+ * `@rdfs: <http://www.w3.org/2000/01/rdf-schema#>`,
6
+ */
7
+ export const rdfs = createNamespace({
5
8
  iri: "http://www.w3.org/2000/01/rdf-schema#",
6
9
  prefix: "rdfs:",
7
10
  terms: [
@@ -1,5 +1,10 @@
1
- import { createNamespace } from "./namespace.js";
2
- export default createNamespace({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * Schema.org vocabulary
4
+ *
5
+ * `@schema: <http://schema.org/>`,
6
+ */
7
+ export const schema = createNamespace({
3
8
  iri: "http://schema.org/",
4
9
  prefix: "schema:",
5
10
  terms: [
@@ -1,5 +1,10 @@
1
- import { createNamespace } from "./namespace.js";
2
- export default createNamespace({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * SIOC Core Ontology Namespace
4
+ *
5
+ * `@sioc: <http://rdfs.org/sioc/ns#>`,
6
+ */
7
+ export const sioc = createNamespace({
3
8
  iri: "http://rdfs.org/sioc/ns#",
4
9
  prefix: "sioc:",
5
10
  terms: [
@@ -1,7 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const namespace_js_1 = require("./namespace.js");
4
- exports.default = (0, namespace_js_1.createNamespace)({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * SKOS - Simple Knowledge Organization System
4
+ *
5
+ * `@skos: <http://www.w3.org/2004/02/skos/core#>`,
6
+ */
7
+ export const skos = createNamespace({
5
8
  iri: "http://www.w3.org/2004/02/skos/core#",
6
9
  prefix: "skos:",
7
10
  terms: [
@@ -1,7 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const namespace_js_1 = require("./namespace.js");
4
- exports.default = (0, namespace_js_1.createNamespace)({
1
+ import { createNamespace } from "../library/namespace.js";
2
+ /**
3
+ * XML Schema Definition Language (XSD)
4
+ *
5
+ * `@xsd: <http://www.w3.org/2001/XMLSchema#>`,
6
+ */
7
+ export const xsd = createNamespace({
5
8
  iri: "http://www.w3.org/2001/XMLSchema#",
6
9
  prefix: "xsd:",
7
10
  terms: [
package/esm/namespaces.js CHANGED
@@ -1 +1,30 @@
1
- export * from "./library/namespaces/mod.js";
1
+ /**
2
+ * Popular namespaces used in Linked Data, fully compatible with LDkit,
3
+ * offering autocompletion and type checking in IDE.
4
+ *
5
+ * Create your own namespaces using {@link createNamespace} helper.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { rdf, schema } from "ldkit/namespaces";
10
+ *
11
+ * console.log(rdf.type); // "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
12
+ * console.log(schema.Person); // "http://schema.org/Person"
13
+ * ```
14
+ *
15
+ * @module
16
+ */
17
+ export { dbo } from "./namespaces/dbo.js";
18
+ export { dc } from "./namespaces/dc.js";
19
+ export { dcterms } from "./namespaces/dcterms.js";
20
+ export { foaf } from "./namespaces/foaf.js";
21
+ export { gr } from "./namespaces/gr.js";
22
+ export { ldkit } from "./namespaces/ldkit.js";
23
+ export { owl } from "./namespaces/owl.js";
24
+ export { rdf } from "./namespaces/rdf.js";
25
+ export { rdfs } from "./namespaces/rdfs.js";
26
+ export { schema } from "./namespaces/schema.js";
27
+ export { sioc } from "./namespaces/sioc.js";
28
+ export { skos } from "./namespaces/skos.js";
29
+ export { xsd } from "./namespaces/xsd.js";
30
+ export * from "./library/namespace.js";