@twin.org/engine-server 0.0.2-next.2 → 0.0.2-next.21
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/dist/cjs/index.cjs +260 -148
- package/dist/esm/index.mjs +260 -148
- package/dist/types/engineServer.d.ts +4 -6
- package/dist/types/utils/engineServerConfigHelper.d.ts +1 -1
- package/docs/changelog.md +342 -0
- package/docs/reference/classes/EngineServer.md +3 -15
- package/docs/reference/functions/addDefaultRestPaths.md +1 -1
- package/package.json +12 -4
package/dist/esm/index.mjs
CHANGED
|
@@ -4,6 +4,201 @@ import { Guards, Is, StringHelper } from '@twin.org/core';
|
|
|
4
4
|
import { RestRouteProcessorType, SocketRouteProcessorType } from '@twin.org/engine-server-types';
|
|
5
5
|
import { ModuleHelper } from '@twin.org/modules';
|
|
6
6
|
|
|
7
|
+
var serverRestRouteGenerators = [
|
|
8
|
+
{
|
|
9
|
+
type: "informationComponent",
|
|
10
|
+
module: "@twin.org/api-service",
|
|
11
|
+
method: "generateRestRoutesInformation",
|
|
12
|
+
defaultPath: ""
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
type: "authenticationComponent",
|
|
16
|
+
module: "@twin.org/api-auth-entity-storage-service",
|
|
17
|
+
method: "generateRestRoutesAuthentication",
|
|
18
|
+
defaultPath: "/authentication"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: "loggingComponent",
|
|
22
|
+
module: "@twin.org/logging-service",
|
|
23
|
+
method: "generateRestRoutesLogging",
|
|
24
|
+
defaultPath: "/logging"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: "telemetryComponent",
|
|
28
|
+
module: "@twin.org/telemetry-service",
|
|
29
|
+
method: "generateRestRoutesTelemetry",
|
|
30
|
+
defaultPath: "/telemetry"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "blobStorageComponent",
|
|
34
|
+
module: "@twin.org/blob-storage-service",
|
|
35
|
+
method: "generateRestRoutesBlobStorage",
|
|
36
|
+
defaultPath: "/blob"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: "identityComponent",
|
|
40
|
+
module: "@twin.org/identity-service",
|
|
41
|
+
method: "generateRestRoutesIdentity",
|
|
42
|
+
defaultPath: "/identity"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "identityResolverComponent",
|
|
46
|
+
module: "@twin.org/identity-service",
|
|
47
|
+
method: "generateRestRoutesIdentityResolver",
|
|
48
|
+
defaultPath: "/identity"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: "identityProfileComponent",
|
|
52
|
+
module: "@twin.org/identity-service",
|
|
53
|
+
method: "generateRestRoutesIdentityProfile",
|
|
54
|
+
defaultPath: "/identity/profile"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "nftComponent",
|
|
58
|
+
module: "@twin.org/nft-service",
|
|
59
|
+
method: "generateRestRoutesNft",
|
|
60
|
+
defaultPath: "/nft"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: "verifiableStorageComponent",
|
|
64
|
+
module: "@twin.org/verifiable-storage-service",
|
|
65
|
+
method: "generateRestRoutesVerifiableStorage",
|
|
66
|
+
defaultPath: "/verifiable"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: "immutableProofComponent",
|
|
70
|
+
module: "@twin.org/immutable-proof-service",
|
|
71
|
+
method: "generateRestRoutesImmutableProof",
|
|
72
|
+
defaultPath: "/immutable-proof"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: "attestationComponent",
|
|
76
|
+
module: "@twin.org/attestation-service",
|
|
77
|
+
method: "generateRestRoutesAttestation",
|
|
78
|
+
defaultPath: "/attestation"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: "auditableItemGraphComponent",
|
|
82
|
+
module: "@twin.org/auditable-item-graph-service",
|
|
83
|
+
method: "generateRestRoutesAuditableItemGraph",
|
|
84
|
+
defaultPath: "/aig"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: "auditableItemStreamComponent",
|
|
88
|
+
module: "@twin.org/auditable-item-stream-service",
|
|
89
|
+
method: "generateRestRoutesAuditableItemStream",
|
|
90
|
+
defaultPath: "/ais"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: "entityStorageComponent",
|
|
94
|
+
module: "@twin.org/entity-storage-service",
|
|
95
|
+
method: "generateRestRoutesEntityStorage"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: "dataProcessingComponent",
|
|
99
|
+
module: "@twin.org/data-processing-service",
|
|
100
|
+
method: "generateRestRoutesDataProcessing",
|
|
101
|
+
defaultPath: "/data-processing"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
type: "documentManagementComponent",
|
|
105
|
+
module: "@twin.org/document-management-service",
|
|
106
|
+
method: "generateRestRoutesDocumentManagement",
|
|
107
|
+
defaultPath: "/documents"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: "rightsManagementPapComponent",
|
|
111
|
+
module: "@twin.org/rights-management-service",
|
|
112
|
+
method: "generateRestRoutesPolicyAdministrationPoint",
|
|
113
|
+
defaultPath: "/rights-management"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
type: "rightsManagementPnpComponent",
|
|
117
|
+
module: "@twin.org/rights-management-service",
|
|
118
|
+
method: "generateRestRoutesPolicyNegotiationPoint",
|
|
119
|
+
defaultPath: "/rights-management"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: "rightsManagementPnapComponent",
|
|
123
|
+
module: "@twin.org/rights-management-service",
|
|
124
|
+
method: "generateRestRoutesPolicyNegotiationAdminPoint",
|
|
125
|
+
defaultPath: "/rights-management"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
type: "rightsManagementDapComponent",
|
|
129
|
+
module: "@twin.org/rights-management-service",
|
|
130
|
+
method: "generateRestRoutesDataAccessPoint",
|
|
131
|
+
defaultPath: "/rights-management"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
type: "synchronisedStorageComponent",
|
|
135
|
+
module: "@twin.org/synchronised-storage-service",
|
|
136
|
+
method: "generateRestRoutesSynchronisedStorage",
|
|
137
|
+
defaultPath: "/synchronised-storage"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
type: "federatedCatalogueComponent",
|
|
141
|
+
module: "@twin.org/federated-catalogue-service",
|
|
142
|
+
method: "generateRestRoutesFederatedCatalogue",
|
|
143
|
+
defaultPath: "/federated-catalogue"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
type: "dataSpaceConnectorComponent",
|
|
147
|
+
module: "@twin.org/data-space-connector-service",
|
|
148
|
+
method: "generateRestRoutesDataSpaceConnector",
|
|
149
|
+
defaultPath: "/data-space-connector"
|
|
150
|
+
}
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
var serverSocketRouteGenerators = [
|
|
154
|
+
{
|
|
155
|
+
type: "eventBusComponent",
|
|
156
|
+
module: "@twin.org/event-bus-service",
|
|
157
|
+
method: "generateSocketRoutesEventBus",
|
|
158
|
+
defaultPath: "event-bus"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
type: "dataSpaceConnectorComponent",
|
|
162
|
+
module: "@twin.org/data-space-connector-service",
|
|
163
|
+
method: "generateSocketRoutesDataSpaceConnector",
|
|
164
|
+
defaultPath: "data-space-connector"
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
var serverTypeInitialisers = [
|
|
169
|
+
{
|
|
170
|
+
type: "authenticationAdminComponent",
|
|
171
|
+
module: "@twin.org/engine-server-types",
|
|
172
|
+
method: "initialiseAuthenticationAdminComponent"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
type: "authenticationComponent",
|
|
176
|
+
module: "@twin.org/engine-server-types",
|
|
177
|
+
method: "initialiseAuthenticationComponent"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
type: "informationComponent",
|
|
181
|
+
module: "@twin.org/engine-server-types",
|
|
182
|
+
method: "initialiseInformationComponent",
|
|
183
|
+
defaultRestPath: ""
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
type: "restRouteProcessor",
|
|
187
|
+
module: "@twin.org/engine-server-types",
|
|
188
|
+
method: "initialiseRestRouteProcessorComponent"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
type: "socketRouteProcessor",
|
|
192
|
+
module: "@twin.org/engine-server-types",
|
|
193
|
+
method: "initialiseSocketRouteProcessorComponent"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
type: "mimeTypeProcessor",
|
|
197
|
+
module: "@twin.org/engine-server-types",
|
|
198
|
+
method: "initialiseMimeTypeProcessorComponent"
|
|
199
|
+
}
|
|
200
|
+
];
|
|
201
|
+
|
|
7
202
|
/**
|
|
8
203
|
* Server for the engine.
|
|
9
204
|
*/
|
|
@@ -11,7 +206,7 @@ class EngineServer {
|
|
|
11
206
|
/**
|
|
12
207
|
* Runtime name for the class.
|
|
13
208
|
*/
|
|
14
|
-
CLASS_NAME = "EngineServer";
|
|
209
|
+
static CLASS_NAME = "EngineServer";
|
|
15
210
|
/**
|
|
16
211
|
* The engine.
|
|
17
212
|
* @internal
|
|
@@ -32,11 +227,6 @@ class EngineServer {
|
|
|
32
227
|
* @internal
|
|
33
228
|
*/
|
|
34
229
|
_webServer;
|
|
35
|
-
/**
|
|
36
|
-
* The logging connector type.
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
_loggingConnectorType;
|
|
40
230
|
/**
|
|
41
231
|
* The REST routes for the application.
|
|
42
232
|
* @internal
|
|
@@ -53,8 +243,8 @@ class EngineServer {
|
|
|
53
243
|
* @param options.engineCore The engine core to serve from.
|
|
54
244
|
*/
|
|
55
245
|
constructor(options) {
|
|
56
|
-
Guards.object(
|
|
57
|
-
Guards.object(
|
|
246
|
+
Guards.object(EngineServer.CLASS_NAME, "options", options);
|
|
247
|
+
Guards.object(EngineServer.CLASS_NAME, "options.engineCore", options.engineCore);
|
|
58
248
|
this._engineCore = options.engineCore;
|
|
59
249
|
this._restRouteGenerators = [];
|
|
60
250
|
this._socketRouteGenerators = [];
|
|
@@ -110,36 +300,34 @@ class EngineServer {
|
|
|
110
300
|
/**
|
|
111
301
|
* Add a REST route generator.
|
|
112
302
|
* @param type The type to add the generator for.
|
|
113
|
-
* @param typeConfig The type config.
|
|
114
303
|
* @param module The module containing the generator.
|
|
115
304
|
* @param method The method to call on the module.
|
|
116
305
|
*/
|
|
117
|
-
addRestRouteGenerator(type,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
306
|
+
addRestRouteGenerator(type, module, method) {
|
|
307
|
+
Guards.stringValue(EngineServer.CLASS_NAME, "type", type);
|
|
308
|
+
Guards.stringValue(EngineServer.CLASS_NAME, "module", module);
|
|
309
|
+
Guards.stringValue(EngineServer.CLASS_NAME, "method", method);
|
|
310
|
+
this._restRouteGenerators.push({
|
|
311
|
+
type,
|
|
312
|
+
module,
|
|
313
|
+
method
|
|
314
|
+
});
|
|
126
315
|
}
|
|
127
316
|
/**
|
|
128
317
|
* Add a socket route generator.
|
|
129
318
|
* @param type The type to add the generator for.
|
|
130
|
-
* @param typeConfig The type config.
|
|
131
319
|
* @param module The module containing the generator.
|
|
132
320
|
* @param method The method to call on the module.
|
|
133
321
|
*/
|
|
134
|
-
addSocketRouteGenerator(type,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
322
|
+
addSocketRouteGenerator(type, module, method) {
|
|
323
|
+
Guards.stringValue(EngineServer.CLASS_NAME, "type", type);
|
|
324
|
+
Guards.stringValue(EngineServer.CLASS_NAME, "module", module);
|
|
325
|
+
Guards.stringValue(EngineServer.CLASS_NAME, "method", method);
|
|
326
|
+
this._socketRouteGenerators.push({
|
|
327
|
+
type,
|
|
328
|
+
module,
|
|
329
|
+
method
|
|
330
|
+
});
|
|
143
331
|
}
|
|
144
332
|
/**
|
|
145
333
|
* Get the built REST routes.
|
|
@@ -188,10 +376,11 @@ class EngineServer {
|
|
|
188
376
|
const socketRouteProcessors = SocketRouteProcessorFactory.names().map(n => SocketRouteProcessorFactory.get(n));
|
|
189
377
|
const mimeTypeProcessors = MimeTypeProcessorFactory.names().map(n => MimeTypeProcessorFactory.get(n));
|
|
190
378
|
const coreConfig = this._engineCore.getConfig();
|
|
191
|
-
const
|
|
192
|
-
|
|
379
|
+
const loggingComponentType = coreConfig.silent
|
|
380
|
+
? undefined
|
|
381
|
+
: this._engineCore.getRegisteredInstanceType("loggingComponent");
|
|
193
382
|
this._webServer = new FastifyWebServer({
|
|
194
|
-
|
|
383
|
+
loggingComponentType,
|
|
195
384
|
mimeTypeProcessors
|
|
196
385
|
});
|
|
197
386
|
await this._webServer.build(restRouteProcessors, this._restRoutes, socketRouteProcessors, this._socketRoutes, coreConfig.web);
|
|
@@ -204,8 +393,8 @@ class EngineServer {
|
|
|
204
393
|
*/
|
|
205
394
|
async buildRestRoutes() {
|
|
206
395
|
const routes = [];
|
|
207
|
-
for (const { type,
|
|
208
|
-
await this.initialiseRestTypeRoute(routes, type,
|
|
396
|
+
for (const { type, module, method } of this._restRouteGenerators) {
|
|
397
|
+
await this.initialiseRestTypeRoute(routes, type, module, method);
|
|
209
398
|
}
|
|
210
399
|
return routes;
|
|
211
400
|
}
|
|
@@ -216,8 +405,8 @@ class EngineServer {
|
|
|
216
405
|
*/
|
|
217
406
|
async buildSocketRoutes() {
|
|
218
407
|
const routes = [];
|
|
219
|
-
for (const { type,
|
|
220
|
-
await this.initialiseSocketTypeRoute(routes, type,
|
|
408
|
+
for (const { type, module, method } of this._socketRouteGenerators) {
|
|
409
|
+
await this.initialiseSocketTypeRoute(routes, type, module, method);
|
|
221
410
|
}
|
|
222
411
|
return routes;
|
|
223
412
|
}
|
|
@@ -225,20 +414,21 @@ class EngineServer {
|
|
|
225
414
|
* Initialise the rest routes from connector.
|
|
226
415
|
* @param routes The routes to add to.
|
|
227
416
|
* @param typeKey The key for the default types.
|
|
228
|
-
* @param typeConfig The type config.
|
|
229
417
|
* @param generateRoutes The function to generate the routes.
|
|
230
418
|
* @internal
|
|
231
419
|
*/
|
|
232
|
-
async initialiseRestTypeRoute(routes, typeKey,
|
|
420
|
+
async initialiseRestTypeRoute(routes, typeKey, module, method) {
|
|
421
|
+
const typeConfig = this._engineCore.getTypeConfig(typeKey);
|
|
233
422
|
if (Is.arrayValue(typeConfig)) {
|
|
234
|
-
const defaultEngineTypes = this._engineCore.getDefaultTypes();
|
|
235
423
|
const generateRoutes = await ModuleHelper.getModuleEntry(module, method);
|
|
236
424
|
for (let i = 0; i < typeConfig.length; i++) {
|
|
237
425
|
const restPath = typeConfig[i].restPath;
|
|
426
|
+
const restOptions = typeConfig[i].restOptions;
|
|
238
427
|
if (Is.string(restPath)) {
|
|
239
|
-
const serviceType = typeConfig[i].overrideInstanceType ??
|
|
428
|
+
const serviceType = typeConfig[i].overrideInstanceType ??
|
|
429
|
+
this._engineCore.getRegisteredInstanceType(typeKey);
|
|
240
430
|
if (Is.stringValue(serviceType)) {
|
|
241
|
-
const generatedRoutes = generateRoutes(restPath, serviceType);
|
|
431
|
+
const generatedRoutes = generateRoutes(restPath, serviceType, restOptions);
|
|
242
432
|
for (const route of generatedRoutes) {
|
|
243
433
|
// Don't strip trailing slashes from the root path.
|
|
244
434
|
if (Is.stringValue(route.path) && route.path.length > 1) {
|
|
@@ -255,21 +445,22 @@ class EngineServer {
|
|
|
255
445
|
* Initialise the socket routes from connector.
|
|
256
446
|
* @param routes The routes to add to.
|
|
257
447
|
* @param typeKey The key for the default types.
|
|
258
|
-
* @param typeConfig The type config.
|
|
259
448
|
* @param module The module containing the generator.
|
|
260
449
|
* @param method The method to call on the module.
|
|
261
450
|
* @internal
|
|
262
451
|
*/
|
|
263
|
-
async initialiseSocketTypeRoute(routes, typeKey,
|
|
452
|
+
async initialiseSocketTypeRoute(routes, typeKey, module, method) {
|
|
453
|
+
const typeConfig = this._engineCore.getTypeConfig(typeKey);
|
|
264
454
|
if (Is.arrayValue(typeConfig)) {
|
|
265
|
-
const defaultEngineTypes = this._engineCore.getDefaultTypes();
|
|
266
455
|
const generateRoutes = await ModuleHelper.getModuleEntry(module, method);
|
|
267
456
|
for (let i = 0; i < typeConfig.length; i++) {
|
|
268
457
|
const socketPath = typeConfig[i].socketPath;
|
|
458
|
+
const socketOptions = typeConfig[i].socketOptions;
|
|
269
459
|
if (Is.string(socketPath)) {
|
|
270
|
-
const serviceType = typeConfig[i].overrideInstanceType ??
|
|
460
|
+
const serviceType = typeConfig[i].overrideInstanceType ??
|
|
461
|
+
this._engineCore.getRegisteredInstanceType(typeKey);
|
|
271
462
|
if (Is.stringValue(serviceType)) {
|
|
272
|
-
routes.push(...generateRoutes(socketPath, serviceType));
|
|
463
|
+
routes.push(...generateRoutes(socketPath, serviceType, socketOptions));
|
|
273
464
|
}
|
|
274
465
|
}
|
|
275
466
|
}
|
|
@@ -280,127 +471,44 @@ class EngineServer {
|
|
|
280
471
|
* @internal
|
|
281
472
|
*/
|
|
282
473
|
addServerTypeInitialisers() {
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
this._engineCore.addTypeInitialiser("informationComponent", coreConfig.types.informationComponent, "@twin.org/engine-server-types", "initialiseInformationComponent");
|
|
287
|
-
this._engineCore.addTypeInitialiser("restRouteProcessor", coreConfig.types.restRouteProcessor, "@twin.org/engine-server-types", "initialiseRestRouteProcessorComponent");
|
|
288
|
-
this._engineCore.addTypeInitialiser("socketRouteProcessor", coreConfig.types.socketRouteProcessor, "@twin.org/engine-server-types", "initialiseSocketRouteProcessorComponent");
|
|
289
|
-
this._engineCore.addTypeInitialiser("mimeTypeProcessor", coreConfig.types.mimeTypeProcessor, "@twin.org/engine-server-types", "initialiseMimeTypeProcessorComponent");
|
|
474
|
+
for (const initializer of serverTypeInitialisers) {
|
|
475
|
+
this._engineCore.addTypeInitialiser(initializer.type, initializer.module, initializer.method);
|
|
476
|
+
}
|
|
290
477
|
}
|
|
291
478
|
/**
|
|
292
479
|
* Add the server REST route generators.
|
|
293
480
|
* @internal
|
|
294
481
|
*/
|
|
295
482
|
addServerRestRouteGenerators() {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
this.addRestRouteGenerator("loggingComponent", coreConfig.types.loggingComponent, "@twin.org/logging-service", "generateRestRoutesLogging");
|
|
300
|
-
this.addRestRouteGenerator("telemetryComponent", coreConfig.types.telemetryComponent, "@twin.org/telemetry-service", "generateRestRoutesTelemetry");
|
|
301
|
-
this.addRestRouteGenerator("blobStorageComponent", coreConfig.types.blobStorageComponent, "@twin.org/blob-storage-service", "generateRestRoutesBlobStorage");
|
|
302
|
-
this.addRestRouteGenerator("identityComponent", coreConfig.types.identityComponent, "@twin.org/identity-service", "generateRestRoutesIdentity");
|
|
303
|
-
this.addRestRouteGenerator("identityResolverComponent", coreConfig.types.identityResolverComponent, "@twin.org/identity-service", "generateRestRoutesIdentityResolver");
|
|
304
|
-
this.addRestRouteGenerator("identityProfileComponent", coreConfig.types.identityProfileComponent, "@twin.org/identity-service", "generateRestRoutesIdentityProfile");
|
|
305
|
-
this.addRestRouteGenerator("nftComponent", coreConfig.types.nftComponent, "@twin.org/nft-service", "generateRestRoutesNft");
|
|
306
|
-
this.addRestRouteGenerator("verifiableStorageComponent", coreConfig.types.verifiableStorageComponent, "@twin.org/verifiable-storage-service", "generateRestRoutesVerifiableStorage");
|
|
307
|
-
this.addRestRouteGenerator("attestationComponent", coreConfig.types.attestationComponent, "@twin.org/attestation-service", "generateRestRoutesAttestation");
|
|
308
|
-
this.addRestRouteGenerator("immutableProofComponent", coreConfig.types.immutableProofComponent, "@twin.org/immutable-proof-service", "generateRestRoutesImmutableProof");
|
|
309
|
-
this.addRestRouteGenerator("auditableItemGraphComponent", coreConfig.types.auditableItemGraphComponent, "@twin.org/auditable-item-graph-service", "generateRestRoutesAuditableItemGraph");
|
|
310
|
-
this.addRestRouteGenerator("auditableItemStreamComponent", coreConfig.types.auditableItemStreamComponent, "@twin.org/auditable-item-stream-service", "generateRestRoutesAuditableItemStream");
|
|
311
|
-
this.addRestRouteGenerator("entityStorageComponent", coreConfig.types.entityStorageComponent, "@twin.org/entity-storage-service", "generateRestRoutesEntityStorage");
|
|
312
|
-
this.addRestRouteGenerator("dataProcessingComponent", coreConfig.types.dataProcessingComponent, "@twin.org/data-processing-service", "generateRestRoutesDataProcessing");
|
|
313
|
-
this.addRestRouteGenerator("documentManagementComponent", coreConfig.types.documentManagementComponent, "@twin.org/document-management-service", "generateRestRoutesDocumentManagement");
|
|
314
|
-
this.addRestRouteGenerator("federatedCatalogueComponent", coreConfig.types.federatedCatalogueComponent, "@twin.org/federated-catalogue-service", "generateRestRoutesFederatedCatalogue");
|
|
315
|
-
this.addRestRouteGenerator("rightsManagementComponent", coreConfig.types.rightsManagementComponent, "@twin.org/rights-management-service", "generateRestRoutesRightsManagement");
|
|
483
|
+
for (const generator of serverRestRouteGenerators) {
|
|
484
|
+
this.addRestRouteGenerator(generator.type, generator.module, generator.method);
|
|
485
|
+
}
|
|
316
486
|
}
|
|
317
487
|
/**
|
|
318
488
|
* Add the server socket route generators.
|
|
319
489
|
* @internal
|
|
320
490
|
*/
|
|
321
491
|
addServerSocketRouteGenerators() {
|
|
322
|
-
const
|
|
323
|
-
|
|
492
|
+
for (const generator of serverSocketRouteGenerators) {
|
|
493
|
+
this.addSocketRouteGenerator(generator.type, generator.module, generator.method);
|
|
494
|
+
}
|
|
324
495
|
}
|
|
325
496
|
}
|
|
326
497
|
|
|
327
498
|
// Copyright 2024 IOTA Stiftung.
|
|
328
499
|
// SPDX-License-Identifier: Apache-2.0.
|
|
329
500
|
/**
|
|
330
|
-
* Adds the rest paths to the server config.
|
|
501
|
+
* Adds the rest paths to the server config if not already set.
|
|
331
502
|
* @param serverConfig The server config.
|
|
332
503
|
*/
|
|
333
504
|
function addDefaultRestPaths(serverConfig) {
|
|
334
|
-
|
|
335
|
-
serverConfig.types.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (Is.arrayValue(serverConfig.types.blobStorageComponent) &&
|
|
342
|
-
!Is.stringValue(serverConfig.types.blobStorageComponent[0].restPath)) {
|
|
343
|
-
serverConfig.types.blobStorageComponent[0].restPath = "/blob";
|
|
344
|
-
}
|
|
345
|
-
if (Is.arrayValue(serverConfig.types.loggingComponent) &&
|
|
346
|
-
!Is.stringValue(serverConfig.types.loggingComponent[0].restPath)) {
|
|
347
|
-
serverConfig.types.loggingComponent[0].restPath = "/logging";
|
|
348
|
-
}
|
|
349
|
-
if (Is.arrayValue(serverConfig.types.telemetryComponent) &&
|
|
350
|
-
!Is.stringValue(serverConfig.types.telemetryComponent[0].restPath)) {
|
|
351
|
-
serverConfig.types.telemetryComponent[0].restPath = "/telemetry";
|
|
352
|
-
}
|
|
353
|
-
if (Is.arrayValue(serverConfig.types.identityComponent) &&
|
|
354
|
-
!Is.stringValue(serverConfig.types.identityComponent[0].restPath)) {
|
|
355
|
-
serverConfig.types.identityComponent[0].restPath = "/identity";
|
|
356
|
-
}
|
|
357
|
-
if (Is.arrayValue(serverConfig.types.identityResolverComponent) &&
|
|
358
|
-
!Is.stringValue(serverConfig.types.identityResolverComponent[0].restPath)) {
|
|
359
|
-
serverConfig.types.identityResolverComponent[0].restPath = "/identity";
|
|
360
|
-
}
|
|
361
|
-
if (Is.arrayValue(serverConfig.types.identityProfileComponent) &&
|
|
362
|
-
!Is.stringValue(serverConfig.types.identityProfileComponent[0].restPath)) {
|
|
363
|
-
serverConfig.types.identityProfileComponent[0].restPath = "/identity/profile";
|
|
364
|
-
}
|
|
365
|
-
if (Is.arrayValue(serverConfig.types.nftComponent) &&
|
|
366
|
-
!Is.stringValue(serverConfig.types.nftComponent[0].restPath)) {
|
|
367
|
-
serverConfig.types.nftComponent[0].restPath = "/nft";
|
|
368
|
-
}
|
|
369
|
-
if (Is.arrayValue(serverConfig.types.verifiableStorageComponent) &&
|
|
370
|
-
!Is.stringValue(serverConfig.types.verifiableStorageComponent[0].restPath)) {
|
|
371
|
-
serverConfig.types.verifiableStorageComponent[0].restPath = "/verifiable";
|
|
372
|
-
}
|
|
373
|
-
if (Is.arrayValue(serverConfig.types.immutableProofComponent) &&
|
|
374
|
-
!Is.stringValue(serverConfig.types.immutableProofComponent[0].restPath)) {
|
|
375
|
-
serverConfig.types.immutableProofComponent[0].restPath = "/immutable-proof";
|
|
376
|
-
}
|
|
377
|
-
if (Is.arrayValue(serverConfig.types.attestationComponent) &&
|
|
378
|
-
!Is.stringValue(serverConfig.types.attestationComponent[0].restPath)) {
|
|
379
|
-
serverConfig.types.attestationComponent[0].restPath = "/attestation";
|
|
380
|
-
}
|
|
381
|
-
if (Is.arrayValue(serverConfig.types.auditableItemGraphComponent) &&
|
|
382
|
-
!Is.stringValue(serverConfig.types.auditableItemGraphComponent[0].restPath)) {
|
|
383
|
-
serverConfig.types.auditableItemGraphComponent[0].restPath = "/aig";
|
|
384
|
-
}
|
|
385
|
-
if (Is.arrayValue(serverConfig.types.auditableItemStreamComponent) &&
|
|
386
|
-
!Is.stringValue(serverConfig.types.auditableItemStreamComponent[0].restPath)) {
|
|
387
|
-
serverConfig.types.auditableItemStreamComponent[0].restPath = "/ais";
|
|
388
|
-
}
|
|
389
|
-
if (Is.arrayValue(serverConfig.types.dataProcessingComponent) &&
|
|
390
|
-
!Is.stringValue(serverConfig.types.dataProcessingComponent[0].restPath)) {
|
|
391
|
-
serverConfig.types.dataProcessingComponent[0].restPath = "/data-processing";
|
|
392
|
-
}
|
|
393
|
-
if (Is.arrayValue(serverConfig.types.documentManagementComponent) &&
|
|
394
|
-
!Is.stringValue(serverConfig.types.documentManagementComponent[0].restPath)) {
|
|
395
|
-
serverConfig.types.documentManagementComponent[0].restPath = "/documents";
|
|
396
|
-
}
|
|
397
|
-
if (Is.arrayValue(serverConfig.types.federatedCatalogueComponent) &&
|
|
398
|
-
!Is.stringValue(serverConfig.types.federatedCatalogueComponent[0].restPath)) {
|
|
399
|
-
serverConfig.types.federatedCatalogueComponent[0].restPath = "/federated-catalogue";
|
|
400
|
-
}
|
|
401
|
-
if (Is.arrayValue(serverConfig.types.rightsManagementComponent) &&
|
|
402
|
-
!Is.stringValue(serverConfig.types.rightsManagementComponent[0].restPath)) {
|
|
403
|
-
serverConfig.types.rightsManagementComponent[0].restPath = "/rights-management";
|
|
505
|
+
for (const routeGenerator of serverRestRouteGenerators) {
|
|
506
|
+
const types = serverConfig.types[routeGenerator.type];
|
|
507
|
+
if (Is.arrayValue(types) &&
|
|
508
|
+
!Is.stringValue(types[0].restPath) &&
|
|
509
|
+
Is.string(routeGenerator.defaultPath)) {
|
|
510
|
+
types[0].restPath = routeGenerator.defaultPath;
|
|
511
|
+
}
|
|
404
512
|
}
|
|
405
513
|
}
|
|
406
514
|
/**
|
|
@@ -408,9 +516,13 @@ function addDefaultRestPaths(serverConfig) {
|
|
|
408
516
|
* @param serverConfig The server config.
|
|
409
517
|
*/
|
|
410
518
|
function addDefaultSocketPaths(serverConfig) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
519
|
+
for (const routeGenerator of serverSocketRouteGenerators) {
|
|
520
|
+
const types = serverConfig.types[routeGenerator.type];
|
|
521
|
+
if (Is.arrayValue(types) &&
|
|
522
|
+
!Is.stringValue(types[0].socketPath) &&
|
|
523
|
+
Is.stringValue(routeGenerator.defaultPath)) {
|
|
524
|
+
types[0].socketPath = routeGenerator.defaultPath;
|
|
525
|
+
}
|
|
414
526
|
}
|
|
415
527
|
}
|
|
416
528
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IRestRoute, ISocketRoute } from "@twin.org/api-models";
|
|
2
|
-
import type { IEngineCore,
|
|
2
|
+
import type { IEngineCore, IEngineServer } from "@twin.org/engine-models";
|
|
3
3
|
import { type IEngineServerConfig } from "@twin.org/engine-server-types";
|
|
4
4
|
/**
|
|
5
5
|
* Server for the engine.
|
|
@@ -8,7 +8,7 @@ export declare class EngineServer<T extends IEngineServerConfig = IEngineServerC
|
|
|
8
8
|
/**
|
|
9
9
|
* Runtime name for the class.
|
|
10
10
|
*/
|
|
11
|
-
readonly CLASS_NAME: string;
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
12
|
/**
|
|
13
13
|
* Create a new instance of EngineServer.
|
|
14
14
|
* @param options The options for the engine.
|
|
@@ -20,19 +20,17 @@ export declare class EngineServer<T extends IEngineServerConfig = IEngineServerC
|
|
|
20
20
|
/**
|
|
21
21
|
* Add a REST route generator.
|
|
22
22
|
* @param type The type to add the generator for.
|
|
23
|
-
* @param typeConfig The type config.
|
|
24
23
|
* @param module The module containing the generator.
|
|
25
24
|
* @param method The method to call on the module.
|
|
26
25
|
*/
|
|
27
|
-
addRestRouteGenerator(type: string,
|
|
26
|
+
addRestRouteGenerator(type: string, module: string, method: string): void;
|
|
28
27
|
/**
|
|
29
28
|
* Add a socket route generator.
|
|
30
29
|
* @param type The type to add the generator for.
|
|
31
|
-
* @param typeConfig The type config.
|
|
32
30
|
* @param module The module containing the generator.
|
|
33
31
|
* @param method The method to call on the module.
|
|
34
32
|
*/
|
|
35
|
-
addSocketRouteGenerator(type: string,
|
|
33
|
+
addSocketRouteGenerator(type: string, module: string, method: string): void;
|
|
36
34
|
/**
|
|
37
35
|
* Get the built REST routes.
|
|
38
36
|
* @returns The REST routes.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IEngineServerConfig } from "@twin.org/engine-server-types";
|
|
2
2
|
/**
|
|
3
|
-
* Adds the rest paths to the server config.
|
|
3
|
+
* Adds the rest paths to the server config if not already set.
|
|
4
4
|
* @param serverConfig The server config.
|
|
5
5
|
*/
|
|
6
6
|
export declare function addDefaultRestPaths(serverConfig: IEngineServerConfig): void;
|