@adhd/apigen-plugin-openapi 0.2.5 → 0.2.6
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 +1 -1
- package/index.mjs +43 -25
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require("node:fs");let e=require("node:module");require("node:path");function t(e){return{raw:e,words:e.split(/(?=[A-Z])|[-_]/).map(e=>e.toLowerCase()).filter(Boolean)}}function n(e,n,r={}){let i=e.split(`/`);if(i.length<2||i.some(e=>e.length===0))throw Error(`syntheticOp: id "${e}" must be "<namespace>/<path...>" with non-empty segments`);let[a,...o]=i,s=a.replace(/^_+/,``),c=r.kind??`action`,l={id:e,host:n.host,namespace:t(s),path:o.map(t),kind:c,async:r.async??!1,streaming:r.streaming??!1,safe:r.safe??c===`query`,input:r.input??{},output:r.output??{},envelope:r.envelope??{},typeText:r.typeText??null};return r.hasCtx!==void 0&&(l.hasCtx=r.hasCtx),r.transports!==void 0&&(l.transports=r.transports),l}(0,e.createRequire)(require("node:url").pathToFileURL(__filename).href);var r={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)}},i={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 a(e){return e}var o={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 a(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 a(e)}},s={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`))}},c=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,l={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`&&!c.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},u=`NaN`,d=`Infinity`,f=`-Infinity`,p=new Set([u,d,f]);r.id,i.id,o.id,s.id,l.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)?u:e===1/0?d:e===-1/0?f:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===u)return NaN;if(e===d)return 1/0;if(e===f)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 ${[...p].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 m=new Set([`string`,`number`,`boolean`,`integer`]);function h(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;let{type:n}=t;return typeof n==`string`?m.has(n):Array.isArray(n)?n.every(e=>m.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}))}function D(e,t={}){return[{...n(`_meta/openapi`,e,{kind:`query`,safe:!0,output:{type:`object`},transports:[`http`]}),handler:n=>w(e.operations,{title:t.title,version:t.version})}]}var O={id:`openapi`,description:`Mount plugin: serves the OpenAPI 3.1 doc at GET /meta/openapi`,language:`ts`,optionsSchema:{type:`object`,properties:{title:{type:`string`,description:`OpenAPI info.title`},version:{type:`string`,description:`OpenAPI info.version`}},additionalProperties:!1},capabilities:{mount:{operations(e,t){return D(e,t)}}}};exports.default=O,exports.openapiPlugin=O;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require("node:fs");let e=require("node:module");require("node:path");function t(e){return{raw:e,words:e.split(/(?=[A-Z])|[-_]/).map(e=>e.toLowerCase()).filter(Boolean)}}function n(e,n,r={}){let i=e.split(`/`);if(i.length<2||i.some(e=>e.length===0))throw Error(`syntheticOp: id "${e}" must be "<namespace>/<path...>" with non-empty segments`);let[a,...o]=i,s=a.replace(/^_+/,``),c=r.kind??`action`,l={id:e,host:n.host,namespace:t(s),path:o.map(t),kind:c,async:r.async??!1,streaming:r.streaming??!1,safe:r.safe??c===`query`,input:r.input??{},output:r.output??{},envelope:r.envelope??{},typeText:r.typeText??null};return r.hasCtx!==void 0&&(l.hasCtx=r.hasCtx),r.transports!==void 0&&(l.transports=r.transports),l}(0,e.createRequire)(require("node:url").pathToFileURL(__filename).href);var r={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)}},i={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 a(e){return e}var o={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 a(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 a(e)}},s={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`))}},c=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,l={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`&&!c.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},u=`NaN`,d=`Infinity`,f=`-Infinity`,p=new Set([u,d,f]);r.id,i.id,o.id,s.id,l.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)?u:e===1/0?d:e===-1/0?f:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===u)return NaN;if(e===d)return 1/0;if(e===f)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 ${[...p].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 m=new Set([`string`,`number`,`boolean`,`integer`]);function h(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`&&m.has(e)){t++;continue}return!1}}return t===1}function g(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 h(t.oneOf??t.anyOf);let{type:n}=t;return typeof n==`string`?m.has(n):Array.isArray(n)?n.every(e=>m.has(e)||e===`null`):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(e=>[`string`,`number`,`boolean`].includes(typeof e)):!1}function _(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(g)}var v={"decimal.js":`Decimal`};function y(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}Object.entries(v).map(([e,t])=>({pattern:RegExp(`import\\(["'][^"']*${y(e)}[^"']*["']\\)\\.\\w+`,`g`),key:t}));function b(e){return e.words.join(`-`)}function x(e){return e.words.map(w).join(``)}function S(e){return e.words.join(`_`)}function C(e,t={}){let n=[e.namespace,...e.path],r=e.safe||_(e.input)?`GET`:`POST`,i=t.http?.verb?.[e.id]??r,a=`/`+n.map(e=>b(e)).join(`/`),o=n.map(e=>S(e)).join(`_`),s=n.map(e=>S(e)).slice(0,-1).join(`.`),c=x(n[n.length-2]??n[0]),l=x(n[n.length-1]),u=n.map(e=>b(e));return{http:{verb:i,route:a},mcp:{name:o},grpc:{package:s,service:c,method:l},cli:{path:u}}}function w(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function T(e,t={}){let n=t.title??`API`,r=t.version??`0.0.0`,i={};for(let t of e){let{verb:e,route:n}=C(t).http,r=e.toLowerCase(),a={operationId:t.id,summary:t.id,responses:{200:E(t.output)}};if(e===`GET`)a.parameters=D(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 E(e){return typeof e==`object`&&e&&Object.keys(e).length>0?{description:`Success`,content:{"application/json":{schema:e}}}:{description:`Success`}}function D(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}))}function O(e,t={}){return[{...n(`_meta/openapi`,e,{kind:`query`,safe:!0,output:{type:`object`},transports:[`http`]}),handler:n=>T(e.operations,{title:t.title,version:t.version})}]}var k={id:`openapi`,description:`Mount plugin: serves the OpenAPI 3.1 doc at GET /meta/openapi`,language:`ts`,optionsSchema:{type:`object`,properties:{title:{type:`string`,description:`OpenAPI info.title`},version:{type:`string`,description:`OpenAPI info.version`}},additionalProperties:!1},capabilities:{mount:{operations(e,t){return O(e,t)}}}};exports.default=k,exports.openapiPlugin=k;
|
package/index.mjs
CHANGED
|
@@ -420,9 +420,27 @@ var m = /* @__PURE__ */ new Set([
|
|
|
420
420
|
"integer"
|
|
421
421
|
]);
|
|
422
422
|
function h(e) {
|
|
423
|
+
if (!Array.isArray(e) || e.length < 2) return !1;
|
|
424
|
+
let t = 0;
|
|
425
|
+
for (let n of e) {
|
|
426
|
+
if (typeof n != "object" || !n) return !1;
|
|
427
|
+
let { type: e, $ref: r, oneOf: i, anyOf: a, allOf: o } = n;
|
|
428
|
+
if (r !== void 0 || i || a || o) return !1;
|
|
429
|
+
if (e !== "null") {
|
|
430
|
+
if (typeof e == "string" && m.has(e)) {
|
|
431
|
+
t++;
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
return !1;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return t === 1;
|
|
438
|
+
}
|
|
439
|
+
function g(e) {
|
|
423
440
|
if (typeof e != "object" || !e) return !1;
|
|
424
441
|
let t = e;
|
|
425
|
-
if (t.$ref !== void 0 || t.
|
|
442
|
+
if (t.$ref !== void 0 || t.allOf) return !1;
|
|
443
|
+
if (t.oneOf || t.anyOf) return h(t.oneOf ?? t.anyOf);
|
|
426
444
|
let { type: n } = t;
|
|
427
445
|
return typeof n == "string" ? m.has(n) : Array.isArray(n) ? n.every((e) => m.has(e) || e === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((e) => [
|
|
428
446
|
"string",
|
|
@@ -430,34 +448,34 @@ function h(e) {
|
|
|
430
448
|
"boolean"
|
|
431
449
|
].includes(typeof e)) : !1;
|
|
432
450
|
}
|
|
433
|
-
function
|
|
451
|
+
function _(e) {
|
|
434
452
|
if (!e || typeof e != "object") return !1;
|
|
435
453
|
let t = e.properties;
|
|
436
|
-
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(
|
|
454
|
+
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(g);
|
|
437
455
|
}
|
|
438
456
|
//#endregion
|
|
439
457
|
//#region ../apigen-core-client/src/lib/schema-builders/ts-json-schema.ts
|
|
440
|
-
var
|
|
441
|
-
function
|
|
458
|
+
var v = { "decimal.js": "Decimal" };
|
|
459
|
+
function y(e) {
|
|
442
460
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
443
461
|
}
|
|
444
|
-
Object.entries(
|
|
445
|
-
pattern: RegExp(`import\\(["'][^"']*${
|
|
462
|
+
Object.entries(v).map(([e, t]) => ({
|
|
463
|
+
pattern: RegExp(`import\\(["'][^"']*${y(e)}[^"']*["']\\)\\.\\w+`, "g"),
|
|
446
464
|
key: t
|
|
447
465
|
}));
|
|
448
466
|
//#endregion
|
|
449
467
|
//#region ../apigen-engine-naming/src/lib/naming.ts
|
|
450
|
-
function y(e) {
|
|
451
|
-
return e.words.join("-");
|
|
452
|
-
}
|
|
453
468
|
function b(e) {
|
|
454
|
-
return e.words.
|
|
469
|
+
return e.words.join("-");
|
|
455
470
|
}
|
|
456
471
|
function x(e) {
|
|
472
|
+
return e.words.map(w).join("");
|
|
473
|
+
}
|
|
474
|
+
function S(e) {
|
|
457
475
|
return e.words.join("_");
|
|
458
476
|
}
|
|
459
|
-
function
|
|
460
|
-
let n = [e.namespace, ...e.path], r = e.safe ||
|
|
477
|
+
function C(e, t = {}) {
|
|
478
|
+
let n = [e.namespace, ...e.path], r = e.safe || _(e.input) ? "GET" : "POST", i = t.http?.verb?.[e.id] ?? r, a = "/" + n.map((e) => b(e)).join("/"), o = n.map((e) => S(e)).join("_"), s = n.map((e) => S(e)).slice(0, -1).join("."), c = x(n[n.length - 2] ?? n[0]), l = x(n[n.length - 1]), u = n.map((e) => b(e));
|
|
461
479
|
return {
|
|
462
480
|
http: {
|
|
463
481
|
verb: i,
|
|
@@ -472,20 +490,20 @@ function S(e, t = {}) {
|
|
|
472
490
|
cli: { path: u }
|
|
473
491
|
};
|
|
474
492
|
}
|
|
475
|
-
function
|
|
493
|
+
function w(e) {
|
|
476
494
|
return e.length === 0 ? e : e[0].toUpperCase() + e.slice(1);
|
|
477
495
|
}
|
|
478
496
|
//#endregion
|
|
479
497
|
//#region ../codegen/openapi/src/lib/to-openapi.ts
|
|
480
|
-
function
|
|
498
|
+
function T(e, t = {}) {
|
|
481
499
|
let n = t.title ?? "API", r = t.version ?? "0.0.0", i = {};
|
|
482
500
|
for (let t of e) {
|
|
483
|
-
let { verb: e, route: n } =
|
|
501
|
+
let { verb: e, route: n } = C(t).http, r = e.toLowerCase(), a = {
|
|
484
502
|
operationId: t.id,
|
|
485
503
|
summary: t.id,
|
|
486
|
-
responses: { 200:
|
|
504
|
+
responses: { 200: E(t.output) }
|
|
487
505
|
};
|
|
488
|
-
if (e === "GET") a.parameters =
|
|
506
|
+
if (e === "GET") a.parameters = D(t.input);
|
|
489
507
|
else {
|
|
490
508
|
let e = t.input;
|
|
491
509
|
typeof e == "object" && e && Object.keys(e).length > 0 && (a.requestBody = {
|
|
@@ -504,13 +522,13 @@ function w(e, t = {}) {
|
|
|
504
522
|
paths: i
|
|
505
523
|
};
|
|
506
524
|
}
|
|
507
|
-
function
|
|
525
|
+
function E(e) {
|
|
508
526
|
return typeof e == "object" && e && Object.keys(e).length > 0 ? {
|
|
509
527
|
description: "Success",
|
|
510
528
|
content: { "application/json": { schema: e } }
|
|
511
529
|
} : { description: "Success" };
|
|
512
530
|
}
|
|
513
|
-
function
|
|
531
|
+
function D(e) {
|
|
514
532
|
if (typeof e != "object" || !e || typeof e.properties != "object" || e.properties === null) return [];
|
|
515
533
|
let t = Array.isArray(e.required) ? e.required : [], n = e.properties;
|
|
516
534
|
return Object.entries(n).map(([e, n]) => ({
|
|
@@ -522,7 +540,7 @@ function E(e) {
|
|
|
522
540
|
}
|
|
523
541
|
//#endregion
|
|
524
542
|
//#region src/lib/plugin.ts
|
|
525
|
-
function
|
|
543
|
+
function O(e, t = {}) {
|
|
526
544
|
return [{
|
|
527
545
|
...n("_meta/openapi", e, {
|
|
528
546
|
kind: "query",
|
|
@@ -530,13 +548,13 @@ function D(e, t = {}) {
|
|
|
530
548
|
output: { type: "object" },
|
|
531
549
|
transports: ["http"]
|
|
532
550
|
}),
|
|
533
|
-
handler: (n) =>
|
|
551
|
+
handler: (n) => T(e.operations, {
|
|
534
552
|
title: t.title,
|
|
535
553
|
version: t.version
|
|
536
554
|
})
|
|
537
555
|
}];
|
|
538
556
|
}
|
|
539
|
-
var
|
|
557
|
+
var k = {
|
|
540
558
|
id: "openapi",
|
|
541
559
|
description: "Mount plugin: serves the OpenAPI 3.1 doc at GET /meta/openapi",
|
|
542
560
|
language: "ts",
|
|
@@ -555,8 +573,8 @@ var O = {
|
|
|
555
573
|
additionalProperties: !1
|
|
556
574
|
},
|
|
557
575
|
capabilities: { mount: { operations(e, t) {
|
|
558
|
-
return
|
|
576
|
+
return O(e, t);
|
|
559
577
|
} } }
|
|
560
578
|
};
|
|
561
579
|
//#endregion
|
|
562
|
-
export {
|
|
580
|
+
export { k as default, k as openapiPlugin };
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhd/apigen-plugin-openapi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@adhd/apigen-core-client": "^0.3.
|
|
7
|
-
"@adhd/apigen-codegen-openapi": "^0.2.
|
|
6
|
+
"@adhd/apigen-core-client": "^0.3.5",
|
|
7
|
+
"@adhd/apigen-codegen-openapi": "^0.2.6"
|
|
8
8
|
},
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|