navi-hey 1.6.0 → 1.6.1

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/README.md CHANGED
@@ -207,4 +207,4 @@ docker run --rm \
207
207
 
208
208
  GitHub repository: [darthjee/navi](https://github.com/darthjee/navi)
209
209
 
210
- Integration guide for developers and AI agents: [How to Use Navi in Your Project](https://github.com/darthjee/navi/blob/main/docs/HOW_TO_USE_NAVI.md)
210
+ Integration guide for developers and AI agents: [How to Use Navi in Your Project](https://github.com/darthjee/navi/blob/main/docs/guides/HOW_TO_USE_NAVI.md)
@@ -1,4 +1,5 @@
1
1
  import { LogConfig } from './LogConfig.js';
2
+ import { NamespaceNotFound } from '../../exceptions/registry/NamespaceNotFound.js';
2
3
  import { NamespaceMap } from '../../registry/NamespaceMap.js';
3
4
  import { ResourceRegistry } from '../../registry/ResourceRegistry.js';
4
5
  import { ConfigLoader } from '../../services/ConfigLoader.js';
@@ -23,15 +24,27 @@ class Config {
23
24
  constructor({ namespaceMap, workersConfig, webConfig, logConfig, failureConfig }) {
24
25
  this.namespaceMap = NamespaceMap.build(namespaceMap);
25
26
 
26
- const defaultNamespace = namespaceMap[DEFAULT_NAMESPACE];
27
- this.resourceRegistry = defaultNamespace ? defaultNamespace.resourceRegistry : new ResourceRegistry({});
28
-
29
27
  this.workersConfig = workersConfig;
30
28
  this.webConfig = webConfig ?? null;
31
29
  this.logConfig = logConfig ?? new LogConfig();
32
30
  this.failureConfig = failureConfig ?? null;
33
31
  }
34
32
 
33
+ /**
34
+ * Returns the current default namespace's resource registry, resolved live
35
+ * from the `namespaceMap` singleton on every access. Falls back to an empty
36
+ * `ResourceRegistry` when there is no `default` namespace.
37
+ * @returns {ResourceRegistry} The default namespace's resource registry.
38
+ */
39
+ get resourceRegistry() {
40
+ try {
41
+ return this.namespaceMap.getItem(DEFAULT_NAMESPACE).resourceRegistry;
42
+ } catch (error) {
43
+ if (error instanceof NamespaceNotFound) return new ResourceRegistry({});
44
+ throw error;
45
+ }
46
+ }
47
+
35
48
  /**
36
49
  * Returns the resource identified by the given name, resolved as if the caller
37
50
  * originated from the `default` namespace.
@@ -8,6 +8,7 @@ import { ApiEngineStartHandler } from './handlers/api/ApiEngineStartHandler.js';
8
8
  import { ApiEngineStopHandler } from './handlers/api/ApiEngineStopHandler.js';
9
9
  import { EngineContinueHandler } from './handlers/engine/EngineContinueHandler.js';
10
10
  import { EnginePauseHandler } from './handlers/engine/EnginePauseHandler.js';
11
+ import { EngineReloadHandler } from './handlers/engine/EngineReloadHandler.js';
11
12
  import { EngineRestartHandler } from './handlers/engine/EngineRestartHandler.js';
12
13
  import { EngineShutdownHandler } from './handlers/engine/EngineShutdownHandler.js';
13
14
  import { EngineStartHandler } from './handlers/engine/EngineStartHandler.js';
@@ -77,6 +78,7 @@ class Router {
77
78
  '/engine/continue': new HandlerConfig(EngineContinueHandler),
78
79
  '/engine/start': new HandlerConfig(EngineStartHandler),
79
80
  '/engine/restart': new HandlerConfig(EngineRestartHandler),
81
+ '/engine/reload': new HandlerConfig(EngineReloadHandler),
80
82
  '/engine/shutdown': new HandlerConfig(EngineShutdownHandler),
81
83
  };
82
84
 
@@ -0,0 +1,32 @@
1
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
+ import { ConflictError } from '../../../exceptions/http/ConflictError.js';
3
+ import { Application } from '../../../services/Application.js';
4
+
5
+ /**
6
+ * Executes request-handling behaviour for PATCH /engine/reload.
7
+ * @author darthjee
8
+ */
9
+ class EngineReloadHandler extends RequestHandler {
10
+ #response;
11
+
12
+ /**
13
+ * @param {object} _request - The Express request object.
14
+ * @param {object} response - The Express response object.
15
+ */
16
+ constructor(_request, response) {
17
+ super();
18
+ this.#response = response;
19
+ }
20
+
21
+ /**
22
+ * Initiates a config reload + restart. Responds immediately with the transitional status.
23
+ * @returns {Promise<void>}
24
+ */
25
+ async handle() {
26
+ if (!Application.isRunning()) throw new ConflictError();
27
+ Application.reload();
28
+ this.#response.json({ status: 'stopping' });
29
+ }
30
+ }
31
+
32
+ export { EngineReloadHandler };
@@ -171,6 +171,15 @@ class Application {
171
171
  return Application.#getInstance().restart();
172
172
  }
173
173
 
174
+ /**
175
+ * Reloads configuration from disk, merging it into the live namespace, then
176
+ * restarts processing.
177
+ * @returns {Promise<void>}
178
+ */
179
+ static async reload() {
180
+ return Application.#getInstance().reload();
181
+ }
182
+
174
183
  /**
175
184
  * Shuts down the web server and stops the engine.
176
185
  * @returns {Promise<void>}
@@ -1,3 +1,4 @@
1
+ import { ConfigIncluder } from './ConfigIncluder.js';
1
2
  import { Engine } from './Engine.js';
2
3
  import { EngineEvents } from './EngineEvents.js';
3
4
  import { FailureChecker } from './FailureChecker.js';
@@ -12,10 +13,10 @@ import { HtmlParseJob } from '../jobs/HtmlParseJob.js';
12
13
  import { PaginatedActionProcessingJob } from '../jobs/PaginatedActionProcessingJob.js';
13
14
  import { Config } from '../models/configs/Config.js';
14
15
  import { LogRegistry } from '../registry/LogRegistry.js';
16
+ import { NamespaceMap } from '../registry/NamespaceMap.js';
15
17
  import { WebServer } from '../server/WebServer.js';
16
18
  import { PromiseAggregator } from '../utils/PromiseAggregator.js';
17
19
  import { ResourceEnqueuer } from '../utils/ResourceEnqueuer.js';
18
- import { ResourceRequestCollector } from '../utils/ResourceRequestCollector.js';
19
20
 
20
21
  const DEFAULT_POLL_SLEEP_MS = 10;
21
22
 
@@ -31,6 +32,7 @@ class ApplicationInstance {
31
32
  #aggregator;
32
33
  #enginePromise;
33
34
  #sleepMs;
35
+ #configPath;
34
36
 
35
37
  /**
36
38
  * @param {object} [params={}] - Optional parameters for dependency injection.
@@ -52,6 +54,7 @@ class ApplicationInstance {
52
54
  throw new ConfigurationFileNotProvided();
53
55
  }
54
56
 
57
+ this.#configPath = configPath;
55
58
  this.config = Config.fromFile(configPath);
56
59
  const logRegistry = LogRegistry.build({ retention: this.config.logConfig.size });
57
60
  this.#bufferedLogger = logRegistry.bufferedLogger;
@@ -121,12 +124,13 @@ class ApplicationInstance {
121
124
  * Enqueues all parameter-free ResourceRequests into the job registry.
122
125
  * These are requests whose URLs contain no {:placeholder} tokens and can be
123
126
  * processed immediately without any external parameters.
127
+ * Delegates to `ResourceEnqueuer#enqueueAll` (default namespace), so it always
128
+ * reflects the live state of the `NamespaceMap` singleton, including resources
129
+ * added via `POST /api/config` after boot.
124
130
  * @returns {void}
125
131
  */
126
132
  enqueueFirstJobs() {
127
- new ResourceRequestCollector(this.config.resourceRegistry).requestsNeedingNoParams().forEach((resourceRequest) => {
128
- JobRegistry.enqueue('ResourceRequestJob', { resourceRequest, parameters: {} });
129
- });
133
+ new ResourceEnqueuer().enqueueAll();
130
134
  }
131
135
 
132
136
  /**
@@ -254,6 +258,19 @@ class ApplicationInstance {
254
258
  await this.start();
255
259
  }
256
260
 
261
+ /**
262
+ * Reloads processing: stops the engine, re-reads the on-disk config file(s) and
263
+ * merges them into the live `NamespaceMap`, then starts the engine again.
264
+ * Only valid when status is 'running'.
265
+ * @returns {Promise<void>}
266
+ */
267
+ async reload() {
268
+ if (this.#engineStatus !== 'running') return;
269
+ await this.stop();
270
+ NamespaceMap.include(ConfigIncluder.resolve(this.#configPath));
271
+ await this.start();
272
+ }
273
+
257
274
  /**
258
275
  * Shuts down the web server and stops the engine loop.
259
276
  * If running, pauses first and waits for workers to idle.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "navi-hey",
3
3
  "type": "module",
4
- "version": "1.6.0",
4
+ "version": "1.6.1",
5
5
  "description": "Navi cache warmer CLI",
6
6
  "readme": "README.md",
7
7
  "main": "index.js",