ItsWendell
ItsWendell
Explore posts from servers
TtRPC
Created by ItsWendell on 10/22/2023 in #❓-help
Global metadata / filters: Re-validate all queries
Hi all, Simple question, I'm looking for the most efficient way to add some global state to all queries, in this case it's a global filter, for this use-case, let's call it testModeFilter. In our dashboard this could be a Context / Provider that manages this state, ideally, when testModeFilter, we want to: 1. invalidate all queries / refetch mounted queries 2. Make sure this global filter / metadata is passed to the server 'somehow' What's the best approach for this? E.g. I was thinking possibly a cookie, or a header but was wondering if there's other ways to sent global metadata with every query / mutation.
4 replies
CDCloudflare Developers
Created by ItsWendell on 8/17/2023 in #workers-help
Sending multipart/mixed form data in Workers
With the form-data node package you can define content types / headers per item in the form, see example.
const form = new FormData();
form.append('directive', JSON.stringify(directive), {
contentType: 'application/json',
header: {
'content-type': 'application/json; charset=utf-8',
}
});
const form = new FormData();
form.append('directive', JSON.stringify(directive), {
contentType: 'application/json',
header: {
'content-type': 'application/json; charset=utf-8',
}
});
I'm trying to conform to the following spec: https://docs.expo.dev/technical-specs/expo-updates-1/#multipart-response Any tips on how to achieve this in Workers?
4 replies
TtRPC
Created by ItsWendell on 8/10/2023 in #❓-help
Deduping is broken, but is being batched
Hi all, We're using TRPC for our React Native app, while doing some testing, I saw in my server logs that the requests don't seem to be deduplicated on the client side, but are batched to the server.
/trpc/drivers.getMapboxToken,drivers.getStatus,users.current,users.current,users.current,settings.get,drivers.getStatus,drivers.getMapboxToken,users.current
/trpc/drivers.getMapboxToken,drivers.getStatus,users.current,users.current,users.current,settings.get,drivers.getStatus,drivers.getMapboxToken,users.current
Here you can see that these requests are being made twice, this is for one active client, not sure why this is or if this is due potentially React Query. Versions being used: 10.37.1 for client / server React Query: ^4.32.6 What could this possibly be? Here's our TRPC Provider (combined some of the files):
export const trpc = createTRPCReact<AppRouter>();

export const createTrpcClient = () => {
return trpc.createClient({
transformer: superjson,
links: [
httpBatchLink({
url: `${apiUrl}/trpc`,
headers: getHeaders,
}),
],
});
};

export const TrpcProvider = ({ children }: { children: React.ReactNode }) => {
const [queryClient] = useState(
() =>
new QueryClient({
queryCache: trpcQueryCache,
}),
);
const [trpcClient] = useState(() => createTrpcClient());

useEffect(() => {
console.debug("[TrpcProvider] Listening for AppState changes", Platform.OS);
const subscription = AppState.addEventListener(
"change",
async (status: AppStateStatus) => {
console.info(
`[TrpcProvider] AppState changed to ${status}, setting onlineManager and focusManager`,
);
focusManager.setFocused(status === "active");
},
);

return () => {
console.debug("[TrpcProvider] Unsubscribing from AppState changes");
subscription.remove();
};
}, []);

return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
};
export const trpc = createTRPCReact<AppRouter>();

export const createTrpcClient = () => {
return trpc.createClient({
transformer: superjson,
links: [
httpBatchLink({
url: `${apiUrl}/trpc`,
headers: getHeaders,
}),
],
});
};

