pinia-orm-edge 1.8.1-28576565.35880c8 → 1.9.0-28577552.61d8fc3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/helpers.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const Utils = require('./shared/pinia-orm.2be56be4.cjs');
3
+ const Utils = require('./shared/pinia-orm.9bb2aea1.cjs');
4
4
 
5
5
  function useSum(models, field) {
6
6
  return models.reduce((sum, item) => {
package/dist/helpers.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { k as getValue, o as orderBy } from './shared/pinia-orm.000eebbf.mjs';
1
+ import { k as getValue, o as orderBy } from './shared/pinia-orm.07af123e.mjs';
2
2
 
3
3
  function useSum(models, field) {
4
4
  return models.reduce((sum, item) => {
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const Utils = require('./shared/pinia-orm.2be56be4.cjs');
3
+ const Utils = require('./shared/pinia-orm.9bb2aea1.cjs');
4
4
  const pinia = require('pinia');
5
5
  const normalizr = require('@pinia-orm/normalizr');
6
6
  const CastAttribute = require('./shared/pinia-orm.a7e3e0f3.cjs');
@@ -667,11 +667,12 @@ class BelongsToMany extends Relation {
667
667
  const relationResults = [];
668
668
  relatedModels.forEach((relatedModel) => {
669
669
  const pivot = pivotModels[`[${parentModel[this.parentKey]},${relatedModel[this.relatedKey]}]`]?.[0] ?? null;
670
+ if (!pivot) {
671
+ return;
672
+ }
670
673
  const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson());
671
674
  relatedModelCopy.$setRelation("pivot", pivot);
672
- if (pivot) {
673
- relationResults.push(relatedModelCopy);
674
- }
675
+ relationResults.push(relatedModelCopy);
675
676
  });
676
677
  parentModel.$setRelation(relation, relationResults);
677
678
  });
@@ -1050,10 +1051,17 @@ class Query {
1050
1051
  if (this.model.$entity() !== this.model.$baseEntity()) {
1051
1052
  this.where(this.model.$typeKey(), this.model.$fields()[this.model.$typeKey()].make());
1052
1053
  }
1053
- const models = this.select();
1054
+ let models = this.select();
1055
+ if (!this.orders) {
1056
+ models = this.filterLimit(models);
1057
+ }
1054
1058
  if (!Utils.isEmpty(models)) {
1055
1059
  this.eagerLoadRelations(models);
1056
1060
  }
1061
+ if (this.orders) {
1062
+ models = this.filterOrder(models);
1063
+ models = this.filterLimit(models);
1064
+ }
1057
1065
  if (triggerHook) {
1058
1066
  models.forEach((model) => model.$self().retrieved(model));
1059
1067
  }
@@ -1087,8 +1095,6 @@ class Query {
1087
1095
  }
1088
1096
  let models = this.storeFind(ids);
1089
1097
  models = this.filterWhere(models);
1090
- models = this.filterOrder(models);
1091
- models = this.filterLimit(models);
1092
1098
  this.wheres = originalWheres;
1093
1099
  return models;
1094
1100
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as isArray, t as throwError, a as assert, g as generateId, b as isNullish, c as compareWithOperator, d as generateKey, e as isEmpty, f as isFunction, h as groupBy, o as orderBy, j as equals } from './shared/pinia-orm.000eebbf.mjs';
1
+ import { i as isArray, t as throwError, a as assert, g as generateId, b as isNullish, c as compareWithOperator, d as generateKey, e as isEmpty, f as isFunction, h as groupBy, o as orderBy, j as equals } from './shared/pinia-orm.07af123e.mjs';
2
2
  import { defineStore, acceptHMRUpdate } from 'pinia';
3
3
  import { schema, normalize } from '@pinia-orm/normalizr';
4
4
  export { C as CastAttribute } from './shared/pinia-orm.4ff2e12f.mjs';
@@ -665,11 +665,12 @@ class BelongsToMany extends Relation {
665
665
  const relationResults = [];
666
666
  relatedModels.forEach((relatedModel) => {
667
667
  const pivot = pivotModels[`[${parentModel[this.parentKey]},${relatedModel[this.relatedKey]}]`]?.[0] ?? null;
668
+ if (!pivot) {
669
+ return;
670
+ }
668
671
  const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson());
669
672
  relatedModelCopy.$setRelation("pivot", pivot);
670
- if (pivot) {
671
- relationResults.push(relatedModelCopy);
672
- }
673
+ relationResults.push(relatedModelCopy);
673
674
  });
674
675
  parentModel.$setRelation(relation, relationResults);
675
676
  });
@@ -1048,10 +1049,17 @@ class Query {
1048
1049
  if (this.model.$entity() !== this.model.$baseEntity()) {
1049
1050
  this.where(this.model.$typeKey(), this.model.$fields()[this.model.$typeKey()].make());
1050
1051
  }
1051
- const models = this.select();
1052
+ let models = this.select();
1053
+ if (!this.orders) {
1054
+ models = this.filterLimit(models);
1055
+ }
1052
1056
  if (!isEmpty(models)) {
1053
1057
  this.eagerLoadRelations(models);
1054
1058
  }
1059
+ if (this.orders) {
1060
+ models = this.filterOrder(models);
1061
+ models = this.filterLimit(models);
1062
+ }
1055
1063
  if (triggerHook) {
1056
1064
  models.forEach((model) => model.$self().retrieved(model));
1057
1065
  }
@@ -1085,8 +1093,6 @@ class Query {
1085
1093
  }
1086
1094
  let models = this.storeFind(ids);
1087
1095
  models = this.filterWhere(models);
1088
- models = this.filterOrder(models);
1089
- models = this.filterLimit(models);
1090
1096
  this.wheres = originalWheres;
1091
1097
  return models;
1092
1098
  }
@@ -35,7 +35,7 @@ function orderBy(collection, iteratees, directions, flags = "SORT_REGULAR") {
35
35
  let index = -1;
36
36
  const result = collection.map((value) => {
37
37
  const criteria = iteratees.map((iteratee) => {
38
- return typeof iteratee === "function" ? iteratee(value) : value[iteratee];
38
+ return typeof iteratee === "function" ? iteratee(value) : getValue(value, iteratee, false);
39
39
  });
40
40
  return { criteria, index: ++index, value };
41
41
  });
@@ -119,13 +119,13 @@ function generateKey(key, params) {
119
119
  const stringifiedKey = JSON.stringify(keyValues);
120
120
  return typeof process === "undefined" ? btoa(stringifiedKey) : stringifiedKey;
121
121
  }
122
- function getValue(obj, keys) {
122
+ function getValue(obj, keys, ifNotFoundReturnObject = true) {
123
123
  keys = typeof keys === "string" ? keys.split(".") : keys;
124
124
  const key = keys.shift();
125
125
  if (obj && Object.prototype.hasOwnProperty.call(obj, key) && keys.length === 0) {
126
126
  return obj[key];
127
127
  } else if (!obj || !Object.prototype.hasOwnProperty.call(obj, key)) {
128
- return obj;
128
+ return ifNotFoundReturnObject ? obj : void 0;
129
129
  } else {
130
130
  return getValue(obj[key], keys);
131
131
  }
@@ -37,7 +37,7 @@ function orderBy(collection, iteratees, directions, flags = "SORT_REGULAR") {
37
37
  let index = -1;
38
38
  const result = collection.map((value) => {
39
39
  const criteria = iteratees.map((iteratee) => {
40
- return typeof iteratee === "function" ? iteratee(value) : value[iteratee];
40
+ return typeof iteratee === "function" ? iteratee(value) : getValue(value, iteratee, false);
41
41
  });
42
42
  return { criteria, index: ++index, value };
43
43
  });
@@ -121,13 +121,13 @@ function generateKey(key, params) {
121
121
  const stringifiedKey = JSON.stringify(keyValues);
122
122
  return typeof process === "undefined" ? btoa(stringifiedKey) : stringifiedKey;
123
123
  }
124
- function getValue(obj, keys) {
124
+ function getValue(obj, keys, ifNotFoundReturnObject = true) {
125
125
  keys = typeof keys === "string" ? keys.split(".") : keys;
126
126
  const key = keys.shift();
127
127
  if (obj && Object.prototype.hasOwnProperty.call(obj, key) && keys.length === 0) {
128
128
  return obj[key];
129
129
  } else if (!obj || !Object.prototype.hasOwnProperty.call(obj, key)) {
130
- return obj;
130
+ return ifNotFoundReturnObject ? obj : void 0;
131
131
  } else {
132
132
  return getValue(obj[key], keys);
133
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinia-orm-edge",
3
- "version": "1.8.1-28576565.35880c8",
3
+ "version": "1.9.0-28577552.61d8fc3",
4
4
  "description": "The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.",
5
5
  "keywords": [
6
6
  "vue",
@@ -46,7 +46,7 @@
46
46
  "pinia": "^2.1.7"
47
47
  },
48
48
  "dependencies": {
49
- "@pinia-orm/normalizr": "npm:@pinia-orm/normalizr-edge@1.8.1-28576565.35880c8"
49
+ "@pinia-orm/normalizr": "npm:@pinia-orm/normalizr-edge@1.9.0-28577552.61d8fc3"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@nuxt/eslint-config": "^0.3.10",