async-matrix 2.1.0-arm-linux → 3.0.0-arm-linux

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -58
  3. data/lib/async/matrix/3.3/async_matrix_e2ee.so +0 -0
  4. data/lib/async/matrix/3.4/async_matrix_e2ee.so +0 -0
  5. data/lib/async/matrix/4.0/async_matrix_e2ee.so +0 -0
  6. data/lib/async/matrix/api/chain.rb +120 -94
  7. data/lib/async/matrix/api/concat.rb +28 -22
  8. data/lib/async/matrix/api/path_tree.rb +71 -44
  9. data/lib/async/matrix/api.rb +6 -1
  10. data/lib/async/matrix/auth_error.rb +20 -0
  11. data/lib/async/matrix/bad_json_error.rb +20 -0
  12. data/lib/async/matrix/client.rb +142 -110
  13. data/lib/async/matrix/config/vivify.rb +107 -0
  14. data/lib/async/matrix/config.rb +184 -0
  15. data/lib/async/matrix/content.rb +106 -0
  16. data/lib/async/matrix/double_puppet_client.rb +1 -1
  17. data/lib/async/matrix/error.rb +0 -27
  18. data/lib/async/matrix/{application_service/error_response.rb → error_response.rb} +10 -10
  19. data/lib/async/matrix/event.rb +197 -0
  20. data/lib/async/matrix/homeserver_error.rb +20 -0
  21. data/lib/async/matrix/invalid_endpoint_error.rb +20 -0
  22. data/lib/async/matrix/media_client.rb +46 -35
  23. data/lib/async/matrix/not_found_error.rb +20 -0
  24. data/lib/async/matrix/notifier.rb +7 -3
  25. data/lib/async/matrix/response_too_large_error.rb +20 -0
  26. data/lib/async/matrix/schema/registry.rb +367 -340
  27. data/lib/async/matrix/schema/validation_error.rb +221 -214
  28. data/lib/async/matrix/schema.rb +161 -161
  29. data/lib/async/matrix/version.rb +3 -3
  30. data/lib/async/matrix.rb +0 -7
  31. metadata +25 -133
  32. data/lib/async/discord/api/path_tree.rb +0 -127
  33. data/lib/async/discord/api.rb +0 -151
  34. data/lib/async/discord/client.rb +0 -283
  35. data/lib/async/discord/error.rb +0 -84
  36. data/lib/async/discord/gateway.rb +0 -359
  37. data/lib/async/discord.rb +0 -15
  38. data/lib/async/matrix/application_service/bot.rb +0 -232
  39. data/lib/async/matrix/application_service/config/schema/analytics.json +0 -21
  40. data/lib/async/matrix/application_service/config/schema/appservice.json +0 -82
  41. data/lib/async/matrix/application_service/config/schema/backfill.json +0 -91
  42. data/lib/async/matrix/application_service/config/schema/bridge.json +0 -209
  43. data/lib/async/matrix/application_service/config/schema/config.json +0 -61
  44. data/lib/async/matrix/application_service/config/schema/database.json +0 -38
  45. data/lib/async/matrix/application_service/config/schema/direct_media.json +0 -35
  46. data/lib/async/matrix/application_service/config/schema/double_puppet.json +0 -24
  47. data/lib/async/matrix/application_service/config/schema/encryption.json +0 -164
  48. data/lib/async/matrix/application_service/config/schema/homeserver.json +0 -58
  49. data/lib/async/matrix/application_service/config/schema/logging.json +0 -50
  50. data/lib/async/matrix/application_service/config/schema/management_room_texts.json +0 -25
  51. data/lib/async/matrix/application_service/config/schema/matrix.json +0 -45
  52. data/lib/async/matrix/application_service/config/schema/permissions.json +0 -54
  53. data/lib/async/matrix/application_service/config/schema/provisioning.json +0 -23
  54. data/lib/async/matrix/application_service/config/schema/public_media.json +0 -39
  55. data/lib/async/matrix/application_service/config/schema/relay.json +0 -43
  56. data/lib/async/matrix/application_service/config/vivify.rb +0 -109
  57. data/lib/async/matrix/application_service/config.rb +0 -225
  58. data/lib/async/matrix/application_service/dispatcher.rb +0 -185
  59. data/lib/async/matrix/application_service/event.rb +0 -285
  60. data/lib/async/matrix/application_service/server.rb +0 -430
  61. data/lib/async/matrix/application_service/transaction.rb +0 -66
  62. data/lib/async/matrix/application_service/transaction_handler.rb +0 -185
  63. data/lib/async/matrix/application_service/transaction_store.rb +0 -80
  64. data/lib/async/matrix/bridge/discord/db/connection.rb +0 -141
  65. data/lib/async/matrix/bridge/discord/db/file.rb +0 -118
  66. data/lib/async/matrix/bridge/discord/db/guild.rb +0 -120
  67. data/lib/async/matrix/bridge/discord/db/message.rb +0 -160
  68. data/lib/async/matrix/bridge/discord/db/migrations/001_create_users.rb +0 -14
  69. data/lib/async/matrix/bridge/discord/db/migrations/002_create_guilds.rb +0 -14
  70. data/lib/async/matrix/bridge/discord/db/migrations/003_create_portals.rb +0 -23
  71. data/lib/async/matrix/bridge/discord/db/migrations/004_create_puppets.rb +0 -19
  72. data/lib/async/matrix/bridge/discord/db/migrations/005_create_messages.rb +0 -20
  73. data/lib/async/matrix/bridge/discord/db/migrations/006_create_reactions.rb +0 -19
  74. data/lib/async/matrix/bridge/discord/db/migrations/007_create_files.rb +0 -18
  75. data/lib/async/matrix/bridge/discord/db/portal.rb +0 -150
  76. data/lib/async/matrix/bridge/discord/db/puppet.rb +0 -128
  77. data/lib/async/matrix/bridge/discord/db/reaction.rb +0 -165
  78. data/lib/async/matrix/bridge/discord/db/schema.rb +0 -18
  79. data/lib/async/matrix/bridge/discord/db/user.rb +0 -112
  80. data/lib/async/matrix/bridge/discord/db.rb +0 -138
