-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#124 Adding API and implementation to specify end…
…points without decorators.
- Loading branch information
Showing
7 changed files
with
447 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @file This file contains tests for the endpoint builder using definitions in "./inline.ts" file. | ||
*/ | ||
|
||
import test from "ava"; | ||
import * as epValidation from "./endpoint-validation"; | ||
import inlineEndpoints, { SEEN_ARGS } from "./inline"; | ||
|
||
test("Test that decorator-based builder works on class with instance methods", async (c) => { | ||
c.plan(6); | ||
const { endpoints } = inlineEndpoints; | ||
c.deepEqual( | ||
endpoints.length, | ||
1, | ||
"There must be exactly one endpoint created by application builder.", | ||
); | ||
await epValidation.validateEndpoint(c, endpoints[0], () => SEEN_ARGS); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @file This file contains the inline implementation for TyRAS-powered app, without using decorators. | ||
*/ | ||
|
||
import type * as spec from ".."; | ||
import * as mp from "./missing-parts"; | ||
import * as protocol from "./protocol"; | ||
|
||
/* eslint-disable jsdoc/require-jsdoc */ | ||
|
||
export const app = mp.newBuilder({}); | ||
type StateSpecBase = spec.StateSpecBaseOfAppBuilder<typeof app>; | ||
|
||
const withURL = app.url`/something/${mp.urlParameter( | ||
"urlParam", | ||
protocol.urlParam, | ||
)}`({}); | ||
const stateSpec = { | ||
userId: false, | ||
} as const satisfies StateSpecBase; | ||
|
||
const endpoint = withURL.endpoint<protocol.SomeEndpoint>({})( | ||
{ | ||
method: "GET", | ||
responseBody: mp.responseBody(protocol.responseBody), | ||
query: mp.query({ | ||
queryParam: { | ||
decoder: protocol.queryParam, | ||
required: false, | ||
}, | ||
}), | ||
responseHeaders: mp.responseHeaders({ | ||
responseHeader: { | ||
encoder: protocol.resHeader, | ||
required: true, | ||
}, | ||
}), | ||
requestBody: app.requestBody(protocol.requestBody), | ||
state: stateSpec, | ||
}, | ||
(args) => { | ||
SEEN_ARGS.push(args); | ||
return { | ||
body: "responseBody", | ||
headers: { | ||
responseHeader: "resHeader", | ||
}, | ||
} as const; | ||
}, | ||
); | ||
|
||
export const SEEN_ARGS: Array< | ||
spec.GetMethodArgs<protocol.SomeEndpoint, typeof withURL, typeof stateSpec> | ||
> = []; | ||
|
||
export default app.createEndpoints( | ||
{}, | ||
{ | ||
"/api": endpoint, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.