@lodestar/utils 0.40.0-dev.266f9e2f44

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 (78) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +12 -0
  3. package/lib/assert.d.ts +45 -0
  4. package/lib/assert.js +69 -0
  5. package/lib/assert.js.map +1 -0
  6. package/lib/bytes.d.ts +17 -0
  7. package/lib/bytes.js +58 -0
  8. package/lib/bytes.js.map +1 -0
  9. package/lib/errors.d.ts +35 -0
  10. package/lib/errors.js +52 -0
  11. package/lib/errors.js.map +1 -0
  12. package/lib/format.d.ts +6 -0
  13. package/lib/format.js +10 -0
  14. package/lib/format.js.map +1 -0
  15. package/lib/index.d.ts +17 -0
  16. package/lib/index.js +17 -0
  17. package/lib/index.js.map +1 -0
  18. package/lib/logger/format.d.ts +6 -0
  19. package/lib/logger/format.js +62 -0
  20. package/lib/logger/format.js.map +1 -0
  21. package/lib/logger/index.d.ts +9 -0
  22. package/lib/logger/index.js +8 -0
  23. package/lib/logger/index.js.map +1 -0
  24. package/lib/logger/interface.d.ts +63 -0
  25. package/lib/logger/interface.js +38 -0
  26. package/lib/logger/interface.js.map +1 -0
  27. package/lib/logger/json.d.ts +18 -0
  28. package/lib/logger/json.js +115 -0
  29. package/lib/logger/json.js.map +1 -0
  30. package/lib/logger/transport.d.ts +24 -0
  31. package/lib/logger/transport.js +41 -0
  32. package/lib/logger/transport.js.map +1 -0
  33. package/lib/logger/util.d.ts +6 -0
  34. package/lib/logger/util.js +14 -0
  35. package/lib/logger/util.js.map +1 -0
  36. package/lib/logger/winston.d.ts +30 -0
  37. package/lib/logger/winston.js +83 -0
  38. package/lib/logger/winston.js.map +1 -0
  39. package/lib/math.d.ts +27 -0
  40. package/lib/math.js +53 -0
  41. package/lib/math.js.map +1 -0
  42. package/lib/notNullish.d.ts +10 -0
  43. package/lib/notNullish.js +12 -0
  44. package/lib/notNullish.js.map +1 -0
  45. package/lib/objects.d.ts +16 -0
  46. package/lib/objects.js +72 -0
  47. package/lib/objects.js.map +1 -0
  48. package/lib/promise.d.ts +5 -0
  49. package/lib/promise.js +22 -0
  50. package/lib/promise.js.map +1 -0
  51. package/lib/retry.d.ts +24 -0
  52. package/lib/retry.js +29 -0
  53. package/lib/retry.js.map +1 -0
  54. package/lib/sleep.d.ts +6 -0
  55. package/lib/sleep.js +32 -0
  56. package/lib/sleep.js.map +1 -0
  57. package/lib/sort.d.ts +2 -0
  58. package/lib/sort.js +10 -0
  59. package/lib/sort.js.map +1 -0
  60. package/lib/timeout.d.ts +2 -0
  61. package/lib/timeout.js +18 -0
  62. package/lib/timeout.js.map +1 -0
  63. package/lib/types.d.ts +10 -0
  64. package/lib/types.js +5 -0
  65. package/lib/types.js.map +1 -0
  66. package/lib/verifyMerkleBranch.d.ts +7 -0
  67. package/lib/verifyMerkleBranch.js +21 -0
  68. package/lib/verifyMerkleBranch.js.map +1 -0
  69. package/lib/yaml/index.d.ts +3 -0
  70. package/lib/yaml/index.js +10 -0
  71. package/lib/yaml/index.js.map +1 -0
  72. package/lib/yaml/int.d.ts +3 -0
  73. package/lib/yaml/int.js +174 -0
  74. package/lib/yaml/int.js.map +1 -0
  75. package/lib/yaml/schema.d.ts +3 -0
  76. package/lib/yaml/schema.js +21 -0
  77. package/lib/yaml/schema.js.map +1 -0
  78. package/package.json +63 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module logger
3
+ */
4
+ export * from "./interface.js";
5
+ export * from "./format.js";
6
+ export * from "./transport.js";
7
+ export * from "./winston.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @module logger
3
+ */
4
+ /// <reference types="node" />
5
+ import { Writable } from "node:stream";
6
+ import { LogData } from "./json.js";
7
+ export declare enum LogLevel {
8
+ error = "error",
9
+ warn = "warn",
10
+ info = "info",
11
+ verbose = "verbose",
12
+ debug = "debug",
13
+ silly = "silly"
14
+ }
15
+ export declare const logLevelNum: {
16
+ [K in LogLevel]: number;
17
+ };
18
+ export declare const LogLevels: LogLevel[];
19
+ export declare const customColors: {
20
+ error: string;
21
+ warn: string;
22
+ info: string;
23
+ verbose: string;
24
+ debug: string;
25
+ silly: string;
26
+ };
27
+ export declare const defaultLogLevel = LogLevel.info;
28
+ export declare type LogFormat = "human" | "json";
29
+ export declare const logFormats: LogFormat[];
30
+ export declare type EpochSlotOpts = {
31
+ genesisTime: number;
32
+ secondsPerSlot: number;
33
+ slotsPerEpoch: number;
34
+ };
35
+ export declare enum TimestampFormatCode {
36
+ DateRegular = 0,
37
+ EpochSlot = 1
38
+ }
39
+ export declare type TimestampFormat = {
40
+ format: TimestampFormatCode.DateRegular;
41
+ } | ({
42
+ format: TimestampFormatCode.EpochSlot;
43
+ } & EpochSlotOpts);
44
+ export interface ILoggerOptions {
45
+ level?: LogLevel;
46
+ module?: string;
47
+ format?: LogFormat;
48
+ hideTimestamp?: boolean;
49
+ timestampFormat?: TimestampFormat;
50
+ }
51
+ export declare type LogHandler = (message: string, context?: LogData, error?: Error) => void;
52
+ export interface ILogger {
53
+ error: LogHandler;
54
+ warn: LogHandler;
55
+ info: LogHandler;
56
+ important: LogHandler;
57
+ verbose: LogHandler;
58
+ debug: LogHandler;
59
+ silly: LogHandler;
60
+ stream(): Writable;
61
+ child(options: ILoggerOptions): ILogger;
62
+ }
63
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @module logger
3
+ */
4
+ export var LogLevel;
5
+ (function (LogLevel) {
6
+ LogLevel["error"] = "error";
7
+ LogLevel["warn"] = "warn";
8
+ LogLevel["info"] = "info";
9
+ LogLevel["verbose"] = "verbose";
10
+ LogLevel["debug"] = "debug";
11
+ LogLevel["silly"] = "silly";
12
+ })(LogLevel || (LogLevel = {}));
13
+ export const logLevelNum = {
14
+ [LogLevel.error]: 0,
15
+ [LogLevel.warn]: 1,
16
+ [LogLevel.info]: 2,
17
+ [LogLevel.verbose]: 3,
18
+ [LogLevel.debug]: 4,
19
+ [LogLevel.silly]: 5,
20
+ };
21
+ // eslint-disable-next-line @typescript-eslint/naming-convention
22
+ export const LogLevels = Object.values(LogLevel);
23
+ export const customColors = {
24
+ error: "red",
25
+ warn: "yellow",
26
+ info: "white",
27
+ verbose: "green",
28
+ debug: "pink",
29
+ silly: "purple",
30
+ };
31
+ export const defaultLogLevel = LogLevel.info;
32
+ export const logFormats = ["human", "json"];
33
+ export var TimestampFormatCode;
34
+ (function (TimestampFormatCode) {
35
+ TimestampFormatCode[TimestampFormatCode["DateRegular"] = 0] = "DateRegular";
36
+ TimestampFormatCode[TimestampFormatCode["EpochSlot"] = 1] = "EpochSlot";
37
+ })(TimestampFormatCode || (TimestampFormatCode = {}));
38
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/logger/interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,+BAAmB,CAAA;IACnB,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAED,MAAM,CAAC,MAAM,WAAW,GAA8B;IACpD,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IACrB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;CACpB,CAAC;AAEF,gEAAgE;AAChE,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,QAAQ;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC;AAG7C,MAAM,CAAC,MAAM,UAAU,GAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAOzD,MAAM,CAAN,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,2EAAW,CAAA;IACX,uEAAS,CAAA;AACX,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,QAG9B"}
@@ -0,0 +1,18 @@
1
+ declare type LogDataBasic = string | number | bigint | boolean | null | undefined;
2
+ export declare type LogData = LogDataBasic | Record<string, LogDataBasic> | LogDataBasic[] | Record<string, LogDataBasic>[];
3
+ /**
4
+ * Renders any log Context to JSON up to one level of depth.
5
+ *
6
+ * By limiting recursiveness, it renders limited content while ensuring safer logging.
7
+ * Consumers of the logger should ensure to send pre-formated data if they require nesting.
8
+ */
9
+ export declare function logCtxToJson(arg: unknown, depth?: number, fromError?: boolean): LogData;
10
+ /**
11
+ * Renders any log Context to a string up to one level of depth.
12
+ *
13
+ * By limiting recursiveness, it renders limited content while ensuring safer logging.
14
+ * Consumers of the logger should ensure to send pre-formated data if they require nesting.
15
+ */
16
+ export declare function logCtxToString(arg: unknown, depth?: number, fromError?: boolean): string;
17
+ export {};
18
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1,115 @@
1
+ import { toHexString } from "../bytes.js";
2
+ import { LodestarError } from "../errors.js";
3
+ import { mapValues } from "../objects.js";
4
+ const MAX_DEPTH = 0;
5
+ /**
6
+ * Renders any log Context to JSON up to one level of depth.
7
+ *
8
+ * By limiting recursiveness, it renders limited content while ensuring safer logging.
9
+ * Consumers of the logger should ensure to send pre-formated data if they require nesting.
10
+ */
11
+ export function logCtxToJson(arg, depth = 0, fromError = false) {
12
+ switch (typeof arg) {
13
+ case "bigint":
14
+ case "symbol":
15
+ case "function":
16
+ return arg.toString();
17
+ case "object":
18
+ if (arg === null)
19
+ return "null";
20
+ if (arg instanceof Uint8Array) {
21
+ return toHexString(arg);
22
+ }
23
+ // For any type that may include recursiveness break early at the first level
24
+ // - Prevent recursive loops
25
+ // - Ensures Error with deep complex metadata won't leak into the logs and cause bugs
26
+ if (depth > MAX_DEPTH) {
27
+ return "[object]";
28
+ }
29
+ if (arg instanceof Error) {
30
+ let metadata;
31
+ if (arg instanceof LodestarError) {
32
+ if (fromError) {
33
+ return "[LodestarErrorCircular]";
34
+ }
35
+ else {
36
+ // Allow one extra depth level for LodestarError
37
+ metadata = logCtxToJson(arg.getMetadata(), depth - 1, true);
38
+ }
39
+ }
40
+ else {
41
+ metadata = { message: arg.message };
42
+ }
43
+ if (arg.stack)
44
+ metadata.stack = arg.stack;
45
+ return metadata;
46
+ }
47
+ if (Array.isArray(arg)) {
48
+ return arg.map((item) => logCtxToJson(item, depth + 1));
49
+ }
50
+ return mapValues(arg, (item) => logCtxToJson(item, depth + 1));
51
+ // Already valid JSON
52
+ case "number":
53
+ case "string":
54
+ case "undefined":
55
+ case "boolean":
56
+ return arg;
57
+ default:
58
+ return String(arg);
59
+ }
60
+ }
61
+ /**
62
+ * Renders any log Context to a string up to one level of depth.
63
+ *
64
+ * By limiting recursiveness, it renders limited content while ensuring safer logging.
65
+ * Consumers of the logger should ensure to send pre-formated data if they require nesting.
66
+ */
67
+ export function logCtxToString(arg, depth = 0, fromError = false) {
68
+ switch (typeof arg) {
69
+ case "bigint":
70
+ case "symbol":
71
+ case "function":
72
+ return arg.toString();
73
+ case "object":
74
+ if (arg === null)
75
+ return "null";
76
+ if (arg instanceof Uint8Array) {
77
+ return toHexString(arg);
78
+ }
79
+ // For any type that may include recursiveness break early at the first level
80
+ // - Prevent recursive loops
81
+ // - Ensures Error with deep complex metadata won't leak into the logs and cause bugs
82
+ if (depth > MAX_DEPTH) {
83
+ return "[object]";
84
+ }
85
+ if (arg instanceof Error) {
86
+ let metadata;
87
+ if (arg instanceof LodestarError) {
88
+ if (fromError) {
89
+ return "[LodestarErrorCircular]";
90
+ }
91
+ else {
92
+ // Allow one extra depth level for LodestarError
93
+ metadata = logCtxToString(arg.getMetadata(), depth - 1, true);
94
+ }
95
+ }
96
+ else {
97
+ metadata = arg.message;
98
+ }
99
+ return `${metadata}\n${arg.stack || ""}`;
100
+ }
101
+ if (Array.isArray(arg)) {
102
+ return arg.map((item) => logCtxToString(item, depth + 1)).join(", ");
103
+ }
104
+ return Object.entries(arg)
105
+ .map(([key, value]) => `${key}=${logCtxToString(value, depth + 1)}`)
106
+ .join(", ");
107
+ case "number":
108
+ case "string":
109
+ case "undefined":
110
+ case "boolean":
111
+ default:
112
+ return String(arg);
113
+ }
114
+ }
115
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/logger/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AAExC,MAAM,SAAS,GAAG,CAAC,CAAC;AAMpB;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAY,EAAE,KAAK,GAAG,CAAC,EAAE,SAAS,GAAG,KAAK;IACrE,QAAQ,OAAO,GAAG,EAAE;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK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,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACtE;YAED,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;iBACvB,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;iBACnE,IAAI,CAAC,IAAI,CAAC,CAAC;QAEhB,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS,CAAC;QACf;YACE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACtB;AACH,CAAC"}
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ import TransportStream from "winston-transport";
3
+ import { LogLevel } from "./interface.js";
4
+ export declare enum TransportType {
5
+ console = "console",
6
+ file = "file",
7
+ stream = "stream"
8
+ }
9
+ export declare type TransportOpts = {
10
+ type: TransportType.console;
11
+ level?: LogLevel;
12
+ } | {
13
+ type: TransportType.file;
14
+ level?: LogLevel;
15
+ filename: string;
16
+ rotate?: boolean;
17
+ maxfiles?: number;
18
+ } | {
19
+ type: TransportType.stream;
20
+ level?: LogLevel;
21
+ stream: NodeJS.WritableStream;
22
+ };
23
+ export declare function fromTransportOpts(transportOpts: TransportOpts): TransportStream;
24
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1,41 @@
1
+ import winston from "winston";
2
+ import DailyRotateFile from "winston-daily-rotate-file";
3
+ const { transports } = winston;
4
+ export var TransportType;
5
+ (function (TransportType) {
6
+ TransportType["console"] = "console";
7
+ TransportType["file"] = "file";
8
+ TransportType["stream"] = "stream";
9
+ })(TransportType || (TransportType = {}));
10
+ export function fromTransportOpts(transportOpts) {
11
+ switch (transportOpts.type) {
12
+ case TransportType.console:
13
+ return new transports.Console({
14
+ debugStdout: true,
15
+ level: transportOpts.level,
16
+ handleExceptions: true,
17
+ });
18
+ case TransportType.file:
19
+ return transportOpts.rotate
20
+ ? new DailyRotateFile({
21
+ level: transportOpts.level,
22
+ //insert the date pattern in filename before the file extension.
23
+ filename: transportOpts.filename.replace(/\.(?=[^.]*$)|$/, "-%DATE%$&"),
24
+ datePattern: "YYYY-MM-DD",
25
+ handleExceptions: true,
26
+ maxFiles: transportOpts.maxfiles,
27
+ })
28
+ : new transports.File({
29
+ level: transportOpts.level,
30
+ filename: transportOpts.filename,
31
+ handleExceptions: true,
32
+ });
33
+ case TransportType.stream:
34
+ return new transports.Stream({
35
+ level: transportOpts.level,
36
+ stream: transportOpts.stream,
37
+ handleExceptions: true,
38
+ });
39
+ }
40
+ }
41
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/logger/transport.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAIxD,MAAM,EAAC,UAAU,EAAC,GAAG,OAAO,CAAC;AAE7B,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,8BAAa,CAAA;IACb,kCAAiB,CAAA;AACnB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAOD,MAAM,UAAU,iBAAiB,CAAC,aAA4B;IAC5D,QAAQ,aAAa,CAAC,IAAI,EAAE;QAC1B,KAAK,aAAa,CAAC,OAAO;YACxB,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC;gBAC5B,WAAW,EAAE,IAAI;gBACjB,KAAK,EAAE,aAAa,CAAC,KAAK;gBAC1B,gBAAgB,EAAE,IAAI;aACvB,CAAC,CAAC;QAEL,KAAK,aAAa,CAAC,IAAI;YACrB,OAAO,aAAa,CAAC,MAAM;gBACzB,CAAC,CAAC,IAAI,eAAe,CAAC;oBAClB,KAAK,EAAE,aAAa,CAAC,KAAK;oBAC1B,gEAAgE;oBAChE,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,EAAE,WAAW,CAAC;oBACvE,WAAW,EAAE,YAAY;oBACzB,gBAAgB,EAAE,IAAI;oBACtB,QAAQ,EAAE,aAAa,CAAC,QAAQ;iBACjC,CAAC;gBACJ,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC;oBAClB,KAAK,EAAE,aAAa,CAAC,KAAK;oBAC1B,QAAQ,EAAE,aAAa,CAAC,QAAQ;oBAChC,gBAAgB,EAAE,IAAI;iBACvB,CAAC,CAAC;QAET,KAAK,aAAa,CAAC,MAAM;YACvB,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC;gBAC3B,KAAK,EAAE,aAAa,CAAC,KAAK;gBAC1B,MAAM,EAAE,aAAa,CAAC,MAAM;gBAC5B,gBAAgB,EAAE,IAAI;aACvB,CAAC,CAAC;KACN;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { EpochSlotOpts } from "./interface.js";
2
+ /**
3
+ * Formats time as: `EPOCH/SLOT_INDEX SECONDS.MILISECONDS
4
+ */
5
+ export declare function formatEpochSlotTime(opts: EpochSlotOpts, now?: number): string;
6
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Formats time as: `EPOCH/SLOT_INDEX SECONDS.MILISECONDS
3
+ */
4
+ export function formatEpochSlotTime(opts, now = Date.now()) {
5
+ const nowSec = now / 1000;
6
+ const secSinceGenesis = nowSec - opts.genesisTime;
7
+ const epoch = Math.floor(secSinceGenesis / (opts.slotsPerEpoch * opts.secondsPerSlot));
8
+ const epochStartSec = opts.genesisTime + epoch * opts.slotsPerEpoch * opts.secondsPerSlot;
9
+ const secSinceStartEpoch = nowSec - epochStartSec;
10
+ const slotIndex = Math.floor(secSinceStartEpoch / opts.secondsPerSlot);
11
+ const slotSec = secSinceStartEpoch % opts.secondsPerSlot;
12
+ return `Eph ${epoch}/${slotIndex} ${slotSec.toFixed(3)}`;
13
+ }
14
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/logger/util.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAmB,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IACvE,MAAM,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC;IAC1B,MAAM,eAAe,GAAG,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC;IAClD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;IACvF,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,GAAG,KAAK,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;IAC1F,MAAM,kBAAkB,GAAG,MAAM,GAAG,aAAa,CAAC;IAClD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;IACvE,MAAM,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAC;IACzD,OAAO,OAAO,KAAK,IAAI,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @module logger
3
+ */
4
+ /// <reference types="node" />
5
+ import { Writable } from "node:stream";
6
+ import { ILogger, ILoggerOptions } from "./interface.js";
7
+ import { TransportOpts } from "./transport.js";
8
+ import { LogData } from "./json.js";
9
+ export declare class WinstonLogger implements ILogger {
10
+ private winston;
11
+ private _level;
12
+ private _options;
13
+ private _transportOptsArr;
14
+ constructor(options?: Partial<ILoggerOptions>, transportOptsArr?: TransportOpts[]);
15
+ error(message: string, context?: LogData, error?: Error): void;
16
+ warn(message: string, context?: LogData, error?: Error): void;
17
+ info(message: string, context?: LogData, error?: Error): void;
18
+ important(message: string, context?: LogData, error?: Error): void;
19
+ verbose(message: string, context?: LogData, error?: Error): void;
20
+ debug(message: string, context?: LogData, error?: Error): void;
21
+ silly(message: string, context?: LogData, error?: Error): void;
22
+ profile(message: string, option?: {
23
+ level: string;
24
+ message: string;
25
+ }): void;
26
+ stream(): Writable;
27
+ child(options: ILoggerOptions): WinstonLogger;
28
+ private createLogEntry;
29
+ }
30
+ //# sourceMappingURL=winston.d.ts.map
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @module logger
3
+ */
4
+ import winston from "winston";
5
+ import chalk from "chalk";
6
+ import { defaultLogLevel, LogLevel, logLevelNum } from "./interface.js";
7
+ import { getFormat } from "./format.js";
8
+ import { TransportType, fromTransportOpts } from "./transport.js";
9
+ const { createLogger } = winston;
10
+ const defaultTransportOpts = { type: TransportType.console };
11
+ export class WinstonLogger {
12
+ constructor(options = {}, transportOptsArr = [defaultTransportOpts]) {
13
+ // `options.level` can override the level in the transport
14
+ // This is necessary for child logger opts to take effect
15
+ let minLevel = options === null || options === void 0 ? void 0 : options.level;
16
+ for (const transportOpts of transportOptsArr) {
17
+ transportOpts.level = getMinLevel(options === null || options === void 0 ? void 0 : options.level, transportOpts.level); // General level may override transport level
18
+ minLevel = getMinLevel(minLevel, transportOpts.level); // Compute the minLevel from general and all transports
19
+ }
20
+ this.winston = createLogger({
21
+ level: (options === null || options === void 0 ? void 0 : options.level) || defaultLogLevel,
22
+ defaultMeta: { module: (options === null || options === void 0 ? void 0 : options.module) || "" },
23
+ format: getFormat(options),
24
+ transports: transportOptsArr.map((transportOpts) => fromTransportOpts(transportOpts)),
25
+ exitOnError: false,
26
+ });
27
+ this._level = minLevel || defaultLogLevel;
28
+ // Store for child logger
29
+ this._options = options;
30
+ this._transportOptsArr = transportOptsArr;
31
+ }
32
+ error(message, context, error) {
33
+ this.createLogEntry(LogLevel.error, message, context, error);
34
+ }
35
+ warn(message, context, error) {
36
+ this.createLogEntry(LogLevel.warn, message, context, error);
37
+ }
38
+ info(message, context, error) {
39
+ this.createLogEntry(LogLevel.info, message, context, error);
40
+ }
41
+ important(message, context, error) {
42
+ this.createLogEntry(LogLevel.info, chalk.red(message), context, error);
43
+ }
44
+ verbose(message, context, error) {
45
+ this.createLogEntry(LogLevel.verbose, message, context, error);
46
+ }
47
+ debug(message, context, error) {
48
+ this.createLogEntry(LogLevel.debug, message, context, error);
49
+ }
50
+ silly(message, context, error) {
51
+ this.createLogEntry(LogLevel.silly, message, context, error);
52
+ }
53
+ profile(message, option) {
54
+ this.winston.profile(message, option);
55
+ }
56
+ stream() {
57
+ throw Error("Not implemented");
58
+ }
59
+ child(options) {
60
+ // Concat module tags
61
+ if (options.module)
62
+ options.module = [this._options.module, options.module].filter(Boolean).join(" ");
63
+ return new WinstonLogger({ ...this._options, ...options }, this._transportOptsArr);
64
+ }
65
+ createLogEntry(level, message, context, error) {
66
+ // don't propagate if silenced or message level is more detailed than logger level
67
+ if (logLevelNum[level] > logLevelNum[this._level]) {
68
+ return;
69
+ }
70
+ this.winston[level](message, { context, error });
71
+ }
72
+ }
73
+ /** Return the min LogLevel from multiple transports */
74
+ function getMinLevel(...levelsArg) {
75
+ const levels = levelsArg.filter((level) => Boolean(level));
76
+ // Only if there are no levels to compute min from, consider defaultLogLevel
77
+ if (levels.length === 0)
78
+ return defaultLogLevel;
79
+ return levels.reduce(
80
+ // error: 0, warn: 1, info: 2, ...
81
+ (minLevel, level) => (logLevelNum[level] > logLevelNum[minLevel] ? level : minLevel));
82
+ }
83
+ //# sourceMappingURL=winston.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"winston.js","sourceRoot":"","sources":["../../src/logger/winston.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,eAAe,EAA2B,QAAQ,EAAE,WAAW,EAAC,MAAM,g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,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CACrF,CAAC;AACJ,CAAC"}
package/lib/math.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @module util/math
3
+ */
4
+ /**
5
+ * Return the min number between two big numbers.
6
+ */
7
+ export declare function bigIntMin(a: bigint, b: bigint): bigint;
8
+ /**
9
+ * Return the max number between two big numbers.
10
+ */
11
+ export declare function bigIntMax(a: bigint, b: bigint): bigint;
12
+ export declare function intDiv(dividend: number, divisor: number): number;
13
+ /**
14
+ * Calculate the largest integer k such that k**2 <= n.
15
+ */
16
+ export declare function intSqrt(n: number): number;
17
+ export declare function bigIntSqrt(n: bigint): bigint;
18
+ /**
19
+ * Regenerates a random integer between min (included) and max (excluded).
20
+ */
21
+ export declare function randBetween(min: number, max: number): number;
22
+ /**
23
+ * Wraps randBetween and returns a bigNumber.
24
+ * @returns {bigint}
25
+ */
26
+ export declare function randBetweenBigInt(min: number, max: number): bigint;
27
+ //# sourceMappingURL=math.d.ts.map
package/lib/math.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @module util/math
3
+ */
4
+ /**
5
+ * Return the min number between two big numbers.
6
+ */
7
+ export function bigIntMin(a, b) {
8
+ return a < b ? a : b;
9
+ }
10
+ /**
11
+ * Return the max number between two big numbers.
12
+ */
13
+ export function bigIntMax(a, b) {
14
+ return a > b ? a : b;
15
+ }
16
+ export function intDiv(dividend, divisor) {
17
+ return Math.floor(dividend / divisor);
18
+ }
19
+ /**
20
+ * Calculate the largest integer k such that k**2 <= n.
21
+ */
22
+ export function intSqrt(n) {
23
+ let x = n;
24
+ let y = intDiv(x + 1, 2);
25
+ while (y < x) {
26
+ x = y;
27
+ y = intDiv(x + intDiv(n, x), 2);
28
+ }
29
+ return x;
30
+ }
31
+ export function bigIntSqrt(n) {
32
+ let x = n;
33
+ let y = (x + BigInt(1)) / BigInt(2);
34
+ while (y < x) {
35
+ x = y;
36
+ y = (x + n / x) / BigInt(2);
37
+ }
38
+ return x;
39
+ }
40
+ /**
41
+ * Regenerates a random integer between min (included) and max (excluded).
42
+ */
43
+ export function randBetween(min, max) {
44
+ return Math.floor(Math.random() * (max - min)) + min;
45
+ }
46
+ /**
47
+ * Wraps randBetween and returns a bigNumber.
48
+ * @returns {bigint}
49
+ */
50
+ export function randBetweenBigInt(min, max) {
51
+ return BigInt(randBetween(min, max));
52
+ }
53
+ //# sourceMappingURL=math.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.js","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,CAAS,EAAE,CAAS;IAC5C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,CAAS,EAAE,CAAS;IAC5C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,QAAgB,EAAE,OAAe;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,CAAS;IAC/B,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACzB,OAAO,CAAC,GAAG,CAAC,EAAE;QACZ,CAAC,GAAG,CAAC,CAAC;QACN,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KACjC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpC,OAAO,CAAC,GAAG,CAAC,EAAE;QACZ,CAAC,GAAG,CAAC,CAAC;QACN,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;KAC7B;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAW;IAClD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAW,EAAE,GAAW;IACxD,OAAO,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Type-safe helper to filter out nullist values from an array
3
+ * ```js
4
+ * const array: (string | null)[] = ['foo', null];
5
+ * const filteredArray: string[] = array.filter(notEmpty);
6
+ * ```
7
+ * @param value
8
+ */
9
+ export declare function notNullish<TValue>(value: TValue | null | undefined): value is TValue;
10
+ //# sourceMappingURL=notNullish.d.ts.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Type-safe helper to filter out nullist values from an array
3
+ * ```js
4
+ * const array: (string | null)[] = ['foo', null];
5
+ * const filteredArray: string[] = array.filter(notEmpty);
6
+ * ```
7
+ * @param value
8
+ */
9
+ export function notNullish(value) {
10
+ return value !== null && value !== undefined;
11
+ }
12
+ //# sourceMappingURL=notNullish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notNullish.js","sourceRoot":"","sources":["../src/notNullish.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAS,KAAgC;IACjE,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,16 @@
1
+ export declare type KeyCase = "snake" | "constant" | "camel" | "param" | "header" | "pascal" | "dot" | "notransform";
2
+ export declare function toExpectedCase(value: string, expectedCase?: KeyCase, customCasingMap?: Record<string, string>): string;
3
+ export declare function isPlainObject(o: unknown): boolean;
4
+ /**
5
+ * Creates an object with the same keys as object and values generated by running each own enumerable
6
+ * string keyed property of object thru iteratee.
7
+ *
8
+ * Inspired on lodash.mapValues, see https://lodash.com/docs/4.17.15#mapValues
9
+ */
10
+ export declare function mapValues<T extends {
11
+ [K: string]: any;
12
+ }, R>(obj: T, iteratee: (value: T[keyof T], key: keyof T) => R): {
13
+ [K in keyof T]: R;
14
+ };
15
+ export declare function objectToExpectedCase<T extends Record<string, unknown> | Record<string, unknown>[]>(obj: T, expectedCase?: "snake" | "constant" | "camel" | "param" | "header" | "pascal" | "dot" | "notransform"): T;
16
+ //# sourceMappingURL=objects.d.ts.map