@twin.org/node-core 0.0.1-next.4 → 0.0.1-next.6

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.
@@ -495,10 +495,12 @@ async function bootstrapAuth(engineCore, context, envVars, features) {
495
495
  * @param envVars The environment variables.
496
496
  * @param openApiSpecFile Path to the OpenAPI spec file.
497
497
  * @param stateStorage The state storage.
498
- * @param customConfig Extends the engine configuration with any additional custom configuration.
498
+ * @param extendConfig Extends the engine configuration with any additional custom configuration.
499
+ * @param extendEngine Extends the engine with any additional options.
500
+ * @param extendEngineServer Extends the engine server with any additional options.
499
501
  * @returns The engine server.
500
502
  */
501
- async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateStorage, customConfig) {
503
+ async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateStorage, extendConfig, extendEngine, extendEngineServer) {
502
504
  envVars.storageFileRoot ??= "";
503
505
  if ((envVars.entityStorageConnectorType === engineTypes.EntityStorageConnectorType.File ||
504
506
  envVars.blobStorageConnectorType === engineTypes.BlobStorageConnectorType.File ||
@@ -511,8 +513,8 @@ async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateS
511
513
  // Build the engine configuration from the environment variables.
512
514
  const engineConfig = engine.buildEngineConfiguration(envVars);
513
515
  // Extend the engine configuration with a custom type.
514
- if (core.Is.function(customConfig)) {
515
- await customConfig(engineConfig);
516
+ if (core.Is.function(extendConfig)) {
517
+ await extendConfig(engineConfig);
516
518
  }
517
519
  // Build the server configuration from the environment variables.
518
520
  const serverConfig = engineServer.buildEngineServerConfiguration(envVars, engineConfig, serverInfo, openApiSpecFile);
@@ -522,11 +524,19 @@ async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateS
522
524
  stateStorage: stateStorage ?? new engineCore.FileStateStorage(envVars.stateFilename ?? ""),
523
525
  customBootstrap: async (core, engineContext) => bootstrap(core, engineContext, envVars)
524
526
  });
527
+ // Extend the engine.
528
+ if (core.Is.function(extendEngine)) {
529
+ await extendEngine(engine$1);
530
+ }
531
+ // Construct the server with the engine.
532
+ const server = new engineServer.EngineServer({ engineCore: engine$1 });
533
+ // Extend the engine server.
534
+ if (core.Is.function(extendEngineServer)) {
535
+ await extendEngineServer(server);
536
+ }
525
537
  // Need to register the engine with the factory so that background tasks
526
538
  // can clone it to spawn new instances.
527
539
  engineModels.EngineCoreFactory.register("engine", () => engine$1);
528
- // Construct the server with the engine.
529
- const server = new engineServer.EngineServer({ engineCore: engine$1 });
530
540
  // Start the server, which also starts the engine.
531
541
  const canContinue = await server.start();
532
542
  if (canContinue) {
@@ -549,7 +559,7 @@ async function run(options) {
549
559
  try {
550
560
  const serverInfo = {
551
561
  name: options?.serverName ?? "TWIN Node Server",
552
- version: options?.serverVersion ?? "0.0.1-next.4" // x-release-please-version
562
+ version: options?.serverVersion ?? "0.0.1-next.6" // x-release-please-version
553
563
  };
554
564
  console.log(`\u001B[4m🌩️ ${serverInfo.name} v${serverInfo.version}\u001B[24m\n`);
555
565
  const executionDirectory = options?.executionDirectory ?? getExecutionDirectory();
@@ -579,7 +589,7 @@ async function run(options) {
579
589
  throw new core.GeneralError("node", "noEnvVars", { prefix: envPrefix });
580
590
  }
581
591
  console.info();
582
- const startResult = await start(serverInfo, envPrefix, envVars, options?.openApiSpecFile, options.stateStorage, options.customConfig);
592
+ const startResult = await start(serverInfo, envPrefix, envVars, options?.openApiSpecFile, options.stateStorage, options.extendConfig, options.extendEngine, options.extendEngineServer);
583
593
  if (!core.Is.empty(startResult)) {
584
594
  for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"]) {
585
595
  process.on(signal, async () => {
@@ -474,10 +474,12 @@ async function bootstrapAuth(engineCore, context, envVars, features) {
474
474
  * @param envVars The environment variables.
475
475
  * @param openApiSpecFile Path to the OpenAPI spec file.
476
476
  * @param stateStorage The state storage.
477
- * @param customConfig Extends the engine configuration with any additional custom configuration.
477
+ * @param extendConfig Extends the engine configuration with any additional custom configuration.
478
+ * @param extendEngine Extends the engine with any additional options.
479
+ * @param extendEngineServer Extends the engine server with any additional options.
478
480
  * @returns The engine server.
479
481
  */
480
- async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateStorage, customConfig) {
482
+ async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateStorage, extendConfig, extendEngine, extendEngineServer) {
481
483
  envVars.storageFileRoot ??= "";
482
484
  if ((envVars.entityStorageConnectorType === EntityStorageConnectorType.File ||
483
485
  envVars.blobStorageConnectorType === BlobStorageConnectorType.File ||
@@ -490,8 +492,8 @@ async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateS
490
492
  // Build the engine configuration from the environment variables.
491
493
  const engineConfig = buildEngineConfiguration(envVars);
492
494
  // Extend the engine configuration with a custom type.
493
- if (Is.function(customConfig)) {
494
- await customConfig(engineConfig);
495
+ if (Is.function(extendConfig)) {
496
+ await extendConfig(engineConfig);
495
497
  }
496
498
  // Build the server configuration from the environment variables.
497
499
  const serverConfig = buildEngineServerConfiguration(envVars, engineConfig, serverInfo, openApiSpecFile);
@@ -501,11 +503,19 @@ async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateS
501
503
  stateStorage: stateStorage ?? new FileStateStorage(envVars.stateFilename ?? ""),
502
504
  customBootstrap: async (core, engineContext) => bootstrap(core, engineContext, envVars)
503
505
  });
506
+ // Extend the engine.
507
+ if (Is.function(extendEngine)) {
508
+ await extendEngine(engine);
509
+ }
510
+ // Construct the server with the engine.
511
+ const server = new EngineServer({ engineCore: engine });
512
+ // Extend the engine server.
513
+ if (Is.function(extendEngineServer)) {
514
+ await extendEngineServer(server);
515
+ }
504
516
  // Need to register the engine with the factory so that background tasks
505
517
  // can clone it to spawn new instances.
506
518
  EngineCoreFactory.register("engine", () => engine);
507
- // Construct the server with the engine.
508
- const server = new EngineServer({ engineCore: engine });
509
519
  // Start the server, which also starts the engine.
510
520
  const canContinue = await server.start();
511
521
  if (canContinue) {
@@ -528,7 +538,7 @@ async function run(options) {
528
538
  try {
529
539
  const serverInfo = {
530
540
  name: options?.serverName ?? "TWIN Node Server",
531
- version: options?.serverVersion ?? "0.0.1-next.4" // x-release-please-version
541
+ version: options?.serverVersion ?? "0.0.1-next.6" // x-release-please-version
532
542
  };
533
543
  console.log(`\u001B[4m🌩️ ${serverInfo.name} v${serverInfo.version}\u001B[24m\n`);
534
544
  const executionDirectory = options?.executionDirectory ?? getExecutionDirectory();
@@ -558,7 +568,7 @@ async function run(options) {
558
568
  throw new GeneralError("node", "noEnvVars", { prefix: envPrefix });
559
569
  }
560
570
  console.info();
561
- const startResult = await start(serverInfo, envPrefix, envVars, options?.openApiSpecFile, options.stateStorage, options.customConfig);
571
+ const startResult = await start(serverInfo, envPrefix, envVars, options?.openApiSpecFile, options.stateStorage, options.extendConfig, options.extendEngine, options.extendEngineServer);
562
572
  if (!Is.empty(startResult)) {
563
573
  for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"]) {
564
574
  process.on(signal, async () => {
@@ -1,4 +1,4 @@
1
- import type { IEngineStateStorage } from "@twin.org/engine-models";
1
+ import type { IEngineCore, IEngineServer, IEngineStateStorage } from "@twin.org/engine-models";
2
2
  import type { IEngineConfig } from "@twin.org/engine-types";
3
3
  /**
4
4
  * The options when running the node.
@@ -36,7 +36,15 @@ export interface IRunOptions {
36
36
  /**
37
37
  * Method to extend the engine configuration with any additional custom configuration.
38
38
  */
39
- customConfig?: (config: IEngineConfig) => Promise<void>;
39
+ extendConfig?: (config: IEngineConfig) => Promise<void>;
40
+ /**
41
+ * Method to extend the engine with any additional options.
42
+ */
43
+ extendEngine?: (engine: IEngineCore) => Promise<void>;
44
+ /**
45
+ * Method to extend the engine server with any additional options.
46
+ */
47
+ extendEngineServer?: (engineServer: IEngineServer) => Promise<void>;
40
48
  /**
41
49
  * The state storage to use for the engine.
42
50
  * If not provided, a default file-based state storage will be used.
@@ -1,6 +1,6 @@
1
1
  import type { IServerInfo } from "@twin.org/api-models";
2
2
  import { Engine } from "@twin.org/engine";
3
- import { type IEngineStateStorage } from "@twin.org/engine-models";
3
+ import { type IEngineCore, type IEngineServer, type IEngineStateStorage } from "@twin.org/engine-models";
4
4
  import { EngineServer } from "@twin.org/engine-server";
5
5
  import type { IEngineServerConfig } from "@twin.org/engine-server-types";
6
6
  import { type IEngineConfig } from "@twin.org/engine-types";
@@ -13,10 +13,12 @@ import type { INodeVariables } from "./models/INodeVariables";
13
13
  * @param envVars The environment variables.
14
14
  * @param openApiSpecFile Path to the OpenAPI spec file.
15
15
  * @param stateStorage The state storage.
16
- * @param customConfig Extends the engine configuration with any additional custom configuration.
16
+ * @param extendConfig Extends the engine configuration with any additional custom configuration.
17
+ * @param extendEngine Extends the engine with any additional options.
18
+ * @param extendEngineServer Extends the engine server with any additional options.
17
19
  * @returns The engine server.
18
20
  */
19
- export declare function start(serverInfo: IServerInfo, envVarsPrefix: string, envVars: INodeVariables, openApiSpecFile?: string, stateStorage?: IEngineStateStorage, customConfig?: (config: IEngineConfig) => Promise<void>): Promise<{
21
+ export declare function start(serverInfo: IServerInfo, envVarsPrefix: string, envVars: INodeVariables, openApiSpecFile?: string, stateStorage?: IEngineStateStorage, extendConfig?: (config: IEngineConfig) => Promise<void>, extendEngine?: (engine: IEngineCore) => Promise<void>, extendEngineServer?: (engineServer: IEngineServer) => Promise<void>): Promise<{
20
22
  engine: Engine<IEngineServerConfig, INodeState>;
21
23
  server: EngineServer;
22
24
  } | undefined>;
package/docs/changelog.md CHANGED
@@ -1,17 +1,39 @@
1
1
  # @twin.org/node-core - Changelog
2
2
 
3
- ## [0.0.1-next.4](https://github.com/twinfoundation/node/compare/node-core-v0.0.1-next.3...node-core-v0.0.1-next.4) (2025-05-27)
3
+ ## [0.0.1-next.6](https://github.com/twinfoundation/node/compare/node-core-v0.0.1-next.5...node-core-v0.0.1-next.6) (2025-06-12)
4
4
 
5
5
 
6
6
  ### Features
7
7
 
8
+ * add extend engine and server methods ([ec09c7e](https://github.com/twinfoundation/node/commit/ec09c7eb882d9f5797f2fd372e96cad1a3716f59))
9
+ * add extend engine and server methods ([0136a6f](https://github.com/twinfoundation/node/commit/0136a6f3f4e1a82b1427ee9618b8a17c79bc7fda))
10
+ * additional run options ([c35e5bb](https://github.com/twinfoundation/node/commit/c35e5bbb8a80fe6a36628d41f64585b3723d9ad7))
8
11
  * improve error reporting ([fcd39a1](https://github.com/twinfoundation/node/commit/fcd39a18da2a6ce33965a99ca5f2f36f4aba712f))
12
+ * initial commit ([522f1e5](https://github.com/twinfoundation/node/commit/522f1e515348f9b1dd1eeb3170b1249e2b0b5371))
13
+ * node app use JavaScript ([14fe08c](https://github.com/twinfoundation/node/commit/14fe08cb760dd885a5dac9056a4d5dbc3d61df64))
14
+ * update dependencies ([9d25f16](https://github.com/twinfoundation/node/commit/9d25f16f1d554cd38f3bec28fdf7f8fff892ceaf))
9
15
 
10
16
 
11
17
  ### Bug Fixes
12
18
 
13
19
  * broken docs ([61479fd](https://github.com/twinfoundation/node/commit/61479fd618f766d22c5aafec5277e1a89e22b453))
14
20
 
21
+ ## [0.0.1-next.5](https://github.com/twinfoundation/node/compare/node-core-v0.0.1-next.4...node-core-v0.0.1-next.5) (2025-06-12)
22
+
23
+ ### Features
24
+
25
+ - add extend engine and server methods ([0136a6f](https://github.com/twinfoundation/node/commit/0136a6f3f4e1a82b1427ee9618b8a17c79bc7fda))
26
+
27
+ ## [0.0.1-next.4](https://github.com/twinfoundation/node/compare/node-core-v0.0.1-next.3...node-core-v0.0.1-next.4) (2025-05-27)
28
+
29
+ ### Features
30
+
31
+ - improve error reporting ([fcd39a1](https://github.com/twinfoundation/node/commit/fcd39a18da2a6ce33965a99ca5f2f36f4aba712f))
32
+
33
+ ### Bug Fixes
34
+
35
+ - broken docs ([61479fd](https://github.com/twinfoundation/node/commit/61479fd618f766d22c5aafec5277e1a89e22b453))
36
+
15
37
  ## [0.0.1-next.3](https://github.com/twinfoundation/node/compare/node-core-v0.0.1-next.2...node-core-v0.0.1-next.3) (2025-05-27)
16
38
 
17
39
  ### Features
@@ -1,6 +1,6 @@
1
1
  # Function: start()
2
2
 
3
- > **start**(`serverInfo`, `envVarsPrefix`, `envVars`, `openApiSpecFile?`, `stateStorage?`, `customConfig?`): `Promise`\<`undefined` \| \{ `engine`: `Engine`\<`IEngineServerConfig`, [`INodeState`](../interfaces/INodeState.md)\>; `server`: `EngineServer`; \}\>
3
+ > **start**(`serverInfo`, `envVarsPrefix`, `envVars`, `openApiSpecFile?`, `stateStorage?`, `extendConfig?`, `extendEngine?`, `extendEngineServer?`): `Promise`\<`undefined` \| \{ `engine`: `Engine`\<`IEngineServerConfig`, [`INodeState`](../interfaces/INodeState.md)\>; `server`: `EngineServer`; \}\>
4
4
 
5
5
  Start the engine server.
6
6
 
@@ -36,12 +36,24 @@ Path to the OpenAPI spec file.
36
36
 
37
37
  The state storage.
38
38
 
39
- ### customConfig?
39
+ ### extendConfig?
40
40
 
41
41
  (`config`) => `Promise`\<`void`\>
42
42
 
43
43
  Extends the engine configuration with any additional custom configuration.
44
44
 
45
+ ### extendEngine?
46
+
47
+ (`engine`) => `Promise`\<`void`\>
48
+
49
+ Extends the engine with any additional options.
50
+
51
+ ### extendEngineServer?
52
+
53
+ (`engineServer`) => `Promise`\<`void`\>
54
+
55
+ Extends the engine server with any additional options.
56
+
45
57
  ## Returns
46
58
 
47
59
  `Promise`\<`undefined` \| \{ `engine`: `Engine`\<`IEngineServerConfig`, [`INodeState`](../interfaces/INodeState.md)\>; `server`: `EngineServer`; \}\>
@@ -66,9 +66,9 @@ The path to the OpenAPI spec file, defaults to docs/open-api/spec.json.
66
66
 
67
67
  ***
68
68
 
69
- ### customConfig()?
69
+ ### extendConfig()?
70
70
 
71
- > `optional` **customConfig**: (`config`) => `Promise`\<`void`\>
71
+ > `optional` **extendConfig**: (`config`) => `Promise`\<`void`\>
72
72
 
73
73
  Method to extend the engine configuration with any additional custom configuration.
74
74
 
@@ -84,6 +84,42 @@ Method to extend the engine configuration with any additional custom configurati
84
84
 
85
85
  ***
86
86
 
87
+ ### extendEngine()?
88
+
89
+ > `optional` **extendEngine**: (`engine`) => `Promise`\<`void`\>
90
+
91
+ Method to extend the engine with any additional options.
92
+
93
+ #### Parameters
94
+
95
+ ##### engine
96
+
97
+ `IEngineCore`
98
+
99
+ #### Returns
100
+
101
+ `Promise`\<`void`\>
102
+
103
+ ***
104
+
105
+ ### extendEngineServer()?
106
+
107
+ > `optional` **extendEngineServer**: (`engineServer`) => `Promise`\<`void`\>
108
+
109
+ Method to extend the engine server with any additional options.
110
+
111
+ #### Parameters
112
+
113
+ ##### engineServer
114
+
115
+ `IEngineServer`
116
+
117
+ #### Returns
118
+
119
+ `Promise`\<`void`\>
120
+
121
+ ***
122
+
87
123
  ### stateStorage?
88
124
 
89
125
  > `optional` **stateStorage**: `IEngineStateStorage`\<`IEngineState`\>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/node-core",
3
- "version": "0.0.1-next.4",
3
+ "version": "0.0.1-next.6",
4
4
  "description": "TWIN Node Core for serving APIs using the specified configuration",
5
5
  "repository": {
6
6
  "type": "git",