mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 01:36:56 +01:00
Merge pull request #312 from bigchaindb/fet-improve-requests
feat: improve requests
This commit is contained in:
commit
f9a4675726
@ -193,7 +193,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true }],
|
||||||
/**
|
/**
|
||||||
* ES6-specific Issues
|
* ES6-specific Issues
|
||||||
* (http://eslint.org/docs/rules/#ecmascript-6)
|
* (http://eslint.org/docs/rules/#ecmascript-6)
|
||||||
|
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@ -45,6 +45,11 @@ jobs:
|
|||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-node-
|
${{ runner.os }}-node-
|
||||||
|
|
||||||
|
- name: Run BigChainDB node
|
||||||
|
run: |
|
||||||
|
echo Building and starting up docker containers
|
||||||
|
docker-compose -f ./docker-compose.yml up -d
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
env:
|
env:
|
||||||
HUSKY_SKIP_INSTALL: 'true'
|
HUSKY_SKIP_INSTALL: 'true'
|
||||||
@ -56,10 +61,8 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
- name: Build docker
|
# ensure BCDB node is up and running
|
||||||
run: |
|
- run: sleep 20
|
||||||
echo Building and starting up docker containers
|
|
||||||
docker-compose -f ./docker-compose.yml up
|
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: npm run test
|
run: npm run test
|
||||||
|
66
package.json
66
package.json
@ -20,6 +20,7 @@
|
|||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
|
"lint:fix": "eslint . --fix",
|
||||||
"build": "npm run clean && npm run build:cjs && npm run build:dist",
|
"build": "npm run clean && npm run build:cjs && npm run build:dist",
|
||||||
"build:bundle": "webpack",
|
"build:bundle": "webpack",
|
||||||
"build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node",
|
"build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node",
|
||||||
@ -36,55 +37,54 @@
|
|||||||
"doc": "documentation build src/index.js -f md -o API.md -g --markdown-toc"
|
"doc": "documentation build src/index.js -f md -o API.md -g --markdown-toc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ava/babel": "^1.0.1",
|
"@ava/babel": "^2.0.0",
|
||||||
"@babel/cli": "^7.13.0",
|
"@babel/cli": "^7.17.0",
|
||||||
"@babel/core": "^7.13.8",
|
"@babel/core": "^7.17.2",
|
||||||
"@babel/eslint-parser": "^7.13.8",
|
"@babel/eslint-parser": "^7.17.0",
|
||||||
"@babel/plugin-proposal-export-default-from": "^7.12.13",
|
"@babel/plugin-proposal-export-default-from": "^7.16.7",
|
||||||
"@babel/plugin-proposal-object-rest-spread": "^7.13.8",
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
|
||||||
"@babel/plugin-syntax-async-generators": "^7.8.4",
|
"@babel/plugin-syntax-async-generators": "^7.8.4",
|
||||||
"@babel/plugin-transform-async-to-generator": "^7.13.0",
|
"@babel/plugin-transform-async-to-generator": "^7.16.8",
|
||||||
"@babel/plugin-transform-object-assign": "^7.12.13",
|
"@babel/plugin-transform-object-assign": "^7.16.7",
|
||||||
"@babel/plugin-transform-regenerator": "^7.12.13",
|
"@babel/plugin-transform-regenerator": "^7.16.7",
|
||||||
"@babel/plugin-transform-runtime": "^7.13.9",
|
"@babel/plugin-transform-runtime": "^7.17.0",
|
||||||
"@babel/preset-env": "^7.13.9",
|
"@babel/preset-env": "^7.16.11",
|
||||||
"@babel/register": "^7.13.8",
|
"@babel/register": "^7.17.0",
|
||||||
"ava": "^3.15.0",
|
"ava": "^3.15.0",
|
||||||
"babel-loader": "^8.2.2",
|
"babel-loader": "^8.2.2",
|
||||||
|
"buffer": "^6.0.3",
|
||||||
"codecov": "^3.8.1",
|
"codecov": "^3.8.1",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"documentation": "^13.1.1",
|
"documentation": "^13.2.5",
|
||||||
"eslint": "^7.21.0",
|
"eslint": "^8.9.0",
|
||||||
"eslint-config-airbnb-base": "^14.2.1",
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
"eslint-plugin-import": "^2.22.1",
|
"eslint-plugin-import": "^2.25.4",
|
||||||
"husky": "^5.1.3",
|
"husky": "^7.0.4",
|
||||||
"lint-staged": "^10.5.4",
|
"lint-staged": "^12.3.4",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"release-it": "^14.4.1",
|
"release-it": "^14.12.4",
|
||||||
"rewire": "^4.0.1",
|
"rewire": "^6.0.0",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"sinon": "^7.3.2",
|
"sinon": "^13.0.1",
|
||||||
"terser-webpack-plugin": "^4.2.3",
|
"terser-webpack-plugin": "^5.3.1",
|
||||||
"webpack": "^4.46.0",
|
"webpack": "^5.68.0",
|
||||||
"webpack-cli": "^4.5.0",
|
"webpack-cli": "^4.9.2",
|
||||||
"webpack-concat-plugin": "^3.0.0",
|
"webpack-merge": "^5.8.0",
|
||||||
"webpack-merge": "^5.7.3",
|
"webpack-sources": "^3.2.3"
|
||||||
"webpack-sources": "^2.2.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime-corejs3": "^7.13.9",
|
"@babel/runtime-corejs3": "^7.17.2",
|
||||||
"browser-resolve": "^1.11.3",
|
"abort-controller": "^3.0.0",
|
||||||
"bs58": "^4.0.1",
|
"bs58": "^4.0.1",
|
||||||
"buffer": "^6.0.3",
|
|
||||||
"clone": "^2.1.2",
|
"clone": "^2.1.2",
|
||||||
"core-js": "^3.9.1",
|
"core-js": "^3.21.0",
|
||||||
"crypto-conditions": "2.1.2",
|
"crypto-conditions": "2.2.1",
|
||||||
"decamelize": "^5.0.0",
|
"decamelize": "^5.0.0",
|
||||||
"es6-promise": "^4.2.8",
|
"es6-promise": "^4.2.8",
|
||||||
"fetch-ponyfill": "^7.1.0",
|
"fetch-ponyfill": "^7.1.0",
|
||||||
"js-sha3": "^0.8.0",
|
"js-sha3": "^0.8.0",
|
||||||
"json-stable-stringify": "^1.0.1",
|
"json-stable-stringify": "^1.0.1",
|
||||||
"query-string": "^6.14.1",
|
"query-string": "^7.1.1",
|
||||||
"sprintf-js": "^1.1.2",
|
"sprintf-js": "^1.1.2",
|
||||||
"tweetnacl": "^1.0.3"
|
"tweetnacl": "^1.0.3"
|
||||||
},
|
},
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
|
// TODO: remove abort-controller when using Node >=15
|
||||||
|
import AbortController from 'abort-controller'
|
||||||
import { Promise } from 'es6-promise'
|
import { Promise } from 'es6-promise'
|
||||||
import fetchPonyfill from 'fetch-ponyfill'
|
import fetchPonyfill from 'fetch-ponyfill'
|
||||||
import { vsprintf } from 'sprintf-js'
|
import { vsprintf } from 'sprintf-js'
|
||||||
@ -9,14 +11,14 @@ import { vsprintf } from 'sprintf-js'
|
|||||||
import formatText from './format_text'
|
import formatText from './format_text'
|
||||||
import stringifyAsQueryParam from './stringify_as_query_param'
|
import stringifyAsQueryParam from './stringify_as_query_param'
|
||||||
|
|
||||||
const fetch = fetchPonyfill(Promise)
|
const fetch = fetchPonyfill({ Promise })
|
||||||
|
|
||||||
export function ResponseError(message, status, requestURI) {
|
export function ResponseError(message, status, requestURI) {
|
||||||
this.name = 'ResponseError'
|
this.name = 'ResponseError'
|
||||||
this.message = message
|
this.message = message
|
||||||
this.status = status
|
this.status = status
|
||||||
this.requestURI = requestURI
|
this.requestURI = requestURI
|
||||||
this.stack = (new Error()).stack
|
this.stack = new Error().stack
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseError.prototype = new Error()
|
ResponseError.prototype = new Error()
|
||||||
@ -26,17 +28,27 @@ ResponseError.prototype = new Error()
|
|||||||
* Timeout function following https://github.com/github/fetch/issues/175#issuecomment-284787564
|
* Timeout function following https://github.com/github/fetch/issues/175#issuecomment-284787564
|
||||||
* @param {integer} obj Source object
|
* @param {integer} obj Source object
|
||||||
* @param {Promise} filter Array of key names to select or function to invoke per iteration
|
* @param {Promise} filter Array of key names to select or function to invoke per iteration
|
||||||
|
* @param {AbortController} controller AbortController instance bound to fetch
|
||||||
* @return {Object} TimeoutError if the time was consumed, otherwise the Promise will be resolved
|
* @return {Object} TimeoutError if the time was consumed, otherwise the Promise will be resolved
|
||||||
*/
|
*/
|
||||||
function timeout(ms, promise) {
|
function timeout(ms, promise, controller) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {
|
const nodeTimeout = setTimeout(() => {
|
||||||
|
controller.abort()
|
||||||
const errorObject = {
|
const errorObject = {
|
||||||
message: 'TimeoutError'
|
message: 'TimeoutError',
|
||||||
}
|
}
|
||||||
reject(new Error(errorObject))
|
reject(new Error(errorObject))
|
||||||
}, ms)
|
}, ms)
|
||||||
promise.then(resolve, reject)
|
promise
|
||||||
|
.then((res) => {
|
||||||
|
clearTimeout(nodeTimeout)
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
clearTimeout(nodeTimeout)
|
||||||
|
reject(err)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,25 +100,30 @@ function handleResponse(res) {
|
|||||||
* @return {Promise} If requestTimeout the timeout function will be called. Otherwise resolve the
|
* @return {Promise} If requestTimeout the timeout function will be called. Otherwise resolve the
|
||||||
* Promise with the handleResponse function
|
* Promise with the handleResponse function
|
||||||
*/
|
*/
|
||||||
export default function baseRequest(url, {
|
export default function baseRequest(
|
||||||
jsonBody,
|
url,
|
||||||
query,
|
{
|
||||||
urlTemplateSpec,
|
jsonBody, query, urlTemplateSpec, ...fetchConfig
|
||||||
...fetchConfig
|
} = {},
|
||||||
} = {}, requestTimeout) {
|
requestTimeout = 0
|
||||||
|
) {
|
||||||
let expandedUrl = url
|
let expandedUrl = url
|
||||||
|
|
||||||
if (urlTemplateSpec != null) {
|
if (urlTemplateSpec != null) {
|
||||||
if (Array.isArray(urlTemplateSpec) && urlTemplateSpec.length) {
|
if (Array.isArray(urlTemplateSpec) && urlTemplateSpec.length) {
|
||||||
// Use vsprintf for the array call signature
|
// Use vsprintf for the array call signature
|
||||||
expandedUrl = vsprintf(url, urlTemplateSpec)
|
expandedUrl = vsprintf(url, urlTemplateSpec)
|
||||||
} else if (urlTemplateSpec &&
|
} else if (
|
||||||
|
urlTemplateSpec &&
|
||||||
typeof urlTemplateSpec === 'object' &&
|
typeof urlTemplateSpec === 'object' &&
|
||||||
Object.keys(urlTemplateSpec).length) {
|
Object.keys(urlTemplateSpec).length
|
||||||
|
) {
|
||||||
expandedUrl = formatText(url, urlTemplateSpec)
|
expandedUrl = formatText(url, urlTemplateSpec)
|
||||||
} else if (process.env.NODE_ENV !== 'production') {
|
} else if (process.env.NODE_ENV !== 'production') {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.warn('Supplied urlTemplateSpec was not an array or object. Ignoring...')
|
console.warn(
|
||||||
|
'Supplied urlTemplateSpec was not an array or object. Ignoring...'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,11 +141,17 @@ export default function baseRequest(url, {
|
|||||||
if (jsonBody != null) {
|
if (jsonBody != null) {
|
||||||
fetchConfig.body = JSON.stringify(jsonBody)
|
fetchConfig.body = JSON.stringify(jsonBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestTimeout) {
|
if (requestTimeout) {
|
||||||
return timeout(requestTimeout, fetch.fetch(expandedUrl, fetchConfig))
|
const controller = new AbortController()
|
||||||
|
const { signal } = controller
|
||||||
|
return timeout(
|
||||||
|
requestTimeout,
|
||||||
|
fetch.fetch(expandedUrl, { ...fetchConfig, signal }),
|
||||||
|
controller
|
||||||
|
)
|
||||||
.then(handleResponse)
|
.then(handleResponse)
|
||||||
} else {
|
} else {
|
||||||
return fetch.fetch(expandedUrl, fetchConfig)
|
return fetch.fetch(expandedUrl, fetchConfig).then(handleResponse)
|
||||||
.then(handleResponse)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,10 +178,11 @@ export default class Connection {
|
|||||||
/**
|
/**
|
||||||
* @param search
|
* @param search
|
||||||
*/
|
*/
|
||||||
searchAssets(search) {
|
searchAssets(search, limit = 10) {
|
||||||
return this._req(Connection.getApiUrls('assets'), {
|
return this._req(Connection.getApiUrls('assets'), {
|
||||||
query: {
|
query: {
|
||||||
search
|
search,
|
||||||
|
limit
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -189,10 +190,11 @@ export default class Connection {
|
|||||||
/**
|
/**
|
||||||
* @param search
|
* @param search
|
||||||
*/
|
*/
|
||||||
searchMetadata(search) {
|
searchMetadata(search, limit = 10) {
|
||||||
return this._req(Connection.getApiUrls('metadata'), {
|
return this._req(Connection.getApiUrls('metadata'), {
|
||||||
query: {
|
query: {
|
||||||
search
|
search,
|
||||||
|
limit
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ export default class Request {
|
|||||||
|
|
||||||
const requestTimeout = timeout ? timeout - backoffTimedelta : timeout
|
const requestTimeout = timeout ? timeout - backoffTimedelta : timeout
|
||||||
return baseRequest(apiUrl, requestConfig, requestTimeout)
|
return baseRequest(apiUrl, requestConfig, requestTimeout)
|
||||||
.then(async (res) => {
|
.then((res) => {
|
||||||
this.connectionError = null
|
this.connectionError = null
|
||||||
return res.json()
|
return res.json()
|
||||||
})
|
})
|
||||||
@ -111,6 +111,8 @@ export default class Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static sleep(ms) {
|
static sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms))
|
return new Promise(resolve => {
|
||||||
|
setTimeout(resolve, ms)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import { Buffer } from 'buffer'
|
|
||||||
import stableStringify from 'json-stable-stringify'
|
import stableStringify from 'json-stable-stringify'
|
||||||
import clone from 'clone'
|
import clone from 'clone'
|
||||||
import base58 from 'bs58'
|
import base58 from 'bs58'
|
||||||
|
@ -225,7 +225,7 @@ test('Get asset for text', t => {
|
|||||||
conn.searchAssets(search)
|
conn.searchAssets(search)
|
||||||
t.truthy(conn._req.calledWith(
|
t.truthy(conn._req.calledWith(
|
||||||
expectedPath,
|
expectedPath,
|
||||||
{ query: { search } }
|
{ query: { search, limit: 10 } }
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -239,6 +239,6 @@ test('Get metadata for text', t => {
|
|||||||
conn.searchMetadata(search)
|
conn.searchMetadata(search)
|
||||||
t.truthy(conn._req.calledWith(
|
t.truthy(conn._req.calledWith(
|
||||||
expectedPath,
|
expectedPath,
|
||||||
{ query: { search } }
|
{ query: { search, limit: 10 } }
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
@ -92,7 +92,8 @@ test('Fulfillment correctly formed', t => {
|
|||||||
const msgHash = sha256Hash(msgUniqueFulfillment)
|
const msgHash = sha256Hash(msgUniqueFulfillment)
|
||||||
|
|
||||||
t.truthy(validateFulfillment(
|
t.truthy(validateFulfillment(
|
||||||
txSigned.inputs[0].fulfillment, txCreate.outputs[0].condition.uri,
|
txSigned.inputs[0].fulfillment,
|
||||||
|
txCreate.outputs[0].condition.uri,
|
||||||
Buffer.from(msgHash, 'hex')
|
Buffer.from(msgHash, 'hex')
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
36
types/connection.d.ts
vendored
36
types/connection.d.ts
vendored
@ -19,6 +19,16 @@ export interface InputNode {
|
|||||||
endpoint: string;
|
endpoint: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type AssetResult = {
|
||||||
|
id: string;
|
||||||
|
data: Record<string, any>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type MetadataResult = {
|
||||||
|
id: string;
|
||||||
|
metadata: Record<string, any>;
|
||||||
|
};
|
||||||
|
|
||||||
export enum Endpoints {
|
export enum Endpoints {
|
||||||
blocks = 'blocks',
|
blocks = 'blocks',
|
||||||
blocksDetail = 'blocksDetail',
|
blocksDetail = 'blocksDetail',
|
||||||
@ -76,8 +86,8 @@ export interface EndpointsResponse<
|
|||||||
[Endpoints.transactionsDetail]: O extends TransactionOperations.CREATE
|
[Endpoints.transactionsDetail]: O extends TransactionOperations.CREATE
|
||||||
? CreateTransaction<A, M>
|
? CreateTransaction<A, M>
|
||||||
: TransferTransaction<M>;
|
: TransferTransaction<M>;
|
||||||
[Endpoints.assets]: { id: string; data: Record<string, any> }[];
|
[Endpoints.assets]: AssetResult[];
|
||||||
[Endpoints.metadata]: { id: string; metadata: Record<string, any> }[];
|
[Endpoints.metadata]: MetadataResult[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Connection {
|
export default class Connection {
|
||||||
@ -111,7 +121,9 @@ export default class Connection {
|
|||||||
transactionId: string
|
transactionId: string
|
||||||
): Promise<EndpointsResponse<O>[Endpoints.transactionsDetail]>;
|
): Promise<EndpointsResponse<O>[Endpoints.transactionsDetail]>;
|
||||||
|
|
||||||
listBlocks(transactionId: string): Promise<EndpointsResponse[Endpoints.blocks]>;
|
listBlocks(
|
||||||
|
transactionId: string
|
||||||
|
): Promise<EndpointsResponse[Endpoints.blocks]>;
|
||||||
|
|
||||||
listOutputs(
|
listOutputs(
|
||||||
publicKey: string,
|
publicKey: string,
|
||||||
@ -124,7 +136,7 @@ export default class Connection {
|
|||||||
): Promise<EndpointsResponse<typeof operation>[Endpoints.transactions]>;
|
): Promise<EndpointsResponse<typeof operation>[Endpoints.transactions]>;
|
||||||
|
|
||||||
postTransaction<
|
postTransaction<
|
||||||
O = TransactionOperations.CREATE,
|
O extends TransactionOperations = TransactionOperations.CREATE,
|
||||||
A = Record<string, any>,
|
A = Record<string, any>,
|
||||||
M = Record<string, any>
|
M = Record<string, any>
|
||||||
>(
|
>(
|
||||||
@ -132,7 +144,7 @@ export default class Connection {
|
|||||||
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
|
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
|
||||||
|
|
||||||
postTransactionSync<
|
postTransactionSync<
|
||||||
O = TransactionOperations.CREATE,
|
O extends TransactionOperations = TransactionOperations.CREATE,
|
||||||
A = Record<string, any>,
|
A = Record<string, any>,
|
||||||
M = Record<string, any>
|
M = Record<string, any>
|
||||||
>(
|
>(
|
||||||
@ -140,7 +152,7 @@ export default class Connection {
|
|||||||
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsSync]>;
|
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsSync]>;
|
||||||
|
|
||||||
postTransactionAsync<
|
postTransactionAsync<
|
||||||
O = TransactionOperations.CREATE,
|
O extends TransactionOperations = TransactionOperations.CREATE,
|
||||||
A = Record<string, any>,
|
A = Record<string, any>,
|
||||||
M = Record<string, any>
|
M = Record<string, any>
|
||||||
>(
|
>(
|
||||||
@ -148,14 +160,20 @@ export default class Connection {
|
|||||||
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsAsync]>;
|
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsAsync]>;
|
||||||
|
|
||||||
postTransactionCommit<
|
postTransactionCommit<
|
||||||
O = TransactionOperations.CREATE,
|
O extends TransactionOperations = TransactionOperations.CREATE,
|
||||||
A = Record<string, any>,
|
A = Record<string, any>,
|
||||||
M = Record<string, any>
|
M = Record<string, any>
|
||||||
>(
|
>(
|
||||||
transaction: TransactionCommon<O>
|
transaction: TransactionCommon<O>
|
||||||
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
|
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
|
||||||
|
|
||||||
searchAssets(search: string): Promise<EndpointsResponse[Endpoints.assets]>;
|
searchAssets(
|
||||||
|
search: string,
|
||||||
|
limit?: number
|
||||||
|
): Promise<EndpointsResponse[Endpoints.assets]>;
|
||||||
|
|
||||||
searchMetadata(search: string): Promise<EndpointsResponse[Endpoints.metadata]>;
|
searchMetadata(
|
||||||
|
search: string,
|
||||||
|
limit?: number
|
||||||
|
): Promise<EndpointsResponse[Endpoints.metadata]>;
|
||||||
}
|
}
|
||||||
|
40
types/index.d.ts
vendored
40
types/index.d.ts
vendored
@ -2,10 +2,38 @@
|
|||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import Ed25519Keypair from './Ed25519Keypair'
|
import Ed25519Keypair from './Ed25519Keypair';
|
||||||
import Connection from './connection'
|
import Connection, {
|
||||||
import Transaction from './transaction'
|
Endpoints,
|
||||||
import ccJsonLoad from './utils/ccJsonLoad'
|
EndpointsResponse,
|
||||||
import ccJsonify from './utils/ccJsonify'
|
EndpointsUrl,
|
||||||
|
} from './connection';
|
||||||
|
import Transaction, {
|
||||||
|
CreateTransaction,
|
||||||
|
TransactionCommon,
|
||||||
|
TransactionCommonSigned,
|
||||||
|
TransactionInput,
|
||||||
|
TransactionOutput,
|
||||||
|
TransferTransaction,
|
||||||
|
TransactionUnspentOutput,
|
||||||
|
TransactionOperations,
|
||||||
|
} from './transaction';
|
||||||
|
import ccJsonLoad from './utils/ccJsonLoad';
|
||||||
|
import ccJsonify from './utils/ccJsonify';
|
||||||
|
|
||||||
export { ccJsonLoad, ccJsonify, Connection, Ed25519Keypair, Transaction }
|
export { ccJsonLoad, ccJsonify, Connection, Ed25519Keypair, Transaction };
|
||||||
|
|
||||||
|
// Extras
|
||||||
|
export {
|
||||||
|
Endpoints,
|
||||||
|
EndpointsResponse,
|
||||||
|
EndpointsUrl,
|
||||||
|
CreateTransaction,
|
||||||
|
TransactionCommon,
|
||||||
|
TransactionCommonSigned,
|
||||||
|
TransactionInput,
|
||||||
|
TransactionOutput,
|
||||||
|
TransferTransaction,
|
||||||
|
TransactionUnspentOutput,
|
||||||
|
TransactionOperations,
|
||||||
|
};
|
||||||
|
6
types/sanitize.d.ts
vendored
6
types/sanitize.d.ts
vendored
@ -6,8 +6,8 @@ declare type FilterFn = (val: any, key?: string) => void;
|
|||||||
|
|
||||||
declare function filterFromObject<I = Record<string, any>>(
|
declare function filterFromObject<I = Record<string, any>>(
|
||||||
obj: I,
|
obj: I,
|
||||||
filter: Array | FilterFn,
|
filter: Array<any> | FilterFn,
|
||||||
conf: { isInclusion?: boolean } = {}
|
conf: { isInclusion?: boolean }
|
||||||
): Partial<I>;
|
): Partial<I>;
|
||||||
|
|
||||||
declare function applyFilterOnObject<I = Record<string, any>>(
|
declare function applyFilterOnObject<I = Record<string, any>>(
|
||||||
@ -17,7 +17,7 @@ declare function applyFilterOnObject<I = Record<string, any>>(
|
|||||||
|
|
||||||
declare function selectFromObject<I = Record<string, any>>(
|
declare function selectFromObject<I = Record<string, any>>(
|
||||||
obj: I,
|
obj: I,
|
||||||
filter: Array | FilterFn
|
filter: Array<any> | FilterFn
|
||||||
): Partial<I>;
|
): Partial<I>;
|
||||||
|
|
||||||
export default function sanitize<I = Record<string, any>>(
|
export default function sanitize<I = Record<string, any>>(
|
||||||
|
50
types/transaction.d.ts
vendored
50
types/transaction.d.ts
vendored
@ -33,9 +33,9 @@ export enum TransactionOperations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface TransactionCommon<
|
export interface TransactionCommon<
|
||||||
O = TransactionOperations,
|
O extends TransactionOperations = TransactionOperations.CREATE,
|
||||||
A = Record<string, unknown>,
|
A extends Record<string, any> = Record<string, unknown>,
|
||||||
M = Record<string, unknown>
|
M extends Record<string, any> = Record<string, unknown>
|
||||||
> {
|
> {
|
||||||
id?: string;
|
id?: string;
|
||||||
inputs: TransactionInput[];
|
inputs: TransactionInput[];
|
||||||
@ -47,16 +47,16 @@ export interface TransactionCommon<
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface TransactionCommonSigned<
|
export interface TransactionCommonSigned<
|
||||||
O = TransactionOperations,
|
O extends TransactionOperations = TransactionOperations.CREATE,
|
||||||
A = Record<string, unknown>,
|
A extends Record<string, any> = Record<string, unknown>,
|
||||||
M = Record<string, unknown>
|
M extends Record<string, any> = Record<string, unknown>
|
||||||
> extends Omit<TransactionCommon<O, A, M>, 'id'> {
|
> extends Omit<TransactionCommon<O, A, M>, 'id'> {
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TransactionAssetMap<
|
export type TransactionAssetMap<
|
||||||
Operation,
|
Operation,
|
||||||
A = Record<string, unknown>
|
A extends Record<string, any>
|
||||||
> = Operation extends TransactionOperations.CREATE
|
> = Operation extends TransactionOperations.CREATE
|
||||||
? {
|
? {
|
||||||
data: A;
|
data: A;
|
||||||
@ -66,18 +66,19 @@ export type TransactionAssetMap<
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface CreateTransaction<
|
export interface CreateTransaction<
|
||||||
A = Record<string, unknown>,
|
A extends Record<string, any> = Record<string, unknown>,
|
||||||
M = Record<string, unknown>
|
M extends Record<string, any> = Record<string, unknown>
|
||||||
> extends TransactionCommon<TransactionOperations.CREATE, A, M> {
|
> extends TransactionCommon<TransactionOperations.CREATE, A, M> {
|
||||||
id: string;
|
id: string;
|
||||||
asset: TransactionAssetMap<TransactionOperations.CREATE, A>;
|
asset: TransactionAssetMap<TransactionOperations.CREATE, A>;
|
||||||
operation: TransactionOperations.CREATE;
|
operation: TransactionOperations.CREATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TransferTransaction<M = Record<string, unknown>>
|
export interface TransferTransaction<
|
||||||
extends TransactionCommon<TransactionOperations.TRANSFER, any, M> {
|
M extends Record<string, any> = Record<string, unknown>
|
||||||
|
> extends TransactionCommon<TransactionOperations.TRANSFER, any, M> {
|
||||||
id: string;
|
id: string;
|
||||||
asset: TransactionAssetMap<TransactionOperations.TRANSFER>;
|
asset: TransactionAssetMap<TransactionOperations.TRANSFER, { id: string }>;
|
||||||
operation: TransactionOperations.TRANSFER;
|
operation: TransactionOperations.TRANSFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,22 +97,22 @@ interface TxTemplate {
|
|||||||
version: '2.0';
|
version: '2.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
declare type DelegateSignFunction = (
|
export type DelegateSignFunction = (
|
||||||
serializedTransaction: string,
|
serializedTransaction: string,
|
||||||
input: TransactionInput,
|
input: TransactionInput,
|
||||||
index?: number
|
index?: number
|
||||||
) => string;
|
) => string;
|
||||||
|
|
||||||
declare type DelegateSignFunctionAsync = (
|
export type DelegateSignFunctionAsync = (
|
||||||
serializedTransaction: string,
|
serializedTransaction: string,
|
||||||
input: TransactionInput,
|
input: TransactionInput,
|
||||||
index?: number
|
index?: number
|
||||||
) => Promise<string>;
|
) => Promise<string>;
|
||||||
|
|
||||||
export default class Transaction {
|
export default class Transaction {
|
||||||
static serializeTransactionIntoCanonicalString<O = TransactionOperations>(
|
static serializeTransactionIntoCanonicalString<
|
||||||
transaction: TransactionCommon<O>
|
O extends TransactionOperations = TransactionOperations
|
||||||
): string;
|
>(transaction: TransactionCommon<O>): string;
|
||||||
|
|
||||||
static serializeTransactionIntoCanonicalString(
|
static serializeTransactionIntoCanonicalString(
|
||||||
transaction: CreateTransaction | TransferTransaction
|
transaction: CreateTransaction | TransferTransaction
|
||||||
@ -185,7 +186,7 @@ export default class Transaction {
|
|||||||
static makeTransactionTemplate(): TxTemplate;
|
static makeTransactionTemplate(): TxTemplate;
|
||||||
|
|
||||||
static makeTransaction<
|
static makeTransaction<
|
||||||
O extends keyof TransactionOperations,
|
O extends TransactionOperations,
|
||||||
A = Record<string, any>,
|
A = Record<string, any>,
|
||||||
M = Record<string, any>
|
M = Record<string, any>
|
||||||
>(
|
>(
|
||||||
@ -212,18 +213,23 @@ export default class Transaction {
|
|||||||
metadata: M
|
metadata: M
|
||||||
): TransferTransaction<M>;
|
): TransferTransaction<M>;
|
||||||
|
|
||||||
static signTransaction<O = TransactionOperations.CREATE>(
|
static signTransaction<
|
||||||
|
O extends TransactionOperations = TransactionOperations.CREATE
|
||||||
|
>(
|
||||||
transaction: TransactionCommon<O>,
|
transaction: TransactionCommon<O>,
|
||||||
...privateKeys: string[]
|
...privateKeys: string[]
|
||||||
): TransactionCommonSigned<O>;
|
): TransactionCommonSigned<O>;
|
||||||
|
|
||||||
|
static delegateSignTransaction<
|
||||||
static delegateSignTransaction<O = TransactionOperations.CREATE>(
|
O extends TransactionOperations = TransactionOperations.CREATE
|
||||||
|
>(
|
||||||
transaction: TransactionCommon<O>,
|
transaction: TransactionCommon<O>,
|
||||||
signFn: DelegateSignFunction
|
signFn: DelegateSignFunction
|
||||||
): TransactionCommonSigned<O>;
|
): TransactionCommonSigned<O>;
|
||||||
|
|
||||||
static delegateSignTransactionAsync<O = TransactionOperations.CREATE>(
|
static delegateSignTransactionAsync<
|
||||||
|
O extends TransactionOperations = TransactionOperations.CREATE
|
||||||
|
>(
|
||||||
transaction: TransactionCommon<O>,
|
transaction: TransactionCommon<O>,
|
||||||
signFn: DelegateSignFunctionAsync
|
signFn: DelegateSignFunctionAsync
|
||||||
): Promise<TransactionCommonSigned<O>>;
|
): Promise<TransactionCommonSigned<O>>;
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const { paths } = require('./webpack.parts.js')
|
const { ProvidePlugin } = require('webpack')
|
||||||
|
const { paths } = require('./webpack.parts')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: paths.entry,
|
entry: paths.entry,
|
||||||
@ -24,10 +25,18 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
optimization: {
|
optimization: {
|
||||||
minimize: true,
|
minimize: true,
|
||||||
noEmitOnErrors: true
|
emitOnErrors: false
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js'],
|
extensions: ['.js'],
|
||||||
modules: ['node_modules'],
|
modules: ['node_modules'],
|
||||||
|
fallback: {
|
||||||
|
buffer: require.resolve('buffer/'),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new ProvidePlugin({
|
||||||
|
Buffer: ['buffer', 'Buffer']
|
||||||
|
})
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
const PRODUCTION = process.env.NODE_ENV === 'production'
|
const PRODUCTION = process.env.NODE_ENV === 'production'
|
||||||
|
|
||||||
const common = require('./webpack.common.js')
|
const common = require('./webpack.common')
|
||||||
|
|
||||||
const { outputs } = require('./webpack.parts.js')
|
const { outputs } = require('./webpack.parts')
|
||||||
|
|
||||||
// '[libraryTarget]': [file extension]
|
// '[libraryTarget]': [file extension]
|
||||||
const OUTPUT_MAPPING = {
|
const OUTPUT_MAPPING = {
|
||||||
|
@ -14,11 +14,9 @@ module.exports = {
|
|||||||
minimizer: [
|
minimizer: [
|
||||||
new TerserPlugin({
|
new TerserPlugin({
|
||||||
test: /vendor/,
|
test: /vendor/,
|
||||||
sourceMap: false
|
|
||||||
}),
|
}),
|
||||||
new TerserPlugin({
|
new TerserPlugin({
|
||||||
test: /^((?!(vendor)).)*.js$/,
|
test: /^((?!(vendor)).)*.js$/,
|
||||||
sourceMap: false
|
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
splitChunks: {
|
splitChunks: {
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const { merge } = require('webpack-merge')
|
const { merge } = require('webpack-merge')
|
||||||
|
|
||||||
const development = require('./webpack.development.js')
|
const development = require('./webpack.development')
|
||||||
const production = require('./webpack.production.js')
|
const production = require('./webpack.production')
|
||||||
|
|
||||||
const AddVendorsPlugin = require('./plugins/add-vendors-plugin')
|
const AddVendorsPlugin = require('./plugins/add-vendors-plugin')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user