• 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

6.41
/src/infrastructure/DriveQueryParams.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 { PublicAccount } from "../model/account/PublicAccount";
1✔
18
import { Address } from "../model/account/Address";
19
import { Order_v2 } from "./QueryParams";
1✔
20
import { UInt64 } from "../model/model";
1✔
21
import { MosaicId, NamespaceId } from "../model/model";
22
import { PaginationQueryParams } from "./PaginationQueryParams";
1✔
23

24
export enum DriveSortingField{
1✔
25

26
    ID = "id"
1✔
27
}
28

29
export class DriveFieldOrder{
1✔
30

31
    constructor(public orderBy: DriveSortingField | string, public order: Order_v2){
×
32
    }
33

34
    static setAscending(orderBy: DriveSortingField | string){
35
        return new DriveFieldOrder(orderBy, Order_v2.ASC);
×
36
    }
37

38
    static setDescending(orderBy: DriveSortingField | string){
39
        return new DriveFieldOrder(orderBy, Order_v2.DESC);
×
40
    }
41
}
42

43
export class DriveQueryParams extends PaginationQueryParams{
1✔
44

45
    /**
46
    * Size of drive (MB).
47
    */
48
    size?: number | UInt64 | bigint;
49
    /**
50
    * From size of drive (MB).
51
    */
52
    fromSize?: number | UInt64 | bigint;
53
    /**
54
    * To size of drive (MB).
55
    */
56
    toSize?: number | UInt64 | bigint;
57
    /**
58
    * Used size of drive.
59
    */
60
    usedSize?: number | UInt64 | bigint;
61
    /**
62
    * From used size of drive.
63
    */
64
    fromUsedSize?: number | UInt64 | bigint;
65
    /**
66
    * To used size of drive.
67
    */
68
    toUsedSize?: number | UInt64 | bigint;
69
    /**
70
     * Meta file size of drive.
71
    */
72
    metaFilesSize?: number | UInt64 | bigint;
73
    /**
74
     * From meta file size of drive.
75
    */
76
    fromMetaFilesSize?: number | UInt64 | bigint;
77
    /**
78
     * To meta file size of drive.
79
    */
80
    toMetaFilesSize?: number | UInt64 | bigint;
81
    /**
82
     * Number of replicators.
83
    */
84
    replicatorCount?: number;
85
    /**
86
     * From number of replicators.
87
    */
88
    fromReplicatorCount?: number;
89
    /**
90
     * To number of replicators.
91
    */
92
    toReplicatorCount?: number;
93
    /**
94
     * Public key of an Owner.
95
     */
96
    owner?: string | PublicAccount; 
97

98
    order?: Order_v2;
99
    orderBy?: string;
100
    offset?: string;
101

102
    /**
103
     * Constructor
104
     */
105
    constructor() {
106
        super();
×
107
    }
108

109
    updateFieldOrder(DriveFieldOrder: DriveFieldOrder){
110
        this.orderBy = DriveFieldOrder.orderBy;
×
111
        this.order = DriveFieldOrder.order;
×
112
    }
113

114
    buildQueryParams(): object{
115
        let queryParams = Object.assign({}, this);
×
116

117
        DriveQueryParams.adjustNonComplianceParams(queryParams);
×
118
        DriveQueryParams.convertToPrimitiveType(queryParams);
×
119

120
        let flattenedQueryParams = super.buildQueryParams(queryParams);
×
121

122
        return flattenedQueryParams;
×
123
    }
124

125
    buildQueryParamsString(): string{
126
        let queryParams = this.buildQueryParams();
×
127

128
        const entries = Object.entries(queryParams);
×
129

130
        let queryParamsArray = entries.map(data=>{
×
131

132
            if(data[1] instanceof Array){
×
133
                return data[1].map(arrayData=>{
×
134
                    return data[0] + "[]" + "=" + arrayData
×
135
                }).join("&");
136
            }
137
            return data[0] + "=" + data[1]
×
138
        })
139

140
        return queryParamsArray.join("&")
×
141
    }
142

143
    static convertToPrimitiveType(queryParams: DriveQueryParams){
144
        if(queryParams.size){
×
145
            if(queryParams.size instanceof UInt64){
×
146
                queryParams.size = queryParams.size.toBigInt();
×
147
            }
148
        }
149

150
        if(queryParams.fromSize){
×
151
            if(queryParams.fromSize instanceof UInt64){
×
152
                queryParams.fromSize = queryParams.fromSize.toBigInt();
×
153
            }
154
        }
155

156
        if(queryParams.toSize){
×
157
            if(queryParams.toSize instanceof UInt64){
×
158
                queryParams.toSize = queryParams.toSize.toBigInt();
×
159
            }
160
        }
161

162
        if(queryParams.usedSize){
×
163
            if(queryParams.usedSize instanceof UInt64){
×
164
                queryParams.usedSize = queryParams.usedSize.toBigInt();
×
165
            }
166
        }
167

168
        if(queryParams.fromUsedSize){
×
169
            if(queryParams.fromUsedSize instanceof UInt64){
×
170
                queryParams.fromUsedSize = queryParams.fromUsedSize.toBigInt();
×
171
            }
172
        }
173

174
        if(queryParams.toUsedSize){
×
175
            if(queryParams.toUsedSize instanceof UInt64){
×
176
                queryParams.toSize = queryParams.toUsedSize.toBigInt();
×
177
            }
178
        }
179

180
        if(queryParams.metaFilesSize){
×
181
            if(queryParams.metaFilesSize instanceof UInt64){
×
182
                queryParams.metaFilesSize = queryParams.metaFilesSize.toBigInt();
×
183
            }
184
        }
185

186
        if(queryParams.fromMetaFilesSize){
×
187
            if(queryParams.fromMetaFilesSize instanceof UInt64){
×
188
                queryParams.fromMetaFilesSize = queryParams.fromMetaFilesSize.toBigInt();
×
189
            }
190
        }
191

192
        if(queryParams.toMetaFilesSize){
×
193
            if(queryParams.toMetaFilesSize instanceof UInt64){
×
194
                queryParams.toMetaFilesSize = queryParams.toMetaFilesSize.toBigInt();
×
195
            }
196
        }
197

198
        if(queryParams.owner){
×
199
            if(queryParams.owner instanceof PublicAccount){
×
200
                queryParams.owner = queryParams.owner.publicKey;
×
201
            }
202
        }
203
    }
204

205
    static adjustNonComplianceParams(queryParams: DriveQueryParams){
206
        if(queryParams.size){
×
207
            if(queryParams.fromSize){
×
208
                delete queryParams.fromSize;
×
209
            }
210

211
            if(queryParams.toSize){
×
212
                delete queryParams.toSize;
×
213
            }
214
        }
215

216
        if(queryParams.usedSize){
×
217
            if(queryParams.fromUsedSize){
×
218
                delete queryParams.fromUsedSize;
×
219
            }
220

221
            if(queryParams.toUsedSize){
×
222
                delete queryParams.toUsedSize;
×
223
            }
224
        }
225

226
        if(queryParams.metaFilesSize){
×
227
            if(queryParams.fromMetaFilesSize){
×
228
                delete queryParams.fromMetaFilesSize;
×
229
            }
230

231
            if(queryParams.toMetaFilesSize){
×
232
                delete queryParams.toMetaFilesSize;
×
233
            }
234
        }
235

236
        if(queryParams.pageSize){
×
237
            if(queryParams.pageSize < 0){
×
238
                delete queryParams.pageSize; // default to 20
×
239
            } else if(queryParams.pageSize < 10){
×
240
                queryParams.pageSize = 10;
×
241
            } else if(queryParams.pageSize > 100){
×
242
                queryParams.pageSize = 100;
×
243
            }
244
        }
245

246
        if(queryParams.pageNumber){
×
247
            if(queryParams.pageNumber <= 0){
×
248
                queryParams.pageNumber = 1;
×
249
            }
250
        }
251
    }
252
}
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