UNPKG

@rxap/ngx-utilities

Version:
1 lines 3.11 kB
{"version":3,"file":"rxap-ngx-utilities.mjs","sources":["../../../../../packages/angular/utilities/src/lib/to-method.ts","../../../../../packages/angular/utilities/src/index.ts","../../../../../packages/angular/utilities/src/rxap-ngx-utilities.ts"],"sourcesContent":["import {\n Injector,\n runInInjectionContext,\n} from '@angular/core';\nimport { Method } from '@rxap/pattern';\nimport { isPromise } from '@rxap/utilities';\n\nexport function ToMethodWithInjectionContext<ReturnType = any, Parameter = any, MethodType extends Method<ReturnType, Parameter> = Method<ReturnType, Parameter>>(\n call: ((\n parameters?: Parameter,\n ...args: any[]\n ) => Promise<ReturnType> | ReturnType),\n injector: Injector,\n metadata: any = { id: 'to-method' }\n): MethodType {\n return {\n call: (parameters, ...args) => new Promise<ReturnType>((resolve, reject) => {\n if (!injector) {\n throw new Error('The injector is not defined. Can not run the method in the injection context.');\n }\n runInInjectionContext(injector, () => {\n try {\n const result = call(parameters, ...args);\n if (isPromise(result)) {\n result.then(resolve).catch(reject);\n } else {\n resolve(result);\n }\n } catch (e: unknown) {\n reject(e);\n }\n });\n }),\n metadata\n } as MethodType;\n}\n\nexport function ToMethodWithInjectionContextFactory<ReturnType = any, Parameter = any, MethodType extends Method<ReturnType, Parameter> = Method<ReturnType, Parameter>>(\n call: ((\n parameters?: Parameter,\n ...args: any[]\n ) => Promise<ReturnType> | ReturnType),\n metadata: any = { id: 'to-method' }\n): (injector: Injector) => MethodType {\n return (injector: Injector) => {\n if (!injector) {\n throw new Error('The injector is not defined. Ensure the factory is used in conjunction with deps: [ INJECTOR ]');\n }\n return ToMethodWithInjectionContext<ReturnType, Parameter, MethodType>(\n call, injector, metadata);\n };\n}\n","// region \nexport * from './lib/to-method';\n// endregion\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAOgB,SAAA,4BAA4B,CAC1C,IAGsC,EACtC,QAAkB,EAClB,QAAA,GAAgB,EAAE,EAAE,EAAE,WAAW,EAAE,EAAA;IAEnC,OAAO;AACL,QAAA,IAAI,EAAE,CAAC,UAAU,EAAE,GAAG,IAAI,KAAK,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,MAAM,KAAI;YACzE,IAAI,CAAC,QAAQ,EAAE;AACb,gBAAA,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC;;AAElG,YAAA,qBAAqB,CAAC,QAAQ,EAAE,MAAK;AACnC,gBAAA,IAAI;oBACF,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC;AACxC,oBAAA,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE;wBACrB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;;yBAC7B;wBACL,OAAO,CAAC,MAAM,CAAC;;;gBAEjB,OAAO,CAAU,EAAE;oBACnB,MAAM,CAAC,CAAC,CAAC;;AAEb,aAAC,CAAC;AACJ,SAAC,CAAC;QACF;KACa;AACjB;AAEM,SAAU,mCAAmC,CACjD,IAGsC,EACtC,WAAgB,EAAE,EAAE,EAAE,WAAW,EAAE,EAAA;IAEnC,OAAO,CAAC,QAAkB,KAAI;QAC5B,IAAI,CAAC,QAAQ,EAAE;AACb,YAAA,MAAM,IAAI,KAAK,CAAC,gGAAgG,CAAC;;QAEnH,OAAO,4BAA4B,CACjC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC;AAC7B,KAAC;AACH;;ACnDA;AAEA;;ACFA;;AAEG;;;;"}