api 7.0.0-beta.0 → 7.0.0-beta.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.
Files changed (52) hide show
  1. package/dist/codegen/codegenerator.d.ts +9 -11
  2. package/dist/codegen/codegenerator.d.ts.map +1 -1
  3. package/dist/codegen/codegenerator.js +11 -0
  4. package/dist/codegen/codegenerator.js.map +1 -1
  5. package/dist/codegen/factory.d.ts +19 -3
  6. package/dist/codegen/factory.d.ts.map +1 -1
  7. package/dist/codegen/factory.js +12 -5
  8. package/dist/codegen/factory.js.map +1 -1
  9. package/dist/codegen/languages/typescript/index.d.ts +8 -2
  10. package/dist/codegen/languages/typescript/index.d.ts.map +1 -1
  11. package/dist/codegen/languages/typescript/index.js +61 -15
  12. package/dist/codegen/languages/typescript/index.js.map +1 -1
  13. package/dist/commands/index.d.ts +2 -0
  14. package/dist/commands/index.d.ts.map +1 -1
  15. package/dist/commands/index.js +4 -0
  16. package/dist/commands/index.js.map +1 -1
  17. package/dist/commands/install.d.ts.map +1 -1
  18. package/dist/commands/install.js +5 -5
  19. package/dist/commands/install.js.map +1 -1
  20. package/dist/commands/list.d.ts +4 -0
  21. package/dist/commands/list.d.ts.map +1 -0
  22. package/dist/commands/list.js +37 -0
  23. package/dist/commands/list.js.map +1 -0
  24. package/dist/commands/uninstall.d.ts +4 -0
  25. package/dist/commands/uninstall.d.ts.map +1 -0
  26. package/dist/commands/uninstall.js +72 -0
  27. package/dist/commands/uninstall.js.map +1 -0
  28. package/dist/lockfileSchema.d.ts +125 -0
  29. package/dist/lockfileSchema.d.ts.map +1 -0
  30. package/dist/lockfileSchema.js +78 -0
  31. package/dist/lockfileSchema.js.map +1 -0
  32. package/dist/packageInfo.d.ts +1 -1
  33. package/dist/packageInfo.js +1 -1
  34. package/dist/storage.d.ts +75 -60
  35. package/dist/storage.d.ts.map +1 -1
  36. package/dist/storage.js +85 -25
  37. package/dist/storage.js.map +1 -1
  38. package/package.json +14 -7
  39. package/schema.json +69 -0
  40. package/src/bin.ts +0 -21
  41. package/src/codegen/codegenerator.ts +0 -75
  42. package/src/codegen/factory.ts +0 -23
  43. package/src/codegen/languages/typescript/index.ts +0 -984
  44. package/src/codegen/languages/typescript/util.ts +0 -174
  45. package/src/commands/index.ts +0 -5
  46. package/src/commands/install.ts +0 -196
  47. package/src/fetcher.ts +0 -145
  48. package/src/lib/prompt.ts +0 -29
  49. package/src/logger.ts +0 -10
  50. package/src/packageInfo.ts +0 -3
  51. package/src/storage.ts +0 -333
  52. package/tsconfig.json +0 -10
