@nocobase/server 0.7.0-alpha.4 → 0.7.0-alpha.56

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.
Files changed (124) hide show
  1. package/lib/acl/available-action.js +37 -35
  2. package/lib/acl/index.js +45 -21
  3. package/lib/app-manager.d.ts +3 -3
  4. package/lib/app-manager.js +151 -72
  5. package/lib/application.d.ts +3 -2
  6. package/lib/application.js +291 -153
  7. package/lib/commands/console.d.ts +2 -3
  8. package/lib/commands/console.js +33 -24
  9. package/lib/commands/db-auth.d.ts +3 -0
  10. package/lib/commands/db-auth.js +26 -0
  11. package/lib/commands/db-clean.d.ts +3 -0
  12. package/lib/commands/db-clean.js +27 -0
  13. package/lib/commands/db-sync.d.ts +2 -4
  14. package/lib/commands/db-sync.js +25 -23
  15. package/lib/commands/index.d.ts +1 -2
  16. package/lib/commands/index.js +29 -29
  17. package/lib/commands/install.d.ts +2 -4
  18. package/lib/commands/install.js +68 -20
  19. package/lib/commands/start.d.ts +2 -4
  20. package/lib/commands/start.js +28 -22
  21. package/lib/commands/upgrade.d.ts +6 -0
  22. package/lib/commands/upgrade.js +45 -0
  23. package/lib/helper.js +132 -61
  24. package/lib/index.js +85 -32
  25. package/lib/middlewares/data-wrapping.js +63 -55
  26. package/lib/middlewares/index.js +30 -14
  27. package/lib/middlewares/table2resource.js +89 -52
  28. package/lib/plugin-manager.js +124 -55
  29. package/lib/plugin.js +65 -45
  30. package/lib/read-config.js +159 -64
  31. package/package.json +8 -13
  32. package/esm/acl/available-action.d.ts +0 -5
  33. package/esm/acl/available-action.js +0 -36
  34. package/esm/acl/available-action.js.map +0 -1
  35. package/esm/acl/index.d.ts +0 -2
  36. package/esm/acl/index.js +0 -19
  37. package/esm/acl/index.js.map +0 -1
  38. package/esm/app-manager.d.ts +0 -19
  39. package/esm/app-manager.js +0 -69
  40. package/esm/app-manager.js.map +0 -1
  41. package/esm/application.d.ts +0 -97
  42. package/esm/application.js +0 -156
  43. package/esm/application.js.map +0 -1
  44. package/esm/commands/console.d.ts +0 -4
  45. package/esm/commands/console.js +0 -25
  46. package/esm/commands/console.js.map +0 -1
  47. package/esm/commands/create-plugin/create-plugin.d.ts +0 -2
  48. package/esm/commands/create-plugin/create-plugin.js +0 -29
  49. package/esm/commands/create-plugin/create-plugin.js.map +0 -1
  50. package/esm/commands/create-plugin/index.d.ts +0 -5
  51. package/esm/commands/create-plugin/index.js +0 -6
  52. package/esm/commands/create-plugin/index.js.map +0 -1
  53. package/esm/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
  54. package/esm/commands/create-plugin/resources/templates/package-json.js +0 -11
  55. package/esm/commands/create-plugin/resources/templates/package-json.js.map +0 -1
  56. package/esm/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
  57. package/esm/commands/create-plugin/resources/templates/plugin.js +0 -12
  58. package/esm/commands/create-plugin/resources/templates/plugin.js.map +0 -1
  59. package/esm/commands/db-sync.d.ts +0 -5
  60. package/esm/commands/db-sync.js +0 -25
  61. package/esm/commands/db-sync.js.map +0 -1
  62. package/esm/commands/index.d.ts +0 -3
  63. package/esm/commands/index.js +0 -26
  64. package/esm/commands/index.js.map +0 -1
  65. package/esm/commands/install.d.ts +0 -5
  66. package/esm/commands/install.js +0 -23
  67. package/esm/commands/install.js.map +0 -1
  68. package/esm/commands/start.d.ts +0 -5
  69. package/esm/commands/start.js +0 -23
  70. package/esm/commands/start.js.map +0 -1
  71. package/esm/helper.d.ts +0 -7
  72. package/esm/helper.js +0 -59
  73. package/esm/helper.js.map +0 -1
  74. package/esm/index.d.ts +0 -7
  75. package/esm/index.js +0 -9
  76. package/esm/index.js.map +0 -1
  77. package/esm/middlewares/data-wrapping.d.ts +0 -3
  78. package/esm/middlewares/data-wrapping.js +0 -54
  79. package/esm/middlewares/data-wrapping.js.map +0 -1
  80. package/esm/middlewares/index.d.ts +0 -2
  81. package/esm/middlewares/index.js +0 -3
  82. package/esm/middlewares/index.js.map +0 -1
  83. package/esm/middlewares/table2resource.d.ts +0 -6
  84. package/esm/middlewares/table2resource.js +0 -51
  85. package/esm/middlewares/table2resource.js.map +0 -1
  86. package/esm/plugin-manager.d.ts +0 -23
  87. package/esm/plugin-manager.js +0 -57
  88. package/esm/plugin-manager.js.map +0 -1
  89. package/esm/plugin.d.ts +0 -32
  90. package/esm/plugin.js +0 -43
  91. package/esm/plugin.js.map +0 -1
  92. package/esm/read-config.d.ts +0 -8
  93. package/esm/read-config.js +0 -63
  94. package/esm/read-config.js.map +0 -1
  95. package/lib/acl/available-action.js.map +0 -1
  96. package/lib/acl/index.js.map +0 -1
  97. package/lib/app-manager.js.map +0 -1
  98. package/lib/application.js.map +0 -1
  99. package/lib/commands/console.js.map +0 -1
  100. package/lib/commands/create-plugin/create-plugin.d.ts +0 -2
  101. package/lib/commands/create-plugin/create-plugin.js +0 -31
  102. package/lib/commands/create-plugin/create-plugin.js.map +0 -1
  103. package/lib/commands/create-plugin/index.d.ts +0 -5
  104. package/lib/commands/create-plugin/index.js +0 -8
  105. package/lib/commands/create-plugin/index.js.map +0 -1
  106. package/lib/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
  107. package/lib/commands/create-plugin/resources/templates/package-json.js +0 -13
  108. package/lib/commands/create-plugin/resources/templates/package-json.js.map +0 -1
  109. package/lib/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
  110. package/lib/commands/create-plugin/resources/templates/plugin.js +0 -33
  111. package/lib/commands/create-plugin/resources/templates/plugin.js.map +0 -1
  112. package/lib/commands/db-sync.js.map +0 -1
  113. package/lib/commands/index.js.map +0 -1
  114. package/lib/commands/install.js.map +0 -1
  115. package/lib/commands/start.js.map +0 -1
  116. package/lib/helper.js.map +0 -1
  117. package/lib/index.js.map +0 -1
  118. package/lib/middlewares/data-wrapping.js.map +0 -1
  119. package/lib/middlewares/index.js.map +0 -1
  120. package/lib/middlewares/table2resource.js.map +0 -1
  121. package/lib/plugin-manager.js.map +0 -1
  122. package/lib/plugin.js.map +0 -1
  123. package/lib/read-config.js.map +0 -1
  124. package/tsconfig.build.json +0 -9
