All files / lib initialize.ts

80% Statements 8/10
87.5% Branches 14/16
100% Functions 2/2
80% Lines 8/10

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      1x       1x           1x     4x       4x       4x 4x     4x        
import { Application } from "@feathersjs/feathers";
import { PartialDeep } from "type-fest";
 
import { 
  makeDefaultOptions as makeDefaultAuthorizeHookOptions
} from "./hooks/authorize/authorize.hook.utils";
 
import { 
  makeDefaultOptions as makeDefaultChannelsOptions
} from "./channels/channels.utils";
 
import { AuthorizeHookOptions, ChannelOptions, InitOptions } from "./types";
 
export default (options?: PartialDeep<InitOptions>): ((app: Application) => void) => {
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  //@ts-ignore
  Iif (options?.version) {
    // asserts that you call app.configure(casl({})) instead of app.configure(casl)
    throw new Error("You passed 'feathers-casl' to app.configure() without a function. You probably wanted to call app.configure(casl({}))!");
  }
  options = {
    authorizeHook: makeDefaultAuthorizeHookOptions(options?.authorizeHook as undefined|Partial<AuthorizeHookOptions>),
    channels: makeDefaultChannelsOptions(options?.channels as undefined|Partial<ChannelOptions>)
  };
  return (app: Application): void => {
    Iif (app.get("casl")) { 
      return;
    }
    app.set("casl", options);
  };
};