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
@@ -1,185 +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
- exports.generateTypeName = exports.toSafeString = exports.docblockEscape = exports.wordWrap = exports.formatter = void 0;
7
- var lodash_camelcase_1 = __importDefault(require("lodash.camelcase"));
8
- var lodash_deburr_1 = __importDefault(require("lodash.deburr"));
9
- var lodash_startcase_1 = __importDefault(require("lodash.startcase"));
10
- var prettier_1 = require("prettier");
11
- /**
12
- * This is a mix of reserved JS words and keywords in TypeScript that might be reserved or
13
- * allowable but functionally confusing (like `let any = 'buster';`)
14
- *
15
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar}
16
- */
17
- var RESERVED_WORDS = [
18
- 'abstract',
19
- 'any',
20
- 'arguments',
21
- 'as',
22
- 'async',
23
- 'await',
24
- 'boolean',
25
- 'break',
26
- 'byte',
27
- 'case',
28
- 'catch',
29
- 'char',
30
- 'class',
31
- 'const',
32
- 'continue',
33
- 'constructor',
34
- 'debugger',
35
- 'default',
36
- 'delete',
37
- 'do',
38
- 'double',
39
- 'else',
40
- 'enum',
41
- 'eval',
42
- 'export',
43
- 'extends',
44
- 'false',
45
- 'final',
46
- 'finally',
47
- 'float',
48
- 'for',
49
- 'from',
50
- 'function',
51
- 'get',
52
- 'goto',
53
- 'if',
54
- 'implements',
55
- 'import',
56
- 'interface',
57
- 'in',
58
- 'instanceof',
59
- 'int',
60
- 'let',
61
- 'long',
62
- 'native',
63
- 'new',
64
- 'null',
65
- 'number',
66
- 'of',
67
- 'package',
68
- 'private',
69
- 'protected',
70
- 'public',
71
- 'module',
72
- 'namespace',
73
- 'return',
74
- 'set',
75
- 'short',
76
- 'static',
77
- 'string',
78
- 'super',
79
- 'switch',
80
- 'synchronized',
81
- 'this',
82
- 'throw',
83
- 'throws',
84
- 'transient',
85
- 'true',
86
- 'try',
87
- 'type',
88
- 'typeof',
89
- 'var',
90
- 'void',
91
- 'while',
92
- 'with',
93
- 'volatile',
94
- 'yield',
95
- // These aren't reserved keywords but because we maybe codegen'ing an SDK to be used in the
96
- // browser it'd be very bad if we overwrote these. This obviously doesn't account for browser APIs
97
- // you can access outside of the `Window` API (like `alert()`), but we can add checks for those
98
- // later if we need to.
99
- 'frames',
100
- 'global',
101
- 'globalThis',
102
- 'navigator',
103
- 'self',
104
- 'window',
105
- ];
106
- function formatter(content) {
107
- return (0, prettier_1.format)(content, {
108
- parser: 'typescript',
109
- printWidth: 100,
110
- singleQuote: true
111
- });
112
- }
113
- exports.formatter = formatter;
114
- /**
115
- * @see {@link https://www.30secondsofcode.org/js/s/word-wrap}
116
- */
117
- function wordWrap(str, max) {
118
- if (max === void 0) { max = 88; }
119
- return str.replace(new RegExp("(?![^\\n]{1,".concat(max, "}$)([^\\n]{1,").concat(max, "})\\s"), 'g'), '$1\n');
120
- }
121
- exports.wordWrap = wordWrap;
122
- /**
123
- * Safely escape some string characters that may break a docblock.
124
- *
125
- */
126
- function docblockEscape(str) {
127
- return str.replace(/\/\*/g, '/\\*').replace(/\*\//g, '*\\/');
128
- }
129
- exports.docblockEscape = docblockEscape;
130
- /**
131
- * Convert a string that might contain spaces or special characters to one that can safely be used
132
- * as a TypeScript interface or enum name.
133
- *
134
- * This function has been adapted and slighty modified from `json-schema-to-typescript`.
135
- *
136
- * @license MIT
137
- * @see {@link https://github.com/bcherny/json-schema-to-typescript}
138
- */
139
- function toSafeString(str) {
140
- // identifiers in javaScript/ts:
141
- // First character: a-zA-Z | _ | $
142
- // Rest: a-zA-Z | _ | $ | 0-9
143
- // remove accents, umlauts, ... by their basic latin letters
144
- return ((0, lodash_deburr_1["default"])(str)
145
- // if the string starts with a number, prefix it with character that typescript can accept
146
- // https://github.com/bcherny/json-schema-to-typescript/issues/489
147
- .replace(/^(\d){1}/, '$$1')
148
- // replace chars which are not valid for typescript identifiers with whitespace
149
- .replace(/(^\s*[^a-zA-Z_$])|([^a-zA-Z_$\d])/g, ' ')
150
- // uppercase leading underscores followed by lowercase
151
- .replace(/^_[a-z]/g, function (match) { return match.toUpperCase(); })
152
- // remove non-leading underscores followed by lowercase (convert snake_case)
153
- .replace(/_[a-z]/g, function (match) { return match.substr(1, match.length).toUpperCase(); })
154
- // uppercase letters after digits, dollars
155
- .replace(/([\d$]+[a-zA-Z])/g, function (match) { return match.toUpperCase(); })
156
- // uppercase first letter after whitespace
157
- .replace(/\s+([a-zA-Z])/g, function (match) { return match.toUpperCase().trim(); })
158
- // remove remaining whitespace
159
- .replace(/\s/g, ''));
160
- }
161
- exports.toSafeString = toSafeString;
162
- function generateTypeName() {
163
- var parts = [];
164
- for (var _i = 0; _i < arguments.length; _i++) {
165
- parts[_i] = arguments[_i];
166
- }
167
- var str;
168
- // If the end of our string ends with something like `2XX`, the combination of `startCase` and
169
- // `camelCase` will transform it into `2Xx`.
170
- if (parts.length > 1) {
171
- var last = parts[parts.length - 1];
172
- if (last.match(/^(\d)XX$/)) {
173
- str = (0, lodash_startcase_1["default"])((0, lodash_camelcase_1["default"])(parts.slice(0, -1).join(' ')));
174
- str += " ".concat(last);
175
- }
176
- }
177
- if (!str) {
178
- str = (0, lodash_startcase_1["default"])((0, lodash_camelcase_1["default"])(parts.join(' ')));
179
- }
180
- if (RESERVED_WORDS.includes(str.toLowerCase())) {
181
- str = "$".concat(str);
182
- }
183
- return toSafeString(str);
184
- }
185
- exports.generateTypeName = generateTypeName;
@@ -1,111 +0,0 @@
1
- import type Storage from '../../storage';
2
- import type { InstallerOptions } from '../language';
3
- import type Oas from 'oas';
4
- import type { Operation } from 'oas';
5
- import type { ClassDeclaration, JSDocStructure, JSDocTagStructure, OptionalKind } from 'ts-morph';
6
- import { Project } from 'ts-morph';
7
- import CodeGeneratorLanguage from '../language';
8
- export interface TSGeneratorOptions {
9
- compilerTarget?: 'cjs' | 'esm';
10
- outputJS?: boolean;
11
- }
12
- interface OperationTypeHousing {
13
- operation: Operation;
14
- types: {
15
- params?: false | Record<'body' | 'formData' | 'metadata', string>;
16
- responses?: Record<string | number, {
17
- description?: string;
18
- type: string;
19
- }>;
20
- };
21
- }
22
- export default class TSGenerator extends CodeGeneratorLanguage {
23
- project: Project;
24
- outputJS: boolean;
25
- compilerTarget: 'cjs' | 'esm';
26
- types: Map<string, string>;
27
- files: Record<string, string>;
28
- sdk: ClassDeclaration;
29
- schemas: Record<string, {
30
- body?: any;
31
- metadata?: any;
32
- response?: Record<string, any>;
33
- } | Record<string, any>>;
34
- usesHTTPMethodRangeInterface: boolean;
35
- constructor(spec: Oas, specPath: string, identifier: string, opts?: TSGeneratorOptions);
36
- installer(storage: Storage, opts?: InstallerOptions): Promise<void>;
37
- /**
38
- * Compile the current OpenAPI definition into a TypeScript library.
39
- *
40
- */
41
- generator(): Promise<{
42
- [x: string]: string;
43
- }>;
44
- /**
45
- * Create our main SDK source file.
46
- *
47
- */
48
- createSourceFile(): import("ts-morph").SourceFile;
49
- /**
50
- * Create our main schemas file. This is where all of the JSON Schema that our TypeScript typing
51
- * infrastructure sources its data from. Without this there are no types.
52
- *
53
- */
54
- createSchemasFile(): import("ts-morph").SourceFile;
55
- /**
56
- * Create our main types file. This sources its data from the JSON Schema `schemas.ts` file and
57
- * will re-export types to be used in TypeScript implementations and IDE intellisense. This
58
- * typing work is functional with the `json-schema-to-ts` library.
59
- *
60
- * @see {@link https://npm.im/json-schema-to-ts}
61
- */
62
- createTypesFile(): import("ts-morph").SourceFile;
63
- /**
64
- * Add a new JSDoc `@tag` to an existing docblock.
65
- *
66
- */
67
- static addTagToDocblock(docblock: OptionalKind<JSDocStructure>, tag: OptionalKind<JSDocTagStructure>): {
68
- tags: OptionalKind<JSDocTagStructure>[];
69
- description?: string | import("ts-morph").WriterFunction;
70
- leadingTrivia?: string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[];
71
- trailingTrivia?: string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[];
72
- kind?: import("ts-morph").StructureKind.JSDoc;
73
- };
74
- /**
75
- * Create operation accessors on the SDK.
76
- *
77
- */
78
- createOperationAccessor(operation: Operation, operationId: string, paramTypes?: OperationTypeHousing['types']['params'], responseTypes?: OperationTypeHousing['types']['responses']): void;
79
- /**
80
- * Scour through the current OpenAPI definition and compile a store of every operation, along
81
- * with every HTTP method that's in use, and their available TypeScript types that we can use,
82
- * along with every HTTP method that's in use.
83
- *
84
- */
85
- loadOperationsAndMethods(): {
86
- operations: Record<string, OperationTypeHousing>;
87
- methods: Set<unknown>;
88
- };
89
- /**
90
- * Compile the parameter (path, query, cookie, and header) schemas for an API operation into
91
- * usable TypeScript types.
92
- *
93
- */
94
- prepareParameterTypesForOperation(operation: Operation, operationId: string): false | Record<"formData" | "body" | "metadata", string>;
95
- /**
96
- * Compile the response schemas for an API operation into usable TypeScript types.
97
- *
98
- */
99
- prepareResponseTypesForOperation(operation: Operation, operationId: string): {
100
- [x: string]: {
101
- type: string;
102
- description: any;
103
- };
104
- };
105
- /**
106
- * Add a given schema into our schema dataset that we'll be be exporting as types.
107
- *
108
- */
109
- addSchemaToExport(schema: any, typeName: string, pointer: string): void;
110
- }
111
- export {};