@nocobase/server 0.9.1-alpha.1 → 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 (40) 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.d.ts +1 -0
  5. package/lib/application.js +35 -170
  6. package/lib/commands/console.js +0 -7
  7. package/lib/commands/db-auth.js +0 -5
  8. package/lib/commands/db-clean.js +0 -5
  9. package/lib/commands/db-sync.js +0 -4
  10. package/lib/commands/index.js +2 -12
  11. package/lib/commands/install.js +0 -14
  12. package/lib/commands/migrator.js +0 -5
  13. package/lib/commands/pm.js +3 -10
  14. package/lib/commands/start.js +0 -5
  15. package/lib/commands/upgrade.js +0 -8
  16. package/lib/helper.js +13 -36
  17. package/lib/index.js +0 -15
  18. package/lib/middlewares/data-template.d.ts +2 -0
  19. package/lib/middlewares/data-template.js +147 -0
  20. package/lib/middlewares/data-wrapping.js +4 -26
  21. package/lib/middlewares/db2resource.js +7 -25
  22. package/lib/middlewares/i18n.js +0 -8
  23. package/lib/middlewares/index.d.ts +1 -0
  24. package/lib/middlewares/index.js +13 -5
  25. package/lib/middlewares/parse-variables.d.ts +1 -0
  26. package/lib/middlewares/parse-variables.js +79 -0
  27. package/lib/migration.js +0 -7
  28. package/lib/plugin-manager/index.d.ts +1 -1
  29. package/lib/plugin-manager/index.js +4 -6
  30. package/lib/plugin-manager/options/collection.d.ts +1 -15
  31. package/lib/plugin-manager/options/collection.js +10 -3
  32. package/lib/plugin-manager/options/resource.js +0 -16
  33. package/lib/plugin-manager/{PluginManagerRepository.d.ts → plugin-manager-repository.d.ts} +1 -1
  34. package/lib/plugin-manager/{PluginManagerRepository.js → plugin-manager-repository.js} +49 -32
  35. package/lib/plugin-manager/{PluginManager.d.ts → plugin-manager.d.ts} +3 -2
  36. package/lib/plugin-manager/{PluginManager.js → plugin-manager.js} +140 -242
  37. package/lib/plugin.d.ts +2 -0
  38. package/lib/plugin.js +6 -20
  39. package/lib/read-config.js +5 -48
  40. package/package.json +9 -7
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = 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
  var _default = app => {
13
10
  app.command('db:auth').option('-r, --retry [retry]').action( /*#__PURE__*/function () {
14
11
  var _ref = _asyncToGenerator(function* (opts) {
@@ -16,11 +13,9 @@ var _default = app => {
16
13
  retry: opts.retry || 10
17
14
  });
18
15
  });
19
-
20
16
  return function (_x) {
21
17
  return _ref.apply(this, arguments);
22
18
  };
23
19
  }());
24
20
  };
25
-
26
21
  exports.default = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = 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
  var _default = app => {
13
10
  app.command('db:clean').option('-y, --yes').action( /*#__PURE__*/function () {
14
11
  var _ref = _asyncToGenerator(function* (opts) {
@@ -17,11 +14,9 @@ var _default = app => {
17
14
  drop: opts.yes
18
15
  });
19
16
  });
20
-
21
17
  return function (_x) {
22
18
  return _ref.apply(this, arguments);
23
19
  };
24
20
  }());
25
21
  };
26
-
27
22
  exports.default = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = 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
  var _default = app => {
13
10
  app.command('db:sync').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
14
11
  const opts = cliArgs[0];
@@ -25,5 +22,4 @@ var _default = app => {
25
22
  });
26
23
  }));
27
24
  };
28
-
29
25
  exports.default = _default;
