@beseif-solutions/prow-core 0.4.1 → 0.4.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/index.d.ts CHANGED
@@ -1,11 +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
7
  export { hasExpression, isExpression, split } from './minified-utils/context';
8
- export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
9
- export { DEFAULT_LOCALE, i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
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';
10
10
  export { Properties } from './minified-utils/properties';
11
11
  export { Protocol } from './minified-utils/protocol';
@@ -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,16 @@ 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
+ ui: {
111
+ ...t(`${root}.${key}.choices.${fc.key}.ui`, { fallback: true, optional: true }) || {},
112
+ ...fc.group && {
113
+ group: {
114
+ key: fc.group,
115
+ label: t(`${root}.${key}.groups.${fc.group}.label`, { fallback: true }),
116
+ help: t(`${root}.${key}.groups.${fc.group}.help`),
117
+ },
118
+ },
119
+ },
109
120
  }));
110
121
  }
111
122
  return field;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
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,11 +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
7
  export { hasExpression, isExpression, split } from './minified-utils/context';
8
- export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
9
- export { DEFAULT_LOCALE, i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
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';
10
10
  export { Properties } from './minified-utils/properties';
11
11
  export { Protocol } from './minified-utils/protocol';
@@ -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,14 +143,25 @@ 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 }));
148
150
  } else if (`format` in field && field.format === `select` && _.isArray(field.choices)) {
149
- field.choices = field.choices.map((fc: SelectFieldChoice<any, LocalizedField>) => ({
151
+ field.choices = field.choices.map((fc: SelectFieldChoice<any, {}>): SelectFieldChoice<any, LocalizedField> => ({
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
+ ui: {
156
+ ...t(`${root}.${key}.choices.${fc.key}.ui`, { fallback: true, optional: true }) || {},
157
+ ...fc.group && {
158
+ group: {
159
+ key: fc.group,
160
+ label: t(`${root}.${key}.groups.${fc.group}.label`, { fallback: true }),
161
+ help: t(`${root}.${key}.groups.${fc.group}.help`),
162
+ },
163
+ },
164
+ },
153
165
  }));
154
166
  }
155
167