All files / qlobber/lib wrap_native.js

100% Statements 116/116
100% Branches 26/26
100% Functions 9/9
100% Lines 116/116

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 11715x 15x 15x 15x 15x 76x 76x 76x 76x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 76x 76x 28x 28x 28x 28x 28x 3835x 3835x 3835x 28x 28x 3807x 3807x 28x 76x 76x 2x 2x 2x 2x 2x 394x 394x 394x 2x 2x 392x 392x 2x 76x 76x 48x 48x 48x 48x 15550x 15550x 15550x 46x 46x 15504x 15504x 48x 76x 76x 32x 30x 30x 32x 15261x 15261x 15261x 30x 30x 15231x 15231x 32x 76x 76x 23x 23x 23x 23x 23x 23x 3003x 3003x 23x 23x 23x 76x 76x 7x 7x 7x 1011x 7x 7x 76x 76x 3x 3x 3x 588x 3x 3x 76x 76x 76x 76x 76x 76x 15x  
"use strict";
 
const util = require('util');
 
module.exports = function(QlobberNative, Qlobber)
{
    class WrappedQlobberNative extends QlobberNative
    {
        constructor(options) {
            super(options);
            this.addP = util.promisify(this.add_async);
            this.removeP = util.promisify(this.remove_async);
            this.matchP = util.promisify(this.match_async);
            this.testP = util.promisify(this.test_async);
            this.clearP = util.promisify(this.clear_async);
            this._get_visitorP = util.promisify(this.get_visitor_async);
            this._visit_nextP = util.promisify(this.visit_next_async);
            this._get_restorerP = util.promisify(this.get_restorer_async);
            this._restore_nextP = util.promisify(this.restore_next_async);
            this._match_iterP = util.promisify(this.match_iter_async);
            this._match_nextP = util.promisify(this.match_next_async);
        }
 
        *visit()
        {
            const visitor = this.get_visitor();
 
            while (true)
            {
                const v = this.visit_next(visitor);
                if (v === undefined)
                {
                    break;
                }
                yield v;
            }
        }
 
        async *visitP()
        {
            const visitor = await this._get_visitorP();
 
            while (true)
            {
                const v = await this._visit_nextP(visitor);
                if (v === undefined)
                {
                    break;
                }
                yield v;
            }
        }
 
        *match_iter(topic, ctx) {
            const iterator = super.match_iter(topic, ctx);
 
            while (true)
            {
                const v = this.match_next(iterator);
                if (v === undefined)
                {
                    break;
                }
                yield v.value;
            }
        }
 
        async *match_iterP(topic, ctx) {
            const iterator = await this._match_iterP(topic, ctx);
 
            while (true)
            {
                const v = await this._match_nextP(iterator);
                if (v === undefined)
                {
                    break;
                }
                yield v.value;
            }
        }
 
        get_trie()
        {
            const qlobber = new Qlobber(this.options);
            const restorer = qlobber.get_restorer();
 
            for (let v of this.visit())
            {
                restorer(v);
            }
 
            return qlobber.get_trie();
        }
 
        get_restorer(options)
        {
            const restorer = super.get_restorer(options);
            return obj => {
                super.restore_next(restorer, obj);
            };
        }
 
        async get_restorerP(options)
        {
            const restorer = await this._get_restorerP(options);
            return async obj => {
                await this._restore_nextP(restorer, obj);
            };
        }
    }
 
    WrappedQlobberNative.is_native = true;
    WrappedQlobberNative.nonNative = Qlobber;
 
    return WrappedQlobberNative;
};