<commit_before>'use strict'
var tape     = require('tape')
var level    = require('level-test')()
var sublevel = require('level-sublevel/bytewise')
var pull     = require('pull-stream')
var cont     = require('cont')

module.exports = function (opts) {

  tape('simple', function (t) {

    var db = sublevel(level('test-ssb-related', {
      valueEncoding: opts.codec
    }))

    var ssb = require('../')(db, opts)

    var alice = ssb.createFeed()
    var bob = ssb.createFeed()
    var charlie = ssb.createFeed()

    alice.add({
      type: 'post',
      text: 'hello, world'
    }, function (err, msg) {
      if(err) throw err
      console.log(msg)

      bob.add({
        type: 'post',
        text: 'welcome!',
        'parent': { msg: msg.key, rel: 'replies-to' }
      }, function (err, msg2) {
        if(err) throw err

        ssb.relatedMessages({id: msg.key, count: true}, function (err, msgs) {

          console.log(msgs)

          t.deepEqual(msgs, {
            key: msg.key, value: msg.value,
            related: [
              msg2
            ],
            count: 1
          })

          t.end()
        })
      })
    })
  })

  tape('deeper', function (t) {

    var db = sublevel(level('test-related2', {
      valueEncoding: opts.codec
    }))

    var ssb = require('../')(db, opts)

    var alice = ssb.createFeed()
    var bob = ssb.createFeed()
    var charlie = ssb.createFeed()


    alice.add({
      type: 'post',
      text: 'hello, world'
    }, function (err, msg) {
      if(err) throw err
      console.log(msg)

      bob.add({
        type: 'post',
        text: 'welcome!',
        'parent': { msg: msg.key, rel: 'replies-to' }
      }, function (err, msg2) {
        if(err) throw err

        charlie.add({
          type: 'post',
          text: 'hey hey',
          'parent': { msg: msg2.key, rel: 'replies-to' }
        }, function (err, msg3) {

          ssb.relatedMessages({id: msg.key, count: true}, function (err, msgs) {

            console.log(JSON.stringify(msgs, null, 2))

            t.deepEqual(msgs, {
              key: msg.key, value: msg.value,
              related: [
                {
                  key: msg2.key, value: msg2.value,
                  related: [
                    msg3
                  ],
                  count: 1
                }
              ],
              count: 2
            })

            t.end()

          })
        })
      })
    })
  })
  tape('shallow', function (t) {

    var db = sublevel(level('test-related3', {
      valueEncoding: opts.codec
    }))

    var ssb = require('../')(db, opts)

    var alice = ssb.createFeed()
    var bob = ssb.createFeed()
    var charlie = ssb.createFeed()


    alice.add({
      type: 'post',
      text: 'hello, world'
    }, function (err, msg1) {
      if(err) throw err


      cont.para([
        bob.add({
          type: 'post',
          text: 'welcome!',
          'parent': { msg: msg1.key, rel: 'replies-to' }
        }),
        charlie.add({
          type: 'post',
          text: 'hey hey',
          'parent': { msg: msg1.key, rel: 'replies-to' }
        })
      ]) (function (err, ary) {
        if(err) throw err
        var msg2 = ary[0]
        var msg3 = ary[1]

        ssb.relatedMessages({id: msg1.key, count: true}, function (err, msgs) {

          console.log(JSON.stringify(msgs, null, 2))

          t.deepEqual(msgs, {
            key: msg1.key, value: msg1.value,
            related: [
              msg2, msg3
            ],
            count: 2
          })

          t.end()
        })
      })
    })
  })


}

if(!module.parent)
  module.exports(require('../defaults'))

<commit_msg>test that disables count, and enables parent fields for related messages<commit_after>'use strict'
var tape     = require('tape')
var level    = require('level-test')()
var sublevel = require('level-sublevel/bytewise')
var pull     = require('pull-stream')
var cont     = require('cont')

