api 4.5.1 → 5.0.0-beta.2

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 (70) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +32 -162
  3. package/bin/api +2 -0
  4. package/dist/bin.d.ts +1 -0
  5. package/dist/bin.js +91 -0
  6. package/dist/cache.d.ts +30 -0
  7. package/dist/cache.js +217 -0
  8. package/dist/cli/codegen/index.d.ts +4 -0
  9. package/dist/cli/codegen/index.js +23 -0
  10. package/dist/cli/codegen/language.d.ts +27 -0
  11. package/dist/cli/codegen/language.js +19 -0
  12. package/dist/cli/codegen/languages/typescript.d.ts +99 -0
  13. package/dist/cli/codegen/languages/typescript.js +769 -0
  14. package/dist/cli/commands/index.d.ts +4 -0
  15. package/dist/cli/commands/index.js +9 -0
  16. package/dist/cli/commands/install.d.ts +3 -0
  17. package/dist/cli/commands/install.js +230 -0
  18. package/dist/cli/lib/prompt.d.ts +9 -0
  19. package/dist/cli/lib/prompt.js +81 -0
  20. package/dist/cli/logger.d.ts +1 -0
  21. package/dist/cli/logger.js +16 -0
  22. package/dist/cli/storage.d.ts +105 -0
  23. package/dist/cli/storage.js +264 -0
  24. package/dist/core/getJSONSchemaDefaults.d.ts +15 -0
  25. package/dist/core/getJSONSchemaDefaults.js +62 -0
  26. package/dist/core/index.d.ts +32 -0
  27. package/dist/core/index.js +143 -0
  28. package/dist/core/parseResponse.d.ts +1 -0
  29. package/dist/core/parseResponse.js +65 -0
  30. package/dist/core/prepareAuth.d.ts +5 -0
  31. package/dist/core/prepareAuth.js +55 -0
  32. package/dist/core/prepareParams.d.ts +24 -0
  33. package/dist/core/prepareParams.js +351 -0
  34. package/dist/core/prepareServer.d.ts +13 -0
  35. package/dist/core/prepareServer.js +50 -0
  36. package/dist/fetcher.d.ts +54 -0
  37. package/dist/fetcher.js +165 -0
  38. package/dist/index.d.ts +6 -0
  39. package/dist/index.js +276 -0
  40. package/dist/packageInfo.d.ts +2 -0
  41. package/dist/packageInfo.js +6 -0
  42. package/package.json +67 -28
  43. package/src/.sink.d.ts +1 -0
  44. package/src/bin.ts +20 -0
  45. package/src/cache.ts +212 -0
  46. package/src/cli/codegen/index.ts +31 -0
  47. package/src/cli/codegen/language.ts +47 -0
  48. package/src/cli/codegen/languages/typescript.ts +807 -0
  49. package/src/cli/commands/index.ts +5 -0
  50. package/src/cli/commands/install.ts +196 -0
  51. package/src/cli/lib/prompt.ts +29 -0
  52. package/src/cli/logger.ts +10 -0
  53. package/src/cli/storage.ts +297 -0
  54. package/src/core/getJSONSchemaDefaults.ts +74 -0
  55. package/src/core/index.ts +108 -0
  56. package/src/{lib/parseResponse.js → core/parseResponse.ts} +5 -7
  57. package/src/core/prepareAuth.ts +85 -0
  58. package/src/core/prepareParams.ts +338 -0
  59. package/src/{lib/prepareServer.js → core/prepareServer.ts} +13 -12
  60. package/src/fetcher.ts +141 -0
  61. package/src/index.ts +212 -0
  62. package/src/packageInfo.ts +3 -0
  63. package/src/typings.d.ts +3 -0
  64. package/tsconfig.json +24 -0
  65. package/src/cache.js +0 -225
  66. package/src/index.js +0 -177
  67. package/src/lib/getSchema.js +0 -34
  68. package/src/lib/index.js +0 -11
  69. package/src/lib/prepareAuth.js +0 -69
  70. package/src/lib/prepareParams.js +0 -198
@@ -0,0 +1,99 @@
1
+ import type Oas from 'oas';
2
+ import type { Operation } from 'oas';
3
+ import type { JSONSchema, SchemaObject } from 'oas/@types/rmoas.types';
4
+ import type { ClassDeclaration, MethodDeclaration } from 'ts-morph';
5
+ import type Storage from '../../storage';
6
+ import type { InstallerOptions } from '../language';
7
+ import CodeGeneratorLanguage from '../language';
8
+ import { Project } from 'ts-morph';
9
+ declare type OperationTypeHousing = {
10
+ types: {
11
+ params?: false | Record<'body' | 'formData' | 'metadata', string>;
12
+ responses?: Record<string, string>;
13
+ };
14
+ operation: Operation;
15
+ };
16
+ export default class TSGenerator extends CodeGeneratorLanguage {
17
+ project: Project;
18
+ outputJS: boolean;
19
+ compilerTarget: 'cjs' | 'esm';
20
+ types: Map<string, string>;
21
+ files: Record<string, string>;
22
+ methodGenerics: Map<string, MethodDeclaration>;
23
+ sdk: ClassDeclaration;
24
+ schemas: Map<string, {
25
+ schema: SchemaObject;
26
+ name: string;
27
+ tsType?: string;
28
+ }>;
29
+ constructor(spec: Oas, specPath: string, identifier: string, opts?: {
30
+ outputJS?: boolean;
31
+ compilerTarget?: 'cjs' | 'esm';
32
+ });
33
+ static formatter(content: string): string;
34
+ installer(storage: Storage, opts?: InstallerOptions): Promise<void>;
35
+ /**
36
+ * Compile the current OpenAPI definition into a TypeScript library.
37
+ *
38
+ */
39
+ generator(): Promise<{
40
+ [x: string]: string;
41
+ }>;
42
+ /**
43
+ * Create a generic HTTP method accessor on the SDK.
44
+ *
45
+ * @param method
46
+ */
47
+ createGenericMethodAccessor(method: string): void;
48
+ /**
49
+ * Create operation accessors on the SDK.
50
+ *
51
+ * @param operation
52
+ * @param operationId
53
+ * @param paramTypes
54
+ * @param responseTypes
55
+ */
56
+ createOperationAccessor(operation: Operation, operationId: string, paramTypes?: OperationTypeHousing['types']['params'], responseTypes?: OperationTypeHousing['types']['responses']): void;
57
+ /**
58
+ * Convert a JSON Schema object into a readily available TypeScript type or interface along with
59
+ * any `$ref` pointers that are in use and turn those into TS types too.
60
+ *
61
+ * Under the hood this uses https://npm.im/json-schema-to-typescript for all composition and
62
+ * conversion.
63
+ *
64
+ * @param schema
65
+ * @param name
66
+ */
67
+ convertJSONSchemaToTypescript(schema: JSONSchema, name: string): Promise<{
68
+ primaryType: string;
69
+ }>;
70
+ /**
71
+ * Scour through the current OpenAPI definition and compile a store of every operation, along
72
+ * with every HTTP method that's in use, and their available TypeScript types that we can use,
73
+ * along with every HTTP method that's in use.
74
+ *
75
+ */
76
+ loadOperationsAndMethods(): Promise<{
77
+ operations: Record<string, OperationTypeHousing>;
78
+ methods: Set<unknown>;
79
+ }>;
80
+ /**
81
+ * Compile the parameter (path, query, cookie, and header) schemas for an API operation into
82
+ * usable TypeScript types.
83
+ *
84
+ * @param operation
85
+ * @param operationId
86
+ */
87
+ prepareParameterTypesForOperation(operation: Operation, operationId: string): false | Record<"formData" | "body" | "metadata", string>;
88
+ /**
89
+ * Compile the response schemas for an API operation into usable TypeScript types.
90
+ *
91
+ * @todo what does this do for a spec that has no responses?
92
+ * @param operation
93
+ * @param operationId
94
+ */
95
+ prepareResponseTypesForOperation(operation: Operation, operationId: string): {
96
+ [x: string]: string;
97
+ };
98
+ }
99
+ export {};