@webority/api-contract 0.161.0 → 0.164.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/dist/call.js +1 -1
- package/dist/emitFile.js +7 -6
- package/dist/emitHubs.js +5 -3
- package/dist/emitSchema.js +3 -3
- package/dist/names.js +2 -2
- package/dist/types/call.d.ts +68 -0
- package/dist/types/emitHubs.d.ts +1 -0
- package/dist/types/emitSchema.d.ts +1 -0
- package/package.json +2 -2
package/dist/call.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=class extends Error{constructor(e){super(e),this.name=`ContractCallError`}},t=/\{([^{}]+)\}/g,n=e=>e instanceof Date?encodeURIComponent(e.toISOString()):encodeURIComponent(typeof e==`object`?JSON.stringify(e):String(e));function r(e){let t=[];for(let[r,i]of Object.entries(e??{})){if(i==null)continue;let e=encodeURIComponent(r);for(let r of Array.isArray(i)?i:[i])r!=null&&t.push(`${e}=${n(r)}`)}return t.join(`&`)}var i=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,a=[`content-type`,`content-length`],o=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function s(t,n,r){if(r===void 0)return n;if(!o(r))throw new e(`${t} needs call headers as an object of header names to string values`);let s=new Set(Object.keys(n??{}).map(e=>e.toLowerCase())),c={...n};for(let[n,o]of Object.entries(r)){if(!i.test(n))throw new e(`${t} has a call header named "${n}", which is not a valid header name`);let r=n.toLowerCase();if(a.includes(r))throw new e(`${t} sets "${n}" as a call header; the body decides it`);if(s.has(r))throw new e(`${t} sets "${n}" twice; set a header the contract declares on the request's headers only`);if(typeof o!=`string`||/[\r\n\0]/.test(o))throw new e(`${t} needs call header "${n}" as a string with no line break`);s.add(r),c[n]=o}return c}function c(t,n){let r=n?.skipErrorLog,i=n?.expectedStatuses;if(r!==void 0&&typeof r!=`boolean`)throw new e(`${t} needs skipErrorLog as true or false`);if(i===void 0)return{skipErrorLog:r,expectedStatuses:void 0};if(!Array.isArray(i)||i.length===0)throw new e(`${t} needs expectedStatuses as a non-empty list of failure statuses`);for(let n of i)if(!Number.isInteger(n)||n<400||n>599)throw new e(`${t} lists ${String(n)} in expectedStatuses; only a failure status from 400 to 599 is expected`);if(new Set(i).size!==i.length)throw new e(`${t} lists a status twice in expectedStatuses`);if(r===!0)throw new e(`${t} sets skipErrorLog and expectedStatuses; skipErrorLog already keeps every failure out of the log`);return{skipErrorLog:r,expectedStatuses:i}}function l(e,t,n){return e.replyKind===`none`||t===204||t===205?void 0:n}function
|
|
1
|
+
var e=class extends Error{constructor(e){super(e),this.name=`ContractCallError`}},t=/\{([^{}]+)\}/g,n=e=>e instanceof Date?encodeURIComponent(e.toISOString()):encodeURIComponent(typeof e==`object`?JSON.stringify(e):String(e));function r(e){let t=[];for(let[r,i]of Object.entries(e??{})){if(i==null)continue;let e=encodeURIComponent(r);for(let r of Array.isArray(i)?i:[i])r!=null&&t.push(`${e}=${n(r)}`)}return t.join(`&`)}var i=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,a=[`content-type`,`content-length`],o=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function s(t,n,r){if(r===void 0)return n;if(!o(r))throw new e(`${t} needs call headers as an object of header names to string values`);let s=new Set(Object.keys(n??{}).map(e=>e.toLowerCase())),c={...n};for(let[n,o]of Object.entries(r)){if(!i.test(n))throw new e(`${t} has a call header named "${n}", which is not a valid header name`);let r=n.toLowerCase();if(a.includes(r))throw new e(`${t} sets "${n}" as a call header; the body decides it`);if(s.has(r))throw new e(`${t} sets "${n}" twice; set a header the contract declares on the request's headers only`);if(typeof o!=`string`||/[\r\n\0]/.test(o))throw new e(`${t} needs call header "${n}" as a string with no line break`);s.add(r),c[n]=o}return c}function c(t,n){let r=n?.skipErrorLog,i=n?.expectedStatuses;if(r!==void 0&&typeof r!=`boolean`)throw new e(`${t} needs skipErrorLog as true or false`);if(i===void 0)return{skipErrorLog:r,expectedStatuses:void 0};if(!Array.isArray(i)||i.length===0)throw new e(`${t} needs expectedStatuses as a non-empty list of failure statuses`);for(let n of i)if(!Number.isInteger(n)||n<400||n>599)throw new e(`${t} lists ${String(n)} in expectedStatuses; only a failure status from 400 to 599 is expected`);if(new Set(i).size!==i.length)throw new e(`${t} lists a status twice in expectedStatuses`);if(r===!0)throw new e(`${t} sets skipErrorLog and expectedStatuses; skipErrorLog already keeps every failure out of the log`);return{skipErrorLog:r,expectedStatuses:i}}function l(t,n){let r=n?.reply,i=n?.replacesSession;if(r!==void 0&&r!==`body`&&r!==`full`)throw new e(`${t} needs reply as "body" or "full"`);if(i!==void 0&&typeof i!=`boolean`)throw new e(`${t} needs replacesSession as true or false`);return{reply:r??`body`,replacesSession:i}}var u=e=>e>=200&&e<300||e===304;function d(e,t,n,r){let i={};for(let[e,t]of Object.entries(n))t!=null&&(i[e.toLowerCase()]=Array.isArray(t)?t.map(String).join(`, `):String(t));return t===304?{status:304,notModified:!0,headers:i,body:void 0}:{status:t,notModified:!1,headers:i,body:f(e,t,r)}}function f(e,t,n){return e.replyKind===`none`||t===204||t===205?void 0:n}function p(n,i,a){let o=`${n.method} ${n.path}`,u=n.path.replace(t,(t,n)=>{let r=i.path?.[n],a=r===void 0?``:String(r);if(a===``)throw new e(`${o} needs a non-empty path value for "${n}"`);if(a===`.`||a===`..`)throw new e(`${o} needs a path value for "${n}" other than "." or ".."`);return encodeURIComponent(a)}),d=r(i.query);return{method:n.method,url:d===``?u:`${u}?${d}`,headers:s(o,i.headers,a?.headers),data:i.body,responseType:n.replyKind===`blob`?`blob`:`json`,...c(o,a),...l(o,a)}}var m=[`page`,`pageSize`,`sortBy`,`sortOrder`,`search`],h=e=>String(e).padStart(2,`0`),g=e=>e instanceof Date?`${e.getFullYear()}-${h(e.getMonth()+1)}-${h(e.getDate())}`:e,_=e=>e==null||typeof e==`string`&&e.trim()===``,v=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Date),y=m;function b(t,n,r){if(!_(r)){if(typeof r==`string`||r instanceof Date)return g(r);throw new e(`listQuery needs "${t}.${n}" as a yyyy-MM-dd string or a Date`)}}function x(t){let n={},{filters:r,...i}=t;for(let e of m){let t=i[e];_(t)||(n[e]=typeof t==`string`?t.trim():t)}n.sortBy===void 0&&delete n.sortOrder;for(let[t,i]of Object.entries(r??{})){if(y.includes(t))throw new e(`listQuery has a filter named "${t}", which the list query reserves (${m.join(`, `)})`);if(Array.isArray(i)){let e=i.filter(e=>!_(e));e.length>0&&(n[t]=e)}else if(v(i)){let e=b(t,`from`,i.from),r=b(t,`to`,i.to);e!==void 0&&(n[`${t}From`]=e),r!==void 0&&(n[`${t}To`]=r)}else i instanceof Date?n[t]=g(i):_(i)||(n[t]=i)}return n}export{e as ContractCallError,p as buildContractRequest,d as contractFullReply,f as contractReply,u as isFullReplyStatus,x as listQuery};
|
package/dist/emitFile.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import{emitHubs as e}from"./emitHubs.js";import{emitType as t,literalType as n,stringEnumMembers as
|
|
1
|
+
import{emitHubs as e}from"./emitHubs.js";import{emitType as t,literalType as n,pad as r,stringEnumMembers as i}from"./emitSchema.js";import{ContractError as a}from"./model.js";import{propertyKey as o,quote as s,typeName as c,uniqueName as l}from"./names.js";var u=[`Blob`,`FormData`,`Record`,`Readonly`,`OperationId`,`OperationTypes`],d=`Blob`,f=[`multipart/form-data`,`application/x-www-form-urlencoded`];function p(t,n){let r=new Set(u),i=/* @__PURE__ */ new Map;for(let e of t.schemas.keys())i.set(e,l(c(e),r));let a=[h(n)];for(let[e,n]of t.schemas)a.push(...m(g(i,e),n,i));let o=t.operations.filter(e=>e.id!==``).map(e=>({operation:e,op:_(c(e.id),r)}));for(let{operation:e,op:t}of o)a.push(v(t,e,i)),a.push(S(t,e,i));return a.push(k(o,i,t.schemas)),a.push(`export type OperationId = keyof typeof operations;`),a.push(A(o)),a.push(...e(t.hubs,i,r)),`${a.join(`
|
|
2
2
|
|
|
3
|
-
`)}\n`}function
|
|
4
|
-
`)}
|
|
5
|
-
`)}
|
|
6
|
-
`)}function k(e){return e.length===0?`export
|
|
7
|
-
`)}export{
|
|
3
|
+
`)}\n`}function m(e,a,s){let c=i(a);if(c===void 0)return[`export type ${e} = ${t(a,s,0)};`];let l=c.map(e=>`${o(e)}: ${n(e)}`),u=`export const ${e} = { ${l.join(`, `)} } as const;`;return[u.length<=140?u:[`export const ${e} = {`,...l.map(e=>`${r(1)}${e},`),`} as const;`].join(`
|
|
4
|
+
`),`export type ${e} = (typeof ${e})[keyof typeof ${e}];`]}function h(e){return`// Generated by @webority/api-contract from ${e.name} (sha256 ${e.sha256}). Do not edit: change the backend contract and generate again.`}function g(e,t){let n=e.get(t);if(n===void 0)throw Error(`no type name was made for schema ${t}`);return n}function _(e,t){for(let n=1;;n+=1){let r=n===1?e:`${e}${n}`,i=`${r}Request`,a=`${r}Response`;if(!t.has(r)&&!t.has(i)&&!t.has(a))return t.add(r),t.add(i),t.add(a),r}}function v(e,t,n){let r=t.parameters.filter(e=>e.place===`path`),i=t.parameters.filter(e=>e.place===`query`),a=t.parameters.filter(e=>e.place===`header`),o=[];return r.length>0&&o.push(y(`path`,r,!1,n)),i.length>0&&o.push(y(`query`,i,!i.some(e=>e.required),n)),a.length>0&&o.push(y(`headers`,a,!a.some(e=>e.required),n)),t.body!==null&&o.push(b(t.body,n)),o.length===0?`export type ${e}Request = Readonly<Record<string, never>>;`:`export type ${e}Request = {\n${o.join(`
|
|
5
|
+
`)}\n};`}function y(e,n,i,a){let s=n.map(e=>`${r(2)}readonly ${o(e.name)}${e.required?``:`?`}: ${t(e.schema,a,2)};`);return[`${r(1)}readonly ${e}${i?`?`:``}: {`,...s,`${r(1)}};`].join(`
|
|
6
|
+
`)}function b(e,t){let n=x(e,t);return`${r(1)}readonly body${e.required?``:`?`}: ${n};`}function x(e,n){return f.includes(T(e.contentType))?`FormData`:e.schema===null?`unknown`:t(e.schema,n,1)}function S(e,t,n){return`export type ${e}Response = ${w(t,n)};`}var C=`undefined`;function w(e,n){let r=[];for(let i of e.replies){if(!i.status.startsWith(`2`))continue;let e=i.schema===null?C:t(i.schema,n,0);r.includes(e)||r.push(e)}return r.length>0?r.join(` | `):C}function T(e){return(e.split(`;`)[0]??``).trim().toLowerCase()}var E=`#/components/schemas/`;function D(e,n,r){let i=/* @__PURE__ */ new Set,a=e;for(;a.$ref?.startsWith(E);){let e=a.$ref.slice(21),t=r.get(e);if(t===void 0||i.has(e))return!1;i.add(e),a=t}return t(a,n,0)===d}function O(e,t,n){let r=!1,i=!1;for(let a of e.replies)a.status.startsWith(`2`)&&a.schema!==null&&(D(a.schema,t,n)?r=!0:i=!0);if(r&&i)throw new a(`${e.method} ${e.path} answers with a file and with JSON; give each its own operation`);return r?`blob`:i?`json`:`none`}function k(e,t,n){return e.length===0?`export const operations = {} as const;`:[`export const operations = {`,...e.flatMap(({operation:e})=>{let i=O(e,t,n),a=o(e.id),c=`${r(1)}${a}: { method: ${s(e.method)}, path: ${s(e.path)}, replyKind: ${s(i)} },`;return c.length<=140?[c]:[`${r(1)}${a}: {`,`${r(2)}method: ${s(e.method)},`,`${r(2)}path: ${s(e.path)},`,`${r(2)}replyKind: ${s(i)},`,`${r(1)}},`]}),`} as const;`].join(`
|
|
7
|
+
`)}function A(e){return e.length===0?`export interface OperationTypes {}`:[`export interface OperationTypes {`,...e.flatMap(({operation:e,op:t})=>{let n=o(e.id),i=`${r(1)}readonly ${n}: { readonly request: ${t}Request; readonly response: ${t}Response };`;return i.length<=140?[i]:[`${r(1)}readonly ${n}: {`,`${r(2)}readonly request: ${t}Request;`,`${r(2)}readonly response: ${t}Response;`,`${r(1)}};`]}),`}`].join(`
|
|
8
|
+
`)}export{p as emitFile};
|
package/dist/emitHubs.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import{emitType as e}from"./emitSchema.js";import{propertyKey as
|
|
2
|
-
`)}function
|
|
3
|
-
`)}function m(
|
|
1
|
+
import{emitType as e,pad as t}from"./emitSchema.js";import{propertyKey as n,quote as r,typeName as i}from"./names.js";var a=[`Method`,`Event`,`Methods`,`Events`,`Invoke`,`On`],o=/^[A-Za-z_$][A-Za-z0-9_$]*$/,s=/* @__PURE__ */ new Set(/* @__PURE__ */ `await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.export.extends.false.finally.for.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.static.super.switch.this.throw.true.try.typeof.var.void.while.with.yield`.split(`.`));function c(e,t,n){let r=[],a=[...e].sort((e,t)=>b(e.name,t.name));for(let e of a){let a=l(i(e.name),n);r.push(...d(a,e,t))}return r}function l(e,t){for(let n=1;;n+=1){let r=n===1?e:`${e}${n}`,i=[r,...a.map(e=>`${r}${e}`)];if(i.every(e=>!t.has(e))){for(let e of i)t.add(e);return r}}}var u=`undefined`;function d(t,n,r){let i=y(n.methods),a=y(n.events),o=[p(t,i,a),`export type ${t}Method = keyof typeof ${t}.methods;`,`export type ${t}Event = keyof typeof ${t}.events;`,h(`${t}Methods`,i,t=>t.result===null?u:e(t.result,r,2),r),h(`${t}Events`,a,()=>u,r)];return i.length>0&&o.push(f(`export type ${t}Invoke = <K extends ${t}Method>(`,[`method: K`,`...args: ${t}Methods[K]["args"]`],`) => Promise<${t}Methods[K]["result"]>;`)),a.length>0&&o.push(f(`export type ${t}On = <K extends ${t}Event>(`,[`event: K`,`handler: (...args: ${t}Events[K]["args"]) => void`],`) => void;`)),o}function f(e,n,r){let i=`${e}${n.join(`, `)}${r}`;if(i.length<=140)return i;let a=(n[n.length-1]??``).startsWith(`...`)?``:`,`;return[e,...n.map((e,r)=>`${t(1)}${e}${r===n.length-1?a:`,`}`),r].join(`
|
|
2
|
+
`)}function p(e,t,n){return[`export const ${e} = {`,...m(`methods`,t),...m(`events`,n),`} as const;`].join(`
|
|
3
|
+
`)}function m(e,i){if(i.length===0)return[`${t(1)}${e}: {},`];let a=i.map(e=>`${n(e.name)}: ${r(e.name)}`),o=`${t(1)}${e}: { ${a.join(`, `)} },`;return o.length<=140?[o]:[`${t(1)}${e}: {`,...a.map(e=>`${t(2)}${e},`),`${t(1)}},`]}function h(e,t,r,i){if(t.length===0)return`export interface ${e} {}`;let a=t.flatMap(e=>g(n(e.name),e.parameters,r(e),i));return[`export interface ${e} {`,...a,`}`].join(`
|
|
4
|
+
`)}function g(e,n,r,i){let a=_(n,i,2).join(`, `),o=`${t(1)}readonly ${e}: { readonly args: readonly [${a}]; readonly result: ${r} };`;if(o.length<=140||o.includes(`
|
|
5
|
+
`))return[o];let s=`${t(2)}readonly args: readonly [${a}];`;if(s.length<=140)return[`${t(1)}readonly ${e}: {`,s,`${t(2)}readonly result: ${r};`,`${t(1)}};`];let c=_(n,i,3).map(e=>`${t(3)}${e},`);return[`${t(1)}readonly ${e}: {`,`${t(2)}readonly args: readonly [`,...c,`${t(2)}];`,`${t(2)}readonly result: ${r};`,`${t(1)}};`]}function _(t,n,r){return t.map((t,i)=>`${v(t.name,i)}: ${e(t.schema,n,r)}`)}function v(e,t){return o.test(e)&&!s.has(e)?e:`arg${t}`}function y(e){return[...e].sort((e,t)=>b(e.name,t.name))}function b(e,t){return e<t?-1:+(e>t)}export{c as emitHubs};
|
package/dist/emitSchema.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{propertyKey as e}from"./names.js";var t=`#/components/schemas/`,n=/* @__PURE__ */ new Map([[`\\`,`\\\\`],[`
|
|
2
|
-
`,`\\n`],[`\r`,`\\r`],[`\u2028`,`\\u2028`],[`\u2029`,`\\u2029`]]),r=/[\\
|
|
3
|
-
`)}\n${P(r)}}`;return s===void 0?l:`${l} & Readonly<Record<string, ${s}>>`}function b(e,t,n){let r=x(e),a=[];r===!0?a.push(`unknown`):r!==void 0&&r!==!1&&a.push(i(r,t,n));for(let r of Object.values(e.patternProperties??{}))a.push(i(r,t,n));if(a.length!==0)return a.includes(`unknown`)?`unknown`:[...new Set(a)].join(` | `)}function x(e){return e.additionalProperties??e.unevaluatedProperties}function S(e){return h(e).includes(`object`)?!0:m(e).length===0&&(C(e)||w(e))}function C(e){return Object.keys(e.properties??{}).length>0}function w(e){let t=x(e);return t===!0||typeof t==`object`||Object.keys(e.patternProperties??{}).length>0}function T(e){return e.oneOf??e.anyOf}function E(e){return k(e)&&!M(e)?`union`:D(e)}function D(e){if(e.$ref!==void 0||O(e)!==void 0)return`plain`;if(e.enum!==void 0)return e.enum.length>1?`union`:`plain`;if(e.allOf!==void 0){let[t,...n]=e.allOf;return t===void 0?`plain`:n.length===0?E(t):`intersection`}let t=T(e);if(t!==void 0){let[e,...n]=t;return e===void 0?`plain`:n.length===0?E(e):`union`}return h(e).length>1?`union`:S(e)&&C(e)&&w(e)?`intersection`:`plain`}function O(e){let t=e.const;return t===null||typeof t==`string`||typeof t==`number`||typeof t==`boolean`?t:void 0}function k(e){return e.nullable===!0||A(e)||j(e)}function A(e){if(!m(e).includes(`null`))return!1;let t=O(e)===void 0&&e.enum===void 0&&e.allOf===void 0&&T(e)===void 0;return e.$ref!==void 0||t}function j(e){return e.$ref!==void 0&&(T(e)?.some(e=>N(e))??!1)}function M(e){if(e.$ref!==void 0)return!1;if(O(e)!==void 0)return e.const===null;if(e.enum!==void 0)return e.enum.includes(null);if(e.allOf!==void 0){let[t,...n]=e.allOf;return t!==void 0&&n.length===0&&N(t)}let t=T(e);return t===void 0?m(e).length>0&&h(e).length===0:t.some(e=>N(e))}function N(e){return k(e)||M(e)}function P(e){return`
|
|
1
|
+
import{propertyKey as e}from"./names.js";var t=`#/components/schemas/`,n=/* @__PURE__ */ new Map([[`\\`,`\\\\`],[`"`,`\\"`],[`
|
|
2
|
+
`,`\\n`],[`\r`,`\\r`],[`\u2028`,`\\u2028`],[`\u2029`,`\\u2029`]]),r=/[\\"\n\r\u2028\u2029]/g;function i(e,t,n){let r=a(e,t,n);return!k(e)||M(e)?r:D(e)===`intersection`?`(${r}) | null`:`${r} | null`}function a(e,t,n){if(e.$ref!==void 0)return o(e.$ref,t);let r=O(e);if(r!==void 0)return l(r);if(e.enum!==void 0)return s(e.enum);if(e.allOf!==void 0)return d(e.allOf,t,n);let a=T(e);return a===void 0?f(e,t,n):a.length===0?`never`:a.map(e=>i(e,t,n)).join(` | `)}function o(e,n){return e.startsWith(t)?n.get(e.slice(21))??`unknown`:`unknown`}function s(e){return e.length===0?`never`:e.map(l).join(` | `)}function c(e){if(e.$ref!==void 0||e.const!==void 0||e.allOf!==void 0||T(e)!==void 0||e.nullable===!0||e.type!==void 0&&e.type!==`string`)return;let t=e.enum;if(t===void 0||t.length===0)return;let n=[];for(let e of t){if(typeof e!=`string`)return;n.push(e)}return[...new Set(n)]}function l(e){return e===null?`null`:typeof e==`string`?`"${e.replace(r,u)}"`:String(e)}function u(e){return n.get(e)??e}function d(e,t,n){let[r,...a]=e;return r===void 0?`unknown`:a.length===0?i(r,t,n):e.map(e=>{let r=i(e,t,n);return E(e)===`union`?`(${r})`:r}).join(` & `)}function f(e,t,n){let r=h(e);return r.length>0?r.map(r=>p(r,e,t,n)).join(` | `):m(e).length>0?`null`:e.contentMediaType!==void 0&&e.contentEncoding===void 0?`Blob`:S(e)?y(e,t,n):`unknown`}function p(e,t,n,r){return e===`string`?t.format===`binary`?`Blob`:`string`:e===`integer`||e===`number`?`number`:e===`boolean`?`boolean`:e===`array`?g(t,n,r):e===`object`?y(t,n,r):`unknown`}function m(e){let t=e.type;return t===void 0?[]:typeof t==`string`?[t]:t}function h(e){let t=/* @__PURE__ */ new Set,n=[];for(let r of m(e)){let e=r===`integer`?`number`:r;r!==`null`&&!t.has(e)&&(t.add(e),n.push(r))}return n}function g(e,t,n){let r=e.prefixItems??[];if(r.length>0)return _(e,r,t,n);let a=e.items;if(a===void 0||a===!0)return`readonly unknown[]`;if(a===!1)return`readonly never[]`;let o=i(a,t,n);return E(a)===`plain`&&!o.startsWith(`readonly `)?`readonly ${o}[]`:`readonly (${o})[]`}function _(e,t,n,r){let a=e.minItems??t.length,o=t.map((e,t)=>{let o=i(e,n,r);return t<a?o:E(e)===`plain`?`${o}?`:`(${o})?`}),s=v(e,t.length,n,r);return`readonly [${(s===void 0?o:[...o,s]).join(`, `)}]`}function v(e,t,n,r){let a=e.items;if(a===!1)return;if(a===void 0)return e.maxItems!==void 0&&e.maxItems<=t?void 0:`...unknown[]`;if(a===!0)return`...unknown[]`;let o=i(a,n,r);return E(a)===`plain`&&!o.startsWith(`readonly `)?`...${o}[]`:`...(${o})[]`}function y(t,n,r){let a=t.properties??{},o=Object.entries(a),s=b(t,n,r);if(o.length===0)return`Readonly<Record<string, ${s??`unknown`}>>`;let c=new Set(t.required??[]),l=`{\n${o.map(([t,a])=>{let o=c.has(t)?``:`?`;return`${P(r+1)}readonly ${e(t)}${o}: ${i(a,n,r+1)};`}).join(`
|
|
3
|
+
`)}\n${P(r)}}`;return s===void 0?l:`${l} & Readonly<Record<string, ${s}>>`}function b(e,t,n){let r=x(e),a=[];r===!0?a.push(`unknown`):r!==void 0&&r!==!1&&a.push(i(r,t,n));for(let r of Object.values(e.patternProperties??{}))a.push(i(r,t,n));if(a.length!==0)return a.includes(`unknown`)?`unknown`:[...new Set(a)].join(` | `)}function x(e){return e.additionalProperties??e.unevaluatedProperties}function S(e){return h(e).includes(`object`)?!0:m(e).length===0&&(C(e)||w(e))}function C(e){return Object.keys(e.properties??{}).length>0}function w(e){let t=x(e);return t===!0||typeof t==`object`||Object.keys(e.patternProperties??{}).length>0}function T(e){return e.oneOf??e.anyOf}function E(e){return k(e)&&!M(e)?`union`:D(e)}function D(e){if(e.$ref!==void 0||O(e)!==void 0)return`plain`;if(e.enum!==void 0)return e.enum.length>1?`union`:`plain`;if(e.allOf!==void 0){let[t,...n]=e.allOf;return t===void 0?`plain`:n.length===0?E(t):`intersection`}let t=T(e);if(t!==void 0){let[e,...n]=t;return e===void 0?`plain`:n.length===0?E(e):`union`}return h(e).length>1?`union`:S(e)&&C(e)&&w(e)?`intersection`:`plain`}function O(e){let t=e.const;return t===null||typeof t==`string`||typeof t==`number`||typeof t==`boolean`?t:void 0}function k(e){return e.nullable===!0||A(e)||j(e)}function A(e){if(!m(e).includes(`null`))return!1;let t=O(e)===void 0&&e.enum===void 0&&e.allOf===void 0&&T(e)===void 0;return e.$ref!==void 0||t}function j(e){return e.$ref!==void 0&&(T(e)?.some(e=>N(e))??!1)}function M(e){if(e.$ref!==void 0)return!1;if(O(e)!==void 0)return e.const===null;if(e.enum!==void 0)return e.enum.includes(null);if(e.allOf!==void 0){let[t,...n]=e.allOf;return t!==void 0&&n.length===0&&N(t)}let t=T(e);return t===void 0?m(e).length>0&&h(e).length===0:t.some(e=>N(e))}function N(e){return k(e)||M(e)}function P(e){return` `.repeat(e)}export{i as emitType,l as literalType,P as pad,c as stringEnumMembers};
|
package/dist/names.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=/[^\p{L}\p{Nd}]+/u,t=/^\p{Nd}/u,n=/^[A-Za-z_$][A-Za-z0-9_$]*$/,r=/* @__PURE__ */ new Map([[`\\`,`\\\\`],[`
|
|
2
|
-
`,`\\n`],[`\r`,`\\r`],[`\u2028`,`\\u2028`],[`\u2029`,`\\u2029`]]),i=/[\\
|
|
1
|
+
var e=/[^\p{L}\p{Nd}]+/u,t=/^\p{Nd}/u,n=/^[A-Za-z_$][A-Za-z0-9_$]*$/,r=/* @__PURE__ */ new Map([[`\\`,`\\\\`],[`"`,`\\"`],[`
|
|
2
|
+
`,`\\n`],[`\r`,`\\r`],[`\u2028`,`\\u2028`],[`\u2029`,`\\u2029`]]),i=/[\\"\n\r\u2028\u2029]/g;function a(n){let r=n.split(e).filter(e=>e!==``).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return r===``?`Unnamed`:t.test(r)?`_${r}`:r}function o(e,t){let n=e;for(let r=2;t.has(n);r++)n=`${e}${r}`;return t.add(n),n}function s(e){return e===`__proto__`?`[${c(e)}]`:n.test(e)?e:`"${e.replace(i,e=>r.get(e)??e)}"`}function c(e){return`"${e.replace(i,e=>r.get(e)??e)}"`}export{s as propertyKey,c as quote,a as typeName,o as uniqueName};
|
package/dist/types/call.d.ts
CHANGED
|
@@ -21,7 +21,29 @@ export interface ContractCallOptions {
|
|
|
21
21
|
readonly skipErrorLog?: boolean | undefined;
|
|
22
22
|
/** Failure statuses the caller handles itself: one still rejects, and the client logs it as handled, not as an error. */
|
|
23
23
|
readonly expectedStatuses?: readonly number[] | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* `"full"` resolves to the status, the headers and the body (`ContractFullReply`), and a 304 resolves as
|
|
26
|
+
* `notModified` instead of rejecting. The default `"body"` resolves to the body alone.
|
|
27
|
+
*/
|
|
28
|
+
readonly reply?: "body" | "full" | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The call ends the current session and answers with a new one (a workspace switch, a reissue after a security
|
|
31
|
+
* change); the client stores the new tokens before the call resolves.
|
|
32
|
+
*/
|
|
33
|
+
readonly replacesSession?: boolean | undefined;
|
|
24
34
|
}
|
|
35
|
+
/** A call's whole reply, asked for with `reply: "full"`. Header names are lower case. */
|
|
36
|
+
export type ContractFullReply<TBody> = {
|
|
37
|
+
readonly status: 304;
|
|
38
|
+
readonly notModified: true;
|
|
39
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
40
|
+
readonly body: undefined;
|
|
41
|
+
} | {
|
|
42
|
+
readonly status: number;
|
|
43
|
+
readonly notModified: false;
|
|
44
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
45
|
+
readonly body: TBody;
|
|
46
|
+
};
|
|
25
47
|
export interface ContractRequest {
|
|
26
48
|
readonly method: OperationEntry["method"];
|
|
27
49
|
/** The path with its values filled in, and the query string when the request has one. */
|
|
@@ -31,10 +53,19 @@ export interface ContractRequest {
|
|
|
31
53
|
readonly responseType: "json" | "blob";
|
|
32
54
|
readonly skipErrorLog: boolean | undefined;
|
|
33
55
|
readonly expectedStatuses: readonly number[] | undefined;
|
|
56
|
+
readonly reply: "body" | "full";
|
|
57
|
+
readonly replacesSession: boolean | undefined;
|
|
34
58
|
}
|
|
35
59
|
export declare class ContractCallError extends Error {
|
|
36
60
|
constructor(message: string);
|
|
37
61
|
}
|
|
62
|
+
/** True for the statuses a `reply: "full"` call resolves with: any 2xx, and 304. */
|
|
63
|
+
export declare const isFullReplyStatus: (status: number) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The whole reply of a `reply: "full"` call. A 304 carries no body; any other status carries what `contractReply`
|
|
66
|
+
* gives. Each header is a string under its lower-case name; a header sent more than once is joined with ", ".
|
|
67
|
+
*/
|
|
68
|
+
export declare function contractFullReply<TReply>(entry: OperationEntry, status: number, headers: Readonly<Record<string, unknown>>, data: TReply): ContractFullReply<TReply>;
|
|
38
69
|
/**
|
|
39
70
|
* The reply a call resolves to: nothing for an operation that answers with no body or for a 204 or 205 (axios hands
|
|
40
71
|
* those over as an empty string or an empty Blob), otherwise the body. It keeps the reply type the caller reads the
|
|
@@ -43,3 +74,40 @@ export declare class ContractCallError extends Error {
|
|
|
43
74
|
*/
|
|
44
75
|
export declare function contractReply<TReply>(entry: OperationEntry, status: number, data: TReply): TReply;
|
|
45
76
|
export declare function buildContractRequest(entry: OperationEntry, request: OperationShape["request"], options?: ContractCallOptions): ContractRequest;
|
|
77
|
+
/** The list params a list operation reads beside its filters (Webority.Delivery `PagedListRequest` plus `search`). */
|
|
78
|
+
declare const LIST_RESERVED: readonly ["page", "pageSize", "sortBy", "sortOrder", "search"];
|
|
79
|
+
type ListReserved = (typeof LIST_RESERVED)[number];
|
|
80
|
+
type QueryValue<TQuery, K> = K extends keyof TQuery ? Exclude<TQuery[K], undefined | null> : never;
|
|
81
|
+
/** A filter key with a `<key>From` and a `<key>To` param in the operation's query: a date range. */
|
|
82
|
+
type RangeKey<TQuery> = {
|
|
83
|
+
[K in keyof TQuery & string]: K extends `${infer Base}From` ? (`${Base}To` extends keyof TQuery ? Base : never) : never;
|
|
84
|
+
}[keyof TQuery & string];
|
|
85
|
+
type ListFilters<TQuery> = {
|
|
86
|
+
readonly [K in Exclude<keyof TQuery & string, ListReserved>]?: QueryValue<TQuery, K> | (QueryValue<TQuery, K> extends readonly unknown[] ? never : "") | null | undefined;
|
|
87
|
+
} & {
|
|
88
|
+
readonly [K in RangeKey<TQuery>]?: {
|
|
89
|
+
readonly from?: string | Date | null | undefined;
|
|
90
|
+
readonly to?: string | Date | null | undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
};
|
|
93
|
+
/** The input of `listQuery`: each key the operation's query declares, typed as it declares it. */
|
|
94
|
+
export interface ContractListQueryInput<TQuery> {
|
|
95
|
+
readonly page?: QueryValue<TQuery, "page"> | undefined;
|
|
96
|
+
readonly pageSize?: QueryValue<TQuery, "pageSize"> | undefined;
|
|
97
|
+
readonly sortBy?: QueryValue<TQuery, "sortBy"> | undefined;
|
|
98
|
+
readonly sortOrder?: QueryValue<TQuery, "sortOrder"> | undefined;
|
|
99
|
+
readonly search?: QueryValue<TQuery, "search"> | undefined;
|
|
100
|
+
readonly filters?: ListFilters<TQuery> | undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The `query` of one list call, typed as the operation declares it, so it goes into the caller with no cast:
|
|
104
|
+
* `call("Team_Removed", { query: listQuery<Q>({ page, sortBy, search, filters: { status } }) })`.
|
|
105
|
+
*
|
|
106
|
+
* Blank values are left out, so a cleared filter sends nothing; `search` is trimmed; `sortOrder` goes out only with
|
|
107
|
+
* `sortBy`. A date range `{ from, to }` on a filter whose `<name>From` and `<name>To` the query declares is written
|
|
108
|
+
* as those two params, a `Date` as yyyy-MM-dd. A list filter keeps its non-blank items.
|
|
109
|
+
*
|
|
110
|
+
* @throws ContractCallError when a filter is named page, pageSize, sortBy, sortOrder or search.
|
|
111
|
+
*/
|
|
112
|
+
export declare function listQuery<TQuery>(input: ContractListQueryInput<TQuery>): TQuery;
|
|
113
|
+
export {};
|
package/dist/types/emitHubs.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export declare function isUnion(schema: SchemaObject): boolean;
|
|
|
4
4
|
export declare function emitType(schema: SchemaObject, names: ReadonlyMap<string, string>, indent: number): string;
|
|
5
5
|
export declare function stringEnumMembers(schema: SchemaObject): readonly string[] | undefined;
|
|
6
6
|
export declare function literalType(value: Literal): string;
|
|
7
|
+
export declare function pad(level: number): string;
|
|
7
8
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/api-contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.164.0",
|
|
4
4
|
"description": "Generates one TypeScript file of API types from a backend OpenAPI 3.0, 3.1 or 3.2 contract, as plain text, with no runtime dependencies.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "25.6.0",
|
|
30
|
-
"@webority/biome-config": "0.
|
|
30
|
+
"@webority/biome-config": "0.164.0",
|
|
31
31
|
"typescript": "^7.0.2",
|
|
32
32
|
"vite": "^8.3.6",
|
|
33
33
|
"vitest": "5.1.0"
|