Skip to content

Commit

Permalink
refactor: organize ts reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Nov 10, 2019
1 parent 314fcbf commit b8c4c8a
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ module.exports = {
"max-len": [2, 120],
"object-curly-newline": ["error", {
"consistent": true
}],
"spaced-comment": ["error", "always", {
"markers": ["/"]
}]
},
"globals": {
Expand Down
2 changes: 2 additions & 0 deletions packages/ckb-sdk-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="../types/global" />

import RPC from '@nervosnetwork/ckb-sdk-rpc'
import { ArgumentRequired } from '@nervosnetwork/ckb-sdk-utils/lib/exceptions'
import ECPair from '@nervosnetwork/ckb-sdk-utils/lib/ecpair'
Expand Down
6 changes: 3 additions & 3 deletions packages/ckb-sdk-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"outDir": "lib",
"lib": ["es6", "esnext.array"],
"types": ["@nervosnetwork/ckb-types", "@nervosnetwork/ckb-sdk-utils", "./types/global"]
"typeRoots": ["@nervosnetwork/ckb-types", "nervosnetwork/ckb-sdk-utils", "types"]
},
"include": ["./src"]
"include": ["src"]
}
84 changes: 42 additions & 42 deletions packages/ckb-sdk-rpc/package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
{
"name": "@nervosnetwork/ckb-sdk-rpc",
"version": "0.24.2",
"description": "RPC module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme",
"license": "MIT",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"directories": {
"lib": "lib",
"test": "__tests__"
},
"files": [
"lib",
"types"
],
"publishConfig": {
"registry": "http://registry.npmjs.org/",
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nervosnetwork/ckb-sdk-js.git"
},
"scripts": {
"tsc": "tsc",
"test": "../../node_modules/.bin/jest",
"doc": "../../node_modules/.bin/typedoc --out docs --mode modules --includeDeclarations --excludeExternals --ignoreCompilerErrors --theme default",
"test:watch": "../../node_modules/.bin/jest --watch"
},
"bugs": {
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "0.24.2",
"axios": "0.19.0"
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.24.2",
"dotenv": "8.1.0"
},
"gitHead": "942872f4bfcf795bf516593a7d96126f058378db"
"name": "@nervosnetwork/ckb-sdk-rpc",
"version": "0.24.2",
"description": "RPC module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme",
"license": "MIT",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"directories": {
"lib": "lib",
"test": "__tests__"
},
"files": [
"lib",
"types"
],
"publishConfig": {
"registry": "http://registry.npmjs.org/",
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nervosnetwork/ckb-sdk-js.git"
},
"scripts": {
"tsc": "tsc",
"test": "../../node_modules/.bin/jest",
"doc": "../../node_modules/.bin/typedoc --out docs --mode modules --includeDeclarations --excludeExternals --ignoreCompilerErrors --theme default",
"test:watch": "../../node_modules/.bin/jest --watch"
},
"bugs": {
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "0.24.2",
"axios": "0.19.0"
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.24.2",
"dotenv": "8.1.0"
},
"gitHead": "942872f4bfcf795bf516593a7d96126f058378db"
}
2 changes: 2 additions & 0 deletions packages/ckb-sdk-rpc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="../types/rpc" />

import DefaultRPC from './defaultRPC'
import { DebugLevel } from './enum'
import Method from './method'
Expand Down
16 changes: 8 additions & 8 deletions packages/ckb-sdk-rpc/src/paramsFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const formatter = {
}
return format(arg)
},
toHash: (hash: string): CKB_RPC.Hash256 => {
toHash: (hash: string): RPC.Hash256 => {
if (typeof hash !== 'string') {
throw new TypeError(`Hash ${hash} should be type of string`)
}
return hash.startsWith('0x') ? hash : `0x${hash}`
},
toNumber: (number: CKBComponents.Number | bigint): CKB_RPC.Number => {
toNumber: (number: CKBComponents.Number | bigint): RPC.Number => {
if (typeof number === 'bigint') {
return `0x${number.toString(16)}`
}
Expand All @@ -25,15 +25,15 @@ const formatter = {
}
return number
},
toScript: (script: CKBComponents.Script): CKB_RPC.Script => {
toScript: (script: CKBComponents.Script): RPC.Script => {
const { codeHash, hashType: hash_type, ...rest } = script
return {
code_hash: formatter.toHash(codeHash),
hash_type,
...rest,
}
},
toOutPoint: (outPoint: CKBComponents.OutPoint | null): CKB_RPC.OutPoint | null => {
toOutPoint: (outPoint: CKBComponents.OutPoint | null): RPC.OutPoint | null => {
if (!outPoint) return outPoint
const { txHash, index, ...rest } = outPoint
return {
Expand All @@ -42,7 +42,7 @@ const formatter = {
...rest,
}
},
toInput: (input: CKBComponents.CellInput): CKB_RPC.CellInput => {
toInput: (input: CKBComponents.CellInput): RPC.CellInput => {
if (!input) return input
const { previousOutput, since, ...rest } = input
return {
Expand All @@ -51,7 +51,7 @@ const formatter = {
...rest,
}
},
toOutput: (output: CKBComponents.CellOutput): CKB_RPC.CellOutput => {
toOutput: (output: CKBComponents.CellOutput): RPC.CellOutput => {
if (!output) return output
const { capacity, lock, type = null, ...rest } = output
return {
Expand All @@ -67,7 +67,7 @@ const formatter = {
}
return type
},
toCellDep: (cellDep: CKBComponents.CellDep): CKB_RPC.CellDep => {
toCellDep: (cellDep: CKBComponents.CellDep): RPC.CellDep => {
if (!cellDep) return cellDep
const { outPoint = null, depType = 'code', ...rest } = cellDep
return {
Expand All @@ -76,7 +76,7 @@ const formatter = {
...rest,
}
},
toRawTransaction: (transaction: CKBComponents.RawTransaction): CKB_RPC.RawTransaction => {
toRawTransaction: (transaction: CKBComponents.RawTransaction): RPC.RawTransaction => {
if (!transaction) return transaction
const {
version,
Expand Down
Loading

0 comments on commit b8c4c8a

Please sign in to comment.