Repository navigation
Conversation
Changelog: - Add quoteLossyIntegers / parseJSONSafeIds scanner (no new dependencies) - REST: keepIdsAsString + customParseJSONFn via axios text + transformResponse - WebSocket: same options in resolveEmittableEvents JSON.parse path - Unit tests for scanner edge cases; benchmark script for 1000-level order book Addresses sieblyio#101 (PoC on JJ-Cro fork). Co-authored-by: Jerko J <JJ-Cro@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Proof of concept for sieblyio/gateio-api#101: Gate order IDs above
Number.MAX_SAFE_INTEGERlose precision when responses are parsed withJSON.parse. This adds an opt-in, dependency-free text scanner and wires it into REST (axios) and WebSocket message parsing.Changelog (1.7.0)
src/lib/jsonParse.ts:quoteLossyIntegers(text)walks JSON text (respecting strings/escapes) and wraps only integer literals whose magnitude exceedsNumber.MAX_SAFE_INTEGERin quotes.parseJSONSafeIds(text)=JSON.parse(quoteLossyIntegers(text)).BaseRestClient): optionalkeepIdsAsStringandcustomParseJSONFnonRestClientOptions(default off). When enabled, usesresponseType: 'text'and atransformResponsethat parses with the scanner or custom fn.WebsocketClient.resolveEmittableEvents): same options onWSClientConfigurableOptionsfor the singleJSON.parsepath.test/lib/jsonParse.test.tscovers root/nested/array ids, negatives, strings (including escapes), decimals/exponents, safe ints, and parity withJSON.parsewhen no lossy ints.scripts/benchmark-json-parse.ts(run afternpm run build).Benchmark (1000 bid + 1000 ask levels, 200 iterations)
JSON.parseparseJSONSafeIdsRatio: ~3.73× slower than plain
JSON.parseon this payload (expected: extra scan pass before parse).npm run build && node --experimental-strip-types scripts/benchmark-json-parse.tsUsage
Response typings are unchanged; with the flag off, behaviour is identical to before.
CI / local checks
npm run lint— passnpm run build— passnpm test— 11/11 newjsonParsetests pass; 23/30 total pass (7 existingtest/REST/private.test.tsfailures: missing API keys in this environment, unchanged by this PR)Notes
CHANGELOG.mdnot edited (per fork workflow); release notes above.