venego
venego
Explore posts from servers
TtRPC
Created by venego on 10/29/2024 in #❓-help
Can I respond to client from a middleware?
I have this authentication middleware that needs to refresh the access token of a JWT session, and I don't want to duplicate the logic in all procedures. How can I send a response from the middleware itself? When I do a simple return, TS gives me some errors, it seems that it expects next() as an output.
2 replies
PPrisma
Created by venego on 8/23/2024 in #help-and-questions
Eloquent's relations equivalent in Prisma?
While it doesn't make a big difference in DX, Eloquen's relations do save some time and make it fun to type those short DSL queries. I haven't skimmed through the whole doc of Prisma, but is there an equivalent to what I described?
2 replies
DDeno
Created by venego on 8/9/2024 in #help
Hard SQL Query
No description
1 replies
DDeno
Created by venego on 1/10/2024 in #help
Can't spawn a shell properly using Deno!
const bash = (() => {
const bashProc = spawn("bash");

bashProc.stdout.on("data", (data: string) => {
console.log(`stdout: ${data}`);
});

bashProc.stderr.on("data", (err: string) => {
console.error(`stderr: ${err}`);
throw Error(err);
});

bashProc.on("close", (code: string) => {
console.log(`child process exited with code ${code}`);
});

return bashProc.stdin.write;
})();
bash('echo lll');
const bash = (() => {
const bashProc = spawn("bash");

bashProc.stdout.on("data", (data: string) => {
console.log(`stdout: ${data}`);
});

bashProc.stderr.on("data", (err: string) => {
console.error(`stderr: ${err}`);
throw Error(err);
});

bashProc.on("close", (code: string) => {
console.log(`child process exited with code ${code}`);
});

return bashProc.stdin.write;
})();
bash('echo lll');
I know there is Deno.run, but I need a way to be able to access the std outputs and errors. I'm really new to Deno, sorry if this is a dumb question.
38 replies
TtRPC
Created by venego on 9/28/2023 in #❓-help
Context is not fully globally accessed? [ probably newbie question ]
I create a context in the based procedure, but It's undefined in the procedure based on it. Also the opts.ctx doesn't exist before I create it, although I've used .context() upon initializing trpc, but that's no big deal. NVM I should've defined it upon server creation. Context defined by a procedure cannot be seen by another procedure?? how do I get around that?
const trpc = initTRPC.context<{
userSession: { id: string, authenticated: boolean }
}>().create();

const baseProcedure = trpc.procedure.use((opts) => {
opts.ctx = {
userSession: {
id: 'dummy',
authenticated: false
}
};

return opts.next()
});
const protectedProcedure = baseProcedure.use((opts) => {
// ctx is undefined
if (!opts.ctx.userSession.authenticated) {
throw new TRPCError(
{ code: 'UNAUTHORIZED', cause: 'because!' }
);
}
return opts.next();
});
const trpc = initTRPC.context<{
userSession: { id: string, authenticated: boolean }
}>().create();

