@rizom/brain 0.2.0-alpha.32 → 0.2.0-alpha.34
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/brain.js +682 -485
- package/dist/deploy.js +2 -2
- package/dist/deploy.js.map +3 -3
- package/dist/seed-content/relay/README.md +27 -371
- package/dist/site.js +282 -282
- package/dist/site.js.map +4 -4
- package/package.json +1 -1
package/dist/deploy.js
CHANGED
|
@@ -165,10 +165,10 @@ Please report this to https://github.com/markedjs/marked.`,q){let G="<p>An error
|
|
|
165
165
|
`).trimEnd()+`
|
|
166
166
|
`}format(q){try{let J=[`# ${this.config.title}`,""];for(let $ of this.config.mappings)this.formatField(q,$,J,2);return J.join(`
|
|
167
167
|
`)}catch{throw Error("Failed to format structured content")}}parse(q){try{let J=this.processor.parse(q),$=this.extractSections(J,2),G=this.buildDataFromSections($,this.config.mappings);return this.schema.parse(G)}catch{throw Error("Failed to parse structured content")}}formatField(q,J,$,G){let X="#".repeat(G)+" "+J.label,Q=this.getValueByPath(q,J.key);if(J.type==="custom"&&J.formatter){if(Q!==void 0&&Q!==null){$.push(X,"");let Y=J.formatter(Q);if(Y)$.push(Y,"")}return}switch(J.type){case"string":case"number":$.push(X,String(Q??""),"");break;case"object":if($.push(X),J.children&&Q)for(let Y of J.children)this.formatField(Q,Y,$,G+1);break;case"array":if($.push(X,""),Array.isArray(Q))if(J.itemType==="object"&&J.itemMappings)Q.forEach((Y,V)=>{if($.push(`${"#".repeat(G+1)} ${J.label.slice(0,-1)} ${V+1}`),$.push(""),J.itemMappings)for(let W of J.itemMappings)this.formatField(Y,W,$,G+2)});else{for(let Y of Q){let V=this.defaultArrayItemFormat(Y);$.push(`- ${V}`)}$.push("")}break}}getValueByPath(q,J){let $=J.split("."),G=q;for(let X of $)if(G&&typeof G==="object"&&X in G)G=G[X];else return;return G}defaultArrayItemFormat(q){if(typeof q==="string"||typeof q==="number")return String(q);return JSON.stringify(q)}extractSections(q,J){let $=new Map,G=null,X=[];for(let Q of q.children)if(Q.type==="heading"&&Q.depth===J){if(G)$.set(G.toLowerCase(),X);G=this.getHeadingText(Q),X=[]}else if(G)X.push(Q);if(G)$.set(G.toLowerCase(),X);return $}extractSubsections(q,J){let $=new Map,G=null,X=[];for(let Q of q)if(Q.type==="heading"&&Q.depth===J){if(G)$.set(G.toLowerCase(),X);G=this.getHeadingText(Q),X=[]}else if(G)X.push(Q);if(G)$.set(G.toLowerCase(),X);return $}textNodeSchema=h.object({type:h.literal("text"),value:h.string()});extractTextValue(q){let J=this.textNodeSchema.safeParse(q);return J.success?J.data.value:""}getHeadingText(q){return q.children.filter(($)=>$.type==="text").map(($)=>this.extractTextValue($)).join("")}buildDataFromSections(q,J,$=2){let G={};for(let X of J){let Q=q.get(X.label.toLowerCase());if(X.type==="custom"&&X.parser&&Q){let Y=this.getTextFromSection(Q),V=X.parser(Y);this.setValueByPath(G,X.key,V)}else if(X.type==="object"&&X.children&&Q){let Y=this.extractSubsections(Q,$+1),V=this.buildDataFromSections(Y,X.children,$+1);this.setValueByPath(G,X.key,V)}else if(X.type==="array"&&Q)if(X.itemType==="object"&&X.itemMappings){let Y=this.extractObjectArrayItems(Q,$+1,X.itemMappings);this.setValueByPath(G,X.key,Y)}else{let Y=this.extractSimpleArrayItems(Q);this.setValueByPath(G,X.key,Y)}else if(Q){let Y=this.getTextFromSection(Q),V=X.type==="number"?Number(Y):Y;this.setValueByPath(G,X.key,V)}}return G}setValueByPath(q,J,$){let G=J.split("."),X=q;for(let Y=0;Y<G.length-1;Y++){let V=G[Y];if(!V)continue;if(!(V in X))X[V]={};X=X[V]}let Q=G[G.length-1];if(Q)X[Q]=$}getTextFromSection(q){let J=[];for(let $ of q)if($.type==="paragraph"){let G=this.extractTextFromParagraph($);if(G)J.push(G)}else if($.type==="list"){let G=$;for(let X of G.children){let Q=this.extractTextFromListItem(X);if(Q)J.push(`- ${Q}`)}}return J.join(`
|
|
168
|
-
`)}extractTextFromParagraph(q){let J=[];for(let $ of q
|
|
168
|
+
`)}extractTextFromParagraph(q){return this.extractInlineText(q.children).trim()}extractInlineText(q){let J=[];for(let $ of q)if($.type==="text")J.push(this.extractTextValue($));else if($.type==="emphasis"){let G=this.extractInlineText($.children);if(G)J.push(`*${G}*`)}else if($.type==="strong"){let G=this.extractInlineText($.children);if(G)J.push(`**${G}**`)}return J.join("")}extractSimpleArrayItems(q){let J=[];for(let $ of q)if($.type==="list"){let G=$;for(let X of G.children){let Q=this.extractTextFromListItem(X);if(Q)J.push(Q)}}return J}extractObjectArrayItems(q,J,$){let G=[],X=[],Q=!1;for(let Y of q)if(Y.type==="heading"&&Y.depth===J){if(Q&&X.length>0){let V=this.extractSubsections(X,J+1),W=this.buildDataFromSections(V,$,J+1);G.push(W)}X=[],Q=!0}else if(Q)X.push(Y);if(Q&&X.length>0){let Y=this.extractSubsections(X,J+1),V=this.buildDataFromSections(Y,$,J+1);G.push(V)}return G}extractTextFromListItem(q){let J=[];for(let $ of q.children)if($.type==="paragraph"){let G=this.extractTextFromParagraph($);if(G)J.push(G)}return J.join(`
|
|
169
169
|
`)}}var xL=h.object({slug:h.string(),title:h.string(),type:h.string(),entityId:h.string(),contentHash:h.string()});var yD=h.object({success:h.boolean(),entityId:h.string().optional(),error:h.string().optional()});import{appendFileSync as q$,readFileSync as J$}from"fs";var xD=/^# ---- .+ ----$/;function j5(q,J){let $=[],G=new Set,X=J?.skipSections??new Set,Q=!1,Y=!1,V=!1;for(let W of q.split(/\r?\n/)){let U=W.trim();if(xD.test(U)){Q=X.has(U),Y=!1,V=!1;continue}if(Q)continue;if(U.startsWith("#")){if(U.includes("@required"))Y=!0;if(U.includes("@sensitive"))V=!0;continue}let H=U.match(/^([A-Z][A-Z0-9_]*)=/);if(!H?.[1]){Y=!1,V=!1;continue}let z=H[1];if(!G.has(z))G.add(z),$.push({key:z,required:Y,sensitive:V});Y=!1,V=!1}return $}function $$(q,J){return j5(J$(q,"utf8"),J)}async function G$(q,J){let $=await q.text();if(!$)throw Error(`${J} returned an empty response (${q.status})`);try{return JSON.parse($)}catch{throw Error(`${J} returned invalid JSON (${q.status}): ${$}`)}}function X$(q){let J=J$(q,"utf8");return Object.fromEntries(J.split(/\r?\n/).filter(Boolean).map(($)=>{let G=$.indexOf("=");return[$.slice(0,G),$.slice(G+1)]}))}function Q$(q){let J=process.env[q];if(!J)throw Error(`Missing ${q}`);return J}function Y$(q,J){let $=process.env.GITHUB_OUTPUT;if($)q$($,`${q}=${J}
|
|
170
170
|
`)}function V$(q,J){let $=process.env.GITHUB_ENV;if($)q$($,`${q}=${J}
|
|
171
171
|
`)}export{Y$ as writeGitHubOutput,V$ as writeGitHubEnv,Q$ as requireEnv,G$ as readJsonResponse,$$ as parseEnvSchemaFile,j5 as parseEnvSchema,X$ as parseEnvFile};
|
|
172
172
|
|
|
173
|
-
//# debugId=
|
|
173
|
+
//# debugId=4D7002F90219197064756E2164756E21
|
|
174
174
|
//# sourceMappingURL=deploy.js.map
|