New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pinia-orm

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinia-orm - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

dist/Contracts-560faa26.d.ts

3

dist/casts.d.ts

@@ -1,4 +0,3 @@

import { X as CastAttribute, o as ModelFields } from './Data-4c999fcd.js';
import { U as CastAttribute, m as ModelFields } from './Data-aad5308e.js';
import 'pinia';
import '@/composables';
import '@pinia-orm/normalizr';

@@ -5,0 +4,0 @@

@@ -1,6 +0,5 @@

import { P as PropertyDecorator, T as TypeOptions } from './Contracts-dfee3653.js';
export { P as PropertyDecorator, T as TypeOptions } from './Contracts-dfee3653.js';
import { Y as TypeDefault, M as Model, y as deleteModes, X as CastAttribute, a5 as Mutator } from './Data-4c999fcd.js';
import { P as PropertyDecorator, T as TypeOptions } from './Contracts-560faa26.js';
export { P as PropertyDecorator, T as TypeOptions } from './Contracts-560faa26.js';
import { V as TypeDefault, M as Model, v as deleteModes, U as CastAttribute, a3 as Mutator } from './Data-aad5308e.js';
import 'pinia';
import '@/composables';
import '@pinia-orm/normalizr';

@@ -59,2 +58,7 @@

/**
* Create a has-many attribute property decorator.
*/
declare function HasManyThrough(related: () => typeof Model, through: () => typeof Model, firstKey: string, secondKey: string, localKey?: string, secondLocalKey?: string): PropertyDecorator;
/**
* Create a morph-one attribute property decorator.

@@ -99,2 +103,2 @@ */

export { Attr, BelongsTo, BelongsToMany, Bool, Cast, HasMany, HasManyBy, HasOne, Hidden, MorphMany, MorphOne, MorphTo, Mutate, NonEnumerable, Num, OnDelete, Str, Uid };
export { Attr, BelongsTo, BelongsToMany, Bool, Cast, HasMany, HasManyBy, HasManyThrough, HasOne, Hidden, MorphMany, MorphOne, MorphTo, Mutate, NonEnumerable, Num, OnDelete, Str, Uid };

