Skip to content

Commit

Permalink
[SDK] update typescript sdk to get /get_table_item
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse authored and gregnazario committed Apr 27, 2022
1 parent c6163c2 commit 97d03e6
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 1 deletion.
39 changes: 39 additions & 0 deletions ecosystem/typescript/sdk/src/api/Tables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable */
/* tslint:disable */
/*
* ---------------------------------------------------------------
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
* ## ##
* ## AUTHOR: acacode ##
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
* ---------------------------------------------------------------
*/

import { AptosError, TableItemRequest } from "./data-contracts";
import { ContentType, HttpClient, RequestParams } from "./http-client";

export class Tables<SecurityDataType = unknown> {
http: HttpClient<SecurityDataType>;

constructor(http: HttpClient<SecurityDataType>) {
this.http = http;
}

/**
* @description Gets a table item for a table identified by the handle and the key for the item. Key and value types need to be passed in to help with key serialization and value deserialization.
*
* @tags state, table
* @name GetTableItem
* @summary Get table item by handle and key.
* @request POST:/tables/{table_handle}/items
*/
getTableItem = (tableHandle: string, data: TableItemRequest, params: RequestParams = {}) =>
this.http.request<object, AptosError>({
path: `/tables/${tableHandle}/items`,
method: "POST",
body: data,
type: ContentType.Json,
format: "json",
...params,
});
}
186 changes: 185 additions & 1 deletion ecosystem/typescript/sdk/src/api/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,13 @@ export interface DirectWriteSet {
events: Event[];
}

export type WriteSetChange = DeleteModule | DeleteResource | WriteModule | WriteResource;
export type WriteSetChange =
| DeleteModule
| DeleteResource
| DeleteTableItem
| WriteModule
| WriteResource
| WriteTableItem;

