@twin.org/engine-models 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/docs/examples.md CHANGED
@@ -1 +1,52 @@
1
- # @twin.org/engine-models - Examples
1
+ # Engine Models Examples
2
+
3
+ These examples show how to register factories and define strongly typed contracts for core and server integrations.
4
+
5
+ ## EngineCoreFactory and EngineServerFactory
6
+
7
+ ```typescript
8
+ import { EngineCoreFactory, EngineServerFactory } from '@twin.org/engine-models';
9
+ import { EngineCore } from '@twin.org/engine-core';
10
+ import { EngineServer } from '@twin.org/engine-server';
11
+
12
+ EngineCoreFactory.register(
13
+ 'default',
14
+ () => new EngineCore({ config: { debug: false, silent: true, types: {} }, skipBootstrap: true })
15
+ );
16
+ EngineServerFactory.register(
17
+ 'default',
18
+ () => new EngineServer({ engineCore: EngineCoreFactory.get('default') })
19
+ );
20
+
21
+ const core = EngineCoreFactory.get('default');
22
+ const server = EngineServerFactory.get('default');
23
+
24
+ console.log(core.isStarted()); // false
25
+ console.log(server.getRestRoutes().length); // 0
26
+ ```
27
+
28
+ ## IEngineCoreConfig and IEngineCoreTypeConfig
29
+
30
+ ```typescript
31
+ import type { IEngineCoreConfig, IEngineCoreTypeConfig } from '@twin.org/engine-models';
32
+
33
+ const loggingConnectorConfig: IEngineCoreTypeConfig<{ config: { prettyPrint: boolean } }> = {
34
+ type: 'console',
35
+ isDefault: true,
36
+ options: {
37
+ config: {
38
+ prettyPrint: true
39
+ }
40
+ }
41
+ };
42
+
43
+ const coreConfig: IEngineCoreConfig = {
44
+ debug: true,
45
+ silent: false,
46
+ types: {
47
+ loggingConnector: [loggingConnectorConfig]
48
+ }
49
+ };
50
+
51
+ console.log(coreConfig.types.loggingConnector?.[0].type); // "console"
52
+ ```
@@ -1,27 +1,47 @@
1
- # Interface: EngineTypeInitialiserReturn
1
+ # Interface: EngineTypeInitialiserReturn\<T, F\>
2
2
 
3
3
  Engine type initialiser return type.
4
4
 
5
+ ## Type Parameters
6
+
7
+ ### T
8
+
9
+ `T` *extends* [`IEngineCoreTypeBaseConfig`](IEngineCoreTypeBaseConfig.md) = [`IEngineCoreTypeBaseConfig`](IEngineCoreTypeBaseConfig.md)
10
+
11
+ ### F
12
+
13
+ `F` = `Factory`\<`unknown`\>
14
+
5
15
  ## Properties
6
16
 
7
- ### instanceType?
17
+ ### instanceTypeName? {#instancetypename}
8
18
 
9
- > `optional` **instanceType**: `string`
19
+ > `optional` **instanceTypeName?**: `string`
10
20
 
11
21
  The instance type created.
12
22
 
13
23
  ***
14
24
 
15
- ### factory?
25
+ ### factory? {#factory}
16
26
 
17
- > `optional` **factory**: `Factory`\<`unknown`\>
27
+ > `optional` **factory?**: `F`
18
28
 
19
29
  The factory to store the instance in.
20
30
 
21
31
  ***
22
32
 
23
- ### component?
33
+ ### createComponent? {#createcomponent}
34
+
35
+ > `optional` **createComponent?**: (`additionalConfig`) => `IComponent`
36
+
37
+ Create a new component.
38
+
39
+ #### Parameters
40
+
41
+ ##### additionalConfig
42
+
43
+ `T`
24
44
 
25
- > `optional` **component**: `IComponent`
45
+ #### Returns
26
46
 
