nightingale 11.7.4 → 12.0.0

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.
@@ -1,147 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const nightingaleLogger = require('nightingale-logger');
6
- const nightingaleLevels = require('nightingale-levels');
7
-
8
- if (!global.__NIGHTINGALE_CONFIG) {
9
- global.__NIGHTINGALE_CONFIG = [];
10
- global.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
11
- global.__NIGHTINGALE_CONFIG_DEFAULT = {
12
- handlers: [],
13
- processors: []
14
- };
15
- }
16
-
17
- function clearCache() {
18
- global.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
19
- }
20
-
21
- function handleConfig(config) {
22
- if (config.keys) {
23
- if (config.pattern) {
24
- throw new Error('Cannot have key and pattern for the same config');
25
- }
26
-
27
- if (config.key) {
28
- throw new Error('Cannot have key and keys for the same config');
29
- }
30
- } else if (config.key) {
31
- if (config.pattern) {
32
- throw new Error('Cannot have key and pattern for the same config');
33
- }
34
-
35
- config.keys = [config.key];
36
- delete config.key;
37
- }
38
-
39
- if (config.handler) {
40
- if (config.handlers) {
41
- throw new Error('Cannot have handler and handlers for the same config');
42
- }
43
-
44
- config.handlers = [config.handler];
45
- delete config.handler;
46
- }
47
-
48
- if (config.processor) {
49
- if (config.processors) {
50
- throw new Error('Cannot have processors and processors for the same config');
51
- }
52
-
53
- config.processors = [config.processor];
54
- delete config.processor;
55
- }
56
-
57
- return config;
58
- }
59
-
60
- function configure(config) {
61
- if (global.__NIGHTINGALE_CONFIG.length > 0) {
62
- // eslint-disable-next-line no-console
63
- console.log('nightingale: warning: config overridden');
64
- }
65
-
66
- clearCache();
67
- global.__NIGHTINGALE_CONFIG = config.map(handleConfig);
68
- }
69
- function addConfig(config, unshift = false) {
70
- config = handleConfig(config);
71
-
72
- global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
73
-
74
- clearCache();
75
- }
76
-
77
- const configIsForKey = key => config => {
78
- if (config.keys) return config.keys.includes(key);
79
- if (config.pattern) return config.pattern.test(key);
80
- return true;
81
- };
82
-
83
- global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
84
- const globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;
85
- const existingCache = globalCache.get(key);
86
-
87
- if (existingCache) {
88
- return existingCache;
89
- }
90
-
91
- const loggerConfig = {
92
- handlers: [],
93
- processors: []
94
- };
95
-
96
- global.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
97
- if (config.handlers) loggerConfig.handlers.push(...config.handlers);
98
- if (config.processors) loggerConfig.processors.push(...config.processors);
99
- return config.stop;
100
- });
101
-
102
- globalCache.set(key, loggerConfig);
103
- return loggerConfig;
104
- };
105
-
106
- if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
107
- global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
108
- const {
109
- handlers,
110
- processors
111
- } = global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
112
-
113
- return {
114
- handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
115
- processors
116
- };
117
- };
118
- }
119
-
120
- /**
121
- * listen to uncaughtException and unhandledRejection
122
- * @param {Logger} [logger]
123
- */
124
-
125
- function listenUnhandledErrors(logger = new nightingaleLogger.Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
126
- process.on('uncaughtException', error => {
127
- logger.error('uncaughtException', {
128
- error,
129
- unhandled: true
130
- });
131
- });
132
- process.on('unhandledRejection', error => {
133
- logger.error('unhandledRejection', {
134
- error,
135
- unhandled: true
136
- });
137
- });
138
- }
139
-
140
- exports.Logger = nightingaleLogger.Logger;
141
- exports["default"] = nightingaleLogger.Logger;
142
- exports.Level = nightingaleLevels.Level;
143
- exports.levels = nightingaleLevels.Level;
144
- exports.addConfig = addConfig;
145
- exports.configure = configure;
146
- exports.listenUnhandledErrors = listenUnhandledErrors;
147
- //# sourceMappingURL=index-node12.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-node12.cjs.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && global.__NIGHTINGALE_GLOBAL_HANDLERS) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!global.__NIGHTINGALE_CONFIG) {\n global.__NIGHTINGALE_CONFIG = [];\n global.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n global.__NIGHTINGALE_CONFIG_DEFAULT = { handlers: [], processors: [] };\n}\n\nfunction clearCache(): void {\n global.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();\n}\n\nfunction handleConfig(config: Config): Config {\n if (config.keys) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n if (config.key) {\n throw new Error('Cannot have key and keys for the same config');\n }\n } else if (config.key) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n config.keys = [config.key];\n delete config.key;\n }\n\n if (config.handler) {\n if (config.handlers) {\n throw new Error('Cannot have handler and handlers for the same config');\n }\n config.handlers = [config.handler];\n delete config.handler;\n }\n\n if (config.processor) {\n if (config.processors) {\n throw new Error(\n 'Cannot have processors and processors for the same config',\n );\n }\n config.processors = [config.processor];\n delete config.processor;\n }\n\n return config;\n}\n\nexport function configure(config: Config[]): void {\n if (global.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n global.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);\n clearCache();\n}\n\nconst configIsForKey = (key: string) => (config: Config) => {\n if (config.keys) return config.keys.includes(key);\n if (config.pattern) return config.pattern.test(key);\n return true;\n};\n\nglobal.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;\n\n const existingCache = globalCache.get(key);\n\n if (existingCache) {\n return existingCache;\n }\n\n const loggerConfig: ComputedConfigForKey = {\n handlers: [],\n processors: [],\n };\n\n global.__NIGHTINGALE_CONFIG\n .filter(configIsForKey(key))\n .some((config: Config) => {\n if (config.handlers) loggerConfig.handlers.push(...config.handlers);\n if (config.processors) loggerConfig.processors.push(...config.processors);\n return config.stop;\n });\n\n globalCache.set(key, loggerConfig);\n return loggerConfig;\n};\n\nif (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: number,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);\n\n return {\n handlers: handlers.filter(\n (handler: Handler) =>\n level >= handler.minLevel &&\n (!handler.isHandling || handler.isHandling(level, key)),\n ),\n processors,\n };\n };\n}\n","import { Logger } from 'nightingale-logger';\n\nexport {\n /** @deprecated use named export instead */\n Logger as default,\n Logger,\n} from 'nightingale-logger';\nexport { Level, Level as levels } from 'nightingale-levels';\nexport { configure, addConfig } from './config';\n\n/**\n * listen to uncaughtException and unhandledRejection\n * @param {Logger} [logger]\n */\nexport function listenUnhandledErrors(\n logger: Logger = new Logger(\n 'nightingale:listenUnhandledErrors',\n 'UnhandledErrors',\n ),\n): void {\n process.on('uncaughtException', (error) => {\n logger.error('uncaughtException', { error, unhandled: true });\n });\n process.on('unhandledRejection', (error) => {\n logger.error('unhandledRejection', { error, unhandled: true });\n });\n}\n"],"names":["global","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","Error","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","push","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","minLevel","isHandling","listenUnhandledErrors","logger","Logger","process","on","error","unhandled"],"mappings":";;;;;;;AAQA,IAAI,CAACA,MAAM,CAACC,oBAAZ,EAAkC;AAChCD,EAAAA,MAAM,CAACC,oBAAP,GAA8B,EAA9B;AACAD,EAAAA,MAAM,CAACE,8BAAP,GAAwC,IAAIC,GAAJ,EAAxC;AAIAH,EAAAA,MAAM,CAACI,4BAAP,GAAsC;AAAEC,IAAAA,QAAQ,EAAE,EAAZ;AAAgBC,IAAAA,UAAU,EAAE;AAA5B,GAAtC;AACD;;AAED,SAASC,UAAT,GAA4B;AAC1BP,EAAAA,MAAM,CAACE,8BAAP,CAAsCM,KAAtC;AACD;;AAED,SAASC,YAAT,CAAsBC,MAAtB,EAA8C;AAC5C,MAAIA,MAAM,CAACC,IAAX,EAAiB;AACf,QAAID,MAAM,CAACE,OAAX,EAAoB;AAClB,YAAM,IAAIC,KAAJ,CAAU,iDAAV,CAAN;AACD;;AACD,QAAIH,MAAM,CAACI,GAAX,EAAgB;AACd,YAAM,IAAID,KAAJ,CAAU,8CAAV,CAAN;AACD;AACF,GAPD,MAOO,IAAIH,MAAM,CAACI,GAAX,EAAgB;AACrB,QAAIJ,MAAM,CAACE,OAAX,EAAoB;AAClB,YAAM,IAAIC,KAAJ,CAAU,iDAAV,CAAN;AACD;;AACDH,IAAAA,MAAM,CAACC,IAAP,GAAc,CAACD,MAAM,CAACI,GAAR,CAAd;AACA,WAAOJ,MAAM,CAACI,GAAd;AACD;;AAED,MAAIJ,MAAM,CAACK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CAACyB,UAAR,CAAmBF,KAAnB,EAA0BxB,GAA1B,CADxB,CAFM,CADL;AAMLR,MAAAA;AANK,KAAP;AAQD,GAfD;AAgBD;;ACnHD;AACA;AACA;AACA;;AACO,SAASmC,qBAAT,CACLC,MAAc,GAAG,IAAIC,wBAAJ,CACf,mCADe,EAEf,iBAFe,CADZ,EAKC;AACNC,EAAAA,OAAO,CAACC,EAAR,CAAW,mBAAX,EAAiCC,KAAD,IAAW;AACzCJ,IAAAA,MAAM,CAACI,KAAP,CAAa,mBAAb,EAAkC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAlC;AACD,GAFD;AAGAH,EAAAA,OAAO,CAACC,EAAR,CAAW,oBAAX,EAAkCC,KAAD,IAAW;AAC1CJ,IAAAA,MAAM,CAACI,KAAP,CAAa,oBAAb,EAAmC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAnC;AACD,GAFD;AAGD;;;;;;;;;;"}
@@ -1,138 +0,0 @@
1
- import { Logger } from 'nightingale-logger';
2
- export { Logger, Logger as default } from 'nightingale-logger';
3
- export { Level, Level as levels } from 'nightingale-levels';
4
-
5
- if (!global.__NIGHTINGALE_CONFIG) {
6
- global.__NIGHTINGALE_CONFIG = [];
7
- global.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
8
- global.__NIGHTINGALE_CONFIG_DEFAULT = {
9
- handlers: [],
10
- processors: []
11
- };
12
- }
13
-
14
- function clearCache() {
15
- global.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
16
- }
17
-
18
- function handleConfig(config) {
19
- if (config.keys) {
20
- if (config.pattern) {
21
- throw new Error('Cannot have key and pattern for the same config');
22
- }
23
-
24
- if (config.key) {
25
- throw new Error('Cannot have key and keys for the same config');
26
- }
27
- } else if (config.key) {
28
- if (config.pattern) {
29
- throw new Error('Cannot have key and pattern for the same config');
30
- }
31
-
32
- config.keys = [config.key];
33
- delete config.key;
34
- }
35
-
36
- if (config.handler) {
37
- if (config.handlers) {
38
- throw new Error('Cannot have handler and handlers for the same config');
39
- }
40
-
41
- config.handlers = [config.handler];
42
- delete config.handler;
43
- }
44
-
45
- if (config.processor) {
46
- if (config.processors) {
47
- throw new Error('Cannot have processors and processors for the same config');
48
- }
49
-
50
- config.processors = [config.processor];
51
- delete config.processor;
52
- }
53
-
54
- return config;
55
- }
56
-
57
- function configure(config) {
58
- if (global.__NIGHTINGALE_CONFIG.length > 0) {
59
- // eslint-disable-next-line no-console
60
- console.log('nightingale: warning: config overridden');
61
- }
62
-
63
- clearCache();
64
- global.__NIGHTINGALE_CONFIG = config.map(handleConfig);
65
- }
66
- function addConfig(config, unshift = false) {
67
- config = handleConfig(config);
68
-
69
- global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
70
-
71
- clearCache();
72
- }
73
-
74
- const configIsForKey = key => config => {
75
- if (config.keys) return config.keys.includes(key);
76
- if (config.pattern) return config.pattern.test(key);
77
- return true;
78
- };
79
-
80
- global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
81
- const globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;
82
- const existingCache = globalCache.get(key);
83
-
84
- if (existingCache) {
85
- return existingCache;
86
- }
87
-
88
- const loggerConfig = {
89
- handlers: [],
90
- processors: []
91
- };
92
-
93
- global.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
94
- if (config.handlers) loggerConfig.handlers.push(...config.handlers);
95
- if (config.processors) loggerConfig.processors.push(...config.processors);
96
- return config.stop;
97
- });
98
-
99
- globalCache.set(key, loggerConfig);
100
- return loggerConfig;
101
- };
102
-
103
- if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
104
- global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
105
- const {
106
- handlers,
107
- processors
108
- } = global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
109
-
110
- return {
111
- handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
112
- processors
113
- };
114
- };
115
- }
116
-
117
- /**
118
- * listen to uncaughtException and unhandledRejection
119
- * @param {Logger} [logger]
120
- */
121
-
122
- function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
123
- process.on('uncaughtException', error => {
124
- logger.error('uncaughtException', {
125
- error,
126
- unhandled: true
127
- });
128
- });
129
- process.on('unhandledRejection', error => {
130
- logger.error('unhandledRejection', {
131
- error,
132
- unhandled: true
133
- });
134
- });
135
- }
136
-
137
- export { addConfig, configure, listenUnhandledErrors };
138
- //# sourceMappingURL=index-node12.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-node12.mjs","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && global.__NIGHTINGALE_GLOBAL_HANDLERS) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!global.__NIGHTINGALE_CONFIG) {\n global.__NIGHTINGALE_CONFIG = [];\n global.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n global.__NIGHTINGALE_CONFIG_DEFAULT = { handlers: [], processors: [] };\n}\n\nfunction clearCache(): void {\n global.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();\n}\n\nfunction handleConfig(config: Config): Config {\n if (config.keys) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n if (config.key) {\n throw new Error('Cannot have key and keys for the same config');\n }\n } else if (config.key) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n config.keys = [config.key];\n delete config.key;\n }\n\n if (config.handler) {\n if (config.handlers) {\n throw new Error('Cannot have handler and handlers for the same config');\n }\n config.handlers = [config.handler];\n delete config.handler;\n }\n\n if (config.processor) {\n if (config.processors) {\n throw new Error(\n 'Cannot have processors and processors for the same config',\n );\n }\n config.processors = [config.processor];\n delete config.processor;\n }\n\n return config;\n}\n\nexport function configure(config: Config[]): void {\n if (global.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n global.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);\n clearCache();\n}\n\nconst configIsForKey = (key: string) => (config: Config) => {\n if (config.keys) return config.keys.includes(key);\n if (config.pattern) return config.pattern.test(key);\n return true;\n};\n\nglobal.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;\n\n const existingCache = globalCache.get(key);\n\n if (existingCache) {\n return existingCache;\n }\n\n const loggerConfig: ComputedConfigForKey = {\n handlers: [],\n processors: [],\n };\n\n global.__NIGHTINGALE_CONFIG\n .filter(configIsForKey(key))\n .some((config: Config) => {\n if (config.handlers) loggerConfig.handlers.push(...config.handlers);\n if (config.processors) loggerConfig.processors.push(...config.processors);\n return config.stop;\n });\n\n globalCache.set(key, loggerConfig);\n return loggerConfig;\n};\n\nif (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: number,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);\n\n return {\n handlers: handlers.filter(\n (handler: Handler) =>\n level >= handler.minLevel &&\n (!handler.isHandling || handler.isHandling(level, key)),\n ),\n processors,\n };\n };\n}\n","import { Logger } from 'nightingale-logger';\n\nexport {\n /** @deprecated use named export instead */\n Logger as default,\n Logger,\n} from 'nightingale-logger';\nexport { Level, Level as levels } from 'nightingale-levels';\nexport { configure, addConfig } from './config';\n\n/**\n * listen to uncaughtException and unhandledRejection\n * @param {Logger} [logger]\n */\nexport function listenUnhandledErrors(\n logger: Logger = new Logger(\n 'nightingale:listenUnhandledErrors',\n 'UnhandledErrors',\n ),\n): void {\n process.on('uncaughtException', (error) => {\n logger.error('uncaughtException', { error, unhandled: true });\n });\n process.on('unhandledRejection', (error) => {\n logger.error('unhandledRejection', { error, unhandled: true });\n });\n}\n"],"names":["global","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","Error","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","push","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","minLevel","isHandling","listenUnhandledErrors","logger","Logger","process","on","error","unhandled"],"mappings":";;;;AAQA,IAAI,CAACA,MAAM,CAACC,oBAAZ,EAAkC;AAChCD,EAAAA,MAAM,CAACC,oBAAP,GAA8B,EAA9B;AACAD,EAAAA,MAAM,CAACE,8BAAP,GAAwC,IAAIC,GAAJ,EAAxC;AAIAH,EAAAA,MAAM,CAACI,4BAAP,GAAsC;AAAEC,IAAAA,QAAQ,EAAE,EAAZ;AAAgBC,IAAAA,UAAU,EAAE;AAA5B,GAAtC;AACD;;AAED,SAASC,UAAT,GAA4B;AAC1BP,EAAAA,MAAM,CAACE,8BAAP,CAAsCM,KAAtC;AACD;;AAED,SAASC,YAAT,CAAsBC,MAAtB,EAA8C;AAC5C,MAAIA,MAAM,CAACC,IAAX,EAAiB;AACf,QAAID,MAAM,CAACE,OAAX,EAAoB;AAClB,YAAM,IAAIC,KAAJ,CAAU,iDAAV,CAAN;AACD;;AACD,QAAIH,MAAM,CAACI,GAAX,EAA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