From f8bddd42ce7e84979f45187131c7112ad05863ca Mon Sep 17 00:00:00 2001 From: ff137 Date: Fri, 26 Jul 2024 12:36:22 +0300 Subject: [PATCH] :sparkles: add order_by and descending options to scan in javascript wrapper Signed-off-by: ff137 --- .../aries-askar-nodejs/src/NodeJSAriesAskar.ts | 5 ++++- .../aries-askar-nodejs/src/library/bindings.ts | 13 ++++++++++++- .../aries-askar-react-native/cpp/ariesAskar.cpp | 4 +++- .../cpp/include/libaries_askar.h | 2 ++ .../aries-askar-shared/src/ariesAskar/AriesAskar.ts | 2 ++ .../packages/aries-askar-shared/src/store/Scan.ts | 10 ++++++++++ 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/wrappers/javascript/packages/aries-askar-nodejs/src/NodeJSAriesAskar.ts b/wrappers/javascript/packages/aries-askar-nodejs/src/NodeJSAriesAskar.ts index 8f221e302..a7775760c 100644 --- a/wrappers/javascript/packages/aries-askar-nodejs/src/NodeJSAriesAskar.ts +++ b/wrappers/javascript/packages/aries-askar-nodejs/src/NodeJSAriesAskar.ts @@ -787,7 +787,8 @@ export class NodeJSAriesAskar implements AriesAskar { } public async scanStart(options: ScanStartOptions): Promise { - const { category, limit, offset, profile, storeHandle, tagFilter } = serializeArguments(options) + const { category, descending, limit, offset, orderBy, profile, storeHandle, tagFilter } = + serializeArguments(options) const handle = await this.promisifyWithResponse( (cb, cbId) => this.nativeAriesAskar.askar_scan_start( @@ -797,6 +798,8 @@ export class NodeJSAriesAskar implements AriesAskar { tagFilter, +offset || 0, +limit || -1, + orderBy, + descending, cb, cbId, ), diff --git a/wrappers/javascript/packages/aries-askar-nodejs/src/library/bindings.ts b/wrappers/javascript/packages/aries-askar-nodejs/src/library/bindings.ts index e1007d5e9..bb5db9cc0 100644 --- a/wrappers/javascript/packages/aries-askar-nodejs/src/library/bindings.ts +++ b/wrappers/javascript/packages/aries-askar-nodejs/src/library/bindings.ts @@ -136,7 +136,18 @@ export const nativeBindings = { askar_scan_next: [FFI_ERROR_CODE, [FFI_SCAN_HANDLE, FFI_CALLBACK_PTR, FFI_CALLBACK_ID]], askar_scan_start: [ FFI_ERROR_CODE, - [FFI_STORE_HANDLE, FFI_STRING, FFI_STRING, FFI_STRING, FFI_INT64, FFI_INT64, FFI_CALLBACK_PTR, FFI_CALLBACK_ID], + [ + FFI_STORE_HANDLE, + FFI_STRING, + FFI_STRING, + FFI_STRING, + FFI_INT64, + FFI_INT64, + FFI_STRING, + FFI_INT8, + FFI_CALLBACK_PTR, + FFI_CALLBACK_ID + ], ], askar_session_close: [FFI_ERROR_CODE, [FFI_SESSION_HANDLE, FFI_INT8, FFI_CALLBACK_PTR, FFI_CALLBACK_ID]], diff --git a/wrappers/javascript/packages/aries-askar-react-native/cpp/ariesAskar.cpp b/wrappers/javascript/packages/aries-askar-react-native/cpp/ariesAskar.cpp index 864877e80..9ae5acd57 100644 --- a/wrappers/javascript/packages/aries-askar-react-native/cpp/ariesAskar.cpp +++ b/wrappers/javascript/packages/aries-askar-react-native/cpp/ariesAskar.cpp @@ -502,6 +502,8 @@ jsi::Value scanStart(jsi::Runtime &rt, jsi::Object options) { auto profile = jsiToValue(rt, options, "profile", true); auto offset = jsiToValue(rt, options, "offset", true); auto limit = jsiToValue(rt, options, "limit", true); + auto orderBy = jsiToValue(rt, options, "orderBy", true); + auto descending = jsiToValue(rt, options, "descending"); jsi::Function cb = options.getPropertyAsFunction(rt, "cb"); State *state = new State(&cb); @@ -510,7 +512,7 @@ jsi::Value scanStart(jsi::Runtime &rt, jsi::Object options) { ErrorCode code = askar_scan_start( storeHandle, profile.length() ? profile.c_str() : nullptr, category.c_str(), tagFilter.length() ? tagFilter.c_str() : nullptr, - offset, limit, callbackWithResponse, CallbackId(state)); + offset, limit, orderBy, descending, callbackWithResponse, CallbackId(state)); return createReturnValue(rt, code, nullptr); }; diff --git a/wrappers/javascript/packages/aries-askar-react-native/cpp/include/libaries_askar.h b/wrappers/javascript/packages/aries-askar-react-native/cpp/include/libaries_askar.h index 103dc47fe..6a8cb52b3 100644 --- a/wrappers/javascript/packages/aries-askar-react-native/cpp/include/libaries_askar.h +++ b/wrappers/javascript/packages/aries-askar-react-native/cpp/include/libaries_askar.h @@ -440,6 +440,8 @@ ErrorCode askar_scan_start(StoreHandle handle, FfiStr tag_filter, int64_t offset, int64_t limit, + FfiStr order_by, + int8_t descending, void (*cb)(CallbackId cb_id, ErrorCode err, ScanHandle handle), CallbackId cb_id); diff --git a/wrappers/javascript/packages/aries-askar-shared/src/ariesAskar/AriesAskar.ts b/wrappers/javascript/packages/aries-askar-shared/src/ariesAskar/AriesAskar.ts index 06d9d5ae2..34d43abd9 100644 --- a/wrappers/javascript/packages/aries-askar-shared/src/ariesAskar/AriesAskar.ts +++ b/wrappers/javascript/packages/aries-askar-shared/src/ariesAskar/AriesAskar.ts @@ -211,6 +211,8 @@ export type ScanStartOptions = { tagFilter?: Record offset?: number limit?: number + orderBy?: string + descending: boolean } export type SessionCloseOptions = { diff --git a/wrappers/javascript/packages/aries-askar-shared/src/store/Scan.ts b/wrappers/javascript/packages/aries-askar-shared/src/store/Scan.ts index fb9ca2144..d6300d37b 100644 --- a/wrappers/javascript/packages/aries-askar-shared/src/store/Scan.ts +++ b/wrappers/javascript/packages/aries-askar-shared/src/store/Scan.ts @@ -16,11 +16,15 @@ export class Scan { private tagFilter?: Record private offset?: number private limit?: number + private orderBy?: string + private descending: boolean public constructor({ category, limit, offset, + orderBy, + descending, profile, tagFilter, store, @@ -30,6 +34,8 @@ export class Scan { tagFilter?: Record offset?: number limit?: number + orderBy?: string, + descending: boolean, store: Store }) { this.category = category @@ -37,6 +43,8 @@ export class Scan { this.tagFilter = tagFilter this.offset = offset this.limit = limit + this.orderBy = orderBy + this.descending = descending this.store = store } @@ -51,6 +59,8 @@ export class Scan { storeHandle: this.store.handle, limit: this.limit, offset: this.offset, + orderBy: this.orderBy, + descending: this.descending, tagFilter: this.tagFilter, profile: this.profile, category: this.category,