UNPKG

casbin

Version:

An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS

80 lines (79 loc) 2.86 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringAdapter = void 0; const helper_1 = require("./helper"); /** * StringAdapter is the string adapter for Casbin. * It can load policy from a string. */ class StringAdapter { /** * StringAdapter is the constructor for StringAdapter. * @param {string} policy policy formatted as a CSV string. */ constructor(policy) { this.policy = policy; } loadPolicy(model) { return __awaiter(this, void 0, void 0, function* () { if (!this.policy) { throw new Error('Invalid policy, policy document cannot be false-y'); } yield this.loadRules(model, helper_1.Helper.loadPolicyLine); }); } loadRules(model, handler) { return __awaiter(this, void 0, void 0, function* () { const rules = this.policy.split('\n'); rules.forEach((n, index) => { const line = n.trim(); if (!line) { return; } handler(n, model); }); }); } /** * savePolicy saves all policy rules to the storage. */ savePolicy(model) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } /** * addPolicy adds a policy rule to the storage. */ addPolicy(sec, ptype, rule) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } /** * removePolicy removes a policy rule from the storage. */ removePolicy(sec, ptype, rule) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } /** * removeFilteredPolicy removes policy rules that match the filter from the storage. */ removeFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues) { return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemented'); }); } } exports.StringAdapter = StringAdapter;