chowbea-axios 1.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.
- package/LICENSE +22 -0
- package/README.md +162 -0
- package/bin/dev.js +13 -0
- package/bin/run.js +10 -0
- package/dist/commands/diff.d.ts +31 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +215 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/fetch.d.ts +28 -0
- package/dist/commands/fetch.d.ts.map +1 -0
- package/dist/commands/fetch.js +223 -0
- package/dist/commands/fetch.js.map +1 -0
- package/dist/commands/generate.d.ts +26 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +187 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/init.d.ts +92 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +738 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/status.d.ts +38 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +233 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/validate.d.ts +27 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +209 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/commands/watch.d.ts +34 -0
- package/dist/commands/watch.d.ts.map +1 -0
- package/dist/commands/watch.js +202 -0
- package/dist/commands/watch.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config.d.ts +151 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +336 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/errors.d.ts +77 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +144 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/fetcher.d.ts +115 -0
- package/dist/lib/fetcher.d.ts.map +1 -0
- package/dist/lib/fetcher.js +237 -0
- package/dist/lib/fetcher.js.map +1 -0
- package/dist/lib/generator.d.ts +96 -0
- package/dist/lib/generator.d.ts.map +1 -0
- package/dist/lib/generator.js +1575 -0
- package/dist/lib/generator.js.map +1 -0
- package/dist/lib/logger.d.ts +63 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +183 -0
- package/dist/lib/logger.js.map +1 -0
- package/oclif.manifest.json +556 -0
- package/package.json +68 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watch command - continuously polls for OpenAPI spec changes and regenerates.
|
|
3
|
+
* Includes graceful shutdown and automatic recovery from transient failures.
|
|
4
|
+
*/
|
|
5
|
+
import { Command, Flags } from "@oclif/core";
|
|
6
|
+
import { ensureOutputFolders, getOutputPaths, loadConfig, } from "../lib/config.js";
|
|
7
|
+
import { formatError } from "../lib/errors.js";
|
|
8
|
+
import { fetchOpenApiSpec, saveSpec } from "../lib/fetcher.js";
|
|
9
|
+
import { generate, generateClientFiles } from "../lib/generator.js";
|
|
10
|
+
import { createLogger, formatDuration, getLogLevel, logSeparator, } from "../lib/logger.js";
|
|
11
|
+
/**
|
|
12
|
+
* Watch for OpenAPI spec changes and regenerate automatically.
|
|
13
|
+
*/
|
|
14
|
+
export default class Watch extends Command {
|
|
15
|
+
static description = `Continuously poll for spec changes and regenerate.
|
|
16
|
+
|
|
17
|
+
Useful during development - automatically regenerates types when
|
|
18
|
+
your API changes. Press Ctrl+C to stop.
|
|
19
|
+
|
|
20
|
+
Gracefully handles network failures and preserves cache on shutdown.`;
|
|
21
|
+
static examples = [
|
|
22
|
+
{
|
|
23
|
+
command: "<%= config.bin %> watch",
|
|
24
|
+
description: "Start watching with default 10s interval",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
command: "<%= config.bin %> watch --interval 5000",
|
|
28
|
+
description: "Poll every 5 seconds",
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
static flags = {
|
|
32
|
+
config: Flags.string({
|
|
33
|
+
char: "c",
|
|
34
|
+
description: "Path to api.config.toml",
|
|
35
|
+
}),
|
|
36
|
+
interval: Flags.integer({
|
|
37
|
+
char: "i",
|
|
38
|
+
description: "Polling interval in milliseconds",
|
|
39
|
+
}),
|
|
40
|
+
quiet: Flags.boolean({
|
|
41
|
+
char: "q",
|
|
42
|
+
description: "Suppress non-error output",
|
|
43
|
+
default: false,
|
|
44
|
+
}),
|
|
45
|
+
debug: Flags.boolean({
|
|
46
|
+
char: "d",
|
|
47
|
+
description: "Show verbose cycle-by-cycle logs",
|
|
48
|
+
default: false,
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
// Track shutdown state
|
|
52
|
+
isShuttingDown = false;
|
|
53
|
+
cycleCounter = 0;
|
|
54
|
+
async run() {
|
|
55
|
+
const { flags } = await this.parse(Watch);
|
|
56
|
+
// Create initial logger (will be updated after config is loaded)
|
|
57
|
+
let logger = createLogger({ level: "warn" });
|
|
58
|
+
try {
|
|
59
|
+
// Load configuration first (auto-creates if missing)
|
|
60
|
+
const { config, projectRoot, configPath, wasCreated } = await loadConfig(flags.config);
|
|
61
|
+
// Update logger with appropriate level (uses config.watch.debug if no flag)
|
|
62
|
+
logger = createLogger({
|
|
63
|
+
level: getLogLevel(flags, config.watch.debug),
|
|
64
|
+
});
|
|
65
|
+
logSeparator(logger, "chowbea-axios watch");
|
|
66
|
+
logger.debug("Configuration loaded successfully");
|
|
67
|
+
if (wasCreated) {
|
|
68
|
+
logger.warn({ configPath }, "Created default api.config.toml - please review and update settings");
|
|
69
|
+
}
|
|
70
|
+
// Get output paths
|
|
71
|
+
const outputPaths = getOutputPaths(config, projectRoot);
|
|
72
|
+
logger.debug({ outputPaths }, "Resolved output paths");
|
|
73
|
+
// Ensure output folders exist (_internal, _generated)
|
|
74
|
+
await ensureOutputFolders(outputPaths);
|
|
75
|
+
// Generate client files if they don't exist (once at startup)
|
|
76
|
+
await generateClientFiles({
|
|
77
|
+
paths: outputPaths,
|
|
78
|
+
instanceConfig: config.instance,
|
|
79
|
+
logger,
|
|
80
|
+
});
|
|
81
|
+
// Determine polling interval
|
|
82
|
+
const intervalMs = flags.interval ?? config.poll_interval_ms;
|
|
83
|
+
const endpoint = config.api_endpoint;
|
|
84
|
+
logger.info({ endpoint, intervalMs }, "Starting watch mode - press Ctrl+C to stop");
|
|
85
|
+
// Set up graceful shutdown handlers
|
|
86
|
+
const shutdown = (signal) => {
|
|
87
|
+
if (this.isShuttingDown)
|
|
88
|
+
return;
|
|
89
|
+
this.isShuttingDown = true;
|
|
90
|
+
logger.warn({ signal }, "Shutting down watch mode...");
|
|
91
|
+
logger.info("Cache preserved for next run");
|
|
92
|
+
// Give time for any current operation to complete
|
|
93
|
+
setTimeout(() => {
|
|
94
|
+
process.exit(0);
|
|
95
|
+
}, 100);
|
|
96
|
+
};
|
|
97
|
+
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
98
|
+
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
99
|
+
// Main watch loop
|
|
100
|
+
while (!this.isShuttingDown) {
|
|
101
|
+
this.cycleCounter++;
|
|
102
|
+
const cycleId = this.cycleCounter;
|
|
103
|
+
await this.runCycle({
|
|
104
|
+
cycleId,
|
|
105
|
+
endpoint,
|
|
106
|
+
outputPaths,
|
|
107
|
+
logger,
|
|
108
|
+
headers: config.fetch?.headers,
|
|
109
|
+
});
|
|
110
|
+
// Wait before next cycle
|
|
111
|
+
if (!this.isShuttingDown) {
|
|
112
|
+
await this.delay(intervalMs);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
logger.error(formatError(error));
|
|
118
|
+
this.exit(1);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Runs a single watch cycle - fetch, check for changes, regenerate if needed.
|
|
123
|
+
*/
|
|
124
|
+
async runCycle(options) {
|
|
125
|
+
const { cycleId, endpoint, outputPaths, logger, headers } = options;
|
|
126
|
+
const startTime = Date.now();
|
|
127
|
+
// Only show cycle separator in debug mode
|
|
128
|
+
if (logger.level === "debug") {
|
|
129
|
+
logSeparator(logger, `Cycle ${cycleId}`);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
// Fetch the spec with retry logic (debug level - only shown with --debug)
|
|
133
|
+
logger.debug({ cycleId, endpoint }, "Checking for API changes...");
|
|
134
|
+
const fetchResult = await fetchOpenApiSpec({
|
|
135
|
+
endpoint,
|
|
136
|
+
specPath: outputPaths.spec,
|
|
137
|
+
cachePath: outputPaths.cache,
|
|
138
|
+
logger,
|
|
139
|
+
force: false,
|
|
140
|
+
headers,
|
|
141
|
+
});
|
|
142
|
+
// Handle network fallback
|
|
143
|
+
if (fetchResult.fromCache) {
|
|
144
|
+
logger.warn({ cycleId }, "Using cached spec due to network issues");
|
|
145
|
+
}
|
|
146
|
+
// Skip if unchanged (debug level - only shown with --debug)
|
|
147
|
+
if (!fetchResult.hasChanged) {
|
|
148
|
+
const durationMs = Date.now() - startTime;
|
|
149
|
+
logger.debug({ cycleId, durationMs: formatDuration(durationMs) }, "No changes detected, skipping generation");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Save the new spec
|
|
153
|
+
await saveSpec({
|
|
154
|
+
buffer: fetchResult.buffer,
|
|
155
|
+
hash: fetchResult.hash,
|
|
156
|
+
endpoint,
|
|
157
|
+
specPath: outputPaths.spec,
|
|
158
|
+
cachePath: outputPaths.cache,
|
|
159
|
+
});
|
|
160
|
+
logger.info({ cycleId, bytes: fetchResult.buffer.length }, "New spec detected, regenerating...");
|
|
161
|
+
// Run generation
|
|
162
|
+
const result = await generate({
|
|
163
|
+
paths: outputPaths,
|
|
164
|
+
logger,
|
|
165
|
+
});
|
|
166
|
+
logger.info({
|
|
167
|
+
cycleId,
|
|
168
|
+
operations: result.operationCount,
|
|
169
|
+
duration: formatDuration(result.durationMs),
|
|
170
|
+
}, "Generation completed");
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
// Log error but continue watching
|
|
174
|
+
logger.error({
|
|
175
|
+
cycleId,
|
|
176
|
+
error: error instanceof Error ? error.message : String(error),
|
|
177
|
+
}, "Cycle failed, will retry next interval");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Delays execution for the specified milliseconds.
|
|
182
|
+
* Respects shutdown state for early termination.
|
|
183
|
+
*/
|
|
184
|
+
delay(ms) {
|
|
185
|
+
return new Promise((resolve) => {
|
|
186
|
+
// Interval to check for early shutdown
|
|
187
|
+
const checkShutdown = setInterval(() => {
|
|
188
|
+
if (this.isShuttingDown) {
|
|
189
|
+
clearTimeout(timer);
|
|
190
|
+
clearInterval(checkShutdown);
|
|
191
|
+
resolve();
|
|
192
|
+
}
|
|
193
|
+
}, 100);
|
|
194
|
+
// Main timeout - clears interval on normal completion to prevent memory leak
|
|
195
|
+
const timer = setTimeout(() => {
|
|
196
|
+
clearInterval(checkShutdown);
|
|
197
|
+
resolve();
|
|
198
|
+
}, ms);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=watch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../src/commands/watch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EACL,YAAY,EACZ,cAAc,EACd,WAAW,E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ist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration loader with auto-create functionality.
|
|
3
|
+
* Finds project root, loads api.config.toml, and auto-creates if missing.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Fetch configuration for remote spec retrieval.
|
|
7
|
+
*/
|
|
8
|
+
export interface FetchConfig {
|
|
9
|
+
/** Headers to include when fetching the OpenAPI spec */
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Watch mode configuration for controlling debug output.
|
|
14
|
+
*/
|
|
15
|
+
export interface WatchConfig {
|
|
16
|
+
/** Enable debug logging in watch mode (shows cycle-by-cycle logs) */
|
|
17
|
+
debug: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Instance configuration for the generated axios client.
|
|
21
|
+
*/
|
|
22
|
+
export interface InstanceConfig {
|
|
23
|
+
/** Environment variable name for base URL (e.g., "VITE_API_URL") */
|
|
24
|
+
base_url_env: string;
|
|
25
|
+
/** localStorage key for auth token */
|
|
26
|
+
token_key: string;
|
|
27
|
+
/** Whether to include credentials (cookies) in requests */
|
|
28
|
+
with_credentials: boolean;
|
|
29
|
+
/** Request timeout in milliseconds */
|
|
30
|
+
timeout: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration structure for api.config.toml
|
|
34
|
+
*/
|
|
35
|
+
export interface ApiConfig {
|
|
36
|
+
/** Remote OpenAPI spec endpoint URL */
|
|
37
|
+
api_endpoint: string;
|
|
38
|
+
/** Local spec file path (takes priority over api_endpoint if set) */
|
|
39
|
+
spec_file?: string;
|
|
40
|
+
/** Polling interval in milliseconds for watch mode */
|
|
41
|
+
poll_interval_ms: number;
|
|
42
|
+
/** Output configuration */
|
|
43
|
+
output: {
|
|
44
|
+
/** Folder where all generated files are written */
|
|
45
|
+
folder: string;
|
|
46
|
+
};
|
|
47
|
+
/** Fetch configuration for remote spec retrieval */
|
|
48
|
+
fetch?: FetchConfig;
|
|
49
|
+
/** Instance configuration for the generated axios client */
|
|
50
|
+
instance: InstanceConfig;
|
|
51
|
+
/** Watch mode configuration */
|
|
52
|
+
watch: WatchConfig;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Default watch configuration values.
|
|
56
|
+
*/
|
|
57
|
+
export declare const DEFAULT_WATCH_CONFIG: WatchConfig;
|
|
58
|
+
/**
|
|
59
|
+
* Default instance configuration values.
|
|
60
|
+
*/
|
|
61
|
+
export declare const DEFAULT_INSTANCE_CONFIG: InstanceConfig;
|
|
62
|
+
/**
|
|
63
|
+
* Default configuration values used when auto-creating config.
|
|
64
|
+
*/
|
|
65
|
+
export declare const DEFAULT_CONFIG: ApiConfig;
|
|
66
|
+
/**
|
|
67
|
+
* Finds the project root by walking up to the nearest package.json.
|
|
68
|
+
* Returns the directory containing package.json.
|
|
69
|
+
*/
|
|
70
|
+
export declare function findProjectRoot(startDir?: string): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the path to api.config.toml relative to project root.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getConfigPath(projectRoot: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if a config file exists at the given path.
|
|
77
|
+
*/
|
|
78
|
+
export declare function configExists(configPath: string): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a default config file at the specified path.
|
|
81
|
+
*/
|
|
82
|
+
export declare function createDefaultConfig(configPath: string): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Spec source types for determining where to load the spec from.
|
|
85
|
+
*/
|
|
86
|
+
export type SpecSource = {
|
|
87
|
+
type: "local";
|
|
88
|
+
path: string;
|
|
89
|
+
} | {
|
|
90
|
+
type: "remote";
|
|
91
|
+
endpoint: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Resolves the spec source based on config and flag overrides.
|
|
95
|
+
* Priority: flag > config spec_file > config api_endpoint
|
|
96
|
+
*/
|
|
97
|
+
export declare function resolveSpecSource(config: ApiConfig, projectRoot: string, flagSpecFile?: string): SpecSource;
|
|
98
|
+
/**
|
|
99
|
+
* Loads and parses the configuration file.
|
|
100
|
+
* Auto-creates with defaults if missing.
|
|
101
|
+
*/
|
|
102
|
+
export declare function loadConfig(configPath?: string): Promise<{
|
|
103
|
+
config: ApiConfig;
|
|
104
|
+
projectRoot: string;
|
|
105
|
+
configPath: string;
|
|
106
|
+
wasCreated: boolean;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Resolves the output folder path to an absolute path.
|
|
110
|
+
*/
|
|
111
|
+
export declare function resolveOutputFolder(config: ApiConfig, projectRoot: string): string;
|
|
112
|
+
/**
|
|
113
|
+
* Output paths for all generated files.
|
|
114
|
+
*/
|
|
115
|
+
export interface OutputPaths {
|
|
116
|
+
/** Root output folder */
|
|
117
|
+
folder: string;
|
|
118
|
+
/** _internal folder for cache files */
|
|
119
|
+
internal: string;
|
|
120
|
+
/** _generated folder for auto-generated code */
|
|
121
|
+
generated: string;
|
|
122
|
+
/** Path to api.types.ts (generated types) */
|
|
123
|
+
types: string;
|
|
124
|
+
/** Path to api.operations.ts (generated operations) */
|
|
125
|
+
operations: string;
|
|
126
|
+
/** Path to api.helpers.ts (utility types - generated once) */
|
|
127
|
+
helpers: string;
|
|
128
|
+
/** Path to openapi.json spec file */
|
|
129
|
+
spec: string;
|
|
130
|
+
/** Path to .api-cache.json */
|
|
131
|
+
cache: string;
|
|
132
|
+
/** Path to api.instance.ts (axios instance - generated once) */
|
|
133
|
+
instance: string;
|
|
134
|
+
/** Path to api.error.ts (error handling - generated once) */
|
|
135
|
+
error: string;
|
|
136
|
+
/** Path to api.client.ts (typed facade - generated once) */
|
|
137
|
+
client: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Gets paths for all generated files based on config.
|
|
141
|
+
*/
|
|
142
|
+
export declare function getOutputPaths(config: ApiConfig, projectRoot: string): OutputPaths;
|
|
143
|
+
/**
|
|
144
|
+
* Ensures the output folder and subfolders exist, creating them if necessary.
|
|
145
|
+
*/
|
|
146
|
+
export declare function ensureOutputFolder(outputFolder: string): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Ensures all output folders exist (_internal, _generated, and root).
|
|
149
|
+
*/
|
|
150
|
+
export declare function ensureOutputFolders(paths: OutputPaths): Promise<void>;
|
|
151
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,qEAAqE;IACrE,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,YAAY,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,gBAAgB,EAAE,OAAO,CAAC;IAC1B,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,uCAAuC;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,gBAAgB,EAAE,MAAM,CAAC;IACzB,2BAA2B;IAC3B,MAAM,EAAE;QACN,mDAAmD;QACnD,MAAM,EA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