@jaypie/express 1.2.15 → 1.2.17

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/esm/index.js CHANGED
@@ -32,6 +32,21 @@ class LambdaRequest extends Readable {
32
32
  this.path = options.url.split("?")[0];
33
33
  this.headers = this.normalizeHeaders(options.headers);
34
34
  this.bodyBuffer = options.body ?? null;
35
+ // Pre-parse body: try JSON first, fall back to string.
36
+ // In Lambda the full body is already in memory, so we parse eagerly
37
+ // instead of requiring express.json() middleware. The raw stream remains
38
+ // available for consumers that need it (e.g. MCP transport).
39
+ if (this.bodyBuffer && this.bodyBuffer.length > 0) {
40
+ const text = this.bodyBuffer.toString("utf8");
41
+ try {
42
+ this.body = JSON.parse(text);
43
+ }
44
+ catch {
45
+ this.body = text;
46
+ }
47
+ // Signal to body-parser that body is already parsed (skip reading stream)
48
+ this._body = true;
49
+ }
35
50
  // Use pre-parsed query if provided, otherwise parse from URL
36
51
  if (options.query) {
37
52
  this.query = options.query;
@@ -1807,14 +1822,18 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
1807
1822
  //
1808
1823
  // Preprocess
1809
1824
  //
1825
+ // Build a request-local setup list to avoid mutating the shared array
1826
+ const requestSetup = [];
1810
1827
  // Load secrets into process.env if configured
1811
1828
  if (secrets && secrets.length > 0) {
1812
1829
  const secretsToLoad = secrets;
1813
1830
  const secretsSetup = async () => {
1814
1831
  await loadEnvSecrets(...secretsToLoad);
1815
1832
  };
1816
- setup.unshift(secretsSetup);
1833
+ requestSetup.push(secretsSetup);
1817
1834
  }
1835
+ // Add shared setup functions
1836
+ requestSetup.push(...setup);
1818
1837
  if (locals) {
1819
1838
  // Locals
1820
1839
  const keys = Object.keys(locals);
@@ -1833,7 +1852,7 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
1833
1852
  }
1834
1853
  }
1835
1854
  };
1836
- setup.push(localsSetup);
1855
+ requestSetup.push(localsSetup);
1837
1856
  }
1838
1857
  }
1839
1858
  let response;
@@ -1844,7 +1863,7 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
1844
1863
  jaypieFunction = jaypieHandler(handler, {
1845
1864
  chaos,
1846
1865
  name,
1847
- setup,
1866
+ setup: requestSetup,
1848
1867
  teardown,
1849
1868
  unavailable,
1850
1869
  validate,
@@ -2155,14 +2174,18 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2155
2174
  //
2156
2175
  // Preprocess
2157
2176
  //
2177
+ // Build a request-local setup list to avoid mutating the shared array
2178
+ const requestSetup = [];
2158
2179
  // Load secrets into process.env if configured
2159
2180
  if (secrets && secrets.length > 0) {
2160
2181
  const secretsToLoad = secrets;
2161
2182
  const secretsSetup = async () => {
2162
2183
  await loadEnvSecrets(...secretsToLoad);
2163
2184
  };
2164
- setup.unshift(secretsSetup);
2185
+ requestSetup.push(secretsSetup);
2165
2186
  }
2187
+ // Add shared setup functions
2188
+ requestSetup.push(...setup);
2166
2189
  if (locals) {
2167
2190
  const keys = Object.keys(locals);
2168
2191
  if (keys.length > 0) {
@@ -2180,7 +2203,7 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2180
2203
  }
2181
2204
  }
2182
2205
  };
2183
- setup.push(localsSetup);
2206
+ requestSetup.push(localsSetup);
2184
2207
  }
2185
2208
  }
2186
2209
  try {
@@ -2188,7 +2211,7 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2188
2211
  jaypieFunction = jaypieHandler(handler, {
2189
2212
  chaos,
2190
2213
  name,
2191
- setup,
2214
+ setup: requestSetup,
2192
2215
  teardown,
2193
2216
  unavailable,
2194
2217
  validate,