@webpieces/core-util 0.4.806 → 0.4.807
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 +1 -1
- package/src/http/StreamingContract.d.ts +20 -10
- package/src/http/StreamingContract.js +23 -16
- package/src/http/StreamingContract.js.map +1 -1
- package/src/http/api-type.js +2 -2
- package/src/http/api-type.js.map +1 -1
- package/src/index.d.ts +5 -4
- package/src/index.js +9 -11
- package/src/index.js.map +1 -1
- package/src/mcp/DtoSchema.d.ts +72 -85
- package/src/mcp/DtoSchema.js +154 -345
- package/src/mcp/DtoSchema.js.map +1 -1
- package/src/mcp/McpCompileAssertions.js +22 -34
- package/src/mcp/McpCompileAssertions.js.map +1 -1
- package/src/mcp/McpMetadata.d.ts +23 -17
- package/src/mcp/McpMetadata.js +25 -15
- package/src/mcp/McpMetadata.js.map +1 -1
- package/src/mcp/McpToolCatalog.d.ts +83 -0
- package/src/mcp/McpToolCatalog.js +185 -0
- package/src/mcp/McpToolCatalog.js.map +1 -0
package/src/mcp/DtoSchema.d.ts
CHANGED
|
@@ -1,64 +1,31 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
export type DtoClass = abstract new (...args: any[]) => unknown;
|
|
3
|
-
/** The element type of an array or the value type of a map; TypeScript erases both at runtime. */
|
|
4
|
-
export type DtoElementType = 'string' | 'number' | 'integer' | 'boolean' | DtoClass;
|
|
5
|
-
/** Runtime values accepted at the DTO validation boundary. */
|
|
6
|
-
export type DtoValue = object | string | number | boolean | null;
|
|
7
|
-
/** Additive field metadata; the scalar/object type itself comes from `design:type`. */
|
|
8
|
-
export declare class WpDtoFieldOptions {
|
|
9
|
-
readonly description: string;
|
|
10
|
-
/** Required/optional is explicit because TypeScript erases `?` at runtime. */
|
|
11
|
-
readonly required: boolean;
|
|
12
|
-
/** Required for arrays because TypeScript erases their element type. */
|
|
13
|
-
readonly arrayItems?: DtoElementType | undefined;
|
|
14
|
-
/** A reflected Number is otherwise emitted as JSON Schema `number`. */
|
|
15
|
-
readonly integer: boolean;
|
|
16
|
-
readonly minimum?: number | undefined;
|
|
17
|
-
readonly maximum?: number | undefined;
|
|
18
|
-
readonly enumValues?: readonly [string, ...string[]] | undefined;
|
|
19
|
-
/** MCP 2026 SEP-2243 header mirrored as `Mcp-Param-{name}`. */
|
|
20
|
-
readonly mcpHeader?: WpMcpHeader | undefined;
|
|
21
|
-
constructor(description: string,
|
|
22
|
-
/** Required/optional is explicit because TypeScript erases `?` at runtime. */
|
|
23
|
-
required: boolean,
|
|
24
|
-
/** Required for arrays because TypeScript erases their element type. */
|
|
25
|
-
arrayItems?: DtoElementType | undefined,
|
|
26
|
-
/** A reflected Number is otherwise emitted as JSON Schema `number`. */
|
|
27
|
-
integer?: boolean, minimum?: number | undefined, maximum?: number | undefined, enumValues?: readonly [string, ...string[]] | undefined,
|
|
28
|
-
/** MCP 2026 SEP-2243 header mirrored as `Mcp-Param-{name}`. */
|
|
29
|
-
mcpHeader?: WpMcpHeader | undefined);
|
|
30
|
-
}
|
|
31
1
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
2
|
+
* The JSON Schema subset webpieces publishes on its API boundaries, and the ONE runtime validator of
|
|
3
|
+
* it.
|
|
4
|
+
*
|
|
5
|
+
* ## Nothing here reads reflect-metadata any more
|
|
6
|
+
*
|
|
7
|
+
* Until #984 this file also carried `@WpDto`, `@WpDtoField`, `WpDtoFieldOptions`,
|
|
8
|
+
* `WpDtoMapFieldOptions`, `WpMcpHeader`, `@WpResponseDto` and `DtoSchemaBuilder` — a second, runtime
|
|
9
|
+
* spelling of facts the TypeScript compiler already holds. #983 measured the two against each other
|
|
10
|
+
* and found the compiler reproduces every one of those arguments byte for byte, so they are deleted
|
|
11
|
+
* rather than deprecated (`.claude/rules/no-backwards-compat.md`): a schema is now BUILT at build
|
|
12
|
+
* time from the source by `@webpieces/api-doc-model`, and the runtime is HANDED the result.
|
|
13
|
+
*
|
|
14
|
+
* What survives is the schema itself, a builder for the boundaries that construct one by hand, and a
|
|
15
|
+
* validator that reads the schema instead of a decorator.
|
|
35
16
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
constructor(name: string);
|
|
39
|
-
}
|
|
17
|
+
/** Runtime values accepted at the DTO validation boundary. */
|
|
18
|
+
export type DtoValue = object | string | number | boolean | null;
|
|
40
19
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
20
|
+
* One JSON Schema `type`. `null` is a member because NULLABLE is expressed as `["string", "null"]`,
|
|
21
|
+
* which is how JSON Schema says "present, and may hold null" — a different wire document from an
|
|
22
|
+
* ABSENT property, and one the reflect-metadata runtime could neither see nor write down.
|
|
44
23
|
*/
|
|
45
|
-
export
|
|
46
|
-
readonly description: string;
|
|
47
|
-
/** Required/optional is explicit because TypeScript erases `?` at runtime. */
|
|
48
|
-
readonly required: boolean;
|
|
49
|
-
readonly mapValues: DtoElementType;
|
|
50
|
-
constructor(description: string,
|
|
51
|
-
/** Required/optional is explicit because TypeScript erases `?` at runtime. */
|
|
52
|
-
required: boolean, mapValues: DtoElementType);
|
|
53
|
-
}
|
|
54
|
-
export declare class WpDtoFieldMetadata {
|
|
55
|
-
readonly propertyKey: string;
|
|
56
|
-
readonly options: WpDtoFieldOptions | WpDtoMapFieldOptions;
|
|
57
|
-
constructor(propertyKey: string, options: WpDtoFieldOptions | WpDtoMapFieldOptions);
|
|
58
|
-
}
|
|
24
|
+
export type ApiJsonSchemaType = 'object' | 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'null';
|
|
59
25
|
/** The JSON Schema subset emitted for Webpieces API DTOs. */
|
|
60
26
|
export declare class ApiJsonSchema {
|
|
61
|
-
|
|
27
|
+
/** One type, or `[T, "null"]` for a nullable field. */
|
|
28
|
+
type?: ApiJsonSchemaType | readonly ApiJsonSchemaType[];
|
|
62
29
|
description?: string;
|
|
63
30
|
properties?: Record<string, ApiJsonSchema>;
|
|
64
31
|
required?: string[];
|
|
@@ -70,7 +37,42 @@ export declare class ApiJsonSchema {
|
|
|
70
37
|
maximum?: number;
|
|
71
38
|
/** MCP 2026 SEP-2243 schema extension consumed by the official SDK. */
|
|
72
39
|
'x-mcp-header'?: string;
|
|
73
|
-
constructor(type?:
|
|
40
|
+
constructor(type?: ApiJsonSchemaType | readonly ApiJsonSchemaType[]);
|
|
41
|
+
/**
|
|
42
|
+
* The non-`null` member of the type, which is the one that decides how a value is checked.
|
|
43
|
+
*
|
|
44
|
+
* These three are STATIC and not instance methods on purpose: an instance method would put a
|
|
45
|
+
* function on the structural type, and this class is handed straight to the MCP SDK, whose
|
|
46
|
+
* parameter types are index-signature JSON objects that a class carrying methods no longer
|
|
47
|
+
* satisfies. It stays a data-only structure (`CLAUDE.md` §1) and the helpers live beside it.
|
|
48
|
+
*/
|
|
49
|
+
static baseTypeOf(schema: ApiJsonSchema): ApiJsonSchemaType | undefined;
|
|
50
|
+
/** True when the schema was widened with `"null"`, i.e. the property may hold `null`. */
|
|
51
|
+
static allowsNull(schema: ApiJsonSchema): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The one closure gate for an object schema. Closed means no key can carry an unspecified value:
|
|
54
|
+
* either extra keys are forbidden (`additionalProperties: false`) or every extra key's value is
|
|
55
|
+
* typed (`additionalProperties: <schema>`, a typed map). A missing or `true` value is open.
|
|
56
|
+
* Use this instead of `schema.additionalProperties === false`, which rejects typed maps.
|
|
57
|
+
*/
|
|
58
|
+
static isClosed(schema: ApiJsonSchema): boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Builds the CLOSED object schema a hand-written runtime boundary validates against — `@WpStream`'s
|
|
62
|
+
* two event schemas are the whole of its client list today.
|
|
63
|
+
*
|
|
64
|
+
* It exists because the alternative spellings are both worse: a decorator that re-states the field
|
|
65
|
+
* types the compiler already knows is exactly what #984 deleted, and a bare object literal is what
|
|
66
|
+
* `CLAUDE.md` §3 forbids. A generated schema never comes through here — it is read from the build's
|
|
67
|
+
* own artifact.
|
|
68
|
+
*/
|
|
69
|
+
export declare class ObjectSchemaBuilder {
|
|
70
|
+
private readonly schema;
|
|
71
|
+
private readonly requiredNames;
|
|
72
|
+
constructor();
|
|
73
|
+
required(name: string, type: ApiJsonSchema): this;
|
|
74
|
+
optional(name: string, type: ApiJsonSchema): this;
|
|
75
|
+
build(): ApiJsonSchema;
|
|
74
76
|
}
|
|
75
77
|
/** A validation result safe to show to an API caller/model. */
|
|
76
78
|
export declare class DtoValidationFailure {
|
|
@@ -81,35 +83,20 @@ export declare class DtoValidationFailure {
|
|
|
81
83
|
/** JSON path of the offending value, e.g. `$.address.city`. */
|
|
82
84
|
field: string, message: string);
|
|
83
85
|
}
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
* The one closure gate for an object schema. Closed means no key can carry an unspecified value:
|
|
96
|
-
* either extra keys are forbidden (`additionalProperties: false`) or every extra key's value is
|
|
97
|
-
* typed (`additionalProperties: <schema>`, a typed map). A missing or `true` value is open.
|
|
98
|
-
* Use this instead of `schema.additionalProperties === false`, which rejects typed maps.
|
|
99
|
-
*/
|
|
100
|
-
isClosedSchema(schema: ApiJsonSchema): boolean;
|
|
101
|
-
build(dtoClass: DtoClass): ApiJsonSchema;
|
|
102
|
-
validate(dtoClass: DtoClass, value: DtoValue): DtoValidationFailure | undefined;
|
|
103
|
-
private buildAt;
|
|
104
|
-
private fieldSchema;
|
|
105
|
-
private validateOptions;
|
|
106
|
-
private itemSchema;
|
|
107
|
-
private validateMcpHeaders;
|
|
86
|
+
/**
|
|
87
|
+
* Validates a value against an {@link ApiJsonSchema} — the ONE runtime narrowing boundary for MCP
|
|
88
|
+
* tool arguments, MCP structured output and typed stream events.
|
|
89
|
+
*
|
|
90
|
+
* It reads the SCHEMA, which is the same object the build published to agents, so a document that
|
|
91
|
+
* says a field is required and a server that accepts it missing cannot disagree. The predecessor
|
|
92
|
+
* walked reflect-metadata instead, which meant the published document and the accepted request were
|
|
93
|
+
* derived from two different declarations.
|
|
94
|
+
*/
|
|
95
|
+
export declare class ApiJsonSchemaValidator {
|
|
96
|
+
validate(schema: ApiJsonSchema, value: DtoValue): DtoValidationFailure | undefined;
|
|
108
97
|
private validateAt;
|
|
109
|
-
private
|
|
98
|
+
private validateObject;
|
|
110
99
|
private validateArray;
|
|
111
|
-
private
|
|
112
|
-
private
|
|
113
|
-
private fields;
|
|
114
|
-
private requireDto;
|
|
100
|
+
private validateString;
|
|
101
|
+
private validateNumber;
|
|
115
102
|
}
|