rdflib 2.2.19-d0f324ca → 2.2.19-e127c2a5

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/fetcher.js CHANGED
@@ -1441,8 +1441,8 @@ var Fetcher = /*#__PURE__*/function () {
1441
1441
  }
1442
1442
  }
1443
1443
  /**
1444
- * A generic web opeation, at the fetch() level.
1445
- * does not invole the quadstore.
1444
+ * A generic web operation, at the fetch() level.
1445
+ * does not involve the quad store.
1446
1446
  *
1447
1447
  * Returns promise of Response
1448
1448
  * If data is returned, copies it to response.responseText before returning
package/esm/serializer.js CHANGED
@@ -696,6 +696,9 @@ export var Serializer = /*#__PURE__*/function () {
696
696
  case 'NamedNode':
697
697
  return this.symbolToN3(expr);
698
698
 
699
+ case 'DefaultGraph':
700
+ return '';
701
+
699
702
  default:
700
703
  throw new Error('Internal: atomicTermToN3 cannot handle ' + expr + ' of termType: ' + expr.termType);
701
704
  }
@@ -16,12 +16,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
16
16
  ** 2010-12-07 TimBL addred local file write code
17
17
  */
18
18
  import IndexedFormula from './store';
19
- import { docpart } from './uri';
19
+ import { docpart, join as uriJoin } from './uri';
20
20
  import Fetcher from './fetcher';
21
21
  import Namespace from './namespace';
22
22
  import Serializer from './serializer';
23
- import { join as uriJoin } from './uri';
24
- import { isStore, isBlankNode } from './utils/terms';
23
+ import { isBlankNode, isStore } from './utils/terms';
25
24
  import * as Util from './utils-js';
26
25
  import { termValue } from './utils/termValue';
27
26
 
