Skip to content

Commit

Permalink
Delete the Naive JSON codec
Browse files Browse the repository at this point in the history
We don't use this and it's only making our test harness slower.

This change drops the `NaiveJsonCodec`, which is slower and more
verbose.
  • Loading branch information
lhchavez committed Jun 18, 2024
1 parent 9cbf62f commit efac112
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 89 deletions.
9 changes: 3 additions & 6 deletions __tests__/fixtures/codec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { BinaryCodec, Codec, NaiveJsonCodec } from '../../codec';
import { BinaryCodec, Codec } from '../../codec';

export type ValidCodecs = 'naive' | 'binary';
export type ValidCodecs = 'binary';
export const codecs: Array<{
name: ValidCodecs;
codec: Codec;
}> = [
{ name: 'naive', codec: NaiveJsonCodec },
{ name: 'binary', codec: BinaryCodec },
];
}> = [{ name: 'binary', codec: BinaryCodec }];
15 changes: 6 additions & 9 deletions __tests__/fixtures/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@ type Selector = [ValidTransports, ValidCodecs];
* @returns An array of TestMatrixEntry objects representing the combinations of transport and codec.
*/
export const testMatrix = (selector?: Selector): Array<TestMatrixEntry> =>
transports
// If a selector is provided, filter transports to match the selector
(selector
? transports.filter((transport) => selector[0] === transport.name)
: transports
)
.map((transport) =>
// If a selector is provided, filter transport + codecs to match the selector; otherwise, use all codecs.
(selector
? codecs.filter(
(codec) =>
selector[0] === transport.name && selector[1] === codec.name,
)
: codecs
).map((codec) => ({
codecs.map((codec) => ({
transport,
codec,
})),
Expand Down
8 changes: 4 additions & 4 deletions __tests__/negative.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
handshakeRequestMessage,
} from '../transport/message';
import { nanoid } from 'nanoid';
import { NaiveJsonCodec } from '../codec';
import { BinaryCodec } from '../codec';
import { Static } from '@sinclair/typebox';
import { WebSocketClientTransport } from '../transport/impls/ws/client';
import { ProtocolError } from '../transport/events';
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('should handle incompatabilities', async () => {
},
sessionId: 'sessionId',
});
ws.send(NaiveJsonCodec.toBuffer(requestMsg));
ws.send(BinaryCodec.toBuffer(requestMsg));

// wait for both sides to be happy
await waitFor(() => expect(spy).toHaveBeenCalledTimes(1));
Expand All @@ -220,7 +220,7 @@ describe('should handle incompatabilities', async () => {
streamId: 'streamid',
payload: {},
};
ws.send(NaiveJsonCodec.toBuffer(msg));
ws.send(BinaryCodec.toBuffer(msg));

await waitFor(() => expect(errMock).toHaveBeenCalledTimes(1));
expect(errMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -265,7 +265,7 @@ describe('should handle incompatabilities', async () => {
sessionId: 'sessionId',
} satisfies Static<typeof ControlMessageHandshakeRequestSchema>,
};
ws.send(NaiveJsonCodec.toBuffer(requestMsg));
ws.send(BinaryCodec.toBuffer(requestMsg));

// should never connect
// ws should be closed
Expand Down
1 change: 0 additions & 1 deletion codec/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { BinaryCodec } from './binary';
export { NaiveJsonCodec } from './json';
export type { Codec } from './types';
67 changes: 0 additions & 67 deletions codec/json.ts

This file was deleted.

4 changes: 2 additions & 2 deletions transport/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NaiveJsonCodec } from '../codec/json';
import { BinaryCodec } from '../codec/binary';
import { ConnectionRetryOptions } from './rateLimit';
import { SessionOptions } from './session';

Expand All @@ -10,7 +10,7 @@ export const defaultTransportOptions: TransportOptions = {
heartbeatIntervalMs: 1_000,
heartbeatsUntilDead: 2,
sessionDisconnectGraceMs: 5_000,
codec: NaiveJsonCodec,
codec: BinaryCodec,
};

export type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
Expand Down

0 comments on commit efac112

Please sign in to comment.