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

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
package/lib/plugin.d.ts CHANGED
@@ -31,9 +31,11 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
31
31
  beforeLoad(): void;
32
32
  load(): Promise<void>;
33
33
  install(options?: InstallOptions): Promise<void>;
34
+ beforeEnable(): Promise<void>;
34
35
  afterEnable(): Promise<void>;
35
36
  afterDisable(): Promise<void>;
36
37
  remove(): Promise<void>;
37
38
  importCollections(collectionsPath: string): Promise<void>;
39
+ requiredPlugins(): any[];
38
40
  }
39
41
  export default Plugin;
package/lib/plugin.js CHANGED
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.Plugin = void 0;
7
-
8
7
  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); } }
9
-
10
8
  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); }); }; }
11
-
12
9
  class Plugin {
13
10
  constructor(app, options) {
14
11
  this.options = void 0;
@@ -18,58 +15,46 @@ class Plugin {
18
15
  this.setOptions(options);
19
16
  this.afterAdd();
20
17
  }
21
-
22
18
  get name() {
23
19
  return this.options.name;
24
20
  }
25
-
26
21
  get db() {
27
22
  return this.app.db;
28
23
  }
29
-
30
24
  get enabled() {
31
25
  return this.options.enabled;
32
26
  }
33
-
34
27
  set enabled(value) {
35
28
  this.options.enabled = value;
36
29
  }
37
-
38
30
  setOptions(options) {
39
31
  this.options = options || {};
40
32
  }
41
-
42
33
  getName() {
43
34
  return this.options.name;
44
35
  }
45
-
46
36
  afterAdd() {}
47
-
48
37
  beforeLoad() {}
49
-
50
38
  load() {
51
39
  return _asyncToGenerator(function* () {})();
52
40
  }
53
-
54
41
  install(options) {
55
42
  return _asyncToGenerator(function* () {})();
56
43
  }
57
-
44
+ beforeEnable() {
45
+ return _asyncToGenerator(function* () {})();
46
+ }
58
47
  afterEnable() {
59
48
  return _asyncToGenerator(function* () {})();
60
49
  }
61
-
62
50
  afterDisable() {
63
51
  return _asyncToGenerator(function* () {})();
64
52
  }
65
-
66
53
  remove() {
67
54
  return _asyncToGenerator(function* () {})();
68
55
  }
69
-
70
56
  importCollections(collectionsPath) {
71
57
  var _this = this;
72
-
73
58
  return _asyncToGenerator(function* () {
74
59
  yield _this.db.import({
75
60
  directory: collectionsPath,
@@ -77,9 +62,10 @@ class Plugin {
77
62
  });
78
63
  })();
79
64
  }
80
-
65
+ requiredPlugins() {
66
+ return [];
67
+ }
81
68
  }
82
-
83
69
  exports.Plugin = Plugin;
84
70
  var _default = Plugin;
85
71
  exports.default = _default;
@@ -6,61 +6,40 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.ConfigurationRepository = void 0;
7
7
  exports.loadConfiguration = loadConfiguration;
8
8
  exports.readConfig = readConfig;
9
-
10
9
  function _lodash() {
11
10
  const data = _interopRequireDefault(require("lodash"));
12
-
13
11
  _lodash = function _lodash() {
14
12
  return data;
15
13
  };
16
-
17
14
  return data;
18
15
  }
19
-
20
16
  function _fs() {
21
17
  const data = _interopRequireDefault(require("fs"));
22
-
23
18
  _fs = function _fs() {
24
19
  return data;
25
20
  };
26
-
27
21
  return data;
28
22
  }
29
-
30
23
  function _path() {
31
24
  const data = _interopRequireDefault(require("path"));
32
-
33
25
  _path = function _path() {
34
26
  return data;
35
27
  };
36
-
37
28
  return data;
38
29
  }
39
-
40
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
41
-
42
31
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
43
-
44
32
  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."); }
45
-
46
- 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; }
47
-
33
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
48
34
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
49
-
50
35
  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; } } }; }
51
-
52
36
  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); }
53
-
54
37
  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; }
55
-
56
38
  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); } }
57
-
58
39
  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); }); }; }
59
-
60
40
  function readConfig(_x) {
61
41
  return _readConfig.apply(this, arguments);
62
42
  }
