@goast/typescript 0.2.19 → 0.3.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 (150) hide show
  1. package/README.md +41 -11
  2. package/assets/client/angular/angular-service.utils.ts +80 -80
  3. package/assets/client/angular/request-builder.ts +372 -372
  4. package/assets/client/fetch/fetch-client.utils.ts +52 -52
  5. package/assets/stubs/easy-network-stub/easy-network-stub.utils.ts +258 -258
  6. package/cjs/index.js +1 -0
  7. package/cjs/lib/ast/nodes/argument.js +1 -1
  8. package/cjs/lib/ast/nodes/array-type.js +1 -1
  9. package/cjs/lib/ast/nodes/call.js +1 -1
  10. package/cjs/lib/ast/nodes/class.js +1 -1
  11. package/cjs/lib/ast/nodes/constructor-parameter.js +1 -1
  12. package/cjs/lib/ast/nodes/decorator.js +1 -1
  13. package/cjs/lib/ast/nodes/enum-value.js +1 -1
  14. package/cjs/lib/ast/nodes/enum.js +1 -1
  15. package/cjs/lib/ast/nodes/export.js +1 -1
  16. package/cjs/lib/ast/nodes/function.js +1 -1
  17. package/cjs/lib/ast/nodes/generic-parameter.js +1 -1
  18. package/cjs/lib/ast/nodes/indexer.js +1 -1
  19. package/cjs/lib/ast/nodes/interface.js +1 -1
  20. package/cjs/lib/ast/nodes/intersection-type.js +1 -1
  21. package/cjs/lib/ast/nodes/lookup-type.js +1 -1
  22. package/cjs/lib/ast/nodes/method.js +1 -1
  23. package/cjs/lib/ast/nodes/parameter.js +1 -1
  24. package/cjs/lib/ast/nodes/property.js +2 -2
  25. package/cjs/lib/ast/nodes/reference.js +1 -1
  26. package/cjs/lib/ast/nodes/string.js +1 -1
  27. package/cjs/lib/ast/nodes/tuple.js +1 -1
  28. package/cjs/lib/ast/nodes/type-alias.js +1 -1
  29. package/cjs/lib/ast/nodes/typeof.js +1 -1
  30. package/cjs/lib/ast/nodes/union-type.js +1 -1
  31. package/cjs/lib/ast/nodes/variable.js +1 -1
  32. package/cjs/lib/ast/utils/get-type-script-builder-options.js +2 -3
  33. package/cjs/lib/ast/utils/to-ts-node.js +1 -2
  34. package/cjs/lib/ast/utils/write-ts-generic-parameters.js +1 -2
  35. package/cjs/lib/ast/utils/write-ts-members.js +1 -2
  36. package/cjs/lib/ast/utils/write-ts-nodes.js +2 -3
  37. package/cjs/lib/ast/utils/write-ts-parameters.js +1 -2
  38. package/cjs/lib/file-builder.js +2 -2
  39. package/cjs/lib/generators/models/model-generator.js +13 -3
  40. package/cjs/lib/generators/models/models-generator.js +18 -7
  41. package/cjs/lib/generators/models/models.js +13 -2
  42. package/cjs/lib/generators/services/angular-services/angular-service-generator.js +17 -15
  43. package/cjs/lib/generators/services/angular-services/angular-services-generator.js +17 -12
  44. package/cjs/lib/generators/services/angular-services/models.js +19 -3
  45. package/cjs/lib/generators/services/angular-services/refs.js +2 -3
  46. package/cjs/lib/generators/services/easy-network-stub/easy-network-stub-generator.js +13 -12
  47. package/cjs/lib/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -11
  48. package/cjs/lib/generators/services/easy-network-stub/models.js +10 -2
  49. package/cjs/lib/generators/services/easy-network-stub/refs.js +2 -3
  50. package/cjs/lib/generators/services/fetch-clients/fetch-client-generator.js +16 -13
  51. package/cjs/lib/generators/services/fetch-clients/fetch-clients-generator.js +48 -13
  52. package/cjs/lib/generators/services/fetch-clients/models.js +13 -1
  53. package/cjs/lib/generators/services/fetch-clients/refs.js +2 -3
  54. package/cjs/lib/import-collection.js +1 -1
  55. package/cjs/lib/utils.js +5 -6
  56. package/esm/index.js +1 -0
  57. package/esm/lib/ast/nodes/argument.js +1 -1
  58. package/esm/lib/ast/nodes/array-type.js +1 -1
  59. package/esm/lib/ast/nodes/call.js +1 -1
  60. package/esm/lib/ast/nodes/class.js +1 -1
  61. package/esm/lib/ast/nodes/constructor-parameter.js +1 -1
  62. package/esm/lib/ast/nodes/decorator.js +1 -1
  63. package/esm/lib/ast/nodes/enum-value.js +1 -1
  64. package/esm/lib/ast/nodes/enum.js +1 -1
  65. package/esm/lib/ast/nodes/export.js +1 -1
  66. package/esm/lib/ast/nodes/function.js +1 -1
  67. package/esm/lib/ast/nodes/generic-parameter.js +1 -1
  68. package/esm/lib/ast/nodes/indexer.js +1 -1
  69. package/esm/lib/ast/nodes/interface.js +1 -1
  70. package/esm/lib/ast/nodes/intersection-type.js +1 -1
  71. package/esm/lib/ast/nodes/lookup-type.js +1 -1
  72. package/esm/lib/ast/nodes/method.js +1 -1
  73. package/esm/lib/ast/nodes/parameter.js +1 -1
  74. package/esm/lib/ast/nodes/property.js +2 -2
  75. package/esm/lib/ast/nodes/reference.js +1 -1
  76. package/esm/lib/ast/nodes/string.js +1 -1
  77. package/esm/lib/ast/nodes/tuple.js +1 -1
  78. package/esm/lib/ast/nodes/type-alias.js +1 -1
  79. package/esm/lib/ast/nodes/typeof.js +1 -1
  80. package/esm/lib/ast/nodes/union-type.js +1 -1
  81. package/esm/lib/ast/nodes/variable.js +1 -1
  82. package/esm/lib/ast/utils/get-type-script-builder-options.js +1 -1
  83. package/esm/lib/generators/models/model-generator.js +13 -3
  84. package/esm/lib/generators/models/models-generator.js +18 -7
  85. package/esm/lib/generators/models/models.js +13 -2
  86. package/esm/lib/generators/services/angular-services/angular-service-generator.js +17 -15
  87. package/esm/lib/generators/services/angular-services/angular-services-generator.js +17 -12
  88. package/esm/lib/generators/services/angular-services/models.js +19 -3
  89. package/esm/lib/generators/services/angular-services/refs.js +1 -1
  90. package/esm/lib/generators/services/easy-network-stub/easy-network-stub-generator.js +13 -12
  91. package/esm/lib/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -11
  92. package/esm/lib/generators/services/easy-network-stub/models.js +10 -2
  93. package/esm/lib/generators/services/easy-network-stub/refs.js +1 -1
  94. package/esm/lib/generators/services/fetch-clients/fetch-client-generator.js +16 -13
  95. package/esm/lib/generators/services/fetch-clients/fetch-clients-generator.js +46 -11
  96. package/esm/lib/generators/services/fetch-clients/models.js +13 -1
  97. package/esm/lib/generators/services/fetch-clients/refs.js +1 -1
  98. package/esm/lib/import-collection.js +1 -1
  99. package/package.json +8 -3
  100. package/types/index.d.ts +1 -0
  101. package/types/lib/ast/nodes/argument.d.ts +1 -1
  102. package/types/lib/ast/nodes/array-type.d.ts +1 -1
  103. package/types/lib/ast/nodes/arrow-function.d.ts +1 -1
  104. package/types/lib/ast/nodes/call.d.ts +1 -1
  105. package/types/lib/ast/nodes/class.d.ts +1 -1
  106. package/types/lib/ast/nodes/constructor-parameter.d.ts +1 -1
  107. package/types/lib/ast/nodes/constructor.d.ts +1 -1
  108. package/types/lib/ast/nodes/decorator.d.ts +2 -2
  109. package/types/lib/ast/nodes/doc.d.ts +1 -1
  110. package/types/lib/ast/nodes/enum-value.d.ts +2 -2
  111. package/types/lib/ast/nodes/enum.d.ts +1 -1
  112. package/types/lib/ast/nodes/export.d.ts +2 -2
  113. package/types/lib/ast/nodes/function-type.d.ts +1 -1
  114. package/types/lib/ast/nodes/function.d.ts +1 -1
  115. package/types/lib/ast/nodes/generic-parameter.d.ts +1 -1
  116. package/types/lib/ast/nodes/indexer.d.ts +1 -1
  117. package/types/lib/ast/nodes/interface.d.ts +1 -1
  118. package/types/lib/ast/nodes/intersection-type.d.ts +1 -1
  119. package/types/lib/ast/nodes/lookup-type.d.ts +1 -1
  120. package/types/lib/ast/nodes/method.d.ts +2 -2
  121. package/types/lib/ast/nodes/object-type.d.ts +1 -1
  122. package/types/lib/ast/nodes/object.d.ts +1 -1
  123. package/types/lib/ast/nodes/parameter.d.ts +1 -1
  124. package/types/lib/ast/nodes/property-accessor.d.ts +2 -2
  125. package/types/lib/ast/nodes/property.d.ts +15 -15
  126. package/types/lib/ast/nodes/reference.d.ts +4 -4
  127. package/types/lib/ast/nodes/string.d.ts +1 -1
  128. package/types/lib/ast/nodes/tuple.d.ts +1 -1
  129. package/types/lib/ast/nodes/type-alias.d.ts +1 -1
  130. package/types/lib/ast/nodes/typeof.d.ts +2 -2
  131. package/types/lib/ast/nodes/union-type.d.ts +1 -1
  132. package/types/lib/ast/nodes/variable.d.ts +1 -1
  133. package/types/lib/ast/references/angular.d.ts +8 -8
  134. package/types/lib/ast/references/easy-network-stub.d.ts +6 -6
  135. package/types/lib/ast/references/rxjs.d.ts +5 -5
  136. package/types/lib/ast/references/typescript.d.ts +46 -46
  137. package/types/lib/common-results.d.ts +1 -0
  138. package/types/lib/config.d.ts +53 -9
  139. package/types/lib/generators/models/model-generator.d.ts +1 -1
  140. package/types/lib/generators/models/models.d.ts +43 -8
  141. package/types/lib/generators/services/angular-services/angular-services-generator.d.ts +1 -1
  142. package/types/lib/generators/services/angular-services/models.d.ts +61 -20
  143. package/types/lib/generators/services/angular-services/refs.d.ts +9 -9
  144. package/types/lib/generators/services/easy-network-stub/easy-network-stubs-generator.d.ts +1 -1
  145. package/types/lib/generators/services/easy-network-stub/models.d.ts +35 -13
  146. package/types/lib/generators/services/easy-network-stub/refs.d.ts +14 -14
  147. package/types/lib/generators/services/fetch-clients/fetch-clients-generator.d.ts +4 -1
  148. package/types/lib/generators/services/fetch-clients/models.d.ts +63 -18
  149. package/types/lib/generators/services/fetch-clients/refs.d.ts +4 -4
  150. package/types/lib/utils.d.ts +2 -1
