UNPKG

@discipl/law-reg

Version:

Discipl Law and Regulation Compliance Library

104 lines (85 loc) 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ModelPublisher = void 0; var _logging_util = require("../utils/logging_util"); var _index = require("../index"); var _abundanceService = require("@discipl/abundance-service"); // Improve intelisense // eslint-disable-next-line no-unused-vars class ModelPublisher { /** * Create a ModelPublisher * @param {ServiceProvider} serviceProvider */ constructor(serviceProvider) { this.logger = (0, _logging_util.getDiscplLogger)(); this.serviceProvider = serviceProvider; } /** * Get abundance service * @return {AbundanceService} * @private */ _getAbundanceService() { return this.serviceProvider.abundanceService; } /** * Publishes the FLINT model (as JSON) in linked verifiable claims (vc's) * in the channel of the given ssid. Each act, fact and duty is stored in a separate vc. * Returns a list to the claim holding the whole model with links to individual claims * Note that references within the model are not translated into links. * * @param {ssid} ssid SSID that publishes the model * @param {object} flintModel Model to publish * @param {object} factFunctions Additional factFunction that are declared outside the model * @return {Promise<string>} Link to a verifiable claim that holds the published model */ async publish(ssid, flintModel, factFunctions = {}) { this.logger.debug('Publishing model'); const core = this._getAbundanceService().getCoreAPI(); const result = { model: flintModel.model, acts: [], facts: [], duties: [] }; for (const fact of flintModel.facts) { let resultFact = fact; if (fact.function === '[]' && factFunctions[fact.fact] != null) { this.logger.debug('Setting function for', fact.fact, 'to', factFunctions[fact.fact]); resultFact = { ...fact, 'function': factFunctions[fact.fact] }; } const link = await core.claim(ssid, { [_index.DISCIPL_FLINT_FACT]: resultFact }); result.facts.push({ [fact.fact]: link }); } for (const act of flintModel.acts) { const link = await core.claim(ssid, { [_index.DISCIPL_FLINT_ACT]: act }); result.acts.push({ [act.act]: link }); } for (const duty of flintModel.duties) { const link = await core.claim(ssid, { [_index.DISCIPL_FLINT_DUTY]: duty }); result.duties.push({ [duty.duty]: link }); } this.logger.debug('Done publishing'); return core.claim(ssid, { [_index.DISCIPL_FLINT_MODEL]: result }); } } exports.ModelPublisher = ModelPublisher;