mirror of
https://github.com/valitydev/dmt-client.git
synced 2024-11-06 09:25:16 +00:00
* fix: Fix API signatures * fix: Fix get_snap version_not_found case
This commit is contained in:
parent
53924f4de4
commit
1a8404ae52
@ -68,6 +68,10 @@
|
|||||||
-type object_filter() :: fun((object_type(), domain_object()) -> boolean()).
|
-type object_filter() :: fun((object_type(), domain_object()) -> boolean()).
|
||||||
-type object_folder(Acc) :: fun((object_type(), domain_object(), Acc) -> Acc).
|
-type object_folder(Acc) :: fun((object_type(), domain_object(), Acc) -> Acc).
|
||||||
-type domain_object() :: dmsl_domain_thrift:'DomainObject'().
|
-type domain_object() :: dmsl_domain_thrift:'DomainObject'().
|
||||||
|
%% HACK: this is type required for checkout_objects_by_type:
|
||||||
|
%% domain_object is any object from union, tagged with it's name
|
||||||
|
%% yet there's no way to extract typespecs for untagged objects
|
||||||
|
-type untagged_domain_object() :: tuple().
|
||||||
-type versioned_object() :: dmsl_domain_config_thrift:'VersionedObject'().
|
-type versioned_object() :: dmsl_domain_config_thrift:'VersionedObject'().
|
||||||
-type domain() :: dmsl_domain_thrift:'Domain'().
|
-type domain() :: dmsl_domain_thrift:'Domain'().
|
||||||
-type history() :: dmsl_domain_config_thrift:'History'().
|
-type history() :: dmsl_domain_config_thrift:'History'().
|
||||||
@ -118,15 +122,15 @@ checkout_versioned_object(Reference, ObjectReference, Opts) ->
|
|||||||
Version = ref_to_version(Reference),
|
Version = ref_to_version(Reference),
|
||||||
#'VersionedObject'{version = Version, object = checkout_object(Reference, ObjectReference, Opts)}.
|
#'VersionedObject'{version = Version, object = checkout_object(Reference, ObjectReference, Opts)}.
|
||||||
|
|
||||||
-spec checkout_objects_by_type(object_type()) -> [domain_object()] | no_return().
|
-spec checkout_objects_by_type(object_type()) -> [untagged_domain_object()] | no_return().
|
||||||
checkout_objects_by_type(ObjectType) ->
|
checkout_objects_by_type(ObjectType) ->
|
||||||
checkout_objects_by_type(latest, ObjectType).
|
checkout_objects_by_type(latest, ObjectType).
|
||||||
|
|
||||||
-spec checkout_objects_by_type(version(), object_type()) -> [domain_object()] | no_return().
|
-spec checkout_objects_by_type(version(), object_type()) -> [untagged_domain_object()] | no_return().
|
||||||
checkout_objects_by_type(Reference, ObjectType) ->
|
checkout_objects_by_type(Reference, ObjectType) ->
|
||||||
checkout_objects_by_type(Reference, ObjectType, #{}).
|
checkout_objects_by_type(Reference, ObjectType, #{}).
|
||||||
|
|
||||||
-spec checkout_objects_by_type(version(), object_type(), opts()) -> [domain_object()] | no_return().
|
-spec checkout_objects_by_type(version(), object_type(), opts()) -> [untagged_domain_object()] | no_return().
|
||||||
checkout_objects_by_type(Reference, ObjectType, Opts) ->
|
checkout_objects_by_type(Reference, ObjectType, Opts) ->
|
||||||
Version = ref_to_version(Reference),
|
Version = ref_to_version(Reference),
|
||||||
unwrap(dmt_client_cache:get_objects_by_type(Version, ObjectType, Opts)).
|
unwrap(dmt_client_cache:get_objects_by_type(Version, ObjectType, Opts)).
|
||||||
@ -162,23 +166,23 @@ checkout_fold_objects(Reference, Folder, Acc, Opts) ->
|
|||||||
Version = ref_to_version(Reference),
|
Version = ref_to_version(Reference),
|
||||||
unwrap(dmt_client_cache:fold_objects(Version, Folder, Acc, Opts)).
|
unwrap(dmt_client_cache:fold_objects(Version, Folder, Acc, Opts)).
|
||||||
|
|
||||||
-spec commit(version(), commit()) -> version() | no_return().
|
-spec commit(vsn(), commit()) -> vsn() | no_return().
|
||||||
commit(Version, Commit) ->
|
commit(Version, Commit) ->
|
||||||
commit(Version, Commit, #{}).
|
commit(Version, Commit, #{}).
|
||||||
|
|
||||||
-spec commit(version(), commit(), opts()) -> version() | no_return().
|
-spec commit(vsn(), commit(), opts()) -> vsn() | no_return().
|
||||||
commit(Version, Commit, Opts) ->
|
commit(Version, Commit, Opts) ->
|
||||||
dmt_client_backend:commit(Version, Commit, Opts).
|
dmt_client_backend:commit(Version, Commit, Opts).
|
||||||
|
|
||||||
-spec get_last_version() -> version().
|
-spec get_last_version() -> vsn().
|
||||||
get_last_version() ->
|
get_last_version() ->
|
||||||
dmt_client_cache:get_last_version().
|
dmt_client_cache:get_last_version().
|
||||||
|
|
||||||
-spec pull_range(version(), limit()) -> history() | no_return().
|
-spec pull_range(vsn(), limit()) -> history() | no_return().
|
||||||
pull_range(Version, Limit) ->
|
pull_range(Version, Limit) ->
|
||||||
pull_range(Version, Limit, #{}).
|
pull_range(Version, Limit, #{}).
|
||||||
|
|
||||||
-spec pull_range(version(), limit(), opts()) -> history() | no_return().
|
-spec pull_range(vsn(), limit(), opts()) -> history() | no_return().
|
||||||
pull_range(Version, Limit, Opts) ->
|
pull_range(Version, Limit, Opts) ->
|
||||||
dmt_client_backend:pull_range(Version, Limit, Opts).
|
dmt_client_backend:pull_range(Version, Limit, Opts).
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ ensure_version(Version, Opts) ->
|
|||||||
|
|
||||||
-spec do_get(dmt_client:vsn()) -> {ok, dmt_client:snapshot()} | {error, version_not_found}.
|
-spec do_get(dmt_client:vsn()) -> {ok, dmt_client:snapshot()} | {error, version_not_found}.
|
||||||
do_get(Version) ->
|
do_get(Version) ->
|
||||||
case get_snap(Version) of
|
case fetch_snap(Version) of
|
||||||
{ok, Snap} ->
|
{ok, Snap} ->
|
||||||
build_snapshot(Snap);
|
build_snapshot(Snap);
|
||||||
{error, version_not_found} = Error ->
|
{error, version_not_found} = Error ->
|
||||||
@ -226,8 +226,10 @@ do_get(Version) ->
|
|||||||
-spec do_get_object(dmt_client:vsn(), dmt_client:object_ref()) ->
|
-spec do_get_object(dmt_client:vsn(), dmt_client:object_ref()) ->
|
||||||
{ok, dmt_client:domain_object()} | {error, version_not_found | object_not_found}.
|
{ok, dmt_client:domain_object()} | {error, version_not_found | object_not_found}.
|
||||||
do_get_object(Version, ObjectRef) ->
|
do_get_object(Version, ObjectRef) ->
|
||||||
{ok, #snap{tid = TID}} = get_snap(Version),
|
try
|
||||||
try ets:lookup(TID, ObjectRef) of
|
Snap = get_snap(Version),
|
||||||
|
ets:lookup(Snap#snap.tid, ObjectRef)
|
||||||
|
of
|
||||||
[#object{obj = Object}] ->
|
[#object{obj = Object}] ->
|
||||||
{ok, Object};
|
{ok, Object};
|
||||||
[] ->
|
[] ->
|
||||||
@ -241,11 +243,13 @@ do_get_object(Version, ObjectRef) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
do_get_objects_by_type(Version, ObjectType) ->
|
do_get_objects_by_type(Version, ObjectType) ->
|
||||||
{ok, #snap{tid = TID}} = get_snap(Version),
|
|
||||||
MatchSpec = [
|
MatchSpec = [
|
||||||
{{object, '_', {ObjectType, '$1'}}, [], ['$1']}
|
{{object, '_', {ObjectType, '$1'}}, [], ['$1']}
|
||||||
],
|
],
|
||||||
try ets:select(TID, MatchSpec) of
|
try
|
||||||
|
Snap = get_snap(Version),
|
||||||
|
ets:select(Snap#snap.tid, MatchSpec)
|
||||||
|
of
|
||||||
Result ->
|
Result ->
|
||||||
{ok, Result}
|
{ok, Result}
|
||||||
catch
|
catch
|
||||||
@ -255,11 +259,13 @@ do_get_objects_by_type(Version, ObjectType) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
do_fold_objects(Version, Folder, Acc) ->
|
do_fold_objects(Version, Folder, Acc) ->
|
||||||
{ok, #snap{tid = TID}} = get_snap(Version),
|
|
||||||
MappedFolder = fun({object, {Type, _Ref}, {Type, Object}}, AccIn) ->
|
MappedFolder = fun({object, {Type, _Ref}, {Type, Object}}, AccIn) ->
|
||||||
Folder(Type, Object, AccIn)
|
Folder(Type, Object, AccIn)
|
||||||
end,
|
end,
|
||||||
try ets:foldl(MappedFolder, Acc, TID) of
|
try
|
||||||
|
Snap = get_snap(Version),
|
||||||
|
ets:foldl(MappedFolder, Acc, Snap#snap.tid)
|
||||||
|
of
|
||||||
Result ->
|
Result ->
|
||||||
{ok, Result}
|
{ok, Result}
|
||||||
catch
|
catch
|
||||||
@ -270,7 +276,7 @@ do_fold_objects(Version, Folder, Acc) ->
|
|||||||
|
|
||||||
-spec put_snapshot(dmt_client:snapshot()) -> ok.
|
-spec put_snapshot(dmt_client:snapshot()) -> ok.
|
||||||
put_snapshot(#'Snapshot'{version = Version, domain = Domain}) ->
|
put_snapshot(#'Snapshot'{version = Version, domain = Domain}) ->
|
||||||
case get_snap(Version) of
|
case fetch_snap(Version) of
|
||||||
{ok, _Snap} ->
|
{ok, _Snap} ->
|
||||||
ok;
|
ok;
|
||||||
{error, version_not_found} ->
|
{error, version_not_found} ->
|
||||||
@ -296,8 +302,15 @@ put_domain_to_table(TID, Domain) ->
|
|||||||
Domain
|
Domain
|
||||||
).
|
).
|
||||||
|
|
||||||
-spec get_snap(dmt_client:vsn()) -> {ok, snap()} | {error, version_not_found}.
|
-spec get_snap(dmt_client:vsn()) -> snap() | no_return().
|
||||||
get_snap(Version) ->
|
get_snap(Version) ->
|
||||||
|
case fetch_snap(Version) of
|
||||||
|
{ok, Snap} -> Snap;
|
||||||
|
{error, version_not_found} -> error(badarg)
|
||||||
|
end.
|
||||||
|
|
||||||
|
-spec fetch_snap(dmt_client:vsn()) -> {ok, snap()} | {error, version_not_found}.
|
||||||
|
fetch_snap(Version) ->
|
||||||
case ets:lookup(?TABLE, Version) of
|
case ets:lookup(?TABLE, Version) of
|
||||||
[Snap] ->
|
[Snap] ->
|
||||||
_ = update_last_access(Version),
|
_ = update_last_access(Version),
|
||||||
|
Loading…
Reference in New Issue
Block a user