api 7.0.0-alpha.1 → 7.0.0-alpha.3
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/bin.js +16 -62
- package/dist/codegen/index.js +2 -2
- package/dist/codegen/language.js +13 -9
- package/dist/codegen/languages/typescript/util.js +15 -20
- package/dist/codegen/languages/typescript.d.ts +3 -3
- package/dist/codegen/languages/typescript.js +324 -397
- package/dist/commands/index.js +1 -1
- package/dist/commands/install.js +155 -215
- package/dist/fetcher.d.ts +3 -3
- package/dist/fetcher.js +54 -95
- package/dist/lib/prompt.js +15 -67
- package/dist/logger.js +1 -1
- package/dist/packageInfo.d.ts +1 -1
- package/dist/packageInfo.js +1 -1
- package/dist/storage.d.ts +1 -1
- package/dist/storage.js +79 -133
- package/package.json +9 -8
- package/src/codegen/languages/typescript.ts +2 -2
- package/src/fetcher.ts +1 -1
- package/src/packageInfo.ts +1 -1
- package/src/storage.ts +1 -1
- package/tsconfig.json +2 -0
package/dist/lib/prompt.js
CHANGED
|
@@ -1,56 +1,9 @@
|
|
|
1
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
4
|
};
|
|
52
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
|
|
6
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
54
7
|
/**
|
|
55
8
|
* The `prompts` library doesn't always interpret CTRL+C and release the terminal back to the user
|
|
56
9
|
* so we need handle this ourselves. This function is just a simple overload of the main `prompts`
|
|
@@ -58,24 +11,19 @@ var prompts_1 = __importDefault(require("prompts"));
|
|
|
58
11
|
*
|
|
59
12
|
* @see {@link https://github.com/terkelg/prompts/issues/252}
|
|
60
13
|
*/
|
|
61
|
-
function promptTerminal(question, options) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
return [2 /*return*/, (0, prompts_1.default)(__assign(__assign({}, question), { onState: onState }), options)];
|
|
78
|
-
});
|
|
79
|
-
});
|
|
14
|
+
async function promptTerminal(question, options) {
|
|
15
|
+
const enableTerminalCursor = () => {
|
|
16
|
+
process.stdout.write('\x1B[?25h');
|
|
17
|
+
};
|
|
18
|
+
const onState = (state) => {
|
|
19
|
+
if (state.aborted) {
|
|
20
|
+
// If we don't re-enable the terminal cursor before exiting the program, the cursor will
|
|
21
|
+
// remain hidden.
|
|
22
|
+
enableTerminalCursor();
|
|
23
|
+
process.stdout.write('\n');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return (0, prompts_1.default)({ ...question, onState }, options);
|
|
80
28
|
}
|
|
81
29
|
exports.default = promptTerminal;
|
package/dist/logger.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/* eslint-disable no-console */
|
|
7
|
-
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
function logger(log, error) {
|
|
9
9
|
if (error) {
|
|
10
10
|
console.error(chalk_1.default.red(log));
|
package/dist/packageInfo.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const PACKAGE_NAME = "api";
|
|
2
|
-
export declare const PACKAGE_VERSION = "7.0.0-alpha.
|
|
2
|
+
export declare const PACKAGE_VERSION = "7.0.0-alpha.3";
|
package/dist/packageInfo.js
CHANGED
|
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PACKAGE_VERSION = exports.PACKAGE_NAME = void 0;
|
|
4
4
|
// This file is automatically updated by the build script.
|
|
5
5
|
exports.PACKAGE_NAME = 'api';
|
|
6
|
-
exports.PACKAGE_VERSION = '7.0.0-alpha.
|
|
6
|
+
exports.PACKAGE_VERSION = '7.0.0-alpha.3';
|
package/dist/storage.d.ts
CHANGED
package/dist/storage.js
CHANGED
|
@@ -1,53 +1,26 @@
|
|
|
1
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
6
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const make_dir_1 = __importDefault(require("make-dir"));
|
|
9
|
+
const ssri_1 = __importDefault(require("ssri"));
|
|
10
|
+
const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
|
11
|
+
const fetcher_1 = __importDefault(require("./fetcher"));
|
|
12
|
+
const packageInfo_1 = require("./packageInfo");
|
|
13
|
+
class Storage {
|
|
14
|
+
static dir;
|
|
15
|
+
static lockfile;
|
|
16
|
+
/**
|
|
17
|
+
* This is the original source that the file came from (relative/absolute file path, URL, ReadMe
|
|
18
|
+
* registry UUID, etc.).
|
|
19
|
+
*/
|
|
20
|
+
source;
|
|
21
|
+
identifier;
|
|
22
|
+
fetcher;
|
|
23
|
+
constructor(source, identifier) {
|
|
51
24
|
Storage.setStorageDir();
|
|
52
25
|
this.fetcher = new fetcher_1.default(source);
|
|
53
26
|
this.source = source;
|
|
@@ -57,13 +30,13 @@ var Storage = /** @class */ (function () {
|
|
|
57
30
|
// This should default to false so we have awareness if we've looked at the lockfile yet.
|
|
58
31
|
Storage.lockfile = false;
|
|
59
32
|
}
|
|
60
|
-
|
|
33
|
+
static getLockfilePath() {
|
|
61
34
|
return node_path_1.default.join(Storage.dir, 'api.json');
|
|
62
|
-
}
|
|
63
|
-
|
|
35
|
+
}
|
|
36
|
+
static getAPIsDir() {
|
|
64
37
|
return node_path_1.default.join(Storage.dir, 'apis');
|
|
65
|
-
}
|
|
66
|
-
|
|
38
|
+
}
|
|
39
|
+
static setStorageDir(dir) {
|
|
67
40
|
if (dir) {
|
|
68
41
|
Storage.dir = dir;
|
|
69
42
|
return;
|
|
@@ -75,148 +48,122 @@ var Storage = /** @class */ (function () {
|
|
|
75
48
|
}
|
|
76
49
|
Storage.dir = make_dir_1.default.sync(node_path_1.default.join(process.cwd(), '.api'));
|
|
77
50
|
make_dir_1.default.sync(Storage.getAPIsDir());
|
|
78
|
-
}
|
|
51
|
+
}
|
|
79
52
|
/**
|
|
80
53
|
* Reset the state of the entire storage system.
|
|
81
54
|
*
|
|
82
55
|
* This will completely destroy the contents of the `.api/` directory!
|
|
83
56
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
case 2:
|
|
95
|
-
if (!Storage.getAPIsDir()) return [3 /*break*/, 5];
|
|
96
|
-
return [4 /*yield*/, node_fs_1.default.promises.rm(Storage.getAPIsDir(), { recursive: true })];
|
|
97
|
-
case 3:
|
|
98
|
-
_a.sent();
|
|
99
|
-
return [4 /*yield*/, node_fs_1.default.promises.mkdir(Storage.getAPIsDir(), { recursive: true })];
|
|
100
|
-
case 4:
|
|
101
|
-
_a.sent();
|
|
102
|
-
_a.label = 5;
|
|
103
|
-
case 5: return [2 /*return*/];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
Storage.getDefaultLockfile = function () {
|
|
57
|
+
static async reset() {
|
|
58
|
+
if (Storage.getLockfilePath()) {
|
|
59
|
+
await node_fs_1.default.promises.writeFile(Storage.getLockfilePath(), JSON.stringify(Storage.getDefaultLockfile(), null, 2));
|
|
60
|
+
}
|
|
61
|
+
if (Storage.getAPIsDir()) {
|
|
62
|
+
await node_fs_1.default.promises.rm(Storage.getAPIsDir(), { recursive: true });
|
|
63
|
+
await node_fs_1.default.promises.mkdir(Storage.getAPIsDir(), { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
static getDefaultLockfile() {
|
|
109
67
|
return {
|
|
110
68
|
version: '1.0',
|
|
111
69
|
apis: [],
|
|
112
70
|
};
|
|
113
|
-
}
|
|
114
|
-
|
|
71
|
+
}
|
|
72
|
+
static generateIntegrityHash(definition) {
|
|
115
73
|
return ssri_1.default
|
|
116
74
|
.fromData(JSON.stringify(definition), {
|
|
117
75
|
algorithms: ['sha512'],
|
|
118
76
|
})
|
|
119
77
|
.toString();
|
|
120
|
-
}
|
|
121
|
-
|
|
78
|
+
}
|
|
79
|
+
static getLockfile() {
|
|
122
80
|
if (typeof Storage.lockfile === 'object') {
|
|
123
81
|
return Storage.lockfile;
|
|
124
82
|
}
|
|
125
83
|
if (node_fs_1.default.existsSync(Storage.getLockfilePath())) {
|
|
126
|
-
|
|
84
|
+
const file = node_fs_1.default.readFileSync(Storage.getLockfilePath(), 'utf8');
|
|
127
85
|
Storage.lockfile = JSON.parse(file);
|
|
128
86
|
}
|
|
129
87
|
else {
|
|
130
88
|
Storage.lockfile = Storage.getDefaultLockfile();
|
|
131
89
|
}
|
|
132
90
|
return Storage.lockfile;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
var _a;
|
|
91
|
+
}
|
|
92
|
+
static isIdentifierValid(identifier, prefixWithAPINamespace) {
|
|
136
93
|
// Is this identifier already in storage?
|
|
137
|
-
if (Storage.isInLockFile({ identifier
|
|
138
|
-
throw new Error("
|
|
94
|
+
if (Storage.isInLockFile({ identifier })) {
|
|
95
|
+
throw new Error(`"${identifier}" is already taken in your \`.api/\` directory. Please try another identifier.`);
|
|
139
96
|
}
|
|
140
|
-
|
|
97
|
+
const isValidForNPM = (0, validate_npm_package_name_1.default)(prefixWithAPINamespace ? `@api/${identifier}` : identifier);
|
|
141
98
|
if (!isValidForNPM.validForNewPackages) {
|
|
142
99
|
// `prompts` doesn't support surfacing multiple errors in a `validate` call so we can only
|
|
143
100
|
// surface the first to the user.
|
|
144
|
-
throw new Error(
|
|
101
|
+
throw new Error(`Identifier cannot be used for an NPM package: ${isValidForNPM?.errors?.[0] || '[error unavailable]'}`);
|
|
145
102
|
}
|
|
146
103
|
return true;
|
|
147
|
-
}
|
|
148
|
-
|
|
104
|
+
}
|
|
105
|
+
static isInLockFile(search) {
|
|
149
106
|
// Because this method may run before we initialize a new storage object we should make sure
|
|
150
107
|
// that we have a storage directory present.
|
|
151
108
|
Storage.setStorageDir();
|
|
152
109
|
if (!search.identifier && !search.source) {
|
|
153
110
|
throw new TypeError('An `identifier` or `source` must be supplied to this method to search in the lockfile.');
|
|
154
111
|
}
|
|
155
|
-
|
|
112
|
+
const lockfile = Storage.getLockfile();
|
|
156
113
|
if (typeof lockfile !== 'object' || lockfile === null || !lockfile.apis) {
|
|
157
114
|
return false;
|
|
158
115
|
}
|
|
159
|
-
|
|
116
|
+
const res = lockfile.apis.find(a => {
|
|
160
117
|
if (search.identifier) {
|
|
161
118
|
return a.identifier === search.identifier;
|
|
162
119
|
}
|
|
163
120
|
return a.source === search.source;
|
|
164
121
|
});
|
|
165
122
|
return res === undefined ? false : res;
|
|
166
|
-
}
|
|
167
|
-
|
|
123
|
+
}
|
|
124
|
+
setIdentifier(identifier) {
|
|
168
125
|
this.identifier = identifier;
|
|
169
|
-
}
|
|
126
|
+
}
|
|
170
127
|
/**
|
|
171
128
|
* Determine if the current spec + identifier we're working with is already in the lockfile.
|
|
172
129
|
*/
|
|
173
|
-
|
|
130
|
+
isInLockfile() {
|
|
174
131
|
return Boolean(this.getFromLockfile());
|
|
175
|
-
}
|
|
132
|
+
}
|
|
176
133
|
/**
|
|
177
134
|
* Retrieve the lockfile record for the current spec + identifier if it exists in the lockfile.
|
|
178
135
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
Storage.prototype.getIdentifierStorageDir = function () {
|
|
136
|
+
getFromLockfile() {
|
|
137
|
+
const lockfile = Storage.getLockfile();
|
|
138
|
+
return lockfile.apis.find(a => a.identifier === this.identifier);
|
|
139
|
+
}
|
|
140
|
+
getIdentifierStorageDir() {
|
|
185
141
|
if (!this.isInLockfile()) {
|
|
186
|
-
throw new Error(
|
|
142
|
+
throw new Error(`${this.source} has not been saved to storage yet and must do so before being retrieved.`);
|
|
187
143
|
}
|
|
188
144
|
return node_path_1.default.join(Storage.getAPIsDir(), this.identifier);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
145
|
+
}
|
|
146
|
+
getAPIDefinition() {
|
|
147
|
+
const file = node_fs_1.default.readFileSync(node_path_1.default.join(this.getIdentifierStorageDir(), 'openapi.json'), 'utf8');
|
|
192
148
|
return JSON.parse(file);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
var _this = this;
|
|
149
|
+
}
|
|
150
|
+
saveSourceFiles(files) {
|
|
196
151
|
if (!this.isInLockfile()) {
|
|
197
|
-
throw new Error(
|
|
152
|
+
throw new Error(`${this.source} has not been saved to storage yet and must do so before being retrieved.`);
|
|
198
153
|
}
|
|
199
|
-
return new Promise(
|
|
200
|
-
|
|
201
|
-
Object.entries(files).forEach(
|
|
202
|
-
|
|
203
|
-
var sourceFilePath = node_path_1.default.join(_this.getIdentifierStorageDir(), fileName);
|
|
154
|
+
return new Promise(resolve => {
|
|
155
|
+
const savedSource = [];
|
|
156
|
+
Object.entries(files).forEach(([fileName, contents]) => {
|
|
157
|
+
const sourceFilePath = node_path_1.default.join(this.getIdentifierStorageDir(), fileName);
|
|
204
158
|
node_fs_1.default.writeFileSync(sourceFilePath, contents);
|
|
205
159
|
savedSource.push(sourceFilePath);
|
|
206
160
|
});
|
|
207
161
|
resolve(savedSource);
|
|
208
162
|
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return
|
|
212
|
-
|
|
213
|
-
return __generator(this, function (_a) {
|
|
214
|
-
return [2 /*return*/, this.fetcher.load().then(function (spec) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
215
|
-
return [2 /*return*/, this.save(spec)];
|
|
216
|
-
}); }); })];
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
};
|
|
163
|
+
}
|
|
164
|
+
async load() {
|
|
165
|
+
return this.fetcher.load().then(async (spec) => this.save(spec));
|
|
166
|
+
}
|
|
220
167
|
/**
|
|
221
168
|
* @example <caption>Storage directory structure</caption>
|
|
222
169
|
* .api/
|
|
@@ -239,7 +186,7 @@ var Storage = /** @class */ (function () {
|
|
|
239
186
|
* └── package.json
|
|
240
187
|
*
|
|
241
188
|
*/
|
|
242
|
-
|
|
189
|
+
save(spec) {
|
|
243
190
|
if (!this.identifier) {
|
|
244
191
|
throw new TypeError('An identifier must be set before saving the API definition into storage.');
|
|
245
192
|
}
|
|
@@ -254,8 +201,8 @@ var Storage = /** @class */ (function () {
|
|
|
254
201
|
if (!this.isInLockfile()) {
|
|
255
202
|
// This API doesn't exist within our storage system yet so we need to record it in the
|
|
256
203
|
// lockfile.
|
|
257
|
-
|
|
258
|
-
|
|
204
|
+
const identifierStorageDir = node_path_1.default.join(Storage.getAPIsDir(), this.identifier);
|
|
205
|
+
const saved = JSON.stringify(spec, null, 2);
|
|
259
206
|
// Create the `.api/apis/<identifier>` directory where we'll be storing this API definition
|
|
260
207
|
// and eventually its codegen'd SDK.
|
|
261
208
|
if (!node_fs_1.default.existsSync(identifierStorageDir)) {
|
|
@@ -274,7 +221,6 @@ var Storage = /** @class */ (function () {
|
|
|
274
221
|
// Is this the same spec that we already have? Should we update it? // @todo
|
|
275
222
|
}
|
|
276
223
|
return spec;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
}());
|
|
224
|
+
}
|
|
225
|
+
}
|
|
280
226
|
exports.default = Storage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.3",
|
|
4
4
|
"description": "Magical SDK generation from an OpenAPI definition 🪄",
|
|
5
5
|
"bin": {
|
|
6
6
|
"api": "./bin/api"
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"lodash.deburr": "^4.1.0",
|
|
48
48
|
"lodash.setwith": "^4.3.2",
|
|
49
49
|
"lodash.startcase": "^4.4.0",
|
|
50
|
-
"make-dir": "^
|
|
51
|
-
"oas": "^
|
|
50
|
+
"make-dir": "^4.0.0",
|
|
51
|
+
"oas": "^22.0.0",
|
|
52
52
|
"ora": "^5.4.1",
|
|
53
53
|
"prompts": "^2.4.2",
|
|
54
54
|
"semver": "^7.3.8",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"validate-npm-package-name": "^5.0.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@api/test-utils": "
|
|
61
|
-
"@readme/api-core": "
|
|
60
|
+
"@api/test-utils": "^7.0.0-alpha.2",
|
|
61
|
+
"@readme/api-core": "^7.0.0-alpha.3",
|
|
62
62
|
"@readme/oas-examples": "^5.12.0",
|
|
63
63
|
"@types/js-yaml": "^4.0.5",
|
|
64
64
|
"@types/lodash.camelcase": "^4.3.7",
|
|
@@ -71,11 +71,12 @@
|
|
|
71
71
|
"@types/validate-npm-package-name": "^4.0.0",
|
|
72
72
|
"@vitest/coverage-v8": "^0.34.4",
|
|
73
73
|
"fetch-mock": "^9.11.0",
|
|
74
|
-
"oas-normalize": "^
|
|
74
|
+
"oas-normalize": "^11.0.0",
|
|
75
75
|
"type-fest": "^4.3.1",
|
|
76
76
|
"typescript": "^5.2.2",
|
|
77
77
|
"unique-temp-dir": "^1.0.0",
|
|
78
|
-
"vitest": "^0.34.
|
|
78
|
+
"vitest": "^0.34.5"
|
|
79
79
|
},
|
|
80
|
-
"prettier": "@readme/eslint-config/prettier"
|
|
80
|
+
"prettier": "@readme/eslint-config/prettier",
|
|
81
|
+
"gitHead": "39b966c3f1bdc283e3f4d0e2d50484cfbc7a49a1"
|
|
81
82
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type Storage from '../../storage';
|
|
2
2
|
import type { InstallerOptions } from '../language';
|
|
3
3
|
import type Oas from 'oas';
|
|
4
|
-
import type
|
|
5
|
-
import type { HttpMethods, SchemaObject } from 'oas/
|
|
4
|
+
import type Operation from 'oas/operation';
|
|
5
|
+
import type { HttpMethods, SchemaObject } from 'oas/rmoas.types';
|
|
6
6
|
import type { SemVer } from 'semver';
|
|
7
7
|
import type {
|
|
8
8
|
ClassDeclaration,
|
package/src/fetcher.ts
CHANGED
package/src/packageInfo.ts
CHANGED
package/src/storage.ts
CHANGED
package/tsconfig.json
CHANGED