@@ -1,58 +1,66 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.dataWrapping = void 0;
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.dataWrapping = dataWrapping;
7
+ exports.default = void 0;
8
+ const _excluded = ["rows"];
9
+
10
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
11
+
12
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
13
+
14
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
15
+
16
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
17
+
24
18
  function dataWrapping() {
25
- return function dataWrapping(ctx, next) {
26
- var _a;
27
- return __awaiter(this, void 0, void 0, function* () {
28
- yield next();
29
- if (ctx.withoutDataWrapping) {
30
- return;
31
- }
32
- if (!((_a = ctx === null || ctx === void 0 ? void 0 : ctx.action) === null || _a === void 0 ? void 0 : _a.params)) {
33
- return;
34
- }
35
- if (ctx.body instanceof Buffer) {
36
- return;
37
- }
38
- if (!ctx.body) {
39
- ctx.body = {};
40
- }
41
- const _b = ctx.body, { rows } = _b, meta = __rest(_b, ["rows"]);
42
- if (rows) {
43
- ctx.body = {
44
- data: rows,
45
- meta,
46
- };
47
- }
48
- else {
49
- ctx.body = {
50
- data: ctx.body,
51
- };
52
- }
53
- });
54
- };
19
+ return /*#__PURE__*/function () {
20
+ var _dataWrapping = _asyncToGenerator(function* (ctx, next) {
21
+ var _ctx$action;
22
+
23
+ yield next();
24
+
25
+ if (ctx.withoutDataWrapping) {
26
+ return;
27
+ }
28
+
29
+ if (!(ctx === null || ctx === void 0 ? void 0 : (_ctx$action = ctx.action) === null || _ctx$action === void 0 ? void 0 : _ctx$action.params)) {
30
+ return;
31
+ }
32
+
33
+ if (ctx.body instanceof Buffer) {
34
+ return;
35
+ }
36
+
37
+ if (!ctx.body) {
38
+ ctx.body = {};
39
+ }
40
+
41
+ const _ctx$body = ctx.body,
42
+ rows = _ctx$body.rows,
43
+ meta = _objectWithoutProperties(_ctx$body, _excluded);
44
+
45
+ if (rows) {
46
+ ctx.body = {
47
+ data: rows,
48
+ meta
49
+ };
50
+ } else {
51
+ ctx.body = {
52
+ data: ctx.body
53
+ };
54
+ }
55
+ });
56
+
57
+ function dataWrapping(_x, _x2) {
58
+ return _dataWrapping.apply(this, arguments);
59
+ }
60
+
61
+ return dataWrapping;
62
+ }();
55
63
  }
