@lodestar/utils 1.0.0-rc.2 → 1.1.0-dev.03e778ba59

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.
@@ -52,7 +52,7 @@ function humanReadableTemplateFn(_info) {
52
52
  let str = "";
53
53
  if (info.timestamp)
54
54
  str += info.timestamp;
55
- str += `[${infoString.toUpperCase()}] ${info.level.padStart(infoPad)}: ${info.message}`;
55
+ str += `[${infoString}] ${info.level.padStart(infoPad)}: ${info.message}`;
56
56
  if (info.context !== undefined)
57
57
  str += " " + logCtxToString(info.context);
58
58
  if (info.error !== undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/logger/format.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,YAAY,EAAE,cAAc,EAAU,MAAM,WAAW,CAAC;AAChE,OAAO,EAAiB,mBAAmB,EAAC,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAC,mBAAmB,EAAC,MAAM,WAAW,CAAC;AAE9C,MAAM,EAAC,MAAM,EAAC,GAAG,OAAO,CAAC;AAezB,MAAM,UAAU,SAAS,CAAC,IAAoB;IAC5C,QAAQ,IAAI,CAAC,MAAM,EAAE;QACnB,KAAK,MAAM;YACT,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;QAE7B,KAAK,OAAO,CAAC;QACb;YACE,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC;KACvC;AACH,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAoB;IAClD,OAAO,MAAM,CAAC,OAAO,CACnB,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EACtD,MAAM,CAAC,QAAQ,EAAE,EACjB,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,CACvC,CAAC;AACJ,CAAC;AA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2D;IAC1F,MAAM,IAAI,GAAG,KAAwB,CAAC;IAEtC,MAAM,kBAAkB,GAAG,EAAE,CAAC;IAE9B,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;IACvD,MAAM,OAAO,GAAG,kBAAkB,GAAG,UAAU,CAAC,MAAM,CAAC;IAEvD,IAAI,GAAG,GAAG,EAAE,CAAC;IAEb,IAAI,IAAI,CAAC,SAAS;QAAE,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC;IAE1C,GAAG,IAAI,IAAI,UAAU,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;IAE1E,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;QAAE,GAAG,IAAI,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1E,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;QAAE,GAAG,IAAI,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEtE,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,6 +1,5 @@
1
1
  export * from "./interface.js";
2
2
  export * from "./format.js";
3
- export * from "./transport.js";
4
3
  export * from "./winston.js";
5
4
  export { LogData } from "./json.js";
6
5
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,4 @@
1
1
  export * from "./interface.js";
2
2
  export * from "./format.js";
3
- export * from "./transport.js";
4
3
  export * from "./winston.js";
5
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- import { Writable } from "node:stream";
3
1
  import { LogData } from "./json.js";
4
2
  export declare enum LogLevel {
5
3
  error = "error",
@@ -45,16 +43,16 @@ export interface ILoggerOptions {
45
43
  hideTimestamp?: boolean;
46
44
  timestampFormat?: TimestampFormat;
47
45
  }
46
+ export declare type LoggerChildOpts = {
47
+ module: string;
48
+ };
48
49
  export declare type LogHandler = (message: string, context?: LogData, error?: Error) => void;
49
50
  export interface ILogger {
50
51
  error: LogHandler;
51
52
  warn: LogHandler;
52
53
  info: LogHandler;
53
- important: LogHandler;
54
54
  verbose: LogHandler;
55
55
  debug: LogHandler;
56
- silly: LogHandler;
57
- stream(): Writable;
58
- child(options: ILoggerOptions): ILogger;
56
+ child(options: LoggerChildOpts): ILogger;
59
57
  }
60
58
  //# sourceMappingURL=interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/logger/interface.ts"],"names":[],"mappings":"AAGA,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,K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E;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"}
@@ -1,27 +1,19 @@
1
- /// <reference types="node" />
2
- import { Writable } from "node:stream";
3
- import { ILogger, ILoggerOptions } from "./interface.js";
4
- import { TransportOpts } from "./transport.js";
1
+ import winston from "winston";
2
+ import type { Logger } from "winston";
3
+ import { ILogger, ILoggerOptions, LoggerChildOpts } from "./interface.js";
5
4
  import { LogData } from "./json.js";
5
+ export declare function createWinstonLogger(options?: Partial<ILoggerOptions>, transports?: winston.transport[]): ILogger;
6
6
  export declare class WinstonLogger implements ILogger {
7
- private winston;
8
- private _level;
9
- private _options;
10
- private _transportOptsArr;
11
- constructor(options?: Partial<ILoggerOptions>, transportOptsArr?: TransportOpts[]);
7
+ private readonly winston;
8
+ constructor(winston: Logger);
9
+ static fromOpts(options?: Partial<ILoggerOptions>, transports?: winston.transport[]): WinstonLogger;
12
10
  error(message: string, context?: LogData, error?: Error): void;
13
11
  warn(message: string, context?: LogData, error?: Error): void;
14
12
  info(message: string, context?: LogData, error?: Error): void;
15
- important(message: string, context?: LogData, error?: Error): void;
16
13
  verbose(message: string, context?: LogData, error?: Error): void;
17
14
  debug(message: string, context?: LogData, error?: Error): void;
18
15
  silly(message: string, context?: LogData, error?: Error): void;
19
- profile(message: string, option?: {
20
- level: string;
21
- message: string;
22
- }): void;
23
- stream(): Writable;
24
- child(options: ILoggerOptions): WinstonLogger;
16
+ child(options: LoggerChildOpts): WinstonLogger;
25
17
  private createLogEntry;
26
18
  }
27
19
  //# sourceMappingURL=winston.d.ts.map
@@ -1,30 +1,23 @@
1
1
  import winston from "winston";
2
- import chalk from "chalk";
3
- import { defaultLogLevel, LogLevel, logLevelNum } from "./interface.js";
2
+ import { LogLevel } from "./interface.js";
4
3
  import { getFormat } from "./format.js";
5
- import { TransportType, fromTransportOpts } from "./transport.js";
6
- const { createLogger } = winston;
7
- const defaultTransportOpts = { type: TransportType.console };
4
+ export function createWinstonLogger(options = {}, transports) {
5
+ return WinstonLogger.fromOpts(options, transports);
6
+ }
8
7
  export class WinstonLogger {
9
- constructor(options = {}, transportOptsArr = [defaultTransportOpts]) {
10
- // `options.level` can override the level in the transport
11
- // This is necessary for child logger opts to take effect
12
- let minLevel = options === null || options === void 0 ? void 0 : options.level;
13
- for (const transportOpts of transportOptsArr) {
14
- transportOpts.level = getMinLevel(options === null || options === void 0 ? void 0 : options.level, transportOpts.level); // General level may override transport level
15
- minLevel = getMinLevel(minLevel, transportOpts.level); // Compute the minLevel from general and all transports
16
- }
17
- this.winston = createLogger({
18
- level: (options === null || options === void 0 ? void 0 : options.level) || defaultLogLevel,
19
- defaultMeta: { module: (options === null || options === void 0 ? void 0 : options.module) || "" },
8
+ constructor(winston) {
9
+ this.winston = winston;
10
+ }
11
+ static fromOpts(options = {}, transports) {
12
+ const defaultMeta = { module: (options === null || options === void 0 ? void 0 : options.module) || "" };
13
+ return new WinstonLogger(winston.createLogger({
14
+ // Do not set level at the logger level. Always control by Transport, unless for testLogger
15
+ level: options.level,
16
+ defaultMeta,
20
17
  format: getFormat(options),
21
- transports: transportOptsArr.map((transportOpts) => fromTransportOpts(transportOpts)),
18
+ transports,
22
19
  exitOnError: false,
23
- });
24
- this._level = minLevel || defaultLogLevel;
25
- // Store for child logger
26
- this._options = options;
27
- this._transportOptsArr = transportOptsArr;
20
+ }));
28
21
  }
29
22
  error(message, context, error) {
30
23
  this.createLogEntry(LogLevel.error, message, context, error);
@@ -35,9 +28,6 @@ export class WinstonLogger {
35
28
  info(message, context, error) {
36
29
  this.createLogEntry(LogLevel.info, message, context, error);
37
30
  }
38
- important(message, context, error) {
39
- this.createLogEntry(LogLevel.info, chalk.red(message), context, error);
40
- }
41
31
  verbose(message, context, error) {
42
32
  this.createLogEntry(LogLevel.verbose, message, context, error);
43
33
  }
@@ -47,34 +37,25 @@ export class WinstonLogger {
47
37
  silly(message, context, error) {
48
38
  this.createLogEntry(LogLevel.silly, message, context, error);
49
39
  }
50
- profile(message, option) {
51
- this.winston.profile(message, option);
52
- }
53
- stream() {
54
- throw Error("Not implemented");
55
- }
56
40
  child(options) {
57
- // Concat module tags
58
- if (options.module)
59
- options.module = [this._options.module, options.module].filter(Boolean).join(" ");
60
- return new WinstonLogger({ ...this._options, ...options }, this._transportOptsArr);
41
+ const parentMeta = this.winston.defaultMeta;
42
+ const childModule = [parentMeta === null || parentMeta === void 0 ? void 0 : parentMeta.module, options.module].filter(Boolean).join("/");
43
+ const defaultMeta = { module: childModule };
44
+ // Same strategy as Winston's source .child.
45
+ // However, their implementation of child is to merge info objects where parent takes precedence, so it's
46
+ // impossible for child to overwrite 'module' field. Instead the winston class is cloned as defaultMeta
47
+ // overwritten completely.
48
+ // https://github.com/winstonjs/winston/blob/3f1dcc13cda384eb30fe3b941764e47a5a5efc26/lib/winston/logger.js#L47
49
+ const childWinston = Object.create(this.winston);
50
+ childWinston.defaultMeta = defaultMeta;
51
+ return new WinstonLogger(childWinston);
61
52
  }
62
53
  createLogEntry(level, message, context, error) {
63
- // don't propagate if silenced or message level is more detailed than logger level
64
- if (logLevelNum[level] > logLevelNum[this._level]) {
65
- return;
66
- }
67
- this.winston[level](message, { context, error });
54
+ // Note: logger does not run format.transform function unless it will actually write the log to the transport
55
+ // If winston logger is called with `winston.info(message, context, error)` it triggers the "splat" path
56
+ // while we just need winston to forward an object to the custom formatter. So we call the fn signature below
57
+ // https://github.com/winstonjs/winston/blob/3f1dcc13cda384eb30fe3b941764e47a5a5efc26/lib/winston/logger.js#L221
58
+ this.winston.log(level, { message, context, error });
68
59
  }
69
60
  }
70
- /** Return the min LogLevel from multiple transports */
71
- function getMinLevel(...levelsArg) {
72
- const levels = levelsArg.filter((level) => Boolean(level));
73
- // Only if there are no levels to compute min from, consider defaultLogLevel
74
- if (levels.length === 0)
75
- return defaultLogLevel;
76
- return levels.reduce(
77
- // error: 0, warn: 1, info: 2, ...
78
- (minLevel, level) => (logLevelNum[level] > logLevelNum[minLevel] ? level : minLevel));
79
- }
80
61
  //# sourceMappingURL=winston.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"winston.js","sourceRoot":"","sources":["../../src/logger/winston.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,eAAe,EAA2B,QAAQ,EAAE,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAgB,aAAa,EAAE,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAG/E,MAAM,EAAC,YAAY,EAAC,GAAG,OAAO,CAAC;AAE/B,MAAM,oBAAoB,GAAkB,EAAC,IAAI,EAAE,aAAa,CAAC,OAAO,EAAC,CAAC;AAM1E,MAAM,OAAO,aAAa;IAMxB,YAAY,UAAmC,EAAE,EAAE,mBAAoC,CAAC,oBAAoB,CAAC;QAC3G,0DAA0D;QAC1D,yDAAyD;QACzD,IAAI,QAAQ,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC;QAC9B,KAAK,MAAM,aAAa,IAAI,gBAAgB,EAAE;YAC5C,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C;IAED,KAAK,CAAC,OAAe,EAAE,OAAiB,EAAE,KAAa;QACrD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,OAAwB;QAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAsC,CAAC;QACvE,MAAM,WAAW,GAAG,CAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnF,MAAM,WAAW,GAAgB,EAAC,MAAM,EAAE,WAAW,EAAC,CAAC;QAEvD,4CAA4C;QAC5C,yGAAyG;QACzG,uGAAuG;QACvG,0BAA0B;QAC1B,+GAA+G;QAC/G,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAwB,CAAC;QAExE,YAAY,CAAC,WAAW,GAAG,WAAW,CAAC;QAEvC,OAAO,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;IAEO,cAAc,CAAC,KAAe,EAAE,OAAe,EAAE,OAAiB,EAAE,KAAa;QACvF,6GAA6G;QAE7G,wGAAwG;QACxG,6GAA6G;QAC7G,gHAAgH;QAChH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;IACrD,CAAC;CACF"}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.0.0-rc.2",
14
+ "version": "1.1.0-dev.03e778ba59",
15
15
  "type": "module",
16
16
  "exports": "./lib/index.js",
17
17
  "files": [
@@ -44,9 +44,7 @@
44
44
  "case": "^1.6.3",
45
45
  "chalk": "^4.1.2",
46
46
  "js-yaml": "^3.13.1",
47
- "winston": "^3.3.3",
48
- "winston-daily-rotate-file": "^4.5.5",
49
- "winston-transport": "^4.3.0"
47
+ "winston": "^3.3.3"
50
48
  },
51
49
  "devDependencies": {
52
50
  "@types/js-yaml": "^3.12.1",
@@ -59,5 +57,5 @@
59
57
  "beacon",
60
58
  "blockchain"
61
59
  ],
62
- "gitHead": "4950ac0f3e33f3e9b1a103f4fba170a789e32a84"
60
+ "gitHead": "19a673c9d6fe06430be66bd04654895705bd1fa4"
63
61
  }
@@ -1,24 +0,0 @@
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
@@ -1,41 +0,0 @@
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
@@ -1 +0,0 @@
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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