Skip to content

Commit

Permalink
Merge branch 'release/v1.10.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
onetechnical committed Jul 21, 2021
2 parents eb0c7a6 + dba2553 commit d009e8b
Show file tree
Hide file tree
Showing 21 changed files with 867 additions and 448 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ module.exports = {
'always',
{ exceptAfterSingleLine: true },
],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error'],
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': ['error'],
},
overrides: [
{
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# 1.10.1

## Added

- Add missing fields `msig` and `lsig` to `EncodedSignedTransaction` type
- Add the missing type `SignedTransaction`, which helped fix the `any` return value for `Transaction.from_obj_for_encoding`
- More internal types are now exported
- Support the new base64 asset fields in algod models
- Add ability to install the package from a git URL with npm

## Fixed

- Remove BigInt literals from package
- Support encoding transactions with a first round of zero
- Fix msgpack encoding of dryrun objects

# 1.10.0

## Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "algosdk",
"version": "1.10.0",
"version": "1.10.1",
"description": "The official JavaScript SDK for Algorand",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -66,6 +66,7 @@
},
"scripts": {
"test": "node -r ts-node/register tests/mocha.js",
"prepare": "npm run build",
"prepare-browser-tests": "npm run build && mkdir -p tests/cucumber/browser/build && cp dist/browser/algosdk.min.* tests/cucumber/browser/build/ && webpack --config tests/cucumber/browser/webpack.config.js",
"build": "concurrently \"webpack --config webpack.config.js\" \"tsc -p tsconfig-esm.json\" \"tsc -p tsconfig-cjs.json\"",
"docs": "typedoc src/main.ts",
Expand Down
2 changes: 0 additions & 2 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ type Query<F> = {
* requested format.
* @param query
*/
/* eslint-disable no-redeclare,no-unused-vars */
function getAcceptFormat(
query?: Query<'msgpack' | 'json'>
): 'application/msgpack' | 'application/json' {
/* eslint-enable no-redeclare,no-unused-vars */
if (
query !== undefined &&
Object.prototype.hasOwnProperty.call(query, 'format')
Expand Down
2 changes: 1 addition & 1 deletion src/client/v2/algod/dryrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class Dryrun extends JSONRequest {

constructor(c: HTTPClient, dr: modelsv2.DryrunRequest) {
super(c);
this.blob = encoding.encode(dr.get_obj_for_encoding());
this.blob = encoding.encode(dr.get_obj_for_encoding(true));
}

// eslint-disable-next-line class-methods-use-this
Expand Down
112 changes: 64 additions & 48 deletions src/client/v2/algod/models/base.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,79 @@
import { Address } from '../../../../types/address';

/**
* Base class for models
*/

/* eslint-disable no-underscore-dangle,camelcase,class-methods-use-this */
export default class BaseModel {
attribute_map: Record<string, string>;

_is_primitive(val: any): val is string | boolean | number | bigint {
return (
val === undefined ||
val == null ||
(typeof val !== 'object' && typeof val !== 'function')
);
}
/* eslint-disable no-underscore-dangle,camelcase */
function _is_primitive(val: any): val is string | boolean | number | bigint {
/* eslint-enable no-underscore-dangle,camelcase */
return (
val === undefined ||
val == null ||
(typeof val !== 'object' && typeof val !== 'function')
);
}

_is_address(val: any): val is Address {
return val.publicKey !== undefined && val.checksum !== undefined;
}
/* eslint-disable no-underscore-dangle,camelcase,no-redeclare,no-unused-vars */
function _get_obj_for_encoding(
val: Function,
binary: boolean
): Record<string, any>;
function _get_obj_for_encoding(val: any[], binary: boolean): any[];
function _get_obj_for_encoding(
val: Record<string, any>,
binary: boolean
): Record<string, any>;
function _get_obj_for_encoding(val: any, binary: boolean): any {
/* eslint-enable no-underscore-dangle,camelcase,no-redeclare,no-unused-vars */
let targetPropValue: any;

/* eslint-disable no-dupe-class-members,no-unused-vars */
_get_obj_for_encoding(val: Function): Record<string, any>;
_get_obj_for_encoding(val: any[]): any[];
_get_obj_for_encoding(val: Record<string, any>): Record<string, any>;
_get_obj_for_encoding(val: any): any {
/* eslint-disable no-unused-vars */
let targetPropValue: any;
if (typeof val.get_obj_for_encoding === 'function') {
targetPropValue = val.get_obj_for_encoding();
} else if (Array.isArray(val)) {
targetPropValue = [];
for (const elem of val) {
targetPropValue.push(this._get_obj_for_encoding(elem));
}
} else if (typeof val === 'object') {
const obj = {};
for (const prop of Object.keys(val)) {
obj[prop] = this._get_obj_for_encoding(val[prop]);
}
targetPropValue = obj;
} else if (this._is_primitive(val)) {
targetPropValue = val;
} else {
throw new Error(`Unsupported value: ${String(val)}`);
if (val instanceof Uint8Array) {
targetPropValue = binary ? val : Buffer.from(val).toString('base64');
} else if (typeof val.get_obj_for_encoding === 'function') {
targetPropValue = val.get_obj_for_encoding(binary);
} else if (Array.isArray(val)) {
targetPropValue = [];
for (const elem of val) {
targetPropValue.push(_get_obj_for_encoding(elem, binary));
}
return targetPropValue;
} else if (typeof val === 'object') {
const obj = {};
for (const prop of Object.keys(val)) {
obj[prop] = _get_obj_for_encoding(val[prop], binary);
}
targetPropValue = obj;
} else if (_is_primitive(val)) {
targetPropValue = val;
} else {
throw new Error(`Unsupported value: ${String(val)}`);
}
/* eslint-disable no-dupe-class-members */
return targetPropValue;
}

export default class BaseModel {
/* eslint-disable no-underscore-dangle,camelcase */
attribute_map: Record<string, string>;

get_obj_for_encoding() {
/**
* Get an object ready for encoding to either JSON or msgpack.
* @param binary - Use true to indicate that the encoding can handle raw binary objects
* (Uint8Arrays). Use false to indicate that raw binary objects should be converted to base64
* strings. True should be used for objects that will be encoded with msgpack, and false should
* be used for objects that will be encoded with JSON.
*/
get_obj_for_encoding(binary = false) {
/* eslint-enable no-underscore-dangle,camelcase */
const obj: Record<string, any> = {};
for (const prop of Object.keys(this)) {
const val = this[prop];
if (prop !== 'attribute_map' && typeof val !== 'undefined') {
const name = this.attribute_map[prop];
obj[name] = val === null ? null : this._get_obj_for_encoding(val);

for (const prop of Object.keys(this.attribute_map)) {
const name = this.attribute_map[prop];
const value = this[prop];

if (typeof value !== 'undefined') {
obj[name] =
value === null ? null : _get_obj_for_encoding(value, binary);
}
}

return obj;
}
}
Loading

0 comments on commit d009e8b

Please sign in to comment.