@goast/core 0.0.5 → 0.1.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.
- package/cjs/lib/codegen/schemas-generator.js +1 -0
- package/cjs/lib/collect/collector.js +4 -0
- package/cjs/lib/parse/parser.js +7 -1
- package/cjs/lib/transform/transform-schema.js +30 -11
- package/cjs/lib/utils/source-builder.js +101 -153
- package/cjs/lib/utils/string.utils.js +7 -2
- package/esm/lib/codegen/schemas-generator.js +1 -0
- package/esm/lib/collect/collector.js +4 -0
- package/esm/lib/parse/parser.js +7 -1
- package/esm/lib/transform/transform-schema.js +30 -11
- package/esm/lib/utils/source-builder.js +101 -153
- package/esm/lib/utils/string.utils.js +7 -2
- package/package.json +1 -1
- package/types/lib/collect/helpers.d.ts +3 -2
- package/types/lib/parse/types.d.ts +5 -2
- package/types/lib/transform/api-types.d.ts +6 -0
- package/types/lib/transform/transform-schema.d.ts +1 -1
- package/types/lib/utils/source-builder.d.ts +65 -78
- package/types/lib/utils/string.utils.d.ts +6 -4
- package/types/lib/utils/type.utils.d.ts +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Condition } from './condition';
|
|
2
|
-
import { StringBuilder, StringBuilderOptions } from './string.utils';
|
|
2
|
+
import { BuilderFn, StringBuilder, StringBuilderOptions, TextOrBuilderFn } from './string.utils';
|
|
3
3
|
import { Nullable } from './type.utils';
|
|
4
4
|
export type IndentOptions = {
|
|
5
5
|
readonly type: 'tabs';
|
|
@@ -16,6 +16,36 @@ type KnownParatheses = '()' | '[]' | '{}' | '<>';
|
|
|
16
16
|
export type Paratheses = KnownParatheses | Omit<string, KnownParatheses> | [open: Nullable<string>, close: Nullable<string>];
|
|
17
17
|
export type SeparatorBuidlerFn<TBuilder extends SourceBuilder, TItem> = (builder: TBuilder, previousItem: TItem, nextItem: TItem, previousItemIndex: number, nextItemIndex: number) => void;
|
|
18
18
|
export type Separator<TBuilder extends SourceBuilder, TItem> = string | SeparatorBuidlerFn<TBuilder, TItem>;
|
|
19
|
+
/**
|
|
20
|
+
* Options for the `parenthesize` methods of the `SourceBuilder`.
|
|
21
|
+
* @see SourceBuilder.parenthesize
|
|
22
|
+
* @see SourceBuilder.parenthesizeIf
|
|
23
|
+
*/
|
|
24
|
+
export type ParenthesizeOptions = {
|
|
25
|
+
/**
|
|
26
|
+
* Whether to add line breaks after start and before end of the parentheses. Defaults to `false`.
|
|
27
|
+
*/
|
|
28
|
+
readonly multiline?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to indent the content inside parentheses. Defaults to `true`.
|
|
31
|
+
*/
|
|
32
|
+
readonly indent?: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Options for the `forEach` methods of the `SourceBuilder`.
|
|
36
|
+
* @see SourceBuilder.forEach
|
|
37
|
+
* @see SourceBuilder.forEachIf
|
|
38
|
+
*/
|
|
39
|
+
export type ForEachOptions<TBuilder extends SourceBuilder, TItem> = {
|
|
40
|
+
/**
|
|
41
|
+
* The condition to check before adding content for each item. Defaults to `true`.
|
|
42
|
+
*/
|
|
43
|
+
readonly condition?: Condition<TItem>;
|
|
44
|
+
/**
|
|
45
|
+
* The seperator to add between items. Default to `undefined`.
|
|
46
|
+
*/
|
|
47
|
+
readonly separator?: Separator<TBuilder, TItem>;
|
|
48
|
+
};
|
|
19
49
|
/**
|
|
20
50
|
* Represents an in-memory source file.
|
|
21
51
|
*/
|
|
@@ -53,74 +83,61 @@ export declare class SourceBuilder extends StringBuilder {
|
|
|
53
83
|
* @param options The options to use for the `SourceBuilder` instance.
|
|
54
84
|
* @returns The string built by the `SourceBuilder` instance.
|
|
55
85
|
*/
|
|
56
|
-
static build(buildAction:
|
|
86
|
+
static build(buildAction: BuilderFn<SourceBuilder>, options?: Partial<SourceBuilderOptions>): string;
|
|
57
87
|
/**
|
|
58
88
|
* Appends one or more strings to the end of the current SourceBuilder.
|
|
59
89
|
* @param value The string(s) to append.
|
|
60
90
|
* @returns The current SourceBuilder.
|
|
61
91
|
*/
|
|
62
|
-
append(...value: Nullable<
|
|
92
|
+
append(...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
63
93
|
/**
|
|
64
|
-
* Appends one or more strings to the end of the current SourceBuilder
|
|
94
|
+
* Appends one or more strings to the end of the current SourceBuilder if the specified condition is true.
|
|
95
|
+
* @param condition The condition to check before appending the specified value.
|
|
65
96
|
* @param value The string(s) to append.
|
|
66
97
|
* @returns The current SourceBuilder.
|
|
67
98
|
*/
|
|
68
|
-
|
|
99
|
+
appendIf(condition: Condition, ...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
69
100
|
/**
|
|
70
|
-
* Appends one or more strings to the end of the current SourceBuilder
|
|
71
|
-
* @param condition The condition to check before appending the specified value.
|
|
101
|
+
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator.
|
|
72
102
|
* @param value The string(s) to append.
|
|
73
103
|
* @returns The current SourceBuilder.
|
|
74
104
|
*/
|
|
75
|
-
|
|
105
|
+
appendLine(...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
76
106
|
/**
|
|
77
107
|
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
78
108
|
* @param condition The condition to check before appending the specified value.
|
|
79
109
|
* @param value The string(s) to append.
|
|
80
110
|
* @returns The current SourceBuilder.
|
|
81
111
|
*/
|
|
82
|
-
appendLineIf(condition: Condition, ...value: Nullable<
|
|
112
|
+
appendLineIf(condition: Condition, ...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
83
113
|
/**
|
|
84
114
|
* Appends the specified values to this source builder with the specified line prefix.
|
|
85
115
|
* @param {string} prefix - The line prefix to use.
|
|
86
116
|
* @param {...(string|null|undefined)} value - The values to append.
|
|
87
117
|
* @returns {SourceBuilder} This source builder instance.
|
|
88
118
|
*/
|
|
89
|
-
appendWithLinePrefix(prefix: string, ...value: Nullable<
|
|
119
|
+
appendWithLinePrefix(prefix: string, ...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
90
120
|
/**
|
|
91
121
|
* Appends the specified values to this source builder as a new line with the specified line prefix.
|
|
92
122
|
* @param {string} prefix - The line prefix to use.
|
|
93
123
|
* @param {...(string|null|undefined)} value - The values to append.
|
|
94
124
|
* @returns {SourceBuilder} This source builder instance.
|
|
95
125
|
*/
|
|
96
|
-
appendLineWithLinePrefix(prefix: string, ...value: Nullable<
|
|
126
|
+
appendLineWithLinePrefix(prefix: string, ...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
97
127
|
/**
|
|
98
128
|
* Prepends one or more strings to the beginning of the current SourceBuilder if the specified condition is true.
|
|
99
129
|
* @param condition The condition to check before prepending the specified value.
|
|
100
130
|
* @param value The string(s) to prepend.
|
|
101
131
|
* @returns The current SourceBuilder.
|
|
102
132
|
*/
|
|
103
|
-
prependIf(condition: Condition, ...value: Nullable<
|
|
133
|
+
prependIf(condition: Condition, ...value: Nullable<TextOrBuilderFn<StringBuilder>>[]): this;
|
|
104
134
|
/**
|
|
105
135
|
* Prepends one or more strings to the beginning of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
106
136
|
* @param condition The condition to check before appending the specified value.
|
|
107
137
|
* @param value The string(s) to prepend.
|
|
108
138
|
* @returns The current SourceBuilder.
|
|
109
139
|
*/
|
|
110
|
-
prependLineIf(condition: Condition, ...value: Nullable<
|
|
111
|
-
/**
|
|
112
|
-
* Applies the provided builder function to this source builder.
|
|
113
|
-
* @param builderFn The builder function to apply.
|
|
114
|
-
* @returns This source builder instance.
|
|
115
|
-
*/
|
|
116
|
-
apply(builderFn: (builder: this) => void): this;
|
|
117
|
-
/**
|
|
118
|
-
* Applies the provided builder function to this source builder with the specified line prefix.
|
|
119
|
-
* @param prefix The line prefix to use.
|
|
120
|
-
* @param builderFn The builder function to apply.
|
|
121
|
-
* @returns This source builder instance.
|
|
122
|
-
*/
|
|
123
|
-
applyWithLinePrefix(prefix: string, builderFn: (builder: this) => void): this;
|
|
140
|
+
prependLineIf(condition: Condition, ...value: Nullable<TextOrBuilderFn<StringBuilder>>[]): this;
|
|
124
141
|
/**
|
|
125
142
|
* Ensures that the current line is empty or consists only of whitespace characters.
|
|
126
143
|
* @returns A reference to this instance.
|
|
@@ -134,83 +151,53 @@ export declare class SourceBuilder extends StringBuilder {
|
|
|
134
151
|
/**
|
|
135
152
|
* Inserts specified content if the specified condition is true.
|
|
136
153
|
* @param condition The condition to check before inserting content.
|
|
137
|
-
* @param builderFn The function to add content.
|
|
138
|
-
* @returns A reference to this instance.
|
|
139
|
-
*/
|
|
140
|
-
applyIf(condition: Condition, builderFn: (builder: this) => void): this;
|
|
141
|
-
/**
|
|
142
|
-
* Inserts specified content depending on the specified condition.
|
|
143
|
-
* @param condition The condition to check before inserting content.
|
|
144
154
|
* @param builderFn The function to add content if the condition is true.
|
|
145
155
|
* @param elseBuilderFn The function to add content if the condition is false.
|
|
146
156
|
* @returns A reference to this instance.
|
|
147
157
|
*/
|
|
148
|
-
|
|
158
|
+
if(condition: Condition, builderFn: BuilderFn<this>, elseBuilderFn?: BuilderFn<this>): this;
|
|
149
159
|
/**
|
|
150
160
|
* Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
|
|
151
|
-
* @param builderFn The function to add indented content.
|
|
161
|
+
* @param builderFn The function to add indented content or the content itself.
|
|
152
162
|
* @param condition The condition to check before adding indentation.
|
|
153
163
|
* @returns A reference to this instance.
|
|
154
164
|
*/
|
|
155
|
-
indent(
|
|
165
|
+
indent(value: Nullable<TextOrBuilderFn<this>>): this;
|
|
156
166
|
/**
|
|
157
|
-
* Adds
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
160
|
-
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
167
|
+
* Adds one indentation level if the specified condition is true. If the current line already contains characters, only subsequent lines are affected.
|
|
168
|
+
* @param builderFn The function to add indented content or the content itself.
|
|
169
|
+
* @param condition The condition to check before adding indentation.
|
|
161
170
|
* @returns A reference to this instance.
|
|
162
171
|
*/
|
|
163
|
-
|
|
172
|
+
indentIf(condition: Condition, value: Nullable<TextOrBuilderFn<this>>): this;
|
|
164
173
|
/**
|
|
165
|
-
* Adds parentheses around the specified content
|
|
166
|
-
* @param condition The condition to check before adding parentheses.
|
|
174
|
+
* Adds parentheses around the specified content.
|
|
167
175
|
* @param brackets The brackets to use.
|
|
168
|
-
* @param
|
|
169
|
-
* @param
|
|
170
|
-
* @returns A reference to this instance.
|
|
171
|
-
*/
|
|
172
|
-
parenthesizeIf(condition: Condition, brackets: Paratheses, builderFn: (builder: this) => void, indent?: boolean): this;
|
|
173
|
-
/**
|
|
174
|
-
* Adds content for each item in the specified array.
|
|
175
|
-
* @param items The items to add content for.
|
|
176
|
-
* @param builderFn The function to add content for each item.
|
|
177
|
-
* @returns A reference to this instance.
|
|
178
|
-
*/
|
|
179
|
-
forEach<T>(items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void): this;
|
|
180
|
-
/**
|
|
181
|
-
* Adds content for each item in the specified array.
|
|
182
|
-
* @param items The items to add content for.
|
|
183
|
-
* @param condition The condition to check before adding content.
|
|
184
|
-
* @param builderFn The function to add content for each item.
|
|
185
|
-
* @returns A reference to this instance.
|
|
186
|
-
*/
|
|
187
|
-
forEachIf<T>(items: Iterable<T>, condition: Condition, builderFn: (builder: this, item: T, index: number) => void): this;
|
|
188
|
-
/**
|
|
189
|
-
* Adds content for each item in the specified array.
|
|
190
|
-
* @param items The items to add content for.
|
|
191
|
-
* @param condition The condition to check before adding content for each item.
|
|
192
|
-
* @param builderFn The function to add content for each item.
|
|
176
|
+
* @param value The function to add content inside parentheses or one string that should be parenthesized.
|
|
177
|
+
* @param options Options for the parentheses.
|
|
193
178
|
* @returns A reference to this instance.
|
|
194
179
|
*/
|
|
195
|
-
|
|
180
|
+
parenthesize(brackets: Paratheses, value: Nullable<TextOrBuilderFn<this>>, options?: ParenthesizeOptions): this;
|
|
196
181
|
/**
|
|
197
|
-
* Adds
|
|
198
|
-
* @param
|
|
199
|
-
* @param
|
|
200
|
-
* @param
|
|
182
|
+
* Adds parentheses around the specified content if the specified condition is true.
|
|
183
|
+
* @param condition The condition to check before adding parentheses.
|
|
184
|
+
* @param brackets The brackets to use.
|
|
185
|
+
* @param value The function to add content inside parentheses or one string that should be parenthesized.
|
|
186
|
+
* @param options Options for the parentheses.
|
|
201
187
|
* @returns A reference to this instance.
|
|
202
188
|
*/
|
|
203
|
-
|
|
189
|
+
parenthesizeIf(condition: Condition, brackets: Paratheses, value: TextOrBuilderFn<this>, options?: ParenthesizeOptions): this;
|
|
204
190
|
/**
|
|
205
191
|
* Adds content for each item in the specified array.
|
|
206
192
|
* @param items The items to add content for.
|
|
207
|
-
* @param condition The condition to check before adding content for each item.
|
|
208
|
-
* @param seperator The seperator to add between items.
|
|
209
193
|
* @param builderFn The function to add content for each item.
|
|
194
|
+
* @param options The options for the loop.
|
|
210
195
|
* @returns A reference to this instance.
|
|
211
196
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
197
|
+
forEach<T>(items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void, options?: ForEachOptions<this, T>): this;
|
|
198
|
+
forEachIf<T>(condition: Condition, items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void, options?: ForEachOptions<this, T>): this;
|
|
199
|
+
appendSeparated(items: Iterable<Nullable<TextOrBuilderFn<this>>>, separator: string): this;
|
|
200
|
+
appendSeparatedIf(condition: Condition, items: Iterable<Nullable<TextOrBuilderFn<this>>>, separator: string): this;
|
|
214
201
|
private appendIndent;
|
|
215
202
|
}
|
|
216
203
|
export {};
|
|
@@ -111,6 +111,8 @@ export type StringBuilderOptions = {
|
|
|
111
111
|
readonly newLine: string;
|
|
112
112
|
};
|
|
113
113
|
export declare const defaultStringBuilderOptions: StringBuilderOptions;
|
|
114
|
+
export type BuilderFn<TBuilder extends StringBuilder> = (builder: TBuilder) => void;
|
|
115
|
+
export type TextOrBuilderFn<TBuilder extends StringBuilder> = string | BuilderFn<TBuilder>;
|
|
114
116
|
/**
|
|
115
117
|
* Represents a mutable string of characters.
|
|
116
118
|
*/
|
|
@@ -142,25 +144,25 @@ export declare class StringBuilder {
|
|
|
142
144
|
* @param value The string(s) to append.
|
|
143
145
|
* @returns The current StringBuilder.
|
|
144
146
|
*/
|
|
145
|
-
append(...value: Nullable<
|
|
147
|
+
append(...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
146
148
|
/**
|
|
147
149
|
* Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
|
|
148
150
|
* @param value
|
|
149
151
|
* @returns
|
|
150
152
|
*/
|
|
151
|
-
appendLine(...value: Nullable<
|
|
153
|
+
appendLine(...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
152
154
|
/**
|
|
153
155
|
* Prepends one or more strings to the beginning of the current StringBuilder.
|
|
154
156
|
* @param value The string(s) to prepend.
|
|
155
157
|
* @returns The current StringBuilder.
|
|
156
158
|
*/
|
|
157
|
-
prepend(...value: Nullable<
|
|
159
|
+
prepend(...value: Nullable<TextOrBuilderFn<StringBuilder>>[]): this;
|
|
158
160
|
/**
|
|
159
161
|
* Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
|
|
160
162
|
* @param value The string(s) to prepend.
|
|
161
163
|
* @returns The current StringBuilder.
|
|
162
164
|
*/
|
|
163
|
-
prependLine(...value: Nullable<
|
|
165
|
+
prependLine(...value: Nullable<TextOrBuilderFn<StringBuilder>>[]): this;
|
|
164
166
|
/**
|
|
165
167
|
* Converts the value of this instance to a string.
|
|
166
168
|
* @returns A string whose value is the same as this instance.
|
|
@@ -3,6 +3,7 @@ type MergeTwo<T, U> = {
|
|
|
3
3
|
} & U;
|
|
4
4
|
export type Merge<U extends unknown[]> = U extends [infer A, ...infer R] ? MergeTwo<A, Merge<R>> : {};
|
|
5
5
|
export type OptionalProperties<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
6
|
+
export type RequiredProperties<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
6
7
|
export type ArrayItem<T> = T extends (infer U)[] ? U : never;
|
|
7
8
|
export type Nullable<T> = T | null | undefined;
|
|
8
9
|
export interface Constructor<T, TArgs extends any[]> extends Function {
|