@goast/typescript 0.6.3-beta.1 → 0.7.1

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 (92) hide show
  1. package/LICENSE +21 -21
  2. package/assets/stubs/easy-network-stub/easy-network-stub.utils.ts +9 -7
  3. package/esm/src/generators/services/easy-network-stub/refs.d.ts +1 -0
  4. package/esm/src/generators/services/easy-network-stub/refs.d.ts.map +1 -1
  5. package/esm/src/generators/services/easy-network-stub/refs.js +1 -0
  6. package/package.json +2 -2
  7. package/script/src/generators/services/easy-network-stub/refs.d.ts +1 -0
  8. package/script/src/generators/services/easy-network-stub/refs.d.ts.map +1 -1
  9. package/script/src/generators/services/easy-network-stub/refs.js +1 -0
  10. package/src/mod.ts +7 -0
  11. package/src/src/assets.ts +9 -0
  12. package/src/src/ast/_index.ts +54 -0
  13. package/src/src/ast/common.ts +1 -0
  14. package/src/src/ast/index.ts +1 -0
  15. package/src/src/ast/node.ts +10 -0
  16. package/src/src/ast/nodes/argument.ts +40 -0
  17. package/src/src/ast/nodes/array-type.ts +49 -0
  18. package/src/src/ast/nodes/arrow-function.ts +91 -0
  19. package/src/src/ast/nodes/call.ts +55 -0
  20. package/src/src/ast/nodes/class.ts +133 -0
  21. package/src/src/ast/nodes/constructor-parameter.ts +70 -0
  22. package/src/src/ast/nodes/constructor.ts +77 -0
  23. package/src/src/ast/nodes/decorator.ts +76 -0
  24. package/src/src/ast/nodes/doc-tag.ts +291 -0
  25. package/src/src/ast/nodes/doc.ts +102 -0
  26. package/src/src/ast/nodes/enum-value.ts +72 -0
  27. package/src/src/ast/nodes/enum.ts +77 -0
  28. package/src/src/ast/nodes/export.ts +54 -0
  29. package/src/src/ast/nodes/function-type.ts +60 -0
  30. package/src/src/ast/nodes/function.ts +107 -0
  31. package/src/src/ast/nodes/generic-parameter.ts +71 -0
  32. package/src/src/ast/nodes/indexer.ts +60 -0
  33. package/src/src/ast/nodes/interface.ts +117 -0
  34. package/src/src/ast/nodes/intersection-type.ts +67 -0
  35. package/src/src/ast/nodes/lookup-type.ts +53 -0
  36. package/src/src/ast/nodes/method.ts +138 -0
  37. package/src/src/ast/nodes/object-type.ts +52 -0
  38. package/src/src/ast/nodes/object.ts +48 -0
  39. package/src/src/ast/nodes/parameter.ts +85 -0
  40. package/src/src/ast/nodes/property-accessor.ts +173 -0
  41. package/src/src/ast/nodes/property.ts +192 -0
  42. package/src/src/ast/nodes/reference.ts +194 -0
  43. package/src/src/ast/nodes/string.ts +49 -0
  44. package/src/src/ast/nodes/tuple.ts +53 -0
  45. package/src/src/ast/nodes/type-alias.ts +75 -0
  46. package/src/src/ast/nodes/typeof.ts +42 -0
  47. package/src/src/ast/nodes/types.ts +40 -0
  48. package/src/src/ast/nodes/union-type.ts +62 -0
  49. package/src/src/ast/nodes/variable.ts +73 -0
  50. package/src/src/ast/references/angular.ts +24 -0
  51. package/src/src/ast/references/easy-network-stub.ts +21 -0
  52. package/src/src/ast/references/index.ts +5 -0
  53. package/src/src/ast/references/k6.ts +8 -0
  54. package/src/src/ast/references/rxjs.ts +7 -0
  55. package/src/src/ast/references/typescript.ts +35 -0
  56. package/src/src/ast/utils/get-type-script-builder-options.ts +19 -0
  57. package/src/src/ast/utils/to-ts-node.ts +27 -0
  58. package/src/src/ast/utils/write-ts-generic-parameters.ts +25 -0
  59. package/src/src/ast/utils/write-ts-members.ts +28 -0
  60. package/src/src/ast/utils/write-ts-nodes.ts +35 -0
  61. package/src/src/ast/utils/write-ts-parameters.ts +25 -0
  62. package/src/src/common-results.ts +26 -0
  63. package/src/src/config.ts +89 -0
  64. package/src/src/file-builder.ts +137 -0
  65. package/src/src/generators/file-generator.ts +15 -0
  66. package/src/src/generators/index.ts +6 -0
  67. package/src/src/generators/models/index.ts +3 -0
  68. package/src/src/generators/models/model-generator.ts +481 -0
  69. package/src/src/generators/models/models-generator.ts +108 -0
  70. package/src/src/generators/models/models.ts +121 -0
  71. package/src/src/generators/services/angular-services/angular-service-generator.ts +414 -0
  72. package/src/src/generators/services/angular-services/angular-services-generator.ts +295 -0
  73. package/src/src/generators/services/angular-services/index.ts +3 -0
  74. package/src/src/generators/services/angular-services/models.ts +277 -0
  75. package/src/src/generators/services/angular-services/refs.ts +54 -0
  76. package/src/src/generators/services/easy-network-stub/easy-network-stub-generator.ts +250 -0
  77. package/src/src/generators/services/easy-network-stub/easy-network-stubs-generator.ts +211 -0
  78. package/src/src/generators/services/easy-network-stub/index.ts +3 -0
  79. package/src/src/generators/services/easy-network-stub/models.ts +124 -0
  80. package/src/src/generators/services/easy-network-stub/refs.ts +47 -0
  81. package/src/src/generators/services/fetch-clients/fetch-client-generator.ts +285 -0
  82. package/src/src/generators/services/fetch-clients/fetch-clients-generator.ts +163 -0
  83. package/src/src/generators/services/fetch-clients/index.ts +3 -0
  84. package/src/src/generators/services/fetch-clients/models.ts +130 -0
  85. package/src/src/generators/services/fetch-clients/refs.ts +21 -0
  86. package/src/src/generators/services/k6-clients/index.ts +3 -0
  87. package/src/src/generators/services/k6-clients/k6-client-generator.ts +474 -0
  88. package/src/src/generators/services/k6-clients/k6-clients-generator.ts +171 -0
  89. package/src/src/generators/services/k6-clients/models.ts +247 -0
  90. package/src/src/generators/services/k6-clients/refs.ts +16 -0
  91. package/src/src/import-collection.ts +236 -0
  92. package/src/src/utils.ts +72 -0
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Marc Schmidt
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Marc Schmidt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,4 +1,4 @@
1
- import type { EasyNetworkStub, ErrorResponse, HttpMethod, RouteResponseCallback } from 'easy-network-stub';
1
+ import type { EasyNetworkStub, ErrorResponse, HttpMethod, RouteResponseCallback, StubHandle } from 'easy-network-stub';
2
2
 
