chore: use json-with-bigint for JSON.stringify hook (#1312)
Reviewed-on: OpenWF/SpaceNinjaServer#1312
This commit is contained in:
parent
3e2e73f6eb
commit
e65393f433
8
package-lock.json
generated
8
package-lock.json
generated
@ -14,7 +14,7 @@
|
||||
"copyfiles": "^2.4.1",
|
||||
"crc-32": "^1.2.2",
|
||||
"express": "^5",
|
||||
"json-with-bigint": "^3.2.1",
|
||||
"json-with-bigint": "^3.2.2",
|
||||
"mongoose": "^8.11.0",
|
||||
"morgan": "^1.10.0",
|
||||
"typescript": ">=5.5 <5.6.0",
|
||||
@ -2348,9 +2348,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/json-with-bigint": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.2.1.tgz",
|
||||
"integrity": "sha512-0f8RHpU1AwBFwIPmtm71W+cFxzlXdiBmzc3JqydsNDSKSAsr0Lso6KXRbz0h2LRwTIRiHAk/UaD+xaAN5f577w==",
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.2.2.tgz",
|
||||
"integrity": "sha512-zbaZ+MZ2PEcAD0yINpxvlLMKzoC1GPqy5p8/ZgzRJRoB+NCczGrTX9x2ashSvkfYTitQKbV5aYQCJCiHxrzF2w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/json5": {
|
||||
|
@ -19,7 +19,7 @@
|
||||
"copyfiles": "^2.4.1",
|
||||
"crc-32": "^1.2.2",
|
||||
"express": "^5",
|
||||
"json-with-bigint": "^3.2.1",
|
||||
"json-with-bigint": "^3.2.2",
|
||||
"mongoose": "^8.11.0",
|
||||
"morgan": "^1.10.0",
|
||||
"typescript": ">=5.5 <5.6.0",
|
||||
|
23
src/index.ts
23
src/index.ts
@ -9,25 +9,12 @@ import { app } from "./app";
|
||||
import { config, validateConfig } from "./services/configService";
|
||||
import { registerLogFileCreationListener } from "@/src/utils/logger";
|
||||
import mongoose from "mongoose";
|
||||
import { Json, JSONStringify } from "json-with-bigint";
|
||||
|
||||
// Patch JSON.stringify to work flawlessly with Bigints. Yeah, it's not pretty.
|
||||
// TODO: Might wanna use json-with-bigint if/when possible.
|
||||
{
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
||||
(BigInt.prototype as any).toJSON = function (): string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
||||
return "<BIGINT>" + this.toString() + "</BIGINT>";
|
||||
};
|
||||
const og_stringify = JSON.stringify;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
JSON.stringify = (obj: any, replacer?: any, space?: string | number): string => {
|
||||
return og_stringify(obj, replacer as string[], space)
|
||||
.split(`"<BIGINT>`)
|
||||
.join(``)
|
||||
.split(`</BIGINT>"`)
|
||||
.join(``);
|
||||
};
|
||||
}
|
||||
// Patch JSON.stringify to work flawlessly with Bigints.
|
||||
JSON.stringify = (obj: Exclude<Json, undefined>, _replacer?: unknown, space?: string | number): string => {
|
||||
return JSONStringify(obj, space);
|
||||
};
|
||||
|
||||
registerLogFileCreationListener();
|
||||
validateConfig();
|
||||
|
Loading…
x
Reference in New Issue
Block a user