@coherent.js/koa 1.0.0-beta.2 → 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/dist/index.js CHANGED
@@ -13,9 +13,9 @@ Or with yarn: yarn add ${packageName}`
13
13
  }
14
14
 
15
15
  // ../core/src/core/object-utils.js
16
- function validateComponent(component, path2 = "root") {
16
+ function validateComponent(component, path = "root") {
17
17
  if (component === null || component === void 0) {
18
- throw new Error(`Invalid component at ${path2}: null or undefined`);
18
+ throw new Error(`Invalid component at ${path}: null or undefined`);
19
19
  }
20
20
  if (["string", "number", "boolean"].includes(typeof component)) {
21
21
  return true;
@@ -25,31 +25,31 @@ function validateComponent(component, path2 = "root") {
25
25
  }
26
26
  if (Array.isArray(component)) {
27
27
  component.forEach((child, index) => {
28
- validateComponent(child, `${path2}[${index}]`);
28
+ validateComponent(child, `${path}[${index}]`);
29
29
  });
30
30
  return true;
31
31
  }
32
32
  if (typeof component === "object") {
33
33
  const keys = Object.keys(component);
34
34
  if (keys.length === 0) {
35
- throw new Error(`Empty object at ${path2}`);
35
+ throw new Error(`Empty object at ${path}`);
36
36
  }
37
37
  keys.forEach((key) => {
38
38
  const value = component[key];
39
39
  if (!/^[a-zA-Z][a-zA-Z0-9-]*$/.test(key) && key !== "text") {
40
- console.warn(`Potentially invalid tag name at ${path2}: ${key}`);
40
+ console.warn(`Potentially invalid tag name at ${path}: ${key}`);
41
41
  }
42
42
  if (value && typeof value === "object" && !Array.isArray(value)) {
43
43
  if (value.children) {
44
- validateComponent(value.children, `${path2}.${key}.children`);
44
+ validateComponent(value.children, `${path}.${key}.children`);
45
45
  }
46
46
  } else if (value && typeof value !== "string" && typeof value !== "number" && typeof value !== "function") {
47
- throw new Error(`Invalid value type at ${path2}.${key}: ${typeof value}`);
47
+ throw new Error(`Invalid value type at ${path}.${key}: ${typeof value}`);
48
48
  }
49
49
  });
50
50
  return true;
51
51
  }
52
- throw new Error(`Invalid component type at ${path2}: ${typeof component}`);
52
+ throw new Error(`Invalid component type at ${path}: ${typeof component}`);
53
53
  }
54
54
  function isCoherentObject(obj) {
55
55
  if (!obj || typeof obj !== "object" || Array.isArray(obj)) {
@@ -131,6 +131,7 @@ function createPerformanceMonitor(options = {}) {
131
131
  },
132
132
  alerts: {
133
133
  enabled: true,
134
+ debounceMs: 5e3,
134
135
  rules: []
135
136
  },
136
137
  resources: {
@@ -292,7 +293,7 @@ function createPerformanceMonitor(options = {}) {
292
293
  const alertKey = `${rule.metric}-${rule.condition}-${rule.threshold}`;
293
294
  const lastTriggered = alertState.triggered.get(alertKey);
294
295
  const now = Date.now();
295
- if (!lastTriggered || now - lastTriggered > 5e3) {
296
+ if (!lastTriggered || now - lastTriggered > opts.alerts.debounceMs) {
296
297
  alertState.triggered.set(alertKey, now);
297
298
  alertState.history.push({
298
299
  rule,
@@ -1274,107 +1275,6 @@ function createCacheManager(options = {}) {
1274
1275
  }
1275
1276
  var cacheManager = createCacheManager();
1276
1277
 
1277
- // ../core/src/rendering/css-manager.js
1278
- import fs from "node:fs/promises";
1279
- import path from "node:path";
1280
- var CSSManager = class {
1281
- constructor(options = {}) {
1282
- this.options = {
1283
- basePath: process.cwd(),
1284
- minify: false,
1285
- cache: true,
1286
- autoprefixer: false,
1287
- ...options
1288
- };
1289
- this.cache = /* @__PURE__ */ new Map();
1290
- this.loadedFiles = /* @__PURE__ */ new Set();
1291
- }
1292
- /**
1293
- * Load CSS file content
1294
- */
1295
- async loadCSSFile(filePath) {
1296
- const fullPath = path.resolve(this.options.basePath, filePath);
1297
- const cacheKey = fullPath;
1298
- if (this.options.cache && this.cache.has(cacheKey)) {
1299
- return this.cache.get(cacheKey);
1300
- }
1301
- try {
1302
- let content = await fs.readFile(fullPath, "utf8");
1303
- if (this.options.minify) {
1304
- content = this.minifyCSS(content);
1305
- }
1306
- if (this.options.cache) {
1307
- this.cache.set(cacheKey, content);
1308
- }
1309
- this.loadedFiles.add(filePath);
1310
- return content;
1311
- } catch (_error) {
1312
- console.warn(`Failed to load CSS file: ${filePath}`, _error.message);
1313
- return "";
1314
- }
1315
- }
1316
- /**
1317
- * Load multiple CSS files
1318
- */
1319
- async loadCSSFiles(filePaths) {
1320
- if (!Array.isArray(filePaths)) {
1321
- filePaths = [filePaths];
1322
- }
1323
- const cssContents = await Promise.all(
1324
- filePaths.map((filePath) => this.loadCSSFile(filePath))
1325
- );
1326
- return cssContents.join("\n");
1327
- }
1328
- /**
1329
- * Generate CSS link tags for external files
1330
- */
1331
- generateCSSLinks(filePaths, baseUrl = "/") {
1332
- if (!Array.isArray(filePaths)) {
1333
- filePaths = [filePaths];
1334
- }
1335
- return filePaths.map((filePath) => {
1336
- const href = filePath.startsWith("http") ? filePath : `${baseUrl}${filePath}`.replace(/\/+/g, "/");
1337
- return `<link rel="stylesheet" href="${this.escapeHtml(href)}" />`;
1338
- }).join("\n");
1339
- }
1340
- /**
1341
- * Generate inline style tag with CSS content
1342
- */
1343
- generateInlineStyles(cssContent) {
1344
- if (!cssContent) return "";
1345
- return `<style type="text/css">
1346
- ${cssContent}
1347
- </style>`;
1348
- }
1349
- /**
1350
- * Basic CSS minification
1351
- */
1352
- minifyCSS(css) {
1353
- return css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s+/g, " ").replace(/;\s*}/g, "}").replace(/{\s+/g, "{").replace(/;\s+/g, ";").trim();
1354
- }
1355
- /**
1356
- * Escape HTML entities
1357
- */
1358
- escapeHtml(text) {
1359
- const div = { textContent: text };
1360
- return div.innerHTML || text;
1361
- }
1362
- /**
1363
- * Clear cache
1364
- */
1365
- clearCache() {
1366
- this.cache.clear();
1367
- this.loadedFiles.clear();
1368
- }
1369
- /**
1370
- * Get loaded file list
1371
- */
1372
- getLoadedFiles() {
1373
- return Array.from(this.loadedFiles);
1374
- }
1375
- };
1376
- var defaultCSSManager = new CSSManager();
1377
-
1378
1278
  // ../core/src/rendering/html-renderer.js
1379
1279
  var rendererCache = createCacheManager({
1380
1280
  maxSize: 1e3,