@twin.org/engine-server 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # TWIN Engine Server
2
2
 
3
- Engine implementation for a server.
3
+ Engine Server exposes runtime capabilities through REST and socket routes and integrates hosting concerns with engine orchestration. It is intended for service deployments that need structured API entry points backed by shared runtime conventions.
4
4
 
5
5
  ## Installation
6
6
 
@@ -5,24 +5,54 @@
5
5
  "method": "generateRestRoutesInformation",
6
6
  "defaultPath": ""
7
7
  },
8
+ {
9
+ "type": "healthComponent",
10
+ "module": "@twin.org/api-service",
11
+ "method": "generateRestRoutesHealth",
12
+ "defaultPath": "/health"
13
+ },
8
14
  {
9
15
  "type": "authenticationComponent",
10
16
  "module": "@twin.org/api-auth-entity-storage-service",
11
17
  "method": "generateRestRoutesAuthentication",
12
18
  "defaultPath": "/authentication"
13
19
  },
20
+ {
21
+ "type": "authenticationAdminComponent",
22
+ "module": "@twin.org/api-auth-entity-storage-service",
23
+ "method": "generateRestRoutesAuthenticationAdmin",
24
+ "defaultPath": "/authentication/admin"
25
+ },
26
+ {
27
+ "type": "authenticationAuditComponent",
28
+ "module": "@twin.org/api-auth-entity-storage-service",
29
+ "method": "generateRestRoutesAuthenticationAudit",
30
+ "defaultPath": "/authentication/audit"
31
+ },
14
32
  {
15
33
  "type": "loggingComponent",
16
34
  "module": "@twin.org/logging-service",
17
35
  "method": "generateRestRoutesLogging",
18
36
  "defaultPath": "/logging"
19
37
  },
38
+ {
39
+ "type": "tenantAdminComponent",
40
+ "module": "@twin.org/api-tenant-processor",
41
+ "method": "generateRestRoutesTenants",
42
+ "defaultPath": "/tenants"
43
+ },
20
44
  {
21
45
  "type": "telemetryComponent",
22
46
  "module": "@twin.org/telemetry-service",
23
47
  "method": "generateRestRoutesTelemetry",
24
48
  "defaultPath": "/telemetry"
25
49
  },
50
+ {
51
+ "type": "automationComponent",
52
+ "module": "@twin.org/automation-service",
53
+ "method": "generateRestRoutesAutomation",
54
+ "defaultPath": "/automation"
55
+ },
26
56
  {
27
57
  "type": "blobStorageComponent",
28
58
  "module": "@twin.org/blob-storage-service",
@@ -53,6 +83,12 @@
53
83
  "method": "generateRestRoutesNft",
54
84
  "defaultPath": "/nft"
55
85
  },
86
+ {
87
+ "type": "notarizationComponent",
88
+ "module": "@twin.org/notarization-service",
89
+ "method": "generateRestRoutesNotarization",
90
+ "defaultPath": "/notarization"
91
+ },
56
92
  {
57
93
  "type": "verifiableStorageComponent",
58
94
  "module": "@twin.org/verifiable-storage-service",
@@ -118,12 +154,6 @@
118
154
  "method": "generateRestRoutesPolicyNegotiationAdminPoint",
119
155
  "defaultPath": "/rights-management"
120
156
  },
121
- {
122
- "type": "rightsManagementDapComponent",
123
- "module": "@twin.org/rights-management-service",
124
- "method": "generateRestRoutesDataAccessPoint",
125
- "defaultPath": "/rights-management"
126
- },
127
157
  {
128
158
  "type": "synchronisedStorageComponent",
129
159
  "module": "@twin.org/synchronised-storage-service",
@@ -137,9 +167,15 @@
137
167
  "defaultPath": "/federated-catalogue"
138
168
  },
139
169
  {
140
- "type": "dataSpaceConnectorComponent",
141
- "module": "@twin.org/data-space-connector-service",
142
- "method": "generateRestRoutesDataSpaceConnector",
143
- "defaultPath": "/data-space-connector"
170
+ "type": "dataspaceControlPlaneComponent",
171
+ "module": "@twin.org/dataspace-control-plane-service",
172
+ "method": "generateRestRoutesDataspaceControlPlane",
173
+ "defaultPath": "/dataspace"
174
+ },
175
+ {
176
+ "type": "dataspaceDataPlaneComponent",
177
+ "module": "@twin.org/dataspace-data-plane-service",
178
+ "method": "generateRestRoutesDataspaceDataPlane",
179
+ "defaultPath": "/dataspace"
144
180
  }
145
181
  ]
@@ -6,9 +6,9 @@
6
6
  "defaultPath": "event-bus"
7
7
  },
8
8
  {
9
- "type": "dataSpaceConnectorComponent",
10
- "module": "@twin.org/data-space-connector-service",
11
- "method": "generateSocketRoutesDataSpaceConnector",
12
- "defaultPath": "data-space-connector"
9
+ "type": "dataspaceDataPlaneComponent",
10
+ "module": "@twin.org/dataspace-data-plane-service",
11
+ "method": "generateSocketRoutesDataspaceDataPlane",
12
+ "defaultPath": "dataspace"
13
13
  }
14
14
  ]
