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

feature: add schema extractor initially #5

Merged
merged 21 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
32 changes: 32 additions & 0 deletions __fixtures__/schema-data/public-methods/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { State } from './state';

export class MyContract {
private state: State;

constructor() {
this.state = {
count: 0,
startCoin: {
denom: 'uatom',
amount: '1000'
},
tokens: []
};
}

public increment() {
this.state.count++;
}

private reset() {
this.state.count = 0;
}

public addToken(denom: string, amount: string) {
this.state.tokens.push({ denom, amount });
}

public removeToken(index: number) {
this.state.tokens.splice(index, 1);
}
}
Anmol1696 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions __fixtures__/schema-data/public-methods/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { MyContract } from "./contract";
export type { State } from "./state";

export default MyContract;
10 changes: 10 additions & 0 deletions __fixtures__/schema-data/public-methods/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface State {
count: number;
startCoin: Coin;
tokens: Coin[];
}

interface Coin {
denom: string;
amount: string;
}
4 changes: 4 additions & 0 deletions __fixtures__/schema-data/state-export/coin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Coin {
denom: string;
amount: string;
}
7 changes: 7 additions & 0 deletions __fixtures__/schema-data/state-export/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Coin } from "./coin";

export interface State {
count: number;
startCoin: Coin;
tokens: Coin[];
}
33 changes: 33 additions & 0 deletions __output__/schema-data/public-methods.bundle.js

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

7 changes: 7 additions & 0 deletions __output__/schema-data/public-methods.bundle.js.map

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

78 changes: 78 additions & 0 deletions __output__/schema-data/public-methods.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"state": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"startCoin": {
"type": "object",
"properties": {
"denom": {
"type": "string"
},
"amount": {
"type": "string"
}
}
},
"tokens": {
"type": "array",
"items": {
"type": "object",
"properties": {
"denom": {
"type": "string"
},
"amount": {
"type": "string"
}
}
}
}
}
},
"methods": [
{
"functionName": "increment",
"parameters": [],
"returnType": {
"type": "any"
}
},
{
"functionName": "addToken",
"parameters": [
{
"name": "denom",
"type": {
"type": "string"
}
},
{
"name": "amount",
"type": {
"type": "string"
}
}
],
"returnType": {
"type": "any"
}
},
{
"functionName": "removeToken",
"parameters": [
{
"name": "index",
"type": {
"type": "number"
}
}
],
"returnType": {
"type": "any"
}
}
]
}
1 change: 1 addition & 0 deletions __output__/schema-data/state-export.bundle.js

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

7 changes: 7 additions & 0 deletions __output__/schema-data/state-export.bundle.js.map

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

36 changes: 36 additions & 0 deletions __output__/schema-data/state-export.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"state": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"startCoin": {
"type": "object",
"properties": {
"denom": {
"type": "string"
},
"amount": {
"type": "string"
}
}
},
"tokens": {
"type": "array",
"items": {
"type": "object",
"properties": {
"denom": {
"type": "string"
},
"amount": {
"type": "string"
}
}
}
}
}
},
"methods": []
}
121 changes: 121 additions & 0 deletions packages/build/__tests__/__snapshots__/schemaExtractor.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`schemaExtractorPlugin should extract a basic contract with public and private methods 1`] = `
{
"methods": [],
"state": {
"properties": {
"count": {
"type": "number",
},
"startCoin": {
"properties": {
"amount": {
"type": "string",
},
"denom": {
"type": "string",
},
},
"type": "object",
},
"tokens": {
"items": {
"properties": {
"amount": {
"type": "string",
},
"denom": {
"type": "string",
},
},
"type": "object",
},
"type": "array",
},
},
"type": "object",
},
}
`;

exports[`schemaExtractorPlugin should extract methods from classes public methods 1`] = `
{
"methods": [
{
"functionName": "increment",
Anmol1696 marked this conversation as resolved.
Show resolved Hide resolved
"parameters": [],
"returnType": {
"type": "any",
},
},
{
"functionName": "addToken",
"parameters": [
{
"name": "denom",
"type": {
"type": "string",
},
},
{
"name": "amount",
"type": {
"type": "string",
},
},
],
"returnType": {
"type": "any",
},
},
{
"functionName": "removeToken",
"parameters": [
{
"name": "index",
"type": {
"type": "number",
},
},
],
"returnType": {
"type": "any",
},
},
],
"state": {
"properties": {
"count": {
"type": "number",
},
"startCoin": {
"properties": {
"amount": {
"type": "string",
},
"denom": {
"type": "string",
},
},
"type": "object",
},
"tokens": {
"items": {
"properties": {
"amount": {
"type": "string",
},
"denom": {
"type": "string",
},
},
"type": "object",
},
"type": "array",
},
},
"type": "object",
},
}
`;
Loading