Skip to content

Commit

Permalink
fix(core): Serialize BigInts (n8n-io#6805)
Browse files Browse the repository at this point in the history
* workaround for non-serializable BigInt

* refactor
  • Loading branch information
flipswitchingmonkey authored Jul 31, 2023
1 parent 651cf34 commit 7b27fa5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/workflow/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ declare module '@n8n_io/riot-tmpl' {
let brackets: Brackets;
let tmpl: Tmpl;
}

interface BigInt {
toJSON(): string;
}
6 changes: 6 additions & 0 deletions packages/workflow/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import type { BinaryFileType, JsonObject } from './Interfaces';

const readStreamClasses = new Set(['ReadStream', 'Readable', 'ReadableStream']);

// NOTE: BigInt.prototype.toJSON is not available, which causes JSON.stringify to throw an error
// as well as the flatted stringify method. This is a workaround for that.
BigInt.prototype.toJSON = function () {
return this.toString();
};

export const isObjectEmpty = (obj: object | null | undefined): boolean => {
if (obj === undefined || obj === null) return true;
if (typeof obj === 'object') {
Expand Down

0 comments on commit 7b27fa5

Please sign in to comment.