( ...loaders: ILoader<any, any, any>[] )
| 1 | import { ILoader, ILoaderDefinition } from "./_types"; |
| 2 | |
| 3 | export function composeLoaders( |
| 4 | ...loaders: ILoader<any, any, any>[] |
| 5 | ): ILoader<any, any> { |
| 6 | return { |
| 7 | init: async () => { |
| 8 | for (const loader of loaders) { |
| 9 | await loader.init?.(); |
| 10 | } |
| 11 | }, |
| 12 | setDefaultLocale(locale: string) { |
| 13 | for (const loader of loaders) { |
| 14 | loader.setDefaultLocale?.(locale); |
| 15 | } |
| 16 | return this; |
| 17 | }, |
| 18 | pull: async (locale, input) => { |
| 19 | let result: any = input; |
| 20 | for (let i = 0; i < loaders.length; i++) { |
| 21 | result = await loaders[i].pull(locale, result); |
| 22 | } |
| 23 | return result; |
| 24 | }, |
| 25 | push: async (locale, data) => { |
| 26 | let result: any = data; |
| 27 | for (let i = loaders.length - 1; i >= 0; i--) { |
| 28 | result = await loaders[i].push(locale, result); |
| 29 | } |
| 30 | return result; |
| 31 | }, |
| 32 | pullHints: async (originalInput?) => { |
| 33 | let result: any = originalInput; |
| 34 | for (let i = 0; i < loaders.length; i++) { |
| 35 | const subResult = await loaders[i].pullHints?.(result); |
| 36 | if (subResult) { |
| 37 | result = subResult; |
| 38 | } |
| 39 | } |
| 40 | return result; |
| 41 | }, |
| 42 | }; |
| 43 | } |
| 44 | |
| 45 | export function createLoader<I, O, C>( |
| 46 | lDefinition: ILoaderDefinition<I, O, C>, |
no test coverage detected