-
Notifications
You must be signed in to change notification settings - Fork 632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ulid): port /x/ulid module #3582
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably only want to export the following from mod.ts
:
decodeTime()
factory()
monotonicFactory()
PRNG
ULID
I think the others should be moved to a_util.ts
or similar file.
We also probably want to include the examples from the README in the JSDocs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM again
@iuioiua Do you know the usage of I'm also unsure we need to export I'd suggest we should only expose |
I think I agree with the rest of your points. |
Ok. Monotonicity looks useful. (This doc also mentions about guaranteeing of generation order). While monotonicity is useful, |
Yeah, it seems a little funny. It only increments monotonically if the last timestamp is less than or equal to the current timestamp (now). I think it's fine how it is with the name Half-related: I think deviating from the ULID's JavaScript implementation is fine. Otherwise, we'd be putting ourselves into a box regarding capability. E.g. I found a possible tweak that could improve the performance of ULID generation by 10x while maintaining cryptographically random strings. Though, I'd have to validate it's correctness first 🤣 |
WDYT, @kt3k? |
I would almost flip the naming to have |
With monotonic version, the random bits are not random anymore, and it seems having far higher possibility of collision in distributed usage. I think monotonic version is not something we should recommend by default. |
I missed that. This makes sense then. Completely agree that no one will replace the PRNG function. I'll rework the PR tonight if I can. |
Oh, I completely missed that you suggested removing the random number generator parameter. Yes, that parameter looks mostly useless to me. |
Return of the flaky tests I guess. This is ready for review @iuioiua. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool to see that change implemented! Few things:
- I don't think
monotonicFactory()
should have anencodeRand
parameter or any parameter. - This implementation deviates from the original JS implementation (e.g. faster
encodeRandom()
and noprng
parameter. I think these differences should be pointed out in the JSDocs somewhere.
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Strongly disagree. It is much harder to test without this parameter. It is not exposed to end users so I don't think this matters.
Again, not exposed to the user so I don't know if that's relevant. |
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regardless of my previous unreachable line comment, LGTM! This implementation is actually better than the original JavaScript implementation because:
- Random strings are generated 10x faster.
- The redundant
prng
parameter is removed. Fewer options are better. - Monontic ULIDs are possible without having first to create the factory.
Good stuff, @lino-levan and @kt3k!
* monotonicUlid(100000); // 000XAL6S41ACTAV9WEVGEMMVRD | ||
* ``` | ||
*/ | ||
export const monotonicUlid = monotonicFactory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally misread your initial suggestion, @kt3k. Now, I understand, and I like it 😎
Anything else pending for this PR? |
Nothing pending afaik. Waiting for any comments from @kt3k. |
I've noticed a bug with |
Could you write a reproduction? I suspect it may be a feature but I'm not too sure. @kt3k may know more about it. |
Yeah, I'll get a repro snippet when I can. |
Alright I've been staring at this code for too long. I don't see this bug. I'd appreciate a fresh set of eyes. |
Sorry, I haven't had the chance to look into this further. @kt3k, would |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for your efforts! @lino-levan
Note: Core team also looked in favor of including this.
Yes, we are planning to keep ulid unstable (versioned as 0.x) for a while. |
Closes #3522.
I think this is valuable, particularly for Deno KV.