@routier/core 0.4.0 → 0.5.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/index.cjs +73 -438
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +78 -443
- package/dist/index.js.map +1 -1
- package/dist/plugins/TelemetryDbPlugin.d.ts +43 -0
- package/dist/plugins/index.cjs +68 -1
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +73 -3
- package/dist/plugins/index.js.map +1 -1
- package/package.json +1 -9
- package/dist/capabilities/Capability.d.ts +0 -11
- package/dist/capabilities/PerformanceCapability.d.ts +0 -13
- package/dist/capabilities/TracingCapability.d.ts +0 -11
- package/dist/capabilities/index.cjs +0 -820
- package/dist/capabilities/index.cjs.map +0 -1
- package/dist/capabilities/index.d.ts +0 -4
- package/dist/capabilities/index.js +0 -808
- package/dist/capabilities/index.js.map +0 -1
- package/dist/capabilities/performance/PerformanceTracker.d.ts +0 -11
- package/dist/capabilities/tracing/CallTraceManager.d.ts +0 -12
- package/dist/capabilities/types.d.ts +0 -17
|
@@ -1,808 +0,0 @@
|
|
|
1
|
-
var __webpack_modules__ = ({
|
|
2
|
-
581(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
3
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
4
|
-
vF: () => (logger)
|
|
5
|
-
});
|
|
6
|
-
/**
|
|
7
|
-
* Levelled logging, resolved once.
|
|
8
|
-
*
|
|
9
|
-
* Three things about the previous implementation drove this shape:
|
|
10
|
-
*
|
|
11
|
-
* - **There was no way to turn logging off.** `globalThis.__ROUTIER_DEBUG__` was only ever
|
|
12
|
-
* compared against `true`, so setting it to `false` did nothing — while
|
|
13
|
-
* `docs/how-to/debug-logging.md` documented exactly that as the way to force logging off.
|
|
14
|
-
* A documented switch that silently does nothing is worse than no switch.
|
|
15
|
-
* - **`NODE_ENV === 'test'` enabled it.** Every Jest run therefore logged, because Jest always
|
|
16
|
-
* sets `NODE_ENV=test`. Measured on the S7 stress scenario, which drives ~2,000 saves through
|
|
17
|
-
* a plugin that logs three lines per query: 12.4s with logging, ~6s without. Test runners also
|
|
18
|
-
* capture console output by snapshotting a stack trace per call, so the cost is far above what
|
|
19
|
-
* writing to a terminal would suggest — and the output buries whatever the failure was.
|
|
20
|
-
* - **It was all-or-nothing, and re-resolved per call.** An error could not be kept while debug
|
|
21
|
-
* was dropped, and every one of the ~97 call sites re-read `globalThis` and `process.env`.
|
|
22
|
-
*
|
|
23
|
-
* Levels are compared numerically against a value cached at module load. Measured against a
|
|
24
|
-
* no-op console at 200k calls: an enabled call costs ~70ns, a call rejected by the gate ~3ns.
|
|
25
|
-
* Building the arguments the call site passes in accounts for ~0.2ns of that 3ns, which is why
|
|
26
|
-
* this keeps the ordinary `logger.debug(msg, payload)` signature instead of taking a thunk —
|
|
27
|
-
* a lazy API would recover 0.3% of an enabled call's cost and would have to change every call
|
|
28
|
-
* site to do it.
|
|
29
|
-
*/ /** Ordered from most severe to most verbose. `silent` discards everything. */ const LOG_LEVELS = [
|
|
30
|
-
'silent',
|
|
31
|
-
'error',
|
|
32
|
-
'warn',
|
|
33
|
-
'info',
|
|
34
|
-
'debug'
|
|
35
|
-
];
|
|
36
|
-
/** Numeric rank, so a gate is one integer comparison. */ const RANK = {
|
|
37
|
-
silent: 0,
|
|
38
|
-
error: 1,
|
|
39
|
-
warn: 2,
|
|
40
|
-
info: 3,
|
|
41
|
-
debug: 4
|
|
42
|
-
};
|
|
43
|
-
const isLogLevel = (value)=>typeof value === 'string' && LOG_LEVELS.includes(value);
|
|
44
|
-
/**
|
|
45
|
-
* Resolves the configured level, in precedence order.
|
|
46
|
-
*
|
|
47
|
-
* Ordered most specific first: an explicit level beats a boolean flag, a boolean flag beats an
|
|
48
|
-
* environment variable, and an environment variable beats an inference from `NODE_ENV`. Anything
|
|
49
|
-
* unrecognised is ignored rather than treated as an error — a typo'd level should not take down
|
|
50
|
-
* an application, and `silent` is the safe direction to fall back to.
|
|
51
|
-
*/ const resolveLevel = ()=>{
|
|
52
|
-
if (typeof globalThis !== 'undefined') {
|
|
53
|
-
const g = globalThis;
|
|
54
|
-
if (isLogLevel(g.__ROUTIER_LOG_LEVEL__)) {
|
|
55
|
-
return g.__ROUTIER_LOG_LEVEL__;
|
|
56
|
-
}
|
|
57
|
-
// Both directions honoured. `=== false` used to fall through to the NODE_ENV checks
|
|
58
|
-
// below and re-enable the logging it was asked to suppress.
|
|
59
|
-
if (g.__ROUTIER_DEBUG__ === true) return 'debug';
|
|
60
|
-
if (g.__ROUTIER_DEBUG__ === false) return 'silent';
|
|
61
|
-
}
|
|
62
|
-
// There is deliberately no `import.meta.env` branch, although the documentation used to
|
|
63
|
-
// promise one. It could never work: this package is bundled with rspack, which replaces
|
|
64
|
-
// `import.meta` with `undefined`, so the check would read the *library's* build-time
|
|
65
|
-
// environment rather than the application's — and referencing `import.meta` at all is a parse
|
|
66
|
-
// error under a CommonJS build target, which is how the test suite loads this file. Vite and
|
|
67
|
-
// similar apps set `__ROUTIER_LOG_LEVEL__` or `__ROUTIER_DEBUG__` from their own
|
|
68
|
-
// `import.meta.env`, which is what the docs now describe.
|
|
69
|
-
if (typeof process !== 'undefined' && process.env != null) {
|
|
70
|
-
if (isLogLevel(process.env.ROUTIER_LOG_LEVEL)) {
|
|
71
|
-
return process.env.ROUTIER_LOG_LEVEL;
|
|
72
|
-
}
|
|
73
|
-
const debug = process.env.DEBUG;
|
|
74
|
-
if (debug === 'routier' || debug === '*') return 'debug';
|
|
75
|
-
const env = "production"?.toLowerCase();
|
|
76
|
-
// `test` is deliberately absent. It used to be here, which meant no test suite anywhere
|
|
77
|
-
// could run Routier quietly. Opt in with DEBUG=routier or ROUTIER_LOG_LEVEL when a test
|
|
78
|
-
// needs the output.
|
|
79
|
-
if (env === 'dev' || env === 'development') return 'debug';
|
|
80
|
-
}
|
|
81
|
-
return 'silent';
|
|
82
|
-
};
|
|
83
|
-
let level = resolveLevel();
|
|
84
|
-
let rank = RANK[level];
|
|
85
|
-
/**
|
|
86
|
-
* Overrides the level for the rest of the process.
|
|
87
|
-
*
|
|
88
|
-
* The configuration above is read once, at import, which is what makes the gate cheap — but it
|
|
89
|
-
* also means an application that decides its verbosity after startup, or a test that wants to
|
|
90
|
-
* assert on output, has no way in. This is that way in.
|
|
91
|
-
*/ const setLogLevel = (next)=>{
|
|
92
|
-
if (isLogLevel(next) === false) {
|
|
93
|
-
throw new Error(`Unknown log level "${next}". Expected one of: ${LOG_LEVELS.join(', ')}`);
|
|
94
|
-
}
|
|
95
|
-
level = next;
|
|
96
|
-
rank = RANK[next];
|
|
97
|
-
};
|
|
98
|
-
const getLogLevel = ()=>level;
|
|
99
|
-
/** Re-reads the environment. For tests that change it after this module was imported. */ const resetLogLevel = ()=>{
|
|
100
|
-
level = resolveLevel();
|
|
101
|
-
rank = RANK[level];
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Whether a message at this level would be emitted.
|
|
105
|
-
*
|
|
106
|
-
* For the rare call site whose *arguments* are expensive to build — a serialization, a deep
|
|
107
|
-
* clone, a join over a large collection. An ordinary payload object is not worth guarding; see
|
|
108
|
-
* the measurement in the header.
|
|
109
|
-
*/ const isLogLevelEnabled = (at)=>rank >= RANK[at];
|
|
110
|
-
const emit = (at, method, args)=>{
|
|
111
|
-
if (rank < RANK[at]) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
// Resolved at call time rather than captured once: test harnesses and browser devtools both
|
|
115
|
-
// replace console methods after modules have loaded, and a captured reference would keep
|
|
116
|
-
// writing past the replacement.
|
|
117
|
-
console[method](...args);
|
|
118
|
-
};
|
|
119
|
-
const logger = {
|
|
120
|
-
/** General-purpose output. Carried at `info`, since `log` names a console method, not a level. */ log: (...args)=>emit('info', 'log', args),
|
|
121
|
-
info: (...args)=>emit('info', 'info', args),
|
|
122
|
-
warn: (...args)=>emit('warn', 'warn', args),
|
|
123
|
-
error: (...args)=>emit('error', 'error', args),
|
|
124
|
-
debug: (...args)=>emit('debug', 'debug', args),
|
|
125
|
-
/** Diagnostic tabular output; verbose by nature, so it sits at `debug`. */ table: (...args)=>emit('debug', 'table', args)
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
},
|
|
130
|
-
615(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
131
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
132
|
-
Zm: () => (stringifyObject)
|
|
133
|
-
});
|
|
134
|
-
const hash = (value, seed = 0)=>{
|
|
135
|
-
// From Stack Overflow
|
|
136
|
-
// https://stackoverflow.com/a/52171480/3329760
|
|
137
|
-
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
|
138
|
-
for(let i = 0, ch; i < value.length; i++){
|
|
139
|
-
ch = value.charCodeAt(i);
|
|
140
|
-
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
141
|
-
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
142
|
-
}
|
|
143
|
-
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
|
|
144
|
-
h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
145
|
-
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
146
|
-
h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
147
|
-
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
|
-
* Fast string hash optimized for comparisons.
|
|
151
|
-
* Uses djb2 algorithm - very fast and good distribution for short to medium strings.
|
|
152
|
-
* Same input always produces same output (deterministic).
|
|
153
|
-
*
|
|
154
|
-
* @param value - The string to hash
|
|
155
|
-
* @param seed - Optional seed value (default: 5381)
|
|
156
|
-
* @returns A positive 32-bit integer hash value
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* fastHash("test") === fastHash("test") // true
|
|
161
|
-
* fastHash("test") !== fastHash("test2") // true
|
|
162
|
-
* ```
|
|
163
|
-
*/ const fastHash = (value, seed = 5381)=>{
|
|
164
|
-
let hash = seed;
|
|
165
|
-
for(let i = 0; i < value.length; i++){
|
|
166
|
-
hash = (hash << 5) + hash + value.charCodeAt(i);
|
|
167
|
-
}
|
|
168
|
-
return hash >>> 0; // Convert to unsigned 32-bit integer
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Converts any value to a readable string representation.
|
|
172
|
-
* Handles primitives, objects, arrays, classes, dates, errors, and functions.
|
|
173
|
-
* Supports depth limiting to prevent infinite recursion on circular references.
|
|
174
|
-
*
|
|
175
|
-
* @param obj - The value to stringify
|
|
176
|
-
* @param maxDepth - Maximum depth for nested objects (default: 3)
|
|
177
|
-
* @param currentDepth - Current recursion depth (default: 0)
|
|
178
|
-
* @returns String representation of the value
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* ```ts
|
|
182
|
-
* stringifyObject({ name: "test", count: 5 }) // '{ name: "test", count: 5 }'
|
|
183
|
-
* stringifyObject([1, 2, 3]) // '[1, 2, 3]'
|
|
184
|
-
* stringifyObject(new Date()) // 'Date(2024-01-01T00:00:00.000Z)'
|
|
185
|
-
* ```
|
|
186
|
-
*/ function stringifyObject(obj, maxDepth = 3, currentDepth = 0) {
|
|
187
|
-
if (obj === null) return 'null';
|
|
188
|
-
if (obj === undefined) return 'undefined';
|
|
189
|
-
const type = typeof obj;
|
|
190
|
-
switch(type){
|
|
191
|
-
case 'string':
|
|
192
|
-
return `"${obj}"`;
|
|
193
|
-
case 'number':
|
|
194
|
-
case 'boolean':
|
|
195
|
-
return String(obj);
|
|
196
|
-
case 'function':
|
|
197
|
-
return `[Function: ${getFunctionName(obj)}]`;
|
|
198
|
-
case 'object':
|
|
199
|
-
if (currentDepth >= maxDepth) {
|
|
200
|
-
return '[Max Depth Reached]';
|
|
201
|
-
}
|
|
202
|
-
return stringifyObjectValue(obj, maxDepth, currentDepth);
|
|
203
|
-
default:
|
|
204
|
-
return `[${type}]`;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function getFunctionName(fn) {
|
|
208
|
-
const name = fn.name;
|
|
209
|
-
return name || 'anonymous';
|
|
210
|
-
}
|
|
211
|
-
function getObjectProperties(obj) {
|
|
212
|
-
const properties = {};
|
|
213
|
-
for(const key in obj){
|
|
214
|
-
if (obj.hasOwnProperty(key)) {
|
|
215
|
-
properties[key] = obj[key];
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return properties;
|
|
219
|
-
}
|
|
220
|
-
function stringifyObjectValue(obj, maxDepth, currentDepth) {
|
|
221
|
-
if (obj === null) return 'null';
|
|
222
|
-
if (obj instanceof Date) {
|
|
223
|
-
return `Date(${obj.toISOString()})`;
|
|
224
|
-
}
|
|
225
|
-
if (obj instanceof Error) {
|
|
226
|
-
return `Error(${obj.message})`;
|
|
227
|
-
}
|
|
228
|
-
if (obj instanceof RegExp) {
|
|
229
|
-
return obj.toString();
|
|
230
|
-
}
|
|
231
|
-
if (Array.isArray(obj)) {
|
|
232
|
-
return stringifyArray(obj, maxDepth, currentDepth);
|
|
233
|
-
}
|
|
234
|
-
if (obj.constructor && obj.constructor.name !== 'Object') {
|
|
235
|
-
return stringifyClassInstance(obj, maxDepth, currentDepth);
|
|
236
|
-
}
|
|
237
|
-
return stringifyPlainObject(obj, maxDepth, currentDepth);
|
|
238
|
-
}
|
|
239
|
-
function stringifyArray(arr, maxDepth, currentDepth) {
|
|
240
|
-
if (arr.length === 0) return '[]';
|
|
241
|
-
const items = arr.slice(0, 5).map((item)=>stringifyObject(item, maxDepth, currentDepth + 1));
|
|
242
|
-
const suffix = arr.length > 5 ? `... (+${arr.length - 5} more)` : '';
|
|
243
|
-
return `[${items.join(', ')}${suffix}]`;
|
|
244
|
-
}
|
|
245
|
-
function stringifyClassInstance(obj, maxDepth, currentDepth) {
|
|
246
|
-
const className = obj.constructor.name;
|
|
247
|
-
const properties = getObjectProperties(obj);
|
|
248
|
-
if (Object.keys(properties).length === 0) {
|
|
249
|
-
return `${className} {}`;
|
|
250
|
-
}
|
|
251
|
-
const props = Object.entries(properties).slice(0, 5).map(([key, value])=>{
|
|
252
|
-
const isPrimitive = value === null || value === undefined || typeof value !== 'object' && typeof value !== 'function';
|
|
253
|
-
const depth = isPrimitive ? currentDepth : currentDepth + 1;
|
|
254
|
-
return `${key}: ${stringifyObject(value, maxDepth, depth)}`;
|
|
255
|
-
});
|
|
256
|
-
const suffix = Object.keys(properties).length > 5 ? `... (+${Object.keys(properties).length - 5} more)` : '';
|
|
257
|
-
return `${className} { ${props.join(', ')}${suffix} }`;
|
|
258
|
-
}
|
|
259
|
-
function stringifyPlainObject(obj, maxDepth, currentDepth) {
|
|
260
|
-
const properties = getObjectProperties(obj);
|
|
261
|
-
if (Object.keys(properties).length === 0) {
|
|
262
|
-
return '{}';
|
|
263
|
-
}
|
|
264
|
-
const props = Object.entries(properties).slice(0, 5).map(([key, value])=>{
|
|
265
|
-
const isPrimitive = value === null || value === undefined || typeof value !== 'object' && typeof value !== 'function';
|
|
266
|
-
const depth = isPrimitive ? currentDepth : currentDepth + 1;
|
|
267
|
-
return `${key}: ${stringifyObject(value, maxDepth, depth)}`;
|
|
268
|
-
});
|
|
269
|
-
const suffix = Object.keys(properties).length > 5 ? `... (+${Object.keys(properties).length - 5} more)` : '';
|
|
270
|
-
return `{ ${props.join(', ')}${suffix} }`;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
},
|
|
275
|
-
618(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
276
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
277
|
-
u: () => (uuid)
|
|
278
|
-
});
|
|
279
|
-
const uuid = (length = 16)=>{
|
|
280
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
281
|
-
const charLength = chars.length;
|
|
282
|
-
let result = '';
|
|
283
|
-
for(let i = 0; i < length; i++){
|
|
284
|
-
result += chars[Math.random() * charLength | 0];
|
|
285
|
-
}
|
|
286
|
-
return result;
|
|
287
|
-
};
|
|
288
|
-
const HEX_CHARS = '0123456789abcdef';
|
|
289
|
-
const UUID_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
290
|
-
const hasCrypto = typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function';
|
|
291
|
-
const hasRandomUUID = typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function';
|
|
292
|
-
const uuidv4 = ()=>{
|
|
293
|
-
if (hasRandomUUID) {
|
|
294
|
-
return crypto.randomUUID();
|
|
295
|
-
}
|
|
296
|
-
return uuidv4Fallback();
|
|
297
|
-
};
|
|
298
|
-
const uuidv4Fallback = ()=>{
|
|
299
|
-
let randomBytes = null;
|
|
300
|
-
if (hasCrypto) {
|
|
301
|
-
randomBytes = crypto.getRandomValues(new Uint8Array(16));
|
|
302
|
-
}
|
|
303
|
-
let byteIndex = 0;
|
|
304
|
-
let uuid = '';
|
|
305
|
-
for(let i = 0; i < UUID_TEMPLATE.length; i++){
|
|
306
|
-
const c = UUID_TEMPLATE[i];
|
|
307
|
-
if (c === '-') {
|
|
308
|
-
uuid += '-';
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
let r;
|
|
312
|
-
if (hasCrypto && randomBytes) {
|
|
313
|
-
// Each byte gives two hex digits (nibbles)
|
|
314
|
-
r = i % 2 === 0 ? randomBytes[byteIndex] >> 4 : randomBytes[byteIndex++] & 0x0f;
|
|
315
|
-
} else {
|
|
316
|
-
r = Math.floor(Math.random() * 16);
|
|
317
|
-
}
|
|
318
|
-
if (c === 'x') {
|
|
319
|
-
uuid += HEX_CHARS[r];
|
|
320
|
-
} else if (c === 'y') {
|
|
321
|
-
// Variant bits: 8, 9, A, or B
|
|
322
|
-
uuid += HEX_CHARS[r & 0x3 | 0x8];
|
|
323
|
-
} else if (c === '4') {
|
|
324
|
-
uuid += '4';
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return uuid;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
},
|
|
332
|
-
|
|
333
|
-
});
|
|
334
|
-
// The module cache
|
|
335
|
-
var __webpack_module_cache__ = {};
|
|
336
|
-
|
|
337
|
-
// The require function
|
|
338
|
-
function __webpack_require__(moduleId) {
|
|
339
|
-
|
|
340
|
-
// Check if module is in cache
|
|
341
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
342
|
-
if (cachedModule !== undefined) {
|
|
343
|
-
return cachedModule.exports;
|
|
344
|
-
}
|
|
345
|
-
// Create a new module (and put it into the cache)
|
|
346
|
-
var module = (__webpack_module_cache__[moduleId] = {
|
|
347
|
-
exports: {}
|
|
348
|
-
});
|
|
349
|
-
// Execute the module function
|
|
350
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
351
|
-
|
|
352
|
-
// Return the exports of the module
|
|
353
|
-
return module.exports;
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// webpack/runtime/define_property_getters
|
|
358
|
-
(() => {
|
|
359
|
-
__webpack_require__.d = (exports, definition) => {
|
|
360
|
-
for(var key in definition) {
|
|
361
|
-
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
362
|
-
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
})();
|
|
367
|
-
// webpack/runtime/has_own_property
|
|
368
|
-
(() => {
|
|
369
|
-
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
370
|
-
})();
|
|
371
|
-
var __webpack_exports__ = {};
|
|
372
|
-
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
|
|
373
|
-
(() => {
|
|
374
|
-
|
|
375
|
-
// EXPORTS
|
|
376
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
377
|
-
nS: () => (/* reexport */ Capability),
|
|
378
|
-
VP: () => (/* reexport */ PerformanceCapability),
|
|
379
|
-
XO: () => (/* reexport */ TracingCapability)
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
;// CONCATENATED MODULE: ./src/capabilities/Capability.ts
|
|
383
|
-
class Capability {
|
|
384
|
-
excludedNames = new Set([
|
|
385
|
-
"Array",
|
|
386
|
-
"Set",
|
|
387
|
-
"Map",
|
|
388
|
-
"AbortController",
|
|
389
|
-
"AbortSignal",
|
|
390
|
-
"SchemaString",
|
|
391
|
-
"SchemaNumber",
|
|
392
|
-
"SchemaArray",
|
|
393
|
-
"SchemaBoolean",
|
|
394
|
-
"SchemaDate",
|
|
395
|
-
"SchemaObject",
|
|
396
|
-
"SchemaDefault",
|
|
397
|
-
"SchemaDeserialize",
|
|
398
|
-
"SchemaDistinct",
|
|
399
|
-
"SchemaSearchable",
|
|
400
|
-
"SchemaFrom",
|
|
401
|
-
"SchemaIdentity",
|
|
402
|
-
"SchemaIndex",
|
|
403
|
-
"SchemaKey",
|
|
404
|
-
"SchemaNullable",
|
|
405
|
-
"SchemaOptional",
|
|
406
|
-
"SchemaReadonly",
|
|
407
|
-
"SchemaSerialize",
|
|
408
|
-
"SchemaTracked",
|
|
409
|
-
"SchemaComputed",
|
|
410
|
-
"SchemaFunction",
|
|
411
|
-
"SchemaBase",
|
|
412
|
-
"SchemaDefinition"
|
|
413
|
-
]);
|
|
414
|
-
isValidObject(obj) {
|
|
415
|
-
return typeof obj === "object" && obj !== null;
|
|
416
|
-
}
|
|
417
|
-
isCallableMethod(descriptor, key) {
|
|
418
|
-
return descriptor?.value && typeof descriptor.value === 'function' && key !== 'constructor' && key !== 'undefined';
|
|
419
|
-
}
|
|
420
|
-
canExplore(descriptor) {
|
|
421
|
-
if (typeof descriptor.value !== "object") {
|
|
422
|
-
return false;
|
|
423
|
-
}
|
|
424
|
-
if (descriptor.value == null) {
|
|
425
|
-
return false;
|
|
426
|
-
}
|
|
427
|
-
const name = this.getName(descriptor.value);
|
|
428
|
-
if (name == null) {
|
|
429
|
-
return true;
|
|
430
|
-
}
|
|
431
|
-
return this.excludedNames.has(name) === false;
|
|
432
|
-
}
|
|
433
|
-
getName(value) {
|
|
434
|
-
if (value.constructor != null) {
|
|
435
|
-
return value.constructor.name;
|
|
436
|
-
}
|
|
437
|
-
return null;
|
|
438
|
-
}
|
|
439
|
-
getPath(info, propertyName) {
|
|
440
|
-
let parent = info.parent;
|
|
441
|
-
const path = [
|
|
442
|
-
info.propertyName,
|
|
443
|
-
propertyName
|
|
444
|
-
];
|
|
445
|
-
while(parent != null){
|
|
446
|
-
path.unshift(parent.propertyName);
|
|
447
|
-
parent = parent.parent;
|
|
448
|
-
}
|
|
449
|
-
return path.join(".");
|
|
450
|
-
}
|
|
451
|
-
explore(instance, onDiscover) {
|
|
452
|
-
if (!this.isValidObject(instance)) {
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
const explore = [
|
|
456
|
-
{
|
|
457
|
-
instance,
|
|
458
|
-
propertyName: this.getName(instance)
|
|
459
|
-
}
|
|
460
|
-
];
|
|
461
|
-
const visited = new Set();
|
|
462
|
-
for(let i = 0; i < explore.length; i++){
|
|
463
|
-
const info = explore[i];
|
|
464
|
-
const item = info.instance;
|
|
465
|
-
if (visited.has(item)) {
|
|
466
|
-
continue;
|
|
467
|
-
}
|
|
468
|
-
const allKeys = [
|
|
469
|
-
...Object.getOwnPropertyNames(item),
|
|
470
|
-
...Object.getOwnPropertySymbols(item)
|
|
471
|
-
];
|
|
472
|
-
for (const key of allKeys){
|
|
473
|
-
const descriptor = Object.getOwnPropertyDescriptor(item, key);
|
|
474
|
-
const isCallable = this.isCallableMethod(descriptor, key);
|
|
475
|
-
onDiscover(info, {
|
|
476
|
-
name: key,
|
|
477
|
-
isCallable
|
|
478
|
-
});
|
|
479
|
-
if (this.canExplore(descriptor) === false) {
|
|
480
|
-
continue;
|
|
481
|
-
}
|
|
482
|
-
const path = this.getPath(info, key);
|
|
483
|
-
explore.push({
|
|
484
|
-
instance: descriptor.value,
|
|
485
|
-
parent: info,
|
|
486
|
-
propertyName: key,
|
|
487
|
-
path
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
visited.add(item);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// EXTERNAL MODULE: ./src/utilities/strings.ts
|
|
496
|
-
var strings = __webpack_require__(615);
|
|
497
|
-
;// CONCATENATED MODULE: ./src/capabilities/performance/PerformanceTracker.ts
|
|
498
|
-
class PerformanceTracker {
|
|
499
|
-
methodTimings = new Map();
|
|
500
|
-
operationStartTimes = new Map();
|
|
501
|
-
startMethodTiming(operationId, methodPath) {
|
|
502
|
-
const startTime = performance.now();
|
|
503
|
-
const key = `${operationId}:${methodPath}`;
|
|
504
|
-
// Track operation start time for delta calculations
|
|
505
|
-
if (!this.operationStartTimes.has(operationId)) {
|
|
506
|
-
this.operationStartTimes.set(operationId, startTime);
|
|
507
|
-
}
|
|
508
|
-
this.methodTimings.set(key, {
|
|
509
|
-
startTime
|
|
510
|
-
});
|
|
511
|
-
return startTime;
|
|
512
|
-
}
|
|
513
|
-
recordNextMethodStart(operationId, methodPath) {
|
|
514
|
-
const key = `${operationId}:${methodPath}`;
|
|
515
|
-
const timing = this.methodTimings.get(key);
|
|
516
|
-
if (timing) {
|
|
517
|
-
timing.nextMethodStartTime = performance.now();
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
endMethodTiming(operationId, methodPath) {
|
|
521
|
-
const endTime = performance.now();
|
|
522
|
-
const key = `${operationId}:${methodPath}`;
|
|
523
|
-
const timing = this.methodTimings.get(key);
|
|
524
|
-
if (!timing) {
|
|
525
|
-
return {
|
|
526
|
-
startTime: endTime
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
const duration = endTime - timing.startTime;
|
|
530
|
-
const timeToNextCall = timing.nextMethodStartTime ? timing.nextMethodStartTime - timing.startTime : undefined;
|
|
531
|
-
// Clean up
|
|
532
|
-
this.methodTimings.delete(key);
|
|
533
|
-
return {
|
|
534
|
-
startTime: timing.startTime,
|
|
535
|
-
endTime,
|
|
536
|
-
duration,
|
|
537
|
-
nextMethodStartTime: timing.nextMethodStartTime,
|
|
538
|
-
timeToNextCall
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
formatDuration(milliseconds) {
|
|
542
|
-
if (milliseconds < 1) {
|
|
543
|
-
return `${(milliseconds * 1000).toFixed(1)}μs`;
|
|
544
|
-
} else if (milliseconds < 1000) {
|
|
545
|
-
return `${milliseconds.toFixed(2)}ms`;
|
|
546
|
-
} else {
|
|
547
|
-
return `${(milliseconds / 1000).toFixed(2)}s`;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
getDeltaFromOperationStart(operationId, currentTime) {
|
|
551
|
-
const operationStartTime = this.operationStartTimes.get(operationId);
|
|
552
|
-
return operationStartTime ? currentTime - operationStartTime : 0;
|
|
553
|
-
}
|
|
554
|
-
cleanupOperation(operationId) {
|
|
555
|
-
this.operationStartTimes.delete(operationId);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
// EXTERNAL MODULE: ./src/utilities/uuid.ts
|
|
560
|
-
var uuid = __webpack_require__(618);
|
|
561
|
-
;// CONCATENATED MODULE: ./src/capabilities/tracing/CallTraceManager.ts
|
|
562
|
-
|
|
563
|
-
class CallTraceManager {
|
|
564
|
-
activeOperationId = null;
|
|
565
|
-
activeCallStack = [];
|
|
566
|
-
startNewOperation() {
|
|
567
|
-
const operationId = (0,uuid/* .uuid */.u)(8);
|
|
568
|
-
this.activeOperationId = operationId;
|
|
569
|
-
this.activeCallStack = [];
|
|
570
|
-
return operationId;
|
|
571
|
-
}
|
|
572
|
-
isNewOperation() {
|
|
573
|
-
return this.activeOperationId === null;
|
|
574
|
-
}
|
|
575
|
-
getActiveOperationId() {
|
|
576
|
-
if (!this.activeOperationId) {
|
|
577
|
-
throw new Error('No active operation context');
|
|
578
|
-
}
|
|
579
|
-
return this.activeOperationId;
|
|
580
|
-
}
|
|
581
|
-
addMethodToTrace(methodPath) {
|
|
582
|
-
if (this.isNewOperation()) {
|
|
583
|
-
this.activeCallStack = [
|
|
584
|
-
methodPath
|
|
585
|
-
];
|
|
586
|
-
} else {
|
|
587
|
-
this.activeCallStack.push(methodPath);
|
|
588
|
-
}
|
|
589
|
-
return [
|
|
590
|
-
...this.activeCallStack
|
|
591
|
-
];
|
|
592
|
-
}
|
|
593
|
-
removeMethodFromTrace() {
|
|
594
|
-
if (!this.isNewOperation()) {
|
|
595
|
-
this.activeCallStack.pop();
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
endOperation() {
|
|
599
|
-
this.activeOperationId = null;
|
|
600
|
-
this.activeCallStack = [];
|
|
601
|
-
}
|
|
602
|
-
formatMethodPaths(methodPaths) {
|
|
603
|
-
return methodPaths.map((path)=>path.replace(/ → /g, '.'));
|
|
604
|
-
}
|
|
605
|
-
getCurrentTrace() {
|
|
606
|
-
return [
|
|
607
|
-
...this.activeCallStack
|
|
608
|
-
];
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
// EXTERNAL MODULE: ./src/utilities/logger.ts
|
|
613
|
-
var logger = __webpack_require__(581);
|
|
614
|
-
;// CONCATENATED MODULE: ./src/capabilities/PerformanceCapability.ts
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
class PerformanceCapability extends Capability {
|
|
621
|
-
callTraceManager;
|
|
622
|
-
performanceTracker;
|
|
623
|
-
filter;
|
|
624
|
-
childDurations = new Map();
|
|
625
|
-
constructor(options){
|
|
626
|
-
super();
|
|
627
|
-
this.filter = options?.filter ?? (()=>true);
|
|
628
|
-
this.callTraceManager = new CallTraceManager();
|
|
629
|
-
this.performanceTracker = new PerformanceTracker();
|
|
630
|
-
}
|
|
631
|
-
apply(instance) {
|
|
632
|
-
this.explore(instance, (meta, info)=>{
|
|
633
|
-
if (info.isCallable) {
|
|
634
|
-
const originalMethod = meta.instance[info.name].bind(meta.instance);
|
|
635
|
-
meta.instance[info.name] = (...args)=>{
|
|
636
|
-
const path = `${meta.path}.${String(info.name)}()`;
|
|
637
|
-
if (this.filter(path, info, meta) === false) {
|
|
638
|
-
return originalMethod(...args);
|
|
639
|
-
}
|
|
640
|
-
const isNewOperation = this.callTraceManager.isNewOperation();
|
|
641
|
-
let operationId;
|
|
642
|
-
let callTrace;
|
|
643
|
-
let depth;
|
|
644
|
-
if (isNewOperation) {
|
|
645
|
-
operationId = this.callTraceManager.startNewOperation();
|
|
646
|
-
this.childDurations.set(operationId, []);
|
|
647
|
-
callTrace = this.callTraceManager.addMethodToTrace(path);
|
|
648
|
-
depth = callTrace.length - 1;
|
|
649
|
-
const formattedCallTrace = this.callTraceManager.formatMethodPaths(callTrace);
|
|
650
|
-
this.performanceTracker.startMethodTiming(operationId, path);
|
|
651
|
-
logger/* .logger.log */.vF.log(`\n${'═'.repeat(60)}`);
|
|
652
|
-
logger/* .logger.log */.vF.log(`▶ ORIGIN [${operationId}] ${path}`);
|
|
653
|
-
if (args.length > 0) {
|
|
654
|
-
logger/* .logger.log */.vF.log(` Args:`, (0,strings/* .stringifyObject */.Zm)(args, 4, 0));
|
|
655
|
-
}
|
|
656
|
-
logger/* .logger.log */.vF.log(` Call Stack: ${formattedCallTrace.join(' → ')}`);
|
|
657
|
-
} else {
|
|
658
|
-
operationId = this.callTraceManager.getActiveOperationId();
|
|
659
|
-
callTrace = this.callTraceManager.addMethodToTrace(path);
|
|
660
|
-
depth = callTrace.length - 1;
|
|
661
|
-
const indent = ' '.repeat(Math.min(depth, 4));
|
|
662
|
-
// Track children for this child method too
|
|
663
|
-
const childMethodKey = `${operationId}:${path}`;
|
|
664
|
-
this.childDurations.set(childMethodKey, []);
|
|
665
|
-
this.performanceTracker.startMethodTiming(operationId, path);
|
|
666
|
-
logger/* .logger.log */.vF.log(`${indent}└─ CHILD [${operationId}] ${path}`);
|
|
667
|
-
if (args.length > 0) {
|
|
668
|
-
logger/* .logger.log */.vF.log(`${indent} Args:`, (0,strings/* .stringifyObject */.Zm)(args, 4, 0));
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
try {
|
|
672
|
-
return originalMethod(...args);
|
|
673
|
-
} finally{
|
|
674
|
-
const metrics = this.performanceTracker.endMethodTiming(operationId, path);
|
|
675
|
-
const duration = metrics.duration ?? 0;
|
|
676
|
-
const formattedDuration = this.performanceTracker.formatDuration(duration);
|
|
677
|
-
if (isNewOperation) {
|
|
678
|
-
const childDurations = this.childDurations.get(operationId) ?? [];
|
|
679
|
-
const totalChildTime = childDurations.reduce((sum, d)=>sum + d, 0);
|
|
680
|
-
const formattedTotalChildTime = this.performanceTracker.formatDuration(totalChildTime);
|
|
681
|
-
const overhead = duration - totalChildTime;
|
|
682
|
-
const formattedOverhead = this.performanceTracker.formatDuration(Math.max(0, overhead));
|
|
683
|
-
logger/* .logger.log */.vF.log(`\n${'═'.repeat(60)}`);
|
|
684
|
-
logger/* .logger.log */.vF.log(`◀ COMPLETE [${operationId}] ${path}`);
|
|
685
|
-
logger/* .logger.log */.vF.log(` Total Duration: ${formattedDuration}`);
|
|
686
|
-
if (childDurations.length > 0) {
|
|
687
|
-
logger/* .logger.log */.vF.log(` Children Duration: ${formattedTotalChildTime} (${childDurations.length} calls)`);
|
|
688
|
-
logger/* .logger.log */.vF.log(` Overhead: ${formattedOverhead}`);
|
|
689
|
-
}
|
|
690
|
-
logger/* .logger.log */.vF.log(`${'═'.repeat(60)}\n`);
|
|
691
|
-
this.childDurations.delete(operationId);
|
|
692
|
-
this.performanceTracker.cleanupOperation(operationId);
|
|
693
|
-
this.callTraceManager.endOperation();
|
|
694
|
-
} else {
|
|
695
|
-
const indent = ' '.repeat(Math.min(depth, 4));
|
|
696
|
-
const childMethodKey = `${operationId}:${path}`;
|
|
697
|
-
const childDurations = this.childDurations.get(childMethodKey) ?? [];
|
|
698
|
-
const totalChildTime = childDurations.reduce((sum, d)=>sum + d, 0);
|
|
699
|
-
const formattedTotalChildTime = this.performanceTracker.formatDuration(totalChildTime);
|
|
700
|
-
const overhead = duration - totalChildTime;
|
|
701
|
-
const formattedOverhead = this.performanceTracker.formatDuration(Math.max(0, overhead));
|
|
702
|
-
logger/* .logger.log */.vF.log(`${indent} ✓ ${formattedDuration}`);
|
|
703
|
-
if (childDurations.length > 0) {
|
|
704
|
-
logger/* .logger.log */.vF.log(`${indent} Children: ${formattedTotalChildTime} (${childDurations.length} calls), Overhead: ${formattedOverhead}`);
|
|
705
|
-
}
|
|
706
|
-
// Clean up child method tracking
|
|
707
|
-
this.childDurations.delete(childMethodKey);
|
|
708
|
-
// Find the parent method and add this duration to its children list
|
|
709
|
-
// The parent is the method one level up in the call trace
|
|
710
|
-
const currentTrace = this.callTraceManager.getCurrentTrace();
|
|
711
|
-
if (currentTrace.length > 1) {
|
|
712
|
-
// Parent is the second-to-last item in the trace (before we remove current)
|
|
713
|
-
const parentPath = currentTrace[currentTrace.length - 2];
|
|
714
|
-
// Check if parent is the root operation (trace length 2 means root + this child)
|
|
715
|
-
if (currentTrace.length === 2) {
|
|
716
|
-
// Direct child of root - add to root's children list
|
|
717
|
-
const rootChildDurations = this.childDurations.get(operationId);
|
|
718
|
-
if (rootChildDurations) {
|
|
719
|
-
rootChildDurations.push(duration);
|
|
720
|
-
}
|
|
721
|
-
} else {
|
|
722
|
-
// Nested child - add to parent method's children list
|
|
723
|
-
const parentMethodKey = `${operationId}:${parentPath}`;
|
|
724
|
-
const parentChildDurations = this.childDurations.get(parentMethodKey);
|
|
725
|
-
if (parentChildDurations) {
|
|
726
|
-
parentChildDurations.push(duration);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
this.callTraceManager.removeMethodFromTrace();
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
;// CONCATENATED MODULE: ./src/capabilities/TracingCapability.ts
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
class TracingCapability extends Capability {
|
|
744
|
-
callTraceManager;
|
|
745
|
-
filter;
|
|
746
|
-
constructor(options){
|
|
747
|
-
super();
|
|
748
|
-
this.filter = options?.filter ?? (()=>true);
|
|
749
|
-
this.callTraceManager = new CallTraceManager();
|
|
750
|
-
}
|
|
751
|
-
apply(instance) {
|
|
752
|
-
this.explore(instance, (meta, info)=>{
|
|
753
|
-
if (info.isCallable) {
|
|
754
|
-
const originalMethod = meta.instance[info.name].bind(meta.instance);
|
|
755
|
-
meta.instance[info.name] = (...args)=>{
|
|
756
|
-
const path = `${meta.path}.${String(info.name)}()`;
|
|
757
|
-
if (this.filter(path, info, meta) === false) {
|
|
758
|
-
return originalMethod(...args);
|
|
759
|
-
}
|
|
760
|
-
const isNewOperation = this.callTraceManager.isNewOperation();
|
|
761
|
-
let operationId;
|
|
762
|
-
if (isNewOperation) {
|
|
763
|
-
operationId = this.callTraceManager.startNewOperation();
|
|
764
|
-
const callTrace = this.callTraceManager.addMethodToTrace(path);
|
|
765
|
-
const formattedCallTrace = this.callTraceManager.formatMethodPaths(callTrace);
|
|
766
|
-
console.log(`\n${'═'.repeat(60)}`);
|
|
767
|
-
console.log(`▶ ORIGIN [${operationId}] ${path}`);
|
|
768
|
-
if (args.length > 0) {
|
|
769
|
-
console.log(` Args:`, (0,strings/* .stringifyObject */.Zm)(args, 4, 0));
|
|
770
|
-
}
|
|
771
|
-
console.log(` Call Stack: ${formattedCallTrace.join(' → ')}`);
|
|
772
|
-
} else {
|
|
773
|
-
operationId = this.callTraceManager.getActiveOperationId();
|
|
774
|
-
const callTrace = this.callTraceManager.addMethodToTrace(path);
|
|
775
|
-
const indent = ' '.repeat(Math.min(callTrace.length - 1, 4));
|
|
776
|
-
console.log(`${indent}└─ CHILD [${operationId}] ${path}`);
|
|
777
|
-
if (args.length > 0) {
|
|
778
|
-
console.log(`${indent} Args:`, (0,strings/* .stringifyObject */.Zm)(args, 4, 0));
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
try {
|
|
782
|
-
return originalMethod(...args);
|
|
783
|
-
} finally{
|
|
784
|
-
this.callTraceManager.removeMethodFromTrace();
|
|
785
|
-
if (isNewOperation) {
|
|
786
|
-
this.callTraceManager.endOperation();
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
;// CONCATENATED MODULE: ./src/capabilities/index.ts
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
})();
|
|
802
|
-
|
|
803
|
-
var __webpack_exports__Capability = __webpack_exports__.nS;
|
|
804
|
-
var __webpack_exports__PerformanceCapability = __webpack_exports__.VP;
|
|
805
|
-
var __webpack_exports__TracingCapability = __webpack_exports__.XO;
|
|
806
|
-
export { __webpack_exports__Capability as Capability, __webpack_exports__PerformanceCapability as PerformanceCapability, __webpack_exports__TracingCapability as TracingCapability };
|
|
807
|
-
|
|
808
|
-
//# sourceMappingURL=index.js.map
|