@websolutespa/bom-core 1.7.9 → 1.7.11

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/CHANGELOG.md CHANGED
@@ -1,11 +1,24 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 1.7.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: JsonService where clauses, limit, sort
8
+ - Added: JsonService tests
9
+
10
+ ## 1.7.10
11
+
12
+ ### Patch Changes
13
+
14
+ - Fixing: getProto
15
+
3
16
  ## 1.7.9
4
17
 
5
18
  ### Patch Changes
6
19
 
7
20
  - Added: asSortedOptions
8
- - Modified: type guards
21
+ - Modified: type guards
9
22
 
10
23
  ## 1.7.8
11
24
 
package/dist/index.d.ts CHANGED
@@ -497,7 +497,22 @@ type IPaginationResult<T> = {
497
497
  docs: T[];
498
498
  } & Pagination;
499
499
 
500
- type Operator = 'equals' | 'contains' | 'not_equals' | 'in' | 'not_in' | 'exists' | 'greater_than' | 'greater_than_equal' | 'less_than' | 'less_than_equal' | 'like' | 'near';
500
+ /**
501
+ equals The value must be exactly equal.
502
+ not_equals The query will return all documents where the value is not equal.
503
+ exists Only return documents where the value either exists (true) or does not exist (false).
504
+ greater_than For numeric or date-based fields.
505
+ greater_than_equal For numeric or date-based fields.
506
+ less_than For numeric or date-based fields.
507
+ less_than_equal For numeric or date-based fields.
508
+ like Case-insensitive string must be present. If string of words, all words must be present, in any order.
509
+ contains Must contain the value entered, case-insensitive.
510
+ in The value must be found within the provided comma-delimited list of values.
511
+ not_in The value must NOT be within the provided comma-delimited list of values.
512
+ all The value must contain all values provided in the comma-delimited list.
513
+ near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
514
+ */
515
+ type Operator = 'equals' | 'not_equals' | 'exists' | 'greater_than' | 'greater_than_equal' | 'less_than' | 'less_than_equal' | 'like' | 'contains' | 'in' | 'not_in' | 'all' | 'near';
501
516
  type WhereField = {
502
517
  [key in Operator]?: unknown;
503
518
  };
@@ -636,31 +651,38 @@ declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
636
651
  protected decorateOne_<B extends T = T>(item: B, params?: QueryParams): Promise<B>;
637
652
  protected decorateMany_<B extends T = T>(items: B[], params?: QueryParams): Promise<B[]>;
638
653
  protected newUUID_(): number;
639
- protected evaluateValue_(value: unknown): unknown;
640
- /**
641
- equals The value must be exactly equal.
642
- not_equals The query will return all documents where the value is not equal.
643
- greater_than For numeric or date-based fields.
644
- greater_than_equal For numeric or date-based fields.
645
- less_than For numeric or date-based fields.
646
- less_than_equal For numeric or date-based fields.
647
- like Case-insensitive string must be present. If string of words, all words must be present, in any order.
648
- contains Must contain the value entered, case-insensitive.
649
- in The value must be found within the provided comma-delimited list of values.
650
- not_in The value must NOT be within the provided comma-delimited list of values.
651
- all The value must contain all values provided in the comma-delimited list.
652
- exists Only return documents where the value either exists (true) or does not exist (false).
653
- near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
654
- */
655
- protected existsClause_(value: unknown, exists?: boolean): boolean;
656
654
  protected equalsClause_(value: unknown, equals?: unknown): boolean;
657
- protected inClause_(value: unknown, values?: unknown[]): boolean;
658
- protected notInClause_(value: unknown, values?: unknown[]): boolean;
655
+ protected notEqualsClause_(value: unknown, not_equals?: unknown): boolean;
656
+ protected existsClause_(value: unknown, exists?: boolean): boolean;
657
+ protected greaterThanClause_(value: unknown, greater_than?: unknown): boolean;
658
+ protected greaterThanEqualClause_(value: unknown, greater_than_equal?: unknown): boolean;
659
+ protected lessThanClause_(value: unknown, less_than?: unknown): boolean;
660
+ protected lessThanEqualClause_(value: unknown, less_than_equal?: unknown): boolean;
659
661
  protected likeClause_(value: unknown, query?: string): boolean;
