ibm-cloud-sdk-core
Advanced tools
Comparing version 4.0.9 to 4.1.0
@@ -36,3 +36,5 @@ <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
| [configureService(serviceName)](./ibm-cloud-sdk-core.baseservice.configureservice.md) | <code>protected</code> | Configure the service using external configuration | | ||
| [convertModel(input, converterFn, isMap)](./ibm-cloud-sdk-core.baseservice.convertmodel.md) | <code>static</code> | Applies a given modifier function on a model object. Since the model object can be a map, or an array, or a model, these types needs different handling. Considering whether the input object is a map happens with an explicit parameter. | | ||
| [createRequest(parameters)](./ibm-cloud-sdk-core.baseservice.createrequest.md) | <code>protected</code> | Wrapper around <code>sendRequest</code> that enforces the request will be authenticated. | | ||
| [createRequestAndDeserializeResponse(parameters, deserializerFn, isMap)](./ibm-cloud-sdk-core.baseservice.createrequestanddeserializeresponse.md) | <code>protected</code> | Wrapper around <code>createRequest</code> that enforces arrived response to be deserialized. | | ||
| [disableRetries()](./ibm-cloud-sdk-core.baseservice.disableretries.md) | | Disables retries. | | ||
@@ -39,0 +41,0 @@ | [enableRetries(retryOptions)](./ibm-cloud-sdk-core.baseservice.enableretries.md) | | Enable retries for unfulfilled requests. | |
@@ -0,1 +1,8 @@ | ||
# [4.1.0](https://github.com/IBM/node-sdk-core/compare/v4.0.9...v4.1.0) (2023-07-06) | ||
### Features | ||
* add logic for serializing/deserializing model objects ([#247](https://github.com/IBM/node-sdk-core/issues/247)) ([2397eae](https://github.com/IBM/node-sdk-core/commit/2397eaef56c247a2720396c7d1444b2331ae5a73)) | ||
## [4.0.9](https://github.com/IBM/node-sdk-core/compare/v4.0.8...v4.0.9) (2023-06-22) | ||
@@ -2,0 +9,0 @@ |
/** | ||
* (C) Copyright IBM Corp. 2014, 2022. | ||
* (C) Copyright IBM Corp. 2014, 2023. | ||
* | ||
@@ -117,2 +117,12 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
/** | ||
* Applies a given modifier function on a model object. | ||
* Since the model object can be a map, or an array, or a model, | ||
* these types needs different handling. | ||
* Considering whether the input object is a map happens with an explicit parameter. | ||
* @param input - the input model object | ||
* @param converterFn - the function that is applied on the input object | ||
* @param isMap - is `true` when the input object should be handled as a map | ||
*/ | ||
static convertModel(input: any, converterFn: any, isMap?: boolean): any; | ||
/** | ||
* Configure the service using external configuration | ||
@@ -146,3 +156,14 @@ * | ||
protected createRequest(parameters: any): Promise<any>; | ||
/** | ||
* Wrapper around `createRequest` that enforces arrived response to be deserialized. | ||
* @param parameters - see `parameters` in `createRequest` | ||
* @param deserializerFn - the deserializer function that is applied on the response object | ||
* @param isMap - is `true` when the response object should be handled as a map | ||
* @protected | ||
* @returns a Promise | ||
*/ | ||
protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>; | ||
private readOptionsFromExternalConfig; | ||
private static convertArray; | ||
private static convertMap; | ||
} |
/** | ||
* (C) Copyright IBM Corp. 2014, 2022. | ||
* (C) Copyright IBM Corp. 2014, 2023. | ||
* | ||
@@ -136,2 +136,24 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
/** | ||
* Applies a given modifier function on a model object. | ||
* Since the model object can be a map, or an array, or a model, | ||
* these types needs different handling. | ||
* Considering whether the input object is a map happens with an explicit parameter. | ||
* @param input - the input model object | ||
* @param converterFn - the function that is applied on the input object | ||
* @param isMap - is `true` when the input object should be handled as a map | ||
*/ | ||
static convertModel(input, converterFn, isMap) { | ||
if (input == null || typeof input === 'string') { | ||
// no need for conversation | ||
return input; | ||
} | ||
if (Array.isArray(input)) { | ||
return BaseService.convertArray(input, converterFn, isMap); | ||
} | ||
else if (isMap === true) { | ||
return BaseService.convertMap(input, converterFn); | ||
} | ||
return converterFn(input); | ||
} | ||
/** | ||
* Configure the service using external configuration | ||
@@ -183,2 +205,22 @@ * | ||
} | ||
/** | ||
* Wrapper around `createRequest` that enforces arrived response to be deserialized. | ||
* @param parameters - see `parameters` in `createRequest` | ||
* @param deserializerFn - the deserializer function that is applied on the response object | ||
* @param isMap - is `true` when the response object should be handled as a map | ||
* @protected | ||
* @returns a Promise | ||
*/ | ||
createRequestAndDeserializeResponse(parameters, deserializerFn, isMap) { | ||
return new Promise((resolve, reject) => { | ||
this.createRequest(parameters) | ||
.then((r) => { | ||
if (r !== undefined && r.result !== undefined) { | ||
r.result = BaseService.convertModel(r.result, deserializerFn, isMap); | ||
} | ||
resolve(r); | ||
}) | ||
.catch((err) => reject(err)); | ||
}); | ||
} | ||
// eslint-disable-next-line class-methods-use-this | ||
@@ -215,2 +257,16 @@ readOptionsFromExternalConfig(serviceName) { | ||
} | ||
static convertArray(arrayInput, converterFn, isMap) { | ||
const serializedList = []; | ||
arrayInput.forEach((element) => { | ||
serializedList.push(this.convertModel(element, converterFn, isMap)); | ||
}); | ||
return serializedList; | ||
} | ||
static convertMap(mapInput, converterFn) { | ||
const serializedMap = {}; | ||
Object.keys(mapInput).forEach((key) => { | ||
serializedMap[key] = BaseService.convertModel(mapInput[key], converterFn); | ||
}); | ||
return serializedMap; | ||
} | ||
} |
@@ -58,3 +58,5 @@ ## API Report File for "ibm-cloud-sdk-core" | ||
protected configureService(serviceName: string): void; | ||
static convertModel(input: any, converterFn: any, isMap?: boolean): any; | ||
protected createRequest(parameters: any): Promise<any>; | ||
protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>; | ||
// (undocumented) | ||
@@ -61,0 +63,0 @@ static DEFAULT_SERVICE_NAME: string; |
/** | ||
* (C) Copyright IBM Corp. 2014, 2022. | ||
* (C) Copyright IBM Corp. 2014, 2023. | ||
* | ||
@@ -117,2 +117,12 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
/** | ||
* Applies a given modifier function on a model object. | ||
* Since the model object can be a map, or an array, or a model, | ||
* these types needs different handling. | ||
* Considering whether the input object is a map happens with an explicit parameter. | ||
* @param input - the input model object | ||
* @param converterFn - the function that is applied on the input object | ||
* @param isMap - is `true` when the input object should be handled as a map | ||
*/ | ||
static convertModel(input: any, converterFn: any, isMap?: boolean): any; | ||
/** | ||
* Configure the service using external configuration | ||
@@ -146,3 +156,14 @@ * | ||
protected createRequest(parameters: any): Promise<any>; | ||
/** | ||
* Wrapper around `createRequest` that enforces arrived response to be deserialized. | ||
* @param parameters - see `parameters` in `createRequest` | ||
* @param deserializerFn - the deserializer function that is applied on the response object | ||
* @param isMap - is `true` when the response object should be handled as a map | ||
* @protected | ||
* @returns a Promise | ||
*/ | ||
protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>; | ||
private readOptionsFromExternalConfig; | ||
private static convertArray; | ||
private static convertMap; | ||
} |
"use strict"; | ||
/** | ||
* (C) Copyright IBM Corp. 2014, 2022. | ||
* (C) Copyright IBM Corp. 2014, 2023. | ||
* | ||
@@ -153,2 +153,24 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
/** | ||
* Applies a given modifier function on a model object. | ||
* Since the model object can be a map, or an array, or a model, | ||
* these types needs different handling. | ||
* Considering whether the input object is a map happens with an explicit parameter. | ||
* @param input - the input model object | ||
* @param converterFn - the function that is applied on the input object | ||
* @param isMap - is `true` when the input object should be handled as a map | ||
*/ | ||
BaseService.convertModel = function (input, converterFn, isMap) { | ||
if (input == null || typeof input === 'string') { | ||
// no need for conversation | ||
return input; | ||
} | ||
if (Array.isArray(input)) { | ||
return BaseService.convertArray(input, converterFn, isMap); | ||
} | ||
else if (isMap === true) { | ||
return BaseService.convertMap(input, converterFn); | ||
} | ||
return converterFn(input); | ||
}; | ||
/** | ||
* Configure the service using external configuration | ||
@@ -202,2 +224,23 @@ * | ||
}; | ||
/** | ||
* Wrapper around `createRequest` that enforces arrived response to be deserialized. | ||
* @param parameters - see `parameters` in `createRequest` | ||
* @param deserializerFn - the deserializer function that is applied on the response object | ||
* @param isMap - is `true` when the response object should be handled as a map | ||
* @protected | ||
* @returns a Promise | ||
*/ | ||
BaseService.prototype.createRequestAndDeserializeResponse = function (parameters, deserializerFn, isMap) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.createRequest(parameters) | ||
.then(function (r) { | ||
if (r !== undefined && r.result !== undefined) { | ||
r.result = BaseService.convertModel(r.result, deserializerFn, isMap); | ||
} | ||
resolve(r); | ||
}) | ||
.catch(function (err) { return reject(err); }); | ||
}); | ||
}; | ||
// eslint-disable-next-line class-methods-use-this | ||
@@ -234,4 +277,19 @@ BaseService.prototype.readOptionsFromExternalConfig = function (serviceName) { | ||
}; | ||
BaseService.convertArray = function (arrayInput, converterFn, isMap) { | ||
var _this = this; | ||
var serializedList = []; | ||
arrayInput.forEach(function (element) { | ||
serializedList.push(_this.convertModel(element, converterFn, isMap)); | ||
}); | ||
return serializedList; | ||
}; | ||
BaseService.convertMap = function (mapInput, converterFn) { | ||
var serializedMap = {}; | ||
Object.keys(mapInput).forEach(function (key) { | ||
serializedMap[key] = BaseService.convertModel(mapInput[key], converterFn); | ||
}); | ||
return serializedMap; | ||
}; | ||
return BaseService; | ||
}()); | ||
exports.BaseService = BaseService; |
{ | ||
"name": "ibm-cloud-sdk-core", | ||
"version": "4.0.9", | ||
"version": "4.1.0", | ||
"description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -58,3 +58,5 @@ ## API Report File for "ibm-cloud-sdk-core" | ||
protected configureService(serviceName: string): void; | ||
static convertModel(input: any, converterFn: any, isMap?: boolean): any; | ||
protected createRequest(parameters: any): Promise<any>; | ||
protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>; | ||
// (undocumented) | ||
@@ -61,0 +63,0 @@ static DEFAULT_SERVICE_NAME: string; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1525788
386
30650