MCPcopy Index your code
hub / github.com/Vincit/objection.js / resolveModel

Function resolveModel

lib/utils/resolveModel.js:8–36  ·  view source on GitHub ↗
(modelRef, modelPaths, errorPrefix)

Source from the content-addressed store, hash-verified

6class ResolveError extends Error {}
7
8function 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
38function requireUsingModelPaths(modelRef, modelPaths) {
39 let firstError = null;

Callers 3

resolveRelatedModelClassFunction · 0.85
resolveModel.jsFile · 0.85

Calls 6

isStringFunction · 0.85
isAbsolutePathFunction · 0.85
requireModelFunction · 0.85
requireUsingModelPathsFunction · 0.85
isFunctionFunction · 0.70
isModelClassFunction · 0.70

Tested by

no test coverage detected