@twin.org/api-models 0.0.1-next.1

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.
Files changed (89) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -0
  3. package/dist/cjs/index.cjs +90 -0
  4. package/dist/esm/index.mjs +87 -0
  5. package/dist/types/helpers/httpErrorHelper.d.ts +25 -0
  6. package/dist/types/index.d.ts +39 -0
  7. package/dist/types/models/api/IServerHealthResponse.d.ts +10 -0
  8. package/dist/types/models/api/IServerInfoResponse.d.ts +10 -0
  9. package/dist/types/models/api/IServerSpecResponse.d.ts +14 -0
  10. package/dist/types/models/config/IBaseRestClientConfig.d.ts +26 -0
  11. package/dist/types/models/config/IBaseSocketClientConfig.d.ts +18 -0
  12. package/dist/types/models/protocol/IHttpRequest.d.ts +24 -0
  13. package/dist/types/models/protocol/IHttpRequestContext.d.ts +17 -0
  14. package/dist/types/models/protocol/IHttpRequestIdentity.d.ts +13 -0
  15. package/dist/types/models/protocol/IHttpRequestPathParams.d.ts +6 -0
  16. package/dist/types/models/protocol/IHttpRequestQuery.d.ts +6 -0
  17. package/dist/types/models/protocol/IHttpResponse.d.ts +18 -0
  18. package/dist/types/models/protocol/IHttpServerRequest.d.ts +15 -0
  19. package/dist/types/models/requests/INoContentRequest.d.ts +22 -0
  20. package/dist/types/models/responses/errors/IBadRequestResponse.d.ts +15 -0
  21. package/dist/types/models/responses/errors/IConflictResponse.d.ts +20 -0
  22. package/dist/types/models/responses/errors/IForbiddenResponse.d.ts +15 -0
  23. package/dist/types/models/responses/errors/IInternalServerErrorResponse.d.ts +15 -0
  24. package/dist/types/models/responses/errors/INotFoundResponse.d.ts +20 -0
  25. package/dist/types/models/responses/errors/IUnauthorizedResponse.d.ts +15 -0
  26. package/dist/types/models/responses/errors/IUnprocessableEntityResponse.d.ts +15 -0
  27. package/dist/types/models/responses/success/IAcceptedResponse.d.ts +19 -0
  28. package/dist/types/models/responses/success/ICreatedResponse.d.ts +19 -0
  29. package/dist/types/models/responses/success/INoContentResponse.d.ts +10 -0
  30. package/dist/types/models/responses/success/IOkResponse.d.ts +10 -0
  31. package/dist/types/models/routes/IBaseRoute.d.ts +17 -0
  32. package/dist/types/models/routes/IRestRoute.d.ts +81 -0
  33. package/dist/types/models/routes/IRestRouteEntryPoint.d.ts +23 -0
  34. package/dist/types/models/routes/IRestRouteResponseAttachmentOptions.d.ts +17 -0
  35. package/dist/types/models/routes/IRestRouteResponseOptions.d.ts +10 -0
  36. package/dist/types/models/routes/ISocketRoute.d.ts +27 -0
  37. package/dist/types/models/routes/ITag.d.ts +13 -0
  38. package/dist/types/models/server/IHttpRestRouteProcessor.d.ts +46 -0
  39. package/dist/types/models/server/IWebServer.d.ts +31 -0
  40. package/dist/types/models/server/IWebServerOptions.d.ts +34 -0
  41. package/dist/types/models/services/IHealthInfo.d.ts +27 -0
  42. package/dist/types/models/services/IInformationComponent.d.ts +38 -0
  43. package/dist/types/models/services/IServerInfo.d.ts +13 -0
  44. package/dist/types/models/services/healthStatus.d.ts +21 -0
  45. package/docs/changelog.md +5 -0
  46. package/docs/examples.md +1 -0
  47. package/docs/reference/classes/HttpErrorHelper.md +71 -0
  48. package/docs/reference/index.md +53 -0
  49. package/docs/reference/interfaces/IAcceptedResponse.md +25 -0
  50. package/docs/reference/interfaces/IBadRequestResponse.md +19 -0
  51. package/docs/reference/interfaces/IBaseRestClientConfig.md +43 -0
  52. package/docs/reference/interfaces/IBaseRoute.md +32 -0
  53. package/docs/reference/interfaces/IBaseSocketClientConfig.md +27 -0
  54. package/docs/reference/interfaces/IConflictResponse.md +27 -0
  55. package/docs/reference/interfaces/ICreatedResponse.md +25 -0
  56. package/docs/reference/interfaces/IForbiddenResponse.md +19 -0
  57. package/docs/reference/interfaces/IHealthInfo.md +19 -0
  58. package/docs/reference/interfaces/IHttpRequest.md +44 -0
  59. package/docs/reference/interfaces/IHttpRequestContext.md +51 -0
  60. package/docs/reference/interfaces/IHttpRequestIdentity.md +23 -0
  61. package/docs/reference/interfaces/IHttpRequestPathParams.md +7 -0
  62. package/docs/reference/interfaces/IHttpRequestQuery.md +7 -0
  63. package/docs/reference/interfaces/IHttpResponse.md +31 -0
  64. package/docs/reference/interfaces/IHttpRestRouteProcessor.md +115 -0
  65. package/docs/reference/interfaces/IHttpServerRequest.md +75 -0
  66. package/docs/reference/interfaces/IInformationComponent.md +97 -0
  67. package/docs/reference/interfaces/IInternalServerErrorResponse.md +19 -0
  68. package/docs/reference/interfaces/INoContentRequest.md +55 -0
  69. package/docs/reference/interfaces/INoContentResponse.md +11 -0
  70. package/docs/reference/interfaces/INotFoundResponse.md +27 -0
  71. package/docs/reference/interfaces/IOkResponse.md +11 -0
  72. package/docs/reference/interfaces/IRestRoute.md +137 -0
  73. package/docs/reference/interfaces/IRestRouteEntryPoint.md +45 -0
  74. package/docs/reference/interfaces/IRestRouteResponseAttachmentOptions.md +27 -0
  75. package/docs/reference/interfaces/IRestRouteResponseOptions.md +11 -0
  76. package/docs/reference/interfaces/IServerHealthResponse.md +11 -0
  77. package/docs/reference/interfaces/IServerInfo.md +19 -0
  78. package/docs/reference/interfaces/IServerInfoResponse.md +11 -0
  79. package/docs/reference/interfaces/IServerSpecResponse.md +19 -0
  80. package/docs/reference/interfaces/ISocketRoute.md +73 -0
  81. package/docs/reference/interfaces/ITag.md +19 -0
  82. package/docs/reference/interfaces/IUnauthorizedResponse.md +19 -0
  83. package/docs/reference/interfaces/IUnprocessableEntityResponse.md +19 -0
  84. package/docs/reference/interfaces/IWebServer.md +77 -0
  85. package/docs/reference/interfaces/IWebServerOptions.md +75 -0
  86. package/docs/reference/type-aliases/HealthStatus.md +5 -0
  87. package/docs/reference/variables/HealthStatus.md +25 -0
  88. package/locales/en.json +9 -0
  89. package/package.json +65 -0
