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

jumpinjackie / mapguide-react-layout / 15160437878

21 May 2025 11:00AM UTC coverage: 21.631% (-42.6%) from 64.24%
15160437878

Pull #1552

github

web-flow
Merge 8b7153d9e into 236e2ea07
Pull Request #1552: Feature/package updates 2505

839 of 1165 branches covered (72.02%)

11 of 151 new or added lines in 25 files covered. (7.28%)

1332 existing lines in 50 files now uncovered.

4794 of 22163 relevant lines covered (21.63%)

6.89 hits per line

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

22.47
/src/api/client.ts
1
import { MgError } from './error';
1✔
2
import { MapAgentRequestBuilder, isErrorResponse, serialize } from './builders/mapagent';
1✔
3
import { ClientKind } from './common';
4
import { createRequestBuilder } from './builders/factory';
1✔
5
import { ResourceBase, ResourceIdentifier, SiteVersionResponse } from './contracts/common';
6
import { ICreateRuntimeMapOptions, IMapGuideClient, RequestBuilder, IDescribeRuntimeMapOptions, IQueryMapFeaturesOptions } from './request-builder';
7
import { RuntimeMap } from './contracts/runtime-map';
8
import { QueryMapFeaturesResponse } from './contracts/query';
9

10
/**
11
 * The MapGuide HTTP client
12
 *
13
 * @export
14
 * @class Client
15
 * @implements {IMapGuideClient}
16
 */
