Skip to content

Commit

Permalink
Merge pull request #131 from ty-ras/issue/129-proper-context-for-endp…
Browse files Browse the repository at this point in the history
…oint-creation-result

#129 Application builder should return endpoint w…
  • Loading branch information
stazz authored Feb 14, 2024
2 parents ef1e6ab + 26f7849 commit f234279
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion endpoint-spec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ty-ras/endpoint-spec",
"version": "2.2.0",
"version": "2.2.1",
"author": {
"name": "Stanislav Muhametsin",
"email": "346799+stazz@users.noreply.github.com",
Expand Down
17 changes: 13 additions & 4 deletions endpoint-spec/src/__test__/endpoint-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import type * as mp from "./missing-parts";

export const validateEndpoint = async (
c: ExecutionContext,
endpoint: ep.AppEndpoint<mp.ServerContext, mp.DefaultStateInfo>,
endpoint:
| ep.AppEndpoint<never, mp.DefaultStateInfo>
| ep.AppEndpoint<mp.ServerContext, mp.DefaultStateInfo>,
getInstanceData: () => ReadonlyArray<unknown>,
prefix = "/api/something",
processFlattenedHandlerInfo: (info: Array<unknown>) => Array<unknown> = (
Expand All @@ -32,12 +34,19 @@ export const validateEndpoint = async (
) => {
c.truthy(endpoint, "Given endpoint must be of given type");

const { handler, url } = endpoint.getRegExpAndHandler("");
const finalized = endpoint.getRegExpAndHandler("") as ep.FinalizedAppEndpoint<
mp.ServerContext | never,
mp.DefaultStateInfo
>;
const { handler, url } = finalized;
c.deepEqual(
url.source,
`${ep.escapeRegExp(prefix).replaceAll("/", "\\/")}\\/(?<urlParam>[^/]+)`,
);
const methodOK = handler(
const methodOK: ep.AppEndpointHandlerGetterResult<
mp.ServerContext | never,
mp.DefaultStateInfo
> = handler(
method,
// 2nd argument is not used by these endpoints, only by the ones produced by endpoint-prefix library
{},
Expand Down Expand Up @@ -68,7 +77,7 @@ export const validateEndpoint = async (
]),
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const args: ep.AppEndpointHandlerFunctionArgs<mp.ServerContext> =
const args: ep.AppEndpointHandlerFunctionArgs<mp.ServerContext | never> =
processHandlerArgs({
context: { req: "req", res: "res" },
state: {
Expand Down
2 changes: 1 addition & 1 deletion endpoint-spec/src/api.types/app.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface ApplicationBuilderGeneric<
...endpoints: [EndpointCreationArg, ...Array<EndpointCreationArg>]
) => EndpointsCreationResult<
TMetadataProviders,
TServerContextPossible,
TServerContextArg,
dataBE.MaterializeStateInfo<
TStateHKT,
dataBE.MaterializeStateSpecBase<TStateHKT>
Expand Down

0 comments on commit f234279

Please sign in to comment.