"use strict";var Qe=Object.create;var te=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var et=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var ot=(e,t)=>{for(var o in t)te(e,o,{get:t[o],enumerable:!0})},ke=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Xe(t))!tt.call(e,r)&&r!==o&&te(e,r,{get:()=>t[r],enumerable:!(n=Ge(t,r))||n.enumerable});return e};var P=(e,t,o)=>(o=e!=null?Qe(et(e)):{},ke(t||!e||!e.__esModule?te(o,"default",{value:e,enumerable:!0}):o,e)),nt=e=>ke(te({},"__esModule",{value:!0}),e);var ao={};ot(ao,{AbstractAction:()=>Q,ActionsFactory:()=>de,Config:()=>J,Documentation:()=>fe,InputValidationError:()=>L,Integration:()=>me,OutputValidationError:()=>V,attachSockets:()=>ve,createSimpleConfig:()=>Re});module.exports=nt(ao);var Ce=require("zod"),oe=(e,t)=>{try{return typeof e.parse(t)}catch{return}},Y=e=>"coerce"in e._def&&typeof e._def.coerce=="boolean"?e._def.coerce:!1,rt=e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),D=e=>e.charAt(0).toLowerCase()+e.slice(1),y=(...e)=>e.flatMap(t=>t.split(/[^A-Z0-9]/gi)).flatMap(t=>t.replaceAll(/[A-Z]+/g,o=>`/${o}`).split("/")).map(rt).join(""),Me=e=>e instanceof Error?e:new Error(String(e)),ge=e=>e instanceof Ce.z.ZodError?e.issues.map(({path:t,message:o})=>(t.length?[t.join("/")]:[]).concat(o).join(": ")).join("; "):e.message;var ne=e=>({join:async t=>e.join(t),leave:async t=>typeof t=="string"?e.leave(t):Promise.all(t.map(o=>e.leave(o))).then(()=>{})});var je=P(require("node:assert/strict"),1);var re=({sockets:e,...t})=>e.map(o=>({id:o.id,handshake:o.handshake,rooms:Array.from(o.rooms),getData:()=>o.data||{},emit:U({subject:o,...t}),...ne(o)}));function U({subject:e,emission:t,timeout:o}){return async(n,...r)=>{let i="id"in e;(0,je.default)(n in t,new Error(`Unsupported event ${n}`));let{schema:s,ack:a}=t[n],d=s.parse(r);if(!a)return e.emit(String(n),...d)||!0;let u=await e.timeout(o).emitWithAck(String(n),...d);return(i?a:a.array()).parse(u)}}var xe=({subject:e,...t})=>o=>({getClients:async()=>re({sockets:await e.in(o).fetchSockets(),...t}),broadcast:U({...t,subject:e.to(o)})});var De={onConnection:({client:{id:e,getData:t},logger:o})=>o.debug("Client connected",{...t(),id:e}),onDisconnect:({client:{id:e,getData:t},logger:o})=>o.debug("Client disconnected",{...t(),id:e}),onAnyIncoming:({event:e,client:{id:t,getData:o},logger:n})=>n.debug(`${e} from ${t}`,o()),onAnyOutgoing:({event:e,logger:t,payload:o})=>t.debug(`Sending ${e}`,o),onStartup:({logger:e})=>e.debug("Ready"),onError:({logger:e,event:t,error:o})=>e.error(t?`${t} handling error`:"Error",o)};var ie="/",B=e=>{let t=e.trim();return t.startsWith("/")?t:`/${t}`};var $=require("ansis"),E=require("ramda"),it=(0,$.italic)("for River".padEnd(20)),st="Proudly supports non-binary community.".padStart(77),at=` ,, MMM"""AMV \u1FEF7MM .M"""bgd \u1FEF7MM mm M\u2019 AMV MM ,MI "Y MM MM \u1FEF AMV ,pW"Wq. ,M""bMM \u1FEFMMb. ,pW"Wq. ,p6"bo MM ,MP\u2019 .gP"Ya mmMMmm ,pP"Ybd AMV 6W\u2019 \u1FEFWb ,AP MM \u1FEFYMMNq. 6W\u2019 \u1FEFWb 6M\u2019 OO MM ;Y ,M\u2019 Yb MM 8I \u1FEF" AMV , 8M M8 8MI MM . \u1FEFMM 8M M8 8M MM;Mm 8M"""""" MM \u1FEFYMMMa. AMV ,M YA. ,A9 \u1FEFMb MM Mb dM YA. ,A9 YM. , MM \u1FEFMb. YM. , MM L. I8 AMVmmmmMM \u1FEFYbmd9\u2019 \u1FEFWbmd"MML. P"Ybmmd" \u1FEFYbmd9\u2019 YMbmd\u2019 .JMML. YA. \u1FEFMbmmd\u2019 \u1FEFMbmo M9mmmP\u2019 ${it}${st} `,ct=(0,E.cond)([[(0,E.gt)(4),(0,E.always)((0,$.hex)("#FCF434"))],[(0,E.gt)(5),(0,E.always)((0,$.hex)("#FFF"))],[(0,E.gt)(8),(0,E.always)((0,$.hex)("#9C59D1"))],[E.T,(0,E.always)((0,$.hex)("#2C2C2C"))]]),Ie=()=>at.split(` `).map((e,t)=>ct(t)(e)).join(` `);var ve=async({io:e,actions:t,target:o,config:{namespaces:n,timeout:r,startupLogo:i=!0},logger:s=console})=>{for(let a in n){let d=e.of(B(a)),{emission:u,hooks:A,metadata:x}=n[a],{onConnection:z,onDisconnect:S,onAnyIncoming:T,onAnyOutgoing:Z,onStartup:H,onError:N}={...De,...A},b={emission:u,timeout:r},v={logger:s,withRooms:xe({subject:e,metadata:x,...b}),all:{getClients:async()=>re({sockets:await d.fetchSockets(),metadata:x,...b}),getRooms:()=>Array.from(d.adapter.rooms.keys()),broadcast:U({subject:e,...b})}};d.on("connection",async g=>{let l=U({subject:g,...b}),O=U({subject:g.broadcast,...b}),M={emit:l,broadcast:O,id:g.id,handshake:g.handshake,getRequest:()=>g.request,isConnected:()=>g.connected,getRooms:()=>Array.from(g.rooms),getData:()=>g.data||{},setData:h=>{x.parse(h),g.data=h},...ne(g)},k={...v,client:M,withRooms:xe({subject:g,metadata:x,...b})};await z(k),g.onAny((h,..._)=>T({event:h,payload:_,...k})),g.onAnyOutgoing((h,..._)=>Z({event:h,payload:_,...k}));for(let h of t)if(h.getNamespace()===a){let _=h.getEvent();g.on(_,async(...Oe)=>{try{return await h.execute({params:Oe,...k})}catch(Je){return N({...k,event:_,payload:Oe,error:Me(Je)})}})}g.on("disconnect",()=>S(k))}),await H(v)}return(i?console.log:()=>{})(Ie()),s.debug("Running","v2.1.1 (CJS)"),s.info("Listening",o.address()),e.attach(o)};var we=require("zod");var J=class e{timeout;startupLogo;security;namespaces;constructor({timeout:t=2e3,startupLogo:o=!0,namespaces:n={},security:r=[]}={}){this.timeout=t,this.startupLogo=o,this.namespaces=n,this.security=r}addNamespace({path:t=ie,emission:o={},metadata:n=we.z.object({}),hooks:r={},examples:i={},security:s=[]}){let{namespaces:a,...d}=this,u={emission:o,examples:i,hooks:r,metadata:n,security:s};return new e({...d,namespaces:{...a,[t]:u}})}},Re=({startupLogo:e,timeout:t,security:o,emission:n,examples:r,hooks:i,metadata:s}={})=>new J({startupLogo:e,timeout:t,security:o}).addNamespace({emission:n,examples:r,metadata:s,hooks:i});var ce=require("ramda"),W=require("zod");var se=class extends Error{name="IOSchemaError"},L=class extends se{constructor(o){super(ge(o));this.originalError=o}name="InputValidationError"},V=class extends se{constructor(o){super(ge(o));this.originalError=o}name="OutputValidationError"};var Q=class{},ae=class extends Q{#t;#r;#o;#e;#n;#i;constructor(t){super(),this.#t=t.event,this.#r=t.ns||ie,this.#o=t.input,this.#e="output"in t?t.output:void 0,this.#n=[],this.#i=t.handler}getEvent(){return this.#t}getNamespace(){return this.#r}getSchema(t){return t==="input"?this.#o:this.#e}#s(t){let o=this.#e?(0,ce.init)(t):t;try{return this.#o.parse(o)}catch(n){throw n instanceof W.z.ZodError?new L(n):n}}#a(t){if(this.#e)try{return W.z.function(this.#e,W.z.void()).parse((0,ce.last)(t),{path:[Math.max(0,t.length-1)]})}catch(o){throw o instanceof W.z.ZodError?new L(o):o}}#c(t){if(this.#e)try{return this.#e.parse(t)}catch(o){throw o instanceof W.z.ZodError?new V(o):o}}async execute({params:t,logger:o,...n}){let r=this.#s(t);o.debug(`${this.#t}: parsed input (${this.#e?"excl.":"no"} ack)`,r);let i=this.#a(t),s=await this.#i({input:r,logger:o,...n}),a=this.#c(s);i&&a&&(o.debug(`${this.#t}: parsed output`,a),i(...a))}example(t,o){return this.#n.push({variant:t,payload:o}),this}getExamples(t){return this.#n.filter(o=>o.variant===t).map(({payload:o})=>o)}};var de=class{constructor(t){this.config=t}build(t){return new ae(t)}};var Ze=P(require("typescript"),1);var Ke=require("node:crypto"),be=require("ramda"),he=P(require("typescript"),1),C=require("zod"),m=he.default.factory,G=[m.createModifier(he.default.SyntaxKind.ExportKeyword)],Pe=e=>(0,Ke.createHash)("sha1").update(JSON.stringify(e),"utf8").digest("hex"),Se=(e,t,o=3)=>{if(!t)return C.z.function(e,C.z.void());let n=C.z.function(t,C.z.void()),r=e._def.rest;if(!r||o<=0)return C.z.function(C.z.tuple([...e.items,n]),C.z.void());let i=(0,be.range)(0,o).map(s=>{let a=[...e.items].concat((0,be.range)(1,s+1).map(d=>r.describe(`${r.description||"rest"}${d}`))).concat(n);return C.z.function(C.z.tuple(a),C.z.void())});return C.z.union(i)};var p=P(require("typescript"),1),X=require("zod");var w=(e,{onEach:t,rules:o,onMissing:n,ctx:r={}})=>{let i=o[e._def.typeName],a=i?i(e,{...r,next:u=>w(u,{ctx:r,onEach:t,rules:o,onMissing:n})}):n(e,r),d=t&&t(e,{prev:a,...r});return d?{...a,...d}:a};var I=P(require("typescript"),1),{factory:pe}=I.default,q=(e,t)=>{I.default.addSyntheticLeadingComment(e,I.default.SyntaxKind.MultiLineCommentTrivia,`* ${t} `,!0)},Ue=(e,t,o)=>{let n=pe.createTypeAliasDeclaration(void 0,pe.createIdentifier(t),void 0,e);return o&&q(n,o),n},$e=(e,t)=>{let o=I.default.createSourceFile("print.ts","",I.default.ScriptTarget.Latest,!1,I.default.ScriptKind.TS);return I.default.createPrinter(t).printNode(I.default.EmitHint.Unspecified,e,o)},dt=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Le=e=>dt.test(e)?pe.createIdentifier(e):pe.createStringLiteral(e);var{factory:c}=p.default,pt={[p.default.SyntaxKind.AnyKeyword]:"",[p.default.SyntaxKind.BigIntKeyword]:BigInt(0),[p.default.SyntaxKind.BooleanKeyword]:!1,[p.default.SyntaxKind.NumberKeyword]:0,[p.default.SyntaxKind.ObjectKeyword]:{},[p.default.SyntaxKind.StringKeyword]:"",[p.default.SyntaxKind.UndefinedKeyword]:void 0,[p.default.SyntaxKind.UnknownKeyword]:void 0},mt=({value:e})=>c.createLiteralTypeNode(typeof e=="number"?c.createNumericLiteral(e):typeof e=="boolean"?e?c.createTrue():c.createFalse():c.createStringLiteral(e)),ut=({shape:e},{direction:t,next:o,optionalPropStyle:{withQuestionMark:n}})=>{let r=Object.entries(e).map(([i,s])=>{let a=t==="out"&&Y(s)?s instanceof X.z.ZodOptional:s.isOptional(),d=c.createPropertySignature(void 0,Le(i),a&&n?c.createToken(p.default.SyntaxKind.QuestionToken):void 0,o(s));return s.description&&q(d,s.description),d});return c.createTypeLiteralNode(r)},lt=({element:e},{next:t})=>c.createArrayTypeNode(t(e)),yt=({options:e})=>c.createUnionTypeNode(e.map(t=>c.createLiteralTypeNode(c.createStringLiteral(t)))),Fe=(e,{next:t})=>c.createUnionTypeNode(e.options.map(t)),ft=(e,t)=>t instanceof X.z.ZodDate?new Date:pt?.[e.kind],gt=(e,{next:t,direction:o})=>{let n=e.innerType(),r=t(n),i=e._def.effect;if(o==="out"&&i.type==="transform"){let s=oe(e,ft(r,n)),a={number:p.default.SyntaxKind.NumberKeyword,bigint:p.default.SyntaxKind.BigIntKeyword,boolean:p.default.SyntaxKind.BooleanKeyword,string:p.default.SyntaxKind.StringKeyword,undefined:p.default.SyntaxKind.UndefinedKeyword,object:p.default.SyntaxKind.ObjectKeyword};return c.createKeywordTypeNode(s&&a[s]||p.default.SyntaxKind.AnyKeyword)}return r},xt=e=>c.createUnionTypeNode(Object.values(e.enum).map(t=>c.createLiteralTypeNode(typeof t=="number"?c.createNumericLiteral(t):c.createStringLiteral(t)))),bt=(e,{next:t,optionalPropStyle:{withUndefined:o}})=>{let n=t(e.unwrap());return o?c.createUnionTypeNode([n,c.createKeywordTypeNode(p.default.SyntaxKind.UndefinedKeyword)]):n},ht=(e,{next:t})=>c.createUnionTypeNode([t(e.unwrap()),c.createLiteralTypeNode(c.createNull())]),St=({items:e,_def:{rest:t}},{next:o})=>c.createTupleTypeNode(e.map(o).concat(t===null?[]:c.createRestTypeNode(o(t)))),Tt=({keySchema:e,valueSchema:t},{next:o})=>c.createExpressionWithTypeArguments(c.createIdentifier("Record"),[e,t].map(o)),Zt=(e,{next:t})=>c.createIntersectionTypeNode([e._def.left,e._def.right].map(t)),Nt=(e,{next:t})=>t(e._def.innerType),F=e=>()=>c.createKeywordTypeNode(e),At=(e,{next:t})=>t(e.unwrap()),Et=(e,{next:t})=>t(e._def.innerType),zt=(e,{next:t})=>t(e._def.innerType),Ot=(e,{next:t,direction:o})=>t(e._def[o]),kt=()=>c.createLiteralTypeNode(c.createNull()),Ct=()=>c.createTypeReferenceNode(c.createIdentifier("Date")),Mt=(e,{getAlias:t,makeAlias:o,next:n,serializer:r})=>{let i=`Type${r(e.schema)}`;return t(i)||(o(i,c.createLiteralTypeNode(c.createNull())),o(i,n(e.schema)))},jt=(e,{next:t})=>{let o=e.parameters().items.map((r,i)=>c.createParameterDeclaration(void 0,void 0,c.createIdentifier(r.description?D(y(r.description)):`${r instanceof X.z.ZodFunction?"cb":"p"}${i+1}`),void 0,t(r))),{rest:n}=e.parameters()._def;return n&&o.push(c.createParameterDeclaration(void 0,c.createToken(p.default.SyntaxKind.DotDotDotToken),c.createIdentifier(n.description?D(y(n.description)):"rest"),void 0,t(X.z.array(n)))),c.createFunctionTypeNode(void 0,o,t(e.returnType()))},Dt={ZodString:F(p.default.SyntaxKind.StringKeyword),ZodNumber:F(p.default.SyntaxKind.NumberKeyword),ZodBigInt:F(p.default.SyntaxKind.BigIntKeyword),ZodBoolean:F(p.default.SyntaxKind.BooleanKeyword),ZodAny:F(p.default.SyntaxKind.AnyKeyword),ZodVoid:F(p.default.SyntaxKind.VoidKeyword),ZodUnknown:F(p.default.SyntaxKind.UnknownKeyword),ZodDate:Ct,ZodNull:kt,ZodArray:lt,ZodTuple:St,ZodRecord:Tt,ZodObject:ut,ZodLiteral:mt,ZodIntersection:Zt,ZodUnion:Fe,ZodDefault:Nt,ZodEnum:yt,ZodNativeEnum:xt,ZodEffects:gt,ZodOptional:bt,ZodNullable:ht,ZodDiscriminatedUnion:Fe,ZodBranded:At,ZodCatch:zt,ZodPipeline:Ot,ZodLazy:Mt,ZodReadonly:Et,ZodFunction:jt},Te=(e,t)=>w(e,{rules:Dt,onMissing:()=>c.createKeywordTypeNode(p.default.SyntaxKind.AnyKeyword),ctx:t});var It="root",He=["emission","actions"],me=class{program=[];aliases={};ids={path:m.createIdentifier("path"),socket:m.createIdentifier("Socket"),socketBase:m.createIdentifier("SocketBase"),ioClient:m.createStringLiteral("socket.io-client"),emission:m.createIdentifier(y(He[0])),actions:m.createIdentifier(y(He[1]))};registry={};getAlias(t,o){return o in this.aliases[t]?m.createTypeReferenceNode(o):void 0}makeAlias(t,o,n){return this.aliases[t][o]=Ue(n,o),this.getAlias(t,o)}constructor({config:{namespaces:t},actions:o,serializer:n=Pe,optionalPropStyle:r={withQuestionMark:!0,withUndefined:!0},maxOverloads:i=3}){this.program.push(m.createImportDeclaration(void 0,m.createImportClause(!0,void 0,m.createNamedImports([m.createImportSpecifier(!1,this.ids.socket,this.ids.socketBase)])),this.ids.ioClient));for(let[s,{emission:a}]of Object.entries(t)){this.aliases[s]={},this.registry[s]={emission:[],actions:[]};let d={getAlias:this.getAlias.bind(this,s),makeAlias:this.makeAlias.bind(this,s),serializer:n,optionalPropStyle:r};for(let[u,{schema:A,ack:x}]of Object.entries(a)){let z=Te(Se(A,x,i),{direction:"out",...d});this.registry[s].emission.push({event:u,node:z})}for(let u of o)if(u.getNamespace()===s){let A=u.getEvent(),x=u.getSchema("input"),z=u.getSchema("output"),S=Te(Se(x,z,i),{direction:"in",...d});this.registry[s].actions.push({event:A,node:S})}}for(let s in this.registry){let a=y(s)||y(It),d=m.createVariableStatement(G,m.createVariableDeclarationList([m.createVariableDeclaration(this.ids.path,void 0,void 0,m.createStringLiteral(B(s)))],Ze.default.NodeFlags.Const));q(d,`@desc The actual path of the ${a} namespace`);let u=Object.entries(this.registry[s]).map(([x,z])=>m.createInterfaceDeclaration(G,y(x),void 0,void 0,z.map(({event:S,node:T})=>m.createPropertySignature(void 0,S,void 0,T)))),A=m.createTypeAliasDeclaration(G,this.ids.socket,void 0,m.createTypeReferenceNode(this.ids.socketBase,[m.createTypeReferenceNode(this.ids.emission),m.createTypeReferenceNode(this.ids.actions)]));q(A,`@example const socket: ${a}.${this.ids.socket.text} = io(${a}.${this.ids.path.text})`),this.program.push(m.createModuleDeclaration(G,m.createIdentifier(a),m.createModuleBlock([d,...Object.values(this.aliases[s]),...u,A]),Ze.default.NodeFlags.Namespace))}}print(t){return this.program.map((o,n)=>$e(o,n({...o(e),default:t()}),Rt=({_def:{innerType:e}},{next:t})=>t(e),Be=()=>({format:"any"}),Kt=({options:e},{next:t})=>({oneOf:e.map(t)}),Pt=({options:e,discriminator:t},{next:o})=>({discriminator:t,oneOf:Array.from(e.values()).map(o)}),Ut=e=>{let[t,o]=e.filter(r=>!R(r)&&r.type==="object"&&Object.keys(r).every(i=>["type","properties","required","examples"].includes(i)));(0,ye.default)(t&&o,"Can not flatten objects");let n={type:"object"};return(t.properties||o.properties)&&(n.properties=(0,f.mergeDeepWith)((r,i)=>Array.isArray(r)&&Array.isArray(i)?(0,f.concat)(r,i):r===i?i:ye.default.fail("Can not flatten properties"),t.properties||{},o.properties||{})),(t.required||o.required)&&(n.required=(0,f.union)(t.required||[],o.required||[])),n},$t=({_def:{left:e,right:t}},{next:o})=>{let n=[e,t].map(o);try{return Ut(n)}catch{}return{allOf:n}},Lt=(e,{next:t})=>t(e.unwrap()),Ft=(e,{next:t})=>t(e._def.innerType),Ht=(e,{next:t})=>{let o=t(e.unwrap());return R(o)||(o.type=qe(o)),o},We=e=>{let t=(0,f.toLower)((0,f.type)(e));return typeof e=="bigint"?"integer":t==="number"||t==="string"||t==="boolean"||t==="object"||t==="null"||t==="array"?t:void 0},Ve=e=>({type:We(Object.values(e.enum)[0]),enum:Object.values(e.enum)}),_t=({value:e})=>({type:We(e),const:e}),Bt=(e,{direction:t,next:o})=>{let n=Object.keys(e.shape),r=a=>t==="out"&&Y(a)?a instanceof j.z.ZodOptional:a.isOptional(),i=n.filter(a=>!r(e.shape[a])),s={type:"object"};return n.length&&(s.properties=le(e,o)),i.length&&(s.required=i),s},Vt=()=>({type:"null"}),Wt=()=>({type:"boolean"}),qt=()=>({type:"integer",format:"bigint"}),Yt=e=>e.every(t=>t instanceof j.z.ZodLiteral),Jt=({keySchema:e,valueSchema:t},{next:o})=>{if(e instanceof j.z.ZodEnum||e instanceof j.z.ZodNativeEnum){let n=Object.values(e.enum),r={type:"object"};return n.length&&(r.properties=le(j.z.object((0,f.fromPairs)((0,f.xprod)(n,[t]))),o),r.required=n),r}if(e instanceof j.z.ZodLiteral)return{type:"object",properties:le(j.z.object({[e.value]:t}),o),required:[e.value]};if(e instanceof j.z.ZodUnion&&Yt(e.options)){let n=(0,f.map)(i=>`${i.value}`,e.options),r=(0,f.fromPairs)((0,f.xprod)(n,[t]));return{type:"object",properties:le(j.z.object(r),o),required:n}}return{type:"object",additionalProperties:o(t)}},Qt=({_def:e,element:t},{next:o})=>{let n={type:"array",items:o(t)};return e.minLength&&(n.minItems=e.minLength.value),e.maxLength&&(n.maxItems=e.maxLength.value),n},Gt=({items:e,_def:{rest:t}},{next:o})=>({type:"array",items:e.length?e.map(o):void 0,additionalItems:t===null?!1:o(t)}),Xt=({isEmail:e,isURL:t,minLength:o,maxLength:n,isUUID:r,isCUID:i,isCUID2:s,isULID:a,isIP:d,isEmoji:u,isDatetime:A,_def:{checks:x}})=>{let z=x.find(N=>N.kind==="regex"),S=x.find(N=>N.kind==="datetime"),T=z?z.regex:S?S.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"):void 0,Z={type:"string"},H={"date-time":A,email:e,url:t,uuid:r,cuid:i,cuid2:s,ulid:a,ip:d,emoji:u};for(let N in H)if(H[N]){Z.format=N;break}return o!==null&&(Z.minLength=o),n!==null&&(Z.maxLength=n),T&&(Z.pattern=T.source),Z},eo=e=>{let t=e._def.checks.find(({kind:d})=>d==="min"),o=e.minValue===null?e.isInt?Number.MIN_SAFE_INTEGER:-Number.MAX_VALUE:e.minValue,n=t?t.inclusive:!0,r=e._def.checks.find(({kind:d})=>d==="max"),i=e.maxValue===null?e.isInt?Number.MAX_SAFE_INTEGER:Number.MAX_VALUE:e.maxValue,s=r?r.inclusive:!0,a={type:e.isInt?"integer":"number",format:e.isInt?"int64":"double"};return n?a.minimum=o:a.exclusiveMinimum=o,s?a.maximum=i:a.exclusiveMaximum=i,a},le=({shape:e},t)=>(0,f.map)(t,e),to=e=>{let t=Array.isArray(e.type)?e.type[0]:e.type;return e.format==="date"?new Date:vt?.[t]},qe=e=>{let t=typeof e.type=="string"?[e.type]:e.type||[];return t.includes("null")?t:t.concat("null")},oo=(e,{direction:t,next:o})=>{let n=o(e.innerType()),{effect:r}=e._def;if(t==="out"&&r.type==="transform"&&!R(n)){let i=oe(e,to(n));return i&&["number","string","boolean"].includes(i)?{type:i}:o(j.z.any())}if(t==="in"&&r.type==="preprocess"&&!R(n)){let{type:i,...s}=n;return{...s,format:`${s.format||i} (preprocessed)`}}return n},no=(e,{direction:t,next:o})=>o(e._def[t]),ro=(e,{next:t})=>t(e.unwrap()),io=()=>({format:"date"}),Ne={ZodString:Xt,ZodNumber:eo,ZodBigInt:qt,ZodBoolean:Wt,ZodNull:Vt,ZodArray:Qt,ZodTuple:Gt,ZodRecord:Jt,ZodObject:Bt,ZodLiteral:_t,ZodIntersection:$t,ZodUnion:Kt,ZodAny:Be,ZodDefault:wt,ZodEnum:Ve,ZodNativeEnum:Ve,ZodEffects:oo,ZodOptional:Lt,ZodNullable:Ht,ZodDiscriminatedUnion:Pt,ZodBranded:ro,ZodCatch:Rt,ZodPipeline:no,ZodReadonly:Ft,ZodDate:io,ZodUnknown:Be},Ae=(e,{direction:t,prev:o})=>{if(R(o))return{};let{description:n}=e,r=o.type!==void 0,i=t==="out"&&Y(e),s=r&&!i&&e.isNullable(),a={};return n&&(a.description=n),s&&(a.type=qe(o)),a},Ee=e=>ye.default.fail(`Zod type ${e.constructor.name} is unsupported.`),so=(e,t)=>{if(R(e)||!t)return e;if(e.type==="array"&&e.items&&Array.isArray(e.items))for(let o of t)for(let n=0;n({name:r?void 0:e,title:r?`Acknowledgement for ${e}`:e,payload:so(w(t,{ctx:{direction:n},onMissing:Ee,onEach:Ae,rules:Ne}),o),examples:o&&o.length?o.map(i=>({payload:i})):void 0}),ze=({direction:e,channelId:t,messageId:o,ackId:n,event:r,ns:i,securityIds:s})=>({action:e==="out"?"send":"receive",channel:{$ref:`#/channels/${t}`},messages:[{$ref:`#/channels/${t}/messages/${o}`}],title:r,summary:`${e==="out"?"Outgoing":"Incoming"} event ${r}`,description:`The message ${e==="out"?"produced":"consumed"} by the application within the ${i} namespace`,security:s&&s.length?s.map(a=>({$ref:`#/components/securitySchemes/${a}`})):void 0,reply:n?{address:{location:"$message.payload#",description:"Last argument: acknowledgement handler"},channel:{$ref:`#/channels/${t}`},messages:[{$ref:`#/channels/${t}/messages/${n}`}]}:void 0});var Ye=(e,t)=>t&&(Array.isArray(t)?t:[t]).map(o=>o[e]).filter(o=>!!o),fe=class extends ue{#t(){let t={onEach:Ae,onMissing:Ee,rules:Ne,ctx:{direction:"in"}};return{bindingVersion:"0.1.0",method:"GET",headers:w(K.z.object({connection:K.z.literal("Upgrade").optional(),upgrade:K.z.literal("websocket").optional()}),t),query:{...w(K.z.object({EIO:K.z.literal("4").describe("The version of the protocol"),transport:K.z.enum(["polling","websocket"]).describe("The name of the transport"),sid:K.z.string().optional().describe("The session identifier")}),t),externalDocs:{description:"Engine.IO Protocol",url:"https://socket.io/docs/v4/engine-io-protocol/"}}}}constructor({actions:t,config:{namespaces:o,security:n},title:r,version:i,documentId:s,description:a,contact:d,license:u,servers:A={}}){super({info:{title:r,version:i,contact:d,license:u,description:a},id:s,defaultContentType:"text/plain"});let x=[];for(let[S,T]of Object.entries(n)){let Z=D(y(`server security ${S}`));this.addSecurityScheme(Z,T),x.push(Z)}for(let S in A){let T=new URL(A[S].url);this.addServer(S,{description:A[S].description,host:T.host,pathname:T.pathname,protocol:T.protocol.slice(0,-1),security:x.length?x.map(Z=>({$ref:`#/components/securitySchemes/${Z}`})):void 0}),this.document.id||(this.document.id=`urn:${T.host.split(".").concat(T.pathname.slice(1).split("/")).join(":")}`)}let z=this.#t();for(let[S,{emission:T,examples:Z,security:H}]of Object.entries(o)){let N=B(S),b=y(N)||"Root",v={},g=[];for(let[l,O]of Object.entries(H)){let M=D(y(`${b} security ${l}`));this.addSecurityScheme(M,O),g.push(M)}for(let[l,{schema:O,ack:M}]of Object.entries(T)){let k=D(y(`${b} outgoing ${l}`)),h=D(y(`${b} ack for outgoing ${l}`));v[k]=ee({event:l,schema:O,direction:"out",examples:Ye("payload",Z[l])}),M&&(v[h]=ee({event:l,schema:M,examples:Ye("ack",Z[l]),direction:"in",isAck:!0})),this.addOperation(y(`${b} send operation ${l}`),ze({direction:"out",event:l,channelId:b,messageId:k,ackId:M&&h,ns:N}))}for(let l of t)if(l.getNamespace()===N){let O=l.getEvent(),M=D(y(`${b} incoming ${O}`)),k=D(y(`${b} ack for incoming ${O}`)),h=l.getSchema("output");v[M]=ee({event:O,schema:l.getSchema("input"),examples:l.getExamples("input"),direction:"in"}),h&&(v[k]=ee({event:O,schema:h,examples:l.getExamples("output"),direction:"out",isAck:!0})),this.addOperation(y(`${b} recv operation ${O}`),ze({direction:"in",channelId:b,messageId:M,event:O,ns:N,ackId:h&&k,securityIds:g}))}this.addChannel(b,{address:N,title:`Namespace ${N}`,bindings:{ws:z},messages:v})}}};0&&(module.exports={AbstractAction,ActionsFactory,Config,Documentation,InputValidationError,Integration,OutputValidationError,attachSockets,createSimpleConfig});