diff --git a/src/common/JSONImporter.js b/src/common/JSONImporter.js index d0b540a..983370a 100644 --- a/src/common/JSONImporter.js +++ b/src/common/JSONImporter.js @@ -30,6 +30,7 @@ define([ const json = { id: this.core.getGuid(node), path: this.core.getPath(node), + guid: this.core.getGuid(node), attributes: {}, attribute_meta: {}, pointers: {}, @@ -145,7 +146,7 @@ define([ 'member_attributes', 'member_registry', ]; - const singleKeyFields = ['children_meta']; + const singleKeyFields = ['children_meta', 'guid']; const sortedChanges = changes .filter( change => change.key.length > 1 || @@ -292,6 +293,10 @@ define([ parent, relid: state.path?.split('/').pop() }); + + if (state.guid) { + params.guid = state.guid; + } const node = this.core.createNode(params); await selector.prepare(this.core, this.rootNode, node); return node; @@ -324,6 +329,11 @@ define([ } } + Importer.prototype._put.guid = async function(node, change, resolvedSelectors) { + const {value} = change; + this.core.setGuid(node, value); + }; + Importer.prototype._put.mixins = async function(node, change, resolvedSelectors) { const [, index] = change.key; const oldMixinPath = this.core.getMixinPaths(node)[index]; diff --git a/test/common/JSONImporter.spec.js b/test/common/JSONImporter.spec.js index ddf21c6..858830e 100644 --- a/test/common/JSONImporter.spec.js +++ b/test/common/JSONImporter.spec.js @@ -853,6 +853,37 @@ describe('JSONImporter', function () { }); }); + describe('guid', function() { + it('should set guid for new nodes', async function() { + const fco = await core.loadByPath(root, '/1'); + const guid = '0d2e0ef3-5b8f-9bc4-45a0-8abab4433565'; + const container = { + guid, + }; + const containerNode = await importer.import(root, container); + assert.equal( + core.getGuid(containerNode), + guid, + 'Did not set guid on creation' + ); + }); + + it('should change guid for existing nodes', async function() { + const fco = await core.loadByPath(root, '/1'); + const node = core.createNode({base: fco, parent: root}); + const guid = '0d2e0ef3-5b8f-9bc4-45a0-8abab4433565'; + const nodeJson = { + guid, + }; + await importer.apply(node, nodeJson); + assert.equal( + core.getGuid(node), + guid, + 'Did not change guid' + ); + }); + }); + describe('findNode', function() { it('should find nodes using @meta', async function() { const fco = await importer.findNode(node, '@meta:FCO');