@ps-aux/api-client-gen 0.7.0-rc.2 → 0.7.0-rc.4
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 +14 -6
- package/dist/bin.cjs +78 -10
- package/dist/bin.mjs +60 -11
- package/dist/generateApiClient.cjs +2023 -1372
- package/dist/generateApiClient.mjs +2024 -1376
- package/dist/index.cjs +4 -3
- package/dist/index.d.cts +2177 -19
- package/dist/index.d.mts +2177 -19
- package/dist/index.d.ts +2177 -19
- package/dist/index.mjs +4 -4
- package/package.json +8 -5
- package/templates/http-client.eta +10 -1
- package/templates/procedure-call.ejs +2 -2
package/README.md
CHANGED
|
@@ -10,17 +10,22 @@ npm install -D @ps-aux/api-client-gen
|
|
|
10
10
|
|
|
11
11
|
## CLI
|
|
12
12
|
|
|
13
|
-
Create api-client-gen.config.
|
|
13
|
+
Create `api-client-gen.config.ts` or `api-client-gen.config.js` (loaded via [c12](https://github.com/unjs/c12)). `api-client-gen.config.ts` is recommended for the best type safety:
|
|
14
14
|
|
|
15
|
-
```
|
|
16
|
-
{
|
|
17
|
-
|
|
15
|
+
```ts
|
|
16
|
+
import { defineConfig } from '@ps-aux/api-client-gen'
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
petstore: {
|
|
18
20
|
"srcSpec": "https://petstore3.swagger.io/api/v3/openapi.json",
|
|
19
21
|
"dstDir": "./generated",
|
|
20
22
|
"apiName": "PetstoreApi",
|
|
23
|
+
"openApiGenerator": {
|
|
24
|
+
"codegen": {}
|
|
25
|
+
},
|
|
21
26
|
"zodSchemas": { "enabled": true }
|
|
22
27
|
}
|
|
23
|
-
}
|
|
28
|
+
})
|
|
24
29
|
```
|
|
25
30
|
|
|
26
31
|
Run: `npx gen-api-client petstore`
|
|
@@ -33,7 +38,10 @@ import { generateApiClient } from '@ps-aux/api-client-gen'
|
|
|
33
38
|
await generateApiClient({
|
|
34
39
|
srcSpec: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
35
40
|
dstDir: './generated',
|
|
36
|
-
apiName: 'PetstoreApi'
|
|
41
|
+
apiName: 'PetstoreApi',
|
|
42
|
+
openApiGenerator: {
|
|
43
|
+
codegen: {}
|
|
44
|
+
}
|
|
37
45
|
})
|
|
38
46
|
```
|
|
39
47
|
|
package/dist/bin.cjs
CHANGED
|
@@ -2,22 +2,90 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var generateApiClient = require('./generateApiClient.cjs');
|
|
5
|
-
var
|
|
5
|
+
var fs = require('node:fs');
|
|
6
|
+
var Path = require('node:path');
|
|
7
|
+
var c12 = require('c12');
|
|
6
8
|
require('path');
|
|
7
9
|
require('fs');
|
|
8
10
|
require('fs/promises');
|
|
9
|
-
require('node:path');
|
|
10
|
-
require('node:fs/promises');
|
|
11
|
-
require('node:fs');
|
|
12
11
|
require('swagger-typescript-api');
|
|
13
12
|
require('node:url');
|
|
13
|
+
require('node:fs/promises');
|
|
14
14
|
require('ts-to-zod');
|
|
15
15
|
|
|
16
|
+
function _interopNamespaceDefault(e) {
|
|
17
|
+
var n = Object.create(null);
|
|
18
|
+
if (e) {
|
|
19
|
+
Object.keys(e).forEach(function (k) {
|
|
20
|
+
if (k !== 'default') {
|
|
21
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return e[k]; }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
n.default = e;
|
|
30
|
+
return Object.freeze(n);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
34
|
+
|
|
35
|
+
const SUPPORTED_CONFIG_EXTENSIONS = ["ts", "js"];
|
|
36
|
+
const getSupportedConfigFiles = (name) => SUPPORTED_CONFIG_EXTENSIONS.map((ext) => `${name}.config.${ext}`);
|
|
37
|
+
const loadConfig = async ({
|
|
38
|
+
cwd = process.cwd(),
|
|
39
|
+
name,
|
|
40
|
+
parseConfig
|
|
41
|
+
}) => {
|
|
42
|
+
const supportedConfigFiles = getSupportedConfigFiles(name);
|
|
43
|
+
const presentConfigFiles = supportedConfigFiles.filter(
|
|
44
|
+
(fileName) => fs__namespace.existsSync(Path.join(cwd, fileName))
|
|
45
|
+
);
|
|
46
|
+
if (presentConfigFiles.length === 0) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`No config provided. Expected one of: ${supportedConfigFiles.join(", ")}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (presentConfigFiles.length > 1) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Multiple config files found. Keep only one of: ${supportedConfigFiles.join(", ")}`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const conf = await c12.loadConfig({
|
|
57
|
+
cwd,
|
|
58
|
+
configFile: presentConfigFiles[0],
|
|
59
|
+
rcFile: false,
|
|
60
|
+
packageJson: false,
|
|
61
|
+
globalRc: false,
|
|
62
|
+
configFileRequired: true
|
|
63
|
+
});
|
|
64
|
+
if (!conf.configFile) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`No config provided. Expected one of: ${supportedConfigFiles.join(", ")}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
config: parseConfig(conf.config, conf.configFile),
|
|
71
|
+
configFile: conf.configFile
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
16
75
|
const profile = process.argv[2];
|
|
17
76
|
if (!profile) throw new Error(`No profile specified`);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
77
|
+
const main = async () => {
|
|
78
|
+
const conf = await loadConfig({
|
|
79
|
+
cwd: process.cwd(),
|
|
80
|
+
name: "api-client-gen",
|
|
81
|
+
parseConfig: generateApiClient.parseConfig
|
|
82
|
+
});
|
|
83
|
+
const profileConf = conf.config[profile];
|
|
84
|
+
if (!profileConf)
|
|
85
|
+
throw new Error(`Profile "${profile}" not present in the configuration`);
|
|
86
|
+
await generateApiClient.generateApiClientFromConfig(profileConf);
|
|
87
|
+
};
|
|
88
|
+
main().catch((error) => {
|
|
89
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
});
|
package/dist/bin.mjs
CHANGED
|
@@ -1,21 +1,70 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { a as generateApiClientFromConfig, p as parseConfig } from './generateApiClient.mjs';
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import Path from 'node:path';
|
|
5
|
+
import { loadConfig as loadConfig$1 } from 'c12';
|
|
4
6
|
import 'path';
|
|
5
7
|
import 'fs';
|
|
6
8
|
import 'fs/promises';
|
|
7
|
-
import 'node:path';
|
|
8
|
-
import 'node:fs/promises';
|
|
9
|
-
import 'node:fs';
|
|
10
9
|
import 'swagger-typescript-api';
|
|
11
10
|
import 'node:url';
|
|
11
|
+
import 'node:fs/promises';
|
|
12
12
|
import 'ts-to-zod';
|
|
13
13
|
|
|
14
|
+
const SUPPORTED_CONFIG_EXTENSIONS = ["ts", "js"];
|
|
15
|
+
const getSupportedConfigFiles = (name) => SUPPORTED_CONFIG_EXTENSIONS.map((ext) => `${name}.config.${ext}`);
|
|
16
|
+
const loadConfig = async ({
|
|
17
|
+
cwd = process.cwd(),
|
|
18
|
+
name,
|
|
19
|
+
parseConfig
|
|
20
|
+
}) => {
|
|
21
|
+
const supportedConfigFiles = getSupportedConfigFiles(name);
|
|
22
|
+
const presentConfigFiles = supportedConfigFiles.filter(
|
|
23
|
+
(fileName) => fs.existsSync(Path.join(cwd, fileName))
|
|
24
|
+
);
|
|
25
|
+
if (presentConfigFiles.length === 0) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`No config provided. Expected one of: ${supportedConfigFiles.join(", ")}`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
if (presentConfigFiles.length > 1) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Multiple config files found. Keep only one of: ${supportedConfigFiles.join(", ")}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
const conf = await loadConfig$1({
|
|
36
|
+
cwd,
|
|
37
|
+
configFile: presentConfigFiles[0],
|
|
38
|
+
rcFile: false,
|
|
39
|
+
packageJson: false,
|
|
40
|
+
globalRc: false,
|
|
41
|
+
configFileRequired: true
|
|
42
|
+
});
|
|
43
|
+
if (!conf.configFile) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`No config provided. Expected one of: ${supportedConfigFiles.join(", ")}`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
config: parseConfig(conf.config, conf.configFile),
|
|
50
|
+
configFile: conf.configFile
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
14
54
|
const profile = process.argv[2];
|
|
15
55
|
if (!profile) throw new Error(`No profile specified`);
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
56
|
+
const main = async () => {
|
|
57
|
+
const conf = await loadConfig({
|
|
58
|
+
cwd: process.cwd(),
|
|
59
|
+
name: "api-client-gen",
|
|
60
|
+
parseConfig
|
|
61
|
+
});
|
|
62
|
+
const profileConf = conf.config[profile];
|
|
63
|
+
if (!profileConf)
|
|
64
|
+
throw new Error(`Profile "${profile}" not present in the configuration`);
|
|
65
|
+
await generateApiClientFromConfig(profileConf);
|
|
66
|
+
};
|
|
67
|
+
main().catch((error) => {
|
|
68
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
});
|