Skip to content

Commit

Permalink
doc_storage: more spec/type updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesaimonetti committed Dec 16, 2016
1 parent 69c7aca commit e13b1e6
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 28 deletions.
13 changes: 8 additions & 5 deletions core/kazoo_attachments/src/aws/kz_aws.erl
Original file line number Diff line number Diff line change
Expand Up @@ -378,21 +378,24 @@ timeout(#aws_config{timeout = 'undefined'}) -> ?DEFAULT_TIMEOUT;
timeout(#aws_config{timeout = Timeout}) -> Timeout.

%% Convert an aws_request record to return value as returned by http_headers_body
-spec request_to_return(#aws_request{}) -> {'ok', {headers(), binary()}} |
{'error', any()}.
-spec request_to_return(aws_request()) -> {'ok', {headers(), binary()}} |
{'error', any()}.
request_to_return(#aws_request{response_type = 'ok'
,response_headers = Headers
,response_body = Body}) ->
,response_body = Body
}) ->
{'ok', {[{string:to_lower(H), V} || {H, V} <- Headers], Body}};
request_to_return(#aws_request{response_type = 'error'
,error_type = httpc
,httpc_error_reason = Reason}) ->
,httpc_error_reason = Reason
}) ->
{'error', {'socket_error', Reason}};
request_to_return(#aws_request{response_type = 'error'
,error_type = 'aws'
,response_status = Status
,response_status_line = StatusLine
,response_body = Body}) ->
,response_body = Body
}) ->
{'error', {'http_error', Status, StatusLine, Body}}.

%% http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html
Expand Down
1 change: 1 addition & 0 deletions core/kazoo_attachments/src/aws/kz_aws.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
%% Service specific error information
should_retry :: boolean()
}).
-type aws_request() :: #aws_request{}.

-define(KZ_ATT_AWS_HRL, 'true').
-endif.
12 changes: 6 additions & 6 deletions core/kazoo_attachments/src/aws/kz_aws_retry.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
]).
-export_type([should_retry/0, retry_fun/0]).

