@polkadot-api/substrate-client 0.0.1 → 0.1.0

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.mjs CHANGED
@@ -71,43 +71,54 @@ var getSubscriptionsManager = () => {
71
71
  };
72
72
  };
73
73
 
74
- // src/transaction/transaction.ts
75
- var getTxBroadcastNames = (input) => {
76
- if (input.has("transaction_v1_broadcast"))
77
- return ["transaction_v1_broadcast", "transaction_v1_stop"];
78
- if (input.has("transactionWatch_unstable_submitAndWatch"))
79
- return [
80
- "transactionWatch_unstable_submitAndWatch",
81
- "transactionWatch_unstable_unwatch"
82
- ];
83
- return ["transaction_unstable_submitAndWatch", "transaction_unstable_unwatch"];
74
+ // src/methods.ts
75
+ var chainHead = {
76
+ body: "",
77
+ call: "",
78
+ continue: "",
79
+ follow: "",
80
+ header: "",
81
+ stopOperation: "",
82
+ storage: "",
83
+ unfollow: "",
84
+ unpin: "",
85
+ followEvent: ""
86
+ };
87
+ var chainSpec = {
88
+ chainName: "",
89
+ genesisHash: "",
90
+ properties: ""
91
+ };
92
+ var transaction = {
93
+ broadcast: "",
94
+ stop: ""
95
+ };
96
+ var transactionWatch = {
97
+ submitAndWatch: "",
98
+ unwatch: ""
84
99
  };
85
- var getTransaction = (request, rpcMethods) => (tx, error) => {
86
- const broadcast = (tx2, broadcastFn, cancelBroadcastFn) => request(broadcastFn, [tx2], {
100
+ Object.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach(
101
+ ([fnGroupName, methods]) => {
102
+ Object.keys(methods).forEach((methodName) => {
103
+ ;
104
+ methods[methodName] = `${fnGroupName}_v1_${methodName}`;
105
+ });
106
+ }
107
+ );
108
+
109
+ // src/transaction/transaction.ts
110
+ var getTransaction = (request) => (tx, error) => {
111
+ let cancel = request(transaction.broadcast, [tx], {
87
112
  onSuccess: (subscriptionId) => {
88
113
  cancel = subscriptionId === null ? noop2 : () => {
89
- request(cancelBroadcastFn, [subscriptionId]);
114
+ request(transaction.stop, [subscriptionId]);
90
115
  };
91
116
  if (subscriptionId === null) {
92
- error(
93
- new Error("Max # of broadcasted transactions has been reached")
94
- );
117
+ error(new Error("Max # of broadcasted transactions has been reached"));
95
118
  }
96
119
  },
97
120
  onError: error
98
121
  });
99
- let isActive = true;
100
- let cancel = () => {
101
- isActive = false;
102
- };
103
- if (rpcMethods instanceof Promise) {
104
- rpcMethods.then(getTxBroadcastNames).then((names) => {
105
- if (!isActive)
106
- return;
107
- cancel = broadcast(tx, ...names);
108
- });
109
- } else
110
- cancel = broadcast(tx, ...getTxBroadcastNames(rpcMethods));
111
122
  return () => {
112
123
  cancel();
113
124
  };
@@ -148,7 +159,7 @@ var OperationInaccessibleError = class extends Error {
148
159
  // src/chainhead/operation-promise.ts
149
160
  var createOperationPromise = (operationName, factory) => (request) => abortablePromiseFn((res, rej, ...args) => {
150
161
  const [requestArgs, logicCb] = factory(...args);
151
- let cancel = request(operationName, requestArgs, {
162
+ let cancel = request(operationName(), requestArgs, {
152
163
  onSuccess: (response, followSubscription) => {
153
164
  if (response.result === "limitReached") {
154
165
  cancel = noop2;
@@ -183,7 +194,7 @@ var createOperationPromise = (operationName, factory) => (request) => abortableP
183
194
  if (!isOperationGoing)
184
195
  return;
185
196
  done();
186
- request("chainHead_unstable_stopOperation", [response.operationId]);
197
+ request(chainHead.stopOperation, [response.operationId]);
187
198
  };
188
199
  },
189
200
  onError: rej
@@ -195,7 +206,7 @@ var createOperationPromise = (operationName, factory) => (request) => abortableP
195
206
 
196
207
  // src/chainhead/body.ts
197
208
  var createBodyFn = createOperationPromise(
198
- "chainHead_unstable_body",
209
+ () => chainHead.body,
199
210
  (hash) => [
200
211
  [hash],
201
212
  (e, res) => {
@@ -206,7 +217,7 @@ var createBodyFn = createOperationPromise(
206
217
 
207
218
  // src/chainhead/call.ts
208
219
  var createCallFn = createOperationPromise(
209
- "chainHead_unstable_call",
220
+ () => chainHead.call,
210
221
  (hash, fnName, callParameters) => [
211
222
  [hash, fnName, callParameters],
212
223
  (e, res) => {
@@ -217,7 +228,7 @@ var createCallFn = createOperationPromise(
217
228
 
218
229
  // src/chainhead/header.ts
219
230
  var createHeaderFn = (request) => (hash) => new Promise((res, rej) => {
220
- request("chainHead_unstable_header", [hash], {
231
+ request(chainHead.header, [hash], {
221
232
  onSuccess: res,
222
233
  onError: rej
223
234
  });
@@ -230,57 +241,53 @@ var createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, o
230
241
  onDone();
231
242
  return noop3;
232
243
  }
233
- let cancel = request(
234
- "chainHead_unstable_storage",
235
- [hash, inputs, childTrie],
236
- {
237
- onSuccess: (response, followSubscription) => {
238
- if (response.result === "limitReached" || response.discardedItems === inputs.length)
239
- return onError(new OperationLimitError());
240
- const doneListening = followSubscription(response.operationId, {
241
- next: (event) => {
242
- switch (event.event) {
243
- case "operationStorageItems": {
244
- onItems(event.items);
245
- break;
246
- }
247
- case "operationStorageDone": {
248
- _onDone();
249
- break;
250
- }
251
- case "operationError": {
252
- _onError(new OperationError(event.error));
253
- break;
254
- }
255
- case "operationInaccessible": {
256
- _onError(new OperationInaccessibleError());
257
- break;
258
- }
259
- default:
260
- request("chainHead_unstable_continue", []);
244
+ let cancel = request(chainHead.storage, [hash, inputs, childTrie], {
245
+ onSuccess: (response, followSubscription) => {
246
+ if (response.result === "limitReached" || response.discardedItems === inputs.length)
247
+ return onError(new OperationLimitError());
248
+ const doneListening = followSubscription(response.operationId, {
249
+ next: (event) => {
250
+ switch (event.event) {
251
+ case "operationStorageItems": {
252
+ onItems(event.items);
253
+ break;
261
254
  }
262
- },
263
- error: onError
264
- });
265
- cancel = () => {
266
- doneListening();
267
- request("chainHead_unstable_stopOperation", [response.operationId]);
268
- };
269
- const _onError = (e) => {
270
- cancel = noop3;
271
- doneListening();
272
- onError(e);
273
- };
274
- const _onDone = () => {
275
- cancel = noop3;
276
- doneListening();
277
- onDone();
278
- };
279
- onDiscardedItems(response.discardedItems);
280
- },
281
- onError
282
- }
283
- );
255
+ case "operationStorageDone": {
256
+ _onDone();
257
+ break;
258
+ }
259
+ case "operationError": {
260
+ _onError(new OperationError(event.error));
261
+ break;
262
+ }
263
+ case "operationInaccessible": {
264
+ _onError(new OperationInaccessibleError());
265
+ break;
266
+ }
267
+ default:
268
+ request(chainHead.continue, [event.operationId]);
269
+ }
270
+ },
271
+ error: onError
272
+ });
273
+ cancel = () => {
274
+ doneListening();
275
+ request(chainHead.stopOperation, [response.operationId]);
276
+ };
277
+ const _onError = (e) => {
278
+ cancel = noop3;
279
+ doneListening();
280
+ onError(e);
281
+ };
282
+ const _onDone = () => {
283
+ cancel = noop3;
284
+ doneListening();
285
+ onDone();
286
+ };
287
+ onDiscardedItems(response.discardedItems);
288
+ },
289
+ onError
290
+ });
284
291
  return () => {
285
292
  cancel();
286
293
  };
@@ -323,7 +330,7 @@ var createStorageFn = (request) => {
323
330
 
324
331
  // src/chainhead/unpin.ts
325
332
  var createUnpinFn = (request) => (hashes) => hashes.length > 0 ? new Promise((res, rej) => {
326
- request("chainHead_unstable_unpin", [hashes], {
333
+ request(chainHead.unpin, [hashes], {
327
334
  onSuccess() {
328
335
  res();
329
336
  },
@@ -374,7 +381,7 @@ function getChainHead(request) {
374
381
  unfollow(!(error instanceof DestroyedError));
375
382
  };
376
383
  const onFollowRequestSuccess = (subscriptionId, follow) => {
377
- const done = follow("chainHead_unstable_followEvent", subscriptionId, {
384
+ const done = follow(chainHead.followEvent, subscriptionId, {
378
385
  next: onAllFollowEventsNext,
379
386
  error: onAllFollowEventsError
380
387
  });
@@ -382,7 +389,7 @@ function getChainHead(request) {
382
389
  followSubscription = null;
383
390
  unfollow = noop2;
384
391
  done();
385
- sendUnfollow && request("chainHead_unstable_unfollow", [subscriptionId]);
392
+ sendUnfollow && request(chainHead.unfollow, [subscriptionId]);
386
393
  subscriptions.errorAll(new DisjointError());
387
394
  ongoingRequests.forEach((cb) => {
388
395
  cb();
@@ -402,7 +409,7 @@ function getChainHead(request) {
402
409
  deferredFollow.res(e);
403
410
  };
404
411
  let unfollow = request(
405
- "chainHead_unstable_follow",
412
+ chainHead.follow,
406
413
  [withRuntime],
407
414
  { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError }
408
415
  );
@@ -560,21 +567,104 @@ var createClient = (gProvider) => {
560
567
  };
561
568
  };
562
569
 
570
+ // src/chainspec.ts
571
+ var createGetChainSpec = (clientRequest) => {
572
+ const request = abortablePromiseFn(
573
+ (onSuccess, onError, method, params) => clientRequest(method, params, { onSuccess, onError })
574
+ );
575
+ let cachedPromise = null;
576
+ return async () => {
577
+ if (cachedPromise)
578
+ return cachedPromise;
579
+ return cachedPromise = Promise.all([
580
+ request(chainSpec.chainName, []),
581
+ request(chainSpec.genesisHash, []),
582
+ request(chainSpec.properties, [])
583
+ ]).then(([name, genesisHash, properties]) => ({
584
+ name,
585
+ genesisHash,
586
+ properties
587
+ }));
588
+ };
589
+ };
590
+
591
+ // src/request-compatibility-enhancer.ts
592
+ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
593
+ let enhancedRequest = null;
594
+ return (method, ...rest) => {
595
+ if (enhancedRequest)
596
+ return enhancedRequest(method, ...rest);
597
+ let isRunning = true;
598
+ let cleanup = () => {
599
+ isRunning = false;
600
+ };
601
+ rpcMethodsP.then((rpcMethods) => {
602
+ enhancedRequest = (method2, ...iRest) => {
603
+ if (rpcMethods.has(method2))
604
+ return request(method2, ...iRest);
605
+ iRest[1]?.onError(new Error(`Unsupported method ${method2}`));
606
+ return noop2;
607
+ };
608
+ if (rpcMethods.has(method))
609
+ return;
610
+ const parts = method.split("_");
611
+ if (parts[1] !== "v1")
612
+ return;
613
+ parts[1] = "unstable";
614
+ method = parts.join("_");
615
+ if (rpcMethods.has(method))
616
+ Object.entries(methods).forEach(([key, value]) => {
617
+ methods[key] = value.replace("_v1_", "_unstable_");
618
+ });
619
+ else if (parts[0] === "transaction") {
620
+ let unwatch;
621
+ let version;
622
+ const txGroup = ["transactionWatch", "transaction"].find(
623
+ (group) => {
624
+ version = ["v1", "unstable"].find(
625
+ (v) => rpcMethods.has(unwatch = `${group}_${v}_unwatch`)
626
+ );
627
+ return !!version;
628
+ }
629
+ );
630
+ if (txGroup) {
631
+ methods.broadcast = `${txGroup}_${version}_submitAndWatch`;
632
+ methods.stop = unwatch;
633
+ }
634
+ }
635
+ }).then(() => {
636
+ if (isRunning)
637
+ cleanup = enhancedRequest(method, ...rest);
638
+ });
639
+ return () => {
640
+ cleanup();
641
+ };
642
+ };
643
+ };
644
+
563
645
  // src/index.ts
564
646
  var createClient2 = (provider) => {
565
647
  const client = createClient(provider);
566
648
  const request = abortablePromiseFn(
567
649
  (onSuccess, onError, method, params) => client.request(method, params, { onSuccess, onError })
568
650
  );
569
- let rpcMethods = request("rpc_methods", []).then(
570
- (x) => rpcMethods = new Set(Array.isArray(x) ? x : x.methods)
651
+ const rpcMethods = request("rpc_methods", []).then(
652
+ (x) => new Set(Array.isArray(x) ? x : x.methods),
653
+ () => /* @__PURE__ */ new Set()
654
+ );
655
+ const compatibilityEnhancer = getCompatibilityEnhancer(
656
+ rpcMethods,
657
+ client.request
571
658
  );
572
- rpcMethods.catch(noop2);
573
659
  return {
574
- chainHead: getChainHead(client.request),
660
+ chainHead: getChainHead(
661
+ compatibilityEnhancer(chainHead)
662
+ ),
575
663
  transaction: getTransaction(
576
- client.request,
577
- rpcMethods
664
+ compatibilityEnhancer(transaction)
665
+ ),
666
+ getChainSpecData: createGetChainSpec(
667
+ compatibilityEnhancer(chainSpec)
578
668
  ),
579
669
  destroy: () => {
580
670
  client.disconnect();
@@ -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/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/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","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\n\nconst getTxBroadcastNames = (input: Set<string>): [string, string] => {\n // Proper\n if (input.has(\"transaction_v1_broadcast\"))\n return [\"transaction_v1_broadcast\", \"transaction_v1_stop\"]\n\n // Fallback for versions not up-to-date yet\n if (input.has(\"transactionWatch_unstable_submitAndWatch\"))\n return [\n \"transactionWatch_unstable_submitAndWatch\",\n \"transactionWatch_unstable_unwatch\",\n ]\n\n // Fallback for very old versions\n return [\"transaction_unstable_submitAndWatch\", \"transaction_unstable_unwatch\"]\n}\n\nexport const getTransaction =\n (\n request: ClientRequest<string, any>,\n rpcMethods: Promise<Set<string>> | Set<string>,\n ) =>\n (tx: string, error: (e: Error) => void) => {\n const broadcast = (\n tx: string,\n broadcastFn: string,\n cancelBroadcastFn: string,\n ) =>\n request(broadcastFn, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(cancelBroadcastFn, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(\n new Error(\"Max # of broadcasted transactions has been reached\"),\n )\n }\n },\n onError: error,\n })\n\n let isActive = true\n let cancel = () => {\n isActive = false\n }\n\n if (rpcMethods instanceof Promise) {\n rpcMethods.then(getTxBroadcastNames).then((names) => {\n if (!isActive) return\n cancel = broadcast(tx, ...names)\n })\n } else cancel = broadcast(tx, ...getTxBroadcastNames(rpcMethods))\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\"\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_unstable_stopOperation\", [response.operationId])\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n \"chainHead_unstable_body\",\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n \"chainHead_unstable_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 { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(\"chainHead_unstable_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\"\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(\n \"chainHead_unstable_storage\",\n [hash, inputs, childTrie],\n {\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_unstable_continue\", [])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(\"chainHead_unstable_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\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 { 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_unstable_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\"\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(\"chainHead_unstable_followEvent\", 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_unstable_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_unstable_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 methodName: string,\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, (methodName, opaqueId, subscriber) => {\n const subscriptionId = methodName + 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 = parsed.method + 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 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, noop } from \"./internal-utils\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\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 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 let rpcMethods: Promise<Set<string>> | Set<string> = request<\n { methods: Array<string> } | Array<string>\n >(\"rpc_methods\", []).then(\n (x) => (rpcMethods = new Set(Array.isArray(x) ? x : x.methods)),\n )\n rpcMethods.catch(noop)\n\n return {\n chainHead: getChainHead(client.request as ClientRequest<any, any>),\n transaction: getTransaction(\n client.request as ClientRequest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G,OAAO,QAAQ,QAAQ,QAAQ,EAAE,WAAW,QAAQ,CAAC;AAAA,EAC5D;AAEA,MAAI,aAAiD,QAEnD,eAAe,CAAC,CAAC,EAAE;AAAA,IACnB,CAAC,MAAO,aAAa,IAAI,IAAI,MAAM,QAAQ,CAAC,IAAI,IAAI,EAAE,OAAO;AAAA,EAC/D;AACA,aAAW,MAAMC,KAAI;AAErB,SAAO;AAAA,IACL,WAAW,aAAa,OAAO,OAAkC;AAAA,IACjE,aAAa;AAAA,MACX,OAAO;AAAA,MACP;AAAA,IACF;AAAA,IACA,SAAS,MAAM;AACb,aAAO,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,EACnB;AACF;","names":["fn","noop","tx","noop","noop","noop","noop","noop","subscriptionId","createClient","noop"]}
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(chainHead.followEvent, 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 methodName: string,\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, (methodName, opaqueId, subscriber) => {\n const subscriptionId = methodName + 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 = parsed.method + 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 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 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 method = parts.join(\"_\")\n\n if (rpcMethods.has(method))\n Object.entries(methods).forEach(([key, value]) => {\n methods[key] = 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 methods.broadcast = `${txGroup}_${version}_submitAndWatch`\n 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;AACrC,MAAI,MAA4B,MAAM;AAAA,EAAC;AAEvC,QAAM,UAAU,IAAI,QAAW,CAAC,MAAM,SAAS;AAC7C,UAAM;AACN,UAAM;AAAA,EACR,CAAC;AAED,SAAO,EAAE,SAAS,KAAK,IAAI;AAC7B;;;AChBO,IAAMC,QAAO,MAAY;AAAC;;;ACK1B,IAAM,0BAA0B,MAAS;AAC9C,QAAM,gBAAgB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A,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"]}
@@ -215,15 +215,23 @@ declare function getChainHead(request: ClientRequest<string, FollowEventRpc>): C
215
215
 
216
216
  type Transaction = (tx: string, error: (e: Error) => void) => UnsubscribeFn;
217
217
 
218
- declare const getTransaction: (request: ClientRequest<string, any>, rpcMethods: Promise<Set<string>> | Set<string>) => (tx: string, error: (e: Error) => void) => () => void;
218
+ declare const getTransaction: (request: ClientRequest<string, any>) => (tx: string, error: (e: Error) => void) => () => void;
219
+
220
+ interface ChainSpecData {
221
+ name: string;
222
+ genesisHash: string;
223
+ properties: any;
224
+ }
225
+ declare const createGetChainSpec: (clientRequest: ClientRequest<any, any>) => () => Promise<ChainSpecData>;
219
226
 
220
227
  interface SubstrateClient {
221
228
  chainHead: ChainHead;
222
229
  transaction: Transaction;
223
230
  destroy: UnsubscribeFn;
231
+ getChainSpecData: () => Promise<ChainSpecData>;
224
232
  request: <T>(method: string, params: any[], abortSignal?: AbortSignal) => Promise<T>;
225
233
  _request: <Reply, Notification>(method: string, params: any[], cb?: ClientRequestCb<Reply, Notification>) => UnsubscribeFn;
226
234
  }
227
235
  declare const createClient: (provider: JsonRpcProvider) => SubstrateClient;
228
236
 
229
- export { type AbortablePromiseFn, type BestBlockChanged, type ChainHead, type Client, type ClientInnerRequest, type ClientInnerRequestCb, type ClientRequest, type ClientRequestCb, DestroyedError, DisjointError, type Finalized, type FollowEventWithRuntime, type FollowEventWithoutRuntime, type FollowInnerSubscriptionCb, type FollowResponse, type FollowSubscriptionCb, type IRpcError, type Initialized, type InitializedWithRuntime$1 as InitializedWithRuntime, type NewBlock, type NewBlockWithRuntime$1 as NewBlockWithRuntime, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, type Runtime, StopError, type StorageItemInput, type StorageItemResponse, type StorageResult, type SubstrateClient, type Transaction, type UnsubscribeFn, createClient, getChainHead, getTransaction };
237
+ export { type AbortablePromiseFn, type BestBlockChanged, type ChainHead, type ChainSpecData, type Client, type ClientInnerRequest, type ClientInnerRequestCb, type ClientRequest, type ClientRequestCb, DestroyedError, DisjointError, type Finalized, type FollowEventWithRuntime, type FollowEventWithoutRuntime, type FollowInnerSubscriptionCb, type FollowResponse, type FollowSubscriptionCb, type IRpcError, type Initialized, type InitializedWithRuntime$1 as InitializedWithRuntime, type NewBlock, type NewBlockWithRuntime$1 as NewBlockWithRuntime, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, type Runtime, StopError, type StorageItemInput, type StorageItemResponse, type StorageResult, type SubstrateClient, type Transaction, type UnsubscribeFn, createClient, createGetChainSpec, getChainHead, getTransaction };