@e-mc/document 0.12.5 → 0.12.6

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.
Files changed (3) hide show
  1. package/README.md +9 -9
  2. package/index.js +15 -9
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.5/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.6/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, ViewEngine } from "./squared";
@@ -185,14 +185,14 @@ NOTE: **@e-mc/document** is an abstract base class and cannot be instantiated. *
185
185
 
186
186
  ## References
187
187
 
188
- - https://www.unpkg.com/@e-mc/types@0.12.5/lib/squared.d.ts
189
- - https://www.unpkg.com/@e-mc/types@0.12.5/lib/asset.d.ts
190
- - https://www.unpkg.com/@e-mc/types@0.12.5/lib/core.d.ts
191
- - https://www.unpkg.com/@e-mc/types@0.12.5/lib/document.d.ts
192
- - https://www.unpkg.com/@e-mc/types@0.12.5/lib/filemanager.d.ts
193
- - https://www.unpkg.com/@e-mc/types@0.12.5/lib/logger.d.ts
194
- - https://www.unpkg.com/@e-mc/types@0.12.5/lib/settings.d.ts
195
- - https://www.unpkg.com/@e-mc/types@0.12.5/lib/watch.d.ts
188
+ - https://www.unpkg.com/@e-mc/types@0.12.6/lib/squared.d.ts
189
+ - https://www.unpkg.com/@e-mc/types@0.12.6/lib/asset.d.ts
190
+ - https://www.unpkg.com/@e-mc/types@0.12.6/lib/core.d.ts
191
+ - https://www.unpkg.com/@e-mc/types@0.12.6/lib/document.d.ts
192
+ - https://www.unpkg.com/@e-mc/types@0.12.6/lib/filemanager.d.ts
193
+ - https://www.unpkg.com/@e-mc/types@0.12.6/lib/logger.d.ts
194
+ - https://www.unpkg.com/@e-mc/types@0.12.6/lib/settings.d.ts
195
+ - https://www.unpkg.com/@e-mc/types@0.12.6/lib/watch.d.ts
196
196
 
197
197
  ## LICENSE
198
198
 
package/index.js CHANGED
@@ -14,6 +14,7 @@ const util_1 = require("@e-mc/document/util");
14
14
  const kDocument = Symbol.for('document:constructor');
15
15
  const CACHE_PACKAGE = {};
16
16
  const CACHE_TEMPLATE = {};
17
+ const CACHE_VIEWENGINE = new Map();
17
18
  const CACHE_EXTERNAL = {};
18
19
  const CACHE_ETAG = {};
19
20
  const CACHE_CODE = {};
@@ -47,7 +48,7 @@ function getConfigObject(instance, data, name, target, cache) {
47
48
  return (0, types_1.cloneObject)(data[name] = target, true);
48
49
  }
49
50
  function errorConfig(instance, ...message) {
50
- instance.addLog(types_1.STATUS_TYPE.ERROR, joinString('config', ...message));
51
+ instance.addLog(2, joinString('config', ...message));
51
52
  }
52
53
  const isExcluded = (type, name, config, cacheData) => !(config?.hasType(type, name) || cacheData?.override === true);
53
54
  const wrapCount = (value) => chalk.grey('(') + value + chalk.grey(')');
@@ -354,6 +355,7 @@ class Document extends core_1.Client {
354
355
  delete cache[name];
355
356
  }
356
357
  }
358
+ CACHE_VIEWENGINE.clear();
357
359
  CACHE_PICOMATCH.clear();
358
360
  CACHE_TOTAL = 0;
359
361
  }
