@twin.org/api-service 0.0.1-next.15 → 0.0.1-next.17

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.
@@ -211,21 +211,16 @@ async function serverSpec(httpRequestContext, componentName, request) {
211
211
  };
212
212
  }
213
213
 
214
- const restEntryPoints = [
215
- {
216
- name: "information",
217
- defaultBaseRoute: "",
218
- tags: tagsInformation,
219
- generateRoutes: generateRestRoutesInformation
220
- }
221
- ];
222
-
223
214
  // Copyright 2024 IOTA Stiftung.
224
215
  // SPDX-License-Identifier: Apache-2.0.
225
216
  /**
226
217
  * The information service for the server.
227
218
  */
228
219
  class InformationService {
220
+ /**
221
+ * The namespace supported by the information service.
222
+ */
223
+ static NAMESPACE = "information";
229
224
  /**
230
225
  * Runtime name for the class.
231
226
  */
@@ -252,15 +247,18 @@ class InformationService {
252
247
  _openApiSpec;
253
248
  /**
254
249
  * Create a new instance of InformationService.
255
- * @param serverInfo The server information.
256
- * @param openApiSpecPath The path to the spec file.
250
+ * @param options The options to create the service.
251
+ * @param options.config The configuration for the service.
257
252
  */
258
- constructor(serverInfo, openApiSpecPath) {
259
- this._serverInfo = serverInfo;
253
+ constructor(options) {
254
+ core.Guards.object(this.CLASS_NAME, "options", options);
255
+ core.Guards.object(this.CLASS_NAME, "options.config", options.config);
256
+ core.Guards.object(this.CLASS_NAME, "options.config.serverInfo", options.config.serverInfo);
257
+ this._serverInfo = options.config.serverInfo;
260
258
  this._healthInfo = {
261
259
  status: "ok"
262
260
  };
263
- this._openApiSpecPath = openApiSpecPath;
261
+ this._openApiSpecPath = options.config.openApiSpecPath;
264
262
  }
265
263
  /**
266
264
  * The service needs to be started when the application is initialized.
@@ -346,6 +344,15 @@ class InformationService {
346
344
  }
347
345
  }
348
346
 
347
+ const restEntryPoints = [
348
+ {
349
+ name: "information",
350
+ defaultBaseRoute: "",
351
+ tags: tagsInformation,
352
+ generateRoutes: generateRestRoutesInformation
353
+ }
354
+ ];
355
+
349
356
  exports.InformationService = InformationService;
350
357
  exports.generateRestRoutesInformation = generateRestRoutesInformation;
351
358
  exports.restEntryPoints = restEntryPoints;
@@ -1,4 +1,4 @@
1
- import { ComponentFactory, Is } from '@twin.org/core';
1
+ import { ComponentFactory, Is, Guards } from '@twin.org/core';
2
2
  import { HttpStatusCode } from '@twin.org/web';
3
3
  import { readFile } from 'node:fs/promises';
4
4
 
@@ -209,21 +209,16 @@ async function serverSpec(httpRequestContext, componentName, request) {
209
209
  };
210
210
  }
211
211
 
212
- const restEntryPoints = [
213
- {
214
- name: "information",
215
- defaultBaseRoute: "",
216
- tags: tagsInformation,
217
- generateRoutes: generateRestRoutesInformation
218
- }
219
- ];
220
-
221
212
  // Copyright 2024 IOTA Stiftung.
222
213
  // SPDX-License-Identifier: Apache-2.0.
223
214
  /**
224
215
  * The information service for the server.
225
216
  */
226
217
  class InformationService {
218
+ /**
219
+ * The namespace supported by the information service.
220
+ */
221
+ static NAMESPACE = "information";
227
222
  /**
228
223
  * Runtime name for the class.
229
224
  */
@@ -250,15 +245,18 @@ class InformationService {
250
245
  _openApiSpec;
251
246
  /**
252
247
  * Create a new instance of InformationService.
253
- * @param serverInfo The server information.
254
- * @param openApiSpecPath The path to the spec file.
248
+ * @param options The options to create the service.
249
+ * @param options.config The configuration for the service.
255
250
  */
256
- constructor(serverInfo, openApiSpecPath) {
257
- this._serverInfo = serverInfo;
251
+ constructor(options) {
252
+ Guards.object(this.CLASS_NAME, "options", options);
253
+ Guards.object(this.CLASS_NAME, "options.config", options.config);
254
+ Guards.object(this.CLASS_NAME, "options.config.serverInfo", options.config.serverInfo);
255
+ this._serverInfo = options.config.serverInfo;
258
256
  this._healthInfo = {
259
257
  status: "ok"
260
258
  };
261
- this._openApiSpecPath = openApiSpecPath;
259
+ this._openApiSpecPath = options.config.openApiSpecPath;
262
260
  }
263
261
  /**
264
262
  * The service needs to be started when the application is initialized.
@@ -344,4 +342,13 @@ class InformationService {
344
342
  }
345
343
  }
346
344
 
345
+ const restEntryPoints = [
346
+ {
347
+ name: "information",
348
+ defaultBaseRoute: "",
349
+ tags: tagsInformation,
350
+ generateRoutes: generateRestRoutesInformation
351
+ }
352
+ ];
353
+
347
354
  export { InformationService, generateRestRoutesInformation, restEntryPoints, serverHealth, serverInfo, serverSpec, tagsInformation };
@@ -1,3 +1,4 @@
1
1
  export * from "./informationRoutes";
2
- export * from "./restEntryPoints";
3
2
  export * from "./informationService";
3
+ export * from "./models/IInformationServiceConfig";
4
+ export * from "./restEntryPoints";
@@ -1,18 +1,25 @@
1
1
  import type { HealthStatus, IHealthInfo, IInformationComponent, IServerInfo } from "@twin.org/api-models";
2
+ import type { IInformationServiceConfig } from "./models/IInformationServiceConfig";
2
3
  /**
3
4
  * The information service for the server.
4
5
  */
5
6
  export declare class InformationService implements IInformationComponent {
7
+ /**
8
+ * The namespace supported by the information service.
9
+ */
10
+ static readonly NAMESPACE: string;
6
11
  /**
7
12
  * Runtime name for the class.
8
13
  */
9
14
  readonly CLASS_NAME: string;
10
15
  /**
11
16
  * Create a new instance of InformationService.
12
- * @param serverInfo The server information.
13
- * @param openApiSpecPath The path to the spec file.
17
+ * @param options The options to create the service.
18
+ * @param options.config The configuration for the service.
14
19
  */
15
- constructor(serverInfo: IServerInfo, openApiSpecPath?: string);
20
+ constructor(options: {
21
+ config: IInformationServiceConfig;
22
+ });
16
23
  /**
17
24
  * The service needs to be started when the application is initialized.
18
25
  * @returns Nothing.
@@ -0,0 +1,14 @@
1
+ import type { IServerInfo } from "@twin.org/api-models";
2
+ /**
3
+ * Configuration for the information service.
4
+ */
5
+ export interface IInformationServiceConfig {
6
+ /**
7
+ * The server information.
8
+ */
9
+ serverInfo: IServerInfo;
10
+ /**
11
+ * The path to the OpenAPI Spec.
12
+ */
13
+ openApiSpecPath?: string;
14
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/api-service - Changelog
2
2
 
3
- ## v0.0.1-next.15
3
+ ## v0.0.1-next.17
4
4
 
5
5
  - Initial Release
@@ -10,19 +10,19 @@ The information service for the server.
10
10
 
11
11
  ### new InformationService()
12
12
 
13
- > **new InformationService**(`serverInfo`, `openApiSpecPath`?): [`InformationService`](InformationService.md)
13
+ > **new InformationService**(`options`): [`InformationService`](InformationService.md)
14
14
 
15
15
  Create a new instance of InformationService.
16
16
 
17
17
  #### Parameters
18
18
 
19
- • **serverInfo**: `IServerInfo`
19
+ • **options**
20
20
 
21
- The server information.
21
+ The options to create the service.
22
22
 
23
- • **openApiSpecPath?**: `string`
23
+ • **options.config**: [`IInformationServiceConfig`](../interfaces/IInformationServiceConfig.md)
24
24
 
25
- The path to the spec file.
25
+ The configuration for the service.
26
26
 
27
27
  #### Returns
28
28
 
@@ -30,6 +30,14 @@ The path to the spec file.
30
30
 
31
31
  ## Properties
32
32
 
33
+ ### NAMESPACE
34
+
35
+ > `readonly` `static` **NAMESPACE**: `string` = `"information"`
36
+
37
+ The namespace supported by the information service.
38
+
39
+ ***
40
+
33
41
  ### CLASS\_NAME
34
42
 
35
43
  > `readonly` **CLASS\_NAME**: `string`
@@ -4,6 +4,10 @@
4
4
 
5
5
  - [InformationService](classes/InformationService.md)
6
6
 
7
+ ## Interfaces
8
+
9
+ - [IInformationServiceConfig](interfaces/IInformationServiceConfig.md)
10
+
7
11
  ## Variables
8
12
 
9
13
  - [tagsInformation](variables/tagsInformation.md)
@@ -0,0 +1,19 @@
1
+ # Interface: IInformationServiceConfig
2
+
3
+ Configuration for the information service.
4
+
5
+ ## Properties
6
+
7
+ ### serverInfo
8
+
9
+ > **serverInfo**: `IServerInfo`
10
+
11
+ The server information.
12
+
13
+ ***
14
+
15
+ ### openApiSpecPath?
16
+
17
+ > `optional` **openApiSpecPath**: `string`
18
+
19
+ The path to the OpenAPI Spec.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-service",
3
- "version": "0.0.1-next.15",
3
+ "version": "0.0.1-next.17",
4
4
  "description": "Information contract implementation and REST endpoint definitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/api-models": "0.0.1-next.15",
17
+ "@twin.org/api-models": "0.0.1-next.17",
18
18
  "@twin.org/core": "next",
19
19
  "@twin.org/nameof": "next",
20
20
  "@twin.org/web": "next"