{"version":3,"file":"dragons.mjs","sources":["../../../../src/dragons.ts"],"sourcesContent":["import { type Effect, type EventCallable, type Node, step } from \"effector\"\n\nexport function patchHandler(fx: Effect<any, any, any>, called: EventCallable<Promise<any>>) {\n  /**\n   * This overrides Effect with our handler that\n   * allows us to aquire a Promise of each call.\n   *\n   * We need this to track each independent execution\n   * rather than `trigger` -> `done` events, which may\n   * or may not be in the correct order.\n   */\n\n  /**\n   * patchHandler is a compute step that overrides the hander.\n   * It is injected just before the execution.\n   *\n   * {@see https://github.com/effector/effector/blob/a0f997b3d355c5a9b682e3747f00a1ffe7de8646/src/effector/__tests__/effect/index.test.ts#L432}\n   */\n  const patchHandler = step.compute({\n    fn(run: { handler: (...args: unknown[]) => unknown }) {\n      const original = run.handler\n\n      run.handler = (...params: unknown[]) => {\n        /**\n         * We convert each call to Promise, regardless of whether\n         * the `original` call is sync or not.\n         */\n        const req = Promise.resolve(original(...params))\n        return called(req)\n      }\n\n      return run\n    },\n  })\n\n  /**\n   * 0. Get the handler from Scope.\n   * 1. Our handler that `wraps`\n   * 2. Running the handler\n   */\n  pickRunner(fx).seq.splice(1, 0, patchHandler)\n}\n\nfunction pickRunner(effect: Effect<unknown, unknown, unknown>): Node {\n  return (effect as unknown as { graphite: Node }).graphite.scope.runner as Node\n}\n"],"names":["patchHandler"],"mappings":";AAEgB,SAAA,aAAa,IAA2B,QAAqC;AAgBrFA,QAAAA,gBAAe,KAAK,QAAQ;AAAA,IAChC,GAAG,KAAmD;AACpD,YAAM,WAAW,IAAI;AAEjB,UAAA,UAAU,IAAI,WAAsB;AAKtC,cAAM,MAAM,QAAQ,QAAQ,SAAS,GAAG,MAAM,CAAC;AAC/C,eAAO,OAAO,GAAG;AAAA,MACnB;AAEO,aAAA;AAAA,IAAA;AAAA,EACT,CACD;AAOD,aAAW,EAAE,EAAE,IAAI,OAAO,GAAG,GAAGA,aAAY;AAC9C;AAEA,SAAS,WAAW,QAAiD;AAC3D,SAAA,OAAyC,SAAS,MAAM;AAClE;"}