Skip to content

Commit f621a62

Browse files
authored
feat: add support for Elixir 1.15 (#195)
1 parent 174c7d9 commit f621a62

File tree

13 files changed

+68
-53
lines changed

13 files changed

+68
-53
lines changed

.tool-versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
elixir 1.13.4-otp-25
2-
erlang 25.0.3
1+
elixir 1.15.4-otp-26
2+
erlang 26.0.2
33
python 3.10.2

config/dev.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

config/prod.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

lib/bson/decoder.ex

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ defmodule BSON.Decoder do
3232
{:NaN, rest}
3333
end
3434

35-
defp type(@type_float, <<float::little-float64, rest::binary>>) do
35+
defp type(@type_float, <<float::little-float64(), rest::binary>>) do
3636
{float, rest}
3737
end
3838

39-
defp type(@type_string, <<size::int32, rest::binary>>) do
39+
defp type(@type_string, <<size::int32(), rest::binary>>) do
4040
size = size - 1
4141
<<string::binary(size), 0x00, rest::binary>> = rest
4242
{string, rest}
@@ -50,12 +50,12 @@ defmodule BSON.Decoder do
5050
list(binary)
5151
end
5252

53-
defp type(@type_binary, <<_size::int32, subtype, length::int32, binary::binary(length), rest::binary>>) when subtype == 0x02 do
53+
defp type(@type_binary, <<_size::int32(), subtype, length::int32(), binary::binary(length), rest::binary>>) when subtype == 0x02 do
5454
subtype = subtype(subtype)
5555
{%BSON.Binary{binary: binary, subtype: subtype}, rest}
5656
end
5757

58-
defp type(@type_binary, <<size::int32, subtype, binary::binary(size), rest::binary>>) do
58+
defp type(@type_binary, <<size::int32(), subtype, binary::binary(size), rest::binary>>) do
5959
subtype = subtype(subtype)
6060
{%BSON.Binary{binary: binary, subtype: subtype}, rest}
6161
end
@@ -72,7 +72,7 @@ defmodule BSON.Decoder do
7272
{true, rest}
7373
end
7474

75-
defp type(@type_datetime, <<unix_ms::int64, rest::binary>>) do
75+
defp type(@type_datetime, <<unix_ms::int64(), rest::binary>>) do
7676
{DateTime.from_unix!(unix_ms, :millisecond), rest}
7777
end
7878

@@ -99,23 +99,23 @@ defmodule BSON.Decoder do
9999
type(@type_string, binary)
100100
end
101101

102-
defp type(@type_js_scope, <<size::int32, binary::binary>>) do
102+
defp type(@type_js_scope, <<size::int32(), binary::binary>>) do
103103
size = size - 4
104104
<<binary::binary(size), rest::binary>> = binary
105105
{code, binary} = type(@type_string, binary)
106106
{scope, ""} = document(binary)
107107
{%BSON.JavaScript{code: code, scope: scope}, rest}
108108
end
109109

110-
defp type(@type_int32, <<int::int32, rest::binary>>) do
110+
defp type(@type_int32, <<int::int32(), rest::binary>>) do
111111
{int, rest}
112112
end
113113

114-
defp type(@type_timestamp, <<ordinal::int32, epoch::int32, rest::binary>>) do
114+
defp type(@type_timestamp, <<ordinal::int32(), epoch::int32(), rest::binary>>) do
115115
{%BSON.Timestamp{value: epoch, ordinal: ordinal}, rest}
116116
end
117117

118-
defp type(@type_int64, <<int::int64, rest::binary>>) do
118+
defp type(@type_int64, <<int::int64(), rest::binary>>) do
119119
{int, rest}
120120
end
121121

@@ -131,7 +131,7 @@ defmodule BSON.Decoder do
131131
{:BSON_max, rest}
132132
end
133133

134-
def document(<<size::int32, rest::binary>>) do
134+
def document(<<size::int32(), rest::binary>>) do
135135
size = size - 5
136136
<<doc::binary(size), 0x00, rest::binary>> = rest
137137

@@ -149,7 +149,7 @@ defmodule BSON.Decoder do
149149
acc |> Enum.reverse() |> Enum.into(%{})
150150
end
151151

152-
defp list(<<size::int32, rest::binary>>) do
152+
defp list(<<size::int32(), rest::binary>>) do
153153
size = size - 5
154154
<<list::binary(size), 0x00, rest::binary>> = rest
155155

lib/bson/encoder.ex

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ defmodule BSON.Encoder do
2020
def encode(%BSON.Binary{binary: binary, subtype: :binary_old}) do
2121
subtype = subtype(:binary_old)
2222
size = IO.iodata_length(binary)
23-
[<<size + 4::int32>>, subtype, <<size::int32>>, binary]
23+
[<<size + 4::int32()>>, subtype, <<size::int32()>>, binary]
2424
end
2525

2626
def encode(%BSON.Binary{binary: binary, subtype: subtype}) do
2727
subtype = subtype(subtype)
28-
[<<IO.iodata_length(binary)::int32>>, subtype | binary]
28+
[<<IO.iodata_length(binary)::int32()>>, subtype | binary]
2929
end
3030

3131
def encode(%BSON.ObjectId{value: <<_::binary(12)>> = value}),
3232
do: value
3333

3434
def encode(%DateTime{} = datetime) do
3535
unix_ms = DateTime.to_unix(datetime, :millisecond)
36-
<<unix_ms::int64>>
36+
<<unix_ms::int64()>>
3737
end
3838

3939
def encode(%BSON.Regex{pattern: pattern, options: options}),
@@ -45,13 +45,13 @@ defmodule BSON.Encoder do
4545
def encode(%BSON.JavaScript{code: code, scope: scope}) do
4646
iodata = [encode(code), document(scope)]
4747
size = IO.iodata_length(iodata) + 4
48-
[<<size::int32>> | iodata]
48+
[<<size::int32()>> | iodata]
4949
end
5050

5151
def encode(%BSON.Timestamp{value: epoch, ordinal: ordinal}),
52-
do: <<ordinal::int32, epoch::int32>>
52+
do: <<ordinal::int32(), epoch::int32()>>
5353

54-
def encode(%BSON.LongNumber{value: value}), do: <<value::int64>>
54+
def encode(%BSON.LongNumber{value: value}), do: <<value::int64()>>
5555

5656
def encode(%Decimal{} = value), do: BSON.Decimal128.encode(value)
5757

@@ -85,16 +85,16 @@ defmodule BSON.Encoder do
8585
do: encode(Atom.to_string(value))
8686

8787
def encode(value) when is_binary(value),
88-
do: [<<byte_size(value) + 1::int32>>, value, 0x00]
88+
do: [<<byte_size(value) + 1::int32()>>, value, 0x00]
8989

9090
def encode(value) when is_float(value),
91-
do: <<value::little-float64>>
91+
do: <<value::little-float64()>>
9292

9393
def encode(value) when is_int32(value),
94-
do: <<value::int32>>
94+
do: <<value::int32()>>
9595

9696
def encode(value) when is_int64(value),
97-
do: <<value::int64>>
97+
do: <<value::int64()>>
9898

9999
def encode(value) do
100100
raise Mongo.Error.exception("invalid document: #{inspect(value)}")
@@ -131,7 +131,7 @@ defmodule BSON.Encoder do
131131
{key_type, [acc, type, key, value]}
132132
end)
133133

