New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@wharfkit/contract

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wharfkit/contract - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

23

lib/contract.d.ts

@@ -1,2 +0,2 @@

import { API, ABIDef, APIClient, ABI, NameType, Name, BytesType, ABISerializableObject, PermissionLevelType, Action } from '@greymass/eosio';
import { API, ABIDef, APIClient, ABI, NameType, Name, BytesType, ABISerializableObject, PermissionLevelType, Action } from '@wharfkit/antelope';
import { ABICacheInterface } from '@wharfkit/abicache';

@@ -68,10 +68,10 @@

interface QueryOptions {
interface QueryParams {
index?: string;
scope?: NameType;
key_type?: keyof API.v1.TableIndexTypes;
}
interface Query extends QueryOptions {
json?: boolean;
from?: API.v1.TableIndexType | string | number;
to?: API.v1.TableIndexType | string | number;
maxRows?: number;
rowsPerAPIRequest?: number;

@@ -148,3 +148,3 @@ }

*/
query(query: Query): TableCursor<RowType>;
query(params?: QueryParams): TableCursor<RowType>;
/**

@@ -157,3 +157,3 @@ * Retrieves the row from the table that matches the given parameters.

*/
get(queryValue: API.v1.TableIndexType | string, { scope, index, key_type }?: QueryOptions): Promise<RowType>;
get(value?: API.v1.TableIndexType | string, params?: QueryParams): Promise<RowType>;
/**

@@ -167,13 +167,8 @@ * Retrieves all the rows from the table.

*/
first(maxRows: number, options?: QueryOptions): TableCursor<RowType>;
first(maxRows: number, params?: QueryParams): TableCursor<RowType>;
/**
* Returns a cursor to get every single rows on the table.
* @returns {TableCursor}
*/
cursor(): TableCursor<RowType>;
/**
* Returns all the rows from the table.
* @returns {Promise<TableRow[]>} Promise resolving to an array of table rows.
*/
all(): Promise<RowType[]>;
all(params?: QueryParams): Promise<RowType[]>;
getFieldToIndex(): any;

@@ -246,2 +241,2 @@ }

export { ABIDefinition, ActionArgs, ActionDataType, ActionOptions, Contract, ContractArgs, ContractKit, ContractKitArgs, ContractKitOptions, GetTableRowsOptions, Query, QueryOptions, Table, TableCursor, TableCursorArgs, TableRowParamsTypes, ContractKit as default };
export { ABIDefinition, ActionArgs, ActionDataType, ActionOptions, Contract, ContractArgs, ContractKit, ContractKitArgs, ContractKitOptions, GetTableRowsOptions, QueryParams, Table, TableCursor, TableCursorArgs, TableRowParamsTypes, ContractKit as default };

@@ -5,3 +5,3 @@ 'use strict';

var eosio = require('@greymass/eosio');
var antelope = require('@wharfkit/antelope');
var eosioSigningRequest = require('eosio-signing-request');

@@ -29,13 +29,13 @@ var tslib = require('tslib');

}
if (eosio.isInstanceOf(value, eosio.UInt128) ||
eosio.isInstanceOf(value, eosio.UInt64) ||
eosio.isInstanceOf(value, eosio.Float64) ||
eosio.isInstanceOf(value, eosio.Checksum256) ||
eosio.isInstanceOf(value, eosio.Checksum160)) {
if (antelope.isInstanceOf(value, antelope.UInt128) ||
antelope.isInstanceOf(value, antelope.UInt64) ||
antelope.isInstanceOf(value, antelope.Float64) ||
antelope.isInstanceOf(value, antelope.Checksum256) ||
antelope.isInstanceOf(value, antelope.Checksum160)) {
return value;
}
if (typeof value === 'number') {
return eosio.UInt64.from(value);
return antelope.UInt64.from(value);
}
return eosio.Name.from(value);
return antelope.Name.from(value);
}

@@ -52,3 +52,3 @@

this.maxRows = Number.MAX_SAFE_INTEGER;
this.abi = eosio.ABI.from(args.abi);
this.abi = antelope.ABI.from(args.abi);
this.client = args.client;

@@ -93,3 +93,3 @@ this.params = Object.assign(Object.assign({}, defaultParams), args.params);

