@infrab4a/connect 4.4.0-beta.6 → 4.4.0-beta.8

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
@@ -3650,7 +3650,10 @@ class ConnectDocumentService {
3650
3650
  await firestore.deleteDoc(this.reference);
3651
3651
  }
3652
3652
  withConverter(params) {
3653
- this.reference = this.reference.withConverter(params);
3653
+ this.reference = this.reference.withConverter({
3654
+ toFirestore: (data) => params.toFirestore(data),
3655
+ fromFirestore: (snapshot, options) => params.fromFirestore(snapshot, options),
3656
+ });
3654
3657
  return this;
3655
3658
  }
3656
3659
  }
@@ -3669,7 +3672,7 @@ class ConnectCollectionService {
3669
3672
  }
3670
3673
  async add(data, id) {
3671
3674
  const newDoc = await this.save(data, id);
3672
- return new ConnectDocumentService(newDoc.path, this.firestore);
3675
+ return new ConnectDocumentService(newDoc.path, this.firestore).withConverter(this.converter);
3673
3676
  }
3674
3677
  async getDocs() {
3675
3678
  const constraints = [
@@ -3683,7 +3686,7 @@ class ConnectCollectionService {
3683
3686
  return firestore.getDocs(firestore.query(this.reference, ...constraints));
3684
3687
  }
3685
3688
  getDoc(id) {
3686
- return new ConnectDocumentService(`${this.reference.path}/${id}`, this.firestore);
3689
+ return new ConnectDocumentService(`${this.reference.path}/${id}`, this.firestore).withConverter(this.converter);
3687
3690
  }
3688
3691
  where(attribute, operator, value) {
3689
3692
  this.wheres.push(firestore.where(attribute, operator, value));
@@ -3710,7 +3713,11 @@ class ConnectCollectionService {
3710
3713
  return this;
3711
3714
  }
3712
3715
  withConverter(params) {
3713
- this.reference = this.reference.withConverter(params);
3716
+ this.converter = {
3717
+ toFirestore: (data) => params.toFirestore(data),
3718
+ fromFirestore: (snapshot, options) => params.fromFirestore(snapshot, options),
3719
+ };
3720
+ this.reference = this.reference.withConverter(this.converter);
3714
3721
  return this;
3715
3722
  }
3716
3723
  async save(data, id) {
package/index.esm.js CHANGED
@@ -3626,7 +3626,10 @@ class ConnectDocumentService {
3626
3626
  await deleteDoc(this.reference);
3627
3627
  }
3628
3628
  withConverter(params) {
3629
- this.reference = this.reference.withConverter(params);
3629
+ this.reference = this.reference.withConverter({
3630
+ toFirestore: (data) => params.toFirestore(data),
3631
+ fromFirestore: (snapshot, options) => params.fromFirestore(snapshot, options),
3632
+ });
3630
3633
  return this;
3631
3634
  }
3632
3635
  }
@@ -3645,7 +3648,7 @@ class ConnectCollectionService {
3645
3648
  }
3646
3649
  async add(data, id) {
3647
3650
  const newDoc = await this.save(data, id);
3648
- return new ConnectDocumentService(newDoc.path, this.firestore);
3651
+ return new ConnectDocumentService(newDoc.path, this.firestore).withConverter(this.converter);
3649
3652
  }
3650
3653
  async getDocs() {
3651
3654
  const constraints = [
@@ -3659,7 +3662,7 @@ class ConnectCollectionService {
3659
3662
  return getDocs(query(this.reference, ...constraints));
3660
3663
  }
3661
3664
  getDoc(id) {
3662
- return new ConnectDocumentService(`${this.reference.path}/${id}`, this.firestore);
3665
+ return new ConnectDocumentService(`${this.reference.path}/${id}`, this.firestore).withConverter(this.converter);
3663
3666
  }
3664
3667
  where(attribute, operator, value) {
3665
3668
  this.wheres.push(where(attribute, operator, value));
@@ -3686,7 +3689,11 @@ class ConnectCollectionService {
3686
3689
  return this;
3687
3690
  }
3688
3691
  withConverter(params) {
3689
- this.reference = this.reference.withConverter(params);
3692
+ this.converter = {
3693
+ toFirestore: (data) => params.toFirestore(data),
3694
+ fromFirestore: (snapshot, options) => params.fromFirestore(snapshot, options),
3695
+ };
3696
+ this.reference = this.reference.withConverter(this.converter);
3690
3697
  return this;
3691
3698
  }
3692
3699
  async save(data, id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.4.0-beta.6",
3
+ "version": "4.4.0-beta.8",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -1,6 +1,6 @@
1
- import { ConnectQuerySnapshop, ConnectWhereOption } from '../types';
1
+ import { ConnectQuerySnapshot, ConnectWhereOption } from '../types';
2
2
  import { ConnectDocumentData } from '../types/connect-firestore/connect-document-data.type';
3
- import { ConnectDocumentSnapshot } from '../types/connect-firestore/connect-document-snapshop.type';
3
+ import { ConnectDocumentSnapshot, ConnectSnapshotOptions } from '../types/connect-firestore/connect-document-snapshot.type';
4
4
  import { ConnectDocumentReference } from './connect-document-reference';
5
5
  export interface ConnectCollectionReference<T extends ConnectDocumentData> {
6
6
  add(data: Partial<T>, id?: string): Promise<ConnectDocumentReference<T>>;
@@ -14,8 +14,8 @@ export interface ConnectCollectionReference<T extends ConnectDocumentData> {
14
14
  fromStartAfter(startAt: ConnectDocumentReference<T>): ConnectCollectionReference<T>;
15
15
  withConverter(converter: {
16
16
  toFirestore: (data: T) => ConnectDocumentData<T>;
17
- fromFirestore: (snap: ConnectDocumentSnapshot<T>) => T;
17
+ fromFirestore: (snapshot: ConnectDocumentSnapshot<T>, options?: ConnectSnapshotOptions) => T;
18
18
  }): ConnectCollectionReference<T>;
19
19
  getDoc(id?: string): ConnectDocumentReference<T>;
20
- getDocs(): Promise<ConnectQuerySnapshop<T>>;
20
+ getDocs(): Promise<ConnectQuerySnapshot<T>>;
21
21
  }
@@ -1,6 +1,5 @@
1
1
  import { Firestore } from 'firebase/firestore';
2
- import { ConnectDocumentData, ConnectQuerySnapshop, ConnectWhereOption } from '../types';
3
- import { ConnectDocumentSnapshot } from '../types/connect-firestore/connect-document-snapshop.type';
2
+ import { ConnectDocumentData, ConnectDocumentSnapshot, ConnectQuerySnapshot, ConnectSnapshotOptions, ConnectWhereOption } from '../types';
4
3
  import { ConnectCollectionReference } from './connect-collection-reference';
5
4
  import { ConnectDocumentReference } from './connect-document-reference';
6
5
  export declare class ConnectCollectionService<T extends ConnectDocumentData> implements ConnectCollectionReference<T> {
@@ -12,9 +11,10 @@ export declare class ConnectCollectionService<T extends ConnectDocumentData> imp
12
11
  private offsetBy;
13
12
  private statingAt;
14
13
  private startingAfter;
14
+ private converter;
15
15
  constructor(path: string, firestore: Firestore);
16
16
  add(data: T, id?: string): Promise<ConnectDocumentReference<T>>;
17
- getDocs(): Promise<ConnectQuerySnapshop<T>>;
17
+ getDocs(): Promise<ConnectQuerySnapshot<T>>;
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>;
@@ -25,8 +25,8 @@ export declare class ConnectCollectionService<T extends ConnectDocumentData> imp
25
25
  fromStartAfter(startingAt: number): ConnectCollectionReference<T>;
26
26
  fromStartAfter(startingAt: ConnectDocumentReference<T>): ConnectCollectionReference<T>;
27
27
  withConverter(params: {
28
- toFirestore: (data: T) => T;
29
- fromFirestore: (snapshot: ConnectDocumentSnapshot<T>) => T;
28
+ toFirestore: (data: T) => ConnectDocumentData<T>;
29
+ fromFirestore: (snapshot: ConnectDocumentSnapshot, options?: ConnectSnapshotOptions) => T;
30
30
  }): ConnectCollectionReference<T>;
31
31
  private save;
32
32
  }
@@ -1,12 +1,12 @@
1
1
  import { ConnectDocumentData } from '../types/connect-firestore/connect-document-data.type';
2
- import { ConnectDocumentSnapshot } from '../types/connect-firestore/connect-document-snapshop.type';
2
+ import { ConnectDocumentSnapshot, ConnectSnapshotOptions } from '../types/connect-firestore/connect-document-snapshot.type';
3
3
  export interface ConnectDocumentReference<T extends ConnectDocumentData> {
4
4
  get(): Promise<ConnectDocumentSnapshot<T>>;
5
5
  getId(): string;
6
6
  save(data: T): Promise<ConnectDocumentReference<T>>;
7
7
  delete(): Promise<void>;
8
8
  withConverter(converter: {
9
- toFirestore: (data: T) => T;
10
- fromFirestore: (snap: ConnectDocumentSnapshot<T>) => T;
9
+ toFirestore: (data: T) => ConnectDocumentData<T>;
10
+ fromFirestore: (snapshot: ConnectDocumentSnapshot<T>, options?: ConnectSnapshotOptions) => T;
11
11
  }): ConnectDocumentReference<T>;
12
12
  }
@@ -1,5 +1,5 @@
1
1
  import { Firestore } from 'firebase/firestore';
2
- import { ConnectDocumentData, ConnectDocumentSnapshot } from '../types';
2
+ import { ConnectDocumentData, ConnectDocumentSnapshot, ConnectSnapshotOptions } from '../types';
3
3
  import { ConnectDocumentReference } from './connect-document-reference';
4
4
  export declare class ConnectDocumentService<T extends ConnectDocumentData> implements ConnectDocumentReference<T> {
5
5
  private path;
@@ -11,7 +11,7 @@ export declare class ConnectDocumentService<T extends ConnectDocumentData> imple
11
11
  save(data: T): Promise<ConnectDocumentReference<T>>;
12
12
  delete(): Promise<void>;
13
13
  withConverter(params: {
14
- toFirestore: (data: T) => T;
15
- fromFirestore: (snapshot: ConnectDocumentSnapshot<T>) => T;
14
+ toFirestore: (data: T) => ConnectDocumentData<T>;
15
+ fromFirestore: (snapshot: ConnectDocumentSnapshot<T>, options?: ConnectSnapshotOptions) => T;
16
16
  }): ConnectDocumentReference<T>;
17
17
  }
@@ -1,7 +1,10 @@
1
1
  import { ConnectDocumentData } from './connect-document-data.type';
2
+ export type ConnectSnapshotOptions = {
3
+ serverTimestamps?: 'estimate' | 'previous' | 'none';
4
+ };
2
5
  export type ConnectDocumentSnapshot<T extends ConnectDocumentData = ConnectDocumentData> = {
3
6
  exists(): boolean;
4
- data(): T | undefined;
7
+ data(options?: ConnectSnapshotOptions): T;
5
8
  get(fieldPath: string): any;
6
9
  id: string;
7
10
  };
@@ -1,6 +1,6 @@
1
1
  import { ConnectDocumentData } from './connect-document-data.type';
2
- import { ConnectDocumentSnapshot } from './connect-document-snapshop.type';
3
- export type ConnectQuerySnapshop<T extends ConnectDocumentData> = {
2
+ import { ConnectDocumentSnapshot } from './connect-document-snapshot.type';
3
+ export type ConnectQuerySnapshot<T extends ConnectDocumentData> = {
4
4
  docs: ConnectDocumentSnapshot<T>[];
5
5
  size: number;
6
6
  empty: boolean;
@@ -1,4 +1,4 @@
1
1
  export * from './connect-document-data.type';
2
- export * from './connect-document-snapshop.type';
2
+ export * from './connect-document-snapshot.type';
3
3
  export * from './connect-query-snapshot.type';
4
4
  export * from './connect-where-option.type';
package/teste2.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};