@emeryld/rrroutes-server 2.6.2 → 2.6.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/index.js CHANGED
@@ -872,28 +872,36 @@ function batchLeaf(server, path, registry, options) {
872
872
  const body = req.body;
873
873
  if (!isPlainObject2(body)) {
874
874
  throw new Error(
875
- "Batch request body must be a plain object keyed by encoded route identifiers."
875
+ "Batch request body must be a plain object keyed by branch aliases."
876
876
  );
877
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);
878
+ const entries = Object.entries(body);
879
+ const outputEntries = await Promise.all(
880
+ entries.map(async ([alias, value]) => {
881
+ const payload = isPlainObject2(value) ? value : {};
882
+ if (typeof payload.encodedLeaf !== "string" || payload.encodedLeaf.length === 0) {
883
+ throw new Error(
884
+ `Batch entry "${alias}" must include a non-empty "encodedLeaf" string.`
885
+ );
886
+ }
887
+ const decodedKey = decodeURIComponent(payload.encodedLeaf);
888
+ const leaf = registry.byKey[decodedKey];
889
+ if (!leaf) {
890
+ throw new Error(`Unknown batch route key: ${decodedKey}`);
891
+ }
892
+ const result = await server.invoke(decodedKey, {
893
+ req,
894
+ res,
895
+ next,
896
+ params: payload.params,
897
+ query: payload.query,
898
+ body: payload.body,
899
+ bodyFiles: payload.bodyFiles
900
+ });
901
+ return [alias, result];
902
+ })
903
+ );
904
+ res.json(Object.fromEntries(outputEntries));
897
905
  } catch (err) {
898
906
  next(err);
899
907
  }