<commit_before>const mongoose = require('mongoose');

const dataDescriptorSchema = new mongoose.Schema({
  label: {
    type: String,
    required: 'Data value label is required.',
  },
  description: {
    type: String,
  },
  unit: {
    longform: {
      type: String,
    },
    shortform: {
      type: String,
    },
  },
  max: {
    type: Number,
  },
  min: {
    type: Number,
  },
});

const deviceTypeSchema = new mongoose.Schema({
  name: {
    type: String,
    trim: true,
    required: 'Device type name is required.',
  },
  description: {
    type: String,
  },
  developer: {
    type: String,
    trim: true,
  },
  deviceClass: {
    type: String,
    enum: {
      values: ['input', 'output'],
      message: 'Device class must be "input" or "output"',
    },
  },
  dataDescriptor: [dataDescriptorSchema],
});

module.exports = mongoose.model('Device Type', deviceTypeSchema);<commit_msg>device-type: adding name field to data descriptor schema<commit_after>const mongoose = require('mongoose');

const dataDescriptorSchema = new mongoose.Schema({
  label: {
    type: String,
    required: 'Data value label is required.',
  },
  name: {
    type: String,
    required: 'Data value name is required.',
    validate: {
      validator(v) {
        return /^[a-z]+$/.test(v);
      },
      message: '{VALUE} must be lowercase letters only.',
    },
  },
  description: {
    type: String,
  },
  unit: {
    longform: {
      type: String,
    },
    shortform: {
      type: String,
    },
  },
  max: {
    type: Number,
  },
  min: {
    type: Number,
  },
});

const deviceTypeSchema = new mongoose.Schema({
  name: {
    type: String,
    trim: true,
    required: 'Device type name is required.',
  },
  description: {
    type: String,
  },
  developer: {
    type: String,
    trim: true,
  },
  deviceClass: {
    type: String,
    enum: {
      values: ['input', 'output'],
      message: 'Device class must be "input" or "output"',
    },
  },
  dataDescriptor: {
    type: [dataDescriptorSchema],
    validate: {
      validator(v) {
        return v.reduce((result, descriptor) => Object.create({
          isUnique: result.names.indexOf(descriptor.name) > -1 ? false : true,
          names: result.names.concat([descriptor.name]),
        }),
        { isUnique: true, names: [] }).isUnique;
      },
      message: 'Data Descriptor objects must have unique names.',
    },
  },
});

module.exports = mongoose.model('Device Type', deviceTypeSchema);
{'fraction_non_alphanumeric': 0.14957780458383596, 'fraction_numerical': 0.0004020908725371934, 'mean_word_length': 2.5091678420310295, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4593648', 'n_tokens_mistral': 787, 'n_tokens_neox': 795, 'n_words': 204}