@emeryld/rrroutes-server 2.6.2 → 2.6.4
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/README.md +9 -7
- package/dist/index.cjs +60 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -49
- package/dist/index.js.map +1 -1
- package/dist/routesV3.server.batch.d.ts +27 -0
- package/dist/routesV3.server.d.ts +1 -21
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -192,6 +192,62 @@ var createRequestSanitizationMiddleware = (options = {}) => {
|
|
|
192
192
|
};
|
|
193
193
|
var requestSanitizationMiddleware = createRequestSanitizationMiddleware();
|
|
194
194
|
|
|
195
|
+
// src/routesV3.server.batch.ts
|
|
196
|
+
var isPlainObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
197
|
+
function batchLeaf(server, path, registry, options) {
|
|
198
|
+
const method = String(options?.method ?? "post").toLowerCase();
|
|
199
|
+
const allowedMethods = ["get", "post", "put", "patch", "delete"];
|
|
200
|
+
if (!allowedMethods.includes(method)) {
|
|
201
|
+
throw new Error(
|
|
202
|
+
`Invalid batch method "${String(options?.method)}". Expected one of: ${allowedMethods.join(", ")}.`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
;
|
|
206
|
+
server.router[method](
|
|
207
|
+
path,
|
|
208
|
+
async (req, res, next) => {
|
|
209
|
+
try {
|
|
210
|
+
const body = req.body;
|
|
211
|
+
if (!isPlainObject2(body)) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
"Batch request body must be a plain object keyed by branch aliases."
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
const entries = Object.entries(body);
|
|
217
|
+
const outputEntries = await Promise.all(
|
|
218
|
+
entries.map(async ([alias, value]) => {
|
|
219
|
+
const payload = isPlainObject2(value) ? value : {};
|
|
220
|
+
if (typeof payload.encodedLeaf !== "string" || payload.encodedLeaf.length === 0) {
|
|
221
|
+
throw new Error(
|
|
222
|
+
`Batch entry "${alias}" must include a non-empty "encodedLeaf" string.`
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
const decodedKey = decodeURIComponent(payload.encodedLeaf);
|
|
226
|
+
const leaf = registry.byKey[decodedKey];
|
|
227
|
+
if (!leaf) {
|
|
228
|
+
throw new Error(`Unknown batch route key: ${decodedKey}`);
|
|
229
|
+
}
|
|
230
|
+
const result = await server.invoke(decodedKey, {
|
|
231
|
+
req,
|
|
232
|
+
res,
|
|
233
|
+
next,
|
|
234
|
+
params: payload.params,
|
|
235
|
+
query: payload.query,
|
|
236
|
+
body: payload.body,
|
|
237
|
+
bodyFiles: payload.bodyFiles
|
|
238
|
+
});
|
|
239
|
+
return [alias, result];
|
|
240
|
+
})
|
|
241
|
+
);
|
|
242
|
+
res.json(Object.fromEntries(outputEntries));
|
|
243
|
+
} catch (err) {
|
|
244
|
+
next(err);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
return server.router;
|
|
249
|
+
}
|
|
250
|
+
|
|
195
251
|
// src/routesV3.server.ts
|
|
196
252
|
var serverDebugEventTypes = [
|
|
197
253
|
"register",
|
|
@@ -226,12 +282,12 @@ function createServerDebugEmitter(option) {
|
|
|
226
282
|
}
|
|
227
283
|
return disabled;
|
|
228
284
|
}
|
|
229
|
-
var
|
|
285
|
+
var isPlainObject3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
230
286
|
var decodeJsonLikeQueryValue = (value) => {
|
|
231
287
|
if (Array.isArray(value)) {
|
|
232
288
|
return value.map((entry) => decodeJsonLikeQueryValue(entry));
|
|
233
289
|
}
|
|
234
|
-
if (
|
|
290
|
+
if (isPlainObject3(value)) {
|
|
235
291
|
const next = {};
|
|
236
292
|
for (const [key, child] of Object.entries(value)) {
|
|
237
293
|
next[key] = decodeJsonLikeQueryValue(child);
|
|
@@ -255,7 +311,7 @@ var REQUEST_PAYLOAD_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
|
255
311
|
"typedLeaves.requestPayload"
|
|
256
312
|
);
|
|
257
313
|
function isMulterFile(value) {
|
|
258
|
-
if (!
|
|
314
|
+
if (!isPlainObject3(value)) return false;
|
|
259
315
|
const candidate = value;
|
|
260
316
|
return typeof candidate.fieldname === "string";
|
|
261
317
|
}
|
|
@@ -271,7 +327,7 @@ function collectMulterFiles(req) {
|
|
|
271
327
|
files.push(value);
|
|
272
328
|
return;
|
|
273
329
|
}
|
|
274
|
-
if (
|
|
330
|
+
if (isPlainObject3(value)) {
|
|
275
331
|
Object.values(value).forEach(pushValue);
|
|
276
332
|
}
|
|
277
333
|
};
|
|
@@ -856,51 +912,6 @@ function bindAll(router, registry, controllers, config) {
|
|
|
856
912
|
server.registerControllers(registry, controllers);
|
|
857
913
|
return router;
|
|
858
914
|
}
|
|
859
|
-
function batchLeaf(server, path, registry, options) {
|
|
860
|
-
const method = String(options?.method ?? "post").toLowerCase();
|
|
861
|
-
const allowedMethods = ["get", "post", "put", "patch", "delete"];
|
|
862
|
-
if (!allowedMethods.includes(method)) {
|
|
863
|
-
throw new Error(
|
|
864
|
-
`Invalid batch method "${String(options?.method)}". Expected one of: ${allowedMethods.join(", ")}.`
|
|
865
|
-
);
|
|
866
|
-
}
|
|
867
|
-
;
|
|
868
|
-
server.router[method](
|
|
869
|
-
path,
|
|
870
|
-
async (req, res, next) => {
|
|
871
|
-
try {
|
|
872
|
-
const body = req.body;
|
|
873
|
-
if (!isPlainObject2(body)) {
|
|
874
|
-
throw new Error(
|
|
875
|
-
"Batch request body must be a plain object keyed by encoded route identifiers."
|
|
876
|
-
);
|
|
877
|
-
}
|
|
878
|
-
const output = {};
|
|
879
|
-
for (const [encodedKey, value] of Object.entries(body)) {
|
|
880
|
-
const decodedKey = decodeURIComponent(encodedKey);
|
|
881
|
-
const leaf = registry.byKey[decodedKey];
|
|
882
|
-
if (!leaf) {
|
|
883
|
-
throw new Error(`Unknown batch route key: ${decodedKey}`);
|
|
884
|
-
}
|
|
885
|
-
const payload = isPlainObject2(value) ? value : {};
|
|
886
|
-
output[encodedKey] = await server.invoke(decodedKey, {
|
|
887
|
-
req,
|
|
888
|
-
res,
|
|
889
|
-
next,
|
|
890
|
-
params: payload.params,
|
|
891
|
-
query: payload.query,
|
|
892
|
-
body: payload.body,
|
|
893
|
-
bodyFiles: payload.bodyFiles
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
res.json(output);
|
|
897
|
-
} catch (err) {
|
|
898
|
-
next(err);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
);
|
|
902
|
-
return server.router;
|
|
903
|
-
}
|
|
904
915
|
var defineControllers = () => (m) => m;
|
|
905
916
|
function warnMissingControllers(router, registry, logger) {
|
|
906
917
|
const registeredStore = router[REGISTERED_ROUTES_SYMBOL];
|