# All files / dist/indexer-management/models indexing-rule.js

32.35% Statements 11/34
12.5% Branches 2/16
16.67% Functions 1/6
32.35% Lines 11/34

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
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147

    3x
    3x
    3x
    3x

    3x
    3x
    3x
    3x

    3x

    3x
    3x

     "use strict";
    /* eslint-disable @typescript-eslint/no-empty-interface */
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.defineIndexingRuleModels = exports.IndexingRule = exports.INDEXING_RULE_GLOBAL = exports.IndexingDecisionBasis = void 0;
    const sequelize_1 = require("sequelize");
    const ethers_1 = require("ethers");
    var IndexingDecisionBasis;
    (function (IndexingDecisionBasis) {
        IndexingDecisionBasis["RULES"] = "rules";
        IndexingDecisionBasis["NEVER"] = "never";
        IndexingDecisionBasis["ALWAYS"] = "always";
    })(IndexingDecisionBasis = exports.IndexingDecisionBasis || (exports.IndexingDecisionBasis = {}));
    exports.INDEXING_RULE_GLOBAL = 'global';
    class IndexingRule extends sequelize_1.Model {
        // eslint-disable-next-line @typescript-eslint/ban-types
        toGraphQL() {
            return Object.assign(Object.assign({}, this.toJSON()), { __typename: 'IndexingRule' });
        }
        // eslint-disable-next-line @typescript-eslint/ban-types
        mergeToGraphQL(global) {
            if (global instanceof IndexingRule) {
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                const globalRule = global.toJSON();
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                const rule = this.toJSON();
                for (const k in globalRule) {
                    if (null == rule[k]) {
                        rule[k] = globalRule[k];
                    }
                }
                for (const k in rule) {
                    if (rule[k] == undefined) {
                        rule[k] = globalRule[k];
                    }
                }
                return Object.assign(Object.assign({}, rule), { __typename: 'IndexingRule' });
            }
            else {
                return this.toGraphQL();
            }
        }
    }
    exports.IndexingRule = IndexingRule;
    exports.defineIndexingRuleModels = (sequelize) => {
        IndexingRule.init({
            id: {
                type: sequelize_1.DataTypes.INTEGER,
                autoIncrement: true,
                unique: true,
            },
            deployment: {
                type: sequelize_1.DataTypes.STRING,
                allowNull: true,
                primaryKey: true,
                validate: {
                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    isDeploymentID: (value) => {
                        if (typeof value !== 'string') {
                            throw new Error('Deployment ID must be a string');
                        }
                        // "global" is ok
                        if (value === 'global') {
                            return;
                        }
                        // "0x..." is ok
                        if (ethers_1.utils.isHexString(value, 32)) {
                            return;
                        }
                        throw new Error(`Deployment ID must be "global" or a valid subgraph deployment ID`);
                    },
                },
            },
            allocationAmount: {
                type: sequelize_1.DataTypes.DECIMAL,
                allowNull: true,
                validate: {
                    min: 0.0,
                },
            },
            parallelAllocations: {
                type: sequelize_1.DataTypes.INTEGER,
                allowNull: true,
                validate: {
                    min: 0,
                    max: 20,
                    emitDeprecationWarning: (value) => {
                        if (value > 1) {
                            throw new Error('Parallel allocations are soon to be fully deprecated. Please set parallel allocations to 1 for all your indexing rules');
                        }
                    },
                },
            },
            maxAllocationPercentage: {
                type: sequelize_1.DataTypes.FLOAT,
                allowNull: true,
                validate: {
                    isFloat: true,
                    min: 0.0,
                    max: 1.0,
                },
            },
            minSignal: {
                type: sequelize_1.DataTypes.DECIMAL,
                allowNull: true,
                validate: {
                    min: 0.0,
                },
            },
            minStake: {
                type: sequelize_1.DataTypes.DECIMAL,
                allowNull: true,
                validate: {
                    min: 0.0,
                },
            },
            maxSignal: {
                type: sequelize_1.DataTypes.DECIMAL,
                allowNull: true,
                validate: {
                    min: 0.0,
                },
            },
            minAverageQueryFees: {
                type: sequelize_1.DataTypes.DECIMAL,
                allowNull: true,
                validate: {
                    min: 0.0,
                },
            },
            custom: {
                type: sequelize_1.DataTypes.STRING,
                allowNull: true,
            },
            decisionBasis: {
                type: sequelize_1.DataTypes.ENUM('rules', 'never', 'always'),
                allowNull: false,
                defaultValue: 'rules',
            },
        }, {
            modelName: 'IndexingRule',
            sequelize,
        });
        return {
            ['IndexingRule']: IndexingRule,
        };
    };
    //# sourceMappingURL=indexing-rule.js.map