12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- exports.loadAdapter = loadAdapter;
- exports.loadModule = loadModule;
- /**
- * @module AdapterLoader
- */
- /**
- * @static
- * Attempt to load an adapter or fallback to the default.
- * @param {Adapter} adapter an adapter
- * @param {Adapter} defaultAdapter the default adapter to load
- * @param {any} options options to pass to the contstructor
- * @returns {Object} the loaded adapter
- */
- function loadAdapter(adapter, defaultAdapter, options) {
- if (!adapter) {
- if (!defaultAdapter) {
- return options;
- }
- // Load from the default adapter when no adapter is set
- return loadAdapter(defaultAdapter, undefined, options);
- } else if (typeof adapter === 'function') {
- try {
- return adapter(options);
- } catch (e) {
- if (e.name === 'TypeError') {
- var Adapter = adapter;
- return new Adapter(options);
- } else {
- throw e;
- }
- }
- } else if (typeof adapter === 'string') {
- /* eslint-disable */
- adapter = require(adapter);
- // If it's define as a module, get the default
- if (adapter.default) {
- adapter = adapter.default;
- }
- return loadAdapter(adapter, undefined, options);
- } else if (adapter.module) {
- return loadAdapter(adapter.module, undefined, adapter.options);
- } else if (adapter.class) {
- return loadAdapter(adapter.class, undefined, adapter.options);
- } else if (adapter.adapter) {
- return loadAdapter(adapter.adapter, undefined, adapter.options);
- }
- // return the adapter as provided
- return adapter;
- }
- async function loadModule(modulePath) {
- let module;
- try {
- module = require(modulePath);
- } catch (err) {
- if (err.code === 'ERR_REQUIRE_ESM') {
- module = await import(modulePath);
- if (module.default) {
- module = module.default;
- }
- } else {
- throw err;
- }
- }
- return module;
- }
- var _default = exports.default = loadAdapter;
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJsb2FkQWRhcHRlciIsImFkYXB0ZXIiLCJkZWZhdWx0QWRhcHRlciIsIm9wdGlvbnMiLCJ1bmRlZmluZWQiLCJlIiwibmFtZSIsIkFkYXB0ZXIiLCJyZXF1a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