63
-
64
43
  function _readConfig() {
65
44
  _readConfig = _asyncToGenerator(function* (dir) {
66
45
  const repository = new ConfigurationRepository();
@@ -69,36 +48,28 @@ function _readConfig() {
69
48
  });
70
49
  return _readConfig.apply(this, arguments);
71
50
  }
72
-
73
51
  class ConfigurationRepository {
74
52
  constructor() {
75
53
  this.items = new Map();
76
54
  }
77
-
78
55
  get(key, defaultValue = undefined) {
79
56
  if (this.items.has(key)) {
80
57
  return this.items.get(key);
81
58
  }
82
-
83
59
  return defaultValue;
84
60
  }
85
-
86
61
  set(key, value) {
87
62
  return this.items.set(key, value);
88
63
  }
89
-
90
64
  toObject() {
91
65
  const result = {};
92
-
93
66
  var _iterator = _createForOfIteratorHelper(this.items.entries()),
94
- _step;
95
-
67
+ _step;
96
68
  try {
97
69
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
98
70
  const _step$value = _slicedToArray(_step.value, 2),
99
- key = _step$value[0],
100
- value = _step$value[1];
101
-
71
+ key = _step$value[0],
72
+ value = _step$value[1];
102
73
  _lodash().default.set(result, key, value);
103
74
  }
104
75
  } catch (err) {
@@ -106,18 +77,13 @@ class ConfigurationRepository {
106
77
  } finally {
107
78
  _iterator.f();
108
79
  }
109
-
110
80
  return result;
111
81
  }
112
-
113
82
  }
114
-
115
83
  exports.ConfigurationRepository = ConfigurationRepository;
116
-
117
84
  function loadConfiguration(_x2, _x3) {
118
85
  return _loadConfiguration.apply(this, arguments);
119
86
  }
120
-
121
87
  function _loadConfiguration() {
122
88
  _loadConfiguration = _asyncToGenerator(function* (configurationDir, repository) {
123
89
  const getConfigurationFiles = /*#__PURE__*/function () {
@@ -125,27 +91,20 @@ function _loadConfiguration() {
125
91
  const files = yield _fs().default.promises.readdir(dir, {
126
92
  withFileTypes: true
127
93
  });
128
-
129
94
  var _iterator2 = _createForOfIteratorHelper(files),
130
- _step2;
131
-
95
+ _step2;
132
96
  try {
133
97
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
134
98
  const file = _step2.value;
135
-
136
99
  if (file.isDirectory()) {
137
100
  yield getConfigurationFiles(_path().default.join(dir, file.name), [...prefix, file.name]);
138
101
  } else {
139
102
  if (!['ts', 'js'].includes(file.name.split('.').slice(1).join('.'))) {
140
103
  continue;
141
104
  }
142
-
143
105
  const filePath = _path().default.join(dir, file.name);
144
-
145
106
  const keyName = _path().default.parse(filePath).name;
146
-
147
107
  const configuration = require(filePath).default;
148
-
149
108
  repository.set([...prefix, keyName].join('.'), configuration);
150
109
  }
151
110
  }
@@ -155,12 +114,10 @@ function _loadConfiguration() {
155
114
  _iterator2.f();
156
115
  }
157
116
  });
158
-
159
117
  return function getConfigurationFiles(_x4) {
160
118
  return _ref.apply(this, arguments);
161
119
  };
162
120
  }();
163
-
164
121
  yield getConfigurationFiles(configurationDir);
165
122
  });
166
123
  return _loadConfiguration.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "0.9.1-alpha.2",
3
+ "version": "0.9.2-alpha.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -8,11 +8,12 @@
8
8
  "@hapi/topo": "^6.0.0",
9
9
  "@koa/cors": "^3.1.0",
10
10
  "@koa/router": "^9.4.0",
11
- "@nocobase/acl": "0.9.1-alpha.2",
12
- "@nocobase/actions": "0.9.1-alpha.2",
13
- "@nocobase/database": "0.9.1-alpha.2",
14
- "@nocobase/logger": "0.9.1-alpha.2",
15
- "@nocobase/resourcer": "0.9.1-alpha.2",
11
+ "@nocobase/acl": "0.9.2-alpha.1",
12
+ "@nocobase/actions": "0.9.2-alpha.1",
13
+ "@nocobase/database": "0.9.2-alpha.1",
14
+ "@nocobase/logger": "0.9.2-alpha.1",
15
+ "@nocobase/resourcer": "0.9.2-alpha.1",
16
+ "@nocobase/utils": "0.9.2-alpha.1",
16
17
  "chalk": "^4.1.1",
17
18
  "commander": "^9.2.0",
18
19
  "find-package-json": "^1.2.0",
@@ -21,11 +22,12 @@
21
22
  "koa-bodyparser": "^4.3.0",
22
23
  "koa-static": "^5.0.0",
23
24
  "lodash": "^4.17.21",
25
+ "moment": "^2.29.1",
24
26
  "semver": "^7.3.7",
25
27
  "xpipe": "^1.0.5"
26
28
  },
27
29
  "devDependencies": {
28
30
  "@types/semver": "^7.3.9"
29
31
  },
30
- "gitHead": "d588a68eca4feed4642a4cb317301011266fe5c9"
32
+ "gitHead": "a4f103eb0144f07205aff7b2a6be8ea6aa1330df"
31
33
  }