Compare commits

...

1 Commits

Author SHA1 Message Date
2f9022a058 chore: use json-with-bigint for JSON.stringify hook 2025-03-24 09:26:15 +01:00
3 changed files with 10 additions and 23 deletions

8
package-lock.json generated
View File

@ -14,7 +14,7 @@
"copyfiles": "^2.4.1", "copyfiles": "^2.4.1",
"crc-32": "^1.2.2", "crc-32": "^1.2.2",
"express": "^5", "express": "^5",
"json-with-bigint": "^3.2.1", "json-with-bigint": "^3.2.2",
"mongoose": "^8.11.0", "mongoose": "^8.11.0",
"morgan": "^1.10.0", "morgan": "^1.10.0",
"typescript": ">=5.5 <5.6.0", "typescript": ">=5.5 <5.6.0",
@ -2348,9 +2348,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/json-with-bigint": { "node_modules/json-with-bigint": {
"version": "3.2.1", "version": "3.2.2",
"resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.2.1.tgz", "resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.2.2.tgz",
"integrity": "sha512-0f8RHpU1AwBFwIPmtm71W+cFxzlXdiBmzc3JqydsNDSKSAsr0Lso6KXRbz0h2LRwTIRiHAk/UaD+xaAN5f577w==", "integrity": "sha512-zbaZ+MZ2PEcAD0yINpxvlLMKzoC1GPqy5p8/ZgzRJRoB+NCczGrTX9x2ashSvkfYTitQKbV5aYQCJCiHxrzF2w==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/json5": { "node_modules/json5": {

View File

@ -19,7 +19,7 @@
"copyfiles": "^2.4.1", "copyfiles": "^2.4.1",
"crc-32": "^1.2.2", "crc-32": "^1.2.2",
"express": "^5", "express": "^5",
"json-with-bigint": "^3.2.1", "json-with-bigint": "^3.2.2",
"mongoose": "^8.11.0", "mongoose": "^8.11.0",
"morgan": "^1.10.0", "morgan": "^1.10.0",
"typescript": ">=5.5 <5.6.0", "typescript": ">=5.5 <5.6.0",

View File

@ -9,25 +9,12 @@ import { app } from "./app";
import { config, validateConfig } from "./services/configService"; import { config, validateConfig } from "./services/configService";
import { registerLogFileCreationListener } from "@/src/utils/logger"; import { registerLogFileCreationListener } from "@/src/utils/logger";
import mongoose from "mongoose"; import mongoose from "mongoose";
import { Json, JSONStringify } from "json-with-bigint";
// Patch JSON.stringify to work flawlessly with Bigints. Yeah, it's not pretty. // Patch JSON.stringify to work flawlessly with Bigints.
// TODO: Might wanna use json-with-bigint if/when possible. JSON.stringify = (obj: Exclude<Json, undefined>, _replacer?: unknown, space?: string | number): string => {
{ return JSONStringify(obj, space);
// 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(``);
};
}
registerLogFileCreationListener(); registerLogFileCreationListener();
validateConfig(); validateConfig();