17
export class Client implements IMapGuideClient {
1✔
18
    private builder: RequestBuilder;
19
    constructor(agentUri: string, kind: ClientKind) {
1✔
20
        this.builder = createRequestBuilder(agentUri, kind);
×
UNCOV
21
    }
×
22
    public async getText(url: string): Promise<string> {
1✔
23
        const r = await fetch(url);
×
24
        if (!r.ok)
×
25
            throw new MgError(r.statusText);
×
26
        const text = await r.text();
×
27
        return text;
×
UNCOV
28
    }
×
29

30
    /**
31
     * Performs a generic GET request at the specified URL
32
     *
33
     * @template T The type of the object you are expecting to receive
34
     * @param {string} url The url to make the request to
35
     * @returns {Promise<T>} A promise for the value of the requested type
36
     *
37
     * @memberOf Client
38
     */
39
    public get<T>(url: string): Promise<T> {
1✔
40
        return new Promise<T>((resolve, reject) => {
×
41
            fetch(url, {
×
UNCOV
42
                headers: {
×
UNCOV
43
                    'Accept': 'application/json',
×
UNCOV
44
                    'Content-Type': 'application/json'
×
UNCOV
45
                } as any,
×
UNCOV
46
                method: "GET"
×
UNCOV
47
            })
×
UNCOV
48
            .then(response => {
×
49
                if (isErrorResponse(response)) {
×
50
                    throw new MgError(response.statusText);
×
UNCOV
51
                } else {
×
52
                    resolve(response.json());
×
UNCOV
53
                }
×
UNCOV
54
            })
×
UNCOV
55
            .catch(reject);
×
UNCOV
56
        });
×
UNCOV
57
    }
×
58

59
    /**
60
     * Performs a generic POST request at the specified URL
61
     *
62
     * @template T The type of the object you are expecting to receive
63
     * @param {string} url The url to make the request to
64
     * @param {*} data The POST form data
65
     * @returns {Promise<T>} A promise for the value of the requested type
66
     *
67
     * @memberOf Client
68
     */
69
    public post<T>(url: string, data: any): Promise<T> {
1✔
70
        if (!data.format) {
×
71
            data.format = "application/json";
×
UNCOV
72
        }
×
73
        //const form = new FormData();
74
        //for (const key in data) {
75
        //    form.append(key.toUpperCase(), data[key]);
76
        //}
77
        return new Promise<T>((resolve, reject) => {
×
78
            fetch(url, {
×
UNCOV
79
                headers: {
×
UNCOV
80
                    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
×
UNCOV
81
                } as any,
×
UNCOV
82
                method: "POST",
×
UNCOV
83
                body: serialize(data) //form
×
UNCOV
84
            })
×
UNCOV
85
            .then(response => {
×
86
                if (isErrorResponse(response)) {
×
87
                    throw new MgError(response.statusText);
×
UNCOV
88
                } else {
×
89
                    resolve(response.json());
×
UNCOV
90
                }
×
UNCOV
91
            })
×
UNCOV
92
            .catch(reject);
×
UNCOV
93
        });
×
UNCOV
94
    }
×
95

96
    /**
97
     * Creates a new MapGuide session
98
     *
99
     * @param {string} username
100
     * @param {string} password
101
     * @returns {Promise<string>}
102
     *
103
     * @memberOf Client
104
     */
105
    public createSession(username: string, password: string): Promise<string> {
1✔
106
        return this.builder.createSession(username, password);
×
UNCOV
107
    }
×
108

109
    /**
110
     * Gets the server session timeout for the given session id
111
     *
112
     * @param {string} session
113
     * @returns {Promise<number>}
114
     *
115
     * @memberOf Client
116
     */
117
    public getServerSessionTimeout(session: string): Promise<number> {
1✔
118
        return this.builder.getServerSessionTimeout(session);
×
UNCOV
119
    }
×
120

121
    /**
122
     * gets the MapGuide Server version
123
     * 
124
     * @since 0.14
125
     */
126
    public getSiteVersion(): Promise<SiteVersionResponse> {
1✔
127
        return this.builder.getSiteVersion();
×
UNCOV
128
    }
×
129

130
    /**
131
     * Retrieves the requested resource
132
     *
133
     * @template T
134
     * @param {ResourceIdentifier} resourceId
135
     * @param {*} [args]
136
     * @returns {Promise<T>}
137
     *
138
     * @memberOf Client
139
     */
140
    public getResource<T extends ResourceBase>(resourceId: ResourceIdentifier, args?: any): Promise<T> {
1✔
141
        return this.builder.getResource<T>(resourceId, args);
×
UNCOV
142
    }
×
143

144
    /**
145
     * Creates a runtime map from the specified map definition. Issues a v3.0.0 request
146
     *
147
     * @param {ICreateRuntimeMapOptions} options
148
     * @returns {Promise<RuntimeMap>}
149
     *
150
     * @memberOf Client
151
     */
152
    public createRuntimeMap(options: ICreateRuntimeMapOptions): Promise<RuntimeMap> {
1✔
153
        return this.builder.createRuntimeMap(options);
×
UNCOV
154
    }
×
155

156
    /**
157
     * Creates a runtime map from the specified map definition. Issues a v4.0.0 request
158
     *
159
     * @param {ICreateRuntimeMapOptions} options
160
     * @returns {Promise<RuntimeMap>}
161
     *
162
     * @memberOf Client
163
     * @since 0.14.8
164
     */
165
    public createRuntimeMap_v4(options: ICreateRuntimeMapOptions): Promise<RuntimeMap> {
1✔
166
        return this.builder.createRuntimeMap_v4(options);
×
UNCOV
167
    }
×
168

169
    /**
170
     * Describes a runtime map. Issues a v3.0.0 request
171
     *
172
     * @param {IDescribeRuntimeMapOptions} options
173
     * @returns {Promise<RuntimeMap>}
174
     *
175
     * @memberOf Client
176
     */
177
    public describeRuntimeMap(options: IDescribeRuntimeMapOptions): Promise<RuntimeMap> {
1✔
178
        return this.builder.describeRuntimeMap(options);
×
UNCOV
179
    }
×
180

181
    /**
182
     * Describes a runtime map. Issues a v4.0.0 request
183
     *
184
     * @param {IDescribeRuntimeMapOptions} options
185
     * @returns {Promise<RuntimeMap>}
186
     *
187
     * @memberOf Client
188
     * @since 0.14.8
189
     */
190
    public describeRuntimeMap_v4(options: IDescribeRuntimeMapOptions): Promise<RuntimeMap> {
1✔
191
        return this.builder.describeRuntimeMap_v4(options);
×
UNCOV
192
    }
×
193

194
    /**
195
     * Performs a map selection query on the current map
196
     *
197
     * @param {IQueryMapFeaturesOptions} options
198
     * @returns {Promise<QueryMapFeaturesResponse>}
199
     *
200
     * @memberOf Client
201
     */
202
    public queryMapFeatures(options: IQueryMapFeaturesOptions): Promise<QueryMapFeaturesResponse> {
1✔
203
        return this.builder.queryMapFeatures(options);
×
UNCOV
204
    }
×
205

206
    /**
207
     * Performs a map selection query on the current map. Only applicable for use in MapGuide Open Source
208
     * 4.0 and higher
209
     *
210
     * @param {IQueryMapFeaturesOptions} options
211
     * @returns {Promise<QueryMapFeaturesResponse>}
212
     *
213
     * @memberOf Client
214
     */
215
    public queryMapFeatures_v4(options: IQueryMapFeaturesOptions): Promise<QueryMapFeaturesResponse> {
1✔
216
        return this.builder.queryMapFeatures_v4(options);
×
UNCOV
217
    }
×
218

219
    /**
220
     * Gets the tile template URL used by the viewer to send tile requests
221
     *
222
     * @param {string} resourceId
223
     * @param {string} groupName
224
     * @param {string} xPlaceholder
225
     * @param {string} yPlaceholder
226
     * @param {string} zPlaceholder
227
     * @returns {string}
228
     *
229
     * @memberOf Client
230
     * @since 0.14.8 added isXYZ parameter
231
     */
232
    public getTileTemplateUrl(resourceId: string, groupName: string, xPlaceholder: string, yPlaceholder: string, zPlaceholder: string, isXYZ: boolean): string {
1✔
233
        return this.builder.getTileTemplateUrl(resourceId, groupName, xPlaceholder, yPlaceholder, zPlaceholder, isXYZ);
×
UNCOV
234
    }
×
235
}
1✔
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

© 2026 Coveralls, Inc