pinia-orm
Version:
The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.
218 lines (196 loc) • 5.86 kB
JavaScript
function Attr(value) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(propertyKey, () => self.attr(value));
};
}
function Str(value, options = {}) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(propertyKey, () => {
const attr = self.string(value);
if (options.notNullable) {
attr.notNullable();
}
return attr;
});
};
}
function Num(value, options = {}) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(propertyKey, () => {
const attr = self.number(value);
if (options.notNullable) {
attr.notNullable();
}
return attr;
});
};
}
function Bool(value, options = {}) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(propertyKey, () => {
const attr = self.boolean(value);
if (options.notNullable) {
attr.notNullable();
}
return attr;
});
};
}
function Uid(options) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(propertyKey, () => self.uid(options));
};
}
function HasOne(related, foreignKey, localKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(
propertyKey,
() => self.hasOne(related(), foreignKey, localKey)
);
};
}
function BelongsTo(related, foreignKey, ownerKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(
propertyKey,
() => self.belongsTo(related(), foreignKey, ownerKey)
);
};
}
function BelongsToMany(related, pivot, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(
propertyKey,
() => {
if (typeof pivot === "function") {
return self.belongsToMany(related(), pivot(), foreignPivotKey, relatedPivotKey, parentKey, relatedKey);
}
return self.belongsToMany(related(), pivot.model(), foreignPivotKey, relatedPivotKey, parentKey, relatedKey).as(pivot.as);
}
);
};
}
function HasMany(related, foreignKey, localKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(
propertyKey,
() => self.hasMany(related(), foreignKey, localKey)
);
};
}
function HasManyBy(related, foreignKey, ownerKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(
propertyKey,
() => self.hasManyBy(related(), foreignKey, ownerKey)
);
};
}
function HasManyThrough(related, through, firstKey, secondKey, localKey, secondLocalKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(
propertyKey,
() => self.hasManyThrough(related(), through(), firstKey, secondKey, localKey, secondLocalKey)
);
};
}
function MorphOne(related, id, type, localKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(
propertyKey,
() => self.morphOne(related(), id, type, localKey)
);
};
}
function MorphTo(related, id, type, ownerKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(
propertyKey,
() => self.morphTo(related(), id, type, ownerKey)
);
};
}
function MorphToMany(related, pivot, relatedId, id, type, parentKey, relatedKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(propertyKey, () => {
if (typeof pivot === "function") {
return self.morphToMany(related(), pivot(), relatedId, id, type, parentKey, relatedKey);
}
return self.morphToMany(related(), pivot.model(), relatedId, id, type, parentKey, relatedKey).as(pivot.as);
});
};
}
function MorphedByMany(related, pivot, relatedId, id, type, parentKey, relatedKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(propertyKey, () => {
if (typeof pivot === "function") {
return self.morphedByMany(related(), pivot(), relatedId, id, type, parentKey, relatedKey);
}
return self.morphedByMany(related(), pivot.model(), relatedId, id, type, parentKey, relatedKey).as(pivot.as);
});
};
}
function MorphMany(related, id, type, localKey) {
return (target, propertyKey) => {
const self = target.$self();
self.setRegistry(
propertyKey,
() => self.morphMany(related(), id, type, localKey)
);
};
}
function OnDelete(mode) {
return (target, propertyKey) => {
const self = target.$self();
self.setFieldDeleteMode(propertyKey, mode);
};
}
function Cast(to) {
return (target, propertyKey) => {
const self = target.$self();
self.setCast(propertyKey, to());
};
}
function Mutate(get, set) {
return (target, propertyKey) => {
const self = target.$self();
self.setMutator(propertyKey, { get, set });
};
}
function Hidden() {
return (target, propertyKey) => {
const self = target.$self();
self.setHidden(propertyKey);
};
}
function NonEnumerable(target, propertyKey) {
const descriptor = Object.getOwnPropertyDescriptor(target, propertyKey) || /* @__PURE__ */ Object.create(null);
if (descriptor.enumerable !== false) {
Object.defineProperty(target, propertyKey, {
enumerable: false,
set(value) {
Object.defineProperty(this, propertyKey, {
enumerable: false,
writable: true,
value
});
}
});
}
}
export { Attr, BelongsTo, BelongsToMany, Bool, Cast, HasMany, HasManyBy, HasManyThrough, HasOne, Hidden, MorphMany, MorphOne, MorphTo, MorphToMany, MorphedByMany, Mutate, NonEnumerable, Num, OnDelete, Str, Uid };