@@ -572,7 +574,7 @@ class Document extends core_1.Client {
572
574
  if (fatal) {
573
575
  ++fatalErrorCount;
574
576
  }
575
- const [type, errorColor] = error === true ? [types_1.STATUS_TYPE.ERROR, 'red'] : error === false ? [types_1.STATUS_TYPE.WARN, 'yellow'] : [types_1.STATUS_TYPE.INFO, 'white'];
577
+ const [type, errorColor] = error === true ? [2, 'red'] : error === false ? [3, 'yellow'] : [4, 'white'];
576
578
  maxWidth = Math.max(1 + 0 + 1 + 0 + 1 + 2 + Math.min(Math.max(ruleId.length, ruleWidth), ruleWidth) + 2 + Math.min(Math.max(message.length, messageWidth), messageWidth), maxWidth);
577
579
  result.push({
578
580
  type,
@@ -582,13 +584,13 @@ class Document extends core_1.Client {
582
584
  }
583
585
  maxWidth += maxLine + maxColumn;
584
586
  const title = (leadingText || '') + (pathname || filename ? (leadingText ? ': ' : '') + (pathname && filename ? path.join(pathname, filename) : pathname || filename) : '');
585
- const divider = { type: types_1.STATUS_TYPE.INFO, value: '-'.repeat(maxWidth), timeStamp };
587
+ const divider = { type: 4, value: '-'.repeat(maxWidth), timeStamp };
586
588
  errorCount = ((Array.isArray(options.errorCount) ? (fixableErrorCount = options.errorCount[1], options.errorCount[0]) : options.errorCount) ?? errorCount).toString();
587
589
  warningCount = ((Array.isArray(options.warningCount) ? (fixableWarningCount = options.warningCount[1], options.warningCount[0]) : options.warningCount) ?? warningCount).toString();
588
590
  fatalErrorCount = (options.fatalErrorCount ?? fatalErrorCount).toString();
589
591
  const hasFatal = fatalErrorCount !== '0';
590
592
  result.unshift(divider, {
591
- type: types_1.STATUS_TYPE.INFO,
593
+ type: 4,
592
594
  value: title + ' '.repeat(maxWidth - title.length - (hasFatal ? fatalErrorCount.length + 9 : 0)) + (hasFatal ? `fatal(${chalk.bold.bgRed.white(` ${fatalErrorCount} `)})` : ''),
593
595
  timeStamp,
594
596
  duration: currentTime - timeStamp
@@ -598,7 +600,7 @@ class Document extends core_1.Client {
598
600
  const errorHint = fixHint(fixableWarningCount, fixableErrorCount, fixableErrorCount);
599
601
  const warningHint = fixHint(fixableWarningCount, fixableErrorCount, fixableWarningCount);
600
602
  result.push({
601
- type: types_1.STATUS_TYPE.INFO,
603
+ type: 4,
602
604
  value: chalk.bold.red('error') + wrapCount(errorCount + errorHint) + ' / ' + chalk.bold.yellow('warning') + wrapCount(warningCount + warningHint) + ' '.repeat(maxWidth - trailingText.length - (7 + errorCount.length + errorHint.length + 3 + warningCount.length + warningHint.length + 9)) + trailingText,
603
605
  timeStamp
604
606
  });
@@ -1087,8 +1089,12 @@ class Document extends core_1.Client {
1087
1089
  target = this.settings.view_engine?.[viewEngine];
1088
1090
  const userConfig = this.getUserSettings()?.view_engine?.[viewEngine];
1089
1091
  if ((0, types_1.isPlainObject)(userConfig)) {
1090
- if ((0, types_1.isPlainObject)(target)) {
1091
- (0, types_1.cloneObject)(userConfig, { target, deep: true, preserve: true });
1092
+ if (CACHE_VIEWENGINE.has(userConfig)) {
1093
+ target = CACHE_VIEWENGINE.get(userConfig);
1094
+ }
1095
+ else if ((0, types_1.isPlainObject)(target)) {
1096
+ target = (0, types_1.cloneObject)(userConfig, { target: { ...target }, deep: true, preserve: true, structured: true });
1097
+ CACHE_VIEWENGINE.set(userConfig, target);
1092
1098
  }
1093
1099
  else {
1094
1100
  target = userConfig;
@@ -1099,7 +1105,7 @@ class Document extends core_1.Client {
1099
1105
  else {
1100
1106
  target = viewEngine;
1101
1107
  }
1102
- if (!(0, types_1.isPlainObject)(target) || !(0, types_1.isString)(target.name)) {
1108
+ if (!((0, types_1.isPlainObject)(target) && (0, types_1.isString)(target.name))) {
1103
1109
  this.abort('view_engine');
1104
1110
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
1105
1111
  this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
@@ -1166,7 +1172,7 @@ class Document extends core_1.Client {
1166
1172
  }
1167
1173
  }
1168
1174
  else if (!(0, types_1.isObject)(row)) {
1169
- this.addLog(types_1.STATUS_TYPE.WARN, joinString('view engine', target.name, core_1.Client.asString(row) || "Unknown"), { source: `row #${i + 1}` });
1175
+ this.addLog(3, joinString('view engine', target.name, core_1.Client.asString(row) || "Unknown"), { source: `row #${i + 1}` });
1170
1176
  continue;
1171
1177
  }
1172
1178
  if (!singleRow) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.12.5",
3
+ "version": "0.12.6",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,9 +19,9 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/core": "0.12.5",
23
- "@e-mc/db": "0.12.5",
24
- "@e-mc/types": "0.12.5",
22
+ "@e-mc/core": "0.12.6",
23
+ "@e-mc/db": "0.12.6",
24
+ "@e-mc/types": "0.12.6",
25
25
  "chalk": "4.1.2",
26
26
  "domhandler": "^5.0.3",
27
27
  "domutils": "^3.2.2",