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/schema.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "api storage lockfile",
|
|
4
|
+
"description": "See https://api.readme.dev/docs",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["apis"],
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"$schema": { "type": "string" },
|
|
10
|
+
"apis": { "type": "array", "description": "The list of installed APIs", "items": { "$ref": "#/definitions/api" } }
|
|
11
|
+
},
|
|
12
|
+
"definitions": {
|
|
13
|
+
"api": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"required": ["createdAt", "identifier", "installerVersion", "integrity"],
|
|
16
|
+
"properties": {
|
|
17
|
+
"createdAt": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"format": "date-time",
|
|
20
|
+
"description": "The date that this SDK was installed.",
|
|
21
|
+
"examples": ["2023-10-19T20:35:39.268Z"]
|
|
22
|
+
},
|
|
23
|
+
"identifier": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "A unique identifier of the API. This'll be used to do imports on `@api/<identifier>` and also where the SDK code will be located in `.api/apis/<identifier>`",
|
|
26
|
+
"examples": ["petstore"]
|
|
27
|
+
},
|
|
28
|
+
"installerVersion": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"description": "The version of `api` that was used to install this SDK.",
|
|
31
|
+
"examples": ["7.0.0"]
|
|
32
|
+
},
|
|
33
|
+
"integrity": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"description": "An integrity hash that will be used to determine on `npx api update` calls if the API has changed since the SDK was last generated.",
|
|
36
|
+
"examples": [
|
|
37
|
+
"sha512-otRF5TLMeDczSJlrmWLNDHLfmXg+C98oa/I/X2WWycwngh+a6WsbnjTbfwKGRU5DFbagOn2qX2SRvtBGOBRVGg=="
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"language": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "The language that this SDK was generated for.",
|
|
43
|
+
"default": "js",
|
|
44
|
+
"enum": ["js"]
|
|
45
|
+
},
|
|
46
|
+
"private": {
|
|
47
|
+
"type": "boolean",
|
|
48
|
+
"description": "Was this SDK installed as a private, unpublished, package to the filesystem?"
|
|
49
|
+
},
|
|
50
|
+
"source": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"description": "The original source that was used to generate the SDK with.",
|
|
53
|
+
"examples": [
|
|
54
|
+
"https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json",
|
|
55
|
+
"./petstore.json",
|
|
56
|
+
"@developers/v2.0#nysezql0wwo236"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"updatedAt": {
|
|
60
|
+
"type": "string",
|
|
61
|
+
"format": "date-time",
|
|
62
|
+
"description": "The date that this SDK was last rebuilt or updated.",
|
|
63
|
+
"examples": ["2023-10-19T20:35:39.268Z"]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"additionalProperties": false
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/bin.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
|
|
3
|
-
import commands from './commands/index.js';
|
|
4
|
-
import * as pkg from './packageInfo.js';
|
|
5
|
-
|
|
6
|
-
(async () => {
|
|
7
|
-
const program = new Command();
|
|
8
|
-
program.name(pkg.PACKAGE_NAME);
|
|
9
|
-
program.version(pkg.PACKAGE_VERSION);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Instead of using Commander's `executableDir` API for loading in external command files we're
|
|
13
|
-
* programatically doing it like this because it's cleaner for us to let Commander manage option
|
|
14
|
-
* and argument parsing within this file than having each command manage that itself.
|
|
15
|
-
*/
|
|
16
|
-
Object.entries(commands).forEach(([, cmd]: [string, Command]) => {
|
|
17
|
-
program.addCommand(cmd);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
await program.parseAsync(process.argv);
|
|
21
|
-
})();
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type Storage from '../storage.js';
|
|
2
|
-
import type Oas from 'oas';
|
|
3
|
-
|
|
4
|
-
import { PACKAGE_NAME, PACKAGE_VERSION } from '../packageInfo.js';
|
|
5
|
-
|
|
6
|
-
export interface InstallerOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Will initiate a dry run install process. Used for simulating installations within a unit test.
|
|
9
|
-
*/
|
|
10
|
-
dryRun?: boolean;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Used for stubbing out the logger that we use within the installation process so it can be
|
|
14
|
-
* easily introspected without having to mock out `console.*`.
|
|
15
|
-
*/
|
|
16
|
-
logger?: (msg: string) => void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default abstract class CodeGenerator {
|
|
20
|
-
spec: Oas;
|
|
21
|
-
|
|
22
|
-
specPath: string;
|
|
23
|
-
|
|
24
|
-
identifier: string;
|
|
25
|
-
|
|
26
|
-
userAgent: string;
|
|
27
|
-
|
|
28
|
-
requiredPackages!: Record<
|
|
29
|
-
string,
|
|
30
|
-
{
|
|
31
|
-
dependencyType: 'production' | 'development';
|
|
32
|
-
reason: string;
|
|
33
|
-
url?: string;
|
|
34
|
-
version: string;
|
|
35
|
-
}
|
|
36
|
-
>;
|
|
37
|
-
|
|
38
|
-
constructor(spec: Oas, specPath: string, identifier: string) {
|
|
39
|
-
this.spec = spec;
|
|
40
|
-
this.specPath = specPath;
|
|
41
|
-
this.identifier = identifier;
|
|
42
|
-
|
|
43
|
-
// User agents should be contextual to the spec in question and the version of `api` that was
|
|
44
|
-
// used to generate the SDK. For example, this'll look like `petstore/1.0.0 (api/4.2.0)` for
|
|
45
|
-
// a `petstore` spec installed on api@4.2.0.
|
|
46
|
-
const info = spec.getDefinition().info;
|
|
47
|
-
this.userAgent = `${identifier}/${info.version} (${PACKAGE_NAME}/${PACKAGE_VERSION})`;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* This check is barbaric but there are a number of issues with how the `transformer` work we
|
|
51
|
-
* have in `oas` and in `.getParametersAsJSONSchema()` and `.getResponseAsJSONSchema()` that
|
|
52
|
-
* are fully crashing when attempting to codegen an SDK for an API definition that has a
|
|
53
|
-
* circular reference.
|
|
54
|
-
*
|
|
55
|
-
* In order to get v5 out the door we're not going to support this case initialy.
|
|
56
|
-
*
|
|
57
|
-
* @see {@link https://github.com/readmeio/api/issues/549}
|
|
58
|
-
*/
|
|
59
|
-
if (JSON.stringify(spec.api).includes('"$ref":"#/')) {
|
|
60
|
-
throw new Error(
|
|
61
|
-
'Sorry, this library does not yet support generating an SDK for an OpenAPI definition that contains circular references.',
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
abstract generate(): Promise<Record<string, string>>;
|
|
67
|
-
|
|
68
|
-
abstract install(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
69
|
-
|
|
70
|
-
abstract compile(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
71
|
-
|
|
72
|
-
hasRequiredPackages() {
|
|
73
|
-
return Boolean(Object.keys(this.requiredPackages));
|
|
74
|
-
}
|
|
75
|
-
}
|
package/src/codegen/factory.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type CodeGenerator from './codegenerator.js';
|
|
2
|
-
import type Oas from 'oas';
|
|
3
|
-
|
|
4
|
-
import TSGenerator from './languages/typescript/index.js';
|
|
5
|
-
|
|
6
|
-
export enum SupportedLanguages {
|
|
7
|
-
JS = 'js',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default function codegenFactory(
|
|
11
|
-
language: SupportedLanguages,
|
|
12
|
-
spec: Oas,
|
|
13
|
-
specPath: string,
|
|
14
|
-
identifier: string,
|
|
15
|
-
): CodeGenerator {
|
|
16
|
-
switch (language) {
|
|
17
|
-
case SupportedLanguages.JS:
|
|
18
|
-
return new TSGenerator(spec, specPath, identifier);
|
|
19
|
-
|
|
20
|
-
default:
|
|
21
|
-
throw new TypeError(`Unsupported language supplied: ${language}`);
|
|
22
|
-
}
|
|
23
|
-
}
|