UNPKG

pinia-orm

Version:

The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.

34 lines (30 loc) 875 B
import { customAlphabet, nanoid } from 'nanoid/async'; import { C as CastAttribute } from '../shared/pinia-orm.C7bM_uXu.mjs'; class UidCast extends CastAttribute { static parameters; /** * Create a new String attribute instance. */ constructor(attributes) { super(attributes); } static withParameters(parameters) { this.parameters = parameters; return this; } /** * Make the value for the attribute. */ async set(value) { const nanoid$1 = this.$parameters?.alphabet ? customAlphabet(this.$parameters.alphabet) : nanoid; return value ?? await nanoid$1(this.$parameters?.size); } } function Uid(options) { return (target, propertyKey) => { const self = target.$self(); self.setCast(propertyKey, UidCast.withParameters(options)); self.setRegistry(propertyKey, () => self.uid()); }; } export { Uid, UidCast };