{"version":3,"file":"expandFnMap.cjs","names":["reduceFnMap","assignByKey"],"sources":["../../../src/machine/functions/expandFnMap.ts"],"sourcesContent":["import type { Action2 } from '#actions';\nimport type { Cast, PrimitiveObject } from '#bemedev/globals/types';\nimport type {\n  ActorsConfigMap,\n  EventsMap,\n  ToEventObject,\n  ToEvents,\n} from '#events';\nimport { reduceFnMap } from '#utils';\nimport type { Decompose } from '@bemedev/decompose';\nimport { type FnMap } from '~types';\nimport { assignByKey } from './subcriber';\n\nexport type ExpandFnMap = <\n  Pc,\n  Tc = PrimitiveObject,\n  D = Decompose<\n    {\n      pContext: Pc;\n      context: Tc;\n    },\n    { sep: '.'; object: 'both'; start: false }\n  >,\n  K extends Extract<keyof D, string> = Extract<keyof D, string>,\n  R = D[K],\n  E extends EventsMap = EventsMap,\n  A extends ActorsConfigMap = ActorsConfigMap,\n  T extends string = string,\n  Eo extends ToEventObject<ToEvents<E, A>> = ToEventObject<ToEvents<E, A>>,\n>(\n  events: E,\n  actorsMap: A,\n  key: K,\n  fn: FnMap<Eo, Pc, Cast<Tc, PrimitiveObject>, T, R>,\n) => Action2<Eo, Pc, Cast<Tc, PrimitiveObject>, T>;\n/**\n *\n * @param events : type {@linkcode EventsMap} [E] - The events map.\n * @param promisees  : type {@linkcode ActorsConfigMap} [P] - The promisees map.\n * @param key  : type {@linkcode Decompose} [D] - The key to assign the result to in the context and the private context.\n * @param fn  : type {@linkcode FnMap} [E, P, Pc, Tc, R] - The function to reduce the events and promisees and performs the action.\n * @returns a {@linkcode Action2} function.\n *\n * @see {@linkcode assignByKey} for assigning the result to the context and private context.\n * @see {@linkcode reduceFnMap} for reducing the events and promisees.\n * @see {@linkcode Decompose} for decomposing the private context and context into paths.\n *\n */\nexport const expandFnMap: ExpandFnMap = (events, promisees, key, fn) => {\n  const _fn = reduceFnMap(events, promisees, fn);\n\n  return async ({ pContext, context, ...rest }) => {\n    const all = {\n      pContext,\n      context,\n    };\n    const result = await _fn({ pContext, context, ...rest });\n    return assignByKey(all, key, result);\n  };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgDA,MAAa,eAA4B,QAAQ,WAAW,KAAK,OAAO;CACtE,MAAM,MAAMA,0BAAAA,YAAY,QAAQ,WAAW,GAAG;AAE9C,QAAO,OAAO,EAAE,UAAU,SAAS,GAAG,WAAW;AAM/C,SAAOC,6CAAAA,YALK;GACV;GACA;GACD,EAEuB,KADT,MAAM,IAAI;GAAE;GAAU;GAAS,GAAG;GAAM,CAAC,CACpB"}