nats-pure 2.2.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -0
  3. data/README.md +251 -0
  4. data/lib/nats/client.rb +1 -0
  5. data/lib/nats/io/client.rb +214 -144
  6. data/lib/nats/io/errors.rb +6 -0
  7. data/lib/nats/io/jetstream/api.rb +4 -0
  8. data/lib/nats/io/jetstream/manager.rb +21 -2
  9. data/lib/nats/io/jetstream/msg/ack_methods.rb +8 -4
  10. data/lib/nats/io/jetstream.rb +82 -7
  11. data/lib/nats/io/msg.rb +3 -1
  12. data/lib/nats/io/rails.rb +29 -0
  13. data/lib/nats/io/subscription.rb +70 -5
  14. data/lib/nats/io/version.rb +1 -1
  15. data/lib/nats/io/websocket.rb +75 -0
  16. data/sig/nats/io/client.rbs +304 -0
  17. data/sig/nats/io/errors.rbs +54 -0
  18. data/sig/nats/io/jetstream/api.rbs +35 -0
  19. data/sig/nats/io/jetstream/errors.rbs +54 -0
  20. data/sig/nats/io/jetstream/js/config.rbs +11 -0
  21. data/sig/nats/io/jetstream/js/header.rbs +17 -0
  22. data/sig/nats/io/jetstream/js/status.rbs +13 -0
  23. data/sig/nats/io/jetstream/js/sub.rbs +14 -0
  24. data/sig/nats/io/jetstream/js.rbs +27 -0
  25. data/sig/nats/io/jetstream/manager.rbs +33 -0
  26. data/sig/nats/io/jetstream/msg/ack.rbs +35 -0
  27. data/sig/nats/io/jetstream/msg/ack_methods.rbs +25 -0
  28. data/sig/nats/io/jetstream/msg/metadata.rbs +15 -0
  29. data/sig/nats/io/jetstream/msg.rbs +6 -0
  30. data/sig/nats/io/jetstream/pull_subscription.rbs +14 -0
  31. data/sig/nats/io/jetstream/push_subscription.rbs +7 -0
  32. data/sig/nats/io/jetstream.rbs +15 -0
  33. data/sig/nats/io/kv/api.rbs +8 -0
  34. data/sig/nats/io/kv/bucket_status.rbs +17 -0
  35. data/sig/nats/io/kv/errors.rbs +30 -0
  36. data/sig/nats/io/kv/manager.rbs +11 -0
  37. data/sig/nats/io/kv.rbs +39 -0
  38. data/sig/nats/io/msg.rbs +14 -0
  39. data/sig/nats/io/parser.rbs +32 -0
  40. data/sig/nats/io/subscription.rbs +33 -0
  41. data/sig/nats/io/version.rbs +9 -0
  42. data/sig/nats/nuid.rbs +32 -0
  43. metadata +49 -4
