Skip to content

Commit

Permalink
Add support for guid field. Closes #24 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb authored Apr 4, 2022
1 parent a853f7f commit 008cec0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/common/JSONImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
31 changes: 31 additions & 0 deletions test/common/JSONImporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 008cec0

Please sign in to comment.