configSchema.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { JSONSchema4 } from 'json-schema'
  2. import { strictObject } from './utils'
  3. import winston from 'winston'
  4. export const bytesizeUnits = ['B', 'K', 'M', 'G', 'T']
  5. export const bytesizeRegex = new RegExp(`^[0-9]+(${bytesizeUnits.join('|')})$`)
  6. export const configSchema: JSONSchema4 = {
  7. type: 'object',
  8. required: ['id', 'endpoints', 'directories', 'buckets', 'keys', 'port', 'workerId', 'limits'],
  9. additionalProperties: false,
  10. properties: {
  11. id: { type: 'string' },
  12. endpoints: {
  13. type: 'object',
  14. additionalProperties: false,
  15. required: ['queryNode', 'substrateNode'],
  16. properties: {
  17. queryNode: { type: 'string' },
  18. substrateNode: { type: 'string' },
  19. elasticSearch: { type: 'string' },
  20. },
  21. },
  22. directories: strictObject({
  23. data: { type: 'string' },
  24. cache: { type: 'string' },
  25. logs: { type: 'string' },
  26. }),
  27. log: {
  28. type: 'object',
  29. additionalProperties: false,
  30. properties: {
  31. file: { type: 'string', enum: [...Object.keys(winston.config.npm.levels), 'off'] },
  32. console: { type: 'string', enum: [...Object.keys(winston.config.npm.levels), 'off'] },
  33. elastic: { type: 'string', enum: [...Object.keys(winston.config.npm.levels), 'off'] },
  34. },
  35. },
  36. limits: strictObject({
  37. storage: { type: 'string', pattern: bytesizeRegex.source },
  38. maxConcurrentStorageNodeDownloads: { type: 'integer', minimum: 1 },
  39. maxConcurrentOutboundConnections: { type: 'integer', minimum: 1 },
  40. outboundRequestsTimeout: { type: 'integer', minimum: 1 },
  41. }),
  42. port: { type: 'integer', minimum: 0 },
  43. keys: { type: 'array', items: { type: 'string' }, minItems: 1 },
  44. buckets: {
  45. oneOf: [
  46. { type: 'array', items: { type: 'integer', minimum: 0 }, minItems: 1 },
  47. { type: 'string', enum: ['all'] },
  48. ],
  49. },
  50. workerId: { type: 'integer', minimum: 0 },
  51. },
  52. }
  53. export default configSchema