@@ -2,12 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultTypeScriptAngularServicesGeneratorConfig = void 0;
4
4
  const config_1 = require("../../../config");
5
- exports.defaultTypeScriptAngularServicesGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultTypeScriptGeneratorConfig), { fileNameCasing: { casing: 'kebab', suffix: '.service' }, responseModelFileNameCasing: { casing: 'kebab', suffix: '-responses.model' }, provideKind: 'provide-fn', strictResponseTypes: true, defaultStatusCodeResponseTypes: {
5
+ exports.defaultTypeScriptAngularServicesGeneratorConfig = {
6
+ ...config_1.defaultTypeScriptGeneratorConfig,
7
+ provideKind: 'provide-fn',
8
+ domainName: undefined,
9
+ strictResponseTypes: true,
10
+ defaultStatusCodeResponseTypes: {
6
11
  401: null,
7
12
  403: null,
8
13
  500: null,
9
- }, possibleStatusCodes: [
14
+ },
15
+ possibleStatusCodes: [
10
16
  100, 101, 102, 103, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308,
11
17
  400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 421, 422, 423, 424, 425,
12
18
  426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511,
13
- ], servicesDirPath: 'services', servicesIndexFilePath: 'services.ts', responseModelsDirPath: 'models/responses', responseModelsIndexFilePath: 'responses.ts', utilsDirPath: 'utils' });
19
+ ],
20
+ rootUrl: undefined,
21
+ pathModifier: undefined,
22
+ servicesDir: 'services',
23
+ serviceFileNameCasing: { casing: 'kebab', suffix: '.service' },
24
+ servicesIndexFile: 'services.ts',
25
+ responseModelsDir: 'models/responses',
26
+ responseModelFileNameCasing: { casing: 'kebab', suffix: '-responses.model' },
27
+ responseModelsIndexFile: 'responses.ts',
28
+ utilsDir: 'utils',
29
+ };
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getReferenceFactories = void 0;
3
+ exports.getReferenceFactories = getReferenceFactories;
4
4
  const path_1 = require("path");
