@kizunajs/kotlin 2.0.0-beta.0
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/LICENSE.MD +9 -0
- package/README.md +19 -0
- package/dist/cli.cjs +66 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +67 -0
- package/dist/generator-BvNpSarY.mjs +1795 -0
- package/dist/generator-s2pn7vqP.cjs +1800 -0
- package/dist/index.cjs +22 -0
- package/dist/index.d.cts +82 -0
- package/dist/index.d.mts +82 -0
- package/dist/index.mjs +20 -0
- package/package.json +80 -0
package/LICENSE.MD
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sondre Ørland
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @kizunajs/kotlin
|
|
2
|
+
|
|
3
|
+
`@kizunajs/kotlin` generates a native Kotlin client from your Kizuna routes. The generated client uses OkHttp for HTTP, kotlinx.serialization for JSON, and Kotlin coroutines for async.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D @kizunajs/kotlin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
kizuna-kotlin generate --config kizuna.config.ts --out android/app/src/main/kotlin/com/example/APIClient.kt --namespace-name API --package com.example
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Documentation
|
|
18
|
+
|
|
19
|
+
[Kotlin client generation](https://kizunajs.com/docs/clients/kotlin)
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const require_generator = require("./generator-s2pn7vqP.cjs");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let node_util = require("node:util");
|
|
6
|
+
let _kizunajs_cli = require("@kizunajs/cli");
|
|
7
|
+
//#region src/cli.ts
|
|
8
|
+
const usage = `Usage: kizuna-kotlin generate --config <path> --out <path> --namespace-name <name>
|
|
9
|
+
|
|
10
|
+
Required:
|
|
11
|
+
--config <path> Path to a kizuna.config.ts. Suffix with an export to read
|
|
12
|
+
something other than the default: src/apis.ts:workspace.
|
|
13
|
+
--out <path> File path to write the generated .kt file.
|
|
14
|
+
--namespace-name <name> Public object wrapping all generated types (e.g. MyAPI).
|
|
15
|
+
|
|
16
|
+
Optional:
|
|
17
|
+
--package <name> Package declaration for the generated file (e.g. com.example.api).
|
|
18
|
+
--camel-case Convert wire field names to camelCase properties with @SerialName.
|
|
19
|
+
Default: keep wire names verbatim.
|
|
20
|
+
--unknown-enum-case Emit enums as a sealed interface with an Unknown(wireValue) member
|
|
21
|
+
so unrecognised wire values decode instead of throwing. Default: off.
|
|
22
|
+
--export <name> Export name when none is suffixed. Default: api.
|
|
23
|
+
`;
|
|
24
|
+
const die = (message, code = 1) => {
|
|
25
|
+
process.stderr.write(`${message}\n`);
|
|
26
|
+
process.exit(code);
|
|
27
|
+
};
|
|
28
|
+
const main = async () => {
|
|
29
|
+
const argv = process.argv.slice(2);
|
|
30
|
+
const command = argv[0];
|
|
31
|
+
if (command !== "generate") die(usage, command ? 1 : 0);
|
|
32
|
+
const { values } = (0, node_util.parseArgs)({
|
|
33
|
+
args: argv.slice(1),
|
|
34
|
+
options: {
|
|
35
|
+
config: { type: "string" },
|
|
36
|
+
out: { type: "string" },
|
|
37
|
+
"namespace-name": { type: "string" },
|
|
38
|
+
package: { type: "string" },
|
|
39
|
+
"camel-case": { type: "boolean" },
|
|
40
|
+
"unknown-enum-case": { type: "boolean" },
|
|
41
|
+
export: { type: "string" }
|
|
42
|
+
},
|
|
43
|
+
strict: true
|
|
44
|
+
});
|
|
45
|
+
const configArg = values.config ?? die("Missing --config\n\n" + usage);
|
|
46
|
+
const outArg = values.out ?? die("Missing --out\n\n" + usage);
|
|
47
|
+
const namespaceName = values["namespace-name"] ?? die("Missing --namespace-name\n\n" + usage);
|
|
48
|
+
const [pathPart, apiName = values.export] = configArg.split(":");
|
|
49
|
+
const configPath = (0, node_path.resolve)(process.cwd(), pathPart);
|
|
50
|
+
const apis = await (0, _kizunajs_cli.loadConfig)(configPath);
|
|
51
|
+
const contract = ((apiName === void 0 ? apis[0] : apis.find((entry) => entry.name === apiName)) ?? die(apiName === void 0 ? `No config found at ${configPath}` : `No api named \`${apiName}\` at ${configPath}`)).api;
|
|
52
|
+
const kotlinSource = require_generator.generateKotlinClient(contract, {
|
|
53
|
+
namespaceName,
|
|
54
|
+
packageName: values.package,
|
|
55
|
+
camelCaseProperties: values["camel-case"],
|
|
56
|
+
unknownEnumCase: values["unknown-enum-case"]
|
|
57
|
+
});
|
|
58
|
+
const outputPath = (0, node_path.resolve)(process.cwd(), outArg);
|
|
59
|
+
(0, node_fs.mkdirSync)((0, node_path.dirname)(outputPath), { recursive: true });
|
|
60
|
+
(0, node_fs.writeFileSync)(outputPath, kotlinSource, "utf8");
|
|
61
|
+
process.stdout.write(`Wrote ${kotlinSource.length} bytes to ${outputPath}\n`);
|
|
62
|
+
};
|
|
63
|
+
main().catch((error) => {
|
|
64
|
+
die(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
65
|
+
});
|
|
66
|
+
//#endregion
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as generateKotlinClient } from "./generator-BvNpSarY.mjs";
|
|
3
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
import { loadConfig } from "@kizunajs/cli";
|
|
7
|
+
//#region src/cli.ts
|
|
8
|
+
const usage = `Usage: kizuna-kotlin generate --config <path> --out <path> --namespace-name <name>
|
|
9
|
+
|
|
10
|
+
Required:
|
|
11
|
+
--config <path> Path to a kizuna.config.ts. Suffix with an export to read
|
|
12
|
+
something other than the default: src/apis.ts:workspace.
|
|
13
|
+
--out <path> File path to write the generated .kt file.
|
|
14
|
+
--namespace-name <name> Public object wrapping all generated types (e.g. MyAPI).
|
|
15
|
+
|
|
16
|
+
Optional:
|
|
17
|
+
--package <name> Package declaration for the generated file (e.g. com.example.api).
|
|
18
|
+
--camel-case Convert wire field names to camelCase properties with @SerialName.
|
|
19
|
+
Default: keep wire names verbatim.
|
|
20
|
+
--unknown-enum-case Emit enums as a sealed interface with an Unknown(wireValue) member
|
|
21
|
+
so unrecognised wire values decode instead of throwing. Default: off.
|
|
22
|
+
--export <name> Export name when none is suffixed. Default: api.
|
|
23
|
+
`;
|
|
24
|
+
const die = (message, code = 1) => {
|
|
25
|
+
process.stderr.write(`${message}\n`);
|
|
26
|
+
process.exit(code);
|
|
27
|
+
};
|
|
28
|
+
const main = async () => {
|
|
29
|
+
const argv = process.argv.slice(2);
|
|
30
|
+
const command = argv[0];
|
|
31
|
+
if (command !== "generate") die(usage, command ? 1 : 0);
|
|
32
|
+
const { values } = parseArgs({
|
|
33
|
+
args: argv.slice(1),
|
|
34
|
+
options: {
|
|
35
|
+
config: { type: "string" },
|
|
36
|
+
out: { type: "string" },
|
|
37
|
+
"namespace-name": { type: "string" },
|
|
38
|
+
package: { type: "string" },
|
|
39
|
+
"camel-case": { type: "boolean" },
|
|
40
|
+
"unknown-enum-case": { type: "boolean" },
|
|
41
|
+
export: { type: "string" }
|
|
42
|
+
},
|
|
43
|
+
strict: true
|
|
44
|
+
});
|
|
45
|
+
const configArg = values.config ?? die("Missing --config\n\n" + usage);
|
|
46
|
+
const outArg = values.out ?? die("Missing --out\n\n" + usage);
|
|
47
|
+
const namespaceName = values["namespace-name"] ?? die("Missing --namespace-name\n\n" + usage);
|
|
48
|
+
const [pathPart, apiName = values.export] = configArg.split(":");
|
|
49
|
+
const configPath = resolve(process.cwd(), pathPart);
|
|
50
|
+
const apis = await loadConfig(configPath);
|
|
51
|
+
const contract = ((apiName === void 0 ? apis[0] : apis.find((entry) => entry.name === apiName)) ?? die(apiName === void 0 ? `No config found at ${configPath}` : `No api named \`${apiName}\` at ${configPath}`)).api;
|
|
52
|
+
const kotlinSource = generateKotlinClient(contract, {
|
|
53
|
+
namespaceName,
|
|
54
|
+
packageName: values.package,
|
|
55
|
+
camelCaseProperties: values["camel-case"],
|
|
56
|
+
unknownEnumCase: values["unknown-enum-case"]
|
|
57
|
+
});
|
|
58
|
+
const outputPath = resolve(process.cwd(), outArg);
|
|
59
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
60
|
+
writeFileSync(outputPath, kotlinSource, "utf8");
|
|
61
|
+
process.stdout.write(`Wrote ${kotlinSource.length} bytes to ${outputPath}\n`);
|
|
62
|
+
};
|
|
63
|
+
main().catch((error) => {
|
|
64
|
+
die(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
65
|
+
});
|
|
66
|
+
//#endregion
|
|
67
|
+
export {};
|