XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

chore: use json-with-bigint for JSON.stringify hook (#1312)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1312

e65393f4
Sainan <sainan@calamity.inc>
提交于

代码差异

3 个文件 +10 -23
Modified package-lock.json +4 -4
@@ -14,7 +14,7 @@
14 14 "copyfiles": "^2.4.1",
15 15 "crc-32": "^1.2.2",
16 16 "express": "^5",
17 "json-with-bigint": "^3.2.1",
17 "json-with-bigint": "^3.2.2",
18 18 "mongoose": "^8.11.0",
19 19 "morgan": "^1.10.0",
20 20 "typescript": ">=5.5 <5.6.0",
@@ -2348,9 +2348,9 @@
2348 2348 "license": "MIT"
2349 2349 },
2350 2350 "node_modules/json-with-bigint": {
2351 "version": "3.2.1",
2352 "resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.2.1.tgz",
2353 "integrity": "sha512-0f8RHpU1AwBFwIPmtm71W+cFxzlXdiBmzc3JqydsNDSKSAsr0Lso6KXRbz0h2LRwTIRiHAk/UaD+xaAN5f577w==",
2351 "version": "3.2.2",
2352 "resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.2.2.tgz",
2353 "integrity": "sha512-zbaZ+MZ2PEcAD0yINpxvlLMKzoC1GPqy5p8/ZgzRJRoB+NCczGrTX9x2ashSvkfYTitQKbV5aYQCJCiHxrzF2w==",
2354 2354 "license": "MIT"
2355 2355 },
2356 2356 "node_modules/json5": {
Modified package.json +1 -1
@@ -19,7 +19,7 @@
19 19 "copyfiles": "^2.4.1",
20 20 "crc-32": "^1.2.2",
21 21 "express": "^5",
22 "json-with-bigint": "^3.2.1",
22 "json-with-bigint": "^3.2.2",
23 23 "mongoose": "^8.11.0",
24 24 "morgan": "^1.10.0",
25 25 "typescript": ">=5.5 <5.6.0",
Modified src/index.ts +5 -18
@@ -9,25 +9,12 @@ import { app } from "./app";
9 9 import { config, validateConfig } from "./services/configService";
10 10 import { registerLogFileCreationListener } from "@/src/utils/logger";
11 11 import mongoose from "mongoose";
12 import { Json, JSONStringify } from "json-with-bigint";
12 13
13 // Patch JSON.stringify to work flawlessly with Bigints. Yeah, it's not pretty.
14 // TODO: Might wanna use json-with-bigint if/when possible.
15 {
16 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
17 (BigInt.prototype as any).toJSON = function (): string {
18 // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
19 return "<BIGINT>" + this.toString() + "</BIGINT>";
20 };
21 const og_stringify = JSON.stringify;
22 // eslint-disable-next-line @typescript-eslint/no-explicit-any
23 JSON.stringify = (obj: any, replacer?: any, space?: string | number): string => {
24 return og_stringify(obj, replacer as string[], space)
25 .split(`"<BIGINT>`)
26 .join(``)
27 .split(`</BIGINT>"`)
28 .join(``);
29 };
30 }
14 // Patch JSON.stringify to work flawlessly with Bigints.
15 JSON.stringify = (obj: Exclude<Json, undefined>, _replacer?: unknown, space?: string | number): string => {
16 return JSONStringify(obj, space);
17 };
31 18
32 19 registerLogFileCreationListener();
33 20 validateConfig();