@goast/kotlin 0.5.9-beta.2 → 0.5.10
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/LICENSE +21 -21
- package/assets/client/okhttp3/ApiAbstractions.kt +30 -30
- package/assets/client/okhttp3/ApiClient.kt +252 -252
- package/assets/client/okhttp3/ApiResponse.kt +43 -43
- package/assets/client/okhttp3/Errors.kt +21 -21
- package/assets/client/okhttp3/PartConfig.kt +11 -11
- package/assets/client/okhttp3/RequestConfig.kt +18 -18
- package/assets/client/okhttp3/RequestMethod.kt +8 -8
- package/assets/client/okhttp3/ResponseExtensions.kt +24 -24
- package/assets/client/spring-reactive-web-clients/ApiRequestFile.kt +33 -33
- package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +28 -28
- package/esm/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +9 -9
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts +11 -11
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.js +15 -13
- package/package.json +1 -1
- package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +28 -28
- package/script/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +9 -9
- package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts +11 -11
- package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
- package/script/src/generators/services/spring-controllers/spring-controller-generator.js +15 -13
- package/src/mod.ts +8 -0
- package/src/src/assets.ts +9 -0
- package/src/src/ast/_index.ts +66 -0
- package/src/src/ast/common.ts +1 -0
- package/src/src/ast/index.ts +1 -0
- package/src/src/ast/node.ts +10 -0
- package/src/src/ast/nodes/annotation.ts +79 -0
- package/src/src/ast/nodes/argument.ts +62 -0
- package/src/src/ast/nodes/call.ts +75 -0
- package/src/src/ast/nodes/class.ts +178 -0
- package/src/src/ast/nodes/collection-literal.ts +49 -0
- package/src/src/ast/nodes/constructor.ts +126 -0
- package/src/src/ast/nodes/doc-tag.ts +138 -0
- package/src/src/ast/nodes/doc.ts +111 -0
- package/src/src/ast/nodes/enum-value.ts +100 -0
- package/src/src/ast/nodes/enum.ts +163 -0
- package/src/src/ast/nodes/function.ts +178 -0
- package/src/src/ast/nodes/generic-parameter.ts +54 -0
- package/src/src/ast/nodes/init-block.ts +38 -0
- package/src/src/ast/nodes/interface.ts +133 -0
- package/src/src/ast/nodes/lambda-type.ts +73 -0
- package/src/src/ast/nodes/lambda.ts +74 -0
- package/src/src/ast/nodes/object.ts +102 -0
- package/src/src/ast/nodes/parameter.ts +118 -0
- package/src/src/ast/nodes/property.ts +225 -0
- package/src/src/ast/nodes/reference.ts +178 -0
- package/src/src/ast/nodes/string.ts +114 -0
- package/src/src/ast/nodes/types.ts +23 -0
- package/src/src/ast/references/index.ts +10 -0
- package/src/src/ast/references/jackson.ts +59 -0
- package/src/src/ast/references/jakarta.ts +14 -0
- package/src/src/ast/references/java.ts +27 -0
- package/src/src/ast/references/kotlin.ts +41 -0
- package/src/src/ast/references/kotlinx.ts +14 -0
- package/src/src/ast/references/okhttp3.ts +5 -0
- package/src/src/ast/references/reactor.ts +5 -0
- package/src/src/ast/references/spring-reactive.ts +33 -0
- package/src/src/ast/references/spring.ts +86 -0
- package/src/src/ast/references/swagger.ts +23 -0
- package/src/src/ast/utils/get-kotlin-builder-options.ts +19 -0
- package/src/src/ast/utils/to-kt-node.ts +31 -0
- package/src/src/ast/utils/write-kt-annotations.ts +15 -0
- package/src/src/ast/utils/write-kt-arguments.ts +45 -0
- package/src/src/ast/utils/write-kt-enum-values.ts +27 -0
- package/src/src/ast/utils/write-kt-generic-parameters.ts +12 -0
- package/src/src/ast/utils/write-kt-members.ts +25 -0
- package/src/src/ast/utils/write-kt-node.ts +37 -0
- package/src/src/ast/utils/write-kt-parameters.ts +25 -0
- package/src/src/common-results.ts +4 -0
- package/src/src/config.ts +61 -0
- package/src/src/file-builder.ts +112 -0
- package/src/src/generators/file-generator.ts +29 -0
- package/src/src/generators/index.ts +5 -0
- package/src/src/generators/models/args.ts +136 -0
- package/src/src/generators/models/index.ts +4 -0
- package/src/src/generators/models/model-generator.ts +725 -0
- package/src/src/generators/models/models-generator.ts +65 -0
- package/src/src/generators/models/models.ts +95 -0
- package/src/src/generators/services/okhttp3-clients/args.ts +90 -0
- package/src/src/generators/services/okhttp3-clients/index.ts +4 -0
- package/src/src/generators/services/okhttp3-clients/models.ts +73 -0
- package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +613 -0
- package/src/src/generators/services/okhttp3-clients/okhttp3-clients-generator.ts +188 -0
- package/src/src/generators/services/okhttp3-clients/refs.ts +59 -0
- package/src/src/generators/services/spring-controllers/args.ts +95 -0
- package/src/src/generators/services/spring-controllers/index.ts +4 -0
- package/src/src/generators/services/spring-controllers/models.ts +76 -0
- package/src/src/generators/services/spring-controllers/refs.ts +17 -0
- package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +1109 -0
- package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +140 -0
- package/src/src/generators/services/spring-reactive-web-clients/args.ts +103 -0
- package/src/src/generators/services/spring-reactive-web-clients/index.ts +4 -0
- package/src/src/generators/services/spring-reactive-web-clients/models.ts +62 -0
- package/src/src/generators/services/spring-reactive-web-clients/refs.ts +11 -0
- package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts +586 -0
- package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.ts +125 -0
- package/src/src/import-collection.ts +98 -0
- package/src/src/types.ts +3 -0
- package/src/src/utils.ts +47 -0
|
@@ -112,31 +112,31 @@ class DefaultKotlinOkHttp3Generator extends file_generator_js_1.KotlinFileGenera
|
|
|
112
112
|
return (0, core_1.appendValueGroup)([
|
|
113
113
|
(0, core_1.builderTemplate) `val localVarResponse = ${index_js_1.kt.call([(0, core_1.toCasing)(endpoint.name + '_WithHttpInfo', ctx.config.functionNameCasing)], parameters.map((x) => (0, core_1.toCasing)(x.name, ctx.config.parameterNameCasing)))}`,
|
|
114
114
|
'',
|
|
115
|
-
(0, core_1.builderTemplate) `return when (localVarResponse.responseType) {${core_1.builderTemplate.indent `
|
|
115
|
+
(0, core_1.builderTemplate) `return when (localVarResponse.responseType) {${core_1.builderTemplate.indent `
|
|
116
116
|
${ctx.refs.responseType()}.Success -> ${responseSchema === undefined
|
|
117
117
|
? index_js_1.kt.refs.unit()
|
|
118
118
|
: (0, core_1.builderTemplate) `(localVarResponse as ${ctx.refs.success(['*'])}).data as ${this.getTypeUsage(ctx, {
|
|
119
119
|
schema: responseSchema,
|
|
120
|
-
})}`}
|
|
121
|
-
${ctx.refs.responseType()}.Informational -> throw ${index_js_1.kt.refs.java.unsupportedOperationException()}("Client does not support Informational responses.")
|
|
122
|
-
${ctx.refs.responseType()}.Redirection -> throw ${index_js_1.kt.refs.java.unsupportedOperationException()}("Client does not support Redirection responses.")
|
|
123
|
-
${ctx.refs.responseType()}.ClientError -> {${core_1.builderTemplate.indent `
|
|
124
|
-
val localVarError = localVarResponse as ${ctx.refs.clientError(['*'])}
|
|
125
|
-
throw ${ctx.refs.clientException()}(${core_1.builderTemplate.indent `
|
|
126
|
-
"Client error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
|
|
127
|
-
localVarError.statusCode,
|
|
128
|
-
localVarResponse`}
|
|
129
|
-
)`}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
${ctx.refs.responseType()}.ServerError -> {${core_1.builderTemplate.indent `
|
|
133
|
-
val localVarError = localVarResponse as ${ctx.refs.serverError(['*'])}
|
|
134
|
-
throw ${ctx.refs.serverException()}(${core_1.builderTemplate.indent `
|
|
135
|
-
"Server error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
|
|
136
|
-
localVarError.statusCode,
|
|
137
|
-
localVarResponse`}
|
|
138
|
-
)`}
|
|
139
|
-
}`}
|
|
120
|
+
})}`}
|
|
121
|
+
${ctx.refs.responseType()}.Informational -> throw ${index_js_1.kt.refs.java.unsupportedOperationException()}("Client does not support Informational responses.")
|
|
122
|
+
${ctx.refs.responseType()}.Redirection -> throw ${index_js_1.kt.refs.java.unsupportedOperationException()}("Client does not support Redirection responses.")
|
|
123
|
+
${ctx.refs.responseType()}.ClientError -> {${core_1.builderTemplate.indent `
|
|
124
|
+
val localVarError = localVarResponse as ${ctx.refs.clientError(['*'])}
|
|
125
|
+
throw ${ctx.refs.clientException()}(${core_1.builderTemplate.indent `
|
|
126
|
+
"Client error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
|
|
127
|
+
localVarError.statusCode,
|
|
128
|
+
localVarResponse`}
|
|
129
|
+
)`}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
${ctx.refs.responseType()}.ServerError -> {${core_1.builderTemplate.indent `
|
|
133
|
+
val localVarError = localVarResponse as ${ctx.refs.serverError(['*'])}
|
|
134
|
+
throw ${ctx.refs.serverException()}(${core_1.builderTemplate.indent `
|
|
135
|
+
"Server error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
|
|
136
|
+
localVarError.statusCode,
|
|
137
|
+
localVarResponse`}
|
|
138
|
+
)`}
|
|
139
|
+
}`}
|
|
140
140
|
}`,
|
|
141
141
|
], '\n');
|
|
142
142
|
}
|
|
@@ -215,16 +215,16 @@ class DefaultKotlinOkHttp3Generator extends file_generator_js_1.KotlinFileGenera
|
|
|
215
215
|
result.values.push(`val localVariableBody = ${bodyParamName}`);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
result.values.push((0, core_1.builderTemplate) `val localVariableQuery: ${ctx.refs.multiValueMap()} = ${index_js_1.kt.call([index_js_1.kt.refs.mutableMapOf([index_js_1.kt.refs.string(), index_js_1.kt.refs.list([index_js_1.kt.refs.string()])])], [])}${queryParameters.length === 0 ? '' : core_1.builderTemplate.indent `
|
|
219
|
-
.apply {${core_1.builderTemplate.indent `
|
|
218
|
+
result.values.push((0, core_1.builderTemplate) `val localVariableQuery: ${ctx.refs.multiValueMap()} = ${index_js_1.kt.call([index_js_1.kt.refs.mutableMapOf([index_js_1.kt.refs.string(), index_js_1.kt.refs.list([index_js_1.kt.refs.string()])])], [])}${queryParameters.length === 0 ? '' : core_1.builderTemplate.indent `
|
|
219
|
+
.apply {${core_1.builderTemplate.indent `
|
|
220
220
|
${(0, core_1.appendValueGroup)(queryParameters.map((param) => {
|
|
221
221
|
const paramName = (0, core_1.toCasing)(param.name, ctx.config.parameterNameCasing);
|
|
222
222
|
const toString = this.getParameterToString(ctx, { endpoint, parameter: param });
|
|
223
223
|
const put = (0, core_1.builderTemplate) `put(${index_js_1.kt.string(param.name)}, listOf(${paramName}${toString}))`;
|
|
224
|
-
return param.required ? put : (0, core_1.builderTemplate) `if (${paramName} != null) {${core_1.builderTemplate.indent `
|
|
225
|
-
${put}`}
|
|
224
|
+
return param.required ? put : (0, core_1.builderTemplate) `if (${paramName} != null) {${core_1.builderTemplate.indent `
|
|
225
|
+
${put}`}
|
|
226
226
|
}`;
|
|
227
|
-
}), '\n')}`}
|
|
227
|
+
}), '\n')}`}
|
|
228
228
|
}`}`);
|
|
229
229
|
result.values.push('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()');
|
|
230
230
|
if (((_b = endpoint.requestBody) === null || _b === void 0 ? void 0 : _b.content[0]) !== undefined) {
|
|
@@ -233,8 +233,8 @@ class DefaultKotlinOkHttp3Generator extends file_generator_js_1.KotlinFileGenera
|
|
|
233
233
|
for (const header of headerParameters) {
|
|
234
234
|
const paramName = (0, core_1.toCasing)(header.name, ctx.config.parameterNameCasing);
|
|
235
235
|
const toString = this.getParameterToString(ctx, { endpoint, parameter: header });
|
|
236
|
-
result.values.push((0, core_1.builderTemplate) `if (${paramName} != null) {${core_1.builderTemplate.indent `
|
|
237
|
-
localVariableHeaders["${header.name}"] = ${paramName}${toString}`}
|
|
236
|
+
result.values.push((0, core_1.builderTemplate) `if (${paramName} != null) {${core_1.builderTemplate.indent `
|
|
237
|
+
localVariableHeaders["${header.name}"] = ${paramName}${toString}`}
|
|
238
238
|
}`);
|
|
239
239
|
}
|
|
240
240
|
result.values.push((0, core_1.builderTemplate) `return ${index_js_1.kt.call([ctx.refs.requestConfig.infer()], [
|
|
@@ -103,16 +103,16 @@ class KotlinOkHttp3ClientsGenerator extends core_1.OpenApiServicesGenerationProv
|
|
|
103
103
|
const jsonIncludeMember = (0, core_1.toCasing)(ctx.config.serializerJsonInclude, 'snake');
|
|
104
104
|
const defaultFactory = springBootVersion === 4
|
|
105
105
|
// Jackson 3's ObjectMapper is immutable; configuration moved to the (Kotlin) mapper builder.
|
|
106
|
-
? (0, core_1.builderTemplate) `${index_js_1.kt.refs.jackson.jacksonMapperBuilder(springBootVersion)}()${core_1.builderTemplate.indent `
|
|
107
|
-
.findAndAddModules()
|
|
108
|
-
.changeDefaultPropertyInclusion { it.withValueInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}).withContentInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}) }
|
|
109
|
-
.configure(${index_js_1.kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
|
|
110
|
-
.configure(${index_js_1.kt.refs.jackson.deserializationFeature(springBootVersion)}.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
|
106
|
+
? (0, core_1.builderTemplate) `${index_js_1.kt.refs.jackson.jacksonMapperBuilder(springBootVersion)}()${core_1.builderTemplate.indent `
|
|
107
|
+
.findAndAddModules()
|
|
108
|
+
.changeDefaultPropertyInclusion { it.withValueInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}).withContentInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}) }
|
|
109
|
+
.configure(${index_js_1.kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
|
|
110
|
+
.configure(${index_js_1.kt.refs.jackson.deserializationFeature(springBootVersion)}.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
|
111
111
|
.build()`}`
|
|
112
|
-
: (0, core_1.builderTemplate) `${index_js_1.kt.refs.jackson.jacksonObjectMapper(springBootVersion)}()${core_1.builderTemplate.indent `
|
|
113
|
-
.findAndRegisterModules()
|
|
114
|
-
.setSerializationInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember})
|
|
115
|
-
.configure(${index_js_1.kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
|
|
112
|
+
: (0, core_1.builderTemplate) `${index_js_1.kt.refs.jackson.jacksonObjectMapper(springBootVersion)}()${core_1.builderTemplate.indent `
|
|
113
|
+
.findAndRegisterModules()
|
|
114
|
+
.setSerializationInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember})
|
|
115
|
+
.configure(${index_js_1.kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
|
|
116
116
|
.configure(${index_js_1.kt.refs.jackson.deserializationFeature(springBootVersion)}.FAIL_ON_UNKNOWN_PROPERTIES, false)`}`;
|
|
117
117
|
const factory = typeof ctx.config.serializer === 'object'
|
|
118
118
|
? ctx.config.serializer.factory
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AppendValueGroup, type BasicAppendValue, type MaybePromise, SourceBuilder } from '@goast/core';
|
|
1
|
+
import { type ApiEndpoint, type AppendValueGroup, type BasicAppendValue, type MaybePromise, SourceBuilder } from '@goast/core';
|
|
2
2
|
import { kt } from '../../../ast/index.js';
|
|
3
3
|
import type { KotlinImport } from '../../../common-results.js';
|
|
4
4
|
import { KotlinFileBuilder } from '../../../file-builder.js';
|
|
@@ -17,23 +17,23 @@ export declare class DefaultKotlinSpringControllerGenerator extends KotlinFileGe
|
|
|
17
17
|
protected generateApiInterfaceFile(ctx: Context, args: Args.GenerateApiInterfaceFile): KotlinImport;
|
|
18
18
|
protected getApiInterfaceFileContent(ctx: Context, args: Args.GetApiInterfaceFileContent): AppendValueGroup<Builder>;
|
|
19
19
|
protected getApiInterface(ctx: Context, args: Args.GetApiInterface): kt.Interface<Builder>;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
protected getApiInterfaceAnnotations(ctx: Context): kt.Annotation<Builder>[];
|
|
21
|
+
protected getApiInterfaceMembers(ctx: Context): kt.InterfaceMember<Builder>[];
|
|
22
22
|
protected getApiInterfaceEndpointMethod(ctx: Context, args: Args.GetApiInterfaceEndpointMethod): kt.Function<Builder>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
protected getApiInterfaceEndpointMethodAnnnotations(ctx: Context, endpoint: ApiEndpoint): kt.Annotation<Builder>[];
|
|
24
|
+
protected getApiInterfaceEndpointMethodParameter(ctx: Context, endpoint: ApiEndpoint, parameter: ApiParameterWithMultipartInfo): kt.Parameter<Builder>;
|
|
25
|
+
protected getApiInterfaceEndpointMethodBody(ctx: Context, endpoint: ApiEndpoint, parameters: ApiParameterWithMultipartInfo[]): AppendValueGroup<Builder>;
|
|
26
|
+
protected getApiResponseEntityClass(ctx: Context, args: Args.GetApiResponseEntityClass): kt.Class<Builder>;
|
|
27
27
|
protected generateApiControllerFile(ctx: Context, args: Args.GenerateApiControllerFile): KotlinImport;
|
|
28
28
|
protected getApiControllerFileContent(ctx: Context, args: Args.GetApiControllerFileContent): AppendValueGroup<Builder>;
|
|
29
29
|
protected getApiController(ctx: Context, args: Args.GetApiController): kt.Class<Builder>;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
protected getApiControllerAnnotations(ctx: Context): kt.Annotation<Builder>[];
|
|
31
|
+
protected getApiControllerMembers(ctx: Context): kt.ClassMember<Builder>[];
|
|
32
32
|
protected generateApiDelegateInterfaceFile(ctx: Context, args: Args.GenerateApiDelegateInterfaceFile): KotlinImport;
|
|
33
33
|
protected getApiDelegateInterfaceFileContent(ctx: Context, args: Args.GetApiDelegateInterfaceFileContent): AppendValueGroup<Builder>;
|
|
34
34
|
protected getApiDelegateInterface(ctx: Context, args: Args.GetApiDelegateInterface): kt.Interface<Builder>;
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
protected getApiDelegateInterfaceAnnotations(ctx: Context): kt.Annotation<Builder>[];
|
|
36
|
+
protected getApiDelegateInterfaceMembers(ctx: Context): kt.InterfaceMember<Builder>[];
|
|
37
37
|
protected getApiDelegateInterfaceEndpointMethod(ctx: Context, args: Args.GetApiDelegateInterfaceEndpointMethod): kt.Function<Builder>;
|
|
38
38
|
protected getParameterType(ctx: Context, args: Args.GetParameterType): kt.Type<Builder>;
|
|
39
39
|
protected getResponseType(ctx: Context, args: Args.GetResponseType): kt.Type<Builder>;
|
package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring-controller-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/spring-controllers/spring-controller-generator.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"spring-controller-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/spring-controllers/spring-controller-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EAIrB,KAAK,YAAY,EAGjB,aAAa,EAEd,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,0CAA0C,IAAI,IAAI,EAA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O,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAQ1D"}
|
|
@@ -8,6 +8,7 @@ const index_js_1 = require("../../../ast/index.js");
|
|
|
8
8
|
const file_builder_js_1 = require("../../../file-builder.js");
|
|
9
9
|
const utils_js_1 = require("../../../utils.js");
|
|
10
10
|
const file_generator_js_1 = require("../../file-generator.js");
|
|
11
|
+
const strictResponseCustomProperty = 'strict-response';
|
|
11
12
|
class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinFileGenerator {
|
|
12
13
|
generate(ctx) {
|
|
13
14
|
const packageName = this.getPackageName(ctx, {});
|
|
@@ -85,9 +86,9 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
85
86
|
ctx.service.endpoints.forEach((endpoint) => {
|
|
86
87
|
members.push(this.getApiInterfaceEndpointMethod(ctx, { endpoint }));
|
|
87
88
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
members.push(...ctx.service.endpoints
|
|
90
|
+
.filter((endpoint) => { var _a; return (_a = endpoint.custom[strictResponseCustomProperty]) !== null && _a !== void 0 ? _a : ctx.config.strictResponseEntities; })
|
|
91
|
+
.map((endpoint) => this.getApiResponseEntityClass(ctx, { endpoint })));
|
|
91
92
|
return members;
|
|
92
93
|
}
|
|
93
94
|
getApiInterfaceEndpointMethod(ctx, args) {
|
|
@@ -260,13 +261,13 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
260
261
|
}
|
|
261
262
|
}
|
|
262
263
|
});
|
|
263
|
-
body.values.push((0, core_1.builderTemplate) `try {${core_1.builderTemplate.indent `
|
|
264
|
+
body.values.push((0, core_1.builderTemplate) `try {${core_1.builderTemplate.indent `
|
|
264
265
|
return ${index_js_1.kt.call([
|
|
265
266
|
index_js_1.kt.call(index_js_1.kt.reference('getDelegate'), []),
|
|
266
267
|
(0, core_1.toCasing)(endpoint.name, ctx.config.functionNameCasing),
|
|
267
|
-
], parameters.map((x) => (0, core_1.toCasing)(x.name, ctx.config.parameterNameCasing)))}`}
|
|
268
|
-
} catch (e: ${index_js_1.kt.refs.throwable()}) {${core_1.builderTemplate.indent `
|
|
269
|
-
return getExceptionHandler()?.handleApiException(e) ?: throw e`}
|
|
268
|
+
], parameters.map((x) => (0, core_1.toCasing)(x.name, ctx.config.parameterNameCasing)))}`}
|
|
269
|
+
} catch (e: ${index_js_1.kt.refs.throwable()}) {${core_1.builderTemplate.indent `
|
|
270
|
+
return getExceptionHandler()?.handleApiException(e) ?: throw e`}
|
|
270
271
|
}`);
|
|
271
272
|
return body;
|
|
272
273
|
}
|
|
@@ -328,11 +329,11 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
328
329
|
hasResponseBody ? index_js_1.kt.argument('body') : index_js_1.kt.toNode(null),
|
|
329
330
|
index_js_1.kt.toNode(code),
|
|
330
331
|
contentType
|
|
331
|
-
? (0, core_1.builderTemplate) `${index_js_1.kt.refs.spring.linkedMultiValueMap([index_js_1.kt.refs.string(), index_js_1.kt.refs.string()])}().also {
|
|
332
|
-
if (headers != null) {
|
|
333
|
-
it.putAll(headers)
|
|
334
|
-
}
|
|
335
|
-
it.addIfAbsent("Content-Type", ${index_js_1.kt.string(contentType)})
|
|
332
|
+
? (0, core_1.builderTemplate) `${index_js_1.kt.refs.spring.linkedMultiValueMap([index_js_1.kt.refs.string(), index_js_1.kt.refs.string()])}().also {
|
|
333
|
+
if (headers != null) {
|
|
334
|
+
it.putAll(headers)
|
|
335
|
+
}
|
|
336
|
+
it.addIfAbsent("Content-Type", ${index_js_1.kt.string(contentType)})
|
|
336
337
|
}`
|
|
337
338
|
: index_js_1.kt.argument('headers'),
|
|
338
339
|
]),
|
|
@@ -471,6 +472,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
471
472
|
return members;
|
|
472
473
|
}
|
|
473
474
|
getApiDelegateInterfaceEndpointMethod(ctx, args) {
|
|
475
|
+
var _a;
|
|
474
476
|
const { endpoint } = args;
|
|
475
477
|
const parameters = this.getAllParameters(ctx, { endpoint });
|
|
476
478
|
const fn = index_js_1.kt.function((0, core_1.toCasing)(endpoint.name, ctx.config.functionNameCasing), {
|
|
@@ -480,7 +482,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
480
482
|
return index_js_1.kt.parameter((0, core_1.toCasing)(parameter.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter }));
|
|
481
483
|
}),
|
|
482
484
|
});
|
|
483
|
-
if (ctx.config.strictResponseEntities) {
|
|
485
|
+
if ((_a = endpoint.custom[strictResponseCustomProperty]) !== null && _a !== void 0 ? _a : ctx.config.strictResponseEntities) {
|
|
484
486
|
const responseEntity = index_js_1.kt.reference.genericFactory(this.getApiResponseEntityName(ctx, { endpoint }), `${this.getPackageName(ctx, {})}.${this.getApiInterfaceName(ctx, {})}`);
|
|
485
487
|
fn.returnType = responseEntity(['*']);
|
|
486
488
|
fn.body = (0, core_1.appendValueGroup)([
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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/types.js';
|
|
8
|
+
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,66 @@
|
|
|
1
|
+
export { type KtAccessModifier as AccessModifier } from './common.js';
|
|
2
|
+
export { KtNode as Node } from './node.js';
|
|
3
|
+
export {
|
|
4
|
+
KtAnnotation as Annotation,
|
|
5
|
+
ktAnnotation as annotation,
|
|
6
|
+
type KtAnnotationTarget as AnnotationTarget,
|
|
7
|
+
} from './nodes/annotation.js';
|
|
8
|
+
export { KtArgument as Argument, ktArgument as argument } from './nodes/argument.js';
|
|
9
|
+
export { KtCall as Call, ktCall as call } from './nodes/call.js';
|
|
10
|
+
export {
|
|
11
|
+
KtClass as Class,
|
|
12
|
+
ktClass as class,
|
|
13
|
+
type KtClassKind as ClassKind,
|
|
14
|
+
type KtClassMember as ClassMember,
|
|
15
|
+
} from './nodes/class.js';
|
|
16
|
+
export {
|
|
17
|
+
KtCollectionLiteral as CollectionLiteral,
|
|
18
|
+
ktCollectionLiteral as collectionLiteral,
|
|
19
|
+
} from './nodes/collection-literal.js';
|
|
20
|
+
export {
|
|
21
|
+
KtConstructor as Constructor,
|
|
22
|
+
ktConstructor as constructor,
|
|
23
|
+
type KtDelegateTarget as DelegateTarget,
|
|
24
|
+
} from './nodes/constructor.js';
|
|
25
|
+
export { KtDocTag as DocTag, ktDocTag as docTag } from './nodes/doc-tag.js';
|
|
26
|
+
export { KtDoc as Doc, ktDoc as doc } from './nodes/doc.js';
|
|
27
|
+
export {
|
|
28
|
+
KtEnumValue as EnumValue,
|
|
29
|
+
ktEnumValue as enumValue,
|
|
30
|
+
type KtEnumValueMember as EnumValueMember,
|
|
31
|
+
} from './nodes/enum-value.js';
|
|
32
|
+
export { KtEnum as Enum, ktEnum as enum, type KtEnumMember as EnumMember } from './nodes/enum.js';
|
|
33
|
+
export { KtFunction as Function, ktFunction as function } from './nodes/function.js';
|
|
34
|
+
export {
|
|
35
|
+
KtGenericParameter as GenericParameter,
|
|
36
|
+
ktGenericParameter as genericParameter,
|
|
37
|
+
} from './nodes/generic-parameter.js';
|
|
38
|
+
export { KtInitBlock as InitBlock, ktInitBlock as initBlock } from './nodes/init-block.js';
|
|
39
|
+
export {
|
|
40
|
+
KtInterface as Interface,
|
|
41
|
+
ktInterface as interface,
|
|
42
|
+
type KtInterfaceMember as InterfaceMember,
|
|
43
|
+
} from './nodes/interface.js';
|
|
44
|
+
export { KtLambdaType as LambdaType, ktLambdaType as lambdaType } from './nodes/lambda-type.js';
|
|
45
|
+
export { KtLambda as Lambda, ktLambda as lambda } from './nodes/lambda.js';
|
|
46
|
+
export { KtObject as Object, ktObject as object, type KtObjectMember as ObjectMember } from './nodes/object.js';
|
|
47
|
+
export { KtParameter as Parameter, ktParameter as parameter } from './nodes/parameter.js';
|
|
48
|
+
export {
|
|
49
|
+
KtProperty as Property,
|
|
50
|
+
ktProperty as property,
|
|
51
|
+
KtPropertyAccessor as PropertyAccessor,
|
|
52
|
+
KtPropertyGetter as PropertyGetter,
|
|
53
|
+
KtPropertySetter as PropertySetter,
|
|
54
|
+
} from './nodes/property.js';
|
|
55
|
+
export {
|
|
56
|
+
type KtGenericReferenceFactory as GenericReferenceFactory,
|
|
57
|
+
KtReference as Reference,
|
|
58
|
+
ktReference as reference,
|
|
59
|
+
type KtReferenceFactory as ReferenceFactory,
|
|
60
|
+
} from './nodes/reference.js';
|
|
61
|
+
export { KtString as String, ktString as string } from './nodes/string.js';
|
|
62
|
+
export { type KtType as Type, type KtValue as Value } from './nodes/types.js';
|
|
63
|
+
export * as refs from './references/index.js';
|
|
64
|
+
export { getKotlinBuilderOptions as getBuilderOptions } from './utils/get-kotlin-builder-options.js';
|
|
65
|
+
export { toKtNode as toNode } from './utils/to-kt-node.js';
|
|
66
|
+
export { writeKtNode as writeNode, writeKtNodes as writeNodes } from './utils/write-kt-node.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type KtAccessModifier = 'public' | 'protected' | 'internal' | 'private';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as kt from './_index.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AstNode, type AstNodeOptions, type SourceBuilder } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
export abstract class KtNode<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,79 @@
|
|
|
1
|
+
import { type AstNodeOptions, notNullish, type Nullable, type Prettify, type SourceBuilder } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { KtNode } from '../node.js';
|
|
4
|
+
import { writeKtAnnotations } from '../utils/write-kt-annotations.js';
|
|
5
|
+
import { writeKtNode } from '../utils/write-kt-node.js';
|
|
6
|
+
import { type KtArgument, ktArgument } from './argument.js';
|
|
7
|
+
import type { KtType, KtValue } from './types.js';
|
|
8
|
+
|
|
9
|
+
type Injects = 'class' | 'target' | 'arguments';
|
|
10
|
+
|
|
11
|
+
type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
|
|
12
|
+
typeof KtNode<TBuilder, TInjects | Injects>,
|
|
13
|
+
{
|
|
14
|
+
class: KtType<TBuilder>;
|
|
15
|
+
arguments?: Nullable<Nullable<KtArgument<TBuilder> | KtValue<TBuilder>>[]>;
|
|
16
|
+
target?: Nullable<KtAnnotationTarget>;
|
|
17
|
+
}
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export type KtAnnotationTarget =
|
|
21
|
+
| 'file'
|
|
22
|
+
| 'property'
|
|
23
|
+
| 'field'
|
|
24
|
+
| 'get'
|
|
25
|
+
| 'set'
|
|
26
|
+
| 'receiver'
|
|
27
|
+
| 'param'
|
|
28
|
+
| 'setparam'
|
|
29
|
+
| 'delegate';
|
|
30
|
+
|
|
31
|
+
export class KtAnnotation<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<
|
|
32
|
+
TBuilder,
|
|
33
|
+
TInjects | Injects
|
|
34
|
+
> {
|
|
35
|
+
public class: KtType<TBuilder>;
|
|
36
|
+
public arguments: (KtArgument<TBuilder> | KtValue<TBuilder>)[];
|
|
37
|
+
public target: KtAnnotationTarget | null;
|
|
38
|
+
|
|
39
|
+
constructor(options: Options<TBuilder, TInjects>) {
|
|
40
|
+
super(options);
|
|
41
|
+
this.class = options.class;
|
|
42
|
+
this.arguments = options.arguments?.filter(notNullish) ?? [];
|
|
43
|
+
this.target = options.target ?? null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected override onWrite(builder: TBuilder): void {
|
|
47
|
+
builder.append('@');
|
|
48
|
+
|
|
49
|
+
if (this.target) {
|
|
50
|
+
builder.append(this.inject.beforeTarget);
|
|
51
|
+
builder.append(this.target);
|
|
52
|
+
builder.append(this.inject.afterTarget);
|
|
53
|
+
builder.append(':');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
builder.append(this.inject.beforeClass);
|
|
57
|
+
writeKtNode(builder, this.class);
|
|
58
|
+
builder.append(this.inject.afterClass);
|
|
59
|
+
|
|
60
|
+
if (this.arguments.length > 0) {
|
|
61
|
+
builder.append(this.inject.beforeArguments);
|
|
62
|
+
ktArgument.write(builder, this.arguments);
|
|
63
|
+
builder.append(this.inject.afterArguments);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const createAnnotation = <TBuilder extends SourceBuilder>(
|
|
69
|
+
$class: Options<TBuilder>['class'],
|
|
70
|
+
$arguments?: Options<TBuilder>['arguments'],
|
|
71
|
+
options?: Prettify<Omit<Options<TBuilder>, 'class' | 'arguments'>>,
|
|
72
|
+
): KtAnnotation<TBuilder> => new KtAnnotation<TBuilder>({ ...options, class: $class, arguments: $arguments });
|
|
73
|
+
|
|
74
|
+
export const ktAnnotation: typeof createAnnotation & { write: typeof writeKtAnnotations } = Object.assign(
|
|
75
|
+
createAnnotation,
|
|
76
|
+
{
|
|
77
|
+
write: writeKtAnnotations,
|
|
78
|
+
},
|
|
79
|
+
);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AstNodeOptions, Nullable, Prettify, SourceBuilder } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { KtNode } from '../node.js';
|
|
4
|
+
import { writeKtArguments } from '../utils/write-kt-arguments.js';
|
|
5
|
+
import { writeKtNode } from '../utils/write-kt-node.js';
|
|
6
|
+
import type { KtValue } from './types.js';
|
|
7
|
+
|
|
8
|
+
type Injects = 'name' | 'value';
|
|
9
|
+
|
|
10
|
+
type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
|
|
11
|
+
typeof KtNode<TBuilder, TInjects | Injects>,
|
|
12
|
+
{
|
|
13
|
+
name?: Nullable<string>;
|
|
14
|
+
value: KtValue<TBuilder>;
|
|
15
|
+
}
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
export class KtArgument<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<
|
|
19
|
+
TBuilder,
|
|
20
|
+
TInjects | Injects
|
|
21
|
+
> {
|
|
22
|
+
public name: string | null;
|
|
23
|
+
public value: KtValue<TBuilder>;
|
|
24
|
+
|
|
25
|
+
constructor(options: Options<TBuilder, TInjects>) {
|
|
26
|
+
super(options);
|
|
27
|
+
this.name = options?.name ?? null;
|
|
28
|
+
this.value = options.value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected override onWrite(builder: TBuilder): void {
|
|
32
|
+
if (this.name) {
|
|
33
|
+
builder.append(this.inject.beforeName);
|
|
34
|
+
builder.append(this.name);
|
|
35
|
+
builder.append(this.inject.afterName);
|
|
36
|
+
builder.append(' = ');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
builder.append(this.inject.beforeValue);
|
|
40
|
+
writeKtNode(builder, this.value);
|
|
41
|
+
builder.append(this.inject.afterValue);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const createArgument = <TBuilder extends SourceBuilder>(
|
|
46
|
+
value: Options<TBuilder>['value'],
|
|
47
|
+
options?: Prettify<Omit<Options<TBuilder>, 'value'>>,
|
|
48
|
+
): KtArgument<TBuilder> => new KtArgument<TBuilder>({ ...options, value });
|
|
49
|
+
|
|
50
|
+
const createNamedArgument = <TBuilder extends SourceBuilder>(
|
|
51
|
+
name: Options<TBuilder>['name'],
|
|
52
|
+
value: Options<TBuilder>['value'],
|
|
53
|
+
options?: Prettify<Omit<Options<TBuilder>, 'value' | 'name'>>,
|
|
54
|
+
): KtArgument<TBuilder> => new KtArgument<TBuilder>({ ...options, value, name });
|
|
55
|
+
|
|
56
|
+
export const ktArgument: typeof createArgument & {
|
|
57
|
+
named: typeof createNamedArgument;
|
|
58
|
+
write: typeof writeKtArguments;
|
|
59
|
+
} = Object.assign(createArgument, {
|
|
60
|
+
named: createNamedArgument,
|
|
61
|
+
write: writeKtArguments,
|
|
62
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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 { KtNode } from '../node.js';
|
|
11
|
+
import { writeKtNode, writeKtNodes } from '../utils/write-kt-node.js';
|
|
12
|
+
import { type KtArgument, ktArgument } from './argument.js';
|
|
13
|
+
import type { KtType, KtValue } from './types.js';
|
|
14
|
+
|
|
15
|
+
type Injects = never;
|
|
16
|
+
|
|
17
|
+
type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
|
|
18
|
+
typeof KtNode<TBuilder, TInjects | Injects>,
|
|
19
|
+
{
|
|
20
|
+
path: Nullable<KtType<TBuilder> | KtValue<TBuilder>>[];
|
|
21
|
+
arguments?: Nullable<Nullable<KtArgument<TBuilder> | KtValue<TBuilder>>[]>;
|
|
22
|
+
infix?: boolean;
|
|
23
|
+
}
|
|
24
|
+
>;
|
|
25
|
+
|
|
26
|
+
export class KtCall<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<
|
|
27
|
+
TBuilder,
|
|
28
|
+
TInjects | Injects
|
|
29
|
+
> {
|
|
30
|
+
public path: (KtType<TBuilder> | KtValue<TBuilder>)[];
|
|
31
|
+
public arguments: (KtArgument<TBuilder> | KtValue<TBuilder>)[] | null;
|
|
32
|
+
public infix: boolean;
|
|
33
|
+
|
|
34
|
+
constructor(options: Options<TBuilder, TInjects>) {
|
|
35
|
+
super(options);
|
|
36
|
+
this.path = options.path.filter(notNullish);
|
|
37
|
+
this.arguments = options.arguments?.filter(notNullish) ?? null;
|
|
38
|
+
this.infix = options.infix ?? false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected override onWrite(builder: TBuilder): void {
|
|
42
|
+
if (this.infix && this.arguments?.length === 1 && this.path.length > 1) {
|
|
43
|
+
writeKtNodes(builder, this.path.slice(0, 1), { separator: '.' });
|
|
44
|
+
builder.append(' ');
|
|
45
|
+
writeKtNode(builder, this.path.at(-1));
|
|
46
|
+
builder.append(' ');
|
|
47
|
+
writeKtNode(builder, this.arguments[0]);
|
|
48
|
+
} else {
|
|
49
|
+
if (this.path.length > 2) {
|
|
50
|
+
writeKtNode(builder, this.path[0]);
|
|
51
|
+
builder.ensureCurrentLineEmpty();
|
|
52
|
+
builder.indent((builder) => {
|
|
53
|
+
builder.append('.');
|
|
54
|
+
writeKtNodes(builder, this.path.slice(1), { separator: '\n.' });
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
writeKtNodes(builder, this.path, { separator: '.' });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (this.arguments) {
|
|
61
|
+
ktArgument.write(builder, this.arguments);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const createCall = <TBuilder extends SourceBuilder>(
|
|
68
|
+
path: Options<TBuilder>['path'] | ArrayItem<Options<TBuilder>['path']>,
|
|
69
|
+
args?: Options<TBuilder>['arguments'],
|
|
70
|
+
options?: Prettify<Omit<Options<TBuilder>, 'path' | 'arguments'>>,
|
|
71
|
+
): KtCall<TBuilder> => new KtCall<TBuilder>({ ...options, path: Array.isArray(path) ? path : [path], arguments: args });
|
|
72
|
+
|
|
73
|
+
export const ktCall: typeof createCall & { write: typeof writeKtNodes } = Object.assign(createCall, {
|
|
74
|
+
write: writeKtNodes,
|
|
75
|
+
});
|