'use strict'; var pluginSpaceConfigure = require('@flatfile/plugin-space-configure'); var pluginConvertJsonSchema = require('@flatfile/plugin-convert-json-schema'); var sqlDdlToJsonSchema = require('sql-ddl-to-json-schema'); var f = require('fs'); var p = require('path'); function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var f__namespace = /*#__PURE__*/_interopNamespace(f); var p__namespace = /*#__PURE__*/_interopNamespace(p); async function c(e){return {workbooks:await Promise.all(e.workbooks.map(async r=>{let n=h(r.source),o=new sqlDdlToJsonSchema.Parser("mysql"),m=o.feed(n).toCompactJson(o.results),u=o.feed(n).toJsonSchemaArray({useRef:!0},m),g=(await Promise.all(r.sheets.map(async a=>{let i=u.find(t=>t.$id===a.slug);if(!i){console.error(`Schema not found for table name ${a.slug}`);return}let l=await pluginConvertJsonSchema.generateFields(i),S=new Set(i.required||[]);return l.forEach(t=>{S.has(t.key)&&t.constraints?.push({type:"required"});}),{...a,fields:l}}))).filter(Boolean);return {...r,sheets:g}})),space:e.space}}function h(e){return f__namespace.readFileSync(p__namespace.join(__dirname,"../",e)).toString()}function w(e,s){return pluginSpaceConfigure.configureSpace(()=>c(e),s)} exports.configureSpaceWithSqlDDL = w; exports.generateSetup = c; //# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map