660
662
  protected containsClause_(value: unknown, contains?: IEquatable): boolean;
663
+ protected inClause_(value: unknown, values?: unknown[]): boolean;
664
+ protected notInClause_(value: unknown, values?: unknown[]): boolean;
665
+ protected allClause_(value: unknown, values?: unknown[]): boolean;
666
+ protected nearClause_(value: unknown, near?: unknown[]): boolean;
661
667
  protected whereItem_<B extends T = T>(item: B, where?: Where): boolean;
662
- protected whereItems_<B extends T = T>(items: B[], where?: Where): B[];
668
+ /**
669
+ equals The value must be exactly equal.
670
+ not_equals The query will return all documents where the value is not equal.
671
+ exists Only return documents where the value either exists (true) or does not exist (false).
672
+ greater_than For numeric or date-based fields.
673
+ greater_than_equal For numeric or date-based fields.
674
+ less_than For numeric or date-based fields.
675
+ less_than_equal For numeric or date-based fields.
676
+ like Case-insensitive string must be present. If string of words, all words must be present, in any order.
677
+ contains Must contain the value entered, case-insensitive.
678
+ in The value must be found within the provided comma-delimited list of values.
679
+ not_in The value must NOT be within the provided comma-delimited list of values.
680
+ all The value must contain all values provided in the comma-delimited list.
681
+ near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
682
+ */
683
+ protected whereItems_<B extends T = T>(items: B[], where?: Where, limit?: number): B[];
663
684
  protected sortCollection_<B extends T = T>(items: B[], sort?: string): B[];
685
+ protected limitCollection_<B extends T = T>(items: B[], limit?: number): B[];
664
686
  protected paginatedItems_<B extends T = T>(items: B[], page?: number, limit?: number): ({
665
687
  docs: B[];
666
688
  } & Pagination);
package/dist/index.js CHANGED
@@ -636,11 +636,14 @@ var JsonService = class {
636
636
  params.pagination = false;
637
637
  let items = await this.getItems();
638
638
  if (params.where) {
639
- items = this.whereItems_(items, params.where);
639
+ items = this.whereItems_(items, params.where, params.limit);
640
640
  }
641
641
  if (params.sort) {
642
642
  items = this.sortCollection_(items, params.sort);
643
643
  }
644
+ if (params.limit && !params.where) {
645
+ items = this.limitCollection_(items, params.limit);
646
+ }
644
647
  return await this.decorateMany_(items, params);
645
648
  }