@@ -1,4 +1,14 @@
1
1
  [
2
+ {
3
+ "type": "authenticationAuditComponent",
4
+ "module": "@twin.org/engine-server-types",
5
+ "method": "initialiseAuthenticationAuditComponent"
6
+ },
7
+ {
8
+ "type": "authenticationRateComponent",
9
+ "module": "@twin.org/engine-server-types",
10
+ "method": "initialiseAuthenticationRateComponent"
11
+ },
2
12
  {
3
13
  "type": "authenticationAdminComponent",
4
14
  "module": "@twin.org/engine-server-types",
@@ -15,6 +25,11 @@
15
25
  "method": "initialiseInformationComponent",
16
26
  "defaultRestPath": ""
17
27
  },
28
+ {
29
+ "type": "hostingComponent",
30
+ "module": "@twin.org/engine-server-types",
31
+ "method": "initialiseHostingComponent"
32
+ },
18
33
  {
19
34
  "type": "restRouteProcessor",
20
35
  "module": "@twin.org/engine-server-types",
@@ -1,3 +1,5 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
1
3
  import { MimeTypeProcessorFactory, RestRouteProcessorFactory, SocketRouteProcessorFactory } from "@twin.org/api-models";
2
4
  import { FastifyWebServer } from "@twin.org/api-server-fastify";
3
5
  import { ContextIdStore } from "@twin.org/context";
@@ -167,16 +169,13 @@ export class EngineServer {
167
169
  }
168
170
  /**
169
171
  * Start the engine server.
170
- * @returns True if the start was successful.
172
+ * @returns Nothing.
171
173
  */
172
174
  async start() {
173
- const canContinue = await this._engineCore.start();
174
- if (canContinue) {
175
- await ContextIdStore.run(this._engineCore.getContextIds() ?? {}, async () => {
176
- await this.startWebServer();
177
- });
178
- }
179
- return canContinue;
175
+ await this._engineCore.start();
176
+ await ContextIdStore.run(this._engineCore.getContextIds() ?? {}, async () => {
177
+ await this.startWebServer();
178
+ });
180
179
  }
181
180
  /**
182
181
  * Stop the engine server.
@@ -206,10 +205,13 @@ export class EngineServer {
206
205
  const loggingComponentType = coreConfig.silent
207
206
  ? undefined
208
207
  : this._engineCore.getRegisteredInstanceType("loggingComponent");
208
+ const hostingComponentType = this._engineCore.getRegisteredInstanceTypeOptional("hostingComponent");
209
209
  this._webServer = new FastifyWebServer({
210
210
  loggingComponentType,
211
+ hostingComponentType,
211
212
  mimeTypeProcessors
212
213
  });
214
+ await this._engineCore.addRegisteredComponent("webServer", this._webServer);
213
215
  await this._webServer.build(restRouteProcessors, this._restRoutes, socketRouteProcessors, this._socketRoutes, coreConfig.web);
214
216
  await this._webServer.start();
215
217
  }
@@ -1 +1 @@
1
- {"version":3,"file":"engineServer.js","sourceRoot":"","sources":["../../src/engineServer.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EACN,sBAAsB,EACtB,wBAAwB,EAExB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,yBAAyB,MAAM,uCAAuC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACpG,OAAO,2BAA2B,MAAM,yCAAyC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACxG,OAAO,sBAAsB,MAAM,oCAAoC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAE9F;;GAEG;AACH,MAAM,OAAO,YAAY;IAGxB;;OAEG;IACI,MAAM,CAAU,UAAU,kBAAkC;IAEnE;;;OAGG;IACc,WAAW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,CAAC,WAAW,CAAC,kBAAkB,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAC/F,CAAC;IACF,CAAC;IAED;;;OAGG;IACK,4BAA4B;QACnC,KAAK,MAAM,SAAS,IAAI,yBAAyB,EAAE,CAAC;YACnD,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAChF,CAAC;IACF,CAAC;IAED;;;OAGG;IACK,8BAA8B;QACrC,KAAK,MAAM,SAAS,IAAI,2BAA2B,EAAE,CAAC;YACrD,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAClF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRoute, ISocketRoute, IWebServer } from \"@twin.org/api-models\";\nimport {\n\tMimeTypeProcessorFactory,\n\tRestRouteProcessorFactory,\n\tSocketRouteProcessorFactory\n} from \"@twin.org/api-models\";\nimport { FastifyWebServer } from \"@twin.org/api-server-fastify\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { Guards, Is, StringHelper } from \"@twin.org/core\";\nimport type { IEngineCore, IEngineCoreTypeConfig, IEngineServer } from \"@twin.org/engine-models\";\nimport {\n\tRestRouteProcessorType,\n\tSocketRouteProcessorType,\n\ttype IEngineServerConfig\n} from \"@twin.org/engine-server-types\";\nimport { ModuleHelper } from \"@twin.org/modules\";\nimport { nameof } from \"@twin.org/nameof\";\nimport serverRestRouteGenerators from \"./data/serverRestRouteGenerators.json\" with { type: \"json\" };\nimport serverSocketRouteGenerators from \"./data/serverSocketRouteGenerators.json\" with { type: \"json\" };\nimport serverTypeInitialisers from \"./data/serverTypeInitialisers.json\" with { type: \"json\" };\n\n/**\n * Server for the engine.\n */\nexport class EngineServer<T extends IEngineServerConfig = IEngineServerConfig>\n\timplements IEngineServer\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<EngineServer>();\n\n\t/**\n\t * The engine.\n\t * @internal\n\t */\n\tprivate readonly _engineCore: IEngineCore<T>;\n\n\t/**\n\t * The REST route generators.\n\t * @internal\n\t */\n\tprivate readonly _restRouteGenerators: {\n\t\ttype: string;\n\t\tmodule: string;\n\t\tmethod: string;\n\t}[];\n\n\t/**\n\t * The socket route generators.\n\t * @internal\n\t */\n\tprivate readonly _socketRouteGenerators: {\n\t\ttype: string;\n\t\tmodule: string;\n\t\tmethod: string;\n\t}[];\n\n\t/**\n\t * The web server.\n\t * @internal\n\t */\n\tprivate _webServer?: IWebServer<unknown>;\n\n\t/**\n\t * The REST routes for the application.\n\t * @internal\n\t */\n\tprivate _restRoutes: IRestRoute[];\n\n\t/**\n\t * The Socket routes for the application.\n\t * @internal\n\t */\n\tprivate _socketRoutes: ISocketRoute[];\n\n\t/**\n\t * Create a new instance of EngineServer.\n\t * @param options The options for the engine.\n\t * @param options.engineCore The engine core to serve from.\n\t */\n\tconstructor(options: { engineCore: IEngineCore<T> }) {\n\t\tGuards.object(EngineServer.CLASS_NAME, nameof(options), options);\n\t\tGuards.object(EngineServer.CLASS_NAME, nameof(options.engineCore), options.engineCore);\n\n\t\tthis._engineCore = options.engineCore;\n\t\tthis._restRouteGenerators = [];\n\t\tthis._socketRouteGenerators = [];\n\t\tthis._restRoutes = [];\n\t\tthis._socketRoutes = [];\n\n\t\tconst coreConfig = this._engineCore.getConfig();\n\n\t\tif (!Is.arrayValue(coreConfig.types.restRouteProcessor)) {\n\t\t\tcoreConfig.types.restRouteProcessor = [];\n\n\t\t\tif (!coreConfig.silent) {\n\t\t\t\tcoreConfig.types.restRouteProcessor.push({\n\t\t\t\t\ttype: RestRouteProcessorType.Logging,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tincludeBody: coreConfig.debug\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\tcoreConfig.types.restRouteProcessor.push({\n\t\t\t\ttype: RestRouteProcessorType.RestRoute,\n\t\t\t\toptions: {\n\t\t\t\t\tconfig: {\n\t\t\t\t\t\tincludeErrorStack: coreConfig.debug\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tif (!Is.arrayValue(coreConfig.types.socketRouteProcessor)) {\n\t\t\tcoreConfig.types.socketRouteProcessor = [];\n\n\t\t\tif (!coreConfig.silent) {\n\t\t\t\tcoreConfig.types.socketRouteProcessor.push({\n\t\t\t\t\ttype: SocketRouteProcessorType.Logging,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tincludeBody: coreConfig.debug\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\tcoreConfig.types.socketRouteProcessor.push({\n\t\t\t\ttype: SocketRouteProcessorType.SocketRoute,\n\t\t\t\toptions: {\n\t\t\t\t\tconfig: {\n\t\t\t\t\t\tincludeErrorStack: coreConfig.debug\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tthis.addServerTypeInitialisers();\n\t\tthis.addServerRestRouteGenerators();\n\t\tthis.addServerSocketRouteGenerators();\n\t}\n\n\t/**\n\t * Add a REST route generator.\n\t * @param type The type to add the generator for.\n\t * @param module The module containing the generator.\n\t * @param method The method to call on the module.\n\t */\n\tpublic addRestRouteGenerator(type: string, module: string, method: string): void {\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(type), type);\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(module), module);\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(method), method);\n\n\t\tconst currentIndex = this._restRouteGenerators.findIndex(r => r.type === type);\n\t\tif (currentIndex >= 0) {\n\t\t\tthis._restRouteGenerators[currentIndex].module = module;\n\t\t\tthis._restRouteGenerators[currentIndex].method = method;\n\t\t} else {\n\t\t\tthis._restRouteGenerators.push({\n\t\t\t\ttype,\n\t\t\t\tmodule,\n\t\t\t\tmethod\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Add a socket route generator.\n\t * @param type The type to add the generator for.\n\t * @param module The module containing the generator.\n\t * @param method The method to call on the module.\n\t */\n\tpublic addSocketRouteGenerator(type: string, module: string, method: string): void {\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(type), type);\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(module), module);\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(method), method);\n\n\t\tconst currentIndex = this._socketRouteGenerators.findIndex(s => s.type === type);\n\t\tif (currentIndex >= 0) {\n\t\t\tthis._socketRouteGenerators[currentIndex].module = module;\n\t\t\tthis._socketRouteGenerators[currentIndex].method = method;\n\t\t} else {\n\t\t\tthis._socketRouteGenerators.push({\n\t\t\t\ttype,\n\t\t\t\tmodule,\n\t\t\t\tmethod\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Get the built REST routes.\n\t * @returns The REST routes.\n\t */\n\tpublic getRestRoutes(): IRestRoute[] {\n\t\treturn this._restRoutes;\n\t}\n\n\t/**\n\t * Get the built socket routes.\n\t * @returns The socket routes.\n\t */\n\tpublic getSocketRoutes(): ISocketRoute[] {\n\t\treturn this._socketRoutes;\n\t}\n\n\t/**\n\t * Start the engine server.\n\t * @returns True if the start was successful.\n\t */\n\tpublic async start(): Promise<boolean> {\n\t\tconst canContinue = await this._engineCore.start();\n\n\t\tif (canContinue) {\n\t\t\tawait ContextIdStore.run(this._engineCore.getContextIds() ?? {}, async () => {\n\t\t\t\tawait this.startWebServer();\n\t\t\t});\n\t\t}\n\n\t\treturn canContinue;\n\t}\n\n\t/**\n\t * Stop the engine server.\n\t * @returns Nothing.\n\t */\n\tpublic async stop(): Promise<void> {\n\t\tawait ContextIdStore.run(this._engineCore.getContextIds() ?? {}, async () => {\n\t\t\tif (this._webServer) {\n\t\t\t\tconst webServer = this._webServer;\n\t\t\t\tthis._webServer = undefined;\n\t\t\t\tawait webServer.stop();\n\t\t\t}\n\t\t});\n\n\t\tawait this._engineCore.stop();\n\t}\n\n\t/**\n\t * Starts the web server.\n\t * @internal\n\t */\n\tprivate async startWebServer(): Promise<void> {\n\t\tthis._restRoutes = await this.buildRestRoutes();\n\t\tthis._socketRoutes = await this.buildSocketRoutes();\n\t\tconst restRouteProcessors = RestRouteProcessorFactory.names().map(n =>\n\t\t\tRestRouteProcessorFactory.get(n)\n\t\t);\n\t\tconst socketRouteProcessors = SocketRouteProcessorFactory.names().map(n =>\n\t\t\tSocketRouteProcessorFactory.get(n)\n\t\t);\n\t\tconst mimeTypeProcessors = MimeTypeProcessorFactory.names().map(n =>\n\t\t\tMimeTypeProcessorFactory.get(n)\n\t\t);\n\n\t\tconst coreConfig = this._engineCore.getConfig();\n\t\tconst loggingComponentType = coreConfig.silent\n\t\t\t? undefined\n\t\t\t: this._engineCore.getRegisteredInstanceType(\"loggingComponent\");\n\n\t\tthis._webServer = new FastifyWebServer({\n\t\t\tloggingComponentType,\n\t\t\tmimeTypeProcessors\n\t\t});\n\n\t\tawait this._webServer.build(\n\t\t\trestRouteProcessors,\n\t\t\tthis._restRoutes,\n\t\t\tsocketRouteProcessors,\n\t\t\tthis._socketRoutes,\n\t\t\tcoreConfig.web\n\t\t);\n\t\tawait this._webServer.start();\n\t}\n\n\t/**\n\t * The REST routes for the application.\n\t * @returns The REST routes for the application.\n\t * @internal\n\t */\n\tprivate async buildRestRoutes(): Promise<IRestRoute[]> {\n\t\tconst routes: IRestRoute[] = [];\n\n\t\tfor (const { type, module, method } of this._restRouteGenerators) {\n\t\t\tawait this.initialiseRestTypeRoute(routes, type, module, method);\n\t\t}\n\n\t\treturn routes;\n\t}\n\n\t/**\n\t * The socket routes for the application.\n\t * @returns The socket routes for the application.\n\t * @internal\n\t */\n\tprivate async buildSocketRoutes(): Promise<ISocketRoute[]> {\n\t\tconst routes: ISocketRoute[] = [];\n\n\t\tfor (const { type, module, method } of this._socketRouteGenerators) {\n\t\t\tawait this.initialiseSocketTypeRoute(routes, type, module, method);\n\t\t}\n\n\t\treturn routes;\n\t}\n\n\t/**\n\t * Initialise the rest routes from connector.\n\t * @param routes The routes to add to.\n\t * @param typeKey The key for the default types.\n\t * @param generateRoutes The function to generate the routes.\n\t * @internal\n\t */\n\tprivate async initialiseRestTypeRoute(\n\t\troutes: IRestRoute[],\n\t\ttypeKey: string,\n\t\tmodule: string,\n\t\tmethod: string\n\t): Promise<void> {\n\t\tconst typeConfig: IEngineCoreTypeConfig[] | undefined = this._engineCore.getTypeConfig(typeKey);\n\n\t\tif (Is.arrayValue(typeConfig)) {\n\t\t\tconst generateRoutes = await ModuleHelper.getModuleEntry<\n\t\t\t\t(baseRouteName: string, componentName: string, options?: unknown) => IRestRoute[]\n\t\t\t>(module, method);\n\n\t\t\tfor (let i = 0; i < typeConfig.length; i++) {\n\t\t\t\tconst restPath = typeConfig[i].restPath;\n\t\t\t\tconst restOptions = typeConfig[i].restOptions;\n\n\t\t\t\tif (Is.string(restPath)) {\n\t\t\t\t\tconst serviceType =\n\t\t\t\t\t\ttypeConfig[i].overrideInstanceType ??\n\t\t\t\t\t\tthis._engineCore.getRegisteredInstanceType(typeKey);\n\t\t\t\t\tif (Is.stringValue(serviceType)) {\n\t\t\t\t\t\tconst generatedRoutes = generateRoutes(restPath, serviceType, restOptions);\n\t\t\t\t\t\tfor (const route of generatedRoutes) {\n\t\t\t\t\t\t\t// Don't strip trailing slashes from the root path.\n\t\t\t\t\t\t\tif (Is.stringValue(route.path) && route.path.length > 1) {\n\t\t\t\t\t\t\t\troute.path = StringHelper.trimTrailingSlashes(route.path);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\troutes.push(...generatedRoutes);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Initialise the socket routes from connector.\n\t * @param routes The routes to add to.\n\t * @param typeKey The key for the default types.\n\t * @param module The module containing the generator.\n\t * @param method The method to call on the module.\n\t * @internal\n\t */\n\tprivate async initialiseSocketTypeRoute(\n\t\troutes: ISocketRoute[],\n\t\ttypeKey: string,\n\t\tmodule: string,\n\t\tmethod: string\n\t): Promise<void> {\n\t\tconst typeConfig: IEngineCoreTypeConfig[] | undefined = this._engineCore.getTypeConfig(typeKey);\n\n\t\tif (Is.arrayValue(typeConfig)) {\n\t\t\tconst generateRoutes = await ModuleHelper.getModuleEntry<\n\t\t\t\t(baseRouteName: string, componentName: string, options?: unknown) => ISocketRoute[]\n\t\t\t>(module, method);\n\n\t\t\tfor (let i = 0; i < typeConfig.length; i++) {\n\t\t\t\tconst socketPath = typeConfig[i].socketPath;\n\t\t\t\tconst socketOptions = typeConfig[i].socketOptions;\n\t\t\t\tif (Is.string(socketPath)) {\n\t\t\t\t\tconst serviceType =\n\t\t\t\t\t\ttypeConfig[i].overrideInstanceType ??\n\t\t\t\t\t\tthis._engineCore.getRegisteredInstanceType(typeKey);\n\t\t\t\t\tif (Is.stringValue(serviceType)) {\n\t\t\t\t\t\troutes.push(...generateRoutes(socketPath, serviceType, socketOptions));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Add the server type initializers.\n\t * @internal\n\t */\n\tprivate addServerTypeInitialisers(): void {\n\t\tfor (const initializer of serverTypeInitialisers) {\n\t\t\tthis._engineCore.addTypeInitialiser(initializer.type, initializer.module, initializer.method);\n\t\t}\n\t}\n\n\t/**\n\t * Add the server REST route generators.\n\t * @internal\n\t */\n\tprivate addServerRestRouteGenerators(): void {\n\t\tfor (const generator of serverRestRouteGenerators) {\n\t\t\tthis.addRestRouteGenerator(generator.type, generator.module, generator.method);\n\t\t}\n\t}\n\n\t/**\n\t * Add the server socket route generators.\n\t * @internal\n\t */\n\tprivate addServerSocketRouteGenerators(): void {\n\t\tfor (const generator of serverSocketRouteGenerators) {\n\t\t\tthis.addSocketRouteGenerator(generator.type, generator.module, generator.method);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"engineServer.js","sourceRoot":"","sources":["../../src/engineServer.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAI3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EACN,sBAAsB,EACtB,wBAAwB,EAExB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,yBAAyB,MAAM,uCAAuC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACpG,OAAO,2BAA2B,MAAM,yCAAyC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACxG,OAAO,sBAAsB,MAAM,oCAAoC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAE9F;;GAEG;AACH,MAAM,OAAO,YAAY;IAGxB;;OAEG;IACI,MAAM,CAAU,UAAU,kBAAkC;IAEnE;;;OAGG;IACc,WAAW,CAAiB;IAE7C;;;OAGG;IACc,oBAAoB,CAIjC;IAEJ;;;OAGG;IACc,sBAAsB,CAInC;IAEJ;;;OAGG;IACK,UAAU,CAAuB;IAEzC;;;OAGG;IACK,WAAW,CAAe;IAElC;;;OAGG;IACK,aAAa,CAAiB;IAEtC;;;;OAIG;IACH,YAAY,OAAuC;QAClD,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,aAAmB,OAA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QACnC,KAAK,MAAM,SAAS,IAAI,yBAAyB,EAAE,CAAC;YACnD,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAChF,CAAC;IACF,CAAC;IAED;;;OAGG;IACK,8BAA8B;QACrC,KAAK,MAAM,SAAS,IAAI,2BAA2B,EAAE,CAAC;YACrD,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAClF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tMimeTypeProcessorFactory,\n\tRestRouteProcessorFactory,\n\tSocketRouteProcessorFactory,\n\ttype IRestRoute,\n\ttype ISocketRoute,\n\ttype IWebServer\n} from \"@twin.org/api-models\";\nimport { FastifyWebServer } from \"@twin.org/api-server-fastify\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { Guards, Is, StringHelper } from \"@twin.org/core\";\nimport type { IEngineCore, IEngineCoreTypeConfig, IEngineServer } from \"@twin.org/engine-models\";\nimport {\n\tRestRouteProcessorType,\n\tSocketRouteProcessorType,\n\ttype IEngineServerConfig\n} from \"@twin.org/engine-server-types\";\nimport { ModuleHelper } from \"@twin.org/modules\";\nimport { nameof } from \"@twin.org/nameof\";\nimport serverRestRouteGenerators from \"./data/serverRestRouteGenerators.json\" with { type: \"json\" };\nimport serverSocketRouteGenerators from \"./data/serverSocketRouteGenerators.json\" with { type: \"json\" };\nimport serverTypeInitialisers from \"./data/serverTypeInitialisers.json\" with { type: \"json\" };\n\n/**\n * Server for the engine.\n */\nexport class EngineServer<\n\tT extends IEngineServerConfig = IEngineServerConfig\n> implements IEngineServer {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<EngineServer>();\n\n\t/**\n\t * The engine.\n\t * @internal\n\t */\n\tprivate readonly _engineCore: IEngineCore<T>;\n\n\t/**\n\t * The REST route generators.\n\t * @internal\n\t */\n\tprivate readonly _restRouteGenerators: {\n\t\ttype: string;\n\t\tmodule: string;\n\t\tmethod: string;\n\t}[];\n\n\t/**\n\t * The socket route generators.\n\t * @internal\n\t */\n\tprivate readonly _socketRouteGenerators: {\n\t\ttype: string;\n\t\tmodule: string;\n\t\tmethod: string;\n\t}[];\n\n\t/**\n\t * The web server.\n\t * @internal\n\t */\n\tprivate _webServer?: IWebServer<unknown>;\n\n\t/**\n\t * The REST routes for the application.\n\t * @internal\n\t */\n\tprivate _restRoutes: IRestRoute[];\n\n\t/**\n\t * The Socket routes for the application.\n\t * @internal\n\t */\n\tprivate _socketRoutes: ISocketRoute[];\n\n\t/**\n\t * Create a new instance of EngineServer.\n\t * @param options The options for the engine.\n\t * @param options.engineCore The engine core to serve from.\n\t */\n\tconstructor(options: { engineCore: IEngineCore<T> }) {\n\t\tGuards.object(EngineServer.CLASS_NAME, nameof(options), options);\n\t\tGuards.object(EngineServer.CLASS_NAME, nameof(options.engineCore), options.engineCore);\n\n\t\tthis._engineCore = options.engineCore;\n\t\tthis._restRouteGenerators = [];\n\t\tthis._socketRouteGenerators = [];\n\t\tthis._restRoutes = [];\n\t\tthis._socketRoutes = [];\n\n\t\tconst coreConfig = this._engineCore.getConfig();\n\n\t\tif (!Is.arrayValue(coreConfig.types.restRouteProcessor)) {\n\t\t\tcoreConfig.types.restRouteProcessor = [];\n\n\t\t\tif (!coreConfig.silent) {\n\t\t\t\tcoreConfig.types.restRouteProcessor.push({\n\t\t\t\t\ttype: RestRouteProcessorType.Logging,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tincludeBody: coreConfig.debug\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\tcoreConfig.types.restRouteProcessor.push({\n\t\t\t\ttype: RestRouteProcessorType.RestRoute,\n\t\t\t\toptions: {\n\t\t\t\t\tconfig: {\n\t\t\t\t\t\tincludeErrorStack: coreConfig.debug\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tif (!Is.arrayValue(coreConfig.types.socketRouteProcessor)) {\n\t\t\tcoreConfig.types.socketRouteProcessor = [];\n\n\t\t\tif (!coreConfig.silent) {\n\t\t\t\tcoreConfig.types.socketRouteProcessor.push({\n\t\t\t\t\ttype: SocketRouteProcessorType.Logging,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tincludeBody: coreConfig.debug\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\tcoreConfig.types.socketRouteProcessor.push({\n\t\t\t\ttype: SocketRouteProcessorType.SocketRoute,\n\t\t\t\toptions: {\n\t\t\t\t\tconfig: {\n\t\t\t\t\t\tincludeErrorStack: coreConfig.debug\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tthis.addServerTypeInitialisers();\n\t\tthis.addServerRestRouteGenerators();\n\t\tthis.addServerSocketRouteGenerators();\n\t}\n\n\t/**\n\t * Add a REST route generator.\n\t * @param type The type to add the generator for.\n\t * @param module The module containing the generator.\n\t * @param method The method to call on the module.\n\t */\n\tpublic addRestRouteGenerator(type: string, module: string, method: string): void {\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(type), type);\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(module), module);\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(method), method);\n\n\t\tconst currentIndex = this._restRouteGenerators.findIndex(r => r.type === type);\n\t\tif (currentIndex >= 0) {\n\t\t\tthis._restRouteGenerators[currentIndex].module = module;\n\t\t\tthis._restRouteGenerators[currentIndex].method = method;\n\t\t} else {\n\t\t\tthis._restRouteGenerators.push({\n\t\t\t\ttype,\n\t\t\t\tmodule,\n\t\t\t\tmethod\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Add a socket route generator.\n\t * @param type The type to add the generator for.\n\t * @param module The module containing the generator.\n\t * @param method The method to call on the module.\n\t */\n\tpublic addSocketRouteGenerator(type: string, module: string, method: string): void {\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(type), type);\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(module), module);\n\t\tGuards.stringValue(EngineServer.CLASS_NAME, nameof(method), method);\n\n\t\tconst currentIndex = this._socketRouteGenerators.findIndex(s => s.type === type);\n\t\tif (currentIndex >= 0) {\n\t\t\tthis._socketRouteGenerators[currentIndex].module = module;\n\t\t\tthis._socketRouteGenerators[currentIndex].method = method;\n\t\t} else {\n\t\t\tthis._socketRouteGenerators.push({\n\t\t\t\ttype,\n\t\t\t\tmodule,\n\t\t\t\tmethod\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Get the built REST routes.\n\t * @returns The REST routes.\n\t */\n\tpublic getRestRoutes(): IRestRoute[] {\n\t\treturn this._restRoutes;\n\t}\n\n\t/**\n\t * Get the built socket routes.\n\t * @returns The socket routes.\n\t */\n\tpublic getSocketRoutes(): ISocketRoute[] {\n\t\treturn this._socketRoutes;\n\t}\n\n\t/**\n\t * Start the engine server.\n\t * @returns Nothing.\n\t */\n\tpublic async start(): Promise<void> {\n\t\tawait this._engineCore.start();\n\n\t\tawait ContextIdStore.run(this._engineCore.getContextIds() ?? {}, async () => {\n\t\t\tawait this.startWebServer();\n\t\t});\n\t}\n\n\t/**\n\t * Stop the engine server.\n\t * @returns Nothing.\n\t */\n\tpublic async stop(): Promise<void> {\n\t\tawait ContextIdStore.run(this._engineCore.getContextIds() ?? {}, async () => {\n\t\t\tif (this._webServer) {\n\t\t\t\tconst webServer = this._webServer;\n\t\t\t\tthis._webServer = undefined;\n\t\t\t\tawait webServer.stop();\n\t\t\t}\n\t\t});\n\n\t\tawait this._engineCore.stop();\n\t}\n\n\t/**\n\t * Starts the web server.\n\t * @internal\n\t */\n\tprivate async startWebServer(): Promise<void> {\n\t\tthis._restRoutes = await this.buildRestRoutes();\n\t\tthis._socketRoutes = await this.buildSocketRoutes();\n\t\tconst restRouteProcessors = RestRouteProcessorFactory.names().map(n =>\n\t\t\tRestRouteProcessorFactory.get(n)\n\t\t);\n\t\tconst socketRouteProcessors = SocketRouteProcessorFactory.names().map(n =>\n\t\t\tSocketRouteProcessorFactory.get(n)\n\t\t);\n\t\tconst mimeTypeProcessors = MimeTypeProcessorFactory.names().map(n =>\n\t\t\tMimeTypeProcessorFactory.get(n)\n\t\t);\n\n\t\tconst coreConfig = this._engineCore.getConfig();\n\t\tconst loggingComponentType = coreConfig.silent\n\t\t\t? undefined\n\t\t\t: this._engineCore.getRegisteredInstanceType(\"loggingComponent\");\n\t\tconst hostingComponentType =\n\t\t\tthis._engineCore.getRegisteredInstanceTypeOptional(\"hostingComponent\");\n\n\t\tthis._webServer = new FastifyWebServer({\n\t\t\tloggingComponentType,\n\t\t\thostingComponentType,\n\t\t\tmimeTypeProcessors\n\t\t});\n\n\t\tawait this._engineCore.addRegisteredComponent(\"webServer\", this._webServer);\n\n\t\tawait this._webServer.build(\n\t\t\trestRouteProcessors,\n\t\t\tthis._restRoutes,\n\t\t\tsocketRouteProcessors,\n\t\t\tthis._socketRoutes,\n\t\t\tcoreConfig.web\n\t\t);\n\t\tawait this._webServer.start();\n\t}\n\n\t/**\n\t * The REST routes for the application.\n\t * @returns The REST routes for the application.\n\t * @internal\n\t */\n\tprivate async buildRestRoutes(): Promise<IRestRoute[]> {\n\t\tconst routes: IRestRoute[] = [];\n\n\t\tfor (const { type, module, method } of this._restRouteGenerators) {\n\t\t\tawait this.initialiseRestTypeRoute(routes, type, module, method);\n\t\t}\n\n\t\treturn routes;\n\t}\n\n\t/**\n\t * The socket routes for the application.\n\t * @returns The socket routes for the application.\n\t * @internal\n\t */\n\tprivate async buildSocketRoutes(): Promise<ISocketRoute[]> {\n\t\tconst routes: ISocketRoute[] = [];\n\n\t\tfor (const { type, module, method } of this._socketRouteGenerators) {\n\t\t\tawait this.initialiseSocketTypeRoute(routes, type, module, method);\n\t\t}\n\n\t\treturn routes;\n\t}\n\n\t/**\n\t * Initialise the rest routes from connector.\n\t * @param routes The routes to add to.\n\t * @param typeKey The key for the default types.\n\t * @param generateRoutes The function to generate the routes.\n\t * @internal\n\t */\n\tprivate async initialiseRestTypeRoute(\n\t\troutes: IRestRoute[],\n\t\ttypeKey: string,\n\t\tmodule: string,\n\t\tmethod: string\n\t): Promise<void> {\n\t\tconst typeConfig: IEngineCoreTypeConfig[] | undefined = this._engineCore.getTypeConfig(typeKey);\n\n\t\tif (Is.arrayValue(typeConfig)) {\n\t\t\tconst generateRoutes = await ModuleHelper.getModuleEntry<\n\t\t\t\t(baseRouteName: string, componentName: string, options?: unknown) => IRestRoute[]\n\t\t\t>(module, method);\n\n\t\t\tfor (let i = 0; i < typeConfig.length; i++) {\n\t\t\t\tconst restPath = typeConfig[i].restPath;\n\t\t\t\tconst restOptions = typeConfig[i].restOptions;\n\n\t\t\t\tif (Is.string(restPath)) {\n\t\t\t\t\tconst serviceType =\n\t\t\t\t\t\ttypeConfig[i].overrideInstanceType ??\n\t\t\t\t\t\tthis._engineCore.getRegisteredInstanceType(typeKey);\n\t\t\t\t\tif (Is.stringValue(serviceType)) {\n\t\t\t\t\t\tconst generatedRoutes = generateRoutes(restPath, serviceType, restOptions);\n\t\t\t\t\t\tfor (const route of generatedRoutes) {\n\t\t\t\t\t\t\t// Don't strip trailing slashes from the root path.\n\t\t\t\t\t\t\tif (Is.stringValue(route.path) && route.path.length > 1) {\n\t\t\t\t\t\t\t\troute.path = StringHelper.trimTrailingSlashes(route.path);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\troutes.push(...generatedRoutes);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Initialise the socket routes from connector.\n\t * @param routes The routes to add to.\n\t * @param typeKey The key for the default types.\n\t * @param module The module containing the generator.\n\t * @param method The method to call on the module.\n\t * @internal\n\t */\n\tprivate async initialiseSocketTypeRoute(\n\t\troutes: ISocketRoute[],\n\t\ttypeKey: string,\n\t\tmodule: string,\n\t\tmethod: string\n\t): Promise<void> {\n\t\tconst typeConfig: IEngineCoreTypeConfig[] | undefined = this._engineCore.getTypeConfig(typeKey);\n\n\t\tif (Is.arrayValue(typeConfig)) {\n\t\t\tconst generateRoutes = await ModuleHelper.getModuleEntry<\n\t\t\t\t(baseRouteName: string, componentName: string, options?: unknown) => ISocketRoute[]\n\t\t\t>(module, method);\n\n\t\t\tfor (let i = 0; i < typeConfig.length; i++) {\n\t\t\t\tconst socketPath = typeConfig[i].socketPath;\n\t\t\t\tconst socketOptions = typeConfig[i].socketOptions;\n\t\t\t\tif (Is.string(socketPath)) {\n\t\t\t\t\tconst serviceType =\n\t\t\t\t\t\ttypeConfig[i].overrideInstanceType ??\n\t\t\t\t\t\tthis._engineCore.getRegisteredInstanceType(typeKey);\n\t\t\t\t\tif (Is.stringValue(serviceType)) {\n\t\t\t\t\t\troutes.push(...generateRoutes(socketPath, serviceType, socketOptions));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Add the server type initializers.\n\t * @internal\n\t */\n\tprivate addServerTypeInitialisers(): void {\n\t\tfor (const initializer of serverTypeInitialisers) {\n\t\t\tthis._engineCore.addTypeInitialiser(initializer.type, initializer.module, initializer.method);\n\t\t}\n\t}\n\n\t/**\n\t * Add the server REST route generators.\n\t * @internal\n\t */\n\tprivate addServerRestRouteGenerators(): void {\n\t\tfor (const generator of serverRestRouteGenerators) {\n\t\t\tthis.addRestRouteGenerator(generator.type, generator.module, generator.method);\n\t\t}\n\t}\n\n\t/**\n\t * Add the server socket route generators.\n\t * @internal\n\t */\n\tprivate addServerSocketRouteGenerators(): void {\n\t\tfor (const generator of serverSocketRouteGenerators) {\n\t\t\tthis.addSocketRouteGenerator(generator.type, generator.module, generator.method);\n\t\t}\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { IRestRoute, ISocketRoute } from "@twin.org/api-models";
1
+ import { type IRestRoute, type ISocketRoute } from "@twin.org/api-models";
2
2
  import type { IEngineCore, IEngineServer } from "@twin.org/engine-models";
3
3
  import { type IEngineServerConfig } from "@twin.org/engine-server-types";
4
4
  /**
@@ -43,9 +43,9 @@ export declare class EngineServer<T extends IEngineServerConfig = IEngineServerC
43
43
  getSocketRoutes(): ISocketRoute[];
44
44
  /**
45
45
  * Start the engine server.
46
- * @returns True if the start was successful.
46
+ * @returns Nothing.
47
47
  */
48
- start(): Promise<boolean>;
48
+ start(): Promise<void>;
49
49
  /**
50
50
  * Stop the engine server.
51
51
  * @returns Nothing.