@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.
- package/dist/lib/{utilities/coding → coding}/Error.js +44 -44
- package/dist/lib/{utilities/coding → coding}/Path.js +210 -198
- package/dist/lib/{utilities/core → core}/Errors.js +86 -86
- package/dist/lib/{utilities/core → core}/Language.js +561 -559
- package/dist/lib/{utilities/core → core}/Log.js +112 -108
- package/dist/lib/{utilities/core → core}/TypeConvertion.js +25 -25
- package/dist/lib/{utilities/core → core}/interface/ITJSON.js +3 -3
- package/dist/lib/{utilities/core → core}/interface/ITianyuType.js +3 -3
- package/dist/lib/{utilities/core → core}/object/ArrayHelper.js +35 -35
- package/dist/lib/core/object/Bytes.js +21 -0
- package/dist/lib/{utilities/core → core}/object/Calculater.js +240 -230
- package/dist/lib/core/object/DataView.js +23 -0
- package/dist/lib/core/object/Integer.js +117 -0
- package/dist/lib/core/object/Json.js +35 -0
- package/dist/lib/{utilities/core/object/Helper.js → core/object/ObjectHelper.js} +202 -201
- package/dist/lib/core/object/StringHelper.js +61 -0
- package/dist/lib/{utilities/core → core}/type/TArray.js +8 -7
- package/dist/lib/{utilities/core → core}/type/TBoolean.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TJSON.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TNumber.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TObject.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TString.js +7 -7
- package/dist/lib/index.js +70 -54
- package/dist/lib/security/Base32.js +104 -0
- package/dist/lib/security/Guid.js +26 -0
- package/dist/lib/{utilities/security → security}/Hash.js +16 -15
- package/dist/lib/security/QRCode.js +46 -0
- package/dist/lib/security/RSA.js +62 -0
- package/dist/lib/security/SHA.js +67 -0
- package/dist/lib/types/AreaCode.js +269 -269
- package/dist/lib/types/Exception.js +19 -19
- package/dist/lib/types/Logs.js +20 -20
- package/dist/lib/types/Object.js +3 -3
- package/dist/lib/types/PathBase.js +109 -109
- package/dist/lib/types/Security.js +10 -10
- package/dist/lib/types/TMap.js +139 -138
- package/dist/lib/types/Types.js +3 -3
- package/dist/lib/types/index.js +17 -17
- package/dist/types/{utilities/coding → coding}/Error.d.ts +27 -27
- package/dist/types/{utilities/coding → coding}/Path.d.ts +61 -61
- package/dist/types/{utilities/core → core}/Errors.d.ts +47 -47
- package/dist/types/{utilities/core → core}/Language.d.ts +17 -17
- package/dist/types/{utilities/core → core}/Log.d.ts +12 -12
- package/dist/types/{utilities/core → core}/TypeConvertion.d.ts +2 -2
- package/dist/types/{utilities/core → core}/interface/ITJSON.d.ts +5 -5
- package/dist/types/{utilities/core → core}/interface/ITianyuType.d.ts +5 -5
- package/dist/types/{utilities/core → core}/object/ArrayHelper.d.ts +11 -11
- package/dist/types/core/object/Bytes.d.ts +13 -0
- package/dist/types/{utilities/core → core}/object/Calculater.d.ts +22 -22
- package/dist/types/core/object/DataView.d.ts +11 -0
- package/dist/types/core/object/Integer.d.ts +71 -0
- package/dist/types/core/object/Json.d.ts +22 -0
- package/dist/types/{utilities/core/object/Helper.d.ts → core/object/ObjectHelper.d.ts} +39 -39
- package/dist/types/core/object/StringHelper.d.ts +21 -0
- package/dist/types/{utilities/core → core}/type/TArray.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TBoolean.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TJSON.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TNumber.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TObject.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TString.d.ts +3 -3
- package/dist/types/index.d.ts +29 -21
- package/dist/types/security/Base32.d.ts +42 -0
- package/dist/types/security/Guid.d.ts +4 -0
- package/dist/types/{utilities/security → security}/Hash.d.ts +3 -3
- package/dist/types/security/QRCode.d.ts +11 -0
- package/dist/types/security/RSA.d.ts +68 -0
- package/dist/types/security/SHA.d.ts +40 -0
- package/dist/types/types/AreaCode.d.ts +135 -135
- package/dist/types/types/Exception.d.ts +11 -11
- package/dist/types/types/Logs.d.ts +64 -64
- package/dist/types/types/Object.d.ts +18 -18
- package/dist/types/types/PathBase.d.ts +76 -76
- package/dist/types/types/Security.d.ts +23 -23
- package/dist/types/types/TMap.d.ts +80 -80
- package/dist/types/types/Types.d.ts +25 -25
- package/dist/types/types/index.d.ts +9 -9
- package/package.json +57 -51
- package/dist/lib/utilities/coding/index.js +0 -10
- package/dist/lib/utilities/core/index.js +0 -21
- package/dist/lib/utilities/core/object/StringHelper.js +0 -22
- package/dist/lib/utilities/security/Guid.js +0 -20
- package/dist/lib/utilities/security/index.js +0 -8
- package/dist/types/utilities/coding/index.d.ts +0 -3
- package/dist/types/utilities/core/index.d.ts +0 -6
- package/dist/types/utilities/core/object/StringHelper.d.ts +0 -4
- package/dist/types/utilities/security/Guid.d.ts +0 -3
- 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("
|
|
6
|
-
const PathBase_1 = require("
|
|
7
|
-
const
|
|
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 =
|
|
26
|
-
const isNextSimple =
|
|
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:
|
|
35
|
-
new:
|
|
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 =
|
|
49
|
-
if (isSame === "different") {
|
|
50
|
-
this.diffs.set(path, {
|
|
51
|
-
path: path.toString(),
|
|
52
|
-
old:
|
|
53
|
-
new:
|
|
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:
|
|
64
|
-
new:
|
|
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:
|
|
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:
|
|
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
|
|
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:
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
//
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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 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;
|