const rows = requiresDecoding
? result.rows.map((data) => eosio.Serializer.decode({
? result.rows.map((data) => antelope.Serializer.decode({
data,

@@ -147,5 +147,5 @@ abi: this.abi,

this.defaultRowLimit = 1000;
this.abi = eosio.ABI.from(args.abi);
this.account = eosio.Name.from(args.account);
this.name = eosio.Name.from(args.name);
this.abi = antelope.ABI.from(args.abi);
this.account = antelope.Name.from(args.account);
this.name = antelope.Name.from(args.name);
this.client = args.client;

@@ -163,20 +163,19 @@ this.rowType = args.rowType;

}
query(query) {
const { from, to, rowsPerAPIRequest } = query;
query(params = {}) {
const tableRowsParams = {
table: this.name,
code: this.account,
scope: query.scope || this.account,
scope: params.scope || this.account,
type: this.rowType,
limit: rowsPerAPIRequest || this.defaultRowLimit,
lower_bound: wrapIndexValue(from),
upper_bound: wrapIndexValue(to),
key_type: query.key_type,
key_type: params.key_type,
lower_bound: wrapIndexValue(params.from),
upper_bound: wrapIndexValue(params.to),
limit: params.rowsPerAPIRequest || this.defaultRowLimit,
};
if (query.index) {
if (params.index) {
const fieldToIndexMapping = this.getFieldToIndex();
if (!fieldToIndexMapping[query.index]) {
throw new Error(`Field ${query.index} is not a valid index.`);
if (!fieldToIndexMapping[params.index]) {
throw new Error(`Field ${params.index} is not a valid index.`);
}
tableRowsParams.index_position = fieldToIndexMapping[query.index].index_position;
tableRowsParams.index_position = fieldToIndexMapping[params.index].index_position;
}

@@ -186,6 +185,7 @@ return new TableCursor({

client: this.client,
maxRows: params.maxRows,
params: tableRowsParams,
});
}
get(queryValue, { scope = this.account, index, key_type } = {}) {
get(value, params = {}) {
return tslib.__awaiter(this, void 0, void 0, function* () {

@@ -196,55 +196,34 @@ const fieldToIndexMapping = this.getFieldToIndex();

code: this.account,
scope,
scope: params.scope || this.account,
type: this.rowType,
limit: 1,
lower_bound: wrapIndexValue(queryValue),
upper_bound: wrapIndexValue(queryValue),
index_position: index ? fieldToIndexMapping[index].index_position : 'primary',
key_type: key_type,
lower_bound: wrapIndexValue(value),
upper_bound: wrapIndexValue(value),
index_position: params.index
? fieldToIndexMapping[params.index].index_position
: 'primary',
key_type: params.key_type,
json: false,
};
let { rows } = yield this.client.v1.chain.get_table_rows(tableRowsParams);
const { rows } = yield this.client.v1.chain.get_table_rows(tableRowsParams);
let [row] = rows;
if (!this.rowType) {
rows = [
eosio.Serializer.decode({
data: rows[0],
abi: this.abi,
type: this.tableABI.type,
}),
];
row = antelope.Serializer.decode({
data: row,
abi: this.abi,
type: this.tableABI.type,
});
}
return rows[0];
if (params.json) {
row = antelope.Serializer.objectify(row);
}
return row;
});
}
first(maxRows, options = {}) {
const tableRowsParams = {
table: this.name,
limit: maxRows,
code: this.account,
type: this.rowType,
scope: options.scope,
};
return new TableCursor({
abi: this.abi,
client: this.client,
maxRows,
params: tableRowsParams,
});
first(maxRows, params = {}) {
return this.query(Object.assign(Object.assign({}, params), { maxRows }));
}
cursor() {
const tableRowsParams = {
table: this.name,
code: this.account,
type: this.rowType,
limit: this.defaultRowLimit,
};
return new TableCursor({
abi: this.abi,
client: this.client,
params: tableRowsParams,
});
}
all() {
all(params = {}) {
return tslib.__awaiter(this, void 0, void 0, function* () {
return this.cursor().all();
return this.query(params).all();
});

@@ -269,4 +248,4 @@ }

constructor(args) {
this.abi = eosio.ABI.from(args.abi);
this.account = eosio.Name.from(args.account);
this.abi = antelope.ABI.from(args.abi);
this.account = antelope.Name.from(args.account);
this.client = args.client;

@@ -304,5 +283,5 @@ }

if (options && options.authorization) {
authorization = options.authorization.map((auth) => eosio.PermissionLevel.from(auth));
authorization = options.authorization.map((auth) => antelope.PermissionLevel.from(auth));
}
return eosio.Action.from({
return antelope.Action.from({
account: this.account,

@@ -323,3 +302,3 @@ name,

}
const action = this.abi.actions.find((action) => eosio.Name.from(action.name).equals(name));
const action = this.abi.actions.find((action) => antelope.Name.from(action.name).equals(name));
if (!action || !action.ricardian_contract) {

@@ -348,3 +327,3 @@ throw new Error(`Contract (${this.account}) action named (${name}) does not have a defined ricardian contract`);

if (options.abis) {
options.abis.forEach(({ name, abi }) => this.abiCache.setAbi(eosio.Name.from(name), eosio.ABI.from(abi)));
options.abis.forEach(({ name, abi }) => this.abiCache.setAbi(antelope.Name.from(name), antelope.ABI.from(abi)));
}

@@ -354,6 +333,6 @@ }

return tslib.__awaiter(this, void 0, void 0, function* () {
const account = eosio.Name.from(contract);
const account = antelope.Name.from(contract);
const abiDef = yield this.abiCache.getAbi(account);
return new Contract({
abi: eosio.ABI.from(abiDef),
abi: antelope.ABI.from(abiDef),
account,

@@ -360,0 +339,0 @@ client: this.client,

@@ -1,2 +0,2 @@

import { isInstanceOf, UInt128, UInt64, Float64, Checksum256, Checksum160, Name, ABI, Serializer, PermissionLevel, Action } from '@greymass/eosio';
import { isInstanceOf, UInt128, UInt64, Float64, Checksum256, Checksum160, Name, ABI, Serializer, PermissionLevel, Action } from '@wharfkit/antelope';
import { PlaceholderAuth } from 'eosio-signing-request';

@@ -135,20 +135,19 @@ import { ABICache } from '@wharfkit/abicache';

}
query(query) {
const { from, to, rowsPerAPIRequest } = query;
query(params = {}) {
const tableRowsParams = {
table: this.name,
code: this.account,
scope: query.scope || this.account,
scope: params.scope || this.account,
type: this.rowType,
limit: rowsPerAPIRequest || this.defaultRowLimit,
lower_bound: wrapIndexValue(from),
upper_bound: wrapIndexValue(to),
key_type: query.key_type,
key_type: params.key_type,
lower_bound: wrapIndexValue(params.from),
upper_bound: wrapIndexValue(params.to),
limit: params.rowsPerAPIRequest || this.defaultRowLimit,
};
if (query.index) {
if (params.index) {
const fieldToIndexMapping = this.getFieldToIndex();
if (!fieldToIndexMapping[query.index]) {
throw new Error(`Field ${query.index} is not a valid index.`);
if (!fieldToIndexMapping[params.index]) {
throw new Error(`Field ${params.index} is not a valid index.`);
}
tableRowsParams.index_position = fieldToIndexMapping[query.index].index_position;
tableRowsParams.index_position = fieldToIndexMapping[params.index].index_position;
}

@@ -158,6 +157,7 @@ return new TableCursor({

client: this.client,
maxRows: params.maxRows,
params: tableRowsParams,
});
}
async get(queryValue, { scope = this.account, index, key_type } = {}) {
async get(value, params = {}) {
const fieldToIndexMapping = this.getFieldToIndex();

@@ -167,54 +167,36 @@ const tableRowsParams = {

code: this.account,
scope,
scope: params.scope || this.account,
type: this.rowType,
limit: 1,
lower_bound: wrapIndexValue(queryValue),
upper_bound: wrapIndexValue(queryValue),
index_position: index ? fieldToIndexMapping[index].index_position : 'primary',
key_type: key_type,
lower_bound: wrapIndexValue(value),
upper_bound: wrapIndexValue(value),
index_position: params.index
? fieldToIndexMapping[params.index].index_position
: 'primary',
key_type: params.key_type,
json: false,
};
let { rows } = await this.client.v1.chain.get_table_rows(tableRowsParams);
const { rows } = await this.client.v1.chain.get_table_rows(tableRowsParams);
let [row] = rows;
if (!this.rowType) {
rows = [
Serializer.decode({
data: rows[0],
abi: this.abi,
type: this.tableABI.type,
}),
];
row = Serializer.decode({
data: row,
abi: this.abi,
type: this.tableABI.type,
});
}
return rows[0];
if (params.json) {
row = Serializer.objectify(row);
}
return row;
}
first(maxRows, options = {}) {
const tableRowsParams = {
table: this.name,
limit: maxRows,
code: this.account,
type: this.rowType,
scope: options.scope,
};
return new TableCursor({
abi: this.abi,
client: this.client,
first(maxRows, params = {}) {
return this.query({
...params,
maxRows,
params: tableRowsParams,
});
}
cursor() {
const tableRowsParams = {
table: this.name,
code: this.account,
type: this.rowType,
limit: this.defaultRowLimit,
};
return new TableCursor({
abi: this.abi,
client: this.client,
params: tableRowsParams,
});
async all(params = {}) {
return this.query(params).all();
}
async all() {
return this.cursor().all();
}
getFieldToIndex() {

@@ -221,0 +203,0 @@ if (this.fieldToIndex) {

{
"name": "@wharfkit/contract",
"description": "ContractKit for Wharf",
"version": "0.2.1",
"version": "0.3.0",
"homepage": "https://github.com/wharfkit/contract",

@@ -22,9 +22,9 @@ "license": "BSD-3-Clause",

"dependencies": {
"@greymass/eosio": "^0.6.10",
"@wharfkit/abicache": "^1.0.0",
"eosio-signing-request": "^2.5.3",
"@wharfkit/abicache": "^1.0.1-beta1",
"@wharfkit/antelope": "^0.7.3",
"eosio-signing-request": "^3.0.0-beta1",
"tslib": "^2.1.0"
},
"resolutions": {
"@greymass/eosio": "^0.6.10"
"@wharfkit/antelope": "^0.7.3"
},

@@ -46,4 +46,4 @@ "devDependencies": {

"@typescript-eslint/parser": "^5.20.0",
"@wharfkit/mock-data": "^1.0.0-beta11",
"@wharfkit/session": "^1.0.0-beta4",
"@wharfkit/mock-data": "^1.0.0-beta13",
"@wharfkit/session": "^1.0.0-beta6",
"assert": "^2.0.0",

@@ -50,0 +50,0 @@ "chai": "^4.3.4",

@@ -1,2 +0,2 @@

import {ABI} from '@greymass/eosio'
import {ABI} from '@wharfkit/antelope'
import * as ts from 'typescript'

@@ -3,0 +3,0 @@

@@ -1,2 +0,2 @@

import {ABI} from '@greymass/eosio'
import {ABI} from '@wharfkit/antelope'
import assert from 'assert'

@@ -3,0 +3,0 @@ import * as ts from 'typescript'

@@ -1,2 +0,2 @@

import {ABI} from '@greymass/eosio'
import {ABI} from '@wharfkit/antelope'
import * as ts from 'typescript'

@@ -3,0 +3,0 @@

@@ -6,3 +6,3 @@ import * as ts from 'typescript'

import {capitalize} from '../utils'
import {APIClient} from '@greymass/eosio'
import {APIClient} from '@wharfkit/antelope'

@@ -9,0 +9,0 @@ export async function generateTableClass(contractName, namespaceName, table, abi) {

@@ -12,3 +12,3 @@ import {

PermissionLevelType,
} from '@greymass/eosio'
} from '@wharfkit/antelope'
import {PlaceholderAuth} from 'eosio-signing-request'

@@ -15,0 +15,0 @@

@@ -1,2 +0,2 @@

import {ABI, ABIDef, API, APIClient, Serializer} from '@greymass/eosio'
import {ABI, ABIDef, API, APIClient, Serializer} from '@wharfkit/antelope'
import {wrapIndexValue} from '../utils'

@@ -3,0 +3,0 @@

@@ -1,14 +0,13 @@

import {ABI, ABIDef, API, APIClient, Name, NameType, Serializer} from '@greymass/eosio'
import {ABI, ABIDef, API, APIClient, Name, NameType, Serializer} from '@wharfkit/antelope'
import {indexPositionInWords, wrapIndexValue} from '../utils'
import {TableCursor} from './table-cursor'
export interface QueryOptions {
export interface QueryParams {
index?: string
scope?: NameType
key_type?: keyof API.v1.TableIndexTypes
}
export interface Query extends QueryOptions {
json?: boolean
from?: API.v1.TableIndexType | string | number
to?: API.v1.TableIndexType | string | number
maxRows?: number
rowsPerAPIRequest?: number

@@ -107,24 +106,25 @@ }

*/
query(query: Query): TableCursor<RowType> {
const {from, to, rowsPerAPIRequest} = query
query(params: QueryParams = {}): TableCursor<RowType> {
const tableRowsParams: any = {
// Table query
table: this.name,
code: this.account,
scope: query.scope || this.account,
scope: params.scope || this.account,
// Response typing
type: this.rowType,
limit: rowsPerAPIRequest || this.defaultRowLimit,
lower_bound: wrapIndexValue(from),
upper_bound: wrapIndexValue(to),
key_type: query.key_type,
// Filtering
key_type: params.key_type,
lower_bound: wrapIndexValue(params.from),
upper_bound: wrapIndexValue(params.to),
limit: params.rowsPerAPIRequest || this.defaultRowLimit,
}
if (query.index) {
if (params.index) {
const fieldToIndexMapping = this.getFieldToIndex()
if (!fieldToIndexMapping[query.index]) {
throw new Error(`Field ${query.index} is not a valid index.`)
if (!fieldToIndexMapping[params.index]) {
throw new Error(`Field ${params.index} is not a valid index.`)
}
tableRowsParams.index_position = fieldToIndexMapping[query.index].index_position
tableRowsParams.index_position = fieldToIndexMapping[params.index].index_position
}

@@ -135,2 +135,3 @@

client: this.client,
maxRows: params.maxRows,
params: tableRowsParams,

@@ -147,6 +148,3 @@ })

*/
async get(
queryValue: API.v1.TableIndexType | string,
{scope = this.account, index, key_type}: QueryOptions = {}
): Promise<RowType> {
async get(value?: API.v1.TableIndexType | string, params: QueryParams = {}): Promise<RowType> {
const fieldToIndexMapping = this.getFieldToIndex()

@@ -157,25 +155,30 @@

code: this.account,
scope,
scope: params.scope || this.account,
type: this.rowType!,
limit: 1,
lower_bound: wrapIndexValue(queryValue),
upper_bound: wrapIndexValue(queryValue),
index_position: index ? fieldToIndexMapping[index].index_position : 'primary',
key_type: key_type,
lower_bound: wrapIndexValue(value),
upper_bound: wrapIndexValue(value),
index_position: params.index
? fieldToIndexMapping[params.index].index_position
: 'primary',
key_type: params.key_type,
json: false,
}
let {rows} = await this.client!.v1.chain.get_table_rows(tableRowsParams)
const {rows} = await this.client!.v1.chain.get_table_rows(tableRowsParams)
let [row] = rows
if (!this.rowType) {
rows = [
Serializer.decode({
data: rows[0],
abi: this.abi,
type: this.tableABI.type,
}),
]
row = Serializer.decode({
data: row,
abi: this.abi,
type: this.tableABI.type,
})
}
return rows[0]
if (params.json) {
row = Serializer.objectify(row)
}
return row
}

@@ -191,16 +194,6 @@

*/
first(maxRows: number, options: QueryOptions = {}): TableCursor<RowType> {
const tableRowsParams = {
table: this.name,
limit: maxRows,
code: this.account,
type: this.rowType,
scope: options.scope,
}
return new TableCursor<RowType>({
abi: this.abi,
client: this.client,
first(maxRows: number, params: QueryParams = {}): TableCursor<RowType> {
return this.query({
...params,
maxRows,
params: tableRowsParams,
})

@@ -210,26 +203,7 @@ }

/**
* Returns a cursor to get every single rows on the table.
* @returns {TableCursor}
*/
cursor(): TableCursor<RowType> {
const tableRowsParams = {
table: this.name,
code: this.account,
type: this.rowType,
limit: this.defaultRowLimit,
}
return new TableCursor<RowType>({
abi: this.abi,
client: this.client,
params: tableRowsParams,
})
}
/**
* Returns all the rows from the table.
* @returns {Promise<TableRow[]>} Promise resolving to an array of table rows.
*/
async all(): Promise<RowType[]> {
return this.cursor().all()
async all(params: QueryParams = {}): Promise<RowType[]> {
return this.query(params).all()
}

@@ -236,0 +210,0 @@

@@ -1,2 +0,2 @@

import {ABI, ABIDef, APIClient, Name, NameType} from '@greymass/eosio'
import {ABI, ABIDef, APIClient, Name, NameType} from '@wharfkit/antelope'
import {ABICache} from '@wharfkit/abicache'

@@ -3,0 +3,0 @@ import type {ABICacheInterface} from '@wharfkit/abicache'

@@ -10,3 +10,3 @@ import {

UInt64,
} from '@greymass/eosio'
} from '@wharfkit/antelope'

@@ -13,0 +13,0 @@ export function pascalCase(value: string): string {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc