@kizunajs/kotlin 2.0.0-beta.10 → 2.0.0-beta.12

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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_generator = require("./generator-CefUI7SC.cjs");
2
+ const require_generator = require("./generator-Cs9NkTCg.cjs");
3
3
  let node_fs = require("node:fs");
4
4
  let node_path = require("node:path");
5
5
  let node_util = require("node:util");
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as generateKotlinClient } from "./generator-Ct5OmESk.mjs";
2
+ import { t as generateKotlinClient } from "./generator-uzHpr6im.mjs";
3
3
  import { mkdirSync, writeFileSync } from "node:fs";
4
4
  import { dirname, resolve } from "node:path";
5
5
  import { parseArgs } from "node:util";
@@ -580,7 +580,7 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
580
580
  stream
581
581
  };
582
582
  };
583
- const kotlinGenerator = (0, kizunajs_generator.createGenerator)((options, _api) => {
583
+ const kotlinRoutesWalk = (options) => {
584
584
  const flatMethods = [];
585
585
  const groupMap = /* @__PURE__ */ new Map();
586
586
  return {
@@ -612,7 +612,7 @@ const kotlinGenerator = (0, kizunajs_generator.createGenerator)((options, _api)
612
612
  };
613
613
  }
614
614
  };
615
- });
615
+ };
616
616
  const KOTLIN_KEYWORDS = new Set([
617
617
  "as",
618
618
  "break",
@@ -1699,21 +1699,8 @@ const emitClient = (writer, config, partition, context, typesByOperation, regist
1699
1699
  }
1700
1700
  });
1701
1701
  };
