<commit_before>import Joi from 'joi';

export default {
  // POST /api/entities
  createEntity: {
    body: {
      entityName: Joi.string(),
      username: Joi.string(),
      domain: Joi.string(),
      contactId: Joi.string().uuid(),
      passwordHash: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
      passwordSalt: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
      keypair: Joi.object({
        public: Joi.string().when('authoritative', { is: false, then: Joi.required() }),
        private: Joi.string(),
        recovery: Joi.string()
      }),
      authoritative: Joi.boolean().default(false),
      admin: Joi.boolean().default(false)
    }
  },

  // UPDATE /api/entities/:entityId
  updateEntity: {
    body: {
      entityName: Joi.string(),
      username: Joi.string(),
      domain: Joi.string(),
      contactId: Joi.string().uuid(),
      passwordHash: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
      passwordSalt: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
      keypair: Joi.object({
        public: Joi.string().when('authoritative', { is: false, then: Joi.required() }),
        private: Joi.string(),
        recovery: Joi.string()
      }),
      authoritative: Joi.boolean().default(false),
      admin: Joi.boolean().default(false)
    },
    params: {
      entityId: Joi.string().uuid().required()
    }
  },

  // POST /api/documents
  createDocument: {
    body: Joi.array().items(Joi.object({
      id: Joi.string().uuid(),
      entityId: Joi.string(),
      contentType: Joi.string().when('deleted', { is: true, otherwise: Joi.required() }),
      version: Joi.number(),
      public: Joi.boolean(),
      diffed: Joi.boolean(),
      encryption: Joi.string(),
      summary: Joi.object({
        contentType: Joi.string(),
        encoding: Joi.string(),
        data: Joi.string()
      }),
      data: Joi.object(),
      references: Joi.object(),
      mentions: Joi.object(),
      tags: Joi.array(),
      key: Joi.string().allow(''),
      deleted: Joi.boolean()
    })).single(),
    options: {
      contextRequest: true
    }
  },

  getActions: {
    query: {
      contentType: Joi.string().required(),
      limit: Joi.number(),
      skip: Joi.number(),
      createdStart: Joi.date(),
      createdEnd: Joi.date(),
      updatedStart: Joi.date(),
      updatedEnd: Joi.date(),
      tags: Joi.array(),
      page: Joi.number()
    }
  },

  // PUT /api/documents
  updateDocument: {
    body: {
      entityId: Joi.string(),
      contentType: Joi.string().required(),
      version: Joi.number(),
      public: Joi.boolean(),
      diffed: Joi.boolean(),
      encryption: Joi.string(),
      summary: Joi.object({
        contentType: Joi.string(),
        encoding: Joi.string(),
        data: Joi.string()
      }),
      data: Joi.object(),
      references: Joi.object(),
      mentions: Joi.object(),
      tags: Joi.array(),
      key: Joi.string().allow('')
    },
    params: {
      documentId: Joi.string().uuid().required()
    }
  },

  // GET /api/auth/salt
  salt: {
    query: {
      username: Joi.string().required()
    }
  },

  // POST /api/auth/login
  login: {
    body: {
      username: Joi.string().required(),
      passwordHash: Joi.string().required()
    }
  },

  // POST /api/clients
  createClient: {
    body: {
      entityId: Joi.string().uuid(),
      clientId: Joi.string().required(),
      clientSecret: Joi.string().required(),
      clientName: Joi.string().required(),
      deviceType: Joi.string().required(),
      redirectUri: Joi.string().required(),
      grantTypes: Joi.string(),
      scope: Joi.string()
    }
  },

  // UPDATE /api/clients/:clientId
  updateClient: {
    body: {
      entityId: Joi.string().uuid(),
      clientId: Joi.string().required(),
      clientSecret: Joi.string().required(),
      clientName: Joi.string().required(),
      deviceType: Joi.string().required(),
      redirectUri: Joi.string().required(),
      grantTypes: Joi.string(),
      scope: Joi.string()
    },
    params: {
      clientId: Joi.string().required()
    }
  },

  adminInterface: {
    body: {
      formname: Joi.string().required(),
      username: Joi.string().required(),
      password: Joi.string().required()
    }
  },

  // POST /api/servers
  createServer: {
    body: {
      domain: Joi.string().required(),
      name: Joi.string(),
      description: Joi.string(),
      keypair: Joi.object({
        public: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
        private: Joi.string()
      }),
      authoritative: Joi.boolean().default(false)
    }
  },

  // UPDATE /api/servers/:serverId
  updateServer: {
    body: {
      domain: Joi.string().required(),
      name: Joi.string(),
      description: Joi.string(),
      keypair: Joi.object({
        public: Joi.string().when('authoritative', { is: true, then: Joi.required() }),<commit_msg>Fixes to server schema validation<commit_after>import Joi from 'joi';

export default {
  // POST /api/entities
  createEntity: {
    body: {
      entityName: Joi.string(),
      username: Joi.string(),
      domain: Joi.string(),
      contactId: Joi.string().uuid(),
      passwordHash: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
      passwordSalt: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
      keypair: Joi.object({
        public: Joi.string().when('authoritative', { is: false, then: Joi.required() }),
        private: Joi.string(),
        recovery: Joi.string()
      }),
      authoritative: Joi.boolean().default(false),
      admin: Joi.boolean().default(false)
    }
  },

  // UPDATE /api/entities/:entityId
  updateEntity: {
    body: {
      entityName: Joi.string(),
      username: Joi.string(),
      domain: Joi.string(),
      contactId: Joi.string().uuid(),
      passwordHash: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
      passwordSalt: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
      keypair: Joi.object({
        public: Joi.string().when('authoritative', { is: false, then: Joi.required() }),
        private: Joi.string(),
        recovery: Joi.string()
      }),
      authoritative: Joi.boolean().default(false),
      admin: Joi.boolean().default(false)
    },
    params: {
      entityId: Joi.string().uuid().required()
    }
  },

  // POST /api/documents
  createDocument: {
    body: Joi.array().items(Joi.object({
      id: Joi.string().uuid(),
      entityId: Joi.string(),
      contentType: Joi.string().when('deleted', { is: true, otherwise: Joi.required() }),
      version: Joi.number(),
      public: Joi.boolean(),
      diffed: Joi.boolean(),
      encryption: Joi.string(),
      summary: Joi.object({
        contentType: Joi.string(),
        encoding: Joi.string(),
        data: Joi.string()
      }),
      data: Joi.object(),
      references: Joi.object(),
      mentions: Joi.object(),
      tags: Joi.array(),
      key: Joi.string().allow(''),
      deleted: Joi.boolean()
    })).single(),
    options: {
      contextRequest: true
    }
  },

  getActions: {
    query: {
      contentType: Joi.string().required(),
      limit: Joi.number(),
      skip: Joi.number(),
      createdStart: Joi.date(),
      createdEnd: Joi.date(),
      updatedStart: Joi.date(),
      updatedEnd: Joi.date(),
      tags: Joi.array(),
      page: Joi.number()
    }
  },

  // PUT /api/documents
  updateDocument: {
    body: {
      entityId: Joi.string(),
      contentType: Joi.string().required(),
      version: Joi.number(),
      public: Joi.boolean(),
      diffed: Joi.boolean(),
      encryption: Joi.string(),
      summary: Joi.object({
        contentType: Joi.string(),
        encoding: Joi.string(),
        data: Joi.string()
      }),
      data: Joi.object(),
      references: Joi.object(),
      mentions: Joi.object(),
      tags: Joi.array(),
      key: Joi.string().allow('')
    },
    params: {
      documentId: Joi.string().uuid().required()
    }
  },

  // GET /api/auth/salt
  salt: {
    query: {
      username: Joi.string().required()
    }
  },

  // POST /api/auth/login
  login: {
    body: {
      username: Joi.string().required(),
      passwordHash: Joi.string().required()
    }
  },

  // POST /api/clients
  createClient: {
    body: {
      entityId: Joi.string().uuid(),
      clientId: Joi.string().required(),
      clientSecret: Joi.string().required(),
      clientName: Joi.string().required(),
      deviceType: Joi.string().required(),
      redirectUri: Joi.string().required(),
      grantTypes: Joi.string(),
      scope: Joi.string()
    }
  },

  // UPDATE /api/clients/:clientId
  updateClient: {
    body: {
      entityId: Joi.string().uuid(),
      clientId: Joi.string().required(),
      clientSecret: Joi.string().required(),
      clientName: Joi.string().required(),
      deviceType: Joi.string().required(),
      redirectUri: Joi.string().required(),
      grantTypes: Joi.string(),
      scope: Joi.string()
    },
    params: {
      clientId: Joi.string().required()
    }
  },

  adminInterface: {
    body: {
      formname: Joi.string().required(),
      username: Joi.string().required(),
      password: <PASSWORD>().<PASSWORD>()
    }
  },

  // POST /api/servers
  createServer: {
    body: {
      domain: Joi.string().required(),
      name: Joi.string(),
      description: Joi.string(),
      keypair: Joi.object({
        public: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
        private: Joi.string()
      }),
      authoritative: Joi.boolean().default(false)
    }
  },

  // UPDATE /api/servers/:serverId
  updateServer: {
    body: {
      domain: Joi.string(),
      name: Joi.string(),
      description: Joi.string(),
      keypair: Joi.object({
        public: Joi.string().when('authoritative', { is: true, then: Joi.required() }),
{'fraction_non_alphanumeric': 0.1806400159505533, 'fraction_numerical': 0.0, 'mean_word_length': 2.4110846650799047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5493912', 'n_tokens_mistral': 3256, 'n_tokens_neox': 3241, 'n_words': 600}