Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@polkadot-api/substrate-client

Package Overview
Dependencies
Maintainers
2
Versions
596
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polkadot-api/substrate-client - npm Package Compare versions

Comparing version 0.0.1-f898f0a3a6cfaf419c932dd350d98303a7375b8c.1.0 to 0.0.1-fac5bf6a6664d72aa08bb6eac0a99a39bbffce72.1.0

180

./dist/index.js

@@ -271,92 +271,97 @@ "use strict";

// src/chainhead/storage-subscription.ts
var import_utils = require("@polkadot-api/utils");
var createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, onDone, onDiscartedItems) => {
if (inputs.length === 0) {
onDone();
return import_utils.noop;
}
let cancel = request(
"chainHead_unstable_storage",
[hash, inputs, childTrie],
{
onSuccess: (response, followSubscription) => {
if (response.result === "limitReached" || response.discardedItems === inputs.length)
return onError(new OperationLimitError());
const doneListening = followSubscription(response.operationId, {
next: (event) => {
switch (event.type) {
case "operationStorageItems": {
onItems(event.items);
break;
}
case "operationStorageDone": {
_onDone();
break;
}
case "operationError": {
_onError(new OperationError(event.error));
break;
}
case "operationInaccessible": {
_onError(new OperationInaccessibleError());
break;
}
default:
request("chainHead_unstable_continue", []);
}
},
error: onError
});
cancel = () => {
doneListening();
request("chainHead_unstable_stopOperation", [response.operationId]);
};
const _onError = (e) => {
cancel = import_utils.noop;
doneListening();
onError(e);
};
const _onDone = () => {
cancel = import_utils.noop;
doneListening();
onDone();
};
onDiscartedItems(response.discardedItems);
},
onError
}
);
return () => {
cancel();
};
};
// src/chainhead/storage.ts
var createStorageFn = createOperationPromise(
"chainHead_unstable_storage",
(hash, query, childTrie) => {
const queries = {
value: new Set(query.value ?? []),
hash: new Set(query.hash ?? []),
closestDescendantMerkleValue: new Set(
query.closestDescendantMerkleValue ?? []
),
descendantsValues: new Set(query.descendantsValues ?? []),
descendantsHashes: new Set(query.descendantsHashes ?? [])
};
const items = [];
query.value?.forEach((key) => {
items.push({
type: "value",
key
});
});
query.hash?.forEach((key) => {
items.push({
type: "hash",
key
});
});
query.descendantsValues?.forEach((key) => {
items.push({
type: "descendantsValues",
key
});
});
query.descendantsHashes?.forEach((key) => {
items.push({
type: "descendantsHashes",
key
});
});
queries["closestDescendantMerkleValue"]?.forEach((key) => {
items.push({
type: "closestDescendantMerkleValue",
key
});
});
const requestArgs = [hash, items, childTrie];
const result = {
values: {},
hashes: {},
closests: {},
descendantsHashes: {},
descendantsValues: {}
};
const resultBuilder = (e, res) => {
if (e.type === "operationStorageDone")
return res(result);
e.items.forEach((item) => {
if (item.value) {
if (queries.value.has(item.key)) {
result.values[item.key] = item.value;
} else {
const queriedKey = [...queries["descendantsValues"]].filter((key) => item.key.startsWith(key)).sort((a, b) => b.length - a.length)[0];
const values = result.descendantsValues[queriedKey] ?? [];
values.push({
key: item.key,
value: item.value
});
result.descendantsValues[queriedKey] = values;
var createStorageFn = (request) => {
const cbStore = createStorageCb(request);
return abortablePromiseFn(
(resolve, reject, hash, type, key, childTrie) => {
const isDescendants = type.startsWith("descendants");
let result = isDescendants ? [] : null;
const onItems = isDescendants ? (items) => {
result.push(...items);
} : (items) => {
result = items[0]?.[type];
};
const cancel = cbStore(
hash,
[{ key, type }],
childTrie ?? null,
onItems,
reject,
() => {
resolve(result);
},
(nDiscarded) => {
if (nDiscarded > 0) {
cancel();
reject(new OperationLimitError());
}
}
if (item.hash) {
if (queries.hash.has(item.key)) {
result.hashes[item.key] = item.hash;
} else {
const queriedKey = [...queries["descendantsHashes"]].filter((key) => item.key.startsWith(key)).sort((a, b) => b.length - a.length)[0];
const hashes = result.descendantsHashes[queriedKey] ?? [];
hashes.push({
key: item.key,
hash: item.hash
});
result.descendantsHashes[queriedKey] = hashes;
}
}
if (item["closestDescendantMerkleValue"] && queries["closestDescendantMerkleValue"].has(item.key)) {
result.closests[item.key] = item["closestDescendantMerkleValue"];
}
});
};
return [requestArgs, resultBuilder];
}
);
);
return cancel;
}
);
};

@@ -483,2 +488,3 @@ // src/chainhead/unpin.ts

storage: createStorageFn(fRequest),
storageSubscription: createStorageCb(fRequest),
unpin: createUnpinFn(fRequest),

@@ -485,0 +491,0 @@ _request: fRequest

@@ -39,2 +39,46 @@ import { GetProvider } from '@polkadot-api/json-rpc-provider';

interface Stop {
type: "stop";
}
interface OperationEvent {
operationId: string;
}
type OperationWaitingForContinue = OperationEvent & {
type: "operationWaitingForContinue";
};
type OperationInaccessible = OperationEvent & {
type: "operationInaccessible";
};
type OperationError$1 = OperationEvent & {
type: "operationError";
error: string;
};
type CommonOperationEvents = OperationInaccessible | OperationError$1;
type OperationBodyDone = OperationEvent & {
type: "operationBodyDone";
value: Array<string>;
};
type OperationCallDone = OperationEvent & {
type: "operationCallDone";
output: string;
};
interface StorageItemResponse {
key: string;
value?: string;
hash?: string;
closestDescendantMerkleValue?: string;
}
type OperationStorageItems = OperationEvent & {
type: "operationStorageItems";
items: Array<StorageItemResponse>;
};
type OperationStorageDone = OperationEvent & {
type: "operationStorageDone";
};
type OperationEvents = OperationBodyDone | OperationCallDone | OperationStorageItems | OperationWaitingForContinue | OperationStorageDone | CommonOperationEvents;
interface StorageItemInput {
key: string;
type: "value" | "hash" | "closestDescendantMerkleValue" | "descendantsValues" | "descendantsHashes";
}
interface Runtime {

@@ -75,15 +119,9 @@ specName: string;

type FollowEventWithoutRuntime = Initialized | NewBlock | CommonFollowEvents;
interface StorageResponse {
values: Record<string, string>;
hashes: Record<string, string>;
closests: Record<string, string>;
descendantsValues: Record<string, Array<{
key: string;
value: string;
}>>;
descendantsHashes: Record<string, Array<{
key: string;
hash: string;
}>>;
}
type StorageResult<Input extends StorageItemInput["type"]> = Input extends "descendantsHashes" ? Array<{
key: string;
hash: string;
}> : Input extends "descendantsValues" ? Array<{
key: string;
value: string;
}> : string | null;
interface FollowResponse {

@@ -97,13 +135,4 @@ unfollow: UnsubscribeFn;

], string>;
storage: AbortablePromiseFn<[
hash: string,
query: Partial<{
value: Array<string>;
hash: Array<string>;
descendantsValues: Array<string>;
descendantsHashes: Array<string>;
closestDescendantMerkleValue: Array<string>;
}>,
childTrie: string | null
], StorageResponse>;
storage: <Type extends StorageItemInput["type"]>(hash: string, type: Type, key: string, childTrie: string | null, abortSignal?: AbortSignal | undefined) => Promise<StorageResult<Type>>;
storageSubscription: (hash: string, inputs: Array<StorageItemInput>, childTrie: string | null, onItems: (items: Array<StorageItemResponse>) => void, onError: (e: Error) => void, onDone: () => void, onDiscartedItems: (nDiscarted: number) => void) => () => void;
header: (hash: string) => Promise<string>;

@@ -127,3 +156,3 @@ unpin: (hashes: Array<string>) => Promise<void>;

}
declare class OperationError$1 extends Error {
declare class OperationError extends Error {
constructor(error: string);

@@ -135,42 +164,2 @@ }

interface Stop {
type: "stop";
}
interface OperationEvent {
operationId: string;
}
type OperationWaitingForContinue = OperationEvent & {
type: "operationWaitingForContinue";
};
type OperationInaccessible = OperationEvent & {
type: "operationInaccessible";
};
type OperationError = OperationEvent & {
type: "operationError";
error: string;
};
type CommonOperationEvents = OperationInaccessible | OperationError;
type OperationBodyDone = OperationEvent & {
type: "operationBodyDone";
value: Array<string>;
};
type OperationCallDone = OperationEvent & {
type: "operationCallDone";
output: string;
};
interface StorageItemResponse {
key: string;
value?: string;
hash?: string;
closestDescendantMerkleValue?: string;
}
type OperationStorageItems = OperationEvent & {
type: "operationStorageItems";
items: Array<StorageItemResponse>;
};
type OperationStorageDone = OperationEvent & {
type: "operationStorageDone";
};
type OperationEvents = OperationBodyDone | OperationCallDone | OperationStorageItems | OperationWaitingForContinue | OperationStorageDone | CommonOperationEvents;
type FollowEvent = FollowEventWithRuntime | FollowEventWithoutRuntime | OperationEvents | Stop;

@@ -235,2 +224,2 @@ declare function getChainHead(request: ClientRequest<string, FollowEvent>): ChainHead;

export { AbortablePromiseFn, BestBlockChanged, ChainHead, Client, ClientRequest, ClientRequestCb, DisjointError, Finalized, FollowEventWithRuntime, FollowEventWithoutRuntime, FollowResponse, FollowSubscriptionCb, IRpcError, Initialized, InitializedWithRuntime, NewBlock, NewBlockWithRuntime, OperationError$1 as OperationError, OperationInaccessibleError, OperationLimitError, RpcError, Runtime, StopError, StorageResponse, SubstrateClient, Transaction, TransactionError, TxBestChainBlockIncluded, TxBroadcasted, TxDropped, TxError, TxEvent, TxFinalized, TxInvalid, TxValidated, UnsubscribeFn, createClient, getChainHead, getTransaction };
export { AbortablePromiseFn, BestBlockChanged, ChainHead, Client, ClientRequest, ClientRequestCb, DisjointError, Finalized, FollowEventWithRuntime, FollowEventWithoutRuntime, FollowResponse, FollowSubscriptionCb, IRpcError, Initialized, InitializedWithRuntime, NewBlock, NewBlockWithRuntime, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, Runtime, StopError, StorageItemInput, StorageItemResponse, StorageResult, SubstrateClient, Transaction, TransactionError, TxBestChainBlockIncluded, TxBroadcasted, TxDropped, TxError, TxEvent, TxFinalized, TxInvalid, TxValidated, UnsubscribeFn, createClient, getChainHead, getTransaction };

@@ -271,92 +271,97 @@ "use strict";

// src/chainhead/storage-subscription.ts
var import_utils = require("@polkadot-api/utils");
var createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, onDone, onDiscartedItems) => {
if (inputs.length === 0) {
onDone();
return import_utils.noop;
}
let cancel = request(
"chainHead_unstable_storage",
[hash, inputs, childTrie],
{
onSuccess: (response, followSubscription) => {
if (response.result === "limitReached" || response.discardedItems === inputs.length)
return onError(new OperationLimitError());
const doneListening = followSubscription(response.operationId, {
next: (event) => {
switch (event.type) {
case "operationStorageItems": {
onItems(event.items);
break;
}
case "operationStorageDone": {
_onDone();
break;
}
case "operationError": {
_onError(new OperationError(event.error));
break;
}
case "operationInaccessible": {
_onError(new OperationInaccessibleError());
break;
}
default:
request("chainHead_unstable_continue", []);
}
},
error: onError
});
cancel = () => {
doneListening();
request("chainHead_unstable_stopOperation", [response.operationId]);
};
const _onError = (e) => {
cancel = import_utils.noop;
doneListening();
onError(e);
};
const _onDone = () => {
cancel = import_utils.noop;
doneListening();
onDone();
};
onDiscartedItems(response.discardedItems);
},
onError
}
);
return () => {
cancel();
};
};
// src/chainhead/storage.ts
var createStorageFn = createOperationPromise(
"chainHead_unstable_storage",
(hash, query, childTrie) => {
const queries = {
value: new Set(query.value ?? []),
hash: new Set(query.hash ?? []),
closestDescendantMerkleValue: new Set(
query.closestDescendantMerkleValue ?? []
),
descendantsValues: new Set(query.descendantsValues ?? []),
descendantsHashes: new Set(query.descendantsHashes ?? [])
};
const items = [];
query.value?.forEach((key) => {
items.push({
type: "value",
key
});
});
query.hash?.forEach((key) => {
items.push({
type: "hash",
key
});
});
query.descendantsValues?.forEach((key) => {
items.push({
type: "descendantsValues",
key
});
});
query.descendantsHashes?.forEach((key) => {
items.push({
type: "descendantsHashes",
key
});
});
queries["closestDescendantMerkleValue"]?.forEach((key) => {
items.push({
type: "closestDescendantMerkleValue",
key
});
});
const requestArgs = [hash, items, childTrie];
const result = {
values: {},
hashes: {},
closests: {},
descendantsHashes: {},
descendantsValues: {}
};
const resultBuilder = (e, res) => {
if (e.type === "operationStorageDone")
return res(result);
e.items.forEach((item) => {
if (item.value) {
if (queries.value.has(item.key)) {
result.values[item.key] = item.value;
} else {
const queriedKey = [...queries["descendantsValues"]].filter((key) => item.key.startsWith(key)).sort((a, b) => b.length - a.length)[0];
const values = result.descendantsValues[queriedKey] ?? [];
values.push({
key: item.key,
value: item.value
});
result.descendantsValues[queriedKey] = values;
var createStorageFn = (request) => {
const cbStore = createStorageCb(request);
return abortablePromiseFn(
(resolve, reject, hash, type, key, childTrie) => {
const isDescendants = type.startsWith("descendants");
let result = isDescendants ? [] : null;
const onItems = isDescendants ? (items) => {
result.push(...items);
} : (items) => {
result = items[0]?.[type];
};
const cancel = cbStore(
hash,
[{ key, type }],
childTrie ?? null,
onItems,
reject,
() => {
resolve(result);
},
(nDiscarded) => {
if (nDiscarded > 0) {
cancel();
reject(new OperationLimitError());
}
}
if (item.hash) {
if (queries.hash.has(item.key)) {
result.hashes[item.key] = item.hash;
} else {
const queriedKey = [...queries["descendantsHashes"]].filter((key) => item.key.startsWith(key)).sort((a, b) => b.length - a.length)[0];
const hashes = result.descendantsHashes[queriedKey] ?? [];
hashes.push({
key: item.key,
hash: item.hash
});
result.descendantsHashes[queriedKey] = hashes;
}
}
if (item["closestDescendantMerkleValue"] && queries["closestDescendantMerkleValue"].has(item.key)) {
result.closests[item.key] = item["closestDescendantMerkleValue"];
}
});
};
return [requestArgs, resultBuilder];
}
);
);
return cancel;
}
);
};

@@ -483,2 +488,3 @@ // src/chainhead/unpin.ts

storage: createStorageFn(fRequest),
storageSubscription: createStorageCb(fRequest),
unpin: createUnpinFn(fRequest),

@@ -485,0 +491,0 @@ _request: fRequest

@@ -39,2 +39,46 @@ import { GetProvider } from '@polkadot-api/json-rpc-provider';

interface Stop {
type: "stop";
}
interface OperationEvent {
operationId: string;
}
type OperationWaitingForContinue = OperationEvent & {
type: "operationWaitingForContinue";
};
type OperationInaccessible = OperationEvent & {
type: "operationInaccessible";
};
type OperationError$1 = OperationEvent & {
type: "operationError";
error: string;
};
type CommonOperationEvents = OperationInaccessible | OperationError$1;
type OperationBodyDone = OperationEvent & {
type: "operationBodyDone";
value: Array<string>;
};
type OperationCallDone = OperationEvent & {
type: "operationCallDone";
output: string;
};
interface StorageItemResponse {
key: string;
value?: string;
hash?: string;
closestDescendantMerkleValue?: string;
}
type OperationStorageItems = OperationEvent & {
type: "operationStorageItems";
items: Array<StorageItemResponse>;
};
type OperationStorageDone = OperationEvent & {
type: "operationStorageDone";
};
type OperationEvents = OperationBodyDone | OperationCallDone | OperationStorageItems | OperationWaitingForContinue | OperationStorageDone | CommonOperationEvents;
interface StorageItemInput {
key: string;
type: "value" | "hash" | "closestDescendantMerkleValue" | "descendantsValues" | "descendantsHashes";
}
interface Runtime {

@@ -75,15 +119,9 @@ specName: string;

type FollowEventWithoutRuntime = Initialized | NewBlock | CommonFollowEvents;
interface StorageResponse {
values: Record<string, string>;
hashes: Record<string, string>;
closests: Record<string, string>;
descendantsValues: Record<string, Array<{
key: string;
value: string;
}>>;
descendantsHashes: Record<string, Array<{
key: string;
hash: string;
}>>;
}
type StorageResult<Input extends StorageItemInput["type"]> = Input extends "descendantsHashes" ? Array<{
key: string;
hash: string;
}> : Input extends "descendantsValues" ? Array<{
key: string;
value: string;
}> : string | null;
interface FollowResponse {

@@ -97,13 +135,4 @@ unfollow: UnsubscribeFn;

], string>;
storage: AbortablePromiseFn<[
hash: string,
query: Partial<{
value: Array<string>;
hash: Array<string>;
descendantsValues: Array<string>;
descendantsHashes: Array<string>;
closestDescendantMerkleValue: Array<string>;
}>,
childTrie: string | null
], StorageResponse>;
storage: <Type extends StorageItemInput["type"]>(hash: string, type: Type, key: string, childTrie: string | null, abortSignal?: AbortSignal | undefined) => Promise<StorageResult<Type>>;
storageSubscription: (hash: string, inputs: Array<StorageItemInput>, childTrie: string | null, onItems: (items: Array<StorageItemResponse>) => void, onError: (e: Error) => void, onDone: () => void, onDiscartedItems: (nDiscarted: number) => void) => () => void;
header: (hash: string) => Promise<string>;

@@ -127,3 +156,3 @@ unpin: (hashes: Array<string>) => Promise<void>;

}
declare class OperationError$1 extends Error {
declare class OperationError extends Error {
constructor(error: string);

@@ -135,42 +164,2 @@ }

interface Stop {
type: "stop";
}
interface OperationEvent {
operationId: string;
}
type OperationWaitingForContinue = OperationEvent & {
type: "operationWaitingForContinue";
};
type OperationInaccessible = OperationEvent & {
type: "operationInaccessible";
};
type OperationError = OperationEvent & {
type: "operationError";
error: string;
};
type CommonOperationEvents = OperationInaccessible | OperationError;
type OperationBodyDone = OperationEvent & {
type: "operationBodyDone";
value: Array<string>;
};
type OperationCallDone = OperationEvent & {
type: "operationCallDone";
output: string;
};
interface StorageItemResponse {
key: string;
value?: string;
hash?: string;
closestDescendantMerkleValue?: string;
}
type OperationStorageItems = OperationEvent & {
type: "operationStorageItems";
items: Array<StorageItemResponse>;
};
type OperationStorageDone = OperationEvent & {
type: "operationStorageDone";
};
type OperationEvents = OperationBodyDone | OperationCallDone | OperationStorageItems | OperationWaitingForContinue | OperationStorageDone | CommonOperationEvents;
type FollowEvent = FollowEventWithRuntime | FollowEventWithoutRuntime | OperationEvents | Stop;

@@ -235,2 +224,2 @@ declare function getChainHead(request: ClientRequest<string, FollowEvent>): ChainHead;

export { AbortablePromiseFn, BestBlockChanged, ChainHead, Client, ClientRequest, ClientRequestCb, DisjointError, Finalized, FollowEventWithRuntime, FollowEventWithoutRuntime, FollowResponse, FollowSubscriptionCb, IRpcError, Initialized, InitializedWithRuntime, NewBlock, NewBlockWithRuntime, OperationError$1 as OperationError, OperationInaccessibleError, OperationLimitError, RpcError, Runtime, StopError, StorageResponse, SubstrateClient, Transaction, TransactionError, TxBestChainBlockIncluded, TxBroadcasted, TxDropped, TxError, TxEvent, TxFinalized, TxInvalid, TxValidated, UnsubscribeFn, createClient, getChainHead, getTransaction };
export { AbortablePromiseFn, BestBlockChanged, ChainHead, Client, ClientRequest, ClientRequestCb, DisjointError, Finalized, FollowEventWithRuntime, FollowEventWithoutRuntime, FollowResponse, FollowSubscriptionCb, IRpcError, Initialized, InitializedWithRuntime, NewBlock, NewBlockWithRuntime, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, Runtime, StopError, StorageItemInput, StorageItemResponse, StorageResult, SubstrateClient, Transaction, TransactionError, TxBestChainBlockIncluded, TxBroadcasted, TxDropped, TxError, TxEvent, TxFinalized, TxInvalid, TxValidated, UnsubscribeFn, createClient, getChainHead, getTransaction };

@@ -1,2 +0,2 @@

"use strict";var I=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var X=(r,e,t)=>e in r?I(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var Y=(r,e)=>{for(var t in e)I(r,t,{get:e[t],enumerable:!0})},Z=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $(e))!Q.call(r,o)&&o!==t&&I(r,o,{get:()=>e[o],enumerable:!(n=K(e,o))||n.enumerable});return r};var ee=r=>Z(I({},"__esModule",{value:!0}),r);var C=(r,e,t)=>(X(r,typeof e!="symbol"?e+"":e,t),t);var se={};Y(se,{DisjointError:()=>x,OperationError:()=>A,OperationInaccessibleError:()=>P,OperationLimitError:()=>O,RpcError:()=>T,StopError:()=>F,TransactionError:()=>R,createClient:()=>oe});module.exports=ee(se);var D=class extends Error{constructor(){super("Aborted by AbortSignal"),this.name="AbortError"}},U=r=>(...e)=>new Promise((t,n)=>{let[o,m]=e[e.length-1]instanceof AbortSignal?[e.slice(0,e.length-1),e[e.length-1]]:[e],u=()=>{i(),n(new D)};m?.addEventListener("abort",u,{once:!0});let d=b=>c=>{m?.removeEventListener("abort",u),b(c)},i=r(d(t),d(n),...o)});function j(){let r=()=>{},e=()=>{};return{promise:new Promise((n,o)=>{r=n,e=o}),res:r,rej:e}}var v=()=>{};var _=()=>{let r=new Map;return{has:r.has.bind(r),subscribe(e,t){r.set(e,t)},unsubscribe(e){r.delete(e)},next(e,t){r.get(e)?.next(t)},error(e,t){let n=r.get(e);n&&(r.delete(e),n.error(t))},errorAll(e){let t=[...r.values()];r.clear(),t.forEach(n=>{n.error(e)})}}};var re=new Set(["dropped","invalid","finalized","error"]);function te(r){return re.has(r.type)}var R=class extends Error{constructor(t){super(`TxError: ${t.type} - ${t.error}`);C(this,"type");C(this,"error");this.type=t.type,this.error=t.error,this.name="TransactionError"}},M=r=>(e,t,n)=>{let o=r("transaction_unstable_submitAndWatch",[e],{onSuccess:(m,u)=>{let d=u(m,{next:i=>{if(te(i)&&(d(),o=v,i.type!=="finalized"))return n(new R(i));t(i)},error(i){o(),o=v,n(i)}});o=()=>{d(),r("transaction_unstable_unwatch",[m])}},onError:n});return()=>{o()}};var F=class extends Error{constructor(){super("ChainHead stopped"),this.name="StopError"}},x=class extends Error{constructor(){super("ChainHead disjointed"),this.name="DisjointError"}},O=class extends Error{constructor(){super("ChainHead operations limit reached"),this.name="OperationLimitError"}},A=class extends Error{constructor(e){super(e),this.name="OperationError"}},P=class extends Error{constructor(){super("ChainHead operation inaccessible"),this.name="OperationInaccessibleError"}};var q=(r,e)=>t=>U((n,o,...m)=>{let[u,d]=e(...m),i=t(r,u,{onSuccess:(b,c)=>{if(b.result==="limitReached")return i=v,o(new O);let h=!0,f=v,y=a=>{h=!1,f(),n(a)},s=a=>{h=!1,f(),o(a)};f=c(b.operationId,{next:a=>{let l=a;l.type==="operationError"?o(new A(l.error)):l.type==="operationInaccessible"?o(new P):d(a,y,s)},error:s}),i=()=>{h&&(f(),t("chainHead_unstable_stopOperation",[b.operationId]))}},onError:o});return()=>{i()}});var B=q("chainHead_unstable_body",r=>[[r],(e,t)=>{t(e.value)}]);var G=q("chainHead_unstable_call",(r,e,t)=>[[r,e,t],(n,o)=>{o(n.output)}]);var N=r=>e=>new Promise((t,n)=>{r("chainHead_unstable_header",[e],{onSuccess:t,onError:n})});var L=q("chainHead_unstable_storage",(r,e,t)=>{let n={value:new Set(e.value??[]),hash:new Set(e.hash??[]),closestDescendantMerkleValue:new Set(e.closestDescendantMerkleValue??[]),descendantsValues:new Set(e.descendantsValues??[]),descendantsHashes:new Set(e.descendantsHashes??[])},o=[];e.value?.forEach(i=>{o.push({type:"value",key:i})}),e.hash?.forEach(i=>{o.push({type:"hash",key:i})}),e.descendantsValues?.forEach(i=>{o.push({type:"descendantsValues",key:i})}),e.descendantsHashes?.forEach(i=>{o.push({type:"descendantsHashes",key:i})}),n.closestDescendantMerkleValue?.forEach(i=>{o.push({type:"closestDescendantMerkleValue",key:i})});let m=[r,o,t],u={values:{},hashes:{},closests:{},descendantsHashes:{},descendantsValues:{}};return[m,(i,b)=>{if(i.type==="operationStorageDone")return b(u);i.items.forEach(c=>{if(c.value)if(n.value.has(c.key))u.values[c.key]=c.value;else{let h=[...n.descendantsValues].filter(y=>c.key.startsWith(y)).sort((y,s)=>s.length-y.length)[0],f=u.descendantsValues[h]??[];f.push({key:c.key,value:c.value}),u.descendantsValues[h]=f}if(c.hash)if(n.hash.has(c.key))u.hashes[c.key]=c.hash;else{let h=[...n.descendantsHashes].filter(y=>c.key.startsWith(y)).sort((y,s)=>s.length-y.length)[0],f=u.descendantsHashes[h]??[];f.push({key:c.key,hash:c.hash}),u.descendantsHashes[h]=f}c.closestDescendantMerkleValue&&n.closestDescendantMerkleValue.has(c.key)&&(u.closests[c.key]=c.closestDescendantMerkleValue)})}]});var z=r=>e=>new Promise((t,n)=>{r("chainHead_unstable_unpin",[e],{onSuccess(){t()},onError:n})});function ne(r){return r.operationId!==void 0}function V(r){return(e,t,n)=>{let o=_(),m=new Set,u=j(),d=u.promise,i=s=>{if(ne(s))return o.next(s.operationId,s);if(s.type!=="stop")return t(s);n(new F),f(!1)},b=s=>{n(s),f()},f=r("chainHead_unstable_follow",[e],{onSuccess:(s,a)=>{let l=a(s,{next:i,error:b});f=(p=!0)=>{d=null,f=v,l(),p&&r("chainHead_unstable_unfollow",[s]),o.errorAll(new x),m.forEach(E=>{E()}),m.clear()},d=s,u.res(s)},onError:s=>{n(s),d=null,u.res(s)}}),y=(s,a,l)=>{let p=()=>{l?.onError(new x)};if(d===null)return p(),v;let E=g=>{if(!l)return r(s,[g,...a]);m.add(p);let H=(w,W)=>d===null?(W.error(new x),v):(o.subscribe(w,W),()=>{o.unsubscribe(w)}),k=r(s,[g,...a],{onSuccess:w=>{m.delete(p),l.onSuccess(w,H)},onError:w=>{m.delete(p),l.onError(w)}});return()=>{m.delete(p),k()}};if(typeof d=="string")return E(d);let S=v;return d.then(g=>{if(g instanceof Error)return p();d&&(S=E(g))}),()=>{S()}};return{unfollow(){f(),d=null},body:B(y),call:G(y),header:N(y),storage:L(y),unpin:z(y),_request:y}}}var T=class extends Error{constructor(t){super(t.message);C(this,"code");C(this,"data");this.code=t.code,this.data=t.data,this.name="RpcError"}};var J=r=>{let e=new Map,t=_(),n=new Map,o=null,m="disconnected",u=(s,a,l)=>{o.send(JSON.stringify({jsonrpc:"2.0",id:s,method:a,params:l}))};function d(s){try{let a,l,p,E,S;if({id:a,result:l,error:p,params:E}=JSON.parse(s),a){let g=e.get(a);return g?(e.delete(a),p?g.onError(new T(p)):g.onSuccess(l,(H,k)=>(t.subscribe(H,k),()=>{t.unsubscribe(H)}))):void 0}if({subscription:S,result:l,error:p}=E,!S||!p&&!Object.hasOwn(E,"result"))throw 0;p?t.error(S,new T(p)):t.next(S,l)}catch(a){console.warn("Error parsing incomming message: "+s),console.error(a)}}function i(s){s==="connected"&&(n.forEach((a,l)=>{h(l,...a)}),n.clear()),m=s}let b=()=>{o=r(d,i),o.open()},c=()=>{o?.close(),o=null,e.clear(),n.clear(),t.errorAll(new Error("disconnected"))},h=(s,...a)=>{let[l,p,E]=a;E&&e.set(s,E),u(s,l,p)},f=1;return{request:(s,a,l)=>{if(!o)throw new Error("Not connected");let p=f++;return m==="connected"?h(p,s,a,l):n.set(p,[s,a,l]),()=>{if(n.has(p)){n.delete(p);return}e.delete(p)}},connect:b,disconnect:c}};var oe=r=>{let e=J(r);return e.connect(),{chainHead:V(e.request),transaction:M(e.request),_request:e.request}};
"use strict";var P=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var Z=(r,e,t)=>e in r?P(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var ee=(r,e)=>{for(var t in e)P(r,t,{get:e[t],enumerable:!0})},re=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of X(e))!Y.call(r,i)&&i!==t&&P(r,i,{get:()=>e[i],enumerable:!(n=V(e,i))||n.enumerable});return r};var te=r=>re(P({},"__esModule",{value:!0}),r);var F=(r,e,t)=>(Z(r,typeof e!="symbol"?e+"":e,t),t);var ae={};ee(ae,{DisjointError:()=>h,OperationError:()=>C,OperationInaccessibleError:()=>T,OperationLimitError:()=>v,RpcError:()=>w,StopError:()=>q,TransactionError:()=>I,createClient:()=>se});module.exports=te(ae);var U=class extends Error{constructor(){super("Aborted by AbortSignal"),this.name="AbortError"}},_=r=>(...e)=>new Promise((t,n)=>{let[i,a]=e[e.length-1]instanceof AbortSignal?[e.slice(0,e.length-1),e[e.length-1]]:[e],b=()=>{p(),n(new U)};a?.addEventListener("abort",b,{once:!0});let c=d=>x=>{a?.removeEventListener("abort",b),d(x)},p=r(c(t),c(n),...i)});function j(){let r=()=>{},e=()=>{};return{promise:new Promise((n,i)=>{r=n,e=i}),res:r,rej:e}}var y=()=>{};var H=()=>{let r=new Map;return{has:r.has.bind(r),subscribe(e,t){r.set(e,t)},unsubscribe(e){r.delete(e)},next(e,t){r.get(e)?.next(t)},error(e,t){let n=r.get(e);n&&(r.delete(e),n.error(t))},errorAll(e){let t=[...r.values()];r.clear(),t.forEach(n=>{n.error(e)})}}};var oe=new Set(["dropped","invalid","finalized","error"]);function ne(r){return oe.has(r.type)}var I=class extends Error{constructor(t){super(`TxError: ${t.type} - ${t.error}`);F(this,"type");F(this,"error");this.type=t.type,this.error=t.error,this.name="TransactionError"}},k=r=>(e,t,n)=>{let i=r("transaction_unstable_submitAndWatch",[e],{onSuccess:(a,b)=>{let c=b(a,{next:p=>{if(ne(p)&&(c(),i=y,p.type!=="finalized"))return n(new I(p));t(p)},error(p){i(),i=y,n(p)}});i=()=>{c(),r("transaction_unstable_unwatch",[a])}},onError:n});return()=>{i()}};var q=class extends Error{constructor(){super("ChainHead stopped"),this.name="StopError"}},h=class extends Error{constructor(){super("ChainHead disjointed"),this.name="DisjointError"}},v=class extends Error{constructor(){super("ChainHead operations limit reached"),this.name="OperationLimitError"}},C=class extends Error{constructor(e){super(e),this.name="OperationError"}},T=class extends Error{constructor(){super("ChainHead operation inaccessible"),this.name="OperationInaccessibleError"}};var D=(r,e)=>t=>_((n,i,...a)=>{let[b,c]=e(...a),p=t(r,b,{onSuccess:(d,x)=>{if(d.result==="limitReached")return p=y,i(new v);let f=!0,m=y,g=s=>{f=!1,m(),n(s)},o=s=>{f=!1,m(),i(s)};m=x(d.operationId,{next:s=>{let l=s;l.type==="operationError"?i(new C(l.error)):l.type==="operationInaccessible"?i(new T):c(s,g,o)},error:o}),p=()=>{f&&(m(),t("chainHead_unstable_stopOperation",[d.operationId]))}},onError:i});return()=>{p()}});var z=D("chainHead_unstable_body",r=>[[r],(e,t)=>{t(e.value)}]);var B=D("chainHead_unstable_call",(r,e,t)=>[[r,e,t],(n,i)=>{i(n.output)}]);var J=r=>e=>new Promise((t,n)=>{r("chainHead_unstable_header",[e],{onSuccess:t,onError:n})});var L=require("@polkadot-api/utils");var W=r=>(e,t,n,i,a,b,c)=>{if(t.length===0)return b(),L.noop;let p=r("chainHead_unstable_storage",[e,t,n],{onSuccess:(d,x)=>{if(d.result==="limitReached"||d.discardedItems===t.length)return a(new v);let f=x(d.operationId,{next:o=>{switch(o.type){case"operationStorageItems":{i(o.items);break}case"operationStorageDone":{g();break}case"operationError":{m(new C(o.error));break}case"operationInaccessible":{m(new T);break}default:r("chainHead_unstable_continue",[])}},error:a});p=()=>{f(),r("chainHead_unstable_stopOperation",[d.operationId])};let m=o=>{p=L.noop,f(),a(o)},g=()=>{p=L.noop,f(),b()};c(d.discardedItems)},onError:a});return()=>{p()}};var $=r=>{let e=W(r);return _((t,n,i,a,b,c)=>{let p=a.startsWith("descendants"),d=p?[]:null,f=e(i,[{key:b,type:a}],c??null,p?m=>{d.push(...m)}:m=>{d=m[0]?.[a]},n,()=>{t(d)},m=>{m>0&&(f(),n(new v))});return f})};var K=r=>e=>new Promise((t,n)=>{r("chainHead_unstable_unpin",[e],{onSuccess(){t()},onError:n})});function ie(r){return r.operationId!==void 0}function G(r){return(e,t,n)=>{let i=H(),a=new Set,b=j(),c=b.promise,p=o=>{if(ie(o))return i.next(o.operationId,o);if(o.type!=="stop")return t(o);n(new q),m(!1)},d=o=>{n(o),m()},m=r("chainHead_unstable_follow",[e],{onSuccess:(o,s)=>{let l=s(o,{next:p,error:d});m=(u=!0)=>{c=null,m=y,l(),u&&r("chainHead_unstable_unfollow",[o]),i.errorAll(new h),a.forEach(E=>{E()}),a.clear()},c=o,b.res(o)},onError:o=>{n(o),c=null,b.res(o)}}),g=(o,s,l)=>{let u=()=>{l?.onError(new h)};if(c===null)return u(),y;let E=S=>{if(!l)return r(o,[S,...s]);a.add(u);let A=(O,N)=>c===null?(N.error(new h),y):(i.subscribe(O,N),()=>{i.unsubscribe(O)}),M=r(o,[S,...s],{onSuccess:O=>{a.delete(u),l.onSuccess(O,A)},onError:O=>{a.delete(u),l.onError(O)}});return()=>{a.delete(u),M()}};if(typeof c=="string")return E(c);let R=y;return c.then(S=>{if(S instanceof Error)return u();c&&(R=E(S))}),()=>{R()}};return{unfollow(){m(),c=null},body:z(g),call:B(g),header:J(g),storage:$(g),storageSubscription:W(g),unpin:K(g),_request:g}}}var w=class extends Error{constructor(t){super(t.message);F(this,"code");F(this,"data");this.code=t.code,this.data=t.data,this.name="RpcError"}};var Q=r=>{let e=new Map,t=H(),n=new Map,i=null,a="disconnected",b=(o,s,l)=>{i.send(JSON.stringify({jsonrpc:"2.0",id:o,method:s,params:l}))};function c(o){try{let s,l,u,E,R;if({id:s,result:l,error:u,params:E}=JSON.parse(o),s){let S=e.get(s);return S?(e.delete(s),u?S.onError(new w(u)):S.onSuccess(l,(A,M)=>(t.subscribe(A,M),()=>{t.unsubscribe(A)}))):void 0}if({subscription:R,result:l,error:u}=E,!R||!u&&!Object.hasOwn(E,"result"))throw 0;u?t.error(R,new w(u)):t.next(R,l)}catch(s){console.warn("Error parsing incomming message: "+o),console.error(s)}}function p(o){o==="connected"&&(n.forEach((s,l)=>{f(l,...s)}),n.clear()),a=o}let d=()=>{i=r(c,p),i.open()},x=()=>{i?.close(),i=null,e.clear(),n.clear(),t.errorAll(new Error("disconnected"))},f=(o,...s)=>{let[l,u,E]=s;E&&e.set(o,E),b(o,l,u)},m=1;return{request:(o,s,l)=>{if(!i)throw new Error("Not connected");let u=m++;return a==="connected"?f(u,o,s,l):n.set(u,[o,s,l]),()=>{if(n.has(u)){n.delete(u);return}e.delete(u)}},connect:d,disconnect:x}};var se=r=>{let e=Q(r);return e.connect(),{chainHead:G(e.request),transaction:k(e.request),_request:e.request}};
//# sourceMappingURL=index.js.map
{
"name": "@polkadot-api/substrate-client",
"version": "0.0.1-f898f0a3a6cfaf419c932dd350d98303a7375b8c.1.0",
"version": "0.0.1-fac5bf6a6664d72aa08bb6eac0a99a39bbffce72.1.0",
"author": "Josep M Sobrepere (https://github.com/josepot)",

@@ -44,4 +44,4 @@ "repository": {

"@vitest/coverage-v8": "^0.34.3",
"@polkadot-api/json-rpc-provider": "0.0.1-f898f0a3a6cfaf419c932dd350d98303a7375b8c.1.0",
"@polkadot-api/utils": "0.0.1-f898f0a3a6cfaf419c932dd350d98303a7375b8c.1.0"
"@polkadot-api/json-rpc-provider": "0.0.1-fac5bf6a6664d72aa08bb6eac0a99a39bbffce72.1.0",
"@polkadot-api/utils": "0.0.1-fac5bf6a6664d72aa08bb6eac0a99a39bbffce72.1.0"
},

@@ -48,0 +48,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc