@beseif-solutions/prow-core 0.0.25 → 0.0.27

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/core.d.ts CHANGED
@@ -4,6 +4,16 @@ import moment from "moment-timezone";
4
4
  import { Properties } from "./minified-utils/properties";
5
5
  import { i18n } from "./minified-utils/locales";
6
6
  import Joi from "joi";
7
+ type SourceFunctions = {
8
+ register: <T>(source: string, data: T) => Promise<{
9
+ id: string;
10
+ }>;
11
+ consume: <T>(source: string) => Promise<{
12
+ id: string;
13
+ data: T;
14
+ }[]>;
15
+ unregister: (source: string, id: string) => Promise<void>;
16
+ };
7
17
  export type Core = {
8
18
  axios: typeof axios;
9
19
  moment: typeof moment;
@@ -11,11 +21,14 @@ export type Core = {
11
21
  env: Properties;
12
22
  t: ReturnType<typeof i18n>[`t`];
13
23
  joi: typeof Joi;
24
+ sources?: SourceFunctions;
14
25
  };
15
26
  type CoreOptions = {
16
- path: string;
27
+ root: string;
28
+ env?: Properties;
17
29
  debug?: boolean;
18
30
  locale?: string;
31
+ sources?: SourceFunctions;
19
32
  };
20
33
  export declare const core: (options: CoreOptions) => Core;
21
34
  export {};
package/dist/core.js CHANGED
@@ -12,6 +12,17 @@ const properties_1 = require("./minified-utils/properties");
12
12
  const locales_1 = require("./minified-utils/locales");
13
13
  const path_1 = __importDefault(require("path"));
14
14
  const joi_1 = __importDefault(require("joi"));
15
+ const FALLBACK_SOURCES = {
16
+ register: async () => {
17
+ throw new Error(`Sources not available: valid implementation not provided`);
18
+ },
19
+ consume: async () => {
20
+ throw new Error(`Sources not available: valid implementation not provided`);
21
+ },
22
+ unregister: async () => {
23
+ throw new Error(`Sources not available: valid implementation not provided`);
24
+ },
25
+ };
15
26
  const axiosLogs = (method, debug = false) => ({
16
27
  before: (name, [url]) => {
17
28
  if (debug) {
@@ -39,8 +50,9 @@ const core = (options) => ({
39
50
  }),
40
51
  moment: moment_timezone_1.default,
41
52
  lodash: lodash_1.default,
42
- env: new properties_1.Properties(options.path, `.env`),
43
- t: (0, locales_1.i18n)(path_1.default.join(options.path, `/locales`), { locale: options.locale }).t,
53
+ env: options.env || new properties_1.Properties(options.root, `.env`),
54
+ t: (0, locales_1.i18n)(path_1.default.join(options.root, `/locales`), { locale: options.locale }).t,
44
55
  joi: joi_1.default,
56
+ sources: options.sources || FALLBACK_SOURCES,
45
57
  });
46
58
  exports.core = core;
@@ -7,7 +7,7 @@ export type CoreConfig = {
7
7
  };
8
8
  export type CoreFunction<Config extends CoreConfig = {}> = (core: Core, configuration: ({
9
9
  sandbox: boolean;
10
- organization: string;
10
+ organization?: string;
11
11
  } & (Config[`inputs`] extends undefined ? {} : {
12
12
  inputs: Config[`inputs`];
13
13
  }) & (Config[`credentials`] extends undefined ? {} : {
@@ -13,11 +13,20 @@ type ErrorConnectableEvent<Keys extends string = string> = CommonConnectableEven
13
13
  };
14
14
  type AdditionalConnectableEvent<Keys extends string = string> = CommonConnectableEvent<Keys> & {};
15
15
  export type ConnectableEvent<Keys extends string = string> = DefaultConnectableEvent<Keys> | ErrorConnectableEvent<Keys> | AdditionalConnectableEvent<Keys>;
16
+ export type SourceConnection<Keys extends string = string> = {
17
+ role: `subscriber`;
18
+ id: Keys;
19
+ } | {
20
+ role: `consumer`;
21
+ id: Keys;
22
+ configurable?: boolean;
23
+ };
16
24
  type EventConfig = Pick<CoreConfig, `credentials` | `outputs`> & {
17
25
  flags?: {
18
26
  inputs?: string[];
19
27
  outputs: string[];
20
28
  };
29
+ sources?: string[];
21
30
  };
22
31
  type CommonEvents<Config extends EventConfig = {}> = Common<Config> & {
23
32
  model: `event`;
@@ -25,7 +34,8 @@ type CommonEvents<Config extends EventConfig = {}> = Common<Config> & {
25
34
  credentials: string[];
26
35
  sandbox: boolean;
27
36
  fields: Field[];
28
- examples: EventConfig[`outputs`][];
37
+ examples: Config[`outputs`][];
38
+ sources?: SourceConnection<Config[`sources`][number]>[];
29
39
  };
30
40
  export type ImmediateTrigger<Config extends EventConfig = {}> = CommonEvents<Config> & {
31
41
  type: `trigger`;
@@ -135,4 +145,6 @@ export declare const immediateTriggerSchema: () => Joi.ObjectSchema<any>;
135
145
  export declare const triggerSchema: () => Joi.AlternativesSchema<any>;
136
146
  export declare const actionSchema: () => Joi.ObjectSchema<any>;
137
147
  export declare const eventSchema: () => Joi.AlternativesSchema<any>;
148
+ export declare const triggerOutputSchema: () => Joi.ObjectSchema<any>;
149
+ export declare const actionOutputSchema: () => Joi.ObjectSchema<any>;
138
150
  export {};
@@ -3,7 +3,7 @@ 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.eventSchema = exports.actionSchema = exports.triggerSchema = exports.immediateTriggerSchema = exports.scheduledTriggerSchema = void 0;
6
+ exports.actionOutputSchema = exports.triggerOutputSchema = exports.eventSchema = exports.actionSchema = exports.triggerSchema = exports.immediateTriggerSchema = exports.scheduledTriggerSchema = void 0;
7
7
  const joi_1 = __importDefault(require("joi"));
8
8
  const fields_1 = require("../minified-utils/fields");
9
9
  const commons_1 = require("./commons");
@@ -27,6 +27,15 @@ const commonEventsSchema = () => joi_1.default.object({
27
27
  sandbox: joi_1.default.bool().required(),
28
28
  fields: (0, fields_1.fieldsSchema)().required(),
29
29
  examples: joi_1.default.array(),
30
+ sources: joi_1.default.array().items(joi_1.default.object({
31
+ role: joi_1.default.valid(`subscriber`, `consumer`).required(),
32
+ id: (0, commons_1.idSchema)(),
33
+ configurable: joi_1.default.when(`role`, {
34
+ is: `consumer`,
35
+ then: joi_1.default.bool().optional(),
36
+ otherwise: joi_1.default.forbidden(),
37
+ }),
38
+ })).optional(),
30
39
  });
31
40
  const scheduledTriggerSchema = () => joi_1.default.object({
32
41
  type: joi_1.default.valid(`trigger`).required(),
@@ -81,3 +90,18 @@ const actionSchema = () => joi_1.default.object({
81
90
  exports.actionSchema = actionSchema;
82
91
  const eventSchema = () => joi_1.default.alternatives((0, exports.triggerSchema)(), (0, exports.actionSchema)());
83
92
  exports.eventSchema = eventSchema;
93
+ const triggerOutputSchema = () => joi_1.default.object({
94
+ records: joi_1.default.array()
95
+ .required(),
96
+ flags: joi_1.default.object()
97
+ .pattern(joi_1.default.string(), joi_1.default.valid(true))
98
+ .required(),
99
+ });
100
+ exports.triggerOutputSchema = triggerOutputSchema;
101
+ const actionOutputSchema = () => joi_1.default.object({
102
+ output: joi_1.default.alternatives(joi_1.default.array(), joi_1.default.object()).required(),
103
+ flags: joi_1.default.object()
104
+ .pattern(joi_1.default.string(), joi_1.default.valid(true))
105
+ .required(),
106
+ });
107
+ exports.actionOutputSchema = actionOutputSchema;
@@ -1,6 +1,7 @@
1
1
  import Joi from "joi";
2
2
  import { Credentials } from "./credentials";
3
3
  import { Action, Trigger } from "./events";
4
+ import { Source } from "./source";
4
5
  export type Provider = {
5
6
  id: string;
6
7
  model: `provider`;
@@ -8,5 +9,6 @@ export type Provider = {
8
9
  credentials: Record<string, Credentials>;
9
10
  triggers: Record<string, Trigger>;
10
11
  actions: Record<string, Action>;
12
+ sources?: Record<string, Source>;
11
13
  };
12
14
  export declare const providerSchema: () => Joi.ObjectSchema<any>;
@@ -8,6 +8,7 @@ const joi_1 = __importDefault(require("joi"));
8
8
  const credentials_1 = require("./credentials");
9
9
  const events_1 = require("./events");
10
10
  const commons_1 = require("./commons");
11
+ const source_1 = require("./source");
11
12
  const providerSchema = () => joi_1.default.object({
12
13
  id: (0, commons_1.idSchema)(),
13
14
  model: joi_1.default.valid(`provider`).required(),
@@ -21,5 +22,7 @@ const providerSchema = () => joi_1.default.object({
21
22
  actions: joi_1.default.object()
22
23
  .pattern((0, commons_1.idSchema)(), (0, events_1.actionSchema)())
23
24
  .required(),
25
+ sources: joi_1.default.object()
26
+ .pattern((0, commons_1.idSchema)(), (0, source_1.sourceSchema)()),
24
27
  });
25
28
  exports.providerSchema = providerSchema;
@@ -0,0 +1,8 @@
1
+ import Joi from "joi";
2
+ import { Field } from "../minified-utils/fields";
3
+ import { Common } from "./commons";
4
+ export type Source = Common & {
5
+ model: "source";
6
+ fields: Field[];
7
+ };
8
+ export declare const sourceSchema: () => Joi.ObjectSchema<any>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sourceSchema = void 0;
7
+ const joi_1 = __importDefault(require("joi"));
8
+ const fields_1 = require("../minified-utils/fields");
9
+ const commons_1 = require("./commons");
10
+ const sourceSchema = () => joi_1.default.object({
11
+ model: joi_1.default.valid(`source`).required(),
12
+ fields: (0, fields_1.fieldsSchema)().required().min(1),
13
+ }).concat((0, commons_1.commonSchema)());
14
+ exports.sourceSchema = sourceSchema;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export { Core, core } from './core';
2
2
  export { getCategories } from './entities/category';
3
3
  export { CoreFunction, idSchema } from './entities/commons';
4
- export { Credentials, OAuthCredentials, StaticCredentials, SessionCredentials, credentialsSchema, oauthCredentialsSchema, staticCredentialsSchema, sessionCredentialsSchema } from './entities/credentials';
5
- export { Action, Event, ImmediateTrigger, ScheduledTrigger, Trigger, actionSchema, eventSchema, immediateTriggerSchema, scheduledTriggerSchema, triggerSchema } from './entities/events';
4
+ export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
5
+ export { Action, actionOutputSchema, actionSchema, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, ScheduledTrigger, scheduledTriggerSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
6
6
  export { Provider, providerSchema } from './entities/provider';
7
- export { Field, SelectFieldChoice, ValidationResult, extract, fieldSchema, fieldsSchema, validate } from './minified-utils/fields';
7
+ export { Source } from './entities/source';
8
+ export { extract, Field, fieldSchema, fieldsSchema, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
8
9
  export { i18n, localizeFields, 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.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeFields = exports.i18n = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.providerSchema = exports.triggerSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.sessionCredentialsSchema = exports.staticCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.getCategories = exports.core = void 0;
3
+ exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeFields = exports.i18n = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.actionOutputSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.getCategories = 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 category_1 = require("./entities/category");
@@ -10,13 +10,15 @@ Object.defineProperty(exports, "idSchema", { enumerable: true, get: function ()
10
10
  var credentials_1 = require("./entities/credentials");
11
11
  Object.defineProperty(exports, "credentialsSchema", { enumerable: true, get: function () { return credentials_1.credentialsSchema; } });
12
12
  Object.defineProperty(exports, "oauthCredentialsSchema", { enumerable: true, get: function () { return credentials_1.oauthCredentialsSchema; } });
13
- Object.defineProperty(exports, "staticCredentialsSchema", { enumerable: true, get: function () { return credentials_1.staticCredentialsSchema; } });
14
13
  Object.defineProperty(exports, "sessionCredentialsSchema", { enumerable: true, get: function () { return credentials_1.sessionCredentialsSchema; } });
14
+ Object.defineProperty(exports, "staticCredentialsSchema", { enumerable: true, get: function () { return credentials_1.staticCredentialsSchema; } });
15
15
  var events_1 = require("./entities/events");
16
+ Object.defineProperty(exports, "actionOutputSchema", { enumerable: true, get: function () { return events_1.actionOutputSchema; } });
16
17
  Object.defineProperty(exports, "actionSchema", { enumerable: true, get: function () { return events_1.actionSchema; } });
17
18
  Object.defineProperty(exports, "eventSchema", { enumerable: true, get: function () { return events_1.eventSchema; } });
18
19
  Object.defineProperty(exports, "immediateTriggerSchema", { enumerable: true, get: function () { return events_1.immediateTriggerSchema; } });
19
20
  Object.defineProperty(exports, "scheduledTriggerSchema", { enumerable: true, get: function () { return events_1.scheduledTriggerSchema; } });
21
+ Object.defineProperty(exports, "triggerOutputSchema", { enumerable: true, get: function () { return events_1.triggerOutputSchema; } });
20
22
  Object.defineProperty(exports, "triggerSchema", { enumerable: true, get: function () { return events_1.triggerSchema; } });
21
23
  var provider_1 = require("./entities/provider");
22
24
  Object.defineProperty(exports, "providerSchema", { enumerable: true, get: function () { return provider_1.providerSchema; } });
@@ -23,7 +23,7 @@ const i18n = (directory, options = {}) => {
23
23
  directory: directory,
24
24
  defaultLocale: DEFAULT_LOCALE,
25
25
  objectNotation: true,
26
- autoReload: true,
26
+ autoReload: false,
27
27
  missingKeyFn: () => ``,
28
28
  });
29
29
  i18nInstance.setLocale(activeLocale);
@@ -2,7 +2,7 @@ export declare class Properties {
2
2
  private readonly filepath;
3
3
  private readonly properties;
4
4
  private readonly getFile;
5
- constructor(root: string, filename: any);
5
+ constructor(root: string, filename: string);
6
6
  readonly read: (name: string, unknown?: boolean) => Promise<string>;
7
7
  readonly write: (name: string, value: string) => Promise<void>;
8
8
  }
@@ -61,7 +61,7 @@ class Properties {
61
61
  }
62
62
  catch (e) {
63
63
  if (e?.code === `ENOENT`) {
64
- this.properties = this.getFile(`w`);
64
+ this.properties = this.getFile(`w+`);
65
65
  }
66
66
  else {
67
67
  throw e;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/core.ts CHANGED
@@ -7,6 +7,25 @@ import { i18n } from "./minified-utils/locales";
7
7
  import path from "path";
8
8
  import Joi from "joi";
9
9
 
10
+ type SourceFunctions = {
11
+ register: <T>(source: string, data: T) => Promise<{ id: string }>,
12
+ consume: <T>(source: string) => Promise<{ id: string, data: T }[]>,
13
+ unregister: (source: string, id: string) => Promise<void>,
14
+ };
15
+
16
+ const FALLBACK_SOURCES: SourceFunctions = {
17
+ register: async () => {
18
+ throw new Error(`Sources not available: valid implementation not provided`);
19
+ },
20
+ consume: async () => {
21
+ throw new Error(`Sources not available: valid implementation not provided`);
22
+ },
23
+ unregister: async () => {
24
+ throw new Error(`Sources not available: valid implementation not provided`);
25
+ },
26
+ };
27
+
28
+
10
29
  export type Core = {
11
30
  axios: typeof axios,
12
31
  moment: typeof moment,
@@ -14,6 +33,7 @@ export type Core = {
14
33
  env: Properties,
15
34
  t: ReturnType<typeof i18n>[`t`],
16
35
  joi: typeof Joi,
36
+ sources?: SourceFunctions,
17
37
  };
18
38
 
19
39
  const axiosLogs = (method: string, debug = false): ProxyLogs<
@@ -34,9 +54,11 @@ const axiosLogs = (method: string, debug = false): ProxyLogs<
34
54
  });
35
55
 
36
56
  type CoreOptions = {
37
- path: string,
57
+ root: string,
58
+ env?: Properties,
38
59
  debug?: boolean,
39
60
  locale?: string,
61
+ sources?: SourceFunctions,
40
62
  };
41
63
 
42
64
  /* eslint-disable @typescript-eslint/unbound-method */
@@ -50,7 +72,8 @@ export const core = (options: CoreOptions): Core => ({
50
72
  }),
51
73
  moment: moment,
52
74
  lodash: _,
53
- env: new Properties(options.path, `.env`),
54
- t: i18n(path.join(options.path, `/locales`), { locale: options.locale }).t,
75
+ env: options.env || new Properties(options.root, `.env`),
76
+ t: i18n(path.join(options.root, `/locales`), { locale: options.locale }).t,
55
77
  joi: Joi,
78
+ sources: options.sources || FALLBACK_SOURCES,
56
79
  });
@@ -9,7 +9,7 @@ export type CoreConfig = {
9
9
 
10
10
  export type CoreFunction<Config extends CoreConfig = {}> = (core: Core, configuration: ({
11
11
  sandbox: boolean,
12
- organization: string,
12
+ organization?: string,
13
13
  } & (
14
14
  Config[`inputs`] extends undefined ?
15
15
  {} :
@@ -19,11 +19,21 @@ type AdditionalConnectableEvent<Keys extends string = string> = CommonConnectabl
19
19
 
20
20
  export type ConnectableEvent<Keys extends string = string> = DefaultConnectableEvent<Keys> | ErrorConnectableEvent<Keys> | AdditionalConnectableEvent<Keys>;
21
21
 
22
+ export type SourceConnection<Keys extends string = string> = {
23
+ role: `subscriber`,
24
+ id: Keys,
25
+ } | {
26
+ role: `consumer`,
27
+ id: Keys,
28
+ configurable?: boolean,
29
+ };
30
+
22
31
  type EventConfig = Pick<CoreConfig, `credentials` | `outputs`> & {
23
32
  flags?: {
24
33
  inputs?: string[],
25
34
  outputs: string[],
26
35
  },
36
+ sources?: string[],
27
37
  };
28
38
 
29
39
  type CommonEvents<Config extends EventConfig = {}> = Common<Config> & {
@@ -32,7 +42,8 @@ type CommonEvents<Config extends EventConfig = {}> = Common<Config> & {
32
42
  credentials: string[],
33
43
  sandbox: boolean,
34
44
  fields: Field[],
35
- examples: EventConfig[`outputs`][],
45
+ examples: Config[`outputs`][],
46
+ sources?: SourceConnection<Config[`sources`][number]>[],
36
47
  };
37
48
 
38
49
  export type ImmediateTrigger<Config extends EventConfig = {}> = CommonEvents<Config> & {
@@ -131,6 +142,17 @@ const commonEventsSchema = () =>
131
142
  sandbox: Joi.bool().required(),
132
143
  fields: fieldsSchema().required(),
133
144
  examples: Joi.array(),
145
+ sources: Joi.array().items(
146
+ Joi.object({
147
+ role: Joi.valid(`subscriber`, `consumer`).required(),
148
+ id: idSchema(),
149
+ configurable: Joi.when(`role`, {
150
+ is: `consumer`,
151
+ then: Joi.bool().optional(),
152
+ otherwise: Joi.forbidden(),
153
+ }),
154
+ })
155
+ ).optional(),
134
156
  });
135
157
 
136
158
  export const scheduledTriggerSchema = () =>
@@ -196,4 +218,24 @@ export const actionSchema = () =>
196
218
  .concat(commonEventsSchema());
197
219
 
198
220
  export const eventSchema = () =>
199
- Joi.alternatives(triggerSchema(), actionSchema());
221
+ Joi.alternatives(triggerSchema(), actionSchema());
222
+
223
+ export const triggerOutputSchema = () =>
224
+ Joi.object({
225
+ records: Joi.array()
226
+ .required(),
227
+ flags: Joi.object()
228
+ .pattern(Joi.string(), Joi.valid(true))
229
+ .required(),
230
+ });
231
+
232
+ export const actionOutputSchema = () =>
233
+ Joi.object({
234
+ output: Joi.alternatives(
235
+ Joi.array(),
236
+ Joi.object(),
237
+ ).required(),
238
+ flags: Joi.object()
239
+ .pattern(Joi.string(), Joi.valid(true))
240
+ .required(),
241
+ });
@@ -2,6 +2,7 @@ import Joi from "joi";
2
2
  import { Credentials, credentialsSchema } from "./credentials";
3
3
  import { Action, actionSchema, Trigger, triggerSchema } from "./events";
4
4
  import { idSchema } from "./commons";
5
+ import { Source, sourceSchema } from "./source";
5
6
 
6
7
  export type Provider = {
7
8
  id: string,
@@ -10,6 +11,7 @@ export type Provider = {
10
11
  credentials: Record<string, Credentials>,
11
12
  triggers: Record<string, Trigger>,
12
13
  actions: Record<string, Action>,
14
+ sources?: Record<string, Source>,
13
15
  };
14
16
 
15
17
  export const providerSchema = () =>
@@ -26,4 +28,6 @@ export const providerSchema = () =>
26
28
  actions: Joi.object()
27
29
  .pattern(idSchema(), actionSchema())
28
30
  .required(),
31
+ sources: Joi.object()
32
+ .pattern(idSchema(), sourceSchema()),
29
33
  });
@@ -0,0 +1,14 @@
1
+ import Joi from "joi";
2
+ import { Field, fieldsSchema } from "../minified-utils/fields";
3
+ import { Common, commonSchema } from "./commons";
4
+
5
+ export type Source = Common & {
6
+ model: "source",
7
+ fields: Field[],
8
+ };
9
+
10
+ export const sourceSchema = () =>
11
+ Joi.object({
12
+ model: Joi.valid(`source`).required(),
13
+ fields: fieldsSchema().required().min(1),
14
+ }).concat(commonSchema());
package/src/index.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export { Core, core } from './core';
2
2
  export { getCategories } from './entities/category';
3
3
  export { CoreFunction, idSchema } from './entities/commons';
4
- export { Credentials, OAuthCredentials, StaticCredentials, SessionCredentials, credentialsSchema, oauthCredentialsSchema, staticCredentialsSchema, sessionCredentialsSchema } from './entities/credentials';
5
- export { Action, Event, ImmediateTrigger, ScheduledTrigger, Trigger, actionSchema, eventSchema, immediateTriggerSchema, scheduledTriggerSchema, triggerSchema } from './entities/events';
4
+ export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
5
+ export { Action, actionOutputSchema, actionSchema, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, ScheduledTrigger, scheduledTriggerSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
6
6
  export { Provider, providerSchema } from './entities/provider';
7
- export { Field, SelectFieldChoice, ValidationResult, extract, fieldSchema, fieldsSchema, validate } from './minified-utils/fields';
7
+ export { Source } from './entities/source';
8
+ export { extract, Field, fieldSchema, fieldsSchema, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
8
9
  export { i18n, localizeFields, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
9
- export { Properties } from './minified-utils/properties';
10
+ export { Properties } from './minified-utils/properties';
@@ -38,7 +38,7 @@ export const i18n = (directory: string, options: { locale?: string } = {}) => {
38
38
  directory: directory,
39
39
  defaultLocale: DEFAULT_LOCALE,
40
40
  objectNotation: true,
41
- autoReload: true,
41
+ autoReload: false,
42
42
  missingKeyFn: () => ``,
43
43
  });
44
44
  i18nInstance.setLocale(activeLocale);
@@ -8,7 +8,7 @@ export class Properties {
8
8
  private readonly filepath: string;
9
9
  private readonly properties: DotenvParseOutput;
10
10
 
11
- private readonly getFile = (flag: `w` | `r`): DotenvParseOutput => {
11
+ private readonly getFile = (flag: `w+` | `r`): DotenvParseOutput => {
12
12
  try {
13
13
  const fd = openSync(this.filepath, flag);
14
14
  const buffer = readFileSync(fd);
@@ -17,7 +17,7 @@ export class Properties {
17
17
  } catch (e) { throw e; }
18
18
  };
19
19
 
20
- constructor(root: string, filename) {
20
+ constructor(root: string, filename: string) {
21
21
  if (path.isAbsolute(root)) {
22
22
  this.filepath = path.resolve(root, filename);
23
23
  } else {
@@ -29,7 +29,7 @@ export class Properties {
29
29
  this.properties = this.getFile(`r`);
30
30
  } catch (e) {
31
31
  if (e?.code === `ENOENT`) {
32
- this.properties = this.getFile(`w`);
32
+ this.properties = this.getFile(`w+`);
33
33
  } else { throw e; }
34
34
  }
35
35
  }