27
- The component created.
47
+ `IComponent`
@@ -14,7 +14,7 @@ Interface describing the engine core methods.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### addTypeInitialiser()
17
+ ### addTypeInitialiser() {#addtypeinitialiser}
18
18
 
19
19
  > **addTypeInitialiser**(`type`, `module`, `method`): `void`
20
20
 
@@ -46,9 +46,9 @@ The name of the method to call.
46
46
 
47
47
  ***
48
48
 
49
- ### getTypeConfig()
49
+ ### getTypeConfig() {#gettypeconfig}
50
50
 
51
- > **getTypeConfig**(`type`): `undefined` \| [`IEngineCoreTypeConfig`](../type-aliases/IEngineCoreTypeConfig.md)[]
51
+ > **getTypeConfig**(`type`): [`IEngineCoreTypeConfig`](../type-aliases/IEngineCoreTypeConfig.md)[] \| `undefined`
52
52
 
53
53
  Get the type config for a specific type.
54
54
 
@@ -62,13 +62,13 @@ The type to get the config for.
62
62
 
63
63
  #### Returns
64
64
 
65
- `undefined` \| [`IEngineCoreTypeConfig`](../type-aliases/IEngineCoreTypeConfig.md)[]
65
+ [`IEngineCoreTypeConfig`](../type-aliases/IEngineCoreTypeConfig.md)[] \| `undefined`
66
66
 
67
67
  The type config or undefined if not found.
68
68
 
69
69
  ***
70
70
 
71
- ### addContextIdKey()
71
+ ### addContextIdKey() {#addcontextidkey}
72
72
 
73
73
  > **addContextIdKey**(`key`, `componentFeatures`): `void`
74
74
 
@@ -94,7 +94,7 @@ The component features for the context ID handler.
94
94
 
95
95
  ***
96
96
 
97
- ### getContextIdKeys()
97
+ ### getContextIdKeys() {#getcontextidkeys}
98
98
 
99
99
  > **getContextIdKeys**(): `string`[]
100
100
 
@@ -108,7 +108,7 @@ The context IDs keys.
108
108
 
109
109
  ***
110
110
 
111
- ### addContextId()
111
+ ### addContextId() {#addcontextid}
112
112
 
113
113
  > **addContextId**(`key`, `value`): `void`
114
114
 
@@ -134,35 +134,43 @@ The context ID value.
134
134
 
135
135
  ***
136
136
 
137
- ### getContextIds()
137
+ ### getContextIds() {#getcontextids}
138
138
 
139
- > **getContextIds**(): `undefined` \| `IContextIds`
139
+ > **getContextIds**(): `IContextIds` \| `undefined`
140
140
 
141
141
  Get the context IDs for the engine.
142
142
 
143
143
  #### Returns
144
144
 
145
- `undefined` \| `IContextIds`
145
+ `IContextIds` \| `undefined`
146
146
 
147
147
  The context IDs or undefined if none are set.
148
148
 
149
149
  ***
150
150
 
151
- ### start()
151
+ ### start() {#start}
152
152
 
153
- > **start**(): `Promise`\<`boolean`\>
153
+ > **start**(`skipComponentStart?`): `Promise`\<`void`\>
154
154
 
155
155
  Start the engine core.
156
156
 
157
+ #### Parameters
158
+
159
+ ##### skipComponentStart?
160
+
161
+ `boolean`
162
+
163
+ Should the component start be skipped.
164
+
157
165
  #### Returns
158
166
 
159
- `Promise`\<`boolean`\>
167
+ `Promise`\<`void`\>
160
168
 
161
- True if the start was successful.
169
+ Nothing.
162
170
 
163
171
  ***
164
172
 
165
- ### stop()
173
+ ### stop() {#stop}
166
174
 
167
175
  > **stop**(): `Promise`\<`void`\>
168
176
 
@@ -176,7 +184,7 @@ Nothing.
176
184
 
177
185
  ***
178
186
 
179
- ### isStarted()
187
+ ### isStarted() {#isstarted}
180
188
 
181
189
  > **isStarted**(): `boolean`
182
190
 
