@beseif-solutions/prow-core 0.3.2 → 0.3.3
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/core.d.ts +5 -5
- package/dist/core.js +4 -2
- package/dist/minified-utils/fields.js +3 -2
- package/package.json +1 -1
- package/src/core.ts +10 -7
- package/src/minified-utils/fields.ts +2 -5
package/dist/core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
2
|
import Joi from "joi";
|
|
3
|
-
import
|
|
3
|
+
import lodash from "lodash";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
import { FromCatalog, FromDirectory, T } from "./minified-utils/locales";
|
|
6
6
|
type SyncOrAsync<T> = T | Promise<T>;
|
|
@@ -15,9 +15,9 @@ export type SourceFunctions = {
|
|
|
15
15
|
unregister: (source: string, sandbox: boolean, id: string) => SyncOrAsync<void>;
|
|
16
16
|
};
|
|
17
17
|
export type Core = {
|
|
18
|
-
axios:
|
|
18
|
+
axios: AxiosInstance;
|
|
19
19
|
moment: typeof moment;
|
|
20
|
-
lodash: LoDashStatic;
|
|
20
|
+
lodash: lodash.LoDashStatic;
|
|
21
21
|
env: Record<string, any>;
|
|
22
22
|
joi: Joi.Root;
|
|
23
23
|
sources?: SourceFunctions;
|
|
@@ -28,5 +28,5 @@ type CoreOptions = {
|
|
|
28
28
|
sources?: SourceFunctions;
|
|
29
29
|
localization: FromDirectory | FromCatalog;
|
|
30
30
|
};
|
|
31
|
-
export declare const core: (options: CoreOptions) => Core
|
|
31
|
+
export declare const core: (options: CoreOptions) => Promise<Core>;
|
|
32
32
|
export {};
|
package/dist/core.js
CHANGED
|
@@ -20,8 +20,10 @@ const FALLBACK_SOURCES = {
|
|
|
20
20
|
throw new Error(`Sources not available: valid implementation not provided`);
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
|
-
const core = (options) => ({
|
|
24
|
-
axios: axios_1.default
|
|
23
|
+
const core = async (options) => ({
|
|
24
|
+
axios: axios_1.default.create({
|
|
25
|
+
adapter: axios_1.default.getAdapter(`http`),
|
|
26
|
+
}),
|
|
25
27
|
moment: moment_timezone_1.default,
|
|
26
28
|
lodash: lodash_1.default,
|
|
27
29
|
env: options.env || {},
|
|
@@ -456,7 +456,9 @@ const recursive_schema = async (field, data, options) => {
|
|
|
456
456
|
: newField.key;
|
|
457
457
|
const value = lodash_1.default.get(data, relativeKey, newField.default);
|
|
458
458
|
const resolved = context_1.default.resolve(newField, value, options.context);
|
|
459
|
-
|
|
459
|
+
if (typeof resolved !== `undefined`) {
|
|
460
|
+
lodash_1.default.set(data, relativeKey, resolved);
|
|
461
|
+
}
|
|
460
462
|
let calculatedSchema;
|
|
461
463
|
if (newField.as_array) {
|
|
462
464
|
const noArrayField = lodash_1.default.omit(newField, [`as_array`, `array_min`, `array_max`, `array_length`]);
|
|
@@ -489,7 +491,6 @@ const recursive_schema = async (field, data, options) => {
|
|
|
489
491
|
genericItemSchema = getSimpleFieldSchema(noArrayField);
|
|
490
492
|
}
|
|
491
493
|
calculatedSchema = getItemsArrayFieldSchema(newField, [genericItemSchema]);
|
|
492
|
-
lodash_1.default.unset(data, relativeKey);
|
|
493
494
|
}
|
|
494
495
|
}
|
|
495
496
|
else if (newField.type === `dict` && newField.items) {
|
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import axios, {
|
|
1
|
+
import axios, { AxiosInstance } from "axios";
|
|
2
2
|
import Joi from "joi";
|
|
3
|
-
import
|
|
3
|
+
import lodash from "lodash";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
import { FromCatalog, FromDirectory, i18n, T } from "./minified-utils/locales";
|
|
6
6
|
|
|
@@ -25,9 +25,9 @@ const FALLBACK_SOURCES: SourceFunctions = {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export type Core = {
|
|
28
|
-
axios:
|
|
28
|
+
axios: AxiosInstance,
|
|
29
29
|
moment: typeof moment,
|
|
30
|
-
lodash: LoDashStatic,
|
|
30
|
+
lodash: lodash.LoDashStatic,
|
|
31
31
|
env: Record<string, any>,
|
|
32
32
|
joi: Joi.Root,
|
|
33
33
|
sources?: SourceFunctions,
|
|
@@ -41,10 +41,13 @@ type CoreOptions = {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
/* eslint-disable @typescript-eslint/unbound-method */
|
|
44
|
-
export const core = (options: CoreOptions): Core => ({
|
|
45
|
-
|
|
44
|
+
export const core = async (options: CoreOptions): Promise<Core> => ({
|
|
45
|
+
// explicit adapter for NodeJS -> avoid DOM errors
|
|
46
|
+
axios: axios.create({
|
|
47
|
+
adapter: axios.getAdapter(`http`),
|
|
48
|
+
}),
|
|
46
49
|
moment: moment,
|
|
47
|
-
lodash:
|
|
50
|
+
lodash: lodash,
|
|
48
51
|
env: options.env || {},
|
|
49
52
|
joi: Joi,
|
|
50
53
|
sources: options.sources || FALLBACK_SOURCES,
|
|
@@ -661,9 +661,9 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
661
661
|
|
|
662
662
|
const value = _.get(data, relativeKey, newField.default);
|
|
663
663
|
|
|
664
|
-
// resolve value with context (even if it's not valid)
|
|
664
|
+
// resolve value with context (even if it's not valid - omit undefined)
|
|
665
665
|
const resolved = context.resolve(newField, value, options.context);
|
|
666
|
-
_.set(data, relativeKey, resolved);
|
|
666
|
+
if (typeof resolved !== `undefined`) { _.set(data, relativeKey, resolved); }
|
|
667
667
|
|
|
668
668
|
// get schema for field with data
|
|
669
669
|
let calculatedSchema: Joi.Schema;
|
|
@@ -697,9 +697,6 @@ const recursive_schema = async (field: Field, data: Record<string, any>, options
|
|
|
697
697
|
}
|
|
698
698
|
|
|
699
699
|
calculatedSchema = getItemsArrayFieldSchema(newField, [genericItemSchema]);
|
|
700
|
-
|
|
701
|
-
// unset value if it wasn't resolved
|
|
702
|
-
_.unset(data, relativeKey);
|
|
703
700
|
}
|
|
704
701
|
} else if (newField.type === `dict` && newField.items) {
|
|
705
702
|
const items: { key: string, schema: Joi.Schema, field: Field }[] = [];
|