@controller-contract/server 0.2.1 → 0.2.3
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
4
|
//#region src/classes/ControllerContractSpec.d.ts
|
|
@@ -64,15 +64,15 @@ type SanitizedOutputFn<TContext, TPath extends string, TInput, TOutput> = Output
|
|
|
64
64
|
}, TPath, TOutput>;
|
|
65
65
|
//#endregion
|
|
66
66
|
//#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> {
|
|
67
|
+
declare class PostInputStep<TContext, TInject, TProduct, const TMethod extends Method, const TPath extends string, const TChannel extends InputChannel, TInput, TOutputFromInput extends Output> {
|
|
68
68
|
private readonly injectable;
|
|
69
69
|
private readonly integrator;
|
|
70
70
|
private readonly method;
|
|
71
71
|
private readonly path;
|
|
72
72
|
private readonly channel;
|
|
73
73
|
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
|
|
74
|
+
constructor(injectable: TInject, integrator: IntegratorFn<TContext, TInject, TProduct>, method: TMethod, path: TPath, channel: TChannel, schema: StandardSchemaV1<TInput>);
|
|
75
|
+
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
76
|
}
|
|
77
77
|
//#endregion
|
|
78
78
|
//#region src/classes/PostEndpointStep.d.ts
|
|
@@ -82,8 +82,8 @@ declare class PostEndpointStep<TContext, TInject, TProduct, const TMethod extend
|
|
|
82
82
|
private readonly method;
|
|
83
83
|
private readonly path;
|
|
84
84
|
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
|
|
85
|
+
input<const TChannel extends InputChannel, TInput>(channel: TChannel, schema: StandardSchemaV1<TInput>): PostInputStep<TContext, TInject, TProduct, TMethod, TPath, TChannel, TInput, FailOutput<Extract<keyof TInput, string>>>;
|
|
86
|
+
output<TOutput extends Output>(outputFn: OutputFn<TContext, TPath, TOutput>): ControllerContractProduct<TMethod, TPath, ParamsFrom<TPath>, NoInput, NoInput, TOutput, TProduct>;
|
|
87
87
|
}
|
|
88
88
|
//#endregion
|
|
89
89
|
//#region src/classes/PostInjectStep.d.ts
|
|
@@ -107,12 +107,6 @@ declare class ControllerContractBuilder<TContext, TInject, TProduct> {
|
|
|
107
107
|
declare class ControllerContractBuilderFactory<TContext, TInject> {
|
|
108
108
|
private readonly injectableDefaultValue;
|
|
109
109
|
constructor(injectableDefaultValue: TInject);
|
|
110
|
-
/**
|
|
111
|
-
* This factory function provides the inteface for you to write the integration between
|
|
112
|
-
* `contract-controller` and your http library/framework of choice.
|
|
113
|
-
*
|
|
114
|
-
* When youre done writing your adaptor you can use the product in your code base.
|
|
115
|
-
*/
|
|
116
110
|
createBuilder<TProduct>(integrator: IntegratorFn<TContext, TInject, TProduct>): ControllerContractBuilder<TContext, TInject, TProduct>;
|
|
117
111
|
}
|
|
118
112
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ var PostInputStep = class {
|
|
|
15
15
|
this.schema = schema;
|
|
16
16
|
}
|
|
17
17
|
output(outputFn) {
|
|
18
|
-
|
|
18
|
+
this.integrator({
|
|
19
19
|
type: "sanitized",
|
|
20
20
|
injectable: this.injectable,
|
|
21
21
|
method: this.method,
|
|
@@ -24,6 +24,7 @@ var PostInputStep = class {
|
|
|
24
24
|
schema: this.schema,
|
|
25
25
|
outputFn
|
|
26
26
|
});
|
|
27
|
+
return {};
|
|
27
28
|
}
|
|
28
29
|
};
|
|
29
30
|
//#endregion
|
|
@@ -43,13 +44,14 @@ var PostEndpointStep = class {
|
|
|
43
44
|
return new PostInputStep(this.injectable, this.integrator, this.method, this.path, channel, schema);
|
|
44
45
|
}
|
|
45
46
|
output(outputFn) {
|
|
46
|
-
|
|
47
|
+
this.integrator({
|
|
47
48
|
type: "nullary",
|
|
48
49
|
method: this.method,
|
|
49
50
|
path: this.path,
|
|
50
51
|
injectable: this.injectable,
|
|
51
52
|
outputFn
|
|
52
53
|
});
|
|
54
|
+
return {};
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
//#endregion
|
|
@@ -88,12 +90,6 @@ var ControllerContractBuilderFactory = class {
|
|
|
88
90
|
constructor(injectableDefaultValue) {
|
|
89
91
|
this.injectableDefaultValue = injectableDefaultValue;
|
|
90
92
|
}
|
|
91
|
-
/**
|
|
92
|
-
* This factory function provides the inteface for you to write the integration between
|
|
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
93
|
createBuilder(integrator) {
|
|
98
94
|
return new ControllerContractBuilder(this.injectableDefaultValue, integrator);
|
|
99
95
|
}
|
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.3",
|
|
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.7",
|
|
27
27
|
"@standard-schema/spec": "1.1.0"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
@@ -4,12 +4,6 @@ import { ControllerContractBuilder } from './ControllerContractBuilder';
|
|
|
4
4
|
export class ControllerContractBuilderFactory<TContext, TInject> {
|
|
5
5
|
constructor(private readonly injectableDefaultValue: TInject) {}
|
|
6
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
7
|
createBuilder<TProduct>(integrator: IntegratorFn<TContext, TInject, TProduct>) {
|
|
14
8
|
return new ControllerContractBuilder<TContext, TInject, TProduct>(this.injectableDefaultValue, integrator);
|
|
15
9
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
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';
|
|
3
11
|
import type { IntegratorFn, OutputFn } from '../types';
|
|
4
12
|
import type { NullaryControllerContractSpec } from './ControllerContractSpec';
|
|
@@ -12,25 +20,30 @@ 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>>{
|
|
46
|
+
...() => product,
|
|
47
|
+
};
|
|
35
48
|
}
|
|
36
49
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
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';
|
|
3
10
|
import type { IntegratorFn, SanitizedOutputFn } from '../types';
|
|
4
11
|
import type { SanitizedControllerContractSpec } from './ControllerContractSpec';
|
|
@@ -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,19 @@ 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
|
+
>{
|
|
54
|
+
...() => product,
|
|
55
|
+
};
|
|
34
56
|
}
|
|
35
57
|
}
|