@@ -0,0 +1,54 @@
1
+ module NATS
2
+ module IO
3
+ class Error < StandardError
4
+ end
5
+
6
+ class ServerError < NATS::IO::Error
7
+ end
8
+
9
+ class ClientError < NATS::IO::Error
10
+ end
11
+
12
+ class ConnectError < NATS::IO::Error
13
+ end
14
+
15
+ class AuthError < NATS::IO::ConnectError
16
+ end
17
+
18
+ class NoServersError < NATS::IO::ConnectError
19
+ end
20
+
21
+ class NoRespondersError < NATS::IO::ConnectError
22
+ end
23
+
24
+ class StaleConnectionError < NATS::IO::Error
25
+ end
26
+
27
+ class Timeout < NATS::IO::Error
28
+ end
29
+
30
+ class SocketTimeoutError < NATS::IO::Timeout
31
+ end
32
+
33
+ class BadSubject < NATS::IO::Error
34
+ end
35
+
36
+ class BadSubscription < NATS::IO::Error
37
+ end
38
+
39
+ class SlowConsumer < NATS::IO::Error
40
+ end
41
+
42
+ class ConnectionDrainingError < NATS::IO::Error
43
+ end
44
+
45
+ class DrainTimeoutError < NATS::IO::Error
46
+ end
47
+ end
48
+
49
+ class Timeout < NATS::IO::Timeout
50
+ end
51
+
52
+ class Error < NATS::IO::Error
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+ module NATS
2
+ class JetStream
3
+ module API
4
+ class Error < NATS::JetStream::Error::APIError
5
+ end
6
+
7
+ class SequenceInfo < Struct[Integer]
8
+ end
9
+
10
+ class ConsumerInfo < Struct[String | NATS::JetStream::API::ConsumerConfig | NATS::JetStream::API::SequenceInfo | Integer | Hash[Symbol, untyped]]
11
+ end
12
+
13
+ class ConsumerConfig < Struct[String | Integer]
14
+ def to_json: (*Hash[untyped, untyped]) -> String
15
+ end
16
+
17
+ class StreamConfig < Struct[String | Hash[Symbol, untyped] | NATS::JetStream::API::StreamState | bool | Integer]
18
+ def to_json: (*Hash[untyped, untyped]) -> String
19
+ end
20
+
21
+ class StreamInfo < Struct[String | Hash[Symbol, untyped]]
22
+ end
23
+
24
+ class StreamState < Struct[Integer]
25
+ end
26
+
27
+ class StreamCreateResponse < Struct[String | NATS::JetStream::API::StreamConfig | NATS::JetStream::API::StreamState | bool]
28
+ end
29
+
30
+ class RawStreamMsg < Struct[String | Integer | Hash[Symbol, untyped]]
31
+ def sequence: () -> Integer
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,54 @@
1
+ module NATS
2
+ class JetStream
3
+ class Error < NATS::IO::Error
4
+ class NoStreamResponse < NATS::JetStream::Error
5
+ end
6
+
7
+ class InvalidDurableName < NATS::JetStream::Error
8
+ end
9
+
10
+ class InvalidJSAck < NATS::JetStream::Error
11
+ end
12
+
13
+ class MsgAlreadyAckd < NATS::JetStream::Error
14
+ end
15
+
16
+ class NotJSMessage < NATS::JetStream::Error
17
+ end
18
+
19
+ class InvalidStreamName < NATS::JetStream::Error
20
+ end
21
+
22
+ class InvalidConsumerName < NATS::JetStream::Error
23
+ end
24
+
25
+ class APIError < NATS::JetStream::Error
26
+ attr_reader code: Integer
27
+ attr_reader err_code: Integer
28
+ attr_reader description: String
29
+ attr_reader stream: String
30
+ attr_reader seq: Integer
31
+
32
+ def initialize: (Hash[Symbol, untyped]) -> void
33
+ end
34
+
35
+ class ServiceUnavailable < NATS::JetStream::Error::APIError
36
+ end
37
+
38
+ class ServerError < NATS::JetStream::Error::APIError
39
+ end
40
+
41
+ class NotFound < NATS::JetStream::Error::APIError
42
+ end
43
+
44
+ class StreamNotFound < NATS::JetStream::Error::NotFound
45
+ end
46
+
47
+ class ConsumerNotFound < NATS::JetStream::Error::NotFound
48
+ end
49
+
50
+ class BadRequest < NATS::JetStream::Error::APIError
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ module Config
5
+ AckExplicit: 'explicit'
6
+ AckAll: 'all'
7
+ AckNone: 'none'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ module Header
5
+ Status: 'Status'
6
+ Desc: 'Description'
7
+ MsgID: 'Nats-Msg-Id'
8
+ ExpectedStream: 'Nats-Expected-Stream'
9
+ ExpectedLastSeq: 'Nats-Expected-Last-Sequence'
10
+ ExpectedLastSubjSeq: 'Nats-Expected-Last-Subject-Sequence'
11
+ ExpectedLastMsgID: 'Nats-Expected-Last-Msg-Id'
12
+ LastConsumerSeq: 'Nats-Last-Consumer'
13
+ LastStreamSeq: 'Nats-Last-Stream'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ module Status
5
+ CtrlMsg: '100'
6
+ NoMsgs: '404'
7
+ NotFound: '404'
8
+ RequestTimeout: '408'
9
+ ServiceUnavailable: '503'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ module Sub
5
+ attr_reader js: NATS::JetStream
6
+ attr_reader stream: String
7
+ attr_reader consumer: String
8
+ attr_reader nms: String
9
+
10
+ def initialize: (Hash[Symbol, untyped]) -> void
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ DefaultAPIPrefix: '$JS.API'
5
+
6
+ # class << self
7
+ def self.next_req_to_json: (Hash[Symbol, untyped]) -> String
8
+
9
+ def self.is_status_msg: (NATS::Msg) -> bool
10
+
11
+ def self.check_503_error: (NATS::Msg) -> void
12
+
13
+ def self.from_msg: (NATS::Msg) -> NATS::JetStream::API::Error
14
+
15
+ def self.from_error: (Hash[Symbol, untyped]) -> (
16
+ NATS::JetStream::Error::ServiceUnavailable |
17
+ NATS::JetStream::Error::ServerError |
18
+ NATS::JetStream::Error::StreamNotFound |
19
+ NATS::JetStream::Error::ConsumerNotFound |
20
+ NATS::JetStream::Error::NotFound |
21
+ NATS::JetStream::Error::BadRequest |
22
+ NATS::JetStream::API::Error
23
+ )
24
+ # end class << self
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module NATS
2
+ class JetStream
3
+ module Manager
4
+ def add_stream: (JetStream::API::StreamConfig, ?Hash[Symbol, untyped]) -> JetStream::API::StreamCreateResponse
5
+
6
+ def stream_info: (String, ?Hash[Symbol, untyped]) -> JetStream::API::StreamInfo
7
+
8
+ def update_stream: (JetStream::API::StreamConfig, ?Hash[Symbol, untyped]) -> JetStream::API::StreamCreateResponse
9
+
10
+ def delete_stream: (String, ?Hash[Symbol, untyped]) -> bool
11
+
12
+ def add_consumer: (String, JetStream::API::ConsumerConfig, ?Hash[Symbol, untyped]) -> JetStream::API::ConsumerInfo
13
+
14
+ def consumer_info: (String, String, ?Hash[Symbol, untyped]) -> JetStream::API::ConsumerInfo
15
+
16
+ def delete_consumer: (String, String, ?Hash[Symbol, untyped]) -> bool
17
+
18
+ def find_stream_name_by_subject: (String, ?Hash[Symbol, untyped]) -> String
19
+
20
+ def get_msg: (String, ?Hash[Symbol, untyped]) -> JetStream::API::RawStreamMsg
21
+
22
+ def get_last_msg: (String, String, ?Hash[Symbol, untyped]) -> JetStream::API::RawStreamMsg
23
+
24
+ def account_info: () -> Hash[Symbol, untyped]
25
+
26
+ private
27
+
28
+ def api_request: (String, String, ?Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
29
+
30
+ def _lift_msg_to_raw_msg: (NATS::Msg) -> JetStream::API::RawStreamMsg
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ module NATS
2
+ class JetStream
3
+ module Msg
4
+ module Ack
5
+ Ack: '+ACK'
6
+ Nak: '-NAK'
7
+ Progress: '+WPI'
8
+ Term: '+TERM'
9
+
10
+ Empty: ''
11
+ DotSep: '.'
12
+ NoDomainName: '_'
13
+
14
+ Prefix0: '$JS'
15
+ Prefix1: 'ACK'
16
+ Domain: 2
17
+ AccHash: 3
18
+ Stream: 4
19
+ Consumer: 5
20
+ NumDelivered: 6
21
+ StreamSeq: 7
22
+ ConsumerSeq: 8
23
+ Timestamp: 9
24
+ NumPending: 10
25
+
26
+ V1TokenCounts: 9
27
+
28
+ V2TokenCounts: 12
29
+
30
+ class SequencePair < Struct[untyped]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ module NATS
2
+ class JetStream
3
+ module Msg
4
+ module AckMethods
5
+ def ack: (**Hash[Symbol, untyped]) -> NATS::JetStream::PubAck
6
+
7
+ def ack_sync: (**Hash[Symbol, untyped]) -> NATS::JetStream::PubAck
8
+
9
+ def nak: (**Hash[Symbol, untyped]) -> NATS::JetStream::PubAck
10
+
11
+ def term: (**Hash[Symbol, untyped]) -> NATS::JetStream::PubAck
12
+
13
+ def in_progress: (**Hash[Symbol, untyped]) -> NATS::JetStream::PubAck
14
+
15
+ def metadata: () -> NATS::JetStream::Msg::Metadata
16
+
17
+ private
18
+
19
+ def ensure_is_acked_once!: () -> void
20
+
21
+ def parse_metadata: (String) -> NATS::JetStream::Msg::Metadata
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module NATS
2
+ class JetStream
3
+ module Msg
4
+ module Metadata
5
+ attr_reader sequence: Ack::SequencePair
6
+ attr_reader num_delivered: Integer
7
+ attr_reader num_pending: Integer
8
+ attr_reader timestamp: Time
9
+ attr_reader stream: String
10
+ attr_reader consumer: String
11
+ attr_reader domain: String
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module NATS
2
+ class JetStream
3
+ module Msg
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ module NATS
2
+ class JetStream
3
+ module PullSubscription
4
+ class PubAck < Struct[String | Numeric | bool]
5
+ end
6
+
7
+ def next_msg: (untyped) -> void
8
+
9
+ def fetch: (Integer, Hash[Symbol, untyped]) -> Array[NATS::Msg]
10
+
11
+ def consumer_info: (Hash[Symbol, untyped]) -> NATS::JetStream::ConsumerInfo
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module NATS
2
+ class JetStream
3
+ module PushSubscription
4
+ def consumer_info: (Hash[Symbol, untyped]) -> NATS::JetStream::ConsumerInfo
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module NATS
2
+ class JetStream
3
+ extend Manager
4
+ extend KeyValue::Manager
5
+
6
+ class PubAck < Struct[String | Numeric | bool]
7
+ end
8
+
9
+ def publish: (String, String, Hash[Symbol, untyped]) -> NATS::JetStream::PubAck
10
+
11
+ def subscribe: (String, Hash[Symbol, untyped]) { (?(NATS::Msg | String), ?String, ?String, ?Hash[Symbol, untyped]) -> void } -> NATS::JetStream::PushSubscription
12
+
13
+ def pull_subscribe: (String, String, Hash[Symbol, untyped]) -> NATS::JetStream::PullSubscription
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ module NATS
2
+ class KeyValue
3
+ module API
4
+ class KeyValueConfig < Struct[untyped]
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module NATS
2
+ class KeyValue
3
+ module BucketStatus
4
+ attr_reader bucket: String
5
+
6
+ @nfo: JetStream::API::StreamInfo
7
+
8
+ def initialize: (JetStream::API::StreamInfo, String) -> void
9
+
10
+ def values: () -> Integer
11
+
12
+ def history: () -> Integer
13
+
14
+ def ttl: () -> Float
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module NATS
2
+ class KeyValue
3
+ class Error < NATS::Error
4
+ end
5
+
6
+ class KeyNotFoundError < NATS::KeyValue::Error
7
+ attr_reader entry: NATS::KeyValue::Entry
8
+ attr_reader op: String
9
+
10
+ @message: String
11
+
12
+ def initialize: (Hash[Symbol, untyped]) -> void
13
+ end
14
+
15
+ class KeyDeletedError < NATS::KeyValue::KeyNotFoundError
16
+ end
17
+
18
+ class BucketNotFoundError < NATS::KeyValue::Error
19
+ end
20
+
21
+ class BadBucketError < NATS::KeyValue::Error
22
+ end
23
+
24
+ class KeyWrongLastSequenceError < NATS::KeyValue::Error
25
+ @msg: String
26
+
27
+ def initialize: (String) -> void
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ module NATS
2
+ class KeyValue
3
+ module Manager
4
+ def key_value: (String) -> NATS::KeyValue
5
+
6
+ def create_key_value: (NATS::KeyValue::API::KeyValueConfig) -> NATS::KeyValue
7
+
8
+ def delete_key_value: (String) -> bool
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ module NATS
2
+ class KeyValue
3
+ KV_OP: 'KV-Operation'
4
+ KV_DEL: 'DEL'
5
+ KV_PURGE: 'PURGE'
6
+ MSG_ROLLUP_SUBJECT: 'sub'
7
+ MSG_ROLLUP_ALL: 'all'
8
+ ROLLUP: 'Nats-Rollup'
9
+
10
+ @name: String
11
+ @stream: String
12
+ @pre: String
13
+ @js: NATS::JetStream
14
+ @direct: bool
15
+
16
+ def initialize: (Hash[Symbol, untyped]) -> void
17
+
18
+ def get: (String, ?Hash[Symbol, untyped]) -> NATS::KeyValue::Entry
19
+
20
+ private def _get: (String, ?Hash[Symbol, untyped]) -> NATS::KeyValue::Entry
21
+
22
+ def put: (String, untyped) -> Integer
23
+
24
+ def create: (String, untyped) -> Integer
25
+
26
+ EXPECTED_LAST_SUBJECT_SEQUENCE: 'Nats-Expected-Last-Subject-Sequence'
27
+
28
+ def update: (String, untyped, ?Hash[Symbol, untyped]) -> Integer
29
+
30
+ def delete: (String, ?Hash[Symbol, untyped]) -> Integer
31
+
32
+ def purge: (String) -> NATS::JetStream::PubAck
33
+
34
+ def status: () -> NATS::KeyValue::BucketStatus
35
+
36
+ class Entry < Struct[untyped]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ module NATS
2
+ class Msg
3
+ attr_reader subject: String
4
+ attr_reader reply: String?
5
+ attr_reader data: String
6
+ attr_reader header: String
7
+
8
+ include NATS::JetStream::Msg::AckMethods
9
+
10
+ def respond: (?String) -> void
11
+
12
+ def respond_msg: (NATS::Msg) -> void
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ module NATS
2
+ module Protocol
3
+ MSG: Regexp
4
+ HMSG: Regexp
5
+ OK: Regexp
6
+ ERR: Regexp
7
+ PING: Regexp
8
+ PONG: Regexp
9
+ INFO: Regexp
10
+ UNKNOWN: Regexp
11
+
12
+ AWAITING_CONTROL_LINE: 1
13
+ AWAITING_MSG_PAYLOAD: 2
14
+
15
+ CR_LF: '\r\n'
16
+ CR_LF_SIZE: Integer
17
+
18
+ PING_REQUEST: String
19
+ PONG_RESPONSE: String
20
+
21
+ SUB_OP: 'SUB'
22
+ EMPTY_MSG: ''
23
+
24
+ class Parser
25
+ def initialize: (NATS::Client) -> void
26
+
27
+ def reset!: () -> void
28
+
29
+ def parse: (String) -> void
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module NATS
2
+ class Subscription
3
+ include MonitorMixin
4
+
5
+ attr_accessor subject: String
6
+ attr_accessor queue: untyped
7
+ attr_accessor future: MonitorMixin::ConditionVariable?
8
+ attr_accessor callback: Proc?
9
+ attr_accessor response: NATS::Msg?
10
+ attr_accessor received: Integer
11
+ attr_accessor max: Integer?
12
+ attr_accessor pending: untyped
13
+ attr_accessor sid: Integer?
14
+
15
+ attr_accessor pending_queue: Thread::SizedQueue?
16
+ attr_accessor pending_size: Integer
17
+ attr_accessor wait_for_msgs_cond: MonitorMixin::ConditionVariable?
18
+
19
+ attr_accessor pending_msgs_limit: Integer?
20
+ attr_accessor pending_bytes_limit: Integer?
21
+
22
+ attr_accessor nc: NATS::Client?
23
+ attr_accessor jsi: NATS::JetStream::JS::Sub
24
+ attr_accessor closed: bool?
25
+
26
+ attr_accessor processing_concurrency: Integer
27
+ attr_reader concurrency_semaphore: Concurrent::Semaphore
28
+
29
+ def unsubscribe: (?Integer?) -> void
30
+
31
+ def next_msg: (Hash[Symbol, untyped]?) -> NATS::Msg
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module NATS
2
+ module IO
3
+ VERSION: String
4
+
5
+ LANG: String
6
+
7
+ Protocol: Integer
8
+ end
9
+ end
data/sig/nats/nuid.rbs ADDED
@@ -0,0 +1,32 @@
1
+ module NATS
2
+ class NUID
3
+ DIGITS: Array[String]
4
+ BASE: Integer
5
+ PREFIX_LENGTH: Integer
6
+ SEQ_LENGTH: Integer
7
+ TOTAL_LENGTH: Integer
8
+ MAX_SEQ: Integer
9
+ MIN_INC: Integer
10
+ MAX_INC: Integer
11
+ INC: Integer
12
+
13
+ @prand: Random
14
+ @seq: Integer
15
+ @inc: Integer
16
+ @prefix: String
17
+
18
+ def next: () -> String
19
+
20
+ def randomize_prefix!: () -> String
21
+
22
+ private
23
+
24
+ def reset_sequential!: () -> Integer
25
+
26
+ # class << self
27
+ @@nuid: NUID
28
+
29
+ def self.next: () -> String
30
+ # end class << self
31
+ end
32
+ end