@@ -190,7 +198,7 @@ True if the engine is started.
190
198
 
191
199
  ***
192
200
 
193
- ### isPrimary()
201
+ ### isPrimary() {#isprimary}
194
202
 
195
203
  > **isPrimary**(): `boolean`
196
204
 
@@ -204,7 +212,7 @@ True if the engine is the primary instance.
204
212
 
205
213
  ***
206
214
 
207
- ### isClone()
215
+ ### isClone() {#isclone}
208
216
 
209
217
  > **isClone**(): `boolean`
210
218
 
@@ -218,7 +226,7 @@ True if the engine instance is a clone.
218
226
 
219
227
  ***
220
228
 
221
- ### logInfo()
229
+ ### logInfo() {#loginfo}
222
230
 
223
231
  > **logInfo**(`message`): `void`
224
232
 
@@ -238,7 +246,7 @@ The message to log.
238
246
 
239
247
  ***
240
248
 
241
- ### logError()
249
+ ### logError() {#logerror}
242
250
 
243
251
  > **logError**(`error`): `void`
244
252
 
@@ -258,7 +266,7 @@ The error to log.
258
266
 
259
267
  ***
260
268
 
261
- ### getConfig()
269
+ ### getConfig() {#getconfig}
262
270
 
263
271
  > **getConfig**(): `C`
264
272
 
@@ -272,7 +280,7 @@ The config for the engine.
272
280
 
273
281
  ***
274
282
 
275
- ### getState()
283
+ ### getState() {#getstate}
276
284
 
277
285
  > **getState**(): `S`
278
286
 
@@ -286,7 +294,19 @@ The state of the engine.
286
294
 
287
295
  ***
288
296
 
289
- ### getRegisteredInstances()
297
+ ### setStateDirty() {#setstatedirty}
298
+
299
+ > **setStateDirty**(): `void`
300
+
301
+ Set the state to dirty so it gets saved.
302
+
303
+ #### Returns
304
+
305
+ `void`
306
+
307
+ ***
308
+
309
+ ### getRegisteredInstances() {#getregisteredinstances}
290
310
 
291
311
  > **getRegisteredInstances**(): `object`
292
312
 
@@ -300,7 +320,7 @@ The registered instances.
300
320
 
301
321
  ***
302
322
 
303
- ### getRegisteredInstanceType()
323
+ ### getRegisteredInstanceType() {#getregisteredinstancetype}
304
324
 
305
325
  > **getRegisteredInstanceType**(`componentConnectorType`, `features?`): `string`
306
326
 
@@ -332,9 +352,9 @@ If a matching instance was not found.
332
352
 
333
353
  ***
334
354
 
335
- ### getRegisteredInstanceTypeOptional()
355
+ ### getRegisteredInstanceTypeOptional() {#getregisteredinstancetypeoptional}
336
356
 
337
- > **getRegisteredInstanceTypeOptional**(`componentConnectorType`, `features?`): `undefined` \| `string`
357
+ > **getRegisteredInstanceTypeOptional**(`componentConnectorType`, `features?`): `string` \| `undefined`
338
358
 
339
359
  Get the registered instance type for the component/connector.
340
360
 
@@ -354,13 +374,55 @@ The requested features of the component, if not specified the default entry will
354
374
 
355
375
  #### Returns
356
376
 
357
- `undefined` \| `string`
377
+ `string` \| `undefined`
358
378
 
359
379
  The instance type matching the criteria if one is registered.
360
380
 
361
381
  ***
362
382
 
