api 4.4.0 → 5.0.0-beta.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 (70) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +18 -5
  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 +762 -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 +53 -0
  37. package/dist/fetcher.js +149 -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 +65 -25
  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 +798 -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 +126 -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 -209
  66. package/src/index.js +0 -175
  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,47 @@
1
+ import type Oas from 'oas';
2
+ import type Storage from '../storage';
3
+ import { PACKAGE_NAME, PACKAGE_VERSION } from '../../packageInfo';
4
+
5
+ export interface InstallerOptions {
6
+ /**
7
+ * Will initiate a dry run install process. Used for simulating installations within a unit test.
8
+ */
9
+ dryRun?: boolean;
10
+
11
+ /**
12
+ * Used for stubbing out the logger that we use within the installation process so it can be
13
+ * easily introspected without having to mock out `console.*`.
14
+ */
15
+ logger?: (msg: string) => void;
16
+ }
17
+
18
+ export default abstract class CodeGeneratorLanguage {
19
+ spec: Oas;
20
+
21
+ specPath: string;
22
+
23
+ identifier: string;
24
+
25
+ userAgent: string;
26
+
27
+ requiredPackages: Record<string, { reason: string; url: string }>;
28
+
29
+ constructor(spec: Oas, specPath: string, identifier: string) {
30
+ this.spec = spec;
31
+ this.specPath = specPath;
32
+
33
+ // User agents should be contextual to the spec in question and the version of `api` that was
34
+ // used to generate the SDK. For example, this'll look like `petstore/1.0.0 (api/4.2.0)` for
35
+ // a `petstore` spec installed on api@4.2.0.
36
+ const info = spec.getDefinition().info;
37
+ this.userAgent = `${identifier}/${info.version} (${PACKAGE_NAME}/${PACKAGE_VERSION})`;
38
+ }
39
+
40
+ abstract generator(): Promise<Record<string, string>>;
41
+
42
+ abstract installer(storage: Storage, opts?: InstallerOptions): Promise<void>;
43
+
44
+ hasRequiredPackages() {
45
+ return Boolean(Object.keys(this.requiredPackages));
46
+ }
47
+ }