@aitianyu.cn/types 0.0.13 → 0.1.0

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 (87) hide show
  1. package/dist/lib/{utilities/coding → coding}/Error.js +44 -44
  2. package/dist/lib/{utilities/coding → coding}/Path.js +210 -198
  3. package/dist/lib/{utilities/core → core}/Errors.js +86 -86
  4. package/dist/lib/{utilities/core → core}/Language.js +561 -559
  5. package/dist/lib/{utilities/core → core}/Log.js +112 -108
  6. package/dist/lib/{utilities/core → core}/TypeConvertion.js +25 -25
  7. package/dist/lib/{utilities/core → core}/interface/ITJSON.js +3 -3
  8. package/dist/lib/{utilities/core → core}/interface/ITianyuType.js +3 -3
  9. package/dist/lib/{utilities/core → core}/object/ArrayHelper.js +35 -35
  10. package/dist/lib/core/object/Bytes.js +21 -0
  11. package/dist/lib/{utilities/core → core}/object/Calculater.js +240 -230
  12. package/dist/lib/core/object/DataView.js +23 -0
  13. package/dist/lib/core/object/Integer.js +117 -0
  14. package/dist/lib/core/object/Json.js +35 -0
  15. package/dist/lib/{utilities/core/object/Helper.js → core/object/ObjectHelper.js} +202 -201
  16. package/dist/lib/core/object/StringHelper.js +61 -0
  17. package/dist/lib/{utilities/core → core}/type/TArray.js +8 -7
  18. package/dist/lib/{utilities/core → core}/type/TBoolean.js +7 -7
  19. package/dist/lib/{utilities/core → core}/type/TJSON.js +7 -7
  20. package/dist/lib/{utilities/core → core}/type/TNumber.js +7 -7
  21. package/dist/lib/{utilities/core → core}/type/TObject.js +7 -7
  22. package/dist/lib/{utilities/core → core}/type/TString.js +7 -7
  23. package/dist/lib/index.js +70 -54
  24. package/dist/lib/security/Base32.js +104 -0
  25. package/dist/lib/security/Guid.js +26 -0
  26. package/dist/lib/{utilities/security → security}/Hash.js +16 -15
  27. package/dist/lib/security/QRCode.js +46 -0
  28. package/dist/lib/security/RSA.js +62 -0
  29. package/dist/lib/security/SHA.js +67 -0
  30. package/dist/lib/types/AreaCode.js +269 -269
  31. package/dist/lib/types/Exception.js +19 -19
  32. package/dist/lib/types/Logs.js +20 -20
  33. package/dist/lib/types/Object.js +3 -3
  34. package/dist/lib/types/PathBase.js +109 -109
  35. package/dist/lib/types/Security.js +10 -10
  36. package/dist/lib/types/TMap.js +139 -138
  37. package/dist/lib/types/Types.js +3 -3
  38. package/dist/lib/types/index.js +17 -17
  39. package/dist/types/{utilities/coding → coding}/Error.d.ts +27 -27
  40. package/dist/types/{utilities/coding → coding}/Path.d.ts +61 -61
  41. package/dist/types/{utilities/core → core}/Errors.d.ts +47 -47
  42. package/dist/types/{utilities/core → core}/Language.d.ts +17 -17
  43. package/dist/types/{utilities/core → core}/Log.d.ts +12 -12
  44. package/dist/types/{utilities/core → core}/TypeConvertion.d.ts +2 -2
  45. package/dist/types/{utilities/core → core}/interface/ITJSON.d.ts +5 -5
  46. package/dist/types/{utilities/core → core}/interface/ITianyuType.d.ts +5 -5
  47. package/dist/types/{utilities/core → core}/object/ArrayHelper.d.ts +11 -11
  48. package/dist/types/core/object/Bytes.d.ts +13 -0
  49. package/dist/types/{utilities/core → core}/object/Calculater.d.ts +22 -22
  50. package/dist/types/core/object/DataView.d.ts +11 -0
  51. package/dist/types/core/object/Integer.d.ts +71 -0
  52. package/dist/types/core/object/Json.d.ts +22 -0
  53. package/dist/types/{utilities/core/object/Helper.d.ts → core/object/ObjectHelper.d.ts} +39 -39
  54. package/dist/types/core/object/StringHelper.d.ts +21 -0
  55. package/dist/types/{utilities/core → core}/type/TArray.d.ts +3 -3
  56. package/dist/types/{utilities/core → core}/type/TBoolean.d.ts +3 -3
  57. package/dist/types/{utilities/core → core}/type/TJSON.d.ts +3 -3
  58. package/dist/types/{utilities/core → core}/type/TNumber.d.ts +3 -3
  59. package/dist/types/{utilities/core → core}/type/TObject.d.ts +3 -3
  60. package/dist/types/{utilities/core → core}/type/TString.d.ts +3 -3
  61. package/dist/types/index.d.ts +29 -21
  62. package/dist/types/security/Base32.d.ts +42 -0
  63. package/dist/types/security/Guid.d.ts +4 -0
  64. package/dist/types/{utilities/security → security}/Hash.d.ts +3 -3
  65. package/dist/types/security/QRCode.d.ts +11 -0
  66. package/dist/types/security/RSA.d.ts +68 -0
  67. package/dist/types/security/SHA.d.ts +40 -0
  68. package/dist/types/types/AreaCode.d.ts +135 -135
  69. package/dist/types/types/Exception.d.ts +11 -11
  70. package/dist/types/types/Logs.d.ts +64 -64
  71. package/dist/types/types/Object.d.ts +18 -18
  72. package/dist/types/types/PathBase.d.ts +76 -76
  73. package/dist/types/types/Security.d.ts +23 -23
  74. package/dist/types/types/TMap.d.ts +80 -80
  75. package/dist/types/types/Types.d.ts +25 -25
  76. package/dist/types/types/index.d.ts +9 -9
  77. package/package.json +57 -51
  78. package/dist/lib/utilities/coding/index.js +0 -10
  79. package/dist/lib/utilities/core/index.js +0 -21
  80. package/dist/lib/utilities/core/object/StringHelper.js +0 -22
  81. package/dist/lib/utilities/security/Guid.js +0 -20
  82. package/dist/lib/utilities/security/index.js +0 -8
  83. package/dist/types/utilities/coding/index.d.ts +0 -3
  84. package/dist/types/utilities/core/index.d.ts +0 -6
  85. package/dist/types/utilities/core/object/StringHelper.d.ts +0 -4
  86. package/dist/types/utilities/security/Guid.d.ts +0 -3
  87. package/dist/types/utilities/security/index.d.ts +0 -3
