@trenskow/app 0.5.6 → 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.
- package/lib/application.js +10 -9
- package/lib/endpoint.js +14 -6
- package/package.json +1 -1
package/lib/application.js
CHANGED
|
@@ -256,7 +256,7 @@ export default class Application extends EventEmitter {
|
|
|
256
256
|
({ error, brutally } = error);
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
if (!['completed', 'aborted'].includes(state)) {
|
|
259
|
+
if (!['completed', 'aborted', 'ignored'].includes(state)) {
|
|
260
260
|
state = 'aborted';
|
|
261
261
|
if (error) context.result = error;
|
|
262
262
|
}
|
|
@@ -269,6 +269,11 @@ export default class Application extends EventEmitter {
|
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
},
|
|
273
|
+
ignore: () => {
|
|
274
|
+
if (!['completed', 'aborted', 'ignored'].includes(state)) {
|
|
275
|
+
state = 'ignored';
|
|
276
|
+
}
|
|
272
277
|
}
|
|
273
278
|
|
|
274
279
|
};
|
|
@@ -321,19 +326,15 @@ export default class Application extends EventEmitter {
|
|
|
321
326
|
});
|
|
322
327
|
});
|
|
323
328
|
|
|
329
|
+
if (state === 'ignored') return;
|
|
330
|
+
|
|
324
331
|
if (context.response.statusCode === 200) {
|
|
325
|
-
context.response.statusCode = context.result ? 200 : 204;
|
|
332
|
+
context.response.statusCode = typeof context.result !== 'undefined' ? 200 : 204;
|
|
326
333
|
}
|
|
327
334
|
|
|
328
335
|
} catch (error) {
|
|
329
336
|
|
|
330
|
-
|
|
331
|
-
console.error(error.stack);
|
|
332
|
-
context.result = new ApiError.InternalError({ underlying: error });
|
|
333
|
-
} else {
|
|
334
|
-
context.result = error;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
+
context.result = error;
|
|
337
338
|
context.response.statusCode = error.statusCode ?? 500;
|
|
338
339
|
|
|
339
340
|
}
|
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] =
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
|