@kizunajs/kotlin 2.0.0-beta.21 → 2.0.0-beta.23
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-Dzx9o6tA.mjs";
|
|
3
3
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
@@ -184,6 +184,8 @@ const mapUnbrandedType = (schema, registry, hint) => {
|
|
|
184
184
|
expression: "ByteArray",
|
|
185
185
|
optional: false
|
|
186
186
|
};
|
|
187
|
+
const model = (0, kizunajs_generator.readModelSchema)(schema);
|
|
188
|
+
if (model !== void 0 && model !== schema) return mapUnbrandedType(model, registry, hint);
|
|
187
189
|
const id = (0, kizunajs_generator.readMetaId)(schema);
|
|
188
190
|
const def = (0, kizunajs_generator.readDef)(schema);
|
|
189
191
|
const discriminated = (0, kizunajs_generator.readDiscriminatedUnion)(schema);
|
|
@@ -551,18 +553,23 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
|
|
|
551
553
|
successResponses.push({
|
|
552
554
|
status,
|
|
553
555
|
type: stream.messageType ?? "Event",
|
|
554
|
-
responseHeaders: headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : []
|
|
556
|
+
responseHeaders: headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : [],
|
|
557
|
+
isText: false
|
|
555
558
|
});
|
|
556
559
|
continue;
|
|
557
560
|
}
|
|
558
|
-
const
|
|
561
|
+
const bodySchema = (0, kizunajs_generator.resolveResponseBody)(responseValue);
|
|
562
|
+
const responseContentType = (0, kizunajs_generator.resolveResponseContentType)(responseValue);
|
|
563
|
+
const isText = !(0, kizunajs_generator.isBinarySchema)(bodySchema) && responseContentType !== void 0 && !(0, kizunajs_generator.isJsonMediaType)(responseContentType);
|
|
564
|
+
const typeExpression = mapType(bodySchema, registry, responseHint).expression;
|
|
559
565
|
if ((0, kizunajs_generator.isSuccessStatus)(status)) {
|
|
560
566
|
const headersSchema = (0, kizunajs_generator.resolveResponseHeaders)(responseValue);
|
|
561
567
|
const perStatusHeaderFields = headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : [];
|
|
562
568
|
successResponses.push({
|
|
563
569
|
status,
|
|
564
570
|
type: typeExpression,
|
|
565
|
-
responseHeaders: perStatusHeaderFields
|
|
571
|
+
responseHeaders: perStatusHeaderFields,
|
|
572
|
+
isText
|
|
566
573
|
});
|
|
567
574
|
} else errorCases.push({
|
|
568
575
|
caseName: (0, kizunajs_generator.statusToCamelCase)(status),
|
|
@@ -700,9 +707,12 @@ const KOTLIN_PRIMITIVE_TYPES = new Set([
|
|
|
700
707
|
"ByteArray"
|
|
701
708
|
]);
|
|
702
709
|
/**
|
|
703
|
-
* How a response body is read. Raw bytes are the body already.
|
|
710
|
+
* How a response body is read. Raw bytes are the body already, and text is its decoded bytes.
|
|
704
711
|
*/
|
|
705
|
-
const decodeBody = (resolved
|
|
712
|
+
const decodeBody = (resolved, isText = false) => {
|
|
713
|
+
if (resolved === "ByteArray") return "data";
|
|
714
|
+
return isText ? "data.decodeToString()" : `json.decodeFromString<${resolved}>(data.decodeToString())`;
|
|
715
|
+
};
|
|
706
716
|
const resolveType = (typeName, currentOperation, context, scope = "client") => {
|
|
707
717
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
708
718
|
const optional = typeName.endsWith("?");
|
|
@@ -1413,7 +1423,7 @@ const emitMethodBody = (writer, method, context) => {
|
|
|
1413
1423
|
writer.indent(() => {
|
|
1414
1424
|
const resolved = resolveType(successResponse.type, method.operationName, context);
|
|
1415
1425
|
writer.block("try", () => {
|
|
1416
|
-
writer.line(`val payload = ${decodeBody(resolved)}`);
|
|
1426
|
+
writer.line(`val payload = ${decodeBody(resolved, successResponse.isText)}`);
|
|
1417
1427
|
const bodyExpr = isMultiSuccess ? `${operationRef}.Success.Status${successResponse.status}(payload)` : "payload";
|
|
1418
1428
|
if (hasHeaders) {
|
|
1419
1429
|
for (const field of successResponse.responseHeaders) writer.line(`val ${escapeKeyword(field.name)} = httpResponse.header(${stringLiteral(field.wireName)})`);
|
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
1
|
+
import { isBinarySchema, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isJsonMediaType, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorStringLiteral, readMetaBrand, readMetaDescription, readMetaId, readModelSchema, readObjectShape, resolveResponseBody, resolveResponseContentType, 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 = [];
|
|
@@ -184,6 +184,8 @@ const mapUnbrandedType = (schema, registry, hint) => {
|
|
|
184
184
|
expression: "ByteArray",
|
|
185
185
|
optional: false
|
|
186
186
|
};
|
|
187
|
+
const model = readModelSchema(schema);
|
|
188
|
+
if (model !== void 0 && model !== schema) return mapUnbrandedType(model, registry, hint);
|
|
187
189
|
const id = readMetaId(schema);
|
|
188
190
|
const def = readDef(schema);
|
|
189
191
|
const discriminated = readDiscriminatedUnion(schema);
|
|
@@ -551,18 +553,23 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
|
|
|
551
553
|
successResponses.push({
|
|
552
554
|
status,
|
|
553
555
|
type: stream.messageType ?? "Event",
|
|
554
|
-
responseHeaders: headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : []
|
|
556
|
+
responseHeaders: headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : [],
|
|
557
|
+
isText: false
|
|
555
558
|
});
|
|
556
559
|
continue;
|
|
557
560
|
}
|
|
558
|
-
const
|
|
561
|
+
const bodySchema = resolveResponseBody(responseValue);
|
|
562
|
+
const responseContentType = resolveResponseContentType(responseValue);
|
|
563
|
+
const isText = !isBinarySchema(bodySchema) && responseContentType !== void 0 && !isJsonMediaType(responseContentType);
|
|
564
|
+
const typeExpression = mapType(bodySchema, registry, responseHint).expression;
|
|
559
565
|
if (isSuccessStatus(status)) {
|
|
560
566
|
const headersSchema = resolveResponseHeaders(responseValue);
|
|
561
567
|
const perStatusHeaderFields = headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : [];
|
|
562
568
|
successResponses.push({
|
|
563
569
|
status,
|
|
564
570
|
type: typeExpression,
|
|
565
|
-
responseHeaders: perStatusHeaderFields
|
|
571
|
+
responseHeaders: perStatusHeaderFields,
|
|
572
|
+
isText
|
|
566
573
|
});
|
|
567
574
|
} else errorCases.push({
|
|
568
575
|
caseName: statusToCamelCase(status),
|
|
@@ -700,9 +707,12 @@ const KOTLIN_PRIMITIVE_TYPES = new Set([
|
|
|
700
707
|
"ByteArray"
|
|
701
708
|
]);
|
|
702
709
|
/**
|
|
703
|
-
* How a response body is read. Raw bytes are the body already.
|
|
710
|
+
* How a response body is read. Raw bytes are the body already, and text is its decoded bytes.
|
|
704
711
|
*/
|
|
705
|
-
const decodeBody = (resolved
|
|
712
|
+
const decodeBody = (resolved, isText = false) => {
|
|
713
|
+
if (resolved === "ByteArray") return "data";
|
|
714
|
+
return isText ? "data.decodeToString()" : `json.decodeFromString<${resolved}>(data.decodeToString())`;
|
|
715
|
+
};
|
|
706
716
|
const resolveType = (typeName, currentOperation, context, scope = "client") => {
|
|
707
717
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
708
718
|
const optional = typeName.endsWith("?");
|
|
@@ -1413,7 +1423,7 @@ const emitMethodBody = (writer, method, context) => {
|
|
|
1413
1423
|
writer.indent(() => {
|
|
1414
1424
|
const resolved = resolveType(successResponse.type, method.operationName, context);
|
|
1415
1425
|
writer.block("try", () => {
|
|
1416
|
-
writer.line(`val payload = ${decodeBody(resolved)}`);
|
|
1426
|
+
writer.line(`val payload = ${decodeBody(resolved, successResponse.isText)}`);
|
|
1417
1427
|
const bodyExpr = isMultiSuccess ? `${operationRef}.Success.Status${successResponse.status}(payload)` : "payload";
|
|
1418
1428
|
if (hasHeaders) {
|
|
1419
1429
|
for (const field of successResponse.responseHeaders) writer.line(`val ${escapeKeyword(field.name)} = httpResponse.header(${stringLiteral(field.wireName)})`);
|
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-CNG65QK6.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-Dzx9o6tA.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.23",
|
|
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.23"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"kizunajs": "2.0.0-beta.
|
|
66
|
+
"kizunajs": "2.0.0-beta.23",
|
|
67
67
|
"zod": "^4.0.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"kizunajs": "2.0.0-beta.
|
|
70
|
+
"kizunajs": "2.0.0-beta.23",
|
|
71
71
|
"@types/node": "^22.9.0",
|
|
72
72
|
"tsdown": "^0.21.0",
|
|
73
73
|
"typescript": "^6.0.3",
|