Skip to content

Commit e7acbc8

Browse files
authored
Pass through UUIDs that are already stringy (#282)
1 parent 176fe3b commit e7acbc8

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

api/stately/stately-utils.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,9 @@ describe('fromStatelyUUID', () => {
160160
it('converts a Stately UUID to a string', () => {
161161
expect(fromStatelyUUID('_XBlcIuJTLCITKFKCQEJPQ')).toBe('fd706570-8b89-4cb0-884c-a14a0901093d');
162162
});
163+
it('passes through a string UUID', () => {
164+
expect(fromStatelyUUID('fd706570-8b89-4cb0-884c-a14a0901093d')).toBe(
165+
'fd706570-8b89-4cb0-884c-a14a0901093d',
166+
);
167+
});
163168
});

api/stately/stately-utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,12 @@ export function parseKeyPath(keyPath: string): { ns: string; id: string }[] {
158158
});
159159
}
160160

161+
/** Convert a UUID from a Stately key path into a string-form UUID. */
161162
export function fromStatelyUUID(id: string): string {
163+
if (id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)) {
164+
// It's already in that format
165+
return id;
166+
}
162167
const bytes = Buffer.from(id, 'base64');
163168
return stringifyUUID(new Uint8Array(bytes));
164169
}

0 commit comments

Comments
 (0)