grafio-mongo 3.12.0 → 3.13.1

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.
@@ -321,6 +321,10 @@ class MongoStorageProvider {
321
321
  };
322
322
  }
323
323
  async importJSON(data) {
324
+ const existingNode = await this._nodes.findOne({ graphId: this._graphId });
325
+ if (existingNode) {
326
+ throw new errors_1.GraphError(`Graph with graphId '${this._graphId}' is not empty. Clear it first before importing.`);
327
+ }
324
328
  const nodeIdSet = new Set();
325
329
  for (const n of data.nodes) {
326
330
  if (nodeIdSet.has(n.id))
@@ -333,37 +337,6 @@ class MongoStorageProvider {
333
337
  throw new errors_1.EdgeAlreadyExistsError(e.id);
334
338
  edgeIdSet.add(e.id);
335
339
  }
336
- const nodeIds = data.nodes.map(n => n.id);
337
- const edgeIds = data.edges.map(e => e.id);
338
- const [conflictNode, conflictEdge] = await Promise.all([
339
- data.nodes.length > 0
340
- ? this._nodes.findOne({ graphId: this._graphId, id: { $in: nodeIds } })
341
- : Promise.resolve(null),
342
- data.edges.length > 0
343
- ? this._edges.findOne({ graphId: this._graphId, id: { $in: edgeIds } })
344
- : Promise.resolve(null),
345
- ]);
346
- if (conflictNode)
347
- throw new errors_1.NodeAlreadyExistsError(conflictNode.id);
348
- if (conflictEdge)
349
- throw new errors_1.EdgeAlreadyExistsError(conflictEdge.id);
350
- const referencedIds = [...nodeIdSet];
351
- for (const e of data.edges) {
352
- referencedIds.push(e.sourceId, e.targetId);
353
- }
354
- const uniqueReferencedIds = [...new Set(referencedIds)];
355
- const existingIdSet = new Set(await this._nodes
356
- .find({ graphId: this._graphId, id: { $in: uniqueReferencedIds } }, { projection: { id: 1 } })
357
- .toArray()
358
- .then(docs => docs.map(d => d.id)));
359
- for (const id of nodeIdSet)
360
- existingIdSet.add(id);
361
- for (const e of data.edges) {
362
- if (!existingIdSet.has(e.sourceId))
363
- throw new errors_1.NodeNotFoundError(e.sourceId);
364
- if (!existingIdSet.has(e.targetId))
365
- throw new errors_1.NodeNotFoundError(e.targetId);
366
- }
367
340
  if (data.nodes.length > 0) {
368
341
  const nodeDocs = data.nodes.map(n => ({
369
342
  id: n.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grafio-mongo",
3
- "version": "3.12.0",
3
+ "version": "3.13.1",
4
4
  "description": "MongoDB storage backend for grafio",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "peerDependencies": {},
18
18
  "dependencies": {
19
- "grafio": ">=7.12.0",
19
+ "grafio": ">=7.13.0",
20
20
  "mongodb": ">=5.0.0"
21
21
  },
22
22
  "devDependencies": {