rdflib 2.2.37-d3a3ef5f → 2.2.37-dbccd446

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.
@@ -56,7 +56,9 @@ function listToCollection(kb, obj) {
56
56
  export default function jsonldParser(str, kb, base, callback) {
57
57
  const baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base;
58
58
  return import('jsonld').then(jsonld => {
59
- return jsonld.flatten(JSON.parse(str), null, {
59
+ // ⚠ Unit tests also work without accessing `jsonld.default` explicitly, but real browser usage will fail with
60
+ // just calling `jsonld.flatten`, so please do not remove `default`
61
+ return jsonld.default.flatten(JSON.parse(str), null, {
60
62
  base: baseString
61
63
  });
62
64
  }).then(flattened => flattened.reduce((store, flatResource) => {
package/esm/store.js CHANGED
@@ -129,9 +129,7 @@ export default class IndexedFormula extends Formula {
129
129
  /** Function to remove quads from the store arrays with */
130
130
  _defineProperty(this, "rdfArrayRemove", void 0);
131
131
  /** Callbacks which are triggered after a statement has been added to the store */
132
- _defineProperty(this, "dataCallbacks", []);
133
- /** Callbacks which are triggered after a statement has been removed from the store */
134
- _defineProperty(this, "dataRemovalCallbacks", []);
132
+ _defineProperty(this, "dataCallbacks", void 0);
135
133
  this.propertyActions = {};
136
134
  this.classActions = {};
137
135
  this.redirections = [];
@@ -153,9 +151,6 @@ export default class IndexedFormula extends Formula {
153
151
  if (opts.dataCallback) {
154
152
  this.dataCallbacks = [opts.dataCallback];
155
153
  }
156
- if (opts.dataRemovalCallback) {
157
- this.dataRemovalCallbacks = [opts.dataRemovalCallback];
158
- }
159
154
  this.initPropertyActions(this.features);
160
155
  }
161
156
 
@@ -184,11 +179,11 @@ export default class IndexedFormula extends Formula {
184
179
  * @param cb
185
180
  */
186
181
  addDataCallback(cb) {
182
+ if (!this.dataCallbacks) {
183
+ this.dataCallbacks = [];
184
+ }
187
185
  this.dataCallbacks.push(cb);
188
186
  }
189
- addDataRemovalCallback(cb) {
190
- this.dataRemovalCallbacks.push(cb);
191
- }
192
187
 
193
188
  /**
194
189
  * Apply a set of statements to be deleted and to be inserted
@@ -402,8 +397,10 @@ export default class IndexedFormula extends Formula {
402
397
 
403
398
  // log.debug("ADDING {"+subj+" "+pred+" "+objNode+"} "+why)
404
399
  this.statements.push(st);
405
- for (const callback of this.dataCallbacks) {
406
- callback(st);
400
+ if (this.dataCallbacks) {
401
+ for (const callback of this.dataCallbacks) {
402
+ callback(st);
403
+ }
407
404
  }
408
405
  return st;
409
406
  }
@@ -853,9 +850,6 @@ export default class IndexedFormula extends Formula {
853
850
  }
854
851
  }
855
852
  this.rdfArrayRemove(this.statements, st);
856
- for (const callback of this.dataRemovalCallbacks) {
857
- callback(st);
858
- }
859
853
  return this;
860
854
  }
861
855
 
package/lib/formula.d.ts CHANGED
@@ -12,7 +12,6 @@ import BlankNode from './blank-node';
12
12
  import NamedNode from './named-node';
13
13
  export interface FormulaOpts {
14
14
  dataCallback?: (q: Quad) => void;
15
- dataRemovalCallback?: (q: Quad) => void;
16
15
  rdfArrayRemove?: (arr: Quad[], q: Quad) => void;
17
16
  rdfFactory?: RdfJsDataFactory;
18
17
  }
@@ -63,7 +63,9 @@ function listToCollection(kb, obj) {
63
63
  function jsonldParser(str, kb, base, callback) {
64
64
  const baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base;
65
65
  return Promise.resolve().then(() => _interopRequireWildcard(require('jsonld'))).then(jsonld => {
66
- return jsonld.flatten(JSON.parse(str), null, {
66
+ // ⚠ Unit tests also work without accessing `jsonld.default` explicitly, but real browser usage will fail with
67
+ // just calling `jsonld.flatten`, so please do not remove `default`
68
+ return jsonld.default.flatten(JSON.parse(str), null, {
67
69
  base: baseString
68
70
  });
69
71
  }).then(flattened => flattened.reduce((store, flatResource) => {
package/lib/store.d.ts CHANGED
@@ -61,9 +61,7 @@ export default class IndexedFormula extends Formula {
61
61
  /** Function to remove quads from the store arrays with */
62
62
  private rdfArrayRemove;
63
63
  /** Callbacks which are triggered after a statement has been added to the store */
64
- private dataCallbacks;
65
- /** Callbacks which are triggered after a statement has been removed from the store */
66
- private dataRemovalCallbacks;
64
+ private dataCallbacks?;
67
65
  /**
68
66
  * Creates a new formula
69
67
  * @param features - What sort of automatic processing to do? Array of string
@@ -88,7 +86,6 @@ export default class IndexedFormula extends Formula {
88
86
  * @param cb
89
87
  */
90
88
  addDataCallback(cb: (q: Quad) => void): void;
91
- addDataRemovalCallback(cb: (q: Quad) => void): void;
92
89
  /**
93
90
  * Apply a set of statements to be deleted and to be inserted
94
91
  *
package/lib/store.js CHANGED
@@ -137,9 +137,7 @@ class IndexedFormula extends _formula.default {
137
137
  /** Function to remove quads from the store arrays with */
138
138
  (0, _defineProperty2.default)(this, "rdfArrayRemove", void 0);
139
139
  /** Callbacks which are triggered after a statement has been added to the store */
140
- (0, _defineProperty2.default)(this, "dataCallbacks", []);
141
- /** Callbacks which are triggered after a statement has been removed from the store */
142
- (0, _defineProperty2.default)(this, "dataRemovalCallbacks", []);
140
+ (0, _defineProperty2.default)(this, "dataCallbacks", void 0);
143
141
  this.propertyActions = {};
144
142
  this.classActions = {};
145
143
  this.redirections = [];
@@ -161,9 +159,6 @@ class IndexedFormula extends _formula.default {
161
159
  if (opts.dataCallback) {
162
160
  this.dataCallbacks = [opts.dataCallback];
163
161
  }
164
- if (opts.dataRemovalCallback) {
165
- this.dataRemovalCallbacks = [opts.dataRemovalCallback];
166
- }
167
162
  this.initPropertyActions(this.features);
168
163
  }
169
164
 
@@ -192,11 +187,11 @@ class IndexedFormula extends _formula.default {
192
187
  * @param cb
193
188
  */
194
189
  addDataCallback(cb) {
190
+ if (!this.dataCallbacks) {
191
+ this.dataCallbacks = [];
192
+ }
195
193
  this.dataCallbacks.push(cb);
196
194
  }
197
- addDataRemovalCallback(cb) {
198
- this.dataRemovalCallbacks.push(cb);
199
- }
200
195
 
201
196
  /**
202
197
  * Apply a set of statements to be deleted and to be inserted
@@ -410,8 +405,10 @@ class IndexedFormula extends _formula.default {
410
405
 
411
406
  // log.debug("ADDING {"+subj+" "+pred+" "+objNode+"} "+why)
412
407
  this.statements.push(st);
413
- for (const callback of this.dataCallbacks) {
414
- callback(st);
408
+ if (this.dataCallbacks) {
409
+ for (const callback of this.dataCallbacks) {
410
+ callback(st);
411
+ }
415
412
  }
416
413
  return st;
417
414
  }
@@ -861,9 +858,6 @@ class IndexedFormula extends _formula.default {
861
858
  }
862
859
  }
863
860
  this.rdfArrayRemove(this.statements, st);
864
- for (const callback of this.dataRemovalCallbacks) {
865
- callback(st);
866
- }
867
861
  return this;
868
862
  }
869
863
 
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.37-d3a3ef5f",
4
+ "version": "2.2.37-dbccd446",
5
5
  "private": false,
6
6
  "browserslist": [
7
7
  "> 0.5%"
package/src/formula.ts CHANGED
@@ -33,7 +33,6 @@ import NamedNode from './named-node'
33
33
 
34
34
  export interface FormulaOpts {
35
35
  dataCallback?: (q: Quad) => void
36
- dataRemovalCallback?: (q: Quad) => void;
37
36
  rdfArrayRemove?: (arr: Quad[], q: Quad) => void
38
37
  rdfFactory?: RdfJsDataFactory
39
38
  }
@@ -1,4 +1,4 @@
1
- import { arrayToStatements } from './utils'
1
+ import {arrayToStatements} from './utils'
2
2
 
3
3
  /**
4
4
  * Parses json-ld formatted JS objects to a rdf Term.
@@ -6,7 +6,7 @@ import { arrayToStatements } from './utils'
6
6
  * @param obj - The json-ld object to process.
7
7
  * @return {Literal|NamedNode|BlankNode|Collection}
8
8
  */
9
- export function jsonldObjectToTerm (kb, obj) {
9
+ export function jsonldObjectToTerm(kb, obj) {
10
10
  if (typeof obj === 'string') {
11
11
  return kb.rdfFactory.literal(obj)
12
12
  }
@@ -41,7 +41,7 @@ export function jsonldObjectToTerm (kb, obj) {
41
41
  /**
42
42
  * Adds the statements in a json-ld list object to {kb}.
43
43
  */
44
- function listToStatements (kb, obj) {
44
+ function listToStatements(kb, obj) {
45
45
  const listId = obj['@id'] ? nodeType(kb, obj) : kb.rdfFactory.blankNode()
46
46
 
47
47
  const items = obj['@list'].map((listItem => jsonldObjectToTerm(kb, listItem)))
@@ -51,7 +51,7 @@ function listToStatements (kb, obj) {
51
51
  return listId
52
52
  }
53
53
 
54
- function listToCollection (kb, obj) {
54
+ function listToCollection(kb, obj) {
55
55
  if (!Array.isArray(obj)) {
56
56
  throw new TypeError("Object must be an array")
57
57
  }
@@ -63,13 +63,15 @@ function listToCollection (kb, obj) {
63
63
  *
64
64
  * Ensure that {kb.rdfFactory} is a DataFactory.
65
65
  */
66
- export default function jsonldParser (str, kb, base, callback) {
67
- const baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType')
68
- ? base.value
69
- : base
66
+ export default function jsonldParser(str, kb, base, callback) {
67
+ const baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base
70
68
 
71
69
  return import('jsonld')
72
- .then(jsonld => { return jsonld.flatten(JSON.parse(str), null, { base: baseString }) })
70
+ .then(jsonld => {
71
+ // ⚠ Unit tests also work without accessing `jsonld.default` explicitly, but real browser usage will fail with
72
+ // just calling `jsonld.flatten`, so please do not remove `default`
73
+ return jsonld.default.flatten(JSON.parse(str), null, {base: baseString})
74
+ })
73
75
  .then((flattened) => flattened.reduce((store, flatResource) => {
74
76
 
75
77
  kb = processResource(kb, base, flatResource)
@@ -80,7 +82,7 @@ export default function jsonldParser (str, kb, base, callback) {
80
82
  .catch(callback)
81
83
  }
82
84
 
83
- function nodeType (kb, obj) {
85
+ function nodeType(kb, obj) {
84
86
  if (obj['@id'].startsWith('_:')) {
85
87
  // This object is a Blank Node. Pass the id without the `_:` prefix
86
88
  return kb.rdfFactory.blankNode(obj['@id'].substring(2));
@@ -106,7 +108,7 @@ function processResource(kb, base, flatResource) {
106
108
  const nestedFlatResources = flatResource[property]
107
109
 
108
110
  // recursively process all flat resources in the array, but with the graphId as base.
109
- for (let i = 0; i < nestedFlatResources.length; i++ ) {
111
+ for (let i = 0; i < nestedFlatResources.length; i++) {
110
112
  kb = processResource(kb, graphId, nestedFlatResources[i])
111
113
  }
112
114
  }
package/src/store.ts CHANGED
@@ -168,9 +168,7 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
168
168
  /** Function to remove quads from the store arrays with */
169
169
  private rdfArrayRemove: (arr: Quad[], q: Quad) => void
170
170
  /** Callbacks which are triggered after a statement has been added to the store */
171
- private dataCallbacks: Array<(q: Quad) => void> = []
172
- /** Callbacks which are triggered after a statement has been removed from the store */
173
- private dataRemovalCallbacks: Array<(q: Quad) => void> = []
171
+ private dataCallbacks?: Array<(q: Quad) => void>
174
172
 
175
173
  /**
176
174
  * Creates a new formula
@@ -210,9 +208,6 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
210
208
  if (opts.dataCallback) {
211
209
  this.dataCallbacks = [opts.dataCallback]
212
210
  }
213
- if (opts.dataRemovalCallback) {
214
- this.dataRemovalCallbacks = [opts.dataRemovalCallback]
215
- }
216
211
 
217
212
  this.initPropertyActions(this.features)
218
213
  }
@@ -242,13 +237,12 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
242
237
  * @param cb
243
238
  */
244
239
  addDataCallback(cb: (q: Quad) => void): void {
240
+ if (!this.dataCallbacks) {
241
+ this.dataCallbacks = []
242
+ }
245
243
  this.dataCallbacks.push(cb)
246
244
  }
247
245
 
248
- addDataRemovalCallback(cb: (q: Quad) => void): void {
249
- this.dataRemovalCallbacks.push(cb)
250
- }
251
-
252
246
  /**
253
247
  * Apply a set of statements to be deleted and to be inserted
254
248
  *
@@ -492,8 +486,10 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
492
486
  // log.debug("ADDING {"+subj+" "+pred+" "+objNode+"} "+why)
493
487
  this.statements.push(st)
494
488
 
495
- for (const callback of this.dataCallbacks) {
496
- callback(st)
489
+ if (this.dataCallbacks) {
490
+ for (const callback of this.dataCallbacks) {
491
+ callback(st)
492
+ }
497
493
  }
498
494
 
499
495
  return st
@@ -991,9 +987,6 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
991
987
  }
992
988
  }
993
989
  this.rdfArrayRemove(this.statements, st)
994
- for (const callback of this.dataRemovalCallbacks) {
995
- callback(st)
996
- }
997
990
  return this
998
991
  }
999
992