opticore-webapp 1.0.71 → 1.0.72

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/dist/index.d.cts CHANGED
@@ -6,78 +6,12 @@ import { express } from 'opticore-express';
6
6
  import { LoggerCore } from 'opticore-logger';
7
7
  import { CorsOptions } from 'cors';
8
8
 
9
- interface WebServerConstructorInterface {
10
- app: express.Application;
11
- loggerConfig: LoggerCore;
12
- localLanguage: string;
13
- environmentPath: any;
14
- corsOriginOptions?: Partial<CorsOptions> | null;
15
- }
16
-
17
- declare class WebServerCore {
18
- private serverUtility;
19
- private expressApp;
20
- private container;
21
- private readonly localLanguage;
22
- private readonly loggerConfig;
23
- private readonly routerExpressApp;
24
- private readonly getEnvironmentValue;
25
- private readonly environmentPath;
26
- private serverListenEvent;
27
- private dependenciesRegistered;
28
- constructor(paramsConstructor: WebServerConstructorInterface);
29
- /**
30
- *
31
- * @param dependencies
32
- */
33
- registerDependencies(dependencies: TDependency[]): void;
34
- /**
35
- *
36
- * @param routers
37
- * @param databaseCallback
38
- * @param dependenciesProvider
39
- */
40
- onStartServer(routers: TFeatureRoutes[], databaseCallback: (env: any) => void, dependenciesProvider?: TDependency[]): Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
41
- /**
42
- *
43
- * @param serverWeb
44
- */
45
- onListeningOnServerEvent(serverWeb: Server): void;
46
- /**
47
- *
48
- * @param serverWeb
49
- */
50
- onRequestOnServerEvent(serverWeb: Server): void;
51
- /**
52
- *
53
- * @private
54
- */
55
- private loadTranslationFiles;
56
- /**
57
- *
58
- * @param allFeatureRoutes
59
- * @private
60
- */
61
- private registerRoutes;
62
- /**
63
- *
64
- * @private
65
- */
66
- private stackTraceErrorHandling;
67
- /**
68
- *
69
- * @private
70
- */
71
- private infoWebApp;
72
- }
73
-
74
- declare const envPath: string;
75
-
76
9
  interface HotReloadConfig {
77
10
  /**
78
- * Entry point file to run (e.g. 'dist/index.js' or 'src/index.ts')
11
+ * Entry point file to run.
12
+ * Reserved for future standalone mode — not used in integrated mode.
79
13
  */
80
- entry: string;
14
+ entry?: string;
81
15
  /**
82
16
  * Runtime to use for spawning the child process.
83
17
  * - 'node' : compiled JS only, supports IPC hot reload for .env
@@ -142,92 +76,155 @@ interface HotReloadConfig {
142
76
  maxCrashRestarts?: number;
143
77
  }
144
78
 
79
+ interface WebServerConstructorInterface {
80
+ app: express.Application;
81
+ loggerConfig: LoggerCore;
82
+ localLanguage: string;
83
+ environmentPath: any;
84
+ corsOriginOptions?: Partial<CorsOptions> | null;
85
+ /**
86
+ * Enable hot reload in development mode.
87
+ * - true → use all defaults
88
+ * - HotReloadConfig → custom configuration
89
+ * The watcher starts automatically when onStartServer() is called.
90
+ * On code changes the HTTP server is closed gracefully and the process
91
+ * exits (code 0) so your external runner restarts it:
92
+ * tsx --watch src/index.ts | nodemon | node --watch dist/index.js
93
+ */
94
+ hotReload?: boolean | HotReloadConfig;
95
+ }
96
+
97
+ declare class WebServerCore {
98
+ private serverUtility;
99
+ private expressApp;
100
+ private container;
101
+ private readonly localLanguage;
102
+ private readonly loggerConfig;
103
+ private readonly routerExpressApp;
104
+ private readonly getEnvironmentValue;
105
+ private readonly environmentPath;
106
+ private serverListenEvent;
107
+ private dependenciesRegistered;
108
+ private readonly hotReloadCfg;
109
+ constructor(paramsConstructor: WebServerConstructorInterface);
110
+ /**
111
+ *
112
+ * @param dependencies
113
+ */
114
+ registerDependencies(dependencies: TDependency[]): void;
115
+ /**
116
+ *
117
+ * @param routers
118
+ * @param databaseCallback
119
+ * @param dependenciesProvider
120
+ */
121
+ onStartServer(routers: TFeatureRoutes[], databaseCallback: (env: any) => void, dependenciesProvider?: TDependency[]): Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
122
+ /**
123
+ *
124
+ * @param serverWeb
125
+ */
126
+ onListeningOnServerEvent(serverWeb: Server): void;
127
+ /**
128
+ *
129
+ * @param serverWeb
130
+ */
131
+ onRequestOnServerEvent(serverWeb: Server): void;
132
+ /**
133
+ *
134
+ * @private
135
+ */
136
+ private loadTranslationFiles;
137
+ /**
138
+ * Resolve the final HotReloadConfig by merging constructor config with
139
+ * HMR environment variables.
140
+ *
141
+ * Priority (highest → lowest):
142
+ * 1. Constructor hotReload properties (explicit code-level config)
143
+ * 2. HMR_* env variables (runtime / per-environment config)
144
+ * 3. HotReloadWatcher internal defaults (built-in fallbacks)
145
+ *
146
+ * The watcher starts when:
147
+ * - constructor passed hotReload: true | HotReloadConfig
148
+ * - OR HMR_ENABLED=true in the .env file
149
+ */
150
+ private resolveHotReloadConfig;
151
+ /**
152
+ * Extract file extensions from glob patterns such as "src/** /*.ts".
153
+ * "src/** /*.ts"
154
+ * ".env" skipped, handled natively by the watcher
155
+ */
156
+ private hmrExtractExtensions;
157
+ /**
158
+ * Extract ignore names from glob patterns such as "node_modules/**".
159
+ * "node_modules/**" → "node_modules"
160
+ * "dist/**" → "dist"
161
+ */
162
+ private hmrExtractIgnore;
163
+ /**
164
+ *
165
+ * @param allFeatureRoutes
166
+ * @private
167
+ */
168
+ private registerRoutes;
169
+ /**
170
+ *
171
+ * @private
172
+ */
173
+ private stackTraceErrorHandling;
174
+ /**
175
+ *
176
+ * @private
177
+ */
178
+ private infoWebApp;
179
+ }
180
+
181
+ declare const envPath: string;
182
+
145
183
  declare class HotReloadWatcher {
146
184
  private readonly cfg;
147
- private child;
185
+ private server;
148
186
  private watchers;
149
187
  private debounceTimer;
150
- private isRestarting;
151
- private crashRestartCount;
152
- private started;
153
- private restartStart;
154
- constructor(config: HotReloadConfig);
155
- start(): Promise<void>;
156
- stop(): Promise<void>;
157
- private spawnChild;
158
- private killChild;
188
+ private restarting;
189
+ constructor(config?: HotReloadConfig);
190
+ attach(server: Server): Promise<void>;
159
191
  private setupWatchers;
160
- private watchDirectoryRecursive;
192
+ private watchRecursive;
161
193
  private onFileChange;
162
194
  private doHotReload;
163
195
  private scheduleRestart;
164
- private sendIpc;
196
+ /**
197
+ * Gracefully close the HTTP server so in-flight requests can finish,
198
+ * then exit with code 0 — the external runner restarts the process.
199
+ */
200
+ private closeAndExit;
165
201
  private shouldIgnoreDir;
166
202
  private shouldIgnoreFile;
167
- private isWatchedFile;
203
+ private isWatched;
168
204
  private isHotReloadable;
169
205
  private isEnvFile;
170
206
  private strip;
171
207
  private ts;
172
208
  /**
173
- * Startup banner — mirrors the infoServer() box style from CoreService.
209
+ * Startup banner — same bgGreen box style as CoreService.infoServer().
174
210
  *
175
- * ╔══════════════════════════════════════════╗
176
- * gradient title
177
- * ╔══ bgGreen box ════════════════════════╗
178
- * entry dist/index.js
179
- * runtime node (IPC enabled)
180
- * root ./src
181
- * watching .ts .js .json .env
182
- * debounce 300ms
183
- * ╚══════════════════════════════════════════╝
211
+ * OPTICORE HOT RELOAD ← gradient
212
+ * ████████████████████████████████ ← bgGreen border
213
+ * root ./src
214
+ * watching .ts .js .json .env
215
+ * debounce 300ms
216
+ * ████████████████████████████████ ← bgGreen border
217
+ * watching for changes...
184
218
  */
185
219
  private printBanner;
186
220
  /**
187
- * HOT event in-process reload, no server restart.
188
- *
189
- * ✔ [ HOT ] 14:23:45 | .env → env variables reloaded
221
+ * ✔ [ HOT ] 14:23:45 | .env → env variables reloaded
190
222
  */
191
223
  private printHot;
192
224
  /**
193
- * RELOAD event — server restart triggered.
194
- *
195
225
  * ⚡ [ RELOAD ] 14:24:03 | src/routes/user.ts → restarting server...
196
226
  */
197
227
  private printReloading;
198
- /**
199
- * READY event — server successfully restarted.
200
- * Uses the same full-width bgGreen border as infoServer().
201
- *
202
- * ════════════════════════════════════════════
203
- * READY server restarted in 245ms
204
- * ════════════════════════════════════════════
205
- */
206
- private printReady;
207
- /**
208
- * CRASH event — unexpected child process exit.
209
- *
210
- * ✘ [ CRASH ] 14:24:10 | server exited with code 1
211
- */
212
- private printCrash;
213
- /**
214
- * RETRY event — auto-restart after crash.
215
- *
216
- * ↺ [ RETRY ] 14:24:11 | attempt 1 / 5
217
- */
218
- private printCrashRetry;
219
- /**
220
- * LIMIT reached — give up restarting.
221
- */
222
- private printCrashLimit;
223
- /**
224
- * Error — miscellaneous internal error.
225
- */
226
- private printError;
227
- /**
228
- * Stopped — watcher shut down.
229
- */
230
- private printStopped;
231
228
  private setupProcessSignals;
232
229
  }
