@nocobase/server 0.5.0-alpha.38 → 0.7.0-alpha.0

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 (134) hide show
  1. package/LICENSE +201 -21
  2. package/esm/acl/available-action.d.ts +5 -0
  3. package/esm/acl/available-action.js +36 -0
  4. package/esm/acl/available-action.js.map +1 -0
  5. package/esm/acl/index.d.ts +2 -0
  6. package/esm/acl/index.js +19 -0
  7. package/esm/acl/index.js.map +1 -0
  8. package/esm/app-manager.d.ts +19 -0
  9. package/esm/app-manager.js +69 -0
  10. package/esm/app-manager.js.map +1 -0
  11. package/esm/application.d.ts +97 -0
  12. package/esm/application.js +156 -0
  13. package/esm/application.js.map +1 -0
  14. package/esm/commands/console.d.ts +4 -0
  15. package/esm/commands/console.js +25 -0
  16. package/esm/commands/console.js.map +1 -0
  17. package/esm/commands/create-plugin/create-plugin.d.ts +2 -0
  18. package/esm/commands/create-plugin/create-plugin.js +29 -0
  19. package/esm/commands/create-plugin/create-plugin.js.map +1 -0
  20. package/esm/commands/create-plugin/index.d.ts +5 -0
  21. package/esm/commands/create-plugin/index.js +6 -0
  22. package/esm/commands/create-plugin/index.js.map +1 -0
  23. package/esm/commands/create-plugin/resources/templates/package-json.d.ts +11 -0
  24. package/esm/commands/create-plugin/resources/templates/package-json.js +11 -0
  25. package/esm/commands/create-plugin/resources/templates/package-json.js.map +1 -0
  26. package/esm/commands/create-plugin/resources/templates/plugin.d.ts +4 -0
  27. package/esm/commands/create-plugin/resources/templates/plugin.js +12 -0
  28. package/esm/commands/create-plugin/resources/templates/plugin.js.map +1 -0
  29. package/esm/commands/db-sync.d.ts +5 -0
  30. package/esm/commands/db-sync.js +25 -0
  31. package/esm/commands/db-sync.js.map +1 -0
  32. package/esm/commands/index.d.ts +3 -0
  33. package/esm/commands/index.js +26 -0
  34. package/esm/commands/index.js.map +1 -0
  35. package/esm/commands/install.d.ts +5 -0
  36. package/esm/commands/install.js +23 -0
  37. package/esm/commands/install.js.map +1 -0
  38. package/esm/commands/start.d.ts +5 -0
  39. package/esm/commands/start.js +23 -0
  40. package/esm/commands/start.js.map +1 -0
  41. package/esm/helper.d.ts +7 -0
  42. package/esm/helper.js +59 -0
  43. package/esm/helper.js.map +1 -0
  44. package/esm/index.d.ts +7 -0
  45. package/esm/index.js +9 -0
  46. package/esm/index.js.map +1 -0
  47. package/esm/middlewares/data-wrapping.d.ts +3 -0
  48. package/esm/middlewares/data-wrapping.js +54 -0
  49. package/esm/middlewares/data-wrapping.js.map +1 -0
  50. package/esm/middlewares/index.d.ts +2 -0
  51. package/esm/middlewares/index.js +3 -0
  52. package/esm/middlewares/index.js.map +1 -0
  53. package/esm/middlewares/table2resource.d.ts +6 -0
  54. package/esm/middlewares/table2resource.js +51 -0
  55. package/esm/middlewares/table2resource.js.map +1 -0
  56. package/esm/plugin-manager.d.ts +23 -0
  57. package/esm/plugin-manager.js +57 -0
  58. package/esm/plugin-manager.js.map +1 -0
  59. package/esm/plugin.d.ts +32 -0
  60. package/esm/plugin.js +43 -0
  61. package/esm/plugin.js.map +1 -0
  62. package/esm/read-config.d.ts +8 -0
  63. package/esm/read-config.js +63 -0
  64. package/esm/read-config.js.map +1 -0
  65. package/lib/acl/available-action.d.ts +5 -0
  66. package/lib/acl/available-action.js +39 -0
  67. package/lib/acl/available-action.js.map +1 -0
  68. package/lib/acl/index.d.ts +2 -0
  69. package/lib/acl/index.js +23 -0
  70. package/lib/acl/index.js.map +1 -0
  71. package/lib/app-manager.d.ts +19 -0
  72. package/lib/app-manager.js +76 -0
  73. package/lib/app-manager.js.map +1 -0
  74. package/lib/application.d.ts +51 -12
  75. package/lib/application.js +147 -245
  76. package/lib/application.js.map +1 -1
  77. package/lib/commands/console.d.ts +4 -0
  78. package/lib/commands/console.js +27 -0
  79. package/lib/commands/console.js.map +1 -0
  80. package/lib/commands/create-plugin/create-plugin.d.ts +2 -0
  81. package/lib/commands/create-plugin/create-plugin.js +31 -0
  82. package/lib/commands/create-plugin/create-plugin.js.map +1 -0
  83. package/lib/commands/create-plugin/index.d.ts +5 -0
  84. package/lib/commands/create-plugin/index.js +8 -0
  85. package/lib/commands/create-plugin/index.js.map +1 -0
  86. package/lib/commands/create-plugin/resources/templates/package-json.d.ts +11 -0
  87. package/lib/commands/create-plugin/resources/templates/package-json.js +13 -0
  88. package/lib/commands/create-plugin/resources/templates/package-json.js.map +1 -0
  89. package/lib/commands/create-plugin/resources/templates/plugin.d.ts +4 -0
  90. package/lib/commands/create-plugin/resources/templates/plugin.js +33 -0
  91. package/lib/commands/create-plugin/resources/templates/plugin.js.map +1 -0
  92. package/lib/commands/db-sync.d.ts +5 -0
  93. package/lib/commands/db-sync.js +27 -0
  94. package/lib/commands/db-sync.js.map +1 -0
  95. package/lib/commands/index.d.ts +3 -0
  96. package/lib/commands/index.js +30 -0
  97. package/lib/commands/index.js.map +1 -0
  98. package/lib/commands/install.d.ts +5 -0
  99. package/lib/commands/install.js +25 -0
  100. package/lib/commands/install.js.map +1 -0
  101. package/lib/commands/start.d.ts +5 -0
  102. package/lib/commands/start.js +25 -0
  103. package/lib/commands/start.js.map +1 -0
  104. package/lib/helper.d.ts +1 -3
  105. package/lib/helper.js +50 -185
  106. package/lib/helper.js.map +1 -1
  107. package/lib/index.d.ts +4 -1
  108. package/lib/index.js +28 -63
  109. package/lib/index.js.map +1 -1
  110. package/lib/middlewares/data-wrapping.js +49 -97
  111. package/lib/middlewares/data-wrapping.js.map +1 -1
  112. package/lib/middlewares/index.js +11 -35
  113. package/lib/middlewares/index.js.map +1 -1
  114. package/lib/middlewares/table2resource.d.ts +4 -1
  115. package/lib/middlewares/table2resource.js +45 -129
  116. package/lib/middlewares/table2resource.js.map +1 -1
  117. package/lib/plugin-manager.d.ts +23 -0
  118. package/lib/plugin-manager.js +61 -0
  119. package/lib/plugin-manager.js.map +1 -0
  120. package/lib/plugin.d.ts +17 -16
  121. package/lib/plugin.js +42 -99
  122. package/lib/plugin.js.map +1 -1
  123. package/lib/read-config.d.ts +8 -0
  124. package/lib/read-config.js +72 -0
  125. package/lib/read-config.js.map +1 -0
  126. package/package.json +22 -9
  127. package/tsconfig.build.json +9 -0
  128. package/lib/application.d.ts.map +0 -1
  129. package/lib/helper.d.ts.map +0 -1
  130. package/lib/index.d.ts.map +0 -1
  131. package/lib/middlewares/data-wrapping.d.ts.map +0 -1
  132. package/lib/middlewares/index.d.ts.map +0 -1
  133. package/lib/middlewares/table2resource.d.ts.map +0 -1
  134. package/lib/plugin.d.ts.map +0 -1
