api-farmer 0.0.26 → 0.0.28
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/dist/{chunk-POFI6LCY.js → chunk-XM2F7GOE.js} +15 -12
- package/dist/cli.cjs +15 -12
- package/dist/cli.js +1 -1
- package/dist/{generate-KSN6M7JH.js → generate-NRJ4NQ4O.js} +1 -1
- package/dist/index.cjs +15 -12
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -39,8 +39,8 @@ import { camelize, pascalCase } from "rattail";
|
|
|
39
39
|
function transformModuleName({ name }) {
|
|
40
40
|
return camelize(name);
|
|
41
41
|
}
|
|
42
|
-
function transformUrl({ path
|
|
43
|
-
return
|
|
42
|
+
function transformUrl({ path }) {
|
|
43
|
+
return path.replace(/{/g, ":").replace(/}/g, "");
|
|
44
44
|
}
|
|
45
45
|
function transformVerb({ method }) {
|
|
46
46
|
switch (method) {
|
|
@@ -52,8 +52,7 @@ function transformVerb({ method }) {
|
|
|
52
52
|
return pascalCase(method);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
function transformEntity({ path, method,
|
|
56
|
-
path = base ? path.replace(base, "") : path;
|
|
55
|
+
function transformEntity({ path, method, uncountableNouns }) {
|
|
57
56
|
const words = path.split("/").filter(Boolean);
|
|
58
57
|
return words.reduce((entity, word, index) => {
|
|
59
58
|
if (word.includes("{")) {
|
|
@@ -75,8 +74,8 @@ function transformFn({ verb, entity }) {
|
|
|
75
74
|
function transformType({ verb, entity }) {
|
|
76
75
|
return `Api${verb}${entity}`;
|
|
77
76
|
}
|
|
78
|
-
function transformTypeValue({
|
|
79
|
-
return `paths['${
|
|
77
|
+
function transformTypeValue({ fullPath, method }) {
|
|
78
|
+
return `paths['${fullPath}']['${method}']`;
|
|
80
79
|
}
|
|
81
80
|
function transformTypeQuery({ type }) {
|
|
82
81
|
return `${type}Query`;
|
|
@@ -129,10 +128,10 @@ function createTransformer() {
|
|
|
129
128
|
|
|
130
129
|
// src/generate.ts
|
|
131
130
|
function transformPayloads(pathItems, options) {
|
|
132
|
-
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
131
|
+
const { transformer, path, fullPath, base, uncountableNouns, validateStatus } = options;
|
|
133
132
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
134
|
-
const url = transformer.url({ path, base });
|
|
135
|
-
const args = { path, base, url, method, uncountableNouns, operation };
|
|
133
|
+
const url = transformer.url({ path, base, fullPath });
|
|
134
|
+
const args = { path, base, fullPath, url, method, uncountableNouns, operation };
|
|
136
135
|
const entity = transformer.entity(args);
|
|
137
136
|
const verb = transformer.verb(args);
|
|
138
137
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
@@ -179,11 +178,13 @@ function partitionApiModules(schema, options) {
|
|
|
179
178
|
const keyToPaths = groupBy(schemaPathKeys, (key) => key.split("/")[1]);
|
|
180
179
|
const apiModules = Object.entries(keyToPaths).reduce((apiModules2, [name, paths]) => {
|
|
181
180
|
const payloads = paths.reduce((payloads2, path) => {
|
|
182
|
-
const
|
|
181
|
+
const fullPath = base ? base + path : path;
|
|
182
|
+
const pathItems = schemaPaths[fullPath];
|
|
183
183
|
payloads2.push(
|
|
184
184
|
...transformPayloads(pathItems, {
|
|
185
185
|
...options,
|
|
186
|
-
path
|
|
186
|
+
path,
|
|
187
|
+
fullPath,
|
|
187
188
|
transformer,
|
|
188
189
|
uncountableNouns,
|
|
189
190
|
validateStatus
|
|
@@ -231,7 +232,9 @@ function renderApiModules(apiModules, options) {
|
|
|
231
232
|
);
|
|
232
233
|
}
|
|
233
234
|
async function generateTypes(schema, output, typesFilename) {
|
|
234
|
-
const ast = await openapiTS(schema
|
|
235
|
+
const ast = await openapiTS(schema, {
|
|
236
|
+
defaultNonNullable: false
|
|
237
|
+
});
|
|
235
238
|
const contents = astToString(ast);
|
|
236
239
|
const typesFilepath = resolve(CWD, output, typesFilename);
|
|
237
240
|
fse.outputFileSync(typesFilepath, contents);
|
package/dist/cli.cjs
CHANGED
|
@@ -150,8 +150,8 @@ var init_config = __esm({
|
|
|
150
150
|
function transformModuleName({ name }) {
|
|
151
151
|
return (0, import_rattail2.camelize)(name);
|
|
152
152
|
}
|
|
153
|
-
function transformUrl({ path
|
|
154
|
-
return
|
|
153
|
+
function transformUrl({ path }) {
|
|
154
|
+
return path.replace(/{/g, ":").replace(/}/g, "");
|
|
155
155
|
}
|
|
156
156
|
function transformVerb({ method }) {
|
|
157
157
|
switch (method) {
|
|
@@ -163,8 +163,7 @@ function transformVerb({ method }) {
|
|
|
163
163
|
return (0, import_rattail2.pascalCase)(method);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
function transformEntity({ path, method,
|
|
167
|
-
path = base ? path.replace(base, "") : path;
|
|
166
|
+
function transformEntity({ path, method, uncountableNouns }) {
|
|
168
167
|
const words = path.split("/").filter(Boolean);
|
|
169
168
|
return words.reduce((entity, word, index) => {
|
|
170
169
|
if (word.includes("{")) {
|
|
@@ -186,8 +185,8 @@ function transformFn({ verb, entity }) {
|
|
|
186
185
|
function transformType({ verb, entity }) {
|
|
187
186
|
return `Api${verb}${entity}`;
|
|
188
187
|
}
|
|
189
|
-
function transformTypeValue({
|
|
190
|
-
return `paths['${
|
|
188
|
+
function transformTypeValue({ fullPath, method }) {
|
|
189
|
+
return `paths['${fullPath}']['${method}']`;
|
|
191
190
|
}
|
|
192
191
|
function transformTypeQuery({ type }) {
|
|
193
192
|
return `${type}Query`;
|
|
@@ -257,10 +256,10 @@ __export(generate_exports, {
|
|
|
257
256
|
transformPayloads: () => transformPayloads
|
|
258
257
|
});
|
|
259
258
|
function transformPayloads(pathItems, options) {
|
|
260
|
-
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
259
|
+
const { transformer, path, fullPath, base, uncountableNouns, validateStatus } = options;
|
|
261
260
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
262
|
-
const url = transformer.url({ path, base });
|
|
263
|
-
const args = { path, base, url, method, uncountableNouns, operation };
|
|
261
|
+
const url = transformer.url({ path, base, fullPath });
|
|
262
|
+
const args = { path, base, fullPath, url, method, uncountableNouns, operation };
|
|
264
263
|
const entity = transformer.entity(args);
|
|
265
264
|
const verb = transformer.verb(args);
|
|
266
265
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
@@ -307,11 +306,13 @@ function partitionApiModules(schema, options) {
|
|
|
307
306
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
308
307
|
const apiModules = Object.entries(keyToPaths).reduce((apiModules2, [name, paths]) => {
|
|
309
308
|
const payloads = paths.reduce((payloads2, path) => {
|
|
310
|
-
const
|
|
309
|
+
const fullPath = base ? base + path : path;
|
|
310
|
+
const pathItems = schemaPaths[fullPath];
|
|
311
311
|
payloads2.push(
|
|
312
312
|
...transformPayloads(pathItems, {
|
|
313
313
|
...options,
|
|
314
|
-
path
|
|
314
|
+
path,
|
|
315
|
+
fullPath,
|
|
315
316
|
transformer,
|
|
316
317
|
uncountableNouns,
|
|
317
318
|
validateStatus
|
|
@@ -359,7 +360,9 @@ function renderApiModules(apiModules, options) {
|
|
|
359
360
|
);
|
|
360
361
|
}
|
|
361
362
|
async function generateTypes(schema, output, typesFilename) {
|
|
362
|
-
const ast = await (0, import_openapi_typescript.default)(schema
|
|
363
|
+
const ast = await (0, import_openapi_typescript.default)(schema, {
|
|
364
|
+
defaultNonNullable: false
|
|
365
|
+
});
|
|
363
366
|
const contents = (0, import_openapi_typescript.astToString)(ast);
|
|
364
367
|
const typesFilepath = (0, import_path3.resolve)(CWD, output, typesFilename);
|
|
365
368
|
import_fs_extra2.default.outputFileSync(typesFilepath, contents);
|
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-NRJ4NQ4O.js");
|
|
12
12
|
return generate();
|
|
13
13
|
});
|
|
14
14
|
program.parse();
|
package/dist/index.cjs
CHANGED
|
@@ -72,8 +72,8 @@ var import_rattail = require("rattail");
|
|
|
72
72
|
function transformModuleName({ name }) {
|
|
73
73
|
return (0, import_rattail.camelize)(name);
|
|
74
74
|
}
|
|
75
|
-
function transformUrl({ path
|
|
76
|
-
return
|
|
75
|
+
function transformUrl({ path }) {
|
|
76
|
+
return path.replace(/{/g, ":").replace(/}/g, "");
|
|
77
77
|
}
|
|
78
78
|
function transformVerb({ method }) {
|
|
79
79
|
switch (method) {
|
|
@@ -85,8 +85,7 @@ function transformVerb({ method }) {
|
|
|
85
85
|
return (0, import_rattail.pascalCase)(method);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
function transformEntity({ path, method,
|
|
89
|
-
path = base ? path.replace(base, "") : path;
|
|
88
|
+
function transformEntity({ path, method, uncountableNouns }) {
|
|
90
89
|
const words = path.split("/").filter(Boolean);
|
|
91
90
|
return words.reduce((entity, word, index) => {
|
|
92
91
|
if (word.includes("{")) {
|
|
@@ -108,8 +107,8 @@ function transformFn({ verb, entity }) {
|
|
|
108
107
|
function transformType({ verb, entity }) {
|
|
109
108
|
return `Api${verb}${entity}`;
|
|
110
109
|
}
|
|
111
|
-
function transformTypeValue({
|
|
112
|
-
return `paths['${
|
|
110
|
+
function transformTypeValue({ fullPath, method }) {
|
|
111
|
+
return `paths['${fullPath}']['${method}']`;
|
|
113
112
|
}
|
|
114
113
|
function transformTypeQuery({ type }) {
|
|
115
114
|
return `${type}Query`;
|
|
@@ -296,10 +295,10 @@ function getResponseMetadataItems(operation, validateStatus) {
|
|
|
296
295
|
|
|
297
296
|
// src/generate.ts
|
|
298
297
|
function transformPayloads(pathItems, options) {
|
|
299
|
-
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
298
|
+
const { transformer, path, fullPath, base, uncountableNouns, validateStatus } = options;
|
|
300
299
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
301
|
-
const url = transformer.url({ path, base });
|
|
302
|
-
const args = { path, base, url, method, uncountableNouns, operation };
|
|
300
|
+
const url = transformer.url({ path, base, fullPath });
|
|
301
|
+
const args = { path, base, fullPath, url, method, uncountableNouns, operation };
|
|
303
302
|
const entity = transformer.entity(args);
|
|
304
303
|
const verb = transformer.verb(args);
|
|
305
304
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
@@ -346,11 +345,13 @@ function partitionApiModules(schema, options) {
|
|
|
346
345
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
347
346
|
const apiModules = Object.entries(keyToPaths).reduce((apiModules2, [name, paths]) => {
|
|
348
347
|
const payloads = paths.reduce((payloads2, path) => {
|
|
349
|
-
const
|
|
348
|
+
const fullPath = base ? base + path : path;
|
|
349
|
+
const pathItems = schemaPaths[fullPath];
|
|
350
350
|
payloads2.push(
|
|
351
351
|
...transformPayloads(pathItems, {
|
|
352
352
|
...options,
|
|
353
|
-
path
|
|
353
|
+
path,
|
|
354
|
+
fullPath,
|
|
354
355
|
transformer,
|
|
355
356
|
uncountableNouns,
|
|
356
357
|
validateStatus
|
|
@@ -398,7 +399,9 @@ function renderApiModules(apiModules, options) {
|
|
|
398
399
|
);
|
|
399
400
|
}
|
|
400
401
|
async function generateTypes(schema, output, typesFilename) {
|
|
401
|
-
const ast = await (0, import_openapi_typescript.default)(schema
|
|
402
|
+
const ast = await (0, import_openapi_typescript.default)(schema, {
|
|
403
|
+
defaultNonNullable: false
|
|
404
|
+
});
|
|
402
405
|
const contents = (0, import_openapi_typescript.astToString)(ast);
|
|
403
406
|
const typesFilepath = (0, import_path3.resolve)(CWD, output, typesFilename);
|
|
404
407
|
import_fs_extra2.default.outputFileSync(typesFilepath, contents);
|
package/dist/index.d.cts
CHANGED
|
@@ -54,6 +54,7 @@ declare function getResponseMetadataItems(operation: OperationObject, validateSt
|
|
|
54
54
|
|
|
55
55
|
type TransformerBaseArgs = {
|
|
56
56
|
path: string;
|
|
57
|
+
fullPath: string;
|
|
57
58
|
base: string | undefined;
|
|
58
59
|
url: string;
|
|
59
60
|
method: string;
|
|
@@ -63,14 +64,15 @@ type TransformerBaseArgs = {
|
|
|
63
64
|
declare function transformModuleName({ name }: {
|
|
64
65
|
name: string;
|
|
65
66
|
}): string;
|
|
66
|
-
declare function transformUrl({ path
|
|
67
|
+
declare function transformUrl({ path }: {
|
|
67
68
|
path: string;
|
|
69
|
+
fullPath: string;
|
|
68
70
|
base: string | undefined;
|
|
69
71
|
}): string;
|
|
70
72
|
declare function transformVerb({ method }: {
|
|
71
73
|
method: string;
|
|
72
74
|
}): string;
|
|
73
|
-
declare function transformEntity({ path, method,
|
|
75
|
+
declare function transformEntity({ path, method, uncountableNouns }: TransformerBaseArgs): string;
|
|
74
76
|
declare function transformFn({ verb, entity }: {
|
|
75
77
|
verb: string;
|
|
76
78
|
entity: string;
|
|
@@ -79,7 +81,7 @@ declare function transformType({ verb, entity }: {
|
|
|
79
81
|
verb: string;
|
|
80
82
|
entity: string;
|
|
81
83
|
} & TransformerBaseArgs): string;
|
|
82
|
-
declare function transformTypeValue({
|
|
84
|
+
declare function transformTypeValue({ fullPath, method }: {
|
|
83
85
|
verb: string;
|
|
84
86
|
entity: string;
|
|
85
87
|
} & TransformerBaseArgs): string;
|
|
@@ -275,8 +277,9 @@ interface GenerateOptions {
|
|
|
275
277
|
}
|
|
276
278
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
277
279
|
path: string;
|
|
278
|
-
|
|
280
|
+
fullPath: string;
|
|
279
281
|
base: string | undefined;
|
|
282
|
+
transformer: Transformer;
|
|
280
283
|
uncountableNouns: string[];
|
|
281
284
|
validateStatus: (status: number) => boolean;
|
|
282
285
|
}): ApiModulePayload[];
|
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ declare function getResponseMetadataItems(operation: OperationObject, validateSt
|
|
|
54
54
|
|
|
55
55
|
type TransformerBaseArgs = {
|
|
56
56
|
path: string;
|
|
57
|
+
fullPath: string;
|
|
57
58
|
base: string | undefined;
|
|
58
59
|
url: string;
|
|
59
60
|
method: string;
|
|
@@ -63,14 +64,15 @@ type TransformerBaseArgs = {
|
|
|
63
64
|
declare function transformModuleName({ name }: {
|
|
64
65
|
name: string;
|
|
65
66
|
}): string;
|
|
66
|
-
declare function transformUrl({ path
|
|
67
|
+
declare function transformUrl({ path }: {
|
|
67
68
|
path: string;
|
|
69
|
+
fullPath: string;
|
|
68
70
|
base: string | undefined;
|
|
69
71
|
}): string;
|
|
70
72
|
declare function transformVerb({ method }: {
|
|
71
73
|
method: string;
|
|
72
74
|
}): string;
|
|
73
|
-
declare function transformEntity({ path, method,
|
|
75
|
+
declare function transformEntity({ path, method, uncountableNouns }: TransformerBaseArgs): string;
|
|
74
76
|
declare function transformFn({ verb, entity }: {
|
|
75
77
|
verb: string;
|
|
76
78
|
entity: string;
|
|
@@ -79,7 +81,7 @@ declare function transformType({ verb, entity }: {
|
|
|
79
81
|
verb: string;
|
|
80
82
|
entity: string;
|
|
81
83
|
} & TransformerBaseArgs): string;
|
|
82
|
-
declare function transformTypeValue({
|
|
84
|
+
declare function transformTypeValue({ fullPath, method }: {
|
|
83
85
|
verb: string;
|
|
84
86
|
entity: string;
|
|
85
87
|
} & TransformerBaseArgs): string;
|
|
@@ -275,8 +277,9 @@ interface GenerateOptions {
|
|
|
275
277
|
}
|
|
276
278
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
277
279
|
path: string;
|
|
278
|
-
|
|
280
|
+
fullPath: string;
|
|
279
281
|
base: string | undefined;
|
|
282
|
+
transformer: Transformer;
|
|
280
283
|
uncountableNouns: string[];
|
|
281
284
|
validateStatus: (status: number) => boolean;
|
|
282
285
|
}): ApiModulePayload[];
|
package/dist/index.js
CHANGED