{"version":3,"file":"builder.cjs","sources":["../../src/builder.ts"],"sourcesContent":["import { omit, pick } from 'radash'\nimport type { Props, Request } from './types'\n\nexport type ExobaseBuilder<\n  KInitArgs extends any[] = any[],\n  KCurrentArgs extends {} = {},\n  KCurrentServices extends {} = {},\n  KCurrentAuth extends {} = {},\n  KCurrentRequest extends Request = Request,\n  KCurrentFramework extends {} = {}\n> = {\n  init: (\n    init: (\n      func: (...args: any[]) => Promise<any>\n    ) => (...args: any[]) => Promise<any>\n  ) => Pick<ExobaseBuilder, 'init' | 'root'>\n  root: <\n    TInitArgs extends any[],\n    TCurrentArgs extends {},\n    TCurrentServices extends {},\n    TCurrentAuth extends {},\n    TCurrentRequest extends Request,\n    TCurrentFramework extends {}\n  >(\n    root: (\n      func: (\n        props: Props<\n          TCurrentArgs,\n          TCurrentServices,\n          TCurrentAuth,\n          TCurrentRequest,\n          TCurrentFramework\n        >\n      ) => Promise<any>\n    ) => (...args: TInitArgs) => Promise<any>\n  ) => Pick<\n    ExobaseBuilder<\n      TInitArgs,\n      TCurrentArgs,\n      TCurrentServices,\n      TCurrentAuth,\n      TCurrentRequest,\n      TCurrentFramework\n    >,\n    'hook' | 'endpoint'\n  >\n  hook: <\n    TNextArgs extends {},\n    TNextServices extends {},\n    TNextAuth extends {},\n    TNextRequest extends Request,\n    TNextFramework extends {},\n    TRequiredServices extends KCurrentServices extends TRequiredServices\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Services to pass to this hook',\n    TRequiredAuth extends KCurrentAuth extends TRequiredAuth\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Auth to pass to this hook',\n    TRequiredArgs extends KCurrentArgs extends TRequiredArgs\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Args to pass to this hook',\n    TRequiredRequest extends KCurrentRequest extends TRequiredRequest\n      ? Request\n      : Request &\n          '>>> ERROR: The chain does not contain the required Request to pass to this hook',\n    TRequiredFramework extends KCurrentFramework extends TRequiredFramework\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Framework to pass to this hook'\n  >(\n    hook: (\n      func: (\n        props: Props<\n          TNextArgs,\n          TNextServices,\n          TNextAuth,\n          TNextRequest,\n          TNextFramework\n        >\n      ) => Promise<any>\n    ) => (\n      props: Props<\n        TRequiredArgs,\n        TRequiredServices,\n        TRequiredAuth,\n        TRequiredRequest,\n        TRequiredFramework\n      >\n    ) => Promise<any>\n  ) => Pick<\n    ExobaseBuilder<\n      KInitArgs,\n      TNextArgs & KCurrentArgs,\n      TNextServices & KCurrentServices,\n      TNextAuth & KCurrentAuth,\n      TNextRequest & KCurrentRequest,\n      TNextFramework & KCurrentFramework\n    >,\n    'hook' | 'endpoint'\n  >\n  endpoint: <\n    TResult,\n    TRequiredServices extends KCurrentServices extends TRequiredServices\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Services to pass to this endpoint',\n    TRequiredAuth extends KCurrentAuth extends TRequiredAuth\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Auth to pass to this endpoint',\n    TRequiredArgs extends KCurrentArgs extends TRequiredArgs\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Args to pass to this endpoint',\n    TRequiredRequest extends KCurrentRequest extends TRequiredRequest\n      ? Request\n      : Request &\n          '>>> ERROR: The chain does not contain the required Request to pass to this endpoint',\n    TRequiredFramework extends KCurrentFramework extends TRequiredFramework\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Framework to pass to this endpoint'\n  >(\n    handler: (\n      props: Props<\n        TRequiredArgs,\n        TRequiredServices,\n        TRequiredAuth,\n        TRequiredRequest,\n        TRequiredFramework\n      >\n    ) => Promise<TResult>\n  ) => ((...args: KInitArgs) => Promise<TResult>) & {\n    hooks: string[]\n  }\n  raw: {\n    init: KInitArgs\n    args: KCurrentArgs\n    services: KCurrentServices\n    auth: KCurrentAuth\n    request: KCurrentRequest\n    framework: KCurrentFramework\n  }\n}\n\nexport const chain = <\n  KInitArgs extends any[] = any[],\n  KCurrentArgs extends {} = {},\n  KCurrentServices extends {} = {},\n  KCurrentAuth extends {} = {},\n  KCurrentRequest extends Request = Request,\n  KCurrentFramework extends {} = {}\n>(\n  funcs: Function[] = []\n): ExobaseBuilder<\n  KInitArgs,\n  KCurrentArgs,\n  KCurrentServices,\n  KCurrentAuth,\n  KCurrentRequest,\n  KCurrentFramework\n> => ({\n  init: (\n    init: (\n      func: (...args: any[]) => Promise<any>\n    ) => (...args: any[]) => Promise<any>\n  ) => {\n    return chain([...funcs, init]) as Pick<ExobaseBuilder, 'init' | 'root'>\n  },\n  root: <\n    TInitArgs extends any[],\n    TCurrentArgs extends {},\n    TCurrentServices extends {},\n    TCurrentAuth extends {},\n    TCurrentRequest extends Request,\n    TCurrentFramework extends {}\n  >(\n    root: (\n      func: (\n        props: Props<\n          TCurrentArgs,\n          TCurrentServices,\n          TCurrentAuth,\n          TCurrentRequest,\n          TCurrentFramework\n        >\n      ) => Promise<any>\n    ) => (...args: TInitArgs) => Promise<any>\n  ) => {\n    return chain([...funcs, root]) as Pick<\n      ExobaseBuilder<\n        TInitArgs,\n        TCurrentArgs,\n        TCurrentServices,\n        TCurrentAuth,\n        TCurrentRequest,\n        TCurrentFramework\n      >,\n      'hook' | 'endpoint'\n    >\n  },\n  hook: <\n    TNextArgs extends {},\n    TNextServices extends {},\n    TNextAuth extends {},\n    TNextRequest extends Request,\n    TNextFramework extends {},\n    TRequiredServices extends KCurrentServices extends TRequiredServices\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Services to pass to this hook',\n    TRequiredAuth extends KCurrentAuth extends TRequiredAuth\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Auth to pass to this hook',\n    TRequiredArgs extends KCurrentArgs extends TRequiredArgs\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Args to pass to this hook',\n    TRequiredRequest extends KCurrentRequest extends TRequiredRequest\n      ? Request\n      : Request &\n          '>>> ERROR: The chain does not contain the required Request to pass to this hook',\n    TRequiredFramework extends KCurrentFramework extends TRequiredFramework\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Framework to pass to this hook'\n  >(\n    hook: (\n      func: (\n        props: Props<\n          TNextArgs,\n          TNextServices,\n          TNextAuth,\n          TNextRequest,\n          TNextFramework\n        >\n      ) => Promise<any>\n    ) => (\n      props: Props<\n        TRequiredArgs,\n        TRequiredServices,\n        TRequiredAuth,\n        TRequiredRequest,\n        TRequiredFramework\n      >\n    ) => Promise<any>\n  ) => {\n    return omit(\n      chain<\n        KInitArgs,\n        TNextArgs & KCurrentArgs,\n        TNextServices & KCurrentServices,\n        TNextAuth & KCurrentAuth,\n        TNextRequest & KCurrentRequest,\n        TNextFramework & KCurrentFramework\n      >([...funcs, hook]),\n      ['init', 'root']\n    ) as Pick<\n      ExobaseBuilder<\n        KInitArgs,\n        TNextArgs & KCurrentArgs,\n        TNextServices & KCurrentServices,\n        TNextAuth & KCurrentAuth,\n        TNextRequest & KCurrentRequest,\n        TNextFramework & KCurrentFramework\n      >,\n      'hook' | 'endpoint'\n    >\n  },\n  endpoint: <\n    TResult,\n    TRequiredServices extends KCurrentServices extends TRequiredServices\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Services to pass to this endpoint',\n    TRequiredAuth extends KCurrentAuth extends TRequiredAuth\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Auth to pass to this endpoint',\n    TRequiredArgs extends KCurrentArgs extends TRequiredArgs\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Args to pass to this endpoint',\n    TRequiredRequest extends KCurrentRequest extends TRequiredRequest\n      ? Request\n      : Request &\n          '>>> ERROR: The chain does not contain the required Request to pass to this endpoint',\n    TRequiredFramework extends KCurrentFramework extends TRequiredFramework\n      ? {}\n      : '>>> ERROR: The chain does not contain the required Framework to pass to this endpoint'\n  >(\n    endpoint: (\n      props: Props<\n        TRequiredArgs,\n        TRequiredServices,\n        TRequiredAuth,\n        TRequiredRequest,\n        TRequiredFramework\n      >\n    ) => Promise<TResult>\n  ) => {\n    const func = [...funcs, endpoint]\n      .reverse()\n      .reduce((acc, fn) => fn(acc)) as ((\n      ...args: KInitArgs\n    ) => Promise<TResult>) & {\n      hooks: string[]\n    }\n    func.hooks = funcs.map(f => f.name)\n    return func\n  },\n  raw: {\n    init: {} as KInitArgs,\n    args: {} as KCurrentArgs,\n    services: {} as KCurrentServices,\n    auth: {} as KCurrentAuth,\n    request: {} as KCurrentRequest,\n    framework: {} as KCurrentFramework\n  }\n})\n\nexport const exo = () => pick(chain(), ['init', 'root'])\n"],"names":["omit","pick"],"mappings":";;;;AA4IO,MAAM,KAAQ,GAAA,CAQnB,KAAoB,GAAA,EAQhB,MAAA;AAAA,EACJ,IAAA,EAAM,CACJ,IAGG,KAAA;AACH,IAAA,OAAO,KAAM,CAAA,CAAC,GAAG,KAAA,EAAO,IAAI,CAAC,CAAA,CAAA;AAAA,GAC/B;AAAA,EACA,IAAA,EAAM,CAQJ,IAWG,KAAA;AACH,IAAA,OAAO,KAAM,CAAA,CAAC,GAAG,KAAA,EAAO,IAAI,CAAC,CAAA,CAAA;AAAA,GAW/B;AAAA,EACA,IAAA,EAAM,CAuBJ,IAmBG,KAAA;AACH,IAAO,OAAAA,WAAA;AAAA,MACL,KAOE,CAAA,CAAC,GAAG,KAAA,EAAO,IAAI,CAAC,CAAA;AAAA,MAClB,CAAC,QAAQ,MAAM,CAAA;AAAA,KACjB,CAAA;AAAA,GAWF;AAAA,EACA,QAAA,EAAU,CAmBR,QASG,KAAA;AACH,IAAA,MAAM,IAAO,GAAA,CAAC,GAAG,KAAA,EAAO,QAAQ,CAC7B,CAAA,OAAA,EACA,CAAA,MAAA,CAAO,CAAC,GAAA,EAAK,EAAO,KAAA,EAAA,CAAG,GAAG,CAAC,CAAA,CAAA;AAK9B,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAM,GAAI,CAAA,CAAA,CAAA,KAAK,EAAE,IAAI,CAAA,CAAA;AAClC,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA,EACA,GAAK,EAAA;AAAA,IACH,MAAM,EAAC;AAAA,IACP,MAAM,EAAC;AAAA,IACP,UAAU,EAAC;AAAA,IACX,MAAM,EAAC;AAAA,IACP,SAAS,EAAC;AAAA,IACV,WAAW,EAAC;AAAA,GACd;AACF,CAAA,EAAA;AAEa,MAAA,GAAA,GAAM,MAAMC,WAAK,CAAA,KAAA,IAAS,CAAC,MAAA,EAAQ,MAAM,CAAC;;;;;"}