@beseif-solutions/prow-core 0.2.8 → 0.3.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.
@@ -3,7 +3,7 @@ import { Core } from "../core";
3
3
  export type CoreConfig = {
4
4
  inputs?: Record<string, any>;
5
5
  credentials?: Record<string, any>;
6
- outputs?: Record<string, any>;
6
+ outputs?: any;
7
7
  };
8
8
  export type CoreFunction<Config extends CoreConfig = {}> = (core: Core, configuration: ({
9
9
  sandbox: boolean;
@@ -1,7 +1,7 @@
1
1
  import Joi from "joi";
2
2
  import { Field } from "../minified-utils/fields";
3
3
  import { Common, CoreConfig, CoreFunction } from "./commons";
4
- import { OneOrArray } from "../minified-utils/types";
4
+ import { ObjectOrArray } from "../minified-utils/types";
5
5
  type CommonConnectableEvent<Keys extends string = string> = {
6
6
  key: Keys;
7
7
  };
@@ -35,9 +35,7 @@ type SetupEventConfig = EventConfig & {
35
35
  type MemoryEventConfig = EventConfig & {
36
36
  memory?: Record<string, any>;
37
37
  };
38
- type CommonEvents<Config extends EventConfig = {
39
- fields: Record<string, any>;
40
- }> = Common<Config> & {
38
+ type CommonEvents<Config extends EventConfig> = Common<Config> & {
41
39
  model: `event`;
42
40
  categorization: {
43
41
  department: string;
@@ -59,10 +57,7 @@ export type Request = {
59
57
  query: Record<string, any>;
60
58
  body: any;
61
59
  };
62
- export type ImmediateTrigger<Config extends SetupEventConfig = {
63
- fields: Record<string, any>;
64
- setup: Record<string, any>;
65
- }> = CommonEvents<Config> & {
60
+ export type ImmediateTrigger<Config extends SetupEventConfig> = CommonEvents<Config> & {
66
61
  type: `trigger`;
67
62
  immediate: true;
68
63
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>];
@@ -139,9 +134,7 @@ export type ImmediateTrigger<Config extends SetupEventConfig = {
139
134
  }>;
140
135
  };
141
136
  };
142
- export type ScheduledTrigger<Config extends EventConfig = {
143
- fields: Record<string, any>;
144
- }> = CommonEvents<Config> & {
137
+ export type ScheduledTrigger<Config extends EventConfig> = CommonEvents<Config> & {
145
138
  type: `trigger`;
146
139
  immediate: false;
147
140
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>];
@@ -160,22 +153,15 @@ export type ScheduledTrigger<Config extends EventConfig = {
160
153
  }>;
161
154
  };
162
155
  };
163
- export type Trigger<Config extends EventConfig = {
164
- fields: Record<string, any>;
165
- }> = ImmediateTrigger<Config> | ScheduledTrigger<Config>;
156
+ export type Trigger<Config extends EventConfig = {}> = ImmediateTrigger<Config> | ScheduledTrigger<Config>;
166
157
  type StandardOutput<Config extends EventConfig> = {
167
- output: OneOrArray<Config[`outputs`]>;
158
+ output: ObjectOrArray<Config[`outputs`]>;
168
159
  flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
169
160
  };
170
- type MemoryOutput<Config extends MemoryEventConfig = {
171
- memory: Record<string, any>;
172
- }> = {
161
+ type MemoryOutput<Config extends MemoryEventConfig> = {
173
162
  memory: Config[`memory`];
174
163
  } & (StandardOutput<Config> | {});
175
- export type SyncAction<Config extends MemoryEventConfig = {
176
- fields: Record<string, any>;
177
- memory: Record<string, any>;
178
- }> = CommonEvents<Config> & {
164
+ export type SyncAction<Config extends MemoryEventConfig> = CommonEvents<Config> & {
179
165
  type: `action`;
180
166
  inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]];
181
167
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]];
@@ -191,10 +177,7 @@ export type SyncAction<Config extends MemoryEventConfig = {
191
177
  }>;
192
178
  };
193
179
  };
194
- export type AsyncAction<Config extends SetupEventConfig = {
195
- fields: Record<string, any>;
196
- setup: Record<string, any>;
197
- }> = CommonEvents<Config> & {
180
+ export type AsyncAction<Config extends SetupEventConfig & MemoryEventConfig> = CommonEvents<Config> & {
198
181
  type: `action`;
199
182
  inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]];
200
183
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]];
@@ -229,9 +212,11 @@ export type AsyncAction<Config extends SetupEventConfig = {
229
212
  flags: Partial<Record<Config[`flags`][`inputs`][number], true>>;
230
213
  link: string;
231
214
  setup?: Config[`setup`];
215
+ memory?: Config[`memory`];
232
216
  };