@@ -4,27 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.registerCli = registerCli;
7
-
8
7
  function registerCli(app) {
9
8
  require('./console').default(app);
10
-
11
9
  require('./db-auth').default(app);
12
-
13
10
  require('./db-clean').default(app);
14
-
15
11
  require('./db-sync').default(app);
16
-
17
12
  require('./install').default(app);
18
-
19
13
  require('./migrator').default(app);
20
-
21
14
  require('./start').default(app);
22
-
23
15
  require('./upgrade').default(app);
24
-
25
- require('./pm').default(app); // development only with @nocobase/cli
26
-
27
-
16
+ require('./pm').default(app);
17
+ // development only with @nocobase/cli
28
18
  app.command('build').argument('[packages...]');
29
19
  app.command('clean');
30
20
  app.command('dev').usage('[options]').option('-p, --port [port]').option('--client').option('--server');
@@ -4,39 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _chalk() {
9
8
  const data = _interopRequireDefault(require("chalk"));
10
-
11
9
  _chalk = function _chalk() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
15
  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
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); }); }; }
23
-
24
17
  var _default = app => {
25
18
  app.command('install').option('-f, --force').option('-c, --clean').option('-s, --silent').option('-r, --retry [retry]').option('-I, --ignore-installed').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
26
19
  let installed = false;
27
20
  const opts = cliArgs[0];
28
-
29
21
  if (opts.ignoreInstalled) {
30
22
  if (yield app.isInstalled()) {
31
23
  console.log('Application installed');
32
24
  return;
33
25
  }
34
26
  }
35
-
36
27
  if (!(opts === null || opts === void 0 ? void 0 : opts.clean) && !(opts === null || opts === void 0 ? void 0 : opts.force)) {
37
28
  if (yield app.isInstalled()) {
38
29
  installed = true;
39
-
40
30
  if (!opts.silent) {
41
31
  console.log('NocoBase is already installed. To reinstall, please execute:');
42
32
  console.log();
@@ -46,15 +36,12 @@ var _default = app => {
46
36
  console.log(_chalk().default.red('This operation will clear the database!!!'));
47
37
  console.log();
48
38
  }
49
-
50
39
  return;
51
40
  }
52
41
  }
53
-
54
42
  if (!opts.silent || !installed) {
55
43
  console.log(`Start installing NocoBase`);
56
44
  }
57
-
58
45
  yield app.install({
59
46
  cliArgs,
60
47
  clean: opts.clean,
@@ -67,5 +54,4 @@ var _default = app => {
67
54
  });
68
55
  }));
69
56
  };
70
-
71
57
  exports.default = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = 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
  var _default = app => {
13
10
  app.command('migrator').action( /*#__PURE__*/function () {
14
11
  var _ref = _asyncToGenerator(function* (opts) {
@@ -17,11 +14,9 @@ var _default = app => {
17
14
  yield app.db.migrator.runAsCLI(process.argv.slice(3));
18
15
  yield app.stop();
19
16
  });
20
-
21
17
  return function (_x) {
22
18
  return _ref.apply(this, arguments);
23
19
  };
24
20
  }());
25
21
  };
26
-
27
22
  exports.default = _default;
@@ -4,32 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = 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
  var _default = app => {
13
- app.command('pm').argument('<method>').arguments('<plugins...>').action( /*#__PURE__*/function () {
10
+ app.command('pm').argument('<method>').arguments('<plugins...>').option('-S, --skip-yarn-install', 'skip yarn install').action( /*#__PURE__*/function () {
14
11
  var _ref = _asyncToGenerator(function* (method, plugins, options, ...args) {
15
- if (method === 'add') {
12
+ if (method === 'add' && !options.skipYarnInstall) {
16
13
  const _require = require('@nocobase/cli/src/util'),
17
- run = _require.run;
18
-
14
+ run = _require.run;
19
15
  console.log('Install dependencies and rebuild workspaces');
20
16
  yield run('yarn', ['install']);
21
17
  }
22
-
23
18
  app.pm.clientWrite({
24
19
  method,
25
20
  plugins
26
21
  });
27
22
  });
28
-
29
23
  return function (_x, _x2, _x3) {
30
24
  return _ref.apply(this, arguments);
31
25
  };
32
26
  }());
33
27
  };
34
-
35
28
  exports.default = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = 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
  var _default = app => {
13
10
  app.command('start').option('-s, --silent').option('-p, --port [post]').option('-h, --host [host]').option('--db-sync').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
14
11
  const opts = cliArgs[0];
@@ -22,11 +19,9 @@ var _default = app => {
22
19
  host
23
20
  }
24
21
  });
25
-
26
22
  if (!opts.silent) {
27
23
  console.log(`🚀 NocoBase server running at: http://${host === '0.0.0.0' ? 'localhost' : host}:${port}/`);
28
24
  }
29
25
  }));
30
26
  };
31
-
32
27
  exports.default = _default;
@@ -4,23 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _chalk() {
9
8
  const data = _interopRequireDefault(require("chalk"));
10
-
11
9
  _chalk = function _chalk() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
15
  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
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); }); }; }
23
-
24
17
  /**
25
18
  * TODO
26
19
  */
@@ -35,5 +28,4 @@ var _default = app => {
35
28
  console.log(_chalk().default.green(`✨ NocoBase has been upgraded to v${app.getVersion()}`));
36
29
  }));
37
30
  };
38
-
39
31
  exports.default = _default;
package/lib/helper.js CHANGED
@@ -7,78 +7,56 @@ exports.createDatabase = createDatabase;
7
7
  exports.createI18n = createI18n;
8
8
  exports.createResourcer = createResourcer;
9
9
  exports.registerMiddlewares = registerMiddlewares;
10
-
11
10
  function _cors() {
12
11
  const data = _interopRequireDefault(require("@koa/cors"));
13
-
14
12
  _cors = function _cors() {
15
13
  return data;
16
14
  };
17
-
18
15
  return data;
19
16
  }
20
-
21
17
  function _database() {
22
18
  const data = _interopRequireDefault(require("@nocobase/database"));
23
-
24
19
  _database = function _database() {
25
20
  return data;
26
21
  };
27
-
28
22
  return data;
29
23
  }
30
-
31
24
  function _resourcer() {
32
25
  const data = _interopRequireDefault(require("@nocobase/resourcer"));
33
-
34
26
  _resourcer = function _resourcer() {
35
27
  return data;
36
28
  };
37
-
38
29
  return data;
39
30
  }
40
-
41
31
  function _i18next() {
42
32
  const data = _interopRequireDefault(require("i18next"));
43
-
44
33
  _i18next = function _i18next() {
45
34
  return data;
46
35
  };
47
-
48
36
  return data;
49
37
  }
50
-
51
38
  function _koaBodyparser() {
52
39
  const data = _interopRequireDefault(require("koa-bodyparser"));
53
-
54
40
  _koaBodyparser = function _koaBodyparser() {
55
41
  return data;
56
42
  };
57
-
58
43
  return data;
59
44
  }
60
-
45
+ var _middlewares = require("./middlewares");
46
+ var _dataTemplate = require("./middlewares/data-template");
61
47
  var _dataWrapping = require("./middlewares/data-wrapping");
62
-
63
48
  var _db2resource = require("./middlewares/db2resource");
64
-
65
49
  var _i18n = require("./middlewares/i18n");
66
-
67
50
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
68
-
69
51
  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); } }
70
-
71
52
  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); }); }; }
72
-
73
53
  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; }
74
-
75
54
  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; }
