MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / loadDataSourceByName

Function loadDataSourceByName

packages/cli/lib/model-discoverer.js:58–77  ·  view source on GitHub ↗

* Loads a compiled loopback datasource by name * @param name - {string} * @returns {*}

(name)

Source from the content-addressed store, hash-verified

56 * @returns {*}
57 */
58function loadDataSourceByName(name) {
59 debug(`Searching for specified dataSource ${name}`);
60 const dataSourceFiles = getAllDataSourceFiles();
61 debug(`Loaded ${dataSourceFiles.length} dataSource files`);
62
63 // eslint-disable-next-line @typescript-eslint/prefer-for-of
64 for (let i = 0; i < dataSourceFiles.length; i++) {
65 const f = dataSourceFiles[i];
66 const ds = loadDataSource(path.resolve(DEFAULT_DATASOURCE_DIRECTORY, f));
67 if (ds.name === name) {
68 debug(`Found dataSource ${name}`);
69 return ds;
70 } else {
71 debug(`Did not match dataSource ${name} !== ${ds.name}`);
72 }
73 }
74 throw new Error(
75 `Cannot find datasource "${name}" in ${DEFAULT_DATASOURCE_DIRECTORY}`,
76 );
77}
78
79const DEFAULT_DATASOURCE_DIRECTORY = './dist/datasources';
80

Callers

nothing calls this directly

Calls 3

getAllDataSourceFilesFunction · 0.85
loadDataSourceFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected