@modelcontextprotocol/server 2.0.0-beta.1 → 2.0.0-beta.2

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.
Files changed (41) hide show
  1. package/dist/ajvProvider-D2kRT_qB.d.cts +1030 -0
  2. package/dist/ajvProvider-D2kRT_qB.d.cts.map +1 -0
  3. package/dist/ajvProvider-DhTNkgm1.cjs +7059 -0
  4. package/dist/ajvProvider-DhTNkgm1.cjs.map +1 -0
  5. package/dist/cfWorkerProvider-Djgwc46-.cjs +976 -0
  6. package/dist/cfWorkerProvider-Djgwc46-.cjs.map +1 -0
  7. package/dist/cfWorkerProvider-RncldJmy.d.cts +59 -0
  8. package/dist/cfWorkerProvider-RncldJmy.d.cts.map +1 -0
  9. package/dist/chunk-Bnu9O96Y.cjs +60 -0
  10. package/dist/createMcpHandler-Du3hjXvf.d.mts.map +1 -1
  11. package/dist/createMcpHandler-DyxapqGO.d.cts +11190 -0
  12. package/dist/createMcpHandler-DyxapqGO.d.cts.map +1 -0
  13. package/dist/index.cjs +1657 -0
  14. package/dist/index.cjs.map +1 -0
  15. package/dist/index.d.cts +1745 -0
  16. package/dist/index.d.cts.map +1 -0
  17. package/dist/index.mjs +3 -2
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/{mcp-JttQJlI9.mjs → mcp-C2tFGfLG.mjs} +18 -5
  20. package/dist/mcp-C2tFGfLG.mjs.map +1 -0
  21. package/dist/mcp-DVEehpM2.cjs +10545 -0
  22. package/dist/mcp-DVEehpM2.cjs.map +1 -0
  23. package/dist/shimsNode.cjs +12 -0
  24. package/dist/shimsNode.d.cts +3 -0
  25. package/dist/shimsWorkerd.cjs +23 -0
  26. package/dist/shimsWorkerd.cjs.map +1 -0
  27. package/dist/shimsWorkerd.d.cts +11 -0
  28. package/dist/shimsWorkerd.d.cts.map +1 -0
  29. package/dist/stdio.cjs +563 -0
  30. package/dist/stdio.cjs.map +1 -0
  31. package/dist/stdio.d.cts +107 -0
  32. package/dist/stdio.d.cts.map +1 -0
  33. package/dist/stdio.mjs +1 -1
  34. package/dist/types-Pc2fJzyM.d.cts +1099 -0
  35. package/dist/types-Pc2fJzyM.d.cts.map +1 -0
  36. package/dist/validators/ajv.cjs +10 -0
  37. package/dist/validators/ajv.d.cts +2 -0
  38. package/dist/validators/cfWorker.cjs +3 -0
  39. package/dist/validators/cfWorker.d.cts +2 -0
  40. package/package.json +68 -19
  41. package/dist/mcp-JttQJlI9.mjs.map +0 -1
