api-farmer 0.1.1 → 0.1.3
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/README.md +5 -0
- package/dist/{chunk-P3SVS555.js → chunk-RIXLRGPZ.js} +17 -6
- package/dist/cli.cjs +17 -6
- package/dist/cli.js +1 -1
- package/dist/{generate-WIU5E7EL.js → generate-4J5VPBTS.js} +1 -1
- package/dist/index.cjs +17 -6
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -153,6 +153,11 @@ export interface Config {
|
|
|
153
153
|
* Certain uncountable nouns that do not change from singular to plural
|
|
154
154
|
*/
|
|
155
155
|
uncountableNouns?: string[]
|
|
156
|
+
/**
|
|
157
|
+
* Whether to clean the output directory before generating.
|
|
158
|
+
* @default false
|
|
159
|
+
*/
|
|
160
|
+
clean?: boolean
|
|
156
161
|
/**
|
|
157
162
|
* The options for the openapiTS library.
|
|
158
163
|
* @see https://openapi-ts.dev/node
|
|
@@ -146,8 +146,8 @@ function createTransformer() {
|
|
|
146
146
|
|
|
147
147
|
// src/generate.ts
|
|
148
148
|
function transformPayloads(pathItems, options) {
|
|
149
|
-
const { transformer, path, fullPath, base, uncountableNouns, validateStatus } = options;
|
|
150
|
-
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
149
|
+
const { transformer, path, fullPath, base, uncountableNouns, validateStatus, excludeDeprecated } = options;
|
|
150
|
+
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).filter(([, operation]) => !(excludeDeprecated && operation.deprecated)).reduce((payloads, [method, operation]) => {
|
|
151
151
|
const url = transformer.url({ path, base, fullPath });
|
|
152
152
|
const args = { path, base, fullPath, url, method, uncountableNouns, operation };
|
|
153
153
|
const entity = transformer.entity(args);
|
|
@@ -192,7 +192,7 @@ function transformPayloads(pathItems, options) {
|
|
|
192
192
|
}, []);
|
|
193
193
|
}
|
|
194
194
|
function partitionApiModules(schema, options) {
|
|
195
|
-
const { base, transformer, uncountableNouns, validateStatus } = options;
|
|
195
|
+
const { base, transformer, uncountableNouns, validateStatus, excludeDeprecated } = options;
|
|
196
196
|
const schemaPaths = schema.paths ?? {};
|
|
197
197
|
const schemaPathKeys = base ? Object.keys(schemaPaths).map((key) => key.replace(base, "")) : Object.keys(schemaPaths);
|
|
198
198
|
const keyToPaths = groupBy(schemaPathKeys, (key) => key.split("/")[1]);
|
|
@@ -207,7 +207,8 @@ function partitionApiModules(schema, options) {
|
|
|
207
207
|
fullPath,
|
|
208
208
|
transformer,
|
|
209
209
|
uncountableNouns,
|
|
210
|
-
validateStatus
|
|
210
|
+
validateStatus,
|
|
211
|
+
excludeDeprecated
|
|
211
212
|
})
|
|
212
213
|
);
|
|
213
214
|
return payloads2;
|
|
@@ -280,14 +281,23 @@ async function generate(userOptions = {}) {
|
|
|
280
281
|
input = "./schema.json",
|
|
281
282
|
output = "./src/apis/generated",
|
|
282
283
|
typesFilename = "_types.ts",
|
|
284
|
+
clean = false,
|
|
283
285
|
validateStatus = (status) => status >= 200 && status < 300,
|
|
284
286
|
transformer = {},
|
|
285
287
|
uncountableNouns = [],
|
|
286
|
-
openapiTsOptions = {}
|
|
288
|
+
openapiTsOptions = {},
|
|
289
|
+
excludeDeprecated = false
|
|
287
290
|
} = options;
|
|
288
291
|
const mergedTransformer = { ...createTransformer(), ...transformer };
|
|
289
292
|
const schema = await readSchema(input);
|
|
293
|
+
if (clean) {
|
|
294
|
+
fse.removeSync(resolve(CWD, output));
|
|
295
|
+
logger.info(`Cleaned output directory: ${resolve(CWD, output)}`);
|
|
296
|
+
}
|
|
290
297
|
logger.info("Generating API modules...");
|
|
298
|
+
if (openapiTsOptions.excludeDeprecated === void 0) {
|
|
299
|
+
openapiTsOptions.excludeDeprecated = excludeDeprecated;
|
|
300
|
+
}
|
|
291
301
|
if (ts2) {
|
|
292
302
|
await generateTypes(schema, output, typesFilename, openapiTsOptions);
|
|
293
303
|
}
|
|
@@ -295,7 +305,8 @@ async function generate(userOptions = {}) {
|
|
|
295
305
|
base,
|
|
296
306
|
uncountableNouns,
|
|
297
307
|
transformer: mergedTransformer,
|
|
298
|
-
validateStatus
|
|
308
|
+
validateStatus,
|
|
309
|
+
excludeDeprecated
|
|
299
310
|
});
|
|
300
311
|
await renderApiModules(apiModules, { output, typesFilename, ts: ts2, typesOnly, overrides, preset });
|
|
301
312
|
logger.success("Done");
|
package/dist/cli.cjs
CHANGED
|
@@ -273,8 +273,8 @@ __export(generate_exports, {
|
|
|
273
273
|
transformPayloads: () => transformPayloads
|
|
274
274
|
});
|
|
275
275
|
function transformPayloads(pathItems, options) {
|
|
276
|
-
const { transformer, path, fullPath, base, uncountableNouns, validateStatus } = options;
|
|
277
|
-
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
276
|
+
const { transformer, path, fullPath, base, uncountableNouns, validateStatus, excludeDeprecated } = options;
|
|
277
|
+
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).filter(([, operation]) => !(excludeDeprecated && operation.deprecated)).reduce((payloads, [method, operation]) => {
|
|
278
278
|
const url = transformer.url({ path, base, fullPath });
|
|
279
279
|
const args = { path, base, fullPath, url, method, uncountableNouns, operation };
|
|
280
280
|
const entity = transformer.entity(args);
|
|
@@ -319,7 +319,7 @@ function transformPayloads(pathItems, options) {
|
|
|
319
319
|
}, []);
|
|
320
320
|
}
|
|
321
321
|
function partitionApiModules(schema, options) {
|
|
322
|
-
const { base, transformer, uncountableNouns, validateStatus } = options;
|
|
322
|
+
const { base, transformer, uncountableNouns, validateStatus, excludeDeprecated } = options;
|
|
323
323
|
const schemaPaths = schema.paths ?? {};
|
|
324
324
|
const schemaPathKeys = base ? Object.keys(schemaPaths).map((key) => key.replace(base, "")) : Object.keys(schemaPaths);
|
|
325
325
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
@@ -334,7 +334,8 @@ function partitionApiModules(schema, options) {
|
|
|
334
334
|
fullPath,
|
|
335
335
|
transformer,
|
|
336
336
|
uncountableNouns,
|
|
337
|
-
validateStatus
|
|
337
|
+
validateStatus,
|
|
338
|
+
excludeDeprecated
|
|
338
339
|
})
|
|
339
340
|
);
|
|
340
341
|
return payloads2;
|
|
@@ -407,14 +408,23 @@ async function generate(userOptions = {}) {
|
|
|
407
408
|
input = "./schema.json",
|
|
408
409
|
output = "./src/apis/generated",
|
|
409
410
|
typesFilename = "_types.ts",
|
|
411
|
+
clean = false,
|
|
410
412
|
validateStatus = (status) => status >= 200 && status < 300,
|
|
411
413
|
transformer = {},
|
|
412
414
|
uncountableNouns = [],
|
|
413
|
-
openapiTsOptions = {}
|
|
415
|
+
openapiTsOptions = {},
|
|
416
|
+
excludeDeprecated = false
|
|
414
417
|
} = options;
|
|
415
418
|
const mergedTransformer = { ...createTransformer(), ...transformer };
|
|
416
419
|
const schema = await readSchema(input);
|
|
420
|
+
if (clean) {
|
|
421
|
+
import_fs_extra2.default.removeSync((0, import_path3.resolve)(CWD, output));
|
|
422
|
+
import_rslog2.logger.info(`Cleaned output directory: ${(0, import_path3.resolve)(CWD, output)}`);
|
|
423
|
+
}
|
|
417
424
|
import_rslog2.logger.info("Generating API modules...");
|
|
425
|
+
if (openapiTsOptions.excludeDeprecated === void 0) {
|
|
426
|
+
openapiTsOptions.excludeDeprecated = excludeDeprecated;
|
|
427
|
+
}
|
|
418
428
|
if (ts2) {
|
|
419
429
|
await generateTypes(schema, output, typesFilename, openapiTsOptions);
|
|
420
430
|
}
|
|
@@ -422,7 +432,8 @@ async function generate(userOptions = {}) {
|
|
|
422
432
|
base,
|
|
423
433
|
uncountableNouns,
|
|
424
434
|
transformer: mergedTransformer,
|
|
425
|
-
validateStatus
|
|
435
|
+
validateStatus,
|
|
436
|
+
excludeDeprecated
|
|
426
437
|
});
|
|
427
438
|
await renderApiModules(apiModules, { output, typesFilename, ts: ts2, typesOnly, overrides, preset });
|
|
428
439
|
import_rslog2.logger.success("Done");
|
package/dist/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ import { Command } from "commander";
|
|
|
8
8
|
var program = new Command();
|
|
9
9
|
program.version(getCliVersion());
|
|
10
10
|
program.action(async () => {
|
|
11
|
-
const { generate } = await import("./generate-
|
|
11
|
+
const { generate } = await import("./generate-4J5VPBTS.js");
|
|
12
12
|
return generate();
|
|
13
13
|
});
|
|
14
14
|
program.parse();
|
package/dist/index.cjs
CHANGED
|
@@ -314,8 +314,8 @@ function getResponseMetadataItems(operation, validateStatus) {
|
|
|
314
314
|
|
|
315
315
|
// src/generate.ts
|
|
316
316
|
function transformPayloads(pathItems, options) {
|
|
317
|
-
const { transformer, path, fullPath, base, uncountableNouns, validateStatus } = options;
|
|
318
|
-
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
317
|
+
const { transformer, path, fullPath, base, uncountableNouns, validateStatus, excludeDeprecated } = options;
|
|
318
|
+
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).filter(([, operation]) => !(excludeDeprecated && operation.deprecated)).reduce((payloads, [method, operation]) => {
|
|
319
319
|
const url = transformer.url({ path, base, fullPath });
|
|
320
320
|
const args = { path, base, fullPath, url, method, uncountableNouns, operation };
|
|
321
321
|
const entity = transformer.entity(args);
|
|
@@ -360,7 +360,7 @@ function transformPayloads(pathItems, options) {
|
|
|
360
360
|
}, []);
|
|
361
361
|
}
|
|
362
362
|
function partitionApiModules(schema, options) {
|
|
363
|
-
const { base, transformer, uncountableNouns, validateStatus } = options;
|
|
363
|
+
const { base, transformer, uncountableNouns, validateStatus, excludeDeprecated } = options;
|
|
364
364
|
const schemaPaths = schema.paths ?? {};
|
|
365
365
|
const schemaPathKeys = base ? Object.keys(schemaPaths).map((key) => key.replace(base, "")) : Object.keys(schemaPaths);
|
|
366
366
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
@@ -375,7 +375,8 @@ function partitionApiModules(schema, options) {
|
|
|
375
375
|
fullPath,
|
|
376
376
|
transformer,
|
|
377
377
|
uncountableNouns,
|
|
378
|
-
validateStatus
|
|
378
|
+
validateStatus,
|
|
379
|
+
excludeDeprecated
|
|
379
380
|
})
|
|
380
381
|
);
|
|
381
382
|
return payloads2;
|
|
@@ -448,14 +449,23 @@ async function generate(userOptions = {}) {
|
|
|
448
449
|
input = "./schema.json",
|
|
449
450
|
output = "./src/apis/generated",
|
|
450
451
|
typesFilename = "_types.ts",
|
|
452
|
+
clean = false,
|
|
451
453
|
validateStatus = (status) => status >= 200 && status < 300,
|
|
452
454
|
transformer = {},
|
|
453
455
|
uncountableNouns = [],
|
|
454
|
-
openapiTsOptions = {}
|
|
456
|
+
openapiTsOptions = {},
|
|
457
|
+
excludeDeprecated = false
|
|
455
458
|
} = options;
|
|
456
459
|
const mergedTransformer = { ...createTransformer(), ...transformer };
|
|
457
460
|
const schema = await readSchema(input);
|
|
461
|
+
if (clean) {
|
|
462
|
+
import_fs_extra2.default.removeSync((0, import_path3.resolve)(CWD, output));
|
|
463
|
+
import_rslog2.logger.info(`Cleaned output directory: ${(0, import_path3.resolve)(CWD, output)}`);
|
|
464
|
+
}
|
|
458
465
|
import_rslog2.logger.info("Generating API modules...");
|
|
466
|
+
if (openapiTsOptions.excludeDeprecated === void 0) {
|
|
467
|
+
openapiTsOptions.excludeDeprecated = excludeDeprecated;
|
|
468
|
+
}
|
|
459
469
|
if (ts2) {
|
|
460
470
|
await generateTypes(schema, output, typesFilename, openapiTsOptions);
|
|
461
471
|
}
|
|
@@ -463,7 +473,8 @@ async function generate(userOptions = {}) {
|
|
|
463
473
|
base,
|
|
464
474
|
uncountableNouns,
|
|
465
475
|
transformer: mergedTransformer,
|
|
466
|
-
validateStatus
|
|
476
|
+
validateStatus,
|
|
477
|
+
excludeDeprecated
|
|
467
478
|
});
|
|
468
479
|
await renderApiModules(apiModules, { output, typesFilename, ts: ts2, typesOnly, overrides, preset });
|
|
469
480
|
import_rslog2.logger.success("Done");
|
package/dist/index.d.cts
CHANGED
|
@@ -285,10 +285,20 @@ interface GenerateOptions {
|
|
|
285
285
|
* Certain uncountable nouns that do not change from singular to plural
|
|
286
286
|
*/
|
|
287
287
|
uncountableNouns?: string[];
|
|
288
|
+
/**
|
|
289
|
+
* Whether to clean the output directory before generating.
|
|
290
|
+
* @default false
|
|
291
|
+
*/
|
|
292
|
+
clean?: boolean;
|
|
288
293
|
/**
|
|
289
294
|
* A function to transform the generated types AST before printing to string.
|
|
290
295
|
*/
|
|
291
296
|
openapiTsOptions?: OpenAPITSOptions;
|
|
297
|
+
/**
|
|
298
|
+
* Whether to exclude deprecated API endpoints.
|
|
299
|
+
* @default false
|
|
300
|
+
*/
|
|
301
|
+
excludeDeprecated?: boolean;
|
|
292
302
|
}
|
|
293
303
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
294
304
|
path: string;
|
|
@@ -297,12 +307,14 @@ declare function transformPayloads(pathItems: Record<string, OperationObject>, o
|
|
|
297
307
|
transformer: Transformer;
|
|
298
308
|
uncountableNouns: string[];
|
|
299
309
|
validateStatus: (status: number) => boolean;
|
|
310
|
+
excludeDeprecated?: boolean;
|
|
300
311
|
}): ApiModulePayload[];
|
|
301
312
|
declare function partitionApiModules(schema: OpenAPI3, options: {
|
|
302
313
|
transformer: Transformer;
|
|
303
314
|
base: string | undefined;
|
|
304
315
|
uncountableNouns: string[];
|
|
305
316
|
validateStatus: (status: number) => boolean;
|
|
317
|
+
excludeDeprecated?: boolean;
|
|
306
318
|
}): ApiModule[];
|
|
307
319
|
declare function renderApiModules(apiModules: ApiModule[], options: {
|
|
308
320
|
output: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -285,10 +285,20 @@ interface GenerateOptions {
|
|
|
285
285
|
* Certain uncountable nouns that do not change from singular to plural
|
|
286
286
|
*/
|
|
287
287
|
uncountableNouns?: string[];
|
|
288
|
+
/**
|
|
289
|
+
* Whether to clean the output directory before generating.
|
|
290
|
+
* @default false
|
|
291
|
+
*/
|
|
292
|
+
clean?: boolean;
|
|
288
293
|
/**
|
|
289
294
|
* A function to transform the generated types AST before printing to string.
|
|
290
295
|
*/
|
|
291
296
|
openapiTsOptions?: OpenAPITSOptions;
|
|
297
|
+
/**
|
|
298
|
+
* Whether to exclude deprecated API endpoints.
|
|
299
|
+
* @default false
|
|
300
|
+
*/
|
|
301
|
+
excludeDeprecated?: boolean;
|
|
292
302
|
}
|
|
293
303
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
294
304
|
path: string;
|
|
@@ -297,12 +307,14 @@ declare function transformPayloads(pathItems: Record<string, OperationObject>, o
|
|
|
297
307
|
transformer: Transformer;
|
|
298
308
|
uncountableNouns: string[];
|
|
299
309
|
validateStatus: (status: number) => boolean;
|
|
310
|
+
excludeDeprecated?: boolean;
|
|
300
311
|
}): ApiModulePayload[];
|
|
301
312
|
declare function partitionApiModules(schema: OpenAPI3, options: {
|
|
302
313
|
transformer: Transformer;
|
|
303
314
|
base: string | undefined;
|
|
304
315
|
uncountableNouns: string[];
|
|
305
316
|
validateStatus: (status: number) => boolean;
|
|
317
|
+
excludeDeprecated?: boolean;
|
|
306
318
|
}): ApiModule[];
|
|
307
319
|
declare function renderApiModules(apiModules: ApiModule[], options: {
|
|
308
320
|
output: string;
|
package/dist/index.js
CHANGED