Skip to content

Commit

Permalink
chore: Apply comments:
Browse files Browse the repository at this point in the history
- Update the type of the 'extrinsics' in the 'saveIfKVStoreBackend' method to 'ExtrinsicResult' instead of 'any' type.
- Update the description of the 'BaseModule._add' method.
- Update the return type of the 'KVStore.set' method to be 'string' instead of 'KVStoreSetOptions' type.
- Update the return type of any function in the grid client that return the tf-chain changed methods
  • Loading branch information
Mahmoud-Emad committed Aug 7, 2024
1 parent 40196ea commit 51aeca9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
8 changes: 4 additions & 4 deletions packages/grid_client/src/clients/tf-grid/kvstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class TFKVStore extends KVStore {
* If encryption is enabled, the value will be encrypted before storing.
*
* @param {KVStoreSetOptions & { encrypt?: boolean }} options - The options for setting the `key-value` pair.
* @returns {Promise<ExtrinsicResult<KVStoreSetOptions>>} - A promise that resolves once the `key-value` set extrinsic is created.
* @returns {Promise<ExtrinsicResult<string>>} - A promise that resolves to the address of the connected account.
*/
async set(options: KVStoreSetOptions & { encrypt?: boolean }): Promise<ExtrinsicResult<KVStoreSetOptions>> {
async set(options: KVStoreSetOptions & { encrypt?: boolean }): Promise<ExtrinsicResult<string>> {
if (options.encrypt === false) {
return super.set({ key: options.key, value: options.value });
}
Expand Down Expand Up @@ -69,11 +69,11 @@ class TFKVStore extends KVStore {
* @returns {Promise<string[]>} - A promise that resolves with an array of keys that were removed.
*/
async batchRemove(options: KVStoreBatchRemoveOptions): Promise<string[]> {
const extrinsics: ExtrinsicResult<KVStoreSetOptions>[] = [];
const extrinsics: ExtrinsicResult<string>[] = [];
for (const key of options.keys) {
extrinsics.push(await this.delete({ key }));
}
await this.client.applyAllExtrinsics<KVStoreSetOptions>(extrinsics);
await this.client.applyAllExtrinsics<string>(extrinsics);
return options.keys;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ class BaseModule {
}

/**
* Add a new [ZDB or K8S worker] to the deployment.
* Add a new [machine, ZDB, or K8S worker] to the deployment.
*
* @param deployment_name The name of the deployment.
* @param node_id The ID of the node where the machine will be added.
Expand Down
6 changes: 2 additions & 4 deletions packages/grid_client/src/modules/kvstore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { KVStoreSetOptions } from "@threefold/tfchain_client";

import { TFClient } from "../clients/tf-grid/client";
import { GridClientConfig } from "../config";
import { expose } from "../helpers/expose";
Expand Down Expand Up @@ -39,7 +37,7 @@ class KVStore {
@expose
@validateInput
@checkBalance
async set(options: KVStoreSetModel): Promise<KVStoreSetOptions> {
async set(options: KVStoreSetModel): Promise<string> {
return (await this.client.kvStore.set(options)).apply();
}

Expand Down Expand Up @@ -92,7 +90,7 @@ class KVStore {
@expose
@validateInput
@checkBalance
async remove(options: KVStoreRemoveModel): Promise<KVStoreSetOptions> {
async remove(options: KVStoreRemoveModel): Promise<string> {
return (await this.client.kvStore.delete(options)).apply();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/grid_client/src/modules/stellar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class Stellar implements blockchainInterface {
/**
* Saves the extrinsics to the `key-value` store backend if the backend storage type is `tfkvstore` and extrinsics are provided.
*
* @param {any[]} extrinsics - The extrinsics to be saved to the `key-value` store backend.
* @param {ExtrinsicResult[]} extrinsics - The extrinsics to be saved to the `key-value` store backend.
* @returns {Promise<void>} - A promise that resolves once the extrinsics are saved to the backend.
*/
private async saveIfKVStoreBackend(extrinsics: any[]) {
private async saveIfKVStoreBackend(extrinsics: ExtrinsicResult<any>[]) {
if (this.config.backendStorageType === BackendStorageType.tfkvstore && extrinsics && extrinsics.length > 0) {
extrinsics = extrinsics.filter(e => e !== undefined);
if (extrinsics.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface BackendStorageInterface {
list(key: string);

// This method currently only implemented in tfkvstore
moveValue?(fromKey: string, toKey: string): Promise<ExtrinsicResult<KVStoreSetOptions>[]>;
moveValue?(fromKey: string, toKey: string): Promise<ExtrinsicResult<string>[]>;
}

export default BackendStorageInterface;
4 changes: 2 additions & 2 deletions packages/grid_client/src/storage/tfkvstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ class TFKVStoreBackend implements BackendStorageInterface {
return splits;
}

public async moveValue(fromKey: string, toKey: string): Promise<ExtrinsicResult<KVStoreSetOptions>[]> {
public async moveValue(fromKey: string, toKey: string): Promise<ExtrinsicResult<string>[]> {
fromKey = cropKey(fromKey);
toKey = cropKey(toKey);

const exts: ExtrinsicResult<KVStoreSetOptions>[] = [];
const exts: ExtrinsicResult<string>[] = [];

for (let i = 0; ; i++) {
const key = i === 0 ? fromKey : fromKey + "." + i;
Expand Down
16 changes: 8 additions & 8 deletions packages/tfchain_client/src/kvstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class KVStore {
* It then patches the extrinsic and returns the options that were set.
*
* @param options - An object containing the key and value to be set in the `key-value` store.
* @returns {Promise<ExtrinsicResult<KVStoreSetOptions>>} A promise that resolves to the options that were set in the store.
* @returns {Promise<ExtrinsicResult<string>>} A promise that resolves to the address of the connected account.
*/
@checkConnection
async set(options: KVStoreSetOptions): Promise<ExtrinsicResult<KVStoreSetOptions>> {
async set(options: KVStoreSetOptions): Promise<ExtrinsicResult<string>> {
const extrinsic = await this.client.api.tx.tfkvStore.set(options.key, options.value);
return this.client.patchExtrinsic<KVStoreSetOptions>(extrinsic);
return this.client.patchExtrinsic<string>(extrinsic);
}

/**
Expand All @@ -38,12 +38,12 @@ class KVStore {
* It then patches the extrinsic and returns the result of the deletion operation.
*
* @param options - An object containing the key to be deleted from the `key-value` store.
* @returns {Promise<ExtrinsicResult<KVStoreSetOptions>>} A promise that resolves once the delete extrinsic is successfully created.
* @returns {Promise<ExtrinsicResult<string>>} A promise that resolves to the address of the connected account.
*/
@checkConnection
async delete(options: KVStoreGetOptions): Promise<ExtrinsicResult<KVStoreSetOptions>> {
async delete(options: KVStoreGetOptions): Promise<ExtrinsicResult<string>> {
const extrinsic = await this.client.api.tx.tfkvStore.delete(options.key);
return this.client.patchExtrinsic<KVStoreSetOptions>(extrinsic);
return this.client.patchExtrinsic<string>(extrinsic);
}

/**
Expand Down Expand Up @@ -91,11 +91,11 @@ class KVStore {
*/
async deleteAll(): Promise<string[]> {
const keys: string[] = await this.list();
const extrinsics: ExtrinsicResult<KVStoreGetOptions>[] = [];
const extrinsics: ExtrinsicResult<string>[] = [];
for (const key of keys) {
extrinsics.push(await this.delete({ key }));
}
await this.client.applyAllExtrinsics<KVStoreGetOptions>(extrinsics);
await this.client.applyAllExtrinsics<string>(extrinsics);
return keys;
}
}
Expand Down

0 comments on commit 51aeca9

Please sign in to comment.