@nocobase/plugin-notification-in-app-message 2.1.0-beta.2 → 2.1.0-beta.21
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/LICENSE +201 -0
- package/README.md +99 -1
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +9 -11
- package/dist/node_modules/uuid/dist/bin/uuid +2 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/index.js +104 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/max.js +7 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/md5.js +200 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/native.js +10 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/nil.js +7 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/parse.js +44 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/regex.js +7 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/rng.js +23 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/sha1.js +82 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/stringify.js +38 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v1.js +131 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v1ToV6.js +26 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v3.js +11 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v35.js +63 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v4.js +32 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v5.js +11 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v6.js +42 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v6ToV1.js +26 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v7.js +152 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/validate.js +12 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/version.js +15 -0
- package/dist/node_modules/uuid/dist/esm-browser/index.js +14 -0
- package/dist/node_modules/uuid/dist/esm-browser/max.js +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/md5.js +194 -0
- package/dist/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/dist/node_modules/uuid/dist/esm-browser/nil.js +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/parse.js +37 -0
- package/dist/node_modules/uuid/dist/esm-browser/regex.js +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/rng.js +17 -0
- package/dist/node_modules/uuid/dist/esm-browser/sha1.js +76 -0
- package/dist/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/dist/node_modules/uuid/dist/esm-browser/v1.js +125 -0
- package/dist/node_modules/uuid/dist/esm-browser/v1ToV6.js +20 -0
- package/dist/node_modules/uuid/dist/esm-browser/v3.js +4 -0
- package/dist/node_modules/uuid/dist/esm-browser/v35.js +55 -0
- package/dist/node_modules/uuid/dist/esm-browser/v4.js +25 -0
- package/dist/node_modules/uuid/dist/esm-browser/v5.js +4 -0
- package/dist/node_modules/uuid/dist/esm-browser/v6.js +36 -0
- package/dist/node_modules/uuid/dist/esm-browser/v6ToV1.js +20 -0
- package/dist/node_modules/uuid/dist/esm-browser/v7.js +146 -0
- package/dist/node_modules/uuid/dist/esm-browser/validate.js +5 -0
- package/dist/node_modules/uuid/dist/esm-browser/version.js +8 -0
- package/dist/node_modules/uuid/dist/esm-node/index.js +14 -0
- package/dist/node_modules/uuid/dist/esm-node/max.js +1 -0
- package/dist/node_modules/uuid/dist/esm-node/md5.js +10 -0
- package/dist/node_modules/uuid/dist/esm-node/native.js +4 -0
- package/dist/node_modules/uuid/dist/esm-node/nil.js +1 -0
- package/dist/node_modules/uuid/dist/esm-node/parse.js +37 -0
- package/dist/node_modules/uuid/dist/esm-node/regex.js +1 -0
- package/dist/node_modules/uuid/dist/esm-node/rng.js +10 -0
- package/dist/node_modules/uuid/dist/esm-node/sha1.js +10 -0
- package/dist/node_modules/uuid/dist/esm-node/stringify.js +31 -0
- package/dist/node_modules/uuid/dist/esm-node/v1.js +125 -0
- package/dist/node_modules/uuid/dist/esm-node/v1ToV6.js +20 -0
- package/dist/node_modules/uuid/dist/esm-node/v3.js +4 -0
- package/dist/node_modules/uuid/dist/esm-node/v35.js +55 -0
- package/dist/node_modules/uuid/dist/esm-node/v4.js +25 -0
- package/dist/node_modules/uuid/dist/esm-node/v5.js +4 -0
- package/dist/node_modules/uuid/dist/esm-node/v6.js +32 -0
- package/dist/node_modules/uuid/dist/esm-node/v6ToV1.js +20 -0
- package/dist/node_modules/uuid/dist/esm-node/v7.js +146 -0
- package/dist/node_modules/uuid/dist/esm-node/validate.js +5 -0
- package/dist/node_modules/uuid/dist/esm-node/version.js +8 -0
- package/dist/node_modules/uuid/dist/index.js +1 -0
- package/dist/node_modules/uuid/dist/max.js +7 -0
- package/dist/node_modules/uuid/dist/md5-browser.js +200 -0
- package/dist/node_modules/uuid/dist/md5.js +17 -0
- package/dist/node_modules/uuid/dist/native-browser.js +10 -0
- package/dist/node_modules/uuid/dist/native.js +11 -0
- package/dist/node_modules/uuid/dist/nil.js +7 -0
- package/dist/node_modules/uuid/dist/parse.js +44 -0
- package/dist/node_modules/uuid/dist/regex.js +7 -0
- package/dist/node_modules/uuid/dist/rng-browser.js +23 -0
- package/dist/node_modules/uuid/dist/rng.js +17 -0
- package/dist/node_modules/uuid/dist/sha1-browser.js +82 -0
- package/dist/node_modules/uuid/dist/sha1.js +17 -0
- package/dist/node_modules/uuid/dist/stringify.js +38 -0
- package/dist/node_modules/uuid/dist/uuid-bin.js +75 -0
- package/dist/node_modules/uuid/dist/v1.js +131 -0
- package/dist/node_modules/uuid/dist/v1ToV6.js +26 -0
- package/dist/node_modules/uuid/dist/v3.js +11 -0
- package/dist/node_modules/uuid/dist/v35.js +63 -0
- package/dist/node_modules/uuid/dist/v4.js +32 -0
- package/dist/node_modules/uuid/dist/v5.js +11 -0
- package/dist/node_modules/uuid/dist/v6.js +38 -0
- package/dist/node_modules/uuid/dist/v6ToV1.js +26 -0
- package/dist/node_modules/uuid/dist/v7.js +152 -0
- package/dist/node_modules/uuid/dist/validate.js +12 -0
- package/dist/node_modules/uuid/dist/version.js +15 -0
- package/dist/node_modules/uuid/package.json +1 -0
- package/dist/server/InAppNotificationChannel.d.ts +5 -0
- package/dist/server/InAppNotificationChannel.js +93 -35
- package/dist/server/defineMyInAppMessages.js +2 -1
- package/dist/server/parseUserSelectionConf.d.ts +2 -1
- package/dist/server/parseUserSelectionConf.js +3 -2
- package/package.json +5 -2
- package/LICENSE.txt +0 -172
- package/dist/client/components/UsersAddition.d.ts +0 -10
- package/dist/client/components/UsersSelect.d.ts +0 -18
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Browser-compatible JavaScript MD5
|
|
3
|
+
*
|
|
4
|
+
* Modification of JavaScript MD5
|
|
5
|
+
* https://github.com/blueimp/JavaScript-MD5
|
|
6
|
+
*
|
|
7
|
+
* Copyright 2011, Sebastian Tschan
|
|
8
|
+
* https://blueimp.net
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT license:
|
|
11
|
+
* https://opensource.org/licenses/MIT
|
|
12
|
+
*
|
|
13
|
+
* Based on
|
|
14
|
+
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
|
15
|
+
* Digest Algorithm, as defined in RFC 1321.
|
|
16
|
+
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
|
|
17
|
+
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
|
18
|
+
* Distributed under the BSD License
|
|
19
|
+
* See http://pajhome.org.uk/crypt/md5 for more info.
|
|
20
|
+
*/
|
|
21
|
+
function md5(bytes) {
|
|
22
|
+
if (typeof bytes === 'string') {
|
|
23
|
+
var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
|
|
24
|
+
|
|
25
|
+
bytes = new Uint8Array(msg.length);
|
|
26
|
+
for (var i = 0; i < msg.length; ++i) {
|
|
27
|
+
bytes[i] = msg.charCodeAt(i);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* Convert an array of little-endian words to an array of bytes
|
|
35
|
+
*/
|
|
36
|
+
function md5ToHexEncodedArray(input) {
|
|
37
|
+
var output = [];
|
|
38
|
+
var length32 = input.length * 32;
|
|
39
|
+
var hexTab = '0123456789abcdef';
|
|
40
|
+
for (var i = 0; i < length32; i += 8) {
|
|
41
|
+
var x = input[i >> 5] >>> i % 32 & 0xff;
|
|
42
|
+
var hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
|
|
43
|
+
output.push(hex);
|
|
44
|
+
}
|
|
45
|
+
return output;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Calculate output length with padding and bit length
|
|
50
|
+
*/
|
|
51
|
+
function getOutputLength(inputLength8) {
|
|
52
|
+
return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* Calculate the MD5 of an array of little-endian words, and a bit length.
|
|
57
|
+
*/
|
|
58
|
+
function wordsToMd5(x, len) {
|
|
59
|
+
/* append padding */
|
|
60
|
+
x[len >> 5] |= 0x80 << len % 32;
|
|
61
|
+
x[getOutputLength(len) - 1] = len;
|
|
62
|
+
var a = 1732584193;
|
|
63
|
+
var b = -271733879;
|
|
64
|
+
var c = -1732584194;
|
|
65
|
+
var d = 271733878;
|
|
66
|
+
for (var i = 0; i < x.length; i += 16) {
|
|
67
|
+
var olda = a;
|
|
68
|
+
var oldb = b;
|
|
69
|
+
var oldc = c;
|
|
70
|
+
var oldd = d;
|
|
71
|
+
a = md5ff(a, b, c, d, x[i], 7, -680876936);
|
|
72
|
+
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
73
|
+
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
74
|
+
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
|
75
|
+
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
|
|
76
|
+
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
|
77
|
+
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
|
78
|
+
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
|
|
79
|
+
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
|
80
|
+
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
|
81
|
+
c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
|
|
82
|
+
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
|
83
|
+
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
|
84
|
+
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
|
|
85
|
+
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
|
86
|
+
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
|
87
|
+
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
|
|
88
|
+
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
|
89
|
+
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
|
|
90
|
+
b = md5gg(b, c, d, a, x[i], 20, -373897302);
|
|
91
|
+
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
|
|
92
|
+
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
|
|
93
|
+
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
|
|
94
|
+
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
|
|
95
|
+
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
|
|
96
|
+
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
|
97
|
+
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
|
|
98
|
+
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
|
99
|
+
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
|
100
|
+
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
|
|
101
|
+
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
|
102
|
+
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
|
103
|
+
a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
|
|
104
|
+
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
|
105
|
+
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
|
106
|
+
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
|
|
107
|
+
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
|
108
|
+
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
|
109
|
+
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
|
|
110
|
+
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
|
111
|
+
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
|
|
112
|
+
d = md5hh(d, a, b, c, x[i], 11, -358537222);
|
|
113
|
+
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
|
|
114
|
+
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
|
|
115
|
+
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
|
|
116
|
+
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
|
|
117
|
+
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
|
|
118
|
+
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
|
|
119
|
+
a = md5ii(a, b, c, d, x[i], 6, -198630844);
|
|
120
|
+
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
|
121
|
+
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
|
122
|
+
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
|
|
123
|
+
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
|
124
|
+
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
|
125
|
+
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
|
|
126
|
+
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
|
127
|
+
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
|
128
|
+
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
|
|
129
|
+
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
|
130
|
+
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
|
131
|
+
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
|
|
132
|
+
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
|
133
|
+
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
|
|
134
|
+
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
|
|
135
|
+
a = safeAdd(a, olda);
|
|
136
|
+
b = safeAdd(b, oldb);
|
|
137
|
+
c = safeAdd(c, oldc);
|
|
138
|
+
d = safeAdd(d, oldd);
|
|
139
|
+
}
|
|
140
|
+
return [a, b, c, d];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
* Convert an array bytes to an array of little-endian words
|
|
145
|
+
* Characters >255 have their high-byte silently ignored.
|
|
146
|
+
*/
|
|
147
|
+
function bytesToWords(input) {
|
|
148
|
+
if (input.length === 0) {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
var length8 = input.length * 8;
|
|
152
|
+
var output = new Uint32Array(getOutputLength(length8));
|
|
153
|
+
for (var i = 0; i < length8; i += 8) {
|
|
154
|
+
output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
|
|
155
|
+
}
|
|
156
|
+
return output;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
|
161
|
+
* to work around bugs in some JS interpreters.
|
|
162
|
+
*/
|
|
163
|
+
function safeAdd(x, y) {
|
|
164
|
+
var lsw = (x & 0xffff) + (y & 0xffff);
|
|
165
|
+
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
166
|
+
return msw << 16 | lsw & 0xffff;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/*
|
|
170
|
+
* Bitwise rotate a 32-bit number to the left.
|
|
171
|
+
*/
|
|
172
|
+
function bitRotateLeft(num, cnt) {
|
|
173
|
+
return num << cnt | num >>> 32 - cnt;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/*
|
|
177
|
+
* These functions implement the four basic operations the algorithm uses.
|
|
178
|
+
*/
|
|
179
|
+
function md5cmn(q, a, b, x, s, t) {
|
|
180
|
+
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
|
|
181
|
+
}
|
|
182
|
+
function md5ff(a, b, c, d, x, s, t) {
|
|
183
|
+
return md5cmn(b & c | ~b & d, a, b, x, s, t);
|
|
184
|
+
}
|
|
185
|
+
function md5gg(a, b, c, d, x, s, t) {
|
|
186
|
+
return md5cmn(b & d | c & ~d, a, b, x, s, t);
|
|
187
|
+
}
|
|
188
|
+
function md5hh(a, b, c, d, x, s, t) {
|
|
189
|
+
return md5cmn(b ^ c ^ d, a, b, x, s, t);
|
|
190
|
+
}
|
|
191
|
+
function md5ii(a, b, c, d, x, s, t) {
|
|
192
|
+
return md5cmn(c ^ (b | ~d), a, b, x, s, t);
|
|
193
|
+
}
|
|
194
|
+
export default md5;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default '00000000-0000-0000-0000-000000000000';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import validate from './validate.js';
|
|
2
|
+
function parse(uuid) {
|
|
3
|
+
if (!validate(uuid)) {
|
|
4
|
+
throw TypeError('Invalid UUID');
|
|
5
|
+
}
|
|
6
|
+
var v;
|
|
7
|
+
var arr = new Uint8Array(16);
|
|
8
|
+
|
|
9
|
+
// Parse ########-....-....-....-............
|
|
10
|
+
arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
|
|
11
|
+
arr[1] = v >>> 16 & 0xff;
|
|
12
|
+
arr[2] = v >>> 8 & 0xff;
|
|
13
|
+
arr[3] = v & 0xff;
|
|
14
|
+
|
|
15
|
+
// Parse ........-####-....-....-............
|
|
16
|
+
arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
|
|
17
|
+
arr[5] = v & 0xff;
|
|
18
|
+
|
|
19
|
+
// Parse ........-....-####-....-............
|
|
20
|
+
arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
|
|
21
|
+
arr[7] = v & 0xff;
|
|
22
|
+
|
|
23
|
+
// Parse ........-....-....-####-............
|
|
24
|
+
arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
|
|
25
|
+
arr[9] = v & 0xff;
|
|
26
|
+
|
|
27
|
+
// Parse ........-....-....-....-############
|
|
28
|
+
// (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
|
|
29
|
+
arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
|
|
30
|
+
arr[11] = v / 0x100000000 & 0xff;
|
|
31
|
+
arr[12] = v >>> 24 & 0xff;
|
|
32
|
+
arr[13] = v >>> 16 & 0xff;
|
|
33
|
+
arr[14] = v >>> 8 & 0xff;
|
|
34
|
+
arr[15] = v & 0xff;
|
|
35
|
+
return arr;
|
|
36
|
+
}
|
|
37
|
+
export default parse;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
2
|
+
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
3
|
+
// generators (like Math.random()).
|
|
4
|
+
|
|
5
|
+
var getRandomValues;
|
|
6
|
+
var rnds8 = new Uint8Array(16);
|
|
7
|
+
export default function rng() {
|
|
8
|
+
// lazy load so that environments that need to polyfill have a chance to do so
|
|
9
|
+
if (!getRandomValues) {
|
|
10
|
+
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
|
|
11
|
+
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
|
12
|
+
if (!getRandomValues) {
|
|
13
|
+
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return getRandomValues(rnds8);
|
|
17
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Adapted from Chris Veness' SHA1 code at
|
|
2
|
+
// http://www.movable-type.co.uk/scripts/sha1.html
|
|
3
|
+
function f(s, x, y, z) {
|
|
4
|
+
switch (s) {
|
|
5
|
+
case 0:
|
|
6
|
+
return x & y ^ ~x & z;
|
|
7
|
+
case 1:
|
|
8
|
+
return x ^ y ^ z;
|
|
9
|
+
case 2:
|
|
10
|
+
return x & y ^ x & z ^ y & z;
|
|
11
|
+
case 3:
|
|
12
|
+
return x ^ y ^ z;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function ROTL(x, n) {
|
|
16
|
+
return x << n | x >>> 32 - n;
|
|
17
|
+
}
|
|
18
|
+
function sha1(bytes) {
|
|
19
|
+
var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
|
|
20
|
+
var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
|
|
21
|
+
if (typeof bytes === 'string') {
|
|
22
|
+
var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
|
|
23
|
+
|
|
24
|
+
bytes = [];
|
|
25
|
+
for (var i = 0; i < msg.length; ++i) {
|
|
26
|
+
bytes.push(msg.charCodeAt(i));
|
|
27
|
+
}
|
|
28
|
+
} else if (!Array.isArray(bytes)) {
|
|
29
|
+
// Convert Array-like to Array
|
|
30
|
+
bytes = Array.prototype.slice.call(bytes);
|
|
31
|
+
}
|
|
32
|
+
bytes.push(0x80);
|
|
33
|
+
var l = bytes.length / 4 + 2;
|
|
34
|
+
var N = Math.ceil(l / 16);
|
|
35
|
+
var M = new Array(N);
|
|
36
|
+
for (var _i = 0; _i < N; ++_i) {
|
|
37
|
+
var arr = new Uint32Array(16);
|
|
38
|
+
for (var j = 0; j < 16; ++j) {
|
|
39
|
+
arr[j] = bytes[_i * 64 + j * 4] << 24 | bytes[_i * 64 + j * 4 + 1] << 16 | bytes[_i * 64 + j * 4 + 2] << 8 | bytes[_i * 64 + j * 4 + 3];
|
|
40
|
+
}
|
|
41
|
+
M[_i] = arr;
|
|
42
|
+
}
|
|
43
|
+
M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
|
|
44
|
+
M[N - 1][14] = Math.floor(M[N - 1][14]);
|
|
45
|
+
M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
|
|
46
|
+
for (var _i2 = 0; _i2 < N; ++_i2) {
|
|
47
|
+
var W = new Uint32Array(80);
|
|
48
|
+
for (var t = 0; t < 16; ++t) {
|
|
49
|
+
W[t] = M[_i2][t];
|
|
50
|
+
}
|
|
51
|
+
for (var _t = 16; _t < 80; ++_t) {
|
|
52
|
+
W[_t] = ROTL(W[_t - 3] ^ W[_t - 8] ^ W[_t - 14] ^ W[_t - 16], 1);
|
|
53
|
+
}
|
|
54
|
+
var a = H[0];
|
|
55
|
+
var b = H[1];
|
|
56
|
+
var c = H[2];
|
|
57
|
+
var d = H[3];
|
|
58
|
+
var e = H[4];
|
|
59
|
+
for (var _t2 = 0; _t2 < 80; ++_t2) {
|
|
60
|
+
var s = Math.floor(_t2 / 20);
|
|
61
|
+
var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[_t2] >>> 0;
|
|
62
|
+
e = d;
|
|
63
|
+
d = c;
|
|
64
|
+
c = ROTL(b, 30) >>> 0;
|
|
65
|
+
b = a;
|
|
66
|
+
a = T;
|
|
67
|
+
}
|
|
68
|
+
H[0] = H[0] + a >>> 0;
|
|
69
|
+
H[1] = H[1] + b >>> 0;
|
|
70
|
+
H[2] = H[2] + c >>> 0;
|
|
71
|
+
H[3] = H[3] + d >>> 0;
|
|
72
|
+
H[4] = H[4] + e >>> 0;
|
|
73
|
+
}
|
|
74
|
+
return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
|
|
75
|
+
}
|
|
76
|
+
export default sha1;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import validate from './validate.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
5
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
6
|
+
*/
|
|
7
|
+
var byteToHex = [];
|
|
8
|
+
for (var i = 0; i < 256; ++i) {
|
|
9
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
10
|
+
}
|
|
11
|
+
export function unsafeStringify(arr, offset = 0) {
|
|
12
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
13
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
14
|
+
//
|
|
15
|
+
// Note to future-self: No, you can't remove the `toLowerCase()` call.
|
|
16
|
+
// REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351
|
|
17
|
+
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();
|
|
18
|
+
}
|
|
19
|
+
function stringify(arr, offset = 0) {
|
|
20
|
+
var uuid = unsafeStringify(arr, offset);
|
|
21
|
+
// Consistency check for valid UUID. If this throws, it's likely due to one
|
|
22
|
+
// of the following:
|
|
23
|
+
// - One or more input array values don't map to a hex octet (leading to
|
|
24
|
+
// "undefined" in the uuid)
|
|
25
|
+
// - Invalid input values for the RFC `version` or `variant` fields
|
|
26
|
+
if (!validate(uuid)) {
|
|
27
|
+
throw TypeError('Stringified UUID is invalid');
|
|
28
|
+
}
|
|
29
|
+
return uuid;
|
|
30
|
+
}
|
|
31
|
+
export default stringify;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import rng from './rng.js';
|
|
2
|
+
import { unsafeStringify } from './stringify.js';
|
|
3
|
+
|
|
4
|
+
// **`v1()` - Generate time-based UUID**
|
|
5
|
+
//
|
|
6
|
+
// Inspired by https://github.com/LiosK/UUID.js
|
|
7
|
+
// and http://docs.python.org/library/uuid.html
|
|
8
|
+
|
|
9
|
+
var _nodeId;
|
|
10
|
+
var _clockseq;
|
|
11
|
+
|
|
12
|
+
// Previous uuid creation time
|
|
13
|
+
var _lastMSecs = 0;
|
|
14
|
+
var _lastNSecs = 0;
|
|
15
|
+
|
|
16
|
+
// See https://github.com/uuidjs/uuid for API details
|
|
17
|
+
function v1(options, buf, offset) {
|
|
18
|
+
var i = buf && offset || 0;
|
|
19
|
+
var b = buf || new Array(16);
|
|
20
|
+
options = options || {};
|
|
21
|
+
var node = options.node;
|
|
22
|
+
var clockseq = options.clockseq;
|
|
23
|
+
|
|
24
|
+
// v1 only: Use cached `node` and `clockseq` values
|
|
25
|
+
if (!options._v6) {
|
|
26
|
+
if (!node) {
|
|
27
|
+
node = _nodeId;
|
|
28
|
+
}
|
|
29
|
+
if (clockseq == null) {
|
|
30
|
+
clockseq = _clockseq;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Handle cases where we need entropy. We do this lazily to minimize issues
|
|
35
|
+
// related to insufficient system entropy. See #189
|
|
36
|
+
if (node == null || clockseq == null) {
|
|
37
|
+
var seedBytes = options.random || (options.rng || rng)();
|
|
38
|
+
|
|
39
|
+
// Randomize node
|
|
40
|
+
if (node == null) {
|
|
41
|
+
node = [seedBytes[0], seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
|
|
42
|
+
|
|
43
|
+
// v1 only: cache node value for reuse
|
|
44
|
+
if (!_nodeId && !options._v6) {
|
|
45
|
+
// per RFC4122 4.5: Set MAC multicast bit (v1 only)
|
|
46
|
+
node[0] |= 0x01; // Set multicast bit
|
|
47
|
+
|
|
48
|
+
_nodeId = node;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Randomize clockseq
|
|
53
|
+
if (clockseq == null) {
|
|
54
|
+
// Per 4.2.2, randomize (14 bit) clockseq
|
|
55
|
+
clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
|
|
56
|
+
if (_clockseq === undefined && !options._v6) {
|
|
57
|
+
_clockseq = clockseq;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// v1 & v6 timestamps are 100 nano-second units since the Gregorian epoch,
|
|
63
|
+
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so time is
|
|
64
|
+
// handled internally as 'msecs' (integer milliseconds) and 'nsecs'
|
|
65
|
+
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
|
|
66
|
+
var msecs = options.msecs !== undefined ? options.msecs : Date.now();
|
|
67
|
+
|
|
68
|
+
// Per 4.2.1.2, use count of uuid's generated during the current clock
|
|
69
|
+
// cycle to simulate higher resolution clock
|
|
70
|
+
var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
|
|
71
|
+
|
|
72
|
+
// Time since last uuid creation (in msecs)
|
|
73
|
+
var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000;
|
|
74
|
+
|
|
75
|
+
// Per 4.2.1.2, Bump clockseq on clock regression
|
|
76
|
+
if (dt < 0 && options.clockseq === undefined) {
|
|
77
|
+
clockseq = clockseq + 1 & 0x3fff;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
|
|
81
|
+
// time interval
|
|
82
|
+
if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
|
|
83
|
+
nsecs = 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Per 4.2.1.2 Throw error if too many uuids are requested
|
|
87
|
+
if (nsecs >= 10000) {
|
|
88
|
+
throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
|
|
89
|
+
}
|
|
90
|
+
_lastMSecs = msecs;
|
|
91
|
+
_lastNSecs = nsecs;
|
|
92
|
+
_clockseq = clockseq;
|
|
93
|
+
|
|
94
|
+
// Per 4.1.4 - Convert from unix epoch to Gregorian epoch
|
|
95
|
+
msecs += 12219292800000;
|
|
96
|
+
|
|
97
|
+
// `time_low`
|
|
98
|
+
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
|
99
|
+
b[i++] = tl >>> 24 & 0xff;
|
|
100
|
+
b[i++] = tl >>> 16 & 0xff;
|
|
101
|
+
b[i++] = tl >>> 8 & 0xff;
|
|
102
|
+
b[i++] = tl & 0xff;
|
|
103
|
+
|
|
104
|
+
// `time_mid`
|
|
105
|
+
var tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
|
|
106
|
+
b[i++] = tmh >>> 8 & 0xff;
|
|
107
|
+
b[i++] = tmh & 0xff;
|
|
108
|
+
|
|
109
|
+
// `time_high_and_version`
|
|
110
|
+
b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
|
|
111
|
+
b[i++] = tmh >>> 16 & 0xff;
|
|
112
|
+
|
|
113
|
+
// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
|
|
114
|
+
b[i++] = clockseq >>> 8 | 0x80;
|
|
115
|
+
|
|
116
|
+
// `clock_seq_low`
|
|
117
|
+
b[i++] = clockseq & 0xff;
|
|
118
|
+
|
|
119
|
+
// `node`
|
|
120
|
+
for (var n = 0; n < 6; ++n) {
|
|
121
|
+
b[i + n] = node[n];
|
|
122
|
+
}
|
|
123
|
+
return buf || unsafeStringify(b);
|
|
124
|
+
}
|
|
125
|
+
export default v1;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import parse from './parse.js';
|
|
2
|
+
import { unsafeStringify } from './stringify.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert a v1 UUID to a v6 UUID
|
|
6
|
+
*
|
|
7
|
+
* @param {string|Uint8Array} uuid - The v1 UUID to convert to v6
|
|
8
|
+
* @returns {string|Uint8Array} The v6 UUID as the same type as the `uuid` arg
|
|
9
|
+
* (string or Uint8Array)
|
|
10
|
+
*/
|
|
11
|
+
export default function v1ToV6(uuid) {
|
|
12
|
+
var v1Bytes = typeof uuid === 'string' ? parse(uuid) : uuid;
|
|
13
|
+
var v6Bytes = _v1ToV6(v1Bytes);
|
|
14
|
+
return typeof uuid === 'string' ? unsafeStringify(v6Bytes) : v6Bytes;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Do the field transformation needed for v1 -> v6
|
|
18
|
+
function _v1ToV6(v1Bytes, randomize = false) {
|
|
19
|
+
return Uint8Array.of((v1Bytes[6] & 0x0f) << 4 | v1Bytes[7] >> 4 & 0x0f, (v1Bytes[7] & 0x0f) << 4 | (v1Bytes[4] & 0xf0) >> 4, (v1Bytes[4] & 0x0f) << 4 | (v1Bytes[5] & 0xf0) >> 4, (v1Bytes[5] & 0x0f) << 4 | (v1Bytes[0] & 0xf0) >> 4, (v1Bytes[0] & 0x0f) << 4 | (v1Bytes[1] & 0xf0) >> 4, (v1Bytes[1] & 0x0f) << 4 | (v1Bytes[2] & 0xf0) >> 4, 0x60 | v1Bytes[2] & 0x0f, v1Bytes[3], v1Bytes[8], v1Bytes[9], v1Bytes[10], v1Bytes[11], v1Bytes[12], v1Bytes[13], v1Bytes[14], v1Bytes[15]);
|
|
20
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { unsafeStringify } from './stringify.js';
|
|
2
|
+
import parse from './parse.js';
|
|
3
|
+
function stringToBytes(str) {
|
|
4
|
+
str = unescape(encodeURIComponent(str)); // UTF8 escape
|
|
5
|
+
|
|
6
|
+
var bytes = [];
|
|
7
|
+
for (var i = 0; i < str.length; ++i) {
|
|
8
|
+
bytes.push(str.charCodeAt(i));
|
|
9
|
+
}
|
|
10
|
+
return bytes;
|
|
11
|
+
}
|
|
12
|
+
export var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
13
|
+
export var URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
|
|
14
|
+
export default function v35(name, version, hashfunc) {
|
|
15
|
+
function generateUUID(value, namespace, buf, offset) {
|
|
16
|
+
var _namespace;
|
|
17
|
+
if (typeof value === 'string') {
|
|
18
|
+
value = stringToBytes(value);
|
|
19
|
+
}
|
|
20
|
+
if (typeof namespace === 'string') {
|
|
21
|
+
namespace = parse(namespace);
|
|
22
|
+
}
|
|
23
|
+
if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
|
|
24
|
+
throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Compute hash of namespace and value, Per 4.3
|
|
28
|
+
// Future: Use spread syntax when supported on all platforms, e.g. `bytes =
|
|
29
|
+
// hashfunc([...namespace, ... value])`
|
|
30
|
+
var bytes = new Uint8Array(16 + value.length);
|
|
31
|
+
bytes.set(namespace);
|
|
32
|
+
bytes.set(value, namespace.length);
|
|
33
|
+
bytes = hashfunc(bytes);
|
|
34
|
+
bytes[6] = bytes[6] & 0x0f | version;
|
|
35
|
+
bytes[8] = bytes[8] & 0x3f | 0x80;
|
|
36
|
+
if (buf) {
|
|
37
|
+
offset = offset || 0;
|
|
38
|
+
for (var i = 0; i < 16; ++i) {
|
|
39
|
+
buf[offset + i] = bytes[i];
|
|
40
|
+
}
|
|
41
|
+
return buf;
|
|
42
|
+
}
|
|
43
|
+
return unsafeStringify(bytes);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Function#name is not settable on some platforms (#270)
|
|
47
|
+
try {
|
|
48
|
+
generateUUID.name = name;
|
|
49
|
+
} catch (err) {}
|
|
50
|
+
|
|
51
|
+
// For CommonJS default export support
|
|
52
|
+
generateUUID.DNS = DNS;
|
|
53
|
+
generateUUID.URL = URL;
|
|
54
|
+
return generateUUID;
|
|
55
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import native from './native.js';
|
|
2
|
+
import rng from './rng.js';
|
|
3
|
+
import { unsafeStringify } from './stringify.js';
|
|
4
|
+
function v4(options, buf, offset) {
|
|
5
|
+
if (native.randomUUID && !buf && !options) {
|
|
6
|
+
return native.randomUUID();
|
|
7
|
+
}
|
|
8
|
+
options = options || {};
|
|
9
|
+
var rnds = options.random || (options.rng || rng)();
|
|
10
|
+
|
|
11
|
+
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
12
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
13
|
+
rnds[8] = rnds[8] & 0x3f | 0x80;
|
|
14
|
+
|
|
15
|
+
// Copy bytes to buffer, if provided
|
|
16
|
+
if (buf) {
|
|
17
|
+
offset = offset || 0;
|
|
18
|
+
for (var i = 0; i < 16; ++i) {
|
|
19
|
+
buf[offset + i] = rnds[i];
|
|
20
|
+
}
|
|
21
|
+
return buf;
|
|
22
|
+
}
|
|
23
|
+
return unsafeStringify(rnds);
|
|
24
|
+
}
|
|
25
|
+
export default v4;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
import { unsafeStringify } from './stringify.js';
|
|
7
|
+
import v1 from './v1.js';
|
|
8
|
+
import v1ToV6 from './v1ToV6.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {object} options
|
|
13
|
+
* @param {Uint8Array=} buf
|
|
14
|
+
* @param {number=} offset
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export default function v6(options = {}, buf, offset = 0) {
|
|
18
|
+
// v6 is v1 with different field layout, so we start with a v1 UUID, albeit
|
|
19
|
+
// with slightly different behavior around how the clock_seq and node fields
|
|
20
|
+
// are randomized, which is why we call v1 with _v6: true.
|
|
21
|
+
var bytes = v1(_objectSpread(_objectSpread({}, options), {}, {
|
|
22
|
+
_v6: true
|
|
23
|
+
}), new Uint8Array(16));
|
|
24
|
+
|
|
25
|
+
// Reorder the fields to v6 layout.
|
|
26
|
+
bytes = v1ToV6(bytes);
|
|
27
|
+
|
|
28
|
+
// Return as a byte array if requested
|
|
29
|
+
if (buf) {
|
|
30
|
+
for (var i = 0; i < 16; i++) {
|
|
31
|
+
buf[offset + i] = bytes[i];
|
|
32
|
+
}
|
|
33
|
+
return buf;
|
|
34
|
+
}
|
|
35
|
+
return unsafeStringify(bytes);
|
|
36
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import parse from './parse.js';
|
|
2
|
+
import { unsafeStringify } from './stringify.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert a v6 UUID to a v1 UUID
|
|
6
|
+
*
|
|
7
|
+
* @param {string|Uint8Array} uuid - The v6 UUID to convert to v6
|
|
8
|
+
* @returns {string|Uint8Array} The v1 UUID as the same type as the `uuid` arg
|
|
9
|
+
* (string or Uint8Array)
|
|
10
|
+
*/
|
|
11
|
+
export default function v6ToV1(uuid) {
|
|
12
|
+
var v6Bytes = typeof uuid === 'string' ? parse(uuid) : uuid;
|
|
13
|
+
var v1Bytes = _v6ToV1(v6Bytes);
|
|
14
|
+
return typeof uuid === 'string' ? unsafeStringify(v1Bytes) : v1Bytes;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Do the field transformation needed for v6 -> v1
|
|
18
|
+
function _v6ToV1(v6Bytes) {
|
|
19
|
+
return Uint8Array.of((v6Bytes[3] & 0x0f) << 4 | v6Bytes[4] >> 4 & 0x0f, (v6Bytes[4] & 0x0f) << 4 | (v6Bytes[5] & 0xf0) >> 4, (v6Bytes[5] & 0x0f) << 4 | v6Bytes[6] & 0x0f, v6Bytes[7], (v6Bytes[1] & 0x0f) << 4 | (v6Bytes[2] & 0xf0) >> 4, (v6Bytes[2] & 0x0f) << 4 | (v6Bytes[3] & 0xf0) >> 4, 0x10 | (v6Bytes[0] & 0xf0) >> 4, (v6Bytes[0] & 0x0f) << 4 | (v6Bytes[1] & 0xf0) >> 4, v6Bytes[8], v6Bytes[9], v6Bytes[10], v6Bytes[11], v6Bytes[12], v6Bytes[13], v6Bytes[14], v6Bytes[15]);
|
|
20
|
+
}
|