@seam-rpc/server 5.1.4 → 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 +15 -5
- 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";
|
|
@@ -142,16 +142,19 @@ function defineSeamRouter(seamSpace, path, seamRouterBuilder) {
|
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
144
|
try {
|
|
145
|
-
const { json, files, paths } = extractFiles({ result: validatedOutput });
|
|
146
|
-
|
|
147
|
-
|
|
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) {
|
|
148
149
|
res.json(json);
|
|
149
150
|
return;
|
|
150
151
|
}
|
|
151
|
-
// Includes file(s)
|
|
152
|
+
// Includes file(s) or date(s)
|
|
152
153
|
const form = new FormData();
|
|
153
154
|
form.append("json", JSON.stringify(json));
|
|
154
155
|
form.append("paths", JSON.stringify(paths));
|
|
156
|
+
form.append("datePaths", JSON.stringify(datePaths));
|
|
157
|
+
form.append("dates", JSON.stringify(dates));
|
|
155
158
|
for (let i = 0; i < files.length; i++) {
|
|
156
159
|
const file = files[i];
|
|
157
160
|
const buffer = Buffer.from(await file.arrayBuffer());
|
|
@@ -197,11 +200,18 @@ async function runMiddleware(seamSpace, req, res) {
|
|
|
197
200
|
// multipart/form-data (already checked before)
|
|
198
201
|
let input = JSON.parse(req.body.json);
|
|
199
202
|
const paths = JSON.parse(req.body.paths);
|
|
203
|
+
const datePaths = JSON.parse(req.body.datePaths || "[]");
|
|
204
|
+
const dates = JSON.parse(req.body.dates || "[]");
|
|
200
205
|
const files = (req.files ?? []).map((file, index) => ({
|
|
201
206
|
path: paths[index],
|
|
202
207
|
file: new File([file.buffer], file.originalname, { type: file.mimetype }),
|
|
203
208
|
}));
|
|
204
209
|
injectFiles(input, files);
|
|
210
|
+
const dateEntries = dates.map((dateString, index) => ({
|
|
211
|
+
path: datePaths[index],
|
|
212
|
+
dateString,
|
|
213
|
+
}));
|
|
214
|
+
injectDates(input, dateEntries);
|
|
205
215
|
return input;
|
|
206
216
|
}
|
|
207
217
|
function validateInput(input, inputSchema) {
|