5
5
  const core_1 = require("@goast/core");
6
6
  const ast_1 = require("../../../ast");
7
7
  // See packages/typescript/assets/client/angular for reference
8
8
  function getReferenceFactories(options) {
9
9
  var _a, _b;
10
- const utilsDirPath = (0, path_1.resolve)(options.outputDir, options.utilsDirPath);
10
+ const utilsDirPath = (0, path_1.resolve)(options.outputDir, options.utilsDir);
11
11
  return {
12
12
  // angular-service.utils.ts
13
13
  abortablePromise: ast_1.ts.reference.genericFactory('AbortablePromise', (0, path_1.join)(utilsDirPath, 'angular-service.utils.ts')),
@@ -24,4 +24,3 @@ function getReferenceFactories(options) {
24
24
  provide: ast_1.ts.reference.factory((0, core_1.toCasing)(`provide_${(_b = options.domainName) !== null && _b !== void 0 ? _b : ''}_Api`, options.functionNameCasing), (0, path_1.join)(utilsDirPath, 'provide.ts')),
25
25
  };
26
26
  }
27
- exports.getReferenceFactories = getReferenceFactories;
@@ -97,22 +97,23 @@ class DefaultTypeScriptEasyNetworkStubGenerator extends file_generator_1.TypeScr
97
97
  ],
98
98
  returnType: 'this',
