@goast/kotlin 0.5.9-beta.2 → 0.5.9

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 (120) hide show
  1. package/LICENSE +21 -21
  2. package/assets/client/okhttp3/ApiAbstractions.kt +30 -30
  3. package/assets/client/okhttp3/ApiClient.kt +253 -252
  4. package/assets/client/okhttp3/ApiResponse.kt +43 -43
  5. package/assets/client/okhttp3/Errors.kt +21 -21
  6. package/assets/client/okhttp3/PartConfig.kt +11 -11
  7. package/assets/client/okhttp3/RequestConfig.kt +18 -18
  8. package/assets/client/okhttp3/RequestMethod.kt +8 -8
  9. package/assets/client/okhttp3/ResponseExtensions.kt +24 -24
  10. package/assets/client/spring-reactive-web-clients/ApiRequestFile.kt +33 -33
  11. package/esm/src/ast/references/jackson.d.ts +5 -8
  12. package/esm/src/ast/references/jackson.d.ts.map +1 -1
  13. package/esm/src/ast/references/jackson.js +6 -14
  14. package/esm/src/config.d.ts +0 -10
  15. package/esm/src/config.d.ts.map +1 -1
  16. package/esm/src/config.js +0 -1
  17. package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts.map +1 -1
  18. package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +32 -36
  19. package/esm/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts.map +1 -1
  20. package/esm/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +6 -22
  21. package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts +11 -11
  22. package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
  23. package/esm/src/generators/services/spring-controllers/spring-controller-generator.js +19 -27
  24. package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
  25. package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +1 -4
  26. package/package.json +1 -1
  27. package/script/src/ast/references/jackson.d.ts +5 -8
  28. package/script/src/ast/references/jackson.d.ts.map +1 -1
  29. package/script/src/ast/references/jackson.js +7 -20
  30. package/script/src/config.d.ts +0 -10
  31. package/script/src/config.d.ts.map +1 -1
  32. package/script/src/config.js +0 -1
  33. package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts.map +1 -1
  34. package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +32 -36
  35. package/script/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts.map +1 -1
  36. package/script/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +6 -22
  37. package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts +11 -11
  38. package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
  39. package/script/src/generators/services/spring-controllers/spring-controller-generator.js +19 -27
  40. package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
  41. package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +1 -4
  42. package/src/mod.ts +8 -0
  43. package/src/src/assets.ts +9 -0
  44. package/src/src/ast/_index.ts +66 -0
  45. package/src/src/ast/common.ts +1 -0
  46. package/src/src/ast/index.ts +1 -0
  47. package/src/src/ast/node.ts +10 -0
  48. package/src/src/ast/nodes/annotation.ts +79 -0
  49. package/src/src/ast/nodes/argument.ts +62 -0
  50. package/src/src/ast/nodes/call.ts +75 -0
  51. package/src/src/ast/nodes/class.ts +178 -0
  52. package/src/src/ast/nodes/collection-literal.ts +49 -0
  53. package/src/src/ast/nodes/constructor.ts +126 -0
  54. package/src/src/ast/nodes/doc-tag.ts +138 -0
  55. package/src/src/ast/nodes/doc.ts +111 -0
  56. package/src/src/ast/nodes/enum-value.ts +100 -0
  57. package/src/src/ast/nodes/enum.ts +163 -0
  58. package/src/src/ast/nodes/function.ts +178 -0
  59. package/src/src/ast/nodes/generic-parameter.ts +54 -0
  60. package/src/src/ast/nodes/init-block.ts +38 -0
  61. package/src/src/ast/nodes/interface.ts +133 -0
  62. package/src/src/ast/nodes/lambda-type.ts +73 -0
  63. package/src/src/ast/nodes/lambda.ts +74 -0
  64. package/src/src/ast/nodes/object.ts +102 -0
  65. package/src/src/ast/nodes/parameter.ts +118 -0
  66. package/src/src/ast/nodes/property.ts +225 -0
  67. package/src/src/ast/nodes/reference.ts +178 -0
  68. package/src/src/ast/nodes/string.ts +114 -0
  69. package/src/src/ast/nodes/types.ts +23 -0
  70. package/src/src/ast/references/index.ts +10 -0
  71. package/src/src/ast/references/jackson.ts +44 -0
  72. package/src/src/ast/references/jakarta.ts +14 -0
  73. package/src/src/ast/references/java.ts +27 -0
  74. package/src/src/ast/references/kotlin.ts +41 -0
  75. package/src/src/ast/references/kotlinx.ts +14 -0
  76. package/src/src/ast/references/okhttp3.ts +5 -0
  77. package/src/src/ast/references/reactor.ts +5 -0
  78. package/src/src/ast/references/spring-reactive.ts +33 -0
  79. package/src/src/ast/references/spring.ts +86 -0
  80. package/src/src/ast/references/swagger.ts +23 -0
  81. package/src/src/ast/utils/get-kotlin-builder-options.ts +19 -0
  82. package/src/src/ast/utils/to-kt-node.ts +31 -0
  83. package/src/src/ast/utils/write-kt-annotations.ts +15 -0
  84. package/src/src/ast/utils/write-kt-arguments.ts +45 -0
  85. package/src/src/ast/utils/write-kt-enum-values.ts +27 -0
  86. package/src/src/ast/utils/write-kt-generic-parameters.ts +12 -0
  87. package/src/src/ast/utils/write-kt-members.ts +25 -0
  88. package/src/src/ast/utils/write-kt-node.ts +37 -0
  89. package/src/src/ast/utils/write-kt-parameters.ts +25 -0
  90. package/src/src/common-results.ts +4 -0
  91. package/src/src/config.ts +48 -0
  92. package/src/src/file-builder.ts +112 -0
  93. package/src/src/generators/file-generator.ts +29 -0
  94. package/src/src/generators/index.ts +5 -0
  95. package/src/src/generators/models/args.ts +136 -0
  96. package/src/src/generators/models/index.ts +4 -0
  97. package/src/src/generators/models/model-generator.ts +725 -0
  98. package/src/src/generators/models/models-generator.ts +65 -0
  99. package/src/src/generators/models/models.ts +95 -0
  100. package/src/src/generators/services/okhttp3-clients/args.ts +90 -0
  101. package/src/src/generators/services/okhttp3-clients/index.ts +4 -0
  102. package/src/src/generators/services/okhttp3-clients/models.ts +73 -0
  103. package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +609 -0
  104. package/src/src/generators/services/okhttp3-clients/okhttp3-clients-generator.ts +169 -0
  105. package/src/src/generators/services/okhttp3-clients/refs.ts +59 -0
  106. package/src/src/generators/services/spring-controllers/args.ts +95 -0
  107. package/src/src/generators/services/spring-controllers/index.ts +4 -0
  108. package/src/src/generators/services/spring-controllers/models.ts +76 -0
  109. package/src/src/generators/services/spring-controllers/refs.ts +17 -0
  110. package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +1099 -0
  111. package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +140 -0
  112. package/src/src/generators/services/spring-reactive-web-clients/args.ts +103 -0
  113. package/src/src/generators/services/spring-reactive-web-clients/index.ts +4 -0
  114. package/src/src/generators/services/spring-reactive-web-clients/models.ts +62 -0
  115. package/src/src/generators/services/spring-reactive-web-clients/refs.ts +11 -0
  116. package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts +583 -0
  117. package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.ts +125 -0
  118. package/src/src/import-collection.ts +98 -0
  119. package/src/src/types.ts +3 -0
  120. package/src/src/utils.ts +47 -0