@@ -103,2 +103,12 @@ 'use strict';

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) {

@@ -185,2 +195,3 @@ return (target, propertyKey) => {

exports.HasManyBy = HasManyBy;
exports.HasManyThrough = HasManyThrough;
exports.HasOne = HasOne;

@@ -187,0 +198,0 @@ exports.Hidden = Hidden;

@@ -1,4 +0,3 @@

import { M as Model, f as Collection } from './Data-4c999fcd.js';
import { M as Model, e as Collection } from './Data-aad5308e.js';
import 'pinia';
import '@/composables';
import '@pinia-orm/normalizr';

@@ -5,0 +4,0 @@

'use strict';
const Utils = require('./shared/pinia-orm.88564ad3.cjs');
const Utils = require('./shared/pinia-orm.34b622d8.cjs');

@@ -5,0 +5,0 @@ function useSum(models, field) {

@@ -1,6 +0,6 @@

import { M as Model, C as Constructor, D as Database, W as WeakCache, a as DataStoreState, E as Elements, Q as Query, b as WherePrimaryClosure, c as WhereSecondaryClosure, d as EagerLoadConstraint, G as GroupByFields, O as OrderBy, e as OrderDirection, f as Collection, I as Item, g as Element, h as DataStore } from './Data-4c999fcd.js';
export { A as AfterHook, w as Attribute, B as BeforeHook, z as BelongsTo, H as BelongsToMany, k as CacheConfigOptions, X as CastAttribute, V as Casts, f as Collection, h as DataStore, a as DataStoreState, D as Database, x as Dictionary, a4 as EagerLoad, d as EagerLoadConstraint, g as Element, E as Elements, F as FilledInstallOptions, a2 as Group, a3 as GroupBy, G as GroupByFields, i as GroupedCollection, J as HasMany, L as HasManyBy, K as HasOne, v as InheritanceTypes, l as InstallOptions, _ as Interpreter, I as Item, t as MetaValues, M as Model, j as ModelConfigOptions, o as ModelFields, s as ModelOptions, q as ModelRegistries, r as ModelRegistry, p as ModelSchemas, P as MorphMany, U as MorphOne, T as MorphTo, N as NormalizedData, a1 as Order, O as OrderBy, e as OrderDirection, Q as Query, R as Relation, n as Schema, S as Schemas, Z as Type, Y as TypeDefault, $ as Where, a0 as WhereGroup, b as WherePrimaryClosure, c as WhereSecondaryClosure, m as createORM, y as deleteModes, u as useDataStore } from './Data-4c999fcd.js';
import { M as Model, C as Constructor, E as Elements, D as Database, W as WeakCache, Q as Query, a as WherePrimaryClosure, b as WhereSecondaryClosure, c as EagerLoadConstraint, G as GroupByFields, O as OrderBy, d as OrderDirection, e as Collection, I as Item, f as Element } from './Data-aad5308e.js';
export { A as AfterHook, t as Attribute, B as BeforeHook, w as BelongsTo, x as BelongsToMany, i as CacheConfigOptions, U as CastAttribute, T as Casts, e as Collection, D as Database, u as Dictionary, a2 as EagerLoad, c as EagerLoadConstraint, f as Element, E as Elements, F as FilledInstallOptions, a0 as Group, a1 as GroupBy, G as GroupByFields, g as GroupedCollection, H as HasMany, z as HasManyBy, J as HasManyThrough, y as HasOne, s as InheritanceTypes, j as InstallOptions, Y as Interpreter, I as Item, r as MetaValues, M as Model, h as ModelConfigOptions, m as ModelFields, q as ModelOptions, o as ModelRegistries, p as ModelRegistry, n as ModelSchemas, K as MorphMany, P as MorphOne, L as MorphTo, N as NormalizedData, $ as Order, O as OrderBy, d as OrderDirection, Q as Query, R as Relation, l as Schema, S as Schemas, X as Type, V as TypeDefault, Z as Where, _ as WhereGroup, a as WherePrimaryClosure, b as WhereSecondaryClosure, k as createORM, v as deleteModes } from './Data-aad5308e.js';
import * as pinia from 'pinia';
import { Pinia } from 'pinia';
import '@/composables';
import { DefineStoreOptionsBase, Pinia } from 'pinia';
import * as __composables from '@/composables';
import '@pinia-orm/normalizr';

@@ -12,2 +12,17 @@

declare function useDataStore<S extends DataStoreState, T extends DataStore = DataStore>(id: string, options: DefineStoreOptionsBase<S, T>): pinia.StoreDefinition<string, S, {}, {
save(this: any, records: Elements): void;
insert(this: any, records: Elements): void;
update(this: any, records: Elements): void;
fresh(this: any, records: Elements): void;
destroy(this: any, ids: string[]): void;
delete(this: any, ids: string[]): void;
flush(this: any): void;
}>;
interface DataStoreState {
data: Record<string, any>;
[s: string]: any;
}
type DataStore = ReturnType<typeof __composables['useDataStore']>;
declare class Repository<M extends Model = Model> {

@@ -61,3 +76,3 @@ /**

*/
piniaStore(): pinia.Store<string, DataStoreState, {}, {
piniaStore<S extends DataStoreState = DataStoreState>(): pinia.Store<string, S, {}, {
save(this: any, records: Elements): void;

@@ -243,2 +258,2 @@ insert(this: any, records: Elements): void;

export { MappedRepositories, ModelOrRepository, ModelsOrRepositories, Repository, mapRepos, useRepo, useStoreActions };
export { DataStore, DataStoreState, MappedRepositories, ModelOrRepository, ModelsOrRepositories, Repository, mapRepos, useDataStore, useRepo, useStoreActions };
'use strict';
const Utils = require('./shared/pinia-orm.88564ad3.cjs');
const Utils = require('./shared/pinia-orm.34b622d8.cjs');
const normalizr = require('@pinia-orm/normalizr');

@@ -293,3 +293,3 @@ const pinia = require('pinia');

function useDataStore(id, options = null) {
function useDataStore(id, options) {
return pinia.defineStore(id, {

@@ -313,3 +313,3 @@ state: () => ({ data: {} }),

getRelateds() {
return [this.related];
return [this.related, this.pivot];
}

@@ -344,3 +344,2 @@ define(schema) {

addEagerConstraints(query, collection) {
query.database.register(this.pivot);
const pivotKeys = query.newQuery(this.pivot.$entity()).where(this.foreignPivotKey, this.getKeys(collection, this.parentKey)).get(false).map((item) => item[this.relatedPivotKey]);

@@ -373,3 +372,3 @@ query.whereIn(this.relatedKey, pivotKeys);

newQueryWithConstraints(model) {
const newQuery = new Query(this.database, this.database.getModel(model), this.cache, this.hydratedData, this.pinia);
const newQuery = new Query(this.database, this.database.getModel(model), this.cache, /* @__PURE__ */ new Map(), this.pinia);
newQuery.eagerLoad = { ...this.eagerLoad };

@@ -634,3 +633,3 @@ newQuery.wheres = [...this.wheres];

return null;
const model = this.hydrate(item, void 0, true);
const model = this.hydrate(item);
this.reviveRelations(model, schema);

@@ -664,3 +663,3 @@ return model;

new() {
const model = this.hydrate({}, void 0, true);
const model = this.hydrate({});
this.commit("insert", this.compile(model));

@@ -706,3 +705,3 @@ return model;

const existing = currentData[id];
const model = existing ? this.hydrate({ ...existing, ...record }, { operation: "set", action: "update" }, true) : this.hydrate(record, { operation: "set", action: "save" }, true);
const model = existing ? this.hydrate({ ...existing, ...record }, { operation: "set", action: "update" }) : this.hydrate(record, { operation: "set", action: "save" });
const isSaving = model.$self().saving(model, record);

@@ -729,3 +728,3 @@ const isUpdatingOrCreating = existing ? model.$self().updating(model, record) : model.$self().creating(model, record);

fresh(records) {
const models = this.hydrate(records);
const models = this.hydrate(records, { action: "update" });
this.commit("fresh", this.compile(models));

@@ -739,3 +738,7 @@ return models;

const newModels = models.map((model) => {
return this.hydrate({ ...model.$getAttributes(), ...record }, void 0, true);
const newModel = this.hydrate({ ...model.$getAttributes(), ...record }, { action: "update" });
if (model.$self().updating(model, record) === false)
return model;
newModel.$self().updated(newModel);
return newModel;
});

@@ -785,2 +788,3 @@ this.commit("update", this.compile(newModels));

this.commit("flush");
this.hydratedData.clear();
return this.get(false);

@@ -828,7 +832,8 @@ }

const isDeleting = currentModel.$self().deleting(currentModel);
this.checkAndDeleteRelations(currentModel);
if (isDeleting === false)
if (isDeleting === false) {
notDeletableIds.push(currentModel.$getIndexId());
else
} else {
afterHooks.push(() => currentModel.$self().deleted(currentModel));
this.checkAndDeleteRelations(currentModel);
}
});

@@ -840,4 +845,4 @@ return [afterHooks, notDeletableIds];

}
hydrate(records, options, update = false) {
return Utils.isArray(records) ? records.map((record) => this.hydrate(record, options, update)) : this.getHydratedModel(records, update, { relations: false, ...options || {} });
hydrate(records, options) {
return Utils.isArray(records) ? records.map((record) => this.hydrate(record, options)) : this.getHydratedModel(records, { relations: false, ...options || {} });
}

@@ -851,10 +856,12 @@ compile(models) {

}
getHydratedModel(record, update = false, options) {
const id = record[this.model.$getKeyName()];
const savedHydratedModel = this.hydratedData.get(id);
getHydratedModel(record, options) {
const modelKey = this.model.$getKeyName();
const id = (!Utils.isArray(modelKey) ? [modelKey] : modelKey).map((key) => record[key]).join("");
const savedHydratedModel = id && this.hydratedData.get(id);
if (savedHydratedModel && this.hidden.length === 0 && this.visible.includes("*") && Utils.equals(record, savedHydratedModel.$toJson()))
return savedHydratedModel;
const modelByType = this.model.$types()[record[this.model.$typeKey()]];
const hydratedModel = (modelByType ? modelByType.newRawInstance() : this.model).$newInstance(record, { relations: false, ...options || {} });
if (!update && savedHydratedModel && JSON.stringify(savedHydratedModel) === JSON.stringify(hydratedModel))
return savedHydratedModel;
this.hydratedData.set(id, hydratedModel);
if (id)
this.hydratedData.set(id, hydratedModel);
return hydratedModel;

@@ -1439,2 +1446,40 @@ }

class HasManyThrough extends Relation {
constructor(parent, related, through, firstKey, secondKey, localKey, secondLocalKey) {
super(parent, related);
this.through = through;
this.firstKey = firstKey;
this.secondKey = secondKey;
this.localKey = localKey;
this.secondLocalKey = secondLocalKey;
}
getRelateds() {
return [this.related, this.through];
}
define(schema) {
return schema.many(this.related, this.parent);
}
attach(_record, _child) {
}
addEagerConstraints(_query, _models) {
}
match(relation, models, query) {
const throughModels = query.newQuery(this.through.$entity()).where(this.firstKey, this.getKeys(models, this.localKey)).get(false);
const relatedModels = query.where(this.secondKey, this.getKeys(throughModels, this.secondLocalKey)).groupBy(this.secondKey).get(false);
const dictionary = this.buildDictionary(throughModels, relatedModels);
models.forEach((model) => {
const key = model[this.localKey];
dictionary[key] ? model.$setRelation(relation, dictionary[key][0]) : model.$setRelation(relation, []);
});
}
buildDictionary(throughResults, results) {
return this.mapToDictionary(throughResults, (throughResult) => {
return [throughResult[this.firstKey], results[throughResult[this.secondLocalKey]]];
});
}
make(elements) {
return elements ? elements.map((element) => this.related.$newInstance(element)) : [];
}
}
class Model {

@@ -1451,2 +1496,3 @@ constructor(attributes, options = { operation: "set" }) {

this.schemas[this.entity] = {};
this.fieldsOnDelete[this.entity] = this.fieldsOnDelete[this.entity] ?? {};
const registry = {

@@ -1459,4 +1505,4 @@ ...this.fields(),

this.schemas[this.entity][key] = typeof attribute === "function" ? attribute() : attribute;
if (this.fieldsOnDelete[key])
this.schemas[this.entity][key] = this.schemas[this.entity][key].onDelete(this.fieldsOnDelete[key]);
if (this.fieldsOnDelete[this.entity][key])
this.schemas[this.entity][key] = this.schemas[this.entity][key].onDelete(this.fieldsOnDelete[this.entity][key]);
}

@@ -1471,3 +1517,4 @@ }

static setFieldDeleteMode(key, mode) {
this.fieldsOnDelete[key] = mode;
this.fieldsOnDelete[this.entity] = this.fieldsOnDelete[this.entity] ?? {};
this.fieldsOnDelete[this.entity][key] = mode;
return this;

@@ -1553,2 +1600,9 @@ }

}
static hasManyThrough(related, through, firstKey, secondKey, localKey, secondLocalKey) {
const model = this.newRawInstance();
const throughModel = through.newRawInstance();
localKey = localKey ?? model.$getLocalKey();
secondLocalKey = secondLocalKey ?? throughModel.$getLocalKey();
return new HasManyThrough(model, related.newRawInstance(), throughModel, firstKey, secondKey, localKey, secondLocalKey);
}
static morphOne(related, id, type, localKey) {

@@ -1664,2 +1718,3 @@ const model = this.newRawInstance();

}
operation === "set" && (this.$self().original = this.$getAttributes());
modelConfig.withMeta && operation === "set" && this.$fillMeta(options.action);

@@ -1768,2 +1823,18 @@ return this;

}
$getOriginal() {
return this.$self().original;
}
$refresh() {
this.$isDirty() && this.$fill(this.$getOriginal(), { action: "save", relations: false, operation: "set" });
return this;
}
$isDirty($attribute) {
const original = this.$getOriginal();
if ($attribute) {
if (!Object.keys(original).includes($attribute))
Utils.throwError(['The property"', $attribute, '"does not exit in the model "', this.$entity(), '"']);
return !Utils.equals(this[$attribute], original[$attribute]);
}
return !Utils.equals(original, this.$getAttributes());
}
$getAttributes() {

@@ -1821,2 +1892,3 @@ return this.$toJson(this, { relations: false });

Model.fieldsOnDelete = {};
Model.original = {};
Model.schemas = {};

@@ -1854,2 +1926,3 @@ Model.registries = {};

exports.HasManyBy = HasManyBy;
exports.HasManyThrough = HasManyThrough;
exports.HasOne = HasOne;

@@ -1856,0 +1929,0 @@ exports.Interpreter = Interpreter;

@@ -1,5 +0,4 @@

import { X as CastAttribute, o as ModelFields } from '../Data-4c999fcd.js';
import { P as PropertyDecorator } from '../Contracts-dfee3653.js';
import { U as CastAttribute, m as ModelFields } from '../Data-aad5308e.js';
import { P as PropertyDecorator } from '../Contracts-560faa26.js';
import 'pinia';
import '@/composables';
import '@pinia-orm/normalizr';

@@ -6,0 +5,0 @@

@@ -1,5 +0,4 @@

import { X as CastAttribute, o as ModelFields } from '../Data-4c999fcd.js';
import { P as PropertyDecorator } from '../Contracts-dfee3653.js';
import { U as CastAttribute, m as ModelFields } from '../Data-aad5308e.js';
import { P as PropertyDecorator } from '../Contracts-560faa26.js';
import 'pinia';
import '@/composables';
import '@pinia-orm/normalizr';

@@ -6,0 +5,0 @@

@@ -1,5 +0,4 @@

import { X as CastAttribute, o as ModelFields } from '../Data-4c999fcd.js';
import { P as PropertyDecorator } from '../Contracts-dfee3653.js';
import { U as CastAttribute, m as ModelFields } from '../Data-aad5308e.js';
import { P as PropertyDecorator } from '../Contracts-560faa26.js';
import 'pinia';
import '@/composables';
import '@pinia-orm/normalizr';

@@ -6,0 +5,0 @@

@@ -1,5 +0,4 @@

import { X as CastAttribute, o as ModelFields } from '../Data-4c999fcd.js';
import { P as PropertyDecorator } from '../Contracts-dfee3653.js';
import { U as CastAttribute, m as ModelFields } from '../Data-aad5308e.js';
import { P as PropertyDecorator } from '../Contracts-560faa26.js';
import 'pinia';
import '@/composables';
import '@pinia-orm/normalizr';

@@ -6,0 +5,0 @@

@@ -1,5 +0,4 @@

import { X as CastAttribute, o as ModelFields } from '../Data-4c999fcd.js';
import { P as PropertyDecorator } from '../Contracts-dfee3653.js';
import { U as CastAttribute, m as ModelFields } from '../Data-aad5308e.js';
import { P as PropertyDecorator } from '../Contracts-560faa26.js';
import 'pinia';
import '@/composables';
import '@pinia-orm/normalizr';

@@ -6,0 +5,0 @@

{
"name": "pinia-orm",
"version": "1.3.0",
"version": "1.4.0",
"description": "The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.",

@@ -47,9 +47,9 @@ "keywords": [

"peerDependencies": {
"pinia": "^2.0.27"
"pinia": "^2.0.28"
},
"dependencies": {
"@pinia-orm/normalizr": ">=1.0.5"
"@pinia-orm/normalizr": ">=1.0.6"
},
"devDependencies": {
"@antfu/eslint-config": "^0.33.1",
"@antfu/eslint-config": "^0.34.0",
"@pinia/testing": "^0.0.14",

@@ -59,4 +59,4 @@ "@size-limit/preset-small-lib": "^8.1.0",

"@types/uuid": "^9.0.0",
"@vitest/coverage-c8": "^0.25.4",
"@vitest/ui": "^0.25.4",
"@vitest/coverage-c8": "^0.26.2",
"@vitest/ui": "^0.26.2",
"@vue/composition-api": "^1.7.1",

@@ -66,16 +66,16 @@ "@vue/test-utils": "^2.2.6",

"core-js": "^3.26.1",
"eslint": "^8.29.0",
"happy-dom": "^7.7.2",
"eslint": "^8.30.0",
"happy-dom": "^8.1.1",
"mkdist": "^1.0.0",
"nanoid": "^4.0.0",
"pinia": "^2.0.27",
"prettier": "^2.8.0",
"pinia": "^2.0.28",
"prettier": "^2.8.1",
"size-limit": "^8.1.0",
"std-env": "^3.3.1",
"tsup": "^6.5.0",
"typescript": "^4.9.3",
"unbuild": "^1.0.1",
"typescript": "^4.9.4",
"unbuild": "^1.0.2",
"uuid": "^9.0.0",
"vite": "^3.2.5",
"vitest": "^0.25.4",
"vite": "^4.0.3",
"vitest": "^0.26.2",
"vue": "^3.2.45",

@@ -88,3 +88,3 @@ "vue-demi": "^0.13.11",

"path": "dist/index.mjs",
"limit": "10 kB"
"limit": "11 kB"
},

@@ -122,3 +122,3 @@ {

"lint:fix": "eslint . --fix --ext .ts",
"test:ui": "vue-demi-switch 3 && vitest --ui",
"test:ui": "vue-demi-switch 3 && vitest --ui --api 9527",
"test:watch": "vue-demi-switch 3 && vitest --watch",

@@ -125,0 +125,0 @@ "test:2": "vue-demi-switch 2 vue2 && vitest --run",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc