cfworker-provider.d.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Cloudflare Worker-compatible JSON Schema validator provider
  3. *
  4. * This provider uses @cfworker/json-schema for validation without code generation,
  5. * making it compatible with edge runtimes like Cloudflare Workers that restrict
  6. * eval and new Function.
  7. */
  8. import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from './types.js';
  9. /**
  10. * JSON Schema draft version supported by @cfworker/json-schema
  11. */
  12. export type CfWorkerSchemaDraft = '4' | '7' | '2019-09' | '2020-12';
  13. /**
  14. *
  15. * @example
  16. * ```typescript
  17. * // Use with default configuration (2020-12, shortcircuit)
  18. * const validator = new CfWorkerJsonSchemaValidator();
  19. *
  20. * // Use with custom configuration
  21. * const validator = new CfWorkerJsonSchemaValidator({
  22. * draft: '2020-12',
  23. * shortcircuit: false // Report all errors
  24. * });
  25. * ```
  26. */
  27. export declare class CfWorkerJsonSchemaValidator implements jsonSchemaValidator {
  28. private shortcircuit;
  29. private draft;
  30. /**
  31. * Create a validator
  32. *
  33. * @param options - Configuration options
  34. * @param options.shortcircuit - If true, stop validation after first error (default: true)
  35. * @param options.draft - JSON Schema draft version to use (default: '2020-12')
  36. */
  37. constructor(options?: {
  38. shortcircuit?: boolean;
  39. draft?: CfWorkerSchemaDraft;
  40. });
  41. /**
  42. * Create a validator for the given JSON Schema
  43. *
  44. * Unlike AJV, this validator is not cached internally
  45. *
  46. * @param schema - Standard JSON Schema object
  47. * @returns A validator function that validates input data
  48. */
  49. getValidator<T>(schema: JsonSchemaType): JsonSchemaValidator<T>;
  50. }
  51. //# sourceMappingURL=cfworker-provider.d.ts.map