api 7.0.0-beta.0 → 7.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/bin.js +8 -1
- package/dist/bin.js.map +1 -1
- package/dist/codegen/codegenerator.d.ts +44 -11
- package/dist/codegen/codegenerator.d.ts.map +1 -1
- package/dist/codegen/codegenerator.js +77 -0
- package/dist/codegen/codegenerator.js.map +1 -1
- package/dist/codegen/factory.d.ts +19 -3
- package/dist/codegen/factory.d.ts.map +1 -1
- package/dist/codegen/factory.js +12 -5
- package/dist/codegen/factory.js.map +1 -1
- package/dist/codegen/languages/typescript/index.d.ts +39 -5
- package/dist/codegen/languages/typescript/index.d.ts.map +1 -1
- package/dist/codegen/languages/typescript/index.js +268 -62
- package/dist/codegen/languages/typescript/index.js.map +1 -1
- package/dist/codegen/languages/typescript/util.d.ts.map +1 -1
- package/dist/codegen/languages/typescript/util.js +1 -3
- package/dist/codegen/languages/typescript/util.js.map +1 -1
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +4 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +71 -58
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/list.d.ts +4 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +37 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/uninstall.d.ts +4 -0
- package/dist/commands/uninstall.d.ts.map +1 -0
- package/dist/commands/uninstall.js +69 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/fetcher.d.ts +17 -17
- package/dist/fetcher.d.ts.map +1 -1
- package/dist/fetcher.js +7 -1
- package/dist/fetcher.js.map +1 -1
- package/dist/lib/isCI.d.ts +8 -0
- package/dist/lib/isCI.d.ts.map +1 -0
- package/dist/lib/isCI.js +18 -0
- package/dist/lib/isCI.js.map +1 -0
- package/dist/lib/prompt.d.ts +1 -1
- package/dist/lib/prompt.d.ts.map +1 -1
- package/dist/lib/prompt.js +33 -8
- package/dist/lib/prompt.js.map +1 -1
- package/dist/lib/suggestedOperations.d.ts +31 -0
- package/dist/lib/suggestedOperations.d.ts.map +1 -0
- package/dist/lib/suggestedOperations.js +108 -0
- package/dist/lib/suggestedOperations.js.map +1 -0
- package/dist/lockfileSchema.d.ts +125 -0
- package/dist/lockfileSchema.d.ts.map +1 -0
- package/dist/lockfileSchema.js +78 -0
- package/dist/lockfileSchema.js.map +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +5 -1
- package/dist/logger.js.map +1 -1
- package/dist/packageInfo.d.ts +1 -1
- package/dist/packageInfo.d.ts.map +1 -1
- package/dist/packageInfo.js +1 -1
- package/dist/packageInfo.js.map +1 -1
- package/dist/storage.d.ts +79 -62
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +112 -30
- package/dist/storage.js.map +1 -1
- package/legacy-require-handler.cjs +29 -0
- package/legacy-require-handler.d.cts +2 -0
- package/package.json +49 -35
- package/schema.json +69 -0
- package/src/bin.ts +0 -21
- package/src/codegen/codegenerator.ts +0 -75
- package/src/codegen/factory.ts +0 -23
- package/src/codegen/languages/typescript/index.ts +0 -984
- package/src/codegen/languages/typescript/util.ts +0 -174
- package/src/commands/index.ts +0 -5
- package/src/commands/install.ts +0 -196
- package/src/fetcher.ts +0 -145
- package/src/lib/prompt.ts +0 -29
- package/src/logger.ts +0 -10
- package/src/packageInfo.ts +0 -3
- package/src/storage.ts +0 -333
- package/tsconfig.json +0 -10
package/dist/storage.d.ts
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SupportedLanguage } from './codegen/factory.js';
|
|
2
|
+
import type { Lockfile } from './lockfileSchema.js';
|
|
3
|
+
import type { OASDocument } from 'oas/types';
|
|
2
4
|
import Fetcher from './fetcher.js';
|
|
3
5
|
export default class Storage {
|
|
4
6
|
static dir: string;
|
|
5
|
-
static lockfile:
|
|
7
|
+
static lockfile: Lockfile | false;
|
|
8
|
+
fetcher: Fetcher;
|
|
6
9
|
/**
|
|
7
10
|
* This is the original source that the file came from (relative/absolute file path, URL, ReadMe
|
|
8
11
|
* registry UUID, etc.).
|
|
12
|
+
*
|
|
13
|
+
* @example @developers/v2.0#nysezql0wwo236
|
|
14
|
+
* @example https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json
|
|
15
|
+
* @example ./petstore.json
|
|
9
16
|
*/
|
|
10
17
|
source: string;
|
|
18
|
+
/**
|
|
19
|
+
* The language that this SDK was generated for.
|
|
20
|
+
*/
|
|
21
|
+
private language;
|
|
22
|
+
/**
|
|
23
|
+
* The identifier that this was installed as.
|
|
24
|
+
*
|
|
25
|
+
* @example petstore
|
|
26
|
+
*/
|
|
11
27
|
identifier: string;
|
|
12
|
-
|
|
13
|
-
constructor(source: string, identifier?: string);
|
|
28
|
+
constructor(source: string, language?: SupportedLanguage, identifier?: string);
|
|
14
29
|
static getLockfilePath(): string;
|
|
15
30
|
static getAPIsDir(): string;
|
|
16
31
|
static setStorageDir(dir?: string): void;
|
|
@@ -18,16 +33,40 @@ export default class Storage {
|
|
|
18
33
|
* Reset the state of the entire storage system.
|
|
19
34
|
*
|
|
20
35
|
* This will completely destroy the contents of the `.api/` directory!
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
21
38
|
*/
|
|
22
39
|
static reset(): Promise<void>;
|
|
23
40
|
static getDefaultLockfile(): Lockfile;
|
|
24
41
|
static generateIntegrityHash(definition: OASDocument): string;
|
|
25
|
-
static getLockfile():
|
|
42
|
+
static getLockfile(): {
|
|
43
|
+
$schema?: string | undefined;
|
|
44
|
+
apis: {
|
|
45
|
+
private?: boolean | undefined;
|
|
46
|
+
source?: string | undefined;
|
|
47
|
+
updatedAt?: string | undefined;
|
|
48
|
+
createdAt: string;
|
|
49
|
+
identifier: string;
|
|
50
|
+
installerVersion: string;
|
|
51
|
+
integrity: string;
|
|
52
|
+
language: "js";
|
|
53
|
+
}[];
|
|
54
|
+
};
|
|
26
55
|
static isIdentifierValid(identifier: string, prefixWithAPINamespace?: boolean): boolean;
|
|
27
56
|
static isInLockFile(search: {
|
|
28
57
|
identifier?: string;
|
|
29
58
|
source?: string;
|
|
30
|
-
}): false |
|
|
59
|
+
}): false | {
|
|
60
|
+
private?: boolean | undefined;
|
|
61
|
+
source?: string | undefined;
|
|
62
|
+
updatedAt?: string | undefined;
|
|
63
|
+
createdAt: string;
|
|
64
|
+
identifier: string;
|
|
65
|
+
installerVersion: string;
|
|
66
|
+
integrity: string;
|
|
67
|
+
language: "js";
|
|
68
|
+
};
|
|
69
|
+
setLanguage(language?: SupportedLanguage): void;
|
|
31
70
|
setIdentifier(identifier: string): void;
|
|
32
71
|
/**
|
|
33
72
|
* Determine if the current spec + identifier we're working with is already in the lockfile.
|
|
@@ -35,73 +74,51 @@ export default class Storage {
|
|
|
35
74
|
isInLockfile(): boolean;
|
|
36
75
|
/**
|
|
37
76
|
* Retrieve the lockfile record for the current spec + identifier if it exists in the lockfile.
|
|
77
|
+
*
|
|
38
78
|
*/
|
|
39
|
-
getFromLockfile():
|
|
79
|
+
getFromLockfile(): {
|
|
80
|
+
private?: boolean | undefined;
|
|
81
|
+
source?: string | undefined;
|
|
82
|
+
updatedAt?: string | undefined;
|
|
83
|
+
createdAt: string;
|
|
84
|
+
identifier: string;
|
|
85
|
+
installerVersion: string;
|
|
86
|
+
integrity: string;
|
|
87
|
+
language: "js";
|
|
88
|
+
} | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Retrieve the lockfile record, if it exists, for a given identifier.
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
static getFromLockfile(identifier: string): {
|
|
94
|
+
private?: boolean | undefined;
|
|
95
|
+
source?: string | undefined;
|
|
96
|
+
updatedAt?: string | undefined;
|
|
97
|
+
createdAt: string;
|
|
98
|
+
identifier: string;
|
|
99
|
+
installerVersion: string;
|
|
100
|
+
integrity: string;
|
|
101
|
+
language: "js";
|
|
102
|
+
} | undefined;
|
|
103
|
+
getSDKLanguage(): "js";
|
|
104
|
+
getPackageName(): string | undefined;
|
|
40
105
|
getIdentifierStorageDir(): string;
|
|
106
|
+
getAPIDefinitionPath(): string;
|
|
41
107
|
getAPIDefinition(): any;
|
|
42
108
|
saveSourceFiles(files: Record<string, string>): Promise<unknown>;
|
|
43
109
|
load(shouldSave?: boolean): Promise<OASDocument>;
|
|
44
110
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* | // installed, when it was installed, what the original source was,
|
|
49
|
-
* | // and what version of `api` was used.
|
|
50
|
-
* └── apis/
|
|
51
|
-
* ├── readme/
|
|
52
|
-
* | ├── node_modules/
|
|
53
|
-
* │ ├── index.js // We may offer the option to export a raw TS file for folks who want
|
|
54
|
-
* | | // that, but for now it'll be a compiled JS file.
|
|
55
|
-
* │ ├── index.d.ts // All types for their SDK, ready to use in an IDE.
|
|
56
|
-
* │ |── openapi.json
|
|
57
|
-
* │ └── package.json
|
|
58
|
-
* └── petstore/
|
|
59
|
-
* ├── node_modules/
|
|
60
|
-
* ├── index.js
|
|
61
|
-
* ├── index.d.ts
|
|
62
|
-
* ├── openapi.json
|
|
63
|
-
* └── package.json
|
|
111
|
+
* Initialize a directory in the storage system for this identifier and add it into the lockfile.
|
|
112
|
+
* This does not create or save the source code for this SDK, that work happens within the
|
|
113
|
+
* code generation system.
|
|
64
114
|
*
|
|
115
|
+
* @see {@link https://api.readme.dev/docs/how-it-works#api-directory}
|
|
65
116
|
*/
|
|
66
117
|
save(spec: OASDocument): OASDocument;
|
|
67
|
-
}
|
|
68
|
-
interface Lockfile {
|
|
69
|
-
apis: LockfileAPI[];
|
|
70
118
|
/**
|
|
71
|
-
*
|
|
72
|
-
* this store.
|
|
73
|
-
*/
|
|
74
|
-
version: '1.0';
|
|
75
|
-
}
|
|
76
|
-
interface 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>`.
|
|
119
|
+
* Delete the stored source code for the given identifier and purge it from the lockfile.
|
|
80
120
|
*
|
|
81
|
-
* @example petstore
|
|
82
121
|
*/
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* The version of `api` that was used to install this SDK.
|
|
86
|
-
*
|
|
87
|
-
* @example 5.0.0
|
|
88
|
-
*/
|
|
89
|
-
installerVersion: string;
|
|
90
|
-
/**
|
|
91
|
-
* An integrity hash that will be used to determine on `npx api update` calls if the API has
|
|
92
|
-
* changed since the SDK was last generated.
|
|
93
|
-
*
|
|
94
|
-
* @example sha512-ld+djZk8uRWmzXC+JYla1PTBScg0NjP/8x9vOOKRW+DuJ3NNMRjrpfbY7T77Jgnc87dZZsU49robbQfYe3ukug==
|
|
95
|
-
*/
|
|
96
|
-
integrity: string;
|
|
97
|
-
/**
|
|
98
|
-
* The original source that was used to generate the SDK with.
|
|
99
|
-
*
|
|
100
|
-
* @example https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json
|
|
101
|
-
* @example ./petstore.json
|
|
102
|
-
* @example @developers/v2.0#nysezql0wwo236
|
|
103
|
-
*/
|
|
104
|
-
source: string;
|
|
122
|
+
remove(): Promise<void>;
|
|
105
123
|
}
|
|
106
|
-
export {};
|
|
107
124
|
//# sourceMappingURL=storage.d.ts.map
|
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,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AU,EAAE,MAAM;;;;;;;;;;IAKzC,cAAc;IAQd,cAAc;IASd,uBAAuB;IAQvB,oBAAoB;IAIpB,gBAAgB;IAWhB,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IA4BvC,IAAI,CAAC,UAAU,GAAE,OAAc;IAUrC;;;;;;OAMG;IACH,IAAI,CAAC,IAAI,EAAE,WAAW;IAgDtB;;;OAGG;IACG,MAAM;CAkBb"}
|
package/dist/storage.js
CHANGED
|
@@ -1,26 +1,42 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import semver from 'semver';
|
|
3
4
|
import ssri from 'ssri';
|
|
4
5
|
import validateNPMPackageName from 'validate-npm-package-name';
|
|
6
|
+
import { SupportedLanguages } from './codegen/factory.js';
|
|
5
7
|
import Fetcher from './fetcher.js';
|
|
6
8
|
import { PACKAGE_VERSION } from './packageInfo.js';
|
|
7
9
|
export default class Storage {
|
|
8
10
|
static dir;
|
|
9
11
|
static lockfile;
|
|
12
|
+
fetcher;
|
|
10
13
|
/**
|
|
11
14
|
* This is the original source that the file came from (relative/absolute file path, URL, ReadMe
|
|
12
15
|
* registry UUID, etc.).
|
|
16
|
+
*
|
|
17
|
+
* @example @developers/v2.0#nysezql0wwo236
|
|
18
|
+
* @example https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json
|
|
19
|
+
* @example ./petstore.json
|
|
13
20
|
*/
|
|
14
21
|
source;
|
|
22
|
+
/**
|
|
23
|
+
* The language that this SDK was generated for.
|
|
24
|
+
*/
|
|
25
|
+
language;
|
|
26
|
+
/**
|
|
27
|
+
* The identifier that this was installed as.
|
|
28
|
+
*
|
|
29
|
+
* @example petstore
|
|
30
|
+
*/
|
|
15
31
|
identifier;
|
|
16
|
-
|
|
17
|
-
constructor(source, identifier) {
|
|
32
|
+
constructor(source, language, identifier) {
|
|
18
33
|
Storage.setStorageDir();
|
|
19
34
|
this.fetcher = new Fetcher(source);
|
|
20
35
|
this.source = source;
|
|
21
|
-
if (
|
|
36
|
+
if (language)
|
|
37
|
+
this.language = language;
|
|
38
|
+
if (identifier)
|
|
22
39
|
this.identifier = identifier;
|
|
23
|
-
}
|
|
24
40
|
// This should default to false so we have awareness if we've looked at the lockfile yet.
|
|
25
41
|
Storage.lockfile = false;
|
|
26
42
|
}
|
|
@@ -48,19 +64,28 @@ export default class Storage {
|
|
|
48
64
|
* Reset the state of the entire storage system.
|
|
49
65
|
*
|
|
50
66
|
* This will completely destroy the contents of the `.api/` directory!
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
51
69
|
*/
|
|
52
70
|
static async reset() {
|
|
71
|
+
const noop = () => {
|
|
72
|
+
// If any of these file and directory removals fail we don't need to throw any errors because
|
|
73
|
+
// this method is only used internally in unit tests.
|
|
74
|
+
};
|
|
53
75
|
if (Storage.getLockfilePath()) {
|
|
54
|
-
await fs.promises
|
|
76
|
+
await fs.promises
|
|
77
|
+
.writeFile(Storage.getLockfilePath(), JSON.stringify(Storage.getDefaultLockfile(), null, 2))
|
|
78
|
+
.catch(noop);
|
|
55
79
|
}
|
|
56
80
|
if (Storage.getAPIsDir()) {
|
|
57
|
-
await fs.promises.rm(Storage.getAPIsDir(), { recursive: true });
|
|
58
|
-
await fs.promises.mkdir(Storage.getAPIsDir(), { recursive: true });
|
|
81
|
+
await fs.promises.rm(Storage.getAPIsDir(), { recursive: true }).catch(noop);
|
|
82
|
+
await fs.promises.mkdir(Storage.getAPIsDir(), { recursive: true }).catch(noop);
|
|
59
83
|
}
|
|
60
84
|
}
|
|
61
85
|
static getDefaultLockfile() {
|
|
86
|
+
const majorVersion = semver.parse(PACKAGE_VERSION)?.major || 'latest';
|
|
62
87
|
return {
|
|
63
|
-
|
|
88
|
+
$schema: `https://unpkg.com/api@${majorVersion}/schema.json`,
|
|
64
89
|
apis: [],
|
|
65
90
|
};
|
|
66
91
|
}
|
|
@@ -77,7 +102,15 @@ export default class Storage {
|
|
|
77
102
|
}
|
|
78
103
|
if (fs.existsSync(Storage.getLockfilePath())) {
|
|
79
104
|
const file = fs.readFileSync(Storage.getLockfilePath(), 'utf8');
|
|
80
|
-
|
|
105
|
+
try {
|
|
106
|
+
Storage.lockfile = JSON.parse(file);
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
// If we can't parse the lock file for whatever reason then it's probably corrupted so we
|
|
111
|
+
// should reset it to the default.
|
|
112
|
+
Storage.lockfile = Storage.getDefaultLockfile();
|
|
113
|
+
}
|
|
81
114
|
}
|
|
82
115
|
else {
|
|
83
116
|
Storage.lockfile = Storage.getDefaultLockfile();
|
|
@@ -116,6 +149,15 @@ export default class Storage {
|
|
|
116
149
|
});
|
|
117
150
|
return res === undefined ? false : res;
|
|
118
151
|
}
|
|
152
|
+
setLanguage(language) {
|
|
153
|
+
// `language` wasn't always present in the lockfile so if we don't have one we should default
|
|
154
|
+
// to JS.
|
|
155
|
+
if (!language) {
|
|
156
|
+
this.language = SupportedLanguages.JS;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this.language = language;
|
|
160
|
+
}
|
|
119
161
|
setIdentifier(identifier) {
|
|
120
162
|
this.identifier = identifier;
|
|
121
163
|
}
|
|
@@ -127,20 +169,51 @@ export default class Storage {
|
|
|
127
169
|
}
|
|
128
170
|
/**
|
|
129
171
|
* Retrieve the lockfile record for the current spec + identifier if it exists in the lockfile.
|
|
172
|
+
*
|
|
130
173
|
*/
|
|
131
174
|
getFromLockfile() {
|
|
132
175
|
const lockfile = Storage.getLockfile();
|
|
133
176
|
return lockfile.apis.find(a => a.identifier === this.identifier);
|
|
134
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Retrieve the lockfile record, if it exists, for a given identifier.
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
static getFromLockfile(identifier) {
|
|
183
|
+
const lockfile = Storage.getLockfile();
|
|
184
|
+
return lockfile.apis.find(a => a.identifier === identifier);
|
|
185
|
+
}
|
|
186
|
+
getSDKLanguage() {
|
|
187
|
+
const entry = this.getFromLockfile();
|
|
188
|
+
// We may not have `language` in the lockfile for old users but we default to JS so we can
|
|
189
|
+
// safely return that if this isn't present.
|
|
190
|
+
return entry?.language || SupportedLanguages.JS;
|
|
191
|
+
}
|
|
192
|
+
getPackageName() {
|
|
193
|
+
const entry = this.getFromLockfile();
|
|
194
|
+
if (entry?.private) {
|
|
195
|
+
return `@api/${entry.identifier}`;
|
|
196
|
+
}
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
135
199
|
getIdentifierStorageDir() {
|
|
136
200
|
if (!this.isInLockfile()) {
|
|
137
201
|
throw new Error(`${this.source} has not been saved to storage yet and must do so before being retrieved.`);
|
|
138
202
|
}
|
|
139
203
|
return path.join(Storage.getAPIsDir(), this.identifier);
|
|
140
204
|
}
|
|
205
|
+
getAPIDefinitionPath() {
|
|
206
|
+
return path.join(this.getIdentifierStorageDir(), 'openapi.json');
|
|
207
|
+
}
|
|
141
208
|
getAPIDefinition() {
|
|
142
|
-
const
|
|
143
|
-
|
|
209
|
+
const filePath = this.getAPIDefinitionPath();
|
|
210
|
+
const file = fs.readFileSync(filePath, 'utf8');
|
|
211
|
+
try {
|
|
212
|
+
return JSON.parse(file);
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
throw new Error(`Sorry we were unable to parse JSON in ${filePath}. Reason: ${err.message}`);
|
|
216
|
+
}
|
|
144
217
|
}
|
|
145
218
|
saveSourceFiles(files) {
|
|
146
219
|
if (!this.isInLockfile()) {
|
|
@@ -173,31 +246,19 @@ export default class Storage {
|
|
|
173
246
|
});
|
|
174
247
|
}
|
|
175
248
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* | // installed, when it was installed, what the original source was,
|
|
180
|
-
* | // and what version of `api` was used.
|
|
181
|
-
* └── apis/
|
|
182
|
-
* ├── readme/
|
|
183
|
-
* | ├── node_modules/
|
|
184
|
-
* │ ├── index.js // We may offer the option to export a raw TS file for folks who want
|
|
185
|
-
* | | // that, but for now it'll be a compiled JS file.
|
|
186
|
-
* │ ├── index.d.ts // All types for their SDK, ready to use in an IDE.
|
|
187
|
-
* │ |── openapi.json
|
|
188
|
-
* │ └── package.json
|
|
189
|
-
* └── petstore/
|
|
190
|
-
* ├── node_modules/
|
|
191
|
-
* ├── index.js
|
|
192
|
-
* ├── index.d.ts
|
|
193
|
-
* ├── openapi.json
|
|
194
|
-
* └── package.json
|
|
249
|
+
* Initialize a directory in the storage system for this identifier and add it into the lockfile.
|
|
250
|
+
* This does not create or save the source code for this SDK, that work happens within the
|
|
251
|
+
* code generation system.
|
|
195
252
|
*
|
|
253
|
+
* @see {@link https://api.readme.dev/docs/how-it-works#api-directory}
|
|
196
254
|
*/
|
|
197
255
|
save(spec) {
|
|
198
256
|
if (!this.identifier) {
|
|
199
257
|
throw new TypeError('An identifier must be set before saving the API definition into storage.');
|
|
200
258
|
}
|
|
259
|
+
else if (!this.language) {
|
|
260
|
+
throw new TypeError('A language must be set before saving the API definition into storage.');
|
|
261
|
+
}
|
|
201
262
|
// Create our main `.api/` directory.
|
|
202
263
|
if (!fs.existsSync(Storage.dir)) {
|
|
203
264
|
fs.mkdirSync(Storage.dir, { recursive: true });
|
|
@@ -217,10 +278,13 @@ export default class Storage {
|
|
|
217
278
|
fs.mkdirSync(identifierStorageDir, { recursive: true });
|
|
218
279
|
}
|
|
219
280
|
Storage.lockfile.apis.push({
|
|
281
|
+
private: true,
|
|
220
282
|
identifier: this.identifier,
|
|
221
283
|
source: this.source,
|
|
222
284
|
integrity: Storage.generateIntegrityHash(spec),
|
|
223
285
|
installerVersion: PACKAGE_VERSION,
|
|
286
|
+
language: this.language,
|
|
287
|
+
createdAt: new Date().toISOString(),
|
|
224
288
|
});
|
|
225
289
|
fs.writeFileSync(path.join(identifierStorageDir, 'openapi.json'), saved);
|
|
226
290
|
fs.writeFileSync(Storage.getLockfilePath(), JSON.stringify(Storage.lockfile, null, 2));
|
|
@@ -230,5 +294,23 @@ export default class Storage {
|
|
|
230
294
|
}
|
|
231
295
|
return spec;
|
|
232
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Delete the stored source code for the given identifier and purge it from the lockfile.
|
|
299
|
+
*
|
|
300
|
+
*/
|
|
301
|
+
async remove() {
|
|
302
|
+
// Delete the codegen'd SDK source code.
|
|
303
|
+
const identifierDir = this.getIdentifierStorageDir();
|
|
304
|
+
await fs.promises.rm(identifierDir, { recursive: true }).catch(() => {
|
|
305
|
+
// If the identifier directory doesn't exist for some reason we can continue on and remove it
|
|
306
|
+
// from the lockfile because some sort of corruption happened.
|
|
307
|
+
});
|
|
308
|
+
// Remove the SDK from the lockfile.
|
|
309
|
+
const lockfile = Storage.lockfile;
|
|
310
|
+
const idx = lockfile.apis.findIndex(api => api.identifier === this.identifier);
|
|
311
|
+
lockfile.apis.splice(idx, 1);
|
|
312
|
+
Storage.lockfile = lockfile;
|
|
313
|
+
fs.writeFileSync(Storage.getLockfilePath(), JSON.stringify(Storage.lockfile, null, 2));
|
|
314
|
+
}
|
|
233
315
|
}
|
|
234
316
|
//# sourceMappingURL=storage.js.map
|
package/dist/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,sBAAsB,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,OAAO,M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,CAAC;aAAM,CAAC;YACN,4EAA4E;QAC9E,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM;QACV,wCAAwC;QACxC,MAAM,aAAa,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACrD,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YAClE,6FAA6F;YAC7F,8DAA8D;QAChE,CAAC,CAAC,CAAC;QAEH,oCAAoC;QACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAoB,CAAC;QAC9C,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;QAE/E,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAE7B,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAE5B,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACzF,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/* eslint-disable import/no-commonjs */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* In `api` v6, this package was a JS library used JavaScript Proxies to dynamically generate SDKs at runtime.
|
|
6
|
+
* This functionality has been sunset in `api` v7 to focus on its CLI, which builds strongly-typed SDKs.
|
|
7
|
+
* This file is here to throw errors for users that attempt to use the legacy library.
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} input
|
|
11
|
+
*/
|
|
12
|
+
module.exports = function legacyHandler(input) {
|
|
13
|
+
let identifier = 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json';
|
|
14
|
+
|
|
15
|
+
if (typeof input === 'string') {
|
|
16
|
+
identifier = input;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
throw new Error(`Oops! You're attempting to use a legacy usage pattern that no longer exists.
|
|
20
|
+
|
|
21
|
+
You can read more about this in our docs: TKTK
|
|
22
|
+
|
|
23
|
+
\`api\` can now generate strongly-typed SDKs that work in pretty much every JS runtime!
|
|
24
|
+
|
|
25
|
+
Try running this command to get started:
|
|
26
|
+
|
|
27
|
+
npx api@latest install ${identifier}
|
|
28
|
+
`);
|
|
29
|
+
};
|
package/package.json
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.10",
|
|
4
4
|
"description": "Magical SDK generation from an OpenAPI definition 🪄",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"api": "bin/api.js"
|
|
8
8
|
},
|
|
9
|
+
"main": "legacy-require-handler.cjs",
|
|
9
10
|
"scripts": {
|
|
10
11
|
"attw": "attw --pack --format table-flipped",
|
|
11
12
|
"build": "tsc",
|
|
12
|
-
"
|
|
13
|
+
"build:legacy-handler": "tsc legacy-require-handler.cjs --checkJs --declaration --emitDeclarationOnly",
|
|
14
|
+
"build:versioned-files": "tsx bin/buildVersionedFiles.ts",
|
|
15
|
+
"debug:bin": "tsx src/bin.ts",
|
|
13
16
|
"lint:types": "tsc --noEmit",
|
|
14
|
-
"prebuild": "rm -rf dist
|
|
17
|
+
"prebuild": "rm -rf dist/ && npm run build:versioned-files",
|
|
18
|
+
"postbuild": "npm run build:legacy-handler",
|
|
15
19
|
"prepack": "npm run build",
|
|
16
20
|
"test": "vitest run --coverage",
|
|
17
|
-
"test:smoke": "vitest --config=vitest-smoketest.config.ts
|
|
18
|
-
"version": "
|
|
21
|
+
"test:smoke": "vitest --config=vitest-smoketest.config.ts",
|
|
22
|
+
"version": "npm run build:versioned-files && git add schema.json src/packageInfo.ts"
|
|
19
23
|
},
|
|
20
24
|
"repository": {
|
|
21
25
|
"type": "git",
|
|
@@ -31,6 +35,11 @@
|
|
|
31
35
|
"engines": {
|
|
32
36
|
"node": ">=18"
|
|
33
37
|
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"legacy-require-handler.**",
|
|
41
|
+
"schema.json"
|
|
42
|
+
],
|
|
34
43
|
"keywords": [
|
|
35
44
|
"api",
|
|
36
45
|
"openapi",
|
|
@@ -38,48 +47,53 @@
|
|
|
38
47
|
"swagger"
|
|
39
48
|
],
|
|
40
49
|
"dependencies": {
|
|
41
|
-
"@readme/api-core": "^7.0.0-beta.
|
|
50
|
+
"@readme/api-core": "^7.0.0-beta.10",
|
|
42
51
|
"@readme/openapi-parser": "^2.4.0",
|
|
43
52
|
"chalk": "^5.3.0",
|
|
44
|
-
"
|
|
53
|
+
"ci-info": "^4.0.0",
|
|
54
|
+
"commander": "^12.1.0",
|
|
55
|
+
"emphasize": "^7.0.0",
|
|
45
56
|
"execa": "^8.0.1",
|
|
46
|
-
"figures": "^
|
|
57
|
+
"figures": "^6.0.1",
|
|
58
|
+
"httpsnippet-client-api": "^7.0.0-beta.9",
|
|
47
59
|
"js-yaml": "^4.1.0",
|
|
48
|
-
"
|
|
49
|
-
"lodash
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"ora": "^7.0.1",
|
|
60
|
+
"license": "^1.0.3",
|
|
61
|
+
"lodash-es": "^4.17.21",
|
|
62
|
+
"oas": "^25.0.1",
|
|
63
|
+
"ora": "^8.0.1",
|
|
64
|
+
"preferred-pm": "^4.0.0",
|
|
54
65
|
"prompts": "^2.4.2",
|
|
55
66
|
"semver": "^7.3.8",
|
|
56
|
-
"ssri": "^
|
|
57
|
-
"ts-morph": "^
|
|
67
|
+
"ssri": "^12.0.0",
|
|
68
|
+
"ts-morph": "^23.0.0",
|
|
69
|
+
"update-notifier": "^7.0.0",
|
|
58
70
|
"uslug": "^1.0.4",
|
|
59
|
-
"validate-npm-package-name": "^
|
|
71
|
+
"validate-npm-package-name": "^6.0.0"
|
|
60
72
|
},
|
|
61
73
|
"devDependencies": {
|
|
62
|
-
"@api/test-utils": "^7.0.0-beta.
|
|
63
|
-
"@readme/oas-examples": "^5.12.
|
|
64
|
-
"@types/js-yaml": "^4.0.
|
|
65
|
-
"@types/lodash
|
|
66
|
-
"@types/
|
|
67
|
-
"@types/
|
|
68
|
-
"@types/
|
|
69
|
-
"@types/
|
|
70
|
-
"@types/
|
|
71
|
-
"@types/
|
|
72
|
-
"@
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"fetch-mock": "^
|
|
74
|
+
"@api/test-utils": "^7.0.0-beta.10",
|
|
75
|
+
"@readme/oas-examples": "^5.12.1",
|
|
76
|
+
"@types/js-yaml": "^4.0.9",
|
|
77
|
+
"@types/lodash-es": "^4.17.12",
|
|
78
|
+
"@types/prompts": "^2.4.9",
|
|
79
|
+
"@types/semver": "^7.5.6",
|
|
80
|
+
"@types/ssri": "^7.1.5",
|
|
81
|
+
"@types/update-notifier": "^6.0.8",
|
|
82
|
+
"@types/uslug": "^1.0.4",
|
|
83
|
+
"@types/validate-npm-package-name": "^4.0.2",
|
|
84
|
+
"@vitest/coverage-v8": "^2.1.3",
|
|
85
|
+
"ajv": "^8.12.0",
|
|
86
|
+
"ajv-formats": "^3.0.1",
|
|
87
|
+
"fetch-mock": "^11.1.3",
|
|
76
88
|
"oas-normalize": "^11.0.1",
|
|
77
|
-
"
|
|
78
|
-
"
|
|
89
|
+
"openapi-types": "^12.1.3",
|
|
90
|
+
"tsup": "^8.0.1",
|
|
91
|
+
"tsx": "^4.19.1",
|
|
92
|
+
"type-fest": "^4.9.0",
|
|
79
93
|
"typescript": "^5.2.2",
|
|
80
94
|
"unique-temp-dir": "^1.0.0",
|
|
81
|
-
"vitest": "^
|
|
95
|
+
"vitest": "^2.1.3"
|
|
82
96
|
},
|
|
83
97
|
"prettier": "@readme/eslint-config/prettier",
|
|
84
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "4a34d5d4642a94928bd4c299d8c45c6b64ee6f20"
|
|
85
99
|
}
|