Skip to content

Commit

Permalink
✨ add order_by and descending options to scan in javascript wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed Jul 26, 2024
1 parent a38d6dc commit cf5787e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,8 @@ export class NodeJSAriesAskar implements AriesAskar {
}

public async scanStart(options: ScanStartOptions): Promise<ScanHandle> {
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<number>(
(cb, cbId) =>
this.nativeAriesAskar.askar_scan_start(
Expand All @@ -797,6 +798,8 @@ export class NodeJSAriesAskar implements AriesAskar {
tagFilter,
+offset || 0,
+limit || -1,
orderBy,
descending,
cb,
cbId,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ jsi::Value scanStart(jsi::Runtime &rt, jsi::Object options) {
auto profile = jsiToValue<std::string>(rt, options, "profile", true);
auto offset = jsiToValue<int64_t>(rt, options, "offset", true);
auto limit = jsiToValue<int64_t>(rt, options, "limit", true);
auto orderBy = jsiToValue<std::string>(rt, options, "orderBy", true);
auto descending = jsiToValue<int8_t>(rt, options, "descending");

jsi::Function cb = options.getPropertyAsFunction(rt, "cb");
State *state = new State(&cb);
Expand All @@ -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);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ export type ScanStartOptions = {
tagFilter?: Record<string, unknown>
offset?: number
limit?: number
orderBy?: string
descending: boolean
}

export type SessionCloseOptions = {
Expand Down
10 changes: 10 additions & 0 deletions wrappers/javascript/packages/aries-askar-shared/src/store/Scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ export class Scan {
private tagFilter?: Record<string, unknown>
private offset?: number
private limit?: number
private orderBy?: string
private descending: boolean

public constructor({
category,
limit,
offset,
orderBy,
descending,
profile,
tagFilter,
store,
Expand All @@ -30,13 +34,17 @@ export class Scan {
tagFilter?: Record<string, unknown>
offset?: number
limit?: number
orderBy?: string
descending: boolean
store: Store
}) {
this.category = category
this.profile = profile
this.tagFilter = tagFilter
this.offset = offset
this.limit = limit
this.orderBy = orderBy
this.descending = descending
this.store = store
}

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export class Store {
tagFilter?: Record<string, unknown>
offset?: number
limit?: number
orderBy?: string
descending: boolean
profile?: string
}) {
return new Scan({ ...options, store: this })
Expand Down

0 comments on commit cf5787e

Please sign in to comment.