363
- ### getCloneData()
383
+ ### getRegisteredComponents() {#getregisteredcomponents}
384
+
385
+ > **getRegisteredComponents**(): `Promise`\<`object`[]\>
386
+
387
+ Get the registered components.
388
+
389
+ #### Returns
390
+
391
+ `Promise`\<`object`[]\>
392
+
393
+ The registered components.
394
+
395
+ ***
396
+
397
+ ### addRegisteredComponent() {#addregisteredcomponent}
398
+
399
+ > **addRegisteredComponent**(`instanceType`, `component`): `Promise`\<`void`\>
400
+
401
+ Add a registered component to the engine.
402
+
403
+ #### Parameters
404
+
405
+ ##### instanceType
406
+
407
+ `string`
408
+
409
+ The instance type to register the component under.
410
+
411
+ ##### component
412
+
413
+ `IComponent`
414
+
415
+ The component to register.
416
+
417
+ #### Returns
418
+
419
+ `Promise`\<`void`\>
420
+
421
+ Nothing.
422
+
423
+ ***
424
+
425
+ ### getCloneData() {#getclonedata}
364
426
 
365
427
  > **getCloneData**(): [`IEngineCoreClone`](IEngineCoreClone.md)\<`C`, `S`\>
366
428
 
@@ -374,9 +436,9 @@ The clone data.
374
436
 
375
437
  ***
376
438
 
377
- ### populateClone()
439
+ ### populateClone() {#populateclone}
378
440
 
379
- > **populateClone**(`cloneData`, `silent?`): `void`
441
+ > **populateClone**(`cloneData`, `contextIds?`, `silent?`): `void`
380
442
 
381
443
  Populate the engine from the clone data.
382
444
 
@@ -388,6 +450,12 @@ Populate the engine from the clone data.
388
450
 
389
451
  The clone data to populate from.
390
452
 
453
+ ##### contextIds?
454
+
455
+ `IContextIds`
456
+
457
+ The context IDs to use for the clone.
458
+
391
459
  ##### silent?
392
460
 
393
461
  `boolean`
@@ -14,7 +14,7 @@ Interface describing the data required to clone an engine.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### config
17
+ ### config {#config}
18
18
 
19
19
  > **config**: `C`
20
20
 
@@ -22,7 +22,7 @@ The config for the engine.
22
22
 
23
23
  ***
24
24
 
25
- ### state
25
+ ### state {#state}
26
26
 
27
27
  > **state**: `S`
28
28
 
@@ -30,7 +30,7 @@ The state of the engine.
30
30
 
31
31
  ***
32
32
 
33
- ### typeInitialisers
33
+ ### typeInitialisers {#typeinitialisers}
34
34
 
35
35
  > **typeInitialisers**: `object`[]
36
36
 
@@ -50,7 +50,7 @@ The type initialisers for the engine.
50
50
 
51
51
  ***
52
52
 
53
- ### entitySchemas
53
+ ### entitySchemas {#entityschemas}
54
54
 
55
55
  > **entitySchemas**: `object`
56
56
 
@@ -62,7 +62,7 @@ The entity schemas for the engine.
62
62
 
63
63
  ***
64
64
 
65
- ### contextIdKeys
65
+ ### contextIdKeys {#contextidkeys}
66
66
 
67
67
  > **contextIdKeys**: `object`[]
68
68
 
@@ -4,9 +4,9 @@ Configuration for the engine core.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### debug?
7
+ ### debug? {#debug}
8
8
 
9
- > `optional` **debug**: `boolean`
9
+ > `optional` **debug?**: `boolean`
10
10
 
11
11
  Start the engine in debug mode.
12
12
 
@@ -18,9 +18,9 @@ false
18
18
 
19
19
  ***
20
20
 
21
- ### silent?
21
+ ### silent? {#silent}
22
22
 
23
- > `optional` **silent**: `boolean`
23
+ > `optional` **silent?**: `boolean`
24
24
 
25
25
  Disable output to the console.
26
26
 
@@ -32,7 +32,7 @@ false
32
32
 
33
33
  ***
34
34
 
35
- ### types
35
+ ### types {#types}
36
36
 
37
37
  > **types**: `object`
38
38
 
@@ -40,4 +40,4 @@ The types to initialise in the engine.
40
40
 
41
41
  #### Index Signature
42
42
 
