avvir 0.4.17 → 0.4.19
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/dist/avvir_api.node.js +167 -61
- package/dist/esm/api/project_api.js +1 -1
- package/dist/esm/api/project_api.js.map +1 -1
- package/dist/esm/api/scan_dataset_api.d.ts +1 -2
- package/dist/esm/api/scan_dataset_api.js.map +1 -1
- package/dist/esm/converters/date_converter.d.ts +27 -10
- package/dist/esm/converters/date_converter.js +76 -45
- package/dist/esm/converters/date_converter.js.map +1 -1
- package/dist/esm/converters/date_formatter.d.ts +16 -0
- package/dist/esm/converters/date_formatter.js +48 -0
- package/dist/esm/converters/date_formatter.js.map +1 -0
- package/dist/esm/converters/index.d.ts +2 -1
- package/dist/esm/converters/index.js +2 -1
- package/dist/esm/converters/index.js.map +1 -1
- package/dist/esm/mixins/add_instant_getter_and_setter_to_api_model.js +11 -2
- package/dist/esm/mixins/add_instant_getter_and_setter_to_api_model.js.map +1 -1
- package/dist/esm/utilities/make_errors_pretty.d.ts +8 -4
- package/dist/esm/utilities/make_errors_pretty.js +3 -2
- package/dist/esm/utilities/make_errors_pretty.js.map +1 -1
- package/package.json +1 -1
- package/source/api/project_api.ts +1 -1
- package/source/api/scan_dataset_api.ts +33 -29
- package/source/converters/date_converter.ts +87 -46
- package/source/converters/date_formatter.ts +55 -0
- package/source/converters/index.ts +6 -5
- package/source/mixins/add_instant_getter_and_setter_to_api_model.ts +15 -4
- package/source/utilities/make_errors_pretty.ts +18 -10
|
@@ -2,8 +2,9 @@ import _ from "underscore";
|
|
|
2
2
|
import checkFetchStatus from "./check_fetch_status";
|
|
3
3
|
import Config from "../config";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type ObjectWithMethodProperties = Record<string, (...args: any) => any>
|
|
6
|
+
const makeErrorsPrettyForFunction = <Class extends ObjectWithMethodProperties, Key extends keyof Class>(actionName: Key, action: Class[Key], displayErrorMessage: boolean): Class[Key] => {
|
|
7
|
+
return ((...argumentList) => {
|
|
7
8
|
return action(...argumentList)
|
|
8
9
|
.then((response) => checkFetchStatus(response, displayErrorMessage))
|
|
9
10
|
.catch((error) => {
|
|
@@ -11,27 +12,34 @@ const makeErrorsPrettyForFunction = (actionName, action, displayErrorMessage) =>
|
|
|
11
12
|
error,
|
|
12
13
|
action: actionName,
|
|
13
14
|
arguments: argumentList
|
|
14
|
-
})
|
|
15
|
-
})
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}) as Class[Key];
|
|
18
|
+
};
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const getFunctionNames = (clazz) => {
|
|
20
|
+
type MethodProperties<T> = keyof { [P in keyof T as T[P] extends (...args: any) => any ? P : never]: any }
|
|
21
|
+
const getFunctionNames = <Class>(clazz: Class): MethodProperties<Class>[] => {
|
|
20
22
|
let builtinProperties = ["length", "constructor", "name", "prototype"];
|
|
21
23
|
// TODO it might make sense to check the type of each property
|
|
22
|
-
return _.without(Object.getOwnPropertyNames(clazz), ...builtinProperties)
|
|
24
|
+
return _.without(Object.getOwnPropertyNames(clazz), ...builtinProperties) as MethodProperties<Class>[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type Options<Class> = {
|
|
28
|
+
exclude?: MethodProperties<Class>[],
|
|
29
|
+
overrideErrorMessage?: MethodProperties<Class>[]
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
const makeErrorsPretty = (apiClass, options = {exclude: [], overrideErrorMessage: []}) => {
|
|
32
|
+
const makeErrorsPretty = <Class>(apiClass: Class, options: Options<Class> = { exclude: [], overrideErrorMessage: [] }) => {
|
|
26
33
|
let functionNames = getFunctionNames(apiClass);
|
|
27
34
|
_.forEach(functionNames, (functionName) => {
|
|
28
35
|
let isExcluded = options.exclude && options.exclude.includes(functionName);
|
|
29
36
|
let displayErrorMessage = !options.overrideErrorMessage || !options.overrideErrorMessage.includes(functionName);
|
|
30
37
|
if (!isExcluded) {
|
|
38
|
+
// @ts-ignore
|
|
31
39
|
apiClass[functionName] = makeErrorsPrettyForFunction(functionName, apiClass[functionName], displayErrorMessage);
|
|
32
40
|
}
|
|
33
41
|
});
|
|
34
42
|
return apiClass;
|
|
35
|
-
}
|
|
43
|
+
};
|
|
36
44
|
|
|
37
45
|
export default makeErrorsPretty;
|