@beseif-solutions/prow-core 0.4.0 → 0.4.1

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
@@ -4,6 +4,7 @@ export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchem
4
4
  export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, SyncAction, syncActionSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
5
5
  export { Provider, providerSchema } from './entities/provider';
6
6
  export { Source } from './entities/source';
7
+ export { hasExpression, isExpression, split } from './minified-utils/context';
7
8
  export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
8
9
  export { DEFAULT_LOCALE, i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
9
10
  export { Properties } from './minified-utils/properties';
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, ``);
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.1",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchem
4
4
  export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, SyncAction, syncActionSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
5
5
  export { Provider, providerSchema } from './entities/provider';
6
6
  export { Source } from './entities/source';
7
+ export { hasExpression, isExpression, split } from './minified-utils/context';
7
8
  export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
8
9
  export { DEFAULT_LOCALE, i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
9
10
  export { Properties } from './minified-utils/properties';
@@ -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