43
- \[`type`: `string`\]: `undefined` \| [`IEngineCoreTypeConfig`](../type-aliases/IEngineCoreTypeConfig.md)[]
43
+ \[`type`: `string`\]: [`IEngineCoreTypeConfig`](../type-aliases/IEngineCoreTypeConfig.md)[] \| `undefined`
@@ -14,7 +14,7 @@ The context for the engine core.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### config
17
+ ### config {#config}
18
18
 
19
19
  > **config**: `C`
20
20
 
@@ -22,7 +22,7 @@ The engine core config.
22
22
 
23
23
  ***
24
24
 
25
- ### state
25
+ ### state {#state}
26
26
 
27
27
  > **state**: `S`
28
28
 
@@ -30,7 +30,7 @@ The engine core state.
30
30
 
31
31
  ***
32
32
 
33
- ### stateDirty
33
+ ### stateDirty {#statedirty}
34
34
 
35
35
  > **stateDirty**: `boolean`
36
36
 
@@ -38,7 +38,7 @@ The state dirty flag, which flags that the state needs saving.
38
38
 
39
39
  ***
40
40
 
41
- ### registeredInstances
41
+ ### registeredInstances {#registeredinstances}
42
42
 
43
43
  > **registeredInstances**: `object`
44
44
 
@@ -51,7 +51,7 @@ The default entry will be the first in the list.
51
51
 
52
52
  ***
53
53
 
54
- ### componentInstances
54
+ ### componentInstances {#componentinstances}
55
55
 
56
56
  > **componentInstances**: `object`[]
57
57
 
@@ -10,7 +10,7 @@ Configuration for the engine core type base.
10
10
 
11
11
  ## Properties
12
12
 
13
- ### type
13
+ ### type {#type}
14
14
 
15
15
  > **type**: `string`
16
16
 
@@ -18,8 +18,8 @@ The type of the instance.
18
18
 
19
19
  ***
20
20
 
21
- ### options?
21
+ ### options? {#options}
22
22
 
23
- > `optional` **options**: `T`
23
+ > `optional` **options?**: `T`
24
24
 
25
25
  The options for the instance.
@@ -4,7 +4,7 @@ Configuration for an engine module.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### id
7
+ ### id {#id}
8
8
 
9
9
  > **id**: `string`
10
10
 
@@ -12,7 +12,7 @@ The unique identifier for the module.
12
12
 
13
13
  ***
14
14
 
15
- ### moduleName
15
+ ### moduleName {#modulename}
16
16
 
17
17
  > **moduleName**: `string`
18
18
 
@@ -20,7 +20,7 @@ The module that implements the additional component.
20
20
 
21
21
  ***
22
22
 
23
- ### className
23
+ ### className {#classname}
24
24
 
25
25
  > **className**: `string`
26
26
 
@@ -28,9 +28,9 @@ The class name of the additional component.
28
28
 
29
29
  ***
30
30
 
31
- ### dependencies?
31
+ ### dependencies? {#dependencies}
32
32
 
33
- > `optional` **dependencies**: `object`[]
33
+ > `optional` **dependencies?**: `object`[]
34
34
 
35
35
  Additional dependencies required by the component.
36
36
 
@@ -44,16 +44,16 @@ Additional dependencies required by the component.
44
44
 
45
45
  #### features?
46
46
 
47
- > `optional` **features**: `string`[]
47
+ > `optional` **features?**: `string`[]
48
48
 
49
49
  #### isOptional?
50
50
 
51
- > `optional` **isOptional**: `boolean`
51
+ > `optional` **isOptional?**: `boolean`
52
52
 
53
53
  ***
54
54
 
55
- ### config?
55
+ ### config? {#config}
56
56
 
57
- > `optional` **config**: `unknown`
57
+ > `optional` **config?**: `unknown`
58
58
 
59
59
  Additional configuration for the component.
@@ -4,7 +4,7 @@ Interface describing the engine server methods.
4
4
 
5
5
  ## Methods
6
6
 
7
- ### addRestRouteGenerator()
7
+ ### addRestRouteGenerator() {#addrestroutegenerator}
8
8
 
