@goast/typescript 0.7.5 → 0.8.0-beta.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 (100) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +52 -52
  3. package/assets/client/angular/angular-service.utils.ts +82 -82
  4. package/assets/client/angular/request-builder.ts +377 -377
  5. package/assets/client/fetch/fetch-client.utils.ts +52 -52
  6. package/assets/client/k6/request-builder.js +448 -448
  7. package/assets/client/k6/request-builder.ts +366 -366
  8. package/assets/stubs/easy-network-stub/easy-network-stub.utils.ts +257 -257
  9. package/esm/src/generators/services/angular-services/angular-service-generator.js +9 -9
  10. package/esm/src/generators/services/easy-network-stub/easy-network-stub-generator.js +9 -9
  11. package/esm/src/generators/services/fetch-clients/fetch-client-generator.js +4 -4
  12. package/esm/src/generators/services/k6-clients/k6-client-generator.js +11 -11
  13. package/package.json +2 -2
  14. package/script/src/generators/services/angular-services/angular-service-generator.js +9 -9
  15. package/script/src/generators/services/easy-network-stub/easy-network-stub-generator.js +9 -9
  16. package/script/src/generators/services/fetch-clients/fetch-client-generator.js +4 -4
  17. package/script/src/generators/services/k6-clients/k6-client-generator.js +11 -11
  18. package/src/mod.ts +0 -7
  19. package/src/src/assets.ts +0 -9
  20. package/src/src/ast/_index.ts +0 -54
  21. package/src/src/ast/common.ts +0 -1
  22. package/src/src/ast/index.ts +0 -1
  23. package/src/src/ast/node.ts +0 -10
  24. package/src/src/ast/nodes/argument.ts +0 -40
  25. package/src/src/ast/nodes/array-type.ts +0 -49
  26. package/src/src/ast/nodes/arrow-function.ts +0 -91
  27. package/src/src/ast/nodes/call.ts +0 -55
  28. package/src/src/ast/nodes/class.ts +0 -133
  29. package/src/src/ast/nodes/constructor-parameter.ts +0 -70
  30. package/src/src/ast/nodes/constructor.ts +0 -77
  31. package/src/src/ast/nodes/decorator.ts +0 -76
  32. package/src/src/ast/nodes/doc-tag.ts +0 -291
  33. package/src/src/ast/nodes/doc.ts +0 -102
  34. package/src/src/ast/nodes/enum-value.ts +0 -72
  35. package/src/src/ast/nodes/enum.ts +0 -77
  36. package/src/src/ast/nodes/export.ts +0 -54
  37. package/src/src/ast/nodes/function-type.ts +0 -60
  38. package/src/src/ast/nodes/function.ts +0 -107
  39. package/src/src/ast/nodes/generic-parameter.ts +0 -71
  40. package/src/src/ast/nodes/indexer.ts +0 -60
  41. package/src/src/ast/nodes/interface.ts +0 -117
  42. package/src/src/ast/nodes/intersection-type.ts +0 -67
  43. package/src/src/ast/nodes/lookup-type.ts +0 -53
  44. package/src/src/ast/nodes/method.ts +0 -138
  45. package/src/src/ast/nodes/object-type.ts +0 -52
  46. package/src/src/ast/nodes/object.ts +0 -48
  47. package/src/src/ast/nodes/parameter.ts +0 -85
  48. package/src/src/ast/nodes/property-accessor.ts +0 -173
  49. package/src/src/ast/nodes/property.ts +0 -192
  50. package/src/src/ast/nodes/reference.ts +0 -194
  51. package/src/src/ast/nodes/string.ts +0 -49
  52. package/src/src/ast/nodes/tuple.ts +0 -53
  53. package/src/src/ast/nodes/type-alias.ts +0 -75
  54. package/src/src/ast/nodes/typeof.ts +0 -42
  55. package/src/src/ast/nodes/types.ts +0 -40
  56. package/src/src/ast/nodes/union-type.ts +0 -62
  57. package/src/src/ast/nodes/variable.ts +0 -73
  58. package/src/src/ast/references/angular.ts +0 -24
  59. package/src/src/ast/references/easy-network-stub.ts +0 -21
  60. package/src/src/ast/references/index.ts +0 -5
  61. package/src/src/ast/references/k6.ts +0 -8
  62. package/src/src/ast/references/rxjs.ts +0 -7
  63. package/src/src/ast/references/typescript.ts +0 -35
  64. package/src/src/ast/utils/get-type-script-builder-options.ts +0 -19
  65. package/src/src/ast/utils/to-ts-node.ts +0 -27
  66. package/src/src/ast/utils/write-ts-generic-parameters.ts +0 -25
  67. package/src/src/ast/utils/write-ts-members.ts +0 -28
  68. package/src/src/ast/utils/write-ts-nodes.ts +0 -35
  69. package/src/src/ast/utils/write-ts-parameters.ts +0 -25
  70. package/src/src/common-results.ts +0 -26
  71. package/src/src/config.ts +0 -96
  72. package/src/src/file-builder.ts +0 -137
  73. package/src/src/generators/file-generator.ts +0 -15
  74. package/src/src/generators/index.ts +0 -6
  75. package/src/src/generators/models/index.ts +0 -3
  76. package/src/src/generators/models/model-generator.ts +0 -493
  77. package/src/src/generators/models/models-generator.ts +0 -108
  78. package/src/src/generators/models/models.ts +0 -121
  79. package/src/src/generators/services/angular-services/angular-service-generator.ts +0 -431
  80. package/src/src/generators/services/angular-services/angular-services-generator.ts +0 -295
  81. package/src/src/generators/services/angular-services/index.ts +0 -3
  82. package/src/src/generators/services/angular-services/models.ts +0 -277
  83. package/src/src/generators/services/angular-services/refs.ts +0 -54
  84. package/src/src/generators/services/easy-network-stub/easy-network-stub-generator.ts +0 -250
  85. package/src/src/generators/services/easy-network-stub/easy-network-stubs-generator.ts +0 -211
  86. package/src/src/generators/services/easy-network-stub/index.ts +0 -3
  87. package/src/src/generators/services/easy-network-stub/models.ts +0 -124
  88. package/src/src/generators/services/easy-network-stub/refs.ts +0 -47
  89. package/src/src/generators/services/fetch-clients/fetch-client-generator.ts +0 -305
  90. package/src/src/generators/services/fetch-clients/fetch-clients-generator.ts +0 -163
  91. package/src/src/generators/services/fetch-clients/index.ts +0 -3
  92. package/src/src/generators/services/fetch-clients/models.ts +0 -130
  93. package/src/src/generators/services/fetch-clients/refs.ts +0 -21
  94. package/src/src/generators/services/k6-clients/index.ts +0 -3
  95. package/src/src/generators/services/k6-clients/k6-client-generator.ts +0 -505
  96. package/src/src/generators/services/k6-clients/k6-clients-generator.ts +0 -171
  97. package/src/src/generators/services/k6-clients/models.ts +0 -247
  98. package/src/src/generators/services/k6-clients/refs.ts +0 -16
  99. package/src/src/import-collection.ts +0 -236
  100. package/src/src/utils.ts +0 -79
