api 5.0.3 → 5.0.5
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 +1 -1
- package/dist/cache.d.ts +1 -1
- package/dist/cache.js +1 -1
- package/dist/cli/codegen/index.d.ts +1 -1
- package/dist/cli/codegen/languages/typescript.d.ts +4 -4
- package/dist/cli/codegen/languages/typescript.js +32 -12
- package/dist/cli/commands/install.js +1 -1
- package/dist/cli/lib/prompt.js +1 -1
- package/dist/cli/storage.d.ts +4 -4
- package/dist/cli/storage.js +1 -1
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +1 -1
- package/dist/core/parseResponse.js +1 -1
- package/dist/core/prepareParams.js +1 -1
- package/dist/fetcher.js +1 -1
- package/dist/index.js +1 -1
- package/dist/packageInfo.d.ts +1 -1
- package/dist/packageInfo.js +1 -1
- package/package.json +22 -22
- package/src/cli/codegen/languages/typescript.ts +36 -22
- package/src/cli/storage.ts +4 -4
- package/src/core/index.ts +2 -2
- package/src/packageInfo.ts +1 -1
package/dist/bin.js
CHANGED
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
38
|
function step(op) {
|
|
39
39
|
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (_) try {
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
41
|
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;
|
|
42
42
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
43
|
switch (op[0]) {
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
2
2
|
import 'isomorphic-fetch';
|
|
3
3
|
import Fetcher from './fetcher';
|
|
4
|
-
|
|
4
|
+
type CacheStore = Record<string, {
|
|
5
5
|
hash: string;
|
|
6
6
|
path?: string;
|
|
7
7
|
original: string | OASDocument;
|
package/dist/cache.js
CHANGED
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type CodeGeneratorLanguage from './language';
|
|
2
2
|
import type Oas from 'oas';
|
|
3
|
-
export
|
|
3
|
+
export type SupportedLanguages = 'js' | 'js-cjs' | 'js-esm' | 'ts';
|
|
4
4
|
export default function codegen(language: SupportedLanguages, spec: Oas, specPath: string, identifier: string): CodeGeneratorLanguage;
|
|
@@ -5,17 +5,17 @@ import type { Operation } from 'oas';
|
|
|
5
5
|
import type { ClassDeclaration } from 'ts-morph';
|
|
6
6
|
import { Project } from 'ts-morph';
|
|
7
7
|
import CodeGeneratorLanguage from '../language';
|
|
8
|
-
export
|
|
8
|
+
export interface TSGeneratorOptions {
|
|
9
9
|
outputJS?: boolean;
|
|
10
10
|
compilerTarget?: 'cjs' | 'esm';
|
|
11
|
-
}
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
interface OperationTypeHousing {
|
|
13
13
|
types: {
|
|
14
14
|
params?: false | Record<'body' | 'formData' | 'metadata', string>;
|
|
15
15
|
responses?: Record<string, string>;
|
|
16
16
|
};
|
|
17
17
|
operation: Operation;
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
export default class TSGenerator extends CodeGeneratorLanguage {
|
|
20
20
|
project: Project;
|
|
21
21
|
outputJS: boolean;
|
|
@@ -40,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
40
40
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
41
|
function step(op) {
|
|
42
42
|
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (_) try {
|
|
43
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
44
44
|
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;
|
|
45
45
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
46
|
switch (op[0]) {
|
|
@@ -100,7 +100,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
100
100
|
reason: "Required for the `api/dist/core` library that the codegen'd SDK uses for making requests.",
|
|
101
101
|
url: 'https://npm.im/api'
|
|
102
102
|
},
|
|
103
|
-
'json-schema-to-ts': {
|
|
103
|
+
'json-schema-to-ts@beta': {
|
|
104
104
|
reason: 'Required for TypeScript type handling.',
|
|
105
105
|
url: 'https://npm.im/json-schema-to-ts'
|
|
106
106
|
},
|
|
@@ -186,15 +186,28 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
186
186
|
if (Object.keys(this.schemas).length) {
|
|
187
187
|
this.createSchemasFile();
|
|
188
188
|
this.createTypesFile();
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Export all of our available types so they can be used in SDK implementations. Types are
|
|
191
|
+
* exported individually because TS has no way right now of allowing us to do
|
|
192
|
+
* `export type * from './types'` on a non-named entry.
|
|
193
|
+
*
|
|
194
|
+
* Types in the main entry point are only being exported for TS outputs as JS users won't be
|
|
195
|
+
* able to use them and it clashes with the default SDK export present.
|
|
196
|
+
*
|
|
197
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/37238}
|
|
198
|
+
* @see {@link https://github.com/readmeio/api/issues/588}
|
|
199
|
+
*/
|
|
200
|
+
if (!this.outputJS) {
|
|
201
|
+
types = Array.from(this.types.keys());
|
|
202
|
+
types.sort();
|
|
203
|
+
sdkSource.addExportDeclarations([
|
|
204
|
+
{
|
|
205
|
+
isTypeOnly: true,
|
|
206
|
+
namedExports: types,
|
|
207
|
+
moduleSpecifier: './types'
|
|
208
|
+
},
|
|
209
|
+
]);
|
|
210
|
+
}
|
|
198
211
|
}
|
|
199
212
|
else {
|
|
200
213
|
// If we don't have any schemas then we shouldn't import a `types` file that doesn't exist.
|
|
@@ -381,7 +394,14 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
381
394
|
},
|
|
382
395
|
]
|
|
383
396
|
});
|
|
384
|
-
sourceFile.addExportAssignment({
|
|
397
|
+
sourceFile.addExportAssignment({
|
|
398
|
+
// Because CJS targets have `createSDK` exported with `module.exports`, but the TS type side
|
|
399
|
+
// of things to work right we need to set this as `export =`. Thankfully `ts-morph` will
|
|
400
|
+
// handle this accordingly and still create our JS file with `module.exports` and not
|
|
401
|
+
// `export =` -- only TS types will have this export style.
|
|
402
|
+
isExportEquals: this.compilerTarget === 'cjs' && this.outputJS,
|
|
403
|
+
expression: 'createSDK'
|
|
404
|
+
});
|
|
385
405
|
return sourceFile;
|
|
386
406
|
};
|
|
387
407
|
/**
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
package/dist/cli/lib/prompt.js
CHANGED
|
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
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
30
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
31
|
switch (op[0]) {
|
package/dist/cli/storage.d.ts
CHANGED
|
@@ -65,15 +65,15 @@ export default class Storage {
|
|
|
65
65
|
*/
|
|
66
66
|
save(spec: OASDocument): OASDocument;
|
|
67
67
|
}
|
|
68
|
-
export
|
|
68
|
+
export interface Lockfile {
|
|
69
69
|
/**
|
|
70
70
|
* The `api.json` schema version. This will only ever change if we introduce breaking changes to
|
|
71
71
|
* this store.
|
|
72
72
|
*/
|
|
73
73
|
version: '1.0';
|
|
74
74
|
apis: LockfileAPI[];
|
|
75
|
-
}
|
|
76
|
-
export
|
|
75
|
+
}
|
|
76
|
+
export 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>`.
|
|
@@ -102,4 +102,4 @@ export declare type LockfileAPI = {
|
|
|
102
102
|
* @example 5.0.0
|
|
103
103
|
*/
|
|
104
104
|
installerVersion: string;
|
|
105
|
-
}
|
|
105
|
+
}
|
package/dist/cli/storage.js
CHANGED
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
package/dist/core/index.d.ts
CHANGED
|
@@ -14,14 +14,14 @@ export interface ConfigOptions {
|
|
|
14
14
|
*/
|
|
15
15
|
timeout?: number;
|
|
16
16
|
}
|
|
17
|
-
export
|
|
17
|
+
export interface FetchResponse<status, data> {
|
|
18
18
|
data: data;
|
|
19
19
|
status: status;
|
|
20
20
|
headers: Headers;
|
|
21
21
|
res: Response;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export
|
|
22
|
+
}
|
|
23
|
+
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
|
|
24
|
+
export type HTTPMethodRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
25
25
|
export { getJSONSchemaDefaults, parseResponse, prepareAuth, prepareParams, prepareServer };
|
|
26
26
|
export default class APICore {
|
|
27
27
|
spec: Oas;
|
package/dist/core/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
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
30
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
31
|
switch (op[0]) {
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
package/dist/fetcher.js
CHANGED
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
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.5";
|
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.5",
|
|
4
4
|
"description": "Magical SDK generation from an OpenAPI definition 🪄",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"swagger"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@readme/oas-to-har": "^20.0.
|
|
41
|
-
"@readme/openapi-parser": "^2.
|
|
40
|
+
"@readme/oas-to-har": "^20.0.1",
|
|
41
|
+
"@readme/openapi-parser": "^2.4.0",
|
|
42
42
|
"caseless": "^0.12.0",
|
|
43
43
|
"chalk": "^4.1.2",
|
|
44
|
-
"commander": "^9.4.
|
|
44
|
+
"commander": "^9.4.1",
|
|
45
45
|
"datauri": "^4.1.0",
|
|
46
46
|
"execa": "^5.1.1",
|
|
47
47
|
"fetch-har": "^8.1.3",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"get-stream": "^6.0.1",
|
|
53
53
|
"isomorphic-fetch": "^3.0.0",
|
|
54
54
|
"js-yaml": "^4.1.0",
|
|
55
|
-
"json-schema-to-ts": "^2.
|
|
55
|
+
"json-schema-to-ts": "^2.6.2-beta.0",
|
|
56
56
|
"json-schema-traverse": "^1.0.0",
|
|
57
57
|
"lodash.camelcase": "^4.3.0",
|
|
58
58
|
"lodash.deburr": "^4.1.0",
|
|
@@ -61,20 +61,20 @@
|
|
|
61
61
|
"lodash.startcase": "^4.4.0",
|
|
62
62
|
"make-dir": "^3.1.0",
|
|
63
63
|
"node-abort-controller": "^3.0.1",
|
|
64
|
-
"oas": "^20.0.
|
|
64
|
+
"oas": "^20.0.1",
|
|
65
65
|
"ora": "^5.4.1",
|
|
66
|
-
"prettier": "^2.8.
|
|
66
|
+
"prettier": "^2.8.1",
|
|
67
67
|
"prompts": "^2.4.2",
|
|
68
|
-
"remove-undefined-objects": "^2.0.
|
|
68
|
+
"remove-undefined-objects": "^2.0.2",
|
|
69
69
|
"semver": "^7.3.8",
|
|
70
|
-
"ssri": "^10.0.
|
|
71
|
-
"ts-morph": "^
|
|
70
|
+
"ssri": "^10.0.1",
|
|
71
|
+
"ts-morph": "^17.0.1",
|
|
72
72
|
"validate-npm-package-name": "^5.0.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@readme/oas-examples": "^5.
|
|
75
|
+
"@readme/oas-examples": "^5.9.0",
|
|
76
76
|
"@types/caseless": "^0.12.2",
|
|
77
|
-
"@types/chai": "^4.3.
|
|
77
|
+
"@types/chai": "^4.3.4",
|
|
78
78
|
"@types/find-cache-dir": "^3.2.1",
|
|
79
79
|
"@types/js-yaml": "^4.0.5",
|
|
80
80
|
"@types/lodash.camelcase": "^4.3.7",
|
|
@@ -82,23 +82,23 @@
|
|
|
82
82
|
"@types/lodash.merge": "^4.6.7",
|
|
83
83
|
"@types/lodash.setwith": "^4.3.7",
|
|
84
84
|
"@types/lodash.startcase": "^4.4.7",
|
|
85
|
-
"@types/mocha": "^10.0.
|
|
85
|
+
"@types/mocha": "^10.0.1",
|
|
86
86
|
"@types/prettier": "^2.7.1",
|
|
87
|
-
"@types/prompts": "^2.
|
|
87
|
+
"@types/prompts": "^2.4.2",
|
|
88
88
|
"@types/semver": "^7.3.13",
|
|
89
|
-
"@types/sinon-chai": "^3.2.
|
|
89
|
+
"@types/sinon-chai": "^3.2.9",
|
|
90
90
|
"@types/ssri": "^7.1.1",
|
|
91
91
|
"@types/validate-npm-package-name": "^4.0.0",
|
|
92
|
-
"chai": "^4.3.
|
|
92
|
+
"chai": "^4.3.7",
|
|
93
93
|
"fetch-mock": "^9.11.0",
|
|
94
|
-
"mocha": "^10.
|
|
94
|
+
"mocha": "^10.1.0",
|
|
95
95
|
"mock-require": "^3.0.3",
|
|
96
96
|
"nyc": "^15.1.0",
|
|
97
|
-
"oas-normalize": "^
|
|
98
|
-
"sinon": "^
|
|
97
|
+
"oas-normalize": "^8.1.4",
|
|
98
|
+
"sinon": "^15.0.0",
|
|
99
99
|
"sinon-chai": "^3.7.0",
|
|
100
|
-
"type-fest": "^3.
|
|
101
|
-
"typescript": "^4.
|
|
100
|
+
"type-fest": "^3.3.0",
|
|
101
|
+
"typescript": "^4.9.4",
|
|
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": "2d399495a06a79e5d2c812766e03281e8d7a1299"
|
|
112
112
|
}
|
|
@@ -19,18 +19,18 @@ import CodeGeneratorLanguage from '../language';
|
|
|
19
19
|
|
|
20
20
|
import { docblockEscape, formatter, generateTypeName, wordWrap } from './typescript/util';
|
|
21
21
|
|
|
22
|
-
export
|
|
22
|
+
export interface TSGeneratorOptions {
|
|
23
23
|
outputJS?: boolean;
|
|
24
24
|
compilerTarget?: 'cjs' | 'esm';
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
interface OperationTypeHousing {
|
|
28
28
|
types: {
|
|
29
29
|
params?: false | Record<'body' | 'formData' | 'metadata', string>;
|
|
30
30
|
responses?: Record<string, string>;
|
|
31
31
|
};
|
|
32
32
|
operation: Operation;
|
|
33
|
-
}
|
|
33
|
+
}
|
|
34
34
|
|
|
35
35
|
export default class TSGenerator extends CodeGeneratorLanguage {
|
|
36
36
|
project: Project;
|
|
@@ -78,7 +78,7 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
78
78
|
reason: "Required for the `api/dist/core` library that the codegen'd SDK uses for making requests.",
|
|
79
79
|
url: 'https://npm.im/api',
|
|
80
80
|
},
|
|
81
|
-
'json-schema-to-ts': {
|
|
81
|
+
'json-schema-to-ts@beta': {
|
|
82
82
|
reason: 'Required for TypeScript type handling.',
|
|
83
83
|
url: 'https://npm.im/json-schema-to-ts',
|
|
84
84
|
},
|
|
@@ -172,22 +172,29 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
172
172
|
this.createSchemasFile();
|
|
173
173
|
this.createTypesFile();
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Export all of our available types so they can be used in SDK implementations. Types are
|
|
177
|
+
* exported individually because TS has no way right now of allowing us to do
|
|
178
|
+
* `export type * from './types'` on a non-named entry.
|
|
179
|
+
*
|
|
180
|
+
* Types in the main entry point are only being exported for TS outputs as JS users won't be
|
|
181
|
+
* able to use them and it clashes with the default SDK export present.
|
|
182
|
+
*
|
|
183
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/37238}
|
|
184
|
+
* @see {@link https://github.com/readmeio/api/issues/588}
|
|
185
|
+
*/
|
|
186
|
+
if (!this.outputJS) {
|
|
187
|
+
const types = Array.from(this.types.keys());
|
|
188
|
+
types.sort();
|
|
189
|
+
|
|
190
|
+
sdkSource.addExportDeclarations([
|
|
191
|
+
{
|
|
192
|
+
isTypeOnly: true,
|
|
193
|
+
namedExports: types,
|
|
194
|
+
moduleSpecifier: './types',
|
|
195
|
+
},
|
|
196
|
+
]);
|
|
197
|
+
}
|
|
191
198
|
} else {
|
|
192
199
|
// If we don't have any schemas then we shouldn't import a `types` file that doesn't exist.
|
|
193
200
|
sdkSource
|
|
@@ -406,7 +413,14 @@ sdk.server('https://eu.api.example.com/v14');`)
|
|
|
406
413
|
],
|
|
407
414
|
});
|
|
408
415
|
|
|
409
|
-
sourceFile.addExportAssignment({
|
|
416
|
+
sourceFile.addExportAssignment({
|
|
417
|
+
// Because CJS targets have `createSDK` exported with `module.exports`, but the TS type side
|
|
418
|
+
// of things to work right we need to set this as `export =`. Thankfully `ts-morph` will
|
|
419
|
+
// handle this accordingly and still create our JS file with `module.exports` and not
|
|
420
|
+
// `export =` -- only TS types will have this export style.
|
|
421
|
+
isExportEquals: this.compilerTarget === 'cjs' && this.outputJS,
|
|
422
|
+
expression: 'createSDK',
|
|
423
|
+
});
|
|
410
424
|
|
|
411
425
|
return sourceFile;
|
|
412
426
|
}
|
package/src/cli/storage.ts
CHANGED
|
@@ -253,16 +253,16 @@ export default class Storage {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
export
|
|
256
|
+
export interface Lockfile {
|
|
257
257
|
/**
|
|
258
258
|
* The `api.json` schema version. This will only ever change if we introduce breaking changes to
|
|
259
259
|
* this store.
|
|
260
260
|
*/
|
|
261
261
|
version: '1.0';
|
|
262
262
|
apis: LockfileAPI[];
|
|
263
|
-
}
|
|
263
|
+
}
|
|
264
264
|
|
|
265
|
-
export
|
|
265
|
+
export interface LockfileAPI {
|
|
266
266
|
/**
|
|
267
267
|
* A unique identifier of the API. This'll be used to do requires on `@api/<identifier>` and also
|
|
268
268
|
* where the SDK code will be located in `.api/apis/<identifier>`.
|
|
@@ -294,4 +294,4 @@ export type LockfileAPI = {
|
|
|
294
294
|
* @example 5.0.0
|
|
295
295
|
*/
|
|
296
296
|
installerVersion: string;
|
|
297
|
-
}
|
|
297
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -24,12 +24,12 @@ export interface ConfigOptions {
|
|
|
24
24
|
timeout?: number;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export
|
|
27
|
+
export interface FetchResponse<status, data> {
|
|
28
28
|
data: data;
|
|
29
29
|
status: status;
|
|
30
30
|
headers: Headers;
|
|
31
31
|
res: Response;
|
|
32
|
-
}
|
|
32
|
+
}
|
|
33
33
|
|
|
34
34
|
// https://stackoverflow.com/a/39495173
|
|
35
35
|
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
|
package/src/packageInfo.ts
CHANGED