@leonardo-ai/sdk 1.3.5 → 1.7.4
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/README.md +8 -4
- package/dist/internal/utils/headers.js +4 -4
- package/dist/internal/utils/pathparams.d.ts +1 -8
- package/dist/internal/utils/pathparams.js +11 -18
- package/dist/internal/utils/queryparams.d.ts +1 -2
- package/dist/internal/utils/queryparams.js +100 -50
- package/dist/internal/utils/requestbody.js +90 -57
- package/dist/internal/utils/security.js +69 -57
- package/dist/internal/utils/utils.d.ts +11 -2
- package/dist/internal/utils/utils.js +51 -15
- package/dist/sdk/dataset.js +11 -10
- package/dist/sdk/generation.js +11 -11
- package/dist/sdk/initimage.js +7 -6
- package/dist/sdk/model.js +7 -6
- package/dist/sdk/models/operations/createdataset.d.ts +2 -0
- package/dist/sdk/models/operations/createdataset.js +14 -4
- package/dist/sdk/models/operations/creategeneration.d.ts +2 -0
- package/dist/sdk/models/operations/creategeneration.js +42 -18
- package/dist/sdk/models/operations/createmodel.d.ts +2 -0
- package/dist/sdk/models/operations/createmodel.js +28 -11
- package/dist/sdk/models/operations/createvariationupscale.d.ts +2 -0
- package/dist/sdk/models/operations/createvariationupscale.js +12 -3
- package/dist/sdk/models/operations/deletedatasetbyid.d.ts +2 -0
- package/dist/sdk/models/operations/deletedatasetbyid.js +10 -2
- package/dist/sdk/models/operations/deletegenerationbyid.d.ts +2 -0
- package/dist/sdk/models/operations/deletegenerationbyid.js +10 -2
- package/dist/sdk/models/operations/deleteinitimagebyid.d.ts +2 -0
- package/dist/sdk/models/operations/deleteinitimagebyid.js +10 -2
- package/dist/sdk/models/operations/deletemodelbyid.d.ts +2 -0
- package/dist/sdk/models/operations/deletemodelbyid.js +10 -2
- package/dist/sdk/models/operations/getdatasetbyid.d.ts +2 -0
- package/dist/sdk/models/operations/getdatasetbyid.js +27 -10
- package/dist/sdk/models/operations/getgenerationbyid.d.ts +2 -0
- package/dist/sdk/models/operations/getgenerationbyid.js +60 -26
- package/dist/sdk/models/operations/getgenerationsbyuserid.d.ts +2 -0
- package/dist/sdk/models/operations/getgenerationsbyuserid.js +60 -26
- package/dist/sdk/models/operations/getinitimagebyid.d.ts +2 -0
- package/dist/sdk/models/operations/getinitimagebyid.js +14 -4
- package/dist/sdk/models/operations/getmodelbyid.d.ts +2 -0
- package/dist/sdk/models/operations/getmodelbyid.js +32 -13
- package/dist/sdk/models/operations/getuserself.d.ts +2 -0
- package/dist/sdk/models/operations/getuserself.js +17 -5
- package/dist/sdk/models/operations/getvariationbyid.d.ts +2 -0
- package/dist/sdk/models/operations/getvariationbyid.js +18 -6
- package/dist/sdk/models/operations/uploaddatasetimage.d.ts +2 -0
- package/dist/sdk/models/operations/uploaddatasetimage.js +18 -6
- package/dist/sdk/models/operations/uploaddatasetimagefromgen.d.ts +2 -0
- package/dist/sdk/models/operations/uploaddatasetimagefromgen.js +12 -3
- package/dist/sdk/models/operations/uploadinitimage.d.ts +2 -0
- package/dist/sdk/models/operations/uploadinitimage.js +20 -7
- package/dist/sdk/sdk.d.ts +2 -2
- package/dist/sdk/sdk.js +5 -4
- package/dist/sdk/user.js +4 -2
- package/dist/sdk/variation.js +5 -4
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -30,17 +30,21 @@ To get access to the API and fetch an API key, please sign up for [access](https
|
|
|
30
30
|
## SDK Example Usage
|
|
31
31
|
<!-- Start SDK Example Usage -->
|
|
32
32
|
```typescript
|
|
33
|
-
import {
|
|
34
|
-
|
|
33
|
+
import {
|
|
34
|
+
CreateDatasetRequest,
|
|
35
|
+
CreateDatasetResponse
|
|
36
|
+
} from "@leonardo-ai/sdk/dist/sdk/models/operations";
|
|
37
|
+
|
|
35
38
|
import { AxiosError } from "axios";
|
|
39
|
+
import { Leonardo } from "@leonardo-ai/sdk";
|
|
36
40
|
|
|
37
|
-
const sdk = new Leonardo(
|
|
41
|
+
const sdk = new Leonardo({
|
|
38
42
|
security: {
|
|
39
43
|
bearerAuth: {
|
|
40
44
|
authorization: "Bearer YOUR_BEARER_TOKEN_HERE",
|
|
41
45
|
},
|
|
42
46
|
}
|
|
43
|
-
)
|
|
47
|
+
});
|
|
44
48
|
|
|
45
49
|
const req: CreateDatasetRequest = {
|
|
46
50
|
request: {
|
|
@@ -15,7 +15,7 @@ function getHeadersFromRequest(headerParams) {
|
|
|
15
15
|
var headerDecorator = (0, utils_1.parseParamDecorator)(headerAnn, fname, "simple", false);
|
|
16
16
|
if (headerDecorator == null)
|
|
17
17
|
return;
|
|
18
|
-
var value = serializeHeader(headerParams[fname], headerDecorator.Explode);
|
|
18
|
+
var value = serializeHeader(headerParams[fname], headerDecorator.Explode, headerDecorator.DateTimeFormat);
|
|
19
19
|
if (value != "")
|
|
20
20
|
headers[headerDecorator.ParamName] = value;
|
|
21
21
|
});
|
|
@@ -44,11 +44,11 @@ function getHeadersFromResponse(headers) {
|
|
|
44
44
|
return reponseHeaders;
|
|
45
45
|
}
|
|
46
46
|
exports.getHeadersFromResponse = getHeadersFromResponse;
|
|
47
|
-
function serializeHeader(header, explode) {
|
|
47
|
+
function serializeHeader(header, explode, dateTimeFormat) {
|
|
48
48
|
var headerVals = [];
|
|
49
49
|
if (Array.isArray(header)) {
|
|
50
50
|
header.forEach(function (val) {
|
|
51
|
-
headerVals.push(
|
|
51
|
+
headerVals.push((0, utils_1.convertIfDateObjectToISOString)(val, dateTimeFormat));
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
else if ((0, utils_1.isStringRecord)(header) ||
|
|
@@ -69,7 +69,7 @@ function serializeHeader(header, explode) {
|
|
|
69
69
|
var headerDecorator = (0, utils_1.parseParamDecorator)(headerAnn, headerKey, "simple", explode);
|
|
70
70
|
if (headerDecorator == null)
|
|
71
71
|
return;
|
|
72
|
-
var headerFieldValue = header[headerKey];
|
|
72
|
+
var headerFieldValue = (0, utils_1.convertIfDateObjectToISOString)(header[headerKey], headerDecorator.DateTimeFormat);
|
|
73
73
|
if ((0, utils_1.isEmpty)(headerFieldValue))
|
|
74
74
|
return;
|
|
75
75
|
else if (explode)
|
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
export declare const ppMetadataKey = "pathParam";
|
|
2
|
-
export declare function getSimplePathParams(paramName: string, paramValue: any, explode: boolean): Map<string, string>;
|
|
3
|
-
export declare class ParamDecorator {
|
|
4
|
-
Style: string;
|
|
5
|
-
Explode: boolean;
|
|
6
|
-
ParamName: string;
|
|
7
|
-
Serialization?: string;
|
|
8
|
-
constructor(Style: string, Explode: boolean, ParamName: string, Serialization?: string);
|
|
9
|
-
}
|
|
2
|
+
export declare function getSimplePathParams(paramName: string, paramValue: any, explode: boolean, dateTimeFormat?: string): Map<string, string>;
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getSimplePathParams = exports.ppMetadataKey = void 0;
|
|
4
4
|
var utils_1 = require("./utils");
|
|
5
5
|
var utils_2 = require("./utils");
|
|
6
6
|
exports.ppMetadataKey = "pathParam";
|
|
7
|
-
function getSimplePathParams(paramName, paramValue, explode) {
|
|
7
|
+
function getSimplePathParams(paramName, paramValue, explode, dateTimeFormat) {
|
|
8
8
|
var pathParams = new Map();
|
|
9
9
|
var ppVals = [];
|
|
10
10
|
if (Array.isArray(paramValue)) {
|
|
11
11
|
paramValue.forEach(function (param) {
|
|
12
|
-
ppVals.push(
|
|
12
|
+
ppVals.push((0, utils_1.encodeAndConvertPrimitiveVal)(param, dateTimeFormat));
|
|
13
13
|
});
|
|
14
14
|
pathParams.set(paramName, ppVals.join(","));
|
|
15
15
|
}
|
|
16
|
-
else if ((0, utils_2.isStringRecord)(paramValue) ||
|
|
16
|
+
else if ((0, utils_2.isStringRecord)(paramValue) ||
|
|
17
|
+
(0, utils_2.isNumberRecord)(paramValue) ||
|
|
18
|
+
(0, utils_2.isBooleanRecord)(paramValue)) {
|
|
17
19
|
Object.getOwnPropertyNames(paramValue).forEach(function (paramKey) {
|
|
20
|
+
var paramFieldValue = (0, utils_1.encodeAndConvertPrimitiveVal)(paramValue[paramKey], dateTimeFormat);
|
|
18
21
|
if (explode)
|
|
19
|
-
ppVals.push("".concat(paramKey, "=").concat(
|
|
22
|
+
ppVals.push("".concat(paramKey, "=").concat(paramFieldValue));
|
|
20
23
|
else
|
|
21
|
-
ppVals.push("".concat(paramKey, ",").concat(
|
|
24
|
+
ppVals.push("".concat(paramKey, ",").concat(paramFieldValue));
|
|
22
25
|
});
|
|
23
26
|
pathParams.set(paramName, ppVals.join(","));
|
|
24
27
|
}
|
|
@@ -30,7 +33,7 @@ function getSimplePathParams(paramName, paramValue, explode) {
|
|
|
30
33
|
var ppDecorator = (0, utils_1.parseParamDecorator)(ppAnn, paramKey, "simple", explode);
|
|
31
34
|
if (ppDecorator == null)
|
|
32
35
|
return;
|
|
33
|
-
var paramFieldValue = paramValue[paramKey];
|
|
36
|
+
var paramFieldValue = (0, utils_1.encodeAndConvertPrimitiveVal)(paramValue[paramKey], ppDecorator.DateTimeFormat);
|
|
34
37
|
if ((0, utils_2.isEmpty)(paramFieldValue))
|
|
35
38
|
return;
|
|
36
39
|
else if (explode)
|
|
@@ -41,18 +44,8 @@ function getSimplePathParams(paramName, paramValue, explode) {
|
|
|
41
44
|
pathParams.set(paramName, ppVals.join(","));
|
|
42
45
|
}
|
|
43
46
|
else {
|
|
44
|
-
pathParams.set(paramName,
|
|
47
|
+
pathParams.set(paramName, (0, utils_1.encodeAndConvertPrimitiveVal)(paramValue, dateTimeFormat));
|
|
45
48
|
}
|
|
46
49
|
return pathParams;
|
|
47
50
|
}
|
|
48
51
|
exports.getSimplePathParams = getSimplePathParams;
|
|
49
|
-
var ParamDecorator = /** @class */ (function () {
|
|
50
|
-
function ParamDecorator(Style, Explode, ParamName, Serialization) {
|
|
51
|
-
this.Style = Style;
|
|
52
|
-
this.Explode = Explode;
|
|
53
|
-
this.ParamName = ParamName;
|
|
54
|
-
this.Serialization = Serialization;
|
|
55
|
-
}
|
|
56
|
-
return ParamDecorator;
|
|
57
|
-
}());
|
|
58
|
-
exports.ParamDecorator = ParamDecorator;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.serializeQueryParams = exports.qpMetadataKey = void 0;
|
|
7
4
|
var utils_1 = require("./utils");
|
|
8
|
-
var qs_1 = __importDefault(require("qs"));
|
|
9
5
|
exports.qpMetadataKey = "queryParam";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
6
|
+
var queryStringPrefix = "?";
|
|
7
|
+
function serializeQueryParams(queryParams) {
|
|
8
|
+
var queryStringParts = [];
|
|
14
9
|
if (!queryParams)
|
|
15
|
-
return
|
|
10
|
+
return queryStringParts.join("&");
|
|
16
11
|
var fieldNames = Object.getOwnPropertyNames(queryParams);
|
|
17
12
|
fieldNames.forEach(function (fname) {
|
|
13
|
+
var _a, _b, _c, _d, _e;
|
|
18
14
|
var qpAnn = Reflect.getMetadata(exports.qpMetadataKey, queryParams, fname);
|
|
19
15
|
if (!qpAnn)
|
|
20
16
|
return { serialize: function (params) { return ""; } };
|
|
@@ -22,81 +18,135 @@ function getQueryParamSerializer(queryParams) {
|
|
|
22
18
|
if (!qpDecorator)
|
|
23
19
|
return;
|
|
24
20
|
if (qpDecorator.Serialization === "json")
|
|
25
|
-
|
|
26
|
-
serialize: function (params) { return Object.keys(params).map(function (key) {
|
|
27
|
-
return "".concat(key, "=").concat(JSON.stringify(params[key]));
|
|
28
|
-
}).join("&"); },
|
|
29
|
-
};
|
|
21
|
+
queryStringParts.push(jsonSerializer((_a = {}, _a[fname] = queryParams[fname], _a)));
|
|
30
22
|
else {
|
|
31
23
|
switch (qpDecorator.Style) {
|
|
32
24
|
case "deepObject":
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return qs_1.default.stringify(params);
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
break;
|
|
25
|
+
queryStringParts.push(deepObjectSerializer((_b = {}, _b[fname] = queryParams[fname], _b), qpDecorator.DateTimeFormat));
|
|
26
|
+
return;
|
|
39
27
|
case "form":
|
|
40
|
-
if (qpDecorator.Explode)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
paramsSerializer = {
|
|
47
|
-
serialize: formSerializer,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
default:
|
|
52
|
-
// go to next query parameter field, assume first implemented serializer will serialize all query parameters for this request
|
|
28
|
+
if (!qpDecorator.Explode)
|
|
29
|
+
queryStringParts.push(formSerializer((_c = {}, _c[fname] = queryParams[fname], _c), qpDecorator.DateTimeFormat));
|
|
30
|
+
else
|
|
31
|
+
queryStringParts.push(formSerializerExplode((_d = {}, _d[fname] = queryParams[fname], _d), qpDecorator.DateTimeFormat));
|
|
53
32
|
return;
|
|
33
|
+
default:
|
|
34
|
+
queryStringParts.push(formSerializerExplode((_e = {}, _e[fname] = queryParams[fname], _e), qpDecorator.DateTimeFormat));
|
|
54
35
|
}
|
|
55
36
|
}
|
|
56
37
|
});
|
|
57
|
-
return
|
|
38
|
+
return queryStringPrefix + queryStringParts.join("&");
|
|
39
|
+
}
|
|
40
|
+
exports.serializeQueryParams = serializeQueryParams;
|
|
41
|
+
// TODO: Add support for disabling percent encoding for reserved characters
|
|
42
|
+
function jsonSerializer(params) {
|
|
43
|
+
var query = [];
|
|
44
|
+
Object.entries(Object.assign({}, params)).forEach(function (_a) {
|
|
45
|
+
var key = _a[0], value = _a[1];
|
|
46
|
+
var values = Object.getOwnPropertyNames(value)
|
|
47
|
+
.map(function (paramKey) {
|
|
48
|
+
var qpAnn = Reflect.getMetadata(exports.qpMetadataKey, value, paramKey);
|
|
49
|
+
var qpDecorator = (0, utils_1.parseParamDecorator)(qpAnn, paramKey, "form", true);
|
|
50
|
+
if (qpDecorator == null)
|
|
51
|
+
return;
|
|
52
|
+
return "\"".concat(paramKey, "\":").concat(JSON.stringify((0, utils_1.convertIfDateObjectToISOString)(value[paramKey], qpDecorator.DateTimeFormat)));
|
|
53
|
+
})
|
|
54
|
+
.join(",");
|
|
55
|
+
query.push("".concat(key, "={").concat(encodeURIComponent(values), "}"));
|
|
56
|
+
});
|
|
57
|
+
return query.join("&");
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
function formSerializer(params) {
|
|
59
|
+
// TODO: Add support for disabling percent encoding for reserved characters
|
|
60
|
+
function formSerializer(params, dateTimeFormat) {
|
|
61
61
|
var query = [];
|
|
62
62
|
Object.entries(Object.assign({}, params)).forEach(function (_a) {
|
|
63
63
|
var key = _a[0], value = _a[1];
|
|
64
64
|
if (!value)
|
|
65
65
|
return;
|
|
66
66
|
if (value !== Object(value))
|
|
67
|
-
query.push("".concat(key, "=").concat(value));
|
|
67
|
+
query.push("".concat(key, "=").concat((0, utils_1.encodeAndConvertPrimitiveVal)(value, dateTimeFormat)));
|
|
68
68
|
else if (Array.isArray(value)) {
|
|
69
|
-
var values = value
|
|
70
|
-
|
|
69
|
+
var values = value
|
|
70
|
+
.map(function (aValue) { return (0, utils_1.convertIfDateObjectToISOString)(aValue, dateTimeFormat); })
|
|
71
|
+
.join(",");
|
|
72
|
+
query.push("".concat(key, "=").concat(encodeURIComponent(values)));
|
|
71
73
|
}
|
|
72
74
|
else {
|
|
73
|
-
var values = Object.
|
|
74
|
-
.map(function (
|
|
75
|
-
var
|
|
76
|
-
|
|
75
|
+
var values = Object.getOwnPropertyNames(value)
|
|
76
|
+
.map(function (paramKey) {
|
|
77
|
+
var qpAnn = Reflect.getMetadata(exports.qpMetadataKey, value, paramKey);
|
|
78
|
+
var qpDecorator = (0, utils_1.parseParamDecorator)(qpAnn, paramKey, "form", true);
|
|
79
|
+
if (qpDecorator == null)
|
|
80
|
+
return;
|
|
81
|
+
return "".concat(paramKey, ",").concat((0, utils_1.convertIfDateObjectToISOString)(value[paramKey], qpDecorator.DateTimeFormat));
|
|
77
82
|
})
|
|
78
83
|
.join(",");
|
|
79
|
-
query.push("".concat(key, "=").concat(values));
|
|
84
|
+
query.push("".concat(key, "=").concat(encodeURIComponent(values)));
|
|
80
85
|
}
|
|
81
86
|
});
|
|
82
87
|
return query.join("&");
|
|
83
88
|
}
|
|
84
|
-
|
|
89
|
+
// TODO: Add support for disabling percent encoding for reserved characters
|
|
90
|
+
function formSerializerExplode(params, dateTimeFormat) {
|
|
85
91
|
var query = [];
|
|
86
92
|
Object.entries(Object.assign({}, params)).forEach(function (_a) {
|
|
87
93
|
var key = _a[0], value = _a[1];
|
|
88
94
|
if (!value)
|
|
89
95
|
return;
|
|
90
96
|
if (value !== Object(value))
|
|
91
|
-
query.push("".concat(key, "=").concat(value));
|
|
97
|
+
query.push("".concat(key, "=").concat((0, utils_1.encodeAndConvertPrimitiveVal)(value, dateTimeFormat)));
|
|
92
98
|
else if (Array.isArray(value)) {
|
|
93
|
-
query.push(value
|
|
99
|
+
query.push(value
|
|
100
|
+
.map(function (aValue) {
|
|
101
|
+
return "".concat(key, "=").concat((0, utils_1.encodeAndConvertPrimitiveVal)(aValue, dateTimeFormat));
|
|
102
|
+
})
|
|
103
|
+
.join("&"));
|
|
94
104
|
}
|
|
95
105
|
else
|
|
96
|
-
query.push(Object.
|
|
106
|
+
query.push(Object.getOwnPropertyNames(value)
|
|
107
|
+
.map(function (paramKey) {
|
|
108
|
+
var qpAnn = Reflect.getMetadata(exports.qpMetadataKey, value, paramKey);
|
|
109
|
+
var qpDecorator = (0, utils_1.parseParamDecorator)(qpAnn, paramKey, "form", true);
|
|
110
|
+
if (qpDecorator == null)
|
|
111
|
+
return;
|
|
112
|
+
return "".concat(paramKey, "=").concat((0, utils_1.encodeAndConvertPrimitiveVal)(value[paramKey], qpDecorator.DateTimeFormat));
|
|
113
|
+
})
|
|
114
|
+
.join("&"));
|
|
115
|
+
});
|
|
116
|
+
return query.join("&");
|
|
117
|
+
}
|
|
118
|
+
// TODO: Add support for disabling percent encoding for reserved characters
|
|
119
|
+
function deepObjectSerializer(params, dateTimeFormat) {
|
|
120
|
+
var query = [];
|
|
121
|
+
Object.entries(Object.assign({}, params)).forEach(function (_a) {
|
|
122
|
+
var key = _a[0], value = _a[1];
|
|
123
|
+
if (!value)
|
|
124
|
+
return;
|
|
125
|
+
if (value !== Object(value))
|
|
126
|
+
query.push("".concat(key, "=").concat((0, utils_1.encodeAndConvertPrimitiveVal)(value, dateTimeFormat)));
|
|
127
|
+
else if (Array.isArray(value)) {
|
|
128
|
+
query.push(value
|
|
97
129
|
.map(function (_a) {
|
|
98
130
|
var objKey = _a[0], objValue = _a[1];
|
|
99
|
-
return "".concat(objKey, "=").concat(objValue);
|
|
131
|
+
return "".concat(key, "[").concat(objKey, "]=").concat((0, utils_1.encodeAndConvertPrimitiveVal)(objValue, dateTimeFormat));
|
|
132
|
+
})
|
|
133
|
+
.join("&"));
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
query.push(Object.getOwnPropertyNames(value)
|
|
137
|
+
.map(function (paramKey) {
|
|
138
|
+
var qpAnn = Reflect.getMetadata(exports.qpMetadataKey, value, paramKey);
|
|
139
|
+
var qpDecorator = (0, utils_1.parseParamDecorator)(qpAnn, paramKey, "form", true);
|
|
140
|
+
if (qpDecorator == null)
|
|
141
|
+
return;
|
|
142
|
+
// For deep objects, arr is wrapped inside object
|
|
143
|
+
if (Array.isArray(value[paramKey]))
|
|
144
|
+
return value[paramKey]
|
|
145
|
+
.map(function (arrValue) {
|
|
146
|
+
return "".concat(key, "[").concat(paramKey, "]=").concat((0, utils_1.encodeAndConvertPrimitiveVal)(arrValue, qpDecorator.DateTimeFormat));
|
|
147
|
+
})
|
|
148
|
+
.join("&");
|
|
149
|
+
return "".concat(key, "[").concat(paramKey, "]=").concat((0, utils_1.encodeAndConvertPrimitiveVal)(value[paramKey], qpDecorator.DateTimeFormat));
|
|
100
150
|
})
|
|
101
151
|
.join("&"));
|
|
102
152
|
});
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.serializeRequestBody = void 0;
|
|
18
7
|
var form_data_1 = __importDefault(require("form-data"));
|
|
8
|
+
var utils_1 = require("./utils");
|
|
19
9
|
var requestMetadataKey = "request";
|
|
20
10
|
var mpFormMetadataKey = "multipart_form";
|
|
21
11
|
function serializeRequestBody(request) {
|
|
@@ -26,8 +16,8 @@ function serializeRequestBody(request) {
|
|
|
26
16
|
var firstLevelRequestAnn = Reflect.getMetadata(requestMetadataKey, request, requestMetadataKey);
|
|
27
17
|
if (firstLevelRequestAnn == null)
|
|
28
18
|
requestBodyObj = request[requestMetadataKey];
|
|
29
|
-
var fieldNames = Object.getOwnPropertyNames(requestBodyObj);
|
|
30
19
|
var _a = [{}, {}], requestHeaders = _a[0], requestBody = _a[1];
|
|
20
|
+
var fieldNames = Object.getOwnPropertyNames(requestBodyObj);
|
|
31
21
|
fieldNames.forEach(function (fname) {
|
|
32
22
|
var _a, _b;
|
|
33
23
|
var requestAnn = Reflect.getMetadata(requestMetadataKey, requestBodyObj, fname);
|
|
@@ -43,14 +33,14 @@ function serializeRequestBody(request) {
|
|
|
43
33
|
case "application/x-www-form-urlencoded":
|
|
44
34
|
_a = [
|
|
45
35
|
{ "Content-Type": "".concat(requestDecorator.MediaType) },
|
|
46
|
-
encodeFormUrlEncodeData(requestBodyObj[fname])
|
|
36
|
+
encodeFormUrlEncodeData(requestBodyObj[fname]),
|
|
47
37
|
], requestHeaders = _a[0], requestBody = _a[1];
|
|
48
38
|
break;
|
|
49
39
|
case "application/json":
|
|
50
40
|
case "text/json":
|
|
51
41
|
_b = [
|
|
52
42
|
{ "Content-Type": "".concat(requestDecorator.MediaType) },
|
|
53
|
-
|
|
43
|
+
requestBodyObj[fname],
|
|
54
44
|
], requestHeaders = _b[0], requestBody = _b[1];
|
|
55
45
|
break;
|
|
56
46
|
default:
|
|
@@ -70,36 +60,41 @@ exports.serializeRequestBody = serializeRequestBody;
|
|
|
70
60
|
var encodeFormUrlEncodeData = function (data) {
|
|
71
61
|
var formData = new form_data_1.default();
|
|
72
62
|
var fieldNames = Object.getOwnPropertyNames(data);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (annotation.style === "form") {
|
|
85
|
-
var parsed_1;
|
|
86
|
-
if (annotation.explode === true) {
|
|
87
|
-
parsed_1 = formExplode(fname, data[fname]);
|
|
63
|
+
if ((0, utils_1.isNumberRecord)(data) || (0, utils_1.isBooleanRecord)(data) || (0, utils_1.isStringRecord)(data)) {
|
|
64
|
+
fieldNames.forEach(function (fname) {
|
|
65
|
+
formData.append(fname, String(data[fname]));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
fieldNames.forEach(function (fname) {
|
|
70
|
+
var _a;
|
|
71
|
+
var formAnn = Reflect.getMetadata("form", data, fname);
|
|
72
|
+
if (formAnn === null) {
|
|
73
|
+
return;
|
|
88
74
|
}
|
|
89
|
-
|
|
90
|
-
|
|
75
|
+
var formDecorator = parseFormDecorator(formAnn);
|
|
76
|
+
if (formDecorator.JSON) {
|
|
77
|
+
formData.append((_a = formDecorator.Name) !== null && _a !== void 0 ? _a : fname, JSON.stringify(data[fname]));
|
|
78
|
+
return;
|
|
91
79
|
}
|
|
92
|
-
|
|
93
|
-
parsed_1
|
|
94
|
-
|
|
80
|
+
if (formDecorator.Style === "form") {
|
|
81
|
+
var parsed_1;
|
|
82
|
+
if (formDecorator.Explode === true) {
|
|
83
|
+
parsed_1 = formExplode(fname, data[fname], formDecorator.DateTimeFormat);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
parsed_1 = formNotExplode(fname, data[fname], formDecorator.DateTimeFormat);
|
|
87
|
+
}
|
|
88
|
+
Object.keys(parsed_1).forEach(function (key) {
|
|
89
|
+
parsed_1[key].forEach(function (v) { return formData.append(key, v); });
|
|
95
90
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
100
95
|
return formData;
|
|
101
96
|
};
|
|
102
|
-
var formExplode = function (fname, data) {
|
|
97
|
+
var formExplode = function (fname, data, dateTimeFormat) {
|
|
103
98
|
var exploded = {};
|
|
104
99
|
if (Array.isArray(data)) {
|
|
105
100
|
data.forEach(function (value) {
|
|
@@ -111,6 +106,13 @@ var formExplode = function (fname, data) {
|
|
|
111
106
|
}
|
|
112
107
|
else {
|
|
113
108
|
if (typeof data === "object") {
|
|
109
|
+
if (data instanceof Date) {
|
|
110
|
+
if (!exploded[fname]) {
|
|
111
|
+
exploded[fname] = [];
|
|
112
|
+
}
|
|
113
|
+
exploded[fname].push((0, utils_1.convertIfDateObjectToISOString)(data, dateTimeFormat));
|
|
114
|
+
return exploded;
|
|
115
|
+
}
|
|
114
116
|
Object.keys(data).forEach(function (key) {
|
|
115
117
|
if (!exploded[key]) {
|
|
116
118
|
exploded[key] = [];
|
|
@@ -127,18 +129,23 @@ var formExplode = function (fname, data) {
|
|
|
127
129
|
}
|
|
128
130
|
return exploded;
|
|
129
131
|
};
|
|
130
|
-
var formNotExplode = function (fname, data) {
|
|
132
|
+
var formNotExplode = function (fname, data, dateTimeFormat) {
|
|
131
133
|
var notExploded = {};
|
|
132
134
|
if (Array.isArray(data)) {
|
|
133
135
|
if (!notExploded[fname]) {
|
|
134
136
|
notExploded[fname] = [];
|
|
135
137
|
}
|
|
136
|
-
notExploded[fname].push(data
|
|
137
|
-
.map(function (item) { return item.toString(); })
|
|
138
|
-
.join(","));
|
|
138
|
+
notExploded[fname].push(data.map(function (item) { return item.toString(); }).join(","));
|
|
139
139
|
}
|
|
140
140
|
else {
|
|
141
141
|
if (typeof data === "object") {
|
|
142
|
+
if (data instanceof Date) {
|
|
143
|
+
if (!notExploded[fname]) {
|
|
144
|
+
notExploded[fname] = [];
|
|
145
|
+
}
|
|
146
|
+
notExploded[fname].push((0, utils_1.convertIfDateObjectToISOString)(data, dateTimeFormat));
|
|
147
|
+
return notExploded;
|
|
148
|
+
}
|
|
142
149
|
Object.keys(data).forEach(function (key) {
|
|
143
150
|
if (!notExploded[key]) {
|
|
144
151
|
notExploded[key] = [];
|
|
@@ -155,17 +162,38 @@ var formNotExplode = function (fname, data) {
|
|
|
155
162
|
}
|
|
156
163
|
return notExploded;
|
|
157
164
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
165
|
+
function parseFormDecorator(formAnn) {
|
|
166
|
+
var formDecorator = new FormDecorator("", "form", false, false);
|
|
167
|
+
formAnn.split(";").forEach(function (formAnnPart) {
|
|
168
|
+
var _a = formAnnPart.split("="), formKey = _a[0], formVal = _a[1];
|
|
169
|
+
switch (formKey) {
|
|
170
|
+
case "name":
|
|
171
|
+
formDecorator.Name = formVal;
|
|
172
|
+
break;
|
|
173
|
+
case "style":
|
|
174
|
+
formDecorator.Style = formVal;
|
|
175
|
+
break;
|
|
176
|
+
case "explode":
|
|
177
|
+
formDecorator.Explode = formVal === "true";
|
|
178
|
+
break;
|
|
179
|
+
case "json":
|
|
180
|
+
formDecorator.JSON = formVal === "true";
|
|
181
|
+
break;
|
|
182
|
+
case "dateTimeFormat":
|
|
183
|
+
formDecorator.DateTimeFormat = formVal;
|
|
163
184
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
185
|
+
});
|
|
186
|
+
return formDecorator;
|
|
187
|
+
}
|
|
188
|
+
var FormDecorator = /** @class */ (function () {
|
|
189
|
+
function FormDecorator(Name, Style, Explode, JSON) {
|
|
190
|
+
this.Name = Name;
|
|
191
|
+
this.Style = Style;
|
|
192
|
+
this.Explode = Explode;
|
|
193
|
+
this.JSON = JSON;
|
|
194
|
+
}
|
|
195
|
+
return FormDecorator;
|
|
196
|
+
}());
|
|
169
197
|
function encodeMultipartFormData(form) {
|
|
170
198
|
var formData = new form_data_1.default();
|
|
171
199
|
var fieldNames = Object.getOwnPropertyNames(form);
|
|
@@ -177,16 +205,18 @@ function encodeMultipartFormData(form) {
|
|
|
177
205
|
if (mpFormDecorator.File)
|
|
178
206
|
return encodeMultipartFormDataFile(formData, form[fname]);
|
|
179
207
|
else if (mpFormDecorator.JSON) {
|
|
180
|
-
formData.append(mpFormDecorator.Name, JSON.stringify(form[fname])
|
|
208
|
+
formData.append(mpFormDecorator.Name, JSON.stringify(form[fname], function (key, value) {
|
|
209
|
+
return (0, utils_1.convertIfDateObjectToISOString)(value, mpFormDecorator.DateTimeFormat);
|
|
210
|
+
}));
|
|
181
211
|
}
|
|
182
212
|
else {
|
|
183
213
|
if (Array.isArray(form[fname])) {
|
|
184
214
|
form[fname].forEach(function (val) {
|
|
185
|
-
formData.append(mpFormDecorator.Name + "[]", String(val));
|
|
215
|
+
formData.append(mpFormDecorator.Name + "[]", String((0, utils_1.convertIfDateObjectToISOString)(val, mpFormDecorator.DateTimeFormat)));
|
|
186
216
|
});
|
|
187
217
|
}
|
|
188
218
|
else {
|
|
189
|
-
formData.append(mpFormDecorator.Name, String(form[fname]));
|
|
219
|
+
formData.append(mpFormDecorator.Name, String((0, utils_1.convertIfDateObjectToISOString)(form[fname], mpFormDecorator.DateTimeFormat)));
|
|
190
220
|
}
|
|
191
221
|
}
|
|
192
222
|
});
|
|
@@ -196,10 +226,10 @@ function encodeMultipartFormDataFile(formData, file) {
|
|
|
196
226
|
if (typeof file !== "object" || Array.isArray(file) || file == null) {
|
|
197
227
|
throw new Error("invalid type for multipart/form-data file");
|
|
198
228
|
}
|
|
199
|
-
var fieldNames = Object.getOwnPropertyNames(file);
|
|
200
229
|
var content = null;
|
|
201
230
|
var fileName = "";
|
|
202
231
|
var mpFormDecoratorName = "";
|
|
232
|
+
var fieldNames = Object.getOwnPropertyNames(file);
|
|
203
233
|
fieldNames.forEach(function (fname) {
|
|
204
234
|
var mpFormAnn = Reflect.getMetadata(mpFormMetadataKey, file, fname);
|
|
205
235
|
if (mpFormAnn == null)
|
|
@@ -237,6 +267,9 @@ function parseMultipartFormDecorator(mpFormAnn) {
|
|
|
237
267
|
break;
|
|
238
268
|
case "json":
|
|
239
269
|
mpFormDecorator.JSON = mpFormVal == "true";
|
|
270
|
+
break;
|
|
271
|
+
case "dateTimeFormat":
|
|
272
|
+
mpFormDecorator.DateTimeFormat = mpFormVal;
|
|
240
273
|
}
|
|
241
274
|
});
|
|
242
275
|
return mpFormDecorator;
|