@adhd/apigen-codegen-openapi 0.2.6 → 0.2.7
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/CHANGELOG.md +4 -0
- package/index.js +12 -1
- package/index.mjs +76 -45
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## 0.2.7 (2026-10-21)
|
|
2
|
+
|
|
3
|
+
This was a version bump only for apigen-codegen-openapi to align it with other projects, there were no code changes.
|
|
4
|
+
|
|
1
5
|
## 0.2.6 (2026-10-15)
|
|
2
6
|
|
|
3
7
|
This was a version bump only for apigen-codegen-openapi to align it with other projects, there were no code changes.
|
package/index.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("node:fs");let e=require("node:module");require("node:path"),(0,e.createRequire)(require("node:url").pathToFileURL(__filename).href);var t={id:`date-time`,kind:`scalar`,schema:{type:`string`,format:`date-time`},matches(e){return e.type===`string`&&e.format===`date-time`},ownsValue(e){return e instanceof Date},encode(e,t,n){return e.toISOString()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);return new Date(String(e))}if(n.mode===`strict`&&Number.isNaN(new Date(e).getTime()))throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);return new Date(e)}},n={id:`int64`,kind:`scalar`,schema:{type:`string`,format:`int64`},matches(e){return e.type===`string`&&e.format===`int64`},ownsValue(e){return typeof e==`bigint`},encode(e,t,n){return String(e)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(n.mode===`strict`)return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}};function r(e){return e}var i={id:`decimal`,kind:`scalar`,schema:{type:`string`,format:`decimal`},matches(e){return e.type===`string`&&e.format===`decimal`},encode(e,t,n){return e},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);return r(String(e))}if(n.mode===`strict`&&!/^-?\d+(\.\d+)?$/.test(e))throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);return r(e)}},a={id:`byte`,kind:`scalar`,schema:{type:`string`,format:`byte`},matches(e){return e.type===`string`&&e.format===`byte`},ownsValue(e){return e instanceof Uint8Array},encode(e,t,n){return Buffer.from(e).toString(`base64`)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);return new Uint8Array}if(n.mode===`strict`&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,`base64`))}},o=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,s={id:`uuid`,kind:`scalar`,schema:{type:`string`,format:`uuid`},matches(e){return e.type===`string`&&e.format===`uuid`},encode(e,t,n){return e.toLowerCase()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e).toLowerCase()}if(n.mode===`strict`&&!o.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},c=`NaN`,l=`Infinity`,u=`-Infinity`,d=new Set([c,l,u]);t.id,n.id,i.id,a.id,s.id,{id:`number-special`,kind:`scalar`,schema:{type:`number`},matches(e){return e.type===`number`&&e.format===void 0},ownsValue(e){return typeof e==`number`&&!Number.isFinite(e)},encode(e,t,n){return Number.isNaN(e)?c:e===1/0?l:e===-1/0?u:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===c)return NaN;if(e===l)return 1/0;if(e===u)return-1/0;let t=Number(e);if(!Number.isNaN(t))return t}if(n.mode===`strict`)throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...d].join(`, `)}.`);return NaN}}.id,Object.freeze({typescript:{"date-time":{encode:`$.toISOString()`,decode:`new Date($)`,mode:`native`},int64:{encode:`String($)`,decode:`BigInt($)`,mode:`native`},decimal:{encode:`$.toString()`,decode:`new Decimal($)`,imports:[],dep:{name:`decimal.js`,version:`^10`},mode:`branded`},byte:{encode:`Buffer.from($).toString('base64')`,decode:`new Uint8Array(Buffer.from($, 'base64'))`,mode:`native`},uuid:{encode:`$.toLowerCase()`,decode:`$`,mode:`native`},"number-special":{encode:`numToWire($)`,decode:`wireToNum($)`,mode:`native`}},python:{"date-time":{encode:`$.isoformat()`,decode:`datetime.fromisoformat($)`,imports:[`from datetime import datetime`],mode:`native`},int64:{encode:`str($)`,decode:`int($)`,mode:`native`},decimal:{encode:`str($)`,decode:`Decimal($)`,imports:[`from decimal import Decimal`],mode:`native`},byte:{encode:`b64encode($).decode()`,decode:`b64decode($)`,imports:[`from base64 import b64encode, b64decode`],mode:`native`},uuid:{encode:`str($)`,decode:`UUID($)`,imports:[`from uuid import UUID`],mode:`native`},"number-special":{encode:`num_to_wire($)`,decode:`wire_to_num($)`,mode:`native`}},rust:{"date-time":{encode:`__SCAFFOLD_RUST_DATETIME_ENCODE__`,decode:`__SCAFFOLD_RUST_DATETIME_DECODE__`,imports:[`use chrono::{DateTime, Utc};`],dep:{name:`chrono`,version:`^0.4`},mode:`lib`},int64:{encode:`__SCAFFOLD_RUST_INT64_ENCODE__`,decode:`__SCAFFOLD_RUST_INT64_DECODE__`,imports:[`use serde_with::DisplayFromStr;`],dep:{name:`serde_with`,version:`^3`},mode:`lib`},decimal:{encode:`__SCAFFOLD_RUST_DECIMAL_ENCODE__`,decode:`__SCAFFOLD_RUST_DECIMAL_DECODE__`,imports:[`use rust_decimal::Decimal;`],dep:{name:`rust_decimal`,version:`^1`},mode:`lib`},byte:{encode:`__SCAFFOLD_RUST_BYTE_ENCODE__`,decode:`__SCAFFOLD_RUST_BYTE_DECODE__`,imports:[`use serde_with::base64::Base64;`],dep:{name:`serde_with`,version:`^3`},mode:`lib`},uuid:{encode:`__SCAFFOLD_RUST_UUID_ENCODE__`,decode:`__SCAFFOLD_RUST_UUID_DECODE__`,imports:[`use uuid::Uuid;`],dep:{name:`uuid`,version:`^1`},mode:`lib`},"number-special":{encode:`__SCAFFOLD_RUST_NUMSPECIAL_ENCODE__`,decode:`__SCAFFOLD_RUST_NUMSPECIAL_DECODE__`,mode:`native`}},go:{"date-time":{encode:`__SCAFFOLD_GO_DATETIME_ENCODE__`,decode:`__SCAFFOLD_GO_DATETIME_DECODE__`,imports:[`"time"`],mode:`native`},int64:{encode:`__SCAFFOLD_GO_INT64_ENCODE__`,decode:`__SCAFFOLD_GO_INT64_DECODE__`,imports:[`"strconv"`],mode:`native`},decimal:{encode:`__SCAFFOLD_GO_DECIMAL_ENCODE__`,decode:`__SCAFFOLD_GO_DECIMAL_DECODE__`,imports:[`"github.com/shopspring/decimal"`],dep:{name:`github.com/shopspring/decimal`,version:`v1`},mode:`lib`},byte:{encode:`__SCAFFOLD_GO_BYTE_ENCODE__`,decode:`__SCAFFOLD_GO_BYTE_DECODE__`,imports:[`"encoding/base64"`],mode:`native`},uuid:{encode:`__SCAFFOLD_GO_UUID_ENCODE__`,decode:`__SCAFFOLD_GO_UUID_DECODE__`,imports:[`"github.com/google/uuid"`],dep:{name:`github.com/google/uuid`,version:`v1`},mode:`lib`},"number-special":{encode:`__SCAFFOLD_GO_NUMSPECIAL_ENCODE__`,decode:`__SCAFFOLD_GO_NUMSPECIAL_DECODE__`,mode:`native`}},java:{"date-time":{encode:`$.toString()`,decode:`Instant.parse($)`,imports:[`import java.time.Instant;`],dep:{name:`jackson-datatype-jsr310`,version:`2.x`},mode:`lib`},int64:{encode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,decode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,imports:[`import com.fasterxml.jackson.annotation.JsonFormat;`],mode:`native`},decimal:{encode:`@JsonSerialize(using = ToStringSerializer.class)`,decode:`new BigDecimal($)`,imports:[`import java.math.BigDecimal;`,`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;`],mode:`native`},byte:{encode:`$`,decode:`$`,mode:`native`},uuid:{encode:`$.toString()`,decode:`UUID.fromString($)`,imports:[`import java.util.UUID;`],mode:`native`},"number-special":{encode:`@JsonSerialize(using = NumberSpecialSerializer.class)`,decode:`@JsonDeserialize(using = NumberSpecialDeserializer.class)`,imports:[`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.annotation.JsonDeserialize;`],mode:`native`}}});var f=new Set([`string`,`number`,`boolean`,`integer`]);function p(e){if(!Array.isArray(e)||e.length<2)return!1;let t=0;for(let n of e){if(typeof n!=`object`||!n)return!1;let{type:e,$ref:r,oneOf:i,anyOf:a,allOf:o}=n;if(r!==void 0||i||a||o)return!1;if(e!==`null`){if(typeof e==`string`&&f.has(e)){t++;continue}return!1}}return t===1}function m(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.$ref!==void 0||t.allOf)return!1;if(t.oneOf||t.anyOf)return p(t.oneOf??t.anyOf);let{type:n}=t;return typeof n==`string`?f.has(n):Array.isArray(n)?n.every(e=>f.has(e)||e===`null`):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(e=>[`string`,`number`,`boolean`].includes(typeof e)):!1}function h(e){if(!e||typeof e!=`object`)return!1;let t=e.properties;return t===void 0||typeof t!=`object`||!t?!1:Object.values(t).every(m)}var g={"decimal.js":`Decimal`};function _(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}Object.entries(g).map(([e,t])=>({pattern:RegExp(`import\\(["'][^"']*${_(e)}[^"']*["']\\)\\.\\w+`,`g`),key:t}));function v(e){return e.words.join(`-`)}function y(e){return e.words.map(S).join(``)}function b(e){return e.words.join(`_`)}function x(e,t={}){let n=[e.namespace,...e.path],r=e.safe||h(e.input)?`GET`:`POST`,i=t.http?.verb?.[e.id]??r,a=`/`+n.map(e=>v(e)).join(`/`),o=n.map(e=>b(e)).join(`_`),s=n.map(e=>b(e)).slice(0,-1).join(`.`),c=y(n[n.length-2]??n[0]),l=y(n[n.length-1]),u=n.map(e=>v(e));return{http:{verb:i,route:a},mcp:{name:o},grpc:{package:s,service:c,method:l},cli:{path:u}}}function S(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function C(e,t={}){let n=t.title??`API`,r=t.version??`0.0.0`,i={};for(let t of e){let{verb:e,route:n}=x(t).http,r=e.toLowerCase(),a={operationId:t.id,summary:t.id,responses:{200:w(t.output)}};if(e===`GET`)a.parameters=T(t.input);else{let e=t.input;typeof e==`object`&&e&&Object.keys(e).length>0&&(a.requestBody={required:!0,content:{"application/json":{schema:e}}})}i[n]===void 0&&(i[n]={}),i[n][r]=a}return{openapi:`3.1.0`,info:{title:n,version:r},paths:i}}function w(e){return typeof e==`object`&&e&&Object.keys(e).length>0?{description:`Success`,content:{"application/json":{schema:e}}}:{description:`Success`}}function T(e){if(typeof e!=`object`||!e||typeof e.properties!=`object`||e.properties===null)return[];let t=Array.isArray(e.required)?e.required:[],n=e.properties;return Object.entries(n).map(([e,n])=>({name:e,in:`query`,required:t.includes(e),schema:n}))}var E=`@adhd/apigen-codegen-openapi`;exports.__apigen_pkg=E,exports.toOpenApi=C;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("node:fs");let e=require("node:module");require("node:path"),(0,e.createRequire)(require("node:url").pathToFileURL(__filename).href);var t=`$apigen`;`
|
|
2
|
+
function __apigenEnvelopeEncode(v) {
|
|
3
|
+
// Schema-less position: pass typed JSON through unchanged. A richer host
|
|
4
|
+
// prelude may wrap recognized runtime types as { ${JSON.stringify(t)}: id, v }.
|
|
5
|
+
return v;
|
|
6
|
+
}
|
|
7
|
+
function __apigenEnvelopeDecode(w) {
|
|
8
|
+
return w != null && typeof w === 'object' && ${JSON.stringify(t)} in w
|
|
9
|
+
? w.v
|
|
10
|
+
: w;
|
|
11
|
+
}
|
|
12
|
+
`.trim(),Object.freeze({"date-time":{encode:`$.toISOString()`,decode:`new Date($)`,mode:`native`},int64:{encode:`String($)`,decode:`BigInt($)`,mode:`native`},byte:{encode:`Buffer.from($).toString('base64')`,decode:`new Uint8Array(Buffer.from($, 'base64'))`,mode:`native`}});var n={id:`date-time`,kind:`scalar`,schema:{type:`string`,format:`date-time`},matches(e){return e.type===`string`&&e.format===`date-time`},ownsValue(e){return e instanceof Date},encode(e,t,n){return e.toISOString()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);return new Date(String(e))}if(n.mode===`strict`&&Number.isNaN(new Date(e).getTime()))throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);return new Date(e)}},r={id:`int64`,kind:`scalar`,schema:{type:`string`,format:`int64`},matches(e){return e.type===`string`&&e.format===`int64`},ownsValue(e){return typeof e==`bigint`},encode(e,t,n){return String(e)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(n.mode===`strict`)return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}};function i(e){return e}var a={id:`decimal`,kind:`scalar`,schema:{type:`string`,format:`decimal`},matches(e){return e.type===`string`&&e.format===`decimal`},encode(e,t,n){return e},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);return i(String(e))}if(n.mode===`strict`&&!/^-?\d+(\.\d+)?$/.test(e))throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);return i(e)}},o={id:`byte`,kind:`scalar`,schema:{type:`string`,format:`byte`},matches(e){return e.type===`string`&&e.format===`byte`},ownsValue(e){return e instanceof Uint8Array},encode(e,t,n){return Buffer.from(e).toString(`base64`)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);return new Uint8Array}if(n.mode===`strict`&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,`base64`))}},s=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,c={id:`uuid`,kind:`scalar`,schema:{type:`string`,format:`uuid`},matches(e){return e.type===`string`&&e.format===`uuid`},encode(e,t,n){return e.toLowerCase()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e).toLowerCase()}if(n.mode===`strict`&&!s.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},l=`NaN`,u=`Infinity`,d=`-Infinity`,f=new Set([l,u,d]);n.id,r.id,a.id,o.id,c.id,{id:`number-special`,kind:`scalar`,schema:{type:`number`},matches(e){return e.type===`number`&&e.format===void 0},ownsValue(e){return typeof e==`number`&&!Number.isFinite(e)},encode(e,t,n){return Number.isNaN(e)?l:e===1/0?u:e===-1/0?d:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===l)return NaN;if(e===u)return 1/0;if(e===d)return-1/0;let t=Number(e);if(!Number.isNaN(t))return t}if(n.mode===`strict`)throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...f].join(`, `)}.`);return NaN}}.id,Object.freeze({typescript:{"date-time":{encode:`$.toISOString()`,decode:`new Date($)`,mode:`native`},int64:{encode:`String($)`,decode:`BigInt($)`,mode:`native`},decimal:{encode:`$.toString()`,decode:`new Decimal($)`,imports:[],dep:{name:`decimal.js`,version:`^10`},mode:`branded`},byte:{encode:`Buffer.from($).toString('base64')`,decode:`new Uint8Array(Buffer.from($, 'base64'))`,mode:`native`},uuid:{encode:`$.toLowerCase()`,decode:`$`,mode:`native`},"number-special":{encode:`numToWire($)`,decode:`wireToNum($)`,mode:`native`}},python:{"date-time":{encode:`$.isoformat()`,decode:`datetime.fromisoformat($)`,imports:[`from datetime import datetime`],mode:`native`},int64:{encode:`str($)`,decode:`int($)`,mode:`native`},decimal:{encode:`str($)`,decode:`Decimal($)`,imports:[`from decimal import Decimal`],mode:`native`},byte:{encode:`b64encode($).decode()`,decode:`b64decode($)`,imports:[`from base64 import b64encode, b64decode`],mode:`native`},uuid:{encode:`str($)`,decode:`UUID($)`,imports:[`from uuid import UUID`],mode:`native`},"number-special":{encode:`num_to_wire($)`,decode:`wire_to_num($)`,mode:`native`}},rust:{"date-time":{encode:`__SCAFFOLD_RUST_DATETIME_ENCODE__`,decode:`__SCAFFOLD_RUST_DATETIME_DECODE__`,imports:[`use chrono::{DateTime, Utc};`],dep:{name:`chrono`,version:`^0.4`},mode:`lib`},int64:{encode:`__SCAFFOLD_RUST_INT64_ENCODE__`,decode:`__SCAFFOLD_RUST_INT64_DECODE__`,imports:[`use serde_with::DisplayFromStr;`],dep:{name:`serde_with`,version:`^3`},mode:`lib`},decimal:{encode:`__SCAFFOLD_RUST_DECIMAL_ENCODE__`,decode:`__SCAFFOLD_RUST_DECIMAL_DECODE__`,imports:[`use rust_decimal::Decimal;`],dep:{name:`rust_decimal`,version:`^1`},mode:`lib`},byte:{encode:`__SCAFFOLD_RUST_BYTE_ENCODE__`,decode:`__SCAFFOLD_RUST_BYTE_DECODE__`,imports:[`use serde_with::base64::Base64;`],dep:{name:`serde_with`,version:`^3`},mode:`lib`},uuid:{encode:`__SCAFFOLD_RUST_UUID_ENCODE__`,decode:`__SCAFFOLD_RUST_UUID_DECODE__`,imports:[`use uuid::Uuid;`],dep:{name:`uuid`,version:`^1`},mode:`lib`},"number-special":{encode:`__SCAFFOLD_RUST_NUMSPECIAL_ENCODE__`,decode:`__SCAFFOLD_RUST_NUMSPECIAL_DECODE__`,mode:`native`}},go:{"date-time":{encode:`__SCAFFOLD_GO_DATETIME_ENCODE__`,decode:`__SCAFFOLD_GO_DATETIME_DECODE__`,imports:[`"time"`],mode:`native`},int64:{encode:`__SCAFFOLD_GO_INT64_ENCODE__`,decode:`__SCAFFOLD_GO_INT64_DECODE__`,imports:[`"strconv"`],mode:`native`},decimal:{encode:`__SCAFFOLD_GO_DECIMAL_ENCODE__`,decode:`__SCAFFOLD_GO_DECIMAL_DECODE__`,imports:[`"github.com/shopspring/decimal"`],dep:{name:`github.com/shopspring/decimal`,version:`v1`},mode:`lib`},byte:{encode:`__SCAFFOLD_GO_BYTE_ENCODE__`,decode:`__SCAFFOLD_GO_BYTE_DECODE__`,imports:[`"encoding/base64"`],mode:`native`},uuid:{encode:`__SCAFFOLD_GO_UUID_ENCODE__`,decode:`__SCAFFOLD_GO_UUID_DECODE__`,imports:[`"github.com/google/uuid"`],dep:{name:`github.com/google/uuid`,version:`v1`},mode:`lib`},"number-special":{encode:`__SCAFFOLD_GO_NUMSPECIAL_ENCODE__`,decode:`__SCAFFOLD_GO_NUMSPECIAL_DECODE__`,mode:`native`}},java:{"date-time":{encode:`$.toString()`,decode:`Instant.parse($)`,imports:[`import java.time.Instant;`],dep:{name:`jackson-datatype-jsr310`,version:`2.x`},mode:`lib`},int64:{encode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,decode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,imports:[`import com.fasterxml.jackson.annotation.JsonFormat;`],mode:`native`},decimal:{encode:`@JsonSerialize(using = ToStringSerializer.class)`,decode:`new BigDecimal($)`,imports:[`import java.math.BigDecimal;`,`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;`],mode:`native`},byte:{encode:`$`,decode:`$`,mode:`native`},uuid:{encode:`$.toString()`,decode:`UUID.fromString($)`,imports:[`import java.util.UUID;`],mode:`native`},"number-special":{encode:`@JsonSerialize(using = NumberSpecialSerializer.class)`,decode:`@JsonDeserialize(using = NumberSpecialDeserializer.class)`,imports:[`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.annotation.JsonDeserialize;`],mode:`native`}}});var p=new Set([`string`,`number`,`boolean`,`integer`]);function m(e){if(!Array.isArray(e)||e.length<2)return!1;let t=0;for(let n of e){if(typeof n!=`object`||!n)return!1;let{type:e,$ref:r,oneOf:i,anyOf:a,allOf:o}=n;if(r!==void 0||i||a||o)return!1;if(e!==`null`){if(typeof e==`string`&&p.has(e)){t++;continue}return!1}}return t===1}function h(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.$ref!==void 0||t.allOf)return!1;if(t.oneOf||t.anyOf)return m(t.oneOf??t.anyOf);let{type:n}=t;return typeof n==`string`?p.has(n):Array.isArray(n)?n.every(e=>p.has(e)||e===`null`):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(e=>[`string`,`number`,`boolean`].includes(typeof e)):!1}function g(e){if(!e||typeof e!=`object`)return!1;let t=e.properties;return t===void 0||typeof t!=`object`||!t?!1:Object.values(t).every(h)}var _={"decimal.js":`Decimal`};function v(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}Object.entries(_).map(([e,t])=>({pattern:RegExp(`import\\(["'][^"']*${v(e)}[^"']*["']\\)\\.\\w+`,`g`),key:t}));function y(e){return e.words.join(`-`)}function b(e){return e.words.map(C).join(``)}function x(e){return e.words.join(`_`)}function S(e,t={}){let n=[e.namespace,...e.path],r=e.safe||g(e.input)?`GET`:`POST`,i=t.http?.verb?.[e.id]??r,a=`/`+n.map(e=>y(e)).join(`/`),o=n.map(e=>x(e)).join(`_`),s=n.map(e=>x(e)).slice(0,-1).join(`.`),c=b(n[n.length-2]??n[0]),l=b(n[n.length-1]),u=n.map(e=>y(e));return{http:{verb:i,route:a},mcp:{name:o},grpc:{package:s,service:c,method:l},cli:{path:u}}}function C(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function w(e,t={}){let n=t.title??`API`,r=t.version??`0.0.0`,i={};for(let t of e){let{verb:e,route:n}=S(t).http,r=e.toLowerCase(),a={operationId:t.id,summary:t.id,responses:{200:T(t.output)}};if(e===`GET`)a.parameters=E(t.input);else{let e=t.input;typeof e==`object`&&e&&Object.keys(e).length>0&&(a.requestBody={required:!0,content:{"application/json":{schema:e}}})}i[n]===void 0&&(i[n]={}),i[n][r]=a}return{openapi:`3.1.0`,info:{title:n,version:r},paths:i}}function T(e){return typeof e==`object`&&e&&Object.keys(e).length>0?{description:`Success`,content:{"application/json":{schema:e}}}:{description:`Success`}}function E(e){if(typeof e!=`object`||!e||typeof e.properties!=`object`||e.properties===null)return[];let t=Array.isArray(e.required)?e.required:[],n=e.properties;return Object.entries(n).map(([e,n])=>({name:e,in:`query`,required:t.includes(e),schema:n}))}var D=`@adhd/apigen-codegen-openapi`;exports.__apigen_pkg=D,exports.toOpenApi=w;
|
package/index.mjs
CHANGED
|
@@ -3,8 +3,39 @@ import { createRequire as e } from "node:module";
|
|
|
3
3
|
import "node:path";
|
|
4
4
|
e(import.meta.url);
|
|
5
5
|
//#endregion
|
|
6
|
+
//#region ../../apigen-base-logical/src/lib/contracts.ts
|
|
7
|
+
var t = "$apigen";
|
|
8
|
+
`
|
|
9
|
+
function __apigenEnvelopeEncode(v) {
|
|
10
|
+
// Schema-less position: pass typed JSON through unchanged. A richer host
|
|
11
|
+
// prelude may wrap recognized runtime types as { ${JSON.stringify(t)}: id, v }.
|
|
12
|
+
return v;
|
|
13
|
+
}
|
|
14
|
+
function __apigenEnvelopeDecode(w) {
|
|
15
|
+
return w != null && typeof w === 'object' && ${JSON.stringify(t)} in w
|
|
16
|
+
? w.v
|
|
17
|
+
: w;
|
|
18
|
+
}
|
|
19
|
+
`.trim(), Object.freeze({
|
|
20
|
+
"date-time": {
|
|
21
|
+
encode: "$.toISOString()",
|
|
22
|
+
decode: "new Date($)",
|
|
23
|
+
mode: "native"
|
|
24
|
+
},
|
|
25
|
+
int64: {
|
|
26
|
+
encode: "String($)",
|
|
27
|
+
decode: "BigInt($)",
|
|
28
|
+
mode: "native"
|
|
29
|
+
},
|
|
30
|
+
byte: {
|
|
31
|
+
encode: "Buffer.from($).toString('base64')",
|
|
32
|
+
decode: "new Uint8Array(Buffer.from($, 'base64'))",
|
|
33
|
+
mode: "native"
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
//#endregion
|
|
6
37
|
//#region ../../apigen-base-logical/src/lib/codecs/date-time.ts
|
|
7
|
-
var
|
|
38
|
+
var n = {
|
|
8
39
|
id: "date-time",
|
|
9
40
|
kind: "scalar",
|
|
10
41
|
schema: {
|
|
@@ -28,7 +59,7 @@ var t = {
|
|
|
28
59
|
if (n.mode === "strict" && Number.isNaN(new Date(e).getTime())) throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);
|
|
29
60
|
return new Date(e);
|
|
30
61
|
}
|
|
31
|
-
},
|
|
62
|
+
}, r = {
|
|
32
63
|
id: "int64",
|
|
33
64
|
kind: "scalar",
|
|
34
65
|
schema: {
|
|
@@ -64,10 +95,10 @@ var t = {
|
|
|
64
95
|
};
|
|
65
96
|
//#endregion
|
|
66
97
|
//#region ../../apigen-base-logical/src/lib/codecs/decimal.ts
|
|
67
|
-
function
|
|
98
|
+
function i(e) {
|
|
68
99
|
return e;
|
|
69
100
|
}
|
|
70
|
-
var
|
|
101
|
+
var a = {
|
|
71
102
|
id: "decimal",
|
|
72
103
|
kind: "scalar",
|
|
73
104
|
schema: {
|
|
@@ -83,12 +114,12 @@ var i = {
|
|
|
83
114
|
decode(e, t, n) {
|
|
84
115
|
if (typeof e != "string") {
|
|
85
116
|
if (n.mode === "strict") throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);
|
|
86
|
-
return
|
|
117
|
+
return i(String(e));
|
|
87
118
|
}
|
|
88
119
|
if (n.mode === "strict" && !/^-?\d+(\.\d+)?$/.test(e)) throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);
|
|
89
|
-
return
|
|
120
|
+
return i(e);
|
|
90
121
|
}
|
|
91
|
-
},
|
|
122
|
+
}, o = {
|
|
92
123
|
id: "byte",
|
|
93
124
|
kind: "scalar",
|
|
94
125
|
schema: {
|
|
@@ -112,7 +143,7 @@ var i = {
|
|
|
112
143
|
if (n.mode === "strict" && !/^[A-Za-z0-9+/]*={0,2}$/.test(e)) throw TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);
|
|
113
144
|
return new Uint8Array(Buffer.from(e, "base64"));
|
|
114
145
|
}
|
|
115
|
-
},
|
|
146
|
+
}, s = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, c = {
|
|
116
147
|
id: "uuid",
|
|
117
148
|
kind: "scalar",
|
|
118
149
|
schema: {
|
|
@@ -130,15 +161,15 @@ var i = {
|
|
|
130
161
|
if (n.mode === "strict") throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);
|
|
131
162
|
return String(e).toLowerCase();
|
|
132
163
|
}
|
|
133
|
-
if (n.mode === "strict" && !
|
|
164
|
+
if (n.mode === "strict" && !s.test(e)) throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);
|
|
134
165
|
return e;
|
|
135
166
|
}
|
|
136
|
-
},
|
|
137
|
-
c,
|
|
167
|
+
}, l = "NaN", u = "Infinity", d = "-Infinity", f = /* @__PURE__ */ new Set([
|
|
138
168
|
l,
|
|
139
|
-
u
|
|
169
|
+
u,
|
|
170
|
+
d
|
|
140
171
|
]);
|
|
141
|
-
|
|
172
|
+
n.id, r.id, a.id, o.id, c.id, {
|
|
142
173
|
id: "number-special",
|
|
143
174
|
kind: "scalar",
|
|
144
175
|
schema: { type: "number" },
|
|
@@ -149,18 +180,18 @@ t.id, n.id, i.id, a.id, s.id, {
|
|
|
149
180
|
return typeof e == "number" && !Number.isFinite(e);
|
|
150
181
|
},
|
|
151
182
|
encode(e, t, n) {
|
|
152
|
-
return Number.isNaN(e) ?
|
|
183
|
+
return Number.isNaN(e) ? l : e === Infinity ? u : e === -Infinity ? d : e;
|
|
153
184
|
},
|
|
154
185
|
decode(e, t, n) {
|
|
155
186
|
if (typeof e == "number") return e;
|
|
156
187
|
if (typeof e == "string") {
|
|
157
|
-
if (e ===
|
|
158
|
-
if (e ===
|
|
159
|
-
if (e ===
|
|
188
|
+
if (e === l) return NaN;
|
|
189
|
+
if (e === u) return Infinity;
|
|
190
|
+
if (e === d) return -Infinity;
|
|
160
191
|
let t = Number(e);
|
|
161
192
|
if (!Number.isNaN(t)) return t;
|
|
162
193
|
}
|
|
163
|
-
if (n.mode === "strict") throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...
|
|
194
|
+
if (n.mode === "strict") throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...f].join(", ")}.`);
|
|
164
195
|
return NaN;
|
|
165
196
|
}
|
|
166
197
|
}.id, Object.freeze({
|
|
@@ -387,13 +418,13 @@ t.id, n.id, i.id, a.id, s.id, {
|
|
|
387
418
|
});
|
|
388
419
|
//#endregion
|
|
389
420
|
//#region ../../apigen-core-client/src/lib/get-safety.ts
|
|
390
|
-
var
|
|
421
|
+
var p = /* @__PURE__ */ new Set([
|
|
391
422
|
"string",
|
|
392
423
|
"number",
|
|
393
424
|
"boolean",
|
|
394
425
|
"integer"
|
|
395
426
|
]);
|
|
396
|
-
function
|
|
427
|
+
function m(e) {
|
|
397
428
|
if (!Array.isArray(e) || e.length < 2) return !1;
|
|
398
429
|
let t = 0;
|
|
399
430
|
for (let n of e) {
|
|
@@ -401,7 +432,7 @@ function p(e) {
|
|
|
401
432
|
let { type: e, $ref: r, oneOf: i, anyOf: a, allOf: o } = n;
|
|
402
433
|
if (r !== void 0 || i || a || o) return !1;
|
|
403
434
|
if (e !== "null") {
|
|
404
|
-
if (typeof e == "string" &&
|
|
435
|
+
if (typeof e == "string" && p.has(e)) {
|
|
405
436
|
t++;
|
|
406
437
|
continue;
|
|
407
438
|
}
|
|
@@ -410,46 +441,46 @@ function p(e) {
|
|
|
410
441
|
}
|
|
411
442
|
return t === 1;
|
|
412
443
|
}
|
|
413
|
-
function
|
|
444
|
+
function h(e) {
|
|
414
445
|
if (typeof e != "object" || !e) return !1;
|
|
415
446
|
let t = e;
|
|
416
447
|
if (t.$ref !== void 0 || t.allOf) return !1;
|
|
417
|
-
if (t.oneOf || t.anyOf) return
|
|
448
|
+
if (t.oneOf || t.anyOf) return m(t.oneOf ?? t.anyOf);
|
|
418
449
|
let { type: n } = t;
|
|
419
|
-
return typeof n == "string" ?
|
|
450
|
+
return typeof n == "string" ? p.has(n) : Array.isArray(n) ? n.every((e) => p.has(e) || e === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((e) => [
|
|
420
451
|
"string",
|
|
421
452
|
"number",
|
|
422
453
|
"boolean"
|
|
423
454
|
].includes(typeof e)) : !1;
|
|
424
455
|
}
|
|
425
|
-
function
|
|
456
|
+
function g(e) {
|
|
426
457
|
if (!e || typeof e != "object") return !1;
|
|
427
458
|
let t = e.properties;
|
|
428
|
-
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(
|
|
459
|
+
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(h);
|
|
429
460
|
}
|
|
430
461
|
//#endregion
|
|
431
462
|
//#region ../../apigen-core-client/src/lib/schema-builders/ts-json-schema.ts
|
|
432
|
-
var
|
|
433
|
-
function
|
|
463
|
+
var _ = { "decimal.js": "Decimal" };
|
|
464
|
+
function v(e) {
|
|
434
465
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
435
466
|
}
|
|
436
|
-
Object.entries(
|
|
437
|
-
pattern: RegExp(`import\\(["'][^"']*${
|
|
467
|
+
Object.entries(_).map(([e, t]) => ({
|
|
468
|
+
pattern: RegExp(`import\\(["'][^"']*${v(e)}[^"']*["']\\)\\.\\w+`, "g"),
|
|
438
469
|
key: t
|
|
439
470
|
}));
|
|
440
471
|
//#endregion
|
|
441
472
|
//#region ../../apigen-engine-naming/src/lib/naming.ts
|
|
442
|
-
function v(e) {
|
|
443
|
-
return e.words.join("-");
|
|
444
|
-
}
|
|
445
473
|
function y(e) {
|
|
446
|
-
return e.words.
|
|
474
|
+
return e.words.join("-");
|
|
447
475
|
}
|
|
448
476
|
function b(e) {
|
|
477
|
+
return e.words.map(C).join("");
|
|
478
|
+
}
|
|
479
|
+
function x(e) {
|
|
449
480
|
return e.words.join("_");
|
|
450
481
|
}
|
|
451
|
-
function
|
|
452
|
-
let n = [e.namespace, ...e.path], r = e.safe ||
|
|
482
|
+
function S(e, t = {}) {
|
|
483
|
+
let n = [e.namespace, ...e.path], r = e.safe || g(e.input) ? "GET" : "POST", i = t.http?.verb?.[e.id] ?? r, a = "/" + n.map((e) => y(e)).join("/"), o = n.map((e) => x(e)).join("_"), s = n.map((e) => x(e)).slice(0, -1).join("."), c = b(n[n.length - 2] ?? n[0]), l = b(n[n.length - 1]), u = n.map((e) => y(e));
|
|
453
484
|
return {
|
|
454
485
|
http: {
|
|
455
486
|
verb: i,
|
|
@@ -464,20 +495,20 @@ function x(e, t = {}) {
|
|
|
464
495
|
cli: { path: u }
|
|
465
496
|
};
|
|
466
497
|
}
|
|
467
|
-
function
|
|
498
|
+
function C(e) {
|
|
468
499
|
return e.length === 0 ? e : e[0].toUpperCase() + e.slice(1);
|
|
469
500
|
}
|
|
470
501
|
//#endregion
|
|
471
502
|
//#region src/lib/to-openapi.ts
|
|
472
|
-
function
|
|
503
|
+
function w(e, t = {}) {
|
|
473
504
|
let n = t.title ?? "API", r = t.version ?? "0.0.0", i = {};
|
|
474
505
|
for (let t of e) {
|
|
475
|
-
let { verb: e, route: n } =
|
|
506
|
+
let { verb: e, route: n } = S(t).http, r = e.toLowerCase(), a = {
|
|
476
507
|
operationId: t.id,
|
|
477
508
|
summary: t.id,
|
|
478
|
-
responses: { 200:
|
|
509
|
+
responses: { 200: T(t.output) }
|
|
479
510
|
};
|
|
480
|
-
if (e === "GET") a.parameters =
|
|
511
|
+
if (e === "GET") a.parameters = E(t.input);
|
|
481
512
|
else {
|
|
482
513
|
let e = t.input;
|
|
483
514
|
typeof e == "object" && e && Object.keys(e).length > 0 && (a.requestBody = {
|
|
@@ -496,13 +527,13 @@ function C(e, t = {}) {
|
|
|
496
527
|
paths: i
|
|
497
528
|
};
|
|
498
529
|
}
|
|
499
|
-
function
|
|
530
|
+
function T(e) {
|
|
500
531
|
return typeof e == "object" && e && Object.keys(e).length > 0 ? {
|
|
501
532
|
description: "Success",
|
|
502
533
|
content: { "application/json": { schema: e } }
|
|
503
534
|
} : { description: "Success" };
|
|
504
535
|
}
|
|
505
|
-
function
|
|
536
|
+
function E(e) {
|
|
506
537
|
if (typeof e != "object" || !e || typeof e.properties != "object" || e.properties === null) return [];
|
|
507
538
|
let t = Array.isArray(e.required) ? e.required : [], n = e.properties;
|
|
508
539
|
return Object.entries(n).map(([e, n]) => ({
|
|
@@ -514,6 +545,6 @@ function T(e) {
|
|
|
514
545
|
}
|
|
515
546
|
//#endregion
|
|
516
547
|
//#region src/index.ts
|
|
517
|
-
var
|
|
548
|
+
var D = "@adhd/apigen-codegen-openapi";
|
|
518
549
|
//#endregion
|
|
519
|
-
export {
|
|
550
|
+
export { D as __apigen_pkg, w as toOpenApi };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhd/apigen-codegen-openapi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"module": "./index.mjs",
|
|
6
6
|
"typings": "./index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@adhd/apigen-core-client": "^0.3.
|
|
12
|
-
"@adhd/apigen-engine-naming": "^0.2.
|
|
11
|
+
"@adhd/apigen-core-client": "^0.3.6",
|
|
12
|
+
"@adhd/apigen-engine-naming": "^0.2.7"
|
|
13
13
|
}
|
|
14
14
|
}
|