@arrirpc/codegen-kotlin 0.49.1 → 0.51.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,11 +1,106 @@
1
- # arri-codegen-kotlin
1
+ # Arri Kotlin Codegen
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ ## Setup
4
4
 
5
- ## Building
5
+ ### 1) Add the generator to your arri config
6
6
 
7
- Run `nx build arri-codegen-kotlin` to build the library.
7
+ ```ts
8
+ // arri.config.ts
9
+ import { defineConfig, generators } from "arri";
8
10
 
9
- ## Running unit tests
11
+ export default defineConfig({
12
+ generators: [
13
+ generators.kotlinClient({
14
+ clientName: "MyClient",
15
+ outputFile: "./client/src/MyClient.g.kt",
16
+ }),
17
+ ],
18
+ });
19
+ ```
10
20
 
11
- Run `nx test arri-codegen-kotlin` to execute the unit tests via [Vitest](https://vitest.dev).
21
+ **Options:**
22
+
23
+ | Name | Description |
24
+ | --------------------- | ------------------------------------------------------------- |
25
+ | clientName | The name of the generated client class (Defaults to "Client") |
26
+ | outputFile (required) | Path to the file that will be created by the generator |
27
+ | modelPrefix | Add a prefix to the generated class names |
28
+
29
+ ### 2) Install dependencies
30
+
31
+ The generated code relies on the following dependencies:
32
+
33
+ - [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization)
34
+ - [ktor client](https://ktor.io/docs/client-dependencies.html)
35
+
36
+ ## Using the Generated Code
37
+
38
+ ### Initialize the client
39
+
40
+ ```kotlin
41
+ fun main() {
42
+ // create a Ktor HTTP client
43
+ val httpClient = HttpClient() {
44
+ install(HttpTimeout)
45
+ }
46
+ // initialize your generated client and pass it the httpClient
47
+ // the client name will match whatever options you passed into your arri config
48
+ val client = MyClient(
49
+ httpClient = httpClient,
50
+ baseUrl = "https://example.com",
51
+ // a function that returns a mutable map of headers
52
+ // this function will run before every request. Or before every reconnection in the case of SSE
53
+ headers = {
54
+ mutableMapOf(Pair("x-example-header", "<some-header-value>"))
55
+ }
56
+ )
57
+ runBlocking {
58
+ client.someProcedure()
59
+ }
60
+ }
61
+ ```
62
+
63
+ The root client will be a class containing all of the services and procedures in a single class. If you only need a particular service, you can initialize just that service.
64
+
65
+ ```kotlin
66
+ val service = MyClientUsersService(
67
+ httpClient = httpClient,
68
+ baseUrl = "https://example.com",
69
+ headers = {
70
+ mutableMapOf(Pair("x-example-header", "<some-header-value>"))
71
+ }
72
+ )
73
+ ```
74
+
75
+ ### Using Arri Models
76
+
77
+ All generated models will be data classes. They will have access to the following features:
78
+
79
+ **Methods**:
80
+
81
+ - `toJson(): String`
82
+ - `toUrlQueryParams(): String`
83
+
84
+ **Factory Methods**:
85
+
86
+ - `new()`
87
+ - `fromJson(input: String)`
88
+ - `fromJsonElement(input: JsonElement, instancePath: String)`
89
+
90
+ **Other Notes**
91
+
92
+ - All Enums will have a `serialValue` property.
93
+ - Discriminator schemas are converted to sealed classes
94
+
95
+ ## Development
96
+
97
+ ```bash
98
+ # build the library
99
+ pnpm nx build codegen-kotlin
100
+
101
+ # test
102
+ pnpm nx test codegen-kotlin
103
+
104
+ # lint
105
+ pnpm nx lint codegen-lint
106
+ ```
package/dist/index.cjs CHANGED
@@ -152,7 +152,7 @@ function kotlinArrayFromSchema(schema, context) {
152
152
  modelPrefix: context.modelPrefix,
153
153
  clientName: context.clientName,
154
154
  clientVersion: context.clientVersion,
155
- instancePath: `${context.instancePath}/[element]`,
155
+ instancePath: `${context.instancePath}/[Element]`,
156
156
  schemaPath: `${context.schemaPath}/elements`,
157
157
  existingTypeIds: context.existingTypeIds
158
158
  });
@@ -1254,7 +1254,7 @@ function kotlinRefFromSchema(schema, context) {
1254
1254
  };
1255
1255
  }
1256
1256
 
