api 5.0.6 → 5.0.8
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 +12 -1
- package/dist/cli/commands/install.js +12 -8
- package/dist/core/prepareParams.js +34 -24
- package/dist/index.js +2 -2
- package/dist/packageInfo.d.ts +1 -1
- package/dist/packageInfo.js +1 -1
- package/package.json +10 -10
- package/src/cli/commands/install.ts +16 -13
- package/src/core/prepareParams.ts +22 -21
- package/src/index.ts +2 -2
- package/src/packageInfo.ts +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,18 @@ const petstore = require('api')(
|
|
|
43
43
|
'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json'
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
-
petstore.listPets().then(({ data })
|
|
46
|
+
petstore.listPets().then(({ data }) => {
|
|
47
|
+
console.log(`My pets name is ${data[0].name}!`);
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The ESM syntax is supported as well:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import api from 'api';
|
|
55
|
+
const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8');
|
|
56
|
+
|
|
57
|
+
petstore.listPets().then(({ data }) => {
|
|
47
58
|
console.log(`My pets name is ${data[0].name}!`);
|
|
48
59
|
});
|
|
49
60
|
```
|
|
@@ -61,6 +61,7 @@ cmd
|
|
|
61
61
|
'js-esm',
|
|
62
62
|
'ts',
|
|
63
63
|
]))
|
|
64
|
+
.addOption(new commander_1.Option('-y, --yes', 'Automatically answer "yes" to any prompts printed'))
|
|
64
65
|
.action(function (uri, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
65
66
|
var language, identifier, spinner, storage, oas, generator, sdkSource, err_1;
|
|
66
67
|
return __generator(this, function (_a) {
|
|
@@ -183,12 +184,13 @@ cmd
|
|
|
183
184
|
})];
|
|
184
185
|
case 11:
|
|
185
186
|
_a.sent();
|
|
186
|
-
if (!generator.hasRequiredPackages()) return [3 /*break*/,
|
|
187
|
+
if (!generator.hasRequiredPackages()) return [3 /*break*/, 17];
|
|
187
188
|
(0, logger_1["default"])("".concat(figures_1["default"].warning, " This generator requires some packages to be installed alongside it:"));
|
|
188
189
|
Object.entries(generator.requiredPackages).forEach(function (_a) {
|
|
189
190
|
var pkg = _a[0], pkgInfo = _a[1];
|
|
190
191
|
(0, logger_1["default"])(" ".concat(figures_1["default"].pointerSmall, " ").concat(pkg, ": ").concat(pkgInfo.reason, " ").concat(pkgInfo.url));
|
|
191
192
|
});
|
|
193
|
+
if (!!options.yes) return [3 /*break*/, 13];
|
|
192
194
|
return [4 /*yield*/, (0, prompt_1["default"])({
|
|
193
195
|
type: 'confirm',
|
|
194
196
|
name: 'value',
|
|
@@ -204,23 +206,25 @@ cmd
|
|
|
204
206
|
})];
|
|
205
207
|
case 12:
|
|
206
208
|
_a.sent();
|
|
207
|
-
spinner = (0, ora_1["default"])('Installing required packages').start();
|
|
208
209
|
_a.label = 13;
|
|
209
210
|
case 13:
|
|
210
|
-
|
|
211
|
-
|
|
211
|
+
spinner = (0, ora_1["default"])('Installing required packages').start();
|
|
212
|
+
_a.label = 14;
|
|
212
213
|
case 14:
|
|
214
|
+
_a.trys.push([14, 16, , 17]);
|
|
215
|
+
return [4 /*yield*/, generator.installer(storage)];
|
|
216
|
+
case 15:
|
|
213
217
|
_a.sent();
|
|
214
218
|
spinner.succeed(spinner.text);
|
|
215
|
-
return [3 /*break*/,
|
|
216
|
-
case
|
|
219
|
+
return [3 /*break*/, 17];
|
|
220
|
+
case 16:
|
|
217
221
|
err_1 = _a.sent();
|
|
218
222
|
// @todo cleanup installed files
|
|
219
223
|
spinner.fail(spinner.text);
|
|
220
224
|
(0, logger_1["default"])(err_1.message, true);
|
|
221
225
|
process.exit(1);
|
|
222
|
-
return [3 /*break*/,
|
|
223
|
-
case
|
|
226
|
+
return [3 /*break*/, 17];
|
|
227
|
+
case 17:
|
|
224
228
|
(0, logger_1["default"])('🚀 All done!');
|
|
225
229
|
return [2 /*return*/];
|
|
226
230
|
}
|
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
exports.__esModule = true;
|
|
42
|
-
var
|
|
42
|
+
var fs_1 = __importDefault(require("fs"));
|
|
43
43
|
var path_1 = __importDefault(require("path"));
|
|
44
44
|
var stream_1 = __importDefault(require("stream"));
|
|
45
45
|
var caseless_1 = __importDefault(require("caseless"));
|
|
@@ -100,32 +100,42 @@ function merge(src, target) {
|
|
|
100
100
|
*
|
|
101
101
|
*/
|
|
102
102
|
function processFile(paramName, file) {
|
|
103
|
+
var _this = this;
|
|
103
104
|
if (typeof file === 'string') {
|
|
104
105
|
// In order to support relative pathed files, we need to attempt to resolve them.
|
|
105
106
|
var resolvedFile_1 = path_1["default"].resolve(file);
|
|
106
|
-
return
|
|
107
|
-
.stat(resolvedFile_1)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
107
|
+
return new Promise(function (resolve, reject) {
|
|
108
|
+
fs_1["default"].stat(resolvedFile_1, function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
109
|
+
var fileMetadata, payloadFilename;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
if (err) {
|
|
114
|
+
if (err.code === 'ENOENT') {
|
|
115
|
+
// It's less than ideal for us to handle files that don't exist like this but because
|
|
116
|
+
// `file` is a string it might actually be the full text contents of the file and not
|
|
117
|
+
// actually a path.
|
|
118
|
+
//
|
|
119
|
+
// We also can't really regex to see if `file` *looks*` like a path because one should be
|
|
120
|
+
// able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that
|
|
121
|
+
// doesn't *look* like a path, it is one that should still work.
|
|
122
|
+
return [2 /*return*/, resolve(undefined)];
|
|
123
|
+
}
|
|
124
|
+
return [2 /*return*/, reject(err)];
|
|
125
|
+
}
|
|
126
|
+
return [4 /*yield*/, (0, sync_1["default"])(resolvedFile_1)];
|
|
127
|
+
case 1:
|
|
128
|
+
fileMetadata = _a.sent();
|
|
129
|
+
payloadFilename = encodeURIComponent(path_1["default"].basename(resolvedFile_1));
|
|
130
|
+
return [2 /*return*/, resolve({
|
|
131
|
+
paramName: paramName,
|
|
132
|
+
base64: fileMetadata.content.replace(';base64', ";name=".concat(payloadFilename, ";base64")),
|
|
133
|
+
filename: payloadFilename,
|
|
134
|
+
buffer: fileMetadata.buffer
|
|
135
|
+
})];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}); });
|
|
129
139
|
});
|
|
130
140
|
}
|
|
131
141
|
else if (file instanceof stream_1["default"].Readable) {
|
package/dist/index.js
CHANGED
|
@@ -149,7 +149,7 @@ var Sdk = /** @class */ (function () {
|
|
|
149
149
|
// returning a Promise. When that happens, chaining `sdk.auth().operationId()` will fail.
|
|
150
150
|
if (['auth', 'config'].includes(method)) {
|
|
151
151
|
// @todo split this up so we have better types for `auth` and `config`
|
|
152
|
-
return function () {
|
|
152
|
+
return function authAndConfigHandler() {
|
|
153
153
|
var args = [];
|
|
154
154
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
155
155
|
args[_i] = arguments[_i];
|
|
@@ -157,7 +157,7 @@ var Sdk = /** @class */ (function () {
|
|
|
157
157
|
return target[method].apply(this, args);
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
|
-
return function () {
|
|
160
|
+
return function accessorHandler() {
|
|
161
161
|
var args = [];
|
|
162
162
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
163
163
|
args[_i] = arguments[_i];
|
package/dist/packageInfo.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const PACKAGE_NAME = "api";
|
|
2
|
-
export declare const PACKAGE_VERSION = "5.0.
|
|
2
|
+
export declare const PACKAGE_VERSION = "5.0.8";
|
package/dist/packageInfo.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.8",
|
|
4
4
|
"description": "Magical SDK generation from an OpenAPI definition 🪄",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"@readme/openapi-parser": "^2.4.0",
|
|
42
42
|
"caseless": "^0.12.0",
|
|
43
43
|
"chalk": "^4.1.2",
|
|
44
|
-
"commander": "^
|
|
44
|
+
"commander": "^10.0.0",
|
|
45
45
|
"datauri": "^4.1.0",
|
|
46
46
|
"execa": "^5.1.1",
|
|
47
|
-
"fetch-har": "^8.1.
|
|
47
|
+
"fetch-har": "^8.1.5",
|
|
48
48
|
"figures": "^3.2.0",
|
|
49
49
|
"find-cache-dir": "^3.3.1",
|
|
50
50
|
"form-data-encoder": "^1.7.2",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"lodash.setwith": "^4.3.2",
|
|
61
61
|
"lodash.startcase": "^4.4.0",
|
|
62
62
|
"make-dir": "^3.1.0",
|
|
63
|
-
"node-abort-controller": "^3.
|
|
64
|
-
"oas": "^20.
|
|
63
|
+
"node-abort-controller": "^3.1.1",
|
|
64
|
+
"oas": "^20.4.0",
|
|
65
65
|
"ora": "^5.4.1",
|
|
66
|
-
"prettier": "^2.8.
|
|
66
|
+
"prettier": "^2.8.3",
|
|
67
67
|
"prompts": "^2.4.2",
|
|
68
68
|
"remove-undefined-objects": "^2.0.2",
|
|
69
69
|
"semver": "^7.3.8",
|
|
@@ -94,11 +94,11 @@
|
|
|
94
94
|
"mocha": "^10.1.0",
|
|
95
95
|
"mock-require": "^3.0.3",
|
|
96
96
|
"nyc": "^15.1.0",
|
|
97
|
-
"oas-normalize": "^8.3.
|
|
97
|
+
"oas-normalize": "^8.3.2",
|
|
98
98
|
"sinon": "^15.0.0",
|
|
99
99
|
"sinon-chai": "^3.7.0",
|
|
100
|
-
"type-fest": "^3.5.
|
|
101
|
-
"typescript": "^4.9.
|
|
100
|
+
"type-fest": "^3.5.4",
|
|
101
|
+
"typescript": "^4.9.5",
|
|
102
102
|
"unique-temp-dir": "^1.0.0"
|
|
103
103
|
},
|
|
104
104
|
"prettier": "@readme/eslint-config/prettier",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"test/"
|
|
109
109
|
]
|
|
110
110
|
},
|
|
111
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "bd15ecccb3aadea9ee821056c41d7897638bbe9d"
|
|
112
112
|
}
|
|
@@ -26,7 +26,8 @@ cmd
|
|
|
26
26
|
'ts',
|
|
27
27
|
])
|
|
28
28
|
)
|
|
29
|
-
.
|
|
29
|
+
.addOption(new Option('-y, --yes', 'Automatically answer "yes" to any prompts printed'))
|
|
30
|
+
.action(async (uri: string, options: { lang: string; yes?: boolean }) => {
|
|
30
31
|
let language: SupportedLanguages;
|
|
31
32
|
if (options.lang) {
|
|
32
33
|
language = options.lang as SupportedLanguages;
|
|
@@ -155,18 +156,20 @@ cmd
|
|
|
155
156
|
logger(` ${figures.pointerSmall} ${pkg}: ${pkgInfo.reason} ${pkgInfo.url}`);
|
|
156
157
|
});
|
|
157
158
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
159
|
+
if (!options.yes) {
|
|
160
|
+
await promptTerminal({
|
|
161
|
+
type: 'confirm',
|
|
162
|
+
name: 'value',
|
|
163
|
+
message: 'OK to proceed with package installation?',
|
|
164
|
+
initial: true,
|
|
165
|
+
}).then(({ value }) => {
|
|
166
|
+
if (!value) {
|
|
167
|
+
// @todo cleanup installed files
|
|
168
|
+
logger('Installation cancelled.', true);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
170
173
|
|
|
171
174
|
spinner = ora('Installing required packages').start();
|
|
172
175
|
try {
|
|
@@ -2,7 +2,7 @@ import type { ReadStream } from 'fs';
|
|
|
2
2
|
import type { Operation } from 'oas';
|
|
3
3
|
import type { ParameterObject, SchemaObject } from 'oas/dist/rmoas.types';
|
|
4
4
|
|
|
5
|
-
import fs from 'fs
|
|
5
|
+
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import stream from 'stream';
|
|
8
8
|
|
|
@@ -81,33 +81,34 @@ function processFile(
|
|
|
81
81
|
// In order to support relative pathed files, we need to attempt to resolve them.
|
|
82
82
|
const resolvedFile = path.resolve(file);
|
|
83
83
|
|
|
84
|
-
return
|
|
85
|
-
.stat(resolvedFile
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
fs.stat(resolvedFile, async err => {
|
|
86
|
+
if (err) {
|
|
87
|
+
if (err.code === 'ENOENT') {
|
|
88
|
+
// It's less than ideal for us to handle files that don't exist like this but because
|
|
89
|
+
// `file` is a string it might actually be the full text contents of the file and not
|
|
90
|
+
// actually a path.
|
|
91
|
+
//
|
|
92
|
+
// We also can't really regex to see if `file` *looks*` like a path because one should be
|
|
93
|
+
// able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that
|
|
94
|
+
// doesn't *look* like a path, it is one that should still work.
|
|
95
|
+
return resolve(undefined);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return reject(err);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const fileMetadata = await datauri(resolvedFile);
|
|
88
102
|
const payloadFilename = encodeURIComponent(path.basename(resolvedFile));
|
|
89
103
|
|
|
90
|
-
return {
|
|
104
|
+
return resolve({
|
|
91
105
|
paramName,
|
|
92
106
|
base64: fileMetadata.content.replace(';base64', `;name=${payloadFilename};base64`),
|
|
93
107
|
filename: payloadFilename,
|
|
94
108
|
buffer: fileMetadata.buffer,
|
|
95
|
-
};
|
|
96
|
-
})
|
|
97
|
-
.catch(err => {
|
|
98
|
-
if (err.code === 'ENOENT') {
|
|
99
|
-
// It's less than ideal for us to handle files that don't exist like this but because
|
|
100
|
-
// `file` is a string it might actually be the full text contents of the file and not
|
|
101
|
-
// actually a path.
|
|
102
|
-
//
|
|
103
|
-
// We also can't really regex to see if `file` *looks*` like a path because one should be
|
|
104
|
-
// able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that
|
|
105
|
-
// doesn't *look* like a path, it is one that should still work.
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
throw err;
|
|
109
|
+
});
|
|
110
110
|
});
|
|
111
|
+
});
|
|
111
112
|
} else if (file instanceof stream.Readable) {
|
|
112
113
|
return getStream.buffer(file).then(buffer => {
|
|
113
114
|
const filePath = file.path as string;
|
package/src/index.ts
CHANGED
|
@@ -103,12 +103,12 @@ class Sdk {
|
|
|
103
103
|
// returning a Promise. When that happens, chaining `sdk.auth().operationId()` will fail.
|
|
104
104
|
if (['auth', 'config'].includes(method)) {
|
|
105
105
|
// @todo split this up so we have better types for `auth` and `config`
|
|
106
|
-
return function (...args: any) {
|
|
106
|
+
return function authAndConfigHandler(...args: any) {
|
|
107
107
|
return target[method].apply(this, args);
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
return async function (...args: unknown[]) {
|
|
111
|
+
return async function accessorHandler(...args: unknown[]) {
|
|
112
112
|
if (!(method in target)) {
|
|
113
113
|
// If this method doesn't exist on the proxy, have we loaded the SDK? If we have, then
|
|
114
114
|
// this method isn't valid.
|
package/src/packageInfo.ts
CHANGED