1702
- /**
1703
- * Generate a Kotlin API client from a Kizuna api.
1704
- *
1705
- * @param api - What `defineConfig` assembled.
1706
- * @param config - Override the generated names:
1707
- * - `namespaceName`: the object wrapping shared types.
1708
- * - `packageName`: optional package declaration for the generated file.
1709
- */
1710
- const generateKotlinClient = (api, config) => {
1711
- const { namespaceName, packageName, camelCaseProperties = false, unknownEnumCase = false } = config;
1712
- const registry = new TypeRegistry(camelCaseProperties, unknownEnumCase);
1713
- const partition = kotlinGenerator(api, {
1714
- namespaceName,
1715
- registry
1716
- });
1702
+ const renderKotlinClient = (api, partition, registry, config) => {
1703
+ const { namespaceName, packageName, camelCaseProperties = false } = config;
1717
1704
  const allMethods = [...partition.flatMethods, ...partition.groups.flatMap((group) => group.methods)];
1718
1705
  const operationTypeMap = buildOperationTypeMap(allMethods, registry);
1719
1706
  const clientName = `${namespaceName}Client`;
@@ -1805,6 +1792,29 @@ const generateKotlinClient = (api, config) => {
1805
1792
  for (const warning of registry.warnings()) process.stderr.write(`[kizuna/kotlin] JsonElement fallback at ${warning}\n`);
1806
1793
  return writer.toString();
1807
1794
  };
1795
+ /**
1796
+ * The Kotlin client's walk: the routes into a partition, then the file.
1797
+ */
1798
+ const kotlinClientWalk = (api, config) => {
1799
+ const registry = new TypeRegistry(config.camelCaseProperties ?? false, config.unknownEnumCase ?? false);
1800
+ const routes = kotlinRoutesWalk({
1801
+ namespaceName: config.namespaceName,
1802
+ registry
1803
+ });
1804
+ return {
1805
+ processRoute: routes.processRoute,
1806
+ finalize: () => renderKotlinClient(api, routes.finalize(), registry, config)
1807
+ };
1808
+ };
1809
+ /**
1810
+ * Generate a Kotlin API client from a Kizuna api.
1811
+ *
1812
+ * @param api - What `defineConfig` assembled.
1813
+ * @param config - Override the generated names:
1814
+ * - `namespaceName`: the object wrapping shared types.
1815
+ * - `packageName`: optional package declaration for the generated file.
1816
+ */
1817
+ const generateKotlinClient = (api, config) => (0, kizunajs_generator.walkApi)(api, kotlinClientWalk(api, config), { skipHidden: true });
1808
1818
  //#endregion
1809
1819
  Object.defineProperty(exports, "generateKotlinClient", {
1810
1820
  enumerable: true,
@@ -1812,3 +1822,9 @@ Object.defineProperty(exports, "generateKotlinClient", {
1812
1822
  return generateKotlinClient;
1813
1823
  }
1814
1824
  });
1825
+ Object.defineProperty(exports, "kotlinClientWalk", {
1826
+ enumerable: true,
1827
+ get: function() {
1828
+ return kotlinClientWalk;
1829
+ }
1830
+ });
@@ -1,4 +1,4 @@
1
- import { createGenerator, 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 } from "kizunajs/generator";
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";
2
2
  //#region src/emit.ts
3
3
  var KotlinWriter = class {
4
4
  lines = [];
@@ -580,7 +580,7 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
580
580
  stream
581
581
  };
582
582
  };
583
- const kotlinGenerator = createGenerator((options, _api) => {
583
+ const kotlinRoutesWalk = (options) => {
584
584
  const flatMethods = [];
585
585
  const groupMap = /* @__PURE__ */ new Map();
586
586
  return {
@@ -612,7 +612,7 @@ const kotlinGenerator = createGenerator((options, _api) => {
612
612
  };
613
613
  }
614
614
  };
615
- });
615
+ };
616
616
  const KOTLIN_KEYWORDS = new Set([
617
617
  "as",
618
618
  "break",
@@ -1699,21 +1699,8 @@ const emitClient = (writer, config, partition, context, typesByOperation, regist
1699
1699
  }
1700
1700
  });
1701
1701
  };
1702
- /**
1703
- * Generate a Kotlin API client from a Kizuna api.
1704
- *
1705
- * @param api - What `defineConfig` assembled.
1706
- * @param config - Override the generated names:
1707
- * - `namespaceName`: the object wrapping shared types.
1708
- * - `packageName`: optional package declaration for the generated file.
1709
- */
1710
- const generateKotlinClient = (api, config) => {
1711
- const { namespaceName, packageName, camelCaseProperties = false, unknownEnumCase = false } = config;
1712
- const registry = new TypeRegistry(camelCaseProperties, unknownEnumCase);
1713
- const partition = kotlinGenerator(api, {
1714
- namespaceName,
1715
- registry
1716
- });
1702
+ const renderKotlinClient = (api, partition, registry, config) => {
1703
+ const { namespaceName, packageName, camelCaseProperties = false } = config;
1717
1704
  const allMethods = [...partition.flatMethods, ...partition.groups.flatMap((group) => group.methods)];
1718
1705
  const operationTypeMap = buildOperationTypeMap(allMethods, registry);
1719
1706
  const clientName = `${namespaceName}Client`;
@@ -1805,5 +1792,28 @@ const generateKotlinClient = (api, config) => {
1805
1792
  for (const warning of registry.warnings()) process.stderr.write(`[kizuna/kotlin] JsonElement fallback at ${warning}\n`);
1806
1793
  return writer.toString();
1807
1794
  };
1795
+ /**
1796
+ * The Kotlin client's walk: the routes into a partition, then the file.
1797
+ */
1798
+ const kotlinClientWalk = (api, config) => {
1799
+ const registry = new TypeRegistry(config.camelCaseProperties ?? false, config.unknownEnumCase ?? false);
1800
+ const routes = kotlinRoutesWalk({
1801
+ namespaceName: config.namespaceName,
1802
+ registry
1803
+ });
1804
+ return {
1805
+ processRoute: routes.processRoute,
1806
+ finalize: () => renderKotlinClient(api, routes.finalize(), registry, config)
1807
+ };
1808
+ };
1809
+ /**
1810
+ * Generate a Kotlin API client from a Kizuna api.
1811
+ *
1812
+ * @param api - What `defineConfig` assembled.
1813
+ * @param config - Override the generated names:
1814
+ * - `namespaceName`: the object wrapping shared types.
1815
+ * - `packageName`: optional package declaration for the generated file.
1816
+ */
1817
+ const generateKotlinClient = (api, config) => walkApi(api, kotlinClientWalk(api, config), { skipHidden: true });
1808
1818
  //#endregion
1809
- export { generateKotlinClient as t };
1819
+ export { kotlinClientWalk as n, generateKotlinClient as t };
package/dist/index.cjs CHANGED
@@ -1,17 +1,48 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_generator = require("./generator-CefUI7SC.cjs");
2
+ const require_generator = require("./generator-Cs9NkTCg.cjs");
3
+ let kizunajs_generator = require("kizunajs/generator");
4
+ let zod = require("zod");
3
5
  //#region src/client-target.ts
6
+ const KotlinClientOptionsSchema = zod.z.object({
7
+ /**
8
+ * Name of the generated namespace object.
9
+ *
10
+ * @default 'API'
11
+ */
12
+ namespace: zod.z.string().default("API"),
13
+ /**
14
+ * Package declaration for the generated file, e.g. `com.example.api`.
15
+ */
16
+ package: zod.z.string().optional(),
17
+ /**
18
+ * Convert wire field names to camelCase properties, mapping the wire name
19
+ * back via `@SerialName`.
20
+ *
21
+ * @default false
22
+ */
23
+ camelCaseProperties: zod.z.boolean().optional(),
24
+ /**
25
+ * Give every enum an `unknown` case, so a value the client has not been
26
+ * generated for decodes instead of throwing.
27
+ *
28
+ * @default false
29
+ */
30
+ unknownEnumCase: zod.z.boolean().optional()
31
+ });
4
32
  /**
5
- * A Kotlin client target for `kizuna.config.ts`.
33
+ * A Kotlin client for `kizuna.config.ts`.
6
34
  *
7
35
  * @example
8
- * kotlinClient({ output: './api/APIClient.kt', package: 'com.example.api' });
36
+ * kotlinClient({
37
+ * output: './api/APIClient.kt',
38
+ * package: 'com.example.api',
39
+ * });
9
40
  */
10
- const kotlinClient = (options) => ({
11
- kind: "kotlin",
12
- output: options.output,
13
- generate: (contract) => require_generator.generateKotlinClient(contract, {
14
- namespaceName: options.namespace ?? "API",
41
+ const kotlinClient = (0, kizunajs_generator.defineClient)({
42
+ target: "kotlin",
43
+ options: KotlinClientOptionsSchema,
44
+ generate: ({ options, api }) => require_generator.kotlinClientWalk(api, {
45
+ namespaceName: options.namespace,
15
46
  packageName: options.package,
16
47
  camelCaseProperties: options.camelCaseProperties,
17
48
  unknownEnumCase: options.unknownEnumCase
package/dist/index.d.cts CHANGED
@@ -1,4 +1,7 @@
1
- import { ApiDefinition, ClientTarget } from "kizunajs";
1
+ import { GeneratedFileOptions } from "kizunajs/generator";
2
+ import * as _$kizunajs from "kizunajs";
3
+ import { ApiDefinition } from "kizunajs";
4
+ import { z } from "zod";
2
5
 
3
6
  //#region src/generator.d.ts
4
7
  interface KotlinConfig {
@@ -38,45 +41,30 @@ interface KotlinConfig {
38
41
  declare const generateKotlinClient: (api: ApiDefinition, config: KotlinConfig) => string;
39
42
  //#endregion
40
43
  //#region src/client-target.d.ts
44
+ declare const KotlinClientOptionsSchema: z.ZodObject<{
45
+ namespace: z.ZodDefault<z.ZodString>;
46
+ package: z.ZodOptional<z.ZodString>;
47
+ camelCaseProperties: z.ZodOptional<z.ZodBoolean>;
48
+ unknownEnumCase: z.ZodOptional<z.ZodBoolean>;
49
+ }, z.core.$strip>;
41
50
  /**
42
51
  * Where a generated Kotlin client is written, and what it is called there.
43
52
  */
44
- interface KotlinClientOptions {
45
- /**
46
- * Path the generated file is written to.
47
- */
48
- output: string;
49
- /**
50
- * Name of the generated namespace object.
51
- *
52
- * @default 'API'
53
- */
54
- namespace?: string;
55
- /**
56
- * Package declaration for the generated file, e.g. `com.example.api`.
57
- */
58
- package?: string;
59
- /**
60
- * Convert wire field names to camelCase properties, mapping the wire name
61
- * back via `@SerialName`.
62
- *
63
- * @default false
64
- */
65
- camelCaseProperties?: boolean;
66
- /**
67
- * Give every enum an `unknown` case, so a value the client has not been
68
- * generated for decodes instead of throwing.
69
- *
70
- * @default false
71
- */
72
- unknownEnumCase?: boolean;
73
- }
53
+ type KotlinClientOptions = z.input<typeof KotlinClientOptionsSchema> & GeneratedFileOptions;
74
54
  /**
75
- * A Kotlin client target for `kizuna.config.ts`.
55
+ * A Kotlin client for `kizuna.config.ts`.
76
56
  *
77
57
  * @example
78
- * kotlinClient({ output: './api/APIClient.kt', package: 'com.example.api' });
58
+ * kotlinClient({
59
+ * output: './api/APIClient.kt',
60
+ * package: 'com.example.api',
61
+ * });
79
62
  */
80
- declare const kotlinClient: (options: KotlinClientOptions) => ClientTarget;
63
+ declare const kotlinClient: (options: {
64
+ namespace?: string | undefined;
65
+ package?: string | undefined;
66
+ camelCaseProperties?: boolean | undefined;
67
+ unknownEnumCase?: boolean | undefined;
68
+ } & GeneratedFileOptions) => _$kizunajs.GeneratedFile;
81
69
  //#endregion
82
70
  export { type KotlinClientOptions, type KotlinConfig, generateKotlinClient, kotlinClient };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,7 @@
1
- import { ApiDefinition, ClientTarget } from "kizunajs";
1
+ import { GeneratedFileOptions } from "kizunajs/generator";
2
+ import { z } from "zod";
3
+ import * as _$kizunajs from "kizunajs";
4
+ import { ApiDefinition } from "kizunajs";
2
5
 
3
6
  //#region src/generator.d.ts
4
7
  interface KotlinConfig {
@@ -38,45 +41,30 @@ interface KotlinConfig {
38
41
  declare const generateKotlinClient: (api: ApiDefinition, config: KotlinConfig) => string;
39
42
  //#endregion
40
43
  //#region src/client-target.d.ts
44
+ declare const KotlinClientOptionsSchema: z.ZodObject<{
45
+ namespace: z.ZodDefault<z.ZodString>;
46
+ package: z.ZodOptional<z.ZodString>;
47
+ camelCaseProperties: z.ZodOptional<z.ZodBoolean>;
48
+ unknownEnumCase: z.ZodOptional<z.ZodBoolean>;
49
+ }, z.core.$strip>;
41
50
  /**
42
51
  * Where a generated Kotlin client is written, and what it is called there.
43
52
  */
44
- interface KotlinClientOptions {
45
- /**
46
- * Path the generated file is written to.
47
- */
48
- output: string;
49
- /**
50
- * Name of the generated namespace object.
51
- *
52
- * @default 'API'
53
- */
54
- namespace?: string;
55
- /**
56
- * Package declaration for the generated file, e.g. `com.example.api`.
57
- */
58
- package?: string;
59
- /**
60
- * Convert wire field names to camelCase properties, mapping the wire name
61
- * back via `@SerialName`.
62
- *
63
- * @default false
64
- */
65
- camelCaseProperties?: boolean;
66
- /**
67
- * Give every enum an `unknown` case, so a value the client has not been
68
- * generated for decodes instead of throwing.
69
- *
70
- * @default false
71
- */
72
- unknownEnumCase?: boolean;
73
- }
53
+ type KotlinClientOptions = z.input<typeof KotlinClientOptionsSchema> & GeneratedFileOptions;
74
54
  /**
75
- * A Kotlin client target for `kizuna.config.ts`.
55
+ * A Kotlin client for `kizuna.config.ts`.
76
56
  *
77
57
  * @example
78
- * kotlinClient({ output: './api/APIClient.kt', package: 'com.example.api' });
58
+ * kotlinClient({
59
+ * output: './api/APIClient.kt',
60
+ * package: 'com.example.api',
61
+ * });
79
62
  */
80
- declare const kotlinClient: (options: KotlinClientOptions) => ClientTarget;
63
+ declare const kotlinClient: (options: {
64
+ namespace?: string | undefined;
65
+ package?: string | undefined;
66
+ camelCaseProperties?: boolean | undefined;
67
+ unknownEnumCase?: boolean | undefined;
68
+ } & GeneratedFileOptions) => _$kizunajs.GeneratedFile;
81
69
  //#endregion
82
70
  export { type KotlinClientOptions, type KotlinConfig, generateKotlinClient, kotlinClient };
package/dist/index.mjs CHANGED
@@ -1,16 +1,45 @@
1
- import { t as generateKotlinClient } from "./generator-Ct5OmESk.mjs";
2
- //#region src/client-target.ts
1
+ import { n as kotlinClientWalk, t as generateKotlinClient } from "./generator-uzHpr6im.mjs";
2
+ import { defineClient } from "kizunajs/generator";
3
+ import { z } from "zod";
3
4
  /**
4
- * A Kotlin client target for `kizuna.config.ts`.
5
+ * A Kotlin client for `kizuna.config.ts`.
5
6
  *
6
7
  * @example
7
- * kotlinClient({ output: './api/APIClient.kt', package: 'com.example.api' });
8
+ * kotlinClient({
9
+ * output: './api/APIClient.kt',
10
+ * package: 'com.example.api',
11
+ * });
8
12
  */
9
- const kotlinClient = (options) => ({
10
- kind: "kotlin",
11
- output: options.output,
12
- generate: (contract) => generateKotlinClient(contract, {
13
- namespaceName: options.namespace ?? "API",
13
+ const kotlinClient = defineClient({
14
+ target: "kotlin",
15
+ options: z.object({
16
+ /**
17
+ * Name of the generated namespace object.
18
+ *
19
+ * @default 'API'
20
+ */
21
+ namespace: z.string().default("API"),
22
+ /**
23
+ * Package declaration for the generated file, e.g. `com.example.api`.
24
+ */
25
+ package: z.string().optional(),
26
+ /**
27
+ * Convert wire field names to camelCase properties, mapping the wire name
28
+ * back via `@SerialName`.
29
+ *
30
+ * @default false
31
+ */
32
+ camelCaseProperties: z.boolean().optional(),
33
+ /**
34
+ * Give every enum an `unknown` case, so a value the client has not been
35
+ * generated for decodes instead of throwing.
36
+ *
37
+ * @default false
38
+ */
39
+ unknownEnumCase: z.boolean().optional()
40
+ }),
41
+ generate: ({ options, api }) => kotlinClientWalk(api, {
42
+ namespaceName: options.namespace,
14
43
  packageName: options.package,
15
44
  camelCaseProperties: options.camelCaseProperties,
16
45
  unknownEnumCase: options.unknownEnumCase
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizunajs/kotlin",
3
- "version": "2.0.0-beta.10",
3
+ "version": "2.0.0-beta.12",
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.10"
63
+ "@kizunajs/cli": "2.0.0-beta.12"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "zod": "^4.0.0",
67
- "kizunajs": "2.0.0-beta.10"
67
+ "kizunajs": "2.0.0-beta.12"
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.10"
74
+ "kizunajs": "2.0.0-beta.12"
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",