99
99
  body: (0, core_1.appendValueGroup)([
100
- (0, core_1.builderTemplate) `this.stubWrapper.stub2<${requestType}>()(${core_1.builderTemplate.indent `
101
- ${ast_1.ts.string(endpoint.method.toUpperCase())},
102
- ${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
103
- async (request) => {${core_1.builderTemplate.indent `
104
- if (this.stubWrapper.options.rememberRequests) {${core_1.builderTemplate.indent `
105
- this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
106
- }
107
- throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
108
- }`}
100
+ (0, core_1.builderTemplate) `this.stubWrapper.stub2<${requestType}>()(${core_1.builderTemplate.indent `
101
+ ${ast_1.ts.string(endpoint.method.toUpperCase())},
102
+ ${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
103
+ async (request) => {${core_1.builderTemplate.indent `
104
+ if (this.stubWrapper.options.rememberRequests) {${core_1.builderTemplate.indent `
105
+ this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
106
+ }
107
+ throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
108
+ }`}
109
109
  );`,
110
110
  'return this;',
111
111
  ], '\n'),
112
112
  });
113
113
  }
114
114
  getStubFilePath(ctx) {
115
- return (0, path_1.resolve)(ctx.config.outputDir, ctx.config.stubsDirPath, `${(0, core_1.toCasing)(ctx.service.name, ctx.config.fileNameCasing)}.ts`);
115
+ var _a;
116
+ return (0, path_1.resolve)(ctx.config.outputDir, ctx.config.stubsDir, `${(0, core_1.toCasing)(ctx.service.name, (_a = ctx.config.stubFileNameCasing) !== null && _a !== void 0 ? _a : ctx.config.fileNameCasing)}.ts`);
116
117
  }
117
118
  getResponderVariableName(ctx, endpoint) {
118
119
  return (0, core_1.toCasing)(endpoint.name + '_Responder', ctx.config.propertyNameCasing);
@@ -137,7 +138,7 @@ class DefaultTypeScriptEasyNetworkStubGenerator extends file_generator_1.TypeScr
137
138
  let path = endpoint.path;
138
139
  let isFirstQueryParam = true;
139
140
  for (const param of endpoint.parameters) {
140
- let type = ((_b = (param.schema && ((_a = ctx.input.models[param.schema.id]) === null || _a === void 0 ? void 0 : _a.component))) !== null && _b !== void 0 ? _b : ast_1.ts.refs.unknown.name).replace(/^readonly /, '');
141
+ let type = ((_b = (param.schema && ((_a = ctx.input.typescript.models[param.schema.id]) === null || _a === void 0 ? void 0 : _a.component))) !== null && _b !== void 0 ? _b : ast_1.ts.refs.unknown.name).replace(/^readonly /, '');
141
142
  const arrayMatch = /^\((.*)\)\[\]$/.exec(type);
142
143
  if (arrayMatch !== null) {
143
144
  type = `${arrayMatch[1]}[]`;
@@ -164,7 +165,7 @@ class DefaultTypeScriptEasyNetworkStubGenerator extends file_generator_1.TypeScr
164
165
  ]);
165
166
  }
166
167
  getSchemaType(ctx, schema, fallback) {
167
- const output = schema && ctx.input.models[schema.id];
168
+ const output = schema && ctx.input.typescript.models[schema.id];
168
169
  if (!output)
169
170
  return fallback !== null && fallback !== void 0 ? fallback : this.getAnyType(ctx);
170
171
  return (b) => b.appendModelUsage(output);
@@ -16,8 +16,10 @@ class TypeScriptEasyNetworkStubsGenerator extends core_1.OpenApiServicesGenerati
16
16
  }
17
17
  initResult() {
18
18
  return {
19
- stubs: {},
20
- indexFiles: { stubs: undefined },
19
+ typescript: {
20
+ stubs: {},
21
+ indexFiles: { stubs: undefined },
22
+ },
21
23
  };
22
24
  }
23
25
  buildContext(context, config) {
@@ -29,19 +31,22 @@ class TypeScriptEasyNetworkStubsGenerator extends core_1.OpenApiServicesGenerati
29
31
  onGenerate(ctx) {
30
32
  const output = super.onGenerate(ctx);
31
33
  this.generateUtilsFiles(ctx);
32
- output.indexFiles = this.generateIndexFiles(ctx);
34
+ output.typescript.indexFiles = this.generateIndexFiles(ctx);
33
35
  return output;
34
36
  }
35
37
  generateService(ctx, service) {
36
38
  const clientGenerator = this._generatorFactory.create();
37
- return clientGenerator.generate(Object.assign(Object.assign({}, ctx), { service }));
39
+ return clientGenerator.generate({
40
+ ...ctx,
41
+ service,
42
+ });
38
43
  }
39
44
  addServiceResult(ctx, service, result) {
40
- ctx.output.stubs[service.id] = result;
45
+ ctx.output.typescript.stubs[service.id] = result;
41
46
  }
42
47
  generateUtilsFiles(ctx) {
43
48
  const sourceDir = (0, path_1.resolve)((0, path_1.dirname)(require.resolve('@goast/typescript')), '../assets/stubs/easy-network-stub');
44
- const targetDir = (0, path_1.resolve)(ctx.config.outputDir, ctx.config.utilsDirPath);
49
+ const targetDir = (0, path_1.resolve)(ctx.config.outputDir, ctx.config.utilsDir);
45
50
  (0, fs_extra_1.ensureDirSync)(targetDir);
46
51
  this.copyFile('easy-network-stub utils', sourceDir, targetDir, 'easy-network-stub.utils.ts');
47
52
  }
@@ -59,7 +64,7 @@ class TypeScriptEasyNetworkStubsGenerator extends core_1.OpenApiServicesGenerati
59
64
  }
60
65
  getStubsIndexFileContent(ctx) {
61
66
  return (0, core_1.appendValueGroup)([
62
- (0, core_1.appendValueGroup)(Object.values(ctx.output.stubs).map((x) => ast_1.ts.export(x.component, x.filePath))),
67
+ (0, core_1.appendValueGroup)(Object.values(ctx.output.typescript.stubs).map((x) => ast_1.ts.export(x.component, x.filePath))),
63
68
  this.getStubsClass(ctx),
64
69
  ], '\n');
65
70
  }
@@ -74,7 +79,7 @@ class TypeScriptEasyNetworkStubsGenerator extends core_1.OpenApiServicesGenerati
74
79
  readonly: true,
75
80
  type: ctx.refs.easyNetworkStubWrapper(),
76
81
  }),
77
- ...Object.entries(ctx.output.stubs).map(([id, x]) => ast_1.ts.property((0, core_1.toCasing)(serviceNames[id], fieldCasing), {
82
+ ...Object.entries(ctx.output.typescript.stubs).map(([id, x]) => ast_1.ts.property((0, core_1.toCasing)(serviceNames[id], fieldCasing), {
78
83
  accessModifier: 'private',
79
84
  optional: true,
80
85
  type: ctx.refs.easyNetworkStubGroup([ast_1.ts.reference(x.component, x.filePath), 'this']),
@@ -96,7 +101,7 @@ class TypeScriptEasyNetworkStubsGenerator extends core_1.OpenApiServicesGenerati
96
101
  body: (0, core_1.appendValueGroup)(['return this._stubWrapper.requests;'], '\n'),
97
102
  }),
98
103
  }),
99
- ...Object.entries(ctx.output.stubs).map(([id, x]) => ast_1.ts.property((0, core_1.toCasing)(serviceNames[id], ctx.config.propertyNameCasing), {
104
+ ...Object.entries(ctx.output.typescript.stubs).map(([id, x]) => ast_1.ts.property((0, core_1.toCasing)(serviceNames[id], ctx.config.propertyNameCasing), {
100
105
  accessModifier: 'public',
101
106
  type: ctx.refs.easyNetworkStubGroup([ast_1.ts.reference(x.component, x.filePath), 'this']),
102
107
  get: ast_1.ts.property.getter({
@@ -109,7 +114,7 @@ class TypeScriptEasyNetworkStubsGenerator extends core_1.OpenApiServicesGenerati
109
114
  accessModifier: 'public',
110
115
  returnType: 'this',
111
116
  body: (0, core_1.appendValueGroup)([
112
- ...Object.keys(ctx.output.stubs).map((id) => `this.${(0, core_1.toCasing)(serviceNames[id], fieldCasing)}?.reset();`),
117
+ ...Object.keys(ctx.output.typescript.stubs).map((id) => `this.${(0, core_1.toCasing)(serviceNames[id], fieldCasing)}?.reset();`),
113
118
  'return this;',
114
119
  ], '\n'),
115
120
  }),
@@ -117,7 +122,7 @@ class TypeScriptEasyNetworkStubsGenerator extends core_1.OpenApiServicesGenerati
117
122
  });
118
123
  }
119
124
  getStubsIndexFilePath(ctx) {
120
- return ctx.config.stubsIndexFilePath ? (0, path_1.resolve)(ctx.config.outputDir, ctx.config.stubsIndexFilePath) : null;
125
+ return ctx.config.stubsIndexFile ? (0, path_1.resolve)(ctx.config.outputDir, ctx.config.stubsIndexFile) : null;
121
126
  }
122
127
  getStubsClassName(ctx) {
123
128
  var _a;
@@ -3,8 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultTypeScriptEasyNetworkStubsGeneratorConfig = void 0;
4
4
  const ast_1 = require("../../../ast");
5
5
  const config_1 = require("../../../config");
6
- exports.defaultTypeScriptEasyNetworkStubsGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultTypeScriptGeneratorConfig), { fileNameCasing: { casing: 'kebab', suffix: '.stubs' }, defaultStatusCodeResponseTypes: {
6
+ exports.defaultTypeScriptEasyNetworkStubsGeneratorConfig = {
7
+ ...config_1.defaultTypeScriptGeneratorConfig,
8
+ domainName: undefined,
9
+ defaultStatusCodeResponseTypes: {
7
10
  401: ast_1.ts.refs.never(),
8
11
  403: ast_1.ts.refs.never(),
9
12
  500: ast_1.ts.refs.never(),
10
- }, stubsDirPath: 'stubs', stubsIndexFilePath: 'stubs.ts', utilsDirPath: 'utils' });
13
+ },
14
+ stubsDir: 'stubs',
15
+ stubFileNameCasing: { casing: 'kebab', suffix: '.stubs' },
16
+ stubsIndexFile: 'stubs.ts',
17
+ utilsDir: 'utils',
18
+ };
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getReferenceFactories = void 0;
3
+ exports.getReferenceFactories = getReferenceFactories;
4
4
  const path_1 = require("path");
5
5
  const ast_1 = require("../../../ast");
6
6
  // See packages/typescript/assets/stubs/easy-network-stub for reference
7
7
  function getReferenceFactories(options) {
8
- const utilsDirPath = (0, path_1.resolve)(options.outputDir, options.utilsDirPath);
8
+ const utilsDirPath = (0, path_1.resolve)(options.outputDir, options.utilsDir);
9
9
  const easyNetworkStubUtilsPath = (0, path_1.join)(utilsDirPath, 'easy-network-stub.utils.ts');
10
10
  return {
11
11
  // easy-network-stub.utils.ts
@@ -20,4 +20,3 @@ function getReferenceFactories(options) {
20
20
  createEasyNetworkStubGroup: ast_1.ts.reference.genericFactory('createEasyNetworkStubGroup', easyNetworkStubUtilsPath),
21
21
  };
22
22
  }
23
- exports.getReferenceFactories = getReferenceFactories;
@@ -18,7 +18,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
18
18
  options: ctx.config,
19
19
  generator: (b) => b.append(this.getInterfaceFileContent(ctx)),
20
20
  });
21
- result.interface = { filePath, component: name };
21
+ result.clientInterface = { filePath, component: name };
22
22
  }
23
23
  if (this.shouldGenerateClass(ctx)) {
24
24
  const filePath = this.getClassFilePath(ctx);
@@ -29,7 +29,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
29
29
  options: ctx.config,
30
30
  generator: (b) => b.append(this.getClassFileContent(ctx)),
31
31
  });
32
- result.class = { filePath, component: name };
32
+ result.client = { filePath, component: name };
33
33
  }
34
34
  return result;
35
35
  }
@@ -56,7 +56,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
56
56
  const params = endpoint.parameters.filter((x) => x.target === 'path' || x.target === 'query');
57
57
  const bodySchema = (_b = (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0]) === null || _b === void 0 ? void 0 : _b.schema;
58
58
  const responseSchema = this.getResponseSchema(ctx, endpoint);
59
- return ast_1.ts.method((0, core_1.toCasing)(endpoint.name, ctx.config.methodCasing), {
59
+ return ast_1.ts.method((0, core_1.toCasing)(endpoint.name, ctx.config.functionNameCasing), {
60
60
  doc: ast_1.ts.doc({ description: endpoint.description, tags: [endpoint.deprecated ? ast_1.ts.docTag('deprecated') : null] }),
61
61
  parameters: [
62
62
  params.length > 0
@@ -132,11 +132,11 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
132
132
  });
133
133
  }
134
134
  getServiceMethod(ctx, endpoint) {
135
- var _a, _b;
135
+ var _a, _b, _c;
136
136
  const method = this.getInterfaceEndpointMethod(ctx, endpoint);
137
137
  method.accessModifier = 'public';
138
138
  method.body = (0, core_1.appendValueGroup)([
139
- (0, core_1.builderTemplate) `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${core_1.builderTemplate.indent `
139
+ (0, core_1.builderTemplate) `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${core_1.builderTemplate.indent `
140
140
  .withPath(${ast_1.ts.string(endpoint.path)})${(b) => b.forEach(endpoint.parameters, (b, p) => {
141
141
  switch (p.target) {
142
142
  case 'path':
@@ -146,7 +146,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
146
146
  b.append((0, core_1.builderTemplate) `\n.withQueryParam(${ast_1.ts.string(p.name)}, params.${(0, core_1.toCasing)(p.name, ctx.config.paramNameCasing)})`);
147
147
  break;
148
148
  }
149
- })}
149
+ })}
150
150
  .build();`}`,
151
151
  (0, core_1.builderTemplate) `const response = (this.options.fetch ?? fetch)(url, ${ast_1.ts.object({
152
152
  members: [
@@ -156,13 +156,13 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
156
156
  ],
157
157
  })});`,
158
158
  (0, core_1.builderTemplate) `Object.defineProperty(response, 'isVoidResponse', { value: ${this.getResponseSchema(ctx, endpoint) ? 'false' : 'true'} });`,
159
- (0, core_1.builderTemplate) `return response as unknown as ${method.returnType};`,
159
+ (0, core_1.builderTemplate) `return response as unknown as ${(_c = method.returnType) !== null && _c !== void 0 ? _c : 'unknown'};`,
160
160
  ], '\n');
161
161
  return method;
162
162
  }
163
163
  // #endregion
164
164
  getSchemaType(ctx, schema, fallback) {
165
- const output = schema && ctx.input.models[schema.id];
165
+ const output = schema && ctx.input.typescript.models[schema.id];
166
166
  if (!output)
167
167
  return fallback !== null && fallback !== void 0 ? fallback : this.getAnyType(ctx);
168
168
  return (b) => b.appendModelUsage(output);
@@ -174,23 +174,26 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
174
174
  return ctx.config.clientFileKind === 'class' || ctx.config.clientFileKind === 'class-and-interface';
175
175
  }
176
176
  getInterfaceName(ctx) {
177
- return (0, core_1.toCasing)(ctx.service.name, ctx.config.interfaceNameCasing);
177
+ var _a;
178
+ return (0, core_1.toCasing)(ctx.service.name, (_a = ctx.config.clientInterfaceNameCasing) !== null && _a !== void 0 ? _a : ctx.config.typeNameCasing);
178
179
  }
179
180
  getClassName(ctx) {
180
- return (0, core_1.toCasing)(ctx.service.name, ctx.config.classNameCasing);
181
+ var _a;
182
+ return (0, core_1.toCasing)(ctx.service.name, (_a = ctx.config.clientNameCasing) !== null && _a !== void 0 ? _a : ctx.config.typeNameCasing);
181
183
  }
182
184
  getDefaultOptionsConstantName(ctx) {
183
185
  return (0, core_1.toCasing)(this.getClassName(ctx) + '-default-options', ctx.config.constantNameCasing);
184
186
  }
185
187
  getInterfaceFilePath(ctx) {
186
188
  var _a, _b;
187
- return (0, path_1.resolve)(ctx.config.outputDir, (_a = ctx.config.clientInterfaceDirPath) !== null && _a !== void 0 ? _a : ctx.config.clientDirPath, `${(0, core_1.toCasing)(ctx.service.name, (_b = ctx.config.interfaceFileNameCasing) !== null && _b !== void 0 ? _b : ctx.config.fileNameCasing)}.ts`);
189
+ return (0, path_1.resolve)(ctx.config.outputDir, (_a = ctx.config.clientInterfaceDir) !== null && _a !== void 0 ? _a : ctx.config.clientDir, `${(0, core_1.toCasing)(ctx.service.name, (_b = ctx.config.clientInterfaceFileNameCasing) !== null && _b !== void 0 ? _b : ctx.config.fileNameCasing)}.ts`);
188
190
  }
189
191
  getClassFilePath(ctx) {
190
- return (0, path_1.resolve)(ctx.config.outputDir, ctx.config.clientDirPath, `${(0, core_1.toCasing)(ctx.service.name, ctx.config.fileNameCasing)}.ts`);
192
+ var _a;
193
+ return (0, path_1.resolve)(ctx.config.outputDir, ctx.config.clientDir, `${(0, core_1.toCasing)(ctx.service.name, (_a = ctx.config.clientFileNameCasing) !== null && _a !== void 0 ? _a : ctx.config.fileNameCasing)}.ts`);
191
194
  }
192
195
  getUtilPath(ctx, fileName) {
193
- return (0, path_1.resolve)(ctx.config.outputDir, ctx.config.utilsDirPath, fileName);
196
+ return (0, path_1.resolve)(ctx.config.outputDir, ctx.config.utilsDir, fileName);
194
197
  }
195
198
  getResponseSchema(ctx, endpoint) {
196
199
  var _a, _b, _c;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeScriptClientsGenerator = void 0;
3
+ exports.TypeScriptFetchClientsGenerator = void 0;
4
4
  const path_1 = require("path");
5
5
  const fs_extra_1 = require("fs-extra");
6
6
  const core_1 = require("@goast/core");
@@ -9,7 +9,7 @@ const models_1 = require("./models");
9
9
  const refs_1 = require("./refs");
10
10
  const ast_1 = require("../../../ast");
11
11
  const file_builder_1 = require("../../../file-builder");
12
- class TypeScriptClientsGenerator extends core_1.OpenApiServicesGenerationProviderBase {
12
+ class TypeScriptFetchClientsGenerator extends core_1.OpenApiServicesGenerationProviderBase {
13
13
  constructor(clientGeneratorFactory) {
14
14
  super();
15
15
  this._clientGeneratorFactory =
@@ -17,9 +17,12 @@ class TypeScriptClientsGenerator extends core_1.OpenApiServicesGenerationProvide
17
17
  }
18
18
  initResult() {
19
19
  return {
20
- clients: {},
21
- indexFiles: {
22
- clients: undefined,
20
+ typescript: {
21
+ clients: {},
22
+ indexFiles: {
23
+ clients: undefined,
24
+ clientInterfaces: undefined,
25
+ },
23
26
  },
24
27
  };
25
28
  }
@@ -32,15 +35,19 @@ class TypeScriptClientsGenerator extends core_1.OpenApiServicesGenerationProvide
32
35
  onGenerate(ctx) {
33
36
  this.copyUtilsFiles(ctx);
34
37
  const output = super.onGenerate(ctx);
35
- output.indexFiles.clients = this.generateIndexFile(ctx);
38
+ output.typescript.indexFiles.clients = this.generateIndexFile(ctx);
39
+ output.typescript.indexFiles.clientInterfaces = this.generateInterfaceIndexFile(ctx);
36
40
  return output;
37
41
  }
38
42
  generateService(ctx, service) {
39
43
  const clientGenerator = this._clientGeneratorFactory.create();
40
- return clientGenerator.generate(Object.assign(Object.assign({}, ctx), { service }));
44
+ return clientGenerator.generate({
45
+ ...ctx,
46
+ service,
47
+ });
41
48
  }
42
49
  addServiceResult(ctx, service, result) {
43
- ctx.output.clients[service.id] = result;
50
+ ctx.output.typescript.clients[service.id] = result;
44
51
  }
45
52
  generateIndexFile(ctx) {
46
53
  const filePath = this.getIndexFilePath(ctx);
@@ -52,18 +59,46 @@ class TypeScriptClientsGenerator extends core_1.OpenApiServicesGenerationProvide
52
59
  });
53
60
  return filePath;
54
61
  }
62
+ generateInterfaceIndexFile(ctx) {
63
+ const filePath = this.getInterfaceIndexFilePath(ctx);
64
+ const clientsFilePath = this.getIndexFilePath(ctx);
65
+ if (filePath && filePath === clientsFilePath) {
66
+ return clientsFilePath;
67
+ }
68
+ file_builder_1.TypeScriptFileBuilder.tryGenerate({
69
+ logName: 'client interfaces index file',
70
+ filePath,
71
+ options: ctx.config,
72
+ generator: (b) => b.append(this.getInterfaceIndexFileContent(ctx)),
73
+ });
74
+ return filePath;
75
+ }
55
76
  getIndexFilePath(ctx) {
56
- return ctx.config.indexFilePath ? (0, path_1.resolve)(ctx.config.outputDir, ctx.config.indexFilePath) : null;
77
+ return ctx.config.clientsIndexFile ? (0, path_1.resolve)(ctx.config.outputDir, ctx.config.clientsIndexFile) : null;
78
+ }
79
+ getInterfaceIndexFilePath(ctx) {
80
+ return ctx.config.clientInterfacesIndexFile
81
+ ? (0, path_1.resolve)(ctx.config.outputDir, ctx.config.clientInterfacesIndexFile)
82
+ : null;
57
83
  }
58
84
  getIndexFileContent(ctx) {
59
- return (0, core_1.appendValueGroup)(Object.values(ctx.output.clients)
60
- .flatMap((c) => [c.class, c.interface])
85
+ const cIndexPath = this.getIndexFilePath(ctx);
86
+ const iIndexPath = this.getInterfaceIndexFilePath(ctx);
87
+ return (0, core_1.appendValueGroup)((iIndexPath && iIndexPath === cIndexPath
88
+ ? Object.values(ctx.output.typescript.clients).flatMap((c) => [c.client, c.clientInterface])
89
+ : Object.values(ctx.output.typescript.clients).map((c) => c.client))
90
+ .filter(core_1.notNullish)
91
+ .map((x) => ast_1.ts.export(x.component, x.filePath)));
92
+ }
93
+ getInterfaceIndexFileContent(ctx) {
94
+ return (0, core_1.appendValueGroup)(Object.values(ctx.output.typescript.clients)
95
+ .map((c) => c.clientInterface)
61
96
  .filter(core_1.notNullish)
62
97
  .map((x) => ast_1.ts.export(x.component, x.filePath)));
63
98
  }
64
99
  copyUtilsFiles(ctx) {
65
100
  const sourceDir = (0, path_1.resolve)((0, path_1.dirname)(require.resolve('@goast/typescript')), '../assets/client/fetch');
66
- const targetDir = (0, path_1.resolve)(ctx.config.outputDir, ctx.config.utilsDirPath);
101
+ const targetDir = (0, path_1.resolve)(ctx.config.outputDir, ctx.config.utilsDir);
67
102
  (0, fs_extra_1.ensureDirSync)(targetDir);
68
103
  const files = (0, fs_extra_1.readdirSync)(sourceDir);
69
104
  for (const file of files) {
@@ -71,4 +106,4 @@ class TypeScriptClientsGenerator extends core_1.OpenApiServicesGenerationProvide
71
106
  }
72
107
  }
73
108
  }
74
- exports.TypeScriptClientsGenerator = TypeScriptClientsGenerator;
109
+ exports.TypeScriptFetchClientsGenerator = TypeScriptFetchClientsGenerator;
@@ -2,4 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultTypeScriptFetchClientsGeneratorConfig = void 0;
4
4
  const config_1 = require("../../../config");
5
- exports.defaultTypeScriptFetchClientsGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultTypeScriptGeneratorConfig), { fileNameCasing: { casing: 'kebab', suffix: '-client' }, interfaceFileNameCasing: null, classNameCasing: { casing: 'pascal', suffix: 'Client' }, interfaceNameCasing: { prefix: 'I', casing: 'pascal', suffix: 'Client' }, methodCasing: 'camel', clientFileKind: 'class', clientDirPath: 'clients', clientInterfaceDirPath: 'clients/interfaces', indexFilePath: 'clients.ts', interfaceIndexFilePath: 'clients.ts', utilsDirPath: 'utils' });
5
+ exports.defaultTypeScriptFetchClientsGeneratorConfig = {
6
+ ...config_1.defaultTypeScriptGeneratorConfig,
7
+ clientFileNameCasing: { casing: 'kebab', suffix: '-client' },
8
+ clientInterfaceFileNameCasing: undefined,
9
+ clientNameCasing: { casing: 'pascal', suffix: 'Client' },
10
+ clientInterfaceNameCasing: { prefix: 'I', casing: 'pascal', suffix: 'Client' },
11
+ clientFileKind: 'class',
12
+ clientDir: 'clients',
13
+ clientInterfaceDir: 'clients/interfaces',
14
+ clientsIndexFile: 'clients.ts',
15
+ clientInterfacesIndexFile: 'clients.ts',
16
+ utilsDir: 'utils',
17
+ };
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getReferenceFactories = void 0;
3
+ exports.getReferenceFactories = getReferenceFactories;
4
4
  const path_1 = require("path");
5
5
  const ast_1 = require("../../../ast");
6
6
  // See packages/typescript/assets/client/fetch for reference
7
7
  function getReferenceFactories(options) {
8
- const utilsDirPath = (0, path_1.resolve)(options.outputDir, options.utilsDirPath);
8
+ const utilsDirPath = (0, path_1.resolve)(options.outputDir, options.utilsDir);
9
9
  const fetchClientUtilsPath = (0, path_1.resolve)(utilsDirPath, 'fetch-client.utils.ts');
10
10
  return {
11
11
  // fetch-client.utils.ts
@@ -14,4 +14,3 @@ function getReferenceFactories(options) {
14
14
  urlBuilder: ast_1.ts.reference.factory('UrlBuilder', fetchClientUtilsPath),
15
15
  };
16
16
  }
17
- exports.getReferenceFactories = getReferenceFactories;
@@ -13,7 +13,7 @@ class ImportExportCollection {
13
13
  constructor(options) {
14
14
  this._imports = new Map();
15
15
  this._exports = new Map();
16
- this._options = Object.assign(Object.assign({}, exports.defaultImportExportCollectionOptions), options);
16
+ this._options = { ...exports.defaultImportExportCollectionOptions, ...options };
17
17
  }
18
18
  get hasImports() {
19
19
  return this._imports.size > 0;
package/cjs/lib/utils.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.modifyString = exports.getModulePathRelativeToDirectory = exports.getModulePathRelativeToFile = exports.toTypeScriptPropertyName = exports.toTypeScriptStringLiteral = void 0;
3
+ exports.toTypeScriptStringLiteral = toTypeScriptStringLiteral;
4
+ exports.toTypeScriptPropertyName = toTypeScriptPropertyName;
5
+ exports.getModulePathRelativeToFile = getModulePathRelativeToFile;
6
+ exports.getModulePathRelativeToDirectory = getModulePathRelativeToDirectory;
7
+ exports.modifyString = modifyString;
4
8
  const path_1 = require("path");
5
9
  function doubleQuotedToSingleQuoted(value) {
6
10
  return `'${value.slice(1, -1).replace(/'/g, "\\'")}'`;
@@ -8,22 +12,18 @@ function doubleQuotedToSingleQuoted(value) {
8
12
  function toTypeScriptStringLiteral(value, useSingleQuotes) {
9
13
  return useSingleQuotes ? doubleQuotedToSingleQuoted(JSON.stringify(value)) : JSON.stringify(value);
10
14
  }
11
- exports.toTypeScriptStringLiteral = toTypeScriptStringLiteral;
12
15
  function toTypeScriptPropertyName(value, useSingleQuotes) {
13
16
  if (value.match(/^[a-zA-Z_$][a-zA-Z_$0-9]*$/)) {
14
17
  return value;
15
18
  }
16
19
  return useSingleQuotes ? doubleQuotedToSingleQuoted(JSON.stringify(value)) : JSON.stringify(value);
17
20
  }
18
- exports.toTypeScriptPropertyName = toTypeScriptPropertyName;
19
21
  function getModulePathRelativeToFile(from, to, transformer) {
20
22
  return transformModulePath((0, path_1.relative)((0, path_1.dirname)(from), to).replace(/\\/g, '/'), transformer);
21
23
  }
22
- exports.getModulePathRelativeToFile = getModulePathRelativeToFile;
23
24
  function getModulePathRelativeToDirectory(from, to, transformer) {
24
25
  return transformModulePath((0, path_1.relative)(from, to).replace(/\\/g, '/'), transformer);
25
26
  }
26
- exports.getModulePathRelativeToDirectory = getModulePathRelativeToDirectory;
27
27
  function transformModulePath(modulePath, transformer) {
28
28
  if (!modulePath.startsWith('.')) {
29
29
  modulePath = `./${modulePath}`;
@@ -53,4 +53,3 @@ function modifyString(value, modifier, ...args) {
53
53
  }
54
54
  return value;
55
55
  }
56
- exports.modifyString = modifyString;
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './lib/ast';
1
2
  export * from './lib/common-results';
2
3
  export * from './lib/config';
3
4
  export * from './lib/generators';
@@ -10,7 +10,7 @@ export class TsArgument extends TsNode {
10
10
  writeTsNode(builder, this.value);
11
11
  }
12
12
  }
13
- const createArgument = (value, options) => new TsArgument(Object.assign(Object.assign({}, options), { value }));
13
+ const createArgument = (value, options) => new TsArgument({ ...options, value });
14
14
  export const tsArgument = Object.assign(createArgument, {
15
15
  write: writeTsParameters,
16
16
  });
@@ -17,7 +17,7 @@ export class TsArrayType extends TsNode {
17
17
  builder.append('[]');
18
18
  }
19
19
  }
20
- const createArrayType = (type, options) => new TsArrayType(Object.assign(Object.assign({}, options), { type }));
20
+ const createArrayType = (type, options) => new TsArrayType({ ...options, type });
21
21
  export const tsArrayType = Object.assign(createArrayType, {
22
22
  write: writeTsNodes,
23
23
  });
@@ -16,7 +16,7 @@ export class TsCall extends TsNode {
16
16
  }
17
17
  }
18
18
  }
19
- const createCall = (path, args, options) => new TsCall(Object.assign(Object.assign({}, options), { path: Array.isArray(path) ? path : [path], arguments: args }));
19
+ const createCall = (path, args, options) => new TsCall({ ...options, path: Array.isArray(path) ? path : [path], arguments: args });
20
20
  export const tsCall = Object.assign(createCall, {
21
21
  write: writeTsNodes,
22
22
  });
@@ -60,7 +60,7 @@ export class TsClass extends TsNode {
60
60
  builder.appendLine();
61
61
  }
62
62
  }
63
- const createClass = (name, options) => new TsClass(Object.assign(Object.assign({}, options), { name }));
63
+ const createClass = (name, options) => new TsClass({ ...options, name });
64
64
  export const tsClass = Object.assign(createClass, {
65
65
  write: writeTsNodes,
66
66
  });
@@ -36,7 +36,7 @@ export class TsConstructorParameter extends TsParameter {
36
36
  }
37
37
  }
