Skip to content

Commit

Permalink
fix(core): Serialize dates and regexps when reading from augmented ob…
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored Apr 26, 2023
1 parent 390841b commit a4eb46a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/workflow/src/AugmentObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export function augmentObject<T extends object>(data: T): T {

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const value = Reflect.get(target, key, receiver);

if (typeof value !== 'object' || value === null) return value;
if (value instanceof RegExp) return value.toString();
if ('toJSON' in value && typeof value.toJSON === 'function') return value.toJSON() as T;

const newValue = augment(value);
if (newValue !== value) {
Object.assign(newData, { [key]: newValue });
Expand Down
4 changes: 2 additions & 2 deletions packages/workflow/test/AugmentObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ describe('AugmentObject', () => {
a: 9111,
b: '9222',
c: 3,
d: date,
r: regexp,
d: date.toJSON(),
r: regexp.toString(),
});
});

Expand Down

0 comments on commit a4eb46a

Please sign in to comment.