@controller-contract/server 0.2.3 → 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 +14 -7
- package/dist/index.mjs +20 -12
- package/package.json +2 -2
- package/src/classes/ControllerContractAdapterFactory.ts +13 -0
- package/src/classes/ControllerContractRouter.ts +9 -0
- package/src/classes/PostEndpointStep.ts +2 -4
- package/src/classes/PostInputStep.ts +2 -4
- package/src/index.ts +1 -1
- package/src/types/index.ts +3 -1
- package/src/classes/ControllerContractBuilderFactory.ts +0 -10
- /package/src/{classes → interfaces}/ControllerContractSpec.ts +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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>;
|
|
@@ -103,11 +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
|
-
|
|
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>;
|
|
111
118
|
}
|
|
112
119
|
//#endregion
|
|
113
|
-
export {
|
|
120
|
+
export { ControllerContractAdapterFactory, StandardOutputs, outputs, rootOnly };
|
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ var PostInputStep = class {
|
|
|
15
15
|
this.schema = schema;
|
|
16
16
|
}
|
|
17
17
|
output(outputFn) {
|
|
18
|
-
this.integrator({
|
|
18
|
+
return this.integrator({
|
|
19
19
|
type: "sanitized",
|
|
20
20
|
injectable: this.injectable,
|
|
21
21
|
method: this.method,
|
|
@@ -24,7 +24,6 @@ var PostInputStep = class {
|
|
|
24
24
|
schema: this.schema,
|
|
25
25
|
outputFn
|
|
26
26
|
});
|
|
27
|
-
return {};
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
//#endregion
|
|
@@ -44,14 +43,13 @@ var PostEndpointStep = class {
|
|
|
44
43
|
return new PostInputStep(this.injectable, this.integrator, this.method, this.path, channel, schema);
|
|
45
44
|
}
|
|
46
45
|
output(outputFn) {
|
|
47
|
-
this.integrator({
|
|
46
|
+
return this.integrator({
|
|
48
47
|
type: "nullary",
|
|
49
48
|
method: this.method,
|
|
50
49
|
path: this.path,
|
|
51
50
|
injectable: this.injectable,
|
|
52
51
|
outputFn
|
|
53
52
|
});
|
|
54
|
-
return {};
|
|
55
53
|
}
|
|
56
54
|
};
|
|
57
55
|
//#endregion
|
|
@@ -84,14 +82,24 @@ var ControllerContractBuilder = class {
|
|
|
84
82
|
}
|
|
85
83
|
};
|
|
86
84
|
//#endregion
|
|
87
|
-
//#region src/classes/
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
constructor(
|
|
91
|
-
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);
|
|
92
100
|
}
|
|
93
|
-
|
|
94
|
-
return new
|
|
101
|
+
createRouter(routerAdapterFn) {
|
|
102
|
+
return new ControllerContractRouter(routerAdapterFn);
|
|
95
103
|
}
|
|
96
104
|
};
|
|
97
105
|
//#endregion
|
|
@@ -145,4 +153,4 @@ const StandardOutputs = Object.freeze({
|
|
|
145
153
|
BadGateway: outputs.fail(rootOnly("Bad Gateway"), 502)
|
|
146
154
|
});
|
|
147
155
|
//#endregion
|
|
148
|
-
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
|
+
}
|
|
@@ -8,8 +8,8 @@ import type {
|
|
|
8
8
|
ParamsFrom,
|
|
9
9
|
} from '@controller-contract/core';
|
|
10
10
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
11
|
+
import type { NullaryControllerContractSpec } from '../interfaces/ControllerContractSpec';
|
|
11
12
|
import type { IntegratorFn, OutputFn } from '../types';
|
|
12
|
-
import type { NullaryControllerContractSpec } from './ControllerContractSpec';
|
|
13
13
|
import { PostInputStep } from './PostInputStep';
|
|
14
14
|
|
|
15
15
|
export class PostEndpointStep<TContext, TInject, TProduct, const TMethod extends Method, const TPath extends string> {
|
|
@@ -42,8 +42,6 @@ export class PostEndpointStep<TContext, TInject, TProduct, const TMethod extends
|
|
|
42
42
|
outputFn,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
return <ControllerContractProduct<TMethod, TPath, ParamsFrom<TPath>, NoInput, NoInput, TOutput, TProduct>>
|
|
46
|
-
...() => product,
|
|
47
|
-
};
|
|
45
|
+
return <ControllerContractProduct<TMethod, TPath, ParamsFrom<TPath>, NoInput, NoInput, TOutput, TProduct>>product;
|
|
48
46
|
}
|
|
49
47
|
}
|
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
ParamsFrom,
|
|
8
8
|
} from '@controller-contract/core';
|
|
9
9
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
10
|
+
import type { SanitizedControllerContractSpec } from '../interfaces/ControllerContractSpec';
|
|
10
11
|
import type { IntegratorFn, SanitizedOutputFn } from '../types';
|
|
11
|
-
import type { SanitizedControllerContractSpec } from './ControllerContractSpec';
|
|
12
12
|
|
|
13
13
|
export class PostInputStep<
|
|
14
14
|
TContext,
|
|
@@ -50,8 +50,6 @@ export class PostInputStep<
|
|
|
50
50
|
TOutputFromInput | TOutput,
|
|
51
51
|
TProduct
|
|
52
52
|
>
|
|
53
|
-
>
|
|
54
|
-
...() => product,
|
|
55
|
-
};
|
|
53
|
+
>product;
|
|
56
54
|
}
|
|
57
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,10 +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
|
-
createBuilder<TProduct>(integrator: IntegratorFn<TContext, TInject, TProduct>) {
|
|
8
|
-
return new ControllerContractBuilder<TContext, TInject, TProduct>(this.injectableDefaultValue, integrator);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
File without changes
|