1- /**
2- * Version: 1.3.0
3- * Description: Loads and validates RAG pipeline configuration with proper error handling
4- * Author: Ali Kahwaji
5- */
6-
7- const fs = require ( 'fs' ) ; // eslint-disable-line global-require
8- const path = require ( 'path' ) ; // eslint-disable-line global-require
9- const { fileURLToPath } = require ( 'url' ) ; // eslint-disable-line global-require
10- const { validateRagrcSchema } = require ( './validate-schema.js' ) ; // eslint-disable-line global-require
11- const { logger } = require ( '../utils/logger.js' ) ; // eslint-disable-line global-require
12-
13- const __filename = fileURLToPath ( import . meta. url ) ;
14- // const __dirname = path.dirname(fileURLToPath(import.meta.url)); // Reserved for future use
15- const __dirname = path . dirname ( __filename ) ;
16-
17- const CONFIG_FILENAME = '.ragrc.json' ;
18-
19- /**
20- * Load and validate a RAG configuration file.
21- * @param {string } [cwd=process.cwd()] - Directory to resolve the _config from
22- * @returns {object } Validated configuration object
23- */
24- function loadRagConfig ( cwd = process . cwd ( ) ) {
25- const configPath = path . resolve ( cwd , CONFIG_FILENAME ) ;
26-
27- if ( ! fs . existsSync ( configPath ) ) {
28- logger . error ( `❌ Config file not found: ${ configPath } ` ) ;
29- throw new Error ( `Config file not found: ${ configPath } ` ) ;
30- }
31-
32- const raw = fs . readFileSync ( configPath , 'utf-8' ) ;
33- let _config ;
34-
35- try {
36- _config = JSON . parse ( raw ) ;
37- } catch ( err ) {
38- logger . error ( '❌ Failed to parse JSON configuration.' ) ;
39- throw new Error ( 'Invalid JSON in _config file.' ) ;
40- }
41-
42- const { valid, errors } = validateRagrcSchema ( _config ) ;
43-
44- if ( ! valid ) {
45- logger . error ( `❌ Config validation failed:\n${ JSON . stringify ( errors , null , 2 ) } ` ) ;
46- throw new Error ( 'Config validation failed' ) ;
47- }
48-
49- return _config ;
50- }
51-
52-
53- module . exports = {
54- loadRagConfig
55- } ;
1+ /**
2+ * Version: 1.3.0
3+ * Description: Loads and validates RAG pipeline configuration with proper error handling
4+ * Author: Ali Kahwaji
5+ */
6+
7+ const fs = require ( 'fs' ) ; // eslint-disable-line global-require
8+ const path = require ( 'path' ) ; // eslint-disable-line global-require
9+ const { fileURLToPath } = require ( 'url' ) ; // eslint-disable-line global-require
10+ const { validateRagrcSchema } = require ( './validate-schema.js' ) ; // eslint-disable-line global-require
11+ const { logger } = require ( '../utils/logger.js' ) ; // eslint-disable-line global-require
12+
13+ const __filename = fileURLToPath ( import . meta. url ) ;
14+ // const __dirname = path.dirname(fileURLToPath(import.meta.url)); // Reserved for future use
15+ const __dirname = path . dirname ( __filename ) ;
16+
17+ const CONFIG_FILENAME = '.ragrc.json' ;
18+
19+ /**
20+ * Load and validate a RAG configuration file.
21+ * @param {string } [cwd=process.cwd()] - Directory to resolve the config from
22+ * @returns {object } Validated configuration object
23+ */
24+ function loadRagConfig ( cwd = process . cwd ( ) ) {
25+ const configPath = path . resolve ( cwd , CONFIG_FILENAME ) ;
26+
27+ if ( ! fs . existsSync ( configPath ) ) {
28+ logger . error ( `❌ Config file not found: ${ configPath } ` ) ;
29+ throw new Error ( `Config file not found: ${ configPath } ` ) ;
30+ }
31+
32+ const raw = fs . readFileSync ( configPath , 'utf-8' ) ;
33+ let config ;
34+
35+ try {
36+ config = JSON . parse ( raw ) ;
37+ } catch ( err ) {
38+ logger . error ( '❌ Failed to parse JSON configuration.' ) ;
39+ throw new Error ( 'Invalid JSON in config file.' ) ;
40+ }
41+
42+ const { valid, errors } = validateRagrcSchema ( config ) ;
43+
44+ if ( ! valid ) {
45+ logger . error ( `❌ Config validation failed:\n${ JSON . stringify ( errors , null , 2 ) } ` ) ;
46+ throw new Error ( 'Config validation failed' ) ;
47+ }
48+
49+ return config ;
50+ }
51+
52+ module . exports = {
53+ loadRagConfig
54+ } ;
0 commit comments