oak-domain 2.3.2 → 2.4.1
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 +16 -16
- package/lib/actions/action.js +17 -17
- package/lib/actions/relation.d.ts +5 -1
- package/lib/actions/relation.js +38 -2
- package/lib/base-app-domain/ActionDefDict.d.ts +5 -5
- package/lib/base-app-domain/ActionDefDict.js +7 -7
- package/lib/base-app-domain/EntityDict.d.ts +12 -12
- package/lib/base-app-domain/EntityDict.js +2 -2
- package/lib/base-app-domain/Modi/Action.d.ts +10 -10
- package/lib/base-app-domain/Modi/Action.js +14 -14
- package/lib/base-app-domain/Modi/Schema.d.ts +146 -148
- package/lib/base-app-domain/Modi/Schema.js +2 -2
- package/lib/base-app-domain/Modi/Storage.d.ts +3 -3
- package/lib/base-app-domain/Modi/Storage.js +60 -60
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +162 -164
- package/lib/base-app-domain/ModiEntity/Schema.js +2 -2
- package/lib/base-app-domain/ModiEntity/Storage.d.ts +3 -3
- package/lib/base-app-domain/ModiEntity/Storage.js +26 -26
- package/lib/base-app-domain/Oper/Schema.d.ts +144 -146
- package/lib/base-app-domain/Oper/Schema.js +2 -2
- package/lib/base-app-domain/Oper/Storage.d.ts +3 -3
- package/lib/base-app-domain/Oper/Storage.js +29 -29
- package/lib/base-app-domain/OperEntity/Schema.d.ts +178 -180
- package/lib/base-app-domain/OperEntity/Schema.js +2 -2
- package/lib/base-app-domain/OperEntity/Storage.d.ts +3 -3
- package/lib/base-app-domain/OperEntity/Storage.js +26 -26
- package/lib/base-app-domain/Storage.d.ts +3 -3
- package/lib/base-app-domain/Storage.js +15 -15
- package/lib/base-app-domain/User/Schema.d.ts +128 -130
- package/lib/base-app-domain/User/Schema.js +2 -2
- package/lib/base-app-domain/User/Storage.d.ts +3 -3
- package/lib/base-app-domain/User/Storage.js +25 -25
- package/lib/base-app-domain/_SubQuery.d.ts +36 -36
- package/lib/base-app-domain/_SubQuery.js +2 -2
- package/lib/base-app-domain/index.d.ts +3 -3
- package/lib/base-app-domain/index.js +6 -6
- package/lib/checkers/index.d.ts +5 -5
- package/lib/checkers/index.js +15 -13
- package/lib/compiler/env.d.ts +11 -11
- package/lib/compiler/env.js +39 -39
- package/lib/compiler/schemalBuilder.d.ts +2 -2
- package/lib/compiler/schemalBuilder.js +3301 -3245
- package/lib/compiler/uiBuilder.d.ts +1 -1
- package/lib/compiler/uiBuilder.js +3 -3
- package/lib/entities/Modi.d.ts +11 -11
- package/lib/entities/Modi.js +46 -46
- package/lib/entities/ModiEntity.d.ts +8 -8
- package/lib/entities/ModiEntity.js +15 -15
- package/lib/entities/Oper.d.ts +10 -10
- package/lib/entities/Oper.js +17 -17
- package/lib/entities/OperEntity.d.ts +8 -8
- package/lib/entities/OperEntity.js +15 -15
- package/lib/entities/User.d.ts +7 -7
- package/lib/entities/User.js +12 -12
- package/lib/store/AsyncRowStore.d.ts +48 -48
- package/lib/store/AsyncRowStore.js +183 -183
- package/lib/store/CascadeStore.d.ts +91 -91
- package/lib/store/CascadeStore.js +1594 -1594
- package/lib/store/SyncRowStore.d.ts +29 -29
- package/lib/store/SyncRowStore.js +48 -48
- package/lib/store/TriggerExecutor.d.ts +32 -32
- package/lib/store/TriggerExecutor.js +527 -508
- package/lib/store/actionDef.d.ts +9 -9
- package/lib/store/actionDef.js +135 -135
- package/lib/store/checker.d.ts +13 -7
- package/lib/store/checker.js +498 -391
- package/lib/store/filter.d.ts +109 -100
- package/lib/store/filter.js +893 -878
- package/lib/store/modi.d.ts +13 -13
- package/lib/store/modi.js +198 -206
- package/lib/store/relation.d.ts +13 -13
- package/lib/store/relation.js +66 -66
- package/lib/store/selection.d.ts +7 -7
- package/lib/store/selection.js +235 -235
- package/lib/triggers/index.d.ts +6 -6
- package/lib/triggers/index.js +11 -11
- package/lib/triggers/modi.d.ts +5 -5
- package/lib/triggers/modi.js +72 -72
- package/lib/types/Action.d.ts +18 -14
- package/lib/types/Action.js +2 -2
- package/lib/types/AppLoader.d.ts +11 -11
- package/lib/types/AppLoader.js +10 -10
- package/lib/types/Aspect.d.ts +12 -12
- package/lib/types/Aspect.js +4 -4
- package/lib/types/Auth.d.ts +66 -66
- package/lib/types/Auth.js +2 -2
- package/lib/types/Connector.d.ts +26 -26
- package/lib/types/Connector.js +9 -9
- package/lib/types/Context.d.ts +7 -7
- package/lib/types/Context.js +3 -3
- package/lib/types/DataType.d.ts +18 -18
- package/lib/types/DataType.js +5 -5
- package/lib/types/Demand.d.ts +77 -77
- package/lib/types/Demand.js +9 -9
- package/lib/types/Endpoint.d.ts +11 -0
- package/lib/types/Endpoint.js +3 -0
- package/lib/types/Entity.d.ts +176 -190
- package/lib/types/Entity.js +14 -15
- package/lib/types/Exception.d.ts +88 -83
- package/lib/types/Exception.js +267 -252
- package/lib/types/Expression.d.ts +163 -141
- package/lib/types/Expression.js +427 -402
- package/lib/types/Geo.d.ts +18 -18
- package/lib/types/Geo.js +2 -2
- package/lib/types/Locale.d.ts +24 -24
- package/lib/types/Locale.js +2 -2
- package/lib/types/Logger.d.ts +5 -5
- package/lib/types/Logger.js +3 -3
- package/lib/types/Polyfill.d.ts +23 -23
- package/lib/types/Polyfill.js +2 -2
- package/lib/types/Port.d.ts +17 -0
- package/lib/types/Port.js +2 -0
- package/lib/types/RowStore.d.ts +12 -12
- package/lib/types/RowStore.js +34 -34
- package/lib/types/Storage.d.ts +56 -56
- package/lib/types/Storage.js +2 -2
- package/lib/types/Timer.d.ts +13 -13
- package/lib/types/Timer.js +2 -2
- package/lib/types/Trigger.d.ts +100 -100
- package/lib/types/Trigger.js +39 -39
- package/lib/types/Txn.d.ts +2 -2
- package/lib/types/Txn.js +3 -3
- package/lib/types/Watcher.d.ts +19 -19
- package/lib/types/Watcher.js +4 -4
- package/lib/types/index.d.ts +21 -19
- package/lib/types/index.js +24 -22
- package/lib/types/schema/DataTypes.d.ts +32 -32
- package/lib/types/schema/DataTypes.js +3 -3
- package/lib/utils/SimpleConnector.d.ts +30 -30
- package/lib/utils/SimpleConnector.js +117 -117
- package/lib/utils/assert.d.ts +5 -5
- package/lib/utils/assert.js +9 -9
- package/lib/utils/concurrent.d.ts +15 -15
- package/lib/utils/concurrent.js +89 -89
- package/lib/utils/cron.d.ts +1 -1
- package/lib/utils/cron.js +18 -18
- package/lib/utils/date.d.ts +1 -0
- package/lib/utils/date.js +18 -0
- package/lib/utils/geo.d.ts +4 -4
- package/lib/utils/geo.js +24 -24
- package/lib/utils/lodash.d.ts +20 -20
- package/lib/utils/lodash.js +55 -55
- package/lib/utils/random/random.d.ts +1 -1
- package/lib/utils/random/random.js +24 -24
- package/lib/utils/random/random.mp.d.ts +1 -1
- package/lib/utils/random/random.mp.js +25 -25
- package/lib/utils/random/random.web.d.ts +1 -1
- package/lib/utils/random/random.web.js +17 -17
- package/lib/utils/string.d.ts +22 -22
- package/lib/utils/string.js +70 -70
- package/lib/utils/uuid.d.ts +12 -12
- package/lib/utils/uuid.js +194 -194
- package/lib/utils/validator.d.ts +23 -23
- package/lib/utils/validator.js +123 -123
- package/package.json +48 -48
- package/src/entities/Modi.ts +68 -68
- package/src/entities/ModiEntity.ts +24 -24
- package/src/entities/Oper.ts +28 -28
- package/src/entities/OperEntity.ts +24 -24
- package/src/entities/User.ts +19 -19
package/lib/utils/uuid.js
CHANGED
|
@@ -1,194 +1,194 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateNewId = exports.setGenerateIdOption = exports.produceIds = exports.generateNewIdAsync = exports.expandUuidTo36Bytes = exports.shrinkUuidTo32Bytes = exports.sequentialUuid = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var uuid_1 = require("uuid");
|
|
6
|
-
var random_1 = require("./random/random");
|
|
7
|
-
var _nodeId;
|
|
8
|
-
var _clockseq;
|
|
9
|
-
// Previous uuid creation time
|
|
10
|
-
var _lastMSecs = 0;
|
|
11
|
-
var _lastNSecs = 0;
|
|
12
|
-
// 根据uuid v1改的,产生按时间顺序uuid的函数(更优于底层数据库的插入行为)
|
|
13
|
-
// **`v1()` - Generate time-based UUID**
|
|
14
|
-
//
|
|
15
|
-
// Inspired by https://github.com/LiosK/UUID.js
|
|
16
|
-
// and http://docs.python.org/library/uuid.html
|
|
17
|
-
var byteToHex = [];
|
|
18
|
-
for (var i = 0; i < 256; ++i) {
|
|
19
|
-
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
20
|
-
}
|
|
21
|
-
function unsafeStringify(arr, offset) {
|
|
22
|
-
if (offset === void 0) { offset = 0; }
|
|
23
|
-
// Note: Be careful editing this code! It's been tuned for performance
|
|
24
|
-
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
25
|
-
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
26
|
-
}
|
|
27
|
-
// See https://github.com/uuidjs/uuid for API details
|
|
28
|
-
function sequentialUuid(_a) {
|
|
29
|
-
var random = _a.random;
|
|
30
|
-
var i = 0;
|
|
31
|
-
var b = new Array(16);
|
|
32
|
-
var node = _nodeId;
|
|
33
|
-
var clockseq = _clockseq;
|
|
34
|
-
// node and clockseq need to be initialized to random values if they're not
|
|
35
|
-
// specified. We do this lazily to minimize issues related to insufficient
|
|
36
|
-
// system entropy. See #189
|
|
37
|
-
if (node == null || clockseq == null) {
|
|
38
|
-
var seedBytes = random;
|
|
39
|
-
if (node == null) {
|
|
40
|
-
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
|
41
|
-
node = _nodeId = [
|
|
42
|
-
seedBytes[0] | 0x01,
|
|
43
|
-
seedBytes[1],
|
|
44
|
-
seedBytes[2],
|
|
45
|
-
seedBytes[3],
|
|
46
|
-
seedBytes[4],
|
|
47
|
-
seedBytes[5],
|
|
48
|
-
];
|
|
49
|
-
}
|
|
50
|
-
if (clockseq == null) {
|
|
51
|
-
// Per 4.2.2, randomize (14 bit) clockseq
|
|
52
|
-
clockseq = _clockseq = ((seedBytes[6] << 8) | seedBytes[7]) & 0x3fff;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// UUID timestamps are 100 nano-second units since the Gregorian epoch,
|
|
56
|
-
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
|
|
57
|
-
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
|
|
58
|
-
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
|
|
59
|
-
var msecs = Date.now();
|
|
60
|
-
// Per 4.2.1.2, use count of uuid's generated during the current clock
|
|
61
|
-
// cycle to simulate higher resolution clock
|
|
62
|
-
var nsecs = _lastNSecs + 1;
|
|
63
|
-
// Time since last uuid creation (in msecs)
|
|
64
|
-
var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000;
|
|
65
|
-
// Per 4.2.1.2, Bump clockseq on clock regression
|
|
66
|
-
if (dt < 0) {
|
|
67
|
-
clockseq = (clockseq + 1) & 0x3fff;
|
|
68
|
-
}
|
|
69
|
-
// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
|
|
70
|
-
// time interval
|
|
71
|
-
if ((dt < 0 || msecs > _lastMSecs)) {
|
|
72
|
-
nsecs = 0;
|
|
73
|
-
}
|
|
74
|
-
// Per 4.2.1.2 Throw error if too many uuids are requested
|
|
75
|
-
if (nsecs >= 10000) {
|
|
76
|
-
throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
|
|
77
|
-
}
|
|
78
|
-
_lastMSecs = msecs;
|
|
79
|
-
_lastNSecs = nsecs;
|
|
80
|
-
_clockseq = clockseq;
|
|
81
|
-
// Per 4.1.4 - Convert from unix epoch to Gregorian epoch
|
|
82
|
-
msecs += 12219292800000;
|
|
83
|
-
// `time_high_and_version`
|
|
84
|
-
var tmh = ((msecs / 0x100000000) * 10000) & 0xfffffff;
|
|
85
|
-
b[i++] = ((tmh >>> 24) & 0xf) | 0x10; // include version
|
|
86
|
-
b[i++] = (tmh >>> 16) & 0xff;
|
|
87
|
-
// `time_mid`
|
|
88
|
-
b[i++] = (tmh >>> 8) & 0xff;
|
|
89
|
-
b[i++] = tmh & 0xff;
|
|
90
|
-
// `time_low`
|
|
91
|
-
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
|
92
|
-
b[i++] = (tl >>> 24) & 0xff;
|
|
93
|
-
b[i++] = (tl >>> 16) & 0xff;
|
|
94
|
-
b[i++] = (tl >>> 8) & 0xff;
|
|
95
|
-
b[i++] = tl & 0xff;
|
|
96
|
-
// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
|
|
97
|
-
b[i++] = (clockseq >>> 8) | 0x80;
|
|
98
|
-
// `clock_seq_low`
|
|
99
|
-
b[i++] = clockseq & 0xff;
|
|
100
|
-
// `node`
|
|
101
|
-
for (var n = 0; n < 6; ++n) {
|
|
102
|
-
b[i + n] = node[n];
|
|
103
|
-
}
|
|
104
|
-
return unsafeStringify(b);
|
|
105
|
-
}
|
|
106
|
-
exports.sequentialUuid = sequentialUuid;
|
|
107
|
-
function shrinkUuidTo32Bytes(uuid) {
|
|
108
|
-
return uuid.replaceAll('-', '');
|
|
109
|
-
}
|
|
110
|
-
exports.shrinkUuidTo32Bytes = shrinkUuidTo32Bytes;
|
|
111
|
-
function expandUuidTo36Bytes(uuidShrinked) {
|
|
112
|
-
return "".concat(uuidShrinked.slice(0, 8), "-").concat(uuidShrinked.slice(8, 12), "-").concat(uuidShrinked.slice(12, 16), "-").concat(uuidShrinked.slice(16, 20), "-").concat(uuidShrinked.slice(20));
|
|
113
|
-
}
|
|
114
|
-
exports.expandUuidTo36Bytes = expandUuidTo36Bytes;
|
|
115
|
-
// 直接生成uuid的接口,为了适配各种环境,写成异步
|
|
116
|
-
function generateNewIdAsync(option) {
|
|
117
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var option2, _a, _b;
|
|
119
|
-
var _c, _d;
|
|
120
|
-
return tslib_1.__generator(this, function (_e) {
|
|
121
|
-
switch (_e.label) {
|
|
122
|
-
case 0:
|
|
123
|
-
option2 = option || ID_OPTION;
|
|
124
|
-
if (!((option2 === null || option2 === void 0 ? void 0 : option2.shuffle) || process.env.NODE_ENV === 'development')) return [3 /*break*/, 2];
|
|
125
|
-
_a = uuid_1.v4;
|
|
126
|
-
_c = {};
|
|
127
|
-
return [4 /*yield*/, (0, random_1.getRandomValues)(16)];
|
|
128
|
-
case 1: return [2 /*return*/, _a.apply(void 0, [(_c.random = _e.sent(), _c)])];
|
|
129
|
-
case 2:
|
|
130
|
-
_b = sequentialUuid;
|
|
131
|
-
_d = {};
|
|
132
|
-
return [4 /*yield*/, (0, random_1.getRandomValues)(16)];
|
|
133
|
-
case 3: return [2 /*return*/, _b.apply(void 0, [(_d.random = _e.sent(), _d)])];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
exports.generateNewIdAsync = generateNewIdAsync;
|
|
139
|
-
// 实现同步的id缓存接口,以便于前台使用
|
|
140
|
-
var ID_BUFFER = [];
|
|
141
|
-
var ID_OPTION = {};
|
|
142
|
-
function produceIds() {
|
|
143
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
144
|
-
var iter, _a, _b;
|
|
145
|
-
return tslib_1.__generator(this, function (_c) {
|
|
146
|
-
switch (_c.label) {
|
|
147
|
-
case 0:
|
|
148
|
-
iter = 0;
|
|
149
|
-
_c.label = 1;
|
|
150
|
-
case 1:
|
|
151
|
-
if (!(iter < 128)) return [3 /*break*/, 4];
|
|
152
|
-
_b = (_a = ID_BUFFER).push;
|
|
153
|
-
return [4 /*yield*/, generateNewIdAsync()];
|
|
154
|
-
case 2:
|
|
155
|
-
_b.apply(_a, [_c.sent()]);
|
|
156
|
-
_c.label = 3;
|
|
157
|
-
case 3:
|
|
158
|
-
iter++;
|
|
159
|
-
return [3 /*break*/, 1];
|
|
160
|
-
case 4: return [2 /*return*/];
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
exports.produceIds = produceIds;
|
|
166
|
-
produceIds();
|
|
167
|
-
function setGenerateIdOption(option) {
|
|
168
|
-
ID_OPTION = option;
|
|
169
|
-
ID_BUFFER.splice(0, ID_BUFFER.length);
|
|
170
|
-
return produceIds();
|
|
171
|
-
}
|
|
172
|
-
exports.setGenerateIdOption = setGenerateIdOption;
|
|
173
|
-
function generateNewId() {
|
|
174
|
-
if (ID_BUFFER.length > 0) {
|
|
175
|
-
var id = ID_BUFFER.pop();
|
|
176
|
-
if (ID_BUFFER.length < 64) {
|
|
177
|
-
produceIds();
|
|
178
|
-
}
|
|
179
|
-
return id;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
// 如果没来的及填满缓冲池,这里用一个简单的算法产生同步id(在小程序环境下跑出来过)
|
|
183
|
-
var random = new Uint8Array(16);
|
|
184
|
-
var iter = 0;
|
|
185
|
-
do {
|
|
186
|
-
random[iter] = Math.ceil(Math.random() * 1000) % 128;
|
|
187
|
-
} while (++iter < 16);
|
|
188
|
-
if ((ID_OPTION === null || ID_OPTION === void 0 ? void 0 : ID_OPTION.shuffle) || process.env.NODE_ENV === 'development') {
|
|
189
|
-
return (0, uuid_1.v4)({ random: random });
|
|
190
|
-
}
|
|
191
|
-
return sequentialUuid({ random: random });
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
exports.generateNewId = generateNewId;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateNewId = exports.setGenerateIdOption = exports.produceIds = exports.generateNewIdAsync = exports.expandUuidTo36Bytes = exports.shrinkUuidTo32Bytes = exports.sequentialUuid = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var uuid_1 = require("uuid");
|
|
6
|
+
var random_1 = require("./random/random");
|
|
7
|
+
var _nodeId;
|
|
8
|
+
var _clockseq;
|
|
9
|
+
// Previous uuid creation time
|
|
10
|
+
var _lastMSecs = 0;
|
|
11
|
+
var _lastNSecs = 0;
|
|
12
|
+
// 根据uuid v1改的,产生按时间顺序uuid的函数(更优于底层数据库的插入行为)
|
|
13
|
+
// **`v1()` - Generate time-based UUID**
|
|
14
|
+
//
|
|
15
|
+
// Inspired by https://github.com/LiosK/UUID.js
|
|
16
|
+
// and http://docs.python.org/library/uuid.html
|
|
17
|
+
var byteToHex = [];
|
|
18
|
+
for (var i = 0; i < 256; ++i) {
|
|
19
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
20
|
+
}
|
|
21
|
+
function unsafeStringify(arr, offset) {
|
|
22
|
+
if (offset === void 0) { offset = 0; }
|
|
23
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
24
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
25
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
// See https://github.com/uuidjs/uuid for API details
|
|
28
|
+
function sequentialUuid(_a) {
|
|
29
|
+
var random = _a.random;
|
|
30
|
+
var i = 0;
|
|
31
|
+
var b = new Array(16);
|
|
32
|
+
var node = _nodeId;
|
|
33
|
+
var clockseq = _clockseq;
|
|
34
|
+
// node and clockseq need to be initialized to random values if they're not
|
|
35
|
+
// specified. We do this lazily to minimize issues related to insufficient
|
|
36
|
+
// system entropy. See #189
|
|
37
|
+
if (node == null || clockseq == null) {
|
|
38
|
+
var seedBytes = random;
|
|
39
|
+
if (node == null) {
|
|
40
|
+
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
|
41
|
+
node = _nodeId = [
|
|
42
|
+
seedBytes[0] | 0x01,
|
|
43
|
+
seedBytes[1],
|
|
44
|
+
seedBytes[2],
|
|
45
|
+
seedBytes[3],
|
|
46
|
+
seedBytes[4],
|
|
47
|
+
seedBytes[5],
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
if (clockseq == null) {
|
|
51
|
+
// Per 4.2.2, randomize (14 bit) clockseq
|
|
52
|
+
clockseq = _clockseq = ((seedBytes[6] << 8) | seedBytes[7]) & 0x3fff;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// UUID timestamps are 100 nano-second units since the Gregorian epoch,
|
|
56
|
+
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
|
|
57
|
+
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
|
|
58
|
+
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
|
|
59
|
+
var msecs = Date.now();
|
|
60
|
+
// Per 4.2.1.2, use count of uuid's generated during the current clock
|
|
61
|
+
// cycle to simulate higher resolution clock
|
|
62
|
+
var nsecs = _lastNSecs + 1;
|
|
63
|
+
// Time since last uuid creation (in msecs)
|
|
64
|
+
var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000;
|
|
65
|
+
// Per 4.2.1.2, Bump clockseq on clock regression
|
|
66
|
+
if (dt < 0) {
|
|
67
|
+
clockseq = (clockseq + 1) & 0x3fff;
|
|
68
|
+
}
|
|
69
|
+
// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
|
|
70
|
+
// time interval
|
|
71
|
+
if ((dt < 0 || msecs > _lastMSecs)) {
|
|
72
|
+
nsecs = 0;
|
|
73
|
+
}
|
|
74
|
+
// Per 4.2.1.2 Throw error if too many uuids are requested
|
|
75
|
+
if (nsecs >= 10000) {
|
|
76
|
+
throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
|
|
77
|
+
}
|
|
78
|
+
_lastMSecs = msecs;
|
|
79
|
+
_lastNSecs = nsecs;
|
|
80
|
+
_clockseq = clockseq;
|
|
81
|
+
// Per 4.1.4 - Convert from unix epoch to Gregorian epoch
|
|
82
|
+
msecs += 12219292800000;
|
|
83
|
+
// `time_high_and_version`
|
|
84
|
+
var tmh = ((msecs / 0x100000000) * 10000) & 0xfffffff;
|
|
85
|
+
b[i++] = ((tmh >>> 24) & 0xf) | 0x10; // include version
|
|
86
|
+
b[i++] = (tmh >>> 16) & 0xff;
|
|
87
|
+
// `time_mid`
|
|
88
|
+
b[i++] = (tmh >>> 8) & 0xff;
|
|
89
|
+
b[i++] = tmh & 0xff;
|
|
90
|
+
// `time_low`
|
|
91
|
+
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
|
92
|
+
b[i++] = (tl >>> 24) & 0xff;
|
|
93
|
+
b[i++] = (tl >>> 16) & 0xff;
|
|
94
|
+
b[i++] = (tl >>> 8) & 0xff;
|
|
95
|
+
b[i++] = tl & 0xff;
|
|
96
|
+
// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
|
|
97
|
+
b[i++] = (clockseq >>> 8) | 0x80;
|
|
98
|
+
// `clock_seq_low`
|
|
99
|
+
b[i++] = clockseq & 0xff;
|
|
100
|
+
// `node`
|
|
101
|
+
for (var n = 0; n < 6; ++n) {
|
|
102
|
+
b[i + n] = node[n];
|
|
103
|
+
}
|
|
104
|
+
return unsafeStringify(b);
|
|
105
|
+
}
|
|
106
|
+
exports.sequentialUuid = sequentialUuid;
|
|
107
|
+
function shrinkUuidTo32Bytes(uuid) {
|
|
108
|
+
return uuid.replaceAll('-', '');
|
|
109
|
+
}
|
|
110
|
+
exports.shrinkUuidTo32Bytes = shrinkUuidTo32Bytes;
|
|
111
|
+
function expandUuidTo36Bytes(uuidShrinked) {
|
|
112
|
+
return "".concat(uuidShrinked.slice(0, 8), "-").concat(uuidShrinked.slice(8, 12), "-").concat(uuidShrinked.slice(12, 16), "-").concat(uuidShrinked.slice(16, 20), "-").concat(uuidShrinked.slice(20));
|
|
113
|
+
}
|
|
114
|
+
exports.expandUuidTo36Bytes = expandUuidTo36Bytes;
|
|
115
|
+
// 直接生成uuid的接口,为了适配各种环境,写成异步
|
|
116
|
+
function generateNewIdAsync(option) {
|
|
117
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
118
|
+
var option2, _a, _b;
|
|
119
|
+
var _c, _d;
|
|
120
|
+
return tslib_1.__generator(this, function (_e) {
|
|
121
|
+
switch (_e.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
option2 = option || ID_OPTION;
|
|
124
|
+
if (!((option2 === null || option2 === void 0 ? void 0 : option2.shuffle) || process.env.NODE_ENV === 'development')) return [3 /*break*/, 2];
|
|
125
|
+
_a = uuid_1.v4;
|
|
126
|
+
_c = {};
|
|
127
|
+
return [4 /*yield*/, (0, random_1.getRandomValues)(16)];
|
|
128
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [(_c.random = _e.sent(), _c)])];
|
|
129
|
+
case 2:
|
|
130
|
+
_b = sequentialUuid;
|
|
131
|
+
_d = {};
|
|
132
|
+
return [4 /*yield*/, (0, random_1.getRandomValues)(16)];
|
|
133
|
+
case 3: return [2 /*return*/, _b.apply(void 0, [(_d.random = _e.sent(), _d)])];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
exports.generateNewIdAsync = generateNewIdAsync;
|
|
139
|
+
// 实现同步的id缓存接口,以便于前台使用
|
|
140
|
+
var ID_BUFFER = [];
|
|
141
|
+
var ID_OPTION = {};
|
|
142
|
+
function produceIds() {
|
|
143
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
144
|
+
var iter, _a, _b;
|
|
145
|
+
return tslib_1.__generator(this, function (_c) {
|
|
146
|
+
switch (_c.label) {
|
|
147
|
+
case 0:
|
|
148
|
+
iter = 0;
|
|
149
|
+
_c.label = 1;
|
|
150
|
+
case 1:
|
|
151
|
+
if (!(iter < 128)) return [3 /*break*/, 4];
|
|
152
|
+
_b = (_a = ID_BUFFER).push;
|
|
153
|
+
return [4 /*yield*/, generateNewIdAsync()];
|
|
154
|
+
case 2:
|
|
155
|
+
_b.apply(_a, [_c.sent()]);
|
|
156
|
+
_c.label = 3;
|
|
157
|
+
case 3:
|
|
158
|
+
iter++;
|
|
159
|
+
return [3 /*break*/, 1];
|
|
160
|
+
case 4: return [2 /*return*/];
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
exports.produceIds = produceIds;
|
|
166
|
+
produceIds();
|
|
167
|
+
function setGenerateIdOption(option) {
|
|
168
|
+
ID_OPTION = option;
|
|
169
|
+
ID_BUFFER.splice(0, ID_BUFFER.length);
|
|
170
|
+
return produceIds();
|
|
171
|
+
}
|
|
172
|
+
exports.setGenerateIdOption = setGenerateIdOption;
|
|
173
|
+
function generateNewId() {
|
|
174
|
+
if (ID_BUFFER.length > 0) {
|
|
175
|
+
var id = ID_BUFFER.pop();
|
|
176
|
+
if (ID_BUFFER.length < 64) {
|
|
177
|
+
produceIds();
|
|
178
|
+
}
|
|
179
|
+
return id;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// 如果没来的及填满缓冲池,这里用一个简单的算法产生同步id(在小程序环境下跑出来过)
|
|
183
|
+
var random = new Uint8Array(16);
|
|
184
|
+
var iter = 0;
|
|
185
|
+
do {
|
|
186
|
+
random[iter] = Math.ceil(Math.random() * 1000) % 128;
|
|
187
|
+
} while (++iter < 16);
|
|
188
|
+
if ((ID_OPTION === null || ID_OPTION === void 0 ? void 0 : ID_OPTION.shuffle) || process.env.NODE_ENV === 'development') {
|
|
189
|
+
return (0, uuid_1.v4)({ random: random });
|
|
190
|
+
}
|
|
191
|
+
return sequentialUuid({ random: random });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.generateNewId = generateNewId;
|
package/lib/utils/validator.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const isMobile: ValidatorFunction;
|
|
4
|
-
export declare const isPassword: ValidatorFunction;
|
|
5
|
-
export declare const isCaptcha: ValidatorFunction;
|
|
6
|
-
export declare const isIdCardNumber: ValidatorFunction;
|
|
7
|
-
export declare const isPassportNumber: ValidatorFunction;
|
|
8
|
-
export declare const isHkCardNumber: ValidatorFunction;
|
|
9
|
-
export declare const isAmCardNumber: ValidatorFunction;
|
|
10
|
-
export declare const isTwCardNumber: ValidatorFunction;
|
|
11
|
-
export declare const isBirthNumber: ValidatorFunction;
|
|
12
|
-
export declare const isSoldierNumber: ValidatorFunction;
|
|
13
|
-
export declare const isUrl: ValidatorFunction;
|
|
14
|
-
export declare const isNickname: ValidatorFunction;
|
|
15
|
-
export declare const isSizedCaptcha: ValidatorFunction;
|
|
16
|
-
export declare const isDigital: ValidatorFunction;
|
|
17
|
-
export declare const isPhone: ValidatorFunction;
|
|
18
|
-
export declare const isNumber: ValidatorFunction;
|
|
19
|
-
export declare const isMoney: ValidatorMoneyFunction;
|
|
20
|
-
export declare const isVehicleNumber: ValidatorFunction;
|
|
21
|
-
export declare function checkAttributesNotNull<T extends Record<string, any>>(entity: string, data: T, attributes: Array<keyof T>, allowEmpty?: true): void;
|
|
22
|
-
export declare function checkAttributesScope<T extends Record<string, any>>(entity: string, data: T, attributes: Array<keyof T>): void;
|
|
23
|
-
export {};
|
|
1
|
+
type ValidatorFunction = (text: string, size?: number) => string | boolean;
|
|
2
|
+
type ValidatorMoneyFunction = (text: string, zero?: boolean) => string | boolean;
|
|
3
|
+
export declare const isMobile: ValidatorFunction;
|
|
4
|
+
export declare const isPassword: ValidatorFunction;
|
|
5
|
+
export declare const isCaptcha: ValidatorFunction;
|
|
6
|
+
export declare const isIdCardNumber: ValidatorFunction;
|
|
7
|
+
export declare const isPassportNumber: ValidatorFunction;
|
|
8
|
+
export declare const isHkCardNumber: ValidatorFunction;
|
|
9
|
+
export declare const isAmCardNumber: ValidatorFunction;
|
|
10
|
+
export declare const isTwCardNumber: ValidatorFunction;
|
|
11
|
+
export declare const isBirthNumber: ValidatorFunction;
|
|
12
|
+
export declare const isSoldierNumber: ValidatorFunction;
|
|
13
|
+
export declare const isUrl: ValidatorFunction;
|
|
14
|
+
export declare const isNickname: ValidatorFunction;
|
|
15
|
+
export declare const isSizedCaptcha: ValidatorFunction;
|
|
16
|
+
export declare const isDigital: ValidatorFunction;
|
|
17
|
+
export declare const isPhone: ValidatorFunction;
|
|
18
|
+
export declare const isNumber: ValidatorFunction;
|
|
19
|
+
export declare const isMoney: ValidatorMoneyFunction;
|
|
20
|
+
export declare const isVehicleNumber: ValidatorFunction;
|
|
21
|
+
export declare function checkAttributesNotNull<T extends Record<string, any>>(entity: string, data: T, attributes: Array<keyof T>, allowEmpty?: true): void;
|
|
22
|
+
export declare function checkAttributesScope<T extends Record<string, any>>(entity: string, data: T, attributes: Array<keyof T>): void;
|
|
23
|
+
export {};
|