@thi.ng/ksuid 3.1.14 → 3.1.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-08-04T10:58:19Z
3
+ - **Last updated**: 2023-08-10T12:25:09Z
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
@@ -1,6 +1,7 @@
1
1
  <!-- This file is generated - DO NOT EDIT! -->
2
+ <!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
2
3
 
3
- # ![@thi.ng/ksuid](https://media.thi.ng/umbrella/banners-20220914/thing-ksuid.svg?2a899961)
4
+ # ![@thi.ng/ksuid](https://media.thi.ng/umbrella/banners-20230807/thing-ksuid.svg?2a899961)
4
5
 
5
6
  [![npm version](https://img.shields.io/npm/v/@thi.ng/ksuid.svg)](https://www.npmjs.com/package/@thi.ng/ksuid)
6
7
  ![npm downloads](https://img.shields.io/npm/dm/@thi.ng/ksuid.svg)
@@ -29,21 +30,22 @@ Idea based on [segmentio/ksuid](https://github.com/segmentio/ksuid), though the
29
30
  added flexibility in terms of configuration & implementation also enables the
30
31
  creation of [ULIDs](https://github.com/ulid/spec):
31
32
 
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 | none |
39
- | Time-only base ID generation | ✅ | ✅ |
40
- | ID parsing / decomposition | ✅ | ✅ |
41
- | Configurable RNG source<sup>(2)</sup> | ✅ | ✅ |
33
+ | Feature | KSUID default | ULID default |
34
+ |---------------------------------------|----------------------------------|------------------------|
35
+ | Configurable bit size | 160 bits | 128 bits |
36
+ | Base-N encoding scheme | base62<sup>(1)</sup> | base32 (Crockford) |
37
+ | Timestamp resolution | seconds (32 bits) | milliseconds (48 bits) |
38
+ | | milliseconds (64 bits) | |
39
+ | Epoch start time offset | approx. 2020-09-13<sup>(2)</sup> | none |
40
+ | Time-only base ID generation | ✅ | ✅ |
41
+ | ID parsing / decomposition | ✅ | ✅ |
42
+ | Configurable RNG source<sup>(3)</sup> | ✅ | ✅ |
42
43
 
43
44
  - <sup>(1)</sup> See
44
45
  [@thi.ng/base-n](https://github.com/thi-ng/umbrella/tree/develop/packages/base-n)
45
46
  for alternatives
46
- - <sup>(2)</sup> Default: `window.crypto`, `Math.random` as fallback
47
+ - <sup>(2)</sup> With the default offset, the max. supported date for `KSUID32` is 2156-10-20T18:54:55Z
48
+ - <sup>(3)</sup> Default: `window.crypto`, `Math.random` as fallback
47
49
 
48
50
  IDs generated w/ this package are composed of a 32, 48 or 64 bit Unix epochs and
49
51
  N additional bits of a random payload (from a configurable source). By default
@@ -86,7 +88,7 @@ implementations already used milliseconds.
86
88
 
87
89
  ## Related packages
88
90
 
89
- - [@thi.ng/base-n](https://github.com/thi-ng/umbrella/tree/develop/packages/base-n) - Arbitrary base-n conversions w/ presets for base16/32/36/58/62/64/85, support for arrays & bigints
91
+ - [@thi.ng/base-n](https://github.com/thi-ng/umbrella/tree/develop/packages/base-n) - Arbitrary base-n conversions w/ presets for base8/16/32/36/58/62/64/85, support for bigints and encoding/decoding of byte arrays
90
92
  - [@thi.ng/idgen](https://github.com/thi-ng/umbrella/tree/develop/packages/idgen) - Generator of opaque numeric identifiers with optional support for ID versioning and efficient re-use
91
93
  - [@thi.ng/random](https://github.com/thi-ng/umbrella/tree/develop/packages/random) - Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation
92
94
 
@@ -110,7 +112,7 @@ For Node.js REPL:
110
112
  const ksuid = await import("@thi.ng/ksuid");
111
113
  ```
112
114
 
113
- Package sizes (brotli'd, pre-treeshake): ESM: 769 bytes
115
+ Package sizes (brotli'd, pre-treeshake): ESM: 809 bytes
114
116
 
115
117
  ## Dependencies
116
118
 
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(((epoch - this.epoch) / 1000) | 0);
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.14",
3
+ "version": "3.1.17",
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,14 +36,14 @@
36
36
  "test": "testament test"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/base-n": "^2.5.6",
40
- "@thi.ng/errors": "^2.3.0",
41
- "@thi.ng/random": "^3.5.1",
42
- "@thi.ng/strings": "^3.4.8"
39
+ "@thi.ng/base-n": "^2.5.9",
40
+ "@thi.ng/errors": "^2.3.2",
41
+ "@thi.ng/random": "^3.5.3",
42
+ "@thi.ng/strings": "^3.4.10"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@microsoft/api-extractor": "^7.36.3",
46
- "@thi.ng/testament": "^0.3.18",
46
+ "@thi.ng/testament": "^0.3.20",
47
47
  "rimraf": "^5.0.1",
48
48
  "tools": "^0.0.1",
49
49
  "typedoc": "^0.24.8",
@@ -114,5 +114,5 @@
114
114
  "status": "stable",
115
115
  "year": 2020
116
116
  },
117
- "gitHead": "9fa3f7f8169efa30e3c71b43c82f77393581c3b5\n"
117
+ "gitHead": "ad9ac3232c6fc5fc8a0df75ac82fc1e0e9fb0258\n"
118
118
  }