Skip to content

Commit

Permalink
Add HTTP adapters' features and generic node
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Sep 28, 2024
1 parent b849f9f commit 9246f6c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
42 changes: 42 additions & 0 deletions core/src/main/kotlin/com/hexagontk/core/Node.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.hexagontk.core

// TODO Other possible names: Struct or Record
class Node(val pairs: List<Pair<String?, *>>) : List<Pair<String?, *>> by pairs {
val list: Boolean by lazy { pairs.all { it.first == null } }
val map: Boolean by lazy { !list }

// constructor(items: List<*>) : this(items.map { null to it })
constructor(items: Map<String, *>) : this(items.map { (k, v) -> k to v })
// constructor(vararg items: Any) : this(items.asList())
constructor(vararg items: Pair<String, *>) : this(items.toMap())

private fun asMap(): Map<String?, *> =
pairs.toMap() // Keeps last if duplicated key

private fun groupMap(): Map<String?, *> =
pairs.groupBy { it.first }
}


fun f() {
Node(
mapOf("a" to 1)
)

// Node(
// listOf("a", 1)
// )

Node("a" to 1)

// Node("a", 1)
//
// Node(
// "a",
// 1,
// Node(
// "a" to "b",
// "b" to true
// )
// )
}
9 changes: 9 additions & 0 deletions http/http/api/http.api
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
public final class com/hexagontk/http/HttpFeature : java/lang/Enum {
public static final field COOKIES Lcom/hexagontk/http/HttpFeature;
public static final field MULTIPART Lcom/hexagontk/http/HttpFeature;
public static final field ZIP Lcom/hexagontk/http/HttpFeature;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/hexagontk/http/HttpFeature;
public static fun values ()[Lcom/hexagontk/http/HttpFeature;
}

public final class com/hexagontk/http/HttpKt {
public static final fun basicAuth (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
public static synthetic fun basicAuth$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
Expand Down
10 changes: 10 additions & 0 deletions http/http/src/main/kotlin/com/hexagontk/http/HttpFeature.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hexagontk.http

/**
* TODO To be used in clients/servers (take advantage in tests to fire only tests that apply)
*/
enum class HttpFeature {
MULTIPART,
COOKIES,
ZIP
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.hexagontk.http.model

interface HttpBase {
val body: Any
// TODO Headers can be 'core.Node'???
val headers: Headers
val contentType: ContentType?

Expand Down

0 comments on commit 9246f6c

Please sign in to comment.