Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
memtech3 opened this issue Sep 14, 2024 · 0 comments

Comments

@memtech3
Copy link

memtech3 commented Sep 14, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant