@fern-api/cli-dynamic-snippets 0.0.0-stage → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ import { AbstractDynamicSnippetsGeneratorContext, FernGeneratorExec, Options, AbstractAstNode, AbstractDynamicSnippetsGenerator } from '@fern-api/browser-compatible-base-generator';
2
+ import { FernIr } from '@fern-api/dynamic-ir-sdk';
3
+
4
+ /** Custom config block the fern-cli-generator reads (generators/cli/src/customConfig.ts). */
5
+ interface CliCustomConfigSchema {
6
+ /** Overrides the binary name. Mirrors FernCliCustomConfig.binaryName. */
7
+ binaryName?: string;
8
+ /** Nests every generated command one level under this group (`<binary> <rootGroup> …`). */
9
+ rootGroup?: string;
10
+ /** Renames the user-agent-suffix flag; when set the runtime reserves this name instead. */
11
+ userAgentSuffixFlag?: string;
12
+ /** Named-profiles feature; when enabled the runtime reserves the `--profile` flag. */
13
+ profiles?: {
14
+ enabled?: boolean;
15
+ };
16
+ /**
17
+ * Not user config: set by the Fern CLI when it builds the `cli` dynamic IR. Maps each namespaced
18
+ * spec's top-level `fernFilepath` part (e.g. `accountsV1`) to its `generators.yml` `namespace:`
19
+ * (`accounts/v1`), which the importer flattens but the runtime mounts verbatim via `spec_under`.
20
+ */
21
+ namespaces?: Record<string, string>;
22
+ }
23
+ declare class DynamicSnippetsGeneratorContext extends AbstractDynamicSnippetsGeneratorContext {
24
+ ir: FernIr.dynamic.DynamicIntermediateRepresentation;
25
+ customConfig: CliCustomConfigSchema | undefined;
26
+ constructor({ ir, config }: {
27
+ ir: FernIr.dynamic.DynamicIntermediateRepresentation;
28
+ config: FernGeneratorExec.GeneratorConfig;
29
+ });
30
+ clone(): DynamicSnippetsGeneratorContext;
31
+ /**
32
+ * The binary name that leads every command (e.g. `twilio`). Mirrors `deriveBinaryName`
33
+ * (generators/cli/src/identity.ts): prefer `customConfig.binaryName`, else fall back to the
34
+ * workspace name (the dynamic-IR analogue of `apiDisplayName`). Normalized with the CLI's own
35
+ * `toKebabCase` (lowercase-first) so acronym/mixed-case names resolve to the real executable —
36
+ * e.g. `MyCLI` → `mycli`, not `camelToKebab`'s `my-c-l-i`.
37
+ */
38
+ getBinaryName(): string;
39
+ /**
40
+ * The command path leading up to (and including) the leaf command, e.g.
41
+ * `["twilio", "messages", "create"]`. When `customConfig.rootGroup` is set the CLI nests every
42
+ * command one level under it (`<binary> <rootGroup> …`), so it is inserted right after the binary.
43
+ * The namespace/resource segments come from the endpoint's `fernFilepath` (see `getGroupPath`) and
44
+ * the leaf from the endpoint `declaration.name` (parser.rs:3055).
45
+ */
46
+ getCommandPrefix(endpoint: FernIr.dynamic.Endpoint): string[];
47
+ /**
48
+ * The group segments for an endpoint's `fernFilepath` parts. Without a `namespaces` entry each part
49
+ * is kebab-cased like `camel_to_kebab` (parser.rs:3310). With one, the namespace is split on `/` into verbatim segments (`split_prefix`,
50
+ * app.rs), and a first resource named like the namespace's last segment is hoisted into it, matching
51
+ * the runtime's stutter elision (`merge_into_path`, app.rs).
52
+ */
53
+ private getGroupPath;
54
+ /**
55
+ * Extra flag names the runtime reserves beyond the built-ins, from config-dependent features:
56
+ * a renamed `userAgentSuffixFlag` and the `profile` flag when `profiles` is enabled. A parameter
57
+ * resolving to one of these gets the runtime's `-param` suffix.
58
+ */
59
+ getReservedFlagNames(): ReadonlySet<string>;
60
+ }
61
+
62
+ declare class EndpointSnippetGenerator {
63
+ private context;
64
+ constructor({ context }: {
65
+ context: DynamicSnippetsGeneratorContext;
66
+ });
67
+ generateSnippet({ endpoint, request }: {
68
+ endpoint: FernIr.dynamic.Endpoint;
69
+ request: FernIr.dynamic.EndpointSnippetRequest;
70
+ }): Promise<string>;
71
+ generateSnippetSync({ endpoint, request }: {
72
+ endpoint: FernIr.dynamic.Endpoint;
73
+ request: FernIr.dynamic.EndpointSnippetRequest;
74
+ }): string;
75
+ generateSnippetAst({ endpoint, request }: {
76
+ endpoint: FernIr.dynamic.Endpoint;
77
+ request: FernIr.dynamic.EndpointSnippetRequest;
78
+ options?: Options;
79
+ }): Promise<AbstractAstNode>;
80
+ private buildCommand;
81
+ private emitInlinedRequest;
82
+ private emitBodyRequest;
83
+ /**
84
+ * Path parameters — merged root-level + endpoint-level in IR order. Parameters bound to a client
85
+ * `variable` (globals like an account SID) are configured out of band and skipped.
86
+ */
87
+ private emitPathParameters;
88
+ private emitNamedParameters;
89
+ private emitInlinedRequestBody;
90
+ private emitReferencedBody;
91
+ /**
92
+ * Flatten an object body into per-field flags. When any field's wire name is a *literal* dotted
93
+ * key (e.g. Twilio `Parameter1.Name`) the whole body is sent verbatim through `--json` instead —
94
+ * the runtime mis-nests the dot in both dedicated flags and `--params`, and `--json` can't be
95
+ * combined with per-field body flags.
96
+ */
97
+ private emitObjectBody;
98
+ /**
99
+ * Emit one resolved input. Scalars render as `--flag value`; arrays of scalars repeat the flag;
100
+ * objects and arrays-of-objects (and any input the runtime exposes no flag for) route through
101
+ * `--params`. Mirrors the publish-time assembler's routing.
102
+ */
103
+ private emitValue;
104
+ /**
105
+ * When two parameters resolve to the same flag the runtime keeps the first and drops the rest; the
106
+ * builder mirrors that by refusing the duplicate. Surface a warning so the dropped value is visible
107
+ * to docs consumers rather than producing a quietly incomplete command (consistent with the
108
+ * omitted-parameter warnings above).
109
+ */
110
+ private warnIfFlagCollision;
111
+ /** Resolve a type reference to its object properties, if it names (or aliases) an object type. */
112
+ private resolveObjectProperties;
113
+ }
114
+
115
+ declare class DynamicSnippetsGenerator extends AbstractDynamicSnippetsGenerator<DynamicSnippetsGeneratorContext, EndpointSnippetGenerator> {
116
+ constructor({ ir, config }: {
117
+ ir: FernIr.dynamic.DynamicIntermediateRepresentation;
118
+ config: FernGeneratorExec.GeneratorConfig;
119
+ });
120
+ generate(request: FernIr.dynamic.EndpointSnippetRequest, options?: Options): Promise<FernIr.dynamic.EndpointSnippetResponse>;
121
+ generateSync(request: FernIr.dynamic.EndpointSnippetRequest): FernIr.dynamic.EndpointSnippetResponse;
122
+ generateSnippetAst(request: FernIr.dynamic.EndpointSnippetRequest, options?: Pick<Options, "skipClientInstantiation" | "endpointId">): Promise<AbstractAstNode>;
123
+ protected createSnippetGenerator(context: DynamicSnippetsGeneratorContext): EndpointSnippetGenerator;
124
+ }
125
+
126
+ export { DynamicSnippetsGenerator };
@@ -0,0 +1,126 @@
1
+ import { AbstractDynamicSnippetsGeneratorContext, FernGeneratorExec, Options, AbstractAstNode, AbstractDynamicSnippetsGenerator } from '@fern-api/browser-compatible-base-generator';
2
+ import { FernIr } from '@fern-api/dynamic-ir-sdk';
3
+
4
+ /** Custom config block the fern-cli-generator reads (generators/cli/src/customConfig.ts). */
5
+ interface CliCustomConfigSchema {
6
+ /** Overrides the binary name. Mirrors FernCliCustomConfig.binaryName. */
7
+ binaryName?: string;
8
+ /** Nests every generated command one level under this group (`<binary> <rootGroup> …`). */
9
+ rootGroup?: string;
10
+ /** Renames the user-agent-suffix flag; when set the runtime reserves this name instead. */
11
+ userAgentSuffixFlag?: string;
12
+ /** Named-profiles feature; when enabled the runtime reserves the `--profile` flag. */
13
+ profiles?: {
14
+ enabled?: boolean;
15
+ };
16
+ /**
17
+ * Not user config: set by the Fern CLI when it builds the `cli` dynamic IR. Maps each namespaced
18
+ * spec's top-level `fernFilepath` part (e.g. `accountsV1`) to its `generators.yml` `namespace:`
19
+ * (`accounts/v1`), which the importer flattens but the runtime mounts verbatim via `spec_under`.
20
+ */
21
+ namespaces?: Record<string, string>;
22
+ }
23
+ declare class DynamicSnippetsGeneratorContext extends AbstractDynamicSnippetsGeneratorContext {
24
+ ir: FernIr.dynamic.DynamicIntermediateRepresentation;
25
+ customConfig: CliCustomConfigSchema | undefined;
26
+ constructor({ ir, config }: {
27
+ ir: FernIr.dynamic.DynamicIntermediateRepresentation;
28
+ config: FernGeneratorExec.GeneratorConfig;
29
+ });
30
+ clone(): DynamicSnippetsGeneratorContext;
31
+ /**
32
+ * The binary name that leads every command (e.g. `twilio`). Mirrors `deriveBinaryName`
33
+ * (generators/cli/src/identity.ts): prefer `customConfig.binaryName`, else fall back to the
34
+ * workspace name (the dynamic-IR analogue of `apiDisplayName`). Normalized with the CLI's own
35
+ * `toKebabCase` (lowercase-first) so acronym/mixed-case names resolve to the real executable —
36
+ * e.g. `MyCLI` → `mycli`, not `camelToKebab`'s `my-c-l-i`.
37
+ */
38
+ getBinaryName(): string;
39
+ /**
40
+ * The command path leading up to (and including) the leaf command, e.g.
41
+ * `["twilio", "messages", "create"]`. When `customConfig.rootGroup` is set the CLI nests every
42
+ * command one level under it (`<binary> <rootGroup> …`), so it is inserted right after the binary.
43
+ * The namespace/resource segments come from the endpoint's `fernFilepath` (see `getGroupPath`) and
44
+ * the leaf from the endpoint `declaration.name` (parser.rs:3055).
45
+ */
46
+ getCommandPrefix(endpoint: FernIr.dynamic.Endpoint): string[];
47
+ /**
48
+ * The group segments for an endpoint's `fernFilepath` parts. Without a `namespaces` entry each part
49
+ * is kebab-cased like `camel_to_kebab` (parser.rs:3310). With one, the namespace is split on `/` into verbatim segments (`split_prefix`,
50
+ * app.rs), and a first resource named like the namespace's last segment is hoisted into it, matching
51
+ * the runtime's stutter elision (`merge_into_path`, app.rs).
52
+ */
53
+ private getGroupPath;
54
+ /**
55
+ * Extra flag names the runtime reserves beyond the built-ins, from config-dependent features:
56
+ * a renamed `userAgentSuffixFlag` and the `profile` flag when `profiles` is enabled. A parameter
57
+ * resolving to one of these gets the runtime's `-param` suffix.
58
+ */
59
+ getReservedFlagNames(): ReadonlySet<string>;
60
+ }
61
+
62
+ declare class EndpointSnippetGenerator {
63
+ private context;
64
+ constructor({ context }: {
65
+ context: DynamicSnippetsGeneratorContext;
66
+ });
67
+ generateSnippet({ endpoint, request }: {
68
+ endpoint: FernIr.dynamic.Endpoint;
69
+ request: FernIr.dynamic.EndpointSnippetRequest;
70
+ }): Promise<string>;
71
+ generateSnippetSync({ endpoint, request }: {
72
+ endpoint: FernIr.dynamic.Endpoint;
73
+ request: FernIr.dynamic.EndpointSnippetRequest;
74
+ }): string;
75
+ generateSnippetAst({ endpoint, request }: {
76
+ endpoint: FernIr.dynamic.Endpoint;
77
+ request: FernIr.dynamic.EndpointSnippetRequest;
78
+ options?: Options;
79
+ }): Promise<AbstractAstNode>;
80
+ private buildCommand;
81
+ private emitInlinedRequest;
82
+ private emitBodyRequest;
83
+ /**
84
+ * Path parameters — merged root-level + endpoint-level in IR order. Parameters bound to a client
85
+ * `variable` (globals like an account SID) are configured out of band and skipped.
86
+ */
87
+ private emitPathParameters;
88
+ private emitNamedParameters;
89
+ private emitInlinedRequestBody;
90
+ private emitReferencedBody;
91
+ /**
92
+ * Flatten an object body into per-field flags. When any field's wire name is a *literal* dotted
93
+ * key (e.g. Twilio `Parameter1.Name`) the whole body is sent verbatim through `--json` instead —
94
+ * the runtime mis-nests the dot in both dedicated flags and `--params`, and `--json` can't be
95
+ * combined with per-field body flags.
96
+ */
97
+ private emitObjectBody;
98
+ /**
99
+ * Emit one resolved input. Scalars render as `--flag value`; arrays of scalars repeat the flag;
100
+ * objects and arrays-of-objects (and any input the runtime exposes no flag for) route through
101
+ * `--params`. Mirrors the publish-time assembler's routing.
102
+ */
103
+ private emitValue;
104
+ /**
105
+ * When two parameters resolve to the same flag the runtime keeps the first and drops the rest; the
106
+ * builder mirrors that by refusing the duplicate. Surface a warning so the dropped value is visible
107
+ * to docs consumers rather than producing a quietly incomplete command (consistent with the
108
+ * omitted-parameter warnings above).
109
+ */
110
+ private warnIfFlagCollision;
111
+ /** Resolve a type reference to its object properties, if it names (or aliases) an object type. */
112
+ private resolveObjectProperties;
113
+ }
114
+
115
+ declare class DynamicSnippetsGenerator extends AbstractDynamicSnippetsGenerator<DynamicSnippetsGeneratorContext, EndpointSnippetGenerator> {
116
+ constructor({ ir, config }: {
117
+ ir: FernIr.dynamic.DynamicIntermediateRepresentation;
118
+ config: FernGeneratorExec.GeneratorConfig;
119
+ });
120
+ generate(request: FernIr.dynamic.EndpointSnippetRequest, options?: Options): Promise<FernIr.dynamic.EndpointSnippetResponse>;
121
+ generateSync(request: FernIr.dynamic.EndpointSnippetRequest): FernIr.dynamic.EndpointSnippetResponse;
122
+ generateSnippetAst(request: FernIr.dynamic.EndpointSnippetRequest, options?: Pick<Options, "skipClientInstantiation" | "endpointId">): Promise<AbstractAstNode>;
123
+ protected createSnippetGenerator(context: DynamicSnippetsGeneratorContext): EndpointSnippetGenerator;
124
+ }
125
+
126
+ export { DynamicSnippetsGenerator };
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ var ze=Object.defineProperty;var jt=(l,t,o)=>t in l?ze(l,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):l[t]=o;var te=(l,t,o)=>()=>{if(o)throw o[0];try{return l&&(t=l(l=0)),t}catch(u){throw o=[u],u}};var Gt=(l,t)=>{for(var o in t)ze(l,o,{get:t[o],enumerable:!0})};var I=(l,t,o)=>jt(l,typeof t!="symbol"?t+"":t,o);var d=te(()=>{"use strict"});var b={};Gt(b,{_debugEnd:()=>kr,_debugProcess:()=>_r,_events:()=>Xr,_eventsCount:()=>Qr,_exiting:()=>mr,_fatalExceptions:()=>Tr,_getActiveHandles:()=>Er,_getActiveRequests:()=>wr,_kill:()=>Br,_linkedBinding:()=>hr,_maxListeners:()=>Kr,_preload_modules:()=>Hr,_rawDebug:()=>cr,_startProfilerIdleNotifier:()=>Lr,_stopProfilerIdleNotifier:()=>$r,_tickCallback:()=>Ur,abort:()=>Vr,addListener:()=>Zr,allowedNodeEnvironmentFlags:()=>Sr,arch:()=>Xe,argv:()=>er,argv0:()=>zr,assert:()=>Pr,binding:()=>or,browser:()=>lr,chdir:()=>ur,config:()=>yr,cpuUsage:()=>Ee,cwd:()=>ar,debugPort:()=>Wr,default:()=>ut,dlopen:()=>gr,domain:()=>dr,emit:()=>it,emitWarning:()=>ir,env:()=>Ze,execArgv:()=>rr,execPath:()=>qr,exit:()=>br,features:()=>Nr,hasUncaughtExceptionCaptureCallback:()=>Fr,hrtime:()=>we,kill:()=>Rr,listeners:()=>at,memoryUsage:()=>vr,moduleLoadList:()=>fr,nextTick:()=>Je,off:()=>rt,on:()=>J,once:()=>et,openStdin:()=>Ar,pid:()=>jr,platform:()=>Qe,ppid:()=>Gr,prependListener:()=>ot,prependOnceListener:()=>st,reallyExit:()=>xr,release:()=>pr,removeAllListeners:()=>nt,removeListener:()=>tt,resourceUsage:()=>Ir,setSourceMapsEnabled:()=>Jr,setUncaughtExceptionCaptureCallback:()=>Cr,stderr:()=>Mr,stdin:()=>Dr,stdout:()=>Or,title:()=>Ke,umask:()=>sr,uptime:()=>Yr,version:()=>tr,versions:()=>nr});function Fe(l){throw new Error("Node.js process "+l+" is not supported by JSPM core outside of Node.js")}function qt(){!ne||!X||(ne=!1,X.length?H=X.concat(H):ge=-1,H.length&&He())}function He(){if(!ne){var l=setTimeout(qt,0);ne=!0;for(var t=H.length;t;){for(X=H,H=[];++ge<t;)X&&X[ge].run();ge=-1,t=H.length}X=null,ne=!1,clearTimeout(l)}}function Je(l){var t=new Array(arguments.length-1);if(arguments.length>1)for(var o=1;o<arguments.length;o++)t[o-1]=arguments[o];H.push(new Ye(l,t)),H.length===1&&!ne&&setTimeout(He,0)}function Ye(l,t){this.fun=l,this.array=t}function O(){}function hr(l){Fe("_linkedBinding")}function gr(l){Fe("dlopen")}function wr(){return[]}function Er(){return[]}function Pr(l,t){if(!l)throw new Error(t||"assertion error")}function Fr(){return!1}function Yr(){return K.now()/1e3}function we(l){var t=Math.floor((Date.now()-K.now())*.001),o=K.now()*.001,u=Math.floor(o)+t,c=Math.floor(o%1*1e9);return l&&(u=u-l[0],c=c-l[1],c<0&&(u--,c+=Ce)),[u,c]}function J(){return ut}function at(l){return[]}var H,ne,X,ge,Ke,Xe,Qe,Ze,er,rr,tr,nr,ir,or,sr,ar,ur,pr,lr,cr,fr,dr,mr,yr,xr,Br,Ee,Ir,vr,Rr,br,Ar,Sr,Nr,Tr,Cr,Ur,_r,kr,Lr,$r,Or,Mr,Dr,Vr,jr,Gr,qr,Wr,zr,Hr,Jr,K,Te,Ce,Kr,Xr,Qr,Zr,et,rt,tt,nt,it,ot,st,ut,pt=te(()=>{"use strict";d();y();m();H=[],ne=!1,ge=-1;Ye.prototype.run=function(){this.fun.apply(null,this.array)};Ke="browser",Xe="x64",Qe="browser",Ze={PATH:"/usr/bin",LANG:typeof navigator<"u"?navigator.language+".UTF-8":void 0,PWD:"/",HOME:"/home",TMP:"/tmp"},er=["/usr/bin/node"],rr=[],tr="v16.8.0",nr={},ir=function(l,t){console.warn((t?t+": ":"")+l)},or=function(l){Fe("binding")},sr=function(l){return 0},ar=function(){return"/"},ur=function(l){},pr={name:"node",sourceUrl:"",headersUrl:"",libUrl:""};lr=!0,cr=O,fr=[];dr={},mr=!1,yr={};xr=O,Br=O,Ee=function(){return{}},Ir=Ee,vr=Ee,Rr=O,br=O,Ar=O,Sr={};Nr={inspector:!1,debug:!1,uv:!1,ipv6:!1,tls_alpn:!1,tls_sni:!1,tls_ocsp:!1,tls:!1,cached_builtins:!0},Tr=O,Cr=O;Ur=O,_r=O,kr=O,Lr=O,$r=O,Or=void 0,Mr=void 0,Dr=void 0,Vr=O,jr=2,Gr=1,qr="/bin/usr/node",Wr=9229,zr="node",Hr=[],Jr=O,K={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0};K.now===void 0&&(Te=Date.now(),K.timing&&K.timing.navigationStart&&(Te=K.timing.navigationStart),K.now=()=>Date.now()-Te);Ce=1e9;we.bigint=function(l){var t=we(l);return typeof BigInt>"u"?t[0]*Ce+t[1]:BigInt(t[0]*Ce)+BigInt(t[1])};Kr=10,Xr={},Qr=0;Zr=J,et=J,rt=J,tt=J,nt=J,it=O,ot=J,st=J;ut={version:tr,versions:nr,arch:Xe,platform:Qe,browser:lr,release:pr,_rawDebug:cr,moduleLoadList:fr,binding:or,_linkedBinding:hr,_events:Xr,_eventsCount:Qr,_maxListeners:Kr,on:J,addListener:Zr,once:et,off:rt,removeListener:tt,removeAllListeners:nt,emit:it,prependListener:ot,prependOnceListener:st,listeners:at,domain:dr,_exiting:mr,config:yr,dlopen:gr,uptime:Yr,_getActiveRequests:wr,_getActiveHandles:Er,reallyExit:xr,_kill:Br,cpuUsage:Ee,resourceUsage:Ir,memoryUsage:vr,kill:Rr,exit:br,openStdin:Ar,allowedNodeEnvironmentFlags:Sr,assert:Pr,features:Nr,_fatalExceptions:Tr,setUncaughtExceptionCaptureCallback:Cr,hasUncaughtExceptionCaptureCallback:Fr,emitWarning:ir,nextTick:Je,_tickCallback:Ur,_debugProcess:_r,_debugEnd:kr,_startProfilerIdleNotifier:Lr,_stopProfilerIdleNotifier:$r,stdout:Or,stdin:Dr,stderr:Mr,abort:Vr,umask:sr,chdir:ur,cwd:ar,env:Ze,title:Ke,argv:er,execArgv:rr,pid:jr,ppid:Gr,execPath:qr,debugPort:Wr,hrtime:we,argv0:zr,_preload_modules:Hr,setSourceMapsEnabled:Jr}});var m=te(()=>{"use strict";pt()});function Wt(){if(lt)return oe;lt=!0,oe.byteLength=w,oe.toByteArray=$,oe.fromByteArray=q;for(var l=[],t=[],o=typeof Uint8Array<"u"?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=0,h=u.length;c<h;++c)l[c]=u[c],t[u.charCodeAt(c)]=c;t[45]=62,t[95]=63;function s(g){var B=g.length;if(B%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var R=g.indexOf("=");R===-1&&(R=B);var _=R===B?0:4-R%4;return[R,_]}function w(g){var B=s(g),R=B[0],_=B[1];return(R+_)*3/4-_}function E(g,B,R){return(B+R)*3/4-R}function $(g){var B,R=s(g),_=R[0],D=R[1],U=new o(E(g,_,D)),V=0,G=D>0?_-4:_,M;for(M=0;M<G;M+=4)B=t[g.charCodeAt(M)]<<18|t[g.charCodeAt(M+1)]<<12|t[g.charCodeAt(M+2)]<<6|t[g.charCodeAt(M+3)],U[V++]=B>>16&255,U[V++]=B>>8&255,U[V++]=B&255;return D===2&&(B=t[g.charCodeAt(M)]<<2|t[g.charCodeAt(M+1)]>>4,U[V++]=B&255),D===1&&(B=t[g.charCodeAt(M)]<<10|t[g.charCodeAt(M+1)]<<4|t[g.charCodeAt(M+2)]>>2,U[V++]=B>>8&255,U[V++]=B&255),U}function A(g){return l[g>>18&63]+l[g>>12&63]+l[g>>6&63]+l[g&63]}function L(g,B,R){for(var _,D=[],U=B;U<R;U+=3)_=(g[U]<<16&16711680)+(g[U+1]<<8&65280)+(g[U+2]&255),D.push(A(_));return D.join("")}function q(g){for(var B,R=g.length,_=R%3,D=[],U=16383,V=0,G=R-_;V<G;V+=U)D.push(L(g,V,V+U>G?G:V+U));return _===1?(B=g[R-1],D.push(l[B>>2]+l[B<<4&63]+"==")):_===2&&(B=(g[R-2]<<8)+g[R-1],D.push(l[B>>10]+l[B>>4&63]+l[B<<2&63]+"=")),D.join("")}return oe}function zt(){if(ct)return xe;ct=!0;return xe.read=function(l,t,o,u,c){var h,s,w=c*8-u-1,E=(1<<w)-1,$=E>>1,A=-7,L=o?c-1:0,q=o?-1:1,g=l[t+L];for(L+=q,h=g&(1<<-A)-1,g>>=-A,A+=w;A>0;h=h*256+l[t+L],L+=q,A-=8);for(s=h&(1<<-A)-1,h>>=-A,A+=u;A>0;s=s*256+l[t+L],L+=q,A-=8);if(h===0)h=1-$;else{if(h===E)return s?NaN:(g?-1:1)*(1/0);s=s+Math.pow(2,u),h=h-$}return(g?-1:1)*s*Math.pow(2,h-u)},xe.write=function(l,t,o,u,c,h){var s,w,E,$=h*8-c-1,A=(1<<$)-1,L=A>>1,q=c===23?Math.pow(2,-24)-Math.pow(2,-77):0,g=u?0:h-1,B=u?1:-1,R=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(w=isNaN(t)?1:0,s=A):(s=Math.floor(Math.log(t)/Math.LN2),t*(E=Math.pow(2,-s))<1&&(s--,E*=2),s+L>=1?t+=q/E:t+=q*Math.pow(2,1-L),t*E>=2&&(s++,E/=2),s+L>=A?(w=0,s=A):s+L>=1?(w=(t*E-1)*Math.pow(2,c),s=s+L):(w=t*Math.pow(2,L-1)*Math.pow(2,c),s=0));c>=8;l[o+g]=w&255,g+=B,w/=256,c-=8);for(s=s<<c|w,$+=c;$>0;l[o+g]=s&255,g+=B,s/=256,$-=8);l[o+g-B]|=R*128},xe}function ht(){if(ft)return Q;ft=!0;let l=Wt(),t=zt(),o=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Q.Buffer=s,Q.SlowBuffer=D,Q.INSPECT_MAX_BYTES=50;let u=2147483647;Q.kMaxLength=u,s.TYPED_ARRAY_SUPPORT=c(),!s.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function c(){try{let n=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(n,e),n.foo()===42}catch{return!1}}Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}});function h(n){if(n>u)throw new RangeError('The value "'+n+'" is invalid for option "size"');let e=new Uint8Array(n);return Object.setPrototypeOf(e,s.prototype),e}function s(n,e,r){if(typeof n=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return A(n)}return w(n,e,r)}s.poolSize=8192;function w(n,e,r){if(typeof n=="string")return L(n,e);if(ArrayBuffer.isView(n))return g(n);if(n==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n);if(z(n,ArrayBuffer)||n&&z(n.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(z(n,SharedArrayBuffer)||n&&z(n.buffer,SharedArrayBuffer)))return B(n,e,r);if(typeof n=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=n.valueOf&&n.valueOf();if(i!=null&&i!==n)return s.from(i,e,r);let a=R(n);if(a)return a;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof n[Symbol.toPrimitive]=="function")return s.from(n[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n)}s.from=function(n,e,r){return w(n,e,r)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array);function E(n){if(typeof n!="number")throw new TypeError('"size" argument must be of type number');if(n<0)throw new RangeError('The value "'+n+'" is invalid for option "size"')}function $(n,e,r){return E(n),n<=0?h(n):e!==void 0?typeof r=="string"?h(n).fill(e,r):h(n).fill(e):h(n)}s.alloc=function(n,e,r){return $(n,e,r)};function A(n){return E(n),h(n<0?0:_(n)|0)}s.allocUnsafe=function(n){return A(n)},s.allocUnsafeSlow=function(n){return A(n)};function L(n,e){if((typeof e!="string"||e==="")&&(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=U(n,e)|0,i=h(r),a=i.write(n,e);return a!==r&&(i=i.slice(0,a)),i}function q(n){let e=n.length<0?0:_(n.length)|0,r=h(e);for(let i=0;i<e;i+=1)r[i]=n[i]&255;return r}function g(n){if(z(n,Uint8Array)){let e=new Uint8Array(n);return B(e.buffer,e.byteOffset,e.byteLength)}return q(n)}function B(n,e,r){if(e<0||n.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(n.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let i;return e===void 0&&r===void 0?i=new Uint8Array(n):r===void 0?i=new Uint8Array(n,e):i=new Uint8Array(n,e,r),Object.setPrototypeOf(i,s.prototype),i}function R(n){if(s.isBuffer(n)){let e=_(n.length)|0,r=h(e);return r.length===0||n.copy(r,0,0,e),r}if(n.length!==void 0)return typeof n.length!="number"||Ne(n.length)?h(0):q(n);if(n.type==="Buffer"&&Array.isArray(n.data))return q(n.data)}function _(n){if(n>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return n|0}function D(n){return+n!=n&&(n=0),s.alloc(+n)}s.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==s.prototype},s.compare=function(e,r){if(z(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),z(r,Uint8Array)&&(r=s.from(r,r.offset,r.byteLength)),!s.isBuffer(e)||!s.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let i=e.length,a=r.length;for(let p=0,f=Math.min(i,a);p<f;++p)if(e[p]!==r[p]){i=e[p],a=r[p];break}return i<a?-1:a<i?1:0},s.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return s.alloc(0);let i;if(r===void 0)for(r=0,i=0;i<e.length;++i)r+=e[i].length;let a=s.allocUnsafe(r),p=0;for(i=0;i<e.length;++i){let f=e[i];if(z(f,Uint8Array))p+f.length>a.length?(s.isBuffer(f)||(f=s.from(f)),f.copy(a,p)):Uint8Array.prototype.set.call(a,f,p);else if(s.isBuffer(f))f.copy(a,p);else throw new TypeError('"list" argument must be an Array of Buffers');p+=f.length}return a};function U(n,e){if(s.isBuffer(n))return n.length;if(ArrayBuffer.isView(n)||z(n,ArrayBuffer))return n.byteLength;if(typeof n!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof n);let r=n.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&r===0)return 0;let a=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Pe(n).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return We(n).length;default:if(a)return i?-1:Pe(n).length;e=(""+e).toLowerCase(),a=!0}}s.byteLength=U;function V(n,e,r){let i=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(n||(n="utf8");;)switch(n){case"hex":return Ut(this,e,r);case"utf8":case"utf-8":return Le(this,e,r);case"ascii":return Ct(this,e,r);case"latin1":case"binary":return Ft(this,e,r);case"base64":return Nt(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _t(this,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(n+"").toLowerCase(),i=!0}}s.prototype._isBuffer=!0;function G(n,e,r){let i=n[e];n[e]=n[r],n[r]=i}s.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)G(this,r,r+1);return this},s.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)G(this,r,r+3),G(this,r+1,r+2);return this},s.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)G(this,r,r+7),G(this,r+1,r+6),G(this,r+2,r+5),G(this,r+3,r+4);return this},s.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Le(this,0,e):V.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(e){if(!s.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:s.compare(this,e)===0},s.prototype.inspect=function(){let e="",r=Q.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},o&&(s.prototype[o]=s.prototype.inspect),s.prototype.compare=function(e,r,i,a,p){if(z(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),i===void 0&&(i=e?e.length:0),a===void 0&&(a=0),p===void 0&&(p=this.length),r<0||i>e.length||a<0||p>this.length)throw new RangeError("out of range index");if(a>=p&&r>=i)return 0;if(a>=p)return-1;if(r>=i)return 1;if(r>>>=0,i>>>=0,a>>>=0,p>>>=0,this===e)return 0;let f=p-a,x=i-r,T=Math.min(f,x),S=this.slice(a,p),C=e.slice(r,i);for(let v=0;v<T;++v)if(S[v]!==C[v]){f=S[v],x=C[v];break}return f<x?-1:x<f?1:0};function M(n,e,r,i,a){if(n.length===0)return-1;if(typeof r=="string"?(i=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,Ne(r)&&(r=a?0:n.length-1),r<0&&(r=n.length+r),r>=n.length){if(a)return-1;r=n.length-1}else if(r<0)if(a)r=0;else return-1;if(typeof e=="string"&&(e=s.from(e,i)),s.isBuffer(e))return e.length===0?-1:ke(n,e,r,i,a);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?a?Uint8Array.prototype.indexOf.call(n,e,r):Uint8Array.prototype.lastIndexOf.call(n,e,r):ke(n,[e],r,i,a);throw new TypeError("val must be string, number or Buffer")}function ke(n,e,r,i,a){let p=1,f=n.length,x=e.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(n.length<2||e.length<2)return-1;p=2,f/=2,x/=2,r/=2}function T(C,v){return p===1?C[v]:C.readUInt16BE(v*p)}let S;if(a){let C=-1;for(S=r;S<f;S++)if(T(n,S)===T(e,C===-1?0:S-C)){if(C===-1&&(C=S),S-C+1===x)return C*p}else C!==-1&&(S-=S-C),C=-1}else for(r+x>f&&(r=f-x),S=r;S>=0;S--){let C=!0;for(let v=0;v<x;v++)if(T(n,S+v)!==T(e,v)){C=!1;break}if(C)return S}return-1}s.prototype.includes=function(e,r,i){return this.indexOf(e,r,i)!==-1},s.prototype.indexOf=function(e,r,i){return M(this,e,r,i,!0)},s.prototype.lastIndexOf=function(e,r,i){return M(this,e,r,i,!1)};function Rt(n,e,r,i){r=Number(r)||0;let a=n.length-r;i?(i=Number(i),i>a&&(i=a)):i=a;let p=e.length;i>p/2&&(i=p/2);let f;for(f=0;f<i;++f){let x=parseInt(e.substr(f*2,2),16);if(Ne(x))return f;n[r+f]=x}return f}function bt(n,e,r,i){return ye(Pe(e,n.length-r),n,r,i)}function At(n,e,r,i){return ye(Ot(e),n,r,i)}function St(n,e,r,i){return ye(We(e),n,r,i)}function Pt(n,e,r,i){return ye(Mt(e,n.length-r),n,r,i)}s.prototype.write=function(e,r,i,a){if(r===void 0)a="utf8",i=this.length,r=0;else if(i===void 0&&typeof r=="string")a=r,i=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(i)?(i=i>>>0,a===void 0&&(a="utf8")):(a=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let p=this.length-r;if((i===void 0||i>p)&&(i=p),e.length>0&&(i<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");a||(a="utf8");let f=!1;for(;;)switch(a){case"hex":return Rt(this,e,r,i);case"utf8":case"utf-8":return bt(this,e,r,i);case"ascii":case"latin1":case"binary":return At(this,e,r,i);case"base64":return St(this,e,r,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Pt(this,e,r,i);default:if(f)throw new TypeError("Unknown encoding: "+a);a=(""+a).toLowerCase(),f=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Nt(n,e,r){return e===0&&r===n.length?l.fromByteArray(n):l.fromByteArray(n.slice(e,r))}function Le(n,e,r){r=Math.min(n.length,r);let i=[],a=e;for(;a<r;){let p=n[a],f=null,x=p>239?4:p>223?3:p>191?2:1;if(a+x<=r){let T,S,C,v;switch(x){case 1:p<128&&(f=p);break;case 2:T=n[a+1],(T&192)===128&&(v=(p&31)<<6|T&63,v>127&&(f=v));break;case 3:T=n[a+1],S=n[a+2],(T&192)===128&&(S&192)===128&&(v=(p&15)<<12|(T&63)<<6|S&63,v>2047&&(v<55296||v>57343)&&(f=v));break;case 4:T=n[a+1],S=n[a+2],C=n[a+3],(T&192)===128&&(S&192)===128&&(C&192)===128&&(v=(p&15)<<18|(T&63)<<12|(S&63)<<6|C&63,v>65535&&v<1114112&&(f=v))}}f===null?(f=65533,x=1):f>65535&&(f-=65536,i.push(f>>>10&1023|55296),f=56320|f&1023),i.push(f),a+=x}return Tt(i)}let $e=4096;function Tt(n){let e=n.length;if(e<=$e)return String.fromCharCode.apply(String,n);let r="",i=0;for(;i<e;)r+=String.fromCharCode.apply(String,n.slice(i,i+=$e));return r}function Ct(n,e,r){let i="";r=Math.min(n.length,r);for(let a=e;a<r;++a)i+=String.fromCharCode(n[a]&127);return i}function Ft(n,e,r){let i="";r=Math.min(n.length,r);for(let a=e;a<r;++a)i+=String.fromCharCode(n[a]);return i}function Ut(n,e,r){let i=n.length;(!e||e<0)&&(e=0),(!r||r<0||r>i)&&(r=i);let a="";for(let p=e;p<r;++p)a+=Dt[n[p]];return a}function _t(n,e,r){let i=n.slice(e,r),a="";for(let p=0;p<i.length-1;p+=2)a+=String.fromCharCode(i[p]+i[p+1]*256);return a}s.prototype.slice=function(e,r){let i=this.length;e=~~e,r=r===void 0?i:~~r,e<0?(e+=i,e<0&&(e=0)):e>i&&(e=i),r<0?(r+=i,r<0&&(r=0)):r>i&&(r=i),r<e&&(r=e);let a=this.subarray(e,r);return Object.setPrototypeOf(a,s.prototype),a};function k(n,e,r){if(n%1!==0||n<0)throw new RangeError("offset is not uint");if(n+e>r)throw new RangeError("Trying to access beyond buffer length")}s.prototype.readUintLE=s.prototype.readUIntLE=function(e,r,i){e=e>>>0,r=r>>>0,i||k(e,r,this.length);let a=this[e],p=1,f=0;for(;++f<r&&(p*=256);)a+=this[e+f]*p;return a},s.prototype.readUintBE=s.prototype.readUIntBE=function(e,r,i){e=e>>>0,r=r>>>0,i||k(e,r,this.length);let a=this[e+--r],p=1;for(;r>0&&(p*=256);)a+=this[e+--r]*p;return a},s.prototype.readUint8=s.prototype.readUInt8=function(e,r){return e=e>>>0,r||k(e,1,this.length),this[e]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||k(e,2,this.length),this[e]|this[e+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||k(e,2,this.length),this[e]<<8|this[e+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||k(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||k(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},s.prototype.readBigUInt64LE=Y(function(e){e=e>>>0,re(e,"offset");let r=this[e],i=this[e+7];(r===void 0||i===void 0)&&ie(e,this.length-8);let a=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,p=this[++e]+this[++e]*2**8+this[++e]*2**16+i*2**24;return BigInt(a)+(BigInt(p)<<BigInt(32))}),s.prototype.readBigUInt64BE=Y(function(e){e=e>>>0,re(e,"offset");let r=this[e],i=this[e+7];(r===void 0||i===void 0)&&ie(e,this.length-8);let a=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],p=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i;return(BigInt(a)<<BigInt(32))+BigInt(p)}),s.prototype.readIntLE=function(e,r,i){e=e>>>0,r=r>>>0,i||k(e,r,this.length);let a=this[e],p=1,f=0;for(;++f<r&&(p*=256);)a+=this[e+f]*p;return p*=128,a>=p&&(a-=Math.pow(2,8*r)),a},s.prototype.readIntBE=function(e,r,i){e=e>>>0,r=r>>>0,i||k(e,r,this.length);let a=r,p=1,f=this[e+--a];for(;a>0&&(p*=256);)f+=this[e+--a]*p;return p*=128,f>=p&&(f-=Math.pow(2,8*r)),f},s.prototype.readInt8=function(e,r){return e=e>>>0,r||k(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},s.prototype.readInt16LE=function(e,r){e=e>>>0,r||k(e,2,this.length);let i=this[e]|this[e+1]<<8;return i&32768?i|4294901760:i},s.prototype.readInt16BE=function(e,r){e=e>>>0,r||k(e,2,this.length);let i=this[e+1]|this[e]<<8;return i&32768?i|4294901760:i},s.prototype.readInt32LE=function(e,r){return e=e>>>0,r||k(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},s.prototype.readInt32BE=function(e,r){return e=e>>>0,r||k(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},s.prototype.readBigInt64LE=Y(function(e){e=e>>>0,re(e,"offset");let r=this[e],i=this[e+7];(r===void 0||i===void 0)&&ie(e,this.length-8);let a=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(i<<24);return(BigInt(a)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)}),s.prototype.readBigInt64BE=Y(function(e){e=e>>>0,re(e,"offset");let r=this[e],i=this[e+7];(r===void 0||i===void 0)&&ie(e,this.length-8);let a=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(a)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i)}),s.prototype.readFloatLE=function(e,r){return e=e>>>0,r||k(e,4,this.length),t.read(this,e,!0,23,4)},s.prototype.readFloatBE=function(e,r){return e=e>>>0,r||k(e,4,this.length),t.read(this,e,!1,23,4)},s.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||k(e,8,this.length),t.read(this,e,!0,52,8)},s.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||k(e,8,this.length),t.read(this,e,!1,52,8)};function j(n,e,r,i,a,p){if(!s.isBuffer(n))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>a||e<p)throw new RangeError('"value" argument is out of bounds');if(r+i>n.length)throw new RangeError("Index out of range")}s.prototype.writeUintLE=s.prototype.writeUIntLE=function(e,r,i,a){if(e=+e,r=r>>>0,i=i>>>0,!a){let x=Math.pow(2,8*i)-1;j(this,e,r,i,x,0)}let p=1,f=0;for(this[r]=e&255;++f<i&&(p*=256);)this[r+f]=e/p&255;return r+i},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(e,r,i,a){if(e=+e,r=r>>>0,i=i>>>0,!a){let x=Math.pow(2,8*i)-1;j(this,e,r,i,x,0)}let p=i-1,f=1;for(this[r+p]=e&255;--p>=0&&(f*=256);)this[r+p]=e/f&255;return r+i},s.prototype.writeUint8=s.prototype.writeUInt8=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,1,255,0),this[r]=e&255,r+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function Oe(n,e,r,i,a){qe(e,i,a,n,r,7);let p=Number(e&BigInt(4294967295));n[r++]=p,p=p>>8,n[r++]=p,p=p>>8,n[r++]=p,p=p>>8,n[r++]=p;let f=Number(e>>BigInt(32)&BigInt(4294967295));return n[r++]=f,f=f>>8,n[r++]=f,f=f>>8,n[r++]=f,f=f>>8,n[r++]=f,r}function Me(n,e,r,i,a){qe(e,i,a,n,r,7);let p=Number(e&BigInt(4294967295));n[r+7]=p,p=p>>8,n[r+6]=p,p=p>>8,n[r+5]=p,p=p>>8,n[r+4]=p;let f=Number(e>>BigInt(32)&BigInt(4294967295));return n[r+3]=f,f=f>>8,n[r+2]=f,f=f>>8,n[r+1]=f,f=f>>8,n[r]=f,r+8}s.prototype.writeBigUInt64LE=Y(function(e,r=0){return Oe(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))}),s.prototype.writeBigUInt64BE=Y(function(e,r=0){return Me(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))}),s.prototype.writeIntLE=function(e,r,i,a){if(e=+e,r=r>>>0,!a){let T=Math.pow(2,8*i-1);j(this,e,r,i,T-1,-T)}let p=0,f=1,x=0;for(this[r]=e&255;++p<i&&(f*=256);)e<0&&x===0&&this[r+p-1]!==0&&(x=1),this[r+p]=(e/f>>0)-x&255;return r+i},s.prototype.writeIntBE=function(e,r,i,a){if(e=+e,r=r>>>0,!a){let T=Math.pow(2,8*i-1);j(this,e,r,i,T-1,-T)}let p=i-1,f=1,x=0;for(this[r+p]=e&255;--p>=0&&(f*=256);)e<0&&x===0&&this[r+p+1]!==0&&(x=1),this[r+p]=(e/f>>0)-x&255;return r+i},s.prototype.writeInt8=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1},s.prototype.writeInt16LE=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2},s.prototype.writeInt16BE=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2},s.prototype.writeInt32LE=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4},s.prototype.writeInt32BE=function(e,r,i){return e=+e,r=r>>>0,i||j(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4},s.prototype.writeBigInt64LE=Y(function(e,r=0){return Oe(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),s.prototype.writeBigInt64BE=Y(function(e,r=0){return Me(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function De(n,e,r,i,a,p){if(r+i>n.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Ve(n,e,r,i,a){return e=+e,r=r>>>0,a||De(n,e,r,4),t.write(n,e,r,i,23,4),r+4}s.prototype.writeFloatLE=function(e,r,i){return Ve(this,e,r,!0,i)},s.prototype.writeFloatBE=function(e,r,i){return Ve(this,e,r,!1,i)};function je(n,e,r,i,a){return e=+e,r=r>>>0,a||De(n,e,r,8),t.write(n,e,r,i,52,8),r+8}s.prototype.writeDoubleLE=function(e,r,i){return je(this,e,r,!0,i)},s.prototype.writeDoubleBE=function(e,r,i){return je(this,e,r,!1,i)},s.prototype.copy=function(e,r,i,a){if(!s.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),!a&&a!==0&&(a=this.length),r>=e.length&&(r=e.length),r||(r=0),a>0&&a<i&&(a=i),a===i||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(a<0)throw new RangeError("sourceEnd out of bounds");a>this.length&&(a=this.length),e.length-r<a-i&&(a=e.length-r+i);let p=a-i;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,i,a):Uint8Array.prototype.set.call(e,this.subarray(i,a),r),p},s.prototype.fill=function(e,r,i,a){if(typeof e=="string"){if(typeof r=="string"?(a=r,r=0,i=this.length):typeof i=="string"&&(a=i,i=this.length),a!==void 0&&typeof a!="string")throw new TypeError("encoding must be a string");if(typeof a=="string"&&!s.isEncoding(a))throw new TypeError("Unknown encoding: "+a);if(e.length===1){let f=e.charCodeAt(0);(a==="utf8"&&f<128||a==="latin1")&&(e=f)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<i)throw new RangeError("Out of range index");if(i<=r)return this;r=r>>>0,i=i===void 0?this.length:i>>>0,e||(e=0);let p;if(typeof e=="number")for(p=r;p<i;++p)this[p]=e;else{let f=s.isBuffer(e)?e:s.from(e,a),x=f.length;if(x===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(p=0;p<i-r;++p)this[p+r]=f[p%x]}return this};let ee={};function Se(n,e,r){ee[n]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${n}]`,this.stack,delete this.name}get code(){return n}set code(a){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:a,writable:!0})}toString(){return`${this.name} [${n}]: ${this.message}`}}}Se("ERR_BUFFER_OUT_OF_BOUNDS",function(n){return n?`${n} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Se("ERR_INVALID_ARG_TYPE",function(n,e){return`The "${n}" argument must be of type number. Received type ${typeof e}`},TypeError),Se("ERR_OUT_OF_RANGE",function(n,e,r){let i=`The value of "${n}" is out of range.`,a=r;return Number.isInteger(r)&&Math.abs(r)>2**32?a=Ge(String(r)):typeof r=="bigint"&&(a=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(a=Ge(a)),a+="n"),i+=` It must be ${e}. Received ${a}`,i},RangeError);function Ge(n){let e="",r=n.length,i=n[0]==="-"?1:0;for(;r>=i+4;r-=3)e=`_${n.slice(r-3,r)}${e}`;return`${n.slice(0,r)}${e}`}function kt(n,e,r){re(e,"offset"),(n[e]===void 0||n[e+r]===void 0)&&ie(e,n.length-(r+1))}function qe(n,e,r,i,a,p){if(n>r||n<e){let f=typeof e=="bigint"?"n":"",x;throw e===0||e===BigInt(0)?x=`>= 0${f} and < 2${f} ** ${(p+1)*8}${f}`:x=`>= -(2${f} ** ${(p+1)*8-1}${f}) and < 2 ** ${(p+1)*8-1}${f}`,new ee.ERR_OUT_OF_RANGE("value",x,n)}kt(i,a,p)}function re(n,e){if(typeof n!="number")throw new ee.ERR_INVALID_ARG_TYPE(e,"number",n)}function ie(n,e,r){throw Math.floor(n)!==n?(re(n,r),new ee.ERR_OUT_OF_RANGE("offset","an integer",n)):e<0?new ee.ERR_BUFFER_OUT_OF_BOUNDS:new ee.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,n)}let Lt=/[^+/0-9A-Za-z-_]/g;function $t(n){if(n=n.split("=")[0],n=n.trim().replace(Lt,""),n.length<2)return"";for(;n.length%4!==0;)n=n+"=";return n}function Pe(n,e){e=e||1/0;let r,i=n.length,a=null,p=[];for(let f=0;f<i;++f){if(r=n.charCodeAt(f),r>55295&&r<57344){if(!a){if(r>56319){(e-=3)>-1&&p.push(239,191,189);continue}else if(f+1===i){(e-=3)>-1&&p.push(239,191,189);continue}a=r;continue}if(r<56320){(e-=3)>-1&&p.push(239,191,189),a=r;continue}r=(a-55296<<10|r-56320)+65536}else a&&(e-=3)>-1&&p.push(239,191,189);if(a=null,r<128){if((e-=1)<0)break;p.push(r)}else if(r<2048){if((e-=2)<0)break;p.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;p.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;p.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return p}function Ot(n){let e=[];for(let r=0;r<n.length;++r)e.push(n.charCodeAt(r)&255);return e}function Mt(n,e){let r,i,a,p=[];for(let f=0;f<n.length&&!((e-=2)<0);++f)r=n.charCodeAt(f),i=r>>8,a=r%256,p.push(a),p.push(i);return p}function We(n){return l.toByteArray($t(n))}function ye(n,e,r,i){let a;for(a=0;a<i&&!(a+r>=e.length||a>=n.length);++a)e[a+r]=n[a];return a}function z(n,e){return n instanceof e||n!=null&&n.constructor!=null&&n.constructor.name!=null&&n.constructor.name===e.name}function Ne(n){return n!==n}let Dt=(function(){let n="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let i=r*16;for(let a=0;a<16;++a)e[i+a]=n[r]+n[a]}return e})();function Y(n){return typeof BigInt>"u"?Vt:n}function Vt(){throw new Error("BigInt not supported")}return Q}var oe,lt,xe,ct,Q,ft,dt=te(()=>{"use strict";d();y();m();oe={},lt=!1;xe={},ct=!1;Q={},ft=!1});var Z,P,gn,wn,mt=te(()=>{"use strict";d();y();m();dt();Z=ht();Z.Buffer;Z.SlowBuffer;Z.INSPECT_MAX_BYTES;Z.kMaxLength;P=Z.Buffer,gn=Z.INSPECT_MAX_BYTES,wn=Z.kMaxLength});var y=te(()=>{"use strict";mt()});d();y();m();d();y();m();d();y();m();d();y();m();function W(l){throw new Error("Unexpected value: "+JSON.stringify(l))}d();y();m();function se(l){return Object.keys(l)}d();y();m();d();y();m();d();y();m();var ae=b.env.FERN_STACK_TRACK?.toLowerCase()??"",Ht=ae!==""&&ae!=="0"&&ae!=="false",zn=["single","multiline","box"].includes(ae)?ae:"single";Ht&&(Error.stackTraceLimit=50);var Jt;function yt(l){Jt?.tag(l)}var Be=class{constructor(){yt(this)}};d();y();m();var ue=class extends Be{constructor(o){super();I(this,"value");this.value=o}write(o){typeof this.value=="string"?o.write(this.value):typeof this.value=="function"?this.value(o):this.value.write(o)}};d();y();m();d();y();m();d();y();m();var pe=class{constructor(){I(this,"reporter");I(this,"snippet");I(this,"err");this.snippet=void 0,this.reporter=void 0,this.err=void 0}update({context:t,snippet:o}){this.shouldUpdate({snippet:o,reporter:t.errors})&&(this.reporter=t.errors.clone(),this.snippet=o)}getResponseOrThrow({endpoint:t}){if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw this.err??new Error(`Failed to generate snippet for endpoint "${t.method} ${t.path}"`)}shouldUpdate({snippet:t,reporter:o}){return this.reporter==null||this.reporter.size()>0&&o.size()===0?!0:t.length>(this.snippet?.length??0)}};var le=class{constructor(t){I(this,"context");this.context=t}async generate(t,o={}){let u=this.resolveEndpoints({request:t,options:o});if(u.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let c=new pe;for(let h of u){let s=this.context.clone(),w=this.createSnippetGenerator(s);try{let E=await w.generateSnippet({endpoint:h,request:t,options:o});if(s.errors.empty())return{snippet:E,errors:void 0};c.update({context:s,snippet:E})}catch(E){c.err==null&&(c.err=E)}}return c.getResponseOrThrow({endpoint:t.endpoint})}async generateSnippetAst(t,o={}){let u=this.resolveEndpoints({request:t,options:o});if(u.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let c;for(let h of u){let s=this.context.clone(),w=this.createSnippetGenerator(s);try{return await w.generateSnippetAst({endpoint:h,request:t,options:o})}catch(E){c=E}}throw c??new Error(`Failed to generate snippet AST for endpoint: ${t.endpoint.method} ${t.endpoint.path}`)}generateSync(t,o={}){let u=this.resolveEndpoints({request:t,options:o});if(u.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let c=new pe;for(let h of u){let s=this.context.clone(),w=this.createSnippetGenerator(s);try{let E=w.generateSnippetSync({endpoint:h,request:t,options:o});if(s.errors.empty())return{snippet:E,errors:void 0};c.update({context:s,snippet:E})}catch(E){c.err==null&&(c.err=E)}}return c.getResponseOrThrow({endpoint:t.endpoint})}resolveEndpoints({request:t,options:o}){if(o.endpointId!=null){let u=this.context.resolveEndpointById(o.endpointId);if(u==null)throw new Error(`No endpoint found with ID "${o.endpointId}"`);return[u]}return this.context.resolveEndpointLocationOrThrow(t.endpoint)}};d();y();m();d();y();m();d();y();m();var ce=class{constructor(){I(this,"REFERENCE_REGEX",/^(?:(\w+)::)?(GET|POST|PUT|DELETE|PATCH|HEAD)\s(\/\S*)$/)}validate(t){return this.REFERENCE_REGEX.test(t)?{type:"valid"}:{type:"invalid"}}tryParse(t){if(this.validate(t).type==="invalid")return;let u=t.match(this.REFERENCE_REGEX);if(!(u==null||u[2]==null||u[3]==null))return{namespace:u[1],method:u[2],path:u[3]}}};d();y();m();var N={Critical:"CRITICAL",Warning:"WARNING"},fe=class l{constructor(){I(this,"errors");I(this,"path");this.errors=[],this.path=[]}add(t){this.errors.push({...t,path:[...this.path]})}scope(t){this.path.push(t)}unscope(){this.path.pop()}getBySeverity(t){return this.errors.filter(o=>o.severity===t)}empty(){return this.errors.length===0}size(){return this.errors.length}truncate(t){this.errors.length=t}clone(){let t=new l;return t.errors=[...this.errors],t.path=[...this.path],t}reset(){this.errors=[],this.path=[]}toDynamicSnippetErrors(){return this.errors.map(t=>({severity:t.severity,path:t.path!=null?this.pathToStringArray(t.path):void 0,message:t.message}))}pathToStringArray(t){let o=[];for(let u of t){if(typeof u=="string"){o.push(u);continue}o[o.length-1]+=`[${u.index}]`}return o}};var he=class{constructor({ir:t,config:o,options:u={}}){I(this,"config");I(this,"options");I(this,"errors");I(this,"_ir");I(this,"httpEndpointReferenceParser");this._ir=t,this.config=o,this.options=u,this.errors=new fe,this.httpEndpointReferenceParser=new ce}associateQueryParametersByWireValue({parameters:t,values:o}){let u=[];for(let[c,h]of Object.entries(o))if(h!==void 0){this.errors.scope(c);try{let s=t.find(E=>E.name.wireValue===c);if(s==null)throw this.newParameterNotRecognizedError(c);let w=this.isListTypeReference(s.typeReference)&&!Array.isArray(h)?[h]:h;u.push({name:s.name,typeReference:s.typeReference,value:w})}finally{this.errors.unscope()}}return u}associateByWireValueOrDefault({parameters:t,values:o}){let u=[];for(let c of t){this.errors.scope(c.name.wireValue);try{let h=o[c.name.wireValue];if(h==null)if(c.typeReference.type==="primitive"&&c.typeReference.value==="STRING")h=`<${c.name.wireValue}>`;else{this.errors.add({severity:N.Critical,message:this.newParameterNotRecognizedError(c.name.wireValue).message});continue}u.push({name:c.name,typeReference:c.typeReference,value:h})}finally{this.errors.unscope()}}return u}associateByWireValue({parameters:t,values:o,ignoreMissingParameters:u}){let c=[],h=new Set;for(let s of t){let w=s.name.wireValue,E=o[w];if(E!==void 0){h.add(w),this.errors.scope(w);try{c.push({name:s.name,typeReference:s.typeReference,value:E})}finally{this.errors.unscope()}}}if(!u){for(let[s,w]of Object.entries(o))if(!(w===void 0||h.has(s))){this.errors.scope(s);try{this.errors.add({severity:N.Critical,message:this.newParameterNotRecognizedError(s).message})}finally{this.errors.unscope()}}}return c}getExampleObjectProperties({parameters:t,snippetObject:o}){let u=typeof o=="object"&&o!==null&&!Array.isArray(o)?o:{},c=[];for(let h of t){let s=u[h.name.wireValue];s==null?h.typeReference.type==="nullable"&&c.push({name:h.name,typeReference:h.typeReference,value:null}):c.push({name:h.name,typeReference:h.typeReference,value:s})}return c}getSingleFileValue({property:t,record:o}){let u=o[t.wireValue];if(u!=null){if(typeof u!="string"){this.errors.add({severity:N.Critical,message:`Expected file value to be a string, got ${typeof u}`});return}return u}}getFileArrayValues({property:t,record:o}){let u=o[t.wireValue];if(u==null)return;if(!Array.isArray(u)){this.errors.add({severity:N.Critical,message:`Expected file array value to be an array of strings, got ${typeof u}`});return}let c=[];for(let h of u){if(typeof h!="string"){this.errors.add({severity:N.Critical,message:`Expected file array value to be an array of strings, got ${typeof h}`});return}c.push(h)}return c}getRecord(t){if(typeof t!="object"||Array.isArray(t)){this.errors.add({severity:N.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(t)?"array":typeof t}`});return}return t??{}}resolveNamedType({typeId:t}){let o=this._ir.types[t];if(o==null){this.errors.add({severity:N.Critical,message:`Type identified by "${t}" could not be found`});return}return o}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:o}){let u=this.getRecord(o);if(u==null)return;let c=t.discriminant.wireValue,h=u[c];if(h==null){this.errors.add({severity:N.Critical,message:this.newParameterNotRecognizedError(c).message});return}if(typeof h!="string"){this.errors.add({severity:N.Critical,message:`Expected discriminant value to be a string but got: ${typeof h}`});return}let s=t.types[h];if(s==null){this.errors.add({severity:N.Critical,message:`No type found for discriminant value "${h}"`});return}let{[c]:w,...E}=u;return{singleDiscriminatedUnionType:s,discriminantValue:s.discriminantValue,value:E}}resolveEndpointOrThrow(t){let o=this.httpEndpointReferenceParser.tryParse(t);if(o==null)throw new Error(`Failed to parse endpoint reference "${t}"`);return this.resolveEndpointLocationOrThrow(o)}resolveEndpointLocation(t){let o=[];for(let u of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:u,parsedEndpoint:t})&&o.push(u);return o}resolveEndpointLocationOrThrow(t){let o=this.resolveEndpointLocation(t);if(o.length===0)throw new Error(`Failed to find endpoint identified by "${t.method} ${t.path}"`);return o}resolveEndpointById(t){return this._ir.endpoints[t]}resolveEndpointByIdOrThrow(t){let o=this.resolveEndpointById(t);if(o==null)throw new Error(`Failed to find endpoint with ID "${t}"`);return o}needsRequestParameter({request:t,inlinePathParameters:o,inlineFileProperties:u}){return this.includePathParametersInWrappedRequest({request:t,inlinePathParameters:o})||t.queryParameters!=null&&t.queryParameters.length>0||t.headers!=null&&t.headers.length>0?!0:t.body!=null?this.includeRequestBodyInWrappedRequest({body:t.body,inlineFileProperties:u}):!t.metadata?.onlyPathParameters}includePathParametersInWrappedRequest({request:t,inlinePathParameters:o}){return o&&(t.metadata?.includePathParameters??!1)}isFileUploadRequestBody(t){switch(t.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:W(t)}}resolveEnvironmentName(t){if(this._ir.environments==null)return;let o=this._ir.environments.environments;switch(o.type){case"singleBaseUrl":{let u=o.environments.find(c=>c.id===t);return u?.name}case"multipleBaseUrls":{let u=o.environments.find(c=>c.id===t);return u?.name}default:W(o)}}isSingleEnvironmentID(t){return typeof t=="string"}isMultiEnvironmentValues(t){return typeof t=="object"}validateMultiEnvironmentUrlValues(t){if(this._ir.environments==null)return this.errors.add({severity:N.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;let o=this._ir.environments.environments;switch(o.type){case"singleBaseUrl":return this.errors.add({severity:N.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let u=o.environments[0];if(u==null)return this.errors.add({severity:N.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let c=new Set(se(u.urls));for(let h of se(t))c.has(h)&&c.delete(h);return c.size>0?(this.errors.add({severity:N.Critical,message:`The provided environments are invalid; got: [${Object.keys(t).join(", ")}], expected: [${se(u.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:t}){if(typeof t!="number"){this.errors.add({severity:N.Critical,message:this.newTypeMismatchError({expected:"number",value:t}).message});return}return t}getValueAsBoolean({value:t}){if(typeof t!="boolean"){this.errors.add({severity:N.Critical,message:this.newTypeMismatchError({expected:"boolean",value:t}).message});return}return t}getValueAsString({value:t}){if(typeof t!="string"){this.errors.add({severity:N.Critical,message:this.newTypeMismatchError({expected:"string",value:t}).message});return}return t}isOptional(t){switch(t.type){case"nullable":return this.isOptional(t.value);case"optional":return!0;case"named":{let o=this.resolveNamedType({typeId:t.value});return o==null?!1:o.type==="alias"?this.isNullable(o.typeReference):!1}}return!1}isNullable(t){switch(t.type){case"nullable":return!0;case"optional":return this.isNullable(t.value);case"named":{let o=this.resolveNamedType({typeId:t.value});return o==null?!1:o.type==="alias"?this.isNullable(o.typeReference):!1}}return!1}newAuthMismatchError({auth:t,values:o}){return new Error(`Expected auth type ${t.type}, got ${o.type}`)}newParameterNotRecognizedError(t){return new Error(`"${t}" is not a recognized parameter for this endpoint`)}newTypeMismatchError({expected:t,value:o}){return new Error(`Expected ${t}, got ${typeof o}`)}includeRequestBodyInWrappedRequest({body:t,inlineFileProperties:o}){switch(t.type){case"properties":case"referenced":return!0;case"fileUpload":return this.includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:o});default:W(t)}}includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:o}){return this.fileUploadHasBodyProperties({fileUpload:t})||o&&this.fileUploadHasFileProperties({fileUpload:t})}fileUploadHasBodyProperties({fileUpload:t}){return t.properties.some(o=>{switch(o.type){case"file":case"fileArray":return!1;case"bodyProperty":return!0;default:W(o)}})}fileUploadHasFileProperties({fileUpload:t}){return t.properties.some(o=>{switch(o.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:W(o)}})}isListTypeReference(t){return t.type==="optional"?this.isListTypeReference(t.value):t.type==="list"||t.type==="set"}parsedEndpointMatches({endpoint:t,parsedEndpoint:o}){return t.location.method===o.method&&t.location.path===o.path}};d();y();m();d();y();m();var Yt=["params","output","json","format","dry-run","base-url","page-all","page-limit","page-delay","no-pager","no-extract","retries","no-retry","no-stream","quiet","query","help","debug","schema","user-agent-suffix"],Kt=new Set(Yt);function gt(l,t){return Kt.has(l)||(t?.has(l)??!1)}function de(l){let t="";for(let o of l)vt(o)?Ue(o)?(t.length>0&&!t.endsWith("-")&&(t+="-"),t+=o.toLowerCase()):t+=o:t.length>0&&!t.endsWith("-")&&(t+="-");for(;t.endsWith("-");)t=t.slice(0,-1);return t}function Ie(l){let t=[...l],o="";for(let u=0;u<t.length;u++){let c=t[u];c==="_"||c==="-"?o.length>0&&!o.endsWith("-")&&(o+="-"):Ue(c)?(u>0&&o.length>0&&!o.endsWith("-")&&(o+="-"),o+=c.toLowerCase()):o+=c}return o}function wt(l){if(l.length===0)return;for(let u of l){let c=u.codePointAt(0)??0;if(c<=31||c===127||/\s/u.test(u))return}let t=l.normalize("NFKD").replace(/\p{M}/gu,"").replace(/[\u200B-\u200F\u202A-\u202E\u2060-\u2064\uFEFF]/gu,"");for(let u of t)if((u.codePointAt(0)??0)>127)return;let o=Xt(t);if(o.length!==0)return o}function Xt(l){let t=[...l],o="";for(let u=0;u<t.length;u++){let c=t[u];vt(c)?Ue(c)?(u>0&&o.length>0&&!o.endsWith("-")&&(o+="-"),o+=c.toLowerCase()):o+=c:o.length>0&&!o.endsWith("-")&&(o+="-")}for(;o.endsWith("-");)o=o.slice(0,-1);return o}function Et(l,t,o){let u;if(l.flagNameOverride!=null)u=l.flagNameOverride;else{let c=l.displayName??t;if(l.location==="body")u=Ie(c);else{let h=wt(c);if(h==null)return;u=h}}return gt(u,o)&&(u=`${u}-param`),u}function xt(l,t){let o=Ie(l);return gt(o,t)?void 0:o}function Bt(l,t){return/[^A-Za-z0-9_-]/.test(l)&&wt(l)!=null?t:l}function It(l){return l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").replace(/-{2,}/g,"-")}function vt(l){return/^[A-Za-z0-9]$/.test(l)}function Ue(l){return l>="A"&&l<="Z"}var ve=class l extends he{constructor({ir:o,config:u}){super({ir:o,config:u});I(this,"ir");I(this,"customConfig");this.ir=o,this.customConfig=u.customConfig!=null?u.customConfig:void 0}clone(){return new l({ir:this.ir,config:this.config})}getBinaryName(){let o=this.customConfig?.binaryName?.trim(),u=o!=null&&o.length>0?o:this.config.workspaceName;return It(u)}getCommandPrefix(o){let u=[this.getBinaryName()],c=this.customConfig?.rootGroup?.trim();return c!=null&&c.length>0&&u.push(de(c)),u.push(...this.getGroupPath(o.declaration.fernFilepath.allParts.map(h=>h.originalName))),u.push(de(o.declaration.name.originalName)),u}getGroupPath(o){let[u,...c]=o,h=u!=null?this.customConfig?.namespaces?.[u]:void 0;if(h==null)return o.map(de);let s=h.split("/").filter(E=>E.length>0),w=c.map(de);return w.length>0&&w[0]===s[s.length-1]&&w.shift(),[...s,...w]}getReservedFlagNames(){let o=new Set,u=this.customConfig?.userAgentSuffixFlag?.trim();return u!=null&&u.length>0&&o.add(Ie(u)),this.customConfig?.profiles?.enabled===!0&&o.add("profile"),o}};d();y();m();d();y();m();var Qt="--params",Zt="--json",be=class{constructor(t){I(this,"tokens");I(this,"paramsPayload",{});I(this,"seenFlags",new Set);I(this,"hasParamsPayload",!1);I(this,"jsonBody");I(this,"jsonBodySet",!1);this.tokens=[...t]}pushFlag(t,o){return this.seenFlags.has(t)?!1:(this.seenFlags.add(t),this.pushFlagValue(t,o),!0)}pushRepeatedFlag(t,o){if(this.seenFlags.has(t))return!1;this.seenFlags.add(t);for(let u of o)u!=null&&this.pushFlagValue(t,u);return!0}pushFlagValue(t,o){let u=en(o);u.startsWith("-")?this.tokens.push(`${t}=${Re(u)}`):this.tokens.push(t,Re(u))}routeToParams(t,o){rn(this.paramsPayload,t,o),this.hasParamsPayload=!0}setJsonBody(t){this.jsonBody=t,this.jsonBodySet=!0}build(){let t=[...this.tokens];return this.jsonBodySet&&this.jsonBody!=null&&(me(this.jsonBody)&&Object.keys(this.jsonBody).length===0||t.push(Zt,Re(JSON.stringify(this.jsonBody)))),this.hasParamsPayload&&t.push(Qt,Re(JSON.stringify(this.paramsPayload))),t.join(" ")}};function en(l){return typeof l=="boolean"?l?"true":"false":String(l)}function Re(l){return l.length>0&&/^[A-Za-z0-9_.:/@%+=-]+$/.test(l)?l:`'${l.replace(/'/g,"'\\''")}'`}function me(l){return typeof l=="object"&&l!=null&&!Array.isArray(l)}function rn(l,t,o){let u=l;for(let c=0;c<t.length-1;c++){let h=t[c],s=u[h];me(s)||(u[h]={}),u=u[h]}u[t[t.length-1]]=o}var Ae=class{constructor({context:t}){I(this,"context");this.context=t}async generateSnippet({endpoint:t,request:o}){return this.buildCommand({endpoint:t,snippet:o})}generateSnippetSync({endpoint:t,request:o}){return this.buildCommand({endpoint:t,snippet:o})}async generateSnippetAst({endpoint:t,request:o}){return new ue(this.buildCommand({endpoint:t,snippet:o}))}buildCommand({endpoint:t,snippet:o}){let u=new be(this.context.getCommandPrefix(t));switch(t.request.type){case"inlined":this.emitInlinedRequest({builder:u,request:t.request,snippet:o});break;case"body":this.emitBodyRequest({builder:u,request:t.request,snippet:o});break;default:W(t.request)}return u.build()}emitInlinedRequest({builder:t,request:o,snippet:u}){this.emitPathParameters({builder:t,requestPathParameters:o.pathParameters,snippet:u}),this.emitNamedParameters({builder:t,location:"query",parameters:o.queryParameters,values:u.queryParameters}),this.emitNamedParameters({builder:t,location:"header",parameters:o.headers,values:u.headers}),o.body!=null&&u.requestBody!=null&&this.emitInlinedRequestBody({builder:t,body:o.body,snippet:u})}emitBodyRequest({builder:t,request:o,snippet:u}){this.emitPathParameters({builder:t,requestPathParameters:o.pathParameters,snippet:u}),o.body!=null&&u.requestBody!=null&&this.emitReferencedBody({builder:t,body:o.body,value:u.requestBody})}emitPathParameters({builder:t,requestPathParameters:o,snippet:u}){let c=[...this.context.ir.pathParameters??[],...o??[]].filter(h=>h.variable==null);this.emitNamedParameters({builder:t,location:"path",parameters:c,values:u.pathParameters})}emitNamedParameters({builder:t,location:o,parameters:u,values:c}){if(!(u==null||u.length===0)){this.context.errors.scope(tn(o));try{let h=this.context.associateByWireValue({parameters:u,values:c??{},ignoreMissingParameters:!0});for(let s of h)this.emitValue({builder:t,location:o,name:s.name,value:s.value})}finally{this.context.errors.unscope()}}}emitInlinedRequestBody({builder:t,body:o,snippet:u}){this.context.errors.scope("Body");try{switch(o.type){case"properties":this.emitObjectBody({builder:t,properties:o.value,value:u.requestBody});break;case"referenced":this.emitReferencedBody({builder:t,body:o.bodyType,value:u.requestBody});break;case"fileUpload":this.emitObjectBody({builder:t,properties:nn(o),value:u.requestBody,multipart:!0});break;default:W(o)}}finally{this.context.errors.unscope()}}emitReferencedBody({builder:t,body:o,value:u}){switch(o.type){case"typeReference":{let c=this.resolveObjectProperties(o.value);c!=null?this.emitObjectBody({builder:t,properties:c,value:u}):t.setJsonBody(u);break}case"bytes":this.context.errors.add({severity:N.Warning,message:"Binary (bytes) request body omitted from the CLI snippet: the dynamic IR does not carry the runtime's file-flag metadata."});break;default:W(o)}}emitObjectBody({builder:t,properties:o,value:u,multipart:c=!1}){let h=this.context.getRecord(u);if(h==null)return;if(o.some(w=>w.name.wireValue.includes("."))){t.setJsonBody(h);return}let s=this.context.associateByWireValue({parameters:o,values:h});for(let w of s)this.emitValue({builder:t,location:"body",name:w.name,value:w.value,multipart:c})}emitValue({builder:t,location:o,name:u,value:c,multipart:h=!1}){if(c===void 0)return;let s=u.wireValue,w=this.context.getReservedFlagNames(),E=h?xt(s,w):Et({location:o,displayName:Bt(s,u.name.originalName)},s,w);if(E==null){this.context.errors.add({severity:N.Warning,message:`Parameter "${s}" was omitted from the CLI snippet: its name cannot be expressed as a flag and the runtime cannot accept it via --params.`});return}let $=`--${E}`;if(Array.isArray(c)){c.every(A=>!me(A)&&!Array.isArray(A))?this.warnIfFlagCollision(t.pushRepeatedFlag($,c),$,s):t.routeToParams([s],c);return}if(me(c)){t.routeToParams([s],c);return}this.warnIfFlagCollision(t.pushFlag($,c),$,s)}warnIfFlagCollision(t,o,u){t||this.context.errors.add({severity:N.Warning,message:`Parameter "${u}" was omitted from the CLI snippet: its flag "${o}" collides with another parameter's and the runtime keeps only the first.`})}resolveObjectProperties(t){if(t.type!=="named")return;let o=this.context.resolveNamedType({typeId:t.value});if(o!=null){if(o.type==="object")return o.properties;if(o.type==="alias")return this.resolveObjectProperties(o.typeReference)}}};function tn(l){switch(l){case"path":return"PathParameters";case"query":return"QueryParameters";case"header":return"Headers";case"body":return"Body"}}function nn(l){let t=[];for(let o of l.properties)switch(o.type){case"bodyProperty":t.push(o);break;case"file":case"fileArray":{let u={name:{wireValue:o.wireValue,name:o.name},typeReference:{type:"primitive",value:"STRING"}};t.push(u);break}default:break}return t}var _e=class extends le{constructor({ir:t,config:o}){super(new ve({ir:t,config:o}))}async generate(t,o={}){return super.generate(t,o)}generateSync(t){return super.generateSync(t)}async generateSnippetAst(t,o){return super.generateSnippetAst(t,o)}createSnippetGenerator(t){return new Ae({context:t})}};export{_e as DynamicSnippetsGenerator};
2
+ /*! Bundled license information:
3
+
4
+ @jspm/core/nodelibs/browser/chunk-DtuTasat.js:
5
+ (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
6
+ */
7
+ //# sourceMappingURL=index.js.map