{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAIA,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEtC,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAkBjD;AAED,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAa3D","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport url from 'node:url';\n\ntype SqlFile = Record<string, string>;\n\nexport function loadSql(filename: string): SqlFile {\n  const sql: SqlFile = {\n    all: fs.readFileSync(filename, 'utf8'),\n  };\n  const lines = sql.all.split(/\\r?\\n/);\n  const blockRE = /^ *-- *BLOCK +([^ ]+) *$/;\n  let blockName: string | null = null;\n  lines.forEach((line) => {\n    const result = blockRE.exec(line);\n    if (result) {\n      blockName = result[1];\n      if (sql[blockName]) throw new Error(`${filename}: duplicate BLOCK name: ${blockName}`);\n      sql[blockName] = line;\n    } else if (blockName) {\n      sql[blockName] += '\\n' + line;\n    }\n  });\n  return sql;\n}\n\nexport function loadSqlEquiv(filePathOrUrl: string): SqlFile {\n  let resolvedPath = filePathOrUrl;\n\n  // This allows for us to pass `import.meta.url` to this function in ES Modules\n  // environments where `__filename` is not available.\n  if (filePathOrUrl.startsWith('file://')) {\n    resolvedPath = url.fileURLToPath(filePathOrUrl);\n  }\n\n  const components = path.parse(resolvedPath);\n  components.ext = '.sql';\n  const sqlFilename = path.join(components.dir, components.name) + components.ext;\n  return loadSql(sqlFilename);\n}\n"]}