Liking cljdoc? Tell your friends :D

typeid.validation

Validation predicates for TypeID components.

Manual validation predicates with zero external dependencies.

Overview

This namespace provides low-level validation functions used internally by typeid.core and typeid.codec. Most users should use the high-level API in typeid.core instead.

Main Functions

Validation predicates for TypeID components.

Manual validation predicates with zero external dependencies.

## Overview

This namespace provides low-level validation functions used internally
by `typeid.core` and `typeid.codec`. Most users should use the high-level
API in [[typeid.core]] instead.

## Main Functions

- [[valid-prefix?]] - Check if a prefix matches the TypeID pattern
- [[validate-prefix]] - Validate prefix with detailed error reporting
- [[valid-base32-suffix?]] - Check if a suffix is valid base32
- [[valid-typeid-string?]] - Check if a string has valid TypeID format
- [[valid-uuid-bytes?]] - Check if bytes represent a valid 16-byte UUID
raw docstring

valid-base32-suffix?clj/s

(valid-base32-suffix? s)

Check if suffix is valid base32 TypeID suffix.

Requirements

  • Exactly 26 characters
  • All characters in Crockford base32 alphabet (0-9a-hjkmnp-tv-z)
  • First character must be 0-7 (prevents 128-bit overflow)

Examples

(valid-base32-suffix? "01h5fskfsk4fpeqwnsyz5hj55t")
;;=> true

(valid-base32-suffix? "81h5fskfsk4fpeqwnsyz5hj55t")
;;=> false ; first char > 7

(valid-base32-suffix? "01h5fskfsk4fpeqwnsyz5hj55")
;;=> false ; too short
Check if suffix is valid base32 TypeID suffix.

## Requirements

- Exactly 26 characters
- All characters in Crockford base32 alphabet (`0-9a-hjkmnp-tv-z`)
- First character must be `0-7` (prevents 128-bit overflow)

## Examples

```clojure
(valid-base32-suffix? "01h5fskfsk4fpeqwnsyz5hj55t")
;;=> true

(valid-base32-suffix? "81h5fskfsk4fpeqwnsyz5hj55t")
;;=> false ; first char > 7

(valid-base32-suffix? "01h5fskfsk4fpeqwnsyz5hj55")
;;=> false ; too short
```
sourceraw docstring

valid-prefix?clj/s

(valid-prefix? s)

Check if prefix matches the TypeID prefix pattern.

Valid Prefixes

  • Empty string
  • 1-63 lowercase characters matching pattern: [a-z]([a-z_]{0,61}[a-z])?

Examples

(valid-prefix? "user")
;;=> true

(valid-prefix? "user_account")
;;=> true

(valid-prefix? "")
;;=> true

(valid-prefix? "User")
;;=> false ; uppercase not allowed

(valid-prefix? "user_")
;;=> false ; cannot end with underscore
Check if prefix matches the TypeID prefix pattern.

## Valid Prefixes

- Empty string
- 1-63 lowercase characters matching pattern: `[a-z]([a-z_]{0,61}[a-z])?`

## Examples

```clojure
(valid-prefix? "user")
;;=> true

(valid-prefix? "user_account")
;;=> true

(valid-prefix? "")
;;=> true

(valid-prefix? "User")
;;=> false ; uppercase not allowed

(valid-prefix? "user_")
;;=> false ; cannot end with underscore
```
sourceraw docstring

valid-typeid-string?clj/s

(valid-typeid-string? s)

Check if string has valid TypeID format (basic checks).

Requirements

  • Length between 26 and 90 characters
    • 26 characters: suffix only
    • Up to 90 characters: 63 (max prefix) + 1 (underscore) + 26 (suffix)
  • All lowercase

Note: This only checks basic format. Use typeid.core/explain for complete validation.

Examples

(valid-typeid-string? "user_01h5fskfsk4fpeqwnsyz5hj55t")
;;=> true

(valid-typeid-string? "01h5fskfsk4fpeqwnsyz5hj55t")
;;=> true

(valid-typeid-string? "User_01h5fskfsk4fpeqwnsyz5hj55t")
;;=> false ; uppercase
Check if string has valid TypeID format (basic checks).

