navi-hey 1.11.0 → 1.12.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.
- package/lib/common/utils/env_resolver/EnvStringResolver.js +1 -1
- package/lib/common/utils/logging/buffer/BufferedLogger.js +1 -1
- package/lib/models/configs/MenuConfig.js +1 -1
- package/lib/models/request/resource_request/ResourceRequest.js +24 -3
- package/lib/models/request/resource_request/ResourceRequestEmit.js +17 -1
- package/lib/parsers/css_selector_parser/FilterMatcher.js +1 -1
- package/lib/registry/instances/LogRegistryInstance.js +1 -2
- package/lib/server/RouteRegister.js +1 -1
- package/lib/server/SecuredRequestHandler.js +1 -1
- package/lib/server/WebServer.js +1 -1
- package/lib/server/extensions/ExtensionRoutesLoader.js +1 -1
- package/lib/server/handlers/api/ApiEngineStartHandler.js +39 -4
- package/lib/services/config/ConfigIncluder.js +1 -1
- package/lib/utils/ResourceEnqueuer.js +33 -8
- package/lib/utils/memory/CgroupV1MemoryLimitReader.js +10 -0
- package/package.json +3 -2
- package/static/assets/react-vendor.js +8 -8
- package/lib/common/utils/logging/BaseLogger.js +0 -98
- package/lib/common/utils/logging/ConsoleLogger.js +0 -20
- package/lib/common/utils/logging/Logger.js +0 -138
- package/lib/common/utils/logging/LoggerGroup.js +0 -104
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { Logger } from 'deku-sprout';
|
|
2
3
|
import YAML from 'yaml';
|
|
3
4
|
import { MenuEntry } from './MenuEntry.js';
|
|
4
5
|
import { EnvStringResolver } from '../../common/utils/env_resolver/EnvStringResolver.js';
|
|
5
|
-
import { Logger } from '../../common/utils/logging/Logger.js';
|
|
6
6
|
import { MenuConfigurationInvalid } from '../../exceptions/config/MenuConfigurationInvalid.js';
|
|
7
7
|
|
|
8
8
|
const DEFAULT_LABELS = {
|
|
@@ -198,11 +198,12 @@ class ResourceRequest {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
/**
|
|
201
|
-
* Returns true when the resource request declares a follow-up emit configuration
|
|
202
|
-
*
|
|
201
|
+
* Returns true when the resource request declares a follow-up emit configuration
|
|
202
|
+
* that is not itself disabled (via the emit's own `enabled`/`disabled` flags).
|
|
203
|
+
* @returns {boolean} True if emit is configured and enabled.
|
|
203
204
|
*/
|
|
204
205
|
hasEmit() {
|
|
205
|
-
return !!this.emit;
|
|
206
|
+
return !!this.emit && !this.emit.disabled;
|
|
206
207
|
}
|
|
207
208
|
|
|
208
209
|
/**
|
|
@@ -225,6 +226,26 @@ class ResourceRequest {
|
|
|
225
226
|
return /\{:\w+\}/.test(this.url);
|
|
226
227
|
}
|
|
227
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Returns true if the URL template contains at least one {:placeholder} token
|
|
231
|
+
* whose key is absent or null in the given parameters. An empty string is
|
|
232
|
+
* considered a present value and does not count as unresolved. Extra keys in
|
|
233
|
+
* parameters with no matching token are irrelevant to this check.
|
|
234
|
+
* @param {object} [parameters={}] Key-value map of URL parameters.
|
|
235
|
+
* @returns {boolean} true if at least one token remains unresolved, false otherwise.
|
|
236
|
+
*/
|
|
237
|
+
hasUnresolvedTokens(parameters = {}) {
|
|
238
|
+
const matches = this.url.matchAll(/\{:(\w+)\}/g);
|
|
239
|
+
|
|
240
|
+
for (const [, key] of matches) {
|
|
241
|
+
if (!Object.prototype.hasOwnProperty.call(parameters, key) || parameters[key] === null) {
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
|
|
228
249
|
/**
|
|
229
250
|
* Creates a list of ResourceRequest instances from an array of objects.
|
|
230
251
|
* @param {Array<{ url: string, status: number }>} array list of objects with attributes to create a new ResourceRequest
|
|
@@ -33,6 +33,7 @@ class ResourceRequestEmit {
|
|
|
33
33
|
#cooldown;
|
|
34
34
|
#headers;
|
|
35
35
|
#bodyTemplate;
|
|
36
|
+
#disabled;
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* @param {object} attributes ResourceRequestEmit attributes.
|
|
@@ -55,8 +56,12 @@ class ResourceRequestEmit {
|
|
|
55
56
|
* to wrap/re-shape the extracted item before it is sent as the emit request body. `{:key}`
|
|
56
57
|
* / `{:nested.path}` tokens are resolved against the item; `{:.}` refers to the whole item.
|
|
57
58
|
* When omitted, the bare item is sent as the body (current behavior).
|
|
59
|
+
* @param {boolean} [attributes.enabled] Whether this emit is enabled. Defaults to enabled
|
|
60
|
+
* when omitted. Ignored when `disabled` is `true`.
|
|
61
|
+
* @param {boolean} [attributes.disabled] Whether this emit is disabled. Takes precedence
|
|
62
|
+
* over `enabled` when `true`.
|
|
58
63
|
*/
|
|
59
|
-
constructor({ client, method, url, status, retries, cooldown, headers, body_template: bodyTemplate }) {
|
|
64
|
+
constructor({ client, method, url, status, retries, cooldown, headers, body_template: bodyTemplate, enabled, disabled }) {
|
|
60
65
|
if (!EMIT_METHODS.includes(method)) throw new InvalidEmitMethod(method);
|
|
61
66
|
if (!url) throw new MissingEmitUrl();
|
|
62
67
|
if (retries !== undefined && (typeof retries !== 'number' || retries < 0)) throw new InvalidEmitRetries(retries);
|
|
@@ -69,6 +74,7 @@ class ResourceRequestEmit {
|
|
|
69
74
|
this.#cooldown = cooldown;
|
|
70
75
|
this.#headers = this.#parseHeaders(headers);
|
|
71
76
|
this.#bodyTemplate = this.#parseBodyTemplate(bodyTemplate);
|
|
77
|
+
this.#disabled = disabled === true || enabled === false;
|
|
72
78
|
|
|
73
79
|
this.method = method;
|
|
74
80
|
this.url = url;
|
|
@@ -127,6 +133,16 @@ class ResourceRequestEmit {
|
|
|
127
133
|
return this.#bodyTemplate;
|
|
128
134
|
}
|
|
129
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Returns whether this emit is disabled, i.e. it must not be enqueued. This emit is
|
|
138
|
+
* disabled when `disabled: true` was given (regardless of `enabled`), or when
|
|
139
|
+
* `enabled: false` was given. Otherwise it is enabled (the default).
|
|
140
|
+
* @returns {boolean} True if this emit is disabled.
|
|
141
|
+
*/
|
|
142
|
+
get disabled() {
|
|
143
|
+
return this.#disabled;
|
|
144
|
+
}
|
|
145
|
+
|
|
130
146
|
/**
|
|
131
147
|
* Returns the URL with every {:placeholder} token replaced by the
|
|
132
148
|
* corresponding value from the parameters object.
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { Logger, LoggerGroup } from 'deku-sprout';
|
|
1
2
|
import { BufferedLogger } from '../../common/utils/logging/buffer/BufferedLogger.js';
|
|
2
3
|
import { LogBufferCollection } from '../../common/utils/logging/buffer/LogBufferCollection.js';
|
|
3
4
|
import { LogFilter } from '../../common/utils/logging/LogFilter.js';
|
|
4
|
-
import { Logger } from '../../common/utils/logging/Logger.js';
|
|
5
|
-
import { LoggerGroup } from '../../common/utils/logging/LoggerGroup.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Holds a LoggerGroup (Logger + BufferedLogger) for the LogRegistry singleton.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger } from '
|
|
1
|
+
import { Logger } from 'deku-sprout';
|
|
2
2
|
import { ConflictError } from '../exceptions/http/ConflictError.js';
|
|
3
3
|
import { ForbiddenError } from '../exceptions/http/ForbiddenError.js';
|
|
4
4
|
import { NotFoundError } from '../exceptions/http/NotFoundError.js';
|
package/lib/server/WebServer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { Logger } from '
|
|
4
|
+
import { Logger } from 'deku-sprout';
|
|
5
5
|
import { ExtensionsDirectoryMissing } from '../../exceptions/config/ExtensionsDirectoryMissing.js';
|
|
6
6
|
import { ForbiddenError } from '../../exceptions/http/ForbiddenError.js';
|
|
7
7
|
import { PathValidator } from '../PathValidator.js';
|
|
@@ -116,22 +116,57 @@ class ApiEngineStartHandler extends SecuredRequestHandler {
|
|
|
116
116
|
*/
|
|
117
117
|
#validTarget(target) {
|
|
118
118
|
if (!target || typeof target.namespace !== 'string' || !target.namespace.trim()) return false;
|
|
119
|
+
if (target.parameters !== undefined && !this.#validParameters(target.parameters)) return false;
|
|
119
120
|
if (target.resources === undefined) return true;
|
|
120
121
|
|
|
121
|
-
return Array.isArray(target.resources) && target.resources.every((
|
|
122
|
+
return Array.isArray(target.resources) && target.resources.every((entry) => this.#validResourceEntry(entry));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Validates a single `resources[]` entry: either a bare string (unchanged, including
|
|
127
|
+
* an empty string), or a plain object with a non-blank `name` and, if present, a
|
|
128
|
+
* `parameters` value that passes `#validParameters`. Unknown keys are ignored.
|
|
129
|
+
* @param {*} entry - The candidate resource entry.
|
|
130
|
+
* @returns {boolean} True when the entry is well-formed.
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
#validResourceEntry(entry) {
|
|
134
|
+
if (typeof entry === 'string') return true;
|
|
135
|
+
|
|
136
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return false;
|
|
137
|
+
if (typeof entry.name !== 'string' || !entry.name.trim()) return false;
|
|
138
|
+
|
|
139
|
+
return entry.parameters === undefined || this.#validParameters(entry.parameters);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Validates a parameter map: a plain object (not an array, not null) whose every
|
|
144
|
+
* value is a string, number, boolean, or null.
|
|
145
|
+
* @param {*} value - The candidate parameters value.
|
|
146
|
+
* @returns {boolean} True when the value is a well-formed parameter map.
|
|
147
|
+
* @private
|
|
148
|
+
*/
|
|
149
|
+
#validParameters(value) {
|
|
150
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
151
|
+
|
|
152
|
+
return Object.values(value).every((paramValue) => (
|
|
153
|
+
paramValue === null || ['string', 'number', 'boolean'].includes(typeof paramValue)
|
|
154
|
+
));
|
|
122
155
|
}
|
|
123
156
|
|
|
124
157
|
/**
|
|
125
158
|
* Aggregates the per-target enqueue results into one flat `{ enqueued, skippedResources }`.
|
|
126
|
-
* @param {Array<{namespace: string, resources: Array<string>|undefined}>} targets - The targets to enqueue.
|
|
159
|
+
* @param {Array<{namespace: string, resources: Array<string|object>|undefined, parameters: object|undefined}>} targets - The targets to enqueue.
|
|
127
160
|
* @param {{enqueued: Array<string>, skippedResources: Array<object>}} [seed] - Initial accumulator.
|
|
128
161
|
* @returns {{enqueued: Array<string>, skippedResources: Array<object>}} The aggregated result.
|
|
129
162
|
* @private
|
|
130
163
|
*/
|
|
131
164
|
#aggregate(targets, seed = { enqueued: [], skippedResources: [] }) {
|
|
132
|
-
return targets.reduce((acc, { namespace, resources }) => {
|
|
165
|
+
return targets.reduce((acc, { namespace, resources, parameters }) => {
|
|
133
166
|
const enqueuer = new ResourceEnqueuer(namespace);
|
|
134
|
-
const result = resources === undefined
|
|
167
|
+
const result = resources === undefined
|
|
168
|
+
? enqueuer.enqueueAll()
|
|
169
|
+
: enqueuer.enqueue(resources, { parameters: parameters ?? {} });
|
|
135
170
|
|
|
136
171
|
return {
|
|
137
172
|
enqueued: [...acc.enqueued, ...result.enqueued],
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { Logger } from 'deku-sprout';
|
|
3
4
|
import YAML from 'yaml';
|
|
4
5
|
import { EnvStringResolver } from '../../common/utils/env_resolver/EnvStringResolver.js';
|
|
5
|
-
import { Logger } from '../../common/utils/logging/Logger.js';
|
|
6
6
|
import { ConfigurationFileNotFound } from '../../exceptions/config/file/ConfigurationFileNotFound.js';
|
|
7
7
|
import { ConfigurationIncludeNotFound } from '../../exceptions/config/file/ConfigurationIncludeNotFound.js';
|
|
8
8
|
|
|
@@ -24,15 +24,20 @@ class ResourceEnqueuer {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* Enqueues the given resource
|
|
28
|
-
* @param {Array<string>}
|
|
29
|
-
*
|
|
27
|
+
* Enqueues the given resource entries.
|
|
28
|
+
* @param {Array<string|{name: string, parameters?: object}>} entries - Resource names to
|
|
29
|
+
* enqueue, either as bare names or as objects carrying per-resource parameter overrides.
|
|
30
|
+
* @param {object} [options={}] Enqueue options.
|
|
31
|
+
* @param {object} [options.parameters={}] Target-level default parameter map, merged
|
|
32
|
+
* underneath each entry's own `parameters` (per-resource values win on key conflict).
|
|
33
|
+
* @returns {{enqueued: Array<string>, skippedResources: Array<{name: string, reason: string, parameters?: object}>}} The enqueued names and any skipped resources.
|
|
30
34
|
*/
|
|
31
|
-
enqueue(
|
|
35
|
+
enqueue(entries, { parameters: targetParameters = {} } = {}) {
|
|
32
36
|
const enqueued = [];
|
|
33
37
|
const skippedResources = [];
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
entries.forEach((entry) => {
|
|
40
|
+
const { name, parameters: merged } = this.#normalizeEntry(entry, targetParameters);
|
|
36
41
|
const resource = this.#findResource(name);
|
|
37
42
|
|
|
38
43
|
if (!resource) {
|
|
@@ -45,13 +50,15 @@ class ResourceEnqueuer {
|
|
|
45
50
|
return;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
if (resource.resourceRequests.some((request) => request.
|
|
49
|
-
|
|
53
|
+
if (resource.resourceRequests.some((request) => request.hasUnresolvedTokens(merged))) {
|
|
54
|
+
const skipped = { name, reason: 'needs_params' };
|
|
55
|
+
if (Object.keys(merged).length > 0) skipped.parameters = merged;
|
|
56
|
+
skippedResources.push(skipped);
|
|
50
57
|
return;
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
resource.resourceRequests.forEach((resourceRequest) => {
|
|
54
|
-
JobRegistry.enqueue('ResourceRequestJob', { resourceRequest, parameters:
|
|
61
|
+
JobRegistry.enqueue('ResourceRequestJob', { resourceRequest, parameters: merged });
|
|
55
62
|
});
|
|
56
63
|
enqueued.push(name);
|
|
57
64
|
});
|
|
@@ -79,6 +86,24 @@ class ResourceEnqueuer {
|
|
|
79
86
|
return { enqueued: [], skippedResources: [] };
|
|
80
87
|
}
|
|
81
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Normalizes a resource entry into its resolved name and merged parameter map.
|
|
91
|
+
* A bare string entry inherits the target-level parameters as-is; an object
|
|
92
|
+
* entry's own `parameters` are shallow-merged on top of the target-level
|
|
93
|
+
* defaults, with the per-resource value winning on key conflict.
|
|
94
|
+
* @param {string|{name: string, parameters?: object}} entry - The raw resource entry.
|
|
95
|
+
* @param {object} targetParameters - The target-level default parameter map.
|
|
96
|
+
* @returns {{name: string, parameters: object}} The resolved name and merged parameters.
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
#normalizeEntry(entry, targetParameters) {
|
|
100
|
+
if (typeof entry === 'string') {
|
|
101
|
+
return { name: entry, parameters: targetParameters };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { name: entry.name, parameters: { ...targetParameters, ...entry.parameters } };
|
|
105
|
+
}
|
|
106
|
+
|
|
82
107
|
/**
|
|
83
108
|
* Looks up a resource, by name, in the target namespace, returning `null`
|
|
84
109
|
* instead of raising when the resource (or the namespace itself) cannot be found.
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
|
|
3
3
|
const CGROUP_V1_MEMORY_LIMIT_PATH = '/sys/fs/cgroup/memory/memory.limit_in_bytes';
|
|
4
|
+
// 9223372036854771712 (0x7FFFFFFFFFFFF000, i.e. 2^63 - 2^12) is the real Linux
|
|
5
|
+
// cgroup v1 kernel "unbounded" sentinel for `memory.limit_in_bytes`, page-aligned
|
|
6
|
+
// (4096-byte multiple) by the kernel — it is NOT an approximation of int64 max
|
|
7
|
+
// (9223372036854775807). Because it's a multiple of 4096, it is exactly
|
|
8
|
+
// representable as a JS double despite exceeding Number.MAX_SAFE_INTEGER, so
|
|
9
|
+
// `Number(content) === UNBOUNDED` reproducibly matches (verified via
|
|
10
|
+
// `BigInt(UNBOUNDED)` round-tripping to this exact literal). Do NOT change this
|
|
11
|
+
// to `Number.MAX_SAFE_INTEGER` (a different value, which would break real
|
|
12
|
+
// unbounded detection) or to a `BigInt` (unnecessary, since the existing
|
|
13
|
+
// comparison already round-trips exactly).
|
|
4
14
|
const UNBOUNDED = 9223372036854771712;
|
|
5
15
|
|
|
6
16
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "navi-hey",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.12.0",
|
|
5
5
|
"description": "Navi cache warmer CLI",
|
|
6
6
|
"readme": "README.md",
|
|
7
7
|
"main": "index.js",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"axios": "^1.13.0",
|
|
37
|
-
"deku-
|
|
37
|
+
"deku-sprout": "file:../logger",
|
|
38
|
+
"deku-swarm": "1.10.0",
|
|
38
39
|
"express": "5.2.1",
|
|
39
40
|
"node-html-parser": "7.1.0",
|
|
40
41
|
"yaml": "^2.8.2"
|