@aitianyu.cn/types 0.0.2 → 0.0.3

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 (47) hide show
  1. package/dist/lib/index.js +16 -5
  2. package/dist/lib/types/AreaCode.js +1 -0
  3. package/dist/lib/types/Exception.js +6 -0
  4. package/dist/lib/types/Logs.js +7 -0
  5. package/dist/lib/types/PathBase.js +109 -0
  6. package/dist/lib/types/Security.js +1 -0
  7. package/dist/lib/types/TMap.js +138 -0
  8. package/dist/lib/types/index.js +17 -0
  9. package/dist/lib/utilities/coding/Error.js +22 -1
  10. package/dist/lib/utilities/coding/Path.js +198 -0
  11. package/dist/lib/utilities/coding/index.js +10 -0
  12. package/dist/lib/utilities/core/Errors.js +64 -1
  13. package/dist/lib/utilities/core/Language.js +13 -0
  14. package/dist/lib/utilities/core/Log.js +2 -0
  15. package/dist/lib/utilities/core/index.js +21 -0
  16. package/dist/lib/utilities/core/object/Calculater.js +230 -0
  17. package/dist/lib/utilities/core/{ObjectHelper.js → object/Helper.js} +1 -1
  18. package/dist/lib/utilities/security/Guid.js +1 -0
  19. package/dist/lib/utilities/security/Hash.js +1 -0
  20. package/dist/lib/utilities/security/index.js +8 -0
  21. package/dist/types/index.d.ts +9 -6
  22. package/dist/types/types/AreaCode.d.ts +1 -0
  23. package/dist/types/types/Exception.d.ts +6 -0
  24. package/dist/types/types/Logs.d.ts +43 -0
  25. package/dist/types/types/Object.d.ts +18 -0
  26. package/dist/types/types/PathBase.d.ts +76 -0
  27. package/dist/types/types/Security.d.ts +14 -0
  28. package/dist/types/types/TMap.d.ts +80 -0
  29. package/dist/types/types/Types.d.ts +13 -0
  30. package/dist/types/types/index.d.ts +9 -0
  31. package/dist/types/utilities/coding/Error.d.ts +17 -0
  32. package/dist/types/utilities/coding/Path.d.ts +61 -0
  33. package/dist/types/utilities/coding/index.d.ts +3 -0
  34. package/dist/types/utilities/core/Errors.d.ts +37 -0
  35. package/dist/types/utilities/core/Language.d.ts +13 -0
  36. package/dist/types/utilities/core/Log.d.ts +2 -0
  37. package/dist/types/utilities/core/index.d.ts +6 -0
  38. package/dist/types/utilities/core/object/Calculater.d.ts +22 -0
  39. package/dist/types/utilities/security/Guid.d.ts +1 -0
  40. package/dist/types/utilities/security/Hash.d.ts +1 -0
  41. package/dist/types/utilities/security/index.d.ts +3 -0
  42. package/package.json +5 -2
  43. package/dist/lib/utilities/coding/PathProcessor.js +0 -108
  44. package/dist/types/types/Coding.d.ts +0 -7
  45. package/dist/types/utilities/coding/PathProcessor.d.ts +0 -6
  46. /package/dist/lib/types/{Coding.js → Object.js} +0 -0
  47. /package/dist/types/utilities/core/{ObjectHelper.d.ts → object/Helper.d.ts} +0 -0
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  /**@format */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ObjectCloneFunctionNotSupportException = exports.ArgumentNullOrEmptyException = void 0;
4
+ exports.ObjectDiffMergeFailedException = exports.ObjectDiffApplyInvalidStatusException = exports.ObjectMergeStatusCheckFailedException = exports.ObjectCloneFunctionNotSupportException = exports.ArgumentNullOrEmptyException = void 0;
5
5
  const Exception_1 = require("../../types/Exception");
