rdflib 2.2.21 → 2.2.22-0de51c50

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 (115) hide show
  1. package/dist/rdflib.min.js +1 -1
  2. package/dist/rdflib.min.js.LICENSE.txt +13 -1
  3. package/dist/rdflib.min.js.map +1 -1
  4. package/esm/blank-node.js +3 -27
  5. package/esm/collection.js +7 -29
  6. package/esm/default-graph.js +1 -15
  7. package/esm/empty.js +0 -13
  8. package/esm/factories/canonical-data-factory.js +5 -40
  9. package/esm/factories/extended-term-factory.js +0 -11
  10. package/esm/factories/factory-types.js +2 -1
  11. package/esm/factories/rdflib-data-factory.js +0 -8
  12. package/esm/fetcher.js +257 -481
  13. package/esm/formula.js +43 -142
  14. package/esm/index.js +19 -36
  15. package/esm/jsonldparser.js +20 -29
  16. package/esm/jsonparser.js +0 -7
  17. package/esm/lists.js +18 -33
  18. package/esm/literal.js +10 -42
  19. package/esm/n3parser.js +38 -351
  20. package/esm/named-node.js +8 -27
  21. package/esm/namespace.js +0 -1
  22. package/esm/node-internal.js +11 -24
  23. package/esm/node.js +1 -6
  24. package/esm/parse.js +10 -17
  25. package/esm/patch-parser.js +9 -29
  26. package/esm/query-to-sparql.js +0 -18
  27. package/esm/query.js +50 -133
  28. package/esm/rdfaparser.js +72 -210
  29. package/esm/rdfxmlparser.js +31 -128
  30. package/esm/serialize.js +8 -33
  31. package/esm/serializer.js +122 -286
  32. package/esm/sparql-to-query.js +44 -134
  33. package/esm/statement.js +8 -19
  34. package/esm/store.js +109 -280
  35. package/esm/types.js +3 -2
  36. package/esm/update-manager.js +110 -246
  37. package/esm/updates-via.js +0 -27
  38. package/esm/uri.js +6 -50
  39. package/esm/utils/default-graph-uri.js +1 -0
  40. package/esm/utils/termValue.js +0 -1
  41. package/esm/utils/terms.js +15 -16
  42. package/esm/utils-js.js +16 -57
  43. package/esm/utils.js +4 -15
  44. package/esm/variable.js +0 -20
  45. package/lib/blank-node.js +3 -28
  46. package/lib/class-order.js +0 -1
  47. package/lib/collection.js +7 -34
  48. package/lib/default-graph.js +0 -20
  49. package/lib/empty.js +0 -18
  50. package/lib/factories/canonical-data-factory.js +4 -51
  51. package/lib/factories/extended-term-factory.js +0 -18
  52. package/lib/factories/factory-types.d.ts +6 -6
  53. package/lib/factories/factory-types.js +0 -3
  54. package/lib/factories/rdflib-data-factory.js +0 -12
  55. package/lib/fetcher.d.ts +6 -6
  56. package/lib/fetcher.js +258 -470
  57. package/lib/formula.d.ts +1 -1
  58. package/lib/formula.js +43 -151
  59. package/lib/index.d.ts +1 -2
  60. package/lib/index.js +14 -82
  61. package/lib/jsonldparser.js +19 -33
  62. package/lib/jsonparser.js +0 -9
  63. package/lib/lists.js +14 -39
  64. package/lib/literal.js +10 -49
  65. package/lib/log.d.ts +0 -6
  66. package/lib/log.js +0 -1
  67. package/lib/n3parser.d.ts +1 -0
  68. package/lib/n3parser.js +39 -359
  69. package/lib/named-node.js +7 -35
  70. package/lib/namespace.js +0 -3
  71. package/lib/node-internal.js +11 -21
  72. package/lib/node.js +1 -11
  73. package/lib/parse.d.ts +1 -1
  74. package/lib/parse.js +8 -27
  75. package/lib/patch-parser.js +10 -33
  76. package/lib/query-to-sparql.js +0 -23
  77. package/lib/query.js +46 -152
  78. package/lib/rdfaparser.js +72 -220
  79. package/lib/rdfxmlparser.js +31 -132
  80. package/lib/serialize.d.ts +1 -1
  81. package/lib/serialize.js +8 -43
  82. package/lib/serializer.d.ts +1 -0
  83. package/lib/serializer.js +121 -297
  84. package/lib/sparql-to-query.js +42 -167
  85. package/lib/statement.js +8 -24
  86. package/lib/store.d.ts +2 -2
  87. package/lib/store.js +102 -282
  88. package/lib/tf-types.d.ts +4 -4
  89. package/lib/types.d.ts +8 -8
  90. package/lib/types.js +3 -3
  91. package/lib/update-manager.d.ts +2 -2
  92. package/lib/update-manager.js +110 -254
  93. package/lib/updates-via.js +0 -30
  94. package/lib/uri.js +5 -58
  95. package/lib/utils/default-graph-uri.js +1 -3
  96. package/lib/utils/termValue.js +0 -2
  97. package/lib/utils/terms.js +15 -34
  98. package/lib/utils-js.js +16 -80
  99. package/lib/utils.js +4 -21
  100. package/lib/variable.js +0 -25
  101. package/lib/xsd-internal.js +0 -3
  102. package/lib/xsd.js +0 -4
  103. package/package.json +40 -39
  104. package/src/fetcher.ts +2 -2
  105. package/src/index.ts +0 -2
  106. package/src/jsonldparser.js +13 -4
  107. package/src/n3parser.js +12 -4
  108. package/src/serialize.ts +4 -11
  109. package/src/serializer.js +24 -0
  110. package/src/update-manager.ts +18 -7
  111. package/changes.txt +0 -59
  112. package/esm/convert.js +0 -61
  113. package/lib/convert.d.ts +0 -2
  114. package/lib/convert.js +0 -77
  115. package/src/convert.js +0 -70
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.21",
4
+ "version": "2.2.22-0de51c50",
5
5
  "private": false,