@@ -224,6 +223,11 @@ var UpdateManager = /*#__PURE__*/function () {
224
223
  value: function anonymizeNT(stmt) {
225
224
  return this.anonymize(stmt.subject) + ' ' + this.anonymize(stmt.predicate) + ' ' + this.anonymize(stmt.object) + ' .';
226
225
  }
226
+ }, {
227
+ key: "nTriples",
228
+ value: function nTriples(stmt) {
229
+ return "".concat(stmt.subject.toNT(), " ").concat(stmt.predicate.toNT(), " ").concat(stmt.object.toNT(), " .");
230
+ }
227
231
  /**
228
232
  * Returns a list of all bnodes occurring in a statement
229
233
  * @private
@@ -425,17 +429,16 @@ var UpdateManager = /*#__PURE__*/function () {
425
429
  value: function fire(uri, query, callbackFunction) {
426
430
  var _this = this;
427
431
 
432
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
428
433
  return Promise.resolve().then(function () {
429
434
  if (!uri) {
430
435
  throw new Error('No URI given for remote editing operation: ' + query);
431
436
  } // console.log('UpdateManager: sending update to <' + uri + '>')
432
437
 
433
438
 
434
- var options = {
435
- noMeta: true,
436
- contentType: 'application/sparql-update',
437
- body: query
438
- };
439
+ options.noMeta = true;
440
+ options.contentType = 'application/sparql-update';
441
+ options.body = query;
439
442
  return _this.store.fetcher.webOperation('PATCH', uri, options);
440
443
  }).then(function (response) {
441
444
  if (!response.ok) {
@@ -800,6 +803,7 @@ var UpdateManager = /*#__PURE__*/function () {
800
803
  * @param insertions - Statement or statements to be inserted.
801
804
  * @param callback - called as callbackFunction(uri, success, errorbody)
802
805
  * OR returns a promise
806
+ * @param options - Options for the fetch call
803
807
  */
804
808
 
805
809
  }, {
@@ -807,6 +811,8 @@ var UpdateManager = /*#__PURE__*/function () {
807
811
  value: function update(deletions, insertions, callback, secondTry) {
808
812
  var _this3 = this;
809
813
 
814
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
815
+
810
816
  if (!callback) {
811
817
  var thisUpdater = this;
812
818
  return new Promise(function (resolve, reject) {
@@ -817,7 +823,7 @@ var UpdateManager = /*#__PURE__*/function () {
817
823
  } else {
818
824
  resolve();
819
825
  }
820
- }); // callbackFunction
826
+ }, secondTry, options); // callbackFunction
821
827
  }); // promise
822
828
  } // if
823
829
 
@@ -883,11 +889,11 @@ var UpdateManager = /*#__PURE__*/function () {
883
889
 
884
890
 
885
891
  this.store.fetcher.load(doc).then(function (response) {
886
- _this3.update(deletions, insertions, callback, true);
892
+ _this3.update(deletions, insertions, callback, true, options);
887
893
  }, function (err) {
888
894
  if (err.response.status === 404) {
889
895
  // nonexistent files are fine
890
- _this3.update(deletions, insertions, callback, true);
896
+ _this3.update(deletions, insertions, callback, true, options);
891
897
  } else {
892
898
  throw new Error("Update: Can't get updatability status ".concat(doc, " before patching: ").concat(err));
893
899
  }
@@ -941,7 +947,7 @@ var UpdateManager = /*#__PURE__*/function () {
941
947
  query += 'INSERT DATA { ';
942
948
 
943
949
  for (var _i7 = 0; _i7 < is.length; _i7++) {
944
- query += this.anonymizeNT(is[_i7]) + '\n';
950
+ query += this.nTriples(is[_i7]) + '\n';
945
951
  }
946
952
 
947
953
  query += ' }\n';
@@ -983,13 +989,13 @@ var UpdateManager = /*#__PURE__*/function () {
983
989
 
984
990
  downstreamAction(doc);
985
991
  }
986
- });
992
+ }, options);
987
993
  } else if (protocol.indexOf('DAV') >= 0) {
988
- this.updateDav(doc, ds, is, callback);
994
+ this.updateDav(doc, ds, is, callback, options);
989
995
  } else {
990
996
  if (protocol.indexOf('LOCALFILE') >= 0) {
991
997
  try {
992
- this.updateLocalFile(doc, ds, is, callback);
998
+ this.updateLocalFile(doc, ds, is, callback, options);
993
999
  } catch (e) {
994
1000
  callback(doc.value, false, 'Exception trying to write back file <' + doc.value + '>\n' // + tabulator.Util.stackString(e))
995
1001
  );
@@ -1005,6 +1011,7 @@ var UpdateManager = /*#__PURE__*/function () {
1005
1011
  }, {
1006
1012
  key: "updateDav",
1007
1013
  value: function updateDav(doc, ds, is, callbackFunction) {
1014
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
1008
1015
  var kb = this.store; // The code below is derived from Kenny's UpdateCenter.js
1009
1016
 
1010
1017
  var request = kb.any(doc, this.ns.link('request'));
@@ -1041,11 +1048,9 @@ var UpdateManager = /*#__PURE__*/function () {
1041
1048
  targetURI = uriJoin(candidateTarget.value, targetURI);
1042
1049
  }
1043
1050
 
1044
- var options = {
1045
- contentType: contentType,
1046
- noMeta: true,
1047
- body: documentString
1048
- };
1051
+ options.contentType = contentType;
1052
+ options.noMeta = true;
1053
+ options.body = documentString;
1049
1054
  return kb.fetcher.webOperation('PUT', targetURI, options).then(function (response) {
1050
1055
  if (!response.ok) {
1051
1056
  throw new Error(response.error);
@@ -1071,11 +1076,13 @@ var UpdateManager = /*#__PURE__*/function () {
1071
1076
  * @param ds
1072
1077
  * @param is
1073
1078
  * @param callbackFunction
1079
+ * @param options
1074
1080
  */
1075
1081
 
1076
1082
  }, {
1077
1083
  key: "updateLocalFile",
1078
1084
  value: function updateLocalFile(doc, ds, is, callbackFunction) {
1085
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
1079
1086
  var kb = this.store; // console.log('Writing back to local file\n')
1080
1087
  // prepare contents of revised document
1081
1088
 
@@ -1103,11 +1110,9 @@ var UpdateManager = /*#__PURE__*/function () {
1103
1110
  throw new Error('File extension .' + ext + ' not supported for data write');
1104
1111
  }
1105
1112
 
1106
- var documentString = this.serialize(doc.value, newSts, contentType);
1107
- kb.fetcher.webOperation('PUT', doc.value, {
1108
- "body": documentString,
1109
- contentType: contentType
1110
- }).then(function (response) {
1113
+ options.body = this.serialize(doc.value, newSts, contentType);
1114
+ options.contentType = contentType;
1115
+ kb.fetcher.webOperation('PUT', doc.value, options).then(function (response) {
1111
1116
  if (!response.ok) return callbackFunction(doc.value, false, response.error);
1112
1117
 
1113
1118
  for (var _i13 = 0; _i13 < ds.length; _i13++) {
package/lib/fetcher.d.ts CHANGED
@@ -56,7 +56,7 @@ declare global {
56
56
  declare type UserCallback = (ok: boolean, message: string, response?: any) => void;
57
57
  declare type HTTPMethods = 'GET' | 'PUT' | 'POST' | 'PATCH' | 'HEAD' | 'DELETE' | 'CONNECT' | 'TRACE' | 'OPTIONS';
58
58
  /** All valid inputs for initFetchOptions */
59
- declare type Options = Partial<AutoInitOptions>;
59
+ export declare type Options = Partial<AutoInitOptions>;
60
60
  /** Initiated by initFetchOptions, which runs on load */
61
61
  export interface AutoInitOptions extends RequestInit {
62
62
  /** The used Fetch function */
@@ -370,8 +370,8 @@ export default class Fetcher implements CallbackifyInterface {
370
370
  createContainer(parentURI: string, folderName: string, data: string): Promise<Response>;
371
371
  invalidateCache(iri: string | NamedNode): void;
372
372
  /**
373
- * A generic web opeation, at the fetch() level.
374
- * does not invole the quadstore.
373
+ * A generic web operation, at the fetch() level.
374
+ * does not involve the quad store.
375
375
  *
376
376
  * Returns promise of Response
377
377
  * If data is returned, copies it to response.responseText before returning
package/lib/fetcher.js CHANGED
@@ -1415,8 +1415,8 @@ var Fetcher = /*#__PURE__*/function () {
1415
1415
  }
1416
1416
  }
1417
1417
  /**
1418
- * A generic web opeation, at the fetch() level.
1419
- * does not invole the quadstore.
1418
+ * A generic web operation, at the fetch() level.
1419
+ * does not involve the quad store.
1420
1420
  *
1421
1421
  * Returns promise of Response
1422
1422
  * If data is returned, copies it to response.responseText before returning
package/lib/serializer.js CHANGED
@@ -717,6 +717,9 @@ var Serializer = /*#__PURE__*/function () {
717
717
  case 'NamedNode':
718
718
  return this.symbolToN3(expr);
719
719
 
720
+ case 'DefaultGraph':
721
+ return '';
722
+
720
723
  default:
721
724
  throw new Error('Internal: atomicTermToN3 cannot handle ' + expr + ' of termType: ' + expr.termType);
722
725
  }
@@ -1,8 +1,8 @@
1
1
  import IndexedFormula from './store';
2
- import Fetcher from './fetcher';
2
+ import Fetcher, { Options } from './fetcher';
3
3
  import Statement from './statement';
4
4
  import RDFlibNamedNode from './named-node';
5
- import { BlankNode, NamedNode, Quad_Subject, Quad, Term } from './tf-types';
5
+ import { BlankNode, NamedNode, Quad, Quad_Subject, Term } from './tf-types';
6
6
  interface UpdateManagerFormula extends IndexedFormula {
7
7
  fetcher: Fetcher;
8
8
  }
@@ -41,6 +41,7 @@ export default class UpdateManager {
41
41
  editable(uri: string | NamedNode, kb?: IndexedFormula): string | boolean | undefined;
42
42
  anonymize(obj: any): any;
43
43
  anonymizeNT(stmt: Quad): string;
44
+ nTriples(stmt: any): string;
44
45
  /**
45
46
  * Returns a list of all bnodes occurring in a statement
46
47
  * @private
@@ -86,7 +87,7 @@ export default class UpdateManager {
86
87
  /**
87
88
  * @private
88
89
  */
89
- fire(uri: string, query: string, callbackFunction: CallBackFunction): Promise<void>;
90
+ fire(uri: string, query: string, callbackFunction: CallBackFunction, options?: Options): Promise<void>;
90
91
  /** return a statemnet updating function
91
92
  *
92
93
  * This does NOT update the statement.
@@ -155,9 +156,10 @@ export default class UpdateManager {
155
156
  * @param insertions - Statement or statements to be inserted.
156
157
  * @param callback - called as callbackFunction(uri, success, errorbody)
157
158
  * OR returns a promise
159
+ * @param options - Options for the fetch call
158
160
  */
159
- update(deletions: ReadonlyArray<Statement>, insertions: ReadonlyArray<Statement>, callback?: (uri: string | undefined | null, success: boolean, errorBody?: string, response?: Response | Error) => void, secondTry?: boolean): void | Promise<void>;
160
- updateDav(doc: Quad_Subject, ds: any, is: any, callbackFunction: any): null | Promise<void>;
161
+ update(deletions: ReadonlyArray<Statement>, insertions: ReadonlyArray<Statement>, callback?: (uri: string | undefined | null, success: boolean, errorBody?: string, response?: Response | Error) => void, secondTry?: boolean, options?: Options): void | Promise<void>;
162
+ updateDav(doc: Quad_Subject, ds: any, is: any, callbackFunction: any, options?: Options): null | Promise<void>;
161
163
  /**
162
164
  * Likely deprecated, since this lib no longer deals with browser extension
163
165
  *
@@ -165,8 +167,9 @@ export default class UpdateManager {
165
167
  * @param ds
166
168
  * @param is
167
169
  * @param callbackFunction
170
+ * @param options
168
171
  */
169
- updateLocalFile(doc: NamedNode, ds: any, is: any, callbackFunction: any): void;
172
+ updateLocalFile(doc: NamedNode, ds: any, is: any, callbackFunction: any, options?: Options): void;
170
173
  /**
171
174
  * @throws {Error} On unsupported content type
172
175
  *
@@ -236,6 +236,11 @@ var UpdateManager = /*#__PURE__*/function () {
236
236
  value: function anonymizeNT(stmt) {
237
237
  return this.anonymize(stmt.subject) + ' ' + this.anonymize(stmt.predicate) + ' ' + this.anonymize(stmt.object) + ' .';
238
238
  }
239
+ }, {
240
+ key: "nTriples",
241
+ value: function nTriples(stmt) {
242
+ return "".concat(stmt.subject.toNT(), " ").concat(stmt.predicate.toNT(), " ").concat(stmt.object.toNT(), " .");
243
+ }
239
244
  /**
240
245
  * Returns a list of all bnodes occurring in a statement
241
246
  * @private
@@ -437,17 +442,16 @@ var UpdateManager = /*#__PURE__*/function () {
437
442
  value: function fire(uri, query, callbackFunction) {
438
443
  var _this = this;
439
444
 
445
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
440
446
  return Promise.resolve().then(function () {
441
447
  if (!uri) {
442
448
  throw new Error('No URI given for remote editing operation: ' + query);
443
449
  } // console.log('UpdateManager: sending update to <' + uri + '>')
444
450
 
445
451
 
446
- var options = {
447
- noMeta: true,
448
- contentType: 'application/sparql-update',
449
- body: query
450
- };
452
+ options.noMeta = true;
453
+ options.contentType = 'application/sparql-update';
454
+ options.body = query;
451
455
  return _this.store.fetcher.webOperation('PATCH', uri, options);
452
456
  }).then(function (response) {
453
457
  if (!response.ok) {
@@ -812,6 +816,7 @@ var UpdateManager = /*#__PURE__*/function () {
812
816
  * @param insertions - Statement or statements to be inserted.
813
817
  * @param callback - called as callbackFunction(uri, success, errorbody)
814
818
  * OR returns a promise
819
+ * @param options - Options for the fetch call
815
820
  */
816
821
 
817
822
  }, {
@@ -819,6 +824,8 @@ var UpdateManager = /*#__PURE__*/function () {
819
824
  value: function update(deletions, insertions, callback, secondTry) {
820
825
  var _this3 = this;
821
826
 
827
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
828
+
822
829
  if (!callback) {
823
830
  var thisUpdater = this;
824
831
  return new Promise(function (resolve, reject) {
@@ -829,7 +836,7 @@ var UpdateManager = /*#__PURE__*/function () {
829
836
  } else {
830
837
  resolve();
831
838
  }
832
- }); // callbackFunction
839
+ }, secondTry, options); // callbackFunction
833
840
  }); // promise
834
841
  } // if
835
842
 
@@ -895,11 +902,11 @@ var UpdateManager = /*#__PURE__*/function () {
895
902
 
896
903
 
897
904
  this.store.fetcher.load(doc).then(function (response) {
898
- _this3.update(deletions, insertions, callback, true);
905
+ _this3.update(deletions, insertions, callback, true, options);
899
906
  }, function (err) {
900
907
  if (err.response.status === 404) {
901
908
  // nonexistent files are fine
902
- _this3.update(deletions, insertions, callback, true);
909
+ _this3.update(deletions, insertions, callback, true, options);
903
910
  } else {
904
911
  throw new Error("Update: Can't get updatability status ".concat(doc, " before patching: ").concat(err));
905
912
  }
@@ -953,7 +960,7 @@ var UpdateManager = /*#__PURE__*/function () {
953
960
  query += 'INSERT DATA { ';
954
961
 
955
962
  for (var _i7 = 0; _i7 < is.length; _i7++) {
956
- query += this.anonymizeNT(is[_i7]) + '\n';
963
+ query += this.nTriples(is[_i7]) + '\n';
957
964
  }
958
965
 
959
966
  query += ' }\n';
@@ -995,13 +1002,13 @@ var UpdateManager = /*#__PURE__*/function () {
995
1002
 
996
1003
  downstreamAction(doc);
997
1004
  }
998
- });
1005
+ }, options);
999
1006
  } else if (protocol.indexOf('DAV') >= 0) {
1000
- this.updateDav(doc, ds, is, callback);
1007
+ this.updateDav(doc, ds, is, callback, options);
1001
1008
  } else {
1002
1009
  if (protocol.indexOf('LOCALFILE') >= 0) {
1003
1010
  try {
1004
- this.updateLocalFile(doc, ds, is, callback);
1011
+ this.updateLocalFile(doc, ds, is, callback, options);
1005
1012
  } catch (e) {
1006
1013
  callback(doc.value, false, 'Exception trying to write back file <' + doc.value + '>\n' // + tabulator.Util.stackString(e))
1007
1014
  );
@@ -1017,6 +1024,7 @@ var UpdateManager = /*#__PURE__*/function () {
1017
1024
  }, {
1018
1025
  key: "updateDav",
1019
1026
  value: function updateDav(doc, ds, is, callbackFunction) {
1027
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
1020
1028
  var kb = this.store; // The code below is derived from Kenny's UpdateCenter.js
1021
1029
 
1022
1030
  var request = kb.any(doc, this.ns.link('request'));
@@ -1053,11 +1061,9 @@ var UpdateManager = /*#__PURE__*/function () {
1053
1061
  targetURI = (0, _uri.join)(candidateTarget.value, targetURI);
1054
1062
  }
1055
1063
 
1056
- var options = {
1057
- contentType: contentType,
1058
- noMeta: true,
1059
- body: documentString
1060
- };
1064
+ options.contentType = contentType;
1065
+ options.noMeta = true;
1066
+ options.body = documentString;
1061
1067
  return kb.fetcher.webOperation('PUT', targetURI, options).then(function (response) {
1062
1068
  if (!response.ok) {
1063
1069
  throw new Error(response.error);
@@ -1083,11 +1089,13 @@ var UpdateManager = /*#__PURE__*/function () {
1083
1089
  * @param ds
1084
1090
  * @param is
1085
1091
  * @param callbackFunction
1092
+ * @param options
1086
1093
  */
1087
1094
 
1088
1095
  }, {
1089
1096
  key: "updateLocalFile",
1090
1097
  value: function updateLocalFile(doc, ds, is, callbackFunction) {
1098
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
1091
1099
  var kb = this.store; // console.log('Writing back to local file\n')
1092
1100
  // prepare contents of revised document
1093
1101
 
@@ -1115,11 +1123,9 @@ var UpdateManager = /*#__PURE__*/function () {
1115
1123
  throw new Error('File extension .' + ext + ' not supported for data write');
1116
1124
  }
1117
1125
 
1118
- var documentString = this.serialize(doc.value, newSts, contentType);
1119
- kb.fetcher.webOperation('PUT', doc.value, {
1120
- "body": documentString,
1121
- contentType: contentType
1122
- }).then(function (response) {
1126
+ options.body = this.serialize(doc.value, newSts, contentType);
1127
+ options.contentType = contentType;
1128
+ kb.fetcher.webOperation('PUT', doc.value, options).then(function (response) {
1123
1129
  if (!response.ok) return callbackFunction(doc.value, false, response.error);
1124
1130
 
1125
1131
  for (var _i13 = 0; _i13 < ds.length; _i13++) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rdflib",
3
3
  "description": "an RDF library for node.js. Suitable for client and server side.",
4
- "version": "2.2.19-d0f324ca",
4
+ "version": "2.2.19-e127c2a5",
5
5
  "private": false,
6
6
  "browserslist": [
7
7
  "> 0.5%"
package/src/fetcher.ts CHANGED
@@ -133,7 +133,7 @@ type UserCallback = (
133
133
  type HTTPMethods = 'GET' | 'PUT' | 'POST' | 'PATCH' | 'HEAD' | 'DELETE' | 'CONNECT' | 'TRACE' | 'OPTIONS'
134
134
 
135
135
  /** All valid inputs for initFetchOptions */
136
- type Options = Partial<AutoInitOptions>
136
+ export type Options = Partial<AutoInitOptions>
137
137
 
138
138
  /** Initiated by initFetchOptions, which runs on load */
139
139
  export interface AutoInitOptions extends RequestInit{
@@ -1571,8 +1571,8 @@ export default class Fetcher implements CallbackifyInterface {
1571
1571
  }
1572
1572
 
1573
1573
  /**
1574
- * A generic web opeation, at the fetch() level.
1575
- * does not invole the quadstore.
1574
+ * A generic web operation, at the fetch() level.
1575
+ * does not involve the quad store.
1576
1576
  *
1577
1577
  * Returns promise of Response
1578
1578
  * If data is returned, copies it to response.responseText before returning
package/src/serializer.js CHANGED
@@ -561,6 +561,8 @@ export class Serializer {
561
561
  return str
562
562
  case 'NamedNode':
563
563
  return this.symbolToN3(expr)
564
+ case 'DefaultGraph':
565
+ return '';
564
566
  default:
565
567
  throw new Error('Internal: atomicTermToN3 cannot handle ' + expr + ' of termType: ' + expr.termType)
566
568
  }
@@ -5,26 +5,16 @@
5
5
  ** 2010-12-07 TimBL addred local file write code
6
6
  */
7
7
  import IndexedFormula from './store'
8
- import { docpart } from './uri'
9
- import Fetcher from './fetcher'
8
+ import {docpart, join as uriJoin} from './uri'
9
+ import Fetcher, {Options} from './fetcher'
10
10
  import Namespace from './namespace'
11
11
  import Serializer from './serializer'
12
- import { join as uriJoin } from './uri'
13
- import { isStore, isBlankNode } from './utils/terms'
12
+ import {isBlankNode, isStore} from './utils/terms'
14
13
  import * as Util from './utils-js'
15
14
  import Statement from './statement'
16
15
  import RDFlibNamedNode from './named-node'
17
- import { termValue } from './utils/termValue'
18
- import {
19
- BlankNode,
20
- NamedNode,
21
- Quad_Graph,
22
- Quad_Object,
23
- Quad_Predicate,
24
- Quad_Subject,
25
- Quad,
26
- Term,
27
- } from './tf-types'
16
+ import {termValue} from './utils/termValue'
17
+ import {BlankNode, NamedNode, Quad, Quad_Graph, Quad_Object, Quad_Predicate, Quad_Subject, Term,} from './tf-types'
28
18
 
29
19
  interface UpdateManagerFormula extends IndexedFormula {
30
20
  fetcher: Fetcher
@@ -205,6 +195,10 @@ export default class UpdateManager {
205
195
  this.anonymize(stmt.object) + ' .'
206
196
  }
207
197
 
198
+ nTriples(stmt) {
199
+ return `${stmt.subject.toNT()} ${stmt.predicate.toNT()} ${stmt.object.toNT()} .`
200
+ }
201
+
208
202
  /**
209
203
  * Returns a list of all bnodes occurring in a statement
210
204
  * @private
@@ -365,7 +359,8 @@ export default class UpdateManager {
365
359
  fire (
366
360
  uri: string,
367
361
  query: string,
368
- callbackFunction: CallBackFunction
362
+ callbackFunction: CallBackFunction,
363
+ options: Options = {}
369
364
  ): Promise<void> {
370
365
  return Promise.resolve()
371
366
  .then(() => {
@@ -374,11 +369,9 @@ export default class UpdateManager {
374
369
  }
375
370
  // console.log('UpdateManager: sending update to <' + uri + '>')
376
371
 
377
- let options = {
378
- noMeta: true,
379
- contentType: 'application/sparql-update',
380
- body: query
381
- }
372
+ options.noMeta = true;
373
+ options.contentType = 'application/sparql-update';
374
+ options.body = query;
382
375
 
383
376
  return this.store.fetcher.webOperation('PATCH', uri, options)
384
377
  })
@@ -709,6 +702,7 @@ export default class UpdateManager {
709
702
  * @param insertions - Statement or statements to be inserted.
710
703
  * @param callback - called as callbackFunction(uri, success, errorbody)
711
704
  * OR returns a promise
705
+ * @param options - Options for the fetch call
712
706
  */
713
707
  update(
714
708
  deletions: ReadonlyArray<Statement>,
@@ -719,7 +713,8 @@ export default class UpdateManager {
719
713
  errorBody?: string,
720
714
  response?: Response | Error
721
715
  ) => void,
722
- secondTry?: boolean
716
+ secondTry?: boolean,
717
+ options: Options = {}
723
718
  ): void | Promise<void> {
724
719
  if (!callback) {
725
720
  var thisUpdater = this
@@ -730,7 +725,7 @@ export default class UpdateManager {
730
725
  } else {
731
726
  resolve()
732
727
  }
733
- }) // callbackFunction
728
+ }, secondTry, options) // callbackFunction
734
729
  }) // promise
735
730
  } // if
736
731
 
@@ -787,10 +782,10 @@ export default class UpdateManager {
787
782
  }
788
783
  // console.log(`Update: have not loaded ${doc} before: loading now...`);
789
784
  (this.store.fetcher.load(doc) as Promise<Response>).then(response => {
790
- this.update(deletions, insertions, callback, true)
785
+ this.update(deletions, insertions, callback, true, options)
791
786
  }, err => {
792
787
  if (err.response.status === 404) { // nonexistent files are fine
793
- this.update(deletions, insertions, callback, true)
788
+ this.update(deletions, insertions, callback, true, options)
794
789
  } else {
795
790
  throw new Error(`Update: Can't get updatability status ${doc} before patching: ${err}`)
796
791
  }
@@ -831,7 +826,7 @@ export default class UpdateManager {
831
826
  if (ds.length) query += ' ; '
832
827
  query += 'INSERT DATA { '
833
828
  for (let i = 0; i < is.length; i++) {
834
- query += this.anonymizeNT(is[i]) + '\n'
829
+ query += this.nTriples(is[i]) + '\n'
835
830
  }
836
831
  query += ' }\n'
837
832
  }
@@ -869,13 +864,13 @@ export default class UpdateManager {
869
864
  // console.log('delayed downstream action:')
870
865
  downstreamAction(doc)
871
866
  }
872
- })
867
+ }, options)
873
868
  } else if ((protocol as string).indexOf('DAV') >= 0) {
874
- this.updateDav(doc, ds, is, callback)
869
+ this.updateDav(doc, ds, is, callback, options)
875
870
  } else {
876
871
  if ((protocol as string).indexOf('LOCALFILE') >= 0) {
877
872
  try {
878
- this.updateLocalFile(doc, ds, is, callback)
873
+ this.updateLocalFile(doc, ds, is, callback, options)
879
874
  } catch (e) {
880
875
  callback(doc.value, false,
881
876
  'Exception trying to write back file <' + doc.value + '>\n'
@@ -896,7 +891,8 @@ export default class UpdateManager {
896
891
  doc: Quad_Subject,
897
892
  ds,
898
893
  is,
899
- callbackFunction
894
+ callbackFunction,
895
+ options: Options = {}
900
896
  ): null | Promise<void> {
901
897
  let kb = this.store
902
898
  // The code below is derived from Kenny's UpdateCenter.js
@@ -929,11 +925,9 @@ export default class UpdateManager {
929
925
  targetURI = uriJoin(candidateTarget.value, targetURI)
930
926
  }
931
927
 
932
- let options = {
933
- contentType,
934
- noMeta: true,
935
- body: documentString
936
- }
928
+ options.contentType = contentType
929
+ options.noMeta = true
930
+ options.body = documentString
937
931
 
938
932
  return kb.fetcher.webOperation('PUT', targetURI, options)
939
933
  .then(response => {
@@ -962,8 +956,9 @@ export default class UpdateManager {
962
956
  * @param ds
963
957
  * @param is
964
958
  * @param callbackFunction
959
+ * @param options
965
960
  */
966
- updateLocalFile (doc: NamedNode, ds, is, callbackFunction): void {
961
+ updateLocalFile (doc: NamedNode, ds, is, callbackFunction, options: Options = {}): void {
967
962
  const kb = this.store
968
963
  // console.log('Writing back to local file\n')
969
964
 
@@ -988,12 +983,10 @@ export default class UpdateManager {
988
983
  throw new Error('File extension .' + ext + ' not supported for data write')
989
984
  }
990
985
 
991
- const documentString = this.serialize(doc.value, newSts, contentType)
986
+ options.body = this.serialize(doc.value, newSts, contentType);
987
+ options.contentType = contentType;
992
988
 
993
- kb.fetcher.webOperation('PUT',doc.value,{
994
- "body" : documentString,
995
- contentType : contentType,
996
- }).then( (response)=>{
989
+ kb.fetcher.webOperation('PUT', doc.value, options).then( (response)=>{
997
990
  if(!response.ok) return callbackFunction(doc.value,false,response.error)
998
991
  for (let i = 0; i < ds.length; i++) {
999
992
  kb.remove(ds[i]);