Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate API types using code generation #325

Merged
merged 9 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/v2/algod/algod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ServiceClient from '../serviceClient';
import { AlgodTokenHeader, CustomTokenHeader } from '../../client';
import modelsv2 from './models/types';
import * as modelsv2 from './models/types';
import AccountInformation from './accountInformation';
import Block from './block';
import Compile from './compile';
Expand Down
2 changes: 1 addition & 1 deletion src/client/v2/algod/dryrun.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import modelsv2 from './models/types';
import * as modelsv2 from './models/types';
import * as encoding from '../../../encoding/encoding';
import { setHeaders } from './compile';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { Address } from '../../../../types/address';

/**
* Base class for models
*/

/* eslint-disable no-underscore-dangle,camelcase,class-methods-use-this */
class BaseModel {
_is_primitive(val) {
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')
);
}

_is_address(val) {
_is_address(val: any): val is Address {
return val.publicKey !== undefined && val.checksum !== undefined;
}

_get_obj_for_encoding(val) {
let targetPropValue;
/* 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)) {
Expand All @@ -38,9 +47,10 @@ class BaseModel {
}
return targetPropValue;
}
/* eslint-disable no-dupe-class-members */

get_obj_for_encoding() {
const obj = {};
const obj: Record<string, any> = {};
for (const prop of Object.keys(this)) {
const val = this[prop];
if (prop !== 'attribute_map' && typeof val !== 'undefined') {
Expand All @@ -51,5 +61,3 @@ class BaseModel {
return obj;
}
}

module.exports = { BaseModel };
Loading