@@ -6,220 +6,227 @@
6
6
  require_relative "../error"
7
7
 
8
8
  module Async
9
- module Matrix
10
- module Schema
11
- # Raised by Event#valid! when data fails schema validation.
12
- #
13
- # Produces detailed, human-readable error messages that identify the exact
14
- # key path and offending value.
15
- #
16
- # Schema validation failed for m.room.member event $abc123:
17
- # - content.membership = "invalid" -- must be one of: ["invite", "join", "knock", "leave", "ban"]
18
- # - sender is required but missing
19
- #
20
- class ValidationError < Async::Matrix::Error
21
- attr_reader :errors, :event_type, :event_id
22
-
23
- # @param errors [Array<Hash>] raw JSONSchemer error hashes
24
- # @param event_type [String, nil] Matrix event type (e.g. "m.room.member")
25
- # @param event_id [String, nil] Matrix event ID (e.g. "$abc123")
26
- def initialize(errors, event_type: nil, event_id: nil)
27
- @errors = errors
28
- @event_type = event_type
29
- @event_id = event_id
30
- super("M_BAD_JSON", build_message)
31
- end
32
-
33
- private
34
-
35
- def build_message
36
- lines = [header_line]
37
- @errors.each { |e| lines.concat(Array(format_error(e))) }
38
- lines.join("\n")
39
- end
40
-
41
- def header_line
42
- header = "Schema validation failed"
43
- header += " for #{@event_type}" if @event_type
44
- header += " event #{@event_id}" if @event_id
45
- header + ":"
46
- end
47
-
48
- def format_error(error)
49
- path = pointer_to_dot(error["data_pointer"])
50
- type = error["type"]
51
- data = error["data"]
52
-
53
- case type
54
- when "required"
55
- format_required(error, path)
56
- when "string", "integer", "number", "boolean", "array", "object", "null"
57
- " - #{path} = #{truncate(data.inspect)} -- expected #{type}, got #{data.class}"
58
- when "minimum"
59
- " - #{path} = #{truncate(data.inspect)} -- must be >= #{error.dig("schema", "minimum")}"
60
- when "maximum"
61
- " - #{path} = #{truncate(data.inspect)} -- must be <= #{error.dig("schema", "maximum")}"
62
- when "enum"
63
- allowed = error.dig("schema", "enum")
64
- " - #{path} = #{truncate(data.inspect)} -- must be one of: #{truncate(allowed.inspect)}"
65
- when "pattern"
66
- pattern = error.dig("schema", "pattern")
67
- " - #{path} = #{truncate(data.inspect)} -- does not match pattern: #{pattern}"
68
- when "format"
69
- fmt = error.dig("schema", "format")
70
- " - #{path} = #{truncate(data.inspect)} -- invalid #{fmt} format"
71
- when "minLength"
72
- " - #{path} = #{truncate(data.inspect)} -- length must be >= #{error.dig("schema", "minLength")}"
73
- when "maxLength"
74
- " - #{path} = #{truncate(data.inspect)} -- length must be <= #{error.dig("schema", "maxLength")}"
75
- when "minItems"
76
- " - #{path} -- array must have >= #{error.dig("schema", "minItems")} items"
77
- when "maxItems"
78
- " - #{path} -- array must have <= #{error.dig("schema", "maxItems")} items"
79
- when "uniqueItems"
80
- " - #{path} -- array items must be unique"
81
- when "const"
82
- expected = error.dig("schema", "const")
83
- " - #{path} = #{truncate(data.inspect)} -- must be #{truncate(expected.inspect)}"
84
- when "additionalProperties"
85
- " - #{path}: #{error["error"] || "has additional properties that are not allowed"}"
86
- else
87
- msg = error["error"] || type
88
- " - #{path}: #{msg}"
89
- end
90
- end
91
-
92
- def format_required(error, path)
93
- missing = error.dig("details", "missing_keys") || []
94
- if missing.empty?
95
- " - #{path}: #{error["error"] || "required"}"
96
- else
97
- missing.map { |key| " - #{join_path(path, key)} is required but missing" }
98
- end
99
- end
100
-
101
- def pointer_to_dot(pointer)
102
- return "root" if pointer.nil? || pointer.empty?
103
- pointer.delete_prefix("/").gsub("/", ".")
104
- end
105
-
106
- def join_path(base, key)
107
- base == "root" ? key.to_s : "#{base}.#{key}"
108
- end
109
-
110
- def truncate(str, max: 60)
111
- str.length > max ? "#{str[0...max]}..." : str
112
- end
113
- end
114
- end
115
- end
9
+ module Matrix
10
+ module Schema
11
+ # Raised by Event#valid! when data fails schema validation.
12
+ #
13
+ # Produces detailed, human-readable error messages that identify the exact
14
+ # key path and offending value.
15
+ #
16
+ # Schema validation failed for m.room.member event $abc123:
17
+ # - content.membership = "invalid" -- must be one of: ["invite", "join", "knock", "leave", "ban"]
18
+ # - sender is required but missing
19
+ #
20
+ class ValidationError < Async::Matrix::Error
21
+ attr_reader :errors, :event_type, :event_id
22
+
23
+ # @param errors [Array<Hash>] raw JSONSchemer error hashes
24
+ # @param event_type [String, nil] Matrix event type (e.g. "m.room.member")
25
+ # @param event_id [String, nil] Matrix event ID (e.g. "$abc123")
26
+ def initialize(errors, event_type: nil, event_id: nil)
27
+ @errors = errors
28
+ @event_type = event_type
29
+ @event_id = event_id
30
+ super("M_BAD_JSON", build_message)
31
+ end
32
+
33
+ private
34
+
35
+ def build_message
36
+ lines = [header_line]
37
+ @errors.each { |e| lines.concat(Array(format_error(e))) }
38
+ lines.join("\n")
39
+ end
40
+
41
+ def header_line
42
+ header = "Schema validation failed"
43
+ if @event_type
44
+ header += " for #{@event_type}"
45
+ end
46
+ if @event_id
47
+ header += " event #{@event_id}"
48
+ end
49
+ header + ":"
50
+ end
51
+
52
+ def format_error(error)
53
+ path = pointer_to_dot(error["data_pointer"])
54
+ type = error["type"]
55
+ data = error["data"]
56
+
57
+ case type
58
+ when "required"
59
+ format_required(error, path)
60
+ when "string", "integer", "number", "boolean", "array", "object", "null"
61
+ " - #{path} = #{truncate(data.inspect)} -- expected #{type}, got #{data.class}"
62
+ when "minimum"
63
+ " - #{path} = #{truncate(data.inspect)} -- must be >= #{error.dig("schema", "minimum")}"
64
+ when "maximum"
65
+ " - #{path} = #{truncate(data.inspect)} -- must be <= #{error.dig("schema", "maximum")}"
66
+ when "enum"
67
+ allowed = error.dig("schema", "enum")
68
+ " - #{path} = #{truncate(data.inspect)} -- must be one of: #{truncate(allowed.inspect)}"
69
+ when "pattern"
70
+ pattern = error.dig("schema", "pattern")
71
+ " - #{path} = #{truncate(data.inspect)} -- does not match pattern: #{pattern}"
72
+ when "format"
73
+ fmt = error.dig("schema", "format")
74
+ " - #{path} = #{truncate(data.inspect)} -- invalid #{fmt} format"
75
+ when "minLength"
76
+ " - #{path} = #{truncate(data.inspect)} -- length must be >= #{error.dig("schema", "minLength")}"
77
+ when "maxLength"
78
+ " - #{path} = #{truncate(data.inspect)} -- length must be <= #{error.dig("schema", "maxLength")}"
79
+ when "minItems"
80
+ " - #{path} -- array must have >= #{error.dig("schema", "minItems")} items"
81
+ when "maxItems"
82
+ " - #{path} -- array must have <= #{error.dig("schema", "maxItems")} items"
83
+ when "uniqueItems"
84
+ " - #{path} -- array items must be unique"
85
+ when "const"
86
+ expected = error.dig("schema", "const")
87
+ " - #{path} = #{truncate(data.inspect)} -- must be #{truncate(expected.inspect)}"
88
+ when "additionalProperties"
89
+ " - #{path}: #{error["error"] || "has additional properties that are not allowed"}"
90
+ else
91
+ msg = error["error"] || type
92
+ " - #{path}: #{msg}"
93
+ end
94
+ end
95
+
96
+ def format_required(error, path)
97
+ missing = error.dig("details", "missing_keys") || []
98
+ if missing.empty?
99
+ " - #{path}: #{error["error"] || "required"}"
100
+ else
101
+ missing.map { |key| " - #{join_path(path, key)} is required but missing" }
102
+ end
103
+ end
104
+
105
+ def pointer_to_dot(pointer)
106
+ if pointer.nil? || pointer.empty?
107
+ "root"
108
+ else
109
+ pointer.delete_prefix("/").gsub("/", ".")
110
+ end
111
+ end
112
+
113
+ def join_path(base, key)
114
+ base == "root" ? key.to_s : "#{base}.#{key}"
115
+ end
116
+
117
+ def truncate(str, max: 60)
118
+ str.length > max ? "#{str[0...max]}..." : str
119
+ end
120
+ end
121
+ end
122
+ end
116
123
  end
