UNPKG

@baqhub/sdk

Version:

The official JavaScript SDK for the BAQ federated app platform.

51 lines (50 loc) 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RecordPermissions = exports.RRecordPermissions = void 0; const tslib_1 = require("tslib"); const IO = tslib_1.__importStar(require("../../helpers/io.js")); const entityLink_js_1 = require("../links/entityLink.js"); // // Runtime model. // const RPermissionLink = entityLink_js_1.EntityLink.io(); exports.RRecordPermissions = IO.partialObject({ read: IO.union([IO.literal("public"), IO.readonlyArray(RPermissionLink)]), write: IO.readonlyArray(RPermissionLink), notify: IO.readonlyArray(RPermissionLink), }); // // I/O. // const publicPermissions = { read: "public", }; const privatePermissions = {}; function buildSimplePermissions(authorEntity, otherEntities) { const authorEntityLink = entityLink_js_1.EntityLink.new(authorEntity); const otherEntityLinks = otherEntities.map(entityLink_js_1.EntityLink.new); return { read: [authorEntityLink, ...otherEntityLinks], }; } function buildReadonlyPermissions(authorEntity, otherEntities) { const authorEntityLink = entityLink_js_1.EntityLink.new(authorEntity); const otherEntityLinks = otherEntities.map(entityLink_js_1.EntityLink.new); return { read: [authorEntityLink, ...otherEntityLinks], write: [], }; } function toReadEntities({ read }) { if (!read || read === "public") { return []; } return read.map(l => l.entity); } exports.RecordPermissions = { public: publicPermissions, private: privatePermissions, simple: buildSimplePermissions, readonly: buildReadonlyPermissions, toReadEntities, };