<commit_before># maybe ensure we're using `bodyParser()`
# app.use express.bodyParser()

# underscores is amazing, we'll be using this a lot.
_ = require "underscore"
qs = require "querystring"

extendify = require "./extended"

# require your nedb installation
ds = null

# crudify switch, will handle all acceptable routes and pass json errors
# on unsupported request methods.
crudify = (opts, req, fn) ->

  ds = new extendify opts.ds

  # define schema
  Schema = ds.Schema

  # listen for `req.param('id')` will fallback until it finds the id
  id = if req.param("id")? then {_id: req.param("id")} else {}
  
  # `append` (Boolean) is a little trick to extend our update 
  # object with its original contents, plus any new content
  append = if req.query? and req.query.append? then true else false

  # `limit` accepts numbers, will limit the response amount 
  # still pretty wip
  limit = if req.param("limit")? then req.param("limit") else null
  
  # `skip` works currently, just not the best pattern -- `tired`.
  skip = if req.param("skip")? then req.param("skip") else null

  # define a list of protected querys to listen for and not do
  # searches with them
  privates = ['skip', 'limit', 'append', 'id']

  query = {}

  for key, value of req.query
    if privates.indexOf(key) == -1
      query[key] = value

  # do our switch stuff based on this variable
  method = req.method.toLowerCase()

  # exclusions accepts `['some', 'arr']` probably needs some more 
  # work.
  exclude = if opts.exclude? then opts.exclude else null

  # cache keys array, helpful for length and such, we'll use it to validate
  # proper cache objects later on
  
  keys = Object.keys req.body

  # if the bodyParser has an object, we're going to create a schema
  # remember each schema has a stale you can override..
  body = null

  # uses `Schema` extension, wee.
  if req.body? and keys.length > 0
    if opts.maxAge? 
      body = new Schema _.extend(req.body, {stale: opts.maxAge, store: opts.store}), ds
    else 
      body = new Schema _.extend(req.body, {stale: null, store: opts.store}), ds

  # on `post` & `put` requests, don't pass go with a null body
  if (method == "post" or method == "put") and body == null 
    return fn error: "You must provide a body to go along with this request.. please try again.", null

  # ensure our delete has an id, otherwise we're its gonna delete randomly?~ out of our cache, das ist bad..
  if (method == "delete") and not id._id?
    return fn error: "One does not always delete the abyss, but when one does, one must include an id", null

  # ensure our datastore is loaded, we don't want to rush anything.
  ds.loadDatabase (err) ->
    return if err? then fn err, null 

    # do our switch, a lot easier this way -- yea
    switch method

      # handle "GET" requests
      # `ds.query` is used
      when "get" then methodHandler.get id, query, (err, datastores) ->
        return if err? then fn err, null

        ### @todo ###
        # added these quickly for my project because I needed it

        if exclude.length > 0

          keys = Object.keys datastores
          
          _.each exclude, (element, index, list) ->
            for k in [0..keys.length]
              do (k) ->
                cur = datastores[k]
                if datastores.indexOf(cur) != -1
                  delete datastores[k][element]

        # build out our skip query
        if skip? then queryHandler.skip skip, datastores, (err, skipped) ->
          datastores = skipped

        # check for limit, if it exists -- we're going to 
        # support a limit
        if limit? then queryHandler.limit limit, datastores, (err, limited) ->
          datastores = limited

        fn null, datastores
<commit_msg>couple small fixes<commit_after># maybe ensure we're using `bodyParser()`
# app.use express.bodyParser()

# underscores is amazing, we'll be using this a lot.
_ = require "underscore"

extendify = require "./extended"

# require your nedb installation
ds = null

# crudify switch, will handle all acceptable routes and pass json errors
# on unsupported request methods.
crudify = (opts, req, fn) ->

  ds = new extendify opts.ds

  # define schema
  Schema = ds.Schema

  # listen for `req.param('id')` will fallback until it finds the id
  id = if req.param("id")? then {_id: req.param("id")} else {}
  
  # `append` (Boolean) is a little trick to extend our update 
  # object with its original contents, plus any new content
  append = if req.query? and req.query.append? then true else false

  # `limit` accepts numbers, will limit the response amount 
  # still pretty wip
  limit = if req.param("limit")? then req.param("limit") else null
  
  # `skip` works currently, just not the best pattern -- `tired`.
  skip = if req.param("skip")? then req.param("skip") else null

  # define a list of protected querys to listen for and not do
  # searches with them
  privates = ['skip', 'limit', 'append', 'id']

  query = {}

  for key, value of req.query
    if privates.indexOf(key) == -1
      query[key] = value

  # do our switch stuff based on this variable
  method = req.method.toLowerCase()

  # exclusions accepts `['some', 'arr']` probably needs some more 
  # work.
  exclude = if opts.exclude? then opts.exclude else null

  # cache keys array, helpful for length and such, we'll use it to validate
  # proper cache objects later on
  
  keys = Object.keys req.body

  # if the bodyParser has an object, we're going to create a schema
  # remember each schema has a stale you can override..
  body = null

  # uses `Schema` extension, wee.
  if req.body? and keys.length > 0
    if opts.maxAge? 
      body = new Schema _.extend(req.body, {stale: opts.maxAge, store: opts.store}), ds
    else 
      body = new Schema _.extend(req.body, {stale: null, store: opts.store}), ds

  # on `post` & `put` requests, don't pass go with a null body
  if (method == "post" or method == "put") and body == null 
    return fn error: "You must provide a body to go along with this request.. please try again.", null

  # ensure our delete has an id, otherwise we're its gonna delete randomly?~ out of our cache, das ist bad..
  if (method == "delete") and not id._id?
    return fn error: "One does not always delete the abyss, but when one does, one must include an id", null

  # ensure our datastore is loaded, we don't want to rush anything.
  ds.loadDatabase (err) ->
    return if err? then fn err, null 

    # do our switch, a lot easier this way -- yea
    switch method

      # handle "GET" requests
      # `ds.query` is used
      when "get" then methodHandler.get id, query, (err, datastores) ->
        return if err? then fn err, null

        ### @todo ###
        # added these quickly for my project because I needed it

        if exclude.length > 0

          keys = Object.keys datastores
          
          _.each exclude, (element, index, list) ->
            for k in [0..keys.length]
              cur = datastores[k]
              if datastores.indexOf(cur) != -1
                delete datastores[k][element]

        # build out our skip query
        if skip? then queryHandler.skip skip, datastores, (err, skipped) ->
          datastores = skipped

        # check for limit, if it exists -- we're going to 
        # support a limit
        if limit? then queryHandler.limit limit, datastores, (err, limited) ->
          datastores = limited

        fn null, datastores

{'fraction_non_alphanumeric': 0.10107095046854082, 'fraction_numerical': 0.0013386880856760374, 'mean_word_length': 2.6857424765663542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '3782030', 'n_tokens_mistral': 2251, 'n_tokens_neox': 2138, 'n_words': 955}