UNPKG

1.56 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Microsoft. All rights reserved.
3// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4Object.defineProperty(exports, "__esModule", { value: true });
5exports.ClientApiBase = void 0;
6const vsom = require("./VsoClient");
7const serm = require("./Serialization");
8const rm = require("typed-rest-client/RestClient");
9const hm = require("typed-rest-client/HttpClient");
10class ClientApiBase {
11 constructor(baseUrl, handlers, userAgent, options) {
12 this.baseUrl = baseUrl;
13 this.http = new hm.HttpClient(userAgent, handlers, options);
14 this.rest = new rm.RestClient(userAgent, null, handlers, options);
15 this.vsoClient = new vsom.VsoClient(baseUrl, this.rest);
16 this.userAgent = userAgent;
17 }
18 createAcceptHeader(type, apiVersion) {
19 return type + (apiVersion ? (';api-version=' + apiVersion) : '');
20 }
21 createRequestOptions(type, apiVersion) {
22 let options = {};
23 options.acceptHeader = this.createAcceptHeader(type, apiVersion);
24 return options;
25 }
26 formatResponse(data, responseTypeMetadata, isCollection) {
27 let serializationData = {
28 responseTypeMetadata: responseTypeMetadata,
29 responseIsCollection: isCollection
30 };
31 let deserializedResult = serm.ContractSerializer.deserialize(data, serializationData.responseTypeMetadata, false, serializationData.responseIsCollection);
32 return deserializedResult;
33 }
34}
35exports.ClientApiBase = ClientApiBase;