@feedmepos/zod-repo 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,24 +6,27 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.CouchdbStaticService = void 0;
8
8
  var _common = require("@nestjs/common");
9
- var _pouchdb = _interopRequireDefault(require("pouchdb"));
10
9
  var _axios = _interopRequireDefault(require("axios"));
10
+ var _pouchdb = _interopRequireDefault(require("pouchdb"));
11
11
  var _pouchdbFind = _interopRequireDefault(require("pouchdb-find"));
12
12
  var _pouchdbSyncToAnything = _interopRequireDefault(require("pouchdb-sync-to-anything"));
13
13
  var _couchdb = require("./couchdb.service");
14
+ var _CouchdbStaticService2;
14
15
  var _initClass, _classDecs;
15
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
17
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
18
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
20
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
21
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
22
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
23
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
24
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
25
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
26
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
27
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
16
28
  function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
17
29
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
18
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
19
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
20
- function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
21
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
22
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
23
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
24
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
25
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
26
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
27
30
  function old_createMetadataMethodsForProperty(e, t, a, r) { return { getMetadata: function getMetadata(o) { old_assertNotFinished(r, "getMetadata"), old_assertMetadataKey(o); var i = e[o]; if (void 0 !== i) if (1 === t) { var n = i["public"]; if (void 0 !== n) return n[a]; } else if (2 === t) { var l = i["private"]; if (void 0 !== l) return l.get(a); } else if (Object.hasOwnProperty.call(i, "constructor")) return i.constructor; }, setMetadata: function setMetadata(o, i) { old_assertNotFinished(r, "setMetadata"), old_assertMetadataKey(o); var n = e[o]; if (void 0 === n && (n = e[o] = {}), 1 === t) { var l = n["public"]; void 0 === l && (l = n["public"] = {}), l[a] = i; } else if (2 === t) { var s = n.priv; void 0 === s && (s = n["private"] = new Map()), s.set(a, i); } else n.constructor = i; } }; }
28
31
  function old_convertMetadataMapToFinal(e, t) { var a = e[Symbol.metadata || Symbol["for"]("Symbol.metadata")], r = Object.getOwnPropertySymbols(t); if (0 !== r.length) { for (var o = 0; o < r.length; o++) { var i = r[o], n = t[i], l = a ? a[i] : null, s = n["public"], c = l ? l["public"] : null; s && c && Object.setPrototypeOf(s, c); var d = n["private"]; if (d) { var u = Array.from(d.values()), f = l ? l["private"] : null; f && (u = u.concat(f)), n["private"] = u; } l && Object.setPrototypeOf(n, l); } a && Object.setPrototypeOf(t, a), e[Symbol.metadata || Symbol["for"]("Symbol.metadata")] = t; } }
29
32
  function old_createAddInitializerMethod(e, t) { return function (a) { old_assertNotFinished(t, "addInitializer"), old_assertCallable(a, "An initializer"), e.push(a); }; }