134-
[<<IO.iodata_length(iodata) + 5::int32>>, iodata, 0x00]
134+
[<<IO.iodata_length(iodata) + 5::int32()>>, iodata, 0x00]
135135
end
136136

137137
defp cstring(string), do: [string, 0x00]

lib/mongo/messages.ex

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ defmodule Mongo.Messages do
6262
end
6363
end
6464

65-
def decode_header(<<length::int32, request_id::int32, response_to::int32, op_code::int32>>) do
65+
def decode_header(<<length::int32(), request_id::int32(), response_to::int32(), op_code::int32()>>) do
6666
header = msg_header(length: length - @header_size, request_id: request_id, response_to: response_to, op_code: op_code)
6767
{:ok, header}
6868
end
@@ -94,33 +94,33 @@ defmodule Mongo.Messages do
9494
@doc """
9595
Decodes a reply message from the response
9696
"""
97-
def decode_reply(<<flags::int32, cursor_id::int64, from::int32, num::int32, rest::binary>>) do
97+
def decode_reply(<<flags::int32(), cursor_id::int64(), from::int32(), num::int32(), rest::binary>>) do
9898
op_reply(flags: flags, cursor_id: cursor_id, from: from, num: num, docs: BSON.Decoder.documents(rest))
9999
end
100100

101-
def decode_msg(<<flags::int32, rest::binary>>) do
101+
def decode_msg(<<flags::int32(), rest::binary>>) do
102102
op_msg(flags: flags, sections: decode_sections(rest))
103103
end
104104

105105
def decode_sections(binary), do: decode_sections(binary, [])
106106
def decode_sections("", acc), do: Enum.reverse(acc)
107107

108-
def decode_sections(<<0x00::int8, payload::binary>>, acc) do
109-
<<size::int32, _rest::binary>> = payload
108+
def decode_sections(<<0x00::int8(), payload::binary>>, acc) do
109+
<<size::int32(), _rest::binary>> = payload
110110
<<doc::binary(size), rest::binary>> = payload
111111

112112
with {doc, ""} <- BSON.Decoder.document(doc) do
113113
decode_sections(rest, [section(payload_type: 0, payload: payload(doc: doc)) | acc])
114114
end
115115
end
116116

117-
def decode_sections(<<0x01::int8, payload::binary>>, acc) do
118-
<<size::int32, _rest::binary>> = payload
117+
def decode_sections(<<0x01::int8(), payload::binary>>, acc) do
118+
<<size::int32(), _rest::binary>> = payload
119119
<<sequence::binary(size), rest::binary>> = payload
120120
decode_sections(rest, [section(payload_type: 1, payload: payload(sequence: decode_sequence(sequence))) | acc])
121121
end
122122

123-
def decode_sequence(<<size::int32, rest::binary>>) do
123+
def decode_sequence(<<size::int32(), rest::binary>>) do
124124
with {identifier, docs} <- cstring(rest) do
125125
sequence(size: size, identifier: identifier, docs: BSON.Decoder.documents(docs))
126126
end
@@ -144,23 +144,23 @@ defmodule Mongo.Messages do
144144
end
145145

146146
defp encode_header(msg_header(length: length, request_id: request_id, response_to: response_to, op_code: op_code)) do
147-
<<length::int32, request_id::int32, response_to::int32, op_code::int32>>
147+
<<length::int32(), request_id::int32(), response_to::int32(), op_code::int32()>>
148148
end
149149

150150
defp encode_op(op_query(flags: flags, coll: coll, num_skip: num_skip, num_return: num_return, query: query, select: select)) do
151-
[<<blit_flags(:query, flags)::int32>>, coll, <<0x00, num_skip::int32, num_return::int32>>, BSON.Encoder.document(query), select]
151+
[<<blit_flags(:query, flags)::int32()>>, coll, <<0x00, num_skip::int32(), num_return::int32()>>, BSON.Encoder.document(query), select]
152152
end
153153

154154
defp encode_op(op_msg(flags: flags, sections: sections)) do
155-
[<<blit_flags(:msg, flags)::int32>> | encode_sections(sections)]
155+
[<<blit_flags(:msg, flags)::int32()>> | encode_sections(sections)]
156156
end
157157

158158
defp encode_sections(sections) do
159159
Enum.map(sections, fn section -> encode_section(section) end)
160160
end
161161

162162
defp encode_section(section(payload_type: t, payload: payload)) do
163-
[<<t::int8>> | encode_payload(payload)]
163+
[<<t::int8()>> | encode_payload(payload)]
164164
end
165165

166166
defp encode_payload(payload(doc: doc, sequence: nil)) do
@@ -170,7 +170,7 @@ defmodule Mongo.Messages do
170170
defp encode_payload(payload(doc: nil, sequence: sequence(identifier: identifier, docs: docs))) do
171171
iodata = [identifier, <<0x00>> | Enum.map(docs, fn doc -> BSON.Encoder.encode(doc) end)]
172172
size = IO.iodata_length(iodata) + 4
173-
[<<size::int32>> | iodata]
173+
[<<size::int32()>> | iodata]
174174
end
175175

176176
defp blit_flags(op, flags) when is_list(flags) do

lib/mongo/monitor.ex

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ defmodule Mongo.Monitor do
178178
end
179179

180180
error ->
181-
Logger.warn("Unable to update server description because of #{inspect(error)}")
181+
warning("Unable to update server description because of #{inspect(error)}")
182182
state
183183
end
184184
end
@@ -195,7 +195,7 @@ defmodule Mongo.Monitor do
195195
%{state | round_trip_time: round_trip_time}
196196

197197
error ->
198-
Logger.warn("Unable to round trip time because of #{inspect(error)}")
198+
warning("Unable to round trip time because of #{inspect(error)}")
199199
state
200200
end
201201
end
@@ -212,7 +212,7 @@ defmodule Mongo.Monitor do
212212
%{state | mode: :streaming_mode, streaming_pid: pid, heartbeat_frequency_ms: 10_000}
213213

214214
error ->
215-
Logger.warn("Unable to start the streaming hello monitor, because of #{inspect(error)}")
215+
warning("Unable to start the streaming hello monitor, because of #{inspect(error)}")
216216
state
217217
end
218218
end
@@ -284,4 +284,14 @@ defmodule Mongo.Monitor do
284284
def info(message) do
285285
Logger.info(IO.ANSI.format([:light_magenta, :bright, message]))
286286
end
287+
288+
if macro_exported?(Logger, :warning, 2) do
289+
defp warning(message) do
290+
Logger.warning(message)
291+
end
292+
else
293+
defp warning(message) do
294+
Logger.warn(message)
295+
end
296+
end
287297
end

