binhend 2.3.11 → 2.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -30,7 +30,8 @@ const csrf = require('./packages/middlewares/src/csrf');
30
30
  const trycatch = require('./packages/middlewares/src/trycatch');
31
31
  const { Auth } = require('./packages/middlewares/src/authorize');
32
32
 
33
- const { config, ConfigLoader, env } = require('./packages/config');
33
+ const { config, ConfigLoader } = require('./packages/config/src/configuration');
34
+ const { env } = require('./packages/config/src/process.env');
34
35
 
35
36
  const CSD = require('./packages/csd/src/csd');
36
37
  const CinCSD = require('./packages/csd/src/controller');
package/jsconfig.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "forceConsistentCasingInFileNames": true,
4
- "moduleResolution": "node",
5
- "target": "ES2022",
6
- "checkJs": true,
7
- "allowJs": true,
8
- "noEmit": true,
3
+ "forceConsistentCasingInFileNames": true, // Enforce consistent file name casing across platforms (Linux is case-sensitive, Windows is not); e.g. require("case/sensitive/path")
4
+ "moduleResolution": "node", // Resolve modules using Node.js resolution algorithm (e.g. require("./utils") → utils.(js|json|node) or utils/index.js)
5
+ "target": "ES2022", // Enable type checking based on the JavaScript version whose syntax and built-ins are supported
6
+
7
+ "checkJs": true, // Enable type checking for .js files (read JSDoc, validate types, report type errors)
8
+ "allowJs": true, // Allow JavaScript files in the project (mainly useful for TypeScript projects)
9
+ "noEmit": true, // Do not emit compiled output files (.js, .d.ts); use TypeScript only for type checking and IntelliSense
10
+
11
+ "resolveJsonModule": true, // Allow importing JSON files as modules with inferred types
12
+ // "maxNodeModuleJsDepth": 10, // Allow VSCode to read JSDoc types from JavaScript files inside node_modules (improves IntelliSense for JS libraries)
9
13
 
10
14
  "baseUrl": "./",
11
15
  "paths": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.3.11",
3
+ "version": "2.3.12",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -4,18 +4,44 @@ const { cli } = require('./configuration').ConfigLoader;
4
4
  const { String } = require('@binhend/validation');
5
5
  const { isString } = require('@binhend/types');
6
6
 
7
- function Options(options = {}) {
8
- options = options || {};
7
+ /**
8
+ * Options used to configure the env loader.
9
+ * @typedef {Object} EnvOptions
10
+ * @property {string} [cli] - Key used to detect env extension from CLI configs (highest priority).
11
+ * @property {string} [ext] - Explicit env extension to load (lower priority).
12
+ * @property {string} [path] - Root path where the config module file is located.
13
+ */
9
14
 
15
+ /**
16
+ * Validator for instances of EnvOptions
17
+ *
18
+ * @param {EnvOptions} [options] - Configuration options need to be validated.
19
+ * @returns {EnvOptions} Validated configuration options.
20
+ */
21
+ function EnvOptions(options) {
10
22
  return {
11
- cli: String(options.cli), // implicitly indicate env extension via a key in CLI configs
12
- ext: String(options.ext), // explicitly declare env extension, lower priority
13
- path: String(options.path, { default: require.main.path }), // root path where config module file located
23
+ cli: String(options?.cli, { message: `Must be string|undefined for option "cli". Current: [${typeof options?.cli}] cli=${options?.cli}` }),
24
+ ext: String(options?.ext, { message: `Must be string|undefined for option "ext". Current: [${typeof options?.ext}] ext=${options?.ext}` }),
25
+ path: String(options?.path, { default: require.main.path }),
14
26
  };
15
27
  }
16
28
 
17
- function env(options = Options()) {
18
- options = options || Options();
29
+ /**
30
+ * Load configuration values from local files, system environment variables,
31
+ * and CLI arguments.
32
+ *
33
+ * Higher-priority sources overwrite values from lower-priority sources.
34
+ *
35
+ * Priority order (highest → lowest):
36
+ * 1. CLI arguments
37
+ * 2. System environment variables
38
+ * 3. Local config files
39
+ *
40
+ * @param {EnvOptions} [options] - Configuration options for loading environment settings.
41
+ * @returns {Record<string, any>} Object containing the merged configuration values.
42
+ */
43
+ function env(options) {
44
+ options = EnvOptions(options);
19
45
 
20
46
  const cliConfigs = cli();
21
47
  const env = isString(options.cli) && cliConfigs.hasOwnProperty(options.cli) ? cliConfigs[options.cli] : options.ext;
@@ -33,7 +59,7 @@ function env(options = Options()) {
33
59
  }
34
60
  }
35
61
  catch (error) {
36
- console.log(`[BINHEND][CONFIG] No config file: ${configModuleFilePath}`);
62
+ console.log(`[BINHEND][CONFIG] No local env file: ${configModuleFilePath}`);
37
63
  }
38
64
 
39
65
  return {