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

jumpinjackie / mapguide-react-layout / 15165370206

21 May 2025 02:48PM UTC coverage: 22.447%. Remained the same
15165370206

push

github

jumpinjackie
#1555: More internalization of things that shouldn't be in the API documentation.

Also dd merge-modules plugin for typedoc which flattens our public symbol list, which makes better sense as our node module usage story is to import from a flat barrel "mapguide-react-layout" module.

878 of 1206 branches covered (72.8%)

4975 of 22163 relevant lines covered (22.45%)

6.95 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
 * @class Client
14
 */
15
export class Client implements IMapGuideClient {
1✔
16
    private builder: RequestBuilder;
17
    constructor(agentUri: string, kind: ClientKind) {
1✔
18
        this.builder = createRequestBuilder(agentUri, kind);
×
19
    }
×
20
    public async getText(url: string): Promise<string> {
1✔
21
        const r = await fetch(url);
×
22
        if (!r.ok)
×
23
            throw new MgError(r.statusText);
×
24
        const text = await r.text();
×
25
        return text;
×
26
    }
×
27

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

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

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

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

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

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

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

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

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

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

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

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

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