All files / src/impl RepositoryFactory.impl.ts

100% Statements 9/9
75% Branches 3/4
100% Functions 4/4
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44        25x               25x 165x                     183x   183x 183x     183x       165x       165x          
import { Contracts } from "@jonloucks/contracts-ts/api/Contracts";
import { Config, Repository } from "@jonloucks/contracts-ts/api/Repository";
import { RepositoryFactory } from "@jonloucks/contracts-ts/api/RepositoryFactory";
import { RequiredType } from "@jonloucks/contracts-ts/api/Types";
import { create as createRepository } from "./Repository.impl";
 
/**
 * Factory method to create a RepositoryFactory
 * 
 * @param contracts the Contracts instance to be used by the RepositoryFactory
 * @returns the RepositoryFactory implementation
 */
export function create(contracts: Contracts): RequiredType<RepositoryFactory> {
  return RepositoryFactoryImpl.internalCreate(contracts);
}
 
// ---- Implementation details below ----
 
/**
 * The RepositoryFactory implementation
 */
class RepositoryFactoryImpl implements RepositoryFactory {
 
  createRepository(config?: Config): RequiredType<Repository> {
    const validConfig: Config =  {...(config ?? {})};
 
    Eif (!validConfig.contracts) {
      validConfig.contracts = this.contracts;
    }
 
    return createRepository(validConfig);
  }
 
  static internalCreate(contracts: Contracts): RequiredType<RepositoryFactory> {
    return new RepositoryFactoryImpl(contracts);
  }
 
  private constructor(contracts: Contracts) {
    this.contracts = contracts;
  }
 
  private readonly contracts: Contracts;
}