6
+ /** Argument null exception */
6
7
  class ArgumentNullOrEmptyException extends Exception_1.Exception {
7
8
  constructor(msg) {
8
9
  super(msg);
@@ -12,6 +13,11 @@ class ArgumentNullOrEmptyException extends Exception_1.Exception {
12
13
  }
13
14
  }
14
15
  exports.ArgumentNullOrEmptyException = ArgumentNullOrEmptyException;
16
+ /**
17
+ * Object Clone:
18
+ * Function type is not supported.
19
+ * Exception will be thrown if try to clone a function type object
20
+ */
15
21
  class ObjectCloneFunctionNotSupportException extends Exception_1.Exception {
16
22
  constructor() {
17
23
  super();
@@ -21,3 +27,60 @@ class ObjectCloneFunctionNotSupportException extends Exception_1.Exception {
21
27
  }
22
28
  }
23
29
  exports.ObjectCloneFunctionNotSupportException = ObjectCloneFunctionNotSupportException;
30
+ /**
31
+ * Object Clone:
32
+ * Object different status could not be matched.
33
+ * Exception will be thrown if the object diff could not to be merged
34
+ */
35
+ class ObjectMergeStatusCheckFailedException extends Exception_1.Exception {
36
+ status;
37
+ path;
38
+ constructor(path, status) {
39
+ super();
40
+ this.path = path;
41
+ this.status = status === "add" ? "新增" : status === "del" ? "删除" : "修改";
42
+ }
43
+ toString() {
44
+ return `错误的合并状态 - ${this.status} 路径 ${this.path} 前后状态不一致`;
45
+ }
46
+ }
47
+ exports.ObjectMergeStatusCheckFailedException = ObjectMergeStatusCheckFailedException;
48
+ /**
49
+ * Object Clone:
50
+ * Object different status could not be applied.
51
+ * Exception will be thrown if the object diff could not to be applied
52
+ */
53
+ class ObjectDiffApplyInvalidStatusException extends Exception_1.Exception {
54
+ value;
55
+ constructor(value) {
56
+ super();
57
+ this.value = value;
58
+ }
59
+ toString() {
60
+ let v2s = "";
61
+ try {
62
+ v2s = JSON.stringify(this.value);
63
+ }
64
+ finally {
65
+ v2s = v2s || `[${(typeof this.value).toString()}]`;
66
+ }
67
+ return `无效的状态 - 值 ${v2s} 不能应用指定的状态`;
68
+ }
69
+ }
70
+ exports.ObjectDiffApplyInvalidStatusException = ObjectDiffApplyInvalidStatusException;
71
+ /**
72
+ * Object Clone:
73
+ * Object different merge failed.
74
+ * Exception will be thrown if the object element could not be accessed
75
+ */
76
+ class ObjectDiffMergeFailedException extends Exception_1.Exception {
77
+ path;
78
+ constructor(path) {
79
+ super();
80
+ this.path = path;
81
+ }
82
+ toString() {
83
+ return `对象合并遇到问题 - 路径 ${this.path} 存在无法访问的对象`;
84
+ }
85
+ }
86
+ exports.ObjectDiffMergeFailedException = ObjectDiffMergeFailedException;
@@ -536,10 +536,23 @@ function _areaCodeToString(eArea) {
536
536
  return "zh_CN";
537
537
  }
538
538
  }
539
+ /**
540
+ * Parse area code to general string
541
+ *
542
+ * @param eArea the area code
543
+ * @returns return the general string of specified area code
544
+ */
539
545
  function parseAreaCode(eArea) {
540
546
  return _areaCodeToString(eArea);
541
547
  }
542
548
  exports.parseAreaCode = parseAreaCode;
549
+ /**
550
+ * Convert the string to area code
551
+ *
552
+ * @param areaStr the source string
553
+ * @param forceArea a boolean value indicates whether needs to have a strict check for the source string. (That means if in strict mode and the string could not be converted, an unkonwn will be returned.)
554
+ * @returns return the area code
555
+ */
543
556
  function parseAreaString(areaStr, forceArea) {
544
557
  return _parseAreaString(areaStr, forceArea);
545
558
  }
@@ -99,7 +99,9 @@ function _endPerf(recorder, console) {
99
99
  }
100
100
  return perfTime;
101
101
  }
102
+ /** Tianyu Log Instance */
102
103
  exports.Log = _log;
104
+ /** Tianyu Performance Instance */
103
105
  exports.Performance = {
104
106
  startPerf: _startPerf,
105
107
  endPerf: _endPerf,
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**@format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ObjectHelper = exports.ObjectCalculater = exports.Performance = exports.Log = exports.parseAreaString = exports.parseAreaCode = exports.ObjectDiffMergeFailedException = exports.ObjectDiffApplyInvalidStatusException = exports.ObjectMergeStatusCheckFailedException = exports.ObjectCloneFunctionNotSupportException = exports.ArgumentNullOrEmptyException = void 0;
5
+ var Errors_1 = require("./Errors");
6
+ Object.defineProperty(exports, "ArgumentNullOrEmptyException", { enumerable: true, get: function () { return Errors_1.ArgumentNullOrEmptyException; } });
7
+ Object.defineProperty(exports, "ObjectCloneFunctionNotSupportException", { enumerable: true, get: function () { return Errors_1.ObjectCloneFunctionNotSupportException; } });
8
+ Object.defineProperty(exports, "ObjectMergeStatusCheckFailedException", { enumerable: true, get: function () { return Errors_1.ObjectMergeStatusCheckFailedException; } });
9
+ Object.defineProperty(exports, "ObjectDiffApplyInvalidStatusException", { enumerable: true, get: function () { return Errors_1.ObjectDiffApplyInvalidStatusException; } });
10
+ Object.defineProperty(exports, "ObjectDiffMergeFailedException", { enumerable: true, get: function () { return Errors_1.ObjectDiffMergeFailedException; } });
11
+ var Language_1 = require("./Language");
12
+ Object.defineProperty(exports, "parseAreaCode", { enumerable: true, get: function () { return Language_1.parseAreaCode; } });
13
+ Object.defineProperty(exports, "parseAreaString", { enumerable: true, get: function () { return Language_1.parseAreaString; } });
14
+ var Log_1 = require("./Log");
15
+ Object.defineProperty(exports, "Log", { enumerable: true, get: function () { return Log_1.Log; } });
16
+ Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return Log_1.Performance; } });
17
+ //// object
18
+ var Calculater_1 = require("./object/Calculater");
19
+ Object.defineProperty(exports, "ObjectCalculater", { enumerable: true, get: function () { return Calculater_1.ObjectCalculater; } });
20
+ var Helper_1 = require("./object/Helper");
21
+ Object.defineProperty(exports, "ObjectHelper", { enumerable: true, get: function () { return Helper_1.ObjectHelper; } });
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /**@format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ObjectCalculater = void 0;
5
+ const TMap_1 = require("../../../types/TMap");
6
+ const PathBase_1 = require("../../../types/PathBase");
7
+ const Helper_1 = require("./Helper");
8
+ const Errors_1 = require("../Errors");
9
+ class ObjectDiffCalculation {
10
+ preObj;
11
+ nextObj;
12
+ objStack;
13
+ diffs;
14
+ constructor(pre, next) {
15
+ this.preObj = pre;
16
+ this.nextObj = next;
17
+ this.objStack = [];
18
+ this.diffs = new TMap_1.TMap();
19
+ }
20
+ calculate() {
21
+ this._calculate(this.preObj, this.nextObj);
22
+ return this.diffs;
23
+ }
24
+ _calculate(pre, next) {
25
+ const isPreSimple = Helper_1.ObjectHelper.isSimpleDataType(pre);
26
+ const isNextSimple = Helper_1.ObjectHelper.isSimpleDataType(next);
27
+ // 如果是基本数据类型
28
+ if (isPreSimple && isNextSimple) {
29
+ // 如果数据不相同,则记录
30
+ if (pre !== next) {
31
+ const path = new PathBase_1.PathBase(this.objStack);
32
+ this.diffs.set(path, {
33
+ path: path.toString(),
34
+ old: Helper_1.ObjectHelper.clone(pre),
35
+ new: Helper_1.ObjectHelper.clone(next),
36
+ });
37
+ }
38
+ // 直接返回
39
+ return;
40
+ }
41
+ // 获取新老对象是否为数组类型
42
+ const isPreArray = Array.isArray(pre);
43
+ const isNextArray = Array.isArray(next);
44
+ if (isPreArray || isNextArray) {
45
+ const path = new PathBase_1.PathBase(this.objStack);
46
+ if (isPreArray && isNextArray) {
47
+ // Pre为数组 Next为数组
48
+ const isSame = Helper_1.ObjectHelper.compareObjects(pre, next);
49
+ if (isSame === "different") {
50
+ this.diffs.set(path, {
51
+ path: path.toString(),
52
+ old: Helper_1.ObjectHelper.clone(pre),
53
+ new: Helper_1.ObjectHelper.clone(next),
54
+ });
55
+ }
56
+ }
57
+ else {
58
+ // Pre或Next为数组,另外一个为object类型
59
+ // Pre为简单对象 & Next为数组
60
+ // Pre为数组 & Next为简单对象
61
+ this.diffs.set(path, {
62
+ path: path.toString(),
63
+ old: Helper_1.ObjectHelper.clone(pre),
64
+ new: Helper_1.ObjectHelper.clone(next),
65
+ });
66
+ }
67
+ return;
68
+ }
69
+ // 新老对象都是Object类型,按照Object类型进行比对
70
+ this._calculateObject(pre, next);
71
+ }
72
+ _calculateObject(pre, next) {
73
+ const preKeys = Object.keys(pre);
74
+ const nextKeys = Object.keys(next);
75
+ const sameItems = [];
76
+ // 寻找已经删除的
77
+ for (const key of preKeys) {
78
+ if (nextKeys.includes(key)) {
79
+ sameItems.push(key);
80
+ }
81
+ else {
82
+ // 已经被删除的对象,储存下来
83
+ this.objStack.push(key);
84
+ const path = new PathBase_1.PathBase(this.objStack);
85
+ this.diffs.set(path, {
86
+ path: path.toString(),
87
+ old: Helper_1.ObjectHelper.clone(pre[key]),
88
+ new: undefined,
89
+ deleted: true,
90
+ });
91
+ this.objStack.pop();
92
+ }
93
+ }
94
+ // 寻找新加的元素
95
+ for (const key of nextKeys) {
96
+ if (!preKeys.includes(key)) {
97
+ // 老的对象中不存在,新加的状态储存下来
98
+ this.objStack.push(key);
99
+ const path = new PathBase_1.PathBase(this.objStack);
100
+ this.diffs.set(path, {
101
+ path: path.toString(),
102
+ old: undefined,
103
+ new: Helper_1.ObjectHelper.clone(next[key]),
104
+ added: true,
105
+ });
106
+ this.objStack.pop();
107
+ }
108
+ }
109
+ // 依次遍历所有相同的元素,判断其是否存在改变
110
+ for (const key of sameItems) {
111
+ this.objStack.push(key);
112
+ this._calculate(pre[key], next[key]);
113
+ this.objStack.pop();
114
+ }
115
+ }
116
+ }
117
+ function __checkOldAndNewStatus(pre, next) {
118
+ return Helper_1.ObjectHelper.compareObjects(pre, next) === "same";
119
+ }
120
+ /** Object Calculation Manager of Tianyu to provide data changes delta calculation and merge */
121
+ class ObjectCalculater {
122
+ /**
123
+ * Compare two objects and get the delta changes between the two objects
124
+ *
125
+ * @param previous the previous object
126
+ * @param newest the newest object
127
+ * @returns return the defferents map
128
+ */
129
+ static calculateDiff(previous, newest) {
130
+ const calculationEntity = new ObjectDiffCalculation(previous, newest);
131
+ return calculationEntity.calculate();
132
+ }
133
+ /**
134
+ * Merge the object value status from one to another one following with the object different maps
135
+ *
136
+ * @param value the raw value(status)
137
+ * @param diffs the value changed status map array, contains multiply status maps and the status merge will be one by one.
138
+ * @param strict a boolean value used to whether the program needs a strict status check to avoid some data errors
139
+ * @returns return a new value status
140
+ */
141
+ static mergeDiff(value, diffs, strict) {
142
+ const resultObj = { root: Helper_1.ObjectHelper.clone(value) };
143
+ if (0 === diffs.length) {
144
+ return resultObj.root;
145
+ }
146
+ for (const diff of diffs) {
147
+ const rootPathDiff = diff.get(new PathBase_1.PathBase([]));
148
+ if (rootPathDiff) {
149
+ if (strict && diff.size() > 1) {
150
+ throw new Errors_1.ObjectDiffApplyInvalidStatusException(resultObj.root);
151
+ }
152
+ if (strict && !__checkOldAndNewStatus(resultObj.root, rootPathDiff.old)) {
153
+ throw new Errors_1.ObjectMergeStatusCheckFailedException("", rootPathDiff.deleted ? "del" : rootPathDiff.added ? "add" : "modify");
154
+ }
155
+ // 直接设置新值
156
+ resultObj.root = Helper_1.ObjectHelper.clone(rootPathDiff.new);
157
+ // 原始值为简单数据类型 或 数组类型 需要根目录修改
158
+ }
159
+ else if (Helper_1.ObjectHelper.isSimpleDataType(resultObj.root) || Array.isArray(resultObj.root)) {
160
+ throw new Errors_1.ObjectDiffApplyInvalidStatusException(resultObj.root);
161
+ }
162
+ else {
163
+ // 没有根目录修改
164
+ // 并且对象不是简单类型
165
+ // 按照复杂值递归进行更改
166
+ // 依次遍历所有的路径
167
+ for (const [path, info] of diff) {
168
+ // 此处不应该进入条件
169
+ if (!!!path || !!!info)
170
+ continue;
171
+ // 获取路径并预处理
172
+ const pathDir = path.getDirs();
173
+ const endDir = pathDir.pop();
174
+ // 此处不应该进入条件
175
+ if (!!!endDir)
176
+ continue;
177
+ const mergeType = info.added ? "add" : info.deleted ? "del" : "modify";
178
+ // 依次查询元素路径
179
+ // 检查父元素是否不存在(error)
180
+ let obj = resultObj.root;
181
+ for (const key of pathDir) {
182
+ if (!!!obj[key]) {
183
+ // 如果父对象不存在 在严格模式下抛出异常
184
+ if (strict) {
185
+ throw new Errors_1.ObjectMergeStatusCheckFailedException(info.path, mergeType);
186
+ }
187
+ else {
188
+ obj[key] = {};
189
+ }
190
+ }
191
+ // 目标点向下移动
192
+ obj = obj[key];
193
+ }
194
+ // 再次检查对象状态 (理论上不应该进入此判断)
195
+ if (!!!obj)
196
+ throw new Errors_1.ObjectDiffMergeFailedException(info.path);
197
+ if (info.added) {
198
+ // 新增一个元素
199
+ // 严格模式下 不允许新增对象存在
200
+ if (strict && obj[endDir]) {
201
+ throw new Errors_1.ObjectMergeStatusCheckFailedException(info.path, mergeType);
202
+ }
203
+ // 执行拷贝
204
+ obj[endDir] = Helper_1.ObjectHelper.clone(info.new);
205
+ }
206
+ else if (info.deleted) {
207
+ // 删除一个元素
208
+ // 严格模式下 不允许删除对象不存在
209
+ if (strict && !!!obj[endDir]) {
210
+ throw new Errors_1.ObjectMergeStatusCheckFailedException(info.path, mergeType);
211
+ }
212
+ // 执行删除(如果对象存在)
213
+ !!obj[endDir] && delete obj[endDir];
214
+ }
215
+ else {
216
+ // 修改一个元素
217
+ // 严格模式下 不允许修改对象不存在
218
+ if (strict && (!!!obj[endDir] || __checkOldAndNewStatus(info.old, obj[endDir]))) {
219
+ throw new Errors_1.ObjectMergeStatusCheckFailedException(info.path, mergeType);
220
+ }
221
+ // 执行修改
222
+ obj[endDir] = Helper_1.ObjectHelper.clone(info.new);
223
+ }
224
+ }
225
+ }
226
+ }
227
+ return resultObj.root;
228
+ }
229
+ }
230
+ exports.ObjectCalculater = ObjectCalculater;
@@ -2,7 +2,7 @@
2
2
  /**@format */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ObjectHelper = void 0;
