@rapidrest/core 1.14.0 → 2.0.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/dist/lib/AlertUtils.js +71 -56
- package/dist/lib/AlertUtils.js.map +1 -1
- package/dist/lib/ApiError.js +8 -1
- package/dist/lib/ApiError.js.map +1 -1
- package/dist/lib/CacheUtils.js +23 -0
- package/dist/lib/CacheUtils.js.map +1 -0
- package/dist/lib/ClassLoader.js +48 -44
- package/dist/lib/ClassLoader.js.map +1 -1
- package/dist/lib/FileUtils.js +133 -60
- package/dist/lib/FileUtils.js.map +1 -1
- package/dist/lib/JWTUtils.js +250 -145
- package/dist/lib/JWTUtils.js.map +1 -1
- package/dist/lib/Logger.js +39 -7
- package/dist/lib/Logger.js.map +1 -1
- package/dist/lib/MemoryStore.js +8 -6
- package/dist/lib/MemoryStore.js.map +1 -1
- package/dist/lib/MessagingUtils.js +71 -35
- package/dist/lib/MessagingUtils.js.map +1 -1
- package/dist/lib/NotificationsUtils.js +60 -8
- package/dist/lib/NotificationsUtils.js.map +1 -1
- package/dist/lib/OASUtils.js +67 -18
- package/dist/lib/OASUtils.js.map +1 -1
- package/dist/lib/ObjectFactory.js +151 -63
- package/dist/lib/ObjectFactory.js.map +1 -1
- package/dist/lib/ObjectUtils.js +48 -7
- package/dist/lib/ObjectUtils.js.map +1 -1
- package/dist/lib/StringUtils.js +55 -21
- package/dist/lib/StringUtils.js.map +1 -1
- package/dist/lib/TelemetryUtils.js +41 -5
- package/dist/lib/TelemetryUtils.js.map +1 -1
- package/dist/lib/UserUtils.js +5 -6
- package/dist/lib/UserUtils.js.map +1 -1
- package/dist/lib/ValidationUtils.js +16 -4
- package/dist/lib/ValidationUtils.js.map +1 -1
- package/dist/lib/index.js +2 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/threads/ThreadPool.js +198 -58
- package/dist/lib/threads/ThreadPool.js.map +1 -1
- package/dist/types/AlertUtils.d.ts +4 -0
- package/dist/types/CacheUtils.d.ts +14 -0
- package/dist/types/ClassLoader.d.ts +10 -0
- package/dist/types/FileUtils.d.ts +23 -7
- package/dist/types/JWTUtils.d.ts +88 -18
- package/dist/types/MessagingUtils.d.ts +7 -1
- package/dist/types/NotificationsUtils.d.ts +30 -0
- package/dist/types/ObjectFactory.d.ts +25 -1
- package/dist/types/ObjectUtils.d.ts +14 -0
- package/dist/types/StringUtils.d.ts +8 -0
- package/dist/types/TelemetryUtils.d.ts +19 -1
- package/dist/types/ValidationUtils.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/threads/ThreadPool.d.ts +34 -2
- package/package.json +1 -1
package/dist/lib/AlertUtils.js
CHANGED
|
@@ -45,6 +45,12 @@ export class AlertUtils {
|
|
|
45
45
|
this.logger = options.logger;
|
|
46
46
|
this.serviceUrl = options.serviceUrl;
|
|
47
47
|
}
|
|
48
|
+
/** Returns `true` if `status` is a 2XX HTTP success code. Shared by every method below that inspects a
|
|
49
|
+
* response's status, so a future change to what counts as "success" (e.g. also accepting 304) only needs
|
|
50
|
+
* to be made in one place. */
|
|
51
|
+
static isSuccess(status) {
|
|
52
|
+
return status >= 200 && status < 300;
|
|
53
|
+
}
|
|
48
54
|
/**
|
|
49
55
|
* Attempts to close the existing alert with the given identifier.
|
|
50
56
|
* @param id The unique identifier of the alert to close.
|
|
@@ -52,23 +58,26 @@ export class AlertUtils {
|
|
|
52
58
|
*/
|
|
53
59
|
async close(id, data = {}) {
|
|
54
60
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
// Truncate into a copy rather than the caller's object, so `data` isn't silently modified out from
|
|
62
|
+
// under a caller that reuses it after this call returns.
|
|
63
|
+
const payload = { ...data };
|
|
64
|
+
if (payload.note) {
|
|
65
|
+
payload.note = payload.note.substring(0, MAX_CHARS_NOTE);
|
|
57
66
|
}
|
|
58
|
-
if (
|
|
59
|
-
|
|
67
|
+
if (payload.source) {
|
|
68
|
+
payload.source = payload.source.substring(0, MAX_CHARS_SOURCE);
|
|
60
69
|
}
|
|
61
|
-
const url = `${this.serviceUrl}/${id}/close`;
|
|
62
|
-
const response = await axios.post(url,
|
|
70
|
+
const url = `${this.serviceUrl}/${encodeURIComponent(id)}/close`;
|
|
71
|
+
const response = await axios.post(url, payload, {
|
|
63
72
|
headers: {
|
|
64
73
|
Authorization: this.auth,
|
|
65
74
|
}
|
|
66
75
|
});
|
|
67
|
-
return
|
|
76
|
+
return AlertUtils.isSuccess(response.status);
|
|
68
77
|
}
|
|
69
78
|
catch (err) {
|
|
70
|
-
this.logger
|
|
71
|
-
this.logger
|
|
79
|
+
this.logger?.error("Failed to close alert with id " + id);
|
|
80
|
+
this.logger?.error(err.message);
|
|
72
81
|
return false;
|
|
73
82
|
}
|
|
74
83
|
}
|
|
@@ -79,7 +88,7 @@ export class AlertUtils {
|
|
|
79
88
|
*/
|
|
80
89
|
async get(id) {
|
|
81
90
|
try {
|
|
82
|
-
const url = `${this.serviceUrl}/${id}`;
|
|
91
|
+
const url = `${this.serviceUrl}/${encodeURIComponent(id)}`;
|
|
83
92
|
const response = await axios.get(url, {
|
|
84
93
|
headers: {
|
|
85
94
|
Authorization: this.auth,
|
|
@@ -87,13 +96,11 @@ export class AlertUtils {
|
|
|
87
96
|
});
|
|
88
97
|
// axios's default validateStatus already rejects (throws) any non-2xx response before we get here, so
|
|
89
98
|
// the alternate branch below is unreachable under normal operation; kept as defense in depth.
|
|
90
|
-
return response.status
|
|
91
|
-
? response.data
|
|
92
|
-
: /* v8 ignore next */ null;
|
|
99
|
+
return AlertUtils.isSuccess(response.status) ? response.data : /* v8 ignore next */ null;
|
|
93
100
|
}
|
|
94
101
|
catch (err) {
|
|
95
|
-
this.logger
|
|
96
|
-
this.logger
|
|
102
|
+
this.logger?.error("Failed to retrieve alert with id " + id);
|
|
103
|
+
this.logger?.error(err.message);
|
|
97
104
|
return null;
|
|
98
105
|
}
|
|
99
106
|
}
|
|
@@ -107,41 +114,50 @@ export class AlertUtils {
|
|
|
107
114
|
*/
|
|
108
115
|
async send(alert, vars = {}, attachments) {
|
|
109
116
|
try {
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
117
|
+
// Substitute/truncate into a copy rather than the caller's `alert` object. `Alert` is a natural
|
|
118
|
+
// template to define once and reuse across multiple send() calls with different `vars` - mutating it
|
|
119
|
+
// in place would leave later calls with no "{{placeholder}}" left to substitute, since the first call
|
|
120
|
+
// already overwrote them with the first call's resolved values.
|
|
121
|
+
const payload = { ...alert };
|
|
122
|
+
// Perform variable substitution on the alert's text fields *before* truncating them below. Note:
|
|
123
|
+
// these fields are treated as plain data, never as a template to compile/execute, since
|
|
124
|
+
// `description`/`message`/`note` frequently originate from untrusted event or exception text and
|
|
125
|
+
// must not be interpretable as code.
|
|
126
|
+
payload.description = StringUtils.findAndReplace(payload.description, vars);
|
|
127
|
+
payload.message = StringUtils.findAndReplace(payload.message, vars);
|
|
128
|
+
if (payload.note) {
|
|
129
|
+
payload.note = StringUtils.findAndReplace(payload.note, vars);
|
|
130
|
+
}
|
|
131
|
+
// Truncate the various properties to the maximimum allowed by the most restrictive known API (e.g.
|
|
132
|
+
// OpsGenie). Done *after* substitution above - substituting into an already-truncated string could
|
|
133
|
+
// expand a short placeholder (e.g. a long exception message) past the API's limit, defeating the
|
|
134
|
+
// truncation this is meant to guarantee.
|
|
135
|
+
payload.alias = payload.alias.substring(0, MAX_CHARS_ALIAS);
|
|
136
|
+
payload.description = payload.description.substring(0, MAX_CHARS_DESCRIPTION);
|
|
137
|
+
if (payload.entity) {
|
|
138
|
+
payload.entity = payload.entity.substring(0, MAX_CHARS_ENTITY);
|
|
115
139
|
}
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
140
|
+
payload.message = payload.message.substring(0, MAX_CHARS_MESSAGE);
|
|
141
|
+
if (payload.note) {
|
|
142
|
+
payload.note = payload.note.substring(0, MAX_CHARS_NOTE);
|
|
119
143
|
}
|
|
120
|
-
|
|
121
|
-
if (
|
|
144
|
+
payload.source = payload.source.substring(0, MAX_CHARS_SOURCE);
|
|
145
|
+
if (payload.tags) {
|
|
122
146
|
let tags = [];
|
|
123
|
-
for (let i = 0; i < Math.min(MAX_TAGS,
|
|
124
|
-
const tag =
|
|
147
|
+
for (let i = 0; i < Math.min(MAX_TAGS, payload.tags.length); i++) {
|
|
148
|
+
const tag = payload.tags[i];
|
|
125
149
|
tags.push(tag.substring(0, MAX_CHARS_TAGS));
|
|
126
150
|
}
|
|
127
|
-
|
|
151
|
+
payload.tags = tags;
|
|
128
152
|
}
|
|
129
|
-
|
|
130
|
-
// data, never as a template to compile/execute, since `description`/`message`/`note` frequently
|
|
131
|
-
// originate from untrusted event or exception text and must not be interpretable as code.
|
|
132
|
-
alert.description = StringUtils.findAndReplace(alert.description, vars);
|
|
133
|
-
alert.message = StringUtils.findAndReplace(alert.message, vars);
|
|
134
|
-
if (alert.note) {
|
|
135
|
-
alert.note = StringUtils.findAndReplace(alert.note, vars);
|
|
136
|
-
}
|
|
137
|
-
let response = await axios.post(this.serviceUrl, alert, {
|
|
153
|
+
let response = await axios.post(this.serviceUrl, payload, {
|
|
138
154
|
headers: {
|
|
139
155
|
Authorization: this.auth,
|
|
140
156
|
}
|
|
141
157
|
});
|
|
142
158
|
// axios's default validateStatus already rejects (throws) any non-2xx response before we get here, so
|
|
143
159
|
// the alternate branch below is unreachable under normal operation; kept as defense in depth.
|
|
144
|
-
const requestId =
|
|
160
|
+
const requestId = AlertUtils.isSuccess(response.status)
|
|
145
161
|
? response.data.requestId
|
|
146
162
|
: /* v8 ignore next */ null;
|
|
147
163
|
if (!requestId) {
|
|
@@ -152,20 +168,19 @@ export class AlertUtils {
|
|
|
152
168
|
let count = 0;
|
|
153
169
|
while (!id && count < MAX_ATTEMPTS) {
|
|
154
170
|
try {
|
|
155
|
-
const url = `${this.serviceUrl}/requests/${requestId}`;
|
|
171
|
+
const url = `${this.serviceUrl}/requests/${encodeURIComponent(requestId)}`;
|
|
156
172
|
const response = await axios.get(url, {
|
|
157
173
|
headers: {
|
|
158
174
|
Authorization: this.auth,
|
|
159
175
|
}
|
|
160
176
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
177
|
+
if (response.data.success && response.data.alertId) {
|
|
178
|
+
id = response.data.alertId;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// Request accepted but not finished processing yet. Wait a second before retrying instead
|
|
182
|
+
// of hot-looping.
|
|
183
|
+
await sleep(1000);
|
|
169
184
|
}
|
|
170
185
|
}
|
|
171
186
|
catch (err) {
|
|
@@ -192,10 +207,10 @@ export class AlertUtils {
|
|
|
192
207
|
}, attachments.indexFile);
|
|
193
208
|
}
|
|
194
209
|
else {
|
|
195
|
-
// Upload each attachment individually
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
210
|
+
// Upload each attachment individually and concurrently - they're independent uploads to
|
|
211
|
+
// different destinations, so there's no need to serialize them and pay N round-trips of
|
|
212
|
+
// latency on this alerting path where fast delivery matters most.
|
|
213
|
+
await Promise.all(attachments.files.map((file) => this.addAttachment(id, file, attachments.indexFile)));
|
|
199
214
|
}
|
|
200
215
|
}
|
|
201
216
|
return id;
|
|
@@ -221,17 +236,17 @@ export class AlertUtils {
|
|
|
221
236
|
filename: attachment.filename,
|
|
222
237
|
knownLength: attachment.size
|
|
223
238
|
});
|
|
224
|
-
let url = `${this.serviceUrl}/${id}/attachments`;
|
|
239
|
+
let url = `${this.serviceUrl}/${encodeURIComponent(id)}/attachments`;
|
|
225
240
|
if (indexFile) {
|
|
226
|
-
url += "?indexFile=" + indexFile;
|
|
241
|
+
url += "?indexFile=" + encodeURIComponent(indexFile);
|
|
227
242
|
}
|
|
228
243
|
const response = await axios.post(url, form, {
|
|
229
244
|
headers: {
|
|
230
|
-
|
|
231
|
-
|
|
245
|
+
...form.getHeaders(),
|
|
246
|
+
Authorization: this.auth
|
|
232
247
|
}
|
|
233
248
|
});
|
|
234
|
-
return
|
|
249
|
+
return AlertUtils.isSuccess(response.status);
|
|
235
250
|
}
|
|
236
251
|
catch (err) {
|
|
237
252
|
// Don't fail the rest of the request if attachments fail
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlertUtils.js","sourceRoot":"","sources":["../../src/AlertUtils.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,kDAAkD;AAClD,+EAA+E;AAC/E,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,YAAY,GAAW,EAAE,CAAC;AAChC,MAAM,eAAe,GAAW,GAAG,CAAC;AACpC,MAAM,qBAAqB,GAAW,KAAK,CAAC;AAC5C,MAAM,gBAAgB,GAAW,GAAG,CAAC;AACrC,MAAM,iBAAiB,GAAW,GAAG,CAAC;AACtC,MAAM,cAAc,GAAW,KAAK,CAAC;AACrC,MAAM,gBAAgB,GAAW,GAAG,CAAC;AACrC,MAAM,cAAc,GAAW,EAAE,CAAC;AAClC,MAAM,QAAQ,GAAW,EAAE,CAAC;AAE5B;;GAEG;AACH,MAAM,CAAN,IAAY,aAWX;AAXD,WAAY,aAAa;IACrB,0FAA0F;IAC1F,gCAAe,CAAA;IACf,kGAAkG;IAClG,8BAAa,CAAA;IACb,gGAAgG;IAChG,iCAAgB,CAAA;IAChB,gHAAgH;IAChH,+BAAc,CAAA;IACd,6GAA6G;IAC7G,8BAAa,CAAA;AACjB,CAAC,EAXW,aAAa,KAAb,aAAa,QAWxB;AA6ED;;;GAGG;AACH,MAAM,OAAO,UAAU;IAQnB;;;OAGG;IACH,YAAY,OAA0B;QAClC,IAAI,CAAC,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BAA+B,UAAU,CAAC,QAAQ,aAAa,EAAE,GAAG,CAAC,CAAC;YACzF,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;YAC/D,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;CACJ"}
|
package/dist/lib/ApiError.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Logger } from "./Logger.js";
|
|
1
2
|
import { StringUtils } from "./StringUtils.js";
|
|
3
|
+
const logger = Logger();
|
|
2
4
|
/**
|
|
3
5
|
* Describes an error that originates from a API service. This class extends the standard `Error` class to include
|
|
4
6
|
* a unique code that can be used to trace an error to source code as well as the HTTP response status returned with
|
|
@@ -22,7 +24,12 @@ export class ApiError extends Error {
|
|
|
22
24
|
this.message = this.ApiMessageTemplate(message, templateVariables);
|
|
23
25
|
}
|
|
24
26
|
catch (error) {
|
|
25
|
-
//
|
|
27
|
+
// Falls back to the raw, unsubstituted `message` (already set via `super(message)` above) rather
|
|
28
|
+
// than propagating - a malformed template/templateVariables shouldn't prevent the error itself from
|
|
29
|
+
// being constructed and thrown. Logged rather than silently swallowed so a caller-supplied template
|
|
30
|
+
// bug is still discoverable.
|
|
31
|
+
logger.warn(`Failed to apply template variables to ApiError message: ${code}`);
|
|
32
|
+
logger.debug(error);
|
|
26
33
|
}
|
|
27
34
|
Object.setPrototypeOf(this, ApiError.prototype);
|
|
28
35
|
}
|
package/dist/lib/ApiError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiError.js","sourceRoot":"","sources":["../../src/ApiError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAMxB,kBAAkB,CAAC,OAA2B,EAAE,iBAAuB;QAC1E,IAAI,CAAC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AI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC;YACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,iGAAiG;YACjG,oGAAoG;YACpG,oGAAoG;YACpG,6BAA6B;YAC7B,MAAM,CAAC,IAAI,CAAC,2DAA2D,IAAI,EAAE,CAAC,CAAC;YAC/E,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;QACD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
|
|
3
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
4
|
+
/**
|
|
5
|
+
* Utility functions for working with bounded in-memory caches.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export class CacheUtils {
|
|
10
|
+
/**
|
|
11
|
+
* Evicts the oldest inserted entry from `map`, if any. A `Map` preserves insertion order, so this removes
|
|
12
|
+
* whatever entry was `set()` least recently among those still present.
|
|
13
|
+
*
|
|
14
|
+
* @param map The map to evict the oldest entry from.
|
|
15
|
+
*/
|
|
16
|
+
static evictOldest(map) {
|
|
17
|
+
const oldestKey = map.keys().next().value;
|
|
18
|
+
if (oldestKey !== undefined) {
|
|
19
|
+
map.delete(oldestKey);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=CacheUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheUtils.js","sourceRoot":"","sources":["../../src/CacheUtils.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,+EAA+E;AAE/E;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACnB;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAO,GAAc;QAC1C,MAAM,SAAS,GAAkB,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;QACzD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1B,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;CACJ"}
|
package/dist/lib/ClassLoader.js
CHANGED
|
@@ -41,6 +41,10 @@ const sepRegex = new RegExp("\\" + path.sep, "g");
|
|
|
41
41
|
* an ESM-only project you must use the `ts-node/esm` module loader. This can be specified by passing the `--loader` to
|
|
42
42
|
* node at runtime.
|
|
43
43
|
*
|
|
44
|
+
* Also, this code intentionally does not perform path-containment and symlink checks during it's load process as the
|
|
45
|
+
* purpose of this utility is never to be exposed to a client-facing API or process. Doing so would never make sense
|
|
46
|
+
* anyway. The lack of containment checks here is to eliminate real performance costs that such containment introduces.
|
|
47
|
+
*
|
|
44
48
|
* ```
|
|
45
49
|
* node --loader ts-node/esm <module>
|
|
46
50
|
* ```
|
|
@@ -95,6 +99,34 @@ export class ClassLoader {
|
|
|
95
99
|
hasClass(fqn) {
|
|
96
100
|
return this.classes.get(fqn) ? true : false;
|
|
97
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Imports the module at `fullpath` and registers each of its exports as a class under its fully qualified
|
|
104
|
+
* name, shared by both the JavaScript and TypeScript loading branches of `load()` so a future change to
|
|
105
|
+
* how exports are turned into registered classes only needs to be made in one place.
|
|
106
|
+
*/
|
|
107
|
+
async registerModule(fullpath, pkg, fileName) {
|
|
108
|
+
const mod = await import(pathToFileURL(fullpath).href);
|
|
109
|
+
/* v8 ignore else -- unreachable: dynamic `import()` either resolves to a truthy namespace object or rejects, it never resolves to a falsy value. */
|
|
110
|
+
if (mod) {
|
|
111
|
+
for (let name in mod) {
|
|
112
|
+
let clazz = mod[name];
|
|
113
|
+
// Skip primitive-valued exports (string/number/boolean/etc.) rather than registering them: ES
|
|
114
|
+
// modules run in strict mode, so `clazz.fqn = fqn` below would throw `TypeError: Cannot create
|
|
115
|
+
// property 'fqn' on <primitive>` for a module that exports e.g. `export const VERSION = "1.0.0"`
|
|
116
|
+
// alongside its classes, aborting the load of the entire directory. Enums compile to plain
|
|
117
|
+
// objects (typeof "object"), so they're still registered as before.
|
|
118
|
+
if (clazz === null || (typeof clazz !== "function" && typeof clazz !== "object")) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
let fqn = `${pkg.length > 0 ? pkg + "." : ""}${name === "default" ? path.basename(fileName, path.extname(fileName)) : name}`;
|
|
122
|
+
clazz.fqn = fqn;
|
|
123
|
+
this.classes.set(fqn, clazz);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw new Error("Failed to load module file: " + fullpath);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
98
130
|
/**
|
|
99
131
|
* Loads all modules exports contained in the directory specified. The folder must be a child
|
|
100
132
|
* directory to the `rootDir` parameter passed in to the constructor.
|
|
@@ -103,68 +135,40 @@ export class ClassLoader {
|
|
|
103
135
|
*/
|
|
104
136
|
async load(dir = "") {
|
|
105
137
|
let fqp = path.resolve(path.join(this.rootDir, dir));
|
|
106
|
-
// Ensure the resolved directory is still contained within rootDir. Prevents a caller-supplied `dir`
|
|
107
|
-
// (e.g. containing "../") from escaping rootDir and dynamically importing/executing arbitrary modules
|
|
108
|
-
// found elsewhere on disk.
|
|
109
|
-
const rel = path.relative(this.rootDir, fqp);
|
|
110
|
-
if (rel !== "" && (rel.startsWith("..") || path.isAbsolute(rel))) {
|
|
111
|
-
throw new Error(`Directory "${dir}" escapes the allowed root directory "${this.rootDir}".`);
|
|
112
|
-
}
|
|
113
138
|
let files = await fs.promises.readdir(fqp, { withFileTypes: true });
|
|
114
|
-
|
|
139
|
+
// Processed concurrently via `Promise.all` since sibling entries in a directory are independent of one
|
|
140
|
+
// another; `Promise.all` still `await`s every entry (and propagates the first rejection) before `load()`
|
|
141
|
+
// itself resolves, so parallelizing here only shortens cold-start time rather than changing behavior.
|
|
142
|
+
await Promise.all(files.map(async (file) => {
|
|
115
143
|
// Is the file in the ignore list?
|
|
116
|
-
let skipFile = false;
|
|
117
144
|
for (const iPath of this.ignore) {
|
|
118
145
|
if (file.name.match(iPath)) {
|
|
119
|
-
|
|
120
|
-
break;
|
|
146
|
+
return;
|
|
121
147
|
}
|
|
122
148
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
149
|
+
let relpath = path.relative(this.rootDir, fqp);
|
|
150
|
+
let pkg = relpath.replace(sepRegex, ".");
|
|
151
|
+
let fullpath = path.join(fqp, file.name);
|
|
126
152
|
let extension = path.extname(file.name);
|
|
127
153
|
if (!extension) {
|
|
128
154
|
extension = file.name;
|
|
129
155
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
156
|
+
// `Dirent.isDirectory()` reflects the directory entry itself, not what it points to, so a
|
|
157
|
+
// symlinked directory falls through to the extension-matching branches below rather than being
|
|
158
|
+
// recursed into - deliberate: following it here (e.g. via `fs.statSync().isDirectory()`) would
|
|
159
|
+
// let a symlink that points back at one of its own ancestors send `load()` into unbounded
|
|
160
|
+
// recursion.
|
|
133
161
|
if (file.isDirectory()) {
|
|
134
162
|
let subdir = path.join(dir, file.name);
|
|
135
163
|
await this.load(subdir);
|
|
136
164
|
}
|
|
137
165
|
else if (this.includeJavaScript && extension.match(/^\.(js|cjs|mjs)$/)) {
|
|
138
|
-
|
|
139
|
-
/* v8 ignore else -- unreachable: dynamic `import()` either resolves to a truthy namespace object or rejects, it never resolves to a falsy value. */
|
|
140
|
-
if (mod) {
|
|
141
|
-
for (let name in mod) {
|
|
142
|
-
let clazz = mod[name];
|
|
143
|
-
let fqn = `${pkg.length > 0 ? pkg + "." : ""}${name === "default" ? file.name.split(".")[0] : name}`;
|
|
144
|
-
clazz.fqn = fqn;
|
|
145
|
-
this.classes.set(fqn, clazz);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
throw new Error("Failed to load module file: " + fullpath);
|
|
150
|
-
}
|
|
166
|
+
await this.registerModule(fullpath, pkg, file.name);
|
|
151
167
|
}
|
|
152
168
|
else if (this.includeTypeScript && extension.match(/^\.(ts|cts|mts|tsx)$/)) {
|
|
153
|
-
|
|
154
|
-
/* v8 ignore else -- unreachable: dynamic `import()` either resolves to a truthy namespace object or rejects, it never resolves to a falsy value. */
|
|
155
|
-
if (mod) {
|
|
156
|
-
for (let name in mod) {
|
|
157
|
-
let clazz = mod[name];
|
|
158
|
-
let fqn = `${pkg.length > 0 ? pkg + "." : ""}${name === "default" ? file.name.split(".")[0] : name}`;
|
|
159
|
-
clazz.fqn = fqn;
|
|
160
|
-
this.classes.set(fqn, clazz);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
throw new Error("Failed to load module file: " + fullpath);
|
|
165
|
-
}
|
|
169
|
+
await this.registerModule(fullpath, pkg, file.name);
|
|
166
170
|
}
|
|
167
|
-
}
|
|
171
|
+
}));
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
//# sourceMappingURL=ClassLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassLoader.js","sourceRoot":"","sources":["../../src/ClassLoader.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,kDAAkD;AAClD,+EAA+E;AAC/E,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAClD
|
|
1
|
+
{"version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