<commit_before>'use strict';

const t = require('koa-joi-router').Joi;

const Category = t.object().label('Category').keys({
   id: t.number(),
   name: t.string()
});

const Tag = t.object().label('Tag').keys({
   id: t.number(),
   name: t.string()
});

const Pet = t.object().label('Pet').keys({
   id: t.number().optional(),
   name: t.string().required(),
   category: Category,
   tags: t.array().items(Tag),
   photoUrls: t.array().items(t.string()).required(),
   status: t.string()
      .valid(['available', 'pending', 'sold'])
      .description(`pet status in the store`)
});

const createPet = {
   method: 'post',
   path: '/pet',
   meta: {
      friendlyName: `Add pet`,
      description: `Add a new pet to the store`
   },
   validate: {
      type: 'json',
      body: Pet
   },
   *handler () {
      const pet = this.request.body;
      return yield this.db().table('pets').insert(pet).run();
   }
};

const updatePet = {
   method: 'put',
   path: '/pet',
   meta: {
      friendlyName: 'Update pet',
      description: 'Update an existing pet'
   },
   validate: {
      type: 'json',
      body: Pet
   },
   *handler () {
      const pet = this.request.body;
      if (!pet.id) this.throw(400, 'Invalid ID supplied');

      const existing = this.db().get(pet.id).run();
      if (!existing) this.throw(404, 'Pet not found');

      return this.db().table('pets').update(pet).run();
   }
};


const getPetByStatus = {
   method: 'put',
   path: '/pet',
   meta: {
      friendlyName: 'Find pets by status'
   },
   validate: {
      type: 'json',
      query: {
         status: t.array()
            .description(`Status values that need to be considered for filter`)
            .items(t.string())
            .min(1)        // At least 1 should be provided
            .single()      // If only one is provided, wrap it in an array
      },
      output: t.array().items(Pet)
   },
   *handler () {
      const query = this.request.query;
<commit_msg>Better example<commit_after>'use strict';

const t = require('koa-joi-router').Joi;

const Category = t.object().label('Category').keys({
   id: t.number(),
   name: t.string()
});

const Tag = t.object().label('Tag').keys({
   id: t.number(),
   name: t.string()
});

const Pet = t.object().label('Pet').keys({
   id: t.number().optional(),
   name: t.string().required(),
   category: Category,
   tags: t.array().items(Tag),
   photoUrls: t.array().items(t.string()).required(),
   status: t.string()
      .valid(['available', 'pending', 'sold'])
      .description(`pet status in the store`)
});

const createPet = {
   method: 'post',
   path: '/pet',
   meta: {
      friendlyName: `Add pet`,
      description: `Add a new pet to the store`
   },
   validate: {
      type: 'json',
      body: Pet
   },
   *handler () {
      const pet = this.request.body;
      return yield this.db().table('pets').insert(pet).run();
   }
};

const updatePet = {
   method: 'put',
   path: '/pet',
   meta: {
      friendlyName: 'Update pet',
      description: 'Update an existing pet'
   },
   validate: {
      type: 'json',
      body: Pet
   },
   *handler () {
      const pet = this.request.body;
      if (!pet.id) this.throw(400, 'Invalid ID supplied');

      const existing = this.db().get(pet.id).run();
      if (!existing) this.throw(404, 'Pet not found');

      return this.db().table('pets').update(pet).run();
   }
};


const getPetByStatus = {
   method: 'put',
   path: '/pet',
   meta: {
      friendlyName: 'Find pets by status'
   },
   validate: {
      type: 'json',
      query: {
         status: t.array()
            .description(`Status values that need to be considered for filter`)
            .items(t.string())
            .min(1)        // At least 1 should be provided
            .single()      // If only one is provided, wrap it in an array
      },
      output: t.array().items(Pet.requiredKeys('id', 'status'))
   },
   *handler () {
      const query = this.request.query;

{'fraction_non_alphanumeric': 0.1815446339017051, 'fraction_numerical': 0.004012036108324975, 'mean_word_length': 2.3747884940778343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4189477', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1275, 'n_words': 332}