@adhd/apigen-plugin-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 +79 -48
- 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-plugin-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-plugin-openapi to align it with other projects, there were no code changes.
|
package/index.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
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;
|
|
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=`$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(r)}: id, v }.
|
|
5
|
+
return v;
|
|
6
|
+
}
|
|
7
|
+
function __apigenEnvelopeDecode(w) {
|
|
8
|
+
return w != null && typeof w === 'object' && ${JSON.stringify(r)} 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 i={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)}},a={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 o(e){return e}var s={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 o(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 o(e)}},c={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`))}},l=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,u={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`&&!l.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},d=`NaN`,f=`Infinity`,p=`-Infinity`,m=new Set([d,f,p]);i.id,a.id,s.id,c.id,u.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)?d:e===1/0?f:e===-1/0?p:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===d)return NaN;if(e===f)return 1/0;if(e===p)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 ${[...m].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 h=new Set([`string`,`number`,`boolean`,`integer`]);function g(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`&&h.has(e)){t++;continue}return!1}}return t===1}function _(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 g(t.oneOf??t.anyOf);let{type:n}=t;return typeof n==`string`?h.has(n):Array.isArray(n)?n.every(e=>h.has(e)||e===`null`):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(e=>[`string`,`number`,`boolean`].includes(typeof e)):!1}function v(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(_)}var y={"decimal.js":`Decimal`};function b(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}Object.entries(y).map(([e,t])=>({pattern:RegExp(`import\\(["'][^"']*${b(e)}[^"']*["']\\)\\.\\w+`,`g`),key:t}));function x(e){return e.words.join(`-`)}function S(e){return e.words.map(T).join(``)}function C(e){return e.words.join(`_`)}function w(e,t={}){let n=[e.namespace,...e.path],r=e.safe||v(e.input)?`GET`:`POST`,i=t.http?.verb?.[e.id]??r,a=`/`+n.map(e=>x(e)).join(`/`),o=n.map(e=>C(e)).join(`_`),s=n.map(e=>C(e)).slice(0,-1).join(`.`),c=S(n[n.length-2]??n[0]),l=S(n[n.length-1]),u=n.map(e=>x(e));return{http:{verb:i,route:a},mcp:{name:o},grpc:{package:s,service:c,method:l},cli:{path:u}}}function T(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function E(e,t={}){let n=t.title??`API`,r=t.version??`0.0.0`,i={};for(let t of e){let{verb:e,route:n}=w(t).http,r=e.toLowerCase(),a={operationId:t.id,summary:t.id,responses:{200:D(t.output)}};if(e===`GET`)a.parameters=O(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 D(e){return typeof e==`object`&&e&&Object.keys(e).length>0?{description:`Success`,content:{"application/json":{schema:e}}}:{description:`Success`}}function O(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 k(e,t={}){return[{...n(`_meta/openapi`,e,{kind:`query`,safe:!0,output:{type:`object`},transports:[`http`]}),handler:n=>E(e.operations,{title:t.title,version:t.version})}]}var A={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 k(e,t)}}}};exports.default=A,exports.openapiPlugin=A;
|
package/index.mjs
CHANGED
|
@@ -29,8 +29,39 @@ function n(e, n, r = {}) {
|
|
|
29
29
|
}
|
|
30
30
|
e(import.meta.url);
|
|
31
31
|
//#endregion
|
|
32
|
+
//#region ../apigen-base-logical/src/lib/contracts.ts
|
|
33
|
+
var r = "$apigen";
|
|
34
|
+
`
|
|
35
|
+
function __apigenEnvelopeEncode(v) {
|
|
36
|
+
// Schema-less position: pass typed JSON through unchanged. A richer host
|
|
37
|
+
// prelude may wrap recognized runtime types as { ${JSON.stringify(r)}: id, v }.
|
|
38
|
+
return v;
|
|
39
|
+
}
|
|
40
|
+
function __apigenEnvelopeDecode(w) {
|
|
41
|
+
return w != null && typeof w === 'object' && ${JSON.stringify(r)} in w
|
|
42
|
+
? w.v
|
|
43
|
+
: w;
|
|
44
|
+
}
|
|
45
|
+
`.trim(), Object.freeze({
|
|
46
|
+
"date-time": {
|
|
47
|
+
encode: "$.toISOString()",
|
|
48
|
+
decode: "new Date($)",
|
|
49
|
+
mode: "native"
|
|
50
|
+
},
|
|
51
|
+
int64: {
|
|
52
|
+
encode: "String($)",
|
|
53
|
+
decode: "BigInt($)",
|
|
54
|
+
mode: "native"
|
|
55
|
+
},
|
|
56
|
+
byte: {
|
|
57
|
+
encode: "Buffer.from($).toString('base64')",
|
|
58
|
+
decode: "new Uint8Array(Buffer.from($, 'base64'))",
|
|
59
|
+
mode: "native"
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
//#endregion
|
|
32
63
|
//#region ../apigen-base-logical/src/lib/codecs/date-time.ts
|
|
33
|
-
var
|
|
64
|
+
var i = {
|
|
34
65
|
id: "date-time",
|
|
35
66
|
kind: "scalar",
|
|
36
67
|
schema: {
|
|
@@ -54,7 +85,7 @@ var r = {
|
|
|
54
85
|
if (n.mode === "strict" && Number.isNaN(new Date(e).getTime())) throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);
|
|
55
86
|
return new Date(e);
|
|
56
87
|
}
|
|
57
|
-
},
|
|
88
|
+
}, a = {
|
|
58
89
|
id: "int64",
|
|
59
90
|
kind: "scalar",
|
|
60
91
|
schema: {
|
|
@@ -90,10 +121,10 @@ var r = {
|
|
|
90
121
|
};
|
|
91
122
|
//#endregion
|
|
92
123
|
//#region ../apigen-base-logical/src/lib/codecs/decimal.ts
|
|
93
|
-
function
|
|
124
|
+
function o(e) {
|
|
94
125
|
return e;
|
|
95
126
|
}
|
|
96
|
-
var
|
|
127
|
+
var s = {
|
|
97
128
|
id: "decimal",
|
|
98
129
|
kind: "scalar",
|
|
99
130
|
schema: {
|
|
@@ -109,12 +140,12 @@ var o = {
|
|
|
109
140
|
decode(e, t, n) {
|
|
110
141
|
if (typeof e != "string") {
|
|
111
142
|
if (n.mode === "strict") throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);
|
|
112
|
-
return
|
|
143
|
+
return o(String(e));
|
|
113
144
|
}
|
|
114
145
|
if (n.mode === "strict" && !/^-?\d+(\.\d+)?$/.test(e)) throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);
|
|
115
|
-
return
|
|
146
|
+
return o(e);
|
|
116
147
|
}
|
|
117
|
-
},
|
|
148
|
+
}, c = {
|
|
118
149
|
id: "byte",
|
|
119
150
|
kind: "scalar",
|
|
120
151
|
schema: {
|
|
@@ -138,7 +169,7 @@ var o = {
|
|
|
138
169
|
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}"`);
|
|
139
170
|
return new Uint8Array(Buffer.from(e, "base64"));
|
|
140
171
|
}
|
|
141
|
-
},
|
|
172
|
+
}, l = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, u = {
|
|
142
173
|
id: "uuid",
|
|
143
174
|
kind: "scalar",
|
|
144
175
|
schema: {
|
|
@@ -156,15 +187,15 @@ var o = {
|
|
|
156
187
|
if (n.mode === "strict") throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);
|
|
157
188
|
return String(e).toLowerCase();
|
|
158
189
|
}
|
|
159
|
-
if (n.mode === "strict" && !
|
|
190
|
+
if (n.mode === "strict" && !l.test(e)) throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);
|
|
160
191
|
return e;
|
|
161
192
|
}
|
|
162
|
-
},
|
|
163
|
-
u,
|
|
193
|
+
}, d = "NaN", f = "Infinity", p = "-Infinity", m = /* @__PURE__ */ new Set([
|
|
164
194
|
d,
|
|
165
|
-
f
|
|
195
|
+
f,
|
|
196
|
+
p
|
|
166
197
|
]);
|
|
167
|
-
|
|
198
|
+
i.id, a.id, s.id, c.id, u.id, {
|
|
168
199
|
id: "number-special",
|
|
169
200
|
kind: "scalar",
|
|
170
201
|
schema: { type: "number" },
|
|
@@ -175,18 +206,18 @@ r.id, i.id, o.id, s.id, l.id, {
|
|
|
175
206
|
return typeof e == "number" && !Number.isFinite(e);
|
|
176
207
|
},
|
|
177
208
|
encode(e, t, n) {
|
|
178
|
-
return Number.isNaN(e) ?
|
|
209
|
+
return Number.isNaN(e) ? d : e === Infinity ? f : e === -Infinity ? p : e;
|
|
179
210
|
},
|
|
180
211
|
decode(e, t, n) {
|
|
181
212
|
if (typeof e == "number") return e;
|
|
182
213
|
if (typeof e == "string") {
|
|
183
|
-
if (e ===
|
|
184
|
-
if (e ===
|
|
185
|
-
if (e ===
|
|
214
|
+
if (e === d) return NaN;
|
|
215
|
+
if (e === f) return Infinity;
|
|
216
|
+
if (e === p) return -Infinity;
|
|
186
217
|
let t = Number(e);
|
|
187
218
|
if (!Number.isNaN(t)) return t;
|
|
188
219
|
}
|
|
189
|
-
if (n.mode === "strict") throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...
|
|
220
|
+
if (n.mode === "strict") throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...m].join(", ")}.`);
|
|
190
221
|
return NaN;
|
|
191
222
|
}
|
|
192
223
|
}.id, Object.freeze({
|
|
@@ -413,13 +444,13 @@ r.id, i.id, o.id, s.id, l.id, {
|
|
|
413
444
|
});
|
|
414
445
|
//#endregion
|
|
415
446
|
//#region ../apigen-core-client/src/lib/get-safety.ts
|
|
416
|
-
var
|
|
447
|
+
var h = /* @__PURE__ */ new Set([
|
|
417
448
|
"string",
|
|
418
449
|
"number",
|
|
419
450
|
"boolean",
|
|
420
451
|
"integer"
|
|
421
452
|
]);
|
|
422
|
-
function
|
|
453
|
+
function g(e) {
|
|
423
454
|
if (!Array.isArray(e) || e.length < 2) return !1;
|
|
424
455
|
let t = 0;
|
|
425
456
|
for (let n of e) {
|
|
@@ -427,7 +458,7 @@ function h(e) {
|
|
|
427
458
|
let { type: e, $ref: r, oneOf: i, anyOf: a, allOf: o } = n;
|
|
428
459
|
if (r !== void 0 || i || a || o) return !1;
|
|
429
460
|
if (e !== "null") {
|
|
430
|
-
if (typeof e == "string" &&
|
|
461
|
+
if (typeof e == "string" && h.has(e)) {
|
|
431
462
|
t++;
|
|
432
463
|
continue;
|
|
433
464
|
}
|
|
@@ -436,46 +467,46 @@ function h(e) {
|
|
|
436
467
|
}
|
|
437
468
|
return t === 1;
|
|
438
469
|
}
|
|
439
|
-
function
|
|
470
|
+
function _(e) {
|
|
440
471
|
if (typeof e != "object" || !e) return !1;
|
|
441
472
|
let t = e;
|
|
442
473
|
if (t.$ref !== void 0 || t.allOf) return !1;
|
|
443
|
-
if (t.oneOf || t.anyOf) return
|
|
474
|
+
if (t.oneOf || t.anyOf) return g(t.oneOf ?? t.anyOf);
|
|
444
475
|
let { type: n } = t;
|
|
445
|
-
return typeof n == "string" ?
|
|
476
|
+
return typeof n == "string" ? h.has(n) : Array.isArray(n) ? n.every((e) => h.has(e) || e === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((e) => [
|
|
446
477
|
"string",
|
|
447
478
|
"number",
|
|
448
479
|
"boolean"
|
|
449
480
|
].includes(typeof e)) : !1;
|
|
450
481
|
}
|
|
451
|
-
function
|
|
482
|
+
function v(e) {
|
|
452
483
|
if (!e || typeof e != "object") return !1;
|
|
453
484
|
let t = e.properties;
|
|
454
|
-
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(
|
|
485
|
+
return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(_);
|
|
455
486
|
}
|
|
456
487
|
//#endregion
|
|
457
488
|
//#region ../apigen-core-client/src/lib/schema-builders/ts-json-schema.ts
|
|
458
|
-
var
|
|
459
|
-
function
|
|
489
|
+
var y = { "decimal.js": "Decimal" };
|
|
490
|
+
function b(e) {
|
|
460
491
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
461
492
|
}
|
|
462
|
-
Object.entries(
|
|
463
|
-
pattern: RegExp(`import\\(["'][^"']*${
|
|
493
|
+
Object.entries(y).map(([e, t]) => ({
|
|
494
|
+
pattern: RegExp(`import\\(["'][^"']*${b(e)}[^"']*["']\\)\\.\\w+`, "g"),
|
|
464
495
|
key: t
|
|
465
496
|
}));
|
|
466
497
|
//#endregion
|
|
467
498
|
//#region ../apigen-engine-naming/src/lib/naming.ts
|
|
468
|
-
function b(e) {
|
|
469
|
-
return e.words.join("-");
|
|
470
|
-
}
|
|
471
499
|
function x(e) {
|
|
472
|
-
return e.words.
|
|
500
|
+
return e.words.join("-");
|
|
473
501
|
}
|
|
474
502
|
function S(e) {
|
|
503
|
+
return e.words.map(T).join("");
|
|
504
|
+
}
|
|
505
|
+
function C(e) {
|
|
475
506
|
return e.words.join("_");
|
|
476
507
|
}
|
|
477
|
-
function
|
|
478
|
-
let n = [e.namespace, ...e.path], r = e.safe ||
|
|
508
|
+
function w(e, t = {}) {
|
|
509
|
+
let n = [e.namespace, ...e.path], r = e.safe || v(e.input) ? "GET" : "POST", i = t.http?.verb?.[e.id] ?? r, a = "/" + n.map((e) => x(e)).join("/"), o = n.map((e) => C(e)).join("_"), s = n.map((e) => C(e)).slice(0, -1).join("."), c = S(n[n.length - 2] ?? n[0]), l = S(n[n.length - 1]), u = n.map((e) => x(e));
|
|
479
510
|
return {
|
|
480
511
|
http: {
|
|
481
512
|
verb: i,
|
|
@@ -490,20 +521,20 @@ function C(e, t = {}) {
|
|
|
490
521
|
cli: { path: u }
|
|
491
522
|
};
|
|
492
523
|
}
|
|
493
|
-
function
|
|
524
|
+
function T(e) {
|
|
494
525
|
return e.length === 0 ? e : e[0].toUpperCase() + e.slice(1);
|
|
495
526
|
}
|
|
496
527
|
//#endregion
|
|
497
528
|
//#region ../codegen/openapi/src/lib/to-openapi.ts
|
|
498
|
-
function
|
|
529
|
+
function E(e, t = {}) {
|
|
499
530
|
let n = t.title ?? "API", r = t.version ?? "0.0.0", i = {};
|
|
500
531
|
for (let t of e) {
|
|
501
|
-
let { verb: e, route: n } =
|
|
532
|
+
let { verb: e, route: n } = w(t).http, r = e.toLowerCase(), a = {
|
|
502
533
|
operationId: t.id,
|
|
503
534
|
summary: t.id,
|
|
504
|
-
responses: { 200:
|
|
535
|
+
responses: { 200: D(t.output) }
|
|
505
536
|
};
|
|
506
|
-
if (e === "GET") a.parameters =
|
|
537
|
+
if (e === "GET") a.parameters = O(t.input);
|
|
507
538
|
else {
|
|
508
539
|
let e = t.input;
|
|
509
540
|
typeof e == "object" && e && Object.keys(e).length > 0 && (a.requestBody = {
|
|
@@ -522,13 +553,13 @@ function T(e, t = {}) {
|
|
|
522
553
|
paths: i
|
|
523
554
|
};
|
|
524
555
|
}
|
|
525
|
-
function
|
|
556
|
+
function D(e) {
|
|
526
557
|
return typeof e == "object" && e && Object.keys(e).length > 0 ? {
|
|
527
558
|
description: "Success",
|
|
528
559
|
content: { "application/json": { schema: e } }
|
|
529
560
|
} : { description: "Success" };
|
|
530
561
|
}
|
|
531
|
-
function
|
|
562
|
+
function O(e) {
|
|
532
563
|
if (typeof e != "object" || !e || typeof e.properties != "object" || e.properties === null) return [];
|
|
533
564
|
let t = Array.isArray(e.required) ? e.required : [], n = e.properties;
|
|
534
565
|
return Object.entries(n).map(([e, n]) => ({
|
|
@@ -540,7 +571,7 @@ function D(e) {
|
|
|
540
571
|
}
|
|
541
572
|
//#endregion
|
|
542
573
|
//#region src/lib/plugin.ts
|
|
543
|
-
function
|
|
574
|
+
function k(e, t = {}) {
|
|
544
575
|
return [{
|
|
545
576
|
...n("_meta/openapi", e, {
|
|
546
577
|
kind: "query",
|
|
@@ -548,13 +579,13 @@ function O(e, t = {}) {
|
|
|
548
579
|
output: { type: "object" },
|
|
549
580
|
transports: ["http"]
|
|
550
581
|
}),
|
|
551
|
-
handler: (n) =>
|
|
582
|
+
handler: (n) => E(e.operations, {
|
|
552
583
|
title: t.title,
|
|
553
584
|
version: t.version
|
|
554
585
|
})
|
|
555
586
|
}];
|
|
556
587
|
}
|
|
557
|
-
var
|
|
588
|
+
var A = {
|
|
558
589
|
id: "openapi",
|
|
559
590
|
description: "Mount plugin: serves the OpenAPI 3.1 doc at GET /meta/openapi",
|
|
560
591
|
language: "ts",
|
|
@@ -573,8 +604,8 @@ var k = {
|
|
|
573
604
|
additionalProperties: !1
|
|
574
605
|
},
|
|
575
606
|
capabilities: { mount: { operations(e, t) {
|
|
576
|
-
return
|
|
607
|
+
return k(e, t);
|
|
577
608
|
} } }
|
|
578
609
|
};
|
|
579
610
|
//#endregion
|
|
580
|
-
export {
|
|
611
|
+
export { A as default, A 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.7",
|
|
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.6",
|
|
7
|
+
"@adhd/apigen-codegen-openapi": "^0.2.7"
|
|
8
8
|
},
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|