@adhd/apigen-codegen-openapi 0.1.2 → 0.1.4
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 +28 -0
- package/index.js +1 -1
- package/index.mjs +47 -47
- package/package.json +3 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
## 0.1.4 (2026-07-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🚀 Features
|
|
5
|
+
|
|
6
|
+
- **apigen:** canonical route/tool-name projection across transports; serve + generate() + import-specifier fixes
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 🩹 Fixes
|
|
10
|
+
|
|
11
|
+
- **apigen:** externalize real npm deps in vite builds — 10 packages shipped broken dist bundles (__filename/timeOrigin crash)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### ❤️ Thank You
|
|
15
|
+
|
|
16
|
+
- pseudosky
|
|
17
|
+
|
|
18
|
+
## 0.1.3 (2026-07-23)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### 🩹 Fixes
|
|
22
|
+
|
|
23
|
+
- **apigen:** externalize real npm deps in vite builds — 10 packages shipped broken dist bundles (__filename/timeOrigin crash)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### ❤️ Thank You
|
|
27
|
+
|
|
28
|
+
- pseudosky
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ts-morph");require("node:fs");require("node:path");require("ts-json-schema-generator");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ts-morph");require("node:fs");require("node:path");require("ts-json-schema-generator");const y=new Set(["string","number","boolean","integer"]);function h(e){if(typeof e!="object"||e===null)return!1;const n=e;if(n.$ref!==void 0||n.oneOf||n.anyOf||n.allOf)return!1;const{type:o}=n;return typeof o=="string"?y.has(o):Array.isArray(o)?o.every(r=>y.has(r)||r==="null"):Array.isArray(n.enum)&&n.enum.length>0?n.enum.every(r=>["string","number","boolean"].includes(typeof r)):!1}function j(e){if(!e||typeof e!="object")return!1;const n=e.properties;return n===void 0||typeof n!="object"||n===null?!1:Object.values(n).every(h)}const v={"decimal.js":"Decimal"};function O(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(v).map(([e,n])=>({pattern:new RegExp(`import\\(["'][^"']*${O(e)}[^"']*["']\\)\\.\\w+`,"g"),key:n}));function m(e){return e.words.join("-")}function b(e){return e.words.map(A).join("")}function g(e){return e.words.join("_")}function q(e,n={}){var o,r;const t=[e.namespace,...e.path],i=e.safe||j(e.input)?"GET":"POST",l=((r=(o=n.http)==null?void 0:o.verb)==null?void 0:r[e.id])??i,u="/"+t.map(s=>m(s)).join("/"),a=t.map(s=>g(s)).join("_"),f=t.map(s=>g(s)).slice(0,-1).join("."),p=b(t[t.length-2]??t[0]),c=b(t[t.length-1]),d=t.map(s=>m(s));return{http:{verb:l,route:u},mcp:{name:a},grpc:{package:f,service:p,method:c},cli:{path:d}}}function A(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function w(e,n={}){const o=n.title??"API",r=n.version??"0.0.0",t={};for(const i of e){const l=q(i),{verb:u,route:a}=l.http,f=u.toLowerCase(),p={operationId:i.id,summary:i.id,responses:{200:S(i.output)}};if(u==="GET")p.parameters=_(i.input);else{const c=i.input;typeof c=="object"&&c!==null&&Object.keys(c).length>0&&(p.requestBody={required:!0,content:{"application/json":{schema:c}}})}t[a]===void 0&&(t[a]={}),t[a][f]=p}return{openapi:"3.1.0",info:{title:o,version:r},paths:t}}function S(e){return typeof e=="object"&&e!==null&&Object.keys(e).length>0?{description:"Success",content:{"application/json":{schema:e}}}:{description:"Success"}}function _(e){if(typeof e!="object"||e===null||typeof e.properties!="object"||e.properties===null)return[];const n=Array.isArray(e.required)?e.required:[],o=e.properties;return Object.entries(o).map(([r,t])=>({name:r,in:"query",required:n.includes(r),schema:t}))}const k="@adhd/apigen-codegen-openapi";exports.__apigen_pkg=k;exports.toOpenApi=w;
|
package/index.mjs
CHANGED
|
@@ -2,31 +2,31 @@ import "ts-morph";
|
|
|
2
2
|
import "node:fs";
|
|
3
3
|
import "node:path";
|
|
4
4
|
import "ts-json-schema-generator";
|
|
5
|
-
const
|
|
5
|
+
const m = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
|
|
6
6
|
function j(e) {
|
|
7
7
|
if (typeof e != "object" || e === null)
|
|
8
8
|
return !1;
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
9
|
+
const n = e;
|
|
10
|
+
if (n.$ref !== void 0 || n.oneOf || n.anyOf || n.allOf)
|
|
11
11
|
return !1;
|
|
12
|
-
const { type:
|
|
13
|
-
return typeof
|
|
12
|
+
const { type: o } = n;
|
|
13
|
+
return typeof o == "string" ? m.has(o) : Array.isArray(o) ? o.every((r) => m.has(r) || r === "null") : Array.isArray(n.enum) && n.enum.length > 0 ? n.enum.every((r) => ["string", "number", "boolean"].includes(typeof r)) : !1;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function g(e) {
|
|
16
16
|
if (!e || typeof e != "object")
|
|
17
17
|
return !1;
|
|
18
|
-
const
|
|
19
|
-
return
|
|
18
|
+
const n = e.properties;
|
|
19
|
+
return n === void 0 || typeof n != "object" || n === null ? !1 : Object.values(n).every(
|
|
20
20
|
j
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
|
-
const
|
|
23
|
+
const v = {
|
|
24
24
|
"decimal.js": "Decimal"
|
|
25
25
|
};
|
|
26
|
-
function
|
|
26
|
+
function O(e) {
|
|
27
27
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
28
28
|
}
|
|
29
|
-
Object.entries(
|
|
29
|
+
Object.entries(v).map(([e, n]) => ({
|
|
30
30
|
// Matches: import("...{modSpec}...").<anyMemberName> (single or double quotes)
|
|
31
31
|
// The module specifier appears inside an absolute path, so we allow any
|
|
32
32
|
// characters between the quote and the specifier, and between the specifier
|
|
@@ -34,65 +34,65 @@ Object.entries(O).map(([e, t]) => ({
|
|
|
34
34
|
// …) is matched generically (`\w+`) rather than anchored to one spelling —
|
|
35
35
|
// see the doc comment above for why.
|
|
36
36
|
pattern: new RegExp(
|
|
37
|
-
`import\\(["'][^"']*${
|
|
37
|
+
`import\\(["'][^"']*${O(e)}[^"']*["']\\)\\.\\w+`,
|
|
38
38
|
"g"
|
|
39
39
|
),
|
|
40
|
-
key:
|
|
40
|
+
key: n
|
|
41
41
|
}));
|
|
42
|
-
function
|
|
42
|
+
function y(e) {
|
|
43
43
|
return e.words.join("-");
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function h(e) {
|
|
46
46
|
return e.words.map(A).join("");
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function b(e) {
|
|
49
49
|
return e.words.join("_");
|
|
50
50
|
}
|
|
51
|
-
function
|
|
52
|
-
var
|
|
53
|
-
const
|
|
51
|
+
function w(e, n = {}) {
|
|
52
|
+
var o, r;
|
|
53
|
+
const t = [e.namespace, ...e.path], i = e.safe || g(e.input) ? "GET" : "POST", l = ((r = (o = n.http) == null ? void 0 : o.verb) == null ? void 0 : r[e.id]) ?? i, u = "/" + t.map((s) => y(s)).join("/"), p = t.map((s) => b(s)).join("_"), f = t.map((s) => b(s)).slice(0, -1).join("."), a = h(t[t.length - 2] ?? t[0]), c = h(t[t.length - 1]), d = t.map((s) => y(s));
|
|
54
54
|
return {
|
|
55
|
-
http: { verb:
|
|
56
|
-
mcp: { name:
|
|
57
|
-
grpc: { package:
|
|
58
|
-
cli: { path:
|
|
55
|
+
http: { verb: l, route: u },
|
|
56
|
+
mcp: { name: p },
|
|
57
|
+
grpc: { package: f, service: a, method: c },
|
|
58
|
+
cli: { path: d }
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function A(e) {
|
|
62
62
|
return e.length === 0 ? e : e[0].toUpperCase() + e.slice(1);
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
const
|
|
66
|
-
for (const
|
|
67
|
-
const
|
|
68
|
-
operationId:
|
|
69
|
-
summary:
|
|
64
|
+
function E(e, n = {}) {
|
|
65
|
+
const o = n.title ?? "API", r = n.version ?? "0.0.0", t = {};
|
|
66
|
+
for (const i of e) {
|
|
67
|
+
const l = w(i), { verb: u, route: p } = l.http, f = u.toLowerCase(), a = {
|
|
68
|
+
operationId: i.id,
|
|
69
|
+
summary: i.id,
|
|
70
70
|
responses: {
|
|
71
|
-
200:
|
|
71
|
+
200: q(i.output)
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
-
if (
|
|
75
|
-
|
|
74
|
+
if (u === "GET")
|
|
75
|
+
a.parameters = S(i.input);
|
|
76
76
|
else {
|
|
77
|
-
const
|
|
78
|
-
typeof
|
|
77
|
+
const c = i.input;
|
|
78
|
+
typeof c == "object" && c !== null && Object.keys(c).length > 0 && (a.requestBody = {
|
|
79
79
|
required: !0,
|
|
80
80
|
content: {
|
|
81
81
|
"application/json": {
|
|
82
|
-
schema:
|
|
82
|
+
schema: c
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
t[p] === void 0 && (t[p] = {}), t[p][f] = a;
|
|
88
88
|
}
|
|
89
89
|
return {
|
|
90
90
|
openapi: "3.1.0",
|
|
91
|
-
info: { title:
|
|
92
|
-
paths:
|
|
91
|
+
info: { title: o, version: r },
|
|
92
|
+
paths: t
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
-
function
|
|
95
|
+
function q(e) {
|
|
96
96
|
return typeof e == "object" && e !== null && Object.keys(e).length > 0 ? {
|
|
97
97
|
description: "Success",
|
|
98
98
|
content: {
|
|
@@ -100,19 +100,19 @@ function P(e) {
|
|
|
100
100
|
}
|
|
101
101
|
} : { description: "Success" };
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function S(e) {
|
|
104
104
|
if (typeof e != "object" || e === null || typeof e.properties != "object" || e.properties === null)
|
|
105
105
|
return [];
|
|
106
|
-
const
|
|
107
|
-
return Object.entries(
|
|
106
|
+
const n = Array.isArray(e.required) ? e.required : [], o = e.properties;
|
|
107
|
+
return Object.entries(o).map(([r, t]) => ({
|
|
108
108
|
name: r,
|
|
109
109
|
in: "query",
|
|
110
|
-
required:
|
|
111
|
-
schema:
|
|
110
|
+
required: n.includes(r),
|
|
111
|
+
schema: t
|
|
112
112
|
}));
|
|
113
113
|
}
|
|
114
|
-
const
|
|
114
|
+
const P = "@adhd/apigen-codegen-openapi";
|
|
115
115
|
export {
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
P as __apigen_pkg,
|
|
117
|
+
E as toOpenApi
|
|
118
118
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhd/apigen-codegen-openapi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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.1.
|
|
12
|
-
"@adhd/apigen-engine-naming": "^0.1.
|
|
11
|
+
"@adhd/apigen-core-client": "^0.1.2",
|
|
12
|
+
"@adhd/apigen-engine-naming": "^0.1.3"
|
|
13
13
|
}
|
|
14
14
|
}
|