19.0.0-preview.36 • Published 9 months ago

@nx-ddd/firestore v19.0.0-preview.36

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

@NxDDD/Firestore

@nx-ddd/firestore is a library that wraps Firestore in the Repository pattern. It uses the Adapter pattern to enable the same codebase to work with both FirebaseAdmin and Firebase.

Install

$ npm i @nx-ddd/firestore

Usage

Common

// libs/common/infrastructure/repositories/user.repository
import { inject, Injectable } from '@angular/core';
import { TransformToDayjs } from '@nx-ddd/common/domain';
import { bootstrap } from '@nx-ddd/core';
import { FirestoreRepository, Firestore, injectConverter } from '@nx-ddd/firestore';
import { IsDayjs } from 'class-validator-extended';
import dayjs from 'dayjs';

export class User {
  @Firestore.ID() id: string;
  @Firestore.String() name: string;
  @Firestore.Timestamp() @IsDayjs() @TransformToDayjs() createdAt: dayjs.Dayjs;
  @Firestore.Timestamp() @IsDayjs() @TransformToDayjs() updatedAt: dayjs.Dayjs;
}

@Injectable({providedIn: 'root'})
export class UserRepository extends FirestoreRepository<User> {
  readonly collectionPath = `users/:id`;
  protected converter = injectConverter(User);
}

Firebase Admin (in NodeJS)

Use UserRepository in NodeJS.

// apps/api/src/app/main.ts
import 'reflect-metadata';
import '@angular/compiler';
import { provideFirestoreAdapter } from '@nx-ddd/firestore/adapters/admin';
import { UserRepository } from 'libs/common/infrastructure/repositories/user.repository';
import dayjs from 'dayjs';

import admin from 'firebase-admin';

admin.initializeApp({
  credential: admin.credential.applicationDefault(),
});

bootstrap([
  provideFirestoreAdapter(),
]).then(async (injector) => {
  const repository = injector.get(UserRepository);
  await repository.create({
    id: '0001',
    name: 'test',
    createdAt: dayjs('2022-01-01'),
    updatedAt: dayjs('2022-01-01'),
  });
  const user = await repository.get({id: '0001'});
  console.debug('user:', user);
});

Firebase (in Browser)

Use UserRepository in browser.

// apps/app/src/app/main.ts
import 'reflect-metadata';
import '@angular/compiler';
import { provideFirestoreAdapter } from '@nx-ddd/firestore/adapters/firebase';
import { UserRepository } from 'libs/common/infrastructure/repositories/user.repository';
import { initializeApp } from "firebase/app";
import dayjs from 'dayjs';

const app = initializeApp({...});

bootstrap([
  provideFirestoreAdapter(),
]).then(async (injector) => {
  const repository = injector.get(UserRepository);
  await repository.create({
    id: '0001',
    name: 'test',
    createdAt: dayjs('2022-01-01'),
    updatedAt: dayjs('2022-01-01'),
  });
  const user = await repository.get({id: '0001'});
  console.debug('user:', user);
});
19.0.0-preview.28

9 months ago

19.0.0-preview.27

9 months ago

19.0.0-preview.29

9 months ago

19.0.0-preview.24

9 months ago

19.0.0-preview.23

9 months ago

19.0.0-preview.26

9 months ago

18.6.0

11 months ago

19.0.0-preview.25

9 months ago

19.0.0-preview.20

9 months ago

19.0.0-preview.22

9 months ago

19.0.0-preview.21

9 months ago

19.0.0-preview.17

9 months ago

19.0.0-preview.16

9 months ago

19.0.0-preview.19

9 months ago

19.0.0-preview.18

9 months ago

19.0.0-preview.13

9 months ago

19.0.0-preview.12

9 months ago

19.0.0-preview.15

9 months ago

19.0.0-preview.14

9 months ago

19.0.0-preview.11

9 months ago

19.0.0-preview.10

9 months ago

18.9.1

11 months ago

18.9.0

11 months ago

18.5.0

11 months ago

18.10.0

10 months ago

18.8.1

11 months ago

18.8.0

11 months ago

19.0.0-preview.8

9 months ago

19.0.0-preview.7

9 months ago

18.11.0

10 months ago

19.0.0-preview.9

9 months ago

19.0.0-preview.2

9 months ago

19.0.0-preview.4

9 months ago

19.0.0-preview.3

9 months ago

19.0.0-preview.6

9 months ago

19.0.0-preview.5

9 months ago

18.4.0

11 months ago

18.7.0

11 months ago

18.12.0

9 months ago

19.0.0-preview.35

9 months ago

19.0.0-preview.34

9 months ago

19.0.0-preview.36

9 months ago

19.0.0-preview.31

9 months ago

19.0.0-preview.30

9 months ago

19.0.0-preview.33

9 months ago

19.0.0-preview.32

9 months ago

18.2.1

1 year ago

17.14.0

1 year ago

18.2.0

1 year ago

18.0.0

1 year ago

17.10.0

1 year ago

17.12.0

1 year ago

17.3.0

1 year ago

17.5.0

1 year ago

17.3.2

1 year ago

17.3.1

1 year ago

17.1.0

1 year ago

17.7.0

1 year ago

17.3.4

1 year ago

17.3.3

1 year ago

17.9.0

1 year ago

17.7.1

1 year ago

17.3.5

1 year ago

17.13.0

1 year ago

18.1.0

1 year ago

17.11.0

1 year ago

17.0.3

1 year ago

17.2.0

1 year ago

17.0.2

1 year ago

17.4.0

1 year ago

17.0.4

1 year ago

17.0.1

1 year ago

17.0.0

1 year ago

17.6.1

1 year ago

17.6.0

1 year ago

17.8.0

1 year ago

16.3.1

1 year ago

15.1.1

2 years ago

15.1.0

2 years ago

5.15.0

2 years ago

5.13.0

2 years ago

5.11.0

2 years ago

16.1.1

2 years ago

16.1.0

2 years ago

15.0.1

2 years ago

6.0.3

2 years ago

6.0.4

2 years ago

5.14.0

2 years ago

5.12.0

2 years ago

16.2.0

2 years ago

16.0.0

2 years ago

5.6.0

2 years ago

5.4.2

2 years ago

5.5.0

2 years ago

5.4.1

2 years ago

5.4.0

2 years ago

5.3.1

3 years ago

5.10.0

2 years ago

5.9.0

2 years ago

5.8.1

2 years ago

5.8.0

2 years ago

5.7.1

2 years ago

5.7.0

2 years ago

5.3.0

3 years ago

5.1.2

3 years ago

5.2.0

3 years ago

5.1.1

3 years ago

4.20.6

3 years ago

5.1.0

3 years ago

4.20.7

3 years ago

5.0.0

3 years ago

4.21.1

3 years ago

1.1.0

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.13

4 years ago

1.0.5

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago