Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-guerin committed Nov 4, 2024
1 parent 3d017f6 commit 5d5d3ec
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Injectable, Type} from '@angular/core';
import {InjectRepository, NgxRepositoryModule, provideNgxRepositoryModule} from '@paddls/ngx-repository';
import {InjectRepository, provideNgxRepositoryModule} from '@paddls/ngx-repository';
import {TestBed} from '@angular/core/testing';
import {Firestore, getFirestore} from 'firebase/firestore';
import {initializeApp} from 'firebase/app';
import {FirestoreRepository} from '../../lib/repository/firestore.repository';
import {NgxFirestoreRepositoryModule, provideNgxFirestoreRepository} from '../../lib/ngx-firestore-repository.module';
import {provideNgxFirestoreRepository} from '../../lib/ngx-firestore-repository.module';
import {FIRESTORE_APP} from '../../lib/ngx-firestore-repository.module.di';

export interface RepositoryContext<T> {
Expand Down Expand Up @@ -35,10 +35,6 @@ export function initializeRepository<T>(bookImpl: Type<T>, providers: any[] = []
}

TestBed.configureTestingModule({
imports: [
NgxRepositoryModule,
NgxFirestoreRepositoryModule
],
providers: [
provideNgxRepositoryModule(),
provideNgxFirestoreRepository(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ describe('NgxFirestoreRepositoryModule.forRoot', () => {
imports: [NgxFirestoreRepositoryModule.forRoot(config)],
});
});

testFirestoreRepository();
});

describe('provideNgxFirestoreRepositoryModule', () => {

const config: NgxFirestoreRepositoryModuleConfiguration = {
Expand All @@ -39,7 +41,6 @@ describe('provideNgxFirestoreRepositoryModule', () => {
});

function testFirestoreRepository() {

it('should provide FirestoreRepositoryBuilder', () => {
expect(() => TestBed.inject(FIRESTORE_APP)).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,57 @@ import {LogExecuteFirestoreRequestEventListener} from './driver/listener/log-exe
import {Firestore} from 'firebase/firestore';

const MODULE_PROVIDERS: Provider[] = [
FirestoreRepositoryBuilder,
FirestoreNormalizer,
FirestoreRepositoryBuilder,
FirestoreRepositoryDriver,
FirestoreRequestBuilder,
FirestoreCriteriaRequestBuilder,
FirestoreRepositoryBuilder,
FirestoreNormalizer,
FirestoreRepositoryBuilder,
FirestoreRepositoryDriver,
FirestoreRequestBuilder,
FirestoreCriteriaRequestBuilder,
{
provide: REPOSITORY_BUILDER_TOKEN,
useExisting: FirestoreRepositoryBuilder,
multi: true
}
];

export interface NgxFirestoreRepositoryModuleConfiguration { // @TODO: RMA/TNI : Add global configuration like ngx-http

firestore?: Firestore;

debug?: boolean;
}

export function provideNgxFirestoreRepository(config: NgxFirestoreRepositoryModuleConfiguration = {debug: false}): EnvironmentProviders {
const providers: Provider[] = [
...MODULE_PROVIDERS,
{
provide: REPOSITORY_BUILDER_TOKEN,
useExisting: FirestoreRepositoryBuilder,
multi: true
provide: FIRESTORE_APP,
useValue: config.firestore
}
];

export interface NgxFirestoreRepositoryModuleConfiguration { // @TODO: RMA/TNI : Add global configuration like ngx-http
if (config.debug) {
providers.push(LogExecuteFirestoreRequestEventListener);
}

firestore?: Firestore;
return makeEnvironmentProviders(providers);
}

debug?: boolean;
}
/**
* @ignore
*/
@NgModule({
providers: [
...MODULE_PROVIDERS
]
})
export class NgxFirestoreRepositoryModule {

export function provideNgxFirestoreRepository(config : NgxFirestoreRepositoryModuleConfiguration = {debug: false}): EnvironmentProviders {
/**
* @deprecated The method should not be used, use provideNgxFirestoreRepository instead
*/
public static forRoot(config: NgxFirestoreRepositoryModuleConfiguration = {debug: false}): ModuleWithProviders<NgxFirestoreRepositoryModule> {
const providers: Provider[] = [
...MODULE_PROVIDERS,
{
provide: FIRESTORE_APP,
useValue: config.firestore
Expand All @@ -45,37 +73,9 @@ const MODULE_PROVIDERS: Provider[] = [
providers.push(LogExecuteFirestoreRequestEventListener);
}

return makeEnvironmentProviders(providers);
}

/**
* @ignore
*/
@NgModule({
providers: [
...MODULE_PROVIDERS
]
})
export class NgxFirestoreRepositoryModule {

/**
* @deprecated The method should not be used, use provideNgxFirestoreRepository instead
*/
public static forRoot(config: NgxFirestoreRepositoryModuleConfiguration = {debug: false}): ModuleWithProviders<NgxFirestoreRepositoryModule> {
const providers: Provider[] = [
{
provide: FIRESTORE_APP,
useValue: config.firestore
}
];

if (config.debug) {
providers.push(LogExecuteFirestoreRequestEventListener);
}

return {
ngModule: NgxFirestoreRepositoryModule,
providers
};
}
return {
ngModule: NgxFirestoreRepositoryModule,
providers
};
}
}

0 comments on commit 5d5d3ec

Please sign in to comment.