5
- const Errors_1 = require("./Errors");
5
+ const Errors_1 = require("../Errors");
6
6
  /** Object Helper of Tianyu to provide data type checking, objects comparing, validation, data clone and other functions */
7
7
  class ObjectHelper {
8
8
  /**
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.guid = void 0;
5
5
  const perf_hooks_1 = require("perf_hooks");
6
+ /** Generate a Guid value string */
6
7
  function guid() {
7
8
  let d = new Date().getTime();
8
9
  d += perf_hooks_1.performance.now(); //use high-precision timer if available
@@ -2,6 +2,7 @@
2
2
  /**@format */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.hash = void 0;
5
+ /** Generate a hash code number of the string */
5
6
  function hash(source) {
6
7
  let length = source.length;
7
8
  let hashCode = 0;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**@format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.hash = exports.guid = void 0;
5
+ var Guid_1 = require("./Guid");
6
+ Object.defineProperty(exports, "guid", { enumerable: true, get: function () { return Guid_1.guid; } });
7
+ var Hash_1 = require("./Hash");
8
+ Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return Hash_1.hash; } });
@@ -1,15 +1,18 @@
1
1
  /**@format */
2
2
  export { AreaCode } from "./types/AreaCode";
3
- export { type PathTargetType, type IPath } from "./types/Coding";
4
3
  export { Exception } from "./types/Exception";
