<commit_before>M         = require \mongoose
Cons      = require \../../lib/model-constraints
Crud      = require \../crud
Err       = require \../error
P-Id      = require \./plugin-id
P-Meta    = require \./plugin-meta

schema = new M.Schema do
  name: type:String, required:yes, match:Cons.node.name.regex

schema
  ..plugin P-Id
  ..plugin P-Meta
  # TODO: refactor when mongo allows case-insensitive unique index
  # https://jira.mongodb.org/browse/SERVER-90
  ..pre \save, (next) ->
    err, node <~ me.findOne name:get-regexp @name
    return next err if err
    return next! unless node
    return next new Err.Api "Duplicate detected: #{node.name}"
    next!

module.exports = me = Crud.set-fns (M.model \nodes, schema)

function get-regexp name then
  name = name.replace /\!/g, '\\!'
  name = name.replace /\(/g, '\\('
  name = name.replace /\)/g, '\\)'
  new RegExp "^#{name}$", \i<commit_msg>refactor<commit_after>M         = require \mongoose
Cons      = require \../../lib/model-constraints
Crud      = require \../crud
Err       = require \../error
P-Id      = require \./plugin-id
P-Meta    = require \./plugin-meta

schema = new M.Schema do
  name: type:String, required:yes, match:Cons.node.name.regex

schema
  ..plugin P-Id
  ..plugin P-Meta
  # TODO: refactor when mongo allows case-insensitive unique index
  # https://jira.mongodb.org/browse/SERVER-90
  ..pre \save, (next) ->
    err, node <~ me.findOne name:get-regexp @name
    return next err if err
    return next! unless node
    next new Err.Api "Duplicate detected: #{node.name}"

module.exports = me = Crud.set-fns (M.model \nodes, schema)

function get-regexp name
  name = name.replace /\!/g, '\\!'
  name = name.replace /\(/g, '\\('
  name = name.replace /\)/g, '\\)'
  new RegExp "^#{name}$", \i
{'fraction_non_alphanumeric': 0.16432978126752665, 'fraction_numerical': 0.002243409983174425, 'mean_word_length': 2.4573643410852712, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '6402565', 'n_tokens_mistral': 622, 'n_tokens_neox': 615, 'n_words': 172}