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