@@ -1,194 +0,0 @@
1
- import {
2
- type AstNodeOptions,
3
- notNullish,
4
- type Nullable,
5
- type Prettify,
6
- type SourceBuilder,
7
- type TupleWithCount,
8
- } from '@goast/core';
9
-
10
- import type { TypeScriptImportType } from '../../common-results.js';
11
- import { TypeScriptFileBuilder } from '../../file-builder.js';
12
- import { TsNode } from '../node.js';
13
- import { writeTsGenericParameters } from '../utils/write-ts-generic-parameters.js';
14
- import { writeTsNodes } from '../utils/write-ts-nodes.js';
15
- import type { TsType } from './types.js';
16
-
17
- type Injects = never;
18
-
19
- type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
20
- typeof TsNode<TBuilder, TInjects | Injects>,
21
- {
22
- name: string;
23
- moduleNameOrfilePath?: Nullable<string>;
24
- generics?: Nullable<Nullable<TsType<TBuilder>>[]>;
25
- importType?: Nullable<TypeScriptImportType>;
26
- }
27
- >;
28
- type FactoryOptions<TBuilder extends SourceBuilder> = {
29
- importType?: Nullable<TypeScriptImportType>;
30
- };
31
-
32
- type _AddImportHandler<T> = {
33
- // deno-lint-ignore no-explicit-any
34
- builderClass: abstract new (...args: any[]) => T;
35
- // deno-lint-ignore no-explicit-any
36
- handler: (builder: T, reference: TsReference<any>) => void;
37
- };
38
-
39
- export class TsReference<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
40
- TBuilder,
41
- TInjects | Injects
42
- > {
43
- // deno-lint-ignore no-explicit-any
44
- private static readonly addImportHandlers: _AddImportHandler<any>[] = [
45
- {
46
- builderClass: TypeScriptFileBuilder,
47
- handler: (builder: TypeScriptFileBuilder, reference) => {
48
- if (reference.moduleNameOrfilePath) {
49
- builder.addImport(reference.name, reference.moduleNameOrfilePath, { type: reference.importType });
50
- }
51
- },
52
- },
53
- ];
54
-
55
- public name: string;
56
- public moduleNameOrfilePath: string | null;
57
- public generics: TsType<TBuilder>[];
58
- public importType: TypeScriptImportType;
59
-
60
- constructor(options: Options<TBuilder, TInjects>) {
61
- super(options);
62
- this.name = options.name;
63
- this.moduleNameOrfilePath = options.moduleNameOrfilePath ?? null;
64
- this.generics = options.generics?.filter(notNullish) ?? [];
65
- this.importType = options.importType ?? 'import';
66
- }
67
-
68
- protected override onWrite(builder: TBuilder): void {
69
- builder.append(this.name);
70
- writeTsGenericParameters(builder, this.generics);
71
- if (this.moduleNameOrfilePath) {
72
- const handler = TsReference.addImportHandlers.find((h) => builder instanceof h.builderClass);
73
- if (handler) {
74
- handler.handler(builder, this);
75
- }
76
- }
77
- }
78
-
79
- public static registerAddImportHandler<TBuilder extends SourceBuilder>(
80
- builderClass: _AddImportHandler<TBuilder>['builderClass'],
81
- handler: _AddImportHandler<TBuilder>['handler'],
82
- ): void {
83
- TsReference.addImportHandlers.push({ builderClass, handler });
84
- }
85
- }
86
-
87
- const createReference = <TBuilder extends SourceBuilder>(
88
- name: Options<TBuilder>['name'],
89
- moduleNameOrfilePath?: Options<TBuilder>['moduleNameOrfilePath'],
90
- options?: Prettify<Omit<Options<TBuilder>, 'name' | 'moduleNameOrfilePath'>>,
91
- ): TsReference<TBuilder> => new TsReference<TBuilder>({ ...options, name, moduleNameOrfilePath });
92
-
93
- export type TsReferenceFactory =
94
- & (<TBuilder extends SourceBuilder>(options?: FactoryOptions<TBuilder>) => TsReference<TBuilder>)
95
- & {
96
- refName: string;
97
- moduleNameOrfilePath: Nullable<string>;
98
- };
99
- export type TsModuleReferenceFactory = TsReferenceFactory & {
100
- moduleNameOrfilePath: string;
101
- };
102
-
103
- export type TsGenericReferenceFactory<TGenericCount extends number | number[]> =
104
- & (<TBuilder extends SourceBuilder>(
105
- generics: TupleWithCount<TsType<TBuilder>, TGenericCount>,
106
- options?: FactoryOptions<TBuilder>,
107
- ) => TsReference<TBuilder>)
108
- & {
109
- refName: string;
110
- moduleNameOrfilePath: Nullable<string>;
111
- infer: <TBuilder extends SourceBuilder>() => TsReference<TBuilder>;
112
- };
113
- export type TsGenericModuleReferenceFactory<TGenericCount extends number | number[]> =
114
- & TsGenericReferenceFactory<TGenericCount>
115
- & {
116
- moduleNameOrfilePath: string;
117
- };
118
-
119
- function _createFactory(
120
- name: string,
121
- moduleNameOrfilePath?: Nullable<string>,
122
- defaultOptions?: { importType?: Nullable<TypeScriptImportType> },
123
- ): TsReferenceFactory {
124
- return Object.assign(
125
- <TBuilder extends SourceBuilder>(options?: FactoryOptions<TBuilder>) =>
126
- createReference<TBuilder>(name, moduleNameOrfilePath, { ...defaultOptions, ...options }),
127
- {
128
- refName: name,
129
- moduleNameOrfilePath,
130
- },
131
- );
132
- }
133
- function createFactory(
134
- name: string,
135
- moduleNameOrfilePath: string,
136
- defaultOptions?: { importType?: Nullable<TypeScriptImportType> },
137
- ): TsModuleReferenceFactory;
138
- function createFactory(
139
- name: string,
140
- moduleNameOrfilePath?: Nullable<string>,
141
- defaultOptions?: { importType?: Nullable<TypeScriptImportType> },
142
- ): TsReferenceFactory;
143
- function createFactory(
144
- name: string,
145
- moduleNameOrfilePath?: Nullable<string>,
146
- defaultOptions?: { importType?: Nullable<TypeScriptImportType> },
147
- ): TsReferenceFactory {
148
- return _createFactory(name, moduleNameOrfilePath, defaultOptions);
149
- }
150
-
151
- function _createGenericFactory<TGenericCount extends number | number[]>(
152
- name: string,
153
- moduleNameOrfilePath?: Nullable<string>,
154
- defaultOptions?: { importType?: Nullable<TypeScriptImportType> },
155
- ): TsGenericReferenceFactory<TGenericCount> {
156
- return Object.assign(
157
- <TBuilder extends SourceBuilder>(
158
- generics: TupleWithCount<TsType<TBuilder>, TGenericCount>,
159
- options?: FactoryOptions<TBuilder>,
160
- ) => createReference<TBuilder>(name, moduleNameOrfilePath, { ...defaultOptions, ...options, generics }),
161
- {
162
- refName: name,
163
- moduleNameOrfilePath,
164
- infer: <TBuilder extends SourceBuilder>() => createReference<TBuilder>(name, moduleNameOrfilePath),
165
- },
166
- );
167
- }
168
- function createGenericFactory<TGenericCount extends number | number[]>(
169
- name: string,
170
- moduleNameOrfilePath: string,
171
- defaultOptions?: { importType?: Nullable<TypeScriptImportType> },
172
- ): TsGenericModuleReferenceFactory<TGenericCount>;
173
- function createGenericFactory<TGenericCount extends number | number[]>(
174
- name: string,
175
- moduleNameOrfilePath?: Nullable<string>,
176
- defaultOptions?: { importType?: Nullable<TypeScriptImportType> },
177
- ): TsGenericReferenceFactory<TGenericCount>;
178
- function createGenericFactory<TGenericCount extends number | number[]>(
179
- name: string,
180
- moduleNameOrfilePath?: Nullable<string>,
181
- defaultOptions?: { importType?: Nullable<TypeScriptImportType> },
182
- ): TsGenericReferenceFactory<TGenericCount> {
183
- return _createGenericFactory<TGenericCount>(name, moduleNameOrfilePath, defaultOptions);
184
- }
185
-
186
- export const tsReference: typeof createReference & {
187
- factory: typeof createFactory;
188
- genericFactory: typeof createGenericFactory;
189
- write: typeof writeTsNodes;
190
- } = Object.assign(createReference, {
191
- factory: createFactory,
192
- genericFactory: createGenericFactory,
193
- write: writeTsNodes,
194
- });
@@ -1,49 +0,0 @@
1
- import type { AstNodeOptions, Nullable, Prettify, SourceBuilder } from '@goast/core';
2
-
3
- import { TsNode } from '../node.js';
4
- import { getTypeScriptBuilderOptions } from '../utils/get-type-script-builder-options.js';
5
- import { writeTsNodes } from '../utils/write-ts-nodes.js';
6
-
7
- type Injects = never;
8
-
9
- type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
10
- typeof TsNode<TBuilder, TInjects | Injects>,
11
- {
12
- value: string;
13
- template?: Nullable<boolean>;
14
- }
15
- >;
16
-
17
- export class TsString<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
18
- TBuilder,
19
- TInjects | Injects
20
- > {
21
- public value: string;
22
- public template: boolean;
23
-
24
- constructor(options: Options<TBuilder, TInjects>) {
25
- super(options);
26
- this.value = options.value;
27
- this.template = options.template ?? false;
28
- }
29
-
30
- protected override onWrite(builder: TBuilder): void {
31
- const builderOptions = getTypeScriptBuilderOptions(builder);
32
- let value = JSON.stringify(this.value);
33
- if (this.template) {
34
- value = `\`${value.slice(1, -1).replace(/`/g, '\\`')}\``;
35
- } else if (builderOptions.useSingleQuotes) {
36
- value = `'${value.slice(1, -1).replace(/'/g, "\\'")}'`;
37
- }
38
- builder.append(value);
39
- }
40
- }
41
-
42
- const createString = <TBuilder extends SourceBuilder>(
43
- value: Options<TBuilder>['value'],
44
- options?: Prettify<Omit<Options<TBuilder>, 'value'>>,
45
- ): TsString<TBuilder> => new TsString<TBuilder>({ ...options, value });
46
-
47
- export const tsString: typeof createString & { write: typeof writeTsNodes } = Object.assign(createString, {
48
- write: writeTsNodes,
49
- });
@@ -1,53 +0,0 @@
1
- import { type AstNodeOptions, notNullish, type Nullable, type Prettify, type SourceBuilder } from '@goast/core';
2
-
3
- import { TsNode } from '../node.js';
4
- import { writeTsNodes } from '../utils/write-ts-nodes.js';
5
- import type { TsType, TsValue } from './types.js';
6
-
7
- type Injects = never;
8
-
9
- type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
10
- typeof TsNode<TBuilder, TInjects | Injects>,
11
- {
12
- elements: Nullable<TsType<TBuilder> | TsValue<TBuilder>>[];
13
- asConst?: Nullable<boolean>;
14
- }
15
- >;
16
-
17
- export class TsTuple<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
18
- TBuilder,
19
- TInjects | Injects
20
- > {
21
- public elements: (TsType<TBuilder> | TsValue<TBuilder>)[];
22
- public asConst: boolean;
23
-
24
- constructor(options: Options<TBuilder, TInjects>) {
25
- super(options);
26
- this.elements = options.elements.filter(notNullish);
27
- this.asConst = options.asConst ?? false;
28
- }
29
-
30
- protected override onWrite(builder: TBuilder): void {
31
- if (this.elements.length === 0) {
32
- builder.append('[]');
33
- } else {
34
- const multiline = this.elements.length > 3;
35
- builder.parenthesize('[]', (b) => writeTsNodes(b, this.elements, { separator: multiline ? ',\n' : ', ' }), {
36
- multiline,
37
- });
38
- }
39
-
40
- if (this.asConst) {
41
- builder.append(' as const');
42
- }
43
- }
44
- }
45
-
46
- const createTuple = <TBuilder extends SourceBuilder>(
47
- elements: Options<TBuilder>['elements'],
48
- options?: Prettify<Omit<Options<TBuilder>, 'elements'>>,
49
- ): TsTuple<TBuilder> => new TsTuple<TBuilder>({ ...options, elements });
50
-
51
- export const tsTuple: typeof createTuple & { write: typeof writeTsNodes } = Object.assign(createTuple, {
52
- write: writeTsNodes,
53
- });
@@ -1,75 +0,0 @@
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 { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
12
- import type { TsDoc } from './doc.js';
13
- import { type TsGenericParameter, tsGenericParameter } from './generic-parameter.js';
14
- import type { TsType } from './types.js';
15
-
16
- type Injects = never;
17
-
18
- type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
19
- typeof TsNode<TBuilder, TInjects | Injects>,
20
- {
21
- name: string;
22
- doc?: Nullable<TsDoc<TBuilder>>;
23
- generics?: Nullable<Nullable<TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
24
- type: TsType<TBuilder>;
25
- export?: Nullable<boolean>;
26
- }
27
- >;
28
-
29
- export class TsTypeAlias<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
30
- TBuilder,
31
- TInjects | Injects
32
- > {
33
- public name: string;
34
- public doc: TsDoc<TBuilder> | null;
35
- public generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
36
- public type: TsType<TBuilder>;
37
- public export: boolean;
38
-
39
- constructor(options: Options<TBuilder, TInjects>) {
40
- super(options);
41
- this.name = options.name;
42
- this.doc = options.doc ?? null;
43
- this.generics = options.generics?.filter(notNullish) ?? [];
44
- this.type = options.type;
45
- this.export = options.export ?? false;
46
- }
47
-
48
- protected override onWrite(builder: TBuilder): void {
49
- if (this.doc) writeTsNode(builder, this.doc);
50
- if (this.export) builder.append('export ');
51
-
52
- builder.append('type ');
53
- builder.append(this.name);
54
- tsGenericParameter.write(builder, this.generics);
55
-
56
- builder.append(' = ');
57
- builder.indent((b) => {
58
- writeTsNode(b, this.type);
59
- });
60
-
61
- builder.append(';');
62
-
63
- builder.appendLine();
64
- }
65
- }
66
-
67
- const createTypeAlias = <TBuilder extends SourceBuilder>(
68
- name: Options<TBuilder>['name'],
69
- type: Options<TBuilder>['type'],
70
- options?: Prettify<Omit<Options<TBuilder>, 'name' | 'type'>>,
71
- ): TsTypeAlias<TBuilder> => new TsTypeAlias<TBuilder>({ ...options, name, type });
72
-
73
- export const tsTypeAlias: typeof createTypeAlias & { write: typeof writeTsNodes } = Object.assign(createTypeAlias, {
74
- write: writeTsNodes,
75
- });
@@ -1,42 +0,0 @@
1
- import type { AstNodeOptions, SourceBuilder } from '@goast/core';
2
-
3
- import { TsNode } from '../node.js';
4
- import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
5
- import type { TsValue } from './types.js';
6
-
7
- type Injects = 'value';
8
-
9
- type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
10
- typeof TsNode<TBuilder, TInjects | Injects>,
11
- {
12
- value: TsValue<TBuilder>;
13
- }
14
- >;
15
-
16
- export class TsTypeof<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
17
- TBuilder,
18
- TInjects | Injects
19
- > {
20
- public value: TsValue<TBuilder>;
21
-
22
- constructor(options: Options<TBuilder, TInjects>) {
23
- super(options);
24
- this.value = options.value;
25
- }
26
-
27
- protected override onWrite(builder: TBuilder): void {
28
- builder.append('typeof ');
29
- builder.append(this.inject.beforeValue);
30
- writeTsNode(builder, this.value);
31
- builder.append(this.inject.afterValue);
32
- }
33
- }
34
-
35
- export const createTypeof = <TBuilder extends SourceBuilder>(
36
- value: Options<TBuilder>['value'],
37
- options?: Omit<Options<TBuilder>, 'value'>,
38
- ): TsTypeof<TBuilder> => new TsTypeof<TBuilder>({ ...options, value });
39
-
40
- export const tsTypeof: typeof createTypeof & { write: typeof writeTsNodes } = Object.assign(createTypeof, {
41
- write: writeTsNodes,
42
- });
@@ -1,40 +0,0 @@
1
- import type { BasicAppendValue, SourceBuilder } from '@goast/core';
2
- import type { TsArrayType } from './array-type.js';
3
- import type { TsArrowFunction } from './arrow-function.js';
4
- import type { TsCall } from './call.js';
5
- import type { TsClass } from './class.js';
6
- import type { TsFunctionType } from './function-type.js';
7
- import type { TsFunction } from './function.js';
8
- import type { TsIntersectionType } from './intersection-type.js';
9
- import type { TsLookupType } from './lookup-type.js';
10
- import type { TsObjectType } from './object-type.js';
11
- import type { TsObject } from './object.js';
12
- import type { TsReference } from './reference.js';
13
- import type { TsString } from './string.js';
14
- import type { TsTuple } from './tuple.js';
15
- import type { TsTypeof } from './typeof.js';
16
- import type { TsUnionType } from './union-type.js';
17
-
18
- export type TsType<TBuilder extends SourceBuilder> =
19
- | BasicAppendValue<TBuilder>
20
- | TsIntersectionType<TBuilder>
21
- | TsUnionType<TBuilder>
22
- | TsArrayType<TBuilder>
23
- | TsTuple<TBuilder>
24
- | TsFunctionType<TBuilder>
25
- | TsObjectType<TBuilder>
26
- | TsString<TBuilder>
27
- | TsLookupType<TBuilder>
28
- | TsTypeof<TBuilder>
29
- | TsReference<TBuilder>;
30
-
31
- export type TsValue<TBuilder extends SourceBuilder> =
32
- | BasicAppendValue<TBuilder>
33
- | TsObject<TBuilder>
34
- | TsTuple<TBuilder>
35
- | TsString<TBuilder>
36
- | TsArrowFunction<TBuilder>
37
- | TsFunction<TBuilder>
38
- | TsClass<TBuilder>
39
- | TsCall<TBuilder>
40
- | TsReference<TBuilder>;
@@ -1,62 +0,0 @@
1
- import { type AstNodeOptions, notNullish, type Nullable, type Prettify, type 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 = never;
8
-
9
- type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
10
- typeof TsNode<TBuilder, TInjects | Injects>,
11
- {
12
- types: Nullable<TsType<TBuilder>>[];
13
- }
14
- >;
15
-
16
- export class TsUnionType<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
17
- TBuilder,
18
- TInjects | Injects
19
- > {
20
- public types: TsType<TBuilder>[];
21
-
22
- constructor(options: Options<TBuilder, TInjects>) {
23
- super(options);
24
- this.types = options.types.filter(notNullish);
25
- }
26
-
27
- protected override onWrite(builder: TBuilder): void {
28
- const types = this.types.length === 0 ? ['never'] : resolveNestedUnionTypes(this);
29
- if (types.length === 1) {
30
- writeTsNode(builder, types[0]);
31
- } else {
32
- const multiline = types.length > 3;
33
- if (multiline) {
34
- builder.appendLine().append('| ');
35
- }
36
- builder.forEach(types, (b, t) => b.parenthesize('()', (b) => writeTsNode(b, t)), {
37
- separator: multiline ? '\n| ' : ' | ',
38
- });
39
- }
40
- }
41
- }
42
-
43
- const createUnionType = <TBuilder extends SourceBuilder>(
44
- types: Options<TBuilder>['types'],
45
- options?: Prettify<Omit<Options<TBuilder>, 'types'>>,
46
- ): TsUnionType<TBuilder> => new TsUnionType<TBuilder>({ ...options, types });
47
-
48
- export const tsUnionType: typeof createUnionType & { write: typeof writeTsNodes } = Object.assign(createUnionType, {
49
- write: writeTsNodes,
50
- });
51
-
52
- function resolveNestedUnionTypes<TBuilder extends SourceBuilder>(node: TsUnionType<TBuilder>): TsType<TBuilder>[] {
53
- const types: TsType<TBuilder>[] = [];
54
- for (const type of node.types) {
55
- if (type instanceof TsUnionType) {
56
- types.push(...resolveNestedUnionTypes(type));
57
- } else {
58
- types.push(type);
59
- }
60
- }
61
- return types;
62
- }
@@ -1,73 +0,0 @@
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 { TsDoc } from './doc.js';
6
- import type { TsType, 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
- name: string;
14
- doc?: Nullable<TsDoc<TBuilder>>;
15
- type?: Nullable<TsType<TBuilder>>;
16
- value?: Nullable<TsValue<TBuilder>>;
17
- export?: Nullable<boolean>;
18
- readonly?: Nullable<boolean>;
19
- }
20
- >;
21
-
22
- export class TsVariable<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
23
- TBuilder,
24
- TInjects | Injects
25
- > {
26
- public name: string;
27
- public doc: TsDoc<TBuilder> | null;
28
- public type: TsType<TBuilder> | null;
29
- public value: TsValue<TBuilder> | null;
30
- public export: boolean;
31
- public readonly: boolean;
32
-
33
- constructor(options: Options<TBuilder, TInjects>) {
34
- super(options);
35
- this.name = options.name;
36
- this.doc = options.doc ?? null;
37
- this.type = options.type ?? null;
38
- this.value = options.value ?? null;
39
- this.export = options.export ?? false;
40
- this.readonly = options.readonly ?? false;
41
- }
42
-
43
- protected override onWrite(builder: TBuilder): void {
44
- if (this.doc) writeTsNode(builder, this.doc);
45
- if (this.export) builder.append('export ');
46
-
47
- builder.append(this.readonly ? 'const ' : 'let ');
48
- builder.append(this.name);
49
-
50
- if (this.type) {
51
- builder.append(': ');
52
- writeTsNode(builder, this.type);
53
- }
54
-
55
- if (this.value) {
56
- builder.append(' = ');
57
- writeTsNode(builder, this.value);
58
- }
59
-
60
- builder.append(';');
61
-
62
- builder.appendLine();
63
- }
64
- }
65
-
66
- const createVariable = <TBuilder extends SourceBuilder>(
67
- name: Options<TBuilder>['name'],
68
- options?: Prettify<Omit<Options<TBuilder>, 'name'>>,
69
- ): TsVariable<TBuilder> => new TsVariable<TBuilder>({ ...options, name });
70
-
71
- export const tsVariable: typeof createVariable & { write: typeof writeTsNodes } = Object.assign(createVariable, {
72
- write: writeTsNodes,
73
- });
@@ -1,24 +0,0 @@
1
- import {
2
- type TsGenericModuleReferenceFactory,
3
- type TsModuleReferenceFactory,
4
- tsReference,
5
- } from '../nodes/reference.js';
6
-
7
- // @angular/core
8
- export const inject: TsModuleReferenceFactory = tsReference.factory('inject', '@angular/core');
9
- export const injectable: TsModuleReferenceFactory = tsReference.factory('Injectable', '@angular/core');
10
- export const provider: TsModuleReferenceFactory = tsReference.factory('Provider', '@angular/core', {
11
- importType: 'type-import',
12
- });
13
-
14
- // @angular/common/http
15
- export const httpClient: TsModuleReferenceFactory = tsReference.factory('HttpClient', '@angular/common/http');
16
- export const httpContext: TsModuleReferenceFactory = tsReference.factory('HttpContext', '@angular/common/http');
17
- export const httpResponse: TsGenericModuleReferenceFactory<1> = tsReference.genericFactory<1>(
18
- 'HttpResponse',
19
- '@angular/common/http',
20
- );
21
- export const httpErrorResponse: TsModuleReferenceFactory = tsReference.factory(
22
- 'HttpErrorResponse',
23
- '@angular/common/http',
24
- );
@@ -1,21 +0,0 @@
1
- import {
2
- type TsGenericModuleReferenceFactory,
3
- type TsModuleReferenceFactory,
4
- tsReference,
5
- } from '../nodes/reference.js';
6
-
7
- export const easyNetworkStub: TsModuleReferenceFactory = tsReference.factory('EasyNetworkStub', 'easy-network-stub');
8
- export const httpMethod: TsModuleReferenceFactory = tsReference.factory('HttpMethod', 'easy-network-stub', {
9
- importType: 'type-import',
10
- });
11
- export const routeResponseCallback: TsGenericModuleReferenceFactory<2> = tsReference.genericFactory<2>(
12
- 'RouteResponseCallback',
13
- 'easy-network-stub',
14
- {
15
- importType: 'type-import',
16
- },
17
- );
18
- export const errorResponse: TsGenericModuleReferenceFactory<1> = tsReference.genericFactory<1>(
19
- 'ErrorResponse',
20
- 'easy-network-stub',
21
- );
@@ -1,5 +0,0 @@
1
- export * as angular from './angular.js';
2
- export * as easyNetworkStub from './easy-network-stub.js';
3
- export * as k6 from './k6.js';
4
- export * as rxjs from './rxjs.js';
5
- export * from './typescript.js';
@@ -1,8 +0,0 @@
1
- import { type TsModuleReferenceFactory, tsReference } from '../nodes/reference.js';
2
-
3
- // k6
4
- export const jsonValue: TsModuleReferenceFactory = tsReference.factory('JSONValue', 'k6');
5
-
6
- // h6/http
7
- export const response: TsModuleReferenceFactory = tsReference.factory('Response', 'k6/http');
8
- export const params: TsModuleReferenceFactory = tsReference.factory('Params', 'k6/http');
@@ -1,7 +0,0 @@
1
- import { type TsModuleReferenceFactory, tsReference } from '../nodes/reference.js';
2
-
3
- export const observable: TsModuleReferenceFactory = tsReference.factory('Observable', 'rxjs');
4
- export const firstValueFrom: TsModuleReferenceFactory = tsReference.factory('firstValueFrom', 'rxjs');
5
- export const filter: TsModuleReferenceFactory = tsReference.factory('filter', 'rxjs');
6
- export const map: TsModuleReferenceFactory = tsReference.factory('map', 'rxjs');
7
- export const take: TsModuleReferenceFactory = tsReference.factory('take', 'rxjs');