{"dependencies":[{"name":"rxjs","data":{"asyncType":null,"isESMImport":false,"locs":[{"start":{"line":4,"column":15,"index":116},"end":{"line":4,"column":30,"index":131}}],"key":"atDzfUGaJNRNtwyVumomzH/5ygw=","exportNames":["*"],"imports":1}},{"name":"@polkadot/util","data":{"asyncType":null,"isESMImport":false,"locs":[{"start":{"line":5,"column":15,"index":148},"end":{"line":5,"column":40,"index":173}}],"key":"u0mzEw2nilnHoUWtEdZl0JKHutA=","exportNames":["*"],"imports":1}},{"name":"../base/index.js","data":{"asyncType":null,"isESMImport":false,"locs":[{"start":{"line":6,"column":19,"index":194},"end":{"line":6,"column":46,"index":221}}],"key":"6LGhkk8t77NLLcuOWVqakFlZ26o=","exportNames":["*"],"imports":1}},{"name":"./decorateMethod.js","data":{"asyncType":null,"isESMImport":false,"locs":[{"start":{"line":7,"column":28,"index":251},"end":{"line":7,"column":58,"index":281}}],"key":"UpHug+leW+HiuYrFQEdxS5jlXD8=","exportNames":["*"],"imports":1}}],"output":[{"data":{"code":"__d(function (global, require, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {\n \"use strict\";\n\n Object.defineProperty(exports, \"__esModule\", {\n value: true\n });\n exports.ApiRx = void 0;\n const rxjs_1 = require(_dependencyMap[0], \"rxjs\");\n const util_1 = require(_dependencyMap[1], \"@polkadot/util\");\n const index_js_1 = require(_dependencyMap[2], \"../base/index.js\");\n const decorateMethod_js_1 = require(_dependencyMap[3], \"./decorateMethod.js\");\n /**\n * # @polkadot/api/rx\n *\n * ## Overview\n *\n * @name ApiRx\n *\n * @description\n * ApiRx is a powerful RxJS Observable wrapper around the RPC and interfaces on the Polkadot network. As a full Observable API, all interface calls return RxJS Observables, including the static `.create(...)`. In the same fashion and subscription-based methods return long-running Observables that update with the latest values.\n *\n * The API is well suited to real-time applications where the latest state is needed, unlocking the subscription-based features of Polkadot (and Substrate) clients. Some familiarity with RxJS is a requirement to use the API, however just understanding `.subscribe` and `.pipe` on Observables will unlock full-scale use thereof.\n *\n * @see [[ApiPromise]]\n *\n * ## Usage\n *\n * Making rpc calls -\n *
\n *\n * ```javascript\n * import ApiRx from '@polkadot/api/rx';\n *\n * // initialize via Promise & static create\n * const api = await ApiRx.create().toPromise();\n *\n * // make a call to retrieve the current network head\n * api.rpc.chain.subscribeNewHeads().subscribe((header) => {\n * console.log(`Chain is at #${header.number}`);\n * });\n * ```\n *
\n *\n * Subscribing to chain state -\n *
\n *\n * ```javascript\n * import { combineLatest, pairwise, switchMap } from 'rxjs';\n * import { ApiRx, WsProvider } from '@polkadot/api';\n *\n *\n * // initialize a provider with a specific endpoint\n * const provider = new WsProvider('wss://example.com:9944')\n *\n * // initialize via isReady & new with specific provider\n * new ApiRx({ provider })\n * .isReady\n * .pipe(\n * switchMap((api) =>\n * combineLatest([\n * api.query.timestamp.blockPeriod(),\n * api.query.timestamp.now().pipe(pairwise())\n * ])\n * )\n * )\n * .subscribe(([blockPeriod, timestamp]) => {\n * const elapsed = timestamp[1].toNumber() - timestamp[0].toNumber();\n * console.log(`timestamp ${timestamp[1]} \\nelapsed ${elapsed} \\n(${blockPeriod}s target)`);\n * });\n * ```\n *
\n *\n * Submitting a transaction -\n *
\n *\n * ```javascript\n * import { first, switchMap } from 'rxjs';\n * import ApiRx from '@polkadot/api/rx';\n *\n * // import the test keyring (already has dev keys for Alice, Bob, Charlie, Eve & Ferdie)\n * import testingPairs from '@polkadot/keyring/testingPairs';\n * const keyring = testingPairs();\n *\n * // get api via Promise\n * const api = await ApiRx.create().toPromise();\n *\n * // retrieve nonce for the account\n * api.query.system\n * .account(keyring.alice.address)\n * .pipe(\n * first(),\n * // pipe nonce into transfer\n * switchMap(([nonce]) =>\n * api.tx.balances\n * // create transfer\n * .transferAllowDeath(keyring.bob.address, 12345)\n * // sign the transaction\n * .sign(keyring.alice, { nonce })\n * // send the transaction\n * .send()\n * )\n * )\n * // subscribe to overall result\n * .subscribe(({ status }) => {\n * if (status.isInBlock) {\n * console.log('Completed at block hash', status.asFinalized.toHex());\n * }\n * });\n * ```\n */\n class ApiRx extends index_js_1.ApiBase {\n #isReadyRx;\n /**\n * @description Create an instance of the ApiRx class\n * @param options Options to create an instance. Can be either [[ApiOptions]] or [[WsProvider]]\n * @example\n *
\n *\n * ```javascript\n * import { switchMap } from 'rxjs';\n * import Api from '@polkadot/api/rx';\n *\n * new Api().isReady\n * .pipe(\n * switchMap((api) =>\n * api.rpc.chain.subscribeNewHeads()\n * ))\n * .subscribe((header) => {\n * console.log(`new block #${header.number.toNumber()}`);\n * });\n * ```\n */\n constructor(options) {\n super(options, 'rxjs', decorateMethod_js_1.toRxMethod);\n this.#isReadyRx = (0, rxjs_1.from)(\n // You can create an observable from an event, however my mind groks this form better\n new Promise(resolve => {\n super.on('ready', () => resolve(this));\n }));\n }\n /**\n * @description Creates an ApiRx instance using the supplied provider. Returns an Observable containing the actual Api instance.\n * @param options options that is passed to the class constructor. Can be either [[ApiOptions]] or [[WsProvider]]\n * @example\n *
\n *\n * ```javascript\n * import { switchMap } from 'rxjs';\n * import Api from '@polkadot/api/rx';\n *\n * Api.create()\n * .pipe(\n * switchMap((api) =>\n * api.rpc.chain.subscribeNewHeads()\n * ))\n * .subscribe((header) => {\n * console.log(`new block #${header.number.toNumber()}`);\n * });\n * ```\n */\n static create(options) {\n return new ApiRx(options).isReady;\n }\n /**\n * @description Observable that returns the first time we are connected and loaded\n */\n get isReady() {\n return this.#isReadyRx;\n }\n /**\n * @description Returns a clone of this ApiRx instance (new underlying provider connection)\n */\n clone() {\n return new ApiRx((0, util_1.objectSpread)({}, this._options, {\n source: this\n }));\n }\n }\n exports.ApiRx = ApiRx;\n});","lineCount":180,"map":[[2,2,1,0],[2,14,1,12],[4,2,2,0,"Object"],[4,8,2,6],[4,9,2,7,"defineProperty"],[4,23,2,21],[4,24,2,22,"exports"],[4,31,2,29],[4,33,2,31],[4,45,2,43],[4,47,2,45],[5,4,2,47,"value"],[5,9,2,52],[5,11,2,54],[6,2,2,59],[6,3,2,60],[6,4,2,61],[7,2,3,0,"exports"],[7,9,3,7],[7,10,3,8,"ApiRx"],[7,15,3,13],[7,18,3,16],[7,23,3,21],[7,24,3,22],[8,2,4,0],[8,8,4,6,"rxjs_1"],[8,14,4,12],[8,17,4,15,"require"],[8,24,4,22],[8,25,4,22,"_dependencyMap"],[8,39,4,22],[8,50,4,29],[8,51,4,30],[9,2,5,0],[9,8,5,6,"util_1"],[9,14,5,12],[9,17,5,15,"require"],[9,24,5,22],[9,25,5,22,"_dependencyMap"],[9,39,5,22],[9,60,5,39],[9,61,5,40],[10,2,6,0],[10,8,6,6,"index_js_1"],[10,18,6,16],[10,21,6,19,"require"],[10,28,6,26],[10,29,6,26,"_dependencyMap"],[10,43,6,26],[10,66,6,45],[10,67,6,46],[11,2,7,0],[11,8,7,6,"decorateMethod_js_1"],[11,27,7,25],[11,30,7,28,"require"],[11,37,7,35],[11,38,7,35,"_dependencyMap"],[11,52,7,35],[11,78,7,57],[11,79,7,58],[12,2,8,0],[13,0,9,0],[14,0,10,0],[15,0,11,0],[16,0,12,0],[17,0,13,0],[18,0,14,0],[19,0,15,0],[20,0,16,0],[21,0,17,0],[22,0,18,0],[23,0,19,0],[24,0,20,0],[25,0,21,0],[26,0,22,0],[27,0,23,0],[28,0,24,0],[29,0,25,0],[30,0,26,0],[31,0,27,0],[32,0,28,0],[33,0,29,0],[34,0,30,0],[35,0,31,0],[36,0,32,0],[37,0,33,0],[38,0,34,0],[39,0,35,0],[40,0,36,0],[41,0,37,0],[42,0,38,0],[43,0,39,0],[44,0,40,0],[45,0,41,0],[46,0,42,0],[47,0,43,0],[48,0,44,0],[49,0,45,0],[50,0,46,0],[51,0,47,0],[52,0,48,0],[53,0,49,0],[54,0,50,0],[55,0,51,0],[56,0,52,0],[57,0,53,0],[58,0,54,0],[59,0,55,0],[60,0,56,0],[61,0,57,0],[62,0,58,0],[63,0,59,0],[64,0,60,0],[65,0,61,0],[66,0,62,0],[67,0,63,0],[68,0,64,0],[69,0,65,0],[70,0,66,0],[71,0,67,0],[72,0,68,0],[73,0,69,0],[74,0,70,0],[75,0,71,0],[76,0,72,0],[77,0,73,0],[78,0,74,0],[79,0,75,0],[80,0,76,0],[81,0,77,0],[82,0,78,0],[83,0,79,0],[84,0,80,0],[85,0,81,0],[86,0,82,0],[87,0,83,0],[88,0,84,0],[89,0,85,0],[90,0,86,0],[91,0,87,0],[92,0,88,0],[93,0,89,0],[94,0,90,0],[95,0,91,0],[96,0,92,0],[97,0,93,0],[98,0,94,0],[99,0,95,0],[100,0,96,0],[101,0,97,0],[102,0,98,0],[103,0,99,0],[104,0,100,0],[105,0,101,0],[106,0,102,0],[107,0,103,0],[108,0,104,0],[109,0,105,0],[110,0,106,0],[111,2,107,0],[111,8,107,6,"ApiRx"],[111,13,107,11],[111,22,107,20,"index_js_1"],[111,32,107,30],[111,33,107,31,"ApiBase"],[111,40,107,38],[111,41,107,39],[112,4,108,4],[112,5,108,5,"isReadyRx"],[112,14,108,14],[113,4,109,4],[114,0,110,0],[115,0,111,0],[116,0,112,0],[117,0,113,0],[118,0,114,0],[119,0,115,0],[120,0,116,0],[121,0,117,0],[122,0,118,0],[123,0,119,0],[124,0,120,0],[125,0,121,0],[126,0,122,0],[127,0,123,0],[128,0,124,0],[129,0,125,0],[130,0,126,0],[131,0,127,0],[132,0,128,0],[133,4,129,4,"constructor"],[133,15,129,15,"constructor"],[133,16,129,16,"options"],[133,23,129,23],[133,25,129,25],[134,6,130,8],[134,11,130,13],[134,12,130,14,"options"],[134,19,130,21],[134,21,130,23],[134,27,130,29],[134,29,130,31,"decorateMethod_js_1"],[134,48,130,50],[134,49,130,51,"toRxMethod"],[134,59,130,61],[134,60,130,62],[135,6,131,8],[135,10,131,12],[135,11,131,13],[135,12,131,14,"isReadyRx"],[135,21,131,23],[135,24,131,26],[135,25,131,27],[135,26,131,28],[135,28,131,30,"rxjs_1"],[135,34,131,36],[135,35,131,37,"from"],[135,39,131,41],[136,6,132,8],[137,6,133,8],[137,10,133,12,"Promise"],[137,17,133,19],[137,18,133,21,"resolve"],[137,25,133,28],[137,29,133,33],[138,8,134,12],[138,13,134,17],[138,14,134,18,"on"],[138,16,134,20],[138,17,134,21],[138,24,134,28],[138,26,134,30],[138,32,134,36,"resolve"],[138,39,134,43],[138,40,134,44],[138,44,134,48],[138,45,134,49],[138,46,134,50],[139,6,135,8],[139,7,135,9],[139,8,135,10],[139,9,135,11],[140,4,136,4],[141,4,137,4],[142,0,138,0],[143,0,139,0],[144,0,140,0],[145,0,141,0],[146,0,142,0],[147,0,143,0],[148,0,144,0],[149,0,145,0],[150,0,146,0],[151,0,147,0],[152,0,148,0],[153,0,149,0],[154,0,150,0],[155,0,151,0],[156,0,152,0],[157,0,153,0],[158,0,154,0],[159,0,155,0],[160,0,156,0],[161,4,157,4],[161,11,157,11,"create"],[161,17,157,17,"create"],[161,18,157,18,"options"],[161,25,157,25],[161,27,157,27],[162,6,158,8],[162,13,158,15],[162,17,158,19,"ApiRx"],[162,22,158,24],[162,23,158,25,"options"],[162,30,158,32],[162,31,158,33],[162,32,158,34,"isReady"],[162,39,158,41],[163,4,159,4],[164,4,160,4],[165,0,161,0],[166,0,162,0],[167,4,163,4],[167,8,163,8,"isReady"],[167,15,163,15,"isReady"],[167,16,163,15],[167,18,163,18],[168,6,164,8],[168,13,164,15],[168,17,164,19],[168,18,164,20],[168,19,164,21,"isReadyRx"],[168,28,164,30],[169,4,165,4],[170,4,166,4],[171,0,167,0],[172,0,168,0],[173,4,169,4,"clone"],[173,9,169,9,"clone"],[173,10,169,9],[173,12,169,12],[174,6,170,8],[174,13,170,15],[174,17,170,19,"ApiRx"],[174,22,170,24],[174,23,170,25],[174,24,170,26],[174,25,170,27],[174,27,170,29,"util_1"],[174,33,170,35],[174,34,170,36,"objectSpread"],[174,46,170,48],[174,48,170,50],[174,49,170,51],[174,50,170,52],[174,52,170,54],[174,56,170,58],[174,57,170,59,"_options"],[174,65,170,67],[174,67,170,69],[175,8,170,71,"source"],[175,14,170,77],[175,16,170,79],[176,6,170,84],[176,7,170,85],[176,8,170,86],[176,9,170,87],[177,4,171,4],[178,2,172,0],[179,2,173,0,"exports"],[179,9,173,7],[179,10,173,8,"ApiRx"],[179,15,173,13],[179,18,173,16,"ApiRx"],[179,23,173,21],[180,0,173,22],[180,3]],"functionMap":{"names":["","ApiRx","ApiRx#constructor","Promise$argument_0","on$argument_1","ApiRx.create","ApiRx#get__isReady","ApiRx#clone"],"mappings":"AAA;AC0G;ICsB;oBCI;8BCC,mBD;SDC;KDC;IIqB;KJE;IKI;KLE;IMI;KNE;CDC"},"hasCjsExports":true},"type":"js/module"}]}