Skip to content

Commit

Permalink
fix(types): fix handlers generic types ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Jan 31, 2020
1 parent c47f690 commit 2b47262
Show file tree
Hide file tree
Showing 29 changed files with 144 additions and 68 deletions.
80 changes: 58 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"cz-conventional-changelog": "^3.0.2",
"lerna": "^3.19.0",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.8.1"
"metapak-nfroidure": "9.8.2"
},
"contributors": [],
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion packages/whook-authorization/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
"jest": "^24.9.0",
"jsdoc-to-markdown": "^5.0.3",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.8.1",
"metapak-nfroidure": "9.8.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"typescript": "^3.7.5"
},
"contributors": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/whook-authorization/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function handleWithAuthorization<P extends Parameters, A, R, WR>(
authentication,
log,
}: WhookAuthorizationDependencies<A, R>,
handler: WhookHandler<WR, WhookOperation, P>,
handler: WhookHandler<P, WR, WhookOperation>,
parameters: P,
operation: WhookOperation,
): Promise<WR> {
Expand Down
3 changes: 2 additions & 1 deletion packages/whook-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@
"jest": "^24.9.0",
"jsdoc-to-markdown": "^5.0.3",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.8.1",
"metapak-nfroidure": "9.8.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"typescript": "^3.7.5"
},
"contributors": [],
Expand Down
3 changes: 2 additions & 1 deletion packages/whook-cors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
"jest": "^24.9.0",
"jsdoc-to-markdown": "^5.0.3",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.8.1",
"metapak-nfroidure": "9.8.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"typescript": "^3.7.5"
},
"contributors": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/whook-cors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function handleWithCORS<
P extends Parameters
>(
{ CORS }: CORSConfig,
handler: WhookHandler<R, O, P>,
handler: WhookHandler<P, R, O>,
parameters: P,
operation: O,
): Promise<R> {
Expand Down
3 changes: 2 additions & 1 deletion packages/whook-create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@
"jest": "^24.9.0",
"jsdoc-to-markdown": "^4.0.1",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.8.1",
"metapak-nfroidure": "9.8.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"typescript": "^3.7.5"
},
"contributors": [],
Expand Down
3 changes: 2 additions & 1 deletion packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@
"jest": "^24.9.0",
"jsdoc-to-markdown": "^4.0.1",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.8.1",
"metapak-nfroidure": "9.8.2",
"openapi-schema-validator": "^3.0.3",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"typescript": "^3.7.5"
},
"contributors": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

exports[`putEcho should fail when crossing the red line ;) 1`] = `
Object {
"errorCode": undefined,
"errorParams": undefined,
"errorCode": "E_MUST_NOT_BE_NAMED",
"errorParams": Array [
"Big up to Lord Voldemort!",
],
"logCalls": Array [
Array [
"warning",
Expand Down
11 changes: 8 additions & 3 deletions packages/whook-example/src/handlers/getDelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
WhookResponse,
WhookAPIHandlerDefinition,
WhookAPIParameterDefinition,
WhookHandlerFunction,
} from '@whook/whook';
import { DelayService } from 'common-services';

Expand Down Expand Up @@ -39,14 +40,18 @@ export const definition: WhookAPIHandlerDefinition = {
},
};

export default autoHandler(getDelay);

async function getDelay(
{ delay }: { delay: DelayService },
{
delay,
}: {
delay: DelayService;
},
{ duration }: { duration: number },
): Promise<WhookResponse<200, {}, undefined>> {
await delay.create(duration);
return {
status: 200,
};
}

export default autoHandler(getDelay);
7 changes: 5 additions & 2 deletions packages/whook-example/src/handlers/getDiagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ export const definition: WhookAPIHandlerDefinition = {

export default autoHandler(getDiagnostic);

type Transaction = {};
type Transactions = { [id: string]: Transaction };

async function getDiagnostic({
TRANSACTIONS,
}: {
TRANSACTIONS: {};
}): Promise<WhookResponse> {
TRANSACTIONS: Transactions;
}): Promise<WhookResponse<200, {}, { transactions: Transactions }>> {
return {
status: 200,
body: {
Expand Down
7 changes: 4 additions & 3 deletions packages/whook-example/src/handlers/getOpenAPI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import getOpenAPI, {
definition as baseGetOpenAPIDefinition,
} from '@whook/swagger-ui/dist/handlers/getOpenAPI';
import {
initGetOpenAPI as getOpenAPI,
getOpenAPIDefinition as baseGetOpenAPIDefinition,
} from '@whook/swagger-ui';

// TODO: Use WHOOK_PLUGINS to get handlers from plugins
// instead of proxying here
Expand Down
2 changes: 1 addition & 1 deletion packages/whook-example/src/handlers/getTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function getTime({
time,
}: {
time: TimeService;
}): Promise<WhookResponse> {
}): Promise<WhookResponse<200, {}, { time: number }>> {
return {
status: 200,
body: {
Expand Down
2 changes: 1 addition & 1 deletion packages/whook-example/src/handlers/putEcho.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('putEcho', () => {

try {
await putEcho({
body: 'Big up to Lord Voldemort!',
body: { echo: 'Big up to Lord Voldemort!' },
});
throw new YError('E_UNEXPECTED_SUCCESS');
} catch (err) {
Expand Down
9 changes: 7 additions & 2 deletions packages/whook-example/src/handlers/putEcho.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { autoHandler } from 'knifecycle';
import YHTTPError from 'yhttperror';
import { WhookAPIHandlerDefinition } from '@whook/whook';
import { WhookAPIHandlerDefinition, WhookResponse } from '@whook/whook';
import { OpenAPIV3 } from 'openapi-types';
import { LogService } from 'common-services';

Expand Down Expand Up @@ -48,7 +48,12 @@ export const definition: WhookAPIHandlerDefinition = {

export default autoHandler(putEcho);

async function putEcho({ log }: { log: LogService }, { body }) {
type Echo = { echo: string };

async function putEcho(
{ log }: { log: LogService },
{ body }: { body: Echo },
): Promise<WhookResponse<200, {}, Echo>> {
if (body.echo.includes('Voldemort')) {
throw new YHTTPError(400, 'E_MUST_NOT_BE_NAMED', body.echo);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/whook-http-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@
"jest": "^24.9.0",
"jsdoc-to-markdown": "^5.0.3",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.8.1",
"metapak-nfroidure": "9.8.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"streamtest": "^1.2.4",
"typescript": "^3.7.5"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/whook-http-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
"jest": "^24.9.0",
"jsdoc-to-markdown": "^5.0.3",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.8.1",
"metapak-nfroidure": "9.8.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"typescript": "^3.7.5"
},
"contributors": [],
Expand Down
3 changes: 2 additions & 1 deletion packages/whook-http-transaction/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@
"jsarch": "^2.0.3",
"jsdoc-to-markdown": "^5.0.3",
"metapak": "^3.1.6",
"metapak-nfroidure": "9.8.1",
"metapak-nfroidure": "9.8.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"streamtest": "^1.2.4",
"typescript": "^3.7.5",
"yerror": "^5.0.0"
Expand Down
Loading

0 comments on commit 2b47262

Please sign in to comment.