Skip to content

Commit

Permalink
fix trpc build
Browse files Browse the repository at this point in the history
  • Loading branch information
younes200 committed Oct 17, 2023
1 parent 255cd19 commit 8ff74b6
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 13 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"admin": "yarn workspace admin",
"backend": "yarn workspace backend",
"prisma": "yarn workspace @celluloid/prisma",
"docker-build": "docker build -t celluloid:local ."
"docker-build": "DOCKER_BUILDKIT=1 docker build --build-arg APP=backend --build-arg START_COMMAND=start -t celluloid-backend:latest --cache-from=celluloid-backend:latest . "
},
"devDependencies": {
"@commitlint/cli": "^17.7.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
"dist/**/*"
],
"prisma": {
"schema": "schema.prisma",
Expand All @@ -33,7 +33,7 @@
"predev": "yarn run generate",
"studio": "yarn prisma studio",
"prisma": "dotenv -e ../../.env -- npx prisma",
"migrate-project": "tsx ./src/migrate-projects.ts",
"migrate-projects": "tsx ./src/migrate-projects.ts",
"tsx": "tsx"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/prisma/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export default defineConfig({
clean: true,
dts: true,
entry: ["src/index.ts"],
format: ["cjs", "esm"],
format: ["esm"],
target: "esnext",
minify: isProduction,
sourcemap: true,
});
5 changes: 4 additions & 1 deletion packages/trpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "dist/index.d.ts",
"type": "module",
"files": [
"dist"
"dist/**/*"
],
"scripts": {
"build": "tsup",
Expand All @@ -18,6 +18,8 @@
"bcryptjs": "^2.4.3",
"change-case": "^4.1.2",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-session": "^1.17.3",
"js2xmlparser": "^5.0.0",
"lodash": "^4.17.21",
"papaparse": "^5.4.1",
Expand All @@ -27,6 +29,7 @@
},
"devDependencies": {
"@celluloid/config": "*",
"@types/express-session": "^1.17.8",
"@types/uuid": "^9.0.4",
"tsup": "^7.2.0"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/trpc/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

declare namespace Express {
export interface Request {
user?: User; // 'User' should be imported or defined before this
}
}
8 changes: 4 additions & 4 deletions packages/trpc/src/routers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ export const projectRouter = router({

return {
...project,
editable: ctx.user && ctx.user?.id == project.userId || ctx.user?.role == UserRole.Admin,
deletable: ctx.user && ctx.user?.id == project.userId || ctx.user?.role == UserRole.Admin,
annotable: ctx.user && ctx.user?.id == project.userId || ctx.user?.role == UserRole.Admin || project.members.some(m => m.id == ctx.user?.id),
commentable: ctx.user && ctx.user?.id == project.userId || ctx.user?.role == UserRole.Admin || project.members.some(m => m.id == ctx.user?.id)
editable: ctx.user && (ctx.user.id == project.userId || ctx.user.role == UserRole.Admin),
deletable: ctx.user && (ctx.user.id == project.userId || ctx.user.role == UserRole.Admin),
annotable: ctx.user && (ctx.user.id == project.userId || ctx.user.role == UserRole.Admin || project.members.some(m => ctx.user && m.userId == ctx.user.id)),
commentable: ctx.user && (ctx.user.id == project.userId || ctx.user.role == UserRole.Admin || project.members.some(m => ctx.user && m.userId == ctx.user.id))
};
}),
add: protectedProcedure
Expand Down
7 changes: 5 additions & 2 deletions packages/trpc/src/trpc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import "express-session"

import { User, UserRole } from '@celluloid/prisma';
import { initTRPC, TRPCError } from '@trpc/server';
import * as trpcExpress from '@trpc/server/adapters/express';
import { Request } from "express";
import { Session } from "express-session";
import { OpenApiMeta } from 'trpc-openapi';
import { v4 as uuid } from 'uuid';


export type Context = {
user: User | null;
requestId: string;
Expand Down Expand Up @@ -32,7 +35,7 @@ export const createRPCContext = async ({

const logout = (): Promise<boolean> => {
return new Promise((resolve) => {
req.session.destroy((err) => {
req.session?.destroy((err: Error | null) => {
if (err) {
throw new TRPCError({
code: 'BAD_REQUEST',
Expand Down
3 changes: 2 additions & 1 deletion packages/trpc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"include": [
"**/*.ts",
"**/*.tsx",
"tsup.config.ts"
"tsup.config.ts",
"src/global.d.ts"
],
"exclude": [
"node_modules"
Expand Down
1 change: 1 addition & 0 deletions packages/trpc/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
dts: true,
entry: ["src/index.ts"],
format: ["esm"],
target: "esnext",
minify: isProduction,
sourcemap: true,
});
5 changes: 4 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1901,10 +1901,13 @@ __metadata:
"@celluloid/config": "*"
"@celluloid/prisma": "*"
"@trpc/server": ^10.40.0
"@types/express-session": ^1.17.8
"@types/uuid": ^9.0.4
bcryptjs: ^2.4.3
change-case: ^4.1.2
dotenv: ^16.3.1
express: ^4.18.2
express-session: ^1.17.3
js2xmlparser: ^5.0.0
lodash: ^4.17.21
papaparse: ^5.4.1
Expand Down Expand Up @@ -5387,7 +5390,7 @@ __metadata:
languageName: node
linkType: hard

"@types/express-session@npm:^1.15.8":
"@types/express-session@npm:^1.15.8, @types/express-session@npm:^1.17.8":
version: 1.17.8
resolution: "@types/express-session@npm:1.17.8"
dependencies:
Expand Down

0 comments on commit 8ff74b6

Please sign in to comment.