@kizunajs/kotlin 2.0.0-beta.21 → 2.0.0-beta.22
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-oVr_SgXs.mjs";
|
|
3
3
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
@@ -551,18 +551,23 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
|
|
|
551
551
|
successResponses.push({
|
|
552
552
|
status,
|
|
553
553
|
type: stream.messageType ?? "Event",
|
|
554
|
-
responseHeaders: headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : []
|
|
554
|
+
responseHeaders: headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : [],
|
|
555
|
+
isText: false
|
|
555
556
|
});
|
|
556
557
|
continue;
|
|
557
558
|
}
|
|
558
|
-
const
|
|
559
|
+
const bodySchema = (0, kizunajs_generator.resolveResponseBody)(responseValue);
|
|
560
|
+
const responseContentType = (0, kizunajs_generator.resolveResponseContentType)(responseValue);
|
|
561
|
+
const isText = !(0, kizunajs_generator.isBinarySchema)(bodySchema) && responseContentType !== void 0 && !(0, kizunajs_generator.isJsonMediaType)(responseContentType);
|
|
562
|
+
const typeExpression = mapType(bodySchema, registry, responseHint).expression;
|
|
559
563
|
if ((0, kizunajs_generator.isSuccessStatus)(status)) {
|
|
560
564
|
const headersSchema = (0, kizunajs_generator.resolveResponseHeaders)(responseValue);
|
|
561
565
|
const perStatusHeaderFields = headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : [];
|
|
562
566
|
successResponses.push({
|
|
563
567
|
status,
|
|
564
568
|
type: typeExpression,
|
|
565
|
-
responseHeaders: perStatusHeaderFields
|
|
569
|
+
responseHeaders: perStatusHeaderFields,
|
|
570
|
+
isText
|
|
566
571
|
});
|
|
567
572
|
} else errorCases.push({
|
|
568
573
|
caseName: (0, kizunajs_generator.statusToCamelCase)(status),
|
|
@@ -700,9 +705,12 @@ const KOTLIN_PRIMITIVE_TYPES = new Set([
|
|
|
700
705
|
"ByteArray"
|
|
701
706
|
]);
|
|
702
707
|
/**
|
|
703
|
-
* How a response body is read. Raw bytes are the body already.
|
|
708
|
+
* How a response body is read. Raw bytes are the body already, and text is its decoded bytes.
|
|
704
709
|
*/
|
|
705
|
-
const decodeBody = (resolved
|
|
710
|
+
const decodeBody = (resolved, isText = false) => {
|
|
711
|
+
if (resolved === "ByteArray") return "data";
|
|
712
|
+
return isText ? "data.decodeToString()" : `json.decodeFromString<${resolved}>(data.decodeToString())`;
|
|
713
|
+
};
|
|
706
714
|
const resolveType = (typeName, currentOperation, context, scope = "client") => {
|
|
707
715
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
708
716
|
const optional = typeName.endsWith("?");
|
|
@@ -1413,7 +1421,7 @@ const emitMethodBody = (writer, method, context) => {
|
|
|
1413
1421
|
writer.indent(() => {
|
|
1414
1422
|
const resolved = resolveType(successResponse.type, method.operationName, context);
|
|
1415
1423
|
writer.block("try", () => {
|
|
1416
|
-
writer.line(`val payload = ${decodeBody(resolved)}`);
|
|
1424
|
+
writer.line(`val payload = ${decodeBody(resolved, successResponse.isText)}`);
|
|
1417
1425
|
const bodyExpr = isMultiSuccess ? `${operationRef}.Success.Status${successResponse.status}(payload)` : "payload";
|
|
1418
1426
|
if (hasHeaders) {
|
|
1419
1427
|
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, 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 = [];
|
|
@@ -551,18 +551,23 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
|
|
|
551
551
|
successResponses.push({
|
|
552
552
|
status,
|
|
553
553
|
type: stream.messageType ?? "Event",
|
|
554
|
-
responseHeaders: headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : []
|
|
554
|
+
responseHeaders: headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : [],
|
|
555
|
+
isText: false
|
|
555
556
|
});
|
|
556
557
|
continue;
|
|
557
558
|
}
|
|
558
|
-
const
|
|
559
|
+
const bodySchema = resolveResponseBody(responseValue);
|
|
560
|
+
const responseContentType = resolveResponseContentType(responseValue);
|
|
561
|
+
const isText = !isBinarySchema(bodySchema) && responseContentType !== void 0 && !isJsonMediaType(responseContentType);
|
|
562
|
+
const typeExpression = mapType(bodySchema, registry, responseHint).expression;
|
|
559
563
|
if (isSuccessStatus(status)) {
|
|
560
564
|
const headersSchema = resolveResponseHeaders(responseValue);
|
|
561
565
|
const perStatusHeaderFields = headersSchema ? collectObjectFields(headersSchema, registry, `${baseHint}ResponseHeaders`) : [];
|
|
562
566
|
successResponses.push({
|
|
563
567
|
status,
|
|
564
568
|
type: typeExpression,
|
|
565
|
-
responseHeaders: perStatusHeaderFields
|
|
569
|
+
responseHeaders: perStatusHeaderFields,
|
|
570
|
+
isText
|
|
566
571
|
});
|
|
567
572
|
} else errorCases.push({
|
|
568
573
|
caseName: statusToCamelCase(status),
|
|
@@ -700,9 +705,12 @@ const KOTLIN_PRIMITIVE_TYPES = new Set([
|
|
|
700
705
|
"ByteArray"
|
|
701
706
|
]);
|
|
702
707
|
/**
|
|
703
|
-
* How a response body is read. Raw bytes are the body already.
|
|
708
|
+
* How a response body is read. Raw bytes are the body already, and text is its decoded bytes.
|
|
704
709
|
*/
|
|
705
|
-
const decodeBody = (resolved
|
|
710
|
+
const decodeBody = (resolved, isText = false) => {
|
|
711
|
+
if (resolved === "ByteArray") return "data";
|
|
712
|
+
return isText ? "data.decodeToString()" : `json.decodeFromString<${resolved}>(data.decodeToString())`;
|
|
713
|
+
};
|
|
706
714
|
const resolveType = (typeName, currentOperation, context, scope = "client") => {
|
|
707
715
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
708
716
|
const optional = typeName.endsWith("?");
|
|
@@ -1413,7 +1421,7 @@ const emitMethodBody = (writer, method, context) => {
|
|
|
1413
1421
|
writer.indent(() => {
|
|
1414
1422
|
const resolved = resolveType(successResponse.type, method.operationName, context);
|
|
1415
1423
|
writer.block("try", () => {
|
|
1416
|
-
writer.line(`val payload = ${decodeBody(resolved)}`);
|
|
1424
|
+
writer.line(`val payload = ${decodeBody(resolved, successResponse.isText)}`);
|
|
1417
1425
|
const bodyExpr = isMultiSuccess ? `${operationRef}.Success.Status${successResponse.status}(payload)` : "payload";
|
|
1418
1426
|
if (hasHeaders) {
|
|
1419
1427
|
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-DGtAlheu.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-oVr_SgXs.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.22",
|
|
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.22"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"kizunajs": "2.0.0-beta.
|
|
66
|
+
"kizunajs": "2.0.0-beta.22",
|
|
67
67
|
"zod": "^4.0.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"kizunajs": "2.0.0-beta.
|
|
70
|
+
"kizunajs": "2.0.0-beta.22",
|
|
71
71
|
"@types/node": "^22.9.0",
|
|
72
72
|
"tsdown": "^0.21.0",
|
|
73
73
|
"typescript": "^6.0.3",
|