Skip to content

Commit

Permalink
feat: get_many_docs (#353)
Browse files Browse the repository at this point in the history
Signed-off-by: David Dal Busco <[email protected]>
  • Loading branch information
peterpeterparker authored Dec 9, 2023
1 parent 6b938e0 commit 837d67a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/declarations/satellite/satellite.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export interface _SERVICE {
deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
get_config: ActorMethod<[], Config>;
get_doc: ActorMethod<[string, string], [] | [Doc]>;
get_many_docs: ActorMethod<[Array<[string, string]>], Array<[string, [] | [Doc]]>>;
http_request: ActorMethod<[HttpRequest], HttpResponse>;
http_request_streaming_callback: ActorMethod<
[StreamingCallbackToken],
Expand Down
5 changes: 5 additions & 0 deletions src/declarations/satellite/satellite.factory.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ export const idlFactory = ({ IDL }) => {
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
get_config: IDL.Func([], [Config], []),
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
get_many_docs: IDL.Func(
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))],
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(Doc)))],
['query']
),
http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']),
http_request_streaming_callback: IDL.Func(
[StreamingCallbackToken],
Expand Down
5 changes: 5 additions & 0 deletions src/declarations/satellite/satellite.factory.did.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ export const idlFactory = ({ IDL }) => {
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
get_config: IDL.Func([], [Config], []),
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
get_many_docs: IDL.Func(
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))],
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(Doc)))],
['query']
),
http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']),
http_request_streaming_callback: IDL.Func(
[StreamingCallbackToken],
Expand Down
3 changes: 3 additions & 0 deletions src/satellite/satellite.did
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ service : () -> {
deposit_cycles : (DepositCyclesArgs) -> ();
get_config : () -> (Config);
get_doc : (text, text) -> (opt Doc) query;
get_many_docs : (vec record { text; text }) -> (
vec record { text; opt Doc },
) query;
http_request : (HttpRequest) -> (HttpResponse) query;
http_request_streaming_callback : (StreamingCallbackToken) -> (
StreamingCallbackHttpResponse,
Expand Down
10 changes: 10 additions & 0 deletions src/satellite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ fn list_docs(collection: CollectionKey, filter: ListParams) -> ListResults<Doc>
}
}

#[query]
fn get_many_docs(docs: Vec<(CollectionKey, Key)>) -> Vec<(Key, Option<Doc>)> {
docs.iter()
.map(|(collection, key)| {
let doc = get_doc(collection.clone(), key.clone());
(key.clone(), doc.clone())
})
.collect()
}

#[update]
fn set_many_docs(docs: Vec<(CollectionKey, Key, SetDoc)>) -> Vec<(Key, Doc)> {
let mut results: Vec<(Key, Doc)> = Vec::new();
Expand Down

0 comments on commit 837d67a

Please sign in to comment.