@jinshuju/cli 0.15.0 → 0.17.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/dist/http.js CHANGED
@@ -76,9 +76,25 @@ function describeFailure(response, text, parsed) {
76
76
  const body = parsed.value;
77
77
  const stated = body.message ?? body.error_description;
78
78
  if (typeof stated === 'string' && stated.trim())
79
- return stated;
79
+ return everyReason(body, stated) ?? stated;
80
80
  return rowErrors(body) ?? `${status}: ${snippet(JSON.stringify(parsed.value))}`;
81
81
  }
82
+ /**
83
+ * A refusal with several reasons that states only the first: a routine against
84
+ * two of the page's rules answers `{error_description, errors: [{code, message}]}`
85
+ * with error_description the first message. Repeating that alone would send the
86
+ * caller round again to learn the second. A body whose error_description says
87
+ * something of its own, as a 400 does, is left to say it.
88
+ */
89
+ function everyReason(body, stated) {
90
+ const errors = body.errors;
91
+ if (!Array.isArray(errors) || errors.length < 2)
92
+ return undefined;
93
+ const messages = errors.map((item) => item?.message);
94
+ if (messages[0] !== stated || !messages.every((message) => typeof message === 'string'))
95
+ return undefined;
96
+ return messages.join('; ');
97
+ }
82
98
  /**
83
99
  * A batch write answers per row: `{errors: [{index, reason}]}`. The index is the
84
100
  * caller's own array position, and is left as the server gave it so it lines up
package/dist/spec.js CHANGED
@@ -197,7 +197,11 @@ function walk(from, steps) {
197
197
  }
198
198
  return schema;
199
199
  }
200
- /** A property as an object schema or any of its allOf parts declares it. */
200
+ /**
201
+ * A property as an object schema or any of its allOf parts declares it. A body
202
+ * that is one of several shapes (oneOf / anyOf) declares it in each shape that
203
+ * has it, and the property takes what any of them allows.
204
+ */
201
205
  function propertyOf(schema, name) {
202
206
  const here = resolved(schema);
203
207
  const own = here.properties?.[name];
@@ -210,12 +214,21 @@ function propertyOf(schema, name) {
210
214
  if (found)
211
215
  return found;
212
216
  }
213
- return undefined;
217
+ const shapes = [...(here.oneOf ?? []), ...(here.anyOf ?? [])].flatMap((part) => {
218
+ const found = typeof part === 'object' ? propertyOf(part, name) : undefined;
219
+ return found ? [found] : [];
220
+ });
221
+ return shapes.length > 0 ? { anyOf: shapes } : undefined;
214
222
  }
215
223
  function enumOf(schema, what) {
216
- const values = (schema ? (resolved(schema).enum ?? []) : []).filter((value) => typeof value === 'string');
224
+ const values = [...new Set(schema ? valuesOf(schema) : [])];
217
225
  if (values.length > 0)
218
226
  return values;
219
227
  unanswered.push(what);
220
228
  return undefined;
221
229
  }
230
+ function valuesOf(schema) {
231
+ const here = resolved(schema);
232
+ const own = (here.enum ?? []).filter((value) => typeof value === 'string');
233
+ return [...own, ...(here.anyOf ?? []).flatMap((part) => (typeof part === 'object' ? valuesOf(part) : []))];
234
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jinshuju/cli",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "Command line interface for Jinshuju Open API v1",
5
5
  "homepage": "https://github.com/jinshuju/cli#readme",
6
6
  "bugs": {