@beseif-solutions/prow-core 0.3.16 → 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.
@@ -169,13 +169,14 @@ export type ScheduledTrigger<Config extends EventConfig> = CommonEvents<Config>
169
169
  };
170
170
  };
171
171
  export type Trigger<Config extends EventConfig = {}> = ImmediateTrigger<Config> | ScheduledTrigger<Config>;
172
- type StandardOutput<Config extends EventConfig> = {
172
+ type StandardOutputWithMemory<Config extends MemoryEventConfig> = {
173
173
  output: ObjectOrArray<Config[`outputs`]>;
174
174
  flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
175
+ memory?: Config[`memory`];
175
176
  };
176
- type MemoryOutput<Config extends MemoryEventConfig> = {
177
+ type OnlyMemoryOutput<Config extends MemoryEventConfig> = {
177
178
  memory: Config[`memory`];
178
- } & (StandardOutput<Config> | {});
179
+ };
179
180
  export type SyncAction<Config extends MemoryEventConfig> = CommonEvents<Config> & {
180
181
  type: `action`;
181
182
  inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]];
@@ -188,7 +189,7 @@ export type SyncAction<Config extends MemoryEventConfig> = CommonEvents<Config>
188
189
  flags: Partial<Record<Config[`flags`][`inputs`][number], true>>;
189
190
  memory?: Config[`memory`];
190
191
  } & SourcePreferences<Config>;
191
- outputs: StandardOutput<Config> | MemoryOutput<Config>;
192
+ outputs: StandardOutputWithMemory<Config> | OnlyMemoryOutput<Config>;
192
193
  }>;
193
194
  };
194
195
  };
@@ -209,7 +210,7 @@ export type AsyncAction<Config extends MemoryEventConfig> = CommonEvents<Config>
209
210
  outputs: {
210
211
  done: boolean;
211
212
  memory?: Config[`memory`];
212
- };
213
+ } | StandardOutputWithMemory<Config>;
213
214
  }>;
214
215
  handle: CoreFunction<{
215
216
  credentials: Config[`credentials`];
@@ -218,7 +219,7 @@ export type AsyncAction<Config extends MemoryEventConfig> = CommonEvents<Config>
218
219
  request: Request;
219
220
  memory?: Config[`memory`];
220
221
  } & SourcePreferences<Config>;
221
- outputs: StandardOutput<Config>;
222
+ outputs: StandardOutputWithMemory<Config>;
222
223
  }>;
223
224
  fire?: CoreFunction<{
224
225
  credentials: Config[`credentials`];
@@ -134,10 +134,8 @@ const actionOutputSchema = () => joi_1.default.alternatives(joi_1.default.object
134
134
  flags: joi_1.default.object()
135
135
  .pattern(joi_1.default.string(), joi_1.default.valid(true))
136
136
  .required(),
137
+ memory: joi_1.default.object(),
137
138
  }), joi_1.default.object({
138
139
  memory: joi_1.default.object().required(),
139
- output: joi_1.default.alternatives(joi_1.default.array(), joi_1.default.object()),
140
- flags: joi_1.default.object()
141
- .pattern(joi_1.default.string(), joi_1.default.valid(true)),
142
- }).and(`output`, `flags`));
140
+ }));
143
141
  exports.actionOutputSchema = actionOutputSchema;
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.3.16",
3
+ "version": "0.4.1",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -135,12 +135,15 @@ export type Trigger<Config extends EventConfig = {}> =
135
135
  | ImmediateTrigger<Config>
136
136
  | ScheduledTrigger<Config>;
137
137
 
138
- type StandardOutput<Config extends EventConfig> =
139
- { output: ObjectOrArray<Config[`outputs`]>, flags: Partial<Record<Config[`flags`][`outputs`][number], true>> };
138
+ type StandardOutputWithMemory<Config extends MemoryEventConfig> = {
139
+ output: ObjectOrArray<Config[`outputs`]>,
140
+ flags: Partial<Record<Config[`flags`][`outputs`][number], true>>,
141
+ memory?: Config[`memory`],
142
+ };
140
143
 
141
- type MemoryOutput<Config extends MemoryEventConfig> = {
144
+ type OnlyMemoryOutput<Config extends MemoryEventConfig> = {
142
145
  memory: Config[`memory`],
143
- } & (StandardOutput<Config> | {});
146
+ };
144
147
 
145
148
  export type SyncAction<Config extends MemoryEventConfig> = CommonEvents<Config> & {
146
149
  type: `action`,
@@ -150,7 +153,7 @@ export type SyncAction<Config extends MemoryEventConfig> = CommonEvents<Config>
150
153
  execute: CoreFunction<{
151
154
  credentials: Config[`credentials`],
152
155
  inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, memory?: Config[`memory`] } & SourcePreferences<Config>,
153
- outputs: StandardOutput<Config> | MemoryOutput<Config>,
156
+ outputs: StandardOutputWithMemory<Config> | OnlyMemoryOutput<Config>,
154
157
  }>,
155
158
  },
156
159
  };
@@ -164,12 +167,12 @@ export type AsyncAction<Config extends MemoryEventConfig> = CommonEvents<Config>
164
167
  execute: CoreFunction<{
165
168
  credentials: Config[`credentials`],
166
169
  inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, link: string, memory?: Config[`memory`] } & SourcePreferences<Config>,
167
- outputs: { done: boolean, memory?: Config[`memory`] },
170
+ outputs: { done: boolean, memory?: Config[`memory`] } | StandardOutputWithMemory<Config>,
168
171
  }>,
169
172
  handle: CoreFunction<{
170
173
  credentials: Config[`credentials`],
171
174
  inputs: { fields: Config[`fields`], request: Request, memory?: Config[`memory`] } & SourcePreferences<Config>,
172
- outputs: StandardOutput<Config>,
175
+ outputs: StandardOutputWithMemory<Config>,
173
176
  }>,
174
177
  fire?: CoreFunction<{
175
178
  credentials: Config[`credentials`],
@@ -346,7 +349,7 @@ export const triggerOutputSchema = () =>
346
349
 
347
350
  export const actionOutputSchema = () =>
348
351
  Joi.alternatives(
349
- // standard output
352
+ // standard output + memory
350
353
  Joi.object({
351
354
  output: Joi.alternatives(
352
355
  Joi.array(),
@@ -355,15 +358,10 @@ export const actionOutputSchema = () =>
355
358
  flags: Joi.object()
356
359
  .pattern(Joi.string(), Joi.valid(true))
357
360
  .required(),
361
+ memory: Joi.object(),
358
362
  }),
359
- // memory output
363
+ // only memory output
360
364
  Joi.object({
361
365
  memory: Joi.object().required(),
362
- output: Joi.alternatives(
363
- Joi.array(),
364
- Joi.object(),
365
- ),
366
- flags: Joi.object()
367
- .pattern(Joi.string(), Joi.valid(true)),
368
- }).and(`output`, `flags`),
366
+ }),
369
367
  );
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