Skip to content

Commit

Permalink
Merge pull request #189 from lucassmuller/fix/json-stringify
Browse files Browse the repository at this point in the history
fix: add safe stringify to format winston events
  • Loading branch information
dasfmi authored Jun 4, 2024
2 parents 70c8467 + eb8b50d commit 7c33f77
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ export class Axiom extends BaseClient {
};
}

declare global {
interface BigInt {
toJSON: () => string;
}
}

BigInt.prototype.toJSON = function () {
return this.toString();
};

export enum ContentType {
JSON = 'application/json',
NDJSON = 'application/x-ndjson',
Expand Down
22 changes: 22 additions & 0 deletions packages/js/test/unit/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,28 @@ describe('Axiom', () => {
expect(response.failed).toEqual(0);
});

it('IngestBigInt', async () => {
const query = [{ foo: 1n }, { bar: 2n }];

const ingestStatus = {
ingested: 2,
failed: 0,
failures: [],
processedBytes: 630,
blocksCreated: 0,
walLength: 2,
};
testMockedFetchCall((_: string, init: RequestInit) => {
expect(init.headers).toHaveProperty('Content-Type');
expect(init.body).toMatch(JSON.stringify(query));
}, ingestStatus);

const response = await axiom.ingestRaw('test', JSON.stringify(query), ContentType.JSON, ContentEncoding.Identity);
expect(response).toBeDefined();
expect(response.ingested).toEqual(2);
expect(response.failed).toEqual(0);
});

it('does not throw exception on ingest (50x failure)', async () => {
let client = new AxiomWithoutBatching({ url: clientURL, token: 'test' })
mockFetchResponseErr();
Expand Down

0 comments on commit 7c33f77

Please sign in to comment.