@thi.ng/ksuid 3.1.14 → 3.1.15
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/CHANGELOG.md +10 -1
- package/README.md +13 -12
- package/aksuid.d.ts +1 -1
- package/aksuid.js +2 -1
- package/ksuid32.js +2 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-08-
|
|
3
|
+
- **Last updated**: 2023-08-06T09:21:31Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,15 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [3.1.15](https://github.com/thi-ng/umbrella/tree/@thi.ng/ksuid@3.1.15) (2023-08-06)
|
|
13
|
+
|
|
14
|
+
#### 🩹 Bug fixes
|
|
15
|
+
|
|
16
|
+
- fix [#403](https://github.com/thi-ng/umbrella/issues/403), update KSUID32 epoch handling ([abbfc5a](https://github.com/thi-ng/umbrella/commit/abbfc5a))
|
|
17
|
+
- update .ensureTime() to check against optional max value
|
|
18
|
+
- fix int coercion in KSUID32.timeOnlyBinary()
|
|
19
|
+
- update readme
|
|
20
|
+
|
|
12
21
|
## [3.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/ksuid@3.1.0) (2023-02-10)
|
|
13
22
|
|
|
14
23
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -29,21 +29,22 @@ Idea based on [segmentio/ksuid](https://github.com/segmentio/ksuid), though the
|
|
|
29
29
|
added flexibility in terms of configuration & implementation also enables the
|
|
30
30
|
creation of [ULIDs](https://github.com/ulid/spec):
|
|
31
31
|
|
|
32
|
-
| Feature | KSUID default
|
|
33
|
-
|
|
34
|
-
| Configurable bit size | 160 bits
|
|
35
|
-
| Base-N encoding scheme | base62<sup>(1)</sup>
|
|
36
|
-
| Timestamp resolution | seconds (32 bits)
|
|
37
|
-
| | milliseconds (64 bits)
|
|
38
|
-
| Epoch start time offset | approx. 2020-09-13
|
|
39
|
-
| Time-only base ID generation | ✅
|
|
40
|
-
| ID parsing / decomposition | ✅
|
|
41
|
-
| Configurable RNG source<sup>(
|
|
32
|
+
| Feature | KSUID default | ULID default |
|
|
33
|
+
|---------------------------------------|----------------------------------|------------------------|
|
|
34
|
+
| Configurable bit size | 160 bits | 128 bits |
|
|
35
|
+
| Base-N encoding scheme | base62<sup>(1)</sup> | base32 (Crockford) |
|
|
36
|
+
| Timestamp resolution | seconds (32 bits) | milliseconds (48 bits) |
|
|
37
|
+
| | milliseconds (64 bits) | |
|
|
38
|
+
| Epoch start time offset | approx. 2020-09-13<sup>(2)</sup> | none |
|
|
39
|
+
| Time-only base ID generation | ✅ | ✅ |
|
|
40
|
+
| ID parsing / decomposition | ✅ | ✅ |
|
|
41
|
+
| Configurable RNG source<sup>(3)</sup> | ✅ | ✅ |
|
|
42
42
|
|
|
43
43
|
- <sup>(1)</sup> See
|
|
44
44
|
[@thi.ng/base-n](https://github.com/thi-ng/umbrella/tree/develop/packages/base-n)
|
|
45
45
|
for alternatives
|
|
46
|
-
- <sup>(2)</sup>
|
|
46
|
+
- <sup>(2)</sup> With the default offset, the max. supported date for `KSUID32` is 2156-10-20T18:54:55Z
|
|
47
|
+
- <sup>(3)</sup> Default: `window.crypto`, `Math.random` as fallback
|
|
47
48
|
|
|
48
49
|
IDs generated w/ this package are composed of a 32, 48 or 64 bit Unix epochs and
|
|
49
50
|
N additional bits of a random payload (from a configurable source). By default
|
|
@@ -110,7 +111,7 @@ For Node.js REPL:
|
|
|
110
111
|
const ksuid = await import("@thi.ng/ksuid");
|
|
111
112
|
```
|
|
112
113
|
|
|
113
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
114
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 809 bytes
|
|
114
115
|
|
|
115
116
|
## Dependencies
|
|
116
117
|
|
package/aksuid.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare abstract class AKSUID implements IKSUID {
|
|
|
26
26
|
id: Uint8Array;
|
|
27
27
|
};
|
|
28
28
|
protected ensureSize(buf: Uint8Array): Uint8Array;
|
|
29
|
-
protected ensureTime(t: number): number;
|
|
29
|
+
protected ensureTime(t: number, max?: number): number;
|
|
30
30
|
protected u32(buf: Uint8Array, i?: number): number;
|
|
31
31
|
}
|
|
32
32
|
//# sourceMappingURL=aksuid.d.ts.map
|
package/aksuid.js
CHANGED
|
@@ -45,8 +45,9 @@ export class AKSUID {
|
|
|
45
45
|
assert(buf.length == this.size, `illegal KSUID size, expected ${this.size} bytes`);
|
|
46
46
|
return buf;
|
|
47
47
|
}
|
|
48
|
-
ensureTime(t) {
|
|
48
|
+
ensureTime(t, max) {
|
|
49
49
|
assert(t >= 0, "configured base epoch must be in the past");
|
|
50
|
+
max && assert(t <= max, `given epoch is out of range ([0...${max}])`);
|
|
50
51
|
return t;
|
|
51
52
|
}
|
|
52
53
|
u32(buf, i = 0) {
|
package/ksuid32.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AKSUID } from "./aksuid.js";
|
|
2
|
+
const MAX_EPOCH = -1 >>> 0;
|
|
2
3
|
export class KSUID32 extends AKSUID {
|
|
3
4
|
constructor(opts) {
|
|
4
5
|
super(4, {
|
|
@@ -9,7 +10,7 @@ export class KSUID32 extends AKSUID {
|
|
|
9
10
|
}
|
|
10
11
|
timeOnlyBinary(epoch = Date.now()) {
|
|
11
12
|
const buf = new Uint8Array(this.size);
|
|
12
|
-
const t = this.ensureTime((
|
|
13
|
+
const t = this.ensureTime((epoch - this.epoch) / 1000, MAX_EPOCH) >>> 0;
|
|
13
14
|
buf.set([t >>> 24, (t >> 16) & 0xff, (t >> 8) & 0xff, t & 0xff]);
|
|
14
15
|
return buf;
|
|
15
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/ksuid",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.15",
|
|
4
4
|
"description": "Configurable K-sortable unique IDs, ULIDs, binary & base-N encoded, 32/48/64bit time resolutions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"test": "testament test"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/base-n": "^2.5.
|
|
39
|
+
"@thi.ng/base-n": "^2.5.7",
|
|
40
40
|
"@thi.ng/errors": "^2.3.0",
|
|
41
41
|
"@thi.ng/random": "^3.5.1",
|
|
42
42
|
"@thi.ng/strings": "^3.4.8"
|
|
@@ -114,5 +114,5 @@
|
|
|
114
114
|
"status": "stable",
|
|
115
115
|
"year": 2020
|
|
116
116
|
},
|
|
117
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "888293c74f2e9a481d500d4ec319f1e2bd765ec6\n"
|
|
118
118
|
}
|