@e-mc/document 0.8.5 → 0.8.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.
package/LICENSE CHANGED
@@ -1,7 +1,11 @@
1
- Copyright 2024 Mile Square Park
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,99 @@
1
1
  # @e-mc/document
2
2
 
3
- PEP 402
3
+ * NodeJS 14
4
+ * ES2020
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/index.d.ts
13
+
14
+ ```typescript
15
+ import type { DataSource, ViewEngine } from "./squared";
16
+
17
+ import type { IFileManager, IScopeOrigin } from "./index";
18
+ import type { ExternalAsset, FileCommand, IFileThread, OutputFinalize } from "./asset";
19
+ import type { HostInitConfig, IClient } from "./core";
20
+ import type { AsSourceFileOptions, ConfigOrTransformer, CustomizeOptions, GenerateLintTableOptions, LintMessage, PluginConfig, SourceCode, SourceInput, SourceMap, SourceMapOptions, TransformAction, TransformCallback, TransformOutput, TransformResult, UpdateGradleOptions } from "./document";
21
+ import type { PostFinalizeCallback } from "./filemanager";
22
+ import type { LogComponent } from "./logger";
23
+ import type { DocumentComponent, DocumentComponentOption, DocumentModule } from "./settings";
24
+ import type { IFileGroup, WatchInitResult } from "./watch";
25
+
26
+ interface IDocument extends IClient<IFileManager, DocumentModule, TransformCallback<IFileManager, ExternalAsset>> {
27
+ Db: IDb | null;
28
+ assets: ExternalAsset[];
29
+ config: Record<string, any>;
30
+ init(assets: ExternalAsset[], config?: HostInitConfig): this;
31
+ customize(options?: CustomizeOptions): void;
32
+ findConfig(data: object, name: string, type?: string): PluginConfig;
33
+ loadConfig(data: object, name: string): ConfigOrTransformer | null | undefined;
34
+ asSourceFile(value: string, options?: AsSourceFileOptions | boolean): unknown;
35
+ findVersion(name: string | string[], fallback?: string): string;
36
+ findSourceScope(uri: string, imports: Record<string, unknown>): Record<string, string | undefined>[];
37
+ findSourceRoot(uri: string, imports?: Record<string, string | undefined>): string | undefined;
38
+ 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;
41
+ tryParse(source: string, format: string, options?: Record<string | number | symbol, unknown>): unknown;
42
+ forDb(item: DataSource): boolean;
43
+ hasEval(name: string): boolean;
44
+ settingsOf(name: keyof DocumentComponent, option: keyof DocumentComponentOption): unknown;
45
+ parseTemplate(viewEngine: ViewEngine | string, template: string, data: unknown[]): Promise<string | null>;
46
+ transform(type: string, code: string, format: string | string[], options?: TransformOutput & TransformAction): Promise<TransformResult | void>;
47
+ abort(name?: keyof DocumentComponent | Error, reason?: unknown): void;
48
+ restart(): void;
49
+ using?(data: IFileThread): Promise<unknown>;
50
+ setLocalUri?(file: ExternalAsset, replace?: boolean): void;
51
+ resolveUri?(file: ExternalAsset, source: string): string;
52
+ resolveUri?(file: ExternalAsset, source: string, trailing: string): [string, string];
53
+ resolveImports?(file: ExternalAsset, code: string, baseFile?: string | ExternalAsset): string | undefined;
54
+ replaceContent?(source: string, statement: RegExpExecArray | string, mimeType?: string): string | undefined;
55
+ addCopy?(data: FileCommand<ExternalAsset>, saveAs: string, replace?: boolean): string | undefined;
56
+ writeImage?(output: OutputFinalize<ExternalAsset>): boolean;
57
+ cloudInit?(state: IScopeOrigin<IFileManager, ICloud>): void;
58
+ cloudObject?(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset): boolean;
59
+ cloudUpload?(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, url: string, active: boolean): Promise<boolean>;
60
+ cloudFinalize?(state: IScopeOrigin<IFileManager, ICloud>): Promise<unknown[]>;
61
+ watchInit?(watch: IFileGroup<ExternalAsset>, assets: ExternalAsset[], sanitize?: boolean): WatchInitResult | undefined;
62
+ watchModified?(watch: IFileGroup<ExternalAsset>, assets?: ExternalAsset[]): PostFinalizeCallback;
63
+ set dataSource(value: DataSource[]);
64
+ get dataSource(): DataSource[];
65
+ set imports(value);
66
+ get imports(): Record<string, string | undefined>;
67
+ get watching(): boolean;
68
+ }
69
+
70
+ interface DocumentConstructor extends ModuleConstructor {
71
+ finalize(this: IFileManager, instance: IDocument): Promise<unknown>;
72
+ createSourceMap(code: string, remove: boolean): SourceMap;
73
+ createSourceMap(code: string, uri?: string, remove?: boolean): SourceMap;
74
+ writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): string | undefined;
75
+ updateGradle(source: string, namespaces: string[], value: string, options?: UpdateGradleOptions | boolean): string;
76
+ generateLintTable(messages: LintMessage[], options: GenerateLintTableOptions): LogComponent[];
77
+ /* @deprecated - IDocument.using */
78
+ using?(this: IFileManager, instance: IDocument, file: ExternalAsset): Promise<unknown>;
79
+ cleanup?(this: IFileManager, instance: IDocument): Promise<unknown>;
80
+ sanitizeAssets?(assets: ExternalAsset[], exclusions?: ExternalAsset[]): ExternalAsset[];
81
+ readonly prototype: IDocument;
82
+ new(module?: DocumentModule, ...args: unknown[]): IDocument;
83
+ }
84
+ ```
85
+
86
+ ## References
87
+
88
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/squared.d.ts
89
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/asset.d.ts
90
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/core.d.ts
91
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/document.d.ts
92
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/filemanager.d.ts
93
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/logger.d.ts
94
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/settings.d.ts
95
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/watch.d.ts
4
96
 
