@seam-rpc/server 5.1.3 → 5.2.0
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/index.d.ts +1 -4
- package/dist/index.js +19 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,6 @@ import express, { Express, NextFunction, Request, RequestHandler, Response } fro
|
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
export { ApiError };
|
|
6
6
|
export type { Result };
|
|
7
|
-
type Simplify<T> = T extends File ? File : T extends object ? {
|
|
8
|
-
[K in keyof T]: Simplify<T[K]>;
|
|
9
|
-
} : T;
|
|
10
7
|
export interface SeamContext {
|
|
11
8
|
request: Request;
|
|
12
9
|
response: Response;
|
|
@@ -31,7 +28,7 @@ export interface SeamEvents {
|
|
|
31
28
|
}
|
|
32
29
|
type ProcedureHandler<Input extends ProcedureInput, Output extends ProcedureOutput> = (options: ProcedureOptions<Input>) => Result<z.infer<Output>, ApiError<any, any>> | Promise<Result<z.infer<Output>, ApiError<any, any>>>;
|
|
33
30
|
interface ProcedureOptions<Input extends ProcedureInput> {
|
|
34
|
-
input:
|
|
31
|
+
input: ProcedureInputData<Input>;
|
|
35
32
|
ctx: SeamContext;
|
|
36
33
|
}
|
|
37
34
|
type ProcedureInput = Record<string, z.ZodType>;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extractFiles, injectFiles, ApiError } from "@seam-rpc/core";
|
|
1
|
+
import { extractFiles, injectFiles, extractDates, injectDates, ApiError } from "@seam-rpc/core";
|
|
2
2
|
import EventEmitter from "events";
|
|
3
3
|
import express, { Router } from "express";
|
|
4
4
|
import FormData from "form-data";
|
|
@@ -42,7 +42,10 @@ function createProcedureBuilder(definition = {}) {
|
|
|
42
42
|
function defineSeamRouter(seamSpace, path, seamRouterBuilder) {
|
|
43
43
|
const router = Router();
|
|
44
44
|
router.post("/:procName", async (req, res, next) => {
|
|
45
|
-
const
|
|
45
|
+
const procedureBuilder = seamRouterBuilder[req.params.procName];
|
|
46
|
+
if (!procedureBuilder)
|
|
47
|
+
return res.sendStatus(404);
|
|
48
|
+
const procedure = procedureBuilder._def;
|
|
46
49
|
if (!procedure || !procedure.handler)
|
|
47
50
|
return res.sendStatus(404);
|
|
48
51
|
let input;
|
|
@@ -139,16 +142,19 @@ function defineSeamRouter(seamSpace, path, seamRouterBuilder) {
|
|
|
139
142
|
return;
|
|
140
143
|
}
|
|
141
144
|
try {
|
|
142
|
-
const { json, files, paths } = extractFiles({ result: validatedOutput });
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
const { json: jsonAfterFiles, files, paths } = extractFiles({ result: validatedOutput });
|
|
146
|
+
const { json, dates, paths: datePaths } = extractDates(jsonAfterFiles);
|
|
147
|
+
// Does not include file(s) or date(s)
|
|
148
|
+
if (files.length === 0 && dates.length === 0) {
|
|
145
149
|
res.json(json);
|
|
146
150
|
return;
|
|
147
151
|
}
|
|
148
|
-
// Includes file(s)
|
|
152
|
+
// Includes file(s) or date(s)
|
|
149
153
|
const form = new FormData();
|
|
150
154
|
form.append("json", JSON.stringify(json));
|
|
151
155
|
form.append("paths", JSON.stringify(paths));
|
|
156
|
+
form.append("datePaths", JSON.stringify(datePaths));
|
|
157
|
+
form.append("dates", JSON.stringify(dates));
|
|
152
158
|
for (let i = 0; i < files.length; i++) {
|
|
153
159
|
const file = files[i];
|
|
154
160
|
const buffer = Buffer.from(await file.arrayBuffer());
|
|
@@ -194,11 +200,18 @@ async function runMiddleware(seamSpace, req, res) {
|
|
|
194
200
|
// multipart/form-data (already checked before)
|
|
195
201
|
let input = JSON.parse(req.body.json);
|
|
196
202
|
const paths = JSON.parse(req.body.paths);
|
|
203
|
+
const datePaths = JSON.parse(req.body.datePaths || "[]");
|
|
204
|
+
const dates = JSON.parse(req.body.dates || "[]");
|
|
197
205
|
const files = (req.files ?? []).map((file, index) => ({
|
|
198
206
|
path: paths[index],
|
|
199
207
|
file: new File([file.buffer], file.originalname, { type: file.mimetype }),
|
|
200
208
|
}));
|
|
201
209
|
injectFiles(input, files);
|
|
210
|
+
const dateEntries = dates.map((dateString, index) => ({
|
|
211
|
+
path: datePaths[index],
|
|
212
|
+
dateString,
|
|
213
|
+
}));
|
|
214
|
+
injectDates(input, dateEntries);
|
|
202
215
|
return input;
|
|
203
216
|
}
|
|
204
217
|
function validateInput(input, inputSchema) {
|