233
217
  outputs: {
234
218
  done: boolean;
219
+ memory?: Config[`memory`];
235
220
  };
236
221
  }>;
237
222
  handle: CoreFunction<{
@@ -240,6 +225,7 @@ export type AsyncAction<Config extends SetupEventConfig = {
240
225
  fields: Config[`fields`];
241
226
  request: Request;
242
227
  setup?: Config[`setup`];
228
+ memory?: Config[`memory`];
243
229
  };
244
230
  outputs: StandardOutput<Config>;
245
231
  }>;
@@ -249,6 +235,7 @@ export type AsyncAction<Config extends SetupEventConfig = {
249
235
  fields: Config[`fields`];
250
236
  link: string;
251
237
  setup?: Config[`setup`];
238
+ memory?: Config[`memory`];
252
239
  };
253
240
  outputs: {
254
241
  done: boolean;
@@ -256,12 +243,8 @@ export type AsyncAction<Config extends SetupEventConfig = {
256
243
  }>;
257
244
  };
258
245
  };
259
- export type Action<Config extends EventConfig = {
260
- fields: Record<string, any>;
261
- }> = SyncAction<Config> | AsyncAction<Config>;
262
- export type Event<Config extends EventConfig = {
263
- fields: Record<string, any>;
264
- }> = Action<Config> | Trigger<Config>;
246
+ export type Action<Config extends EventConfig = {}> = SyncAction<Config> | AsyncAction<Config>;
247
+ export type Event<Config extends EventConfig = {}> = Action<Config> | Trigger<Config>;
265
248
  export declare const scheduledTriggerSchema: () => Joi.ObjectSchema<any>;
266
249
  export declare const immediateTriggerSchema: () => Joi.ObjectSchema<any>;
267
250
  export declare const triggerSchema: () => Joi.AlternativesSchema<any>;
@@ -9,4 +9,4 @@ export type DeepPartial<T extends Record<string, any>> = {
9
9
  [P in keyof T]?: T[P] extends Record<string, any> ? DeepPartial<T[P]> : T[P];
10
10
  };