56
- exports.dataWrapping = dataWrapping;
57
- exports.default = dataWrapping;
58
- //# sourceMappingURL=data-wrapping.js.map
64
+
65
+ var _default = dataWrapping;
66
+ exports.default = _default;
@@ -1,15 +1,31 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./table2resource"), exports);
14
- __exportStar(require("./data-wrapping"), exports);
15
- //# sourceMappingURL=index.js.map
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _table2resource = require("./table2resource");
8
+
9
+ Object.keys(_table2resource).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _table2resource[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _table2resource[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _dataWrapping = require("./data-wrapping");
21
+
22
+ Object.keys(_dataWrapping).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _dataWrapping[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function get() {
28
+ return _dataWrapping[key];
29
+ }
30
+ });
31
+ });
@@ -1,55 +1,92 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.table2resource = void 0;
13
- const resourcer_1 = require("@nocobase/resourcer");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ exports.table2resource = table2resource;
8
+
9
+ function _resourcer() {
10
+ const data = require("@nocobase/resourcer");
11
+
12
+ _resourcer = function _resourcer() {
13
+ return data;
14
+ };
15
+
16
+ return data;
17
+ }
18
+
19
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
20
+
21
+ 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."); }
22
+
23
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
24
+
25
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
26
+
27
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
28
+
29
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
30
+
31
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
32
+
33
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
34
+
14
35
  function table2resource() {
15
- return function table2resource(ctx, next) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const resourcer = ctx.resourcer;
18
- const database = ctx.db;
19
- let params = (0, resourcer_1.parseRequest)({
20
- path: ctx.request.path,
21
- method: ctx.request.method,
22
- }, {
23
- prefix: resourcer.options.prefix,
24
- accessors: resourcer.options.accessors,
25
- });
26
- if (!params) {
27
- return next();
28
- }
29
- const resourceName = (0, resourcer_1.getNameByParams)(params);
30
- // 如果资源名称未被定义
31
- if (resourcer.isDefined(resourceName)) {
32
- return next();
33
- }
34
- const [collectionName, fieldName] = resourceName.split('.');
35
- // 如果经过加载后是已经定义的表
36
- if (!database.hasCollection(collectionName)) {
37
- return next();
38
- }
39
- const collection = database.getCollection(collectionName);
40
- let resourceType = 'single';
41
- if (fieldName && collection.hasField(fieldName)) {
42
- const field = collection.getField(fieldName);
43
- resourceType = field.type;
44
- }
45
- resourcer.define({
46
- type: resourceType,
47
- name: resourceName,
48
- });
49
- return next();
50
- });
51
- };
36
+ return /*#__PURE__*/function () {
37
+ var _table2resource = _asyncToGenerator(function* (ctx, next) {
38
+ const resourcer = ctx.resourcer;
39
+ const database = ctx.db;
40
+ let params = (0, _resourcer().parseRequest)({
41
+ path: ctx.request.path,
42
+ method: ctx.request.method
43
+ }, {
44
+ prefix: resourcer.options.prefix,
45
+ accessors: resourcer.options.accessors
46
+ });
47
+
48
+ if (!params) {
49
+ return next();
50
+ }
51
+
52
+ const resourceName = (0, _resourcer().getNameByParams)(params); // 如果资源名称未被定义
53
+
54
+ if (resourcer.isDefined(resourceName)) {
55
+ return next();
56
+ }
57
+
58
+ const _resourceName$split = resourceName.split('.'),
59
+ _resourceName$split2 = _slicedToArray(_resourceName$split, 2),
60
+ collectionName = _resourceName$split2[0],
61
+ fieldName = _resourceName$split2[1]; // 如果经过加载后是已经定义的表
62
+
63
+
64
+ if (!database.hasCollection(collectionName)) {
65
+ return next();
66
+ }
67
+
68
+ const collection = database.getCollection(collectionName);
69
+ let resourceType = 'single';
70
+
71
+ if (fieldName && collection.hasField(fieldName)) {
72
+ const field = collection.getField(fieldName);
73
+ resourceType = field.type;
74
+ }
75
+
76
+ resourcer.define({
77
+ type: resourceType,
78
+ name: resourceName
79
+ });
80
+ return next();
81
+ });
82
+
83
+ function table2resource(_x, _x2) {
84
+ return _table2resource.apply(this, arguments);
85
+ }
86
+
87
+ return table2resource;
88
+ }();
52
89
  }
