api 7.0.0-beta.1 → 7.0.0-beta.11

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 (55) hide show
  1. package/README.md +1 -2
  2. package/dist/bin.js +8 -1
  3. package/dist/bin.js.map +1 -1
  4. package/dist/codegen/codegenerator.d.ts +36 -1
  5. package/dist/codegen/codegenerator.d.ts.map +1 -1
  6. package/dist/codegen/codegenerator.js +66 -0
  7. package/dist/codegen/codegenerator.js.map +1 -1
  8. package/dist/codegen/factory.js.map +1 -1
  9. package/dist/codegen/languages/typescript/index.d.ts +32 -4
  10. package/dist/codegen/languages/typescript/index.d.ts.map +1 -1
  11. package/dist/codegen/languages/typescript/index.js +222 -62
  12. package/dist/codegen/languages/typescript/index.js.map +1 -1
  13. package/dist/codegen/languages/typescript/util.d.ts.map +1 -1
  14. package/dist/codegen/languages/typescript/util.js +1 -3
  15. package/dist/codegen/languages/typescript/util.js.map +1 -1
  16. package/dist/commands/install.d.ts.map +1 -1
  17. package/dist/commands/install.js +67 -54
  18. package/dist/commands/install.js.map +1 -1
  19. package/dist/commands/list.js.map +1 -1
  20. package/dist/commands/uninstall.d.ts.map +1 -1
  21. package/dist/commands/uninstall.js +7 -10
  22. package/dist/commands/uninstall.js.map +1 -1
  23. package/dist/fetcher.d.ts +17 -17
  24. package/dist/fetcher.d.ts.map +1 -1
  25. package/dist/fetcher.js +7 -1
  26. package/dist/fetcher.js.map +1 -1
  27. package/dist/lib/isCI.d.ts +8 -0
  28. package/dist/lib/isCI.d.ts.map +1 -0
  29. package/dist/lib/isCI.js +18 -0
  30. package/dist/lib/isCI.js.map +1 -0
  31. package/dist/lib/prompt.d.ts +1 -1
  32. package/dist/lib/prompt.d.ts.map +1 -1
  33. package/dist/lib/prompt.js +33 -8
  34. package/dist/lib/prompt.js.map +1 -1
  35. package/dist/lib/suggestedOperations.d.ts +31 -0
  36. package/dist/lib/suggestedOperations.d.ts.map +1 -0
  37. package/dist/lib/suggestedOperations.js +108 -0
  38. package/dist/lib/suggestedOperations.js.map +1 -0
  39. package/dist/lockfileSchema.d.ts +1 -1
  40. package/dist/lockfileSchema.d.ts.map +1 -1
  41. package/dist/logger.d.ts +2 -0
  42. package/dist/logger.d.ts.map +1 -1
  43. package/dist/logger.js +5 -1
  44. package/dist/logger.js.map +1 -1
  45. package/dist/packageInfo.d.ts +1 -1
  46. package/dist/packageInfo.d.ts.map +1 -1
  47. package/dist/packageInfo.js +1 -1
  48. package/dist/packageInfo.js.map +1 -1
  49. package/dist/storage.d.ts +8 -6
  50. package/dist/storage.d.ts.map +1 -1
  51. package/dist/storage.js +28 -6
  52. package/dist/storage.js.map +1 -1
  53. package/legacy-require-handler.cjs +29 -0
  54. package/legacy-require-handler.d.cts +2 -0
  55. package/package.json +44 -37
