UNPKG

jinaga

Version:

Data management for web and mobile applications.

40 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FeedCache = void 0; const hash_1 = require("../fact/hash"); const skeleton_1 = require("./skeleton"); class FeedCache { constructor() { this.feedByHash = {}; } addFeeds(feeds, namedStart) { const feedsByHash = feeds.reduce((map, feed) => { const skeleton = (0, skeleton_1.skeletonOfSpecification)(feed); const indexedStart = skeleton.inputs.map(input => ({ factReference: namedStart[feed.given[input.inputIndex].label.name], index: input.inputIndex })); const feedIdentifier = { start: indexedStart, skeleton }; const feedObject = { namedStart, feed }; const hash = urlSafe((0, hash_1.computeObjectHash)(feedIdentifier)); return (Object.assign(Object.assign({}, map), { [hash]: feedObject })); }, {}); const feedHashes = Object.keys(feedsByHash); this.feedByHash = Object.assign(Object.assign({}, this.feedByHash), feedsByHash); return feedHashes; } getFeed(feed) { return this.feedByHash[feed]; } } exports.FeedCache = FeedCache; function urlSafe(hash) { return hash.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); } //# sourceMappingURL=feed-cache.js.map