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/README.md
CHANGED
|
@@ -39,8 +39,7 @@ petstore.listPets().then(({ data }) => {
|
|
|
39
39
|
The ESM syntax is supported as well:
|
|
40
40
|
|
|
41
41
|
```js
|
|
42
|
-
import
|
|
43
|
-
const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8');
|
|
42
|
+
import petstore from '@api/petstore';
|
|
44
43
|
|
|
45
44
|
petstore.listPets().then(({ data }) => {
|
|
46
45
|
console.log(`My pets name is ${data[0].name}!`);
|
package/dist/bin.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import updateNotifier from 'update-notifier';
|
|
2
3
|
import commands from './commands/index.js';
|
|
4
|
+
import logger from './logger.js';
|
|
3
5
|
import * as pkg from './packageInfo.js';
|
|
6
|
+
updateNotifier({ pkg: { name: pkg.PACKAGE_NAME, version: pkg.PACKAGE_VERSION } }).notify();
|
|
4
7
|
(async () => {
|
|
5
8
|
const program = new Command();
|
|
6
9
|
program.name(pkg.PACKAGE_NAME);
|
|
@@ -13,6 +16,10 @@ import * as pkg from './packageInfo.js';
|
|
|
13
16
|
Object.entries(commands).forEach(([, cmd]) => {
|
|
14
17
|
program.addCommand(cmd);
|
|
15
18
|
});
|
|
16
|
-
await program.parseAsync(process.argv)
|
|
19
|
+
await program.parseAsync(process.argv).catch(err => {
|
|
20
|
+
if (err.message)
|
|
21
|
+
logger(err.message, true);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
});
|
|
17
24
|
})();
|
|
18
25
|
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAE7C,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAExC,cAAc,CAAC,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,GAAG,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAE3F,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAErC;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAoB,EAAE,EAAE;QAC9D,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACjD,IAAI,GAAG,CAAC,OAAO;YAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -1,31 +1,64 @@
|
|
|
1
|
+
import type { InstallerOptions } from './factory.js';
|
|
1
2
|
import type Storage from '../storage.js';
|
|
2
3
|
import type Oas from 'oas';
|
|
3
|
-
export
|
|
4
|
+
export default abstract class CodeGenerator {
|
|
5
|
+
/** The associated API definition */
|
|
6
|
+
spec: Oas;
|
|
4
7
|
/**
|
|
5
|
-
*
|
|
8
|
+
* The path to the API definion (might be a local path, a URL, or an API registry identifier)
|
|
9
|
+
* @example https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json
|
|
10
|
+
* @example @petstore/v1.0#n6kvf10vakpemvplx
|
|
11
|
+
* @example ./petstore.json
|
|
6
12
|
*/
|
|
7
|
-
|
|
13
|
+
specPath: string;
|
|
8
14
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
15
|
+
* The user-specified identifier for the SDK,
|
|
16
|
+
* used as the directory name in the `.api/apis` directory
|
|
17
|
+
* where the SDK source code is located.
|
|
11
18
|
*/
|
|
12
|
-
logger?: (msg: string) => void;
|
|
13
|
-
}
|
|
14
|
-
export default abstract class CodeGenerator {
|
|
15
|
-
spec: Oas;
|
|
16
|
-
specPath: string;
|
|
17
19
|
identifier: string;
|
|
20
|
+
/** The user agent which is set for all outgoing fetch requests */
|
|
18
21
|
userAgent: string;
|
|
22
|
+
/**
|
|
23
|
+
* The license associated with the SDK.
|
|
24
|
+
* This is extrapolated from the API definition file.
|
|
25
|
+
*/
|
|
26
|
+
spdxLicense?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Contact info for the API and/or SDK author in case users need support.
|
|
29
|
+
* This is extrapolated from the API definition file.
|
|
30
|
+
*/
|
|
31
|
+
apiContact: {
|
|
32
|
+
name?: string;
|
|
33
|
+
url?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* An object containing any downstream packages that are required
|
|
37
|
+
* for building/executing the SDK.
|
|
38
|
+
*/
|
|
19
39
|
requiredPackages: Record<string, {
|
|
20
|
-
dependencyType: '
|
|
40
|
+
dependencyType: 'development' | 'production';
|
|
21
41
|
reason: string;
|
|
22
42
|
url?: string;
|
|
23
43
|
version: string;
|
|
24
44
|
}>;
|
|
45
|
+
/**
|
|
46
|
+
* An example code snippet that a user can run to get started with the SDK.
|
|
47
|
+
*/
|
|
48
|
+
exampleCodeSnippet?: string | false;
|
|
25
49
|
constructor(spec: Oas, specPath: string, identifier: string);
|
|
26
50
|
abstract generate(): Promise<Record<string, string>>;
|
|
27
51
|
abstract install(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* It would be better if this were an abstract function but TS/JS doesn't have support for that so
|
|
54
|
+
* we instead have to rely on throwing a `TypeError` if it's not been implemented instead of a
|
|
55
|
+
* build-time error.
|
|
56
|
+
*
|
|
57
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/34516}
|
|
58
|
+
*/
|
|
59
|
+
static uninstall(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
28
60
|
abstract compile(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
61
|
+
abstract getExampleCodeSnippet(): Promise<string | false>;
|
|
29
62
|
hasRequiredPackages(): boolean;
|
|
30
63
|
}
|
|
31
64
|
//# sourceMappingURL=codegenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegenerator.d.ts","sourceRoot":"","sources":["../../src/codegen/codegenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"codegenerator.d.ts","sourceRoot":"","sources":["../../src/codegen/codegenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAO3B,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,aAAa;IACzC,oCAAoC;IACpC,IAAI,EAAE,GAAG,CAAC;IAEV;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,UAAU,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAM;IAEjD;;;OAGG;IACH,gBAAgB,EAAG,MAAM,CACvB,MAAM,EACN;QACE,cAAc,EAAE,aAAa,GAAG,YAAY,CAAC;QAC7C,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CACF,CAAC;IAEF;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;gBAExB,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAgE3D,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEpD,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1E;;;;;;OAMG;WAEU,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhF,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1E,QAAQ,CAAC,qBAAqB,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;IAEzD,mBAAmB;CAGpB"}
|
|
@@ -1,10 +1,42 @@
|
|
|
1
|
+
import { findLicense } from 'license';
|
|
1
2
|
import { PACKAGE_NAME, PACKAGE_VERSION } from '../packageInfo.js';
|
|
2
3
|
export default class CodeGenerator {
|
|
4
|
+
/** The associated API definition */
|
|
3
5
|
spec;
|
|
6
|
+
/**
|
|
7
|
+
* The path to the API definion (might be a local path, a URL, or an API registry identifier)
|
|
8
|
+
* @example https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json
|
|
9
|
+
* @example @petstore/v1.0#n6kvf10vakpemvplx
|
|
10
|
+
* @example ./petstore.json
|
|
11
|
+
*/
|
|
4
12
|
specPath;
|
|
13
|
+
/**
|
|
14
|
+
* The user-specified identifier for the SDK,
|
|
15
|
+
* used as the directory name in the `.api/apis` directory
|
|
16
|
+
* where the SDK source code is located.
|
|
17
|
+
*/
|
|
5
18
|
identifier;
|
|
19
|
+
/** The user agent which is set for all outgoing fetch requests */
|
|
6
20
|
userAgent;
|
|
21
|
+
/**
|
|
22
|
+
* The license associated with the SDK.
|
|
23
|
+
* This is extrapolated from the API definition file.
|
|
24
|
+
*/
|
|
25
|
+
spdxLicense;
|
|
26
|
+
/**
|
|
27
|
+
* Contact info for the API and/or SDK author in case users need support.
|
|
28
|
+
* This is extrapolated from the API definition file.
|
|
29
|
+
*/
|
|
30
|
+
apiContact = {};
|
|
31
|
+
/**
|
|
32
|
+
* An object containing any downstream packages that are required
|
|
33
|
+
* for building/executing the SDK.
|
|
34
|
+
*/
|
|
7
35
|
requiredPackages;
|
|
36
|
+
/**
|
|
37
|
+
* An example code snippet that a user can run to get started with the SDK.
|
|
38
|
+
*/
|
|
39
|
+
exampleCodeSnippet;
|
|
8
40
|
constructor(spec, specPath, identifier) {
|
|
9
41
|
this.spec = spec;
|
|
10
42
|
this.specPath = specPath;
|
|
@@ -27,6 +59,51 @@ export default class CodeGenerator {
|
|
|
27
59
|
if (JSON.stringify(spec.api).includes('"$ref":"#/')) {
|
|
28
60
|
throw new Error('Sorry, this library does not yet support generating an SDK for an OpenAPI definition that contains circular references.');
|
|
29
61
|
}
|
|
62
|
+
const infoObject = this.spec.api.info;
|
|
63
|
+
if (infoObject?.license?.name || infoObject?.license?.identifier) {
|
|
64
|
+
let spdxLicense;
|
|
65
|
+
if (infoObject?.license?.identifier) {
|
|
66
|
+
spdxLicense = infoObject?.license?.identifier;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Though `name` is required by the OpenAPI specification but most people seem to use `name`
|
|
70
|
+
// instead `identifier` for their licensing identifier so if they've done this we should
|
|
71
|
+
// try to make the license name recognizable by the `license` package. For example this'll
|
|
72
|
+
// change "Apache 2.0" to the SPDX-recognized "Apache-2.0".
|
|
73
|
+
spdxLicense = infoObject?.license?.name.replace(/ /g, '-');
|
|
74
|
+
}
|
|
75
|
+
// If the license they've got has too many matches we shouldn't try to pick a license because
|
|
76
|
+
// we'll run the risk of licensing it under a license they didn't intend.
|
|
77
|
+
if (findLicense(spdxLicense).length === 1) {
|
|
78
|
+
this.spdxLicense = spdxLicense;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (infoObject?.contact) {
|
|
82
|
+
if (infoObject.contact?.name || infoObject.contact?.email) {
|
|
83
|
+
if (infoObject.contact?.name && infoObject.contact?.email) {
|
|
84
|
+
this.apiContact.name = `${infoObject.contact.name} <${infoObject.contact.email}>`;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.apiContact.name = infoObject.contact.email
|
|
88
|
+
? `<${infoObject.contact.email}>`
|
|
89
|
+
: (infoObject.contact.name ?? undefined);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (infoObject.contact?.url) {
|
|
93
|
+
this.apiContact.url = infoObject.contact.url;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* It would be better if this were an abstract function but TS/JS doesn't have support for that so
|
|
99
|
+
* we instead have to rely on throwing a `TypeError` if it's not been implemented instead of a
|
|
100
|
+
* build-time error.
|
|
101
|
+
*
|
|
102
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/34516}
|
|
103
|
+
*/
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
105
|
+
static async uninstall(storage, opts) {
|
|
106
|
+
throw new TypeError('The uninstallation step for this language has not been implemented');
|
|
30
107
|
}
|
|
31
108
|
hasRequiredPackages() {
|
|
32
109
|
return Boolean(Object.keys(this.requiredPackages));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegenerator.js","sourceRoot":"","sources":["../../src/codegen/codegenerator.ts"],"names":[],"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C,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;IAMD;;;;;;OAMG;IACH,6DAA6D;IAC7D,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAgB,EAAE,IAAuB;QAC9D,MAAM,IAAI,SAAS,CAAC,oEAAoE,CAAC,CAAC;IAC5F,CAAC;IAMD,mBAAmB;QACjB,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import type CodeGenerator from './codegenerator.js';
|
|
2
|
+
import type Storage from '../storage.js';
|
|
2
3
|
import type Oas from 'oas';
|
|
3
|
-
export declare
|
|
4
|
-
JS
|
|
4
|
+
export declare const SupportedLanguages: {
|
|
5
|
+
readonly JS: "js";
|
|
6
|
+
};
|
|
7
|
+
type ObjectValues<T> = T[keyof T];
|
|
8
|
+
export type SupportedLanguage = ObjectValues<typeof SupportedLanguages>;
|
|
9
|
+
export interface InstallerOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Will initiate a dry run install process. Used for simulating installations within a unit test.
|
|
12
|
+
*/
|
|
13
|
+
dryRun?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Used for stubbing out the logger that we use within the installation process so it can be
|
|
16
|
+
* easily introspected without having to mock out `console.*`.
|
|
17
|
+
*/
|
|
18
|
+
logger?: (msg: string) => void;
|
|
5
19
|
}
|
|
6
|
-
export
|
|
20
|
+
export declare function codegenFactory(language: SupportedLanguage, spec: Oas, specPath: string, identifier: string): CodeGenerator;
|
|
21
|
+
export declare function uninstallerFactory(language: SupportedLanguage, storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
22
|
+
export {};
|
|
7
23
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/codegen/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAI3B,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/codegen/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAI3B,eAAO,MAAM,kBAAkB;;CAErB,CAAC;AAEX,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAElC,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,aAAa,CAQf;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,OAAO,EAChB,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAQf"}
|
package/dist/codegen/factory.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import TSGenerator from './languages/typescript/index.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default function codegenFactory(language, spec, specPath, identifier) {
|
|
2
|
+
export const SupportedLanguages = {
|
|
3
|
+
JS: 'js',
|
|
4
|
+
};
|
|
5
|
+
export function codegenFactory(language, spec, specPath, identifier) {
|
|
7
6
|
switch (language) {
|
|
8
7
|
case SupportedLanguages.JS:
|
|
9
8
|
return new TSGenerator(spec, specPath, identifier);
|
|
@@ -11,4 +10,12 @@ export default function codegenFactory(language, spec, specPath, identifier) {
|
|
|
11
10
|
throw new TypeError(`Unsupported language supplied: ${language}`);
|
|
12
11
|
}
|
|
13
12
|
}
|
|
13
|
+
export function uninstallerFactory(language, storage, opts = {}) {
|
|
14
|
+
switch (language) {
|
|
15
|
+
case SupportedLanguages.JS:
|
|
16
|
+
return TSGenerator.uninstall(storage, opts);
|
|
17
|
+
default:
|
|
18
|
+
throw new TypeError(`Unsupported language supplied: ${language}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
14
21
|
//# sourceMappingURL=factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/codegen/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/codegen/factory.ts"],"names":[],"mappings":"AAIA,OAAO,WAAW,MAAM,iCAAiC,CAAC;AAE1D,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,EAAE,EAAE,IAAI;CACA,CAAC;AAmBX,MAAM,UAAU,cAAc,CAC5B,QAA2B,EAC3B,IAAS,EACT,QAAgB,EAChB,UAAkB;IAElB,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,kBAAkB,CAAC,EAAE;YACxB,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;QAErD;YACE,MAAM,IAAI,SAAS,CAAC,kCAAkC,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,QAA2B,EAC3B,OAAgB,EAChB,OAAyB,EAAE;IAE3B,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,kBAAkB,CAAC,EAAE;YACxB,OAAO,WAAW,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE9C;YACE,MAAM,IAAI,SAAS,CAAC,kCAAkC,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { InstallerOptions } from '../../codegenerator.js';
|
|
1
|
+
import type { InstallerOptions } from '../../factory.js';
|
|
3
2
|
import type Oas from 'oas';
|
|
4
|
-
import type { ClassDeclaration } from 'ts-morph';
|
|
3
|
+
import type { ClassDeclaration, SourceFile } from 'ts-morph';
|
|
5
4
|
import { Project } from 'ts-morph';
|
|
5
|
+
import Storage from '../../../storage.js';
|
|
6
6
|
import CodeGenerator from '../../codegenerator.js';
|
|
7
7
|
export default class TSGenerator extends CodeGenerator {
|
|
8
8
|
#private;
|
|
@@ -17,6 +17,7 @@ export default class TSGenerator extends CodeGenerator {
|
|
|
17
17
|
usesHTTPMethodRangeInterface: boolean;
|
|
18
18
|
constructor(spec: Oas, specPath: string, identifier: string);
|
|
19
19
|
install(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
20
|
+
static uninstall(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
20
21
|
/**
|
|
21
22
|
* Compile the TS code we generated into JS for use in CJS and ESM environments.
|
|
22
23
|
*
|
|
@@ -29,21 +30,54 @@ export default class TSGenerator extends CodeGenerator {
|
|
|
29
30
|
generate(): Promise<{
|
|
30
31
|
[x: string]: string;
|
|
31
32
|
}>;
|
|
33
|
+
getExampleCodeSnippet(): Promise<string | false>;
|
|
34
|
+
/**
|
|
35
|
+
* Create our main `index.ts` file that will be the entrypoint for our SDK.
|
|
36
|
+
* This file will be used to export the SDK and any types that are generated.
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
private createIndexSource;
|
|
32
40
|
/**
|
|
33
41
|
* Create our main SDK source file.
|
|
34
42
|
*
|
|
35
43
|
*/
|
|
36
44
|
private createSDKSource;
|
|
45
|
+
/**
|
|
46
|
+
* Create an IIFE export of our SDK in the SDK source file so users can do
|
|
47
|
+
* `import sdk from '<package>'` and have a ready-to-go instance of their SDK -- eliminating them
|
|
48
|
+
* having to create an instance with `new SDK()`.
|
|
49
|
+
*
|
|
50
|
+
* This will also fill our a JSDoc heading on the IIFE we're creating based on various pieces of
|
|
51
|
+
* data that may be present in the OpenAPI definition `info` object.
|
|
52
|
+
*
|
|
53
|
+
* Additionally if a license in `info.license` is recognized by the SPDX we'll also create a
|
|
54
|
+
* `LICENSE` file in for their generated SDK. We're only supporting SPDX-recognized licenses for
|
|
55
|
+
* this because we otherwise have no idea what the license represents and we should be extremely
|
|
56
|
+
* cautious around assuming intent with software licensing.
|
|
57
|
+
*
|
|
58
|
+
* @see {@link https://spdx.org/licenses/}
|
|
59
|
+
*/
|
|
60
|
+
createSDKExport(sourceFile: SourceFile): SourceFile;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a `.gitignore` file to prevent the `dist/` directory from being tracked.
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
createGitIgnore(): SourceFile;
|
|
37
66
|
/**
|
|
38
67
|
* Create the `tsconfig.json` file that will allow this SDK to be compiled for use.
|
|
39
68
|
*
|
|
40
69
|
*/
|
|
41
|
-
createTSConfig():
|
|
70
|
+
createTSConfig(): SourceFile;
|
|
42
71
|
/**
|
|
43
72
|
* Create the `package.json` file that will ultimately make this SDK available to use.
|
|
44
73
|
*
|
|
45
74
|
*/
|
|
46
|
-
createPackageJSON():
|
|
75
|
+
createPackageJSON(): SourceFile;
|
|
76
|
+
/**
|
|
77
|
+
* Create a placeholder `README.md` file in the repository, with information on how to use/administer the SDK.
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
createREADME(): Promise<SourceFile>;
|
|
47
81
|
/**
|
|
48
82
|
* Create our main schemas file. This is where all of the JSON Schema that our TypeScript typing
|
|
49
83
|
* infrastructure sources its data from. Without this there are no types.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/codegen/languages/typescript/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/codegen/languages/typescript/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAK3B,OAAO,KAAK,EACV,gBAAgB,EAMhB,UAAU,EACX,MAAM,UAAU,CAAC;AAYlB,OAAO,EAAmB,OAAO,EAAoD,MAAM,UAAU,CAAC;AAKtG,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,aAAa,MAAM,wBAAwB,CAAC;AA0DnD,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,aAAa;;IACpD,OAAO,EAAE,OAAO,CAAC;IAEjB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE3B,GAAG,EAAG,gBAAgB,CAAC;IAEvB,OAAO,EAAE,MAAM,CACb,MAAM,EAGJ;QACE,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,GAED,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC1B,CAAC;IAEF,4BAA4B,UAAS;gBAEzB,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAiDrD,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;WA2B9D,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAWpF;;;OAGG;IAEG,OAA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