@acid-cat/spec-ts 0.3.0 → 0.4.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 CHANGED
@@ -151,6 +151,14 @@ export declare function visitObjects(value: unknown, onObject: (node: JsonObject
151
151
  export declare function typesUsedBy(schema: unknown, types: {
152
152
  readonly [name: string]: JsonObject;
153
153
  }): Map<string, JsonObject>;
154
+ /**
155
+ * An input schema that is a union of object schemas, with `"type": "object"`, so that it is an object schema
156
+ * (spec/catalog.md#capabilities). A union is `anyOf` or `oneOf`, directly or in the type that a `$ref` names. Each of
157
+ * its schemas is an object, or a `$ref` to a type that is an object. Other schemas do not change.
158
+ */
159
+ export declare function objectInput(schema: JsonObject, types: {
160
+ readonly [name: string]: JsonObject;
161
+ }): JsonObject;
154
162
  /** Bundle a schema (spec/catalog.md#bundling). */
155
163
  export declare function bundle(schema: JsonObject, types: {
156
164
  readonly [name: string]: JsonObject;
package/dist/index.js CHANGED
@@ -217,6 +217,27 @@ function typesUsedBy(schema, types) {
217
217
  collect(schema);
218
218
  return used;
219
219
  }
220
+ /**
221
+ * An input schema that is a union of object schemas, with `"type": "object"`, so that it is an object schema
222
+ * (spec/catalog.md#capabilities). A union is `anyOf` or `oneOf`, directly or in the type that a `$ref` names. Each of
223
+ * its schemas is an object, or a `$ref` to a type that is an object. Other schemas do not change.
224
+ */
225
+ function objectInput(schema, types) {
226
+ const resolve = (node) => {
227
+ if (node === null || typeof node !== "object" || Array.isArray(node)) return void 0;
228
+ const object = node;
229
+ const name = typeof object.$ref === "string" ? REFERENCE.exec(object.$ref)?.[1] : void 0;
230
+ return name === void 0 ? object : types[name];
231
+ };
232
+ const target = resolve(schema);
233
+ if (schema.type !== void 0 || target === void 0 || target.type !== void 0) return schema;
234
+ const union = target.anyOf ?? target.oneOf;
235
+ if (!Array.isArray(union) || union.length === 0) return schema;
236
+ return union.every((member) => resolve(member)?.type === "object") ? {
237
+ type: "object",
238
+ ...schema
239
+ } : schema;
240
+ }
220
241
  /** Bundle a schema (spec/catalog.md#bundling). */
221
242
  function bundle(schema, types) {
222
243
  const only = Object.keys(schema).length === 1 ? REFERENCE.exec(String(schema.$ref))?.[1] : void 0;
@@ -246,4 +267,4 @@ function viewOf(catalog, target) {
246
267
  };
247
268
  }
248
269
  //#endregion
249
- 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, mcpToolResult, ok, readBounded, schemasOf, screenRequest, typesUsedBy, unavailable, viewOf, visitObjects };
270
+ 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, 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.0",
3
+ "version": "0.4.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",