@@ -0,0 +1,976 @@
1
+
2
+ //#region ../../node_modules/.pnpm/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js
3
+ function deepCompareStrict(a, b) {
4
+ const typeofa = typeof a;
5
+ if (typeofa !== typeof b) return false;
6
+ if (Array.isArray(a)) {
7
+ if (!Array.isArray(b)) return false;
8
+ const length = a.length;
9
+ if (length !== b.length) return false;
10
+ for (let i = 0; i < length; i++) if (!deepCompareStrict(a[i], b[i])) return false;
11
+ return true;
12
+ }
13
+ if (typeofa === "object") {
14
+ if (!a || !b) return a === b;
15
+ const aKeys = Object.keys(a);
16
+ const bKeys = Object.keys(b);
17
+ if (aKeys.length !== bKeys.length) return false;
18
+ for (const k of aKeys) if (!deepCompareStrict(a[k], b[k])) return false;
19
+ return true;
20
+ }
21
+ return a === b;
22
+ }
23
+
24
+ //#endregion
25
+ //#region ../../node_modules/.pnpm/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/pointer.js
26
+ function encodePointer(p) {
27
+ return encodeURI(escapePointer(p));
28
+ }
29
+ function escapePointer(p) {
30
+ return p.replace(/~/g, "~0").replace(/\//g, "~1");
31
+ }
32
+
33
+ //#endregion
34
+ //#region ../../node_modules/.pnpm/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/dereference.js
35
+ const schemaArrayKeyword = {
36
+ prefixItems: true,
37
+ items: true,
38
+ allOf: true,
39
+ anyOf: true,
40
+ oneOf: true
41
+ };
42
+ const schemaMapKeyword = {
43
+ $defs: true,
44
+ definitions: true,
45
+ properties: true,
46
+ patternProperties: true,
47
+ dependentSchemas: true
48
+ };
49
+ const ignoredKeyword = {
50
+ id: true,
51
+ $id: true,
52
+ $ref: true,
53
+ $schema: true,
54
+ $anchor: true,
55
+ $vocabulary: true,
56
+ $comment: true,
57
+ default: true,
58
+ enum: true,
59
+ const: true,
60
+ required: true,
61
+ type: true,
62
+ maximum: true,
63
+ minimum: true,
64
+ exclusiveMaximum: true,
65
+ exclusiveMinimum: true,
66
+ multipleOf: true,
67
+ maxLength: true,
68
+ minLength: true,
69
+ pattern: true,
70
+ format: true,
71
+ maxItems: true,
72
+ minItems: true,
73
+ uniqueItems: true,
74
+ maxProperties: true,
75
+ minProperties: true
76
+ };
77
+ let initialBaseURI = typeof self !== "undefined" && self.location && self.location.origin !== "null" ? new URL(self.location.origin + self.location.pathname + location.search) : new URL("https://github.com/cfworker");
78
+ function dereference(schema, lookup = Object.create(null), baseURI = initialBaseURI, basePointer = "") {
79
+ if (schema && typeof schema === "object" && !Array.isArray(schema)) {
80
+ const id = schema.$id || schema.id;
81
+ if (id) {
82
+ const url = new URL(id, baseURI.href);
83
+ if (url.hash.length > 1) lookup[url.href] = schema;
84
+ else {
85
+ url.hash = "";
86
+ if (basePointer === "") baseURI = url;
87
+ else dereference(schema, lookup, baseURI);
88
+ }
89
+ }
90
+ } else if (schema !== true && schema !== false) return lookup;
91
+ const schemaURI = baseURI.href + (basePointer ? "#" + basePointer : "");
92
+ if (lookup[schemaURI] !== void 0) throw new Error(`Duplicate schema URI "${schemaURI}".`);
93
+ lookup[schemaURI] = schema;
94
+ if (schema === true || schema === false) return lookup;
95
+ if (schema.__absolute_uri__ === void 0) Object.defineProperty(schema, "__absolute_uri__", {
96
+ enumerable: false,
97
+ value: schemaURI
98
+ });
99
+ if (schema.$ref && schema.__absolute_ref__ === void 0) {
100
+ const url = new URL(schema.$ref, baseURI.href);
101
+ url.hash = url.hash;
102
+ Object.defineProperty(schema, "__absolute_ref__", {
103
+ enumerable: false,
104
+ value: url.href
105
+ });
106
+ }
107
+ if (schema.$recursiveRef && schema.__absolute_recursive_ref__ === void 0) {
108
+ const url = new URL(schema.$recursiveRef, baseURI.href);
109
+ url.hash = url.hash;
110
+ Object.defineProperty(schema, "__absolute_recursive_ref__", {
111
+ enumerable: false,
112
+ value: url.href
113
+ });
114
+ }
115
+ if (schema.$anchor) {
116
+ const url = new URL("#" + schema.$anchor, baseURI.href);
117
+ lookup[url.href] = schema;
118
+ }
119
+ for (let key in schema) {
120
+ if (ignoredKeyword[key]) continue;
121
+ const keyBase = `${basePointer}/${encodePointer(key)}`;
122
+ const subSchema = schema[key];
123
+ if (Array.isArray(subSchema)) {
124
+ if (schemaArrayKeyword[key]) {
125
+ const length = subSchema.length;
126
+ for (let i = 0; i < length; i++) dereference(subSchema[i], lookup, baseURI, `${keyBase}/${i}`);
127
+ }
128
+ } else if (schemaMapKeyword[key]) for (let subKey in subSchema) dereference(subSchema[subKey], lookup, baseURI, `${keyBase}/${encodePointer(subKey)}`);
129
+ else dereference(subSchema, lookup, baseURI, keyBase);
130
+ }
131
+ return lookup;
132
+ }
133
+
134
+ //#endregion
135
+ //#region ../../node_modules/.pnpm/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/format.js
136
+ const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
137
+ const DAYS = [
138
+ 0,
139
+ 31,
140
+ 28,
141
+ 31,
142
+ 30,
143
+ 31,
144
+ 30,
145
+ 31,
146
+ 31,
147
+ 30,
148
+ 31,
149
+ 30,
150
+ 31
151
+ ];
152
+ const TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
153
+ const HOSTNAME = /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;
154
+ const URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
155
+ const URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
156
+ const URL_ = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
157
+ const UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
158
+ const JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
159
+ const JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
160
+ const RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
161
+ const EMAIL = (input) => {
162
+ if (input[0] === "\"") return false;
163
+ const [name, host, ...rest] = input.split("@");
164
+ if (!name || !host || rest.length !== 0 || name.length > 64 || host.length > 253) return false;
165
+ if (name[0] === "." || name.endsWith(".") || name.includes("..")) return false;
166
+ if (!/^[a-z0-9.-]+$/i.test(host) || !/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(name)) return false;
167
+ return host.split(".").every((part) => /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(part));
168
+ };
169
+ const IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
170
+ const IPV6 = /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i;
171
+ const DURATION = (input) => input.length > 1 && input.length < 80 && (/^P\d+([.,]\d+)?W$/.test(input) || /^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(input) && /^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(input));
172
+ function bind(r) {
173
+ return r.test.bind(r);
174
+ }
175
+ const format = {
176
+ date,
177
+ time: time.bind(void 0, false),
178
+ "date-time": date_time,
179
+ duration: DURATION,
180
+ uri,
181
+ "uri-reference": bind(URIREF),
182
+ "uri-template": bind(URITEMPLATE),
183
+ url: bind(URL_),
184
+ email: EMAIL,
185
+ hostname: bind(HOSTNAME),
186
+ ipv4: bind(IPV4),
187
+ ipv6: bind(IPV6),
188
+ regex,
189
+ uuid: bind(UUID),
190
+ "json-pointer": bind(JSON_POINTER),
191
+ "json-pointer-uri-fragment": bind(JSON_POINTER_URI_FRAGMENT),
192
+ "relative-json-pointer": bind(RELATIVE_JSON_POINTER)
193
+ };
194
+ function isLeapYear(year) {
195
+ return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
196
+ }
197
+ function date(str) {
198
+ const matches = str.match(DATE);
199
+ if (!matches) return false;
200
+ const year = +matches[1];
201
+ const month = +matches[2];
202
+ const day = +matches[3];
203
+ return month >= 1 && month <= 12 && day >= 1 && day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]);
204
+ }
205
+ function time(full, str) {
206
+ const matches = str.match(TIME);
207
+ if (!matches) return false;
208
+ const hour = +matches[1];
209
+ const minute = +matches[2];
210
+ const second = +matches[3];
211
+ const timeZone = !!matches[5];
212
+ return (hour <= 23 && minute <= 59 && second <= 59 || hour == 23 && minute == 59 && second == 60) && (!full || timeZone);
213
+ }
214
+ const DATE_TIME_SEPARATOR = /t|\s/i;
215
+ function date_time(str) {
216
+ const dateTime = str.split(DATE_TIME_SEPARATOR);
217
+ return dateTime.length == 2 && date(dateTime[0]) && time(true, dateTime[1]);
218
+ }
219
+ const NOT_URI_FRAGMENT = /\/|:/;
220
+ const URI_PATTERN = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
221
+ function uri(str) {
222
+ return NOT_URI_FRAGMENT.test(str) && URI_PATTERN.test(str);
223
+ }
224
+ const Z_ANCHOR = /[^\\]\\Z/;
225
+ function regex(str) {
226
+ if (Z_ANCHOR.test(str)) return false;
227
+ try {
228
+ new RegExp(str, "u");
229
+ return true;
230
+ } catch (e) {
231
+ return false;
232
+ }
233
+ }
234
+
235
+ //#endregion
236
+ //#region ../../node_modules/.pnpm/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/ucs2-length.js
237
+ function ucs2length(s) {
238
+ let result = 0;
239
+ let length = s.length;
240
+ let index = 0;
241
+ let charCode;
242
+ while (index < length) {
243
+ result++;
244
+ charCode = s.charCodeAt(index++);
245
+ if (charCode >= 55296 && charCode <= 56319 && index < length) {
246
+ charCode = s.charCodeAt(index);
247
+ if ((charCode & 64512) == 56320) index++;
248
+ }
249
+ }
250
+ return result;
251
+ }
252
+
253
+ //#endregion
254
+ //#region ../../node_modules/.pnpm/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/validate.js
255
+ function validate(instance, schema, draft = "2019-09", lookup = dereference(schema), shortCircuit = true, recursiveAnchor = null, instanceLocation = "#", schemaLocation = "#", evaluated = Object.create(null)) {
256
+ if (schema === true) return {
257
+ valid: true,
258
+ errors: []
259
+ };
260
+ if (schema === false) return {
261
+ valid: false,
262
+ errors: [{
263
+ instanceLocation,
264
+ keyword: "false",
265
+ keywordLocation: instanceLocation,
266
+ error: "False boolean schema."
267
+ }]
268
+ };
269
+ const rawInstanceType = typeof instance;
270
+ let instanceType;
271
+ switch (rawInstanceType) {
272
+ case "boolean":
273
+ case "number":
274
+ case "string":
275
+ instanceType = rawInstanceType;
276
+ break;
277
+ case "object":
278
+ if (instance === null) instanceType = "null";
279
+ else if (Array.isArray(instance)) instanceType = "array";
280
+ else instanceType = "object";
281
+ break;
282
+ default: throw new Error(`Instances of "${rawInstanceType}" type are not supported.`);
283
+ }
284
+ const { $ref, $recursiveRef, $recursiveAnchor, type: $type, const: $const, enum: $enum, required: $required, not: $not, anyOf: $anyOf, allOf: $allOf, oneOf: $oneOf, if: $if, then: $then, else: $else, format: $format, properties: $properties, patternProperties: $patternProperties, additionalProperties: $additionalProperties, unevaluatedProperties: $unevaluatedProperties, minProperties: $minProperties, maxProperties: $maxProperties, propertyNames: $propertyNames, dependentRequired: $dependentRequired, dependentSchemas: $dependentSchemas, dependencies: $dependencies, prefixItems: $prefixItems, items: $items, additionalItems: $additionalItems, unevaluatedItems: $unevaluatedItems, contains: $contains, minContains: $minContains, maxContains: $maxContains, minItems: $minItems, maxItems: $maxItems, uniqueItems: $uniqueItems, minimum: $minimum, maximum: $maximum, exclusiveMinimum: $exclusiveMinimum, exclusiveMaximum: $exclusiveMaximum, multipleOf: $multipleOf, minLength: $minLength, maxLength: $maxLength, pattern: $pattern, __absolute_ref__, __absolute_recursive_ref__ } = schema;
285
+ const errors = [];
286
+ if ($recursiveAnchor === true && recursiveAnchor === null) recursiveAnchor = schema;
287
+ if ($recursiveRef === "#") {
288
+ const refSchema = recursiveAnchor === null ? lookup[__absolute_recursive_ref__] : recursiveAnchor;
289
+ const keywordLocation = `${schemaLocation}/$recursiveRef`;
290
+ const result = validate(instance, recursiveAnchor === null ? schema : recursiveAnchor, draft, lookup, shortCircuit, refSchema, instanceLocation, keywordLocation, evaluated);
291
+ if (!result.valid) errors.push({
292
+ instanceLocation,
293
+ keyword: "$recursiveRef",
294
+ keywordLocation,
295
+ error: "A subschema had errors."
296
+ }, ...result.errors);
297
+ }
298
+ if ($ref !== void 0) {
299
+ const refSchema = lookup[__absolute_ref__ || $ref];
300
+ if (refSchema === void 0) {
301
+ let message = `Unresolved $ref "${$ref}".`;
302
+ if (__absolute_ref__ && __absolute_ref__ !== $ref) message += ` Absolute URI "${__absolute_ref__}".`;
303
+ message += `\nKnown schemas:\n- ${Object.keys(lookup).join("\n- ")}`;
304
+ throw new Error(message);
305
+ }
306
+ const keywordLocation = `${schemaLocation}/$ref`;
307
+ const result = validate(instance, refSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated);
308
+ if (!result.valid) errors.push({
309
+ instanceLocation,
310
+ keyword: "$ref",
311
+ keywordLocation,
312
+ error: "A subschema had errors."
313
+ }, ...result.errors);
314
+ if (draft === "4" || draft === "7") return {
315
+ valid: errors.length === 0,
316
+ errors
317
+ };
318
+ }
319
+ if (Array.isArray($type)) {
320
+ let length = $type.length;
321
+ let valid = false;
322
+ for (let i = 0; i < length; i++) if (instanceType === $type[i] || $type[i] === "integer" && instanceType === "number" && instance % 1 === 0 && instance === instance) {
323
+ valid = true;
324
+ break;
325
+ }
326
+ if (!valid) errors.push({
327
+ instanceLocation,
328
+ keyword: "type",
329
+ keywordLocation: `${schemaLocation}/type`,
330
+ error: `Instance type "${instanceType}" is invalid. Expected "${$type.join("\", \"")}".`
331
+ });
332
+ } else if ($type === "integer") {
333
+ if (instanceType !== "number" || instance % 1 || instance !== instance) errors.push({
334
+ instanceLocation,
335
+ keyword: "type",
336
+ keywordLocation: `${schemaLocation}/type`,
337
+ error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`
338
+ });
339
+ } else if ($type !== void 0 && instanceType !== $type) errors.push({
340
+ instanceLocation,
341
+ keyword: "type",
342
+ keywordLocation: `${schemaLocation}/type`,
343
+ error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`
344
+ });
345
+ if ($const !== void 0) {
346
+ if (instanceType === "object" || instanceType === "array") {
347
+ if (!deepCompareStrict(instance, $const)) errors.push({
348
+ instanceLocation,
349
+ keyword: "const",
350
+ keywordLocation: `${schemaLocation}/const`,
351
+ error: `Instance does not match ${JSON.stringify($const)}.`
352
+ });
353
+ } else if (instance !== $const) errors.push({
354
+ instanceLocation,
355
+ keyword: "const",
356
+ keywordLocation: `${schemaLocation}/const`,
357
+ error: `Instance does not match ${JSON.stringify($const)}.`
358
+ });
359
+ }
360
+ if ($enum !== void 0) {
361
+ if (instanceType === "object" || instanceType === "array") {
362
+ if (!$enum.some((value) => deepCompareStrict(instance, value))) errors.push({
363
+ instanceLocation,
364
+ keyword: "enum",
365
+ keywordLocation: `${schemaLocation}/enum`,
366
+ error: `Instance does not match any of ${JSON.stringify($enum)}.`
367
+ });
368
+ } else if (!$enum.some((value) => instance === value)) errors.push({
369
+ instanceLocation,
370
+ keyword: "enum",
371
+ keywordLocation: `${schemaLocation}/enum`,
372
+ error: `Instance does not match any of ${JSON.stringify($enum)}.`
373
+ });
374
+ }
375
+ if ($not !== void 0) {
376
+ const keywordLocation = `${schemaLocation}/not`;
377
+ if (validate(instance, $not, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation).valid) errors.push({
378
+ instanceLocation,
379
+ keyword: "not",
380
+ keywordLocation,
381
+ error: "Instance matched \"not\" schema."
382
+ });
383
+ }
384
+ let subEvaluateds = [];
385
+ if ($anyOf !== void 0) {
386
+ const keywordLocation = `${schemaLocation}/anyOf`;
387
+ const errorsLength = errors.length;
388
+ let anyValid = false;
389
+ for (let i = 0; i < $anyOf.length; i++) {
390
+ const subSchema = $anyOf[i];
391
+ const subEvaluated = Object.create(evaluated);
392
+ const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
393
+ errors.push(...result.errors);
394
+ anyValid = anyValid || result.valid;
395
+ if (result.valid) subEvaluateds.push(subEvaluated);
396
+ }
397
+ if (anyValid) errors.length = errorsLength;
398
+ else errors.splice(errorsLength, 0, {
399
+ instanceLocation,
400
+ keyword: "anyOf",
401
+ keywordLocation,
402
+ error: "Instance does not match any subschemas."
403
+ });
404
+ }
405
+ if ($allOf !== void 0) {
406
+ const keywordLocation = `${schemaLocation}/allOf`;
407
+ const errorsLength = errors.length;
408
+ let allValid = true;
409
+ for (let i = 0; i < $allOf.length; i++) {
410
+ const subSchema = $allOf[i];
411
+ const subEvaluated = Object.create(evaluated);
412
+ const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
413
+ errors.push(...result.errors);
414
+ allValid = allValid && result.valid;
415
+ if (result.valid) subEvaluateds.push(subEvaluated);
416
+ }
417
+ if (allValid) errors.length = errorsLength;
418
+ else errors.splice(errorsLength, 0, {
419
+ instanceLocation,
420
+ keyword: "allOf",
421
+ keywordLocation,
422
+ error: `Instance does not match every subschema.`
423
+ });
424
+ }
425
+ if ($oneOf !== void 0) {
426
+ const keywordLocation = `${schemaLocation}/oneOf`;
427
+ const errorsLength = errors.length;
428
+ const matches = $oneOf.filter((subSchema, i) => {
429
+ const subEvaluated = Object.create(evaluated);
430
+ const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
431
+ errors.push(...result.errors);
432
+ if (result.valid) subEvaluateds.push(subEvaluated);
433
+ return result.valid;
434
+ }).length;
435
+ if (matches === 1) errors.length = errorsLength;
436
+ else errors.splice(errorsLength, 0, {
437
+ instanceLocation,
438
+ keyword: "oneOf",
439
+ keywordLocation,
440
+ error: `Instance does not match exactly one subschema (${matches} matches).`
441
+ });
442
+ }
443
+ if (instanceType === "object" || instanceType === "array") Object.assign(evaluated, ...subEvaluateds);
444
+ if ($if !== void 0) {
445
+ const keywordLocation = `${schemaLocation}/if`;
446
+ if (validate(instance, $if, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated).valid) {
447
+ if ($then !== void 0) {
448
+ const thenResult = validate(instance, $then, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/then`, evaluated);
449
+ if (!thenResult.valid) errors.push({
450
+ instanceLocation,
451
+ keyword: "if",
452
+ keywordLocation,
453
+ error: `Instance does not match "then" schema.`
454
+ }, ...thenResult.errors);
455
+ }
456
+ } else if ($else !== void 0) {
457
+ const elseResult = validate(instance, $else, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/else`, evaluated);
458
+ if (!elseResult.valid) errors.push({
459
+ instanceLocation,
460
+ keyword: "if",
461
+ keywordLocation,
462
+ error: `Instance does not match "else" schema.`
463
+ }, ...elseResult.errors);
464
+ }
465
+ }
466
+ if (instanceType === "object") {
467
+ if ($required !== void 0) {
468
+ for (const key of $required) if (!(key in instance)) errors.push({
469
+ instanceLocation,
470
+ keyword: "required",
471
+ keywordLocation: `${schemaLocation}/required`,
472
+ error: `Instance does not have required property "${key}".`
473
+ });
474
+ }
475
+ const keys = Object.keys(instance);
476
+ if ($minProperties !== void 0 && keys.length < $minProperties) errors.push({
477
+ instanceLocation,
478
+ keyword: "minProperties",
479
+ keywordLocation: `${schemaLocation}/minProperties`,
480
+ error: `Instance does not have at least ${$minProperties} properties.`
481
+ });
482
+ if ($maxProperties !== void 0 && keys.length > $maxProperties) errors.push({
483
+ instanceLocation,
484
+ keyword: "maxProperties",
485
+ keywordLocation: `${schemaLocation}/maxProperties`,
486
+ error: `Instance does not have at least ${$maxProperties} properties.`
487
+ });
488
+ if ($propertyNames !== void 0) {
489
+ const keywordLocation = `${schemaLocation}/propertyNames`;
490
+ for (const key in instance) {
491
+ const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
492
+ const result = validate(key, $propertyNames, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
493
+ if (!result.valid) errors.push({
494
+ instanceLocation,
495
+ keyword: "propertyNames",
496
+ keywordLocation,
497
+ error: `Property name "${key}" does not match schema.`
498
+ }, ...result.errors);
499
+ }
500
+ }
501
+ if ($dependentRequired !== void 0) {
502
+ const keywordLocation = `${schemaLocation}/dependantRequired`;
503
+ for (const key in $dependentRequired) if (key in instance) {
504
+ const required = $dependentRequired[key];
505
+ for (const dependantKey of required) if (!(dependantKey in instance)) errors.push({
506
+ instanceLocation,
507
+ keyword: "dependentRequired",
508
+ keywordLocation,
509
+ error: `Instance has "${key}" but does not have "${dependantKey}".`
510
+ });
511
+ }
512
+ }
513
+ if ($dependentSchemas !== void 0) for (const key in $dependentSchemas) {
514
+ const keywordLocation = `${schemaLocation}/dependentSchemas`;
515
+ if (key in instance) {
516
+ const result = validate(instance, $dependentSchemas[key], draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`, evaluated);
517
+ if (!result.valid) errors.push({
518
+ instanceLocation,
519
+ keyword: "dependentSchemas",
520
+ keywordLocation,
521
+ error: `Instance has "${key}" but does not match dependant schema.`
522
+ }, ...result.errors);
523
+ }
524
+ }
525
+ if ($dependencies !== void 0) {
526
+ const keywordLocation = `${schemaLocation}/dependencies`;
527
+ for (const key in $dependencies) if (key in instance) {
528
+ const propsOrSchema = $dependencies[key];
529
+ if (Array.isArray(propsOrSchema)) {
530
+ for (const dependantKey of propsOrSchema) if (!(dependantKey in instance)) errors.push({
531
+ instanceLocation,
532
+ keyword: "dependencies",
533
+ keywordLocation,
534
+ error: `Instance has "${key}" but does not have "${dependantKey}".`
535
+ });
536
+ } else {
537
+ const result = validate(instance, propsOrSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`);
538
+ if (!result.valid) errors.push({
539
+ instanceLocation,
540
+ keyword: "dependencies",
541
+ keywordLocation,
542
+ error: `Instance has "${key}" but does not match dependant schema.`
543
+ }, ...result.errors);
544
+ }
545
+ }
546
+ }
547
+ const thisEvaluated = Object.create(null);
548
+ let stop = false;
549
+ if ($properties !== void 0) {
550
+ const keywordLocation = `${schemaLocation}/properties`;
551
+ for (const key in $properties) {
552
+ if (!(key in instance)) continue;
553
+ const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
554
+ const result = validate(instance[key], $properties[key], draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(key)}`);
555
+ if (result.valid) evaluated[key] = thisEvaluated[key] = true;
556
+ else {
557
+ stop = shortCircuit;
558
+ errors.push({
559
+ instanceLocation,
560
+ keyword: "properties",
561
+ keywordLocation,
562
+ error: `Property "${key}" does not match schema.`
563
+ }, ...result.errors);
564
+ if (stop) break;
565
+ }
566
+ }
567
+ }
568
+ if (!stop && $patternProperties !== void 0) {
569
+ const keywordLocation = `${schemaLocation}/patternProperties`;
570
+ for (const pattern in $patternProperties) {
571
+ const regex$1 = new RegExp(pattern, "u");
572
+ const subSchema = $patternProperties[pattern];
573
+ for (const key in instance) {
574
+ if (!regex$1.test(key)) continue;
575
+ const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
576
+ const result = validate(instance[key], subSchema, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(pattern)}`);
577
+ if (result.valid) evaluated[key] = thisEvaluated[key] = true;
578
+ else {
579
+ stop = shortCircuit;
580
+ errors.push({
581
+ instanceLocation,
582
+ keyword: "patternProperties",
583
+ keywordLocation,
584
+ error: `Property "${key}" matches pattern "${pattern}" but does not match associated schema.`
585
+ }, ...result.errors);
586
+ }
587
+ }
588
+ }
589
+ }
590
+ if (!stop && $additionalProperties !== void 0) {
591
+ const keywordLocation = `${schemaLocation}/additionalProperties`;
592
+ for (const key in instance) {
593
+ if (thisEvaluated[key]) continue;
594
+ const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
595
+ const result = validate(instance[key], $additionalProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
596
+ if (result.valid) evaluated[key] = true;
597
+ else {
598
+ stop = shortCircuit;
599
+ errors.push({
600
+ instanceLocation,
601
+ keyword: "additionalProperties",
602
+ keywordLocation,
603
+ error: `Property "${key}" does not match additional properties schema.`
604
+ }, ...result.errors);
605
+ }
606
+ }
607
+ } else if (!stop && $unevaluatedProperties !== void 0) {
608
+ const keywordLocation = `${schemaLocation}/unevaluatedProperties`;
609
+ for (const key in instance) if (!evaluated[key]) {
610
+ const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
611
+ const result = validate(instance[key], $unevaluatedProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
612
+ if (result.valid) evaluated[key] = true;
613
+ else errors.push({
614
+ instanceLocation,
615
+ keyword: "unevaluatedProperties",
616
+ keywordLocation,
617
+ error: `Property "${key}" does not match unevaluated properties schema.`
618
+ }, ...result.errors);
619
+ }
620
+ }
621
+ } else if (instanceType === "array") {
622
+ if ($maxItems !== void 0 && instance.length > $maxItems) errors.push({
623
+ instanceLocation,
624
+ keyword: "maxItems",
625
+ keywordLocation: `${schemaLocation}/maxItems`,
626
+ error: `Array has too many items (${instance.length} > ${$maxItems}).`
627
+ });
628
+ if ($minItems !== void 0 && instance.length < $minItems) errors.push({
629
+ instanceLocation,
630
+ keyword: "minItems",
631
+ keywordLocation: `${schemaLocation}/minItems`,
632
+ error: `Array has too few items (${instance.length} < ${$minItems}).`
633
+ });
634
+ const length = instance.length;
635
+ let i = 0;
636
+ let stop = false;
637
+ if ($prefixItems !== void 0) {
638
+ const keywordLocation = `${schemaLocation}/prefixItems`;
639
+ const length2 = Math.min($prefixItems.length, length);
640
+ for (; i < length2; i++) {
641
+ const result = validate(instance[i], $prefixItems[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);
642
+ evaluated[i] = true;
643
+ if (!result.valid) {
644
+ stop = shortCircuit;
645
+ errors.push({
646
+ instanceLocation,
647
+ keyword: "prefixItems",
648
+ keywordLocation,
649
+ error: `Items did not match schema.`
650
+ }, ...result.errors);
651
+ if (stop) break;
652
+ }
653
+ }
654
+ }
655
+ if ($items !== void 0) {
656
+ const keywordLocation = `${schemaLocation}/items`;
657
+ if (Array.isArray($items)) {
658
+ const length2 = Math.min($items.length, length);
659
+ for (; i < length2; i++) {
660
+ const result = validate(instance[i], $items[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);
661
+ evaluated[i] = true;
662
+ if (!result.valid) {
663
+ stop = shortCircuit;
664
+ errors.push({
665
+ instanceLocation,
666
+ keyword: "items",
667
+ keywordLocation,
668
+ error: `Items did not match schema.`
669
+ }, ...result.errors);
670
+ if (stop) break;
671
+ }
672
+ }
673
+ } else for (; i < length; i++) {
674
+ const result = validate(instance[i], $items, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
675
+ evaluated[i] = true;
676
+ if (!result.valid) {
677
+ stop = shortCircuit;
678
+ errors.push({
679
+ instanceLocation,
680
+ keyword: "items",
681
+ keywordLocation,
682
+ error: `Items did not match schema.`
683
+ }, ...result.errors);
684
+ if (stop) break;
685
+ }
686
+ }
687
+ if (!stop && $additionalItems !== void 0) {
688
+ const keywordLocation$1 = `${schemaLocation}/additionalItems`;
689
+ for (; i < length; i++) {
690
+ const result = validate(instance[i], $additionalItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation$1);
691
+ evaluated[i] = true;
692
+ if (!result.valid) {
693
+ stop = shortCircuit;
694
+ errors.push({
695
+ instanceLocation,
696
+ keyword: "additionalItems",
697
+ keywordLocation: keywordLocation$1,
698
+ error: `Items did not match additional items schema.`
699
+ }, ...result.errors);
700
+ }
701
+ }
702
+ }
703
+ }
704
+ if ($contains !== void 0) if (length === 0 && $minContains === void 0) errors.push({
705
+ instanceLocation,
706
+ keyword: "contains",
707
+ keywordLocation: `${schemaLocation}/contains`,
708
+ error: `Array is empty. It must contain at least one item matching the schema.`
709
+ });
710
+ else if ($minContains !== void 0 && length < $minContains) errors.push({
711
+ instanceLocation,
712
+ keyword: "minContains",
713
+ keywordLocation: `${schemaLocation}/minContains`,
714
+ error: `Array has less items (${length}) than minContains (${$minContains}).`
715
+ });
716
+ else {
717
+ const keywordLocation = `${schemaLocation}/contains`;
718
+ const errorsLength = errors.length;
719
+ let contained = 0;
720
+ for (let j = 0; j < length; j++) {
721
+ const result = validate(instance[j], $contains, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${j}`, keywordLocation);
722
+ if (result.valid) {
723
+ evaluated[j] = true;
724
+ contained++;
725
+ } else errors.push(...result.errors);
726
+ }
727
+ if (contained >= ($minContains || 0)) errors.length = errorsLength;
728
+ if ($minContains === void 0 && $maxContains === void 0 && contained === 0) errors.splice(errorsLength, 0, {
729
+ instanceLocation,
730
+ keyword: "contains",
731
+ keywordLocation,
732
+ error: `Array does not contain item matching schema.`
733
+ });
734
+ else if ($minContains !== void 0 && contained < $minContains) errors.push({
735
+ instanceLocation,
736
+ keyword: "minContains",
737
+ keywordLocation: `${schemaLocation}/minContains`,
738
+ error: `Array must contain at least ${$minContains} items matching schema. Only ${contained} items were found.`
739
+ });
740
+ else if ($maxContains !== void 0 && contained > $maxContains) errors.push({
741
+ instanceLocation,
742
+ keyword: "maxContains",
743
+ keywordLocation: `${schemaLocation}/maxContains`,
744
+ error: `Array may contain at most ${$maxContains} items matching schema. ${contained} items were found.`
745
+ });
746
+ }
747
+ if (!stop && $unevaluatedItems !== void 0) {
748
+ const keywordLocation = `${schemaLocation}/unevaluatedItems`;
749
+ for (; i < length; i++) {
750
+ if (evaluated[i]) continue;
751
+ const result = validate(instance[i], $unevaluatedItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
752
+ evaluated[i] = true;
753
+ if (!result.valid) errors.push({
754
+ instanceLocation,
755
+ keyword: "unevaluatedItems",
756
+ keywordLocation,
757
+ error: `Items did not match unevaluated items schema.`
758
+ }, ...result.errors);
759
+ }
760
+ }
761
+ if ($uniqueItems) for (let j = 0; j < length; j++) {
762
+ const a = instance[j];
763
+ const ao = typeof a === "object" && a !== null;
764
+ for (let k = 0; k < length; k++) {
765
+ if (j === k) continue;
766
+ const b = instance[k];
767
+ if (a === b || ao && typeof b === "object" && b !== null && deepCompareStrict(a, b)) {
768
+ errors.push({
769
+ instanceLocation,
770
+ keyword: "uniqueItems",
771
+ keywordLocation: `${schemaLocation}/uniqueItems`,
772
+ error: `Duplicate items at indexes ${j} and ${k}.`
773
+ });
774
+ j = Number.MAX_SAFE_INTEGER;
775
+ k = Number.MAX_SAFE_INTEGER;
776
+ }
777
+ }
778
+ }
779
+ } else if (instanceType === "number") {
780
+ if (draft === "4") {
781
+ if ($minimum !== void 0 && ($exclusiveMinimum === true && instance <= $minimum || instance < $minimum)) errors.push({
782
+ instanceLocation,
783
+ keyword: "minimum",
784
+ keywordLocation: `${schemaLocation}/minimum`,
785
+ error: `${instance} is less than ${$exclusiveMinimum ? "or equal to " : ""} ${$minimum}.`
786
+ });
787
+ if ($maximum !== void 0 && ($exclusiveMaximum === true && instance >= $maximum || instance > $maximum)) errors.push({
788
+ instanceLocation,
789
+ keyword: "maximum",
790
+ keywordLocation: `${schemaLocation}/maximum`,
791
+ error: `${instance} is greater than ${$exclusiveMaximum ? "or equal to " : ""} ${$maximum}.`
792
+ });
793
+ } else {
794
+ if ($minimum !== void 0 && instance < $minimum) errors.push({
795
+ instanceLocation,
796
+ keyword: "minimum",
797
+ keywordLocation: `${schemaLocation}/minimum`,
798
+ error: `${instance} is less than ${$minimum}.`
799
+ });
800
+ if ($maximum !== void 0 && instance > $maximum) errors.push({
801
+ instanceLocation,
802
+ keyword: "maximum",
803
+ keywordLocation: `${schemaLocation}/maximum`,
804
+ error: `${instance} is greater than ${$maximum}.`
805
+ });
806
+ if ($exclusiveMinimum !== void 0 && instance <= $exclusiveMinimum) errors.push({
807
+ instanceLocation,
808
+ keyword: "exclusiveMinimum",
809
+ keywordLocation: `${schemaLocation}/exclusiveMinimum`,
810
+ error: `${instance} is less than ${$exclusiveMinimum}.`
811
+ });
812
+ if ($exclusiveMaximum !== void 0 && instance >= $exclusiveMaximum) errors.push({
813
+ instanceLocation,
814
+ keyword: "exclusiveMaximum",
815
+ keywordLocation: `${schemaLocation}/exclusiveMaximum`,
816
+ error: `${instance} is greater than or equal to ${$exclusiveMaximum}.`
817
+ });
818
+ }
819
+ if ($multipleOf !== void 0) {
820
+ const remainder = instance % $multipleOf;
821
+ if (Math.abs(0 - remainder) >= 1.1920929e-7 && Math.abs($multipleOf - remainder) >= 1.1920929e-7) errors.push({
822
+ instanceLocation,
823
+ keyword: "multipleOf",
824
+ keywordLocation: `${schemaLocation}/multipleOf`,
825
+ error: `${instance} is not a multiple of ${$multipleOf}.`
826
+ });
827
+ }
828
+ } else if (instanceType === "string") {
829
+ const length = $minLength === void 0 && $maxLength === void 0 ? 0 : ucs2length(instance);
830
+ if ($minLength !== void 0 && length < $minLength) errors.push({
831
+ instanceLocation,
832
+ keyword: "minLength",
833
+ keywordLocation: `${schemaLocation}/minLength`,
834
+ error: `String is too short (${length} < ${$minLength}).`
835
+ });
836
+ if ($maxLength !== void 0 && length > $maxLength) errors.push({
837
+ instanceLocation,
838
+ keyword: "maxLength",
839
+ keywordLocation: `${schemaLocation}/maxLength`,
840
+ error: `String is too long (${length} > ${$maxLength}).`
841
+ });
842
+ if ($pattern !== void 0 && !new RegExp($pattern, "u").test(instance)) errors.push({
843
+ instanceLocation,
844
+ keyword: "pattern",
845
+ keywordLocation: `${schemaLocation}/pattern`,
846
+ error: `String does not match pattern.`
847
+ });
848
+ if ($format !== void 0 && format[$format] && !format[$format](instance)) errors.push({
849
+ instanceLocation,
850
+ keyword: "format",
851
+ keywordLocation: `${schemaLocation}/format`,
852
+ error: `String does not match format "${$format}".`
853
+ });
854
+ }
855
+ return {
856
+ valid: errors.length === 0,
857
+ errors
858
+ };
859
+ }
860
+
861
+ //#endregion
862
+ //#region ../../node_modules/.pnpm/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/validator.js
863
+ var Validator = class {
864
+ schema;
865
+ draft;
866
+ shortCircuit;
867
+ lookup;
868
+ constructor(schema, draft = "2019-09", shortCircuit = true) {
869
+ this.schema = schema;
870
+ this.draft = draft;
871
+ this.shortCircuit = shortCircuit;
872
+ this.lookup = dereference(schema);
873
+ }
874
+ validate(instance) {
875
+ return validate(instance, this.schema, this.draft, this.lookup, this.shortCircuit);
876
+ }
877
+ addSchema(schema, id) {
878
+ if (id) schema = {
879
+ ...schema,
880
+ $id: id
881
+ };
882
+ dereference(schema, this.lookup);
883
+ }
884
+ };
885
+
886
+ //#endregion
887
+ //#region ../core-internal/src/validators/cfWorkerProvider.ts
888
+ /**
889
+ * Cloudflare Worker-compatible JSON Schema validator provider
890
+ *
891
+ * This provider uses @cfworker/json-schema for validation without code generation,
892
+ * making it compatible with edge runtimes like Cloudflare Workers that restrict
893
+ * eval and new Function.
894
+ *
895
+ * @see {@linkcode AjvJsonSchemaValidator} for the Node.js alternative
896
+ */
897
+ /**
898
+ * Canonical 2020-12 `$schema` URIs (http + https variants, trailing-`#` stripped). When a schema
899
+ * declares anything else and no `{draft}` is forced, the provider throws a plain `Error`.
900
+ */
901
+ const DRAFT_2020_12_URIS = new Set(["https://json-schema.org/draft/2020-12/schema", "http://json-schema.org/draft/2020-12/schema"]);
902
+ /**
903
+ * `@cfworker/json-schema`-backed JSON Schema validator. See
904
+ * `@modelcontextprotocol/{client,server}/validators/cf-worker` for the customisation entry point.
905
+ *
906
+ * Default validates as **JSON Schema 2020-12** (SEP-1613). Schemas declaring a different
907
+ * `$schema` are rejected with a plain `Error`. Passing an explicit `draft` to the constructor
908
+ * overrides this — that draft is used for every schema regardless of `$schema`.
909
+ *
910
+ * @example Use with default configuration (2020-12, shortcircuit on)
911
+ * ```ts source="./cfWorkerProvider.examples.ts#CfWorkerJsonSchemaValidator_default"
912
+ * const validator = new CfWorkerJsonSchemaValidator();
913
+ * ```
914
+ *
915
+ * @example Use with custom configuration
916
+ * ```ts source="./cfWorkerProvider.examples.ts#CfWorkerJsonSchemaValidator_customConfig"
917
+ * const validator = new CfWorkerJsonSchemaValidator({
918
+ * draft: '2020-12',
919
+ * shortcircuit: false // Report all errors
920
+ * });
921
+ * ```
922
+ */
923
+ var CfWorkerJsonSchemaValidator = class {
924
+ shortcircuit;
925
+ /** Caller-supplied draft; when set, the `$schema` check is skipped (caller owns dialect). */
926
+ draft;
927
+ /**
928
+ * Create a validator
929
+ *
930
+ * @param options - Configuration options
931
+ * @param options.shortcircuit - If `true`, stop validation after first error (default: `true`)
932
+ * @param options.draft - JSON Schema draft version to force for every schema. When set, the
933
+ * `$schema` check is skipped. When omitted, the provider validates as 2020-12 and rejects
934
+ * schemas declaring a different `$schema`.
935
+ */
936
+ constructor(options) {
937
+ this.shortcircuit = options?.shortcircuit ?? true;
938
+ this.draft = options?.draft;
939
+ }
940
+ /**
941
+ * Create a validator for the given JSON Schema
942
+ *
943
+ * Unlike AJV, this validator is not cached internally
944
+ *
945
+ * @param schema - Standard JSON Schema object
946
+ * @returns A validator function that validates input data
947
+ */
948
+ getValidator(schema) {
949
+ if (this.draft === void 0 && "$schema" in schema && typeof schema.$schema === "string" && !DRAFT_2020_12_URIS.has(schema.$schema.replace(/#$/, ""))) {
950
+ const declared = schema.$schema.slice(0, 200);
951
+ throw new Error(`JSON Schema declares an unsupported dialect ("$schema": "${declared}"). The default validator supports JSON Schema 2020-12 only; pass an explicit { draft } to CfWorkerJsonSchemaValidator to validate other dialects.`);
952
+ }
953
+ const validator = new Validator(schema, this.draft ?? "2020-12", this.shortcircuit);
954
+ return (input) => {
955
+ const result = validator.validate(input);
956
+ return result.valid ? {
957
+ valid: true,
958
+ data: input,
959
+ errorMessage: void 0
960
+ } : {
961
+ valid: false,
962
+ data: void 0,
963
+ errorMessage: result.errors.map((err) => `${err.instanceLocation}: ${err.error}`).join("; ")
964
+ };
965
+ };
966
+ }
967
+ };
968
+
969
+ //#endregion
970
+ Object.defineProperty(exports, 'CfWorkerJsonSchemaValidator', {
971
+ enumerable: true,
972
+ get: function () {
973
+ return CfWorkerJsonSchemaValidator;
974
+ }
975
+ });
976
+ //# sourceMappingURL=cfWorkerProvider-Djgwc46-.cjs.map