@zze/mock-server 0.2.4 → 0.2.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.
@@ -111,10 +111,11 @@ export declare class MockServer {
111
111
  * 2. Creates and starts the Express server
112
112
  * 3. Optionally starts the file watcher for hot reload
113
113
  *
114
- * @returns Promise that resolves when the server is ready
115
- * @throws Error if configuration loading fails or server fails to start
114
+ * @returns Promise that resolves when the server is ready (when no callback is provided)
115
+ * @throws Error if configuration loading fails or server fails to start (when no callback is provided)
116
116
  */
117
117
  start(): Promise<void>;
118
+ start(callback: (err?: Error) => void): void;
118
119
  /**
119
120
  * Stop the mock server
120
121
  *
@@ -122,9 +123,10 @@ export declare class MockServer {
122
123
  * 1. Stops the file watcher (if running)
123
124
  * 2. Stops the Express server
124
125
  *
125
- * @returns Promise that resolves when the server has stopped
126
+ * @returns Promise that resolves when the server has stopped (when no callback is provided)
126
127
  */
127
128
  stop(): Promise<void>;
129
+ stop(callback: (err?: Error) => void): void;
128
130
  /**
129
131
  * Restart the mock server
130
132
  *
@@ -1 +1 @@
1
- {"version":3,"file":"mock-server.d.ts","sourceRoot":"","sources":["../src/mock-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGvC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,SAAS,CAAC,EAAE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BAAgB,GAAG,MAAM,IAAI;IAUhD;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAU9C;;OAEG;YACW,YAAY;IAyC1B;;OAEG;IACH,OAAO,CAAC,SAAS;CASlB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAEvE"}
@@ -66,70 +66,64 @@ class MockServer {
66
66
  flowsDir: path_1.default.join(this.options.configPath, 'flows'),
67
67
  });
68
68
  }
69
- /**
70
- * Start the mock server
71
- *
72
- * This method:
73
- * 1. Loads configuration from the config directory
74
- * 2. Creates and starts the Express server
75
- * 3. Optionally starts the file watcher for hot reload
76
- *
77
- * @returns Promise that resolves when the server is ready
78
- * @throws Error if configuration loading fails or server fails to start
79
- */
80
- async start() {
81
- if (this.serverApp?.isRunning()) {
82
- throw new Error('Server is already running');
83
- }
84
- // Load configuration
85
- const result = await this.configLoader.load();
86
- if (!result.success || !result.config) {
87
- const errorMessages = result.errors.map((e) => `${e.filePath}: ${e.error}`).join('\n');
88
- throw new Error(`Failed to load configuration:\n${errorMessages}`);
89
- }
90
- // Store loaded config
91
- this.loadedEndpoints = result.config.endpoints;
92
- this.loadedFlows = result.config.flows;
93
- // Create server app
94
- const serverOptions = {
95
- port: this.options.port,
96
- apiPrefix: this.options.apiPrefix,
97
- hotReload: this.options.hotReload,
69
+ start(callback) {
70
+ const run = async () => {
71
+ if (this.serverApp?.isRunning()) {
72
+ throw new Error('Server is already running');
73
+ }
74
+ // Load configuration
75
+ const result = await this.configLoader.load();
76
+ if (!result.success || !result.config) {
77
+ const errorMessages = result.errors.map((e) => `${e.filePath}: ${e.error}`).join('\n');
78
+ throw new Error(`Failed to load configuration:\n${errorMessages}`);
79
+ }
80
+ // Store loaded config
81
+ this.loadedEndpoints = result.config.endpoints;
82
+ this.loadedFlows = result.config.flows;
83
+ // Create server app
84
+ const serverOptions = {
85
+ port: this.options.port,
86
+ apiPrefix: this.options.apiPrefix,
87
+ hotReload: this.options.hotReload,
88
+ };
89
+ this.serverApp = new mock_server_app_js_1.MockServerApp(serverOptions);
90
+ // Set config writer for endpoint/flow management via admin API
91
+ this.serverApp.setConfigWriter(this.configWriter, () => this.reload());
92
+ this.serverApp.registerConfig(this.loadedEndpoints, this.loadedFlows);
93
+ // Start the server
94
+ await this.serverApp.start();
95
+ // Start file watcher if hot reload is enabled
96
+ if (this.options.hotReload) {
97
+ await this.startWatcher();
98
+ }
98
99
  };
99
- this.serverApp = new mock_server_app_js_1.MockServerApp(serverOptions);
100
- // Set config writer for endpoint/flow management via admin API
101
- this.serverApp.setConfigWriter(this.configWriter, () => this.reload());
102
- this.serverApp.registerConfig(this.loadedEndpoints, this.loadedFlows);
103
- // Start the server
104
- await this.serverApp.start();
105
- // Start file watcher if hot reload is enabled
106
- if (this.options.hotReload) {
107
- await this.startWatcher();
100
+ if (callback) {
101
+ run().then(() => callback()).catch((err) => callback(err));
102
+ return;
108
103
  }
104
+ return run();
109
105
  }
110
- /**
111
- * Stop the mock server
112
- *
113
- * This method:
114
- * 1. Stops the file watcher (if running)
115
- * 2. Stops the Express server
116
- *
117
- * @returns Promise that resolves when the server has stopped
118
- */
119
- async stop() {
120
- // Stop watcher first
121
- if (this.watcher) {
122
- await this.watcher.stop();
123
- this.watcher = null;
124
- }
125
- // Stop server
126
- if (this.serverApp) {
127
- await this.serverApp.stop();
128
- this.serverApp = null;
106
+ stop(callback) {
107
+ const run = async () => {
108
+ // Stop watcher first
109
+ if (this.watcher) {
110
+ await this.watcher.stop();
111
+ this.watcher = null;
112
+ }
113
+ // Stop server
114
+ if (this.serverApp) {
115
+ await this.serverApp.stop();
116
+ this.serverApp = null;
117
+ }
118
+ // Clear loaded config
119
+ this.loadedEndpoints = [];
120
+ this.loadedFlows = [];
121
+ };
122
+ if (callback) {
123
+ run().then(() => callback()).catch((err) => callback(err));
124
+ return;
129
125
  }
130
- // Clear loaded config
131
- this.loadedEndpoints = [];
132
- this.loadedFlows = [];
126
+ return run();
133
127
  }
134
128
  /**
135
129
  * Restart the mock server
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zze/mock-server",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "A reusable Node.js mock server for microfrontend development",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",