@vertexvis/utils 0.15.0 → 0.15.1-canary.10

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.
@@ -3154,103 +3154,58 @@ function stringify(arr) {
3154
3154
  return uuid;
3155
3155
  }
3156
3156
 
3157
- //
3158
- // Inspired by https://github.com/LiosK/UUID.js
3159
- // and http://docs.python.org/library/uuid.html
3160
-
3161
- var _nodeId;
3162
-
3163
- var _clockseq; // Previous uuid creation time
3164
-
3165
-
3166
- var _lastMSecs = 0;
3167
- var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
3168
-
3169
- function v1(options, buf, offset) {
3170
- var i = buf && offset || 0;
3171
- var b = buf || new Array(16);
3157
+ function v4(options, buf, offset) {
3172
3158
  options = options || {};
3173
- var node = options.node || _nodeId;
3174
- var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
3175
- // specified. We do this lazily to minimize issues related to insufficient
3176
- // system entropy. See #189
3159
+ var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
3177
3160
 
3178
- if (node == null || clockseq == null) {
3179
- var seedBytes = options.random || (options.rng || rng)();
3161
+ rnds[6] = rnds[6] & 0x0f | 0x40;
3162
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
3180
3163
 
3181
- if (node == null) {
3182
- // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
3183
- node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
3184
- }
3164
+ if (buf) {
3165
+ offset = offset || 0;
3185
3166
 
3186
- if (clockseq == null) {
3187
- // Per 4.2.2, randomize (14 bit) clockseq
3188
- clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
3167
+ for (var i = 0; i < 16; ++i) {
3168
+ buf[offset + i] = rnds[i];
3189
3169
  }
3190
- } // UUID timestamps are 100 nano-second units since the Gregorian epoch,
3191
- // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
3192
- // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
3193
- // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
3194
-
3195
-
3196
- var msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock
3197
- // cycle to simulate higher resolution clock
3198
3170
 
3199
- var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
3200
-
3201
- var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
3202
-
3203
- if (dt < 0 && options.clockseq === undefined) {
3204
- clockseq = clockseq + 1 & 0x3fff;
3205
- } // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
3206
- // time interval
3207
-
3208
-
3209
- if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
3210
- nsecs = 0;
3211
- } // Per 4.2.1.2 Throw error if too many uuids are requested
3212
-
3213
-
3214
- if (nsecs >= 10000) {
3215
- throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
3171
+ return buf;
3216
3172
  }
3217
3173
 
3218
- _lastMSecs = msecs;
3219
- _lastNSecs = nsecs;
3220
- _clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
3221
-
3222
- msecs += 12219292800000; // `time_low`
3223
-
3224
- var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
3225
- b[i++] = tl >>> 24 & 0xff;
3226
- b[i++] = tl >>> 16 & 0xff;
3227
- b[i++] = tl >>> 8 & 0xff;
3228
- b[i++] = tl & 0xff; // `time_mid`
3229
-
3230
- var tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
3231
- b[i++] = tmh >>> 8 & 0xff;
3232
- b[i++] = tmh & 0xff; // `time_high_and_version`
3233
-
3234
- b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
3235
-
3236
- b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
3237
-
3238
- b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low`
3239
-
3240
- b[i++] = clockseq & 0xff; // `node`
3241
-
3242
- for (var n = 0; n < 6; ++n) {
3243
- b[i + n] = node[n];
3244
- }
3245
-
3246
- return buf || stringify(b);
3174
+ return stringify(rnds);
3247
3175
  }
3248
3176
 
3249
- var create = function () { return v1(); };
3177
+ function create() {
3178
+ return v4();
3179
+ }
3180
+ function fromMsbLsb(msb, lsb) {
3181
+ function digits(val, ds) {
3182
+ var hi = BigInt(1) << (ds * BigInt(4));
3183
+ return (hi | (val & (hi - BigInt(1)))).toString(16).substring(1);
3184
+ }
3185
+ var msbB = typeof msb === 'string' ? BigInt(msb) : msb;
3186
+ var lsbB = typeof lsb === 'string' ? BigInt(lsb) : lsb;
3187
+ var sec1 = digits(msbB >> BigInt(32), BigInt(8));
3188
+ var sec2 = digits(msbB >> BigInt(16), BigInt(4));
3189
+ var sec3 = digits(msbB, BigInt(4));
3190
+ var sec4 = digits(lsbB >> BigInt(48), BigInt(4));
3191
+ var sec5 = digits(lsbB, BigInt(12));
3192
+ return "".concat(sec1, "-").concat(sec2, "-").concat(sec3, "-").concat(sec4, "-").concat(sec5);
3193
+ }
3194
+ function toMsbLsb(id) {
3195
+ var _a = __read(id.split('-'), 5), c1 = _a[0], c2 = _a[1], c3 = _a[2], c4 = _a[3], c5 = _a[4];
3196
+ if (c1 == null || c2 == null || c3 == null || c4 == null || c5 == null) {
3197
+ throw new Error("Invalid UUID string ".concat(id));
3198
+ }
3199
+ var msb = BigInt.asIntN(64, BigInt("0x".concat(c1 + c2 + c3)));
3200
+ var lsb = BigInt.asIntN(64, BigInt("0x".concat(c4 + c5)));
3201
+ return { msb: msb.toString(), lsb: lsb.toString() };
3202
+ }
3250
3203
 
3251
3204
  var uuid = /*#__PURE__*/Object.freeze({
3252
3205
  __proto__: null,
3253
- create: create
3206
+ create: create,
3207
+ fromMsbLsb: fromMsbLsb,
3208
+ toMsbLsb: toMsbLsb
3254
3209
  });
3255
3210
 
3256
3211
  var EventDispatcher = /** @class */ (function () {