@@ -0,0 +1,22 @@
1
+ import type { IHttpRequest } from "../protocol/IHttpRequest";
2
+ /**
3
+ * A REST request with no input parameters.
4
+ */
5
+ export interface INoContentRequest extends IHttpRequest {
6
+ /**
7
+ * Incoming Http Headers.
8
+ */
9
+ headers?: never;
10
+ /**
11
+ * The path parameters.
12
+ */
13
+ pathParams?: never;
14
+ /**
15
+ * The query parameters.
16
+ */
17
+ query?: never;
18
+ /**
19
+ * Data to return send as the body.
20
+ */
21
+ body?: never;
22
+ }
@@ -0,0 +1,15 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The server cannot process the request, see the content for more details.
5
+ */
6
+ export interface IBadRequestResponse {
7
+ /**
8
+ * Response status code.
9
+ */
10
+ statusCode: typeof HttpStatusCode.badRequest;
11
+ /**
12
+ * The body which contains the error.
13
+ */
14
+ body: IError;
15
+ }
@@ -0,0 +1,20 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The request resulted in a conflicting operation, see the content for more details.
5
+ */
6
+ export interface IConflictResponse {
7
+ /**
8
+ * Response status code.
9
+ */
10
+ statusCode: typeof HttpStatusCode.conflict;
11
+ /**
12
+ * The body which contains the error.
13
+ */
14
+ body: IError & {
15
+ /**
16
+ * The conflicting items.
17
+ */
18
+ conflicts: string[];
19
+ };
20
+ }
@@ -0,0 +1,15 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The operation that you tried to perform is not possible, see the content for more details.
5
+ */
6
+ export interface IForbiddenResponse {
7
+ /**
8
+ * Response status code.
9
+ */
10
+ statusCode: typeof HttpStatusCode.forbidden;
11
+ /**
12
+ * The body which contains the error.
13
+ */
14
+ body: IError;
15
+ }
@@ -0,0 +1,15 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The server has encountered a situation it does not know how to handle, see the content for more details.
5
+ */
6
+ export interface IInternalServerErrorResponse {
7
+ /**
8
+ * Response status code.
9
+ */
10
+ statusCode: typeof HttpStatusCode.internalServerError;
11
+ /**
12
+ * The body which contains the error.
13
+ */
14
+ body: IError;
15
+ }
@@ -0,0 +1,20 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The resource you tried to access does not exist, see the content for more details.
5
+ */
6
+ export interface INotFoundResponse {
7
+ /**
8
+ * Response status code.
9
+ */
10
+ statusCode: typeof HttpStatusCode.notFound;
11
+ /**
12
+ * The body which contains the error.
13
+ */
14
+ body: IError & {
15
+ /**
16
+ * The id if the item that was not found.
17
+ */
18
+ notFoundId?: string;
19
+ };
20
+ }
@@ -0,0 +1,15 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * You are not authorized to use the API or no credentials were supplied, see the content for more details.
5
+ */
6
+ export interface IUnauthorizedResponse {
7
+ /**
8
+ * Response status code.
9
+ */
10
+ statusCode: typeof HttpStatusCode.unauthorized;
11
+ /**
12
+ * The body which contains the error.
13
+ */
14
+ body: IError;
15
+ }
@@ -0,0 +1,15 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The server cannot process the request, see the content for more details.
5
+ */
6
+ export interface IUnprocessableEntityResponse {
7
+ /**
8
+ * Response status code.
9
+ */
10
+ statusCode: typeof HttpStatusCode.unprocessableEntity;
11
+ /**
12
+ * The body which contains the error.
13
+ */
14
+ body: IError;
15
+ }
@@ -0,0 +1,19 @@
1
+ import type { HttpStatusCode } from "@twin.org/web";
2
+ /**
3
+ * The rest request ended in accepted response.
4
+ */
5
+ export interface IAcceptedResponse {
6
+ /**
7
+ * Response status code.
8
+ */
9
+ statusCode: typeof HttpStatusCode.accepted;
10
+ /**
11
+ * Additional response headers.
12
+ */
13
+ headers: {
14
+ /**
15
+ * The location where the resource was accepted.
16
+ */
17
+ location: string;
18
+ };
19
+ }
@@ -0,0 +1,19 @@
1
+ import type { HeaderTypes, HttpStatusCode } from "@twin.org/web";
2
+ /**
3
+ * The rest request ended in created response.
4
+ */
5
+ export interface ICreatedResponse {
6
+ /**
7
+ * Response status code.
8
+ */
9
+ statusCode: typeof HttpStatusCode.created;
10
+ /**
11
+ * Additional response headers.
12
+ */
13
+ headers: {
14
+ /**
15
+ * The location where the resource was created.
16
+ */
17
+ [HeaderTypes.Location]: string;
18
+ };
19
+ }
@@ -0,0 +1,10 @@
1
+ import type { HttpStatusCode } from "@twin.org/web";
2
+ /**
3
+ * The rest request ended in success with no data.
4
+ */
5
+ export interface INoContentResponse {
6
+ /**
7
+ * Response status code.
8
+ */
9
+ statusCode: typeof HttpStatusCode.noContent;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { HttpStatusCode } from "@twin.org/web";
2
+ /**
3
+ * The rest request ended in success with no data.
4
+ */
5
+ export interface IOkResponse {
6
+ /**
7
+ * Response status code.
8
+ */
9
+ statusCode: typeof HttpStatusCode.ok;
10
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Interface which defines a route.
3
+ */
4
+ export interface IBaseRoute {
5
+ /**
6
+ * The id of the operation.
7
+ */
8
+ operationId: string;
9
+ /**
10
+ * The path to use for routing.
11
+ */
12
+ path: string;
13
+ /**
14
+ * Skips the authentication for this route.
15
+ */
16
+ skipAuth?: boolean;
17
+ }
@@ -0,0 +1,81 @@
1
+ import type { HttpMethod } from "@twin.org/web";
2
+ import type { IBaseRoute } from "./IBaseRoute";
3
+ import type { IRestRouteResponseOptions } from "./IRestRouteResponseOptions";
4
+ import type { IHttpRequest } from "../protocol/IHttpRequest";
5
+ import type { IHttpRequestContext } from "../protocol/IHttpRequestContext";
6
+ import type { IHttpResponse } from "../protocol/IHttpResponse";
7
+ /**
8
+ * Interface which defines a REST route.
9
+ */
10
+ export interface IRestRoute<T extends IHttpRequest = any, U extends IHttpResponse & IRestRouteResponseOptions = any> extends IBaseRoute {
11
+ /**
12
+ * Summary of what task the operation performs.
13
+ */
14
+ summary: string;
15
+ /**
16
+ * Tag for the operation.
17
+ */
18
+ tag: string;
19
+ /**
20
+ * The http method.
21
+ */
22
+ method: HttpMethod;
23
+ /**
24
+ * The handler module.
25
+ */
26
+ handler: (
27
+ /**
28
+ * The http request context.
29
+ */
30
+ httpRequestContext: IHttpRequestContext,
31
+ /**
32
+ * The request object, combined query param, path params and body.
33
+ */
34
+ request: T) => Promise<U>;
35
+ /**
36
+ * The type of the request object.
37
+ */
38
+ requestType?: {
39
+ /**
40
+ * The object type for the request.
41
+ */
42
+ type: string;
43
+ /**
44
+ * The mime type of the request, defaults to "application/json" if there is a body.
45
+ */
46
+ mimeType?: string;
47
+ /**
48
+ * Example objects for the request.
49
+ */
50
+ examples?: {
51
+ id: string;
52
+ description?: string;
53
+ request: T;
54
+ }[];
55
+ };
56
+ /**
57
+ * The type of the response object.
58
+ */
59
+ responseType?: {
60
+ /**
61
+ * The object type of the response.
62
+ */
63
+ type: string;
64
+ /**
65
+ * The mime type of the response, defaults to "application/json" if there is a body.
66
+ */
67
+ mimeType?: string;
68
+ /**
69
+ * Example objects of the response.
70
+ */
71
+ examples?: {
72
+ id: string;
73
+ description?: string;
74
+ response: U;
75
+ }[];
76
+ }[];
77
+ /**
78
+ * Exclude the route from being included in the spec file.
79
+ */
80
+ excludeFromSpec?: boolean;
81
+ }
@@ -0,0 +1,23 @@
1
+ import type { IRestRoute } from "./IRestRoute";
2
+ import type { ITag } from "./ITag";
3
+ /**
4
+ * Route entry points are used for exposing the REST routes from a package.
5
+ */
6
+ export interface IRestRouteEntryPoint {
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
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Interface which defines a REST route response for attachments.
3
+ */
4
+ export interface IRestRouteResponseAttachmentOptions {
5
+ /**
6
+ * The content type to use in the response.
7
+ */
8
+ mimeType?: string;
9
+ /**
10
+ * The filename to use in content disposition.
11
+ */
12
+ filename?: string;
13
+ /**
14
+ * Whether to inline the content.
15
+ */
16
+ inline?: boolean;
17
+ }
@@ -0,0 +1,10 @@
1
+ import type { IRestRouteResponseAttachmentOptions } from "./IRestRouteResponseAttachmentOptions";
2
+ /**
3
+ * Interface which defines a REST route response.
4
+ */
5
+ export interface IRestRouteResponseOptions {
6
+ /**
7
+ * Additional options that can be used to control the response.
8
+ */
9
+ attachment?: IRestRouteResponseAttachmentOptions;
10
+ }
@@ -0,0 +1,27 @@
1
+ import type { IBaseRoute } from "./IBaseRoute";
2
+ import type { IHttpRequestContext } from "../protocol/IHttpRequestContext";
3
+ /**
4
+ * Interface which defines a socket route.
5
+ */
6
+ export interface ISocketRoute extends IBaseRoute {
7
+ /**
8
+ * The handler module.
9
+ */
10
+ handler: (
11
+ /**
12
+ * The request context.
13
+ */
14
+ httpRequestContext: IHttpRequestContext,
15
+ /**
16
+ * The id of the socket the request is arriving on.
17
+ */
18
+ socketId: string,
19
+ /**
20
+ * The request object.
21
+ */
22
+ request: unknown,
23
+ /**
24
+ * Method to emit data on the socket.
25
+ */
26
+ emitter: (topic: string, response?: unknown) => Promise<void>) => Promise<void>;
27
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Tag for routes used to generate OpenAPI information.
3
+ */
4
+ export interface ITag {
5
+ /**
6
+ * The name of the tag.
7
+ */
8
+ name: string;
9
+ /**
10
+ * Description for the tag.
11
+ */
12
+ description: string;
13
+ }
@@ -0,0 +1,46 @@
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 { IRestRoute } from "../routes/IRestRoute";
6
+ /**
7
+ * The definition for a processor for handling REST routes.
8
+ */
9
+ export interface IHttpRestRouteProcessor 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: IRestRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
20
+ [id: string]: unknown;
21
+ }): Promise<void>;
22
+ /**
23
+ * 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
+ process?(request: IHttpServerRequest, response: IHttpResponse, route: IRestRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
32
+ [id: string]: unknown;
33
+ }): Promise<void>;
34
+ /**
35
+ * Post process the REST request for the specified route.
36
+ * @param request The request to handle.
37
+ * @param response The response data to send if any.
38
+ * @param route The route being requested, if a matching one was found.
39
+ * @param requestIdentity The identity context for the request.
40
+ * @param processorState The state handed through the processors.
41
+ * @returns Promise that resolves when the request is processed.
42
+ */
43
+ post?(request: IHttpServerRequest, response: IHttpResponse, route: IRestRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
44
+ [id: string]: unknown;
45
+ }): Promise<void>;
46
+ }
@@ -0,0 +1,31 @@
1
+ import type { IHttpRestRouteProcessor } from "./IHttpRestRouteProcessor";
2
+ import type { IWebServerOptions } from "./IWebServerOptions";
3
+ import type { IRestRoute } from "../routes/IRestRoute";
4
+ /**
5
+ * Interface describing a web server.
6
+ */
7
+ export interface IWebServer<T> {
8
+ /**
9
+ * Get the web server instance.
10
+ * @returns The web server instance.
11
+ */
12
+ getInstance(): T;
13
+ /**
14
+ * Build the server.
15
+ * @param restRouteProcessors The hooks to process the incoming requests.
16
+ * @param restRoutes The REST routes.
17
+ * @param options Options for building the server.
18
+ * @returns Nothing.
19
+ */
20
+ build(restRouteProcessors: IHttpRestRouteProcessor[], restRoutes: IRestRoute[], options?: IWebServerOptions): Promise<void>;
21
+ /**
22
+ * Start the server.
23
+ * @returns Nothing.
24
+ */
25
+ start(): Promise<void>;
26
+ /**
27
+ * Stop the server.
28
+ * @returns Nothing.
29
+ */
30
+ stop(): Promise<void>;
31
+ }
@@ -0,0 +1,34 @@
1
+ import type { HttpMethod } from "@twin.org/web";
2
+ /**
3
+ * Options for the web server.
4
+ */
5
+ export interface IWebServerOptions {
6
+ /**
7
+ * The port to bind the web server to.
8
+ * @default 3000
9
+ */
10
+ port?: number;
11
+ /**
12
+ * The address to bind the web server to.
13
+ * @default localhost
14
+ */
15
+ host?: string;
16
+ /**
17
+ * The methods that the server accepts.
18
+ * @default ["GET", "PUT", "POST", "DELETE", "OPTIONS"]
19
+ */
20
+ methods?: HttpMethod[];
21
+ /**
22
+ * Any additional allowed headers.
23
+ */
24
+ allowedHeaders?: string[];
25
+ /**
26
+ * And additional exposed headers.
27
+ */
28
+ exposedHeaders?: string[];
29
+ /**
30
+ * The allowed CORS domains.
31
+ * @default ["*"]
32
+ */
33
+ corsOrigins?: string | string[];
34
+ }
@@ -0,0 +1,27 @@
1
+ import type { HealthStatus } from "./healthStatus";
2
+ /**
3
+ * The status of the server.
4
+ */
5
+ export interface IHealthInfo {
6
+ /**
7
+ * The status.
8
+ */
9
+ status: HealthStatus;
10
+ /**
11
+ * The status of the components.
12
+ */
13
+ components?: {
14
+ /**
15
+ * The name of the component.
16
+ */
17
+ name: string;
18
+ /**
19
+ * The status of the component.
20
+ */
21
+ status: HealthStatus;
22
+ /**
23
+ * The details for the status.
24
+ */
25
+ details?: string;
26
+ }[];
27
+ }
@@ -0,0 +1,38 @@
1
+ import type { IComponent } from "@twin.org/core";
2
+ import type { HealthStatus } from "./healthStatus";
3
+ import type { IHealthInfo } from "./IHealthInfo";
4
+ import type { IServerInfo } from "./IServerInfo";
5
+ /**
6
+ * The information component for the server.
7
+ */
8
+ export interface IInformationComponent extends IComponent {
9
+ /**
10
+ * Get the server information.
11
+ * @returns The service information.
12
+ */
13
+ info(): Promise<IServerInfo>;
14
+ /**
15
+ * Get the OpenAPI spec.
16
+ * @returns The OpenAPI spec.
17
+ */
18
+ spec(): Promise<unknown>;
19
+ /**
20
+ * Get the server health.
21
+ * @returns The service health.
22
+ */
23
+ health(): Promise<IHealthInfo>;
24
+ /**
25
+ * Set the status of a component.
26
+ * @param name The component name.
27
+ * @param status The status of the component.
28
+ * @param details The details for the status.
29
+ * @returns Nothing.
30
+ */
31
+ setComponentHealth(name: string, status: HealthStatus, details?: string): Promise<void>;
32
+ /**
33
+ * Remove the status of a component.
34
+ * @param name The component name.
35
+ * @returns Nothing.
36
+ */
37
+ removeComponentHealth(name: string): Promise<void>;
38
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The information about the server.
3
+ */
4
+ export interface IServerInfo {
5
+ /**
6
+ * The application name.
7
+ */
8
+ name: string;
9
+ /**
10
+ * The version of the server.
11
+ */
12
+ version: string;
13
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The health status of the component.
3
+ */
4
+ export declare const HealthStatus: {
5
+ /**
6
+ * OK.
7
+ */
8
+ readonly Ok: "ok";
9
+ /**
10
+ * Warning.
11
+ */
12
+ readonly Warning: "warning";
13
+ /**
14
+ * Error.
15
+ */
16
+ readonly Error: "error";
17
+ };
18
+ /**
19
+ * The health status of the component.
20
+ */
21
+ export type HealthStatus = (typeof HealthStatus)[keyof typeof HealthStatus];
@@ -0,0 +1,5 @@
1
+ # @twin.org/api-models - Changelog
2
+
3
+ ## v0.0.1
4
+
5
+ - Initial Release
@@ -0,0 +1 @@
1
+ # @twin.org/api-models - Examples