117
124
 
118
125
  __END__
119
- describe "Async::Matrix::Schema::ValidationError" do
120
- def error_hash(overrides = {})
121
- {
122
- "data" => nil,
123
- "data_pointer" => "",
124
- "schema" => {},
125
- "schema_pointer" => "",
126
- "root_schema" => {},
127
- "type" => "unknown",
128
- "error" => "something went wrong"
129
- }.merge(overrides)
130
- end
131
-
132
- it "includes event type in header" do
133
- err = Async::Matrix::Schema::ValidationError.new(
134
- [error_hash],
135
- event_type: "m.room.message"
136
- )
137
- err.message.should.include "Schema validation failed for m.room.message"
138
- end
139
-
140
- it "includes event ID in header" do
141
- err = Async::Matrix::Schema::ValidationError.new(
142
- [error_hash],
143
- event_type: "m.room.member",
144
- event_id: "$abc123"
145
- )
146
- err.message.should.include "m.room.member event $abc123"
147
- end
148
-
149
- it "formats type mismatch errors" do
150
- err = Async::Matrix::Schema::ValidationError.new([
151
- error_hash(
152
- "data_pointer" => "/content/body",
153
- "type" => "string",
154
- "data" => 42
155
- )
156
- ])
157
- err.message.should.include "content.body = 42 -- expected string, got Integer"
158
- end
159
-
160
- it "formats required errors with missing keys" do
161
- err = Async::Matrix::Schema::ValidationError.new([
162
- error_hash(
163
- "data_pointer" => "/content",
164
- "type" => "required",
165
- "details" => {"missing_keys" => ["msgtype", "body"]}
166
- )
167
- ])
168
- err.message.should.include "content.msgtype is required but missing"
169
- err.message.should.include "content.body is required but missing"
170
- end
171
-
172
- it "formats enum errors" do
173
- err = Async::Matrix::Schema::ValidationError.new([
174
- error_hash(
175
- "data_pointer" => "/content/membership",
176
- "type" => "enum",
177
- "data" => "invalid",
178
- "schema" => {"enum" => %w[invite join knock leave ban]}
179
- )
180
- ])
181
- err.message.should.include 'content.membership = "invalid" -- must be one of:'
182
- err.message.should.include "invite"
183
- end
184
-
185
- it "formats pattern errors" do
186
- err = Async::Matrix::Schema::ValidationError.new([
187
- error_hash(
188
- "data_pointer" => "/state_key",
189
- "type" => "pattern",
190
- "data" => "bad",
191
- "schema" => {"pattern" => "^@"}
192
- )
193
- ])
194
- err.message.should.include 'state_key = "bad" -- does not match pattern: ^@'
195
- end
196
-
197
- it "formats format errors" do
198
- err = Async::Matrix::Schema::ValidationError.new([
199
- error_hash(
200
- "data_pointer" => "/content/avatar_url",
201
- "type" => "format",
202
- "data" => "not-a-uri",
203
- "schema" => {"format" => "uri"}
204
- )
205
- ])
206
- err.message.should.include "invalid uri format"
207
- end
208
-
209
- it "truncates long values" do
210
- err = Async::Matrix::Schema::ValidationError.new([
211
- error_hash(
212
- "data_pointer" => "/content/body",
213
- "type" => "integer",
214
- "data" => "a" * 200
215
- )
216
- ])
217
- err.message.should.include "..."
218
- end
219
-
220
- it "exposes the raw errors array" do
221
- raw = [error_hash]
222
- err = Async::Matrix::Schema::ValidationError.new(raw)
223
- err.errors.should.equal raw
224
- end
225
- end
126
+ describe "Async::Matrix::Schema::ValidationError" do
127
+ def error_hash(overrides = {})
128
+ {
129
+ "data" => nil,
130
+ "data_pointer" => "",
131
+ "schema" => {},
132
+ "schema_pointer" => "",
133
+ "root_schema" => {},
134
+ "type" => "unknown",
135
+ "error" => "something went wrong"
136
+ }.merge(overrides)
137
+ end
138
+
139
+ it "includes event type in header" do
140
+ err = Async::Matrix::Schema::ValidationError.new(
141
+ [error_hash],
142
+ event_type: "m.room.message"
143
+ )
144
+ err.message.should.include "Schema validation failed for m.room.message"
145
+ end
146
+
147
+ it "includes event ID in header" do
148
+ err = Async::Matrix::Schema::ValidationError.new(
149
+ [error_hash],
150
+ event_type: "m.room.member",
151
+ event_id: "$abc123"
152
+ )
153
+ err.message.should.include "m.room.member event $abc123"
154
+ end
155
+
156
+ it "formats type mismatch errors" do
157
+ err = Async::Matrix::Schema::ValidationError.new([
158
+ error_hash(
159
+ "data_pointer" => "/content/body",
160
+ "type" => "string",
161
+ "data" => 42
162
+ )
163
+ ])
164
+ err.message.should.include "content.body = 42 -- expected string, got Integer"
165
+ end
166
+
167
+ it "formats required errors with missing keys" do
168
+ err = Async::Matrix::Schema::ValidationError.new([
169
+ error_hash(
170
+ "data_pointer" => "/content",
171
+ "type" => "required",
172
+ "details" => {"missing_keys" => ["msgtype", "body"]}
173
+ )
174
+ ])
175
+ err.message.should.include "content.msgtype is required but missing"
176
+ err.message.should.include "content.body is required but missing"
177
+ end
178
+
179
+ it "formats enum errors" do
180
+ err = Async::Matrix::Schema::ValidationError.new([
181
+ error_hash(
182
+ "data_pointer" => "/content/membership",
183
+ "type" => "enum",
184
+ "data" => "invalid",
185
+ "schema" => {"enum" => %w[invite join knock leave ban]}
186
+ )
187
+ ])
188
+ err.message.should.include 'content.membership = "invalid" -- must be one of:'
189
+ err.message.should.include "invite"
190
+ end
191
+
192
+ it "formats pattern errors" do
193
+ err = Async::Matrix::Schema::ValidationError.new([
194
+ error_hash(
195
+ "data_pointer" => "/state_key",
196
+ "type" => "pattern",
197
+ "data" => "bad",
198
+ "schema" => {"pattern" => "^@"}
199
+ )
200
+ ])
201
+ err.message.should.include 'state_key = "bad" -- does not match pattern: ^@'
202
+ end
203
+
204
+ it "formats format errors" do
205
+ err = Async::Matrix::Schema::ValidationError.new([
206
+ error_hash(
207
+ "data_pointer" => "/content/avatar_url",
208
+ "type" => "format",
209
+ "data" => "not-a-uri",
210
+ "schema" => {"format" => "uri"}
211
+ )
212
+ ])
213
+ err.message.should.include "invalid uri format"
214
+ end
215
+
216
+ it "truncates long values" do
217
+ err = Async::Matrix::Schema::ValidationError.new([
218
+ error_hash(
219
+ "data_pointer" => "/content/body",
220
+ "type" => "integer",
221
+ "data" => "a" * 200
222
+ )
223
+ ])
224
+ err.message.should.include "..."
225
+ end
226
+
227
+ it "exposes the raw errors array" do
228
+ raw = [error_hash]
229
+ err = Async::Matrix::Schema::ValidationError.new(raw)
230
+ err.errors.should.equal raw
231
+ end
232
+ end