@beseif-solutions/prow-core 0.0.16

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.
Files changed (47) hide show
  1. package/dist/core.d.ts +21 -0
  2. package/dist/core.js +46 -0
  3. package/dist/entities/category.d.ts +1 -0
  4. package/dist/entities/category.js +20 -0
  5. package/dist/entities/commons.d.ts +26 -0
  6. package/dist/entities/commons.js +15 -0
  7. package/dist/entities/credentials.d.ts +85 -0
  8. package/dist/entities/credentials.js +48 -0
  9. package/dist/entities/events.d.ts +131 -0
  10. package/dist/entities/events.js +82 -0
  11. package/dist/entities/provider.d.ts +12 -0
  12. package/dist/entities/provider.js +25 -0
  13. package/dist/index.d.ts +8 -0
  14. package/dist/index.js +33 -0
  15. package/dist/minified-utils/context.d.ts +6 -0
  16. package/dist/minified-utils/context.js +55 -0
  17. package/dist/minified-utils/env.d.ts +13 -0
  18. package/dist/minified-utils/env.js +96 -0
  19. package/dist/minified-utils/fields.d.ts +128 -0
  20. package/dist/minified-utils/fields.js +458 -0
  21. package/dist/minified-utils/locales.d.ts +27 -0
  22. package/dist/minified-utils/locales.js +88 -0
  23. package/dist/minified-utils/proxy.d.ts +9 -0
  24. package/dist/minified-utils/proxy.js +55 -0
  25. package/dist/minified-utils/types.d.ts +11 -0
  26. package/dist/minified-utils/types.js +2 -0
  27. package/dist/minified-utils/utils.d.ts +1 -0
  28. package/dist/minified-utils/utils.js +26 -0
  29. package/dist/minified-utils/where.d.ts +40 -0
  30. package/dist/minified-utils/where.js +265 -0
  31. package/package.json +44 -0
  32. package/src/core.ts +56 -0
  33. package/src/entities/category.ts +9 -0
  34. package/src/entities/commons.ts +40 -0
  35. package/src/entities/credentials.ts +131 -0
  36. package/src/entities/events.ts +198 -0
  37. package/src/entities/provider.ts +29 -0
  38. package/src/index.ts +8 -0
  39. package/src/minified-utils/context.ts +56 -0
  40. package/src/minified-utils/env.ts +90 -0
  41. package/src/minified-utils/fields.ts +628 -0
  42. package/src/minified-utils/locales.ts +124 -0
  43. package/src/minified-utils/proxy.ts +44 -0
  44. package/src/minified-utils/types.ts +18 -0
  45. package/src/minified-utils/utils.ts +18 -0
  46. package/src/minified-utils/where.ts +330 -0
  47. package/tsconfig.json +21 -0
