• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

proximax-storage / tsjs-xpx-chain-sdk / 5722694066

pending completion
5722694066

push

github

web-flow
Merge pull request #159 from proximax-storage/next

add storage transactions support

1167 of 2568 branches covered (45.44%)

Branch coverage included in aggregate %.

1604 of 1604 new or added lines in 66 files covered. (100.0%)

8621 of 11167 relevant lines covered (77.2%)

155987.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.47
/src/infrastructure/ReplicatorQueryParams.ts
1
/*
2
 * Copyright 2023 ProximaX
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
import { Order_v2 } from "./QueryParams";
1✔
18
import { UInt64 } from "../model/model";
1✔
19
import { PaginationQueryParams } from "./PaginationQueryParams";
1✔
20

21
export enum ReplicatorSortingField{
1✔
22

23
    ID = "id"
1✔
24
}
25

26
export class ReplicatorFieldOrder{
1✔
27

28
    constructor(public orderBy: ReplicatorSortingField | string, public order: Order_v2){
×
29
    }
30

31
    static setAscending(orderBy: ReplicatorSortingField | string){
32
        return new ReplicatorFieldOrder(orderBy, Order_v2.ASC);
×
33
    }
34

35
    static setDescending(orderBy: ReplicatorSortingField | string){
36
        return new ReplicatorFieldOrder(orderBy, Order_v2.DESC);
×
37
    }
38
}
39

40
export class ReplicatorQueryParams extends PaginationQueryParams{
1✔
41

42
    /**
43
    * Version of replicator.
44
    */
45
    version?: number;
46
    /**
47
    * From version of replicator.
48
    */
49
    fromVersion?: number;
50
    /**
51
    * To version of replicator.
52
    */
53
    toVersion?: number;
54
    /**
55
    * Storage size that the replicator provides.
56
    */
57
    capacity?: number | UInt64 | bigint;
58
    /**
59
    * From storage size that the replicator provides.
60
    */
61
    fromCapacity?: number | UInt64 | bigint;
62
    /**
63
    * To storage size that the replicator provides.
64
    */
65
    toCapacity?: number | UInt64 | bigint;
66
    offset?: string;
67
    orderBy?: string;
68
    order?: Order_v2;
69

70
    /**
71
     * Constructor
72
     */
73
    constructor() {
74
        super();
×
75
    }
76

77
    updateFieldOrder(replicatorFieldOrder: ReplicatorFieldOrder){
78
        this.orderBy = replicatorFieldOrder.orderBy;
×
79
        this.order = replicatorFieldOrder.order;
×
80
    }
81

82
    buildQueryParams(): object{
83
        let queryParams = Object.assign({}, this);
×
84

85
        ReplicatorQueryParams.adjustNonComplianceParams(queryParams);
×
86
        ReplicatorQueryParams.convertToPrimitiveType(queryParams);
×
87

88
        let flattenedQueryParams = super.buildQueryParams(queryParams);
×
89

90
        return flattenedQueryParams;
×
91
    }
92

93
    buildQueryParamsString(): string{
94
        let queryParams = this.buildQueryParams();
×
95

96
        const entries = Object.entries(queryParams);
×
97

98
        let queryParamsArray = entries.map(data=>{
×
99

100
            if(data[1] instanceof Array){
×
101
                return data[1].map(arrayData=>{
×
102
                    return data[0] + "[]" + "=" + arrayData
×
103
                }).join("&");
104
            }
105
            return data[0] + "=" + data[1]
×
106
        })
107

108
        return queryParamsArray.join("&")
×
109
    }
110

111
    static convertToPrimitiveType(queryParams: ReplicatorQueryParams){
112
        if(queryParams.capacity){
×
113
            if(queryParams.capacity instanceof UInt64){
×
114
                queryParams.capacity = queryParams.capacity.toBigInt();
×
115
            }
116
        }
117

118
        if(queryParams.toCapacity){
×
119
            if(queryParams.toCapacity instanceof UInt64){
×
120
                queryParams.toCapacity = queryParams.toCapacity.toBigInt();
×
121
            }
122
        }
123

124
        if(queryParams.fromCapacity){
×
125
            if(queryParams.fromCapacity instanceof UInt64){
×
126
                queryParams.fromCapacity = queryParams.fromCapacity.toBigInt();
×
127
            }
128
        }
129
    }
130

131
    static adjustNonComplianceParams(queryParams: ReplicatorQueryParams){
132
        if(queryParams.capacity){
×
133
            if(queryParams.toCapacity){
×
134
                delete queryParams.toCapacity;
×
135
            }
136

137
            if(queryParams.fromCapacity){
×
138
                delete queryParams.fromCapacity;
×
139
            }
140
        }
141

142
        if(queryParams.version){
×
143
            if(queryParams.toVersion){
×
144
                delete queryParams.toVersion;
×
145
            }
146

147
            if(queryParams.fromVersion){
×
148
                delete queryParams.fromVersion;
×
149
            }
150
        }
151

152
        if(queryParams.pageSize){
×
153
            if(queryParams.pageSize < 0){
×
154
                delete queryParams.pageSize; // default to 20
×
155
            } else if(queryParams.pageSize < 10){
×
156
                queryParams.pageSize = 10;
×
157
            } else if(queryParams.pageSize > 100){
×
158
                queryParams.pageSize = 100;
×
159
            }
160
        }
161

162
        if(queryParams.pageNumber){
×
163
            if(queryParams.pageNumber <= 0){
×
164
                queryParams.pageNumber = 1;
×
165
            }
166
        }
167
    }
168
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc