@twin.org/api-rest-client 0.0.3-next.4 → 0.0.3-next.40
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/README.md +1 -1
- package/dist/es/healthRestClient.js +35 -0
- package/dist/es/healthRestClient.js.map +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/informationRestClient.js +10 -21
- package/dist/es/informationRestClient.js.map +1 -1
- package/dist/types/healthRestClient.d.ts +30 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/informationRestClient.d.ts +11 -16
- package/docs/changelog.md +607 -53
- package/docs/examples.md +64 -1
- package/docs/reference/classes/HealthRestClient.md +145 -0
- package/docs/reference/classes/InformationRestClient.md +84 -64
- package/docs/reference/index.md +1 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { BaseRestClient } from "@twin.org/api-core";
|
|
4
|
+
/**
|
|
5
|
+
* The client to connect to the health service.
|
|
6
|
+
*/
|
|
7
|
+
export class HealthRestClient extends BaseRestClient {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static CLASS_NAME = "HealthRestClient";
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of HealthRestClient.
|
|
14
|
+
* @param config The configuration for the client.
|
|
15
|
+
*/
|
|
16
|
+
constructor(config) {
|
|
17
|
+
super("HealthRestClient", config, "");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns the class name of the component.
|
|
21
|
+
* @returns The class name of the component.
|
|
22
|
+
*/
|
|
23
|
+
className() {
|
|
24
|
+
return HealthRestClient.CLASS_NAME;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the server health.
|
|
28
|
+
* @returns The service health.
|
|
29
|
+
*/
|
|
30
|
+
async healthStatus() {
|
|
31
|
+
const response = await this.fetch("/health", "GET");
|
|
32
|
+
return response.body;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=healthRestClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"healthRestClient.js","sourceRoot":"","sources":["../../src/healthRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAUpD;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,cAAc;IACnD;;OAEG;IACI,MAAM,CAAU,UAAU,sBAAsC;IAEvE;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,qBAA6B,MAAM,EAAE,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,gBAAgB,CAAC,UAAU,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,YAAY;QAIxB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAA2C,SAAS,EAAE,KAAK,CAAC,CAAC;QAC9F,OAAO,QAAQ,CAAC,IAAI,CAAC;IACtB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type {\n\tIBaseRestClientConfig,\n\tIHealthComponent,\n\tINoContentRequest,\n\tIServerHealthResponse\n} from \"@twin.org/api-models\";\nimport type { HealthStatus, IHealth } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * The client to connect to the health service.\n */\nexport class HealthRestClient extends BaseRestClient implements IHealthComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<HealthRestClient>();\n\n\t/**\n\t * Create a new instance of HealthRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(nameof<HealthRestClient>(), config, \"\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn HealthRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the server health.\n\t * @returns The service health.\n\t */\n\tpublic async healthStatus(): Promise<{\n\t\tstatus: HealthStatus;\n\t\tcomponents: IHealth[];\n\t}> {\n\t\tconst response = await this.fetch<INoContentRequest, IServerHealthResponse>(\"/health\", \"GET\");\n\t\treturn response.body;\n\t}\n}\n"]}
|
package/dist/es/index.js
CHANGED
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,4BAA4B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./informationRestClient.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./healthRestClient.js\";\nexport * from \"./informationRestClient.js\";\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { BaseRestClient } from "@twin.org/api-core";
|
|
4
|
-
import { NotSupportedError } from "@twin.org/core";
|
|
5
4
|
/**
|
|
6
5
|
* The client to connect to the information service.
|
|
7
6
|
*/
|
|
@@ -57,30 +56,20 @@ export class InformationRestClient extends BaseRestClient {
|
|
|
57
56
|
return response.body;
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @returns
|
|
59
|
+
* Is the server live.
|
|
60
|
+
* @returns True if the server is live.
|
|
62
61
|
*/
|
|
63
|
-
async
|
|
64
|
-
const response = await this.fetch("/
|
|
65
|
-
return response.body;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Set the status of a component.
|
|
69
|
-
* @param name The component name.
|
|
70
|
-
* @param status The status of the component.
|
|
71
|
-
* @param details The details for the status.
|
|
72
|
-
* @returns Nothing.
|
|
73
|
-
*/
|
|
74
|
-
async setComponentHealth(name, status, details) {
|
|
75
|
-
throw new NotSupportedError(InformationRestClient.CLASS_NAME, "\"setComponentHealth\"");
|
|
62
|
+
async livez() {
|
|
63
|
+
const response = await this.fetch("/livez", "GET");
|
|
64
|
+
return { status: response.body };
|
|
76
65
|
}
|
|
77
66
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @
|
|
80
|
-
* @returns Nothing.
|
|
67
|
+
* Is the server ready.
|
|
68
|
+
* @returns True if the server is ready.
|
|
81
69
|
*/
|
|
82
|
-
async
|
|
83
|
-
|
|
70
|
+
async readyz() {
|
|
71
|
+
const response = await this.fetch("/readyz", "GET");
|
|
72
|
+
return { status: response.body };
|
|
84
73
|
}
|
|
85
74
|
}
|
|
86
75
|
//# sourceMappingURL=informationRestClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"informationRestClient.js","sourceRoot":"","sources":["../../src/informationRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"informationRestClient.js","sourceRoot":"","sources":["../../src/informationRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAepD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,cA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OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;IAClC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type {\n\tIBaseRestClientConfig,\n\tIInformationComponent,\n\tINoContentRequest,\n\tIServerFavIconResponse,\n\tIServerInfo,\n\tIServerInfoResponse,\n\tIServerLivezResponse,\n\tIServerReadyzResponse,\n\tIServerRootResponse,\n\tIServerSpecResponse\n} from \"@twin.org/api-models\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * The client to connect to the information service.\n */\nexport class InformationRestClient extends BaseRestClient implements IInformationComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<InformationRestClient>();\n\n\t/**\n\t * Create a new instance of InformationRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(nameof<InformationRestClient>(), config, \"\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn InformationRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the server root.\n\t * @returns The root root.\n\t */\n\tpublic async root(): Promise<string> {\n\t\tconst response = await this.fetch<INoContentRequest, IServerRootResponse>(\"/\", \"GET\");\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get the server information.\n\t * @returns The service information.\n\t */\n\tpublic async info(): Promise<IServerInfo> {\n\t\tconst response = await this.fetch<INoContentRequest, IServerInfoResponse>(\"/info\", \"GET\");\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get the favicon.\n\t * @returns The favicon.\n\t */\n\tpublic async favicon(): Promise<Uint8Array | undefined> {\n\t\tconst response = await this.fetch<INoContentRequest, IServerFavIconResponse>(\n\t\t\t\"/favicon.ico\",\n\t\t\t\"GET\"\n\t\t);\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get the OpenAPI spec.\n\t * @returns The OpenAPI spec.\n\t */\n\tpublic async spec(): Promise<unknown> {\n\t\tconst response = await this.fetch<INoContentRequest, IServerSpecResponse>(\"/spec\", \"GET\");\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Is the server live.\n\t * @returns True if the server is live.\n\t */\n\tpublic async livez(): Promise<{ status: \"alive\" | \"dead\" }> {\n\t\tconst response = await this.fetch<INoContentRequest, IServerLivezResponse>(\"/livez\", \"GET\");\n\t\treturn { status: response.body };\n\t}\n\n\t/**\n\t * Is the server ready.\n\t * @returns True if the server is ready.\n\t */\n\tpublic async readyz(): Promise<{ status: \"ready\" | \"not ready\" }> {\n\t\tconst response = await this.fetch<INoContentRequest, IServerReadyzResponse>(\"/readyz\", \"GET\");\n\t\treturn { status: response.body };\n\t}\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseRestClient } from "@twin.org/api-core";
|
|
2
|
+
import type { IBaseRestClientConfig, IHealthComponent } from "@twin.org/api-models";
|
|
3
|
+
import type { HealthStatus, IHealth } from "@twin.org/core";
|
|
4
|
+
/**
|
|
5
|
+
* The client to connect to the health service.
|
|
6
|
+
*/
|
|
7
|
+
export declare class HealthRestClient extends BaseRestClient implements IHealthComponent {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of HealthRestClient.
|
|
14
|
+
* @param config The configuration for the client.
|
|
15
|
+
*/
|
|
16
|
+
constructor(config: IBaseRestClientConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Returns the class name of the component.
|
|
19
|
+
* @returns The class name of the component.
|
|
20
|
+
*/
|
|
21
|
+
className(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Get the server health.
|
|
24
|
+
* @returns The service health.
|
|
25
|
+
*/
|
|
26
|
+
healthStatus(): Promise<{
|
|
27
|
+
status: HealthStatus;
|
|
28
|
+
components: IHealth[];
|
|
29
|
+
}>;
|
|
30
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseRestClient } from "@twin.org/api-core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IBaseRestClientConfig, IInformationComponent, IServerInfo } from "@twin.org/api-models";
|
|
3
3
|
/**
|
|
4
4
|
* The client to connect to the information service.
|
|
5
5
|
*/
|
|
@@ -39,22 +39,17 @@ export declare class InformationRestClient extends BaseRestClient implements IIn
|
|
|
39
39
|
*/
|
|
40
40
|
spec(): Promise<unknown>;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @returns
|
|
42
|
+
* Is the server live.
|
|
43
|
+
* @returns True if the server is live.
|
|
44
44
|
*/
|
|
45
|
-
|
|
45
|
+
livez(): Promise<{
|
|
46
|
+
status: "alive" | "dead";
|
|
47
|
+
}>;
|
|
46
48
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
49
|
-
* @param status The status of the component.
|
|
50
|
-
* @param details The details for the status.
|
|
51
|
-
* @returns Nothing.
|
|
49
|
+
* Is the server ready.
|
|
50
|
+
* @returns True if the server is ready.
|
|
52
51
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @param name The component name.
|
|
57
|
-
* @returns Nothing.
|
|
58
|
-
*/
|
|
59
|
-
removeComponentHealth(name: string): Promise<void>;
|
|
52
|
+
readyz(): Promise<{
|
|
53
|
+
status: "ready" | "not ready";
|
|
54
|
+
}>;
|
|
60
55
|
}
|