@polkadot-api/substrate-client 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -36
- package/dist/index.mjs.map +1 -1
- package/dist/min/index.d.ts +2 -0
- package/dist/min/index.js +1 -1
- package/dist/min/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,14 +17,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) =>
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
21
|
|
|
25
22
|
// src/index.ts
|
|
26
23
|
var src_exports = {};
|
|
27
24
|
__export(src_exports, {
|
|
25
|
+
AbortError: () => import_utils3.AbortError,
|
|
28
26
|
DestroyedError: () => DestroyedError,
|
|
29
27
|
DisjointError: () => DisjointError,
|
|
30
28
|
OperationError: () => OperationError,
|
|
@@ -202,8 +200,7 @@ var createOperationPromise = (operationName, factory) => (request) => abortableP
|
|
|
202
200
|
const stopOperation = () => {
|
|
203
201
|
request(chainHead.stopOperation, [operationId]);
|
|
204
202
|
};
|
|
205
|
-
if (!isRunning)
|
|
206
|
-
return stopOperation();
|
|
203
|
+
if (!isRunning) return stopOperation();
|
|
207
204
|
let done = noop2;
|
|
208
205
|
const _res = (x) => {
|
|
209
206
|
isRunning = false;
|
|
@@ -222,8 +219,7 @@ var createOperationPromise = (operationName, factory) => (request) => abortableP
|
|
|
222
219
|
rej(new OperationError(_e.error));
|
|
223
220
|
else if (_e.event === "operationInaccessible")
|
|
224
221
|
rej(new OperationInaccessibleError());
|
|
225
|
-
else
|
|
226
|
-
logicCb(e, _res, _rej);
|
|
222
|
+
else logicCb(e, _res, _rej);
|
|
227
223
|
},
|
|
228
224
|
error: _rej
|
|
229
225
|
});
|
|
@@ -290,8 +286,7 @@ var createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, o
|
|
|
290
286
|
const stopOperation = () => {
|
|
291
287
|
request(chainHead.stopOperation, [operationId]);
|
|
292
288
|
};
|
|
293
|
-
if (!isRunning)
|
|
294
|
-
return stopOperation();
|
|
289
|
+
if (!isRunning) return stopOperation();
|
|
295
290
|
const doneListening = followSubscription(response.operationId, {
|
|
296
291
|
next: (event) => {
|
|
297
292
|
switch (event.event) {
|
|
@@ -469,8 +464,7 @@ function getChainHead(request) {
|
|
|
469
464
|
return noop2;
|
|
470
465
|
}
|
|
471
466
|
const onSubscription = (subscription) => {
|
|
472
|
-
if (!cb)
|
|
473
|
-
return request(method, [subscription, ...params]);
|
|
467
|
+
if (!cb) return request(method, [subscription, ...params]);
|
|
474
468
|
ongoingRequests.add(disjoint);
|
|
475
469
|
const onSubscribeOperation = (operationId, subscriber) => {
|
|
476
470
|
if (followSubscription === null) {
|
|
@@ -501,10 +495,8 @@ function getChainHead(request) {
|
|
|
501
495
|
return onSubscription(followSubscription);
|
|
502
496
|
let onCancel = noop2;
|
|
503
497
|
followSubscription.then((x) => {
|
|
504
|
-
if (x instanceof Error)
|
|
505
|
-
|
|
506
|
-
if (followSubscription)
|
|
507
|
-
onCancel = onSubscription(x);
|
|
498
|
+
if (x instanceof Error) return disjoint();
|
|
499
|
+
if (followSubscription) onCancel = onSubscription(x);
|
|
508
500
|
});
|
|
509
501
|
return () => {
|
|
510
502
|
onCancel();
|
|
@@ -562,8 +554,7 @@ var createClient = (gProvider) => {
|
|
|
562
554
|
({ id, result, error, params } = parsed);
|
|
563
555
|
if (id) {
|
|
564
556
|
const cb = responses.get(id);
|
|
565
|
-
if (!cb)
|
|
566
|
-
return;
|
|
557
|
+
if (!cb) return;
|
|
567
558
|
responses.delete(id);
|
|
568
559
|
return error ? cb.onError(new RpcError(error)) : cb.onSuccess(result, (opaqueId, subscriber) => {
|
|
569
560
|
const subscriptionId2 = opaqueId;
|
|
@@ -575,8 +566,7 @@ var createClient = (gProvider) => {
|
|
|
575
566
|
}
|
|
576
567
|
;
|
|
577
568
|
({ subscription, result, error } = params);
|
|
578
|
-
if (!subscription || !error && !Object.hasOwn(params, "result"))
|
|
579
|
-
throw 0;
|
|
569
|
+
if (!subscription || !error && !Object.hasOwn(params, "result")) throw 0;
|
|
580
570
|
const subscriptionId = subscription;
|
|
581
571
|
if (error) {
|
|
582
572
|
subscriptions.error(subscriptionId, new RpcError(error));
|
|
@@ -598,11 +588,9 @@ var createClient = (gProvider) => {
|
|
|
598
588
|
};
|
|
599
589
|
let nextId = 1;
|
|
600
590
|
const request = (method, params, cb) => {
|
|
601
|
-
if (!connection)
|
|
602
|
-
throw new Error("Not connected");
|
|
591
|
+
if (!connection) throw new Error("Not connected");
|
|
603
592
|
const id = `${clientId}-${nextId++}`;
|
|
604
|
-
if (cb)
|
|
605
|
-
responses.set(id, cb);
|
|
593
|
+
if (cb) responses.set(id, cb);
|
|
606
594
|
send(id, method, params);
|
|
607
595
|
return () => {
|
|
608
596
|
responses.delete(id);
|
|
@@ -621,8 +609,7 @@ var createGetChainSpec = (clientRequest) => {
|
|
|
621
609
|
);
|
|
622
610
|
let cachedPromise = null;
|
|
623
611
|
return async () => {
|
|
624
|
-
if (cachedPromise)
|
|
625
|
-
return cachedPromise;
|
|
612
|
+
if (cachedPromise) return cachedPromise;
|
|
626
613
|
return cachedPromise = Promise.all([
|
|
627
614
|
request(chainSpec.chainName, []),
|
|
628
615
|
request(chainSpec.genesisHash, []),
|
|
@@ -640,8 +627,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
640
627
|
let translations = {};
|
|
641
628
|
let enhancedRequest = null;
|
|
642
629
|
return (method, ...rest) => {
|
|
643
|
-
if (enhancedRequest)
|
|
644
|
-
return enhancedRequest(method, ...rest);
|
|
630
|
+
if (enhancedRequest) return enhancedRequest(method, ...rest);
|
|
645
631
|
let isRunning = true;
|
|
646
632
|
let cleanup = () => {
|
|
647
633
|
isRunning = false;
|
|
@@ -649,16 +635,13 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
649
635
|
rpcMethodsP.then((rpcMethods) => {
|
|
650
636
|
enhancedRequest = (method_, ...iRest) => {
|
|
651
637
|
const method2 = translations[method_] ?? method_;
|
|
652
|
-
if (rpcMethods.has(method2))
|
|
653
|
-
return request(method2, ...iRest);
|
|
638
|
+
if (rpcMethods.has(method2)) return request(method2, ...iRest);
|
|
654
639
|
iRest[1]?.onError(new Error(`Unsupported method ${method2}`));
|
|
655
640
|
return noop2;
|
|
656
641
|
};
|
|
657
|
-
if (rpcMethods.has(method))
|
|
658
|
-
return;
|
|
642
|
+
if (rpcMethods.has(method)) return;
|
|
659
643
|
const parts = method.split("_");
|
|
660
|
-
if (parts[1] !== "v1")
|
|
661
|
-
return;
|
|
644
|
+
if (parts[1] !== "v1") return;
|
|
662
645
|
parts[1] = "unstable";
|
|
663
646
|
if (rpcMethods.has(parts.join("_")))
|
|
664
647
|
Object.values(methods).forEach((value) => {
|
|
@@ -681,8 +664,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
681
664
|
}
|
|
682
665
|
}
|
|
683
666
|
}).then(() => {
|
|
684
|
-
if (isRunning)
|
|
685
|
-
cleanup = enhancedRequest(method, ...rest);
|
|
667
|
+
if (isRunning) cleanup = enhancedRequest(method, ...rest);
|
|
686
668
|
});
|
|
687
669
|
return () => {
|
|
688
670
|
cleanup();
|
|
@@ -691,6 +673,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
691
673
|
};
|
|
692
674
|
|
|
693
675
|
// src/index.ts
|
|
676
|
+
var import_utils3 = require("@polkadot-api/utils");
|
|
694
677
|
var createClient2 = (provider) => {
|
|
695
678
|
const client = createClient(provider);
|
|
696
679
|
const request = abortablePromiseFn(
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/internal-utils/subscriptions-manager.ts","../src/methods.ts","../src/transaction/transaction.ts","../src/chainhead/errors.ts","../src/chainhead/operation-promise.ts","../src/chainhead/body.ts","../src/chainhead/call.ts","../src/chainhead/header.ts","../src/chainhead/storage-subscription.ts","../src/chainhead/storage.ts","../src/chainhead/unpin.ts","../src/client/DestroyedError.ts","../src/chainhead/chainhead.ts","../src/client/RpcError.ts","../src/client/createClient.ts","../src/chainspec.ts","../src/request-compatibility-enhancer.ts"],"sourcesContent":["import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport {\n ClientRequest,\n ClientRequestCb,\n createClient as createRawClient,\n} from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\nimport { getCompatibilityEnhancer } from \"./request-compatibility-enhancer\"\nimport { chainHead, chainSpec, transaction } from \"./methods\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\nexport type * from \"./chainspec\"\n\nexport { RpcError, DestroyedError } from \"./client\"\nexport {\n StopError,\n DisjointError,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./chainhead\"\n\nexport interface SubstrateClient {\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const client = createRawClient(provider)\n\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => client.request(method, params, { onSuccess, onError }),\n )\n\n const rpcMethods: Promise<Set<string>> = request<\n { methods: Array<string> } | Array<string>\n >(\"rpc_methods\", []).then(\n (x) => new Set(Array.isArray(x) ? x : x.methods),\n () => new Set(),\n )\n\n const compatibilityEnhancer = getCompatibilityEnhancer(\n rpcMethods,\n client.request,\n )\n\n return {\n chainHead: getChainHead(\n compatibilityEnhancer(chainHead) as ClientRequest<any, any>,\n ),\n transaction: getTransaction(\n compatibilityEnhancer(transaction) as ClientRequest<string, any>,\n ),\n getChainSpecData: createGetChainSpec(\n compatibilityEnhancer(chainSpec) as ClientRequest<any, any>,\n ),\n destroy: () => {\n client.disconnect()\n },\n request,\n _request: client.request,\n }\n}\n","import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","export const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nexport const chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nexport const transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nexport const transactionWatch = {\n submitAndWatch: \"\",\n unwatch: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { transaction } from \"@/methods\"\n\nexport const getTransaction =\n (request: ClientRequest<string, any>) =>\n (tx: string, error: (e: Error) => void) => {\n let cancel = request(transaction.broadcast, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(transaction.stop, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(new Error(\"Max # of broadcasted transactions has been reached\"))\n }\n },\n onError: error,\n })\n\n return () => {\n cancel()\n }\n }\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n const [requestArgs, logicCb] = factory(...args)\n request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\")\n return rej(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n let done = noop\n const _res = (x: O) => {\n isRunning = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isRunning = false\n done()\n rej(x)\n }\n\n done = followSubscription(operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\")\n rej(new OperationError(_e.error))\n else if (_e.event === \"operationInaccessible\")\n rej(new OperationInaccessibleError())\n else logicCb(e as I, _res, _rej)\n },\n error: _rej,\n })\n\n cancel = () => {\n if (isRunning) {\n done()\n stopOperation()\n }\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import { chainHead } from \"@/methods\"\nimport type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n chainHead.body,\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n chainHead.call,\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(chainHead.header, [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport {\n ClientInnerRequest,\n FollowResponse,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"..\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n request(chainHead.storage, [hash, inputs, childTrie], {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(chainHead.continue, [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(chainHead.stopOperation, [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { ClientInnerRequest, FollowResponse, OperationLimitError } from \"..\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(chainHead.unpin, [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes:\n \"finalizedBlockHash\" in event\n ? [event.finalizedBlockHash]\n : event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (opaqueId, subscriber) => {\n const subscriptionId = opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n","import { ClientRequest } from \"./client\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { chainSpec } from \"./methods\"\n\nexport interface ChainSpecData {\n name: string\n genesisHash: string\n properties: any\n}\n\nexport const createGetChainSpec = (clientRequest: ClientRequest<any, any>) => {\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => clientRequest(method, params, { onSuccess, onError }),\n )\n let cachedPromise: null | Promise<ChainSpecData> = null\n\n return async (): Promise<ChainSpecData> => {\n if (cachedPromise) return cachedPromise\n return (cachedPromise = Promise.all([\n request<string>(chainSpec.chainName, []),\n request<string>(chainSpec.genesisHash, []),\n request<any>(chainSpec.properties, []),\n ]).then(([name, genesisHash, properties]) => ({\n name,\n genesisHash,\n properties,\n })))\n }\n}\n","import type { ClientRequest } from \"@/client\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { noop } from \"./internal-utils\"\n\nexport const getCompatibilityEnhancer =\n <T, E>(rpcMethodsP: Promise<Set<string>>, request: ClientRequest<T, E>) =>\n (methods: Record<string, string>): ClientRequest<T, E> => {\n let translations: Record<string, string> = {}\n let enhancedRequest: ClientRequest<T, E> | null = null\n\n return ((method, ...rest) => {\n if (enhancedRequest) return enhancedRequest(method, ...rest)\n\n let isRunning = true\n let cleanup: UnsubscribeFn = () => {\n isRunning = false\n }\n\n rpcMethodsP\n .then((rpcMethods) => {\n enhancedRequest = (method_, ...iRest) => {\n const method = translations[method_] ?? method_\n if (rpcMethods.has(method)) return request(method, ...iRest)\n iRest[1]?.onError(new Error(`Unsupported method ${method}`))\n return noop\n }\n\n if (rpcMethods.has(method)) return\n\n const parts = method.split(\"_\")\n if (parts[1] !== \"v1\") return\n\n parts[1] = \"unstable\"\n\n if (rpcMethods.has(parts.join(\"_\")))\n Object.values(methods).forEach((value) => {\n translations[value] = value.replace(\"_v1_\", \"_unstable_\")\n })\n else if (parts[0] === \"transaction\") {\n // old versions of smoldot and Polkadot-SDK don't support transaction_xx_broadcast\n // some old versions have `transactions_unstable_submitAndWatch` while others have `transaction_xx_submitAndWatch`\n // if we find any of this options, then we will can use them as if they were broadast/stop\n let unwatch: string | undefined\n let version: string | undefined\n\n const txGroup = [\"transactionWatch\", \"transaction\"].find(\n (group) => {\n version = [\"v1\", \"unstable\"].find((v) =>\n rpcMethods.has((unwatch = `${group}_${v}_unwatch`)),\n )\n return !!version\n },\n )\n\n if (txGroup) {\n translations[methods.broadcast] =\n `${txGroup}_${version}_submitAndWatch`\n translations[methods.stop] = unwatch!\n }\n }\n })\n .then(() => {\n if (isRunning) cleanup = enhancedRequest!(method, ...rest)\n })\n\n return () => {\n cleanup()\n }\n }) as ClientRequest<T, E>\n }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAAA;AAAA;AAAA;;;ACAA,mBAAiC;AAG1B,IAAM,qBACX,CACE,OAIF,IAAI,SACF,IAAI,QAAQ,CAAC,KAAK,QAAQ;AACxB,MAAI,SAAS;AAEb,QAAM,CAAC,YAAY,WAAW,IAC5B,KAAK,KAAK,SAAS,CAAC,aAAa,cAC5B,CAAC,KAAK,MAAM,GAAG,KAAK,SAAS,CAAC,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,IAItD,CAAC,IAAI;AAEZ,QAAM,UAAU,MAAM;AACpB,WAAO;AACP,QAAI,IAAI,wBAAW,CAAC;AAAA,EACtB;AAEA,eAAa,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;AAE9D,QAAM,cACJ,CAAIC,QACJ,CAAC,MAAM;AACL,aAAS;AACT,iBAAa,oBAAoB,SAAS,OAAO;AACjD,IAAAA,IAAG,CAAC;AAAA,EACN;AAEF,WAAS,GAAG,GAAG,CAAC,YAAY,GAAG,GAAG,YAAY,GAAG,GAAG,GAAG,UAAU,CAAC;AACpE,CAAC;;;AC/BE,SAAS,WAAkC;AAChD,MAAI,MAA0B,MAAM;AAAA,EAAC;AACrC,MAAI,MAA4B,MAAM;AAAA,EAAC;AAEvC,QAAM,UAAU,IAAI,QAAW,CAAC,MAAM,SAAS;AAC7C,UAAM;AACN,UAAM;AAAA,EACR,CAAC;AAED,SAAO,EAAE,SAAS,KAAK,IAAI;AAC7B;;;AChBO,IAAMC,QAAO,MAAY;AAAC;;;ACK1B,IAAM,0BAA0B,MAAS;AAC9C,QAAM,gBAAgB,oBAAI,IAA2B;AAErD,SAAO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,WACG,OAAO,QAAQ,QAAQ,QAAQ,EAAE,WAAW,QAAQ,CAAC;AAAA,EAC5D;AAEA,QAAM,aAAmC,QAEvC,eAAe,CAAC,CAAC,EAAE;AAAA,IACnB,CAAC,MAAM,IAAI,IAAI,MAAM,QAAQ,CAAC,IAAI,IAAI,EAAE,OAAO;AAAA,IAC/C,MAAM,oBAAI,IAAI;AAAA,EAChB;AAEA,QAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA,OAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,WAAW;AAAA,MACT,sBAAsB,SAAS;AAAA,IACjC;AAAA,IACA,aAAa;AAAA,MACX,sBAAsB,WAAW;AAAA,IACnC;AAAA,IACA,kBAAkB;AAAA,MAChB,sBAAsB,SAAS;AAAA,IACjC;AAAA,IACA,SAAS,MAAM;AACb,aAAO,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,EACnB;AACF;","names":["createClient","fn","noop","noop","noop","import_utils","noop","subscriptionId","method","noop","createClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/internal-utils/subscriptions-manager.ts","../src/methods.ts","../src/transaction/transaction.ts","../src/chainhead/errors.ts","../src/chainhead/operation-promise.ts","../src/chainhead/body.ts","../src/chainhead/call.ts","../src/chainhead/header.ts","../src/chainhead/storage-subscription.ts","../src/chainhead/storage.ts","../src/chainhead/unpin.ts","../src/client/DestroyedError.ts","../src/chainhead/chainhead.ts","../src/client/RpcError.ts","../src/client/createClient.ts","../src/chainspec.ts","../src/request-compatibility-enhancer.ts"],"sourcesContent":["import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport {\n ClientRequest,\n ClientRequestCb,\n createClient as createRawClient,\n} from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\nimport { getCompatibilityEnhancer } from \"./request-compatibility-enhancer\"\nimport { chainHead, chainSpec, transaction } from \"./methods\"\n\nexport { AbortError } from \"@polkadot-api/utils\"\nexport type * from \"@polkadot-api/json-rpc-provider\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\nexport type * from \"./chainspec\"\n\nexport { RpcError, DestroyedError } from \"./client\"\nexport {\n StopError,\n DisjointError,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./chainhead\"\n\nexport interface SubstrateClient {\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const client = createRawClient(provider)\n\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => client.request(method, params, { onSuccess, onError }),\n )\n\n const rpcMethods: Promise<Set<string>> = request<\n { methods: Array<string> } | Array<string>\n >(\"rpc_methods\", []).then(\n (x) => new Set(Array.isArray(x) ? x : x.methods),\n () => new Set(),\n )\n\n const compatibilityEnhancer = getCompatibilityEnhancer(\n rpcMethods,\n client.request,\n )\n\n return {\n chainHead: getChainHead(\n compatibilityEnhancer(chainHead) as ClientRequest<any, any>,\n ),\n transaction: getTransaction(\n compatibilityEnhancer(transaction) as ClientRequest<string, any>,\n ),\n getChainSpecData: createGetChainSpec(\n compatibilityEnhancer(chainSpec) as ClientRequest<any, any>,\n ),\n destroy: () => {\n client.disconnect()\n },\n request,\n _request: client.request,\n }\n}\n","import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","export const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nexport const chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nexport const transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nexport const transactionWatch = {\n submitAndWatch: \"\",\n unwatch: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { transaction } from \"@/methods\"\n\nexport const getTransaction =\n (request: ClientRequest<string, any>) =>\n (tx: string, error: (e: Error) => void) => {\n let cancel = request(transaction.broadcast, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(transaction.stop, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(new Error(\"Max # of broadcasted transactions has been reached\"))\n }\n },\n onError: error,\n })\n\n return () => {\n cancel()\n }\n }\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n const [requestArgs, logicCb] = factory(...args)\n request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\")\n return rej(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n let done = noop\n const _res = (x: O) => {\n isRunning = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isRunning = false\n done()\n rej(x)\n }\n\n done = followSubscription(operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\")\n rej(new OperationError(_e.error))\n else if (_e.event === \"operationInaccessible\")\n rej(new OperationInaccessibleError())\n else logicCb(e as I, _res, _rej)\n },\n error: _rej,\n })\n\n cancel = () => {\n if (isRunning) {\n done()\n stopOperation()\n }\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import { chainHead } from \"@/methods\"\nimport type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n chainHead.body,\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n chainHead.call,\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(chainHead.header, [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport {\n ClientInnerRequest,\n FollowResponse,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"..\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n request(chainHead.storage, [hash, inputs, childTrie], {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(chainHead.continue, [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(chainHead.stopOperation, [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { ClientInnerRequest, FollowResponse, OperationLimitError } from \"..\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(chainHead.unpin, [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes:\n \"finalizedBlockHash\" in event\n ? [event.finalizedBlockHash]\n : event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import type {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (opaqueId, subscriber) => {\n const subscriptionId = opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n","import { ClientRequest } from \"./client\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { chainSpec } from \"./methods\"\n\nexport interface ChainSpecData {\n name: string\n genesisHash: string\n properties: any\n}\n\nexport const createGetChainSpec = (clientRequest: ClientRequest<any, any>) => {\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => clientRequest(method, params, { onSuccess, onError }),\n )\n let cachedPromise: null | Promise<ChainSpecData> = null\n\n return async (): Promise<ChainSpecData> => {\n if (cachedPromise) return cachedPromise\n return (cachedPromise = Promise.all([\n request<string>(chainSpec.chainName, []),\n request<string>(chainSpec.genesisHash, []),\n request<any>(chainSpec.properties, []),\n ]).then(([name, genesisHash, properties]) => ({\n name,\n genesisHash,\n properties,\n })))\n }\n}\n","import type { ClientRequest } from \"@/client\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { noop } from \"./internal-utils\"\n\nexport const getCompatibilityEnhancer =\n <T, E>(rpcMethodsP: Promise<Set<string>>, request: ClientRequest<T, E>) =>\n (methods: Record<string, string>): ClientRequest<T, E> => {\n let translations: Record<string, string> = {}\n let enhancedRequest: ClientRequest<T, E> | null = null\n\n return ((method, ...rest) => {\n if (enhancedRequest) return enhancedRequest(method, ...rest)\n\n let isRunning = true\n let cleanup: UnsubscribeFn = () => {\n isRunning = false\n }\n\n rpcMethodsP\n .then((rpcMethods) => {\n enhancedRequest = (method_, ...iRest) => {\n const method = translations[method_] ?? method_\n if (rpcMethods.has(method)) return request(method, ...iRest)\n iRest[1]?.onError(new Error(`Unsupported method ${method}`))\n return noop\n }\n\n if (rpcMethods.has(method)) return\n\n const parts = method.split(\"_\")\n if (parts[1] !== \"v1\") return\n\n parts[1] = \"unstable\"\n\n if (rpcMethods.has(parts.join(\"_\")))\n Object.values(methods).forEach((value) => {\n translations[value] = value.replace(\"_v1_\", \"_unstable_\")\n })\n else if (parts[0] === \"transaction\") {\n // old versions of smoldot and Polkadot-SDK don't support transaction_xx_broadcast\n // some old versions have `transactions_unstable_submitAndWatch` while others have `transaction_xx_submitAndWatch`\n // if we find any of this options, then we will can use them as if they were broadast/stop\n let unwatch: string | undefined\n let version: string | undefined\n\n const txGroup = [\"transactionWatch\", \"transaction\"].find(\n (group) => {\n version = [\"v1\", \"unstable\"].find((v) =>\n rpcMethods.has((unwatch = `${group}_${v}_unwatch`)),\n )\n return !!version\n },\n )\n\n if (txGroup) {\n translations[methods.broadcast] =\n `${txGroup}_${version}_submitAndWatch`\n translations[methods.stop] = unwatch!\n }\n }\n })\n .then(() => {\n if (isRunning) cleanup = enhancedRequest!(method, ...rest)\n })\n\n return () => {\n cleanup()\n }\n }) as ClientRequest<T, E>\n }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAAA;AAAA;AAAA;;;ACAA,mBAAiC;AAG1B,IAAM,qBACX,CACE,OAIF,IAAI,SACF,IAAI,QAAQ,CAAC,KAAK,QAAQ;AACxB,MAAI,SAAS;AAEb,QAAM,CAAC,YAAY,WAAW,IAC5B,KAAK,KAAK,SAAS,CAAC,aAAa,cAC5B,CAAC,KAAK,MAAM,GAAG,KAAK,SAAS,CAAC,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,IAItD,CAAC,IAAI;AAEZ,QAAM,UAAU,MAAM;AACpB,WAAO;AACP,QAAI,IAAI,wBAAW,CAAC;AAAA,EACtB;AAEA,eAAa,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;AAE9D,QAAM,cACJ,CAAIC,QACJ,CAAC,MAAM;AACL,aAAS;AACT,iBAAa,oBAAo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CAAC,UAAW;AAAA,YACpD;AACA,mBAAO,CAAC,CAAC;AAAA,UACX;AAAA,QACF;AAEA,YAAI,SAAS;AACX,uBAAa,QAAQ,SAAS,IAC5B,GAAG,OAAO,IAAI,OAAO;AACvB,uBAAa,QAAQ,IAAI,IAAI;AAAA,QAC/B;AAAA,MACF;AAAA,IACF,CAAC,EACA,KAAK,MAAM;AACV,UAAI,UAAW,WAAU,gBAAiB,QAAQ,GAAG,IAAI;AAAA,IAC3D,CAAC;AAEH,WAAO,MAAM;AACX,cAAQ;AAAA,IACV;AAAA,EACF;AACF;;;ApBrDF,IAAAC,gBAA2B;AAmCpB,IAAMC,gBAAe,CAAC,aAA+C;AAC1E,QAAM,SAAS,aAAgB,QAAQ;AAEvC,QAAM,UAAU;AAAA,IACd,CACE,WACA,SACA,QACA,WACG,OAAO,QAAQ,QAAQ,QAAQ,EAAE,WAAW,QAAQ,CAAC;AAAA,EAC5D;AAEA,QAAM,aAAmC,QAEvC,eAAe,CAAC,CAAC,EAAE;AAAA,IACnB,CAAC,MAAM,IAAI,IAAI,MAAM,QAAQ,CAAC,IAAI,IAAI,EAAE,OAAO;AAAA,IAC/C,MAAM,oBAAI,IAAI;AAAA,EAChB;AAEA,QAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA,OAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,WAAW;AAAA,MACT,sBAAsB,SAAS;AAAA,IACjC;AAAA,IACA,aAAa;AAAA,MACX,sBAAsB,WAAW;AAAA,IACnC;AAAA,IACA,kBAAkB;AAAA,MAChB,sBAAsB,SAAS;AAAA,IACjC;AAAA,IACA,SAAS,MAAM;AACb,aAAO,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,EACnB;AACF;","names":["createClient","fn","noop","noop","noop","import_utils","noop","subscriptionId","method","noop","import_utils","createClient"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) =>
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
4
|
|
|
8
5
|
// src/internal-utils/abortablePromiseFn.ts
|
|
9
6
|
import { AbortError, noop } from "@polkadot-api/utils";
|
|
@@ -171,8 +168,7 @@ var createOperationPromise = (operationName, factory) => (request) => abortableP
|
|
|
171
168
|
const stopOperation = () => {
|
|
172
169
|
request(chainHead.stopOperation, [operationId]);
|
|
173
170
|
};
|
|
174
|
-
if (!isRunning)
|
|
175
|
-
return stopOperation();
|
|
171
|
+
if (!isRunning) return stopOperation();
|
|
176
172
|
let done = noop2;
|
|
177
173
|
const _res = (x) => {
|
|
178
174
|
isRunning = false;
|
|
@@ -191,8 +187,7 @@ var createOperationPromise = (operationName, factory) => (request) => abortableP
|
|
|
191
187
|
rej(new OperationError(_e.error));
|
|
192
188
|
else if (_e.event === "operationInaccessible")
|
|
193
189
|
rej(new OperationInaccessibleError());
|
|
194
|
-
else
|
|
195
|
-
logicCb(e, _res, _rej);
|
|
190
|
+
else logicCb(e, _res, _rej);
|
|
196
191
|
},
|
|
197
192
|
error: _rej
|
|
198
193
|
});
|
|
@@ -259,8 +254,7 @@ var createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, o
|
|
|
259
254
|
const stopOperation = () => {
|
|
260
255
|
request(chainHead.stopOperation, [operationId]);
|
|
261
256
|
};
|
|
262
|
-
if (!isRunning)
|
|
263
|
-
return stopOperation();
|
|
257
|
+
if (!isRunning) return stopOperation();
|
|
264
258
|
const doneListening = followSubscription(response.operationId, {
|
|
265
259
|
next: (event) => {
|
|
266
260
|
switch (event.event) {
|
|
@@ -438,8 +432,7 @@ function getChainHead(request) {
|
|
|
438
432
|
return noop2;
|
|
439
433
|
}
|
|
440
434
|
const onSubscription = (subscription) => {
|
|
441
|
-
if (!cb)
|
|
442
|
-
return request(method, [subscription, ...params]);
|
|
435
|
+
if (!cb) return request(method, [subscription, ...params]);
|
|
443
436
|
ongoingRequests.add(disjoint);
|
|
444
437
|
const onSubscribeOperation = (operationId, subscriber) => {
|
|
445
438
|
if (followSubscription === null) {
|
|
@@ -470,10 +463,8 @@ function getChainHead(request) {
|
|
|
470
463
|
return onSubscription(followSubscription);
|
|
471
464
|
let onCancel = noop2;
|
|
472
465
|
followSubscription.then((x) => {
|
|
473
|
-
if (x instanceof Error)
|
|
474
|
-
|
|
475
|
-
if (followSubscription)
|
|
476
|
-
onCancel = onSubscription(x);
|
|
466
|
+
if (x instanceof Error) return disjoint();
|
|
467
|
+
if (followSubscription) onCancel = onSubscription(x);
|
|
477
468
|
});
|
|
478
469
|
return () => {
|
|
479
470
|
onCancel();
|
|
@@ -531,8 +522,7 @@ var createClient = (gProvider) => {
|
|
|
531
522
|
({ id, result, error, params } = parsed);
|
|
532
523
|
if (id) {
|
|
533
524
|
const cb = responses.get(id);
|
|
534
|
-
if (!cb)
|
|
535
|
-
return;
|
|
525
|
+
if (!cb) return;
|
|
536
526
|
responses.delete(id);
|
|
537
527
|
return error ? cb.onError(new RpcError(error)) : cb.onSuccess(result, (opaqueId, subscriber) => {
|
|
538
528
|
const subscriptionId2 = opaqueId;
|
|
@@ -544,8 +534,7 @@ var createClient = (gProvider) => {
|
|
|
544
534
|
}
|
|
545
535
|
;
|
|
546
536
|
({ subscription, result, error } = params);
|
|
547
|
-
if (!subscription || !error && !Object.hasOwn(params, "result"))
|
|
548
|
-
throw 0;
|
|
537
|
+
if (!subscription || !error && !Object.hasOwn(params, "result")) throw 0;
|
|
549
538
|
const subscriptionId = subscription;
|
|
550
539
|
if (error) {
|
|
551
540
|
subscriptions.error(subscriptionId, new RpcError(error));
|
|
@@ -567,11 +556,9 @@ var createClient = (gProvider) => {
|
|
|
567
556
|
};
|
|
568
557
|
let nextId = 1;
|
|
569
558
|
const request = (method, params, cb) => {
|
|
570
|
-
if (!connection)
|
|
571
|
-
throw new Error("Not connected");
|
|
559
|
+
if (!connection) throw new Error("Not connected");
|
|
572
560
|
const id = `${clientId}-${nextId++}`;
|
|
573
|
-
if (cb)
|
|
574
|
-
responses.set(id, cb);
|
|
561
|
+
if (cb) responses.set(id, cb);
|
|
575
562
|
send(id, method, params);
|
|
576
563
|
return () => {
|
|
577
564
|
responses.delete(id);
|
|
@@ -590,8 +577,7 @@ var createGetChainSpec = (clientRequest) => {
|
|
|
590
577
|
);
|
|
591
578
|
let cachedPromise = null;
|
|
592
579
|
return async () => {
|
|
593
|
-
if (cachedPromise)
|
|
594
|
-
return cachedPromise;
|
|
580
|
+
if (cachedPromise) return cachedPromise;
|
|
595
581
|
return cachedPromise = Promise.all([
|
|
596
582
|
request(chainSpec.chainName, []),
|
|
597
583
|
request(chainSpec.genesisHash, []),
|
|
@@ -609,8 +595,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
609
595
|
let translations = {};
|
|
610
596
|
let enhancedRequest = null;
|
|
611
597
|
return (method, ...rest) => {
|
|
612
|
-
if (enhancedRequest)
|
|
613
|
-
return enhancedRequest(method, ...rest);
|
|
598
|
+
if (enhancedRequest) return enhancedRequest(method, ...rest);
|
|
614
599
|
let isRunning = true;
|
|
615
600
|
let cleanup = () => {
|
|
616
601
|
isRunning = false;
|
|
@@ -618,16 +603,13 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
618
603
|
rpcMethodsP.then((rpcMethods) => {
|
|
619
604
|
enhancedRequest = (method_, ...iRest) => {
|
|
620
605
|
const method2 = translations[method_] ?? method_;
|
|
621
|
-
if (rpcMethods.has(method2))
|
|
622
|
-
return request(method2, ...iRest);
|
|
606
|
+
if (rpcMethods.has(method2)) return request(method2, ...iRest);
|
|
623
607
|
iRest[1]?.onError(new Error(`Unsupported method ${method2}`));
|
|
624
608
|
return noop2;
|
|
625
609
|
};
|
|
626
|
-
if (rpcMethods.has(method))
|
|
627
|
-
return;
|
|
610
|
+
if (rpcMethods.has(method)) return;
|
|
628
611
|
const parts = method.split("_");
|
|
629
|
-
if (parts[1] !== "v1")
|
|
630
|
-
return;
|
|
612
|
+
if (parts[1] !== "v1") return;
|
|
631
613
|
parts[1] = "unstable";
|
|
632
614
|
if (rpcMethods.has(parts.join("_")))
|
|
633
615
|
Object.values(methods).forEach((value) => {
|
|
@@ -650,8 +632,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
650
632
|
}
|
|
651
633
|
}
|
|
652
634
|
}).then(() => {
|
|
653
|
-
if (isRunning)
|
|
654
|
-
cleanup = enhancedRequest(method, ...rest);
|
|
635
|
+
if (isRunning) cleanup = enhancedRequest(method, ...rest);
|
|
655
636
|
});
|
|
656
637
|
return () => {
|
|
657
638
|
cleanup();
|
|
@@ -660,6 +641,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
660
641
|
};
|
|
661
642
|
|
|
662
643
|
// src/index.ts
|
|
644
|
+
import { AbortError as AbortError2 } from "@polkadot-api/utils";
|
|
663
645
|
var createClient2 = (provider) => {
|
|
664
646
|
const client = createClient(provider);
|
|
665
647
|
const request = abortablePromiseFn(
|
|
@@ -691,6 +673,7 @@ var createClient2 = (provider) => {
|
|
|
691
673
|
};
|
|
692
674
|
};
|
|
693
675
|
export {
|
|
676
|
+
AbortError2 as AbortError,
|
|
694
677
|
DestroyedError,
|
|
695
678
|
DisjointError,
|
|
696
679
|
OperationError,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/internal-utils/subscriptions-manager.ts","../src/methods.ts","../src/transaction/transaction.ts","../src/chainhead/errors.ts","../src/chainhead/operation-promise.ts","../src/chainhead/body.ts","../src/chainhead/call.ts","../src/chainhead/header.ts","../src/chainhead/storage-subscription.ts","../src/chainhead/storage.ts","../src/chainhead/unpin.ts","../src/client/DestroyedError.ts","../src/chainhead/chainhead.ts","../src/client/RpcError.ts","../src/client/createClient.ts","../src/chainspec.ts","../src/request-compatibility-enhancer.ts","../src/index.ts"],"sourcesContent":["import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","export const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nexport const chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nexport const transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nexport const transactionWatch = {\n submitAndWatch: \"\",\n unwatch: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { transaction } from \"@/methods\"\n\nexport const getTransaction =\n (request: ClientRequest<string, any>) =>\n (tx: string, error: (e: Error) => void) => {\n let cancel = request(transaction.broadcast, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(transaction.stop, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(new Error(\"Max # of broadcasted transactions has been reached\"))\n }\n },\n onError: error,\n })\n\n return () => {\n cancel()\n }\n }\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n const [requestArgs, logicCb] = factory(...args)\n request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\")\n return rej(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n let done = noop\n const _res = (x: O) => {\n isRunning = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isRunning = false\n done()\n rej(x)\n }\n\n done = followSubscription(operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\")\n rej(new OperationError(_e.error))\n else if (_e.event === \"operationInaccessible\")\n rej(new OperationInaccessibleError())\n else logicCb(e as I, _res, _rej)\n },\n error: _rej,\n })\n\n cancel = () => {\n if (isRunning) {\n done()\n stopOperation()\n }\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import { chainHead } from \"@/methods\"\nimport type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n chainHead.body,\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n chainHead.call,\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(chainHead.header, [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport {\n ClientInnerRequest,\n FollowResponse,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"..\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n request(chainHead.storage, [hash, inputs, childTrie], {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(chainHead.continue, [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(chainHead.stopOperation, [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { ClientInnerRequest, FollowResponse, OperationLimitError } from \"..\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(chainHead.unpin, [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes:\n \"finalizedBlockHash\" in event\n ? [event.finalizedBlockHash]\n : event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (opaqueId, subscriber) => {\n const subscriptionId = opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n","import { ClientRequest } from \"./client\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { chainSpec } from \"./methods\"\n\nexport interface ChainSpecData {\n name: string\n genesisHash: string\n properties: any\n}\n\nexport const createGetChainSpec = (clientRequest: ClientRequest<any, any>) => {\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => clientRequest(method, params, { onSuccess, onError }),\n )\n let cachedPromise: null | Promise<ChainSpecData> = null\n\n return async (): Promise<ChainSpecData> => {\n if (cachedPromise) return cachedPromise\n return (cachedPromise = Promise.all([\n request<string>(chainSpec.chainName, []),\n request<string>(chainSpec.genesisHash, []),\n request<any>(chainSpec.properties, []),\n ]).then(([name, genesisHash, properties]) => ({\n name,\n genesisHash,\n properties,\n })))\n }\n}\n","import type { ClientRequest } from \"@/client\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { noop } from \"./internal-utils\"\n\nexport const getCompatibilityEnhancer =\n <T, E>(rpcMethodsP: Promise<Set<string>>, request: ClientRequest<T, E>) =>\n (methods: Record<string, string>): ClientRequest<T, E> => {\n let translations: Record<string, string> = {}\n let enhancedRequest: ClientRequest<T, E> | null = null\n\n return ((method, ...rest) => {\n if (enhancedRequest) return enhancedRequest(method, ...rest)\n\n let isRunning = true\n let cleanup: UnsubscribeFn = () => {\n isRunning = false\n }\n\n rpcMethodsP\n .then((rpcMethods) => {\n enhancedRequest = (method_, ...iRest) => {\n const method = translations[method_] ?? method_\n if (rpcMethods.has(method)) return request(method, ...iRest)\n iRest[1]?.onError(new Error(`Unsupported method ${method}`))\n return noop\n }\n\n if (rpcMethods.has(method)) return\n\n const parts = method.split(\"_\")\n if (parts[1] !== \"v1\") return\n\n parts[1] = \"unstable\"\n\n if (rpcMethods.has(parts.join(\"_\")))\n Object.values(methods).forEach((value) => {\n translations[value] = value.replace(\"_v1_\", \"_unstable_\")\n })\n else if (parts[0] === \"transaction\") {\n // old versions of smoldot and Polkadot-SDK don't support transaction_xx_broadcast\n // some old versions have `transactions_unstable_submitAndWatch` while others have `transaction_xx_submitAndWatch`\n // if we find any of this options, then we will can use them as if they were broadast/stop\n let unwatch: string | undefined\n let version: string | undefined\n\n const txGroup = [\"transactionWatch\", \"transaction\"].find(\n (group) => {\n version = [\"v1\", \"unstable\"].find((v) =>\n rpcMethods.has((unwatch = `${group}_${v}_unwatch`)),\n )\n return !!version\n },\n )\n\n if (txGroup) {\n translations[methods.broadcast] =\n `${txGroup}_${version}_submitAndWatch`\n translations[methods.stop] = unwatch!\n }\n }\n })\n .then(() => {\n if (isRunning) cleanup = enhancedRequest!(method, ...rest)\n })\n\n return () => {\n cleanup()\n }\n }) as ClientRequest<T, E>\n }\n","import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport {\n ClientRequest,\n ClientRequestCb,\n createClient as createRawClient,\n} from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\nimport { getCompatibilityEnhancer } from \"./request-compatibility-enhancer\"\nimport { chainHead, chainSpec, transaction } from \"./methods\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\nexport type * from \"./chainspec\"\n\nexport { RpcError, DestroyedError } from \"./client\"\nexport {\n StopError,\n DisjointError,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./chainhead\"\n\nexport interface SubstrateClient {\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const client = createRawClient(provider)\n\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => client.request(method, params, { onSuccess, onError }),\n )\n\n const rpcMethods: Promise<Set<string>> = request<\n { methods: Array<string> } | Array<string>\n >(\"rpc_methods\", []).then(\n (x) => new Set(Array.isArray(x) ? x : x.methods),\n () => new Set(),\n )\n\n const compatibilityEnhancer = getCompatibilityEnhancer(\n rpcMethods,\n client.request,\n )\n\n return {\n chainHead: getChainHead(\n compatibilityEnhancer(chainHead) as ClientRequest<any, any>,\n ),\n transaction: getTransaction(\n compatibilityEnhancer(transaction) as ClientRequest<string, any>,\n ),\n getChainSpecData: createGetChainSpec(\n compatibilityEnhancer(chainSpec) as ClientRequest<any, any>,\n ),\n destroy: () => {\n client.disconnect()\n },\n request,\n _request: client.request,\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,YAAY,YAAY;AAG1B,IAAM,qBACX,CACE,OAIF,IAAI,SACF,IAAI,QAAQ,CAAC,KAAK,QAAQ;AACxB,MAAI,SAAS;AAEb,QAAM,CAAC,YAAY,WAAW,IAC5B,KAAK,KAAK,SAAS,CAAC,aAAa,cAC5B,CAAC,KAAK,MAAM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MAChB,sBAAsB,SAAS;AAAA,IACjC;AAAA,IACA,SAAS,MAAM;AACb,aAAO,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,EACnB;AACF;","names":["fn","noop","noop","noop","noop","noop","noop","subscriptionId","method","noop","createClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/internal-utils/subscriptions-manager.ts","../src/methods.ts","../src/transaction/transaction.ts","../src/chainhead/errors.ts","../src/chainhead/operation-promise.ts","../src/chainhead/body.ts","../src/chainhead/call.ts","../src/chainhead/header.ts","../src/chainhead/storage-subscription.ts","../src/chainhead/storage.ts","../src/chainhead/unpin.ts","../src/client/DestroyedError.ts","../src/chainhead/chainhead.ts","../src/client/RpcError.ts","../src/client/createClient.ts","../src/chainspec.ts","../src/request-compatibility-enhancer.ts","../src/index.ts"],"sourcesContent":["import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","export const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nexport const chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nexport const transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nexport const transactionWatch = {\n submitAndWatch: \"\",\n unwatch: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { transaction } from \"@/methods\"\n\nexport const getTransaction =\n (request: ClientRequest<string, any>) =>\n (tx: string, error: (e: Error) => void) => {\n let cancel = request(transaction.broadcast, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(transaction.stop, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(new Error(\"Max # of broadcasted transactions has been reached\"))\n }\n },\n onError: error,\n })\n\n return () => {\n cancel()\n }\n }\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n const [requestArgs, logicCb] = factory(...args)\n request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\")\n return rej(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n let done = noop\n const _res = (x: O) => {\n isRunning = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isRunning = false\n done()\n rej(x)\n }\n\n done = followSubscription(operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\")\n rej(new OperationError(_e.error))\n else if (_e.event === \"operationInaccessible\")\n rej(new OperationInaccessibleError())\n else logicCb(e as I, _res, _rej)\n },\n error: _rej,\n })\n\n cancel = () => {\n if (isRunning) {\n done()\n stopOperation()\n }\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import { chainHead } from \"@/methods\"\nimport type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n chainHead.body,\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n chainHead.call,\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(chainHead.header, [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport {\n ClientInnerRequest,\n FollowResponse,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"..\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n request(chainHead.storage, [hash, inputs, childTrie], {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(chainHead.continue, [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(chainHead.stopOperation, [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { ClientInnerRequest, FollowResponse, OperationLimitError } from \"..\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(chainHead.unpin, [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes:\n \"finalizedBlockHash\" in event\n ? [event.finalizedBlockHash]\n : event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import type {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (opaqueId, subscriber) => {\n const subscriptionId = opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n","import { ClientRequest } from \"./client\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { chainSpec } from \"./methods\"\n\nexport interface ChainSpecData {\n name: string\n genesisHash: string\n properties: any\n}\n\nexport const createGetChainSpec = (clientRequest: ClientRequest<any, any>) => {\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => clientRequest(method, params, { onSuccess, onError }),\n )\n let cachedPromise: null | Promise<ChainSpecData> = null\n\n return async (): Promise<ChainSpecData> => {\n if (cachedPromise) return cachedPromise\n return (cachedPromise = Promise.all([\n request<string>(chainSpec.chainName, []),\n request<string>(chainSpec.genesisHash, []),\n request<any>(chainSpec.properties, []),\n ]).then(([name, genesisHash, properties]) => ({\n name,\n genesisHash,\n properties,\n })))\n }\n}\n","import type { ClientRequest } from \"@/client\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { noop } from \"./internal-utils\"\n\nexport const getCompatibilityEnhancer =\n <T, E>(rpcMethodsP: Promise<Set<string>>, request: ClientRequest<T, E>) =>\n (methods: Record<string, string>): ClientRequest<T, E> => {\n let translations: Record<string, string> = {}\n let enhancedRequest: ClientRequest<T, E> | null = null\n\n return ((method, ...rest) => {\n if (enhancedRequest) return enhancedRequest(method, ...rest)\n\n let isRunning = true\n let cleanup: UnsubscribeFn = () => {\n isRunning = false\n }\n\n rpcMethodsP\n .then((rpcMethods) => {\n enhancedRequest = (method_, ...iRest) => {\n const method = translations[method_] ?? method_\n if (rpcMethods.has(method)) return request(method, ...iRest)\n iRest[1]?.onError(new Error(`Unsupported method ${method}`))\n return noop\n }\n\n if (rpcMethods.has(method)) return\n\n const parts = method.split(\"_\")\n if (parts[1] !== \"v1\") return\n\n parts[1] = \"unstable\"\n\n if (rpcMethods.has(parts.join(\"_\")))\n Object.values(methods).forEach((value) => {\n translations[value] = value.replace(\"_v1_\", \"_unstable_\")\n })\n else if (parts[0] === \"transaction\") {\n // old versions of smoldot and Polkadot-SDK don't support transaction_xx_broadcast\n // some old versions have `transactions_unstable_submitAndWatch` while others have `transaction_xx_submitAndWatch`\n // if we find any of this options, then we will can use them as if they were broadast/stop\n let unwatch: string | undefined\n let version: string | undefined\n\n const txGroup = [\"transactionWatch\", \"transaction\"].find(\n (group) => {\n version = [\"v1\", \"unstable\"].find((v) =>\n rpcMethods.has((unwatch = `${group}_${v}_unwatch`)),\n )\n return !!version\n },\n )\n\n if (txGroup) {\n translations[methods.broadcast] =\n `${txGroup}_${version}_submitAndWatch`\n translations[methods.stop] = unwatch!\n }\n }\n })\n .then(() => {\n if (isRunning) cleanup = enhancedRequest!(method, ...rest)\n })\n\n return () => {\n cleanup()\n }\n }) as ClientRequest<T, E>\n }\n","import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport {\n ClientRequest,\n ClientRequestCb,\n createClient as createRawClient,\n} from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\nimport { getCompatibilityEnhancer } from \"./request-compatibility-enhancer\"\nimport { chainHead, chainSpec, transaction } from \"./methods\"\n\nexport { AbortError } from \"@polkadot-api/utils\"\nexport type * from \"@polkadot-api/json-rpc-provider\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\nexport type * from \"./chainspec\"\n\nexport { RpcError, DestroyedError } from \"./client\"\nexport {\n StopError,\n DisjointError,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./chainhead\"\n\nexport interface SubstrateClient {\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const client = createRawClient(provider)\n\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => client.request(method, params, { onSuccess, onError }),\n )\n\n const rpcMethods: Promise<Set<string>> = request<\n { methods: Array<string> } | Array<string>\n >(\"rpc_methods\", []).then(\n (x) => new Set(Array.isArray(x) ? x : x.methods),\n () => new Set(),\n )\n\n const compatibilityEnhancer = getCompatibilityEnhancer(\n rpcMethods,\n client.request,\n )\n\n return {\n chainHead: getChainHead(\n compatibilityEnhancer(chainHead) as ClientRequest<any, any>,\n ),\n transaction: getTransaction(\n compatibilityEnhancer(transaction) as ClientRequest<string, any>,\n ),\n getChainSpecData: createGetChainSpec(\n compatibilityEnhancer(chainSpec) as ClientRequest<any, any>,\n ),\n destroy: () => {\n client.disconnect()\n },\n request,\n _request: client.request,\n }\n}\n"],"mappings":";;;;;AAAA,SAAS,YAAY,YAAY;AAG1B,IAAM,qBACX,CACE,OAIF,IAAI,SACF,IAAI,QAAQ,CAAC,KAAK,QAAQ;AACxB,MAAI,SAAS;AAEb,QAAM,CAAC,YAAY,WAAW,IAC5B,KAAK,KAAK,SAAS,CAAC,aAAa,cAC5B,CAAC,KAAK,MAAM,GAAG,KAAK,SAAS,CAAC,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,IAItD,CAAC,IAAI;AAEZ,QAAM,UAAU,MAAM;AACpB,WAAO;AACP,QAAI,IAAI,WAAW,CAAC;AAAA,EACtB;AAEA,eAAa,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;AAE9D,QAAM,cACJ,CAAIA,QACJ,CAAC,MAAM;AACL,aAAS;AACT,iBAAa,oBAAoB,SAAS,OAAO;AACjD,IAAAA,IAAG,CAAC;AAAA,EACN;AAEF,WAAS,GAAG,GAAG,CAAC,YAAY,GAAG,GAAG,YAAY,GAAG,GAAG,GAAG,UAAU,CAAC;AACpE,CAAC;;;AC/BE,SAAS,WAAkC;AAChD,MAAI,MAA0B,MAAM;AAAA,EAAC;AACrC,MAAI,MAA4B,MAAM;AAAA,EAAC;AAEvC,QAAM,UAAU,IAAI,QAAW,CAAC,MAAM,SAAS;AAC7C,UAAM;AACN,UAAM;AAAA,EACR,CAAC;AAED,SAAO,EAAE,SAAS,KAAK,IAAI;AAC7B;;;AChBO,IAAMC,QAAO,MAAY;AAAC;;;ACK1B,IAAM,0BAA0B,MAAS;AAC9C,QAAM,gBAAgB,oBAAI,IAA2B;AAErD,SAAO;AAAA,IACL,KAAK,cAAc,IAAI,KAAK,aAAa;AAAA,IACzC,UAAU,IAAY,YAA2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W,QAAQ,CAAC;AAAA,EAC5D;AAEA,QAAM,aAAmC,QAEvC,eAAe,CAAC,CAAC,EAAE;AAAA,IACnB,CAAC,MAAM,IAAI,IAAI,MAAM,QAAQ,CAAC,IAAI,IAAI,EAAE,OAAO;AAAA,IAC/C,MAAM,oBAAI,IAAI;AAAA,EAChB;AAEA,QAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA,OAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,WAAW;AAAA,MACT,sBAAsB,SAAS;AAAA,IACjC;AAAA,IACA,aAAa;AAAA,MACX,sBAAsB,WAAW;AAAA,IACnC;AAAA,IACA,kBAAkB;AAAA,MAChB,sBAAsB,SAAS;AAAA,IACjC;AAAA,IACA,SAAS,MAAM;AACb,aAAO,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,EACnB;AACF;","names":["fn","noop","noop","noop","noop","noop","noop","subscriptionId","method","noop","AbortError","createClient"]}
|
package/dist/min/index.d.ts
CHANGED
package/dist/min/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var k=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var ie=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var se=(r,e)=>{for(var t in e)k(r,t,{get:e[t],enumerable:!0})},ae=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of oe(e))!ne.call(r,o)&&o!==t&&k(r,o,{get:()=>e[o],enumerable:!(n=te(e,o))||n.enumerable});return r};var ce=r=>ae(k({},"__esModule",{value:!0}),r);var B=(r,e,t)=>ie(r,typeof e!="symbol"?e+"":e,t);var de={};se(de,{AbortError:()=>ee.AbortError,DestroyedError:()=>S,DisjointError:()=>w,OperationError:()=>x,OperationInaccessibleError:()=>O,OperationLimitError:()=>C,RpcError:()=>I,StopError:()=>P,createClient:()=>me});module.exports=ce(de);var H=require("@polkadot-api/utils"),v=r=>(...e)=>new Promise((t,n)=>{let o=H.noop,[s,m]=e[e.length-1]instanceof AbortSignal?[e.slice(0,e.length-1),e[e.length-1]]:[e],u=()=>{o(),n(new H.AbortError)};m?.addEventListener("abort",u,{once:!0});let R=f=>p=>{o=H.noop,m?.removeEventListener("abort",u),f(p)};o=r(R(t),R(n),...s)});function z(){let r=()=>{},e=()=>{};return{promise:new Promise((n,o)=>{r=n,e=o}),res:r,rej:e}}var y=()=>{};var W=()=>{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 b={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:"",followEvent:""},F={chainName:"",genesisHash:"",properties:""},A={broadcast:"",stop:""},pe={submitAndWatch:"",unwatch:""};Object.entries({chainHead:b,chainSpec:F,transaction:A,transactionWatch:pe}).forEach(([r,e])=>{Object.keys(e).forEach(t=>{e[t]=`${r}_v1_${t}`})});var M=r=>(e,t)=>{let n=r(A.broadcast,[e],{onSuccess:o=>{n=o===null?y:()=>{r(A.stop,[o])},o===null&&t(new Error("Max # of broadcasted transactions has been reached"))},onError:t});return()=>{n()}};var P=class extends Error{constructor(){super("ChainHead stopped"),this.name="StopError"}},w=class extends Error{constructor(){super("ChainHead disjointed"),this.name="DisjointError"}},C=class extends Error{constructor(){super("ChainHead operations limit reached"),this.name="OperationLimitError"}},x=class extends Error{constructor(e){super(e),this.name="OperationError"}},O=class extends Error{constructor(){super("ChainHead operation inaccessible"),this.name="OperationInaccessibleError"}};var j=(r,e)=>t=>v((n,o,...s)=>{let m=!0,u=()=>{m=!1},[R,f]=e(...s);return t(r,R,{onSuccess:(p,l)=>{if(p.result==="limitReached")return o(new C);let{operationId:a}=p,c=()=>{t(b.stopOperation,[a])};if(!m)return c();let i=y,g=d=>{m=!1,i(),n(d)},h=d=>{m=!1,i(),o(d)};i=l(a,{next:d=>{let E=d;E.event==="operationError"?o(new x(E.error)):E.event==="operationInaccessible"?o(new O):f(d,g,h)},error:h}),u=()=>{m&&(i(),c())}},onError:o}),()=>{u()}});var N=j(b.body,r=>[[r],(e,t)=>{t(e.value)}]);var G=j(b.call,(r,e,t)=>[[r,e,t],(n,o)=>{o(n.output)}]);var K=r=>e=>new Promise((t,n)=>{r(b.header,[e],{onSuccess:t,onError:n})});var U=require("@polkadot-api/utils");var L=r=>(e,t,n,o,s,m,u)=>{if(t.length===0)return m(),U.noop;let R=!0,f=()=>{R=!1};return r(b.storage,[e,t,n],{onSuccess:(p,l)=>{if(p.result==="limitReached"||p.discardedItems===t.length)return s(new C);let{operationId:a}=p,c=()=>{r(b.stopOperation,[a])};if(!R)return c();let i=l(p.operationId,{next:d=>{switch(d.event){case"operationStorageItems":{o(d.items);break}case"operationStorageDone":{h();break}case"operationError":{g(new x(d.error));break}case"operationInaccessible":{g(new O);break}default:r(b.continue,[d.operationId])}},error:s});f=()=>{i(),r(b.stopOperation,[p.operationId])};let g=d=>{f=U.noop,i(),s(d)},h=()=>{f=U.noop,i(),m()};u(p.discardedItems)},onError:s}),()=>{f()}};var Q=r=>{let e=L(r);return v((t,n,o,s,m,u)=>{let R=s.startsWith("descendants"),f=R?[]:null,l=e(o,[{key:m,type:s}],u??null,R?a=>{f.push(a)}:a=>{f=a[0]?.[s]},n,()=>{try{t(R?f.flat():f)}catch(a){n(a)}},a=>{a>0&&(l(),n(new C))});return l})};var V=r=>e=>e.length>0?new Promise((t,n)=>{r(b.unpin,[e],{onSuccess(){t()},onError:n})}):Promise.resolve();var S=class extends Error{constructor(){super("Client destroyed"),this.name="DestroyedError"}};function le(r){return r.operationId!==void 0}function $(r){return(e,t,n)=>{let o=W(),s=new Set,m=z(),u=m.promise,R=i=>{if(le(i))return o.has(i.operationId)||console.warn("Uknown operationId on",i),o.next(i.operationId,i);if(i.event!=="stop"){if(i.event==="initialized")return t({type:i.event,finalizedBlockHashes:"finalizedBlockHash"in i?[i.finalizedBlockHash]:i.finalizedBlockHashes,finalizedBlockRuntime:i.finalizedBlockRuntime});let{event:g,...h}=i;return t({type:g,...h})}n(new P),a(!1)},f=i=>{n(i),a(!(i instanceof S))},p=(i,g)=>{let h=g(i,{next:R,error:f});a=(d=!0)=>{u=null,a=y,h(),d&&r(b.unfollow,[i]),o.errorAll(new w),s.forEach(E=>{E()}),s.clear()},u=i,m.res(i)},l=i=>{i instanceof S?a(!1):n(i),u=null,m.res(i)},a=r(b.follow,[e],{onSuccess:p,onError:l}),c=(i,g,h)=>{let d=()=>{h?.onError(new w)};if(u===null)return d(),y;let E=T=>{if(!h)return r(i,[T,...g]);s.add(d);let _=(q,J)=>u===null?(J.error(new w),y):(o.subscribe(q,J),()=>{o.unsubscribe(q)}),re=r(i,[T,...g],{onSuccess:q=>{s.delete(d),h.onSuccess(q,_)},onError:q=>{s.delete(d),h.onError(q)}});return()=>{s.delete(d),re()}};if(typeof u=="string")return E(u);let D=y;return u.then(T=>{if(T instanceof Error)return d();u&&(D=E(T))}),()=>{D()}};return{unfollow(){a(),u=null},body:N(c),call:G(c),header:K(c),storage:Q(c),storageSubscription:L(c),unpin:V(c),_request:c}}}var I=class extends Error{constructor(t){super(t.message);B(this,"code");B(this,"data");this.code=t.code,this.data=t.data,this.name="RpcError"}};var ue=1,X=r=>{let e=ue++,t=new Map,n=W(),o=null,s=(p,l,a)=>{o.send(JSON.stringify({jsonrpc:"2.0",id:p,method:l,params:a}))};function m(p){try{let l,a,c,i,g;if({id:l,result:a,error:c,params:i}=JSON.parse(p),l){let E=t.get(l);return E?(t.delete(l),c?E.onError(new I(c)):E.onSuccess(a,(D,T)=>{let _=D;return n.subscribe(_,T),()=>{n.unsubscribe(_)}})):void 0}if({subscription:g,result:a,error:c}=i,!g||!c&&!Object.hasOwn(i,"result"))throw 0;let d=g;c?n.error(d,new I(c)):n.next(d,a)}catch(l){console.warn("Error parsing incomming message: "+p),console.error(l)}}o=r(m);let u=()=>{o?.disconnect(),o=null,n.errorAll(new S),t.forEach(p=>p.onError(new S)),t.clear()},R=1;return{request:(p,l,a)=>{if(!o)throw new Error("Not connected");let c=`${e}-${R++}`;return a&&t.set(c,a),s(c,p,l),()=>{t.delete(c)}},disconnect:u}};var Y=r=>{let e=v((n,o,s,m)=>r(s,m,{onSuccess:n,onError:o})),t=null;return async()=>t||(t=Promise.all([e(F.chainName,[]),e(F.genesisHash,[]),e(F.properties,[])]).then(([n,o,s])=>({name:n,genesisHash:o,properties:s})))};var Z=(r,e)=>t=>{let n={},o=null;return(s,...m)=>{if(o)return o(s,...m);let u=!0,R=()=>{u=!1};return r.then(f=>{if(o=(l,...a)=>{let c=n[l]??l;return f.has(c)?e(c,...a):(a[1]?.onError(new Error(`Unsupported method ${c}`)),y)},f.has(s))return;let p=s.split("_");if(p[1]==="v1"){if(p[1]="unstable",f.has(p.join("_")))Object.values(t).forEach(l=>{n[l]=l.replace("_v1_","_unstable_")});else if(p[0]==="transaction"){let l,a,c=["transactionWatch","transaction"].find(i=>(a=["v1","unstable"].find(g=>f.has(l=`${i}_${g}_unwatch`)),!!a));c&&(n[t.broadcast]=`${c}_${a}_submitAndWatch`,n[t.stop]=l)}}}).then(()=>{u&&(R=o(s,...m))}),()=>{R()}}};var ee=require("@polkadot-api/utils"),me=r=>{let e=X(r),t=v((s,m,u,R)=>e.request(u,R,{onSuccess:s,onError:m})),n=t("rpc_methods",[]).then(s=>new Set(Array.isArray(s)?s:s.methods),()=>new Set),o=Z(n,e.request);return{chainHead:$(o(b)),transaction:M(o(A)),getChainSpecData:Y(o(F)),destroy:()=>{e.disconnect()},request:t,_request:e.request}};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/min/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/internal-utils/abortablePromiseFn.ts","../../src/internal-utils/deferred-promise.ts","../../src/internal-utils/noop.ts","../../src/internal-utils/subscriptions-manager.ts","../../src/methods.ts","../../src/transaction/transaction.ts","../../src/chainhead/errors.ts","../../src/chainhead/operation-promise.ts","../../src/chainhead/body.ts","../../src/chainhead/call.ts","../../src/chainhead/header.ts","../../src/chainhead/storage-subscription.ts","../../src/chainhead/storage.ts","../../src/chainhead/unpin.ts","../../src/client/DestroyedError.ts","../../src/chainhead/chainhead.ts","../../src/client/RpcError.ts","../../src/client/createClient.ts","../../src/chainspec.ts","../../src/request-compatibility-enhancer.ts"],"sourcesContent":["import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport {\n ClientRequest,\n ClientRequestCb,\n createClient as createRawClient,\n} from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\nimport { getCompatibilityEnhancer } from \"./request-compatibility-enhancer\"\nimport { chainHead, chainSpec, transaction } from \"./methods\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\nexport type * from \"./chainspec\"\n\nexport { RpcError, DestroyedError } from \"./client\"\nexport {\n StopError,\n DisjointError,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./chainhead\"\n\nexport interface SubstrateClient {\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const client = createRawClient(provider)\n\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => client.request(method, params, { onSuccess, onError }),\n )\n\n const rpcMethods: Promise<Set<string>> = request<\n { methods: Array<string> } | Array<string>\n >(\"rpc_methods\", []).then(\n (x) => new Set(Array.isArray(x) ? x : x.methods),\n () => new Set(),\n )\n\n const compatibilityEnhancer = getCompatibilityEnhancer(\n rpcMethods,\n client.request,\n )\n\n return {\n chainHead: getChainHead(\n compatibilityEnhancer(chainHead) as ClientRequest<any, any>,\n ),\n transaction: getTransaction(\n compatibilityEnhancer(transaction) as ClientRequest<string, any>,\n ),\n getChainSpecData: createGetChainSpec(\n compatibilityEnhancer(chainSpec) as ClientRequest<any, any>,\n ),\n destroy: () => {\n client.disconnect()\n },\n request,\n _request: client.request,\n }\n}\n","import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","export const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nexport const chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nexport const transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nexport const transactionWatch = {\n submitAndWatch: \"\",\n unwatch: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { transaction } from \"@/methods\"\n\nexport const getTransaction =\n (request: ClientRequest<string, any>) =>\n (tx: string, error: (e: Error) => void) => {\n let cancel = request(transaction.broadcast, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(transaction.stop, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(new Error(\"Max # of broadcasted transactions has been reached\"))\n }\n },\n onError: error,\n })\n\n return () => {\n cancel()\n }\n }\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n const [requestArgs, logicCb] = factory(...args)\n request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\")\n return rej(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n let done = noop\n const _res = (x: O) => {\n isRunning = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isRunning = false\n done()\n rej(x)\n }\n\n done = followSubscription(operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\")\n rej(new OperationError(_e.error))\n else if (_e.event === \"operationInaccessible\")\n rej(new OperationInaccessibleError())\n else logicCb(e as I, _res, _rej)\n },\n error: _rej,\n })\n\n cancel = () => {\n if (isRunning) {\n done()\n stopOperation()\n }\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import { chainHead } from \"@/methods\"\nimport type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n chainHead.body,\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n chainHead.call,\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(chainHead.header, [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport {\n ClientInnerRequest,\n FollowResponse,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"..\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n request(chainHead.storage, [hash, inputs, childTrie], {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(chainHead.continue, [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(chainHead.stopOperation, [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { ClientInnerRequest, FollowResponse, OperationLimitError } from \"..\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(chainHead.unpin, [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes:\n \"finalizedBlockHash\" in event\n ? [event.finalizedBlockHash]\n : event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (opaqueId, subscriber) => {\n const subscriptionId = opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n","import { ClientRequest } from \"./client\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { chainSpec } from \"./methods\"\n\nexport interface ChainSpecData {\n name: string\n genesisHash: string\n properties: any\n}\n\nexport const createGetChainSpec = (clientRequest: ClientRequest<any, any>) => {\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => clientRequest(method, params, { onSuccess, onError }),\n )\n let cachedPromise: null | Promise<ChainSpecData> = null\n\n return async (): Promise<ChainSpecData> => {\n if (cachedPromise) return cachedPromise\n return (cachedPromise = Promise.all([\n request<string>(chainSpec.chainName, []),\n request<string>(chainSpec.genesisHash, []),\n request<any>(chainSpec.properties, []),\n ]).then(([name, genesisHash, properties]) => ({\n name,\n genesisHash,\n properties,\n })))\n }\n}\n","import type { ClientRequest } from \"@/client\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { noop } from \"./internal-utils\"\n\nexport const getCompatibilityEnhancer =\n <T, E>(rpcMethodsP: Promise<Set<string>>, request: ClientRequest<T, E>) =>\n (methods: Record<string, string>): ClientRequest<T, E> => {\n let translations: Record<string, string> = {}\n let enhancedRequest: ClientRequest<T, E> | null = null\n\n return ((method, ...rest) => {\n if (enhancedRequest) return enhancedRequest(method, ...rest)\n\n let isRunning = true\n let cleanup: UnsubscribeFn = () => {\n isRunning = false\n }\n\n rpcMethodsP\n .then((rpcMethods) => {\n enhancedRequest = (method_, ...iRest) => {\n const method = translations[method_] ?? method_\n if (rpcMethods.has(method)) return request(method, ...iRest)\n iRest[1]?.onError(new Error(`Unsupported method ${method}`))\n return noop\n }\n\n if (rpcMethods.has(method)) return\n\n const parts = method.split(\"_\")\n if (parts[1] !== \"v1\") return\n\n parts[1] = \"unstable\"\n\n if (rpcMethods.has(parts.join(\"_\")))\n Object.values(methods).forEach((value) => {\n translations[value] = value.replace(\"_v1_\", \"_unstable_\")\n })\n else if (parts[0] === \"transaction\") {\n // old versions of smoldot and Polkadot-SDK don't support transaction_xx_broadcast\n // some old versions have `transactions_unstable_submitAndWatch` while others have `transaction_xx_submitAndWatch`\n // if we find any of this options, then we will can use them as if they were broadast/stop\n let unwatch: string | undefined\n let version: string | undefined\n\n const txGroup = [\"transactionWatch\", \"transaction\"].find(\n (group) => {\n version = [\"v1\", \"unstable\"].find((v) =>\n rpcMethods.has((unwatch = `${group}_${v}_unwatch`)),\n )\n return !!version\n },\n )\n\n if (txGroup) {\n translations[methods.broadcast] =\n `${txGroup}_${version}_submitAndWatch`\n translations[methods.stop] = unwatch!\n }\n }\n })\n .then(() => {\n if (isRunning) cleanup = enhancedRequest!(method, ...rest)\n })\n\n return () => {\n cleanup()\n }\n }) as ClientRequest<T, E>\n }\n"],"mappings":"ikBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,oBAAAE,EAAA,kBAAAC,EAAA,mBAAA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Y,CAC1D,CAAC,UACMD,EAAM,CAAC,IAAM,cAAe,CAInC,IAAIE,EACAC,EAEEC,EAAU,CAAC,mBAAoB,aAAa,EAAE,KACjDC,IACCF,EAAU,CAAC,KAAM,UAAU,EAAE,KAAMG,GACjCV,EAAW,IAAKM,EAAU,GAAGG,CAAK,IAAIC,CAAC,UAAW,CACpD,EACO,CAAC,CAACH,EAEb,EAEIC,IACFd,EAAaD,EAAQ,SAAS,EAC5B,GAAGe,CAAO,IAAID,CAAO,kBACvBb,EAAaD,EAAQ,IAAI,EAAIa,EAEjC,EACF,CAAC,EACA,KAAK,IAAM,CACNR,IAAWC,EAAUJ,EAAiBC,EAAQ,GAAGC,CAAI,EAC3D,CAAC,EAEI,IAAM,CACXE,EAAQ,CACV,CACF,CACF,EpBrBK,IAAMY,GAAgBC,GAA+C,CAC1E,IAAMC,EAASF,EAAgBC,CAAQ,EAEjCE,EAAUC,EACd,CACEC,EACAC,EACAC,EACAC,IACGN,EAAO,QAAQK,EAAQC,EAAQ,CAAE,UAAAH,EAAW,QAAAC,CAAQ,CAAC,CAC5D,EAEMG,EAAmCN,EAEvC,cAAe,CAAC,CAAC,EAAE,KAClBO,GAAM,IAAI,IAAI,MAAM,QAAQA,CAAC,EAAIA,EAAIA,EAAE,OAAO,EAC/C,IAAM,IAAI,GACZ,EAEMC,EAAwBC,EAC5BH,EACAP,EAAO,OACT,EAEA,MAAO,CACL,UAAWW,EACTF,EAAsBG,CAAS,CACjC,EACA,YAAaC,EACXJ,EAAsBK,CAAW,CACnC,EACA,iBAAkBC,EAChBN,EAAsBO,CAAS,CACjC,EACA,QAAS,IAAM,CACbhB,EAAO,WAAW,CACpB,EACA,QAAAC,EACA,SAAUD,EAAO,OACnB,CACF","names":["src_exports","__export","DestroyedError","DisjointError","OperationError","OperationInaccessibleError","OperationLimitError","RpcError","StopError","createClient","__toCommonJS","import_utils","abortablePromiseFn","fn","args","res","rej","cancel","actualArgs","abortSignal","onAbort","withCleanup","x","deferred","res","rej","_res","_rej","noop","getSubscriptionsManager","subscriptions","id","subscriber","data","e","subscribers","s","chainHead","chainSpec","transaction","transactionWatch","fnGroupName","methods","methodName","getTransaction","request","tx","error","cancel","transaction","subscriptionId","noop","StopError","DisjointError","OperationLimitError","OperationError","error","OperationInaccessibleError","createOperationPromise","operationName","factory","request","abortablePromiseFn","res","rej","args","isRunning","cancel","requestArgs","logicCb","response","followSubscription","OperationLimitError","operationId","stopOperation","chainHead","done","noop","_res","x","_rej","e","_e","OperationError","OperationInaccessibleError","createBodyFn","createOperationPromise","chainHead","hash","res","createCallFn","createOperationPromise","chainHead","hash","fnName","callParameters","e","res","createHeaderFn","request","hash","res","rej","chainHead","import_utils","createStorageCb","request","hash","inputs","childTrie","onItems","onError","onDone","onDiscardedItems","isRunning","cancel","chainHead","response","followSubscription","OperationLimitError","operationId","stopOperation","doneListening","event","_onDone","_onError","OperationError","OperationInaccessibleError","e","createStorageFn","request","cbStore","createStorageCb","abortablePromiseFn","resolve","reject","hash","type","key","childTrie","isDescendants","result","cancel","items","e","nDiscarded","OperationLimitError","createUnpinFn","request","hashes","res","rej","chainHead","DestroyedError","isOperationEvent","event","getChainHead","request","withRuntime","onFollowEvent","onFollowError","subscriptions","getSubscriptionsManager","ongoingRequests","deferredFollow","deferred","followSubscription","onAllFollowEventsNext","type","rest","StopError","unfollow","onAllFollowEventsError","error","DestroyedError","onFollowRequestSuccess","subscriptionId","follow","done","sendUnfollow","noop","chainHead","DisjointError","cb","onFollowRequestError","e","fRequest","method","params","disjoint","onSubscription","subscription","onSubscribeOperation","operationId","subscriber","cleanup","response","onCancel","x","createBodyFn","createCallFn","createHeaderFn","createStorageFn","createStorageCb","createUnpinFn","RpcError","e","__publicField","nextClientId","createClient","gProvider","clientId","responses","subscriptions","getSubscriptionsManager","connection","send","id","method","params","onMessage","message","result","error","subscription","cb","RpcError","opaqueId","subscriber","subscriptionId","e","disconnect","DestroyedError","r","nextId","createGetChainSpec","clientRequest","request","abortablePromiseFn","onSuccess","onError","method","params","cachedPromise","chainSpec","name","genesisHash","properties","getCompatibilityEnhancer","rpcMethodsP","request","methods","translations","enhancedRequest","method","rest","isRunning","cleanup","rpcMethods","method_","iRest","noop","parts","value","unwatch","version","txGroup","group","v","createClient","provider","client","request","abortablePromiseFn","onSuccess","onError","method","params","rpcMethods","x","compatibilityEnhancer","getCompatibilityEnhancer","getChainHead","chainHead","getTransaction","transaction","createGetChainSpec","chainSpec"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/internal-utils/abortablePromiseFn.ts","../../src/internal-utils/deferred-promise.ts","../../src/internal-utils/noop.ts","../../src/internal-utils/subscriptions-manager.ts","../../src/methods.ts","../../src/transaction/transaction.ts","../../src/chainhead/errors.ts","../../src/chainhead/operation-promise.ts","../../src/chainhead/body.ts","../../src/chainhead/call.ts","../../src/chainhead/header.ts","../../src/chainhead/storage-subscription.ts","../../src/chainhead/storage.ts","../../src/chainhead/unpin.ts","../../src/client/DestroyedError.ts","../../src/chainhead/chainhead.ts","../../src/client/RpcError.ts","../../src/client/createClient.ts","../../src/chainspec.ts","../../src/request-compatibility-enhancer.ts"],"sourcesContent":["import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport {\n ClientRequest,\n ClientRequestCb,\n createClient as createRawClient,\n} from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\nimport { getCompatibilityEnhancer } from \"./request-compatibility-enhancer\"\nimport { chainHead, chainSpec, transaction } from \"./methods\"\n\nexport { AbortError } from \"@polkadot-api/utils\"\nexport type * from \"@polkadot-api/json-rpc-provider\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\nexport type * from \"./chainspec\"\n\nexport { RpcError, DestroyedError } from \"./client\"\nexport {\n StopError,\n DisjointError,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./chainhead\"\n\nexport interface SubstrateClient {\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const client = createRawClient(provider)\n\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => client.request(method, params, { onSuccess, onError }),\n )\n\n const rpcMethods: Promise<Set<string>> = request<\n { methods: Array<string> } | Array<string>\n >(\"rpc_methods\", []).then(\n (x) => new Set(Array.isArray(x) ? x : x.methods),\n () => new Set(),\n )\n\n const compatibilityEnhancer = getCompatibilityEnhancer(\n rpcMethods,\n client.request,\n )\n\n return {\n chainHead: getChainHead(\n compatibilityEnhancer(chainHead) as ClientRequest<any, any>,\n ),\n transaction: getTransaction(\n compatibilityEnhancer(transaction) as ClientRequest<string, any>,\n ),\n getChainSpecData: createGetChainSpec(\n compatibilityEnhancer(chainSpec) as ClientRequest<any, any>,\n ),\n destroy: () => {\n client.disconnect()\n },\n request,\n _request: client.request,\n }\n}\n","import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","export const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nexport const chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nexport const transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nexport const transactionWatch = {\n submitAndWatch: \"\",\n unwatch: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { transaction } from \"@/methods\"\n\nexport const getTransaction =\n (request: ClientRequest<string, any>) =>\n (tx: string, error: (e: Error) => void) => {\n let cancel = request(transaction.broadcast, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(transaction.stop, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(new Error(\"Max # of broadcasted transactions has been reached\"))\n }\n },\n onError: error,\n })\n\n return () => {\n cancel()\n }\n }\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n const [requestArgs, logicCb] = factory(...args)\n request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\")\n return rej(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n let done = noop\n const _res = (x: O) => {\n isRunning = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isRunning = false\n done()\n rej(x)\n }\n\n done = followSubscription(operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\")\n rej(new OperationError(_e.error))\n else if (_e.event === \"operationInaccessible\")\n rej(new OperationInaccessibleError())\n else logicCb(e as I, _res, _rej)\n },\n error: _rej,\n })\n\n cancel = () => {\n if (isRunning) {\n done()\n stopOperation()\n }\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import { chainHead } from \"@/methods\"\nimport type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n chainHead.body,\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n chainHead.call,\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(chainHead.header, [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport {\n ClientInnerRequest,\n FollowResponse,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"..\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n request(chainHead.storage, [hash, inputs, childTrie], {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(chainHead.continue, [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(chainHead.stopOperation, [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { ClientInnerRequest, FollowResponse, OperationLimitError } from \"..\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(chainHead.unpin, [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes:\n \"finalizedBlockHash\" in event\n ? [event.finalizedBlockHash]\n : event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import type {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (opaqueId, subscriber) => {\n const subscriptionId = opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n","import { ClientRequest } from \"./client\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { chainSpec } from \"./methods\"\n\nexport interface ChainSpecData {\n name: string\n genesisHash: string\n properties: any\n}\n\nexport const createGetChainSpec = (clientRequest: ClientRequest<any, any>) => {\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => clientRequest(method, params, { onSuccess, onError }),\n )\n let cachedPromise: null | Promise<ChainSpecData> = null\n\n return async (): Promise<ChainSpecData> => {\n if (cachedPromise) return cachedPromise\n return (cachedPromise = Promise.all([\n request<string>(chainSpec.chainName, []),\n request<string>(chainSpec.genesisHash, []),\n request<any>(chainSpec.properties, []),\n ]).then(([name, genesisHash, properties]) => ({\n name,\n genesisHash,\n properties,\n })))\n }\n}\n","import type { ClientRequest } from \"@/client\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { noop } from \"./internal-utils\"\n\nexport const getCompatibilityEnhancer =\n <T, E>(rpcMethodsP: Promise<Set<string>>, request: ClientRequest<T, E>) =>\n (methods: Record<string, string>): ClientRequest<T, E> => {\n let translations: Record<string, string> = {}\n let enhancedRequest: ClientRequest<T, E> | null = null\n\n return ((method, ...rest) => {\n if (enhancedRequest) return enhancedRequest(method, ...rest)\n\n let isRunning = true\n let cleanup: UnsubscribeFn = () => {\n isRunning = false\n }\n\n rpcMethodsP\n .then((rpcMethods) => {\n enhancedRequest = (method_, ...iRest) => {\n const method = translations[method_] ?? method_\n if (rpcMethods.has(method)) return request(method, ...iRest)\n iRest[1]?.onError(new Error(`Unsupported method ${method}`))\n return noop\n }\n\n if (rpcMethods.has(method)) return\n\n const parts = method.split(\"_\")\n if (parts[1] !== \"v1\") return\n\n parts[1] = \"unstable\"\n\n if (rpcMethods.has(parts.join(\"_\")))\n Object.values(methods).forEach((value) => {\n translations[value] = value.replace(\"_v1_\", \"_unstable_\")\n })\n else if (parts[0] === \"transaction\") {\n // old versions of smoldot and Polkadot-SDK don't support transaction_xx_broadcast\n // some old versions have `transactions_unstable_submitAndWatch` while others have `transaction_xx_submitAndWatch`\n // if we find any of this options, then we will can use them as if they were broadast/stop\n let unwatch: string | undefined\n let version: string | undefined\n\n const txGroup = [\"transactionWatch\", \"transaction\"].find(\n (group) => {\n version = [\"v1\", \"unstable\"].find((v) =>\n rpcMethods.has((unwatch = `${group}_${v}_unwatch`)),\n )\n return !!version\n },\n )\n\n if (txGroup) {\n translations[methods.broadcast] =\n `${txGroup}_${version}_submitAndWatch`\n translations[methods.stop] = unwatch!\n }\n }\n })\n .then(() => {\n if (isRunning) cleanup = enhancedRequest!(method, ...rest)\n })\n\n return () => {\n cleanup()\n }\n }) as ClientRequest<T, E>\n }\n"],"mappings":"6jBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,iDAAAE,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,+BAAAC,EAAA,wBAAAC,EAAA,aAAAC,EAAA,cAAAC,EAAA,iBAAAC,KAAA,eAAAC,GAAAV,ICAA,IAAAW,EAAiC,+BAGpBC,EAETC,GAIF,IAAIC,IACF,IAAI,QAAQ,CAACC,EAAKC,IAAQ,CACxB,IAAIC,EAAS,OAEP,CAACC,EAAYC,CAAW,EAC5BL,EAAKA,EAAK,OAAS,CAAC,YAAa,YAC5B,CAACA,EAAK,MAAM,EAAGA,EAAK,OAAS,CAAC,EAAGA,EAAKA,EAAK,OAAS,CAAC,CAAC,EAItD,CAACA,CAAI,EAENM,EAAU,IAAM,CACpBH,EAAO,EACPD,EAAI,IAAI,YAAY,CACtB,EAEAG,GAAa,iBAAiB,QAASC,EAAS,CAAE,KAAM,EAAK,CAAC,EAE9D,IAAMC,EACAR,GACHS,GAAM,CACLL,EAAS,OACTE,GAAa,oBAAoB,QAASC,CAAO,EACjDP,EAAGS,CAAC,CACN,EAEFL,EAASJ,EAAOQ,EAAYN,CAAG,EAAGM,EAAYL,CAAG,EAAG,GAAGE,CAAW,CACpE,CAAC,EC/BE,SAASK,GAAkC,CAChD,IAAIC,EAA0B,IAAM,CAAC,EACjCC,EAA4B,IAAM,CAAC,EAOvC,MAAO,CAAE,QALO,IAAI,QAAW,CAACC,EAAMC,IAAS,CAC7CH,EAAME,EACND,EAAME,CACR,CAAC,EAEiB,IAAAH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,EAAO,OACT,EAEA,MAAO,CACL,UAAWW,EACTF,EAAsBG,CAAS,CACjC,EACA,YAAaC,EACXJ,EAAsBK,CAAW,CACnC,EACA,iBAAkBC,EAChBN,EAAsBO,CAAS,CACjC,EACA,QAAS,IAAM,CACbhB,EAAO,WAAW,CACpB,EACA,QAAAC,EACA,SAAUD,EAAO,OACnB,CACF","names":["src_exports","__export","DestroyedError","DisjointError","OperationError","OperationInaccessibleError","OperationLimitError","RpcError","StopError","createClient","__toCommonJS","import_utils","abortablePromiseFn","fn","args","res","rej","cancel","actualArgs","abortSignal","onAbort","withCleanup","x","deferred","res","rej","_res","_rej","noop","getSubscriptionsManager","subscriptions","id","subscriber","data","e","subscribers","s","chainHead","chainSpec","transaction","transactionWatch","fnGroupName","methods","methodName","getTransaction","request","tx","error","cancel","transaction","subscriptionId","noop","StopError","DisjointError","OperationLimitError","OperationError","error","OperationInaccessibleError","createOperationPromise","operationName","factory","request","abortablePromiseFn","res","rej","args","isRunning","cancel","requestArgs","logicCb","response","followSubscription","OperationLimitError","operationId","stopOperation","chainHead","done","noop","_res","x","_rej","e","_e","OperationError","OperationInaccessibleError","createBodyFn","createOperationPromise","chainHead","hash","res","createCallFn","createOperationPromise","chainHead","hash","fnName","callParameters","e","res","createHeaderFn","request","hash","res","rej","chainHead","import_utils","createStorageCb","request","hash","inputs","childTrie","onItems","onError","onDone","onDiscardedItems","isRunning","cancel","chainHead","response","followSubscription","OperationLimitError","operationId","stopOperation","doneListening","event","_onDone","_onError","OperationError","OperationInaccessibleError","e","createStorageFn","request","cbStore","createStorageCb","abortablePromiseFn","resolve","reject","hash","type","key","childTrie","isDescendants","result","cancel","items","e","nDiscarded","OperationLimitError","createUnpinFn","request","hashes","res","rej","chainHead","DestroyedError","isOperationEvent","event","getChainHead","request","withRuntime","onFollowEvent","onFollowError","subscriptions","getSubscriptionsManager","ongoingRequests","deferredFollow","deferred","followSubscription","onAllFollowEventsNext","type","rest","StopError","unfollow","onAllFollowEventsError","error","DestroyedError","onFollowRequestSuccess","subscriptionId","follow","done","sendUnfollow","noop","chainHead","DisjointError","cb","onFollowRequestError","e","fRequest","method","params","disjoint","onSubscription","subscription","onSubscribeOperation","operationId","subscriber","cleanup","response","onCancel","x","createBodyFn","createCallFn","createHeaderFn","createStorageFn","createStorageCb","createUnpinFn","RpcError","e","__publicField","nextClientId","createClient","gProvider","clientId","responses","subscriptions","getSubscriptionsManager","connection","send","id","method","params","onMessage","message","result","error","subscription","cb","RpcError","opaqueId","subscriber","subscriptionId","e","disconnect","DestroyedError","r","nextId","createGetChainSpec","clientRequest","request","abortablePromiseFn","onSuccess","onError","method","params","cachedPromise","chainSpec","name","genesisHash","properties","getCompatibilityEnhancer","rpcMethodsP","request","methods","translations","enhancedRequest","method","rest","isRunning","cleanup","rpcMethods","method_","iRest","noop","parts","value","unwatch","version","txGroup","group","v","import_utils","createClient","provider","client","request","abortablePromiseFn","onSuccess","onError","method","params","rpcMethods","x","compatibilityEnhancer","getCompatibilityEnhancer","getChainHead","chainHead","getTransaction","transaction","createGetChainSpec","chainSpec"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polkadot-api/substrate-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
|
-
"
|
|
38
|
-
"@polkadot-api/
|
|
39
|
-
"@polkadot-api/
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@polkadot-api/utils": "0.1.0",
|
|
39
|
+
"@polkadot-api/json-rpc-provider": "0.0.1"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"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",
|