@twin.org/engine-server 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.
@@ -0,0 +1,511 @@
1
+ import { initSchema, EntityStorageAuthenticationService, AuthHeaderProcessor, generateRestRoutesAuthentication } from '@twin.org/api-auth-entity-storage-service';
2
+ import { MimeTypeProcessorFactory, RestRouteProcessorFactory, SocketRouteProcessorFactory } from '@twin.org/api-models';
3
+ import { FastifyWebServer } from '@twin.org/api-server-fastify';
4
+ import { InformationService, generateRestRoutesInformation } from '@twin.org/api-service';
5
+ import { generateRestRoutesAttestation } from '@twin.org/attestation-service';
6
+ import { generateRestRoutesAuditableItemGraph } from '@twin.org/auditable-item-graph-service';
7
+ import { generateRestRoutesAuditableItemStream } from '@twin.org/auditable-item-stream-service';
8
+ import { generateRestRoutesBlobStorage } from '@twin.org/blob-storage-service';
9
+ import { I18n, GeneralError, ComponentFactory, Guards, Is } from '@twin.org/core';
10
+ import { AuthenticationComponentType, InformationComponentType, MimeTypeProcessorType, RestRouteProcessorType, SocketRouteProcessorType } from '@twin.org/engine-models';
11
+ import { generateRestRoutesEntityStorage } from '@twin.org/entity-storage-service';
12
+ import { generateRestRoutesIdentity, generateRestRoutesIdentityProfile } from '@twin.org/identity-service';
13
+ import { generateRestRoutesLogging } from '@twin.org/logging-service';
14
+ import { generateRestRoutesNft } from '@twin.org/nft-service';
15
+ import { generateRestRoutesTelemetry } from '@twin.org/telemetry-service';
16
+ import { initialiseEntityStorageConnector } from '@twin.org/engine-core';
17
+ import { JwtMimeTypeProcessor, LoggingProcessor, NodeIdentityProcessor, StaticUserIdentityProcessor, RestRouteProcessor, SocketRouteProcessor } from '@twin.org/api-processors';
18
+
19
+ /**
20
+ * Initialise the authentication.
21
+ * @param engineCore The engine core.
22
+ * @param context The context for the engine.
23
+ * @param instanceConfig The instance config.
24
+ * @param overrideInstanceType The instance type to override the default.
25
+ * @returns The name of the instance created.
26
+ * @throws GeneralError if the component type is unknown.
27
+ */
28
+ function initialiseAuthenticationComponent(engineCore, context, instanceConfig, overrideInstanceType) {
29
+ engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
30
+ element: `Authentication Component: ${instanceConfig.type}`
31
+ }));
32
+ const type = instanceConfig.type;
33
+ let component;
34
+ let instanceType;
35
+ if (type === AuthenticationComponentType.AuthEntityStorage) {
36
+ initSchema();
37
+ initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.userEntityStorageType, "AuthenticationUser");
38
+ component = new EntityStorageAuthenticationService({
39
+ vaultConnectorType: context.defaultTypes.vaultConnector,
40
+ ...instanceConfig.options
41
+ });
42
+ instanceType = EntityStorageAuthenticationService.NAMESPACE;
43
+ }
44
+ else {
45
+ throw new GeneralError("engineCore", "componentUnknownType", {
46
+ type,
47
+ componentType: "authenticationComponent"
48
+ });
49
+ }
50
+ const finalInstanceType = overrideInstanceType ?? instanceType;
51
+ context.componentInstances.push({
52
+ instanceType: finalInstanceType,
53
+ component
54
+ });
55
+ ComponentFactory.register(finalInstanceType, () => component);
56
+ return finalInstanceType;
57
+ }
58
+
59
+ /**
60
+ * Initialise the information component.
61
+ * @param engineCore The engine core.
62
+ * @param context The context for the engine.
63
+ * @param instanceConfig The instance config.
64
+ * @param overrideInstanceType The instance type to override the default.
65
+ * @returns The name of the instance created.
66
+ * @throws GeneralError if the component type is unknown.
67
+ */
68
+ function initialiseInformationComponent(engineCore, context, instanceConfig, overrideInstanceType) {
69
+ engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
70
+ element: `Information Component: ${instanceConfig.type}`
71
+ }));
72
+ const type = instanceConfig.type;
73
+ let component;
74
+ let instanceType;
75
+ if (type === InformationComponentType.Service) {
76
+ component = new InformationService(instanceConfig.options);
77
+ instanceType = InformationService.NAMESPACE;
78
+ }
79
+ else {
80
+ throw new GeneralError("engineCore", "componentUnknownType", {
81
+ type,
82
+ componentType: "informationComponent"
83
+ });
84
+ }
85
+ const finalInstanceType = overrideInstanceType ?? instanceType;
86
+ context.componentInstances.push({
87
+ instanceType: finalInstanceType,
88
+ component
89
+ });
90
+ ComponentFactory.register(finalInstanceType, () => component);
91
+ return finalInstanceType;
92
+ }
93
+
94
+ // Copyright 2024 IOTA Stiftung.
95
+ // SPDX-License-Identifier: Apache-2.0.
96
+ /**
97
+ * Initialise the mime type processor.
98
+ * @param engineCore The engine core.
99
+ * @param context The context for the engine.
100
+ * @param instanceConfig The instance config.
101
+ * @param overrideInstanceType The instance type to override the default.
102
+ * @returns The name of the instance created.
103
+ * @throws GeneralError if the component type is unknown.
104
+ */
105
+ function initialiseMimeTypeProcessorComponent(engineCore, context, instanceConfig, overrideInstanceType) {
106
+ engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
107
+ element: `Mime Type Processor: ${instanceConfig.type}`
108
+ }));
109
+ const type = instanceConfig.type;
110
+ let component;
111
+ let instanceType;
112
+ if (type === MimeTypeProcessorType.Jwt) {
113
+ component = new JwtMimeTypeProcessor();
114
+ instanceType = JwtMimeTypeProcessor.NAMESPACE;
115
+ }
116
+ else {
117
+ throw new GeneralError("engineCore", "componentUnknownType", {
118
+ type,
119
+ componentType: "mimeTypeProcessorComponent"
120
+ });
121
+ }
122
+ const finalInstanceType = overrideInstanceType ?? instanceType;
123
+ context.componentInstances.push({
124
+ instanceType: finalInstanceType,
125
+ component
126
+ });
127
+ MimeTypeProcessorFactory.register(finalInstanceType, () => component);
128
+ return finalInstanceType;
129
+ }
130
+
131
+ // Copyright 2024 IOTA Stiftung.
132
+ // SPDX-License-Identifier: Apache-2.0.
133
+ /**
134
+ * Initialise the rest route processor.
135
+ * @param engineCore The engine core.
136
+ * @param context The context for the engine.
137
+ * @param instanceConfig The instance config.
138
+ * @param overrideInstanceType The instance type to override the default.
139
+ * @returns The name of the instance created.
140
+ * @throws GeneralError if the component type is unknown.
141
+ */
142
+ function initialiseRestRouteProcessorComponent(engineCore, context, instanceConfig, overrideInstanceType) {
143
+ engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
144
+ element: `REST Route Processor: ${instanceConfig.type}`
145
+ }));
146
+ const type = instanceConfig.type;
147
+ let component;
148
+ let instanceType;
149
+ if (type === RestRouteProcessorType.AuthHeader) {
150
+ component = new AuthHeaderProcessor({
151
+ vaultConnectorType: context.defaultTypes.vaultConnector,
152
+ config: {
153
+ ...instanceConfig.options?.config
154
+ }
155
+ });
156
+ instanceType = AuthHeaderProcessor.NAMESPACE;
157
+ }
158
+ else if (type === RestRouteProcessorType.Logging) {
159
+ component = new LoggingProcessor({
160
+ loggingConnectorType: context.defaultTypes.loggingConnector,
161
+ config: {
162
+ ...instanceConfig.options?.config
163
+ }
164
+ });
165
+ instanceType = LoggingProcessor.NAMESPACE;
166
+ }
167
+ else if (type === RestRouteProcessorType.NodeIdentity) {
168
+ component = new NodeIdentityProcessor();
169
+ instanceType = NodeIdentityProcessor.NAMESPACE;
170
+ }
171
+ else if (type === RestRouteProcessorType.StaticUserIdentity) {
172
+ component = new StaticUserIdentityProcessor(instanceConfig.options);
173
+ instanceType = StaticUserIdentityProcessor.NAMESPACE;
174
+ }
175
+ else if (type === RestRouteProcessorType.RestRoute) {
176
+ component = new RestRouteProcessor(instanceConfig.options);
177
+ instanceType = RestRouteProcessor.NAMESPACE;
178
+ }
179
+ else {
180
+ throw new GeneralError("engineCore", "componentUnknownType", {
181
+ type,
182
+ componentType: "restRouteProcessorComponent"
183
+ });
184
+ }
185
+ const finalInstanceType = overrideInstanceType ?? instanceType;
186
+ context.componentInstances.push({
187
+ instanceType: finalInstanceType,
188
+ component
189
+ });
190
+ RestRouteProcessorFactory.register(finalInstanceType, () => component);
191
+ return finalInstanceType;
192
+ }
193
+
194
+ // Copyright 2024 IOTA Stiftung.
195
+ // SPDX-License-Identifier: Apache-2.0.
196
+ /**
197
+ * Initialise the socket route processor.
198
+ * @param engineCore The engine core.
199
+ * @param context The context for the engine.
200
+ * @param instanceConfig The instance config.
201
+ * @param overrideInstanceType The instance type to override the default.
202
+ * @returns The name of the instance created.
203
+ * @throws GeneralError if the component type is unknown.
204
+ */
205
+ function initialiseSocketRouteProcessorComponent(engineCore, context, instanceConfig, overrideInstanceType) {
206
+ engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
207
+ element: `Socket Route Processor: ${instanceConfig.type}`
208
+ }));
209
+ const type = instanceConfig.type;
210
+ let component;
211
+ let instanceType;
212
+ if (type === SocketRouteProcessorType.AuthHeader) {
213
+ component = new AuthHeaderProcessor({
214
+ vaultConnectorType: context.defaultTypes.vaultConnector,
215
+ config: {
216
+ ...instanceConfig.options?.config
217
+ }
218
+ });
219
+ instanceType = AuthHeaderProcessor.NAMESPACE;
220
+ }
221
+ else if (type === SocketRouteProcessorType.Logging) {
222
+ component = new LoggingProcessor({
223
+ loggingConnectorType: context.defaultTypes.loggingConnector,
224
+ config: {
225
+ ...instanceConfig.options.config
226
+ }
227
+ });
228
+ instanceType = LoggingProcessor.NAMESPACE;
229
+ }
230
+ else if (type === SocketRouteProcessorType.NodeIdentity) {
231
+ component = new NodeIdentityProcessor();
232
+ instanceType = NodeIdentityProcessor.NAMESPACE;
233
+ }
234
+ else if (type === SocketRouteProcessorType.StaticUserIdentity) {
235
+ component = new StaticUserIdentityProcessor(instanceConfig.options);
236
+ instanceType = StaticUserIdentityProcessor.NAMESPACE;
237
+ }
238
+ else if (type === SocketRouteProcessorType.SocketRoute) {
239
+ component = new SocketRouteProcessor(instanceConfig.options);
240
+ instanceType = SocketRouteProcessor.NAMESPACE;
241
+ }
242
+ else {
243
+ throw new GeneralError("engineCore", "componentUnknownType", {
244
+ type,
245
+ componentType: "socketRouteProcessorComponent"
246
+ });
247
+ }
248
+ const finalInstanceType = overrideInstanceType ?? instanceType;
249
+ context.componentInstances.push({
250
+ instanceType: finalInstanceType,
251
+ component
252
+ });
253
+ SocketRouteProcessorFactory.register(finalInstanceType, () => component);
254
+ return finalInstanceType;
255
+ }
256
+
257
+ // Copyright 2024 IOTA Stiftung.
258
+ // SPDX-License-Identifier: Apache-2.0.
259
+ /**
260
+ * Server for the engine.
261
+ */
262
+ class EngineServer {
263
+ /**
264
+ * Runtime name for the class.
265
+ */
266
+ CLASS_NAME = "EngineServer";
267
+ /**
268
+ * The server config.
269
+ */
270
+ _config;
271
+ /**
272
+ * The engine.
273
+ * @internal
274
+ */
275
+ _engineCore;
276
+ /**
277
+ * The REST route generators.
278
+ * @internal
279
+ */
280
+ _restRouteGenerators;
281
+ /**
282
+ * The socket route generators.
283
+ * @internal
284
+ */
285
+ _socketRouteGenerators;
286
+ /**
287
+ * The web server.
288
+ * @internal
289
+ */
290
+ _webServer;
291
+ /**
292
+ * The logging connector type.
293
+ * @internal
294
+ */
295
+ _loggingConnectorType;
296
+ /**
297
+ * Create a new instance of EngineServer.
298
+ * @param options The options for the engine.
299
+ * @param options.server The server options for the engine.
300
+ * @param options.engineCore The engine core to serve from.
301
+ */
302
+ constructor(options) {
303
+ Guards.object(this.CLASS_NAME, "options", options);
304
+ Guards.object(this.CLASS_NAME, "options.engineCore", options.engineCore);
305
+ this._config = options?.server ?? {};
306
+ this._engineCore = options.engineCore;
307
+ this._restRouteGenerators = [];
308
+ this._socketRouteGenerators = [];
309
+ const coreConfig = this._engineCore.getConfig();
310
+ const defaults = this._engineCore.getDefaultTypes();
311
+ this._loggingConnectorType = coreConfig.silent ? undefined : defaults.loggingConnector;
312
+ if (!Is.arrayValue(this._config.restRouteProcessor)) {
313
+ this._config.restRouteProcessor = [];
314
+ if (!coreConfig.silent) {
315
+ this._config.restRouteProcessor.push({
316
+ type: RestRouteProcessorType.Logging,
317
+ options: {
318
+ config: {
319
+ includeBody: coreConfig.debug
320
+ }
321
+ }
322
+ });
323
+ }
324
+ this._config.restRouteProcessor.push({
325
+ type: RestRouteProcessorType.RestRoute,
326
+ options: {
327
+ config: {
328
+ includeErrorStack: coreConfig.debug
329
+ }
330
+ }
331
+ });
332
+ }
333
+ this.addServerTypeInitialisers();
334
+ this.addServerRestRouteGenerators();
335
+ this.addServerSocketRouteGenerators();
336
+ }
337
+ /**
338
+ * Add a REST route generator.
339
+ * @param type The type to add the generator for.
340
+ * @param typeConfig The type config.
341
+ * @param generator The generator to add.
342
+ */
343
+ addRestRouteGenerator(type, typeConfig, generator) {
344
+ if (!Is.empty(typeConfig)) {
345
+ this._restRouteGenerators.push({
346
+ type,
347
+ typeConfig,
348
+ generator
349
+ });
350
+ }
351
+ }
352
+ /**
353
+ * Add a socket route generator.
354
+ * @param type The type to add the generator for.
355
+ * @param typeConfig The type config.
356
+ * @param generator The generator to add.
357
+ */
358
+ addSocketRouteGenerator(type, typeConfig, generator) {
359
+ if (!Is.empty(typeConfig)) {
360
+ this._socketRouteGenerators.push({
361
+ type,
362
+ typeConfig,
363
+ generator
364
+ });
365
+ }
366
+ }
367
+ /**
368
+ * Start the engine server.
369
+ * @returns Nothing.
370
+ */
371
+ async start() {
372
+ await this._engineCore.start();
373
+ await this.startWebServer();
374
+ }
375
+ /**
376
+ * Stop the engine server.
377
+ * @returns Nothing.
378
+ */
379
+ async stop() {
380
+ if (this._webServer) {
381
+ await this._webServer.stop();
382
+ this._webServer = undefined;
383
+ }
384
+ await this._engineCore.stop();
385
+ }
386
+ /**
387
+ * Starts the web server.
388
+ * @internal
389
+ */
390
+ async startWebServer() {
391
+ const restRoutes = this.buildRestRoutes();
392
+ const socketRoutes = this.buildSocketRoutes();
393
+ const restRouteProcessors = RestRouteProcessorFactory.names().map(n => RestRouteProcessorFactory.get(n));
394
+ const socketRouteProcessors = SocketRouteProcessorFactory.names().map(n => SocketRouteProcessorFactory.get(n));
395
+ const mimeTypeProcessors = MimeTypeProcessorFactory.names().map(n => MimeTypeProcessorFactory.get(n));
396
+ this._webServer = new FastifyWebServer({
397
+ loggingConnectorType: this._loggingConnectorType,
398
+ mimeTypeProcessors
399
+ });
400
+ await this._webServer.build(restRouteProcessors, restRoutes, socketRouteProcessors, socketRoutes, this._config.web);
401
+ await this._webServer.start();
402
+ }
403
+ /**
404
+ * The REST routes for the application.
405
+ * @returns The REST routes for the application.
406
+ * @internal
407
+ */
408
+ buildRestRoutes() {
409
+ const routes = [];
410
+ for (const { type, typeConfig, generator } of this._restRouteGenerators) {
411
+ this.initialiseRestTypeRoute(routes, type, typeConfig, generator);
412
+ }
413
+ return routes;
414
+ }
415
+ /**
416
+ * The socket routes for the application.
417
+ * @returns The socket routes for the application.
418
+ * @internal
419
+ */
420
+ buildSocketRoutes() {
421
+ const routes = [];
422
+ for (const { type, typeConfig, generator } of this._socketRouteGenerators) {
423
+ this.initialiseSocketTypeRoute(routes, type, typeConfig, generator);
424
+ }
425
+ return routes;
426
+ }
427
+ /**
428
+ * Initialise the rest routes from connector.
429
+ * @param routes The routes to add to.
430
+ * @param typeKey The key for the default types.
431
+ * @param typeConfig The type config.
432
+ * @param generateRoutes The function to generate the routes.
433
+ * @internal
434
+ */
435
+ initialiseRestTypeRoute(routes, typeKey, typeConfig, generateRoutes) {
436
+ if (Is.arrayValue(typeConfig)) {
437
+ const defaultEngineTypes = this._engineCore.getDefaultTypes();
438
+ for (let i = 0; i < typeConfig.length; i++) {
439
+ const restPath = typeConfig[i].restPath;
440
+ if (Is.string(restPath)) {
441
+ const serviceType = typeConfig[i].overrideInstanceType ?? defaultEngineTypes[typeKey];
442
+ if (Is.stringValue(serviceType)) {
443
+ routes.push(...generateRoutes(restPath, serviceType));
444
+ }
445
+ }
446
+ }
447
+ }
448
+ }
449
+ /**
450
+ * Initialise the rest routes from connector.
451
+ * @param routes The routes to add to.
452
+ * @param typeKey The key for the default types.
453
+ * @param typeConfig The type config.
454
+ * @param generateRoutes The function to generate the routes.
455
+ * @internal
456
+ */
457
+ initialiseSocketTypeRoute(routes, typeKey, typeConfig, generateRoutes) {
458
+ if (Is.arrayValue(typeConfig)) {
459
+ const defaultEngineTypes = this._engineCore.getDefaultTypes();
460
+ for (let i = 0; i < typeConfig.length; i++) {
461
+ const socketPath = typeConfig[i].socketPath;
462
+ if (Is.string(socketPath)) {
463
+ const serviceType = typeConfig[i].overrideInstanceType ?? defaultEngineTypes[typeKey];
464
+ if (Is.stringValue(serviceType)) {
465
+ routes.push(...generateRoutes(socketPath, serviceType));
466
+ }
467
+ }
468
+ }
469
+ }
470
+ }
471
+ /**
472
+ * Add the server type initializers.
473
+ * @internal
474
+ */
475
+ addServerTypeInitialisers() {
476
+ this._engineCore.addTypeInitialiser("authenticationComponent", this._config.authenticationComponent, initialiseAuthenticationComponent);
477
+ this._engineCore.addTypeInitialiser("informationComponent", this._config.informationComponent, initialiseInformationComponent);
478
+ this._engineCore.addTypeInitialiser("restRouteProcessor", this._config.restRouteProcessor, initialiseRestRouteProcessorComponent);
479
+ this._engineCore.addTypeInitialiser("socketRouteProcessor", this._config.socketRouteProcessor, initialiseSocketRouteProcessorComponent);
480
+ this._engineCore.addTypeInitialiser("mimeTypeProcessor", this._config.mimeTypeProcessor, initialiseMimeTypeProcessorComponent);
481
+ }
482
+ /**
483
+ * Add the server REST route generators.
484
+ * @internal
485
+ */
486
+ addServerRestRouteGenerators() {
487
+ this.addRestRouteGenerator("informationComponent", this._config.informationComponent, generateRestRoutesInformation);
488
+ this.addRestRouteGenerator("authenticationComponent", this._config.authenticationComponent, generateRestRoutesAuthentication);
489
+ const coreConfig = this._engineCore.getConfig();
490
+ this.addRestRouteGenerator("loggingComponent", coreConfig.loggingComponent, generateRestRoutesBlobStorage);
491
+ this.addRestRouteGenerator("telemetryComponent", coreConfig.telemetryComponent, generateRestRoutesTelemetry);
492
+ this.addRestRouteGenerator("blobStorageComponent", coreConfig.blobStorageComponent, generateRestRoutesLogging);
493
+ this.addRestRouteGenerator("identityComponent", coreConfig.identityComponent, generateRestRoutesIdentity);
494
+ this.addRestRouteGenerator("identityProfileComponent", coreConfig.identityProfileComponent, generateRestRoutesIdentityProfile);
495
+ this.addRestRouteGenerator("nftComponent", coreConfig.nftComponent, generateRestRoutesNft);
496
+ this.addRestRouteGenerator("attestationComponent", coreConfig.attestationComponent, generateRestRoutesAttestation);
497
+ this.addRestRouteGenerator("auditableItemGraphComponent", coreConfig.auditableItemGraphComponent, generateRestRoutesAuditableItemGraph);
498
+ this.addRestRouteGenerator("auditableItemStreamComponent", coreConfig.auditableItemStreamComponent, generateRestRoutesAuditableItemStream);
499
+ this.addRestRouteGenerator("entityStorageComponent", coreConfig.entityStorageComponent, generateRestRoutesEntityStorage);
500
+ }
501
+ /**
502
+ * Add the server socket route generators.
503
+ * @internal
504
+ */
505
+ addServerSocketRouteGenerators() {
506
+ // const coreConfig = this._engineCore.getConfig();
507
+ // this.addSocketRouteGenerator("eventBusComponent", coreConfig.eventBusComponent, generateSocketRoutesEventBus);
508
+ }
509
+ }
510
+
511
+ export { EngineServer };
@@ -0,0 +1,11 @@
1
+ import { type IEngineCoreContext, type AuthenticationComponentConfig, type IEngineCore } from "@twin.org/engine-models";
2
+ /**
3
+ * Initialise the authentication.
4
+ * @param engineCore The engine core.
5
+ * @param context The context for the engine.
6
+ * @param instanceConfig The instance config.
7
+ * @param overrideInstanceType The instance type to override the default.
8
+ * @returns The name of the instance created.
9
+ * @throws GeneralError if the component type is unknown.
10
+ */
11
+ export declare function initialiseAuthenticationComponent(engineCore: IEngineCore, context: IEngineCoreContext, instanceConfig: AuthenticationComponentConfig, overrideInstanceType?: string): string | undefined;
@@ -0,0 +1,11 @@
1
+ import { type IEngineCore, type IEngineCoreContext, type InformationComponentConfig } from "@twin.org/engine-models";
2
+ /**
3
+ * Initialise the information component.
4
+ * @param engineCore The engine core.
5
+ * @param context The context for the engine.
6
+ * @param instanceConfig The instance config.
7
+ * @param overrideInstanceType The instance type to override the default.
8
+ * @returns The name of the instance created.
9
+ * @throws GeneralError if the component type is unknown.
10
+ */
11
+ export declare function initialiseInformationComponent(engineCore: IEngineCore, context: IEngineCoreContext, instanceConfig: InformationComponentConfig, overrideInstanceType?: string): string | undefined;
@@ -0,0 +1,11 @@
1
+ import { type IEngineCore, type IEngineCoreContext, type MimeTypeProcessorConfig } from "@twin.org/engine-models";
2
+ /**
3
+ * Initialise the mime type processor.
4
+ * @param engineCore The engine core.
5
+ * @param context The context for the engine.
6
+ * @param instanceConfig The instance config.
7
+ * @param overrideInstanceType The instance type to override the default.
8
+ * @returns The name of the instance created.
9
+ * @throws GeneralError if the component type is unknown.
10
+ */
11
+ export declare function initialiseMimeTypeProcessorComponent(engineCore: IEngineCore, context: IEngineCoreContext, instanceConfig: MimeTypeProcessorConfig, overrideInstanceType?: string): string | undefined;
@@ -0,0 +1,11 @@
1
+ import { type IEngineCoreContext, type IEngineCore, type RestRouteProcessorConfig } from "@twin.org/engine-models";
2
+ /**
3
+ * Initialise the rest route processor.
4
+ * @param engineCore The engine core.
5
+ * @param context The context for the engine.
6
+ * @param instanceConfig The instance config.
7
+ * @param overrideInstanceType The instance type to override the default.
8
+ * @returns The name of the instance created.
9
+ * @throws GeneralError if the component type is unknown.
10
+ */
11
+ export declare function initialiseRestRouteProcessorComponent(engineCore: IEngineCore, context: IEngineCoreContext, instanceConfig: RestRouteProcessorConfig, overrideInstanceType?: string): string | undefined;
@@ -0,0 +1,11 @@
1
+ import { type IEngineCoreContext, type IEngineCore, type SocketRouteProcessorConfig } from "@twin.org/engine-models";
2
+ /**
3
+ * Initialise the socket route processor.
4
+ * @param engineCore The engine core.
5
+ * @param context The context for the engine.
6
+ * @param instanceConfig The instance config.
7
+ * @param overrideInstanceType The instance type to override the default.
8
+ * @returns The name of the instance created.
9
+ * @throws GeneralError if the component type is unknown.
10
+ */
11
+ export declare function initialiseSocketRouteProcessorComponent(engineCore: IEngineCore, context: IEngineCoreContext, instanceConfig: SocketRouteProcessorConfig, overrideInstanceType?: string): string | undefined;
@@ -0,0 +1,48 @@
1
+ import { type IEngineCore, type IEngineCoreTypeConfig, type IEngineServer, type IEngineServerConfig, type RestRouteGenerator, type SocketRouteGenerator } from "@twin.org/engine-models";
2
+ /**
3
+ * Server for the engine.
4
+ */
5
+ export declare class EngineServer implements IEngineServer {
6
+ /**
7
+ * Runtime name for the class.
8
+ */
9
+ readonly CLASS_NAME: string;
10
+ /**
11
+ * The server config.
12
+ */
13
+ protected readonly _config: IEngineServerConfig;
14
+ /**
15
+ * Create a new instance of EngineServer.
16
+ * @param options The options for the engine.
17
+ * @param options.server The server options for the engine.
18
+ * @param options.engineCore The engine core to serve from.
19
+ */
20
+ constructor(options: {
21
+ engineCore: IEngineCore;
22
+ server?: IEngineServerConfig;
23
+ });
24
+ /**
25
+ * Add a REST route generator.
26
+ * @param type The type to add the generator for.
27
+ * @param typeConfig The type config.
28
+ * @param generator The generator to add.
29
+ */
30
+ addRestRouteGenerator(type: string, typeConfig: IEngineCoreTypeConfig[] | undefined, generator: RestRouteGenerator): void;
31
+ /**
32
+ * Add a socket route generator.
33
+ * @param type The type to add the generator for.
34
+ * @param typeConfig The type config.
35
+ * @param generator The generator to add.
36
+ */
37
+ addSocketRouteGenerator(type: string, typeConfig: IEngineCoreTypeConfig[] | undefined, generator: SocketRouteGenerator): void;
38
+ /**
39
+ * Start the engine server.
40
+ * @returns Nothing.
41
+ */
42
+ start(): Promise<void>;
43
+ /**
44
+ * Stop the engine server.
45
+ * @returns Nothing.
46
+ */
47
+ stop(): Promise<void>;
48
+ }
@@ -0,0 +1 @@
1
+ export * from "./engineServer";
@@ -0,0 +1,5 @@
1
+ # @twin.org/engine-server - Changelog
2
+
3
+ ## v0.0.1-next.1
4
+
5
+ - Initial Release
@@ -0,0 +1 @@
1
+ # @twin.org/engine-server - Examples