Skip to content

Commit 1d87385

Browse files
authored
Merge pull request #232 from typelevel/main
0.1 -> 1.x
2 parents f121dbd + 1e21b07 commit 1d87385

5 files changed

Lines changed: 217 additions & 0 deletions

File tree

lambda/shared/src/main/scala-2/feral/lambda/package.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@ package object lambda {
4141
type ApiGatewayProxyLambdaEnv[F[_]] = LambdaEnv[F, ApiGatewayProxyEventV2]
4242
type DynamoDbStreamLambdaEnv[F[_]] = LambdaEnv[F, DynamoDbStreamEvent]
4343
type KinesisStreamLambdaEnv[F[_]] = LambdaEnv[F, KinesisStreamEvent]
44+
type S3BatchLambdaEnv[F[_]] = LambdaEnv[F, S3BatchEvent]
45+
type SnsLambdaEnv[F[_]] = LambdaEnv[F, SnsEvent]
4446
type SqsLambdaEnv[F[_]] = LambdaEnv[F, SqsEvent]
4547
}

lambda/shared/src/main/scala-3/feral/lambda/envs.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ import events._
2121
type ApiGatewayProxyLambdaEnv[F[_]] = LambdaEnv[F, ApiGatewayProxyEventV2]
2222
type DynamoDbStreamLambdaEnv[F[_]] = LambdaEnv[F, DynamoDbStreamEvent]
2323
type KinesisStreamLambdaEnv[F[_]] = LambdaEnv[F, KinesisStreamEvent]
24+
type S3BatchLambdaEnv[F[_]] = LambdaEnv[F, S3BatchEvent]
25+
type SnsLambdaEnv[F[_]] = LambdaEnv[F, SnsEvent]
2426
type SqsLambdaEnv[F[_]] = LambdaEnv[F, SqsEvent]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2021 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package feral.lambda.events
18+
19+
import feral.lambda.KernelSource
20+
import io.circe.Decoder
21+
22+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/s3-batch.d.ts
23+
24+
final case class S3BatchEvent(
25+
invocationSchemaVersion: String,
26+
invocationId: String,
27+
job: S3BatchEventJob,
28+
tasks: List[S3BatchEventTask]
29+
)
30+
31+
object S3BatchEvent {
32+
implicit val decoder: Decoder[S3BatchEvent] =
33+
Decoder.forProduct4("invocationSchemaVersion", "invocationId", "job", "tasks")(
34+
S3BatchEvent.apply)
35+
36+
implicit def kernelSource: KernelSource[S3BatchEvent] = KernelSource.emptyKernelSource
37+
}
38+
39+
final case class S3BatchEventJob(id: String)
40+
41+
object S3BatchEventJob {
42+
implicit val decoder: Decoder[S3BatchEventJob] =
43+
Decoder.forProduct1("id")(S3BatchEventJob.apply)
44+
}
45+
46+
final case class S3BatchEventTask(
47+
taskId: String,
48+
s3Key: String,
49+
s3VersionId: Option[String],
50+
s3BucketArn: String)
51+
52+
object S3BatchEventTask {
53+
implicit val decoder: Decoder[S3BatchEventTask] =
54+
Decoder.forProduct4("taskId", "s3Key", "s3VersionId", "s3BucketArn")(S3BatchEventTask.apply)
55+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2021 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package feral.lambda.events
18+
19+
import io.circe.Encoder
20+
21+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/s3-batch.d.ts
22+
23+
final case class S3BatchResult(
24+
invocationSchemaVersion: String,
25+
treatMissingKeysAs: S3BatchResultResultCode,
26+
invocationId: String,
27+
results: List[S3BatchResultResult]
28+
)
29+
30+
object S3BatchResult {
31+
implicit val encoder: Encoder[S3BatchResult] =
32+
Encoder.forProduct4(
33+
"invocationSchemaVersion",
34+
"treatMissingKeysAs",
35+
"invocationId",
36+
"results")(r =>
37+
(r.invocationSchemaVersion, r.treatMissingKeysAs, r.invocationId, r.results))
38+
}
39+
40+
sealed abstract class S3BatchResultResultCode
41+
42+
object S3BatchResultResultCode {
43+
case object Succeeded extends S3BatchResultResultCode
44+
case object TemporaryFailure extends S3BatchResultResultCode
45+
case object PermanentFailure extends S3BatchResultResultCode
46+
47+
implicit val encoder: Encoder[S3BatchResultResultCode] = Encoder.encodeString.contramap {
48+
case Succeeded => "Succeeded"
49+
case TemporaryFailure => "TemporaryFailure"
50+
case PermanentFailure => "PermanentFailure"
51+
}
52+
}
53+
54+
final case class S3BatchResultResult(
55+
taskId: String,
56+
resultCode: S3BatchResultResultCode,
57+
resultString: String)
58+
59+
object S3BatchResultResult {
60+
implicit val encoder: Encoder[S3BatchResultResult] =
61+
Encoder.forProduct3("taskId", "resultCode", "resultString")(r =>
62+
(r.taskId, r.resultCode, r.resultString))
63+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2021 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package feral.lambda.events
18+
19+
import io.circe.literal._
20+
import io.circe.syntax._
21+
import munit.FunSuite
22+
23+
class S3BatchEventSuite extends FunSuite {
24+
25+
test("decoder") {
26+
event.as[S3BatchEvent].toTry.get
27+
eventNullVersionId.as[S3BatchEvent].toTry.get
28+
}
29+
30+
test("result encoder") {
31+
assertEquals(result.asJson, resultEncoded)
32+
}
33+
34+
def event = json"""
35+
{
36+
"invocationSchemaVersion": "1.0",
37+
"invocationId": "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo",
38+
"job": {
39+
"id": "f3cc4f60-61f6-4a2b-8a21-d07600c373ce"
40+
},
41+
"tasks": [
42+
{
43+
"taskId": "dGFza2lkZ29lc2hlcmUK",
44+
"s3Key": "customerImage1.jpg",
45+
"s3VersionId": "1",
46+
"s3BucketArn": "arn:aws:s3:us-east-1:0123456788:awsexamplebucket1"
47+
}
48+
]
49+
}
50+
"""
51+
52+
def eventNullVersionId = json"""
53+
{
54+
"invocationSchemaVersion": "1.0",
55+
"invocationId": "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo",
56+
"job": {
57+
"id": "f3cc4f60-61f6-4a2b-8a21-d07600c373ce"
58+
},
59+
"tasks": [
60+
{
61+
"taskId": "dGFza2lkZ29lc2hlcmUK",
62+
"s3Key": "customerImage1.jpg",
63+
"s3VersionId": null,
64+
"s3BucketArn": "arn:aws:s3:us-east-1:0123456788:awsexamplebucket1"
65+
}
66+
]
67+
}
68+
"""
69+
70+
def result = S3BatchResult(
71+
"1.0",
72+
S3BatchResultResultCode.PermanentFailure,
73+
"YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo",
74+
List(
75+
S3BatchResultResult(
76+
"dGFza2lkZ29lc2hlcmUK",
77+
S3BatchResultResultCode.Succeeded,
78+
List("Mary Major", "John Stiles").asJson.noSpaces))
79+
)
80+
81+
def resultEncoded = json"""
82+
{
83+
"invocationSchemaVersion": "1.0",
84+
"treatMissingKeysAs" : "PermanentFailure",
85+
"invocationId" : "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo",
86+
"results": [
87+
{
88+
"taskId": "dGFza2lkZ29lc2hlcmUK",
89+
"resultCode": "Succeeded",
90+
"resultString": "[\"Mary Major\",\"John Stiles\"]"
91+
}
92+
]
93+
}
94+
"""
95+
}

0 commit comments

Comments
 (0)