const baseProcedure = trpc.procedure.use((opts) => {
opts.ctx = {
userSession: {
id: 'dummy',
authenticated: false
}
};

return opts.next()
});
const protectedProcedure = baseProcedure.use((opts) => {
// ctx is undefined
if (!opts.ctx.userSession.authenticated) {
throw new TRPCError(
{ code: 'UNAUTHORIZED', cause: 'because!' }
);
}
return opts.next();
});
7 replies
TTCTheo's Typesafe Cult
Created by venego on 4/1/2023 in #questions
How do I represent relationships in a sql database?
I don't want to duplicate the connection twice, so I though there would be a way to do this in sql. I'm not good at sql, but I would assume that the logic of the query would be something like: select col!='7mida' where userA='7mida' or userB='7mida' from connections; Where "7mida" is the guy I'm trying to list his friends. So the table needs to be filtered twice in one query. It's possible that I only filter once, using sql, and get something like so:
7mida | bo9al
3disa | 7mida
7mida | bo9al
3disa | 7mida
Then, using programming, I can let list only the ones that do not match the target's name. But I though first to check if something similar to the first option exists. Please help!
3 replies
TTCTheo's Typesafe Cult
Created by venego on 3/3/2023 in #questions
How do I redraw DOM elements in a react component?
8 replies
TTCTheo's Typesafe Cult
Created by venego on 3/1/2023 in #questions
how do I get an iso formated local date that matches my OS's one in js?
@corn flour you know...
30 replies
TTCTheo's Typesafe Cult
Created by venego on 2/25/2023 in #questions
Is there a good sqlite client for js?
I'm really trying to cope with this one: https://www.npmjs.com/package/sqlite3 but seems like it has been designed to hate you.
9 replies
TTCTheo's Typesafe Cult
Created by venego on 2/22/2023 in #questions
what's happening to tailwind's lsp client?
yesterday I left my code working, but today I don't know what is happening with tailwind, I tried updating npm packages and everything. this is the piece of code where I struggled to get tailwind to work: (simplified version)
//...
return <li className={`h-${4}`}></li>
//...
//...
return <li className={`h-${4}`}></li>
//...
when I inspect the dom in the browser, the classname is there but the actual class is not. seems like tailwind is running out of order?? note: other react+tailwind projects in my pc are working just fine. how do I debug this?
100 replies
TTCTheo's Typesafe Cult
Created by venego on 2/6/2023 in #questions
Is these animations a lot for a library like react?
I want to make an algorithm visualizer, like this one: https://www.toptal.com/developers/sorting-algorithms I found this lib called framer-motion. I might be wrong but it seems that I need to re-render a lot to be able to build the project above. I probably need charts because it's animating based on data. but I don't know a charting lib that is flexible enough. Is there another way other than using pure js. or should I just learn another framework?
1 replies
TTCTheo's Typesafe Cult
Created by venego on 1/17/2023 in #questions
how do you change the parent branch in git?
Here is my current git graph:
main __c1__c2__c3__c4__c5
|
branchA |__c1__c2__c3__c4
|
branchB |__c1__c2__c3__C4
main __c1__c2__c3__c4__c5
|
branchA |__c1__c2__c3__c4
|
branchB |__c1__c2__c3__C4
I mistakenly though I was branching out of the last commit on main. but I instead branched out of branchA. I don't wanna go through removing the branchA changes from every single file on branchB. Is there a way to "rebase" the branchB - c1 on main - c2 without doing it the hard way?
21 replies
TTCTheo's Typesafe Cult
Created by venego on 1/8/2023 in #questions
can I have overlapping primary keys? (mysql)
I have this DB where I have two entities that has to be managed by a user. The user can manage either one of the two entities or both. So here is the structure:
create table users(
id varchar(50) primary key
)
create table A(
id varchar(50) primary key
)
create table B(
id varchar(50) primary key
)
create table privileges(
id varchar(50),
manager_fk varchar(50),
A_fk varchar(50),
B_fk varchar(50),
primary key(manager_fk, A_fk, B_fk),
foreign key(A_fk) references A(id),
foreign key(B_fk) references B(id)
)
create table users(
id varchar(50) primary key
)
create table A(
id varchar(50) primary key
)
create table B(
id varchar(50) primary key
)
create table privileges(
id varchar(50),
manager_fk varchar(50),
A_fk varchar(50),
B_fk varchar(50),
primary key(manager_fk, A_fk, B_fk),
foreign key(A_fk) references A(id),
foreign key(B_fk) references B(id)
)
the problem: If a user has access to both A and B. he also can accidentally have access to one of them and the table would have partial duplication. solutions in mind: - I could only add privilege to only one of them entities at a time. - I could have two privileges tables. one for A and another for B I thought there should be some way to have an overlapped primary keys or something similar. my real question: Is there any other way to do this other than my simple solution?
1 replies
TTCTheo's Typesafe Cult
Created by venego on 12/23/2022 in #questions
media files do not show on my netlify site when I deploy my astro project.
I have this astro project working just fine on my local machine. when I do build and preview everything works as expected. but when I deployed it on netlify all media files and favicon stopped working. I have some fonts in the src directory and they work fine. but the media files in public directory do not show up. Is there a way to browse the file system on netlify or something similar?
12 replies
TTCTheo's Typesafe Cult
Created by venego on 12/19/2022 in #questions
I still have hmr.js when I do `pnpm build` in an Astro project???
how do I generate a production optimised build in Astro?
10 replies
TTCTheo's Typesafe Cult
Created by venego on 12/16/2022 in #questions
is there an image lazy loading library for astro?
I found this cool library called Blurr-Hash with helps with lazy loading images in a really cool and efficient way. but the thing is I also want to use this component from @astro/image called Picture where I can specify multiple versions/sizes of images. and I don't know how to combine both, then I thought there must be some library for this that is specific to astro. unfortunately I found non. How do I do this?
4 replies
TTCTheo's Typesafe Cult
Created by venego on 12/13/2022 in #questions
tailwind newly added spacing overrides the defaults
I just added this custom spacing to tailwind: spacing: {main: '10%'} and other spacings eg.py-4 stopped working.
3 replies
TTCTheo's Typesafe Cult
Created by venego on 12/1/2022 in #questions
adding typescript to a vite setup in progress
I have this project started with vite and after two moths of working with it, I finally realised that I really need typescript. the problem is I can get vite to recognise typescript.
9 replies
TTCTheo's Typesafe Cult
Created by venego on 11/28/2022 in #questions
html `img` tag considered as not same origin?
I have this API that is 100% allowing the client to access it, and now I'm trying make it serve images to the client. so I setup everything and now I can visit the route (dedicated to static files serving) and browse to any file and get that file to show/download in my browser. the only problem is when I use the src attribute of an html img tag, I see this error in the browser: net::ERR_BLOCKED_BY_RESPONSE.NotSameOrigin 200 the url in the src is the same as the one I visit in the browser and the image loads successfully.
52 replies
TTCTheo's Typesafe Cult
Created by venego on 11/19/2022 in #questions
I can't inner join with a table twice
I have these two tables:
CREATE TABLE users(
id,
username,
pass
)

CREATE TABLE articles(
id,
ownerId,
authorId,
CONSTRAINT fk_articles_owner FOREIGN KEY(ownerId) REFERENCES users(id),
CONSTRAINT fk_articles_author FOREIGN KEY(authorId) REFERENCES users(id)
)
CREATE TABLE users(
id,
username,
pass
)

CREATE TABLE articles(
id,
ownerId,
authorId,
CONSTRAINT fk_articles_owner FOREIGN KEY(ownerId) REFERENCES users(id),
CONSTRAINT fk_articles_author FOREIGN KEY(authorId) REFERENCES users(id)
)
I need to inner join the two tables twice to get the owner and the author in one request. the query I write is:
select * from articles
INNER JOIN users ON articles.ownerId =users.id
INNER JOIN users ON articles.authorId=users.id
select * from articles
INNER JOIN users ON articles.ownerId =users.id
INNER JOIN users ON articles.authorId=users.id
and I get this error: sqlMessage: "Not unique table/alias: 'users'" Is there a way to do it without having to query two times? I suspect that the error is because the users table would output duplicate columns but how do I rename those columns for each inner join?
9 replies