11
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;
12
- export type OneOrArray<T> = T | T[];
12
+ export type ObjectOrArray<T> = T extends any[] ? T : T extends Record<string, any> ? T | T[] : T[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.2.8",
3
+ "version": "0.3.1",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -4,7 +4,7 @@ import { Core } from "../core";
4
4
  export type CoreConfig = {
5
5
  inputs?: Record<string, any>,
6
6
  credentials?: Record<string, any>,
7
- outputs?: Record<string, any>,
7
+ outputs?: any,
8
8
  };
9
9
 
10
10
  export type CoreFunction<Config extends CoreConfig = {}> = (core: Core, configuration: ({
@@ -1,7 +1,7 @@
1
1
  import Joi from "joi";
2
2
  import { Field, fieldsSchema } from "../minified-utils/fields";
3
3
  import { Common, commonSchema, CoreConfig, CoreFunction, idSchema } from "./commons";
4
- import { OneOrArray } from "../minified-utils/types";
4
+ import { ObjectOrArray } from "../minified-utils/types";
5
5
 
6
6
  type CommonConnectableEvent<Keys extends string = string> = {
7
7
  key: Keys,
@@ -45,7 +45,7 @@ type MemoryEventConfig = EventConfig & {
45
45
  memory?: Record<string, any>,
46
46
  };
47
47
 
48
- type CommonEvents<Config extends EventConfig = { fields: Record<string, any> }> = Common<Config> & {
48
+ type CommonEvents<Config extends EventConfig> = Common<Config> & {
49
49
  model: `event`,
50
50
  categorization: {
51
51
  department: string,
@@ -69,7 +69,7 @@ export type Request = {
69
69
  body: any,
70
70
  };
71
71
 
72
- export type ImmediateTrigger<Config extends SetupEventConfig = { fields: Record<string, any>, setup: Record<string, any> }> = CommonEvents<Config> & {
72
+ export type ImmediateTrigger<Config extends SetupEventConfig> = CommonEvents<Config> & {
73
73
  type: `trigger`,
74
74
  immediate: true,
75
75
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>],
@@ -107,7 +107,7 @@ export type ImmediateTrigger<Config extends SetupEventConfig = { fields: Record<
107
107
  },
108
108
  };
109
109
 
110
- export type ScheduledTrigger<Config extends EventConfig = { fields: Record<string, any> }> = CommonEvents<Config> & {
110
+ export type ScheduledTrigger<Config extends EventConfig> = CommonEvents<Config> & {
111
111
  type: `trigger`,
112
112
  immediate: false,
113
113
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>],
@@ -120,18 +120,18 @@ export type ScheduledTrigger<Config extends EventConfig = { fields: Record<strin
120
120
  },
121
121
  };
122
122
 
123
- export type Trigger<Config extends EventConfig = { fields: Record<string, any> }> =
123
+ export type Trigger<Config extends EventConfig = {}> =
124
124
  | ImmediateTrigger<Config>
125
125
  | ScheduledTrigger<Config>;
126
126
 
127
127
  type StandardOutput<Config extends EventConfig> =
128
- { output: OneOrArray<Config[`outputs`]>, flags: Partial<Record<Config[`flags`][`outputs`][number], true>> };
128
+ { output: ObjectOrArray<Config[`outputs`]>, flags: Partial<Record<Config[`flags`][`outputs`][number], true>> };
129
129
 
130
- type MemoryOutput<Config extends MemoryEventConfig = { memory: Record<string, any> }> = {
130
+ type MemoryOutput<Config extends MemoryEventConfig> = {
131
131
  memory: Config[`memory`],
132
132
  } & (StandardOutput<Config> | {});
133
133
 
134
- export type SyncAction<Config extends MemoryEventConfig = { fields: Record<string, any>, memory: Record<string, any> }> = CommonEvents<Config> & {
134
+ export type SyncAction<Config extends MemoryEventConfig> = CommonEvents<Config> & {
135
135
  type: `action`,
136
136
  inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]],
137
137
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]],
@@ -144,7 +144,7 @@ export type SyncAction<Config extends MemoryEventConfig = { fields: Record<strin
144
144
  },
145
145
  };
146
146
 
147
- export type AsyncAction<Config extends SetupEventConfig = { fields: Record<string, any>, setup: Record<string, any> }> = CommonEvents<Config> & {
147
+ export type AsyncAction<Config extends SetupEventConfig & MemoryEventConfig> = CommonEvents<Config> & {
148
148
  type: `action`,
149
149
  inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]],
150
150
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]],
@@ -162,26 +162,26 @@ export type AsyncAction<Config extends SetupEventConfig = { fields: Record<strin
162
162
  }>,
163
163
  execute: CoreFunction<{
164
164
  credentials: Config[`credentials`],
165
- inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, link: string, setup?: Config[`setup`] },
166
- outputs: { done: boolean },
165
+ inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, link: string, setup?: Config[`setup`], memory?: Config[`memory`] },
166
+ outputs: { done: boolean, memory?: Config[`memory`] },
167
167
  }>,
168
168
  handle: CoreFunction<{
169
169
  credentials: Config[`credentials`],
170
- inputs: { fields: Config[`fields`], request: Request, setup?: Config[`setup`] },
170
+ inputs: { fields: Config[`fields`], request: Request, setup?: Config[`setup`], memory?: Config[`memory`] },
171
171
  outputs: StandardOutput<Config>,
172
172
  }>,
173
173
  fire?: CoreFunction<{
174
174
  credentials: Config[`credentials`],
175
- inputs: { fields: Config[`fields`], link: string, setup?: Config[`setup`] },
175
+ inputs: { fields: Config[`fields`], link: string, setup?: Config[`setup`], memory?: Config[`memory`] },
176
176
  outputs: { done: boolean },
177
177
  }>,
178
178
  },
179
179
  };
180
- export type Action<Config extends EventConfig = { fields: Record<string, any> }> =
180
+ export type Action<Config extends EventConfig = {}> =
181
181
  | SyncAction<Config>
182
182
  | AsyncAction<Config>;
183
183
 
184
- export type Event<Config extends EventConfig = { fields: Record<string, any> }> =
184
+ export type Event<Config extends EventConfig = {}> =
185
185
  | Action<Config>
186
186
  | Trigger<Config>;
187
187
 
@@ -17,4 +17,7 @@ export type AsyncReturnType<T extends (...args: any[]) => any> =
17
17
  T extends (...args: any[]) => infer U ? U :
18
18
  any;
19
19
 
20
- export type OneOrArray<T> = T | T[];
20
+ export type ObjectOrArray<T> =
21
+ T extends any[] ? T
22
+ : T extends Record<string, any> ? T | T[]
23
+ : T[];