Start typescript client generation
This commit is contained in:
parent
ab576305c2
commit
840c38d8c1
|
@ -1,4 +1,6 @@
|
|||
bin/
|
||||
node_modules/
|
||||
dist/
|
||||
.idea/
|
||||
target/
|
||||
*~
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
preset: 'ts-jest/presets/default',
|
||||
testEnvironment: 'node',
|
||||
testTimeout: 90000
|
||||
};
|
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"name": "anchor",
|
||||
"version": "0.0.0",
|
||||
"description": "Anchor client",
|
||||
"main": "dist/cjs/index.js",
|
||||
"module": "dist/esm/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn build:node",
|
||||
"build:node": "tsc && tsc -p tsconfig.cjs.json",
|
||||
"watch": "tsc --watch",
|
||||
"test:unit": "jest test/unit",
|
||||
"test:integration": "jest test/integration --detectOpenHandles",
|
||||
"coverage": "jest --coverage test/unit",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@project-serum/borsh": "^0.0.1-beta.0",
|
||||
"@project-serum/common": "^0.0.1-beta.0",
|
||||
"@project-serum/lockup": "^0.0.1-beta.0",
|
||||
"@solana/spl-token": "0.0.11",
|
||||
"bn.js": "^5.1.2",
|
||||
"buffer-layout": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^8.2.0",
|
||||
"@commitlint/config-conventional": "^8.2.0",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@typescript-eslint/eslint-plugin": "^4.6.0",
|
||||
"@typescript-eslint/parser": "^4.6.0",
|
||||
"eslint": "^7.12.1",
|
||||
"eslint-config-prettier": "^6.15.0",
|
||||
"husky": "^4.3.0",
|
||||
"jest": "26.6.0",
|
||||
"jest-config": "26.6.0",
|
||||
"lint-staged": "^10.5.0",
|
||||
"prettier": "^2.1.2",
|
||||
"ts-jest": "^26.4.3",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@solana/web3.js": "^0.86.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
import { PublicKey } from '@solana/web3.js';
|
||||
|
||||
export class Program {
|
||||
/**
|
||||
* Address of the program.
|
||||
*/
|
||||
public programId: PublicKey;
|
||||
|
||||
/**
|
||||
* The inner variables required to implement the Program object.
|
||||
*/
|
||||
public _inner: ProgramInner;
|
||||
|
||||
public constructor(idl: Idl, programId: PublicKey, options?: ProgramOptions) {
|
||||
this.programId = programId;
|
||||
this._inner = {
|
||||
options: options === undefined ? {} : options,
|
||||
};
|
||||
console.log("building",idl);
|
||||
}
|
||||
}
|
||||
|
||||
type Idl = any;
|
||||
|
||||
type ProgramInner = {
|
||||
options: ProgramOptions;
|
||||
}
|
||||
|
||||
type ProgramOptions = {};
|
|
@ -0,0 +1,10 @@
|
|||
const anchor = require('.');
|
||||
|
||||
console.log(anchor)
|
||||
function test() {
|
||||
const fs = require('fs');
|
||||
const idl = JSON.parse(fs.readFileSync('../examples/basic/idl.json', 'utf8'));
|
||||
const program = new anchor.Program(idl);
|
||||
}
|
||||
|
||||
test();
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es2019",
|
||||
|
||||
"outDir": "dist/cjs/",
|
||||
"rootDir": "./src"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"include": ["src"],
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "node",
|
||||
"module": "es6",
|
||||
"target": "es2019",
|
||||
|
||||
"outDir": "dist/esm/",
|
||||
"rootDir": "./src",
|
||||
"declarationDir": "dist",
|
||||
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"noImplicitAny": true,
|
||||
|
||||
"esModuleInterop": true,
|
||||
"composite": true,
|
||||
"baseUrl": ".",
|
||||
"typeRoots": ["types/", "node_modules/@types"],
|
||||
"paths": {
|
||||
"@solana/web3.js": ["../../node_modules/@solana/web3.js/lib"]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
|
||||
declare module 'buffer-layout' {
|
||||
// TODO: remove `any`.
|
||||
export class Layout<T = any> {
|
||||
span: number;
|
||||
property?: string;
|
||||
|
||||
constructor(span: number, property?: string);
|
||||
|
||||
decode(b: Buffer, offset?: number): T;
|
||||
encode(src: T, b: Buffer, offset?: number): number;
|
||||
getSpan(b: Buffer, offset?: number): number;
|
||||
replicate(name: string): this;
|
||||
}
|
||||
// TODO: remove any.
|
||||
export class Structure<T = any> extends Layout<T> {
|
||||
span: any;
|
||||
}
|
||||
export function greedy(
|
||||
elementSpan?: number,
|
||||
property?: string,
|
||||
): Layout<number>;
|
||||
export function offset<T>(
|
||||
layout: Layout<T>,
|
||||
offset?: number,
|
||||
property?: string,
|
||||
): Layout<T>;
|
||||
export function u8(property?: string): Layout<number>;
|
||||
export function u16(property?: string): Layout<number>;
|
||||
export function u24(property?: string): Layout<number>;
|
||||
export function u32(property?: string): Layout<number>;
|
||||
export function u40(property?: string): Layout<number>;
|
||||
export function u48(property?: string): Layout<number>;
|
||||
export function nu64(property?: string): Layout<number>;
|
||||
export function u16be(property?: string): Layout<number>;
|
||||
export function u24be(property?: string): Layout<number>;
|
||||
export function u32be(property?: string): Layout<number>;
|
||||
export function u40be(property?: string): Layout<number>;
|
||||
export function u48be(property?: string): Layout<number>;
|
||||
export function nu64be(property?: string): Layout<number>;
|
||||
export function s8(property?: string): Layout<number>;
|
||||
export function s16(property?: string): Layout<number>;
|
||||
export function s24(property?: string): Layout<number>;
|
||||
export function s32(property?: string): Layout<number>;
|
||||
export function s40(property?: string): Layout<number>;
|
||||
export function s48(property?: string): Layout<number>;
|
||||
export function ns64(property?: string): Layout<number>;
|
||||
export function s16be(property?: string): Layout<number>;
|
||||
export function s24be(property?: string): Layout<number>;
|
||||
export function s32be(property?: string): Layout<number>;
|
||||
export function s40be(property?: string): Layout<number>;
|
||||
export function s48be(property?: string): Layout<number>;
|
||||
export function ns64be(property?: string): Layout<number>;
|
||||
export function f32(property?: string): Layout<number>;
|
||||
export function f32be(property?: string): Layout<number>;
|
||||
export function f64(property?: string): Layout<number>;
|
||||
export function f64be(property?: string): Layout<number>;
|
||||
export function struct<T>(
|
||||
fields: Layout<any>[],
|
||||
property?: string,
|
||||
decodePrefixes?: boolean,
|
||||
): Layout<T>;
|
||||
export function bits(
|
||||
word: Layout<number>,
|
||||
msb?: boolean,
|
||||
property?: string,
|
||||
): any;
|
||||
export function seq<T>(
|
||||
elementLayout: Layout<T>,
|
||||
count: number | Layout<number>,
|
||||
property?: string,
|
||||
): Layout<T[]>;
|
||||
export function union(
|
||||
discr: Layout<any>,
|
||||
defaultLayout?: any,
|
||||
property?: string,
|
||||
): any;
|
||||
export function unionLayoutDiscriminator(
|
||||
layout: Layout<any>,
|
||||
property?: string,
|
||||
): any;
|
||||
export function blob(
|
||||
length: number | Layout<number>,
|
||||
property?: string,
|
||||
): Layout<Buffer>;
|
||||
export function cstr(property?: string): Layout<string>;
|
||||
export function utf8(maxSpan: number, property?: string): Layout<string>;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue