(modelRef, modelPaths, errorPrefix)
| 6 | class ResolveError extends Error {} |
| 7 | |
| 8 | function resolveModel(modelRef, modelPaths, errorPrefix) { |
| 9 | try { |
| 10 | if (isString(modelRef)) { |
| 11 | if (isAbsolutePath(modelRef)) { |
| 12 | return requireModel(modelRef); |
| 13 | } else if (modelPaths) { |
| 14 | return requireUsingModelPaths(modelRef, modelPaths); |
| 15 | } |
| 16 | } else { |
| 17 | if (isFunction(modelRef) && !isModelClass(modelRef)) { |
| 18 | modelRef = modelRef(); |
| 19 | } |
| 20 | |
| 21 | if (!isModelClass(modelRef)) { |
| 22 | throw new ResolveError( |
| 23 | `is not a subclass of Model or a file path to a module that exports one. You may be dealing with a require loop. See the documentation section about require loops.`, |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | return modelRef; |
| 28 | } |
| 29 | } catch (err) { |
| 30 | if (err instanceof ResolveError) { |
| 31 | throw new Error(`${errorPrefix}: ${err.message}`); |
| 32 | } else { |
| 33 | throw err; |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | function requireUsingModelPaths(modelRef, modelPaths) { |
| 39 | let firstError = null; |
no test coverage detected