Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
3.3 KiB
Plaintext
1 line
3.3 KiB
Plaintext
{"version":3,"sources":["../../../../../src/queues/operations/runJobs/runJob/importHandlerPath.ts"],"sourcesContent":["import type { TaskConfig, TaskHandler, TaskType } from '../../../config/types/taskTypes.js'\n\nimport { dynamicImport } from '../../../../utilities/dynamicImport.js'\n\n/**\n * Imports a handler function from a given path.\n */\nexport async function importHandlerPath<T>(path: string): Promise<T> {\n let runner!: T\n const [runnerPath, runnerImportName] = path.split('#')\n\n let runnerModule: Record<string, unknown>\n try {\n runnerModule = await dynamicImport<Record<string, unknown>>(runnerPath!)\n } catch (e) {\n throw new Error(\n `Error importing job queue handler module for path ${path}. This is an advanced feature that may require a sophisticated build pipeline, especially when using it in production or within Next.js, e.g. by calling opening the /api/payload-jobs/run endpoint. You will have to transpile the handler files separately and ensure they are available in the same location when the job is run. If you're using an endpoint to execute your jobs, it's recommended to define your handlers as functions directly in your Payload Config, or use import paths handlers outside of Next.js. Import Error: \\n${e instanceof Error ? e.message : 'Unknown error'}`,\n )\n }\n\n // If the path has indicated an #exportName, try to get it\n if (runnerImportName && runnerModule[runnerImportName]) {\n runner = runnerModule[runnerImportName] as T\n }\n\n // If there is a default export, use it\n if (!runner && runnerModule.default) {\n runner = runnerModule.default as T\n }\n\n // Finally, use whatever was imported\n if (!runner) {\n runner = runnerModule as T\n }\n\n return runner\n}\n\n/**\n * The `handler` property of a task config can either be a function or a path to a module that exports a function.\n * This function resolves the handler to a function, either by importing it from the path or returning the function directly\n * if it is already a function.\n */\nexport async function getTaskHandlerFromConfig(taskConfig?: TaskConfig) {\n if (!taskConfig) {\n throw new Error('Task config is required to get the task handler')\n }\n if (typeof taskConfig.handler === 'function') {\n return taskConfig.handler\n } else {\n return await importHandlerPath<TaskHandler<TaskType>>(taskConfig.handler)\n }\n}\n"],"names":["dynamicImport","importHandlerPath","path","runner","runnerPath","runnerImportName","split","runnerModule","e","Error","message","default","getTaskHandlerFromConfig","taskConfig","handler"],"mappings":"AAEA,SAASA,aAAa,QAAQ,yCAAwC;AAEtE;;CAEC,GACD,OAAO,eAAeC,kBAAqBC,IAAY;IACrD,IAAIC;IACJ,MAAM,CAACC,YAAYC,iBAAiB,GAAGH,KAAKI,KAAK,CAAC;IAElD,IAAIC;IACJ,IAAI;QACFA,eAAe,MAAMP,cAAuCI;IAC9D,EAAE,OAAOI,GAAG;QACV,MAAM,IAAIC,MACR,CAAC,kDAAkD,EAAEP,KAAK,+gBAA+gB,EAAEM,aAAaC,QAAQD,EAAEE,OAAO,GAAG,iBAAiB;IAEjoB;IAEA,0DAA0D;IAC1D,IAAIL,oBAAoBE,YAAY,CAACF,iBAAiB,EAAE;QACtDF,SAASI,YAAY,CAACF,iBAAiB;IACzC;IAEA,uCAAuC;IACvC,IAAI,CAACF,UAAUI,aAAaI,OAAO,EAAE;QACnCR,SAASI,aAAaI,OAAO;IAC/B;IAEA,qCAAqC;IACrC,IAAI,CAACR,QAAQ;QACXA,SAASI;IACX;IAEA,OAAOJ;AACT;AAEA;;;;CAIC,GACD,OAAO,eAAeS,yBAAyBC,UAAuB;IACpE,IAAI,CAACA,YAAY;QACf,MAAM,IAAIJ,MAAM;IAClB;IACA,IAAI,OAAOI,WAAWC,OAAO,KAAK,YAAY;QAC5C,OAAOD,WAAWC,OAAO;IAC3B,OAAO;QACL,OAAO,MAAMb,kBAAyCY,WAAWC,OAAO;IAC1E;AACF"} |