Skip to content

Commit

Permalink
fix(SPV-1143): fix query builder and bump version (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolt-4chain authored Oct 30, 2024
1 parent 97c4091 commit ad0bc12
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bsv/spv-wallet-js-client",
"version": "1.0.0-beta.23",
"version": "1.0.0-beta.24",
"description": "TypeScript library for connecting to a SPV Wallet server",
"repository": {
"type": "git",
Expand Down
10 changes: 3 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
PageModel,
Utxo,
MerkleRootsRepository,
QueryPageParams,
} from './types';
import { defaultLogger, Logger, LoggerConfig, makeLogger } from './logger';
import { HttpClient } from './httpclient';
Expand Down Expand Up @@ -537,19 +538,14 @@ export class SpvWalletClient {
* Get a list of all access keys for the current user, filtered by conditions, metadata and queryParams
*
* @param {AccessKeyFilter} conditions Key value object to use to filter the documents
* @param {Metadata} metadata Key value object to use to filter the documents by the metadata
* @param {QueryParams} queryParams Database query parameters for page, page size and sorting
* @return {PageModel<AccessKey>}
*/
async GetAccessKeys(
conditions: AccessKeyFilter,
metadata: Metadata,
queryParams: QueryParams,
): Promise<PageModel<AccessKey>> {
async GetAccessKeys(conditions: AccessKeyFilter, queryParams: QueryPageParams): Promise<PageModel<AccessKey>> {
const basePath = `users/current/keys`;
const queryString = buildQueryPath({
filter: conditions,
metadata: metadata,
metadata: {},
page: queryParams,
});

Expand Down
8 changes: 6 additions & 2 deletions src/query/query-builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccessKeyFilter, ContactFilter, ModelFilter, TransactionFilter, UtxoFilter, XpubFilter } from "../filters";
import { Metadata, QueryParams as Page } from "../types";
import { AccessKeyFilter, ContactFilter, ModelFilter, TransactionFilter, UtxoFilter, XpubFilter } from '../filters';
import { Metadata, QueryParams as Page } from '../types';

export interface BuildPathOptions {
filter: ModelFilter | TransactionFilter | UtxoFilter | XpubFilter | AccessKeyFilter | ContactFilter;
Expand All @@ -11,6 +11,10 @@ function flattenParams(params: Record<string, any>, parentKey?: string): Record<
const flattened: Record<string, string> = {};

Object.entries(params).forEach(([key, value]) => {
if (!value) {
return;
}

const newKey = parentKey ? `${parentKey}[${key}]` : key;

if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
Expand Down
95 changes: 52 additions & 43 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,50 +64,50 @@ export interface MerkleRootsRepository {
"next_external_num": 229
}
*/
export interface XPub {
/**
* metadata object
*/
metadata?: Metadata;
/**
* xpub id
*/
id: string;
/**
* Current balance in sats of the xpub
*/
current_balance: number;
/**
* Next internal (change address) number to use for a new destination
*
* NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination
*/
next_internal_num: number;
/**
* Next external number to use for a new destination
*
* NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination
*/
next_external_num: number;
/**
* Date when this object was created
*/
created_at?: Date;
/**
* Date when this object was last updated
*/
updated_at?: Date;
/**
* If this object has been deleted, this date will be set
*/
deleted_at?: Date;
}

export interface XPub {
/**
* metadata object
*/
metadata?: Metadata;
/**
* xpub id
*/
id: string;
/**
* Current balance in sats of the xpub
*/
current_balance: number;
/**
* Next internal (change address) number to use for a new destination
*
* NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination
*/
next_internal_num: number;
/**
* Next external number to use for a new destination
*
* NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination
*/
next_external_num: number;
/**
* Date when this object was created
*/
created_at?: Date;
/**
* Array of xpubs
* @see {@link XPub}
* Date when this object was last updated
*/
export interface XPubs extends Array<XPub> {}
updated_at?: Date;
/**
* If this object has been deleted, this date will be set
*/
deleted_at?: Date;
}

/**
* Array of xpubs
* @see {@link XPub}
*/
export interface XPubs extends Array<XPub> {}

/**
* Page interface
Expand Down Expand Up @@ -444,7 +444,6 @@ export interface OldUtxo {
*/
export interface OldUtxos extends Array<OldUtxo> {}


/**
* Old paymail address interface for Admin endpoints (Deprecated)
*/
Expand Down Expand Up @@ -719,6 +718,16 @@ export interface QueryParams {
sortDirection?: string;
}

/**
* Query page params to limit and order database list results.
*/
export interface QueryPageParams {
page?: number;
size?: number;
sort?: string;
sortBy?: string;
}

/**
* SharedConfig defines the configuration shared by different parts of the application.
*/
Expand Down

0 comments on commit ad0bc12

Please sign in to comment.