Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Use factory macro to reduce boilerplate #149

Merged
merged 5 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ organization := "net.exoego"
scalacOptions ++= Seq("-P:scalajs:sjsDefinedByDefault").filter { _ =>
Option(System.getenv("SCALAJS_VERSION")).exists(_.startsWith("0.6."))
}
// false positive on js.native
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule))
scalacOptions --= Seq(
// false positive on js.native
"-Wdead-code",
"-Wunused:params",
"-Ywarn-dead-code",
Expand All @@ -15,5 +16,23 @@ scalacOptions --= Seq(

val awsSdkScalajsFacadeVersion = "[0.29.0-v2.624.0,1.0)"
libraryDependencies ++= Seq(
"net.exoego" %%% "scalajs-types-util" % "0.2.2",
"net.exoego" %%% "aws-sdk-scalajs-facade-dynamodb" % awsSdkScalajsFacadeVersion
)

Compile / scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n >= 13 => "-Ymacro-annotations" :: Nil
case _ => Nil
}
}

libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n >= 13 => Nil
case _ =>
compilerPlugin(
"org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full
) :: Nil
}
}
72 changes: 6 additions & 66 deletions src/main/scala/net/exoego/facade/aws_lambda/Handler.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.exoego.facade.aws_lambda

import net.exoego.scalajs.types.util.Factory

import scala.scalajs.js
import scala.scalajs.js.annotation.JSName
import scala.scalajs.js.|
Expand Down Expand Up @@ -46,47 +48,22 @@ trait Context extends js.Object {
def succeed(message: String, `object`: js.Any): Unit = js.native
}

@Factory
@js.native
trait CognitoIdentity extends js.Object {
var cognitoIdentityId: String = js.native
var cognitoIdentityPoolId: String = js.native
}

object CognitoIdentity {
def apply(
cognitoIdentityId: String,
cognitoIdentityPoolId: String
): CognitoIdentity = {
val _obj$ = js.Dynamic.literal(
"cognitoIdentityId" -> cognitoIdentityId.asInstanceOf[js.Any],
"cognitoIdentityPoolId" -> cognitoIdentityPoolId.asInstanceOf[js.Any]
)
_obj$.asInstanceOf[CognitoIdentity]
}
}

@Factory
@js.native
trait ClientContext extends js.Object {
var client: ClientContextClient = js.native
var Custom: js.UndefOr[js.Any] = js.native
var env: ClientContextEnv = js.native
}

