@theunwalked/cardigantime 0.0.2 → 0.0.3

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/dist/constants.js CHANGED
@@ -1,14 +1,24 @@
1
- const DEFAULT_ENCODING = 'utf8';
2
- const DEFAULT_CONFIG_FILE = 'config.yaml';
3
- const DEFAULT_OPTIONS = {
1
+ /** Default file encoding for reading configuration files */ const DEFAULT_ENCODING = 'utf8';
2
+ /** Default configuration file name to look for in the config directory */ const DEFAULT_CONFIG_FILE = 'config.yaml';
3
+ /**
4
+ * Default configuration options applied when creating a Cardigantime instance.
5
+ * These provide sensible defaults that work for most use cases.
6
+ */ const DEFAULT_OPTIONS = {
4
7
  configFile: DEFAULT_CONFIG_FILE,
5
8
  isRequired: false,
6
9
  encoding: DEFAULT_ENCODING
7
10
  };
8
- const DEFAULT_FEATURES = [
11
+ /**
12
+ * Default features enabled when creating a Cardigantime instance.
13
+ * Currently includes only the 'config' feature for configuration file support.
14
+ */ const DEFAULT_FEATURES = [
9
15
  'config'
10
16
  ];
11
- const DEFAULT_LOGGER = {
17
+ /**
18
+ * Default logger implementation using console methods.
19
+ * Provides basic logging functionality when no custom logger is specified.
20
+ * The verbose and silly methods are no-ops to avoid excessive output.
21
+ */ const DEFAULT_LOGGER = {
12
22
  // eslint-disable-next-line no-console
13
23
  debug: console.debug,
14
24
  // eslint-disable-next-line no-console
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["import { DefaultOptions, Feature, Logger } from \"./types\";\n\nexport const VERSION = '__VERSION__ (__GIT_BRANCH__/__GIT_COMMIT__ __GIT_TAGS__ __GIT_COMMIT_DATE__) __SYSTEM_INFO__';\nexport const PROGRAM_NAME = 'cardigantime';\nexport const DEFAULT_ENCODING = 'utf8';\nexport const DEFAULT_CONFIG_FILE = 'config.yaml';\n\nexport const DEFAULT_OPTIONS: Partial<DefaultOptions> = {\n configFile: DEFAULT_CONFIG_FILE,\n isRequired: false,\n encoding: DEFAULT_ENCODING,\n}\n\nexport const DEFAULT_FEATURES: Feature[] = ['config'];\n\nexport const DEFAULT_LOGGER: Logger = {\n // eslint-disable-next-line no-console\n debug: console.debug,\n // eslint-disable-next-line no-console\n info: console.info,\n // eslint-disable-next-line no-console\n warn: console.warn,\n // eslint-disable-next-line no-console\n error: console.error,\n\n verbose: () => { },\n\n silly: () => { },\n}\n"],"names":["DEFAULT_ENCODING","DEFAULT_CONFIG_FILE","DEFAULT_OPTIONS","configFile","isRequired","encoding","DEFAULT_FEATURES","DEFAULT_LOGGER","debug","console","info","warn","error","verbose","silly"],"mappings":"AAIO,MAAMA,mBAAmB;AACzB,MAAMC,sBAAsB;MAEtBC,eAA2C,GAAA;IACpDC,UAAYF,EAAAA,mBAAAA;IACZG,UAAY,EAAA,KAAA;IACZC,QAAUL,EAAAA;AACd;MAEaM,gBAA8B,GAAA;AAAC,IAAA;;MAE/BC,cAAyB,GAAA;;AAElCC,IAAAA,KAAAA,EAAOC,QAAQD,KAAK;;AAEpBE,IAAAA,IAAAA,EAAMD,QAAQC,IAAI;;AAElBC,IAAAA,IAAAA,EAAMF,QAAQE,IAAI;;AAElBC,IAAAA,KAAAA,EAAOH,QAAQG,KAAK;AAEpBC,IAAAA,OAAAA,EAAS,IAAQ,EAAA;AAEjBC,IAAAA,KAAAA,EAAO,IAAQ;AACnB;;;;"}
1
+ {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["import { DefaultOptions, Feature, Logger } from \"./types\";\n\n/** Version string populated at build time with git and system information */\nexport const VERSION = '__VERSION__ (__GIT_BRANCH__/__GIT_COMMIT__ __GIT_TAGS__ __GIT_COMMIT_DATE__) __SYSTEM_INFO__';\n\n/** The program name used in CLI help and error messages */\nexport const PROGRAM_NAME = 'cardigantime';\n\n/** Default file encoding for reading configuration files */\nexport const DEFAULT_ENCODING = 'utf8';\n\n/** Default configuration file name to look for in the config directory */\nexport const DEFAULT_CONFIG_FILE = 'config.yaml';\n\n/**\n * Default configuration options applied when creating a Cardigantime instance.\n * These provide sensible defaults that work for most use cases.\n */\nexport const DEFAULT_OPTIONS: Partial<DefaultOptions> = {\n configFile: DEFAULT_CONFIG_FILE,\n isRequired: false,\n encoding: DEFAULT_ENCODING,\n}\n\n/**\n * Default features enabled when creating a Cardigantime instance.\n * Currently includes only the 'config' feature for configuration file support.\n */\nexport const DEFAULT_FEATURES: Feature[] = ['config'];\n\n/**\n * Default logger implementation using console methods.\n * Provides basic logging functionality when no custom logger is specified.\n * The verbose and silly methods are no-ops to avoid excessive output.\n */\nexport const DEFAULT_LOGGER: Logger = {\n // eslint-disable-next-line no-console\n debug: console.debug,\n // eslint-disable-next-line no-console\n info: console.info,\n // eslint-disable-next-line no-console\n warn: console.warn,\n // eslint-disable-next-line no-console\n error: console.error,\n\n verbose: () => { },\n\n silly: () => { },\n}\n"],"names":["DEFAULT_ENCODING","DEFAULT_CONFIG_FILE","DEFAULT_OPTIONS","configFile","isRequired","encoding","DEFAULT_FEATURES","DEFAULT_LOGGER","debug","console","info","warn","error","verbose","silly"],"mappings":"AAQA,6DACO,MAAMA,gBAAAA,GAAmB;AAEhC,2EACO,MAAMC,mBAAAA,GAAsB;AAEnC;;;UAIaC,eAAAA,GAA2C;IACpDC,UAAAA,EAAYF,mBAAAA;IACZG,UAAAA,EAAY,KAAA;IACZC,QAAAA,EAAUL;AACd;AAEA;;;UAIaM,gBAAAA,GAA8B;AAAC,IAAA;;AAE5C;;;;UAKaC,cAAAA,GAAyB;;AAElCC,IAAAA,KAAAA,EAAOC,QAAQD,KAAK;;AAEpBE,IAAAA,IAAAA,EAAMD,QAAQC,IAAI;;AAElBC,IAAAA,IAAAA,EAAMF,QAAQE,IAAI;;AAElBC,IAAAA,KAAAA,EAAOH,QAAQG,KAAK;AAEpBC,IAAAA,OAAAA,EAAS,IAAA,EAAQ;AAEjBC,IAAAA,KAAAA,EAAO,IAAA;AACX;;;;"}
@@ -1,5 +1,31 @@
1
+ /**
2
+ * Error thrown when CLI arguments or function parameters are invalid.
3
+ *
4
+ * This error provides specific context about which argument failed validation
5
+ * and why, making it easier for users to fix their command-line usage or
6
+ * for developers to debug parameter issues.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * throw new ArgumentError('config-directory', 'Path cannot be empty');
11
+ * // Error message: "Path cannot be empty"
12
+ * // error.argument: "config-directory"
13
+ * ```
14
+ */
1
15
  export declare class ArgumentError extends Error {
16
+ /** The name of the argument that caused the error */
2
17
  private argumentName;
18
+ /**
19
+ * Creates a new ArgumentError instance.
20
+ *
21
+ * @param argumentName - The name of the invalid argument
22
+ * @param message - Description of why the argument is invalid
23
+ */
3
24
  constructor(argumentName: string, message: string);
25
+ /**
26
+ * Gets the name of the argument that caused this error.
27
+ *
28
+ * @returns The argument name
29
+ */
4
30
  get argument(): string;
5
31
  }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Error thrown when CLI arguments or function parameters are invalid.
3
+ *
4
+ * This error provides specific context about which argument failed validation
5
+ * and why, making it easier for users to fix their command-line usage or
6
+ * for developers to debug parameter issues.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * throw new ArgumentError('config-directory', 'Path cannot be empty');
11
+ * // Error message: "Path cannot be empty"
12
+ * // error.argument: "config-directory"
13
+ * ```
14
+ */ function _define_property(obj, key, value) {
15
+ if (key in obj) {
16
+ Object.defineProperty(obj, key, {
17
+ value: value,
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true
21
+ });
22
+ } else {
23
+ obj[key] = value;
24
+ }
25
+ return obj;
26
+ }
27
+ class ArgumentError extends Error {
28
+ /**
29
+ * Gets the name of the argument that caused this error.
30
+ *
31
+ * @returns The argument name
32
+ */ get argument() {
33
+ return this.argumentName;
34
+ }
35
+ /**
36
+ * Creates a new ArgumentError instance.
37
+ *
38
+ * @param argumentName - The name of the invalid argument
39
+ * @param message - Description of why the argument is invalid
40
+ */ constructor(argumentName, message){
41
+ super(`${message}`), /** The name of the argument that caused the error */ _define_property(this, "argumentName", void 0);
42
+ this.name = 'ArgumentError';
43
+ this.argumentName = argumentName;
44
+ }
45
+ }
46
+
47
+ export { ArgumentError };
48
+ //# sourceMappingURL=ArgumentError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArgumentError.js","sources":["../../src/error/ArgumentError.ts"],"sourcesContent":["/**\n * Error thrown when CLI arguments or function parameters are invalid.\n * \n * This error provides specific context about which argument failed validation\n * and why, making it easier for users to fix their command-line usage or\n * for developers to debug parameter issues.\n * \n * @example\n * ```typescript\n * throw new ArgumentError('config-directory', 'Path cannot be empty');\n * // Error message: \"Path cannot be empty\"\n * // error.argument: \"config-directory\"\n * ```\n */\nexport class ArgumentError extends Error {\n /** The name of the argument that caused the error */\n private argumentName: string;\n\n /**\n * Creates a new ArgumentError instance.\n * \n * @param argumentName - The name of the invalid argument\n * @param message - Description of why the argument is invalid\n */\n constructor(argumentName: string, message: string) {\n super(`${message}`);\n this.name = 'ArgumentError';\n this.argumentName = argumentName;\n }\n\n /**\n * Gets the name of the argument that caused this error.\n * \n * @returns The argument name\n */\n get argument(): string {\n return this.argumentName;\n }\n}"],"names":["ArgumentError","Error","argument","argumentName","message","name"],"mappings":"AAAA;;;;;;;;;;;;;AAaC,IAAA,SAAA,gBAAA,CAAA,GAAA,EAAA,GAAA,EAAA,KAAA,EAAA;;;;;;;;;;;;;AACM,MAAMA,aAAAA,SAAsBC,KAAAA,CAAAA;AAgB/B;;;;AAIC,QACD,IAAIC,QAAAA,GAAmB;QACnB,OAAO,IAAI,CAACC,YAAY;AAC5B;AAnBA;;;;;AAKC,QACD,WAAA,CAAYA,YAAoB,EAAEC,OAAe,CAAE;QAC/C,KAAK,CAAC,GAAGA,OAAAA,CAAAA,CAAS,CAAA,wDATtB,gBAAA,CAAA,IAAA,EAAQD,gBAAR,MAAA,CAAA;QAUI,IAAI,CAACE,IAAI,GAAG,eAAA;QACZ,IAAI,CAACF,YAAY,GAAGA,YAAAA;AACxB;AAUJ;;;;"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Error thrown when configuration validation fails
3
+ */
4
+ export declare class ConfigurationError extends Error {
5
+ readonly errorType: 'validation' | 'schema' | 'extra_keys';
6
+ readonly details?: any;
7
+ readonly configPath?: string;
8
+ constructor(errorType: 'validation' | 'schema' | 'extra_keys', message: string, details?: any, configPath?: string);
9
+ /**
10
+ * Creates a validation error for when config doesn't match the schema
11
+ */
12
+ static validation(message: string, zodError?: any, configPath?: string): ConfigurationError;
13
+ /**
14
+ * Creates an error for when extra/unknown keys are found
15
+ */
16
+ static extraKeys(extraKeys: string[], allowedKeys: string[], configPath?: string): ConfigurationError;
17
+ /**
18
+ * Creates a schema error for when the configuration schema itself is invalid
19
+ */
20
+ static schema(message: string, details?: any): ConfigurationError;
21
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Error thrown when configuration validation fails
3
+ */ function _define_property(obj, key, value) {
4
+ if (key in obj) {
5
+ Object.defineProperty(obj, key, {
6
+ value: value,
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true
10
+ });
11
+ } else {
12
+ obj[key] = value;
13
+ }
14
+ return obj;
15
+ }
16
+ class ConfigurationError extends Error {
17
+ /**
18
+ * Creates a validation error for when config doesn't match the schema
19
+ */ static validation(message, zodError, configPath) {
20
+ return new ConfigurationError('validation', message, zodError, configPath);
21
+ }
22
+ /**
23
+ * Creates an error for when extra/unknown keys are found
24
+ */ static extraKeys(extraKeys, allowedKeys, configPath) {
25
+ const message = `Unknown configuration keys found: ${extraKeys.join(', ')}. Allowed keys are: ${allowedKeys.join(', ')}`;
26
+ return new ConfigurationError('extra_keys', message, {
27
+ extraKeys,
28
+ allowedKeys
29
+ }, configPath);
30
+ }
31
+ /**
32
+ * Creates a schema error for when the configuration schema itself is invalid
33
+ */ static schema(message, details) {
34
+ return new ConfigurationError('schema', message, details);
35
+ }
36
+ constructor(errorType, message, details, configPath){
37
+ super(message), _define_property(this, "errorType", void 0), _define_property(this, "details", void 0), _define_property(this, "configPath", void 0);
38
+ this.name = 'ConfigurationError';
39
+ this.errorType = errorType;
40
+ this.details = details;
41
+ this.configPath = configPath;
42
+ }
43
+ }
44
+
45
+ export { ConfigurationError };
46
+ //# sourceMappingURL=ConfigurationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigurationError.js","sources":["../../src/error/ConfigurationError.ts"],"sourcesContent":["/**\n * Error thrown when configuration validation fails\n */\nexport class ConfigurationError extends Error {\n public readonly errorType: 'validation' | 'schema' | 'extra_keys';\n public readonly details?: any;\n public readonly configPath?: string;\n\n constructor(\n errorType: 'validation' | 'schema' | 'extra_keys',\n message: string,\n details?: any,\n configPath?: string\n ) {\n super(message);\n this.name = 'ConfigurationError';\n this.errorType = errorType;\n this.details = details;\n this.configPath = configPath;\n }\n\n /**\n * Creates a validation error for when config doesn't match the schema\n */\n static validation(message: string, zodError?: any, configPath?: string): ConfigurationError {\n return new ConfigurationError('validation', message, zodError, configPath);\n }\n\n /**\n * Creates an error for when extra/unknown keys are found\n */\n static extraKeys(extraKeys: string[], allowedKeys: string[], configPath?: string): ConfigurationError {\n const message = `Unknown configuration keys found: ${extraKeys.join(', ')}. Allowed keys are: ${allowedKeys.join(', ')}`;\n return new ConfigurationError('extra_keys', message, { extraKeys, allowedKeys }, configPath);\n }\n\n /**\n * Creates a schema error for when the configuration schema itself is invalid\n */\n static schema(message: string, details?: any): ConfigurationError {\n return new ConfigurationError('schema', message, details);\n }\n} "],"names":["ConfigurationError","Error","validation","message","zodError","configPath","extraKeys","allowedKeys","join","schema","details","errorType","name"],"mappings":"AAAA;;AAEC,IAAA,SAAA,gBAAA,CAAA,GAAA,EAAA,GAAA,EAAA,KAAA,EAAA;;;;;;;;;;;;;AACM,MAAMA,kBAAAA,SAA2BC,KAAAA,CAAAA;AAkBpC;;AAEC,QACD,OAAOC,UAAAA,CAAWC,OAAe,EAAEC,QAAc,EAAEC,UAAmB,EAAsB;AACxF,QAAA,OAAO,IAAIL,kBAAAA,CAAmB,YAAA,EAAcG,OAAAA,EAASC,QAAAA,EAAUC,UAAAA,CAAAA;AACnE;AAEA;;AAEC,QACD,OAAOC,SAAAA,CAAUA,SAAmB,EAAEC,WAAqB,EAAEF,UAAmB,EAAsB;AAClG,QAAA,MAAMF,OAAAA,GAAU,CAAC,kCAAkC,EAAEG,SAAAA,CAAUE,IAAI,CAAC,IAAA,CAAA,CAAM,oBAAoB,EAAED,WAAAA,CAAYC,IAAI,CAAC,IAAA,CAAA,CAAA,CAAO;QACxH,OAAO,IAAIR,kBAAAA,CAAmB,YAAA,EAAcG,OAAAA,EAAS;AAAEG,YAAAA,SAAAA;AAAWC,YAAAA;SAAY,EAAGF,UAAAA,CAAAA;AACrF;AAEA;;AAEC,QACD,OAAOI,MAAAA,CAAON,OAAe,EAAEO,OAAa,EAAsB;QAC9D,OAAO,IAAIV,kBAAAA,CAAmB,QAAA,EAAUG,OAAAA,EAASO,OAAAA,CAAAA;AACrD;AAjCA,IAAA,WAAA,CACIC,SAAiD,EACjDR,OAAe,EACfO,OAAa,EACbL,UAAmB,CACrB;AACE,QAAA,KAAK,CAACF,OAAAA,CAAAA,EAVV,gBAAA,CAAA,IAAA,EAAgBQ,WAAAA,EAAhB,MAAA,CAAA,EACA,gBAAA,CAAA,IAAA,EAAgBD,SAAAA,EAAhB,MAAA,CAAA,EACA,gBAAA,CAAA,IAAA,EAAgBL,YAAAA,EAAhB,MAAA,CAAA;QASI,IAAI,CAACO,IAAI,GAAG,oBAAA;QACZ,IAAI,CAACD,SAAS,GAAGA,SAAAA;QACjB,IAAI,CAACD,OAAO,GAAGA,OAAAA;QACf,IAAI,CAACL,UAAU,GAAGA,UAAAA;AACtB;AAuBJ;;;;"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Error thrown when file system operations fail
3
+ */
4
+ export declare class FileSystemError extends Error {
5
+ readonly errorType: 'not_found' | 'not_readable' | 'not_writable' | 'creation_failed' | 'operation_failed';
6
+ readonly path: string;
7
+ readonly operation: string;
8
+ readonly originalError?: Error;
9
+ constructor(errorType: 'not_found' | 'not_readable' | 'not_writable' | 'creation_failed' | 'operation_failed', message: string, path: string, operation: string, originalError?: Error);
10
+ /**
11
+ * Creates an error for when a required directory doesn't exist
12
+ */
13
+ static directoryNotFound(path: string, isRequired?: boolean): FileSystemError;
14
+ /**
15
+ * Creates an error for when a directory exists but isn't readable
16
+ */
17
+ static directoryNotReadable(path: string): FileSystemError;
18
+ /**
19
+ * Creates an error for directory creation failures
20
+ */
21
+ static directoryCreationFailed(path: string, originalError: Error): FileSystemError;
22
+ /**
23
+ * Creates an error for file operation failures (glob, etc.)
24
+ */
25
+ static operationFailed(operation: string, path: string, originalError: Error): FileSystemError;
26
+ /**
27
+ * Creates an error for when a file is not found
28
+ */
29
+ static fileNotFound(path: string): FileSystemError;
30
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Error thrown when file system operations fail
3
+ */ function _define_property(obj, key, value) {
4
+ if (key in obj) {
5
+ Object.defineProperty(obj, key, {
6
+ value: value,
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true
10
+ });
11
+ } else {
12
+ obj[key] = value;
13
+ }
14
+ return obj;
15
+ }
16
+ class FileSystemError extends Error {
17
+ /**
18
+ * Creates an error for when a required directory doesn't exist
19
+ */ static directoryNotFound(path, isRequired = false) {
20
+ const message = isRequired ? 'Configuration directory does not exist and is required' : 'Configuration directory not found';
21
+ return new FileSystemError('not_found', message, path, 'directory_access');
22
+ }
23
+ /**
24
+ * Creates an error for when a directory exists but isn't readable
25
+ */ static directoryNotReadable(path) {
26
+ const message = 'Configuration directory exists but is not readable';
27
+ return new FileSystemError('not_readable', message, path, 'directory_read');
28
+ }
29
+ /**
30
+ * Creates an error for directory creation failures
31
+ */ static directoryCreationFailed(path, originalError) {
32
+ const message = 'Failed to create directory: ' + (originalError.message || 'Unknown error');
33
+ return new FileSystemError('creation_failed', message, path, 'directory_create', originalError);
34
+ }
35
+ /**
36
+ * Creates an error for file operation failures (glob, etc.)
37
+ */ static operationFailed(operation, path, originalError) {
38
+ const message = `Failed to ${operation}: ${originalError.message || 'Unknown error'}`;
39
+ return new FileSystemError('operation_failed', message, path, operation, originalError);
40
+ }
41
+ /**
42
+ * Creates an error for when a file is not found
43
+ */ static fileNotFound(path) {
44
+ const message = 'Configuration file not found';
45
+ return new FileSystemError('not_found', message, path, 'file_read');
46
+ }
47
+ constructor(errorType, message, path, operation, originalError){
48
+ super(message), _define_property(this, "errorType", void 0), _define_property(this, "path", void 0), _define_property(this, "operation", void 0), _define_property(this, "originalError", void 0);
49
+ this.name = 'FileSystemError';
50
+ this.errorType = errorType;
51
+ this.path = path;
52
+ this.operation = operation;
53
+ this.originalError = originalError;
54
+ }
55
+ }
56
+
57
+ export { FileSystemError };
58
+ //# sourceMappingURL=FileSystemError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileSystemError.js","sources":["../../src/error/FileSystemError.ts"],"sourcesContent":["/**\n * Error thrown when file system operations fail\n */\nexport class FileSystemError extends Error {\n public readonly errorType: 'not_found' | 'not_readable' | 'not_writable' | 'creation_failed' | 'operation_failed';\n public readonly path: string;\n public readonly operation: string;\n public readonly originalError?: Error;\n\n constructor(\n errorType: 'not_found' | 'not_readable' | 'not_writable' | 'creation_failed' | 'operation_failed',\n message: string,\n path: string,\n operation: string,\n originalError?: Error\n ) {\n super(message);\n this.name = 'FileSystemError';\n this.errorType = errorType;\n this.path = path;\n this.operation = operation;\n this.originalError = originalError;\n }\n\n /**\n * Creates an error for when a required directory doesn't exist\n */\n static directoryNotFound(path: string, isRequired: boolean = false): FileSystemError {\n const message = isRequired\n ? 'Configuration directory does not exist and is required'\n : 'Configuration directory not found';\n return new FileSystemError('not_found', message, path, 'directory_access');\n }\n\n /**\n * Creates an error for when a directory exists but isn't readable\n */\n static directoryNotReadable(path: string): FileSystemError {\n const message = 'Configuration directory exists but is not readable';\n return new FileSystemError('not_readable', message, path, 'directory_read');\n }\n\n /**\n * Creates an error for directory creation failures\n */\n static directoryCreationFailed(path: string, originalError: Error): FileSystemError {\n const message = 'Failed to create directory: ' + (originalError.message || 'Unknown error');\n return new FileSystemError('creation_failed', message, path, 'directory_create', originalError);\n }\n\n /**\n * Creates an error for file operation failures (glob, etc.)\n */\n static operationFailed(operation: string, path: string, originalError: Error): FileSystemError {\n const message = `Failed to ${operation}: ${originalError.message || 'Unknown error'}`;\n return new FileSystemError('operation_failed', message, path, operation, originalError);\n }\n\n /**\n * Creates an error for when a file is not found\n */\n static fileNotFound(path: string): FileSystemError {\n const message = 'Configuration file not found';\n return new FileSystemError('not_found', message, path, 'file_read');\n }\n} "],"names":["FileSystemError","Error","directoryNotFound","path","isRequired","message","directoryNotReadable","directoryCreationFailed","originalError","operationFailed","operation","fileNotFound","errorType","name"],"mappings":"AAAA;;AAEC,IAAA,SAAA,gBAAA,CAAA,GAAA,EAAA,GAAA,EAAA,KAAA,EAAA;;;;;;;;;;;;;AACM,MAAMA,eAAAA,SAAwBC,KAAAA,CAAAA;AAqBjC;;AAEC,QACD,OAAOC,iBAAAA,CAAkBC,IAAY,EAAEC,UAAAA,GAAsB,KAAK,EAAmB;QACjF,MAAMC,OAAAA,GAAUD,aACV,wDAAA,GACA,mCAAA;AACN,QAAA,OAAO,IAAIJ,eAAAA,CAAgB,WAAA,EAAaK,OAAAA,EAASF,IAAAA,EAAM,kBAAA,CAAA;AAC3D;AAEA;;QAGA,OAAOG,oBAAAA,CAAqBH,IAAY,EAAmB;AACvD,QAAA,MAAME,OAAAA,GAAU,oDAAA;AAChB,QAAA,OAAO,IAAIL,eAAAA,CAAgB,cAAA,EAAgBK,OAAAA,EAASF,IAAAA,EAAM,gBAAA,CAAA;AAC9D;AAEA;;AAEC,QACD,OAAOI,uBAAAA,CAAwBJ,IAAY,EAAEK,aAAoB,EAAmB;AAChF,QAAA,MAAMH,UAAU,8BAAA,IAAkCG,aAAAA,CAAcH,OAAO,IAAI,eAAc,CAAA;AACzF,QAAA,OAAO,IAAIL,eAAAA,CAAgB,iBAAA,EAAmBK,OAAAA,EAASF,MAAM,kBAAA,EAAoBK,aAAAA,CAAAA;AACrF;AAEA;;AAEC,QACD,OAAOC,eAAAA,CAAgBC,SAAiB,EAAEP,IAAY,EAAEK,aAAoB,EAAmB;QAC3F,MAAMH,OAAAA,GAAU,CAAC,UAAU,EAAEK,SAAAA,CAAU,EAAE,EAAEF,aAAAA,CAAcH,OAAO,IAAI,eAAA,CAAA,CAAiB;AACrF,QAAA,OAAO,IAAIL,eAAAA,CAAgB,kBAAA,EAAoBK,OAAAA,EAASF,MAAMO,SAAAA,EAAWF,aAAAA,CAAAA;AAC7E;AAEA;;QAGA,OAAOG,YAAAA,CAAaR,IAAY,EAAmB;AAC/C,QAAA,MAAME,OAAAA,GAAU,8BAAA;AAChB,QAAA,OAAO,IAAIL,eAAAA,CAAgB,WAAA,EAAaK,OAAAA,EAASF,IAAAA,EAAM,WAAA,CAAA;AAC3D;IAvDA,WAAA,CACIS,SAAiG,EACjGP,OAAe,EACfF,IAAY,EACZO,SAAiB,EACjBF,aAAqB,CACvB;AACE,QAAA,KAAK,CAACH,OAAAA,CAAAA,EAZV,gBAAA,CAAA,IAAA,EAAgBO,WAAAA,EAAhB,SACA,gBAAA,CAAA,IAAA,EAAgBT,MAAAA,EAAhB,MAAA,CAAA,EACA,uBAAgBO,WAAAA,EAAhB,MAAA,CAAA,EACA,gBAAA,CAAA,IAAA,EAAgBF,iBAAhB,MAAA,CAAA;QAUI,IAAI,CAACK,IAAI,GAAG,iBAAA;QACZ,IAAI,CAACD,SAAS,GAAGA,SAAAA;QACjB,IAAI,CAACT,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACO,SAAS,GAAGA,SAAAA;QACjB,IAAI,CAACF,aAAa,GAAGA,aAAAA;AACzB;AA2CJ;;;;"}
@@ -0,0 +1,3 @@
1
+ export { ArgumentError } from './ArgumentError';
2
+ export { ConfigurationError } from './ConfigurationError';
3
+ export { FileSystemError } from './FileSystemError';
package/dist/read.d.ts CHANGED
@@ -1,3 +1,33 @@
1
1
  import { z, ZodObject } from 'zod';
2
2
  import { Args, ConfigSchema, Options } from './types';
3
+ /**
4
+ * Reads configuration from files and merges it with CLI arguments.
5
+ *
6
+ * This function implements the core configuration loading logic:
7
+ * 1. Validates and resolves the configuration directory path
8
+ * 2. Attempts to read the YAML configuration file
9
+ * 3. Safely parses the YAML content with security protections
10
+ * 4. Merges file configuration with runtime arguments
11
+ * 5. Returns a typed configuration object
12
+ *
13
+ * The function handles missing files gracefully and provides detailed
14
+ * logging for troubleshooting configuration issues.
15
+ *
16
+ * @template T - The Zod schema shape type for configuration validation
17
+ * @param args - Parsed command-line arguments containing potential config overrides
18
+ * @param options - Cardigantime options with defaults, schema, and logger
19
+ * @returns Promise resolving to the merged and typed configuration object
20
+ * @throws {Error} When configuration directory is invalid or required files cannot be read
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const config = await read(cliArgs, {
25
+ * defaults: { configDirectory: './config', configFile: 'app.yaml' },
26
+ * configShape: MySchema.shape,
27
+ * logger: console,
28
+ * features: ['config']
29
+ * });
30
+ * // config is fully typed based on your schema
31
+ * ```
32
+ */
3
33
  export declare const read: <T extends z.ZodRawShape>(args: Args, options: Options<T>) => Promise<z.infer<ZodObject<T & typeof ConfigSchema.shape>>>;
package/dist/read.js CHANGED
@@ -1,36 +1,129 @@
1
1
  import * as yaml from 'js-yaml';
2
- import path from 'path';
2
+ import * as path from 'path';
3
3
  import { create } from './util/storage.js';
4
4
 
5
- function clean(obj) {
5
+ /**
6
+ * Removes undefined values from an object to create a clean configuration.
7
+ * This is used to merge configuration sources while avoiding undefined pollution.
8
+ *
9
+ * @param obj - The object to clean
10
+ * @returns A new object with undefined values filtered out
11
+ */ function clean(obj) {
6
12
  return Object.fromEntries(Object.entries(obj).filter(([_, v])=>v !== undefined));
7
13
  }
8
- const read = async (args, options)=>{
14
+ /**
15
+ * Validates and secures a user-provided path to prevent path traversal attacks.
16
+ *
17
+ * Security checks include:
18
+ * - Path traversal prevention (blocks '..')
19
+ * - Absolute path detection
20
+ * - Path separator validation
21
+ *
22
+ * @param userPath - The user-provided path component
23
+ * @param basePath - The base directory to join the path with
24
+ * @returns The safely joined and normalized path
25
+ * @throws {Error} When path traversal or absolute paths are detected
26
+ */ function validatePath(userPath, basePath) {
27
+ if (!userPath || !basePath) {
28
+ throw new Error('Invalid path parameters');
29
+ }
30
+ const normalized = path.normalize(userPath);
31
+ // Prevent path traversal attacks
32
+ if (normalized.includes('..') || path.isAbsolute(normalized)) {
33
+ throw new Error('Invalid path: path traversal detected');
34
+ }
35
+ // Ensure the path doesn't start with a path separator
36
+ if (normalized.startsWith('/') || normalized.startsWith('\\')) {
37
+ throw new Error('Invalid path: absolute path detected');
38
+ }
39
+ return path.join(basePath, normalized);
40
+ }
41
+ /**
42
+ * Validates a configuration directory path for security and basic formatting.
43
+ *
44
+ * Performs validation to prevent:
45
+ * - Null byte injection attacks
46
+ * - Extremely long paths that could cause DoS
47
+ * - Empty or invalid directory specifications
48
+ *
49
+ * @param configDir - The configuration directory path to validate
50
+ * @returns The normalized configuration directory path
51
+ * @throws {Error} When the directory path is invalid or potentially dangerous
52
+ */ function validateConfigDirectory(configDir) {
53
+ if (!configDir) {
54
+ throw new Error('Configuration directory is required');
55
+ }
56
+ // Check for null bytes which could be used for path injection
57
+ if (configDir.includes('\0')) {
58
+ throw new Error('Invalid path: null byte detected');
59
+ }
60
+ const normalized = path.normalize(configDir);
61
+ // Basic validation - could be expanded based on requirements
62
+ if (normalized.length > 1000) {
63
+ throw new Error('Configuration directory path too long');
64
+ }
65
+ return normalized;
66
+ }
67
+ /**
68
+ * Reads configuration from files and merges it with CLI arguments.
69
+ *
70
+ * This function implements the core configuration loading logic:
71
+ * 1. Validates and resolves the configuration directory path
72
+ * 2. Attempts to read the YAML configuration file
73
+ * 3. Safely parses the YAML content with security protections
74
+ * 4. Merges file configuration with runtime arguments
75
+ * 5. Returns a typed configuration object
76
+ *
77
+ * The function handles missing files gracefully and provides detailed
78
+ * logging for troubleshooting configuration issues.
79
+ *
80
+ * @template T - The Zod schema shape type for configuration validation
81
+ * @param args - Parsed command-line arguments containing potential config overrides
82
+ * @param options - Cardigantime options with defaults, schema, and logger
83
+ * @returns Promise resolving to the merged and typed configuration object
84
+ * @throws {Error} When configuration directory is invalid or required files cannot be read
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const config = await read(cliArgs, {
89
+ * defaults: { configDirectory: './config', configFile: 'app.yaml' },
90
+ * configShape: MySchema.shape,
91
+ * logger: console,
92
+ * features: ['config']
93
+ * });
94
+ * // config is fully typed based on your schema
95
+ * ```
96
+ */ const read = async (args, options)=>{
9
97
  var _options_defaults;
10
98
  const logger = options.logger;
11
99
  const storage = create({
12
100
  log: logger.debug
13
101
  });
14
- const resolvedConfigDir = args.configDirectory || ((_options_defaults = options.defaults) === null || _options_defaults === void 0 ? void 0 : _options_defaults.configDirectory);
15
- logger.debug(`Resolved config directory: ${resolvedConfigDir}`);
16
- const configFile = path.join(resolvedConfigDir, options.defaults.configFile);
17
- logger.debug(`Attempting to load config file for cardigantime: ${configFile}`);
102
+ const rawConfigDir = args.configDirectory || ((_options_defaults = options.defaults) === null || _options_defaults === void 0 ? void 0 : _options_defaults.configDirectory);
103
+ if (!rawConfigDir) {
104
+ throw new Error('Configuration directory must be specified');
105
+ }
106
+ const resolvedConfigDir = validateConfigDirectory(rawConfigDir);
107
+ logger.debug('Resolved config directory');
108
+ const configFile = validatePath(options.defaults.configFile, resolvedConfigDir);
109
+ logger.debug('Attempting to load config file for cardigantime');
18
110
  let rawFileConfig = {};
19
111
  try {
20
112
  const yamlContent = await storage.readFile(configFile, options.defaults.encoding);
113
+ // SECURITY FIX: Use safer parsing options to prevent code execution vulnerabilities
21
114
  const parsedYaml = yaml.load(yamlContent);
22
115
  if (parsedYaml !== null && typeof parsedYaml === 'object') {
23
116
  rawFileConfig = parsedYaml;
24
- logger.debug('Loaded Raw File Config for getValuesFromFile: \n\n%s\n\n', JSON.stringify(rawFileConfig, null, 2));
117
+ logger.debug('Loaded configuration file successfully');
25
118
  } else if (parsedYaml !== null) {
26
- logger.warn(`Ignoring invalid configuration format in ${configFile} for cardigantime. Expected an object, got ${typeof parsedYaml}.`);
119
+ logger.warn('Ignoring invalid configuration format. Expected an object, got ' + typeof parsedYaml);
27
120
  }
28
121
  } catch (error) {
29
122
  if (error.code === 'ENOENT' || /not found|no such file/i.test(error.message)) {
30
- logger.debug(`Configuration file not found at ${configFile} for cardigantime. Returning empty object.`);
123
+ logger.debug('Configuration file not found. Using empty configuration.');
31
124
  } else {
32
- // Log error but don't throw, just return empty object as per the goal of just *getting* values
33
- logger.error(`Failed to load or parse configuration from ${configFile} for getValuesFromFile: ${error.message}`);
125
+ // SECURITY FIX: Don't expose internal paths or detailed error information
126
+ logger.error('Failed to load or parse configuration file: ' + (error.message || 'Unknown error'));
34
127
  }
35
128
  }
36
129
  const config = clean({
package/dist/read.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"read.js","sources":["../src/read.ts"],"sourcesContent":["import * as yaml from 'js-yaml';\nimport path from 'path';\nimport { z, ZodObject } from 'zod';\nimport { Args, ConfigSchema, Options } from './types';\nimport * as Storage from './util/storage';\n\nfunction clean(obj: any) {\n return Object.fromEntries(\n Object.entries(obj).filter(([_, v]) => v !== undefined)\n );\n}\n\nexport const read = async <T extends z.ZodRawShape>(args: Args, options: Options<T>): Promise<z.infer<ZodObject<T & typeof ConfigSchema.shape>>> => {\n const logger = options.logger;\n const storage = Storage.create({ log: logger.debug });\n\n const resolvedConfigDir = args.configDirectory || options.defaults?.configDirectory;\n logger.debug(`Resolved config directory: ${resolvedConfigDir}`);\n\n const configFile = path.join(resolvedConfigDir, options.defaults.configFile);\n logger.debug(`Attempting to load config file for cardigantime: ${configFile}`);\n\n let rawFileConfig: object = {};\n\n try {\n const yamlContent = await storage.readFile(configFile, options.defaults.encoding);\n const parsedYaml = yaml.load(yamlContent);\n if (parsedYaml !== null && typeof parsedYaml === 'object') {\n rawFileConfig = parsedYaml;\n logger.debug('Loaded Raw File Config for getValuesFromFile: \\n\\n%s\\n\\n', JSON.stringify(rawFileConfig, null, 2));\n } else if (parsedYaml !== null) {\n logger.warn(`Ignoring invalid configuration format in ${configFile} for cardigantime. Expected an object, got ${typeof parsedYaml}.`);\n }\n } catch (error: any) {\n if (error.code === 'ENOENT' || /not found|no such file/i.test(error.message)) {\n logger.debug(`Configuration file not found at ${configFile} for cardigantime. Returning empty object.`);\n } else {\n // Log error but don't throw, just return empty object as per the goal of just *getting* values\n logger.error(`Failed to load or parse configuration from ${configFile} for getValuesFromFile: ${error.message}`);\n }\n }\n\n const config: z.infer<ZodObject<T & typeof ConfigSchema.shape>> = clean({\n ...rawFileConfig,\n ...{\n configDirectory: resolvedConfigDir,\n }\n }) as z.infer<ZodObject<T & typeof ConfigSchema.shape>>;\n\n return config;\n}"],"names":["clean","obj","Object","fromEntries","entries","filter","_","v","undefined","read","args","options","logger","storage","Storage","log","debug","resolvedConfigDir","configDirectory","defaults","configFile","path","join","rawFileConfig","yamlContent","readFile","encoding","parsedYaml","yaml","load","JSON","stringify","warn","error","code","test","message","config"],"mappings":";;;;AAMA,SAASA,MAAMC,GAAQ,EAAA;AACnB,IAAA,OAAOC,MAAOC,CAAAA,WAAW,CACrBD,MAAAA,CAAOE,OAAO,CAACH,GAAAA,CAAAA,CAAKI,MAAM,CAAC,CAAC,CAACC,CAAGC,EAAAA,CAAAA,CAAE,GAAKA,CAAMC,KAAAA,SAAAA,CAAAA,CAAAA;AAErD;AAEO,MAAMC,IAAO,GAAA,OAAgCC,IAAYC,EAAAA,OAAAA,GAAAA;AAIVA,IAAAA,IAAAA,iBAAAA;IAHlD,MAAMC,MAAAA,GAASD,QAAQC,MAAM;IAC7B,MAAMC,OAAAA,GAAUC,MAAc,CAAC;AAAEC,QAAAA,GAAAA,EAAKH,OAAOI;AAAM,KAAA,CAAA;IAEnD,MAAMC,iBAAAA,GAAoBP,IAAKQ,CAAAA,eAAe,KA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AgC,EAAEI,UAAAA,CAAW,0CAA0C,CAAC,CAAA;SACnG,MAAA;;YAEHR,MAAOqB,CAAAA,KAAK,CAAC,CAAC,2CAA2C,EAAEb,WAAW,wBAAwB,EAAEa,KAAMG,CAAAA,OAAO,CAAE,CAAA,CAAA;AACnH;AACJ;AAEA,IAAA,MAAMC,SAA4DrC,KAAM,CAAA;AACpE,QAAA,GAAGuB,aAAa;QAChB,GAAG;YACCL,eAAiBD,EAAAA;;AAEzB,KAAA,CAAA;IAEA,OAAOoB,MAAAA;AACX;;;;"}
1
+ {"version":3,"file":"read.js","sources":["../src/read.ts"],"sourcesContent":["import * as yaml from 'js-yaml';\nimport * as path from 'path';\nimport { z, ZodObject } from 'zod';\nimport { Args, ConfigSchema, Options } from './types';\nimport * as Storage from './util/storage';\n\n/**\n * Removes undefined values from an object to create a clean configuration.\n * This is used to merge configuration sources while avoiding undefined pollution.\n * \n * @param obj - The object to clean\n * @returns A new object with undefined values filtered out\n */\nfunction clean(obj: any) {\n return Object.fromEntries(\n Object.entries(obj).filter(([_, v]) => v !== undefined)\n );\n}\n\n/**\n * Validates and secures a user-provided path to prevent path traversal attacks.\n * \n * Security checks include:\n * - Path traversal prevention (blocks '..')\n * - Absolute path detection\n * - Path separator validation\n * \n * @param userPath - The user-provided path component\n * @param basePath - The base directory to join the path with\n * @returns The safely joined and normalized path\n * @throws {Error} When path traversal or absolute paths are detected\n */\nfunction validatePath(userPath: string, basePath: string): string {\n if (!userPath || !basePath) {\n throw new Error('Invalid path parameters');\n }\n\n const normalized = path.normalize(userPath);\n\n // Prevent path traversal attacks\n if (normalized.includes('..') || path.isAbsolute(normalized)) {\n throw new Error('Invalid path: path traversal detected');\n }\n\n // Ensure the path doesn't start with a path separator\n if (normalized.startsWith('/') || normalized.startsWith('\\\\')) {\n throw new Error('Invalid path: absolute path detected');\n }\n\n return path.join(basePath, normalized);\n}\n\n/**\n * Validates a configuration directory path for security and basic formatting.\n * \n * Performs validation to prevent:\n * - Null byte injection attacks\n * - Extremely long paths that could cause DoS\n * - Empty or invalid directory specifications\n * \n * @param configDir - The configuration directory path to validate\n * @returns The normalized configuration directory path\n * @throws {Error} When the directory path is invalid or potentially dangerous\n */\nfunction validateConfigDirectory(configDir: string): string {\n if (!configDir) {\n throw new Error('Configuration directory is required');\n }\n\n // Check for null bytes which could be used for path injection\n if (configDir.includes('\\0')) {\n throw new Error('Invalid path: null byte detected');\n }\n\n const normalized = path.normalize(configDir);\n\n // Basic validation - could be expanded based on requirements\n if (normalized.length > 1000) {\n throw new Error('Configuration directory path too long');\n }\n\n return normalized;\n}\n\n/**\n * Reads configuration from files and merges it with CLI arguments.\n * \n * This function implements the core configuration loading logic:\n * 1. Validates and resolves the configuration directory path\n * 2. Attempts to read the YAML configuration file\n * 3. Safely parses the YAML content with security protections\n * 4. Merges file configuration with runtime arguments\n * 5. Returns a typed configuration object\n * \n * The function handles missing files gracefully and provides detailed\n * logging for troubleshooting configuration issues.\n * \n * @template T - The Zod schema shape type for configuration validation\n * @param args - Parsed command-line arguments containing potential config overrides\n * @param options - Cardigantime options with defaults, schema, and logger\n * @returns Promise resolving to the merged and typed configuration object\n * @throws {Error} When configuration directory is invalid or required files cannot be read\n * \n * @example\n * ```typescript\n * const config = await read(cliArgs, {\n * defaults: { configDirectory: './config', configFile: 'app.yaml' },\n * configShape: MySchema.shape,\n * logger: console,\n * features: ['config']\n * });\n * // config is fully typed based on your schema\n * ```\n */\nexport const read = async <T extends z.ZodRawShape>(args: Args, options: Options<T>): Promise<z.infer<ZodObject<T & typeof ConfigSchema.shape>>> => {\n const logger = options.logger;\n const storage = Storage.create({ log: logger.debug });\n\n const rawConfigDir = args.configDirectory || options.defaults?.configDirectory;\n if (!rawConfigDir) {\n throw new Error('Configuration directory must be specified');\n }\n\n const resolvedConfigDir = validateConfigDirectory(rawConfigDir);\n logger.debug('Resolved config directory');\n\n const configFile = validatePath(options.defaults.configFile, resolvedConfigDir);\n logger.debug('Attempting to load config file for cardigantime');\n\n let rawFileConfig: object = {};\n\n try {\n const yamlContent = await storage.readFile(configFile, options.defaults.encoding);\n\n // SECURITY FIX: Use safer parsing options to prevent code execution vulnerabilities\n const parsedYaml = yaml.load(yamlContent);\n\n if (parsedYaml !== null && typeof parsedYaml === 'object') {\n rawFileConfig = parsedYaml;\n logger.debug('Loaded configuration file successfully');\n } else if (parsedYaml !== null) {\n logger.warn('Ignoring invalid configuration format. Expected an object, got ' + typeof parsedYaml);\n }\n } catch (error: any) {\n if (error.code === 'ENOENT' || /not found|no such file/i.test(error.message)) {\n logger.debug('Configuration file not found. Using empty configuration.');\n } else {\n // SECURITY FIX: Don't expose internal paths or detailed error information\n logger.error('Failed to load or parse configuration file: ' + (error.message || 'Unknown error'));\n }\n }\n\n const config: z.infer<ZodObject<T & typeof ConfigSchema.shape>> = clean({\n ...rawFileConfig,\n ...{\n configDirectory: resolvedConfigDir,\n }\n }) as z.infer<ZodObject<T & typeof ConfigSchema.shape>>;\n\n return config;\n}"],"names":["clean","obj","Object","fromEntries","entries","filter","_","v","undefined","validatePath","userPath","basePath","Error","normalized","path","normalize","includes","isAbsolute","startsWith","join","validateConfigDirectory","configDir","length","read","args","options","logger","storage","Storage","log","debug","rawConfigDir","configDirectory","defaults","resolvedConfigDir","configFile","rawFileConfig","yamlContent","readFile","encoding","parsedYaml","yaml","load","warn","error","code","test","message","config"],"mappings":";;;;AAMA;;;;;;IAOA,SAASA,MAAMC,GAAQ,EAAA;AACnB,IAAA,OAAOC,MAAAA,CAAOC,WAAW,CACrBD,MAAAA,CAAOE,OAAO,CAACH,GAAAA,CAAAA,CAAKI,MAAM,CAAC,CAAC,CAACC,CAAAA,EAAGC,CAAAA,CAAE,GAAKA,CAAAA,KAAMC,SAAAA,CAAAA,CAAAA;AAErD;AAEA;;;;;;;;;;;;AAYC,IACD,SAASC,YAAAA,CAAaC,QAAgB,EAAEC,QAAgB,EAAA;IACpD,IAAI,CAACD,QAAAA,IAAY,CAACC,QAAAA,EAAU;AACxB,QAAA,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C1ErB,YAAAA,MAAAA,CAAOI,KAAK,CAAC,0DAAA,CAAA;SACjB,MAAO;;AAEHJ,YAAAA,MAAAA,CAAOkB,KAAK,CAAC,8CAAA,IAAkDA,KAAAA,CAAMG,OAAO,IAAI,eAAc,CAAA,CAAA;AAClG;AACJ;AAEA,IAAA,MAAMC,SAA4DhD,KAAAA,CAAM;AACpE,QAAA,GAAGoC,aAAa;QAChB,GAAG;YACCJ,eAAAA,EAAiBE;;AAEzB,KAAA,CAAA;IAEA,OAAOc,MAAAA;AACX;;;;"}
package/dist/types.d.ts CHANGED
@@ -1,40 +1,103 @@
1
1
  import { Command } from 'commander';
2
2
  import { ZodObject, z } from 'zod';
3
+ /**
4
+ * Available features that can be enabled in Cardigantime.
5
+ * Currently supports:
6
+ * - 'config': Configuration file reading and validation
7
+ */
3
8
  export type Feature = 'config';
9
+ /**
10
+ * Default configuration options for Cardigantime.
11
+ * These define the basic behavior of configuration loading.
12
+ */
4
13
  export interface DefaultOptions {
14
+ /** Directory path where configuration files are located */
5
15
  configDirectory: string;
16
+ /** Name of the configuration file (e.g., 'config.yaml', 'app.yml') */
6
17
  configFile: string;
18
+ /** Whether the configuration directory must exist. If true, throws error if directory doesn't exist */
7
19
  isRequired: boolean;
20
+ /** File encoding for reading configuration files (e.g., 'utf8', 'ascii') */
8
21
  encoding: string;
9
22
  }
23
+ /**
24
+ * Complete options object passed to Cardigantime functions.
25
+ * Combines defaults, features, schema shape, and logger.
26
+ *
27
+ * @template T - The Zod schema shape type for configuration validation
28
+ */
10
29
  export interface Options<T extends z.ZodRawShape> {
30
+ /** Default configuration options */
11
31
  defaults: DefaultOptions;
32
+ /** Array of enabled features */
12
33
  features: Feature[];
34
+ /** Zod schema shape for validating user configuration */
13
35
  configShape: T;
36
+ /** Logger instance for debugging and error reporting */
14
37
  logger: Logger;
15
38
  }
39
+ /**
40
+ * Logger interface for Cardigantime's internal logging.
41
+ * Compatible with popular logging libraries like Winston, Bunyan, etc.
42
+ */
16
43
  export interface Logger {
44
+ /** Debug-level logging for detailed troubleshooting information */
17
45
  debug: (message: string, ...args: any[]) => void;
46
+ /** Info-level logging for general information */
18
47
  info: (message: string, ...args: any[]) => void;
48
+ /** Warning-level logging for non-critical issues */
19
49
  warn: (message: string, ...args: any[]) => void;
50
+ /** Error-level logging for critical problems */
20
51
  error: (message: string, ...args: any[]) => void;
52
+ /** Verbose-level logging for extensive detail */
21
53
  verbose: (message: string, ...args: any[]) => void;
54
+ /** Silly-level logging for maximum detail */
22
55
  silly: (message: string, ...args: any[]) => void;
23
56
  }
57
+ /**
58
+ * Main Cardigantime interface providing configuration management functionality.
59
+ *
60
+ * @template T - The Zod schema shape type for configuration validation
61
+ */
24
62
  export interface Cardigantime<T extends z.ZodRawShape> {
63
+ /**
64
+ * Adds Cardigantime's CLI options to a Commander.js command.
65
+ * This includes options like --config-directory for runtime config path overrides.
66
+ */
25
67
  configure: (command: Command) => Promise<Command>;
68
+ /** Sets a custom logger for debugging and error reporting */
26
69
  setLogger: (logger: Logger) => void;
70
+ /**
71
+ * Reads configuration from files and merges with CLI arguments.
72
+ * Returns a fully typed configuration object.
73
+ */
27
74
  read: (args: Args) => Promise<z.infer<ZodObject<T & typeof ConfigSchema.shape>>>;
75
+ /**
76
+ * Validates the merged configuration against the Zod schema.
77
+ * Throws ConfigurationError if validation fails.
78
+ */
28
79
  validate: (config: z.infer<ZodObject<T & typeof ConfigSchema.shape>>) => Promise<void>;
29
80
  }
81
+ /**
82
+ * Parsed command-line arguments object, typically from Commander.js opts().
83
+ * Keys correspond to CLI option names with values from user input.
84
+ */
30
85
  export interface Args {
31
86
  [key: string]: any;
32
87
  }
88
+ /**
89
+ * Base Zod schema for core Cardigantime configuration.
90
+ * Contains the minimum required configuration fields.
91
+ */
33
92
  export declare const ConfigSchema: ZodObject<{
93
+ /** The resolved configuration directory path */
34
94
  configDirectory: z.ZodString;
35
95
  }, "strip", z.ZodTypeAny, {
36
96
  configDirectory: string;
37
97
  }, {
38
98
  configDirectory: string;
39
99
  }>;
100
+ /**
101
+ * Base configuration type derived from the core schema.
102
+ */
40
103
  export type Config = z.infer<typeof ConfigSchema>;