38
38
  }
39
- const createConstructorParameter = (name, options) => new TsConstructorParameter(Object.assign(Object.assign({}, options), { name }));
39
+ const createConstructorParameter = (name, options) => new TsConstructorParameter({ ...options, name });
40
40
  export const tsConstructorParameter = Object.assign(createConstructorParameter, {
41
41
  write: writeTsParameters,
42
42
  });
@@ -21,7 +21,7 @@ export class TsDecorator extends TsNode {
21
21
  }
22
22
  }
23
23
  }
24
- const createDecorator = (fn, args, options) => new TsDecorator(Object.assign(Object.assign({}, options), { function: fn, arguments: args }));
24
+ const createDecorator = (fn, args, options) => new TsDecorator({ ...options, function: fn, arguments: args });
25
25
  const writeDecorators = (builder, nodes, options) => {
26
26
  const filteredNodes = toArray(nodes).filter(notNullish);
27
27
  builder.forEach(filteredNodes, (b, d) => {
@@ -22,7 +22,7 @@ export class TsEnumValue extends TsNode {
22
22
  }
23
23
  }
24
24
  }
25
- const createEnumValue = (name, options) => new TsEnumValue(Object.assign(Object.assign({}, options), { name }));
25
+ const createEnumValue = (name, options) => new TsEnumValue({ ...options, name });
26
26
  const writeEnumValues = (builder, nodes) => {
27
27
  writeTsNodes(builder, nodes, { separator: ',\n' });
28
28
  };
@@ -36,7 +36,7 @@ export class TsEnum extends TsNode {
36
36
  builder.appendLine();
37
37
  }
38
38
  }
39
- const createEnum = (name, options) => new TsEnum(Object.assign(Object.assign({}, options), { name }));
39
+ const createEnum = (name, options) => new TsEnum({ ...options, name });
40
40
  export const tsEnum = Object.assign(createEnum, {
41
41
  write: writeTsNodes,
42
42
  });
@@ -16,7 +16,7 @@ export class TsExport extends TsNode {
16
16
  }
17
17
  }
18
18
  }
19
- export const createExport = (name, filePath, options) => new TsExport(Object.assign(Object.assign({}, options), { name, filePath }));
19
+ export const createExport = (name, filePath, options) => new TsExport({ ...options, name, filePath });
20
20
  export const tsExport = Object.assign(createExport, {
21
21
  write: writeTsNodes,
22
22
  });
@@ -50,7 +50,7 @@ export class TsFunction extends TsNode {
50
50
  builder.appendLine();
51
51
  }
52
52
  }
53
- const createFunction = (name, options) => new TsFunction(Object.assign(Object.assign({}, options), { name }));
53
+ const createFunction = (name, options) => new TsFunction({ ...options, name });
54
54
  export const tsFunction = Object.assign(createFunction, {
55
55
  write: writeTsNodes,
56
56
  });