53
- exports.table2resource = table2resource;
54
- exports.default = table2resource;
55
- //# sourceMappingURL=table2resource.js.map
90
+
91
+ var _default = table2resource;
92
+ exports.default = _default;
@@ -1,61 +1,130 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
12
6
  exports.PluginManager = void 0;
7
+
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+
10
+ 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."); }
11
+
12
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
13
+
14
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
+
16
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
17
+
18
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
19
+
20
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
21
+
22
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
23
+
24
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
25
+
13
26
  class PluginManager {
14
- constructor(options) {
15
- this.plugins = new Map();
16
- this.app = options.app;
27
+ constructor(options) {
28
+ this.app = void 0;
29
+ this.plugins = new Map();
30
+ this.app = options.app;
31
+ }
32
+
33
+ getPlugins() {
34
+ return this.plugins;
35
+ }
36
+
37
+ get(name) {
38
+ return this.plugins.get(name);
39
+ }
40
+
41
+ add(pluginClass, options) {
42
+ const instance = new pluginClass(this.app, options);
43
+ const name = instance.getName();
44
+
45
+ if (this.plugins.has(name)) {
46
+ throw new Error(`plugin name [${name}] `);
17
47
  }
18
- getPlugins() {
19
- return this.plugins;
20
- }
21
- get(name) {
22
- return this.plugins.get(name);
23
- }
24
- add(pluginClass, options) {
25
- const instance = new pluginClass(this.app, options);
26
- const name = instance.getName();
27
- if (this.plugins.has(name)) {
28
- throw new Error(`plugin name [${name}] `);
48
+
49
+ this.plugins.set(name, instance);
50
+ return instance;
51
+ }
52
+
53
+ load() {
54
+ var _this = this;
55
+
56
+ return _asyncToGenerator(function* () {
57
+ yield _this.app.emitAsync('beforeLoadAll');
58
+
59
+ var _iterator = _createForOfIteratorHelper(_this.plugins),
60
+ _step;
61
+
62
+ try {
63
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
64
+ const _step$value = _slicedToArray(_step.value, 2),
65
+ name = _step$value[0],
66
+ plugin = _step$value[1];
67
+
68
+ yield plugin.beforeLoad();
29
69
  }
30
- this.plugins.set(name, instance);
31
- return instance;
32
- }
33
- load() {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- yield this.app.emitAsync('beforeLoadAll');
36
- for (const [name, plugin] of this.plugins) {
37
- yield plugin.beforeLoad();
38
- }
39
- for (const [name, plugin] of this.plugins) {
40
- yield this.app.emitAsync('beforeLoadPlugin', plugin);
41
- yield plugin.load();
42
- yield this.app.emitAsync('afterLoadPlugin', plugin);
43
- }
44
- yield this.app.emitAsync('afterLoadAll');
45
- });
46
- }
47
- install(options) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- for (const [name, plugin] of this.plugins) {
50
- yield this.app.emitAsync('beforeInstallPlugin', plugin, options);
51
- yield plugin.install(options);
52
- yield this.app.emitAsync('afterInstallPlugin', plugin, options);
53
- }
54
- });
55
- }
56
- static resolvePlugin(pluginName) {
57
- return require(pluginName).default;
58
- }
70
+ } catch (err) {
71
+ _iterator.e(err);
72
+ } finally {
73
+ _iterator.f();
74
+ }
75
+
76
+ var _iterator2 = _createForOfIteratorHelper(_this.plugins),
77
+ _step2;
78
+
79
+ try {
80
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
81
+ const _step2$value = _slicedToArray(_step2.value, 2),
82
+ name = _step2$value[0],
83
+ plugin = _step2$value[1];
84
+
85
+ yield _this.app.emitAsync('beforeLoadPlugin', plugin);
86
+ yield plugin.load();
87
+ yield _this.app.emitAsync('afterLoadPlugin', plugin);
88
+ }
89
+ } catch (err) {
90
+ _iterator2.e(err);
91
+ } finally {
92
+ _iterator2.f();
93
+ }
94
+
95
+ yield _this.app.emitAsync('afterLoadAll');
96
+ })();
97
+ }
98
+
99
+ install(options = {}) {
100
+ var _this2 = this;
101
+
102
+ return _asyncToGenerator(function* () {
103
+ var _iterator3 = _createForOfIteratorHelper(_this2.plugins),
104
+ _step3;
105
+
106
+ try {
107
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
108
+ const _step3$value = _slicedToArray(_step3.value, 2),
109
+ name = _step3$value[0],
110
+ plugin = _step3$value[1];
111
+
112
+ yield _this2.app.emitAsync('beforeInstallPlugin', plugin, options);
113
+ yield plugin.install(options);
114
+ yield _this2.app.emitAsync('afterInstallPlugin', plugin, options);
115
+ }
116
+ } catch (err) {
117
+ _iterator3.e(err);
118
+ } finally {
119
+ _iterator3.f();
120
+ }
121
+ })();
122
+ }
123
+
124
+ static resolvePlugin(pluginName) {
125
+ return require(pluginName).default;
126
+ }
127
+
59
128
  }