@@ -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
- if (ctx.config.strictResponseEntities) {
89
- members.push(...ctx.service.endpoints.map((endpoint) => this.getApiResponseEntityClass(ctx, { endpoint })));
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,28 +261,24 @@ 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
  }
273
274
  getApiResponseEntityClass(ctx, args) {
274
275
  const { endpoint } = args;
275
276
  const name = this.getApiResponseEntityName(ctx, { endpoint });
276
- // Spring 7's `ResponseEntity<T>` carries an `Any` upper bound (JSpecify), so the subclass must bound `T`.
277
- // The body parameter is then made nullable (`T?`) to keep null-body ("no response body") responses legal
278
- // while staying wire-identical, since Spring's super constructor accepts a `@Nullable T body`.
279
- const springBoot4 = ctx.config.springBootVersion === 4;
280
277
  return index_js_1.kt.class(name, {
281
278
  doc: index_js_1.kt.doc(`Response entity for ${endpoint.name}.`),
282
- generics: [index_js_1.kt.genericParameter('T', springBoot4 ? { constraint: index_js_1.kt.refs.any() } : undefined)],
279
+ generics: [index_js_1.kt.genericParameter('T')],
283
280
  primaryConstructor: index_js_1.kt.constructor([
284
- index_js_1.kt.parameter.class('body', index_js_1.kt.reference('T', null, springBoot4 ? { nullable: true } : undefined)),
281
+ index_js_1.kt.parameter.class('body', index_js_1.kt.reference('T')),
285
282
  index_js_1.kt.parameter.class('rawStatus', index_js_1.kt.refs.int()),
286
283
  index_js_1.kt.parameter.class('headers', index_js_1.kt.refs.spring.multiValueMap([index_js_1.kt.refs.string(), index_js_1.kt.refs.string()], {
287
284
  nullable: true,
@@ -317,22 +314,18 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
317
314
  body: index_js_1.kt.call([
318
315
  index_js_1.kt.reference(this.getApiResponseEntityName(ctx, { endpoint }), null, {
319
316
  generics: [
320
- hasResponseBody
321
- ? responseType
322
- // `Unit?` violates the `T : Any` bound under Spring Boot 4; the `null` body argument
323
- // below stays (now legal because the subclass body parameter is nullable).
324
- : (springBoot4 ? index_js_1.kt.refs.unit() : index_js_1.kt.refs.unit({ nullable: true })),
317
+ hasResponseBody ? responseType : index_js_1.kt.refs.unit({ nullable: true }),
325
318
  ],
326
319
  }),
327
320
  ], [
328
321
  hasResponseBody ? index_js_1.kt.argument('body') : index_js_1.kt.toNode(null),
329
322
  index_js_1.kt.toNode(code),
330
323
  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)})
324
+ ? (0, core_1.builderTemplate) `${index_js_1.kt.refs.spring.linkedMultiValueMap([index_js_1.kt.refs.string(), index_js_1.kt.refs.string()])}().also {
325
+ if (headers != null) {
326
+ it.putAll(headers)
327
+ }
328
+ it.addIfAbsent("Content-Type", ${index_js_1.kt.string(contentType)})
336
329
  }`
337
330
  : index_js_1.kt.argument('headers'),
338
331
  ]),
@@ -471,6 +464,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
471
464
  return members;
472
465
  }
473
466
  getApiDelegateInterfaceEndpointMethod(ctx, args) {
467
+ var _a;
474
468
  const { endpoint } = args;
475
469
  const parameters = this.getAllParameters(ctx, { endpoint });
476
470
  const fn = index_js_1.kt.function((0, core_1.toCasing)(endpoint.name, ctx.config.functionNameCasing), {
@@ -480,7 +474,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
480
474
  return index_js_1.kt.parameter((0, core_1.toCasing)(parameter.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter }));
481
475
  }),
482
476
  });
483
- if (ctx.config.strictResponseEntities) {
477
+ if ((_a = endpoint.custom[strictResponseCustomProperty]) !== null && _a !== void 0 ? _a : ctx.config.strictResponseEntities) {
484
478
  const responseEntity = index_js_1.kt.reference.genericFactory(this.getApiResponseEntityName(ctx, { endpoint }), `${this.getPackageName(ctx, {})}.${this.getApiInterfaceName(ctx, {})}`);
485
479
  fn.returnType = responseEntity(['*']);
486
480
  fn.body = (0, core_1.appendValueGroup)([
@@ -536,9 +530,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
536
530
  return index_js_1.kt.refs.unit();
537
531
  }
538
532
  else {
539
- // Under Spring Boot 4, this type flows into `ResponseEntity<T : Any>` (e.g. the delegate default methods),
540
- // so the ambiguous/unknown-body fallback must be non-null `Any` rather than `Any?`.
541
- return ctx.config.springBootVersion === 4 ? index_js_1.kt.refs.any() : index_js_1.kt.refs.any({ nullable: true });
533
+ return index_js_1.kt.refs.any({ nullable: true });
542
534
  }
543
535
  }
544
536
  getTypeUsage(ctx, args) {
@@ -1 +1 @@
1
- {"version":3,"file":"spring-reactive-web-client-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EAIrB,KAAK,YAAY,EAGjB,aAAa,EAEd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAE3C,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,iDAAiD,IAAI,IAAI,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,KAAK,EACV,6CAA6C,EAC7C,4CAA4C,EAC7C,MAAM,aAAa,CAAC;AAErB,KAAK,OAAO,GAAG,6CAA6C,CAAC;AAC7D,KAAK,MAAM,GAAG,4CAA4C,CAAC;AAC3D,KAAK,OAAO,GAAG,iBAAiB,CAAC;AAEjC,MAAM,WAAW,sCAAsC,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IACrF,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;CAC/C;AAED,qBAAa,6CAA8C,SAAQ,mBAAmB,CAAC,OAAO,EAAE,MAAM,CACpG,YAAW,sCAAsC;IAC1C,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC;IAoBnD,SAAS,CAAC,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,oBAAoB,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAKxG,SAAS,CAAC,iBA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,CAAC,aAAa,CAAC,GAAG,SAAS;IAKxG,SAAS,CAAC,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,gBAAgB,GAAG,6BAA6B,EAAE;IAmDtG,SAAS,CAAC,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,uBAAuB,GAAG,MAAM;IAU3F,SAAS,CAAC,yBAAyB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,yBAAyB,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAUlH,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,GAAG,MAAM;IAQpE,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,eAAe,GAAG,MAAM;IAK3E,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,GAAG,MAAM;IAMnE,SAAS,CAAC,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,qBAAqB,GAAG,MAAM;IAIvF,OAAO,CAAC,kBAAkB;CAgB3B"}
1
+ {"version":3,"file":"spring-reactive-web-client-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EAIrB,KAAK,YAAY,EAGjB,aAAa,EAEd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAE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C,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,eAAe,GAAG,MAAM;IAK3E,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,GAAG,MAAM;IAMnE,SAAS,CAAC,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,qBAAqB,GAAG,MAAM;IAIvF,OAAO,CAAC,kBAAkB;CAgB3B"}
@@ -86,10 +86,7 @@ class DefaultKotlinSpringReactiveWebClientGenerator extends file_generator_js_1.
86
86
  return index_js_1.kt.function(functionName, {
87
87
  doc: index_js_1.kt.doc(this.getEndpointDocDescription(ctx, { endpoint })),
88
88
  suspend: true,
89
- // Spring 7's `WebClient.exchangeToMono` is `<V : Any>`, so the `<T>` overloads need an `Any` bound to infer.
90
- generics: [
91
- index_js_1.kt.genericParameter('T', ctx.config.springBootVersion === 4 ? { constraint: index_js_1.kt.refs.any() } : undefined),
92
- ],
89
+ generics: [index_js_1.kt.genericParameter('T')],
93
90
  receiverType: index_js_1.kt.refs.springReactive.webClient(),
94
91
  parameters: [
95
92
  ...parameters.map((parameter) => index_js_1.kt.parameter((0, core_1.toCasing)(parameter.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter }), { default: this.getParameterDefaultValue(ctx, { endpoint, parameter }) })),
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
+ });
@@ -0,0 +1,178 @@
1
+ import {
2
+ type AppendValue,
3
+ type AstNodeOptions,
4
+ type BasicAppendValue,
5
+ createOverwriteProxy,
6
+ notNullish,
7
+ type Nullable,
8
+ type Prettify,
9
+ type SourceBuilder,
10
+ } from '@goast/core';
11
+
12
+ import type { KtAccessModifier } from '../common.js';
13
+ import { KtNode } from '../node.js';
14
+ import { writeKtMembers } from '../utils/write-kt-members.js';
15
+ import { writeKtNode, writeKtNodes } from '../utils/write-kt-node.js';
16
+ import { type KtAnnotation, ktAnnotation } from './annotation.js';
17
+ import { ktArgument } from './argument.js';
18
+ import type { KtConstructor } from './constructor.js';
19
+ import { type KtDoc, ktDoc } from './doc.js';
20
+ import type { KtEnum } from './enum.js';
21
+ import type { KtFunction } from './function.js';
22
+ import { type KtGenericParameter, ktGenericParameter } from './generic-parameter.js';
23
+ import { type KtInitBlock, ktInitBlock } from './init-block.js';
24
+ import type { KtInterface } from './interface.js';
25
+ import type { KtObject } from './object.js';
26
+ import type { KtProperty } from './property.js';
27
+ import type { KtType } from './types.js';
28
+
29
+ type Injects =
30
+ | 'doc'
31
+ | 'annotations'
32
+ | 'modifiers'
33
+ | 'name'
34
+ | 'generics'
35
+ | 'primaryConstructor'
36
+ | 'inheritList'
37
+ | 'body'
38
+ | 'members';
39
+
40
+ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
41
+ typeof KtNode<TBuilder, TInjects | Injects>,
42
+ {
43
+ doc?: Nullable<KtDoc<TBuilder>>;
44
+ annotations?: Nullable<Nullable<KtAnnotation<TBuilder>>[]>;
45
+ accessModifier?: Nullable<KtAccessModifier>;
46
+ open?: Nullable<boolean>;
47
+ abstract?: Nullable<boolean>;
48
+ classKind?: Nullable<KtClassKind>;
49
+ name: string;
50
+ generics?: Nullable<Nullable<KtGenericParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
51
+ primaryConstructor?: Nullable<KtConstructor<TBuilder>>;
52
+ extends?: Nullable<KtType<TBuilder>>;
53
+ implements?: Nullable<Nullable<KtType<TBuilder>>[]>;
54
+ companionObject?: Nullable<KtObject<TBuilder>>;
55
+ members?: Nullable<Nullable<KtClassMember<TBuilder>>[]>;
56
+ }
57
+ >;
58
+
59
+ export type KtClassKind = 'data' | 'value' | 'annotation' | 'sealed';
60
+ export type KtClassMember<TBuilder extends SourceBuilder> =
61
+ | KtConstructor<TBuilder>
62
+ | KtEnum<TBuilder>
63
+ | KtInitBlock<TBuilder>
64
+ | KtInterface<TBuilder>
65
+ | KtProperty<TBuilder>
66
+ | KtFunction<TBuilder>
67
+ | KtClass<TBuilder>
68
+ | AppendValue<TBuilder>;
69
+
70
+ export class KtClass<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<
71
+ TBuilder,
72
+ TInjects | Injects
73
+ > {
74
+ public doc: KtDoc<TBuilder> | null;
75
+ public annotations: KtAnnotation<TBuilder>[];
76
+ public accessModifier: KtAccessModifier | null;
77
+ public open: boolean;
78
+ public abstract: boolean;
79
+ public classKind: KtClassKind | null;
80
+ public name: string;
81
+ public generics: (KtGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
82
+ public primaryConstructor: KtConstructor<TBuilder> | null;
83
+ public extends: KtType<TBuilder> | null;
84
+ public implements: KtType<TBuilder>[];
85
+ public members: KtClassMember<TBuilder>[];
86
+ public companionObject: Nullable<KtObject<TBuilder>>;
87
+
88
+ constructor(options: Options<TBuilder, TInjects>) {
89
+ super(options);
90
+ this.doc = options.doc ?? null;
91
+ this.annotations = options.annotations?.filter(notNullish) ?? [];
92
+ this.accessModifier = options.accessModifier ?? null;
93
+ this.open = options.open ?? false;
94
+ this.abstract = options.abstract ?? false;
95
+ this.classKind = options.classKind ?? null;
96
+ this.name = options.name;
97
+ this.generics = options.generics?.filter(notNullish) ?? [];
98
+ this.primaryConstructor = options.primaryConstructor ?? null;
99
+ this.extends = options.extends ?? null;
100
+ this.implements = options.implements?.filter(notNullish) ?? [];
101
+ this.members = options.members?.filter(notNullish) ?? [];
102
+ this.companionObject = options.companionObject;
103
+ }
104
+
105
+ protected override onWrite(builder: TBuilder): void {
106
+ builder.append(this.inject.beforeDoc);
107
+ ktDoc.get(this.doc, { generics: this.generics, parameters: this.primaryConstructor?.parameters })?.write(builder);
108
+ builder.append(this.inject.afterDoc);
109
+
110
+ builder.append(this.inject.beforeAnnotations);
111
+ ktAnnotation.write(builder, this.annotations, { multiline: true });
112
+ builder.append(this.inject.afterAnnotations);
113
+
114
+ builder.append(this.inject.beforeModifiers);
115
+ if (this.accessModifier) builder.append(this.accessModifier, ' ');
116
+ if (this.open) builder.append('open ');
117
+ if (this.abstract) builder.append('abstract ');
118
+ if (this.classKind) builder.append(this.classKind, ' ');
119
+ builder.append(this.inject.afterModifiers);
120
+
121
+ builder.append('class ');
122
+ builder.append(this.inject.beforeName, this.name, this.inject.afterName);
123
+
124
+ builder.append(this.inject.beforeGenerics);
125
+ ktGenericParameter.write(builder, this.generics);
126
+ builder.append(this.inject.afterGenerics);
127
+
128
+ if (this.primaryConstructor) {
129
+ builder.append(this.inject.beforePrimaryConstructor);
130
+ this.primaryConstructor.writeAsPrimary(builder);
131
+ builder.append(this.inject.afterPrimaryConstructor);
132
+ }
133
+
134
+ if (this.extends || this.implements.length > 0) {
135
+ builder.append(' : ');
136
+ builder.append(this.inject.beforeInheritList);
137
+ writeKtNode(builder, this.extends);
138
+ if (this.extends && this.primaryConstructor?.delegateTarget === 'super') {
139
+ ktArgument.write(builder, this.primaryConstructor.delegateArguments);
140
+ }
141
+ if (this.extends && this.implements.length > 0) {
142
+ builder.append(', ');
143
+ }
144
+ writeKtNodes(builder, this.implements, { separator: ', ' });
145
+ builder.append(this.inject.afterInheritList);
146
+ }
147
+
148
+ if (this.members.length > 0 || this.primaryConstructor?.body || this.companionObject) {
149
+ builder.append(' ');
150
+ builder.append(this.inject.beforeBody);
151
+ builder.parenthesize(
152
+ '{}',
153
+ (b) => {
154
+ b.append(this.inject.beforeMembers);
155
+ writeKtMembers(b, [
156
+ this.companionObject ? createOverwriteProxy(this.companionObject, { companion: true }) : null,
157
+ this.primaryConstructor?.body ? ktInitBlock(this.primaryConstructor?.body) : null,
158
+ ...this.members,
159
+ ]);
160
+ b.append(this.inject.afterMembers);
161
+ },
162
+ { multiline: true },
163
+ );
164
+ builder.append(this.inject.afterBody);
165
+ }
166
+
167
+ builder.appendLine();
168
+ }
169
+ }
170
+
171
+ const createClass = <TBuilder extends SourceBuilder>(
172
+ name: Options<TBuilder>['name'],
173
+ options?: Prettify<Omit<Options<TBuilder>, 'name'>>,
174
+ ): KtClass<TBuilder> => new KtClass<TBuilder>({ ...options, name });
175
+
176
+ export const ktClass: typeof createClass & { write: typeof writeKtNodes } = Object.assign(createClass, {
177
+ write: writeKtNodes,
178
+ });