marcoonroad / ocaml-cuid

CUID generator for OCaml. :id: :camel: :1234: :gear:
MIT License
18 stars 1 forks source link

Command-line tool must remember internal state (i.e, counter) #1

Open marcoonroad opened 6 years ago

marcoonroad commented 6 years ago

No matter how much time we call ocuidml, it will always return the same counter field (in the case, 0000). It doesn't seem right, honestly. We should figure out a way to persist the counter state among shell invocations for such command. Either through a sort of daemon server or local/user configuration might be reasonable. :v:

marcoonroad commented 6 years ago

The command line tool will be removed for the initial release. Future releases could track this question. By now, this Issue will remain open until that.

See commit 2613aae.

marcoonroad commented 3 years ago

This command-line utility tool (as a wrapper around this library) must be properly implemented for the next 1.0 release.

marcoonroad commented 3 years ago

If a lockfile for CUID's counter is used, it will need a new user/group permission (such as ocaml-cuid-process), otherwise, external potentially malicious actors could predict and/or tamper part of ID generation. Unhappily, this user/group idea could only work on Unix-like environments (Linux, BSD and MacOS), making the Windows implementation infeasible.

If I make the counter random or a fixed number, it would break the linear ordering of generated CUIDs. The only option I have is to make the counter the milliseconds piece of timestamp. In this sense, the library should support a ?(stateless=false) for both CUIDs and slugs generation, so the ~stateless:true parameter would be useful on concurrent/asynchronous environments as well.