UNPKG

jinaga

Version:

Data management for web and mobile applications.

41 lines 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateGiven = exports.computeTupleSubsetHash = exports.uniqueFactReferences = exports.factEnvelopeEquals = exports.factReferenceEquals = void 0; const hash_1 = require("./fact/hash"); const fn_1 = require("./util/fn"); function factReferenceEquals(a) { return (r) => r.hash === a.hash && r.type === a.type; } exports.factReferenceEquals = factReferenceEquals; function factEnvelopeEquals(r) { return (e) => e.fact.hash === r.hash && e.fact.type === r.type; } exports.factEnvelopeEquals = factEnvelopeEquals; function uniqueFactReferences(references) { return references.filter((value, index, array) => { return (0, fn_1.findIndex)(array, factReferenceEquals(value)) === index; }); } exports.uniqueFactReferences = uniqueFactReferences; function computeTupleSubsetHash(tuple, subset) { const parentTuple = Object.getOwnPropertyNames(tuple) .filter(name => subset.some(s => s === name)) .reduce((t, name) => (Object.assign(Object.assign({}, t), { [name]: tuple[name] })), {}); const parentTupleHash = (0, hash_1.computeObjectHash)(parentTuple); return parentTupleHash; } exports.computeTupleSubsetHash = computeTupleSubsetHash; function validateGiven(start, specification) { // Verify that the number of start facts equals the number of inputs if (start.length !== specification.given.length) { throw new Error(`The number of start facts (${start.length}) does not equal the number of inputs (${specification.given.length})`); } // Verify that the input type matches the start fact type for (let i = 0; i < start.length; i++) { if (start[i].type !== specification.given[i].label.type) { throw new Error(`The type of start fact ${i} (${start[i].type}) does not match the type of input ${i} (${specification.given[i].label.type})`); } } } exports.validateGiven = validateGiven; //# sourceMappingURL=storage.js.map