@@ -0,0 +1,72 @@
1
+ import path from 'node:path';
2
+ import chalk from 'chalk';
3
+ import { Command, Option } from 'commander';
4
+ import ora from 'ora';
5
+ import { SupportedLanguages, uninstallerFactory } from '../codegen/factory.js';
6
+ import promptTerminal from '../lib/prompt.js';
7
+ import logger from '../logger.js';
8
+ import Storage from '../storage.js';
9
+ const cmd = new Command();
10
+ cmd
11
+ .name('uninstall')
12
+ .description('uninstall an SDK from your codebase')
13
+ .argument('<identifier>', 'the SDK to uninstall')
14
+ .addOption(new Option('-y, --yes', 'Automatically answer "yes" to any prompts printed'))
15
+ .action(async (identifier, options) => {
16
+ // We don't know if we have `identifier` in the storage system yet, we just need to preload the
17
+ // system so we can access lockfiles.
18
+ const storage = new Storage('', SupportedLanguages.JS, identifier);
19
+ const entry = Storage.getFromLockfile(identifier);
20
+ if (!entry) {
21
+ logger(`You do not appear to have ${identifier} installed. You can run \`npx api list\` to see what SDKs are present.`, true);
22
+ process.exit(1);
23
+ }
24
+ storage.setLanguage(entry?.language);
25
+ storage.setIdentifier(identifier);
26
+ const directory = path.relative(process.cwd(), storage.getIdentifierStorageDir());
27
+ if (!options.yes) {
28
+ await promptTerminal({
29
+ type: 'confirm',
30
+ name: 'value',
31
+ message: `Are you sure you want to uninstall ${chalk.yellow(identifier)}? This will delete the ${chalk.yellow(directory)} directory and potentially any changes you may have made there.`,
32
+ initial: true,
33
+ }).then(({ value }) => {
34
+ if (!value) {
35
+ process.exit(1);
36
+ }
37
+ });
38
+ }
39
+ let spinner = ora(`Uninstalling ${chalk.grey(identifier)}`).start();
40
+ // If we have a known package name for this then we can uninstall it from within cooresponding
41
+ // package manager.
42
+ const pkgName = storage.getPackageName();
43
+ if (pkgName) {
44
+ const language = storage.getSDKLanguage();
45
+ await uninstallerFactory(language, storage)
46
+ .then(() => {
47
+ spinner.succeed(spinner.text);
48
+ })
49
+ .catch(err => {
50
+ spinner.fail(spinner.text);
51
+ logger(err.message, true);
52
+ process.exit(1);
53
+ });
54
+ }
55
+ spinner = ora(`Removing ${chalk.grey(directory)}`).start();
56
+ await storage
57
+ .remove()
58
+ .then(() => {
59
+ spinner.succeed(spinner.text);
60
+ })
61
+ .catch(err => {
62
+ spinner.fail(spinner.text);
63
+ logger(err.message, true);
64
+ process.exit(1);
65
+ });
66
+ logger('🚀 All done!');
67
+ })
68
+ .addHelpText('after', `
69
+ Examples:
70
+ $ npx api uninstall petstore`);
71
+ export default cmd;
72
+ //# sourceMappingURL=uninstall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uninstall.js","sourceRoot":"","sources":["../../src/commands/uninstall.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,OAAO,MAAM,eAAe,CAAC;AAMpC,MAAM,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC;AAC1B,GAAG;KACA,IAAI,CAAC,WAAW,CAAC;KACjB,WAAW,CAAC,qCAAqC,CAAC;KAClD,QAA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@
1
+ import type { FromSchema } from '@readme/api-core/lib';
2
+ declare const lockfileApiSchema: {
3
+ readonly type: "object";
4
+ readonly required: readonly ["createdAt", "identifier", "installerVersion", "integrity"];
5
+ readonly properties: {
6
+ readonly createdAt: {
7
+ readonly type: "string";
8
+ readonly format: "date-time";
9
+ readonly description: "The date that this SDK was installed.";
10
+ readonly examples: readonly ["2023-10-19T20:35:39.268Z"];
11
+ };
12
+ readonly identifier: {
13
+ readonly type: "string";
14
+ readonly 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>`";
15
+ readonly examples: readonly ["petstore"];
16
+ };
17
+ readonly installerVersion: {
18
+ readonly type: "string";
19
+ readonly description: "The version of `api` that was used to install this SDK.";
20
+ readonly examples: readonly ["7.0.0"];
21
+ };
22
+ readonly integrity: {
23
+ readonly type: "string";
24
+ readonly 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.";
25
+ readonly examples: readonly ["sha512-otRF5TLMeDczSJlrmWLNDHLfmXg+C98oa/I/X2WWycwngh+a6WsbnjTbfwKGRU5DFbagOn2qX2SRvtBGOBRVGg=="];
26
+ };
27
+ readonly language: {
28
+ readonly type: "string";
29
+ readonly description: "The language that this SDK was generated for.";
30
+ readonly default: "js";
31
+ readonly enum: "js"[];
32
+ };
33
+ readonly private: {
34
+ readonly type: "boolean";
35
+ readonly description: "Was this SDK installed as a private, unpublished, package to the filesystem?";
36
+ };
37
+ readonly source: {
38
+ readonly type: "string";
39
+ readonly description: "The original source that was used to generate the SDK with.";
40
+ readonly examples: readonly ["https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json", "./petstore.json", "@developers/v2.0#nysezql0wwo236"];
41
+ };
42
+ readonly updatedAt: {
43
+ readonly type: "string";
44
+ readonly format: "date-time";
45
+ readonly description: "The date that this SDK was last rebuilt or updated.";
46
+ readonly examples: readonly ["2023-10-19T20:35:39.268Z"];
47
+ };
48
+ };
49
+ readonly additionalProperties: false;
50
+ };
51
+ export declare const lockfileSchema: {
52
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
53
+ readonly title: "api storage lockfile";
54
+ readonly description: "See https://api.readme.dev/docs";
55
+ readonly type: "object";
56
+ readonly required: readonly ["apis"];
57
+ readonly additionalProperties: false;
58
+ readonly properties: {
59
+ readonly $schema: {
60
+ readonly type: "string";
61
+ };
62
+ readonly apis: {
63
+ readonly type: "array";
64
+ readonly description: "The list of installed APIs";
65
+ readonly items: {
66
+ readonly $ref: "#/definitions/api";
67
+ };
68
+ };
69
+ };
70
+ readonly definitions: {
71
+ readonly api: {
72
+ readonly type: "object";
73
+ readonly required: readonly ["createdAt", "identifier", "installerVersion", "integrity"];
74
+ readonly properties: {
75
+ readonly createdAt: {
76
+ readonly type: "string";
77
+ readonly format: "date-time";
78
+ readonly description: "The date that this SDK was installed.";
79
+ readonly examples: readonly ["2023-10-19T20:35:39.268Z"];
80
+ };
81
+ readonly identifier: {
82
+ readonly type: "string";
83
+ readonly 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>`";
84
+ readonly examples: readonly ["petstore"];
85
+ };
86
+ readonly installerVersion: {
87
+ readonly type: "string";
88
+ readonly description: "The version of `api` that was used to install this SDK.";
89
+ readonly examples: readonly ["7.0.0"];
90
+ };
91
+ readonly integrity: {
92
+ readonly type: "string";
93
+ readonly 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.";
94
+ readonly examples: readonly ["sha512-otRF5TLMeDczSJlrmWLNDHLfmXg+C98oa/I/X2WWycwngh+a6WsbnjTbfwKGRU5DFbagOn2qX2SRvtBGOBRVGg=="];
95
+ };
96
+ readonly language: {
97
+ readonly type: "string";
98
+ readonly description: "The language that this SDK was generated for.";
99
+ readonly default: "js";
100
+ readonly enum: "js"[];
101
+ };
102
+ readonly private: {
103
+ readonly type: "boolean";
104
+ readonly description: "Was this SDK installed as a private, unpublished, package to the filesystem?";
105
+ };
106
+ readonly source: {
107
+ readonly type: "string";
108
+ readonly description: "The original source that was used to generate the SDK with.";
109
+ readonly examples: readonly ["https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json", "./petstore.json", "@developers/v2.0#nysezql0wwo236"];
110
+ };
111
+ readonly updatedAt: {
112
+ readonly type: "string";
113
+ readonly format: "date-time";
114
+ readonly description: "The date that this SDK was last rebuilt or updated.";
115
+ readonly examples: readonly ["2023-10-19T20:35:39.268Z"];
116
+ };
117
+ };
118
+ readonly additionalProperties: false;
119
+ };
120
+ };
121
+ };
122
+ export type Lockfile = FromSchema<typeof lockfileSchema>;
123
+ export type LockfileAPI = FromSchema<typeof lockfileApiSchema>;
124
+ export {};
125
+ //# sourceMappingURL=lockfileSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockfileSchema.d.ts","sourceRoot":"","sources":["../src/lockfileSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsDb,CAAC;AAEX,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsBjB,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACzD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { SupportedLanguages } from './codegen/factory.js';
2
+ const lockfileApiSchema = {
3
+ type: 'object',
4
+ required: ['createdAt', 'identifier', 'installerVersion', 'integrity'],
5
+ properties: {
6
+ createdAt: {
7
+ type: 'string',
8
+ format: 'date-time',
9
+ description: 'The date that this SDK was installed.',
10
+ examples: ['2023-10-19T20:35:39.268Z'],
11
+ },
12
+ identifier: {
13
+ type: 'string',
14
+ 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>`",
15
+ examples: ['petstore'],
16
+ },
17
+ installerVersion: {
18
+ type: 'string',
19
+ description: 'The version of `api` that was used to install this SDK.',
20
+ examples: ['7.0.0'],
21
+ },
22
+ integrity: {
23
+ type: 'string',
24
+ 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.',
25
+ examples: ['sha512-otRF5TLMeDczSJlrmWLNDHLfmXg+C98oa/I/X2WWycwngh+a6WsbnjTbfwKGRU5DFbagOn2qX2SRvtBGOBRVGg=='],
26
+ },
27
+ language: {
28
+ type: 'string',
29
+ description: 'The language that this SDK was generated for.',
30
+ default: SupportedLanguages.JS,
31
+ enum: Object.values(SupportedLanguages),
32
+ },
33
+ private: {
34
+ type: 'boolean',
35
+ description: 'Was this SDK installed as a private, unpublished, package to the filesystem?',
36
+ },
37
+ source: {
38
+ type: 'string',
39
+ description: 'The original source that was used to generate the SDK with.',
40
+ examples: [
41
+ 'https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json',
42
+ './petstore.json',
43
+ '@developers/v2.0#nysezql0wwo236',
44
+ ],
45
+ },
46
+ updatedAt: {
47
+ type: 'string',
48
+ format: 'date-time',
49
+ description: 'The date that this SDK was last rebuilt or updated.',
50
+ examples: ['2023-10-19T20:35:39.268Z'],
51
+ },
52
+ },
53
+ additionalProperties: false,
54
+ };
55
+ export const lockfileSchema = {
56
+ $schema: 'http://json-schema.org/draft-07/schema#',
57
+ title: 'api storage lockfile',
58
+ description: 'See https://api.readme.dev/docs',
59
+ type: 'object',
60
+ required: ['apis'],
61
+ additionalProperties: false,
62
+ properties: {
63
+ $schema: {
64
+ type: 'string',
65
+ },
66
+ apis: {
67
+ type: 'array',
68
+ description: 'The list of installed APIs',
69
+ items: {
70
+ $ref: '#/definitions/api',
71
+ },
72
+ },
73
+ },
74
+ definitions: {
75
+ api: lockfileApiSchema,
76
+ },
77
+ };
78
+ //# sourceMappingURL=lockfileSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockfileSchema.js","sourceRoot":"","sources":["../src/lockfileSchema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,CAAC;IACtE,UAAU,EAAE;QACV,SAAS,EAAE;YACT,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,WAAW;YACnB,WAAW,EAAE,uCAAuC;YACpD,QAAQ,EAAE,CAAC,0BAA0B,CAAC;SACvC;QACD,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,8JAA8J;YAChK,QAAQ,EAAE,CAAC,UAAU,CAAC;SACvB;QACD,gBAAgB,EAAE;YAChB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,yDAAyD;YACtE,QAAQ,EAAE,CAAC,OAAO,CAAC;SACpB;QACD,SAAS,EAAE;YACT,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,qIAAqI;YACvI,QAAQ,EAAE,CAAC,iGAAiG,CAAC;SAC9G;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,+CAA+C;YAC5D,OAAO,EAAE,kBAAkB,CAAC,EAAE;YAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC;SACxC;QACD,OAAO,EAAE;YACP,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,8EAA8E;SAC5F;QACD,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,6DAA6D;YAC1E,QAAQ,EAAE;gBACR,4FAA4F;gBAC5F,iBAAiB;gBACjB,iCAAiC;aAClC;SACF;QACD,SAAS,EAAE;YACT,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,WAAW;YACnB,WAAW,EAAE,qDAAqD;YAClE,QAAQ,EAAE,CAAC,0BAA0B,CAAC;SACvC;KACF;IACD,oBAAoB,EAAE,KAAK;CACnB,CAAC;AAEX,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,sBAAsB;IAC7B,WAAW,EAAE,iCAAiC;IAC9C,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,MAAM,CAAC;IAClB,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;SACf;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,4BAA4B;YACzC,KAAK,EAAE;gBACL,IAAI,EAAE,mBAAmB;aAC1B;SACF;KACF;IACD,WAAW,EAAE;QACX,GAAG,EAAE,iBAAiB;KACvB;CACO,CAAC"}
@@ -1,3 +1,3 @@
1
1
  export declare const PACKAGE_NAME = "api";
2
- export declare const PACKAGE_VERSION = "7.0.0-beta.0";
2
+ export declare const PACKAGE_VERSION = "7.0.0-beta.1";
3
3
  //# sourceMappingURL=packageInfo.d.ts.map
@@ -1,4 +1,4 @@
1
1
  // This file is automatically updated by the build script.
2
2
  export const PACKAGE_NAME = 'api';
3
- export const PACKAGE_VERSION = '7.0.0-beta.0';
3
+ export const PACKAGE_VERSION = '7.0.0-beta.1';
4
4
  //# sourceMappingURL=packageInfo.js.map
package/dist/storage.d.ts CHANGED
@@ -1,16 +1,31 @@
1
+ import type { SupportedLanguage } from './codegen/factory.js';
2
+ import type { Lockfile } from './lockfileSchema.js';
1
3
  import type { OASDocument } from 'oas/rmoas.types';
2
4
  import Fetcher from './fetcher.js';
3
5
  export default class Storage {
4
6
  static dir: string;
5
7
  static lockfile: false | Lockfile;
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
- fetcher: Fetcher;
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;
@@ -22,12 +37,34 @@ export default class Storage {
22
37
  static reset(): Promise<void>;
23
38
  static getDefaultLockfile(): Lockfile;
24
39
  static generateIntegrityHash(definition: OASDocument): string;
25
- static getLockfile(): Lockfile;
40
+ static getLockfile(): {
41
+ $schema?: string | undefined;
42
+ apis: {
43
+ language?: "js" | undefined;
44
+ private?: boolean | undefined;
45
+ source?: string | undefined;
46
+ updatedAt?: string | undefined;
47
+ createdAt: string;
48
+ identifier: string;
49
+ installerVersion: string;
50
+ integrity: string;
51
+ }[];
52
+ };
26
53
  static isIdentifierValid(identifier: string, prefixWithAPINamespace?: boolean): boolean;
27
54
  static isInLockFile(search: {
28
55
  identifier?: string;
29
56
  source?: string;
30
- }): false | LockfileAPI;
57
+ }): false | {
58
+ language?: "js" | undefined;
59
+ private?: boolean | undefined;
60
+ source?: string | undefined;
61
+ updatedAt?: string | undefined;
62
+ createdAt: string;
63
+ identifier: string;
64
+ installerVersion: string;
65
+ integrity: string;
66
+ };
67
+ setLanguage(language?: SupportedLanguage): void;
31
68
  setIdentifier(identifier: string): void;
32
69
  /**
33
70
  * Determine if the current spec + identifier we're working with is already in the lockfile.
@@ -35,73 +72,51 @@ export default class Storage {
35
72
  isInLockfile(): boolean;
36
73
  /**
37
74
  * Retrieve the lockfile record for the current spec + identifier if it exists in the lockfile.
75
+ *
76
+ */
77
+ getFromLockfile(): {
78
+ language?: "js" | undefined;
79
+ private?: boolean | undefined;
80
+ source?: string | undefined;
81
+ updatedAt?: string | undefined;
82
+ createdAt: string;
83
+ identifier: string;
84
+ installerVersion: string;
85
+ integrity: string;
86
+ } | undefined;
87
+ /**
88
+ * Retrieve the lockfile record, if it exists, for a given identifier.
89
+ *
38
90
  */
39
- getFromLockfile(): LockfileAPI | undefined;
91
+ static getFromLockfile(identifier: string): {
92
+ language?: "js" | undefined;
93
+ private?: boolean | undefined;
94
+ source?: string | undefined;
95
+ updatedAt?: string | undefined;
96
+ createdAt: string;
97
+ identifier: string;
98
+ installerVersion: string;
99
+ integrity: string;
100
+ } | undefined;
101
+ getSDKLanguage(): "js";
102
+ getPackageName(): string | undefined;
40
103
  getIdentifierStorageDir(): string;
104
+ getAPIDefinitionPath(): string;
41
105
  getAPIDefinition(): any;
42
106
  saveSourceFiles(files: Record<string, string>): Promise<unknown>;
43
107
  load(shouldSave?: boolean): Promise<OASDocument>;
44
108
  /**
45
- * @example <caption>Storage directory structure</caption>
46
- * .api/
47
- * ├── api.json // The `package-lock.json` equivalent that records everything that's
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
109
+ * Initialize a directory in the storage system for this identifier and add it into the lockfile.
110
+ * This does not create or save the source code for this SDK, that work happens within the
111
+ * code generation system.
64
112
  *
113
+ * @see {@link https://api.readme.dev/docs/how-it-works#api-directory}
65
114
  */
66
115
  save(spec: OASDocument): OASDocument;
67
- }
68
- interface Lockfile {
69
- apis: LockfileAPI[];
70
116
  /**
71
- * The `api.json` schema version. This will only ever change if we introduce breaking changes to
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>`.
80
- *
81
- * @example petstore
82
- */
83
- identifier: string;
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.
117
+ * Delete the stored source code for the given identifier and purge it from the lockfile.
99
118
  *
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
119
  */
104
- source: string;
120
+ remove(): Promise<void>;
105
121
  }
106
- export {};
107
122
  //# sourceMappingURL=storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQnD,OAAO,OAAO,MAAM,cAAc,CAAC;AAGnC,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;IAEnB,MAAM,CAAC,QAAQ,EAAE,KAAK,GAAG,QAAQ,CAAC;IAElC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAG,MAAM,CAAC;IAEpB,OAAO,EAAE,O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