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,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration loader with auto-create functionality.
|
|
3
|
+
* Finds project root, loads api.config.toml, and auto-creates if missing.
|
|
4
|
+
*/
|
|
5
|
+
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import toml from "toml";
|
|
8
|
+
import { ConfigError, ConfigValidationError } from "./errors.js";
|
|
9
|
+
/**
|
|
10
|
+
* Default watch configuration values.
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_WATCH_CONFIG = {
|
|
13
|
+
debug: false,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Default instance configuration values.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_INSTANCE_CONFIG = {
|
|
19
|
+
base_url_env: "VITE_API_URL",
|
|
20
|
+
token_key: "auth-token",
|
|
21
|
+
with_credentials: true,
|
|
22
|
+
timeout: 30_000,
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Default configuration values used when auto-creating config.
|
|
26
|
+
*/
|
|
27
|
+
export const DEFAULT_CONFIG = {
|
|
28
|
+
api_endpoint: "http://localhost:3000/docs/swagger/json",
|
|
29
|
+
spec_file: undefined,
|
|
30
|
+
poll_interval_ms: 10_000,
|
|
31
|
+
output: {
|
|
32
|
+
folder: "app/services/api",
|
|
33
|
+
},
|
|
34
|
+
fetch: undefined,
|
|
35
|
+
instance: DEFAULT_INSTANCE_CONFIG,
|
|
36
|
+
watch: DEFAULT_WATCH_CONFIG,
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Default config file template with comments.
|
|
40
|
+
*/
|
|
41
|
+
const CONFIG_TEMPLATE = `# Chowbea Axios Configuration
|
|
42
|
+
|
|
43
|
+
api_endpoint = "http://localhost:3000/docs/swagger/json"
|
|
44
|
+
# spec_file = "./openapi.json" # Use local file instead of remote
|
|
45
|
+
poll_interval_ms = 10000
|
|
46
|
+
|
|
47
|
+
[output]
|
|
48
|
+
folder = "app/services/api"
|
|
49
|
+
|
|
50
|
+
[instance]
|
|
51
|
+
base_url_env = "VITE_API_URL"
|
|
52
|
+
token_key = "auth-token"
|
|
53
|
+
with_credentials = true
|
|
54
|
+
timeout = 30000
|
|
55
|
+
|
|
56
|
+
[watch]
|
|
57
|
+
debug = false
|
|
58
|
+
`;
|
|
59
|
+
/**
|
|
60
|
+
* Finds the project root by walking up to the nearest package.json.
|
|
61
|
+
* Returns the directory containing package.json.
|
|
62
|
+
*/
|
|
63
|
+
export async function findProjectRoot(startDir) {
|
|
64
|
+
let currentDir = startDir ?? process.cwd();
|
|
65
|
+
// Walk up the directory tree looking for package.json
|
|
66
|
+
while (currentDir !== path.dirname(currentDir)) {
|
|
67
|
+
const packageJsonPath = path.join(currentDir, "package.json");
|
|
68
|
+
try {
|
|
69
|
+
await access(packageJsonPath);
|
|
70
|
+
return currentDir;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// package.json not found, continue walking up
|
|
74
|
+
currentDir = path.dirname(currentDir);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// No package.json found, use the starting directory
|
|
78
|
+
return startDir ?? process.cwd();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets the path to api.config.toml relative to project root.
|
|
82
|
+
*/
|
|
83
|
+
export function getConfigPath(projectRoot) {
|
|
84
|
+
return path.join(projectRoot, "api.config.toml");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Checks if a config file exists at the given path.
|
|
88
|
+
*/
|
|
89
|
+
export async function configExists(configPath) {
|
|
90
|
+
try {
|
|
91
|
+
await access(configPath);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates a default config file at the specified path.
|
|
100
|
+
*/
|
|
101
|
+
export async function createDefaultConfig(configPath) {
|
|
102
|
+
const configDir = path.dirname(configPath);
|
|
103
|
+
// Ensure directory exists
|
|
104
|
+
await mkdir(configDir, { recursive: true });
|
|
105
|
+
// Write the config template
|
|
106
|
+
await writeFile(configPath, CONFIG_TEMPLATE, "utf8");
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Validates the watch configuration section.
|
|
110
|
+
*/
|
|
111
|
+
function validateWatchConfig(watch) {
|
|
112
|
+
// If watch section is missing, use defaults
|
|
113
|
+
if (watch === undefined || watch === null) {
|
|
114
|
+
return DEFAULT_WATCH_CONFIG;
|
|
115
|
+
}
|
|
116
|
+
if (typeof watch !== "object") {
|
|
117
|
+
throw new ConfigValidationError("watch", "watch section must be an object");
|
|
118
|
+
}
|
|
119
|
+
const w = watch;
|
|
120
|
+
// Validate or use default for debug field
|
|
121
|
+
const debug = typeof w.debug === "boolean" ? w.debug : DEFAULT_WATCH_CONFIG.debug;
|
|
122
|
+
return { debug };
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Validates the instance configuration section.
|
|
126
|
+
*/
|
|
127
|
+
function validateInstanceConfig(instance) {
|
|
128
|
+
// If instance section is missing, use defaults
|
|
129
|
+
if (instance === undefined || instance === null) {
|
|
130
|
+
return DEFAULT_INSTANCE_CONFIG;
|
|
131
|
+
}
|
|
132
|
+
if (typeof instance !== "object") {
|
|
133
|
+
throw new ConfigValidationError("instance", "instance section must be an object");
|
|
134
|
+
}
|
|
135
|
+
const inst = instance;
|
|
136
|
+
// Validate or use defaults for each field
|
|
137
|
+
const base_url_env = typeof inst.base_url_env === "string" && inst.base_url_env.trim().length > 0
|
|
138
|
+
? inst.base_url_env
|
|
139
|
+
: DEFAULT_INSTANCE_CONFIG.base_url_env;
|
|
140
|
+
const token_key = typeof inst.token_key === "string" && inst.token_key.trim().length > 0
|
|
141
|
+
? inst.token_key
|
|
142
|
+
: DEFAULT_INSTANCE_CONFIG.token_key;
|
|
143
|
+
const with_credentials = typeof inst.with_credentials === "boolean"
|
|
144
|
+
? inst.with_credentials
|
|
145
|
+
: DEFAULT_INSTANCE_CONFIG.with_credentials;
|
|
146
|
+
const timeout = typeof inst.timeout === "number" && inst.timeout > 0
|
|
147
|
+
? inst.timeout
|
|
148
|
+
: DEFAULT_INSTANCE_CONFIG.timeout;
|
|
149
|
+
return { base_url_env, token_key, with_credentials, timeout };
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Validates the loaded configuration and throws descriptive errors.
|
|
153
|
+
*/
|
|
154
|
+
function validateConfig(config) {
|
|
155
|
+
if (typeof config !== "object" || config === null) {
|
|
156
|
+
throw new ConfigValidationError("root", "Configuration must be an object");
|
|
157
|
+
}
|
|
158
|
+
const cfg = config;
|
|
159
|
+
// Validate api_endpoint
|
|
160
|
+
if (typeof cfg.api_endpoint !== "string" ||
|
|
161
|
+
cfg.api_endpoint.trim().length === 0) {
|
|
162
|
+
throw new ConfigValidationError("api_endpoint", "api_endpoint must be a non-empty string URL");
|
|
163
|
+
}
|
|
164
|
+
// Validate poll_interval_ms
|
|
165
|
+
if (typeof cfg.poll_interval_ms !== "number" || cfg.poll_interval_ms < 1000) {
|
|
166
|
+
throw new ConfigValidationError("poll_interval_ms", "poll_interval_ms must be a number >= 1000");
|
|
167
|
+
}
|
|
168
|
+
// Validate output section
|
|
169
|
+
if (typeof cfg.output !== "object" || cfg.output === null) {
|
|
170
|
+
throw new ConfigValidationError("output", "output section is required");
|
|
171
|
+
}
|
|
172
|
+
const output = cfg.output;
|
|
173
|
+
if (typeof output.folder !== "string" || output.folder.trim().length === 0) {
|
|
174
|
+
throw new ConfigValidationError("output.folder", "output.folder must be a non-empty string path");
|
|
175
|
+
}
|
|
176
|
+
// Validate spec_file if provided (optional)
|
|
177
|
+
const spec_file = typeof cfg.spec_file === "string" && cfg.spec_file.trim().length > 0
|
|
178
|
+
? cfg.spec_file
|
|
179
|
+
: undefined;
|
|
180
|
+
// Validate fetch section if provided (optional)
|
|
181
|
+
const fetchConfig = validateFetchConfig(cfg.fetch);
|
|
182
|
+
// Validate instance section (uses defaults if missing)
|
|
183
|
+
const instance = validateInstanceConfig(cfg.instance);
|
|
184
|
+
// Validate watch section (uses defaults if missing)
|
|
185
|
+
const watch = validateWatchConfig(cfg.watch);
|
|
186
|
+
return {
|
|
187
|
+
api_endpoint: cfg.api_endpoint,
|
|
188
|
+
spec_file,
|
|
189
|
+
poll_interval_ms: cfg.poll_interval_ms,
|
|
190
|
+
output: {
|
|
191
|
+
folder: output.folder,
|
|
192
|
+
},
|
|
193
|
+
fetch: fetchConfig,
|
|
194
|
+
instance,
|
|
195
|
+
watch,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Validates the fetch configuration section.
|
|
200
|
+
*/
|
|
201
|
+
function validateFetchConfig(fetch) {
|
|
202
|
+
// If fetch section is missing, return undefined
|
|
203
|
+
if (fetch === undefined || fetch === null) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (typeof fetch !== "object") {
|
|
207
|
+
throw new ConfigValidationError("fetch", "fetch section must be an object");
|
|
208
|
+
}
|
|
209
|
+
const fetchObj = fetch;
|
|
210
|
+
// Validate headers if provided
|
|
211
|
+
let headers;
|
|
212
|
+
if (fetchObj.headers !== undefined && fetchObj.headers !== null) {
|
|
213
|
+
if (typeof fetchObj.headers !== "object") {
|
|
214
|
+
throw new ConfigValidationError("fetch.headers", "fetch.headers must be an object");
|
|
215
|
+
}
|
|
216
|
+
const headersObj = fetchObj.headers;
|
|
217
|
+
headers = {};
|
|
218
|
+
for (const [key, value] of Object.entries(headersObj)) {
|
|
219
|
+
if (typeof value !== "string") {
|
|
220
|
+
throw new ConfigValidationError(`fetch.headers.${key}`, "header value must be a string");
|
|
221
|
+
}
|
|
222
|
+
headers[key] = value;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return headers ? { headers } : undefined;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Resolves the spec source based on config and flag overrides.
|
|
229
|
+
* Priority: flag > config spec_file > config api_endpoint
|
|
230
|
+
*/
|
|
231
|
+
export function resolveSpecSource(config, projectRoot, flagSpecFile) {
|
|
232
|
+
// Flag takes highest priority
|
|
233
|
+
if (flagSpecFile) {
|
|
234
|
+
const resolvedPath = path.isAbsolute(flagSpecFile)
|
|
235
|
+
? flagSpecFile
|
|
236
|
+
: path.join(projectRoot, flagSpecFile);
|
|
237
|
+
return { type: "local", path: resolvedPath };
|
|
238
|
+
}
|
|
239
|
+
// Config spec_file takes second priority
|
|
240
|
+
if (config.spec_file) {
|
|
241
|
+
const resolvedPath = path.isAbsolute(config.spec_file)
|
|
242
|
+
? config.spec_file
|
|
243
|
+
: path.join(projectRoot, config.spec_file);
|
|
244
|
+
return { type: "local", path: resolvedPath };
|
|
245
|
+
}
|
|
246
|
+
// Default to remote endpoint
|
|
247
|
+
return { type: "remote", endpoint: config.api_endpoint };
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Loads and parses the configuration file.
|
|
251
|
+
* Auto-creates with defaults if missing.
|
|
252
|
+
*/
|
|
253
|
+
export async function loadConfig(configPath) {
|
|
254
|
+
// Find project root
|
|
255
|
+
const projectRoot = await findProjectRoot();
|
|
256
|
+
const resolvedConfigPath = configPath ?? getConfigPath(projectRoot);
|
|
257
|
+
// Check if config exists
|
|
258
|
+
const exists = await configExists(resolvedConfigPath);
|
|
259
|
+
if (!exists) {
|
|
260
|
+
// Auto-create config with defaults
|
|
261
|
+
await createDefaultConfig(resolvedConfigPath);
|
|
262
|
+
return {
|
|
263
|
+
config: DEFAULT_CONFIG,
|
|
264
|
+
projectRoot,
|
|
265
|
+
configPath: resolvedConfigPath,
|
|
266
|
+
wasCreated: true,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
// Load and parse existing config
|
|
270
|
+
try {
|
|
271
|
+
const content = await readFile(resolvedConfigPath, "utf8");
|
|
272
|
+
const parsed = toml.parse(content);
|
|
273
|
+
const config = validateConfig(parsed);
|
|
274
|
+
return {
|
|
275
|
+
config,
|
|
276
|
+
projectRoot,
|
|
277
|
+
configPath: resolvedConfigPath,
|
|
278
|
+
wasCreated: false,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
if (error instanceof ConfigValidationError) {
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
if (error instanceof Error && error.message.includes("Unexpected")) {
|
|
286
|
+
throw new ConfigError(`Failed to parse api.config.toml: ${error.message}`, "Check your TOML syntax. Run 'chowbea-axios init --force' to regenerate with defaults.");
|
|
287
|
+
}
|
|
288
|
+
throw new ConfigError(`Failed to load config: ${error instanceof Error ? error.message : String(error)}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Resolves the output folder path to an absolute path.
|
|
293
|
+
*/
|
|
294
|
+
export function resolveOutputFolder(config, projectRoot) {
|
|
295
|
+
return path.isAbsolute(config.output.folder)
|
|
296
|
+
? config.output.folder
|
|
297
|
+
: path.join(projectRoot, config.output.folder);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Gets paths for all generated files based on config.
|
|
301
|
+
*/
|
|
302
|
+
export function getOutputPaths(config, projectRoot) {
|
|
303
|
+
const folder = resolveOutputFolder(config, projectRoot);
|
|
304
|
+
const internal = path.join(folder, "_internal");
|
|
305
|
+
const generated = path.join(folder, "_generated");
|
|
306
|
+
return {
|
|
307
|
+
folder,
|
|
308
|
+
internal,
|
|
309
|
+
generated,
|
|
310
|
+
// _internal/ files (always overwritten)
|
|
311
|
+
spec: path.join(internal, "openapi.json"),
|
|
312
|
+
cache: path.join(internal, ".api-cache.json"),
|
|
313
|
+
// _generated/ files (always overwritten)
|
|
314
|
+
types: path.join(generated, "api.types.ts"),
|
|
315
|
+
operations: path.join(generated, "api.operations.ts"),
|
|
316
|
+
// Root files (generated once, user-editable)
|
|
317
|
+
helpers: path.join(folder, "api.helpers.ts"),
|
|
318
|
+
instance: path.join(folder, "api.instance.ts"),
|
|
319
|
+
error: path.join(folder, "api.error.ts"),
|
|
320
|
+
client: path.join(folder, "api.client.ts"),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Ensures the output folder and subfolders exist, creating them if necessary.
|
|
325
|
+
*/
|
|
326
|
+
export async function ensureOutputFolder(outputFolder) {
|
|
327
|
+
await mkdir(outputFolder, { recursive: true });
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Ensures all output folders exist (_internal, _generated, and root).
|
|
331
|
+
*/
|
|
332
|
+
export async function ensureOutputFolders(paths) {
|
|
333
|
+
await mkdir(paths.internal, { recursive: true });
|
|
334
|
+
await mkdir(paths.generated, { recursive: true });
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAuDjE;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,KAAK,EAAE,KAAK;CACb,CAAC;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CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,KAAkB;IAC1D,MAAM,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,MAAM,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes with recovery hints for self-healing behavior.
|
|
3
|
+
* Each error type provides actionable suggestions to help users recover.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base error class with recovery hint support.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ChowbeaAxiosError extends Error {
|
|
9
|
+
readonly recoveryHint: string;
|
|
10
|
+
readonly code: string;
|
|
11
|
+
constructor(message: string, code: string, recoveryHint: string);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Thrown when api.config.toml is missing or invalid.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ConfigError extends ChowbeaAxiosError {
|
|
17
|
+
constructor(message: string, recoveryHint?: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when the config file has invalid or missing values.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ConfigValidationError extends ChowbeaAxiosError {
|
|
23
|
+
readonly field: string;
|
|
24
|
+
constructor(field: string, message: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Thrown when network operations fail (fetching OpenAPI spec).
|
|
28
|
+
*/
|
|
29
|
+
export declare class NetworkError extends ChowbeaAxiosError {
|
|
30
|
+
readonly url: string;
|
|
31
|
+
readonly statusCode?: number;
|
|
32
|
+
constructor(url: string, message: string, statusCode?: number);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Thrown when the OpenAPI spec file is missing locally.
|
|
36
|
+
*/
|
|
37
|
+
export declare class SpecNotFoundError extends ChowbeaAxiosError {
|
|
38
|
+
readonly specPath: string;
|
|
39
|
+
constructor(specPath: string);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Thrown when the OpenAPI spec is invalid or cannot be parsed.
|
|
43
|
+
*/
|
|
44
|
+
export declare class SpecParseError extends ChowbeaAxiosError {
|
|
45
|
+
readonly specPath: string;
|
|
46
|
+
constructor(specPath: string, parseError: string);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Thrown when code generation fails.
|
|
50
|
+
*/
|
|
51
|
+
export declare class GenerationError extends ChowbeaAxiosError {
|
|
52
|
+
readonly phase: string;
|
|
53
|
+
constructor(phase: string, message: string);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Thrown when output directory operations fail.
|
|
57
|
+
*/
|
|
58
|
+
export declare class OutputError extends ChowbeaAxiosError {
|
|
59
|
+
readonly outputPath: string;
|
|
60
|
+
constructor(outputPath: string, message: string);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Thrown when validation finds issues with the OpenAPI spec.
|
|
64
|
+
*/
|
|
65
|
+
export declare class ValidationError extends ChowbeaAxiosError {
|
|
66
|
+
readonly issues: string[];
|
|
67
|
+
constructor(issues: string[]);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Formats an error for display, including recovery hints.
|
|
71
|
+
*/
|
|
72
|
+
export declare function formatError(error: unknown): string;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if an error is recoverable (can retry or use fallback).
|
|
75
|
+
*/
|
|
76
|
+
export declare function isRecoverable(error: unknown): boolean;
|
|
77
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,SAAgB,YAAY,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C;gBAErB,MAAM,EAAE,MAAM,EAAE;CAS5B;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAclD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAYrD"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes with recovery hints for self-healing behavior.
|
|
3
|
+
* Each error type provides actionable suggestions to help users recover.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base error class with recovery hint support.
|
|
7
|
+
*/
|
|
8
|
+
export class ChowbeaAxiosError extends Error {
|
|
9
|
+
recoveryHint;
|
|
10
|
+
code;
|
|
11
|
+
constructor(message, code, recoveryHint) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "ChowbeaAxiosError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.recoveryHint = recoveryHint;
|
|
16
|
+
Error.captureStackTrace(this, this.constructor);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when api.config.toml is missing or invalid.
|
|
21
|
+
*/
|
|
22
|
+
export class ConfigError extends ChowbeaAxiosError {
|
|
23
|
+
constructor(message, recoveryHint) {
|
|
24
|
+
super(message, "CONFIG_ERROR", recoveryHint ??
|
|
25
|
+
"Run 'chowbea-axios init' to create a default configuration file.");
|
|
26
|
+
this.name = "ConfigError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when the config file has invalid or missing values.
|
|
31
|
+
*/
|
|
32
|
+
export class ConfigValidationError extends ChowbeaAxiosError {
|
|
33
|
+
field;
|
|
34
|
+
constructor(field, message) {
|
|
35
|
+
super(`Invalid configuration: ${message}`, "CONFIG_VALIDATION_ERROR", `Check your api.config.toml and ensure '${field}' is correctly set.`);
|
|
36
|
+
this.name = "ConfigValidationError";
|
|
37
|
+
this.field = field;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Thrown when network operations fail (fetching OpenAPI spec).
|
|
42
|
+
*/
|
|
43
|
+
export class NetworkError extends ChowbeaAxiosError {
|
|
44
|
+
url;
|
|
45
|
+
statusCode;
|
|
46
|
+
constructor(url, message, statusCode) {
|
|
47
|
+
super(message, "NETWORK_ERROR", statusCode === 404
|
|
48
|
+
? `The OpenAPI endpoint was not found. Verify the 'api_endpoint' in api.config.toml.`
|
|
49
|
+
: statusCode && statusCode >= 500
|
|
50
|
+
? "The server returned an error. Try again later or check if the API server is running."
|
|
51
|
+
: `Check your network connection and ensure the API endpoint is accessible: ${url}`);
|
|
52
|
+
this.name = "NetworkError";
|
|
53
|
+
this.url = url;
|
|
54
|
+
this.statusCode = statusCode;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Thrown when the OpenAPI spec file is missing locally.
|
|
59
|
+
*/
|
|
60
|
+
export class SpecNotFoundError extends ChowbeaAxiosError {
|
|
61
|
+
specPath;
|
|
62
|
+
constructor(specPath) {
|
|
63
|
+
super(`OpenAPI spec not found at: ${specPath}`, "SPEC_NOT_FOUND", "Run 'chowbea-axios fetch' to download the spec from the remote endpoint.");
|
|
64
|
+
this.name = "SpecNotFoundError";
|
|
65
|
+
this.specPath = specPath;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Thrown when the OpenAPI spec is invalid or cannot be parsed.
|
|
70
|
+
*/
|
|
71
|
+
export class SpecParseError extends ChowbeaAxiosError {
|
|
72
|
+
specPath;
|
|
73
|
+
constructor(specPath, parseError) {
|
|
74
|
+
super(`Failed to parse OpenAPI spec: ${parseError}`, "SPEC_PARSE_ERROR", `The OpenAPI spec at '${specPath}' may be corrupted. Try running 'chowbea-axios fetch --force' to re-download it.`);
|
|
75
|
+
this.name = "SpecParseError";
|
|
76
|
+
this.specPath = specPath;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Thrown when code generation fails.
|
|
81
|
+
*/
|
|
82
|
+
export class GenerationError extends ChowbeaAxiosError {
|
|
83
|
+
phase;
|
|
84
|
+
constructor(phase, message) {
|
|
85
|
+
super(`Generation failed during ${phase}: ${message}`, "GENERATION_ERROR", phase === "openapi-typescript"
|
|
86
|
+
? "Ensure 'openapi-typescript' is available. Run 'pnpm add -D openapi-typescript' in the CLI directory."
|
|
87
|
+
: "Check the error details above. Previous generated files have been preserved.");
|
|
88
|
+
this.name = "GenerationError";
|
|
89
|
+
this.phase = phase;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Thrown when output directory operations fail.
|
|
94
|
+
*/
|
|
95
|
+
export class OutputError extends ChowbeaAxiosError {
|
|
96
|
+
outputPath;
|
|
97
|
+
constructor(outputPath, message) {
|
|
98
|
+
super(message, "OUTPUT_ERROR", `Check permissions for the output directory: ${outputPath}`);
|
|
99
|
+
this.name = "OutputError";
|
|
100
|
+
this.outputPath = outputPath;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Thrown when validation finds issues with the OpenAPI spec.
|
|
105
|
+
*/
|
|
106
|
+
export class ValidationError extends ChowbeaAxiosError {
|
|
107
|
+
issues;
|
|
108
|
+
constructor(issues) {
|
|
109
|
+
super(`OpenAPI spec validation failed with ${issues.length} issue(s)`, "VALIDATION_ERROR", "Review the issues listed above and fix them in your API definition.");
|
|
110
|
+
this.name = "ValidationError";
|
|
111
|
+
this.issues = issues;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Formats an error for display, including recovery hints.
|
|
116
|
+
*/
|
|
117
|
+
export function formatError(error) {
|
|
118
|
+
if (error instanceof ChowbeaAxiosError) {
|
|
119
|
+
return [
|
|
120
|
+
`Error [${error.code}]: ${error.message}`,
|
|
121
|
+
"",
|
|
122
|
+
`Recovery: ${error.recoveryHint}`,
|
|
123
|
+
].join("\n");
|
|
124
|
+
}
|
|
125
|
+
if (error instanceof Error) {
|
|
126
|
+
return `Error: ${error.message}`;
|
|
127
|
+
}
|
|
128
|
+
return `Unknown error: ${String(error)}`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Checks if an error is recoverable (can retry or use fallback).
|
|
132
|
+
*/
|
|
133
|
+
export function isRecoverable(error) {
|
|
134
|
+
if (error instanceof NetworkError) {
|
|
135
|
+
// Network errors are generally recoverable via retry or cache fallback
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if (error instanceof SpecNotFoundError) {
|
|
139
|
+
// Can recover by fetching the spec
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC3B,YAAY,CAAS;IACrB,IAAI,CAAS;IAE7B,YAAY,OAAe,EAAE,IAAY,EAAE,YAAoB;QAC9D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IACjD,YAAY,OAAe,EAAE,YAAqB;QACjD,KAAK,CACJ,OAAO,EACP,cAAc,EACd,YAAY;YACX,kEAAkE,CACnE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC3B,CAAC;CACD;AAED;;GAEG;A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