@griddo/core 11.10.1 → 11.10.3-rc.0

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/autotypes.js CHANGED
@@ -1,2 +1,2 @@
1
- import e from"node:fs";import t from"node:path";import{fileURLToPath as n}from"node:url";import r from"node:process";import o from"prettier";function i(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{l(r.next(e))}catch(e){i(e)}}function a(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((r=r.apply(e,t||[])).next())})}function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var a,l;"function"==typeof SuppressedError&&SuppressedError;var c=s(function(){if(l)return a;l=1;const{FORCE_COLOR:e,NODE_DISABLE_COLORS:t,TERM:n}=process.env,r={enabled:!t&&"dumb"!==n&&"0"!==e,reset:i(0,0),bold:i(1,22),dim:i(2,22),italic:i(3,23),underline:i(4,24),inverse:i(7,27),hidden:i(8,28),strikethrough:i(9,29),black:i(30,39),red:i(31,39),green:i(32,39),yellow:i(33,39),blue:i(34,39),magenta:i(35,39),cyan:i(36,39),white:i(37,39),gray:i(90,39),grey:i(90,39),bgBlack:i(40,49),bgRed:i(41,49),bgGreen:i(42,49),bgYellow:i(43,49),bgBlue:i(44,49),bgMagenta:i(45,49),bgCyan:i(46,49),bgWhite:i(47,49)};function o(e,t){let n,r=0,o="",i="";for(;r<e.length;r++)n=e[r],o+=n.open,i+=n.close,t.includes(n.close)&&(t=t.replace(n.rgx,n.close+n.open));return o+t+i}function i(e,t){let n={open:`[${e}m`,close:`[${t}m`,rgx:new RegExp(`\\x1b\\[${t}m`,"g")};return function(t){return void 0!==this&&void 0!==this.has?(this.has.includes(e)||(this.has.push(e),this.keys.push(n)),void 0===t?this:r.enabled?o(this.keys,t+""):t+""):void 0===t?function(e,t){let n={has:e,keys:t};return n.reset=r.reset.bind(n),n.bold=r.bold.bind(n),n.dim=r.dim.bind(n),n.italic=r.italic.bind(n),n.underline=r.underline.bind(n),n.inverse=r.inverse.bind(n),n.hidden=r.hidden.bind(n),n.strikethrough=r.strikethrough.bind(n),n.black=r.black.bind(n),n.red=r.red.bind(n),n.green=r.green.bind(n),n.yellow=r.yellow.bind(n),n.blue=r.blue.bind(n),n.magenta=r.magenta.bind(n),n.cyan=r.cyan.bind(n),n.white=r.white.bind(n),n.gray=r.gray.bind(n),n.grey=r.grey.bind(n),n.bgBlack=r.bgBlack.bind(n),n.bgRed=r.bgRed.bind(n),n.bgGreen=r.bgGreen.bind(n),n.bgYellow=r.bgYellow.bind(n),n.bgBlue=r.bgBlue.bind(n),n.bgMagenta=r.bgMagenta.bind(n),n.bgCyan=r.bgCyan.bind(n),n.bgWhite=r.bgWhite.bind(n),n}([e],[n]):r.enabled?o([n],t+""):t+""}}return a=r}());const p={directory:"isDirectory",file:"isFile"};const u=(e,t)=>t[p[e]]();function d(o,{cwd:i=r.cwd(),type:s="file",allowSymlinks:a=!0}={}){var l;!function(e){if(!Object.hasOwnProperty.call(p,e))throw new Error(`Invalid type specified: ${e}`)}(s),i=(l=i)instanceof URL?n(l):l;const c=a?e.statSync:e.lstatSync;for(const e of o)try{const n=c(t.resolve(i,e),{throwIfNoEntry:!1});if(!n)continue;if(u(s,n))return e}catch{}}const m=Symbol("findUpStop");function y(e,r={}){let o=t.resolve(((i=r.cwd)instanceof URL?n(i):i)||"");var i;const{root:s}=t.parse(o),a=r.stopAt||s,l=r.limit||Number.POSITIVE_INFINITY,c=[e].flat(),p=t=>{if("function"!=typeof e)return d(c,t);const n=e(t.cwd);return"string"==typeof n?d([n],t):n},u=[];for(;;){const e=p({...r,cwd:o});if(e===m)break;if(e&&u.push(t.resolve(o,e)),o===a||u.length>=l)break;o=t.dirname(o)}return u}function f({cwd:e}={}){const n=function(e,t={}){return y(e,{...t,limit:1})[0]}("package.json",{cwd:e});return n&&t.dirname(n)}function g(e){return{AIReferenceField:"Fields.AIReference",FormCategorySelect:"Fields.FormCategorySelect",FormContainer:"Fields.FormContainer",FormFieldArray:"Fields.FormFieldArray",ArrayFieldGroup:"Fields.ArrayFieldGroup",AsyncCheckGroup:"Fields.AsyncCheckGroup",AsyncSelect:"Fields.AsyncSelect",CheckGroup:"Fields.CheckGroup",ColorPicker:"Fields.ColorPicker",ComponentArray:"Fields.ComponentArray",ComponentContainer:"Fields.ComponentContainer",ConditionalField:"Fields.Conditional",DateField:"Fields.Date",FieldGroup:"Fields.FieldGroup",FieldsDivider:"Fields.FieldsDivider",FileField:"Fields.File",HeadingField:"Fields.Heading",ImageField:"Fields.Image",LinkField:"Fields.Link",MultiCheckSelect:"Fields.MultiCheckSelect",MultiCheckSelectGroup:"Fields.MultiCheckSelectGroup",NoteField:"Fields.Note",NumberField:"Fields.Number",RadioGroup:"Fields.RadioGroup",ReferenceField:"Fields.Reference",RichText:"Fields.RichText",Select:"Fields.Select",SliderField:"Fields.Slider",TagsField:"Fields.Tags",TextArea:"Fields.TextArea",TextField:"Fields.Text",TimeField:"Fields.Time",ToggleField:"Fields.Toggle",UniqueCheck:"Fields.UniqueCheck",UrlField:"Fields.Url",VisualUniqueSelection:"Fields.VisualUniqueSelection",Wysiwyg:"Fields.Wysiwyg"}[e]}function h(e,t){var n;const{returnTypeName:r,generic:o}=t||{},i="hideable"in e&&Boolean(e.hideable),s=o?`<${o}>`:"",a=`${r||g(e.type)}${s}`,l=i?`Hideable<${a}>`:`${a}`;return`\n\t\t${(null===(n=e._autoType)||void 0===n?void 0:n.doc)||""}\n\t\t${`${e.key}?: ${l}`}\n\t`}const $=__dirname.includes("node_modules");function b(){const e=__dirname,n=$?"../../../":"../griddo-components";return t.resolve(f({cwd:e}),n)}function F(){var e,n,r;const o=t.join(b(),"griddo.config.ts"),i=require(o);return{interfaceSuffix:(null===(e=i.autotypes)||void 0===e?void 0:e.interfaceSuffix)||"Props",contentTypeSuffix:(null===(n=i.autotypes)||void 0===n?void 0:n.contentTypeSuffix)||"ContentType",publicApiSuffix:(null===(r=i.autotypes)||void 0===r?void 0:r.publicApiSuffix)||"List"}}function T(e,t,n){var r,o;const{contentTypeSuffix:i,interfaceSuffix:s}=F();if("FieldsDivider"===e.type)return"// FieldsDivider";if(null===(r=e._autoType)||void 0===r?void 0:r.ignore)return"// Ignored by AutoType.ignore";const{type:a,_autoType:l,key:c}=e,{hasDistributorData:p,getStaticData:u}=n;if(!a||!c)return"\n\t\t\t/** · (ノ-_-)ノ ミ ┴┴ You forgot to write the `type` | `key` or some mandatory prop */\n\t\t";if("DateField"===a||"FileField"===a||"ImageField"===a||"NoteField"===a||"NumberField"===a||"RichText"===a||"SliderField"===a||"TagsField"===a||"TextArea"===a||"TextField"===a||"TimeField"===a||"ToggleField"===a||"UniqueCheck"===a||"UrlField"===a||"Wysiwyg"===a)return h(e);if("MultiCheckSelect"===a){if("pageContentType"===t||"simpleContentType"===t){const t=`${e.source}${i}${s}`;return h(e,{generic:`Relations, FromList, ${t}<false, false>, FromDistributor`})}return h(e,{generic:"true"})}if("AsyncCheckGroup"===a){if("pageContentType"===t||"simpleContentType"===t){const t=`${e.source}${i}${s}`;return h(e,{generic:`Relations, FromList, ${t}<false, false>, FromDistributor`})}return h(e,{generic:"true"})}if("MultiCheckSelectGroup"===a){const t=[e.elements.map(e=>`"${e.key}"`).join("|"),null===(o=e._autoType)||void 0===o?void 0:o.relations].join(",");return h(e,{generic:t})}if("ColorPicker"===a)return e.isThemePalette?h(e,{returnTypeName:"Fields.ColorPickerFixed"}):h(e);if("HeadingField"===a||"RadioGroup"===a||"Select"===a){const{options:t}=e,n=function(e){return e.map(({value:e})=>"string"==typeof e?`"${e}"`:e).join("|")}(t);return h(e,{generic:n})}if("CheckGroup"===a){const{options:t}=e,n=function(e){return e.map(({name:e})=>"string"==typeof e?`"${e}"`:e).join("|")}(t);return h(e,{generic:n})}if("LinkField"===a){const{whiteList:t}=e;let r="";if(t.length>1&&"default"in n.schema){const t=n.schema.default[e.key].modal,o=Object.keys(t).map(e=>`${e}?: ${t[e].component}${s}`).join(",");r=`{${o}}`}else r=`${t[0]}${s}`;return h(e,{generic:r})}if("AsyncSelect"===a){if("entity"in e&&"menu_containers"===e.entity)return`\n${c}?: Menu`;if("pageContentType"===t||"simpleContentType"===t){const t=`${e.source}${i}${s}`;return h(e,{generic:`Relations, FromList, ${t}<false, false>, FromDistributor`})}return`\n${c}?: Fields.AsyncSelect;`}if("FieldGroup"===a)return`\n\t\t\t// << ${a}\n\t\t\t${e.fields.map(e=>T(e,t,n)).join("")}\n\t\t\t// end >>\n\t\t`;if("ArrayFieldGroup"===a){return`\n\t\t\t\n${(null==l?void 0:l.doc)||""}\n${c}?: Fields.ArrayFieldGroup<{${e.fields.map(e=>T(e,t,Object.assign(Object.assign({},n),{_from:"ArrayFieldGroup",_fromKey:c}))).join(",")}}>\n\t\t`}if("ConditionalField"===a){const r=e.fields.map(e=>T(e,t,n)),o=(null==l?void 0:l.doc)||"",i="hideable"in e&&e.hideable,s=i?">":"";return`\n\t\t\t// << ${a}\n\t\t\t\n${o}\n${c}?: ${i?"Hideable<":""}${g(a)}<${e.options.map(e=>"string"==typeof e.value?`"${e.value}"`:e.value).join("|")}>${s};\n\t\t\t${r.join("")}\n\t\t\t// end >>\n\t\t`}if("FormFieldArray"===a){const r="template"===t||"pageContentType"===t?"TemplateSection":"formTemplate"===t?"FormFieldArray":"ComponentArray",o="template"===t?"":"?",{key:i,_autoType:a,whiteList:l}=e,c=(null==a?void 0:a.doc)||"",p=(e,t,n)=>e.filter(e=>e&&"schemaType"in e&&"module"===(null==e?void 0:e.schemaType)?(null==e?void 0:e.sectionList)&&!!(null==e?void 0:e.sectionList[t]):void 0).map(e=>({t:null==e?void 0:e.sectionList[t].filter(e=>e===n),m:null==e?void 0:e.component})).filter(e=>{var t;return null===(t=null==e?void 0:e.t)||void 0===t?void 0:t.length}).map(e=>null==e?void 0:e.m).filter(Boolean);let u="";"template"===t&&(u=p(n.moduleSchemas,n.schema.component,i).join("|"));return`\n${c}\n${i}${o}: Fields.${r}<${[...new Set([...u.split("|"),...l])].filter(Boolean).map(e=>`${e}${s}`).join("|")}>;`}if("ComponentArray"===a){const r="template"===t||"pageContentType"===t?"TemplateSection":"ComponentArray",o="template"===t?"":"?",i=e,{key:a,_autoType:l,whiteList:c}=i,p=(null==l?void 0:l.doc)||"",u=(e,t,n)=>e.filter(e=>{if(e&&"schemaType"in e&&"module"===(null==e?void 0:e.schemaType))return(null==e?void 0:e.sectionList)&&!!(null==e?void 0:e.sectionList[t])}).map(e=>({t:null==e?void 0:e.sectionList[t].filter(e=>e===n),m:null==e?void 0:e.component})).filter(e=>{var t;return null===(t=null==e?void 0:e.t)||void 0===t?void 0:t.length}).map(e=>null==e?void 0:e.m).filter(Boolean);let d="";"template"===t&&(d=u(n.moduleSchemas,n.schema.component,a).join("|"));return`\n${p}\n${a}${o}: Fields.${r}<${[...new Set([...d.split("|"),...c])].filter(Boolean).map(e=>`${e}${s}`).join("|")}>;`}if("ComponentContainer"===a&&("object"===t||"component"===t||"module"===t||"template"===t||"pageContentType"===t)){const t=e,{whiteList:r}=t;let o="";if(r.length>1&&"default"in n.schema)if("ArrayFieldGroup"===n._from){const t=n._fromKey;o=n.schema.default[t].map(t=>Object.keys(t[e.key]).map(n=>`{ ${n}:${t[e.key][n].component}${s} }`)).join("")}else{const t=n.schema.default[e.key],r=Object.keys(t).map(e=>`${e}?: ${t[e].component}${s};`).join("");o=`{${r}}`}else o=`${r[0]}${s}`;return h(e,{generic:o})}if("FormContainer"===a&&("object"===t||"component"===t||"module"===t||"template"===t||"pageContentType"===t)){return`\n${(null==l?void 0:l.doc)||""}\n${c}?: Fields.FormContainer<FormTemplates${s}>;`}if("ReferenceField"===a){const t=e.sources||[{structuredData:void 0}],n=Array.isArray(t)&&t.map(e=>e.structuredData?`${e.structuredData}${i}${s}`:"unknown").join("|")||"";return`\n\t\t \t${h(e,{generic:n})}\n\t\t \t${p||u?`queriedItems?: Fields.QueriedData<${n}>;`:""}\n\t\t `}if("VisualUniqueSelection"===a){const t=e.options[0],n=e.options[0];let r="";if(t.value){r=e.options.map(e=>`"${e.value}"`).join("|")}if(n.theme){r=e.options[0].options.map(e=>`"${e.value}"`).join("|")}return h(e,{generic:r})}return"FormCategorySelect"===a?`${c}?: Fields.FormCategorySelect<FormCategoryLabels>`:"AIReferenceField"===a?`${c}?: Fields.AIReference`:(console.warn(`The field ${e.type} has not been implemented yet ㅠ.ㅠ`),"")}class v{setParser(e){this.parser=e}parse(e){var t;return(null===(t=this.parser)||void 0===t?void 0:t.parse(e))||""}}const C={ComponentsNameParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type Components = ${t.join("|")}`:""}},DataPacksCategoryParser:class{parse(e){return e?`export type DatapacksCategories = ${Object.keys(e).map(e=>`"${e}"`).join("|")}`:""}},DataPacksParser:class{parse(e){return e?`export type Datapacks = ${Object.keys(e).map(e=>`"${e}"`).join("|")}`:""}},DataTemplatesNameParser:class{parse(e){const t=Object.keys(e).map(t=>"detail"===e[t].type.mode?`"${t}"`:"").filter(Boolean);return t.length?`export type DetailTemplates = ${t.join("|")}`:""}},FormCategoryNamesParser:class{parse(e){const t=e.map(({value:e})=>`"${e}"`);return t.length?`export type FormCategoryLabels = ${t.join("|")}`:""}},FormFieldsParser:class{parse(e){const{interfaceSuffix:t}=F(),n=Object.keys(e).map(e=>`"${e}"`),r=Object.keys(e).map(e=>`${e}${t}`);return n.length?`export type FormFields = ${n.join("|")}\nexport type FormFields${t} = ${r.join("|")}\n`:""}},FormTemplatesParser:class{parse(e){const{interfaceSuffix:t}=F(),n=Object.keys(e).map(e=>`"${e}"`),r=Object.keys(e).map(e=>`${e}${t}`);return n.length?`export type FormTemplates = ${n.join("|")}\nexport type FormTemplates${t} = ${r.join("|")}\n`:""}},LanguagesParser:class{parse(e){const t=Object.keys(e);return`\n\t\texport interface SiteLanguage {\n\t\t\tdomain: { id: number; url: string; slug: string };\n\t\t\thome: string;\n\t\t\tid: number;\n\t\t\tisDefault: boolean;\n\t\t\tlabel: ${t.map(t=>{var n;return`"${null===(n=e[t])||void 0===n?void 0:n.label}"`}).join("|")};\n\t\t\tlanguage: ${t.map(t=>{var n;return`"${null===(n=e[t])||void 0===n?void 0:n.name}"`}).join("|")};\n\t\t\tlocale: ${t.map(e=>`"${e}"`).join("|")}\n\t\t\tpath: string;\n\t\t}\n\t`}},MenuItemsParser:class{getMenuItemsProps(e){return e?e.map(e=>T(e,"object",{hasDistributorData:!1,getStaticData:!1,moduleSchemas:[],schema:{},allSchemas:{}})).join(""):""}parse(e){var t,n;const r=null===(t=null==e?void 0:e.link)||void 0===t?void 0:t.fields,o=null===(n=null==e?void 0:e.group)||void 0===n?void 0:n.fields;return`\n\t\texport interface InstanceMenuItems {\n\t\t\tlink:{\n\t\t\t\t${this.getMenuItemsProps(r)}\n\t\t\t\tconfig?: {\n\t\t\t\t\theaderStyle?: string;\n\t\t\t\t\tfooterStyle?: string;\n\t\t\t\t\ttype?: "link";\n\t\t\t\t};\n\t\t\t};\n\t\t\tgroup: {\n\t\t\t\turl?: null;\n\t\t\t\t${this.getMenuItemsProps(o)}\n\t\t\t\tconfig?: {\n\t\t\t\t\theaderStyle?: string;\n\t\t\t\t\tfooterStyle?: string;\n\t\t\t\t\ttype?: "group";\n\t\t\t\t};\n\t\t\t};\n\t\t}\n\t\texport type LinkMenuElement = Fields.BaseLinkElement<InstanceMenuItems> & InstanceMenuItems["link"];\n\t\texport type GroupMenuElement = Fields.BaseLinkElement<InstanceMenuItems> & InstanceMenuItems["group"];\n\t\texport type MenuElement = LinkMenuElement | GroupMenuElement;\n\t\texport type Menu = Fields.Menu<InstanceMenuItems>;\n\t`}},ModuleCateogiresParser:class{parse(e){return e?`export type ModuleCategories = ${e.map(e=>`"${e.value}"`).join("|")}`:""}},ModulesNameParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type Modules = ${t.join("|")}`:""}},PageContentTypeParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type PageContentTypes = ${t.join("|")}`:""}},PageDataPropsParser:class{parse(e){const{contentTypeSuffix:t,interfaceSuffix:n}=F(),r=Object.keys(e).map(e=>`${e}${t}${n}`);return r.length?`export type Page${t}${n} = ${r.join("|")}`:""}},SimpleContentTypeParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type SimpleContentTypes = ${t.join("|")}`:""}},SimpleDataPropsParser:class{parse(e){const{contentTypeSuffix:t,interfaceSuffix:n}=F(),r=Object.keys(e).map(e=>`${e}${t}${n}`);return r.length?`export type Simple${t}${n} = ${r.join("|")}`:""}},SubthemesParser:class{parse(e){return Array.isArray(e)&&e.length?`export type Subthemes = ${e.map(e=>`"${e}"`).join("|")}`:""}},TaxonomyParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type TaxonomyContentTypes = ${t.join("|")}`:""}},TaxonomyPropsParser:class{parse(e){const{contentTypeSuffix:t,interfaceSuffix:n}=F(),r=Object.keys(e).map(e=>`${e}${t}${n}`);return r.length?`export type Taxonomy${t}${n} = ${r.join("|")}`:""}},TemplateSectionListParser:class{parse(e){const t=[];for(const n in e){const r=e[n],o=r.content.filter(e=>"ComponentArray"===e.type).map(({key:e})=>`"${e}"`).filter(Boolean),i=o&&(null==o?void 0:o.length)>0?`${r.component}?: NonEmptyArray<${o.join("|")}>;`:"";t.push(i)}return`\n\t\t\texport type SectionList = { ${t.join("")} }\n\t\t`}},TemplatesNameParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type Templates = ${t.join("|")}`:""}},ThemesParser:class{parse(e){return Array.isArray(e)&&e.length?`export type Themes = ${e.map(e=>`"${e.value}"`).join("|")}`:""}},UIAndDataPropsParser:class{parse(e){const t=(n=e,Object.keys(n).map(e=>Object.assign(Object.assign({},n[e]),{component:e})));var n;const{interfaceSuffix:r}=F(),{ARRAY_OF_MODULE_SCHEMAS:o}=function(e){const t=e.map(e=>{if("schemaType"in e&&"module"===e.schemaType)return e}).filter(Boolean);return{ARRAY_OF_MODULE_SCHEMAS:t}}(t);return t.map(e=>{var t;let n={kind:"component",contentTypeSuffixStr:"",contentTypeName:"",contentTypeKind:"",relatedContentTypeNames:"",componentName:"",hasDistributorData:!1,getStaticData:!1,interfaceForPublicAPI:"",relationsGeneric:(null===(t=e._autoType)||void 0===t?void 0:t.relations)?"<Relations = unknown, FromList = unknown, FromDistributor = true>":""};if(function(e){return"fromPage"in e}(e)){const t=function(e){const{contentTypeSuffix:t,interfaceSuffix:n,publicApiSuffix:r}=F(),o=[],i=[],s=[],a=e.fromPage?"pageContentType":"simpleContentType";"pageContentType"===a&&o.push(`"${e.component}"`);"simpleContentType"!==a||e.taxonomy||i.push(`"${e.component}"`);"simpleContentType"===a&&e.taxonomy&&s.push(`"${e.component}"`);let l="";if("schema"in e){const t=e.schema.fields.map(e=>"source"in e&&(null==e?void 0:e.source)).filter(Boolean);l=t.length?`__relatedContentTypeNames: ${JSON.stringify(t)}`:""}const c="<Relations = unknown, FromList = unknown, FromDistributor = true>",p=`\n\t\t\t\t/** Type to be consumed by public API: useList(), etc.. */\n\t\t\t\texport type ${e.component}${t}${r}${n}<R extends Core.ContentTypeRelations = false> = ${e.component}${t}${n}<R, true>;\n\t\t\t\t`;return{kind:a,componentName:"",contentTypeName:`__contentTypeName: "${e.component}";`,contentTypeKind:`__contentTypeKind: "${a}";`,contentTypeSuffixStr:t,getStaticData:!1,hasDistributorData:!1,relatedContentTypeNames:l,relationsGeneric:c,interfaceForPublicAPI:p}}(e);n=Object.assign(Object.assign({},n),t)}if(function(e){return"schemaType"in e}(e)){const t=function(e){return{kind:e.schemaType,componentName:`component: "${e.component}"`,contentTypeName:"",contentTypeKind:"",contentTypeSuffixStr:"",relatedContentTypeNames:"",relationsGeneric:"",interfaceForPublicAPI:"",hasDistributorData:!!e.default.hasDistributorData,getStaticData:!!e.default.getStaticData}}(e);n=Object.assign(Object.assign({},n),t)}const i=function(e,t,n,r){return function(e){if("fromPage"in e)return e.taxonomy?[]:e.schema.fields;if("template"===e.schemaType){return[...e.content||[],...e.config||[]]}if("formTemplate"===e.schemaType){return[...e.content||[],...e.config||[]]}if("component"===e.schemaType||"module"===e.schemaType||"formComponent"===e.schemaType)return e.configTabs.flatMap(e=>e.fields);throw new Error(`Wrong schema ${JSON.stringify(e,null,2)}`)}(e).map(o=>T(o,r.kind,{hasDistributorData:r.hasDistributorData,getStaticData:r.getStaticData,moduleSchemas:t,schema:e,allSchemas:n})).filter(Boolean).join("")}(e,o,e,n);return`\n\t\t\t\texport interface ${e.component}${n.contentTypeSuffixStr}${r}${n.relationsGeneric} ${function(e){const t=function(e){return"schemaType"in e&&"template"===e.schemaType&&("list"===e.type.mode||"paginated-data"===e.type.mode)}(e)?"Fields.ExtraListTemplateProps":"";return n=[t],n.filter(e=>e.length).length<1?"":`extends ${n.join(", ")}`;var n}(e)} {\n\t\t\t\t\t${n.contentTypeName}\n\t\t\t\t\t${n.contentTypeKind}\n\t\t\t\t\t${n.relatedContentTypeNames}\n\t\t\t\t\t${n.componentName}\n\t\t\t\t\t${i}\n\t\t\t\t\t${function(e){return"fromPage"in e&&!e.fromPage&&!0===e.taxonomy}(e)?"title?: string; code?: string":""}\n\t\t\t\t}\n\t\t\t\t${n.interfaceForPublicAPI}\n\t\t\t`}).join("")}}};i(void 0,void 0,void 0,function*(){try{const n=b(),r=t.join(n,"griddo.config.ts"),s=require(r).default,{schemas:{config:{languages:a,menuItems:l,themes:p,subthemes:u,moduleCategories:d},contentTypes:{dataPacks:m,dataPacksCategories:y,structuredData:f},ui:{components:g,modules:h,templates:$},forms:F}}=s,{categoryContentTypes:T,pageContentTypes:S,simpleContentTypes:k}=function(e){return{categoryContentTypes:function(e){const t={};for(const n in e){const r=e[n];!r.fromPage&&r.taxonomy&&(t[n]=r)}return t}(e),pageContentTypes:function(e){const t={};for(const n in e){const r=e[n];r.fromPage&&(t[n]=r)}return t}(e),simpleContentTypes:function(e){const t={};for(const n in e){const r=e[n];r.fromPage||r.taxonomy||(t[n]=r)}return t}(e)}}(s.schemas.contentTypes.structuredData),P=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},g),h),$),f),(null==F?void 0:F.templates)||{}),(null==F?void 0:F.fields)||{}),j=function(e){const t=new v;return e.map(e=>(t.setParser(new e.parser),t.parse(e.schema)))}([{schema:l,parser:C.MenuItemsParser},{schema:a,parser:C.LanguagesParser},{schema:P,parser:C.UIAndDataPropsParser},{schema:u||{},parser:C.SubthemesParser},{schema:S,parser:C.PageContentTypeParser},{schema:k,parser:C.SimpleContentTypeParser},{schema:T,parser:C.TaxonomyParser},{schema:g,parser:C.ComponentsNameParser},{schema:h,parser:C.ModulesNameParser},{schema:(null==F?void 0:F.templates)||{},parser:C.FormTemplatesParser},{schema:(null==F?void 0:F.fields)||{},parser:C.FormFieldsParser},{schema:(null==F?void 0:F.categories)||[],parser:C.FormCategoryNamesParser},{schema:$,parser:C.TemplatesNameParser},{schema:$,parser:C.DataTemplatesNameParser},{schema:$,parser:C.TemplateSectionListParser},{schema:d,parser:C.ModuleCateogiresParser},{schema:m,parser:C.DataPacksParser},{schema:y,parser:C.DataPacksCategoryParser},{schema:T,parser:C.TaxonomyPropsParser},{schema:k,parser:C.SimpleDataPropsParser},{schema:S,parser:C.PageDataPropsParser},{schema:p,parser:C.ThemesParser}]),x=yield function(e){return i(this,void 0,void 0,function*(){const t=yield o.resolveConfigFile(),n=(yield o.resolveConfig(t))||{useTabs:!0},r=Object.assign(Object.assign({},n),{parser:"typescript"});return(yield o.format(e,r)).replace(/^\s*\n/gm,"")})}(`\n\t\t\t/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-use-before-define */\n//\n//\n// ' ____\n// /\\ \\\n// º / /\\ \\\n// ' / / \\ _>\n// ' _\\ \\__> \\__\n// ' O ( __;·;______ ) AutoTypes\n// O º, | , , \\ \\\\ ·..~~.·~.·\n// ,,, /| , , /\\ <\\\\\n// \\''\\-' ⎩, <\\/\\ \\ \\\n// \\_/ /\\_____⎩/ > > >\n// '___' <_(_)__> / \\ <\n// / / ´ \\ | \\___//\\\\\n// / / | / > > \\\\\n// · ··~~~~·~·~~~~~~~·~··~~~~~·~·~~·~~~~·~~~~~·· · ·\n//\n// Embrace the beauty of effortless typing by indulging in the benefits of them\n// sans the actual typing!\n//\n// Behold! These dynamically generated types were conjured from the schemas\n// nestled within this repository. However, should you yearn to expand upon\n// these types, kindly abstain from doing so in this file, lest AutoTypes'\n// magic shall smite your changes with each schema modification.\n//\n// Check out the details of Griddo AutoTypes in:\n// https://griddoio.notion.site/Griddo-AutoTypes-e7420867dd2e489c8da34a493b763cd8>\n//\n// Happy magic types!\n//\nimport { Core, Fields, Hideable, NonEmptyArray } from "@griddo/core"\n//\n\n\t\t\t${j.join("\n")}\n\t\t`),_=t.join(n,"autotypes.d.ts");e.writeFileSync(_,x),console.log(`${c.green(" ✔")} AutoTypes`)}catch(e){console.log(`${c.red(" ✘")} AutoTypes`),console.log(e)}});
1
+ import e from"node:fs";import t from"node:path";import{spawn as n}from"node:child_process";import{fileURLToPath as o}from"node:url";import r from"node:process";import i from"prettier";function s(e,t,n,o){return new(n||(n=Promise))(function(r,i){function s(e){try{l(o.next(e))}catch(e){i(e)}}function a(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((o=o.apply(e,t||[])).next())})}function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var l,c;"function"==typeof SuppressedError&&SuppressedError;var p=a(function(){if(c)return l;c=1;const{FORCE_COLOR:e,NODE_DISABLE_COLORS:t,TERM:n}=process.env,o={enabled:!t&&"dumb"!==n&&"0"!==e,reset:i(0,0),bold:i(1,22),dim:i(2,22),italic:i(3,23),underline:i(4,24),inverse:i(7,27),hidden:i(8,28),strikethrough:i(9,29),black:i(30,39),red:i(31,39),green:i(32,39),yellow:i(33,39),blue:i(34,39),magenta:i(35,39),cyan:i(36,39),white:i(37,39),gray:i(90,39),grey:i(90,39),bgBlack:i(40,49),bgRed:i(41,49),bgGreen:i(42,49),bgYellow:i(43,49),bgBlue:i(44,49),bgMagenta:i(45,49),bgCyan:i(46,49),bgWhite:i(47,49)};function r(e,t){let n,o=0,r="",i="";for(;o<e.length;o++)n=e[o],r+=n.open,i+=n.close,t.includes(n.close)&&(t=t.replace(n.rgx,n.close+n.open));return r+t+i}function i(e,t){let n={open:`[${e}m`,close:`[${t}m`,rgx:new RegExp(`\\x1b\\[${t}m`,"g")};return function(t){return void 0!==this&&void 0!==this.has?(this.has.includes(e)||(this.has.push(e),this.keys.push(n)),void 0===t?this:o.enabled?r(this.keys,t+""):t+""):void 0===t?function(e,t){let n={has:e,keys:t};return n.reset=o.reset.bind(n),n.bold=o.bold.bind(n),n.dim=o.dim.bind(n),n.italic=o.italic.bind(n),n.underline=o.underline.bind(n),n.inverse=o.inverse.bind(n),n.hidden=o.hidden.bind(n),n.strikethrough=o.strikethrough.bind(n),n.black=o.black.bind(n),n.red=o.red.bind(n),n.green=o.green.bind(n),n.yellow=o.yellow.bind(n),n.blue=o.blue.bind(n),n.magenta=o.magenta.bind(n),n.cyan=o.cyan.bind(n),n.white=o.white.bind(n),n.gray=o.gray.bind(n),n.grey=o.grey.bind(n),n.bgBlack=o.bgBlack.bind(n),n.bgRed=o.bgRed.bind(n),n.bgGreen=o.bgGreen.bind(n),n.bgYellow=o.bgYellow.bind(n),n.bgBlue=o.bgBlue.bind(n),n.bgMagenta=o.bgMagenta.bind(n),n.bgCyan=o.bgCyan.bind(n),n.bgWhite=o.bgWhite.bind(n),n}([e],[n]):o.enabled?r([n],t+""):t+""}}return l=o}());const u={directory:"isDirectory",file:"isFile"};const d=(e,t)=>t[u[e]]();function m(n,{cwd:i=r.cwd(),type:s="file",allowSymlinks:a=!0}={}){var l;!function(e){if(!Object.hasOwnProperty.call(u,e))throw new Error(`Invalid type specified: ${e}`)}(s),i=(l=i)instanceof URL?o(l):l;const c=a?e.statSync:e.lstatSync;for(const e of n)try{const n=c(t.resolve(i,e),{throwIfNoEntry:!1});if(!n)continue;if(d(s,n))return e}catch{}}const y=Symbol("findUpStop");function f(e,n={}){let r=t.resolve(((i=n.cwd)instanceof URL?o(i):i)||"");var i;const{root:s}=t.parse(r),a=n.stopAt||s,l=n.limit||Number.POSITIVE_INFINITY,c=[e].flat(),p=t=>{if("function"!=typeof e)return m(c,t);const n=e(t.cwd);return"string"==typeof n?m([n],t):n},u=[];for(;;){const e=p({...n,cwd:r});if(e===y)break;if(e&&u.push(t.resolve(r,e)),r===a||u.length>=l)break;r=t.dirname(r)}return u}function g({cwd:e}={}){const n=function(e,t={}){return f(e,{...t,limit:1})[0]}("package.json",{cwd:e});return n&&t.dirname(n)}const h="Props",$="ContentType",b="List",F=t.dirname(o(import.meta.url));function v(e){return{AIReferenceField:"Fields.AIReference",FormCategorySelect:"Fields.FormCategorySelect",FormContainer:"Fields.FormContainer",FormFieldArray:"Fields.FormFieldArray",ArrayFieldGroup:"Fields.ArrayFieldGroup",AsyncCheckGroup:"Fields.AsyncCheckGroup",AsyncSelect:"Fields.AsyncSelect",CheckGroup:"Fields.CheckGroup",ColorPicker:"Fields.ColorPicker",ComponentArray:"Fields.ComponentArray",ComponentContainer:"Fields.ComponentContainer",ConditionalField:"Fields.Conditional",DateField:"Fields.Date",FieldGroup:"Fields.FieldGroup",FieldsDivider:"Fields.FieldsDivider",FileField:"Fields.File",HeadingField:"Fields.Heading",ImageField:"Fields.Image",LinkField:"Fields.Link",MultiCheckSelect:"Fields.MultiCheckSelect",MultiCheckSelectGroup:"Fields.MultiCheckSelectGroup",NoteField:"Fields.Note",NumberField:"Fields.Number",RadioGroup:"Fields.RadioGroup",ReferenceField:"Fields.Reference",RichText:"Fields.RichText",Select:"Fields.Select",SliderField:"Fields.Slider",TagsField:"Fields.Tags",TextArea:"Fields.TextArea",TextField:"Fields.Text",TimeField:"Fields.Time",ToggleField:"Fields.Toggle",UniqueCheck:"Fields.UniqueCheck",UrlField:"Fields.Url",VisualUniqueSelection:"Fields.VisualUniqueSelection",Wysiwyg:"Fields.Wysiwyg"}[e]}function T(e,t){var n;const{returnTypeName:o,generic:r}=t||{},i="hideable"in e&&Boolean(e.hideable),s=r?`<${r}>`:"",a=`${o||v(e.type)}${s}`,l=i?`Hideable<${a}>`:`${a}`;return`\n\t\t${(null===(n=e._autoType)||void 0===n?void 0:n.doc)||""}\n\t\t${`${e.key}?: ${l}`}\n\t`}const C=F.includes("node_modules");function P(e,t,n){var o,r,i,s;const a=(null===(o=n.autotypesConfig)||void 0===o?void 0:o.interfaceSuffix)||h,l=(null===(r=n.autotypesConfig)||void 0===r?void 0:r.contentTypeSuffix)||$;if("FieldsDivider"===e.type)return"// FieldsDivider";if(null===(i=e._autoType)||void 0===i?void 0:i.ignore)return"// Ignored by AutoType.ignore";const{type:c,_autoType:p,key:u}=e,{hasDistributorData:d,getStaticData:m}=n;if(!c||!u)return"\n\t\t\t/** · (ノ-_-)ノ ミ ┴┴ You forgot to write the `type` | `key` or some mandatory prop */\n\t\t";if("DateField"===c||"FileField"===c||"ImageField"===c||"NoteField"===c||"NumberField"===c||"RichText"===c||"SliderField"===c||"TagsField"===c||"TextArea"===c||"TextField"===c||"TimeField"===c||"ToggleField"===c||"UniqueCheck"===c||"UrlField"===c||"Wysiwyg"===c)return T(e);if("MultiCheckSelect"===c){if("pageContentType"===t||"simpleContentType"===t){const t=`${e.source}${l}${a}`;return T(e,{generic:`Relations, FromList, ${t}<false, false>, FromDistributor`})}return T(e,{generic:"true"})}if("AsyncCheckGroup"===c){if("pageContentType"===t||"simpleContentType"===t){const t=`${e.source}${l}${a}`;return T(e,{generic:`Relations, FromList, ${t}<false, false>, FromDistributor`})}return T(e,{generic:"true"})}if("MultiCheckSelectGroup"===c){const t=[e.elements.map(e=>`"${e.key}"`).join("|"),null===(s=e._autoType)||void 0===s?void 0:s.relations].join(",");return T(e,{generic:t})}if("ColorPicker"===c)return e.isThemePalette?T(e,{returnTypeName:"Fields.ColorPickerFixed"}):T(e);if("HeadingField"===c||"RadioGroup"===c||"Select"===c){const{options:t}=e,n=function(e){return e.map(({value:e})=>"string"==typeof e?`"${e}"`:e).join("|")}(t);return T(e,{generic:n})}if("CheckGroup"===c){const{options:t}=e,n=function(e){return e.map(({name:e})=>"string"==typeof e?`"${e}"`:e).join("|")}(t);return T(e,{generic:n})}if("LinkField"===c){const{whiteList:t}=e;let o="";if(t.length>1&&"default"in n.schema){const t=n.schema.default[e.key].modal,r=Object.keys(t).map(e=>`${e}?: ${t[e].component}${a}`).join(",");o=`{${r}}`}else o=`${t[0]}${a}`;return T(e,{generic:o})}if("AsyncSelect"===c){if("entity"in e&&"menu_containers"===e.entity)return`\n${u}?: Menu`;if("pageContentType"===t||"simpleContentType"===t){const t=`${e.source}${l}${a}`;return T(e,{generic:`Relations, FromList, ${t}<false, false>, FromDistributor`})}return`\n${u}?: Fields.AsyncSelect;`}if("FieldGroup"===c)return`\n\t\t\t// << ${c}\n\t\t\t${e.fields.map(e=>P(e,t,n)).join("")}\n\t\t\t// end >>\n\t\t`;if("ArrayFieldGroup"===c){return`\n\t\t\t\n${(null==p?void 0:p.doc)||""}\n${u}?: Fields.ArrayFieldGroup<{${e.fields.map(e=>P(e,t,Object.assign(Object.assign({},n),{_from:"ArrayFieldGroup",_fromKey:u}))).join(",")}}>\n\t\t`}if("ConditionalField"===c){const o=e.fields.map(e=>P(e,t,n)),r=(null==p?void 0:p.doc)||"",i="hideable"in e&&e.hideable,s=i?">":"";return`\n\t\t\t// << ${c}\n\t\t\t\n${r}\n${u}?: ${i?"Hideable<":""}${v(c)}<${e.options.map(e=>"string"==typeof e.value?`"${e.value}"`:e.value).join("|")}>${s};\n\t\t\t${o.join("")}\n\t\t\t// end >>\n\t\t`}if("FormFieldArray"===c){const o="template"===t||"pageContentType"===t?"TemplateSection":"formTemplate"===t?"FormFieldArray":"ComponentArray",r="template"===t?"":"?",{key:i,_autoType:s,whiteList:l}=e,c=(null==s?void 0:s.doc)||"",p=(e,t,n)=>e.filter(e=>e&&"schemaType"in e&&"module"===(null==e?void 0:e.schemaType)?(null==e?void 0:e.sectionList)&&!!(null==e?void 0:e.sectionList[t]):void 0).map(e=>({t:null==e?void 0:e.sectionList[t].filter(e=>e===n),m:null==e?void 0:e.component})).filter(e=>{var t;return null===(t=null==e?void 0:e.t)||void 0===t?void 0:t.length}).map(e=>null==e?void 0:e.m).filter(Boolean);let u="";"template"===t&&(u=p(n.moduleSchemas,n.schema.component,i).join("|"));return`\n${c}\n${i}${r}: Fields.${o}<${[...new Set([...u.split("|"),...l])].filter(Boolean).map(e=>`${e}${a}`).join("|")}>;`}if("ComponentArray"===c){const o="template"===t||"pageContentType"===t?"TemplateSection":"ComponentArray",r="template"===t?"":"?",i=e,{key:s,_autoType:l,whiteList:c}=i,p=(null==l?void 0:l.doc)||"",u=(e,t,n)=>e.filter(e=>{if(e&&"schemaType"in e&&"module"===(null==e?void 0:e.schemaType))return(null==e?void 0:e.sectionList)&&!!(null==e?void 0:e.sectionList[t])}).map(e=>({t:null==e?void 0:e.sectionList[t].filter(e=>e===n),m:null==e?void 0:e.component})).filter(e=>{var t;return null===(t=null==e?void 0:e.t)||void 0===t?void 0:t.length}).map(e=>null==e?void 0:e.m).filter(Boolean);let d="";"template"===t&&(d=u(n.moduleSchemas,n.schema.component,s).join("|"));return`\n${p}\n${s}${r}: Fields.${o}<${[...new Set([...d.split("|"),...c])].filter(Boolean).map(e=>`${e}${a}`).join("|")}>;`}if("ComponentContainer"===c&&("object"===t||"component"===t||"module"===t||"template"===t||"pageContentType"===t)){const t=e,{whiteList:o}=t;let r="";if(o.length>1&&"default"in n.schema)if("ArrayFieldGroup"===n._from){const t=n._fromKey;r=`{${n.schema.default[t].map(t=>Object.keys(t[e.key]).map(n=>`${n}:${t[e.key][n].component}${a}`)).join("")}}`}else{const t=n.schema.default[e.key],o=Object.keys(t).map(e=>`${e}?: ${t[e].component}${a};`).join("");r=`{${o}}`}else r=`${o[0]}${a}`;return T(e,{generic:r})}if("FormContainer"===c&&("object"===t||"component"===t||"module"===t||"template"===t||"pageContentType"===t)){return`\n${(null==p?void 0:p.doc)||""}\n${u}?: Fields.FormContainer<FormTemplates${a}>;`}if("ReferenceField"===c){const t=e.sources||[{structuredData:void 0}],n=Array.isArray(t)&&t.map(e=>e.structuredData?`${e.structuredData}${l}${a}`:"unknown").join("|")||"";return`\n\t\t \t${T(e,{generic:n})}\n\t\t \t${d||m?`queriedItems?: Fields.QueriedData<${n}>;`:""}\n\t\t `}if("VisualUniqueSelection"===c){const t=e.options[0],n=e.options[0];let o="";if(t.value){o=e.options.map(e=>`"${e.value}"`).join("|")}if(n.theme){o=e.options[0].options.map(e=>`"${e.value}"`).join("|")}return T(e,{generic:o})}return"FormCategorySelect"===c?`${u}?: Fields.FormCategorySelect<FormCategoryLabels>`:"AIReferenceField"===c?`${u}?: Fields.AIReference`:(console.warn(`The field ${e.type} has not been implemented yet ㅠ.ㅠ`),"")}class S{setParser(e){this.parser=e}parse(e,t){var n;return(null===(n=this.parser)||void 0===n?void 0:n.parse(e,t))||""}}const k={ComponentsNameParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type Components = ${t.join("|")}`:""}},DataPacksCategoryParser:class{parse(e){return e?`export type DatapacksCategories = ${Object.keys(e).map(e=>`"${e}"`).join("|")}`:""}},DataPacksParser:class{parse(e){return e?`export type Datapacks = ${Object.keys(e).map(e=>`"${e}"`).join("|")}`:""}},DataTemplatesNameParser:class{parse(e){const t=Object.keys(e).map(t=>"detail"===e[t].type.mode?`"${t}"`:"").filter(Boolean);return t.length?`export type DetailTemplates = ${t.join("|")}`:""}},FormCategoryNamesParser:class{parse(e){const t=e.map(({value:e})=>`"${e}"`);return t.length?`export type FormCategoryLabels = ${t.join("|")}`:""}},FormFieldsParser:class{parse(e,t){var n;const o=(null===(n=t.autotypes)||void 0===n?void 0:n.interfaceSuffix)||h,r=Object.keys(e).map(e=>`"${e}"`),i=Object.keys(e).map(e=>`${e}${o}`);return r.length?`export type FormFields = ${r.join("|")}\nexport type FormFields${o} = ${i.join("|")}\n`:""}},FormTemplatesParser:class{parse(e,t){var n;const o=(null===(n=t.autotypes)||void 0===n?void 0:n.interfaceSuffix)||h,r=Object.keys(e).map(e=>`"${e}"`),i=Object.keys(e).map(e=>`${e}${o}`);return r.length?`export type FormTemplates = ${r.join("|")}\nexport type FormTemplates${o} = ${i.join("|")}\n`:""}},LanguagesParser:class{parse(e){const t=Object.keys(e);return`\n\t\texport interface SiteLanguage {\n\t\t\tdomain: { id: number; url: string; slug: string };\n\t\t\thome: string;\n\t\t\tid: number;\n\t\t\tisDefault: boolean;\n\t\t\tlabel: ${t.map(t=>{var n;return`"${null===(n=e[t])||void 0===n?void 0:n.label}"`}).join("|")};\n\t\t\tlanguage: ${t.map(t=>{var n;return`"${null===(n=e[t])||void 0===n?void 0:n.name}"`}).join("|")};\n\t\t\tlocale: ${t.map(e=>`"${e}"`).join("|")}\n\t\t\tpath: string;\n\t\t}\n\t`}},MenuItemsParser:class{getMenuItemsProps(e,t){return e?e.map(e=>P(e,"object",{hasDistributorData:!1,getStaticData:!1,moduleSchemas:[],schema:{},allSchemas:{},autotypesConfig:t})).join(""):""}parse(e,t){var n,o;const r=null===(n=null==e?void 0:e.link)||void 0===n?void 0:n.fields,i=null===(o=null==e?void 0:e.group)||void 0===o?void 0:o.fields;return`\n\t\texport interface InstanceMenuItems {\n\t\t\tlink:{\n\t\t\t\t${this.getMenuItemsProps(r,t.autotypes)}\n\t\t\t\tconfig?: {\n\t\t\t\t\theaderStyle?: string;\n\t\t\t\t\tfooterStyle?: string;\n\t\t\t\t\ttype?: "link";\n\t\t\t\t};\n\t\t\t};\n\t\t\tgroup: {\n\t\t\t\turl?: null;\n\t\t\t\t${this.getMenuItemsProps(i,t.autotypes)}\n\t\t\t\tconfig?: {\n\t\t\t\t\theaderStyle?: string;\n\t\t\t\t\tfooterStyle?: string;\n\t\t\t\t\ttype?: "group";\n\t\t\t\t};\n\t\t\t};\n\t\t}\n\t\texport type LinkMenuElement = Fields.BaseLinkElement<InstanceMenuItems> & InstanceMenuItems["link"];\n\t\texport type GroupMenuElement = Fields.BaseLinkElement<InstanceMenuItems> & InstanceMenuItems["group"];\n\t\texport type MenuElement = LinkMenuElement | GroupMenuElement;\n\t\texport type Menu = Fields.Menu<InstanceMenuItems>;\n\t`}},ModuleCateogiresParser:class{parse(e){return e?`export type ModuleCategories = ${e.map(e=>`"${e.value}"`).join("|")}`:""}},ModulesNameParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type Modules = ${t.join("|")}`:""}},PageContentTypeParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type PageContentTypes = ${t.join("|")}`:""}},PageDataPropsParser:class{parse(e,t){var n,o;const r=(null===(n=t.autotypes)||void 0===n?void 0:n.contentTypeSuffix)||$,i=(null===(o=t.autotypes)||void 0===o?void 0:o.interfaceSuffix)||h,s=Object.keys(e).map(e=>`${e}${r}${i}`);return s.length?`export type Page${r}${i} = ${s.join("|")}`:""}},SimpleContentTypeParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type SimpleContentTypes = ${t.join("|")}`:""}},SimpleDataPropsParser:class{parse(e,t){var n,o;const r=(null===(n=t.autotypes)||void 0===n?void 0:n.contentTypeSuffix)||$,i=(null===(o=t.autotypes)||void 0===o?void 0:o.interfaceSuffix)||h,s=Object.keys(e).map(e=>`${e}${r}${i}`);return s.length?`export type Simple${r}${i} = ${s.join("|")}`:""}},SubthemesParser:class{parse(e){return Array.isArray(e)&&e.length?`export type Subthemes = ${e.map(e=>`"${e}"`).join("|")}`:""}},TaxonomyParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type TaxonomyContentTypes = ${t.join("|")}`:""}},TaxonomyPropsParser:class{parse(e,t){var n,o;const r=(null===(n=t.autotypes)||void 0===n?void 0:n.contentTypeSuffix)||$,i=(null===(o=t.autotypes)||void 0===o?void 0:o.interfaceSuffix)||h,s=Object.keys(e).map(e=>`${e}${r}${i}`);return s.length?`export type Taxonomy${r}${i} = ${s.join("|")}`:""}},TemplateSectionListParser:class{parse(e){const t=[];for(const n in e){const o=e[n],r=o.content.filter(e=>"ComponentArray"===e.type).map(({key:e})=>`"${e}"`).filter(Boolean),i=r&&(null==r?void 0:r.length)>0?`${o.component}?: NonEmptyArray<${r.join("|")}>;`:"";t.push(i)}return`\n\t\t\texport type SectionList = { ${t.join("")} }\n\t\t`}},TemplatesNameParser:class{parse(e){const t=Object.keys(e).map(e=>`"${e}"`);return t.length?`export type Templates = ${t.join("|")}`:""}},ThemesParser:class{parse(e){return Array.isArray(e)&&e.length?`export type Themes = ${e.map(e=>`"${e.value}"`).join("|")}`:""}},UIAndDataPropsParser:class{parse(e,t){var n;const o=(r=e,Object.keys(r).map(e=>Object.assign(Object.assign({},r[e]),{component:e})));var r;const i=(null===(n=t.autotypes)||void 0===n?void 0:n.interfaceSuffix)||h,{ARRAY_OF_MODULE_SCHEMAS:s}=function(e){const t=e.map(e=>{if("schemaType"in e&&"module"===e.schemaType)return e}).filter(Boolean);return{ARRAY_OF_MODULE_SCHEMAS:t}}(o);return o.map(e=>{var n;let o={kind:"component",contentTypeSuffixStr:"",contentTypeName:"",contentTypeKind:"",relatedContentTypeNames:"",componentName:"",hasDistributorData:!1,getStaticData:!1,interfaceForPublicAPI:"",relationsGeneric:(null===(n=e._autoType)||void 0===n?void 0:n.relations)?"<Relations = unknown, FromList = unknown, FromDistributor = true>":""};if(function(e){return"fromPage"in e}(e)){const n=function(e,t){var n,o,r;const i=[],s=[],a=[],l=e.fromPage?"pageContentType":"simpleContentType",c=(null===(n=t.autotypes)||void 0===n?void 0:n.contentTypeSuffix)||$,p=(null===(o=t.autotypes)||void 0===o?void 0:o.publicApiSuffix)||b,u=(null===(r=t.autotypes)||void 0===r?void 0:r.interfaceSuffix)||h;"pageContentType"===l&&i.push(`"${e.component}"`);"simpleContentType"!==l||e.taxonomy||s.push(`"${e.component}"`);"simpleContentType"===l&&e.taxonomy&&a.push(`"${e.component}"`);let d="";if("schema"in e){const t=e.schema.fields.map(e=>"source"in e&&(null==e?void 0:e.source)).filter(Boolean);d=t.length?`__relatedContentTypeNames: ${JSON.stringify(t)}`:""}const m="<Relations = unknown, FromList = unknown, FromDistributor = true>",y=`\n\t\t\t\t/** Type to be consumed by public API: useList(), etc.. */\n\t\t\t\texport type ${e.component}${c}${p}${u}<R extends Core.ContentTypeRelations = false> = ${e.component}${c}${u}<R, true>;\n\t\t\t\t`;return{kind:l,componentName:"",contentTypeName:`__contentTypeName: "${e.component}";`,contentTypeKind:`__contentTypeKind: "${l}";`,contentTypeSuffixStr:c,getStaticData:!1,hasDistributorData:!1,relatedContentTypeNames:d,relationsGeneric:m,interfaceForPublicAPI:y}}(e,t);o=Object.assign(Object.assign({},o),n)}if(function(e){return"schemaType"in e}(e)){const t=function(e){return{kind:e.schemaType,componentName:`component: "${e.component}"`,contentTypeName:"",contentTypeKind:"",contentTypeSuffixStr:"",relatedContentTypeNames:"",relationsGeneric:"",interfaceForPublicAPI:"",hasDistributorData:!!e.default.hasDistributorData,getStaticData:!!e.default.getStaticData}}(e);o=Object.assign(Object.assign({},o),t)}const r=function(e,t,n,o,r){return function(e){if("fromPage"in e)return e.taxonomy?[]:e.schema.fields;if("template"===e.schemaType){return[...e.content||[],...e.config||[]]}if("formTemplate"===e.schemaType){return[...e.content||[],...e.config||[]]}if("component"===e.schemaType||"module"===e.schemaType||"formComponent"===e.schemaType)return e.configTabs.flatMap(e=>e.fields);throw new Error(`Wrong schema ${JSON.stringify(e,null,2)}`)}(e).map(i=>P(i,o.kind,{hasDistributorData:o.hasDistributorData,getStaticData:o.getStaticData,moduleSchemas:t,schema:e,allSchemas:n,autotypesConfig:r})).filter(Boolean).join("")}(e,s,e,o,t.autotypes);return`\n\t\t\t\texport interface ${e.component}${o.contentTypeSuffixStr}${i}${o.relationsGeneric} ${function(e){const t=function(e){return"schemaType"in e&&"template"===e.schemaType&&("list"===e.type.mode||"paginated-data"===e.type.mode)}(e)?"Fields.ExtraListTemplateProps":"";return n=[t],n.filter(e=>e.length).length<1?"":`extends ${n.join(", ")}`;var n}(e)} {\n\t\t\t\t\t${o.contentTypeName}\n\t\t\t\t\t${o.contentTypeKind}\n\t\t\t\t\t${o.relatedContentTypeNames}\n\t\t\t\t\t${o.componentName}\n\t\t\t\t\t${r}\n\t\t\t\t\t${function(e){return"fromPage"in e&&!e.fromPage&&!0===e.taxonomy}(e)?"title?: string; code?: string":""}\n\t\t\t\t}\n\t\t\t\t${o.interfaceForPublicAPI}\n\t\t\t`}).join("")}}};s(void 0,void 0,void 0,function*(){try{const r=function(){const e=F,n=C?"../../../":"../griddo-components";return t.resolve(g({cwd:e}),n)}(),a=t.join(r,"griddo.config.ts");let l;try{const e=yield(o=a,new Promise((e,r)=>{const i=t.resolve(o),s=n(process.execPath,["--import","tsx","-e",`import('${i}').then(m => console.log(JSON.stringify(m.default ?? m)))`],{stdio:["ignore","pipe","inherit"]});let a="";s.stdout.on("data",e=>{a+=e}),s.on("error",r),s.on("close",t=>{if(0!==t)return r(new Error(`Config process exited with code ${t}`));try{e(JSON.parse(a))}catch(e){r(e)}})}));l=e&&"object"==typeof e&&"default"in e?e.default:e}catch(e){console.error("Failed to load griddo.config.ts:",e),process.exit(1)}const{schemas:{config:{languages:c,menuItems:u,themes:d,subthemes:m,moduleCategories:y},contentTypes:{dataPacks:f,dataPacksCategories:h,structuredData:$},ui:{components:b,modules:v,templates:T},forms:P}}=l,{categoryContentTypes:j,pageContentTypes:x,simpleContentTypes:_}=function(e){return{categoryContentTypes:function(e){const t={};for(const n in e){const o=e[n];!o.fromPage&&o.taxonomy&&(t[n]=o)}return t}(e),pageContentTypes:function(e){const t={};for(const n in e){const o=e[n];o.fromPage&&(t[n]=o)}return t}(e),simpleContentTypes:function(e){const t={};for(const n in e){const o=e[n];o.fromPage||o.taxonomy||(t[n]=o)}return t}(e)}}(l.schemas.contentTypes.structuredData),D=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},b),v),T),$),(null==P?void 0:P.templates)||{}),(null==P?void 0:P.fields)||{}),A=function(e){const t=new S;return e.map(e=>(t.setParser(new e.parser),t.parse(e.schema,e.config)))}([{schema:u,parser:k.MenuItemsParser,config:l},{schema:c,parser:k.LanguagesParser,config:l},{schema:D,parser:k.UIAndDataPropsParser,config:l},{schema:m||{},parser:k.SubthemesParser,config:l},{schema:x,parser:k.PageContentTypeParser,config:l},{schema:_,parser:k.SimpleContentTypeParser,config:l},{schema:j,parser:k.TaxonomyParser,config:l},{schema:b,parser:k.ComponentsNameParser,config:l},{schema:v,parser:k.ModulesNameParser,config:l},{schema:(null==P?void 0:P.templates)||{},parser:k.FormTemplatesParser,config:l},{schema:(null==P?void 0:P.fields)||{},parser:k.FormFieldsParser,config:l},{schema:(null==P?void 0:P.categories)||[],parser:k.FormCategoryNamesParser,config:l},{schema:T,parser:k.TemplatesNameParser,config:l},{schema:T,parser:k.DataTemplatesNameParser,config:l},{schema:T,parser:k.TemplateSectionListParser,config:l},{schema:y,parser:k.ModuleCateogiresParser,config:l},{schema:f,parser:k.DataPacksParser,config:l},{schema:h,parser:k.DataPacksCategoryParser,config:l},{schema:j,parser:k.TaxonomyPropsParser,config:l},{schema:_,parser:k.SimpleDataPropsParser,config:l},{schema:x,parser:k.PageDataPropsParser,config:l},{schema:d,parser:k.ThemesParser,config:l}]),O=yield function(e){return s(this,void 0,void 0,function*(){return(yield i.format(e,{useTabs:!0,printWidth:120,parser:"typescript"})).replace(/^\s*\n/gm,"")})}(`\n\t\t\t/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-use-before-define */\n//\n//\n// ' ____\n// /\\ \\\n// º / /\\ \\\n// ' / / \\ _>\n// ' _\\ \\__> \\__\n// ' O ( __;·;______ ) AutoTypes\n// O º, | , , \\ \\\\ ·..~~.·~.·\n// ,,, /| , , /\\ <\\\\\n// \\''\\-' ⎩, <\\/\\ \\ \\\n// \\_/ /\\_____⎩/ > > >\n// '___' <_(_)__> / \\ <\n// / / ´ \\ | \\___//\\\\\n// / / | / > > \\\\\n// · ··~~~~·~·~~~~~~~·~··~~~~~·~·~~·~~~~·~~~~~·· · ·\n//\n// Embrace the beauty of effortless typing by indulging in the benefits of them\n// sans the actual typing!\n//\n// Behold! These dynamically generated types were conjured from the schemas\n// nestled within this repository. However, should you yearn to expand upon\n// these types, kindly abstain from doing so in this file, lest AutoTypes'\n// magic shall smite your changes with each schema modification.\n//\n// Check out the details of Griddo AutoTypes in:\n// https://griddoio.notion.site/Griddo-AutoTypes-e7420867dd2e489c8da34a493b763cd8>\n//\n// Happy magic types!\n//\nimport { Core, Fields, Hideable, NonEmptyArray } from "@griddo/core"\n//\n\n\t\t\t${A.join("\n")}\n\t\t`),w=t.join(r,"autotypes.d.ts");e.writeFileSync(w,O),console.log(`${p.green(" ✔")} AutoTypes`)}catch(e){console.log(`${p.red(" ✘")} AutoTypes`),console.log(e)}var o});
2
2
  //# sourceMappingURL=autotypes.js.map