Skip to content

Commit ba5a588

Browse files
committed
refactor: replace JSON.stringify with lossless-json.stringify for BigInt handling
1 parent 48e49eb commit ba5a588

4 files changed

Lines changed: 6 additions & 11 deletions

File tree

src/extraction/getTypeFromValue.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ts from "typescript";
22
import {createCompilerHost, getSharedTypeDeclarations} from "../utils";
33
import {DataType, LiteralValue} from "@code0-tech/sagittarius-graphql-types";
4+
import {stringify} from "lossless-json";
45

56
/**
67
* Uses the TypeScript compiler to generate a precise type string from any runtime value.
@@ -12,9 +13,7 @@ export const getTypeFromValue = (
1213

1314

1415
// 1. Serialize value to a JSON string for embedding in source code.
15-
const literal = JSON.stringify(value?.value, (key, val) =>
16-
typeof val === 'bigint' ? val.toString() : val
17-
)
16+
const literal = stringify(value?.value)
1817

1918
if (!literal) return "any"
2019

src/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ts from "typescript";
1212
import {createSystem, createVirtualTypeScriptEnvironment, VirtualTypeScriptEnvironment} from "@typescript/vfs"
1313
import {DataTypeVariant, getTypeVariant} from "./extraction/getTypeVariant";
1414
import {getTypesFromFunction} from "./extraction/getTypesFromFunction";
15+
import {stringify} from "lossless-json";
1516

1617
/**
1718
* Result of a node or flow validation.
@@ -126,9 +127,7 @@ export function generateFlowSourceCode(
126127
return `/* @pos ${nodeId} ${paramIdx} */ ${refCode}`;
127128
}
128129
if (val.__typename === "LiteralValue") {
129-
const jsonString = JSON.stringify(val?.value, (key, val) =>
130-
typeof val === 'bigint' ? val.toString() : val
131-
)
130+
const jsonString = stringify(val?.value)
132131
return `/* @pos ${nodeId} ${paramIdx} */ ${jsonString}`;
133132
}
134133
if (val.__typename === "NodeFunctionIdWrapper") {

src/validation/getValueValidation.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ts from "typescript";
22
import {DataType, LiteralValue} from "@code0-tech/sagittarius-graphql-types";
33
import {createCompilerHost, getSharedTypeDeclarations, ValidationResult} from "../utils";
4+
import { stringify } from 'lossless-json'
45

56

67
export const getValueValidation = (
@@ -9,9 +10,7 @@ export const getValueValidation = (
910
dataTypes?: DataType[]
1011
): ValidationResult => {
1112

12-
const jsonString = JSON.stringify(value?.value, (key, val) =>
13-
typeof val === 'bigint' ? val.toString() : val
14-
)
13+
const jsonString = stringify(value?.value)
1514

1615
// 1. Construct the source code for validation.
1716
const sourceCode = `

test/getReferenceSuggestions.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ describe('getReferenceSuggestions', () => {
125125

126126
const suggestions = getReferenceSuggestions(flow, "gid://sagittarius/NodeFunction/4", 0, FUNCTION_SIGNATURES, DATA_TYPES);
127127

128-
console.log(suggestions)
129-
130128
//expect(suggestions.some(s => !s.nodeFunctionId)).toBe(true);
131129
});
132130

0 commit comments

Comments
 (0)