@controller-contract/server 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-DvVe6qYj.d.mts +44 -0
- package/dist/index.d.mts +181 -104
- package/dist/index.mjs +171 -113
- package/dist/utils.d.mts +2 -0
- package/dist/utils.mjs +59 -0
- package/package.json +11 -7
- package/src/classes/controller-builder/controller-builder.ts +24 -0
- package/src/classes/controller-builder/input-builder/input-builder.ts +20 -0
- package/src/classes/controller-builder/input-builder/steps/after-body-step.ts +19 -0
- package/src/classes/controller-builder/input-builder/steps/after-params-step.ts +26 -0
- package/src/classes/controller-builder/input-builder/steps/after-query-step.ts +24 -0
- package/src/classes/controller-builder/steps/endpoint-step.ts +19 -0
- package/src/classes/controller-builder/steps/input-step.ts +67 -0
- package/src/classes/controller-builder/steps/output-step.ts +70 -0
- package/src/classes/controller-router-factory.ts +31 -0
- package/src/classes/controller-router.ts +25 -0
- package/src/classes/framework-setup.ts +28 -0
- package/src/index.ts +1 -2
- package/src/interfaces/controller-blueprint.ts +34 -0
- package/src/interfaces/endable.ts +5 -0
- package/src/interfaces/index.ts +2 -0
- package/src/types/combine-routes-fn.ts +7 -0
- package/src/{classes/controller-contract-controller/controller-contract-controller.ts → types/controller.ts} +5 -5
- package/src/types/create-route-fn.ts +5 -0
- package/src/types/fail-output-from.ts +8 -0
- package/src/types/index.ts +12 -44
- package/src/types/infer-controller-contract.ts +8 -0
- package/src/types/infer-controller-contracts-from-router.ts +3 -3
- package/src/types/input-builder-fn.ts +6 -0
- package/src/types/map-to-controller-contract.ts +7 -0
- package/src/types/no-output-from-inputs.ts +1 -0
- package/src/types/output-fn-outputs.ts +4 -0
- package/src/types/output-fn.ts +23 -0
- package/src/types/prettify.ts +1 -0
- package/src/types/resolved-params.ts +8 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/outputs.ts +9 -28
- package/src/utils/root-only.ts +8 -0
- package/src/utils/standard-outputs.ts +20 -0
- package/src/classes/controller-contract-controller-builder/builder-steps/post-endpoint-step.ts +0 -48
- package/src/classes/controller-contract-controller-builder/builder-steps/post-inject-step.ts +0 -19
- package/src/classes/controller-contract-controller-builder/builder-steps/post-input-step.ts +0 -49
- package/src/classes/controller-contract-controller-builder/controller-contract-controller-builder.ts +0 -24
- package/src/classes/controller-contract-controller-router/controller-contract-controller-router-factory.ts +0 -13
- package/src/classes/controller-contract-controller-router/controller-contract-controller-router.ts +0 -16
- package/src/classes/framework-integration-factory.ts +0 -19
- package/src/interfaces/ControllerContractSpec.ts +0 -25
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ExitOutput, FailOutput, NextOutput, PassOutput } from "@controller-contract/core";
|
|
2
|
+
//#region src/utils/outputs.d.ts
|
|
3
|
+
declare const outputs: Readonly<{
|
|
4
|
+
next<T>(data: T, code?: number): NextOutput<T>;
|
|
5
|
+
pass<T>(data: T, code?: number): PassOutput<T>;
|
|
6
|
+
fail<const T extends string>(data: FailOutput<T>['data'], code?: number): FailOutput<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Used to escape the controller contract state machine, useful for redirects.
|
|
9
|
+
*/
|
|
10
|
+
exit(): ExitOutput;
|
|
11
|
+
}>;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/utils/root-only.d.ts
|
|
14
|
+
/**
|
|
15
|
+
* Useful for quickly sending a root level error to the client.
|
|
16
|
+
*/
|
|
17
|
+
declare function rootOnly(message: string): FailOutput<'root'>['data'];
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/utils/standard-outputs.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* Useful for quick http basic responses.
|
|
22
|
+
*/
|
|
23
|
+
declare const StandardOutputs: Readonly<{
|
|
24
|
+
OK: import("@controller-contract/core").PassOutput<{
|
|
25
|
+
key: "root";
|
|
26
|
+
message: string;
|
|
27
|
+
}[]>;
|
|
28
|
+
Created: import("@controller-contract/core").PassOutput<{
|
|
29
|
+
key: "root";
|
|
30
|
+
message: string;
|
|
31
|
+
}[]>;
|
|
32
|
+
Accepted: import("@controller-contract/core").PassOutput<{
|
|
33
|
+
key: "root";
|
|
34
|
+
message: string;
|
|
35
|
+
}[]>;
|
|
36
|
+
BadRequest: import("@controller-contract/core").FailOutput<"root">;
|
|
37
|
+
Unauthorized: import("@controller-contract/core").FailOutput<"root">;
|
|
38
|
+
Forbidden: import("@controller-contract/core").FailOutput<"root">;
|
|
39
|
+
NotFound: import("@controller-contract/core").FailOutput<"root">;
|
|
40
|
+
InternalServerError: import("@controller-contract/core").FailOutput<"root">;
|
|
41
|
+
BadGateway: import("@controller-contract/core").FailOutput<"root">;
|
|
42
|
+
}>;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { rootOnly as n, outputs as r, StandardOutputs as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,137 +1,214 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as outputs } from "./index-DvVe6qYj.mjs";
|
|
2
|
+
import { ControllerContract, ExitOutput, FailOutput, Method, NoInput, Output, PassOutput, PathParams } from "@controller-contract/core";
|
|
2
3
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
//#region src/
|
|
4
|
-
type
|
|
5
|
-
'~cc'?: TMethod | TPath | TParamsInput | TQueryInput | TBodyInput |
|
|
4
|
+
//#region src/types/controller.d.ts
|
|
5
|
+
type Controller<TMethod extends Method, TPath extends string, TParamsInput, TQueryInput, TBodyInput, TOutput extends Output, TFrameworkRouter> = (() => TFrameworkRouter) & {
|
|
6
|
+
'~cc'?: TMethod | TPath | TParamsInput | TQueryInput | TBodyInput | TOutput;
|
|
6
7
|
};
|
|
7
8
|
//#endregion
|
|
8
|
-
//#region src/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
//#region src/types/combine-routes-fn.d.ts
|
|
10
|
+
type CombineRoutesFn<TFrameworkRouter> = <TRoutes extends Record<any, Controller<any, any, any, any, any, any, TFrameworkRouter>>>(routes: TRoutes) => TFrameworkRouter;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/interfaces/controller-blueprint.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* The true shapes aren't needed at this level. We only need a broad description.
|
|
15
|
+
*/
|
|
16
|
+
interface ControllerBlueprintSchemas<TParams, TQuery, TBody> {
|
|
17
|
+
params: StandardSchemaV1<any, TParams> | null;
|
|
18
|
+
query: StandardSchemaV1<any, TQuery> | null;
|
|
19
|
+
body: StandardSchemaV1<any, TBody> | null;
|
|
15
20
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
type OutputFnBlueprint<TFrameworkContext> = (context: Prettify<TFrameworkContext & {
|
|
22
|
+
inputs: {
|
|
23
|
+
params: any;
|
|
24
|
+
query: any;
|
|
25
|
+
body: any;
|
|
26
|
+
};
|
|
27
|
+
outputs: OutputFnOutputs;
|
|
28
|
+
}>) => Promise<PassOutput<any> | FailOutput<any> | ExitOutput>;
|
|
29
|
+
interface ControllerBlueprint<TFrameworkContext, TFrameworkInjectable> {
|
|
30
|
+
readonly injectable: TFrameworkInjectable;
|
|
19
31
|
readonly method: Method;
|
|
20
32
|
readonly path: string;
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
23
|
-
readonly outputFn: SanitizedOutputFn<TFrameworkContext, string, unknown, Output>;
|
|
33
|
+
readonly schemas: ControllerBlueprintSchemas<unknown, unknown, unknown>;
|
|
34
|
+
readonly outputFn: OutputFnBlueprint<TFrameworkContext>;
|
|
24
35
|
}
|
|
25
|
-
type ControllerContractSpec<TFrameworkContext, TInject> = NullaryControllerContractSpec<TFrameworkContext, TInject> | SanitizedControllerContractSpec<TFrameworkContext, TInject>;
|
|
26
36
|
//#endregion
|
|
27
|
-
//#region src/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
//#region src/types/create-route-fn.d.ts
|
|
38
|
+
type CreateRouteFn<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter> = (blueprint: ControllerBlueprint<TFrameworkContext, TFrameworkInjectable>) => TFrameworkRouter;
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/types/fail-output-from.d.ts
|
|
41
|
+
/**
|
|
42
|
+
* The fail output a validated input can produce. Skipped inputs are `NoInput` and produce none.
|
|
43
|
+
*/
|
|
44
|
+
type FailOutputFrom<T> = [T] extends [NoInput] ? never : FailOutput<Extract<keyof T, string>>;
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/types/infer-controller-contract.d.ts
|
|
47
|
+
type InferControllerContract<T> = T extends Controller<infer M, infer P, any, infer Q, infer B, infer O, any> ? ControllerContract<M, P, PathParams<P>, Q, B, O> : never;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/classes/controller-router.d.ts
|
|
50
|
+
declare class ControllerRouter<TFrameworkRouter, TRoutes extends Record<any, Controller<any, any, any, any, any, any, TFrameworkRouter>>> {
|
|
51
|
+
private readonly combineRoutes;
|
|
52
|
+
private readonly routes;
|
|
53
|
+
constructor(combineRoutes: CombineRoutesFn<TFrameworkRouter>, routes: TRoutes);
|
|
32
54
|
/**
|
|
33
|
-
*
|
|
55
|
+
* @example
|
|
56
|
+
* const usersRouter = controllerRouterFactory.createControllerRouter({ getUser, createUser });
|
|
57
|
+
*
|
|
58
|
+
* const app = express();
|
|
59
|
+
* app.use(express.json());
|
|
60
|
+
* app.use(usersRouter.toRouter());
|
|
61
|
+
* app.listen(3000);
|
|
34
62
|
*/
|
|
35
|
-
|
|
63
|
+
toRouter(): TFrameworkRouter;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/types/map-to-controller-contract.d.ts
|
|
67
|
+
type MapToControllerContract<TRoutes> = { [TRouteName in Extract<keyof TRoutes, string> as Capitalize<TRouteName>]: InferControllerContract<TRoutes[TRouteName]>; };
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/types/infer-controller-contracts-from-router.d.ts
|
|
70
|
+
type InferControllerContractsFromRouter<T> = T extends ControllerRouter<any, infer TRoutes> ? MapToControllerContract<TRoutes> : never;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/interfaces/endable.d.ts
|
|
73
|
+
interface Endable<TParams, TQuery, TBody> {
|
|
74
|
+
getSchemas(): ControllerBlueprintSchemas<TParams, TQuery, TBody>;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/classes/controller-builder/input-builder/steps/after-body-step.d.ts
|
|
78
|
+
declare class AfterBodyStep<TParams, TQuery, TBody> implements Endable<TParams, TQuery, TBody> {
|
|
79
|
+
private readonly paramsSchema;
|
|
80
|
+
private readonly querySchema;
|
|
81
|
+
private readonly bodySchema;
|
|
82
|
+
constructor(paramsSchema: StandardSchemaV1<any, TParams> | null, querySchema: StandardSchemaV1<any, TQuery> | null, bodySchema: StandardSchemaV1<any, TBody>);
|
|
83
|
+
getSchemas(): ControllerBlueprintSchemas<TParams, TQuery, TBody>;
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/classes/controller-builder/input-builder/steps/after-query-step.d.ts
|
|
87
|
+
declare class AfterQueryStep<TParams, TQuery> implements Endable<TParams, TQuery, NoInput> {
|
|
88
|
+
private readonly paramsSchema;
|
|
89
|
+
private readonly querySchema;
|
|
90
|
+
constructor(paramsSchema: StandardSchemaV1<any, TParams> | null, querySchema: StandardSchemaV1<any, TQuery>);
|
|
91
|
+
body<TBody>(schema: StandardSchemaV1<any, TBody>): AfterBodyStep<TParams, TQuery, TBody>;
|
|
92
|
+
getSchemas(): ControllerBlueprintSchemas<TParams, TQuery, NoInput>;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/classes/controller-builder/input-builder/steps/after-params-step.d.ts
|
|
96
|
+
declare class AfterParamsStep<TParams> implements Endable<TParams, NoInput, NoInput> {
|
|
97
|
+
private readonly paramsSchema;
|
|
98
|
+
constructor(paramsSchema: StandardSchemaV1<any, TParams>);
|
|
99
|
+
query<TQuery>(schema: StandardSchemaV1<any, TQuery>): AfterQueryStep<TParams, TQuery>;
|
|
100
|
+
body<TBody>(schema: StandardSchemaV1<any, TBody>): AfterBodyStep<TParams, NoInput, TBody>;
|
|
101
|
+
getSchemas(): ControllerBlueprintSchemas<TParams, NoInput, NoInput>;
|
|
36
102
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
message: string;
|
|
50
|
-
}[]>;
|
|
51
|
-
BadRequest: FailOutput<"root">;
|
|
52
|
-
Unauthorized: FailOutput<"root">;
|
|
53
|
-
Forbidden: FailOutput<"root">;
|
|
54
|
-
NotFound: FailOutput<"root">;
|
|
55
|
-
InternalServerError: FailOutput<"root">;
|
|
56
|
-
BadGateway: FailOutput<"root">;
|
|
57
|
-
}>;
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/types/index.d.ts
|
|
60
|
-
type BuilderIntegratorFn<TFrameworkContext, TFrameworkInject, TFrameworkRouter> = (spec: ControllerContractSpec<TFrameworkContext, TFrameworkInject>) => TFrameworkRouter;
|
|
61
|
-
type RouterIntegratorFn<TRouter> = <TRoutes extends Record<any, ControllerContractController<any, any, any, any, any, any, TRouter>>>(routes: TRoutes) => TRouter;
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/classes/controller-builder/input-builder/input-builder.d.ts
|
|
105
|
+
declare class InputBuilder {
|
|
106
|
+
params<TParams>(schema: StandardSchemaV1<any, TParams>): AfterParamsStep<TParams>;
|
|
107
|
+
query<TQuery>(schema: StandardSchemaV1<any, TQuery>): AfterQueryStep<NoInput, TQuery>;
|
|
108
|
+
body<TBody>(schema: StandardSchemaV1<any, TBody>): AfterBodyStep<NoInput, NoInput, TBody>;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/types/input-builder-fn.d.ts
|
|
112
|
+
type InputBuilderFn<TParams, TQuery, TBody> = (inputBuilder: InputBuilder) => Endable<TParams, TQuery, TBody>;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/types/prettify.d.ts
|
|
62
115
|
type Prettify<T> = { [K in keyof T]: T[K]; } & {};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/types/output-fn-outputs.d.ts
|
|
118
|
+
type OutputFnOutputs = Prettify<Omit<typeof outputs, 'next'>>;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/types/output-fn.d.ts
|
|
121
|
+
type OutputFn<TFrameworkContext, TParams, TQuery, TBody, TOutput extends PassOutput<any> | FailOutput<any> | ExitOutput> = (context: Prettify<TFrameworkContext & {
|
|
122
|
+
inputs: {
|
|
123
|
+
params: TParams;
|
|
124
|
+
query: TQuery;
|
|
125
|
+
body: TBody;
|
|
126
|
+
};
|
|
127
|
+
outputs: OutputFnOutputs;
|
|
66
128
|
}>) => Promise<TOutput>;
|
|
67
|
-
type SanitizedOutputFn<TFrameworkContext, TPath extends string, TInput, TOutput> = OutputFn<TFrameworkContext & {
|
|
68
|
-
input: TInput;
|
|
69
|
-
}, TPath, TOutput>;
|
|
70
|
-
type InferControllerContract<T> = T extends ControllerContractController<infer M, infer P, any, infer Q, infer B, infer O, any> ? ControllerContract<M, P, ParamsFrom<P>, Q, B, O> : never;
|
|
71
|
-
type MapToControllerContract<TRoutes> = { [TRouteName in Extract<keyof TRoutes, string> as Capitalize<TRouteName>]: InferControllerContract<TRoutes[TRouteName]>; };
|
|
72
129
|
//#endregion
|
|
73
|
-
//#region src/
|
|
74
|
-
|
|
130
|
+
//#region src/types/resolved-params.d.ts
|
|
131
|
+
/**
|
|
132
|
+
* Falls back to the raw path params when no params schema was given.
|
|
133
|
+
*/
|
|
134
|
+
type ResolvedParams<TParams, TPath extends string> = [TParams] extends [NoInput] ? PathParams<TPath> : TParams;
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/classes/controller-builder/steps/output-step.d.ts
|
|
137
|
+
declare class OutputStep<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter, const TMethod extends Method, const TPath extends string, TParams, TQuery, TBody> {
|
|
75
138
|
private readonly injectable;
|
|
76
|
-
private readonly
|
|
139
|
+
private readonly createRoute;
|
|
77
140
|
private readonly method;
|
|
78
141
|
private readonly path;
|
|
79
|
-
private readonly
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
output<TOutput extends Output>(outputFn: SanitizedOutputFn<TFrameworkContext, TPath, TInput, TOutput>): ControllerContractController<TMethod, TPath, ParamsFrom<TPath>, TChannel extends 'query' ? TInput : NoInput, TChannel extends 'body' ? TInput : NoInput, TOutputFromInput | TOutput, TRouter>;
|
|
142
|
+
private readonly schemas;
|
|
143
|
+
constructor(injectable: TFrameworkInjectable, createRoute: CreateRouteFn<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter>, method: TMethod, path: TPath, schemas: ControllerBlueprintSchemas<TParams, TQuery, TBody>);
|
|
144
|
+
output<TOutput extends PassOutput<any> | FailOutput<any> | ExitOutput>(outputFn: OutputFn<TFrameworkContext, Prettify<ResolvedParams<TParams, TPath>>, TQuery, TBody, TOutput>): Controller<TMethod, TPath, Prettify<PathParams<TPath>>, TQuery, TBody, FailOutputFrom<TParams> | FailOutputFrom<TQuery> | FailOutputFrom<TBody> | TOutput, TFrameworkRouter>;
|
|
83
145
|
}
|
|
84
146
|
//#endregion
|
|
85
|
-
//#region src/classes/controller-
|
|
86
|
-
declare class
|
|
147
|
+
//#region src/classes/controller-builder/steps/input-step.d.ts
|
|
148
|
+
declare class InputStep<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter, const TMethod extends Method, const TPath extends string> {
|
|
87
149
|
private readonly injectable;
|
|
88
|
-
private readonly
|
|
150
|
+
private readonly createRoute;
|
|
89
151
|
private readonly method;
|
|
90
152
|
private readonly path;
|
|
91
|
-
constructor(injectable:
|
|
92
|
-
input<
|
|
93
|
-
output<TOutput extends
|
|
153
|
+
constructor(injectable: TFrameworkInjectable, createRoute: CreateRouteFn<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter>, method: TMethod, path: TPath);
|
|
154
|
+
input<TParams, TQuery, TBody>(inputBuilderFn: InputBuilderFn<TParams, TQuery, TBody>): OutputStep<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter, TMethod, TPath, TParams, TQuery, TBody>;
|
|
155
|
+
output<TOutput extends PassOutput<any> | FailOutput<any> | ExitOutput>(outputFn: OutputFn<TFrameworkContext, Prettify<PathParams<TPath>>, NoInput, NoInput, TOutput>): Controller<TMethod, TPath, Prettify<PathParams<TPath>>, NoInput, NoInput, TOutput, TFrameworkRouter>;
|
|
94
156
|
}
|
|
95
157
|
//#endregion
|
|
96
|
-
//#region src/classes/controller-
|
|
97
|
-
declare class
|
|
158
|
+
//#region src/classes/controller-builder/steps/endpoint-step.d.ts
|
|
159
|
+
declare class EndpointStep<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter> {
|
|
98
160
|
private readonly injectable;
|
|
99
|
-
private readonly
|
|
100
|
-
constructor(injectable:
|
|
101
|
-
endpoint<const TMethod extends Method, const TPath extends string>(method: TMethod, path: TPath):
|
|
161
|
+
private readonly createRoute;
|
|
162
|
+
constructor(injectable: TFrameworkInjectable, createRoute: CreateRouteFn<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter>);
|
|
163
|
+
endpoint<const TMethod extends Method, const TPath extends string>(method: TMethod, path: TPath): InputStep<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter, TMethod, TPath>;
|
|
102
164
|
}
|
|
103
165
|
//#endregion
|
|
104
|
-
//#region src/classes/controller-
|
|
105
|
-
declare class
|
|
106
|
-
private readonly
|
|
107
|
-
private readonly
|
|
108
|
-
constructor(
|
|
109
|
-
inject(injectable:
|
|
110
|
-
endpoint<const TMethod extends Method, const TPath extends string>(method: TMethod, path: TPath):
|
|
166
|
+
//#region src/classes/controller-builder/controller-builder.d.ts
|
|
167
|
+
declare class ControllerBuilder<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter> {
|
|
168
|
+
private readonly defaultInjectable;
|
|
169
|
+
private readonly createRoute;
|
|
170
|
+
constructor(defaultInjectable: TFrameworkInjectable, createRoute: CreateRouteFn<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter>);
|
|
171
|
+
inject(injectable: TFrameworkInjectable): EndpointStep<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter>;
|
|
172
|
+
endpoint<const TMethod extends Method, const TPath extends string>(method: TMethod, path: TPath): InputStep<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter, TMethod, TPath>;
|
|
111
173
|
}
|
|
112
174
|
//#endregion
|
|
113
|
-
//#region src/classes/controller-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
private readonly
|
|
117
|
-
constructor(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
175
|
+
//#region src/classes/controller-router-factory.d.ts
|
|
176
|
+
type ControllerRouterRecord<TFrameworkRouter> = Record<string, Controller<any, any, any, any, any, any, TFrameworkRouter>>;
|
|
177
|
+
declare class ControllerRouterFactory<TFrameworkRouter> {
|
|
178
|
+
private readonly combineRoutes;
|
|
179
|
+
constructor(combineRoutes: CombineRoutesFn<TFrameworkRouter>);
|
|
180
|
+
/**
|
|
181
|
+
* @example
|
|
182
|
+
* const getUser = builder
|
|
183
|
+
* .endpoint('get', '/api/users/:id')
|
|
184
|
+
* .output(async ({ inputs, outputs }) => outputs.pass({ id: inputs.params.id }));
|
|
185
|
+
*
|
|
186
|
+
* const createUser = builder
|
|
187
|
+
* .endpoint('post', '/api/users')
|
|
188
|
+
* .input((s) => s.body(z.object({ name: z.string() })))
|
|
189
|
+
* .output(async ({ inputs, outputs }) => outputs.pass({ name: inputs.body.name }, 201));
|
|
190
|
+
*
|
|
191
|
+
* const usersRouter = controllerRouterFactory.createControllerRouter({ getUser, createUser });
|
|
192
|
+
*/
|
|
193
|
+
createControllerRouter<TRoutes extends ControllerRouterRecord<TFrameworkRouter>>(routes: TRoutes): ControllerRouter<TFrameworkRouter, TRoutes>;
|
|
126
194
|
}
|
|
127
195
|
//#endregion
|
|
128
|
-
//#region src/classes/framework-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
196
|
+
//#region src/classes/framework-setup.d.ts
|
|
197
|
+
/**
|
|
198
|
+
* @example
|
|
199
|
+
* const setup = new FrameworkSetup<Request, RequestHandler[], Router>();
|
|
200
|
+
*/
|
|
201
|
+
declare class FrameworkSetup<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter> {
|
|
202
|
+
/**
|
|
203
|
+
* @example
|
|
204
|
+
* const builder = setup.createControllerBuilder([], (blueprint) => { ... });
|
|
205
|
+
*/
|
|
206
|
+
createControllerBuilder(defaultInjectable: TFrameworkInjectable, createRoute: CreateRouteFn<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter>): ControllerBuilder<TFrameworkContext, TFrameworkInjectable, TFrameworkRouter>;
|
|
207
|
+
/**
|
|
208
|
+
* @example
|
|
209
|
+
* const routerFactory = setup.createControllerRouterFactory((routes) => { ... });
|
|
210
|
+
*/
|
|
211
|
+
createControllerRouterFactory(combineRoutes: CombineRoutesFn<TFrameworkRouter>): ControllerRouterFactory<TFrameworkRouter>;
|
|
132
212
|
}
|
|
133
213
|
//#endregion
|
|
134
|
-
|
|
135
|
-
type InferControllerContractsFromRouter<T> = T extends ControllerContractControllerRouter<any, infer TRoutes> ? MapToControllerContract<TRoutes> : never;
|
|
136
|
-
//#endregion
|
|
137
|
-
export { FrameworkIntegrationFactory, InferControllerContractsFromRouter, StandardOutputs, outputs, rootOnly };
|
|
214
|
+
export { FrameworkSetup, InferControllerContractsFromRouter };
|