646
649
  async findPaged(params = {}) {
@@ -700,49 +703,45 @@ var JsonService = class {
700
703
  return (/* @__PURE__ */ new Date()).getTime();
701
704
  }
702
705
  // where
703
- evaluateValue_(value) {
704
- if (typeof value === "object" && value) {
705
- return value.id;
706
- } else {
707
- return value;
706
+ equalsClause_(value, equals) {
707
+ if (typeof equals !== "undefined") {
708
+ return value === equals;
708
709
  }
710
+ return true;
711
+ }
712
+ notEqualsClause_(value, not_equals) {
713
+ if (typeof not_equals !== "undefined") {
714
+ return value != not_equals;
715
+ }
716
+ return true;
709
717
  }
710
- /**
711
- equals The value must be exactly equal.
712
- not_equals The query will return all documents where the value is not equal.
713
- greater_than For numeric or date-based fields.
714
- greater_than_equal For numeric or date-based fields.
715
- less_than For numeric or date-based fields.
716
- less_than_equal For numeric or date-based fields.
717
- like Case-insensitive string must be present. If string of words, all words must be present, in any order.
718
- contains Must contain the value entered, case-insensitive.
719
- in The value must be found within the provided comma-delimited list of values.
720
- not_in The value must NOT be within the provided comma-delimited list of values.
721
- all The value must contain all values provided in the comma-delimited list.
722
- exists Only return documents where the value either exists (true) or does not exist (false).
723
- near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
724
- */
725
718
  existsClause_(value, exists) {
726
719
  if (typeof exists === "boolean") {
727
720
  return value != null === exists;
728
721
  }
729
722
  return true;
730
723
  }
731
- equalsClause_(value, equals) {
732
- if (typeof equals !== "undefined") {
733
- return this.evaluateValue_(value) === equals;
724
+ greaterThanClause_(value, greater_than) {
725
+ if (typeof greater_than === "number") {
726
+ return typeof value === "number" && value > greater_than;
734
727
  }
735
728
  return true;
736
729
  }
737
- inClause_(value, values) {
738
- if (Array.isArray(values)) {
739
- return values.indexOf(this.evaluateValue_(value)) !== -1;
730
+ greaterThanEqualClause_(value, greater_than_equal) {
731
+ if (typeof greater_than_equal === "number") {
732
+ return typeof value === "number" && value >= greater_than_equal;
740
733
  }
741
734
  return true;
742
735
  }
743
- notInClause_(value, values) {
744
- if (Array.isArray(values)) {
745
- return values.indexOf(this.evaluateValue_(value)) === -1;
736
+ lessThanClause_(value, less_than) {
737
+ if (typeof less_than === "number") {
738
+ return typeof value === "number" && value < less_than;
739
+ }
740
+ return true;
741
+ }
742
+ lessThanEqualClause_(value, less_than_equal) {
743
+ if (typeof less_than_equal === "number") {
744
+ return typeof value === "number" && value <= less_than_equal;
746
745
  }
747
746
  return true;
748
747
  }
@@ -765,6 +764,49 @@ var JsonService = class {
765
764
  }
766
765
  return true;
767
766
  }
767
+ inClause_(value, values) {
768
+ if (Array.isArray(values) && values.length > 0) {
769
+ return values.indexOf(value) !== -1;
770
+ }
771
+ return true;
772
+ }
773
+ notInClause_(value, values) {
774
+ if (Array.isArray(values) && values.length > 0) {
775
+ return values.indexOf(value) === -1;
776
+ }
777
+ return true;
778
+ }
779
+ allClause_(value, values) {
780
+ if (Array.isArray(values) && values.length > 0) {
781
+ return Array.isArray(value) ? values.reduce((p, c) => p && value.includes(c), true) : false;
782
+ }
783
+ return true;
784
+ }
785
+ nearClause_(value, near) {
786
+ if (Array.isArray(near) && near.reduce((p, c) => p && typeof c === "number", true)) {
787
+ if (!Array.isArray(value)) {
788
+ return false;
789
+ }
790
+ const itemLongitude = value[0];
791
+ if (typeof itemLongitude !== "number") {
792
+ return false;
793
+ }
794
+ const itemLatitude = value[1];
795
+ if (typeof itemLatitude !== "number") {
796
+ return false;
797
+ }
798
+ const [longitude, latitude, maxDistance, minDistance] = near;
799
+ const distance = calculateDistanceInMeters_(itemLongitude, itemLatitude, longitude, latitude);
800
+ if (typeof maxDistance === "number" && typeof minDistance === "number") {
801
+ return distance <= maxDistance && distance >= minDistance;
802
+ } else if (typeof maxDistance === "number") {
803
+ return distance <= maxDistance;
804
+ } else if (typeof minDistance === "number") {
805
+ return distance >= minDistance;
806
+ }
807
+ }
808
+ return true;
809
+ }
768
810
  whereItem_(item, where) {
769
811
  let has = true;
770
812
  if (typeof where === "object") {
@@ -787,22 +829,53 @@ var JsonService = class {
787
829
  default:
788
830
  if (Array.isArray(v)) {
789
831
  } else if (typeof v === "object") {
790
- const value = item[k];
791
- has = has && this.existsClause_(value, v.exists);
832
+ const value = getValue(item, k);
792
833
  has = has && this.equalsClause_(value, v.equals);
793
- has = has && this.inClause_(value, v.in);
794
- has = has && this.notInClause_(value, v.not_in);
834
+ has = has && this.notEqualsClause_(value, v.not_equals);
835
+ has = has && this.existsClause_(value, v.exists);
836
+ has = has && this.greaterThanClause_(value, v.greater_than);
837
+ has = has && this.greaterThanEqualClause_(value, v.greater_than_equal);
838
+ has = has && this.lessThanClause_(value, v.less_than);
839
+ has = has && this.lessThanEqualClause_(value, v.less_than_equal);
795
840
  has = has && this.likeClause_(value, v.like);
796
841
  has = has && this.containsClause_(value, v.contains);
842
+ has = has && this.inClause_(value, v.in);
843
+ has = has && this.notInClause_(value, v.not_in);
844
+ has = has && this.allClause_(value, v.all);
845
+ has = has && this.nearClause_(value, v.near);
797
846
  }
798
847
  }
799
848
  });
800
849
  }
801
850
  return has;
802
851
  }
803
- whereItems_(items, where) {
852
+ /**
853
+ equals The value must be exactly equal.
854
+ not_equals The query will return all documents where the value is not equal.
855
+ exists Only return documents where the value either exists (true) or does not exist (false).
856
+ greater_than For numeric or date-based fields.
857
+ greater_than_equal For numeric or date-based fields.
858
+ less_than For numeric or date-based fields.
859
+ less_than_equal For numeric or date-based fields.
860
+ like Case-insensitive string must be present. If string of words, all words must be present, in any order.
861
+ contains Must contain the value entered, case-insensitive.
862
+ in The value must be found within the provided comma-delimited list of values.
863
+ not_in The value must NOT be within the provided comma-delimited list of values.
864
+ all The value must contain all values provided in the comma-delimited list.
865
+ near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
866
+ */
867
+ whereItems_(items, where, limit = -1) {
804
868
  if (typeof where === "object") {
805
- items = items.filter((item) => this.whereItem_(item, where));
869
+ const whereItems = [];
870
+ for (const item of items) {
871
+ if (limit > -1 && whereItems.length >= limit) {
872
+ return whereItems;
873
+ }
874
+ if (this.whereItem_(item, where)) {
875
+ whereItems.push(item);
876
+ }
877
+ }
878
+ return whereItems;
806
879
  }
807
880
  return items;
808
881
  }
@@ -828,14 +901,12 @@ var JsonService = class {
828
901
  }
829
902
  // ^ sort
830
903
  // limit
831
- /*
832
- protected limitCollection_<B extends T = T>(items: B[], limit?: number): B[] {
904
+ limitCollection_(items, limit) {
833
905
  if (limit) {
834
906
  items = items.slice(0, Math.min(limit, items.length));
835
907
  }
836
908
  return items;
837
909
  }
838
- */
839
910
  // ^ limit
840
911
  // pagination
841
912
  paginatedItems_(items, page = 1, limit = 10) {
@@ -865,6 +936,29 @@ var JsonService = class {
865
936
  }
866
937
  // ^ sort
867
938
  };
939
+ function getValue(item, key) {
940
+ const keys = key.split(".");
941
+ const value = keys.reduce((p, c) => {
942
+ if (isObject(p)) {
943
+ return p[c];
944
+ } else {
945
+ return void 0;
946
+ }
947
+ }, item);
948
+ return value;
949
+ }
950
+ function calculateDistanceInMeters_(lon1, lat1, lon2, lat2) {
951
+ const R = 6371;
952
+ const dLat = deg2rad_(lat2 - lat1);
953
+ const dLon = deg2rad_(lon2 - lon1);
954
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(deg2rad_(lat1)) * Math.cos(deg2rad_(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
955
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
956
+ const distance = R * c * 1e3;
957
+ return distance;
958
+ }
959
+ function deg2rad_(deg) {
960
+ return deg * (Math.PI / 180);
961
+ }
868
962
 
869
963
  // src/locale/locale.ts
870
964
  function getDefaultLocale() {
@@ -1101,17 +1195,17 @@ function getHost(headers) {
1101
1195
  }
1102
1196
  function getProto(headers) {
1103
1197
  if (isIncomingHttpHeaders(headers)) {
1104
- return headers["x-forwarded-proto"] || "https://";
1198
+ return headers["x-forwarded-proto"] || "https";
1105
1199
  } else if (isHeaders(headers)) {
1106
- return headers.get("X-Forwarded-Proto") || "https://";
1200
+ return headers.get("X-Forwarded-Proto") || "https";
1107
1201
  } else {
1108
- return "https://";
1202
+ return "https";
1109
1203
  }
1110
1204
  }
1111
1205
  function getOrigin(headers) {
1112
1206
  const host = getHost(headers);
1113
1207
  if (host) {
1114
- return host.indexOf("localhost") !== -1 ? "http://" + host : getProto(headers) + host;
1208
+ return host.indexOf("localhost") !== -1 ? "http://" + host : getProto(headers) + "://" + host;
1115
1209
  } else {
1116
1210
  return process.env.NEXT_PUBLIC_URL || "";
1117
1211
  }
package/dist/index.mjs CHANGED
@@ -503,11 +503,14 @@ var JsonService = class {
503
503
  params.pagination = false;
504
504
  let items = await this.getItems();
505
505
  if (params.where) {
506
- items = this.whereItems_(items, params.where);
506
+ items = this.whereItems_(items, params.where, params.limit);
507
507
  }
508
508
  if (params.sort) {
509
509
  items = this.sortCollection_(items, params.sort);
510
510
  }
511
+ if (params.limit && !params.where) {
512
+ items = this.limitCollection_(items, params.limit);
513
+ }
511
514
  return await this.decorateMany_(items, params);
512
515
  }
513
516
  async findPaged(params = {}) {
@@ -567,49 +570,45 @@ var JsonService = class {
567
570
  return (/* @__PURE__ */ new Date()).getTime();
568
571
  }
569
572
  // where
570
- evaluateValue_(value) {
571
- if (typeof value === "object" && value) {
572
- return value.id;
573
- } else {
574
- return value;
573
+ equalsClause_(value, equals) {
574
+ if (typeof equals !== "undefined") {
575
+ return value === equals;
575
576
  }
577
+ return true;
578
+ }
579
+ notEqualsClause_(value, not_equals) {
580
+ if (typeof not_equals !== "undefined") {
581
+ return value != not_equals;
582
+ }
583
+ return true;
576
584
  }
577
- /**
578
- equals The value must be exactly equal.
579
- not_equals The query will return all documents where the value is not equal.
580
- greater_than For numeric or date-based fields.
581
- greater_than_equal For numeric or date-based fields.
582
- less_than For numeric or date-based fields.
583
- less_than_equal For numeric or date-based fields.
584
- like Case-insensitive string must be present. If string of words, all words must be present, in any order.
585
- contains Must contain the value entered, case-insensitive.
586
- in The value must be found within the provided comma-delimited list of values.
587
- not_in The value must NOT be within the provided comma-delimited list of values.
588
- all The value must contain all values provided in the comma-delimited list.
589
- exists Only return documents where the value either exists (true) or does not exist (false).
590
- near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
591
- */
592
585
  existsClause_(value, exists) {
593
586
  if (typeof exists === "boolean") {
594
587
  return value != null === exists;
595
588
  }
596
589
  return true;
597
590
  }
598
- equalsClause_(value, equals) {
599
- if (typeof equals !== "undefined") {
600
- return this.evaluateValue_(value) === equals;
591
+ greaterThanClause_(value, greater_than) {
592
+ if (typeof greater_than === "number") {
593
+ return typeof value === "number" && value > greater_than;
601
594
  }
602
595
  return true;
603
596
  }
604
- inClause_(value, values) {
605
- if (Array.isArray(values)) {
606
- return values.indexOf(this.evaluateValue_(value)) !== -1;
597
+ greaterThanEqualClause_(value, greater_than_equal) {
598
+ if (typeof greater_than_equal === "number") {
599
+ return typeof value === "number" && value >= greater_than_equal;
607
600
  }
608
601
  return true;
609
602
  }
610
- notInClause_(value, values) {
611
- if (Array.isArray(values)) {
612
- return values.indexOf(this.evaluateValue_(value)) === -1;
603
+ lessThanClause_(value, less_than) {
604
+ if (typeof less_than === "number") {
605
+ return typeof value === "number" && value < less_than;
606
+ }
607
+ return true;
608
+ }
609
+ lessThanEqualClause_(value, less_than_equal) {
610
+ if (typeof less_than_equal === "number") {
611
+ return typeof value === "number" && value <= less_than_equal;
613
612
  }
614
613
  return true;
615
614
  }
@@ -632,6 +631,49 @@ var JsonService = class {
632
631
  }
633
632
  return true;
634
633
  }
634
+ inClause_(value, values) {
635
+ if (Array.isArray(values) && values.length > 0) {
636
+ return values.indexOf(value) !== -1;
637
+ }
638
+ return true;
639
+ }
640
+ notInClause_(value, values) {
641
+ if (Array.isArray(values) && values.length > 0) {
642
+ return values.indexOf(value) === -1;
643
+ }
644
+ return true;
645
+ }
646
+ allClause_(value, values) {
647
+ if (Array.isArray(values) && values.length > 0) {
648
+ return Array.isArray(value) ? values.reduce((p, c) => p && value.includes(c), true) : false;
649
+ }
650
+ return true;
651
+ }
652
+ nearClause_(value, near) {
653
+ if (Array.isArray(near) && near.reduce((p, c) => p && typeof c === "number", true)) {
654
+ if (!Array.isArray(value)) {
655
+ return false;
656
+ }
657
+ const itemLongitude = value[0];
658
+ if (typeof itemLongitude !== "number") {
659
+ return false;
660
+ }
661
+ const itemLatitude = value[1];
662
+ if (typeof itemLatitude !== "number") {
663
+ return false;
664
+ }
665
+ const [longitude, latitude, maxDistance, minDistance] = near;
666
+ const distance = calculateDistanceInMeters_(itemLongitude, itemLatitude, longitude, latitude);
667
+ if (typeof maxDistance === "number" && typeof minDistance === "number") {
668
+ return distance <= maxDistance && distance >= minDistance;
669
+ } else if (typeof maxDistance === "number") {
670
+ return distance <= maxDistance;
671
+ } else if (typeof minDistance === "number") {
672
+ return distance >= minDistance;
673
+ }
674
+ }
675
+ return true;
676
+ }
635
677
  whereItem_(item, where) {
636
678
  let has = true;
637
679
  if (typeof where === "object") {
@@ -654,22 +696,53 @@ var JsonService = class {
654
696
  default:
655
697
  if (Array.isArray(v)) {
656
698
  } else if (typeof v === "object") {
657
- const value = item[k];
658
- has = has && this.existsClause_(value, v.exists);
699
+ const value = getValue(item, k);
659
700
  has = has && this.equalsClause_(value, v.equals);
660
- has = has && this.inClause_(value, v.in);
661
- has = has && this.notInClause_(value, v.not_in);
701
+ has = has && this.notEqualsClause_(value, v.not_equals);
702
+ has = has && this.existsClause_(value, v.exists);
703
+ has = has && this.greaterThanClause_(value, v.greater_than);
704
+ has = has && this.greaterThanEqualClause_(value, v.greater_than_equal);
705
+ has = has && this.lessThanClause_(value, v.less_than);
706
+ has = has && this.lessThanEqualClause_(value, v.less_than_equal);
662
707
  has = has && this.likeClause_(value, v.like);
663
708
  has = has && this.containsClause_(value, v.contains);
709
+ has = has && this.inClause_(value, v.in);
710
+ has = has && this.notInClause_(value, v.not_in);
711
+ has = has && this.allClause_(value, v.all);
712
+ has = has && this.nearClause_(value, v.near);
664
713
  }
665
714
  }
666
715
  });
667
716
  }
668
717
  return has;
669
718
  }
670
- whereItems_(items, where) {
719
+ /**
720
+ equals The value must be exactly equal.
721
+ not_equals The query will return all documents where the value is not equal.
722
+ exists Only return documents where the value either exists (true) or does not exist (false).
723
+ greater_than For numeric or date-based fields.
724
+ greater_than_equal For numeric or date-based fields.
725
+ less_than For numeric or date-based fields.
726
+ less_than_equal For numeric or date-based fields.
727
+ like Case-insensitive string must be present. If string of words, all words must be present, in any order.
728
+ contains Must contain the value entered, case-insensitive.
729
+ in The value must be found within the provided comma-delimited list of values.
730
+ not_in The value must NOT be within the provided comma-delimited list of values.
731
+ all The value must contain all values provided in the comma-delimited list.
732
+ near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
733
+ */
734
+ whereItems_(items, where, limit = -1) {
671
735
  if (typeof where === "object") {
672
- items = items.filter((item) => this.whereItem_(item, where));
736
+ const whereItems = [];
737
+ for (const item of items) {
738
+ if (limit > -1 && whereItems.length >= limit) {
739
+ return whereItems;
740
+ }
741
+ if (this.whereItem_(item, where)) {
742
+ whereItems.push(item);
743
+ }
744
+ }
745
+ return whereItems;
673
746
  }
674
747
  return items;
675
748
  }
@@ -695,14 +768,12 @@ var JsonService = class {
695
768
  }
696
769
  // ^ sort
697
770
  // limit
698
- /*
699
- protected limitCollection_<B extends T = T>(items: B[], limit?: number): B[] {
771
+ limitCollection_(items, limit) {
700
772
  if (limit) {
701
773
  items = items.slice(0, Math.min(limit, items.length));
702
774
  }
703
775
  return items;
704
776
  }
705
- */
706
777
  // ^ limit
707
778
  // pagination
708
779
  paginatedItems_(items, page = 1, limit = 10) {
@@ -732,6 +803,29 @@ var JsonService = class {
732
803
  }
733
804
  // ^ sort
734
805
  };
806
+ function getValue(item, key) {
807
+ const keys = key.split(".");
808
+ const value = keys.reduce((p, c) => {
809
+ if (isObject(p)) {
810
+ return p[c];
811
+ } else {
812
+ return void 0;
813
+ }
814
+ }, item);
815
+ return value;
816
+ }
817
+ function calculateDistanceInMeters_(lon1, lat1, lon2, lat2) {
818
+ const R = 6371;
819
+ const dLat = deg2rad_(lat2 - lat1);
820
+ const dLon = deg2rad_(lon2 - lon1);
821
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(deg2rad_(lat1)) * Math.cos(deg2rad_(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
822
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
823
+ const distance = R * c * 1e3;
824
+ return distance;
825
+ }
826
+ function deg2rad_(deg) {
827
+ return deg * (Math.PI / 180);
828
+ }
735
829
 
736
830
  // src/locale/locale.ts
737
831
  function getDefaultLocale() {
@@ -968,17 +1062,17 @@ function getHost(headers) {
968
1062
  }
969
1063
  function getProto(headers) {
970
1064
  if (isIncomingHttpHeaders(headers)) {
971
- return headers["x-forwarded-proto"] || "https://";
1065
+ return headers["x-forwarded-proto"] || "https";
972
1066
  } else if (isHeaders(headers)) {
973
- return headers.get("X-Forwarded-Proto") || "https://";
1067
+ return headers.get("X-Forwarded-Proto") || "https";
974
1068
  } else {
975
- return "https://";
1069
+ return "https";
976
1070
  }
977
1071
  }
978
1072
  function getOrigin(headers) {
979
1073
  const host = getHost(headers);
980
1074
  if (host) {
981
- return host.indexOf("localhost") !== -1 ? "http://" + host : getProto(headers) + host;
1075
+ return host.indexOf("localhost") !== -1 ? "http://" + host : getProto(headers) + "://" + host;
982
1076
  } else {
983
1077
  return process.env.NEXT_PUBLIC_URL || "";
984
1078
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "1.7.9",
3
+ "version": "1.7.11",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "lint": "eslint *.ts*",
17
17
  "test": "jest",
18
- "test-watch": "npm test -- --watch",
18
+ "test-watch": "npm test -- --watch --silent=false",
19
19
  "coverage:integration": "npm run test -- --coverage",
20
20
  "coverage": "run-s -c --silent coverage:*",
21
21
  "compile": "tsup ./src/index.ts --format esm,cjs --dts --external react",