api 4.5.1 → 5.0.0-beta.2
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/LICENSE +1 -1
- package/README.md +32 -162
- package/bin/api +2 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +91 -0
- package/dist/cache.d.ts +30 -0
- package/dist/cache.js +217 -0
- package/dist/cli/codegen/index.d.ts +4 -0
- package/dist/cli/codegen/index.js +23 -0
- package/dist/cli/codegen/language.d.ts +27 -0
- package/dist/cli/codegen/language.js +19 -0
- package/dist/cli/codegen/languages/typescript.d.ts +99 -0
- package/dist/cli/codegen/languages/typescript.js +769 -0
- package/dist/cli/commands/index.d.ts +4 -0
- package/dist/cli/commands/index.js +9 -0
- package/dist/cli/commands/install.d.ts +3 -0
- package/dist/cli/commands/install.js +230 -0
- package/dist/cli/lib/prompt.d.ts +9 -0
- package/dist/cli/lib/prompt.js +81 -0
- package/dist/cli/logger.d.ts +1 -0
- package/dist/cli/logger.js +16 -0
- package/dist/cli/storage.d.ts +105 -0
- package/dist/cli/storage.js +264 -0
- package/dist/core/getJSONSchemaDefaults.d.ts +15 -0
- package/dist/core/getJSONSchemaDefaults.js +62 -0
- package/dist/core/index.d.ts +32 -0
- package/dist/core/index.js +143 -0
- package/dist/core/parseResponse.d.ts +1 -0
- package/dist/core/parseResponse.js +65 -0
- package/dist/core/prepareAuth.d.ts +5 -0
- package/dist/core/prepareAuth.js +55 -0
- package/dist/core/prepareParams.d.ts +24 -0
- package/dist/core/prepareParams.js +351 -0
- package/dist/core/prepareServer.d.ts +13 -0
- package/dist/core/prepareServer.js +50 -0
- package/dist/fetcher.d.ts +54 -0
- package/dist/fetcher.js +165 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +276 -0
- package/dist/packageInfo.d.ts +2 -0
- package/dist/packageInfo.js +6 -0
- package/package.json +67 -28
- package/src/.sink.d.ts +1 -0
- package/src/bin.ts +20 -0
- package/src/cache.ts +212 -0
- package/src/cli/codegen/index.ts +31 -0
- package/src/cli/codegen/language.ts +47 -0
- package/src/cli/codegen/languages/typescript.ts +807 -0
- package/src/cli/commands/index.ts +5 -0
- package/src/cli/commands/install.ts +196 -0
- package/src/cli/lib/prompt.ts +29 -0
- package/src/cli/logger.ts +10 -0
- package/src/cli/storage.ts +297 -0
- package/src/core/getJSONSchemaDefaults.ts +74 -0
- package/src/core/index.ts +108 -0
- package/src/{lib/parseResponse.js → core/parseResponse.ts} +5 -7
- package/src/core/prepareAuth.ts +85 -0
- package/src/core/prepareParams.ts +338 -0
- package/src/{lib/prepareServer.js → core/prepareServer.ts} +13 -12
- package/src/fetcher.ts +141 -0
- package/src/index.ts +212 -0
- package/src/packageInfo.ts +3 -0
- package/src/typings.d.ts +3 -0
- package/tsconfig.json +24 -0
- package/src/cache.js +0 -225
- package/src/index.js +0 -177
- package/src/lib/getSchema.js +0 -34
- package/src/lib/index.js +0 -11
- package/src/lib/prepareAuth.js +0 -69
- package/src/lib/prepareParams.js +0 -198
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
var install_1 = __importDefault(require("./install"));
|
|
7
|
+
exports["default"] = {
|
|
8
|
+
install: install_1["default"]
|
|
9
|
+
};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
exports.__esModule = true;
|
|
42
|
+
var commander_1 = require("commander");
|
|
43
|
+
var ora_1 = __importDefault(require("ora"));
|
|
44
|
+
var oas_1 = __importDefault(require("oas"));
|
|
45
|
+
var codegen_1 = __importDefault(require("../codegen"));
|
|
46
|
+
var fetcher_1 = __importDefault(require("../../fetcher"));
|
|
47
|
+
var storage_1 = __importDefault(require("../storage"));
|
|
48
|
+
var logger_1 = __importDefault(require("../logger"));
|
|
49
|
+
var prompt_1 = __importDefault(require("../lib/prompt"));
|
|
50
|
+
var figures_1 = __importDefault(require("figures"));
|
|
51
|
+
var validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
|
52
|
+
// @todo log logs to `.api/.logs` and have `.logs` ignored
|
|
53
|
+
var cmd = new commander_1.Command();
|
|
54
|
+
cmd
|
|
55
|
+
.name('install')
|
|
56
|
+
.description('install an API SDK into your codebase')
|
|
57
|
+
.argument('<uri>', 'an API to install')
|
|
58
|
+
.addOption(new commander_1.Option('-l, --lang <language>', 'SDK language').choices([
|
|
59
|
+
'js',
|
|
60
|
+
'js-cjs',
|
|
61
|
+
'js-esm',
|
|
62
|
+
'ts',
|
|
63
|
+
]))
|
|
64
|
+
.action(function (uri, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
65
|
+
var language, identifier, spinner, storage, oas, generator, sdkSource, err_1;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
if (!options.lang) return [3 /*break*/, 1];
|
|
70
|
+
language = options.lang;
|
|
71
|
+
return [3 /*break*/, 3];
|
|
72
|
+
case 1: return [4 /*yield*/, (0, prompt_1["default"])({
|
|
73
|
+
type: 'select',
|
|
74
|
+
name: 'value',
|
|
75
|
+
message: 'What language would you like to generate an SDK for?',
|
|
76
|
+
choices: [
|
|
77
|
+
{ title: 'TypeScript', value: 'ts' },
|
|
78
|
+
{ title: 'JavaScript', value: 'js' },
|
|
79
|
+
],
|
|
80
|
+
initial: 1
|
|
81
|
+
})];
|
|
82
|
+
case 2:
|
|
83
|
+
(language = (_a.sent()).value);
|
|
84
|
+
_a.label = 3;
|
|
85
|
+
case 3:
|
|
86
|
+
if (!(language === 'js')) return [3 /*break*/, 5];
|
|
87
|
+
return [4 /*yield*/, (0, prompt_1["default"])({
|
|
88
|
+
type: 'select',
|
|
89
|
+
name: 'value',
|
|
90
|
+
message: 'How are your project imports and exports structured?',
|
|
91
|
+
choices: [
|
|
92
|
+
{ title: 'CommonJS', description: 'require/exports', value: 'cjs' },
|
|
93
|
+
{ title: 'ECMAScript Modules', description: 'import/export', value: 'esm' },
|
|
94
|
+
],
|
|
95
|
+
initial: 0,
|
|
96
|
+
format: function (sel) { return (sel === 'cjs' ? 'js-cjs' : 'js-esm'); }
|
|
97
|
+
})];
|
|
98
|
+
case 4:
|
|
99
|
+
(language = (_a.sent()).value);
|
|
100
|
+
_a.label = 5;
|
|
101
|
+
case 5:
|
|
102
|
+
// @todo let them know that we're going to be creating a `.api/ directory
|
|
103
|
+
// @todo detect if they have a gitigore and .npmignore and if .api woudl be ignored by that
|
|
104
|
+
// @todo don't support swagger files without upconverting them
|
|
105
|
+
if (storage_1["default"].isInLockFile({ source: uri })) {
|
|
106
|
+
// @todo
|
|
107
|
+
// logger(`It looks like you already have this API installed. Would you like to update it?`);
|
|
108
|
+
}
|
|
109
|
+
if (!fetcher_1["default"].isAPIRegistryUUID(uri)) return [3 /*break*/, 6];
|
|
110
|
+
identifier = fetcher_1["default"].getProjectPrefixFromRegistryUUID(uri);
|
|
111
|
+
return [3 /*break*/, 8];
|
|
112
|
+
case 6: return [4 /*yield*/, (0, prompt_1["default"])({
|
|
113
|
+
type: 'text',
|
|
114
|
+
name: 'value',
|
|
115
|
+
message: 'What would you like to identify this API as? This will be how you import the SDK. (e.g. entering `petstore` would result in `@api/petstore`)',
|
|
116
|
+
validate: function (value) {
|
|
117
|
+
if (!value) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
// Is this identifier already in storage?
|
|
121
|
+
if (storage_1["default"].isInLockFile({ identifier: value })) {
|
|
122
|
+
return "\"".concat(value, "\" is already taken in your `.api/` directory. Please enter another identifier.");
|
|
123
|
+
}
|
|
124
|
+
var isValidForNPM = (0, validate_npm_package_name_1["default"])("@api/".concat(value));
|
|
125
|
+
if (!isValidForNPM.validForNewPackages) {
|
|
126
|
+
// `prompts` doesn't support surfacing multiple errors in a `validate` call so we can
|
|
127
|
+
// only surface the first to the user.
|
|
128
|
+
return isValidForNPM.errors[0];
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
})];
|
|
133
|
+
case 7:
|
|
134
|
+
(identifier = (_a.sent()).value);
|
|
135
|
+
_a.label = 8;
|
|
136
|
+
case 8:
|
|
137
|
+
if (!identifier) {
|
|
138
|
+
(0, logger_1["default"])('You must tell us what you would like to identify this API as in order to install it.', true);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
spinner = (0, ora_1["default"])('Fetching your API').start();
|
|
142
|
+
storage = new storage_1["default"](uri, identifier);
|
|
143
|
+
return [4 /*yield*/, storage
|
|
144
|
+
.load()
|
|
145
|
+
.then(function (res) {
|
|
146
|
+
spinner.succeed(spinner.text);
|
|
147
|
+
return res;
|
|
148
|
+
})
|
|
149
|
+
.then(oas_1["default"].init)["catch"](function (err) {
|
|
150
|
+
// @todo cleanup installed files
|
|
151
|
+
spinner.fail(spinner.text);
|
|
152
|
+
(0, logger_1["default"])(err.message, true);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
})];
|
|
155
|
+
case 9:
|
|
156
|
+
oas = _a.sent();
|
|
157
|
+
// @todo look for a prettier config and if we find one ask them if we should use it
|
|
158
|
+
spinner = (0, ora_1["default"])('Generating your SDK').start();
|
|
159
|
+
generator = (0, codegen_1["default"])(language, oas, './openapi.json', identifier);
|
|
160
|
+
return [4 /*yield*/, generator
|
|
161
|
+
.generator()
|
|
162
|
+
.then(function (res) {
|
|
163
|
+
spinner.succeed(spinner.text);
|
|
164
|
+
return res;
|
|
165
|
+
})["catch"](function (err) {
|
|
166
|
+
// @todo cleanup installed files
|
|
167
|
+
spinner.fail(spinner.text);
|
|
168
|
+
(0, logger_1["default"])(err.message, true);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
})];
|
|
171
|
+
case 10:
|
|
172
|
+
sdkSource = _a.sent();
|
|
173
|
+
spinner = (0, ora_1["default"])('Saving your SDK into your codebase').start();
|
|
174
|
+
return [4 /*yield*/, storage
|
|
175
|
+
.saveSourceFiles(sdkSource)
|
|
176
|
+
.then(function () {
|
|
177
|
+
spinner.succeed(spinner.text);
|
|
178
|
+
})["catch"](function (err) {
|
|
179
|
+
// @todo cleanup installed files
|
|
180
|
+
spinner.fail(spinner.text);
|
|
181
|
+
(0, logger_1["default"])(err.message, true);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
})];
|
|
184
|
+
case 11:
|
|
185
|
+
_a.sent();
|
|
186
|
+
if (!generator.hasRequiredPackages()) return [3 /*break*/, 16];
|
|
187
|
+
(0, logger_1["default"])("".concat(figures_1["default"].warning, " This generator requires some packages to be installed alongside it:"));
|
|
188
|
+
Object.entries(generator.requiredPackages).forEach(function (_a) {
|
|
189
|
+
var pkg = _a[0], pkgInfo = _a[1];
|
|
190
|
+
(0, logger_1["default"])(" ".concat(figures_1["default"].pointerSmall, " ").concat(pkg, ": ").concat(pkgInfo.reason, " ").concat(pkgInfo.url));
|
|
191
|
+
});
|
|
192
|
+
return [4 /*yield*/, (0, prompt_1["default"])({
|
|
193
|
+
type: 'confirm',
|
|
194
|
+
name: 'value',
|
|
195
|
+
message: 'OK to proceed with package installation?',
|
|
196
|
+
initial: true
|
|
197
|
+
}).then(function (_a) {
|
|
198
|
+
var value = _a.value;
|
|
199
|
+
if (!value) {
|
|
200
|
+
// @todo cleanup installed files
|
|
201
|
+
(0, logger_1["default"])('Installation cancelled.', true);
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
})];
|
|
205
|
+
case 12:
|
|
206
|
+
_a.sent();
|
|
207
|
+
spinner = (0, ora_1["default"])('Installing required packages').start();
|
|
208
|
+
_a.label = 13;
|
|
209
|
+
case 13:
|
|
210
|
+
_a.trys.push([13, 15, , 16]);
|
|
211
|
+
return [4 /*yield*/, generator.installer(storage)];
|
|
212
|
+
case 14:
|
|
213
|
+
_a.sent();
|
|
214
|
+
spinner.succeed(spinner.text);
|
|
215
|
+
return [3 /*break*/, 16];
|
|
216
|
+
case 15:
|
|
217
|
+
err_1 = _a.sent();
|
|
218
|
+
// @todo cleanup installed files
|
|
219
|
+
spinner.fail(spinner.text);
|
|
220
|
+
(0, logger_1["default"])(err_1.message, true);
|
|
221
|
+
process.exit(1);
|
|
222
|
+
return [3 /*break*/, 16];
|
|
223
|
+
case 16:
|
|
224
|
+
(0, logger_1["default"])('🚀 All done!');
|
|
225
|
+
return [2 /*return*/];
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}); })
|
|
229
|
+
.addHelpText('after', "\nExamples:\n $ api install @developers/v2.0#nysezql0wwo236\n $ api install https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json\n $ api install ./petstore.json");
|
|
230
|
+
exports["default"] = cmd;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import prompts from 'prompts';
|
|
2
|
+
/**
|
|
3
|
+
* The `prompts` library doesn't always interpret CTRL+C and release the terminal back to the user
|
|
4
|
+
* so we need handle this ourselves. This function is just a simple overload of the main `prompts`
|
|
5
|
+
* import that we use.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://github.com/terkelg/prompts/issues/252}
|
|
8
|
+
*/
|
|
9
|
+
export default function promptTerminal<T extends string = string>(question: prompts.PromptObject<T>, options?: prompts.Options): Promise<prompts.Answers<T>>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
exports.__esModule = true;
|
|
53
|
+
var prompts_1 = __importDefault(require("prompts"));
|
|
54
|
+
/**
|
|
55
|
+
* The `prompts` library doesn't always interpret CTRL+C and release the terminal back to the user
|
|
56
|
+
* so we need handle this ourselves. This function is just a simple overload of the main `prompts`
|
|
57
|
+
* import that we use.
|
|
58
|
+
*
|
|
59
|
+
* @see {@link https://github.com/terkelg/prompts/issues/252}
|
|
60
|
+
*/
|
|
61
|
+
function promptTerminal(question, options) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
var enableTerminalCursor, onState;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
enableTerminalCursor = function () {
|
|
66
|
+
process.stdout.write('\x1B[?25h');
|
|
67
|
+
};
|
|
68
|
+
onState = function (state) {
|
|
69
|
+
if (state.aborted) {
|
|
70
|
+
// If we don't re-enable the terminal cursor before exiting the program, the cursor will
|
|
71
|
+
// remain hidden.
|
|
72
|
+
enableTerminalCursor();
|
|
73
|
+
process.stdout.write('\n');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return [2 /*return*/, (0, prompts_1["default"])(__assign(__assign({}, question), { onState: onState }), options)];
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports["default"] = promptTerminal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function logger(log: string, error?: boolean): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
/* eslint-disable no-console */
|
|
7
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
function logger(log, error) {
|
|
9
|
+
if (error) {
|
|
10
|
+
console.error(chalk_1["default"].red(log));
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
console.log(log);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports["default"] = logger;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { OASDocument } from 'oas/@types/rmoas.types';
|
|
2
|
+
import Fetcher from '../fetcher';
|
|
3
|
+
export default class Storage {
|
|
4
|
+
static dir: string;
|
|
5
|
+
static lockfile: false | Lockfile;
|
|
6
|
+
/**
|
|
7
|
+
* This is the original source that the file came from (relative/absolute file path, URL, ReadMe
|
|
8
|
+
* registry UUID, etc.).
|
|
9
|
+
*/
|
|
10
|
+
source: string;
|
|
11
|
+
identifier: string;
|
|
12
|
+
fetcher: Fetcher;
|
|
13
|
+
constructor(source: string, identifier?: string);
|
|
14
|
+
static getLockfilePath(): string;
|
|
15
|
+
static getAPIsDir(): string;
|
|
16
|
+
static setStorageDir(dir?: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Reset the state of the entire storage system.
|
|
19
|
+
*
|
|
20
|
+
* This will completely destroy the contents of the `.api/` directory!
|
|
21
|
+
*/
|
|
22
|
+
static reset(): Promise<void>;
|
|
23
|
+
static getDefaultLockfile(): Lockfile;
|
|
24
|
+
static generateIntegrityHash(definition: OASDocument): string;
|
|
25
|
+
static getLockfile(): Lockfile;
|
|
26
|
+
static isInLockFile(search: {
|
|
27
|
+
identifier?: string;
|
|
28
|
+
source?: string;
|
|
29
|
+
}): false | LockfileAPI;
|
|
30
|
+
setIdentifier(identifier: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Determine if the current spec + identifier we're working with is already in the lockfile.
|
|
33
|
+
*/
|
|
34
|
+
isInLockfile(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Retrieve the lockfile record for the current spec + identifier if it exists in the lockfile.
|
|
37
|
+
*/
|
|
38
|
+
getFromLockfile(): LockfileAPI;
|
|
39
|
+
getIdentifierStorageDir(): string;
|
|
40
|
+
getAPIDefinition(): any;
|
|
41
|
+
saveSourceFiles(files: Record<string, string>): Promise<unknown>;
|
|
42
|
+
load(): Promise<OASDocument>;
|
|
43
|
+
/**
|
|
44
|
+
* @example <caption>Storage directory structure</caption>
|
|
45
|
+
* .api/
|
|
46
|
+
* ├── api.json // The `package-lock.json` equivalent that records everything that's
|
|
47
|
+
* | // installed, when it was installed, what the original source was,
|
|
48
|
+
* | // and what version of `api` was used.
|
|
49
|
+
* └── apis/
|
|
50
|
+
* ├── readme/
|
|
51
|
+
* | ├── node_modules/
|
|
52
|
+
* │ ├── index.js // We may offer the option to export a raw TS file for folks who want
|
|
53
|
+
* | | // that, but for now it'll be a compiled JS file.
|
|
54
|
+
* │ ├── index.d.ts // All types for their SDK, ready to use in an IDE.
|
|
55
|
+
* │ |── openapi.json
|
|
56
|
+
* │ └── package.json
|
|
57
|
+
* └── petstore/
|
|
58
|
+
* ├── node_modules/
|
|
59
|
+
* ├── index.js
|
|
60
|
+
* ├── index.d.ts
|
|
61
|
+
* ├── openapi.json
|
|
62
|
+
* └── package.json
|
|
63
|
+
*
|
|
64
|
+
* @param spec
|
|
65
|
+
*/
|
|
66
|
+
save(spec: OASDocument): OASDocument;
|
|
67
|
+
}
|
|
68
|
+
export declare type Lockfile = {
|
|
69
|
+
/**
|
|
70
|
+
* The `api.json` schema version. This will only ever change if we introduce breaking changes to
|
|
71
|
+
* this store.
|
|
72
|
+
*/
|
|
73
|
+
version: '1.0';
|
|
74
|
+
apis: LockfileAPI[];
|
|
75
|
+
};
|
|
76
|
+
export declare type LockfileAPI = {
|
|
77
|
+
/**
|
|
78
|
+
* A unique identifier of the API. This'll be used to do requires on `@api/<identifier>` and also
|
|
79
|
+
* where the SDK code will be located in `.api/apis/<identifier>`.
|
|
80
|
+
*
|
|
81
|
+
* @example petstore
|
|
82
|
+
*/
|
|
83
|
+
identifier: string;
|
|
84
|
+
/**
|
|
85
|
+
* The original source that was used to generate the SDK with.
|
|
86
|
+
*
|
|
87
|
+
* @example https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json
|
|
88
|
+
* @example ./petstore.json
|
|
89
|
+
* @example @developers/v2.0#nysezql0wwo236
|
|
90
|
+
*/
|
|
91
|
+
source: string;
|
|
92
|
+
/**
|
|
93
|
+
* An integrity hash that will be used to determine on `npx api update` calls if the API has
|
|
94
|
+
* changed since the SDK was last generated.
|
|
95
|
+
*
|
|
96
|
+
* @example sha512-ld+djZk8uRWmzXC+JYla1PTBScg0NjP/8x9vOOKRW+DuJ3NNMRjrpfbY7T77Jgnc87dZZsU49robbQfYe3ukug==
|
|
97
|
+
*/
|
|
98
|
+
integrity: string;
|
|
99
|
+
/**
|
|
100
|
+
* The version of `api` that was used to install this SDK.
|
|
101
|
+
*
|
|
102
|
+
* @example 5.0.0
|
|
103
|
+
*/
|
|
104
|
+
installerVersion: string;
|
|
105
|
+
};
|