1. /**
  2. * Generates configuration file content for hypothesis validation with rate limiting.
  3. *
  4. * @param {object} config - Configuration parameters.
  5. * @param {number} validationRate - Validation requests per time unit.
  6. * @param {number} burstSize - Maximum number of requests allowed in a burst.
  7. * @param {number} timeUnit - Time unit for rate limiting (e.g., seconds).
  8. * @returns {string} - Configuration file content as a string.
  9. */
  10. function generateRateLimitConfig(config) {
  11. const { validationRate, burstSize, timeUnit } = config;
  12. if (typeof validationRate !== 'number' || validationRate <= 0) {
  13. return 'ERROR: validationRate must be a positive number.';
  14. }
  15. if (typeof burstSize !== 'number' || burstSize <= 0) {
  16. return 'ERROR: burstSize must be a positive number.';
  17. }
  18. if (typeof timeUnit !== 'number' || timeUnit <= 0) {
  19. return 'ERROR: timeUnit must be a positive number.';
  20. }
  21. const configContent = `
  22. {
  23. "validation": {
  24. "rateLimit": {
  25. "enabled": true,
  26. "validationRatePerSecond": ${validationRate},
  27. "burstSize": ${burstSize},
  28. "timeUnit": ${timeUnit}
  29. }
  30. }
  31. }
  32. `;
  33. return configContent;
  34. }

Add your comment