@@ -0,0 +1,27 @@
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.default = ({ app, cliArgs }) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const [opts] = cliArgs;
14
+ console.log('db sync...');
15
+ yield app.db.sync(opts.force
16
+ ? {
17
+ force: true,
18
+ alter: {
19
+ drop: true,
20
+ },
21
+ }
22
+ : {});
23
+ yield app.stop({
24
+ cliArgs,
25
+ });
26
+ });
27
+ //# sourceMappingURL=db-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-sync.js","sourceRoot":"","sources":["../../src/commands/db-sync.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kBAAe,CAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACvB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1B,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CACf,IAAI,CAAC,KAAK;QACR,CAAC,CAAC;YACE,KAAK,EAAE,IAAI;YACX,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI;aACX;SACF;QACH,CAAC,CAAC,EAAE,CACP,CAAC;IACF,MAAM,GAAG,CAAC,IAAI,CAAC;QACb,OAAO;KACR,CAAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["export default async ({ app, cliArgs }) => {\n const [opts] = cliArgs;\n console.log('db sync...');\n await app.db.sync(\n opts.force\n ? {\n force: true,\n alter: {\n drop: true,\n },\n }\n : {},\n );\n await app.stop({\n cliArgs,\n });\n};\n"]}
@@ -0,0 +1,3 @@
1
+ import Application from '../application';
2
+ import { Command } from 'commander';
3
+ export declare function createCli(app: Application): Command;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCli = void 0;
4
+ const commander_1 = require("commander");
5
+ function createCli(app) {
6
+ const program = new commander_1.Command();
7
+ const runSubCommand = (name) => (...cliArgs) => {
8
+ const command = require(`./${name}`).default;
9
+ Promise.resolve()
10
+ .then(() => {
11
+ return command({ app, cliArgs });
12
+ })
13
+ .catch((error) => {
14
+ console.error(error);
15
+ process.exit(1);
16
+ });
17
+ };
18
+ program.command('start').description('start NocoBase application').action(runSubCommand('start'));
19
+ program.command('install').option('-f, --force').option('-c, --clean').action(runSubCommand('install'));
20
+ program.command('db:sync').option('-f, --force').action(runSubCommand('db-sync'));
21
+ program.command('console').action(runSubCommand('console'));
22
+ program
23
+ .command('create-plugin')
24
+ .argument('<name>', 'name of plugin')
25
+ .description('create NocoBase plugin')
26
+ .action(runSubCommand('create-plugin'));
27
+ return program;
28
+ }
29
+ exports.createCli = createCli;
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],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AAM,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC;IAE1C,OAAO,OAAO,CAAC;AACjB,CAAC;AA9BD,8BA8BC","sourcesContent":["import Application from '../application';\nimport { Command } from 'commander';\n\nexport function createCli(app: Application) {\n const program = new Command();\n\n const runSubCommand =\n (name) =>\n (...cliArgs) => {\n const command = require(`./${name}`).default;\n\n Promise.resolve()\n .then(() => {\n return command({ app, cliArgs });\n })\n .catch((error) => {\n console.error(error);\n process.exit(1);\n });\n };\n\n program.command('start').description('start NocoBase application').action(runSubCommand('start'));\n program.command('install').option('-f, --force').option('-c, --clean').action(runSubCommand('install'));\n program.command('db:sync').option('-f, --force').action(runSubCommand('db-sync'));\n program.command('console').action(runSubCommand('console'));\n\n program\n .command('create-plugin')\n .argument('<name>', 'name of plugin')\n .description('create NocoBase plugin')\n .action(runSubCommand('create-plugin'));\n\n return program;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ declare const _default: ({ app, cliArgs }: {
2
+ app: any;
3
+ cliArgs: any;
4
+ }) => Promise<void>;
5
+ export default _default;
@@ -0,0 +1,25 @@
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.default = ({ app, cliArgs }) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const [opts] = cliArgs;
14
+ yield app.install({
15
+ cliArgs,
16
+ clean: opts.clean,
17
+ sync: {
18
+ force: opts.force,
19
+ },
20
+ });
21
+ yield app.stop({
22
+ cliArgs,
23
+ });
24
+ });
25
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/commands/install.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kBAAe,CAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACvB,MAAM,GAAG,CAAC,OAAO,CAAC;QAChB,OAAO;QACP,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,IAAI,EAAE;YACJ,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB;KACF,CAAC,CAAC;IACH,MAAM,GAAG,CAAC,IAAI,CAAC;QACb,OAAO;KACR,CAAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["export default async ({ app, cliArgs }) => {\n const [opts] = cliArgs;\n await app.install({\n cliArgs,\n clean: opts.clean,\n sync: {\n force: opts.force,\n },\n });\n await app.stop({\n cliArgs,\n });\n};\n"]}
@@ -0,0 +1,5 @@
1
+ declare const _default: ({ app, cliArgs }: {
2
+ app: any;
3
+ cliArgs: any;
4
+ }) => Promise<void>;
5
+ export default _default;
@@ -0,0 +1,25 @@
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.default = ({ app, cliArgs }) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const [opts] = cliArgs;
14
+ const port = opts.port || process.env.SERVER_PORT || 3000;
15
+ const host = opts.host || process.env.SERVER_HOST || '0.0.0.0';
16
+ yield app.start({
17
+ cliArgs,
18
+ listen: {
19
+ port,
20
+ host,
21
+ },
22
+ });
23
+ console.log(`🚀 nocobase server had started at http://${host}:${port}`);
24
+ });
25
+ //# sourceMappingURL=start.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kBAAe,CAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,IAAI,CAAC;IAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,SAAS,CAAC;IAE/D,MAAM,GAAG,CAAC,KAAK,CAAC;QACd,OAAO;QACP,MAAM,EAAE;YACN,IAAI;YACJ,IAAI;SACL;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,4CAA4C,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAA,CAAC","sourcesContent":["export default async ({ app, cliArgs }) => {\n const [opts] = cliArgs;\n const port = opts.port || process.env.SERVER_PORT || 3000;\n const host = opts.host || process.env.SERVER_HOST || '0.0.0.0';\n\n await app.start({\n cliArgs,\n listen: {\n port,\n host,\n },\n });\n\n console.log(`🚀 nocobase server had started at http://${host}:${port}`);\n};\n"]}
package/lib/helper.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import Database from '@nocobase/database';
2
2
  import Resourcer from '@nocobase/resourcer';
