@polkadot-api/substrate-client
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -147,5 +147,2 @@ import { JsonRpcProvider } from '@polkadot-api/json-rpc-provider'; | ||
event: "initialized"; | ||
finalizedBlockHash: string; | ||
} | { | ||
event: "initialized"; | ||
finalizedBlockHashes: string[]; | ||
@@ -152,0 +149,0 @@ }; |
@@ -1,49 +0,15 @@ | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
'use strict'; | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
AbortError: () => import_utils3.AbortError, | ||
DestroyedError: () => DestroyedError, | ||
DisjointError: () => DisjointError, | ||
OperationError: () => OperationError, | ||
OperationInaccessibleError: () => OperationInaccessibleError, | ||
OperationLimitError: () => OperationLimitError, | ||
RpcError: () => RpcError, | ||
StopError: () => StopError, | ||
createClient: () => createClient2 | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var utils = require('@polkadot-api/utils'); | ||
// src/internal-utils/abortablePromiseFn.ts | ||
var import_utils = require("@polkadot-api/utils"); | ||
var abortablePromiseFn = (fn) => (...args) => new Promise((res, rej) => { | ||
let cancel = import_utils.noop; | ||
const abortablePromiseFn = (fn) => (...args) => new Promise((res, rej) => { | ||
let cancel = utils.noop; | ||
const [actualArgs, abortSignal] = args[args.length - 1] instanceof AbortSignal ? [args.slice(0, args.length - 1), args[args.length - 1]] : [args]; | ||
const onAbort = () => { | ||
cancel(); | ||
rej(new import_utils.AbortError()); | ||
rej(new utils.AbortError()); | ||
}; | ||
abortSignal?.addEventListener("abort", onAbort, { once: true }); | ||
const withCleanup = (fn2) => (x) => { | ||
cancel = import_utils.noop; | ||
cancel = utils.noop; | ||
abortSignal?.removeEventListener("abort", onAbort); | ||
@@ -55,3 +21,2 @@ fn2(x); | ||
// src/internal-utils/deferred-promise.ts | ||
function deferred() { | ||
@@ -69,8 +34,6 @@ let res = () => { | ||
// src/internal-utils/noop.ts | ||
var noop2 = () => { | ||
const noop = () => { | ||
}; | ||
// src/internal-utils/subscriptions-manager.ts | ||
var getSubscriptionsManager = () => { | ||
const getSubscriptionsManager = () => { | ||
const subscriptions = /* @__PURE__ */ new Map(); | ||
@@ -105,4 +68,3 @@ return { | ||
// src/methods.ts | ||
var chainHead = { | ||
const chainHead = { | ||
body: "", | ||
@@ -119,3 +81,3 @@ call: "", | ||
}; | ||
var chainSpec = { | ||
const chainSpec = { | ||
chainName: "", | ||
@@ -125,14 +87,9 @@ genesisHash: "", | ||
}; | ||
var transaction = { | ||
const transaction = { | ||
broadcast: "", | ||
stop: "" | ||
}; | ||
var transactionWatch = { | ||
submitAndWatch: "", | ||
unwatch: "" | ||
}; | ||
Object.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach( | ||
Object.entries({ chainHead, chainSpec, transaction }).forEach( | ||
([fnGroupName, methods]) => { | ||
Object.keys(methods).forEach((methodName) => { | ||
; | ||
methods[methodName] = `${fnGroupName}_v1_${methodName}`; | ||
@@ -143,7 +100,6 @@ }); | ||
// src/transaction/transaction.ts | ||
var getTransaction = (request) => (tx, error) => { | ||
const getTransaction = (request) => (tx, error) => { | ||
let cancel = request(transaction.broadcast, [tx], { | ||
onSuccess: (subscriptionId) => { | ||
cancel = subscriptionId === null ? noop2 : () => { | ||
cancel = subscriptionId === null ? noop : () => { | ||
request(transaction.stop, [subscriptionId]); | ||
@@ -162,4 +118,3 @@ }; | ||
// src/chainhead/errors.ts | ||
var StopError = class extends Error { | ||
class StopError extends Error { | ||
constructor() { | ||
@@ -169,4 +124,4 @@ super("ChainHead stopped"); | ||
} | ||
}; | ||
var DisjointError = class extends Error { | ||
} | ||
class DisjointError extends Error { | ||
constructor() { | ||
@@ -176,4 +131,4 @@ super("ChainHead disjointed"); | ||
} | ||
}; | ||
var OperationLimitError = class extends Error { | ||
} | ||
class OperationLimitError extends Error { | ||
constructor() { | ||
@@ -183,4 +138,4 @@ super("ChainHead operations limit reached"); | ||
} | ||
}; | ||
var OperationError = class extends Error { | ||
} | ||
class OperationError extends Error { | ||
constructor(error) { | ||
@@ -190,4 +145,4 @@ super(error); | ||
} | ||
}; | ||
var OperationInaccessibleError = class extends Error { | ||
} | ||
class OperationInaccessibleError extends Error { | ||
constructor() { | ||
@@ -197,6 +152,5 @@ super("ChainHead operation inaccessible"); | ||
} | ||
}; | ||
} | ||
// src/chainhead/operation-promise.ts | ||
var createOperationPromise = (operationName, factory) => (request) => abortablePromiseFn((res, rej, ...args) => { | ||
const createOperationPromise = (operationName, factory) => (request) => abortablePromiseFn((res, rej, ...args) => { | ||
let isRunning = true; | ||
@@ -216,3 +170,3 @@ let cancel = () => { | ||
if (!isRunning) return stopOperation(); | ||
let done = noop2; | ||
let done = noop; | ||
const _res = (x) => { | ||
@@ -253,4 +207,3 @@ isRunning = false; | ||
// src/chainhead/body.ts | ||
var createBodyFn = createOperationPromise( | ||
const createBodyFn = createOperationPromise( | ||
chainHead.body, | ||
@@ -265,4 +218,3 @@ (hash) => [ | ||
// src/chainhead/call.ts | ||
var createCallFn = createOperationPromise( | ||
const createCallFn = createOperationPromise( | ||
chainHead.call, | ||
@@ -277,4 +229,3 @@ (hash, fnName, callParameters) => [ | ||
// src/chainhead/header.ts | ||
var createHeaderFn = (request) => (hash) => new Promise((res, rej) => { | ||
const createHeaderFn = (request) => (hash) => new Promise((res, rej) => { | ||
request(chainHead.header, [hash], { | ||
@@ -286,8 +237,6 @@ onSuccess: res, | ||
// src/chainhead/storage-subscription.ts | ||
var import_utils2 = require("@polkadot-api/utils"); | ||
var createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => { | ||
const createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => { | ||
if (inputs.length === 0) { | ||
onDone(); | ||
return import_utils2.noop; | ||
return utils.noop; | ||
} | ||
@@ -337,3 +286,3 @@ let isRunning = true; | ||
const _onError = (e) => { | ||
cancel = import_utils2.noop; | ||
cancel = utils.noop; | ||
doneListening(); | ||
@@ -343,3 +292,3 @@ onError(e); | ||
const _onDone = () => { | ||
cancel = import_utils2.noop; | ||
cancel = utils.noop; | ||
doneListening(); | ||
@@ -357,4 +306,3 @@ onDone(); | ||
// src/chainhead/storage.ts | ||
var createStorageFn = (request) => { | ||
const createStorageFn = (request) => { | ||
const cbStore = createStorageCb(request); | ||
@@ -393,4 +341,3 @@ return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => { | ||
// src/chainhead/unpin.ts | ||
var createUnpinFn = (request) => (hashes) => hashes.length > 0 ? new Promise((res, rej) => { | ||
const createUnpinFn = (request) => (hashes) => hashes.length > 0 ? new Promise((res, rej) => { | ||
request(chainHead.unpin, [hashes], { | ||
@@ -404,4 +351,3 @@ onSuccess() { | ||
// src/client/DestroyedError.ts | ||
var DestroyedError = class extends Error { | ||
class DestroyedError extends Error { | ||
constructor() { | ||
@@ -411,5 +357,4 @@ super("Client destroyed"); | ||
} | ||
}; | ||
} | ||
// src/chainhead/chainhead.ts | ||
function isOperationEvent(event) { | ||
@@ -434,3 +379,3 @@ return event.operationId !== void 0; | ||
type: event.event, | ||
finalizedBlockHashes: "finalizedBlockHash" in event ? [event.finalizedBlockHash] : event.finalizedBlockHashes, | ||
finalizedBlockHashes: event.finalizedBlockHashes, | ||
finalizedBlockRuntime: event.finalizedBlockRuntime | ||
@@ -456,3 +401,3 @@ }); | ||
followSubscription = null; | ||
unfollow = noop2; | ||
unfollow = noop; | ||
done(); | ||
@@ -489,3 +434,3 @@ sendUnfollow && request(chainHead.unfollow, [subscriptionId]); | ||
disjoint(); | ||
return noop2; | ||
return noop; | ||
} | ||
@@ -498,3 +443,3 @@ const onSubscription = (subscription) => { | ||
subscriber.error(new DisjointError()); | ||
return noop2; | ||
return noop; | ||
} | ||
@@ -523,3 +468,3 @@ subscriptions.subscribe(operationId, subscriber); | ||
return onSubscription(followSubscription); | ||
let onCancel = noop2; | ||
let onCancel = noop; | ||
followSubscription.then((x) => { | ||
@@ -549,4 +494,6 @@ if (x instanceof Error) return disjoint(); | ||
// src/client/RpcError.ts | ||
var RpcError = class extends Error { | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
class RpcError extends Error { | ||
constructor(e) { | ||
@@ -560,7 +507,6 @@ super(e.message); | ||
} | ||
}; | ||
} | ||
// src/client/createClient.ts | ||
var nextClientId = 1; | ||
var createClient = (gProvider) => { | ||
let nextClientId = 1; | ||
const createClient$1 = (gProvider) => { | ||
let clientId = nextClientId++; | ||
@@ -635,4 +581,3 @@ const responses = /* @__PURE__ */ new Map(); | ||
// src/chainspec.ts | ||
var createGetChainSpec = (clientRequest) => { | ||
const createGetChainSpec = (clientRequest) => { | ||
const request = abortablePromiseFn( | ||
@@ -656,84 +601,28 @@ (onSuccess, onError, method, params) => clientRequest(method, params, { onSuccess, onError }) | ||
// src/request-compatibility-enhancer.ts | ||
var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => { | ||
let translations = {}; | ||
let enhancedRequest = null; | ||
return (method, ...rest) => { | ||
if (enhancedRequest) return enhancedRequest(method, ...rest); | ||
let isRunning = true; | ||
let cleanup = () => { | ||
isRunning = false; | ||
}; | ||
rpcMethodsP.then((rpcMethods) => { | ||
enhancedRequest = (method_, ...iRest) => { | ||
const method2 = translations[method_] ?? method_; | ||
if (rpcMethods.has(method2)) return request(method2, ...iRest); | ||
iRest[1]?.onError(new Error(`Unsupported method ${method2}`)); | ||
return noop2; | ||
}; | ||
if (rpcMethods.has(method)) return; | ||
const parts = method.split("_"); | ||
if (parts[1] !== "v1") return; | ||
parts[1] = "unstable"; | ||
if (rpcMethods.has(parts.join("_"))) | ||
Object.values(methods).forEach((value) => { | ||
translations[value] = value.replace("_v1_", "_unstable_"); | ||
}); | ||
else if (parts[0] === "transaction") { | ||
let unwatch; | ||
let version; | ||
const txGroup = ["transactionWatch", "transaction"].find( | ||
(group) => { | ||
version = ["v1", "unstable"].find( | ||
(v) => rpcMethods.has(unwatch = `${group}_${v}_unwatch`) | ||
); | ||
return !!version; | ||
} | ||
); | ||
if (txGroup) { | ||
translations[methods.broadcast] = `${txGroup}_${version}_submitAndWatch`; | ||
translations[methods.stop] = unwatch; | ||
} | ||
} | ||
}).then(() => { | ||
if (isRunning) cleanup = enhancedRequest(method, ...rest); | ||
}); | ||
return () => { | ||
cleanup(); | ||
}; | ||
}; | ||
}; | ||
// src/index.ts | ||
var import_utils3 = require("@polkadot-api/utils"); | ||
var createClient2 = (provider) => { | ||
const client = createClient(provider); | ||
const request = abortablePromiseFn( | ||
(onSuccess, onError, method, params) => client.request(method, params, { onSuccess, onError }) | ||
); | ||
const rpcMethods = request("rpc_methods", []).then( | ||
(x) => new Set(Array.isArray(x) ? x : x.methods), | ||
() => /* @__PURE__ */ new Set() | ||
); | ||
const compatibilityEnhancer = getCompatibilityEnhancer( | ||
rpcMethods, | ||
client.request | ||
); | ||
const createClient = (provider) => { | ||
const { request, disconnect } = createClient$1(provider); | ||
return { | ||
chainHead: getChainHead( | ||
compatibilityEnhancer(chainHead) | ||
chainHead: getChainHead(request), | ||
transaction: getTransaction(request), | ||
getChainSpecData: createGetChainSpec(request), | ||
destroy: disconnect, | ||
request: abortablePromiseFn( | ||
(onSuccess, onError, method, params) => request(method, params, { onSuccess, onError }) | ||
), | ||
transaction: getTransaction( | ||
compatibilityEnhancer(transaction) | ||
), | ||
getChainSpecData: createGetChainSpec( | ||
compatibilityEnhancer(chainSpec) | ||
), | ||
destroy: () => { | ||
client.disconnect(); | ||
}, | ||
request, | ||
_request: client.request | ||
_request: request | ||
}; | ||
}; | ||
//# sourceMappingURL=index.js.map | ||
Object.defineProperty(exports, "AbortError", { | ||
enumerable: true, | ||
get: function () { return utils.AbortError; } | ||
}); | ||
exports.DestroyedError = DestroyedError; | ||
exports.DisjointError = DisjointError; | ||
exports.OperationError = OperationError; | ||
exports.OperationInaccessibleError = OperationInaccessibleError; | ||
exports.OperationLimitError = OperationLimitError; | ||
exports.RpcError = RpcError; | ||
exports.StopError = StopError; | ||
exports.createClient = createClient; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@polkadot-api/substrate-client", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"author": "Josep M Sobrepere (https://github.com/josepot)", | ||
@@ -15,12 +15,12 @@ "repository": { | ||
"production": { | ||
"import": "./dist/index.mjs", | ||
"import": "./dist/esm/index.mjs", | ||
"require": "./dist/min/index.js", | ||
"default": "./dist/index.js" | ||
}, | ||
"import": "./dist/index.mjs", | ||
"import": "./dist/esm/index.mjs", | ||
"require": "./dist/index.js", | ||
"default": "./dist/index.js" | ||
}, | ||
"module": "./dist/index.mjs", | ||
"import": "./dist/index.mjs", | ||
"module": "./dist/esm/index.mjs", | ||
"import": "./dist/esm/index.mjs", | ||
"require": "./dist/index.js", | ||
@@ -32,4 +32,4 @@ "default": "./dist/index.js" | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"browser": "./dist/index.mjs", | ||
"module": "./dist/esm/index.mjs", | ||
"browser": "./dist/esm/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
@@ -40,7 +40,7 @@ "files": [ | ||
"dependencies": { | ||
"@polkadot-api/utils": "0.1.0", | ||
"@polkadot-api/json-rpc-provider": "0.0.1" | ||
"@polkadot-api/utils": "0.1.1", | ||
"@polkadot-api/json-rpc-provider": "0.0.2" | ||
}, | ||
"scripts": { | ||
"build": "tsc --noEmit && tsup-node src/index.ts --clean --sourcemap --platform neutral --target=es2020 --format esm,cjs --dts && tsup-node src/index.ts --clean --sourcemap --platform neutral --target=es2020 --format cjs --dts --minify --out-dir dist/min", | ||
"build": "tsc --noEmit && rollup -c ../../rollup.config.js", | ||
"test": "vitest", | ||
@@ -47,0 +47,0 @@ "coverage": "vitest run --coverage", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
46
2
147784
1447
1
+ Added@polkadot-api/json-rpc-provider@0.0.2(transitive)
+ Added@polkadot-api/utils@0.1.1(transitive)
- Removed@polkadot-api/json-rpc-provider@0.0.1(transitive)
- Removed@polkadot-api/utils@0.1.0(transitive)
Updated@polkadot-api/utils@0.1.1