@coherent.js/fastify 1.0.0-beta.3 → 1.0.0-beta.5
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 +18 -0
- package/dist/index.cjs +10 -120
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +10 -110
- package/dist/index.js.map +4 -4
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// ../core/src/core/object-utils.js
|
|
2
|
-
function validateComponent(component,
|
|
2
|
+
function validateComponent(component, path = "root") {
|
|
3
3
|
if (component === null || component === void 0) {
|
|
4
|
-
throw new Error(`Invalid component at ${
|
|
4
|
+
throw new Error(`Invalid component at ${path}: null or undefined`);
|
|
5
5
|
}
|
|
6
6
|
if (["string", "number", "boolean"].includes(typeof component)) {
|
|
7
7
|
return true;
|
|
@@ -11,31 +11,31 @@ function validateComponent(component, path2 = "root") {
|
|
|
11
11
|
}
|
|
12
12
|
if (Array.isArray(component)) {
|
|
13
13
|
component.forEach((child, index) => {
|
|
14
|
-
validateComponent(child, `${
|
|
14
|
+
validateComponent(child, `${path}[${index}]`);
|
|
15
15
|
});
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
18
|
if (typeof component === "object") {
|
|
19
19
|
const keys = Object.keys(component);
|
|
20
20
|
if (keys.length === 0) {
|
|
21
|
-
throw new Error(`Empty object at ${
|
|
21
|
+
throw new Error(`Empty object at ${path}`);
|
|
22
22
|
}
|
|
23
23
|
keys.forEach((key) => {
|
|
24
24
|
const value = component[key];
|
|
25
25
|
if (!/^[a-zA-Z][a-zA-Z0-9-]*$/.test(key) && key !== "text") {
|
|
26
|
-
console.warn(`Potentially invalid tag name at ${
|
|
26
|
+
console.warn(`Potentially invalid tag name at ${path}: ${key}`);
|
|
27
27
|
}
|
|
28
28
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
29
29
|
if (value.children) {
|
|
30
|
-
validateComponent(value.children, `${
|
|
30
|
+
validateComponent(value.children, `${path}.${key}.children`);
|
|
31
31
|
}
|
|
32
32
|
} else if (value && typeof value !== "string" && typeof value !== "number" && typeof value !== "function") {
|
|
33
|
-
throw new Error(`Invalid value type at ${
|
|
33
|
+
throw new Error(`Invalid value type at ${path}.${key}: ${typeof value}`);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
return true;
|
|
37
37
|
}
|
|
38
|
-
throw new Error(`Invalid component type at ${
|
|
38
|
+
throw new Error(`Invalid component type at ${path}: ${typeof component}`);
|
|
39
39
|
}
|
|
40
40
|
function isCoherentObject(obj) {
|
|
41
41
|
if (!obj || typeof obj !== "object" || Array.isArray(obj)) {
|
|
@@ -117,6 +117,7 @@ function createPerformanceMonitor(options = {}) {
|
|
|
117
117
|
},
|
|
118
118
|
alerts: {
|
|
119
119
|
enabled: true,
|
|
120
|
+
debounceMs: 5e3,
|
|
120
121
|
rules: []
|
|
121
122
|
},
|
|
122
123
|
resources: {
|
|
@@ -278,7 +279,7 @@ function createPerformanceMonitor(options = {}) {
|
|
|
278
279
|
const alertKey = `${rule.metric}-${rule.condition}-${rule.threshold}`;
|
|
279
280
|
const lastTriggered = alertState.triggered.get(alertKey);
|
|
280
281
|
const now = Date.now();
|
|
281
|
-
if (!lastTriggered || now - lastTriggered >
|
|
282
|
+
if (!lastTriggered || now - lastTriggered > opts.alerts.debounceMs) {
|
|
282
283
|
alertState.triggered.set(alertKey, now);
|
|
283
284
|
alertState.history.push({
|
|
284
285
|
rule,
|
|
@@ -1260,107 +1261,6 @@ function createCacheManager(options = {}) {
|
|
|
1260
1261
|
}
|
|
1261
1262
|
var cacheManager = createCacheManager();
|
|
1262
1263
|
|
|
1263
|
-
// ../core/src/rendering/css-manager.js
|
|
1264
|
-
import fs from "node:fs/promises";
|
|
1265
|
-
import path from "node:path";
|
|
1266
|
-
var CSSManager = class {
|
|
1267
|
-
constructor(options = {}) {
|
|
1268
|
-
this.options = {
|
|
1269
|
-
basePath: process.cwd(),
|
|
1270
|
-
minify: false,
|
|
1271
|
-
cache: true,
|
|
1272
|
-
autoprefixer: false,
|
|
1273
|
-
...options
|
|
1274
|
-
};
|
|
1275
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
1276
|
-
this.loadedFiles = /* @__PURE__ */ new Set();
|
|
1277
|
-
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Load CSS file content
|
|
1280
|
-
*/
|
|
1281
|
-
async loadCSSFile(filePath) {
|
|
1282
|
-
const fullPath = path.resolve(this.options.basePath, filePath);
|
|
1283
|
-
const cacheKey = fullPath;
|
|
1284
|
-
if (this.options.cache && this.cache.has(cacheKey)) {
|
|
1285
|
-
return this.cache.get(cacheKey);
|
|
1286
|
-
}
|
|
1287
|
-
try {
|
|
1288
|
-
let content = await fs.readFile(fullPath, "utf8");
|
|
1289
|
-
if (this.options.minify) {
|
|
1290
|
-
content = this.minifyCSS(content);
|
|
1291
|
-
}
|
|
1292
|
-
if (this.options.cache) {
|
|
1293
|
-
this.cache.set(cacheKey, content);
|
|
1294
|
-
}
|
|
1295
|
-
this.loadedFiles.add(filePath);
|
|
1296
|
-
return content;
|
|
1297
|
-
} catch (_error) {
|
|
1298
|
-
console.warn(`Failed to load CSS file: ${filePath}`, _error.message);
|
|
1299
|
-
return "";
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Load multiple CSS files
|
|
1304
|
-
*/
|
|
1305
|
-
async loadCSSFiles(filePaths) {
|
|
1306
|
-
if (!Array.isArray(filePaths)) {
|
|
1307
|
-
filePaths = [filePaths];
|
|
1308
|
-
}
|
|
1309
|
-
const cssContents = await Promise.all(
|
|
1310
|
-
filePaths.map((filePath) => this.loadCSSFile(filePath))
|
|
1311
|
-
);
|
|
1312
|
-
return cssContents.join("\n");
|
|
1313
|
-
}
|
|
1314
|
-
/**
|
|
1315
|
-
* Generate CSS link tags for external files
|
|
1316
|
-
*/
|
|
1317
|
-
generateCSSLinks(filePaths, baseUrl = "/") {
|
|
1318
|
-
if (!Array.isArray(filePaths)) {
|
|
1319
|
-
filePaths = [filePaths];
|
|
1320
|
-
}
|
|
1321
|
-
return filePaths.map((filePath) => {
|
|
1322
|
-
const href = filePath.startsWith("http") ? filePath : `${baseUrl}${filePath}`.replace(/\/+/g, "/");
|
|
1323
|
-
return `<link rel="stylesheet" href="${this.escapeHtml(href)}" />`;
|
|
1324
|
-
}).join("\n");
|
|
1325
|
-
}
|
|
1326
|
-
/**
|
|
1327
|
-
* Generate inline style tag with CSS content
|
|
1328
|
-
*/
|
|
1329
|
-
generateInlineStyles(cssContent) {
|
|
1330
|
-
if (!cssContent) return "";
|
|
1331
|
-
return `<style type="text/css">
|
|
1332
|
-
${cssContent}
|
|
1333
|
-
</style>`;
|
|
1334
|
-
}
|
|
1335
|
-
/**
|
|
1336
|
-
* Basic CSS minification
|
|
1337
|
-
*/
|
|
1338
|
-
minifyCSS(css) {
|
|
1339
|
-
return css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s+/g, " ").replace(/;\s*}/g, "}").replace(/{\s+/g, "{").replace(/;\s+/g, ";").trim();
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Escape HTML entities
|
|
1343
|
-
*/
|
|
1344
|
-
escapeHtml(text) {
|
|
1345
|
-
const div = { textContent: text };
|
|
1346
|
-
return div.innerHTML || text;
|
|
1347
|
-
}
|
|
1348
|
-
/**
|
|
1349
|
-
* Clear cache
|
|
1350
|
-
*/
|
|
1351
|
-
clearCache() {
|
|
1352
|
-
this.cache.clear();
|
|
1353
|
-
this.loadedFiles.clear();
|
|
1354
|
-
}
|
|
1355
|
-
/**
|
|
1356
|
-
* Get loaded file list
|
|
1357
|
-
*/
|
|
1358
|
-
getLoadedFiles() {
|
|
1359
|
-
return Array.from(this.loadedFiles);
|
|
1360
|
-
}
|
|
1361
|
-
};
|
|
1362
|
-
var defaultCSSManager = new CSSManager();
|
|
1363
|
-
|
|
1364
1264
|
// ../core/src/rendering/html-renderer.js
|
|
1365
1265
|
var rendererCache = createCacheManager({
|
|
1366
1266
|
maxSize: 1e3,
|