Skip to content

Commit

Permalink
Fixed bug where generated table functions don't match up with actual …
Browse files Browse the repository at this point in the history
…table functions at runtime if the table has a `.` in its name.
  • Loading branch information
thekevinbrown committed May 7, 2019
1 parent d3b616a commit f94ddb4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/contracts/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Api } from 'eosjs';
import { Contract as EOSJSContract, Type } from 'eosjs/dist/eosjs-serialize';
import { EOSManager } from '../eosManager';
import { Abi } from 'eosjs/dist/eosjs-rpc-interfaces';
import { camelCase } from './utils';

export interface ContractActionParameters {
[key: string]: any;
Expand Down Expand Up @@ -115,7 +116,7 @@ export class Contract implements EOSJSContract {
}
// And now the tables.
for (const table of abi.tables) {
(this as any)[table.name] = function() {
(this as any)[camelCase(table.name)] = function() {
return this.getTableRows(table.name, arguments[0]);
};
}
Expand Down
22 changes: 1 addition & 21 deletions src/contracts/typeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,10 @@ import * as path from 'path';
import { promisify } from 'util';
import mapTypes from './typeMap';
import { ConfigManager } from '../configManager';
import { pascalCase, camelCase } from './utils';

const glob = promisify(globWithCallbacks);

/**
* Transforms a string into the pascal-case format
* @author Kevin Brown <github.com/thekevinbrown>
* @param value String for case transformation
*/
const pascalCase = (value: string) => {
const snakePattern = /[_.]+./g;
const upperFirst = value[0].toUpperCase() + value.slice(1);
return upperFirst.replace(snakePattern, match => match[match.length - 1].toUpperCase());
};

/**
* Transforms a string into the camel-case format
* @author Kevin Brown <github.com/thekevinbrown>
* @param value String for case transformation
*/
const camelCase = (value: string) => {
const snakePattern = /[_.]+./g;
return value.replace(snakePattern, match => match[match.length - 1].toUpperCase());
};

type IndentedGeneratorLevel = { [key: string]: Array<string> | IndentedGeneratorLevel };
type GeneratorLevel = Array<string | IndentedGeneratorLevel>;

Expand Down
22 changes: 22 additions & 0 deletions src/contracts/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Transforms a string into the pascal-case format.
* ThisIsPascalCase, while thisIsCamelCase, this-is-kebab-case, and this_is_snake_case.
* @author Kevin Brown <github.com/thekevinbrown>
* @param value String for case transformation
*/
export const pascalCase = (value: string) => {
const snakePattern = /[_.]+./g;
const upperFirst = value[0].toUpperCase() + value.slice(1);
return upperFirst.replace(snakePattern, match => match[match.length - 1].toUpperCase());
};

/**
* Transforms a string into the camel-case format.
* ThisIsPascalCase, while thisIsCamelCase, this-is-kebab-case, and this_is_snake_case.
* @author Kevin Brown <github.com/thekevinbrown>
* @param value String for case transformation
*/
export const camelCase = (value: string) => {
const snakePattern = /[_.]+./g;
return value.replace(snakePattern, match => match[match.length - 1].toUpperCase());
};

0 comments on commit f94ddb4

Please sign in to comment.