## Requirements

- Length between 26 and 90 characters
  - 26 characters: suffix only
  - Up to 90 characters: 63 (max prefix) + 1 (underscore) + 26 (suffix)
- All lowercase

**Note:** This only checks basic format. Use [[typeid.core/explain]] for complete validation.

## Examples

```clojure
(valid-typeid-string? "user_01h5fskfsk4fpeqwnsyz5hj55t")
;;=> true

(valid-typeid-string? "01h5fskfsk4fpeqwnsyz5hj55t")
;;=> true

(valid-typeid-string? "User_01h5fskfsk4fpeqwnsyz5hj55t")
;;=> false ; uppercase
```
sourceraw docstring

valid-uuid-bytes?clj/s

(valid-uuid-bytes? b)

Check if bytes represent a valid UUID.

Requirements

  • Exactly 16 bytes
  • Platform-specific byte array type:
    • JVM: byte array (bytes?)
    • ClojureScript: js/Uint8Array

Examples

(def uuid-bytes (byte-array 16))
(valid-uuid-bytes? uuid-bytes)
;;=> true

(valid-uuid-bytes? (byte-array 15))
;;=> false ; too short
Check if bytes represent a valid UUID.

## Requirements

- Exactly 16 bytes
- Platform-specific byte array type:
  - JVM: byte array (`bytes?`)
  - ClojureScript: `js/Uint8Array`

## Examples

```clojure
(def uuid-bytes (byte-array 16))
(valid-uuid-bytes? uuid-bytes)
;;=> true

(valid-uuid-bytes? (byte-array 15))
;;=> false ; too short
```
sourceraw docstring

valid-uuidv7-bytes?clj/s

(valid-uuidv7-bytes? b)

Stricter validation for UUIDv7 format.

Checks that bytes conform to UUIDv7 specification:

  • Exactly 16 bytes
  • Version bits (bits 48-51) = 0111 (version 7)
  • Variant bits (bits 64-65) = 10 (RFC 4122 variant)

Examples

(require '[typeid.impl.uuid :as uuid])

(def v7-bytes (uuid/generate-uuidv7))
(valid-uuidv7-bytes? v7-bytes)
;;=> true

;; Random bytes won't pass version check
(valid-uuidv7-bytes? (byte-array 16))
;;=> false ; version/variant bits not set correctly
Stricter validation for UUIDv7 format.

Checks that bytes conform to UUIDv7 specification:
- Exactly 16 bytes
- Version bits (bits 48-51) = `0111` (version 7)
- Variant bits (bits 64-65) = `10` (RFC 4122 variant)

## Examples

```clojure
(require '[typeid.impl.uuid :as uuid])

(def v7-bytes (uuid/generate-uuidv7))
(valid-uuidv7-bytes? v7-bytes)
;;=> true

;; Random bytes won't pass version check
(valid-uuidv7-bytes? (byte-array 16))
;;=> false ; version/variant bits not set correctly
```
sourceraw docstring

validate-prefixclj/s

(validate-prefix prefix)

Validate prefix and return detailed result.

Returns

  • {:ok prefix} if valid
  • {:error error-map} if invalid

The error map contains :type, :message, and :data keys.

Examples

(validate-prefix "user")
;;=> {:ok "user"}

(validate-prefix "User")
;;=> {:error {:type :invalid-prefix-format, :message "...", ...}}

(validate-prefix (str/join (repeat 64 "a")))
;;=> {:error {:type :prefix-too-long, :message "...", ...}}
Validate prefix and return detailed result.

## Returns

- `{:ok prefix}` if valid
- `{:error error-map}` if invalid

The error map contains `:type`, `:message`, and `:data` keys.

## Examples

```clojure
(validate-prefix "user")
;;=> {:ok "user"}

(validate-prefix "User")
;;=> {:error {:type :invalid-prefix-format, :message "...", ...}}

(validate-prefix (str/join (repeat 64 "a")))
;;=> {:error {:type :prefix-too-long, :message "...", ...}}
```
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close