rdflib 2.2.32 → 2.2.33
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/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/serializer.js +1 -1
- package/esm/update-manager.js +122 -67
- package/lib/serializer.js +1 -1
- package/lib/update-manager.d.ts +24 -4
- package/lib/update-manager.js +122 -67
- package/package.json +2 -1
- package/src/serializer.js +1 -1
- package/src/update-manager.ts +240 -169
package/esm/serializer.js
CHANGED
package/esm/update-manager.js
CHANGED
|
@@ -9,9 +9,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
9
9
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
10
|
/* @file Update Manager Class
|
|
11
11
|
**
|
|
12
|
-
** 2007-07-15
|
|
12
|
+
** 2007-07-15 original SPARQL Update module by Joe Presbrey <presbrey@mit.edu>
|
|
13
13
|
** 2010-08-08 TimBL folded in Kenny's WEBDAV
|
|
14
|
-
** 2010-12-07 TimBL
|
|
14
|
+
** 2010-12-07 TimBL added local file write code
|
|
15
15
|
*/
|
|
16
16
|
import IndexedFormula from './store';
|
|
17
17
|
import { docpart, join as uriJoin } from './uri';
|
|
@@ -77,8 +77,8 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/** Remove from the store HTTP authorization metadata
|
|
80
|
-
* The
|
|
81
|
-
* of the results of previous HTTP transactions.
|
|
80
|
+
* The editable function below relies on copies we have in the store
|
|
81
|
+
* of the results of previous HTTP transactions. However, when
|
|
82
82
|
* the user logs in, then that data misrepresents what would happen
|
|
83
83
|
* if the user tried again.
|
|
84
84
|
*/
|
|
@@ -119,7 +119,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
119
119
|
* and local write access is determined by those headers.
|
|
120
120
|
* This async version not only looks at past HTTP requests, it also makes new ones if necessary.
|
|
121
121
|
*
|
|
122
|
-
* @returns The method string SPARQL or DAV or
|
|
122
|
+
* @returns The method string N3PATCH or SPARQL or DAV or
|
|
123
123
|
* LOCALFILE or false if known, undefined if not known.
|
|
124
124
|
*/
|
|
125
125
|
}, {
|
|
@@ -231,6 +231,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
231
231
|
if (acceptPatch.length) {
|
|
232
232
|
for (var i = 0; i < acceptPatch.length; i++) {
|
|
233
233
|
method = acceptPatch[i].value.trim();
|
|
234
|
+
if (method.indexOf('text/n3') >= 0) return 'N3PATCH';
|
|
234
235
|
if (method.indexOf('application/sparql-update') >= 0) return 'SPARQL';
|
|
235
236
|
if (method.indexOf('application/sparql-update-single-match') >= 0) return 'SPARQL';
|
|
236
237
|
}
|
|
@@ -278,7 +279,8 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
278
279
|
}, {
|
|
279
280
|
key: "anonymize",
|
|
280
281
|
value: function anonymize(obj) {
|
|
281
|
-
|
|
282
|
+
var anonymized = obj.toNT().substr(0, 2) === '_:' && this.mentioned(obj) ? '?' + obj.toNT().substr(2) : obj.toNT();
|
|
283
|
+
return anonymized;
|
|
282
284
|
}
|
|
283
285
|
}, {
|
|
284
286
|
key: "anonymizeNT",
|
|
@@ -476,7 +478,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
476
478
|
// console.log('UpdateManager: sending update to <' + uri + '>')
|
|
477
479
|
|
|
478
480
|
options.noMeta = true;
|
|
479
|
-
options.contentType = 'application/sparql-update';
|
|
481
|
+
options.contentType = options.contentType || 'application/sparql-update';
|
|
480
482
|
options.body = query;
|
|
481
483
|
return _this.store.fetcher.webOperation('PATCH', uri, options);
|
|
482
484
|
}).then(function (response) {
|
|
@@ -494,7 +496,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
494
496
|
});
|
|
495
497
|
}
|
|
496
498
|
|
|
497
|
-
// ARE THESE
|
|
499
|
+
// ARE THESE THREE FUNCTIONS USED? DEPRECATE?
|
|
498
500
|
|
|
499
501
|
/** return a statemnet updating function
|
|
500
502
|
*
|
|
@@ -804,7 +806,93 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
804
806
|
}
|
|
805
807
|
|
|
806
808
|
/**
|
|
807
|
-
*
|
|
809
|
+
* @private
|
|
810
|
+
*
|
|
811
|
+
* This helper function constructs SPARQL Update query from resolved arguments.
|
|
812
|
+
*
|
|
813
|
+
* @param ds: deletions array.
|
|
814
|
+
* @param is: insertions array.
|
|
815
|
+
* @param bnodes_context: Additional context to uniquely identify any blank nodes.
|
|
816
|
+
*/
|
|
817
|
+
}, {
|
|
818
|
+
key: "constructSparqlUpdateQuery",
|
|
819
|
+
value: function constructSparqlUpdateQuery(ds, is, bnodes_context) {
|
|
820
|
+
var whereClause = this.contextWhere(bnodes_context);
|
|
821
|
+
var query = '';
|
|
822
|
+
if (whereClause.length) {
|
|
823
|
+
// Is there a WHERE clause?
|
|
824
|
+
if (ds.length) {
|
|
825
|
+
query += 'DELETE { ';
|
|
826
|
+
for (var i = 0; i < ds.length; i++) {
|
|
827
|
+
query += this.anonymizeNT(ds[i]) + '\n';
|
|
828
|
+
}
|
|
829
|
+
query += ' }\n';
|
|
830
|
+
}
|
|
831
|
+
if (is.length) {
|
|
832
|
+
query += 'INSERT { ';
|
|
833
|
+
for (var _i5 = 0; _i5 < is.length; _i5++) {
|
|
834
|
+
query += this.anonymizeNT(is[_i5]) + '\n';
|
|
835
|
+
}
|
|
836
|
+
query += ' }\n';
|
|
837
|
+
}
|
|
838
|
+
query += whereClause;
|
|
839
|
+
} else {
|
|
840
|
+
// no where clause
|
|
841
|
+
if (ds.length) {
|
|
842
|
+
query += 'DELETE DATA { ';
|
|
843
|
+
for (var _i6 = 0; _i6 < ds.length; _i6++) {
|
|
844
|
+
query += this.anonymizeNT(ds[_i6]) + '\n';
|
|
845
|
+
}
|
|
846
|
+
query += ' } \n';
|
|
847
|
+
}
|
|
848
|
+
if (is.length) {
|
|
849
|
+
if (ds.length) query += ' ; ';
|
|
850
|
+
query += 'INSERT DATA { ';
|
|
851
|
+
for (var _i7 = 0; _i7 < is.length; _i7++) {
|
|
852
|
+
query += this.nTriples(is[_i7]) + '\n';
|
|
853
|
+
}
|
|
854
|
+
query += ' }\n';
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
return query;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* @private
|
|
862
|
+
*
|
|
863
|
+
* This helper function constructs n3-patch query from resolved arguments.
|
|
864
|
+
*
|
|
865
|
+
* @param ds: deletions array.
|
|
866
|
+
* @param is: insertions array.
|
|
867
|
+
* @param bnodes_context: Additional context to uniquely identify any blanknodes.
|
|
868
|
+
*/
|
|
869
|
+
}, {
|
|
870
|
+
key: "constructN3PatchQuery",
|
|
871
|
+
value: function constructN3PatchQuery(ds, is, bnodes_context) {
|
|
872
|
+
var _this3 = this;
|
|
873
|
+
var query = "\n@prefix solid: <http://www.w3.org/ns/solid/terms#>.\n@prefix ex: <http://www.example.org/terms#>.\n\n_:patch\n";
|
|
874
|
+
// If bnode context is non trivial, express it as ?conditions formula.
|
|
875
|
+
if (bnodes_context && bnodes_context.length > 0) {
|
|
876
|
+
query += "\n solid:where {\n ".concat(bnodes_context.map(function (x) {
|
|
877
|
+
return _this3.anonymizeNT(x);
|
|
878
|
+
}).join('\n '), "\n };");
|
|
879
|
+
}
|
|
880
|
+
if (ds.length > 0) {
|
|
881
|
+
query += "\n solid:deletes {\n ".concat(ds.map(function (x) {
|
|
882
|
+
return _this3.anonymizeNT(x);
|
|
883
|
+
}).join('\n '), "\n };");
|
|
884
|
+
}
|
|
885
|
+
if (is.length > 0) {
|
|
886
|
+
query += "\n solid:inserts {\n ".concat(is.map(function (x) {
|
|
887
|
+
return _this3.anonymizeNT(x);
|
|
888
|
+
}).join('\n '), "\n };");
|
|
889
|
+
}
|
|
890
|
+
query += " a solid:InsertDeletePatch .\n";
|
|
891
|
+
return query;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* This high-level function updates the local store if the web is changed successfully.
|
|
808
896
|
* Deletions, insertions may be undefined or single statements or lists or formulae (may contain bnodes which can be indirectly identified by a where clause).
|
|
809
897
|
* The `why` property of each statement must be the same and give the web document to be updated.
|
|
810
898
|
* @param deletions - Statement or statements to be deleted.
|
|
@@ -816,7 +904,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
816
904
|
}, {
|
|
817
905
|
key: "update",
|
|
818
906
|
value: function update(deletions, insertions, callback, secondTry) {
|
|
819
|
-
var
|
|
907
|
+
var _this4 = this;
|
|
820
908
|
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
821
909
|
if (!callback) {
|
|
822
910
|
var thisUpdater = this;
|
|
@@ -884,64 +972,31 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
884
972
|
if (protocol === undefined) {
|
|
885
973
|
// Not enough metadata
|
|
886
974
|
if (secondTry) {
|
|
887
|
-
throw new Error('Update: Loaded ' + doc + "but
|
|
975
|
+
throw new Error('Update: Loaded ' + doc + "but still can't figure out what editing protocol it supports.");
|
|
888
976
|
}
|
|
889
977
|
// console.log(`Update: have not loaded ${doc} before: loading now...`);
|
|
890
978
|
this.store.fetcher.load(doc).then(function (response) {
|
|
891
|
-
|
|
979
|
+
_this4.update(deletions, insertions, callback, true, options);
|
|
892
980
|
}, function (err) {
|
|
893
981
|
if (err.response.status === 404) {
|
|
894
982
|
// nonexistent files are fine
|
|
895
|
-
|
|
983
|
+
_this4.update(deletions, insertions, callback, true, options);
|
|
896
984
|
} else {
|
|
897
985
|
throw new Error("Update: Can't get updatability status ".concat(doc, " before patching: ").concat(err));
|
|
898
986
|
}
|
|
899
987
|
});
|
|
900
988
|
return;
|
|
901
|
-
} else if (protocol.indexOf('SPARQL') >= 0) {
|
|
989
|
+
} else if (protocol.indexOf('SPARQL') >= 0 || protocol.indexOf('N3PATCH') >= 0) {
|
|
990
|
+
var isSparql = protocol.indexOf('SPARQL') >= 0;
|
|
902
991
|
var bnodes = [];
|
|
903
992
|
// change ReadOnly type to Mutable type
|
|
904
993
|
|
|
905
994
|
if (ds.length) bnodes = this.statementArrayBnodes(ds);
|
|
906
995
|
if (is.length) bnodes = bnodes.concat(this.statementArrayBnodes(is));
|
|
907
996
|
var context = this.bnodeContext(bnodes, doc);
|
|
908
|
-
var
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
// Is there a WHERE clause?
|
|
912
|
-
if (ds.length) {
|
|
913
|
-
query += 'DELETE { ';
|
|
914
|
-
for (var i = 0; i < ds.length; i++) {
|
|
915
|
-
query += this.anonymizeNT(ds[i]) + '\n';
|
|
916
|
-
}
|
|
917
|
-
query += ' }\n';
|
|
918
|
-
}
|
|
919
|
-
if (is.length) {
|
|
920
|
-
query += 'INSERT { ';
|
|
921
|
-
for (var _i5 = 0; _i5 < is.length; _i5++) {
|
|
922
|
-
query += this.anonymizeNT(is[_i5]) + '\n';
|
|
923
|
-
}
|
|
924
|
-
query += ' }\n';
|
|
925
|
-
}
|
|
926
|
-
query += whereClause;
|
|
927
|
-
} else {
|
|
928
|
-
// no where clause
|
|
929
|
-
if (ds.length) {
|
|
930
|
-
query += 'DELETE DATA { ';
|
|
931
|
-
for (var _i6 = 0; _i6 < ds.length; _i6++) {
|
|
932
|
-
query += this.anonymizeNT(ds[_i6]) + '\n';
|
|
933
|
-
}
|
|
934
|
-
query += ' } \n';
|
|
935
|
-
}
|
|
936
|
-
if (is.length) {
|
|
937
|
-
if (ds.length) query += ' ; ';
|
|
938
|
-
query += 'INSERT DATA { ';
|
|
939
|
-
for (var _i7 = 0; _i7 < is.length; _i7++) {
|
|
940
|
-
query += this.nTriples(is[_i7]) + '\n';
|
|
941
|
-
}
|
|
942
|
-
query += ' }\n';
|
|
943
|
-
}
|
|
944
|
-
}
|
|
997
|
+
var query = isSparql ? this.constructSparqlUpdateQuery(ds, is, context) : this.constructN3PatchQuery(ds, is, context);
|
|
998
|
+
options.contentType = isSparql ? 'application/sparql-update' : 'text/n3';
|
|
999
|
+
|
|
945
1000
|
// Track pending upstream patches until they have finished their callbackFunction
|
|
946
1001
|
control.pendingUpstream = control.pendingUpstream ? control.pendingUpstream + 1 : 1;
|
|
947
1002
|
if ('upstreamCount' in control) {
|
|
@@ -962,8 +1017,8 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
962
1017
|
success = false;
|
|
963
1018
|
body = 'Remote Ok BUT error deleting ' + ds.length + ' from store!!! ' + e;
|
|
964
1019
|
} // Add in any case -- help recover from weirdness??
|
|
965
|
-
for (var
|
|
966
|
-
kb.add(is[
|
|
1020
|
+
for (var i = 0; i < is.length; i++) {
|
|
1021
|
+
kb.add(is[i].subject, is[i].predicate, is[i].object, doc);
|
|
967
1022
|
}
|
|
968
1023
|
}
|
|
969
1024
|
callback(uri, success, body, response);
|
|
@@ -1017,8 +1072,8 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1017
1072
|
for (var i = 0; i < ds.length; i++) {
|
|
1018
1073
|
Util.RDFArrayRemove(newSts, ds[i]);
|
|
1019
1074
|
}
|
|
1020
|
-
for (var
|
|
1021
|
-
newSts.push(is[
|
|
1075
|
+
for (var _i8 = 0; _i8 < is.length; _i8++) {
|
|
1076
|
+
newSts.push(is[_i8]);
|
|
1022
1077
|
}
|
|
1023
1078
|
var documentString = this.serialize(doc.value, newSts, contentType);
|
|
1024
1079
|
|
|
@@ -1035,11 +1090,11 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1035
1090
|
if (!response.ok) {
|
|
1036
1091
|
throw new Error(response.error);
|
|
1037
1092
|
}
|
|
1038
|
-
for (var
|
|
1039
|
-
kb.remove(ds[
|
|
1093
|
+
for (var _i9 = 0; _i9 < ds.length; _i9++) {
|
|
1094
|
+
kb.remove(ds[_i9]);
|
|
1040
1095
|
}
|
|
1041
|
-
for (var
|
|
1042
|
-
kb.add(is[
|
|
1096
|
+
for (var _i10 = 0; _i10 < is.length; _i10++) {
|
|
1097
|
+
kb.add(is[_i10].subject, is[_i10].predicate, is[_i10].object, doc);
|
|
1043
1098
|
}
|
|
1044
1099
|
callbackFunction(doc.value, response.ok, response.responseText, response);
|
|
1045
1100
|
}).catch(function (err) {
|
|
@@ -1069,8 +1124,8 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1069
1124
|
for (var i = 0; i < ds.length; i++) {
|
|
1070
1125
|
Util.RDFArrayRemove(newSts, ds[i]);
|
|
1071
1126
|
}
|
|
1072
|
-
for (var
|
|
1073
|
-
newSts.push(is[
|
|
1127
|
+
for (var _i11 = 0; _i11 < is.length; _i11++) {
|
|
1128
|
+
newSts.push(is[_i11]);
|
|
1074
1129
|
}
|
|
1075
1130
|
// serialize to the appropriate format
|
|
1076
1131
|
var dot = doc.value.lastIndexOf('.');
|
|
@@ -1086,11 +1141,11 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1086
1141
|
options.contentType = contentType;
|
|
1087
1142
|
kb.fetcher.webOperation('PUT', doc.value, options).then(function (response) {
|
|
1088
1143
|
if (!response.ok) return callbackFunction(doc.value, false, response.error);
|
|
1089
|
-
for (var
|
|
1090
|
-
kb.remove(ds[
|
|
1144
|
+
for (var _i12 = 0; _i12 < ds.length; _i12++) {
|
|
1145
|
+
kb.remove(ds[_i12]);
|
|
1091
1146
|
}
|
|
1092
|
-
for (var
|
|
1093
|
-
kb.add(is[
|
|
1147
|
+
for (var _i13 = 0; _i13 < is.length; _i13++) {
|
|
1148
|
+
kb.add(is[_i13].subject, is[_i13].predicate, is[_i13].object, doc);
|
|
1094
1149
|
}
|
|
1095
1150
|
callbackFunction(doc.value, true, ''); // success!
|
|
1096
1151
|
});
|
|
@@ -1138,11 +1193,11 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1138
1193
|
}, {
|
|
1139
1194
|
key: "put",
|
|
1140
1195
|
value: function put(doc, data, contentType, callback) {
|
|
1141
|
-
var
|
|
1196
|
+
var _this5 = this;
|
|
1142
1197
|
var kb = this.store;
|
|
1143
1198
|
var documentString;
|
|
1144
1199
|
return Promise.resolve().then(function () {
|
|
1145
|
-
documentString =
|
|
1200
|
+
documentString = _this5.serialize(doc.value, data, contentType);
|
|
1146
1201
|
return kb.fetcher.webOperation('PUT', doc.value, {
|
|
1147
1202
|
contentType: contentType,
|
|
1148
1203
|
body: documentString
|
package/lib/serializer.js
CHANGED
package/lib/update-manager.d.ts
CHANGED
|
@@ -28,8 +28,8 @@ export default class UpdateManager {
|
|
|
28
28
|
patchControlFor(doc: NamedNode): any;
|
|
29
29
|
isHttpUri(uri: string): boolean;
|
|
30
30
|
/** Remove from the store HTTP authorization metadata
|
|
31
|
-
* The
|
|
32
|
-
* of the results of previous HTTP transactions.
|
|
31
|
+
* The editable function below relies on copies we have in the store
|
|
32
|
+
* of the results of previous HTTP transactions. However, when
|
|
33
33
|
* the user logs in, then that data misrepresents what would happen
|
|
34
34
|
* if the user tried again.
|
|
35
35
|
*/
|
|
@@ -42,7 +42,7 @@ export default class UpdateManager {
|
|
|
42
42
|
* and local write access is determined by those headers.
|
|
43
43
|
* This async version not only looks at past HTTP requests, it also makes new ones if necessary.
|
|
44
44
|
*
|
|
45
|
-
* @returns The method string SPARQL or DAV or
|
|
45
|
+
* @returns The method string N3PATCH or SPARQL or DAV or
|
|
46
46
|
* LOCALFILE or false if known, undefined if not known.
|
|
47
47
|
*/
|
|
48
48
|
checkEditable(uri: string | NamedNode, kb?: IndexedFormula): Promise<string | boolean | undefined>;
|
|
@@ -168,7 +168,27 @@ export default class UpdateManager {
|
|
|
168
168
|
*/
|
|
169
169
|
updateMany(deletions: ReadonlyArray<Statement>, insertions?: ReadonlyArray<Statement>): Promise<void[]>;
|
|
170
170
|
/**
|
|
171
|
-
*
|
|
171
|
+
* @private
|
|
172
|
+
*
|
|
173
|
+
* This helper function constructs SPARQL Update query from resolved arguments.
|
|
174
|
+
*
|
|
175
|
+
* @param ds: deletions array.
|
|
176
|
+
* @param is: insertions array.
|
|
177
|
+
* @param bnodes_context: Additional context to uniquely identify any blank nodes.
|
|
178
|
+
*/
|
|
179
|
+
constructSparqlUpdateQuery(ds: ReadonlyArray<Statement>, is: ReadonlyArray<Statement>, bnodes_context: any): string;
|
|
180
|
+
/**
|
|
181
|
+
* @private
|
|
182
|
+
*
|
|
183
|
+
* This helper function constructs n3-patch query from resolved arguments.
|
|
184
|
+
*
|
|
185
|
+
* @param ds: deletions array.
|
|
186
|
+
* @param is: insertions array.
|
|
187
|
+
* @param bnodes_context: Additional context to uniquely identify any blanknodes.
|
|
188
|
+
*/
|
|
189
|
+
constructN3PatchQuery(ds: ReadonlyArray<Statement>, is: ReadonlyArray<Statement>, bnodes_context: any): string;
|
|
190
|
+
/**
|
|
191
|
+
* This high-level function updates the local store if the web is changed successfully.
|
|
172
192
|
* Deletions, insertions may be undefined or single statements or lists or formulae (may contain bnodes which can be indirectly identified by a where clause).
|
|
173
193
|
* The `why` property of each statement must be the same and give the web document to be updated.
|
|
174
194
|
* @param deletions - Statement or statements to be deleted.
|