protovalidate icon indicating copy to clipboard operation
protovalidate copied to clipboard

[Feature Request] Add support for ULID as a well_known validation rule

Open joldf opened this issue 2 years ago • 0 comments

Feature description:

Support for ULID as a well_known validation rule.

Problem it solves or use case:

ULID aims to be a unique identifier that can be generated on independent machines, much like UUID. However, the first component is generated from the timestamp (and the second half is meant to be monotonic for a given timestamp on a given generator, although this is not often followed in practice). This has the effect that it is better suited to use cases where ordering helps with performance, particularly database indices.

https://github.com/ulid/spec

It is possible to use the existing regex validation facility, but doing this separately to ever ULID field is quite redundant and noisy. Additionally, marking a field as ULID carries some semantic information (e.g. for generated documentation). Basically: the standard arguments for adding something as a well-known type.

Proposed implementation or solution:

Add ULID to the well_known oneof, and its implementation could be the following regex or equivalent (this is Python syntax):

[0-7][0-9A-HJKMNP-TV-Z]{25}

Alternatively, for a case insensitive implementation (this is what the ULID spec recommends but is probably less useful in a data interchange format, especially to optimise use as a database index):

[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}

Contribution:

Unfortunately I can't contribute an implementation, but would be happy to help with testing.

Examples or references:

Similar request for old protoc-gen-validate (issue 278)

joldf avatar Sep 14 '23 10:09 joldf