vafast 0.3.7 → 0.3.10

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.
@@ -165,142 +165,91 @@ function stream(stream2, status = 200, headers = {}) {
165
165
  });
166
166
  }
167
167
 
168
- // src/utils/validators/schema-validators-ultra.ts
168
+ // src/utils/validators/validators.ts
169
+ import { Type } from "@sinclair/typebox";
169
170
  import { TypeCompiler } from "@sinclair/typebox/compiler";
170
- var SCHEMA_FLAGS = {
171
- BODY: 1 << 0,
172
- // 1
173
- QUERY: 1 << 1,
174
- // 2
175
- PARAMS: 1 << 2,
176
- // 4
177
- HEADERS: 1 << 3,
178
- // 8
179
- COOKIES: 1 << 4
180
- // 16
181
- };
182
- var ultraSchemaCache = /* @__PURE__ */ new Map();
183
- var schemaCacheHits = /* @__PURE__ */ new Map();
184
- var errorPool = [];
185
- var ERROR_POOL_SIZE = 200;
186
- var errorMessagePool = /* @__PURE__ */ new Map();
187
- var commonMessages = [
188
- "\u8BF7\u6C42\u4F53\u9A8C\u8BC1\u5931\u8D25",
189
- "Query\u53C2\u6570\u9A8C\u8BC1\u5931\u8D25",
190
- "\u8DEF\u5F84\u53C2\u6570\u9A8C\u8BC1\u5931\u8D25",
191
- "\u8BF7\u6C42\u5934\u9A8C\u8BC1\u5931\u8D25",
192
- "Cookie\u9A8C\u8BC1\u5931\u8D25",
193
- "\u7C7B\u578B\u9A8C\u8BC1\u5931\u8D25",
194
- "Schema\u7F16\u8BD1\u5931\u8D25",
195
- "\u672A\u77E5\u9519\u8BEF"
196
- ];
197
- commonMessages.forEach((msg) => errorMessagePool.set(msg, msg));
198
- for (let i = 0; i < ERROR_POOL_SIZE; i++) {
199
- errorPool.push(new Error());
200
- }
201
- var errorPoolIndex = 0;
202
- function getErrorFromPool(message) {
203
- const error = errorPool[errorPoolIndex];
204
- error.message = message;
205
- errorPoolIndex = (errorPoolIndex + 1) % ERROR_POOL_SIZE;
206
- return error;
207
- }
208
- function getPooledString(key) {
209
- let pooled = errorMessagePool.get(key);
210
- if (!pooled) {
211
- pooled = key;
212
- errorMessagePool.set(key, key);
213
- }
214
- return pooled;
215
- }
216
- function getUltraSchemaCompiler(schema) {
217
- let compiler = ultraSchemaCache.get(schema);
218
- if (compiler) {
219
- schemaCacheHits.set(schema, (schemaCacheHits.get(schema) || 0) + 1);
220
- return compiler;
221
- }
222
- try {
171
+ var compilerCache = /* @__PURE__ */ new WeakMap();
172
+ function getCompiledValidator(schema) {
173
+ let compiler = compilerCache.get(schema);
174
+ if (!compiler) {
223
175
  compiler = TypeCompiler.Compile(schema);
224
- ultraSchemaCache.set(schema, compiler);
225
- return compiler;
226
- } catch (error) {
227
- return null;
176
+ compilerCache.set(schema, compiler);
228
177
  }
178
+ return compiler;
229
179
  }
230
- function getSchemaFlags(config) {
231
- let flags = 0;
232
- if (config.body) flags |= SCHEMA_FLAGS.BODY;
233
- if (config.query) flags |= SCHEMA_FLAGS.QUERY;
234
- if (config.params) flags |= SCHEMA_FLAGS.PARAMS;
235
- if (config.headers) flags |= SCHEMA_FLAGS.HEADERS;
236
- if (config.cookies) flags |= SCHEMA_FLAGS.COOKIES;
237
- return flags;
238
- }
239
- function validateSchemaUltra(schema, data, context) {
240
- if (!schema) return data;
180
+ function validateSchema(schema, data) {
241
181
  try {
242
- let compiler = ultraSchemaCache.get(schema);
243
- if (!compiler) {
244
- try {
245
- compiler = TypeCompiler.Compile(schema);
246
- ultraSchemaCache.set(schema, compiler);
247
- } catch (error) {
248
- const message = getPooledString(`${context}\u9A8C\u8BC1\u5931\u8D25: Schema\u7F16\u8BD1\u5931\u8D25`);
249
- throw getErrorFromPool(message);
250
- }
182
+ const compiler = getCompiledValidator(schema);
183
+ if (compiler.Check(data)) {
184
+ return { success: true, data };
251
185
  }
252
- const result = compiler.Check(data);
253
- if (!result) {
254
- const message = getPooledString(`${context}\u9A8C\u8BC1\u5931\u8D25`);
255
- throw getErrorFromPool(message);
186
+ const errors = [];
187
+ for (const error of compiler.Errors(data)) {
188
+ errors.push({
189
+ path: error.path,
190
+ message: error.message,
191
+ code: "VALIDATION_FAILED",
192
+ value: error.value
193
+ });
256
194
  }
257
- return data;
195
+ return { success: false, errors };
258
196
  } catch (error) {
259
- if (error instanceof Error && error.message.includes("\u9A8C\u8BC1\u5931\u8D25")) {
260
- throw error;
261
- }
262
- const message = getPooledString(
263
- `${context}\u9A8C\u8BC1\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`
264
- );
265
- throw getErrorFromPool(message);
197
+ return {
198
+ success: false,
199
+ errors: [
200
+ {
201
+ path: "",
202
+ message: error instanceof Error ? error.message : "\u9A8C\u8BC1\u5F02\u5E38",
203
+ code: "VALIDATION_EXCEPTION"
204
+ }
205
+ ]
206
+ };
266
207
  }
267
208
  }
268
- function validateAllSchemasUltra(config, data) {
269
- const flags = getSchemaFlags(config);
270
- if (flags & SCHEMA_FLAGS.BODY) {
271
- validateSchemaUltra(config.body, data.body, "\u8BF7\u6C42\u4F53");
272
- }
273
- if (flags & SCHEMA_FLAGS.QUERY) {
274
- validateSchemaUltra(config.query, data.query, "Query\u53C2\u6570");
275
- }
276
- if (flags & SCHEMA_FLAGS.PARAMS) {
277
- validateSchemaUltra(config.params, data.params, "\u8DEF\u5F84\u53C2\u6570");
278
- }
279
- if (flags & SCHEMA_FLAGS.HEADERS) {
280
- validateSchemaUltra(config.headers, data.headers, "\u8BF7\u6C42\u5934");
281
- }
282
- if (flags & SCHEMA_FLAGS.COOKIES) {
283
- validateSchemaUltra(config.cookies, data.cookies, "Cookie");
209
+ function validateSchemaOrThrow(schema, data, context) {
210
+ const compiler = getCompiledValidator(schema);
211
+ if (!compiler.Check(data)) {
212
+ throw new Error(`${context}\u9A8C\u8BC1\u5931\u8D25`);
284
213
  }
285
214
  return data;
286
215
  }
287
- function precompileSchemasUltra(config) {
288
- const flags = getSchemaFlags(config);
289
- if (flags & SCHEMA_FLAGS.BODY && config.body) {
290
- getUltraSchemaCompiler(config.body);
216
+ function validateFast(schema, data) {
217
+ const compiler = getCompiledValidator(schema);
218
+ return compiler.Check(data);
219
+ }
220
+ function validateAllSchemas(config, data) {
221
+ if (config.body) {
222
+ validateSchemaOrThrow(config.body, data.body, "\u8BF7\u6C42\u4F53");
291
223
  }
292
- if (flags & SCHEMA_FLAGS.QUERY && config.query) {
293
- getUltraSchemaCompiler(config.query);
224
+ if (config.query) {
225
+ validateSchemaOrThrow(config.query, data.query, "Query\u53C2\u6570");
294
226
  }
295
- if (flags & SCHEMA_FLAGS.PARAMS && config.params) {
296
- getUltraSchemaCompiler(config.params);
227
+ if (config.params) {
228
+ validateSchemaOrThrow(config.params, data.params, "\u8DEF\u5F84\u53C2\u6570");
297
229
  }
298
- if (flags & SCHEMA_FLAGS.HEADERS && config.headers) {
299
- getUltraSchemaCompiler(config.headers);
230
+ if (config.headers) {
231
+ validateSchemaOrThrow(config.headers, data.headers, "\u8BF7\u6C42\u5934");
300
232
  }
301
- if (flags & SCHEMA_FLAGS.COOKIES && config.cookies) {
302
- getUltraSchemaCompiler(config.cookies);
233
+ if (config.cookies) {
234
+ validateSchemaOrThrow(config.cookies, data.cookies, "Cookie");
303
235
  }
236
+ return data;
237
+ }
238
+ function precompileSchemas(config) {
239
+ if (config.body) getCompiledValidator(config.body);
240
+ if (config.query) getCompiledValidator(config.query);
241
+ if (config.params) getCompiledValidator(config.params);
242
+ if (config.headers) getCompiledValidator(config.headers);
243
+ if (config.cookies) getCompiledValidator(config.cookies);
244
+ }
245
+ function createValidator(schema) {
246
+ return (data) => validateSchema(schema, data);
247
+ }
248
+ function getValidatorCacheStats() {
249
+ return {
250
+ cacheType: "WeakMap",
251
+ note: "WeakMap \u7F13\u5B58\u4F1A\u968F Schema \u5BF9\u8C61\u81EA\u52A8\u6E05\u7406\uFF0C\u65E0\u5185\u5B58\u6CC4\u6F0F\u98CE\u9669"
252
+ };
304
253
  }
305
254
 
306
255
  // src/utils/create-handler.ts
@@ -375,7 +324,7 @@ function createHandler(schemaOrHandler, maybeHandler) {
375
324
  const schema = hasSchema ? schemaOrHandler : {};
376
325
  const handler = hasSchema ? maybeHandler : schemaOrHandler;
377
326
  if (schema.body || schema.query || schema.params || schema.headers || schema.cookies) {
378
- precompileSchemasUltra(schema);
327
+ precompileSchemas(schema);
379
328
  }
380
329
  return async (req) => {
381
330
  try {
@@ -390,7 +339,7 @@ function createHandler(schemaOrHandler, maybeHandler) {
390
339
  }
391
340
  const data = { body, query, params, headers, cookies };
392
341
  if (schema.body || schema.query || schema.params || schema.headers || schema.cookies) {
393
- validateAllSchemasUltra(schema, data);
342
+ validateAllSchemas(schema, data);
394
343
  }
395
344
  const result = await handler({
396
345
  req,
@@ -414,7 +363,7 @@ function createHandlerWithExtra(schemaOrHandler, maybeHandler) {
414
363
  const schema = hasSchema ? schemaOrHandler : {};
415
364
  const handler = hasSchema ? maybeHandler : schemaOrHandler;
416
365
  if (schema.body || schema.query || schema.params || schema.headers || schema.cookies) {
417
- precompileSchemasUltra(schema);
366
+ precompileSchemas(schema);
418
367
  }
419
368
  return async (req) => {
420
369
  try {
@@ -429,7 +378,7 @@ function createHandlerWithExtra(schemaOrHandler, maybeHandler) {
429
378
  }
430
379
  const data = { body, query, params, headers, cookies };
431
380
  if (schema.body || schema.query || schema.params || schema.headers || schema.cookies) {
432
- validateAllSchemasUltra(schema, data);
381
+ validateAllSchemas(schema, data);
433
382
  }
434
383
  const extras = req.__locals ?? {};
435
384
  const result = await handler({
@@ -497,7 +446,7 @@ async function parseRequest(request, params) {
497
446
  }
498
447
  function validateRequest(config, requestData) {
499
448
  try {
500
- const validatedData = validateAllSchemasUltra(config, requestData);
449
+ const validatedData = validateAllSchemas(config, requestData);
501
450
  return {
502
451
  success: true,
503
452
  data: validatedData
@@ -666,93 +615,119 @@ var DependencyManager = class {
666
615
  }
667
616
  };
668
617
 
669
- // src/utils/validators/validators.ts
670
- import { Type } from "@sinclair/typebox";
671
- import { TypeCompiler as TypeCompiler2 } from "@sinclair/typebox/compiler";
672
- var compilerCache = /* @__PURE__ */ new WeakMap();
673
- function getCompiledValidator(schema) {
674
- let compiler = compilerCache.get(schema);
675
- if (!compiler) {
676
- compiler = TypeCompiler2.Compile(schema);
677
- compilerCache.set(schema, compiler);
678
- }
679
- return compiler;
680
- }
681
- function precompileSchemas(schemas) {
682
- for (const schema of schemas) {
683
- getCompiledValidator(schema);
684
- }
685
- }
686
- function validateSchema(schema, data) {
687
- try {
688
- const compiler = getCompiledValidator(schema);
689
- if (compiler.Check(data)) {
690
- return {
691
- success: true,
692
- data
693
- };
694
- }
695
- const errors = [];
696
- const errorIterator = compiler.Errors(data);
697
- for (const error of errorIterator) {
698
- errors.push({
699
- path: error.path,
700
- message: error.message,
701
- code: "VALIDATION_FAILED",
702
- value: error.value,
703
- schema: error.schema
704
- });
705
- }
706
- return {
707
- success: false,
708
- errors
709
- };
710
- } catch (error) {
711
- return {
712
- success: false,
713
- errors: [
714
- {
715
- path: "",
716
- message: error instanceof Error ? error.message : "Unknown validation error",
717
- code: "VALIDATION_EXCEPTION",
718
- value: data
719
- }
720
- ]
721
- };
722
- }
723
- }
724
- function createValidator(schema) {
725
- const compiler = getCompiledValidator(schema);
726
- return (data) => {
727
- if (compiler.Check(data)) {
728
- return { success: true, data };
729
- }
730
- const errors = [];
731
- for (const error of compiler.Errors(data)) {
732
- errors.push({
733
- path: error.path,
734
- message: error.message,
735
- code: "VALIDATION_FAILED",
736
- value: error.value,
737
- schema: error.schema
738
- });
618
+ // src/utils/formats.ts
619
+ import { FormatRegistry } from "@sinclair/typebox";
620
+ var EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
621
+ var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
622
+ var UUID_ANY_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
623
+ var CUID_REGEX = /^c[^\s-]{8,}$/i;
624
+ var CUID2_REGEX = /^[0-9a-z]+$/;
625
+ var ULID_REGEX = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
626
+ var NANOID_REGEX = /^[A-Za-z0-9_-]{21}$/;
627
+ var URL_REGEX = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b[-a-zA-Z0-9()@:%_+.~#?&/=]*$/;
628
+ var IPV4_REGEX = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
629
+ var IPV6_REGEX = /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}$|^(?:[0-9a-fA-F]{1,4}:){1,7}:$|^(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}$|^(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}$|^(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}$|^(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}$|^(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}$|^[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,6}$/;
630
+ var CIDR_REGEX = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:3[0-2]|[12]?[0-9])$/;
631
+ var DATE_REGEX = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])$/;
632
+ var TIME_REGEX = /^(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.\d{1,3})?$/;
633
+ var DATE_TIME_REGEX = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.\d{1,3})?(?:Z|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])?$/;
634
+ var DURATION_REGEX = /^P(?:\d+Y)?(?:\d+M)?(?:\d+W)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?$/;
635
+ var HOSTNAME_REGEX = /^(?=.{1,253}$)(?:(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)*(?!-)[a-zA-Z0-9-]{1,63}(?<!-)$/;
636
+ var PHONE_CN_REGEX = /^1[3-9]\d{9}$/;
637
+ var PHONE_E164_REGEX = /^\+[1-9]\d{6,14}$/;
638
+ var OBJECTID_REGEX = /^[0-9a-fA-F]{24}$/;
639
+ var HEX_COLOR_REGEX = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
640
+ var RGB_COLOR_REGEX = /^rgba?\(\s*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\s*,\s*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\s*,\s*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$/;
641
+ var BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
642
+ var BASE64URL_REGEX = /^[A-Za-z0-9_-]+$/;
643
+ var JWT_REGEX = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
644
+ var EMOJI_REGEX = /^[\p{Emoji}]+$/u;
645
+ var SLUG_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
646
+ var SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
647
+ function isValidCreditCard(value) {
648
+ const digits = value.replace(/\D/g, "");
649
+ if (digits.length < 13 || digits.length > 19) return false;
650
+ let sum = 0;
651
+ let isEven = false;
652
+ for (let i = digits.length - 1; i >= 0; i--) {
653
+ let digit = parseInt(digits[i], 10);
654
+ if (isEven) {
655
+ digit *= 2;
656
+ if (digit > 9) digit -= 9;
739
657
  }
740
- return { success: false, errors };
741
- };
742
- }
743
- function validateFast(schema, data) {
744
- const compiler = getCompiledValidator(schema);
745
- return compiler.Check(data);
746
- }
747
- function getValidatorCacheStats() {
748
- return {
749
- cacheType: "WeakMap",
750
- note: "WeakMap \u4E0D\u652F\u6301 size \u5C5E\u6027\uFF0C\u7F13\u5B58\u4F1A\u968F Schema \u5BF9\u8C61\u81EA\u52A8\u6E05\u7406"
751
- };
752
- }
658
+ sum += digit;
659
+ isEven = !isEven;
660
+ }
661
+ return sum % 10 === 0;
662
+ }
663
+ var isRegistered = false;
664
+ function registerFormats() {
665
+ if (isRegistered) return;
666
+ isRegistered = true;
667
+ FormatRegistry.Set("email", (v) => EMAIL_REGEX.test(v));
668
+ FormatRegistry.Set("uuid", (v) => UUID_REGEX.test(v));
669
+ FormatRegistry.Set("uuid-any", (v) => UUID_ANY_REGEX.test(v));
670
+ FormatRegistry.Set("cuid", (v) => CUID_REGEX.test(v));
671
+ FormatRegistry.Set("cuid2", (v) => CUID2_REGEX.test(v) && v.length >= 1);
672
+ FormatRegistry.Set("ulid", (v) => ULID_REGEX.test(v));
673
+ FormatRegistry.Set("nanoid", (v) => NANOID_REGEX.test(v));
674
+ FormatRegistry.Set("objectid", (v) => OBJECTID_REGEX.test(v));
675
+ FormatRegistry.Set("slug", (v) => SLUG_REGEX.test(v));
676
+ FormatRegistry.Set("url", (v) => URL_REGEX.test(v));
677
+ FormatRegistry.Set("uri", (v) => URL_REGEX.test(v));
678
+ FormatRegistry.Set("ipv4", (v) => IPV4_REGEX.test(v));
679
+ FormatRegistry.Set("ipv6", (v) => IPV6_REGEX.test(v));
680
+ FormatRegistry.Set("ip", (v) => IPV4_REGEX.test(v) || IPV6_REGEX.test(v));
681
+ FormatRegistry.Set("cidr", (v) => CIDR_REGEX.test(v));
682
+ FormatRegistry.Set("hostname", (v) => HOSTNAME_REGEX.test(v));
683
+ FormatRegistry.Set("date", (v) => DATE_REGEX.test(v));
684
+ FormatRegistry.Set("time", (v) => TIME_REGEX.test(v));
685
+ FormatRegistry.Set("date-time", (v) => DATE_TIME_REGEX.test(v));
686
+ FormatRegistry.Set("datetime", (v) => DATE_TIME_REGEX.test(v));
687
+ FormatRegistry.Set("duration", (v) => DURATION_REGEX.test(v));
688
+ FormatRegistry.Set("phone", (v) => PHONE_CN_REGEX.test(v));
689
+ FormatRegistry.Set("phone-cn", (v) => PHONE_CN_REGEX.test(v));
690
+ FormatRegistry.Set("phone-e164", (v) => PHONE_E164_REGEX.test(v));
691
+ FormatRegistry.Set("base64", (v) => BASE64_REGEX.test(v));
692
+ FormatRegistry.Set("base64url", (v) => BASE64URL_REGEX.test(v));
693
+ FormatRegistry.Set("jwt", (v) => JWT_REGEX.test(v));
694
+ FormatRegistry.Set("hex-color", (v) => HEX_COLOR_REGEX.test(v));
695
+ FormatRegistry.Set("rgb-color", (v) => RGB_COLOR_REGEX.test(v));
696
+ FormatRegistry.Set(
697
+ "color",
698
+ (v) => HEX_COLOR_REGEX.test(v) || RGB_COLOR_REGEX.test(v)
699
+ );
700
+ FormatRegistry.Set("emoji", (v) => EMOJI_REGEX.test(v));
701
+ FormatRegistry.Set("semver", (v) => SEMVER_REGEX.test(v));
702
+ FormatRegistry.Set("credit-card", isValidCreditCard);
703
+ }
704
+ function registerFormat(name, validator) {
705
+ FormatRegistry.Set(name, validator);
706
+ }
707
+ function hasFormat(name) {
708
+ return FormatRegistry.Has(name);
709
+ }
710
+ var Patterns = {
711
+ EMAIL: EMAIL_REGEX,
712
+ UUID: UUID_REGEX,
713
+ URL: URL_REGEX,
714
+ IPV4: IPV4_REGEX,
715
+ IPV6: IPV6_REGEX,
716
+ DATE: DATE_REGEX,
717
+ TIME: TIME_REGEX,
718
+ DATE_TIME: DATE_TIME_REGEX,
719
+ PHONE_CN: PHONE_CN_REGEX,
720
+ PHONE_E164: PHONE_E164_REGEX,
721
+ OBJECTID: OBJECTID_REGEX,
722
+ HEX_COLOR: HEX_COLOR_REGEX,
723
+ SLUG: SLUG_REGEX,
724
+ SEMVER: SEMVER_REGEX,
725
+ JWT: JWT_REGEX
726
+ };
753
727
  export {
754
728
  DependencyManager,
755
729
  HtmlRenderer,
730
+ Patterns,
756
731
  base64urlDecode,
757
732
  base64urlEncode,
758
733
  createHandler,
@@ -765,6 +740,7 @@ export {
765
740
  getLocals,
766
741
  getValidatorCacheStats,
767
742
  goAwait,
743
+ hasFormat,
768
744
  html,
769
745
  json,
770
746
  parseAndValidateRequest,
@@ -777,13 +753,17 @@ export {
777
753
  parseRequest,
778
754
  precompileSchemas,
779
755
  redirect,
756
+ registerFormat,
757
+ registerFormats,
780
758
  setLocals,
781
759
  simpleHandler,
782
760
  stream,
783
761
  text,
762
+ validateAllSchemas,
784
763
  validateFast,
785
764
  validateRequest,
786
- validateSchema
765
+ validateSchema,
766
+ validateSchemaOrThrow
787
767
  };
788
768
  /**
789
769
  * Go 风格的错误处理工具
@@ -793,25 +773,6 @@ export {
793
773
  * @version 1.0.0
794
774
  * @license MIT
795
775
  */
796
- /**
797
- * 超优化版Schema验证器 v5.0.0
798
- *
799
- * 使用经过验证的优化技术,确保极致性能
800
- * - 内联函数调用
801
- * - 预编译缓存优化
802
- * - 内存池优化
803
- * - 位运算优化
804
- * - 类型特化优化
805
- * - 循环展开优化
806
- * - 位掩码优化
807
- * - 字符串池优化
808
- * - 内联缓存优化
809
- * - 内存对齐优化
810
- *
811
- * @author Framework Team
812
- * @version 5.0.0
813
- * @license MIT
814
- */
815
776
  /**
816
777
  * 类型安全的路由处理器工厂
817
778
  *