@polkadot-api/substrate-client 0.4.1 → 0.4.2

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
@@ -1 +1 @@
1
- {"version":3,"file":"archive.mjs","sources":["../../../src/archive/archive.ts"],"sourcesContent":["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,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ACG,KAAA;AACH,IAAA,IAAI,CAAC,CAAA,EAAS,MAAA,IAAI,uBAAuB,IAAI,CAAA;AAC7C,IAAA,IAAI,CAAC,CAAE,CAAA,OAAA,QAAe,IAAI,SAAA,CAAU,EAAE,KAAK,CAAA;AAC3C,IAAA,OAAO,CAAE,CAAA,KAAA;AAAA,GACV,CAAA;AAED,EAAA,MAAM,eAAkB,GAAA,SAAA,CAAc,iBAAiB,CAAA,CAAE,UAAkB,CAAA;AAC3E,EAAA,MAAM,YACJ,GAAA,SAAA,CAA4B,cAAc,CAAA,CAAE,UAAoB,CAAA;AAElE,EAAO,OAAA;AAAA,IACL,MAAA;AAAA,IACA,IAAA;AAAA,IACA,mBAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,eAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"archive.mjs","sources":["../../../src/archive/archive.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;;AAOA,MAAM,QAAA,GACJ,MACA,CAAC,CAAA,KACC,CAAA;AAEJ,MAAM,sBAAA,GACJ,MACA,CAAC,MAAA,EAAkB,IAAA,KAAoB;AACrC,EAAA,IAAI,MAAA,KAAW,IAAA,EAAM,MAAM,IAAI,uBAAuB,IAAI,CAAA;AAC1D,EAAA,OAAO,MAAA;AACT,CAAA;AAEK,MAAM,UAAA,GAAa,CAAC,OAAA,KAA8C;AACvE,EAAA,MAAM,cAAA,GAA0C,CAAC,MAAA,EAAA,GAAmB,IAAA,KAClE,QAAQ,CAAA,WAAA,EAAc,MAAM,CAAA,CAAA,EAAI,GAAG,IAAI,CAAA;AAEzC,EAAA,MAAM,SAAA,GACJ,CAAuB,MAAA,KACvB,CAAO,MAAA,KACL,kBAAA;AAAA,IAAyB,CAAC,GAAA,EAAK,GAAA,EAAA,GAAQ,IAAA,KACrC,cAAA,CAAe,QAAQ,IAAA,EAAM;AAAA,MAC3B,SAAA,EAAW,CAAC,CAAA,KAAS;AACnB,QAAA,IAAI;AACF,UAAA,GAAA,CAAI,MAAA,CAAO,CAAA,EAAG,GAAG,IAAI,CAAC,CAAA;AAAA,QACxB,SAAS,CAAA,EAAG;AACV,UAAA,GAAA,CAAI,CAAC,CAAA;AAAA,QACP;AAAA,MACF,CAAA;AAAA,MACA,OAAA,EAAS;AAAA,KACV;AAAA,GACH;AAEJ,EAAA,MAAM,MAAA,GAAS,UAA0B,QAAQ,CAAA;AAAA,IAC/C,sBAAA;AAA+B,GACjC;AAEA,EAAA,MAAM,IAAA,GAAO,UAA0B,MAAM,CAAA;AAAA,IAC3C,sBAAA;AAAiC,GACnC;AAEA,EAAA,MAAM,mBAAA,GAAsB,gBAAgB,cAAc,CAAA;AAC1D,EAAA,MAAM,OAAA,GAAU,gBAAgB,mBAAmB,CAAA;AAEnD,EAAA,MAAM,OAAO,SAAA,CAEX,MAAM,CAAA,CAAE,CACR,GAIA,IAAA,KACG;AACH,IAAA,IAAI,CAAC,CAAA,EAAG,MAAM,IAAI,uBAAuB,IAAI,CAAA;AAC7C,IAAA,IAAI,CAAC,CAAA,CAAE,OAAA,QAAe,IAAI,SAAA,CAAU,EAAE,KAAK,CAAA;AAC3C,IAAA,OAAO,CAAA,CAAE,KAAA;AAAA,EACX,CAAC,CAAA;AAED,EAAA,MAAM,eAAA,GAAkB,SAAA,CAAc,iBAAiB,CAAA,CAAE,UAAkB,CAAA;AAC3E,EAAA,MAAM,YAAA,GACJ,SAAA,CAA4B,cAAc,CAAA,CAAE,UAAoB,CAAA;AAElE,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,IAAA;AAAA,IACA,mBAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,eAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","sources":["../../../src/archive/errors.ts"],"sourcesContent":["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"],"names":[],"mappings":"AAAO,MAAM,+BAA+B,KAAM,CAAA;AAAA,EAChD,YAAY,IAAc,EAAA;AACxB,IAAM,KAAA,CAAA,CAAA,mBAAA,EAAsB,IAAI,CAAE,CAAA,CAAA;AAClC,IAAA,IAAA,CAAK,IAAO,GAAA,wBAAA;AAAA;AAEhB;AAEO,MAAM,qBAAqB,KAAM,CAAA;AAAA,EACtC,YAAY,OAAiB,EAAA;AAC3B,IAAM,KAAA,CAAA,CAAA,eAAA,EAAkB,OAAO,CAAE,CAAA,CAAA;AACjC,IAAA,IAAA,CAAK,IAAO,GAAA,cAAA;AAAA;AAEhB;AAEO,MAAM,kBAAkB,KAAM,CAAA;AAAA,EACnC,YAAY,OAAiB,EAAA;AAC3B,IAAM,KAAA,CAAA,CAAA,YAAA,EAAe,OAAO,CAAE,CAAA,CAAA;AAC9B,IAAA,IAAA,CAAK,IAAO,GAAA,WAAA;AAAA;AAEhB;;;;"}
1
+ {"version":3,"file":"errors.mjs","sources":["../../../src/archive/errors.ts"],"sourcesContent":["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"],"names":[],"mappings":"AAAO,MAAM,+BAA+B,KAAA,CAAM;AAAA,EAChD,YAAY,IAAA,EAAc;AACxB,IAAA,KAAA,CAAM,CAAA,mBAAA,EAAsB,IAAI,CAAA,CAAE,CAAA;AAClC,IAAA,IAAA,CAAK,IAAA,GAAO,wBAAA;AAAA,EACd;AACF;AAEO,MAAM,qBAAqB,KAAA,CAAM;AAAA,EACtC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,CAAA,eAAA,EAAkB,OAAO,CAAA,CAAE,CAAA;AACjC,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AAAA,EACd;AACF;AAEO,MAAM,kBAAkB,KAAA,CAAM;AAAA,EACnC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,CAAA,YAAA,EAAe,OAAO,CAAA,CAAE,CAAA;AAC9B,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AAAA,EACd;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"storage-subscription.mjs","sources":["../../../src/archive/storage-subscription.ts"],"sourcesContent":["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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A,MAAM,WAAW,MAAM;AACrB,QAAS,MAAA,GAAA,IAAA;AACT,QAAc,aAAA,EAAA;AAAA,OAChB;AAEA,MAAA,MAAA,GAAS,MAAM;AACb,QAAS,QAAA,EAAA;AACT,QAAc,aAAA,EAAA;AAAA,OAChB;AAEA,MAAM,MAAA,QAAA,GAAW,CAAC,CAAa,KAAA;AAC7B,QAAS,QAAA,EAAA;AACT,QAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,OACX;AAEA,MAAA,MAAM,UAAU,MAAM;AACpB,QAAS,QAAA,EAAA;AACT,QAAO,MAAA,EAAA;AAAA,OACT;AAAA,KACF;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAO,MAAA,EAAA;AAAA,GACT;AACF;;;;"}
1
+ {"version":3,"file":"storage-subscription.mjs","sources":["../../../src/archive/storage-subscription.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;AAmBO,MAAM,eAAA,GACX,CACE,cAAA,KAKF,CAAC,MAAM,MAAA,EAAQ,SAAA,EAAW,MAAA,EAAQ,OAAA,EAAS,MAAA,KAAW;AACpD,EAAA,IAAI,MAAA,CAAO,WAAW,CAAA,EAAG;AACvB,IAAA,MAAA,EAAO;AACP,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,IAAI,SAAA,GAAY,IAAA;AAChB,EAAA,IAAI,SAAS,MAAM;AACjB,IAAA,SAAA,GAAY,KAAA;AAAA,EACd,CAAA;AAEA,EAAA,cAAA,CAAe,SAAA,EAAW,CAAC,IAAA,EAAM,MAAA,EAAQ,SAAS,CAAA,EAAG;AAAA,IACnD,SAAA,EAAW,CAAC,WAAA,EAAa,kBAAA,KAAuB;AAC9C,MAAA,MAAM,gBAAgB,MAAM;AAC1B,QAAA,cAAA,CAAe,aAAA,EAAe,CAAC,WAAW,CAAC,CAAA;AAAA,MAC7C,CAAA;AAEA,MAAA,IAAI,CAAC,SAAA,EAAW,OAAO,aAAA,EAAc;AAErC,MAAA,MAAM,aAAA,GAAgB,mBAAmB,WAAA,EAAa;AAAA,QACpD,IAAA,EAAM,CAAC,KAAA,KAAU;AACf,UAAA,MAAM,EAAE,KAAA,EAAO,IAAA,EAAK,GAAI,KAAA;AACxB,UAAA,IAAI,SAAS,SAAA,EAAW;AACtB,YAAA,MAAM,EAAE,KAAA,EAAO,CAAA,EAAG,GAAG,MAAK,GAAI,KAAA;AAC9B,YAAA,MAAA,CAAO,IAAI,CAAA;AAAA,UACb,CAAA,MAAA,IAAW,IAAA,KAAS,aAAA,EAAe,OAAA,EAAQ;AAAA,eACtC,QAAA,CAAS,IAAI,YAAA,CAAa,KAAA,CAAM,KAAK,CAAC,CAAA;AAAA,QAC7C,CAAA;AAAA,QACA,KAAA,EAAO;AAAA,OACR,CAAA;AAED,MAAA,MAAM,WAAW,MAAM;AACrB,QAAA,MAAA,GAAS,IAAA;AACT,QAAA,aAAA,EAAc;AAAA,MAChB,CAAA;AAEA,MAAA,MAAA,GAAS,MAAM;AACb,QAAA,QAAA,EAAS;AACT,QAAA,aAAA,EAAc;AAAA,MAChB,CAAA;AAEA,MAAA,MAAM,QAAA,GAAW,CAAC,CAAA,KAAa;AAC7B,QAAA,QAAA,EAAS;AACT,QAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MACX,CAAA;AAEA,MAAA,MAAM,UAAU,MAAM;AACpB,QAAA,QAAA,EAAS;AACT,QAAA,MAAA,EAAO;AAAA,MACT,CAAA;AAAA,IACF,CAAA;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAA,MAAA,EAAO;AAAA,EACT,CAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"storage.mjs","sources":["../../../src/archive/storage.ts"],"sourcesContent":["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"],"names":[],"mappings":";;AAGa,MAAA,eAAA,GAAkB,CAC7B,OAAA,KAEA,kBAAmB,CAAA,CAAC,SAAS,MAAQ,EAAA,IAAA,EAAM,IAAM,EAAA,GAAA,EAAK,SAAc,KAAA;AAClE,EAAM,MAAA,aAAA,GAAgB,IAAK,CAAA,UAAA,CAAW,aAAa,CAAA;AAEnD,EAAI,IAAA,MAAA,GAAc,aAAgB,GAAA,EAAK,GAAA,IAAA;AACvC,EAAA,MAAM,MAAwC,GAAA,aAAA,GAC1C,MAAO,CAAA,IAAA,CAAK,IAAK,CAAA,MAAM,CACvB,GAAA,CAAC,EAAE,CAAC,IAAO,GAAA,GAAA,EAAU,KAAA;AACnB,IAAS,MAAA,GAAA,GAAA;AAAA,GACX;AAEJ,EAAO,OAAA,OAAA;AAAA,IACL,IAAA;AAAA,IACA,CAAC,EAAE,GAAK,EAAA,IAAA,EAAM,CAAA;AAAA,IACd,SAAA;AAAA,IACA,MAAA;AAAA,IACA,CAAC,CAAM,KAAA;AACL,MAAA,MAAA,CAAO,CAAC,CAAA;AACR,MAAS,MAAA,GAAA,IAAA;AAAA,KACX;AAAA,IACA,MAAM;AACJ,MAAA,OAAA,CAAQ,MAAM,CAAA;AACd,MAAS,MAAA,GAAA,IAAA;AAAA;AACX,GACF;AACF,CAAC;;;;"}
1
+ {"version":3,"file":"storage.mjs","sources":["../../../src/archive/storage.ts"],"sourcesContent":["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"],"names":[],"mappings":";;AAGO,MAAM,eAAA,GAAkB,CAC7B,OAAA,KAEA,kBAAA,CAAmB,CAAC,SAAS,MAAA,EAAQ,IAAA,EAAM,IAAA,EAAM,GAAA,EAAK,SAAA,KAAc;AAClE,EAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,UAAA,CAAW,aAAa,CAAA;AAEnD,EAAA,IAAI,MAAA,GAAc,aAAA,GAAgB,EAAC,GAAI,IAAA;AACvC,EAAA,MAAM,MAAA,GAAwC,aAAA,GAC1C,MAAA,CAAO,IAAA,CAAK,IAAA,CAAK,MAAM,CAAA,GACvB,CAAC,EAAE,CAAC,IAAA,GAAO,GAAA,EAAI,KAAM;AACnB,IAAA,MAAA,GAAS,GAAA;AAAA,EACX,CAAA;AAEJ,EAAA,OAAO,OAAA;AAAA,IACL,IAAA;AAAA,IACA,CAAC,EAAE,GAAA,EAAK,IAAA,EAAM,CAAA;AAAA,IACd,SAAA;AAAA,IACA,MAAA;AAAA,IACA,CAAC,CAAA,KAAM;AACL,MAAA,MAAA,CAAO,CAAC,CAAA;AACR,MAAA,MAAA,GAAS,IAAA;AAAA,IACX,CAAA;AAAA,IACA,MAAM;AACJ,MAAA,OAAA,CAAQ,MAAM,CAAA;AACd,MAAA,MAAA,GAAS,IAAA;AAAA,IACX;AAAA,GACF;AACF,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"body.mjs","sources":["../../../src/chainhead/body.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;AAIO,MAAM,YAAe,GAAA,sBAAA;AAAA,EAC1B,SAAU,CAAA,IAAA;AAAA,EACV,CAAC,IAAiB,KAAA;AAAA,IAChB,CAAC,IAAI,CAAA;AAAA,IACL,CAAC,GAAyB,GAAoC,KAAA;AAC5D,MAAA,GAAA,CAAI,EAAE,KAAK,CAAA;AAAA;AACb;AAEJ;;;;"}
1
+ {"version":3,"file":"body.mjs","sources":["../../../src/chainhead/body.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;AAIO,MAAM,YAAA,GAAe,sBAAA;AAAA,EAC1B,SAAA,CAAU,IAAA;AAAA,EACV,CAAC,IAAA,KAAiB;AAAA,IAChB,CAAC,IAAI,CAAA;AAAA,IACL,CAAC,GAAyB,GAAA,KAAoC;AAC5D,MAAA,GAAA,CAAI,EAAE,KAAK,CAAA;AAAA,IACb;AAAA;AAEJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"call.mjs","sources":["../../../src/chainhead/call.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;AAIO,MAAM,YAAe,GAAA,sBAAA;AAAA,EAC1B,SAAU,CAAA,IAAA;AAAA,EACV,CAAC,IAAc,EAAA,MAAA,EAAgB,cAA2B,KAAA;AAAA,IACxD,CAAC,IAAM,EAAA,MAAA,EAAQ,cAAc,CAAA;AAAA,IAC7B,CAAC,GAAyB,GAAkC,KAAA;AAC1D,MAAA,GAAA,CAAI,EAAE,MAAM,CAAA;AAAA;AACd;AAEJ;;;;"}
1
+ {"version":3,"file":"call.mjs","sources":["../../../src/chainhead/call.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;AAIO,MAAM,YAAA,GAAe,sBAAA;AAAA,EAC1B,SAAA,CAAU,IAAA;AAAA,EACV,CAAC,IAAA,EAAc,MAAA,EAAgB,cAAA,KAA2B;AAAA,IACxD,CAAC,IAAA,EAAM,MAAA,EAAQ,cAAc,CAAA;AAAA,IAC7B,CAAC,GAAyB,GAAA,KAAkC;AAC1D,MAAA,GAAA,CAAI,EAAE,MAAM,CAAA;AAAA,IACd;AAAA;AAEJ;;;;"}
@@ -1,15 +1,14 @@
1
+ import { getSubscriptionsManager, DestroyedError } from '@polkadot-api/raw-client';
1
2
  import '@polkadot-api/utils';
2
3
  import { deferred } from '../internal-utils/deferred-promise.mjs';
3
4
  import { noop } from '../internal-utils/noop.mjs';
4
- import { getSubscriptionsManager } from '../internal-utils/subscriptions-manager.mjs';
5
5
  import { createBodyFn } from './body.mjs';
6
6
  import { createCallFn } from './call.mjs';
7
7
  import { createHeaderFn } from './header.mjs';
8
8
  import { createStorageFn } from './storage.mjs';
9
9
  import { createUnpinFn } from './unpin.mjs';
10
- import { DisjointError, StopError } from './errors.mjs';
10
+ import { StopError, DisjointError } from './errors.mjs';
11
11
  import { createStorageCb } from './storage-subscription.mjs';
12
- import { DestroyedError } from '../client/DestroyedError.mjs';
13
12
  import { chainHead } from '../methods.mjs';
14
13
 
15
14
  function isOperationEvent(event) {
@@ -21,63 +20,67 @@ function getChainHead(request) {
21
20
  const ongoingRequests = /* @__PURE__ */ new Set();
22
21
  const deferredFollow = deferred();
23
22
  let followSubscription = deferredFollow.promise;
23
+ let stopListeningToFollowEvents = noop;
24
+ const unfollowRequest = (subscriptionId) => {
25
+ request(chainHead.unfollow, [subscriptionId]);
26
+ };
27
+ const stopEverything = (sendUnfollow) => {
28
+ stopListeningToFollowEvents();
29
+ if (followSubscription === null) return;
30
+ if (sendUnfollow) {
31
+ if (followSubscription instanceof Promise) {
32
+ followSubscription.then((x) => {
33
+ if (typeof x === "string") unfollowRequest(x);
34
+ });
35
+ } else unfollowRequest(followSubscription);
36
+ }
37
+ followSubscription = null;
38
+ ongoingRequests.forEach((cb) => {
39
+ cb();
40
+ });
41
+ ongoingRequests.clear();
42
+ subscriptions.errorAll(new DisjointError());
43
+ };
24
44
  const onAllFollowEventsNext = (event) => {
25
45
  if (isOperationEvent(event)) {
26
46
  if (!subscriptions.has(event.operationId))
27
47
  console.warn("Uknown operationId on", event);
28
48
  return subscriptions.next(event.operationId, event);
29
49
  }
30
- if (event.event !== "stop") {
31
- if (event.event === "initialized") {
32
- return onFollowEvent({
33
- type: event.event,
34
- finalizedBlockHashes: event.finalizedBlockHashes,
35
- finalizedBlockRuntime: event.finalizedBlockRuntime
36
- });
37
- }
38
- const { event: type, ...rest } = event;
39
- return onFollowEvent({ type, ...rest });
50
+ switch (event.event) {
51
+ case "stop":
52
+ onFollowError(new StopError());
53
+ return stopEverything(false);
54
+ case "initialized":
55
+ case "newBlock":
56
+ case "bestBlockChanged":
57
+ case "finalized":
58
+ const { event: type, ...rest } = event;
59
+ return onFollowEvent({ type, ...rest });
40
60
  }
41
- onFollowError(new StopError());
42
- unfollow(false);
61
+ console.warn("Invalid event", event);
43
62
  };
44
63
  const onAllFollowEventsError = (error) => {
45
64
  onFollowError(error);
46
- unfollow(!(error instanceof DestroyedError));
65
+ stopEverything(!(error instanceof DestroyedError));
47
66
  };
48
- const onFollowRequestSuccess = (subscriptionId, follow) => {
49
- const done = follow(subscriptionId, {
50
- next: onAllFollowEventsNext,
51
- error: onAllFollowEventsError
52
- });
53
- unfollow = (sendUnfollow = true) => {
67
+ request(chainHead.follow, [withRuntime], {
68
+ onSuccess: (subscriptionId, follow) => {
69
+ if (followSubscription instanceof Promise) {
70
+ followSubscription = subscriptionId;
71
+ stopListeningToFollowEvents = follow(subscriptionId, {
72
+ next: onAllFollowEventsNext,
73
+ error: onAllFollowEventsError
74
+ });
75
+ }
76
+ deferredFollow.res(subscriptionId);
77
+ },
78
+ onError: (e) => {
54
79
  followSubscription = null;
55
- unfollow = noop;
56
- done();
57
- sendUnfollow && request(chainHead.unfollow, [subscriptionId]);
58
- subscriptions.errorAll(new DisjointError());
59
- ongoingRequests.forEach((cb) => {
60
- cb();
61
- });
62
- ongoingRequests.clear();
63
- };
64
- followSubscription = subscriptionId;
65
- deferredFollow.res(subscriptionId);
66
- };
67
- const onFollowRequestError = (e) => {
68
- if (e instanceof DestroyedError) {
69
- unfollow(false);
70
- } else {
80
+ deferredFollow.res(e);
71
81
  onFollowError(e);
72
82
  }
73
- followSubscription = null;
74
- deferredFollow.res(e);
75
- };
76
- let unfollow = request(
77
- chainHead.follow,
78
- [withRuntime],
79
- { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError }
80
- );
83
+ });
81
84
  const fRequest = (method, params, cb) => {
82
85
  const disjoint = () => {
83
86
  cb?.onError(new DisjointError());
@@ -127,8 +130,7 @@ function getChainHead(request) {
127
130
  };
128
131
  return {
129
132
  unfollow() {
130
- unfollow();
131
- followSubscription = null;
133
+ stopEverything(true);
132
134
  },
133
135
  body: createBodyFn(fRequest),
134
136
  call: createCallFn(fRequest),
@@ -1 +1 @@
1
- {"version":3,"file":"chainhead.mjs","sources":["../../../src/chainhead/chainhead.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;;;;;;;;;;;AAoCA,SAAS,iBAAiB,KAAoD,EAAA;AAC5E,EAAA,OAAQ,MAA6B,WAAgB,KAAA,MAAA;AACvD;AAEO,SAAS,aACd,OACW,EAAA;AACX,EAAO,OAAA,CACL,WACA,EAAA,aAAA,EAGA,aACmB,KAAA;AACnB,IAAA,MAAM,gBAAgB,uBAA4C,EAAA;AAElE,IAAM,MAAA,eAAA,uBAAsB,GAAgB,EAAA;AAC5C,IAAA,MAAM,iBAAiB,QAAyB,EAAA;AAChD,IAAA,IAAI,qBACF,cAAe,CAAA,OAAA;AAEjB,IAAM,MAAA,qBAAA,GAAwB,CAAC,KAA0B,KAAA;AACvD,MAAI,IAAA,gBAAA,CAAiB,KAAK,CAAG,EAAA;AAC3B,QAAA,IAAI,CAAC,aAAA,CAAc,GAAI,CAAA,KAAA,CAAM,WAAW,CAAA;AACtC,UAAQ,OAAA,CAAA,IAAA,CAAK,yBAAyB,KAAK,CAAA;AAE7C,QAAA,OAAO,aAAc,CAAA,IAAA,CAAK,KAAM,CAAA,WAAA,EAAa,KAAK,CAAA;AAAA;AAGpD,MAAI,IAAA,KAAA,CAAM,UAAU,MAAQ,EAAA;AAC1B,QAAI,IAAA,KAAA,CAAM,UAAU,aAAe,EAAA;AACjC,UAAA,OAAO,aAAc,CAAA;AAAA,YACnB,MAAM,KAAM,CAAA,KAAA;AAAA,YACZ,sBAAsB,KAAM,CAAA,oBAAA;AAAA,YAC5B,uBAAwB,KAAc,CAAA;AAAA,WACvC,CAAA;AAAA;AAGH,QAAA,MAAM,EAAE,KAAA,EAAO,IAAM,EAAA,GAAG,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["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"],"names":[],"mappings":";;;;;;;;;;;;;AAoCA,SAAS,iBAAiB,KAAA,EAAoD;AAC5E,EAAA,OAAQ,MAA6B,WAAA,KAAgB,MAAA;AACvD;AAEO,SAAS,aACd,OAAA,EACW;AACX,EAAA,OAAO,CACL,WAAA,EACA,aAAA,EAGA,aAAA,KACmB;AACnB,IAAA,MAAM,gBAAgB,uBAAA,EAA4C;AAClE,IAAA,MAAM,eAAA,uBAAsB,GAAA,EAAgB;AAC5C,IAAA,MAAM,iBAAiB,QAAA,EAAyB;AAKhD,IAAA,IAAI,qBACF,cAAA,CAAe,OAAA;AAEjB,IAAA,IAAI,2BAAA,GAA8B,IAAA;AAClC,IAAA,MAAM,eAAA,GAAkB,CAAC,cAAA,KAA2B;AAClD,MAAA,OAAA,CAAQ,SAAA,CAAU,QAAA,EAAU,CAAC,cAAc,CAAC,CAAA;AAAA,IAC9C,CAAA;AAEA,IAAA,MAAM,cAAA,GAAiB,CAAC,YAAA,KA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AAA,EAAS;AACxC,QAAA,IAAI,kBAAA,EAAoB,QAAA,GAAW,cAAA,CAAe,CAAC,CAAA;AAAA,MACrD,CAAC,CAAA;AAED,MAAA,OAAO,MAAM;AACX,QAAA,QAAA,EAAS;AAAA,MACX,CAAA;AAAA,IACF,CAAA;AAEA,IAAA,OAAO;AAAA,MACL,QAAA,GAAW;AACT,QAAA,cAAA,CAAe,IAAI,CAAA;AAAA,MACrB,CAAA;AAAA,MACA,IAAA,EAAM,aAAa,QAAQ,CAAA;AAAA,MAC3B,IAAA,EAAM,aAAa,QAAQ,CAAA;AAAA,MAC3B,MAAA,EAAQ,eAAe,QAAQ,CAAA;AAAA,MAC/B,OAAA,EAAS,gBAAgB,QAAQ,CAAA;AAAA,MACjC,mBAAA,EAAqB,gBAAgB,QAAQ,CAAA;AAAA,MAC7C,KAAA,EAAO,cAAc,QAAQ,CAAA;AAAA,MAC7B,QAAA,EAAU;AAAA,KACZ;AAAA,EACF,CAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","sources":["../../../src/chainhead/errors.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"],"names":[],"mappings":"AAAO,MAAM,kBAAkB,KAAM,CAAA;AAAA,EACnC,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,mBAAmB,CAAA;AACzB,IAAA,IAAA,CAAK,IAAO,GAAA,WAAA;AAAA;AAEhB;AAEO,MAAM,sBAAsB,KAAM,CAAA;AAAA,EACvC,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,sBAAsB,CAAA;AAC5B,IAAA,IAAA,CAAK,IAAO,GAAA,eAAA;AAAA;AAEhB;AAEO,MAAM,4BAA4B,KAAM,CAAA;AAAA,EAC7C,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,oCAAoC,CAAA;AAC1C,IAAA,IAAA,CAAK,IAAO,GAAA,qBAAA;AAAA;AAEhB;AAEO,MAAM,uBAAuB,KAAM,CAAA;AAAA,EACxC,YAAY,KAAe,EAAA;AACzB,IAAA,KAAA,CAAM,KAAK,CAAA;AACX,IAAA,IAAA,CAAK,IAAO,GAAA,gBAAA;AAAA;AAEhB;AAEO,MAAM,mCAAmC,KAAM,CAAA;AAAA,EACpD,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,kCAAkC,CAAA;AACxC,IAAA,IAAA,CAAK,IAAO,GAAA,4BAAA;AAAA;AAEhB;;;;"}
1
+ {"version":3,"file":"errors.mjs","sources":["../../../src/chainhead/errors.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"],"names":[],"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;AACZ,IAAA,KAAA,CAAM,sBAAsB,CAAA;AAC5B,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AAAA,EACd;AACF;AAEO,MAAM,4BAA4B,KAAA,CAAM;AAAA,EAC7C,WAAA,GAAc;AACZ,IAAA,KAAA,CAAM,oCAAoC,CAAA;AAC1C,IAAA,IAAA,CAAK,IAAA,GAAO,qBAAA;AAAA,EACd;AACF;AAEO,MAAM,uBAAuB,KAAA,CAAM;AAAA,EACxC,YAAY,KAAA,EAAe;AACzB,IAAA,KAAA,CAAM,KAAK,CAAA;AACX,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AAAA,EACd;AACF;AAEO,MAAM,mCAAmC,KAAA,CAAM;AAAA,EACpD,WAAA,GAAc;AACZ,IAAA,KAAA,CAAM,kCAAkC,CAAA;AACxC,IAAA,IAAA,CAAK,IAAA,GAAO,4BAAA;AAAA,EACd;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"header.mjs","sources":["../../../src/chainhead/header.ts"],"sourcesContent":["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"],"names":[],"mappings":";;AAGa,MAAA,cAAA,GACX,CAAC,OAAiD,KAAA,CAAC,SACjD,IAAI,OAAA,CAAgB,CAAC,GAAA,EAAK,GAAQ,KAAA;AAChC,EAAA,OAAA,CAAQ,SAAU,CAAA,MAAA,EAAQ,CAAC,IAAI,CAAG,EAAA;AAAA,IAChC,SAAW,EAAA,GAAA;AAAA,IACX,OAAS,EAAA;AAAA,GACV,CAAA;AACH,CAAC;;;;"}
1
+ {"version":3,"file":"header.mjs","sources":["../../../src/chainhead/header.ts"],"sourcesContent":["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"],"names":[],"mappings":";;AAGO,MAAM,cAAA,GACX,CAAC,OAAA,KAAiD,CAAC,SACjD,IAAI,OAAA,CAAgB,CAAC,GAAA,EAAK,GAAA,KAAQ;AAChC,EAAA,OAAA,CAAQ,SAAA,CAAU,MAAA,EAAQ,CAAC,IAAI,CAAA,EAAG;AAAA,IAChC,SAAA,EAAW,GAAA;AAAA,IACX,OAAA,EAAS;AAAA,GACV,CAAA;AACH,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"operation-promise.mjs","sources":["../../../src/chainhead/operation-promise.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;;AAaa,MAAA,sBAAA,GACX,CACE,aAAA,EACA,OAOF,KAAA,CACE,YAKA,kBAAyB,CAAA,CAAC,GAAK,EAAA,GAAA,EAAA,GAAQ,IAAS,KAAA;AAC9C,EAAA,IAAI,SAAY,GAAA,IAAA;AAChB,EAAA,IAAI,SAAS,MAAM;AACjB,IAAY,SAAA,GAAA,KAAA;AAAA,GACd;AAEA,EAAA,MAAM,CAAC,WAAa,EAAA,OAAO,CAAI,GAAA,OAAA,CAAQ,GAAG,IAAI,CAAA;AAC9C,EAAA,OAAA,CAAQ,eAAe,WAAa,EAAA;AAAA,IAClC,SAAA,EAAW,CAAC,QAAA,EAAU,kBAAuB,KAAA;AAC3C,MAAA,IAAI,SAAS,MAAW,KAAA,cAAA;AACtB,QAAO,OAAA,GAAA,CAAI,IAAI,mBAAA,EAAqB,CAAA;AAEtC,MAAM,MAAA,EAAE,aAAgB,GAAA,QAAA;AACxB,MAAA,MAAM,gBAAgB,MAAM;AAC1B,QAAA,OAAA,CAAQ,SAAU,CAAA,aAAA,EAAe,CAAC,WAAW,CAAC,CAAA;AAAA,OAChD;AAEA,MAAI,IAAA,CAAC,SAAW,EAAA,OAAO,aAAc,EAAA;AAErC,MAAA,IAAI,IAAO,GAAA,IAAA;AACX,MAAM,MAAA,IAAA,GAAO,CAAC,CAAS,KAAA;AACrB,QAAY,SAAA,GAAA,KAAA;AACZ,QAAK,IAAA,EAAA;AACL,QAAA,GAAA,CAAI,CAAC,CAAA;AAAA,OACP;AACA,MAAM,MAAA,IAAA,GAAO,CAAC,CAAa,KAAA;AACzB,QAAY,SAAA,GAAA,KAAA;AACZ,QAAK,IAAA,EAAA;AACL,QAAA,GAAA,CAAI,CAAC,CAAA;AAAA,OACP;AAEA,MAAA,IAAA,GAAO,mBAAmB,WAAa,EAAA;AAAA,QACrC,IAAA,EAAM,CAAC,CAAM,KAAA;AACX,UAAA,MAAM,EAAK,GAAA,CAAA;AACX,UAAA,IAAI,GAAG,KAAU,KAAA,gBAAA;AACf,YAAA,GAAA,CAAI,IAAI,cAAA,CAAe,EAAG,CAAA,KAAK,CAAC,CAAA;AAAA,eAAA,IACzB,GAAG,KAAU,KAAA,uBAAA;AACpB,YAAI,GAAA,CAAA,IAAI,4BAA4B,CAAA;AAAA,eACjC,OAAA,CAAQ,CAAQ,EAAA,IAAA,EAAM,IAAI,CAAA;AAAA,SACjC;AAAA,QACA,KAAO,EAAA;AAAA,OACR,CAAA;AAED,MAAA,MAAA,GAAS,MAAM;AACb,QAAA,IAAI,SAAW,EAAA;AACb,UAAK,IAAA,EAAA;AACL,UAAc,aAAA,EAAA;AAAA;AAChB,OACF;AAAA,KACF;AAAA,IACA,OAAS,EAAA;AAAA,GACV,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAO,MAAA,EAAA;AAAA,GACT;AACF,CAAC;;;;"}
1
+ {"version":3,"file":"operation-promise.mjs","sources":["../../../src/chainhead/operation-promise.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;;AAaO,MAAM,sBAAA,GACX,CACE,aAAA,EACA,OAAA,KAOF,CACE,YAKA,kBAAA,CAAyB,CAAC,GAAA,EAAK,GAAA,EAAA,GAAQ,IAAA,KAAS;AAC9C,EAAA,IAAI,SAAA,GAAY,IAAA;AAChB,EAAA,IAAI,SAAS,MAAM;AACjB,IAAA,SAAA,GAAY,KAAA;AAAA,EACd,CAAA;AAEA,EAAA,MAAM,CAAC,WAAA,EAAa,OAAO,CAAA,GAAI,OAAA,CAAQ,GAAG,IAAI,CAAA;AAC9C,EAAA,OAAA,CAAQ,eAAe,WAAA,EAAa;AAAA,IAClC,SAAA,EAAW,CAAC,QAAA,EAAU,kBAAA,KAAuB;AAC3C,MAAA,IAAI,SAAS,MAAA,KAAW,cAAA;AACtB,QAAA,OAAO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AA;AAED,EAAA,OAAO,MAAM;AACX,IAAA,MAAA,EAAO;AAAA,EACT,CAAA;AACF,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"storage-subscription.mjs","sources":["../../../src/chainhead/storage-subscription.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;AAiBa,MAAA,eAAA,GACX,CACE,OAAA,KAQF,CAAC,IAAA,EAAM,QAAQ,SAAW,EAAA,OAAA,EAAS,OAAS,EAAA,MAAA,EAAQ,gBAAqB,KAAA;AACvE,EAAI,IAAA,MAAA,CAAO,WAAW,CAAG,EAAA;AACvB,IAAO,MAAA,EAAA;AACP,IAAO,OAAA,IAAA;AAAA;AAGT,EAAA,IAAI,SAAY,GAAA,IAAA;AAChB,EAAA,IAAI,SAAS,MAAM;AACjB,IAAY,SAAA,GAAA,KAAA;AAAA,GACd;AAEA,EAAA,OAAA,CAAQ,UAAU,OAAS,EAAA,CAAC,IAAM,EAAA,MAAA,EAAQ,SAAS,CAAG,EAAA;AAAA,IACpD,SAAA,EAAW,CAAC,QAAA,EAAU,kBAAuB,KAAA;AAC3C,MAAA,IACE,QAAS,CAAA,MAAA,KAAW,cACpB,IAAA,QAAA,CAAS,mBAAmB,MAAO,CAAA,MAAA;AAEnC,QAAO,OAAA,OAAA,CAAQ,IAAI,mBAAA,EAAqB,CAAA;AAE1C,MAAM,MAAA,EAAE,aAAgB,GAAA,QAAA;AACxB,MAAA,MAAM,gBAAgB,MAAM;AAC1B,QAAA,OAAA,CAAQ,SAAU,CAAA,aAAA,EAAe,CAAC,WAAW,CAAC,CAAA;AAAA,OAChD;AAEA,MAAI,IAAA,CAAC,SAAW,EAAA,OAAO,aAAc,EAAA;AAErC,MAAM,MAAA,aAAA,GAAgB,kBAAmB,CAAA,QAAA,CAAS,WAAa,EAAA;AAAA,QAC7D,IAAA,EAAM,CAAC,KAAU,KAAA;AACf,UAAA,QAAQ,MAAM,KAAO;AAAA,YACnB,KAAK,uBAAyB,EAAA;AAC5B,cAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AACnB,cAAA;AAAA;AACF,YACA,KAAK,sBAAwB,EAAA;AAC3B,cAAQ,OAAA,EAAA;AACR,cAAA;AAAA;AACF,YACA,KAAK,gBAAkB,EAAA;AACrB,cAAA,QAAA,CAAS,IAAI,cAAA,CAAe,KAAM,CAAA,KAAK,CAAC,CAAA;AACxC,cAAA;AAAA;AACF,YACA,KAAK,uBAAyB,EAAA;AAC5B,cAAS,QAAA,CAAA,IAAI,4BAA4B,CAAA;AACzC,cAAA;AAAA;AACF,YACA;AACE,cAAA,OAAA,CAAQ,SAAU,CAAA,QAAA,EAAU,CAAC,KAAA,CAAM,WAAW,CAAC,CAAA;AAAA;AACnD,SACF;AAAA,QACA,KAAO,EAAA;AAAA,OACR,CAAA;AAED,MAAA,MAAA,GAAS,MAAM;AACb,QAAc,aAAA,EAAA;AACd,QAAA,OAAA,CAAQ,SAAU,CAAA,aAAA,EAAe,CAAC,QAAA,CAAS,WAAW,CAAC,CAAA;AAAA,OACzD;AAEA,MAAM,MAAA,QAAA,GAAW,CAAC,CAAa,KAAA;AAC7B,QAAS,MAAA,GAAA,IAAA;AACT,QAAc,aAAA,EAAA;AACd,QAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,OACX;AAEA,MAAA,MAAM,UAAU,MAAM;AACpB,QAAS,MAAA,GAAA,IAAA;AACT,QAAc,aAAA,EAAA;AACd,QAAO,MAAA,EAAA;AAAA,OACT;AAEA,MAAA,gBAAA,CAAiB,SAAS,cAAc,CAAA;AAAA,KAC1C;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAO,MAAA,EAAA;AAAA,GACT;AACF;;;;"}
1
+ {"version":3,"file":"storage-subscription.mjs","sources":["../../../src/chainhead/storage-subscription.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;AAiBO,MAAM,eAAA,GACX,CACE,OAAA,KAQF,CAAC,IAAA,EAAM,QAAQ,SAAA,EAAW,OAAA,E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ACF;AAAA,YACA,KAAK,uBAAA,EAAyB;AAC5B,cAAA,QAAA,CAAS,IAAI,4BAA4B,CAAA;AACzC,cAAA;AAAA,YACF;AAAA,YACA;AACE,cAAA,OAAA,CAAQ,SAAA,CAAU,QAAA,EAAU,CAAC,KAAA,CAAM,WAAW,CAAC,CAAA;AAAA;AACnD,QACF,CAAA;AAAA,QACA,KAAA,EAAO;AAAA,OACR,CAAA;AAED,MAAA,MAAA,GAAS,MAAM;AACb,QAAA,aAAA,EAAc;AACd,QAAA,OAAA,CAAQ,SAAA,CAAU,aAAA,EAAe,CAAC,QAAA,CAAS,WAAW,CAAC,CAAA;AAAA,MACzD,CAAA;AAEA,MAAA,MAAM,QAAA,GAAW,CAAC,CAAA,KAAa;AAC7B,QAAA,MAAA,GAAS,IAAA;AACT,QAAA,aAAA,EAAc;AACd,QAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MACX,CAAA;AAEA,MAAA,MAAM,UAAU,MAAM;AACpB,QAAA,MAAA,GAAS,IAAA;AACT,QAAA,aAAA,EAAc;AACd,QAAA,MAAA,EAAO;AAAA,MACT,CAAA;AAEA,MAAA,gBAAA,CAAiB,SAAS,cAAc,CAAA;AAAA,IAC1C,CAAA;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAA,MAAA,EAAO;AAAA,EACT,CAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"storage.mjs","sources":["../../../src/chainhead/storage.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;AAaa,MAAA,eAAA,GAAkB,CAC7B,OAO8B,KAAA;AAC9B,EAAM,MAAA,OAAA,GAAU,gBAAgB,OAAO,CAAA;AACvC,EAAA,OAAO,mBAAmB,CAAC,OAAA,EAAS,QAAQ,IAAM,EAAA,IAAA,EAAM,KAAK,SAAc,KAAA;AACzE,IAAM,MAAA,aAAA,GAAgB,IAAK,CAAA,UAAA,CAAW,aAAa,CAAA;AACnD,IAAI,IAAA,MAAA,GAAc,aAAgB,GAAA,EAAK,GAAA,IAAA;AAEvC,IAAM,MAAA,OAAA,GAAyC,aAC3C,GAAA,CAAC,KAAU,KAAA;AACT,MAAA,MAAA,CAAO,KAAK,KAAK,CAAA;AAAA,KACnB,GACA,CAAC,KAAU,KAAA;AACT,MAAS,MAAA,GAAA,KAAA,CAAM,CAAC,CAAA,GAAI,IAAe,CAAA;AAAA,KACrC;AAEJ,IAAA,MAAM,MAAS,GAAA,OAAA;AAAA,MACb,IAAA;AAAA,MACA,CAAC,EAAE,GAAK,EAAA,IAAA,EAAM,CAAA;AAAA,MACd,SAAa,IAAA,IAAA;AAAA,MACb,OAAA;AAAA,MACA,MAAA;AAAA,MACA,MAAM;AACJ,QAAI,IAAA;AACF,UAAA,OAAA,CAAQ,aAAgB,GAAA,MAAA,CAAO,IAAK,EAAA,GAAI,MAAM,CAAA;AAAA,iBACvC,CAAG,EAAA;AACV,UAAA,MAAA,CAAO,CAAC,CAAA;AAAA;AACV,OACF;AAAA,MACA,CAAC,UAAe,KAAA;AACd,QAAA,IAAI,aAAa,CAAG,EAAA;AAClB,UAAO,MAAA,EAAA;AACP,UAAO,MAAA,CAAA,IAAI,qBAAqB,CAAA;AAAA;AAClC;AACF,KACF;AACA,IAAO,OAAA,MAAA;AAAA,GACR,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"storage.mjs","sources":["../../../src/chainhead/storage.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;AAaO,MAAM,eAAA,GAAkB,CAC7B,OAAA,KAO8B;AAC9B,EAAA,MAAM,OAAA,GAAU,gBAAgB,OAAO,CAAA;AACvC,EAAA,OAAO,mBAAmB,CAAC,OAAA,EAAS,QAAQ,IAAA,EAAM,IAAA,EAAM,KAAK,SAAA,KAAc;AACzE,IAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,UAAA,CAAW,aAAa,CAAA;AACnD,IAAA,IAAI,MAAA,GAAc,aAAA,GAAgB,EAAC,GAAI,IAAA;AAEvC,IAAA,MAAM,OAAA,GAAyC,aAAA,GAC3C,CAAC,KAAA,KAAU;AACT,MAAA,MAAA,CAAO,KAAK,KAAK,CAAA;AAAA,IACnB,CAAA,GACA,CAAC,KAAA,KAAU;AACT,MAAA,MAAA,GAAS,KAAA,CAAM,CAAC,CAAA,GAAI,IAAe,CAAA;AAAA,IACrC,CAAA;AAEJ,IAAA,MAAM,MAAA,GAAS,OAAA;AAAA,MACb,IAAA;AAAA,MACA,CAAC,EAAE,GAAA,EAAK,IAAA,EAAM,CAAA;AAAA,MACd,SAAA,IAAa,IAAA;AAAA,MACb,OAAA;AAAA,MACA,MAAA;AAAA,MACA,MAAM;AACJ,QAAA,IAAI;AACF,UAAA,OAAA,CAAQ,aAAA,GAAgB,MAAA,CAAO,IAAA,EAAK,GAAI,MAAM,CAAA;AAAA,QAChD,SAAS,CAAA,EAAG;AACV,UAAA,MAAA,CAAO,CAAC,CAAA;AAAA,QACV;AAAA,MACF,CAAA;AAAA,MACA,CAAC,UAAA,KAAe;AACd,QAAA,IAAI,aAAa,CAAA,EAAG;AAClB,UAAA,MAAA,EAAO;AACP,UAAA,MAAA,CAAO,IAAI,qBAAqB,CAAA;AAAA,QAClC;AAAA,MACF;AAAA,KACF;AACA,IAAA,OAAO,MAAA;AAAA,EACT,CAAC,CAAA;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"unpin.mjs","sources":["../../../src/chainhead/unpin.ts"],"sourcesContent":["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"],"names":[],"mappings":";;AAGO,MAAM,aACX,GAAA,CAAC,OAA+C,KAAA,CAAC,MAC/C,KAAA,MAAA,CAAO,MAAS,GAAA,CAAA,GACZ,IAAI,OAAA,CAAc,CAAC,GAAA,EAAK,GAAQ,KAAA;AAC9B,EAAA,OAAA,CAAQ,SAAU,CAAA,KAAA,EAAO,CAAC,MAAM,CAAG,EAAA;AAAA,IACjC,SAAY,GAAA;AACV,MAAI,GAAA,EAAA;AAAA,KACN;AAAA,IACA,OAAS,EAAA;AAAA,GACV,CAAA;AACH,CAAC,CAAA,GACD,QAAQ,OAAQ;;;;"}
1
+ {"version":3,"file":"unpin.mjs","sources":["../../../src/chainhead/unpin.ts"],"sourcesContent":["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"],"names":[],"mappings":";;AAGO,MAAM,aAAA,GACX,CAAC,OAAA,KAA+C,CAAC,MAAA,KAC/C,MAAA,CAAO,MAAA,GAAS,CAAA,GACZ,IAAI,OAAA,CAAc,CAAC,GAAA,EAAK,GAAA,KAAQ;AAC9B,EAAA,OAAA,CAAQ,SAAA,CAAU,KAAA,EAAO,CAAC,MAAM,CAAA,EAAG;AAAA,IACjC,SAAA,GAAY;AACV,MAAA,GAAA,EAAI;AAAA,IACN,CAAA;AAAA,IACA,OAAA,EAAS;AAAA,GACV,CAAA;AACH,CAAC,CAAA,GACD,QAAQ,OAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"chainspec.mjs","sources":["../../src/chainspec.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;AAUa,MAAA,kBAAA,GAAqB,CAAC,aAA2C,KAAA;AAC5E,EAAA,MAAM,OAAU,GAAA,kBAAA;AAAA,IACd,CACE,SACA,EAAA,OAAA,EACA,MACA,EAAA,MAAA,KACG,aAAc,CAAA,MAAA,EAAQ,MAAQ,EAAA,EAAE,SAAW,EAAA,OAAA,EAAS;AAAA,GAC3D;AACA,EAAA,IAAI,aAA+C,GAAA,IAAA;AAEnD,EAAA,OAAO,YAAoC;AACzC,IAAA,IAAI,eAAsB,OAAA,aAAA;AAC1B,IAAQ,OAAA,aAAA,GAAgB,QAAQ,GAAI,CAAA;AAAA,MAClC,OAAgB,CAAA,SAAA,CAAU,SAAW,EAAA,EAAE,CAAA;AAAA,MACvC,OAAgB,CAAA,SAAA,CAAU,WAAa,EAAA,EAAE,CAAA;AAAA,MACzC,OAAa,CAAA,SAAA,CAAU,UAAY,EAAA,EAAE;AAAA,KACtC,EAAE,IAAK,CAAA,CAAC,CAAC,IAAM,EAAA,WAAA,EAAa,UAAU,CAAO,MAAA;AAAA,MAC5C,IAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACA,CAAA,CAAA;AAAA,GACJ;AACF;;;;"}
1
+ {"version":3,"file":"chainspec.mjs","sources":["../../src/chainspec.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;AAUO,MAAM,kBAAA,GAAqB,CAAC,aAAA,KAA2C;AAC5E,EAAA,MAAM,OAAA,GAAU,kBAAA;AAAA,IACd,CACE,SAAA,EACA,OAAA,EACA,MAAA,EACA,MAAA,KACG,aAAA,CAAc,MAAA,EAAQ,MAAA,EAAQ,EAAE,SAAA,EAAW,OAAA,EAAS;AAAA,GAC3D;AACA,EAAA,IAAI,aAAA,GAA+C,IAAA;AAEnD,EAAA,OAAO,YAAoC;AACzC,IAAA,IAAI,eAAe,OAAO,aAAA;AAC1B,IAAA,OAAQ,aAAA,GAAgB,QAAQ,GAAA,CAAI;AAAA,MAClC,OAAA,CAAgB,SAAA,CAAU,SAAA,EAAW,EAAE,CAAA;AAAA,MACvC,OAAA,CAAgB,SAAA,CAAU,WAAA,EAAa,EAAE,CAAA;AAAA,MACzC,OAAA,CAAa,SAAA,CAAU,UAAA,EAAY,EAAE;AAAA,KACtC,EAAE,IAAA,CAAK,CAAC,CAAC,IAAA,EAAM,WAAA,EAAa,UAAU,CAAA,MAAO;AAAA,MAC5C,IAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACF,CAAE,CAAA;AAAA,EACJ,CAAA;AACF;;;;"}
@@ -1,6 +1,5 @@
1
1
  export { AbortError } from '@polkadot-api/utils';
2
- export { RpcError } from './client/RpcError.mjs';
3
- export { DestroyedError } from './client/DestroyedError.mjs';
2
+ export { DestroyedError, RpcError } from '@polkadot-api/raw-client';
4
3
  export { DisjointError, OperationError, OperationInaccessibleError, OperationLimitError, StopError } from './chainhead/errors.mjs';
5
4
  import './methods.mjs';
6
5
  export { BlockHashNotFoundError, CallError, StorageError } from './archive/errors.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"abortablePromiseFn.mjs","sources":["../../../src/internal-utils/abortablePromiseFn.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"],"names":["fn"],"mappings":";;AAGa,MAAA,kBAAA,GACX,CACE,EAIF,KAAA,CAAA,GAAI,SACF,IAAI,OAAA,CAAQ,CAAC,GAAA,EAAK,GAAQ,KAAA;AACxB,EAAA,IAAI,MAAS,GAAA,IAAA;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,IAAI,YAAY,CAAA;AAAA,GACtB;AAEA,EAAA,WAAA,EAAa,iBAAiB,OAAS,EAAA,OAAA,EAAS,EAAE,IAAA,EAAM,MAAM,CAAA;AAE9D,EAAA,MAAM,WACJ,GAAA,CAAIA,GACJ,KAAA,CAAC,CAAM,KAAA;AACL,IAAS,MAAA,GAAA,IAAA;AACT,IAAa,WAAA,EAAA,mBAAA,CAAoB,SAAS,OAAO,CAAA;AACjD,IAAAA,IAAG,CAAC,CAAA;AAAA,GACN;AAEF,EAAS,MAAA,GAAA,EAAA,CAAG,GAAG,CAAC,WAAY,CAAA,GAAG,CAAG,EAAA,WAAA,CAAY,GAAG,CAAA,EAAG,GAAG,UAAU,CAAC,CAAA;AACpE,CAAC;;;;"}
1
+ {"version":3,"file":"abortablePromiseFn.mjs","sources":["../../../src/internal-utils/abortablePromiseFn.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"],"names":["fn"],"mappings":";;AAGO,MAAM,kBAAA,GACX,CACE,EAAA,KAIF,CAAA,GAAI,SACF,IAAI,OAAA,CAAQ,CAAC,GAAA,EAAK,GAAA,KAAQ;AACxB,EAAA,IAAI,MAAA,GAAS,IAAA;AAEb,EAAA,MAAM,CAAC,UAAA,EAAY,WAAW,CAAA,GAC5B,IAAA,CAAK,KAAK,MAAA,GAAS,CAAC,CAAA,YAAa,WAAA,GAC5B,CAAC,IAAA,CAAK,MAAM,CAAA,EAAG,IAAA,CAAK,MAAA,GAAS,CAAC,CAAA,EAAG,IAAA,CAAK,IAAA,CAAK,MAAA,GAAS,CAAC,CAAC,CAAA,GAItD,CAAC,IAAI,CAAA;AAEZ,EAAA,MAAM,UAAU,MAAM;AACpB,IAAA,MAAA,EAAO;AACP,IAAA,GAAA,CAAI,IAAI,YAAY,CAAA;AAAA,EACtB,CAAA;AAEA,EAAA,WAAA,EAAa,iBAAiB,OAAA,EAAS,OAAA,EAAS,EAAE,IAAA,EAAM,MAAM,CAAA;AAE9D,EAAA,MAAM,WAAA,GACJ,CAAIA,GAAAA,KACJ,CAAC,CAAA,KAAM;AACL,IAAA,MAAA,GAAS,IAAA;AACT,IAAA,WAAA,EAAa,mBAAA,CAAoB,SAAS,OAAO,CAAA;AACjD,IAAAA,IAAG,CAAC,CAAA;AAAA,EACN,CAAA;AAEF,EAAA,MAAA,GAAS,EAAA,CAAG,GAAG,CAAC,WAAA,CAAY,GAAG,CAAA,EAAG,WAAA,CAAY,GAAG,CAAA,EAAG,GAAG,UAAU,CAAC,CAAA;AACpE,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"deferred-promise.mjs","sources":["../../../src/internal-utils/deferred-promise.ts"],"sourcesContent":["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"],"names":[],"mappings":"AAMO,SAAS,QAAkC,GAAA;AAChD,EAAA,IAAI,MAA0B,MAAM;AAAA,GAAC;AACrC,EAAA,IAAI,MAA4B,MAAM;AAAA,GAAC;AAEvC,EAAA,MAAM,OAAU,GAAA,IAAI,OAAW,CAAA,CAAC,MAAM,IAAS,KAAA;AAC7C,IAAM,GAAA,GAAA,IAAA;AACN,IAAM,GAAA,GAAA,IAAA;AAAA,GACP,CAAA;AAED,EAAO,OAAA,EAAE,OAAS,EAAA,GAAA,EAAK,GAAI,EAAA;AAC7B;;;;"}
1
+ {"version":3,"file":"deferred-promise.mjs","sources":["../../../src/internal-utils/deferred-promise.ts"],"sourcesContent":["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"],"names":[],"mappings":"AAMO,SAAS,QAAA,GAAkC;AAChD,EAAA,IAAI,MAA0B,MAAM;AAAA,EAAC,CAAA;AACrC,EAAA,IAAI,MAA4B,MAAM;AAAA,EAAC,CAAA;AAEvC,EAAA,MAAM,OAAA,GAAU,IAAI,OAAA,CAAW,CAAC,MAAM,IAAA,KAAS;AAC7C,IAAA,GAAA,GAAM,IAAA;AACN,IAAA,GAAA,GAAM,IAAA;AAAA,EACR,CAAC,CAAA;AAED,EAAA,OAAO,EAAE,OAAA,EAAS,GAAA,EAAK,GAAA,EAAI;AAC7B;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"methods.mjs","sources":["../../src/methods.ts"],"sourcesContent":["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"],"names":[],"mappings":"AAAA,MAAM,SAAY,GAAA;AAAA,EAChB,IAAM,EAAA,EAAA;AAAA,EACN,IAAM,EAAA,EAAA;AAAA,EACN,QAAU,EAAA,EAAA;AAAA,EACV,MAAQ,EAAA,EAAA;AAAA,EACR,MAAQ,EAAA,EAAA;AAAA,EACR,aAAe,EAAA,EAAA;AAAA,EACf,OAAS,EAAA,EAAA;AAAA,EACT,QAAU,EAAA,EAAA;AAAA,EACV,KAAO,EAAA,EAAA;AAAA,EACP,WAAa,EAAA;AACf;AAEA,MAAM,SAAY,GAAA;AAAA,EAChB,SAAW,EAAA,EAAA;AAAA,EACX,WAAa,EAAA,EAAA;AAAA,EACb,UAAY,EAAA;AACd;AAEA,MAAM,WAAc,GAAA;AAAA,EAClB,SAAW,EAAA,EAAA;AAAA,EACX,IAAM,EAAA;AACR;AAEA,MAAA,CAAO,QAAQ,EAAE,SAAA,EAAW,SAAW,EAAA,WAAA,EAAa,CAAE,CAAA,OAAA;AAAA,EACpD,CAAC,CAAC,WAAa,EAAA,OAAO,CAAM,KAAA;AAC1B,IAAA,MAAA,CAAO,IAAK,CAAA,OAAO,CAAE,CAAA,OAAA,CAAQ,CAAC,UAAe,KAAA;AAC1C,MAAC,QAAgB,UAAU,CAAA,GAAI,CAAG,EAAA,WAAW,OAAO,UAAU,CAAA,CAAA;AAAA,KAChE,CAAA;AAAA;AAEL,CAAA;;;;"}
1
+ {"version":3,"file":"methods.mjs","sources":["../../src/methods.ts"],"sourcesContent":["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"],"names":[],"mappings":"AAAA,MAAM,SAAA,GAAY;AAAA,EAChB,IAAA,EAAM,EAAA;AAAA,EACN,IAAA,EAAM,EAAA;AAAA,EACN,QAAA,EAAU,EAAA;AAAA,EACV,MAAA,EAAQ,EAAA;AAAA,EACR,MAAA,EAAQ,EAAA;AAAA,EACR,aAAA,EAAe,EAAA;AAAA,EACf,OAAA,EAAS,EAAA;AAAA,EACT,QAAA,EAAU,EAAA;AAAA,EACV,KAAA,EAAO,EAAA;AAAA,EACP,WAAA,EAAa;AACf;AAEA,MAAM,SAAA,GAAY;AAAA,EAChB,SAAA,EAAW,EAAA;AAAA,EACX,WAAA,EAAa,EAAA;AAAA,EACb,UAAA,EAAY;AACd;AAEA,MAAM,WAAA,GAAc;AAAA,EAClB,SAAA,EAAW,EAAA;AAAA,EACX,IAAA,EAAM;AACR;AAEA,MAAA,CAAO,QAAQ,EAAE,SAAA,EAAW,SAAA,EAAW,WAAA,EAAa,CAAA,CAAE,OAAA;AAAA,EACpD,CAAC,CAAC,WAAA,EAAa,OAAO,CAAA,KAAM;AAC1B,IAAA,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA,CAAE,OAAA,CAAQ,CAAC,UAAA,KAAe;AAC1C,MAAC,QAAgB,UAAU,CAAA,GAAI,CAAA,EAAG,WAAW,OAAO,UAAU,CAAA,CAAA;AAAA,IACjE,CAAC,CAAA;AAAA,EACH;AACF,CAAA;;;;"}
@@ -1,6 +1,6 @@
1
+ import { createClient as createClient$1 } from '@polkadot-api/raw-client';
1
2
  import { getTransaction } from './transaction/transaction.mjs';
2
3
  import { getChainHead } from './chainhead/chainhead.mjs';
3
- import { createClient as createClient$1 } from './client/createClient.mjs';
4
4
  import { abortablePromiseFn } from './internal-utils/abortablePromiseFn.mjs';
5
5
  import { createGetChainSpec } from './chainspec.mjs';
6
6
  import { getArchive } from './archive/archive.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"substrate-client.mjs","sources":["../../src/substrate-client.ts"],"sourcesContent":["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":["createRawClient","cached"],"mappings":";;;;;;;AA6BA,MAAM,WAAA,uBAAkB,GAGtB,EAAA;AAEW,MAAA,YAAA,GAAe,CAAC,QAA+C,KAAA;AAC1E,EAAM,MAAA,MAAA,GAAS,WAAY,CAAA,GAAA,CAAI,QAAQ,CAAA;AACvC,EAAA,IAAI,MAAQ,EAAA;AACV,IAAO,MAAA,CAAA,QAAA,EAAA;AACP,IAAA,OAAO,MAAO,CAAA,MAAA;AAAA;AAGhB,EAAA,MAAM,EAAE,OAAA,EAAS,UAAW,EAAA,GAAIA,eAAgB,QAAQ,CAAA;AACxD,EAAA,MAAM,UAAU,MAAM;AACpB,IAAMC,MAAAA,OAAAA,GAAS,WAAY,CAAA,GAAA,CAAI,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":"substrate-client.mjs","sources":["../../src/substrate-client.ts"],"sourcesContent":["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":["createRawClient","cached"],"mappings":";;;;;;;AAgCA,MAAM,WAAA,uBAAkB,GAAA,EAGtB;AAEK,MAAM,YAAA,GAAe,CAAC,QAAA,KAA+C;AAC1E,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,GAAA,CAAI,QAAQ,CAAA;AACvC,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,MAAA,CAAO,QAAA,EAAA;AACP,IAAA,OAAO,MAAA,CAAO,MAAA;AAAA,EAChB;AAEA,EAAA,MAAM,EAAE,OAAA,EAAS,UAAA,EAAW,GAAIA,eAAgB,QAAQ,CAAA;AACxD,EAAA,MAAM,UAAU,MAAM;AACpB,IAAA,MAAMC,OAAAA,GAAS,WAAA,CAAY,GAAA,CAAI,QAAQ,CAAA;AACvC,IAAA,IAAI,CAACA,OAAAA,IAAUA,OAAAA,CAAO,QAAA,IAAY,CAAA,EAAG;AACnC,MAAA,WAAA,CAAY,OAAO,QAAQ,CAAA;AAC3B,MAAA,UAAA,EAAW;AAAA,IACb,CAAA,MAAO;AACL,MAAAA,OAAAA,CAAO,QAAA,EAAA;AAAA,IACT;AAAA,EACF,CAAA;AACA,EAAA,MAAM,MAAA,GAA0B;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,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;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.mjs","sources":["../../../src/transaction/transaction.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;AAIO,MAAM,cACX,GAAA,CAAC,OACD,KAAA,CAAC,IAAY,KAA8B,KAAA;AACzC,EAAA,IAAI,SAAS,OAAQ,CAAA,WAAA,CAAY,SAAW,EAAA,CAAC,EAAE,CAAG,EAAA;AAAA,IAChD,SAAA,EAAW,CAAC,cAAmB,KAAA;AAC7B,MACE,MAAA,GAAA,cAAA,KAAmB,IACf,GAAA,IAAA,GACA,MAAM;AACJ,QAAA,OAAA,CAAQ,WAAY,CAAA,IAAA,EAAM,CAAC,cAAc,CAAC,CAAA;AAAA,OAC5C;AAEN,MAAA,IAAI,mBAAmB,IAAM,EAAA;AAC3B,QAAM,KAAA,CAAA,IAAI,KAAM,CAAA,oDAAoD,CAAC,CAAA;AAAA;AACvE,KACF;AAAA,IACA,OAAS,EAAA;AAAA,GACV,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAO,MAAA,EAAA;AAAA,GACT;AACF;;;;"}
1
+ {"version":3,"file":"transaction.mjs","sources":["../../../src/transaction/transaction.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;AAIO,MAAM,cAAA,GACX,CAAC,OAAA,KACD,CAAC,IAAY,KAAA,KAA8B;AACzC,EAAA,IAAI,SAAS,OAAA,CAAQ,WAAA,CAAY,SAAA,EAAW,CAAC,EAAE,CAAA,EAAG;AAAA,IAChD,SAAA,EAAW,CAAC,cAAA,KAAmB;AAC7B,MAAA,MAAA,GACE,cAAA,KAAmB,IAAA,GACf,IAAA,GACA,MAAM;AACJ,QAAA,OAAA,CAAQ,WAAA,CAAY,IAAA,EAAM,CAAC,cAAc,CAAC,CAAA;AAAA,MAC5C,CAAA;AAEN,MAAA,IAAI,mBAAmB,IAAA,EAAM;AAC3B,QAAA,KAAA,CAAM,IAAI,KAAA,CAAM,oDAAoD,CAAC,CAAA;AAAA,MACvE;AAAA,IACF,CAAA;AAAA,IACA,OAAA,EAAS;AAAA,GACV,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAA,MAAA,EAAO;AAAA,EACT,CAAA;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export { AbortError } from '@polkadot-api/utils';
2
2
  import { JsonRpcProvider } from '@polkadot-api/json-rpc-provider';
3
3
  export * from '@polkadot-api/json-rpc-provider';
4
+ import { ClientRequest, Subscriber, ClientRequestCb } from '@polkadot-api/raw-client';
5
+ export * from '@polkadot-api/raw-client';
6
+ export { DestroyedError, RpcError } from '@polkadot-api/raw-client';
4
7
 
5
8
  type UnsubscribeFn = () => void;
6
9
  type WithAbortSignal<T extends Array<any>> = [
@@ -9,37 +12,6 @@ type WithAbortSignal<T extends Array<any>> = [
9
12
  ];
10
13
  type AbortablePromiseFn<A extends Array<any>, T> = (...args: WithAbortSignal<A>) => Promise<T>;
11
14
 
12
- interface IRpcError {
13
- code: number;
14
- message: string;
15
- data?: any;
16
- }
17
- declare class RpcError extends Error implements IRpcError {
18
- code: number;
19
- data: any;
20
- constructor(e: IRpcError);
21
- }
22
-
23
- interface Subscriber<T> {
24
- next: (data: T) => void;
25
- error: (e: Error) => void;
26
- }
27
-
28
- type FollowSubscriptionCb<T> = (subscriptionId: string, cb: Subscriber<T>) => UnsubscribeFn;
29
- type ClientRequestCb<T, TT> = {
30
- onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void;
31
- onError: (e: Error) => void;
32
- };
33
- type ClientRequest<T, TT> = (method: string, params: Array<any>, cb?: ClientRequestCb<T, TT>) => UnsubscribeFn;
34
- interface Client {
35
- disconnect: () => void;
36
- request: ClientRequest<any, any>;
37
- }
38
-
39
- declare class DestroyedError extends Error {
40
- constructor();
41
- }
42
-
43
15
  type Transaction = (tx: string, error: (e: Error) => void) => UnsubscribeFn;
44
16
 
45
17
  declare const getTransaction: (request: ClientRequest<string, any>) => (tx: string, error: (e: Error) => void) => () => void;
@@ -263,5 +235,5 @@ interface SubstrateClient {
263
235
  }
264
236
  declare const createClient: (provider: JsonRpcProvider) => SubstrateClient;
265
237
 
266
- export { BlockHashNotFoundError, CallError, DestroyedError, DisjointError, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, StopError, StorageError, createClient, createGetChainSpec, getArchive, getChainHead, getTransaction };
267
- export type { AbortablePromiseFn, Archive, ArchiveStorageItemInput, BestBlockChanged, ChainHead, ChainSpecData, Client, ClientInnerRequest, ClientInnerRequestCb, ClientRequest, ClientRequestCb, Finalized, FollowEventWithRuntime, FollowEventWithoutRuntime, FollowInnerSubscriptionCb, FollowResponse, FollowSubscriptionCb, IRpcError, Initialized, InitializedWithRuntime$1 as InitializedWithRuntime, NewBlock, NewBlockWithRuntime$1 as NewBlockWithRuntime, Runtime, StorageItemInput, StorageItemResponse, StorageResult, SubstrateClient, Transaction, UnsubscribeFn };
238
+ export { BlockHashNotFoundError, CallError, DisjointError, OperationError, OperationInaccessibleError, OperationLimitError, StopError, StorageError, createClient, createGetChainSpec, getArchive, getChainHead, getTransaction };
239
+ export type { AbortablePromiseFn, Archive, ArchiveStorageItemInput, BestBlockChanged, ChainHead, ChainSpecData, ClientInnerRequest, ClientInnerRequestCb, Finalized, FollowEventWithRuntime, FollowEventWithoutRuntime, FollowInnerSubscriptionCb, FollowResponse, Initialized, InitializedWithRuntime$1 as InitializedWithRuntime, NewBlock, NewBlockWithRuntime$1 as NewBlockWithRuntime, Runtime, StorageItemInput, StorageItemResponse, StorageResult, SubstrateClient, Transaction, UnsubscribeFn };