@e-mc/document 0.8.10 → 0.9.1

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/LICENSE CHANGED
@@ -1,7 +1,11 @@
1
1
  Copyright 2024 An Pham
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
4
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
6
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @e-mc/document
2
2
 
3
- * NodeJS 14
4
- * ES2019
3
+ * NodeJS 16
4
+ * ES2020
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/index.d.ts
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.1/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, ViewEngine } from "./squared";
@@ -31,20 +31,22 @@ interface IDocument extends IClient<IFileManager, DocumentModule, TransformCallb
31
31
  customize(options?: CustomizeOptions): void;
32
32
  findConfig(data: object, name: string, type?: string): PluginConfig;
33
33
  loadConfig(data: object, name: string): ConfigOrTransformer | null | undefined;
34
- asSourceFile(value: string, options?: AsSourceFileOptions | boolean): unknown;
34
+ asSourceFile(value: string, cache: boolean): unknown;
35
+ asSourceFile(value: string, options?: AsSourceFileOptions): unknown;
35
36
  findVersion(name: string | string[], fallback?: string): string;
36
37
  findSourceScope(uri: string, imports: Record<string, unknown>): Record<string, string | undefined>[];
37
38
  findSourceRoot(uri: string, imports?: Record<string, string | undefined>): string | undefined;
38
39
  resolveDir(name: string, ...paths: string[]): string | undefined;
39
- locateSourceFiles(file: ExternalAsset, code?: string, bundleContent?: string[]): (imports?: Record<string, string | undefined>) => SourceInput | undefined;
40
- resolveSourceFile(file: ExternalAsset): (code?: string, imports?: Record<string, string | undefined>) => SourceInput<string> | undefined;
40
+ locateSourceFiles(file: ExternalAsset, code?: string, bundleContent?: string[]): ((imports?: Record<string, string | undefined>) => SourceInput | undefined);
41
+ resolveSourceFile(file: ExternalAsset): ((code?: string, imports?: Record<string, string | undefined>) => SourceInput<string> | undefined);
41
42
  tryParse(source: string, format: string, options?: Record<string | number | symbol, unknown>): unknown;
42
43
  forDb(item: DataSource): boolean;
43
44
  hasEval(name: string): boolean;
44
45
  settingsOf(name: keyof DocumentComponent, option: keyof DocumentComponentOption): unknown;
45
46
  parseTemplate(viewEngine: ViewEngine | string, template: string, data: unknown[]): Promise<string | null>;
46
47
  transform(type: string, code: string, format: string | string[], options?: TransformOutput & TransformAction): Promise<TransformResult | void>;
47
- abort(name?: keyof DocumentComponent | Error, reason?: unknown): void;
48
+ abort(err: Error): void;
49
+ abort(name?: keyof DocumentComponent, reason?: unknown): void;
48
50
  restart(): void;
49
51
  using?(data: IFileThread): Promise<unknown>;
50
52
  setLocalUri?(file: ExternalAsset, replace?: boolean): void;
@@ -72,10 +74,9 @@ interface DocumentConstructor extends ModuleConstructor {
72
74
  createSourceMap(code: string, remove: boolean): SourceMap;
73
75
  createSourceMap(code: string, uri?: string, remove?: boolean): SourceMap;
74
76
  writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): string | undefined;
75
- updateGradle(source: string, namespaces: string[], value: string, options?: UpdateGradleOptions | boolean): string;
77
+ updateGradle(source: string, namespaces: string[], value: string, upgrade: boolean): string;
78
+ updateGradle(source: string, namespaces: string[], value: string, options?: UpdateGradleOptions): string;
76
79
  generateLintTable(messages: LintMessage[], options: GenerateLintTableOptions): LogComponent[];
77
- /* @deprecated - IDocument.using */
78
- using?(this: IFileManager, instance: IDocument, file: ExternalAsset): Promise<unknown>;
79
80
  cleanup?(this: IFileManager, instance: IDocument): Promise<unknown>;
80
81
  sanitizeAssets?(assets: ExternalAsset[], exclusions?: ExternalAsset[]): ExternalAsset[];
81
82
  readonly prototype: IDocument;
@@ -83,17 +84,114 @@ interface DocumentConstructor extends ModuleConstructor {
83
84
  }
