oak-domain 3.0.3 → 3.0.4
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/lib/actions/action.d.ts +8 -8
- package/lib/actions/action.js +2 -2
- package/lib/actions/relation.d.ts +1 -1
- package/lib/actions/relation.js +9 -22
- package/lib/base-app-domain/ActionAuth/Schema.d.ts +68 -42
- package/lib/base-app-domain/ActionAuth/Storage.js +12 -15
- package/lib/base-app-domain/ActionDefDict.d.ts +2 -3
- package/lib/base-app-domain/ActionDefDict.js +3 -5
- package/lib/base-app-domain/EntityDict.d.ts +5 -1
- package/lib/base-app-domain/I18n/Schema.d.ts +24 -24
- package/lib/base-app-domain/I18n/Storage.js +5 -5
- package/lib/base-app-domain/Modi/Action.d.ts +4 -4
- package/lib/base-app-domain/Modi/Action.js +3 -3
- package/lib/base-app-domain/Modi/Schema.d.ts +24 -24
- package/lib/base-app-domain/Modi/Storage.js +3 -3
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +128 -55
- package/lib/base-app-domain/ModiEntity/Storage.js +2 -2
- package/lib/base-app-domain/Oper/Schema.d.ts +30 -29
- package/lib/base-app-domain/Oper/Storage.js +1 -1
- package/lib/base-app-domain/OperEntity/Schema.d.ts +126 -53
- package/lib/base-app-domain/OperEntity/Storage.js +2 -2
- package/lib/base-app-domain/Path/Schema.d.ts +149 -0
- package/lib/base-app-domain/Path/Schema.js +2 -0
- package/lib/base-app-domain/Path/Storage.d.ts +3 -0
- package/lib/base-app-domain/Path/Storage.js +54 -0
- package/lib/base-app-domain/Relation/Schema.d.ts +34 -34
- package/lib/base-app-domain/Relation/Storage.js +6 -6
- package/lib/base-app-domain/Relation.d.ts +0 -8
- package/lib/base-app-domain/Relation.js +1 -7
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +74 -40
- package/lib/base-app-domain/RelationAuth/Storage.js +9 -11
- package/lib/base-app-domain/Storage.js +20 -16
- package/lib/base-app-domain/User/Action.d.ts +4 -4
- package/lib/base-app-domain/User/Action.js +3 -3
- package/lib/base-app-domain/User/Schema.d.ts +40 -27
- package/lib/base-app-domain/User/Storage.js +1 -1
- package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +264 -0
- package/lib/base-app-domain/UserEntityClaim/Schema.js +2 -0
- package/lib/base-app-domain/UserEntityClaim/Storage.d.ts +3 -0
- package/lib/base-app-domain/UserEntityClaim/Storage.js +37 -0
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +2 -2
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +55 -81
- package/lib/base-app-domain/UserEntityGrant/Storage.js +7 -11
- package/lib/base-app-domain/UserRelation/Schema.d.ts +50 -36
- package/lib/base-app-domain/UserRelation/Storage.js +7 -7
- package/lib/base-app-domain/_SubQuery.d.ts +45 -15
- package/lib/base-app-domain/index.js +1 -1
- package/lib/checkers/index.js +6 -7
- package/lib/compiler/env.js +16 -18
- package/lib/compiler/localeBuilder.js +83 -79
- package/lib/compiler/schemalBuilder.d.ts +16 -0
- package/lib/compiler/schemalBuilder.js +1160 -1378
- package/lib/entities/ActionAuth.d.ts +3 -5
- package/lib/entities/ActionAuth.js +9 -7
- package/lib/entities/I18n.js +1 -1
- package/lib/entities/Modi.js +2 -2
- package/lib/entities/ModiEntity.js +1 -1
- package/lib/entities/Oper.js +1 -1
- package/lib/entities/OperEntity.js +1 -1
- package/lib/entities/Path.d.ts +8 -0
- package/lib/entities/Path.js +35 -0
- package/lib/entities/Relation.js +1 -1
- package/lib/entities/RelationAuth.d.ts +2 -2
- package/lib/entities/RelationAuth.js +1 -1
- package/lib/entities/User.js +2 -2
- package/lib/entities/UserEntityClaim.d.ts +13 -0
- package/lib/entities/UserEntityClaim.js +17 -0
- package/lib/entities/UserEntityGrant.d.ts +5 -4
- package/lib/entities/UserEntityGrant.js +4 -7
- package/lib/entities/UserRelation.js +1 -1
- package/lib/index.d.ts +23 -0
- package/lib/index.js +37 -0
- package/lib/store/AsyncRowStore.d.ts +2 -1
- package/lib/store/AsyncRowStore.js +75 -149
- package/lib/store/CascadeStore.js +917 -1291
- package/lib/store/RelationAuth.d.ts +9 -16
- package/lib/store/RelationAuth.js +750 -908
- package/lib/store/SyncRowStore.d.ts +1 -1
- package/lib/store/SyncRowStore.js +27 -26
- package/lib/store/TriggerExecutor.d.ts +17 -10
- package/lib/store/TriggerExecutor.js +350 -423
- package/lib/store/actionAuth.js +13 -28
- package/lib/store/actionDef.js +118 -193
- package/lib/store/checker.js +225 -361
- package/lib/store/filter.d.ts +2 -3
- package/lib/store/filter.js +451 -589
- package/lib/store/modi.js +116 -177
- package/lib/store/relation.js +17 -17
- package/lib/timers/oper.d.ts +1 -1
- package/lib/timers/oper.js +44 -47
- package/lib/timers/vaccum.d.ts +2 -2
- package/lib/timers/vaccum.js +100 -165
- package/lib/triggers/index.js +1 -1
- package/lib/types/Action.d.ts +7 -7
- package/lib/types/AppLoader.d.ts +8 -2
- package/lib/types/AppLoader.js +4 -4
- package/lib/types/Aspect.d.ts +1 -3
- package/lib/types/Auth.d.ts +15 -19
- package/lib/types/Connector.d.ts +19 -15
- package/lib/types/Connector.js +0 -7
- package/lib/types/DataType.d.ts +19 -18
- package/lib/types/DataType.js +1 -1
- package/lib/types/Demand.d.ts +25 -25
- package/lib/types/Endpoint.d.ts +1 -1
- package/lib/types/Entity.d.ts +57 -53
- package/lib/types/Entity.js +3 -3
- package/lib/types/EntityDesc.d.ts +2 -1
- package/lib/types/Environment.d.ts +4 -4
- package/lib/types/Exception.d.ts +29 -2
- package/lib/types/Exception.js +205 -205
- package/lib/types/Expression.d.ts +14 -14
- package/lib/types/Expression.js +54 -87
- package/lib/types/Geo.d.ts +6 -6
- package/lib/types/Locale.d.ts +5 -5
- package/lib/types/Polyfill.d.ts +9 -9
- package/lib/types/Port.d.ts +4 -4
- package/lib/types/RowStore.d.ts +3 -3
- package/lib/types/RowStore.js +18 -19
- package/lib/types/Storage.d.ts +5 -4
- package/lib/types/Style.d.ts +2 -2
- package/lib/types/Timer.d.ts +3 -3
- package/lib/types/Trigger.d.ts +30 -14
- package/lib/types/Trigger.js +6 -2
- package/lib/types/Watcher.d.ts +2 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +2 -1
- package/lib/types/schema/DataTypes.d.ts +7 -7
- package/lib/utils/SimpleConnector.d.ts +24 -10
- package/lib/utils/SimpleConnector.js +166 -144
- package/lib/utils/assert.js +2 -2
- package/lib/utils/concurrent.d.ts +1 -1
- package/lib/utils/concurrent.js +31 -57
- package/lib/utils/date.js +2 -2
- package/lib/utils/geo.js +8 -8
- package/lib/utils/lodash.d.ts +3 -1
- package/lib/utils/lodash.js +21 -34
- package/lib/utils/mask.js +12 -13
- package/lib/utils/money.d.ts +1 -1
- package/lib/utils/money.js +22 -11
- package/lib/utils/projection.d.ts +4 -0
- package/lib/utils/projection.js +15 -0
- package/lib/utils/random/random.js +11 -16
- package/lib/utils/random/random.mp.js +7 -18
- package/lib/utils/random/random.web.js +6 -12
- package/lib/utils/string.d.ts +4 -4
- package/lib/utils/string.js +19 -32
- package/lib/utils/url.js +5 -4
- package/lib/utils/uuid.d.ts +1 -1
- package/lib/utils/uuid.js +46 -85
- package/lib/utils/validator.d.ts +4 -3
- package/lib/utils/validator.js +35 -32
- package/lib/utils/version.js +6 -6
- package/package.json +7 -7
- package/src/entities/ActionAuth.ts +10 -10
- package/src/entities/Path.ts +43 -0
- package/src/entities/RelationAuth.ts +2 -1
- package/src/entities/UserEntityClaim.ts +30 -0
- package/src/entities/UserEntityGrant.ts +9 -12
package/lib/utils/concurrent.js
CHANGED
|
@@ -1,76 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RWLock = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
/**
|
|
7
7
|
* 模拟一个读写锁,用于同步。
|
|
8
8
|
* 注意,千万不要发生自己等自己
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
class RWLock {
|
|
11
|
+
readNumber;
|
|
12
|
+
writeNumber;
|
|
13
|
+
readWaiter;
|
|
14
|
+
writeWaiter;
|
|
15
|
+
constructor() {
|
|
12
16
|
this.readNumber = 0;
|
|
13
17
|
this.writeNumber = 0;
|
|
14
18
|
this.readWaiter = [];
|
|
15
19
|
this.writeWaiter = [];
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.readNumber++;
|
|
35
|
-
return [3 /*break*/, 7];
|
|
36
|
-
case 4:
|
|
37
|
-
if (!(this.writeNumber || this.readNumber)) return [3 /*break*/, 6];
|
|
38
|
-
p = new Promise(function (resolve) { return _this.writeWaiter.push(resolve); });
|
|
39
|
-
return [4 /*yield*/, p];
|
|
40
|
-
case 5:
|
|
41
|
-
_a.sent();
|
|
42
|
-
return [3 /*break*/, 4];
|
|
43
|
-
case 6:
|
|
44
|
-
this.writeNumber++;
|
|
45
|
-
_a.label = 7;
|
|
46
|
-
case 7: return [2 /*return*/];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
RWLock.prototype.release = function () {
|
|
52
|
-
var e_1, _a;
|
|
21
|
+
async acquire(mode) {
|
|
22
|
+
if (mode === 'S') {
|
|
23
|
+
while (this.writeNumber > 0) {
|
|
24
|
+
const p = new Promise((resolve) => this.readWaiter.push(resolve));
|
|
25
|
+
await p;
|
|
26
|
+
}
|
|
27
|
+
this.readNumber++;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
while (this.writeNumber || this.readNumber) {
|
|
31
|
+
const p = new Promise((resolve) => this.writeWaiter.push(resolve));
|
|
32
|
+
await p;
|
|
33
|
+
}
|
|
34
|
+
this.writeNumber++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
release() {
|
|
53
38
|
if (this.writeNumber) {
|
|
54
39
|
(0, assert_1.default)(this.writeNumber === 1);
|
|
55
40
|
this.writeNumber = 0;
|
|
56
41
|
if (this.readWaiter.length > 0) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var f = _c.value;
|
|
60
|
-
f(undefined);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
64
|
-
finally {
|
|
65
|
-
try {
|
|
66
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
67
|
-
}
|
|
68
|
-
finally { if (e_1) throw e_1.error; }
|
|
42
|
+
for (const f of this.readWaiter) {
|
|
43
|
+
f(undefined);
|
|
69
44
|
}
|
|
70
45
|
this.readWaiter = [];
|
|
71
46
|
}
|
|
72
47
|
else if (this.writeWaiter.length > 0) {
|
|
73
|
-
|
|
48
|
+
const f = this.writeWaiter.pop();
|
|
74
49
|
f(undefined);
|
|
75
50
|
}
|
|
76
51
|
}
|
|
@@ -79,11 +54,10 @@ var RWLock = /** @class */ (function () {
|
|
|
79
54
|
(0, assert_1.default)(this.readWaiter.length === 0);
|
|
80
55
|
this.readNumber--;
|
|
81
56
|
if (this.readNumber === 0) {
|
|
82
|
-
|
|
57
|
+
const f = this.writeWaiter.pop();
|
|
83
58
|
f && f(undefined);
|
|
84
59
|
}
|
|
85
60
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
89
63
|
exports.RWLock = RWLock;
|
package/lib/utils/date.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.excelStringToDate = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
6
|
function excelStringToDate(str) {
|
|
7
7
|
if (!str) {
|
|
8
8
|
return undefined;
|
package/lib/utils/geo.js
CHANGED
|
@@ -9,16 +9,16 @@ function getDistanceBetweenPoints(lat1, lon1, lat2, lon2) {
|
|
|
9
9
|
function toRadians(d) {
|
|
10
10
|
return d * Math.PI / 180;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const R = 6378137; // 地球长半径
|
|
13
|
+
const φ1 = toRadians(lat1);
|
|
14
|
+
const φ2 = toRadians(lat2);
|
|
15
|
+
const Δφ = toRadians(lat2 - lat1);
|
|
16
|
+
const Δλ = toRadians(lon2 - lon1);
|
|
17
|
+
const a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
|
|
18
18
|
Math.cos(φ1) * Math.cos(φ2) *
|
|
19
19
|
Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
21
|
+
const d = R * c;
|
|
22
22
|
return d * 1000;
|
|
23
23
|
}
|
|
24
24
|
exports.getDistanceBetweenPoints = getDistanceBetweenPoints;
|
package/lib/utils/lodash.d.ts
CHANGED
|
@@ -17,4 +17,6 @@ import isEqual from 'lodash/isEqual';
|
|
|
17
17
|
import union from 'lodash/union';
|
|
18
18
|
import difference from 'lodash/difference';
|
|
19
19
|
import groupBy from 'lodash/groupBy';
|
|
20
|
-
|
|
20
|
+
import unionBy from 'lodash/unionBy';
|
|
21
|
+
import pullAll from 'lodash/pullAll';
|
|
22
|
+
export { unset, pull, uniq, uniqBy, get, set, intersection, omit, merge, cloneDeep, pick, isEqual, union, difference, groupBy, unionBy, pullAll, };
|
package/lib/utils/lodash.js
CHANGED
|
@@ -1,55 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.groupBy = exports.difference = exports.union = exports.isEqual = exports.pick = exports.cloneDeep = exports.merge = exports.omit = exports.intersection = exports.set = exports.get = exports.uniqBy = exports.uniq = exports.pull = exports.unset = void 0;
|
|
4
|
-
|
|
3
|
+
exports.pullAll = exports.unionBy = exports.groupBy = exports.difference = exports.union = exports.isEqual = exports.pick = exports.cloneDeep = exports.merge = exports.omit = exports.intersection = exports.set = exports.get = exports.uniqBy = exports.uniq = exports.pull = exports.unset = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
5
|
/**
|
|
6
6
|
* 避免lodash打包体积过大
|
|
7
7
|
* 像assign, keys尽量使用Object的函数
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const unset_1 = tslib_1.__importDefault(require("lodash/unset"));
|
|
10
10
|
exports.unset = unset_1.default;
|
|
11
|
-
|
|
11
|
+
const uniqBy_1 = tslib_1.__importDefault(require("lodash/uniqBy"));
|
|
12
12
|
exports.uniqBy = uniqBy_1.default;
|
|
13
|
-
|
|
13
|
+
const pull_1 = tslib_1.__importDefault(require("lodash/pull"));
|
|
14
14
|
exports.pull = pull_1.default;
|
|
15
|
-
|
|
15
|
+
const uniq_1 = tslib_1.__importDefault(require("lodash/uniq"));
|
|
16
16
|
exports.uniq = uniq_1.default;
|
|
17
|
-
|
|
17
|
+
const get_1 = tslib_1.__importDefault(require("lodash/get"));
|
|
18
18
|
exports.get = get_1.default;
|
|
19
|
-
|
|
19
|
+
const set_1 = tslib_1.__importDefault(require("lodash/set"));
|
|
20
20
|
exports.set = set_1.default;
|
|
21
|
-
|
|
21
|
+
const intersection_1 = tslib_1.__importDefault(require("lodash/intersection"));
|
|
22
22
|
exports.intersection = intersection_1.default;
|
|
23
|
-
|
|
23
|
+
const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
|
|
24
24
|
exports.omit = omit_1.default;
|
|
25
|
-
|
|
25
|
+
const merge_1 = tslib_1.__importDefault(require("lodash/merge"));
|
|
26
26
|
exports.merge = merge_1.default;
|
|
27
|
-
|
|
27
|
+
const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
|
|
28
28
|
exports.cloneDeep = cloneDeep_1.default;
|
|
29
|
-
|
|
29
|
+
const pick_1 = tslib_1.__importDefault(require("lodash/pick"));
|
|
30
30
|
exports.pick = pick_1.default;
|
|
31
|
-
|
|
31
|
+
const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
|
|
32
32
|
exports.isEqual = isEqual_1.default;
|
|
33
|
-
|
|
33
|
+
const union_1 = tslib_1.__importDefault(require("lodash/union"));
|
|
34
34
|
exports.union = union_1.default;
|
|
35
|
-
|
|
35
|
+
const difference_1 = tslib_1.__importDefault(require("lodash/difference"));
|
|
36
36
|
exports.difference = difference_1.default;
|
|
37
|
-
|
|
37
|
+
const groupBy_1 = tslib_1.__importDefault(require("lodash/groupBy"));
|
|
38
38
|
exports.groupBy = groupBy_1.default;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// uniqBy,
|
|
44
|
-
// get,
|
|
45
|
-
// set,
|
|
46
|
-
// intersection,
|
|
47
|
-
// omit,
|
|
48
|
-
// merge,
|
|
49
|
-
// cloneDeep,
|
|
50
|
-
// pick,
|
|
51
|
-
// isEqual,
|
|
52
|
-
// union,
|
|
53
|
-
// difference,
|
|
54
|
-
// groupBy,
|
|
55
|
-
// } from 'lodash';
|
|
39
|
+
const unionBy_1 = tslib_1.__importDefault(require("lodash/unionBy"));
|
|
40
|
+
exports.unionBy = unionBy_1.default;
|
|
41
|
+
const pullAll_1 = tslib_1.__importDefault(require("lodash/pullAll"));
|
|
42
|
+
exports.pullAll = pullAll_1.default;
|
package/lib/utils/mask.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.maskStar = exports.maskName = exports.maskMobile = exports.maskIdCard = void 0;
|
|
4
|
-
|
|
4
|
+
const maskIdCard = (idCardNumber) => {
|
|
5
5
|
if (!idCardNumber instanceof String) {
|
|
6
6
|
throw new Error("身份证号码必须是String类型");
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
for (
|
|
8
|
+
let begin = idCardNumber.slice(0, 4);
|
|
9
|
+
let end = idCardNumber.slice(idCardNumber.length - 4, 4);
|
|
10
|
+
for (let i = 0; i < idCardNumber.length - 8; i++) {
|
|
11
11
|
begin = begin.concat("*");
|
|
12
12
|
}
|
|
13
13
|
return begin.concat(end);
|
|
14
14
|
};
|
|
15
15
|
exports.maskIdCard = maskIdCard;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const maskMobile = (mobile) => {
|
|
17
|
+
let begin = mobile.slice(0, 3);
|
|
18
|
+
let end = mobile.slice(7, 11);
|
|
19
19
|
return begin.concat("****").concat(end);
|
|
20
20
|
};
|
|
21
21
|
exports.maskMobile = maskMobile;
|
|
22
|
-
|
|
22
|
+
const maskName = (name) => {
|
|
23
23
|
return name.slice(0, name.length - 1).concat("*");
|
|
24
24
|
};
|
|
25
25
|
exports.maskName = maskName;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (var i = 0; i < len; i++) {
|
|
26
|
+
const maskStar = (str, frontLen, endLen, star = '*') => {
|
|
27
|
+
const len = str.length - frontLen - endLen;
|
|
28
|
+
let xing = '';
|
|
29
|
+
for (let i = 0; i < len; i++) {
|
|
31
30
|
xing += star;
|
|
32
31
|
}
|
|
33
32
|
return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
|
package/lib/utils/money.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ declare const ToCent: (float: number) => number;
|
|
|
2
2
|
declare const ToYuan: (int: number) => number;
|
|
3
3
|
declare const StringToCent: (value: string, allowNegative?: true) => number | undefined;
|
|
4
4
|
declare const CentToString: (value: number) => string | undefined;
|
|
5
|
-
declare const ThousandCont: (value: number) => string | undefined;
|
|
5
|
+
declare const ThousandCont: (value: number, decimalPlaces?: number) => string | undefined;
|
|
6
6
|
export { ToCent, ToYuan, StringToCent, CentToString, ThousandCont };
|
package/lib/utils/money.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ThousandCont = exports.CentToString = exports.StringToCent = exports.ToYuan = exports.ToCent = void 0;
|
|
4
|
-
|
|
4
|
+
const ToCent = (float) => {
|
|
5
5
|
return Math.round(float * 100);
|
|
6
6
|
};
|
|
7
7
|
exports.ToCent = ToCent;
|
|
8
|
-
|
|
8
|
+
const ToYuan = (int) => {
|
|
9
9
|
return Math.round(int) / 100;
|
|
10
10
|
};
|
|
11
11
|
exports.ToYuan = ToYuan;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const StringToCent = (value, allowNegative) => {
|
|
13
|
+
const numValue = parseInt(value, 10);
|
|
14
14
|
if (typeof numValue === 'number' && (numValue >= 0 || allowNegative)) {
|
|
15
15
|
return ToCent(numValue);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
exports.StringToCent = StringToCent;
|
|
19
|
-
|
|
19
|
+
const CentToString = (value) => {
|
|
20
20
|
if (typeof value === 'number') {
|
|
21
|
-
return
|
|
21
|
+
return `${ToYuan(value)}`;
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
exports.CentToString = CentToString;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const ThousandCont = (value, decimalPlaces) => {
|
|
26
|
+
let value1 = `${value}`;
|
|
27
|
+
const numArr = value1.split('.');
|
|
28
28
|
value1 = numArr[0];
|
|
29
|
-
|
|
29
|
+
let result = '';
|
|
30
30
|
while (value1.length > 3) {
|
|
31
31
|
result = ',' + value1.slice(-3) + result;
|
|
32
32
|
value1 = value1.slice(0, value1.length - 3);
|
|
@@ -34,7 +34,18 @@ var ThousandCont = function (value) {
|
|
|
34
34
|
if (value1) {
|
|
35
35
|
result = value1 + result;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
if (decimalPlaces && decimalPlaces > 0) {
|
|
38
|
+
if (numArr[1]) {
|
|
39
|
+
const decimalPart = numArr[1].padEnd(decimalPlaces, '0').slice(0, decimalPlaces);
|
|
40
|
+
result = result + '.' + decimalPart;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
result = result + '.' + '0'.repeat(decimalPlaces);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
result = numArr[1] ? result + '.' + numArr[1] : result;
|
|
48
|
+
}
|
|
38
49
|
return result;
|
|
39
50
|
};
|
|
40
51
|
exports.ThousandCont = ThousandCont;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { EntityDict } from '../types/Entity';
|
|
2
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
|
+
import { StorageSchema } from '..';
|
|
4
|
+
export declare function makeProjection<ED extends BaseEntityDict & EntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>): ED[T]["Selection"]["data"];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeProjection = void 0;
|
|
4
|
+
const Entity_1 = require("../types/Entity");
|
|
5
|
+
function makeProjection(entity, schema) {
|
|
6
|
+
const { attributes } = schema[entity];
|
|
7
|
+
const attrs = Object.keys(attributes);
|
|
8
|
+
attrs.push(Entity_1.PrimaryKeyAttribute, Entity_1.CreateAtAttribute, Entity_1.UpdateAtAttribute, Entity_1.DeleteAtAttribute);
|
|
9
|
+
const projection = {};
|
|
10
|
+
attrs.forEach((attr) => Object.assign(projection, {
|
|
11
|
+
[attr]: 1,
|
|
12
|
+
}));
|
|
13
|
+
return projection;
|
|
14
|
+
}
|
|
15
|
+
exports.makeProjection = makeProjection;
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRandomValues = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
async function getRandomValues(length) {
|
|
6
|
+
if (length > 65536) {
|
|
7
|
+
throw new Error('Can only request a maximum of 65536 bytes');
|
|
8
|
+
}
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
(0, node_crypto_1.randomBytes)(length, (err, buf) => {
|
|
11
|
+
if (err) {
|
|
12
|
+
reject(err);
|
|
13
|
+
return;
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
(0, node_crypto_1.randomBytes)(length, function (err, buf) {
|
|
14
|
-
if (err) {
|
|
15
|
-
reject(err);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
resolve(new Uint8Array(buf));
|
|
19
|
-
});
|
|
20
|
-
})];
|
|
15
|
+
resolve(new Uint8Array(buf));
|
|
21
16
|
});
|
|
22
17
|
});
|
|
23
18
|
}
|
|
@@ -2,24 +2,13 @@
|
|
|
2
2
|
/// <reference types="wechat-miniprogram" />
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.getRandomValues = void 0;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
case 0:
|
|
12
|
-
if (length > 65536) {
|
|
13
|
-
throw new Error('Can only request a maximum of 65536 bytes');
|
|
14
|
-
}
|
|
15
|
-
return [4 /*yield*/, wx.getRandomValues({
|
|
16
|
-
length: length,
|
|
17
|
-
})];
|
|
18
|
-
case 1:
|
|
19
|
-
randomValues = (_a.sent()).randomValues;
|
|
20
|
-
return [2 /*return*/, new Uint8Array(randomValues)];
|
|
21
|
-
}
|
|
22
|
-
});
|
|
5
|
+
async function getRandomValues(length) {
|
|
6
|
+
if (length > 65536) {
|
|
7
|
+
throw new Error('Can only request a maximum of 65536 bytes');
|
|
8
|
+
}
|
|
9
|
+
const { randomValues } = await wx.getRandomValues({
|
|
10
|
+
length,
|
|
23
11
|
});
|
|
12
|
+
return new Uint8Array(randomValues);
|
|
24
13
|
}
|
|
25
14
|
exports.getRandomValues = getRandomValues;
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRandomValues = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
throw new Error('Can only request a maximum of 65536 bytes');
|
|
11
|
-
}
|
|
12
|
-
randomValues = window.crypto.getRandomValues(new Uint8Array(length));
|
|
13
|
-
return [2 /*return*/, new Uint8Array(randomValues)];
|
|
14
|
-
});
|
|
15
|
-
});
|
|
4
|
+
async function getRandomValues(length) {
|
|
5
|
+
if (length > 65536) {
|
|
6
|
+
throw new Error('Can only request a maximum of 65536 bytes');
|
|
7
|
+
}
|
|
8
|
+
const randomValues = window.crypto.getRandomValues(new Uint8Array(length));
|
|
9
|
+
return new Uint8Array(randomValues);
|
|
16
10
|
}
|
|
17
11
|
exports.getRandomValues = getRandomValues;
|
package/lib/utils/string.d.ts
CHANGED
|
@@ -9,17 +9,17 @@ export declare function firstLetterUpperCase(s: string): string;
|
|
|
9
9
|
export declare const template: (strings: TemplateStringsArray, ...keys: Array<any>) => (...values: Array<any>) => string;
|
|
10
10
|
/**
|
|
11
11
|
* 随机生成字符串
|
|
12
|
-
* @param
|
|
12
|
+
* @param length
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
|
15
|
-
export declare const random: (
|
|
15
|
+
export declare const random: (length?: number) => string;
|
|
16
16
|
/**
|
|
17
17
|
* 随机生成带前缀的字符串
|
|
18
18
|
* @param prefix 第一个参数为你想生成的固定的文字开头比如: 微信用户xxxxx
|
|
19
|
-
* @param
|
|
19
|
+
* @param length 第二个为你想生成出固定开头文字外的随机长度
|
|
20
20
|
* @returns
|
|
21
21
|
*/
|
|
22
|
-
export declare const
|
|
22
|
+
export declare const randomPrefixedString: (prefix?: string, length?: number) => string;
|
|
23
23
|
/**
|
|
24
24
|
* 将字符串中的u16编码转换回汉字
|
|
25
25
|
* @param str
|
package/lib/utils/string.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unescapeUnicode = exports.
|
|
3
|
+
exports.unescapeUnicode = exports.randomPrefixedString = exports.random = exports.template = exports.firstLetterUpperCase = exports.firstLetterLowerCase = void 0;
|
|
4
4
|
function firstLetterLowerCase(s) {
|
|
5
5
|
return s.slice(0, 1).toLowerCase().concat(s.slice(1));
|
|
6
6
|
}
|
|
@@ -15,20 +15,12 @@ exports.firstLetterUpperCase = firstLetterUpperCase;
|
|
|
15
15
|
* @param keys
|
|
16
16
|
* @returns {function(...[*]): string}
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var values = [];
|
|
25
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
26
|
-
values[_i] = arguments[_i];
|
|
27
|
-
}
|
|
28
|
-
var dict = values[values.length - 1] || {};
|
|
29
|
-
var result = [strings[0]];
|
|
30
|
-
keys.forEach(function (key, i) {
|
|
31
|
-
var value = Number.isInteger(key) ? values[key] : dict[key];
|
|
18
|
+
const template = (strings, ...keys) => {
|
|
19
|
+
return (function (...values) {
|
|
20
|
+
const dict = values[values.length - 1] || {};
|
|
21
|
+
const result = [strings[0]];
|
|
22
|
+
keys.forEach((key, i) => {
|
|
23
|
+
const value = Number.isInteger(key) ? values[key] : dict[key];
|
|
32
24
|
result.push(value, strings[i + 1]);
|
|
33
25
|
});
|
|
34
26
|
return result.join('');
|
|
@@ -37,16 +29,15 @@ var template = function (strings) {
|
|
|
37
29
|
exports.template = template;
|
|
38
30
|
/**
|
|
39
31
|
* 随机生成字符串
|
|
40
|
-
* @param
|
|
32
|
+
* @param length
|
|
41
33
|
* @returns
|
|
42
34
|
*/
|
|
43
|
-
|
|
44
|
-
if (randomLength === void 0) { randomLength = 16; }
|
|
35
|
+
const random = (length = 16) => {
|
|
45
36
|
// 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
for (
|
|
37
|
+
const DICT = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
|
|
38
|
+
const maxPos = DICT.length;
|
|
39
|
+
let pwd = '';
|
|
40
|
+
for (let i = 0; i < length; i++) {
|
|
50
41
|
pwd += DICT.charAt(Math.floor(Math.random() * maxPos));
|
|
51
42
|
}
|
|
52
43
|
return pwd;
|
|
@@ -55,26 +46,22 @@ exports.random = random;
|
|
|
55
46
|
/**
|
|
56
47
|
* 随机生成带前缀的字符串
|
|
57
48
|
* @param prefix 第一个参数为你想生成的固定的文字开头比如: 微信用户xxxxx
|
|
58
|
-
* @param
|
|
49
|
+
* @param length 第二个为你想生成出固定开头文字外的随机长度
|
|
59
50
|
* @returns
|
|
60
51
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var DICT = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
|
|
65
|
-
var maxPos = DICT.length;
|
|
66
|
-
var name = prefix === undefined ? '' : prefix;
|
|
67
|
-
name += (0, exports.random)(randomLength);
|
|
52
|
+
const randomPrefixedString = (prefix, length = 8) => {
|
|
53
|
+
let name = prefix === undefined ? '' : prefix;
|
|
54
|
+
name += (0, exports.random)(length);
|
|
68
55
|
return name;
|
|
69
56
|
};
|
|
70
|
-
exports.
|
|
57
|
+
exports.randomPrefixedString = randomPrefixedString;
|
|
71
58
|
/**
|
|
72
59
|
* 将字符串中的u16编码转换回汉字
|
|
73
60
|
* @param str
|
|
74
61
|
* @returns
|
|
75
62
|
*/
|
|
76
63
|
function unescapeUnicode(str) {
|
|
77
|
-
return str.replace(/\\u[\dA-F]{4}/gi,
|
|
64
|
+
return str.replace(/\\u[\dA-F]{4}/gi, (match) => {
|
|
78
65
|
return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16));
|
|
79
66
|
});
|
|
80
67
|
}
|
package/lib/utils/url.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.composeUrl = void 0;
|
|
4
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const url_1 = tslib_1.__importDefault(require("url"));
|
|
5
6
|
function composeUrl(url, params) {
|
|
6
|
-
|
|
7
|
+
const urlSp = new url_1.default.URLSearchParams(params);
|
|
7
8
|
if (url.includes('?')) {
|
|
8
|
-
return
|
|
9
|
+
return `${url}&${urlSp}`;
|
|
9
10
|
}
|
|
10
|
-
return
|
|
11
|
+
return `${url}?${urlSp}`;
|
|
11
12
|
}
|
|
12
13
|
exports.composeUrl = composeUrl;
|
package/lib/utils/uuid.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare function sequentialUuid({ random }: {
|
|
|
3
3
|
}): string;
|
|
4
4
|
export declare function shrinkUuidTo32Bytes(uuid: string): string;
|
|
5
5
|
export declare function expandUuidTo36Bytes(uuidShrinked: string): string;
|
|
6
|
-
export
|
|
6
|
+
export type GenerateIdOption = {
|
|
7
7
|
shuffle?: boolean;
|
|
8
8
|
};
|
|
9
9
|
export declare function generateNewIdAsync(option?: GenerateIdOption): Promise<string>;
|