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.
Files changed (158) hide show
  1. package/lib/actions/action.d.ts +8 -8
  2. package/lib/actions/action.js +2 -2
  3. package/lib/actions/relation.d.ts +1 -1
  4. package/lib/actions/relation.js +9 -22
  5. package/lib/base-app-domain/ActionAuth/Schema.d.ts +68 -42
  6. package/lib/base-app-domain/ActionAuth/Storage.js +12 -15
  7. package/lib/base-app-domain/ActionDefDict.d.ts +2 -3
  8. package/lib/base-app-domain/ActionDefDict.js +3 -5
  9. package/lib/base-app-domain/EntityDict.d.ts +5 -1
  10. package/lib/base-app-domain/I18n/Schema.d.ts +24 -24
  11. package/lib/base-app-domain/I18n/Storage.js +5 -5
  12. package/lib/base-app-domain/Modi/Action.d.ts +4 -4
  13. package/lib/base-app-domain/Modi/Action.js +3 -3
  14. package/lib/base-app-domain/Modi/Schema.d.ts +24 -24
  15. package/lib/base-app-domain/Modi/Storage.js +3 -3
  16. package/lib/base-app-domain/ModiEntity/Schema.d.ts +128 -55
  17. package/lib/base-app-domain/ModiEntity/Storage.js +2 -2
  18. package/lib/base-app-domain/Oper/Schema.d.ts +30 -29
  19. package/lib/base-app-domain/Oper/Storage.js +1 -1
  20. package/lib/base-app-domain/OperEntity/Schema.d.ts +126 -53
  21. package/lib/base-app-domain/OperEntity/Storage.js +2 -2
  22. package/lib/base-app-domain/Path/Schema.d.ts +149 -0
  23. package/lib/base-app-domain/Path/Schema.js +2 -0
  24. package/lib/base-app-domain/Path/Storage.d.ts +3 -0
  25. package/lib/base-app-domain/Path/Storage.js +54 -0
  26. package/lib/base-app-domain/Relation/Schema.d.ts +34 -34
  27. package/lib/base-app-domain/Relation/Storage.js +6 -6
  28. package/lib/base-app-domain/Relation.d.ts +0 -8
  29. package/lib/base-app-domain/Relation.js +1 -7
  30. package/lib/base-app-domain/RelationAuth/Schema.d.ts +74 -40
  31. package/lib/base-app-domain/RelationAuth/Storage.js +9 -11
  32. package/lib/base-app-domain/Storage.js +20 -16
  33. package/lib/base-app-domain/User/Action.d.ts +4 -4
  34. package/lib/base-app-domain/User/Action.js +3 -3
  35. package/lib/base-app-domain/User/Schema.d.ts +40 -27
  36. package/lib/base-app-domain/User/Storage.js +1 -1
  37. package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +264 -0
  38. package/lib/base-app-domain/UserEntityClaim/Schema.js +2 -0
  39. package/lib/base-app-domain/UserEntityClaim/Storage.d.ts +3 -0
  40. package/lib/base-app-domain/UserEntityClaim/Storage.js +37 -0
  41. package/lib/base-app-domain/UserEntityGrant/Action.d.ts +2 -2
  42. package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +55 -81
  43. package/lib/base-app-domain/UserEntityGrant/Storage.js +7 -11
  44. package/lib/base-app-domain/UserRelation/Schema.d.ts +50 -36
  45. package/lib/base-app-domain/UserRelation/Storage.js +7 -7
  46. package/lib/base-app-domain/_SubQuery.d.ts +45 -15
  47. package/lib/base-app-domain/index.js +1 -1
  48. package/lib/checkers/index.js +6 -7
  49. package/lib/compiler/env.js +16 -18
  50. package/lib/compiler/localeBuilder.js +83 -79
  51. package/lib/compiler/schemalBuilder.d.ts +16 -0
  52. package/lib/compiler/schemalBuilder.js +1160 -1378
  53. package/lib/entities/ActionAuth.d.ts +3 -5
  54. package/lib/entities/ActionAuth.js +9 -7
  55. package/lib/entities/I18n.js +1 -1
  56. package/lib/entities/Modi.js +2 -2
  57. package/lib/entities/ModiEntity.js +1 -1
  58. package/lib/entities/Oper.js +1 -1
  59. package/lib/entities/OperEntity.js +1 -1
  60. package/lib/entities/Path.d.ts +8 -0
  61. package/lib/entities/Path.js +35 -0
  62. package/lib/entities/Relation.js +1 -1
  63. package/lib/entities/RelationAuth.d.ts +2 -2
  64. package/lib/entities/RelationAuth.js +1 -1
  65. package/lib/entities/User.js +2 -2
  66. package/lib/entities/UserEntityClaim.d.ts +13 -0
  67. package/lib/entities/UserEntityClaim.js +17 -0
  68. package/lib/entities/UserEntityGrant.d.ts +5 -4
  69. package/lib/entities/UserEntityGrant.js +4 -7
  70. package/lib/entities/UserRelation.js +1 -1
  71. package/lib/index.d.ts +23 -0
  72. package/lib/index.js +37 -0
  73. package/lib/store/AsyncRowStore.d.ts +2 -1
  74. package/lib/store/AsyncRowStore.js +75 -149
  75. package/lib/store/CascadeStore.js +917 -1291
  76. package/lib/store/RelationAuth.d.ts +9 -16
  77. package/lib/store/RelationAuth.js +750 -908
  78. package/lib/store/SyncRowStore.d.ts +1 -1
  79. package/lib/store/SyncRowStore.js +27 -26
  80. package/lib/store/TriggerExecutor.d.ts +17 -10
  81. package/lib/store/TriggerExecutor.js +350 -423
  82. package/lib/store/actionAuth.js +13 -28
  83. package/lib/store/actionDef.js +118 -193
  84. package/lib/store/checker.js +225 -361
  85. package/lib/store/filter.d.ts +2 -3
  86. package/lib/store/filter.js +451 -589
  87. package/lib/store/modi.js +116 -177
  88. package/lib/store/relation.js +17 -17
  89. package/lib/timers/oper.d.ts +1 -1
  90. package/lib/timers/oper.js +44 -47
  91. package/lib/timers/vaccum.d.ts +2 -2
  92. package/lib/timers/vaccum.js +100 -165
  93. package/lib/triggers/index.js +1 -1
  94. package/lib/types/Action.d.ts +7 -7
  95. package/lib/types/AppLoader.d.ts +8 -2
  96. package/lib/types/AppLoader.js +4 -4
  97. package/lib/types/Aspect.d.ts +1 -3
  98. package/lib/types/Auth.d.ts +15 -19
  99. package/lib/types/Connector.d.ts +19 -15
  100. package/lib/types/Connector.js +0 -7
  101. package/lib/types/DataType.d.ts +19 -18
  102. package/lib/types/DataType.js +1 -1
  103. package/lib/types/Demand.d.ts +25 -25
  104. package/lib/types/Endpoint.d.ts +1 -1
  105. package/lib/types/Entity.d.ts +57 -53
  106. package/lib/types/Entity.js +3 -3
  107. package/lib/types/EntityDesc.d.ts +2 -1
  108. package/lib/types/Environment.d.ts +4 -4
  109. package/lib/types/Exception.d.ts +29 -2
  110. package/lib/types/Exception.js +205 -205
  111. package/lib/types/Expression.d.ts +14 -14
  112. package/lib/types/Expression.js +54 -87
  113. package/lib/types/Geo.d.ts +6 -6
  114. package/lib/types/Locale.d.ts +5 -5
  115. package/lib/types/Polyfill.d.ts +9 -9
  116. package/lib/types/Port.d.ts +4 -4
  117. package/lib/types/RowStore.d.ts +3 -3
  118. package/lib/types/RowStore.js +18 -19
  119. package/lib/types/Storage.d.ts +5 -4
  120. package/lib/types/Style.d.ts +2 -2
  121. package/lib/types/Timer.d.ts +3 -3
  122. package/lib/types/Trigger.d.ts +30 -14
  123. package/lib/types/Trigger.js +6 -2
  124. package/lib/types/Watcher.d.ts +2 -2
  125. package/lib/types/index.d.ts +1 -0
  126. package/lib/types/index.js +2 -1
  127. package/lib/types/schema/DataTypes.d.ts +7 -7
  128. package/lib/utils/SimpleConnector.d.ts +24 -10
  129. package/lib/utils/SimpleConnector.js +166 -144
  130. package/lib/utils/assert.js +2 -2
  131. package/lib/utils/concurrent.d.ts +1 -1
  132. package/lib/utils/concurrent.js +31 -57
  133. package/lib/utils/date.js +2 -2
  134. package/lib/utils/geo.js +8 -8
  135. package/lib/utils/lodash.d.ts +3 -1
  136. package/lib/utils/lodash.js +21 -34
  137. package/lib/utils/mask.js +12 -13
  138. package/lib/utils/money.d.ts +1 -1
  139. package/lib/utils/money.js +22 -11
  140. package/lib/utils/projection.d.ts +4 -0
  141. package/lib/utils/projection.js +15 -0
  142. package/lib/utils/random/random.js +11 -16
  143. package/lib/utils/random/random.mp.js +7 -18
  144. package/lib/utils/random/random.web.js +6 -12
  145. package/lib/utils/string.d.ts +4 -4
  146. package/lib/utils/string.js +19 -32
  147. package/lib/utils/url.js +5 -4
  148. package/lib/utils/uuid.d.ts +1 -1
  149. package/lib/utils/uuid.js +46 -85
  150. package/lib/utils/validator.d.ts +4 -3
  151. package/lib/utils/validator.js +35 -32
  152. package/lib/utils/version.js +6 -6
  153. package/package.json +7 -7
  154. package/src/entities/ActionAuth.ts +10 -10
  155. package/src/entities/Path.ts +43 -0
  156. package/src/entities/RelationAuth.ts +2 -1
  157. package/src/entities/UserEntityClaim.ts +30 -0
  158. package/src/entities/UserEntityGrant.ts +9 -12
