@koralabs/kora-labs-common 6.4.15 → 6.4.17
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/logger/index.d.ts +3 -0
- package/logger/index.js +31 -9
- package/package.json +1 -1
- package/utils/cbor/index.js +6 -0
package/logger/index.d.ts
CHANGED
|
@@ -12,6 +12,9 @@ export declare class Logger {
|
|
|
12
12
|
static application: string;
|
|
13
13
|
static network: CardanoNetwork;
|
|
14
14
|
private static isInitialized;
|
|
15
|
+
private static isInitializing;
|
|
16
|
+
private static getSynchronousApplicationNameFallback;
|
|
17
|
+
private static setFallbackMetadata;
|
|
15
18
|
static initialize(): Promise<void>;
|
|
16
19
|
static local(args: {
|
|
17
20
|
message: string;
|
package/logger/index.js
CHANGED
|
@@ -39,18 +39,32 @@ const LOCAL_CATEGORY_COLORS = {
|
|
|
39
39
|
[LogCategory.NOTIFY]: ANSI_RED
|
|
40
40
|
};
|
|
41
41
|
class Logger {
|
|
42
|
+
static getSynchronousApplicationNameFallback() {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
if (process.env.NODE_ENV === 'test')
|
|
45
|
+
return 'TEST';
|
|
46
|
+
return (_c = (_b = (_a = process.env.APPLICATION_NAME) !== null && _a !== void 0 ? _a : process.env.AWS_LAMBDA_FUNCTION_NAME) !== null && _b !== void 0 ? _b : process.env.ECS_CLUSTER) !== null && _c !== void 0 ? _c : process.cwd();
|
|
47
|
+
}
|
|
48
|
+
static setFallbackMetadata() {
|
|
49
|
+
if (!Logger.application) {
|
|
50
|
+
Logger.application = this.getSynchronousApplicationNameFallback();
|
|
51
|
+
}
|
|
52
|
+
if (!Logger.network) {
|
|
53
|
+
Logger.network = environment_1.Environment.getCardanoNetwork();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
42
56
|
static async initialize() {
|
|
57
|
+
this.setFallbackMetadata();
|
|
43
58
|
if (process.env.NODE_ENV !== 'test') {
|
|
44
|
-
|
|
59
|
+
try {
|
|
45
60
|
const potentialName = await environment_1.Environment.getPotentialApplicationName();
|
|
46
|
-
if (
|
|
47
|
-
|
|
61
|
+
if (potentialName) {
|
|
62
|
+
Logger.application = potentialName;
|
|
48
63
|
}
|
|
49
|
-
Logger.application = potentialName;
|
|
50
64
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
catch (_a) {
|
|
66
|
+
// fall back to sync-derived application name
|
|
67
|
+
}
|
|
54
68
|
}
|
|
55
69
|
this.network = environment_1.Environment.getCardanoNetwork();
|
|
56
70
|
Logger.isInitialized = true;
|
|
@@ -69,8 +83,15 @@ class Logger {
|
|
|
69
83
|
});
|
|
70
84
|
}
|
|
71
85
|
static log(args) {
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
this.setFallbackMetadata();
|
|
87
|
+
if (!Logger.isInitialized && !Logger.isInitializing) {
|
|
88
|
+
Logger.isInitializing = true;
|
|
89
|
+
Logger.initialize()
|
|
90
|
+
.catch(() => { })
|
|
91
|
+
.finally(() => {
|
|
92
|
+
Logger.isInitializing = false;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
74
95
|
if (typeof args === 'string') {
|
|
75
96
|
this.log_entry(LogCategory.INFO, args);
|
|
76
97
|
return;
|
|
@@ -112,3 +133,4 @@ class Logger {
|
|
|
112
133
|
}
|
|
113
134
|
exports.Logger = Logger;
|
|
114
135
|
Logger.isInitialized = false;
|
|
136
|
+
Logger.isInitializing = false;
|
package/package.json
CHANGED
package/utils/cbor/index.js
CHANGED
|
@@ -248,6 +248,12 @@ const getAddressHexFromObject = (obj) => {
|
|
|
248
248
|
return `0x${addressType}${network}${paymentHash}${stakeHash}`;
|
|
249
249
|
};
|
|
250
250
|
const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = DefaultTextFormat.UTF8, forJson = true }) => {
|
|
251
|
+
if (val === null || val === undefined) {
|
|
252
|
+
if (schema === 'bool' && (0, boolean_1.isBooleanable)(val)) {
|
|
253
|
+
return (0, boolean_1.boolean)(val);
|
|
254
|
+
}
|
|
255
|
+
return val;
|
|
256
|
+
}
|
|
251
257
|
const isMap = val instanceof Map;
|
|
252
258
|
if (isMap) {
|
|
253
259
|
const obj = new Map();
|