api 6.1.0 → 7.0.0-alpha.0

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 (69) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +0 -12
  3. package/package.json +18 -38
  4. package/src/bin.ts +1 -1
  5. package/src/{cli/codegen → codegen}/index.ts +1 -1
  6. package/src/{cli/codegen → codegen}/language.ts +4 -3
  7. package/src/{cli/codegen → codegen}/languages/typescript/util.ts +1 -10
  8. package/src/{cli/codegen → codegen}/languages/typescript.ts +40 -41
  9. package/src/{cli/commands → commands}/install.ts +3 -3
  10. package/src/fetcher.ts +6 -8
  11. package/src/{cli/lib → lib}/prompt.ts +1 -1
  12. package/src/packageInfo.ts +1 -1
  13. package/src/{cli/storage.ts → storage.ts} +13 -9
  14. package/tsconfig.json +3 -13
  15. package/dist/bin.d.ts +0 -1
  16. package/dist/bin.js +0 -91
  17. package/dist/cache.d.ts +0 -68
  18. package/dist/cache.js +0 -198
  19. package/dist/cli/codegen/index.d.ts +0 -4
  20. package/dist/cli/codegen/index.js +0 -23
  21. package/dist/cli/codegen/language.d.ts +0 -27
  22. package/dist/cli/codegen/language.js +0 -32
  23. package/dist/cli/codegen/languages/typescript/util.d.ts +0 -21
  24. package/dist/cli/codegen/languages/typescript/util.js +0 -185
  25. package/dist/cli/codegen/languages/typescript.d.ts +0 -111
  26. package/dist/cli/codegen/languages/typescript.js +0 -821
  27. package/dist/cli/commands/index.d.ts +0 -4
  28. package/dist/cli/commands/index.js +0 -9
  29. package/dist/cli/commands/install.d.ts +0 -3
  30. package/dist/cli/commands/install.js +0 -236
  31. package/dist/cli/lib/prompt.d.ts +0 -9
  32. package/dist/cli/lib/prompt.js +0 -81
  33. package/dist/cli/logger.d.ts +0 -1
  34. package/dist/cli/logger.js +0 -16
  35. package/dist/cli/storage.d.ts +0 -105
  36. package/dist/cli/storage.js +0 -277
  37. package/dist/core/errors/fetchError.d.ts +0 -12
  38. package/dist/core/errors/fetchError.js +0 -36
  39. package/dist/core/getJSONSchemaDefaults.d.ts +0 -14
  40. package/dist/core/getJSONSchemaDefaults.js +0 -61
  41. package/dist/core/index.d.ts +0 -40
  42. package/dist/core/index.js +0 -168
  43. package/dist/core/parseResponse.d.ts +0 -6
  44. package/dist/core/parseResponse.js +0 -71
  45. package/dist/core/prepareAuth.d.ts +0 -5
  46. package/dist/core/prepareAuth.js +0 -84
  47. package/dist/core/prepareParams.d.ts +0 -21
  48. package/dist/core/prepareParams.js +0 -422
  49. package/dist/core/prepareServer.d.ts +0 -10
  50. package/dist/core/prepareServer.js +0 -47
  51. package/dist/fetcher.d.ts +0 -54
  52. package/dist/fetcher.js +0 -165
  53. package/dist/index.d.ts +0 -6
  54. package/dist/index.js +0 -259
  55. package/dist/packageInfo.d.ts +0 -2
  56. package/dist/packageInfo.js +0 -6
  57. package/src/.sink.d.ts +0 -1
  58. package/src/cache.ts +0 -193
  59. package/src/core/errors/fetchError.ts +0 -31
  60. package/src/core/getJSONSchemaDefaults.ts +0 -74
  61. package/src/core/index.ts +0 -148
  62. package/src/core/parseResponse.ts +0 -26
  63. package/src/core/prepareAuth.ts +0 -109
  64. package/src/core/prepareParams.ts +0 -410
  65. package/src/core/prepareServer.ts +0 -48
  66. package/src/index.ts +0 -203
  67. package/src/typings.d.ts +0 -2
  68. /package/src/{cli/commands → commands}/index.ts +0 -0
  69. /package/src/{cli/logger.ts → logger.ts} +0 -0
package/tsconfig.json CHANGED
@@ -4,21 +4,11 @@
4
4
  "baseUrl": "./src",
