@controller-contract/server 0.2.1 → 0.2.4
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.d.mts +20 -19
- package/dist/index.mjs +18 -14
- package/package.json +2 -2
- package/src/classes/ControllerContractAdapterFactory.ts +13 -0
- package/src/classes/ControllerContractRouter.ts +9 -0
- package/src/classes/PostEndpointStep.ts +15 -4
- package/src/classes/PostInputStep.ts +25 -5
- package/src/index.ts +1 -1
- package/src/types/index.ts +3 -1
- package/src/classes/ControllerContractBuilderFactory.ts +0 -16
- /package/src/{classes → interfaces}/ControllerContractSpec.ts +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ExitOutput, FailOutput, InputChannel, Method, NextOutput, Output, ParamsFrom, PassOutput } from "@controller-contract/core";
|
|
1
|
+
import { ControllerContractProduct, ExitOutput, FailOutput, InputChannel, Method, NextOutput, NoInput, Output, ParamsFrom, PassOutput } from "@controller-contract/core";
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/interfaces/ControllerContractSpec.d.ts
|
|
5
5
|
interface NullaryControllerContractSpec<TContext, TInject> {
|
|
6
6
|
readonly type: 'nullary';
|
|
7
7
|
readonly injectable: TInject;
|
|
@@ -54,6 +54,7 @@ declare const StandardOutputs: Readonly<{
|
|
|
54
54
|
//#endregion
|
|
55
55
|
//#region src/types/index.d.ts
|
|
56
56
|
type IntegratorFn<TContext, TInject, TProduct> = (spec: ControllerContractSpec<TContext, TInject>) => TProduct;
|
|
57
|
+
type RouterAdapterFn<TProduct> = (routes: Record<string, TProduct>) => TProduct;
|
|
57
58
|
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
58
59
|
type OutputFn<TContext, TPath extends string, TOutput> = (context: Prettify<TContext & {
|
|
59
60
|
params: ParamsFrom<TPath>;
|
|
@@ -64,15 +65,15 @@ type SanitizedOutputFn<TContext, TPath extends string, TInput, TOutput> = Output
|
|
|
64
65
|
}, TPath, TOutput>;
|
|
65
66
|
//#endregion
|
|
66
67
|
//#region src/classes/PostInputStep.d.ts
|
|
67
|
-
declare class PostInputStep<TContext, TInject, TProduct, const TMethod extends Method, const TPath extends string, TInput, TOutputFromInput extends Output> {
|
|
68
|
+
declare class PostInputStep<TContext, TInject, TProduct, const TMethod extends Method, const TPath extends string, const TChannel extends InputChannel, TInput, TOutputFromInput extends Output> {
|
|
68
69
|
private readonly injectable;
|
|
69
70
|
private readonly integrator;
|
|
70
71
|
private readonly method;
|
|
71
72
|
private readonly path;
|
|
72
73
|
private readonly channel;
|
|
73
74
|
private readonly schema;
|
|
74
|
-
constructor(injectable: TInject, integrator: IntegratorFn<TContext, TInject, TProduct>, method: TMethod, path: TPath, channel:
|
|
75
|
-
output<TOutput extends Output>(outputFn: SanitizedOutputFn<TContext, TPath, TInput, TOutputFromInput | TOutput
|
|
75
|
+
constructor(injectable: TInject, integrator: IntegratorFn<TContext, TInject, TProduct>, method: TMethod, path: TPath, channel: TChannel, schema: StandardSchemaV1<TInput>);
|
|
76
|
+
output<TOutput extends Output>(outputFn: SanitizedOutputFn<TContext, TPath, TInput, TOutput>): ControllerContractProduct<TMethod, TPath, ParamsFrom<TPath>, TChannel extends "query" ? TInput : NoInput, TChannel extends "body" ? TInput : NoInput, TOutputFromInput | TOutput, TProduct>;
|
|
76
77
|
}
|
|
77
78
|
//#endregion
|
|
78
79
|
//#region src/classes/PostEndpointStep.d.ts
|
|
@@ -82,8 +83,8 @@ declare class PostEndpointStep<TContext, TInject, TProduct, const TMethod extend
|
|
|
82
83
|
private readonly method;
|
|
83
84
|
private readonly path;
|
|
84
85
|
constructor(injectable: TInject, integrator: IntegratorFn<TContext, TInject, TProduct>, method: TMethod, path: TPath);
|
|
85
|
-
input<TInput>(channel:
|
|
86
|
-
output<TOutput extends Output>(outputFn: OutputFn<TContext, TPath, TOutput>): TProduct
|
|
86
|
+
input<const TChannel extends InputChannel, TInput>(channel: TChannel, schema: StandardSchemaV1<TInput>): PostInputStep<TContext, TInject, TProduct, TMethod, TPath, TChannel, TInput, FailOutput<Extract<keyof TInput, string>>>;
|
|
87
|
+
output<TOutput extends Output>(outputFn: OutputFn<TContext, TPath, TOutput>): ControllerContractProduct<TMethod, TPath, ParamsFrom<TPath>, NoInput, NoInput, TOutput, TProduct>;
|
|
87
88
|
}
|
|
88
89
|
//#endregion
|
|
89
90
|
//#region src/classes/PostInjectStep.d.ts
|
|
@@ -103,17 +104,17 @@ declare class ControllerContractBuilder<TContext, TInject, TProduct> {
|
|
|
103
104
|
endpoint<const TMethod extends Method, const TPath extends string>(method: TMethod, path: TPath): PostEndpointStep<TContext, TInject, TProduct, TMethod, TPath>;
|
|
104
105
|
}
|
|
105
106
|
//#endregion
|
|
106
|
-
//#region src/classes/
|
|
107
|
-
declare class
|
|
108
|
-
private readonly
|
|
109
|
-
constructor(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
107
|
+
//#region src/classes/ControllerContractRouter.d.ts
|
|
108
|
+
declare class ControllerContractRouter<TProduct> {
|
|
109
|
+
private readonly routerAdapterFn;
|
|
110
|
+
constructor(routerAdapterFn: RouterAdapterFn<TProduct>);
|
|
111
|
+
getRouter(routes: Record<string, TProduct>): TProduct;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/classes/ControllerContractAdapterFactory.d.ts
|
|
115
|
+
declare class ControllerContractAdapterFactory<TContext, TInject, TProduct> {
|
|
116
|
+
createBuilder(injectableDefaultValue: TInject, integrator: IntegratorFn<TContext, TInject, TProduct>): ControllerContractBuilder<TContext, TInject, TProduct>;
|
|
117
|
+
createRouter(routerAdapterFn: RouterAdapterFn<TProduct>): ControllerContractRouter<TProduct>;
|
|
117
118
|
}
|
|
118
119
|
//#endregion
|
|
119
|
-
export {
|
|
120
|
+
export { ControllerContractAdapterFactory, StandardOutputs, outputs, rootOnly };
|
package/dist/index.mjs
CHANGED
|
@@ -82,20 +82,24 @@ var ControllerContractBuilder = class {
|
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
//#endregion
|
|
85
|
-
//#region src/classes/
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
constructor(
|
|
89
|
-
this.
|
|
85
|
+
//#region src/classes/ControllerContractRouter.ts
|
|
86
|
+
var ControllerContractRouter = class {
|
|
87
|
+
routerAdapterFn;
|
|
88
|
+
constructor(routerAdapterFn) {
|
|
89
|
+
this.routerAdapterFn = routerAdapterFn;
|
|
90
|
+
}
|
|
91
|
+
getRouter(routes) {
|
|
92
|
+
return this.routerAdapterFn(routes);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/classes/ControllerContractAdapterFactory.ts
|
|
97
|
+
var ControllerContractAdapterFactory = class {
|
|
98
|
+
createBuilder(injectableDefaultValue, integrator) {
|
|
99
|
+
return new ControllerContractBuilder(injectableDefaultValue, integrator);
|
|
90
100
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* `contract-controller` and your http library/framework of choice.
|
|
94
|
-
*
|
|
95
|
-
* When youre done writing your adaptor you can use the product in your code base.
|
|
96
|
-
*/
|
|
97
|
-
createBuilder(integrator) {
|
|
98
|
-
return new ControllerContractBuilder(this.injectableDefaultValue, integrator);
|
|
101
|
+
createRouter(routerAdapterFn) {
|
|
102
|
+
return new ControllerContractRouter(routerAdapterFn);
|
|
99
103
|
}
|
|
100
104
|
};
|
|
101
105
|
//#endregion
|
|
@@ -149,4 +153,4 @@ const StandardOutputs = Object.freeze({
|
|
|
149
153
|
BadGateway: outputs.fail(rootOnly("Bad Gateway"), 502)
|
|
150
154
|
});
|
|
151
155
|
//#endregion
|
|
152
|
-
export {
|
|
156
|
+
export { ControllerContractAdapterFactory, StandardOutputs, outputs, rootOnly };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@controller-contract/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.4",
|
|
5
5
|
"author": "kennychulo",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"typescript": "6.0.3"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@controller-contract/core": "0.2.
|
|
26
|
+
"@controller-contract/core": "0.2.9",
|
|
27
27
|
"@standard-schema/spec": "1.1.0"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IntegratorFn, RouterAdapterFn } from '../types';
|
|
2
|
+
import { ControllerContractBuilder } from './ControllerContractBuilder';
|
|
3
|
+
import { ControllerContractRouter } from './ControllerContractRouter';
|
|
4
|
+
|
|
5
|
+
export class ControllerContractAdapterFactory<TContext, TInject, TProduct> {
|
|
6
|
+
createBuilder(injectableDefaultValue: TInject, integrator: IntegratorFn<TContext, TInject, TProduct>) {
|
|
7
|
+
return new ControllerContractBuilder<TContext, TInject, TProduct>(injectableDefaultValue, integrator);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
createRouter(routerAdapterFn: RouterAdapterFn<TProduct>) {
|
|
11
|
+
return new ControllerContractRouter<TProduct>(routerAdapterFn);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RouterAdapterFn } from '../types';
|
|
2
|
+
|
|
3
|
+
export class ControllerContractRouter<TProduct> {
|
|
4
|
+
constructor(private readonly routerAdapterFn: RouterAdapterFn<TProduct>) {}
|
|
5
|
+
|
|
6
|
+
getRouter(routes: Record<string, TProduct>): TProduct {
|
|
7
|
+
return this.routerAdapterFn(routes);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ControllerContractProduct,
|
|
3
|
+
FailOutput,
|
|
4
|
+
InputChannel,
|
|
5
|
+
Method,
|
|
6
|
+
NoInput,
|
|
7
|
+
Output,
|
|
8
|
+
ParamsFrom,
|
|
9
|
+
} from '@controller-contract/core';
|
|
2
10
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
11
|
+
import type { NullaryControllerContractSpec } from '../interfaces/ControllerContractSpec';
|
|
3
12
|
import type { IntegratorFn, OutputFn } from '../types';
|
|
4
|
-
import type { NullaryControllerContractSpec } from './ControllerContractSpec';
|
|
5
13
|
import { PostInputStep } from './PostInputStep';
|
|
6
14
|
|
|
7
15
|
export class PostEndpointStep<TContext, TInject, TProduct, const TMethod extends Method, const TPath extends string> {
|
|
@@ -12,25 +20,28 @@ export class PostEndpointStep<TContext, TInject, TProduct, const TMethod extends
|
|
|
12
20
|
private readonly path: TPath,
|
|
13
21
|
) {}
|
|
14
22
|
|
|
15
|
-
input<TInput>(channel:
|
|
23
|
+
input<const TChannel extends InputChannel, TInput>(channel: TChannel, schema: StandardSchemaV1<TInput>) {
|
|
16
24
|
return new PostInputStep<
|
|
17
25
|
TContext,
|
|
18
26
|
TInject,
|
|
19
27
|
TProduct,
|
|
20
28
|
TMethod,
|
|
21
29
|
TPath,
|
|
30
|
+
TChannel,
|
|
22
31
|
TInput,
|
|
23
32
|
FailOutput<Extract<keyof TInput, string>>
|
|
24
33
|
>(this.injectable, this.integrator, this.method, this.path, channel, schema);
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
output<TOutput extends Output>(outputFn: OutputFn<TContext, TPath, TOutput>) {
|
|
28
|
-
|
|
37
|
+
const product = this.integrator(<NullaryControllerContractSpec<TContext, TInject>>{
|
|
29
38
|
type: 'nullary',
|
|
30
39
|
method: this.method,
|
|
31
40
|
path: this.path,
|
|
32
41
|
injectable: this.injectable,
|
|
33
42
|
outputFn,
|
|
34
43
|
});
|
|
44
|
+
|
|
45
|
+
return <ControllerContractProduct<TMethod, TPath, ParamsFrom<TPath>, NoInput, NoInput, TOutput, TProduct>>product;
|
|
35
46
|
}
|
|
36
47
|
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ControllerContractProduct,
|
|
3
|
+
InputChannel,
|
|
4
|
+
Method,
|
|
5
|
+
NoInput,
|
|
6
|
+
Output,
|
|
7
|
+
ParamsFrom,
|
|
8
|
+
} from '@controller-contract/core';
|
|
2
9
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
10
|
+
import type { SanitizedControllerContractSpec } from '../interfaces/ControllerContractSpec';
|
|
3
11
|
import type { IntegratorFn, SanitizedOutputFn } from '../types';
|
|
4
|
-
import type { SanitizedControllerContractSpec } from './ControllerContractSpec';
|
|
5
12
|
|
|
6
13
|
export class PostInputStep<
|
|
7
14
|
TContext,
|
|
@@ -9,6 +16,7 @@ export class PostInputStep<
|
|
|
9
16
|
TProduct,
|
|
10
17
|
const TMethod extends Method,
|
|
11
18
|
const TPath extends string,
|
|
19
|
+
const TChannel extends InputChannel,
|
|
12
20
|
TInput,
|
|
13
21
|
TOutputFromInput extends Output,
|
|
14
22
|
> {
|
|
@@ -17,12 +25,12 @@ export class PostInputStep<
|
|
|
17
25
|
private readonly integrator: IntegratorFn<TContext, TInject, TProduct>,
|
|
18
26
|
private readonly method: TMethod,
|
|
19
27
|
private readonly path: TPath,
|
|
20
|
-
private readonly channel:
|
|
28
|
+
private readonly channel: TChannel,
|
|
21
29
|
private readonly schema: StandardSchemaV1<TInput>,
|
|
22
30
|
) {}
|
|
23
31
|
|
|
24
|
-
output<TOutput extends Output>(outputFn: SanitizedOutputFn<TContext, TPath, TInput,
|
|
25
|
-
|
|
32
|
+
output<TOutput extends Output>(outputFn: SanitizedOutputFn<TContext, TPath, TInput, TOutput>) {
|
|
33
|
+
const product = this.integrator(<SanitizedControllerContractSpec<TContext, TInject>>{
|
|
26
34
|
type: 'sanitized',
|
|
27
35
|
injectable: this.injectable,
|
|
28
36
|
method: this.method,
|
|
@@ -31,5 +39,17 @@ export class PostInputStep<
|
|
|
31
39
|
schema: this.schema,
|
|
32
40
|
outputFn,
|
|
33
41
|
});
|
|
42
|
+
|
|
43
|
+
return <
|
|
44
|
+
ControllerContractProduct<
|
|
45
|
+
TMethod,
|
|
46
|
+
TPath,
|
|
47
|
+
ParamsFrom<TPath>,
|
|
48
|
+
TChannel extends 'query' ? TInput : NoInput,
|
|
49
|
+
TChannel extends 'body' ? TInput : NoInput,
|
|
50
|
+
TOutputFromInput | TOutput,
|
|
51
|
+
TProduct
|
|
52
|
+
>
|
|
53
|
+
>product;
|
|
34
54
|
}
|
|
35
55
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './classes/
|
|
1
|
+
export * from './classes/ControllerContractAdapterFactory';
|
|
2
2
|
export * from './utils';
|
package/src/types/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ParamsFrom } from '@controller-contract/core';
|
|
2
|
-
import type { ControllerContractSpec } from '../
|
|
2
|
+
import type { ControllerContractSpec } from '../interfaces/ControllerContractSpec';
|
|
3
3
|
import type { outputs } from '../utils';
|
|
4
4
|
|
|
5
5
|
export type IntegratorFn<TContext, TInject, TProduct> = (spec: ControllerContractSpec<TContext, TInject>) => TProduct;
|
|
6
6
|
|
|
7
|
+
export type RouterAdapterFn<TProduct> = (routes: Record<string, TProduct>) => TProduct;
|
|
8
|
+
|
|
7
9
|
export type Prettify<T> = {
|
|
8
10
|
[K in keyof T]: T[K];
|
|
9
11
|
} & {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { IntegratorFn } from '../types';
|
|
2
|
-
import { ControllerContractBuilder } from './ControllerContractBuilder';
|
|
3
|
-
|
|
4
|
-
export class ControllerContractBuilderFactory<TContext, TInject> {
|
|
5
|
-
constructor(private readonly injectableDefaultValue: TInject) {}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This factory function provides the inteface for you to write the integration between
|
|
9
|
-
* `contract-controller` and your http library/framework of choice.
|
|
10
|
-
*
|
|
11
|
-
* When youre done writing your adaptor you can use the product in your code base.
|
|
12
|
-
*/
|
|
13
|
-
createBuilder<TProduct>(integrator: IntegratorFn<TContext, TInject, TProduct>) {
|
|
14
|
-
return new ControllerContractBuilder<TContext, TInject, TProduct>(this.injectableDefaultValue, integrator);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
File without changes
|