5
97
  ## LICENSE
6
98
 
7
- MIT
99
+ BSD 3-Clause
package/index.js CHANGED
@@ -5,12 +5,12 @@ const fs = require("fs");
5
5
  const pm = require("picomatch");
6
6
  const yaml = require("js-yaml");
7
7
  const chalk = require("chalk");
8
- const types_1 = require("../types");
9
- const core_1 = require("../core");
10
- const db_1 = require("../db");
11
- const util_1 = require("./util");
12
- const transform_1 = require("./transform");
13
- const parse_1 = require("./parse");
8
+ const types_1 = require("@e-mc/types");
9
+ const core_1 = require("@e-mc/core");
10
+ const db_1 = require("@e-mc/db");
11
+ const util_1 = require("@e-mc/document/util");
12
+ const transform_1 = require("@e-mc/document/transform");
13
+ const parse_1 = require("@e-mc/document/parse");
14
14
  const PLATFORM_WIN32 = process.platform === 'win32';
15
15
  const CACHE_PACKAGE = {};
16
16
  const CACHE_REQUIRE = {};
@@ -95,17 +95,16 @@ class Document extends core_1.Client {
95
95
  }
96
96
  try {
97
97
  const args = [instance];
98
- // @ts-ignore
99
- if (ext["__cjs__" /* INTERNAL.CJS */]) {
98
+ if (ext["__cjs__"]) {
100
99
  args.push(__dirname);
101
100
  }
102
- else if (core_1.Client.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */)) {
101
+ else if (core_1.Client.enabled("node.require.inline")) {
103
102
  args.push(require);
104
103
  }
105
104
  await ext.apply(this, args);
106
105
  }
107
106
  catch (err) {
108
- instance.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, this.moduleName], err);
107
+ instance.writeFail(["Unknown", this.moduleName], err);
109
108
  }
110
109
  }
111
110
  }
@@ -127,7 +126,7 @@ class Document extends core_1.Client {
127
126
  map.sources = [""];
128
127
  }
