@polkadot-api/substrate-client 0.1.1 → 0.1.3
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.js +45 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -48
- package/dist/index.mjs.map +1 -1
- package/dist/min/index.js +1 -1
- package/dist/min/index.js.map +1 -1
- package/package.json +4 -7
package/dist/index.js
CHANGED
|
@@ -17,10 +17,7 @@ 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 = {};
|
|
@@ -189,43 +186,47 @@ var OperationInaccessibleError = class extends Error {
|
|
|
189
186
|
|
|
190
187
|
// src/chainhead/operation-promise.ts
|
|
191
188
|
var createOperationPromise = (operationName, factory) => (request) => abortablePromiseFn((res, rej, ...args) => {
|
|
189
|
+
let isRunning = true;
|
|
190
|
+
let cancel = () => {
|
|
191
|
+
isRunning = false;
|
|
192
|
+
};
|
|
192
193
|
const [requestArgs, logicCb] = factory(...args);
|
|
193
|
-
|
|
194
|
+
request(operationName, requestArgs, {
|
|
194
195
|
onSuccess: (response, followSubscription) => {
|
|
195
|
-
if (response.result === "limitReached")
|
|
196
|
-
cancel = noop2;
|
|
196
|
+
if (response.result === "limitReached")
|
|
197
197
|
return rej(new OperationLimitError());
|
|
198
|
-
}
|
|
199
|
-
|
|
198
|
+
const { operationId } = response;
|
|
199
|
+
const stopOperation = () => {
|
|
200
|
+
request(chainHead.stopOperation, [operationId]);
|
|
201
|
+
};
|
|
202
|
+
if (!isRunning) return stopOperation();
|
|
200
203
|
let done = noop2;
|
|
201
204
|
const _res = (x) => {
|
|
202
|
-
|
|
205
|
+
isRunning = false;
|
|
203
206
|
done();
|
|
204
207
|
res(x);
|
|
205
208
|
};
|
|
206
209
|
const _rej = (x) => {
|
|
207
|
-
|
|
210
|
+
isRunning = false;
|
|
208
211
|
done();
|
|
209
212
|
rej(x);
|
|
210
213
|
};
|
|
211
|
-
done = followSubscription(
|
|
214
|
+
done = followSubscription(operationId, {
|
|
212
215
|
next: (e) => {
|
|
213
216
|
const _e = e;
|
|
214
|
-
if (_e.event === "operationError")
|
|
217
|
+
if (_e.event === "operationError")
|
|
215
218
|
rej(new OperationError(_e.error));
|
|
216
|
-
|
|
219
|
+
else if (_e.event === "operationInaccessible")
|
|
217
220
|
rej(new OperationInaccessibleError());
|
|
218
|
-
|
|
219
|
-
logicCb(e, _res, _rej);
|
|
220
|
-
}
|
|
221
|
+
else logicCb(e, _res, _rej);
|
|
221
222
|
},
|
|
222
223
|
error: _rej
|
|
223
224
|
});
|
|
224
225
|
cancel = () => {
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
if (isRunning) {
|
|
227
|
+
done();
|
|
228
|
+
stopOperation();
|
|
229
|
+
}
|
|
229
230
|
};
|
|
230
231
|
},
|
|
231
232
|
onError: rej
|
|
@@ -272,10 +273,19 @@ var createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, o
|
|
|
272
273
|
onDone();
|
|
273
274
|
return import_utils2.noop;
|
|
274
275
|
}
|
|
275
|
-
let
|
|
276
|
+
let isRunning = true;
|
|
277
|
+
let cancel = () => {
|
|
278
|
+
isRunning = false;
|
|
279
|
+
};
|
|
280
|
+
request(chainHead.storage, [hash, inputs, childTrie], {
|
|
276
281
|
onSuccess: (response, followSubscription) => {
|
|
277
282
|
if (response.result === "limitReached" || response.discardedItems === inputs.length)
|
|
278
283
|
return onError(new OperationLimitError());
|
|
284
|
+
const { operationId } = response;
|
|
285
|
+
const stopOperation = () => {
|
|
286
|
+
request(chainHead.stopOperation, [operationId]);
|
|
287
|
+
};
|
|
288
|
+
if (!isRunning) return stopOperation();
|
|
279
289
|
const doneListening = followSubscription(response.operationId, {
|
|
280
290
|
next: (event) => {
|
|
281
291
|
switch (event.event) {
|
|
@@ -453,8 +463,7 @@ function getChainHead(request) {
|
|
|
453
463
|
return noop2;
|
|
454
464
|
}
|
|
455
465
|
const onSubscription = (subscription) => {
|
|
456
|
-
if (!cb)
|
|
457
|
-
return request(method, [subscription, ...params]);
|
|
466
|
+
if (!cb) return request(method, [subscription, ...params]);
|
|
458
467
|
ongoingRequests.add(disjoint);
|
|
459
468
|
const onSubscribeOperation = (operationId, subscriber) => {
|
|
460
469
|
if (followSubscription === null) {
|
|
@@ -485,10 +494,8 @@ function getChainHead(request) {
|
|
|
485
494
|
return onSubscription(followSubscription);
|
|
486
495
|
let onCancel = noop2;
|
|
487
496
|
followSubscription.then((x) => {
|
|
488
|
-
if (x instanceof Error)
|
|
489
|
-
|
|
490
|
-
if (followSubscription)
|
|
491
|
-
onCancel = onSubscription(x);
|
|
497
|
+
if (x instanceof Error) return disjoint();
|
|
498
|
+
if (followSubscription) onCancel = onSubscription(x);
|
|
492
499
|
});
|
|
493
500
|
return () => {
|
|
494
501
|
onCancel();
|
|
@@ -546,8 +553,7 @@ var createClient = (gProvider) => {
|
|
|
546
553
|
({ id, result, error, params } = parsed);
|
|
547
554
|
if (id) {
|
|
548
555
|
const cb = responses.get(id);
|
|
549
|
-
if (!cb)
|
|
550
|
-
return;
|
|
556
|
+
if (!cb) return;
|
|
551
557
|
responses.delete(id);
|
|
552
558
|
return error ? cb.onError(new RpcError(error)) : cb.onSuccess(result, (opaqueId, subscriber) => {
|
|
553
559
|
const subscriptionId2 = opaqueId;
|
|
@@ -559,8 +565,7 @@ var createClient = (gProvider) => {
|
|
|
559
565
|
}
|
|
560
566
|
;
|
|
561
567
|
({ subscription, result, error } = params);
|
|
562
|
-
if (!subscription || !error && !Object.hasOwn(params, "result"))
|
|
563
|
-
throw 0;
|
|
568
|
+
if (!subscription || !error && !Object.hasOwn(params, "result")) throw 0;
|
|
564
569
|
const subscriptionId = subscription;
|
|
565
570
|
if (error) {
|
|
566
571
|
subscriptions.error(subscriptionId, new RpcError(error));
|
|
@@ -582,11 +587,9 @@ var createClient = (gProvider) => {
|
|
|
582
587
|
};
|
|
583
588
|
let nextId = 1;
|
|
584
589
|
const request = (method, params, cb) => {
|
|
585
|
-
if (!connection)
|
|
586
|
-
throw new Error("Not connected");
|
|
590
|
+
if (!connection) throw new Error("Not connected");
|
|
587
591
|
const id = `${clientId}-${nextId++}`;
|
|
588
|
-
if (cb)
|
|
589
|
-
responses.set(id, cb);
|
|
592
|
+
if (cb) responses.set(id, cb);
|
|
590
593
|
send(id, method, params);
|
|
591
594
|
return () => {
|
|
592
595
|
responses.delete(id);
|
|
@@ -605,8 +608,7 @@ var createGetChainSpec = (clientRequest) => {
|
|
|
605
608
|
);
|
|
606
609
|
let cachedPromise = null;
|
|
607
610
|
return async () => {
|
|
608
|
-
if (cachedPromise)
|
|
609
|
-
return cachedPromise;
|
|
611
|
+
if (cachedPromise) return cachedPromise;
|
|
610
612
|
return cachedPromise = Promise.all([
|
|
611
613
|
request(chainSpec.chainName, []),
|
|
612
614
|
request(chainSpec.genesisHash, []),
|
|
@@ -624,8 +626,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
624
626
|
let translations = {};
|
|
625
627
|
let enhancedRequest = null;
|
|
626
628
|
return (method, ...rest) => {
|
|
627
|
-
if (enhancedRequest)
|
|
628
|
-
return enhancedRequest(method, ...rest);
|
|
629
|
+
if (enhancedRequest) return enhancedRequest(method, ...rest);
|
|
629
630
|
let isRunning = true;
|
|
630
631
|
let cleanup = () => {
|
|
631
632
|
isRunning = false;
|
|
@@ -633,16 +634,13 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
633
634
|
rpcMethodsP.then((rpcMethods) => {
|
|
634
635
|
enhancedRequest = (method_, ...iRest) => {
|
|
635
636
|
const method2 = translations[method_] ?? method_;
|
|
636
|
-
if (rpcMethods.has(method2))
|
|
637
|
-
return request(method2, ...iRest);
|
|
637
|
+
if (rpcMethods.has(method2)) return request(method2, ...iRest);
|
|
638
638
|
iRest[1]?.onError(new Error(`Unsupported method ${method2}`));
|
|
639
639
|
return noop2;
|
|
640
640
|
};
|
|
641
|
-
if (rpcMethods.has(method))
|
|
642
|
-
return;
|
|
641
|
+
if (rpcMethods.has(method)) return;
|
|
643
642
|
const parts = method.split("_");
|
|
644
|
-
if (parts[1] !== "v1")
|
|
645
|
-
return;
|
|
643
|
+
if (parts[1] !== "v1") return;
|
|
646
644
|
parts[1] = "unstable";
|
|
647
645
|
if (rpcMethods.has(parts.join("_")))
|
|
648
646
|
Object.values(methods).forEach((value) => {
|
|
@@ -665,8 +663,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
665
663
|
}
|
|
666
664
|
}
|
|
667
665
|
}).then(() => {
|
|
668
|
-
if (isRunning)
|
|
669
|
-
cleanup = enhancedRequest(method, ...rest);
|
|
666
|
+
if (isRunning) cleanup = enhancedRequest(method, ...rest);
|
|
670
667
|
});
|
|
671
668
|
return () => {
|
|
672
669
|
cleanup();
|
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 const [requestArgs, logicCb] = factory(...args)\n let cancel = request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\") {\n cancel = noop\n return rej(new OperationLimitError())\n }\n\n let isOperationGoing = true\n let done = noop\n const _res = (x: O) => {\n isOperationGoing = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isOperationGoing = false\n done()\n rej(x)\n }\n\n done = followSubscription(response.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 {\n logicCb(e as I, _res, _rej)\n }\n },\n error: _rej,\n })\n\n cancel = () => {\n if (!isOperationGoing) return\n done()\n request(chainHead.stopOperation, [response.operationId])\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 cancel = 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 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;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AM;AACV,UAAI;AAAW,kBAAU,gBAAiB,QAAQ,GAAG,IAAI;AAAA,IAC3D,CAAC;AAEH,WAAO,MAAM;AACX,cAAQ;AAAA,IACV;AAAA,EACF;AACF;;;ApBrBK,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","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 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,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;AACp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;AAAA,EACnB;AACF;","names":["createClient","fn","noop","noop","noop","import_utils","noop","subscriptionId","method","noop","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";
|
|
@@ -158,43 +155,47 @@ var OperationInaccessibleError = class extends Error {
|
|
|
158
155
|
|
|
159
156
|
// src/chainhead/operation-promise.ts
|
|
160
157
|
var createOperationPromise = (operationName, factory) => (request) => abortablePromiseFn((res, rej, ...args) => {
|
|
158
|
+
let isRunning = true;
|
|
159
|
+
let cancel = () => {
|
|
160
|
+
isRunning = false;
|
|
161
|
+
};
|
|
161
162
|
const [requestArgs, logicCb] = factory(...args);
|
|
162
|
-
|
|
163
|
+
request(operationName, requestArgs, {
|
|
163
164
|
onSuccess: (response, followSubscription) => {
|
|
164
|
-
if (response.result === "limitReached")
|
|
165
|
-
cancel = noop2;
|
|
165
|
+
if (response.result === "limitReached")
|
|
166
166
|
return rej(new OperationLimitError());
|
|
167
|
-
}
|
|
168
|
-
|
|
167
|
+
const { operationId } = response;
|
|
168
|
+
const stopOperation = () => {
|
|
169
|
+
request(chainHead.stopOperation, [operationId]);
|
|
170
|
+
};
|
|
171
|
+
if (!isRunning) return stopOperation();
|
|
169
172
|
let done = noop2;
|
|
170
173
|
const _res = (x) => {
|
|
171
|
-
|
|
174
|
+
isRunning = false;
|
|
172
175
|
done();
|
|
173
176
|
res(x);
|
|
174
177
|
};
|
|
175
178
|
const _rej = (x) => {
|
|
176
|
-
|
|
179
|
+
isRunning = false;
|
|
177
180
|
done();
|
|
178
181
|
rej(x);
|
|
179
182
|
};
|
|
180
|
-
done = followSubscription(
|
|
183
|
+
done = followSubscription(operationId, {
|
|
181
184
|
next: (e) => {
|
|
182
185
|
const _e = e;
|
|
183
|
-
if (_e.event === "operationError")
|
|
186
|
+
if (_e.event === "operationError")
|
|
184
187
|
rej(new OperationError(_e.error));
|
|
185
|
-
|
|
188
|
+
else if (_e.event === "operationInaccessible")
|
|
186
189
|
rej(new OperationInaccessibleError());
|
|
187
|
-
|
|
188
|
-
logicCb(e, _res, _rej);
|
|
189
|
-
}
|
|
190
|
+
else logicCb(e, _res, _rej);
|
|
190
191
|
},
|
|
191
192
|
error: _rej
|
|
192
193
|
});
|
|
193
194
|
cancel = () => {
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
if (isRunning) {
|
|
196
|
+
done();
|
|
197
|
+
stopOperation();
|
|
198
|
+
}
|
|
198
199
|
};
|
|
199
200
|
},
|
|
200
201
|
onError: rej
|
|
@@ -241,10 +242,19 @@ var createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, o
|
|
|
241
242
|
onDone();
|
|
242
243
|
return noop3;
|
|
243
244
|
}
|
|
244
|
-
let
|
|
245
|
+
let isRunning = true;
|
|
246
|
+
let cancel = () => {
|
|
247
|
+
isRunning = false;
|
|
248
|
+
};
|
|
249
|
+
request(chainHead.storage, [hash, inputs, childTrie], {
|
|
245
250
|
onSuccess: (response, followSubscription) => {
|
|
246
251
|
if (response.result === "limitReached" || response.discardedItems === inputs.length)
|
|
247
252
|
return onError(new OperationLimitError());
|
|
253
|
+
const { operationId } = response;
|
|
254
|
+
const stopOperation = () => {
|
|
255
|
+
request(chainHead.stopOperation, [operationId]);
|
|
256
|
+
};
|
|
257
|
+
if (!isRunning) return stopOperation();
|
|
248
258
|
const doneListening = followSubscription(response.operationId, {
|
|
249
259
|
next: (event) => {
|
|
250
260
|
switch (event.event) {
|
|
@@ -422,8 +432,7 @@ function getChainHead(request) {
|
|
|
422
432
|
return noop2;
|
|
423
433
|
}
|
|
424
434
|
const onSubscription = (subscription) => {
|
|
425
|
-
if (!cb)
|
|
426
|
-
return request(method, [subscription, ...params]);
|
|
435
|
+
if (!cb) return request(method, [subscription, ...params]);
|
|
427
436
|
ongoingRequests.add(disjoint);
|
|
428
437
|
const onSubscribeOperation = (operationId, subscriber) => {
|
|
429
438
|
if (followSubscription === null) {
|
|
@@ -454,10 +463,8 @@ function getChainHead(request) {
|
|
|
454
463
|
return onSubscription(followSubscription);
|
|
455
464
|
let onCancel = noop2;
|
|
456
465
|
followSubscription.then((x) => {
|
|
457
|
-
if (x instanceof Error)
|
|
458
|
-
|
|
459
|
-
if (followSubscription)
|
|
460
|
-
onCancel = onSubscription(x);
|
|
466
|
+
if (x instanceof Error) return disjoint();
|
|
467
|
+
if (followSubscription) onCancel = onSubscription(x);
|
|
461
468
|
});
|
|
462
469
|
return () => {
|
|
463
470
|
onCancel();
|
|
@@ -515,8 +522,7 @@ var createClient = (gProvider) => {
|
|
|
515
522
|
({ id, result, error, params } = parsed);
|
|
516
523
|
if (id) {
|
|
517
524
|
const cb = responses.get(id);
|
|
518
|
-
if (!cb)
|
|
519
|
-
return;
|
|
525
|
+
if (!cb) return;
|
|
520
526
|
responses.delete(id);
|
|
521
527
|
return error ? cb.onError(new RpcError(error)) : cb.onSuccess(result, (opaqueId, subscriber) => {
|
|
522
528
|
const subscriptionId2 = opaqueId;
|
|
@@ -528,8 +534,7 @@ var createClient = (gProvider) => {
|
|
|
528
534
|
}
|
|
529
535
|
;
|
|
530
536
|
({ subscription, result, error } = params);
|
|
531
|
-
if (!subscription || !error && !Object.hasOwn(params, "result"))
|
|
532
|
-
throw 0;
|
|
537
|
+
if (!subscription || !error && !Object.hasOwn(params, "result")) throw 0;
|
|
533
538
|
const subscriptionId = subscription;
|
|
534
539
|
if (error) {
|
|
535
540
|
subscriptions.error(subscriptionId, new RpcError(error));
|
|
@@ -551,11 +556,9 @@ var createClient = (gProvider) => {
|
|
|
551
556
|
};
|
|
552
557
|
let nextId = 1;
|
|
553
558
|
const request = (method, params, cb) => {
|
|
554
|
-
if (!connection)
|
|
555
|
-
throw new Error("Not connected");
|
|
559
|
+
if (!connection) throw new Error("Not connected");
|
|
556
560
|
const id = `${clientId}-${nextId++}`;
|
|
557
|
-
if (cb)
|
|
558
|
-
responses.set(id, cb);
|
|
561
|
+
if (cb) responses.set(id, cb);
|
|
559
562
|
send(id, method, params);
|
|
560
563
|
return () => {
|
|
561
564
|
responses.delete(id);
|
|
@@ -574,8 +577,7 @@ var createGetChainSpec = (clientRequest) => {
|
|
|
574
577
|
);
|
|
575
578
|
let cachedPromise = null;
|
|
576
579
|
return async () => {
|
|
577
|
-
if (cachedPromise)
|
|
578
|
-
return cachedPromise;
|
|
580
|
+
if (cachedPromise) return cachedPromise;
|
|
579
581
|
return cachedPromise = Promise.all([
|
|
580
582
|
request(chainSpec.chainName, []),
|
|
581
583
|
request(chainSpec.genesisHash, []),
|
|
@@ -593,8 +595,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
593
595
|
let translations = {};
|
|
594
596
|
let enhancedRequest = null;
|
|
595
597
|
return (method, ...rest) => {
|
|
596
|
-
if (enhancedRequest)
|
|
597
|
-
return enhancedRequest(method, ...rest);
|
|
598
|
+
if (enhancedRequest) return enhancedRequest(method, ...rest);
|
|
598
599
|
let isRunning = true;
|
|
599
600
|
let cleanup = () => {
|
|
600
601
|
isRunning = false;
|
|
@@ -602,16 +603,13 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
602
603
|
rpcMethodsP.then((rpcMethods) => {
|
|
603
604
|
enhancedRequest = (method_, ...iRest) => {
|
|
604
605
|
const method2 = translations[method_] ?? method_;
|
|
605
|
-
if (rpcMethods.has(method2))
|
|
606
|
-
return request(method2, ...iRest);
|
|
606
|
+
if (rpcMethods.has(method2)) return request(method2, ...iRest);
|
|
607
607
|
iRest[1]?.onError(new Error(`Unsupported method ${method2}`));
|
|
608
608
|
return noop2;
|
|
609
609
|
};
|
|
610
|
-
if (rpcMethods.has(method))
|
|
611
|
-
return;
|
|
610
|
+
if (rpcMethods.has(method)) return;
|
|
612
611
|
const parts = method.split("_");
|
|
613
|
-
if (parts[1] !== "v1")
|
|
614
|
-
return;
|
|
612
|
+
if (parts[1] !== "v1") return;
|
|
615
613
|
parts[1] = "unstable";
|
|
616
614
|
if (rpcMethods.has(parts.join("_")))
|
|
617
615
|
Object.values(methods).forEach((value) => {
|
|
@@ -634,8 +632,7 @@ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
|
|
|
634
632
|
}
|
|
635
633
|
}
|
|
636
634
|
}).then(() => {
|
|
637
|
-
if (isRunning)
|
|
638
|
-
cleanup = enhancedRequest(method, ...rest);
|
|
635
|
+
if (isRunning) cleanup = enhancedRequest(method, ...rest);
|
|
639
636
|
});
|
|
640
637
|
return () => {
|
|
641
638
|
cleanup();
|
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 const [requestArgs, logicCb] = factory(...args)\n let cancel = request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\") {\n cancel = noop\n return rej(new OperationLimitError())\n }\n\n let isOperationGoing = true\n let done = noop\n const _res = (x: O) => {\n isOperationGoing = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isOperationGoing = false\n done()\n rej(x)\n }\n\n done = followSubscription(response.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 {\n logicCb(e as I, _res, _rej)\n }\n },\n error: _rej,\n })\n\n cancel = () => {\n if (!isOperationGoing) return\n done()\n request(chainHead.stopOperation, [response.operationId])\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 cancel = 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 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,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;A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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":["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 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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vB,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;;;ACrBK,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":["fn","noop","noop","noop","noop","noop","noop","subscriptionId","method","noop","createClient"]}
|
package/dist/min/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var k=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var oe=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var ie=(r,e)=>{for(var t in e)k(r,t,{get:e[t],enumerable:!0})},se=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of te(e))!ne.call(r,n)&&n!==t&&k(r,n,{get:()=>e[n],enumerable:!(o=re(e,n))||o.enumerable});return r};var ae=r=>se(k({},"__esModule",{value:!0}),r);var B=(r,e,t)=>oe(r,typeof e!="symbol"?e+"":e,t);var me={};ie(me,{DestroyedError:()=>S,DisjointError:()=>w,OperationError:()=>x,OperationInaccessibleError:()=>O,OperationLimitError:()=>C,RpcError:()=>I,StopError:()=>P,createClient:()=>ue});module.exports=ae(me);var H=require("@polkadot-api/utils"),v=r=>(...e)=>new Promise((t,o)=>{let n=H.noop,[s,m]=e[e.length-1]instanceof AbortSignal?[e.slice(0,e.length-1),e[e.length-1]]:[e],u=()=>{n(),o(new H.AbortError)};m?.addEventListener("abort",u,{once:!0});let R=f=>p=>{n=H.noop,m?.removeEventListener("abort",u),f(p)};n=r(R(t),R(o),...s)});function z(){let r=()=>{},e=()=>{};return{promise:new Promise((o,n)=>{r=o,e=n}),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 o=r.get(e);o&&(r.delete(e),o.error(t))},errorAll(e){let t=[...r.values()];r.clear(),t.forEach(o=>{o.error(e)})}}};var b={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:"",followEvent:""},F={chainName:"",genesisHash:"",properties:""},A={broadcast:"",stop:""},ce={submitAndWatch:"",unwatch:""};Object.entries({chainHead:b,chainSpec:F,transaction:A,transactionWatch:ce}).forEach(([r,e])=>{Object.keys(e).forEach(t=>{e[t]=`${r}_v1_${t}`})});var M=r=>(e,t)=>{let o=r(A.broadcast,[e],{onSuccess:n=>{o=n===null?y:()=>{r(A.stop,[n])},n===null&&t(new Error("Max # of broadcasted transactions has been reached"))},onError:t});return()=>{o()}};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((o,n,...s)=>{let m=!0,u=()=>{m=!1},[R,f]=e(...s);return t(r,R,{onSuccess:(p,l)=>{if(p.result==="limitReached")return n(new C);let{operationId:a}=p,c=()=>{t(b.stopOperation,[a])};if(!m)return c();let i=y,g=d=>{m=!1,i(),o(d)},h=d=>{m=!1,i(),n(d)};i=l(a,{next:d=>{let E=d;E.event==="operationError"?n(new x(E.error)):E.event==="operationInaccessible"?n(new O):f(d,g,h)},error:h}),u=()=>{m&&(i(),c())}},onError:n}),()=>{u()}});var N=j(b.body,r=>[[r],(e,t)=>{t(e.value)}]);var G=j(b.call,(r,e,t)=>[[r,e,t],(o,n)=>{n(o.output)}]);var K=r=>e=>new Promise((t,o)=>{r(b.header,[e],{onSuccess:t,onError:o})});var U=require("@polkadot-api/utils");var L=r=>(e,t,o,n,s,m,u)=>{if(t.length===0)return m(),U.noop;let R=!0,f=()=>{R=!1};return r(b.storage,[e,t,o],{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":{n(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,o,n,s,m,u)=>{let R=s.startsWith("descendants"),f=R?[]:null,l=e(n,[{key:m,type:s}],u??null,R?a=>{f.push(a)}:a=>{f=a[0]?.[s]},o,()=>{try{t(R?f.flat():f)}catch(a){o(a)}},a=>{a>0&&(l(),o(new C))});return l})};var V=r=>e=>e.length>0?new Promise((t,o)=>{r(b.unpin,[e],{onSuccess(){t()},onError:o})}):Promise.resolve();var S=class extends Error{constructor(){super("Client destroyed"),this.name="DestroyedError"}};function pe(r){return r.operationId!==void 0}function $(r){return(e,t,o)=>{let n=W(),s=new Set,m=z(),u=m.promise,R=i=>{if(pe(i))return n.has(i.operationId)||console.warn("Uknown operationId on",i),n.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})}o(new P),a(!1)},f=i=>{o(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]),n.errorAll(new w),s.forEach(E=>{E()}),s.clear()},u=i,m.res(i)},l=i=>{i instanceof S?a(!1):o(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):(n.subscribe(q,J),()=>{n.unsubscribe(q)}),ee=r(i,[T,...g],{onSuccess:q=>{s.delete(d),h.onSuccess(q,_)},onError:q=>{s.delete(d),h.onError(q)}});return()=>{s.delete(d),ee()}};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 le=1,X=r=>{let e=le++,t=new Map,o=W(),n=null,s=(p,l,a)=>{n.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 o.subscribe(_,T),()=>{o.unsubscribe(_)}})):void 0}if({subscription:g,result:a,error:c}=i,!g||!c&&!Object.hasOwn(i,"result"))throw 0;let d=g;c?o.error(d,new I(c)):o.next(d,a)}catch(l){console.warn("Error parsing incomming message: "+p),console.error(l)}}n=r(m);let u=()=>{n?.disconnect(),n=null,o.errorAll(new S),t.forEach(p=>p.onError(new S)),t.clear()},R=1;return{request:(p,l,a)=>{if(!n)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((o,n,s,m)=>r(s,m,{onSuccess:o,onError:n})),t=null;return async()=>t||(t=Promise.all([e(F.chainName,[]),e(F.genesisHash,[]),e(F.properties,[])]).then(([o,n,s])=>({name:o,genesisHash:n,properties:s})))};var Z=(r,e)=>t=>{let o={},n=null;return(s,...m)=>{if(n)return n(s,...m);let u=!0,R=()=>{u=!1};return r.then(f=>{if(n=(l,...a)=>{let c=o[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=>{o[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&&(o[t.broadcast]=`${c}_${a}_submitAndWatch`,o[t.stop]=l)}}}).then(()=>{u&&(R=n(s,...m))}),()=>{R()}}};var ue=r=>{let e=X(r),t=v((s,m,u,R)=>e.request(u,R,{onSuccess:s,onError:m})),o=t("rpc_methods",[]).then(s=>new Set(Array.isArray(s)?s:s.methods),()=>new Set),n=Z(o,e.request);return{chainHead:$(n(b)),transaction:M(n(A)),getChainSpecData:Y(n(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 const [requestArgs, logicCb] = factory(...args)\n let cancel = request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\") {\n cancel = noop\n return rej(new OperationLimitError())\n }\n\n let isOperationGoing = true\n let done = noop\n const _res = (x: O) => {\n isOperationGoing = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isOperationGoing = false\n done()\n rej(x)\n }\n\n done = followSubscription(response.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 {\n logicCb(e as I, _res, _rej)\n }\n },\n error: _rej,\n })\n\n cancel = () => {\n if (!isOperationGoing) return\n done()\n request(chainHead.stopOperation, [response.operationId])\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 cancel = 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 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 = enh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AAKM,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","requestArgs","logicCb","cancel","response","followSubscription","noop","OperationLimitError","isOperationGoing","done","_res","x","_rej","e","_e","OperationError","OperationInaccessibleError","chainHead","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","cancel","chainHead","response","followSubscription","OperationLimitError","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 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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AAG,CAAC,EAChC,OAAO,OAAOX,CAAO,EAAE,QAASY,GAAU,CACxCX,EAAaW,CAAK,EAAIA,EAAM,QAAQ,OAAQ,YAAY,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"]}
|
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.3",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,14 +34,11 @@
|
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"semi": false,
|
|
40
|
-
"trailingComma": "all"
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@polkadot-api/utils": "0.1.0"
|
|
41
39
|
},
|
|
42
40
|
"devDependencies": {
|
|
43
|
-
"@polkadot-api/json-rpc-provider": "0.0.1"
|
|
44
|
-
"@polkadot-api/utils": "0.0.1"
|
|
41
|
+
"@polkadot-api/json-rpc-provider": "0.0.1"
|
|
45
42
|
},
|
|
46
43
|
"scripts": {
|
|
47
44
|
"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",
|