DivMode
DivMode
Explore posts from servers
TTCTheo's Typesafe Cult
Created by DivMode on 8/24/2023 in #questions
Zod not returning undefined
I have this but it looks like zod has a problem returning undefined. I use prisma and I want it to do nothing which prisma does when value is undefined.
created: z.string().nullish().transform((val) => {
return val ? new Date(val) : undefined;
}),
created: z.string().nullish().transform((val) => {
return val ? new Date(val) : undefined;
}),
But get this error
[TypeScript] Types of property 'creationDate' are incompatible.
[TypeScript] Type '(Date | ((params?: RawCreateParams) => ZodUndefined)) & (Date | ((params?: RawCreateParams) => ZodUndefined) | undefined)' is not assignable to type 'string | Date | NullableDateTimeFieldUpdateOperationsInput | null | undefined'.
[TypeScript] Type '(params?: RawCreateParams) => ZodUndefined' is not assignable to type 'string | Date | NullableDateTimeFieldUpdateOperationsInput | null | undefined'.
[TypeScript]
[TypeScript] 308 update: whois
[TypeScript] Types of property 'creationDate' are incompatible.
[TypeScript] Type '(Date | ((params?: RawCreateParams) => ZodUndefined)) & (Date | ((params?: RawCreateParams) => ZodUndefined) | undefined)' is not assignable to type 'string | Date | NullableDateTimeFieldUpdateOperationsInput | null | undefined'.
[TypeScript] Type '(params?: RawCreateParams) => ZodUndefined' is not assignable to type 'string | Date | NullableDateTimeFieldUpdateOperationsInput | null | undefined'.
[TypeScript]
[TypeScript] 308 update: whois
16 replies
TTCTheo's Typesafe Cult
Created by DivMode on 7/11/2023 in #questions
prefetchInfinite not working when inputs are different from useInfinite
Ive been trying to figure out why prefetching doesnt work when the inputs are different between prefetchinfinite and infinitequery. Its works great when the inputs are the same. Hoping someone can shed some light on this.
export const getStaticProps: GetStaticProps<
PageProps,
Query,
PreviewData
> = async (ctx) => {
const { preview = false, previewData = {} } = ctx;

const token = previewData.token;
const [settings, page = fallbackPage] = await Promise.all([
getSettings({ token }),
getHomePage({ token })
]);

const ssg = createServerSideHelpers({
router: appRouter,
ctx: await createContextInner(),
transformer: superjson
});

await ssg.domain.getAll.prefetchInfinite({
recordsPerPage: 40,
query: null,
sorting: [
{
id: "godaddyDomainData.auctionEndTime",
desc: true
}
],
activeAuctions: true,
attributes: attributes,
filters: {
query: {
items: [{ type: "cond", data: {} }]
}
}
});

return {
props: {
trpcState: ssg.dehydrate(),
page,
settings,
preview,
token: previewData.token ?? null
},
revalidate: 3600
};
};
export const getStaticProps: GetStaticProps<
PageProps,
Query,
PreviewData
> = async (ctx) => {
const { preview = false, previewData = {} } = ctx;

const token = previewData.token;
const [settings, page = fallbackPage] = await Promise.all([
getSettings({ token }),
getHomePage({ token })
]);

const ssg = createServerSideHelpers({
router: appRouter,
ctx: await createContextInner(),
transformer: superjson
});

await ssg.domain.getAll.prefetchInfinite({
recordsPerPage: 40,
query: null,
sorting: [
{
id: "godaddyDomainData.auctionEndTime",
desc: true
}
],
activeAuctions: true,
attributes: attributes,
filters: {
query: {
items: [{ type: "cond", data: {} }]
}
}
});

return {
props: {
trpcState: ssg.dehydrate(),
page,
settings,
preview,
token: previewData.token ?? null
},
revalidate: 3600
};
};
const {
data,
hasNextPage,
fetchNextPage,
isError,
isFetching,
isLoading
} = trpc.domain.getAll.useInfiniteQuery(
{
recordsPerPage: 40,
query: debounced,
sorting,
activeAuctions,
attributes: undefined,
filters
},
{
getNextPageParam: (lastPage) => {
// @ts-ignore
const totalPages = Math.floor(
lastPage.estimatedTotalHits / lastPage.limit
);
// @ts-ignore
const actualPage = lastPage.offset / lastPage.limit;
return actualPage < totalPages ? actualPage + 1 : undefined; // By returning undefined if there are no more pages, hasNextPage boolean will be set to false
}
}
);
const {
data,
hasNextPage,
fetchNextPage,
isError,
isFetching,
isLoading
} = trpc.domain.getAll.useInfiniteQuery(
{
recordsPerPage: 40,
query: debounced,
sorting,
activeAuctions,
attributes: undefined,
filters
},
{
getNextPageParam: (lastPage) => {
// @ts-ignore
const totalPages = Math.floor(
lastPage.estimatedTotalHits / lastPage.limit
);
// @ts-ignore
const actualPage = lastPage.offset / lastPage.limit;
return actualPage < totalPages ? actualPage + 1 : undefined; // By returning undefined if there are no more pages, hasNextPage boolean will be set to false
}
}
);
2 replies
TTCTheo's Typesafe Cult
Created by DivMode on 7/6/2023 in #questions
Regex cutting off anything after space in the url
Heres the current regex : const regex = /(https?://\S+)\s\n\s(Canonical|\d)/g; it gives back: "http://www.stjosephnewwaverlytx.net/Religious" want it to give me the full url: "http://www.stjosephnewwaverlytx.net/Religious" + " Education/Teachers and Staff/Lessons/Misc/Sacraments.jpg Tried for a couple of hours to get it working but with no luck. Any help would be appreciated. Thanks!
5 replies
TTCTheo's Typesafe Cult
Created by DivMode on 3/8/2023 in #questions
prefetchInfinite causing query on initial load
I am prefetching the data in getStaticProps and it fetches on initial load even with staletime set to infinity. https://www.loom.com/share/454e3d2b75fa426d923e119775d1086c
4 replies
TTCTheo's Typesafe Cult
Created by DivMode on 11/1/2022 in #questions
No longer able to set background images in css with nextjs 13?
3 replies