@twin.org/engine-server 0.0.3-next.4 → 0.0.3-next.41

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/docs/examples.md CHANGED
@@ -1 +1,79 @@
1
- # @twin.org/engine-server - Examples
1
+ # Engine Server Examples
2
+
3
+ These examples show how to wire a core instance into an HTTP server and apply default REST and socket paths.
4
+
5
+ ## EngineServer
6
+
7
+ ```typescript
8
+ import { Engine } from '@twin.org/engine';
9
+ import { EngineServer } from '@twin.org/engine-server';
10
+ import type { IEngineServerConfig } from '@twin.org/engine-server-types';
11
+ import {
12
+ HostingComponentType,
13
+ InformationComponentType,
14
+ RestRouteProcessorType,
15
+ SocketRouteProcessorType
16
+ } from '@twin.org/engine-server-types';
17
+
18
+ const config: IEngineServerConfig = {
19
+ debug: false,
20
+ silent: true,
21
+ web: { port: 3001 },
22
+ types: {
23
+ hostingComponent: [{ type: HostingComponentType.Service }],
24
+ informationComponent: [{ type: InformationComponentType.Service, restPath: '/info' }],
25
+ restRouteProcessor: [{ type: RestRouteProcessorType.RestRoute }],
26
+ socketRouteProcessor: [{ type: SocketRouteProcessorType.SocketRoute }]
27
+ }
28
+ };
29
+
30
+ const engine = new Engine({ config, skipBootstrap: true });
31
+ const server = new EngineServer({ engineCore: engine });
32
+
33
+ server.addRestRouteGenerator(
34
+ 'informationComponent',
35
+ '@twin.org/engine-server-types',
36
+ 'generateInformationRestRoutes'
37
+ );
38
+ server.addSocketRouteGenerator(
39
+ 'informationComponent',
40
+ '@twin.org/engine-server-types',
41
+ 'generateInformationSocketRoutes'
42
+ );
43
+
44
+ console.log(server.getRestRoutes().length); // 0
45
+ console.log(server.getSocketRoutes().length); // 0
46
+
47
+ await server.start();
48
+ console.log(server.getRestRoutes().length > 0); // true
49
+
50
+ await server.stop();
51
+ ```
52
+
53
+ ## addDefaultRestPaths and addDefaultSocketPaths
54
+
55
+ ```typescript
56
+ import { addDefaultRestPaths, addDefaultSocketPaths } from '@twin.org/engine-server';
57
+ import type { IEngineServerConfig } from '@twin.org/engine-server-types';
58
+ import {
59
+ InformationComponentType,
60
+ RestRouteProcessorType,
61
+ SocketRouteProcessorType
62
+ } from '@twin.org/engine-server-types';
63
+
64
+ const serverConfig: IEngineServerConfig = {
65
+ debug: false,
66
+ silent: false,
67
+ types: {
68
+ informationComponent: [{ type: InformationComponentType.Service }],
69
+ restRouteProcessor: [{ type: RestRouteProcessorType.RestRoute }],
70
+ socketRouteProcessor: [{ type: SocketRouteProcessorType.SocketRoute }]
71
+ }
72
+ };
73
+
74
+ addDefaultRestPaths(serverConfig);
75
+ addDefaultSocketPaths(serverConfig);
76
+
77
+ console.log(typeof serverConfig.types.informationComponent?.[0].restPath === 'string'); // true
78
+ console.log(typeof serverConfig.types.informationComponent?.[0].socketPath === 'string'); // true
79
+ ```
@@ -38,7 +38,7 @@ The engine core to serve from.
38
38
 
39
39
  ## Properties
40
40
 
41
- ### CLASS\_NAME
41
+ ### CLASS\_NAME {#class_name}
42
42
 
43
43
  > `readonly` `static` **CLASS\_NAME**: `string`
44
44
 
@@ -46,7 +46,7 @@ Runtime name for the class.
46
46
 
47
47
  ## Methods
48
48
 
49
- ### addRestRouteGenerator()
49
+ ### addRestRouteGenerator() {#addrestroutegenerator}
50
50
 
51
51
  > **addRestRouteGenerator**(`type`, `module`, `method`): `void`
52
52
 
@@ -82,7 +82,7 @@ The method to call on the module.
82
82
 
83
83
  ***
84
84
 
85
- ### addSocketRouteGenerator()
85
+ ### addSocketRouteGenerator() {#addsocketroutegenerator}
86
86
 
87
87
  > **addSocketRouteGenerator**(`type`, `module`, `method`): `void`
88
88
 
@@ -118,7 +118,7 @@ The method to call on the module.
118
118
 
119
119
  ***
120
120
 
121
- ### getRestRoutes()
121
+ ### getRestRoutes() {#getrestroutes}
122
122
 
123
123
  > **getRestRoutes**(): `IRestRoute`\<`any`, `any`\>[]
124
124
 
@@ -132,7 +132,7 @@ The REST routes.
132
132
 
133
133
  ***
134
134
 
135
- ### getSocketRoutes()
135
+ ### getSocketRoutes() {#getsocketroutes}
136
136
 
137
137
  > **getSocketRoutes**(): `ISocketRoute`\<`any`, `any`\>[]
138
138
 
@@ -146,17 +146,17 @@ The socket routes.
146
146
 
147
147
  ***
148
148
 
149
- ### start()
149
+ ### start() {#start}
150
150
 
151
- > **start**(): `Promise`\<`boolean`\>
151
+ > **start**(): `Promise`\<`void`\>
152
152
 
153
153
  Start the engine server.
154
154
 
155
155
  #### Returns
156
156
 
157
- `Promise`\<`boolean`\>
157
+ `Promise`\<`void`\>
158
158
 
159
- True if the start was successful.
159
+ Nothing.
160
160
 
161
161
  #### Implementation of
162
162
 
@@ -164,7 +164,7 @@ True if the start was successful.
164
164
 
165
165
  ***
166
166
 
167
- ### stop()
167
+ ### stop() {#stop}
168
168
 
169
169
  > **stop**(): `Promise`\<`void`\>
170
170
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/engine-server",
3
- "version": "0.0.3-next.4",
4
- "description": "Engine implementation for a server.",
3
+ "version": "0.0.3-next.41",
4
+ "description": "Server runtime that exposes engine components through REST and socket routes.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/engine.git",
7
+ "url": "git+https://github.com/iotaledger/engine.git",
8
8
  "directory": "packages/engine-server"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -18,9 +18,9 @@
18
18
  "@twin.org/api-server-fastify": "next",
19
19
  "@twin.org/context": "next",
20
20
  "@twin.org/core": "next",
21
- "@twin.org/engine-core": "0.0.3-next.4",
22
- "@twin.org/engine-models": "0.0.3-next.4",
23
- "@twin.org/engine-server-types": "0.0.3-next.4",
21
+ "@twin.org/engine-core": "0.0.3-next.41",
22
+ "@twin.org/engine-models": "0.0.3-next.41",
23
+ "@twin.org/engine-server-types": "0.0.3-next.41",
24
24
  "@twin.org/modules": "next",
25
25
  "@twin.org/nameof": "next"
26
26
  },
@@ -49,7 +49,7 @@
49
49
  "engine"
50
50
  ],
51
51
  "bugs": {
52
- "url": "git+https://github.com/twinfoundation/engine/issues"
52
+ "url": "git+https://github.com/iotaledger/engine/issues"
53
53
  },
54
54
  "homepage": "https://twindev.org"
55
55
  }