@faable/deploy-sdk 2.14.0 → 2.16.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@faable/deploy-sdk",
3
3
  "description": "Codebase for SDK building",
4
- "version": "2.14.0",
4
+ "version": "2.16.0",
5
5
  "author": "Marc Pomar <marc@faable.com>",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "access": "public"
12
12
  },
13
13
  "dependencies": {
14
- "@faable/sdk-base": "^1.5.6"
14
+ "@faable/sdk-base": "^1.7.0"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@septh/ts-run": "^1.3.0",
@@ -87,6 +87,40 @@ for (const [path, methods] of Object.entries(spec.paths || {})) {
87
87
  }
88
88
  operations.sort((a, b) => a.op.operationId.localeCompare(b.op.operationId));
89
89
 
90
+ // Multi-line descriptions become one JSDoc line each.
91
+ const escapeBlock = (text) =>
92
+ String(text)
93
+ .split("\n")
94
+ .map((l) => ` * ${escape(l)}`);
95
+
96
+ // The server documents each 4xx/5xx as an ErrorResponse whose `error_code`
97
+ // is restricted to an enum, and describes every code in the response
98
+ // description as "`code` — text" lines. Read both back so the docstring can
99
+ // list what a caller may branch on.
100
+ const errorCodesOf = (op) => {
101
+ const out = [];
102
+ const seen = new Set();
103
+ for (const [status, res] of Object.entries(op.responses || {})) {
104
+ if (!/^[45]\d\d$/.test(status)) continue;
105
+ const schema = res?.content?.["application/json"]?.schema;
106
+ const parts = schema?.allOf || (schema ? [schema] : []);
107
+ const codes = parts.flatMap((p) => p?.properties?.error_code?.enum || []);
108
+ const descriptions = new Map(
109
+ String(res?.description || "")
110
+ .split("\n")
111
+ .map((l) => l.match(/^`([a-z_]+)` — (.*)$/))
112
+ .filter(Boolean)
113
+ .map((m) => [m[1], m[2]]),
114
+ );
115
+ for (const code of codes) {
116
+ if (seen.has(code)) continue;
117
+ seen.add(code);
118
+ out.push({ code, status, description: descriptions.get(code) });
119
+ }
120
+ }
121
+ return out;
122
+ };
123
+
90
124
  const emitMethod = ({ path, httpMethod, op }) => {
91
125
  const id = op.operationId;
92
126
  const name = toMethodName(id);
@@ -146,11 +180,23 @@ const emitMethod = ({ path, httpMethod, op }) => {
146
180
  }
147
181
 
148
182
  const guards = pathParams.map((p) => ` requireId("${p}", ${p});`);
149
- const doc = op.summary || op.description;
183
+ // Summary AND description: the CRUD summaries are generic ("Get User") and
184
+ // used to hide the prose that actually explains the endpoint.
185
+ const docLines = [op.summary, op.description]
186
+ .filter((x, i, all) => x && all.indexOf(x) === i)
187
+ .flatMap((text, i) => [...(i ? [" *"] : []), ...escapeBlock(text)]);
188
+ // One `@throws` per documented error code, read from the 4xx/5xx responses
189
+ // the server injects (see auth's server/openapi_errors.ts). The code is
190
+ // `err.error_code` on the FaableApiError the fetcher throws.
191
+ const throwsLines = errorCodesOf(op).map(
192
+ ({ code, status, description }) =>
193
+ ` * @throws {FaableApiError} \`${code}\` (${status})${description ? ` — ${escape(description)}` : ""}`,
194
+ );
150
195
  const jsdoc = [
151
196
  " /**",
152
197
  ` * \`${httpMethod.toUpperCase()} ${path}\` — operationId: \`${id}\``,
153
- ...(doc ? [` *`, ` * ${escape(doc)}`] : []),
198
+ ...(docLines.length ? [" *", ...docLines] : []),
199
+ ...(throwsLines.length ? [" *", ...throwsLines] : []),
154
200
  " */",
155
201
  ].join("\n");
156
202