api 6.1.1 → 7.0.0-alpha.1
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 +0 -12
- package/dist/bin.js +3 -3
- package/dist/{cli/codegen → codegen}/index.js +4 -4
- package/dist/{cli/codegen → codegen}/language.js +4 -3
- package/dist/codegen/languages/typescript/util.d.ts +10 -0
- package/dist/{cli/codegen → codegen}/languages/typescript/util.js +5 -6
- package/dist/{cli/codegen → codegen}/languages/typescript.d.ts +12 -12
- package/dist/{cli/codegen → codegen}/languages/typescript.js +75 -75
- package/dist/{cli/commands → commands}/index.js +3 -3
- package/dist/{cli/commands → commands}/install.js +37 -34
- package/dist/fetcher.d.ts +8 -9
- package/dist/fetcher.js +15 -15
- package/dist/{cli/lib → lib}/prompt.js +3 -3
- package/dist/{cli/logger.js → logger.js} +3 -3
- package/dist/packageInfo.d.ts +1 -1
- package/dist/packageInfo.js +2 -2
- package/dist/{cli/storage.d.ts → storage.d.ts} +5 -4
- package/dist/{cli/storage.js → storage.js} +39 -36
- package/package.json +14 -32
- package/src/bin.ts +1 -1
- package/src/{cli/codegen → codegen}/language.ts +3 -2
- package/src/{cli/codegen → codegen}/languages/typescript/util.ts +1 -1
- package/src/{cli/codegen → codegen}/languages/typescript.ts +31 -32
- package/src/{cli/commands → commands}/install.ts +1 -1
- package/src/fetcher.ts +4 -5
- package/src/packageInfo.ts +1 -1
- package/src/{cli/storage.ts → storage.ts} +13 -9
- package/tsconfig.json +3 -13
- package/dist/cache.d.ts +0 -68
- package/dist/cache.js +0 -198
- package/dist/cli/codegen/languages/typescript/util.d.ts +0 -20
- package/dist/core/errors/fetchError.d.ts +0 -12
- package/dist/core/errors/fetchError.js +0 -36
- package/dist/core/getJSONSchemaDefaults.d.ts +0 -14
- package/dist/core/getJSONSchemaDefaults.js +0 -61
- package/dist/core/index.d.ts +0 -40
- package/dist/core/index.js +0 -168
- package/dist/core/parseResponse.d.ts +0 -6
- package/dist/core/parseResponse.js +0 -71
- package/dist/core/prepareAuth.d.ts +0 -5
- package/dist/core/prepareAuth.js +0 -84
- package/dist/core/prepareParams.d.ts +0 -21
- package/dist/core/prepareParams.js +0 -425
- package/dist/core/prepareServer.d.ts +0 -10
- package/dist/core/prepareServer.js +0 -47
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -259
- package/src/.sink.d.ts +0 -1
- package/src/cache.ts +0 -193
- package/src/core/errors/fetchError.ts +0 -31
- package/src/core/getJSONSchemaDefaults.ts +0 -74
- package/src/core/index.ts +0 -148
- package/src/core/parseResponse.ts +0 -26
- package/src/core/prepareAuth.ts +0 -109
- package/src/core/prepareParams.ts +0 -415
- package/src/core/prepareServer.ts +0 -48
- package/src/index.ts +0 -203
- package/src/typings.d.ts +0 -2
- /package/dist/{cli/codegen → codegen}/index.d.ts +0 -0
- /package/dist/{cli/codegen → codegen}/language.d.ts +0 -0
- /package/dist/{cli/commands → commands}/index.d.ts +0 -0
- /package/dist/{cli/commands → commands}/install.d.ts +0 -0
- /package/dist/{cli/lib → lib}/prompt.d.ts +0 -0
- /package/dist/{cli/logger.d.ts → logger.d.ts} +0 -0
- /package/src/{cli/codegen → codegen}/index.ts +0 -0
- /package/src/{cli/commands → commands}/index.ts +0 -0
- /package/src/{cli/lib → lib}/prompt.ts +0 -0
- /package/src/{cli/logger.ts → logger.ts} +0 -0
|
@@ -38,13 +38,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
|
-
exports
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
var commander_1 = require("commander");
|
|
43
43
|
var figures_1 = __importDefault(require("figures"));
|
|
44
44
|
var oas_1 = __importDefault(require("oas"));
|
|
45
45
|
var ora_1 = __importDefault(require("ora"));
|
|
46
|
-
var fetcher_1 = __importDefault(require("../../fetcher"));
|
|
47
46
|
var codegen_1 = __importDefault(require("../codegen"));
|
|
47
|
+
var fetcher_1 = __importDefault(require("../fetcher"));
|
|
48
48
|
var prompt_1 = __importDefault(require("../lib/prompt"));
|
|
49
49
|
var logger_1 = __importDefault(require("../logger"));
|
|
50
50
|
var storage_1 = __importDefault(require("../storage"));
|
|
@@ -70,7 +70,7 @@ cmd
|
|
|
70
70
|
if (!options.lang) return [3 /*break*/, 1];
|
|
71
71
|
language = options.lang;
|
|
72
72
|
return [3 /*break*/, 3];
|
|
73
|
-
case 1: return [4 /*yield*/, (0, prompt_1
|
|
73
|
+
case 1: return [4 /*yield*/, (0, prompt_1.default)({
|
|
74
74
|
type: 'select',
|
|
75
75
|
name: 'value',
|
|
76
76
|
message: 'What language would you like to generate an SDK for?',
|
|
@@ -78,14 +78,14 @@ cmd
|
|
|
78
78
|
{ title: 'TypeScript', value: 'ts' },
|
|
79
79
|
{ title: 'JavaScript', value: 'js' },
|
|
80
80
|
],
|
|
81
|
-
initial: 1
|
|
81
|
+
initial: 1,
|
|
82
82
|
})];
|
|
83
83
|
case 2:
|
|
84
84
|
(language = (_a.sent()).value);
|
|
85
85
|
_a.label = 3;
|
|
86
86
|
case 3:
|
|
87
87
|
if (!(language === 'js')) return [3 /*break*/, 5];
|
|
88
|
-
return [4 /*yield*/, (0, prompt_1
|
|
88
|
+
return [4 /*yield*/, (0, prompt_1.default)({
|
|
89
89
|
type: 'select',
|
|
90
90
|
name: 'value',
|
|
91
91
|
message: 'How are your project imports and exports structured?',
|
|
@@ -94,7 +94,7 @@ cmd
|
|
|
94
94
|
{ title: 'ECMAScript Modules', description: 'import/export', value: 'esm' },
|
|
95
95
|
],
|
|
96
96
|
initial: 0,
|
|
97
|
-
format: function (sel) { return (sel === 'cjs' ? 'js-cjs' : 'js-esm'); }
|
|
97
|
+
format: function (sel) { return (sel === 'cjs' ? 'js-cjs' : 'js-esm'); },
|
|
98
98
|
})];
|
|
99
99
|
case 4:
|
|
100
100
|
(language = (_a.sent()).value);
|
|
@@ -103,21 +103,21 @@ cmd
|
|
|
103
103
|
// @todo let them know that we're going to be creating a `.api/ directory
|
|
104
104
|
// @todo detect if they have a gitigore and .npmignore and if .api woudl be ignored by that
|
|
105
105
|
// @todo don't support swagger files without upconverting them
|
|
106
|
-
if (storage_1
|
|
106
|
+
if (storage_1.default.isInLockFile({ source: uri })) {
|
|
107
107
|
// @todo
|
|
108
108
|
// logger(`It looks like you already have this API installed. Would you like to update it?`);
|
|
109
109
|
}
|
|
110
110
|
if (!options.identifier) return [3 /*break*/, 6];
|
|
111
111
|
// `Storage.isIdentifierValid` will throw an exception if an identifier is invalid.
|
|
112
|
-
if (storage_1
|
|
112
|
+
if (storage_1.default.isIdentifierValid(options.identifier)) {
|
|
113
113
|
identifier = options.identifier;
|
|
114
114
|
}
|
|
115
115
|
return [3 /*break*/, 9];
|
|
116
116
|
case 6:
|
|
117
|
-
if (!fetcher_1
|
|
118
|
-
identifier = fetcher_1
|
|
117
|
+
if (!fetcher_1.default.isAPIRegistryUUID(uri)) return [3 /*break*/, 7];
|
|
118
|
+
identifier = fetcher_1.default.getProjectPrefixFromRegistryUUID(uri);
|
|
119
119
|
return [3 /*break*/, 9];
|
|
120
|
-
case 7: return [4 /*yield*/, (0, prompt_1
|
|
120
|
+
case 7: return [4 /*yield*/, (0, prompt_1.default)({
|
|
121
121
|
type: 'text',
|
|
122
122
|
name: 'value',
|
|
123
123
|
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`)',
|
|
@@ -126,83 +126,86 @@ cmd
|
|
|
126
126
|
return false;
|
|
127
127
|
}
|
|
128
128
|
try {
|
|
129
|
-
return storage_1
|
|
129
|
+
return storage_1.default.isIdentifierValid(value, true);
|
|
130
130
|
}
|
|
131
131
|
catch (err) {
|
|
132
132
|
return err.message;
|
|
133
133
|
}
|
|
134
|
-
}
|
|
134
|
+
},
|
|
135
135
|
})];
|
|
136
136
|
case 8:
|
|
137
137
|
(identifier = (_a.sent()).value);
|
|
138
138
|
_a.label = 9;
|
|
139
139
|
case 9:
|
|
140
140
|
if (!identifier) {
|
|
141
|
-
(0, logger_1
|
|
141
|
+
(0, logger_1.default)('You must tell us what you would like to identify this API as in order to install it.', true);
|
|
142
142
|
process.exit(1);
|
|
143
143
|
}
|
|
144
|
-
spinner = (0, ora_1
|
|
145
|
-
storage = new storage_1
|
|
144
|
+
spinner = (0, ora_1.default)('Fetching your API').start();
|
|
145
|
+
storage = new storage_1.default(uri, identifier);
|
|
146
146
|
return [4 /*yield*/, storage
|
|
147
147
|
.load()
|
|
148
148
|
.then(function (res) {
|
|
149
149
|
spinner.succeed(spinner.text);
|
|
150
150
|
return res;
|
|
151
151
|
})
|
|
152
|
-
.then(oas_1
|
|
152
|
+
.then(oas_1.default.init)
|
|
153
|
+
.catch(function (err) {
|
|
153
154
|
// @todo cleanup installed files
|
|
154
155
|
spinner.fail(spinner.text);
|
|
155
|
-
(0, logger_1
|
|
156
|
+
(0, logger_1.default)(err.message, true);
|
|
156
157
|
process.exit(1);
|
|
157
158
|
})];
|
|
158
159
|
case 10:
|
|
159
160
|
oas = _a.sent();
|
|
160
161
|
// @todo look for a prettier config and if we find one ask them if we should use it
|
|
161
|
-
spinner = (0, ora_1
|
|
162
|
-
generator = (0, codegen_1
|
|
162
|
+
spinner = (0, ora_1.default)('Generating your SDK').start();
|
|
163
|
+
generator = (0, codegen_1.default)(language, oas, './openapi.json', identifier);
|
|
163
164
|
return [4 /*yield*/, generator
|
|
164
165
|
.generator()
|
|
165
166
|
.then(function (res) {
|
|
166
167
|
spinner.succeed(spinner.text);
|
|
167
168
|
return res;
|
|
168
|
-
})
|
|
169
|
+
})
|
|
170
|
+
.catch(function (err) {
|
|
169
171
|
// @todo cleanup installed files
|
|
170
172
|
spinner.fail(spinner.text);
|
|
171
|
-
(0, logger_1
|
|
173
|
+
(0, logger_1.default)(err.message, true);
|
|
172
174
|
process.exit(1);
|
|
173
175
|
})];
|
|
174
176
|
case 11:
|
|
175
177
|
sdkSource = _a.sent();
|
|
176
|
-
spinner = (0, ora_1
|
|
178
|
+
spinner = (0, ora_1.default)('Saving your SDK into your codebase').start();
|
|
177
179
|
return [4 /*yield*/, storage
|
|
178
180
|
.saveSourceFiles(sdkSource)
|
|
179
181
|
.then(function () {
|
|
180
182
|
spinner.succeed(spinner.text);
|
|
181
|
-
})
|
|
183
|
+
})
|
|
184
|
+
.catch(function (err) {
|
|
182
185
|
// @todo cleanup installed files
|
|
183
186
|
spinner.fail(spinner.text);
|
|
184
|
-
(0, logger_1
|
|
187
|
+
(0, logger_1.default)(err.message, true);
|
|
185
188
|
process.exit(1);
|
|
186
189
|
})];
|
|
187
190
|
case 12:
|
|
188
191
|
_a.sent();
|
|
189
192
|
if (!generator.hasRequiredPackages()) return [3 /*break*/, 18];
|
|
190
|
-
(0, logger_1
|
|
193
|
+
(0, logger_1.default)("".concat(figures_1.default.warning, " This generator requires some packages to be installed alongside it:"));
|
|
191
194
|
Object.entries(generator.requiredPackages).forEach(function (_a) {
|
|
192
195
|
var pkg = _a[0], pkgInfo = _a[1];
|
|
193
|
-
(0, logger_1
|
|
196
|
+
(0, logger_1.default)(" ".concat(figures_1.default.pointerSmall, " ").concat(pkg, ": ").concat(pkgInfo.reason, " ").concat(pkgInfo.url));
|
|
194
197
|
});
|
|
195
198
|
if (!!options.yes) return [3 /*break*/, 14];
|
|
196
|
-
return [4 /*yield*/, (0, prompt_1
|
|
199
|
+
return [4 /*yield*/, (0, prompt_1.default)({
|
|
197
200
|
type: 'confirm',
|
|
198
201
|
name: 'value',
|
|
199
202
|
message: 'OK to proceed with package installation?',
|
|
200
|
-
initial: true
|
|
203
|
+
initial: true,
|
|
201
204
|
}).then(function (_a) {
|
|
202
205
|
var value = _a.value;
|
|
203
206
|
if (!value) {
|
|
204
207
|
// @todo cleanup installed files
|
|
205
|
-
(0, logger_1
|
|
208
|
+
(0, logger_1.default)('Installation cancelled.', true);
|
|
206
209
|
process.exit(1);
|
|
207
210
|
}
|
|
208
211
|
})];
|
|
@@ -210,7 +213,7 @@ cmd
|
|
|
210
213
|
_a.sent();
|
|
211
214
|
_a.label = 14;
|
|
212
215
|
case 14:
|
|
213
|
-
spinner = (0, ora_1
|
|
216
|
+
spinner = (0, ora_1.default)('Installing required packages').start();
|
|
214
217
|
_a.label = 15;
|
|
215
218
|
case 15:
|
|
216
219
|
_a.trys.push([15, 17, , 18]);
|
|
@@ -223,14 +226,14 @@ cmd
|
|
|
223
226
|
err_1 = _a.sent();
|
|
224
227
|
// @todo cleanup installed files
|
|
225
228
|
spinner.fail(spinner.text);
|
|
226
|
-
(0, logger_1
|
|
229
|
+
(0, logger_1.default)(err_1.message, true);
|
|
227
230
|
process.exit(1);
|
|
228
231
|
return [3 /*break*/, 18];
|
|
229
232
|
case 18:
|
|
230
|
-
(0, logger_1
|
|
233
|
+
(0, logger_1.default)('🚀 All done!');
|
|
231
234
|
return [2 /*return*/];
|
|
232
235
|
}
|
|
233
236
|
});
|
|
234
237
|
}); })
|
|
235
238
|
.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");
|
|
236
|
-
exports
|
|
239
|
+
exports.default = cmd;
|
package/dist/fetcher.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
2
|
-
import 'isomorphic-fetch';
|
|
3
2
|
export default class Fetcher {
|
|
4
3
|
uri: string | OASDocument;
|
|
5
4
|
/**
|
|
@@ -10,11 +9,11 @@ export default class Fetcher {
|
|
|
10
9
|
constructor(uri: string | OASDocument);
|
|
11
10
|
static isAPIRegistryUUID(uri: string): boolean;
|
|
12
11
|
static isGitHubBlobURL(uri: string): boolean;
|
|
13
|
-
static getProjectPrefixFromRegistryUUID(uri: string): string;
|
|
12
|
+
static getProjectPrefixFromRegistryUUID(uri: string): string | undefined;
|
|
14
13
|
load(): Promise<(Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
|
|
15
14
|
info: import("openapi-types").OpenAPIV3_1.InfoObject;
|
|
16
|
-
jsonSchemaDialect?: string;
|
|
17
|
-
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
|
|
15
|
+
jsonSchemaDialect?: string | undefined;
|
|
16
|
+
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[] | undefined;
|
|
18
17
|
} & Pick<{
|
|
19
18
|
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
20
19
|
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
@@ -25,8 +24,8 @@ export default class Fetcher {
|
|
|
25
24
|
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
26
25
|
}>, "paths"> & Record<string, unknown>) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
|
|
27
26
|
info: import("openapi-types").OpenAPIV3_1.InfoObject;
|
|
28
|
-
jsonSchemaDialect?: string;
|
|
29
|
-
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
|
|
27
|
+
jsonSchemaDialect?: string | undefined;
|
|
28
|
+
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[] | undefined;
|
|
30
29
|
} & Pick<{
|
|
31
30
|
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
32
31
|
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
@@ -37,8 +36,8 @@ export default class Fetcher {
|
|
|
37
36
|
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
38
37
|
}>, "webhooks"> & Record<string, unknown>) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
|
|
39
38
|
info: import("openapi-types").OpenAPIV3_1.InfoObject;
|
|
40
|
-
jsonSchemaDialect?: string;
|
|
41
|
-
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
|
|
39
|
+
jsonSchemaDialect?: string | undefined;
|
|
40
|
+
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[] | undefined;
|
|
42
41
|
} & Pick<{
|
|
43
42
|
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
44
43
|
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
@@ -50,5 +49,5 @@ export default class Fetcher {
|
|
|
50
49
|
}>, "components"> & Record<string, unknown>) | (import("openapi-types").OpenAPIV3.Document<{}> & Record<string, unknown>)>;
|
|
51
50
|
static getURL(url: string): Promise<any>;
|
|
52
51
|
static getFile(uri: string): Promise<any>;
|
|
53
|
-
static validate(json:
|
|
52
|
+
static validate(json: OASDocument): Promise<import("openapi-types").OpenAPI.Document<{}>>;
|
|
54
53
|
}
|
package/dist/fetcher.js
CHANGED
|
@@ -38,11 +38,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
|
-
exports
|
|
42
|
-
var
|
|
43
|
-
var
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var node_fs_1 = __importDefault(require("node:fs"));
|
|
43
|
+
var node_path_1 = __importDefault(require("node:path"));
|
|
44
44
|
var openapi_parser_1 = __importDefault(require("@readme/openapi-parser"));
|
|
45
|
-
require("isomorphic-fetch");
|
|
46
45
|
var js_yaml_1 = __importDefault(require("js-yaml"));
|
|
47
46
|
var Fetcher = /** @class */ (function () {
|
|
48
47
|
function Fetcher(uri) {
|
|
@@ -76,11 +75,12 @@ var Fetcher = /** @class */ (function () {
|
|
|
76
75
|
return /\/\/github.com\/[-_a-zA-Z0-9]+\/[-_a-zA-Z0-9]+\/blob\/(.*).(yaml|json|yml)/.test(uri);
|
|
77
76
|
};
|
|
78
77
|
Fetcher.getProjectPrefixFromRegistryUUID = function (uri) {
|
|
78
|
+
var _a;
|
|
79
79
|
var matches = uri.match(Fetcher.registryUUIDRegex);
|
|
80
80
|
if (!matches) {
|
|
81
81
|
return undefined;
|
|
82
82
|
}
|
|
83
|
-
return matches.groups.project;
|
|
83
|
+
return (_a = matches.groups) === null || _a === void 0 ? void 0 : _a.project;
|
|
84
84
|
};
|
|
85
85
|
Fetcher.prototype.load = function () {
|
|
86
86
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -114,7 +114,7 @@ var Fetcher = /** @class */ (function () {
|
|
|
114
114
|
}
|
|
115
115
|
if (res.headers.get('content-type') === 'application/yaml' || /\.(yaml|yml)/.test(url)) {
|
|
116
116
|
return res.text().then(function (text) {
|
|
117
|
-
return js_yaml_1
|
|
117
|
+
return js_yaml_1.default.load(text);
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
return res.json();
|
|
@@ -122,13 +122,13 @@ var Fetcher = /** @class */ (function () {
|
|
|
122
122
|
};
|
|
123
123
|
Fetcher.getFile = function (uri) {
|
|
124
124
|
// Support relative paths by resolving them against the cwd.
|
|
125
|
-
var file =
|
|
126
|
-
if (!
|
|
125
|
+
var file = node_path_1.default.resolve(process.cwd(), uri);
|
|
126
|
+
if (!node_fs_1.default.existsSync(file)) {
|
|
127
127
|
throw new Error("Sorry, we were unable to load an API definition from ".concat(file, ". Please either supply a URL or a path on your filesystem."));
|
|
128
128
|
}
|
|
129
|
-
return Promise.resolve(
|
|
129
|
+
return Promise.resolve(node_fs_1.default.readFileSync(file, 'utf8')).then(function (res) {
|
|
130
130
|
if (/\.(yaml|yml)/.test(file)) {
|
|
131
|
-
return js_yaml_1
|
|
131
|
+
return js_yaml_1.default.load(res);
|
|
132
132
|
}
|
|
133
133
|
return JSON.parse(res);
|
|
134
134
|
});
|
|
@@ -138,16 +138,16 @@ var Fetcher = /** @class */ (function () {
|
|
|
138
138
|
throw new Error('Sorry, this module only supports OpenAPI definitions.');
|
|
139
139
|
}
|
|
140
140
|
// The `validate` method handles dereferencing for us.
|
|
141
|
-
return openapi_parser_1
|
|
141
|
+
return openapi_parser_1.default.validate(json, {
|
|
142
142
|
dereference: {
|
|
143
143
|
/**
|
|
144
144
|
* If circular `$refs` are ignored they'll remain in the API definition as `$ref: String`.
|
|
145
145
|
* This allows us to not only do easy circular reference detection but also stringify and
|
|
146
146
|
* save dereferenced API definitions back into the cache directory.
|
|
147
147
|
*/
|
|
148
|
-
circular: 'ignore'
|
|
149
|
-
}
|
|
150
|
-
})
|
|
148
|
+
circular: 'ignore',
|
|
149
|
+
},
|
|
150
|
+
}).catch(function (err) {
|
|
151
151
|
if (/is not a valid openapi definition/i.test(err.message)) {
|
|
152
152
|
throw new Error("Sorry, that doesn't look like a valid OpenAPI definition.");
|
|
153
153
|
}
|
|
@@ -161,4 +161,4 @@ var Fetcher = /** @class */ (function () {
|
|
|
161
161
|
Fetcher.registryUUIDRegex = /^@(?<project>[a-zA-Z0-9-_]+)(\/?(?<version>.+))?#(?<uuid>[a-z0-9]+)$/;
|
|
162
162
|
return Fetcher;
|
|
163
163
|
}());
|
|
164
|
-
exports
|
|
164
|
+
exports.default = Fetcher;
|
|
@@ -49,7 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
|
-
exports
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
var prompts_1 = __importDefault(require("prompts"));
|
|
54
54
|
/**
|
|
55
55
|
* The `prompts` library doesn't always interpret CTRL+C and release the terminal back to the user
|
|
@@ -74,8 +74,8 @@ function promptTerminal(question, options) {
|
|
|
74
74
|
process.exit(1);
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
return [2 /*return*/, (0, prompts_1
|
|
77
|
+
return [2 /*return*/, (0, prompts_1.default)(__assign(__assign({}, question), { onState: onState }), options)];
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
exports
|
|
81
|
+
exports.default = promptTerminal;
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
-
exports
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/* eslint-disable no-console */
|
|
7
7
|
var chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
function logger(log, error) {
|
|
9
9
|
if (error) {
|
|
10
|
-
console.error(chalk_1
|
|
10
|
+
console.error(chalk_1.default.red(log));
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
13
|
console.log(log);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
exports
|
|
16
|
+
exports.default = logger;
|
package/dist/packageInfo.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const PACKAGE_NAME = "api";
|
|
2
|
-
export declare const PACKAGE_VERSION = "
|
|
2
|
+
export declare const PACKAGE_VERSION = "7.0.0-alpha.1";
|
package/dist/packageInfo.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
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 = '
|
|
6
|
+
exports.PACKAGE_VERSION = '7.0.0-alpha.1';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
2
|
-
import Fetcher from '
|
|
2
|
+
import Fetcher from './fetcher';
|
|
3
3
|
export default class Storage {
|
|
4
4
|
static dir: string;
|
|
5
5
|
static lockfile: false | Lockfile;
|
|
@@ -36,7 +36,7 @@ export default class Storage {
|
|
|
36
36
|
/**
|
|
37
37
|
* Retrieve the lockfile record for the current spec + identifier if it exists in the lockfile.
|
|
38
38
|
*/
|
|
39
|
-
getFromLockfile(): LockfileAPI;
|
|
39
|
+
getFromLockfile(): LockfileAPI | undefined;
|
|
40
40
|
getIdentifierStorageDir(): string;
|
|
41
41
|
getAPIDefinition(): any;
|
|
42
42
|
saveSourceFiles(files: Record<string, string>): Promise<unknown>;
|
|
@@ -65,7 +65,7 @@ export default class Storage {
|
|
|
65
65
|
*/
|
|
66
66
|
save(spec: OASDocument): OASDocument;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
interface Lockfile {
|
|
69
69
|
apis: LockfileAPI[];
|
|
70
70
|
/**
|
|
71
71
|
* The `api.json` schema version. This will only ever change if we introduce breaking changes to
|
|
@@ -73,7 +73,7 @@ export interface Lockfile {
|
|
|
73
73
|
*/
|
|
74
74
|
version: '1.0';
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
interface LockfileAPI {
|
|
77
77
|
/**
|
|
78
78
|
* A unique identifier of the API. This'll be used to do requires on `@api/<identifier>` and also
|
|
79
79
|
* where the SDK code will be located in `.api/apis/<identifier>`.
|
|
@@ -103,3 +103,4 @@ export interface LockfileAPI {
|
|
|
103
103
|
*/
|
|
104
104
|
source: string;
|
|
105
105
|
}
|
|
106
|
+
export {};
|
|
@@ -38,28 +38,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
|
-
exports
|
|
42
|
-
var
|
|
43
|
-
var
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var node_fs_1 = __importDefault(require("node:fs"));
|
|
43
|
+
var node_path_1 = __importDefault(require("node:path"));
|
|
44
44
|
var make_dir_1 = __importDefault(require("make-dir"));
|
|
45
45
|
var ssri_1 = __importDefault(require("ssri"));
|
|
46
46
|
var validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
|
47
|
-
var fetcher_1 = __importDefault(require("
|
|
48
|
-
var packageInfo_1 = require("
|
|
47
|
+
var fetcher_1 = __importDefault(require("./fetcher"));
|
|
48
|
+
var packageInfo_1 = require("./packageInfo");
|
|
49
49
|
var Storage = /** @class */ (function () {
|
|
50
50
|
function Storage(source, identifier) {
|
|
51
51
|
Storage.setStorageDir();
|
|
52
|
-
this.fetcher = new fetcher_1
|
|
52
|
+
this.fetcher = new fetcher_1.default(source);
|
|
53
53
|
this.source = source;
|
|
54
|
-
|
|
54
|
+
if (identifier) {
|
|
55
|
+
this.identifier = identifier;
|
|
56
|
+
}
|
|
55
57
|
// This should default to false so we have awareness if we've looked at the lockfile yet.
|
|
56
58
|
Storage.lockfile = false;
|
|
57
59
|
}
|
|
58
60
|
Storage.getLockfilePath = function () {
|
|
59
|
-
return
|
|
61
|
+
return node_path_1.default.join(Storage.dir, 'api.json');
|
|
60
62
|
};
|
|
61
63
|
Storage.getAPIsDir = function () {
|
|
62
|
-
return
|
|
64
|
+
return node_path_1.default.join(Storage.dir, 'apis');
|
|
63
65
|
};
|
|
64
66
|
Storage.setStorageDir = function (dir) {
|
|
65
67
|
if (dir) {
|
|
@@ -71,8 +73,8 @@ var Storage = /** @class */ (function () {
|
|
|
71
73
|
// shouldn't overwrite what we've already got.
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
|
-
Storage.dir = make_dir_1
|
|
75
|
-
make_dir_1
|
|
76
|
+
Storage.dir = make_dir_1.default.sync(node_path_1.default.join(process.cwd(), '.api'));
|
|
77
|
+
make_dir_1.default.sync(Storage.getAPIsDir());
|
|
76
78
|
};
|
|
77
79
|
/**
|
|
78
80
|
* Reset the state of the entire storage system.
|
|
@@ -85,16 +87,16 @@ var Storage = /** @class */ (function () {
|
|
|
85
87
|
switch (_a.label) {
|
|
86
88
|
case 0:
|
|
87
89
|
if (!Storage.getLockfilePath()) return [3 /*break*/, 2];
|
|
88
|
-
return [4 /*yield*/,
|
|
90
|
+
return [4 /*yield*/, node_fs_1.default.promises.writeFile(Storage.getLockfilePath(), JSON.stringify(Storage.getDefaultLockfile(), null, 2))];
|
|
89
91
|
case 1:
|
|
90
92
|
_a.sent();
|
|
91
93
|
_a.label = 2;
|
|
92
94
|
case 2:
|
|
93
95
|
if (!Storage.getAPIsDir()) return [3 /*break*/, 5];
|
|
94
|
-
return [4 /*yield*/,
|
|
96
|
+
return [4 /*yield*/, node_fs_1.default.promises.rm(Storage.getAPIsDir(), { recursive: true })];
|
|
95
97
|
case 3:
|
|
96
98
|
_a.sent();
|
|
97
|
-
return [4 /*yield*/,
|
|
99
|
+
return [4 /*yield*/, node_fs_1.default.promises.mkdir(Storage.getAPIsDir(), { recursive: true })];
|
|
98
100
|
case 4:
|
|
99
101
|
_a.sent();
|
|
100
102
|
_a.label = 5;
|
|
@@ -106,13 +108,13 @@ var Storage = /** @class */ (function () {
|
|
|
106
108
|
Storage.getDefaultLockfile = function () {
|
|
107
109
|
return {
|
|
108
110
|
version: '1.0',
|
|
109
|
-
apis: []
|
|
111
|
+
apis: [],
|
|
110
112
|
};
|
|
111
113
|
};
|
|
112
114
|
Storage.generateIntegrityHash = function (definition) {
|
|
113
|
-
return ssri_1
|
|
115
|
+
return ssri_1.default
|
|
114
116
|
.fromData(JSON.stringify(definition), {
|
|
115
|
-
algorithms: ['sha512']
|
|
117
|
+
algorithms: ['sha512'],
|
|
116
118
|
})
|
|
117
119
|
.toString();
|
|
118
120
|
};
|
|
@@ -120,8 +122,8 @@ var Storage = /** @class */ (function () {
|
|
|
120
122
|
if (typeof Storage.lockfile === 'object') {
|
|
121
123
|
return Storage.lockfile;
|
|
122
124
|
}
|
|
123
|
-
if (
|
|
124
|
-
var file =
|
|
125
|
+
if (node_fs_1.default.existsSync(Storage.getLockfilePath())) {
|
|
126
|
+
var file = node_fs_1.default.readFileSync(Storage.getLockfilePath(), 'utf8');
|
|
125
127
|
Storage.lockfile = JSON.parse(file);
|
|
126
128
|
}
|
|
127
129
|
else {
|
|
@@ -130,15 +132,16 @@ var Storage = /** @class */ (function () {
|
|
|
130
132
|
return Storage.lockfile;
|
|
131
133
|
};
|
|
132
134
|
Storage.isIdentifierValid = function (identifier, prefixWithAPINamespace) {
|
|
135
|
+
var _a;
|
|
133
136
|
// Is this identifier already in storage?
|
|
134
137
|
if (Storage.isInLockFile({ identifier: identifier })) {
|
|
135
138
|
throw new Error("\"".concat(identifier, "\" is already taken in your `.api/` directory. Please try another identifier."));
|
|
136
139
|
}
|
|
137
|
-
var isValidForNPM = (0, validate_npm_package_name_1
|
|
140
|
+
var isValidForNPM = (0, validate_npm_package_name_1.default)(prefixWithAPINamespace ? "@api/".concat(identifier) : identifier);
|
|
138
141
|
if (!isValidForNPM.validForNewPackages) {
|
|
139
142
|
// `prompts` doesn't support surfacing multiple errors in a `validate` call so we can only
|
|
140
143
|
// surface the first to the user.
|
|
141
|
-
throw new Error("Identifier cannot be used for an NPM package: ".concat(isValidForNPM.errors[0]));
|
|
144
|
+
throw new Error("Identifier cannot be used for an NPM package: ".concat(((_a = isValidForNPM === null || isValidForNPM === void 0 ? void 0 : isValidForNPM.errors) === null || _a === void 0 ? void 0 : _a[0]) || '[error unavailable]'));
|
|
142
145
|
}
|
|
143
146
|
return true;
|
|
144
147
|
};
|
|
@@ -182,10 +185,10 @@ var Storage = /** @class */ (function () {
|
|
|
182
185
|
if (!this.isInLockfile()) {
|
|
183
186
|
throw new Error("".concat(this.source, " has not been saved to storage yet and must do so before being retrieved."));
|
|
184
187
|
}
|
|
185
|
-
return
|
|
188
|
+
return node_path_1.default.join(Storage.getAPIsDir(), this.identifier);
|
|
186
189
|
};
|
|
187
190
|
Storage.prototype.getAPIDefinition = function () {
|
|
188
|
-
var file =
|
|
191
|
+
var file = node_fs_1.default.readFileSync(node_path_1.default.join(this.getIdentifierStorageDir(), 'openapi.json'), 'utf8');
|
|
189
192
|
return JSON.parse(file);
|
|
190
193
|
};
|
|
191
194
|
Storage.prototype.saveSourceFiles = function (files) {
|
|
@@ -197,8 +200,8 @@ var Storage = /** @class */ (function () {
|
|
|
197
200
|
var savedSource = [];
|
|
198
201
|
Object.entries(files).forEach(function (_a) {
|
|
199
202
|
var fileName = _a[0], contents = _a[1];
|
|
200
|
-
var sourceFilePath =
|
|
201
|
-
|
|
203
|
+
var sourceFilePath = node_path_1.default.join(_this.getIdentifierStorageDir(), fileName);
|
|
204
|
+
node_fs_1.default.writeFileSync(sourceFilePath, contents);
|
|
202
205
|
savedSource.push(sourceFilePath);
|
|
203
206
|
});
|
|
204
207
|
resolve(savedSource);
|
|
@@ -241,31 +244,31 @@ var Storage = /** @class */ (function () {
|
|
|
241
244
|
throw new TypeError('An identifier must be set before saving the API definition into storage.');
|
|
242
245
|
}
|
|
243
246
|
// Create our main `.api/` directory.
|
|
244
|
-
if (!
|
|
245
|
-
|
|
247
|
+
if (!node_fs_1.default.existsSync(Storage.dir)) {
|
|
248
|
+
node_fs_1.default.mkdirSync(Storage.dir, { recursive: true });
|
|
246
249
|
}
|
|
247
250
|
// Create the `.api/apis/` diretory where we'll be storing API definitions.
|
|
248
|
-
if (!
|
|
249
|
-
|
|
251
|
+
if (!node_fs_1.default.existsSync(Storage.getAPIsDir())) {
|
|
252
|
+
node_fs_1.default.mkdirSync(Storage.getAPIsDir(), { recursive: true });
|
|
250
253
|
}
|
|
251
254
|
if (!this.isInLockfile()) {
|
|
252
255
|
// This API doesn't exist within our storage system yet so we need to record it in the
|
|
253
256
|
// lockfile.
|
|
254
|
-
var identifierStorageDir =
|
|
257
|
+
var identifierStorageDir = node_path_1.default.join(Storage.getAPIsDir(), this.identifier);
|
|
255
258
|
var saved = JSON.stringify(spec, null, 2);
|
|
256
259
|
// Create the `.api/apis/<identifier>` directory where we'll be storing this API definition
|
|
257
260
|
// and eventually its codegen'd SDK.
|
|
258
|
-
if (!
|
|
259
|
-
|
|
261
|
+
if (!node_fs_1.default.existsSync(identifierStorageDir)) {
|
|
262
|
+
node_fs_1.default.mkdirSync(identifierStorageDir, { recursive: true });
|
|
260
263
|
}
|
|
261
264
|
Storage.lockfile.apis.push({
|
|
262
265
|
identifier: this.identifier,
|
|
263
266
|
source: this.source,
|
|
264
267
|
integrity: Storage.generateIntegrityHash(spec),
|
|
265
|
-
installerVersion: packageInfo_1.PACKAGE_VERSION
|
|
268
|
+
installerVersion: packageInfo_1.PACKAGE_VERSION,
|
|
266
269
|
});
|
|
267
|
-
|
|
268
|
-
|
|
270
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(identifierStorageDir, 'openapi.json'), saved);
|
|
271
|
+
node_fs_1.default.writeFileSync(Storage.getLockfilePath(), JSON.stringify(Storage.lockfile, null, 2));
|
|
269
272
|
}
|
|
270
273
|
else {
|
|
271
274
|
// Is this the same spec that we already have? Should we update it? // @todo
|
|
@@ -274,4 +277,4 @@ var Storage = /** @class */ (function () {
|
|
|
274
277
|
};
|
|
275
278
|
return Storage;
|
|
276
279
|
}());
|
|
277
|
-
exports
|
|
280
|
+
exports.default = Storage;
|