@infrab4a/connect 4.9.7-beta.0 → 4.9.7-beta.1

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/index.cjs.js CHANGED
@@ -2862,7 +2862,7 @@ const withFindFirestore = (MixinBase) => {
2862
2862
  const req = { collection: collectionName, data: find };
2863
2863
  try {
2864
2864
  const intercepted = await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.call(_c, { find }));
2865
- const { filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
2865
+ const { fields, filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
2866
2866
  const queries = this.makeFirestoreWhere(filters || {});
2867
2867
  const ordination = this.makeFirestoreOrderBy(filters, orderBy);
2868
2868
  const offsets = await this.defineLimits(filters, limits);
@@ -2901,8 +2901,9 @@ const withFindFirestore = (MixinBase) => {
2901
2901
  .getDoc((_a = Object.values(limits.offset.identifier).shift()) === null || _a === void 0 ? void 0 : _a.toString())
2902
2902
  .get(),
2903
2903
  ]);
2904
- else if (lodash.isNumber(limits.offset) || lodash.isString(limits.offset))
2904
+ else if (lodash.isNumber(limits.offset) || lodash.isString(limits.offset)) {
2905
2905
  queries.push(['fromStartAt', limits.offset]);
2906
+ }
2906
2907
  }
2907
2908
  if (limits === null || limits === void 0 ? void 0 : limits.limit)
2908
2909
  queries.push(['limit', limits.limit]);
@@ -2986,7 +2987,7 @@ const withUpdateFirestore = (MixinBase) => {
2986
2987
  const req = { collection: collectionName, data };
2987
2988
  try {
2988
2989
  const identifiers = getValueFromParams(data, keyField);
2989
- const docRef = this.collection().getDoc(identifiers.toString());
2990
+ const docRef = this.collection(collectionName).getDoc(identifiers.toString());
2990
2991
  const plainFromData = this.model.toInstance(this.paramsToPlain(data));
2991
2992
  const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance: plainFromData }));
2992
2993
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
@@ -3727,19 +3728,21 @@ class ConnectCollectionService {
3727
3728
  return new ConnectDocumentService(newDoc.path, this.firestore).withConverter(this.converter);
3728
3729
  }
3729
3730
  async getDocs() {
3731
+ if (this.startingAt > 0)
3732
+ this.limitBy += this.startingAt;
3730
3733
  const constraints = [
3731
3734
  ...this.wheres,
3732
3735
  ...this.orderBys,
3733
- ...(this.limitBy ? [this.limitBy] : []),
3734
- ...(this.offsetBy ? [this.offsetBy] : []),
3735
- ...(this.statingAt ? [this.statingAt] : []),
3736
- ...(this.startingAfter ? [this.startingAfter] : []),
3736
+ ...(this.limitBy ? [firestore.limit(this.limitBy)] : []),
3737
3737
  ];
3738
- return firestore.getDocs(firestore.query(this.reference, ...constraints)).then((docs) => ({
3739
- empty: docs.empty,
3740
- size: docs.size,
3741
- docs: docs.docs.map((doc) => new ConnectBaseDocumentSnapshot(doc)),
3742
- }));
3738
+ return firestore.getDocs(firestore.query(this.reference, ...constraints)).then((docs) => {
3739
+ const docsPaginated = this.startingAt > 0 ? docs.docs.slice(this.startingAt, this.limitBy) : docs.docs;
3740
+ return {
3741
+ empty: Boolean(docsPaginated.length),
3742
+ size: docsPaginated.length,
3743
+ docs: docsPaginated.map((doc) => new ConnectBaseDocumentSnapshot(doc)),
3744
+ };
3745
+ });
3743
3746
  }
