Skip to content

UID Decorator: Setting Custom Alphabet Results in "undefined" Instead of Characters in UIDs #1928

@memtech3

Description

@memtech3

Environment

Vue, no Nuxt

Dependencies:

  "dependencies": {
    "@storybook/addon-themes": "^8.2.6",
    "@urql/vue": "^1.4.0",
    "@vueuse/core": "^10.11.0",
    "bootstrap": "^5.3.3",
    "bootstrap-icons": "^1.11.3",
    "graphql": "^16.9.0",
    "maplibre-gl": "^4.5.0",
    "pinia": "^2.2.0",
    "pinia-orm": "^1.9.2",
    "pinia-shared-state": "^0.5.1",
    "sass": "^1.77.8",
    "vue": "^3.4.34",
    "vue-router": "^4.4.0",
    "vue-winbox": "^0.2.3"
  },

Reproduction

Couldn't get decorators to work in pinia-orm-play.codedredd.de. Let me know if you need a proper reproduction.

Below is the code snippet from my project. Relevant line is the line that starts with @Uid. When I remove the alphabet parameter ,pinia ORM generates UIDs properly.

import { Model } from 'pinia-orm'
import { Attr, Num, Str, Uid, HasMany } from 'pinia-orm/decorators'
import { UnitEntity } from '@/stores/units'

export class ReportingParty {
  constructor(
    public firstName: string,
    public middleName: string,
    public lastName: string,
    public howReported: string,
    public callbackPhone: string,
    public fromPhone: string,
    public reportingPartyLocation: string
  ) {}
}

export class CadEventEntity extends Model {
  static readonly entity: string = 'cadEventEntities'

  @Uid({ size: 3, alphabet: '0123456789' }) declare id: string
  @Attr(Date) declare createdAt: Date
  @Str('') declare eventType: string
  @Num(7) declare priority: number
  @Str('') declare location: string
  @Str('') declare narrative: string
  @Attr([ReportingParty]) declare reportingParties: ReportingParty[]
  @HasMany(() => UnitEntity, 'assignedEventId') declare assignedUnits: UnitEntity[]
  // TODO: add comments/event history items
}

Describe the bug

Setting custom alphabet results in some characters of UID getting generated as "undefined"

Ex:

Expected UID: 123
Actual UID: undefined2undefined or undefinedundefined3 or 1undefinedundefined

Additional context

Here is a link to the problem file in my project's repo in case that helps. Let me know if there's anything I can do to gather and condense diagnostic information.
https://github.com/memtech3/dispatchSystem/blob/main/vue-frontend/src/stores/cadEvents.ts

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions