UNPKG

@kurrent/kurrentdb-client

Version:
50 lines 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Client_1 = require("../Client"); const constants_1 = require("../constants"); const utils_1 = require("../utils"); const convertRustEvent_1 = require("../utils/convertRustEvent"); const convertBridgeError_1 = require("../utils/convertBridgeError"); Client_1.Client.prototype.readStream = function (streamName, { maxCount = Number.MAX_SAFE_INTEGER, fromRevision = constants_1.START, resolveLinkTos = false, direction = constants_1.FORWARDS, ...baseOptions } = {}) { if (fromRevision !== constants_1.START && fromRevision !== constants_1.END && typeof fromRevision === "bigint") { const lowerBound = BigInt("0"); const upperBound = BigInt("0xffffffffffffffff"); if (fromRevision < lowerBound) { throw new utils_1.InvalidArgumentError(`fromRevision value must be a non-negative integer. Value Received: ${fromRevision}`); } if (fromRevision > upperBound) { throw new utils_1.InvalidArgumentError(`fromRevision value must be a non-negative integer, range from 0 to 18446744073709551615. Value Received: ${fromRevision}`); } } const convert = async function* () { const credentials = await this.resolveBridgeCredentials(baseOptions.credentials); let stream; try { stream = this.rustClient.readStream(streamName, { credentials, direction, fromRevision, maxCount: BigInt(maxCount), requiresLeader: baseOptions.requiresLeader ?? false, resolvesLink: resolveLinkTos, }); } catch (error) { throw (0, convertBridgeError_1.convertBridgeError)(error, streamName); } try { for await (const events of stream) { for (const event of events) { yield (0, convertRustEvent_1.convertRustEvent)(event); } } } catch (error) { throw (0, convertBridgeError_1.convertBridgeError)(error, streamName); } }; return convert.call(this); }; //# sourceMappingURL=readStream.js.map