ldkit 0.0.1 → 0.0.2
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.
- package/esm/_dnt.shims.js +70 -0
- package/esm/library/comunica/bundle.js +82389 -0
- package/esm/library/comunica/mod.js +1 -0
- package/esm/library/context.js +13 -0
- package/esm/library/decoder.js +203 -0
- package/esm/library/encoder.js +116 -0
- package/esm/library/engine.js +9 -0
- package/esm/library/namespaces/dcterms.js +105 -0
- package/esm/library/namespaces/ldkit.js +6 -0
- package/esm/library/namespaces/mod.js +7 -0
- package/esm/library/namespaces/namespace.js +11 -0
- package/esm/library/namespaces/rdf.js +29 -0
- package/esm/library/namespaces/schema.js +2698 -0
- package/esm/library/namespaces/skos.js +39 -0
- package/esm/library/namespaces/xsd.js +57 -0
- package/esm/library/rdf.js +19 -0
- package/esm/library/resource/mod.js +1 -0
- package/esm/library/resource/query_builder.js +147 -0
- package/esm/library/resource/query_helper.js +102 -0
- package/esm/library/resource/resource.js +102 -0
- package/esm/library/resource/types.js +1 -0
- package/esm/library/rxjs.js +2 -0
- package/esm/library/schema/data_types.js +37 -0
- package/esm/library/schema/interface.js +1 -0
- package/esm/library/schema/mod.js +1 -0
- package/esm/library/schema/schema.js +1 -0
- package/esm/library/schema/utils.js +58 -0
- package/esm/library/sparql.js +2 -0
- package/esm/mod.js +3 -0
- package/package.json +16 -5
- package/script/_dnt.shims.js +80 -0
- package/script/library/comunica/bundle.js +82415 -0
- package/script/library/comunica/mod.js +5 -0
- package/script/library/context.js +19 -0
- package/script/library/decoder.js +207 -0
- package/script/library/encoder.js +120 -0
- package/script/library/engine.js +16 -0
- package/script/library/namespaces/dcterms.js +107 -0
- package/script/library/namespaces/ldkit.js +8 -0
- package/script/library/namespaces/mod.js +20 -0
- package/script/library/namespaces/namespace.js +15 -0
- package/script/library/namespaces/rdf.js +31 -0
- package/script/library/namespaces/schema.js +2700 -0
- package/script/library/namespaces/skos.js +41 -0
- package/script/library/namespaces/xsd.js +59 -0
- package/script/library/rdf.js +54 -0
- package/script/library/resource/mod.js +6 -0
- package/script/library/resource/query_builder.js +151 -0
- package/script/library/resource/query_helper.js +106 -0
- package/script/library/resource/resource.js +107 -0
- package/script/{npm.js → library/resource/types.js} +0 -2
- package/script/library/rxjs.js +11 -0
- package/script/library/schema/data_types.js +39 -0
- package/script/library/schema/interface.js +2 -0
- package/script/library/schema/mod.js +6 -0
- package/script/library/schema/schema.js +2 -0
- package/script/library/schema/utils.js +63 -0
- package/script/library/sparql.js +13 -0
- package/script/mod.js +10 -0
- package/esm/npm.js +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
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)({
|
|
5
|
+
iri: "http://www.w3.org/2004/02/skos/core#",
|
|
6
|
+
prefix: "skos:",
|
|
7
|
+
terms: [
|
|
8
|
+
"Collection",
|
|
9
|
+
"Concept",
|
|
10
|
+
"ConceptScheme",
|
|
11
|
+
"OrderedCollection",
|
|
12
|
+
"altLabel",
|
|
13
|
+
"broadMatch",
|
|
14
|
+
"broader",
|
|
15
|
+
"broaderTransitive",
|
|
16
|
+
"changeNote",
|
|
17
|
+
"closeMatch",
|
|
18
|
+
"definition",
|
|
19
|
+
"editorialNote",
|
|
20
|
+
"exactMatch",
|
|
21
|
+
"example",
|
|
22
|
+
"hasTopConcept",
|
|
23
|
+
"hiddenLabel",
|
|
24
|
+
"historyNote",
|
|
25
|
+
"inScheme",
|
|
26
|
+
"mappingRelation",
|
|
27
|
+
"member",
|
|
28
|
+
"memberList",
|
|
29
|
+
"narrowMatch",
|
|
30
|
+
"narrower",
|
|
31
|
+
"narrowerTransitive",
|
|
32
|
+
"notation",
|
|
33
|
+
"note",
|
|
34
|
+
"prefLabel",
|
|
35
|
+
"related",
|
|
36
|
+
"relatedMatch",
|
|
37
|
+
"scopeNote",
|
|
38
|
+
"semanticRelation",
|
|
39
|
+
"topConceptOf",
|
|
40
|
+
],
|
|
41
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
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)({
|
|
5
|
+
iri: "http://www.w3.org/2001/XMLSchema#",
|
|
6
|
+
prefix: "xsd:",
|
|
7
|
+
terms: [
|
|
8
|
+
"ENTITIES",
|
|
9
|
+
"ENTITY",
|
|
10
|
+
"ID",
|
|
11
|
+
"IDREF",
|
|
12
|
+
"IDREFS",
|
|
13
|
+
"NCName",
|
|
14
|
+
"NMTOKEN",
|
|
15
|
+
"NMTOKENS",
|
|
16
|
+
"NOTATION",
|
|
17
|
+
"Name",
|
|
18
|
+
"QName",
|
|
19
|
+
"anyAtomicType",
|
|
20
|
+
"anySimpleType",
|
|
21
|
+
"anyType",
|
|
22
|
+
"anyURI",
|
|
23
|
+
"base64Binary",
|
|
24
|
+
"boolean",
|
|
25
|
+
"byte",
|
|
26
|
+
"date",
|
|
27
|
+
"dateTime",
|
|
28
|
+
"dateTimeStamp",
|
|
29
|
+
"dayTimeDuration",
|
|
30
|
+
"decimal",
|
|
31
|
+
"double",
|
|
32
|
+
"duration",
|
|
33
|
+
"float",
|
|
34
|
+
"gDay",
|
|
35
|
+
"gMonth",
|
|
36
|
+
"gMonthDay",
|
|
37
|
+
"gYear",
|
|
38
|
+
"gYearMonth",
|
|
39
|
+
"hexBinary",
|
|
40
|
+
"int",
|
|
41
|
+
"integer",
|
|
42
|
+
"language",
|
|
43
|
+
"long",
|
|
44
|
+
"negativeInteger",
|
|
45
|
+
"nonNegativeInteger",
|
|
46
|
+
"nonPositiveInteger",
|
|
47
|
+
"normalizedString",
|
|
48
|
+
"positiveInteger",
|
|
49
|
+
"short",
|
|
50
|
+
"string",
|
|
51
|
+
"time",
|
|
52
|
+
"token",
|
|
53
|
+
"unsignedByte",
|
|
54
|
+
"unsignedInt",
|
|
55
|
+
"unsignedLong",
|
|
56
|
+
"unsignedShort",
|
|
57
|
+
"yearMonthDuration",
|
|
58
|
+
],
|
|
59
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.quadsToGraph = exports.variable = exports.quad = exports.literal = exports.blankNode = exports.namedNode = exports.DataFactory = exports.toRdf = exports.fromRdf = void 0;
|
|
27
|
+
var rdf_literal_1 = require("rdf-literal");
|
|
28
|
+
Object.defineProperty(exports, "fromRdf", { enumerable: true, get: function () { return rdf_literal_1.fromRdf; } });
|
|
29
|
+
Object.defineProperty(exports, "toRdf", { enumerable: true, get: function () { return rdf_literal_1.toRdf; } });
|
|
30
|
+
const DataFactory = __importStar(require("rdf-data-factory"));
|
|
31
|
+
var rdf_data_factory_1 = require("rdf-data-factory");
|
|
32
|
+
Object.defineProperty(exports, "DataFactory", { enumerable: true, get: function () { return rdf_data_factory_1.DataFactory; } });
|
|
33
|
+
const namedNode = (value) => new DataFactory.NamedNode(value);
|
|
34
|
+
exports.namedNode = namedNode;
|
|
35
|
+
const blankNode = (value) => new DataFactory.BlankNode(value);
|
|
36
|
+
exports.blankNode = blankNode;
|
|
37
|
+
const literal = (value, languageOrDatatype) => new DataFactory.Literal(value, languageOrDatatype);
|
|
38
|
+
exports.literal = literal;
|
|
39
|
+
const quad = (subject, predicate, object, graph) => new DataFactory.Quad(subject, predicate, object, graph || DataFactory.DefaultGraph.INSTANCE);
|
|
40
|
+
exports.quad = quad;
|
|
41
|
+
const variable = (value) => new DataFactory.Variable(value);
|
|
42
|
+
exports.variable = variable;
|
|
43
|
+
const quadsToGraph = (quads) => {
|
|
44
|
+
const graph = new Map();
|
|
45
|
+
for (const quad of quads) {
|
|
46
|
+
const s = quad.subject.value;
|
|
47
|
+
const p = quad.predicate.value;
|
|
48
|
+
const predicateMap = graph.get(s) || graph.set(s, new Map()).get(s);
|
|
49
|
+
const termArray = predicateMap.get(p) || predicateMap.set(p, []).get(p);
|
|
50
|
+
termArray.push(quad.object);
|
|
51
|
+
}
|
|
52
|
+
return graph;
|
|
53
|
+
};
|
|
54
|
+
exports.quadsToGraph = quadsToGraph;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Resource = exports.createResource = void 0;
|
|
4
|
+
var resource_js_1 = require("./resource.js");
|
|
5
|
+
Object.defineProperty(exports, "createResource", { enumerable: true, get: function () { return resource_js_1.createResource; } });
|
|
6
|
+
Object.defineProperty(exports, "Resource", { enumerable: true, get: function () { return resource_js_1.Resource; } });
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryBuilder = void 0;
|
|
4
|
+
const mod_js_1 = require("../schema/mod.js");
|
|
5
|
+
const sparql_js_1 = require("../sparql.js");
|
|
6
|
+
const rdf_js_1 = require("../rdf.js");
|
|
7
|
+
const mod_js_2 = require("../namespaces/mod.js");
|
|
8
|
+
const encoder_js_1 = require("../encoder.js");
|
|
9
|
+
const query_helper_js_1 = require("./query_helper.js");
|
|
10
|
+
class QueryBuilder {
|
|
11
|
+
constructor(schema, context) {
|
|
12
|
+
Object.defineProperty(this, "schema", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: void 0
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "schemaProperties", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: void 0
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "context", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: void 0
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(this, "deleteQuery", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: (iris) => {
|
|
35
|
+
return (0, sparql_js_1.DELETE) `
|
|
36
|
+
?s ?p ?o
|
|
37
|
+
`.WHERE `
|
|
38
|
+
?s ?p ?o .
|
|
39
|
+
VALUES ?s { ${iris.map(rdf_js_1.namedNode)} }
|
|
40
|
+
`.build();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
this.schema = schema;
|
|
44
|
+
this.schemaProperties = (0, mod_js_1.getSchemaProperties)(this.schema);
|
|
45
|
+
this.context = context;
|
|
46
|
+
}
|
|
47
|
+
getResourceSignature() {
|
|
48
|
+
return (0, rdf_js_1.quad)((0, rdf_js_1.variable)("iri"), (0, rdf_js_1.namedNode)(mod_js_2.rdf.type), (0, rdf_js_1.namedNode)(mod_js_2.ldkit.Resource));
|
|
49
|
+
}
|
|
50
|
+
getTypesSignature() {
|
|
51
|
+
return (0, rdf_js_1.quad)((0, rdf_js_1.variable)("iri"), (0, rdf_js_1.namedNode)(mod_js_2.rdf.type), (0, rdf_js_1.variable)("iri_type"));
|
|
52
|
+
}
|
|
53
|
+
entitiesToQuads(entities) {
|
|
54
|
+
const quadArrays = entities.map((entity) => (0, encoder_js_1.encode)(entity, this.schema, this.context));
|
|
55
|
+
return [].concat(...quadArrays);
|
|
56
|
+
}
|
|
57
|
+
getShape(includeOptional = false, wrapOptional = true, omitRootTypes = false) {
|
|
58
|
+
const mainVar = "iri";
|
|
59
|
+
const conditions = [];
|
|
60
|
+
const populateConditionsRecursive = (s, varPrefix) => {
|
|
61
|
+
const rdfType = s["@type"];
|
|
62
|
+
const properties = (0, mod_js_1.getSchemaProperties)(s);
|
|
63
|
+
if (varPrefix !== "iri" || !omitRootTypes) {
|
|
64
|
+
rdfType.forEach((type) => {
|
|
65
|
+
conditions.push((0, rdf_js_1.quad)((0, rdf_js_1.variable)(varPrefix), (0, rdf_js_1.namedNode)(mod_js_2.rdf.type), (0, rdf_js_1.namedNode)(type)));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
Object.keys(properties).forEach((prop, index) => {
|
|
69
|
+
const property = properties[prop];
|
|
70
|
+
const isOptional = property["@optional"];
|
|
71
|
+
if (!includeOptional && isOptional) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (wrapOptional && isOptional) {
|
|
75
|
+
conditions.push((0, sparql_js_1.$) `\nOPTIONAL {`);
|
|
76
|
+
}
|
|
77
|
+
conditions.push((0, rdf_js_1.quad)((0, rdf_js_1.variable)(varPrefix), (0, rdf_js_1.namedNode)(property["@id"]), (0, rdf_js_1.variable)(`${varPrefix}_${index}`)));
|
|
78
|
+
if (typeof property["@context"] === "object") {
|
|
79
|
+
populateConditionsRecursive(property["@context"], `${varPrefix}_${index}`);
|
|
80
|
+
}
|
|
81
|
+
if (wrapOptional && isOptional) {
|
|
82
|
+
conditions.push((0, sparql_js_1.$) `\n}\n`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
populateConditionsRecursive(this.schema, mainVar);
|
|
87
|
+
return conditions;
|
|
88
|
+
}
|
|
89
|
+
countQuery() {
|
|
90
|
+
const quads = this.getShape();
|
|
91
|
+
return (0, sparql_js_1.SELECT) `(count(?iri) as ?count)`.WHERE `${quads}`.build();
|
|
92
|
+
}
|
|
93
|
+
getQuery(where, limit = 1000) {
|
|
94
|
+
const selectSubQuery = (0, sparql_js_1.SELECT) `
|
|
95
|
+
${(0, rdf_js_1.variable)("iri")}
|
|
96
|
+
`.WHERE `
|
|
97
|
+
${this.getShape(false, true)}
|
|
98
|
+
${where}
|
|
99
|
+
`.LIMIT(limit);
|
|
100
|
+
const query = (0, sparql_js_1.CONSTRUCT) `
|
|
101
|
+
${this.getResourceSignature()}
|
|
102
|
+
${this.getTypesSignature()}
|
|
103
|
+
${this.getShape(true, false, true)}
|
|
104
|
+
`.WHERE `
|
|
105
|
+
${this.getTypesSignature()}
|
|
106
|
+
${this.getShape(true, true, true)}
|
|
107
|
+
{
|
|
108
|
+
${selectSubQuery}
|
|
109
|
+
}
|
|
110
|
+
`.build();
|
|
111
|
+
return query;
|
|
112
|
+
}
|
|
113
|
+
getByIrisQuery(iris) {
|
|
114
|
+
const query = (0, sparql_js_1.CONSTRUCT) `
|
|
115
|
+
${this.getResourceSignature()}
|
|
116
|
+
${this.getTypesSignature()}
|
|
117
|
+
${this.getShape(true, false, true)}
|
|
118
|
+
`.WHERE `
|
|
119
|
+
${this.getTypesSignature()}
|
|
120
|
+
${this.getShape(true, true, true)}
|
|
121
|
+
VALUES ?iri {
|
|
122
|
+
${iris.map(rdf_js_1.namedNode)}
|
|
123
|
+
}
|
|
124
|
+
`.build();
|
|
125
|
+
return query;
|
|
126
|
+
}
|
|
127
|
+
insertQuery(entities) {
|
|
128
|
+
const quads = this.entitiesToQuads(entities);
|
|
129
|
+
return this.insertDataQuery(quads);
|
|
130
|
+
}
|
|
131
|
+
insertDataQuery(quads) {
|
|
132
|
+
return sparql_js_1.INSERT.DATA `${quads}`.build();
|
|
133
|
+
}
|
|
134
|
+
deleteDataQuery(quads) {
|
|
135
|
+
return (0, sparql_js_1.$) `DELETE DATA { ${quads} }`.toString();
|
|
136
|
+
}
|
|
137
|
+
updateQuery(entities) {
|
|
138
|
+
const deleteQuads = [];
|
|
139
|
+
const insertQuads = [];
|
|
140
|
+
const whereQuads = [];
|
|
141
|
+
entities.forEach((entity, index) => {
|
|
142
|
+
const helper = new query_helper_js_1.QueryHelper(entity, this.schema, this.context, 1000 * index);
|
|
143
|
+
deleteQuads.push(...helper.getDeleteQuads());
|
|
144
|
+
insertQuads.push(...helper.getInsertQuads());
|
|
145
|
+
whereQuads.push(...helper.getWhereQuads());
|
|
146
|
+
});
|
|
147
|
+
return (0, sparql_js_1.DELETE) `${deleteQuads}`.INSERT `${insertQuads}`
|
|
148
|
+
.WHERE `${deleteQuads}`.build();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.QueryBuilder = QueryBuilder;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryHelper = void 0;
|
|
4
|
+
const encoder_js_1 = require("../encoder.js");
|
|
5
|
+
class QueryHelper {
|
|
6
|
+
constructor(entity, schema, context, variableInitCounter = 0) {
|
|
7
|
+
Object.defineProperty(this, "entity", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: void 0
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "schema", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "context", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "variableInitCounter", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "quads", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "variableQuads", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: void 0
|
|
42
|
+
});
|
|
43
|
+
this.entity = entity;
|
|
44
|
+
this.schema = schema;
|
|
45
|
+
this.context = context;
|
|
46
|
+
this.variableInitCounter = variableInitCounter;
|
|
47
|
+
}
|
|
48
|
+
getQuads() {
|
|
49
|
+
if (!this.quads) {
|
|
50
|
+
this.quads = (0, encoder_js_1.encode)(this.entity, this.schema, this.context, this.variableInitCounter);
|
|
51
|
+
}
|
|
52
|
+
return this.quads;
|
|
53
|
+
}
|
|
54
|
+
getVariableQuads() {
|
|
55
|
+
if (!this.variableQuads) {
|
|
56
|
+
this.variableQuads = (0, encoder_js_1.encode)(this.getEntityWithReplacedVariables(), this.schema, this.context, this.variableInitCounter);
|
|
57
|
+
}
|
|
58
|
+
return this.variableQuads;
|
|
59
|
+
}
|
|
60
|
+
getDeleteQuads() {
|
|
61
|
+
return this.getVariableQuads().filter((quad) => quad.object.termType === "Variable");
|
|
62
|
+
}
|
|
63
|
+
getInsertQuads() {
|
|
64
|
+
return this.getQuads();
|
|
65
|
+
}
|
|
66
|
+
getWhereQuads() {
|
|
67
|
+
return this.getVariableQuads();
|
|
68
|
+
}
|
|
69
|
+
getEntityWithReplacedVariables() {
|
|
70
|
+
return this.replaceVariables(this.entity, this.schema);
|
|
71
|
+
}
|
|
72
|
+
replaceVariables(entity, schema) {
|
|
73
|
+
return Object.keys(entity).reduce((output, key) => {
|
|
74
|
+
const value = entity[key];
|
|
75
|
+
if (key === "$id") {
|
|
76
|
+
output.$id = value;
|
|
77
|
+
return output;
|
|
78
|
+
}
|
|
79
|
+
if (key === "$type") {
|
|
80
|
+
output.$type = value;
|
|
81
|
+
return output;
|
|
82
|
+
}
|
|
83
|
+
const property = schema[key];
|
|
84
|
+
if (!property) {
|
|
85
|
+
throw new Error("Unknown field '${key}' detected in entity");
|
|
86
|
+
}
|
|
87
|
+
if (!property["@context"]) {
|
|
88
|
+
output[key] = null;
|
|
89
|
+
return output;
|
|
90
|
+
}
|
|
91
|
+
if (property["@array"]) {
|
|
92
|
+
if (value.length === 0) {
|
|
93
|
+
output[key] = null;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
output[key] = value.map((subEntity) => this.replaceVariables(subEntity, property["@context"]));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
output[key] = this.replaceVariables(value, property["@context"]);
|
|
101
|
+
}
|
|
102
|
+
return output;
|
|
103
|
+
}, {});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.QueryHelper = QueryHelper;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Resource = exports.createResource = void 0;
|
|
4
|
+
const rxjs_js_1 = require("../rxjs.js");
|
|
5
|
+
const engine_js_1 = require("../engine.js");
|
|
6
|
+
const context_js_1 = require("../context.js");
|
|
7
|
+
const mod_js_1 = require("../schema/mod.js");
|
|
8
|
+
const decoder_js_1 = require("../decoder.js");
|
|
9
|
+
const query_builder_js_1 = require("./query_builder.js");
|
|
10
|
+
const createResource = (spec, context) => new Resource(spec, context);
|
|
11
|
+
exports.createResource = createResource;
|
|
12
|
+
class Resource {
|
|
13
|
+
constructor(schema, context) {
|
|
14
|
+
Object.defineProperty(this, "schema", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "context", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "queryBuilder", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "$trigger", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: new rxjs_js_1.BehaviorSubject(null)
|
|
37
|
+
});
|
|
38
|
+
this.schema = (0, mod_js_1.expandSchema)(schema);
|
|
39
|
+
this.context = (0, context_js_1.resolveContext)(context);
|
|
40
|
+
this.queryBuilder = new query_builder_js_1.QueryBuilder(this.schema, this.context);
|
|
41
|
+
}
|
|
42
|
+
decode(graph) {
|
|
43
|
+
return (0, decoder_js_1.decode)(graph, this.schema, this.context);
|
|
44
|
+
}
|
|
45
|
+
count() {
|
|
46
|
+
const q = this.queryBuilder.countQuery();
|
|
47
|
+
console.log(q);
|
|
48
|
+
return this.$trigger.pipe((0, rxjs_js_1.switchMap)(() => (0, engine_js_1.bindingsQuery)(q, this.context)), (0, rxjs_js_1.map)((bindings) => {
|
|
49
|
+
console.warn("BINDINGS", bindings);
|
|
50
|
+
return parseInt(bindings[0].get("count").value);
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
//exists(entity: Identity) {}
|
|
54
|
+
query(sparqlConstructQuery) {
|
|
55
|
+
console.log(sparqlConstructQuery);
|
|
56
|
+
return (0, engine_js_1.quadsQuery)(sparqlConstructQuery, this.context).pipe((0, rxjs_js_1.map)((graph) => {
|
|
57
|
+
return this.decode(graph);
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
find(where, limit) {
|
|
61
|
+
const q = this.queryBuilder.getQuery(where, limit);
|
|
62
|
+
console.log(q);
|
|
63
|
+
return this.$trigger.pipe((0, rxjs_js_1.switchMap)(() => (0, engine_js_1.quadsQuery)(q, this.context)), (0, rxjs_js_1.map)((graph) => {
|
|
64
|
+
return this.decode(graph);
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
findByIri(iri) {
|
|
68
|
+
return this.findByIris([iri]).pipe((0, rxjs_js_1.map)((result) => (result.length > 0 ? result[0] : undefined)));
|
|
69
|
+
}
|
|
70
|
+
findByIris(iris) {
|
|
71
|
+
const q = this.queryBuilder.getByIrisQuery(iris);
|
|
72
|
+
console.log(q);
|
|
73
|
+
return this.$trigger.pipe((0, rxjs_js_1.switchMap)(() => (0, engine_js_1.quadsQuery)(q, this.context)), (0, rxjs_js_1.map)((graph) => {
|
|
74
|
+
return this.decode(graph);
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
updateQuery(query) {
|
|
78
|
+
console.log(query);
|
|
79
|
+
const result = (0, engine_js_1.updateQuery)(query, this.context).pipe((0, rxjs_js_1.tap)(() => this.$trigger.next(null)), (0, rxjs_js_1.share)());
|
|
80
|
+
result.subscribe();
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
insert(...entities) {
|
|
84
|
+
const q = this.queryBuilder.insertQuery(entities);
|
|
85
|
+
return this.updateQuery(q);
|
|
86
|
+
}
|
|
87
|
+
insertData(...quads) {
|
|
88
|
+
const q = this.queryBuilder.insertDataQuery(quads);
|
|
89
|
+
return this.updateQuery(q);
|
|
90
|
+
}
|
|
91
|
+
update(...entities) {
|
|
92
|
+
const q = this.queryBuilder.updateQuery(entities);
|
|
93
|
+
return this.updateQuery(q);
|
|
94
|
+
}
|
|
95
|
+
delete(...identities) {
|
|
96
|
+
const iris = identities.map((identity) => {
|
|
97
|
+
return typeof identity === "string" ? identity : identity.$id;
|
|
98
|
+
});
|
|
99
|
+
const q = this.queryBuilder.deleteQuery(iris);
|
|
100
|
+
return this.updateQuery(q);
|
|
101
|
+
}
|
|
102
|
+
deleteData(...quads) {
|
|
103
|
+
const q = this.queryBuilder.deleteDataQuery(quads);
|
|
104
|
+
return this.updateQuery(q);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.Resource = Resource;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.share = exports.tap = exports.switchMap = exports.map = exports.BehaviorSubject = exports.from = void 0;
|
|
4
|
+
var rxjs_1 = require("rxjs");
|
|
5
|
+
Object.defineProperty(exports, "from", { enumerable: true, get: function () { return rxjs_1.from; } });
|
|
6
|
+
Object.defineProperty(exports, "BehaviorSubject", { enumerable: true, get: function () { return rxjs_1.BehaviorSubject; } });
|
|
7
|
+
var operators_1 = require("rxjs/operators");
|
|
8
|
+
Object.defineProperty(exports, "map", { enumerable: true, get: function () { return operators_1.map; } });
|
|
9
|
+
Object.defineProperty(exports, "switchMap", { enumerable: true, get: function () { return operators_1.switchMap; } });
|
|
10
|
+
Object.defineProperty(exports, "tap", { enumerable: true, get: function () { return operators_1.tap; } });
|
|
11
|
+
Object.defineProperty(exports, "share", { enumerable: true, get: function () { return operators_1.share; } });
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mod_js_1 = require("../namespaces/mod.js");
|
|
4
|
+
const SupportedDataTypesPrototype = {
|
|
5
|
+
[mod_js_1.xsd.dateTime]: new Date(),
|
|
6
|
+
[mod_js_1.xsd.date]: new Date(),
|
|
7
|
+
[mod_js_1.xsd.gDay]: new Date(),
|
|
8
|
+
[mod_js_1.xsd.gMonthDay]: new Date(),
|
|
9
|
+
[mod_js_1.xsd.gYear]: new Date(),
|
|
10
|
+
[mod_js_1.xsd.gYearMonth]: new Date(),
|
|
11
|
+
[mod_js_1.xsd.boolean]: true,
|
|
12
|
+
[mod_js_1.xsd.double]: 0.0,
|
|
13
|
+
[mod_js_1.xsd.decimal]: 0.0,
|
|
14
|
+
[mod_js_1.xsd.float]: 0.0,
|
|
15
|
+
[mod_js_1.xsd.integer]: 0,
|
|
16
|
+
[mod_js_1.xsd.long]: 0,
|
|
17
|
+
[mod_js_1.xsd.int]: 0,
|
|
18
|
+
[mod_js_1.xsd.byte]: 0,
|
|
19
|
+
[mod_js_1.xsd.short]: 0,
|
|
20
|
+
[mod_js_1.xsd.negativeInteger]: 0,
|
|
21
|
+
[mod_js_1.xsd.nonNegativeInteger]: 0,
|
|
22
|
+
[mod_js_1.xsd.nonPositiveInteger]: 0,
|
|
23
|
+
[mod_js_1.xsd.positiveInteger]: 0,
|
|
24
|
+
[mod_js_1.xsd.unsignedByte]: 0,
|
|
25
|
+
[mod_js_1.xsd.unsignedInt]: 0,
|
|
26
|
+
[mod_js_1.xsd.unsignedLong]: 0,
|
|
27
|
+
[mod_js_1.xsd.unsignedShort]: 0,
|
|
28
|
+
[mod_js_1.xsd.string]: "",
|
|
29
|
+
[mod_js_1.xsd.normalizedString]: "",
|
|
30
|
+
[mod_js_1.xsd.anyURI]: "",
|
|
31
|
+
[mod_js_1.xsd.base64Binary]: "",
|
|
32
|
+
[mod_js_1.xsd.language]: "",
|
|
33
|
+
[mod_js_1.xsd.Name]: "",
|
|
34
|
+
[mod_js_1.xsd.NCName]: "",
|
|
35
|
+
[mod_js_1.xsd.NMTOKEN]: "",
|
|
36
|
+
[mod_js_1.xsd.token]: "",
|
|
37
|
+
[mod_js_1.xsd.hexBinary]: "",
|
|
38
|
+
[mod_js_1.rdf.langString]: "",
|
|
39
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSchemaProperties = exports.expandSchema = void 0;
|
|
4
|
+
var utils_js_1 = require("./utils.js");
|
|
5
|
+
Object.defineProperty(exports, "expandSchema", { enumerable: true, get: function () { return utils_js_1.expandSchema; } });
|
|
6
|
+
Object.defineProperty(exports, "getSchemaProperties", { enumerable: true, get: function () { return utils_js_1.getSchemaProperties; } });
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSchemaProperties = exports.expandSchema = void 0;
|
|
4
|
+
const mod_js_1 = require("../namespaces/mod.js");
|
|
5
|
+
const expandSchema = (schemaPrototype) => {
|
|
6
|
+
const expandArray = (stringOrStrings) => {
|
|
7
|
+
return Array.isArray(stringOrStrings) ? stringOrStrings : [stringOrStrings];
|
|
8
|
+
};
|
|
9
|
+
const expandSchemaProperty = (stringOrProperty) => {
|
|
10
|
+
if (typeof stringOrProperty === "string") {
|
|
11
|
+
return {
|
|
12
|
+
"@id": stringOrProperty,
|
|
13
|
+
"@type": mod_js_1.xsd.string,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const property = stringOrProperty;
|
|
17
|
+
if (!property["@id"]) {
|
|
18
|
+
throw new Error(`Invalid schema, "@id" key for property missing`);
|
|
19
|
+
}
|
|
20
|
+
const validKeys = [
|
|
21
|
+
"@context",
|
|
22
|
+
"@id",
|
|
23
|
+
"@type",
|
|
24
|
+
"@array",
|
|
25
|
+
"@optional",
|
|
26
|
+
"@multilang",
|
|
27
|
+
];
|
|
28
|
+
const baseProperty = {
|
|
29
|
+
"@id": "",
|
|
30
|
+
};
|
|
31
|
+
const expandedProperty = Object.keys(property).reduce((acc, key) => {
|
|
32
|
+
if (key === "@context") {
|
|
33
|
+
acc[key] = (0, exports.expandSchema)(property[key]);
|
|
34
|
+
}
|
|
35
|
+
else if (validKeys.includes(key)) {
|
|
36
|
+
acc[key] = property[key];
|
|
37
|
+
}
|
|
38
|
+
return acc;
|
|
39
|
+
}, baseProperty);
|
|
40
|
+
if (!baseProperty["@type"] && !baseProperty["@context"]) {
|
|
41
|
+
baseProperty["@type"] = mod_js_1.xsd.string;
|
|
42
|
+
}
|
|
43
|
+
return expandedProperty;
|
|
44
|
+
};
|
|
45
|
+
const baseSchema = {
|
|
46
|
+
"@type": [],
|
|
47
|
+
};
|
|
48
|
+
return Object.keys(schemaPrototype).reduce((acc, key) => {
|
|
49
|
+
if (key === "@type") {
|
|
50
|
+
acc[key] = expandArray(schemaPrototype[key]);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
acc[key] = expandSchemaProperty(schemaPrototype[key]);
|
|
54
|
+
}
|
|
55
|
+
return acc;
|
|
56
|
+
}, baseSchema);
|
|
57
|
+
};
|
|
58
|
+
exports.expandSchema = expandSchema;
|
|
59
|
+
const getSchemaProperties = (schema) => {
|
|
60
|
+
const { "@type": _ommitedType, ...properties } = schema;
|
|
61
|
+
return properties;
|
|
62
|
+
};
|
|
63
|
+
exports.getSchemaProperties = getSchemaProperties;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WITH = exports.SELECT = exports.CONSTRUCT = exports.DESCRIBE = exports.ASK = exports.INSERT = exports.DELETE = exports.$ = void 0;
|
|
4
|
+
var rdf_string_1 = require("@tpluscode/rdf-string");
|
|
5
|
+
Object.defineProperty(exports, "$", { enumerable: true, get: function () { return rdf_string_1.sparql; } });
|
|
6
|
+
var sparql_builder_1 = require("@tpluscode/sparql-builder");
|
|
7
|
+
Object.defineProperty(exports, "DELETE", { enumerable: true, get: function () { return sparql_builder_1.DELETE; } });
|
|
8
|
+
Object.defineProperty(exports, "INSERT", { enumerable: true, get: function () { return sparql_builder_1.INSERT; } });
|
|
9
|
+
Object.defineProperty(exports, "ASK", { enumerable: true, get: function () { return sparql_builder_1.ASK; } });
|
|
10
|
+
Object.defineProperty(exports, "DESCRIBE", { enumerable: true, get: function () { return sparql_builder_1.DESCRIBE; } });
|
|
11
|
+
Object.defineProperty(exports, "CONSTRUCT", { enumerable: true, get: function () { return sparql_builder_1.CONSTRUCT; } });
|
|
12
|
+
Object.defineProperty(exports, "SELECT", { enumerable: true, get: function () { return sparql_builder_1.SELECT; } });
|
|
13
|
+
Object.defineProperty(exports, "WITH", { enumerable: true, get: function () { return sparql_builder_1.WITH; } });
|