@@ -1,76 +1,51 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RWLock = void 0;
4
- var tslib_1 = require("tslib");
5
- var assert_1 = tslib_1.__importDefault(require("assert"));
4
+ const tslib_1 = require("tslib");
5
+ const assert_1 = tslib_1.__importDefault(require("assert"));
6
6
  /**
7
7
  * 模拟一个读写锁,用于同步。
8
8
  * 注意,千万不要发生自己等自己
9
9
  */
10
- var RWLock = /** @class */ (function () {
11
- function RWLock() {
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
- RWLock.prototype.acquire = function (mode) {
18
- return tslib_1.__awaiter(this, void 0, void 0, function () {
19
- var p, p;
20
- var _this = this;
21
- return tslib_1.__generator(this, function (_a) {
22
- switch (_a.label) {
23
- case 0:
24
- if (!(mode === 'S')) return [3 /*break*/, 4];
25
- _a.label = 1;
26
- case 1:
27
- if (!(this.writeNumber > 0)) return [3 /*break*/, 3];
28
- p = new Promise(function (resolve) { return _this.readWaiter.push(resolve); });
29
- return [4 /*yield*/, p];
30
- case 2:
31
- _a.sent();
32
- return [3 /*break*/, 1];
33
- case 3:
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
- try {
58
- for (var _b = tslib_1.__values(this.readWaiter), _c = _b.next(); !_c.done; _c = _b.next()) {
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
- var f = this.writeWaiter.pop();
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
- var f = this.writeWaiter.pop();
57
+ const f = this.writeWaiter.pop();
83
58
  f && f(undefined);
84
59
  }
85
60
  }
86
- };
87
- return RWLock;
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
- var tslib_1 = require("tslib");
5
- var dayjs_1 = tslib_1.__importDefault(require("dayjs"));
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
- var R = 6378137; // 地球长半径
13
- var φ1 = toRadians(lat1);
14
- var φ2 = toRadians(lat2);
15
- var Δφ = toRadians(lat2 - lat1);
16
- var Δλ = toRadians(lon2 - lon1);
17
- var a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
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
- var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
21
- var d = R * c;
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;
@@ -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
- export { unset, pull, uniq, uniqBy, get, set, intersection, omit, merge, cloneDeep, pick, isEqual, union, difference, groupBy, };
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, };
@@ -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
- var tslib_1 = require("tslib");
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
- var unset_1 = tslib_1.__importDefault(require("lodash/unset"));
9
+ const unset_1 = tslib_1.__importDefault(require("lodash/unset"));
10
10
  exports.unset = unset_1.default;
11
- var uniqBy_1 = tslib_1.__importDefault(require("lodash/uniqBy"));
11
+ const uniqBy_1 = tslib_1.__importDefault(require("lodash/uniqBy"));
12
12
  exports.uniqBy = uniqBy_1.default;
13
- var pull_1 = tslib_1.__importDefault(require("lodash/pull"));
13
+ const pull_1 = tslib_1.__importDefault(require("lodash/pull"));
14
14
  exports.pull = pull_1.default;
15
- var uniq_1 = tslib_1.__importDefault(require("lodash/uniq"));
15
+ const uniq_1 = tslib_1.__importDefault(require("lodash/uniq"));
16
16
  exports.uniq = uniq_1.default;
17
- var get_1 = tslib_1.__importDefault(require("lodash/get"));
17
+ const get_1 = tslib_1.__importDefault(require("lodash/get"));
18
18
  exports.get = get_1.default;
19
- var set_1 = tslib_1.__importDefault(require("lodash/set"));
19
+ const set_1 = tslib_1.__importDefault(require("lodash/set"));
20
20
  exports.set = set_1.default;
21
- var intersection_1 = tslib_1.__importDefault(require("lodash/intersection"));
21
+ const intersection_1 = tslib_1.__importDefault(require("lodash/intersection"));
22
22
  exports.intersection = intersection_1.default;
23
- var omit_1 = tslib_1.__importDefault(require("lodash/omit"));
23
+ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
24
24
  exports.omit = omit_1.default;
25
- var merge_1 = tslib_1.__importDefault(require("lodash/merge"));
25
+ const merge_1 = tslib_1.__importDefault(require("lodash/merge"));
26
26
  exports.merge = merge_1.default;
27
- var cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
27
+ const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
28
28
  exports.cloneDeep = cloneDeep_1.default;
29
- var pick_1 = tslib_1.__importDefault(require("lodash/pick"));
29
+ const pick_1 = tslib_1.__importDefault(require("lodash/pick"));
30
30
  exports.pick = pick_1.default;
31
- var isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
31
+ const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
32
32
  exports.isEqual = isEqual_1.default;
33
- var union_1 = tslib_1.__importDefault(require("lodash/union"));
33
+ const union_1 = tslib_1.__importDefault(require("lodash/union"));
34
34
  exports.union = union_1.default;
35
- var difference_1 = tslib_1.__importDefault(require("lodash/difference"));
35
+ const difference_1 = tslib_1.__importDefault(require("lodash/difference"));
36
36
  exports.difference = difference_1.default;
37
- var groupBy_1 = tslib_1.__importDefault(require("lodash/groupBy"));
37
+ const groupBy_1 = tslib_1.__importDefault(require("lodash/groupBy"));
38
38
  exports.groupBy = groupBy_1.default;
39
- // export {
40
- // unset,
41
- // pull,
42
- // uniq,
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
- var maskIdCard = function (idCardNumber) {
4
+ const maskIdCard = (idCardNumber) => {
5
5
  if (!idCardNumber instanceof String) {
6
6
  throw new Error("身份证号码必须是String类型");
7
7
  }
8
- var begin = idCardNumber.slice(0, 4);
9
- var end = idCardNumber.slice(idCardNumber.length - 4, 4);
10
- for (var i = 0; i < idCardNumber.length - 8; i++) {
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
- var maskMobile = function (mobile) {
17
- var begin = mobile.slice(0, 3);
18
- var end = mobile.slice(7, 11);
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
- var maskName = function (name) {
22
+ const maskName = (name) => {
23
23
  return name.slice(0, name.length - 1).concat("*");
24
24
  };
25
25
  exports.maskName = maskName;
26
- var maskStar = function (str, frontLen, endLen, star) {
27
- if (star === void 0) { star = '*'; }
28
- var len = str.length - frontLen - endLen;
29
- var xing = '';
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);
@@ -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 };
@@ -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
- var ToCent = function (float) {
4
+ const ToCent = (float) => {
5
5
  return Math.round(float * 100);
6
6
  };
7
7
  exports.ToCent = ToCent;
8
- var ToYuan = function (int) {
8
+ const ToYuan = (int) => {
9
9
  return Math.round(int) / 100;
10
10
  };
11
11
  exports.ToYuan = ToYuan;
12
- var StringToCent = function (value, allowNegative) {
13
- var numValue = parseInt(value, 10);
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
- var CentToString = function (value) {
19
+ const CentToString = (value) => {
20
20
  if (typeof value === 'number') {
21
- return "".concat(ToYuan(value));
21
+ return `${ToYuan(value)}`;
22
22
  }
23
23
  };
24
24
  exports.CentToString = CentToString;
25
- var ThousandCont = function (value) {
26
- var value1 = "".concat(value);
27
- var numArr = value1.split('.');
25
+ const ThousandCont = (value, decimalPlaces) => {
26
+ let value1 = `${value}`;
27
+ const numArr = value1.split('.');
28
28
  value1 = numArr[0];
29
- var result = '';
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
- result = numArr[1] ? result + '.' + numArr[1] : result;
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
- var tslib_1 = require("tslib");
5
- var node_crypto_1 = require("node:crypto");
6
- function getRandomValues(length) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function () {
8
- return tslib_1.__generator(this, function (_a) {
9
- if (length > 65536) {
10
- throw new Error('Can only request a maximum of 65536 bytes');
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
- return [2 /*return*/, new Promise(function (resolve, reject) {
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
- var tslib_1 = require("tslib");
6
- function getRandomValues(length) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function () {
8
- var randomValues;
9
- return tslib_1.__generator(this, function (_a) {
10
- switch (_a.label) {
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
- var tslib_1 = require("tslib");
5
- function getRandomValues(length) {
6
- return tslib_1.__awaiter(this, void 0, void 0, function () {
7
- var randomValues;
8
- return tslib_1.__generator(this, function (_a) {
9
- if (length > 65536) {
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;
@@ -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 randomLength
12
+ * @param length
13
13
  * @returns
14
14
  */
15
- export declare const random: (randomLength?: number) => string;
15
+ export declare const random: (length?: number) => string;
16
16
  /**
17
17
  * 随机生成带前缀的字符串
18
18
  * @param prefix 第一个参数为你想生成的固定的文字开头比如: 微信用户xxxxx
19
- * @param randomLength 第二个为你想生成出固定开头文字外的随机长度
19
+ * @param length 第二个为你想生成出固定开头文字外的随机长度
20
20
  * @returns
21
21
  */
22
- export declare const randomName: (prefix?: string, randomLength?: number) => string;
22
+ export declare const randomPrefixedString: (prefix?: string, length?: number) => string;
23
23
  /**
24
24
  * 将字符串中的u16编码转换回汉字
25
25
  * @param str
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unescapeUnicode = exports.randomName = exports.random = exports.template = exports.firstLetterUpperCase = exports.firstLetterLowerCase = void 0;
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
- var template = function (strings) {
19
- var keys = [];
20
- for (var _i = 1; _i < arguments.length; _i++) {
21
- keys[_i - 1] = arguments[_i];
22
- }
23
- return (function () {
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 randomLength
32
+ * @param length
41
33
  * @returns
42
34
  */
43
- var random = function (randomLength) {
44
- if (randomLength === void 0) { randomLength = 16; }
35
+ const random = (length = 16) => {
45
36
  // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
46
- var DICT = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
47
- var maxPos = DICT.length;
48
- var pwd = '';
49
- for (var i = 0; i < randomLength; i++) {
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 randomLength 第二个为你想生成出固定开头文字外的随机长度
49
+ * @param length 第二个为你想生成出固定开头文字外的随机长度
59
50
  * @returns
60
51
  */
61
- var randomName = function (prefix, randomLength) {
62
- if (randomLength === void 0) { randomLength = 8; }
63
- // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
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.randomName = randomName;
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, function (match) {
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
- var url_1 = require("url");
4
+ const tslib_1 = require("tslib");
5
+ const url_1 = tslib_1.__importDefault(require("url"));
5
6
  function composeUrl(url, params) {
6
- var urlSp = new url_1.URLSearchParams(params);
7
+ const urlSp = new url_1.default.URLSearchParams(params);
7
8
  if (url.includes('?')) {
8
- return "".concat(url, "&").concat(urlSp);
9
+ return `${url}&${urlSp}`;
9
10
  }
10
- return "".concat(url, "?").concat(urlSp);
11
+ return `${url}?${urlSp}`;
11
12
  }
12
13
  exports.composeUrl = composeUrl;
@@ -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 declare type GenerateIdOption = {
6
+ export type GenerateIdOption = {
7
7
  shuffle?: boolean;
8
8
  };
9
9
  export declare function generateNewIdAsync(option?: GenerateIdOption): Promise<string>;