@polkadot-api/substrate-client 0.4.1 → 0.4.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.
Files changed (35) hide show
  1. package/dist/esm/archive/archive.mjs.map +1 -1
  2. package/dist/esm/archive/errors.mjs.map +1 -1
  3. package/dist/esm/archive/storage-subscription.mjs.map +1 -1
  4. package/dist/esm/archive/storage.mjs.map +1 -1
  5. package/dist/esm/chainhead/body.mjs.map +1 -1
  6. package/dist/esm/chainhead/call.mjs.map +1 -1
  7. package/dist/esm/chainhead/chainhead.mjs +50 -48
  8. package/dist/esm/chainhead/chainhead.mjs.map +1 -1
  9. package/dist/esm/chainhead/errors.mjs.map +1 -1
  10. package/dist/esm/chainhead/header.mjs.map +1 -1
  11. package/dist/esm/chainhead/operation-promise.mjs.map +1 -1
  12. package/dist/esm/chainhead/storage-subscription.mjs.map +1 -1
  13. package/dist/esm/chainhead/storage.mjs.map +1 -1
  14. package/dist/esm/chainhead/unpin.mjs.map +1 -1
  15. package/dist/esm/chainspec.mjs.map +1 -1
  16. package/dist/esm/index.mjs +1 -2
  17. package/dist/esm/index.mjs.map +1 -1
  18. package/dist/esm/internal-utils/abortablePromiseFn.mjs.map +1 -1
  19. package/dist/esm/internal-utils/deferred-promise.mjs.map +1 -1
  20. package/dist/esm/methods.mjs.map +1 -1
  21. package/dist/esm/substrate-client.mjs +1 -1
  22. package/dist/esm/substrate-client.mjs.map +1 -1
  23. package/dist/esm/transaction/transaction.mjs.map +1 -1
  24. package/dist/index.d.ts +5 -33
  25. package/dist/index.js +87 -200
  26. package/dist/index.js.map +1 -1
  27. package/package.json +2 -1
  28. package/dist/esm/client/DestroyedError.mjs +0 -9
  29. package/dist/esm/client/DestroyedError.mjs.map +0 -1
  30. package/dist/esm/client/RpcError.mjs +0 -16
  31. package/dist/esm/client/RpcError.mjs.map +0 -1
  32. package/dist/esm/client/createClient.mjs +0 -79
  33. package/dist/esm/client/createClient.mjs.map +0 -1
  34. package/dist/esm/internal-utils/subscriptions-manager.mjs +0 -32
  35. package/dist/esm/internal-utils/subscriptions-manager.mjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,18 +1,36 @@
1
1
  'use strict';
2
2
 
3
3
  var utils = require('@polkadot-api/utils');
