@modelcontextprotocol/server 2.0.0-alpha.2 → 2.0.0-alpha.3

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