"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }


var _chunkFYSASWVKcjs = require('./chunk-FYSASWVK.cjs');



var _chunkN3H4E6EHcjs = require('./chunk-N3H4E6EH.cjs');

// src/generators/dts.ts
_chunkN3H4E6EHcjs.init_cjs_shims.call(void 0, );
var _promises = require('fs/promises');
var _untyped = require('untyped');
function generateDeclaration(schema) {
  return `
// Generated by @storm-software/untyped
// Do not edit this file directly

${_untyped.generateTypes.call(void 0, schema, {
    addExport: true,
    partial: true,
    interfaceName: `${_optionalChain([schema, 'access', _ => _.title, 'optionalAccess', _2 => _2.replaceAll, 'call', _3 => _3(" ", "")]) || "Type"}Schema`
  })}

`;
}
function generateDeclarationFile(schema, file, config) {
  try {
    const declarations = _chunkN3H4E6EHcjs.getOutputFile.call(void 0, file, "d.ts");
    _chunkFYSASWVKcjs.writeTrace.call(void 0, `Writing type declaration file ${declarations}`, config);
    return _promises.writeFile.call(void 0, declarations, generateDeclaration(schema));
  } catch (error) {
    _chunkFYSASWVKcjs.writeError.call(void 0, 
      `Error writing declaration file for ${file.name}

Error:
${_optionalChain([error, 'optionalAccess', _4 => _4.message]) ? error.message : JSON.stringify(error)}${_optionalChain([error, 'optionalAccess', _5 => _5.stack]) ? `
Stack Trace: ${error.stack}` : ""}

Parsed schema:
${JSON.stringify(schema)}
`,
      config
    );
    throw error;
  }
}




exports.generateDeclaration = generateDeclaration; exports.generateDeclarationFile = generateDeclarationFile;