3
3
  /**
4
4
  * Options for the `EasyNetworkStubWrapper`.
@@ -128,8 +128,8 @@ export class EasyNetworkStubWrapper {
128
128
  method: HttpMethod,
129
129
  route: Route,
130
130
  response: RouteResponseCallback<Route, unknown>,
131
- ): void {
132
- this.wrappedStub.stub<Route>(method, route, async (request) => {
131
+ ): StubHandle {
132
+ return this.wrappedStub.stub<Route>(method, route, async (request) => {
133
133
  if (this.options.delay > 0) await sleep(this.options.delay);
134
134
  return await this.runRequest(method, route, response, request);
135
135
  });
@@ -152,9 +152,9 @@ export class EasyNetworkStubWrapper {
152
152
  method: HttpMethod,
153
153
  route: Route,
154
154
  response: RouteResponseCallback<Route, T>,
155
- ) => void {
155
+ ) => StubHandle {
156
156
  return <Route extends string>(method: HttpMethod, route: Route, response: RouteResponseCallback<Route, T>) => {
157
- this.wrappedStub.stub2<T>()<Route>(method, route, async (request) => {
157
+ return this.wrappedStub.stub2<T>()<Route>(method, route, async (request) => {
158
158
  if (this.options.delay > 0) await sleep(this.options.delay);
159
159
  return await this.runRequest(method, route, response, request);
160
160
  });
@@ -166,7 +166,7 @@ export class EasyNetworkStubWrapper {
166
166
  */