76
-
77
- 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; }
78
-
55
+ 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; }
56
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
57
+ 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); }
79
58
  function createI18n(options) {
80
59
  const instance = _i18next().default.createInstance();
81
-
82
60
  instance.init(_objectSpread({
83
61
  lng: 'en-US',
84
62
  resources: {},
@@ -87,7 +65,6 @@ function createI18n(options) {
87
65
  }, options.i18n));
88
66
  return instance;
89
67
  }
90
-
91
68
  function createDatabase(options) {
92
69
  if (options.database instanceof _database().default) {
93
70
  return options.database;
@@ -95,11 +72,9 @@ function createDatabase(options) {
95
72
  return new (_database().default)(options.database);
96
73
  }
97
74
  }
98
-
99
75
  function createResourcer(options) {
100
76
  return new (_resourcer().default)(_objectSpread({}, options.resourcer));
101
77
  }
102
-
103
78
  function registerMiddlewares(app, options) {
104
79
  app.use((0, _cors().default)(_objectSpread({
105
80
  exposeHeaders: ['content-disposition']
@@ -107,24 +82,20 @@ function registerMiddlewares(app, options) {
107
82
  tag: 'cors',
108
83
  after: 'bodyParser'
109
84
  });
110
-
111
85
  if (options.bodyParser !== false) {
112
86
  app.use((0, _koaBodyparser().default)(_objectSpread({}, options.bodyParser)), {
113
87
  tag: 'bodyParser',
114
88
  after: 'logger'
115
89
  });
116
90
  }
117
-
118
91
  app.use( /*#__PURE__*/function () {
119
92
  var _ref = _asyncToGenerator(function* (ctx, next) {
120
93
  ctx.getBearerToken = () => {
121
94
  const token = ctx.get('Authorization').replace(/^Bearer\s+/gi, '');
122
95
  return token || ctx.query.token;
123
96
  };
124
-
125
97
  yield next();
126
98
  });
127
-
128
99
  return function (_x, _x2) {
129
100
  return _ref.apply(this, arguments);
130
101
  };
@@ -133,14 +104,20 @@ function registerMiddlewares(app, options) {
133
104
  tag: 'i18n',
134
105
  after: 'cors'
135
106
  });
136
-
137
107
  if (options.dataWrapping !== false) {
138
108
  app.use((0, _dataWrapping.dataWrapping)(), {
139
109
  tag: 'dataWrapping',
140
110
  after: 'i18n'
141
111
  });
142
112
  }
143
-
113
+ app.resourcer.use(_middlewares.parseVariables, {
114
+ tag: 'parseVariables',
115
+ after: 'acl'
116
+ });
117
+ app.resourcer.use(_dataTemplate.dateTemplate, {
118
+ tag: 'dateTemplate',
119
+ after: 'acl'
120
+ });
144
121
  app.use(_db2resource.db2resource, {
145
122
  tag: 'db2resource',
146
123
  after: 'dataWrapping'
package/lib/index.js CHANGED
@@ -20,11 +20,8 @@ Object.defineProperty(exports, "default", {
20
20
  }
21
21
  });
22
22
  exports.middlewares = void 0;
23
-
24
23
  var _appManager = require("./app-manager");
25
-
26
24
  var _application = require("./application");
27
-
28
25
  Object.keys(_application).forEach(function (key) {
29
26
  if (key === "default" || key === "__esModule") return;
30
27
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -36,13 +33,9 @@ Object.keys(_application).forEach(function (key) {
36
33
  }
37
34
  });
38
35
  });
39
-
40
36
  var _middlewares = _interopRequireWildcard(require("./middlewares"));
41
-
42
37
  exports.middlewares = _middlewares;
43
-
44
38
  var _migration = require("./migration");
45
-
46
39
  Object.keys(_migration).forEach(function (key) {
47
40
  if (key === "default" || key === "__esModule") return;
48
41
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -54,9 +47,7 @@ Object.keys(_migration).forEach(function (key) {
54
47
  }
55
48
  });
56
49
  });
57
-
58
50
  var _plugin = require("./plugin");
59
-
60
51
  Object.keys(_plugin).forEach(function (key) {
61
52
  if (key === "default" || key === "__esModule") return;
62
53
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -68,9 +59,7 @@ Object.keys(_plugin).forEach(function (key) {
68
59
  }
69
60
  });
70
61
  });
71
-
72
62
  var _pluginManager = require("./plugin-manager");
73
-
74
63
  Object.keys(_pluginManager).forEach(function (key) {
75
64
  if (key === "default" || key === "__esModule") return;
76
65
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -82,9 +71,7 @@ Object.keys(_pluginManager).forEach(function (key) {
82
71
  }
83
72
  });
84
73
  });
85
-
86
74
  var _readConfig = require("./read-config");
87
-
88
75
  Object.keys(_readConfig).forEach(function (key) {
89
76
  if (key === "default" || key === "__esModule") return;
90
77
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -96,7 +83,5 @@ Object.keys(_readConfig).forEach(function (key) {
96
83
  }
97
84
  });
98
85
  });
99
-
100
86
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
101
-
102
87
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -0,0 +1,2 @@
1
+ import { Context } from '@nocobase/actions';
2
+ export declare const dateTemplate: (ctx: Context, next: any) => Promise<void>;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.dateTemplate = void 0;
7
+ 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; } } }; }
8
+ 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); }
9
+ 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; }
10
+ 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); } }
11
+ 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); }); }; }
12
+ const dateTemplate = /*#__PURE__*/function () {
13
+ var _ref = _asyncToGenerator(function* (ctx, next) {
14
+ const _ctx$action = ctx.action,
15
+ resourceName = _ctx$action.resourceName,
16
+ actionName = _ctx$action.actionName;
17
+ const _ctx$action$params = ctx.action.params,
18
+ isTemplate = _ctx$action$params.isTemplate,
19
+ fields = _ctx$action$params.fields;
20
+ yield next();
21
+ if (isTemplate && actionName === 'get' && fields.length > 0) {
22
+ var _ctx$body;
23
+ ctx.body = traverseJSON((_ctx$body = ctx.body) === null || _ctx$body === void 0 ? void 0 : _ctx$body.toJSON(), {
24
+ collection: ctx.db.getCollection(resourceName),
25
+ include: fields
26
+ });
27
+ }
28
+ });
29
+ return function dateTemplate(_x, _x2) {
30
+ return _ref.apply(this, arguments);
31
+ };
32
+ }();
33
+ exports.dateTemplate = dateTemplate;
34
+ const traverseHasMany = (arr, {
35
+ collection,
36
+ exclude = [],
37
+ include = []
38
+ }) => {
39
+ if (!arr) {
40
+ return arr;
41
+ }
42
+ return arr.map(item => traverseJSON(item, {
43
+ collection,
44
+ exclude,
45
+ include
46
+ }));
47
+ };
48
+ const traverseBelongsToMany = (arr, {
49
+ collection,
50
+ exclude = [],
51
+ through
52
+ }) => {
53
+ if (!arr) {
54
+ return arr;
55
+ }
56
+ const throughCollection = collection.db.getCollection(through);
57
+ return arr.map(item => {
58
+ const data = traverseJSON(item[through], {
59
+ collection: throughCollection,
60
+ exclude
61
+ });
62
+ if (Object.keys(data).length) {
63
+ item[through] = data;
64
+ } else {
65
+ delete item[through];
66
+ }
67
+ return item;
68
+ });
69
+ };
70
+ const parseInclude = keys => {
71
+ const map = {};
72
+ var _iterator = _createForOfIteratorHelper(keys),
73
+ _step;
74
+ try {
75
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
76
+ const key = _step.value;
77
+ const args = key.split('.');
78
+ const field = args.shift();
79
+ map[field] = map[field] || [];
80
+ if (args.length) {
81
+ map[field].push(args.join('.'));
82
+ }
83
+ }
84
+ } catch (err) {
85
+ _iterator.e(err);
86
+ } finally {
87
+ _iterator.f();
88
+ }
89
+ return map;
90
+ };
91
+ const traverseJSON = (data, options) => {
92
+ const collection = options.collection,
93
+ _options$exclude = options.exclude,
94
+ exclude = _options$exclude === void 0 ? [] : _options$exclude,
95
+ _options$include = options.include,
96
+ include = _options$include === void 0 ? [] : _options$include;
97
+ const map = parseInclude(include);
98
+ const result = {};
99
+ for (var _i = 0, _Object$keys = Object.keys(data); _i < _Object$keys.length; _i++) {
100
+ const key = _Object$keys[_i];
101
+ const subInclude = map[key];
102
+ if (include.length > 0 && !subInclude) {
103
+ continue;
104
+ }
105
+ if (exclude.includes(key)) {
106
+ continue;
107
+ }
108
+ if (['createdAt', 'updatedAt', 'createdBy', 'createdById', 'updatedById', 'updatedBy'].includes(key)) {
109
+ continue;
110
+ }
111
+ const field = collection.getField(key);
112
+ if (!field) {
113
+ result[key] = data[key];
114
+ continue;
115
+ }
116
+ if (field.options.primaryKey) {
117
+ continue;
118
+ }
119
+ if (['sort', 'password', 'sequence'].includes(field.type)) {
120
+ continue;
121
+ }
122
+ if (field.type === 'hasOne') {
123
+ result[key] = traverseJSON(data[key], {
124
+ collection: collection.db.getCollection(field.target),
125
+ exclude: [field.foreignKey],
126
+ include: subInclude
127
+ });
128
+ } else if (field.type === 'hasMany') {
129
+ result[key] = traverseHasMany(data[key], {
130
+ collection: collection.db.getCollection(field.target),
131
+ exclude: [field.foreignKey],
132
+ include: subInclude
133
+ });
134
+ } else if (field.type === 'belongsTo') {
135
+ result[key] = data[key];
136
+ } else if (field.type === 'belongsToMany') {
137
+ result[key] = traverseBelongsToMany(data[key], {
138
+ collection: collection.db.getCollection(field.target),
139
+ exclude: [field.foreignKey, field.otherKey],
140
+ through: field.through
141
+ });
142
+ } else {
143
+ result[key] = data[key];
144
+ }
145
+ }
146
+ return result;
147
+ };