pinia-orm-edge 1.9.2-28644224.417ef5c → 1.9.2-28661520.9747a33

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
@@ -66,4 +66,5 @@ exports.useKeys = useKeys;
66
66
  exports.useMax = useMax;
67
67
  exports.useMin = useMin;
68
68
  exports.usePluck = usePluck;
69
+ exports.useSortBy = useSortBy;
69
70
  exports.useSum = useSum;
@@ -6,6 +6,11 @@ import '@/composables';
6
6
  type SortFlags = 'SORT_REGULAR' | 'SORT_FLAG_CASE';
7
7
 
8
8
  type sorting<T> = ((record: T) => any) | string | [string, 'asc' | 'desc'][];
9
+ /**
10
+ * Creates an array of elements, sorted in specified order by the results
11
+ * of running each element in a collection thru each iteratee.
12
+ */
13
+ declare function useSortBy<T extends Record<string, any>>(collection: T[], sort: sorting<T>, flags?: SortFlags): T[];
9
14
 
10
15
  interface UseCollect<M extends Model = Model> {
11
16
  sum: (field: string) => number;
@@ -51,4 +56,4 @@ declare function useMax(models: Collection, field: string): number;
51
56
  */
52
57
  declare function usePluck(models: Collection, field: string): any[];
53
58
 
54
- export { type UseCollect, useCollect, useGroupBy, useKeys, useMax, useMin, usePluck, useSum };
59
+ export { type UseCollect, type sorting, useCollect, useGroupBy, useKeys, useMax, useMin, usePluck, useSortBy, useSum };
@@ -6,6 +6,11 @@ import '@/composables';
6
6
  type SortFlags = 'SORT_REGULAR' | 'SORT_FLAG_CASE';
7
7
 
8
8
  type sorting<T> = ((record: T) => any) | string | [string, 'asc' | 'desc'][];
9
+ /**
10
+ * Creates an array of elements, sorted in specified order by the results
11
+ * of running each element in a collection thru each iteratee.
12
+ */
13
+ declare function useSortBy<T extends Record<string, any>>(collection: T[], sort: sorting<T>, flags?: SortFlags): T[];
9
14
 
10
15
  interface UseCollect<M extends Model = Model> {
11
16
  sum: (field: string) => number;
@@ -51,4 +56,4 @@ declare function useMax(models: Collection, field: string): number;
51
56
  */
52
57
  declare function usePluck(models: Collection, field: string): any[];
53
58
 
54
- export { type UseCollect, useCollect, useGroupBy, useKeys, useMax, useMin, usePluck, useSum };
59
+ export { type UseCollect, type sorting, useCollect, useGroupBy, useKeys, useMax, useMin, usePluck, useSortBy, useSum };
package/dist/helpers.d.ts CHANGED
@@ -6,6 +6,11 @@ import '@/composables';
6
6
  type SortFlags = 'SORT_REGULAR' | 'SORT_FLAG_CASE';
7
7
 
8
8
  type sorting<T> = ((record: T) => any) | string | [string, 'asc' | 'desc'][];
9
+ /**
10
+ * Creates an array of elements, sorted in specified order by the results
11
+ * of running each element in a collection thru each iteratee.
12
+ */
13
+ declare function useSortBy<T extends Record<string, any>>(collection: T[], sort: sorting<T>, flags?: SortFlags): T[];
9
14
 
10
15
  interface UseCollect<M extends Model = Model> {
11
16
  sum: (field: string) => number;
@@ -51,4 +56,4 @@ declare function useMax(models: Collection, field: string): number;
51
56
  */
52
57
  declare function usePluck(models: Collection, field: string): any[];
53
58
 
54
- export { type UseCollect, useCollect, useGroupBy, useKeys, useMax, useMin, usePluck, useSum };
59
+ export { type UseCollect, type sorting, useCollect, useGroupBy, useKeys, useMax, useMin, usePluck, useSortBy, useSum };
package/dist/helpers.mjs CHANGED
@@ -58,4 +58,4 @@ function useCollect(models) {
58
58
  };
59
59
  }
60
60
 
61
- export { useCollect, useGroupBy, useKeys, useMax, useMin, usePluck, useSum };
61
+ export { useCollect, useGroupBy, useKeys, useMax, useMin, usePluck, useSortBy, useSum };
package/dist/index.cjs CHANGED
@@ -668,7 +668,7 @@ class BelongsToMany extends Relation {
668
668
  */
669
669
  match(relation, models, query) {
670
670
  const relatedModels = query.get(false);
671
- const pivotModels = query.newQuery(this.pivot.$entity()).whereIn(this.relatedPivotKey, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.foreignPivotKey, this.getKeys(models, this.parentKey)).groupBy(this.foreignPivotKey, this.relatedPivotKey).get();
671
+ const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedPivotKey, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.foreignPivotKey, this.getKeys(models, this.parentKey)).groupBy(this.foreignPivotKey, this.relatedPivotKey).get();
672
672
  models.forEach((parentModel) => {
673
673
  const relationResults = [];
674
674
  relatedModels.forEach((relatedModel) => {
@@ -2837,7 +2837,7 @@ class MorphToMany extends Relation {
2837
2837
  */
2838
2838
  match(relation, models, query) {
2839
2839
  const relatedModels = query.get(false);
2840
- const pivotModels = query.newQuery(this.pivot.$entity()).whereIn(this.relatedId, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.morphId, this.getKeys(models, this.parentKey)).groupBy(this.morphId, this.relatedId, this.morphType).get();
2840
+ const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedId, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.morphId, this.getKeys(models, this.parentKey)).groupBy(this.morphId, this.relatedId, this.morphType).get();
2841
2841
  models.forEach((parentModel) => {
2842
2842
  const relationResults = [];
2843
2843
  relatedModels.forEach((relatedModel) => {
@@ -3032,7 +3032,7 @@ class Model {
3032
3032
  const pivotInstance = pivot.newRawInstance();
3033
3033
  parentKey = parentKey ?? model.$getLocalKey();
3034
3034
  relatedKey = relatedKey ?? instance.$getLocalKey();
3035
- this.schemas[related.entity][`pivot_${relatedPivotKey}_${pivotInstance.$entity()}`] = new HasOne(instance, pivotInstance, relatedPivotKey, relatedKey);
3035
+ this.schemas[related.modelEntity()][`pivot_${relatedPivotKey}_${pivotInstance.$entity()}`] = new HasOne(instance, pivotInstance, relatedPivotKey, relatedKey);
3036
3036
  return new BelongsToMany(
3037
3037
  model,
3038
3038
  instance,
@@ -3052,7 +3052,7 @@ class Model {
3052
3052
  const pivotInstance = pivot.newRawInstance();
3053
3053
  parentKey = parentKey ?? model.$getLocalKey();
3054
3054
  relatedKey = relatedKey ?? instance.$getLocalKey();
3055
- this.schemas[related.entity][`pivot_${relatedId}_${pivotInstance.$entity()}`] = new MorphOne(instance, pivotInstance, relatedId, model.$entity(), relatedKey);
3055
+ this.schemas[related.modelEntity()][`pivot_${relatedId}_${pivotInstance.$entity()}`] = new MorphOne(instance, pivotInstance, relatedId, model.$entity(), relatedKey);
3056
3056
  return new MorphToMany(
3057
3057
  model,
3058
3058
  instance,
package/dist/index.mjs CHANGED
@@ -666,7 +666,7 @@ class BelongsToMany extends Relation {
666
666
  */
667
667
  match(relation, models, query) {
668
668
  const relatedModels = query.get(false);
669
- const pivotModels = query.newQuery(this.pivot.$entity()).whereIn(this.relatedPivotKey, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.foreignPivotKey, this.getKeys(models, this.parentKey)).groupBy(this.foreignPivotKey, this.relatedPivotKey).get();
669
+ const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedPivotKey, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.foreignPivotKey, this.getKeys(models, this.parentKey)).groupBy(this.foreignPivotKey, this.relatedPivotKey).get();
670
670
  models.forEach((parentModel) => {
671
671
  const relationResults = [];
672
672
  relatedModels.forEach((relatedModel) => {
@@ -2835,7 +2835,7 @@ class MorphToMany extends Relation {
2835
2835
  */
2836
2836
  match(relation, models, query) {
2837
2837
  const relatedModels = query.get(false);
2838
- const pivotModels = query.newQuery(this.pivot.$entity()).whereIn(this.relatedId, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.morphId, this.getKeys(models, this.parentKey)).groupBy(this.morphId, this.relatedId, this.morphType).get();
2838
+ const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedId, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.morphId, this.getKeys(models, this.parentKey)).groupBy(this.morphId, this.relatedId, this.morphType).get();
2839
2839
  models.forEach((parentModel) => {
2840
2840
  const relationResults = [];
2841
2841
  relatedModels.forEach((relatedModel) => {
@@ -3030,7 +3030,7 @@ class Model {
3030
3030
  const pivotInstance = pivot.newRawInstance();
3031
3031
  parentKey = parentKey ?? model.$getLocalKey();
3032
3032
  relatedKey = relatedKey ?? instance.$getLocalKey();
3033
- this.schemas[related.entity][`pivot_${relatedPivotKey}_${pivotInstance.$entity()}`] = new HasOne(instance, pivotInstance, relatedPivotKey, relatedKey);
3033
+ this.schemas[related.modelEntity()][`pivot_${relatedPivotKey}_${pivotInstance.$entity()}`] = new HasOne(instance, pivotInstance, relatedPivotKey, relatedKey);
3034
3034
  return new BelongsToMany(
3035
3035
  model,
3036
3036
  instance,
@@ -3050,7 +3050,7 @@ class Model {
3050
3050
  const pivotInstance = pivot.newRawInstance();
3051
3051
  parentKey = parentKey ?? model.$getLocalKey();
3052
3052
  relatedKey = relatedKey ?? instance.$getLocalKey();
3053
- this.schemas[related.entity][`pivot_${relatedId}_${pivotInstance.$entity()}`] = new MorphOne(instance, pivotInstance, relatedId, model.$entity(), relatedKey);
3053
+ this.schemas[related.modelEntity()][`pivot_${relatedId}_${pivotInstance.$entity()}`] = new MorphOne(instance, pivotInstance, relatedId, model.$entity(), relatedKey);
3054
3054
  return new MorphToMany(
3055
3055
  model,
3056
3056
  instance,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinia-orm-edge",
3
- "version": "1.9.2-28644224.417ef5c",
3
+ "version": "1.9.2-28661520.9747a33",
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.9.2-28644224.417ef5c"
49
+ "@pinia-orm/normalizr": "npm:@pinia-orm/normalizr-edge@1.9.2-28661520.9747a33"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@nuxt/eslint-config": "^0.3.13",