lib/mongo/url_parser.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ defmodule Mongo.UrlParser do
137137

138138
with url_char <- String.to_charlist(url),
139139
{:ok, {_, _, _, _, _, srv_record}} <-
140-
:inet_res.getbyname('_mongodb._tcp.' ++ url_char, :srv),
140+
:inet_res.getbyname(~c"_mongodb._tcp." ++ url_char, :srv),
141141
{:ok, host} <- get_host_srv(srv_record),
142142
{:ok, {_, _, _, _, _, txt_record}} <- :inet_res.getbyname(url_char, :txt),
143143
txt <- "#{orig_options}&#{txt_record}&ssl=true" do

mix.exs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,17 @@ defmodule Mongodb.Mixfile do
2323

2424
def application do
2525
[
26-
applications: applications(Mix.env()),
2726
env: [],
28-
extra_applications: [:crypto, :ssl, :eex],
27+
extra_applications: [:logger, :crypto, :ssl],
2928
mod: {Mongo.App, []}
3029
]
3130
end
3231

33-
def applications(:test), do: [:logger, :connection, :db_connection]
34-
def applications(_), do: [:logger, :connection, :db_connection]
35-
3632
defp deps do
3733
[
3834
{:telemetry, "~> 1.0"},
3935
{:db_connection, "~> 2.4.1"},
40-
{:decimal, "~> 2.0"},
36+
{:decimal, "~> 2.1.1"},
4137
{:patch, "~> 0.12.0", only: [:dev, :test]},
4238
{:jason, "~> 1.3", only: [:dev, :test]},
4339
{:credo, "~> 1.6.1", only: [:dev, :test], runtime: false},

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
66
"credo": {:hex, :credo, "1.6.4", "ddd474afb6e8c240313f3a7b0d025cc3213f0d171879429bf8535d7021d9ad78", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "c28f910b61e1ff829bffa056ef7293a8db50e87f2c57a9b5c3f57eee124536b7"},
77
"db_connection": {:hex, :db_connection, "2.4.1", "6411f6e23f1a8b68a82fa3a36366d4881f21f47fc79a9efb8c615e62050219da", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ea36d226ec5999781a9a8ad64e5d8c4454ecedc7a4d643e4832bf08efca01f00"},
8-
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
8+
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
99
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
1010
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm", "6c32a70ed5d452c6650916555b1f96c79af5fc4bf286997f8b15f213de786f73"},
1111
"earmark": {:hex, :earmark, "1.4.15", "2c7f924bf495ec1f65bd144b355d0949a05a254d0ec561740308a54946a67888", [:mix], [{:earmark_parser, ">= 1.4.13", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "3b1209b85bc9f3586f370f7c363f6533788fb4e51db23aa79565875e7f9999ee"},

test/bson_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ defmodule BSONTest do
112112
assert encode(@map_23) == @bin_23
113113
assert encode(@map_24) == @bin_24
114114
assert encode(@map_25) == @bin_25
115-
assert encode(@map_26) == @bin_26
115+
assert @map_26 |> encode() |> decode() == %{"age" => 27, "name" => "John"}
116116
end
117117

118118
test "decode" do

test/mongo/connection_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ defmodule Mongo.ConnectionTest do
6969
end
7070

7171
defp connect_ssl do
72-
assert {:ok, pid} = Mongo.start_link(hostname: "localhost", database: "mongodb_test", ssl: true, ssl_opts: [ciphers: ['AES256-GCM-SHA384'], versions: [:"tlsv1.2"]])
72+
assert {:ok, pid} = Mongo.start_link(hostname: "localhost", database: "mongodb_test", ssl: true, ssl_opts: [ciphers: [~c"AES256-GCM-SHA384"], versions: [:"tlsv1.2"]])
7373
pid
7474
end
7575

test/mongo/cursor_test.exs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,18 @@ defmodule Mongo.CursorTest do
3838
# issue #35: Crash executing find function without enough permission
3939
test "matching errors in the next function of the stream api", c do
4040
assert {:error,
41-
%Mongo.Error{__exception__: true, code: 2, error_labels: '', fail_command: false, host: nil, message: "unknown operator: $gth", resumable: false, retryable_reads: false, retryable_writes: false, not_writable_primary_or_recovering: false}} ==
41+
%Mongo.Error{
42+
__exception__: true,
43+
code: 2,
44+
error_labels: ~c"",
45+
fail_command: false,
46+
host: nil,
47+
message: "unknown operator: $gth",
48+
resumable: false,
49+
retryable_reads: false,
50+
retryable_writes: false,
51+
not_writable_primary_or_recovering: false
52+
}} ==
4253
Mongo.find(c.pid, "test", _id: ["$gth": 1])
4354
end
4455
end

0 commit comments

Comments
 (0)