3
- import { Command } from 'commander';
4
3
  import Application, { ApplicationOptions } from './application';
4
+ export declare function createI18n(options: ApplicationOptions): import("i18next").i18n;
5
5
  export declare function createDatabase(options: ApplicationOptions): Database;
6
6
  export declare function createResourcer(options: ApplicationOptions): Resourcer;
7
- export declare function createI18n(options: ApplicationOptions): import("i18next").i18n;
8
- export declare function createCli(app: Application, options: ApplicationOptions): Command;
9
7
  export declare function registerMiddlewares(app: Application, options: ApplicationOptions): void;
package/lib/helper.js CHANGED
@@ -1,204 +1,69 @@
1
1
  "use strict";
2
-
3
- function _react() {
4
- const data = _interopRequireDefault(require("react"));
5
-
6
- _react = function _react() {
7
- return data;
8
- };
9
-
10
- return data;
11
- }
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
16
-
17
- 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."); }
18
-
19
- 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); }
20
-
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; }
22
-
23
- 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; }
24
-
25
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
26
-
27
- var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
28
- function adopt(value) {
29
- return value instanceof P ? value : new P(function (resolve) {
30
- resolve(value);
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());
31
9
  });
32
- }
33
-
34
- return new (P || (P = Promise))(function (resolve, reject) {
35
- function fulfilled(value) {
36
- try {
37
- step(generator.next(value));
38
- } catch (e) {
39
- reject(e);
40
- }
41
- }
42
-
43
- function rejected(value) {
44
- try {
45
- step(generator["throw"](value));
46
- } catch (e) {
47
- reject(e);
48
- }
49
- }
50
-
51
- function step(result) {
52
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
53
- }
54
-
55
- step((generator = generator.apply(thisArg, _arguments || [])).next());
56
- });
57
10
  };
58
-
59
- var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
60
- return mod && mod.__esModule ? mod : {
61
- "default": mod
62
- };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
13
  };
64
-
65
- Object.defineProperty(exports, "__esModule", {
66
- value: true
67
- });
68
- exports.registerMiddlewares = exports.createCli = exports.createI18n = exports.createResourcer = exports.createDatabase = void 0;
69
-
70
- const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
71
-
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.registerMiddlewares = exports.createResourcer = exports.createDatabase = exports.createI18n = void 0;
72
16
  const cors_1 = __importDefault(require("@koa/cors"));
73
-
74
17
  const database_1 = __importDefault(require("@nocobase/database"));
75
-
76
18
  const resourcer_1 = __importDefault(require("@nocobase/resourcer"));
77
-
78
- const commander_1 = require("commander");
79
-
19
+ const i18next_1 = __importDefault(require("i18next"));
20
+ const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
80
21
  const data_wrapping_1 = require("./middlewares/data-wrapping");
81
-
82
22
  const table2resource_1 = require("./middlewares/table2resource");
83
-
84
- const i18next_1 = __importDefault(require("i18next"));
85
-
23
+ function createI18n(options) {
24
+ const instance = i18next_1.default.createInstance();
25
+ instance.init(Object.assign({ lng: 'en-US', resources: {} }, options.i18n));
26
+ return instance;
27
+ }
28
+ exports.createI18n = createI18n;
86
29
  function createDatabase(options) {
87
- if (options.database instanceof database_1.default) {
88
- return options.database;
89
- } else {
90
- return new database_1.default(options.database);
91
- }
30
+ if (options.database instanceof database_1.default) {
31
+ return options.database;
32
+ }
33
+ else {
34
+ return new database_1.default(options.database);
35
+ }
92
36
  }