5
4
  export { LogLevel, type ILog, type IPerfRecorder } from "./types/Logs";
5
+ export { type IObjectDiffInfo, type ObjectDiffMap } from "./types/Object";
6
+ export { PathBase } from "./types/PathBase";
6
7
  export { EncryptOption, type ICipher } from "./types/Security";
7
- export { type MapOfBoolean, type MapOfStrings, type MapOfString, type MapOfType, type CallbackAction, type CallbackActionT, } from "./types/Types";
8
- export { PathProcessorSourceLostException, PathDirectoryValidationFailException } from "./utilities/coding/Error";
9
- export { PathProcessor } from "./utilities/coding/PathProcessor";
10
- export { ArgumentNullOrEmptyException, ObjectCloneFunctionNotSupportException } from "./utilities/core/Errors";
8
+ export { TMap } from "./types/TMap";
9
+ export { type MapOfBoolean, type MapOfStrings, type MapOfString, type MapOfType, type CallbackAction, type CallbackActionT, type IComparable, } from "./types/Types";
10
+ export { PathProcessorSourceLostException, PathDirectoryValidationFailException, PathDirAndFileConvertInvaild, } from "./utilities/coding/Error";
11
+ export { type PathTargetType, Path } from "./utilities/coding/Path";
12
+ export { ArgumentNullOrEmptyException, ObjectCloneFunctionNotSupportException, ObjectMergeStatusCheckFailedException, ObjectDiffApplyInvalidStatusException, ObjectDiffMergeFailedException, } from "./utilities/core/Errors";
11
13
  export { parseAreaCode, parseAreaString } from "./utilities/core/Language";
