@goscribe/server 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.d.ts +1 -1
- package/dist/lib/file.d.ts +1 -0
- package/dist/lib/file.d.ts.map +1 -0
- package/dist/lib/file.js +1 -0
- package/dist/lib/prisma.d.ts +2 -2
- package/dist/lib/prisma.d.ts.map +1 -1
- package/dist/lib/prisma.js +2 -2
- package/dist/lib/storage.d.ts +4 -0
- package/dist/lib/storage.d.ts.map +1 -0
- package/dist/lib/storage.js +13 -0
- package/dist/routers/_app.d.ts +61 -15
- package/dist/routers/_app.d.ts.map +1 -1
- package/dist/routers/auth.d.ts +1 -1
- package/dist/routers/workspace.d.ts +59 -13
- package/dist/routers/workspace.d.ts.map +1 -1
- package/dist/routers/workspace.js +113 -11
- package/dist/server.js +4 -1
- package/dist/trpc.d.ts +6 -6
- package/package.json +9 -4
- package/prisma/schema.prisma +0 -1
- package/src/context.ts +1 -1
- package/src/index.ts +3 -3
- package/src/lib/auth.ts +1 -1
- package/src/lib/prisma.ts +1 -1
- package/src/routers/_app.ts +3 -3
- package/src/routers/auth.ts +1 -1
- package/src/routers/workspace.ts +9 -8
- package/src/server.ts +3 -3
- package/src/trpc.ts +1 -1
- package/tsconfig.json +17 -10
package/dist/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express";
|
|
2
2
|
export declare function createContext({ req, res }: CreateExpressContextOptions): Promise<{
|
|
3
|
-
db: import("
|
|
3
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
4
4
|
session: any;
|
|
5
5
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
6
6
|
res: import("express").Response<any, Record<string, any>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/lib/file.ts"],"names":[],"mappings":""}
|
package/dist/lib/file.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/lib/prisma.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { PrismaClient } from "
|
|
2
|
-
export declare const prisma: PrismaClient<import("
|
|
1
|
+
import { PrismaClient } from "@prisma/client";
|
|
2
|
+
export declare const prisma: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
3
3
|
//# sourceMappingURL=prisma.d.ts.map
|
package/dist/lib/prisma.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/lib/prisma.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/lib/prisma.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,eAAO,MAAM,MAAM,gIAIf,CAAC"}
|
package/dist/lib/prisma.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.prisma = void 0;
|
|
4
|
-
const
|
|
4
|
+
const client_1 = require("@prisma/client");
|
|
5
5
|
const globalForPrisma = globalThis;
|
|
6
6
|
exports.prisma = globalForPrisma.prisma ??
|
|
7
|
-
new
|
|
7
|
+
new client_1.PrismaClient({
|
|
8
8
|
// log: ["query"], // enable if you want
|
|
9
9
|
});
|
|
10
10
|
if (process.env.NODE_ENV !== "production")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/lib/storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,eAAO,MAAM,OAAO,SAMlB,CAAC;AAEH,eAAO,MAAM,MAAM,wCAA0C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bucket = exports.storage = void 0;
|
|
4
|
+
// src/server/lib/gcs.ts
|
|
5
|
+
const storage_1 = require("@google-cloud/storage");
|
|
6
|
+
exports.storage = new storage_1.Storage({
|
|
7
|
+
projectId: process.env.GCP_PROJECT_ID,
|
|
8
|
+
credentials: {
|
|
9
|
+
client_email: process.env.GCP_CLIENT_EMAIL,
|
|
10
|
+
private_key: process.env.GCP_PRIVATE_KEY?.replace(/\\n/g, "\n"),
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
exports.bucket = exports.storage.bucket(process.env.GCP_BUCKET);
|
package/dist/routers/_app.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
2
2
|
export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
3
3
|
ctx: {
|
|
4
|
-
db: import("
|
|
4
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
5
5
|
session: any;
|
|
6
6
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
7
7
|
res: import("express").Response<any, Record<string, any>>;
|
|
@@ -12,7 +12,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
12
12
|
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
13
13
|
auth: import("@trpc/server").TRPCBuiltRouter<{
|
|
14
14
|
ctx: {
|
|
15
|
-
db: import("
|
|
15
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
16
16
|
session: any;
|
|
17
17
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
18
18
|
res: import("express").Response<any, Record<string, any>>;
|
|
@@ -37,7 +37,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
37
37
|
}>>;
|
|
38
38
|
workspace: import("@trpc/server").TRPCBuiltRouter<{
|
|
39
39
|
ctx: {
|
|
40
|
-
db: import("
|
|
40
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
41
41
|
session: any;
|
|
42
42
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
43
43
|
res: import("express").Response<any, Record<string, any>>;
|
|
@@ -48,47 +48,93 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
48
48
|
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
49
49
|
list: import("@trpc/server").TRPCQueryProcedure<{
|
|
50
50
|
input: void;
|
|
51
|
-
output:
|
|
51
|
+
output: {
|
|
52
|
+
id: string;
|
|
53
|
+
createdAt: Date;
|
|
54
|
+
updatedAt: Date;
|
|
55
|
+
ownerId: string;
|
|
56
|
+
title: string;
|
|
57
|
+
description: string | null;
|
|
58
|
+
folderId: string | null;
|
|
59
|
+
}[];
|
|
52
60
|
meta: object;
|
|
53
61
|
}>;
|
|
54
62
|
create: import("@trpc/server").TRPCMutationProcedure<{
|
|
55
|
-
input:
|
|
56
|
-
|
|
63
|
+
input: {
|
|
64
|
+
name: string;
|
|
65
|
+
description?: string | undefined;
|
|
66
|
+
};
|
|
67
|
+
output: {
|
|
68
|
+
id: string;
|
|
69
|
+
createdAt: Date;
|
|
70
|
+
updatedAt: Date;
|
|
71
|
+
ownerId: string;
|
|
72
|
+
title: string;
|
|
73
|
+
description: string | null;
|
|
74
|
+
folderId: string | null;
|
|
75
|
+
};
|
|
57
76
|
meta: object;
|
|
58
77
|
}>;
|
|
59
78
|
get: import("@trpc/server").TRPCQueryProcedure<{
|
|
60
79
|
input: {
|
|
61
80
|
id: string;
|
|
62
81
|
};
|
|
63
|
-
output:
|
|
82
|
+
output: {
|
|
83
|
+
id: string;
|
|
84
|
+
createdAt: Date;
|
|
85
|
+
updatedAt: Date;
|
|
86
|
+
ownerId: string;
|
|
87
|
+
title: string;
|
|
88
|
+
description: string | null;
|
|
89
|
+
folderId: string | null;
|
|
90
|
+
} | null;
|
|
64
91
|
meta: object;
|
|
65
92
|
}>;
|
|
66
93
|
update: import("@trpc/server").TRPCMutationProcedure<{
|
|
67
94
|
input: {
|
|
68
95
|
id: string;
|
|
96
|
+
name?: string | undefined;
|
|
97
|
+
description?: string | undefined;
|
|
98
|
+
};
|
|
99
|
+
output: {
|
|
100
|
+
id: string;
|
|
101
|
+
createdAt: Date;
|
|
102
|
+
updatedAt: Date;
|
|
103
|
+
ownerId: string;
|
|
104
|
+
title: string;
|
|
105
|
+
description: string | null;
|
|
106
|
+
folderId: string | null;
|
|
69
107
|
};
|
|
70
|
-
output: void;
|
|
71
108
|
meta: object;
|
|
72
109
|
}>;
|
|
73
110
|
delete: import("@trpc/server").TRPCMutationProcedure<{
|
|
74
111
|
input: {
|
|
75
112
|
id: string;
|
|
76
113
|
};
|
|
77
|
-
output:
|
|
114
|
+
output: boolean;
|
|
78
115
|
meta: object;
|
|
79
116
|
}>;
|
|
80
|
-
|
|
117
|
+
uploadFiles: import("@trpc/server").TRPCMutationProcedure<{
|
|
81
118
|
input: {
|
|
82
|
-
|
|
119
|
+
id: string;
|
|
120
|
+
files: {
|
|
121
|
+
filename: string;
|
|
122
|
+
contentType: string;
|
|
123
|
+
size: number;
|
|
124
|
+
}[];
|
|
83
125
|
};
|
|
84
|
-
output:
|
|
126
|
+
output: {
|
|
127
|
+
fileId: string;
|
|
128
|
+
uploadUrl: string;
|
|
129
|
+
}[];
|
|
85
130
|
meta: object;
|
|
86
131
|
}>;
|
|
87
|
-
|
|
132
|
+
deleteFiles: import("@trpc/server").TRPCMutationProcedure<{
|
|
88
133
|
input: {
|
|
89
|
-
fileId: string;
|
|
134
|
+
fileId: string[];
|
|
135
|
+
id: string;
|
|
90
136
|
};
|
|
91
|
-
output:
|
|
137
|
+
output: import(".prisma/client").Prisma.BatchPayload;
|
|
92
138
|
meta: object;
|
|
93
139
|
}>;
|
|
94
140
|
}>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_app.d.ts","sourceRoot":"","sources":["../../src/routers/_app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAKrE,eAAO,MAAM,SAAS
|
|
1
|
+
{"version":3,"file":"_app.d.ts","sourceRoot":"","sources":["../../src/routers/_app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAKrE,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGpB,CAAC;AAGH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC;AACzC,MAAM,MAAM,YAAY,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;AACxD,MAAM,MAAM,aAAa,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/routers/auth.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const auth: import("@trpc/server").TRPCBuiltRouter<{
|
|
2
2
|
ctx: {
|
|
3
|
-
db: import("
|
|
3
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
4
4
|
session: any;
|
|
5
5
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
6
6
|
res: import("express").Response<any, Record<string, any>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const workspace: import("@trpc/server").TRPCBuiltRouter<{
|
|
2
2
|
ctx: {
|
|
3
|
-
db: import("
|
|
3
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
4
4
|
session: any;
|
|
5
5
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
6
6
|
res: import("express").Response<any, Record<string, any>>;
|
|
@@ -11,47 +11,93 @@ export declare const workspace: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
11
11
|
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
12
12
|
list: import("@trpc/server").TRPCQueryProcedure<{
|
|
13
13
|
input: void;
|
|
14
|
-
output:
|
|
14
|
+
output: {
|
|
15
|
+
id: string;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
ownerId: string;
|
|
19
|
+
title: string;
|
|
20
|
+
description: string | null;
|
|
21
|
+
folderId: string | null;
|
|
22
|
+
}[];
|
|
15
23
|
meta: object;
|
|
16
24
|
}>;
|
|
17
25
|
create: import("@trpc/server").TRPCMutationProcedure<{
|
|
18
|
-
input:
|
|
19
|
-
|
|
26
|
+
input: {
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string | undefined;
|
|
29
|
+
};
|
|
30
|
+
output: {
|
|
31
|
+
id: string;
|
|
32
|
+
createdAt: Date;
|
|
33
|
+
updatedAt: Date;
|
|
34
|
+
ownerId: string;
|
|
35
|
+
title: string;
|
|
36
|
+
description: string | null;
|
|
37
|
+
folderId: string | null;
|
|
38
|
+
};
|
|
20
39
|
meta: object;
|
|
21
40
|
}>;
|
|
22
41
|
get: import("@trpc/server").TRPCQueryProcedure<{
|
|
23
42
|
input: {
|
|
24
43
|
id: string;
|
|
25
44
|
};
|
|
26
|
-
output:
|
|
45
|
+
output: {
|
|
46
|
+
id: string;
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
updatedAt: Date;
|
|
49
|
+
ownerId: string;
|
|
50
|
+
title: string;
|
|
51
|
+
description: string | null;
|
|
52
|
+
folderId: string | null;
|
|
53
|
+
} | null;
|
|
27
54
|
meta: object;
|
|
28
55
|
}>;
|
|
29
56
|
update: import("@trpc/server").TRPCMutationProcedure<{
|
|
30
57
|
input: {
|
|
31
58
|
id: string;
|
|
59
|
+
name?: string | undefined;
|
|
60
|
+
description?: string | undefined;
|
|
61
|
+
};
|
|
62
|
+
output: {
|
|
63
|
+
id: string;
|
|
64
|
+
createdAt: Date;
|
|
65
|
+
updatedAt: Date;
|
|
66
|
+
ownerId: string;
|
|
67
|
+
title: string;
|
|
68
|
+
description: string | null;
|
|
69
|
+
folderId: string | null;
|
|
32
70
|
};
|
|
33
|
-
output: void;
|
|
34
71
|
meta: object;
|
|
35
72
|
}>;
|
|
36
73
|
delete: import("@trpc/server").TRPCMutationProcedure<{
|
|
37
74
|
input: {
|
|
38
75
|
id: string;
|
|
39
76
|
};
|
|
40
|
-
output:
|
|
77
|
+
output: boolean;
|
|
41
78
|
meta: object;
|
|
42
79
|
}>;
|
|
43
|
-
|
|
80
|
+
uploadFiles: import("@trpc/server").TRPCMutationProcedure<{
|
|
44
81
|
input: {
|
|
45
|
-
|
|
82
|
+
id: string;
|
|
83
|
+
files: {
|
|
84
|
+
filename: string;
|
|
85
|
+
contentType: string;
|
|
86
|
+
size: number;
|
|
87
|
+
}[];
|
|
46
88
|
};
|
|
47
|
-
output:
|
|
89
|
+
output: {
|
|
90
|
+
fileId: string;
|
|
91
|
+
uploadUrl: string;
|
|
92
|
+
}[];
|
|
48
93
|
meta: object;
|
|
49
94
|
}>;
|
|
50
|
-
|
|
95
|
+
deleteFiles: import("@trpc/server").TRPCMutationProcedure<{
|
|
51
96
|
input: {
|
|
52
|
-
fileId: string;
|
|
97
|
+
fileId: string[];
|
|
98
|
+
id: string;
|
|
53
99
|
};
|
|
54
|
-
output:
|
|
100
|
+
output: import(".prisma/client").Prisma.BatchPayload;
|
|
55
101
|
meta: object;
|
|
56
102
|
}>;
|
|
57
103
|
}>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/routers/workspace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/routers/workspace.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuJpB,CAAC"}
|
|
@@ -3,43 +3,145 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.workspace = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const trpc_1 = require("../trpc");
|
|
6
|
+
const storage_1 = require("src/lib/storage");
|
|
6
7
|
exports.workspace = (0, trpc_1.router)({
|
|
7
8
|
// Mutation with Zod input
|
|
8
9
|
list: trpc_1.publicProcedure
|
|
9
10
|
.query(async ({ ctx, input }) => {
|
|
11
|
+
const workspaces = await ctx.db.workspace.findMany({
|
|
12
|
+
where: {
|
|
13
|
+
ownerId: ctx.session?.user.id,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
return workspaces;
|
|
10
17
|
}),
|
|
11
18
|
create: trpc_1.publicProcedure
|
|
12
|
-
.input(zod_1.z.object({
|
|
13
|
-
.
|
|
19
|
+
.input(zod_1.z.object({
|
|
20
|
+
name: zod_1.z.string().min(1).max(100),
|
|
21
|
+
description: zod_1.z.string().max(500).optional(),
|
|
22
|
+
}))
|
|
23
|
+
.mutation(({ ctx, input }) => {
|
|
24
|
+
return ctx.db.workspace.create({
|
|
25
|
+
data: {
|
|
26
|
+
title: input.name,
|
|
27
|
+
description: input.description,
|
|
28
|
+
ownerId: ctx.session?.user.id,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
14
31
|
}),
|
|
15
32
|
get: trpc_1.publicProcedure
|
|
16
33
|
.input(zod_1.z.object({
|
|
17
34
|
id: zod_1.z.string().uuid(),
|
|
18
35
|
}))
|
|
19
|
-
.query(({ input }) => {
|
|
36
|
+
.query(({ ctx, input }) => {
|
|
37
|
+
return ctx.db.workspace.findUnique({
|
|
38
|
+
where: {
|
|
39
|
+
id: input.id,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
20
42
|
}),
|
|
21
43
|
update: trpc_1.publicProcedure
|
|
22
44
|
.input(zod_1.z.object({
|
|
23
45
|
id: zod_1.z.string().uuid(),
|
|
46
|
+
name: zod_1.z.string().min(1).max(100).optional(),
|
|
47
|
+
description: zod_1.z.string().max(500).optional(),
|
|
24
48
|
}))
|
|
25
|
-
.mutation(({ input }) => {
|
|
49
|
+
.mutation(({ ctx, input }) => {
|
|
50
|
+
return ctx.db.workspace.update({
|
|
51
|
+
where: {
|
|
52
|
+
id: input.id,
|
|
53
|
+
},
|
|
54
|
+
data: {
|
|
55
|
+
title: input.name,
|
|
56
|
+
description: input.description,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
26
59
|
}),
|
|
27
60
|
delete: trpc_1.publicProcedure
|
|
28
61
|
.input(zod_1.z.object({
|
|
29
62
|
id: zod_1.z.string().uuid(),
|
|
30
63
|
}))
|
|
31
|
-
.mutation(({ input }) => {
|
|
64
|
+
.mutation(({ ctx, input }) => {
|
|
65
|
+
ctx.db.workspace.delete({
|
|
66
|
+
where: {
|
|
67
|
+
id: input.id,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
return true;
|
|
32
71
|
}),
|
|
33
|
-
|
|
72
|
+
uploadFiles: trpc_1.publicProcedure
|
|
34
73
|
.input(zod_1.z.object({
|
|
35
|
-
|
|
74
|
+
id: zod_1.z.string().uuid(),
|
|
75
|
+
files: zod_1.z.array(zod_1.z.object({
|
|
76
|
+
filename: zod_1.z.string().min(1).max(255),
|
|
77
|
+
contentType: zod_1.z.string().min(1).max(100),
|
|
78
|
+
size: zod_1.z.number().min(1), // size in bytes
|
|
79
|
+
})),
|
|
36
80
|
}))
|
|
37
|
-
.mutation(({ input }) => {
|
|
81
|
+
.mutation(async ({ ctx, input }) => {
|
|
82
|
+
const results = [];
|
|
83
|
+
for (const file of input.files) {
|
|
84
|
+
// 1. Insert into DB
|
|
85
|
+
const record = await ctx.db.fileAsset.create({
|
|
86
|
+
data: {
|
|
87
|
+
userId: ctx.session.user.id,
|
|
88
|
+
name: file.filename,
|
|
89
|
+
mimeType: file.contentType,
|
|
90
|
+
size: file.size,
|
|
91
|
+
workspaceId: input.id,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
// 2. Generate signed URL for direct upload
|
|
95
|
+
const [url] = await storage_1.bucket
|
|
96
|
+
.file(`${ctx.session.user.id}/${record.id}-${file.filename}`)
|
|
97
|
+
.getSignedUrl({
|
|
98
|
+
action: "write",
|
|
99
|
+
expires: Date.now() + 5 * 60 * 1000, // 5 min
|
|
100
|
+
contentType: file.contentType,
|
|
101
|
+
});
|
|
102
|
+
// 3. Update record with bucket info
|
|
103
|
+
await ctx.db.fileAsset.update({
|
|
104
|
+
where: { id: record.id },
|
|
105
|
+
data: {
|
|
106
|
+
bucket: storage_1.bucket.name,
|
|
107
|
+
objectKey: `${ctx.session.user.id}/${record.id}-${file.filename}`,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
results.push({
|
|
111
|
+
fileId: record.id,
|
|
112
|
+
uploadUrl: url,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return results;
|
|
38
116
|
}),
|
|
39
|
-
|
|
117
|
+
deleteFiles: trpc_1.publicProcedure
|
|
40
118
|
.input(zod_1.z.object({
|
|
41
|
-
fileId: zod_1.z.string().uuid(),
|
|
119
|
+
fileId: zod_1.z.array(zod_1.z.string().uuid()),
|
|
120
|
+
id: zod_1.z.string().uuid(),
|
|
42
121
|
}))
|
|
43
|
-
.mutation(({ input }) => {
|
|
122
|
+
.mutation(({ ctx, input }) => {
|
|
123
|
+
const files = ctx.db.fileAsset.findMany({
|
|
124
|
+
where: {
|
|
125
|
+
id: { in: input.fileId },
|
|
126
|
+
workspaceId: input.id,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
// Delete from GCS
|
|
130
|
+
files.then((fileRecords) => {
|
|
131
|
+
fileRecords.forEach((file) => {
|
|
132
|
+
if (file.bucket && file.objectKey) {
|
|
133
|
+
const gcsFile = storage_1.bucket.file(file.objectKey);
|
|
134
|
+
gcsFile.delete({ ignoreNotFound: true }).catch((err) => {
|
|
135
|
+
console.error(`Error deleting file ${file.objectKey} from bucket ${file.bucket}:`, err);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
return ctx.db.fileAsset.deleteMany({
|
|
141
|
+
where: {
|
|
142
|
+
id: { in: input.fileId },
|
|
143
|
+
workspaceId: input.id,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
44
146
|
}),
|
|
45
147
|
});
|
package/dist/server.js
CHANGED
|
@@ -50,7 +50,10 @@ async function main() {
|
|
|
50
50
|
const app = (0, express_1.default)();
|
|
51
51
|
// Middlewares
|
|
52
52
|
app.use((0, helmet_1.default)());
|
|
53
|
-
app.use((0, cors_1.default)({
|
|
53
|
+
app.use((0, cors_1.default)({
|
|
54
|
+
origin: "http://localhost:3000", // your Next.js dev URL
|
|
55
|
+
credentials: true, // allow cookies
|
|
56
|
+
}));
|
|
54
57
|
app.use((0, morgan_1.default)('dev'));
|
|
55
58
|
app.use((0, compression_1.default)());
|
|
56
59
|
app.use(express_1.default.json());
|
package/dist/trpc.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const router: import("@trpc/server").TRPCRouterBuilder<{
|
|
2
2
|
ctx: {
|
|
3
|
-
db: import("
|
|
3
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
4
4
|
session: any;
|
|
5
5
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
6
6
|
res: import("express").Response<any, Record<string, any>>;
|
|
@@ -10,32 +10,32 @@ export declare const router: import("@trpc/server").TRPCRouterBuilder<{
|
|
|
10
10
|
transformer: true;
|
|
11
11
|
}>;
|
|
12
12
|
export declare const middleware: <$ContextOverrides>(fn: import("@trpc/server").TRPCMiddlewareFunction<{
|
|
13
|
-
db: import("
|
|
13
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
14
14
|
session: any;
|
|
15
15
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
16
16
|
res: import("express").Response<any, Record<string, any>>;
|
|
17
17
|
}, object, object, $ContextOverrides, unknown>) => import("@trpc/server").TRPCMiddlewareBuilder<{
|
|
18
|
-
db: import("
|
|
18
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
19
19
|
session: any;
|
|
20
20
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
21
21
|
res: import("express").Response<any, Record<string, any>>;
|
|
22
22
|
}, object, $ContextOverrides, unknown>;
|
|
23
23
|
export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilder<{
|
|
24
|
-
db: import("
|
|
24
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
25
25
|
session: any;
|
|
26
26
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
27
27
|
res: import("express").Response<any, Record<string, any>>;
|
|
28
28
|
}, object, object, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
|
|
29
29
|
/** Exported authed procedure */
|
|
30
30
|
export declare const authedProcedure: import("@trpc/server").TRPCProcedureBuilder<{
|
|
31
|
-
db: import("
|
|
31
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
32
32
|
session: any;
|
|
33
33
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
34
34
|
res: import("express").Response<any, Record<string, any>>;
|
|
35
35
|
}, object, {
|
|
36
36
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
37
37
|
res: import("express").Response<any, Record<string, any>>;
|
|
38
|
-
db: import("
|
|
38
|
+
db: import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
39
39
|
session: any;
|
|
40
40
|
}, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
|
|
41
41
|
//# sourceMappingURL=trpc.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goscribe/server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
9
10
|
"types": "./dist/index.d.ts",
|
|
@@ -12,14 +13,15 @@
|
|
|
12
13
|
},
|
|
13
14
|
"scripts": {
|
|
14
15
|
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
|
|
15
|
-
"build": "tsc -p .",
|
|
16
|
-
"start": "node dist/server.js"
|
|
16
|
+
"build": "npx prisma generate && tsc -p .",
|
|
17
|
+
"start": "node --experimental-specifier-resolution=node dist/server.js"
|
|
17
18
|
},
|
|
18
19
|
"author": "",
|
|
19
20
|
"license": "MIT",
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"@auth/express": "^0.11.0",
|
|
22
23
|
"@auth/prisma-adapter": "^2.10.0",
|
|
24
|
+
"@google-cloud/storage": "^7.17.0",
|
|
23
25
|
"@prisma/client": "^6.14.0",
|
|
24
26
|
"@trpc/server": "^11.5.0",
|
|
25
27
|
"bcryptjs": "^3.0.2",
|
|
@@ -40,6 +42,9 @@
|
|
|
40
42
|
"@types/node": "^24.3.0",
|
|
41
43
|
"ts-node": "^10.9.2",
|
|
42
44
|
"ts-node-dev": "^2.0.0",
|
|
43
|
-
"
|
|
45
|
+
"tsc-alias": "^1.8.16",
|
|
46
|
+
"tsc-esm-fix": "^3.1.2",
|
|
47
|
+
"typescript": "^5.9.2",
|
|
48
|
+
"typescript-transform-paths": "^3.5.5"
|
|
44
49
|
}
|
|
45
50
|
}
|
package/prisma/schema.prisma
CHANGED
package/src/context.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/server/trpc/context.ts
|
|
2
2
|
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express";
|
|
3
|
-
import { prisma } from "./lib/prisma";
|
|
3
|
+
import { prisma } from "./lib/prisma.js";
|
|
4
4
|
|
|
5
5
|
export async function createContext({ req, res }: CreateExpressContextOptions) {
|
|
6
6
|
const session = (req as any).auth ?? null;
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { AppRouter } from "./routers/_app";
|
|
2
|
-
export type { RouterInputs } from "./routers/_app";
|
|
3
|
-
export type { RouterOutputs } from "./routers/_app";
|
|
1
|
+
export type { AppRouter } from "./routers/_app.js";
|
|
2
|
+
export type { RouterInputs } from "./routers/_app.js";
|
|
3
|
+
export type { RouterOutputs } from "./routers/_app.js";
|
package/src/lib/auth.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/server/auth.ts
|
|
2
2
|
import { ExpressAuth } from "@auth/express";
|
|
3
3
|
import { PrismaAdapter } from "@auth/prisma-adapter";
|
|
4
|
-
import { prisma } from "../lib/prisma";
|
|
4
|
+
import { prisma } from "../lib/prisma.js";
|
|
5
5
|
import Google from "@auth/core/providers/google";
|
|
6
6
|
import Credentials from "@auth/core/providers/credentials";
|
|
7
7
|
|
package/src/lib/prisma.ts
CHANGED
package/src/routers/_app.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
2
|
-
import { router } from '../trpc';
|
|
3
|
-
import { auth } from './auth';
|
|
4
|
-
import { workspace } from './workspace';
|
|
2
|
+
import { router } from '../trpc.js';
|
|
3
|
+
import { auth } from './auth.js';
|
|
4
|
+
import { workspace } from './workspace.js';
|
|
5
5
|
|
|
6
6
|
export const appRouter = router({
|
|
7
7
|
auth,
|
package/src/routers/auth.ts
CHANGED
package/src/routers/workspace.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { router, publicProcedure, authedProcedure } from '../trpc';
|
|
3
|
-
import { bucket } from '
|
|
2
|
+
import { router, publicProcedure, authedProcedure } from '../trpc.js';
|
|
3
|
+
import { bucket } from '../lib/storage.js';
|
|
4
|
+
import { FileAsset } from '@prisma/client';
|
|
4
5
|
|
|
5
6
|
export const workspace = router({
|
|
6
7
|
// Mutation with Zod input
|
|
@@ -135,13 +136,13 @@ export const workspace = router({
|
|
|
135
136
|
});
|
|
136
137
|
|
|
137
138
|
// Delete from GCS
|
|
138
|
-
files.then((fileRecords) => {
|
|
139
|
-
fileRecords.forEach((file) => {
|
|
139
|
+
files.then((fileRecords: FileAsset[]) => {
|
|
140
|
+
fileRecords.forEach((file: FileAsset) => {
|
|
140
141
|
if (file.bucket && file.objectKey) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
const gcsFile: import('@google-cloud/storage').File = bucket.file(file.objectKey);
|
|
143
|
+
gcsFile.delete({ ignoreNotFound: true }).catch((err: unknown) => {
|
|
144
|
+
console.error(`Error deleting file ${file.objectKey} from bucket ${file.bucket}:`, err);
|
|
145
|
+
});
|
|
145
146
|
}
|
|
146
147
|
});
|
|
147
148
|
});
|
package/src/server.ts
CHANGED
|
@@ -4,10 +4,10 @@ import helmet from 'helmet';
|
|
|
4
4
|
import morgan from 'morgan';
|
|
5
5
|
import compression from 'compression';
|
|
6
6
|
import * as trpcExpress from '@trpc/server/adapters/express';
|
|
7
|
-
import { authRouter } from './lib/auth';
|
|
7
|
+
import { authRouter } from './lib/auth.js';
|
|
8
8
|
|
|
9
|
-
import { appRouter } from './routers/_app';
|
|
10
|
-
import { createContext } from './context';
|
|
9
|
+
import { appRouter } from './routers/_app.js';
|
|
10
|
+
import { createContext } from './context.js';
|
|
11
11
|
|
|
12
12
|
const PORT = process.env.PORT ? Number(process.env.PORT) : 3001;
|
|
13
13
|
|
package/src/trpc.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2020",
|
|
4
|
-
"module": "
|
|
5
|
-
"moduleResolution": "
|
|
4
|
+
"module": "ES2020", // <-- this ensures ESM output
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"plugins": [
|
|
7
|
+
{ "transform": "typescript-transform-paths" },
|
|
8
|
+
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
|
|
9
|
+
|
|
10
|
+
],
|
|
11
|
+
"baseUrl": "./",
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationDir": "dist", // optional, but keeps .d.ts in dist
|
|
14
|
+
"emitDeclarationOnly": false, // unless you only want .d.ts
|
|
15
|
+
"noEmit": false, // must not be true
|
|
16
|
+
|
|
6
17
|
"esModuleInterop": true,
|
|
7
18
|
"strict": true,
|
|
8
19
|
"skipLibCheck": true,
|
|
9
|
-
"
|
|
10
|
-
"outDir": "dist",
|
|
11
|
-
"baseUrl": ".",
|
|
12
|
-
"declaration": true,
|
|
13
|
-
"declarationMap": true
|
|
20
|
+
"outDir": "dist"
|
|
14
21
|
},
|
|
15
|
-
"include": ["src
|
|
16
|
-
"exclude": ["node_modules", "dist"]
|
|
17
|
-
}
|
|
22
|
+
"include": ["src"],
|
|
23
|
+
"exclude": ["node_modules", "dist" ]
|
|
24
|
+
}
|