export interface DeleteModule {
/** @example delete_module */
Expand Down Expand Up @@ -695,6 +701,25 @@ export interface DeleteResource {
resource: MoveStructTagId;
}

/**
* Delete table item change.
*/
export interface DeleteTableItem {
/** @example delete_table_item */
type: string;

/**
* All bytes data are represented as hex-encoded string prefixed with `0x` and fulfilled with
* two hex digits per byte.
*
* Different with `Address` type, hex-encoded bytes should not trim any zeros.
*/
state_key_hash: HexEncodedBytes;

/** Table item deletion */
data: { handle: HexEncodedBytes; key: HexEncodedBytes };
}

/**
* Write move module
*/
Expand Down Expand Up @@ -747,6 +772,25 @@ export interface WriteResource {
data: AccountResource;
}

/**
* Write table item
*/
export interface WriteTableItem {
/** @example write_table_item */
type: string;

/**
* All bytes data are represented as hex-encoded string prefixed with `0x` and fulfilled with
* two hex digits per byte.
*
* Different with `Address` type, hex-encoded bytes should not trim any zeros.
*/
state_key_hash: HexEncodedBytes;

/** Table item write */
data: { handle: HexEncodedBytes; key: HexEncodedBytes; value: HexEncodedBytes };
}

export interface Script {
code: MoveScript;
type_arguments: MoveTypeTagId[];
Expand Down Expand Up @@ -954,3 +998,143 @@ export interface MultiAgentSignature {
}

export type AccountSignature = Ed25519Signature | MultiEd25519Signature;

export interface TableItemRequest {
/**
* String representation of an on-chain Move type identifier defined by the Move language.
*
* Values:
* - bool
* - u8
* - u64
* - u128
* - address
* - signer
* - vector: `vector<{non-reference MoveTypeId}>`
* - struct: `{address}::{module_name}::{struct_name}::<{generic types}>`
* - reference: immutable `&` and mutable `&mut` references.
* - generic_type_parameter: it is always start with `T` and following an index number,
* which is the position of the generic type parameter in the `struct` or
* `function` generic type parameters definition.
* Vector type value examples:
* * `vector<u8>`
* * `vector<vector<u64>>`
* * `vector<0x1::AptosAccount::Balance<0x1::XDX::XDX>>`
* Struct type value examples:
* * `0x1::Aptos::Aptos<0x1::XDX::XDX>`
* * `0x1::Abc::Abc<vector<u8>, vector<u64>>`
* * `0x1::AptosAccount::AccountOperationsCapability`
* Reference type value examples:
* * `&signer`
* * `&mut address`
* * `&mut vector<u8>`
* Generic type parameter value example, the following is `0x1::TransactionFee::TransactionFee` JSON representation:
* {
* "name": "TransactionFee",
* "is_native": false,
* "abilities": ["key"],
* "generic_type_params": [
* {"constraints": [], "is_phantom": true}
* ],
* "fields": [
* { "name": "balance", "type": "0x1::Aptos::Aptos<T0>" },
* { "name": "preburn", "type": "0x1::Aptos::Preburn<T0>" }
* ]
* }
* It's Move source code:
* module AptosFramework::TransactionFee {
* struct TransactionFee<phantom CoinType> has key {
* balance: Aptos<CoinType>,
* preburn: Preburn<CoinType>,
* }
* The `T0` in the above JSON representation is the generic type place holder for
* the `CoinType` in the Move source code.
* Note:
* 1. Empty chars should be ignored when comparing 2 struct tag ids.
* 2. When used in an URL path, should be encoded by url-encoding (AKA percent-encoding).
*/
key_type: MoveTypeId;

/**
* String representation of an on-chain Move type identifier defined by the Move language.
*
* Values:
* - bool
* - u8
* - u64
* - u128
* - address
* - signer
* - vector: `vector<{non-reference MoveTypeId}>`
* - struct: `{address}::{module_name}::{struct_name}::<{generic types}>`
* - reference: immutable `&` and mutable `&mut` references.
* - generic_type_parameter: it is always start with `T` and following an index number,
* which is the position of the generic type parameter in the `struct` or
* `function` generic type parameters definition.
* Vector type value examples:
* * `vector<u8>`
* * `vector<vector<u64>>`
* * `vector<0x1::AptosAccount::Balance<0x1::XDX::XDX>>`
* Struct type value examples:
* * `0x1::Aptos::Aptos<0x1::XDX::XDX>`
* * `0x1::Abc::Abc<vector<u8>, vector<u64>>`
* * `0x1::AptosAccount::AccountOperationsCapability`
* Reference type value examples:
* * `&signer`
* * `&mut address`
* * `&mut vector<u8>`
* Generic type parameter value example, the following is `0x1::TransactionFee::TransactionFee` JSON representation:
* {
* "name": "TransactionFee",
* "is_native": false,
* "abilities": ["key"],
* "generic_type_params": [
* {"constraints": [], "is_phantom": true}
* ],
* "fields": [
* { "name": "balance", "type": "0x1::Aptos::Aptos<T0>" },
* { "name": "preburn", "type": "0x1::Aptos::Preburn<T0>" }
* ]
* }
* It's Move source code:
* module AptosFramework::TransactionFee {
* struct TransactionFee<phantom CoinType> has key {
* balance: Aptos<CoinType>,
* preburn: Preburn<CoinType>,
* }
* The `T0` in the above JSON representation is the generic type place holder for
* the `CoinType` in the Move source code.
* Note:
* 1. Empty chars should be ignored when comparing 2 struct tag ids.
* 2. When used in an URL path, should be encoded by url-encoding (AKA percent-encoding).
*/
value_type: MoveTypeId;

/**
* Move `bool` type value is serialized into `boolean`.
*
* Move `u8` type value is serialized into `integer`.
* Move `u64` and `u128` type value is serialized into `string`.
* Move `address` type value(16 bytes Aptos account address) is serialized into
* hex-encoded string, which is prefixed with `0x` and leading zeros are trimmed.
* For example:
* * `0x1`
* * `0x1668f6be25668c1a17cd8caf6b8d2f25`
* Move `vector` type value is serialized into `array`, except `vector<u8>` which is
* serialized into hex-encoded string with `0x` prefix.
* * `vector<u64>{255, 255}` => `["255", "255"]`
* * `vector<u8>{255, 255}` => `0xffff`
* Move `struct` type value is serialized into `object` that looks like this (except some Move stdlib types, see the following section):
* ```json
* {
* field1_name: field1_value,
* field2_name: field2_value,
* ......
* }
* ```
* `{ "created": "0xa550c18", "role_id": "0" }`
* **Special serialization for Move stdlib types:**
* * [0x1::ASCII::String](https://github.com/aptos-labs/aptos-core/blob/main/language/move-stdlib/docs/ASCII.md) is serialized into `string`. For example, struct value `0x1::ASCII::String{bytes: b"hello world"}` is serialized as `"hello world"` in JSON.
*/
key: MoveValue;
}

0 comments on commit 97d03e6

Please sign in to comment.