@seam-rpc/client 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.js +13 -3
- package/package.json +1 -1
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
|
export { ApiError };
|
|
3
3
|
export class SeamClient {
|
|
4
4
|
constructor(baseUrl, options) {
|
|
@@ -98,6 +98,8 @@ export async function callApi(seamClient, routerName, funcName, input) {
|
|
|
98
98
|
const formData = await res.formData();
|
|
99
99
|
const jsonPart = JSON.parse(formData.get("json")?.toString() || "[]");
|
|
100
100
|
const pathsPart = JSON.parse(formData.get("paths")?.toString() || "[]");
|
|
101
|
+
const datePathsPart = JSON.parse(formData.get("datePaths")?.toString() || "[]");
|
|
102
|
+
const datesPart = JSON.parse(formData.get("dates")?.toString() || "[]");
|
|
101
103
|
const responseFiles = [];
|
|
102
104
|
for (const [key, value] of formData.entries()) {
|
|
103
105
|
if (key.startsWith("file-")) {
|
|
@@ -110,6 +112,11 @@ export async function callApi(seamClient, routerName, funcName, input) {
|
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
injectFiles(jsonPart, responseFiles);
|
|
115
|
+
const responseDates = datesPart.map((dateString, index) => ({
|
|
116
|
+
path: datePathsPart[index],
|
|
117
|
+
dateString,
|
|
118
|
+
}));
|
|
119
|
+
injectDates(jsonPart, responseDates);
|
|
113
120
|
if (seamClient.options?.middleware?.response) {
|
|
114
121
|
for (const mw of seamClient.options.middleware.response) {
|
|
115
122
|
await mw({
|
|
@@ -128,11 +135,14 @@ export async function callApi(seamClient, routerName, funcName, input) {
|
|
|
128
135
|
}
|
|
129
136
|
function buildRequest(input = {}) {
|
|
130
137
|
let req;
|
|
131
|
-
const { json, files, paths } = extractFiles(input);
|
|
132
|
-
|
|
138
|
+
const { json: jsonAfterFiles, files, paths } = extractFiles(input);
|
|
139
|
+
const { json, dates, paths: datePaths } = extractDates(jsonAfterFiles);
|
|
140
|
+
if (files.length > 0 || dates.length > 0) {
|
|
133
141
|
const formData = new FormData();
|
|
134
142
|
formData.append("json", JSON.stringify(json));
|
|
135
143
|
formData.append("paths", JSON.stringify(paths));
|
|
144
|
+
formData.append("datePaths", JSON.stringify(datePaths));
|
|
145
|
+
formData.append("dates", JSON.stringify(dates));
|
|
136
146
|
for (let i = 0; i < files.length; i++) {
|
|
137
147
|
const file = files[i];
|
|
138
148
|
formData.append(`file-${i}`, file, file.name || `file-${i}`);
|