api-farmer 0.0.23 → 0.0.25
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 +4 -0
- package/dist/{chunk-DJ4JEQRW.js → chunk-AHZLGQI5.js} +18 -8
- package/dist/cli.cjs +18 -8
- package/dist/cli.js +1 -1
- package/dist/{generate-5XSJIKDA.js → generate-UUTBYLAG.js} +1 -1
- package/dist/index.cjs +18 -8
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -148,6 +148,10 @@ export interface Config {
|
|
|
148
148
|
* The transformer api options, used to override the default transformation rules.
|
|
149
149
|
*/
|
|
150
150
|
transformer?: Partial<Transformer>
|
|
151
|
+
/**
|
|
152
|
+
* Certain uncountable nouns that do not change from singular to plural
|
|
153
|
+
*/
|
|
154
|
+
uncountableNouns?: string[]
|
|
151
155
|
}
|
|
152
156
|
```
|
|
153
157
|
|
|
@@ -53,7 +53,7 @@ function transformVerb({ method }) {
|
|
|
53
53
|
return pascalCase(method);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
function transformEntity({ path, method, base }) {
|
|
56
|
+
function transformEntity({ path, method, base, uncountableNouns }) {
|
|
57
57
|
path = base ? path.replace(base, "") : path;
|
|
58
58
|
const words = path.split("/").filter(Boolean);
|
|
59
59
|
return words.reduce((entity, word, index) => {
|
|
@@ -61,9 +61,11 @@ function transformEntity({ path, method, base }) {
|
|
|
61
61
|
return entity;
|
|
62
62
|
}
|
|
63
63
|
word = word.replace(/\.([a-z])/g, (_, p) => p.toUpperCase());
|
|
64
|
-
|
|
64
|
+
const isUncountableNoun = uncountableNouns.includes(word);
|
|
65
|
+
word = pascalCase(word);
|
|
66
|
+
word = isUncountableNoun ? word : pluralize.singular(word);
|
|
65
67
|
if (method === "get" && index === words.length - 1) {
|
|
66
|
-
word = pluralize.plural(word);
|
|
68
|
+
word = isUncountableNoun ? `${word}List` : pluralize.plural(word);
|
|
67
69
|
}
|
|
68
70
|
return `${entity}${word}`;
|
|
69
71
|
}, "");
|
|
@@ -128,10 +130,10 @@ function createTransformer() {
|
|
|
128
130
|
|
|
129
131
|
// src/generate.ts
|
|
130
132
|
function transformPayloads(pathItems, options) {
|
|
131
|
-
const { transformer, path, base, validateStatus } = options;
|
|
133
|
+
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
132
134
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
133
135
|
const url = transformer.url({ path, base });
|
|
134
|
-
const args = { path, base, url, method, operation };
|
|
136
|
+
const args = { path, base, url, method, uncountableNouns, operation };
|
|
135
137
|
const entity = transformer.entity(args);
|
|
136
138
|
const verb = transformer.verb(args);
|
|
137
139
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
@@ -172,7 +174,7 @@ function transformPayloads(pathItems, options) {
|
|
|
172
174
|
}, []);
|
|
173
175
|
}
|
|
174
176
|
function partitionApiModules(schema, options) {
|
|
175
|
-
const { base, transformer, validateStatus } = options;
|
|
177
|
+
const { base, transformer, uncountableNouns, validateStatus } = options;
|
|
176
178
|
const schemaPaths = schema.paths ?? {};
|
|
177
179
|
const schemaPathKeys = base ? Object.keys(schemaPaths).map((key) => key.replace(base, "")) : Object.keys(schemaPaths);
|
|
178
180
|
const keyToPaths = groupBy(schemaPathKeys, (key) => key.split("/")[1]);
|
|
@@ -180,7 +182,13 @@ function partitionApiModules(schema, options) {
|
|
|
180
182
|
const payloads = paths.reduce((payloads2, path) => {
|
|
181
183
|
const pathItems = schemaPaths[path];
|
|
182
184
|
payloads2.push(
|
|
183
|
-
...transformPayloads(pathItems, {
|
|
185
|
+
...transformPayloads(pathItems, {
|
|
186
|
+
...options,
|
|
187
|
+
path: base ? base + path : path,
|
|
188
|
+
transformer,
|
|
189
|
+
uncountableNouns,
|
|
190
|
+
validateStatus
|
|
191
|
+
})
|
|
184
192
|
);
|
|
185
193
|
return payloads2;
|
|
186
194
|
}, []);
|
|
@@ -243,7 +251,8 @@ async function generate(userOptions = {}) {
|
|
|
243
251
|
output = "./src/apis/generated",
|
|
244
252
|
typesFilename = "_types.ts",
|
|
245
253
|
validateStatus = (status) => status >= 200 && status < 300,
|
|
246
|
-
transformer = {}
|
|
254
|
+
transformer = {},
|
|
255
|
+
uncountableNouns = []
|
|
247
256
|
} = options;
|
|
248
257
|
const mergedTransformer = { ...createTransformer(), ...transformer };
|
|
249
258
|
const schema = await readSchema(input);
|
|
@@ -253,6 +262,7 @@ async function generate(userOptions = {}) {
|
|
|
253
262
|
}
|
|
254
263
|
const apiModules = partitionApiModules(schema, {
|
|
255
264
|
base,
|
|
265
|
+
uncountableNouns,
|
|
256
266
|
transformer: mergedTransformer,
|
|
257
267
|
validateStatus
|
|
258
268
|
});
|
package/dist/cli.cjs
CHANGED
|
@@ -166,7 +166,7 @@ function transformVerb({ method }) {
|
|
|
166
166
|
return (0, import_rattail2.pascalCase)(method);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
function transformEntity({ path, method, base }) {
|
|
169
|
+
function transformEntity({ path, method, base, uncountableNouns }) {
|
|
170
170
|
path = base ? path.replace(base, "") : path;
|
|
171
171
|
const words = path.split("/").filter(Boolean);
|
|
172
172
|
return words.reduce((entity, word, index) => {
|
|
@@ -174,9 +174,11 @@ function transformEntity({ path, method, base }) {
|
|
|
174
174
|
return entity;
|
|
175
175
|
}
|
|
176
176
|
word = word.replace(/\.([a-z])/g, (_, p) => p.toUpperCase());
|
|
177
|
-
|
|
177
|
+
const isUncountableNoun = uncountableNouns.includes(word);
|
|
178
|
+
word = (0, import_rattail2.pascalCase)(word);
|
|
179
|
+
word = isUncountableNoun ? word : import_pluralize.default.singular(word);
|
|
178
180
|
if (method === "get" && index === words.length - 1) {
|
|
179
|
-
word = import_pluralize.default.plural(word);
|
|
181
|
+
word = isUncountableNoun ? `${word}List` : import_pluralize.default.plural(word);
|
|
180
182
|
}
|
|
181
183
|
return `${entity}${word}`;
|
|
182
184
|
}, "");
|
|
@@ -258,10 +260,10 @@ __export(generate_exports, {
|
|
|
258
260
|
transformPayloads: () => transformPayloads
|
|
259
261
|
});
|
|
260
262
|
function transformPayloads(pathItems, options) {
|
|
261
|
-
const { transformer, path, base, validateStatus } = options;
|
|
263
|
+
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
262
264
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
263
265
|
const url = transformer.url({ path, base });
|
|
264
|
-
const args = { path, base, url, method, operation };
|
|
266
|
+
const args = { path, base, url, method, uncountableNouns, operation };
|
|
265
267
|
const entity = transformer.entity(args);
|
|
266
268
|
const verb = transformer.verb(args);
|
|
267
269
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
@@ -302,7 +304,7 @@ function transformPayloads(pathItems, options) {
|
|
|
302
304
|
}, []);
|
|
303
305
|
}
|
|
304
306
|
function partitionApiModules(schema, options) {
|
|
305
|
-
const { base, transformer, validateStatus } = options;
|
|
307
|
+
const { base, transformer, uncountableNouns, validateStatus } = options;
|
|
306
308
|
const schemaPaths = schema.paths ?? {};
|
|
307
309
|
const schemaPathKeys = base ? Object.keys(schemaPaths).map((key) => key.replace(base, "")) : Object.keys(schemaPaths);
|
|
308
310
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
@@ -310,7 +312,13 @@ function partitionApiModules(schema, options) {
|
|
|
310
312
|
const payloads = paths.reduce((payloads2, path) => {
|
|
311
313
|
const pathItems = schemaPaths[path];
|
|
312
314
|
payloads2.push(
|
|
313
|
-
...transformPayloads(pathItems, {
|
|
315
|
+
...transformPayloads(pathItems, {
|
|
316
|
+
...options,
|
|
317
|
+
path: base ? base + path : path,
|
|
318
|
+
transformer,
|
|
319
|
+
uncountableNouns,
|
|
320
|
+
validateStatus
|
|
321
|
+
})
|
|
314
322
|
);
|
|
315
323
|
return payloads2;
|
|
316
324
|
}, []);
|
|
@@ -373,7 +381,8 @@ async function generate(userOptions = {}) {
|
|
|
373
381
|
output = "./src/apis/generated",
|
|
374
382
|
typesFilename = "_types.ts",
|
|
375
383
|
validateStatus = (status) => status >= 200 && status < 300,
|
|
376
|
-
transformer = {}
|
|
384
|
+
transformer = {},
|
|
385
|
+
uncountableNouns = []
|
|
377
386
|
} = options;
|
|
378
387
|
const mergedTransformer = { ...createTransformer(), ...transformer };
|
|
379
388
|
const schema = await readSchema(input);
|
|
@@ -383,6 +392,7 @@ async function generate(userOptions = {}) {
|
|
|
383
392
|
}
|
|
384
393
|
const apiModules = partitionApiModules(schema, {
|
|
385
394
|
base,
|
|
395
|
+
uncountableNouns,
|
|
386
396
|
transformer: mergedTransformer,
|
|
387
397
|
validateStatus
|
|
388
398
|
});
|
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-UUTBYLAG.js");
|
|
12
12
|
return generate();
|
|
13
13
|
});
|
|
14
14
|
program.parse();
|
package/dist/index.cjs
CHANGED
|
@@ -85,7 +85,7 @@ function transformVerb({ method }) {
|
|
|
85
85
|
return (0, import_rattail.pascalCase)(method);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
function transformEntity({ path, method, base }) {
|
|
88
|
+
function transformEntity({ path, method, base, uncountableNouns }) {
|
|
89
89
|
path = base ? path.replace(base, "") : path;
|
|
90
90
|
const words = path.split("/").filter(Boolean);
|
|
91
91
|
return words.reduce((entity, word, index) => {
|
|
@@ -93,9 +93,11 @@ function transformEntity({ path, method, base }) {
|
|
|
93
93
|
return entity;
|
|
94
94
|
}
|
|
95
95
|
word = word.replace(/\.([a-z])/g, (_, p) => p.toUpperCase());
|
|
96
|
-
|
|
96
|
+
const isUncountableNoun = uncountableNouns.includes(word);
|
|
97
|
+
word = (0, import_rattail.pascalCase)(word);
|
|
98
|
+
word = isUncountableNoun ? word : import_pluralize.default.singular(word);
|
|
97
99
|
if (method === "get" && index === words.length - 1) {
|
|
98
|
-
word = import_pluralize.default.plural(word);
|
|
100
|
+
word = isUncountableNoun ? `${word}List` : import_pluralize.default.plural(word);
|
|
99
101
|
}
|
|
100
102
|
return `${entity}${word}`;
|
|
101
103
|
}, "");
|
|
@@ -293,10 +295,10 @@ function getResponseMetadataItems(operation, validateStatus) {
|
|
|
293
295
|
|
|
294
296
|
// src/generate.ts
|
|
295
297
|
function transformPayloads(pathItems, options) {
|
|
296
|
-
const { transformer, path, base, validateStatus } = options;
|
|
298
|
+
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
297
299
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
298
300
|
const url = transformer.url({ path, base });
|
|
299
|
-
const args = { path, base, url, method, operation };
|
|
301
|
+
const args = { path, base, url, method, uncountableNouns, operation };
|
|
300
302
|
const entity = transformer.entity(args);
|
|
301
303
|
const verb = transformer.verb(args);
|
|
302
304
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
@@ -337,7 +339,7 @@ function transformPayloads(pathItems, options) {
|
|
|
337
339
|
}, []);
|
|
338
340
|
}
|
|
339
341
|
function partitionApiModules(schema, options) {
|
|
340
|
-
const { base, transformer, validateStatus } = options;
|
|
342
|
+
const { base, transformer, uncountableNouns, validateStatus } = options;
|
|
341
343
|
const schemaPaths = schema.paths ?? {};
|
|
342
344
|
const schemaPathKeys = base ? Object.keys(schemaPaths).map((key) => key.replace(base, "")) : Object.keys(schemaPaths);
|
|
343
345
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
@@ -345,7 +347,13 @@ function partitionApiModules(schema, options) {
|
|
|
345
347
|
const payloads = paths.reduce((payloads2, path) => {
|
|
346
348
|
const pathItems = schemaPaths[path];
|
|
347
349
|
payloads2.push(
|
|
348
|
-
...transformPayloads(pathItems, {
|
|
350
|
+
...transformPayloads(pathItems, {
|
|
351
|
+
...options,
|
|
352
|
+
path: base ? base + path : path,
|
|
353
|
+
transformer,
|
|
354
|
+
uncountableNouns,
|
|
355
|
+
validateStatus
|
|
356
|
+
})
|
|
349
357
|
);
|
|
350
358
|
return payloads2;
|
|
351
359
|
}, []);
|
|
@@ -408,7 +416,8 @@ async function generate(userOptions = {}) {
|
|
|
408
416
|
output = "./src/apis/generated",
|
|
409
417
|
typesFilename = "_types.ts",
|
|
410
418
|
validateStatus = (status) => status >= 200 && status < 300,
|
|
411
|
-
transformer = {}
|
|
419
|
+
transformer = {},
|
|
420
|
+
uncountableNouns = []
|
|
412
421
|
} = options;
|
|
413
422
|
const mergedTransformer = { ...createTransformer(), ...transformer };
|
|
414
423
|
const schema = await readSchema(input);
|
|
@@ -418,6 +427,7 @@ async function generate(userOptions = {}) {
|
|
|
418
427
|
}
|
|
419
428
|
const apiModules = partitionApiModules(schema, {
|
|
420
429
|
base,
|
|
430
|
+
uncountableNouns,
|
|
421
431
|
transformer: mergedTransformer,
|
|
422
432
|
validateStatus
|
|
423
433
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -58,6 +58,7 @@ type TransformerBaseArgs = {
|
|
|
58
58
|
url: string;
|
|
59
59
|
method: string;
|
|
60
60
|
operation: OperationObject;
|
|
61
|
+
uncountableNouns: string[];
|
|
61
62
|
};
|
|
62
63
|
declare function transformModuleName({ name }: {
|
|
63
64
|
name: string;
|
|
@@ -69,7 +70,7 @@ declare function transformUrl({ path, base }: {
|
|
|
69
70
|
declare function transformVerb({ method }: {
|
|
70
71
|
method: string;
|
|
71
72
|
}): string;
|
|
72
|
-
declare function transformEntity({ path, method, base }: TransformerBaseArgs): string;
|
|
73
|
+
declare function transformEntity({ path, method, base, uncountableNouns }: TransformerBaseArgs): string;
|
|
73
74
|
declare function transformFn({ verb, entity }: {
|
|
74
75
|
verb: string;
|
|
75
76
|
entity: string;
|
|
@@ -267,16 +268,22 @@ interface GenerateOptions {
|
|
|
267
268
|
* The transformer api options, used to override the default transformation rules.
|
|
268
269
|
*/
|
|
269
270
|
transformer?: Partial<Transformer>;
|
|
271
|
+
/**
|
|
272
|
+
* Certain uncountable nouns that do not change from singular to plural
|
|
273
|
+
*/
|
|
274
|
+
uncountableNouns?: string[];
|
|
270
275
|
}
|
|
271
276
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
272
277
|
path: string;
|
|
273
278
|
transformer: Transformer;
|
|
274
279
|
base: string | undefined;
|
|
280
|
+
uncountableNouns: string[];
|
|
275
281
|
validateStatus: (status: number) => boolean;
|
|
276
282
|
}): ApiModulePayload[];
|
|
277
283
|
declare function partitionApiModules(schema: OpenAPI3, options: {
|
|
278
284
|
transformer: Transformer;
|
|
279
285
|
base: string | undefined;
|
|
286
|
+
uncountableNouns: string[];
|
|
280
287
|
validateStatus: (status: number) => boolean;
|
|
281
288
|
}): ApiModule[];
|
|
282
289
|
declare function renderApiModules(apiModules: ApiModule[], options: {
|
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ type TransformerBaseArgs = {
|
|
|
58
58
|
url: string;
|
|
59
59
|
method: string;
|
|
60
60
|
operation: OperationObject;
|
|
61
|
+
uncountableNouns: string[];
|
|
61
62
|
};
|
|
62
63
|
declare function transformModuleName({ name }: {
|
|
63
64
|
name: string;
|
|
@@ -69,7 +70,7 @@ declare function transformUrl({ path, base }: {
|
|
|
69
70
|
declare function transformVerb({ method }: {
|
|
70
71
|
method: string;
|
|
71
72
|
}): string;
|
|
72
|
-
declare function transformEntity({ path, method, base }: TransformerBaseArgs): string;
|
|
73
|
+
declare function transformEntity({ path, method, base, uncountableNouns }: TransformerBaseArgs): string;
|
|
73
74
|
declare function transformFn({ verb, entity }: {
|
|
74
75
|
verb: string;
|
|
75
76
|
entity: string;
|
|
@@ -267,16 +268,22 @@ interface GenerateOptions {
|
|
|
267
268
|
* The transformer api options, used to override the default transformation rules.
|
|
268
269
|
*/
|
|
269
270
|
transformer?: Partial<Transformer>;
|
|
271
|
+
/**
|
|
272
|
+
* Certain uncountable nouns that do not change from singular to plural
|
|
273
|
+
*/
|
|
274
|
+
uncountableNouns?: string[];
|
|
270
275
|
}
|
|
271
276
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
272
277
|
path: string;
|
|
273
278
|
transformer: Transformer;
|
|
274
279
|
base: string | undefined;
|
|
280
|
+
uncountableNouns: string[];
|
|
275
281
|
validateStatus: (status: number) => boolean;
|
|
276
282
|
}): ApiModulePayload[];
|
|
277
283
|
declare function partitionApiModules(schema: OpenAPI3, options: {
|
|
278
284
|
transformer: Transformer;
|
|
279
285
|
base: string | undefined;
|
|
286
|
+
uncountableNouns: string[];
|
|
280
287
|
validateStatus: (status: number) => boolean;
|
|
281
288
|
}): ApiModule[];
|
|
282
289
|
declare function renderApiModules(apiModules: ApiModule[], options: {
|
package/dist/index.js
CHANGED