60
- exports.PluginManager = PluginManager;
61
- //# sourceMappingURL=plugin-manager.js.map
129
+
130
+ exports.PluginManager = PluginManager;
package/lib/plugin.js CHANGED
@@ -1,50 +1,70 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
15
6
  exports.Plugin = void 0;
16
- const find_package_json_1 = __importDefault(require("find-package-json"));
7
+
8
+ function _findPackageJson() {
9
+ const data = _interopRequireDefault(require("find-package-json"));
10
+
11
+ _findPackageJson = function _findPackageJson() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
+
22
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
23
+
17
24
  class Plugin {
18
- constructor(app, options) {
19
- this.app = app;
20
- this.db = app.db;
21
- this.setOptions(options);
22
- }
23
- setOptions(options) {
24
- this.options = options || {};
25
- }
26
- beforeLoad() { }
27
- install(options) {
28
- return __awaiter(this, void 0, void 0, function* () { });
29
- }
30
- load() {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const collectionPath = this.collectionPath();
33
- if (collectionPath) {
34
- yield this.db.import({
35
- directory: collectionPath,
36
- });
37
- }
25
+ constructor(app, options) {
26
+ this.options = void 0;
27
+ this.app = void 0;
28
+ this.db = void 0;
29
+ this.app = app;
30
+ this.db = app.db;
31
+ this.setOptions(options);
32
+ }
33
+
34
+ setOptions(options) {
35
+ this.options = options || {};
36
+ }
37
+
38
+ beforeLoad() {}
39
+
40
+ install(options) {
41
+ return _asyncToGenerator(function* () {})();
42
+ }
43
+
44
+ load() {
45
+ var _this = this;
46
+
47
+ return _asyncToGenerator(function* () {
48
+ const collectionPath = _this.collectionPath();
49
+
50
+ if (collectionPath) {
51
+ yield _this.db.import({
52
+ directory: collectionPath
38
53
  });
39
- }
40
- collectionPath() {
41
- return null;
42
- }
43
- getPackageName(dirname) {
44
- const f = (0, find_package_json_1.default)(dirname);
45
- const packageObj = f.next().value;
46
- return packageObj['name'];
47
- }
54
+ }
55
+ })();
56
+ }
57
+
58
+ collectionPath() {
59
+ return null;
60
+ }
61
+
62
+ getPackageName(dirname) {
63
+ const f = (0, _findPackageJson().default)(dirname);
64
+ const packageObj = f.next().value;
65
+ return packageObj['name'];
66
+ }
67
+
48
68
  }
49
- exports.Plugin = Plugin;
50
- //# sourceMappingURL=plugin.js.map
69
+
70
+ exports.Plugin = Plugin;