UNPKG

pinia-orm

Version:

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

35 lines (31 loc) 1.05 kB
import { customAlphabet, nanoid } from 'nanoid/non-secure'; import { C as CastAttribute } from '../shared/pinia-orm.C7bM_uXu.mjs'; import { o as ownMetadataRecord, c as createFieldDecorator, C as CASTS } from '../shared/pinia-orm.DhuaEUVi.mjs'; import '../shared/pinia-orm.pROBaphR.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. */ set(value) { const nanoid$1 = this.$parameters?.alphabet ? customAlphabet(this.$parameters.alphabet) : nanoid; return value ?? nanoid$1(this.$parameters?.size); } } function Uid(options) { return (_value, context) => { ownMetadataRecord(context.metadata, CASTS)[String(context.name)] = UidCast.withParameters(options); return createFieldDecorator((model) => model.uid())(_value, context); }; } export { Uid, UidCast };