module.exports = function (opts) {

  var db = sublevel(level('test-ssb-related', {
    valueEncoding: opts.codec
  }))

  var ssb = require('../')(db, opts)

  var alice = ssb.createFeed()
  var bob = ssb.createFeed()
  var charlie = ssb.createFeed()

  tape('simple', function (t) {

    alice.add({
      type: 'post',
      text: 'hello, world 1'
    }, function (err, msg) {
      if(err) throw err
      console.log(msg)

      bob.add({
        type: 'post',
        text: 'welcome! 1',
        'parent': { msg: msg.key, rel: 'replies-to' }
      }, function (err, msg2) {
        if(err) throw err

        ssb.relatedMessages({id: msg.key, count: true}, function (err, msgs) {

          console.log(msgs)

          t.deepEqual(msgs, {
            key: msg.key, value: msg.value,
            related: [
              msg2
            ],
            count: 1
          })

          t.end()
        })
      })
    })
  })

  tape('deeper', function (t) {

    alice.add({
      type: 'post',
      text: 'hello, world 2'
    }, function (err, msg) {
      if(err) throw err
      console.log(msg)

      bob.add({
        type: 'post',
        text: 'welcome! 2',
        'parent': { msg: msg.key, rel: 'replies-to' }
      }, function (err, msg2) {
        if(err) throw err

        charlie.add({
          type: 'post',
          text: 'hey hey 2',
          'parent': { msg: msg2.key, rel: 'replies-to' }
        }, function (err, msg3) {

          ssb.relatedMessages({id: msg.key, count: true}, function (err, msgs) {

            console.log(JSON.stringify(msgs, null, 2))

            t.deepEqual(msgs, {
              key: msg.key, value: msg.value,
              related: [
                {
                  key: msg2.key, value: msg2.value,
                  related: [
                    msg3
                  ],
                  count: 1
                }
              ],
              count: 2
            })

            t.end()

          })
        })
      })
    })
  })

  tape('shallow', function (t) {

    alice.add({
      type: 'post',
      text: 'hello, world 3'
    }, function (err, msg1) {
      if(err) throw err


      cont.para([
        bob.add({
          type: 'post',
          text: 'welcome! 3',
          'parent': { msg: msg1.key, rel: 'replies-to' }
        }),
        charlie.add({
          type: 'post',
          text: 'hey hey 3',
          'parent': { msg: msg1.key, rel: 'replies-to' }
        })
      ]) (function (err, ary) {
        if(err) throw err
        var msg2 = ary[0]
        var msg3 = ary[1]

        ssb.relatedMessages({id: msg1.key, count: true}, function (err, msgs) {

          console.log(JSON.stringify(msgs, null, 2))

          t.deepEqual(msgs, {
            key: msg1.key, value: msg1.value,
            related: [
              msg2, msg3
            ],
            count: 2
          })
          t.end()
        })
      })
    })
  })

  tape('parent, no counts', function (t) {

    alice.add({
      type: 'post',
      text: 'hello, world 4'
    }, function (err, msg) {
      if(err) throw err
      console.log(msg)

      bob.add({
        type: 'post',
        text: 'welcome! 4',
        'parent': { msg: msg.key, rel: 'replies-to' }
      }, function (err, msg2) {
        if(err) throw err

        ssb.relatedMessages({id: msg.key, parent: true}, function (err, msgs) {

          console.log(JSON.stringify(msgs, null, 2))

          t.deepEqual(msgs, {
            key: msg.key, value: msg.value,
            related: [
              {key: msg2.key, value: msg2.value, parent: msg.key}
            ]
          })

          t.end()
        })
      })
    })
  })



}



if(!module.parent)
  module.exports(require('../defaults'))


{'fraction_non_alphanumeric': 0.1538860103626943, 'fraction_numerical': 0.008808290155440414, 'mean_word_length': 1.4778562259306804, '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': '1275252', 'n_tokens_mistral': 2603, 'n_tokens_neox': 2502, 'n_words': 579}