From 837d67aac28d9d6fe3135c030efaacb7a85a253f Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sat, 9 Dec 2023 10:01:55 +0100 Subject: [PATCH] feat: get_many_docs (#353) Signed-off-by: David Dal Busco --- src/declarations/satellite/satellite.did.d.ts | 1 + src/declarations/satellite/satellite.factory.did.js | 5 +++++ src/declarations/satellite/satellite.factory.did.mjs | 5 +++++ src/satellite/satellite.did | 3 +++ src/satellite/src/lib.rs | 10 ++++++++++ 5 files changed, 24 insertions(+) diff --git a/src/declarations/satellite/satellite.did.d.ts b/src/declarations/satellite/satellite.did.d.ts index c73f34047..977d36051 100644 --- a/src/declarations/satellite/satellite.did.d.ts +++ b/src/declarations/satellite/satellite.did.d.ts @@ -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], diff --git a/src/declarations/satellite/satellite.factory.did.js b/src/declarations/satellite/satellite.factory.did.js index dc677521d..7b06593c4 100644 --- a/src/declarations/satellite/satellite.factory.did.js +++ b/src/declarations/satellite/satellite.factory.did.js @@ -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], diff --git a/src/declarations/satellite/satellite.factory.did.mjs b/src/declarations/satellite/satellite.factory.did.mjs index dc677521d..7b06593c4 100644 --- a/src/declarations/satellite/satellite.factory.did.mjs +++ b/src/declarations/satellite/satellite.factory.did.mjs @@ -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], diff --git a/src/satellite/satellite.did b/src/satellite/satellite.did index 6fc10b629..eae9ebdb5 100644 --- a/src/satellite/satellite.did +++ b/src/satellite/satellite.did @@ -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, diff --git a/src/satellite/src/lib.rs b/src/satellite/src/lib.rs index d696d446c..9dfef1edb 100644 --- a/src/satellite/src/lib.rs +++ b/src/satellite/src/lib.rs @@ -178,6 +178,16 @@ fn list_docs(collection: CollectionKey, filter: ListParams) -> ListResults } } +#[query] +fn get_many_docs(docs: Vec<(CollectionKey, Key)>) -> Vec<(Key, Option)> { + 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();