All files / src/auxiliary Idempotent.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

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 45 46 47 48 49 50 51      2x                                                                               2x 19x            
import { Open, OpenType } from "@jonloucks/contracts-ts/api/Open";
import { State } from "@jonloucks/contracts-ts/auxiliary/IdempotenState";
import { Contracts } from "@jonloucks/contracts-ts/api/Contracts";
import { guardFunctions, RequiredType } from "@jonloucks/contracts-ts/api/Types";
 
/** 
 * The configuration used to create a new Idempotent instance
 */
export interface Config {
 
  /** The Contracts instance to use */
  contracts?: Contracts;
 
  /** The Open type to use when opening the Idempotent */
  open: OpenType;
}
 
/**
 * The Idempotent API
 */
export interface Idempotent extends Open {
 
  /**
   * Get the current state of the Idempotent
   *
   * @return the current state
   */
  getState(): State;
 
  /**
   * Determine if the Idempotent is open
   *
   * @return true if the Idempotent is open
   */
  isOpen(): boolean;
}
 
/**
 * Determine if an instance implements Idempotent
 * 
 * @param instance the instance to check
 * @returns true if the instance implements Idempotent
 */
export function guard(instance: unknown): instance is RequiredType<Idempotent> {
  return guardFunctions(instance,
    'getState',
    'open',
    'isOpen',
  );
}