@@ -0,0 +1,27 @@
1
+ import I18n from 'i18n';
2
+ import { Credentials, SessionCredentials, StaticCredentials } from '../entities/credentials';
3
+ import { Action, ConnectableEvent, Trigger } from '../entities/events';
4
+ import { Field } from './fields';
5
+ import { Provider } from '../entities/provider';
6
+ type LocalizedField = {
7
+ label: string;
8
+ help: string;
9
+ };
10
+ type LocalizedProperties = {
11
+ name: string;
12
+ description: string;
13
+ };
14
+ type TOptions = {
15
+ fallback?: boolean;
16
+ };
17
+ export declare const i18n: (directory: string, options?: {
18
+ locale?: string;
19
+ }) => {
20
+ t: (code: string, opts?: TOptions) => string;
21
+ i18n: I18n.I18n;
22
+ };
23
+ export declare const localizeFields: (t: ReturnType<typeof i18n>[`t`], element: Action | Trigger | StaticCredentials | SessionCredentials) => Field<LocalizedField>[];
24
+ export declare const localizeProperties: (t: ReturnType<typeof i18n>[`t`], element: Action | Trigger | Credentials | Provider) => LocalizedProperties;
25
+ export declare const localizeInputs: (t: ReturnType<typeof i18n>[`t`], element: Action) => (ConnectableEvent & LocalizedProperties)[];
26
+ export declare const localizeOutputs: (t: ReturnType<typeof i18n>[`t`], element: Action | Trigger) => (ConnectableEvent & LocalizedProperties)[];
27
+ export {};
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.localizeOutputs = exports.localizeInputs = exports.localizeProperties = exports.localizeFields = exports.i18n = void 0;
7
+ const i18n_1 = __importDefault(require("i18n"));
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const utils_1 = require("./utils");
12
+ const DEFAULT_LOCALE = `en`;
13
+ const i18n = (directory, options = {}) => {
14
+ try {
15
+ if (!(0, utils_1.validateDirectory)(directory)) {
16
+ throw new Error(`Invalid directory: ${directory}`);
17
+ }
18
+ const availableLocales = fs_1.default.readdirSync(directory).map((file) => path_1.default.basename(file, path_1.default.extname(file)));
19
+ const requestedLocale = options.locale || DEFAULT_LOCALE;
20
+ const activeLocale = availableLocales.includes(requestedLocale) ? requestedLocale : DEFAULT_LOCALE;
21
+ const i18nInstance = new i18n_1.default.I18n({
22
+ locales: availableLocales,
23
+ directory: directory,
24
+ defaultLocale: DEFAULT_LOCALE,
25
+ objectNotation: true,
26
+ autoReload: true,
27
+ missingKeyFn: () => ``,
28
+ });
29
+ i18nInstance.setLocale(activeLocale);
30
+ return {
31
+ t: (code, opts = {}) => {
32
+ let response = i18nInstance.__(code);
33
+ if (!response && opts.fallback) {
34
+ response = i18nInstance.__({ phrase: code, locale: DEFAULT_LOCALE });
35
+ }
36
+ return response;
37
+ }, i18n: i18nInstance,
38
+ };
39
+ }
40
+ catch (e) {
41
+ throw e;
42
+ }
43
+ };
44
+ exports.i18n = i18n;
45
+ const localizeField = (t, element, field, parent = ``) => {
46
+ const key = lodash_1.default.compact([parent, field.key]).join(`.`);
47
+ field.label = t(`${element}.fields.${key}.label`, { fallback: true });
48
+ field.help = t(`${element}.fields.${key}.help`);
49
+ if (field.type === `dict` && field.items) {
50
+ field.items = field.items.map((f) => localizeField(t, element, f, `${key}.items`));
51
+ }
52
+ else if (`format` in field && field.format === `select` && lodash_1.default.isArray(field.choices)) {
53
+ field.choices = field.choices.map((fc) => ({
54
+ ...fc,
55
+ label: t(`${element}.fields.${key}.choices.${fc.key}.label`, { fallback: true }),
56
+ help: t(`${element}.fields.${key}.choices.${fc.key}.help`),
57
+ }));
58
+ }
59
+ return field;
60
+ };
61
+ const localizeFields = (t, element) => {
62
+ const response = [];
63
+ if (element[`fields`] && element[`fields`].length > 0) {
64
+ response.push(...element[`fields`].map((f) => localizeField(t, element.id, f)));
65
+ }
66
+ return response;
67
+ };
68
+ exports.localizeFields = localizeFields;
69
+ const localizeProperties = (t, element) => ({
70
+ name: t(`${element.id}.name`, { fallback: true }),
71
+ description: t(`${element.id}.description`),
72
+ });
73
+ exports.localizeProperties = localizeProperties;
74
+ const localizeConnectable = (t, element, type) => {
75
+ const response = [];
76
+ if (element[type] && element[type].length > 0) {
77
+ response.push(...element[type].map((c) => ({
78
+ ...c,
79
+ name: t(`${element.id}.${type}.${c.key}.name`, { fallback: true }),
80
+ description: t(`${element.id}.${type}.${c.key}.description`),
81
+ })));
82
+ }
83
+ return response;
84
+ };
85
+ const localizeInputs = (t, element) => localizeConnectable(t, element, `inputs`);
86
+ exports.localizeInputs = localizeInputs;
87
+ const localizeOutputs = (t, element) => localizeConnectable(t, element, `outputs`);
88
+ exports.localizeOutputs = localizeOutputs;
@@ -0,0 +1,9 @@
1
+ import { AsyncReturnType } from "./types";
2
+ export type ProxyLogs<F extends (...args: any[]) => any> = {
3
+ before?: (name: string, args: Parameters<F>) => (void | Promise<void>);
4
+ after?: (name: string, response: AsyncReturnType<F>) => (void | Promise<void>);
5
+ error?: (name: string, error: Error) => (void | Promise<void>);
6
+ };
7
+ export declare const logProxy: <F extends (...args: any[]) => any>(name: string, f: F, logs?: ProxyLogs<F>) => F;
8
+ export declare const functionProxy: <F extends (...args: any[]) => (any | Promise<any>)>(f: F, name?: string) => F;
9
+ export declare const accessProxy: <T extends object>(obj: T, custom?: Partial<{ [K in keyof T]: T[K]; }>) => T;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.accessProxy = exports.functionProxy = exports.logProxy = void 0;
4
+ const logProxy = (name, f, logs = {}) => new Proxy(f, {
5
+ apply: async (target, self, args) => {
6
+ try {
7
+ if (logs.before) {
8
+ await logs.before(name, args);
9
+ }
10
+ const response = await target(...args);
11
+ if (logs.after) {
12
+ await logs.after(name, response);
13
+ }
14
+ return response;
15
+ }
16
+ catch (e) {
17
+ if (logs.error) {
18
+ await logs.error(name, e);
19
+ }
20
+ throw e;
21
+ }
22
+ },
23
+ });
24
+ exports.logProxy = logProxy;
25
+ const functionProxy = (f, name) => new Proxy(f, {
26
+ apply: async (target, self, args) => {
27
+ try {
28
+ console.log(`Call to ${name || target}`);
29
+ const response = await target(...args);
30
+ return response;
31
+ }
32
+ catch (e) {
33
+ throw e;
34
+ }
35
+ },
36
+ });
37
+ exports.functionProxy = functionProxy;
38
+ const accessProxy = (obj, custom) => new Proxy(obj, {
39
+ get: (target, prop) => {
40
+ const value = target[prop];
41
+ if (custom && custom[prop]) {
42
+ return custom[prop];
43
+ }
44
+ else if (typeof value === `function`) {
45
+ return (0, exports.functionProxy)(value, prop);
46
+ }
47
+ else if (typeof value === `object`) {
48
+ return (0, exports.accessProxy)(value);
49
+ }
50
+ else {
51
+ return value;
52
+ }
53
+ },
54
+ });
55
+ exports.accessProxy = accessProxy;
@@ -0,0 +1,11 @@
1
+ export type RequireMinOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
2
+ [K in Keys]-?: Required<Pick<T, K>>;
3
+ }[Keys];
4
+ export type RequireOne<T extends Record<string, any>, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
5
+ [K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
6
+ }[Keys];
7
+ export type OneOf<T extends Record<string, any>> = Partial<RequireOne<T>>;
8
+ export type DeepPartial<T extends Record<string, any>> = {
9
+ [P in keyof T]?: T[P] extends Record<string, any> ? DeepPartial<T[P]> : T[P];
10
+ };
11
+ export type AsyncReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => Promise<infer U> ? U : T extends (...args: any[]) => infer U ? U : any;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare const validateDirectory: (directory: string) => boolean;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.validateDirectory = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const validateDirectory = (directory) => {
9
+ try {
10
+ if (!fs_1.default.existsSync(directory)) {
11
+ console.error(`Directory does not exist: ${directory}`);
12
+ return false;
13
+ }
14
+ const files = fs_1.default.readdirSync(directory);
15
+ if (!files.some((file) => file.endsWith(`.json`))) {
16
+ console.error(`No valid localization files found in directory: ${directory}`);
17
+ return false;
18
+ }
19
+ return true;
20
+ }
21
+ catch (error) {
22
+ console.error(`Error validating directory: ${error.message}`);
23
+ return false;
24
+ }
25
+ };
26
+ exports.validateDirectory = validateDirectory;
@@ -0,0 +1,40 @@
1
+ import { DeepPartial, RequireMinOne } from "./types";
2
+ type Basic = string | number | boolean;
3
+ type Is<T extends Basic> = {
4
+ is: T;
5
+ };
6
+ type Like<T extends Basic> = T extends string ? {
7
+ like: T;
8
+ } : undefined;
9
+ type ILike<T extends Basic> = T extends string ? {
10
+ ilike: T;
11
+ } : undefined;
12
+ type In<T extends Basic> = {
13
+ in: T[];
14
+ };
15
+ type Range<T extends Basic> = RequireMinOne<{
16
+ lt: T;
17
+ eq: T;
18
+ gt: T;
19
+ gte: T;
20
+ lte: T;
21
+ }> & {
22
+ date?: boolean;
23
+ };
24
+ type Contains<T extends (Basic | Record<string, any>)[]> = {
25
+ contains: T[number] | T;
26
+ };
27
+ type Complex<T extends (Basic | (Basic | Record<string, any>)[])> = T extends Basic ? Is<T> | Like<T> | ILike<T> | In<T> | Range<T> : T extends (Basic | Record<string, any>)[] ? T extends Record<string, any>[] ? Contains<DeepPartial<T[number]>[]> : Contains<T> : never;
28
+ type Condition<T> = (T extends Basic ? T : T extends Complex<infer F> ? (Complex<F> & {
29
+ inverse?: boolean;
30
+ nullable?: boolean;
31
+ relational?: string;
32
+ }) : never);
33
+ export type Where<T extends Record<string, any> = Record<string, any>> = Partial<{
34
+ [K in keyof T]: T[K] extends Basic ? Condition<T[K] | Complex<T[K]>> | Condition<T[K] | Complex<T[K]>>[] : (T[K] extends Record<string, any> ? Where<T[K]> : (T[K] extends any[] ? Condition<Complex<T[K]>> : never));
35
+ }>;
36
+ type Flags = {
37
+ i?: boolean;
38
+ };
39
+ export declare const where: (json: Record<string, any>, conditions: Where[], flags?: Flags) => boolean;
40
+ export {};
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.where = void 0;
7
+ const moment_timezone_1 = __importDefault(require("moment-timezone"));
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const joi_1 = __importDefault(require("joi"));
10
+ const conditionSchema = () => joi_1.default.object({
11
+ inverse: joi_1.default.bool(),
12
+ nullable: joi_1.default.bool(),
13
+ });
14
+ const relationalSchema = () => conditionSchema()
15
+ .concat(joi_1.default.object({
16
+ relational: joi_1.default.string().required(),
17
+ is: joi_1.default.string().allow(null),
18
+ in: joi_1.default.array().items(joi_1.default.string().allow(null)),
19
+ lt: joi_1.default.string().allow(null),
20
+ eq: joi_1.default.string().allow(null),
21
+ gt: joi_1.default.string().allow(null),
22
+ gte: joi_1.default.string().allow(null),
23
+ lte: joi_1.default.string().allow(null),
24
+ }));
25
+ const numberSchema = (params) => conditionSchema()
26
+ .concat(joi_1.default.object({
27
+ is: joi_1.default.number().strict(params.strict).allow(null),
28
+ in: joi_1.default.array().items(joi_1.default.number().strict(params.strict).allow(null)),
29
+ lt: joi_1.default.number().strict(params.strict).allow(null),
30
+ eq: joi_1.default.number().strict(params.strict).allow(null),
31
+ gt: joi_1.default.number().strict(params.strict).allow(null),
32
+ gte: joi_1.default.number().strict(params.strict).allow(null),
33
+ lte: joi_1.default.number().strict(params.strict).allow(null),
34
+ })).or(`is`, `in`, `lt`, `eq`, `gt`, `gte`, `lte`);
35
+ const stringSchema = (params) => conditionSchema()
36
+ .concat(joi_1.default.object({
37
+ is: joi_1.default.string().strict(params.strict).allow(null),
38
+ like: joi_1.default.string().strict(params.strict).allow(null),
39
+ ilike: joi_1.default.string().strict(params.strict).allow(null),
40
+ in: joi_1.default.array().items(joi_1.default.string().strict(params.strict).allow(null)),
41
+ })).or(`is`, `ilike`, `like`, `in`);
42
+ const boolSchema = (params) => conditionSchema()
43
+ .concat(joi_1.default.object({
44
+ is: joi_1.default.bool().strict(params.strict).allow(null),
45
+ })).or(`is`);
46
+ const dateSchema = (params) => conditionSchema()
47
+ .concat(joi_1.default.object({
48
+ lt: joi_1.default.date().strict(params.strict).allow(null),
49
+ eq: joi_1.default.date().strict(params.strict).allow(null),
50
+ gt: joi_1.default.date().strict(params.strict).allow(null),
51
+ gte: joi_1.default.date().strict(params.strict).allow(null),
52
+ lte: joi_1.default.date().strict(params.strict).allow(null),
53
+ date: true,
54
+ })).or(`lt`, `eq`, `gt`, `gte`, `lte`);
55
+ const arraySchema = () => conditionSchema()
56
+ .concat(joi_1.default.object({
57
+ contains: joi_1.default.alternatives(basicSchema(), joi_1.default.array().items(joi_1.default.any()), joi_1.default.object()
58
+ .pattern(joi_1.default.string(), joi_1.default.alternatives(basicSchema(), joi_1.default.array().items(joi_1.default.any()), joi_1.default.link(`#object`)))
59
+ .id(`object`)),
60
+ }));
61
+ const basicSchema = () => joi_1.default.alternatives(joi_1.default.string().strict(false), joi_1.default.number().strict(false), joi_1.default.bool().strict(false));
62
+ const complexSchema = () => joi_1.default.alternatives(numberSchema({ strict: false }), stringSchema({ strict: false }), boolSchema({ strict: false }), dateSchema({ strict: false }), arraySchema(), relationalSchema());
63
+ const orSchema = () => joi_1.default.array().items(joi_1.default.alternatives(basicSchema(), complexSchema()));
64
+ const whereSchema = () => joi_1.default.object()
65
+ .pattern(joi_1.default.string(), joi_1.default.alternatives(basicSchema(), complexSchema(), orSchema(), joi_1.default.link(`#where`)))
66
+ .id(`where`);
67
+ const clearObject = (obj, path = ``) => {
68
+ lodash_1.default.map(obj || {}, (v, k) => {
69
+ if (lodash_1.default.isUndefined(v)) {
70
+ lodash_1.default.unset(obj, `${path}${k}`);
71
+ }
72
+ if (lodash_1.default.isObject(v)) {
73
+ clearObject(v, `${k}.`);
74
+ }
75
+ });
76
+ };
77
+ const validate = (schema, data, options) => {
78
+ try {
79
+ if (!lodash_1.default.isFunction(schema[`validate`])) {
80
+ throw new Error(`Invalid schema`);
81
+ }
82
+ if (lodash_1.default.isObject(data)) {
83
+ clearObject(data);
84
+ }
85
+ const result = schema.validate(data, options);
86
+ if (result.error) {
87
+ throw result.error;
88
+ }
89
+ return data;
90
+ }
91
+ catch (err) {
92
+ throw new Error(lodash_1.default.get(err, `details.0.message`) || err.message || err);
93
+ }
94
+ };
95
+ const isBasic = (condition) => {
96
+ try {
97
+ basicSchema().validate(condition);
98
+ validate(basicSchema(), condition);
99
+ return true;
100
+ }
101
+ catch (e) {
102
+ return false;
103
+ }
104
+ };
105
+ const isComplex = (condition) => {
106
+ try {
107
+ validate(complexSchema(), condition);
108
+ return true;
109
+ }
110
+ catch (e) {
111
+ return false;
112
+ }
113
+ };
114
+ const isOr = (condition) => {
115
+ try {
116
+ validate(orSchema(), condition);
117
+ return true;
118
+ }
119
+ catch (e) {
120
+ return false;
121
+ }
122
+ };
123
+ const isWhere = (condition) => {
124
+ try {
125
+ validate(whereSchema(), condition);
126
+ return true;
127
+ }
128
+ catch (e) {
129
+ return false;
130
+ }
131
+ };
132
+ const processRange = (condition, value, comparator, date) => {
133
+ let v1;
134
+ let v2;
135
+ let compare;
136
+ if (date) {
137
+ v1 = (0, moment_timezone_1.default)(value);
138
+ v2 = (0, moment_timezone_1.default)(condition);
139
+ switch (comparator) {
140
+ case `<`:
141
+ compare = (d1, d2) => d1.isBefore(d2);
142
+ break;
143
+ case `=`:
144
+ compare = (d1, d2) => !d1.isAfter(d2) && !d1.isBefore(d2);
145
+ break;
146
+ case `>`:
147
+ compare = (d1, d2) => d1.isAfter(d2);
148
+ break;
149
+ case `>=`:
150
+ compare = (d1, d2) => d1.isAfter(d2) || (!d1.isAfter(d2) && !d1.isBefore(d2));
151
+ break;
152
+ case `<=`:
153
+ compare = (d1, d2) => d1.isBefore(d2) || (!d1.isAfter(d2) && !d1.isBefore(d2));
154
+ break;
155
+ }
156
+ }
157
+ else {
158
+ v1 = value;
159
+ v2 = condition;
160
+ switch (comparator) {
161
+ case `<`:
162
+ compare = (d1, d2) => d1 < d2;
163
+ break;
164
+ case `=`:
165
+ compare = (d1, d2) => d1 === d2;
166
+ break;
167
+ case `>`:
168
+ compare = (d1, d2) => d1 > d2;
169
+ break;
170
+ case `>=`:
171
+ compare = (d1, d2) => d1 >= d2;
172
+ break;
173
+ case `<=`:
174
+ compare = (d1, d2) => d1 <= d2;
175
+ break;
176
+ }
177
+ }
178
+ return compare(v1, v2);
179
+ };
180
+ const processBasic = (value, condition, flags) => (typeof value === `string` && typeof condition === `string` && flags?.i) ?
181
+ value.toLowerCase() === condition.toLowerCase()
182
+ : value === condition;
183
+ const processComplex = (value, condition, flags) => {
184
+ const results = [];
185
+ const withNullable = (bool, val) => (bool || condition.nullable && lodash_1.default.isNull(val));
186
+ const withInverse = (bool) => bool !== condition.inverse;
187
+ if (`is` in condition) {
188
+ const is = (typeof value === `string` && typeof condition.is === `string` && flags?.i) ?
189
+ value.toLowerCase() === condition.is.toLowerCase()
190
+ : value === condition.is;
191
+ results.push(withInverse(withNullable(is, value)));
192
+ }
193
+ if (`like` in condition) {
194
+ const regexp = new RegExp(`^${condition.like.replace(/%/g, `.*`).replace(/_/g, `.`)}$`);
195
+ const like = regexp.test(value);
196
+ results.push(withInverse(withNullable(like, value)));
197
+ }
198
+ if (`ilike` in condition) {
199
+ const regexp = new RegExp(`^${condition.ilike.replace(/%/g, `.*`).replace(/_/g, `.`)}$`, `i`);
200
+ const ilike = regexp.test(value);
201
+ results.push(withInverse(withNullable(ilike, value)));
202
+ }
203
+ if (`in` in condition) {
204
+ const isIn = (condition.in && condition.in.length > 0) ?
205
+ lodash_1.default.includes(condition.in, value) :
206
+ lodash_1.default.isNull(value);
207
+ results.push(withInverse(withNullable(isIn, value)));
208
+ }
209
+ if (`lt` in condition) {
210
+ const lt = processRange(condition.lt, value, `<`, condition.date || false);
211
+ results.push(withInverse(withNullable(lt, value)));
212
+ }
213
+ if (`eq` in condition) {
214
+ const eq = processRange(condition.eq, value, `=`, condition.date || false);
215
+ results.push(withInverse(withNullable(eq, value)));
216
+ }
217
+ if (`gt` in condition) {
218
+ const gt = processRange(condition.gt, value, `>`, condition.date || false);
219
+ results.push(withInverse(withNullable(gt, value)));
220
+ }
221
+ if (`gte` in condition) {
222
+ const gte = processRange(condition.gte, value, `>=`, condition.date || false);
223
+ results.push(withInverse(withNullable(gte, value)));
224
+ }
225
+ if (`lte` in condition) {
226
+ const lte = processRange(condition.lte, value, `<=`, condition.date || false);
227
+ results.push(withInverse(withNullable(lte, value)));
228
+ }
229
+ return !results.some((r) => !r);
230
+ };
231
+ const processWhere = (json, conditions, flags) => {
232
+ let matches = false;
233
+ for (const w of conditions) {
234
+ let matchesWhere = true;
235
+ for (const key of lodash_1.default.keys(w)) {
236
+ const value = lodash_1.default.get(json, key, null);
237
+ const cond = w[key];
238
+ if (isOr(cond)) {
239
+ matchesWhere && (matchesWhere = lodash_1.default.some(cond, (c) => processWhere({ [key]: value }, [{ [key]: c }], flags)));
240
+ }
241
+ else if (isBasic(cond)) {
242
+ matchesWhere && (matchesWhere = processBasic(value, cond, flags));
243
+ }
244
+ else if (isComplex(cond)) {
245
+ matchesWhere && (matchesWhere = processComplex(value, cond, flags));
246
+ }
247
+ else if (isWhere(cond)) {
248
+ matchesWhere && (matchesWhere = processWhere(value, [cond], flags));
249
+ }
250
+ else {
251
+ continue;
252
+ }
253
+ if (!matchesWhere) {
254
+ break;
255
+ }
256
+ }
257
+ matches || (matches = matchesWhere);
258
+ if (matches) {
259
+ break;
260
+ }
261
+ }
262
+ return matches;
263
+ };
264
+ const where = (json, conditions, flags) => processWhere(json, conditions, flags);
265
+ exports.where = where;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@beseif-solutions/prow-core",
3
+ "version": "0.0.16",
4
+ "description": "Zapdos core functionalities and classes",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "clean": "rimraf dist",
8
+ "build": "npm run clean && tsc",
9
+ "release": "npm-run-all clean build",
10
+ "build_watch": "tsc --watch",
11
+ "run": "nodemon './dist/index.js' --watch './dist/**/*.js'",
12
+ "develop": "npm-run-all clean build --parallel build_watch run",
13
+ "start": "node dist/index.js",
14
+ "lint": "npx eslint -c .eslintrc.js --ext .ts src --fix"
15
+ },
16
+ "keywords": [],
17
+ "author": "",
18
+ "license": "ISC",
19
+ "dependencies": {
20
+ "@types/express": "^4.17.21",
21
+ "axios": "^1.7.7",
22
+ "dotenv": "^16.4.5",
23
+ "handlebars": "^4.7.8",
24
+ "i18n": "^0.15.1",
25
+ "joi": "^17.13.3",
26
+ "lodash": "^4.17.21",
27
+ "moment-timezone": "^0.5.46",
28
+ "ts-node": "^8.10.2"
29
+ },
30
+ "devDependencies": {
31
+ "@types/i18n": "^0.13.12",
32
+ "@types/lodash": "^4.14.168",
33
+ "@types/node": "^22.8.4",
34
+ "@typescript-eslint/eslint-plugin": "^5.38.0",
35
+ "@typescript-eslint/parser": "^5.38.0",
36
+ "eslint": "^8.24.0",
37
+ "eslint-plugin-jsdoc": "^39.3.6",
38
+ "eslint-plugin-prefer-arrow": "^1.2.3",
39
+ "nodemon": "^3.1.9",
40
+ "npm-run-all": "^4.1.5",
41
+ "rimraf": "^6.0.1",
42
+ "typescript": "5.6.3"
43
+ }
44
+ }
package/src/core.ts ADDED
@@ -0,0 +1,56 @@
1
+ import axios, { AxiosError, AxiosResponse } from "axios";
2
+ import _ from "lodash";
3
+ import moment from "moment-timezone";
4
+ import { accessProxy, logProxy, ProxyLogs } from "./minified-utils/proxy";
5
+ import { Env } from "./minified-utils/env";
6
+ import { i18n } from "./minified-utils/locales";
7
+ import path from "path";
8
+ import Joi from "joi";
9
+
10
+ export type Core = {
11
+ axios: typeof axios,
12
+ moment: typeof moment,
13
+ lodash: typeof _,
14
+ env: Env,
15
+ t: ReturnType<typeof i18n>[`t`],
16
+ joi: typeof Joi,
17
+ };
18
+
19
+ const axiosLogs = (method: string, debug = false): ProxyLogs<
20
+ typeof axios[`get`]
21
+ | typeof axios[`post`]
22
+ | typeof axios[`put`]
23
+ | typeof axios[`patch`]
24
+ | typeof axios[`delete`]> => ({
25
+ before: (name, [url]) => {
26
+ if (debug) { console.log(`> [${method}]`, url); }
27
+ },
28
+ after: (name, response: AxiosResponse) => {
29
+ if (debug) { console.log(`< [${method}]`, response.config.url, response.status); }
30
+ },
31
+ error: (name, error: AxiosError) => {
32
+ if (debug) { console.log(`< [${method}]`, error.config.url, error.status); }
33
+ },
34
+ });
35
+
36
+ type CoreOptions = {
37
+ path: string,
38
+ debug?: boolean,
39
+ locale?: string,
40
+ };
41
+
42
+ /* eslint-disable @typescript-eslint/unbound-method */
43
+ export const core = (options: CoreOptions): Core => ({
44
+ axios: accessProxy(axios, {
45
+ get: logProxy(`axios.get`, axios.get, axiosLogs(`GET`, options.debug)),
46
+ post: logProxy(`axios.post`, axios.post, axiosLogs(`POST`, options.debug)),
47
+ put: logProxy(`axios.put`, axios.put, axiosLogs(`PUT`, options.debug)),
48
+ patch: logProxy(`axios.patch`, axios.patch, axiosLogs(`PATCH`, options.debug)),
49
+ delete: logProxy(`axios.delete`, axios.delete, axiosLogs(`DELETE`, options.debug)),
50
+ }),
51
+ moment: moment,
52
+ lodash: _,
53
+ env: new Env(options.path),
54
+ t: i18n(path.join(options.path, `/locales`), { locale: options.locale }).t,
55
+ joi: Joi,
56
+ });
@@ -0,0 +1,9 @@
1
+ import axios from "axios";
2
+
3
+ export const getCategories = async (): Promise<string[]> => {
4
+ try {
5
+ const { data } = await axios.get(`https://dev-beseif.s3.eu-west-1.amazonaws.com/prow/categories.txt`);
6
+ if (!data || typeof data !== `string`) { throw new Error(`Could not obtain category list`); }
7
+ return data.split(`\n`).map((d) => d.trim());
8
+ } catch (e) { throw e; }
9
+ };