@adhd/apigen-codegen-openapi 0.1.1 → 0.1.2

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