1257
- const kotlinClientGenerator = codegenUtils.defineClientGeneratorPlugin(
1257
+ const kotlinClientGenerator = codegenUtils.defineGeneratorPlugin(
1258
1258
  (options) => {
1259
1259
  return {
1260
1260
  generator(def) {
package/dist/index.d.cts CHANGED
@@ -33,7 +33,7 @@ interface KotlinClientOptions {
33
33
  modelPrefix?: string;
34
34
  outputFile: string;
35
35
  }
36
- declare const kotlinClientGenerator: _arrirpc_codegen_utils.ClientGeneratorPlugin<KotlinClientOptions>;
36
+ declare const kotlinClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<KotlinClientOptions>;
37
37
  declare function kotlinClientFromAppDefinition(def: AppDefinition, options: KotlinClientOptions): string;
38
38
  declare function kotlinTypeFromSchema(schema: Schema, context: CodegenContext): KotlinProperty;
39
39
 
package/dist/index.d.mts CHANGED
@@ -33,7 +33,7 @@ interface KotlinClientOptions {
33
33
  modelPrefix?: string;
34
34
  outputFile: string;
35
35
  }
36
- declare const kotlinClientGenerator: _arrirpc_codegen_utils.ClientGeneratorPlugin<KotlinClientOptions>;
36
+ declare const kotlinClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<KotlinClientOptions>;
37
37
  declare function kotlinClientFromAppDefinition(def: AppDefinition, options: KotlinClientOptions): string;
38
38
  declare function kotlinTypeFromSchema(schema: Schema, context: CodegenContext): KotlinProperty;
39
39
 
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ interface KotlinClientOptions {
33
33
  modelPrefix?: string;
34
34
  outputFile: string;
35
35
  }
36
- declare const kotlinClientGenerator: _arrirpc_codegen_utils.ClientGeneratorPlugin<KotlinClientOptions>;
36
+ declare const kotlinClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<KotlinClientOptions>;
37
37
  declare function kotlinClientFromAppDefinition(def: AppDefinition, options: KotlinClientOptions): string;
38
38
  declare function kotlinTypeFromSchema(schema: Schema, context: CodegenContext): KotlinProperty;
39
39
 
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs';
2
- import { removeDisallowedChars, camelCase, stringStartsWithNumber, pascalCase, isServiceDefinition, isRpcDefinition, defineClientGeneratorPlugin, unflattenProcedures, isSchemaFormType, isSchemaFormEnum, isSchemaFormProperties, isSchemaFormElements, isSchemaFormValues, isSchemaFormDiscriminator, isSchemaFormRef } from '@arrirpc/codegen-utils';
2
+ import { removeDisallowedChars, camelCase, stringStartsWithNumber, pascalCase, isServiceDefinition, isRpcDefinition, defineGeneratorPlugin, unflattenProcedures, isSchemaFormType, isSchemaFormEnum, isSchemaFormProperties, isSchemaFormElements, isSchemaFormValues, isSchemaFormDiscriminator, isSchemaFormRef } from '@arrirpc/codegen-utils';
3
3
 
4
4
  const reservedIdentifierKeywords = [
5
5
  "as",
@@ -146,7 +146,7 @@ function kotlinArrayFromSchema(schema, context) {
146
146
  modelPrefix: context.modelPrefix,
147
147
  clientName: context.clientName,
148
148
  clientVersion: context.clientVersion,
149
- instancePath: `${context.instancePath}/[element]`,
149
+ instancePath: `${context.instancePath}/[Element]`,
150
150
  schemaPath: `${context.schemaPath}/elements`,
151
151
  existingTypeIds: context.existingTypeIds
152
152
  });
@@ -1248,7 +1248,7 @@ function kotlinRefFromSchema(schema, context) {
1248
1248
  };
1249
1249
  }
1250
1250
 
1251
- const kotlinClientGenerator = defineClientGeneratorPlugin(
1251
+ const kotlinClientGenerator = defineGeneratorPlugin(
1252
1252
  (options) => {
1253
1253
  return {
1254
1254
  generator(def) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/codegen-kotlin",
3
- "version": "0.49.1",
3
+ "version": "0.51.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -22,8 +22,8 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@arrirpc/schema": "0.49.1",
26
- "json-schema-to-jtd": "0.49.1",
27
- "@arrirpc/codegen-utils": "0.49.1"
25
+ "@arrirpc/schema": "0.51.0",
26
+ "@arrirpc/codegen-utils": "0.51.0",
27
+ "json-schema-to-jtd": "0.51.0"
28
28
  }
29
29
  }