UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 2.15 kB
{"version":3,"file":"lifecycle.mjs","names":[],"sources":["../../../src/libs/image-processor/lifecycle.ts"],"sourcesContent":["import type { Config } from \"../../types/config.js\";\nimport { createAdapterLifecycleContext } from \"../runtime/adapter-lifecycle.js\";\nimport type {\n\tAdapterRuntimeContext,\n\tEnvironmentVariables,\n} from \"../runtime/types.js\";\nimport getImageProcessor from \"./get-adapter.js\";\nimport type { ImageProcessorInstance } from \"./types.js\";\n\n/** Resolve the configured image processor and run its init lifecycle hook. */\nexport const getInitializedImageProcessor = async (\n\tconfig: Config,\n\toptions: {\n\t\tenv?: EnvironmentVariables;\n\t\truntimeContext?: AdapterRuntimeContext;\n\t} = {},\n): Promise<ImageProcessorInstance> => {\n\tconst processor = await getImageProcessor(config);\n\tconst context = createAdapterLifecycleContext({\n\t\tconfig,\n\t\tenv: options.env,\n\t\truntimeContext: options.runtimeContext,\n\t});\n\n\ttry {\n\t\tawait processor.lifecycle?.init?.(context);\n\t} catch (error) {\n\t\tawait Promise.allSettled([processor.lifecycle?.destroy?.(context)]);\n\t\tthrow error;\n\t}\n\n\treturn processor;\n};\n\n/** Run an image processor destroy lifecycle hook when one exists. */\nexport const destroyImageProcessor = async (\n\tprocessor: ImageProcessorInstance | undefined,\n\toptions: {\n\t\tconfig: Config;\n\t\tenv?: EnvironmentVariables;\n\t\truntimeContext?: AdapterRuntimeContext;\n\t},\n): Promise<void> => {\n\tif (!processor) return;\n\n\tawait processor.lifecycle?.destroy?.(\n\t\tcreateAdapterLifecycleContext({\n\t\t\tconfig: options.config,\n\t\t\tenv: options.env,\n\t\t\truntimeContext: options.runtimeContext,\n\t\t}),\n\t);\n};\n"],"mappings":"kHAUA,MAAa,EAA+B,MAC3C,EACA,EAGI,CAAC,IACgC,CACrC,IAAM,EAAY,MAAM,EAAkB,CAAM,EAC1C,EAAU,EAA8B,CAC7C,SACA,IAAK,EAAQ,IACb,eAAgB,EAAQ,cACzB,CAAC,EAED,GAAI,CACH,MAAM,EAAU,WAAW,OAAO,CAAO,CAC1C,OAAS,EAAO,CAEf,MADA,MAAM,QAAQ,WAAW,CAAC,EAAU,WAAW,UAAU,CAAO,CAAC,CAAC,EAC5D,CACP,CAEA,OAAO,CACR,EAGa,EAAwB,MACpC,EACA,IAKmB,CACd,GAEL,MAAM,EAAU,WAAW,UAC1B,EAA8B,CAC7B,OAAQ,EAAQ,OAChB,IAAK,EAAQ,IACb,eAAgB,EAAQ,cACzB,CAAC,CACF,CACD"}