@@ -41,18 +44,231 @@ function _applyDecs(e, t, a) { var r = [], o = {}, i = {}; return old_applyMembe
41
44
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
42
45
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
43
46
  function _setFunctionName(e, t, n) { "symbol" == _typeof(t) && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
44
- function _identity(t) { return t; }
45
47
  _pouchdb["default"].plugin(_pouchdbSyncToAnything["default"]);
46
48
  _pouchdb["default"].plugin(_pouchdbFind["default"]);
49
+ var _USER_DB_NAME = "_users";
47
50
  _classDecs = [(0, _common.Injectable)()];
48
51
  var _CouchdbStaticService;
49
- new (/*#__PURE__*/function (_identity2) {
50
- function _class() {
51
- var _this;
52
- _classCallCheck(this, _class);
53
- _this = _callSuper(this, _class, [_CouchdbStaticService]), _defineProperty(_assertThisInitialized(_this), "USER_DB_NAME", '_users'), _initClass();
54
- return _this;
52
+ var CouchdbStaticService = /*#__PURE__*/function () {
53
+ function CouchdbStaticService(configService, moduleRef) {
54
+ _classCallCheck(this, CouchdbStaticService);
55
+ this.configService = configService;
56
+ this.moduleRef = moduleRef;
57
+ this.logger = new _common.Logger(_CouchdbStaticService.name);
55
58
  }
56
- _inherits(_class, _identity2);
57
- return _createClass(_class);
58
- }(_identity))();
59
+ return _createClass(CouchdbStaticService, [{
60
+ key: "baseUrl",
61
+ get: function get() {
62
+ return this.configService.get('COUCHDB_URL') || '';
63
+ }
64
+ }, {
65
+ key: "basePublicUrl",
66
+ get: function get() {
67
+ return this.configService.get('PUBLIC_COUCHDB_URL') || '';
68
+ }
69
+ }, {
70
+ key: "getCouchdbServiceFromDbName",
71
+ value: function () {
72
+ var _getCouchdbServiceFromDbName = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(dbName) {
73
+ var db;
74
+ return _regenerator().w(function (_context) {
75
+ while (1) switch (_context.n) {
76
+ case 0:
77
+ _context.n = 1;
78
+ return this.moduleRef.create(_couchdb.CouchdbService);
79
+ case 1:
80
+ db = _context.v;
81
+ db.dbName = dbName;
82
+ return _context.a(2, db);
83
+ }
84
+ }, _callee, this);
85
+ }));
86
+ function getCouchdbServiceFromDbName(_x) {
87
+ return _getCouchdbServiceFromDbName.apply(this, arguments);
88
+ }
89
+ return getCouchdbServiceFromDbName;
90
+ }()
91
+ }, {
92
+ key: "getConnectionForDbName",
93
+ value: function () {
94
+ var _getConnectionForDbName = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(dbName) {
95
+ return _regenerator().w(function (_context2) {
96
+ while (1) switch (_context2.n) {
97
+ case 0:
98
+ _context2.n = 1;
99
+ return this.getCouchdbServiceFromDbName(dbName);
100
+ case 1:
101
+ return _context2.a(2, _context2.v.getConnection());
102
+ }
103
+ }, _callee2, this);
104
+ }));
105
+ function getConnectionForDbName(_x2) {
106
+ return _getConnectionForDbName.apply(this, arguments);
107
+ }
108
+ return getConnectionForDbName;
109
+ }()
110
+ }, {
111
+ key: "getInstance",
112
+ value: function getInstance(dbName) {
113
+ var fullPath = "".concat(this.baseUrl, "/").concat(dbName);
114
+ return new _pouchdb["default"](fullPath);
115
+ }
116
+ }, {
117
+ key: "replicate",
118
+ value: function () {
119
+ var _replicate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(fromDbName, toDbName, _filter) {
120
+ var _this = this;
121
+ return _regenerator().w(function (_context3) {
122
+ while (1) switch (_context3.n) {
123
+ case 0:
124
+ return _context3.a(2, new Promise(function (resolve, reject) {
125
+ var from = new _pouchdb["default"]("".concat(_this.baseUrl, "/").concat(fromDbName));
126
+ var to = new _pouchdb["default"]("".concat(_this.baseUrl, "/").concat(toDbName));
127
+ from.replicate.to(to, {
128
+ retry: true,
129
+ since: 0,
130
+ filter: function filter(doc) {
131
+ var result = !doc._id.includes('_design/');
132
+ if (_filter && typeof _filter === 'function') {
133
+ result = _filter(doc) && result;
134
+ }
135
+ _this.logger.verbose("should sync ".concat(doc._id, ": ").concat(result));
136
+ return result;
137
+ }
138
+ }).on('complete', function (info) {
139
+ info;
140
+ resolve();
141
+ }).on('denied', function (err) {
142
+ _this.logger.error(err);
143
+ reject(err);
144
+ }).on('error', function (err) {
145
+ _this.logger.error(err);
146
+ reject(err);
147
+ });
148
+ }));
149
+ }
150
+ }, _callee3);
151
+ }));
152
+ function replicate(_x3, _x4, _x5) {
153
+ return _replicate.apply(this, arguments);
154
+ }
155
+ return replicate;
156
+ }()
157
+ }, {
158
+ key: "createDb",
159
+ value: function createDb(dbName) {
160
+ _axios["default"].put("".concat(this.baseUrl, "/").concat(dbName));
161
+ }
162
+ }, {
163
+ key: "deleteDb",
164
+ value: function deleteDb(dbName) {
165
+ _axios["default"]["delete"]("".concat(this.baseUrl, "/").concat(dbName));
166
+ }
167
+ }, {
168
+ key: "createUser",
169
+ value: function createUser(username, password) {
170
+ var document = {
171
+ _id: "org.couchdb.user:".concat(username),
172
+ name: username,
173
+ type: 'user',
174
+ password: password,
175
+ roles: []
176
+ };
177
+ this.getInstance(_USER_DB_NAME).put(document);
178
+ }
179
+ }, {
180
+ key: "getUser",
181
+ value: function getUser(username) {
182
+ return this.getInstance(_USER_DB_NAME).get("org.couchdb.user:".concat(username));
183
+ }
184
+ }, {
185
+ key: "deleteUser",
186
+ value: function () {
187
+ var _deleteUser = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(username) {
188
+ var document;
189
+ return _regenerator().w(function (_context4) {
190
+ while (1) switch (_context4.n) {
191
+ case 0:
192
+ _context4.n = 1;
193
+ return this.getUser(username);
194
+ case 1:
195
+ document = _context4.v;
196
+ this.getInstance(_USER_DB_NAME).remove(document);
197
+ case 2:
198
+ return _context4.a(2);
199
+ }
200
+ }, _callee4, this);
201
+ }));
202
+ function deleteUser(_x6) {
203
+ return _deleteUser.apply(this, arguments);
204
+ }
205
+ return deleteUser;
206
+ }()
207
+ }, {
208
+ key: "authorizeUser",
209
+ value: function () {
210
+ var _authorizeUser = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(dbName, username) {
211
+ var document;
212
+ return _regenerator().w(function (_context5) {
213
+ while (1) switch (_context5.n) {
214
+ case 0:
215
+ document = {
216
+ admins: {
217
+ names: [username],
218
+ roles: []
219
+ },
220
+ members: {
221
+ names: [username],
222
+ roles: []
223
+ }
224
+ };
225
+ _context5.n = 1;
226
+ return _axios["default"].put("".concat(this.baseUrl, "/").concat(dbName, "/_security"), document);
227
+ case 1:
228
+ return _context5.a(2);
229
+ }
230
+ }, _callee5, this);
231
+ }));
232
+ function authorizeUser(_x7, _x8) {
233
+ return _authorizeUser.apply(this, arguments);
234
+ }
235
+ return authorizeUser;
236
+ }()
237
+ }, {
238
+ key: "resetPermission",
239
+ value: function () {
240
+ var _resetPermission = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(dbName) {
241
+ var document;
242
+ return _regenerator().w(function (_context6) {
243
+ while (1) switch (_context6.n) {
244
+ case 0:
245
+ document = {
246
+ admins: {
247
+ names: ['admin'],
248
+ roles: []
249
+ },
250
+ members: {
251
+ names: ['admin'],
252
+ roles: []
253
+ }
254
+ };
255
+ _context6.n = 1;
256
+ return _axios["default"].put("".concat(this.baseUrl, "/").concat(dbName, "/_security"), document);
257
+ case 1:
258
+ return _context6.a(2);
259
+ }
260
+ }, _callee6, this);
261
+ }));
262
+ function resetPermission(_x9) {
263
+ return _resetPermission.apply(this, arguments);
264
+ }
265
+ return resetPermission;
266
+ }()
267
+ }]);
268
+ }();
269
+ _CouchdbStaticService2 = CouchdbStaticService;
270
+ var _applyDecs2 = _applyDecs(_CouchdbStaticService2, [], _classDecs);
271
+ var _applyDecs3 = _slicedToArray(_applyDecs2, 2);
272
+ exports.CouchdbStaticService = _CouchdbStaticService = _applyDecs3[0];
273
+ _initClass = _applyDecs3[1];
274
+ _initClass();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedmepos/zod-repo",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/feedmepos/core.git"