Nivoa
Nivoa
Explore posts from servers
TtRPC
Created by Nivoa on 6/16/2024 in #❓-help
When a procedure returns an instance of a class, the superjson isApplicable doesnt detect it
When a procedure returns an instance of a class, the superjson isApplicable doesnt detect it as that class, but when you return it inside an object or array, it does.
// ❌
class Test {
a: string;
constructor() {
this.a = "a";
}
serialize() {
return "a"
}
deserialize() {
return "b"
}
}
test: publicProcedure
.query(async ({ input, ctx }) => {
return new Test()
}),
// ❌
class Test {
a: string;
constructor() {
this.a = "a";
}
serialize() {
return "a"
}
deserialize() {
return "b"
}
}
test: publicProcedure
.query(async ({ input, ctx }) => {
return new Test()
}),
// ✅
test: publicProcedure
.query(async ({ input, ctx }) => {
return { test: new Test() }
}),
// ✅
test: publicProcedure
.query(async ({ input, ctx }) => {
return { test: new Test() }
}),
then in superjson:
superjson.registerCustom(
{
deserialize: (test) => {
return null;
},
serialize: (test) => {
return null;
},
isApplicable: (val: unknown) => {
return val instanceof Test
},
},
"Test",
);
superjson.registerCustom(
{
deserialize: (test) => {
return null;
},
serialize: (test) => {
return null;
},
isApplicable: (val: unknown) => {
return val instanceof Test
},
},
"Test",
);
what happens is that val is never an actual instanceof Test, it is an object with the properties of Test, but not the instance itself. But when I return it as the 2nd procedure, val.test instanceof Test evals to true. is this a bug?
10 replies
TtRPC
Created by Nivoa on 6/9/2024 in #❓-help
How to set up custom response headers at procedure level
hello guys, i'd like to know how to set up custom headers per procedure. I am aware of the responseMeta, but thats general. I'd like something more fine-grained. Something like this but doesnt work:
getPoolByPoolId: publicProcedure.query(async ({ ctx }) => {
const pool = await ctx.raydiumClient.fetchJupTokenList(
JupTokenType.Strict,
true,
);
// ctx.headers["Cache-Controlz"] = "public, max-age=600";
if ("headers" in ctx) {
ctx.headers.append("x-test-Control", "public, max-age=600");
console.log("ctx.headers", ctx.headers);
}
return pool;
}),
getPoolByPoolId: publicProcedure.query(async ({ ctx }) => {
const pool = await ctx.raydiumClient.fetchJupTokenList(
JupTokenType.Strict,
true,
);
// ctx.headers["Cache-Controlz"] = "public, max-age=600";
if ("headers" in ctx) {
ctx.headers.append("x-test-Control", "public, max-age=600");
console.log("ctx.headers", ctx.headers);
}
return pool;
}),
2 replies
TTCTheo's Typesafe Cult
Created by Nivoa on 8/30/2023 in #questions
A client asked me to build a video course webapp. How would you build it?
A client asked me to build a video course webapp. How would you build it? CMS?
9 replies