@creator.co/wapi 1.6.1 → 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.
- package/.github/workflows/npmpublish.yml +1 -1
- package/.github/workflows/prs.yml +1 -1
- package/dist/index.js +45 -31
- package/dist/index.js.map +1 -1
- package/dist/jest.config.js +2 -4
- package/dist/jest.config.js.map +1 -1
- package/dist/package.json +12 -12
- package/dist/src/API/Request.js +53 -59
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.js +81 -156
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.js +54 -132
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.js +40 -98
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.js +122 -310
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Cache/Redis.js +55 -119
- package/dist/src/Cache/Redis.js.map +1 -1
- package/dist/src/Cache/types.js +1 -2
- package/dist/src/Config/Configuration.js +46 -86
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.js +57 -119
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.js +35 -82
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.js +12 -27
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Database/Database.js +3 -8
- package/dist/src/Database/Database.js.map +1 -1
- package/dist/src/Database/DatabaseManager.js +23 -28
- package/dist/src/Database/DatabaseManager.js.map +1 -1
- package/dist/src/Database/DatabaseTransaction.js +50 -166
- package/dist/src/Database/DatabaseTransaction.js.map +1 -1
- package/dist/src/Database/index.js +11 -15
- package/dist/src/Database/index.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexDatabase.js +22 -76
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexTransaction.js +19 -85
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +37 -88
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +46 -114
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +20 -71
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +19 -85
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -1
- package/dist/src/Database/types.js +1 -2
- package/dist/src/Globals.js +93 -98
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.js +88 -222
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.js +83 -204
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.js +43 -107
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.js +22 -49
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.js +12 -16
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.js +21 -83
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.js +50 -99
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.js +32 -107
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +37 -81
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.js +3 -35
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.js +64 -127
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.js +12 -55
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Util/AsyncSingleton.js +40 -164
- package/dist/src/Util/AsyncSingleton.js.map +1 -1
- package/dist/src/Util/Utils.js +18 -24
- package/dist/src/Util/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.js +10 -16
- package/dist/src/Validation/Validator.js.map +1 -1
- package/package.json +12 -12
- package/tests/Logger/Logger.test.ts +5 -3
- package/tsconfig.json +3 -1
package/dist/src/Cache/Redis.js
CHANGED
|
@@ -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
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
Redis.connection = function (config) {
|
|
16
|
+
class Redis {
|
|
17
|
+
static connection(config) {
|
|
59
18
|
return _a.singleton.instance(config);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
80
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
100
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"Redis.js","sourceRoot":"","sources":["../../../src/Cache/Redis.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAqC,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAGtF,OAAO,cAAc,MAAM,wBAAwB,CAAA;AACnD;;GAEG;AACH,MAAqB,KAAK;IAkBjB,MAAM,CAAC,UAAU,CACtB,MAA4B;QAE5B,OAAO,EAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;IAEO,MAAM,CAAO,iBAAiB,CACpC,MAA4B;;YAE5B,IAAI,MAAM,CAAC,WAAW;gBAAE,OAAO,EAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAA;;gBAC9D,OAAO,EAAK,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;QACjD,CAAC;KAAA;IACD;;;;;;OAMG;IACK,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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"}
|
package/dist/src/Cache/types.js
CHANGED
|
@@ -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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
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
|
-
|
|
85
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
+
resetCache() {
|
|
138
99
|
cacheStore = new MemCache();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/Config/Configuration.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,cAAc,MAAM,gBAAgB,CAAA;AAEhD,OAAO,cAAc,EAAE,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAElE,qCAAqC;AACrC,kCAAkC;AAClC;;;GAGG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