233
230
 
package/dist/index.d.ts CHANGED
@@ -6,78 +6,12 @@ import { express } from 'opticore-express';
6
6
  import { LoggerCore } from 'opticore-logger';
7
7
  import { CorsOptions } from 'cors';
8
8
 
9
- interface WebServerConstructorInterface {
10
- app: express.Application;
11
- loggerConfig: LoggerCore;
12
- localLanguage: string;
13
- environmentPath: any;
14
- corsOriginOptions?: Partial<CorsOptions> | null;
15
- }
16
-
17
- declare class WebServerCore {
18
- private serverUtility;
19
- private expressApp;
20
- private container;
21
- private readonly localLanguage;
22
- private readonly loggerConfig;
23
- private readonly routerExpressApp;
24
- private readonly getEnvironmentValue;
25
- private readonly environmentPath;
26
- private serverListenEvent;
27
- private dependenciesRegistered;
28
- constructor(paramsConstructor: WebServerConstructorInterface);
29
- /**
30
- *
31
- * @param dependencies
32
- */
33
- registerDependencies(dependencies: TDependency[]): void;
34
- /**
35
- *
36
- * @param routers
37
- * @param databaseCallback
38
- * @param dependenciesProvider
39
- */
40
- onStartServer(routers: TFeatureRoutes[], databaseCallback: (env: any) => void, dependenciesProvider?: TDependency[]): Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
41
- /**
42
- *
43
- * @param serverWeb
44
- */
45
- onListeningOnServerEvent(serverWeb: Server): void;
46
- /**
47
- *
48
- * @param serverWeb
49
- */
50
- onRequestOnServerEvent(serverWeb: Server): void;
51
- /**
52
- *
53
- * @private
54
- */
55
- private loadTranslationFiles;
56
- /**
57
- *
58
- * @param allFeatureRoutes
59
- * @private
60
- */
61
- private registerRoutes;
62
- /**
63
- *
64
- * @private
65
- */
66
- private stackTraceErrorHandling;
67
- /**
68
- *
69
- * @private
70
- */
71
- private infoWebApp;
72
- }
73
-
74
- declare const envPath: string;
75
-
76
9
  interface HotReloadConfig {
77
10
  /**
78
- * Entry point file to run (e.g. 'dist/index.js' or 'src/index.ts')
11
+ * Entry point file to run.
12
+ * Reserved for future standalone mode — not used in integrated mode.
79
13
  */
80
- entry: string;
14
+ entry?: string;
81
15
  /**
82
16
  * Runtime to use for spawning the child process.
83
17
  * - 'node' : compiled JS only, supports IPC hot reload for .env
@@ -142,92 +76,155 @@ interface HotReloadConfig {
142
76
  maxCrashRestarts?: number;
143
77
  }
144
78
 
79
+ interface WebServerConstructorInterface {
80
+ app: express.Application;
81
+ loggerConfig: LoggerCore;
82
+ localLanguage: string;
83
+ environmentPath: any;
84
+ corsOriginOptions?: Partial<CorsOptions> | null;
85
+ /**
86
+ * Enable hot reload in development mode.
87
+ * - true → use all defaults
88
+ * - HotReloadConfig → custom configuration
89
+ * The watcher starts automatically when onStartServer() is called.
90
+ * On code changes the HTTP server is closed gracefully and the process
91
+ * exits (code 0) so your external runner restarts it:
92
+ * tsx --watch src/index.ts | nodemon | node --watch dist/index.js
93
+ */
94
+ hotReload?: boolean | HotReloadConfig;
95
+ }
96
+
97
+ declare class WebServerCore {
98
+ private serverUtility;
99
+ private expressApp;
100
+ private container;
101
+ private readonly localLanguage;
102
+ private readonly loggerConfig;
103
+ private readonly routerExpressApp;
104
+ private readonly getEnvironmentValue;
105
+ private readonly environmentPath;
106
+ private serverListenEvent;
107
+ private dependenciesRegistered;
108
+ private readonly hotReloadCfg;
109
+ constructor(paramsConstructor: WebServerConstructorInterface);
110
+ /**
111
+ *
112
+ * @param dependencies
113
+ */
114
+ registerDependencies(dependencies: TDependency[]): void;
115
+ /**
116
+ *
117
+ * @param routers
118
+ * @param databaseCallback
119
+ * @param dependenciesProvider
120
+ */
121
+ onStartServer(routers: TFeatureRoutes[], databaseCallback: (env: any) => void, dependenciesProvider?: TDependency[]): Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
122
+ /**
123
+ *
124
+ * @param serverWeb
125
+ */
126
+ onListeningOnServerEvent(serverWeb: Server): void;
127
+ /**
128
+ *
129
+ * @param serverWeb
130
+ */
131
+ onRequestOnServerEvent(serverWeb: Server): void;
132
+ /**
133
+ *
134
+ * @private
135
+ */
136
+ private loadTranslationFiles;
137
+ /**
138
+ * Resolve the final HotReloadConfig by merging constructor config with
139
+ * HMR environment variables.
140
+ *
141
+ * Priority (highest → lowest):
142
+ * 1. Constructor hotReload properties (explicit code-level config)
143
+ * 2. HMR_* env variables (runtime / per-environment config)
144
+ * 3. HotReloadWatcher internal defaults (built-in fallbacks)
145
+ *
146
+ * The watcher starts when:
147
+ * - constructor passed hotReload: true | HotReloadConfig
148
+ * - OR HMR_ENABLED=true in the .env file
149
+ */
150
+ private resolveHotReloadConfig;
151
+ /**
152
+ * Extract file extensions from glob patterns such as "src/** /*.ts".
153
+ * "src/** /*.ts"
154
+ * ".env" skipped, handled natively by the watcher
155
+ */
156
+ private hmrExtractExtensions;
157
+ /**
158
+ * Extract ignore names from glob patterns such as "node_modules/**".
159
+ * "node_modules/**" → "node_modules"
160
+ * "dist/**" → "dist"
161
+ */
162
+ private hmrExtractIgnore;
163
+ /**
164
+ *
165
+ * @param allFeatureRoutes
166
+ * @private
167
+ */
168
+ private registerRoutes;
169
+ /**
170
+ *
171
+ * @private
172
+ */
173
+ private stackTraceErrorHandling;
174
+ /**
175
+ *
176
+ * @private
177
+ */
178
+ private infoWebApp;
179
+ }
180
+
181
+ declare const envPath: string;
182
+
145
183
  declare class HotReloadWatcher {
146
184
  private readonly cfg;
147
- private child;
185
+ private server;
148
186
  private watchers;
149
187
  private debounceTimer;
150
- private isRestarting;
151
- private crashRestartCount;
152
- private started;
153
- private restartStart;
154
- constructor(config: HotReloadConfig);
155
- start(): Promise<void>;
156
- stop(): Promise<void>;
157
- private spawnChild;
158
- private killChild;
188
+ private restarting;
189
+ constructor(config?: HotReloadConfig);
190
+ attach(server: Server): Promise<void>;
159
191
  private setupWatchers;
160
- private watchDirectoryRecursive;
192
+ private watchRecursive;
161
193
  private onFileChange;
162
194
  private doHotReload;
163
195
  private scheduleRestart;
164
- private sendIpc;
196
+ /**
197
+ * Gracefully close the HTTP server so in-flight requests can finish,
198
+ * then exit with code 0 — the external runner restarts the process.
199
+ */
200
+ private closeAndExit;
165
201
  private shouldIgnoreDir;
166
202
  private shouldIgnoreFile;
167
- private isWatchedFile;
203
+ private isWatched;
168
204
  private isHotReloadable;
169
205
  private isEnvFile;
170
206
  private strip;
171
207
  private ts;
172
208
  /**
173
- * Startup banner — mirrors the infoServer() box style from CoreService.
209
+ * Startup banner — same bgGreen box style as CoreService.infoServer().
174
210
  *
175
- * ╔══════════════════════════════════════════╗
176
- * gradient title
177
- * ╔══ bgGreen box ════════════════════════╗
178
- * entry dist/index.js
179
- * runtime node (IPC enabled)
180
- * root ./src
181
- * watching .ts .js .json .env
182
- * debounce 300ms
183
- * ╚══════════════════════════════════════════╝
211
+ * OPTICORE HOT RELOAD ← gradient
212
+ * ████████████████████████████████ ← bgGreen border
213
+ * root ./src
214
+ * watching .ts .js .json .env
215
+ * debounce 300ms
216
+ * ████████████████████████████████ ← bgGreen border
217
+ * watching for changes...
184
218
  */
185
219
  private printBanner;
186
220
  /**
187
- * HOT event in-process reload, no server restart.
188
- *
189
- * ✔ [ HOT ] 14:23:45 | .env → env variables reloaded
221
+ * ✔ [ HOT ] 14:23:45 | .env → env variables reloaded
190
222
  */
191
223
  private printHot;
192
224
  /**
193
- * RELOAD event — server restart triggered.
194
- *
195
225
  * ⚡ [ RELOAD ] 14:24:03 | src/routes/user.ts → restarting server...
196
226
  */
197
227
  private printReloading;
198
- /**
199
- * READY event — server successfully restarted.
200
- * Uses the same full-width bgGreen border as infoServer().
201
- *
202
- * ════════════════════════════════════════════
203
- * READY server restarted in 245ms
204
- * ════════════════════════════════════════════
205
- */
206
- private printReady;
207
- /**
208
- * CRASH event — unexpected child process exit.
209
- *
210
- * ✘ [ CRASH ] 14:24:10 | server exited with code 1
211
- */
212
- private printCrash;
213
- /**
214
- * RETRY event — auto-restart after crash.
215
- *
216
- * ↺ [ RETRY ] 14:24:11 | attempt 1 / 5
217
- */
218
- private printCrashRetry;
219
- /**
220
- * LIMIT reached — give up restarting.
221
- */
222
- private printCrashLimit;
223
- /**
224
- * Error — miscellaneous internal error.
225
- */
226
- private printError;
227
- /**
228
- * Stopped — watcher shut down.
229
- */
230
- private printStopped;
231
228
  private setupProcessSignals;
232
229
  }
233
230