@kizunajs/kotlin 2.0.0-beta.12 → 2.0.0-beta.13
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-BYxosxwy.mjs";
|
|
3
3
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isBinarySchema, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorStringLiteral, readMetaDescription, readMetaId, readObjectShape, resolveResponseBody, resolveResponseHeaders, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamMode, toCamelCase, toPascalCase, unwrapOptionalWrappers, walkApi } from "kizunajs/generator";
|
|
1
|
+
import { isBinarySchema, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorStringLiteral, readMetaBrand, readMetaDescription, readMetaId, readObjectShape, resolveResponseBody, resolveResponseHeaders, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamMode, toCamelCase, toPascalCase, unwrapOptionalWrappers, walkApi } from "kizunajs/generator";
|
|
2
2
|
//#region src/emit.ts
|
|
3
3
|
var KotlinWriter = class {
|
|
4
4
|
lines = [];
|
|
@@ -56,6 +56,7 @@ var TypeRegistry = class {
|
|
|
56
56
|
explicitIds = /* @__PURE__ */ new Set();
|
|
57
57
|
sealedVariantPayloads = /* @__PURE__ */ new Set();
|
|
58
58
|
sealedVariantPaths = /* @__PURE__ */ new Map();
|
|
59
|
+
brands = /* @__PURE__ */ new Map();
|
|
59
60
|
usesJsonElement = false;
|
|
60
61
|
constructor(camelCaseProperties = false, unknownEnumCase = false) {
|
|
61
62
|
this.camelCaseProperties = camelCaseProperties;
|
|
@@ -99,6 +100,15 @@ var TypeRegistry = class {
|
|
|
99
100
|
sealedVariantPath(name) {
|
|
100
101
|
return this.sealedVariantPaths.get(name);
|
|
101
102
|
}
|
|
103
|
+
addBrand(brand) {
|
|
104
|
+
const existing = this.brands.get(brand.name);
|
|
105
|
+
if (existing !== void 0 && existing.rawType !== brand.rawType) throw new Error(`@kizunajs/kotlin: brand ${stringify(brand.name)} wraps both ${existing.rawType} and ${brand.rawType}. Give each its own name.`);
|
|
106
|
+
if (this.types.has(brand.name)) throw new Error(`@kizunajs/kotlin: brand ${stringify(brand.name)} has the same name as a model. Give each its own name.`);
|
|
107
|
+
this.brands.set(brand.name, brand);
|
|
108
|
+
}
|
|
109
|
+
allBrands() {
|
|
110
|
+
return Array.from(this.brands.values());
|
|
111
|
+
}
|
|
102
112
|
warnJsonElement(hint, reason) {
|
|
103
113
|
this.usesJsonElement = true;
|
|
104
114
|
this.warningSet.add(`${hint}: ${reason}`);
|
|
@@ -141,7 +151,29 @@ const objectFields = (schema, registry, hint, shape = readObjectShape(schema) ??
|
|
|
141
151
|
return fields;
|
|
142
152
|
};
|
|
143
153
|
const stringify = (value) => JSON.stringify(value);
|
|
154
|
+
const BRANDABLE_TYPES = new Set([
|
|
155
|
+
"String",
|
|
156
|
+
"Int",
|
|
157
|
+
"Long",
|
|
158
|
+
"Double",
|
|
159
|
+
"Boolean",
|
|
160
|
+
"Instant"
|
|
161
|
+
]);
|
|
144
162
|
const mapType = (schema, registry, hint) => {
|
|
163
|
+
const result = mapUnbrandedType(schema, registry, hint);
|
|
164
|
+
const brand = readMetaBrand(schema);
|
|
165
|
+
if (brand === void 0 || !BRANDABLE_TYPES.has(result.expression)) return result;
|
|
166
|
+
const name = sanitizeIdentifier(brand);
|
|
167
|
+
registry.addBrand({
|
|
168
|
+
name,
|
|
169
|
+
rawType: result.expression
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
expression: name,
|
|
173
|
+
optional: false
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const mapUnbrandedType = (schema, registry, hint) => {
|
|
145
177
|
if (isFileSchema(schema)) return {
|
|
146
178
|
expression: "MultipartFile",
|
|
147
179
|
optional: false,
|
|
@@ -936,6 +968,16 @@ const emitType = (writer, type, ownedTypeMap = /* @__PURE__ */ new Map(), ownedT
|
|
|
936
968
|
else if (type.kind === "enum-class") emitEnumClass(writer, type.name, type.cases, type.unknownCase, type.description);
|
|
937
969
|
else if (registry) emitSealedClass(writer, type, registry, ownedTypeMap, ownedTypeLookup);
|
|
938
970
|
};
|
|
971
|
+
/**
|
|
972
|
+
* A brand as a value class that serializes and prints as the bare value.
|
|
973
|
+
*/
|
|
974
|
+
const emitBrand = (writer, brand) => {
|
|
975
|
+
writer.line("@Serializable");
|
|
976
|
+
writer.line("@JvmInline");
|
|
977
|
+
writer.block(`value class ${brand.name}(val value: ${brand.rawType})`, () => {
|
|
978
|
+
writer.line(`override fun toString(): String = ${brand.rawType === "String" ? "value" : "value.toString()"}`);
|
|
979
|
+
});
|
|
980
|
+
};
|
|
939
981
|
const emitTypes = (writer, types, ownedTypeMap = /* @__PURE__ */ new Map(), ownedTypeLookup = /* @__PURE__ */ new Map(), registry) => {
|
|
940
982
|
for (const type of types) emitType(writer, type, ownedTypeMap, ownedTypeLookup, void 0, registry);
|
|
941
983
|
};
|
|
@@ -1785,6 +1827,10 @@ const renderKotlinClient = (api, partition, registry, config) => {
|
|
|
1785
1827
|
};
|
|
1786
1828
|
writer.block(`object ${namespaceName}`, () => {
|
|
1787
1829
|
emitTypes(writer, topLevelSharedTypes, ownedTypeMap, ownedTypeLookup, registry);
|
|
1830
|
+
for (const brand of registry.allBrands()) {
|
|
1831
|
+
writer.blank();
|
|
1832
|
+
emitBrand(writer, brand);
|
|
1833
|
+
}
|
|
1788
1834
|
});
|
|
1789
1835
|
emitClient(writer, { clientName }, partition, context, typesByOperation, registry);
|
|
1790
1836
|
for (const group of partition.groups) emitSubClientClass(writer, group, clientName, context);
|
|
@@ -56,6 +56,7 @@ var TypeRegistry = class {
|
|
|
56
56
|
explicitIds = /* @__PURE__ */ new Set();
|
|
57
57
|
sealedVariantPayloads = /* @__PURE__ */ new Set();
|
|
58
58
|
sealedVariantPaths = /* @__PURE__ */ new Map();
|
|
59
|
+
brands = /* @__PURE__ */ new Map();
|
|
59
60
|
usesJsonElement = false;
|
|
60
61
|
constructor(camelCaseProperties = false, unknownEnumCase = false) {
|
|
61
62
|
this.camelCaseProperties = camelCaseProperties;
|
|
@@ -99,6 +100,15 @@ var TypeRegistry = class {
|
|
|
99
100
|
sealedVariantPath(name) {
|
|
100
101
|
return this.sealedVariantPaths.get(name);
|
|
101
102
|
}
|
|
103
|
+
addBrand(brand) {
|
|
104
|
+
const existing = this.brands.get(brand.name);
|
|
105
|
+
if (existing !== void 0 && existing.rawType !== brand.rawType) throw new Error(`@kizunajs/kotlin: brand ${stringify(brand.name)} wraps both ${existing.rawType} and ${brand.rawType}. Give each its own name.`);
|
|
106
|
+
if (this.types.has(brand.name)) throw new Error(`@kizunajs/kotlin: brand ${stringify(brand.name)} has the same name as a model. Give each its own name.`);
|
|
107
|
+
this.brands.set(brand.name, brand);
|
|
108
|
+
}
|
|
109
|
+
allBrands() {
|
|
110
|
+
return Array.from(this.brands.values());
|
|
111
|
+
}
|
|
102
112
|
warnJsonElement(hint, reason) {
|
|
103
113
|
this.usesJsonElement = true;
|
|
104
114
|
this.warningSet.add(`${hint}: ${reason}`);
|
|
@@ -141,7 +151,29 @@ const objectFields = (schema, registry, hint, shape = (0, kizunajs_generator.rea
|
|
|
141
151
|
return fields;
|
|
142
152
|
};
|
|
143
153
|
const stringify = (value) => JSON.stringify(value);
|
|
154
|
+
const BRANDABLE_TYPES = new Set([
|
|
155
|
+
"String",
|
|
156
|
+
"Int",
|
|
157
|
+
"Long",
|
|
158
|
+
"Double",
|
|
159
|
+
"Boolean",
|
|
160
|
+
"Instant"
|
|
161
|
+
]);
|
|
144
162
|
const mapType = (schema, registry, hint) => {
|
|
163
|
+
const result = mapUnbrandedType(schema, registry, hint);
|
|
164
|
+
const brand = (0, kizunajs_generator.readMetaBrand)(schema);
|
|
165
|
+
if (brand === void 0 || !BRANDABLE_TYPES.has(result.expression)) return result;
|
|
166
|
+
const name = (0, kizunajs_generator.sanitizeIdentifier)(brand);
|
|
167
|
+
registry.addBrand({
|
|
168
|
+
name,
|
|
169
|
+
rawType: result.expression
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
expression: name,
|
|
173
|
+
optional: false
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const mapUnbrandedType = (schema, registry, hint) => {
|
|
145
177
|
if ((0, kizunajs_generator.isFileSchema)(schema)) return {
|
|
146
178
|
expression: "MultipartFile",
|
|
147
179
|
optional: false,
|
|
@@ -936,6 +968,16 @@ const emitType = (writer, type, ownedTypeMap = /* @__PURE__ */ new Map(), ownedT
|
|
|
936
968
|
else if (type.kind === "enum-class") emitEnumClass(writer, type.name, type.cases, type.unknownCase, type.description);
|
|
937
969
|
else if (registry) emitSealedClass(writer, type, registry, ownedTypeMap, ownedTypeLookup);
|
|
938
970
|
};
|
|
971
|
+
/**
|
|
972
|
+
* A brand as a value class that serializes and prints as the bare value.
|
|
973
|
+
*/
|
|
974
|
+
const emitBrand = (writer, brand) => {
|
|
975
|
+
writer.line("@Serializable");
|
|
976
|
+
writer.line("@JvmInline");
|
|
977
|
+
writer.block(`value class ${brand.name}(val value: ${brand.rawType})`, () => {
|
|
978
|
+
writer.line(`override fun toString(): String = ${brand.rawType === "String" ? "value" : "value.toString()"}`);
|
|
979
|
+
});
|
|
980
|
+
};
|
|
939
981
|
const emitTypes = (writer, types, ownedTypeMap = /* @__PURE__ */ new Map(), ownedTypeLookup = /* @__PURE__ */ new Map(), registry) => {
|
|
940
982
|
for (const type of types) emitType(writer, type, ownedTypeMap, ownedTypeLookup, void 0, registry);
|
|
941
983
|
};
|
|
@@ -1785,6 +1827,10 @@ const renderKotlinClient = (api, partition, registry, config) => {
|
|
|
1785
1827
|
};
|
|
1786
1828
|
writer.block(`object ${namespaceName}`, () => {
|
|
1787
1829
|
emitTypes(writer, topLevelSharedTypes, ownedTypeMap, ownedTypeLookup, registry);
|
|
1830
|
+
for (const brand of registry.allBrands()) {
|
|
1831
|
+
writer.blank();
|
|
1832
|
+
emitBrand(writer, brand);
|
|
1833
|
+
}
|
|
1788
1834
|
});
|
|
1789
1835
|
emitClient(writer, { clientName }, partition, context, typesByOperation, registry);
|
|
1790
1836
|
for (const group of partition.groups) emitSubClientClass(writer, group, clientName, context);
|
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-D2dgwOZe.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-BYxosxwy.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.13",
|
|
4
4
|
"description": "Kotlin client generation for Kizuna.js APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -60,18 +60,18 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@kizunajs/cli": "2.0.0-beta.
|
|
63
|
+
"@kizunajs/cli": "2.0.0-beta.13"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"zod": "^4.0.0",
|
|
67
|
-
"kizunajs": "2.0.0-beta.
|
|
67
|
+
"kizunajs": "2.0.0-beta.13"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/node": "^22.9.0",
|
|
71
71
|
"tsdown": "^0.21.0",
|
|
72
72
|
"typescript": "^6.0.3",
|
|
73
73
|
"zod": "^4.0.0",
|
|
74
|
-
"kizunajs": "2.0.0-beta.
|
|
74
|
+
"kizunajs": "2.0.0-beta.13"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"build": "tsdown src/index.ts src/cli.ts --format esm,cjs --dts --clean --external kizunajs --external @kizunajs/cli --external zod",
|