4
+ var rawClient = require('@polkadot-api/raw-client');
4
5
 
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
- class RpcError extends Error {
9
- constructor(e) {
10
- super(e.message);
11
- __publicField(this, "code");
12
- __publicField(this, "data");
13
- this.code = e.code;
14
- this.data = e.data;
15
- this.name = "RpcError";
6
+ class StopError extends Error {
7
+ constructor() {
8
+ super("ChainHead stopped");
9
+ this.name = "StopError";
10
+ }
11
+ }
12
+ class DisjointError extends Error {
13
+ constructor() {
14
+ super("ChainHead disjointed");
15
+ this.name = "DisjointError";
16
+ }
17
+ }
18
+ class OperationLimitError extends Error {
19
+ constructor() {
20
+ super("ChainHead operations limit reached");
21
+ this.name = "OperationLimitError";
22
+ }
23
+ }
24
+ class OperationError extends Error {
25
+ constructor(error) {
26
+ super(error);
27
+ this.name = "OperationError";
28
+ }
29
+ }
30
+ class OperationInaccessibleError extends Error {
31
+ constructor() {
32
+ super("ChainHead operation inaccessible");
33
+ this.name = "OperationInaccessibleError";
16
34
  }
17
35
  }
18
36
 
@@ -47,146 +65,6 @@ function deferred() {
47
65
  const noop = () => {
48
66
  };
49
67
 
50
- const getSubscriptionsManager = () => {
51
- const subscriptions = /* @__PURE__ */ new Map();
52
- return {
53
- has: subscriptions.has.bind(subscriptions),
54
- subscribe(id, subscriber) {
55
- subscriptions.set(id, subscriber);
56
- },
57
- unsubscribe(id) {
58
- subscriptions.delete(id);
59
- },
60
- next(id, data) {
61
- subscriptions.get(id)?.next(data);
62
- },
63
- error(id, e) {
64
- const subscriber = subscriptions.get(id);
65
- if (subscriber) {
66
- subscriptions.delete(id);
67
- subscriber.error(e);
68
- }
69
- },
70
- errorAll(e) {
71
- const subscribers = [...subscriptions.values()];
72
- subscriptions.clear();
73
- subscribers.forEach((s) => {
74
- s.error(e);
75
- });
76
- }
77
- };
78
- };
79
-
80
- class DestroyedError extends Error {
81
- constructor() {
82
- super("Client destroyed");
83
- this.name = "DestroyedError";
84
- }
85
- }
86
-
87
- let nextClientId = 1;
88
- const createClient$1 = (gProvider) => {
89
- let clientId = nextClientId++;
90
- const responses = /* @__PURE__ */ new Map();
91
- const subscriptions = getSubscriptionsManager();
92
- let connection = null;
93
- const send = (id, method, params) => {
94
- connection.send(
95
- JSON.stringify({
96
- jsonrpc: "2.0",
97
- id,
98
- method,
99
- params
100
- })
101
- );
102
- };
103
- function onMessage(message) {
104
- try {
105
- let id, result, error, params, subscription;
106
- const parsed = JSON.parse(message);
107
- ({ id, result, error, params } = parsed);
108
- if (id === null) throw new Error(params?.error?.message ?? "id null");
109
- if (id != null) {
110
- const cb = responses.get(id);
111
- if (!cb) return;
112
- responses.delete(id);
113
- return error ? cb.onError(new RpcError(error)) : cb.onSuccess(result, (opaqueId, subscriber) => {
114
- const subscriptionId2 = opaqueId;
115
- subscriptions.subscribe(subscriptionId2, subscriber);
116
- return () => {
117
- subscriptions.unsubscribe(subscriptionId2);
118
- };
119
- });
120
- }
121
- ;
122
- ({ subscription, result, error } = params);
123
- if (!subscription || !error && !Object.hasOwn(params, "result")) throw 0;
124
- const subscriptionId = subscription;
125
- if (error) {
126
- subscriptions.error(subscriptionId, new RpcError(error));
127
- } else {
128
- subscriptions.next(subscriptionId, result);
129
- }
130
- } catch (e) {
131
- console.warn("Error parsing incomming message: " + message);
132
- console.error(e);
133
- }
134
- }
135
- connection = gProvider(onMessage);
136
- const disconnect = () => {
137
- connection?.disconnect();
138
- connection = null;
139
- subscriptions.errorAll(new DestroyedError());
140
- responses.forEach((r) => r.onError(new DestroyedError()));
141
- responses.clear();
142
- };
143
- let nextId = 1;
144
- const request = (method, params, cb) => {
145
- if (!connection) throw new Error("Not connected");
146
- const id = `${clientId}-${nextId++}`;
147
- if (cb) responses.set(id, cb);
148
- send(id, method, params);
149
- return () => {
150
- responses.delete(id);
151
- };
152
- };
153
- return {
154
- request,
155
- disconnect
156
- };
157
- };
158
-
159
- class StopError extends Error {
160
- constructor() {
161
- super("ChainHead stopped");
162
- this.name = "StopError";
163
- }
164
- }
165
- class DisjointError extends Error {
166
- constructor() {
167
- super("ChainHead disjointed");
168
- this.name = "DisjointError";
169
- }
170
- }
171
- class OperationLimitError extends Error {
172
- constructor() {
173
- super("ChainHead operations limit reached");
174
- this.name = "OperationLimitError";
175
- }
176
- }
177
- class OperationError extends Error {
178
- constructor(error) {
179
- super(error);
180
- this.name = "OperationError";
181
- }
182
- }
183
- class OperationInaccessibleError extends Error {
184
- constructor() {
185
- super("ChainHead operation inaccessible");
186
- this.name = "OperationInaccessibleError";
187
- }
188
- }
189
-
190
68
  const chainHead = {
191
69
  body: "",
192
70
  call: "",
@@ -408,67 +286,71 @@ function isOperationEvent(event) {
408
286
  }
409
287
  function getChainHead(request) {
410
288
  return (withRuntime, onFollowEvent, onFollowError) => {
411
- const subscriptions = getSubscriptionsManager();
289
+ const subscriptions = rawClient.getSubscriptionsManager();
412
290
  const ongoingRequests = /* @__PURE__ */ new Set();
413
291
  const deferredFollow = deferred();
414
292
  let followSubscription = deferredFollow.promise;
293
+ let stopListeningToFollowEvents = noop;
294
+ const unfollowRequest = (subscriptionId) => {
295
+ request(chainHead.unfollow, [subscriptionId]);
296
+ };
297
+ const stopEverything = (sendUnfollow) => {
298
+ stopListeningToFollowEvents();
299
+ if (followSubscription === null) return;
300
+ if (sendUnfollow) {
301
+ if (followSubscription instanceof Promise) {
302
+ followSubscription.then((x) => {
303
+ if (typeof x === "string") unfollowRequest(x);
304
+ });
305
+ } else unfollowRequest(followSubscription);
306
+ }
307
+ followSubscription = null;
308
+ ongoingRequests.forEach((cb) => {
309
+ cb();
310
+ });
311
+ ongoingRequests.clear();
312
+ subscriptions.errorAll(new DisjointError());
313
+ };
415
314
  const onAllFollowEventsNext = (event) => {
416
315
  if (isOperationEvent(event)) {
417
316
  if (!subscriptions.has(event.operationId))
418
317
  console.warn("Uknown operationId on", event);
419
318
  return subscriptions.next(event.operationId, event);
420
319
  }
421
- if (event.event !== "stop") {
422
- if (event.event === "initialized") {
423
- return onFollowEvent({
424
- type: event.event,
425
- finalizedBlockHashes: event.finalizedBlockHashes,
426
- finalizedBlockRuntime: event.finalizedBlockRuntime
427
- });
428
- }
429
- const { event: type, ...rest } = event;
430
- return onFollowEvent({ type, ...rest });
320
+ switch (event.event) {
321
+ case "stop":
322
+ onFollowError(new StopError());
323
+ return stopEverything(false);
324
+ case "initialized":
325
+ case "newBlock":
326
+ case "bestBlockChanged":
327
+ case "finalized":
328
+ const { event: type, ...rest } = event;
329
+ return onFollowEvent({ type, ...rest });
431
330
  }
432
- onFollowError(new StopError());
433
- unfollow(false);
331
+ console.warn("Invalid event", event);
434
332
  };
435
333
  const onAllFollowEventsError = (error) => {
436
334
  onFollowError(error);
437
- unfollow(!(error instanceof DestroyedError));
335
+ stopEverything(!(error instanceof rawClient.DestroyedError));
438
336
  };
439
- const onFollowRequestSuccess = (subscriptionId, follow) => {
440
- const done = follow(subscriptionId, {
441
- next: onAllFollowEventsNext,
442
- error: onAllFollowEventsError
443
- });
444
- unfollow = (sendUnfollow = true) => {
337
+ request(chainHead.follow, [withRuntime], {
338
+ onSuccess: (subscriptionId, follow) => {
339
+ if (followSubscription instanceof Promise) {
340
+ followSubscription = subscriptionId;
341
+ stopListeningToFollowEvents = follow(subscriptionId, {
342
+ next: onAllFollowEventsNext,
343
+ error: onAllFollowEventsError
344
+ });
345
+ }
346
+ deferredFollow.res(subscriptionId);
347
+ },
348
+ onError: (e) => {
445
349
  followSubscription = null;
446
- unfollow = noop;
447
- done();
448
- sendUnfollow && request(chainHead.unfollow, [subscriptionId]);
449
- subscriptions.errorAll(new DisjointError());
450
- ongoingRequests.forEach((cb) => {
451
- cb();
452
- });
453
- ongoingRequests.clear();
454
- };
455
- followSubscription = subscriptionId;
456
- deferredFollow.res(subscriptionId);
457
- };
458
- const onFollowRequestError = (e) => {
459
- if (e instanceof DestroyedError) {
460
- unfollow(false);
461
- } else {
350
+ deferredFollow.res(e);
462
351
  onFollowError(e);
463
352
  }
464
- followSubscription = null;
465
- deferredFollow.res(e);
466
- };
467
- let unfollow = request(
468
- chainHead.follow,
469
- [withRuntime],
470
- { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError }
471
- );
353
+ });
472
354
  const fRequest = (method, params, cb) => {
473
355
  const disjoint = () => {
474
356
  cb?.onError(new DisjointError());
@@ -518,8 +400,7 @@ function getChainHead(request) {
518
400
  };
519
401
  return {
520
402
  unfollow() {
521
- unfollow();
522
- followSubscription = null;
403
+ stopEverything(true);
523
404
  },
524
405
  body: createBodyFn(fRequest),
525
406
  call: createCallFn(fRequest),
@@ -711,7 +592,7 @@ const createClient = (provider) => {
711
592
  cached.refCount++;
712
593
  return cached.client;
713
594
  }
714
- const { request, disconnect } = createClient$1(provider);
595
+ const { request, disconnect } = rawClient.createClient(provider);
715
596
  const destroy = () => {
716
597
  const cached2 = clientCache.get(provider);
717
598
  if (!cached2 || cached2.refCount <= 1) {
@@ -740,14 +621,20 @@ Object.defineProperty(exports, "AbortError", {
740
621
  enumerable: true,
741
622
  get: function () { return utils.AbortError; }
742
623
  });
624
+ Object.defineProperty(exports, "DestroyedError", {
625
+ enumerable: true,
626
+ get: function () { return rawClient.DestroyedError; }
627
+ });
628
+ Object.defineProperty(exports, "RpcError", {
629
+ enumerable: true,
630
+ get: function () { return rawClient.RpcError; }
631
+ });
743
632
  exports.BlockHashNotFoundError = BlockHashNotFoundError;
744
633
  exports.CallError = CallError;
745
- exports.DestroyedError = DestroyedError;
746
634
  exports.DisjointError = DisjointError;
747
635
  exports.OperationError = OperationError;
748
636
  exports.OperationInaccessibleError = OperationInaccessibleError;
749
637
  exports.OperationLimitError = OperationLimitError;
750
- exports.RpcError = RpcError;
751
638
  exports.StopError = StopError;
752
639
  exports.StorageError = StorageError;
753
640
  exports.createClient = createClient;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/client/RpcError.ts","../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/internal-utils/subscriptions-manager.ts","../src/client/DestroyedError.ts","../src/client/createClient.ts","../src/chainhead/errors.ts","../src/methods.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/chainhead/chainhead.ts","../src/archive/errors.ts","../src/archive/storage-subscription.ts","../src/archive/storage.ts","../src/archive/archive.ts","../src/transaction/transaction.ts","../src/chainspec.ts","../src/substrate-client.ts"],"sourcesContent":["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 { 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 class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\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 === null) throw new Error(params?.error?.message ?? \"id null\")\n\n if (id != null) {\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","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","const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nconst chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nconst transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n\nexport { chainHead, transaction, chainSpec }\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 type { ClientInnerRequest, FollowResponse } from \"./public-types\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\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 { OperationLimitError } from \"./errors\"\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\"\nimport type { ClientInnerRequest, FollowResponse } from \"./public-types\"\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","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: 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 class BlockHashNotFoundError extends Error {\n constructor(hash: string) {\n super(`Invalid BlockHash: ${hash}`)\n this.name = \"BlockHashNotFoundError\"\n }\n}\n\nexport class StorageError extends Error {\n constructor(message: string) {\n super(`Storage Error: ${message}`)\n this.name = \"StorageError\"\n }\n}\n\nexport class CallError extends Error {\n constructor(message: string) {\n super(`Call Error: ${message}`)\n this.name = \"CallError\"\n }\n}\n","import type { ClientRequest } from \"@/client\"\nimport { noop } from \"@polkadot-api/utils\"\nimport { Archive } from \"./public-types\"\nimport { StorageItemResponse } from \"@/chainhead\"\nimport { StorageError } from \"./errors\"\n\ntype StorageEvent = {\n event: \"storage\"\n} & StorageItemResponse\n\ntype StorageDone = {\n event: \"storageDone\"\n}\n\ntype StorageErrorEvent = {\n event: \"storageError\"\n error: string\n}\n\nexport const createStorageCb =\n (\n archiveRequest: ClientRequest<\n string,\n StorageEvent | StorageDone | StorageErrorEvent\n >,\n ): Archive[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItem, onError, onDone) => {\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 archiveRequest(\"storage\", [hash, inputs, childTrie], {\n onSuccess: (operationId, followSubscription) => {\n const stopOperation = () => {\n archiveRequest(\"stopStorage\", [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(operationId, {\n next: (event) => {\n const { event: type } = event\n if (type === \"storage\") {\n const { event: _, ...item } = event\n onItem(item)\n } else if (type === \"storageDone\") _onDone()\n else _onError(new StorageError(event.error))\n },\n error: onError,\n })\n\n const tearDown = () => {\n cancel = noop\n doneListening()\n }\n\n cancel = () => {\n tearDown()\n stopOperation()\n }\n\n const _onError = (e: Error) => {\n tearDown()\n onError(e)\n }\n\n const _onDone = () => {\n tearDown()\n onDone()\n }\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { abortablePromiseFn } from \"@/internal-utils\"\nimport type { Archive } from \"./public-types\"\n\nexport const createStorageFn = (\n cbStore: Archive[\"storageSubscription\"],\n): Archive[\"storage\"] =>\n abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n\n let result: any = isDescendants ? [] : null\n const onItem: Parameters<typeof cbStore>[3] = isDescendants\n ? result.push.bind(result)\n : ({ [type]: res }) => {\n result = res\n }\n\n return cbStore(\n hash,\n [{ key, type }],\n childTrie,\n onItem,\n (e) => {\n reject(e)\n result = null\n },\n () => {\n resolve(result)\n result = null\n },\n )\n })\n","import { abortablePromiseFn } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { createStorageFn } from \"./storage\"\nimport { Archive } from \"./public-types\"\nimport { CallError, BlockHashNotFoundError } from \"./errors\"\n\nconst identity =\n <T>() =>\n (x: T): T =>\n x\n\nconst handleInvalidBlockHash =\n <T>() =>\n (result: T | null, hash: string): T => {\n if (result === null) throw new BlockHashNotFoundError(hash)\n return result\n }\n\nexport const getArchive = (request: ClientRequest<any, any>): Archive => {\n const archiveRequest: ClientRequest<any, any> = (method: string, ...rest) =>\n request(`archive_v1_${method}`, ...rest)\n\n const fnCreator =\n <A extends Array<any>>(method: string) =>\n <I, O>(mapper: (input: I, ...args: A) => O) =>\n abortablePromiseFn<O, A>((res, rej, ...args) =>\n archiveRequest(method, args, {\n onSuccess: (x: I) => {\n try {\n res(mapper(x, ...args))\n } catch (e) {\n rej(e)\n }\n },\n onError: rej,\n }),\n )\n\n const header = fnCreator<[hash: string]>(\"header\")(\n handleInvalidBlockHash<string>(),\n )\n\n const body = fnCreator<[hash: string]>(\"body\")(\n handleInvalidBlockHash<string[]>(),\n )\n\n const storageSubscription = createStorageCb(archiveRequest)\n const storage = createStorageFn(storageSubscription)\n\n const call = fnCreator<\n [hash: string, function: string, callParameters: string]\n >(\"call\")((\n x:\n | { success: true; value: string }\n | { success: false; error: string }\n | null,\n hash,\n ) => {\n if (!x) throw new BlockHashNotFoundError(hash)\n if (!x.success) throw new CallError(x.error)\n return x.value\n })\n\n const finalizedHeight = fnCreator<[]>(\"finalizedHeight\")(identity<number>())\n const hashByHeight =\n fnCreator<[height: number]>(\"hashByHeight\")(identity<string[]>())\n\n return {\n header,\n body,\n storageSubscription,\n storage,\n call,\n finalizedHeight,\n hashByHeight,\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","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 { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport { ClientRequestCb, createClient as createRawClient } 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 { Archive, getArchive } from \"./archive\"\n\nexport interface SubstrateClient {\n archive: Archive\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\nconst clientCache = new Map<\n JsonRpcProvider,\n { client: SubstrateClient; refCount: number }\n>()\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const cached = clientCache.get(provider)\n if (cached) {\n cached.refCount++\n return cached.client\n }\n\n const { request, disconnect } = createRawClient(provider)\n const destroy = () => {\n const cached = clientCache.get(provider)\n if (!cached || cached.refCount <= 1) {\n clientCache.delete(provider)\n disconnect()\n } else {\n cached.refCount--\n }\n }\n const client: SubstrateClient = {\n archive: getArchive(request),\n chainHead: getChainHead(request),\n transaction: getTransaction(request),\n getChainSpecData: createGetChainSpec(request),\n destroy,\n request: abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => request(method, params, { onSuccess, onError }),\n ),\n _request: request,\n }\n clientCache.set(provider, { client, refCount: 1 })\n return client\n}\n"],"names":["noop","AbortError","fn","createClient","subscriptionId","createStorageCb","createStorageFn","createRawClient","cached"],"mappings":";;;;;;;AAMO,MAAM,iBAAiB,KAA2B,CAAA;AAAA,EAGvD,YAAY,CAAc,EAAA;AACxB,IAAA,KAAA,CAAM,EAAE,OAAO,CAAA;AAHjB,IAAA,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AACA,IAAA,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAGE,IAAA,IAAA,CAAK,OAAO,CAAE,CAAA,IAAA;AACd,IAAA,IAAA,CAAK,OAAO,CAAE,CAAA,IAAA;AACd,IAAA,IAAA,CAAK,IAAO,GAAA,UAAA;AAAA;AAEhB;;ACZa,MAAA,kBAAA,GACX,CACE,EAIF,KAAA,CAAA,GAAI,SACF,IAAI,OAAA,CAAQ,CAAC,GAAA,EAAK,GAAQ,KAAA;AACxB,EAAA,IAAI,MAAS,GAAAA,UAAA;AAEb,EAAM,MAAA,CAAC,UAAY,EAAA,WAAW,CAC5B,GAAA,IAAA,CAAK,KAAK,MAAS,GAAA,CAAC,CAAa,YAAA,WAAA,GAC5B,CAAC,IAAA,CAAK,MAAM,CAAG,EAAA,IAAA,CAAK,MAAS,GAAA,CAAC,CAAG,EAAA,IAAA,CAAK,IAAK,CAAA,MAAA,GAAS,CAAC,CAAC,CAItD,GAAA,CAAC,IAAI,CAAA;AAEZ,EAAA,MAAM,UAAU,MAAM;AACpB,IAAO,MAAA,EAAA;AACP,IAAI,GAAA,CAAA,IAAIC,kBAAY,CAAA;AAAA,GACtB;AAEA,EAAA,WAAA,EAAa,iBAAiB,OAAS,EAAA,OAAA,EAAS,EAAE,IAAA,EAAM,MAAM,CAAA;AAE9D,EAAA,MAAM,WACJ,GAAA,CAAIC,GACJ,KAAA,CAAC,CAAM,KAAA;AACL,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AI,QAAQ,CAAA;AACvC,IAAA,IAAI,CAACA,OAAAA,IAAUA,OAAO,CAAA,QAAA,IAAY,CAAG,EAAA;AACnC,MAAA,WAAA,CAAY,OAAO,QAAQ,CAAA;AAC3B,MAAW,UAAA,EAAA;AAAA,KACN,MAAA;AACL,MAAAA,OAAO,CAAA,QAAA,EAAA;AAAA;AACT,GACF;AACA,EAAA,MAAM,MAA0B,GAAA;AAAA,IAC9B,OAAA,EAAS,WAAW,OAAO,CAAA;AAAA,IAC3B,SAAA,EAAW,aAAa,OAAO,CAAA;AAAA,IAC/B,WAAA,EAAa,eAAe,OAAO,CAAA;AAAA,IACnC,gBAAA,EAAkB,mBAAmB,OAAO,CAAA;AAAA,IAC5C,OAAA;AAAA,IACA,OAAS,EAAA,kBAAA;AAAA,MACP,CACE,SACA,EAAA,OAAA,EACA,MACA,EAAA,MAAA,KACG,OAAQ,CAAA,MAAA,EAAQ,MAAQ,EAAA,EAAE,SAAW,EAAA,OAAA,EAAS;AAAA,KACrD;AAAA,IACA,QAAU,EAAA;AAAA,GACZ;AACA,EAAA,WAAA,CAAY,IAAI,QAAU,EAAA,EAAE,MAAQ,EAAA,QAAA,EAAU,GAAG,CAAA;AACjD,EAAO,OAAA,MAAA;AACT;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/chainhead/errors.ts","../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/methods.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/chainhead/chainhead.ts","../src/archive/errors.ts","../src/archive/storage-subscription.ts","../src/archive/storage.ts","../src/archive/archive.ts","../src/transaction/transaction.ts","../src/chainspec.ts","../src/substrate-client.ts"],"sourcesContent":["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 { 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","const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nconst chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nconst transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n\nexport { chainHead, transaction, chainSpec }\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 type { ClientInnerRequest, FollowResponse } from \"./public-types\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\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 { OperationLimitError } from \"./errors\"\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\"\nimport type { ClientInnerRequest, FollowResponse } from \"./public-types\"\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","import {\n DestroyedError,\n Subscriber,\n getSubscriptionsManager,\n ClientRequest,\n FollowSubscriptionCb,\n} from \"@polkadot-api/raw-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 { noop, deferred } 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 { 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 const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n // If it's:\n // - a (deferred)`Promise`: it means that the susbscription is active AND that the response to the follow request has not been resolved\n // - a `string`: it means that the subscription is active and that the response to the follow request has been successful.\n // - `null`: it means that the subscription is inactive (for whatever reason: error or unsubscription)\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n let stopListeningToFollowEvents = noop\n const unfollowRequest = (subscriptionId: string) => {\n request(chainHead.unfollow, [subscriptionId])\n }\n\n const stopEverything = (sendUnfollow: boolean) => {\n stopListeningToFollowEvents()\n // if it's `null` it means that everything has already been stopped\n if (followSubscription === null) return\n\n if (sendUnfollow) {\n if (followSubscription instanceof Promise) {\n followSubscription.then((x) => {\n if (typeof x === \"string\") unfollowRequest(x)\n })\n } else unfollowRequest(followSubscription)\n }\n followSubscription = null\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n subscriptions.errorAll(new DisjointError())\n }\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n return subscriptions.next(event.operationId, event)\n }\n\n switch (event.event) {\n case \"stop\":\n onFollowError(new StopError())\n return stopEverything(false)\n case \"initialized\":\n case \"newBlock\":\n case \"bestBlockChanged\":\n case \"finalized\":\n const { event: type, ...rest } = event\n return onFollowEvent({ type, ...rest } as any)\n }\n console.warn(\"Invalid event\", event)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n stopEverything(!(error instanceof DestroyedError))\n }\n\n request(chainHead.follow, [withRuntime], {\n onSuccess: (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n // If the consumer has unsubscribed in between, then it will be `null`\n // and it should stay that way\n if (followSubscription instanceof Promise) {\n followSubscription = subscriptionId\n stopListeningToFollowEvents = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n }\n deferredFollow.res(subscriptionId)\n },\n onError: (e: Error) => {\n followSubscription = null\n deferredFollow.res(e)\n onFollowError(e)\n },\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 stopEverything(true)\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 class BlockHashNotFoundError extends Error {\n constructor(hash: string) {\n super(`Invalid BlockHash: ${hash}`)\n this.name = \"BlockHashNotFoundError\"\n }\n}\n\nexport class StorageError extends Error {\n constructor(message: string) {\n super(`Storage Error: ${message}`)\n this.name = \"StorageError\"\n }\n}\n\nexport class CallError extends Error {\n constructor(message: string) {\n super(`Call Error: ${message}`)\n this.name = \"CallError\"\n }\n}\n","import type { ClientRequest } from \"@polkadot-api/raw-client\"\nimport { noop } from \"@polkadot-api/utils\"\nimport { Archive } from \"./public-types\"\nimport { StorageItemResponse } from \"@/chainhead\"\nimport { StorageError } from \"./errors\"\n\ntype StorageEvent = {\n event: \"storage\"\n} & StorageItemResponse\n\ntype StorageDone = {\n event: \"storageDone\"\n}\n\ntype StorageErrorEvent = {\n event: \"storageError\"\n error: string\n}\n\nexport const createStorageCb =\n (\n archiveRequest: ClientRequest<\n string,\n StorageEvent | StorageDone | StorageErrorEvent\n >,\n ): Archive[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItem, onError, onDone) => {\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 archiveRequest(\"storage\", [hash, inputs, childTrie], {\n onSuccess: (operationId, followSubscription) => {\n const stopOperation = () => {\n archiveRequest(\"stopStorage\", [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(operationId, {\n next: (event) => {\n const { event: type } = event\n if (type === \"storage\") {\n const { event: _, ...item } = event\n onItem(item)\n } else if (type === \"storageDone\") _onDone()\n else _onError(new StorageError(event.error))\n },\n error: onError,\n })\n\n const tearDown = () => {\n cancel = noop\n doneListening()\n }\n\n cancel = () => {\n tearDown()\n stopOperation()\n }\n\n const _onError = (e: Error) => {\n tearDown()\n onError(e)\n }\n\n const _onDone = () => {\n tearDown()\n onDone()\n }\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { abortablePromiseFn } from \"@/internal-utils\"\nimport type { Archive } from \"./public-types\"\n\nexport const createStorageFn = (\n cbStore: Archive[\"storageSubscription\"],\n): Archive[\"storage\"] =>\n abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n\n let result: any = isDescendants ? [] : null\n const onItem: Parameters<typeof cbStore>[3] = isDescendants\n ? result.push.bind(result)\n : ({ [type]: res }) => {\n result = res\n }\n\n return cbStore(\n hash,\n [{ key, type }],\n childTrie,\n onItem,\n (e) => {\n reject(e)\n result = null\n },\n () => {\n resolve(result)\n result = null\n },\n )\n })\n","import { abortablePromiseFn } from \"@/internal-utils\"\nimport { type ClientRequest } from \"@polkadot-api/raw-client\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { createStorageFn } from \"./storage\"\nimport { Archive } from \"./public-types\"\nimport { CallError, BlockHashNotFoundError } from \"./errors\"\n\nconst identity =\n <T>() =>\n (x: T): T =>\n x\n\nconst handleInvalidBlockHash =\n <T>() =>\n (result: T | null, hash: string): T => {\n if (result === null) throw new BlockHashNotFoundError(hash)\n return result\n }\n\nexport const getArchive = (request: ClientRequest<any, any>): Archive => {\n const archiveRequest: ClientRequest<any, any> = (method: string, ...rest) =>\n request(`archive_v1_${method}`, ...rest)\n\n const fnCreator =\n <A extends Array<any>>(method: string) =>\n <I, O>(mapper: (input: I, ...args: A) => O) =>\n abortablePromiseFn<O, A>((res, rej, ...args) =>\n archiveRequest(method, args, {\n onSuccess: (x: I) => {\n try {\n res(mapper(x, ...args))\n } catch (e) {\n rej(e)\n }\n },\n onError: rej,\n }),\n )\n\n const header = fnCreator<[hash: string]>(\"header\")(\n handleInvalidBlockHash<string>(),\n )\n\n const body = fnCreator<[hash: string]>(\"body\")(\n handleInvalidBlockHash<string[]>(),\n )\n\n const storageSubscription = createStorageCb(archiveRequest)\n const storage = createStorageFn(storageSubscription)\n\n const call = fnCreator<\n [hash: string, function: string, callParameters: string]\n >(\"call\")((\n x:\n | { success: true; value: string }\n | { success: false; error: string }\n | null,\n hash,\n ) => {\n if (!x) throw new BlockHashNotFoundError(hash)\n if (!x.success) throw new CallError(x.error)\n return x.value\n })\n\n const finalizedHeight = fnCreator<[]>(\"finalizedHeight\")(identity<number>())\n const hashByHeight =\n fnCreator<[height: number]>(\"hashByHeight\")(identity<string[]>())\n\n return {\n header,\n body,\n storageSubscription,\n storage,\n call,\n finalizedHeight,\n hashByHeight,\n }\n}\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"@polkadot-api/raw-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","import { type ClientRequest } from \"@polkadot-api/raw-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 { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport {\n ClientRequestCb,\n createClient as createRawClient,\n} from \"@polkadot-api/raw-client\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\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 { Archive, getArchive } from \"./archive\"\n\nexport interface SubstrateClient {\n archive: Archive\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\nconst clientCache = new Map<\n JsonRpcProvider,\n { client: SubstrateClient; refCount: number }\n>()\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const cached = clientCache.get(provider)\n if (cached) {\n cached.refCount++\n return cached.client\n }\n\n const { request, disconnect } = createRawClient(provider)\n const destroy = () => {\n const cached = clientCache.get(provider)\n if (!cached || cached.refCount <= 1) {\n clientCache.delete(provider)\n disconnect()\n } else {\n cached.refCount--\n }\n }\n const client: SubstrateClient = {\n archive: getArchive(request),\n chainHead: getChainHead(request),\n transaction: getTransaction(request),\n getChainSpecData: createGetChainSpec(request),\n destroy,\n request: abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => request(method, params, { onSuccess, onError }),\n ),\n _request: request,\n }\n clientCache.set(provider, { client, refCount: 1 })\n return client\n}\n"],"names":["noop","AbortError","fn","createStorageCb","createStorageFn","getSubscriptionsManager","DestroyedError","createRawClient","cached"],"mappings":";;;;;AAAO,MAAM,kBAAkB,KAAA,CAAM;AAAA,EACnC,WAAA,GAAc;AACZ,IAAA,KAAA,CAAM,mBAAmB,CAAA;AACzB,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AAAA,EACd;AACF;AAEO,MAAM,sBAAsB,KAAA,CAAM;AAAA,EACvC,WAAA,GAAc;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C,gBAAA,EAAkB,mBAAmB,OAAO,CAAA;AAAA,IAC5C,OAAA;AAAA,IACA,OAAA,EAAS,kBAAA;AAAA,MACP,CACE,SAAA,EACA,OAAA,EACA,MAAA,EACA,MAAA,KACG,OAAA,CAAQ,MAAA,EAAQ,MAAA,EAAQ,EAAE,SAAA,EAAW,OAAA,EAAS;AAAA,KACrD;AAAA,IACA,QAAA,EAAU;AAAA,GACZ;AACA,EAAA,WAAA,CAAY,IAAI,QAAA,EAAU,EAAE,MAAA,EAAQ,QAAA,EAAU,GAAG,CAAA;AACjD,EAAA,OAAO,MAAA;AACT;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polkadot-api/substrate-client",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "author": "Josep M Sobrepere (https://github.com/josepot)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,6 +35,7 @@
35
35
  "dist"
36
36
  ],
37
37
  "dependencies": {
38
+ "@polkadot-api/raw-client": "0.1.1",
38
39
  "@polkadot-api/utils": "0.2.0",
39
40
  "@polkadot-api/json-rpc-provider": "0.0.4"
40
41
  },
@@ -1,9 +0,0 @@
1
- class DestroyedError extends Error {
2
- constructor() {
3
- super("Client destroyed");
4
- this.name = "DestroyedError";
5
- }
6
- }
7
-
8
- export { DestroyedError };
9
- //# sourceMappingURL=DestroyedError.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DestroyedError.mjs","sources":["../../../src/client/DestroyedError.ts"],"sourcesContent":["export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n"],"names":[],"mappings":"AAAO,MAAM,uBAAuB,KAAM,CAAA;AAAA,EACxC,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,kBAAkB,CAAA;AACxB,IAAA,IAAA,CAAK,IAAO,GAAA,gBAAA;AAAA;AAEhB;;;;"}
@@ -1,16 +0,0 @@
1
- var __defProp = Object.defineProperty;
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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- class RpcError extends Error {
5
- constructor(e) {
6
- super(e.message);
7
- __publicField(this, "code");
8
- __publicField(this, "data");
9
- this.code = e.code;
10
- this.data = e.data;
11
- this.name = "RpcError";
12
- }
13
- }
14
-
15
- export { RpcError };
16
- //# sourceMappingURL=RpcError.mjs.map