@rizom/brain 0.2.0-alpha.63 → 0.2.0-alpha.65
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 +1166 -992
- package/dist/entities.js +2 -2
- package/dist/entities.js.map +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/plugins.d.ts +78 -2
- package/dist/plugins.js +90 -90
- package/dist/plugins.js.map +11 -11
- package/dist/services.js +2 -2
- package/dist/services.js.map +2 -2
- package/dist/site.js +100 -100
- package/dist/site.js.map +19 -16
- package/package.json +1 -1
package/dist/entities.js
CHANGED
|
@@ -166,7 +166,7 @@ Please report this to https://github.com/markedjs/marked.`,$){let X="<p>An error
|
|
|
166
166
|
`}format($){try{let J=[`# ${this.config.title}`,""];for(let G of this.config.mappings)this.formatField($,G,J,2);return J.join(`
|
|
167
167
|
`)}catch{throw Error("Failed to format structured content")}}parse($){try{let J=this.processor.parse($),G=this.extractSections(J,2),X=this.buildDataFromSections(G,this.config.mappings);return this.schema.parse(X)}catch{throw Error("Failed to parse structured content")}}formatField($,J,G,X){let q="#".repeat(X)+" "+J.label,Y=this.getValueByPath($,J.key);if(J.type==="custom"&&J.formatter){if(Y!==void 0&&Y!==null){G.push(q,"");let V=J.formatter(Y);if(V)G.push(V,"")}return}switch(J.type){case"string":case"number":G.push(q,String(Y??""),"");break;case"object":if(G.push(q),J.children&&Y)for(let V of J.children)this.formatField(Y,V,G,X+1);break;case"array":if(G.push(q,""),Array.isArray(Y))if(J.itemType==="object"&&J.itemMappings)Y.forEach((V,W)=>{if(G.push(`${"#".repeat(X+1)} ${J.label.slice(0,-1)} ${W+1}`),G.push(""),J.itemMappings)for(let H of J.itemMappings)this.formatField(V,H,G,X+2)});else{for(let V of Y){let W=this.defaultArrayItemFormat(V);G.push(`- ${W}`)}G.push("")}break}}getValueByPath($,J){let G=J.split("."),X=$;for(let q of G)if(X&&typeof X==="object"&&q in X)X=X[q];else return;return X}defaultArrayItemFormat($){if(typeof $==="string"||typeof $==="number")return String($);return JSON.stringify($)}extractSections($,J){let G=new Map,X=null,q=[];for(let Y of $.children)if(Y.type==="heading"&&Y.depth===J){if(X)G.set(X.toLowerCase(),q);X=this.getHeadingText(Y),q=[]}else if(X)q.push(Y);if(X)G.set(X.toLowerCase(),q);return G}extractSubsections($,J){let G=new Map,X=null,q=[];for(let Y of $)if(Y.type==="heading"&&Y.depth===J){if(X)G.set(X.toLowerCase(),q);X=this.getHeadingText(Y),q=[]}else if(X)q.push(Y);if(X)G.set(X.toLowerCase(),q);return G}textNodeSchema=Z.object({type:Z.literal("text"),value:Z.string()});extractTextValue($){let J=this.textNodeSchema.safeParse($);return J.success?J.data.value:""}getHeadingText($){return $.children.filter((G)=>G.type==="text").map((G)=>this.extractTextValue(G)).join("")}buildDataFromSections($,J,G=2){let X={};for(let q of J){let Y=$.get(q.label.toLowerCase());if(q.type==="custom"&&q.parser&&Y){let V=this.getTextFromSection(Y),W=q.parser(V);this.setValueByPath(X,q.key,W)}else if(q.type==="object"&&q.children&&Y){let V=this.extractSubsections(Y,G+1),W=this.buildDataFromSections(V,q.children,G+1);this.setValueByPath(X,q.key,W)}else if(q.type==="array"&&Y)if(q.itemType==="object"&&q.itemMappings){let V=this.extractObjectArrayItems(Y,G+1,q.itemMappings);this.setValueByPath(X,q.key,V)}else{let V=this.extractSimpleArrayItems(Y);this.setValueByPath(X,q.key,V)}else if(Y){let V=this.getTextFromSection(Y),W=q.type==="number"?Number(V):V;this.setValueByPath(X,q.key,W)}}return X}setValueByPath($,J,G){let X=J.split("."),q=$;for(let V=0;V<X.length-1;V++){let W=X[V];if(!W)continue;if(!(W in q))q[W]={};q=q[W]}let Y=X[X.length-1];if(Y)q[Y]=G}getTextFromSection($){let J=[];for(let G of $)if(G.type==="paragraph"){let X=this.extractTextFromParagraph(G);if(X)J.push(X)}else if(G.type==="list"){let X=G;for(let q of X.children){let Y=this.extractTextFromListItem(q);if(Y)J.push(`- ${Y}`)}}return J.join(`
|
|
168
168
|
`)}extractTextFromParagraph($){return this.extractInlineText($.children).trim()}extractInlineText($){let J=[];for(let G of $)if(G.type==="text")J.push(this.extractTextValue(G));else if(G.type==="emphasis"){let X=this.extractInlineText(G.children);if(X)J.push(`*${X}*`)}else if(G.type==="strong"){let X=this.extractInlineText(G.children);if(X)J.push(`**${X}**`)}return J.join("")}extractSimpleArrayItems($){let J=[];for(let G of $)if(G.type==="list"){let X=G;for(let q of X.children){let Y=this.extractTextFromListItem(q);if(Y)J.push(Y)}}return J}extractObjectArrayItems($,J,G){let X=[],q=[],Y=!1;for(let V of $)if(V.type==="heading"&&V.depth===J){if(Y&&q.length>0){let W=this.extractSubsections(q,J+1),H=this.buildDataFromSections(W,G,J+1);X.push(H)}q=[],Y=!0}else if(Y)q.push(V);if(Y&&q.length>0){let V=this.extractSubsections(q,J+1),W=this.buildDataFromSections(V,G,J+1);X.push(W)}return X}extractTextFromListItem($){let J=[];for(let G of $.children)if(G.type==="paragraph"){let X=this.extractTextFromParagraph(G);if(X)J.push(X)}return J.join(`
|
|
169
|
-
`)}}var IS=Z.object({slug:Z.string(),title:Z.string(),type:Z.string(),entityId:Z.string(),contentHash:Z.string()});var NF=Z.object({success:Z.boolean(),entityId:Z.string().optional(),error:Z.string().optional()});var
|
|
169
|
+
`)}}var IS=Z.object({slug:Z.string(),title:Z.string(),type:Z.string(),entityId:Z.string(),contentHash:Z.string()});var NF=Z.object({success:Z.boolean(),entityId:Z.string().optional(),error:Z.string().optional()});var fC=Z.object({id:Z.string().min(1,"Entity ID is required"),entityType:Z.string().min(1,"Entity type is required"),contentHash:Z.string().min(1,"Content hash is required"),operation:Z.enum(["create","update"])});var lC=Z.object({limit:Z.number().int().positive().optional().default(20),offset:Z.number().int().min(0).optional().default(0),types:Z.array(Z.string()).optional().default([]),excludeTypes:Z.array(Z.string()).optional().default([]),weight:Z.record(Z.string(),Z.number()).optional()});var PF=Z.object({field:Z.string(),direction:Z.enum(["asc","desc"]),nullsFirst:Z.boolean().optional()}),eC=Z.object({limit:Z.number().int().positive().optional(),offset:Z.number().int().min(0).optional().default(0),sortFields:Z.array(PF).optional(),filter:Z.object({metadata:Z.record(Z.string(),Z.unknown()).optional()}).optional(),publishedOnly:Z.boolean().optional()});var H6=o2(n6(),1);function U6($,J){if(Object.keys(J).length===0)return $;let G=Object.fromEntries(Object.entries(J).filter(([,X])=>X!==void 0));return H6.default.stringify($,G)}function z8($){if($ instanceof Date)return $.toISOString();if(Array.isArray($))return $.map(z8);if($!==null&&typeof $==="object"){let J={};for(let[G,X]of Object.entries($))J[G]=z8(X);return J}return $}function p0($,J){let{content:G,data:X}=H6.default($),q=z8(X);return{content:G.trim(),metadata:J.parse(q)}}function Q6($){if(Object.keys($).length===0)return"";let G=H6.default.stringify("",$).match(/^---\n[\s\S]*?\n---/);return G?G[0]:""}var vF={generateBodyTemplate:()=>""};class c2{entityType;schema;frontmatterSchema;isSingleton;hasBody;supportsCoverImage;fmSchema;bodyFormatter;constructor($){if(this.entityType=$.entityType,this.schema=$.schema,this.frontmatterSchema=$.frontmatterSchema,this.fmSchema=$.frontmatterSchema,this.bodyFormatter=$.bodyFormatter??vF,$.isSingleton!==void 0)this.isSingleton=$.isSingleton;if($.hasBody!==void 0)this.hasBody=$.hasBody;if($.supportsCoverImage!==void 0)this.supportsCoverImage=$.supportsCoverImage}toMarkdown($){let J=this.renderBody($),X={...this.readExistingFrontmatter($.content)},q=Object.keys(this.frontmatterSchema.shape);for(let[Y,V]of Object.entries($.metadata))if(q.includes(Y))X[Y]=V;return this.buildMarkdown(J,X)}renderBody($){return this.extractBody($.content)}readExistingFrontmatter($){try{return p0($,Z.record(Z.unknown())).metadata}catch{return{}}}extractMetadata($){return $.metadata}parseFrontMatter($,J){return p0($,J).metadata}getBodyTemplate(){return this.bodyFormatter.generateBodyTemplate()}generateFrontMatter($){let J=$.metadata;return Q6(J)}extractBody($){try{return p0($,Z.record(Z.unknown())).content}catch{return $}}parseFrontmatter($){return p0($,this.fmSchema).metadata}buildMarkdown($,J){return U6($,J)}}var kX="base",K8=Z.object({id:Z.string(),entityType:Z.string(),content:Z.string(),created:Z.string().datetime(),updated:Z.string().datetime(),metadata:Z.record(Z.string(),Z.unknown()),contentHash:Z.string()});var yX=Z.object({currentPage:Z.number(),totalPages:Z.number(),totalItems:Z.number(),pageSize:Z.number(),hasNextPage:Z.boolean(),hasPrevPage:Z.boolean()});function fX($,J,G){let X=Math.max(1,Math.ceil($/G));return{currentPage:J,totalPages:X,totalItems:$,pageSize:G,hasNextPage:J<X,hasPrevPage:J>1}}function mX($,J){let{page:G,limit:X,pageSize:q}=J;if(G!==void 0){let Y=G,V=q??X??$.length,W=$.length,H=Math.ceil(W/V),U=(Y-1)*V,Q=U+V;return{items:$.slice(U,Q),pagination:{currentPage:Y,totalPages:H,totalItems:W,pageSize:V,hasNextPage:Y<H,hasPrevPage:Y>1}}}if(X!==void 0)return{items:$.slice(0,X),pagination:null};return{items:$,pagination:null}}export{p0 as parseMarkdownWithFrontmatter,yX as paginationInfoSchema,mX as paginateItems,U6 as generateMarkdownWithFrontmatter,Q6 as generateFrontmatter,fX as buildPaginationInfo,K8 as baseEntitySchema,c2 as BaseEntityAdapter,kX as BASE_ENTITY_TYPE};
|
|
170
170
|
|
|
171
|
-
//# debugId=
|
|
171
|
+
//# debugId=DDF982E4E60BB5C464756E2164756E21
|
|
172
172
|
//# sourceMappingURL=entities.js.map
|