18.2.1 • Published 11 months ago

@nx-ddd/firestore v18.2.1

Weekly downloads
-
License
-
Repository
github
Last release
11 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/models';
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);
});
18.2.1

11 months ago

17.14.0

11 months ago

18.2.0

11 months ago

18.0.0

11 months ago

17.10.0

12 months ago

17.12.0

12 months 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

12 months ago

17.7.1

1 year ago

17.3.5

1 year ago

17.13.0

12 months ago

18.1.0

11 months ago

17.11.0

12 months 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

2 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

2 years ago

5.1.2

2 years ago

5.2.0

2 years ago

5.1.1

2 years ago

4.20.6

2 years ago

5.1.0

2 years ago

4.20.7

2 years ago

5.0.0

2 years ago

4.21.1

2 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.13

3 years ago

1.0.5

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago