@trenskow/app 0.5.9 → 0.5.10

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.
Files changed (2) hide show
  1. package/lib/endpoint.js +14 -6
  2. package/package.json +1 -1
package/lib/endpoint.js CHANGED
@@ -121,6 +121,10 @@ export default class Endpoint extends Router {
121
121
 
122
122
  endpoint = resolveInlineImport(endpoint);
123
123
 
124
+ if (typeof transform !== 'undefined' && typeof transform !== 'function') {
125
+ throw new Error('Transforms must be a function.');
126
+ }
127
+
124
128
  if (!(endpoint instanceof Endpoint)) {
125
129
  throw new Error('Endpoints must be of type Endpoint');
126
130
  }
@@ -233,12 +237,16 @@ export default class Endpoint extends Router {
233
237
 
234
238
  if (!component) return await path.popped(next);
235
239
 
236
- context.parameters[layer.name] = await layer.transform?.(
237
- Object.fromEntries([
238
- [ 'context', context ],
239
- [ layer.name, component ]
240
- ])
241
- ) || component;
240
+ context.parameters[layer.name] = component;
241
+
242
+ if (typeof layer.transform === 'function') {
243
+ context.parameters[layer.name] = await layer.transform(
244
+ Object.fromEntries([
245
+ [ 'context', context ],
246
+ [ layer.name, component ]
247
+ ])
248
+ );
249
+ }
242
250
 
243
251
  return await layer.endpoint._route(path, context, next);
244
252
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/app",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "A small HTTP router.",
5
5
  "type": "module",
6
6
  "main": "index.js",