3744
3747
  getDoc(id) {
3745
3748
  return new ConnectDocumentService(`${this.reference.path}/${id}`, this.firestore).withConverter(this.converter);
@@ -3753,15 +3756,15 @@ class ConnectCollectionService {
3753
3756
  return this;
3754
3757
  }
3755
3758
  limit(quantity) {
3756
- this.limitBy = firestore.limit(quantity);
3759
+ this.limitBy = quantity;
3757
3760
  return this;
3758
3761
  }
3759
3762
  offset(offsetBy) {
3760
- this.offsetBy = firestore.startAfter(offsetBy);
3763
+ this.offsetBy = offsetBy;
3761
3764
  return this;
3762
3765
  }
3763
3766
  fromStartAt(startingAt) {
3764
- this.statingAt = firestore.startAt(startingAt);
3767
+ this.startingAt = startingAt;
3765
3768
  return this;
3766
3769
  }
3767
3770
  fromStartAfter(startingAt) {
package/index.esm.js CHANGED
@@ -9,7 +9,7 @@ import { debug } from 'debug';
9
9
  import { CustomError } from 'ts-custom-error';
10
10
  import axios from 'axios';
11
11
  import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, signInAnonymously, sendPasswordResetEmail, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth';
12
- import { deleteField, arrayUnion, arrayRemove, Timestamp, doc, getDoc, updateDoc, setDoc, deleteDoc, collection, getDocs, query, where, orderBy, limit, startAfter, startAt, addDoc } from 'firebase/firestore';
12
+ import { deleteField, arrayUnion, arrayRemove, Timestamp, doc, getDoc, updateDoc, setDoc, deleteDoc, collection, limit, getDocs, query, where, orderBy, startAfter, addDoc } from 'firebase/firestore';
13
13
  import { ref, uploadBytes } from 'firebase/storage';
14
14
  import { mutation, query as query$1 } from 'gql-query-builder';
15
15
 
@@ -2856,7 +2856,7 @@ const withFindFirestore = (MixinBase) => {
2856
2856
  const req = { collection: collectionName, data: find };
2857
2857
  try {
2858
2858
  const intercepted = await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.call(_c, { find }));
2859
- const { filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
2859
+ const { fields, filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
2860
2860
  const queries = this.makeFirestoreWhere(filters || {});
2861
2861
  const ordination = this.makeFirestoreOrderBy(filters, orderBy);
2862
2862
  const offsets = await this.defineLimits(filters, limits);
@@ -2895,8 +2895,9 @@ const withFindFirestore = (MixinBase) => {
2895
2895
  .getDoc((_a = Object.values(limits.offset.identifier).shift()) === null || _a === void 0 ? void 0 : _a.toString())
2896
2896
  .get(),
2897
2897
  ]);
2898
- else if (isNumber(limits.offset) || isString(limits.offset))
2898
+ else if (isNumber(limits.offset) || isString(limits.offset)) {
2899
2899
  queries.push(['fromStartAt', limits.offset]);
2900
+ }
2900
2901
  }
2901
2902
  if (limits === null || limits === void 0 ? void 0 : limits.limit)
2902
2903
  queries.push(['limit', limits.limit]);
@@ -2980,7 +2981,7 @@ const withUpdateFirestore = (MixinBase) => {
2980
2981
  const req = { collection: collectionName, data };
2981
2982
  try {
2982
2983
  const identifiers = getValueFromParams(data, keyField);
2983
- const docRef = this.collection().getDoc(identifiers.toString());
2984
+ const docRef = this.collection(collectionName).getDoc(identifiers.toString());
2984
2985
  const plainFromData = this.model.toInstance(this.paramsToPlain(data));
2985
2986
  const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance: plainFromData }));
2986
2987
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
@@ -3721,19 +3722,21 @@ class ConnectCollectionService {
3721
3722
  return new ConnectDocumentService(newDoc.path, this.firestore).withConverter(this.converter);
3722
3723
  }
3723
3724
  async getDocs() {
3725
+ if (this.startingAt > 0)
3726
+ this.limitBy += this.startingAt;
3724
3727
  const constraints = [
3725
3728
  ...this.wheres,
3726
3729
  ...this.orderBys,
3727
- ...(this.limitBy ? [this.limitBy] : []),
3728
- ...(this.offsetBy ? [this.offsetBy] : []),
3729
- ...(this.statingAt ? [this.statingAt] : []),
3730
- ...(this.startingAfter ? [this.startingAfter] : []),
3730
+ ...(this.limitBy ? [limit(this.limitBy)] : []),
3731
3731
  ];
3732
- return getDocs(query(this.reference, ...constraints)).then((docs) => ({
3733
- empty: docs.empty,
3734
- size: docs.size,
3735
- docs: docs.docs.map((doc) => new ConnectBaseDocumentSnapshot(doc)),
3736
- }));
3732
+ return getDocs(query(this.reference, ...constraints)).then((docs) => {
3733
+ const docsPaginated = this.startingAt > 0 ? docs.docs.slice(this.startingAt, this.limitBy) : docs.docs;
3734
+ return {
3735
+ empty: Boolean(docsPaginated.length),
3736
+ size: docsPaginated.length,
3737
+ docs: docsPaginated.map((doc) => new ConnectBaseDocumentSnapshot(doc)),
3738
+ };
3739
+ });
3737
3740
  }
3738
3741
  getDoc(id) {
3739
3742
  return new ConnectDocumentService(`${this.reference.path}/${id}`, this.firestore).withConverter(this.converter);
@@ -3747,15 +3750,15 @@ class ConnectCollectionService {
3747
3750
  return this;
3748
3751
  }
3749
3752
  limit(quantity) {
3750
- this.limitBy = limit(quantity);
3753
+ this.limitBy = quantity;
3751
3754
  return this;
3752
3755
  }
3753
3756
  offset(offsetBy) {
3754
- this.offsetBy = startAfter(offsetBy);
3757
+ this.offsetBy = offsetBy;
3755
3758
  return this;
3756
3759
  }
3757
3760
  fromStartAt(startingAt) {
3758
- this.statingAt = startAt(startingAt);
3761
+ this.startingAt = startingAt;
3759
3762
  return this;
3760
3763
  }
3761
3764
  fromStartAfter(startingAt) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.9.7-beta.0",
3
+ "version": "4.9.7-beta.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -9,12 +9,12 @@ export declare class ConnectCollectionService<T extends ConnectDocumentData> imp
9
9
  private orderBys;
10
10
  private limitBy;
11
11
  private offsetBy;
12
- private statingAt;
12
+ private startingAt;
13
13
  private startingAfter;
14
14
  private converter;
15
15
  constructor(path: string, firestore: Firestore);
16
16
  add(data: T, id?: string): Promise<ConnectDocumentReference<T>>;
17
- getDocs(): Promise<ConnectQuerySnapshot<T>>;
17
+ getDocs(): Promise<ConnectQuerySnapshot<T> | any>;
18
18
  getDoc(id?: string): ConnectDocumentReference<T>;
19
19
  where(attribute: string, operator: ConnectWhereOption, value: any): ConnectCollectionReference<T>;
20
20
  order(attribute: string, order: 'asc' | 'desc'): ConnectCollectionReference<T>;