129
128
  try {
130
- let css = mimeType === 'text/css', flags = 0 /* SOURCEMAP.NONE */;
129
+ let css = mimeType === 'text/css', flags = 0;
131
130
  const output = JSON.stringify(map);
132
131
  const toBase64 = () => 'data:application/json;base64,' + Buffer.from(output).toString('base64');
133
132
  if (!inlineMap) {
@@ -148,24 +147,24 @@ class Document extends core_1.Client {
148
147
  }
149
148
  }
150
149
  let code = data.code.replace(transform_1.SourceMap.RE_SOURCE_MAPPING_URL, (...capture) => {
151
- flags |= 1 /* SOURCEMAP.FOUND */;
150
+ flags |= 1;
152
151
  if (capture[2] && capture[5]) {
153
152
  css = true;
154
153
  }
155
154
  if (inlineMap || capture[3]) {
156
- flags |= 2 /* SOURCEMAP.INLINE */;
155
+ flags |= 2;
157
156
  return getSourceMappingURL(toBase64(), css);
158
157
  }
159
158
  return capture[1] || css ? getSourceMappingURL(sourceMappingURL, css) : capture[0];
160
159
  });
161
- if (inlineMap || flags & 2 /* SOURCEMAP.INLINE */) {
162
- if (flags === 0 /* SOURCEMAP.NONE */) {
160
+ if (inlineMap || flags & 2) {
161
+ if (flags === 0) {
163
162
  code += getSourceMappingURL(toBase64(), css);
164
163
  }
165
164
  data.code = code;
166
165
  }
167
166
  else {
168
- if (flags === 0 /* SOURCEMAP.NONE */) {
167
+ if (flags === 0) {
169
168
  code += getSourceMappingURL(sourceMappingURL, css);
170
169
  }
171
170
  const result = path.join(path.dirname(uri), sourceMappingURL);
@@ -276,7 +275,7 @@ class Document extends core_1.Client {
276
275
  for (const { severity, line, column, ruleId, message, fatal } of messages) {
277
276
  let error;
278
277
  if (severity) {
279
- if (error = severity === 2 /* LINT_SEVERITY.ERROR */ || severity === "error" /* LINT_SEVERITY.ERROR_TEXT */) {
278
+ if (error = severity === 2 || severity === "error") {
280
279
  ++errorCount;
281
280
  }
282
281
  else {
@@ -389,19 +388,18 @@ class Document extends core_1.Client {
389
388
  const handler = db.handler;
390
389
  const database = this.dataSource.filter(this.forDb.bind(this));
391
390
  let instance;
392
- if ((0, types_1.isString)(handler) && handler !== "@e-mc/db" /* PACKAGE_NAME.DB */) {
391
+ if ((0, types_1.isString)(handler) && handler !== "@e-mc/db") {
393
392
  try {
394
393
  const Handler = require(handler);
395
394
  if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
396
- // @ts-ignore
397
395
  instance = new Handler(db, database);
398
396
  }
399
397
  else {
400
- throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor" /* ERR_DB.CONSTRUCTOR */, handler);
398
+ throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor", handler);
401
399
  }
402
400
  }
403
401
  catch (err) {
404
- this.checkPackage(err, handler, ["Unable to load handler" /* ERR_MESSAGE.LOAD_HANDLER */, this.moduleName], 65536 /* LOG_TYPE.DB */);
402
+ this.checkPackage(err, handler, ["Unable to load handler", this.moduleName], 65536);
405
403
  }
406
404
  }
407
405
  else {
@@ -578,7 +576,7 @@ class Document extends core_1.Client {
578
576
  return getObject(result, false);
579
577
  }
580
578
  else {
581
- warning(path.isAbsolute(value) ? "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */ + ` (${value})` : "Unknown" /* ERR_MESSAGE.UNKNOWN */);
579
+ warning(path.isAbsolute(value) ? "Unsupported access" + ` (${value})` : "Unknown");
582
580
  }
583
581
  break;
584
582
  }
@@ -621,7 +619,7 @@ class Document extends core_1.Client {
621
619
  result = CACHE_REQUIRE[pkgName];
622
620
  }
623
621
  if (!result) {
624
- if (!core_1.Client.enabled("node.require.npm" /* KEY_NAME.NODE_REQUIRE_NPM */)) {
622
+ if (!core_1.Client.enabled("node.require.npm")) {
625
623
  return null;
626
624
  }
627
625
  try {
@@ -630,11 +628,11 @@ class Document extends core_1.Client {
630
628
  CACHE_REQUIRE[pkgName] = result;
631
629
  }
632
630
  if (typeof result === 'function') {
633
- return Object.defineProperty(result, "__cjs__" /* INTERNAL.CJS */, { value: true });
631
+ return Object.defineProperty(result, "__cjs__", { value: true });
634
632
  }
635
633
  }
636
634
  catch (err) {
637
- this.checkPackage(err, pkgName, "Unknown" /* ERR_MESSAGE.UNKNOWN */);
635
+ this.checkPackage(err, pkgName, "Unknown");
638
636
  }
639
637
  if (!result) {
640
638
  return null;
@@ -653,13 +651,12 @@ class Document extends core_1.Client {
653
651
  catch {
654
652
  }
655
653
  }
656
- // @ts-ignore
657
- if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__" /* INTERNAL.CJS */] || this.hasEval('function'))) {
654
+ if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__"] || this.hasEval('function'))) {
658
655
  return result;
659
656
  }
660
657
  }
661
658
  catch (err) {
662
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(value)], err, 8192 /* LOG_TYPE.PERMISSION */);
659
+ this.writeFail(["Unable to read file", path.basename(value)], err, 8192);
663
660
  }
664
661
  return null;
665
662
  }
@@ -809,7 +806,7 @@ class Document extends core_1.Client {
809
806
  }
810
807
  }
811
808
  catch (err) {
812
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, localUri && path.basename(localUri)], 32 /* LOG_TYPE.FILE */);
809
+ this.writeFail(["Unable to read file", localUri && path.basename(localUri)], 32);
813
810
  }
814
811
  }
815
812
  else if (bundleContent) {
@@ -865,7 +862,7 @@ class Document extends core_1.Client {
865
862
  catch (err) {
866
863
  const name = (0, util_1.getModuleName)(err);
867
864
  if (name) {
868
- this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown" /* ERR_MESSAGE.UNKNOWN */);
865
+ this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown");
869
866
  }
870
867
  throw err;
871
868
  }
@@ -903,7 +900,7 @@ class Document extends core_1.Client {
903
900
  if (!((0, types_1.isPlainObject)(target) && target.name)) {
904
901
  this.abort('view_engine');
905
902
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
906
- this.writeFail(["Unable to load configuration" /* ERR_MESSAGE.LOAD_CONFIG */, from], (0, types_1.errorMessage)('view-engine', from, "Unknown" /* ERR_MESSAGE.UNKNOWN */));
903
+ this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
907
904
  return null;
908
905
  }
909
906
  const length = data.length;
@@ -931,10 +928,10 @@ class Document extends core_1.Client {
931
928
  const cacheKey = username + core_1.Client.asHash(template + (compile ? core_1.Client.asString(compile) : ''));
932
929
  let result = '', render, valid;
933
930
  if (!(render = cache[cacheKey])) {
934
- render = await context.compile(template, compile); // eslint-disable-line @typescript-eslint/await-thenable
931
+ render = await context.compile(template, compile);
935
932
  cache[cacheKey] = render;
936
- if (!core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, username)) {
937
- setTimeout(() => delete cache[cacheKey], 60000 /* VALUES.TEMPLATE_EXPIRES */);
933
+ if (!core_1.Client.enabled("memory.settings.users", username)) {
934
+ setTimeout(() => delete cache[cacheKey], 60000);
938
935
  }
939
936
  }
940
937
  for (let i = 0, j = 0, row; i < length; ++i) {
@@ -945,11 +942,11 @@ class Document extends core_1.Client {
945
942
  }
946
943
  }
947
944
  else if (!(0, types_1.isObject)(row)) {
948
- this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
945
+ this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown"));
949
946
  continue;
950
947
  }
951
948
  if (!singleRow) {
952
- const content = await render.call(context, row); // eslint-disable-line @typescript-eslint/await-thenable
949
+ const content = await render.call(context, row);
953
950
  if (content !== undefined && content !== null) {
954
951
  result += content;
955
952
  valid = true;
@@ -960,7 +957,7 @@ class Document extends core_1.Client {
960
957
  }
961
958
  catch (err) {
962
959
  this.abort('view_engine');
963
- this.checkPackage(err, name, "Unknown" /* ERR_MESSAGE.UNKNOWN */, 4 /* LOG_TYPE.PROCESS */);
960
+ this.checkPackage(err, name, "Unknown", 4);
964
961
  }
965
962
  return null;
966
963
  }
@@ -974,7 +971,7 @@ class Document extends core_1.Client {
974
971
  const username = this.host?.username || '';
975
972
  const config = this._transformConfig;
976
973
  const cacheData = config && options.cacheData;
977
- const cacheType = username && core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */);
974
+ const cacheType = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
978
975
  let formatKey, hashKey, excludeKey;
979
976
  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)))) {
980
977
  const { uri, etag } = cacheData;
@@ -1050,7 +1047,7 @@ class Document extends core_1.Client {
1050
1047
  }
1051
1048
  if (result) {
1052
1049
  result.storedLog?.forEach(log => this.addLog(log));
1053
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
1050
+ this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
1054
1051
  return result;
1055
1052
  }
1056
1053
  }
@@ -1128,7 +1125,7 @@ class Document extends core_1.Client {
1128
1125
  if (typeof value !== 'string' || (0, types_1.isArray)(out.sourceFiles) && this.hasOwnPermission() && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
1129
1126
  failed = true;
1130
1127
  ignoreCache = true;
1131
- this.writeFail(["Unable to transform document" /* ERR_MESSAGE.TRANSFORM_DOCUMENT */, plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */ : 'Empty'), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1128
+ this.writeFail(["Unable to transform document", plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" : 'Empty'), { type: 4, startTime });
1132
1129
  }
1133
1130
  else if (source !== value) {
1134
1131
  series.code = value;
@@ -1160,19 +1157,18 @@ class Document extends core_1.Client {
1160
1157
  }
1161
1158
  this.writeTimeProcess(failed ? 'CHECK' : type, joinString(hint, options.filename) + (series.out.messageAppend || ''), startTime, { failed, bypassLog });
1162
1159
  };
1163
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
1160
+ this.formatMessage(4, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
1164
1161
  try {
1165
1162
  let context = require(plugin);
1166
1163
  series.packageName = plugin;
1167
1164
  if (typeof baseConfig === 'function') {
1168
1165
  series.baseConfig = outputConfig;
1169
- // @ts-ignore
1170
- if (baseConfig["__cjs__" /* INTERNAL.CJS */]) {
1166
+ if (baseConfig["__cjs__"]) {
1171
1167
  next(await baseConfig(context, source, series));
1172
1168
  }
1173
1169
  else {
1174
- const thisArg = core_1.Client.enabled("node.process.inline" /* KEY_NAME.NODE_PROCESS_INLINE */) ? process : null;
1175
- const inline = core_1.Client.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */);
1170
+ const thisArg = core_1.Client.enabled("node.process.inline") ? process : null;
1171
+ const inline = core_1.Client.enabled("node.require.inline");
1176
1172
  const args = [context, source, series];
1177
1173
  if (baseConfig.toString().startsWith('async')) {
1178
1174
  if (inline) {
@@ -1206,7 +1202,7 @@ class Document extends core_1.Client {
1206
1202
  }
1207
1203
  else {
1208
1204
  transformer = context;
1209
- context = this; // eslint-disable-line @typescript-eslint/no-this-alias
1205
+ context = this;
1210
1206
  pkg = undefined;
1211
1207
  }
1212
1208
  if (transformer && typeof transformer !== 'function') {
@@ -1221,7 +1217,7 @@ class Document extends core_1.Client {
1221
1217
  }
1222
1218
  catch (err) {
1223
1219
  abort();
1224
- this.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, username ? plugin + ':' + username : hint], err, { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1220
+ this.writeFail(["Unknown", username ? plugin + ':' + username : hint], err, { type: 4, startTime });
1225
1221
  continue;
1226
1222
  }
1227
1223
  }
@@ -1231,7 +1227,7 @@ class Document extends core_1.Client {
1231
1227
  }
1232
1228
  catch (err) {
1233
1229
  abort();
1234
- this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document" /* ERR_MESSAGE.TRANSFORM_DOCUMENT */, hint], { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1230
+ this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document", hint], { type: 4, startTime });
1235
1231
  if (i < length - 1) {
1236
1232
  series.reset();
1237
1233
  }
@@ -1240,10 +1236,10 @@ class Document extends core_1.Client {
1240
1236
  else {
1241
1237
  abort();
1242
1238
  if (plugin) {
1243
- this.writeFail("Unable to load configuration" /* ERR_MESSAGE.LOAD_CONFIG */, (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4 /* LOG_TYPE.PROCESS */);
1239
+ this.writeFail("Unable to load configuration", (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4);
1244
1240
  }
1245
1241
  else {
1246
- this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown" /* ERR_MESSAGE.UNKNOWN */), 4 /* LOG_TYPE.PROCESS */);
1242
+ this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown"), 4);
1247
1243
  }
1248
1244
  }
1249
1245
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,12 +17,12 @@
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.5",
24
- "@e-mc/db": "0.8.5",
25
- "@e-mc/types": "0.8.5",
23
+ "@e-mc/core": "0.8.6",
24
+ "@e-mc/db": "0.8.6",
25
+ "@e-mc/types": "0.8.6",
26
26
  "chalk": "4.1.2",
27
27
  "htmlparser2": "^9.1.0",
28
28
  "js-yaml": "^4.1.0",
package/parse/dom.js CHANGED
@@ -4,9 +4,9 @@ exports.IGNORE_FLAG = exports.HtmlElement = exports.DomWriter = void 0;
4
4
  const htmlparser2 = require("htmlparser2");
5
5
  const domhandler = require("domhandler");
6
6
  const domutils = require("domutils");
7
- const types_1 = require("../../types");
8
- const util_1 = require("../util");
9
- const index_1 = require("./index");
7
+ const types_1 = require("@e-mc/types");
8
+ const util_1 = require("@e-mc/document/util");
9
+ const index_1 = require("@e-mc/document/parse");
10
10
  Object.defineProperty(exports, "IGNORE_FLAG", { enumerable: true, get: function () { return index_1.IGNORE_FLAG; } });
11
11
  const Parser = htmlparser2.Parser;
12
12
  const DomHandler = domhandler.DomHandler;
@@ -89,7 +89,7 @@ class DomWriter extends index_1.XmlWriter {
89
89
  const result = { element: null, error: null };
90
90
  new Parser(new DomHandler((err, dom) => {
91
91
  if (!err) {
92
- result.element = domutils.findOne(elem => elem.tagName === "html" /* VALUES.ROOT */, dom);
92
+ result.element = domutils.findOne(elem => elem.tagName === "html", dom);
93
93
  }
94
94
  else {
95
95
  result.error = err;
@@ -111,8 +111,8 @@ class DomWriter extends index_1.XmlWriter {
111
111
  parser || (parser = { ...PARSER_OPTIONS });
112
112
  super(documentName, source, elements, { parser });
113
113
  this.documentElement = null;
114
- this.ignoreTagName = "title|style|script" /* VALUES.IGNORE_TAGNAME */;
115
- this.rootName = "html" /* VALUES.ROOT */;
114
+ this.ignoreTagName = "title|style|script";
115
+ this.rootName = "html";
116
116
  this.ignoreCaseTagName = true;
117
117
  const items = [];
118
118
  let outerXml = '', documentElement, offsetMap, startIndex = -1;
@@ -121,7 +121,7 @@ class DomWriter extends index_1.XmlWriter {
121
121
  item.tagName = item.tagName.toLowerCase();
122
122
  item.ignoreCase = true;
123
123
  }
124
- if (item.tagName === "html" /* VALUES.ROOT */) {
124
+ if (item.tagName === "html") {
125
125
  items.push(item);
126
126
  if (!documentElement && item.innerXml) {
127
127
  documentElement = item;
@@ -198,7 +198,7 @@ class DomWriter extends index_1.XmlWriter {
198
198
  if (this.modified && this.documentElement) {
199
199
  let innerXml;
200
200
  for (const item of this.elements) {
201
- if (item.tagName === "html" /* VALUES.ROOT */) {
201
+ if (item.tagName === "html") {
202
202
  if (!innerXml && index_1.XmlWriter.isIndex(item.endIndex)) {
203
203
  innerXml = this.source.substring(item.endIndex + 1, this.source.length - 7).trim();
204
204
  }
@@ -223,7 +223,7 @@ class HtmlElement extends index_1.XmlElement {
223
223
  constructor(documentName, node, attributes, options = {}) {
224
224
  options.parser || (options.parser = { ...PARSER_OPTIONS });
225
225
  super(documentName, node, attributes, { ...options, tagVoid: TAG_VOID.includes(node.tagName) });
226
- this._documentType = "HTML" /* VALUES.DOCUMENT_TYPE */;
226
+ this._documentType = "HTML";
227
227
  }
228
228
  getTagOffset(source) {
229
229
  switch (this.node.append?.tagName || this.tagName) {
@@ -233,7 +233,7 @@ class HtmlElement extends index_1.XmlElement {
233
233
  case 'script':
234
234
  return;
235
235
  default:
236
- return super.getTagOffset(source, { ignoreCase: this.ignoreCase, ignoreTagName: "title|style|script" /* VALUES.IGNORE_TAGNAME */, parser: this.parser });
236
+ return super.getTagOffset(source, { ignoreCase: this.ignoreCase, ignoreTagName: "title|style|script", parser: this.parser });
237
237
  }
238
238
  }
239
239
  findIndexOf(source) {
@@ -244,8 +244,8 @@ class HtmlElement extends index_1.XmlElement {
244
244
  }
245
245
  get outerXml() {
246
246
  const [tagName, items, innerXml] = this.getOuterContent();
247
- return '<' + tagName + HtmlElement.writeAttributes(items) + '>' + (DomWriter.hasInnerXml(tagName) && tagName !== "html" /* VALUES.ROOT */ ? (tagName === 'title' ? index_1.XmlWriter.escapeXmlString(innerXml) : innerXml) + `</${tagName}>` : '');
247
+ return '<' + tagName + HtmlElement.writeAttributes(items) + '>' + (DomWriter.hasInnerXml(tagName) && tagName !== "html" ? (tagName === 'title' ? index_1.XmlWriter.escapeXmlString(innerXml) : innerXml) + `</${tagName}>` : '');
248
248
  }
249
249
  }
250
250
  exports.HtmlElement = HtmlElement;
251
- index_1.XmlWriter.namesOfTagVoid("HTML" /* VALUES.DOCUMENT_TYPE */, TAG_VOID);
251
+ index_1.XmlWriter.namesOfTagVoid("HTML", TAG_VOID);
package/parse/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
- /* eslint @typescript-eslint/prefer-includes: off */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.XmlElement = exports.XmlWriter = exports.IGNORE_FLAG = void 0;
5
4
  const htmlparser2 = require("htmlparser2");
6
5
  const domhandler = require("domhandler");
7
6
  const domutils = require("domutils");
8
- const types_1 = require("../../types");
9
- const module_1 = require("../../module");
7
+ const types_1 = require("@e-mc/types");
8
+ const module_1 = require("@e-mc/module");
10
9
  var IGNORE_FLAG;
11
10
  (function (IGNORE_FLAG) {
12
11
  IGNORE_FLAG[IGNORE_FLAG["NONE"] = 0] = "NONE";
@@ -3,8 +3,8 @@ var _a, _b, _c, _d;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.SourceMap = exports.TransformSeries = void 0;
5
5
  const path = require("path");
6
- const types_1 = require("../../types");
7
- const core_1 = require("../../core");
6
+ const types_1 = require("@e-mc/types");
7
+ const core_1 = require("@e-mc/core");
8
8
  const kCode = Symbol('code');
9
9
  const kMap = Symbol('map');
10
10
  const kOut = Symbol('out');
@@ -185,20 +185,16 @@ class TransformSeries extends core_1.Module {
185
185
  return this.options.external;
186
186
  }
187
187
  set version(value) {
188
- // @ts-ignore
189
188
  this.metadata.__version__ = value;
190
189
  }
191
190
  get version() {
192
- // @ts-ignore
193
191
  return this.metadata.__version__ || '';
194
192
  }
195
193
  set packageName(value) {
196
- // @ts-ignore
197
194
  this.metadata.__packagename__ = value;
198
195
  this.version = 'latest';
199
196
  }
200
197
  get packageName() {
201
- // @ts-ignore
202
198
  return this.metadata.__packagename__ || '';
203
199
  }
204
200
  get packageVersion() {
package/util.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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
4
  const path = require("path");
5
- const types_1 = require("../types");
5
+ const types_1 = require("@e-mc/types");
6
6
  Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
7
7
  exports.IMPORTS = {
8
8
  "@babel/core": "@pi-r/babel",
@@ -50,7 +50,7 @@ function replaceAll(source, valueOf, opening = '{{', closing = '}}') {
50
50
  exports.replaceAll = replaceAll;
51
51
  function concatString(values, newline) {
52
52
  if ((0, types_1.isArray)(values)) {
53
- newline || (newline = values.find(item => item.indexOf('\r') !== -1) ? '\r\n' : '\n'); // eslint-disable-line @typescript-eslint/prefer-includes
53
+ newline || (newline = values.find(item => item.indexOf('\r') !== -1) ? '\r\n' : '\n');
54
54
  return values.reduce((a, b) => a + newline + b, '');
55
55
  }
56
56
  return typeof values === 'string' ? values : '';