@bifravst/aws-cdk-lambda-helpers 1.2.1 → 1.2.3

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.
Files changed (76) hide show
  1. package/dist/cdk/TestApp.d.ts +5 -0
  2. package/dist/cdk/TestApp.js +12 -0
  3. package/dist/cdk/TestStack.d.ts +12 -0
  4. package/dist/cdk/TestStack.js +39 -0
  5. package/dist/cdk/baseLayer.d.ts +2 -0
  6. package/dist/cdk/baseLayer.js +5 -0
  7. package/dist/cdk/e2e.js +11 -0
  8. package/dist/cdk/lambda.d.ts +2 -0
  9. package/dist/cdk/lambda.js +5 -0
  10. package/dist/cdk/packTestLambdas.d.ts +5 -0
  11. package/dist/cdk/packTestLambdas.js +4 -0
  12. package/dist/e2e.spec.js +17 -0
  13. package/dist/lambdas/test.zip +0 -0
  14. package/dist/layers/baseLayer/nodejs/node_modules/.package-lock.json +16 -0
  15. package/dist/layers/baseLayer/nodejs/node_modules/id128/CHANGES +20 -0
  16. package/dist/layers/baseLayer/nodejs/node_modules/id128/LICENSE +18 -0
  17. package/dist/layers/baseLayer/nodejs/node_modules/id128/README.md +853 -0
  18. package/dist/layers/baseLayer/nodejs/node_modules/id128/index.d.ts +167 -0
  19. package/dist/layers/baseLayer/nodejs/node_modules/id128/index.js +49 -0
  20. package/dist/layers/baseLayer/nodejs/node_modules/id128/package.json +68 -0
  21. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/coder/base.js +53 -0
  22. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/coder/crockford32.js +114 -0
  23. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/coder/hex.js +63 -0
  24. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/coder/uuid.js +77 -0
  25. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/byte-array.js +26 -0
  26. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/epoch-converter.js +32 -0
  27. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/exception.js +18 -0
  28. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/fake-machine.js +26 -0
  29. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/machine.js +37 -0
  30. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/random-bytes-browser.js +9 -0
  31. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/random-bytes.js +17 -0
  32. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/factory/id.js +96 -0
  33. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/factory/versioned-id.js +72 -0
  34. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/base.js +39 -0
  35. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/ulid-monotonic.js +71 -0
  36. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/ulid.js +64 -0
  37. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid-1.js +149 -0
  38. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid-4.js +24 -0
  39. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid-6.js +146 -0
  40. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid-nil.js +33 -0
  41. package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid.js +58 -0
  42. package/dist/layers/baseLayer/nodejs/node_modules/id128/utils.js +35 -0
  43. package/dist/layers/baseLayer/nodejs/package-lock.json +6671 -0
  44. package/dist/layers/baseLayer/nodejs/package.json +1 -0
  45. package/dist/layers/baseLayer.zip +0 -0
  46. package/dist/src/checkSumOfFiles.spec.d.ts +1 -0
  47. package/dist/src/commonParent.spec.d.ts +1 -0
  48. package/dist/{packLambda.d.ts → src/packLambda.d.ts} +2 -2
  49. package/package.json +20 -14
  50. /package/dist/{checkSumOfFiles.spec.d.ts → cdk/e2e.d.ts} +0 -0
  51. /package/dist/{commonParent.spec.d.ts → e2e.spec.d.ts} +0 -0
  52. /package/dist/{LambdaLogGroup.d.ts → src/LambdaLogGroup.d.ts} +0 -0
  53. /package/dist/{LambdaLogGroup.js → src/LambdaLogGroup.js} +0 -0
  54. /package/dist/{LambdaSource.d.ts → src/LambdaSource.d.ts} +0 -0
  55. /package/dist/{LambdaSource.js → src/LambdaSource.js} +0 -0
  56. /package/dist/{cdk.d.ts → src/cdk.d.ts} +0 -0
  57. /package/dist/{cdk.js → src/cdk.js} +0 -0
  58. /package/dist/{checkSumOfFiles.spec.js → src/checkSumOfFiles.spec.js} +0 -0
  59. /package/dist/{checksumOfFiles.d.ts → src/checksumOfFiles.d.ts} +0 -0
  60. /package/dist/{checksumOfFiles.js → src/checksumOfFiles.js} +0 -0
  61. /package/dist/{commonParent.d.ts → src/commonParent.d.ts} +0 -0
  62. /package/dist/{commonParent.js → src/commonParent.js} +0 -0
  63. /package/dist/{commonParent.spec.js → src/commonParent.spec.js} +0 -0
  64. /package/dist/{findDependencies.d.ts → src/findDependencies.d.ts} +0 -0
  65. /package/dist/{findDependencies.js → src/findDependencies.js} +0 -0
  66. /package/dist/{lambda.d.ts → src/lambda.d.ts} +0 -0
  67. /package/dist/{lambda.js → src/lambda.js} +0 -0
  68. /package/dist/{layer.d.ts → src/layer.d.ts} +0 -0
  69. /package/dist/{layer.js → src/layer.js} +0 -0
  70. /package/dist/{packLambda.js → src/packLambda.js} +0 -0
  71. /package/dist/{packLambdaFromPath.d.ts → src/packLambdaFromPath.d.ts} +0 -0
  72. /package/dist/{packLambdaFromPath.js → src/packLambdaFromPath.js} +0 -0
  73. /package/dist/{packLayer.d.ts → src/packLayer.d.ts} +0 -0
  74. /package/dist/{packLayer.js → src/packLayer.js} +0 -0
  75. /package/dist/{util.d.ts → src/util.d.ts} +0 -0
  76. /package/dist/{util.js → src/util.js} +0 -0