5
5
  "declaration": true,
6
6
  "esModuleInterop": true,
7
- "lib": ["dom", "dom.iterable", "es2020"],
7
+ "lib": ["DOM", "DOM.Iterable", "ES2020"],
8
8
  "noImplicitAny": true,
9
9
  "outDir": "dist/",
10
- "paths": {
11
- // Because this library uses ES2015+ `#private` syntax that would require us to maket his
12
- // library ESM-only we're overloading its types with a `paths` config with this empty file.
13
- // This isn't a great solution as we're losing type checks where this library is used, but
14
- // it's far too early in the ESM lifecycle for us to make API an ESM-only library.
15
- //
16
- // And though TS offers an unstable `node12` module resolution that lets us manage this in
17
- // another way that module resolution requires TS nightlies to be installed, which no thanks!
18
- //
19
- // https://github.com/microsoft/TypeScript/issues/17042
20
- "form-data-encoder": [".sink.d.ts"]
21
- }
10
+ "strict": true,
11
+ "useUnknownInCatchVariables": false
22
12
  },
23
13
  "include": ["./src/**/*"]
24
14
  }
package/dist/bin.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/bin.js DELETED
@@ -1,91 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
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
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- var __importDefault = (this && this.__importDefault) || function (mod) {
62
- return (mod && mod.__esModule) ? mod : { "default": mod };
63
- };
64
- exports.__esModule = true;
65
- var commander_1 = require("commander");
66
- var commands_1 = __importDefault(require("./cli/commands"));
67
- var pkg = __importStar(require("./packageInfo"));
68
- (function () { return __awaiter(void 0, void 0, void 0, function () {
69
- var program;
70
- return __generator(this, function (_a) {
71
- switch (_a.label) {
72
- case 0:
73
- program = new commander_1.Command();
74
- program.name(pkg.PACKAGE_NAME);
75
- program.version(pkg.PACKAGE_VERSION);
76
- /**
77
- * Instead of using Commander's `executableDir` API for loading in external command files we're
78
- * programatically doing it like this because it's cleaner for us to let Commander manage option
79
- * and argument parsing within this file than having each command manage that itself.
80
- */
81
- Object.entries(commands_1["default"]).forEach(function (_a) {
82
- var cmd = _a[1];
83
- program.addCommand(cmd);
84
- });
85
- return [4 /*yield*/, program.parseAsync(process.argv)];
86
- case 1:
87
- _a.sent();
88
- return [2 /*return*/];
89
- }
90
- });
91
- }); })();
package/dist/cache.d.ts DELETED
@@ -1,68 +0,0 @@
1
- import type { OASDocument } from 'oas/dist/rmoas.types';
2
- import 'isomorphic-fetch';
3
- import Fetcher from './fetcher';
4
- type CacheStore = Record<string, {
5
- hash: string;
6
- original: string | OASDocument;
7
- /**
8
- * @deprecated Deprecated in v4.5.0 in favor of `hash`.
9
- */
10
- path?: string;
11
- title?: string;
12
- version?: string;
13
- }>;
14
- export default class Cache {
15
- static dir: string;
16
- static cacheStore: string;
17
- static specsCache: string;
18
- uri: string | OASDocument;
19
- uriHash: string;
20
- cached: false | CacheStore;
21
- fetcher: Fetcher;
22
- constructor(uri: string | OASDocument, cacheDir?: string | false);
23
- static getCacheHash(file: string | OASDocument): string;
24
- static setCacheDir(dir?: string | false): void;
25
- static reset(): Promise<void>;
26
- isCached(): boolean;
27
- getCache(): CacheStore;
28
- get(): any;
29
- load(): Promise<import("openapi-types").OpenAPIV3.Document<{}> | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
30
- info: import("openapi-types").OpenAPIV3_1.InfoObject;
31
- jsonSchemaDialect?: string;
32
- servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
33
- } & Pick<{
34
- paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
35
- webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
36
- components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
37
- }, "paths"> & Omit<Partial<{
38
- paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
39
- webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
40
- components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
41
- }>, "paths">) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
42
- info: import("openapi-types").OpenAPIV3_1.InfoObject;
43
- jsonSchemaDialect?: string;
44
- servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
45
- } & Pick<{
46
- paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
47
- webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
48
- components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
49
- }, "webhooks"> & Omit<Partial<{
50
- paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
51
- webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
52
- components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
53
- }>, "webhooks">) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
54
- info: import("openapi-types").OpenAPIV3_1.InfoObject;
55
- jsonSchemaDialect?: string;
56
- servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
57
- } & Pick<{
58
- paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
59
- webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
60
- components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
61
- }, "components"> & Omit<Partial<{
62
- paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
63
- webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
64
- components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
65
- }>, "components">) | import("openapi-types").OpenAPIV2.Document<{}>>;
66
- save(spec: OASDocument): OASDocument;
67
- }
68
- export {};
package/dist/cache.js DELETED
@@ -1,198 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
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
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- exports.__esModule = true;
42
- var crypto_1 = __importDefault(require("crypto"));
43
- var fs_1 = __importDefault(require("fs"));
44
- var os_1 = __importDefault(require("os"));
45
- var path_1 = __importDefault(require("path"));
46
- var find_cache_dir_1 = __importDefault(require("find-cache-dir"));
47
- require("isomorphic-fetch");
48
- var make_dir_1 = __importDefault(require("make-dir"));
49
- var fetcher_1 = __importDefault(require("./fetcher"));
50
- var packageInfo_1 = require("./packageInfo");
51
- var Cache = /** @class */ (function () {
52
- function Cache(uri, cacheDir) {
53
- if (cacheDir === void 0) { cacheDir = false; }
54
- Cache.setCacheDir(cacheDir);
55
- Cache.cacheStore = path_1["default"].join(Cache.dir, 'cache.json');
56
- Cache.specsCache = path_1["default"].join(Cache.dir, 'specs');
57
- this.fetcher = new fetcher_1["default"](uri);
58
- this.uri = this.fetcher.uri;
59
- this.uriHash = Cache.getCacheHash(this.uri);
60
- // This should default to false so we have awareness if we've looked at the cache yet.
61
- this.cached = false;
62
- }
63
- Cache.getCacheHash = function (file) {
64
- var data;
65
- if (typeof file === 'object') {
66
- // Under certain unit testing circumstances, we might be supplying the class with a raw JSON
67
- // object so we'll need to convert it to a string in order to hand it off to the crypto
68
- // module.
69
- data = JSON.stringify(file);
70
- }
71
- else {
72
- data = file;
73
- }
74
- return crypto_1["default"].createHash('md5').update(data).digest('hex');
75
- };
76
- Cache.setCacheDir = function (dir) {
77
- if (dir) {
78
- Cache.dir = dir;
79
- return;
80
- }
81
- else if (Cache.dir) {
82
- // If we already have a cache dir set and aren't explicitly it to something new then we
83
- // shouldn't overwrite what we've already got.
84
- return;
85
- }
86
- Cache.dir = (0, find_cache_dir_1["default"])({ name: packageInfo_1.PACKAGE_NAME });
87
- if (typeof Cache.dir === 'undefined') {
88
- // The `find-cache-dir` module returns `undefined` if the `node_modules/` directory isn't
89
- // writable, or there's no `package.json` in the root-most directory. If this happens, we can
90
- // instead adhoc create a cache directory in the users OS temp directory and store our data
91
- // there.
92
- //
93
- // @link https://github.com/avajs/find-cache-dir/issues/29
94
- Cache.dir = make_dir_1["default"].sync(path_1["default"].join(os_1["default"].tmpdir(), packageInfo_1.PACKAGE_NAME));
95
- }
96
- };
97
- Cache.reset = function () {
98
- return __awaiter(this, void 0, void 0, function () {
99
- return __generator(this, function (_a) {
100
- switch (_a.label) {
101
- case 0:
102
- if (!Cache.cacheStore) return [3 /*break*/, 2];
103
- return [4 /*yield*/, fs_1["default"].promises.rm(Cache.cacheStore)["catch"](function () {
104
- // no-op
105
- })];
106
- case 1:
107
- _a.sent();
108
- _a.label = 2;
109
- case 2:
110
- if (!Cache.specsCache) return [3 /*break*/, 4];
111
- return [4 /*yield*/, fs_1["default"].promises.rm(Cache.specsCache, { recursive: true })["catch"](function () {
112
- // no-op
113
- })];
114
- case 3:
115
- _a.sent();
116
- _a.label = 4;
117
- case 4: return [2 /*return*/];
118
- }
119
- });
120
- });
121
- };
122
- Cache.prototype.isCached = function () {
123
- var cache = this.getCache();
124
- return cache && this.uriHash in cache;
125
- };
126
- Cache.prototype.getCache = function () {
127
- if (typeof this.cached === 'object') {
128
- return this.cached;
129
- }
130
- this.cached = {};
131
- if (fs_1["default"].existsSync(Cache.cacheStore)) {
132
- this.cached = JSON.parse(fs_1["default"].readFileSync(Cache.cacheStore, 'utf8'));
133
- }
134
- return this.cached;
135
- };
136
- Cache.prototype.get = function () {
137
- // If the class was supplied a raw object, just go ahead and bypass the caching system and
138
- // return that.
139
- if (typeof this.uri === 'object') {
140
- return this.uri;
141
- }
142
- if (!this.isCached()) {
143
- throw new Error("".concat(this.uri, " has not been cached yet and must do so before being retrieved."));
144
- }
145
- var cache = this.getCache();
146
- // Prior to v4.5.0 we were putting a fully resolved path to the API definition in the cache
147
- // store but if you had specified a custom caching directory and would generate the cache on
148
- // your system, that filepath would obviously not be the same in other environments. For this
149
- // reason the `path` was removed from the cache store in favor of storing the `hash` instead.
150
- //
151
- // If we still have `path` in the config cache for backwards compatibility we should use it.
152
- if ('path' in cache[this.uriHash]) {
153
- return JSON.parse(fs_1["default"].readFileSync(cache[this.uriHash].path, 'utf8'));
154
- }
155
- return JSON.parse(fs_1["default"].readFileSync(path_1["default"].join(Cache.specsCache, "".concat(cache[this.uriHash].hash, ".json")), 'utf8'));
156
- };
157
- Cache.prototype.load = function () {
158
- return __awaiter(this, void 0, void 0, function () {
159
- var _this = this;
160
- return __generator(this, function (_a) {
161
- // If the class was supplied a raw object we should still validate and make sure that it's
162
- // dereferenced in order for everything to function, but we shouldn't worry about saving it
163
- // into the cache directory architecture.
164
- if (typeof this.uri === 'object') {
165
- return [2 /*return*/, fetcher_1["default"].validate(this.uri)];
166
- }
167
- return [2 /*return*/, this.fetcher.load().then(function (spec) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
168
- return [2 /*return*/, this.save(spec)];
169
- }); }); })];
170
- });
171
- });
172
- };
173
- Cache.prototype.save = function (spec) {
174
- if (!fs_1["default"].existsSync(Cache.dir)) {
175
- fs_1["default"].mkdirSync(Cache.dir, { recursive: true });
176
- }
177
- if (!fs_1["default"].existsSync(Cache.specsCache)) {
178
- fs_1["default"].mkdirSync(Cache.specsCache, { recursive: true });
179
- }
180
- var cache = this.getCache();
181
- if (!(this.uriHash in cache)) {
182
- var saved = JSON.stringify(spec, null, 2);
183
- var fileHash = crypto_1["default"].createHash('md5').update(saved).digest('hex');
184
- cache[this.uriHash] = {
185
- hash: fileHash,
186
- original: this.uri,
187
- title: 'title' in spec.info ? spec.info.title : undefined,
188
- version: 'version' in spec.info ? spec.info.version : undefined
189
- };
190
- fs_1["default"].writeFileSync(path_1["default"].join(Cache.specsCache, "".concat(fileHash, ".json")), saved);
191
- fs_1["default"].writeFileSync(Cache.cacheStore, JSON.stringify(cache, null, 2));
192
- this.cached = cache;
193
- }
194
- return spec;
195
- };
196
- return Cache;
197
- }());
198
- exports["default"] = Cache;
@@ -1,4 +0,0 @@
1
- import type CodeGeneratorLanguage from './language';
2
- import type Oas from 'oas';
3
- export type SupportedLanguages = 'js' | 'js-cjs' | 'js-esm' | 'ts';
4
- export default function codegen(language: SupportedLanguages, spec: Oas, specPath: string, identifier: string): CodeGeneratorLanguage;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- exports.__esModule = true;
6
- var typescript_1 = __importDefault(require("./languages/typescript"));
7
- function codegen(language, spec, specPath, identifier) {
8
- switch (language) {
9
- case 'js':
10
- throw new TypeError('An export format of CommonJS or ECMAScript is required for JavaScript compilation.');
11
- case 'js-cjs':
12
- case 'js-esm':
13
- case 'ts':
14
- return new typescript_1["default"](spec, specPath, identifier, {
15
- outputJS: ['js-cjs', 'js-esm'].includes(language),
16
- // TS will always generate with ESM-like exports.
17
- compilerTarget: language === 'js-cjs' ? 'cjs' : 'esm'
18
- });
19
- default:
20
- throw new TypeError("Unsupported language supplied: ".concat(language));
21
- }
22
- }
23
- exports["default"] = codegen;
@@ -1,27 +0,0 @@
1
- import type Storage from '../storage';
2
- import type Oas from 'oas';
3
- export interface InstallerOptions {
4
- /**
5
- * Will initiate a dry run install process. Used for simulating installations within a unit test.
6
- */
7
- dryRun?: boolean;
8
- /**
9
- * Used for stubbing out the logger that we use within the installation process so it can be
10
- * easily introspected without having to mock out `console.*`.
11
- */
12
- logger?: (msg: string) => void;
13
- }
14
- export default abstract class CodeGeneratorLanguage {
15
- spec: Oas;
16
- specPath: string;
17
- identifier: string;
18
- userAgent: string;
19
- requiredPackages: Record<string, {
20
- reason: string;
21
- url: string;
22
- }>;
23
- constructor(spec: Oas, specPath: string, identifier: string);
24
- abstract generator(): Promise<Record<string, string>>;
25
- abstract installer(storage: Storage, opts?: InstallerOptions): Promise<void>;
26
- hasRequiredPackages(): boolean;
27
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- var packageInfo_1 = require("../../packageInfo");
4
- var CodeGeneratorLanguage = /** @class */ (function () {
5
- function CodeGeneratorLanguage(spec, specPath, identifier) {
6
- this.spec = spec;
7
- this.specPath = specPath;
8
- // User agents should be contextual to the spec in question and the version of `api` that was
9
- // used to generate the SDK. For example, this'll look like `petstore/1.0.0 (api/4.2.0)` for
10
- // a `petstore` spec installed on api@4.2.0.
11
- var info = spec.getDefinition().info;
12
- this.userAgent = "".concat(identifier, "/").concat(info.version, " (").concat(packageInfo_1.PACKAGE_NAME, "/").concat(packageInfo_1.PACKAGE_VERSION, ")");
13
- /**
14
- * This check is barbaric but there are a number of issues with how the `transformer` work we
15
- * have in `oas` and in `.getParametersAsJSONSchema()` and `.getResponseAsJSONSchema()` that
16
- * are fully crashing when attempting to codegen an SDK for an API definition that has a
17
- * circular reference.
18
- *
19
- * In order to get v5 out the door we're not going to support this case initialy.
20
- *
21
- * @see {@link https://github.com/readmeio/api/issues/549}
22
- */
23
- if (JSON.stringify(spec.api).includes('"$ref":"#/')) {
24
- throw new Error('Sorry, this library does not yet support generating an SDK for an OpenAPI definition that contains circular references.');
25
- }
26
- }
27
- CodeGeneratorLanguage.prototype.hasRequiredPackages = function () {
28
- return Boolean(Object.keys(this.requiredPackages));
29
- };
30
- return CodeGeneratorLanguage;
31
- }());
32
- exports["default"] = CodeGeneratorLanguage;
@@ -1,21 +0,0 @@
1
- export declare function formatter(content: string): string;
2
- /**
3
- * @see {@link https://www.30secondsofcode.org/js/s/word-wrap}
4
- */
5
- export declare function wordWrap(str: string, max?: number): string;
6
- /**
7
- * Safely escape some string characters that may break a docblock.
8
- *
9
- */
10
- export declare function docblockEscape(str: string): string;
11
- /**
12
- * Convert a string that might contain spaces or special characters to one that can safely be used
13
- * as a TypeScript interface or enum name.
14
- *
15
- * This function has been adapted and slighty modified from `json-schema-to-typescript`.
16
- *
17
- * @license MIT
18
- * @see {@link https://github.com/bcherny/json-schema-to-typescript}
19
- */
20
- export declare function toSafeString(str: string): string;
21
- export declare function generateTypeName(...parts: string[]): string;