• 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

16.0
/src/infrastructure/StorageHttp.ts
1
// Copyright 2023 ProximaX Limited. All rights reserved.
2
// Use of this source code is governed by the Apache 2.0
3
// license that can be found in the LICENSE file
4

5
import { from as observableFrom, Observable } from 'rxjs';
1✔
6
import { map, mergeMap } from 'rxjs/operators';
1✔
7
import { StorageRoutesApi } from './api/apis';
1✔
8
import { NetworkHttp } from './NetworkHttp';
1✔
9
import { Http } from './Http';
1✔
10
import { StorageRepository } from './StorageRepository';
11
import { 
1✔
12
    DownloadChannel, DownloadChannelSearch, 
13
    DriveInfo, DriveInfoSearch, 
14
    Replicator, ReplicatorSearch,
15
    PublicAccount, Address
16
} from '../model/model';
17
import { RequestOptions } from './RequestOptions';
18
import { DriveQueryParams } from './DriveQueryParams';
19
import { DownloadChannelQueryParams } from './DownloadChannelQueryParams';
20
import { ReplicatorQueryParams } from './ReplicatorQueryParams';
21
import { Pagination } from '../model/Pagination';
1✔
22

23
/**
24
 * Storage http repository.
25
 *
26
 * @since 0.9.0
27
 */
28
export class StorageHttp extends Http implements StorageRepository {
1✔
29
    /**
30
     * @internal
31
     * xpx chain Library Storage routes api
32
     */
33
    private storageRoutesApi: StorageRoutesApi;
34

35
    /**
36
     * Constructor
37
     * @param url
38
     * @param networkHttp
39
     */
40
    constructor(url: string, networkHttp?: NetworkHttp) {
41
        networkHttp = networkHttp == null ? new NetworkHttp(url) : networkHttp;
×
42
        super(networkHttp);
×
43
        this.storageRoutesApi = new StorageRoutesApi(url);
×
44
    }
45

46

47
    /**
48
     * Get the drive for a given accountId
49
     * @param accountId - public key
50
     * @returns Observable<DriveInfo | undefined>
51
     */
52
    public getBcDrive(accountId: string | PublicAccount | Address, requestOptions?: RequestOptions): Observable<DriveInfo | undefined> {
53
        let accountIdArg: string = ""; 
×
54
        
55
        if(accountId instanceof PublicAccount){
×
56
            accountIdArg = accountId.publicKey;
×
57
        }else if(accountId instanceof Address){
×
58
            accountIdArg = accountId.plain();
×
59
        }else{
60
            accountIdArg = accountId;
×
61
        }
62

63
        return observableFrom(this.storageRoutesApi.getBcDrive(accountIdArg, requestOptions))
×
64
                    .pipe(map(response =>
65
                        DriveInfo.createFromDriveDTO(response.body.drive)
×
66
                        )
67
                    );
68
    }
69

70
    /**
71
     * Get Drives info with query params.
72
     * @param driveQueryParams - conditions of the drive info search 
73
     * @returns Observable<DriveInfoSearch>
74
     */
75
    public searchBcDrives(queryParams?: DriveQueryParams, requestOptions?: RequestOptions): Observable<DriveInfoSearch> {
76
        return observableFrom(this.storageRoutesApi.searchBcDrives(queryParams, requestOptions)).pipe(
×
77
            map((response) => {
78
                let driveInfos = response.body.data.map((driveInfoInlineDTO) => {
×
79
                    return DriveInfo.createFromDriveDTO(driveInfoInlineDTO.drive, driveInfoInlineDTO.meta.id);
×
80
                });
81
                let paginationData = new Pagination(
×
82
                    response.body.pagination.totalEntries, 
83
                    response.body.pagination.pageNumber,
84
                    response.body.pagination.pageSize,
85
                    response.body.pagination.totalPages
86
                );
87
                return new DriveInfoSearch(driveInfos, paginationData)
×
88
            })
89
        )
90
    }
91

92
    /**
93
     * Get the download channel
94
     * @param channelId - Download channel public key or address
95
     * @returns Observable<DownloadChannel | undefined>
96
     */
97
    public getDownloadChannel(channelId: string | PublicAccount, requestOptions?: RequestOptions): Observable<DownloadChannel | undefined> {
98
        const accountIdArg = (channelId instanceof PublicAccount) ? channelId.publicKey : channelId;
×
99
        return observableFrom(this.storageRoutesApi.getDownloadChannel(accountIdArg, requestOptions))
×
100
                    .pipe(map(response =>
101
                        DownloadChannel.createFromDownloadChannelInfoDTO(response.body.downloadChannelInfo)
×
102
                        )
103
                    );
104
    }
105

106
    /**
107
     * Get Download Channels info with query params.
108
     * @param downloadChannelQueryParams - conditions of the Download Channel info search 
109
     * @returns Observable<DownloadChannelSearch>
110
     */
111
    public searchDownloadChannels(queryParams?: DownloadChannelQueryParams, requestOptions?: RequestOptions): Observable<DownloadChannelSearch> {
112
        return observableFrom(this.storageRoutesApi.searchDownloadChannel(queryParams, requestOptions)).pipe(
×
113
            map((response) => {
114
                let downloadChannels = response.body.data.map((downloadChannelInlineDTO) => {
×
115
                    return DownloadChannel.createFromDownloadChannelInfoDTO(
×
116
                        downloadChannelInlineDTO.downloadChannelInfo,
117
                        downloadChannelInlineDTO.meta.id    
118
                    );
119
                });
120
                let paginationData = new Pagination(
×
121
                    response.body.pagination.totalEntries, 
122
                    response.body.pagination.pageNumber,
123
                    response.body.pagination.pageSize,
124
                    response.body.pagination.totalPages
125
                );
126
                return new DownloadChannelSearch(downloadChannels, paginationData)
×
127
            })
128
        )
129
    }
130

131
    /**
132
     * Gets the exchanges for a given accountId
133
     * @param accountId - Account public key or address
134
     * @returns Observable<Replicator | undefined>
135
     */
136
    public getReplicator(accountId: string | PublicAccount, requestOptions?: RequestOptions): Observable<Replicator | undefined> {
137
        const accountIdArg: string = accountId instanceof PublicAccount ? accountId.publicKey : accountId; 
×
138

139
        return observableFrom(this.storageRoutesApi.getReplicator(accountIdArg, requestOptions))
×
140
                    .pipe(map(response =>
141
                        Replicator.createFromReplicatorDTO(response.body.replicator)
×
142
                        )
143
                    );
144
    }
145

146
    /**
147
     * Get replicator info with query params.
148
     * @param replicatorQueryParams - conditions of the replicator info search 
149
     * @returns Observable<ReplicatorSearch>
150
     */
151
    public searchReplicators(queryParams?: ReplicatorQueryParams, requestOptions?: RequestOptions): Observable<ReplicatorSearch> {
152
        return observableFrom(this.storageRoutesApi.searchReplicators(queryParams, requestOptions)).pipe(
×
153
            map((response) => {
154
                let replicators = response.body.data.map((replicatorInlineDTO) => {
×
155
                    return Replicator.createFromReplicatorDTO(replicatorInlineDTO.replicator, replicatorInlineDTO.meta.id);
×
156
                });
157
                let paginationData = new Pagination(
×
158
                    response.body.pagination.totalEntries, 
159
                    response.body.pagination.pageNumber,
160
                    response.body.pagination.pageSize,
161
                    response.body.pagination.totalPages
162
                );
163
                return new ReplicatorSearch(replicators, paginationData)
×
164
            })
165
        )
166
    }
167
}
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