@bitblit/ratchet-common 4.0.115-alpha → 4.0.119-alpha
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/lib/index.d.ts +73 -1
- package/lib/index.mjs +4 -0
- package/lib/index.mjs.map +1 -0
- package/lib/lang/base64-ratchet.d.ts +1 -1
- package/lib/stream/buffer-writable.d.ts +2 -2
- package/lib/stream/multi-stream.d.ts +1 -1
- package/lib/stream/stream-ratchet.d.ts +2 -2
- package/lib/stream/string-writable.d.ts +1 -1
- package/package.json +9 -5
- package/lib/2d/line-2d.js +0 -1
- package/lib/2d/plane-2d.js +0 -1
- package/lib/2d/point-2d.js +0 -1
- package/lib/2d/poly-line-2d.js +0 -1
- package/lib/2d/ratchet-2d.js +0 -245
- package/lib/2d/ratchet-2d.spec.js +0 -117
- package/lib/build/build-information.js +0 -1
- package/lib/build/ratchet-common-info.js +0 -14
- package/lib/histogram/histogram-entry.js +0 -1
- package/lib/histogram/histogram.js +0 -48
- package/lib/histogram/histogram.spec.js +0 -19
- package/lib/index.js +0 -1
- package/lib/jwt/common-jwt-token.js +0 -1
- package/lib/jwt/expired-jwt-handling.js +0 -6
- package/lib/jwt/jwt-ratchet-like.js +0 -1
- package/lib/jwt/jwt-ratchet.js +0 -164
- package/lib/jwt/jwt-ratchet.spec.js +0 -49
- package/lib/jwt/jwt-token-base.js +0 -1
- package/lib/lang/array-ratchet.js +0 -83
- package/lib/lang/array-ratchet.spec.js +0 -68
- package/lib/lang/base64-ratchet.js +0 -45
- package/lib/lang/base64-ratchet.spec.js +0 -28
- package/lib/lang/boolean-ratchet.js +0 -45
- package/lib/lang/boolean-ratchet.spec.js +0 -81
- package/lib/lang/composite-last-success-provider.js +0 -26
- package/lib/lang/composite-last-success-provider.spec.js +0 -26
- package/lib/lang/date-ratchet.js +0 -29
- package/lib/lang/date-ratchet.spec.js +0 -21
- package/lib/lang/duration-ratchet.js +0 -42
- package/lib/lang/duration-ratchet.spec.js +0 -39
- package/lib/lang/enum-ratchet.js +0 -30
- package/lib/lang/enum-ratchet.spec.js +0 -31
- package/lib/lang/error-ratchet.js +0 -44
- package/lib/lang/error-ratchet.spec.js +0 -20
- package/lib/lang/esm-ratchet.js +0 -17
- package/lib/lang/expiring-object.js +0 -72
- package/lib/lang/expiring-object.spec.js +0 -51
- package/lib/lang/geolocation-ratchet.js +0 -263
- package/lib/lang/geolocation-ratchet.spec.js +0 -74
- package/lib/lang/global-ratchet.js +0 -43
- package/lib/lang/global-ratchet.spec.js +0 -14
- package/lib/lang/key-value.js +0 -4
- package/lib/lang/last-success-provider.js +0 -1
- package/lib/lang/map-ratchet.js +0 -164
- package/lib/lang/map-ratchet.spec.js +0 -90
- package/lib/lang/no.js +0 -4
- package/lib/lang/no.spec.js +0 -7
- package/lib/lang/number-ratchet.js +0 -155
- package/lib/lang/number-ratchet.spec.js +0 -118
- package/lib/lang/parsed-url.js +0 -1
- package/lib/lang/promise-ratchet.js +0 -138
- package/lib/lang/promise-ratchet.spec.js +0 -74
- package/lib/lang/require-ratchet.js +0 -56
- package/lib/lang/require-ratchet.spec.js +0 -80
- package/lib/lang/stop-watch.js +0 -114
- package/lib/lang/string-ratchet.js +0 -201
- package/lib/lang/string-ratchet.spec.js +0 -158
- package/lib/lang/time-zone-ratchet.js +0 -77
- package/lib/lang/time-zone-ratchet.spec.js +0 -40
- package/lib/lang/timeout-token.js +0 -17
- package/lib/lang/timeout-token.spec.js +0 -9
- package/lib/lang/transform-ratchet.js +0 -66
- package/lib/lang/transform-ratchet.spec.js +0 -118
- package/lib/logger/classic-single-line-log-message-formatter.js +0 -13
- package/lib/logger/log-message-builder.js +0 -48
- package/lib/logger/log-message-format-type.js +0 -6
- package/lib/logger/log-message-formatter.js +0 -1
- package/lib/logger/log-message-processor.js +0 -1
- package/lib/logger/log-message.js +0 -1
- package/lib/logger/log-snapshot.js +0 -1
- package/lib/logger/logger-instance.js +0 -208
- package/lib/logger/logger-level-name.js +0 -9
- package/lib/logger/logger-meta.js +0 -1
- package/lib/logger/logger-options.js +0 -1
- package/lib/logger/logger-output-function.js +0 -6
- package/lib/logger/logger-ring-buffer.js +0 -73
- package/lib/logger/logger-util.js +0 -44
- package/lib/logger/logger-util.spec.js +0 -9
- package/lib/logger/logger.js +0 -134
- package/lib/logger/logger.spec.js +0 -134
- package/lib/logger/none-log-message-formatter.js +0 -5
- package/lib/logger/structured-json-log-message-formatter.js +0 -19
- package/lib/network/browser-local-ip-provider.js +0 -21
- package/lib/network/browser-local-ip-provider.spec.js +0 -16
- package/lib/network/fixed-local-ip-provider.js +0 -9
- package/lib/network/local-ip-provider.js +0 -1
- package/lib/network/network-ratchet.js +0 -102
- package/lib/network/network-ratchet.spec.js +0 -13
- package/lib/stream/buffer-writable.js +0 -16
- package/lib/stream/multi-stream.js +0 -12
- package/lib/stream/stream-ratchet.js +0 -68
- package/lib/stream/stream-ratchet.spec.js +0 -13
- package/lib/stream/string-writable.js +0 -14
- package/lib/stream/string-writable.spec.js +0 -12
- package/lib/third-party/google/google-recaptcha-ratchet.js +0 -28
- package/lib/third-party/google/google-recaptcha-ratchet.spec.js +0 -20
- package/lib/third-party/twilio/twilio-ratchet.js +0 -73
- package/lib/transform/built-in-transforms.js +0 -191
- package/lib/transform/transform-rule.js +0 -1
- package/lib/tx/transaction-configuration.js +0 -1
- package/lib/tx/transaction-final-state.js +0 -6
- package/lib/tx/transaction-ratchet.js +0 -76
- package/lib/tx/transaction-ratchet.spec.js +0 -130
- package/lib/tx/transaction-result.js +0 -1
- package/lib/tx/transaction-step.js +0 -1
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { StringRatchet } from './string-ratchet.js';
|
|
2
|
-
describe('#formatBytes', function () {
|
|
3
|
-
it('should format 0 bytes correctly', function () {
|
|
4
|
-
const result = StringRatchet.formatBytes(0);
|
|
5
|
-
expect(result).toEqual('0 Bytes');
|
|
6
|
-
});
|
|
7
|
-
it('should format less than a Kb correctly', function () {
|
|
8
|
-
const result = StringRatchet.formatBytes(123);
|
|
9
|
-
expect(result).toEqual('123 Bytes');
|
|
10
|
-
});
|
|
11
|
-
it('should format less than a Mb correctly', function () {
|
|
12
|
-
const result = StringRatchet.formatBytes(1024);
|
|
13
|
-
expect(result).toEqual('1 KB');
|
|
14
|
-
});
|
|
15
|
-
it('should format less than a Mb correctly with 3 decimals', function () {
|
|
16
|
-
const result = StringRatchet.formatBytes(1234, 3);
|
|
17
|
-
expect(result).toEqual('1.205 KB');
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
describe('#safeToString', function () {
|
|
21
|
-
it('should return "asdf"', function () {
|
|
22
|
-
const result = StringRatchet.safeString('asdf');
|
|
23
|
-
expect(result).toEqual('asdf');
|
|
24
|
-
});
|
|
25
|
-
it('should return "55"', function () {
|
|
26
|
-
const result = StringRatchet.safeString(55);
|
|
27
|
-
expect(result).toEqual('55');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
describe('#obscure', function () {
|
|
31
|
-
it('should return "pa****rd"', function () {
|
|
32
|
-
const result = StringRatchet.obscure('password', 2, 2);
|
|
33
|
-
expect(result).toEqual('pa****rd');
|
|
34
|
-
});
|
|
35
|
-
it('should return null', function () {
|
|
36
|
-
const result = StringRatchet.obscure(null, 2, 2);
|
|
37
|
-
expect(result).toBeNull();
|
|
38
|
-
});
|
|
39
|
-
it('should return "p**s"', function () {
|
|
40
|
-
const result = StringRatchet.obscure('pass', 2, 2);
|
|
41
|
-
expect(result).toEqual('p**s');
|
|
42
|
-
});
|
|
43
|
-
it('should return "****"', function () {
|
|
44
|
-
const result = StringRatchet.obscure('pass', 0, 0);
|
|
45
|
-
expect(result).toEqual('****');
|
|
46
|
-
});
|
|
47
|
-
it('should return "p***"', function () {
|
|
48
|
-
const result = StringRatchet.obscure('pass', 1, 0);
|
|
49
|
-
expect(result).toEqual('p***');
|
|
50
|
-
});
|
|
51
|
-
it('should return "***s"', function () {
|
|
52
|
-
const result = StringRatchet.obscure('pass', 0, 1);
|
|
53
|
-
expect(result).toEqual('***s');
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
describe('#guid', function () {
|
|
57
|
-
it('should generate a guid"', function () {
|
|
58
|
-
const result = StringRatchet.createType4Guid();
|
|
59
|
-
expect(result).toBeTruthy();
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe('#randomHexString', function () {
|
|
63
|
-
it('should generate a random hex string"', function () {
|
|
64
|
-
const result = StringRatchet.createRandomHexString(12);
|
|
65
|
-
expect(result).toBeTruthy();
|
|
66
|
-
expect(result.length).toEqual(12);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe('#leadingZeros', function () {
|
|
70
|
-
it('should generate string with leading zeros"', function () {
|
|
71
|
-
const result = StringRatchet.leadingZeros(25, 4);
|
|
72
|
-
expect(result).toEqual('0025');
|
|
73
|
-
});
|
|
74
|
-
it('should generate string with leading zeros and a negative sign"', function () {
|
|
75
|
-
const result = StringRatchet.leadingZeros(-8, 2);
|
|
76
|
-
expect(result).toEqual('-08');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
describe('#stripNonNumeric', function () {
|
|
80
|
-
it('should return a string containing only numbers"', function () {
|
|
81
|
-
const result = StringRatchet.stripNonNumeric('702-555-1212');
|
|
82
|
-
expect(result).toEqual('7025551212');
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
describe('#stringContainsOnly', function () {
|
|
86
|
-
it('should check string contains only valid chars"', function () {
|
|
87
|
-
expect(StringRatchet.stringContainsOnly('test', 'tes')).toBeTruthy();
|
|
88
|
-
expect(StringRatchet.stringContainsOnly('test', 'teg')).toBeFalsy();
|
|
89
|
-
expect(StringRatchet.stringContainsOnlyAlphanumeric('test')).toBeTruthy();
|
|
90
|
-
expect(StringRatchet.stringContainsOnlyAlphanumeric('tes-')).toBeFalsy();
|
|
91
|
-
expect(StringRatchet.stringContainsOnlyHex('1a3')).toBeTruthy();
|
|
92
|
-
expect(StringRatchet.stringContainsOnlyHex('test')).toBeFalsy();
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
describe('#stringCsvSafe', function () {
|
|
96
|
-
it('should make values safe to place in a CSV"', function () {
|
|
97
|
-
expect(StringRatchet.csvSafe('test')).toEqual('test');
|
|
98
|
-
expect(StringRatchet.csvSafe('test,and 1')).toEqual('"test,and 1"');
|
|
99
|
-
expect(StringRatchet.csvSafe(1)).toEqual('1');
|
|
100
|
-
expect(StringRatchet.csvSafe("test'blah")).toEqual('"test\'blah"');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe('#trimToEmpty', function () {
|
|
104
|
-
it('should return an empty string for null"', function () {
|
|
105
|
-
const result = StringRatchet.trimToEmpty(null);
|
|
106
|
-
expect(result).toEqual('');
|
|
107
|
-
});
|
|
108
|
-
it('should return an empty string for undefined"', function () {
|
|
109
|
-
const result = StringRatchet.trimToEmpty(undefined);
|
|
110
|
-
expect(result).toEqual('');
|
|
111
|
-
});
|
|
112
|
-
it('should return an empty string"', function () {
|
|
113
|
-
const result = StringRatchet.trimToEmpty(' ');
|
|
114
|
-
expect(result).toEqual('');
|
|
115
|
-
});
|
|
116
|
-
it('should return an abc"', function () {
|
|
117
|
-
const result = StringRatchet.trimToEmpty('abc ');
|
|
118
|
-
expect(result).toEqual('abc');
|
|
119
|
-
});
|
|
120
|
-
it('should return string "5"', function () {
|
|
121
|
-
const result = StringRatchet.trimToEmpty(5);
|
|
122
|
-
expect(result).toEqual('5');
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
describe('#trimStringPropertiesInPlace', function () {
|
|
126
|
-
it('should trim properties to null"', function () {
|
|
127
|
-
const test = {
|
|
128
|
-
a: 'test ',
|
|
129
|
-
b: 1,
|
|
130
|
-
c: ' test',
|
|
131
|
-
d: null,
|
|
132
|
-
e: ' ',
|
|
133
|
-
};
|
|
134
|
-
const nullResult = StringRatchet.trimAllStringPropertiesToNullInPlace(test);
|
|
135
|
-
expect(nullResult).not.toBeNull();
|
|
136
|
-
expect(nullResult['a']).toEqual('test');
|
|
137
|
-
expect(nullResult['b']).toEqual(1);
|
|
138
|
-
expect(nullResult['c']).toEqual('test');
|
|
139
|
-
expect(nullResult['d']).toEqual(null);
|
|
140
|
-
expect(nullResult['e']).toEqual(null);
|
|
141
|
-
});
|
|
142
|
-
it('should trim properties to empty"', function () {
|
|
143
|
-
const test = {
|
|
144
|
-
a: 'test ',
|
|
145
|
-
b: 1,
|
|
146
|
-
c: ' test',
|
|
147
|
-
d: null,
|
|
148
|
-
e: ' ',
|
|
149
|
-
};
|
|
150
|
-
const emptyResult = StringRatchet.trimAllStringPropertiesToEmptyInPlace(test);
|
|
151
|
-
expect(emptyResult).not.toBeNull();
|
|
152
|
-
expect(emptyResult['a']).toEqual('test');
|
|
153
|
-
expect(emptyResult['b']).toEqual(1);
|
|
154
|
-
expect(emptyResult['c']).toEqual('test');
|
|
155
|
-
expect(emptyResult['d']).toEqual(null);
|
|
156
|
-
expect(emptyResult['e']).toEqual('');
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { DateTime } from 'luxon';
|
|
2
|
-
export class TimeZoneRatchet {
|
|
3
|
-
static PACIFIC = new TimeZoneRatchet('America/Los_Angeles');
|
|
4
|
-
timezone;
|
|
5
|
-
constructor(timezone) {
|
|
6
|
-
if (!timezone) {
|
|
7
|
-
throw 'Timezone cannot be null';
|
|
8
|
-
}
|
|
9
|
-
this.timezone = timezone;
|
|
10
|
-
}
|
|
11
|
-
currentHour() {
|
|
12
|
-
const rval = DateTime.local().setZone(this.timezone).hour;
|
|
13
|
-
return rval;
|
|
14
|
-
}
|
|
15
|
-
toEpochSeconds(dt) {
|
|
16
|
-
return Math.round(dt.toMillis() / 1000);
|
|
17
|
-
}
|
|
18
|
-
startOfTodayEpochSeconds() {
|
|
19
|
-
const startOfToday = this.toEpochSeconds(DateTime.local().setZone(this.timezone).set({ hour: 0, minute: 0, second: 0, millisecond: 0 }));
|
|
20
|
-
return startOfToday;
|
|
21
|
-
}
|
|
22
|
-
startOfMatchingDayEpochSeconds(inputTS) {
|
|
23
|
-
const startOfToday = this.toEpochSeconds(DateTime.fromMillis(inputTS).set({ hour: 0, minute: 0, second: 0, millisecond: 0 }));
|
|
24
|
-
return startOfToday;
|
|
25
|
-
}
|
|
26
|
-
startOfMatchingDayEpochMS(inputTS) {
|
|
27
|
-
return this.startOfMatchingDayEpochSeconds(inputTS) * 1000;
|
|
28
|
-
}
|
|
29
|
-
startOfCurrentHourEpochSeconds() {
|
|
30
|
-
const rval = this.toEpochSeconds(DateTime.local().setZone(this.timezone).set({ minute: 0, second: 0, millisecond: 0 }));
|
|
31
|
-
return rval;
|
|
32
|
-
}
|
|
33
|
-
startOfCurrentMinuteEpochSeconds() {
|
|
34
|
-
const rval = this.toEpochSeconds(DateTime.local().setZone(this.timezone).set({ second: 0, millisecond: 0 }));
|
|
35
|
-
return rval;
|
|
36
|
-
}
|
|
37
|
-
startOfCurrentSecondEpochSeconds() {
|
|
38
|
-
const rval = this.toEpochSeconds(DateTime.local().setZone(this.timezone).set({ millisecond: 0 }));
|
|
39
|
-
return rval;
|
|
40
|
-
}
|
|
41
|
-
startOfTodayEpochMS() {
|
|
42
|
-
const startOfToday = DateTime.local().setZone(this.timezone).set({ hour: 0, minute: 0, second: 0, millisecond: 0 }).toMillis();
|
|
43
|
-
return startOfToday;
|
|
44
|
-
}
|
|
45
|
-
dailySlotCount(slotWidthMs) {
|
|
46
|
-
return Math.ceil(86400000 / slotWidthMs);
|
|
47
|
-
}
|
|
48
|
-
currentTimeSlotIdx(slotWidthMs) {
|
|
49
|
-
if (slotWidthMs < 1) {
|
|
50
|
-
throw new Error('Cannot process with slot less than one ms wide');
|
|
51
|
-
}
|
|
52
|
-
const startOfToday = this.startOfTodayEpochMS();
|
|
53
|
-
const now = new Date().getTime();
|
|
54
|
-
const delta = now - startOfToday;
|
|
55
|
-
const idx = Math.floor(delta / slotWidthMs);
|
|
56
|
-
return idx;
|
|
57
|
-
}
|
|
58
|
-
matchingTimeSlotIdx(timestamp, slotWidthMs) {
|
|
59
|
-
if (slotWidthMs < 1) {
|
|
60
|
-
throw new Error('Cannot process with slot less than one ms wide');
|
|
61
|
-
}
|
|
62
|
-
const startOfDay = this.startOfMatchingDayEpochMS(timestamp);
|
|
63
|
-
const delta = timestamp - startOfDay;
|
|
64
|
-
const idx = Math.floor(delta / slotWidthMs);
|
|
65
|
-
return idx;
|
|
66
|
-
}
|
|
67
|
-
startOfCurrentSlotEpochMS(slotWidthMs) {
|
|
68
|
-
const startOfToday = this.startOfTodayEpochMS();
|
|
69
|
-
const currentIdx = this.currentTimeSlotIdx(slotWidthMs);
|
|
70
|
-
return startOfToday + currentIdx * slotWidthMs;
|
|
71
|
-
}
|
|
72
|
-
startOfMatchingSlotEpochMS(timestamp, slotWidthMs) {
|
|
73
|
-
const startOfDay = this.startOfMatchingDayEpochMS(timestamp);
|
|
74
|
-
const currentIdx = this.matchingTimeSlotIdx(timestamp, slotWidthMs);
|
|
75
|
-
return startOfDay + currentIdx * slotWidthMs;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { TimeZoneRatchet } from './time-zone-ratchet.js';
|
|
2
|
-
const tz = TimeZoneRatchet.PACIFIC;
|
|
3
|
-
describe('#currentHour', function () {
|
|
4
|
-
it('should return 0- 23', function () {
|
|
5
|
-
const result = tz.currentHour();
|
|
6
|
-
expect(result).toBeGreaterThanOrEqual(0);
|
|
7
|
-
expect(result).toBeLessThanOrEqual(23);
|
|
8
|
-
});
|
|
9
|
-
});
|
|
10
|
-
describe('#startOfTodayEpochSeconds', function () {
|
|
11
|
-
it('should never be more than now or more than 86400 seconds in the past', function () {
|
|
12
|
-
const now = Math.floor(new Date().getTime() / 1000);
|
|
13
|
-
const start = tz.startOfTodayEpochSeconds();
|
|
14
|
-
const result = now - start;
|
|
15
|
-
expect(result).toBeGreaterThanOrEqual(0);
|
|
16
|
-
expect(result).toBeLessThanOrEqual(86400);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
describe('#dailySlotCount', function () {
|
|
20
|
-
it('should return 86400', function () {
|
|
21
|
-
const result = tz.dailySlotCount(1000);
|
|
22
|
-
expect(result).toEqual(86400);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
describe('#currentTimeSlotIdx', function () {
|
|
26
|
-
xit('should return same as current hour', function () {
|
|
27
|
-
const curHour = tz.currentHour();
|
|
28
|
-
const hourSlot = 1000 * 60 * 60;
|
|
29
|
-
const curSlot = tz.currentTimeSlotIdx(hourSlot);
|
|
30
|
-
expect(curSlot).toEqual(curHour);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
describe('#matchingTimeSlotIdx', function () {
|
|
34
|
-
xit('should return same as current hour', function () {
|
|
35
|
-
const curHour = tz.currentHour();
|
|
36
|
-
const hourSlot = 1000 * 60 * 60;
|
|
37
|
-
const matchSlot = tz.matchingTimeSlotIdx(new Date().getTime(), hourSlot);
|
|
38
|
-
expect(matchSlot).toEqual(curHour);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Logger } from '../logger/logger.js';
|
|
2
|
-
import { LoggerLevelName } from '../logger/logger-level-name.js';
|
|
3
|
-
export class TimeoutToken {
|
|
4
|
-
title;
|
|
5
|
-
timeoutMS;
|
|
6
|
-
__timeoutTokenFlagField = true;
|
|
7
|
-
constructor(title, timeoutMS) {
|
|
8
|
-
this.title = title;
|
|
9
|
-
this.timeoutMS = timeoutMS;
|
|
10
|
-
}
|
|
11
|
-
writeToLog(logLevel = LoggerLevelName.warn) {
|
|
12
|
-
Logger.logByLevel(logLevel, 'Timed out after %d ms waiting for results of %s', this.timeoutMS, this.title);
|
|
13
|
-
}
|
|
14
|
-
static isTimeoutToken(value) {
|
|
15
|
-
return !!value && !!value['__timeoutTokenFlagField'];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TimeoutToken } from './timeout-token.js';
|
|
2
|
-
describe('#timeoutToken', function () {
|
|
3
|
-
it('should return the correct value for isTimeoutToken', function () {
|
|
4
|
-
const tt = new TimeoutToken('title', 20000);
|
|
5
|
-
const ntt = { a: 'b' };
|
|
6
|
-
expect(TimeoutToken.isTimeoutToken(tt)).toBeTruthy();
|
|
7
|
-
expect(TimeoutToken.isTimeoutToken(ntt)).toBeFalsy();
|
|
8
|
-
});
|
|
9
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Logger } from '../logger/logger.js';
|
|
2
|
-
export class TransformRatchet {
|
|
3
|
-
static transform(toTransform, rules = []) {
|
|
4
|
-
return TransformRatchet.transformGeneric(toTransform, rules, false, null);
|
|
5
|
-
}
|
|
6
|
-
static transformGeneric(toTransform, rules = [], isKey, context) {
|
|
7
|
-
let rval = null;
|
|
8
|
-
const type = typeof toTransform;
|
|
9
|
-
switch (type) {
|
|
10
|
-
case 'undefined':
|
|
11
|
-
case 'symbol':
|
|
12
|
-
case 'function':
|
|
13
|
-
rval = toTransform;
|
|
14
|
-
break;
|
|
15
|
-
case 'number':
|
|
16
|
-
case 'string':
|
|
17
|
-
case 'boolean':
|
|
18
|
-
rval = TransformRatchet.applyTransformToPrimitive(toTransform, rules, isKey, context);
|
|
19
|
-
break;
|
|
20
|
-
case 'object':
|
|
21
|
-
rval = TransformRatchet.applyTransformToObject(toTransform, rules, isKey, context);
|
|
22
|
-
break;
|
|
23
|
-
default:
|
|
24
|
-
throw new Error('Unrecognized type ' + type);
|
|
25
|
-
}
|
|
26
|
-
return rval;
|
|
27
|
-
}
|
|
28
|
-
static applyTransformToObject(toTransform, rules = [], isKey, context = null) {
|
|
29
|
-
Logger.silly('Tranform: %j, %s, %j', toTransform, isKey, context);
|
|
30
|
-
let rval = null;
|
|
31
|
-
if (toTransform != null) {
|
|
32
|
-
if (Array.isArray(toTransform)) {
|
|
33
|
-
rval = [];
|
|
34
|
-
toTransform.forEach((val) => {
|
|
35
|
-
const newVal = TransformRatchet.transformGeneric(val, rules, isKey, toTransform);
|
|
36
|
-
if (newVal != null) {
|
|
37
|
-
rval.push(newVal);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
rval = {};
|
|
43
|
-
Object.keys(toTransform).forEach((k) => {
|
|
44
|
-
const oldValue = toTransform[k];
|
|
45
|
-
const newKey = TransformRatchet.applyTransformToPrimitive(k, rules, true, toTransform);
|
|
46
|
-
if (newKey != null) {
|
|
47
|
-
let newValue = TransformRatchet.transformGeneric(oldValue, rules, false, toTransform);
|
|
48
|
-
newValue = TransformRatchet.applyTransformToPrimitive(newValue, rules, false, toTransform);
|
|
49
|
-
if (newValue != null) {
|
|
50
|
-
rval[newKey] = newValue;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
rval = TransformRatchet.applyTransformToPrimitive(rval, rules, false, toTransform);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return rval;
|
|
58
|
-
}
|
|
59
|
-
static applyTransformToPrimitive(toTransform, rules = [], isKey, context) {
|
|
60
|
-
let rval = toTransform;
|
|
61
|
-
rules.forEach((r) => {
|
|
62
|
-
rval = rval == null ? null : r.transform(rval, isKey, context);
|
|
63
|
-
});
|
|
64
|
-
return rval;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { TransformRatchet } from './transform-ratchet.js';
|
|
2
|
-
import { BuiltInTransforms } from '../transform/built-in-transforms.js';
|
|
3
|
-
describe('#formatBytes', function () {
|
|
4
|
-
const srcData = {
|
|
5
|
-
key1: 'value1',
|
|
6
|
-
key2: 'value2',
|
|
7
|
-
dateKey1: '1995-02-01',
|
|
8
|
-
intKey1: 0,
|
|
9
|
-
intKey2: 1,
|
|
10
|
-
boolKey1: true,
|
|
11
|
-
boolKey2: false,
|
|
12
|
-
camelSnake: 'this is a camel case',
|
|
13
|
-
subKey: {
|
|
14
|
-
key1: 'subValue1',
|
|
15
|
-
key2: 'subValue2',
|
|
16
|
-
convertToNumberInner: '42',
|
|
17
|
-
},
|
|
18
|
-
convertToNumber: '1',
|
|
19
|
-
convertToNumberAlso: '20',
|
|
20
|
-
};
|
|
21
|
-
const srcUnderData = {
|
|
22
|
-
new_key_1: 'value1',
|
|
23
|
-
sub_key: {
|
|
24
|
-
new_key_2: 'value2',
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
it('should convert camel to snakecase', function () {
|
|
28
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.keysOnly(BuiltInTransforms.camelToSnakeCase())]);
|
|
29
|
-
expect(result['dateKey1']).toBeUndefined();
|
|
30
|
-
expect(result['intKey1']).toBeUndefined();
|
|
31
|
-
expect(result['intKey2']).toBeUndefined();
|
|
32
|
-
expect(result['boolKey1']).toBeUndefined();
|
|
33
|
-
expect(result['boolKey2']).toBeUndefined();
|
|
34
|
-
expect(result['subKey']).toBeUndefined();
|
|
35
|
-
expect(result['date_key1']).toBeTruthy();
|
|
36
|
-
expect(result['int_key1']).toEqual(0);
|
|
37
|
-
expect(result['int_key2']).toBeTruthy();
|
|
38
|
-
expect(result['bool_key1']).toBeTruthy();
|
|
39
|
-
expect(result['bool_key1']).toBeTruthy();
|
|
40
|
-
expect(result['sub_key']).toBeTruthy();
|
|
41
|
-
});
|
|
42
|
-
it('should duplicate key1 into key3', function () {
|
|
43
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.makeDuplicateField('key1', 'key3')]);
|
|
44
|
-
expect(result.key1).toEqual('value1');
|
|
45
|
-
expect(result.key3).toEqual('value1');
|
|
46
|
-
});
|
|
47
|
-
it('should create a new field named key3', function () {
|
|
48
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.addField('key3', 'value3')]);
|
|
49
|
-
expect(result.key1).toEqual('value1');
|
|
50
|
-
expect(result.key3).toEqual('value3');
|
|
51
|
-
});
|
|
52
|
-
it('should reformat the date in dateField1 to MM-dd-yyyy', function () {
|
|
53
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.reformatDateFields(['dateKey1'], 'yyyy-MM-dd', 'MM/dd/yyyy')]);
|
|
54
|
-
expect(result.dateKey1).toEqual('02/01/1995');
|
|
55
|
-
});
|
|
56
|
-
it('should convert numbers to booleans', function () {
|
|
57
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.numberToBool(['intKey1', 'intKey2'])]);
|
|
58
|
-
expect(result.key1).toEqual('value1');
|
|
59
|
-
expect(result.intKey1).toEqual(false);
|
|
60
|
-
expect(result.intKey2).toEqual(true);
|
|
61
|
-
});
|
|
62
|
-
it('should convert booleans to number', function () {
|
|
63
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.boolToNumber(['boolKey1', 'boolKey2'])]);
|
|
64
|
-
expect(result.key1).toEqual('value1');
|
|
65
|
-
expect(result.boolKey1).toEqual(1);
|
|
66
|
-
expect(result.boolKey2).toEqual(0);
|
|
67
|
-
});
|
|
68
|
-
it('should concatenate key1 and key2 into key3', function () {
|
|
69
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.concatenateToNewField('key3', ['key1', 'key2'])]);
|
|
70
|
-
expect(result.key1).toBeUndefined();
|
|
71
|
-
expect(result.key2).toBeUndefined();
|
|
72
|
-
expect(result.key3).toEqual('value1value2');
|
|
73
|
-
expect(result.subKey.key1).toBeUndefined();
|
|
74
|
-
expect(result.subKey.key2).toBeUndefined();
|
|
75
|
-
expect(result.subKey.key3).toEqual('subValue1subValue2');
|
|
76
|
-
});
|
|
77
|
-
it('should strip a key correctly', function () {
|
|
78
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.stripStringTransform('key1')]);
|
|
79
|
-
expect(result.key1).toBeUndefined();
|
|
80
|
-
});
|
|
81
|
-
it('should rename a key correctly', function () {
|
|
82
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.stringReplaceTransform('key1', 'newKey1')]);
|
|
83
|
-
expect(result.key1).toBeUndefined();
|
|
84
|
-
expect(result.newKey1).toEqual('value1');
|
|
85
|
-
expect(result.subKey.key1).toBeUndefined();
|
|
86
|
-
expect(result.subKey.newKey1).toEqual('subValue1');
|
|
87
|
-
});
|
|
88
|
-
it('should retain only key1 and key2', function () {
|
|
89
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.keysOnly(BuiltInTransforms.retainAll(['key1', 'key2']))]);
|
|
90
|
-
expect(result.key1).toBeTruthy();
|
|
91
|
-
expect(result.key2).toBeTruthy();
|
|
92
|
-
expect(result.intKey1).toBeUndefined();
|
|
93
|
-
expect(result.boolKey1).toBeUndefined();
|
|
94
|
-
expect(result.subKey).toBeUndefined();
|
|
95
|
-
});
|
|
96
|
-
it('should remove only key1 and key2', function () {
|
|
97
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.keysOnly(BuiltInTransforms.removeAll(['key1', 'key2']))]);
|
|
98
|
-
expect(result.key1).toBeUndefined();
|
|
99
|
-
expect(result.key2).toBeUndefined();
|
|
100
|
-
expect(result.intKey1).toEqual(0);
|
|
101
|
-
expect(result.boolKey1).toBeTruthy();
|
|
102
|
-
expect(result.subKey).toBeTruthy();
|
|
103
|
-
});
|
|
104
|
-
it('should convert snake to camelcase', function () {
|
|
105
|
-
const result = TransformRatchet.transform(srcUnderData, [BuiltInTransforms.keysOnly(BuiltInTransforms.snakeToCamelCase())]);
|
|
106
|
-
expect(result['new_key_1']).toBeUndefined();
|
|
107
|
-
expect(result['sub_key']).toBeUndefined();
|
|
108
|
-
expect(result.newKey1).toBeTruthy();
|
|
109
|
-
expect(result.subKey).toBeTruthy();
|
|
110
|
-
expect(result.subKey.newKey2).toBeTruthy();
|
|
111
|
-
});
|
|
112
|
-
it('should convert strings to numbers', function () {
|
|
113
|
-
const result = TransformRatchet.transform(srcData, [BuiltInTransforms.valuesOnly(BuiltInTransforms.stringToNumber())]);
|
|
114
|
-
expect(result['convertToNumber']).toEqual(1);
|
|
115
|
-
expect(result['convertToNumberAlso']).toEqual(20);
|
|
116
|
-
expect(result['subKey']['convertToNumberInner']).toEqual(42);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import util from 'util';
|
|
2
|
-
export class ClassicSingleLineLogMessageFormatter {
|
|
3
|
-
formatMessage(msg, meta) {
|
|
4
|
-
let tmp = null;
|
|
5
|
-
if (msg) {
|
|
6
|
-
tmp = '';
|
|
7
|
-
tmp += meta.options.trace ? meta.options.trace + ' ' : '';
|
|
8
|
-
tmp += '[' + msg.lvl + '] ';
|
|
9
|
-
tmp += util.format(msg.messageSource, ...msg.subsVars);
|
|
10
|
-
}
|
|
11
|
-
return tmp;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export class LogMessageBuilder {
|
|
2
|
-
wrapped;
|
|
3
|
-
constructor(lvl, messageSource) {
|
|
4
|
-
if (!lvl) {
|
|
5
|
-
throw Error('Cannot set level to null/undefined');
|
|
6
|
-
}
|
|
7
|
-
this.wrapped = { lvl: lvl, timestamp: Date.now(), messageSource: messageSource };
|
|
8
|
-
}
|
|
9
|
-
clone() {
|
|
10
|
-
const rval = new LogMessageBuilder(this.wrapped.lvl, this.wrapped.messageSource);
|
|
11
|
-
rval.wrapped = Object.assign({}, this.wrapped);
|
|
12
|
-
return rval;
|
|
13
|
-
}
|
|
14
|
-
level(lvl) {
|
|
15
|
-
if (!lvl) {
|
|
16
|
-
throw Error('Cannot set level to null/undefined');
|
|
17
|
-
}
|
|
18
|
-
this.wrapped.lvl = lvl;
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
timestamp(val) {
|
|
22
|
-
if (!val) {
|
|
23
|
-
throw Error('Cannot set timestamp to null/undefined');
|
|
24
|
-
}
|
|
25
|
-
this.wrapped.timestamp = val;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
messageSource(val) {
|
|
29
|
-
this.wrapped.messageSource = val;
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
subVars(val) {
|
|
33
|
-
this.wrapped.subsVars = val || [];
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
params(val) {
|
|
37
|
-
this.wrapped.params = val || {};
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
p(name, value) {
|
|
41
|
-
this.wrapped.params = this.wrapped.params || {};
|
|
42
|
-
this.wrapped.params[name] = value;
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
toMessage() {
|
|
46
|
-
return Object.assign({}, this.wrapped);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export var LogMessageFormatType;
|
|
2
|
-
(function (LogMessageFormatType) {
|
|
3
|
-
LogMessageFormatType["ClassicSingleLine"] = "ClassicSingleLine";
|
|
4
|
-
LogMessageFormatType["StructuredJson"] = "StructuredJson";
|
|
5
|
-
LogMessageFormatType["None"] = "None";
|
|
6
|
-
})(LogMessageFormatType || (LogMessageFormatType = {}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|