84
85
  ```
85
86
 
87
+ ## Settings
88
+
89
+ ```typescript
90
+ import type { PermittedDirectories } from "./core";
91
+ import type { DbModule, DbSettings, DocumentComponentOptions, PurgeComponent } from "./settings";
92
+
93
+ interface DocumentModule {
94
+ // handler: "@pi-r/chrome";
95
+ extensions?: string[];
96
+ db?: DbModule<DbSettings>;
97
+ eval?: {
98
+ function?: boolean;
99
+ absolute?: boolean;
100
+ template?: boolean;
101
+ userconfig?: boolean;
102
+ };
103
+ format?: {
104
+ uuid?: {
105
+ dictionary?: string;
106
+ pathname?: string;
107
+ filename?: string;
108
+ };
109
+ };
110
+ imports?: StringMap;
111
+ settings?: {
112
+ broadcast_id?: string | string[];
113
+ users?: Record<string, {
114
+ extensions?: string[] | null;
115
+ imports?: StringMap;
116
+ imports_strict?: boolean;
117
+ pages?: unknown;
118
+ transform?: unknown;
119
+ view_engine?: unknown;
120
+ }>;
121
+ cache_dir?: string;
122
+ imports_strict?: boolean;
123
+ directory?: {
124
+ template?: string;
125
+ data?: string;
126
+ export?: string;
127
+ schema?: string;
128
+ package?: string;
129
+ };
130
+ purge?: PurgeComponent;
131
+ options?: DocumentComponentOptions<boolean | number>;
132
+ pages?: Record<string, Record<string, unknown>>;
133
+ transform?: {
134
+ html?: Record<string, Record<string, unknown>>;
135
+ css?: Record<string, Record<string, unknown>>;
136
+ js?: Record<string, Record<string, unknown>>;
137
+ };
138
+ view_engine?: Record<string, Record<string, unknown>>;
139
+ export?: Record<string, string | (...args: unknown[]) => unknown>;
140
+ };
141
+ permission?: PermittedDirectories;
142
+ }
143
+ ```
144
+
145
+ ### Example usage
146
+
147
+ ```javascript
148
+ const Document = require("@e-mc/document"); // @pi-r/chrome
149
+
150
+ const assets = [
151
+ { pathname: "output", filename: "image1.png", uri: "http://hostname/path/document1.png" },
152
+ { pathname: "output", filename: "image2.png", uri: "http://hostname/path/document2.png" }
153
+ ];
154
+
155
+ const instance = new Document({
156
+ eval: {
157
+ function: true,
158
+ template: true
159
+ },
160
+ imports: {
161
+ "http://hostname/path/": "build/"
162
+ },
163
+ settings: {
164
+ imports_strict: true,
165
+ users: {
166
+ "nodejs-001": {
167
+ imports_strict: false,
168
+ imports: {
169
+ "http://hostname/path": "build"
170
+ }
171
+ }
172
+ },
173
+ directory: {
174
+ template: "../chrome/template" // ../chrome/template/users/nodejs-001
175
+ }
176
+ }
177
+ });
178
+ // instance.host = new Host();
179
+ instance.init(assets);
180
+ ```
181
+
182
+ NOTE: **@e-mc/document** is an abstract base class and cannot be instantiated. **Document** is more commonly called through [@pi-r/chrome](https://www.npmjs.com/package/@pi-r/chrome).
183
+
86
184
  ## References
87
185
 
88
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/squared.d.ts
89
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/asset.d.ts
90
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/core.d.ts
91
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/document.d.ts
92
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/filemanager.d.ts
93
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/logger.d.ts
94
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/settings.d.ts
95
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/watch.d.ts
186
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/squared.d.ts
187
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/asset.d.ts
188
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/core.d.ts
189
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/document.d.ts
190
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/filemanager.d.ts
191
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/logger.d.ts
192
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/settings.d.ts
193
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/watch.d.ts
96
194
 
97
195
  ## LICENSE
98
196
 
99
- MIT
197
+ BSD 3-Clause
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  const path = require("path");
4
3
  const fs = require("fs");
5
4
  const pm = require("picomatch");
@@ -34,6 +33,48 @@ function deleteTransform(map, key, timeout) {
34
33
  delete map[key];
35
34
  --CACHE_TOTAL;
36
35
  }
36
+ function resetTransform(config, map, key, stored) {
37
+ if (config.renew) {
38
+ if (stored.timeout) {
39
+ clearTimeout(stored.timeout);
40
+ }
41
+ stored.timeout = renewTransform(map, key, config.expires);
42
+ }
43
+ stored.lastAccessed = Date.now();
44
+ }
45
+ function getTransformData(stored, key, encoding) {
46
+ const location = stored.format[key];
47
+ if (typeof location === 'string') {
48
+ try {
49
+ return JSON.parse(fs.readFileSync(location, encoding));
50
+ }
51
+ catch {
52
+ fs.unlink(location, () => { });
53
+ return;
54
+ }
55
+ }
56
+ return location;
57
+ }
58
+ function setTransformData(type, cacheDir, data) {
59
+ let pathname;
60
+ if (typeof cacheDir === 'string' && core_1.Client.createDir(pathname = path.join(cacheDir, 'transform', type))) {
61
+ try {
62
+ fs.writeFileSync(pathname = path.join(pathname, (0, types_1.incrementUUID)()), JSON.stringify(data));
63
+ return pathname;
64
+ }
65
+ catch {
66
+ }
67
+ }
68
+ return data;
69
+ }
70
+ function hasTransformType(config, type, name, data) {
71
+ const include = config?.include[type];
72
+ if (include === true || include?.includes(name)) {
73
+ const exclude = config.exclude[type];
74
+ return !exclude || exclude === true && include !== true || Array.isArray(exclude) && !exclude.includes(name);
75
+ }
76
+ return data?.override === true;
77
+ }
37
78
  function getSourceMappingURL(value, css) {
38
79
  if (value.includes(' ')) {
39
80
  value = encodeURIComponent(value);
@@ -91,7 +132,7 @@ class Document extends core_1.Client {
91
132
  static async finalize(instance) {
92
133
  for (const ext of instance.extensions) {
93
134
  if (instance.aborted) {
94
- return Promise.reject((0, types_1.createAbortError)());
135
+ return (0, types_1.createAbortError)(true);
95
136
  }
96
137
  try {
97
138
  const args = [instance];
@@ -254,7 +295,6 @@ class Document extends core_1.Client {
254
295
  return lastIndex > 0 ? spliceSource(source, lastIndex, lastIndex, content) : source + newline + content;
255
296
  }
256
297
  static generateLintTable(messages, options) {
257
- var _a, _b, _c;
258
298
  const { leadingText, trailingText, pathname, filename, ruleWidth = 30, messageWidth = 60 } = options;
259
299
  const result = [];
260
300
  const truncate = (value, width) => value.length > width ? value.substring(0, width - 3) + '...' : value.padStart(width);
@@ -300,9 +340,9 @@ class Document extends core_1.Client {
300
340
  maxWidth += maxLine + maxColumn;
301
341
  const title = (leadingText || '') + (pathname || filename ? (leadingText ? ': ' : '') + (pathname && filename ? path.join(pathname, filename) : pathname || filename) : '');
302
342
  const divider = { type: types_1.STATUS_TYPE.INFO, value: '-'.repeat(maxWidth), timeStamp };
303
- errorCount = ((_a = options.errorCount) !== null && _a !== void 0 ? _a : errorCount).toString();
304
- warningCount = ((_b = options.warningCount) !== null && _b !== void 0 ? _b : warningCount).toString();
305
- fatalErrorCount = ((_c = options.fatalErrorCount) !== null && _c !== void 0 ? _c : fatalErrorCount).toString();
343
+ errorCount = (options.errorCount ?? errorCount).toString();
344
+ warningCount = (options.warningCount ?? warningCount).toString();
345
+ fatalErrorCount = (options.fatalErrorCount ?? fatalErrorCount).toString();
306
346
  const hasFatal = fatalErrorCount !== '0';
307
347
  result.unshift(divider, { type: types_1.STATUS_TYPE.INFO, value: title + ' '.repeat(maxWidth - title.length - (hasFatal ? fatalErrorCount.length + 9 : 0)) + (hasFatal ? `fatal(${chalk.bold.bgRed.white(` ${fatalErrorCount} `)})` : ''), timeStamp, duration: currentTime - timeStamp }, divider);
308
348
  result.push(divider);
@@ -315,7 +355,6 @@ class Document extends core_1.Client {
315
355
  constructor(data) {
316
356
  super(data);
317
357
  this.Db = null;
318
- this.config = {};
319
358
  this._assets = null;
320
359
  this._dataSource = null;
321
360
  this._transformConfig = null;
@@ -387,12 +426,12 @@ class Document extends core_1.Client {
387
426
  }
388
427
  }
389
428
  }
390
- if (this.dataSource.length && !(ignoreModules === null || ignoreModules === void 0 ? void 0 : ignoreModules.includes('db'))) {
429
+ if (this.dataSource.length && !ignoreModules?.includes('db')) {
391
430
  const db = (_a = this.module).db || (_a.db = {});
392
431
  const handler = db.handler;
393
432
  const database = this.dataSource.filter(this.forDb.bind(this));
394
433
  let instance;
395
- if ((0, types_1.isString)(handler) && handler !== "@e-mc/db") {
434
+ if (handler && handler !== "@e-mc/db") {
396
435
  try {
397
436
  const Handler = require(handler);
398
437
  if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
@@ -407,7 +446,7 @@ class Document extends core_1.Client {
407
446
  }
408
447
  }
409
448
  else {
410
- instance = new db_1.default(db, database);
449
+ instance = new db_1(db, database);
411
450
  }
412
451
  if (instance) {
413
452
  const host = this.host;
@@ -470,7 +509,7 @@ class Document extends core_1.Client {
470
509
  this._transformConfig = null;
471
510
  return;
472
511
  }
473
- switch (algorithm = algorithm === null || algorithm === void 0 ? void 0 : algorithm.toLowerCase()) {
512
+ switch (algorithm = algorithm?.toLowerCase()) {
474
513
  case 'md5':
475
514
  case 'sha1':
476
515
  case 'sha224':
@@ -588,12 +627,11 @@ class Document extends core_1.Client {
588
627
  delete data[name];
589
628
  }
590
629
  resolveDir(name, ...paths) {
591
- var _a, _b;
592
- let baseDir = (_a = this.settings.directory) === null || _a === void 0 ? void 0 : _a[name];
630
+ let baseDir = this.settings.directory?.[name];
593
631
  if (baseDir) {
594
632
  try {
595
633
  baseDir = path.resolve(baseDir);
596
- const username = (_b = this.host) === null || _b === void 0 ? void 0 : _b.username;
634
+ const username = this.host?.username;
597
635
  let result;
598
636
  if (username) {
599
637
  const leading = path.join(baseDir, 'users', username);
@@ -666,7 +704,6 @@ class Document extends core_1.Client {
666
704
  return null;
667
705
  }
668
706
  findVersion(name, fallback = '') {
669
- var _a;
670
707
  let result;
671
708
  const versions = this.module.versions;
672
709
  if (versions) {
@@ -678,7 +715,7 @@ class Document extends core_1.Client {
678
715
  }
679
716
  }
680
717
  else {
681
- result = (_a = this.module.versions) === null || _a === void 0 ? void 0 : _a[name];
718
+ result = this.module.versions?.[name];
682
719
  }
683
720
  }
684
721
  return result || fallback;
@@ -698,7 +735,6 @@ class Document extends core_1.Client {
698
735
  return [];
699
736
  }
700
737
  findSourceRoot(uri, imports = this.imports) {
701
- var _a, _b;
702
738
  if (!(0, types_1.isPlainObject)(imports)) {
703
739
  return;
704
740
  }
@@ -710,7 +746,7 @@ class Document extends core_1.Client {
710
746
  }
711
747
  return value.endsWith(sep) ? value : value + sep;
712
748
  };
713
- const importsStrict = (_b = (_a = this.getUserSettings()) === null || _a === void 0 ? void 0 : _a.imports_strict) !== null && _b !== void 0 ? _b : this.settings.imports_strict;
749
+ const importsStrict = this.getUserSettings()?.imports_strict ?? this.settings.imports_strict;
714
750
  const scopes = (importsStrict ? this.findSourceScope(uri, imports) : []).concat([imports]);
715
751
  const isDir = /[\\/]$/;
716
752
  let result;
@@ -781,14 +817,13 @@ class Document extends core_1.Client {
781
817
  }
782
818
  locateSourceFiles(file, code, bundleContent) {
783
819
  return (imports = this.imports) => {
784
- var _a;
785
820
  const href = file.uri;
786
821
  const sourceFile = [];
787
822
  let mainFile, invalid;
788
823
  if (Document.isFile(href, 'unc') || path.isAbsolute(href)) {
789
824
  sourceFile.push([href]);
790
825
  }
791
- else if (imports && Object.keys(imports).length) {
826
+ else if (Object.keys(imports).length) {
792
827
  const bundleId = file.bundleId;
793
828
  const assets = !(0, types_1.isEmpty)(bundleId) ? this.assets.filter(item => item.bundleId === bundleId).sort((a, b) => a.bundleIndex - b.bundleIndex) : [file];
794
829
  if (!Array.isArray(bundleContent) || bundleContent.length !== assets.length - 1) {
@@ -808,7 +843,7 @@ class Document extends core_1.Client {
808
843
  if (this.resolveUri && (0, types_1.isArray)(file.trailingContent)) {
809
844
  let trailing;
810
845
  [source, trailing] = this.resolveUri(file, source, (0, util_1.concatString)(file.trailingContent));
811
- if ((0, types_1.isString)(trailing)) {
846
+ if (trailing) {
812
847
  source += trailing;
813
848
  }
814
849
  }
@@ -824,7 +859,7 @@ class Document extends core_1.Client {
824
859
  invalid = true;
825
860
  break;
826
861
  }
827
- sourceFile.push(['', ((_a = this.resolveImports) === null || _a === void 0 ? void 0 : _a.call(this, item, source, localFile)) || source, localFile]);
862
+ sourceFile.push(['', this.resolveImports?.(item, source, localFile) || source, localFile]);
828
863
  }
829
864
  }
830
865
  }
@@ -835,11 +870,10 @@ class Document extends core_1.Client {
835
870
  }
836
871
  resolveSourceFile(file) {
837
872
  return (code, imports = this.imports) => {
838
- var _a;
839
873
  const uri = file.uri;
840
874
  let source, sourceFile;
841
- if (code && imports && Object.keys(imports).length) {
842
- const output = (_a = this.resolveImports) === null || _a === void 0 ? void 0 : _a.call(this, file, code, uri && this.findSourceRoot(uri, imports));
875
+ if (code && Object.keys(imports).length) {
876
+ const output = this.resolveImports?.(file, code, uri && this.findSourceRoot(uri, imports));
843
877
  if (output) {
844
878
  source = output;
845
879
  }
@@ -880,22 +914,19 @@ class Document extends core_1.Client {
880
914
  return item.source !== 'cloud';
881
915
  }
882
916
  hasEval(name) {
883
- var _a;
884
- return !!((_a = this.module.eval) === null || _a === void 0 ? void 0 : _a[name]);
917
+ return !!this.module.eval?.[name];
885
918
  }
886
919
  settingsOf(name, option) {
887
- var _a;
888
- const options = (_a = this.settings.options) === null || _a === void 0 ? void 0 : _a[name];
920
+ const options = this.settings.options?.[name];
889
921
  if ((0, types_1.isObject)(options)) {
890
922
  return options[option];
891
923
  }
892
924
  }
893
925
  async parseTemplate(viewEngine, template, data) {
894
- var _a, _b, _c, _d, _e, _f;
895
926
  let target, stored;
896
927
  if (typeof viewEngine === 'string') {
897
- target = (_a = this.settings.view_engine) === null || _a === void 0 ? void 0 : _a[viewEngine];
898
- const userConfig = (_c = (_b = this.getUserSettings()) === null || _b === void 0 ? void 0 : _b.view_engine) === null || _c === void 0 ? void 0 : _c[viewEngine];
928
+ target = this.settings.view_engine?.[viewEngine];
929
+ const userConfig = this.getUserSettings()?.view_engine?.[viewEngine];
899
930
  if ((0, types_1.isPlainObject)(userConfig)) {
900
931
  if ((0, types_1.isPlainObject)(target)) {
901
932
  (0, types_1.cloneObject)(userConfig, { target, deep: true, preserve: true });
@@ -935,7 +966,7 @@ class Document extends core_1.Client {
935
966
  (0, types_1.coerceObject)(output, stored);
936
967
  }
937
968
  }
938
- const username = ((_d = this.host) === null || _d === void 0 ? void 0 : _d.username) || '';
969
+ const username = this.host?.username || '';
939
970
  const cache = CACHE_TEMPLATE[name] || (CACHE_TEMPLATE[name] = {});
940
971
  const cacheKey = username + core_1.Client.asHash(template + (compile ? core_1.Client.asString(compile) : ''));
941
972
  let result = '', render, valid;
@@ -948,7 +979,7 @@ class Document extends core_1.Client {
948
979
  }
949
980
  for (let i = 0, j = 0, row; i < length; ++i) {
950
981
  if ((0, types_1.isPlainObject)(row = data[i])) {
951
- (_e = row.__index__) !== null && _e !== void 0 ? _e : (row.__index__ = ++j);
982
+ row.__index__ ?? (row.__index__ = ++j);
952
983
  if (output) {
953
984
  row = { ...output, ...row };
954
985
  }
@@ -965,7 +996,7 @@ class Document extends core_1.Client {
965
996
  }
966
997
  }
967
998
  }
968
- return singleRow ? (_f = render.call(context, data)) !== null && _f !== void 0 ? _f : null : valid ? result : null;
999
+ return singleRow ? render.call(context, data) ?? null : valid ? result : null;
969
1000
  }
970
1001
  catch (err) {
971
1002
  this.abort('view_engine');
@@ -974,55 +1005,32 @@ class Document extends core_1.Client {
974
1005
  return null;
975
1006
  }
976
1007
  async transform(type, code, format, options = {}) {
977
- var _a, _b, _c, _d;
1008
+ var _a, _b, _c;
978
1009
  let transform = this.settings.transform, data;
979
- if (!transform || !(0, types_1.isObject)(data = transform[type])) {
1010
+ if (!(transform && (0, types_1.isObject)(data = transform[type]))) {
980
1011
  return;
981
1012
  }
982
1013
  format = typeof format === 'string' ? format.trim().split(/\s*\+\s*/) : format.map(item => typeof item === 'string' ? item.trim() : '');
983
- const moduleName = this.moduleName;
984
- const username = ((_a = this.host) === null || _a === void 0 ? void 0 : _a.username) || '';
1014
+ const username = this.host?.username || '';
985
1015
  const config = this._transformConfig;
986
1016
  const cacheData = config && options.cacheData;
987
- const cacheType = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
988
- let formatKey, hashKey, excludeKey;
989
- if (cacheData && cacheType && !CACHE_EXTERNAL[excludeKey = moduleName + '_' + type + '_' + format] && (!config.exclude[type] || Array.isArray(config.exclude[type]) && !format.some(value => config.exclude[type].includes(value)) || Array.isArray(config.include[type]) && format.every(value => config.include[type].includes(value)))) {
1017
+ const cacheDir = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
1018
+ let formatKey = '', hashKey, excludeKey;
1019
+ if (cacheData && cacheDir && !CACHE_EXTERNAL[excludeKey = this.moduleName + '_' + type + '_' + format] && (!config.exclude[type] || Array.isArray(config.exclude[type]) && !format.some(value => config.exclude[type].includes(value)) || Array.isArray(config.include[type]) && format.every(value => config.include[type].includes(value)))) {
990
1020
  const { uri, etag } = cacheData;
991
1021
  const encoding = (0, types_1.getEncoding)(cacheData.encoding);
992
1022
  const algorithm = config.algorithm;
993
1023
  let result, cacheName;
994
1024
  formatKey = type + '_' + format + '_' + encoding + (username ? '_' + username : '') + core_1.Client.asString(options.external) + core_1.Client.asString(options.metadata);
995
- const resetTimeout = (map, key, stored) => {
996
- if (config.renew) {
997
- if (stored.timeout) {
998
- clearTimeout(stored.timeout);
999
- }
1000
- stored.timeout = renewTransform(map, key, config.expires);
1001
- }
1002
- stored.lastAccessed = Date.now();
1003
- };
1004
- const getData = (stored) => {
1005
- const location = stored.format[formatKey];
1006
- if (typeof location === 'string') {
1007
- try {
1008
- return JSON.parse(fs.readFileSync(location, encoding));
1009
- }
1010
- catch {
1011
- fs.unlink(location, () => { });
1012
- return;
1013
- }
1014
- }
1015
- return location;
1016
- };
1017
1025
  if (config.etag && etag && uri) {
1018
- const etagMap = CACHE_ETAG[moduleName] || (CACHE_ETAG[moduleName] = {});
1026
+ const etagMap = CACHE_ETAG[_a = this.moduleName] || (CACHE_ETAG[_a] = {});
1019
1027
  const stored = etagMap[uri];
1020
1028
  if (stored) {
1021
1029
  if (stored.etag !== etag) {
1022
1030
  deleteTransform(etagMap, uri, stored.timeout);
1023
1031
  }
1024
- else if (result = getData(stored)) {
1025
- resetTimeout(etagMap, uri, stored);
1032
+ else if (result = getTransformData(stored, formatKey, encoding)) {
1033
+ resetTransform(config, etagMap, uri, stored);
1026
1034
  cacheName = 'etag';
1027
1035
  }
1028
1036
  }
@@ -1031,10 +1039,10 @@ class Document extends core_1.Client {
1031
1039
  if (algorithm) {
1032
1040
  const limit = config.limit;
1033
1041
  if ((limit === Infinity || limit > 0 && Buffer.byteLength(code, encoding) <= limit) && (hashKey = core_1.Client.asHash(code, { algorithm, encoding }))) {
1034
- const hashMap = CACHE_HASH[moduleName] || (CACHE_HASH[moduleName] = {});
1042
+ const hashMap = CACHE_HASH[_b = this.moduleName] || (CACHE_HASH[_b] = {});
1035
1043
  const stored = hashMap[hashKey];
1036
- if (stored && (result = getData(stored))) {
1037
- resetTimeout(hashMap, hashKey, stored);
1044
+ if (stored && (result = getTransformData(stored, formatKey, encoding))) {
1045
+ resetTransform(config, hashMap, hashKey, stored);
1038
1046
  cacheName = algorithm;
1039
1047
  }
1040
1048
  }
@@ -1043,14 +1051,14 @@ class Document extends core_1.Client {
1043
1051
  }
1044
1052
  }
1045
1053
  else if (uri) {
1046
- const codeMap = CACHE_CODE[moduleName] || (CACHE_CODE[moduleName] = {});
1054
+ const codeMap = CACHE_CODE[_c = this.moduleName] || (CACHE_CODE[_c] = {});
1047
1055
  const stored = codeMap[uri];
1048
1056
  if (stored) {
1049
1057
  if (stored.code !== code) {
1050
1058
  deleteTransform(codeMap, uri, stored.timeout);
1051
1059
  }
1052
- else if (result = getData(stored)) {
1053
- resetTimeout(codeMap, uri, stored);
1060
+ else if (result = getTransformData(stored, formatKey, encoding)) {
1061
+ resetTransform(config, codeMap, uri, stored);
1054
1062
  }
1055
1063
  }
1056
1064
  }
@@ -1059,7 +1067,7 @@ class Document extends core_1.Client {
1059
1067
  }
1060
1068
  }
1061
1069
  if (result) {
1062
- (_b = result.storedLog) === null || _b === void 0 ? void 0 : _b.forEach(log => this.addLog(log));
1070
+ result.storedLog?.forEach(log => this.addLog(log));
1063
1071
  this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
1064
1072
  return result;
1065
1073
  }
@@ -1071,22 +1079,14 @@ class Document extends core_1.Client {
1071
1079
  const series = new transform_1.TransformSeries(type, code, options);
1072
1080
  series.init(this, __dirname);
1073
1081
  let valid, excluded, userData, userImports, ignoreCache, storedLog, sourceFiles;
1074
- if (username && (transform = (_d = (_c = this.settings.users) === null || _c === void 0 ? void 0 : _c[username]) === null || _d === void 0 ? void 0 : _d.transform)) {
1082
+ if (username && (transform = this.settings.users?.[username]?.transform)) {
1075
1083
  userData = transform[type];
1076
1084
  userImports = transform.imports;
1077
1085
  }
1078
- const abort = () => {
1086
+ const abortTransform = () => {
1079
1087
  ignoreCache = true;
1080
1088
  this.abort('transform');
1081
1089
  };
1082
- const includes = (name) => {
1083
- const include = config === null || config === void 0 ? void 0 : config.include[type];
1084
- if (include === true || (include === null || include === void 0 ? void 0 : include.includes(name))) {
1085
- const exclude = config.exclude[type];
1086
- return !exclude || exclude === true && include !== true || Array.isArray(exclude) && !exclude.includes(name);
1087
- }
1088
- return (cacheData === null || cacheData === void 0 ? void 0 : cacheData.override) === true;
1089
- };
1090
1090
  for (let i = 0, length = format.length, name; i < length; ++i) {
1091
1091
  if (this.aborted) {
1092
1092
  break;
@@ -1120,7 +1120,7 @@ class Document extends core_1.Client {
1120
1120
  }
1121
1121
  }
1122
1122
  if (!baseSettings) {
1123
- excluded = !includes(name);
1123
+ excluded = !hasTransformType(config, type, name, cacheData);
1124
1124
  }
1125
1125
  outputConfig || (outputConfig = {});
1126
1126
  if (plugin && baseConfig) {
@@ -1143,7 +1143,7 @@ class Document extends core_1.Client {
1143
1143
  else if (source !== value) {
1144
1144
  series.code = value;
1145
1145
  valid = true;
1146
- if (out.ignoreCache && !includes(name)) {
1146
+ if (out.ignoreCache && !hasTransformType(config, type, name, cacheData)) {
1147
1147
  ignoreCache = true;
1148
1148
  }
1149
1149
  if ((0, types_1.isArray)(out.sourceFiles)) {
@@ -1204,8 +1204,8 @@ class Document extends core_1.Client {
1204
1204
  let transformer = CACHE_PACKAGE[plugin + username];
1205
1205
  if (!transformer) {
1206
1206
  try {
1207
- let pkg = this.resolveDir('package', plugin + '.js') || (userImports === null || userImports === void 0 ? void 0 : userImports[plugin]) || imports[plugin] || util_1.IMPORTS[plugin];
1208
- if ((0, types_1.isString)(pkg)) {
1207
+ let pkg = this.resolveDir('package', plugin + '.js') || userImports?.[plugin] || imports[plugin] || util_1.IMPORTS[plugin];
1208
+ if (pkg) {
1209
1209
  const match = /^(@?\S+)@(\d+(?:\.\d+(?:\.\S+)?)?|[a-z]+)$/.exec(pkg);
1210
1210
  if (match) {
1211
1211
  pkg = match[1];
@@ -1216,20 +1216,19 @@ class Document extends core_1.Client {
1216
1216
  else {
1217
1217
  transformer = context;
1218
1218
  context = this;
1219
- pkg = undefined;
1220
- }
1221
- if (transformer && typeof transformer !== 'function') {
1222
- transformer = transformer.default;
1223
1219
  }
1224
1220
  if (typeof transformer !== 'function') {
1225
- throw (0, types_1.errorMessage)(plugin, pkg || name, 'Invalid function');
1221
+ transformer && (transformer = transformer.default);
1222
+ if (typeof transformer !== 'function') {
1223
+ throw (0, types_1.errorMessage)(plugin, pkg || name, 'Invalid function');
1224
+ }
1226
1225
  }
1227
1226
  if (pkg) {
1228
1227
  CACHE_PACKAGE[plugin + username] = transformer;
1229
1228
  }
1230
1229
  }
1231
1230
  catch (err) {
1232
- abort();
1231
+ abortTransform();
1233
1232
  this.writeFail(["Unknown", username ? plugin + ':' + username : hint], err, { type: 4, startTime });
1234
1233
  continue;
1235
1234
  }
@@ -1239,7 +1238,7 @@ class Document extends core_1.Client {
1239
1238
  }
1240
1239
  }
1241
1240
  catch (err) {
1242
- abort();
1241
+ abortTransform();
1243
1242
  this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document", hint], { type: 4, startTime });
1244
1243
  if (i < length - 1) {
1245
1244
  series.reset();
@@ -1247,7 +1246,7 @@ class Document extends core_1.Client {
1247
1246
  }
1248
1247
  }
1249
1248
  else {
1250
- abort();
1249
+ abortTransform();
1251
1250
  if (plugin) {
1252
1251
  this.writeFail("Unable to load configuration", (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4);
1253
1252
  }
@@ -1273,7 +1272,7 @@ class Document extends core_1.Client {
1273
1272
  output.map = sourceMap.map;
1274
1273
  }
1275
1274
  if ((0, types_1.isArray)(series.supplementChunks)) {
1276
- output.chunks = series.supplementChunks.map(item => { var _a; return ({ code: item.code, map: output.map && ((_a = item.sourceMap) === null || _a === void 0 ? void 0 : _a.map), entryPoint: item.entryPoint, filename: item.filename }); });
1275
+ output.chunks = series.supplementChunks.map(item => ({ code: item.code, map: output.map && item.sourceMap?.map, entryPoint: item.entryPoint, filename: item.filename }));
1277
1276
  }
1278
1277
  if (sourceFiles) {
1279
1278
  output.sourceFiles = sourceFiles;
@@ -1282,55 +1281,43 @@ class Document extends core_1.Client {
1282
1281
  const { uri, etag } = cacheData;
1283
1282
  const formatData = { ...output, storedLog };
1284
1283
  const lastAccessed = Date.now();
1285
- const setData = () => {
1286
- let pathname;
1287
- if (typeof cacheType === 'string' && core_1.Client.createDir(pathname = path.join(cacheType, 'transform', type))) {
1288
- try {
1289
- fs.writeFileSync(pathname = path.join(pathname, (0, types_1.incrementUUID)()), JSON.stringify(formatData));
1290
- return pathname;
1291
- }
1292
- catch {
1293
- }
1294
- }
1295
- return formatData;
1296
- };
1297
1284
  if (config.etag && etag && uri) {
1298
- const etagMap = CACHE_ETAG[moduleName];
1285
+ const etagMap = CACHE_ETAG[this.moduleName];
1299
1286
  const stored = etagMap[uri];
1300
1287
  if (stored) {
1301
1288
  if (stored.etag === etag) {
1302
- stored.format[formatKey] = setData();
1289
+ stored.format[formatKey] = setTransformData(type, cacheDir, formatData);
1303
1290
  stored.lastAccessed = lastAccessed;
1304
1291
  return output;
1305
1292
  }
1306
1293
  deleteTransform(etagMap, uri, stored.timeout);
1307
1294
  }
1308
- etagMap[uri] = { lastAccessed, etag, timeout: renewTransform(etagMap, uri, config.expires), format: { [formatKey]: setData() } };
1295
+ etagMap[uri] = { lastAccessed, etag, timeout: renewTransform(etagMap, uri, config.expires), format: { [formatKey]: setTransformData(type, cacheDir, formatData) } };
1309
1296
  ++CACHE_TOTAL;
1310
1297
  }
1311
1298
  else if (hashKey) {
1312
- const hashMap = CACHE_HASH[moduleName];
1299
+ const hashMap = CACHE_HASH[this.moduleName];
1313
1300
  const stored = hashMap[hashKey];
1314
1301
  if (stored) {
1315
- stored.format[formatKey] = setData();
1302
+ stored.format[formatKey] = setTransformData(type, cacheDir, formatData);
1316
1303
  stored.lastAccessed = lastAccessed;
1317
1304
  return output;
1318
1305
  }
1319
- hashMap[hashKey] = { lastAccessed, timeout: renewTransform(hashMap, hashKey, config.expires), format: { [formatKey]: setData() } };
1306
+ hashMap[hashKey] = { lastAccessed, timeout: renewTransform(hashMap, hashKey, config.expires), format: { [formatKey]: setTransformData(type, cacheDir, formatData) } };
1320
1307
  ++CACHE_TOTAL;
1321
1308
  }
1322
1309
  else if (uri) {
1323
- const codeMap = CACHE_CODE[moduleName];
1310
+ const codeMap = CACHE_CODE[this.moduleName];
1324
1311
  const stored = codeMap[uri];
1325
1312
  if (stored) {
1326
1313
  if (stored.code === code) {
1327
- stored.format[formatKey] = setData();
1314
+ stored.format[formatKey] = setTransformData(type, cacheDir, formatData);
1328
1315
  stored.lastAccessed = lastAccessed;
1329
1316
  return output;
1330
1317
  }
1331
1318
  deleteTransform(codeMap, uri, stored.timeout);
1332
1319
  }
1333
- codeMap[uri] = { lastAccessed, code, timeout: renewTransform(codeMap, uri, config.expires), format: { [formatKey]: setData() } };
1320
+ codeMap[uri] = { lastAccessed, code, timeout: renewTransform(codeMap, uri, config.expires), format: { [formatKey]: setTransformData(type, cacheDir, formatData) } };
1334
1321
  ++CACHE_TOTAL;
1335
1322
  }
1336
1323
  }
@@ -1363,7 +1350,6 @@ class Document extends core_1.Client {
1363
1350
  return this._dataSource || [];
1364
1351
  }
1365
1352
  set imports(value) {
1366
- var _a;
1367
1353
  if (!(0, types_1.isPlainObject)(value)) {
1368
1354
  this._imports = null;
1369
1355
  return;
@@ -1373,23 +1359,16 @@ class Document extends core_1.Client {
1373
1359
  this._imports = Object.assign(imports, value);
1374
1360
  }
1375
1361
  else {
1376
- imports = ((_a = this.getUserSettings()) === null || _a === void 0 ? void 0 : _a.imports) || this.module.imports;
1362
+ imports = this.getUserSettings()?.imports || this.module.imports;
1377
1363
  this._imports = Object.assign(this._imports || {}, (0, types_1.isPlainObject)(imports) ? imports : undefined, value);
1378
1364
  }
1379
1365
  }
1380
1366
  get imports() {
1381
- if (!this._imports) {
1382
- this.imports = {};
1383
- }
1384
- return this._imports;
1367
+ return this._imports || (this._imports = {});
1385
1368
  }
1386
1369
  get watching() {
1387
1370
  return this.assets.some(item => item.watch);
1388
1371
  }
1389
1372
  }
1390
- exports.default = Document;
1391
1373
 
1392
- if (exports.default) {
1393
- module.exports = exports.default;
1394
- module.exports.default = exports.default;
1395
- }
1374
+ module.exports = Document;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.8.10",
3
+ "version": "0.9.1",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,15 +17,15 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
20
+ "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.8.10",
24
- "@e-mc/db": "0.8.10",
25
- "@e-mc/types": "0.8.10",
23
+ "@e-mc/core": "0.9.1",
24
+ "@e-mc/db": "0.9.1",
25
+ "@e-mc/types": "0.9.1",
26
26
  "chalk": "4.1.2",
27
27
  "htmlparser2": "^9.1.0",
28
28
  "js-yaml": "^4.1.0",
29
- "picomatch": "^3.0.1"
29
+ "picomatch": "^4.0.2"
30
30
  }
31
31
  }
package/parse/dom.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  exports.IGNORE_FLAG = exports.HtmlElement = exports.DomWriter = void 0;
4
3
  const htmlparser2 = require("htmlparser2");
5
4
  const domhandler = require("domhandler");
@@ -34,7 +33,7 @@ class DomWriter extends index_1.XmlWriter {
34
33
  tagGroup.push(new RegExp('^' + (0, types_1.escapePattern)(start)));
35
34
  }
36
35
  const end = ignoreTagGroup[i + 1];
37
- if ((end === null || end === void 0 ? void 0 : end[end.length - 1]) === '>') {
36
+ if (end?.[end.length - 1] === '>') {
38
37
  tagGroup.push(new RegExp((0, types_1.escapePattern)(start) + '$'));
39
38
  }
40
39
  }
@@ -82,7 +81,6 @@ class DomWriter extends index_1.XmlWriter {
82
81
  pattern.lastIndex += tag.length - match[0].length;
83
82
  }
84
83
  }
85
- pattern.lastIndex = 0;
86
84
  return source;
87
85
  }
88
86
  static getDocumentElement(source, parser) {
@@ -226,8 +224,7 @@ class HtmlElement extends index_1.XmlElement {
226
224
  this._documentType = "HTML";
227
225
  }
228
226
  getTagOffset(source) {
229
- var _a;
230
- switch (((_a = this.node.append) === null || _a === void 0 ? void 0 : _a.tagName) || this.tagName) {
227
+ switch (this.node.append?.tagName || this.tagName) {
231
228
  case 'html':
232
229
  case 'title':
233
230
  case 'style':
package/parse/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  exports.XmlElement = exports.XmlWriter = exports.IGNORE_FLAG = void 0;
4
3
  const htmlparser2 = require("htmlparser2");
5
4
  const domhandler = require("domhandler");
@@ -235,7 +234,7 @@ class XmlWriter {
235
234
  return result;
236
235
  }
237
236
  const nodes = domutils.getElementsByTagName(node.tagName, outDom, true);
238
- if (!(parser === null || parser === void 0 ? void 0 : parser.xmlMode)) {
237
+ if (!parser?.xmlMode) {
239
238
  nodes.filter(item => item.next && item.next.startIndex <= item.endIndex).forEach(item => {
240
239
  for (let i = 0, length = nodes.length; i < length; ++i) {
241
240
  const element = nodes[i];
@@ -262,7 +261,7 @@ class XmlWriter {
262
261
  const locator = node.locator;
263
262
  if (locator && locatorAttr) {
264
263
  const { element } = this.locateElement(source, locator, locatorAttr, { parser, outDom });
265
- if ((element === null || element === void 0 ? void 0 : element.tagName) === node.tagName) {
264
+ if (element?.tagName === node.tagName) {
266
265
  result.element = element;
267
266
  index = nodes.findIndex(item => item === element);
268
267
  }
@@ -346,12 +345,10 @@ class XmlWriter {
346
345
  CACHE_TAGVOID[type] = values;
347
346
  }
348
347
  static isTagVoid(type, tagName) {
349
- var _a;
350
- return !!((_a = CACHE_TAGVOID[type]) === null || _a === void 0 ? void 0 : _a.includes(tagName));
348
+ return !!CACHE_TAGVOID[type]?.includes(tagName);
351
349
  }
352
350
  static getNodeId(node, document) {
353
- var _a;
354
- return ((_a = node.id) === null || _a === void 0 ? void 0 : _a[document]) || '';
351
+ return node.id?.[document] || '';
355
352
  }
356
353
  static getNameOfId(document) {
357
354
  return `data-${document}-id`;
@@ -426,7 +423,7 @@ class XmlWriter {
426
423
  if ((ignoreCase ? tagName.toLowerCase() === other.tagName.toLowerCase() : tagName === other.tagName) && (index === other.index && isIndex(index) || tagIndex === other.tagIndex && tagCount === other.tagCount && isIndex(tagIndex) && isCount(tagCount))) {
427
424
  return true;
428
425
  }
429
- return document && other.id && (id === null || id === void 0 ? void 0 : id[document]) ? id[document] === other.id[document] : false;
426
+ return document && other.id && id?.[document] ? id[document] === other.id[document] : false;
430
427
  }
431
428
  static isIndex(value) {
432
429
  return isIndex(value);
@@ -452,7 +449,7 @@ class XmlWriter {
452
449
  this._patternIgnore = null;
453
450
  this._writeStartIndex = -1;
454
451
  this._source = source;
455
- this.parser = options === null || options === void 0 ? void 0 : options.parser;
452
+ this.parser = options?.parser;
456
453
  }
457
454
  init(offsetMap) {
458
455
  const appending = [];
@@ -463,7 +460,7 @@ class XmlWriter {
463
460
  }
464
461
  if (isCount(item.tagCount)) {
465
462
  const tagName = item.tagName;
466
- item.tagCount += (offsetMap === null || offsetMap === void 0 ? void 0 : offsetMap[tagName]) || 0;
463
+ item.tagCount += offsetMap?.[tagName] || 0;
467
464
  this._tagCount[tagName] = item.tagCount;
468
465
  }
469
466
  deletePosition(item, rootName);
@@ -552,7 +549,6 @@ class XmlWriter {
552
549
  return null;
553
550
  }
554
551
  write(element) {
555
- var _a;
556
552
  if (!element.modified) {
557
553
  return true;
558
554
  }
@@ -583,7 +579,7 @@ class XmlWriter {
583
579
  if (append) {
584
580
  const { tagName, id, textContent = '', prepend, nextSibling } = append;
585
581
  if (!prepend) {
586
- node.index = nextSibling !== null && nextSibling !== void 0 ? nextSibling : -1;
582
+ node.index = nextSibling ?? -1;
587
583
  }
588
584
  (node.id || (node.id = {}))[this.documentName] = id;
589
585
  element.id = id;
@@ -606,7 +602,7 @@ class XmlWriter {
606
602
  this.renameTag(node, element.tagName);
607
603
  }
608
604
  this.update(node, outerXml, append, element.tagOffset);
609
- if (element.innerXml && !element.remove && (element.hasModifiedContent() || ((_a = this.patternIgnore) === null || _a === void 0 ? void 0 : _a.test(element.tagName)))) {
605
+ if (element.innerXml && !element.remove && (element.hasModifiedContent() || this.patternIgnore?.test(element.tagName))) {
610
606
  this._hasInvalidContent = true;
611
607
  this._writeStartIndex = -1;
612
608
  }
@@ -805,7 +801,6 @@ class XmlWriter {
805
801
  }
806
802
  }
807
803
  indexTag(tagName, append, offset = 0) {
808
- var _a;
809
804
  if (tagName in this._tagCount) {
810
805
  const elements = [];
811
806
  const revised = [];
@@ -875,7 +870,7 @@ class XmlWriter {
875
870
  return;
876
871
  }
877
872
  }
878
- const id = append ? append.id : (_a = revised[0].id) === null || _a === void 0 ? void 0 : _a[this.documentName];
873
+ const id = append ? append.id : revised[0].id?.[this.documentName];
879
874
  if (id) {
880
875
  const element = XmlWriter.findElement(this.source, (append || revised[0]), { document: this.documentName, id, tagCount: nextCount, parser: this.parser });
881
876
  if (element) {
@@ -897,7 +892,7 @@ class XmlWriter {
897
892
  item.index = -1;
898
893
  }
899
894
  const append = item.append;
900
- if ((append === null || append === void 0 ? void 0 : append.tagName) === tagName) {
895
+ if (append?.tagName === tagName) {
901
896
  delete append.tagCount;
902
897
  const nextSibling = append.nextSibling;
903
898
  if (isIndex(nextSibling)) {
@@ -958,7 +953,6 @@ class XmlWriter {
958
953
  }
959
954
  getElementsByTagName(tagName, ignoreCase = false, options) {
960
955
  var _a;
961
- var _b;
962
956
  let tagVoid;
963
957
  if (options) {
964
958
  ({ tagVoid } = options);
@@ -968,14 +962,14 @@ class XmlWriter {
968
962
  const result = [];
969
963
  const patternId = XmlWriter.getPatternId(this.nameOfId);
970
964
  const flags = ignoreCase ? 'gi' : 'g';
971
- const pattern = CACHE_TAGNAME[_b = tagName + flags + '3'] || (CACHE_TAGNAME[_b] = new RegExp(`<${escapeTagName(tagName) + PATTERN_TAGOPEN}*>`, flags));
965
+ const pattern = CACHE_TAGNAME[_a = tagName + flags + '3'] || (CACHE_TAGNAME[_a] = new RegExp(`<${escapeTagName(tagName) + PATTERN_TAGOPEN}*>`, flags));
972
966
  pattern.lastIndex = 0;
973
967
  let match;
974
968
  while (match = pattern.exec(source)) {
975
969
  const startIndex = match.index;
976
970
  let outerXml = match[0], endIndex = startIndex + outerXml.length - 1;
977
971
  if (!invalid || isValidIndex(invalid, startIndex, endIndex)) {
978
- const id = (_a = patternId.exec(outerXml)) === null || _a === void 0 ? void 0 : _a[1];
972
+ const id = patternId.exec(outerXml)?.[1];
979
973
  if (!tagVoid) {
980
974
  const [index, closeTag] = findCloseIndex(source, tagName, endIndex + 1, ignoreCase);
981
975
  if (index !== -1) {
@@ -1052,7 +1046,7 @@ class XmlElement {
1052
1046
  if (value === null) {
1053
1047
  continue;
1054
1048
  }
1055
- result += '="' + (typeof value === 'string' ? escapeEntities ? XmlWriter.escapeXmlString(value) : value.replace(/"/g, '&quot;') : module_1.default.asString(value)) + '"';
1049
+ result += '="' + (typeof value === 'string' ? escapeEntities ? XmlWriter.escapeXmlString(value) : value.replace(/"/g, '&quot;') : module_1.asString(value)) + '"';
1056
1050
  }
1057
1051
  return result;
1058
1052
  }
@@ -1157,7 +1151,6 @@ class XmlElement {
1157
1151
  }
1158
1152
  }
1159
1153
  getAttribute(name) {
1160
- var _a;
1161
1154
  let result = this._attributes.get(this._ignoreCase ? name = name.toLowerCase() : name);
1162
1155
  if (result) {
1163
1156
  return result;
@@ -1170,7 +1163,7 @@ class XmlElement {
1170
1163
  if (outerXml) {
1171
1164
  const index = XmlWriter.findCloseTag(outerXml);
1172
1165
  if (index !== -1) {
1173
- return ((_a = XmlWriter.getPatternId(this.nameOfId).exec(outerXml.substring(0, index))) === null || _a === void 0 ? void 0 : _a[1]) || '';
1166
+ return XmlWriter.getPatternId(this.nameOfId).exec(outerXml.substring(0, index))?.[1] || '';
1174
1167
  }
1175
1168
  }
1176
1169
  }
@@ -1382,8 +1375,7 @@ class XmlElement {
1382
1375
  return [this.tagName, attributes, this.innerXml];
1383
1376
  }
1384
1377
  getInnerOffset(tagName) {
1385
- var _a;
1386
- return ((_a = this._tagOffset) === null || _a === void 0 ? void 0 : _a[tagName]) || 0;
1378
+ return this._tagOffset?.[tagName] || 0;
1387
1379
  }
1388
1380
  hasPosition() {
1389
1381
  return isIndex(this.node.startIndex) && isIndex(this.node.endIndex);
@@ -1419,8 +1411,7 @@ class XmlElement {
1419
1411
  return this._documentType || this.documentName;
1420
1412
  }
1421
1413
  get tagVoid() {
1422
- var _a;
1423
- return (_a = this._tagVoid) !== null && _a !== void 0 ? _a : XmlWriter.isTagVoid(this.documentType, this.tagName);
1414
+ return this._tagVoid ?? XmlWriter.isTagVoid(this.documentType, this.tagName);
1424
1415
  }
1425
1416
  set innerXml(value) {
1426
1417
  if (!this.tagVoid && value !== this._innerXml) {
@@ -127,7 +127,7 @@ export class IXmlWriter extends IXmlBase {
127
127
  renameTag(node: XmlTagNode, tagName: string): void;
128
128
  indexTag(tagName: string, append?: TagAppend, offset?: number): void;
129
129
  resetTag(tagName: string): void;
130
- ignoreTag(value: StringOfArray): void;
130
+ ignoreTag(value: ArrayOf<string>): void;
131
131
  resetPosition(startIndex?: number): void;
132
132
  getElementById(id: string, ignoreCase?: boolean, options?: TagNodeByIdOptions): Undef<SourceTagNode>;
133
133
  getElementsByTagName(tagName: string, ignoreCase?: boolean, options?: TagNodeOptions): SourceTagNode[];
@@ -165,7 +165,7 @@ export interface XmlWriterConstructor {
165
165
  getNameOfId(document: string): string;
166
166
  getPatternId(name: string): RegExp;
167
167
  getCommentsAndCDATA(source: string, tagPattern: unknown, ignoreCase: boolean, stripXml: true): string;
168
- getCommentsAndCDATA(source: string, tagPattern?: StringOfArray | [Undef<string>, Undef<string[]>], ignoreCase?: boolean, stripXml?: boolean): SourceContent[];
168
+ getCommentsAndCDATA(source: string, tagPattern?: ArrayOf<string> | [Undef<string>, Undef<string[]>], ignoreCase?: boolean, stripXml?: boolean): SourceContent[];
169
169
  isEqual(node: XmlTagNode, other: XmlTagNode, ignoreCase: boolean): boolean;
170
170
  isEqual(node: XmlTagNode, other: XmlTagNode, documentName?: string, ignoreCase?: boolean): boolean;
171
171
  isIndex(value: Undef<number>): value is number;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  var _a, _b, _c, _d;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.SourceMap = exports.TransformSeries = void 0;
5
4
  const path = require("path");
6
5
  const types_1 = require("@e-mc/types");
@@ -136,9 +135,8 @@ class TransformSeries extends core_1.Module {
136
135
  return context;
137
136
  }
138
137
  close(instance) {
139
- var _e;
140
138
  core_1.AbortComponent.detach(instance, this.signal);
141
- (_e = this.host) === null || _e === void 0 ? void 0 : _e.release(this);
139
+ this.host?.release(this);
142
140
  }
143
141
  set code(value) {
144
142
  this[kCode] = value;
package/util.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  exports.isObject = exports.removeInternalProperties = exports.getModuleName = exports.hasValue = exports.getHashData = exports.getNewline = exports.getIndent = exports.appendSuffix = exports.splitEnclosing = exports.concatString = exports.replaceAll = exports.loadPlugins = exports.IMPORTS = void 0;
4
3
  const path = require("path");
5
4
  const types_1 = require("@e-mc/types");