@twin.org/engine-core 0.0.3-next.5 → 0.0.3-next.51
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 +1 -1
- package/dist/es/engineCore.js +138 -77
- package/dist/es/engineCore.js.map +1 -1
- package/dist/es/index.js +0 -1
- package/dist/es/index.js.map +1 -1
- package/dist/es/storage/fileStateStorage.js +1 -1
- package/dist/es/storage/fileStateStorage.js.map +1 -1
- package/dist/es/storage/memoryStateStorage.js +1 -1
- package/dist/es/storage/memoryStateStorage.js.map +1 -1
- package/dist/types/engineCore.d.ts +35 -5
- package/dist/types/index.d.ts +0 -1
- package/dist/types/storage/fileStateStorage.d.ts +1 -1
- package/dist/types/storage/memoryStateStorage.d.ts +1 -1
- package/docs/changelog.md +871 -111
- package/docs/examples.md +156 -1
- package/docs/reference/classes/EngineCore.md +148 -38
- package/docs/reference/classes/FileStateStorage.md +8 -8
- package/docs/reference/classes/MemoryStateStorage.md +8 -8
- package/docs/reference/index.md +0 -1
- package/docs/reference/interfaces/IEngineCoreOptions.md +10 -10
- package/locales/en.json +2 -4
- package/package.json +5 -5
- package/dist/es/utils/engineModuleHelper.js +0 -46
- package/dist/es/utils/engineModuleHelper.js.map +0 -1
- package/dist/types/utils/engineModuleHelper.d.ts +0 -17
- package/docs/reference/classes/EngineModuleHelper.md +0 -55
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoryStateStorage.js","sourceRoot":"","sources":["../../../src/storage/memoryStateStorage.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAItC;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAG9B;;OAEG;IACI,MAAM,CAAU,UAAU,wBAAwC;IAEzE;;;OAGG;IACc,aAAa,CAAU;IAExC;;;OAGG;IACK,YAAY,CAAK;IAEzB;;;;OAIG;IACH,YAAY,eAAwB,KAAK,EAAE,KAAS;QACnD,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI,CAAC,UAAuB;QACxC,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,GAAG,oBAAqC,UAAU,EAAE;YACtE,QAAQ,EAAE,IAAI,CAAC,YAAY;SAC3B,CAAC,CACF,CAAC;QACF,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CAAC,UAAuB,EAAE,KAAQ;QAClD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACzB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,oBAAqC,SAAS,CAAC,CAAC,CAAC;YAC1F,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC3B,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { I18n } from \"@twin.org/core\";\nimport type { IEngineCore, IEngineState, IEngineStateStorage } from \"@twin.org/engine-models\";\nimport { nameof, nameofCamelCase } from \"@twin.org/nameof\";\n\n/**\n * Store state in memory.\n */\nexport class MemoryStateStorage
|
|
1
|
+
{"version":3,"file":"memoryStateStorage.js","sourceRoot":"","sources":["../../../src/storage/memoryStateStorage.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAItC;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAG9B;;OAEG;IACI,MAAM,CAAU,UAAU,wBAAwC;IAEzE;;;OAGG;IACc,aAAa,CAAU;IAExC;;;OAGG;IACK,YAAY,CAAK;IAEzB;;;;OAIG;IACH,YAAY,eAAwB,KAAK,EAAE,KAAS;QACnD,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI,CAAC,UAAuB;QACxC,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,GAAG,oBAAqC,UAAU,EAAE;YACtE,QAAQ,EAAE,IAAI,CAAC,YAAY;SAC3B,CAAC,CACF,CAAC;QACF,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CAAC,UAAuB,EAAE,KAAQ;QAClD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACzB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,oBAAqC,SAAS,CAAC,CAAC,CAAC;YAC1F,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC3B,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { I18n } from \"@twin.org/core\";\nimport type { IEngineCore, IEngineState, IEngineStateStorage } from \"@twin.org/engine-models\";\nimport { nameof, nameofCamelCase } from \"@twin.org/nameof\";\n\n/**\n * Store state in memory.\n */\nexport class MemoryStateStorage<\n\tS extends IEngineState = IEngineState\n> implements IEngineStateStorage<S> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MemoryStateStorage>();\n\n\t/**\n\t * Readonly mode state file is not updated.\n\t * @internal\n\t */\n\tprivate readonly _readonlyMode: boolean;\n\n\t/**\n\t * The state object.\n\t * @internal\n\t */\n\tprivate _engineState?: S;\n\n\t/**\n\t * Create a new instance of MemoryStateStorage.\n\t * @param readonlyMode Whether the file is in read-only mode.\n\t * @param state The initial state.\n\t */\n\tconstructor(readonlyMode: boolean = false, state?: S) {\n\t\tthis._readonlyMode = readonlyMode;\n\t\tthis._engineState = state;\n\t}\n\n\t/**\n\t * Method for loading the state.\n\t * @param engineCore The engine core to load the state for.\n\t * @returns The state of the engine or undefined if it doesn't exist.\n\t */\n\tpublic async load(engineCore: IEngineCore): Promise<S | undefined> {\n\t\tengineCore.logInfo(\n\t\t\tI18n.formatMessage(`${nameofCamelCase<MemoryStateStorage>()}.loading`, {\n\t\t\t\tfilename: this._engineState\n\t\t\t})\n\t\t);\n\t\treturn this._engineState;\n\t}\n\n\t/**\n\t * Method for saving the state.\n\t * @param engineCore The engine core to save the state for.\n\t * @param state The state of the engine to save.\n\t * @returns A promise that resolves when the state has been stored in memory.\n\t */\n\tpublic async save(engineCore: IEngineCore, state: S): Promise<void> {\n\t\tif (!this._readonlyMode) {\n\t\t\tengineCore.logInfo(I18n.formatMessage(`${nameofCamelCase<MemoryStateStorage>()}.saving`));\n\t\t\tthis._engineState = state;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type IContextIds } from "@twin.org/context";
|
|
2
|
-
import { type IError } from "@twin.org/core";
|
|
2
|
+
import { type IComponent, type IError } from "@twin.org/core";
|
|
3
3
|
import type { IEngineCore, IEngineCoreClone, IEngineCoreConfig, IEngineCoreContext, IEngineCoreTypeConfig, IEngineState } from "@twin.org/engine-models";
|
|
4
4
|
import type { IEngineCoreOptions } from "./models/IEngineCoreOptions.js";
|
|
5
5
|
/**
|
|
@@ -75,12 +75,13 @@ export declare class EngineCore<C extends IEngineCoreConfig = IEngineCoreConfig,
|
|
|
75
75
|
getContextIds(): IContextIds | undefined;
|
|
76
76
|
/**
|
|
77
77
|
* Start the engine core.
|
|
78
|
-
* @
|
|
78
|
+
* @param skipComponentStart Should the component start be skipped.
|
|
79
|
+
* @returns A promise that resolves when the engine and all components have started.
|
|
79
80
|
*/
|
|
80
|
-
start(): Promise<
|
|
81
|
+
start(skipComponentStart?: boolean): Promise<void>;
|
|
81
82
|
/**
|
|
82
83
|
* Stop the engine core.
|
|
83
|
-
* @returns
|
|
84
|
+
* @returns A promise that resolves when all components have stopped and state has been saved.
|
|
84
85
|
*/
|
|
85
86
|
stop(): Promise<void>;
|
|
86
87
|
/**
|
|
@@ -101,11 +102,13 @@ export declare class EngineCore<C extends IEngineCoreConfig = IEngineCoreConfig,
|
|
|
101
102
|
/**
|
|
102
103
|
* Log info.
|
|
103
104
|
* @param message The message to log.
|
|
105
|
+
* @returns A promise that resolves when the message has been logged.
|
|
104
106
|
*/
|
|
105
107
|
logInfo(message: string): Promise<void>;
|
|
106
108
|
/**
|
|
107
109
|
* Log error.
|
|
108
110
|
* @param error The error to log.
|
|
111
|
+
* @returns A promise that resolves when the error has been logged.
|
|
109
112
|
*/
|
|
110
113
|
logError(error: IError): Promise<void>;
|
|
111
114
|
/**
|
|
@@ -118,6 +121,10 @@ export declare class EngineCore<C extends IEngineCoreConfig = IEngineCoreConfig,
|
|
|
118
121
|
* @returns The state of the engine.
|
|
119
122
|
*/
|
|
120
123
|
getState(): S;
|
|
124
|
+
/**
|
|
125
|
+
* Set the state to dirty so it gets saved.
|
|
126
|
+
*/
|
|
127
|
+
setStateDirty(): void;
|
|
121
128
|
/**
|
|
122
129
|
* Get all the registered instances.
|
|
123
130
|
* @returns The registered instances.
|
|
@@ -144,6 +151,28 @@ export declare class EngineCore<C extends IEngineCoreConfig = IEngineCoreConfig,
|
|
|
144
151
|
* @returns The instance type matching the criteria if one is registered.
|
|
145
152
|
*/
|
|
146
153
|
getRegisteredInstanceTypeOptional(componentConnectorType: string, features?: string[]): string | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Get the registered logger for the component/connector.
|
|
156
|
+
* @param componentName The name of the component to get the logger for.
|
|
157
|
+
* @returns The logger type name if one is registered and not silenced.
|
|
158
|
+
*/
|
|
159
|
+
getRegisteredLoggerType(componentName: string): string | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Get the registered components.
|
|
162
|
+
* @returns The registered components.
|
|
163
|
+
*/
|
|
164
|
+
getRegisteredComponents(): Promise<{
|
|
165
|
+
instanceType: string;
|
|
166
|
+
component: IComponent;
|
|
167
|
+
initialised: boolean;
|
|
168
|
+
}[]>;
|
|
169
|
+
/**
|
|
170
|
+
* Add a registered component to the engine.
|
|
171
|
+
* @param instanceType The instance type to register the component under.
|
|
172
|
+
* @param component The component to register.
|
|
173
|
+
* @returns A promise that resolves when the component has been registered.
|
|
174
|
+
*/
|
|
175
|
+
addRegisteredComponent(instanceType: string, component: IComponent): Promise<void>;
|
|
147
176
|
/**
|
|
148
177
|
* Get the data required to create a clone of the engine.
|
|
149
178
|
* @returns The clone data.
|
|
@@ -152,7 +181,8 @@ export declare class EngineCore<C extends IEngineCoreConfig = IEngineCoreConfig,
|
|
|
152
181
|
/**
|
|
153
182
|
* Populate the engine from the clone data.
|
|
154
183
|
* @param cloneData The clone data to populate from.
|
|
184
|
+
* @param contextIds The context IDs to use for the clone.
|
|
155
185
|
* @param silent Should the clone be silent.
|
|
156
186
|
*/
|
|
157
|
-
populateClone(cloneData: IEngineCoreClone<C, S>, silent?: boolean): void;
|
|
187
|
+
populateClone(cloneData: IEngineCoreClone<C, S>, contextIds?: IContextIds, silent?: boolean): void;
|
|
158
188
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare class FileStateStorage<S extends IEngineState = IEngineState> imp
|
|
|
23
23
|
* Method for saving the state.
|
|
24
24
|
* @param engineCore The engine core to save the state for.
|
|
25
25
|
* @param state The state of the engine to save.
|
|
26
|
-
* @returns
|
|
26
|
+
* @returns A promise that resolves when the state has been written to disk.
|
|
27
27
|
*/
|
|
28
28
|
save(engineCore: IEngineCore, state: S): Promise<void>;
|
|
29
29
|
}
|
|
@@ -23,7 +23,7 @@ export declare class MemoryStateStorage<S extends IEngineState = IEngineState> i
|
|
|
23
23
|
* Method for saving the state.
|
|
24
24
|
* @param engineCore The engine core to save the state for.
|
|
25
25
|
* @param state The state of the engine to save.
|
|
26
|
-
* @returns
|
|
26
|
+
* @returns A promise that resolves when the state has been stored in memory.
|
|
27
27
|
*/
|
|
28
28
|
save(engineCore: IEngineCore, state: S): Promise<void>;
|
|
29
29
|
}
|