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.
- checksums.yaml +4 -4
- data/README.md +33 -58
- data/lib/async/matrix/3.3/async_matrix_e2ee.so +0 -0
- data/lib/async/matrix/3.4/async_matrix_e2ee.so +0 -0
- data/lib/async/matrix/4.0/async_matrix_e2ee.so +0 -0
- data/lib/async/matrix/api/chain.rb +120 -94
- data/lib/async/matrix/api/concat.rb +28 -22
- data/lib/async/matrix/api/path_tree.rb +71 -44
- data/lib/async/matrix/api.rb +6 -1
- data/lib/async/matrix/auth_error.rb +20 -0
- data/lib/async/matrix/bad_json_error.rb +20 -0
- data/lib/async/matrix/client.rb +142 -110
- data/lib/async/matrix/config/vivify.rb +107 -0
- data/lib/async/matrix/config.rb +184 -0
- data/lib/async/matrix/content.rb +106 -0
- data/lib/async/matrix/double_puppet_client.rb +1 -1
- data/lib/async/matrix/error.rb +0 -27
- data/lib/async/matrix/{application_service/error_response.rb → error_response.rb} +10 -10
- data/lib/async/matrix/event.rb +197 -0
- data/lib/async/matrix/homeserver_error.rb +20 -0
- data/lib/async/matrix/invalid_endpoint_error.rb +20 -0
- data/lib/async/matrix/media_client.rb +46 -35
- data/lib/async/matrix/not_found_error.rb +20 -0
- data/lib/async/matrix/notifier.rb +7 -3
- data/lib/async/matrix/response_too_large_error.rb +20 -0
- data/lib/async/matrix/schema/registry.rb +367 -340
- data/lib/async/matrix/schema/validation_error.rb +221 -214
- data/lib/async/matrix/schema.rb +161 -161
- data/lib/async/matrix/version.rb +3 -3
- data/lib/async/matrix.rb +0 -7
- metadata +25 -133
- data/lib/async/discord/api/path_tree.rb +0 -127
- data/lib/async/discord/api.rb +0 -151
- data/lib/async/discord/client.rb +0 -283
- data/lib/async/discord/error.rb +0 -84
- data/lib/async/discord/gateway.rb +0 -359
- data/lib/async/discord.rb +0 -15
- data/lib/async/matrix/application_service/bot.rb +0 -232
- data/lib/async/matrix/application_service/config/schema/analytics.json +0 -21
- data/lib/async/matrix/application_service/config/schema/appservice.json +0 -82
- data/lib/async/matrix/application_service/config/schema/backfill.json +0 -91
- data/lib/async/matrix/application_service/config/schema/bridge.json +0 -209
- data/lib/async/matrix/application_service/config/schema/config.json +0 -61
- data/lib/async/matrix/application_service/config/schema/database.json +0 -38
- data/lib/async/matrix/application_service/config/schema/direct_media.json +0 -35
- data/lib/async/matrix/application_service/config/schema/double_puppet.json +0 -24
- data/lib/async/matrix/application_service/config/schema/encryption.json +0 -164
- data/lib/async/matrix/application_service/config/schema/homeserver.json +0 -58
- data/lib/async/matrix/application_service/config/schema/logging.json +0 -50
- data/lib/async/matrix/application_service/config/schema/management_room_texts.json +0 -25
- data/lib/async/matrix/application_service/config/schema/matrix.json +0 -45
- data/lib/async/matrix/application_service/config/schema/permissions.json +0 -54
- data/lib/async/matrix/application_service/config/schema/provisioning.json +0 -23
- data/lib/async/matrix/application_service/config/schema/public_media.json +0 -39
- data/lib/async/matrix/application_service/config/schema/relay.json +0 -43
- data/lib/async/matrix/application_service/config/vivify.rb +0 -109
- data/lib/async/matrix/application_service/config.rb +0 -225
- data/lib/async/matrix/application_service/dispatcher.rb +0 -185
- data/lib/async/matrix/application_service/event.rb +0 -285
- data/lib/async/matrix/application_service/server.rb +0 -430
- data/lib/async/matrix/application_service/transaction.rb +0 -66
- data/lib/async/matrix/application_service/transaction_handler.rb +0 -185
- data/lib/async/matrix/application_service/transaction_store.rb +0 -80
- data/lib/async/matrix/bridge/discord/db/connection.rb +0 -141
- data/lib/async/matrix/bridge/discord/db/file.rb +0 -118
- data/lib/async/matrix/bridge/discord/db/guild.rb +0 -120
- data/lib/async/matrix/bridge/discord/db/message.rb +0 -160
- data/lib/async/matrix/bridge/discord/db/migrations/001_create_users.rb +0 -14
- data/lib/async/matrix/bridge/discord/db/migrations/002_create_guilds.rb +0 -14
- data/lib/async/matrix/bridge/discord/db/migrations/003_create_portals.rb +0 -23
- data/lib/async/matrix/bridge/discord/db/migrations/004_create_puppets.rb +0 -19
- data/lib/async/matrix/bridge/discord/db/migrations/005_create_messages.rb +0 -20
- data/lib/async/matrix/bridge/discord/db/migrations/006_create_reactions.rb +0 -19
- data/lib/async/matrix/bridge/discord/db/migrations/007_create_files.rb +0 -18
- data/lib/async/matrix/bridge/discord/db/portal.rb +0 -150
- data/lib/async/matrix/bridge/discord/db/puppet.rb +0 -128
- data/lib/async/matrix/bridge/discord/db/reaction.rb +0 -165
- data/lib/async/matrix/bridge/discord/db/schema.rb +0 -18
- data/lib/async/matrix/bridge/discord/db/user.rb +0 -112
- 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
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|