@automatons/typescript-client-axios 1.0.6 → 1.0.7
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/package.json
CHANGED
package/templates/apis/api.hbs
CHANGED
|
@@ -6,9 +6,7 @@ import { Config{{#if securities}}, Security{{/if}} } from "../config";
|
|
|
6
6
|
import { {{#if hasTemplate}}template{{#or hasQuery hasFormData}},{{/or}}{{/if}} {{#if hasQuery}}query{{#if hasFormData}},{{/if}}{{/if}} {{#if hasFormData}}formData{{/if}} } from "../utils";
|
|
7
7
|
{{/or}}
|
|
8
8
|
{{/with}}
|
|
9
|
-
{{#each api/imports~}}
|
|
10
|
-
import { {{title}} } from "../models";
|
|
11
|
-
{{/each}}
|
|
9
|
+
import { {{#each api/imports~}} {{title}}{{#unless @last}}, {{/unless}}{{/each}} } from "../models";
|
|
12
10
|
|
|
13
11
|
{{#each api/servers}}
|
|
14
12
|
type {{name}}Server = { name: "{{name}}"{{#if values}}; values: { {{#each values}}{{name}}: {{#if enums}}{{#each enums}}'{{this}}'{{#unless @last}} | {{/unless}}{{/each}}{{else}}string{{/if}} {{/each}} }; {{/if}} }
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
type ParsedUrlQueryInput = NodeJS.Dict<string | number | boolean | ReadonlyArray<string> | ReadonlyArray<number> | ReadonlyArray<boolean> | null>
|
|
2
2
|
|
|
3
|
+
const isObject = (value: any): value is object => {
|
|
4
|
+
const type = typeof value
|
|
5
|
+
return value != null && (type == 'object' || type == 'function')
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
const queryForm =
|
|
4
9
|
(name: string,
|
|
5
10
|
value: string | number | Array<string | number> | { [key: string]: string | number },
|
|
@@ -10,7 +15,7 @@ const queryForm =
|
|
|
10
15
|
} else {
|
|
11
16
|
return {[name]: value.join(',')}
|
|
12
17
|
}
|
|
13
|
-
} else if (value
|
|
18
|
+
} else if (isObject(value)) {
|
|
14
19
|
if (explode) {
|
|
15
20
|
return value;
|
|
16
21
|
} else {
|
|
@@ -26,7 +31,7 @@ const querySpaceDelimited =
|
|
|
26
31
|
value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
|
|
27
32
|
if (Array.isArray(value)) {
|
|
28
33
|
return {[name]: value.join(' ')}
|
|
29
|
-
} else if (value
|
|
34
|
+
} else if (isObject(value)) {
|
|
30
35
|
return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join(' ')).join(' ')}
|
|
31
36
|
}
|
|
32
37
|
throw new Error(`Unsupported value: ${name}`);
|
|
@@ -37,7 +42,7 @@ const queryPipeDelimited =
|
|
|
37
42
|
value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
|
|
38
43
|
if (Array.isArray(value)) {
|
|
39
44
|
return {[name]: value.join('|')}
|
|
40
|
-
} else if (value
|
|
45
|
+
} else if (isObject(value)) {
|
|
41
46
|
return {[name]: Object.entries(value).map((prop: [string, string | number]) => prop.join('|')).join('|')}
|
|
42
47
|
}
|
|
43
48
|
throw new Error(`Unsupported value: ${name}`);
|
|
@@ -46,7 +51,7 @@ const queryPipeDelimited =
|
|
|
46
51
|
const queryDeepObject =
|
|
47
52
|
(name: string,
|
|
48
53
|
value: string | number | Array<string | number> | { [key: string]: string | number }): ParsedUrlQueryInput => {
|
|
49
|
-
if (!Array.isArray(value) && value
|
|
54
|
+
if (!Array.isArray(value) && isObject(value)) {
|
|
50
55
|
return Object.keys(value).reduce((pre, cur) => ({...pre, [`${name}[${cur}]`]: value[cur]}), {});
|
|
51
56
|
}
|
|
52
57
|
throw new Error(`Unsupported value: ${name}`);
|