Skip to content

Commit 237913f

Browse files
committed
fix(util): add Set serialization support
1 parent 81b6d67 commit 237913f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: packages/util/src/serializableObject.ts

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ export const toSerializableObject = (obj: unknown, options: ToSerializableObject
5353
value: obj.getTime()
5454
};
5555
}
56+
if (obj instanceof Set) {
57+
return {
58+
[transformationTypeKey]: 'Set',
59+
value: [...obj].map((item) => toSerializableObject(item, options))
60+
};
61+
}
5662
if (obj instanceof Map) {
5763
return {
5864
[transformationTypeKey]: 'Map',
@@ -101,6 +107,8 @@ const fromSerializableObjectUnknown = (obj: unknown, options: FromSerializableOb
101107
return Buffer.from(docAsAny.value, 'hex');
102108
case 'Date':
103109
return new Date(docAsAny.value);
110+
case 'Set':
111+
return new Set(docAsAny.value);
104112
case 'Map':
105113
return new Map(
106114
docAsAny.value.map((keyValues: unknown[]) =>

Diff for: packages/util/test/serializableObject.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('serializableObject', () => {
3636
date: new Date(),
3737
error: new Error('error obj'),
3838
map: new Map([['key', 'value']]),
39+
set: new Set(['item1', 'item2']),
3940
undefined
4041
};
4142
expect(serializeAndDeserialize(obj)).toEqual(obj);

0 commit comments

Comments
 (0)