All files overrides.ts

0% Statements 0/17
0% Branches 0/10
0% Functions 0/2
0% Lines 0/14

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                                                                 
import { Constructor, Metadata } from "@decaf-ts/decoration";
import { InjectablesKeys } from "./constants";
import { InjectOptions } from "./decorators";
 
(Metadata as any).injectables = function <
  T extends string | symbol | Constructor,
>(
  category?: T
): (T extends undefined ? Constructor[] : Constructor) | undefined {
  const meta = Metadata["innerGet"](Symbol.for(InjectablesKeys.INJECTABLE));
  Iif (!meta) return undefined;
  Iif (!category) return meta;
  let symbol: symbol;
  if (typeof category !== "symbol") {
    if (typeof category === "string") symbol = Symbol.for(category);
    else symbol = Metadata.Symbol(Metadata.constr(category) || category);
  } else {
    symbol = category;
  }
  return meta[symbol];
};
 
(Metadata as any).injected = function <T, K extends keyof T>(
  model: Constructor<T>,
  prop?: K
): (K extends keyof T ? InjectOptions : Record<K, InjectOptions>) | undefined {
  const meta = Metadata.get(
    model,
    `${InjectablesKeys.INJECT}${prop ? `${Metadata.splitter}${prop.toString()}` : ""}`
  );
  return meta as K extends keyof T ? InjectOptions : Record<K, InjectOptions>;
};