Cobain
Explore posts from serversAarktype
•Created by Cobain on 10/9/2024 in #questions
Function which receives a arktype's 'type'
I'm trying to do something like this:
But the parsedResponse isn't of type T, so how do I make this function accept as schema anything created using type({...})
13 replies
Aarktype
•Created by Cobain on 9/20/2024 in #questions
Use native ts type
I was wondering if I could use an already created type:
inside an arktype type declaration:
I would go on and create an arktype literal as suggested in the docs, but this type is being declared from another object:
And I want it to be tighly coupled with that object
5 replies
Multiple platforms, same project
Hi! I was wondering if I could have, for the same monorepo, a hono instance to deploy with NodeJS to a traditional long-running server, and also have another instance to be able to deploy to vercel or aws lambda for stuff like cronjobs.
7 replies
Aarktype
•Created by Cobain on 9/6/2024 in #questions
Represent the File class
Hi! I want to make a schema for validating a form, and one of the elements of the form is going to be a file upload, so I would like to validate that the form is sending an instance of the File class, and then validate that this file size is smaller than a certain amount. Is there a way to represent class instances in Arktype?
An example of doing this in Zod would be:
23 replies
DTDrizzle Team
•Created by Cobain on 4/29/2024 in #help
Delete and insert a record using deleted id in one transaction
Hi! I want to delete a record and use the deleted id to insert another one later in the same table. Is it possible to do so in a single transaction? The problem I'm encountering when doing this is I get a primary key error on insertion.
1 replies
DTDrizzle Team
•Created by Cobain on 4/25/2024 in #help
Struggling with subqueries
I want to basically do this query in drizzle:
SELECT o.id, o.date, t.currency
FROM "Operations" o
LEFT JOIN "Transactions" t ON o."id" = t."operationId"
WHERE o.id IN (
SELECT DISTINCT t."operationId"
FROM "Transactions" t
WHERE t.currency = 'usd'
ORDER BY t."operationId" DESC
LIMIT 8
);
Im using postgres-js and the problem is how to select those operations from the subquery.
This query is just a mock, but the reason to do the subquery is that I have to put conditions on both the operations and the transactions table, and if i just make a join of these queries and put the conditions, i will get the last 8 transactions for example, when what I really want is the last 8 operations and all their related transactions (meaning possibly more than 8 rows), even the ones whose currency isn't 'usd' for example. Doing raw sql it works as intended but I hoped to get it working with drizzle
Suggestions? Thanks in advance
3 replies
TTCTheo's Typesafe Cult
•Created by Cobain on 3/19/2024 in #questions
Deploy backend to cloudflare workers
Hi! So i was thinking in deploying the tRPC backend to cloudflare workers, but I don't know if it is an option to host backend and frontend separately in T3 as they are evidently deeply related. Is it possible? If is not, is it at least possible to host the whole t3 app on the cloudflare stack?
2 replies
TTCTheo's Typesafe Cult
•Created by Cobain on 2/8/2024 in #questions
Capture output in middleware?
Hi! I am making a middleware in TRPC which sends a log to DynamoDB, the thing is I managed to capture input of course, but don't know if I can capture the output (or response) of the endpoint to include it in the dynamodb item. Is it possible?
1 replies
TTCTheo's Typesafe Cult
•Created by Cobain on 1/25/2024 in #questions
How to monitor and analyze web app and api usage?
Hi! I was wondering how could I collect some key metrics (I'm deploying the next app on docker) like my web app visits and load time divided per page or trpc endpoints metrics.
4 replies
TTCTheo's Typesafe Cult
•Created by Cobain on 1/5/2024 in #questions
How to access files on production (Vercel deployment)
Hi! I'm have some mdx files which are directly red with readdirSync, so i have configured it to detect if it is in dev or prod environment. The mdx files are in /public/docs/*.mdx So when accessing in local enviroment i use path.join("public", "docs"), and when im in prod i use: path.join(process.cwd(), "docs"), which in vercel logs it says that it is trying to access /var/tasks/docs. And it is not finding the folder, however, when I look at the output info of my vercel deployment, the docs folder is there at the root with all the .mdx files, how do i access them in production?
3 replies
TTCTheo's Typesafe Cult
•Created by Cobain on 11/23/2023 in #questions
Log elapsedMs to axiom
Hi! I want to track my endpoints speed, they involve querying my postgresql db as well as my redis cache, how could I log the elapsedMs to axiom? I know it grabs all console.logged data, but the elapsedMs is already being calculated in the loggerlink, is there some way to include that in the logs axiom recieve?
2 replies
TTCTheo's Typesafe Cult
•Created by Cobain on 11/19/2023 in #questions
JSON Parsing, TRPC Client error
I have a project with various trcp endpoints on nextjs 13.5 and they are working fine on development, but when deploying to vercel i get this strange error of a non-whitespace character on all the GET operations:
[next-auth][error][CREATE_USER_EVENT_ERROR]
https://next-auth.js.org/errors#create_user_event_error Unexpected non-whitespace character after JSON at position 4 {
message: 'Unexpected non-whitespace character after JSON at position 4',
stack: 'TRPCClientError: Unexpected non-whitespace character after JSON at position 4\n' +
' at TRPCClientError.from (/var/task/.next/server/chunks/5.js:39:117279)\n' +
' at /var/task/.next/server/chunks/5.js:39:122357\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)',
name: 'TRPCClientError'
}
[97;46m << query [1;97;46m #1 entities.getAll [0m {
input: undefined,
result: TRPCClientError: Unexpected non-whitespace character after JSON at position 4
at TRPCClientError.from (/var/task/.next/server/chunks/5.js:39:117279)
at /var/task/.next/server/chunks/5.js:39:122357
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
meta: undefined,
shape: undefined,
data: undefined,
[cause]: SyntaxError: Unexpected non-whitespace character after JSON at position 4
at JSON.parse (<anonymous>)
at parse (/var/task/.next/server/chunks/5.js:43:4667)
at /var/task/.next/server/chunks/5.js:43:3830
at onChunk (/var/task/.next/server/chunks/5.js:43:3983)
at readStandardChunks (/var/task/.next/server/chunks/5.js:43:4254)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async readLines (/var/task/.next/server/chunks/5.js:43:4064)
at async parseJSONStream (/var/task/.next/server/chunks/5.js:43:3670)
},
elapsedMs: 145
}
The connection with the db is working fine, so I can't seem to find the problem.
6 replies
TTCTheo's Typesafe Cult
•Created by Cobain on 11/7/2023 in #questions
How to refetch useQuery with different input
Hi!
I have a query run with useQuery in a parent component, and in a child component which just contains a react-hook-form with some options for filtering. The tRPC endpoint has some optional inputs for filtering the query, the thing is I want to handle the submit of the filter form in the child component and re run the query but with new inputs added, how can I do that?
I tried using the utils from the api.context and using the refetch, but that didn't make my data refresh. Maybe is worth noting that my parent component useQuery is using this flags:
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
4 replies