skir-kotlin-gen 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -1,26 +1,27 @@
1
1
  [![npm](https://img.shields.io/npm/v/skir-kotlin-gen)](https://www.npmjs.com/package/skir-kotlin-gen)
2
2
  [![build](https://github.com/gepheum/skir-kotlin-gen/workflows/Build/badge.svg)](https://github.com/gepheum/skir-kotlin-gen/actions)
3
3
 
4
- # Soia's Kotlin code generator
4
+ # Skir's Kotlin code generator
5
5
 
6
6
  Official plugin for generating Kotlin code from [.skir](https://github.com/gepheum/skir) files.
7
7
 
8
- ## Installation
9
-
10
- From your project's root directory, run `npm i --save-dev skir-kotlin-gen`.
8
+ ## Set up
11
9
 
12
10
  In your `skir.yml` file, add the following snippet under `generators`:
13
11
  ```yaml
14
12
  - mod: skir-kotlin-gen
13
+ outDir: ./src/main/kotlin/skirout
15
14
  config: {}
15
+ # Alternatively:
16
+ # outDir: ./src/main/kotlin/my/project/skirout
17
+ # config:
18
+ # packagePrefix: my.project.
16
19
  ```
17
20
 
18
- The `npm run skirc` command will now generate .kt files within the `skirout` directory.
19
-
20
21
  The generated Kotlin code has a runtime dependency on `build.skir:skir-client`. Add this line to your `build.gradle.kts` file in the `dependencies` section:
21
22
 
22
23
  ```kotlin
23
- implementation("build.skir:skir-client:1.1.4") // Pick the latest version
24
+ implementation("build.skir:skir-client:latest.release")
24
25
  ```
25
26
 
26
27
  For more information, see this Kotlin project [example](https://github.com/gepheum/skir-kotlin-example).
@@ -197,17 +198,17 @@ greet(lyla)
197
198
 
198
199
  ### Enum classes
199
200
 
200
- Soia generates a deeply immutable Kotlin class for every enum in the .skir file. This class is *not* a Kotlin enum, although the syntax for referring to constants is similar.
201
+ Skir generates a deeply immutable Kotlin class for every enum in the .skir file. This class is *not* a Kotlin enum, although the syntax for referring to constants is similar.
201
202
 
202
203
  ```kotlin
203
204
  val someStatuses =
204
205
  listOf(
205
- // The UNKNOWN constant is present in all Soia enums even if it is not
206
+ // The UNKNOWN constant is present in all Skir enums even if it is not
206
207
  // declared in the .skir file.
207
208
  SubscriptionStatus.UNKNOWN,
208
209
  SubscriptionStatus.FREE,
209
210
  SubscriptionStatus.PREMIUM,
210
- // Soia generates one subclass {VariantName}Wrapper for every wrapper
211
+ // Skir generates one subclass {VariantName}Wrapper for every wrapper
211
212
  // variant. The constructor of this subclass expects the value to
212
213
  // wrap.
213
214
  SubscriptionStatus.TrialWrapper(
@@ -287,7 +288,7 @@ println(serializer.toJsonCode(john, JsonFlavor.READABLE))
287
288
  // }
288
289
 
289
290
  // The dense JSON flavor is the flavor you should pick if you intend to
290
- // deserialize the value in the future. Soia allows fields to be renamed,
291
+ // deserialize the value in the future. Skir allows fields to be renamed,
291
292
  // and because field names are not part of the dense JSON, renaming a field
292
293
  // does not prevent you from deserializing the value.
293
294
  // You should pick the readable flavor mostly for debugging purposes.
@@ -371,8 +372,8 @@ assert(userRegistry.users.findByKey(100) == null)
371
372
  ### Frozen lists and copies
372
373
 
373
374
  ```kotlin
374
- // Since all Soia objects are deeply immutable, all lists contained in a
375
- // Soia object are also deeply immutable.
375
+ // Since all Skir objects are deeply immutable, all lists contained in a
376
+ // Skir object are also deeply immutable.
376
377
  // This section helps understand when lists are copied and when they are
377
378
  // not.
378
379
  val pets: MutableList<Pet> =
@@ -385,7 +386,7 @@ val jade =
385
386
  User.partial(
386
387
  name = "Jade",
387
388
  pets = pets,
388
- // ^ 'pets' is mutable, so Soia makes an immutable shallow copy of it
389
+ // ^ 'pets' is mutable, so Skir makes an immutable shallow copy of it
389
390
  )
390
391
 
391
392
  assert(pets == jade.pets)
@@ -395,13 +396,13 @@ val jack =
395
396
  User.partial(
396
397
  name = "Jack",
397
398
  pets = jade.pets,
398
- // ^ 'jade.pets' is already immutable, so Soia does not make a copy
399
+ // ^ 'jade.pets' is already immutable, so Skir does not make a copy
399
400
  )
400
401
 
401
402
  assert(jack.pets === jade.pets)
402
403
  ```
403
404
 
404
- ### Soia services
405
+ ### Skir services
405
406
 
406
407
  #### Starting a skir service on an HTTP server
407
408
 
@@ -434,7 +435,7 @@ assert(typeDescriptor is StructDescriptor)
434
435
  assert((typeDescriptor as StructDescriptor).fields.size == 5)
435
436
 
436
437
  // The 'allStringsToUpperCase' function uses reflection to convert all the
437
- // strings contained in a given Soia value to upper case.
438
+ // strings contained in a given Skir value to upper case.
438
439
  // See the implementation at
439
440
  // https://github.com/gepheum/skir-kotlin-example/blob/main/src/main/kotlin/AllStringsToUpperCase.kt
440
441
  println(allStringsToUpperCase(TARZAN, User.typeDescriptor))
@@ -462,7 +463,7 @@ println(allStringsToUpperCase(TARZAN, User.typeDescriptor))
462
463
 
463
464
  ## Java codegen versus Kotlin codegen
464
465
 
465
- While Java and Kotlin code can interoperate seamlessly, Soia provides separate code generators for each language to leverage their unique strengths and idioms. For instance, the Kotlin generator utilizes named parameters for struct construction, whereas the Java generator employs the builder pattern.
466
+ While Java and Kotlin code can interoperate seamlessly, skir provides separate code generators for each language to leverage their unique strengths and idioms. For instance, the Kotlin generator utilizes named parameters for struct construction, whereas the Java generator employs the builder pattern.
466
467
 
467
468
  Although it's technically feasible to use Kotlin-generated code in a Java project (or vice versa), doing so results in an API that feels unnatural and cumbersome in the calling language. For the best developer experience, use the code generator that matches your project's primary language.
468
469
 
package/dist/index.js CHANGED
@@ -374,7 +374,7 @@ class KotlinSourceFileGenerator {
374
374
  return JSON.stringify(valueAsDenseJson);
375
375
  case "int64":
376
376
  return `${valueAsDenseJson}L`;
377
- case "uint64":
377
+ case "hash64":
378
378
  return `${valueAsDenseJson}UL`;
379
379
  case "float32": {
380
380
  if (valueAsDenseJson === "NaN") {
@@ -427,7 +427,7 @@ class KotlinSourceFileGenerator {
427
427
  return "false";
428
428
  case "int32":
429
429
  case "int64":
430
- case "uint64":
430
+ case "hash64":
431
431
  return "0";
432
432
  case "float32":
433
433
  return "0.0f";
@@ -104,7 +104,7 @@ export class TypeSpeller {
104
104
  return "kotlin.Int";
105
105
  case "int64":
106
106
  return "kotlin.Long";
107
- case "uint64":
107
+ case "hash64":
108
108
  return "kotlin.ULong";
109
109
  case "float32":
110
110
  return "kotlin.Float";
@@ -134,8 +134,8 @@ export class TypeSpeller {
134
134
  return "build.skir.Serializers.int32";
135
135
  case "int64":
136
136
  return "build.skir.Serializers.int64";
137
- case "uint64":
138
- return "build.skir.Serializers.uint64";
137
+ case "hash64":
138
+ return "build.skir.Serializers.hash64";
139
139
  case "float32":
140
140
  return "build.skir.Serializers.float32";
141
141
  case "float64":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skir-kotlin-gen",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "lint:fix": "eslint src/**/*.ts --fix"
34
34
  },
35
35
  "dependencies": {
36
- "skir-internal": "^0.0.8",
36
+ "skir-internal": "^0.1.0",
37
37
  "zod": "^4.2.1"
38
38
  },
39
39
  "devDependencies": {
@@ -47,7 +47,7 @@
47
47
  "mocha": "^11.7.5",
48
48
  "prettier": "^3.2.4",
49
49
  "prettier-plugin-organize-imports": "^4.2.0",
50
- "skir": "^0.0.7",
50
+ "skir": "^1.0.11",
51
51
  "ts-node": "^10.9.2",
52
52
  "tsx": "^4.21.0",
53
53
  "typescript": "^5.2.2",
package/src/index.ts CHANGED
@@ -692,7 +692,7 @@ class KotlinSourceFileGenerator {
692
692
  return JSON.stringify(valueAsDenseJson);
693
693
  case "int64":
694
694
  return `${valueAsDenseJson}L`;
695
- case "uint64":
695
+ case "hash64":
696
696
  return `${valueAsDenseJson}UL`;
697
697
  case "float32": {
698
698
  if (valueAsDenseJson === "NaN") {
@@ -750,7 +750,7 @@ class KotlinSourceFileGenerator {
750
750
  return "false";
751
751
  case "int32":
752
752
  case "int64":
753
- case "uint64":
753
+ case "hash64":
754
754
  return "0";
755
755
  case "float32":
756
756
  return "0.0f";
@@ -143,7 +143,7 @@ export class TypeSpeller {
143
143
  return "kotlin.Int";
144
144
  case "int64":
145
145
  return "kotlin.Long";
146
- case "uint64":
146
+ case "hash64":
147
147
  return "kotlin.ULong";
148
148
  case "float32":
149
149
  return "kotlin.Float";
@@ -175,8 +175,8 @@ export class TypeSpeller {
175
175
  return "build.skir.Serializers.int32";
176
176
  case "int64":
177
177
  return "build.skir.Serializers.int64";
178
- case "uint64":
179
- return "build.skir.Serializers.uint64";
178
+ case "hash64":
179
+ return "build.skir.Serializers.hash64";
180
180
  case "float32":
181
181
  return "build.skir.Serializers.float32";
182
182
  case "float64":