Skip to content

Commit e2d1e84

Browse files
committed
feat: ➕ use superjson instead of built-in json
1 parent c6ec7af commit e2d1e84

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"build": "rimraf dist && rimraf adapter && rimraf link && rimraf types && tsc -p tsconfig.build.json && shx mv dist/* . && rimraf dist"
1919
},
2020
"peerDependencies": {
21-
"@trpc/client": "10.0.0-proxy-beta.18",
22-
"@trpc/server": "10.0.0-proxy-beta.18"
21+
"@trpc/client": "^10.0.0-proxy-beta.18",
22+
"@trpc/server": "^10.0.0-proxy-beta.18"
2323
},
2424
"devDependencies": {
2525
"@trivago/prettier-plugin-sort-imports": "^3.3.0",

src/adapter/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import type { OnErrorFunction } from '@trpc/server/dist/internals/types';
99
import * as amqp from 'amqp-connection-manager';
1010
import type { ConsumeMessage } from 'amqplib';
11+
import { parse, stringify } from 'superjson';
1112

1213
import { getErrorFromUnknown } from './errors';
1314

@@ -41,7 +42,7 @@ export const createRMQHandler = <TRouter extends AnyRouter>(
4142
if (!correlationId || !replyTo) return;
4243
const res = await handleMessage(router, msg, onError);
4344
if (!res) return;
44-
void channel.sendToQueue(replyTo as string, Buffer.from(JSON.stringify({ trpc: res })), {
45+
void channel.sendToQueue(replyTo as string, Buffer.from(stringify({ trpc: res })), {
4546
correlationId: correlationId as string
4647
});
4748
});
@@ -59,7 +60,7 @@ async function handleMessage<TRouter extends AnyRouter>(
5960
const { transformer } = router._def._config;
6061

6162
try {
62-
const message = JSON.parse(msg.content.toString('utf-8'));
63+
const message: any = parse(msg.content.toString('utf-8'));
6364
if (!('trpc' in message)) return;
6465
const { trpc } = message;
6566
if (!('id' in trpc) || trpc.id === null || trpc.id === undefined) return;

src/link/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { observable } from '@trpc/server/observable';
44
import * as amqp from 'amqp-connection-manager';
55
import { randomUUID } from 'crypto';
66
import EventEmitter from 'events';
7+
import { parse, stringify } from 'superjson';
78

89
import type { TRPCRMQRequest, TRPCRMQResponse } from '../types';
910

@@ -31,7 +32,7 @@ export const rmqLink = <TRouter extends AnyRouter>(opts: TRPCRMQLinkOptions): TR
3132
if (!msg) return;
3233
responseEmitter.emit(
3334
msg.properties.correlationId as string,
34-
JSON.parse(msg.content.toString('utf-8'))
35+
parse(msg.content.toString('utf-8'))
3536
);
3637
},
3738
{ noAck: true }
@@ -43,7 +44,7 @@ export const rmqLink = <TRouter extends AnyRouter>(opts: TRPCRMQLinkOptions): TR
4344
new Promise<any>(resolve => {
4445
const correlationId = randomUUID();
4546
responseEmitter.once(correlationId, resolve);
46-
void channel.sendToQueue(queue, Buffer.from(JSON.stringify(message)), {
47+
void channel.sendToQueue(queue, Buffer.from(stringify(message)), {
4748
correlationId,
4849
replyTo: REPLY_QUEUE
4950
});

0 commit comments

Comments
 (0)