Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete the Naive JSON codec #214

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading