libmodulor 0.18.1 → 0.20.0

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +1 -1
  3. package/dist/esm/apps/Helper/src/lib/project.js +8 -8
  4. package/dist/esm/convention.d.ts +2 -0
  5. package/dist/esm/convention.js +2 -0
  6. package/dist/esm/error/index.d.ts +3 -0
  7. package/dist/esm/error/index.js +3 -0
  8. package/dist/esm/error/internal/NotAvailableError.d.ts +3 -0
  9. package/dist/esm/error/internal/NotAvailableError.js +7 -0
  10. package/dist/esm/error/internal/NotCallableError.d.ts +4 -0
  11. package/dist/esm/error/internal/NotCallableError.js +7 -0
  12. package/dist/esm/error/internal/NotImplementedError.d.ts +3 -0
  13. package/dist/esm/error/internal/NotImplementedError.js +7 -0
  14. package/dist/esm/index.cloudflare-worker-hono.d.ts +5 -0
  15. package/dist/esm/index.cloudflare-worker-hono.js +5 -0
  16. package/dist/esm/index.d.ts +1 -0
  17. package/dist/esm/index.js +1 -0
  18. package/dist/esm/index.node-express.d.ts +2 -0
  19. package/dist/esm/index.node-express.js +2 -0
  20. package/dist/esm/index.node-hono.d.ts +1 -0
  21. package/dist/esm/index.node-hono.js +1 -0
  22. package/dist/esm/product/index.d.ts +1 -0
  23. package/dist/esm/product/index.js +1 -0
  24. package/dist/esm/product/workers/SyncProductUCsLoader.d.ts +15 -0
  25. package/dist/esm/product/workers/SyncProductUCsLoader.js +52 -0
  26. package/dist/esm/std/ShellCommandExecutor.d.ts +1 -0
  27. package/dist/esm/std/impl/FakeFSManager.js +2 -1
  28. package/dist/esm/std/impl/FakeJobManager.d.ts +1 -0
  29. package/dist/esm/std/impl/FakeJobManager.js +3 -0
  30. package/dist/esm/std/impl/NodeSpawnShellCommandExecutor.js +6 -0
  31. package/dist/esm/std/impl/SimpleMapI18nManager.d.ts +2 -0
  32. package/dist/esm/std/impl/SimpleMapI18nManager.js +14 -8
  33. package/dist/esm/std/impl/UCDataStoreExternalResourceManager.js +1 -1
  34. package/dist/esm/std/impl/WebCryptoManager.js +5 -4
  35. package/dist/esm/std/impl/WebFSManager.js +15 -14
  36. package/dist/esm/target/edge-worker-hono-server/SyncEdgeWorkerHonoServerManager.d.ts +32 -0
  37. package/dist/esm/target/edge-worker-hono-server/SyncEdgeWorkerHonoServerManager.js +87 -0
  38. package/dist/esm/target/lib/mcp-server/MCPServerBooter.d.ts +3 -2
  39. package/dist/esm/target/lib/mcp-server/MCPServerBooter.js +10 -6
  40. package/dist/esm/target/lib/react/UCContainer.js +1 -1
  41. package/dist/esm/target/lib/server/ServerBooter.d.ts +1 -0
  42. package/dist/esm/target/lib/server/ServerBooter.js +41 -44
  43. package/dist/esm/target/lib/server/ServerManager.d.ts +7 -0
  44. package/dist/esm/target/lib/server/SyncEdgeWorkerInitializer.d.ts +17 -0
  45. package/dist/esm/target/lib/server/SyncEdgeWorkerInitializer.js +76 -0
  46. package/dist/esm/target/lib/server/funcs.d.ts +3 -0
  47. package/dist/esm/target/lib/server/funcs.js +11 -0
  48. package/dist/esm/target/lib/server-express/HelmetMiddlewareBuilder.d.ts +12 -0
  49. package/dist/esm/target/lib/server-express/HelmetMiddlewareBuilder.js +39 -0
  50. package/dist/esm/target/lib/server-express/funcs.d.ts +15 -0
  51. package/dist/esm/target/lib/server-express/funcs.js +103 -0
  52. package/dist/esm/target/lib/server-hono/funcs.d.ts +10 -0
  53. package/dist/esm/target/lib/server-hono/funcs.js +72 -0
  54. package/dist/esm/target/lib/server-node/funcs.d.ts +5 -0
  55. package/dist/esm/target/lib/server-node/funcs.js +25 -0
  56. package/dist/esm/target/lib/server-node/types.d.ts +2 -0
  57. package/dist/esm/target/nextjs-server/NextJSServerManager.d.ts +2 -0
  58. package/dist/esm/target/nextjs-server/NextJSServerManager.js +6 -0
  59. package/dist/esm/target/node-core-cli/NodeCoreCLIManager.d.ts +3 -1
  60. package/dist/esm/target/node-core-cli/NodeCoreCLIManager.js +8 -5
  61. package/dist/esm/target/node-express-server/NodeExpressServerManager.d.ts +6 -5
  62. package/dist/esm/target/node-express-server/NodeExpressServerManager.js +16 -103
  63. package/dist/esm/target/node-hono-server/NodeHonoServerManager.d.ts +7 -5
  64. package/dist/esm/target/node-hono-server/NodeHonoServerManager.js +16 -67
  65. package/dist/esm/target/node-mcp-server/NodeLocalStdioMCPServerManager.d.ts +5 -1
  66. package/dist/esm/target/node-mcp-server/NodeLocalStdioMCPServerManager.js +42 -29
  67. package/dist/esm/testing/AppTester.d.ts +5 -2
  68. package/dist/esm/testing/AppTester.js +17 -4
  69. package/dist/esm/testing/UCDataStoreTester.js +3 -3
  70. package/dist/esm/testing/impl/VitestAppTestSuiteEmitter.js +132 -115
  71. package/dist/esm/testing/impl/VitestAppTestSuiteRunner.d.ts +2 -3
  72. package/dist/esm/testing/impl/VitestAppTestSuiteRunner.js +6 -8
  73. package/dist/esm/testing/workers/checkers/UCDefChecker.d.ts +2 -0
  74. package/dist/esm/testing/workers/checkers/UCDefChecker.js +4 -1
  75. package/dist/esm/uc/data-store.d.ts +3 -4
  76. package/dist/esm/uc/helpers/UCOutputBuilder.js +1 -0
  77. package/dist/esm/uc/impl/CloudflareD1UCDataStore.d.ts +34 -0
  78. package/dist/esm/uc/impl/CloudflareD1UCDataStore.js +201 -0
  79. package/dist/esm/uc/impl/InMemoryUCDataStore.d.ts +3 -2
  80. package/dist/esm/uc/impl/InMemoryUCDataStore.js +17 -14
  81. package/dist/esm/uc/impl/KnexUCDataStore.d.ts +3 -2
  82. package/dist/esm/uc/impl/KnexUCDataStore.js +9 -5
  83. package/dist/esm/uc/impl/SimpleUCManager.d.ts +1 -1
  84. package/dist/esm/uc/impl/SimpleUCManager.js +2 -2
  85. package/dist/esm/uc/manager.d.ts +1 -1
  86. package/dist/esm/uc/settings/consts.js +1 -1
  87. package/dist/esm/utils/concerns/Initializable.d.ts +1 -0
  88. package/dist/esm/utils/ioc/bindCloudflareWorker.d.ts +2 -0
  89. package/dist/esm/utils/ioc/bindCloudflareWorker.js +15 -0
  90. package/package.json +17 -14
  91. package/pnpm-workspace.yaml +1 -1
  92. package/tsconfig.json +0 -1
@@ -0,0 +1,25 @@
1
+ export function listen(server, entrypointsBuilder, logger, settingsManager) {
2
+ const host = settingsManager.get()('server_binding_host');
3
+ const port = settingsManager.get()('server_binding_port');
4
+ server.listen(port, host, () => {
5
+ logger.info(`Listening on ${entrypointsBuilder.exec().http}`);
6
+ });
7
+ }
8
+ export async function stop(server) {
9
+ if (!server?.listening) {
10
+ return;
11
+ }
12
+ // As stated in the docs of `close`, only awaiting `.close` is not enough to make sure all the connections are closed.
13
+ // Hence the wrapping in a promise, where the callback is called when the 'close' event is emitted.
14
+ return new Promise((resolve, reject) => {
15
+ if (!server) {
16
+ return resolve();
17
+ }
18
+ server.close((err) => {
19
+ if (err) {
20
+ return reject(err);
21
+ }
22
+ resolve();
23
+ });
24
+ });
25
+ }
@@ -1,3 +1,5 @@
1
1
  import type http from 'node:http';
2
2
  import type https from 'node:https';
3
+ import type { ServerManagerSettings } from '../server/ServerManager.js';
3
4
  export type Server = http.Server | https.Server;
5
+ export type ListenSettings = Pick<ServerManagerSettings, 'server_binding_host' | 'server_binding_port'>;
@@ -5,7 +5,9 @@ import type { ServerManager } from '../lib/server/ServerManager.js';
5
5
  export declare class NextJSServerManager implements ServerManager {
6
6
  overrideUCManager(_ucManager: UCManager): void;
7
7
  init(): Promise<void>;
8
+ initSync(): void;
8
9
  mount<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(_appManifest: AppManifest, _ucd: UCDef<I, OPI0, OPI1>, _contract: UCHTTPContract): Promise<void>;
10
+ mountSync<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(_appManifest: AppManifest, _ucd: UCDef<I, OPI0, OPI1>, _contract: UCHTTPContract): void;
9
11
  mountStaticDir(_dirPath: DirPath): Promise<void>;
10
12
  start(): Promise<void>;
11
13
  stop(): Promise<void>;
@@ -12,9 +12,15 @@ let NextJSServerManager = class NextJSServerManager {
12
12
  async init() {
13
13
  // Nothing to do
14
14
  }
15
+ initSync() {
16
+ // Nothing to do
17
+ }
15
18
  async mount(_appManifest, _ucd, _contract) {
16
19
  // Nothing to do
17
20
  }
21
+ mountSync(_appManifest, _ucd, _contract) {
22
+ // Nothing to do
23
+ }
18
24
  async mountStaticDir(_dirPath) {
19
25
  // Nothing to do
20
26
  }
@@ -1,12 +1,14 @@
1
1
  import { WordingManager } from '../../i18n/index.js';
2
2
  import { ProductUCsLoader } from '../../product/index.js';
3
+ import type { I18nManager } from '../../std/index.js';
3
4
  import type { CLIManager, Input, Output } from '../lib/cli/CLIManager.js';
4
5
  import { CommandExecutor } from '../lib/cli/CommandExecutor.js';
5
6
  export declare class NodeCoreCLIManager implements CLIManager {
6
7
  private commandExecutor;
8
+ private i18nManager;
7
9
  private productUCsLoader;
8
10
  private wordingManager;
9
- constructor(commandExecutor: CommandExecutor, productUCsLoader: ProductUCsLoader, wordingManager: WordingManager);
11
+ constructor(commandExecutor: CommandExecutor, i18nManager: I18nManager, productUCsLoader: ProductUCsLoader, wordingManager: WordingManager);
10
12
  handleCommand({ appsRootPath, srcImporter, }: Input): Promise<Output>;
11
13
  private parseArgsConfig;
12
14
  }
@@ -21,14 +21,17 @@ import { print } from '../lib/cli/renderer.js';
21
21
  import { showHelp } from './commands.js';
22
22
  let NodeCoreCLIManager = class NodeCoreCLIManager {
23
23
  commandExecutor;
24
+ i18nManager;
24
25
  productUCsLoader;
25
26
  wordingManager;
26
- constructor(commandExecutor, productUCsLoader, wordingManager) {
27
+ constructor(commandExecutor, i18nManager, productUCsLoader, wordingManager) {
27
28
  this.commandExecutor = commandExecutor;
29
+ this.i18nManager = i18nManager;
28
30
  this.productUCsLoader = productUCsLoader;
29
31
  this.wordingManager = wordingManager;
30
32
  }
31
33
  async handleCommand({ appsRootPath, srcImporter, }) {
34
+ await this.i18nManager.init();
32
35
  const command = process.argv[2] ?? '';
33
36
  const ucs = await this.productUCsLoader.exec({
34
37
  appsRootPath,
@@ -84,10 +87,10 @@ let NodeCoreCLIManager = class NodeCoreCLIManager {
84
87
  NodeCoreCLIManager = __decorate([
85
88
  injectable(),
86
89
  __param(0, inject(CommandExecutor)),
87
- __param(1, inject(ProductUCsLoader)),
88
- __param(2, inject(WordingManager)),
89
- __metadata("design:paramtypes", [CommandExecutor,
90
- ProductUCsLoader,
90
+ __param(1, inject('I18nManager')),
91
+ __param(2, inject(ProductUCsLoader)),
92
+ __param(3, inject(WordingManager)),
93
+ __metadata("design:paramtypes", [CommandExecutor, Object, ProductUCsLoader,
91
94
  WordingManager])
92
95
  ], NodeCoreCLIManager);
93
96
  export { NodeCoreCLIManager };
@@ -7,8 +7,9 @@ import { EntrypointsBuilder } from '../lib/server/EntrypointsBuilder.js';
7
7
  import type { ServerManager, ServerManagerSettings } from '../lib/server/ServerManager.js';
8
8
  import { ServerRequestHandler } from '../lib/server/ServerRequestHandler.js';
9
9
  import { ServerSSLCertLoader } from '../lib/server/ServerSSLCertLoader.js';
10
- import { HelmetMiddlewareBuilder } from './middlewares/HelmetMiddlewareBuilder.js';
11
- type S = Pick<LoggerSettings, 'logger_level'> & Pick<ServerManagerSettings, 'server_binding_host' | 'server_binding_port' | 'server_tmp_path'>;
10
+ import { HelmetMiddlewareBuilder } from '../lib/server-express/HelmetMiddlewareBuilder.js';
11
+ import type { ListenSettings } from '../lib/server-node/types.js';
12
+ type S = ListenSettings & Pick<LoggerSettings, 'logger_level'> & Pick<ServerManagerSettings, 'server_tmp_path'>;
12
13
  export declare class NodeExpressServerManager implements Configurable<S>, ServerManager {
13
14
  private entrypointsBuilder;
14
15
  protected environmentManager: EnvironmentManager;
@@ -25,14 +26,14 @@ export declare class NodeExpressServerManager implements Configurable<S>, Server
25
26
  getRuntime(): Express;
26
27
  overrideUCManager(ucManager: UCManager): void;
27
28
  init(): Promise<void>;
29
+ initSync(): void;
28
30
  mount<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, contract: UCHTTPContract): Promise<void>;
31
+ mountSync<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, contract: UCHTTPContract): void;
29
32
  mountStaticDir(dirPath: DirPath): Promise<void>;
30
33
  start(): Promise<void>;
31
34
  stop(): Promise<void>;
32
35
  warmUp(): Promise<void>;
33
36
  private createServer;
34
- private toFile;
35
- private toReq;
36
- private toRes;
37
+ private mountCommon;
37
38
  }
38
39
  export {};
@@ -12,15 +12,15 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  };
13
13
  import http from 'node:http';
14
14
  import https from 'node:https';
15
- import cookieParser from 'cookie-parser';
16
15
  import express, {} from 'express';
17
- import fileUpload from 'express-fileupload';
18
16
  import { inject, injectable } from 'inversify';
17
+ import { NotCallableError } from '../../error/index.js';
19
18
  import { EntrypointsBuilder } from '../lib/server/EntrypointsBuilder.js';
20
- import { ServerRequestHandler, } from '../lib/server/ServerRequestHandler.js';
19
+ import { ServerRequestHandler } from '../lib/server/ServerRequestHandler.js';
21
20
  import { ServerSSLCertLoader } from '../lib/server/ServerSSLCertLoader.js';
22
- import { stop } from '../lib/server-node/stop.js';
23
- import { HelmetMiddlewareBuilder } from './middlewares/HelmetMiddlewareBuilder.js';
21
+ import { buildHandler, init, mountHandler, } from '../lib/server-express/funcs.js';
22
+ import { HelmetMiddlewareBuilder } from '../lib/server-express/HelmetMiddlewareBuilder.js';
23
+ import { listen, stop } from '../lib/server-node/funcs.js';
24
24
  let NodeExpressServerManager = class NodeExpressServerManager {
25
25
  entrypointsBuilder;
26
26
  environmentManager;
@@ -60,53 +60,23 @@ let NodeExpressServerManager = class NodeExpressServerManager {
60
60
  this.ucManager = ucManager;
61
61
  }
62
62
  async init() {
63
- this.runtime = express();
64
- this.runtime.use(this.helmetMB.exec({}));
65
- // TODO : Add FileStorageManager (Local, S3, FSBucket)
66
- // Right now, the files are only stored locally. We need more flexibility. Maybe we can also install https://imgproxy.net.
67
- this.runtime.use(fileUpload({
68
- createParentPath: true,
69
- debug: this.s().logger_level === 'trace',
70
- tempFileDir: this.s().server_tmp_path,
71
- useTempFiles: true,
72
- }));
73
- this.runtime.use(express.json());
74
- this.runtime.use(express.urlencoded({ extended: true }));
75
- this.runtime.use(cookieParser());
63
+ this.runtime = init(this.helmetMB, this.s().logger_level, this.s().server_tmp_path);
76
64
  await this.createServer();
77
65
  }
66
+ initSync() {
67
+ throw new NotCallableError('initSync', 'init', 'async-only');
68
+ }
78
69
  async mount(appManifest, ucd, contract) {
79
- const { envelope, method, path, pathAliases } = contract;
80
- const httpMethod = method.toLowerCase();
81
- const handler = async (req, res) => {
82
- const { body, status } = await this.serverRequestHandler.exec({
83
- appManifest,
84
- envelope,
85
- req: this.toReq(req),
86
- res: this.toRes(res),
87
- ucd,
88
- ucManager: this.ucManager,
89
- });
90
- if (!body) {
91
- res.status(status).send();
92
- return;
93
- }
94
- res.status(status).send(body);
95
- };
96
- this.runtime[httpMethod](path, handler);
97
- for (const pathAlias of pathAliases) {
98
- this.runtime[httpMethod](pathAlias, handler);
99
- }
70
+ this.mountCommon(appManifest, ucd, contract);
71
+ }
72
+ mountSync(appManifest, ucd, contract) {
73
+ this.mountCommon(appManifest, ucd, contract);
100
74
  }
101
75
  async mountStaticDir(dirPath) {
102
76
  this.runtime.use(express.static(dirPath));
103
77
  }
104
78
  async start() {
105
- const host = this.s().server_binding_host;
106
- const port = this.s().server_binding_port;
107
- this.server.listen(port, host, () => {
108
- this.logger.info(`Listening on ${this.entrypointsBuilder.exec().http}`);
109
- });
79
+ listen(this.server, this.entrypointsBuilder, this.logger, this.settingsManager);
110
80
  }
111
81
  async stop() {
112
82
  await stop(this.server);
@@ -125,65 +95,8 @@ let NodeExpressServerManager = class NodeExpressServerManager {
125
95
  const credentials = await this.serverSSLCertLoader.exec(undefined);
126
96
  this.server = https.createServer(credentials, this.runtime);
127
97
  }
128
- toFile(f) {
129
- return {
130
- name: f.name,
131
- path: f.tempFilePath,
132
- type: f.mimetype,
133
- };
134
- }
135
- toReq(req) {
136
- return {
137
- bodyFromFormData: async () => {
138
- // Since express v5, if the request contains only a file, the `req.body` returns `undefined`
139
- const input = req.body ?? {};
140
- // files is present when using express-fileupload
141
- if ('files' in req && req.files) {
142
- for (const [field, value] of Object.entries(req.files)) {
143
- input[field] = Array.isArray(value)
144
- ? value.map(this.toFile)
145
- : this.toFile(value);
146
- }
147
- }
148
- for (const [k, v] of Object.entries(input)) {
149
- const isMultiple = k.endsWith('[]'); // e.g. 'tags[]': 'Electronic'
150
- const key = isMultiple ? k.replaceAll('[]', '') : k;
151
- if (isMultiple) {
152
- input[key] = Array.isArray(v) ? v : [v];
153
- }
154
- else {
155
- input[key] = v;
156
- }
157
- }
158
- return input;
159
- },
160
- bodyFromJSON: async () => req.body,
161
- bodyFromQueryParams: async () => req.query,
162
- bodyRaw: req.body,
163
- cookie: (name) => req.cookies[name],
164
- header: async (name) => {
165
- const h = req.headers[name.toLowerCase()];
166
- if (Array.isArray(h)) {
167
- this.logger.warn(`Multiple headers found for ${name}. Returning the first one.`);
168
- return h[0];
169
- }
170
- return h;
171
- },
172
- method: req.method,
173
- secure: req.secure,
174
- url: req.url,
175
- };
176
- }
177
- toRes(res) {
178
- return {
179
- clearCookie: async (name) => {
180
- res.clearCookie(name);
181
- },
182
- redirect: async (location) => res.redirect(location),
183
- setCookie: async ({ name, opts, val }) => {
184
- res.cookie(name, val, opts);
185
- },
186
- };
98
+ mountCommon(appManifest, ucd, contract) {
99
+ mountHandler(contract, this.runtime, buildHandler(appManifest, ucd, contract, this.serverRequestHandler, this.ucManager));
187
100
  }
188
101
  };
189
102
  NodeExpressServerManager = __decorate([
@@ -1,13 +1,14 @@
1
- import { Hono } from 'hono';
1
+ import type { Hono } from 'hono';
2
2
  import type { AppManifest } from '../../app/index.js';
3
3
  import type { DirPath } from '../../dt/index.js';
4
4
  import type { Configurable, EnvironmentManager, Logger, SettingsManager } from '../../std/index.js';
5
5
  import type { UCDef, UCHTTPContract, UCInput, UCManager, UCOPIBase } from '../../uc/index.js';
6
6
  import { EntrypointsBuilder } from '../lib/server/EntrypointsBuilder.js';
7
- import type { ServerManager, ServerManagerSettings } from '../lib/server/ServerManager.js';
7
+ import type { ServerManager } from '../lib/server/ServerManager.js';
8
8
  import { ServerRequestHandler } from '../lib/server/ServerRequestHandler.js';
9
9
  import { ServerSSLCertLoader } from '../lib/server/ServerSSLCertLoader.js';
10
- type S = Pick<ServerManagerSettings, 'server_binding_host' | 'server_binding_port'>;
10
+ import type { ListenSettings } from '../lib/server-node/types.js';
11
+ type S = ListenSettings;
11
12
  export declare class NodeHonoServerManager implements Configurable<S>, ServerManager {
12
13
  private entrypointsBuilder;
13
14
  protected environmentManager: EnvironmentManager;
@@ -23,13 +24,14 @@ export declare class NodeHonoServerManager implements Configurable<S>, ServerMan
23
24
  getRuntime(): Hono;
24
25
  overrideUCManager(ucManager: UCManager): void;
25
26
  init(): Promise<void>;
27
+ initSync(): void;
26
28
  mount<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, contract: UCHTTPContract): Promise<void>;
29
+ mountSync<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, contract: UCHTTPContract): void;
27
30
  mountStaticDir(dirPath: DirPath): Promise<void>;
28
31
  start(): Promise<void>;
29
32
  stop(): Promise<void>;
30
33
  warmUp(): Promise<void>;
31
34
  private createServer;
32
- private toReq;
33
- private toRes;
35
+ mountCommon<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, contract: UCHTTPContract): void;
34
36
  }
35
37
  export {};
@@ -12,18 +12,15 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  };
13
13
  import http from 'node:http';
14
14
  import https from 'node:https';
15
- import { createAdaptorServer, } from '@hono/node-server';
15
+ import { createAdaptorServer } from '@hono/node-server';
16
16
  import { serveStatic } from '@hono/node-server/serve-static';
17
- import { Hono } from 'hono';
18
- import { deleteCookie, getCookie, setCookie } from 'hono/cookie';
19
- import { logger } from 'hono/logger';
20
- import { secureHeaders } from 'hono/secure-headers';
21
17
  import { inject, injectable } from 'inversify';
22
- import { fromFormData } from '../../utils/index.js';
18
+ import { NotCallableError } from '../../error/index.js';
23
19
  import { EntrypointsBuilder } from '../lib/server/EntrypointsBuilder.js';
24
- import { ServerRequestHandler, } from '../lib/server/ServerRequestHandler.js';
20
+ import { ServerRequestHandler } from '../lib/server/ServerRequestHandler.js';
25
21
  import { ServerSSLCertLoader } from '../lib/server/ServerSSLCertLoader.js';
26
- import { stop } from '../lib/server-node/stop.js';
22
+ import { buildHandler, init, mountHandler } from '../lib/server-hono/funcs.js';
23
+ import { listen, stop } from '../lib/server-node/funcs.js';
27
24
  let NodeHonoServerManager = class NodeHonoServerManager {
28
25
  entrypointsBuilder;
29
26
  environmentManager;
@@ -59,50 +56,23 @@ let NodeHonoServerManager = class NodeHonoServerManager {
59
56
  this.ucManager = ucManager;
60
57
  }
61
58
  async init() {
62
- this.runtime = new Hono();
63
- this.runtime.use(secureHeaders());
64
- this.runtime.use(logger());
65
- this.runtime.notFound((c) => {
66
- return c.json({}, 404);
67
- });
59
+ this.runtime = init();
68
60
  await this.createServer();
69
61
  }
62
+ initSync() {
63
+ throw new NotCallableError('initSync', 'init', 'async-only');
64
+ }
70
65
  async mount(appManifest, ucd, contract) {
71
- const { envelope, method, path, pathAliases } = contract;
72
- const httpMethod = method.toLowerCase();
73
- if (httpMethod === 'connect' ||
74
- httpMethod === 'head' ||
75
- httpMethod === 'trace') {
76
- throw new Error(`Unsupported HTTP method : ${httpMethod}`);
77
- }
78
- const handler = async (c) => {
79
- const { body, status } = await this.serverRequestHandler.exec({
80
- appManifest,
81
- envelope,
82
- req: this.toReq(c),
83
- res: this.toRes(c),
84
- ucd,
85
- ucManager: this.ucManager,
86
- });
87
- if (!body) {
88
- return c.newResponse(null, status);
89
- }
90
- return c.json(body, status);
91
- };
92
- this.runtime[httpMethod](path, handler);
93
- for (const pathAlias of pathAliases) {
94
- this.runtime[httpMethod](pathAlias, handler);
95
- }
66
+ this.mountCommon(appManifest, ucd, contract);
67
+ }
68
+ mountSync(appManifest, ucd, contract) {
69
+ this.mountCommon(appManifest, ucd, contract);
96
70
  }
97
71
  async mountStaticDir(dirPath) {
98
72
  this.runtime.use(serveStatic({ root: dirPath }));
99
73
  }
100
74
  async start() {
101
- const host = this.s().server_binding_host;
102
- const port = this.s().server_binding_port;
103
- this.server.listen(port, host, () => {
104
- this.logger.info(`Listening on ${this.entrypointsBuilder.exec().http}`);
105
- });
75
+ listen(this.server, this.entrypointsBuilder, this.logger, this.settingsManager);
106
76
  }
107
77
  async stop() {
108
78
  await stop(this.server);
@@ -129,29 +99,8 @@ let NodeHonoServerManager = class NodeHonoServerManager {
129
99
  opts.serverOptions = await this.serverSSLCertLoader.exec(undefined);
130
100
  this.server = createAdaptorServer(opts);
131
101
  }
132
- toReq(c) {
133
- return {
134
- bodyFromFormData: async () => fromFormData(await c.req.formData()),
135
- bodyFromJSON: () => c.req.json(),
136
- bodyFromQueryParams: async () => c.req.queries(),
137
- bodyRaw: c.req.raw,
138
- cookie: async (name) => getCookie(c, name),
139
- header: async (name) => c.req.header(name),
140
- method: c.req.method,
141
- secure: c.req.url.startsWith('https://'),
142
- url: c.req.url,
143
- };
144
- }
145
- toRes(c) {
146
- return {
147
- clearCookie: async (name) => {
148
- deleteCookie(c, name);
149
- },
150
- redirect: async (location) => {
151
- c.redirect(location);
152
- },
153
- setCookie: async ({ name, opts, val }) => setCookie(c, name, val, opts),
154
- };
102
+ mountCommon(appManifest, ucd, contract) {
103
+ mountHandler(contract, this.runtime, buildHandler(appManifest, ucd, contract, this.serverRequestHandler, this.ucManager));
155
104
  }
156
105
  };
157
106
  NodeHonoServerManager = __decorate([
@@ -31,12 +31,16 @@ export declare class NodeLocalStdioMCPServerManager implements Configurable<S>,
31
31
  s(): S;
32
32
  overrideUCManager(ucManager: UCManager): void;
33
33
  init(): Promise<void>;
34
- mount<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, _contract: UCHTTPContract): Promise<void>;
34
+ initSync(): void;
35
+ mount<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, contract: UCHTTPContract): Promise<void>;
36
+ mountSync<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, contract: UCHTTPContract): void;
35
37
  mountStaticDir(_dirPath: DirPath): Promise<void>;
36
38
  start(): Promise<void>;
37
39
  stop(): Promise<void>;
38
40
  warmUp(): Promise<void>;
39
41
  private buildInputSchema;
40
42
  private execRequest;
43
+ private initCommon;
44
+ mountCommon<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, _contract: UCHTTPContract): void;
41
45
  }
42
46
  export {};
@@ -14,6 +14,7 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
14
14
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
15
15
  import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
16
16
  import { inject, injectable } from 'inversify';
17
+ import { NotAvailableError } from '../../error/index.js';
17
18
  import { WordingManager } from '../../i18n/index.js';
18
19
  import { UCBuilder, ucifIsMandatory, ucMountingPoint, } from '../../uc/index.js';
19
20
  import { propertyType, resError, resObj } from './funcs.js';
@@ -55,38 +56,19 @@ let NodeLocalStdioMCPServerManager = class NodeLocalStdioMCPServerManager {
55
56
  this.ucManager = ucManager;
56
57
  }
57
58
  async init() {
58
- this.runtime = new Server({
59
- name: this.productManifest.name,
60
- version: '0.1.0',
61
- }, {
62
- capabilities: {
63
- tools: {},
64
- },
65
- });
66
- if (this.s().logger_level !== 'error') {
67
- const message = 'Set the logging_level to "error" as MCP does not want the server to log to stdout (see https://modelcontextprotocol.io/docs/tools/debugging#implementing-logging)';
68
- // Depending on the `Logger` implementation, this.logger.error() might not write to stderr (e.g. can write to a file).
69
- // That's why we explicitly write to stdout by calling console.error().
70
- // biome-ignore lint/suspicious/noConsole: we want it
71
- console.error(new Error(message));
72
- }
59
+ this.initCommon();
73
60
  }
74
- async mount(appManifest, ucd, _contract) {
75
- const uc = this.ucBuilder.exec({
76
- appManifest,
77
- auth: null,
78
- def: ucd,
79
- });
80
- if (!this.appManifests.has(appManifest.name)) {
81
- this.appManifests.set(appManifest.name, appManifest);
82
- }
83
- const inputSchema = this.buildInputSchema(uc);
84
- const mountingPoint = uc.def.ext?.cmd?.mountAt ?? ucMountingPoint(uc);
85
- const tool = { inputSchema, name: mountingPoint };
86
- this.tools.set(mountingPoint, { appName: appManifest.name, tool, ucd });
61
+ initSync() {
62
+ this.initCommon();
63
+ }
64
+ async mount(appManifest, ucd, contract) {
65
+ this.mountCommon(appManifest, ucd, contract);
66
+ }
67
+ mountSync(appManifest, ucd, contract) {
68
+ this.mountCommon(appManifest, ucd, contract);
87
69
  }
88
70
  async mountStaticDir(_dirPath) {
89
- throw new Error('Method not implemented.');
71
+ throw new NotAvailableError('mountStaticDir');
90
72
  }
91
73
  async start() {
92
74
  this.transport = new StdioServerTransport();
@@ -156,6 +138,37 @@ let NodeLocalStdioMCPServerManager = class NodeLocalStdioMCPServerManager {
156
138
  return resError(err);
157
139
  }
158
140
  }
141
+ initCommon() {
142
+ this.runtime = new Server({
143
+ name: this.productManifest.name,
144
+ version: '0.1.0',
145
+ }, {
146
+ capabilities: {
147
+ tools: {},
148
+ },
149
+ });
150
+ if (this.s().logger_level !== 'error') {
151
+ const message = 'Set the logging_level to "error" as MCP does not want the server to log to stdout (see https://modelcontextprotocol.io/docs/tools/debugging#implementing-logging)';
152
+ // Depending on the `Logger` implementation, this.logger.error() might not write to stderr (e.g. can write to a file).
153
+ // That's why we explicitly write to stdout by calling console.error().
154
+ // biome-ignore lint/suspicious/noConsole: we want it
155
+ console.error(new Error(message));
156
+ }
157
+ }
158
+ mountCommon(appManifest, ucd, _contract) {
159
+ const uc = this.ucBuilder.exec({
160
+ appManifest,
161
+ auth: null,
162
+ def: ucd,
163
+ });
164
+ if (!this.appManifests.has(appManifest.name)) {
165
+ this.appManifests.set(appManifest.name, appManifest);
166
+ }
167
+ const inputSchema = this.buildInputSchema(uc);
168
+ const mountingPoint = uc.def.ext?.cmd?.mountAt ?? ucMountingPoint(uc);
169
+ const tool = { inputSchema, name: mountingPoint };
170
+ this.tools.set(mountingPoint, { appName: appManifest.name, tool, ucd });
171
+ }
159
172
  };
160
173
  NodeLocalStdioMCPServerManager = __decorate([
161
174
  injectable(),
@@ -1,7 +1,7 @@
1
1
  import type { FilePath } from '../dt/index.js';
2
2
  import type { ServerClientManagerSettings } from '../target/lib/client/ServerClientManager.js';
3
3
  import type { ServerManager } from '../target/lib/server/ServerManager.js';
4
- import { type UCAuth, UCBuilder, type UCDef, type UCInput, type UCOPIBase } from '../uc/index.js';
4
+ import { type UCAuth, UCBuilder, type UCDef, type UCInput, type UCName, type UCOPIBase } from '../uc/index.js';
5
5
  import type { SrcImporter } from '../utils/index.js';
6
6
  import type { AppTesterConfigurator } from './AppTesterConfigurator.js';
7
7
  import type { AppTesterCtx, AppTesterUCDRef } from './ctx.js';
@@ -50,6 +50,7 @@ export declare class AppTester {
50
50
  * This can happen in case of circular dependencies for example.
51
51
  */
52
52
  private safeSrcImporter;
53
+ private ucds;
53
54
  private testResults;
54
55
  private testSummary;
55
56
  private ucDefSourcesCheckerOutput;
@@ -59,13 +60,15 @@ export declare class AppTester {
59
60
  checkAppIndex(): Promise<void>;
60
61
  checkAppManifest(): Promise<void>;
61
62
  checkUCDSources(): Promise<void>;
62
- checkUC(ucdRef: AppTesterUCDRef): Promise<UCDef>;
63
+ checkUC(ucdRef: AppTesterUCDRef): Promise<void>;
63
64
  execFlow(flow: AppTesterFlow): Promise<AppTesterFlowExecOutput>;
64
65
  execMonkeyTest<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(ucd: UCDef<I, OPI0, OPI1>, input: I): Promise<UCExecutorExecOutput<I, OPI0, OPI1>>;
65
66
  execUC<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(input: Omit<UCExecutorInput<I, OPI0, OPI1>, 'appManifest'>, flow?: AppTesterFlow): Promise<AppTestSuiteTestResult<I, OPI0, OPI1>>;
66
67
  finalize(): Promise<void>;
67
68
  getCtx(): AppTesterCtx;
69
+ getUCD<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(ucName: UCName): UCDef<I, OPI0, OPI1>;
68
70
  init({ appPath, configurator, serverClientSettings, srcImporter, }: AppTesterInitArgs): Promise<void>;
71
+ initForUCExec(): Promise<void>;
69
72
  ucTestData(ucdRef: AppTesterUCDRef): Promise<AppTesterUCTestData[]>;
70
73
  private bindI18n;
71
74
  private bindServerClientSettings;