1var store; 2// @__NO_SIDE_EFFECTS__ 3function getGlobalConfig(config2) { 4 return { 5 lang: (config2 == null ? void 0 : config2.lang) ?? (store == null ? void 0 : store.lang), 6 message: config2 == null ? void 0 : config2.message, 7 abortEarly: (config2 == null ? void 0 : config2.abortEarly) ?? (store == null ? void 0 : store.abortEarly), 8 abortPipeEarly: (config2 == null ? void 0 : config2.abortPipeEarly) ?? (store == null ? void 0 : store.abortPipeEarly) 9 }; 10} 11var store2; 12// @__NO_SIDE_EFFECTS__ 13function getGlobalMessage(lang) { 14 return store2 == null ? void 0 : store2.get(lang); 15} 16var store3; 17// @__NO_SIDE_EFFECTS__ 18function getSchemaMessage(lang) { 19 return store3 == null ? void 0 : store3.get(lang); 20} 21var store4; 22// @__NO_SIDE_EFFECTS__ 23function getSpecificMessage(reference, lang) { 24 var _a; 25 return (_a = store4 == null ? void 0 : store4.get(reference)) == null ? void 0 : _a.get(lang); 26} 27// @__NO_SIDE_EFFECTS__ 28function _stringify(input) { 29 var _a, _b; 30 const type = typeof input; 31 if (type === "string") { 32 return `"${input}"`; 33 } 34 if (type === "number" || type === "bigint" || type === "boolean") { 35 return `${input}`; 36 } 37 if (type === "object" || type === "function") { 38 return (input && ((_b = (_a = Object.getPrototypeOf(input)) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name)) ?? "null"; 39 } 40 return type; 41} 42function _addIssue(context, label, dataset, config2, other) { 43 const input = other && "input" in other ? other.input : dataset.value; 44 const expected = (other == null ? void 0 : other.expected) ?? context.expects ?? null; 45 const received = (other == null ? void 0 : other.received) ?? /* @__PURE__ */ _stringify(input); 46 const issue = { 47 kind: context.kind, 48 type: context.type, 49 input, 50 expected, 51 received, 52 message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`, 53 requirement: context.requirement, 54 path: other == null ? void 0 : other.path, 55 issues: other == null ? void 0 : other.issues, 56 lang: config2.lang,
57 abortEarly: config2.abortEarly, 58 abortPipeEarly: config2.abortPipeEarly 59 }; 60 const isSchema = context.kind === "schema"; 61 const message2 = (other == null ? void 0 : other.message) ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config2.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang); 62 if (message2 !== void 0) { 63 issue.message = typeof message2 === "function" ? ( 64 // @ts-expect-error 65 message2(issue) 66 ) : message2; 67 } 68 if (isSchema) { 69 dataset.typed = false; 70 } 71 if (dataset.issues) { 72 dataset.issues.push(issue); 73 } else { 74 dataset.issues = [issue]; 75 } 76} 77// @__NO_SIDE_EFFECTS__ 78function _getStandardProps(context) { 79 return { 80 version: 1, 81 vendor: "valibot", 82 validate(value2) { 83 return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig()); 84 } 85 }; 86} 87// @__NO_SIDE_EFFECTS__ 88function _joinExpects(values2, separator) { 89 const list = [...new Set(values2)]; 90 if (list.length > 1) { 91 return `(${list.join(` ${separator} `)})`; 92 } 93 return list[0] ?? "never"; 94} 95var ValiError = class extends Error { 96 /** 97 * Creates a Valibot error with useful information. 98 * 99 * @param issues The error issues. 100 */ 101 constructor(issues) { 102 super(issues[0].message); 103 this.name = "ValiError"; 104 this.issues = issues; 105 } 106}; 107var EMAIL_REGEX = /^[\w+-]+(?:\.[\w+-]+)*@[\da-z]+(?:[.-][\da-z]+)*\.[a-z]{2,}$/iu; 108// @__NO_SIDE_EFFECTS__ 109function check(requirement, message2) { 110 return { 111 kind: "validation", 112 type: "check", 113 reference: check, 114 async: false, 115 expects: null, 116 requirement, 117 message: message2, 118 "~run"(dataset, config2) { 119 if (dataset.typed && !this.requirement(dataset.value)) { 120 _addIssue(this, "input", dataset, config2); 121 } 122 return dataset; 123 } 124 }; 125} 126// @__NO_SIDE_EFFECTS__ 127function email(message2) { 128 return { 129 kind: "validation", 130 type: "email", 131 reference: email, 132 expects: null, 133 async: false, 134 requirement: EMAIL_REGEX, 135 message: message2, 136 "~run"(dataset, config2) { 137 if (dataset.typed && !this.requirement.test(dataset.value)) { 138 _addIssue(this, "email", dataset, config2); 139 } 140 return dataset; 141 } 142 }; 143} 144// @__NO_SIDE_EFFECTS__ 145function minLength(requirement, message2) { 146 return { 147 kind: "validation", 148 type: "min_length", 149 reference: minLength, 150 async: false, 151 expects: `>=${requirement}`, 152 requirement, 153 message: message2, 154 "~run"(dataset, config2) { 155 if (dataset.typed && dataset.value.length < this.requirement) { 156 _addIssue(this, "length", dataset, config2, { 157 received: `${dataset.value.length}` 158 }); 159 } 160 return dataset; 161 } 162 }; 163} 164// @__NO_SIDE_EFFECTS__ 165function nonEmpty(message2) { 166 return { 167 kind: "validation", 168 type: "non_empty", 169 reference: nonEmpty, 170 async: false, 171 expects: "!0", 172 message: message2, 173 "~run"(dataset, config2) { 174 if (dataset.typed && dataset.value.length === 0) { 175 _addIssue(this, "length", dataset, config2, { 176 received: "0" 177 }); 178 } 179 return dataset; 180 } 181 }; 182} 183// @__NO_SIDE_EFFECTS__ 184function getFallback(schema, dataset, config2) { 185 return typeof schema.fallback === "function" ? ( 186 // @ts-expect-error 187 schema.fallback(dataset, config2) 188 ) : ( 189 // @ts-expect-error 190 schema.fallback 191 ); 192} 193// @__NO_SIDE_EFFECTS__ 194function forward(action, path) { 195 return { 196 ...action, 197 "~run"(dataset, config2) { 198 const prevIssues = dataset.issues && [...dataset.issues]; 199 dataset = action["~run"](dataset, config2); 200 if (dataset.issues) { 201 for (const issue of dataset.issues) { 202 if (!(prevIssues == null ? void 0 : prevIssues.includes(issue))) { 203 let pathInput = dataset.value; 204 for (const key of path) { 205 const pathValue = pathInput[key]; 206 const pathItem = { 207 type: "unknown", 208 origin: "value", 209 input: pathInput, 210 key, 211 value: pathValue 212 }; 213 if (issue.path) { 214 issue.path.push(pathItem); 215 } else { 216 issue.path = [pathItem]; 217 } 218 if (!pathValue) { 219 break; 220 } 221 pathInput = pathValue; 222 } 223 } 224 } 225 } 226 return dataset; 227 } 228 }; 229} 230// @__NO_SIDE_EFFECTS__ 231function getDefault(schema, dataset, config2) { 232 return typeof schema.default === "function" ? ( 233 // @ts-expect-error 234 schema.default(dataset, config2) 235 ) : ( 236 // @ts-expect-error 237 schema.default 238 ); 239} 240// @__NO_SIDE_EFFECTS__ 241function custom(check2, message2) { 242 return { 243 kind: "schema", 244 type: "custom", 245 reference: custom, 246 expects: "unknown", 247 async: false, 248 check: check2, 249 message: message2, 250 get "~standard"() { 251 return /* @__PURE__ */ _getStandardProps(this); 252 }, 253 "~run"(dataset, config2) { 254 if (this.check(dataset.value)) { 255 dataset.typed = true; 256 } else { 257 _addIssue(this, "type", dataset, config2); 258 } 259 return dataset; 260 } 261 }; 262} 263// @__NO_SIDE_EFFECTS__ 264function enum_(enum__, message2) { 265 const options = []; 266 for (const key in enum__) { 267 if (`${+key}` !== key || typeof enum__[key] !== "string" || !Object.is(enum__[enum__[key]], +key)) { 268 options.push(enum__[key]); 269 } 270 } 271 return { 272 kind: "schema", 273 type: "enum", 274 reference: enum_, 275 expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"), 276 async: false, 277 enum: enum__, 278 options, 279 message: message2, 280 get "~standard"() { 281 return /* @__PURE__ */ _getStandardProps(this); 282 }, 283 "~run"(dataset, config2) { 284 if (this.options.includes(dataset.value)) { 285 dataset.typed = true; 286 } else { 287 _addIssue(this, "type", dataset, config2); 288 } 289 return dataset; 290 } 291 }; 292} 293// @__NO_SIDE_EFFECTS__ 294function object(entries2, message2) { 295 return { 296 kind: "schema", 297 type: "object", 298 reference: object, 299 expects: "Object", 300 async: false, 301 entries: entries2, 302 message: message2, 303 get "~standard"() { 304 return /* @__PURE__ */ _getStandardProps(this); 305 }, 306 "~run"(dataset, config2) { 307 var _a; 308 const input = dataset.value; 309 if (input && typeof input === "object") { 310 dataset.typed = true; 311 dataset.value = {}; 312 for (const key in this.entries) { 313 const valueSchema = this.entries[key]; 314 if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && // @ts-expect-error 315 valueSchema.default !== void 0) { 316 const value2 = key in input ? ( 317 // @ts-expect-error 318 input[key] 319 ) : /* @__PURE__ */ getDefault(valueSchema); 320 const valueDataset = valueSchema["~run"]({ value: value2 }, config2); 321 if (valueDataset.issues) { 322 const pathItem = { 323 type: "object", 324 origin: "value", 325 input, 326 key, 327 value: value2 328 }; 329 for (const issue of valueDataset.issues) { 330 if (issue.path) { 331 issue.path.unshift(pathItem); 332 } else { 333 issue.path = [pathItem]; 334 } 335 (_a = dataset.issues) == null ? void 0 : _a.push(issue); 336 } 337 if (!dataset.issues) { 338 dataset.issues = valueDataset.issues; 339 }
340 if (config2.abortEarly) { 341 dataset.typed = false; 342 break; 343 } 344 } 345 if (!valueDataset.typed) { 346 dataset.typed = false; 347 } 348 dataset.value[key] = valueDataset.value; 349 } else if (valueSchema.fallback !== void 0) { 350 dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema); 351 } else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") { 352 _addIssue(this, "key", dataset, config2, { 353 input: void 0, 354 expected: `"${key}"`, 355 path: [ 356 { 357 type: "object", 358 origin: "key", 359 input, 360 key, 361 // @ts-expect-error 362 value: input[key] 363 } 364 ] 365 }); 366 if (config2.abortEarly) { 367 break; 368 } 369 } 370 } 371 } else { 372 _addIssue(this, "type", dataset, config2); 373 } 374 return dataset; 375 } 376 }; 377} 378// @__NO_SIDE_EFFECTS__ 379function optional(wrapped, default_) { 380 return { 381 kind: "schema", 382 type: "optional", 383 reference: optional, 384 expects: `(${wrapped.expects} | undefined)`, 385 async: false, 386 wrapped, 387 default: default_, 388 get "~standard"() { 389 return /* @__PURE__ */ _getStandardProps(this); 390 }, 391 "~run"(dataset, config2) { 392 if (dataset.value === void 0) { 393 if (this.default !== void 0) { 394 dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2); 395 } 396 if (dataset.value === void 0) { 397 dataset.typed = true; 398 return dataset; 399 } 400 } 401 return this.wrapped["~run"](dataset, config2); 402 } 403 }; 404} 405// @__NO_SIDE_EFFECTS__ 406function picklist(options, message2) { 407 return { 408 kind: "schema", 409 type: "picklist", 410 reference: picklist, 411 expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"), 412 async: false, 413 options, 414 message: message2, 415 get "~standard"() { 416 return /* @__PURE__ */ _getStandardProps(this); 417 }, 418 "~run"(dataset, config2) { 419 if (this.options.includes(dataset.value)) { 420 dataset.typed = true; 421 } else { 422 _addIssue(this, "type", dataset, config2); 423 } 424 return dataset; 425 } 426 }; 427} 428// @__NO_SIDE_EFFECTS__ 429function string(message2) { 430 return { 431 kind: "schema", 432 type: "string", 433 reference: string, 434 expects: "string", 435 async: false, 436 message: message2, 437 get "~standard"() { 438 return /* @__PURE__ */ _getStandardProps(this); 439 }, 440 "~run"(dataset, config2) { 441 if (typeof dataset.value === "string") { 442 dataset.typed = true; 443 } else { 444 _addIssue(this, "type", dataset, config2); 445 } 446 return dataset; 447 } 448 }; 449} 450function parse(schema, input, config2) { 451 const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2)); 452 if (dataset.issues) { 453 throw new ValiError(dataset.issues); 454 } 455 return dataset.value; 456} 457// @__NO_SIDE_EFFECTS__ 458function pipe(...pipe2) { 459 return { 460 ...pipe2[0], 461 pipe: pipe2, 462 get "~standard"() { 463 return /* @__PURE__ */ _getStandardProps(this); 464 }, 465 "~run"(dataset, config2) { 466 for (const item of pipe2) { 467 if (item.kind !== "metadata") { 468 if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) { 469 dataset.typed = false; 470 break; 471 }
472 if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) { 473 dataset = item["~run"](dataset, config2); 474 } 475 } 476 } 477 return dataset; 478 } 479 }; 480} 481export { 482 ValiError as V, 483 parse as a, 484 optional as b, 485 picklist as c, 486 enum_ as d, 487 email as e, 488 forward as f, 489 check as g, 490 custom as h, 491 minLength as m, 492 nonEmpty as n, 493 object as o, 494 pipe as p, 495 string as s 496};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.