@zeroxyz/cli 1.3.0 → 1.5.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/index.js +105 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -76582,7 +76582,7 @@ init_esm_shims();
|
|
|
76582
76582
|
|
|
76583
76583
|
// package.json
|
|
76584
76584
|
var package_default = {
|
|
76585
|
-
version: "1.
|
|
76585
|
+
version: "1.5.0"};
|
|
76586
76586
|
|
|
76587
76587
|
// src/app.ts
|
|
76588
76588
|
init_esm_shims();
|
|
@@ -147012,12 +147012,27 @@ var coerceToType = (value, type2) => {
|
|
|
147012
147012
|
}
|
|
147013
147013
|
return value;
|
|
147014
147014
|
};
|
|
147015
|
-
var sampleValueFor = (fieldName, propSchema) => {
|
|
147015
|
+
var sampleValueFor = (fieldName, propSchema, depth = 0) => {
|
|
147016
147016
|
const node = asNode(propSchema);
|
|
147017
147017
|
const type2 = schemaType(node);
|
|
147018
|
-
const
|
|
147019
|
-
|
|
147020
|
-
|
|
147018
|
+
const enumFirst = Array.isArray(node?.enum) && node.enum.length > 0 ? node.enum[0] : void 0;
|
|
147019
|
+
const fixed = node?.const ?? node?.example ?? node?.default ?? enumFirst;
|
|
147020
|
+
if (fixed !== void 0 && fixed !== null) {
|
|
147021
|
+
return coerceToType(fixed, type2);
|
|
147022
|
+
}
|
|
147023
|
+
if (node && depth < MAX_SCHEMA_DEPTH) {
|
|
147024
|
+
const props = asNode(node.properties);
|
|
147025
|
+
if (props && (type2 === "object" || type2 === void 0)) {
|
|
147026
|
+
const obj = {};
|
|
147027
|
+
for (const [k3, sub] of Object.entries(props)) {
|
|
147028
|
+
obj[k3] = sampleValueFor(k3, sub, depth + 1);
|
|
147029
|
+
}
|
|
147030
|
+
return obj;
|
|
147031
|
+
}
|
|
147032
|
+
if (type2 === "array") {
|
|
147033
|
+
const items = asNode(node.items);
|
|
147034
|
+
return items ? [sampleValueFor(fieldName, items, depth + 1)] : [];
|
|
147035
|
+
}
|
|
147021
147036
|
}
|
|
147022
147037
|
switch (type2) {
|
|
147023
147038
|
case "number":
|
|
@@ -147061,35 +147076,87 @@ var schemaTypeLabel = (node) => {
|
|
|
147061
147076
|
};
|
|
147062
147077
|
var constraintHint = (node) => {
|
|
147063
147078
|
const num2 = (k3) => typeof node[k3] === "number" ? node[k3] : void 0;
|
|
147079
|
+
const hints = [];
|
|
147064
147080
|
const min = num2("minimum");
|
|
147065
147081
|
const max = num2("maximum");
|
|
147066
|
-
if (min !== void 0 && max !== void 0)
|
|
147067
|
-
|
|
147068
|
-
if (
|
|
147082
|
+
if (min !== void 0 && max !== void 0)
|
|
147083
|
+
hints.push(`range: ${min}..${max}`);
|
|
147084
|
+
else if (min !== void 0) hints.push(`min: ${min}`);
|
|
147085
|
+
else if (max !== void 0) hints.push(`max: ${max}`);
|
|
147086
|
+
const exMin = num2("exclusiveMinimum");
|
|
147087
|
+
const exMax = num2("exclusiveMaximum");
|
|
147088
|
+
if (exMin !== void 0) hints.push(`> ${exMin}`);
|
|
147089
|
+
if (exMax !== void 0) hints.push(`< ${exMax}`);
|
|
147069
147090
|
const minLen = num2("minLength");
|
|
147070
147091
|
const maxLen = num2("maxLength");
|
|
147071
147092
|
if (minLen !== void 0 && maxLen !== void 0)
|
|
147072
|
-
|
|
147073
|
-
if (maxLen !== void 0)
|
|
147074
|
-
if (minLen !== void 0)
|
|
147075
|
-
|
|
147076
|
-
|
|
147077
|
-
|
|
147078
|
-
|
|
147093
|
+
hints.push(`length: ${minLen}..${maxLen}`);
|
|
147094
|
+
else if (maxLen !== void 0) hints.push(`maxLength: ${maxLen}`);
|
|
147095
|
+
else if (minLen !== void 0) hints.push(`minLength: ${minLen}`);
|
|
147096
|
+
const minItems = num2("minItems");
|
|
147097
|
+
const maxItems = num2("maxItems");
|
|
147098
|
+
if (minItems !== void 0 && maxItems !== void 0)
|
|
147099
|
+
hints.push(`items: ${minItems}..${maxItems}`);
|
|
147100
|
+
else if (maxItems !== void 0) hints.push(`maxItems: ${maxItems}`);
|
|
147101
|
+
else if (minItems !== void 0) hints.push(`minItems: ${minItems}`);
|
|
147102
|
+
if (typeof node.pattern === "string") hints.push(`pattern: ${node.pattern}`);
|
|
147103
|
+
return hints.length > 0 ? hints.join(", ") : null;
|
|
147104
|
+
};
|
|
147105
|
+
var MAX_SCHEMA_DEPTH = 5;
|
|
147106
|
+
var paramAttrs = (node, required3) => {
|
|
147079
147107
|
const attrs = [schemaTypeLabel(node)];
|
|
147080
147108
|
if (required3) attrs.push("required");
|
|
147109
|
+
if (node.const !== void 0)
|
|
147110
|
+
attrs.push(`const: ${JSON.stringify(node.const)}`);
|
|
147081
147111
|
if (node.default !== void 0)
|
|
147082
147112
|
attrs.push(`default: ${JSON.stringify(node.default)}`);
|
|
147083
147113
|
if (Array.isArray(node.enum))
|
|
147084
147114
|
attrs.push(`one of: ${node.enum.map((v) => String(v)).join(" | ")}`);
|
|
147115
|
+
if (typeof node.format === "string") attrs.push(`format: ${node.format}`);
|
|
147085
147116
|
const hint = constraintHint(node);
|
|
147086
147117
|
if (hint) attrs.push(hint);
|
|
147087
|
-
|
|
147118
|
+
return attrs.join(", ");
|
|
147119
|
+
};
|
|
147120
|
+
var renderParam = (name, propSchema, required3, depth = 0) => {
|
|
147121
|
+
const node = asNode(propSchema) ?? {};
|
|
147122
|
+
const pad9 = ` ${" ".repeat(depth)}`;
|
|
147123
|
+
const lines = [`${pad9}${name} (${paramAttrs(node, required3)})`];
|
|
147088
147124
|
const desc = typeof node.description === "string" ? node.description.trim() : "";
|
|
147089
|
-
if (desc) lines.push(
|
|
147125
|
+
if (desc) lines.push(`${pad9} ${desc}`);
|
|
147126
|
+
if (depth >= MAX_SCHEMA_DEPTH) return lines;
|
|
147127
|
+
if (asNode(node.properties)) {
|
|
147128
|
+
lines.push(...renderProps(node, depth + 1));
|
|
147129
|
+
}
|
|
147130
|
+
const items = asNode(node.items);
|
|
147131
|
+
if (items) {
|
|
147132
|
+
if (asNode(items.properties)) {
|
|
147133
|
+
lines.push(`${pad9} each item (${schemaTypeLabel(items)}):`);
|
|
147134
|
+
lines.push(...renderProps(items, depth + 2));
|
|
147135
|
+
} else {
|
|
147136
|
+
lines.push(`${pad9} each item (${paramAttrs(items, false)})`);
|
|
147137
|
+
}
|
|
147138
|
+
}
|
|
147139
|
+
const variants = Array.isArray(node.oneOf) ? node.oneOf : Array.isArray(node.anyOf) ? node.anyOf : null;
|
|
147140
|
+
if (variants && variants.length > 0) {
|
|
147141
|
+
lines.push(`${pad9} one of these shapes:`);
|
|
147142
|
+
variants.forEach((v, i) => {
|
|
147143
|
+
lines.push(...renderParam(`option ${i + 1}`, v, false, depth + 2));
|
|
147144
|
+
});
|
|
147145
|
+
}
|
|
147146
|
+
if (Array.isArray(node.allOf) && node.allOf.length > 0) {
|
|
147147
|
+
lines.push(`${pad9} must satisfy all of:`);
|
|
147148
|
+
node.allOf.forEach((v, i) => {
|
|
147149
|
+
lines.push(...renderParam(`part ${i + 1}`, v, false, depth + 2));
|
|
147150
|
+
});
|
|
147151
|
+
}
|
|
147152
|
+
if (typeof node.$ref === "string") {
|
|
147153
|
+
lines.push(
|
|
147154
|
+
`${pad9} \u26A0 schema reference not inlined (${node.$ref}) \u2014 shape incomplete, see provider docs`
|
|
147155
|
+
);
|
|
147156
|
+
}
|
|
147090
147157
|
return lines;
|
|
147091
147158
|
};
|
|
147092
|
-
var renderProps = (node) => {
|
|
147159
|
+
var renderProps = (node, depth = 0) => {
|
|
147093
147160
|
const props = node ? asNode(node.properties) : null;
|
|
147094
147161
|
if (!props) return [];
|
|
147095
147162
|
const entries = Object.entries(props);
|
|
@@ -147098,7 +147165,7 @@ var renderProps = (node) => {
|
|
|
147098
147165
|
Array.isArray(node?.required) ? node.required.filter((x2) => typeof x2 === "string") : []
|
|
147099
147166
|
);
|
|
147100
147167
|
return entries.flatMap(
|
|
147101
|
-
([name, schema]) => renderParam(name, schema, requiredSet.has(name))
|
|
147168
|
+
([name, schema]) => renderParam(name, schema, requiredSet.has(name), depth)
|
|
147102
147169
|
);
|
|
147103
147170
|
};
|
|
147104
147171
|
var buildSchemaSection = (capability) => {
|
|
@@ -147106,7 +147173,17 @@ var buildSchemaSection = (capability) => {
|
|
|
147106
147173
|
capability.bodySchema,
|
|
147107
147174
|
capability.method
|
|
147108
147175
|
);
|
|
147109
|
-
|
|
147176
|
+
const lines = [...renderProps(queryParams), ...renderProps(body)];
|
|
147177
|
+
if (lines.length === 0) {
|
|
147178
|
+
const root = asNode(capability.bodySchema);
|
|
147179
|
+
const unresolved = (n) => !!n && (n.$ref !== void 0 || Array.isArray(n.allOf));
|
|
147180
|
+
if (unresolved(root ?? void 0) || unresolved(queryParams) || unresolved(body)) {
|
|
147181
|
+
return [
|
|
147182
|
+
" \u26A0 input schema could not be expanded ($ref/allOf not inlined) \u2014 use the verified example below or the provider's docs"
|
|
147183
|
+
];
|
|
147184
|
+
}
|
|
147185
|
+
}
|
|
147186
|
+
return lines;
|
|
147110
147187
|
};
|
|
147111
147188
|
var buildResponseSection = (capability) => {
|
|
147112
147189
|
const rs = asNode(capability.responseSchema);
|
|
@@ -147126,6 +147203,13 @@ var buildResponseSection = (capability) => {
|
|
|
147126
147203
|
}
|
|
147127
147204
|
return [];
|
|
147128
147205
|
};
|
|
147206
|
+
var buildVerifiedExampleSection = (capability) => {
|
|
147207
|
+
const req = capability.example?.request;
|
|
147208
|
+
if (req === void 0 || req === null) return [];
|
|
147209
|
+
const json3 = typeof req === "string" ? req : JSON.stringify(req);
|
|
147210
|
+
const truncated = json3.length > 600 ? `${json3.slice(0, 600)}\u2026` : json3;
|
|
147211
|
+
return ["", "Verified example (request):", ` ${truncated}`];
|
|
147212
|
+
};
|
|
147129
147213
|
var buildTryItExample = (capability) => {
|
|
147130
147214
|
const method = capability.method.toUpperCase();
|
|
147131
147215
|
const lines = ["", "Try it:"];
|
|
@@ -147199,6 +147283,7 @@ var formatCapability = (capability) => {
|
|
|
147199
147283
|
lines.push("", "Parameters:");
|
|
147200
147284
|
lines.push(...schemaLines);
|
|
147201
147285
|
}
|
|
147286
|
+
lines.push(...buildVerifiedExampleSection(capability));
|
|
147202
147287
|
lines.push(...buildResponseSection(capability));
|
|
147203
147288
|
lines.push(...buildTryItExample(capability));
|
|
147204
147289
|
return lines.join("\n");
|