9
9
  > **addRestRouteGenerator**(`type`, `module`, `method`): `void`
10
10
 
@@ -36,7 +36,7 @@ The method to call on the module.
36
36
 
37
37
  ***
38
38
 
39
- ### addSocketRouteGenerator()
39
+ ### addSocketRouteGenerator() {#addsocketroutegenerator}
40
40
 
41
41
  > **addSocketRouteGenerator**(`type`, `module`, `method`): `void`
42
42
 
@@ -68,21 +68,21 @@ The method to call on the module.
68
68
 
69
69
  ***
70
70
 
71
- ### start()
71
+ ### start() {#start}
72
72
 
73
- > **start**(): `Promise`\<`boolean`\>
73
+ > **start**(): `Promise`\<`void`\>
74
74
 
75
75
  Start the engine server.
76
76
 
77
77
  #### Returns
78
78
 
79
- `Promise`\<`boolean`\>
79
+ `Promise`\<`void`\>
80
80
 
81
- True if the start was successful.
81
+ Nothing.
82
82
 
83
83
  ***
84
84
 
85
- ### stop()
85
+ ### stop() {#stop}
86
86
 
87
87
  > **stop**(): `Promise`\<`void`\>
88
88
 
@@ -10,9 +10,9 @@ Definition of state storage for engine.
10
10
 
11
11
  ## Methods
12
12
 
13
- ### load()
13
+ ### load() {#load}
14
14
 
15
- > **load**(`engineCore`): `Promise`\<`undefined` \| `S`\>
15
+ > **load**(`engineCore`): `Promise`\<`S` \| `undefined`\>
16
16
 
17
17
  Method for loading the state.
18
18
 
@@ -26,13 +26,13 @@ The engine core to load the state for.
26
26
 
27
27
  #### Returns
28
28
 
29
- `Promise`\<`undefined` \| `S`\>
29
+ `Promise`\<`S` \| `undefined`\>
30
30
 
31
31
  The state of the engine or undefined if it doesn't exist.
32
32
 
33
33
  ***
34
34
 
35
- ### save()
35
+ ### save() {#save}
36
36
 
37
37
  > **save**(`engineCore`, `state`): `Promise`\<`void`\>
38
38
 
@@ -1,6 +1,6 @@
1
- # Type Alias: EngineTypeInitialiser()\<T\>
1
+ # Type Alias: EngineTypeInitialiser\<T, F\>
2
2
 
3
- > **EngineTypeInitialiser**\<`T`\> = (`engineCore`, `context`, `instanceConfig`) => `Promise`\<[`EngineTypeInitialiserReturn`](../interfaces/EngineTypeInitialiserReturn.md)\>
3
+ > **EngineTypeInitialiser**\<`T`, `F`\> = (`engineCore`, `context`, `instanceConfig`) => [`EngineTypeInitialiserReturn`](../interfaces/EngineTypeInitialiserReturn.md)\<`T`, `F`\>
4
4
 
5
5
  Method definition for the engine type initialiser.
6
6
 
@@ -10,6 +10,10 @@ Method definition for the engine type initialiser.
10
10
 
11
11
  `T` *extends* [`IEngineCoreTypeBaseConfig`](../interfaces/IEngineCoreTypeBaseConfig.md) = [`IEngineCoreTypeBaseConfig`](../interfaces/IEngineCoreTypeBaseConfig.md)
12
12
 
13
+ ### F
14
+
15
+ `F` = `Factory`\<`unknown`\>
16
+
13
17
  ## Parameters
14
18
 
15
19
  ### engineCore
@@ -26,4 +30,4 @@ Method definition for the engine type initialiser.
26
30
 
27
31
  ## Returns
28
32
 
29
- `Promise`\<[`EngineTypeInitialiserReturn`](../interfaces/EngineTypeInitialiserReturn.md)\>
33
+ [`EngineTypeInitialiserReturn`](../interfaces/EngineTypeInitialiserReturn.md)\<`T`, `F`\>