@creator.co/wapi 1.6.0 → 2.0.0-alpha.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.
Files changed (85) hide show
  1. package/.github/workflows/npmpublish.yml +1 -1
  2. package/.github/workflows/prs.yml +1 -1
  3. package/dist/index.js +45 -31
  4. package/dist/index.js.map +1 -1
  5. package/dist/jest.config.js +2 -4
  6. package/dist/jest.config.js.map +1 -1
  7. package/dist/package.json +12 -12
  8. package/dist/src/API/Request.js +53 -59
  9. package/dist/src/API/Request.js.map +1 -1
  10. package/dist/src/API/Response.js +81 -156
  11. package/dist/src/API/Response.js.map +1 -1
  12. package/dist/src/BaseEvent/EventProcessor.js +54 -132
  13. package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
  14. package/dist/src/BaseEvent/Process.js +40 -98
  15. package/dist/src/BaseEvent/Process.js.map +1 -1
  16. package/dist/src/BaseEvent/Transaction.js +122 -310
  17. package/dist/src/BaseEvent/Transaction.js.map +1 -1
  18. package/dist/src/Cache/Redis.js +55 -119
  19. package/dist/src/Cache/Redis.js.map +1 -1
  20. package/dist/src/Cache/types.js +1 -2
  21. package/dist/src/Config/Configuration.js +46 -86
  22. package/dist/src/Config/Configuration.js.map +1 -1
  23. package/dist/src/Config/EnvironmentVar.js +57 -119
  24. package/dist/src/Config/EnvironmentVar.js.map +1 -1
  25. package/dist/src/Crypto/Crypto.js +35 -82
  26. package/dist/src/Crypto/Crypto.js.map +1 -1
  27. package/dist/src/Crypto/JWT.js +12 -27
  28. package/dist/src/Crypto/JWT.js.map +1 -1
  29. package/dist/src/Database/Database.js +3 -8
  30. package/dist/src/Database/Database.js.map +1 -1
  31. package/dist/src/Database/DatabaseManager.js +23 -28
  32. package/dist/src/Database/DatabaseManager.js.map +1 -1
  33. package/dist/src/Database/DatabaseTransaction.js +50 -166
  34. package/dist/src/Database/DatabaseTransaction.js.map +1 -1
  35. package/dist/src/Database/index.js +11 -15
  36. package/dist/src/Database/index.js.map +1 -1
  37. package/dist/src/Database/integrations/knex/KnexDatabase.js +22 -76
  38. package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
  39. package/dist/src/Database/integrations/knex/KnexTransaction.js +19 -85
  40. package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -1
  41. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +37 -88
  42. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -1
  43. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +46 -114
  44. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -1
  45. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +20 -71
  46. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
  47. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +19 -85
  48. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -1
  49. package/dist/src/Database/types.js +1 -2
  50. package/dist/src/Globals.js +93 -98
  51. package/dist/src/Globals.js.map +1 -1
  52. package/dist/src/Logger/Logger.js +88 -222
  53. package/dist/src/Logger/Logger.js.map +1 -1
  54. package/dist/src/Mailer/Mailer.js +83 -204
  55. package/dist/src/Mailer/Mailer.js.map +1 -1
  56. package/dist/src/Publisher/Publisher.js +43 -107
  57. package/dist/src/Publisher/Publisher.js.map +1 -1
  58. package/dist/src/Server/RouteResolver.js +22 -49
  59. package/dist/src/Server/RouteResolver.js.map +1 -1
  60. package/dist/src/Server/Router.js +12 -16
  61. package/dist/src/Server/Router.js.map +1 -1
  62. package/dist/src/Server/lib/ContainerServer.js +21 -83
  63. package/dist/src/Server/lib/ContainerServer.js.map +1 -1
  64. package/dist/src/Server/lib/Server.js +50 -99
  65. package/dist/src/Server/lib/Server.js.map +1 -1
  66. package/dist/src/Server/lib/container/GenericHandler.js +32 -107
  67. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
  68. package/dist/src/Server/lib/container/GenericHandlerEvent.js +37 -81
  69. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
  70. package/dist/src/Server/lib/container/HealthHandler.js +3 -35
  71. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
  72. package/dist/src/Server/lib/container/Proxy.js +64 -127
  73. package/dist/src/Server/lib/container/Proxy.js.map +1 -1
  74. package/dist/src/Server/lib/container/Utils.js +12 -55
  75. package/dist/src/Server/lib/container/Utils.js.map +1 -1
  76. package/dist/src/Util/AsyncSingleton.js +40 -164
  77. package/dist/src/Util/AsyncSingleton.js.map +1 -1
  78. package/dist/src/Util/Utils.js +18 -24
  79. package/dist/src/Util/Utils.js.map +1 -1
  80. package/dist/src/Validation/Validator.js +10 -16
  81. package/dist/src/Validation/Validator.js.map +1 -1
  82. package/package.json +12 -12
  83. package/src/Logger/Logger.ts +2 -2
  84. package/tests/Logger/Logger.test.ts +6 -4
  85. package/tsconfig.json +3 -1
@@ -1,15 +1,3 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,56 +7,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
8
  });
21
9
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- var redis_1 = require("redis");
51
- var AsyncSingleton_1 = require("../Util/AsyncSingleton");
10
+ var _a;
11
+ import { createCluster, createClient } from 'redis';
12
+ import AsyncSingleton from '../Util/AsyncSingleton';
52
13
  /**
53
14
  * Represents a Redis cache connection class.
54
15
  */
55
- var Redis = /** @class */ (function () {
56
- function Redis() {
57
- }
58
- Redis.connection = function (config) {
16
+ class Redis {
17
+ static connection(config) {
59
18
  return _a.singleton.instance(config);
60
- };
61
- Redis.connectionFactory = function (config) {
62
- return __awaiter(this, void 0, void 0, function () {
63
- return __generator(this, function (_b) {
64
- if (config.clusterMode)
65
- return [2 /*return*/, _a.redisClusterConnection(config)];
66
- else
67
- return [2 /*return*/, _a.redisClientConnection(config)];
68
- return [2 /*return*/];
69
- });
19
+ }
20
+ static connectionFactory(config) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ if (config.clusterMode)
23
+ return _a.redisClusterConnection(config);
24
+ else
25
+ return _a.redisClientConnection(config);
70
26
  });
71
- };
27
+ }
72
28
  /**
73
29
  * Establishes a connection to a Redis client based on the provided configuration
74
30
  * and holds it for reusability. If connection is detected closed, new connection is
@@ -76,69 +32,49 @@ var Redis = /** @class */ (function () {
76
32
  * @param {CacheConfig<'redis'>} config - The configuration object for connecting to the Redis client.
77
33
  * @returns {Promise<RedisClientType>} A promise that resolves to the Redis client connection.
78
34
  */
79
- Redis.redisClientConnection = function (config) {
80
- return __awaiter(this, void 0, void 0, function () {
81
- var connection;
82
- return __generator(this, function (_b) {
83
- switch (_b.label) {
84
- case 0:
85
- console.debug('Starting remote client cache connection');
86
- connection = _a.ClientFactory(__assign(__assign({ username: config.username }, (config.password ? { password: config.password } : {})), { disableOfflineQueue: true, socket: {
87
- host: config.hostname,
88
- tls: config.enableTLS,
89
- connectTimeout: 10000,
90
- } }));
91
- return [4 /*yield*/, connection.connect()];
92
- case 1:
93
- _b.sent();
94
- return [2 /*return*/, connection];
95
- }
96
- });
35
+ static redisClientConnection(config) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ console.debug('Starting remote client cache connection');
38
+ const connection = _a.ClientFactory(Object.assign(Object.assign({ username: config.username }, (config.password ? { password: config.password } : {})), { disableOfflineQueue: true, socket: {
39
+ host: config.hostname,
40
+ tls: config.enableTLS,
41
+ connectTimeout: 10000,
42
+ } }));
43
+ yield connection.connect();
44
+ return connection;
97
45
  });
98
- };
99
- Redis.redisClusterConnection = function (config) {
100
- return __awaiter(this, void 0, void 0, function () {
101
- var connection;
102
- return __generator(this, function (_b) {
103
- switch (_b.label) {
104
- case 0:
105
- console.debug('Starting remote cluster cache connection');
106
- connection = _a.ClusterFactory({
107
- defaults: __assign(__assign({ username: config.username }, (config.password ? { password: config.password } : {})), { socket: {
108
- tls: config.enableTLS,
109
- connectTimeout: 10000,
110
- } }),
111
- rootNodes: [
112
- {
113
- url: "redis://".concat(config.username, ":").concat(config.username, "@").concat(config.hostname, ":6379"),
114
- disableOfflineQueue: true,
115
- },
116
- ],
117
- });
118
- return [4 /*yield*/, connection.connect()];
119
- case 1:
120
- _b.sent();
121
- return [2 /*return*/, connection];
122
- }
46
+ }
47
+ static redisClusterConnection(config) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ console.debug('Starting remote cluster cache connection');
50
+ const connection = _a.ClusterFactory({
51
+ defaults: Object.assign(Object.assign({ username: config.username }, (config.password ? { password: config.password } : {})), { socket: {
52
+ tls: config.enableTLS,
53
+ connectTimeout: 10000,
54
+ } }),
55
+ rootNodes: [
56
+ {
57
+ url: `redis://${config.username}:${config.username}@${config.hostname}:6379`,
58
+ disableOfflineQueue: true,
59
+ },
60
+ ],
123
61
  });
62
+ yield connection.connect();
63
+ return connection;
124
64
  });
125
- };
126
- var _a;
127
- _a = Redis;
128
- Redis.singleton = new AsyncSingleton_1.default(_a.connectionFactory, function (c) { return __awaiter(void 0, void 0, void 0, function () { return __generator(_a, function (_b) {
129
- return [2 /*return*/, c.isOpen];
130
- }); }); });
131
- /**
132
- * A private static property that holds a reference to the redis.createClient function.
133
- * This property is used to create client.
134
- */
135
- Redis.ClientFactory = redis_1.createClient;
136
- /**
137
- * A private static property that references the createCluster function.
138
- * This property can be used to create clusters within the class.
139
- */
140
- Redis.ClusterFactory = redis_1.createCluster;
141
- return Redis;
142
- }());
143
- exports.default = Redis;
65
+ }
66
+ }
67
+ _a = Redis;
68
+ Redis.singleton = new AsyncSingleton(_a.connectionFactory, (c) => __awaiter(void 0, void 0, void 0, function* () { return c.isOpen; }));
69
+ /**
70
+ * A private static property that holds a reference to the redis.createClient function.
71
+ * This property is used to create client.
72
+ */
73
+ Redis.ClientFactory = createClient;
74
+ /**
75
+ * A private static property that references the createCluster function.
76
+ * This property can be used to create clusters within the class.
77
+ */
78
+ Redis.ClusterFactory = createCluster;
79
+ export default Redis;
144
80
  //# sourceMappingURL=Redis.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Redis.js","sourceRoot":"","sources":["../../../src/Cache/Redis.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAsF;AAGtF,yDAAmD;AACnD;;GAEG;AACH;IAAA;IAgFA,CAAC;IA9De,gBAAU,GAAxB,UACE,MAA4B;QAE5B,OAAO,EAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;IAEoB,uBAAiB,GAAtC,UACE,MAA4B;;;gBAE5B,IAAI,MAAM,CAAC,WAAW;oBAAE,sBAAO,EAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAA;;oBAC9D,sBAAO,EAAK,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAA;;;;KAChD;IACD;;;;;;OAMG;IACkB,2BAAqB,GAA1C,UACE,MAA4B;;;;;;wBAE5B,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAA;wBAClD,UAAU,GAAG,EAAK,CAAC,aAAa,qBACpC,QAAQ,EAAE,MAAM,CAAC,QAAQ,IACtB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KACzD,mBAAmB,EAAE,IAAI,EACzB,MAAM,EAAE;gCACN,IAAI,EAAE,MAAM,CAAC,QAAQ;gCACrB,GAAG,EAAE,MAAM,CAAC,SAAS;gCACrB,cAAc,EAAE,KAAK;6BACtB,IACD,CAAA;wBACF,qBAAM,UAAU,CAAC,OAAO,EAAE,EAAA;;wBAA1B,SAA0B,CAAA;wBAE1B,sBAAO,U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AAE;wBACN,GAAG,EAAE,MAAM,CAAC,SAAS;wBACrB,cAAc,EAAE,KAAK;qBACtB,GACF;gBACD,SAAS,EAAE;oBACT;wBACE,GAAG,EAAE,WAAW,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,OAAO;wBAC5E,mBAAmB,EAAE,IAAI;qBAC1B;iBACF;aACF,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,UAAiB,CAAA;QAC1B,CAAC;KAAA;;;AA9Ec,eAAS,GAAG,IAAI,cAAc,CAG3C,EAAK,CAAC,iBAAiB,EAAE,CAAM,CAAC,EAAC,EAAE,kDAAC,OAAA,CAAC,CAAC,MAAM,CAAA,GAAA,CAAC,AAHvB,CAGuB;AAE/C;;;GAGG;AACY,mBAAa,GAAG,YAAY,AAAf,CAAe;AAE3C;;;GAGG;AACY,oBAAc,GAAG,aAAa,AAAhB,CAAgB;eAhB1B,KAAK"}
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,56 +7,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var MemCache = require("node-cache");
40
- var DurationParser = require("parse-duration");
41
- var EnvironmentVar_1 = require("./EnvironmentVar");
10
+ import * as MemCache from 'node-cache';
11
+ import * as DurationParser from 'parse-duration';
12
+ import EnvironmentVar, { EnvironmentType } from './EnvironmentVar';
42
13
  // Hold cached values at nodeVM level
43
14
  // eslint-disable-next-line no-var
44
15
  /**
45
16
  * Creates a new instance of a memory cache store.
46
17
  * @returns {MemCache} A new instance of a memory cache store.
47
18
  */
48
- var cacheStore = new MemCache();
19
+ let cacheStore = new MemCache();
49
20
  /**
50
21
  * Represents a configuration object with a specified schema and remote prefix.
51
22
  * @template T - The type of the configuration schema.
52
23
  */
53
- var Configuration = /** @class */ (function () {
24
+ class Configuration {
54
25
  /**
55
26
  * Constructs a new instance of the class.
56
27
  * @param {T} schema - The schema object.
57
28
  * @param {string} remotePrefix - The remote prefix string.
58
29
  * @returns None
59
30
  */
60
- function Configuration(schema, remotePrefix) {
31
+ constructor(schema, remotePrefix) {
61
32
  this.schema = schema;
62
33
  this.remotePrefix = remotePrefix;
63
34
  }
@@ -66,59 +37,50 @@ var Configuration = /** @class */ (function () {
66
37
  * @param {keyof OmitByValueType<ExtractLocal<T>, null>} propName - The name of the property to retrieve.
67
38
  * @returns The value of the property.
68
39
  */
69
- Configuration.prototype.get = function (propName) {
70
- var propString = propName;
71
- var propSchema = this.schema[propString];
72
- var v = this.getCachedValue(propString);
40
+ get(propName) {
41
+ const propString = propName;
42
+ const propSchema = this.schema[propString];
43
+ let v = this.getCachedValue(propString);
73
44
  v =
74
45
  v ||
75
- new EnvironmentVar_1.default(propSchema.nameOverride || propString, EnvironmentVar_1.EnvironmentType.Local, !propSchema.required, !propSchema.noPrefix ? this.remotePrefix : '').syncResolve();
46
+ new EnvironmentVar(propSchema.nameOverride || propString, EnvironmentType.Local, !propSchema.required, !propSchema.noPrefix ? this.remotePrefix : '').syncResolve();
76
47
  this.cacheValue(propString, v, propSchema.cachingPolicy);
77
48
  return v;
78
- };
49
+ }
79
50
  /**
80
51
  * Asynchronously retrieves the value of a property from the remote environment.
81
52
  * @param {keyof OmitByValueType<ExtractRemote<T>, null>} propName - The name of the property to retrieve.
82
53
  * @returns {Promise<any>} - A promise that resolves to the value of the property.
83
54
  */
84
- Configuration.prototype.asyncGet = function (propName) {
85
- return __awaiter(this, void 0, void 0, function () {
86
- var propString, propSchema, v, v_1;
87
- return __generator(this, function (_a) {
88
- switch (_a.label) {
89
- case 0:
90
- propString = propName;
91
- propSchema = this.schema[propString];
92
- v = this.getCachedValue(propString);
93
- if (v !== undefined)
94
- return [2 /*return*/, v
95
- // check for local override
96
- ];
97
- // check for local override
98
- if (Configuration.isLocal && process.env[propString] !== undefined) {
99
- console.log("Overriding remote variable ".concat(propString, " with local value!"));
100
- v_1 = process.env[propString];
101
- this.cacheValue(propString, v_1, propSchema.cachingPolicy);
102
- return [2 /*return*/, v_1];
103
- }
104
- return [4 /*yield*/, new EnvironmentVar_1.default(propSchema.nameOverride || propString, propSchema.isSecure ? EnvironmentVar_1.EnvironmentType.SecureRemote : EnvironmentVar_1.EnvironmentType.PlainRemote, !propSchema.required, !propSchema.noPrefix ? this.remotePrefix : '').resolve()];
105
- case 1:
106
- // remote
107
- v = _a.sent();
108
- this.cacheValue(propString, v, propSchema.cachingPolicy);
109
- return [2 /*return*/, v];
110
- }
111
- });
55
+ asyncGet(propName) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const propString = propName;
58
+ const propSchema = this.schema[propString];
59
+ // check cache
60
+ let v = this.getCachedValue(propString);
61
+ if (v !== undefined)
62
+ return v;
63
+ // check for local override
64
+ if (Configuration.isLocal && process.env[propString] !== undefined) {
65
+ console.log(`Overriding remote variable ${propString} with local value!`);
66
+ const v = process.env[propString];
67
+ this.cacheValue(propString, v, propSchema.cachingPolicy);
68
+ return v;
69
+ }
70
+ // remote
71
+ v = yield new EnvironmentVar(propSchema.nameOverride || propString, propSchema.isSecure ? EnvironmentType.SecureRemote : EnvironmentType.PlainRemote, !propSchema.required, !propSchema.noPrefix ? this.remotePrefix : '').resolve();
72
+ this.cacheValue(propString, v, propSchema.cachingPolicy);
73
+ return v;
112
74
  });
113
- };
75
+ }
114
76
  /**
115
77
  * Retrieves the cached value associated with the given key from the cache store.
116
78
  * @param {string} valueKey - The key of the value to retrieve from the cache.
117
79
  * @returns The cached value associated with the given key, or undefined if the key does not exist in the cache.
118
80
  */
119
- Configuration.prototype.getCachedValue = function (valueKey) {
81
+ getCachedValue(valueKey) {
120
82
  return cacheStore.get(valueKey);
121
- };
83
+ }
122
84
  /**
123
85
  * Caches a value with the specified key and expiration policy.
124
86
  * @param {string} valueKey - The key to associate with the cached value.
@@ -126,24 +88,22 @@ var Configuration = /** @class */ (function () {
126
88
  * @param {string} [policy='1d'] - The expiration policy for the cached value. Defaults to '1d' (1 day).
127
89
  * @returns None
128
90
  */
129
- Configuration.prototype.cacheValue = function (valueKey, value, policy) {
130
- if (policy === void 0) { policy = '1d'; }
91
+ cacheValue(valueKey, value, policy = '1d') {
131
92
  cacheStore.set(valueKey, value, DurationParser(policy, 's') || '');
132
- };
93
+ }
133
94
  /**
134
95
  * Resets the cache by creating a new instance of the MemCache class and assigning it to the cacheStore variable.
135
96
  * @returns None
136
97
  */
137
- Configuration.prototype.resetCache = function () {
98
+ resetCache() {
138
99
  cacheStore = new MemCache();
139
- };
140
- /**
141
- * Indicates if config is local and should attempt to override
142
- * remote values from local.
143
- * @type {string}
144
- */
145
- Configuration.isLocal = process.env.NODE_ENV == 'local';
146
- return Configuration;
147
- }());
148
- exports.default = Configuration;
100
+ }
101
+ }
102
+ /**
103
+ * Indicates if config is local and should attempt to override
104
+ * remote values from local.
105
+ * @type {string}
106
+ */
107
+ Configuration.isLocal = process.env.NODE_ENV == 'local';
108
+ export default Configuration;
149
109
  //# sourceMappingURL=Configuration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/Config/Configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAsC;AACtC,+CAAgD;AAEhD,mDAAkE;AAElE,qCAAqC;AACrC,kCAAkC;AAClC;;;GAGG;AACH,IAAI,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAA;AA6E/B;;;GAGG;AACH;IAkBE;;;;;OAKG;IACH,uBAAY,MAAS,EAAE,YAAoB;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED;;;;OAIG;IACI,2BAAG,GAAV,UAAW,QAAsD;QAC/D,IAAM,UAAU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