@beseif-solutions/prow-core 0.4.0 → 0.4.2

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/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  export { Core, core } from './core';
2
2
  export { CoreFunction, idSchema } from './entities/commons';
3
- export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
4
- export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, SyncAction, syncActionSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
3
+ export { Credentials, OAuthCredentials, SessionCredentials, StaticCredentials, credentialsSchema, oauthCredentialsSchema, sessionCredentialsSchema, staticCredentialsSchema } from './entities/credentials';
4
+ export { Action, AsyncAction, Event, ImmediateTrigger, Request, ScheduledTrigger, SyncAction, Trigger, actionOutputSchema, actionSchema, eventSchema, immediateTriggerSchema, scheduledTriggerSchema, syncActionSchema, triggerOutputSchema, triggerSchema } from './entities/events';
5
5
  export { Provider, providerSchema } from './entities/provider';
6
6
  export { Source } from './entities/source';
7
- export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
8
- export { DEFAULT_LOCALE, i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
7
+ export { hasExpression, isExpression, split } from './minified-utils/context';
8
+ export { Condition, Field, File, SelectFieldChoice, ValidationResult, alter, extract, fieldSchema, fieldsSchema, validate } from './minified-utils/fields';
9
+ export { DEFAULT_LOCALE, LocalizedField, LocalizedProperties, i18n, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
9
10
  export { Properties } from './minified-utils/properties';
10
11
  export { Protocol } from './minified-utils/protocol';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeGroup = exports.localizeFields = exports.i18n = exports.DEFAULT_LOCALE = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.alter = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.syncActionSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.actionOutputSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.core = void 0;
3
+ exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeGroup = exports.localizeFields = exports.i18n = exports.DEFAULT_LOCALE = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.alter = exports.split = exports.isExpression = exports.hasExpression = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.syncActionSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.actionOutputSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.core = void 0;
4
4
  var core_1 = require("./core");
5
5
  Object.defineProperty(exports, "core", { enumerable: true, get: function () { return core_1.core; } });
6
6
  var commons_1 = require("./entities/commons");
@@ -21,6 +21,10 @@ Object.defineProperty(exports, "triggerOutputSchema", { enumerable: true, get: f
21
21
  Object.defineProperty(exports, "triggerSchema", { enumerable: true, get: function () { return events_1.triggerSchema; } });
22
22
  var provider_1 = require("./entities/provider");
23
23
  Object.defineProperty(exports, "providerSchema", { enumerable: true, get: function () { return provider_1.providerSchema; } });
24
+ var context_1 = require("./minified-utils/context");
25
+ Object.defineProperty(exports, "hasExpression", { enumerable: true, get: function () { return context_1.hasExpression; } });
26
+ Object.defineProperty(exports, "isExpression", { enumerable: true, get: function () { return context_1.isExpression; } });
27
+ Object.defineProperty(exports, "split", { enumerable: true, get: function () { return context_1.split; } });
24
28
  var fields_1 = require("./minified-utils/fields");
25
29
  Object.defineProperty(exports, "alter", { enumerable: true, get: function () { return fields_1.alter; } });
26
30
  Object.defineProperty(exports, "extract", { enumerable: true, get: function () { return fields_1.extract; } });
@@ -1,4 +1,7 @@
1
1
  import { Field } from "./fields";
2
+ export declare const isExpression: (value: any) => boolean;
3
+ export declare const hasExpression: (value: any) => boolean;
4
+ export declare const split: (value: string) => string[];
2
5
  declare class Context {
3
6
  readonly resolve: (field: Field, source: any, data: Record<string, any>) => any;
4
7
  }
@@ -3,7 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.split = exports.hasExpression = exports.isExpression = void 0;
6
7
  const lodash_1 = __importDefault(require("lodash"));
8
+ const IS_EXPRESSION_REGEX = /^{{2,3}[^}]+}{2,3}$/;
9
+ const isExpression = (value) => typeof value === `string` ? IS_EXPRESSION_REGEX.test(value) : false;
10
+ exports.isExpression = isExpression;
11
+ const HAS_EXPRESSION_REGEX = /{{2,3}[^}]+}{2,3}/;
12
+ const hasExpression = (value) => typeof value === `string` ? HAS_EXPRESSION_REGEX.test(value) : false;
13
+ exports.hasExpression = hasExpression;
14
+ const SPLIT_REGEX = /{{2,3}[^}]+}{2,3}|[^{}]+/g;
15
+ const split = (value) => typeof value === `string` ? Array.from(value.match(SPLIT_REGEX) || []) : [];
16
+ exports.split = split;
7
17
  class Context {
8
18
  constructor() {
9
19
  this.resolve = (field, source, data) => {
@@ -22,14 +32,14 @@ class Context {
22
32
  else {
23
33
  return source;
24
34
  }
25
- if (!unresolved || !unresolved.includes(`{{`)) {
35
+ if (!unresolved || !(0, exports.hasExpression)(unresolved)) {
26
36
  return source;
27
37
  }
28
38
  const clonedData = lodash_1.default.cloneDeep(data);
29
- const parts = Array.from(unresolved.match(/{{[^}]+}}|[^{}]+/g) || []);
39
+ const parts = (0, exports.split)(unresolved);
30
40
  let resolved = unresolved;
31
41
  for (const expression of parts) {
32
- if (!expression.startsWith(`{{`)) {
42
+ if (!(0, exports.isExpression)(expression)) {
33
43
  continue;
34
44
  }
35
45
  const path = expression.replace(/^{+/g, ``).replace(/}+$/g, ``);
@@ -11,7 +11,6 @@ type Common = {
11
11
  required?: boolean;
12
12
  as_password?: boolean;
13
13
  show?: boolean;
14
- show_label?: boolean;
15
14
  t?: string;
16
15
  } & ({
17
16
  as_array?: false;
@@ -20,7 +19,7 @@ type Common = {
20
19
  array_min?: number;
21
20
  array_max?: number;
22
21
  array_length?: number;
23
- });
22
+ }) & Record<`experimental_${string}`, any>;
24
23
  export type Field<Extend = Record<never, never>> = Common & InputField<Extend>;
25
24
  type InputField<Extend = Record<never, never>> = (AnyInputField<Extend> | StringInputField<Extend> | NumberInputField<Extend> | BooleanInputField<Extend> | DateTimeInputField<Extend> | DateInputField<Extend> | TimeInputField<Extend> | DictInputField<Extend> | FileInputField<Extend>) & Extend;
26
25
  type Any = string | number | boolean | Any[] | {
@@ -102,6 +101,7 @@ type SelectField<Values = string | number | boolean | File, Extend = Record<neve
102
101
  export type SelectFieldChoice<Values = string | number | boolean | File, Extend = Record<never, never>> = {
103
102
  key: string;
104
103
  value: Values;
104
+ group?: string;
105
105
  } & Extend;
106
106
  type CustomDisplayTextField = {
107
107
  format: `textarea` | `rich-text` | `markdown`;
@@ -20,7 +20,6 @@ const commonFieldSchema = () => joi_1.default.object({
20
20
  required: joi_1.default.bool(),
21
21
  as_password: joi_1.default.bool(),
22
22
  show: joi_1.default.bool(),
23
- show_label: joi_1.default.bool().default(true),
24
23
  t: joi_1.default.string(),
25
24
  as_array: joi_1.default.bool(),
26
25
  array_min: joi_1.default.when(`as_array`, {
@@ -38,7 +37,8 @@ const commonFieldSchema = () => joi_1.default.object({
38
37
  then: joi_1.default.number(),
39
38
  otherwise: joi_1.default.forbidden(),
40
39
  }),
41
- });
40
+ }).concat(joi_1.default.object()
41
+ .pattern(joi_1.default.string().regex(/^experimental_/), joi_1.default.any()));
42
42
  const types = [`any`, `string`, `number`, `boolean`, `date`, `datetime`, `time`, `dict`, `file`];
43
43
  const inputFieldBaseSchema = () => joi_1.default.object({
44
44
  type: joi_1.default.string().required()
@@ -49,6 +49,7 @@ const inputFieldBaseSchema = () => joi_1.default.object({
49
49
  const choiceSchema = (type) => joi_1.default.object({
50
50
  key: joi_1.default.string().required(),
51
51
  value: type.required(),
52
+ group: joi_1.default.string(),
52
53
  }).unknown();
53
54
  const choicesSchema = (type) => joi_1.default.alternatives(joi_1.default.string(), joi_1.default.array().min(1)
54
55
  .items(choiceSchema(type)));
@@ -185,7 +186,8 @@ const fileReplacer = (field) => ({
185
186
  },
186
187
  ],
187
188
  default: field.default,
188
- ...lodash_1.default.pick(field, [`altered_by`, `disabled`, `required`, `as_password`, `show`, `show_label`, `as_array`, `array_min`, `array_max`, `array_length`]),
189
+ ...lodash_1.default.pick(field, [`altered_by`, `disabled`, `required`, `as_password`, `show`, `as_array`, `array_min`, `array_max`, `array_length`]),
190
+ ...Object.assign({}, ...Object.entries(field).map(([k, v]) => k.startsWith(`experimental_`) ? { [k]: v } : {})),
189
191
  });
190
192
  const fileInputFieldSchema = () => joi_1.default.object({
191
193
  default: defaultSchema(fileSchema()),
@@ -7,6 +7,7 @@ import { Source } from '../entities/source';
7
7
  export type LocalizedField = {
8
8
  label: string;
9
9
  help: string;
10
+ ui?: Record<string, any>;
10
11
  };
11
12
  export type LocalizedProperties = {
12
13
  name: string;
@@ -98,6 +98,7 @@ const localizeField = (t, element, field, recursive = {}) => {
98
98
  const root = field.t || recursive.t || `${element}.fields`;
99
99
  field.label = t(`${root}.${key}.label`, { fallback: true });
100
100
  field.help = t(`${root}.${key}.help`);
101
+ field.ui = t(`${root}.${key}.ui`, { fallback: true, optional: true });
101
102
  if (field.type === `dict` && field.items) {
102
103
  field.items = field.items.map((f) => localizeField(t, element, f, { parent: `${key}.items`, t: field.t }));
103
104
  }
@@ -106,6 +107,7 @@ const localizeField = (t, element, field, recursive = {}) => {
106
107
  ...fc,
107
108
  label: t(`${root}.${key}.choices.${fc.key}.label`, { fallback: true }),
108
109
  help: t(`${root}.${key}.choices.${fc.key}.help`),
110
+ ...fc.group && { group: t(`${root}.${key}.groups.${fc.group}`, { fallback: true }) },
109
111
  }));
110
112
  }
111
113
  return field;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -322,8 +322,6 @@ export const asyncActionSchema = () =>
322
322
  .min(1)
323
323
  .required(),
324
324
  functions: Joi.object({
325
- // mount: Joi.function(),
326
- // unmount: Joi.function(),
327
325
  execute: Joi.function().required(),
328
326
  handle: Joi.function().required(),
329
327
  fire: Joi.function(),
package/src/index.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  export { Core, core } from './core';
2
2
  export { CoreFunction, idSchema } from './entities/commons';
3
- export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
4
- export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, SyncAction, syncActionSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
3
+ export { Credentials, OAuthCredentials, SessionCredentials, StaticCredentials, credentialsSchema, oauthCredentialsSchema, sessionCredentialsSchema, staticCredentialsSchema } from './entities/credentials';
4
+ export { Action, AsyncAction, Event, ImmediateTrigger, Request, ScheduledTrigger, SyncAction, Trigger, actionOutputSchema, actionSchema, eventSchema, immediateTriggerSchema, scheduledTriggerSchema, syncActionSchema, triggerOutputSchema, triggerSchema } from './entities/events';
5
5
  export { Provider, providerSchema } from './entities/provider';
6
6
  export { Source } from './entities/source';
7
- export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
8
- export { DEFAULT_LOCALE, i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
7
+ export { hasExpression, isExpression, split } from './minified-utils/context';
8
+ export { Condition, Field, File, SelectFieldChoice, ValidationResult, alter, extract, fieldSchema, fieldsSchema, validate } from './minified-utils/fields';
9
+ export { DEFAULT_LOCALE, LocalizedField, LocalizedProperties, i18n, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
9
10
  export { Properties } from './minified-utils/properties';
10
11
  export { Protocol } from './minified-utils/protocol';
@@ -1,6 +1,18 @@
1
1
  import _ from "lodash";
2
2
  import { Field } from "./fields";
3
3
 
4
+ const IS_EXPRESSION_REGEX = /^{{2,3}[^}]+}{2,3}$/;
5
+ export const isExpression = (value: any) =>
6
+ typeof value === `string` ? IS_EXPRESSION_REGEX.test(value) : false;
7
+
8
+ const HAS_EXPRESSION_REGEX = /{{2,3}[^}]+}{2,3}/;
9
+ export const hasExpression = (value: any) =>
10
+ typeof value === `string` ? HAS_EXPRESSION_REGEX.test(value) : false;
11
+
12
+ const SPLIT_REGEX = /{{2,3}[^}]+}{2,3}|[^{}]+/g;
13
+ export const split = (value: string) =>
14
+ typeof value === `string` ? Array.from(value.match(SPLIT_REGEX) || []) : [];
15
+
4
16
  class Context {
5
17
 
6
18
  public readonly resolve = (field: Field, source: any, data: Record<string, any>) => {
@@ -15,16 +27,16 @@ class Context {
15
27
  unresolved = source;
16
28
  } else { return source; }
17
29
 
18
- if (!unresolved || !unresolved.includes(`{{`)) { return source; }
30
+ if (!unresolved || !hasExpression(unresolved)) { return source; }
19
31
 
20
32
  const clonedData = _.cloneDeep(data);
21
33
 
22
-
23
- const parts = Array.from(unresolved.match(/{{[^}]+}}|[^{}]+/g) || []);
34
+ const parts = split(unresolved);
24
35
 
25
36
  let resolved: any = unresolved;
26
37
  for (const expression of parts) {
27
- if (!expression.startsWith(`{{`)) { continue; }
38
+ if (!isExpression(expression)) { continue; }
39
+
28
40
  const path = expression.replace(/^{+/g, ``).replace(/}+$/g, ``);
29
41
  const get = _.get(clonedData, path);
30
42
 
@@ -16,7 +16,6 @@ type Common = {
16
16
  required?: boolean,
17
17
  as_password?: boolean,
18
18
  show?: boolean,
19
- show_label?: boolean,
20
19
  t?: string,
21
20
  } & ({
22
21
  as_array?: false,
@@ -25,7 +24,10 @@ type Common = {
25
24
  array_min?: number,
26
25
  array_max?: number,
27
26
  array_length?: number,
28
- });
27
+ })
28
+ // experimental properties for custom front features
29
+ & Record<`experimental_${string}`, any>
30
+ ;
29
31
 
30
32
  export type Field<Extend = Record<never, never>> = Common & InputField<Extend>;
31
33
 
@@ -154,6 +156,7 @@ type SelectField<Values = string | number | boolean | File, Extend = Record<neve
154
156
  export type SelectFieldChoice<Values = string | number | boolean | File, Extend = Record<never, never>> = {
155
157
  key: string,
156
158
  value: Values,
159
+ group?: string,
157
160
  } & Extend;
158
161
 
159
162
  /* custom display configuration */
@@ -194,7 +197,6 @@ const commonFieldSchema = () =>
194
197
  required: Joi.bool(),
195
198
  as_password: Joi.bool(),
196
199
  show: Joi.bool(),
197
- show_label: Joi.bool().default(true),
198
200
  t: Joi.string(),
199
201
  as_array: Joi.bool(),
200
202
  array_min: Joi.when(`as_array`, {
@@ -212,7 +214,8 @@ const commonFieldSchema = () =>
212
214
  then: Joi.number(),
213
215
  otherwise: Joi.forbidden(),
214
216
  }),
215
- });
217
+ }).concat(Joi.object() // experimental properties for custom front features
218
+ .pattern(Joi.string().regex(/^experimental_/), Joi.any()));
216
219
 
217
220
  const types = [`any`, `string`, `number`, `boolean`, `date`, `datetime`, `time`, `dict`, `file`];
218
221
 
@@ -229,6 +232,7 @@ const choiceSchema = (type: Joi.Schema) =>
229
232
  Joi.object({
230
233
  key: Joi.string().required(),
231
234
  value: type.required(),
235
+ group: Joi.string(),
232
236
  }).unknown();
233
237
 
234
238
  const choicesSchema = (type: Joi.Schema) =>
@@ -398,7 +402,8 @@ const fileReplacer = (field: Common & FileInputField): Field => ({
398
402
  },
399
403
  ],
400
404
  default: field.default,
401
- ..._.pick(field, [`altered_by`, `disabled`, `required`, `as_password`, `show`, `show_label`, `as_array`, `array_min`, `array_max`, `array_length`]),
405
+ ..._.pick(field, [`altered_by`, `disabled`, `required`, `as_password`, `show`, `as_array`, `array_min`, `array_max`, `array_length`]),
406
+ ...Object.assign({}, ...Object.entries(field).map(([k, v]) => k.startsWith(`experimental_`) ? { [k]: v } : {})),
402
407
  }) as Field;
403
408
 
404
409
  const fileInputFieldSchema = () =>
@@ -11,6 +11,7 @@ import { Source } from '../entities/source';
11
11
  export type LocalizedField = {
12
12
  label: string,
13
13
  help: string,
14
+ ui?: Record<string, any>,
14
15
  };
15
16
 
16
17
  export type LocalizedProperties = {
@@ -142,6 +143,7 @@ const localizeField = (
142
143
 
143
144
  field.label = t(`${root}.${key}.label`, { fallback: true });
144
145
  field.help = t(`${root}.${key}.help`);
146
+ field.ui = t(`${root}.${key}.ui`, { fallback: true, optional: true });
145
147
 
146
148
  if (field.type === `dict` && field.items) {
147
149
  field.items = field.items.map((f) => localizeField(t, element, f, { parent: `${key}.items`, t: field.t }));
@@ -150,6 +152,7 @@ const localizeField = (
150
152
  ...fc,
151
153
  label: t(`${root}.${key}.choices.${fc.key}.label`, { fallback: true }),
152
154
  help: t(`${root}.${key}.choices.${fc.key}.help`),
155
+ ...fc.group && { group: t(`${root}.${key}.groups.${fc.group}`, { fallback: true }) },
153
156
  }));
154
157
  }
155
158