@acid-cat/spec-ts 0.7.0 → 0.9.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.d.ts +14 -0
- package/dist/index.js +36 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,20 @@ export declare const cliExitCode: (outcome: Outcome<unknown, unknown>) => number
|
|
|
63
63
|
* code point order of the names. `input` is the bundled input schema.
|
|
64
64
|
*/
|
|
65
65
|
export declare function cliFlags(input: JsonObject): string[];
|
|
66
|
+
/** A property schema, or the type in `definitions` that its `$ref` refers to. */
|
|
67
|
+
export declare function cliResolve(property: JsonObject, definitions: JsonObject): JsonObject;
|
|
68
|
+
/**
|
|
69
|
+
* The schema of the items of a repeated flag (spec/bindings/cli.md#commands), or `undefined` when the property does
|
|
70
|
+
* not give a repeated flag. A property gives a repeated flag when its type is `array`, and its `items` schema, or the
|
|
71
|
+
* type that it refers to, is an `enum` of strings, `integer`, `number` or `string`. `property` is already resolved.
|
|
72
|
+
*/
|
|
73
|
+
export declare function cliRepeatedItems(property: JsonObject, definitions: JsonObject): JsonObject | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* The array that a repeated flag gives as JSON text (spec/bindings/cli.md#commands), or `undefined` when its values
|
|
76
|
+
* give one item each. `values` are the values of the flag, in the order of the flags. They give an array as JSON text
|
|
77
|
+
* when the flag occurs exactly once and its value is JSON text of an array.
|
|
78
|
+
*/
|
|
79
|
+
export declare function cliJsonArray(values: readonly string[]): readonly unknown[] | undefined;
|
|
66
80
|
/**
|
|
67
81
|
* The `usage` of a capability in `list` (spec/bindings/cli.md#commands). `input` is the bundled input schema, or
|
|
68
82
|
* `undefined` when the capability has no input.
|
package/dist/index.js
CHANGED
|
@@ -68,16 +68,45 @@ function cliFlags(input) {
|
|
|
68
68
|
const byName = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
69
69
|
const names = Object.keys(properties).sort(byName);
|
|
70
70
|
return [...names.filter((name) => required.has(name)), ...names.filter((name) => !required.has(name))].map((name) => {
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const property = objectOrEmpty((target === void 0 ? void 0 : definitions[target]) ?? declared);
|
|
75
|
-
const flag = property.type === "boolean" ? `--${name}` : `--${name} <${flagValue(property)}>`;
|
|
71
|
+
const property = cliResolve(objectOrEmpty(properties[name]), definitions);
|
|
72
|
+
const items = cliRepeatedItems(property, definitions);
|
|
73
|
+
const flag = items !== void 0 ? `--${name} <${flagValue(items)}>...` : property.type === "boolean" ? `--${name}` : `--${name} <${flagValue(property)}>`;
|
|
76
74
|
return required.has(name) ? flag : `[${flag}]`;
|
|
77
75
|
});
|
|
78
76
|
}
|
|
77
|
+
/** A property schema, or the type in `definitions` that its `$ref` refers to. */
|
|
78
|
+
function cliResolve(property, definitions) {
|
|
79
|
+
const target = typeof property.$ref === "string" ? REFERENCE.exec(property.$ref)?.[1] : void 0;
|
|
80
|
+
return target === void 0 ? property : objectOrEmpty(definitions[target] ?? property);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The schema of the items of a repeated flag (spec/bindings/cli.md#commands), or `undefined` when the property does
|
|
84
|
+
* not give a repeated flag. A property gives a repeated flag when its type is `array`, and its `items` schema, or the
|
|
85
|
+
* type that it refers to, is an `enum` of strings, `integer`, `number` or `string`. `property` is already resolved.
|
|
86
|
+
*/
|
|
87
|
+
function cliRepeatedItems(property, definitions) {
|
|
88
|
+
if (property.type !== "array" || !isJsonObject(property.items)) return void 0;
|
|
89
|
+
const items = cliResolve(property.items, definitions);
|
|
90
|
+
return isStringEnum(items.enum) || items.type === "integer" || items.type === "number" || items.type === "string" ? items : void 0;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The array that a repeated flag gives as JSON text (spec/bindings/cli.md#commands), or `undefined` when its values
|
|
94
|
+
* give one item each. `values` are the values of the flag, in the order of the flags. They give an array as JSON text
|
|
95
|
+
* when the flag occurs exactly once and its value is JSON text of an array.
|
|
96
|
+
*/
|
|
97
|
+
function cliJsonArray(values) {
|
|
98
|
+
const [value] = values;
|
|
99
|
+
if (values.length !== 1 || value === void 0) return void 0;
|
|
100
|
+
try {
|
|
101
|
+
const parsed = JSON.parse(value);
|
|
102
|
+
return Array.isArray(parsed) ? parsed : void 0;
|
|
103
|
+
} catch {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const isStringEnum = (value) => Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string");
|
|
79
108
|
function flagValue(property) {
|
|
80
|
-
if (
|
|
109
|
+
if (isStringEnum(property.enum)) return property.enum.join("|");
|
|
81
110
|
if (property.type === "integer" || property.type === "number" || property.type === "string") return property.type;
|
|
82
111
|
return "json";
|
|
83
112
|
}
|
|
@@ -271,4 +300,4 @@ function viewOf(catalog, target) {
|
|
|
271
300
|
};
|
|
272
301
|
}
|
|
273
302
|
//#endregion
|
|
274
|
-
export { AVAILABLE, CALL_FAILURE_KINDS, CLI_EXIT_CODES, CallFailureError, HTTP_STATUS, ID_PATTERN, MCP_PROTOCOL_VERSION, MCP_REJECTIONS, MCP_UNKNOWN_TOOL, REFERENCE, bundle, callFailure, cliExitCode, cliFlags, cliUsage, commandPath, fail, httpStatus, isCallFailure, isId, isJsonObject, mcpToolResult, objectInput, ok, readBounded, schemasOf, screenRequest, typesUsedBy, unavailable, viewOf, visitObjects };
|
|
303
|
+
export { AVAILABLE, CALL_FAILURE_KINDS, CLI_EXIT_CODES, CallFailureError, HTTP_STATUS, ID_PATTERN, MCP_PROTOCOL_VERSION, MCP_REJECTIONS, MCP_UNKNOWN_TOOL, REFERENCE, bundle, callFailure, cliExitCode, cliFlags, cliJsonArray, cliRepeatedItems, cliResolve, cliUsage, commandPath, fail, httpStatus, isCallFailure, isId, isJsonObject, mcpToolResult, objectInput, ok, readBounded, schemasOf, screenRequest, typesUsedBy, unavailable, viewOf, visitObjects };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acid-cat/spec-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "The fixed details of the AcidCat specification as TypeScript data and pure functions, with no dependencies. Part of the TypeScript reference implementation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"acidcat",
|