Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce "node.addr" (deprecates "uniqueId") #314

Merged
merged 3 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change "Default" to case sensitive
  • Loading branch information
Elad Ben-Israel committed Oct 25, 2020
commit d98c34cef1b50fe2e8b1b88d0b4c2e91e0269043
6 changes: 3 additions & 3 deletions src/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export class Node {
* Addresses are calculated using a SHA-1 of the components of the construct
* path.
*
* To enable refactorings of construct trees, constructs with the ID `default`
* (case insensitive) will be excluded from the calculation. In those cases
* constructs in the same tree may have the same addreess.
* To enable refactorings of construct trees, constructs with the ID `Default`
* will be excluded from the calculation. In those cases constructs in the
* same tree may have the same addreess.
*
* @example c83a2846e506bcc5f10682b564084bca2d275709ee
*/
Expand Down
8 changes: 3 additions & 5 deletions src/private/uniqueid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ const MAX_ID_LEN = 255;
/**
* Calculates the construct uid based on path components.
*
* Components named `Default` (case insensitive) are excluded from uid calculation
* Components named `Default` (case sensitive) are excluded from uid calculation
* to allow tree refactorings.
*
* @param components path components
*/
export function addressOf(components: string[]) {
const hash = crypto.createHash('sha1');
for (const c of components) {
// skip "default".
if (c.toLocaleLowerCase() === HIDDEN_ID.toLocaleLowerCase()) {
continue;
}
// skip components called "Default" to enable refactorings
if (c === HIDDEN_ID) { continue; }

hash.update(c);
hash.update('\n');
Expand Down
8 changes: 4 additions & 4 deletions test/construct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,20 @@ test('node.addr excludes "default" from the address calculation', () => {
const c1 = new Construct(root, 'c1');

// WHEN:
const group1 = new Construct(root, 'default');
const group1 = new Construct(root, 'Default'); // <-- this is a "hidden node"
const c1a = new Construct(group1, 'c1');
const group2 = new Construct(root, 'DeFAULt');
const group2 = new Construct(root, 'DeFAULt'); // <-- not hidden, "Default" is case sensitive
const c1b = new Construct(group2, 'c1');


// THEN: all addresses are the same because they go through "default"
const addr = Node.of(c1).addr;
const addrA = Node.of(c1a).addr;
const addrB = Node.of(c1b).addr;

expect(addr).toEqual('c86a34031367d11f4bef80afca42b7e7e5c6253b77');
expect(addrA).toEqual(addr);
expect(addrB).toEqual(addr);
expect(addrB).toEqual('c8fa72abd28f794f6bacb100b26beb761d004572f5');
expect(addrB).not.toEqual(addr);
});

test('construct.getChildren() returns an array of all children', () => {
Expand Down