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