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