async-matrix 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the Apache License, Version 2.0.
4
+ # Copyright, 2026, by General Intelligence Systems.
5
+
6
+ require "bundler/setup"
7
+
8
+ module Async
9
+ module Matrix
10
+ class Error < StandardError
11
+ attr_reader :errcode, :status
12
+
13
+ def initialize(errcode, message, status: nil)
14
+ @errcode = errcode
15
+ @status = status
16
+ super(message)
17
+ end
18
+ end
19
+
20
+ class NotFoundError < Error; end
21
+ class BadJsonError < Error; end
22
+ class AuthError < Error; end
23
+ class HomeserverError < Error; end
24
+ end
25
+ end
26
+
27
+ test do
28
+ describe "Async::Matrix::Error" do
29
+ it "stores errcode and message" do
30
+ err = Async::Matrix::Error.new("M_UNKNOWN", "something broke")
31
+ err.errcode.should == "M_UNKNOWN"
32
+ err.message.should == "something broke"
33
+ end
34
+
35
+ it "stores optional status" do
36
+ err = Async::Matrix::Error.new("M_UNKNOWN", "bad", status: 400)
37
+ err.status.should == 400
38
+ end
39
+
40
+ it "defaults status to nil" do
41
+ Async::Matrix::Error.new("M_UNKNOWN", "bad").status.should.be.nil
42
+ end
43
+
44
+ it "is a StandardError" do
45
+ Async::Matrix::Error.new("M_UNKNOWN", "bad").should.be.kind_of StandardError
46
+ end
47
+ end
48
+
49
+ it "NotFoundError inherits from Error" do
50
+ Async::Matrix::NotFoundError.new("M_NOT_FOUND", "gone").should.be.kind_of Async::Matrix::Error
51
+ end
52
+
53
+ it "BadJsonError inherits from Error" do
54
+ Async::Matrix::BadJsonError.new("M_BAD_JSON", "invalid").should.be.kind_of Async::Matrix::Error
55
+ end
56
+
57
+ it "AuthError inherits from Error" do
58
+ Async::Matrix::AuthError.new("M_FORBIDDEN", "denied").should.be.kind_of Async::Matrix::Error
59
+ end
60
+
61
+ it "HomeserverError inherits from Error" do
62
+ Async::Matrix::HomeserverError.new("M_UNKNOWN", "upstream").should.be.kind_of Async::Matrix::Error
63
+ end
64
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the Apache License, Version 2.0.
4
+ # Copyright, 2026, by General Intelligence Systems.
5
+
6
+ require "bundler/setup"
7
+ require "async"
8
+ require "async/condition"
9
+
10
+ module Async
11
+ module Matrix
12
+ # Waitable event bus. Signal it when events arrive;
13
+ # /sync handlers wait on it with a timeout.
14
+ #
15
+ # notifier = Async::Matrix::Notifier.new
16
+ #
17
+ # # In a /sync handler fiber (blocks until signalled or timeout):
18
+ # notifier.wait(timeout: 30) { check_for_events() }
19
+ #
20
+ # # After persisting an event (wakes all waiting fibers):
21
+ # notifier.signal
22
+ #
23
+ class Notifier
24
+ def initialize
25
+ @condition = Async::Condition.new
26
+ end
27
+
28
+ # Wake all waiting fibers.
29
+ def signal
30
+ @condition.signal
31
+ end
32
+
33
+ # Block up to +timeout+ seconds. Yields to check for data after
34
+ # each wake-up; returns the block's value as soon as it is truthy.
35
+ # Returns the block's value (possibly nil/false) when time runs out.
36
+ def wait(timeout: 30, &block)
37
+ deadline = Time.now + timeout
38
+
39
+ loop do
40
+ result = yield
41
+ return result if result
42
+
43
+ remaining = deadline - Time.now
44
+ return result if remaining <= 0
45
+
46
+ begin
47
+ Async::Task.current.with_timeout(remaining) do
48
+ @condition.wait
49
+ end
50
+ rescue Async::TimeoutError
51
+ return yield
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ test do
60
+ it "can be instantiated" do
61
+ notifier = Async::Matrix::Notifier.new
62
+ notifier.should.be.kind_of Async::Matrix::Notifier
63
+ end
64
+
65
+ it "responds to #signal" do
66
+ Async::Matrix::Notifier.new.should.respond_to :signal
67
+ end
68
+
69
+ it "responds to #wait" do
70
+ Async::Matrix::Notifier.new.should.respond_to :wait
71
+ end
72
+
73
+ it "returns truthy block value immediately without waiting" do
74
+ Async do
75
+ notifier = Async::Matrix::Notifier.new
76
+ result = notifier.wait(timeout: 1) { :data }
77
+ result.should == :data
78
+ end.wait
79
+ end
80
+
81
+ it "returns falsy block value on timeout" do
82
+ Async do
83
+ notifier = Async::Matrix::Notifier.new
84
+ result = notifier.wait(timeout: 0.05) { nil }
85
+ result.should.be.nil
86
+ end.wait
87
+ end
88
+
89
+ it "wakes waiting fibers on signal" do
90
+ result = nil
91
+ Async do |task|
92
+ notifier = Async::Matrix::Notifier.new
93
+ signalled = false
94
+
95
+ task.async do
96
+ result = notifier.wait(timeout: 5) { signalled }
97
+ end
98
+
99
+ task.async do
100
+ signalled = true
101
+ notifier.signal
102
+ end
103
+ end.wait
104
+ result.should == true
105
+ end
106
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the Apache License, Version 2.0.
4
+ # Copyright, 2026, by General Intelligence Systems.
5
+
6
+ require "bundler/setup"
7
+ require "async/http"
8
+
9
+ module Async
10
+ module Matrix
11
+ class Server < Async::HTTP::Protocol::HTTP2::Server
12
+ end
13
+ end
14
+ end
15
+
16
+ test do
17
+ it "inherits from Async::HTTP::Protocol::HTTP2::Server" do
18
+ Async::Matrix::Server.ancestors.should.include Async::HTTP::Protocol::HTTP2::Server
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the Apache License, Version 2.0.
4
+ Copyright, 2026, by General Intelligence Systems.
5
+
6
+ require "bundler/setup"
7
+ require "async/http"
8
+
9
+ module Async
10
+ module Matrix
11
+ class Stream < Async::HTTP::Protocol::HTTP2::Stream
12
+ end
13
+ end
14
+ end
15
+
16
+ test do
17
+ it "inherits from Async::HTTP::Protocol::HTTP2::Stream" do
18
+ Async::Matrix::Stream.ancestors.should.include Async::HTTP::Protocol::HTTP2::Stream
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the Apache License, Version 2.0.
4
+ # Copyright, 2026, by General Intelligence Systems.
5
+
6
+ module Async
7
+ module Matrix
8
+ VERSION = "0.1.0"
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the Apache License, Version 2.0.
4
+ # Copyright, 2026, by General Intelligence Systems.
5
+
6
+ # @namespace
7
+ module Async
8
+ # @namespace
9
+ module Matrix
10
+ end
11
+ end
12
+
13
+ Dir.glob("#{__dir__}/brute/**/*.rb").sort.each do |path|
14
+ require path
15
+ end
16
+
data/lib/async.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the Apache License, Version 2.0.
4
+ # Copyright, 2026, by General Intelligence Systems.
5
+
6
+ require_relative "async/matrix"
7
+
8
+ module Async
9
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async-matrix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Kidd
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-01 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: async
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: async-http
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.69'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.69'
40
+ - !ruby/object:Gem::Dependency
41
+ name: scampi
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.1.7
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.1.7
54
+ - !ruby/object:Gem::Dependency
55
+ name: falcon
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.47'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.47'
68
+ - !ruby/object:Gem::Dependency
69
+ name: logger
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ description: Async-native Matrix protocol primitives built on the Socketry async ecosystem.
83
+ Provides well-known discovery, event notification, and application service models.
84
+ email:
85
+ - nathankidd@hey.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - lib/async.rb
92
+ - lib/async/matrix.rb
93
+ - lib/async/matrix/application_service/config.rb
94
+ - lib/async/matrix/application_service/dispatcher.rb
95
+ - lib/async/matrix/application_service/error_response.rb
96
+ - lib/async/matrix/application_service/event.rb
97
+ - lib/async/matrix/application_service/server.rb
98
+ - lib/async/matrix/application_service/transaction.rb
99
+ - lib/async/matrix/application_service/transaction_store.rb
100
+ - lib/async/matrix/client.rb
101
+ - lib/async/matrix/connection.rb
102
+ - lib/async/matrix/endpoint.rb
103
+ - lib/async/matrix/error.rb
104
+ - lib/async/matrix/notifier.rb
105
+ - lib/async/matrix/server.rb
106
+ - lib/async/matrix/stream.rb
107
+ - lib/async/matrix/version.rb
108
+ homepage: https://github.com/general-intelligence-systems/async-matrix
109
+ licenses:
110
+ - Apache-2.0
111
+ metadata:
112
+ homepage_uri: https://github.com/general-intelligence-systems/async-matrix
113
+ source_code_uri: https://github.com/general-intelligence-systems/async-matrix
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '3.3'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.7.2
129
+ specification_version: 4
130
+ summary: An asynchronous Ruby library for the Matrix protocol.
131
+ test_files: []