12
14
  export { Log, Performance } from "./utilities/core/Log";
13
- export { ObjectHelper } from "./utilities/core/ObjectHelper";
15
+ export { ObjectCalculater } from "./utilities/core/object/Calculater";
16
+ export { ObjectHelper } from "./utilities/core/object/Helper";
14
17
  export { guid } from "./utilities/security/Guid";
15
18
  export { hash } from "./utilities/security/Hash";
@@ -1,4 +1,5 @@
1
1
  /**@format */
2
+ /** International Area name and its code */
2
3
  export declare enum AreaCode {
3
4
  unknown = 0,
4
5
  af_ZA = 1078,
@@ -1,5 +1,11 @@
1
1
  /**@format */
2
+ /** Exception base class */
2
3
  export declare class Exception extends Error {
3
4
  constructor(msg?: string, options?: ErrorOptions);
5
+ /**
6
+ * Get a string of the Exception object
7
+ *
8
+ * @returns return an error message
9
+ */
4
10
  toString(): string;
5
11
  }
@@ -1,21 +1,64 @@
1
1
  /**@format */
2
+ /** Tianyu Log Level */
2
3
  export declare enum LogLevel {
4
+ /** Debug mode log */
3
5
  DEBUG = 0,
6
+ /** error msg */
4
7
  ERROR = 1,
8
+ /** fatal error msg */
5
9
  FATAL = 2,
10
+ /** info log */
6
11
  INFO = 3,
12
+ /** warning log */
7
13
  WARNING = 4,
14
+ /** default log */
8
15
  LOG = 5
9
16
  }
17
+ /** Tianyu Log Interface */
10
18
  export interface ILog {
19
+ /**
20
+ * Write a console log with specified log level
21
+ *
22
+ * @param msg the message body
23
+ * @param level the console log level, if not be specified, to print as default log
24
+ * @param timer a boolean value indicates whether needs to add a timestamp for the log
25
+ */
11
26
  log(msg: string, level?: LogLevel, timer?: boolean): void;
27
+ /**
28
+ * Write a console info log
29
+ * @param msg the message body
30
+ * @param timer a boolean value indicates whether needs to add a timestamp for the log
31
+ */
12
32
  info(msg: string, timer?: boolean): void;
33
+ /**
34
+ * Write a console warning log
35
+ * @param msg the message body
36
+ * @param timer a boolean value indicates whether needs to add a timestamp for the log
37
+ */
13
38
  warn(msg: string, timer?: boolean): void;
39
+ /**
40
+ * Write a console debug log
41
+ * @param msg the message body
42
+ * @param timer a boolean value indicates whether needs to add a timestamp for the log
43
+ */
14
44
  debug(msg: string, timer?: boolean): void;
45
+ /**
46
+ * Write a console error message
47
+ * @param msg the message body
48
+ * @param timer a boolean value indicates whether needs to add a timestamp for the log
49
+ */
15
50
  error(msg: string, timer?: boolean): void;
51
+ /**
52
+ * Write a console fatal message
53
+ * @param msg the message body
54
+ * @param timer a boolean value indicates whether needs to add a timestamp for the log
55
+ */
16
56
  fatal(msg: string, timer?: boolean): void;
17
57
  }
58
+ /** Tianyu Performance recorder */
18
59
  export interface IPerfRecorder {
60
+ /** the recording id */
19
61
  id: string;
62
+ /** the start time number */
20
63
  start: number;
21
64
  }
@@ -0,0 +1,18 @@
1
+ /**@format */
2
+ import { TMap } from "./TMap";
3
+ import { PathBase } from "./PathBase";
4
+ /** Tianyu Object calculated different item */
5
+ export interface IObjectDiffInfo {
6
+ /** different item path */
7
+ path: string;
8
+ /** the old value of this path */
9
+ old: any;
10
+ /** the new value of this path */
11
+ new: any;
12
+ /** does the change be deletion */
13
+ deleted?: true;
14
+ /** does the change be adding */
15
+ added?: true;
16
+ }
17
+ /** Different items map */
18
+ export type ObjectDiffMap = TMap<PathBase, IObjectDiffInfo>;
@@ -0,0 +1,76 @@
1
+ /**@format */
2
+ import { IComparable } from "./Types";
3
+ /** Path base class */
4
+ export declare class PathBase implements IComparable {
5
+ protected _dirs: string[];
6
+ /**
7
+ * Create a Path instance by specified dirs
8
+ *
9
+ * @param dirs the specified directories
10
+ */
11
+ constructor(dirs?: string[]);
12
+ /**
13
+ * Convert the path instance to string
14
+ *
15
+ * @returns return the fromatted string
16
+ */
17
+ toString(): string;
18
+ /**
19
+ * Iterator of path directories
20
+ *
21
+ * @returns return an iterator
22
+ */
23
+ [Symbol.iterator](): {
24
+ next: () => {
25
+ done: boolean;
26
+ value: string;
27
+ };
28
+ };
29
+ /**
30
+ * Get a directories array deep copy
31
+ *
32
+ * @returns return directories
33
+ */
34
+ getDirs(): string[];
35
+ /**
36
+ * Get a number that indicates the directories count
37
+ *
38
+ * @returns return the directories count
39
+ */
40
+ length(): number;
41
+ /**
42
+ * Append a new directory to the end of path
43
+ *
44
+ * @param dir the new directory name
45
+ * @returns return the new directories count
46
+ */
47
+ append(dir: string): number;
48
+ /**
49
+ * Clean all the pathes
50
+ */
51
+ clear(): void;
52
+ /**
53
+ * Remove the end directory of the path instance and return it
54
+ *
55
+ * @returns return the end of directory
56
+ */
57
+ pop(): string | undefined;
58
+ /**
59
+ * Remove the first directory of the path instance and return it
60
+ *
61
+ * @returns return the first directory
62
+ */
63
+ shift(): string | undefined;
64
+ /**
65
+ * Convert the path instance to string for object comparing
66
+ *
67
+ * @returns return the comparable string
68
+ */
69
+ getString(): string;
70
+ /**
71
+ * Get the hashcode of current path
72
+ *
73
+ * @returns always return 0
74
+ */
75
+ getHashCode(): number;
76
+ }
@@ -1,9 +1,23 @@
1
1
  /**@format */
2
+ /** Encrypt Option Type */
2
3
  export declare enum EncryptOption {
3
4
  Encryption = 0,
4
5
  Decryption = 1
5
6
  }
7
+ /** An Interface of the Cipher */
6
8
  export interface ICipher {
9
+ /**
10
+ * To encode the source value
11
+ *
12
+ * @param source the source value
13
+ * @returns return the encoded value
14
+ */
7
15
  encryption(source: number[]): number[];
16
+ /**
17
+ * To decode the encoded value
18
+ *
19
+ * @param source the encoded value
20
+ * @returns return the decoded value
21
+ */
8
22
  decryption(source: number[]): number[];
9
23
  }