-
Notifications
You must be signed in to change notification settings - Fork 1
/
metastreams.scala
94 lines (84 loc) · 4.42 KB
/
metastreams.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright 2020 Scala EventStoreDB Client
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sec
package syntax
import scala.concurrent.duration.FiniteDuration
import cats.MonadThrow
import cats.syntax.all._
import sec.api._
import StreamId.Id
trait MetaStreamsSyntax {
extension [F[_]: MonadThrow](ms: MetaStreams[F]) {
/** Sets max age in [[scala.concurrent.duration.FiniteDuration]] for a stream and returns [[sec.api.WriteResult]]
* with current positions of the stream after a successful operation. Failure to fulfill the expected state is
* manifested by raising [[sec.api.exceptions.WrongExpectedState]].
*
* @param id
* the id of the stream.
* @param expectedState
* the state that the stream is expected to in. See [[StreamState]] for details.
* @param age
* the max age [[scala.concurrent.duration.FiniteDuration]] value for data in the stream. Valid values are
* [[scala.concurrent.duration.FiniteDuration]] greater or equal to 1 second. An [[InvalidInput]] exception is
* raised for invalid input value.
*/
def setMaxAge(id: Id, expectedState: StreamState, age: FiniteDuration): F[WriteResult] =
MaxAge(age).liftTo[F] >>= (ms.setMaxAge(id, expectedState, _))
/** Sets max count in [[scala.Int]] for a stream and returns [[sec.api.WriteResult]] with current positions of the
* stream after a successful operation. Failure to fulfill the expected state is manifested by raising
* [[sec.api.exceptions.WrongExpectedState]].
*
* @param id
* the id of the stream.
* @param expectedState
* the state that the stream is expected to in. See [[StreamState]] for details.
* @param count
* the max count [[scala.Int]] value for data in the stream. Valid values are greater or equal to 1. An
* [[InvalidInput]] exception is raised for invalid input value.
*/
def setMaxCount(id: Id, expectedState: StreamState, count: Int): F[WriteResult] =
MaxCount(count).liftTo[F] >>= (ms.setMaxCount(id, expectedState, _))
/** Sets cache control in [[scala.concurrent.duration.FiniteDuration]] for a stream and returns
* [[sec.api.WriteResult]] with current positions of the stream after a successful operation. Failure to fulfill
* the expected state is manifested by raising [[sec.api.exceptions.WrongExpectedState]].
*
* @param id
* the id of the stream.
* @param expectedState
* the state that the stream is expected to in. See [[StreamState]] for details.
* @param cacheControl
* the cache control [[scala.concurrent.duration.FiniteDuration]] value for data in the stream. Valid values are
* [[scala.concurrent.duration.FiniteDuration]] greater or equal to 1 second. An [[InvalidInput]] exception is
* raised for invalid input value.
*/
def setCacheControl(id: Id, expectedState: StreamState, cacheControl: FiniteDuration): F[WriteResult] =
CacheControl(cacheControl).liftTo[F] >>= (ms.setCacheControl(id, expectedState, _))
/** Sets truncated before in [[Long]] for a stream and returns [[sec.api.WriteResult]] with current positions of the
* stream after a successful operation. Failure to fulfill the expected state is manifested by raising
* [[sec.api.exceptions.WrongExpectedState]].
*
* @param id
* the id of the stream.
* @param expectedState
* the state that the stream is expected to in. See [[StreamState]] for details.
* @param truncatedBefore
* the truncated before [[scala.Long]] value for data in the stream. Valid values are [[scala.Long]] greater or
* equal to 0L. An [[InvalidInput]] exception is raised for invalid input value.
*/
def setTruncateBefore(id: Id, expectedState: StreamState, truncateBefore: Long): F[WriteResult] =
ms.setTruncateBefore(id, expectedState, StreamPosition(truncateBefore))
}
}