6
6
  "browserslist": [
7
7
  "> 0.5%"
@@ -44,62 +44,63 @@
44
44
  "homepage": "http://github.com/linkeddata/rdflib.js",
45
45
  "bugs": "http://github.com/linkeddata/rdflib.js/issues",
46
46
  "dependencies": {
47
- "@babel/runtime": "^7.17.8",
48
- "@xmldom/xmldom": "^0.8.1",
49
- "async": "^3.2.3",
47
+ "@babel/runtime": "^7.20.1",
48
+ "@frogcat/ttl2jsonld": "^0.0.9",
49
+ "@xmldom/xmldom": "^0.8.6",
50
50
  "cross-fetch": "^3.1.5",
51
- "jsonld": "^5.2.0",
52
- "n3": "^1.16.0",
51
+ "jsonld": "^8.1.0",
52
+ "n3": "^1.16.3",
53
53
  "solid-namespace": "^0.5.2"
54
54
  },
55
55
  "devDependencies": {
56
- "@babel/cli": "^7.17.6",
57
- "@babel/core": "^7.17.8",
58
- "@babel/plugin-proposal-class-properties": "^7.16.7",
59
- "@babel/plugin-transform-runtime": "^7.17.0",
60
- "@babel/preset-env": "^7.16.11",
61
- "@babel/preset-typescript": "^7.16.7",
62
- "@babel/register": "^7.17.7",
63
- "@types/chai": "^4.3.0",
56
+ "@babel/cli": "^7.19.3",
57
+ "@babel/core": "^7.20.2",
58
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
59
+ "@babel/plugin-transform-runtime": "^7.19.6",
60
+ "@babel/preset-env": "^7.20.2",
61
+ "@babel/preset-typescript": "^7.18.6",
62
+ "@babel/register": "^7.18.9",
63
+ "@types/chai": "^4.3.4",
64
64
  "@types/dirty-chai": "^2.0.2",
65
- "@types/express": "^4.17.13",
66
- "@types/jsonld": "^1.5.6",
67
- "@types/rdf-js": "^4.0.2",
68
- "@types/sinon-chai": "^3.2.8",
69
- "babel-loader": "^8.2.4",
70
- "chai": "^4.3.6",
71
- "diff": "^5.0.0",
65
+ "@types/express": "^4.17.14",
66
+ "@types/jsonld": "^1.5.8",
67
+ "@types/sinon-chai": "^3.2.9",
68
+ "babel-loader": "^9.1.0",
69
+ "chai": "^4.3.7",
70
+ "diff": "^5.1.0",
72
71
  "dirty-chai": "^2.0.1",
73
- "eslint": "^8.12.0",
72
+ "eslint": "^8.28.0",
74
73
  "fs-grep": "0.0.5",
75
- "locate-path": "^7.1.0",
76
- "mocha": "^9.2.2",
77
- "nock": "^13.2.4",
78
- "node-fetch": "^2.6.7",
79
- "node-polyfill-webpack-plugin": "^1.1.4",
80
- "sinon": "^13.0.1",
74
+ "locate-path": "^7.1.1",
75
+ "mocha": "^10.1.0",
76
+ "nock": "^13.2.9",
77
+ "node-fetch": "^3.3.0",
78
+ "node-polyfill-webpack-plugin": "^2.0.1",
79
+ "rdf-js": "^4.0.2",
80
+ "sinon": "^14.0.2",
81
81
  "sinon-chai": "^3.7.0",
82
- "source-map-loader": "^3.0.1",
83
- "ts-node": "^10.7.0",
84
- "typedoc": "^0.22.13",
85
- "typescript": "^4.6.3",
86
- "webpack": "^5.70.0",
87
- "webpack-cli": "^4.9.2",
88
- "webpack-dev-server": "^4.7.4"
82
+ "source-map-loader": "^4.0.1",
83
+ "ts-node": "^10.9.1",
84
+ "typedoc": "^0.23.24",
85
+ "typescript": "^4.9.3",
86
+ "webpack": "^5.75.0",
87
+ "webpack-cli": "^5.0.0",
88
+ "webpack-dev-server": "^4.11.1"
89
89
  },
90
90
  "scripts": {
91
91
  "build": "babel src --extensions \".ts,.js\" -d lib",
92
92
  "build:esm": "babel src --extensions \".ts,.js\" --env-name esm -d esm",
93
93
  "build:browser": "webpack --progress",
94
94
  "build:types": "tsc --emitDeclarationOnly -d --moduleResolution node --declarationDir lib",
95
+ "build:all": "npm run build && npm run build:types && npm run build:browser && npm run build:esm",
95
96
  "doc": "typedoc --out ./doc ./src/index.ts --excludePrivate --excludeInternal --tsconfig ./tsconfig.json",
96
- "ignore:prepublishOnly": "npm ci && npm run build && npm run build:types && npm run build:browser && npm run build:esm",
97
+ "ignore:prepublishOnly": "npm ci && npm run build:all && npm run doc && npm run test",
97
98
  "postversion": "git push --follow-tags",
98
99
  "start": "webpack serve --port 4800",
99
100
  "test": "npm run test:unit && npm run test:serialize && npm run test:types",
100
101
  "test:clean": "rimraf tests/serialize/,*",
101
102
  "test:serialize": "npm run build && npm run test:serialize:all && npm run test:clean",
102
- "test:serialize:all": "npm run test:serialize:1 && npm run test:serialize:2 && npm run test:serialize:3 && npm run test:serialize:4 && npm run test:serialize:5 && npm run test:serialize:6 && npm run test:serialize:7 && npm run test:serialize:10 && npm run test:serialize:11 && npm run test:serialize:12 && npm run test:serialize:13 && npm run test:serialize:14 && npm run test:serialize:15",
103
+ "test:serialize:all": "npm run test:serialize:1 && npm run test:serialize:2 && npm run test:serialize:3 && npm run test:serialize:4 && npm run test:serialize:5 && npm run test:serialize:6 && npm run test:serialize:7 && npm run test:serialize:8 && npm run test:serialize:10 && npm run test:serialize:11 && npm run test:serialize:12 && npm run test:serialize:13 && npm run test:serialize:14 && npm run test:serialize:15",
103
104
  "test:serialize:1": "cd ./tests/serialize && node ./data.js -in=t1.ttl -format=application/rdf+xml -out=,t1.xml && fs-grep http://www.w3.org/2001/XMLSchema#integer ,t1.xml",
104
105
  "test:serialize:2": "cd ./tests/serialize && node ./data.js -in=t2.ttl -format=application/rdf+xml -out=,t2.xml && node diff ,t2.xml t2-ref.xml",
105
106
  "test:serialize:3": "cd ./tests/serialize && node ./data.js -in=t3.ttl -format=application/rdf+xml -out=,t3.xml && node diff ,t3.xml t3-ref.xml",
@@ -107,14 +108,14 @@
107
108
  "test:serialize:5": "cd ./tests/serialize && node ./data.js -in=t5.n3 -format=text/turtle -out=,t5.ttl && node diff ,t5.ttl t5-ref.ttl",
108
109
  "test:serialize:6": "cd ./tests/serialize && node ./data.js -in=t5.n3 -format=text/n3 -out=,t6.n3 && node diff ,t6.n3 t6-ref.n3",
109
110
  "test:serialize:7": "cd ./tests/serialize && node ./data.js -in=t7.n3 -format=application/n-triples -out=,t7.nt && node diff ,t7.nt t7-ref.nt",
110
- "test:serialize:8": "cd ./tests/serialize && node ./data.js -in=t5.n3 -format=application/n-quads -dump=,t8.nq && node diff ,t8.nq t8-ref.nq",
111
- "test:serialize:9": "cd ./tests/serialize && node ./data.js -in=t7.n3 -format=application/ld+json -out=,t9.json && node diff ,t9.json t9-ref.json",
111
+ "test:serialize:8": "cd ./tests/serialize && node ./data.js -in=t5.n3 -format=application/n-quads -out=,t8.nq && node diff ,t8.nq t8-ref.nq",
112
112
  "test:serialize:10": "cd ./tests/serialize && node ./data.js -in=details.ttl -format=text/turtle -out=,t10.ttl && node diff ,t10.ttl t10-ref.ttl",
113
113
  "test:serialize:11": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=application/rdf+xml -out=,structures.xml && node diff ,structures.xml t11-ref.xml",
114
114
  "test:serialize:12": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=text/turtle -out=,structures.ttl && node diff ,structures.ttl t12-ref.ttl",
115
115
  "test:serialize:13": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=application/n-triples -out=,structures.nt && node ./data.js -format=application/n-triples -in=,structures.nt -format=text/turtle -out=,structures.nt.ttl && node diff ,structures.nt.ttl t13-ref.ttl",
116
116
  "test:serialize:14": "cd ./tests/serialize && node ./data.js -in=t14.html -format=text/turtle -out=,t14.ttl && node diff ,t14.ttl t14-ref.ttl",
117
117
  "test:serialize:15": "cd ./tests/serialize && node ./data.js -in=t15.html -format=text/turtle -out=,t15.ttl && node diff ,t15.ttl t15-ref.ttl",
118
+ "test:serialize:16": "cd ./tests/serialize && node ./data.js -in=t1.ttl -format=application/ld+json -out=,t1.jsonld && node diff ,t1.jsonld t16-ref.jsonld",
118
119
  "test:types": "tsc --noEmit --target es2019 --moduleResolution node tests/types/*.ts",
119
120
  "test:unit": "mocha --growl --require ./tests/babel-register.js tests/unit/**-test.*",
120
121
  "test:unit:egp": "mocha --require ./tests/babel-register.js tests/unit/fetcher-egp-test.js",
package/src/fetcher.ts CHANGED
@@ -979,7 +979,7 @@ export default class Fetcher implements CallbackifyInterface {
979
979
  return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions) as any
980
980
  }
981
981
 
982
- pendingFetchPromise (
982
+ async pendingFetchPromise (
983
983
  uri: string,
984
984
  originalUri: string,
985
985
  options: AutoInitOptions
@@ -987,7 +987,7 @@ export default class Fetcher implements CallbackifyInterface {
987
987
  let pendingPromise
988
988
 
989
989
  // Check to see if some request is already dealing with this uri
990
- if (!options.force && this.fetchQueue[originalUri]) {
990
+ if (!options.force && await this.fetchQueue[originalUri]) {
991
991
  pendingPromise = this.fetchQueue[originalUri]
992
992
  } else {
993
993
  pendingPromise = Promise
package/src/index.ts CHANGED
@@ -2,7 +2,6 @@ import { IRDFlibDataFactory } from './types'
2
2
 
3
3
  import BlankNode from './blank-node'
4
4
  import Collection from './collection'
5
- import * as convert from './convert'
6
5
  import Empty from './empty'
7
6
  import Fetcher from './fetcher'
8
7
  import Formula from './formula'
@@ -66,7 +65,6 @@ export type { AutoInitOptions, ExtendedResponse, FetchError } from './fetcher'
66
65
  export {
67
66
  BlankNode,
68
67
  Collection,
69
- convert,
70
68
  DataFactory,
71
69
  Empty,
72
70
  Fetcher,
@@ -22,7 +22,7 @@ export function jsonldObjectToTerm (kb, obj) {
22
22
  }
23
23
 
24
24
  if (Object.prototype.hasOwnProperty.call(obj, '@id')) {
25
- return kb.rdfFactory.namedNode(obj['@id'])
25
+ return nodeType(kb, obj)
26
26
  }
27
27
 
28
28
  if (Object.prototype.hasOwnProperty.call(obj, '@language')) {
@@ -44,7 +44,7 @@ export function jsonldObjectToTerm (kb, obj) {
44
44
  * Adds the statements in a json-ld list object to {kb}.
45
45
  */
46
46
  function listToStatements (kb, obj) {
47
- const listId = obj['@id'] ? kb.rdfFactory.namedNode(obj['@id']) : kb.rdfFactory.blankNode()
47
+ const listId = obj['@id'] ? nodeType(kb, obj) : kb.rdfFactory.blankNode()
48
48
 
49
49
  const items = obj['@list'].map((listItem => jsonldObjectToTerm(kb, listItem)))
50
50
  const statements = arrayToStatements(kb.rdfFactory, listId, items)
@@ -82,10 +82,19 @@ export default function jsonldParser (str, kb, base, callback) {
82
82
  .catch(callback)
83
83
  }
84
84
 
85
+ function nodeType (kb, obj) {
86
+ if (obj['@id'].startsWith('_:')) {
87
+ // This object is a Blank Node. Pass the id without the `_:` prefix
88
+ return kb.rdfFactory.blankNode(obj['@id'].substring(2));
89
+ } else {
90
+ // This object is a Named Node
91
+ return kb.rdfFactory.namedNode(obj['@id']);
92
+ }
93
+ }
85
94
 
86
95
  function processResource(kb, base, flatResource) {
87
96
  const id = flatResource['@id']
88
- ? kb.rdfFactory.namedNode(flatResource['@id'])
97
+ ? nodeType(kb, flatResource)
89
98
  : kb.rdfFactory.blankNode()
90
99
 
91
100
  for (const property of Object.keys(flatResource)) {
@@ -136,4 +145,4 @@ function createStatement(kb, id, property, value, base) {
136
145
  object = jsonldObjectToTerm(kb, value)
137
146
  }
138
147
  return kb.rdfFactory.quad(id, predicate, object, kb.rdfFactory.namedNode(base))
139
- }
148
+ }
package/src/n3parser.js CHANGED
@@ -6,6 +6,7 @@
6
6
  **/
7
7
  import * as Uri from './uri'
8
8
  import { ArrayIndexOf } from './utils'
9
+ import { convertFirstRestNil } from './lists'
9
10
 
10
11
  function hexify (str) { // also used in parser
11
12
  return encodeURI(str);
@@ -148,6 +149,7 @@ var diag_progress = function(str) { /*$rdf.log.debug(str);*/ }
148
149
 
149
150
 
150
151
  var RDF_type_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
152
+ var RDF_nil_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
151
153
  var DAML_sameAs_URI = "http://www.w3.org/2002/07/owl#sameAs";
152
154
 
153
155
  /*
@@ -247,6 +249,7 @@ export class SinkParser {
247
249
  this.source = store.sym(thisDoc);
248
250
  this.lines = 0;
249
251
  this.statementCount = 0;
252
+ this.hasNil = false;
250
253
  this.startOfLine = 0;
251
254
  this.previousLine = 0;
252
255
  this._genPrefix = genPrefix;
@@ -509,14 +512,20 @@ export class SinkParser {
509
512
  };
510
513
  startDoc() {
511
514
  };
512
- endDoc() {
513
- /*
514
- Signal end of document and stop parsing. returns formula*/
515
515
 
516
+ /* Signal end of document and stop parsing. returns formula */
517
+ endDoc() {
518
+ if (this.hasNil && this._store.rdfFactory.supports["COLLECTIONS"]) {
519
+ convertFirstRestNil(this._store, this.source)
520
+ }
516
521
  return this._formula;
517
522
  };
518
523
  makeStatement(quad) {
519
524
  quad[0].add(quad[2], quad[1], quad[3], this.source);
525
+ if ((quad[2].uri && quad[2].uri === RDF_nil_URI)
526
+ || (quad[3].uri && quad[3].uri === RDF_nil_URI)) {
527
+ this.hasNil = true
528
+ }
520
529
  this.statementCount += 1;
521
530
  };
522
531
  statement(str, i) {
@@ -1571,4 +1580,3 @@ function stripCR(str) {
1571
1580
 
1572
1581
  function dummyWrite(x) {
1573
1582
  }
1574
-
package/src/serialize.ts CHANGED
@@ -1,4 +1,3 @@
1
- import * as convert from './convert'
2
1
  import Formula from './formula'
3
2
  import Serializer from './serializer'
4
3
  import {
@@ -42,7 +41,7 @@ export default function serialize (
42
41
  */
43
42
  namespaces?: Record<string, string>
44
43
  }
45
- ): string | undefined {
44
+ ): string | undefined | Promise<string> {
46
45
  base = base || target?.value
47
46
  const opts = options || {}
48
47
  contentType = contentType || TurtleContentType // text/n3 if complex?
@@ -51,7 +50,6 @@ export default function serialize (
51
50
  var sz = Serializer(kb)
52
51
  if ((opts as any).flags) sz.setFlags((opts as any).flags)
53
52
  var newSts = kb!.statementsMatching(undefined, undefined, undefined, target as NamedNode)
54
- var n3String: string
55
53
 
56
54
  // If an IndexedFormula, use the namespaces from the given graph as suggestions
57
55
  if ('namespaces' in kb) {
@@ -82,19 +80,14 @@ export default function serialize (
82
80
  documentString = sz.statementsToNTriples(newSts)
83
81
  return executeCallback(null, documentString)
84
82
  case JSONLDContentType:
85
- sz.setFlags('deinprstux') // Use adapters to connect to incmpatible parser
86
- n3String = sz.statementsToNTriples(newSts)
87
- // n3String = sz.statementsToN3(newSts)
88
- convert.convertToJson(n3String, callback)
89
- break
83
+ sz.setFlags('si') // use turtle parameters
84
+ documentString = sz.statementsToJsonld(newSts) // convert via turtle
85
+ return executeCallback(null, documentString)
90
86
  case NQuadsContentType:
91
87
  case NQuadsAltContentType: // @@@ just outpout the quads? Does not work for collections
92
88
  sz.setFlags('deinprstux q') // Suppress nice parts of N3 to make ntriples
93
89
  documentString = sz.statementsToNTriples(newSts) // q in flag means actually quads
94
90
  return executeCallback(null, documentString)
95
- // n3String = sz.statementsToN3(newSts)
96
- // documentString = convert.convertToNQuads(n3String, callback)
97
- // break
98
91
  default:
99
92
  throw new Error('Serialize: Content-type ' + contentType + ' not supported for data write.')
100
93
  }
package/src/serializer.js CHANGED
@@ -12,6 +12,8 @@ import * as Util from './utils-js'
12
12
  import CanonicalDataFactory from './factories/canonical-data-factory'
13
13
  import { createXSD } from './xsd'
14
14
  import solidNs from 'solid-namespace'
15
+ // import * as jsonld from 'jsonld'
16
+ import * as ttl2jsonld from '@frogcat/ttl2jsonld'
15
17
 
16
18
 
17
19
  export default function createSerializer(store) {
@@ -1011,6 +1013,28 @@ export class Serializer {
1011
1013
  var tree2 = [str, tree, '</rdf:RDF>'] // @@ namespace declrations
1012
1014
  return XMLtreeToString(tree2, -1)
1013
1015
  } // End @@ body
1016
+
1017
+ statementsToJsonld (sts) {
1018
+ // ttl2jsonld creates context keys for all ttl prefix
1019
+ // context keys must be full IRI
1020
+ function findId (itemObj) {
1021
+ if (itemObj['@id']) {
1022
+ const item = itemObj['@id'].split(':')
1023
+ if (keys[item[0]]) itemObj['@id'] = jsonldObj['@context'][item[0]] + item[1]
1024
+ }
1025
+ const itemValues = Object.values(itemObj)
1026
+ for (const i in itemValues) {
1027
+ if (typeof itemValues[i] !== 'string') { // @list contains array
1028
+ findId(itemValues[i])
1029
+ }
1030
+ }
1031
+ }
1032
+ const turtleDoc = this.statementsToN3(sts)
1033
+ const jsonldObj = ttl2jsonld.parse(turtleDoc)
1034
+
1035
+ return JSON.stringify(jsonldObj, null, 2)
1036
+ }
1037
+
1014
1038
  }
1015
1039
 
1016
1040
  // String escaping utilities
@@ -213,7 +213,7 @@ export default class UpdateManager {
213
213
  * Returns a list of all bnodes occurring in a list of statements
214
214
  * @private
215
215
  */
216
- statementArrayBnodes (sts: Quad[]) {
216
+ statementArrayBnodes (sts: ReadonlyArray<Quad>) {
217
217
  var bnodes: BlankNode[] = []
218
218
  for (let i = 0; i < sts.length; i++) {
219
219
  bnodes = bnodes.concat(this.statementBnodes(sts[i]))
@@ -752,7 +752,13 @@ export default class UpdateManager {
752
752
  // console.log(message)
753
753
  throw new Error(message)
754
754
  }
755
+ if (doc.termType !== 'NamedNode') {
756
+ let message = 'Error patching: document not a NamedNode:' + ds[0] + ', ' + is[0]
757
+ // console.log(message)
758
+ throw new Error(message)
759
+ }
755
760
  var control = this.patchControlFor(doc)
761
+
756
762
  var startTime = Date.now()
757
763
 
758
764
  var props = ['subject', 'predicate', 'object', 'why']
@@ -781,7 +787,7 @@ export default class UpdateManager {
781
787
  throw new Error('Update: Loaded ' + doc + "but stil can't figure out what editing protcol it supports.")
782
788
  }
783
789
  // console.log(`Update: have not loaded ${doc} before: loading now...`);
784
- (this.store.fetcher.load(doc) as Promise<Response>).then(response => {
790
+ (this.store.fetcher.load(doc as NamedNode) as Promise<Response>).then(response => {
785
791
  this.update(deletions, insertions, callback, true, options)
786
792
  }, err => {
787
793
  if (err.response.status === 404) { // nonexistent files are fine
@@ -793,8 +799,13 @@ export default class UpdateManager {
793
799
  return
794
800
  } else if ((protocol as string).indexOf('SPARQL') >= 0) {
795
801
  var bnodes: BlankNode[] = []
796
- if (ds.length) bnodes = this.statementArrayBnodes(ds)
797
- if (is.length) bnodes = bnodes.concat(this.statementArrayBnodes(is))
802
+ // change ReadOnly type to Mutable type
803
+ type Mutable<Type> = {
804
+ -readonly [Key in keyof Type]: Type[Key];
805
+ }
806
+
807
+ if (ds.length) bnodes = this.statementArrayBnodes(ds as Mutable<typeof ds>)
808
+ if (is.length) bnodes = bnodes.concat(this.statementArrayBnodes(is as Mutable<typeof is>))
798
809
  var context = this.bnodeContext(bnodes, doc)
799
810
  var whereClause = this.contextWhere(context)
800
811
  var query = ''
@@ -846,7 +857,7 @@ export default class UpdateManager {
846
857
  */
847
858
  if (success) {
848
859
  try {
849
- kb.remove(ds)
860
+ kb.remove(ds as Mutable<typeof ds>)
850
861
  } catch (e) {
851
862
  success = false
852
863
  body = 'Remote Ok BUT error deleting ' + ds.length + ' from store!!! ' + e
@@ -867,11 +878,11 @@ export default class UpdateManager {
867
878
  }
868
879
  }, options)
869
880
  } else if ((protocol as string).indexOf('DAV') >= 0) {
870
- this.updateDav(doc, ds, is, callback, options)
881
+ this.updateDav(doc as NamedNode, ds, is, callback, options)
871
882
  } else {
872
883
  if ((protocol as string).indexOf('LOCALFILE') >= 0) {
873
884
  try {
874
- this.updateLocalFile(doc, ds, is, callback, options)
885
+ this.updateLocalFile(doc as NamedNode, ds, is, callback, options)
875
886
  } catch (e) {
876
887
  callback(doc.value, false,
877
888
  'Exception trying to write back file <' + doc.value + '>\n'
package/changes.txt DELETED
@@ -1,59 +0,0 @@
1
- REMOVED FILES:
2
-
3
- plistClosure.js -> no refs to about() or pickOne.
4
- unify.js -> contained _no_ code !
5
- remote.js -> remoteQuery ref'd in query.js, but commented out.
6
- parser.js -> not used anymore.
7
-
8
- LOGGING:
9
-
10
- Without assuming that there is a global log var, logging can be weird. What do we do?
11
- (bring in the log js)
12
-
13
- ORDERING:
14
-
15
- util.js - done (util-nonlib.js) - FIGURE OUT AJAR_HandleNew (should be in sources probably..) for now in util class.
16
- uri.js - done (REMOVED URIjoin, uri_docpart, uri_protocol
17
- term.js - done..
18
- rdfparser.js -done..
19
- n3parser.js -ew, but done.
20
- identity.js 21k -RDFArrayRemove now in Util.RDFArrayRemove.
21
- query.js 21k -NEEDS MORE WORK.
22
- sources.js 37k -ok??
23
- serialize.js 24k -OK!
24
- sparqlUpdate.js 8k -ok, seemingly.
25
- sparql.js 21k -SPARQLtoQuery needs kb in calls to it now.. isbnode: /^[]$/ -> /^$/ NO! Take it back.
26
-
27
- TODO: Add the minor sources bugfix into sources.js!
28
-
29
- HANGING GLOBALS:
30
-
31
- isExtension
32
-
33
-
34
-
35
-
36
- =========================================================================
37
- extension code!
38
-
39
- KILLED GLOBALS:
40
- string_startswith
41
- kb
42
- sf
43
- qs
44
-
45
-
46
- NAMESPACE GLOBALS DELETED:
47
- mo
48
- contact
49
- xsd
50
- rss
51
- dc
52
- owl
53
- rdfs
54
- rdf
55
- tabont
56
- foaf
57
-
58
-
59
- WEBDAV.js -- WHERE IS IT NEEDED.
package/esm/convert.js DELETED
@@ -1,61 +0,0 @@
1
- import asyncLib from 'async'; // @@ Goal: remove this dependency
2
-
3
- import jsonld from 'jsonld';
4
- import { Parser, Writer } from 'n3'; // @@ Goal: remove this dependency
5
-
6
- export function convertToJson(n3String, jsonCallback) {
7
- var jsonString;
8
- var n3Parser = new Parser();
9
- var n3Writer = new Writer({
10
- format: 'N-Quads'
11
- });
12
- asyncLib.waterfall([function (callback) {
13
- n3Parser.parse(n3String, function (error, quad, prefixes) {
14
- if (error) {
15
- callback(error);
16
- } else if (quad !== null) {
17
- n3Writer.addQuad(quad);
18
- } else {
19
- n3Writer.end(callback);
20
- }
21
- });
22
- }, function (result, callback) {
23
- try {
24
- jsonld.fromRDF(result, {
25
- format: 'application/nquads'
26
- }).then(function (result) {
27
- callback(null, result);
28
- });
29
- } catch (err) {
30
- callback(err);
31
- }
32
- }, function (json, callback) {
33
- jsonString = JSON.stringify(json);
34
- jsonCallback(null, jsonString);
35
- }], function (err, result) {
36
- jsonCallback(err, jsonString);
37
- });
38
- }
39
- export function convertToNQuads(n3String, nquadCallback) {
40
- var nquadString;
41
- var n3Parser = new Parser();
42
- var n3Writer = new Writer({
43
- format: 'N-Quads'
44
- });
45
- asyncLib.waterfall([function (callback) {
46
- n3Parser.parse(n3String, function (error, triple, prefixes) {
47
- if (error) {
48
- callback(error);
49
- } else if (quad !== null) {
50
- n3Writer.addQuad(quad);
51
- } else {
52
- n3Writer.end(callback);
53
- }
54
- });
55
- }, function (result, callback) {
56
- nquadString = result;
57
- nquadCallback(null, nquadString);
58
- }], function (err, result) {
59
- nquadCallback(err, nquadString);
60
- });
61
- }
package/lib/convert.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export function convertToJson(n3String: any, jsonCallback: any): void;
2
- export function convertToNQuads(n3String: any, nquadCallback: any): void;
package/lib/convert.js DELETED
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.convertToJson = convertToJson;
9
- exports.convertToNQuads = convertToNQuads;
10
-
11
- var _async = _interopRequireDefault(require("async"));
12
-
13
- var _jsonld = _interopRequireDefault(require("jsonld"));
14
-
15
- var _n = require("n3");
16
-
17
- // @@ Goal: remove this dependency
18
- // @@ Goal: remove this dependency
19
- function convertToJson(n3String, jsonCallback) {
20
- var jsonString;
21
- var n3Parser = new _n.Parser();
22
- var n3Writer = new _n.Writer({
23
- format: 'N-Quads'
24
- });
25
-
26
- _async.default.waterfall([function (callback) {
27
- n3Parser.parse(n3String, function (error, quad, prefixes) {
28
- if (error) {
29
- callback(error);
30
- } else if (quad !== null) {
31
- n3Writer.addQuad(quad);
32
- } else {
33
- n3Writer.end(callback);
34
- }
35
- });
36
- }, function (result, callback) {
37
- try {
38
- _jsonld.default.fromRDF(result, {
39
- format: 'application/nquads'
40
- }).then(function (result) {
41
- callback(null, result);
42
- });
43
- } catch (err) {
44
- callback(err);
45
- }
46
- }, function (json, callback) {
47
- jsonString = JSON.stringify(json);
48
- jsonCallback(null, jsonString);
49
- }], function (err, result) {
50
- jsonCallback(err, jsonString);
51
- });
52
- }
53
-
54
- function convertToNQuads(n3String, nquadCallback) {
55
- var nquadString;
56
- var n3Parser = new _n.Parser();
57
- var n3Writer = new _n.Writer({
58
- format: 'N-Quads'
59
- });
60
-
61
- _async.default.waterfall([function (callback) {
62
- n3Parser.parse(n3String, function (error, triple, prefixes) {
63
- if (error) {
64
- callback(error);
65
- } else if (quad !== null) {
66
- n3Writer.addQuad(quad);
67
- } else {
68
- n3Writer.end(callback);
69
- }
70
- });
71
- }, function (result, callback) {
72
- nquadString = result;
73
- nquadCallback(null, nquadString);
74
- }], function (err, result) {
75
- nquadCallback(err, nquadString);
76
- });
77
- }