-type should_retry() :: {'retry' | 'error', #aws_request{}}.
-type retry_fun() :: fun((#aws_request{}) -> should_retry()).
-type should_retry() :: {'retry' | 'error', aws_request()}.
-type retry_fun() :: fun((aws_request()) -> should_retry()).

%% Internal impl api
-export([request/3]).

%% Error returns maintained for backwards compatibility
-spec no_retry(#aws_request{}) -> should_retry().
-spec no_retry(aws_request()) -> should_retry().
no_retry(Request) ->
{'error', Request}.

Expand All @@ -32,11 +32,11 @@ backoff(Attempt) ->
%% It's likely this is too many retries for other services
-define(NUM_ATTEMPTS, 10).

-spec default_retry(#aws_request{}) -> should_retry().
-spec default_retry(aws_request()) -> should_retry().
default_retry(Request) ->
default_retry(Request, ?NUM_ATTEMPTS).

-spec default_retry(#aws_request{}, integer()) -> should_retry().
-spec default_retry(aws_request(), integer()) -> should_retry().
default_retry(#aws_request{attempt = Attempt} = Request, MaxAttempts)
when Attempt >= MaxAttempts ->
{'error', Request};
Expand All @@ -46,7 +46,7 @@ default_retry(#aws_request{attempt = Attempt} = Request, _) ->
backoff(Attempt),
{'retry', Request}.

-spec request(aws_config(), #aws_request{}, retry_fun()) -> #aws_request{}.
-spec request(aws_config(), aws_request(), retry_fun()) -> aws_request().
request(Config, #aws_request{attempt = 0} = Request, ResultFun) ->
request_and_retry(Config, ResultFun, {'retry', Request}).

Expand Down
1 change: 1 addition & 0 deletions core/kazoo_attachments/src/aws/kz_aws_s3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@ query_string_from_params(Params, "") ->
query_string_from_params(Params, _SubResource) ->
[$&, kz_aws_http:make_query_string(Params, 'no_assignment')].

-spec s3_result_fun(aws_request()) -> aws_request().
s3_result_fun(#aws_request{response_type = 'ok'} = Request) ->
Request;
s3_result_fun(#aws_request{response_type = 'error'
Expand Down
24 changes: 17 additions & 7 deletions core/kazoo_couch/src/kazoo_couch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ save_doc(Server, DbName, Doc, Options) ->
save_docs(Server, DbName, Docs, Options) ->
kz_couch_doc:save_docs(Server, DbName, Docs, Options).

-spec del_doc(kz_data:connection(), ne_binary(), kz_data:documents(), kz_data:options()) -> any().
-spec del_doc(kz_data:connection(), ne_binary(), kz_data:document(), kz_data:options()) ->
any().
del_doc(Server, DbName, Doc, Options) ->
kz_couch_doc:del_doc(Server, DbName, Doc, Options).

Expand Down Expand Up @@ -194,8 +195,8 @@ attachment_url(Server, DbName, DocId, AName, Options) ->
design_info(Server, DBName, Design) ->
kz_couch_view:design_info(Server, DBName, Design).

-spec all_design_docs(kz_data:connection(), ne_binary(), kz_data:connection()) -> any().
all_design_docs(Server, DBName, Options) ->
-spec all_design_docs(kz_data:connection(), ne_binary(), kz_data:options()) -> any().
all_design_docs(#server{}=Server, ?NE_BINARY = DBName, Options) ->
kz_couch_view:all_design_docs(Server, DBName, Options).

-spec get_results(kz_data:connection(), ne_binary(), ne_binary(), kz_data:options()) -> any().
Expand All @@ -214,12 +215,21 @@ all_docs(Server, DbName, Options) ->
version(#server{options=Options}) ->
props:get_value('driver_version', Options).

-spec db_local_filter(ne_binaries(), kz_data:options()) -> ne_binaries().
db_local_filter(List, Options) ->
[DB || DB <- List,
lists:all(fun(Option) ->
db_local_filter_option(Option, DB)
end, Options)].

all_valid_options(Options, DB)
].

-spec all_valid_options(kz_data:options(), ne_binary()) -> boolean().
all_valid_options(Options, DB) ->
lists:all(fun(Option) ->
db_local_filter_option(Option, DB)
end
,Options
).

-spec db_local_filter_option(kz_data:option(), ne_binary()) -> boolean().
db_local_filter_option({'start_key', Value}, DB) ->
DB >= Value;
db_local_filter_option({'startkey', Value}, DB) ->
Expand Down
4 changes: 2 additions & 2 deletions core/kazoo_couch/src/kz_couch_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ retry504s(Fun, Cnt) ->
%% @doc
%% @end
%%------------------------------------------------------------------------------
-spec new_connection(couch_connection() | #{}) ->
-spec new_connection(couch_connection() | map()) ->
server() |
{'error', 'timeout' | 'ehostunreach' | _}.
new_connection(#{}=Map) ->
Expand Down Expand Up @@ -203,7 +203,7 @@ db_url(#server{}=Conn, DbName) ->
%% returns the #db{} record
%% @end
%%------------------------------------------------------------------------------
-spec get_db(server(), ne_binary()) -> db().
-spec get_db(kz_data:connection(), ne_binary()) -> db().
get_db(#server{}=Conn, DbName) ->
{'ok', Db} = couchbeam:open_db(Conn, DbName),
Db.
Expand Down
2 changes: 1 addition & 1 deletion core/kazoo_couch/src/kz_couch_view.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ design_info(#server{}=Conn, DBName, Design) ->
Db = kz_couch_util:get_db(Conn, DBName),
do_get_design_info(Db, Design).

-spec all_design_docs(server(), ne_binary(), view_options()) ->
-spec all_design_docs(kz_data:connection(), ne_binary(), view_options()) ->
{'ok', kz_json:objects()} |
couchbeam_error().
all_design_docs(#server{}=Conn, DBName, Options) ->
Expand Down
6 changes: 3 additions & 3 deletions core/kazoo_data/src/kazoo_dataconnection_error.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
-type error(Type) :: {'error', Type}.
-type error() :: error('resource_not_available').


%% Server operations
-spec new_connection(kz_data:connection()) -> error().
-spec format_error(error(A)) -> error(A).
-spec new_connection(map()) -> error().
new_connection(_Map) ->
{'error', 'resource_not_available'}.

-spec format_error(error(A)) -> error(A).
format_error(Error) ->
Error.

Expand Down
12 changes: 8 additions & 4 deletions core/kazoo_data/src/kz_data.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
-include("kz_data.hrl").

-type connection() :: server() | any().
-type options() :: kz_proplist().
-type option() :: {atom(), term()}.
-type options() :: [option()].
-type document() :: kz_json:object().
-type documents() :: [document()].

-export_type([connection/0, options/0, document/0, documents/0]).
-export_type([connection/0
,option/0, options/0
,document/0
,documents/0
]).

-callback new_connection(ne_binary()) -> connection().
-callback new_connection(map()) -> connection().
-callback format_error(any()) -> any().


%% Connection operations
-callback get_db(connection(), ne_binary()) -> any().
-callback server_url(connection()) ->
Expand Down

0 comments on commit e13b1e6

Please sign in to comment.