167
167
  public reset(): void {
168
168
  this._requests = [];
169
- this.wrappedStub['_config'].stubs = [];
169
+ this.wrappedStub.reset();
170
170
  }
171
171
 
172
172
  private async runRequest<Route extends string, T>(
@@ -219,7 +219,9 @@ export class EasyNetworkStubBase {
219
219
  }
220
220
 
221
221
  public reset() {
222
- this.stubWrapper.reset();
222
+ if (this.ownsStubWrapper) {
223
+ this.stubWrapper.reset();
224
+ }
223
225
  }
224
226
  }
225
227
 
@@ -10,5 +10,6 @@ export declare function getReferenceFactories(options: TypeScriptEasyNetworkStub
10
10
  easyNetworkStubBase: ts.ModuleReferenceFactory;
11
11
  easyNetworkStubGroup: ts.GenericModuleReferenceFactory<2>;
12
12
  createEasyNetworkStubGroup: ts.GenericModuleReferenceFactory<2>;
13
+ stubHandle: ts.ModuleReferenceFactory;
13
14
  };
14
15
  //# sourceMappingURL=refs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/refs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yCAAyC,GAAG;IACzF,6BAA6B,EAAE,EAAE,CAAC,sBAAsB,CAAC;IACzD,eAAe,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC3C,eAAe,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACrD,2BAA2B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAClD,mBAAmB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC/C,oBAAoB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAC1D,0BAA0B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;CACjE,CA4BA"}
1
+ {"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/refs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yCAAyC,GAAG;IACzF,6BAA6B,EAAE,EAAE,CAAC,sBAAsB,CAAC;IACzD,eAAe,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC3C,eAAe,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACrD,2BAA2B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAClD,mBAAmB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC/C,oBAAoB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAC1D,0BAA0B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAChE,UAAU,EAAE,EAAE,CAAC,sBAAsB,CAAC;CACvC,CA6BA"}
@@ -23,5 +23,6 @@ export function getReferenceFactories(options) {
23
23
  importType: 'type-import',
24
24
  }),
25
25
  createEasyNetworkStubGroup: ts.reference.genericFactory('createEasyNetworkStubGroup', easyNetworkStubUtilsPath),
26
+ stubHandle: ts.reference.factory('StubHandle', 'easy-network-stub', { importType: 'type-import' }),
26
27
  };
27
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/typescript",
3
- "version": "0.6.3-beta.1",
3
+ "version": "0.7.1",
4
4
  "description": "Provides gOAst generators for generating TypeScript code from OpenAPI specifications.",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "tslib": "^2.6.2",
27
27
  "fs-extra": "^11.3.3",
28
- "@goast/core": "0.5.0-beta.5"
28
+ "@goast/core": "0.5.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^20.9.0",
@@ -10,5 +10,6 @@ export declare function getReferenceFactories(options: TypeScriptEasyNetworkStub
10
10
  easyNetworkStubBase: ts.ModuleReferenceFactory;
11
11
  easyNetworkStubGroup: ts.GenericModuleReferenceFactory<2>;
12
12
  createEasyNetworkStubGroup: ts.GenericModuleReferenceFactory<2>;
13
+ stubHandle: ts.ModuleReferenceFactory;
13
14
  };
14
15
  //# sourceMappingURL=refs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/refs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yCAAyC,GAAG;IACzF,6BAA6B,EAAE,EAAE,CAAC,sBAAsB,CAAC;IACzD,eAAe,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC3C,eAAe,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACrD,2BAA2B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAClD,mBAAmB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC/C,oBAAoB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAC1D,0BAA0B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;CACjE,CA4BA"}
1
+ {"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/refs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yCAAyC,GAAG;IACzF,6BAA6B,EAAE,EAAE,CAAC,sBAAsB,CAAC;IACzD,eAAe,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC3C,eAAe,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACrD,2BAA2B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAClD,mBAAmB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC/C,oBAAoB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAC1D,0BAA0B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAChE,UAAU,EAAE,EAAE,CAAC,sBAAsB,CAAC;CACvC,CA6BA"}
@@ -26,5 +26,6 @@ function getReferenceFactories(options) {
26
26
  importType: 'type-import',
27
27
  }),
28
28
  createEasyNetworkStubGroup: index_js_1.ts.reference.genericFactory('createEasyNetworkStubGroup', easyNetworkStubUtilsPath),