package/README.md CHANGED
@@ -39,8 +39,7 @@ petstore.listPets().then(({ data }) => {
39
39
  The ESM syntax is supported as well:
40
40
 
41
41
  ```js
42
- import api from 'api';
43
- const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8');
42
+ import petstore from '@api/petstore';
44
43
 
45
44
  petstore.listPets().then(({ data }) => {
46
45
  console.log(`My pets name is ${data[0].name}!`);
package/dist/bin.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import { Command } from 'commander';
2
+ import updateNotifier from 'update-notifier';
2
3
  import commands from './commands/index.js';
4
+ import logger from './logger.js';
3
5
  import * as pkg from './packageInfo.js';
6
+ updateNotifier({ pkg: { name: pkg.PACKAGE_NAME, version: pkg.PACKAGE_VERSION } }).notify();
4
7
  (async () => {
5
8
  const program = new Command();
6
9
  program.name(pkg.PACKAGE_NAME);
@@ -13,6 +16,10 @@ import * as pkg from './packageInfo.js';
13
16
  Object.entries(commands).forEach(([, cmd]) => {
14
17
  program.addCommand(cmd);
15
18
  });
16
- await program.parseAsync(process.argv);
19
+ await program.parseAsync(process.argv).catch(err => {
20
+ if (err.message)
21
+ logger(err.message, true);
22
+ process.exit(1);
23
+ });
17
24
  })();
18
25
  //# sourceMappingURL=bin.js.map
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAExC,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAErC;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAoB,EAAE,EAAE;QAC9D,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC,CAAC,EAAE,CAAC"}
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAE7C,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAExC,cAAc,CAAC,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,GAAG,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAE3F,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAErC;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAoB,EAAE,EAAE;QAC9D,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACjD,IAAI,GAAG,CAAC,OAAO;YAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC"}
@@ -2,16 +2,50 @@ import type { InstallerOptions } from './factory.js';
2
2
  import type Storage from '../storage.js';
3
3
  import type Oas from 'oas';
4
4
  export default abstract class CodeGenerator {
5
+ /** The associated API definition */
5
6
  spec: Oas;
7
+ /**
8
+ * The path to the API definion (might be a local path, a URL, or an API registry identifier)
9
+ * @example https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json
10
+ * @example @petstore/v1.0#n6kvf10vakpemvplx
11
+ * @example ./petstore.json
12
+ */
6
13
  specPath: string;
14
+ /**
15
+ * The user-specified identifier for the SDK,
16
+ * used as the directory name in the `.api/apis` directory
17
+ * where the SDK source code is located.
18
+ */
7
19
  identifier: string;
20
+ /** The user agent which is set for all outgoing fetch requests */
8
21
  userAgent: string;
22
+ /**
23
+ * The license associated with the SDK.
24
+ * This is extrapolated from the API definition file.
25
+ */
26
+ spdxLicense?: string;
27
+ /**
28
+ * Contact info for the API and/or SDK author in case users need support.
29
+ * This is extrapolated from the API definition file.
30
+ */
31
+ apiContact: {
32
+ name?: string;
33
+ url?: string;
34
+ };
35
+ /**
36
+ * An object containing any downstream packages that are required
37
+ * for building/executing the SDK.
38
+ */
9
39
  requiredPackages: Record<string, {
10
- dependencyType: 'production' | 'development';
40
+ dependencyType: 'development' | 'production';
11
41
  reason: string;
12
42
  url?: string;
13
43
  version: string;
14
44
  }>;
45
+ /**
46
+ * An example code snippet that a user can run to get started with the SDK.
47
+ */
48
+ exampleCodeSnippet?: string | false;
15
49
  constructor(spec: Oas, specPath: string, identifier: string);
16
50
  abstract generate(): Promise<Record<string, string>>;
17
51
  abstract install(storage: Storage, opts?: InstallerOptions): Promise<void>;
@@ -24,6 +58,7 @@ export default abstract class CodeGenerator {
24
58
  */
25
59
  static uninstall(storage: Storage, opts?: InstallerOptions): Promise<void>;
26
60
  abstract compile(storage: Storage, opts?: InstallerOptions): Promise<void>;
61
+ abstract getExampleCodeSnippet(): Promise<string | false>;
27
62
  hasRequiredPackages(): boolean;
28
63
  }
29
64
  //# sourceMappingURL=codegenerator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codegenerator.d.ts","sourceRoot":"","sources":["../../src/codegen/codegenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAI3B,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,aAAa;IACzC,IAAI,EAAE,GAAG,CAAC;IAEV,QAAQ,EAAE,MAAM,CAAC;IAEjB,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,MAAM,CAAC;IAElB,gBAAgB,EAAG,MAAM,CACvB,MAAM,EACN;QACE,cAAc,EAAE,YAAY,GAAG,aAAa,CAAC;QAC7C,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;Q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MAAM,CACvB,MAAM,EACN;QACE,cAAc,EAAE,aAAa,GAAG,YAAY,CAAC;QAC7C,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CACF,CAAC;IAEF;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;gBAExB,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAgE3D,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEpD,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1E;;;;;;OAMG;WAEU,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhF,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1E,QAAQ,CAAC,qBAAqB,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;IAEzD,mBAAmB;CAGpB"}
@@ -1,10 +1,42 @@
1
+ import { findLicense } from 'license';
1
2
  import { PACKAGE_NAME, PACKAGE_VERSION } from '../packageInfo.js';
2
3
  export default class CodeGenerator {
4
+ /** The associated API definition */
3
5
  spec;
6
+ /**
7
+ * The path to the API definion (might be a local path, a URL, or an API registry identifier)
8
+ * @example https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json
9
+ * @example @petstore/v1.0#n6kvf10vakpemvplx
10
+ * @example ./petstore.json
11
+ */
4
12
  specPath;
13
+ /**
14
+ * The user-specified identifier for the SDK,
15
+ * used as the directory name in the `.api/apis` directory
16
+ * where the SDK source code is located.
17
+ */
5
18
  identifier;
19
+ /** The user agent which is set for all outgoing fetch requests */
6
20
  userAgent;
21
+ /**
22
+ * The license associated with the SDK.
23
+ * This is extrapolated from the API definition file.
24
+ */
25
+ spdxLicense;
26
+ /**
27
+ * Contact info for the API and/or SDK author in case users need support.
28
+ * This is extrapolated from the API definition file.
29
+ */
30
+ apiContact = {};
31
+ /**
32
+ * An object containing any downstream packages that are required
33
+ * for building/executing the SDK.
34
+ */
7
35
  requiredPackages;
36
+ /**
37
+ * An example code snippet that a user can run to get started with the SDK.
38
+ */
39
+ exampleCodeSnippet;
8
40
  constructor(spec, specPath, identifier) {
9
41
  this.spec = spec;
10
42
  this.specPath = specPath;
@@ -27,6 +59,40 @@ export default class CodeGenerator {
27
59
  if (JSON.stringify(spec.api).includes('"$ref":"#/')) {
28
60
  throw new Error('Sorry, this library does not yet support generating an SDK for an OpenAPI definition that contains circular references.');
29
61
  }
62
+ const infoObject = this.spec.api.info;
63
+ if (infoObject?.license?.name || infoObject?.license?.identifier) {
64
+ let spdxLicense;
65
+ if (infoObject?.license?.identifier) {
66
+ spdxLicense = infoObject?.license?.identifier;
67
+ }
68
+ else {
69
+ // Though `name` is required by the OpenAPI specification but most people seem to use `name`
70
+ // instead `identifier` for their licensing identifier so if they've done this we should
71
+ // try to make the license name recognizable by the `license` package. For example this'll
72
+ // change "Apache 2.0" to the SPDX-recognized "Apache-2.0".
73
+ spdxLicense = infoObject?.license?.name.replace(/ /g, '-');
74
+ }
75
+ // If the license they've got has too many matches we shouldn't try to pick a license because
76
+ // we'll run the risk of licensing it under a license they didn't intend.
77
+ if (findLicense(spdxLicense).length === 1) {
78
+ this.spdxLicense = spdxLicense;
79
+ }
80
+ }
81
+ if (infoObject?.contact) {
82
+ if (infoObject.contact?.name || infoObject.contact?.email) {
83
+ if (infoObject.contact?.name && infoObject.contact?.email) {
84
+ this.apiContact.name = `${infoObject.contact.name} <${infoObject.contact.email}>`;
85
+ }
86
+ else {
87
+ this.apiContact.name = infoObject.contact.email
88
+ ? `<${infoObject.contact.email}>`
89
+ : (infoObject.contact.name ?? undefined);
90
+ }
91
+ }
92
+ if (infoObject.contact?.url) {
93
+ this.apiContact.url = infoObject.contact.url;
94
+ }
95
+ }
30
96
  }
31
97
  /**
32
98
  * It would be better if this were an abstract function but TS/JS doesn't have support for that so
@@ -1 +1 @@
1
- {"version":3,"file":"codegenerator.js","sourceRoot":"","sources":["../../src/codegen/codegenerator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAElE,MAAM,CAAC,OAAO,OAAgB,aAAa;IACzC,IAAI,CAAM;IAEV,QAAQ,CAAS;IAEjB,UAAU,CAAS;IAEnB,SAAS,CAAS;IAElB,gBAAgB,CAQd;IAEF,YAAY,IAAS,EAAE,QAAgB,EAAE,UAAkB;QACzD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7B,6FAA6F;QAC7F,4FAA4F;QAC5F,4CAA4C;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC;QACvC,IAAI,CAAC,SAAS,GAAG,GAAG,UAAU,IAAI,IAAI,CAAC,OAAO,KAAK,YAAY,IAAI,eAAe,GAAG,CAAC;QAEtF;;;;;;;;;WASG;QACH,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YACnD,MAAM,IAAI,KAAK,CACb,yHAAyH,CAC1H,CAAC;SACH;IACH,CAAC;IAMD;;;;;;OAMG;IACH,6DAA6D;IAC7D,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAgB,EAAE,IAAuB;QAC9D,MAAM,IAAI,SAAS,CAAC,oEAAoE,CAAC,CAAC;IAC5F,CAAC;I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rE;AACH,CAAC"}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/codegen/factory.ts"],"names":[],"mappings":"AAIA,OAAO,WAAW,MAAM,iCAAiC,CAAC;AAE1D,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,EAAE,EAAE,IAAI;CACA,CAAC;AAmBX,MAAM,UAAU,cAAc,CAC5B,QAA2B,EAC3B,IAAS,EACT,QAAgB,EAChB,UAAkB;IAElB,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,kBAAkB,CAAC,EAAE;YACxB,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;QAErD;YACE,MAAM,IAAI,SAAS,CAAC,kCAAkC,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,QAA2B,EAC3B,OAAgB,EAChB,OAAyB,EAAE;IAE3B,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,kBAAkB,CAAC,EAAE;YACxB,OAAO,WAAW,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE9C;YACE,MAAM,IAAI,SAAS,CAAC,kCAAkC,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;AACH,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { InstallerOptions } from '../../factory.js';
2
2
  import type Oas from 'oas';
3
- import type { ClassDeclaration } from 'ts-morph';
3
+ import type { ClassDeclaration, SourceFile } from 'ts-morph';
4
4
  import { Project } from 'ts-morph';
5
5
  import Storage from '../../../storage.js';
6
6
  import CodeGenerator from '../../codegenerator.js';
@@ -30,26 +30,54 @@ export default class TSGenerator extends CodeGenerator {
30
30
  generate(): Promise<{
31
31
  [x: string]: string;
32
32
  }>;
33
+ getExampleCodeSnippet(): Promise<string | false>;
34
+ /**
35
+ * Create our main `index.ts` file that will be the entrypoint for our SDK.
36
+ * This file will be used to export the SDK and any types that are generated.
37
+ *
38
+ */
39
+ private createIndexSource;
33
40
  /**
34
41
  * Create our main SDK source file.
35
42
  *
36
43
  */
37
44
  private createSDKSource;
45
+ /**
46
+ * Create an IIFE export of our SDK in the SDK source file so users can do
47
+ * `import sdk from '<package>'` and have a ready-to-go instance of their SDK -- eliminating them
48
+ * having to create an instance with `new SDK()`.
49
+ *
50
+ * This will also fill our a JSDoc heading on the IIFE we're creating based on various pieces of
51
+ * data that may be present in the OpenAPI definition `info` object.
52
+ *
53
+ * Additionally if a license in `info.license` is recognized by the SPDX we'll also create a
54
+ * `LICENSE` file in for their generated SDK. We're only supporting SPDX-recognized licenses for
55
+ * this because we otherwise have no idea what the license represents and we should be extremely
56
+ * cautious around assuming intent with software licensing.
57
+ *
58
+ * @see {@link https://spdx.org/licenses/}
59
+ */
60
+ createSDKExport(sourceFile: SourceFile): SourceFile;
61
+ /**
62
+ * Creates a `.gitignore` file to prevent the `dist/` directory from being tracked.
63
+ *
64
+ */
65
+ createGitIgnore(): SourceFile;
38
66
  /**
39
67
  * Create the `tsconfig.json` file that will allow this SDK to be compiled for use.
40
68
  *
41
69
  */
42
- createTSConfig(): import("ts-morph").SourceFile;
70
+ createTSConfig(): SourceFile;
43
71
  /**
44
72
  * Create the `package.json` file that will ultimately make this SDK available to use.
45
73
  *
46
74
  */
47
- createPackageJSON(): import("ts-morph").SourceFile;
75
+ createPackageJSON(): SourceFile;
48
76
  /**
49
77
  * Create a placeholder `README.md` file in the repository, with information on how to use/administer the SDK.
50
78
  *
51
79
  */
52
- createREADME(): import("ts-morph").SourceFile;
80
+ createREADME(): Promise<SourceFile>;
53
81
  /**
54
82
  * Create our main schemas file. This is where all of the JSON Schema that our TypeScript typing
55
83
  * infrastructure sources its data from. Without this there are no types.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/codegen/languages/typescript/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC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