@nocobase/server 0.9.1-alpha.2 → 0.9.2-alpha.2

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 (39) hide show
  1. package/lib/acl/index.js +3 -18
  2. package/lib/app-manager.d.ts +9 -9
  3. package/lib/app-manager.js +58 -89
  4. package/lib/application.js +25 -171
  5. package/lib/commands/console.js +0 -7
  6. package/lib/commands/db-auth.js +0 -5
  7. package/lib/commands/db-clean.js +0 -5
  8. package/lib/commands/db-sync.js +0 -4
  9. package/lib/commands/index.js +2 -12
  10. package/lib/commands/install.js +0 -14
  11. package/lib/commands/migrator.js +0 -5
  12. package/lib/commands/pm.js +3 -10
  13. package/lib/commands/start.js +0 -5
  14. package/lib/commands/upgrade.js +0 -8
  15. package/lib/helper.js +13 -36
  16. package/lib/index.js +0 -15
  17. package/lib/middlewares/data-template.d.ts +2 -0
  18. package/lib/middlewares/data-template.js +147 -0
  19. package/lib/middlewares/data-wrapping.js +4 -26
  20. package/lib/middlewares/db2resource.js +7 -25
  21. package/lib/middlewares/i18n.js +0 -8
  22. package/lib/middlewares/index.d.ts +1 -0
  23. package/lib/middlewares/index.js +13 -5
  24. package/lib/middlewares/parse-variables.d.ts +1 -0
  25. package/lib/middlewares/parse-variables.js +79 -0
  26. package/lib/migration.js +0 -7
  27. package/lib/plugin-manager/index.d.ts +1 -1
  28. package/lib/plugin-manager/index.js +4 -6
  29. package/lib/plugin-manager/options/collection.d.ts +1 -15
  30. package/lib/plugin-manager/options/collection.js +10 -3
  31. package/lib/plugin-manager/options/resource.js +0 -16
  32. package/lib/plugin-manager/{PluginManagerRepository.d.ts → plugin-manager-repository.d.ts} +1 -1
  33. package/lib/plugin-manager/{PluginManagerRepository.js → plugin-manager-repository.js} +49 -32
  34. package/lib/plugin-manager/{PluginManager.d.ts → plugin-manager.d.ts} +1 -1
  35. package/lib/plugin-manager/{PluginManager.js → plugin-manager.js} +83 -202
  36. package/lib/plugin.d.ts +2 -0
  37. package/lib/plugin.js +6 -20
  38. package/lib/read-config.js +5 -48
  39. package/package.json +9 -7
@@ -4,46 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PluginManagerRepository = void 0;
7
-
8
7
  function _database() {
9
8
  const data = require("@nocobase/database");
10
-
11
9
  _database = function _database() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
-
20
15
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
-
22
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
-
16
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
24
19
  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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
25
-
26
20
  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); }
27
-
28
21
  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; }
29
-
30
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); } }
31
-
32
23
  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); }); }; }
33
-
34
24
  class PluginManagerRepository extends _database().Repository {
35
25
  constructor(...args) {
36
26
  super(...args);
37
27
  this.pm = void 0;
38
28
  }
39
-
40
29
  setPluginManager(pm) {
41
30
  this.pm = pm;
42
31
  }
43
-
44
32
  remove(name) {
45
33
  var _this = this;
46
-
47
34
  return _asyncToGenerator(function* () {
48
35
  yield _this.destroy({
49
36
  filter: {
@@ -52,12 +39,50 @@ class PluginManagerRepository extends _database().Repository {
52
39
  });
53
40
  })();
54
41
  }
55
-
56
42
  enable(name) {
57
43
  var _this2 = this;
58
-
59
44
  return _asyncToGenerator(function* () {
60
45
  const pluginNames = typeof name === 'string' ? [name] : name;
46
+ const plugins = pluginNames.map(name => _this2.pm.plugins.get(name));
47
+ var _iterator = _createForOfIteratorHelper(plugins),
48
+ _step;
49
+ try {
50
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
51
+ const plugin = _step.value;
52
+ const requiredPlugins = plugin.requiredPlugins();
53
+ var _iterator3 = _createForOfIteratorHelper(requiredPlugins),
54
+ _step3;
55
+ try {
56
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
57
+ const requiredPluginName = _step3.value;
58
+ const requiredPlugin = _this2.pm.plugins.get(requiredPluginName);
59
+ if (!requiredPlugin.enabled) {
60
+ throw new Error(`${plugin.name} plugin need ${requiredPluginName} plugin enabled`);
61
+ }
62
+ }
63
+ } catch (err) {
64
+ _iterator3.e(err);
65
+ } finally {
66
+ _iterator3.f();
67
+ }
68
+ }
69
+ } catch (err) {
70
+ _iterator.e(err);
71
+ } finally {
72
+ _iterator.f();
73
+ }
74
+ var _iterator2 = _createForOfIteratorHelper(plugins),
75
+ _step2;
76
+ try {
77
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
78
+ const plugin = _step2.value;
79
+ yield plugin.beforeEnable();
80
+ }
81
+ } catch (err) {
82
+ _iterator2.e(err);
83
+ } finally {
84
+ _iterator2.f();
85
+ }
61
86
  yield _this2.update({
62
87
  filter: {
63
88
  name
@@ -70,10 +95,8 @@ class PluginManagerRepository extends _database().Repository {
70
95
  return pluginNames;
71
96
  })();
72
97
  }
73
-
74
98
  disable(name) {
75
99
  var _this3 = this;
76
-
77
100
  return _asyncToGenerator(function* () {
78
101
  const pluginNames = typeof name === 'string' ? [name] : name;
79
102
  yield _this3.update({
@@ -88,22 +111,18 @@ class PluginManagerRepository extends _database().Repository {
88
111
  return pluginNames;
89
112
  })();
90
113
  }
91
-
92
114
  load() {
93
115
  var _this4 = this;
94
-
95
116
  return _asyncToGenerator(function* () {
96
117
  // sort plugins by id
97
118
  const items = yield _this4.find({
98
119
  sort: 'id'
99
120
  });
100
-
101
- var _iterator = _createForOfIteratorHelper(items),
102
- _step;
103
-
121
+ var _iterator4 = _createForOfIteratorHelper(items),
122
+ _step4;
104
123
  try {
105
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
106
- const item = _step.value;
124
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
125
+ const item = _step4.value;
107
126
  yield _this4.pm.addStatic(item.get('name'), _objectSpread(_objectSpread({}, item.get('options')), {}, {
108
127
  name: item.get('name'),
109
128
  version: item.get('version'),
@@ -112,13 +131,11 @@ class PluginManagerRepository extends _database().Repository {
112
131
  }));
113
132
  }
114
133
  } catch (err) {
115
- _iterator.e(err);
134
+ _iterator4.e(err);
116
135
  } finally {
117
- _iterator.f();
136
+ _iterator4.f();
118
137
  }
119
138
  })();
120
139
  }
121
-
122
140
  }
123
-
124
141
  exports.PluginManagerRepository = PluginManagerRepository;
@@ -3,7 +3,7 @@ import { CleanOptions, Collection, SyncOptions } from '@nocobase/database';
3
3
  import net from 'net';
4
4
  import Application from '../application';
5
5
  import { Plugin } from '../plugin';
6
- import { PluginManagerRepository } from './PluginManagerRepository';
6
+ import { PluginManagerRepository } from './plugin-manager-repository';
7
7
  export interface PluginManagerOptions {
8
8
  app: Application;
9
9
  plugins?: any[];