UNPKG

@tangany/waas

Version:

node.js SDK for Tangany Wallet as a Service API

36 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventArgumentFilterCollection = void 0; // It would probably be better to extend the array type. // However, this currently doesn't seem to work if you want to use the convenient [] object initializer then. var EventArgumentFilterCollection = /** @class */ (function () { function EventArgumentFilterCollection(filters) { this.filters = filters; } /** * Assembles a URL query string to filter smart contract events based on their arguments. * Since axios does not accept this JavaScript-side configuration with objects, it is necessary to convert it into a URL query string compatible with WaaS. */ EventArgumentFilterCollection.prototype.toQueryString = function () { return this.filters.reduce(function (accumulatedQuery, filter) { var position = filter.position, type = filter.type, value = filter.value; if (!(position || type || value)) { throw new Error("An argument filter object must define at least one criterion"); } // If it is the first URL query parameter, use "?", otherwise use "&" to join multiple filters var s = "".concat(accumulatedQuery === "" ? "?" : "&", "inputs"); // Ensure that the brackets are created to produce the form "inputs[]" even if no position is specified s += "[".concat(position !== undefined ? JSON.stringify(position) : "", "]"); if (type) { s += ".".concat(type); } if (value) { s += "=".concat(JSON.stringify(value)); } return accumulatedQuery + s; }, ""); }; return EventArgumentFilterCollection; }()); exports.EventArgumentFilterCollection = EventArgumentFilterCollection; //# sourceMappingURL=event-argument-filter-collection.js.map