opticore-webapp 1.0.70 → 1.0.71

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
@@ -17,6 +17,7 @@ interface WebServerConstructorInterface {
17
17
  declare class WebServerCore {
18
18
  private serverUtility;
19
19
  private expressApp;
20
+ private container;
20
21
  private readonly localLanguage;
21
22
  private readonly loggerConfig;
22
23
  private readonly routerExpressApp;
@@ -25,9 +26,27 @@ declare class WebServerCore {
25
26
  private serverListenEvent;
26
27
  private dependenciesRegistered;
27
28
  constructor(paramsConstructor: WebServerConstructorInterface);
29
+ /**
30
+ *
31
+ * @param dependencies
32
+ */
28
33
  registerDependencies(dependencies: TDependency[]): void;
34
+ /**
35
+ *
36
+ * @param routers
37
+ * @param databaseCallback
38
+ * @param dependenciesProvider
39
+ */
29
40
  onStartServer(routers: TFeatureRoutes[], databaseCallback: (env: any) => void, dependenciesProvider?: TDependency[]): Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
41
+ /**
42
+ *
43
+ * @param serverWeb
44
+ */
30
45
  onListeningOnServerEvent(serverWeb: Server): void;
46
+ /**
47
+ *
48
+ * @param serverWeb
49
+ */
31
50
  onRequestOnServerEvent(serverWeb: Server): void;
32
51
  /**
33
52
  *
@@ -54,6 +73,164 @@ declare class WebServerCore {
54
73
 
55
74
  declare const envPath: string;
56
75
 
76
+ interface HotReloadConfig {
77
+ /**
78
+ * Entry point file to run (e.g. 'dist/index.js' or 'src/index.ts')
79
+ */
80
+ entry: string;
81
+ /**
82
+ * Runtime to use for spawning the child process.
83
+ * - 'node' : compiled JS only, supports IPC hot reload for .env
84
+ * - 'tsx' : runs TypeScript directly via tsx
85
+ * - 'ts-node' : runs TypeScript directly via ts-node
86
+ * @default 'node'
87
+ */
88
+ runtime?: 'node' | 'tsx' | 'ts-node';
89
+ /**
90
+ * Extra arguments passed to the runtime before the entry file.
91
+ * Example: ['--experimental-specifier-resolution=node']
92
+ */
93
+ runtimeArgs?: string[];
94
+ /**
95
+ * Root directory to watch for file changes.
96
+ * @default process.cwd()
97
+ */
98
+ rootDir?: string;
99
+ /**
100
+ * Additional directories or glob patterns to watch.
101
+ * Merged with the default watched extensions (.ts, .js, .env, .json).
102
+ * Example: ['config', 'locales']
103
+ */
104
+ watchDirs?: string[];
105
+ /**
106
+ * File extensions to watch.
107
+ * @default ['.ts', '.js', '.mjs', '.cjs', '.json', '.env']
108
+ */
109
+ watchExtensions?: string[];
110
+ /**
111
+ * Patterns / file names to ignore in addition to the built-in ignores.
112
+ * Built-in ignores: node_modules, dist, .git, package.json, package-lock.json
113
+ * Example: ['coverage', 'tmp', 'myIgnored.json']
114
+ */
115
+ ignore?: string[];
116
+ /**
117
+ * Path to the .env file that should be hot-reloaded without restarting.
118
+ * @default '.env'
119
+ */
120
+ envFile?: string;
121
+ /**
122
+ * File extensions that support in-process hot reload (no server restart).
123
+ * All other watched extensions trigger a full server restart.
124
+ * @default ['.env', '.json']
125
+ */
126
+ hotReloadExtensions?: string[];
127
+ /**
128
+ * Milliseconds to wait after the last change before acting (debounce).
129
+ * Prevents rapid successive restarts when many files change at once.
130
+ * @default 300
131
+ */
132
+ debounceMs?: number;
133
+ /**
134
+ * Automatically restart the child process if it exits unexpectedly.
135
+ * @default true
136
+ */
137
+ restartOnCrash?: boolean;
138
+ /**
139
+ * Maximum number of automatic restarts on crash before giving up.
140
+ * @default 5
141
+ */
142
+ maxCrashRestarts?: number;
143
+ }
144
+
145
+ declare class HotReloadWatcher {
146
+ private readonly cfg;
147
+ private child;
148
+ private watchers;
149
+ 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;
159
+ private setupWatchers;
160
+ private watchDirectoryRecursive;
161
+ private onFileChange;
162
+ private doHotReload;
163
+ private scheduleRestart;
164
+ private sendIpc;
165
+ private shouldIgnoreDir;
166
+ private shouldIgnoreFile;
167
+ private isWatchedFile;
168
+ private isHotReloadable;
169
+ private isEnvFile;
170
+ private strip;
171
+ private ts;
172
+ /**
173
+ * Startup banner — mirrors the infoServer() box style from CoreService.
174
+ *
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
+ * ╚══════════════════════════════════════════╝
184
+ */
185
+ private printBanner;
186
+ /**
187
+ * HOT event — in-process reload, no server restart.
188
+ *
189
+ * ✔ [ HOT ] 14:23:45 | .env → env variables reloaded
190
+ */
191
+ private printHot;
192
+ /**
193
+ * RELOAD event — server restart triggered.
194
+ *
195
+ * ⚡ [ RELOAD ] 14:24:03 | src/routes/user.ts → restarting server...
196
+ */
197
+ 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
+ private setupProcessSignals;
232
+ }
233
+
57
234
  type KernelModuleType = [any[], () => void];
58
235
 
59
- export { type KernelModuleType, WebServerCore as WebServer, envPath };
236
+ export { type HotReloadConfig, HotReloadWatcher, type KernelModuleType, WebServerCore as WebServer, envPath };
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ interface WebServerConstructorInterface {
17
17
  declare class WebServerCore {
18
18
  private serverUtility;
19
19
  private expressApp;
20
+ private container;
20
21
  private readonly localLanguage;
21
22
  private readonly loggerConfig;
22
23
  private readonly routerExpressApp;
@@ -25,9 +26,27 @@ declare class WebServerCore {
25
26
  private serverListenEvent;
26
27
  private dependenciesRegistered;
27
28
  constructor(paramsConstructor: WebServerConstructorInterface);
29
+ /**
30
+ *
31
+ * @param dependencies
32
+ */
28
33
  registerDependencies(dependencies: TDependency[]): void;
34
+ /**
35
+ *
36
+ * @param routers
37
+ * @param databaseCallback
38
+ * @param dependenciesProvider
39
+ */
29
40
  onStartServer(routers: TFeatureRoutes[], databaseCallback: (env: any) => void, dependenciesProvider?: TDependency[]): Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
41
+ /**
42
+ *
43
+ * @param serverWeb
44
+ */
30
45
  onListeningOnServerEvent(serverWeb: Server): void;
46
+ /**
47
+ *
48
+ * @param serverWeb
49
+ */
31
50
  onRequestOnServerEvent(serverWeb: Server): void;
32
51
  /**
33
52
  *
@@ -54,6 +73,164 @@ declare class WebServerCore {
54
73
 
55
74
  declare const envPath: string;
56
75
 
76
+ interface HotReloadConfig {
77
+ /**
78
+ * Entry point file to run (e.g. 'dist/index.js' or 'src/index.ts')
79
+ */
80
+ entry: string;
81
+ /**
82
+ * Runtime to use for spawning the child process.
83
+ * - 'node' : compiled JS only, supports IPC hot reload for .env
84
+ * - 'tsx' : runs TypeScript directly via tsx
85
+ * - 'ts-node' : runs TypeScript directly via ts-node
86
+ * @default 'node'
87
+ */
88
+ runtime?: 'node' | 'tsx' | 'ts-node';
89
+ /**
90
+ * Extra arguments passed to the runtime before the entry file.
91
+ * Example: ['--experimental-specifier-resolution=node']
92
+ */
93
+ runtimeArgs?: string[];
94
+ /**
95
+ * Root directory to watch for file changes.
96
+ * @default process.cwd()
97
+ */
98
+ rootDir?: string;
99
+ /**
100
+ * Additional directories or glob patterns to watch.
101
+ * Merged with the default watched extensions (.ts, .js, .env, .json).
102
+ * Example: ['config', 'locales']
103
+ */
104
+ watchDirs?: string[];
105
+ /**
106
+ * File extensions to watch.
107
+ * @default ['.ts', '.js', '.mjs', '.cjs', '.json', '.env']
108
+ */
109
+ watchExtensions?: string[];
110
+ /**
111
+ * Patterns / file names to ignore in addition to the built-in ignores.
112
+ * Built-in ignores: node_modules, dist, .git, package.json, package-lock.json
113
+ * Example: ['coverage', 'tmp', 'myIgnored.json']
114
+ */
115
+ ignore?: string[];
116
+ /**
117
+ * Path to the .env file that should be hot-reloaded without restarting.
118
+ * @default '.env'
119
+ */
120
+ envFile?: string;
121
+ /**
122
+ * File extensions that support in-process hot reload (no server restart).
123
+ * All other watched extensions trigger a full server restart.
124
+ * @default ['.env', '.json']
125
+ */
126
+ hotReloadExtensions?: string[];
127
+ /**
128
+ * Milliseconds to wait after the last change before acting (debounce).
129
+ * Prevents rapid successive restarts when many files change at once.
130
+ * @default 300
131
+ */
132
+ debounceMs?: number;
133
+ /**
134
+ * Automatically restart the child process if it exits unexpectedly.
135
+ * @default true
136
+ */
137
+ restartOnCrash?: boolean;
138
+ /**
139
+ * Maximum number of automatic restarts on crash before giving up.
140
+ * @default 5
141
+ */
142
+ maxCrashRestarts?: number;
143
+ }
144
+
145
+ declare class HotReloadWatcher {
146
+ private readonly cfg;
147
+ private child;
148
+ private watchers;
149
+ 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;
159
+ private setupWatchers;
160
+ private watchDirectoryRecursive;
161
+ private onFileChange;
162
+ private doHotReload;
163
+ private scheduleRestart;
164
+ private sendIpc;
165
+ private shouldIgnoreDir;
166
+ private shouldIgnoreFile;
167
+ private isWatchedFile;
168
+ private isHotReloadable;
169
+ private isEnvFile;
170
+ private strip;
171
+ private ts;
172
+ /**
173
+ * Startup banner — mirrors the infoServer() box style from CoreService.
174
+ *
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
+ * ╚══════════════════════════════════════════╝
184
+ */
185
+ private printBanner;
186
+ /**
187
+ * HOT event — in-process reload, no server restart.
188
+ *
189
+ * ✔ [ HOT ] 14:23:45 | .env → env variables reloaded
190
+ */
191
+ private printHot;
192
+ /**
193
+ * RELOAD event — server restart triggered.
194
+ *
195
+ * ⚡ [ RELOAD ] 14:24:03 | src/routes/user.ts → restarting server...
196
+ */
197
+ 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
+ private setupProcessSignals;
232
+ }
233
+
57
234
  type KernelModuleType = [any[], () => void];
58
235
 
59
- export { type KernelModuleType, WebServerCore as WebServer, envPath };
236
+ export { type HotReloadConfig, HotReloadWatcher, type KernelModuleType, WebServerCore as WebServer, envPath };