93
-
94
37
  exports.createDatabase = createDatabase;
95
-
96
38
  function createResourcer(options) {
97
- return new resourcer_1.default(Object.assign({}, options.resourcer));
39
+ return new resourcer_1.default(Object.assign({}, options.resourcer));
98
40
  }
99
-
100
41
  exports.createResourcer = createResourcer;
101
-
102
- function createI18n(options) {
103
- const instance = i18next_1.default.createInstance();
104
- instance.init(Object.assign({
105
- lng: 'en-US',
106
- resources: {}
107
- }, options.i18n));
108
- return instance;
109
- }
110
-
111
- exports.createI18n = createI18n;
112
-
113
- function createCli(app, options) {
114
- const cli = new commander_1.Command();
115
- cli.command('db:sync').option('-f, --force').action((...args) => __awaiter(this, void 0, void 0, function* () {
116
- var _a;
117
-
118
- console.log('db sync...');
119
- const cli = args.pop();
120
- const force = (_a = cli.opts()) === null || _a === void 0 ? void 0 : _a.force;
121
- yield app.db.sync(force ? {
122
- force: true,
123
- alter: {
124
- drop: true
125
- }
126
- } : {});
127
- yield app.destroy();
128
- }));
129
- cli.command('init').option('-f, --force').action((opts, ...args) => __awaiter(this, void 0, void 0, function* () {
130
- if (!(opts === null || opts === void 0 ? void 0 : opts.force)) {
131
- const tables = yield app.db.sequelize.getQueryInterface().showAllTables();
132
-
133
- if (tables.includes('collections')) {
134
- console.log('NocoBase is already installed. To reinstall, please execute:');
135
- console.log();
136
- let command = 'yarn nocobase init --force';
137
-
138
- for (var _i = 0, _Object$entries = Object.entries(opts || {}); _i < _Object$entries.length; _i++) {
139
- const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
140
- key = _Object$entries$_i[0],
141
- value = _Object$entries$_i[1];
142
-
143
- command += value === true ? ` --${key}` : ` --${key}=${value}`;
144
- }
145
-
146
- console.log(command);
147
- console.log();
148
- return;
149
- }
150
- }
151
-
152
- yield app.db.sync({
153
- force: true
154
- });
155
- yield app.emitAsync('db.init', opts, ...args);
156
- yield app.destroy();
157
- }));
158
- cli.command('start').option('-p, --port [port]').action((...args) => __awaiter(this, void 0, void 0, function* () {
159
- const cli = args.pop();
160
- const opts = cli.opts();
161
- yield app.emitAsync('beforeStart');
162
- app.listen(opts.port || 3000);
163
- console.log(`http://localhost:${opts.port || 3000}/`);
164
- }));
165
- return cli;
166
- }
167
-
168
- exports.createCli = createCli;
169
-
170
42
  function registerMiddlewares(app, options) {
171
- if (options.bodyParser !== false) {
172
- app.use((0, koa_bodyparser_1.default)(Object.assign({}, options.bodyParser)));
173
- }
174
-
175
- app.use((0, cors_1.default)(Object.assign({
176
- exposeHeaders: ['content-disposition']
177
- }, options.cors)));
178
- app.use((ctx, next) => __awaiter(this, void 0, void 0, function* () {
179
- ctx.db = app.db;
180
- ctx.resourcer = app.resourcer;
181
- const i18n = app.i18n.cloneInstance({
182
- initImmediate: false
183
- });
184
- ctx.i18n = i18n;
185
- ctx.t = i18n.t.bind(i18n);
186
- const lng = ctx.request.query.locale || ctx.acceptsLanguages().shift();
187
-
188
- if (lng !== '*' && lng) {
189
- i18n.changeLanguage(lng);
43
+ if (options.bodyParser !== false) {
44
+ app.use((0, koa_bodyparser_1.default)(Object.assign({}, options.bodyParser)));
45
+ }
46
+ app.use((0, cors_1.default)(Object.assign({ exposeHeaders: ['content-disposition'] }, options.cors)));
47
+ app.use((ctx, next) => __awaiter(this, void 0, void 0, function* () {
48
+ ctx.getBearerToken = () => {
49
+ return ctx.get('Authorization').replace(/^Bearer\s+/gi, '');
50
+ };
51
+ ctx.db = app.db;
52
+ ctx.resourcer = app.resourcer;
53
+ const i18n = app.i18n.cloneInstance({ initImmediate: false });
54
+ ctx.i18n = i18n;
55
+ ctx.t = i18n.t.bind(i18n);
56
+ const lng = ctx.request.query.locale || ctx.acceptsLanguages().shift();
57
+ if (lng !== '*' && lng) {
58
+ i18n.changeLanguage(lng);
59
+ }
60
+ yield next();
61
+ }));
62
+ if (options.dataWrapping !== false) {
63
+ app.use((0, data_wrapping_1.dataWrapping)());
190
64
  }
191
-
192
- yield next();
193
- }));
194
-
195
- if (options.dataWrapping !== false) {
196
- app.use((0, data_wrapping_1.dataWrapping)());
197
- }
198
-
199
- app.use((0, table2resource_1.table2resource)());
200
- app.use(app.resourcer.restApiMiddleware());
65
+ app.use((0, table2resource_1.table2resource)());
66
+ app.use(app.resourcer.restApiMiddleware());
201
67
  }
202
-
203
68
  exports.registerMiddlewares = registerMiddlewares;
204
- //# sourceMappingURL=helper.js.map
69
+ //# sourceMappingURL=helper.js.map
package/lib/helper.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,oEAAwC;AACxC,qDAA6B;AAC7B,kEAA0C;AAC1C,oEAA4C;AAC5C,yCAAoC;AAEpC,+DAA2D;AAC3D,iEAA8D;AAC9D,sDAA8B;AAE9B,SAAgB,cAAc,CAAC,OAA2B;IACxD,IAAI,OAAO,CAAC,QAAQ,YAAY,kBAAQ,EAAE;QACxC,OAAO,OAAO,CAAC,QAAQ,C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AAE,CAAC;IACf,CAAC,CAAA,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,YAAY,KAAK,KAAK,EAAE;QAClC,GAAG,CAAC,GAAG,CAAC,IAAA,4BAAY,GAAE,CAAC,CAAC;KACzB;IAED,GAAG,CAAC,GAAG,CAAC,IAAA,+BAAc,GAAE,CAAC,CAAC;IAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,CAAC;AAC7C,CAAC;AAtCD,kDAsCC","file":"helper.js","sourcesContent":["import { DefaultContext, DefaultState } from 'koa';\nimport bodyParser from 'koa-bodyparser';\nimport cors from '@koa/cors';\nimport Database from '@nocobase/database';\nimport Resourcer from '@nocobase/resourcer';\nimport { Command } from 'commander';\nimport Application, { ApplicationOptions } from './application';\nimport { dataWrapping } from './middlewares/data-wrapping';\nimport { table2resource } from './middlewares/table2resource';\nimport i18next from 'i18next';\n\nexport function createDatabase(options: ApplicationOptions) {\n if (options.database instanceof Database) {\n return options.database;\n } else {\n return new Database(options.database);\n }\n}\n\nexport function createResourcer(options: ApplicationOptions) {\n return new Resourcer({ ...options.resourcer });\n}\n\nexport function createI18n(options: ApplicationOptions) {\n const instance = i18next.createInstance();\n instance.init({\n lng: 'en-US',\n resources: {},\n ...options.i18n,\n });\n return instance;\n}\n\nexport function createCli(app: Application, options: ApplicationOptions) {\n const cli = new Command();\n\n cli\n .command('db:sync')\n .option('-f, --force')\n .action(async (...args) => {\n console.log('db sync...');\n const cli = args.pop();\n const force = cli.opts()?.force;\n await app.db.sync(\n force\n ? {\n force: true,\n alter: {\n drop: true,\n },\n }\n : {},\n );\n await app.destroy();\n });\n\n cli\n .command('init')\n .option('-f, --force')\n .action(async (opts, ...args) => {\n if (!opts?.force) {\n const tables = await app.db.sequelize.getQueryInterface().showAllTables();\n if (tables.includes('collections')) {\n console.log('NocoBase is already installed. To reinstall, please execute:');\n console.log();\n let command = 'yarn nocobase init --force'\n for (const [key, value] of Object.entries(opts||{})) {\n command += value === true ? ` --${key}` : ` --${key}=${value}`;\n }\n console.log(command);\n console.log();\n return;\n }\n }\n await app.db.sync({\n force: true,\n });\n await app.emitAsync('db.init', opts, ...args);\n await app.destroy();\n });\n\n cli\n .command('start')\n .option('-p, --port [port]')\n .action(async (...args) => {\n const cli = args.pop();\n const opts = cli.opts();\n await app.emitAsync('beforeStart');\n app.listen(opts.port || 3000);\n console.log(`http://localhost:${opts.port || 3000}/`);\n });\n return cli;\n}\n\nexport function registerMiddlewares(\n app: Application,\n options: ApplicationOptions,\n) {\n if (options.bodyParser !== false) {\n app.use(\n bodyParser({\n ...options.bodyParser,\n }),\n );\n }\n\n app.use(\n cors({\n exposeHeaders: ['content-disposition'],\n ...options.cors,\n }),\n );\n\n app.use<DefaultState, DefaultContext>(async (ctx, next) => {\n ctx.db = app.db;\n ctx.resourcer = app.resourcer;\n const i18n = app.i18n.cloneInstance({ initImmediate: false })\n ctx.i18n = i18n;\n ctx.t = i18n.t.bind(i18n);\n const lng = ctx.request.query.locale as string || ctx.acceptsLanguages().shift();\n if (lng !== '*' && lng) {\n i18n.changeLanguage(lng);\n }\n await next();\n });\n\n if (options.dataWrapping !== false) {\n app.use(dataWrapping());\n }\n\n app.use(table2resource());\n app.use(app.resourcer.restApiMiddleware());\n}\n"]}
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qDAA6B;AAC7B,kEAA0C;AAC1C,oEAA4C;AAE5C,sDAA8B;AAE9B,oEAAwC;AAExC,+DAA2D;AAC3D,iEAA8D;AAE9D,SAAgB,UAAU,CAAC,OAA2B;IACpD,MAAM,QAAQ,GAAG,iBAAO,CAAC,cAAc,EAAE,CAAC;IAC1C,QAAQ,CAAC,IAAI,iBACX,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,EAAE,IACV,OAAO,CAAC,IAAI,EACf,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;A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GAAG,GAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,MAAiB,IAAI,GAAG,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,CAAC;QACnF,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,EAAE;YACtB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;SAC1B;QACD,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAA,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,YAAY,KAAK,KAAK,EAAE;QAClC,GAAG,CAAC,GAAG,CAAC,IAAA,4BAAY,GAAE,CAAC,CAAC;KACzB;IAED,GAAG,CAAC,GAAG,CAAC,IAAA,+BAAc,GAAE,CAAC,CAAC;IAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,CAAC;AAC7C,CAAC;AAtCD,kDAsCC","sourcesContent":["import cors from '@koa/cors';\nimport Database from '@nocobase/database';\nimport Resourcer from '@nocobase/resourcer';\nimport { Command } from 'commander';\nimport i18next from 'i18next';\nimport { DefaultContext, DefaultState } from 'koa';\nimport bodyParser from 'koa-bodyparser';\nimport Application, { ApplicationOptions } from './application';\nimport { dataWrapping } from './middlewares/data-wrapping';\nimport { table2resource } from './middlewares/table2resource';\n\nexport function createI18n(options: ApplicationOptions) {\n const instance = i18next.createInstance();\n instance.init({\n lng: 'en-US',\n resources: {},\n ...options.i18n,\n });\n return instance;\n}\n\nexport function createDatabase(options: ApplicationOptions) {\n if (options.database instanceof Database) {\n return options.database;\n } else {\n return new Database(options.database);\n }\n}\n\nexport function createResourcer(options: ApplicationOptions) {\n return new Resourcer({ ...options.resourcer });\n}\n\nexport function registerMiddlewares(app: Application, options: ApplicationOptions) {\n if (options.bodyParser !== false) {\n app.use(\n bodyParser({\n ...options.bodyParser,\n }),\n );\n }\n\n app.use(\n cors({\n exposeHeaders: ['content-disposition'],\n ...options.cors,\n }),\n );\n\n app.use<DefaultState, DefaultContext>(async (ctx, next) => {\n ctx.getBearerToken = () => {\n return ctx.get('Authorization').replace(/^Bearer\\s+/gi, '');\n };\n ctx.db = app.db;\n ctx.resourcer = app.resourcer;\n const i18n = app.i18n.cloneInstance({ initImmediate: false });\n ctx.i18n = i18n;\n ctx.t = i18n.t.bind(i18n);\n const lng = (ctx.request.query.locale as string) || ctx.acceptsLanguages().shift();\n if (lng !== '*' && lng) {\n i18n.changeLanguage(lng);\n }\n await next();\n });\n\n if (options.dataWrapping !== false) {\n app.use(dataWrapping());\n }\n\n app.use(table2resource());\n app.use(app.resourcer.restApiMiddleware());\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
+ export { AppManager } from './app-manager';
1
2
  export * from './application';
3
+ export { Application as default } from './application';
2
4
  export * as middlewares from './middlewares';
3
5
  export * from './plugin';
4
- export { Application as default } from './application';
6
+ export * from './plugin-manager';
7
+ export * from './read-config';
package/lib/index.js CHANGED
@@ -1,70 +1,35 @@
1
1
  "use strict";
2
-
3
- function _react() {
4
- const data = _interopRequireDefault(require("react"));
5
-
6
- _react = function _react() {
7
- return data;
8
- };
9
-
10
- return data;
11
- }
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- Object.defineProperty(o, k2, {
18
- enumerable: true,
19
- get: function get() {
20
- return m[k];
21
- }
22
- });
23
- } : function (o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- o[k2] = m[k];
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
26
13
  });
