@polagram/core 0.0.2
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/README.md +124 -0
- package/dist/index.d.ts +625 -0
- package/dist/polagram-core.js +3653 -0
- package/dist/polagram-core.umd.cjs +28 -0
- package/dist/src/api.d.ts +75 -0
- package/dist/src/api.js +160 -0
- package/dist/src/ast/ast.test.d.ts +1 -0
- package/dist/src/ast/ast.test.js +146 -0
- package/dist/src/ast/index.d.ts +119 -0
- package/dist/src/ast/index.js +2 -0
- package/dist/src/config/index.d.ts +1 -0
- package/dist/src/config/index.js +1 -0
- package/dist/src/config/schema.d.ts +182 -0
- package/dist/src/config/schema.js +78 -0
- package/dist/src/config/schema.test.d.ts +1 -0
- package/dist/src/config/schema.test.js +94 -0
- package/dist/src/generator/base/walker.d.ts +19 -0
- package/dist/src/generator/base/walker.js +56 -0
- package/dist/src/generator/base/walker.test.d.ts +1 -0
- package/dist/src/generator/base/walker.test.js +49 -0
- package/dist/src/generator/generators/mermaid.d.ts +24 -0
- package/dist/src/generator/generators/mermaid.js +140 -0
- package/dist/src/generator/generators/mermaid.test.d.ts +1 -0
- package/dist/src/generator/generators/mermaid.test.js +70 -0
- package/dist/src/generator/interface.d.ts +17 -0
- package/dist/src/generator/interface.js +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +17 -0
- package/dist/src/parser/base/lexer.d.ts +18 -0
- package/dist/src/parser/base/lexer.js +95 -0
- package/dist/src/parser/base/lexer.test.d.ts +1 -0
- package/dist/src/parser/base/lexer.test.js +53 -0
- package/dist/src/parser/base/parser.d.ts +14 -0
- package/dist/src/parser/base/parser.js +43 -0
- package/dist/src/parser/base/parser.test.d.ts +1 -0
- package/dist/src/parser/base/parser.test.js +90 -0
- package/dist/src/parser/index.d.ts +10 -0
- package/dist/src/parser/index.js +29 -0
- package/dist/src/parser/index.test.d.ts +1 -0
- package/dist/src/parser/index.test.js +23 -0
- package/dist/src/parser/interface.d.ts +8 -0
- package/dist/src/parser/interface.js +1 -0
- package/dist/src/parser/languages/mermaid/constants.d.ts +7 -0
- package/dist/src/parser/languages/mermaid/constants.js +20 -0
- package/dist/src/parser/languages/mermaid/index.d.ts +4 -0
- package/dist/src/parser/languages/mermaid/index.js +11 -0
- package/dist/src/parser/languages/mermaid/lexer.d.ts +14 -0
- package/dist/src/parser/languages/mermaid/lexer.js +152 -0
- package/dist/src/parser/languages/mermaid/lexer.test.d.ts +1 -0
- package/dist/src/parser/languages/mermaid/lexer.test.js +58 -0
- package/dist/src/parser/languages/mermaid/parser.d.ts +21 -0
- package/dist/src/parser/languages/mermaid/parser.js +340 -0
- package/dist/src/parser/languages/mermaid/parser.test.d.ts +1 -0
- package/dist/src/parser/languages/mermaid/parser.test.js +252 -0
- package/dist/src/parser/languages/mermaid/tokens.d.ts +9 -0
- package/dist/src/parser/languages/mermaid/tokens.js +1 -0
- package/dist/src/transformer/cleaners/prune-empty.d.ts +9 -0
- package/dist/src/transformer/cleaners/prune-empty.js +27 -0
- package/dist/src/transformer/cleaners/prune-empty.test.d.ts +1 -0
- package/dist/src/transformer/cleaners/prune-empty.test.js +69 -0
- package/dist/src/transformer/cleaners/prune-unused.d.ts +5 -0
- package/dist/src/transformer/cleaners/prune-unused.js +48 -0
- package/dist/src/transformer/cleaners/prune-unused.test.d.ts +1 -0
- package/dist/src/transformer/cleaners/prune-unused.test.js +71 -0
- package/dist/src/transformer/filters/focus.d.ts +13 -0
- package/dist/src/transformer/filters/focus.js +71 -0
- package/dist/src/transformer/filters/focus.test.d.ts +1 -0
- package/dist/src/transformer/filters/focus.test.js +50 -0
- package/dist/src/transformer/filters/remove.d.ts +12 -0
- package/dist/src/transformer/filters/remove.js +82 -0
- package/dist/src/transformer/filters/remove.test.d.ts +1 -0
- package/dist/src/transformer/filters/remove.test.js +38 -0
- package/dist/src/transformer/filters/resolve.d.ts +9 -0
- package/dist/src/transformer/filters/resolve.js +32 -0
- package/dist/src/transformer/filters/resolve.test.d.ts +1 -0
- package/dist/src/transformer/filters/resolve.test.js +48 -0
- package/dist/src/transformer/index.d.ts +10 -0
- package/dist/src/transformer/index.js +10 -0
- package/dist/src/transformer/lens.d.ts +12 -0
- package/dist/src/transformer/lens.js +58 -0
- package/dist/src/transformer/lens.test.d.ts +1 -0
- package/dist/src/transformer/lens.test.js +60 -0
- package/dist/src/transformer/orchestration/engine.d.ts +5 -0
- package/dist/src/transformer/orchestration/engine.js +24 -0
- package/dist/src/transformer/orchestration/engine.test.d.ts +1 -0
- package/dist/src/transformer/orchestration/engine.test.js +41 -0
- package/dist/src/transformer/orchestration/registry.d.ts +10 -0
- package/dist/src/transformer/orchestration/registry.js +27 -0
- package/dist/src/transformer/selector/matcher.d.ts +9 -0
- package/dist/src/transformer/selector/matcher.js +62 -0
- package/dist/src/transformer/selector/matcher.test.d.ts +1 -0
- package/dist/src/transformer/selector/matcher.test.js +53 -0
- package/dist/src/transformer/traverse/walker.d.ts +14 -0
- package/dist/src/transformer/traverse/walker.js +67 -0
- package/dist/src/transformer/traverse/walker.test.d.ts +1 -0
- package/dist/src/transformer/traverse/walker.test.js +48 -0
- package/dist/src/transformer/types.d.ts +47 -0
- package/dist/src/transformer/types.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
(function(m,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(m=typeof globalThis<"u"?globalThis:m||self,T(m.PolagramCore={}))})(this,(function(m){"use strict";var Rs=Object.defineProperty;var Cs=(m,T,F)=>T in m?Rs(m,T,{enumerable:!0,configurable:!0,writable:!0,value:F}):m[T]=F;var Ct=(m,T,F)=>Cs(m,typeof T!="symbol"?T+"":T,F);class T{constructor(t){this.input=t,this.readChar()}position=0;readPosition=0;ch="";line=1;column=0;getInput(){return this.input}readChar(){this.readPosition>=this.input.length?this.ch="":this.ch=this.input[this.readPosition],this.position=this.readPosition,this.readPosition+=1,this.column+=1,this.ch===`
|
|
2
|
+
`&&(this.line+=1,this.column=0)}peekChar(){return this.readPosition>=this.input.length?"":this.input[this.readPosition]}skipWhitespace(){for(;this.ch===" "||this.ch===" "||this.ch==="\r";)this.readChar()}readWhile(t){const n=this.position;for(;t(this.ch);)this.readChar();return this.input.slice(n,this.position)}isLetter(t){return"a"<=t&&t<="z"||"A"<=t&&t<="Z"||t==="_"?!0:t.charCodeAt(0)>127?!/[\s\d]/.test(t):!1}isDigit(t){return"0"<=t&&t<="9"}}class F extends T{constructor(t){super(t)}nextToken(){this.skipWhitespace();const t=this.position,n=this.column;let r;switch(this.ch){case":":r=this.newToken("COLON",this.ch,t,n);break;case",":r=this.newToken("COMMA",this.ch,t,n);break;case"+":r=this.newToken("PLUS",this.ch,t,n);break;case"-":if(this.isArrowStart()){const i=this.readArrow();return r=this.newToken("ARROW",i,t,n),r}else r=this.newToken("MINUS",this.ch,t,n);break;case'"':const o=this.readString();return r=this.newToken("STRING",o,t,n),r;case`
|
|
3
|
+
`:r=this.newToken("NEWLINE",this.ch,t,n);break;case"":r=this.newToken("EOF","",t,n);break;default:if(this.isLetter(this.ch)){const i=this.readIdentifier(),s=this.lookupIdent(i);return this.newToken(s,i,t,n)}else if(this.isDigit(this.ch)){const i=this.readNumber();return this.newToken("IDENTIFIER",i,t,n)}else r=this.newToken("UNKNOWN",this.ch,t,n)}return this.readChar(),r}newToken(t,n,r,o){return{type:t,literal:n,line:this.line,column:o,start:r,end:this.position>r?this.position:r+n.length}}readIdentifier(){const t=this.position;for(;this.isLetter(this.ch)||this.isDigit(this.ch);)this.readChar();return this.input.slice(t,this.position)}readNumber(){const t=this.position;for(;this.isDigit(this.ch);)this.readChar();return this.input.slice(t,this.position)}readString(){const t=this.position+1;for(this.readChar();this.ch!=='"'&&this.ch!==""&&this.ch!==`
|
|
4
|
+
`;)this.readChar();const n=this.input.slice(t,this.position);return this.ch,this.readChar(),n}isArrowStart(){if(this.ch!=="-")return!1;const t=this.peekChar();return t===">"||t==="-"||t===")"||t==="x"}readArrow(){if(this.input.slice(this.position,this.position+4)==="-->>")return this.readMulti(4),"-->>";const n=this.input.slice(this.position,this.position+3);if(n==="-->"||n==="--)"||n==="->>"||n==="--x")return this.readMulti(3),n;const r=this.input.slice(this.position,this.position+2);return r==="->"||r==="-)"||r==="-x"?(this.readMulti(2),r):"-"}readMulti(t){for(let n=0;n<t;n++)this.readChar()}lookupIdent(t){return{sequenceDiagram:"SEQUENCE_DIAGRAM",participant:"PARTICIPANT",actor:"ACTOR",loop:"LOOP",alt:"ALT",opt:"OPT",end:"END",else:"ELSE",note:"NOTE",left:"LEFT",right:"RIGHT",over:"OVER",of:"OF",as:"AS",title:"TITLE",activate:"ACTIVATE",deactivate:"DEACTIVATE",box:"BOX"}[t]||"IDENTIFIER"}}class jt{constructor(t){this.lexer=t,this.advance(),this.advance()}currToken;peekToken;advance(){this.currToken=this.peekToken,this.peekToken=this.lexer.nextToken()}curTokenIs(t){return this.currToken.type===t}peekTokenIs(t){return this.peekToken.type===t}expectPeek(t){return this.peekTokenIs(t)?(this.advance(),!0):!1}}const $e={"->":{type:"sync",style:{line:"solid",head:"open"}},"->>":{type:"sync",style:{line:"solid",head:"arrow"}},"-->":{type:"reply",style:{line:"dotted",head:"open"}},"-->>":{type:"reply",style:{line:"dotted",head:"arrow"}},"-)":{type:"async",style:{line:"solid",head:"async"}},"--)":{type:"async",style:{line:"dotted",head:"async"}},"-x":{type:"destroy",style:{line:"solid",head:"cross"}},"--x":{type:"destroy",style:{line:"dotted",head:"cross"}}},xt=Object.entries($e).reduce((e,[t,n])=>{const r=JSON.stringify({type:n.type,style:n.style});return e[r]=t,e},{});function Dt(e,t){const n=JSON.stringify({type:e,style:t});return xt[n]||"->>"}class Ft extends jt{currentGroup=null;idCounters={evt:0,frag:0,br:0,note:0,group:0};constructor(t){super(t)}parse(){const t={kind:"root",meta:{version:"1.0.0",source:"unknown"},participants:[],groups:[],events:[]};return t.events=this.parseBlock(t),t}parseBlock(t,n=[]){const r=[];for(;this.currToken.type!=="EOF";){const o=this.currToken.type;if(n.includes(o))return r;if(o==="NEWLINE"){this.advance();continue}if(o==="SEQUENCE_DIAGRAM"){t.meta.source="mermaid",this.advance();continue}if(o==="TITLE"){this.advance(),t.meta.title=this.readRestOfLine();continue}if(o==="BOX"){const i=this.parseGroup(t);r.push(...i);continue}if(o==="PARTICIPANT"||o==="ACTOR"){this.parseParticipant(t);continue}if(o==="LOOP"||o==="ALT"||o==="OPT"){r.push(this.parseFragment(t));continue}if(o==="NOTE"){r.push(this.parseNote(t));continue}if(o==="ACTIVATE"||o==="DEACTIVATE"){r.push(this.parseActivation(t));continue}if(this.isParticipantToken(this.currToken)){const i=this.parseMessage(t);if(i){r.push(i);continue}}this.advance()}return r}isParticipantToken(t){return t.type==="IDENTIFIER"||t.type==="STRING"}parseGroup(t){this.advance();const n=this.readRestOfLine().trim();let r=n,o;const i=n.split(/\s+/);if(i.length>0){const l=i[0];(l.startsWith("#")||["rgb","rgba","transparent","aqua","grey","gray","purple","red","blue","green"].includes(l.toLowerCase()))&&(o=l,r=i.slice(1).join(" "))}r||(r=`Group ${this.idCounters.group+1}`);const s={kind:"group",id:this.generateId("group"),name:r,type:"box",participantIds:[],style:o?{backgroundColor:o}:void 0};t.groups.push(s);const a=this.currentGroup;this.currentGroup=s;const u=this.parseBlock(t,["END"]);return this.currentGroup=a,this.currToken.type==="END"&&this.advance(),u}parseFragment(t){const n=this.currToken.type;let r="loop";n==="ALT"&&(r="alt"),n==="OPT"&&(r="opt"),this.advance();const o=this.readRestOfLine(),i=[],s=this.parseBlock(t,["END","ELSE"]);for(i.push({id:this.generateId("br"),condition:o,events:s});this.currToken.type==="ELSE";){this.advance();const a=this.readRestOfLine(),u=this.parseBlock(t,["END","ELSE"]);i.push({id:this.generateId("br"),condition:a,events:u})}return this.currToken.type==="END"&&this.advance(),{kind:"fragment",id:this.generateId("frag"),operator:r,branches:i}}parseParticipant(t){const n=this.currToken.type==="ACTOR";this.advance();let r="",o="";if(this.isParticipantToken(this.currToken)&&(r=this.currToken.literal,o=r,this.advance()),this.currToken.type==="AS"){this.advance();const s=this.readRestOfLine().trim();s&&(o=s)}const i=t.participants.find(s=>s.id===r);i?(o!==r&&(i.name=o),n&&(i.type="actor")):t.participants.push({id:r,name:o,type:n?"actor":"participant"}),this.currentGroup&&(this.currentGroup.participantIds.includes(r)||this.currentGroup.participantIds.push(r))}parseNote(t){this.advance();let n="over";this.currToken.type==="LEFT"?(n="left",this.advance()):this.currToken.type==="RIGHT"?(n="right",this.advance()):this.currToken.type==="OVER"&&(n="over",this.advance()),this.currToken.type==="OF"&&this.advance();const r=[];for(;this.isParticipantToken(this.currToken)&&(r.push(this.currToken.literal),this.ensureParticipant(t,this.currToken.literal),this.advance(),this.currToken.type==="COMMA");)this.advance();let o="";return this.currToken.type==="COLON"&&(this.advance(),o=this.readRestOfLine()),{kind:"note",id:this.generateId("note"),position:n,participantIds:r,text:o}}parseActivation(t){const n=this.currToken.type==="ACTIVATE"?"activate":"deactivate";this.advance();let r="";return this.isParticipantToken(this.currToken)&&(r=this.currToken.literal,this.ensureParticipant(t,r),this.advance()),{kind:"activation",participantId:r,action:n}}parseMessage(t){if(this.peekToken.type!=="ARROW")return null;const n=this.currToken.literal;if(this.ensureParticipant(t,n),this.advance(),this.currToken.type!=="ARROW")return null;const r=this.currToken.literal;this.advance();let o=!1,i=!1;if(this.currToken.type==="PLUS"&&(o=!0,this.advance()),this.currToken.type==="MINUS"&&(i=!0,this.advance()),!this.isParticipantToken(this.currToken))return null;const s=this.currToken.literal;this.ensureParticipant(t,s),this.advance();let a="";this.currToken.type==="COLON"&&(this.advance(),a=this.readRestOfLine());const{type:u,style:l}=this.resolveArrow(r);return{kind:"message",id:this.generateId("evt"),from:n,to:s,text:a,type:u,style:l,lifecycle:o||i?{activateTarget:o,deactivateSource:i}:void 0}}resolveArrow(t){const n=$e[t];return n||{type:"sync",style:{line:"solid",head:"arrow"}}}generateId(t){return this.idCounters[t]++,`${t}_${this.idCounters[t]}`}readRestOfLine(){if(this.currToken.type==="NEWLINE"||this.currToken.type==="EOF")return"";const t=this.currToken.start;let n=this.currToken.end;for(;this.currToken.type!=="NEWLINE"&&this.currToken.type!=="EOF";)n=this.currToken.end,this.advance();return this.lexer.getInput().slice(t,n)}ensureParticipant(t,n){t.participants.find(r=>r.id===n)||t.participants.push({id:n,name:n,type:"participant"})}}const Lt={parse:e=>{const t=new F(e);return new Ft(t).parse()}},le=class le{static register(t,n){this.parsers.set(t,n)}static getParser(t){const n=this.parsers.get(t);if(!n)throw new Error(`Parser for language '${t}' not found.`);return n}};Ct(le,"parsers",new Map),le.register("mermaid",Lt);let q=le;class Te{constructor(t){this.visitor=t}traverse(t){this.visitor.visitRoot(t)}dispatchEvent(t){switch(t.kind){case"message":this.visitor.visitMessage(t);break;case"fragment":this.visitor.visitFragment(t);break;case"note":this.visitor.visitNote(t);break;case"activation":this.visitor.visitActivation(t);break;case"divider":this.visitor.visitDivider(t);break;case"spacer":this.visitor.visitSpacer(t);break;case"ref":this.visitor.visitReference(t);break}}dispatchEvents(t){for(const n of t)this.dispatchEvent(n)}}class Ze{lines=[];indentLevel=0;traverser;constructor(){this.traverser=new Te(this)}generate(t){return this.lines=[],this.indentLevel=0,this.traverser.traverse(t),this.lines.join(`
|
|
5
|
+
`)}visitRoot(t){this.lines.push("sequenceDiagram"),this.indentLevel++,t.meta?.title&&this.add(`title ${t.meta.title}`);for(const n of t.participants)this.visitParticipant(n);this.traverser.dispatchEvents(t.events)}visitParticipant(t){const n=t.type==="actor"?"actor":"participant",r=t.name;t.id===t.name?this.add(`${n} ${t.id}`):this.add(`${n} ${t.id} as ${r}`)}visitParticipantGroup(t){let n="box";t.style?.backgroundColor&&(n+=` ${t.style.backgroundColor}`),t.name&&(n+=` ${t.name}`),this.add(n)}visitMessage(t){const n=t.from??"[*]",r=t.to??"[*]",o=Dt(t.type,t.style);let i="";t.lifecycle?.activateTarget&&(i+="+"),t.lifecycle?.deactivateSource&&(i+="-"),this.add(`${n}${o}${i}${r}: ${t.text}`)}visitFragment(t){if(t.branches.length===0)return;const n=t.branches[0],r=n.condition?` ${n.condition}`:"";this.add(`${t.operator}${r}`),this.indent(()=>{this.traverser.dispatchEvents(n.events)});for(let o=1;o<t.branches.length;o++){const i=t.branches[o],s=i.condition?` ${i.condition}`:"";this.add(`else${s}`),this.indent(()=>{this.traverser.dispatchEvents(i.events)})}this.add("end")}visitNote(t){const n=t.position;let r="";t.participantIds.length>0&&(r=t.participantIds.join(","),n!=="over"?r=` of ${r}`:r=` ${r}`),this.add(`note ${n}${r}: ${t.text}`)}visitActivation(t){this.add(`${t.action} ${t.participantId}`)}visitDivider(t){this.add(`%% == ${t.text||""} ==`)}visitSpacer(t){this.add(`...${t.text||""}...`)}visitReference(t){this.add(`%% ref: ${t.text}`)}add(t){const n=" ".repeat(this.indentLevel);this.lines.push(`${n}${t}`)}indent(t){this.indentLevel++,t(),this.indentLevel--}}class X{transform(t){const n=this.mapEvents(t.events);return{...t,events:n}}mapEvents(t){return t.flatMap(n=>this.visitEvent(n))}visitEvent(t){return t.kind==="fragment"?this.visitFragment(t):[t]}visitFragment(t){const n=t.branches.map(r=>this.visitBranch(r));return[{...t,branches:n}]}visitBranch(t){return{...t,events:this.mapEvents(t.events)}}}class Ie extends X{visitFragment(t){const n=super.visitFragment(t);if(n.length===0)return[];const r=n[0],o=r.branches.filter(i=>i.events.length>0);return o.length===0?[]:[{...r,branches:o}]}}class Ee{transform(t){const n=this.collectUsedParticipants(t.events),r=t.participants.filter(i=>n.has(i.id)),o=t.groups.map(i=>({...i,participantIds:i.participantIds.filter(s=>n.has(s))})).filter(i=>i.participantIds.length>0);return{...t,participants:r,groups:o}}collectUsedParticipants(t){const n=new Set;function r(o){for(const i of o)switch(i.kind){case"message":i.from&&n.add(i.from),i.to&&n.add(i.to);break;case"fragment":for(const s of i.branches)r(s.events);break;case"activation":n.add(i.participantId);break;case"note":i.participantIds.forEach(s=>n.add(s));break;case"ref":i.participantIds.forEach(s=>n.add(s));break}}return r(t),n}}class Y{matchBranch(t,n,r){return!(n.operator&&!(Array.isArray(n.operator)?n.operator:[n.operator]).includes(r)||n.condition&&(!t.condition||!this.matchText(t.condition,n.condition)))}matchParticipant(t,n){return!(n.id&&!this.matchText(t.id,n.id)||n.name&&!this.matchText(t.name,n.name)||n.stereotype&&t.stereotype&&!this.matchText(t.stereotype,n.stereotype))}matchMessage(t,n){return!(n.text&&!this.matchText(t.text,n.text)||n.from&&t.from&&!this.matchText(t.from,n.from)||n.to&&t.to&&!this.matchText(t.to,n.to))}matchGroup(t,n){return!(n.name&&t.name&&!this.matchText(t.name,n.name))}matchText(t,n){if(typeof n=="string")return t===n;if(n instanceof RegExp)return n.test(t);if(typeof n=="object"&&n.pattern){const r=n.flags||"";return new RegExp(n.pattern,r).test(t)}return!1}}class Se extends X{constructor(t){super(),this.layer=t}matcher=new Y;targetParticipantIds=new Set;transform(t){return this.resolveTargetParticipants(t),super.transform(t)}resolveTargetParticipants(t){this.targetParticipantIds.clear();const n=this.layer.selector;t.participants.forEach(r=>{this.matcher.matchParticipant(r,n)&&this.targetParticipantIds.add(r.id)})}visitEvent(t){if(t.kind==="message"){const n=t;if(!this.isRelatedToParticipant(n))return[]}if(t.kind==="note"&&!t.participantIds.some(o=>this.targetParticipantIds.has(o)))return[];if(t.kind==="activation"){const n=t;if(!this.targetParticipantIds.has(n.participantId))return[]}return super.visitEvent(t)}isRelatedToParticipant(t){return!!(t.from&&this.targetParticipantIds.has(t.from)||t.to&&this.targetParticipantIds.has(t.to))}}class Oe extends X{constructor(t){super(),this.layer=t}matcher=new Y;removedParticipantIds=new Set;transform(t){const n=this.layer.selector;return n.kind==="participant"&&(t.participants.forEach(r=>{this.matcher.matchParticipant(r,n)&&this.removedParticipantIds.add(r.id)}),t.participants=t.participants.filter(r=>!this.removedParticipantIds.has(r.id))),n.kind==="group"&&(t.groups=t.groups.filter(r=>!this.matcher.matchGroup(r,n))),super.transform(t)}visitEvent(t){const n=this.layer.selector;if(n.kind==="message"&&t.kind==="message"&&this.matcher.matchMessage(t,n))return[];if(n.kind==="participant"){if(t.kind==="message"){const r=t;if(this.isRelatedToRemovedParticipant(r))return[]}if(t.kind==="note"&&t.participantIds.some(i=>this.removedParticipantIds.has(i)))return[];if(t.kind==="activation"){const r=t;if(this.removedParticipantIds.has(r.participantId))return[]}}return super.visitEvent(t)}isRelatedToRemovedParticipant(t){return!!(t.from&&this.removedParticipantIds.has(t.from)||t.to&&this.removedParticipantIds.has(t.to))}}class Pe extends X{constructor(t){super(),this.layer=t}matcher=new Y;visitFragment(t){const n=t.branches.find(r=>this.matcher.matchBranch(r,this.layer.selector,t.operator));return n?this.mapEvents(n.events):super.visitFragment(t)}}class Mt{factories=new Map;constructor(){this.register("resolve",t=>new Pe(t)),this.register("focus",t=>new Se(t)),this.register("remove",t=>new Oe(t))}register(t,n){this.factories.set(t,n)}get(t){const n=this.factories.get(t.action);return n?n(t):null}}const Ne=new Mt;class H{transform(t,n){let r=t;for(const o of n){const i=Ne.get(o);i?r=i.transform(r):console.warn(`Unknown action: ${o.action}`)}return r=new Ie().transform(r),r=new Ee().transform(r),r}}function Ut(e){if(typeof e!="object"||e===null)return!1;const t=e;if(Reflect.has(t,"name")&&typeof t.name!="string"||!Array.isArray(t.layers))return!1;for(const n of t.layers)if(!Jt(n))return!1;return!0}function Jt(e){if(typeof e!="object"||e===null)return!1;const t=e;return!(typeof t.action!="string"||!["focus","remove","resolve"].includes(t.action)||typeof t.selector!="object"||t.selector===null||typeof t.selector.kind!="string")}function Vt(e,t){return new H().transform(e,t.layers)}class Gt{constructor(){}static init(t,n="mermaid"){const o=q.getParser(n).parse(t);return new Ae(o)}}class Ae{ast;layers=[];constructor(t){this.ast=t}focusParticipant(t){return this.layers.push({action:"focus",selector:this.normalizeParticipantSelector(t)}),this}removeParticipant(t){return this.layers.push({action:"remove",selector:this.normalizeParticipantSelector(t)}),this}removeMessage(t){return this.layers.push({action:"remove",selector:this.normalizeMessageSelector(t)}),this}removeGroup(t){return this.layers.push({action:"remove",selector:this.normalizeGroupSelector(t)}),this}resolveFragment(t){return this.layers.push({action:"resolve",selector:this.normalizeFragmentSelector(t)}),this}applyLens(t){return this.layers.push(...t.layers),this}toMermaid(){const n=new H().transform(this.ast,this.layers);return new Ze().generate(n)}toAST(){return new H().transform(this.ast,this.layers)}normalizeParticipantSelector(t){return this.isTextMatcher(t)?{kind:"participant",name:t}:{kind:"participant",...t}}normalizeMessageSelector(t){return this.isTextMatcher(t)?{kind:"message",text:t}:{kind:"message",...t}}normalizeGroupSelector(t){return this.isTextMatcher(t)?{kind:"group",name:t}:{kind:"group",...t}}normalizeFragmentSelector(t){return this.isTextMatcher(t)?{kind:"fragment",condition:t}:{kind:"fragment",...t}}isTextMatcher(t){return typeof t=="string"||t instanceof RegExp||typeof t=="object"&&t!==null&&"pattern"in t&&!("kind"in t)}}function c(e,t,n){function r(a,u){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:u,constr:s,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,u);const l=s.prototype,f=Object.keys(l);for(let p=0;p<f.length;p++){const d=f[p];d in a||(a[d]=l[d].bind(a))}}const o=n?.Parent??Object;class i extends o{}Object.defineProperty(i,"name",{value:e});function s(a){var u;const l=n?.Parent?new i:this;r(l,a),(u=l._zod).deferred??(u.deferred=[]);for(const f of l._zod.deferred)f();return l}return Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}class L extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Re extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const Ce={};function R(e){return Ce}function je(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,o])=>t.indexOf(+r)===-1).map(([r,o])=>o)}function fe(e,t){return typeof t=="bigint"?t.toString():t}function Q(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function he(e){return e==null}function pe(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function Wt(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let o=(r.split(".")[1]||"").length;if(o===0&&/\d?e-\d?/.test(r)){const u=r.match(/\d?e-(\d?)/);u?.[1]&&(o=Number.parseInt(u[1]))}const i=n>o?n:o,s=Number.parseInt(e.toFixed(i).replace(".","")),a=Number.parseInt(t.toFixed(i).replace(".",""));return s%a/10**i}const xe=Symbol("evaluating");function g(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==xe)return r===void 0&&(r=xe,r=n()),r},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}function C(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function j(...e){const t={};for(const n of e){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function De(e){return JSON.stringify(e)}function Bt(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Fe="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function V(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Kt=Q(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function G(e){if(V(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(V(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Le(e){return G(e)?{...e}:Array.isArray(e)?[...e]:e}const qt=new Set(["string","number","symbol"]);function M(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function N(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function h(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Xt(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const Yt={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Ht(e,t){const n=e._zod.def,r=j(e._zod.def,{get shape(){const o={};for(const i in t){if(!(i in n.shape))throw new Error(`Unrecognized key: "${i}"`);t[i]&&(o[i]=n.shape[i])}return C(this,"shape",o),o},checks:[]});return N(e,r)}function Qt(e,t){const n=e._zod.def,r=j(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const i in t){if(!(i in n.shape))throw new Error(`Unrecognized key: "${i}"`);t[i]&&delete o[i]}return C(this,"shape",o),o},checks:[]});return N(e,r)}function en(e,t){if(!G(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const o=j(e._zod.def,{get shape(){const i={...e._zod.def.shape,...t};return C(this,"shape",i),i},checks:[]});return N(e,o)}function tn(e,t){if(!G(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n={...e._zod.def,get shape(){const r={...e._zod.def.shape,...t};return C(this,"shape",r),r},checks:e._zod.def.checks};return N(e,n)}function nn(e,t){const n=j(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t._zod.def.shape};return C(this,"shape",r),r},get catchall(){return t._zod.def.catchall},checks:[]});return N(e,n)}function rn(e,t,n){const r=j(t._zod.def,{get shape(){const o=t._zod.def.shape,i={...o};if(n)for(const s in n){if(!(s in o))throw new Error(`Unrecognized key: "${s}"`);n[s]&&(i[s]=e?new e({type:"optional",innerType:o[s]}):o[s])}else for(const s in o)i[s]=e?new e({type:"optional",innerType:o[s]}):o[s];return C(this,"shape",i),i},checks:[]});return N(t,r)}function on(e,t,n){const r=j(t._zod.def,{get shape(){const o=t._zod.def.shape,i={...o};if(n)for(const s in n){if(!(s in i))throw new Error(`Unrecognized key: "${s}"`);n[s]&&(i[s]=new e({type:"nonoptional",innerType:o[s]}))}else for(const s in o)i[s]=new e({type:"nonoptional",innerType:o[s]});return C(this,"shape",i),i},checks:[]});return N(t,r)}function U(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Me(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function ee(e){return typeof e=="string"?e:e?.message}function x(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const o=ee(e.inst?._zod.def?.error?.(e))??ee(t?.error?.(e))??ee(n.customError?.(e))??ee(n.localeError?.(e))??"Invalid input";r.message=o}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function de(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function W(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}const Ue=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,fe,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Je=c("$ZodError",Ue),Ve=c("$ZodError",Ue,{Parent:Error});function sn(e,t=n=>n.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}function an(e,t=n=>n.message){const n={_errors:[]},r=o=>{for(const i of o.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(s=>r({issues:s}));else if(i.code==="invalid_key")r({issues:i.issues});else if(i.code==="invalid_element")r({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let s=n,a=0;for(;a<i.path.length;){const u=i.path[a];a===i.path.length-1?(s[u]=s[u]||{_errors:[]},s[u]._errors.push(t(i))):s[u]=s[u]||{_errors:[]},s=s[u],a++}}};return r(e),n}const me=e=>(t,n,r,o)=>{const i=r?Object.assign(r,{async:!1}):{async:!1},s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw new L;if(s.issues.length){const a=new(o?.Err??e)(s.issues.map(u=>x(u,i,R())));throw Fe(a,o?.callee),a}return s.value},ge=e=>async(t,n,r,o)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise&&(s=await s),s.issues.length){const a=new(o?.Err??e)(s.issues.map(u=>x(u,i,R())));throw Fe(a,o?.callee),a}return s.value},te=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new L;return i.issues.length?{success:!1,error:new(e??Je)(i.issues.map(s=>x(s,o,R())))}:{success:!0,data:i.value}},cn=te(Ve),ne=e=>async(t,n,r)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(s=>x(s,o,R())))}:{success:!0,data:i.value}},un=ne(Ve),ln=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return me(e)(t,n,o)},fn=e=>(t,n,r)=>me(e)(t,n,r),hn=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ge(e)(t,n,o)},pn=e=>async(t,n,r)=>ge(e)(t,n,r),dn=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return te(e)(t,n,o)},mn=e=>(t,n,r)=>te(e)(t,n,r),gn=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ne(e)(t,n,o)},vn=e=>async(t,n,r)=>ne(e)(t,n,r),_n=/^[cC][^\s-]{8,}$/,yn=/^[0-9a-z]+$/,kn=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,wn=/^[0-9a-vA-V]{20}$/,bn=/^[A-Za-z0-9]{27}$/,zn=/^[a-zA-Z0-9_-]{21}$/,$n=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Tn=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ge=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Zn=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,In="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function En(){return new RegExp(In,"u")}const Sn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,On=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Pn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Nn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,An=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,We=/^[A-Za-z0-9_-]*$/,Rn=/^\+(?:[0-9]){6,14}[0-9]$/,Be="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Cn=new RegExp(`^${Be}$`);function Ke(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function jn(e){return new RegExp(`^${Ke(e)}$`)}function xn(e){const t=Ke({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${Be}T(?:${r})$`)}const Dn=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},Fn=/^-?\d+$/,Ln=/^-?\d+(?:\.\d+)?/,Mn=/^[^A-Z]*$/,Un=/^[^a-z]*$/,$=c("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),qe={number:"number",bigint:"bigint",object:"date"},Xe=c("$ZodCheckLessThan",(e,t)=>{$.init(e,t);const n=qe[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,i=(t.inclusive?o.maximum:o.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<i&&(t.inclusive?o.maximum=t.value:o.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ye=c("$ZodCheckGreaterThan",(e,t)=>{$.init(e,t);const n=qe[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,i=(t.inclusive?o.minimum:o.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>i&&(t.inclusive?o.minimum=t.value:o.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Jn=c("$ZodCheckMultipleOf",(e,t)=>{$.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):Wt(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Vn=c("$ZodCheckNumberFormat",(e,t)=>{$.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,i]=Yt[t.format];e._zod.onattach.push(s=>{const a=s._zod.bag;a.format=t.format,a.minimum=o,a.maximum=i,n&&(a.pattern=Fn)}),e._zod.check=s=>{const a=s.value;if(n){if(!Number.isInteger(a)){s.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});return}if(!Number.isSafeInteger(a)){a>0?s.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):s.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort});return}}a<o&&s.issues.push({origin:"number",input:a,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),a>i&&s.issues.push({origin:"number",input:a,code:"too_big",maximum:i,inst:e})}}),Gn=c("$ZodCheckMaxLength",(e,t)=>{var n;$.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!he(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<o&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const o=r.value;if(o.length<=t.maximum)return;const s=de(o);r.issues.push({origin:s,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Wn=c("$ZodCheckMinLength",(e,t)=>{var n;$.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!he(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>o&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const o=r.value;if(o.length>=t.minimum)return;const s=de(o);r.issues.push({origin:s,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Bn=c("$ZodCheckLengthEquals",(e,t)=>{var n;$.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!he(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag;o.minimum=t.length,o.maximum=t.length,o.length=t.length}),e._zod.check=r=>{const o=r.value,i=o.length;if(i===t.length)return;const s=de(o),a=i>t.length;r.issues.push({origin:s,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),re=c("$ZodCheckStringFormat",(e,t)=>{var n,r;$.init(e,t),e._zod.onattach.push(o=>{const i=o._zod.bag;i.format=t.format,t.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Kn=c("$ZodCheckRegex",(e,t)=>{re.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),qn=c("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Mn),re.init(e,t)}),Xn=c("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Un),re.init(e,t)}),Yn=c("$ZodCheckIncludes",(e,t)=>{$.init(e,t);const n=M(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(o=>{const i=o._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),e._zod.check=o=>{o.value.includes(t.includes,t.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),Hn=c("$ZodCheckStartsWith",(e,t)=>{$.init(e,t);const n=new RegExp(`^${M(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),Qn=c("$ZodCheckEndsWith",(e,t)=>{$.init(e,t);const n=new RegExp(`.*${M(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),er=c("$ZodCheckOverwrite",(e,t)=>{$.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class tr{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const r=t.split(`
|
|
6
|
+
`).filter(s=>s),o=Math.min(...r.map(s=>s.length-s.trimStart().length)),i=r.map(s=>s.slice(o)).map(s=>" ".repeat(this.indent*2)+s);for(const s of i)this.content.push(s)}compile(){const t=Function,n=this?.args,o=[...(this?.content??[""]).map(i=>` ${i}`)];return new t(...n,o.join(`
|
|
7
|
+
`))}}const nr={major:4,minor:2,patch:1},k=c("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=nr;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const o of r)for(const i of o._zod.onattach)i(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const o=(s,a,u)=>{let l=U(s),f;for(const p of a){if(p._zod.def.when){if(!p._zod.def.when(s))continue}else if(l)continue;const d=s.issues.length,y=p._zod.check(s);if(y instanceof Promise&&u?.async===!1)throw new L;if(f||y instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await y,s.issues.length!==d&&(l||(l=U(s,d)))});else{if(s.issues.length===d)continue;l||(l=U(s,d))}}return f?f.then(()=>s):s},i=(s,a,u)=>{if(U(s))return s.aborted=!0,s;const l=o(a,r,u);if(l instanceof Promise){if(u.async===!1)throw new L;return l.then(f=>e._zod.parse(f,u))}return e._zod.parse(l,u)};e._zod.run=(s,a)=>{if(a.skipChecks)return e._zod.parse(s,a);if(a.direction==="backward"){const l=e._zod.parse({value:s.value,issues:[]},{...a,skipChecks:!0});return l instanceof Promise?l.then(f=>i(f,s,a)):i(l,s,a)}const u=e._zod.parse(s,a);if(u instanceof Promise){if(a.async===!1)throw new L;return u.then(l=>o(l,r,a))}return o(u,r,a)}}e["~standard"]={validate:o=>{try{const i=cn(e,o);return i.success?{value:i.data}:{issues:i.error?.issues}}catch{return un(e,o).then(s=>s.success?{value:s.data}:{issues:s.error?.issues})}},vendor:"zod",version:1}}),ve=c("$ZodString",(e,t)=>{k.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Dn(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),v=c("$ZodStringFormat",(e,t)=>{re.init(e,t),ve.init(e,t)}),rr=c("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Tn),v.init(e,t)}),or=c("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Ge(r))}else t.pattern??(t.pattern=Ge());v.init(e,t)}),ir=c("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Zn),v.init(e,t)}),sr=c("$ZodURL",(e,t)=>{v.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),o=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=o.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),ar=c("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=En()),v.init(e,t)}),cr=c("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=zn),v.init(e,t)}),ur=c("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=_n),v.init(e,t)}),lr=c("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=yn),v.init(e,t)}),fr=c("$ZodULID",(e,t)=>{t.pattern??(t.pattern=kn),v.init(e,t)}),hr=c("$ZodXID",(e,t)=>{t.pattern??(t.pattern=wn),v.init(e,t)}),pr=c("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=bn),v.init(e,t)}),dr=c("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=xn(t)),v.init(e,t)}),mr=c("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Cn),v.init(e,t)}),gr=c("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=jn(t)),v.init(e,t)}),vr=c("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=$n),v.init(e,t)}),_r=c("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Sn),v.init(e,t),e._zod.bag.format="ipv4"}),yr=c("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=On),v.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),kr=c("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Pn),v.init(e,t)}),wr=c("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Nn),v.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[o,i]=r;if(!i)throw new Error;const s=Number(i);if(`${s}`!==i)throw new Error;if(s<0||s>128)throw new Error;new URL(`http://[${o}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function He(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const br=c("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=An),v.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{He(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function zr(e){if(!We.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return He(n)}const $r=c("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=We),v.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{zr(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Tr=c("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Rn),v.init(e,t)});function Zr(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&o?.typ!=="JWT"||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}}const Ir=c("$ZodJWT",(e,t)=>{v.init(e,t),e._zod.check=n=>{Zr(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Qe=c("$ZodNumber",(e,t)=>{k.init(e,t),e._zod.pattern=e._zod.bag.pattern??Ln,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const o=n.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return n;const i=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...i?{received:i}:{}}),n}}),Er=c("$ZodNumberFormat",(e,t)=>{Vn.init(e,t),Qe.init(e,t)}),Sr=c("$ZodUnknown",(e,t)=>{k.init(e,t),e._zod.parse=n=>n}),Or=c("$ZodNever",(e,t)=>{k.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function et(e,t,n){e.issues.length&&t.issues.push(...Me(n,e.issues)),t.value[n]=e.value}const Pr=c("$ZodArray",(e,t)=>{k.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const i=[];for(let s=0;s<o.length;s++){const a=o[s],u=t.element._zod.run({value:a,issues:[]},r);u instanceof Promise?i.push(u.then(l=>et(l,n,s))):et(u,n,s)}return i.length?Promise.all(i).then(()=>n):n}});function oe(e,t,n,r){e.issues.length&&t.issues.push(...Me(n,e.issues)),e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function tt(e){const t=Object.keys(e.shape);for(const r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=Xt(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function nt(e,t,n,r,o,i){const s=[],a=o.keySet,u=o.catchall._zod,l=u.def.type;for(const f in t){if(a.has(f))continue;if(l==="never"){s.push(f);continue}const p=u.run({value:t[f],issues:[]},r);p instanceof Promise?e.push(p.then(d=>oe(d,n,f,t))):oe(p,n,f,t)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}const Nr=c("$ZodObject",(e,t)=>{if(k.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const u={...a};return Object.defineProperty(t,"shape",{value:u}),u}})}const r=Q(()=>tt(t));g(e._zod,"propValues",()=>{const a=t.shape,u={};for(const l in a){const f=a[l]._zod;if(f.values){u[l]??(u[l]=new Set);for(const p of f.values)u[l].add(p)}}return u});const o=V,i=t.catchall;let s;e._zod.parse=(a,u)=>{s??(s=r.value);const l=a.value;if(!o(l))return a.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),a;a.value={};const f=[],p=s.shape;for(const d of s.keys){const Z=p[d]._zod.run({value:l[d],issues:[]},u);Z instanceof Promise?f.push(Z.then(ze=>oe(ze,a,d,l))):oe(Z,a,d,l)}return i?nt(f,l,a,u,r.value,e):f.length?Promise.all(f).then(()=>a):a}}),Ar=c("$ZodObjectJIT",(e,t)=>{Nr.init(e,t);const n=e._zod.parse,r=Q(()=>tt(t)),o=d=>{const y=new tr(["shape","payload","ctx"]),Z=r.value,ze=P=>{const S=De(P);return`shape[${S}]._zod.run({ value: input[${S}], issues: [] }, ctx)`};y.write("const input = payload.value;");const Rt=Object.create(null);let Ns=0;for(const P of Z.keys)Rt[P]=`key_${Ns++}`;y.write("const newResult = {};");for(const P of Z.keys){const S=Rt[P],K=De(P);y.write(`const ${S} = ${ze(P)};`),y.write(`
|
|
8
|
+
if (${S}.issues.length) {
|
|
9
|
+
payload.issues = payload.issues.concat(${S}.issues.map(iss => ({
|
|
10
|
+
...iss,
|
|
11
|
+
path: iss.path ? [${K}, ...iss.path] : [${K}]
|
|
12
|
+
})));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if (${S}.value === undefined) {
|
|
17
|
+
if (${K} in input) {
|
|
18
|
+
newResult[${K}] = undefined;
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
newResult[${K}] = ${S}.value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
`)}y.write("payload.value = newResult;"),y.write("return payload;");const As=y.compile();return(P,S)=>As(d,P,S)};let i;const s=V,a=!Ce.jitless,l=a&&Kt.value,f=t.catchall;let p;e._zod.parse=(d,y)=>{p??(p=r.value);const Z=d.value;return s(Z)?a&&l&&y?.async===!1&&y.jitless!==!0?(i||(i=o(t.shape)),d=i(d,y),f?nt([],Z,d,y,p,e):d):n(d,y):(d.issues.push({expected:"object",code:"invalid_type",input:Z,inst:e}),d)}});function rt(e,t,n,r){for(const i of e)if(i.issues.length===0)return t.value=i.value,t;const o=e.filter(i=>!U(i));return o.length===1?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(i=>i.issues.map(s=>x(s,r,R())))}),t)}const ot=c("$ZodUnion",(e,t)=>{k.init(e,t),g(e._zod,"optin",()=>t.options.some(o=>o._zod.optin==="optional")?"optional":void 0),g(e._zod,"optout",()=>t.options.some(o=>o._zod.optout==="optional")?"optional":void 0),g(e._zod,"values",()=>{if(t.options.every(o=>o._zod.values))return new Set(t.options.flatMap(o=>Array.from(o._zod.values)))}),g(e._zod,"pattern",()=>{if(t.options.every(o=>o._zod.pattern)){const o=t.options.map(i=>i._zod.pattern);return new RegExp(`^(${o.map(i=>pe(i.source)).join("|")})$`)}});const n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(o,i)=>{if(n)return r(o,i);let s=!1;const a=[];for(const u of t.options){const l=u._zod.run({value:o.value,issues:[]},i);if(l instanceof Promise)a.push(l),s=!0;else{if(l.issues.length===0)return l;a.push(l)}}return s?Promise.all(a).then(u=>rt(u,o,e,i)):rt(a,o,e,i)}}),Rr=c("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,ot.init(e,t);const n=e._zod.parse;g(e._zod,"propValues",()=>{const o={};for(const i of t.options){const s=i._zod.propValues;if(!s||Object.keys(s).length===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(i)}"`);for(const[a,u]of Object.entries(s)){o[a]||(o[a]=new Set);for(const l of u)o[a].add(l)}}return o});const r=Q(()=>{const o=t.options,i=new Map;for(const s of o){const a=s._zod.propValues?.[t.discriminator];if(!a||a.size===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(s)}"`);for(const u of a){if(i.has(u))throw new Error(`Duplicate discriminator value "${String(u)}"`);i.set(u,s)}}return i});e._zod.parse=(o,i)=>{const s=o.value;if(!V(s))return o.issues.push({code:"invalid_type",expected:"object",input:s,inst:e}),o;const a=r.value.get(s?.[t.discriminator]);return a?a._zod.run(o,i):t.unionFallback?n(o,i):(o.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,input:s,path:[t.discriminator],inst:e}),o)}}),Cr=c("$ZodIntersection",(e,t)=>{k.init(e,t),e._zod.parse=(n,r)=>{const o=n.value,i=t.left._zod.run({value:o,issues:[]},r),s=t.right._zod.run({value:o,issues:[]},r);return i instanceof Promise||s instanceof Promise?Promise.all([i,s]).then(([u,l])=>it(n,u,l)):it(n,i,s)}});function _e(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(G(e)&&G(t)){const n=Object.keys(t),r=Object.keys(e).filter(i=>n.indexOf(i)!==-1),o={...e,...t};for(const i of r){const s=_e(e[i],t[i]);if(!s.valid)return{valid:!1,mergeErrorPath:[i,...s.mergeErrorPath]};o[i]=s.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=e[r],i=t[r],s=_e(o,i);if(!s.valid)return{valid:!1,mergeErrorPath:[r,...s.mergeErrorPath]};n.push(s.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function it(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),U(e))return e;const r=_e(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const jr=c("$ZodEnum",(e,t)=>{k.init(e,t);const n=je(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(o=>qt.has(typeof o)).map(o=>typeof o=="string"?M(o):o.toString()).join("|")})$`),e._zod.parse=(o,i)=>{const s=o.value;return r.has(s)||o.issues.push({code:"invalid_value",values:n,input:s,inst:e}),o}}),xr=c("$ZodLiteral",(e,t)=>{if(k.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(r=>typeof r=="string"?M(r):r?M(r.toString()):String(r)).join("|")})$`),e._zod.parse=(r,o)=>{const i=r.value;return n.has(i)||r.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),r}}),Dr=c("$ZodTransform",(e,t)=>{k.init(e,t),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Re(e.constructor.name);const o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(s=>(n.value=s,n));if(o instanceof Promise)throw new L;return n.value=o,n}});function st(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const Fr=c("$ZodOptional",(e,t)=>{k.init(e,t),e._zod.optin="optional",e._zod.optout="optional",g(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),g(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${pe(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>st(i,n.value)):st(o,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,r)}}),Lr=c("$ZodNullable",(e,t)=>{k.init(e,t),g(e._zod,"optin",()=>t.innerType._zod.optin),g(e._zod,"optout",()=>t.innerType._zod.optout),g(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${pe(n.source)}|null)$`):void 0}),g(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),Mr=c("$ZodDefault",(e,t)=>{k.init(e,t),e._zod.optin="optional",g(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>at(i,t)):at(o,t)}});function at(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Ur=c("$ZodPrefault",(e,t)=>{k.init(e,t),e._zod.optin="optional",g(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),Jr=c("$ZodNonOptional",(e,t)=>{k.init(e,t),g(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>ct(i,e)):ct(o,e)}});function ct(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Vr=c("$ZodCatch",(e,t)=>{k.init(e,t),g(e._zod,"optin",()=>t.innerType._zod.optin),g(e._zod,"optout",()=>t.innerType._zod.optout),g(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(s=>x(s,r,R()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=t.catchValue({...n,error:{issues:o.issues.map(i=>x(i,r,R()))},input:n.value}),n.issues=[]),n)}}),Gr=c("$ZodPipe",(e,t)=>{k.init(e,t),g(e._zod,"values",()=>t.in._zod.values),g(e._zod,"optin",()=>t.in._zod.optin),g(e._zod,"optout",()=>t.out._zod.optout),g(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const i=t.out._zod.run(n,r);return i instanceof Promise?i.then(s=>ie(s,t.in,r)):ie(i,t.in,r)}const o=t.in._zod.run(n,r);return o instanceof Promise?o.then(i=>ie(i,t.out,r)):ie(o,t.out,r)}});function ie(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Wr=c("$ZodReadonly",(e,t)=>{k.init(e,t),g(e._zod,"propValues",()=>t.innerType._zod.propValues),g(e._zod,"values",()=>t.innerType._zod.values),g(e._zod,"optin",()=>t.innerType?._zod?.optin),g(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(ut):ut(o)}});function ut(e){return e.value=Object.freeze(e.value),e}const Br=c("$ZodCustom",(e,t)=>{$.init(e,t),k.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(i=>lt(i,n,r,e));lt(o,n,r,e)}});function lt(e,t,n,r){if(!e){const o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),t.issues.push(W(o))}}var ft;class Kr{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const r=n[0];if(this._map.set(t,r),r&&typeof r=="object"&&"id"in r){if(this._idmap.has(r.id))throw new Error(`ID ${r.id} already exists in the registry`);this._idmap.set(r.id,t)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const o={...r,...this._map.get(t)};return Object.keys(o).length?o:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function qr(){return new Kr}(ft=globalThis).__zod_globalRegistry??(ft.__zod_globalRegistry=qr());const B=globalThis.__zod_globalRegistry;function Xr(e,t){return new e({type:"string",...h(t)})}function Yr(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...h(t)})}function ht(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...h(t)})}function Hr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...h(t)})}function Qr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...h(t)})}function eo(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...h(t)})}function to(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...h(t)})}function no(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...h(t)})}function ro(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...h(t)})}function oo(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...h(t)})}function io(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...h(t)})}function so(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...h(t)})}function ao(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...h(t)})}function co(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...h(t)})}function uo(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...h(t)})}function lo(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...h(t)})}function fo(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...h(t)})}function ho(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...h(t)})}function po(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...h(t)})}function mo(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...h(t)})}function go(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...h(t)})}function vo(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...h(t)})}function _o(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...h(t)})}function yo(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...h(t)})}function ko(e,t){return new e({type:"string",format:"date",check:"string_format",...h(t)})}function wo(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...h(t)})}function bo(e,t){return new e({type:"string",format:"duration",check:"string_format",...h(t)})}function zo(e,t){return new e({type:"number",checks:[],...h(t)})}function $o(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...h(t)})}function To(e){return new e({type:"unknown"})}function Zo(e,t){return new e({type:"never",...h(t)})}function pt(e,t){return new Xe({check:"less_than",...h(t),value:e,inclusive:!1})}function ye(e,t){return new Xe({check:"less_than",...h(t),value:e,inclusive:!0})}function dt(e,t){return new Ye({check:"greater_than",...h(t),value:e,inclusive:!1})}function ke(e,t){return new Ye({check:"greater_than",...h(t),value:e,inclusive:!0})}function mt(e,t){return new Jn({check:"multiple_of",...h(t),value:e})}function gt(e,t){return new Gn({check:"max_length",...h(t),maximum:e})}function se(e,t){return new Wn({check:"min_length",...h(t),minimum:e})}function vt(e,t){return new Bn({check:"length_equals",...h(t),length:e})}function Io(e,t){return new Kn({check:"string_format",format:"regex",...h(t),pattern:e})}function Eo(e){return new qn({check:"string_format",format:"lowercase",...h(e)})}function So(e){return new Xn({check:"string_format",format:"uppercase",...h(e)})}function Oo(e,t){return new Yn({check:"string_format",format:"includes",...h(t),includes:e})}function Po(e,t){return new Hn({check:"string_format",format:"starts_with",...h(t),prefix:e})}function No(e,t){return new Qn({check:"string_format",format:"ends_with",...h(t),suffix:e})}function J(e){return new er({check:"overwrite",tx:e})}function Ao(e){return J(t=>t.normalize(e))}function Ro(){return J(e=>e.trim())}function Co(){return J(e=>e.toLowerCase())}function jo(){return J(e=>e.toUpperCase())}function xo(){return J(e=>Bt(e))}function Do(e,t,n){return new e({type:"array",element:t,...h(n)})}function Fo(e,t,n){return new e({type:"custom",check:"custom",fn:t,...h(n)})}function Lo(e){const t=Mo(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(W(r,n.value,t._zod.def));else{const o=r;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),o.continue??(o.continue=!t._zod.def.abort),n.issues.push(W(o))}},e(n.value,n)));return t}function Mo(e,t){const n=new $({check:"custom",...h(t)});return n._zod.check=e,n}function _t(e){let t=e?.target??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??B,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function b(e,t,n={path:[],schemaPath:[]}){var r;const o=e._zod.def,i=t.seen.get(e);if(i)return i.count++,n.schemaPath.includes(e)&&(i.cycle=n.path),i.schema;const s={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,s);const a=e._zod.toJSONSchema?.();if(a)s.schema=a;else{const f={...n,schemaPath:[...n.schemaPath,e],path:n.path},p=e._zod.parent;if(p)s.ref=p,b(p,t,f),t.seen.get(p).isParent=!0;else if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,s.schema,f);else{const d=s.schema,y=t.processors[o.type];if(!y)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);y(e,t,d,f)}}const u=t.metadataRegistry.get(e);return u&&Object.assign(s.schema,u),t.io==="input"&&z(e)&&(delete s.schema.examples,delete s.schema.default),t.io==="input"&&s.schema._prefault&&((r=s.schema).default??(r.default=s.schema._prefault)),delete s.schema._prefault,t.seen.get(e).schema}function yt(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=i=>{const s=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const f=e.external.registry.get(i[0])?.id,p=e.external.uri??(y=>y);if(f)return{ref:p(f)};const d=i[1].defId??i[1].schema.id??`schema${e.counter++}`;return i[1].defId=d,{defId:d,ref:`${p("__shared")}#/${s}/${d}`}}if(i[1]===n)return{ref:"#"};const u=`#/${s}/`,l=i[1].schema.id??`__schema${e.counter++}`;return{defId:l,ref:u+l}},o=i=>{if(i[1].schema.$ref)return;const s=i[1],{ref:a,defId:u}=r(i);s.def={...s.schema},u&&(s.defId=u);const l=s.schema;for(const f in l)delete l[f];l.$ref=a};if(e.cycles==="throw")for(const i of e.seen.entries()){const s=i[1];if(s.cycle)throw new Error(`Cycle detected: #/${s.cycle?.join("/")}/<root>
|
|
25
|
+
|
|
26
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const i of e.seen.entries()){const s=i[1];if(t===i[0]){o(i);continue}if(e.external){const u=e.external.registry.get(i[0])?.id;if(t!==i[0]&&u){o(i);continue}}if(e.metadataRegistry.get(i[0])?.id){o(i);continue}if(s.cycle){o(i);continue}if(s.count>1&&e.reused==="ref"){o(i);continue}}}function kt(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=s=>{const a=e.seen.get(s),u=a.def??a.schema,l={...u};if(a.ref===null)return;const f=a.ref;if(a.ref=null,f){r(f);const p=e.seen.get(f).schema;p.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(u.allOf=u.allOf??[],u.allOf.push(p)):(Object.assign(u,p),Object.assign(u,l))}a.isParent||e.override({zodSchema:s,jsonSchema:u,path:a.path??[]})};for(const s of[...e.seen.entries()].reverse())r(s[0]);const o={};if(e.target==="draft-2020-12"?o.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?o.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?o.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const s=e.external.registry.get(t)?.id;if(!s)throw new Error("Schema is missing an `id` property");o.$id=e.external.uri(s)}Object.assign(o,n.def??n.schema);const i=e.external?.defs??{};for(const s of e.seen.entries()){const a=s[1];a.def&&a.defId&&(i[a.defId]=a.def)}e.external||Object.keys(i).length>0&&(e.target==="draft-2020-12"?o.$defs=i:o.definitions=i);try{const s=JSON.parse(JSON.stringify(o));return Object.defineProperty(s,"~standard",{value:{...t["~standard"],jsonSchema:{input:ae(t,"input"),output:ae(t,"output")}},enumerable:!1,writable:!1}),s}catch{throw new Error("Error converting schema to JSON.")}}function z(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return z(r.element,n);if(r.type==="set")return z(r.valueType,n);if(r.type==="lazy")return z(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return z(r.innerType,n);if(r.type==="intersection")return z(r.left,n)||z(r.right,n);if(r.type==="record"||r.type==="map")return z(r.keyType,n)||z(r.valueType,n);if(r.type==="pipe")return z(r.in,n)||z(r.out,n);if(r.type==="object"){for(const o in r.shape)if(z(r.shape[o],n))return!0;return!1}if(r.type==="union"){for(const o of r.options)if(z(o,n))return!0;return!1}if(r.type==="tuple"){for(const o of r.items)if(z(o,n))return!0;return!!(r.rest&&z(r.rest,n))}return!1}const Uo=(e,t={})=>n=>{const r=_t({...n,processors:t});return b(e,r),yt(r,e),kt(r,e)},ae=(e,t)=>n=>{const{libraryOptions:r,target:o}=n??{},i=_t({...r??{},target:o,io:t,processors:{}});return b(e,i),yt(i,e),kt(i,e)},Jo={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Vo=(e,t,n,r)=>{const o=n;o.type="string";const{minimum:i,maximum:s,format:a,patterns:u,contentEncoding:l}=e._zod.bag;if(typeof i=="number"&&(o.minLength=i),typeof s=="number"&&(o.maxLength=s),a&&(o.format=Jo[a]??a,o.format===""&&delete o.format),l&&(o.contentEncoding=l),u&&u.size>0){const f=[...u];f.length===1?o.pattern=f[0].source:f.length>1&&(o.allOf=[...f.map(p=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:p.source}))])}},Go=(e,t,n,r)=>{const o=n,{minimum:i,maximum:s,format:a,multipleOf:u,exclusiveMaximum:l,exclusiveMinimum:f}=e._zod.bag;typeof a=="string"&&a.includes("int")?o.type="integer":o.type="number",typeof f=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(o.minimum=f,o.exclusiveMinimum=!0):o.exclusiveMinimum=f),typeof i=="number"&&(o.minimum=i,typeof f=="number"&&t.target!=="draft-04"&&(f>=i?delete o.minimum:delete o.exclusiveMinimum)),typeof l=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(o.maximum=l,o.exclusiveMaximum=!0):o.exclusiveMaximum=l),typeof s=="number"&&(o.maximum=s,typeof l=="number"&&t.target!=="draft-04"&&(l<=s?delete o.maximum:delete o.exclusiveMaximum)),typeof u=="number"&&(o.multipleOf=u)},Wo=(e,t,n,r)=>{n.not={}},Bo=(e,t,n,r)=>{},Ko=(e,t,n,r)=>{const o=e._zod.def,i=je(o.entries);i.every(s=>typeof s=="number")&&(n.type="number"),i.every(s=>typeof s=="string")&&(n.type="string"),n.enum=i},qo=(e,t,n,r)=>{const o=e._zod.def,i=[];for(const s of o.values)if(s===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof s=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");i.push(Number(s))}else i.push(s);if(i.length!==0)if(i.length===1){const s=i[0];n.type=s===null?"null":typeof s,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[s]:n.const=s}else i.every(s=>typeof s=="number")&&(n.type="number"),i.every(s=>typeof s=="string")&&(n.type="string"),i.every(s=>typeof s=="boolean")&&(n.type="boolean"),i.every(s=>s===null)&&(n.type="null"),n.enum=i},Xo=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},Yo=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},Ho=(e,t,n,r)=>{const o=n,i=e._zod.def,{minimum:s,maximum:a}=e._zod.bag;typeof s=="number"&&(o.minItems=s),typeof a=="number"&&(o.maxItems=a),o.type="array",o.items=b(i.element,t,{...r,path:[...r.path,"items"]})},Qo=(e,t,n,r)=>{const o=n,i=e._zod.def;o.type="object",o.properties={};const s=i.shape;for(const l in s)o.properties[l]=b(s[l],t,{...r,path:[...r.path,"properties",l]});const a=new Set(Object.keys(s)),u=new Set([...a].filter(l=>{const f=i.shape[l]._zod;return t.io==="input"?f.optin===void 0:f.optout===void 0}));u.size>0&&(o.required=Array.from(u)),i.catchall?._zod.def.type==="never"?o.additionalProperties=!1:i.catchall?i.catchall&&(o.additionalProperties=b(i.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(o.additionalProperties=!1)},ei=(e,t,n,r)=>{const o=e._zod.def,i=o.inclusive===!1,s=o.options.map((a,u)=>b(a,t,{...r,path:[...r.path,i?"oneOf":"anyOf",u]}));i?n.oneOf=s:n.anyOf=s},ti=(e,t,n,r)=>{const o=e._zod.def,i=b(o.left,t,{...r,path:[...r.path,"allOf",0]}),s=b(o.right,t,{...r,path:[...r.path,"allOf",1]}),a=l=>"allOf"in l&&Object.keys(l).length===1,u=[...a(i)?i.allOf:[i],...a(s)?s.allOf:[s]];n.allOf=u},ni=(e,t,n,r)=>{const o=e._zod.def,i=b(o.innerType,t,r),s=t.seen.get(e);t.target==="openapi-3.0"?(s.ref=o.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]},ri=(e,t,n,r)=>{const o=e._zod.def;b(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType},oi=(e,t,n,r)=>{const o=e._zod.def;b(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType,n.default=JSON.parse(JSON.stringify(o.defaultValue))},ii=(e,t,n,r)=>{const o=e._zod.def;b(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(o.defaultValue)))},si=(e,t,n,r)=>{const o=e._zod.def;b(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType;let s;try{s=o.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=s},ai=(e,t,n,r)=>{const o=e._zod.def,i=t.io==="input"?o.in._zod.def.type==="transform"?o.out:o.in:o.out;b(i,t,r);const s=t.seen.get(e);s.ref=i},ci=(e,t,n,r)=>{const o=e._zod.def;b(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType,n.readOnly=!0},ui=(e,t,n,r)=>{const o=e._zod.def;b(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType},li=c("ZodISODateTime",(e,t)=>{dr.init(e,t),_.init(e,t)});function fi(e){return yo(li,e)}const hi=c("ZodISODate",(e,t)=>{mr.init(e,t),_.init(e,t)});function pi(e){return ko(hi,e)}const di=c("ZodISOTime",(e,t)=>{gr.init(e,t),_.init(e,t)});function mi(e){return wo(di,e)}const gi=c("ZodISODuration",(e,t)=>{vr.init(e,t),_.init(e,t)});function vi(e){return bo(gi,e)}const I=c("ZodError",(e,t)=>{Je.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>an(e,n)},flatten:{value:n=>sn(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,fe,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,fe,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),_i=me(I),yi=ge(I),ki=te(I),wi=ne(I),bi=ln(I),zi=fn(I),$i=hn(I),Ti=pn(I),Zi=dn(I),Ii=mn(I),Ei=gn(I),Si=vn(I),w=c("ZodType",(e,t)=>(k.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:ae(e,"input"),output:ae(e,"output")}}),e.toJSONSchema=Uo(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(j(t,{checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]})),e.clone=(n,r)=>N(e,n,r),e.brand=()=>e,e.register=((n,r)=>(n.add(e,r),e)),e.parse=(n,r)=>_i(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>ki(e,n,r),e.parseAsync=async(n,r)=>yi(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>wi(e,n,r),e.spa=e.safeParseAsync,e.encode=(n,r)=>bi(e,n,r),e.decode=(n,r)=>zi(e,n,r),e.encodeAsync=async(n,r)=>$i(e,n,r),e.decodeAsync=async(n,r)=>Ti(e,n,r),e.safeEncode=(n,r)=>Zi(e,n,r),e.safeDecode=(n,r)=>Ii(e,n,r),e.safeEncodeAsync=async(n,r)=>Ei(e,n,r),e.safeDecodeAsync=async(n,r)=>Si(e,n,r),e.refine=(n,r)=>e.check(ks(n,r)),e.superRefine=n=>e.check(ws(n)),e.overwrite=n=>e.check(J(n)),e.optional=()=>St(e),e.nullable=()=>Ot(e),e.nullish=()=>St(Ot(e)),e.nonoptional=n=>ps(e,n),e.array=()=>D(e),e.or=n=>we([e,n]),e.and=n=>os(e,n),e.transform=n=>Nt(e,as(n)),e.default=n=>ls(e,n),e.prefault=n=>hs(e,n),e.catch=n=>ms(e,n),e.pipe=n=>Nt(e,n),e.readonly=()=>_s(e),e.describe=n=>{const r=e.clone();return B.add(r,{description:n}),r},Object.defineProperty(e,"description",{get(){return B.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return B.get(e);const r=e.clone();return B.add(r,n[0]),r},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),wt=c("_ZodString",(e,t)=>{ve.init(e,t),w.init(e,t),e._zod.processJSONSchema=(r,o,i)=>Vo(e,r,o);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...r)=>e.check(Io(...r)),e.includes=(...r)=>e.check(Oo(...r)),e.startsWith=(...r)=>e.check(Po(...r)),e.endsWith=(...r)=>e.check(No(...r)),e.min=(...r)=>e.check(se(...r)),e.max=(...r)=>e.check(gt(...r)),e.length=(...r)=>e.check(vt(...r)),e.nonempty=(...r)=>e.check(se(1,...r)),e.lowercase=r=>e.check(Eo(r)),e.uppercase=r=>e.check(So(r)),e.trim=()=>e.check(Ro()),e.normalize=(...r)=>e.check(Ao(...r)),e.toLowerCase=()=>e.check(Co()),e.toUpperCase=()=>e.check(jo()),e.slugify=()=>e.check(xo())}),Oi=c("ZodString",(e,t)=>{ve.init(e,t),wt.init(e,t),e.email=n=>e.check(Yr(Pi,n)),e.url=n=>e.check(no(Ni,n)),e.jwt=n=>e.check(_o(Bi,n)),e.emoji=n=>e.check(ro(Ai,n)),e.guid=n=>e.check(ht(bt,n)),e.uuid=n=>e.check(Hr(ce,n)),e.uuidv4=n=>e.check(Qr(ce,n)),e.uuidv6=n=>e.check(eo(ce,n)),e.uuidv7=n=>e.check(to(ce,n)),e.nanoid=n=>e.check(oo(Ri,n)),e.guid=n=>e.check(ht(bt,n)),e.cuid=n=>e.check(io(Ci,n)),e.cuid2=n=>e.check(so(ji,n)),e.ulid=n=>e.check(ao(xi,n)),e.base64=n=>e.check(mo(Vi,n)),e.base64url=n=>e.check(go(Gi,n)),e.xid=n=>e.check(co(Di,n)),e.ksuid=n=>e.check(uo(Fi,n)),e.ipv4=n=>e.check(lo(Li,n)),e.ipv6=n=>e.check(fo(Mi,n)),e.cidrv4=n=>e.check(ho(Ui,n)),e.cidrv6=n=>e.check(po(Ji,n)),e.e164=n=>e.check(vo(Wi,n)),e.datetime=n=>e.check(fi(n)),e.date=n=>e.check(pi(n)),e.time=n=>e.check(mi(n)),e.duration=n=>e.check(vi(n))});function E(e){return Xr(Oi,e)}const _=c("ZodStringFormat",(e,t)=>{v.init(e,t),wt.init(e,t)}),Pi=c("ZodEmail",(e,t)=>{ir.init(e,t),_.init(e,t)}),bt=c("ZodGUID",(e,t)=>{rr.init(e,t),_.init(e,t)}),ce=c("ZodUUID",(e,t)=>{or.init(e,t),_.init(e,t)}),Ni=c("ZodURL",(e,t)=>{sr.init(e,t),_.init(e,t)}),Ai=c("ZodEmoji",(e,t)=>{ar.init(e,t),_.init(e,t)}),Ri=c("ZodNanoID",(e,t)=>{cr.init(e,t),_.init(e,t)}),Ci=c("ZodCUID",(e,t)=>{ur.init(e,t),_.init(e,t)}),ji=c("ZodCUID2",(e,t)=>{lr.init(e,t),_.init(e,t)}),xi=c("ZodULID",(e,t)=>{fr.init(e,t),_.init(e,t)}),Di=c("ZodXID",(e,t)=>{hr.init(e,t),_.init(e,t)}),Fi=c("ZodKSUID",(e,t)=>{pr.init(e,t),_.init(e,t)}),Li=c("ZodIPv4",(e,t)=>{_r.init(e,t),_.init(e,t)}),Mi=c("ZodIPv6",(e,t)=>{yr.init(e,t),_.init(e,t)}),Ui=c("ZodCIDRv4",(e,t)=>{kr.init(e,t),_.init(e,t)}),Ji=c("ZodCIDRv6",(e,t)=>{wr.init(e,t),_.init(e,t)}),Vi=c("ZodBase64",(e,t)=>{br.init(e,t),_.init(e,t)}),Gi=c("ZodBase64URL",(e,t)=>{$r.init(e,t),_.init(e,t)}),Wi=c("ZodE164",(e,t)=>{Tr.init(e,t),_.init(e,t)}),Bi=c("ZodJWT",(e,t)=>{Ir.init(e,t),_.init(e,t)}),zt=c("ZodNumber",(e,t)=>{Qe.init(e,t),w.init(e,t),e._zod.processJSONSchema=(r,o,i)=>Go(e,r,o),e.gt=(r,o)=>e.check(dt(r,o)),e.gte=(r,o)=>e.check(ke(r,o)),e.min=(r,o)=>e.check(ke(r,o)),e.lt=(r,o)=>e.check(pt(r,o)),e.lte=(r,o)=>e.check(ye(r,o)),e.max=(r,o)=>e.check(ye(r,o)),e.int=r=>e.check($t(r)),e.safe=r=>e.check($t(r)),e.positive=r=>e.check(dt(0,r)),e.nonnegative=r=>e.check(ke(0,r)),e.negative=r=>e.check(pt(0,r)),e.nonpositive=r=>e.check(ye(0,r)),e.multipleOf=(r,o)=>e.check(mt(r,o)),e.step=(r,o)=>e.check(mt(r,o)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Ki(e){return zo(zt,e)}const qi=c("ZodNumberFormat",(e,t)=>{Er.init(e,t),zt.init(e,t)});function $t(e){return $o(qi,e)}const Xi=c("ZodUnknown",(e,t)=>{Sr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Bo()});function Tt(){return To(Xi)}const Yi=c("ZodNever",(e,t)=>{Or.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Wo(e,n,r)});function Hi(e){return Zo(Yi,e)}const Qi=c("ZodArray",(e,t)=>{Pr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ho(e,n,r,o),e.element=t.element,e.min=(n,r)=>e.check(se(n,r)),e.nonempty=n=>e.check(se(1,n)),e.max=(n,r)=>e.check(gt(n,r)),e.length=(n,r)=>e.check(vt(n,r)),e.unwrap=()=>e.element});function D(e,t){return Do(Qi,e,t)}const es=c("ZodObject",(e,t)=>{Ar.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Qo(e,n,r,o),g(e,"shape",()=>t.shape),e.keyof=()=>It(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Tt()}),e.loose=()=>e.clone({...e._zod.def,catchall:Tt()}),e.strict=()=>e.clone({...e._zod.def,catchall:Hi()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>en(e,n),e.safeExtend=n=>tn(e,n),e.merge=n=>nn(e,n),e.pick=n=>Ht(e,n),e.omit=n=>Qt(e,n),e.partial=(...n)=>rn(Et,e,n[0]),e.required=(...n)=>on(Pt,e,n[0])});function O(e,t){const n={type:"object",shape:e??{},...h(t)};return new es(n)}const Zt=c("ZodUnion",(e,t)=>{ot.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ei(e,n,r,o),e.options=t.options});function we(e,t){return new Zt({type:"union",options:e,...h(t)})}const ts=c("ZodDiscriminatedUnion",(e,t)=>{Zt.init(e,t),Rr.init(e,t)});function ns(e,t,n){return new ts({type:"union",options:t,discriminator:e,...h(n)})}const rs=c("ZodIntersection",(e,t)=>{Cr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ti(e,n,r,o)});function os(e,t){return new rs({type:"intersection",left:e,right:t})}const be=c("ZodEnum",(e,t)=>{jr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(r,o,i)=>Ko(e,r,o),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,o)=>{const i={};for(const s of r)if(n.has(s))i[s]=t.entries[s];else throw new Error(`Key ${s} not found in enum`);return new be({...t,checks:[],...h(o),entries:i})},e.exclude=(r,o)=>{const i={...t.entries};for(const s of r)if(n.has(s))delete i[s];else throw new Error(`Key ${s} not found in enum`);return new be({...t,checks:[],...h(o),entries:i})}});function It(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new be({type:"enum",entries:n,...h(t)})}const is=c("ZodLiteral",(e,t)=>{xr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>qo(e,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function ue(e,t){return new is({type:"literal",values:Array.isArray(e)?e:[e],...h(t)})}const ss=c("ZodTransform",(e,t)=>{Dr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Yo(e,n),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Re(e.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(W(i,n.value,t));else{const s=i;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=n.value),s.inst??(s.inst=e),n.issues.push(W(s))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(i=>(n.value=i,n)):(n.value=o,n)}});function as(e){return new ss({type:"transform",transform:e})}const Et=c("ZodOptional",(e,t)=>{Fr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ui(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function St(e){return new Et({type:"optional",innerType:e})}const cs=c("ZodNullable",(e,t)=>{Lr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ni(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Ot(e){return new cs({type:"nullable",innerType:e})}const us=c("ZodDefault",(e,t)=>{Mr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>oi(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function ls(e,t){return new us({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Le(t)}})}const fs=c("ZodPrefault",(e,t)=>{Ur.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ii(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function hs(e,t){return new fs({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():Le(t)}})}const Pt=c("ZodNonOptional",(e,t)=>{Jr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ri(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function ps(e,t){return new Pt({type:"nonoptional",innerType:e,...h(t)})}const ds=c("ZodCatch",(e,t)=>{Vr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>si(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function ms(e,t){return new ds({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const gs=c("ZodPipe",(e,t)=>{Gr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ai(e,n,r,o),e.in=t.in,e.out=t.out});function Nt(e,t){return new gs({type:"pipe",in:e,out:t})}const vs=c("ZodReadonly",(e,t)=>{Wr.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ci(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function _s(e){return new vs({type:"readonly",innerType:e})}const ys=c("ZodCustom",(e,t)=>{Br.init(e,t),w.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Xo(e,n)});function ks(e,t={}){return Fo(ys,e,t)}function ws(e){return Lo(e)}const A=we([E(),O({pattern:E(),flags:E().optional()})]),bs=O({kind:ue("fragment"),condition:A.optional(),operator:we([E(),D(E())]).optional()}),zs=O({kind:ue("participant"),name:A.optional(),id:A.optional(),stereotype:A.optional()}),$s=O({kind:ue("message"),text:A.optional(),from:A.optional(),to:A.optional()}),Ts=O({kind:ue("group"),name:A.optional()}),Zs=ns("kind",[bs,zs,$s,Ts]),Is=It(["focus","remove","resolve"]),Es=O({action:Is,selector:Zs}),Ss=O({name:E(),suffix:E().optional(),layers:D(Es)}),Os=O({input:D(E()),outputDir:E(),ignore:D(E()).optional(),lenses:D(Ss)}),At=O({version:Ki(),targets:D(Os)});function Ps(e){const t=At.safeParse(e);if(!t.success){const n=t.error.issues.map(r=>`[${r.path.join(".")}]: ${r.message}`).join(`
|
|
27
|
+
`);throw new Error(`Invalid Polagram Configuration:
|
|
28
|
+
${n}`)}return t.data}m.FocusFilter=Se,m.Matcher=Y,m.MermaidGeneratorVisitor=Ze,m.ParserFactory=q,m.Polagram=Gt,m.PolagramBuilder=Ae,m.PolagramConfigSchema=At,m.RemoveFilter=Oe,m.ResolveFilter=Pe,m.StructureCleaner=Ie,m.TransformationEngine=H,m.Traverser=Te,m.UnusedCleaner=Ee,m.applyLens=Vt,m.transformerRegistry=Ne,m.validateConfig=Ps,m.validateLens=Ut,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { PolagramRoot } from './ast';
|
|
2
|
+
import { FragmentSelector, GroupSelector, Lens, MessageSelector, ParticipantSelector, TextMatcher } from './transformer/types';
|
|
3
|
+
/**
|
|
4
|
+
* Polagram Fluent API
|
|
5
|
+
*
|
|
6
|
+
* Provides a high-level, chainable interface for transformations.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const result = Polagram.init(mermaidCode)
|
|
10
|
+
* .focusParticipant('PaymentService')
|
|
11
|
+
* .removeParticipant('DebugLogger')
|
|
12
|
+
* .toMermaid();
|
|
13
|
+
*/
|
|
14
|
+
export declare class Polagram {
|
|
15
|
+
private constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Initialize a new Polagram transformation pipeline.
|
|
18
|
+
* @param code Source diagram code
|
|
19
|
+
* @param format Input format (currently only 'mermaid' is supported)
|
|
20
|
+
*/
|
|
21
|
+
static init(code: string, format?: 'mermaid'): PolagramBuilder;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Builder class for chaining transformations.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PolagramBuilder {
|
|
27
|
+
private ast;
|
|
28
|
+
private layers;
|
|
29
|
+
constructor(ast: PolagramRoot);
|
|
30
|
+
/**
|
|
31
|
+
* Focus on specific participants.
|
|
32
|
+
* Keeps only interactions involving the matched participants.
|
|
33
|
+
* @param selector Name (string/RegExp) or detailed ParticipantSelector
|
|
34
|
+
*/
|
|
35
|
+
focusParticipant(selector: TextMatcher | Partial<ParticipantSelector>): this;
|
|
36
|
+
/**
|
|
37
|
+
* Remove specific participants and their interactions.
|
|
38
|
+
* @param selector Name (string/RegExp) or detailed ParticipantSelector
|
|
39
|
+
*/
|
|
40
|
+
removeParticipant(selector: TextMatcher | Partial<ParticipantSelector>): this;
|
|
41
|
+
/**
|
|
42
|
+
* Remove specific messages.
|
|
43
|
+
* @param selector Message text (string/RegExp) or detailed MessageSelector
|
|
44
|
+
*/
|
|
45
|
+
removeMessage(selector: TextMatcher | Partial<MessageSelector>): this;
|
|
46
|
+
/**
|
|
47
|
+
* Remove specific groups (visual boxes).
|
|
48
|
+
* @param selector Group name (string/RegExp) or detailed GroupSelector
|
|
49
|
+
*/
|
|
50
|
+
removeGroup(selector: TextMatcher | Partial<GroupSelector>): this;
|
|
51
|
+
/**
|
|
52
|
+
* Resolve (unwrap) specific fragments like 'alt', 'opt', 'loop'.
|
|
53
|
+
* Promotes the content of the matched branch and removes the wrapper.
|
|
54
|
+
* @param selector Condition text (string/RegExp) or detailed FragmentSelector
|
|
55
|
+
*/
|
|
56
|
+
resolveFragment(selector: TextMatcher | Partial<FragmentSelector>): this;
|
|
57
|
+
/**
|
|
58
|
+
* Apply a Lens (a named set of transformation layers).
|
|
59
|
+
* @param lens Lens object containing layers
|
|
60
|
+
*/
|
|
61
|
+
applyLens(lens: Lens): this;
|
|
62
|
+
/**
|
|
63
|
+
* Generate Mermaid code from the transformed AST.
|
|
64
|
+
*/
|
|
65
|
+
toMermaid(): string;
|
|
66
|
+
/**
|
|
67
|
+
* Get the transformed AST (for advanced use cases).
|
|
68
|
+
*/
|
|
69
|
+
toAST(): PolagramRoot;
|
|
70
|
+
private normalizeParticipantSelector;
|
|
71
|
+
private normalizeMessageSelector;
|
|
72
|
+
private normalizeGroupSelector;
|
|
73
|
+
private normalizeFragmentSelector;
|
|
74
|
+
private isTextMatcher;
|
|
75
|
+
}
|
package/dist/src/api.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { MermaidGeneratorVisitor } from './generator/generators/mermaid';
|
|
2
|
+
import { ParserFactory } from './parser';
|
|
3
|
+
import { TransformationEngine } from './transformer/orchestration/engine';
|
|
4
|
+
/**
|
|
5
|
+
* Polagram Fluent API
|
|
6
|
+
*
|
|
7
|
+
* Provides a high-level, chainable interface for transformations.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = Polagram.init(mermaidCode)
|
|
11
|
+
* .focusParticipant('PaymentService')
|
|
12
|
+
* .removeParticipant('DebugLogger')
|
|
13
|
+
* .toMermaid();
|
|
14
|
+
*/
|
|
15
|
+
export class Polagram {
|
|
16
|
+
constructor() { }
|
|
17
|
+
/**
|
|
18
|
+
* Initialize a new Polagram transformation pipeline.
|
|
19
|
+
* @param code Source diagram code
|
|
20
|
+
* @param format Input format (currently only 'mermaid' is supported)
|
|
21
|
+
*/
|
|
22
|
+
static init(code, format = 'mermaid') {
|
|
23
|
+
const parser = ParserFactory.getParser(format);
|
|
24
|
+
const ast = parser.parse(code);
|
|
25
|
+
return new PolagramBuilder(ast);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Builder class for chaining transformations.
|
|
30
|
+
*/
|
|
31
|
+
export class PolagramBuilder {
|
|
32
|
+
constructor(ast) {
|
|
33
|
+
Object.defineProperty(this, "ast", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "layers", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: []
|
|
44
|
+
});
|
|
45
|
+
this.ast = ast;
|
|
46
|
+
}
|
|
47
|
+
// -- Entity Filtering --
|
|
48
|
+
/**
|
|
49
|
+
* Focus on specific participants.
|
|
50
|
+
* Keeps only interactions involving the matched participants.
|
|
51
|
+
* @param selector Name (string/RegExp) or detailed ParticipantSelector
|
|
52
|
+
*/
|
|
53
|
+
focusParticipant(selector) {
|
|
54
|
+
this.layers.push({
|
|
55
|
+
action: 'focus',
|
|
56
|
+
selector: this.normalizeParticipantSelector(selector)
|
|
57
|
+
});
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Remove specific participants and their interactions.
|
|
62
|
+
* @param selector Name (string/RegExp) or detailed ParticipantSelector
|
|
63
|
+
*/
|
|
64
|
+
removeParticipant(selector) {
|
|
65
|
+
this.layers.push({
|
|
66
|
+
action: 'remove',
|
|
67
|
+
selector: this.normalizeParticipantSelector(selector)
|
|
68
|
+
});
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
// -- Message Filtering --
|
|
72
|
+
/**
|
|
73
|
+
* Remove specific messages.
|
|
74
|
+
* @param selector Message text (string/RegExp) or detailed MessageSelector
|
|
75
|
+
*/
|
|
76
|
+
removeMessage(selector) {
|
|
77
|
+
this.layers.push({
|
|
78
|
+
action: 'remove',
|
|
79
|
+
selector: this.normalizeMessageSelector(selector)
|
|
80
|
+
});
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
// -- Group Filtering --
|
|
84
|
+
/**
|
|
85
|
+
* Remove specific groups (visual boxes).
|
|
86
|
+
* @param selector Group name (string/RegExp) or detailed GroupSelector
|
|
87
|
+
*/
|
|
88
|
+
removeGroup(selector) {
|
|
89
|
+
this.layers.push({
|
|
90
|
+
action: 'remove',
|
|
91
|
+
selector: this.normalizeGroupSelector(selector)
|
|
92
|
+
});
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
// -- Structural Resolution --
|
|
96
|
+
/**
|
|
97
|
+
* Resolve (unwrap) specific fragments like 'alt', 'opt', 'loop'.
|
|
98
|
+
* Promotes the content of the matched branch and removes the wrapper.
|
|
99
|
+
* @param selector Condition text (string/RegExp) or detailed FragmentSelector
|
|
100
|
+
*/
|
|
101
|
+
resolveFragment(selector) {
|
|
102
|
+
this.layers.push({
|
|
103
|
+
action: 'resolve',
|
|
104
|
+
selector: this.normalizeFragmentSelector(selector)
|
|
105
|
+
});
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Apply a Lens (a named set of transformation layers).
|
|
110
|
+
* @param lens Lens object containing layers
|
|
111
|
+
*/
|
|
112
|
+
applyLens(lens) {
|
|
113
|
+
this.layers.push(...lens.layers);
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Generate Mermaid code from the transformed AST.
|
|
118
|
+
*/
|
|
119
|
+
toMermaid() {
|
|
120
|
+
const engine = new TransformationEngine();
|
|
121
|
+
const transformedAst = engine.transform(this.ast, this.layers);
|
|
122
|
+
const generator = new MermaidGeneratorVisitor();
|
|
123
|
+
return generator.generate(transformedAst);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get the transformed AST (for advanced use cases).
|
|
127
|
+
*/
|
|
128
|
+
toAST() {
|
|
129
|
+
const engine = new TransformationEngine();
|
|
130
|
+
return engine.transform(this.ast, this.layers);
|
|
131
|
+
}
|
|
132
|
+
// -- Helper Methods --
|
|
133
|
+
normalizeParticipantSelector(selector) {
|
|
134
|
+
if (this.isTextMatcher(selector)) {
|
|
135
|
+
return { kind: 'participant', name: selector };
|
|
136
|
+
}
|
|
137
|
+
return { kind: 'participant', ...selector };
|
|
138
|
+
}
|
|
139
|
+
normalizeMessageSelector(selector) {
|
|
140
|
+
if (this.isTextMatcher(selector)) {
|
|
141
|
+
return { kind: 'message', text: selector };
|
|
142
|
+
}
|
|
143
|
+
return { kind: 'message', ...selector };
|
|
144
|
+
}
|
|
145
|
+
normalizeGroupSelector(selector) {
|
|
146
|
+
if (this.isTextMatcher(selector)) {
|
|
147
|
+
return { kind: 'group', name: selector };
|
|
148
|
+
}
|
|
149
|
+
return { kind: 'group', ...selector };
|
|
150
|
+
}
|
|
151
|
+
normalizeFragmentSelector(selector) {
|
|
152
|
+
if (this.isTextMatcher(selector)) {
|
|
153
|
+
return { kind: 'fragment', condition: selector };
|
|
154
|
+
}
|
|
155
|
+
return { kind: 'fragment', ...selector };
|
|
156
|
+
}
|
|
157
|
+
isTextMatcher(val) {
|
|
158
|
+
return typeof val === 'string' || val instanceof RegExp || (typeof val === 'object' && val !== null && 'pattern' in val && !('kind' in val));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// packages/core/test/complex_ast_example.test.ts
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
describe('Polagram AST Definition', () => {
|
|
4
|
+
it('should support a complex lossless scenario', () => {
|
|
5
|
+
// This "Rosetta Stone" object attempts to use ALL new features
|
|
6
|
+
// to prove they are correctly typed and coexist.
|
|
7
|
+
const complexAst = {
|
|
8
|
+
kind: 'root',
|
|
9
|
+
meta: {
|
|
10
|
+
version: '1.0.0',
|
|
11
|
+
source: 'plantuml',
|
|
12
|
+
title: 'Complex Order System',
|
|
13
|
+
theme: {
|
|
14
|
+
participantPadding: '10'
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
groups: [
|
|
18
|
+
{
|
|
19
|
+
kind: 'group',
|
|
20
|
+
id: 'g_1',
|
|
21
|
+
name: 'AWS Cloud',
|
|
22
|
+
type: 'box',
|
|
23
|
+
participantIds: ['p_db', 'p_sqs'],
|
|
24
|
+
style: { backgroundColor: '#f0f0f0' }
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
participants: [
|
|
28
|
+
{
|
|
29
|
+
id: 'p_user',
|
|
30
|
+
name: 'User',
|
|
31
|
+
type: 'actor'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'p_api',
|
|
35
|
+
name: 'API Gateway',
|
|
36
|
+
type: 'control'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'p_sqs',
|
|
40
|
+
name: 'Order Queue',
|
|
41
|
+
type: 'queue'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'p_db',
|
|
45
|
+
name: 'DynamoDB',
|
|
46
|
+
type: 'database'
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
events: [
|
|
50
|
+
// 1. Found message (from unknown)
|
|
51
|
+
{
|
|
52
|
+
kind: 'message',
|
|
53
|
+
id: 'm_1',
|
|
54
|
+
from: null,
|
|
55
|
+
to: 'p_user',
|
|
56
|
+
text: 'User lands on page',
|
|
57
|
+
type: 'sync',
|
|
58
|
+
style: { line: 'solid', head: 'arrow' }
|
|
59
|
+
},
|
|
60
|
+
// 2. Activation independent of message
|
|
61
|
+
{
|
|
62
|
+
kind: 'activation',
|
|
63
|
+
participantId: 'p_user',
|
|
64
|
+
action: 'activate'
|
|
65
|
+
},
|
|
66
|
+
// 3. Message with lifecycle
|
|
67
|
+
{
|
|
68
|
+
kind: 'message',
|
|
69
|
+
id: 'm_2',
|
|
70
|
+
from: 'p_user',
|
|
71
|
+
to: 'p_api',
|
|
72
|
+
text: 'POST /order',
|
|
73
|
+
type: 'sync',
|
|
74
|
+
style: { line: 'solid', head: 'arrow' },
|
|
75
|
+
lifecycle: { activateTarget: true }
|
|
76
|
+
},
|
|
77
|
+
// 4. Create message (Lifecycle)
|
|
78
|
+
{
|
|
79
|
+
kind: 'message',
|
|
80
|
+
id: 'm_3',
|
|
81
|
+
from: 'p_api',
|
|
82
|
+
to: 'p_sqs',
|
|
83
|
+
text: 'new OrderMessage()',
|
|
84
|
+
type: 'create', // Explicit create
|
|
85
|
+
style: { line: 'dotted', head: 'arrow' }
|
|
86
|
+
},
|
|
87
|
+
// 5. Visual Divider
|
|
88
|
+
{
|
|
89
|
+
kind: 'divider',
|
|
90
|
+
id: 'd_1',
|
|
91
|
+
text: 'Async Processing'
|
|
92
|
+
},
|
|
93
|
+
// 6. Visual Spacer (Delay)
|
|
94
|
+
{
|
|
95
|
+
kind: 'spacer',
|
|
96
|
+
id: 's_1',
|
|
97
|
+
text: '... 5 seconds later ...'
|
|
98
|
+
},
|
|
99
|
+
// 7. Grouping/Fragment (Loop)
|
|
100
|
+
{
|
|
101
|
+
kind: 'fragment',
|
|
102
|
+
id: 'f_1',
|
|
103
|
+
operator: 'loop',
|
|
104
|
+
branches: [
|
|
105
|
+
{
|
|
106
|
+
id: 'b_1',
|
|
107
|
+
condition: 'Every 1s',
|
|
108
|
+
events: [
|
|
109
|
+
{
|
|
110
|
+
kind: 'message',
|
|
111
|
+
id: 'm_poll',
|
|
112
|
+
from: 'p_db',
|
|
113
|
+
to: 'p_sqs',
|
|
114
|
+
text: 'Check items',
|
|
115
|
+
type: 'sync',
|
|
116
|
+
style: { line: 'solid', head: 'arrow' }
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
// 8. Reference (Ref)
|
|
123
|
+
{
|
|
124
|
+
kind: 'ref',
|
|
125
|
+
id: 'r_1',
|
|
126
|
+
text: 'Payment Processing',
|
|
127
|
+
link: 'payment.mermaid',
|
|
128
|
+
participantIds: ['p_api', 'p_db']
|
|
129
|
+
},
|
|
130
|
+
// 9. Destroy (Lifecycle)
|
|
131
|
+
{
|
|
132
|
+
kind: 'message',
|
|
133
|
+
id: 'm_del',
|
|
134
|
+
from: 'p_api',
|
|
135
|
+
to: 'p_sqs',
|
|
136
|
+
text: 'delete',
|
|
137
|
+
type: 'destroy',
|
|
138
|
+
style: { line: 'solid', head: 'cross' } // X marker
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
};
|
|
142
|
+
expect(complexAst).toBeTruthy();
|
|
143
|
+
expect(complexAst.participants.length).toBe(4);
|
|
144
|
+
expect(complexAst.events.length).toBe(9);
|
|
145
|
+
});
|
|
146
|
+
});
|