@kizunajs/kotlin 2.0.0-beta.18 → 2.0.0-beta.19
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/dist/cli.cjs
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as generateKotlinClient } from "./generator-
|
|
2
|
+
import { t as generateKotlinClient } from "./generator-DT7c2Vo3.mjs";
|
|
3
3
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
@@ -58,7 +58,6 @@ var TypeRegistry = class {
|
|
|
58
58
|
sealedVariantPaths = /* @__PURE__ */ new Map();
|
|
59
59
|
brands = /* @__PURE__ */ new Map();
|
|
60
60
|
usesJsonElement = false;
|
|
61
|
-
usesNullish = false;
|
|
62
61
|
constructor(camelCaseProperties = false, unknownEnumCase = false) {
|
|
63
62
|
this.camelCaseProperties = camelCaseProperties;
|
|
64
63
|
this.unknownEnumCase = unknownEnumCase;
|
|
@@ -128,13 +127,11 @@ const propertyName = (key, camelCase) => {
|
|
|
128
127
|
if (!camel) return "field";
|
|
129
128
|
return /^[0-9]/.test(camel) ? `_${camel}` : camel;
|
|
130
129
|
};
|
|
131
|
-
const objectFields = (schema, registry, hint,
|
|
130
|
+
const objectFields = (schema, registry, hint, shape = (0, kizunajs_generator.readObjectShape)(schema) ?? {}) => {
|
|
132
131
|
const fields = [];
|
|
133
132
|
const seen = /* @__PURE__ */ new Map();
|
|
134
133
|
for (const [key, value] of Object.entries(shape)) {
|
|
135
134
|
const result = mapType(value, registry, `${hint}${(0, kizunajs_generator.toPascalCase)(key)}`);
|
|
136
|
-
const nullish = nullishTriState && result.nullish === true;
|
|
137
|
-
if (nullish) registry.usesNullish = true;
|
|
138
135
|
const deprecation = (0, kizunajs_generator.readDeprecation)(value);
|
|
139
136
|
const kotlinName = propertyName(key, registry.camelCaseProperties);
|
|
140
137
|
const previousWireName = seen.get(kotlinName);
|
|
@@ -143,10 +140,9 @@ const objectFields = (schema, registry, hint, nullishTriState = true, shape = (0
|
|
|
143
140
|
fields.push({
|
|
144
141
|
name: kotlinName,
|
|
145
142
|
wireName: key,
|
|
146
|
-
type:
|
|
147
|
-
optional: result.optional
|
|
143
|
+
type: result.expression,
|
|
144
|
+
optional: result.optional,
|
|
148
145
|
requiredNullable: result.requiredNullable,
|
|
149
|
-
nullish,
|
|
150
146
|
description: (0, kizunajs_generator.readMetaDescription)(value),
|
|
151
147
|
isFile: result.isFile,
|
|
152
148
|
deprecated: deprecation !== void 0,
|
|
@@ -270,7 +266,6 @@ const mapUnbrandedType = (schema, registry, hint) => {
|
|
|
270
266
|
expression: innerResult.expression.endsWith("?") ? innerResult.expression : `${innerResult.expression}?`,
|
|
271
267
|
optional: true,
|
|
272
268
|
requiredNullable: nullable && !optional,
|
|
273
|
-
nullish: nullable && optional,
|
|
274
269
|
isFile: innerResult.isFile
|
|
275
270
|
};
|
|
276
271
|
}
|
|
@@ -452,13 +447,10 @@ const sanitizeCaseName = (literal) => {
|
|
|
452
447
|
if (/^[0-9]/.test(cleaned)) return `_${cleaned}`;
|
|
453
448
|
return cleaned.charAt(0).toUpperCase() + cleaned.slice(1);
|
|
454
449
|
};
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
*/
|
|
458
|
-
const collectObjectFields = (schema, registry, hint, json = false) => {
|
|
459
|
-
return objectFields(schema, registry, hint, json);
|
|
450
|
+
const collectObjectFields = (schema, registry, hint) => {
|
|
451
|
+
return objectFields(schema, registry, hint);
|
|
460
452
|
};
|
|
461
|
-
const hasDefault = (field) => field.optional && field.requiredNullable !== true
|
|
453
|
+
const hasDefault = (field) => field.optional && field.requiredNullable !== true;
|
|
462
454
|
const objectFieldCount = (schema) => {
|
|
463
455
|
return Object.keys((0, kizunajs_generator.readObjectShape)(schema) ?? {}).length;
|
|
464
456
|
};
|
|
@@ -523,7 +515,7 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
|
|
|
523
515
|
else bodyDescriptor = {
|
|
524
516
|
kind: "json-flat",
|
|
525
517
|
structName,
|
|
526
|
-
flattened: collectObjectFields(route.body, registry, bodyHint
|
|
518
|
+
flattened: collectObjectFields(route.body, registry, bodyHint),
|
|
527
519
|
multipartFields: []
|
|
528
520
|
};
|
|
529
521
|
}
|
|
@@ -689,48 +681,9 @@ const KOTLIN_KEYWORDS = new Set([
|
|
|
689
681
|
const escapeKeyword = (name) => {
|
|
690
682
|
return KOTLIN_KEYWORDS.has(name) ? `\`${name}\`` : name;
|
|
691
683
|
};
|
|
692
|
-
const NULLISH_TYPE = /^Nullish<(.+)>$/;
|
|
693
|
-
const emitNullish = (writer) => {
|
|
694
|
-
writer.line("/** A `.nullish()` field: left out, sent as `null`, or sent with a value. */");
|
|
695
|
-
writer.line("@Serializable(with = NullishSerializer::class)");
|
|
696
|
-
writer.block("sealed interface Nullish<out T>", () => {
|
|
697
|
-
writer.line("val value: T?");
|
|
698
|
-
writer.blank();
|
|
699
|
-
writer.block("data object Absent : Nullish<Nothing>", () => {
|
|
700
|
-
writer.line("override val value: Nothing? get() = null");
|
|
701
|
-
});
|
|
702
|
-
writer.blank();
|
|
703
|
-
writer.block("data object Null : Nullish<Nothing>", () => {
|
|
704
|
-
writer.line("override val value: Nothing? get() = null");
|
|
705
|
-
});
|
|
706
|
-
writer.blank();
|
|
707
|
-
writer.line("data class Some<out T>(override val value: T) : Nullish<T>");
|
|
708
|
-
});
|
|
709
|
-
writer.blank();
|
|
710
|
-
writer.block("class NullishSerializer<T>(private val valueSerializer: KSerializer<T>) : KSerializer<Nullish<T>>", () => {
|
|
711
|
-
writer.line("override val descriptor: SerialDescriptor = valueSerializer.descriptor.nullable");
|
|
712
|
-
writer.blank();
|
|
713
|
-
writer.line("@OptIn(ExperimentalSerializationApi::class)");
|
|
714
|
-
writer.block("override fun serialize(encoder: Encoder, value: Nullish<T>)", () => {
|
|
715
|
-
writer.line("when (value) {");
|
|
716
|
-
writer.line(" is Nullish.Some -> encoder.encodeSerializableValue(valueSerializer, value.value)");
|
|
717
|
-
writer.line(" Nullish.Null -> encoder.encodeNull()");
|
|
718
|
-
writer.line(" Nullish.Absent -> throw SerializationException(\"An absent field has no value to write, so its key is left out\")");
|
|
719
|
-
writer.line("}");
|
|
720
|
-
});
|
|
721
|
-
writer.blank();
|
|
722
|
-
writer.line("@OptIn(ExperimentalSerializationApi::class)");
|
|
723
|
-
writer.block("override fun deserialize(decoder: Decoder): Nullish<T>", () => {
|
|
724
|
-
writer.line("if (decoder.decodeNotNullMark()) return Nullish.Some(decoder.decodeSerializableValue(valueSerializer))");
|
|
725
|
-
writer.line("decoder.decodeNull()");
|
|
726
|
-
writer.line("return Nullish.Null");
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
writer.blank();
|
|
730
|
-
};
|
|
731
684
|
const defaultArgument = (field) => {
|
|
732
685
|
if (!hasDefault(field)) return "";
|
|
733
|
-
return
|
|
686
|
+
return " = null";
|
|
734
687
|
};
|
|
735
688
|
const optionalize = (type, optional) => {
|
|
736
689
|
if (!optional) return type;
|
|
@@ -752,8 +705,6 @@ const KOTLIN_PRIMITIVE_TYPES = new Set([
|
|
|
752
705
|
const decodeBody = (resolved) => resolved === "ByteArray" ? "data" : `json.decodeFromString<${resolved}>(data.decodeToString())`;
|
|
753
706
|
const resolveType = (typeName, currentOperation, context, scope = "client") => {
|
|
754
707
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
755
|
-
const nullish = NULLISH_TYPE.exec(typeName);
|
|
756
|
-
if (nullish) return `Nullish<${resolveType(nullish[1], currentOperation, context, scope)}>`;
|
|
757
708
|
const optional = typeName.endsWith("?");
|
|
758
709
|
const base = optional ? typeName.slice(0, -1) : typeName;
|
|
759
710
|
if (KOTLIN_PRIMITIVE_TYPES.has(base)) return typeName;
|
|
@@ -876,8 +827,6 @@ const emitDataClass = (writer, type, ownedTypeMap, ownedTypeLookup, registryName
|
|
|
876
827
|
const baseFields = type.discriminatorWireName ? type.fields.filter((field) => field.wireName !== type.discriminatorWireName) : type.fields;
|
|
877
828
|
const hasFile = baseFields.some((field) => field.isFile);
|
|
878
829
|
const resolveOwnedType = (raw) => {
|
|
879
|
-
const nullish = NULLISH_TYPE.exec(raw);
|
|
880
|
-
if (nullish) return `Nullish<${resolveOwnedType(nullish[1])}>`;
|
|
881
830
|
const optional = raw.endsWith("?");
|
|
882
831
|
const stripped = optional ? raw.slice(0, -1) : raw;
|
|
883
832
|
const isList = stripped.startsWith("List<") && stripped.endsWith(">");
|
|
@@ -893,15 +842,12 @@ const emitDataClass = (writer, type, ownedTypeMap, ownedTypeLookup, registryName
|
|
|
893
842
|
}));
|
|
894
843
|
const needsSerialName = !hasFile && baseFields.some((field) => field.name !== field.wireName || KOTLIN_KEYWORDS.has(field.name));
|
|
895
844
|
if (type.serialName !== void 0) writer.line(`@SerialName(${stringLiteral(type.serialName)})`);
|
|
896
|
-
if (!hasFile)
|
|
897
|
-
if (adjustedFields.some((field) => field.nullish)) writer.line("@OptIn(ExperimentalSerializationApi::class)");
|
|
898
|
-
writer.line("@Serializable");
|
|
899
|
-
}
|
|
845
|
+
if (!hasFile) writer.line("@Serializable");
|
|
900
846
|
const params = adjustedFields.map((field) => {
|
|
901
847
|
const typeExpression = optionalize(field.type, field.optional);
|
|
902
848
|
const defaultPart = defaultArgument(field);
|
|
903
849
|
const serialNameAnnotation = needsSerialName && (field.name !== field.wireName || KOTLIN_KEYWORDS.has(field.name)) ? `@SerialName(${stringLiteral(field.wireName)}) ` : "";
|
|
904
|
-
return `${field.deprecated ? `${deprecatedAnnotation(field.deprecationMessage)} ` : ""}${serialNameAnnotation}
|
|
850
|
+
return `${field.deprecated ? `${deprecatedAnnotation(field.deprecationMessage)} ` : ""}${serialNameAnnotation}val ${escapeKeyword(field.name)}: ${typeExpression}${defaultPart}`;
|
|
905
851
|
});
|
|
906
852
|
const hasOwnedTypes = Array.from(ownedTypeMap.entries()).some(([, owner]) => owner === lookupName);
|
|
907
853
|
if (params.length === 0) writer.line(`data class ${type.name}(private val unused: Unit = Unit)`);
|
|
@@ -943,8 +889,6 @@ const relativeOwnedPath = (typeName, ownedTypeMap, enclosingPath, registry) => {
|
|
|
943
889
|
return path.startsWith(prefix) ? path.slice(prefix.length) : void 0;
|
|
944
890
|
};
|
|
945
891
|
const ownedTypePath = (typeName, ownedTypeMap, registry) => {
|
|
946
|
-
const nullish = NULLISH_TYPE.exec(typeName);
|
|
947
|
-
if (nullish) return `Nullish<${ownedTypePath(nullish[1], ownedTypeMap, registry)}>`;
|
|
948
892
|
const sealedPath = registry?.sealedVariantPath(typeName);
|
|
949
893
|
if (sealedPath !== void 0) return sealedPath;
|
|
950
894
|
const owningClass = ownedTypeMap.get(typeName);
|
|
@@ -1837,7 +1781,7 @@ const renderKotlinClient = (api, partition, registry, config) => {
|
|
|
1837
1781
|
}
|
|
1838
1782
|
writer.line("import kotlinx.serialization.*");
|
|
1839
1783
|
writer.line("import kotlinx.serialization.json.*");
|
|
1840
|
-
if (registry.all().some((type) => type.kind === "enum-class" && type.unknownCase)
|
|
1784
|
+
if (registry.all().some((type) => type.kind === "enum-class" && type.unknownCase)) {
|
|
1841
1785
|
writer.line("import kotlinx.serialization.descriptors.*");
|
|
1842
1786
|
writer.line("import kotlinx.serialization.encoding.*");
|
|
1843
1787
|
}
|
|
@@ -1855,7 +1799,6 @@ const renderKotlinClient = (api, partition, registry, config) => {
|
|
|
1855
1799
|
});
|
|
1856
1800
|
writer.blank();
|
|
1857
1801
|
}
|
|
1858
|
-
if (registry.usesNullish) emitNullish(writer);
|
|
1859
1802
|
const sharedTypes = [];
|
|
1860
1803
|
const typesByOperation = /* @__PURE__ */ new Map();
|
|
1861
1804
|
for (const type of registry.all()) {
|
|
@@ -58,7 +58,6 @@ var TypeRegistry = class {
|
|
|
58
58
|
sealedVariantPaths = /* @__PURE__ */ new Map();
|
|
59
59
|
brands = /* @__PURE__ */ new Map();
|
|
60
60
|
usesJsonElement = false;
|
|
61
|
-
usesNullish = false;
|
|
62
61
|
constructor(camelCaseProperties = false, unknownEnumCase = false) {
|
|
63
62
|
this.camelCaseProperties = camelCaseProperties;
|
|
64
63
|
this.unknownEnumCase = unknownEnumCase;
|
|
@@ -128,13 +127,11 @@ const propertyName = (key, camelCase) => {
|
|
|
128
127
|
if (!camel) return "field";
|
|
129
128
|
return /^[0-9]/.test(camel) ? `_${camel}` : camel;
|
|
130
129
|
};
|
|
131
|
-
const objectFields = (schema, registry, hint,
|
|
130
|
+
const objectFields = (schema, registry, hint, shape = readObjectShape(schema) ?? {}) => {
|
|
132
131
|
const fields = [];
|
|
133
132
|
const seen = /* @__PURE__ */ new Map();
|
|
134
133
|
for (const [key, value] of Object.entries(shape)) {
|
|
135
134
|
const result = mapType(value, registry, `${hint}${toPascalCase(key)}`);
|
|
136
|
-
const nullish = nullishTriState && result.nullish === true;
|
|
137
|
-
if (nullish) registry.usesNullish = true;
|
|
138
135
|
const deprecation = readDeprecation(value);
|
|
139
136
|
const kotlinName = propertyName(key, registry.camelCaseProperties);
|
|
140
137
|
const previousWireName = seen.get(kotlinName);
|
|
@@ -143,10 +140,9 @@ const objectFields = (schema, registry, hint, nullishTriState = true, shape = re
|
|
|
143
140
|
fields.push({
|
|
144
141
|
name: kotlinName,
|
|
145
142
|
wireName: key,
|
|
146
|
-
type:
|
|
147
|
-
optional: result.optional
|
|
143
|
+
type: result.expression,
|
|
144
|
+
optional: result.optional,
|
|
148
145
|
requiredNullable: result.requiredNullable,
|
|
149
|
-
nullish,
|
|
150
146
|
description: readMetaDescription(value),
|
|
151
147
|
isFile: result.isFile,
|
|
152
148
|
deprecated: deprecation !== void 0,
|
|
@@ -270,7 +266,6 @@ const mapUnbrandedType = (schema, registry, hint) => {
|
|
|
270
266
|
expression: innerResult.expression.endsWith("?") ? innerResult.expression : `${innerResult.expression}?`,
|
|
271
267
|
optional: true,
|
|
272
268
|
requiredNullable: nullable && !optional,
|
|
273
|
-
nullish: nullable && optional,
|
|
274
269
|
isFile: innerResult.isFile
|
|
275
270
|
};
|
|
276
271
|
}
|
|
@@ -452,13 +447,10 @@ const sanitizeCaseName = (literal) => {
|
|
|
452
447
|
if (/^[0-9]/.test(cleaned)) return `_${cleaned}`;
|
|
453
448
|
return cleaned.charAt(0).toUpperCase() + cleaned.slice(1);
|
|
454
449
|
};
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
*/
|
|
458
|
-
const collectObjectFields = (schema, registry, hint, json = false) => {
|
|
459
|
-
return objectFields(schema, registry, hint, json);
|
|
450
|
+
const collectObjectFields = (schema, registry, hint) => {
|
|
451
|
+
return objectFields(schema, registry, hint);
|
|
460
452
|
};
|
|
461
|
-
const hasDefault = (field) => field.optional && field.requiredNullable !== true
|
|
453
|
+
const hasDefault = (field) => field.optional && field.requiredNullable !== true;
|
|
462
454
|
const objectFieldCount = (schema) => {
|
|
463
455
|
return Object.keys(readObjectShape(schema) ?? {}).length;
|
|
464
456
|
};
|
|
@@ -523,7 +515,7 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
|
|
|
523
515
|
else bodyDescriptor = {
|
|
524
516
|
kind: "json-flat",
|
|
525
517
|
structName,
|
|
526
|
-
flattened: collectObjectFields(route.body, registry, bodyHint
|
|
518
|
+
flattened: collectObjectFields(route.body, registry, bodyHint),
|
|
527
519
|
multipartFields: []
|
|
528
520
|
};
|
|
529
521
|
}
|
|
@@ -689,48 +681,9 @@ const KOTLIN_KEYWORDS = new Set([
|
|
|
689
681
|
const escapeKeyword = (name) => {
|
|
690
682
|
return KOTLIN_KEYWORDS.has(name) ? `\`${name}\`` : name;
|
|
691
683
|
};
|
|
692
|
-
const NULLISH_TYPE = /^Nullish<(.+)>$/;
|
|
693
|
-
const emitNullish = (writer) => {
|
|
694
|
-
writer.line("/** A `.nullish()` field: left out, sent as `null`, or sent with a value. */");
|
|
695
|
-
writer.line("@Serializable(with = NullishSerializer::class)");
|
|
696
|
-
writer.block("sealed interface Nullish<out T>", () => {
|
|
697
|
-
writer.line("val value: T?");
|
|
698
|
-
writer.blank();
|
|
699
|
-
writer.block("data object Absent : Nullish<Nothing>", () => {
|
|
700
|
-
writer.line("override val value: Nothing? get() = null");
|
|
701
|
-
});
|
|
702
|
-
writer.blank();
|
|
703
|
-
writer.block("data object Null : Nullish<Nothing>", () => {
|
|
704
|
-
writer.line("override val value: Nothing? get() = null");
|
|
705
|
-
});
|
|
706
|
-
writer.blank();
|
|
707
|
-
writer.line("data class Some<out T>(override val value: T) : Nullish<T>");
|
|
708
|
-
});
|
|
709
|
-
writer.blank();
|
|
710
|
-
writer.block("class NullishSerializer<T>(private val valueSerializer: KSerializer<T>) : KSerializer<Nullish<T>>", () => {
|
|
711
|
-
writer.line("override val descriptor: SerialDescriptor = valueSerializer.descriptor.nullable");
|
|
712
|
-
writer.blank();
|
|
713
|
-
writer.line("@OptIn(ExperimentalSerializationApi::class)");
|
|
714
|
-
writer.block("override fun serialize(encoder: Encoder, value: Nullish<T>)", () => {
|
|
715
|
-
writer.line("when (value) {");
|
|
716
|
-
writer.line(" is Nullish.Some -> encoder.encodeSerializableValue(valueSerializer, value.value)");
|
|
717
|
-
writer.line(" Nullish.Null -> encoder.encodeNull()");
|
|
718
|
-
writer.line(" Nullish.Absent -> throw SerializationException(\"An absent field has no value to write, so its key is left out\")");
|
|
719
|
-
writer.line("}");
|
|
720
|
-
});
|
|
721
|
-
writer.blank();
|
|
722
|
-
writer.line("@OptIn(ExperimentalSerializationApi::class)");
|
|
723
|
-
writer.block("override fun deserialize(decoder: Decoder): Nullish<T>", () => {
|
|
724
|
-
writer.line("if (decoder.decodeNotNullMark()) return Nullish.Some(decoder.decodeSerializableValue(valueSerializer))");
|
|
725
|
-
writer.line("decoder.decodeNull()");
|
|
726
|
-
writer.line("return Nullish.Null");
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
writer.blank();
|
|
730
|
-
};
|
|
731
684
|
const defaultArgument = (field) => {
|
|
732
685
|
if (!hasDefault(field)) return "";
|
|
733
|
-
return
|
|
686
|
+
return " = null";
|
|
734
687
|
};
|
|
735
688
|
const optionalize = (type, optional) => {
|
|
736
689
|
if (!optional) return type;
|
|
@@ -752,8 +705,6 @@ const KOTLIN_PRIMITIVE_TYPES = new Set([
|
|
|
752
705
|
const decodeBody = (resolved) => resolved === "ByteArray" ? "data" : `json.decodeFromString<${resolved}>(data.decodeToString())`;
|
|
753
706
|
const resolveType = (typeName, currentOperation, context, scope = "client") => {
|
|
754
707
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
755
|
-
const nullish = NULLISH_TYPE.exec(typeName);
|
|
756
|
-
if (nullish) return `Nullish<${resolveType(nullish[1], currentOperation, context, scope)}>`;
|
|
757
708
|
const optional = typeName.endsWith("?");
|
|
758
709
|
const base = optional ? typeName.slice(0, -1) : typeName;
|
|
759
710
|
if (KOTLIN_PRIMITIVE_TYPES.has(base)) return typeName;
|
|
@@ -876,8 +827,6 @@ const emitDataClass = (writer, type, ownedTypeMap, ownedTypeLookup, registryName
|
|
|
876
827
|
const baseFields = type.discriminatorWireName ? type.fields.filter((field) => field.wireName !== type.discriminatorWireName) : type.fields;
|
|
877
828
|
const hasFile = baseFields.some((field) => field.isFile);
|
|
878
829
|
const resolveOwnedType = (raw) => {
|
|
879
|
-
const nullish = NULLISH_TYPE.exec(raw);
|
|
880
|
-
if (nullish) return `Nullish<${resolveOwnedType(nullish[1])}>`;
|
|
881
830
|
const optional = raw.endsWith("?");
|
|
882
831
|
const stripped = optional ? raw.slice(0, -1) : raw;
|
|
883
832
|
const isList = stripped.startsWith("List<") && stripped.endsWith(">");
|
|
@@ -893,15 +842,12 @@ const emitDataClass = (writer, type, ownedTypeMap, ownedTypeLookup, registryName
|
|
|
893
842
|
}));
|
|
894
843
|
const needsSerialName = !hasFile && baseFields.some((field) => field.name !== field.wireName || KOTLIN_KEYWORDS.has(field.name));
|
|
895
844
|
if (type.serialName !== void 0) writer.line(`@SerialName(${stringLiteral(type.serialName)})`);
|
|
896
|
-
if (!hasFile)
|
|
897
|
-
if (adjustedFields.some((field) => field.nullish)) writer.line("@OptIn(ExperimentalSerializationApi::class)");
|
|
898
|
-
writer.line("@Serializable");
|
|
899
|
-
}
|
|
845
|
+
if (!hasFile) writer.line("@Serializable");
|
|
900
846
|
const params = adjustedFields.map((field) => {
|
|
901
847
|
const typeExpression = optionalize(field.type, field.optional);
|
|
902
848
|
const defaultPart = defaultArgument(field);
|
|
903
849
|
const serialNameAnnotation = needsSerialName && (field.name !== field.wireName || KOTLIN_KEYWORDS.has(field.name)) ? `@SerialName(${stringLiteral(field.wireName)}) ` : "";
|
|
904
|
-
return `${field.deprecated ? `${deprecatedAnnotation(field.deprecationMessage)} ` : ""}${serialNameAnnotation}
|
|
850
|
+
return `${field.deprecated ? `${deprecatedAnnotation(field.deprecationMessage)} ` : ""}${serialNameAnnotation}val ${escapeKeyword(field.name)}: ${typeExpression}${defaultPart}`;
|
|
905
851
|
});
|
|
906
852
|
const hasOwnedTypes = Array.from(ownedTypeMap.entries()).some(([, owner]) => owner === lookupName);
|
|
907
853
|
if (params.length === 0) writer.line(`data class ${type.name}(private val unused: Unit = Unit)`);
|
|
@@ -943,8 +889,6 @@ const relativeOwnedPath = (typeName, ownedTypeMap, enclosingPath, registry) => {
|
|
|
943
889
|
return path.startsWith(prefix) ? path.slice(prefix.length) : void 0;
|
|
944
890
|
};
|
|
945
891
|
const ownedTypePath = (typeName, ownedTypeMap, registry) => {
|
|
946
|
-
const nullish = NULLISH_TYPE.exec(typeName);
|
|
947
|
-
if (nullish) return `Nullish<${ownedTypePath(nullish[1], ownedTypeMap, registry)}>`;
|
|
948
892
|
const sealedPath = registry?.sealedVariantPath(typeName);
|
|
949
893
|
if (sealedPath !== void 0) return sealedPath;
|
|
950
894
|
const owningClass = ownedTypeMap.get(typeName);
|
|
@@ -1837,7 +1781,7 @@ const renderKotlinClient = (api, partition, registry, config) => {
|
|
|
1837
1781
|
}
|
|
1838
1782
|
writer.line("import kotlinx.serialization.*");
|
|
1839
1783
|
writer.line("import kotlinx.serialization.json.*");
|
|
1840
|
-
if (registry.all().some((type) => type.kind === "enum-class" && type.unknownCase)
|
|
1784
|
+
if (registry.all().some((type) => type.kind === "enum-class" && type.unknownCase)) {
|
|
1841
1785
|
writer.line("import kotlinx.serialization.descriptors.*");
|
|
1842
1786
|
writer.line("import kotlinx.serialization.encoding.*");
|
|
1843
1787
|
}
|
|
@@ -1855,7 +1799,6 @@ const renderKotlinClient = (api, partition, registry, config) => {
|
|
|
1855
1799
|
});
|
|
1856
1800
|
writer.blank();
|
|
1857
1801
|
}
|
|
1858
|
-
if (registry.usesNullish) emitNullish(writer);
|
|
1859
1802
|
const sharedTypes = [];
|
|
1860
1803
|
const typesByOperation = /* @__PURE__ */ new Map();
|
|
1861
1804
|
for (const type of registry.all()) {
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generator = require("./generator-
|
|
2
|
+
const require_generator = require("./generator-D4SnsG2Q.cjs");
|
|
3
3
|
let kizunajs_generator = require("kizunajs/generator");
|
|
4
4
|
let zod = require("zod");
|
|
5
5
|
//#region src/client-target.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as kotlinClientWalk, t as generateKotlinClient } from "./generator-
|
|
1
|
+
import { n as kotlinClientWalk, t as generateKotlinClient } from "./generator-DT7c2Vo3.mjs";
|
|
2
2
|
import { defineClient } from "kizunajs/generator";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/kotlin",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.19",
|
|
4
4
|
"description": "Kotlin client generation for Kizuna.js APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@kizunajs/cli": "2.0.0-beta.
|
|
63
|
+
"@kizunajs/cli": "2.0.0-beta.19"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"kizunajs": "2.0.0-beta.
|
|
66
|
+
"kizunajs": "2.0.0-beta.19",
|
|
67
67
|
"zod": "^4.0.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"kizunajs": "2.0.0-beta.
|
|
70
|
+
"kizunajs": "2.0.0-beta.19",
|
|
71
71
|
"@types/node": "^22.9.0",
|
|
72
72
|
"tsdown": "^0.21.0",
|
|
73
73
|
"typescript": "^6.0.3",
|