@ama-sdk/core 12.3.0-prerelease.72 → 12.3.0-prerelease.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/fwk/param-deserialization.js +261 -0
- package/cjs/fwk/param-deserialization.spec.js +466 -0
- package/cjs/fwk/param-serialization.js +22 -6
- package/cjs/fwk/param-serialization.spec.js +200 -174
- package/esm2015/fwk/param-deserialization.js +253 -0
- package/esm2015/fwk/param-deserialization.spec.js +462 -0
- package/esm2015/fwk/param-serialization.js +10 -6
- package/esm2015/fwk/param-serialization.spec.js +200 -174
- package/package.json +6 -6
- package/src/fwk/param-deserialization.d.ts +34 -0
- package/src/fwk/param-deserialization.d.ts.map +1 -0
- package/src/fwk/param-deserialization.js +198 -0
- package/src/fwk/param-deserialization.js.map +1 -0
- package/src/fwk/param-serialization.d.ts +8 -0
- package/src/fwk/param-serialization.d.ts.map +1 -1
- package/src/fwk/param-serialization.js +12 -6
- package/src/fwk/param-serialization.js.map +1 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
deserializePathParams: function() {
|
|
13
|
+
return deserializePathParams;
|
|
14
|
+
},
|
|
15
|
+
deserializeQueryParams: function() {
|
|
16
|
+
return deserializeQueryParams;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var _paramserialization = require("./param-serialization");
|
|
20
|
+
function _array_like_to_array(arr, len) {
|
|
21
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
22
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
23
|
+
return arr2;
|
|
24
|
+
}
|
|
25
|
+
function _array_with_holes(arr) {
|
|
26
|
+
if (Array.isArray(arr)) return arr;
|
|
27
|
+
}
|
|
28
|
+
function _iterable_to_array_limit(arr, i) {
|
|
29
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
30
|
+
if (_i == null) return;
|
|
31
|
+
var _arr = [];
|
|
32
|
+
var _n = true;
|
|
33
|
+
var _d = false;
|
|
34
|
+
var _s, _e;
|
|
35
|
+
try {
|
|
36
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
37
|
+
_arr.push(_s.value);
|
|
38
|
+
if (i && _arr.length === i) break;
|
|
39
|
+
}
|
|
40
|
+
} catch (err) {
|
|
41
|
+
_d = true;
|
|
42
|
+
_e = err;
|
|
43
|
+
} finally{
|
|
44
|
+
try {
|
|
45
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
46
|
+
} finally{
|
|
47
|
+
if (_d) throw _e;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return _arr;
|
|
51
|
+
}
|
|
52
|
+
function _non_iterable_rest() {
|
|
53
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
54
|
+
}
|
|
55
|
+
function _sliced_to_array(arr, i) {
|
|
56
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
57
|
+
}
|
|
58
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
59
|
+
if (!o) return;
|
|
60
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
61
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
62
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
63
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
64
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Split parameter elements by delimiter based on the serialization style (with removal of the prefix)
|
|
68
|
+
* @param serializedParamValue serialized parameter value
|
|
69
|
+
* @param paramSerialization parameter serialization
|
|
70
|
+
*/ function splitParamElements(serializedParamValue, paramSerialization) {
|
|
71
|
+
switch(paramSerialization.style){
|
|
72
|
+
case 'simple':
|
|
73
|
+
{
|
|
74
|
+
return serializedParamValue.split(',').map(function(value) {
|
|
75
|
+
return decodeURIComponent(value);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
case 'label':
|
|
79
|
+
{
|
|
80
|
+
// NOTE: Path parameters of style label are prefixed with a '.'
|
|
81
|
+
return serializedParamValue.substring(1).split(paramSerialization.explode ? '.' : ',').map(function(value) {
|
|
82
|
+
return decodeURIComponent(value);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
case 'matrix':
|
|
86
|
+
{
|
|
87
|
+
// NOTE: Path parameters of style matrix and exploded true are written like this: ';paramName=value1;paramName=value2'
|
|
88
|
+
// NOTE: Path parameters of style matrix and exploded false are prefixed with a ';paramName=' and the values are separated by a ','
|
|
89
|
+
return paramSerialization.explode ? serializedParamValue.substring(1).split(';').map(function(value) {
|
|
90
|
+
return decodeURIComponent(value.split('=')[1]);
|
|
91
|
+
}) : serializedParamValue.split('=')[1].split(',').map(function(value) {
|
|
92
|
+
return decodeURIComponent(value);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
case 'form':
|
|
96
|
+
{
|
|
97
|
+
// NOTE: Query parameters of style form and explode true are written like this: 'paramName=value1¶mName=value2¶mName=value3'
|
|
98
|
+
// NOTE: Query parameters of style form and explode false are prefixed with the parameter name and delimited by a ','
|
|
99
|
+
return paramSerialization.explode ? serializedParamValue.split('&').map(function(value) {
|
|
100
|
+
return decodeURIComponent(value.split('=')[1]);
|
|
101
|
+
}) : serializedParamValue.split('=')[1].split(',').map(function(value) {
|
|
102
|
+
return decodeURIComponent(value);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
case 'spaceDelimited':
|
|
106
|
+
{
|
|
107
|
+
// NOTE: Query parameters of style spaceDelimited and explode false are prefixed with the parameter name and delimited by the encoded space character
|
|
108
|
+
// Here is an example of the format: 'paramName=value1%20value2%20value3'
|
|
109
|
+
return paramSerialization.explode ? undefined : serializedParamValue.split('=')[1].split(_paramserialization.SPACE_URL_CODE).map(function(value) {
|
|
110
|
+
return decodeURIComponent(value);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
case 'pipeDelimited':
|
|
114
|
+
{
|
|
115
|
+
// NOTE: Query parameters of style spaceDelimited and explode false are prefixed with the parameter name and delimited by the encoded pipe character
|
|
116
|
+
// Here is an example of the format: 'paramName=value1%7Cvalue2%7Cvalue3'
|
|
117
|
+
return paramSerialization.explode ? undefined : serializedParamValue.split('=')[1].split(_paramserialization.PIPE_URL_CODE).map(function(value) {
|
|
118
|
+
return decodeURIComponent(value);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Create object from pairwise array - every other item of the array is a key and the following item is the corresponding value
|
|
125
|
+
* @param splitObject
|
|
126
|
+
*/ function objectFromPairwiseArray(splitObject) {
|
|
127
|
+
return splitObject.reduce(function(obj, currentValue, index, array) {
|
|
128
|
+
// NOTE: Every other item of the array is a key and the following item is the corresponding value
|
|
129
|
+
if (index % 2 === 0) {
|
|
130
|
+
obj[decodeURIComponent(currentValue)] = decodeURIComponent(array[index + 1]);
|
|
131
|
+
}
|
|
132
|
+
return obj;
|
|
133
|
+
}, {});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Deserialize query parameters of type array
|
|
137
|
+
* OpenAPI Parameter Serialization {@link https://swagger.io/specification | documentation}
|
|
138
|
+
* @param serializedParamValue serialized query parameter value
|
|
139
|
+
* @param paramSerialization parameter serialization
|
|
140
|
+
*/ function deserializeArrayQueryParams(serializedParamValue, paramSerialization) {
|
|
141
|
+
return splitParamElements(serializedParamValue, paramSerialization);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Deserialize query parameters of type object
|
|
145
|
+
* OpenAPI Parameter Serialization {@link https://swagger.io/specification | documentation}
|
|
146
|
+
* @param serializedParamValue serialized query parameter value
|
|
147
|
+
* @param paramSerialization parameter serialization
|
|
148
|
+
*/ function deserializeObjectQueryParams(serializedParamValue, paramSerialization) {
|
|
149
|
+
// NOTE: Applies to the exploded styles 'form' and 'deepObject'
|
|
150
|
+
if (paramSerialization.explode && (paramSerialization.style === 'form' || paramSerialization.style === 'deepObject')) {
|
|
151
|
+
return serializedParamValue.split('&').reduce(function(obj, serializedProperty) {
|
|
152
|
+
var _serializedProperty_split = _sliced_to_array(serializedProperty.split('='), 2), key = _serializedProperty_split[0], value = _serializedProperty_split[1];
|
|
153
|
+
// NOTE: The key of an object in deepObject style is surrounded by opening and closing square brackets
|
|
154
|
+
var objKey = paramSerialization.style === 'deepObject' ? key.split(_paramserialization.OPENING_SQUARE_BRACKET_URL_CODE)[1].split(_paramserialization.CLOSING_SQUARE_BRACKET_URL_CODE)[0] : key;
|
|
155
|
+
obj[decodeURIComponent(objKey)] = decodeURIComponent(value);
|
|
156
|
+
return obj;
|
|
157
|
+
}, {});
|
|
158
|
+
}
|
|
159
|
+
// NOTE: Applies to the non-exploded styles 'form', 'spaceDelimited', and 'pipeDelimited'
|
|
160
|
+
if (paramSerialization.style !== 'deepObject' && !paramSerialization.explode) {
|
|
161
|
+
// NOTE: The splitParamElements function is called since object query parameters can be split by delimiters based on the serialization style
|
|
162
|
+
// NOTE: The deserialized value will exist since these exploded styles are supported
|
|
163
|
+
var splitObject = splitParamElements(serializedParamValue, paramSerialization);
|
|
164
|
+
return objectFromPairwiseArray(splitObject);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function deserializeQueryParams(serializedQueryParams, queryParamSerialization) {
|
|
168
|
+
return Object.entries(serializedQueryParams).reduce(function(acc, param) {
|
|
169
|
+
var _param = _sliced_to_array(param, 2), queryParamName = _param[0], serializedParamValue = _param[1];
|
|
170
|
+
var paramSerialization = queryParamSerialization[queryParamName];
|
|
171
|
+
var deserializedValue;
|
|
172
|
+
if (paramSerialization.paramType === 'array') {
|
|
173
|
+
deserializedValue = deserializeArrayQueryParams(serializedParamValue, paramSerialization);
|
|
174
|
+
} else if (paramSerialization.paramType === 'object') {
|
|
175
|
+
deserializedValue = deserializeObjectQueryParams(serializedParamValue, paramSerialization);
|
|
176
|
+
} else {
|
|
177
|
+
// NOTE: Query parameters of type primitive are prefixed with the parameter name like this: 'paramName=value'
|
|
178
|
+
deserializedValue = decodeURIComponent(serializedParamValue.split('=')[1]);
|
|
179
|
+
}
|
|
180
|
+
if (deserializedValue) {
|
|
181
|
+
acc[queryParamName] = deserializedValue;
|
|
182
|
+
} else {
|
|
183
|
+
throw new Error("Unable to deserialize query parameter ".concat(queryParamName, " since the combination explode=").concat(paramSerialization.explode, " and style='").concat(paramSerialization.style, "' is not supported."));
|
|
184
|
+
}
|
|
185
|
+
return acc;
|
|
186
|
+
}, {});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Deserialize path parameters of type primitive
|
|
190
|
+
* OpenAPI Parameter Serialization {@link https://swagger.io/specification | documentation}
|
|
191
|
+
* @param serializedParamValue serialized path parameter value
|
|
192
|
+
* @param paramSerialization parameter serialization
|
|
193
|
+
*/ function deserializePrimitivePathParams(serializedParamValue, paramSerialization) {
|
|
194
|
+
switch(paramSerialization.style){
|
|
195
|
+
case 'simple':
|
|
196
|
+
{
|
|
197
|
+
return decodeURIComponent(serializedParamValue);
|
|
198
|
+
}
|
|
199
|
+
case 'label':
|
|
200
|
+
{
|
|
201
|
+
// NOTE: Path parameters of style label are prefixed with a '.'
|
|
202
|
+
return decodeURIComponent(serializedParamValue.substring(1));
|
|
203
|
+
}
|
|
204
|
+
case 'matrix':
|
|
205
|
+
{
|
|
206
|
+
return decodeURIComponent(serializedParamValue.substring(1).split('=')[1]);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Deserialize path parameters of type array
|
|
212
|
+
* OpenAPI Parameter Serialization {@link https://swagger.io/specification | documentation}
|
|
213
|
+
* @param serializedParamValue serialized path parameter value
|
|
214
|
+
* @param paramSerialization parameter serialization
|
|
215
|
+
*/ function deserializeArrayPathParams(serializedParamValue, paramSerialization) {
|
|
216
|
+
return splitParamElements(serializedParamValue, paramSerialization);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Deserialize path parameters of type object
|
|
220
|
+
* OpenAPI Parameter Serialization {@link https://swagger.io/specification | documentation}
|
|
221
|
+
* @param serializedParamValue serialized path parameter value
|
|
222
|
+
* @param paramSerialization parameter serialization
|
|
223
|
+
*/ function deserializeObjectPathParams(serializedParamValue, paramSerialization) {
|
|
224
|
+
// NOTE: The splitParamElements function is called since object path parameters can be split by delimiters based on the serialization style
|
|
225
|
+
// NOTE: There is an exception for path parameters of exploded style 'matrix' which is not serialized like its corresponding array
|
|
226
|
+
// This exception is serialized like this (prefixed by a ';'): ';prop1=value1;prop2=value2'
|
|
227
|
+
var splitObject = paramSerialization.style === 'matrix' && paramSerialization.explode ? serializedParamValue.substring(1).split(';').map(function(value) {
|
|
228
|
+
return decodeURIComponent(value);
|
|
229
|
+
}) : splitParamElements(serializedParamValue, paramSerialization);
|
|
230
|
+
// NOTE: Object path parameters that are exploded are serialized as 'prop=value'
|
|
231
|
+
if (paramSerialization.explode) {
|
|
232
|
+
return splitObject.reduce(function(obj, serializedProperty) {
|
|
233
|
+
var _serializedProperty_split_map = _sliced_to_array(serializedProperty.split('=').map(function(v) {
|
|
234
|
+
return decodeURIComponent(v);
|
|
235
|
+
}), 2), key = _serializedProperty_split_map[0], value = _serializedProperty_split_map[1];
|
|
236
|
+
obj[key] = value;
|
|
237
|
+
return obj;
|
|
238
|
+
}, {});
|
|
239
|
+
}
|
|
240
|
+
return objectFromPairwiseArray(splitObject);
|
|
241
|
+
}
|
|
242
|
+
function deserializePathParams(serializedPathParams, pathParamSerialization) {
|
|
243
|
+
return Object.entries(serializedPathParams).reduce(function(acc, param) {
|
|
244
|
+
var _param = _sliced_to_array(param, 2), pathParamName = _param[0], serializedParamValue = _param[1];
|
|
245
|
+
var paramSerialization = pathParamSerialization[pathParamName];
|
|
246
|
+
var deserializedValue;
|
|
247
|
+
if (paramSerialization.paramType === 'array') {
|
|
248
|
+
deserializedValue = deserializeArrayPathParams(serializedParamValue, paramSerialization);
|
|
249
|
+
} else if (paramSerialization.paramType === 'object') {
|
|
250
|
+
deserializedValue = deserializeObjectPathParams(serializedParamValue, paramSerialization);
|
|
251
|
+
} else {
|
|
252
|
+
deserializedValue = deserializePrimitivePathParams(serializedParamValue, paramSerialization);
|
|
253
|
+
}
|
|
254
|
+
if (deserializedValue) {
|
|
255
|
+
acc[pathParamName] = deserializedValue;
|
|
256
|
+
} else {
|
|
257
|
+
throw new Error("Unable to deserialize path parameter ".concat(pathParamName, " since the combination explode=").concat(paramSerialization.explode, " and style='").concat(paramSerialization.style, "' is not supported."));
|
|
258
|
+
}
|
|
259
|
+
return acc;
|
|
260
|
+
}, {});
|
|
261
|
+
}
|