UNPKG

@actyx/sdk

Version:
43 lines 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OffsetMap = exports._offsetMapLookup = void 0; /* * Actyx SDK: Functions for writing distributed apps * deployed on peer-to-peer networks, without any servers. * * Copyright (C) 2021 Actyx AG */ const Option_1 = require("fp-ts/lib/Option"); const util_1 = require("../util"); const various_1 = require("./various"); const emptyOffsetMap = {}; /** * @internal */ const _offsetMapLookup = (m, s) => (0, Option_1.getOrElse)(() => various_1.Offset.min)((0, Option_1.fromNullable)(m[s])); exports._offsetMapLookup = _offsetMapLookup; /** * Updates a given psn map with a new event. * Note that the events need to be applied in event order * * @param psnMap the psn map to update. WILL BE MODIFIED IN PLACE * @param ev the event to include */ const includeEvent = (psnMap, ev) => { const { offset, stream } = ev; const current = (0, util_1.lookup)(psnMap, stream); if (current === undefined || current < offset) { psnMap[stream] = offset; } return psnMap; }; /** OffsetMap companion functions. * @public */ exports.OffsetMap = { empty: emptyOffsetMap, isEmpty: (m) => Object.keys(m).length === 0, lookup: exports._offsetMapLookup, lookupOrUndefined: (m, s) => m[s], update: includeEvent, }; //# sourceMappingURL=offsetMap.js.map