27
-
28
- var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
29
- Object.defineProperty(o, "default", {
30
- enumerable: true,
31
- value: v
32
- });
33
- } : function (o, v) {
34
- o["default"] = v;
35
- });
36
-
37
- var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
38
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
39
16
  };
40
-
41
- var __importStar = void 0 && (void 0).__importStar || function (mod) {
42
- if (mod && mod.__esModule) return mod;
43
- var result = {};
44
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
45
-
46
- __setModuleDefault(result, mod);
47
-
48
- return result;
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
49
23
  };
50
-
51
- Object.defineProperty(exports, "__esModule", {
52
- value: true
53
- });
54
- exports.default = exports.middlewares = void 0;
55
-
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.middlewares = exports.default = exports.AppManager = void 0;
26
+ var app_manager_1 = require("./app-manager");
27
+ Object.defineProperty(exports, "AppManager", { enumerable: true, get: function () { return app_manager_1.AppManager; } });
56
28
  __exportStar(require("./application"), exports);
57
-
29
+ var application_1 = require("./application");
30
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return application_1.Application; } });
58
31
  exports.middlewares = __importStar(require("./middlewares"));
59
-
60
32
  __exportStar(require("./plugin"), exports);
61
-
62
- var application_1 = require("./application");
63
-
64
- Object.defineProperty(exports, "default", {
65
- enumerable: true,
66
- get: function get() {
67
- return application_1.Application;
68
- }
69
- });
70
- //# sourceMappingURL=index.js.map
33
+ __exportStar(require("./plugin-manager"), exports);
34
+ __exportStar(require("./read-config"), exports);
35
+ //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,6DAA6C;AAC7C,2CAAyB;AACzB,6CAAuD;AAA9C,sGAAA,WAAW,OAAW","file":"index.js","sourcesContent":["export * from './application';\nexport * as middlewares from './middlewares';\nexport * from './plugin';\nexport { Application as default } from './application';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,gDAA8B;AAC9B,6CAAuD;AAA9C,sGAAA,WAAW,OAAW;AAC/B,6DAA6C;AAC7C,2CAAyB;AACzB,mDAAiC;AACjC,gDAA8B","sourcesContent":["export { AppManager } from './app-manager';\nexport * from './application';\nexport { Application as default } from './application';\nexport * as middlewares from './middlewares';\nexport * from './plugin';\nexport * from './plugin-manager';\nexport * from './read-config';\n\n"]}