@twin.org/api-models 0.0.1-next.3 → 0.0.1-next.30
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/cjs/index.cjs +68 -0
- package/dist/esm/index.mjs +66 -2
- package/dist/types/factories/mimeTypeProcessorFactory.d.ts +6 -0
- package/dist/types/factories/restRouteProcessorFactory.d.ts +6 -0
- package/dist/types/factories/socketRouteProcessorFactory.d.ts +6 -0
- package/dist/types/helpers/httpParameterHelper.d.ts +29 -0
- package/dist/types/index.d.ts +13 -1
- package/dist/types/models/config/IBaseSocketClientConfig.d.ts +4 -0
- package/dist/types/models/routes/IBaseRouteEntryPoint.d.ts +22 -0
- package/dist/types/models/routes/IRestRoute.d.ts +4 -10
- package/dist/types/models/routes/IRestRouteEntryPoint.d.ts +2 -19
- package/dist/types/models/routes/IRestRouteExample.d.ts +13 -0
- package/dist/types/models/routes/IRestRouteRequestExample.d.ts +10 -0
- package/dist/types/models/routes/IRestRouteResponseExample.d.ts +10 -0
- package/dist/types/models/routes/ISocketRoute.d.ts +6 -8
- package/dist/types/models/routes/ISocketRouteEntryPoint.d.ts +6 -0
- package/dist/types/models/server/IBaseRouteProcessor.d.ts +34 -0
- package/dist/types/models/server/IMimeTypeProcessor.d.ts +17 -0
- package/dist/types/models/server/IRestRouteProcessor.d.ts +22 -0
- package/dist/types/models/server/{IHttpRestRouteProcessor.d.ts → ISocketRouteProcessor.d.ts} +12 -15
- package/dist/types/models/server/IWebServer.d.ts +7 -3
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/HttpErrorHelper.md +15 -5
- package/docs/reference/classes/HttpParameterHelper.md +117 -0
- package/docs/reference/index.md +14 -2
- package/docs/reference/interfaces/IBaseRouteEntryPoint.md +53 -0
- package/docs/reference/interfaces/IBaseRouteProcessor.md +104 -0
- package/docs/reference/interfaces/IBaseSocketClientConfig.md +8 -0
- package/docs/reference/interfaces/ICreatedResponse.md +2 -2
- package/docs/reference/interfaces/IHealthInfo.md +18 -0
- package/docs/reference/interfaces/IHttpRequestContext.md +2 -2
- package/docs/reference/interfaces/IHttpRequestPathParams.md +1 -1
- package/docs/reference/interfaces/IHttpRequestQuery.md +1 -1
- package/docs/reference/interfaces/IInformationComponent.md +12 -4
- package/docs/reference/interfaces/IMimeTypeProcessor.md +43 -0
- package/docs/reference/interfaces/IRestRoute.md +25 -3
- package/docs/reference/interfaces/IRestRouteExample.md +24 -0
- package/docs/reference/interfaces/{IHttpRestRouteProcessor.md → IRestRouteProcessor.md} +55 -23
- package/docs/reference/interfaces/IRestRouteRequestExample.md +43 -0
- package/docs/reference/interfaces/IRestRouteResponseExample.md +43 -0
- package/docs/reference/interfaces/ISocketRoute.md +18 -10
- package/docs/reference/interfaces/ISocketRouteProcessor.md +217 -0
- package/docs/reference/interfaces/IWebServer.md +23 -5
- package/docs/reference/type-aliases/IRestRouteEntryPoint.md +5 -0
- package/docs/reference/type-aliases/ISocketRouteEntryPoint.md +5 -0
- package/docs/reference/variables/MimeTypeProcessorFactory.md +5 -0
- package/docs/reference/variables/RestRouteProcessorFactory.md +5 -0
- package/docs/reference/variables/SocketRouteProcessorFactory.md +5 -0
- package/package.json +3 -30
- package/docs/reference/interfaces/IRestRouteEntryPoint.md +0 -45
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
3
3
|
var core = require('@twin.org/core');
|
|
4
4
|
var web = require('@twin.org/web');
|
|
5
5
|
|
|
6
|
+
// Copyright 2024 IOTA Stiftung.
|
|
7
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
8
|
+
/**
|
|
9
|
+
* Factory for creating implementation of mime type processor types.
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
12
|
+
const MimeTypeProcessorFactory = core.Factory.createFactory("mime-type-processor");
|
|
13
|
+
|
|
14
|
+
// Copyright 2024 IOTA Stiftung.
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
16
|
+
/**
|
|
17
|
+
* Factory for creating implementation of REST route processor types.
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
20
|
+
const RestRouteProcessorFactory = core.Factory.createFactory("rest-route-processor");
|
|
21
|
+
|
|
22
|
+
// Copyright 2024 IOTA Stiftung.
|
|
23
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
24
|
+
/**
|
|
25
|
+
* Factory for creating implementation of socket route processor types.
|
|
26
|
+
*/
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
|
+
const SocketRouteProcessorFactory = core.Factory.createFactory("socket-route-processor");
|
|
29
|
+
|
|
6
30
|
// Copyright 2024 IOTA Stiftung.
|
|
7
31
|
// SPDX-License-Identifier: Apache-2.0.
|
|
8
32
|
/**
|
|
@@ -65,6 +89,46 @@ class HttpErrorHelper {
|
|
|
65
89
|
}
|
|
66
90
|
}
|
|
67
91
|
|
|
92
|
+
// Copyright 2024 IOTA Stiftung.
|
|
93
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
94
|
+
/**
|
|
95
|
+
* Class to help with handling http parameters.
|
|
96
|
+
*/
|
|
97
|
+
class HttpParameterHelper {
|
|
98
|
+
/**
|
|
99
|
+
* Convert list query to array.
|
|
100
|
+
* @param values The values query string.
|
|
101
|
+
* @returns The array of values.
|
|
102
|
+
*/
|
|
103
|
+
static arrayFromString(values) {
|
|
104
|
+
return values?.split(",");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Convert array of values to query string.
|
|
108
|
+
* @param values The values to combine string.
|
|
109
|
+
* @returns The combined.
|
|
110
|
+
*/
|
|
111
|
+
static arrayToString(values) {
|
|
112
|
+
return values?.join(",");
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Convert object string to object.
|
|
116
|
+
* @param value The value query string.
|
|
117
|
+
* @returns The object.
|
|
118
|
+
*/
|
|
119
|
+
static objectFromString(value) {
|
|
120
|
+
return core.Is.json(value) ? JSON.parse(value) : undefined;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Convert object to query string.
|
|
124
|
+
* @param value The value to convert to a string.
|
|
125
|
+
* @returns The converted object.
|
|
126
|
+
*/
|
|
127
|
+
static objectToString(value) {
|
|
128
|
+
return core.Is.empty(value) ? undefined : JSON.stringify(value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
68
132
|
// Copyright 2024 IOTA Stiftung.
|
|
69
133
|
// SPDX-License-Identifier: Apache-2.0.
|
|
70
134
|
/**
|
|
@@ -88,3 +152,7 @@ const HealthStatus = {
|
|
|
88
152
|
|
|
89
153
|
exports.HealthStatus = HealthStatus;
|
|
90
154
|
exports.HttpErrorHelper = HttpErrorHelper;
|
|
155
|
+
exports.HttpParameterHelper = HttpParameterHelper;
|
|
156
|
+
exports.MimeTypeProcessorFactory = MimeTypeProcessorFactory;
|
|
157
|
+
exports.RestRouteProcessorFactory = RestRouteProcessorFactory;
|
|
158
|
+
exports.SocketRouteProcessorFactory = SocketRouteProcessorFactory;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
import { BaseError, GuardError, ConflictError, NotFoundError, AlreadyExistsError, UnauthorizedError, NotImplementedError, UnprocessableError } from '@twin.org/core';
|
|
1
|
+
import { Factory, BaseError, GuardError, ConflictError, NotFoundError, AlreadyExistsError, UnauthorizedError, NotImplementedError, UnprocessableError, Is } from '@twin.org/core';
|
|
2
2
|
import { HttpStatusCode, HeaderTypes, MimeTypes } from '@twin.org/web';
|
|
3
3
|
|
|
4
|
+
// Copyright 2024 IOTA Stiftung.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
6
|
+
/**
|
|
7
|
+
* Factory for creating implementation of mime type processor types.
|
|
8
|
+
*/
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
|
+
const MimeTypeProcessorFactory = Factory.createFactory("mime-type-processor");
|
|
11
|
+
|
|
12
|
+
// Copyright 2024 IOTA Stiftung.
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
14
|
+
/**
|
|
15
|
+
* Factory for creating implementation of REST route processor types.
|
|
16
|
+
*/
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
18
|
+
const RestRouteProcessorFactory = Factory.createFactory("rest-route-processor");
|
|
19
|
+
|
|
20
|
+
// Copyright 2024 IOTA Stiftung.
|
|
21
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
22
|
+
/**
|
|
23
|
+
* Factory for creating implementation of socket route processor types.
|
|
24
|
+
*/
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
26
|
+
const SocketRouteProcessorFactory = Factory.createFactory("socket-route-processor");
|
|
27
|
+
|
|
4
28
|
// Copyright 2024 IOTA Stiftung.
|
|
5
29
|
// SPDX-License-Identifier: Apache-2.0.
|
|
6
30
|
/**
|
|
@@ -63,6 +87,46 @@ class HttpErrorHelper {
|
|
|
63
87
|
}
|
|
64
88
|
}
|
|
65
89
|
|
|
90
|
+
// Copyright 2024 IOTA Stiftung.
|
|
91
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
92
|
+
/**
|
|
93
|
+
* Class to help with handling http parameters.
|
|
94
|
+
*/
|
|
95
|
+
class HttpParameterHelper {
|
|
96
|
+
/**
|
|
97
|
+
* Convert list query to array.
|
|
98
|
+
* @param values The values query string.
|
|
99
|
+
* @returns The array of values.
|
|
100
|
+
*/
|
|
101
|
+
static arrayFromString(values) {
|
|
102
|
+
return values?.split(",");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Convert array of values to query string.
|
|
106
|
+
* @param values The values to combine string.
|
|
107
|
+
* @returns The combined.
|
|
108
|
+
*/
|
|
109
|
+
static arrayToString(values) {
|
|
110
|
+
return values?.join(",");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Convert object string to object.
|
|
114
|
+
* @param value The value query string.
|
|
115
|
+
* @returns The object.
|
|
116
|
+
*/
|
|
117
|
+
static objectFromString(value) {
|
|
118
|
+
return Is.json(value) ? JSON.parse(value) : undefined;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Convert object to query string.
|
|
122
|
+
* @param value The value to convert to a string.
|
|
123
|
+
* @returns The converted object.
|
|
124
|
+
*/
|
|
125
|
+
static objectToString(value) {
|
|
126
|
+
return Is.empty(value) ? undefined : JSON.stringify(value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
66
130
|
// Copyright 2024 IOTA Stiftung.
|
|
67
131
|
// SPDX-License-Identifier: Apache-2.0.
|
|
68
132
|
/**
|
|
@@ -84,4 +148,4 @@ const HealthStatus = {
|
|
|
84
148
|
Error: "error"
|
|
85
149
|
};
|
|
86
150
|
|
|
87
|
-
export { HealthStatus, HttpErrorHelper };
|
|
151
|
+
export { HealthStatus, HttpErrorHelper, HttpParameterHelper, MimeTypeProcessorFactory, RestRouteProcessorFactory, SocketRouteProcessorFactory };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Factory } from "@twin.org/core";
|
|
2
|
+
import type { IMimeTypeProcessor } from "../models/server/IMimeTypeProcessor";
|
|
3
|
+
/**
|
|
4
|
+
* Factory for creating implementation of mime type processor types.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MimeTypeProcessorFactory: Factory<IMimeTypeProcessor>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Factory } from "@twin.org/core";
|
|
2
|
+
import type { IRestRouteProcessor } from "../models/server/IRestRouteProcessor";
|
|
3
|
+
/**
|
|
4
|
+
* Factory for creating implementation of REST route processor types.
|
|
5
|
+
*/
|
|
6
|
+
export declare const RestRouteProcessorFactory: Factory<IRestRouteProcessor>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Factory } from "@twin.org/core";
|
|
2
|
+
import type { ISocketRouteProcessor } from "../models/server/ISocketRouteProcessor";
|
|
3
|
+
/**
|
|
4
|
+
* Factory for creating implementation of socket route processor types.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SocketRouteProcessorFactory: Factory<ISocketRouteProcessor>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to help with handling http parameters.
|
|
3
|
+
*/
|
|
4
|
+
export declare class HttpParameterHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Convert list query to array.
|
|
7
|
+
* @param values The values query string.
|
|
8
|
+
* @returns The array of values.
|
|
9
|
+
*/
|
|
10
|
+
static arrayFromString<T = string>(values?: string): T[] | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Convert array of values to query string.
|
|
13
|
+
* @param values The values to combine string.
|
|
14
|
+
* @returns The combined.
|
|
15
|
+
*/
|
|
16
|
+
static arrayToString<T = string>(values?: T[]): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Convert object string to object.
|
|
19
|
+
* @param value The value query string.
|
|
20
|
+
* @returns The object.
|
|
21
|
+
*/
|
|
22
|
+
static objectFromString<T = unknown>(value?: string): T | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Convert object to query string.
|
|
25
|
+
* @param value The value to convert to a string.
|
|
26
|
+
* @returns The converted object.
|
|
27
|
+
*/
|
|
28
|
+
static objectToString<T = unknown>(value?: T): string | undefined;
|
|
29
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export * from "./factories/mimeTypeProcessorFactory";
|
|
2
|
+
export * from "./factories/restRouteProcessorFactory";
|
|
3
|
+
export * from "./factories/socketRouteProcessorFactory";
|
|
1
4
|
export * from "./helpers/httpErrorHelper";
|
|
5
|
+
export * from "./helpers/httpParameterHelper";
|
|
2
6
|
export * from "./models/api/IServerHealthResponse";
|
|
3
7
|
export * from "./models/api/IServerInfoResponse";
|
|
4
8
|
export * from "./models/api/IServerSpecResponse";
|
|
@@ -24,13 +28,21 @@ export * from "./models/responses/success/ICreatedResponse";
|
|
|
24
28
|
export * from "./models/responses/success/INoContentResponse";
|
|
25
29
|
export * from "./models/responses/success/IOkResponse";
|
|
26
30
|
export * from "./models/routes/IBaseRoute";
|
|
31
|
+
export * from "./models/routes/IBaseRouteEntryPoint";
|
|
27
32
|
export * from "./models/routes/IRestRoute";
|
|
28
33
|
export * from "./models/routes/IRestRouteEntryPoint";
|
|
34
|
+
export * from "./models/routes/IRestRouteExample";
|
|
35
|
+
export * from "./models/routes/IRestRouteRequestExample";
|
|
29
36
|
export * from "./models/routes/IRestRouteResponseAttachmentOptions";
|
|
37
|
+
export * from "./models/routes/IRestRouteResponseExample";
|
|
30
38
|
export * from "./models/routes/IRestRouteResponseOptions";
|
|
31
39
|
export * from "./models/routes/ISocketRoute";
|
|
40
|
+
export * from "./models/routes/ISocketRouteEntryPoint";
|
|
32
41
|
export * from "./models/routes/ITag";
|
|
33
|
-
export * from "./models/server/
|
|
42
|
+
export * from "./models/server/IBaseRouteProcessor";
|
|
43
|
+
export * from "./models/server/IMimeTypeProcessor";
|
|
44
|
+
export * from "./models/server/IRestRouteProcessor";
|
|
45
|
+
export * from "./models/server/ISocketRouteProcessor";
|
|
34
46
|
export * from "./models/server/IWebServer";
|
|
35
47
|
export * from "./models/server/IWebServerOptions";
|
|
36
48
|
export * from "./models/services/healthStatus";
|
|
@@ -3,6 +3,10 @@ import type { IHttpHeaders } from "@twin.org/web";
|
|
|
3
3
|
* Definition for the configuration of a socket service.
|
|
4
4
|
*/
|
|
5
5
|
export interface IBaseSocketClientConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Base path for the socket service, defaults to /socket.
|
|
8
|
+
*/
|
|
9
|
+
basePath?: string;
|
|
6
10
|
/**
|
|
7
11
|
* The endpoint where the api is hosted.
|
|
8
12
|
*/
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ITag } from "./ITag";
|
|
2
|
+
/**
|
|
3
|
+
* Route entry points are used for exposing the routes from a package.
|
|
4
|
+
*/
|
|
5
|
+
export interface IBaseRouteEntryPoint<T> {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the routes.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* The default base route name for the routes.
|
|
12
|
+
*/
|
|
13
|
+
defaultBaseRoute: string;
|
|
14
|
+
/**
|
|
15
|
+
* The tags for the routes.
|
|
16
|
+
*/
|
|
17
|
+
tags: ITag[];
|
|
18
|
+
/**
|
|
19
|
+
* The method to generate the routes.
|
|
20
|
+
*/
|
|
21
|
+
generateRoutes: (baseRouteName: string, componentName: string) => T[];
|
|
22
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { HttpMethod } from "@twin.org/web";
|
|
2
2
|
import type { IBaseRoute } from "./IBaseRoute";
|
|
3
|
+
import type { IRestRouteRequestExample } from "./IRestRouteRequestExample";
|
|
4
|
+
import type { IRestRouteResponseExample } from "./IRestRouteResponseExample";
|
|
3
5
|
import type { IRestRouteResponseOptions } from "./IRestRouteResponseOptions";
|
|
4
6
|
import type { IHttpRequest } from "../protocol/IHttpRequest";
|
|
5
7
|
import type { IHttpRequestContext } from "../protocol/IHttpRequestContext";
|
|
@@ -47,11 +49,7 @@ export interface IRestRoute<T extends IHttpRequest = any, U extends IHttpRespons
|
|
|
47
49
|
/**
|
|
48
50
|
* Example objects for the request.
|
|
49
51
|
*/
|
|
50
|
-
examples?:
|
|
51
|
-
id: string;
|
|
52
|
-
description?: string;
|
|
53
|
-
request: T;
|
|
54
|
-
}[];
|
|
52
|
+
examples?: IRestRouteRequestExample<T>[];
|
|
55
53
|
};
|
|
56
54
|
/**
|
|
57
55
|
* The type of the response object.
|
|
@@ -68,11 +66,7 @@ export interface IRestRoute<T extends IHttpRequest = any, U extends IHttpRespons
|
|
|
68
66
|
/**
|
|
69
67
|
* Example objects of the response.
|
|
70
68
|
*/
|
|
71
|
-
examples?:
|
|
72
|
-
id: string;
|
|
73
|
-
description?: string;
|
|
74
|
-
response: U;
|
|
75
|
-
}[];
|
|
69
|
+
examples?: IRestRouteResponseExample<U>[];
|
|
76
70
|
}[];
|
|
77
71
|
/**
|
|
78
72
|
* Exclude the route from being included in the spec file.
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
+
import type { IBaseRouteEntryPoint } from "./IBaseRouteEntryPoint";
|
|
1
2
|
import type { IRestRoute } from "./IRestRoute";
|
|
2
|
-
import type { ITag } from "./ITag";
|
|
3
3
|
/**
|
|
4
4
|
* Route entry points are used for exposing the REST routes from a package.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
/**
|
|
8
|
-
* The name of the REST routes.
|
|
9
|
-
*/
|
|
10
|
-
name: string;
|
|
11
|
-
/**
|
|
12
|
-
* The default base route name for the REST routes.
|
|
13
|
-
*/
|
|
14
|
-
defaultBaseRoute: string;
|
|
15
|
-
/**
|
|
16
|
-
* The tags for the REST routes.
|
|
17
|
-
*/
|
|
18
|
-
tags: ITag[];
|
|
19
|
-
/**
|
|
20
|
-
* The method to generate the REST routes.
|
|
21
|
-
*/
|
|
22
|
-
generateRoutes: (baseRouteName: string, componentName: string) => IRestRoute[];
|
|
23
|
-
}
|
|
6
|
+
export type IRestRouteEntryPoint = IBaseRouteEntryPoint<IRestRoute>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IRestRouteExample } from "./IRestRouteExample";
|
|
2
|
+
/**
|
|
3
|
+
* Interface which defines a REST route request example.
|
|
4
|
+
*/
|
|
5
|
+
export interface IRestRouteRequestExample<T> extends IRestRouteExample {
|
|
6
|
+
/**
|
|
7
|
+
* The example request object.
|
|
8
|
+
*/
|
|
9
|
+
request: T;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IRestRouteExample } from "./IRestRouteExample";
|
|
2
|
+
/**
|
|
3
|
+
* Interface which defines a REST route response example.
|
|
4
|
+
*/
|
|
5
|
+
export interface IRestRouteResponseExample<T> extends IRestRouteExample {
|
|
6
|
+
/**
|
|
7
|
+
* The example response object.
|
|
8
|
+
*/
|
|
9
|
+
response: T;
|
|
10
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { IBaseRoute } from "./IBaseRoute";
|
|
2
|
+
import type { IHttpRequest } from "../protocol/IHttpRequest";
|
|
2
3
|
import type { IHttpRequestContext } from "../protocol/IHttpRequestContext";
|
|
4
|
+
import type { IHttpResponse } from "../protocol/IHttpResponse";
|
|
3
5
|
/**
|
|
4
6
|
* Interface which defines a socket route.
|
|
5
7
|
*/
|
|
6
|
-
export interface ISocketRoute extends IBaseRoute {
|
|
8
|
+
export interface ISocketRoute<T extends IHttpRequest = any, U extends IHttpResponse = any> extends IBaseRoute {
|
|
7
9
|
/**
|
|
8
10
|
* The handler module.
|
|
9
11
|
*/
|
|
@@ -12,16 +14,12 @@ export interface ISocketRoute extends IBaseRoute {
|
|
|
12
14
|
* The request context.
|
|
13
15
|
*/
|
|
14
16
|
httpRequestContext: IHttpRequestContext,
|
|
15
|
-
/**
|
|
16
|
-
* The id of the socket the request is arriving on.
|
|
17
|
-
*/
|
|
18
|
-
socketId: string,
|
|
19
17
|
/**
|
|
20
18
|
* The request object.
|
|
21
19
|
*/
|
|
22
|
-
request:
|
|
20
|
+
request: T,
|
|
23
21
|
/**
|
|
24
|
-
*
|
|
22
|
+
* The function to emit an event.
|
|
25
23
|
*/
|
|
26
|
-
|
|
24
|
+
emit: (event: string, response: U) => Promise<void>) => void;
|
|
27
25
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IBaseRouteEntryPoint } from "./IBaseRouteEntryPoint";
|
|
2
|
+
import type { ISocketRoute } from "./ISocketRoute";
|
|
3
|
+
/**
|
|
4
|
+
* Route entry points are used for exposing the socket routes from a package.
|
|
5
|
+
*/
|
|
6
|
+
export type ISocketRouteEntryPoint = IBaseRouteEntryPoint<ISocketRoute>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IComponent } from "@twin.org/core";
|
|
2
|
+
import type { IHttpRequestIdentity } from "../protocol/IHttpRequestIdentity";
|
|
3
|
+
import type { IHttpResponse } from "../protocol/IHttpResponse";
|
|
4
|
+
import type { IHttpServerRequest } from "../protocol/IHttpServerRequest";
|
|
5
|
+
import type { IBaseRoute } from "../routes/IBaseRoute";
|
|
6
|
+
/**
|
|
7
|
+
* The definition for a base processor for handling REST routes.
|
|
8
|
+
*/
|
|
9
|
+
export interface IBaseRouteProcessor<T = IBaseRoute> extends IComponent {
|
|
10
|
+
/**
|
|
11
|
+
* Pre process the REST request for the specified route.
|
|
12
|
+
* @param request The request to handle.
|
|
13
|
+
* @param response The response data to send if any.
|
|
14
|
+
* @param route The route being requested, if a matching one was found.
|
|
15
|
+
* @param requestIdentity The identity context for the request.
|
|
16
|
+
* @param processorState The state handed through the processors.
|
|
17
|
+
* @returns Promise that resolves when the request is processed.
|
|
18
|
+
*/
|
|
19
|
+
pre?(request: IHttpServerRequest, response: IHttpResponse, route: T | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
|
|
20
|
+
[id: string]: unknown;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Post process the REST request for the specified route.
|
|
24
|
+
* @param request The request to handle.
|
|
25
|
+
* @param response The response data to send if any.
|
|
26
|
+
* @param route The route being requested, if a matching one was found.
|
|
27
|
+
* @param requestIdentity The identity context for the request.
|
|
28
|
+
* @param processorState The state handed through the processors.
|
|
29
|
+
* @returns Promise that resolves when the request is processed.
|
|
30
|
+
*/
|
|
31
|
+
post?(request: IHttpServerRequest, response: IHttpResponse, route: T | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
|
|
32
|
+
[id: string]: unknown;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IComponent } from "@twin.org/core";
|
|
2
|
+
/**
|
|
3
|
+
* The definition for a handler for a specific MIME type.
|
|
4
|
+
*/
|
|
5
|
+
export interface IMimeTypeProcessor extends IComponent {
|
|
6
|
+
/**
|
|
7
|
+
* Get the MIME types that this handler can handle.
|
|
8
|
+
* @returns The MIME types that this handler can handle.
|
|
9
|
+
*/
|
|
10
|
+
getTypes(): string[];
|
|
11
|
+
/**
|
|
12
|
+
* Handle content.
|
|
13
|
+
* @param body The body to process.
|
|
14
|
+
* @returns The processed body.
|
|
15
|
+
*/
|
|
16
|
+
handle(body: Uint8Array): Promise<unknown>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IBaseRouteProcessor } from "./IBaseRouteProcessor";
|
|
2
|
+
import type { IHttpRequestIdentity } from "../protocol/IHttpRequestIdentity";
|
|
3
|
+
import type { IHttpResponse } from "../protocol/IHttpResponse";
|
|
4
|
+
import type { IHttpServerRequest } from "../protocol/IHttpServerRequest";
|
|
5
|
+
import type { IRestRoute } from "../routes/IRestRoute";
|
|
6
|
+
/**
|
|
7
|
+
* The definition for a processor for handling REST routes.
|
|
8
|
+
*/
|
|
9
|
+
export interface IRestRouteProcessor extends IBaseRouteProcessor<IRestRoute> {
|
|
10
|
+
/**
|
|
11
|
+
* Process the REST request for the specified route.
|
|
12
|
+
* @param request The request to handle.
|
|
13
|
+
* @param response The response data to send if any.
|
|
14
|
+
* @param route The route being requested, if a matching one was found.
|
|
15
|
+
* @param requestIdentity The identity context for the request.
|
|
16
|
+
* @param processorState The state handed through the processors.
|
|
17
|
+
* @returns Promise that resolves when the request is processed.
|
|
18
|
+
*/
|
|
19
|
+
process?(request: IHttpServerRequest, response: IHttpResponse, route: IRestRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
|
|
20
|
+
[id: string]: unknown;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
}
|
package/dist/types/models/server/{IHttpRestRouteProcessor.d.ts → ISocketRouteProcessor.d.ts}
RENAMED
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IBaseRouteProcessor } from "./IBaseRouteProcessor";
|
|
2
2
|
import type { IHttpRequestIdentity } from "../protocol/IHttpRequestIdentity";
|
|
3
3
|
import type { IHttpResponse } from "../protocol/IHttpResponse";
|
|
4
4
|
import type { IHttpServerRequest } from "../protocol/IHttpServerRequest";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ISocketRoute } from "../routes/ISocketRoute";
|
|
6
6
|
/**
|
|
7
|
-
* The definition for a processor for handling
|
|
7
|
+
* The definition for a processor for handling socket routes.
|
|
8
8
|
*/
|
|
9
|
-
export interface
|
|
9
|
+
export interface ISocketRouteProcessor extends IBaseRouteProcessor<ISocketRoute> {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Process the connected event.
|
|
12
12
|
* @param request The request to handle.
|
|
13
|
-
* @param response The response data to send if any.
|
|
14
13
|
* @param route The route being requested, if a matching one was found.
|
|
15
|
-
* @param requestIdentity The identity context for the request.
|
|
16
14
|
* @param processorState The state handed through the processors.
|
|
17
15
|
* @returns Promise that resolves when the request is processed.
|
|
18
16
|
*/
|
|
19
|
-
|
|
17
|
+
connected?(request: IHttpServerRequest, route: ISocketRoute | undefined, processorState: {
|
|
20
18
|
[id: string]: unknown;
|
|
21
19
|
}): Promise<void>;
|
|
22
20
|
/**
|
|
23
|
-
* Process the
|
|
21
|
+
* Process the disconnected event.
|
|
24
22
|
* @param request The request to handle.
|
|
25
|
-
* @param response The response data to send if any.
|
|
26
23
|
* @param route The route being requested, if a matching one was found.
|
|
27
|
-
* @param requestIdentity The identity context for the request.
|
|
28
24
|
* @param processorState The state handed through the processors.
|
|
29
25
|
* @returns Promise that resolves when the request is processed.
|
|
30
26
|
*/
|
|
31
|
-
|
|
27
|
+
disconnected?(request: IHttpServerRequest, route: ISocketRoute | undefined, processorState: {
|
|
32
28
|
[id: string]: unknown;
|
|
33
29
|
}): Promise<void>;
|
|
34
30
|
/**
|
|
35
|
-
*
|
|
31
|
+
* Process the REST request for the specified route.
|
|
36
32
|
* @param request The request to handle.
|
|
37
33
|
* @param response The response data to send if any.
|
|
38
34
|
* @param route The route being requested, if a matching one was found.
|
|
39
35
|
* @param requestIdentity The identity context for the request.
|
|
40
36
|
* @param processorState The state handed through the processors.
|
|
37
|
+
* @param responseEmitter The function to emit a response.
|
|
41
38
|
* @returns Promise that resolves when the request is processed.
|
|
42
39
|
*/
|
|
43
|
-
|
|
40
|
+
process?(request: IHttpServerRequest, response: IHttpResponse, route: ISocketRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
|
|
44
41
|
[id: string]: unknown;
|
|
45
|
-
}): Promise<void>;
|
|
42
|
+
}, responseEmitter: (topic: string, response: IHttpResponse) => Promise<void>): Promise<void>;
|
|
46
43
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IRestRouteProcessor } from "./IRestRouteProcessor";
|
|
2
|
+
import type { ISocketRouteProcessor } from "./ISocketRouteProcessor";
|
|
2
3
|
import type { IWebServerOptions } from "./IWebServerOptions";
|
|
3
4
|
import type { IRestRoute } from "../routes/IRestRoute";
|
|
5
|
+
import type { ISocketRoute } from "../routes/ISocketRoute";
|
|
4
6
|
/**
|
|
5
7
|
* Interface describing a web server.
|
|
6
8
|
*/
|
|
@@ -12,12 +14,14 @@ export interface IWebServer<T> {
|
|
|
12
14
|
getInstance(): T;
|
|
13
15
|
/**
|
|
14
16
|
* Build the server.
|
|
15
|
-
* @param restRouteProcessors The
|
|
17
|
+
* @param restRouteProcessors The processors for incoming requests over REST.
|
|
16
18
|
* @param restRoutes The REST routes.
|
|
19
|
+
* @param socketRouteProcessors The processors for incoming requests over Sockets.
|
|
20
|
+
* @param socketRoutes The socket routes.
|
|
17
21
|
* @param options Options for building the server.
|
|
18
22
|
* @returns Nothing.
|
|
19
23
|
*/
|
|
20
|
-
build(restRouteProcessors
|
|
24
|
+
build(restRouteProcessors?: IRestRouteProcessor[], restRoutes?: IRestRoute[], socketRouteProcessors?: ISocketRouteProcessor[], socketRoutes?: ISocketRoute[], options?: IWebServerOptions): Promise<void>;
|
|
21
25
|
/**
|
|
22
26
|
* Start the server.
|
|
23
27
|
* @returns Nothing.
|
package/docs/changelog.md
CHANGED
|
@@ -22,11 +22,15 @@ Process the errors from the routes.
|
|
|
22
22
|
|
|
23
23
|
#### Parameters
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
##### err
|
|
26
|
+
|
|
27
|
+
`unknown`
|
|
26
28
|
|
|
27
29
|
The error to process.
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
##### includeStack?
|
|
32
|
+
|
|
33
|
+
`boolean`
|
|
30
34
|
|
|
31
35
|
Should the stack be included in the error.
|
|
32
36
|
|
|
@@ -54,15 +58,21 @@ Build an error response.
|
|
|
54
58
|
|
|
55
59
|
#### Parameters
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
##### response
|
|
62
|
+
|
|
63
|
+
[`IHttpResponse`](../interfaces/IHttpResponse.md)
|
|
58
64
|
|
|
59
65
|
The response to build the error into.
|
|
60
66
|
|
|
61
|
-
|
|
67
|
+
##### error
|
|
68
|
+
|
|
69
|
+
`IError`
|
|
62
70
|
|
|
63
71
|
The error to build the response for.
|
|
64
72
|
|
|
65
|
-
|
|
73
|
+
##### statusCode
|
|
74
|
+
|
|
75
|
+
`HttpStatusCode`
|
|
66
76
|
|
|
67
77
|
The status code to use for the error.
|
|
68
78
|
|