@@ -0,0 +1,37 @@
1
+ const Os = require('os');
2
+ const { randomBytes } = require('./random-bytes');
3
+
4
+ const _mac_address = Symbol('mac-address');
5
+
6
+ class Machine {
7
+ constructor() {
8
+ this.reset();
9
+ }
10
+
11
+ get mac_address() {
12
+ let mac_address = this[_mac_address];
13
+
14
+ if (! mac_address) {
15
+ const { mac } = Object.values(Os.networkInterfaces())
16
+ .reduce((memo, arr) => memo.concat(arr), [])
17
+ .find((iface) => ! iface.internal && iface.mac)
18
+ || {};
19
+
20
+ mac_address = this[_mac_address] = mac
21
+ ? Uint8Array.from(mac.split(':'), (hex) => Number.parseInt(hex, 16))
22
+ : randomBytes(6);
23
+
24
+ if (! mac) {
25
+ mac_address[0] |= 0b00000001;
26
+ }
27
+ }
28
+
29
+ return mac_address;
30
+ }
31
+
32
+ reset() {
33
+ this[_mac_address] = null;
34
+ }
35
+ }
36
+
37
+ module.exports = new Machine;
@@ -0,0 +1,9 @@
1
+ const Crypto = self.crypto;
2
+
3
+ function randomBytes(size) {
4
+ const bytes = new Uint8Array(size);
5
+ Crypto.getRandomValues(bytes);
6
+ return bytes;
7
+ };
8
+
9
+ module.exports = { randomBytes };
@@ -0,0 +1,17 @@
1
+ const Crypto = require('crypto');
2
+
3
+ const BUFFER_SIZE = 4096 /* typical page size */ - 96 /* Empty buffer overhead */;
4
+
5
+ const buffer = new Uint8Array(BUFFER_SIZE)
6
+ let offset = BUFFER_SIZE;
7
+
8
+ function randomBytes(size) {
9
+ if (offset + size >= BUFFER_SIZE) {
10
+ offset = 0;
11
+ Crypto.randomFillSync(buffer)
12
+ }
13
+
14
+ return buffer.slice(offset, offset += size);
15
+ }
16
+
17
+ module.exports = { randomBytes };
@@ -0,0 +1,96 @@
1
+ 'use strict';
2
+
3
+ const _id = Symbol('id');
4
+ const _canonical_coder = Symbol('canonical_coder');
5
+ const _raw_coder = Symbol('raw_coder');
6
+
7
+ class IdFactory {
8
+ constructor({
9
+ id,
10
+ canonical_coder,
11
+ raw_coder,
12
+ } = {}) {
13
+ this[_id] = class extends id {
14
+ static get name() { return id.name; }
15
+ static get [Symbol.species]() { return id; }
16
+ get [Symbol.toStringTag]() { return `${id.name} ${this.toRaw()}`; }
17
+ toCanonical() { return canonical_coder.encodeTrusted(this.bytes); }
18
+ toRaw() { return raw_coder.encodeTrusted(this.bytes); }
19
+ };
20
+ this[_canonical_coder] = canonical_coder;
21
+ this[_raw_coder] = raw_coder;
22
+ }
23
+
24
+ // Properties
25
+
26
+ get name() { return this[_id].name; }
27
+ get type() { return this[_id][Symbol.species]; }
28
+
29
+ // Generators
30
+
31
+ construct(bytes) {
32
+ return new this[_id](bytes);
33
+ }
34
+
35
+ generate() {
36
+ return this[_id].generate(...arguments);
37
+ }
38
+
39
+ MIN() {
40
+ return this[_id].MIN(...arguments);
41
+ }
42
+
43
+ MAX() {
44
+ return this[_id].MAX(...arguments);
45
+ }
46
+
47
+ // Coders
48
+
49
+ fromCanonical(canonical) {
50
+ return this.construct(this[_canonical_coder].decode(canonical));
51
+ }
52
+
53
+ fromCanonicalTrusted(canonical) {
54
+ return this.construct(this[_canonical_coder].decodeTrusted(canonical));
55
+ }
56
+
57
+ fromRaw(raw) {
58
+ return this.construct(this[_raw_coder].decode(raw));
59
+ }
60
+
61
+ fromRawTrusted(raw) {
62
+ return this.construct(this[_raw_coder].decodeTrusted(raw));
63
+ }
64
+
65
+ toCanonical(id) {
66
+ return this[_canonical_coder].encode(id.bytes);
67
+ }
68
+
69
+ toRaw(id) {
70
+ return this[_raw_coder].encode(id.bytes);
71
+ }
72
+
73
+ // Comparators
74
+
75
+ compare(lhs, rhs) {
76
+ console.warn("Deprecated: use generic idCompare instead.")
77
+ return lhs.compare(rhs);
78
+ }
79
+
80
+ equal(lhs, rhs) {
81
+ console.warn("Deprecated: use generic idEqual instead.")
82
+ return lhs.equal(rhs);
83
+ }
84
+
85
+ // Verifiers
86
+
87
+ isCanonical(canonical) {
88
+ return this[_canonical_coder].isValidEncoding(canonical);
89
+ }
90
+
91
+ isRaw(raw) {
92
+ return this[_raw_coder].isValidEncoding(raw);
93
+ }
94
+ }
95
+
96
+ module.exports = { IdFactory };
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ const { IdFactory } = require('./id');
4
+ const { UnsupportedVersion } = require('../common/exception');
5
+
6
+ const _id_by_version = Symbol('id_by_version');
7
+
8
+ function detect(factory, { version } = {}) {
9
+ return factory[_id_by_version][version]
10
+ || (() => { throw new UnsupportedVersion(
11
+ `No support for version [${version}]`
12
+ ) })();
13
+ }
14
+
15
+ class VersionedIdFactory extends IdFactory {
16
+ constructor({
17
+ abstract_id,
18
+ versioned_ids,
19
+ canonical_coder,
20
+ raw_coder,
21
+ }) {
22
+ super({
23
+ id: abstract_id,
24
+ canonical_coder,
25
+ raw_coder,
26
+ });
27
+
28
+ this[_id_by_version] = versioned_ids.reduce(
29
+ (mapping, id) => Object.assign(mapping, {
30
+ [id.MIN().version]: new IdFactory({
31
+ id,
32
+ canonical_coder,
33
+ raw_coder,
34
+ })
35
+ }),
36
+ Object.create(null),
37
+ );
38
+ }
39
+
40
+ get versioned_ids() {
41
+ return Object.values(this[_id_by_version]);
42
+ }
43
+
44
+ // Generators
45
+
46
+ construct(bytes) {
47
+ const id = super.construct(bytes);
48
+ const version = id.version;
49
+
50
+ try {
51
+ return detect(this, { version }).construct(bytes);
52
+ }
53
+ catch (error) {
54
+ if (error instanceof UnsupportedVersion) { return id }
55
+ else { throw error }
56
+ }
57
+ }
58
+
59
+ generate() {
60
+ return detect(this, ...arguments).generate(...arguments);
61
+ }
62
+
63
+ MIN() {
64
+ return detect(this, ...arguments).MIN();
65
+ }
66
+
67
+ MAX() {
68
+ return detect(this, ...arguments).MAX();
69
+ }
70
+ }
71
+
72
+ module.exports = { VersionedIdFactory };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ const ByteArray = require('../common/byte-array');
4
+
5
+ const _bytes = Symbol('bytes');
6
+
7
+ class BaseId {
8
+ //Constructors
9
+
10
+ constructor(bytes) {
11
+ this[_bytes] = bytes;
12
+ }
13
+
14
+ clone() {
15
+ return new this.constructor(this.bytes.slice());
16
+ }
17
+
18
+ // Accessors
19
+
20
+ get bytes() {
21
+ return this[_bytes];
22
+ }
23
+
24
+ get [Symbol.toStringTag]() {
25
+ return this.constructor.name;
26
+ }
27
+
28
+ // Comparators
29
+
30
+ compare(rhs) {
31
+ return ByteArray.compare(this.bytes, rhs.bytes);
32
+ }
33
+
34
+ equal(rhs) {
35
+ return this.compare(rhs) === 0;
36
+ }
37
+ }
38
+
39
+ module.exports = { BaseId };
@@ -0,0 +1,71 @@
1
+ const { Ulid, setTime } = require('./ulid');
2
+ const ByteArray = require('../common/byte-array');
3
+ const EpochConverter = require('../common/epoch-converter');
4
+ const { ClockSequenceOverflow } = require('../common/exception');
5
+
6
+ const TIME_OFFSET = 0;
7
+ const CLOCK_SEQUENCE_OFFSET = 6;
8
+ const RANDOM_OFFSET = 8;
9
+
10
+ const EPOCH_ORIGIN_MS = 0;
11
+
12
+ let _previous_id;
13
+ let _previous_time;
14
+
15
+ function incrementClockSequence(bytes) {
16
+ for (
17
+ let
18
+ idx = RANDOM_OFFSET - 1,
19
+ end = CLOCK_SEQUENCE_OFFSET - 1;
20
+ idx > end;
21
+ --idx
22
+ ) {
23
+ if (bytes[idx] === 0xFF) {
24
+ bytes[idx] = 0;
25
+ } else {
26
+ ++bytes[idx];
27
+ return;
28
+ }
29
+ }
30
+
31
+ throw new ClockSequenceOverflow('Exhausted clock sequence');
32
+ };
33
+
34
+ function reserveClockSequence(bytes) {
35
+ bytes[CLOCK_SEQUENCE_OFFSET] &= 0b01111111;
36
+ };
37
+
38
+ function restoreClockSequence(bytes) {
39
+ for (let idx = TIME_OFFSET; idx < RANDOM_OFFSET; ++idx) {
40
+ bytes[idx] = _previous_id.bytes[idx];
41
+ }
42
+ };
43
+
44
+ class UlidMonotonic extends Ulid {
45
+ static reset() {
46
+ _previous_time = -1;
47
+ _previous_id = this.MIN();
48
+ }
49
+
50
+ //Constructors
51
+
52
+ static generate({ time } = {}) {
53
+ time = EpochConverter.toEpoch(EPOCH_ORIGIN_MS, time);
54
+ let bytes = ByteArray.generateRandomFilled();
55
+
56
+ if (time <= _previous_time) {
57
+ restoreClockSequence(bytes);
58
+ incrementClockSequence(bytes);
59
+ } else {
60
+ setTime(time, bytes)
61
+ reserveClockSequence(bytes);
62
+ _previous_time = time;
63
+ }
64
+
65
+ return (_previous_id = new this(bytes));
66
+ }
67
+ }
68
+
69
+ UlidMonotonic.reset();
70
+
71
+ module.exports = { UlidMonotonic };
@@ -0,0 +1,64 @@
1
+ const ByteArray = require('../common/byte-array');
2
+ const EpochConverter = require('../common/epoch-converter');
3
+ const { BaseId } = require('./base');
4
+
5
+ const TIME_OFFSET = 0;
6
+
7
+ const EPOCH_ORIGIN_MS = 0;
8
+ const UINT32_RADIX = Math.pow(2, 32);
9
+ const UINT8_MAX = 0b11111111;
10
+
11
+ function setTime(time, bytes) {
12
+ const time_low = time % UINT32_RADIX;
13
+ const time_high = (time - time_low) / UINT32_RADIX;
14
+
15
+ let idx = TIME_OFFSET - 1;
16
+ bytes[++idx] = (time_high >>> 8) & UINT8_MAX;
17
+ bytes[++idx] = (time_high >>> 0) & UINT8_MAX;
18
+ bytes[++idx] = (time_low >>> 24) & UINT8_MAX;
19
+ bytes[++idx] = (time_low >>> 16) & UINT8_MAX;
20
+ bytes[++idx] = (time_low >>> 8) & UINT8_MAX;
21
+ bytes[++idx] = (time_low >>> 0) & UINT8_MAX;
22
+ }
23
+
24
+ class Ulid extends BaseId {
25
+
26
+ //Constructors
27
+
28
+ static generate({ time } = {}) {
29
+ time = EpochConverter.toEpoch(EPOCH_ORIGIN_MS, time);
30
+
31
+ let bytes = ByteArray.generateRandomFilled();
32
+
33
+ setTime(time, bytes);
34
+
35
+ return new this(bytes);
36
+ }
37
+
38
+ static MIN() {
39
+ return new this(ByteArray.generateZeroFilled());
40
+ }
41
+
42
+ static MAX() {
43
+ return new this(ByteArray.generateOneFilled());
44
+ }
45
+
46
+ // Accessors
47
+
48
+ get time() {
49
+ let idx = TIME_OFFSET - 1;
50
+ const time_high = 0
51
+ | (this.bytes[++idx] << 8)
52
+ | (this.bytes[++idx] << 0);
53
+ const time_low = 0
54
+ | (this.bytes[++idx] << 24)
55
+ | (this.bytes[++idx] << 16)
56
+ | (this.bytes[++idx] << 8)
57
+ | (this.bytes[++idx] << 0);
58
+ const epoch_ms = (time_high * UINT32_RADIX) + (time_low >>> 0);
59
+
60
+ return EpochConverter.fromEpoch(EPOCH_ORIGIN_MS, epoch_ms);
61
+ };
62
+ }
63
+
64
+ module.exports = { Ulid, setTime };
@@ -0,0 +1,149 @@
1
+ 'use strict';
2
+
3
+ const ByteArray = require('../common/byte-array');
4
+ const EpochConverter = require('../common/epoch-converter');
5
+ const Machine = require('../common/machine');
6
+ const {
7
+ Uuid,
8
+ setVariant,
9
+ setVersion,
10
+ } = require('./uuid');
11
+
12
+ const TIME_OFFSET = 0;
13
+ const HIRES_TIME_OFFSET = 2;
14
+ const CLOCK_SEQUENCE_OFFSET = 8;
15
+ const NODE_OFFSET = 10;
16
+
17
+ const CLOCK_SEQUENCE_RADIX = Math.pow(2, 14);
18
+ const EPOCH_ORIGIN_MS = Date.parse('1582-10-15Z');
19
+ const HIRES_TIME_RADIX = Math.pow(2, 12);
20
+ const TIME_LOW_MS_RADIX = Math.pow(2, 20);
21
+ const UINT8_MAX = 0b11111111;
22
+
23
+ let _clock_sequence;
24
+ let _hires_time;
25
+ let _previous_time;
26
+
27
+ function incrementClockSequence() {
28
+ _clock_sequence = (_clock_sequence + 1) % CLOCK_SEQUENCE_RADIX;
29
+ }
30
+
31
+ function setClockSequence(time, bytes) {
32
+ if (_clock_sequence === null) {
33
+ const random_bytes = ByteArray.generateRandomFilled();
34
+ _clock_sequence = (
35
+ 0
36
+ | random_bytes[CLOCK_SEQUENCE_OFFSET + 0] << 8
37
+ | random_bytes[CLOCK_SEQUENCE_OFFSET + 1] << 0
38
+ ) % CLOCK_SEQUENCE_RADIX;
39
+ }
40
+ else if (time < _previous_time) {
41
+ incrementClockSequence();
42
+ }
43
+
44
+ let idx = CLOCK_SEQUENCE_OFFSET - 1;
45
+ bytes[++idx] = (_clock_sequence >>> 8) & UINT8_MAX;
46
+ bytes[++idx] = (_clock_sequence >>> 0) & UINT8_MAX;
47
+ }
48
+
49
+ function setNode(node, bytes) {
50
+ for (let idx = 0; idx < 6; ++idx) {
51
+ bytes[NODE_OFFSET + idx] = node[idx];
52
+ }
53
+ }
54
+
55
+ function setTime(time, bytes) {
56
+ _hires_time = time > _previous_time ? 0 : _hires_time + 1;
57
+ if (_hires_time === HIRES_TIME_RADIX) {
58
+ _hires_time = 0;
59
+ incrementClockSequence();
60
+ }
61
+
62
+ const time_low_ms = time % TIME_LOW_MS_RADIX;
63
+ const time_low = time_low_ms * HIRES_TIME_RADIX + _hires_time;
64
+ const time_high = (time - time_low_ms) / TIME_LOW_MS_RADIX;
65
+
66
+ let idx = TIME_OFFSET - 1;
67
+ bytes[++idx] = (time_low >>> 24) & UINT8_MAX;
68
+ bytes[++idx] = (time_low >>> 16) & UINT8_MAX;
69
+ bytes[++idx] = (time_low >>> 8) & UINT8_MAX;
70
+ bytes[++idx] = (time_low >>> 0) & UINT8_MAX;
71
+ bytes[++idx] = (time_high >>> 8) & UINT8_MAX;
72
+ bytes[++idx] = (time_high >>> 0) & UINT8_MAX;
73
+ bytes[++idx] = (time_high >>> 24) & UINT8_MAX;
74
+ bytes[++idx] = (time_high >>> 16) & UINT8_MAX;
75
+ }
76
+
77
+ class Uuid1 extends Uuid {
78
+ static get VARIANT() { return 1 }
79
+ static get VERSION() { return 1 }
80
+
81
+ static reset() {
82
+ _clock_sequence = null;
83
+ _hires_time = -1;
84
+ _previous_time = -1;
85
+ }
86
+
87
+ //Constructors
88
+
89
+ static generate({ node, time } = {}) {
90
+ time = EpochConverter.toEpoch(EPOCH_ORIGIN_MS, time);
91
+
92
+ let bytes = ByteArray.generateZeroFilled();
93
+
94
+ setTime(time, bytes);
95
+ setClockSequence(time, bytes);
96
+ setNode(node || Machine.mac_address, bytes);
97
+ setVariant(this.VARIANT, bytes);
98
+ setVersion(this.VERSION, bytes);
99
+
100
+ if (time > _previous_time) {
101
+ _previous_time = time;
102
+ }
103
+
104
+ return new this(bytes);
105
+ }
106
+
107
+ // Accessors
108
+
109
+ get clock_sequence() {
110
+ return (
111
+ 0
112
+ | this.bytes[CLOCK_SEQUENCE_OFFSET] << 8
113
+ | this.bytes[CLOCK_SEQUENCE_OFFSET + 1]
114
+ ) & (CLOCK_SEQUENCE_RADIX - 1);
115
+ }
116
+
117
+ get hires_time() {
118
+ return (
119
+ 0
120
+ | this.bytes[HIRES_TIME_OFFSET] << 8
121
+ | this.bytes[HIRES_TIME_OFFSET + 1]
122
+ ) & (HIRES_TIME_RADIX - 1);
123
+ }
124
+
125
+ get node() {
126
+ return this.bytes.slice(NODE_OFFSET);
127
+ }
128
+
129
+ get time() {
130
+ let idx = TIME_OFFSET - 1;
131
+ const time_low_ms = 0
132
+ | (this.bytes[++idx] << 12)
133
+ | (this.bytes[++idx] << 4)
134
+ | (this.bytes[++idx] >>> 4);
135
+ ++idx; // Skip hi-res bits
136
+ const time_high = 0
137
+ | (this.bytes[++idx] << 8)
138
+ | (this.bytes[++idx] << 0)
139
+ | ((this.bytes[++idx] & 0x0F) << 24)
140
+ | (this.bytes[++idx] << 16);
141
+ const epoch_ms = time_high * TIME_LOW_MS_RADIX + time_low_ms;
142
+
143
+ return EpochConverter.fromEpoch(EPOCH_ORIGIN_MS, epoch_ms);
144
+ };
145
+ }
146
+
147
+ Uuid1.reset();
148
+
149
+ module.exports = { Uuid1 };
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ const ByteArray = require('../common/byte-array');
4
+ const {
5
+ Uuid,
6
+ setVariant,
7
+ setVersion,
8
+ } = require('./uuid');
9
+
10
+ class Uuid4 extends Uuid {
11
+ static get VARIANT() { return 1 }
12
+ static get VERSION() { return 4 }
13
+
14
+ static generate() {
15
+ let bytes = ByteArray.generateRandomFilled();
16
+
17
+ setVariant(this.VARIANT, bytes);
18
+ setVersion(this.VERSION, bytes);
19
+
20
+ return new this(bytes);
21
+ }
22
+ }
23
+
24
+ module.exports = { Uuid4 };