1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports["default"] = exports.GrantCacheStore = exports.GrantCacheApi = void 0;
|
9 |
|
10 | var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
11 |
|
12 | var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
13 |
|
14 | var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
|
15 |
|
16 | var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
17 |
|
18 | var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
|
19 |
|
20 | var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
|
21 |
|
22 | var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
23 |
|
24 | var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
25 |
|
26 | var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
27 |
|
28 | var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
29 |
|
30 | var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
31 |
|
32 | var _Api2 = _interopRequireDefault(require("@lskjs/mobx/mobxStores/Api"));
|
33 |
|
34 | var _Store2 = _interopRequireDefault(require("@lskjs/mobx/mobxStores/Store"));
|
35 |
|
36 | var _mobx = require("mobx");
|
37 |
|
38 | var _class, _descriptor, _descriptor2, _class2, _temp;
|
39 |
|
40 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
41 |
|
42 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
43 |
|
44 | var GrantCacheApi = function (_Api) {
|
45 | (0, _inherits2["default"])(GrantCacheApi, _Api);
|
46 |
|
47 | var _super = _createSuper(GrantCacheApi);
|
48 |
|
49 | function GrantCacheApi() {
|
50 | var _this;
|
51 |
|
52 | (0, _classCallCheck2["default"])(this, GrantCacheApi);
|
53 |
|
54 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
55 | args[_key] = arguments[_key];
|
56 | }
|
57 |
|
58 | _this = _super.call.apply(_super, [this].concat(args));
|
59 | _this.baseURL = '/api/grant';
|
60 | return _this;
|
61 | }
|
62 |
|
63 | (0, _createClass2["default"])(GrantCacheApi, [{
|
64 | key: "ask",
|
65 | value: function ask(data, params) {
|
66 | return this.fetch('/ask', {
|
67 | method: 'POST',
|
68 | params: params,
|
69 | data: data
|
70 | });
|
71 | }
|
72 | }]);
|
73 | return GrantCacheApi;
|
74 | }(_Api2["default"]);
|
75 |
|
76 | exports.GrantCacheApi = GrantCacheApi;
|
77 | var GrantCacheStore = (_class = (_temp = _class2 = function (_Store) {
|
78 | (0, _inherits2["default"])(GrantCacheStore, _Store);
|
79 |
|
80 | var _super2 = _createSuper(GrantCacheStore);
|
81 |
|
82 | function GrantCacheStore() {
|
83 | var _this2;
|
84 |
|
85 | (0, _classCallCheck2["default"])(this, GrantCacheStore);
|
86 |
|
87 | for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
88 | args[_key2] = arguments[_key2];
|
89 | }
|
90 |
|
91 | _this2 = _super2.call.apply(_super2, [this].concat(args));
|
92 | (0, _initializerDefineProperty2["default"])(_this2, "params", _descriptor, (0, _assertThisInitialized2["default"])(_this2));
|
93 | (0, _initializerDefineProperty2["default"])(_this2, "res", _descriptor2, (0, _assertThisInitialized2["default"])(_this2));
|
94 | return _this2;
|
95 | }
|
96 |
|
97 | (0, _createClass2["default"])(GrantCacheStore, [{
|
98 | key: "can",
|
99 | value: function can(name) {
|
100 | var res = this.get(name);
|
101 | return !!res;
|
102 | }
|
103 | }, {
|
104 | key: "get",
|
105 | value: function get(name) {
|
106 | var log = this.constructor.app.log;
|
107 | var res = (this.res || {})[name];
|
108 |
|
109 | if (res == null) {
|
110 | log.warn('?GrantCacheStore.get', 'cant find rule in grantCache', {
|
111 | action: name
|
112 | }, this.res, res);
|
113 | return null;
|
114 | }
|
115 |
|
116 | return res;
|
117 | }
|
118 | }, {
|
119 | key: "update",
|
120 | value: function () {
|
121 | var _update = (0, _asyncToGenerator2["default"])( _regenerator["default"].mark(function _callee() {
|
122 | var params,
|
123 | _yield$this$construct,
|
124 | res,
|
125 | _args = arguments;
|
126 |
|
127 | return _regenerator["default"].wrap(function _callee$(_context) {
|
128 | while (1) {
|
129 | switch (_context.prev = _context.next) {
|
130 | case 0:
|
131 | params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {
|
132 | clearCache: 1
|
133 | };
|
134 |
|
135 | if (this.debug) {
|
136 | this.log.debug('grantCache.update', [this.res, this.res['cabinet.verifyAccess']]);
|
137 | }
|
138 |
|
139 | _context.next = 4;
|
140 | return this.constructor.api.ask((0, _mobx.toJS)(this.params), params);
|
141 |
|
142 | case 4:
|
143 | _yield$this$construct = _context.sent;
|
144 | res = _yield$this$construct.data;
|
145 |
|
146 | this.res = res;
|
147 |
|
148 | case 7:
|
149 | case "end":
|
150 | return _context.stop();
|
151 | }
|
152 | }
|
153 | }, _callee, this);
|
154 | }));
|
155 |
|
156 | function update() {
|
157 | return _update.apply(this, arguments);
|
158 | }
|
159 |
|
160 | return update;
|
161 | }()
|
162 | }], [{
|
163 | key: "create",
|
164 | value: function () {
|
165 | var _create = (0, _asyncToGenerator2["default"])( _regenerator["default"].mark(function _callee2(params) {
|
166 | var _yield$this$api$ask, res, item;
|
167 |
|
168 | return _regenerator["default"].wrap(function _callee2$(_context2) {
|
169 | while (1) {
|
170 | switch (_context2.prev = _context2.next) {
|
171 | case 0:
|
172 | _context2.next = 2;
|
173 | return this.api.ask((0, _mobx.toJS)(params));
|
174 |
|
175 | case 2:
|
176 | _yield$this$api$ask = _context2.sent;
|
177 | res = _yield$this$api$ask.data;
|
178 | item = new this({
|
179 | params: params,
|
180 | res: res
|
181 | });
|
182 | return _context2.abrupt("return", item);
|
183 |
|
184 | case 6:
|
185 | case "end":
|
186 | return _context2.stop();
|
187 | }
|
188 | }
|
189 | }, _callee2, this);
|
190 | }));
|
191 |
|
192 | function create(_x) {
|
193 | return _create.apply(this, arguments);
|
194 | }
|
195 |
|
196 | return create;
|
197 | }()
|
198 | }]);
|
199 | return GrantCacheStore;
|
200 | }(_Store2["default"]), _class2.Api = GrantCacheApi, _temp), (_descriptor = (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "params", [_mobx.observable], {
|
201 | configurable: true,
|
202 | enumerable: true,
|
203 | writable: true,
|
204 | initializer: null
|
205 | }), _descriptor2 = (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "res", [_mobx.observable], {
|
206 | configurable: true,
|
207 | enumerable: true,
|
208 | writable: true,
|
209 | initializer: null
|
210 | }), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "can", [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, "can"), _class.prototype), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "get", [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, "get"), _class.prototype)), _class);
|
211 | exports.GrantCacheStore = GrantCacheStore;
|
212 | var _default = GrantCacheStore;
|
213 | exports["default"] = _default;
|
214 |
|
\ | No newline at end of file |