@redocly/cli 2.47.0 → 2.49.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.
- package/lib/chunks/{QRD3XQNU.js → 2U54VUOE.js} +1 -1
- package/lib/chunks/3JJEI7CJ.js +456 -0
- package/lib/chunks/4I2OVMBJ.js +11 -0
- package/lib/chunks/{REBHK2JR.js → 4JDAOKRJ.js} +1 -1
- package/lib/chunks/5JIGUBC3.js +7 -0
- package/lib/chunks/{QVV2EKMT.js → 5SAFIITS.js} +1 -1
- package/lib/chunks/6KCIFTIG.js +57 -0
- package/lib/chunks/{5NR4DJW4.js → 6VSHPQXO.js} +1 -1
- package/lib/chunks/{W2NJCZOS.js → 74WJ7S7J.js} +1 -1
- package/lib/chunks/{QL4V2A4A.js → 7R5PBTLG.js} +1 -1
- package/lib/chunks/BT3ELZVX.js +42 -0
- package/lib/chunks/C5TR4MMN.js +19 -0
- package/lib/chunks/CCR5RYCX.js +20 -0
- package/lib/chunks/DCN3GSUA.js +7 -0
- package/lib/chunks/{TEQA5OM7.js → E5I67ZCZ.js} +1 -1
- package/lib/chunks/FUMCRNTK.js +78 -0
- package/lib/chunks/GNMJA2V2.js +16 -0
- package/lib/chunks/GRJG3TOI.js +14 -0
- package/lib/chunks/HA22GUKQ.js +7 -0
- package/lib/chunks/HJ36YGCI.js +184 -0
- package/lib/chunks/HJYFWIVE.js +9 -0
- package/lib/chunks/HL5FOKC4.js +16 -0
- package/lib/chunks/{SL6AH3N2.js → JBNPGEIJ.js} +1 -1
- package/lib/chunks/KHEMMNFU.js +26 -0
- package/lib/chunks/{SN2EC2ZR.js → KK2STV73.js} +1 -1
- package/lib/chunks/KK77ANZH.js +7 -0
- package/lib/chunks/L3TZNNJJ.js +13 -0
- package/lib/chunks/M6KLAAY4.js +7 -0
- package/lib/chunks/MHITBEGC.js +90 -0
- package/lib/chunks/NB54XRRU.js +10 -0
- package/lib/chunks/NSIQWNYL.js +7 -0
- package/lib/chunks/{YQW463Z7.js → NTPLYWAB.js} +1 -1
- package/lib/chunks/{5PXRDPHV.js → NUNOXB7Z.js} +1 -1
- package/lib/chunks/NWMTC4AN.js +7 -0
- package/lib/chunks/NYLAOZPO.js +22 -0
- package/lib/chunks/O4R6BSAS.js +20 -0
- package/lib/chunks/OKITK6EF.js +30 -0
- package/lib/chunks/OUCZOBEX.js +22 -0
- package/lib/chunks/PFYPTG4G.js +7 -0
- package/lib/chunks/QZH7EL26.js +7 -0
- package/lib/chunks/R4XFBOJU.js +9 -0
- package/lib/chunks/REFX2EKS.js +13 -0
- package/lib/chunks/{S4MX7JPH.js → RXOEH2LN.js} +1 -1
- package/lib/chunks/SGBB4RNM.js +11 -0
- package/lib/chunks/SQVG3CEM.js +8 -0
- package/lib/chunks/{RIFZSMUA.js → T5EPIBMA.js} +1 -1
- package/lib/chunks/TLQZAJQU.js +18 -0
- package/lib/chunks/TSB6PODJ.js +13 -0
- package/lib/chunks/TSRK76GA.js +19 -0
- package/lib/chunks/{34J2ZJDK.js → U2H2LXZE.js} +1 -1
- package/lib/chunks/UKSQ7B5H.js +2268 -0
- package/lib/chunks/UMQN5HTL.js +42 -0
- package/lib/chunks/V2LJ4UGM.js +7 -0
- package/lib/chunks/VBPP2WUF.js +7 -0
- package/lib/chunks/WPGKH5NI.js +177 -0
- package/lib/chunks/WXVC3KOI.js +67 -0
- package/lib/chunks/{KEUH3PST.js → YI34NB7D.js} +1 -1
- package/lib/chunks/YOJGIGE3.js +7 -0
- package/lib/chunks/{TO2KJ36N.js → YP5GHFYE.js} +1 -1
- package/lib/chunks/YXXYE4G2.js +7 -0
- package/lib/chunks/ZBL4IVEW.js +11 -0
- package/lib/chunks/ZMCRMR2V.js +5400 -0
- package/lib/chunks/ZOUQBK53.js +14 -0
- package/lib/chunks/ZXKOHMC6.js +177 -0
- package/lib/eject-assets/AGENTS.md +137 -0
- package/lib/eject-assets/generators/cli/docs.ts +224 -0
- package/lib/eject-assets/generators/cli/engine-source.ts +21 -0
- package/lib/eject-assets/generators/cli/index.ts +90 -0
- package/lib/eject-assets/generators/cli/render.ts +348 -0
- package/lib/eject-assets/generators/go/client.ts +57 -0
- package/lib/eject-assets/generators/go/descriptor.ts +41 -0
- package/lib/eject-assets/generators/go/index.ts +336 -0
- package/lib/eject-assets/generators/go/models.ts +179 -0
- package/lib/eject-assets/generators/go/naming.ts +49 -0
- package/lib/eject-assets/generators/go/operations.ts +296 -0
- package/lib/eject-assets/generators/go/pagination.ts +194 -0
- package/lib/eject-assets/generators/go/types.ts +60 -0
- package/lib/eject-assets/generators/mock/faker.ts +214 -0
- package/lib/eject-assets/generators/mock/index.ts +35 -0
- package/lib/eject-assets/generators/mock/render.ts +282 -0
- package/lib/eject-assets/generators/mock/sample.ts +316 -0
- package/lib/eject-assets/generators/mock/values.ts +63 -0
- package/lib/eject-assets/generators/php/client.ts +63 -0
- package/lib/eject-assets/generators/php/descriptor.ts +58 -0
- package/lib/eject-assets/generators/php/index.ts +237 -0
- package/lib/eject-assets/generators/php/models.ts +275 -0
- package/lib/eject-assets/generators/php/naming.ts +51 -0
- package/lib/eject-assets/generators/php/operations.ts +232 -0
- package/lib/eject-assets/generators/php/pagination.ts +133 -0
- package/lib/eject-assets/generators/php/types.ts +148 -0
- package/lib/eject-assets/generators/python/client.ts +123 -0
- package/lib/eject-assets/generators/python/descriptor.ts +52 -0
- package/lib/eject-assets/generators/python/index.ts +251 -0
- package/lib/eject-assets/generators/python/models.ts +242 -0
- package/lib/eject-assets/generators/python/naming.ts +46 -0
- package/lib/eject-assets/generators/python/operations.ts +147 -0
- package/lib/eject-assets/generators/python/pagination.ts +128 -0
- package/lib/eject-assets/generators/python/types.ts +54 -0
- package/lib/eject-assets/generators/swr/index.ts +37 -0
- package/lib/eject-assets/generators/swr/render.ts +78 -0
- package/lib/eject-assets/generators/tanstack-query/index.ts +48 -0
- package/lib/eject-assets/generators/tanstack-query/render.ts +346 -0
- package/lib/eject-assets/generators/transformers/index.ts +46 -0
- package/lib/eject-assets/generators/transformers/render.ts +506 -0
- package/lib/eject-assets/generators/typescript/banner.ts +35 -0
- package/lib/eject-assets/generators/typescript/client.ts +254 -0
- package/lib/eject-assets/generators/typescript/descriptor.ts +137 -0
- package/lib/eject-assets/generators/typescript/index.ts +101 -0
- package/lib/eject-assets/generators/typescript/inline-runtime.ts +135 -0
- package/lib/eject-assets/generators/typescript/operation-signature.ts +62 -0
- package/lib/eject-assets/generators/typescript/operation-types.ts +17 -0
- package/lib/eject-assets/generators/typescript/operations.ts +524 -0
- package/lib/eject-assets/generators/typescript/response-headers.ts +74 -0
- package/lib/eject-assets/generators/typescript/type-guards.ts +159 -0
- package/lib/eject-assets/generators/typescript/types.ts +172 -0
- package/lib/eject-assets/generators/zod/index.ts +32 -0
- package/lib/eject-assets/generators/zod/schemas.ts +456 -0
- package/lib/eject-assets/skills/cli-generator/SKILL.md +121 -0
- package/lib/eject-assets/skills/client-generators/SKILL.md +142 -0
- package/lib/eject-assets/skills/go-generator/SKILL.md +96 -0
- package/lib/eject-assets/skills/mock-generator/SKILL.md +50 -0
- package/lib/eject-assets/skills/php-generator/SKILL.md +112 -0
- package/lib/eject-assets/skills/python-generator/SKILL.md +110 -0
- package/lib/eject-assets/skills/swr-generator/SKILL.md +50 -0
- package/lib/eject-assets/skills/tanstack-query-generator/SKILL.md +55 -0
- package/lib/eject-assets/skills/transformers-generator/SKILL.md +47 -0
- package/lib/eject-assets/skills/typescript-generator/SKILL.md +95 -0
- package/lib/eject-assets/skills/zod-generator/SKILL.md +54 -0
- package/lib/index.js +271 -193
- package/package.json +1 -1
- package/lib/chunks/B6HS7CVY.js +0 -184
- package/lib/chunks/PIJLRHNN.js +0 -8
- package/lib/chunks/Y5HLCNL5.js +0 -2542
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import{a as k,b as d,c as g,d as f}from"./R4XFBOJU.js";import"./OKITK6EF.js";import"./4I2OVMBJ.js";import"./ZMCRMR2V.js";import"./PFYPTG4G.js";import"./HJ36YGCI.js";import"./NEWT5A6S.js";import{b as p,d as O,e as u}from"./NB54XRRU.js";import{m as P}from"./HJYFWIVE.js";import"./RFWIIJFG.js";import{join as R}from"node:path";function x(e,t){let n=k(e,"tanstack-query");if(n.length===0)return"";let r=t.pagination??new Map;return[b(n,t,r),...n.filter(d).map(s=>K(s,t.queryKeyPrefix)),j(e,n,r,t.queryKeyPrefix,t.argsStyle),...N(n,r)].join(`
|
|
8
|
+
`)}function h(e,t){if(!d(e))return!1;let n=t.get(e.name);return n!==void 0&&n.spec.style!=="link"}function b(e,t,n){let r=[...e.some(a=>h(a,n))?["infiniteQueryOptions"]:[],...e.some(d)?["queryOptions"]:[]],i=[...e.filter(g).map(f),"RequestOptions"].sort().map(a=>`type ${a}`),s=[];return r.length>0&&s.push(`import { ${r.join(", ")} } from "@tanstack/${t.framework}-query";`),s.push(`import { client, ${i.join(", ")} } from "${t.sdkModule}";`),s.join(`
|
|
9
|
+
`)}function K(e,t){let n=A(e,t);return g(e)?`export const ${e.name}QueryKey = (vars?: ${f(e)}) =>
|
|
10
|
+
vars === undefined ? ([${n}] as const) : ([${n}, vars] as const);`:`export const ${e.name}QueryKey = () => [${n}] as const;`}function A(e,t){return t===void 0?`"${e.name}"`:`${O(t)}, "${e.name}"`}function j(e,t,n,r,i){return`/**
|
|
11
|
+
* Build the factories over a specific client instance \u2014 its config, middleware, and
|
|
12
|
+
* retry apply to every call (\`createQueryFactories(createClient(OPERATIONS, config))\`).
|
|
13
|
+
* The module-level exports below are these factories bound to the generated module's default \`client\`.
|
|
14
|
+
*/
|
|
15
|
+
export const createQueryFactories = (instance: typeof client = client) => ({
|
|
16
|
+
`+t.flatMap(a=>{if(!d(a))return[T(a,r)];let o=n.get(a.name);return o!==void 0&&o.spec.style!=="link"?[v(a),Q(e,a,o.spec,i)]:[v(a)]}).join(`,
|
|
17
|
+
`)+`
|
|
18
|
+
});`}function v(e){let{params:t,keyArg:n,callArgs:r}=q(e);return` ${e.name}Options: (${t}) => queryOptions({
|
|
19
|
+
queryKey: ${e.name}QueryKey(${n}),
|
|
20
|
+
queryFn: ({ signal }) => instance.${e.name}(${r}, { ...init, signal, envelope: undefined }),
|
|
21
|
+
})`}function T(e,t){let n=g(e)?`(vars: ${f(e)}) => instance.${e.name}(vars, { ...init, envelope: undefined })`:`() => instance.${e.name}({}, { ...init, envelope: undefined })`;return` ${e.name}Mutation: (${M}) => ({
|
|
22
|
+
mutationKey: [${A(e,t)}] as const,
|
|
23
|
+
mutationFn: ${n},
|
|
24
|
+
})`}function Q(e,t,n,r){let{params:i,keyArg:s}=q(t),a=u(n.param),o=r==="flat"?`{ ...vars, ${a}: pageParam }`:`{ ...vars, query: { ...vars.query, ${a}: pageParam } }`;return` ${t.name}InfiniteOptions: (${i}) => infiniteQueryOptions({
|
|
25
|
+
queryKey: [...${t.name}QueryKey(${s}), "infinite"] as const,
|
|
26
|
+
queryFn: ({ pageParam, signal }) => instance.${t.name}(${o}, { ...init, signal, envelope: undefined }),
|
|
27
|
+
`+F(e,t,n,r)+" })"}function F(e,t,n,r){let i=w(n.param),s=r==="flat"?C("vars",n.param):`vars.query?.${i}`;if(n.style==="cursor"){let l=n.hasMore===void 0?"":` if (lastPage${y(n.hasMore)} === false) return undefined;
|
|
28
|
+
`,m=I(e,t,n.nextCursor),$=m.length===0?` return lastPage${y(n.nextCursor)};
|
|
29
|
+
`:` const next = lastPage${y(n.nextCursor)};
|
|
30
|
+
return ${m.join(" || ")} ? undefined : next;
|
|
31
|
+
`;return` initialPageParam: ${s},
|
|
32
|
+
getNextPageParam: (lastPage) => {
|
|
33
|
+
`+l+$+` },
|
|
34
|
+
`}let a=n.style==="offset"?"lastPageParam + count":"lastPageParam + 1",o=n.style==="offset"?"0":"1";return` initialPageParam: ${s} ?? ${o},
|
|
35
|
+
getNextPageParam: (lastPage, _allPages, lastPageParam) => {
|
|
36
|
+
const count = ${E(n.items)};
|
|
37
|
+
return count === 0 ? undefined : ${a};
|
|
38
|
+
},
|
|
39
|
+
`}function I(e,t,n){let r=t.successResponses.find(c=>c.contentType.toLowerCase().includes("json")),i=P(r.schema,"",e),s=P(r.schema,n,e),a=n.slice(1).split("/"),o=a.length>1;if(!o&&i?.kind==="object"){let c=i.properties.find(S=>S.name===a[0]);o=c===void 0||!c.required}let l=s?.kind==="union"?s.members:s?[s]:[],m=l.some(c=>c.kind==="null"),$=l.some(c=>c.kind==="scalar"&&c.scalar==="string");return[...o?["next === undefined"]:[],...m?["next === null"]:[],...$?['next === ""']:[]]}var M='init?: Omit<RequestOptions, "envelope">';function q(e){return g(e)?{params:`vars: ${f(e)}, ${M}`,keyArg:"vars",callArgs:"vars"}:{params:M,keyArg:"",callArgs:"{}"}}function w(e){return p(e)?e:`[${u(e)}]`}function C(e,t){return p(t)?`${e}.${t}`:`${e}[${u(t)}]`}function y(e){return e.slice(1).split("/").map(n=>n.replaceAll("~1","/").replaceAll("~0","~")).map((n,r)=>{let i=p(n);return r===0?i?`.${n}`:`[${u(n)}]`:i?`?.${n}`:`?.[${u(n)}]`}).join("")}function E(e){return e===""?"lastPage?.length ?? 0":`lastPage${y(e)}?.length ?? 0`}function N(e,t){return["const defaultFactories = createQueryFactories();",...e.flatMap(r=>d(r)?h(r,t)?[`${r.name}Options`,`${r.name}InfiniteOptions`]:[`${r.name}Options`]:[`${r.name}Mutation`]).map(r=>`export const ${r} = defaultFactories.${r};`)]}function z(e){return({model:t,output:n,banner:r,emit:i,pagination:s})=>{let a=x(t,{argsStyle:i.argsStyle??"grouped",sdkModule:`./${n.stem}.${i.importExt??"js"}`,framework:e,pagination:s,queryKeyPrefix:i.queryKeyPrefix});if(a==="")return[];let o=r.map(l=>`// ${l}`).join(`
|
|
40
|
+
`);return[{path:R(n.dir,`${n.stem}.tanstack.ts`),content:`${o}
|
|
41
|
+
|
|
42
|
+
${a}`}]}}export{z as tanstackQueryGenerator};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import{a}from"./GNMJA2V2.js";import"./R4XFBOJU.js";import"./OKITK6EF.js";import"./4I2OVMBJ.js";import"./ZMCRMR2V.js";import"./PFYPTG4G.js";import"./HJ36YGCI.js";import"./NEWT5A6S.js";import"./NB54XRRU.js";import"./HJYFWIVE.js";import"./RFWIIJFG.js";export{a as swrGenerator};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import{a}from"./BT3ELZVX.js";import"./R4XFBOJU.js";import"./OKITK6EF.js";import"./4I2OVMBJ.js";import"./ZMCRMR2V.js";import"./PFYPTG4G.js";import"./HJ36YGCI.js";import"./NEWT5A6S.js";import"./NB54XRRU.js";import"./HJYFWIVE.js";import"./RFWIIJFG.js";export{a as tanstackQueryGenerator};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import{a as h}from"./ZMCRMR2V.js";import{e as g,h as p,k as $}from"./NB54XRRU.js";import{join as R}from"node:path";var a=" ";function m(e){return`${$(e)}Schema`}var y=new Map;function u(e,r=y,t=""){return j(w(e,r,t),e)}function w(e,r,t){switch(e.kind){case"scalar":return z(e.scalar,e.metadata);case"object":return b(e.properties,r,t);case"array":return`z.array(${u(e.items,r,t)})`;case"record":return`z.record(z.string(), ${u(e.value,r,t)})`;case"ref":return`z.lazy(() => ${m(e.name)})`;case"literal":return`z.literal(${p(e.value)})`;case"enum":return q(e.values);case"union":return k(e.members,r,t);case"intersection":return e.members.map(n=>u(n,r,t)).reduce((n,o)=>`${n}.and(${o})`);case"null":return"z.null()";case"unknown":return"z.unknown()";case"omit":return E(e.base,e.keys,r,t)}}function z(e,r){switch(e){case"string":return r?.format==="binary"?"z.instanceof(Blob)":"z.string()";case"integer":return"z.number().int()";case"number":return"z.number()";case"boolean":return"z.boolean()"}}function c(e){return g(e)===e?e:JSON.stringify(e)}function b(e,r,t){if(e.length===0)return"z.object({})";let n=t+a;return`z.object({
|
|
8
|
+
${e.map((s,i)=>{let d=u(s.schema,r,n),l=s.required?d:`${d}.optional()`,x=i===e.length-1?"":",";return`${n}${c(s.name)}: ${l}${x}`}).join(`
|
|
9
|
+
`)}
|
|
10
|
+
${t}})`}function q(e){return e.every(r=>typeof r=="string")?`z.enum([${e.map(r=>JSON.stringify(r)).join(", ")}])`:`z.union([${e.map(r=>`z.literal(${p(r)})`).join(", ")}])`}function k(e,r,t){let n=e.map(o=>u(o,r,t));return n.length===1?n[0]:`z.union([${n.join(", ")}])`}function E(e,r,t,n){let o=t.get(e);if(o&&o.kind!=="object")return u(f(o,r,t,new Set([e])),t,n);let s=r.map(i=>`${c(i)}: true`).join(", ");return`${m(e)}.omit({ ${s} })`}function f(e,r,t,n){switch(e.kind){case"object":return{...e,properties:e.properties.filter(o=>!r.includes(o.name))};case"union":case"intersection":return{...e,members:e.members.map(o=>f(o,r,t,n))};case"ref":{if(n.has(e.name))return e;let o=t.get(e.name);if(!o)return e;if(o.kind==="object"){let s=r.filter(i=>o.properties.some(d=>d.name===i));return s.length>0?{kind:"omit",base:e.name,keys:s}:e}return f(o,r,t,new Set([...n,e.name]))}default:return e}}function j(e,r){let t=r.metadata;if(!t)return e;let n=e;return r.kind==="scalar"&&r.scalar==="string"&&(t.minLength!==void 0&&(n=`${n}.min(${t.minLength})`),t.maxLength!==void 0&&(n=`${n}.max(${t.maxLength})`),t.pattern!==void 0&&(n=`${n}.regex(new RegExp(${JSON.stringify(t.pattern)}))`)),r.kind==="scalar"&&(r.scalar==="number"||r.scalar==="integer")&&(t.minimum!==void 0&&(n=`${n}.min(${t.minimum})`),t.maximum!==void 0&&(n=`${n}.max(${t.maximum})`),t.exclusiveMinimum!==void 0&&(n=`${n}.gt(${t.exclusiveMinimum})`),t.exclusiveMaximum!==void 0&&(n=`${n}.lt(${t.exclusiveMaximum})`)),r.kind==="array"&&(t.minItems!==void 0&&(n=`${n}.min(${t.minItems})`),t.maxItems!==void 0&&(n=`${n}.max(${t.maxItems})`)),n}function Z(e,r){let t=[];for(let n of h(e.services)){if(n.sse!==void 0)continue;let o=n.requestBody,s=o&&o.contentType.toLowerCase().includes("json")?u(o.schema,r,a):void 0,i=n.successResponses.find(l=>l.contentType.toLowerCase().includes("json")),d=i?u(i.schema,r,a):void 0;!s&&!d||t.push({name:n.specName??n.name,request:s,response:d})}return t}function I(e){let r=e.flatMap(n=>[`${a}${c(n.name)}: {`,...n.request?[`${a}${a}request: z.ZodType;`]:[],...n.response?[`${a}${a}response: z.ZodType;`]:[],`${a}};`]),t=e.map((n,o)=>{let s=[...n.request?[`request: ${n.request}`]:[],...n.response?[`response: ${n.response}`]:[]].join(", "),i=o===e.length-1?"":",";return`${a}${c(n.name)}: { ${s} }${i}`});return["/**"," * Request/response validators by operationId \u2014 powers `zodValidation`, or import one directly."," */","export const operationSchemas: {",...r,"} = {",...t,"};"].join(`
|
|
11
|
+
`)}var S=`/** \`request\`/\`response\` validators for one operation (an absent side is not validated). */
|
|
12
|
+
export type OperationSchemaSet = { request?: z.ZodType; response?: z.ZodType };
|
|
13
|
+
|
|
14
|
+
const schemaIndex: Partial<Record<string, OperationSchemaSet>> = operationSchemas;
|
|
15
|
+
|
|
16
|
+
/** One flattened validation problem: the full nested path and a short preview of the value. */
|
|
17
|
+
export type ZodViolation = { path: string; message: string; received: string };
|
|
18
|
+
|
|
19
|
+
/** A request or response payload failed validation. Requests throw it; response handling is configurable. */
|
|
20
|
+
export class ZodValidationError extends Error {
|
|
21
|
+
// Declared and assigned in the body, NOT as constructor parameter properties: those
|
|
22
|
+
// need a transform, so they break \`node --experimental-strip-types\` for anything
|
|
23
|
+
// importing this module (the generated CLI runs that way).
|
|
24
|
+
readonly operationId: string;
|
|
25
|
+
readonly direction: "request" | "response";
|
|
26
|
+
readonly issues: z.ZodError["issues"];
|
|
27
|
+
readonly violations: ZodViolation[];
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
operationId: string,
|
|
31
|
+
direction: "request" | "response",
|
|
32
|
+
issues: z.ZodError["issues"],
|
|
33
|
+
violations: ZodViolation[]
|
|
34
|
+
) {
|
|
35
|
+
const detail = violations
|
|
36
|
+
.slice(0, 5)
|
|
37
|
+
.map((violation) => \`\${violation.path || "(root)"}: \${violation.message} (received \${violation.received})\`)
|
|
38
|
+
.join("; ");
|
|
39
|
+
const more = violations.length > 5 ? \`; \u2026and \${violations.length - 5} more\` : "";
|
|
40
|
+
super(\`\${direction === "request" ? "Request" : "Response"} validation failed for operation "\${operationId}": \${detail}\${more}\`);
|
|
41
|
+
this.operationId = operationId;
|
|
42
|
+
this.direction = direction;
|
|
43
|
+
this.issues = issues;
|
|
44
|
+
this.violations = violations;
|
|
45
|
+
this.name = "ZodValidationError";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Flatten zod issues into leaf violations. Union branches (zod 3 \`unionErrors\`, zod 4
|
|
50
|
+
// nested \`errors\`) are recursed into, so the message names the actual failing fields
|
|
51
|
+
// instead of just the union root ("Invalid input").
|
|
52
|
+
function flattenIssues(
|
|
53
|
+
issues: z.ZodError["issues"],
|
|
54
|
+
value: unknown,
|
|
55
|
+
base: PropertyKey[] = []
|
|
56
|
+
): ZodViolation[] {
|
|
57
|
+
const violations: ZodViolation[] = [];
|
|
58
|
+
for (const issue of issues) {
|
|
59
|
+
const path = [...base, ...issue.path];
|
|
60
|
+
const nested = nestedIssueLists(issue);
|
|
61
|
+
if (nested.length > 0) {
|
|
62
|
+
for (const sub of nested) violations.push(...flattenIssues(sub, value, path));
|
|
63
|
+
} else {
|
|
64
|
+
violations.push({
|
|
65
|
+
path: path.map(String).join("."),
|
|
66
|
+
message: issue.message,
|
|
67
|
+
received: preview(valueAt(value, path)),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return violations;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The nested issue lists of a union-ish issue, across zod 3 (\`unionErrors\`) and zod 4 (\`errors\`). */
|
|
75
|
+
function nestedIssueLists(issue: unknown): Array<z.ZodError["issues"]> {
|
|
76
|
+
const candidate = issue as {
|
|
77
|
+
unionErrors?: Array<{ issues: z.ZodError["issues"] }>;
|
|
78
|
+
errors?: Array<z.ZodError["issues"]>;
|
|
79
|
+
};
|
|
80
|
+
if (Array.isArray(candidate.unionErrors)) return candidate.unionErrors.map((error) => error.issues);
|
|
81
|
+
if (Array.isArray(candidate.errors)) return candidate.errors;
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function valueAt(value: unknown, path: PropertyKey[]): unknown {
|
|
86
|
+
let current = value;
|
|
87
|
+
for (const key of path) {
|
|
88
|
+
if (current === null || typeof current !== "object") return undefined;
|
|
89
|
+
current = (current as Record<PropertyKey, unknown>)[key];
|
|
90
|
+
}
|
|
91
|
+
return current;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A short single-line preview of the offending value. NOTE: validation output can surface
|
|
95
|
+
* payload data \u2014 route \`onViolation\` to a scrubbed logger when responses may carry secrets. */
|
|
96
|
+
function preview(value: unknown): string {
|
|
97
|
+
let text: string;
|
|
98
|
+
try {
|
|
99
|
+
text = JSON.stringify(value) ?? String(value);
|
|
100
|
+
} catch {
|
|
101
|
+
text = String(value);
|
|
102
|
+
}
|
|
103
|
+
return text.length > 80 ? \`\${text.slice(0, 77)}\u2026\` : text;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type ZodValidationOptions = {
|
|
107
|
+
/** Validate request bodies before any network call; a failure THROWS (it is the caller's own bug). Default: true. */
|
|
108
|
+
request?: boolean;
|
|
109
|
+
/** Replace the outgoing body with the parsed result, dropping keys the schema does not declare
|
|
110
|
+
* (for strict-DTO servers that 400 on excess properties). Runs request validation. Default: false. */
|
|
111
|
+
stripRequestBodies?: boolean;
|
|
112
|
+
/** Response drift handling: \`"warn"\` (default) reports via \`onViolation\` and lets the call
|
|
113
|
+
* succeed \u2014 a server drifting from its description should not crash the consumer;
|
|
114
|
+
* \`"throw"\` fails the call (even on result-mode clients); \`false\` skips response validation. */
|
|
115
|
+
response?: "warn" | "throw" | false;
|
|
116
|
+
/** Sink for \`"warn"\` mode. Default: \`console.warn\` with the error message. */
|
|
117
|
+
onViolation?: (error: ZodValidationError) => void;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Schema-validation middleware for the generated client: \`use(zodValidation())\`.
|
|
122
|
+
* Request bodies are validated before any network call and throw on failure; successful
|
|
123
|
+
* JSON responses are validated against the operation's response schema and WARN by
|
|
124
|
+
* default (see \`ZodValidationOptions.response\`). Operations without a schema pass
|
|
125
|
+
* through untouched. Payloads are never mutated unless \`stripRequestBodies\` is set.
|
|
126
|
+
*/
|
|
127
|
+
export function zodValidation(options: ZodValidationOptions = {}) {
|
|
128
|
+
const { request = true, stripRequestBodies = false, response = "warn", onViolation } = options;
|
|
129
|
+
const report = onViolation ?? ((error: ZodValidationError) => console.warn(error.message));
|
|
130
|
+
return {
|
|
131
|
+
onRequest(context: { body?: unknown; operation: { id: string } }): void {
|
|
132
|
+
if ((!request && !stripRequestBodies) || context.body === undefined) return;
|
|
133
|
+
const schema = schemaIndex[context.operation.id]?.request;
|
|
134
|
+
if (!schema) return;
|
|
135
|
+
const result = schema.safeParse(context.body);
|
|
136
|
+
if (!result.success) {
|
|
137
|
+
throw new ZodValidationError(
|
|
138
|
+
context.operation.id,
|
|
139
|
+
"request",
|
|
140
|
+
result.error.issues,
|
|
141
|
+
flattenIssues(result.error.issues, context.body)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
// zod object schemas drop undeclared keys during parsing, so the parsed value
|
|
145
|
+
// IS the declared shape (intersections keep their own zod semantics).
|
|
146
|
+
if (stripRequestBodies) context.body = result.data;
|
|
147
|
+
},
|
|
148
|
+
async onResponse(incoming: Response, context: { operation: { id: string } }): Promise<void> {
|
|
149
|
+
if (response === false || !incoming.ok) return;
|
|
150
|
+
const schema = schemaIndex[context.operation.id]?.response;
|
|
151
|
+
if (!schema) return;
|
|
152
|
+
const contentType = (incoming.headers.get("content-type") ?? "").toLowerCase();
|
|
153
|
+
if (!contentType.includes("json")) return;
|
|
154
|
+
const payload: unknown = await incoming.clone().json();
|
|
155
|
+
const result = schema.safeParse(payload);
|
|
156
|
+
if (!result.success) {
|
|
157
|
+
const error = new ZodValidationError(
|
|
158
|
+
context.operation.id,
|
|
159
|
+
"response",
|
|
160
|
+
result.error.issues,
|
|
161
|
+
flattenIssues(result.error.issues, payload)
|
|
162
|
+
);
|
|
163
|
+
if (response === "throw") throw error;
|
|
164
|
+
report(error);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}`;function v(e){let r=new Map(e.schemas.map(o=>[o.name,o.schema])),t=Z(e,r);if(e.schemas.length===0&&t.length===0)return"";let n=['import { z } from "zod";',...e.schemas.map(o=>`export const ${m(o.name)} = ${u(o.schema,r)};`)];return t.length===0?n.join(`
|
|
169
|
+
|
|
170
|
+
`):(n.push(I(t)),`${n.join(`
|
|
171
|
+
|
|
172
|
+
`)}
|
|
173
|
+
${S}
|
|
174
|
+
`)}var M=({model:e,output:r,banner:t})=>{let n=v(e);if(n==="")return[];let o=t.map(s=>`// ${s}`).join(`
|
|
175
|
+
`);return[{path:R(r.dir,`${r.stem}.zod.ts`),content:`${o}
|
|
176
|
+
|
|
177
|
+
${n}`}]};export{M as a};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import"./UKSQ7B5H.js";import{b as S,c as v,d as k,e as P,f as w,g as D,h as q,i as U,j as B}from"./OKITK6EF.js";import{b,g as R}from"./4I2OVMBJ.js";import{a as d,c as j,d as N,e as T}from"./ZMCRMR2V.js";import"./PFYPTG4G.js";import"./HJ36YGCI.js";import"./NEWT5A6S.js";import{d as E,f as A,h as I,i as x,m as C}from"./NB54XRRU.js";import"./HJYFWIVE.js";import"./RFWIIJFG.js";import{join as Y}from"node:path";var y="// Generated by @redocly/client-generator \u2014 do not edit by hand.\n// Source: OpenAPI description. Re-run `redocly generate-client` to update.";function O(e){return e.filter(t=>t.length>0).join(`
|
|
8
|
+
|
|
9
|
+
`)+`
|
|
10
|
+
`}function M(e){let t=["/**",` * ${x(`${e.title} (v${e.version})`)}`];if(e.description)for(let n of C(x(e.description)))t.push(` * ${n}`.replace(/ +$/,""));return t.push(" */"),t.join(`
|
|
11
|
+
`)}function $(e){let t=new Set(T),n=new Map;for(let r of d(e.services))n.set(r.name,A(r.name,t));return n}function Z(e,t,n,r,i=[],o="grouped"){let s=[...e.pathParams,...e.queryParams,...e.headerParams,...e.cookieParams].map(p=>({name:p.name,in:p.in,...p.style!==void 0?{style:p.style}:{},...p.explode!==void 0?{explode:p.explode}:{},...p.allowReserved!==void 0?{allowReserved:p.allowReserved}:{}})),c=R(e,{securitySchemes:t}),m=e.sse!==void 0?"sse":w(e.successResponses,n).kind,l=v(e.successResponseHeaders,i);return{id:e.specName??e.name,method:e.method.toUpperCase(),path:e.path,...e.tags.length>0?{tags:e.tags}:{},...s.length>0?{params:s}:{},...e.requestBody?{body:{contentType:e.requestBody.contentType,...S(e.requestBody)?{multipart:!0}:{}}}:{},...m!=="json"?{responseKind:m}:{},...e.sse===void 0?{}:{sseDataKind:e.sse.dataKind},...c.length>0?{security:c}:{},...l===void 0?{}:{responseHeaders:l},...r?.has(e.name)?{pagination:r.get(e.name).spec}:{},...o==="flat"&&"collisions"in D(e,i)?{argsStyle:"grouped"}:{}}}function F(e,t,n,r,i="grouped"){let o=d(e.services);if(o.length===0)return"";let s=o.map((a,m)=>{let l=I(Z(a,e.securitySchemes,n,r,e.schemas,i));return` ${t.get(a.name)}: ${l}${m===o.length-1?"":","}`}),c=[[...k(`The wire-shape descriptor for every operation, keyed by operationId \u2014 the data the
|
|
12
|
+
runtime routes requests by. Also minification-safe static metadata (method, path,
|
|
13
|
+
tags) for cache keys, tracing span names, and request logging.`,void 0,""),"export const OPERATIONS = {",...s,"} as const satisfies Record<string, OperationDescriptor>;"].join(`
|
|
14
|
+
`),'export type OperationId = (typeof OPERATIONS)[keyof typeof OPERATIONS]["id"];','export type OperationPath = (typeof OPERATIONS)[keyof typeof OPERATIONS]["path"];'];return o.some(a=>a.tags.length>0)&&c.push(`export type OperationTag = Extract<(typeof OPERATIONS)[keyof typeof OPERATIONS], {
|
|
15
|
+
tags: readonly string[];
|
|
16
|
+
}>["tags"][number];`),c.join(`
|
|
17
|
+
|
|
18
|
+
`)}var ee="// \u2500\u2500\u2500 Embedded runtime (@redocly/client-generator, assembled per this API's needs) \u2500\u2500\u2500";function L(e){let t=["types.ts","errors.ts","url.ts","parse.ts","retry.ts"];return e.multipart&&t.push("multipart.ts"),e.auth&&t.push("auth.ts"),e.setup&&t.push("setup.ts"),e.paginate&&t.push("paginate.ts"),t.push("send.ts"),e.sse&&t.push("sse.ts"),t.push("create-client.ts"),t}function G(e){return[ee,...L(e).map(t=>N[t]),H(e)].join(`
|
|
19
|
+
|
|
20
|
+
`)}function _(e,t="js"){let n=[...L(e).map(r=>({name:r,content:j[r]})),{name:"factory.ts",content:te(e)}];return t==="js"?n:n.map(({name:r,content:i})=>({name:r,content:i.replace(/(from '\.\/[a-z-]+)\.js'/g,"$1.ts'")}))}function te(e){let t=["import { createClientCore } from './create-client.js';",...e.multipart?["import { toFormData } from './multipart.js';"]:[],...e.auth?["import { resolveAuth } from './auth.js';"]:[],...e.paginate?["import { items, itemsByLink, pages, pagesByLink } from './paginate.js';"]:[],...e.sse?["import { sse } from './sse.js';"]:[],`import type {
|
|
21
|
+
Client,
|
|
22
|
+
ClientConfig,
|
|
23
|
+
OperationContext,
|
|
24
|
+
OperationDescriptor,
|
|
25
|
+
OpsShape,
|
|
26
|
+
} from './types.js';`],n=["export { ApiError, TimeoutError } from './errors.js';","export { defaultRetryOn } from './retry.js';",...e.setup?["export { mergeSetup } from './setup.js';"]:[],"export type * from './types.js';"];return[t.join(`
|
|
27
|
+
`),H(e),n.join(`
|
|
28
|
+
`)].join(`
|
|
29
|
+
|
|
30
|
+
`)}function H(e){let t=[...e.multipart?["serializeMultipart: toFormData"]:[],...e.auth?["resolveAuth"]:[],...e.sse?["sse"]:[],...e.paginate?["paginate: { pages, items, pagesByLink, itemsByLink }"]:[]];return`/**
|
|
31
|
+
* The client factory: \`createClientCore\` wired with the capabilities this API needs.
|
|
32
|
+
* Exported so apps can build additional instances (per-tenant, per-environment) over
|
|
33
|
+
* the same \`OPERATIONS\`/\`Ops\`. The trailing string params carry the wiring's literal
|
|
34
|
+
* unions (\`OperationId\`/\`OperationPath\`/\`OperationTag\`) into \`ctx.operation\`.
|
|
35
|
+
*/
|
|
36
|
+
export function createClient<
|
|
37
|
+
Ops extends OpsShape,
|
|
38
|
+
Id extends string = string,
|
|
39
|
+
Path extends string = string,
|
|
40
|
+
Tag extends string = string,
|
|
41
|
+
>(
|
|
42
|
+
operations: Record<string, OperationDescriptor>,
|
|
43
|
+
config?: ClientConfig<OperationContext<Id, Path, Tag>>
|
|
44
|
+
): Client<Ops, OperationContext<Id, Path, Tag>> {
|
|
45
|
+
return createClientCore<Ops, Id, Path, Tag>(operations, config, ${t.length>0?`{ ${t.join(", ")} }`:"{}"});
|
|
46
|
+
}`}function J(e){let t=new Map(e.map(i=>[i.name,i.schema])),n=[],r=new Set;for(let i of e)for(let o of ne(i)){let s=o.union.discriminator??re(o.union,t);if(!s)continue;let c=new Map;for(let a of s.mapping){if(!t.has(a.schemaName))continue;let m=c.get(a.schemaName);m?m.push(a.value):c.set(a.schemaName,[a.value])}for(let[a,m]of c){let l=`is${a}`;if(r.has(l))continue;r.add(l);let p=`(value as Record<string, unknown>)[${JSON.stringify(s.propertyName)}]`,f=m.length===1?`${p} === ${JSON.stringify(m[0])}`:`([${m.map(h=>JSON.stringify(h)).join(", ")}] as readonly unknown[]).includes(${p})`;n.push(["/**",` * Narrow a \`${o.label}\` to \`${a}\` via its \`${s.propertyName}\` discriminant.`," */",`export function ${l}(value: ${o.label}): value is ${a} {`,` return ${f};`,"}"].join(`
|
|
47
|
+
`))}}return n.join(`
|
|
48
|
+
|
|
49
|
+
`)}function ne(e){let t=[],n=e.schema;if(n.kind==="union"){t.push({union:n,label:e.name});for(let r of n.members)g(r,t)}else g(n,t);return t}function g(e,t){switch(e.kind){case"union":{let n=e.members.map(r=>r.kind==="ref"?r.name:void 0);n.every(r=>r!==void 0)&&t.push({union:e,label:n.join(" | ")});for(let r of e.members)g(r,t);break}case"array":g(e.items,t);break;case"record":g(e.value,t);break;case"object":for(let n of e.properties)g(n.schema,t);break;case"intersection":for(let n of e.members)g(n,t);break}}function re(e,t){let n=[];for(let i of e.members){if(i.kind!=="ref"||!t.get(i.name))return;n.push(i.name)}if(n.length<2)return;let r=n.map(i=>ie(t.get(i)));for(let i of Object.keys(r[0])){if(!r.every(s=>i in s))continue;let o=r.map(s=>s[i]);if(o.every(s=>typeof s=="string")&&new Set(o).size===o.length)return{propertyName:i,mapping:n.map((s,c)=>({value:o[c],schemaName:s}))}}}function ie(e){let t={},n=r=>{if(r.kind==="object")for(let i of r.properties)i.schema.kind==="literal"&&(t[i.name]=i.schema.value);else if(r.kind==="intersection")for(let i of r.members)n(i)};return n(e),t}function K(e,t={}){return X(e,t).entry}function Q(e,t){let n=d(e.services);return{multipart:n.some(r=>r.requestBody&&S(r.requestBody)),auth:e.securitySchemes.length>0||n.some(r=>r.security.length>0),sse:n.some(r=>r.sse!==void 0),setup:!!t.setup,paginate:(t.pagination??new Map).size>0}}function V(e,t){return t.runtime!=="module"?[]:_(Q(e,t),t.importExt??"js").map(({name:n,content:r})=>({name:n,content:`${y}
|
|
50
|
+
|
|
51
|
+
${r.trim()}
|
|
52
|
+
`}))}function se(e,t,n){let r=e.importExt??"js",i=["OperationDescriptor",...e.setup?["ClientConfig","Middleware"]:[],...t.errorMode==="result"&&n?["Result"]:[]].sort();return[`import { createClient${e.setup?", mergeSetup":""} } from './runtime/factory.${r}';`,`import type { ${i.join(", ")} } from './runtime/types.${r}';`,`export * from './runtime/factory.${r}';`].join(`
|
|
53
|
+
`)}function W(e,t,n){return X(e,t,n)}function X(e,t,n){let r=d(e.services),i=$(e),o=t.pagination??new Map,s={argsStyle:t.argsStyle??"grouped",errorMode:t.errorMode??"throw",dateType:t.dateType??"string",schemaNames:new Set(e.schemas.map(u=>u.name)),schemas:e.schemas,pagination:o},c=r.length>0?[q(e,i,s),F(e,i,s.dateType,o,s.argsStyle)]:["export type Ops = Record<string, never>;","export const OPERATIONS = {} as const satisfies Record<string, OperationDescriptor>;"],a=t.runtime==="module"?se(t,s,r.length>0):G(Q(e,t)),m=[P(e.schemas,s.dateType),J(e.schemas)].filter(u=>u.length>0).join(`
|
|
54
|
+
|
|
55
|
+
`),l=[...r.map(u=>U(u,s)),...c].filter(u=>u.length>0).join(`
|
|
56
|
+
|
|
57
|
+
`),p=ae(r,i),f=t.runtime==="module";if(n===void 0)return{entry:O([y,M(e),...f?[a]:[],[m,l].filter(u=>u.length>0).join(`
|
|
58
|
+
|
|
59
|
+
`),...f?[]:[a],z(t,s,e),p])};let h=m.length>0;return{entry:O([y,M(e),...f?[a]:[],h?oe(e,s,`./${n}.schemas.${t.importExt??"js"}`):"",l,...f?[]:[a],z(t,s,e),p]),schemas:h?O([y,M(e),m]):void 0}}function oe(e,t,n){let r=B(e,t);return`${r.length>0?`import type { ${r.join(", ")} } from '${n}';
|
|
60
|
+
`:""}export * from '${n}';`}function z(e,t,n){let r=e.serverUrl??n.serverUrl,i=[...r!==void 0?[`serverUrl: ${E(r)}`]:[],...t.errorMode==="result"?['errorMode: "result"']:[],...t.argsStyle==="flat"?['argsStyle: "flat"']:[],'clientHeader: "redocly-client-generator"'],o=i.length>0?`{ ${i.join(", ")} }`:"{}",s=e.setup?`mergeSetup({ config: ${o} }, mergeSetup(__redoclySetup, {}))`:o,c=d(n.services),a=c.some(p=>p.tags.length>0),l=`export const client = createClient${c.length>0?`<Ops, OperationId, OperationPath, ${a?"OperationTag":"string"}>`:"<Ops>"}(OPERATIONS, ${s});`;return e.setup?`// \u2500\u2500\u2500 Baked-in setup (--setup) \u2500\u2500\u2500
|
|
61
|
+
const __redoclySetup: { config?: ClientConfig; middleware?: Middleware[] } = ${e.setup};
|
|
62
|
+
`+l:l}function ae(e,t){let n=["export const { configure, use } = client;"];if(e.length===0)return n.join(`
|
|
63
|
+
`);let r=e.map(i=>t.get(i.name)).join(", ");return n.push(`export const { ${r} } = client;`),n.join(`
|
|
64
|
+
`)}var we=({model:e,output:t,outputMode:n,emit:r})=>{let i=V(e,r).map(({name:o,content:s})=>({path:Y(t.dir,"runtime",o),content:s}));if(n==="split"){let{dir:o,stem:s}=t,{entry:c,schemas:a}=W(e,r,s);return[...a===void 0?[]:[{path:Y(o,`${s}.schemas.ts`),content:a}],{path:t.path,content:c},...i]}return[{path:t.path,content:K(e,r)},...i]},De=({model:e,output:t,emit:n,pagination:r})=>[{path:t.path.replace(/\.[^.\\/]+$/,".typescript.md"),content:b(e,{title:`${e.title} TypeScript client reference`,frontmatter:n.docsFrontmatter===!0,language:{name:"typescript",label:"TypeScript",fence:"typescript",requires:"The client has no dependencies."},sample:i=>pe(i,{model:e,emit:n,outputPath:t.path}),paginated:new Set(r?.keys()??[])})}];function pe(e,t){let n=$(t.model).get(e.name)??e.name,i=`./${t.outputPath.replace(/^.*[\\/]/,"").replace(/\.[^.]+$/,"")}.${t.emit.importExt??"js"}`,o=e.queryParams.filter(p=>p.required),s=t.emit.argsStyle==="flat",c=e.pathParams.map(p=>`${p.name}: '<${p.name}>'`),a=o.map(p=>`${p.name}: /* \u2026 */`),m=s?[...c,...a,...e.requestBody?["/* body properties */"]:[]]:[...c.length>0?[`path: { ${c.join(", ")} }`]:[],...a.length>0?[`query: { ${a.join(", ")} }`]:[],...e.requestBody?["body: { /* \u2026 */ }"]:[]],l=m.length>0?[`{ ${m.join(", ")} }`]:[];return{lang:"typescript",label:"TypeScript SDK",source:`import { ${n} } from '${i}';
|
|
65
|
+
|
|
66
|
+
const result = await ${n}(${l.join(", ")});
|
|
67
|
+
`}}export{De as typescriptDocs,we as typescriptGenerator,pe as typescriptSample};
|
|
@@ -4,7 +4,7 @@ import { dirname as __pathDirname } from 'node:path';
|
|
|
4
4
|
const require = __createRequire(import.meta.url);
|
|
5
5
|
var __filename = __fileURLToPath(import.meta.url);
|
|
6
6
|
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{a as G}from"./
|
|
7
|
+
import{a as G}from"./YP5GHFYE.js";import{c as I,d as N,e as fe,h as q,j as _,k as ue,v as D,w as B}from"./NTPLYWAB.js";import{a as ce,c as pe}from"./T5EPIBMA.js";import{b as ae}from"./2U54VUOE.js";import{B as oe,C as P,O as y,c as b,ca as se,ia as ie,l as $}from"./HJ36YGCI.js";import"./NEWT5A6S.js";import"./RFWIIJFG.js";import{mkdir as Bt,writeFile as zt}from"node:fs/promises";import Ht from"node:path";import*as Ce from"node:process";var Ve=/^[a-zA-Z][a-zA-Z0-9]*(?:[_\-.][a-zA-Z0-9]+)*$/,Fe=/^[0-9a-f-]{8,}$/i,Ye=[["uuid",/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i],["date-time",/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/],["date",/^\d{4}-\d{2}-\d{2}$/],["email",/^[^\s@]+@[^\s@]+\.[^\s@]+$/],["uri",/^https?:\/\/\S+$/],["ipv4",/^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/]],J=new WeakMap;function z(e){return{formats:Ye.filter(([,t])=>t.test(e)).map(([t])=>t),values:[e],count:1,overflow:!1}}function C(e,t){if(!e)return t;if(!t)return e;let r={formats:e.formats.filter(n=>t.formats.includes(n)),values:[],count:e.count+t.count,overflow:e.overflow||t.overflow};if(!r.overflow){let n=[...e.values];for(let o of t.values)n.includes(o)||n.push(o);n.length>10?r.overflow=!0:r.values=n}return r}function H(e,t){J.set(e,t)}function L(e){return J.get(e)}function U(e,t){let r=J.get(e);r&&J.set(t,r)}function Ke(e){return e.length<=30&&!Fe.test(e)&&Ve.test(e)}function W(e,t){return e.formats.length>0?{format:e.formats[0]}:t&&!e.overflow&&e.count>=4&&e.values.length>0&&e.values.length<=5&&e.values.length*2<=e.count&&e.values.every(Ke)?{enum:[...e.values].sort()}:{}}function R(e){let t=J.get(e);if(t){let r=typeof e.type=="string"?[e.type]:e.type??[];r.includes("string")&&Object.assign(e,W(t,r.length===1))}for(let r of Object.values(e.properties??{}))R(r);e.additionalProperties&&R(e.additionalProperties),e.items&&R(e.items);for(let r of e.oneOf??[])R(r)}function me(e){for(let t of Object.values(e.paths))for(let r of Object.values(t)){for(let n of Object.values(r.requestBody?.content??{}))R(n.schema);for(let n of Object.values(r.responses))for(let o of Object.values(n.content??{}))R(o.schema)}for(let t of Object.values(e.components?.schemas??{}))R(t);return e}var be=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,F=/^\d+$/,We=/^[0-9a-hjkmnp-tv-z]{26}$/i,Xe=/^[a-z][a-z0-9]*_(?=[0-9a-z]*\d)[0-9a-z]{10,}$/i,Ze=/^[a-z](?=[a-z0-9]*\d)[a-z0-9]{23,24}$/,Z=new Set(ce),Qe=new Set(["get","head"]),de="application/x-www-form-urlencoded",le="multipart/form-data";function et(e){return e?F.test(e)||be.test(e)||We.test(e)||Xe.test(e)||Ze.test(e)?!0:/^[0-9a-f]{16,}$/i.test(e):!1}function Q(e){let t=e.split("/"),r=[],n=new Set;return{template:t.map((s,a)=>{if(!et(s))return s;let i=t[a-1],c=i?`${$(i,1)}Id`:"id",p=1;for(;n.has(c);)p+=1,c=i?`${$(i,1)}Id${p}`:`id${p}`;return n.add(c),r.push({name:c,value:s}),`{${c}}`}).join("/")||"/",params:r}}function A(e){if(e===null)return{type:"null"};if(Array.isArray(e)){if(e.length===0)return{type:"array"};let t=e.slice(0,20).map(A);return{type:"array",items:x(t)}}switch(typeof e){case"string":{let t={type:"string"};return H(t,z(e)),t}case"boolean":return{type:"boolean"};case"number":return Number.isInteger(e)?{type:"integer"}:{type:"number"};case"object":{let t=Object.entries(e);if(t.length>0&&(t.every(([a])=>F.test(a))||t.every(([a])=>be.test(a))))return{type:"object",additionalProperties:x(t.map(([,a])=>A(a)))};let r={},n=[];for(let[s,a]of t)r[s]=A(a),n.push(s);let o={type:"object",properties:r};return n.length>0&&(o.required=n),o}default:return{}}}function x(e){if(e.length===0)return{};let[t,...r]=e,n=t;for(let o of r)n=V(n,o);return n}function he(e){return Object.keys(e).length===0}function k(e){return e.additionalProperties?"map":e.type==="object"?"object":e.type==="array"?"array":"scalar"}function X(e){return e.oneOf?e.oneOf.flatMap(X):Array.isArray(e.type)?e.type.map(t=>{if(t==="object"){let n={type:"object"};return e.properties&&(n.properties=e.properties),e.required&&(n.required=e.required),e.additionalProperties&&(n.additionalProperties=e.additionalProperties),n}if(t==="array")return e.items?{type:"array",items:e.items}:{type:"array"};let r={type:t};return t==="string"&&U(e,r),r}):[e]}var tt=.5,rt=3;function we(e,t){let r=Object.keys(e.properties??{}),n=Object.keys(t.properties??{});if(r.length===0||n.length===0)return 1;let o=new Set(n),s=r.filter(a=>o.has(a)).length;return s/(r.length+n.length-s)}function nt(e,t){let r=k(e);if(r!==k(t))return!1;switch(r){case"scalar":return e.type===t.type||e.type==="integer"&&t.type==="number"||e.type==="number"&&t.type==="integer";case"object":return we(e,t)>=tt;default:return!0}}function ve(e,t){switch(k(e)){case"scalar":{if(e.type!==t.type)return{type:"number"};if(e.type==="string"){let r=C(L(e),L(t));if(r){let n={type:"string"};return H(n,r),n}}return e}case"map":return{type:"object",additionalProperties:V(e.additionalProperties??{},t.additionalProperties??{})};case"object":{let r={...e.properties??{}};for(let[a,i]of Object.entries(t.properties??{}))r[a]=r[a]?V(r[a],i):i;let n=new Set(t.required??[]),o=(e.required??[]).filter(a=>n.has(a)),s={type:"object",properties:r};return o.length>0&&(s.required=o),s}case"array":{if(!e.items||!t.items){let r=e.items??t.items;return r?{type:"array",items:r}:{type:"array"}}return{type:"array",items:V(e.items,t.items)}}}}function ot(e){let t=[...e],r=()=>t.filter(n=>k(n)==="object").length;for(;r()>rt;){let n=-1,o=-1,s=-1;for(let a=0;a<t.length;a++)if(k(t[a])==="object")for(let i=a+1;i<t.length;i++){if(k(t[i])!=="object")continue;let c=we(t[a],t[i]);c>s&&(s=c,n=a,o=i)}t[n]=ve(t[n],t[o]),t.splice(o,1)}return t}var st=["boolean","integer","number","string","null"];function it(e){if(e.length===1)return e[0];let t=[],r=new Set,n;for(let i of e)k(i)==="scalar"&&typeof i.type=="string"?(r.add(i.type),i.type==="string"&&(n=C(n,L(i)))):t.push(i);let o=st.filter(i=>r.has(i)),s=i=>{let c={type:i};return(typeof i=="string"?i==="string":i.includes("string"))&&n&&H(c,n),c};if(t.length===0)return o.length===1?s(o[0]):s(o);if(t.length===1&&o.length===1&&o[0]==="null"&&typeof t[0].type=="string")return{...t[0],type:[t[0].type,"null"]};let a=[...t];return o.length===1?a.push(s(o[0])):o.length>1&&a.push(s(o)),{oneOf:a}}function V(e,t){if(he(e)||he(t))return{};let r=X(e);for(let n of X(t)){let o=r.findIndex(s=>nt(s,n));o===-1?r.push(n):r[o]=ve(r[o],n)}return it(ot(r))}function at(e){if(!e)return;let t=e.trim();if(!(!t.startsWith("{")&&!t.startsWith("[")))try{return JSON.parse(t)}catch{return}}function ct(e,t){let r=t?.match(/boundary="?([^";,]+)"?/i)?.[1];if(!r)return;let n={};for(let o of e.split(`--${r}`)){let s=o.match(/^\r?\n([\s\S]*?)\r?\n\r?\n([\s\S]*)\r?\n$/);if(!s)continue;let[,a,i]=s,c=a.match(/\bname="([^"]*)"/i)?.[1];c!==void 0&&(n[c]=/\bfilename="/i.test(a)?{type:"string",format:"binary"}:A(i))}if(Object.keys(n).length!==0)return{type:"object",properties:n,required:Object.keys(n)}}function ge(e){let t=_(e.contentType);if(e.bodyJson!==void 0)return{mime:ue(t)?t:"application/json",schema:A(e.bodyJson)};if(t===de&&e.bodyText){let n={};for(let[o,s]of new URLSearchParams(e.bodyText))n[o]=s;return Object.keys(n).length===0?void 0:{mime:de,schema:A(n)}}if(t===le&&e.bodyText){let n=ct(e.bodyText,e.contentType);return n?{mime:le,schema:n}:void 0}let r=at(e.bodyText);if(r!==void 0)return{mime:"application/json",schema:A(r)}}function ye(e,t,r){let n=e.get(t);e.set(t,n?x([n,r]):r)}async function Oe(e){let t=await N(e.trafficPath);if(t.length===0)throw new Error("No traffic files found in the provided traffic path.");let r=D(e.server),n=new Map,o=new Set,s=0,a=c=>{let p=c.request.method.toLowerCase();if(!Z.has(p))return;let f=c.request.path||"/";if(r){let u=B(c.request,r);if(u===void 0)return;f=u}else c.request.host&&!fe(c.request.host)&&o.add(`${c.request.protocol}//${c.request.host}`);let{template:l,params:m}=Q(q(f)),w=`${p} ${l}`,d=n.get(w);d||(d={method:p,template:l,pathParams:new Map,queryParams:new Map,requestBodies:new Map,responses:new Map},n.set(w,d));for(let{name:u,value:h}of m){let g=d.pathParams.get(u);d.pathParams.set(u,{numeric:(g?.numeric??!0)&&F.test(h),observations:C(g?.observations,z(h))})}for(let u of new Set(c.request.query.keys())){let h=c.request.query.getAll(u),g=d.queryParams.get(u),v=h.length>0&&h.every(O=>F.test(O)),S=g?.observations;for(let O of h)S=C(S,z(O));d.queryParams.set(u,{numeric:(g?.numeric??!0)&&v,observations:S})}if(!Qe.has(p)){let u=ge(c.request);u&&ye(d.requestBodies,u.mime,u.schema)}if(c.response&&c.response.status>=100){let u=String(c.response.status),h=d.responses.get(u);h||(h={bodies:new Map},d.responses.set(u,h)),h.statusText??=c.response.statusText||void 0;let g=ge(c.response);g&&ye(h.bodies,g.mime,g.schema)}};for(let c of t){let p=await G(c,e.format);if(!p){y.warn(`Skipping traffic file with unrecognized format: ${c}
|
|
8
8
|
`);continue}s+=1;for await(let f of p.parse(c))a(f)}if(s===0)throw new Error("No supported traffic files found to generate an OpenAPI description from.");if(n.size===0)throw new Error(r?`No HTTP exchanges in the traffic matched the server "${r}".`:"No HTTP exchanges were observed in the traffic. Cannot generate an OpenAPI description.");let i=r?[r]:Array.from(o).sort();return pt(n,e.title??"Generated API",i)}function $e(e){return Object.values(e.paths).reduce((t,r)=>t+Object.keys(r).length,0)}function Se(e,t){if(e.numeric)return{type:"integer"};let r={type:"string"};return e.observations&&Object.assign(r,W(e.observations,t)),r}function pt(e,t,r){let n={};for(let o of e.values()){let s=n[o.template]??={},a=[...Array.from(o.pathParams).map(([c,p])=>({name:c,in:"path",required:!0,schema:Se(p,!1)})),...Array.from(o.queryParams).map(([c,p])=>({name:c,in:"query",required:!1,schema:Se(p,!0)}))],i={operationId:ft(o.method,o.template),responses:{}};if(a.length>0&&(i.parameters=a),o.requestBodies.size>0){let c={};for(let[p,f]of o.requestBodies)c[p]={schema:f};i.requestBody={content:c}}if(o.responses.size===0)i.responses.default={description:"Observed response"};else for(let[c,p]of o.responses){let f={description:p.statusText||"Observed response"};if(p.bodies.size>0){let l={};for(let[m,w]of p.bodies)l[m]={schema:w};f.content=l}i.responses[c]=f}s[o.method]=i}return{openapi:"3.2.0",info:{title:t,version:"1.0.0"},...r.length>0?{servers:r.map(o=>({url:o}))}:{},paths:n}}function ft(e,t){let r=t.split("/").filter(Boolean).map(n=>n.replace(/[{}]/g,"")).join("-");return`${e}-${r||"root"}`}function Y(e,t){return`${e.toUpperCase()} ${t}`}function Pe(e,t){let r;if(e.bodyJson!==void 0)try{r=JSON.stringify(e.bodyJson)}catch{r=void 0}if(r??=e.bodyText,!r)return;let n=r.trim();if(n)return n.length>t?`${n.slice(0,t)}\u2026[truncated]`:n}function Te(e){if(!e)return"";let t=e.bodyJson;return t===void 0?e.bodyText?_(e.contentType)||"text":"":t===null?"null":Array.isArray(t)?`array<${t.length>0?Ee(t[0]):""}>`:Ee(t)}function Ee(e){return b(e)?Object.keys(e).sort().join(","):e===null?"null":typeof e}async function Re(e){let t=e.perGroup??2,r=e.perOperation??4,n=e.maxBodyChars??2e3,o=D(e.server),s=await N(e.trafficPath),a=new Map;for(let c of s){let p=await G(c,e.format);if(p)for await(let f of p.parse(c)){let l=f.request.method.toUpperCase();if(!Z.has(l.toLowerCase()))continue;let m=f.request.path||"/";if(o){let ne=B(f.request,o);if(ne===void 0)continue;m=ne}let w=q(m),{template:d}=Q(w),u=f.response&&f.response.status>=100?f.response:void 0,h=u?.status,g=`${Te(f.request)}\u2192${Te(u)}`,v=a.get(Y(l,d));v||(v=new Map,a.set(Y(l,d),v));let S=`${h??""} ${g}`,O=v.get(S);O||(O=[],v.set(S,O)),!(O.length>=t)&&O.push({method:l,path:w,query:f.request.query.toString(),status:h,requestContentType:f.request.contentType,requestBody:Pe(f.request,n),responseContentType:u?.contentType,responseBody:u?Pe(u,n):void 0})}}let i=new Map;for(let[c,p]of a){let f=[];for(let l=0;l<t&&f.length<r;l++)for(let m of p.values()){if(f.length>=r)break;m[l]&&f.push(m[l])}i.set(c,f)}return i}var ut=`You are an expert API designer. You are given one operation from an OpenAPI 3.2 description that was inferred mechanically from recorded HTTP traffic, the component schemas it references, and a sample of the real recorded HTTP exchanges for that operation. The inferred description is only a hypothesis: types are coarse, every observed property is marked required, and descriptions are missing. Alternative body shapes observed in the traffic appear as "oneOf" variants or type unions. Common string formats (uuid, date-time, date, email, uri, ipv4) and small closed enums are detected conservatively from the observed values.
|
|
9
9
|
|
|
10
10
|
Refine the operation into the most accurate OpenAPI 3.2 definition you can justify from the evidence, while staying conservative:
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import{b as a,c as b,d as c}from"./FUMCRNTK.js";import"./UKSQ7B5H.js";import"./R4XFBOJU.js";import"./OKITK6EF.js";import"./4I2OVMBJ.js";import"./ZMCRMR2V.js";import"./PFYPTG4G.js";import"./HJ36YGCI.js";import"./NEWT5A6S.js";import"./NB54XRRU.js";import"./HJYFWIVE.js";import"./RFWIIJFG.js";export{b as cliDocs,a as cliGenerator,c as cliSample};
|
|
@@ -4,6 +4,6 @@ import { dirname as __pathDirname } from 'node:path';
|
|
|
4
4
|
const require = __createRequire(import.meta.url);
|
|
5
5
|
var __filename = __fileURLToPath(import.meta.url);
|
|
6
6
|
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{b as m,j as C,o as a,p,q as T,r as l,s as h,t as f,u as d}from"./
|
|
7
|
+
import{b as m,j as C,o as a,p,q as T,r as l,s as h,t as f,u as d}from"./NTPLYWAB.js";import{c as g}from"./HJ36YGCI.js";import A from"node:path";function L(e,n){if(C(e)!=="application/x-www-form-urlencoded"||!Array.isArray(n))return;let o=new URLSearchParams;for(let s of n){if(!g(s))continue;let t=a(s.name);t!==void 0&&o.append(t,a(s.value)??"")}return o.size>0?o.toString():void 0}function K(e,n,o){let s=e?.request,t=e?.response;if(!s)return null;let r=s?.postData,i=a(r?.mimeType),u=r?.text??L(i,r?.params),c=a(r?.encoding),y=t?.content?.text,S=a(t?.content?.encoding),q=p(t?.status);return l({method:a(s?.method),url:a(s?.url),requestHeaders:s?.headers,requestBody:T(u,c),requestContentType:i,responseStatus:q===0?void 0:q,responseStatusText:a(t?.statusText),responseHeaders:t?.headers,responseBody:T(y,S),responseContentType:a(t?.content?.mimeType),startedAt:a(e?.startedDateTime),raw:e},n,o)}var b=class{id="har";canParse(n,o){if(A.extname(n).toLowerCase()===".har")return!0;let t=o.toLowerCase();return t.includes('"log"')&&t.includes('"entries"')}async*parse(n){let o=0;for await(let s of f(n,"log.entries")){let t=K(s,o,n);t&&(yield t),o+=1}}};import $ from"node:path";function H(e){let n=a(e.url??e.uri);if(n)return{url:n};let o=a(e.host??e.headers?.host),s=a(e.path??e.request_uri),t=a(e.scheme??e.forwarded_proto);return o&&s?{url:`${t??"http"}://${o}${s}`,schemeKnown:!!t}:{url:s,schemeKnown:!!t}}function z(e,n,o){let s=e?.request??e?.req??e?.http?.request;if(!s)return null;let t=e?.response??e?.res??e?.http?.response,r=t?.body??t?.raw_body??t?.payload??t?.data,i=s?.body??s?.raw_body??s?.payload??s?.data,{url:u,schemeKnown:c}=H(s);return l({method:a(s?.method??s?.http_method),url:u,schemeKnown:c,requestHeaders:s?.headers,requestBody:i,requestContentType:d(s?.headers),responseStatus:p(t?.status??t?.statusCode),responseHeaders:t?.headers,responseBody:r,responseContentType:d(t?.headers),startedAt:a(e?.started_at??e?.startedAt??e?.timestamp),raw:e},n,o)}var x=class{id="kong";canParse(n,o){if($.extname(n).toLowerCase()===".kong")return!0;let t=o.toLowerCase();return t.includes('"latencies"')||t.includes('"request"')&&t.includes('"response"')&&t.includes('"route"')}async*parse(n){let o=(await m(n,16)).trim().slice(0,1),s=0;if(o==="["){for await(let t of f(n)){let r=z(t,s,n);r&&(yield r),s+=1}return}for await(let t of h(n)){let r=z(t,s,n);r&&(yield r),s+=1}}};import R from"node:path";function U(e){return e?.request??e?.req??e?.httpRequest??e?.http?.request??e}function I(e){return e?.response??e?.res??e?.httpResponse??e?.http?.response}function O(e,n){let o=a(n?.url??n?.uri??n?.requestUrl??e?.url);if(o)return{url:o};let s=a(n?.host??n?.headers?.host??e?.host),t=a(n?.path??e?.path??n?.pathname),r=a(n?.scheme??e?.scheme);return s&&t?{url:`${r??"http"}://${s}${t}`,schemeKnown:!!r}:{url:t,schemeKnown:!!r}}function k(e,n,o){let s=U(e),t=I(e),r=s?.body??s?.bodyText??s?.payload??s?.data??s?.rawBody,i=t?.body??t?.bodyText??t?.payload??t?.data??t?.rawBody,{url:u,schemeKnown:c}=O(e,s);return l({method:a(s?.method??s?.httpMethod??e?.method??e?.httpMethod),url:u,schemeKnown:c,requestHeaders:s?.headers,requestBody:r,requestContentType:d(s?.headers),responseStatus:p(t?.status??t?.statusCode??e?.status??e?.statusCode),responseHeaders:t?.headers,responseBody:i,responseContentType:d(t?.headers),startedAt:a(e?.startedAt??e?.timestamp??e?.time),raw:e},n,o)}var w=class{id="ndjson";canParse(n,o){let s=R.extname(n).toLowerCase();if(s===".ndjson"||s===".jsonl"||s===".jsonlines")return!0;let t=o.lastIndexOf(`
|
|
8
8
|
`),i=(t===-1?o:o.slice(0,t)).split(`
|
|
9
9
|
`).map(u=>u.trim()).find(Boolean);if(!i?.startsWith("{")||!i.endsWith("}"))return!1;try{return JSON.parse(i),!0}catch{return!1}}async*parse(n){let o=0;for await(let s of h(n)){let t=k(s,o,n);t&&(yield t),o+=1}}};import J from"node:path";function P(e){if(!e)return{};let n=e.trim().split(/\s+/);return n.length<2?{}:{method:n[0],path:n[1],protocol:n[2]}}function W(e,n){let o=a(n?.url??n?.request_uri??n?.uri??e?.url??e?.request_url??e?.absolute_uri),s=P(a(e?.request??n?.request_line)),t=a(n?.request_uri??n?.uri??n?.path??e?.request_uri??e?.uri)??s.path;if(o?.startsWith("http://")||o?.startsWith("https://"))return{url:o};let r=a(n?.host??n?.headers?.host??e?.host??e?.http_host??e?.server_name??e?.vhost),i=a(e?.scheme??n?.scheme??e?.request_scheme),u=!!i;if(r&&(o||t)){let c=i??"http",y=o??t;return y?.startsWith("/")?{url:`${c}://${r}${y}`,schemeKnown:u}:{url:`${c}://${r}/${y}`,schemeKnown:u}}return{url:o??t,schemeKnown:u}}function E(e,n,o){let s=g(e?.request)?e.request:e,t=g(e?.response)?e.response:void 0,r=P(a(e?.request)),i=a(s?.method??s?.request_method??e?.request_method??e?.method)??r.method,{url:u,schemeKnown:c}=W(e,s);return l({method:i,url:u,schemeKnown:c,requestHeaders:s?.headers??s?.request_headers??e?.request_headers??e?.headers,requestBody:s?.body??s?.request_body??e?.request_body??e?.body,requestContentType:d(s?.headers??s?.request_headers??e?.request_headers),responseStatus:p(t?.status??t?.status_code??e?.status??e?.status_code??e?.response_status),responseHeaders:t?.headers??t?.response_headers??e?.response_headers??e?.headers_out,responseBody:t?.body??t?.response_body??e?.response_body,responseContentType:d(t?.headers??t?.response_headers??e?.response_headers),startedAt:a(e?.time_iso8601??e?.timestamp??e?.time??e?.time_local??e?.["@timestamp"]),raw:e},n,o)}async function*j(e){if((await m(e,16)).trim().slice(0,1)==="["){yield*f(e);return}for await(let o of h(e))yield o}var N=class{id="nginx-json";canParse(n,o){let s=J.extname(n).toLowerCase(),t=n.toLowerCase();if(s===".ndjson"&&t.includes("nginx"))return!0;let r=o.toLowerCase();return r.includes('"request_uri"')||r.includes('"time_iso8601"')||r.includes('"upstream_response_time"')||r.includes('"remote_addr"')}async*parse(n){let o=0;for await(let s of j(n)){let t=E(s,o,n);t&&(yield t),o+=1}}},_=class{id="apache-json";canParse(n,o){let s=J.extname(n).toLowerCase(),t=n.toLowerCase();if(s===".ndjson"&&t.includes("apache"))return!0;let r=o.toLowerCase();return r.includes('"request_method"')||r.includes('"request_uri"')||r.includes('"vhost"')||r.includes('"response_status"')}async*parse(n){let o=0;for await(let s of j(n)){let t=E(s,o,n);t&&(yield t),o+=1}}};var B=[new b,new x,new N,new _,new w];async function le(e,n){if(n!=="auto"){let s=B.find(t=>t.id===n);if(!s)throw new Error(`Unsupported parser format: ${n}`);return s}let o=await m(e);return B.find(s=>s.canParse(e,o))}export{le as a};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import{a as g,b as h,c as r,d as s,e as t,f as u,g as v,h as w,i as x,j as y,k as B,l as C,m as D,n as F,o as G}from"./4I2OVMBJ.js";import{a as z,e as A,h as E}from"./ZMCRMR2V.js";import{a}from"./PFYPTG4G.js";import"./HJ36YGCI.js";import"./NEWT5A6S.js";import{a as b,b as c,c as d,d as e,e as f,f as i,g as j,h as k,i as l,j as m,k as n,l as o,m as p,n as q}from"./HJYFWIVE.js";import"./RFWIIJFG.js";export{x as AUTHORING_HELPER_NAMES,E as GENERATOR_VERSION,a as NotSupportedError,b as Printer,d as RESERVED_WORDS,A as WIRING_NAMES,z as allOperations,c as casing,C as constantCase,y as defineClientSetup,F as defineGenerator,i as deref,k as discriminatorCases,o as docText,n as enumValues,j as flattenAllOf,G as generateClient,B as groupSlug,q as headerCoerceType,e as identifierFor,t as isMultipartBody,l as isNullable,r as jsonSuccessSchema,D as mergeConfig,w as paginationItemSchema,g as paginationRuleFor,h as renderReferencePage,p as resolveSchemaPointer,p as schemaAtPointer,v as securityRequirements,u as serverUrlParts,s as sseResponse,f as uniqueIdentifiers,m as unwrapNullable};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import{a as m}from"./3JJEI7CJ.js";import{a as s}from"./PFYPTG4G.js";import{e as f}from"./RFWIIJFG.js";var e=f(m(),1);if(typeof e.default?.createSourceFile!="function")throw new Error(`Baking a --setup module needs the TypeScript compiler API, but the installed \`typescript\` package${e.default?.version?` (${e.default.version})`:""} does not include it \u2014 TypeScript 7 ships only the native tsc. Install TypeScript 6 for generation (npm i -D typescript@6); your app can still compile the generated client with TypeScript 7.`);var l="@redocly/client-generator";function y(n){let i=e.default.createSourceFile("setup.ts",n,e.default.ScriptTarget.Latest,!0,e.default.ScriptKind.TS),p=[],r,d="defineClientSetup";for(let t of i.statements){if(e.default.isImportDeclaration(t)){let o=t.moduleSpecifier.text;if(o!==l)throw new s(`A --setup file may only import from "${l}"; found "${o}". Setup code may use web globals and the client contract only (keeps the client zero-dependency).`);let a=t.importClause?.namedBindings;if(a&&e.default.isNamedImports(a))for(let c of a.elements)(c.propertyName?.text??c.name.text)==="defineClientSetup"&&(d=c.name.text);continue}if(e.default.isExportAssignment(t)&&!t.isExportEquals){r=g(t.expression,d).getText(i);continue}if(e.default.isExportDeclaration(t)){if(t.moduleSpecifier!==void 0)throw new s(`A --setup file may only import from "${l}"; found "${t.moduleSpecifier.text}". Setup code may use web globals and the client contract only (keeps the client zero-dependency).`);continue}let u=e.default.canHaveModifiers(t)?e.default.getModifiers(t)?.find(o=>o.kind===e.default.SyntaxKind.ExportKeyword):void 0;p.push(u===void 0?t.getText(i):n.slice(u.end,t.getEnd()).trimStart())}if(r===void 0)throw new s("A --setup file must `export default defineClientSetup({ config, middleware })` (or a setup object).");return p.length===0?r:`(() => {
|
|
8
|
+
${p.join(`
|
|
9
|
+
`)}
|
|
10
|
+
return ${r};
|
|
11
|
+
})()`}function g(n,i){return e.default.isCallExpression(n)&&e.default.isIdentifier(n.expression)&&n.expression.text===i&&n.arguments.length===1?n.arguments[0]:n}export{y as bakeSetup};
|