Closed aelr closed 1 year ago
Thanks & fixed! :) Also updated the readme to point out the new max date for the KSUID32 implementation. With the default offset, the max. supported date for KSUID32 is 2156-10-20T18:54:55Z. If you need even further ahead, you'll have to switch to one of the other impls (KSUID64 or ULID)
Btw. @aelr, the fix has been released yesterday a v3.1.15
Thank you!
Please let me know if that's working for you now. If you're using these IDs for a new project, you might also be able to adjust the time shift to an offset around now and so gain an additional 3 years since the initial version of this library... You can do that like so:
const idgen = defKSUID32({ epoch: new Date("2023-08-08").getTime() });
I actually shifted away from KSUID after checking the perf numbers. Instead I'm using @thi.ng/base-n
to base62-encode Date.now()
and appending a nanoid
for the random bits. On my laptop, the ops/sec is 1.2 million/sec vs 90k/sec.
const encodeTimestamp = (ts) => BASE62.encode(ts).padStart(8, "0");
const nanoid = customAlphabet(B62_CHARS, 21);
const genId = (ts) => encodeTimestamp(ts) + nanoid();
This code using KSUID32 fails:
It throws at https://github.com/aelr/umbrella/blob/develop/packages/ksuid/src/aksuid.ts#L77:
For this specific case,
t = -2139591296
Also, should the error message be, "configured base epoch must not be in the past"?