rdflib 2.2.19-c14dfd57 → 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.
@@ -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]);