diff --git a/src/controllers/API.ts b/src/controllers/API.ts index ae085029..3c7f5e42 100755 --- a/src/controllers/API.ts +++ b/src/controllers/API.ts @@ -106,12 +106,12 @@ export type ResultBuildingContext = QueryBuildingContext; // approach that the express typings seem to use, so I imagine it's safe enough. export type QueryTransformNoReq = { // tslint:disable-next-line callable-types - (first: RunnableQuery): RunnableQuery; + (first: RunnableQuery): RunnableQuery | Promise; }; export type QueryTransformWithReq = { // tslint:disable-next-line callable-types - (first: ServerReq, second: RunnableQuery): RunnableQuery; + (first: ServerReq, second: RunnableQuery): RunnableQuery | Promise; }; export type RequestOpts = { diff --git a/test/app/src/index.ts b/test/app/src/index.ts index 5fe0a882..f8d21c06 100755 --- a/test/app/src/index.ts +++ b/test/app/src/index.ts @@ -85,6 +85,17 @@ export default database.then(function(dbModule) { }) ); + app.get('/request-with-async-transform/:type(people)/:id(42)', + Front.customAPIRequest({ + queryTransform: (query: RunnableQuery) => + Promise.resolve( + query.resultsIn(undefined, () => ({ + document: new Document({}) + })) + ) + }) + ); + // Apply a query transform that returns a custom error app.get('/request-that-errors/:type(people)/:id(42)', Front.customAPIRequest({ diff --git a/test/integration/custom-query/index.ts b/test/integration/custom-query/index.ts index 6b76fd3a..fac68126 100644 --- a/test/integration/custom-query/index.ts +++ b/test/integration/custom-query/index.ts @@ -17,6 +17,14 @@ describe("Customizing the Query", () => { }); }); + it("should rceive an empty response from an async query transform without error", () => { + return Agent.request("GET", "/request-with-async-transform/people/42") + .accept("application/vnd.api+json") + .then((res) => { + expect(res).to.be.ok + }); + }); + it("should run the resultingIn transform to create a custom error", () => { return Agent.request("GET", "/request-that-errors/people/42") .accept("application/vnd.api+json")