Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tonisives committed Nov 3, 2023
1 parent bb128dd commit 7ee3e57
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 123 deletions.
119 changes: 2 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
<!-- TOC -->

* [Current status](#current-status)
* [build/run java/js targets](#buildrun-javajs-targets)
* [run js](#run-js)
* [run jvm](#run-jvm)
* [native](#native)
* [positives](#positives)
* [negatives](#negatives)
* [debugging crashes](#debugging-crashes)
* [js stack trace](#js-stack-trace)
* [js debugger](#js-debugger)
* [java stack trace](#java-stack-trace)
* [java debugging](#java-debugging)
* [issues](#issues)

<!-- TOC -->

## Current status

jvm and js targets working with `getEligibility` request.
It creates jwt and gets auth token with it. Then it uses the token in getEligibility request.

- jvm crypto - hmcrypto-java
- js crypto - jsrsasign

Next request implementations are trivial because crypto and auth is the hardest part.
# HMKit Fleet Multiplatform

## build/run java/js targets

Expand All @@ -48,93 +22,4 @@ in js folder: `yarn && tsx ./src/index.ts`

### native

currently not implemented

## positives

- Main purpose of sharing the http request logic with Coroutines can be exported to both JVM and JS.

Coroutines work. Ktor http client works.

- has code completions with Typescript .d.ts definitions
- can generate TS docs from this

```typescript
// import { HMKitFleet, Environment } from "hmkit-fleet" // types working
import { HMKitFleet, Environment } from "hmkit-fleet/kotlin/hmkit-fleet-mp-hmkit-fleet.mjs" // build working
import fs from "fs"

let privateKey = fs.readFileSync("private-key.json", "utf8")

let env = Environment.SANDBOX

let hmkit = new HMKitFleet(privateKey, env)

hmkit.getEligibility("vin1", env).then((response) => {
console.log(response)
})
```

![completions](./docs/completions.png)
check out generated types in [docs](./docs/hmkit-fleet-hmkit-fleet.d.ts)

## negatives

- if run into a problem, then it is probably a lot slower/impossible to resolve it. Jetbrains needs to update
their multiplatform. For instance their TypeScript support is experimental, but Typescript has been around for a long
time already.
- There is more overhead to manage 2 platforms
- need separate HMKitFleet classes for js and jvm. It's because Js has Promise return type and Java
has CompletableFuture. These return types cannot be mixed in Kotlin

### JVM negatives

adds new dependencies:
- ktor. With native jvm, only OkHttp was used.

## debugging crashes

### js stack trace

```
➜ node index.js
throw SerializationException_init_$Create$(notRegisteredMessage(_this__u8e3s4) + 'To get enum serializer on Kotlin/JS, it should be annotated with @Serializable annotation.');
^
SerializationException: Serializer for class 'Brand' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
To get enum serializer on Kotlin/JS, it should be annotated with @Serializable annotation.
at platformSpecificSerializerNotRegistered (/opt/buildAgent/work/b2fef8360e1bcf3d/core/jsMain/src/kotlinx/serialization/internal/Platform.kt:45:11)
at serializer (/opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/Serializers.kt:134:10)
at requestBody (/opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt:80:1)
at $getEligibilityCOROUTINE$0.protoOf.hh (/Users/tonis/workspace/src/commonMain/kotlin/network/UtilityRequests.kt:49:20)
```

It shows the Kotlin line where the exception was thrown(`UtilityRequests.kt:49:20`). Not problematic to debug.

### js debugger

node js: they recommend normal node
debugging: https://nodejs.org/en/docs/guides/debugging-getting-started#jetbrains-webstorm-2017-1-and-other-jetbrains-ides

The mjs source code for this is not clean, but it is kind of readable
![img](docs/js-debugging.png)

### java stack trace

The java compiled version looks exactly like the current one. I think there won't be any difference for the clients.

- verified
- package is correct (for spring targets that require a package)

### java debugging

With implementation project(""), the debugging works normally

I tested it with releasing to sonatype and debugging in a sample app

### issues

Currently, cannot get both building and types working in js. I don't know how to map .mjs with types in vscode.

I think Js target can be set to experimental, and can be used by customers to quickly verify their use case. If it
works, then they can use the js target.
currently not implemented
139 changes: 139 additions & 0 deletions docs/multiplatform-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<!-- TOC -->
* [Current status](#current-status)
* [build/run java/js targets](#buildrun-javajs-targets)
* [run js](#run-js)
* [run jvm](#run-jvm)
* [native](#native)
* [positives](#positives)
* [negatives](#negatives)
* [JVM negatives](#jvm-negatives)
* [debugging crashes](#debugging-crashes)
* [js stack trace](#js-stack-trace)
* [js debugger](#js-debugger)
* [java stack trace](#java-stack-trace)
* [java debugging](#java-debugging)
* [issues](#issues)
<!-- TOC -->

## Current status

jvm and js targets working with `getEligibility` request.
It creates jwt and gets auth token with it. Then it uses the token in getEligibility request.

- jvm crypto - hmcrypto-java
- js crypto - jsrsasign

Next request implementations are trivial because crypto and auth is the hardest part.

## build/run java/js targets

### run js

build and run js:

`./gradlew assemble && cd hmkit-fleet-consumer-js && yarn && tsx ./src/index.ts && cd -`

continuous building - don't have to manually build on every change

`./gradle assemble --continuous`
in js folder: `yarn && tsx ./src/index.ts`

- js will be located in `build/dist/js/productionLibrary/`
- java will be located in `build/libs/`

### run jvm

`./gradlew :consumer-jvm:run `

### native

currently not implemented

## positives

- Main purpose of sharing the http request logic with Coroutines can be exported to both JVM and JS.

Coroutines work. Ktor http client works.

- has code completions with Typescript .d.ts definitions
- can generate TS docs from this

```typescript
// import { HMKitFleet, Environment } from "hmkit-fleet" // types working
import { HMKitFleet, Environment } from "hmkit-fleet/kotlin/hmkit-fleet-mp-hmkit-fleet.mjs" // build working
import fs from "fs"

let privateKey = fs.readFileSync("private-key.json", "utf8")

let env = Environment.SANDBOX

let hmkit = new HMKitFleet(privateKey, env)

hmkit.getEligibility("vin1", env).then((response) => {
console.log(response)
})
```

![completions](./docs/completions.png)
check out generated types in [docs](./docs/hmkit-fleet-hmkit-fleet.d.ts)

## negatives

- if run into a problem, then it is probably a lot slower/impossible to resolve it. Jetbrains needs to update
their multiplatform. For instance their TypeScript support is experimental, but Typescript has been around for a long
time already.
- There is more overhead to manage 2 platforms
- need separate HMKitFleet classes for js and jvm. It's because Js has Promise return type and Java
has CompletableFuture. These return types cannot be mixed in Kotlin

### JVM negatives

adds new dependencies:
- ktor. With native jvm, only OkHttp was used.

## debugging crashes

### js stack trace

```
➜ node index.js
throw SerializationException_init_$Create$(notRegisteredMessage(_this__u8e3s4) + 'To get enum serializer on Kotlin/JS, it should be annotated with @Serializable annotation.');
^
SerializationException: Serializer for class 'Brand' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
To get enum serializer on Kotlin/JS, it should be annotated with @Serializable annotation.
at platformSpecificSerializerNotRegistered (/opt/buildAgent/work/b2fef8360e1bcf3d/core/jsMain/src/kotlinx/serialization/internal/Platform.kt:45:11)
at serializer (/opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/Serializers.kt:134:10)
at requestBody (/opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt:80:1)
at $getEligibilityCOROUTINE$0.protoOf.hh (/Users/tonis/workspace/src/commonMain/kotlin/network/UtilityRequests.kt:49:20)
```

It shows the Kotlin line where the exception was thrown(`UtilityRequests.kt:49:20`). Not problematic to debug.

### js debugger

node js: they recommend normal node
debugging: https://nodejs.org/en/docs/guides/debugging-getting-started#jetbrains-webstorm-2017-1-and-other-jetbrains-ides

The mjs source code for this is not clean, but it is kind of readable
![img](docs/js-debugging.png)

### java stack trace

The java compiled version looks exactly like the current one. I think there won't be any difference for the clients.

- verified
- package is correct (for spring targets that require a package)

### java debugging

With implementation project(""), the debugging works normally

I tested it with releasing to sonatype and debugging in a sample app

### issues

Currently, cannot get both building and types working in js. I don't know how to map .mjs with types in vscode.

I think Js target can be set to experimental, and can be used by customers to quickly verify their use case. If it
works, then they can use the js target.
6 changes: 0 additions & 6 deletions hmkit-fleet/src/jsMain/kotlin/HMKitFleet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ import com.highmobility.hmkitfleet.model.RequestClearanceResponse
import com.highmobility.hmkitfleet.network.Response
import com.highmobility.hmkitfleet.network.UtilityRequests
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.promise
import kotlinx.serialization.json.Json.Default.configuration
import platform.Crypto
import kotlin.js.Promise
import kotlin.jvm.JvmOverloads

/**
* HMKitFleet is the access point for the Fleet SDK functionality. It is accessed by
Expand Down

0 comments on commit 7ee3e57

Please sign in to comment.