@@ -1,230 +1,240 @@
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;
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 ObjectHelper_1 = require("./ObjectHelper");
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 = ObjectHelper_1.ObjectHelper.isSimpleDataType(pre);
26
+ const isNextSimple = ObjectHelper_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: ObjectHelper_1.ObjectHelper.clone(pre),
35
+ new: ObjectHelper_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 = ObjectHelper_1.ObjectHelper.compareObjects(pre, next);
49
+ if (isSame === "different") {
50
+ this.diffs.set(path, {
51
+ path: path.toString(),
52
+ old: ObjectHelper_1.ObjectHelper.clone(pre),
53
+ new: ObjectHelper_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: ObjectHelper_1.ObjectHelper.clone(pre),
64
+ new: ObjectHelper_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: ObjectHelper_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: ObjectHelper_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 ObjectHelper_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: ObjectHelper_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
154
+ ? /* istanbul ignore next */ "del"
155
+ : rootPathDiff.added
156
+ ? /* istanbul ignore next */ "add"
157
+ : "modify");
158
+ }
159
+ // 直接设置新值
160
+ resultObj.root = ObjectHelper_1.ObjectHelper.clone(rootPathDiff.new);
161
+ // 原始值为简单数据类型 或 数组类型 需要根目录修改
162
+ }
163
+ else if (ObjectHelper_1.ObjectHelper.isSimpleDataType(resultObj.root) || Array.isArray(resultObj.root)) {
164
+ throw new Errors_1.ObjectDiffApplyInvalidStatusException(resultObj.root);
165
+ }
166
+ else {
167
+ // 没有根目录修改
168
+ // 并且对象不是简单类型
169
+ // 按照复杂值递归进行更改
170
+ // 依次遍历所有的路径
171
+ for (const [path, info] of diff) {
172
+ // 此处不应该进入条件
173
+ /* istanbul ignore if */
174
+ if (!!!path || !!!info) {
175
+ continue;
176
+ }
177
+ // 获取路径并预处理
178
+ const pathDir = path.getDirs();
179
+ const endDir = pathDir.pop();
180
+ // 此处不应该进入条件
181
+ /* istanbul ignore if */
182
+ if (!!!endDir) {
183
+ continue;
184
+ }
185
+ const mergeType = info.added ? "add" : info.deleted ? "del" : "modify";
186
+ // 依次查询元素路径
187
+ // 检查父元素是否不存在(error)
188
+ let obj = resultObj.root;
189
+ for (const key of pathDir) {
190
+ if (!!!obj[key]) {
191
+ // 如果父对象不存在 在严格模式下抛出异常
192
+ if (strict) {
193
+ throw new Errors_1.ObjectMergeStatusCheckFailedException(info.path, mergeType);
194
+ }
195
+ else {
196
+ obj[key] = {};
197
+ }
198
+ }
199
+ // 目标点向下移动
200
+ obj = obj[key];
201
+ }
202
+ // 再次检查对象状态 (理论上不应该进入此判断)
203
+ /* istanbul ignore if */
204
+ if (!!!obj) {
205
+ throw new Errors_1.ObjectDiffMergeFailedException(info.path);
206
+ }
207
+ if (info.added) {
208
+ // 新增一个元素
209
+ // 严格模式下 不允许新增对象存在
210
+ if (strict && obj[endDir]) {
211
+ throw new Errors_1.ObjectMergeStatusCheckFailedException(info.path, mergeType);
212
+ }
213
+ // 执行拷贝
214
+ obj[endDir] = ObjectHelper_1.ObjectHelper.clone(info.new);
215
+ }
216
+ else if (info.deleted) {
217
+ // 删除一个元素
218
+ // 严格模式下 不允许删除对象不存在
219
+ if (strict && !!!obj[endDir]) {
220
+ throw new Errors_1.ObjectMergeStatusCheckFailedException(info.path, mergeType);
221
+ }
222
+ // 执行删除(如果对象存在)
223
+ !!obj[endDir] && delete obj[endDir];
224
+ }
225
+ else {
226
+ // 修改一个元素
227
+ // 严格模式下 不允许修改对象不存在
228
+ if (strict && (!!!obj[endDir] || __checkOldAndNewStatus(info.old, obj[endDir]))) {
229
+ throw new Errors_1.ObjectMergeStatusCheckFailedException(info.path, mergeType);
230
+ }
231
+ // 执行修改
232
+ obj[endDir] = ObjectHelper_1.ObjectHelper.clone(info.new);
233
+ }
234
+ }
235
+ }
236
+ }
237
+ return resultObj.root;
238
+ }
239
+ }
240
+ exports.ObjectCalculater = ObjectCalculater;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DataView = void 0;
5
+ /** DataView Object Type */
6
+ class DataView {
7
+ /**
8
+ * Create a new node:DataView from given data buffer
9
+ *
10
+ * @param data source data buffer
11
+ * @returns return node:DataView type equals to given data buffer
12
+ */
13
+ static parse(data) {
14
+ if (data instanceof Int8Array || data instanceof Uint8Array || data instanceof Uint8ClampedArray) {
15
+ return new globalThis.DataView(data.buffer, data.byteOffset, data.byteLength);
16
+ }
17
+ if (data instanceof ArrayBuffer) {
18
+ return new globalThis.DataView(data);
19
+ }
20
+ throw new Error("Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray");
21
+ }
22
+ }
23
+ exports.DataView = DataView;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ /** @format */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Integer = void 0;
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ /** Integer Object Type */
10
+ class Integer {
11
+ /**
12
+ * Get a random integer between min value and max value.
13
+ * min value should greater than 0, max value should less than 2^48-1 (281474976710655)
14
+ *
15
+ * @param min the min value (0 will be applied when not given)
16
+ * @param max the max value (281474976710655 will be applied when not given)
17
+ * @returns return the random value
18
+ */
19
+ static random(min, max) {
20
+ const minNum = Math.max(min ?? 0, 0);
21
+ const maxNum = Math.max(max ?? 281474976710655, minNum + 1);
22
+ return crypto_1.default.randomInt(Math.min(minNum, maxNum), Math.max(minNum, maxNum));
23
+ }
24
+ /**
25
+ * convert source number to be a 8-byte array
26
+ *
27
+ * @param srcValue source value
28
+ * @returns return a 8-byte array
29
+ */
30
+ static toBytes(srcValue) {
31
+ const bytes = [];
32
+ let num = srcValue;
33
+ for (let i = 7; i >= 0; --i) {
34
+ bytes[i] = Integer.and(num, 255);
35
+ num = Integer.right(num, 8);
36
+ }
37
+ return bytes;
38
+ }
39
+ /**
40
+ * number left shift
41
+ * times will be calculated to get the end 6-bit at the beginning to avoid over-flow
42
+ *
43
+ * @param value source value
44
+ * @param times left shift steps
45
+ * @returns return result value
46
+ */
47
+ static left(value, times) {
48
+ // eslint-disable-next-line no-bitwise
49
+ return value << (times & 0x3f);
50
+ }
51
+ /**
52
+ * number right shift
53
+ * times will be calculated to get the end 6-bit at the beginning to avoid over-flow
54
+ *
55
+ * @param value source value
56
+ * @param times right shift steps
57
+ * @returns return result value
58
+ */
59
+ static right(value, times) {
60
+ // eslint-disable-next-line no-bitwise
61
+ return value >> (times & 0x3f);
62
+ }
63
+ /**
64
+ * number unsigned right shift
65
+ * times will be calculated to get the end 6-bit at the beginning to avoid over-flow
66
+ *
67
+ * @param value source value
68
+ * @param times right shift steps
69
+ * @returns return result value
70
+ */
71
+ static rightUnsigned(value, times) {
72
+ // eslint-disable-next-line no-bitwise
73
+ return value >>> (times & 0x3f);
74
+ }
75
+ /**
76
+ * or
77
+ *
78
+ * @param value1 the first value
79
+ * @param values the following values array
80
+ * @returns return calculated value
81
+ */
82
+ static or(value1, ...values) {
83
+ let value = value1;
84
+ for (const i of values) {
85
+ // eslint-disable-next-line no-bitwise
86
+ value |= i;
87
+ }
88
+ return value;
89
+ }
90
+ /**
91
+ * and
92
+ *
93
+ * @param value1 the first value
94
+ * @param values the following values array
95
+ * @returns return calculated value
96
+ */
97
+ static and(value1, ...values) {
98
+ let value = value1;
99
+ for (const i of values) {
100
+ // eslint-disable-next-line no-bitwise
101
+ value &= i;
102
+ }
103
+ return value;
104
+ }
105
+ /**
106
+ * xor
107
+ *
108
+ * @param value1 the first value
109
+ * @param value2 the second value
110
+ * @returns return calculated value
111
+ */
112
+ static xor(value1, value2) {
113
+ // eslint-disable-next-line no-bitwise
114
+ return value1 ^ value2;
115
+ }
116
+ }
117
+ exports.Integer = Integer;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Json = void 0;
5
+ /** Json Lib */
6
+ class Json {
7
+ /**
8
+ * @deprecated
9
+ *
10
+ * convert a string to be a javascript object.
11
+ * This is an unsafe function to convert a string to be object. suggest to use parseSafe to convert string to object.
12
+ *
13
+ * @param src source string
14
+ * @returns target js-object
15
+ */
16
+ static parse(src) {
17
+ return JSON.parse(src);
18
+ }
19
+ /**
20
+ * convert a string to be a javascript object safty
21
+ *
22
+ * @param src source string
23
+ * @param failed value returned when converted failed, default is null
24
+ * @returns target js-object
25
+ */
26
+ static parseSafe(src, failed = null) {
27
+ try {
28
+ return JSON.parse(src);
29
+ }
30
+ catch {
31
+ return failed;
32
+ }
33
+ }
34
+ }
35
+ exports.Json = Json;