Skip to content

Uid attribute extended options #1509

@daniser

Description

@daniser

Describe the feature

Currently, only uid size is configurable in Uid attribute, and it's only passed to default implementation (generateId) and not the custom uid casts. For example, you cannot use supplied secure nanoid cast with custom size, or you cannot provide custom alphabet.

Also, there's no way to pass uid size to @Uid decorator. So, @Uid(7) won't generate uid with a size of 7 chars, but create default 21-char uid.

My suggestion is to replace size?: number with options?: Record<string, any> where possible, pass this parameter down to custom uid casts, and allow its usage in decorators.

Example usage:

import { Model } from 'pinia-orm'
import { Uid } from 'pinia-orm/nanoid'

class User extends Model {
  static entity = 'users'

  @Uid({ size: 7, alphabet: '0123456789abcdef' })
  declare id: string
}

This will generate secure nanoids with the length of 7 chars using custom alphabet.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions