Skip to content

Commit f234279

Browse files
authored
Merge pull request #131 from ty-ras/issue/129-proper-context-for-endpoint-creation-result
#129 Application builder should return endpoint w…
2 parents ef1e6ab + 26f7849 commit f234279

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

endpoint-spec/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ty-ras/endpoint-spec",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"author": {
55
"name": "Stanislav Muhametsin",
66
"email": "[email protected]",

endpoint-spec/src/__test__/endpoint-validation.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import type * as mp from "./missing-parts";
1111

1212
export const validateEndpoint = async (
1313
c: ExecutionContext,
14-
endpoint: ep.AppEndpoint<mp.ServerContext, mp.DefaultStateInfo>,
14+
endpoint:
15+
| ep.AppEndpoint<never, mp.DefaultStateInfo>
16+
| ep.AppEndpoint<mp.ServerContext, mp.DefaultStateInfo>,
1517
getInstanceData: () => ReadonlyArray<unknown>,
1618
prefix = "/api/something",
1719
processFlattenedHandlerInfo: (info: Array<unknown>) => Array<unknown> = (
@@ -32,12 +34,19 @@ export const validateEndpoint = async (
3234
) => {
3335
c.truthy(endpoint, "Given endpoint must be of given type");
3436

35-
const { handler, url } = endpoint.getRegExpAndHandler("");
37+
const finalized = endpoint.getRegExpAndHandler("") as ep.FinalizedAppEndpoint<
38+
mp.ServerContext | never,
39+
mp.DefaultStateInfo
40+
>;
41+
const { handler, url } = finalized;
3642
c.deepEqual(
3743
url.source,
3844
`${ep.escapeRegExp(prefix).replaceAll("/", "\\/")}\\/(?<urlParam>[^/]+)`,
3945
);
40-
const methodOK = handler(
46+
const methodOK: ep.AppEndpointHandlerGetterResult<
47+
mp.ServerContext | never,
48+
mp.DefaultStateInfo
49+
> = handler(
4150
method,
4251
// 2nd argument is not used by these endpoints, only by the ones produced by endpoint-prefix library
4352
{},
@@ -68,7 +77,7 @@ export const validateEndpoint = async (
6877
]),
6978
);
7079
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
71-
const args: ep.AppEndpointHandlerFunctionArgs<mp.ServerContext> =
80+
const args: ep.AppEndpointHandlerFunctionArgs<mp.ServerContext | never> =
7281
processHandlerArgs({
7382
context: { req: "req", res: "res" },
7483
state: {

endpoint-spec/src/api.types/app.types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface ApplicationBuilderGeneric<
9090
...endpoints: [EndpointCreationArg, ...Array<EndpointCreationArg>]
9191
) => EndpointsCreationResult<
9292
TMetadataProviders,
93-
TServerContextPossible,
93+
TServerContextArg,
9494
dataBE.MaterializeStateInfo<
9595
TStateHKT,
9696
dataBE.MaterializeStateSpecBase<TStateHKT>

0 commit comments

Comments
 (0)