@theunwalked/cardigantime 0.0.10 → 0.0.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.
@@ -1658,10 +1658,17 @@ class ConfigurationError extends Error {
1658
1658
  const defaultSchema = schema;
1659
1659
  return defaultSchema._def.defaultValue();
1660
1660
  }
1661
- // Handle ZodOptional and ZodNullable - unwrap and recurse
1661
+ // Handle ZodOptional and ZodNullable - only recurse if there's an explicit default
1662
1662
  if (schema._def && (schema._def.typeName === 'ZodOptional' || schema._def.typeName === 'ZodNullable')) {
1663
1663
  const unwrappable = schema;
1664
- return extractSchemaDefaults(unwrappable.unwrap());
1664
+ const unwrapped = unwrappable.unwrap();
1665
+ // Only provide defaults if the unwrapped schema has explicit defaults
1666
+ // This prevents optional arrays/objects from automatically getting [] or {} defaults
1667
+ if (unwrapped._def && unwrapped._def.typeName === 'ZodDefault') {
1668
+ return extractSchemaDefaults(unwrapped);
1669
+ }
1670
+ // For optional fields without explicit defaults, return undefined
1671
+ return undefined;
1665
1672
  }
1666
1673
  // Handle ZodObject - recursively process shape
1667
1674
  if (schema._def && schema._def.typeName === 'ZodObject') {
@@ -1720,7 +1727,7 @@ class ConfigurationError extends Error {
1720
1727
  const fullSchema = zod.z.object({
1721
1728
  ...configShape
1722
1729
  });
1723
- // Extract defaults from the full schema
1730
+ // Extract defaults from the full schema using only explicit defaults
1724
1731
  const defaults = extractSchemaDefaults(fullSchema);
1725
1732
  // Don't include configDirectory in the generated file since it's runtime-specific
1726
1733
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -1786,6 +1793,10 @@ class ConfigurationError extends Error {
1786
1793
  * // These paths will be resolved relative to ../config/ directory
1787
1794
  * ```
1788
1795
  */ const create = (pOptions)=>{
1796
+ // Validate that configDirectory is a string
1797
+ if (!pOptions.defaults.configDirectory || typeof pOptions.defaults.configDirectory !== 'string') {
1798
+ throw new Error(`Configuration directory must be a string, received: ${typeof pOptions.defaults.configDirectory} (${JSON.stringify(pOptions.defaults.configDirectory)})`);
1799
+ }
1789
1800
  const defaults = {
1790
1801
  ...DEFAULT_OPTIONS,
1791
1802
  ...pOptions.defaults
@@ -1807,6 +1818,10 @@ class ConfigurationError extends Error {
1807
1818
  const targetDir = configDirectory || options.defaults.configDirectory;
1808
1819
  const configFile = options.defaults.configFile;
1809
1820
  const encoding = options.defaults.encoding;
1821
+ // Validate that targetDir is a string
1822
+ if (!targetDir || typeof targetDir !== 'string') {
1823
+ throw new Error(`Configuration directory must be a string, received: ${typeof targetDir} (${JSON.stringify(targetDir)})`);
1824
+ }
1810
1825
  logger.verbose(`Generating configuration file in: ${targetDir}`);
1811
1826
  // Create storage utility
1812
1827
  const storage = create$1({
@@ -1830,7 +1845,9 @@ class ConfigurationError extends Error {
1830
1845
  // Build the full config file path
1831
1846
  const configFilePath = path__namespace.join(targetDir, configFile);
1832
1847
  // Generate default configuration
1848
+ logger.debug(`Generating defaults for schema with keys: ${Object.keys(options.configShape).join(', ')}`);
1833
1849
  const defaultConfig = generateDefaultConfig(options.configShape);
1850
+ logger.debug(`Generated default config: ${JSON.stringify(defaultConfig, null, 2)}`);
1834
1851
  // Convert to YAML with nice formatting
1835
1852
  const yamlContent = yaml__namespace.dump(defaultConfig, {
1836
1853
  indent: 2,