object ClientContext {
def apply(
client: ClientContextClient,
env: ClientContextEnv,
Custom: js.UndefOr[js.Any] = js.undefined
): ClientContext = {
val _obj$ = js.Dynamic.literal(
"client" -> client.asInstanceOf[js.Any],
"env" -> env.asInstanceOf[js.Any]
)
Custom.foreach(_v => _obj$.updateDynamic("Custom")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[ClientContext]
}
}

@Factory
@js.native
trait ClientContextClient extends js.Object {
var installationId: String = js.native
Expand All @@ -96,25 +73,7 @@ trait ClientContextClient extends js.Object {
var appPackageName: String = js.native
}

object ClientContextClient {
def apply(
installationId: String,
appTitle: String,
appVersionName: String,
appVersionCode: String,
appPackageName: String
): ClientContextClient = {
val _obj$ = js.Dynamic.literal(
"installationId" -> installationId.asInstanceOf[js.Any],
"appTitle" -> appTitle.asInstanceOf[js.Any],
"appVersionName" -> appVersionName.asInstanceOf[js.Any],
"appVersionCode" -> appVersionCode.asInstanceOf[js.Any],
"appPackageName" -> appPackageName.asInstanceOf[js.Any]
)
_obj$.asInstanceOf[ClientContextClient]
}
}

@Factory
@js.native
trait ClientContextEnv extends js.Object {
var platformVersion: String = js.native
Expand All @@ -123,22 +82,3 @@ trait ClientContextEnv extends js.Object {
var model: String = js.native
var locale: String = js.native
}

object ClientContextEnv {
def apply(
platformVersion: String,
platform: String,
make: String,
model: String,
locale: String
): ClientContextEnv = {
val _obj$ = js.Dynamic.literal(
"platformVersion" -> platformVersion.asInstanceOf[js.Any],
"platform" -> platform.asInstanceOf[js.Any],
"make" -> make.asInstanceOf[js.Any],
"model" -> model.asInstanceOf[js.Any],
"locale" -> locale.asInstanceOf[js.Any]
)
_obj$.asInstanceOf[ClientContextEnv]
}
}
87 changes: 7 additions & 80 deletions src/main/scala/net/exoego/facade/aws_lambda/alb.scala
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
package net.exoego.facade.aws_lambda

import net.exoego.scalajs.types.util.Factory

import scala.scalajs.js
import scala.scalajs.js.|

@Factory
@js.native
trait ALBEventRequestContext extends js.Object {
var elb: ALBEventRequestContext.Elb = js.native
}

object ALBEventRequestContext {
def apply(
elb: ALBEventRequestContext.Elb
): ALBEventRequestContext = {
val _obj$ = js.Dynamic.literal(
"elb" -> elb.asInstanceOf[js.Any]
)
_obj$.asInstanceOf[ALBEventRequestContext]
}

@Factory(false)
@js.native
trait Elb extends js.Object {
var targetGroupArn: String = js.native
}

object Elb {
def apply(
targetGroupArn: String
): Elb = {
val _obj$ = js.Dynamic.literal(
"targetGroupArn" -> targetGroupArn.asInstanceOf[js.Any]
)
_obj$.asInstanceOf[Elb]
}
}
}

@Factory
@js.native
trait ALBEvent extends js.Object {
var requestContext: ALBEventRequestContext = js.native
Expand All @@ -51,48 +36,13 @@ trait ALBEvent extends js.Object {
}

object ALBEvent {
def apply(
requestContext: ALBEventRequestContext,
httpMethod: String,
path: String,
isBase64Encoded: Boolean,
body: String | Null = null,
queryStringParameters: js.UndefOr[ALBEvent.QueryStringParameters] =
js.undefined,
headers: js.UndefOr[ALBEvent.Headers] = js.undefined,
multiValueQueryStringParameters: js.UndefOr[
ALBEvent.MultiValueQueryStringParameters
] = js.undefined,
multiValueHeaders: js.UndefOr[ALBEvent.MultiValueHeaders] = js.undefined
): ALBEvent = {
val _obj$ = js.Dynamic.literal(
"requestContext" -> requestContext.asInstanceOf[js.Any],
"httpMethod" -> httpMethod.asInstanceOf[js.Any],
"path" -> path.asInstanceOf[js.Any],
"body" -> body.asInstanceOf[js.Any],
"isBase64Encoded" -> isBase64Encoded.asInstanceOf[js.Any]
)
queryStringParameters.foreach(_v =>
_obj$.updateDynamic("queryStringParameters")(_v.asInstanceOf[js.Any])
)
headers.foreach(_v =>
_obj$.updateDynamic("headers")(_v.asInstanceOf[js.Any])
)
multiValueQueryStringParameters.foreach(_v =>
_obj$.updateDynamic("multiValueQueryStringParameters")(
_v.asInstanceOf[js.Any]
)
)
multiValueHeaders.foreach(_v =>
_obj$.updateDynamic("multiValueHeaders")(_v.asInstanceOf[js.Any])
)
_obj$.asInstanceOf[ALBEvent]
}
type QueryStringParameters = js.Dictionary[String]
type Headers = js.Dictionary[String]
type MultiValueQueryStringParameters = js.Dictionary[js.Array[String]]
type MultiValueHeaders = js.Dictionary[js.Array[String]]
}

@Factory
@js.native
trait ALBResult extends js.Object {
var statusCode: Double = js.native
Expand All @@ -104,29 +54,6 @@ trait ALBResult extends js.Object {
}

object ALBResult {
def apply(
statusCode: Double,
statusDescription: String,
isBase64Encoded: Boolean,
headers: js.UndefOr[ALBResult.Headers] = js.undefined,
multiValueHeaders: js.UndefOr[ALBResult.MultiValueHeaders] = js.undefined,
body: js.UndefOr[String] = js.undefined
): ALBResult = {
val _obj$ = js.Dynamic.literal(
"statusCode" -> statusCode.asInstanceOf[js.Any],
"statusDescription" -> statusDescription.asInstanceOf[js.Any],
"isBase64Encoded" -> isBase64Encoded.asInstanceOf[js.Any]
)
headers.foreach(_v =>
_obj$.updateDynamic("headers")(_v.asInstanceOf[js.Any])
)
multiValueHeaders.foreach(_v =>
_obj$.updateDynamic("multiValueHeaders")(_v.asInstanceOf[js.Any])
)
body.foreach(_v => _obj$.updateDynamic("body")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[ALBResult]
}

type Headers = HeadersBDS
type MultiValueHeaders = MultiValueHeadersBDS
}
Loading