@instruments/materialgraph 0.25.0 → 0.26.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/association-types.d.ts +20 -20
- package/associations-client.d.ts +4 -4
- package/associations-client.js +3 -10
- package/attribution-types.d.ts +3 -3
- package/brand-most-sampled-types.d.ts +4 -4
- package/brand-types.d.ts +6 -6
- package/brands-client.d.ts +4 -4
- package/brands-client.js +9 -13
- package/browse-types.d.ts +8 -8
- package/by-colour-types.d.ts +18 -18
- package/by-spec-types.d.ts +14 -14
- package/catalog-discovery-types.d.ts +14 -14
- package/catalogue-client.d.ts +4 -4
- package/catalogue-client.js +38 -37
- package/catalogue-types.d.ts +4 -4
- package/citation-types.d.ts +4 -4
- package/client-browse.d.ts +4 -4
- package/client-browse.js +24 -25
- package/client-config.d.ts +2 -2
- package/client-exploration.d.ts +3 -3
- package/client-exploration.js +4 -6
- package/client-source-material-comments.d.ts +4 -4
- package/client-source-material-comments.js +4 -38
- package/client-vocabulary.d.ts +8 -8
- package/client-vocabulary.js +20 -30
- package/client.d.ts +11 -45
- package/client.js +143 -188
- package/codes-client.d.ts +2 -2
- package/codes-client.js +8 -8
- package/codes-types.d.ts +34 -34
- package/colour-aggregate-types.d.ts +24 -24
- package/colours-client.d.ts +2 -2
- package/colours-client.js +15 -15
- package/compare-types.d.ts +10 -10
- package/composition-client.d.ts +3 -3
- package/composition-client.js +8 -7
- package/composition-types.d.ts +12 -12
- package/coordinate-client.d.ts +2 -2
- package/coordinate-client.js +1 -13
- package/corpus-scope-types.d.ts +3 -3
- package/corpus-scope-types.js +1 -25
- package/correction-types.d.ts +10 -10
- package/demand-batch-types.d.ts +18 -18
- package/demand-types.d.ts +24 -24
- package/errors.d.ts +12 -12
- package/errors.js +53 -52
- package/exploration-types.d.ts +22 -22
- package/fan-deck-types.d.ts +6 -6
- package/http-transport.d.ts +13 -21
- package/http-transport.js +31 -28
- package/identify-types.d.ts +10 -10
- package/index.d.ts +0 -6
- package/index.js +0 -2
- package/match-rejection-types.d.ts +6 -6
- package/match-stream-types.d.ts +32 -32
- package/match-stream.d.ts +2 -2
- package/match-stream.js +55 -41
- package/match-types.d.ts +8 -8
- package/material-asset-types.d.ts +26 -26
- package/material-block-types.d.ts +6 -6
- package/material-query-plan-types.d.ts +26 -26
- package/material-resources-client.d.ts +5 -5
- package/material-resources-client.js +10 -20
- package/material-types.d.ts +12 -12
- package/ndjson.js +16 -8
- package/operations.d.ts +6 -6
- package/operations.js +9 -39
- package/package.json +1 -1
- package/palette-completion-types.d.ts +22 -22
- package/palette-search-types.d.ts +28 -28
- package/query-understanding-types.d.ts +38 -35
- package/render-assets-types.d.ts +8 -8
- package/resolve-client.d.ts +2 -2
- package/resolve-client.js +4 -6
- package/resolve-colour-types.d.ts +8 -8
- package/resolve-types.d.ts +10 -10
- package/run-types.d.ts +70 -70
- package/runs.d.ts +13 -26
- package/runs.js +77 -89
- package/samplize-catalogue-types.d.ts +18 -18
- package/samplize-colorvec.d.ts +20 -20
- package/samplize-colorvec.js +66 -42
- package/schema-resource-types.d.ts +38 -38
- package/schema-resource-types.js +5 -5
- package/search-card-types.d.ts +4 -4
- package/search-collapse-types.d.ts +4 -4
- package/search-mood-types.d.ts +2 -2
- package/search-refinement-types.d.ts +8 -8
- package/search-request-types.d.ts +5 -5
- package/search-response-receipt-types.d.ts +58 -42
- package/search-response-types.d.ts +2 -2
- package/search-result-validation.d.ts +3 -3
- package/search-result-validation.js +53 -36
- package/search-window-types.d.ts +2 -2
- package/slot-pool-types.d.ts +20 -20
- package/source-material-validation.d.ts +3 -3
- package/source-material-validation.js +35 -39
- package/spec-facet-types.d.ts +10 -10
- package/spec-types.d.ts +6 -6
- package/specifications.d.ts +9 -25
- package/specifications.js +15 -21
- package/sse.d.ts +2 -2
- package/sse.js +32 -16
- package/substitute-types.d.ts +22 -22
- package/suggest-types.d.ts +7 -7
- package/suggest-types.js +3 -3
- package/taxonomy-coverage-types.d.ts +8 -8
- package/types.d.ts +119 -119
- package/validation.d.ts +26 -26
- package/validation.js +97 -92
- package/webmcp.d.ts +2 -2
- package/webmcp.generated.js +94 -93
- package/project-types.d.ts +0 -79
- package/project-types.js +0 -9
- package/projects.d.ts +0 -13
- package/projects.js +0 -46
- package/run-events.d.ts +0 -106
- package/run-events.js +0 -32
- package/schedule-reference-types.d.ts +0 -46
- package/schedule-reference-types.js +0 -1
- package/schedule-references-client.d.ts +0 -14
- package/schedule-references-client.js +0 -26
- package/schedule-types.d.ts +0 -261
- package/schedule-types.js +0 -1
package/validation.d.ts
CHANGED
|
@@ -14,26 +14,26 @@
|
|
|
14
14
|
* owned by the calling module — so one payload's failures all read alike without
|
|
15
15
|
* this file knowing what a Match frame or a Run event is.
|
|
16
16
|
*/
|
|
17
|
-
import { MaterialGraphError } from "./errors.js";
|
|
17
|
+
import type { MaterialGraphError } from "./errors.js";
|
|
18
18
|
import type { JsonValue } from "./types.js";
|
|
19
19
|
/**
|
|
20
20
|
* Builds the one error a validation run raises. The calling module supplies it,
|
|
21
21
|
* so the message names that payload and quotes its source.
|
|
22
22
|
*/
|
|
23
23
|
export type ValidationFailure = (reason: string) => MaterialGraphError;
|
|
24
|
-
export declare
|
|
24
|
+
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
25
25
|
/** A `z.object({…})`. */
|
|
26
|
-
export declare
|
|
26
|
+
export declare const requireRecord: (value: unknown, what: string, fail: ValidationFailure) => Record<string, unknown>;
|
|
27
27
|
/** A `z.string()`. */
|
|
28
|
-
export declare
|
|
28
|
+
export declare const requireString: (value: unknown, what: string, fail: ValidationFailure) => string;
|
|
29
29
|
/** A `z.string().min(1)`. */
|
|
30
|
-
export declare
|
|
30
|
+
export declare const requireNonEmptyString: (value: unknown, what: string, fail: ValidationFailure) => string;
|
|
31
31
|
/** A `z.string().optional()`: absent is fine, present-but-wrong is not. */
|
|
32
|
-
export declare
|
|
32
|
+
export declare const requireOptionalString: (value: unknown, what: string, fail: ValidationFailure) => void;
|
|
33
33
|
/** A `z.string().nullable()`. */
|
|
34
|
-
export declare
|
|
34
|
+
export declare const requireNullableString: (value: unknown, what: string, fail: ValidationFailure) => string | null;
|
|
35
35
|
/** A `z.string().min(1).nullable()`. */
|
|
36
|
-
export declare
|
|
36
|
+
export declare const requireNullableNonEmptyString: (value: unknown, what: string, fail: ValidationFailure) => string | null;
|
|
37
37
|
/**
|
|
38
38
|
* A `z.string().trim().min(1).max(max)`.
|
|
39
39
|
*
|
|
@@ -43,29 +43,29 @@ export declare function requireNullableNonEmptyString(value: unknown, what: stri
|
|
|
43
43
|
* whitespace-only value the schema rejects, and reject a padded value the schema
|
|
44
44
|
* accepts. Returns the trimmed string, which is what the schema returns.
|
|
45
45
|
*/
|
|
46
|
-
export declare
|
|
46
|
+
export declare const requireTrimmedBoundedString: (value: unknown, what: string, max: number, fail: ValidationFailure) => string;
|
|
47
47
|
/** A `z.string().trim().min(1).max(max).nullable()`. */
|
|
48
|
-
export declare
|
|
48
|
+
export declare const requireNullableTrimmedBoundedString: (value: unknown, what: string, max: number, fail: ValidationFailure) => string | null;
|
|
49
49
|
/** A `z.boolean()`. */
|
|
50
|
-
export declare
|
|
50
|
+
export declare const requireBoolean: (value: unknown, what: string, fail: ValidationFailure) => boolean;
|
|
51
51
|
/** A `z.boolean().optional()`. */
|
|
52
|
-
export declare
|
|
52
|
+
export declare const requireOptionalBoolean: (value: unknown, what: string, fail: ValidationFailure) => void;
|
|
53
53
|
/**
|
|
54
54
|
* A `z.number()`. Zod 4 rejects `NaN` AND `±Infinity` for it, and `1e999` parses
|
|
55
55
|
* out of JSON as `Infinity`, so finiteness is a reachable check.
|
|
56
56
|
*/
|
|
57
|
-
export declare
|
|
57
|
+
export declare const requireNumber: (value: unknown, what: string, fail: ValidationFailure) => number;
|
|
58
58
|
/** A `z.number().optional()`. */
|
|
59
|
-
export declare
|
|
59
|
+
export declare const requireOptionalNumber: (value: unknown, what: string, fail: ValidationFailure) => void;
|
|
60
60
|
/** A `z.number().nullable()`. */
|
|
61
|
-
export declare
|
|
61
|
+
export declare const requireNullableNumber: (value: unknown, what: string, fail: ValidationFailure) => number | null;
|
|
62
62
|
/**
|
|
63
63
|
* A `z.number().min(min).max(max)`. `NaN` and both infinities fail the
|
|
64
64
|
* comparisons, exactly as the bounded Zod schema rejects them.
|
|
65
65
|
*/
|
|
66
|
-
export declare
|
|
66
|
+
export declare const requireBoundedNumber: (value: unknown, what: string, fail: ValidationFailure, min: number, max: number) => number;
|
|
67
67
|
/** A `z.number().min(min).max(max).nullable()`. */
|
|
68
|
-
export declare
|
|
68
|
+
export declare const requireNullableBoundedNumber: (value: unknown, what: string, fail: ValidationFailure, min: number, max: number) => number | null;
|
|
69
69
|
/**
|
|
70
70
|
* A bare `z.number().int()` — integer, finite, and within the SAFE range, with
|
|
71
71
|
* NO lower bound.
|
|
@@ -80,22 +80,22 @@ export declare function requireNullableBoundedNumber(value: unknown, what: strin
|
|
|
80
80
|
* which the schema rejects — so `requireIntegerAtLeast` is not this helper with
|
|
81
81
|
* the bound dropped, and the safe-range test is why.
|
|
82
82
|
*/
|
|
83
|
-
export declare
|
|
83
|
+
export declare const requireSafeInteger: (value: unknown, what: string, fail: ValidationFailure) => number;
|
|
84
84
|
/** A `z.number().int().min(min)` — the integer constraint AND the lower bound. */
|
|
85
|
-
export declare
|
|
85
|
+
export declare const requireIntegerAtLeast: (value: unknown, what: string, fail: ValidationFailure, min: number) => number;
|
|
86
86
|
/** A `z.enum([…])` — CLOSED, exactly like the canonical member list. */
|
|
87
|
-
export declare
|
|
87
|
+
export declare const requireEnum: (value: unknown, allowed: readonly string[], what: string, fail: ValidationFailure) => string;
|
|
88
88
|
/** A `z.enum([…]).nullable()`. */
|
|
89
|
-
export declare
|
|
89
|
+
export declare const requireNullableEnum: (value: unknown, allowed: readonly string[], what: string, fail: ValidationFailure) => string | null;
|
|
90
90
|
/** A `z.array(…)`. */
|
|
91
|
-
export declare
|
|
91
|
+
export declare const requireArray: (value: unknown, what: string, fail: ValidationFailure) => unknown[];
|
|
92
92
|
/**
|
|
93
93
|
* A `z.array(…).default([])`: an OMITTED array is valid and materialises as
|
|
94
94
|
* `[]`; a present non-array is not.
|
|
95
95
|
*/
|
|
96
|
-
export declare
|
|
96
|
+
export declare const requireDefaultedArray: (value: unknown, what: string, fail: ValidationFailure) => unknown[];
|
|
97
97
|
/** A `z.array(z.string()).min(1)` — non-empty, and every element a string. */
|
|
98
|
-
export declare
|
|
98
|
+
export declare const requireNonEmptyStringArray: (value: unknown, what: string, fail: ValidationFailure) => string[];
|
|
99
99
|
/**
|
|
100
100
|
* A `z.json()` — a JSON value, recursively: `string | number | boolean | null`,
|
|
101
101
|
* an array of them, or an object of them, at ANY depth.
|
|
@@ -110,7 +110,7 @@ export declare function requireNonEmptyStringArray(value: unknown, what: string,
|
|
|
110
110
|
* back than written). The mirror has to reject what the schema rejects or the
|
|
111
111
|
* parity test is lying. Do not delete this as dead code.
|
|
112
112
|
*/
|
|
113
|
-
export declare
|
|
113
|
+
export declare const requireJsonValue: (value: unknown, what: string, fail: ValidationFailure) => JsonValue;
|
|
114
114
|
/**
|
|
115
115
|
* A `z.record(z.string(), z.json())` — a PLAIN JSON object of JSON values.
|
|
116
116
|
*
|
|
@@ -128,4 +128,4 @@ export declare function requireJsonValue(value: unknown, what: string, fail: Val
|
|
|
128
128
|
* genuinely does accept any record, and tightening a shared helper under them
|
|
129
129
|
* would be a change none of them asked for.
|
|
130
130
|
*/
|
|
131
|
-
export declare
|
|
131
|
+
export declare const requireJsonRecord: (value: unknown, what: string, fail: ValidationFailure) => Record<string, JsonValue>;
|
package/validation.js
CHANGED
|
@@ -1,60 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
* The SDK's shared wire-validation primitives — the vocabulary every hand-rolled
|
|
3
|
-
* mirror of a canonical Zod schema is built from.
|
|
4
|
-
*
|
|
5
|
-
* The SDK publishes with ZERO runtime dependencies, so it cannot call
|
|
6
|
-
* `schema.parse()` on anything. Where a wire payload must be proven rather than
|
|
7
|
-
* trusted, it is checked with these helpers and the result is pinned against the
|
|
8
|
-
* real schema in `contract-parity.test.ts`. Each helper mirrors one Zod
|
|
9
|
-
* construct, named for it, so a reviewer can read the mirror against the schema
|
|
10
|
-
* line by line.
|
|
11
|
-
*
|
|
12
|
-
* Every helper takes the same three shapes: the value, a `what` path used in the
|
|
13
|
-
* diagnostic (`results[3].verdict.cells[0].state`), and a {@link ValidationFailure}
|
|
14
|
-
* owned by the calling module — so one payload's failures all read alike without
|
|
15
|
-
* this file knowing what a Match frame or a Run event is.
|
|
16
|
-
*/
|
|
17
|
-
import { MaterialGraphError } from "./errors.js";
|
|
18
|
-
export function isRecord(value) {
|
|
19
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
|
-
}
|
|
1
|
+
export const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
2
|
/** A `z.object({…})`. */
|
|
22
|
-
export
|
|
23
|
-
if (!isRecord(value))
|
|
3
|
+
export const requireRecord = (value, what, fail) => {
|
|
4
|
+
if (!isRecord(value)) {
|
|
24
5
|
throw fail(`${what} is not a JSON object`);
|
|
6
|
+
}
|
|
25
7
|
return value;
|
|
26
|
-
}
|
|
8
|
+
};
|
|
27
9
|
/** A `z.string()`. */
|
|
28
|
-
export
|
|
29
|
-
if (typeof value !== "string")
|
|
10
|
+
export const requireString = (value, what, fail) => {
|
|
11
|
+
if (typeof value !== "string") {
|
|
30
12
|
throw fail(`${what} is not a string`);
|
|
13
|
+
}
|
|
31
14
|
return value;
|
|
32
|
-
}
|
|
15
|
+
};
|
|
33
16
|
/** A `z.string().min(1)`. */
|
|
34
|
-
export
|
|
17
|
+
export const requireNonEmptyString = (value, what, fail) => {
|
|
35
18
|
const text = requireString(value, what, fail);
|
|
36
|
-
if (text.length === 0)
|
|
19
|
+
if (text.length === 0) {
|
|
37
20
|
throw fail(`${what} is an empty string`);
|
|
21
|
+
}
|
|
38
22
|
return text;
|
|
39
|
-
}
|
|
23
|
+
};
|
|
40
24
|
/** A `z.string().optional()`: absent is fine, present-but-wrong is not. */
|
|
41
|
-
export
|
|
42
|
-
if (value === undefined)
|
|
25
|
+
export const requireOptionalString = (value, what, fail) => {
|
|
26
|
+
if (value === undefined) {
|
|
43
27
|
return;
|
|
28
|
+
}
|
|
44
29
|
requireString(value, what, fail);
|
|
45
|
-
}
|
|
30
|
+
};
|
|
46
31
|
/** A `z.string().nullable()`. */
|
|
47
|
-
export
|
|
48
|
-
if (value === null)
|
|
32
|
+
export const requireNullableString = (value, what, fail) => {
|
|
33
|
+
if (value === null) {
|
|
49
34
|
return null;
|
|
35
|
+
}
|
|
50
36
|
return requireString(value, what, fail);
|
|
51
|
-
}
|
|
37
|
+
};
|
|
52
38
|
/** A `z.string().min(1).nullable()`. */
|
|
53
|
-
export
|
|
54
|
-
if (value === null)
|
|
39
|
+
export const requireNullableNonEmptyString = (value, what, fail) => {
|
|
40
|
+
if (value === null) {
|
|
55
41
|
return null;
|
|
42
|
+
}
|
|
56
43
|
return requireNonEmptyString(value, what, fail);
|
|
57
|
-
}
|
|
44
|
+
};
|
|
58
45
|
/**
|
|
59
46
|
* A `z.string().trim().min(1).max(max)`.
|
|
60
47
|
*
|
|
@@ -64,70 +51,78 @@ export function requireNullableNonEmptyString(value, what, fail) {
|
|
|
64
51
|
* whitespace-only value the schema rejects, and reject a padded value the schema
|
|
65
52
|
* accepts. Returns the trimmed string, which is what the schema returns.
|
|
66
53
|
*/
|
|
67
|
-
export
|
|
54
|
+
export const requireTrimmedBoundedString = (value, what, max, fail) => {
|
|
68
55
|
const text = requireString(value, what, fail).trim();
|
|
69
|
-
if (text.length === 0)
|
|
56
|
+
if (text.length === 0) {
|
|
70
57
|
throw fail(`${what} is empty once trimmed`);
|
|
71
|
-
|
|
58
|
+
}
|
|
59
|
+
if (text.length > max) {
|
|
72
60
|
throw fail(`${what} is longer than ${max} characters (${text.length})`);
|
|
61
|
+
}
|
|
73
62
|
return text;
|
|
74
|
-
}
|
|
63
|
+
};
|
|
75
64
|
/** A `z.string().trim().min(1).max(max).nullable()`. */
|
|
76
|
-
export
|
|
77
|
-
if (value === null)
|
|
65
|
+
export const requireNullableTrimmedBoundedString = (value, what, max, fail) => {
|
|
66
|
+
if (value === null) {
|
|
78
67
|
return null;
|
|
68
|
+
}
|
|
79
69
|
return requireTrimmedBoundedString(value, what, max, fail);
|
|
80
|
-
}
|
|
70
|
+
};
|
|
81
71
|
/** A `z.boolean()`. */
|
|
82
|
-
export
|
|
83
|
-
if (typeof value !== "boolean")
|
|
72
|
+
export const requireBoolean = (value, what, fail) => {
|
|
73
|
+
if (typeof value !== "boolean") {
|
|
84
74
|
throw fail(`${what} is not a boolean`);
|
|
75
|
+
}
|
|
85
76
|
return value;
|
|
86
|
-
}
|
|
77
|
+
};
|
|
87
78
|
/** A `z.boolean().optional()`. */
|
|
88
|
-
export
|
|
89
|
-
if (value === undefined)
|
|
79
|
+
export const requireOptionalBoolean = (value, what, fail) => {
|
|
80
|
+
if (value === undefined) {
|
|
90
81
|
return;
|
|
82
|
+
}
|
|
91
83
|
requireBoolean(value, what, fail);
|
|
92
|
-
}
|
|
84
|
+
};
|
|
93
85
|
/**
|
|
94
86
|
* A `z.number()`. Zod 4 rejects `NaN` AND `±Infinity` for it, and `1e999` parses
|
|
95
87
|
* out of JSON as `Infinity`, so finiteness is a reachable check.
|
|
96
88
|
*/
|
|
97
|
-
export
|
|
89
|
+
export const requireNumber = (value, what, fail) => {
|
|
98
90
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
99
91
|
throw fail(`${what} is not a finite number`);
|
|
100
92
|
}
|
|
101
93
|
return value;
|
|
102
|
-
}
|
|
94
|
+
};
|
|
103
95
|
/** A `z.number().optional()`. */
|
|
104
|
-
export
|
|
105
|
-
if (value === undefined)
|
|
96
|
+
export const requireOptionalNumber = (value, what, fail) => {
|
|
97
|
+
if (value === undefined) {
|
|
106
98
|
return;
|
|
99
|
+
}
|
|
107
100
|
requireNumber(value, what, fail);
|
|
108
|
-
}
|
|
101
|
+
};
|
|
109
102
|
/** A `z.number().nullable()`. */
|
|
110
|
-
export
|
|
111
|
-
if (value === null)
|
|
103
|
+
export const requireNullableNumber = (value, what, fail) => {
|
|
104
|
+
if (value === null) {
|
|
112
105
|
return null;
|
|
106
|
+
}
|
|
113
107
|
return requireNumber(value, what, fail);
|
|
114
|
-
}
|
|
108
|
+
};
|
|
115
109
|
/**
|
|
116
110
|
* A `z.number().min(min).max(max)`. `NaN` and both infinities fail the
|
|
117
111
|
* comparisons, exactly as the bounded Zod schema rejects them.
|
|
118
112
|
*/
|
|
119
|
-
export
|
|
113
|
+
export const requireBoundedNumber = (value, what, fail, min, max) => {
|
|
120
114
|
if (typeof value !== "number" || !(value >= min && value <= max)) {
|
|
121
115
|
throw fail(`${what} is not a number within [${min}, ${max}]`);
|
|
122
116
|
}
|
|
123
117
|
return value;
|
|
124
|
-
}
|
|
118
|
+
};
|
|
125
119
|
/** A `z.number().min(min).max(max).nullable()`. */
|
|
126
|
-
export
|
|
127
|
-
if (value === null)
|
|
120
|
+
export const requireNullableBoundedNumber = (value, what, fail, min, max) => {
|
|
121
|
+
if (value === null) {
|
|
128
122
|
return null;
|
|
123
|
+
}
|
|
129
124
|
return requireBoundedNumber(value, what, fail, min, max);
|
|
130
|
-
}
|
|
125
|
+
};
|
|
131
126
|
/**
|
|
132
127
|
* A bare `z.number().int()` — integer, finite, and within the SAFE range, with
|
|
133
128
|
* NO lower bound.
|
|
@@ -142,56 +137,63 @@ export function requireNullableBoundedNumber(value, what, fail, min, max) {
|
|
|
142
137
|
* which the schema rejects — so `requireIntegerAtLeast` is not this helper with
|
|
143
138
|
* the bound dropped, and the safe-range test is why.
|
|
144
139
|
*/
|
|
145
|
-
export
|
|
146
|
-
if (!Number.isSafeInteger(value))
|
|
140
|
+
export const requireSafeInteger = (value, what, fail) => {
|
|
141
|
+
if (!Number.isSafeInteger(value)) {
|
|
147
142
|
throw fail(`${what} is not a safe integer`);
|
|
143
|
+
}
|
|
148
144
|
return requireNumber(value, what, fail);
|
|
149
|
-
}
|
|
145
|
+
};
|
|
150
146
|
/** A `z.number().int().min(min)` — the integer constraint AND the lower bound. */
|
|
151
|
-
export
|
|
147
|
+
export const requireIntegerAtLeast = (value, what, fail, min) => {
|
|
152
148
|
const numeric = requireNumber(value, what, fail);
|
|
153
|
-
if (!Number.isInteger(numeric))
|
|
149
|
+
if (!Number.isInteger(numeric)) {
|
|
154
150
|
throw fail(`${what} is not an integer`);
|
|
155
|
-
|
|
151
|
+
}
|
|
152
|
+
if (numeric < min) {
|
|
156
153
|
throw fail(`${what} is below the minimum of ${min}`);
|
|
154
|
+
}
|
|
157
155
|
return numeric;
|
|
158
|
-
}
|
|
156
|
+
};
|
|
159
157
|
/** A `z.enum([…])` — CLOSED, exactly like the canonical member list. */
|
|
160
|
-
export
|
|
158
|
+
export const requireEnum = (value, allowed, what, fail) => {
|
|
161
159
|
const text = requireString(value, what, fail);
|
|
162
160
|
if (!allowed.includes(text)) {
|
|
163
161
|
throw fail(`${what} is not one of ${allowed.join(" | ")} (${text})`);
|
|
164
162
|
}
|
|
165
163
|
return text;
|
|
166
|
-
}
|
|
164
|
+
};
|
|
167
165
|
/** A `z.enum([…]).nullable()`. */
|
|
168
|
-
export
|
|
169
|
-
if (value === null)
|
|
166
|
+
export const requireNullableEnum = (value, allowed, what, fail) => {
|
|
167
|
+
if (value === null) {
|
|
170
168
|
return null;
|
|
169
|
+
}
|
|
171
170
|
return requireEnum(value, allowed, what, fail);
|
|
172
|
-
}
|
|
171
|
+
};
|
|
173
172
|
/** A `z.array(…)`. */
|
|
174
|
-
export
|
|
175
|
-
if (!Array.isArray(value))
|
|
173
|
+
export const requireArray = (value, what, fail) => {
|
|
174
|
+
if (!Array.isArray(value)) {
|
|
176
175
|
throw fail(`${what} is not an array`);
|
|
176
|
+
}
|
|
177
177
|
return value;
|
|
178
|
-
}
|
|
178
|
+
};
|
|
179
179
|
/**
|
|
180
180
|
* A `z.array(…).default([])`: an OMITTED array is valid and materialises as
|
|
181
181
|
* `[]`; a present non-array is not.
|
|
182
182
|
*/
|
|
183
|
-
export
|
|
184
|
-
if (value === undefined)
|
|
183
|
+
export const requireDefaultedArray = (value, what, fail) => {
|
|
184
|
+
if (value === undefined) {
|
|
185
185
|
return [];
|
|
186
|
+
}
|
|
186
187
|
return requireArray(value, what, fail);
|
|
187
|
-
}
|
|
188
|
+
};
|
|
188
189
|
/** A `z.array(z.string()).min(1)` — non-empty, and every element a string. */
|
|
189
|
-
export
|
|
190
|
+
export const requireNonEmptyStringArray = (value, what, fail) => {
|
|
190
191
|
const items = requireArray(value, what, fail);
|
|
191
|
-
if (items.length === 0)
|
|
192
|
+
if (items.length === 0) {
|
|
192
193
|
throw fail(`${what} is empty`);
|
|
194
|
+
}
|
|
193
195
|
return items.map((item, index) => requireString(item, `${what}[${index}]`, fail));
|
|
194
|
-
}
|
|
196
|
+
};
|
|
195
197
|
/**
|
|
196
198
|
* A `z.json()` — a JSON value, recursively: `string | number | boolean | null`,
|
|
197
199
|
* an array of them, or an object of them, at ANY depth.
|
|
@@ -206,16 +208,19 @@ export function requireNonEmptyStringArray(value, what, fail) {
|
|
|
206
208
|
* back than written). The mirror has to reject what the schema rejects or the
|
|
207
209
|
* parity test is lying. Do not delete this as dead code.
|
|
208
210
|
*/
|
|
209
|
-
export
|
|
210
|
-
if (value === null)
|
|
211
|
+
export const requireJsonValue = (value, what, fail) => {
|
|
212
|
+
if (value === null) {
|
|
211
213
|
return null;
|
|
212
|
-
|
|
214
|
+
}
|
|
215
|
+
if (typeof value === "string" || typeof value === "boolean") {
|
|
213
216
|
return value;
|
|
217
|
+
}
|
|
214
218
|
if (typeof value === "number") {
|
|
215
219
|
// `z.json()`'s number leaf rejects NaN and ±Infinity, and `1e999` parses out
|
|
216
220
|
// of JSON as `Infinity` — so finiteness IS reachable, unlike the rest.
|
|
217
|
-
if (!Number.isFinite(value))
|
|
221
|
+
if (!Number.isFinite(value)) {
|
|
218
222
|
throw fail(`${what} is not a finite number`);
|
|
223
|
+
}
|
|
219
224
|
return value;
|
|
220
225
|
}
|
|
221
226
|
if (Array.isArray(value)) {
|
|
@@ -237,7 +242,7 @@ export function requireJsonValue(value, what, fail) {
|
|
|
237
242
|
]));
|
|
238
243
|
}
|
|
239
244
|
throw fail(`${what} is not a JSON value`);
|
|
240
|
-
}
|
|
245
|
+
};
|
|
241
246
|
/**
|
|
242
247
|
* A `z.record(z.string(), z.json())` — a PLAIN JSON object of JSON values.
|
|
243
248
|
*
|
|
@@ -255,10 +260,10 @@ export function requireJsonValue(value, what, fail) {
|
|
|
255
260
|
* genuinely does accept any record, and tightening a shared helper under them
|
|
256
261
|
* would be a change none of them asked for.
|
|
257
262
|
*/
|
|
258
|
-
export
|
|
263
|
+
export const requireJsonRecord = (value, what, fail) => {
|
|
259
264
|
const json = requireJsonValue(value, what, fail);
|
|
260
265
|
if (json === null || typeof json !== "object" || Array.isArray(json)) {
|
|
261
266
|
throw fail(`${what} is not a JSON object`);
|
|
262
267
|
}
|
|
263
268
|
return json;
|
|
264
|
-
}
|
|
269
|
+
};
|
package/webmcp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Canonical operation contracts. Consumers validate both boundaries and supply their own transport. */
|
|
2
|
-
export
|
|
2
|
+
export type WebMcpToolContract = {
|
|
3
3
|
readonly name: "identify" | "search" | "compare" | "create_correction";
|
|
4
4
|
readonly operationId: string;
|
|
5
5
|
readonly path: string;
|
|
@@ -13,5 +13,5 @@ export interface WebMcpToolContract {
|
|
|
13
13
|
};
|
|
14
14
|
readonly requiresVisibleConfirmation: boolean;
|
|
15
15
|
readonly requiredHeaders: readonly string[];
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
export { WEBMCP_TOOLS } from "./webmcp.generated.js";
|