29
+ stubHandle: index_js_1.ts.reference.factory('StubHandle', 'easy-network-stub', { importType: 'type-import' }),
29
30
  };
30
31
  }
package/src/mod.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './src/ast/index.js';
2
+ export * from './src/common-results.js';
3
+ export * from './src/config.js';
4
+ export * from './src/file-builder.js';
5
+ export * from './src/generators/index.js';
6
+ export * from './src/import-collection.js';
7
+ export * from './src/utils.js';
@@ -0,0 +1,9 @@
1
+ import { AssetManager } from '@goast/core';
2
+ import { pathToFileURL, URL } from 'node:url';
3
+
4
+ declare const __filename: string | undefined;
5
+ const scriptUrl = typeof __filename === 'undefined' ? import.meta.url : pathToFileURL(__filename);
6
+
7
+ const manager = new AssetManager(new URL('../assets/', scriptUrl));
8
+ export const getAssetFileContent = manager.getAssetFileContent.bind(manager);
9
+ export const copyAssetFile = manager.copyAssetFile.bind(manager);
@@ -0,0 +1,54 @@
1
+ export { type TsAccessModifier as AccessModifier } from './common.js';
2
+ export { TsNode as Node } from './node.js';
3
+ export { TsArgument as Argument, tsArgument as argument } from './nodes/argument.js';
4
+ export { TsArrayType as ArrayType, tsArrayType as arrayType } from './nodes/array-type.js';
5
+ export { TsArrowFunction as ArrowFunction, tsArrowFunction as arrowFunction } from './nodes/arrow-function.js';
6
+ export { TsCall as Call, tsCall as call } from './nodes/call.js';
7
+ export { TsClass as Class, tsClass as class } from './nodes/class.js';
8
+ export {
9
+ TsConstructorParameter as ConstructorParameter,
10
+ tsConstructorParameter as constructorParameter,
11
+ } from './nodes/constructor-parameter.js';
12
+ export { TsConstructor as Constructor, tsConstructor as constructor } from './nodes/constructor.js';
13
+ export { TsDecorator as Decorator, tsDecorator as decorator } from './nodes/decorator.js';
14
+ export { TsDocTag as DocTag, tsDocTag as docTag } from './nodes/doc-tag.js';
15
+ export { TsDoc as Doc, tsDoc as doc } from './nodes/doc.js';
16
+ export { TsEnumValue as EnumValue, tsEnumValue as enumValue } from './nodes/enum-value.js';
17
+ export { TsEnum as Enum, tsEnum as enum } from './nodes/enum.js';
18
+ export { TsExport as Export, tsExport as export } from './nodes/export.js';
19
+ export { TsFunctionType as FunctionType, tsFunctionType as functionType } from './nodes/function-type.js';
20
+ export { TsFunction as Function, tsFunction as function } from './nodes/function.js';
21
+ export {
22
+ TsGenericParameter as GenericParameter,
23
+ tsGenericParameter as genericParameter,
24
+ } from './nodes/generic-parameter.js';
25
+ export { TsIndexer as Indexer, tsIndexer as indexer } from './nodes/indexer.js';
26
+ export { TsInterface as Interface, tsInterface as interface } from './nodes/interface.js';
27
+ export {
28
+ TsIntersectionType as IntersectionType,
29
+ tsIntersectionType as intersectionType,
30
+ } from './nodes/intersection-type.js';
31
+ export { TsLookupType as LookupType, tsLookupType as lookupType } from './nodes/lookup-type.js';
32
+ export { TsMethod as Method, tsMethod as method } from './nodes/method.js';
33
+ export { TsObjectType as ObjectType, tsObjectType as objectType } from './nodes/object-type.js';
34
+ export { TsObject as Object, tsObject as object } from './nodes/object.js';
35
+ export { TsParameter as Parameter, tsParameter as parameter } from './nodes/parameter.js';
36
+ export { TsProperty as Property, tsProperty as property } from './nodes/property.js';
37
+ export {
38
+ type TsGenericModuleReferenceFactory as GenericModuleReferenceFactory,
39
+ type TsGenericReferenceFactory as GenericReferenceFactory,
40
+ type TsModuleReferenceFactory as ModuleReferenceFactory,
41
+ TsReference as Reference,
42
+ tsReference as reference,
43
+ type TsReferenceFactory as ReferenceFactory,
44
+ } from './nodes/reference.js';
45
+ export { TsString as String, tsString as string } from './nodes/string.js';
46
+ export { TsTuple as Tuple, tsTuple as tuple } from './nodes/tuple.js';
47
+ export { TsTypeAlias as TypeAlias, tsTypeAlias as typeAlias } from './nodes/type-alias.js';
48
+ export { TsTypeof as Typeof, tsTypeof as typeof } from './nodes/typeof.js';
49
+ export { type TsType as Type, type TsValue as Value } from './nodes/types.js';
50
+ export { TsUnionType as UnionType, tsUnionType as unionType } from './nodes/union-type.js';
51
+ export { TsVariable as Variable, tsVariable as variable } from './nodes/variable.js';
52
+ export * as refs from './references/index.js';
53
+ export { getTypeScriptBuilderOptions as getBuilderOptions } from './utils/get-type-script-builder-options.js';
54
+ export { toTsNode as toNode } from './utils/to-ts-node.js';
@@ -0,0 +1 @@
1
+ export type TsAccessModifier = 'public' | 'protected' | 'private';
@@ -0,0 +1 @@
1
+ export * as ts from './_index.js';
@@ -0,0 +1,10 @@
1
+ import { AstNode, type AstNodeOptions, type SourceBuilder } from '@goast/core';
2
+
3
+ export abstract class TsNode<TBuilder extends SourceBuilder, TInjects extends string = never> extends AstNode<
4
+ TBuilder,
5
+ TInjects
6
+ > {
7
+ constructor(options: AstNodeOptions<typeof AstNode<TBuilder, TInjects>>) {
8
+ super(options);
9
+ }
10
+ }
@@ -0,0 +1,40 @@
1
+ import type { AstNodeOptions, Prettify, SourceBuilder } from '@goast/core';
2
+
3
+ import { TsNode } from '../node.js';
4
+ import { writeTsNode } from '../utils/write-ts-nodes.js';
5
+ import { writeTsParameters } from '../utils/write-ts-parameters.js';
6
+ import type { TsValue } from './types.js';
7
+
8
+ type Injects = never;
9
+
10
+ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
11
+ typeof TsNode<TBuilder, TInjects | Injects>,
12
+ {
13
+ value: TsValue<TBuilder>;
14
+ }
15
+ >;
16
+
17
+ export class TsArgument<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
18
+ TBuilder,
19
+ TInjects | Injects
20
+ > {
21
+ public value: TsValue<TBuilder>;
22
+
23
+ constructor(options: Options<TBuilder, TInjects>) {
24
+ super(options);
25
+ this.value = options.value;
26
+ }
27
+
28
+ protected override onWrite(builder: TBuilder): void {
29
+ writeTsNode(builder, this.value);
30
+ }
31
+ }
32
+
33
+ const createArgument = <TBuilder extends SourceBuilder>(
34
+ value: Options<TBuilder>['value'],
35
+ options?: Prettify<Omit<Options<TBuilder>, 'value'>>,
36
+ ): TsArgument<TBuilder> => new TsArgument<TBuilder>({ ...options, value });
37
+
38
+ export const tsArgument: typeof createArgument & { write: typeof writeTsParameters } = Object.assign(createArgument, {
39
+ write: writeTsParameters,
40
+ });
@@ -0,0 +1,49 @@
1
+ import type { AstNodeOptions, Nullable, Prettify, SourceBuilder } from '@goast/core';
2
+
3
+ import { TsNode } from '../node.js';
4
+ import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
5
+ import type { TsType } from './types.js';
6
+
7
+ type Injects = 'type';
8
+
9
+ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
10
+ typeof TsNode<TBuilder, TInjects | Injects>,
11
+ {
12
+ readonly?: Nullable<boolean>;
13
+ type: TsType<TBuilder>;
14
+ }
15
+ >;
16
+
17
+ export class TsArrayType<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
18
+ TBuilder,
19
+ TInjects | Injects
20
+ > {
21
+ public readonly: boolean;
22
+ public type: TsType<TBuilder>;
23
+
24
+ constructor(options: Options<TBuilder, TInjects>) {
25
+ super(options);
26
+ this.readonly = options.readonly ?? false;
27
+ this.type = options.type;
28
+ }
29
+
30
+ protected override onWrite(builder: TBuilder): void {
31
+ if (this.readonly) builder.append('readonly ');
32
+
33
+ builder
34
+ .append(this.inject.beforeType)
35
+ .parenthesize('()', (b) => writeTsNode(b, this.type))
36
+ .append(this.inject.afterType);
37
+
38
+ builder.append('[]');
39
+ }
40
+ }
41
+
42
+ const createArrayType = <TBuilder extends SourceBuilder>(
43
+ type: Options<TBuilder>['type'],
44
+ options?: Prettify<Omit<Options<TBuilder>, 'type'>>,
45
+ ): TsArrayType<TBuilder> => new TsArrayType<TBuilder>({ ...options, type });
46
+
47
+ export const tsArrayType: typeof createArrayType & { write: typeof writeTsNodes } = Object.assign(createArrayType, {
48
+ write: writeTsNodes,
49
+ });
@@ -0,0 +1,91 @@
1
+ import {
2
+ type AppendValue,
3
+ type AstNodeOptions,
4
+ type BasicAppendValue,
5
+ notNullish,
6
+ type Nullable,
7
+ type SourceBuilder,
8
+ } from '@goast/core';
9
+
10
+ import { TsNode } from '../node.js';
11
+ import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
12
+ import { type TsGenericParameter, tsGenericParameter } from './generic-parameter.js';
13
+ import { type TsParameter, tsParameter } from './parameter.js';
14
+ import type { TsType } from './types.js';
15
+
16
+ type Injects = 'generics' | 'params' | 'returnType' | 'body';
17
+
18
+ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
19
+ typeof TsNode<TBuilder, TInjects | Injects>,
20
+ {
21
+ async?: Nullable<boolean>;
22
+ generics?: Nullable<Nullable<TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
23
+ parameters?: Nullable<Nullable<TsParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
24
+ returnType?: Nullable<TsType<TBuilder>>;
25
+ singleExpression?: Nullable<boolean>;
26
+ body?: Nullable<AppendValue<TBuilder>>;
27
+ }
28
+ >;
29
+
30
+ export class TsArrowFunction<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
31
+ TBuilder,
32
+ TInjects | Injects
33
+ > {
34
+ public async: boolean;
35
+ public generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
36
+ public parameters: (TsParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
37
+ public returnType: TsType<TBuilder> | null;
38
+ public singleExpression: boolean;
39
+ public body: AppendValue<TBuilder> | null;
40
+
41
+ constructor(options: Options<TBuilder, TInjects>) {
42
+ super(options);
43
+ this.async = options.async ?? false;
44
+ this.generics = options.generics?.filter(notNullish) ?? [];
45
+ this.parameters = options.parameters?.filter(notNullish) ?? [];
46
+ this.returnType = options.returnType ?? null;
47
+ this.singleExpression = options.singleExpression ?? false;
48
+ this.body = options.body ?? null;
49
+ }
50
+
51
+ protected override onWrite(builder: TBuilder): void {
52
+ if (this.async) {
53
+ builder.append('async ');
54
+ }
55
+
56
+ builder.append(this.inject.beforeGenerics);
57
+ tsGenericParameter.write(builder, this.generics);
58
+ builder.append(this.inject.afterGenerics);
59
+
60
+ builder.append(this.inject.beforeParams);
61
+ tsParameter.write(builder, this.parameters);
62
+ builder.append(this.inject.afterParams);
63
+
64
+ if (this.returnType) {
65
+ builder.append(': ');
66
+ builder.append(this.inject.beforeReturnType);
67
+ writeTsNode(builder, this.returnType);
68
+ builder.append(this.inject.afterReturnType);
69
+ }
70
+
71
+ builder.append(' => ');
72
+
73
+ builder.append(this.inject.beforeBody);
74
+ if (this.singleExpression && this.body) {
75
+ builder.append(this.body);
76
+ } else {
77
+ builder.parenthesize('{}', this.body, { multiline: !!this.body });
78
+ }
79
+ builder.append(this.inject.afterBody);
80
+ }
81
+ }
82
+
83
+ const createArrowFunction = <TBuilder extends SourceBuilder>(options?: Options<TBuilder>): TsArrowFunction<TBuilder> =>
84
+ new TsArrowFunction<TBuilder>(options ?? {});
85
+
86
+ export const tsArrowFunction: typeof createArrowFunction & { write: typeof writeTsNodes } = Object.assign(
87
+ createArrowFunction,
88
+ {
89
+ write: writeTsNodes,
90
+ },
91
+ );
@@ -0,0 +1,55 @@
1
+ import {
2
+ type ArrayItem,
3
+ type AstNodeOptions,
4
+ notNullish,
5
+ type Nullable,
6
+ type Prettify,
7
+ type SourceBuilder,
8
+ } from '@goast/core';
9
+
10
+ import { TsNode } from '../node.js';
11
+ import { writeTsNodes } from '../utils/write-ts-nodes.js';
12
+ import { type TsArgument, tsArgument } from './argument.js';
13
+ import type { TsType, TsValue } from './types.js';
14
+
15
+ type Injects = never;
16
+
17
+ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
18
+ typeof TsNode<TBuilder, TInjects | Injects>,
19
+ {
20
+ path: Nullable<TsType<TBuilder> | TsValue<TBuilder>>[];
21
+ arguments?: Nullable<Nullable<TsArgument<TBuilder> | TsValue<TBuilder>>[]>;
22
+ }
23
+ >;
24
+
25
+ export class TsCall<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
26
+ TBuilder,
27
+ TInjects | Injects
28
+ > {
29
+ public path: (TsType<TBuilder> | TsValue<TBuilder>)[];
30
+ public arguments: (TsArgument<TBuilder> | TsValue<TBuilder>)[] | null;
31
+
32
+ constructor(options: Options<TBuilder, TInjects>) {
33
+ super(options);
34
+ this.path = options.path.filter(notNullish);
35
+ this.arguments = options.arguments?.filter(notNullish) ?? null;
36
+ }
37
+
38
+ protected override onWrite(builder: TBuilder): void {
39
+ writeTsNodes(builder, this.path, { separator: '.' });
40
+
41
+ if (this.arguments) {
42
+ tsArgument.write(builder, this.arguments);
43
+ }
44
+ }
45
+ }
46
+
47
+ const createCall = <TBuilder extends SourceBuilder>(
48
+ path: Options<TBuilder>['path'] | ArrayItem<Options<TBuilder>['path']>,
49
+ args?: Options<TBuilder>['arguments'],
50
+ options?: Prettify<Omit<Options<TBuilder>, 'path' | 'arguments'>>,
51
+ ): TsCall<TBuilder> => new TsCall<TBuilder>({ ...options, path: Array.isArray(path) ? path : [path], arguments: args });
52
+
53
+ export const tsCall: typeof createCall & { write: typeof writeTsNodes } = Object.assign(createCall, {
54
+ write: writeTsNodes,
55
+ });
@@ -0,0 +1,133 @@
1
+ import {
2
+ type AstNodeOptions,
3
+ type BasicAppendValue,
4
+ notNullish,
5
+ type Nullable,
6
+ type Prettify,
7
+ type SourceBuilder,
8
+ } from '@goast/core';
9
+
10
+ import { TsNode } from '../node.js';
11
+ import { writeTsMembers } from '../utils/write-ts-members.js';
12
+ import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
13
+ import type { TsConstructor } from './constructor.js';
14
+ import { type TsDecorator, tsDecorator } from './decorator.js';
15
+ import { type TsDoc, tsDoc } from './doc.js';
16
+ import { type TsGenericParameter, tsGenericParameter } from './generic-parameter.js';
17
+ import type { TsIndexer } from './indexer.js';
18
+ import type { TsMethod } from './method.js';
19
+ import type { TsProperty } from './property.js';
20
+ import type { TsReference } from './reference.js';
21
+
22
+ type Injects = 'doc' | 'decorators' | 'modifiers' | 'name' | 'generics' | 'extends' | 'implements' | 'body' | 'members';
23
+
24
+ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
25
+ typeof TsNode<TBuilder, TInjects | Injects>,
26
+ {
27
+ doc?: Nullable<TsDoc<TBuilder>>;
28
+ decorators?: Nullable<Nullable<TsDecorator<TBuilder>>[]>;
29
+ export?: Nullable<boolean>;
30
+ abstract?: Nullable<boolean>;
31
+ name: string;
32
+ generics?: Nullable<Nullable<TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
33
+ extends?: Nullable<TsReference<TBuilder> | BasicAppendValue<TBuilder>>;
34
+ implements?: Nullable<Nullable<TsReference<TBuilder> | BasicAppendValue<TBuilder>>[]>;
35
+ members?: Nullable<Nullable<Member<TBuilder>>[]>;
36
+ }
37
+ >;
38
+
39
+ type Member<TBuilder extends SourceBuilder> =
40
+ | TsProperty<TBuilder>
41
+ | TsMethod<TBuilder>
42
+ | TsIndexer<TBuilder>
43
+ | TsConstructor<TBuilder>
44
+ | BasicAppendValue<TBuilder>;
45
+
46
+ export class TsClass<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
47
+ TBuilder,
48
+ TInjects | Injects
49
+ > {
50
+ public doc: TsDoc<TBuilder> | null;
51
+ public decorators: TsDecorator<TBuilder>[];
52
+ public export: boolean;
53
+ public abstract: boolean;
54
+ public name: string;
55
+ public generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
56
+ public extends: TsReference<TBuilder> | BasicAppendValue<TBuilder> | null;
57
+ public implements: (TsReference<TBuilder> | BasicAppendValue<TBuilder>)[];
58
+ public members: Member<TBuilder>[];
59
+
60
+ constructor(options: Options<TBuilder, TInjects>) {
61
+ super(options);
62
+ this.doc = options.doc ?? null;
63
+ this.decorators = options.decorators?.filter(notNullish) ?? [];
64
+ this.export = options.export ?? false;
65
+ this.abstract = options.abstract ?? false;
66
+ this.name = options.name;
67
+ this.generics = options.generics?.filter(notNullish) ?? [];
68
+ this.extends = options.extends ?? null;
69
+ this.implements = options.implements?.filter(notNullish) ?? [];
70
+ this.members = options.members?.filter(notNullish) ?? [];
71
+ }
72
+
73
+ protected override onWrite(builder: TBuilder): void {
74
+ builder.append(this.inject.beforeDoc);
75
+ tsDoc.write(builder, tsDoc.get(this.doc, { generics: this.generics }));
76
+ builder.append(this.inject.afterDoc);
77
+
78
+ builder.append(this.inject.beforeDecorators);
79
+ tsDecorator.write(builder, this.decorators, { multiline: true });
80
+ builder.append(this.inject.afterDecorators);
81
+
82
+ builder.append(this.inject.beforeModifiers);
83
+ if (this.export) builder.append('export ');
84
+ if (this.abstract) builder.append('abstract ');
85
+ builder.append(this.inject.afterModifiers);
86
+
87
+ builder.append('class ');
88
+ builder.append(this.inject.beforeName, this.name, this.inject.afterName);
89
+
90
+ builder.append(this.inject.beforeGenerics);
91
+ tsGenericParameter.write(builder, this.generics);
92
+ builder.append(this.inject.afterGenerics);
93
+
94
+ if (this.extends) {
95
+ builder.append(' extends ');
96
+ builder.append(this.inject.beforeExtends);
97
+ writeTsNode(builder, this.extends);
98
+ builder.append(this.inject.afterExtends);
99
+ }
100
+
101
+ if (this.implements.length > 0) {
102
+ builder.append(' implements ');
103
+ builder.append(this.inject.beforeImplements);
104
+ writeTsNodes(builder, this.implements, { separator: ', ' });
105
+ builder.append(this.inject.afterImplements);
106
+ }
107
+
108
+ builder.append(' ');
109
+
110
+ builder.append(this.inject.beforeBody);
111
+ builder.parenthesize(
112
+ '{}',
113
+ (b) => {
114
+ b.append(this.inject.beforeMembers);
115
+ writeTsMembers(b, this.members);
116
+ b.append(this.inject.afterMembers);
117
+ },
118
+ { multiline: this.members.length > 0 },
119
+ );
120
+ builder.append(this.inject.afterBody);
121
+
122
+ builder.appendLine();
123
+ }
124
+ }
125
+
126
+ const createClass = <TBuilder extends SourceBuilder>(
127
+ name: Options<TBuilder>['name'],
128
+ options?: Prettify<Omit<Options<TBuilder>, 'name'>>,
129
+ ): TsClass<TBuilder> => new TsClass<TBuilder>({ ...options, name });
130
+
131
+ export const tsClass: typeof createClass & { write: typeof writeTsNodes } = Object.assign(createClass, {
132
+ write: writeTsNodes,
133
+ });