Skip to content

Commit 32a3be3

Browse files
authored
v4.0.2 prep (#28)
Adds dialyxir, addresses dialyzer warnings, credo fixes, adds code_quality alias, updates documentation with info about latest local DDB version.
1 parent 460521c commit 32a3be3

File tree

9 files changed

+89
-63
lines changed

9 files changed

+89
-63
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## v4.0.2 - 2021-12-24
4+
5+
- Add :consistent_read option in scan_opts spec
6+
- Add `code_quality` alias
7+
- Adds dialyxir to dev dependencies
8+
- Various credo and dialyzer fixes
9+
- Fixes typos in documentation and README
10+
311
## v4.0.1 - 2021-04-26
412

513
- Update dependencies

CONTRIBUTING.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ Contributions to ExAws.Dynamo are always welcome! For contributions to this part
66
Before submitting any PR, please make sure that the code is adequately tested, formatted, and checked for other issues... in other words, please run
77

88
```bash
9-
mix format
10-
mix credo
9+
# a convenient alias for runnin `mix format`, `mix credo --strict`, and `mix dialyzer`
10+
mix code_quality
11+
```
12+
13+
and
14+
15+
```bash
1116
mix test
1217
```
1318

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Documentation for **ExAwsDynamo** can be found at [https://hexdocs.pm/ex_aws_dyn
3131

3232
### DynamoDB Local
3333

34-
If you are running this module against a local development instance of DynamoDB, you'll want to make sure that you have installed the latest version, `1.15.0` (released 2021-02-08). You can find links to download the latest version [here](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html).
34+
If you are running this module against a local development instance of DynamoDB, you'll want to make sure that you have installed the latest version, `1.17.2` (released 2021-12-16). You can find links to download the latest version [here](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html).
3535

3636
## Configuration
3737

lib/ex_aws/dynamo.ex

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ defmodule ExAws.Dynamo do
6262

6363
import ExAws.Utils, only: [camelize: 1, camelize_keys: 1, camelize_keys: 2, upcase: 1]
6464
alias __MODULE__
65+
alias ExAws.Dynamo.{Decoder, Lazy}
66+
alias ExAws.Operation.JSON
6567

6668
@nested_opts [:exclusive_start_key, :expression_attribute_values, :expression_attribute_names]
6769
@upcase_opts [:return_values, :return_item_collection_metrics, :select, :total_segments]
@@ -125,8 +127,8 @@ defmodule ExAws.Dynamo do
125127
|> Dynamo.decode_item(as: User)
126128
```
127129
"""
128-
@spec decode_item(Map.t()) :: Map.t()
129-
@spec decode_item(Map.t(), as: atom) :: Map.t()
130+
@spec decode_item(map()) :: map()
131+
@spec decode_item(map(), as: atom) :: map()
130132
def decode_item(item, opts \\ [])
131133

132134
def decode_item(%{"Items" => items}, opts) do
@@ -138,12 +140,12 @@ defmodule ExAws.Dynamo do
138140
end
139141

140142
def decode_item(item, opts) do
141-
ExAws.Dynamo.Decoder.decode(item, opts)
143+
Decoder.decode(item, opts)
142144
end
143145

144146
@doc "List tables"
145-
@spec list_tables() :: ExAws.Operation.JSON.t()
146-
def list_tables() do
147+
@spec list_tables() :: JSON.t()
148+
def list_tables do
147149
request(:list_tables, %{})
148150
end
149151

@@ -163,7 +165,7 @@ defmodule ExAws.Dynamo do
163165
read_capacity :: pos_integer,
164166
write_capacity :: pos_integer,
165167
billing_mode :: dynamo_billing_types
166-
) :: ExAws.Operation.JSON.t()
168+
) :: JSON.t()
167169
def create_table(
168170
name,
169171
primary_key,
@@ -252,10 +254,10 @@ defmodule ExAws.Dynamo do
252254
key_definitions :: key_definitions,
253255
read_capacity :: pos_integer,
254256
write_capacity :: pos_integer,
255-
global_indexes :: [Map.t()],
256-
local_indexes :: [Map.t()],
257+
global_indexes :: [map()],
258+
local_indexes :: [map()],
257259
billing_mode :: dynamo_billing_types
258-
) :: ExAws.ExAws.Operation.JSON.t()
260+
) :: JSON.t()
259261
def create_table(
260262
name,
261263
key_schema,
@@ -303,7 +305,7 @@ defmodule ExAws.Dynamo do
303305
read_capacity :: pos_integer,
304306
write_capacity :: pos_integer,
305307
billing_mode :: dynamo_billing_types
306-
) :: Map.t()
308+
) :: map()
307309
defp build_billing_mode(read_capacity, write_capacity, :provisioned) do
308310
%{
309311
"BillingMode" => "PROVISIONED",
@@ -320,14 +322,14 @@ defmodule ExAws.Dynamo do
320322
end
321323

322324
@doc "Describe table"
323-
@spec describe_table(name :: binary) :: ExAws.Operation.JSON.t()
325+
@spec describe_table(name :: binary) :: JSON.t()
324326
def describe_table(name) do
325327
request(:describe_table, %{"TableName" => name})
326328
end
327329

328330
@doc "Update Table"
329-
@spec update_table(name :: binary, attributes :: Keyword.t() | Map.t()) ::
330-
ExAws.Operation.JSON.t()
331+
@spec update_table(name :: binary, attributes :: Keyword.t() | map()) ::
332+
JSON.t()
331333
def update_table(name, attributes) do
332334
data =
333335
attributes
@@ -338,46 +340,46 @@ defmodule ExAws.Dynamo do
338340
request(:update_table, data)
339341
end
340342

341-
@spec maybe_convert_billing_mode(attributes :: Keyword.t() | Map.t()) :: Keyword.t() | Map.t()
343+
@spec maybe_convert_billing_mode(attributes :: Keyword.t() | map()) :: Keyword.t() | map()
342344
defp maybe_convert_billing_mode(attributes) do
343345
case attributes[:billing_mode] do
344346
nil -> attributes
345347
_ -> convert_billing_mode(attributes, attributes[:billing_mode])
346348
end
347349
end
348350

349-
@spec convert_billing_mode(attributes :: Keyword.t() | Map.t(), dynamo_billing_types) ::
350-
Keyword.t() | Map.t()
351+
@spec convert_billing_mode(attributes :: Keyword.t() | map(), dynamo_billing_types) ::
352+
Keyword.t() | map()
351353
defp convert_billing_mode(attributes, :provisioned),
352354
do: do_convert_billing_mode(attributes, "PROVISIONED")
353355

354356
defp convert_billing_mode(attributes, :pay_per_request),
355357
do: do_convert_billing_mode(attributes, "PAY_PER_REQUEST")
356358

357-
@spec do_convert_billing_mode(attributes :: Keyword.t() | Map.t(), value :: String.t()) ::
358-
Keyword.t() | Map.t()
359+
@spec do_convert_billing_mode(attributes :: Keyword.t() | map(), value :: String.t()) ::
360+
Keyword.t() | map()
359361
defp do_convert_billing_mode(attributes, value) when is_map(attributes),
360362
do: Map.replace!(attributes, :billing_mode, value)
361363

362364
defp do_convert_billing_mode(attributes, value) when is_list(attributes),
363365
do: Keyword.replace!(attributes, :billing_mode, value)
364366

365367
@doc "Delete Table"
366-
@spec delete_table(table :: binary) :: ExAws.Operation.JSON.t()
368+
@spec delete_table(table :: binary) :: JSON.t()
367369
def delete_table(table) do
368370
request(:delete_table, %{"TableName" => table})
369371
end
370372

371373
@doc "Update time to live"
372374
@spec update_time_to_live(table :: binary, ttl_attribute :: binary, enabled :: boolean) ::
373-
ExAws.Operation.JSON.t()
375+
JSON.t()
374376
def update_time_to_live(table, ttl_attribute, enabled) do
375377
data = build_time_to_live(ttl_attribute, enabled) |> Map.merge(%{"TableName" => table})
376378

377379
request(:update_time_to_live, data)
378380
end
379381

380-
@spec build_time_to_live(ttl_attribute :: binary, enabled :: boolean) :: Map.t()
382+
@spec build_time_to_live(ttl_attribute :: binary, enabled :: boolean) :: map()
381383
defp build_time_to_live("", _enabled) do
382384
%{}
383385
end
@@ -396,7 +398,7 @@ defmodule ExAws.Dynamo do
396398
end
397399

398400
@doc "Describe time to live"
399-
@spec describe_time_to_live(table :: binary) :: ExAws.Operation.JSON.t()
401+
@spec describe_time_to_live(table :: binary) :: JSON.t()
400402
def describe_time_to_live(table) do
401403
request(:describe_time_to_live, %{"TableName" => table})
402404
end
@@ -437,15 +439,15 @@ defmodule ExAws.Dynamo do
437439
| {:select, select_vals}
438440
| {:total_segments, pos_integer}
439441
]
440-
@spec scan(table_name :: table_name) :: ExAws.Operation.JSON.t()
441-
@spec scan(table_name :: table_name, opts :: scan_opts) :: ExAws.Operation.JSON.t()
442+
@spec scan(table_name :: table_name) :: JSON.t()
443+
@spec scan(table_name :: table_name, opts :: scan_opts) :: JSON.t()
442444
def scan(name, opts \\ []) do
443445
data =
444446
opts
445447
|> build_opts()
446448
|> Map.merge(%{"TableName" => name})
447449

448-
request(:scan, data, %{stream_builder: &ExAws.Dynamo.Lazy.stream_scan(name, opts, &1)})
450+
request(:scan, data, %{stream_builder: &Lazy.stream_scan(name, opts, &1)})
449451
end
450452

451453
@doc """
@@ -477,15 +479,15 @@ defmodule ExAws.Dynamo do
477479
| {:scan_index_forward, boolean}
478480
| {:select, select_vals}
479481
]
480-
@spec query(table_name :: table_name) :: ExAws.Operation.JSON.t()
481-
@spec query(table_name :: table_name, opts :: query_opts) :: ExAws.Operation.JSON.t()
482+
@spec query(table_name :: table_name) :: JSON.t()
483+
@spec query(table_name :: table_name, opts :: query_opts) :: JSON.t()
482484
def query(name, opts \\ []) do
483485
data =
484486
opts
485487
|> build_opts()
486488
|> Map.merge(%{"TableName" => name})
487489

488-
request(:query, data, %{stream_builder: &ExAws.Dynamo.Lazy.stream_query(name, opts, &1)})
490+
request(:query, data, %{stream_builder: &Lazy.stream_query(name, opts, &1)})
489491
end
490492

491493
@doc """
@@ -529,9 +531,9 @@ defmodule ExAws.Dynamo do
529531
| {:expression_attribute_names, expression_attribute_names_vals}
530532
| {:projection_expression, binary}
531533
]
532-
@spec batch_get_item(%{table_name => get_item}) :: ExAws.Operation.JSON.t()
534+
@spec batch_get_item(%{table_name => get_item}) :: JSON.t()
533535
@spec batch_get_item(%{table_name => get_item}, opts :: batch_get_item_opts) ::
534-
ExAws.Operation.JSON.t()
536+
JSON.t()
535537
def batch_get_item(data, opts \\ []) do
536538
request_items =
537539
data
@@ -571,9 +573,9 @@ defmodule ExAws.Dynamo do
571573
| {:return_item_collection_metrics, return_item_collection_metrics_vals}
572574
| {:return_values, return_values_vals}
573575
]
574-
@spec put_item(table_name :: table_name, record :: map()) :: ExAws.Operation.JSON.t()
576+
@spec put_item(table_name :: table_name, record :: map()) :: JSON.t()
575577
@spec put_item(table_name :: table_name, record :: map(), opts :: put_item_opts) ::
576-
ExAws.Operation.JSON.t()
578+
JSON.t()
577579
def put_item(name, record, opts \\ []) do
578580
data =
579581
opts
@@ -603,9 +605,9 @@ defmodule ExAws.Dynamo do
603605
{:return_consumed_capacity, return_consumed_capacity_vals}
604606
| {:return_item_collection_metrics, return_item_collection_metrics_vals}
605607
]
606-
@spec batch_write_item(%{table_name => [write_item]}) :: ExAws.Operation.JSON.t()
608+
@spec batch_write_item(%{table_name => [write_item]}) :: JSON.t()
607609
@spec batch_write_item(%{table_name => [write_item]}, opts :: batch_write_item_opts) ::
608-
ExAws.Operation.JSON.t()
610+
JSON.t()
609611
def batch_write_item(data, opts \\ []) do
610612
request_items =
611613
data
@@ -638,9 +640,9 @@ defmodule ExAws.Dynamo do
638640
| {:projection_expression, binary}
639641
| {:return_consumed_capacity, return_consumed_capacity_vals}
640642
]
641-
@spec get_item(table_name :: table_name, primary_key :: primary_key) :: ExAws.Operation.JSON.t()
643+
@spec get_item(table_name :: table_name, primary_key :: primary_key) :: JSON.t()
642644
@spec get_item(table_name :: table_name, primary_key :: primary_key, opts :: get_item_opts) ::
643-
ExAws.Operation.JSON.t()
645+
JSON.t()
644646
def get_item(name, primary_key, opts \\ []) do
645647
data =
646648
opts
@@ -672,7 +674,7 @@ defmodule ExAws.Dynamo do
672674
table_name :: table_name,
673675
primary_key :: primary_key,
674676
opts :: update_item_opts
675-
) :: ExAws.Operation.JSON.t()
677+
) :: JSON.t()
676678
def update_item(table_name, primary_key, update_opts) do
677679
data =
678680
update_opts
@@ -695,12 +697,12 @@ defmodule ExAws.Dynamo do
695697
| {:return_values, return_values_vals}
696698
]
697699
@spec delete_item(table_name :: table_name, primary_key :: primary_key) ::
698-
ExAws.Operation.JSON.t()
700+
JSON.t()
699701
@spec delete_item(
700702
table_name :: table_name,
701703
primary_key :: primary_key,
702704
opts :: delete_item_opts
703-
) :: ExAws.Operation.JSON.t()
705+
) :: JSON.t()
704706
def delete_item(name, primary_key, opts \\ []) do
705707
data =
706708
opts
@@ -727,8 +729,8 @@ defmodule ExAws.Dynamo do
727729
]
728730

729731
@spec transact_get_items(items :: [transact_get_item], transact_get_items_opts) ::
730-
ExAws.Operation.JSON.t()
731-
@spec transact_get_items(items :: [transact_get_item]) :: ExAws.Operation.JSON.t()
732+
JSON.t()
733+
@spec transact_get_items(items :: [transact_get_item]) :: JSON.t()
732734

733735
@doc """
734736
A synchronous operation that retrieves multiple items from one or more tables (but not from indexes) in a single account and region
@@ -801,8 +803,8 @@ defmodule ExAws.Dynamo do
801803
A synchronous write operation that groups up to 25 action requests
802804
"""
803805
@spec transact_write_items(items :: [transact_write_item], transact_write_items_opts) ::
804-
ExAws.Operation.JSON.t()
805-
@spec transact_write_items(items :: [transact_write_item]) :: ExAws.Operation.JSON.t()
806+
JSON.t()
807+
@spec transact_write_items(items :: [transact_write_item]) :: JSON.t()
806808
def transact_write_items(items, opts \\ []) do
807809
data =
808810
opts
@@ -896,7 +898,7 @@ defmodule ExAws.Dynamo do
896898
|> Atom.to_string()
897899
|> Macro.camelize()
898900

899-
ExAws.Operation.JSON.new(
901+
JSON.new(
900902
:dynamodb,
901903
%{
902904
data: data,

lib/ex_aws/dynamo/decoder.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ defmodule ExAws.Dynamo.Decoder do
88
This is important for handling nested maps if you wanted the nested maps
99
to have atom keys.
1010
"""
11+
12+
alias ExAws.Dynamo.Decodable
13+
1114
def decode(item, as: struct_module) do
1215
item
1316
|> decode
1417
|> binary_map_to_struct(struct_module)
15-
|> ExAws.Dynamo.Decodable.decode()
18+
|> Decodable.decode()
1619
end
1720

1821
@doc """
@@ -57,11 +60,9 @@ defmodule ExAws.Dynamo.Decoder do
5760

5861
@doc "Attempts to convert a number to a float, and then an integer"
5962
def binary_to_number(binary) when is_binary(binary) do
60-
try do
61-
String.to_float(binary)
62-
rescue
63-
ArgumentError -> String.to_integer(binary)
64-
end
63+
String.to_float(binary)
64+
rescue
65+
ArgumentError -> String.to_integer(binary)
6566
end
6667

6768
def binary_to_number(binary), do: binary

lib/ex_aws/dynamo/encoder.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ defmodule ExAws.Dynamo.Encoder do
1616
This is handled via the ExAws.Dynamo.Encodable protocol.
1717
"""
1818

19+
alias ExAws.Dynamo.Encodable
20+
1921
# These functions exist to ensure that encoding is idempotent.
2022
def encode(value), do: encode(value, [])
2123
def encode(%{"B" => _} = val, _), do: val
@@ -29,19 +31,17 @@ defmodule ExAws.Dynamo.Encoder do
2931
def encode(%{"S" => _} = val, _), do: val
3032
def encode(%{"SS" => _} = val, _), do: val
3133

32-
def encode(value, options) do
33-
ExAws.Dynamo.Encodable.encode(value, options)
34-
end
34+
def encode(value, options), do: Encodable.encode(value, options)
3535

3636
# Use this in case you want to encode something already in Dynamo format
3737
# for some reason I cannot fathom. If you find yourself using this, please open an issue
3838
# so I can find out why and better support this.
3939
def encode!(value, options \\ []) do
40-
ExAws.Dynamo.Encodable.encode(value, options)
40+
Encodable.encode(value, options)
4141
end
4242

4343
def encode_root(value, options \\ []) do
44-
case ExAws.Dynamo.Encodable.encode(value, options) do
44+
case Encodable.encode(value, options) do
4545
%{"M" => value} -> value
4646
%{"L" => value} -> value
4747
end

0 commit comments

Comments
 (0)