export const TrpcProvider = ({ children }: { children: React.ReactNode }) => {
const [queryClient] = useState(
() =>
new QueryClient({
queryCache: trpcQueryCache,
}),
);
const [trpcClient] = useState(() => createTrpcClient());

useEffect(() => {
console.debug("[TrpcProvider] Listening for AppState changes", Platform.OS);
const subscription = AppState.addEventListener(
"change",
async (status: AppStateStatus) => {
console.info(
`[TrpcProvider] AppState changed to ${status}, setting onlineManager and focusManager`,
);
focusManager.setFocused(status === "active");
},
);

return () => {
console.debug("[TrpcProvider] Unsubscribing from AppState changes");
subscription.remove();
};
}, []);

return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
};
4 replies
CDCloudflare Developers
Created by ItsWendell on 5/26/2023 in #workers-help
Deployment Error: workers.api.error.placement_and_triggers_configured (100150)
Hi all! I'm suddenly getting the following error when trying to deploy an worker, as the error might indicate, we do have placements set to smart and we have a queue consumer / producer set in the same worker. I feel like this didn't happen before and wonder what changed, and if it's not possible to have smart placements enabled with queue consumers / producers?
56 replies
CDCloudflare Developers
Created by ItsWendell on 5/20/2023 in #workers-help
KV Assets (site bucket) __STATIC_CONTENT is are suffixed with hashes (05c5fa8db8)
Hi all, We're trying to use a workers sites bucket defined in our API wrangler to host some (temporary) image assets in to show in our app, but once we attempt to fetch these we see that they are suffixed with hashes. What is the recommended way to continue here so we can access assets in these buckets through e.g. /public/some-temp-image.png? We use getAssetFromKV:
return await getAssetFromKV(
{
request: ctx.req.raw,
waitUntil: ctx.executionCtx.waitUntil.bind(ctx.executionCtx),
},
{
ASSET_NAMESPACE: ctx.env.__STATIC_CONTENT,
mapRequestToAsset: (req) => {
const url = new URL(req.url);
url.pathname = url.pathname.replace(/^\/public/, "");
return new Request(url.toString(), req);
},
},
);
} catch (e) {
if (e instanceof Error) {
console.error(e);
if ("status" in e) {
if (e.status === 404) {
return ctx.notFound();
}
}
}
throw e;
}
return await getAssetFromKV(
{
request: ctx.req.raw,
waitUntil: ctx.executionCtx.waitUntil.bind(ctx.executionCtx),
},
{
ASSET_NAMESPACE: ctx.env.__STATIC_CONTENT,
mapRequestToAsset: (req) => {
const url = new URL(req.url);
url.pathname = url.pathname.replace(/^\/public/, "");
return new Request(url.toString(), req);
},
},
);
} catch (e) {
if (e instanceof Error) {
console.error(e);
if ("status" in e) {
if (e.status === 404) {
return ctx.notFound();
}
}
}
throw e;
}
Can we skip workers sites from adding these hashes?
5 replies
CDCloudflare Developers
Created by ItsWendell on 5/20/2023 in #general-help
One email, multiple accounts?
Hi all! A friend is trying to invite me to an Cloudflare account he recently made so we can work together on a project in there (Workers, etc). He sent me an invite on an email address I already have registered at Cloudflare but I haven't received any emails. He now tried to delete and add me so many times that he got rate limited and needs to wait for an hour. I was wondering whether it's even possible to have multiple accounts / organizations connected to a user?
8 replies
TtRPC
Created by ItsWendell on 4/30/2023 in #❓-help
TypeScript, Mono-Repositories and Internal Packages / Project References
I am getting quite frustrate with project references / internal projects and the resolving of types for TypeScript. To make it a bit smaller, let's say I have @acme/api-service which exports TRPC types and a Cloudflare Worker, I also have @acme/app which wants to consume this api service's TRPC types. In @acme/api-service I am exporting main / types fields in package.json, I am also using path aliases, and defining global types for it's environment in compilerOptions.types in tsconfig.json. When I don't use project references, and I run tsc --noEmit for type checking in the @acme/app folder I get errors about the missing global types, and the path aliases. When I use project references it seems like that kind of fixes it, but it looks like I need to continuously watch / build the declaration files of @acme/api-service while in development to not get these types out of sync. What is a good solution here, can I make sure that tsc reads the aliases / types from the tsconfig file from @acme/api-service? I am looking for a good setup for this scenario, where I can properly type check the whole mono repo during CI / CD, and making sure that the IDE stays fast since our repository is getting quite big.
4 replies
TtRPC
Created by ItsWendell on 11/27/2022 in #❓-help
Proxy TRPC server to another client
I've two TRPC servers, one essentially acts like a proxy, it validates auth and based on a specific property it forwards you to the destined server (with that one property removed). Now I have to write all those queries and mutation twice, is there a simpeler way to do this? Is there any way to bind a specific TRPC client to a server?
8 replies
TtRPC
Created by ItsWendell on 9/28/2022 in #❓-help
Sharing middleware between TRPC servers
We currently have microservices REST API's on Cloudflare Workers and I'm thinking about moving this to TRPC Microservices. We currently have a middleware in a shared package that we can reuse between microservices for authentication, how do I do this within TRPC? How do I define a MiddlewareFunction that can be reused between multiple TRPC instances?
2 replies