Skip to content

Commit

Permalink
chore: fix stackblitz output types (#6346)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored Dec 29, 2024
1 parent bea006b commit d5b7199
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@trpc/client": "npm:@trpc/client@next",
"@trpc/server": "npm:@trpc/server@next",
"superjson": "^1.12.4",
"zod": "^3.0.0"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
* We only import the `AppRouter` type from the server - this is not available at runtime
*/
import type { AppRouter } from '../server/index.js';
import { transformer } from '../shared/transformer.js';

// Initialize the tRPC client
const trpc = createTRPCClient<AppRouter>({
Expand All @@ -19,9 +20,11 @@ const trpc = createTRPCClient<AppRouter>({
condition: (op) => op.type === 'subscription',
true: unstable_httpSubscriptionLink({
url: 'http://localhost:3000',
transformer,
}),
false: unstable_httpBatchStreamLink({
url: 'http://localhost:3000',
transformer,
}),
}),
],
Expand Down
5 changes: 4 additions & 1 deletion src/server/trpc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { initTRPC } from '@trpc/server';
import { transformer } from '../shared/transformer.js';

/**
* Initialization of tRPC backend
* Should be done only once per backend!
*/
const t = initTRPC.create();
const t = initTRPC.create({
transformer,
});

/**
* Export reusable router and procedure helpers
Expand Down
8 changes: 8 additions & 0 deletions src/shared/transformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* If you need to add transformers for special data types like `Temporal.Instant` or `Temporal.Date`, `Decimal.js`, etc you can do so here.
* Make sure to import this file rather than `superjson` directly.
* @see https://github.com/blitz-js/superjson#recipes
*/
import superjson from 'superjson';

export const transformer = superjson;

0 comments on commit d5b7199

Please sign in to comment.