@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,57 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export class PluginManager {
11
+ constructor(options) {
12
+ this.plugins = new Map();
13
+ this.app = options.app;
14
+ }
15
+ getPlugins() {
16
+ return this.plugins;
17
+ }
18
+ get(name) {
19
+ return this.plugins.get(name);
20
+ }
21
+ add(pluginClass, options) {
22
+ const instance = new pluginClass(this.app, options);
23
+ const name = instance.getName();
24
+ if (this.plugins.has(name)) {
25
+ throw new Error(`plugin name [${name}] `);
26
+ }
27
+ this.plugins.set(name, instance);
28
+ return instance;
29
+ }
30
+ load() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ yield this.app.emitAsync('beforeLoadAll');
33
+ for (const [name, plugin] of this.plugins) {
34
+ yield plugin.beforeLoad();
35
+ }
36
+ for (const [name, plugin] of this.plugins) {
37
+ yield this.app.emitAsync('beforeLoadPlugin', plugin);
38
+ yield plugin.load();
39
+ yield this.app.emitAsync('afterLoadPlugin', plugin);
40
+ }
41
+ yield this.app.emitAsync('afterLoadAll');
42
+ });
43
+ }
44
+ install(options) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ for (const [name, plugin] of this.plugins) {
47
+ yield this.app.emitAsync('beforeInstallPlugin', plugin, options);
48
+ yield plugin.install(options);
49
+ yield this.app.emitAsync('afterInstallPlugin', plugin, options);
50
+ }
51
+ });
52
+ }
53
+ static resolvePlugin(pluginName) {
54
+ return require(pluginName).default;
55
+ }
56
+ }
57
+ //# sourceMappingURL=plugin-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-manager.js","sourceRoot":"","sources":["../src/plugin-manager.ts"],"names":[],"mappings":";;;;;;;;;AAcA,MAAM,OAAO,aAAa;IAIxB,YAAY,OAA6B;QAF/B,YAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAG5C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,GAAG,CAAsB,WAAgB,EAAE,OAAW;QACpD,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAEpD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC;QAEhC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,IAAI,CAAC,CAAC;SAC3C;QAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEK,IAAI;;YACR,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;YAE1C,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE;gBACzC,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;aAC3B;YAED,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE;gBACzC,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;gBACrD,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBACpB,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;aACrD;YAED,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;QAC3C,CAAC;KAAA;IAEK,OAAO,CAAC,OAAwB;;YACpC,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE;gBACzC,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,qBAAqB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBACjE,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC9B,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,oBAAoB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;aACjE;QACH,CAAC;KAAA;IAED,MAAM,CAAC,aAAa,CAAC,UAAkB;QACrC,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC;IACrC,CAAC;CACF","sourcesContent":["import { CleanOptions, SyncOptions } from '@nocobase/database';\nimport Application from './application';\nimport { Plugin } from './plugin';\n\ninterface PluginManagerOptions {\n app: Application;\n}\n\nexport interface InstallOptions {\n cliArgs?: any[];\n clean?: CleanOptions | boolean;\n sync?: SyncOptions;\n}\n\nexport class PluginManager {\n app: Application;\n protected plugins = new Map<string, Plugin>();\n\n constructor(options: PluginManagerOptions) {\n this.app = options.app;\n }\n\n getPlugins() {\n return this.plugins;\n }\n\n get(name: string) {\n return this.plugins.get(name);\n }\n\n add<P = Plugin, O = any>(pluginClass: any, options?: O): P {\n const instance = new pluginClass(this.app, options);\n\n const name = instance.getName();\n\n if (this.plugins.has(name)) {\n throw new Error(`plugin name [${name}] `);\n }\n\n this.plugins.set(name, instance);\n\n return instance;\n }\n\n async load() {\n await this.app.emitAsync('beforeLoadAll');\n\n for (const [name, plugin] of this.plugins) {\n await plugin.beforeLoad();\n }\n\n for (const [name, plugin] of this.plugins) {\n await this.app.emitAsync('beforeLoadPlugin', plugin);\n await plugin.load();\n await this.app.emitAsync('afterLoadPlugin', plugin);\n }\n\n await this.app.emitAsync('afterLoadAll');\n }\n\n async install(options?: InstallOptions) {\n for (const [name, plugin] of this.plugins) {\n await this.app.emitAsync('beforeInstallPlugin', plugin, options);\n await plugin.install(options);\n await this.app.emitAsync('afterInstallPlugin', plugin, options);\n }\n }\n\n static resolvePlugin(pluginName: string) {\n return require(pluginName).default;\n }\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import { Database } from '@nocobase/database';
2
+ import { Application } from './application';
3
+ import { InstallOptions } from './plugin-manager';
4
+ export interface PluginInterface {
5
+ beforeLoad?: () => void;
6
+ load(): any;
7
+ getName(): string;
8
+ }
9
+ export interface PluginOptions {
10
+ activate?: boolean;
11
+ displayName?: string;
12
+ description?: string;
13
+ version?: string;
14
+ install?: (this: Plugin) => void;
15
+ load?: (this: Plugin) => void;
16
+ plugin?: typeof Plugin;
17
+ [key: string]: any;
18
+ }
19
+ export declare type PluginType = typeof Plugin;
20
+ export declare abstract class Plugin<O = any> implements PluginInterface {
21
+ options: O;
22
+ app: Application;
23
+ db: Database;
24
+ constructor(app: Application, options?: O);
25
+ setOptions(options: O): void;
26
+ abstract getName(): string;
27
+ beforeLoad(): void;
28
+ install(options?: InstallOptions): Promise<void>;
29
+ load(): Promise<void>;
30
+ collectionPath(): any;
31
+ protected getPackageName(dirname: string): any;
32
+ }
package/esm/plugin.js ADDED
@@ -0,0 +1,43 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import finder from 'find-package-json';
11
+ export class Plugin {
12
+ constructor(app, options) {
13
+ this.app = app;
14
+ this.db = app.db;
15
+ this.setOptions(options);
16
+ }
17
+ setOptions(options) {
18
+ this.options = options || {};
19
+ }
20
+ beforeLoad() { }
21
+ install(options) {
22
+ return __awaiter(this, void 0, void 0, function* () { });
23
+ }
24
+ load() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const collectionPath = this.collectionPath();
27
+ if (collectionPath) {
28
+ yield this.db.import({
29
+ directory: collectionPath,
30
+ });
31
+ }
32
+ });
33
+ }
34
+ collectionPath() {
35
+ return null;
36
+ }
37
+ getPackageName(dirname) {
38
+ const f = finder(dirname);
39
+ const packageObj = f.next().value;
40
+ return packageObj['name'];
41
+ }
42
+ }
43
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAuBvC,MAAM,OAAgB,MAAM;IAK1B,YAAY,GAAgB,EAAE,OAAW;QACvC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;QACjB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,UAAU,CAAC,OAAU;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAK,EAAU,CAAC;IACxC,CAAC;IAID,UAAU,KAAI,CAAC;IAET,OAAO,CAAC,OAAwB;8DAAG,CAAC;KAAA;IAEpC,IAAI;;YACR,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAC7C,IAAI,cAAc,EAAE;gBAClB,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC;oBACnB,SAAS,EAAE,cAAc;iBAC1B,CAAC,CAAC;aACJ;QACH,CAAC;KAAA;IAED,cAAc;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAES,cAAc,CAAC,OAAe;QACtC,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC1B,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;QAClC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { Database } from '@nocobase/database';\nimport { Application } from './application';\nimport finder from 'find-package-json';\n\nimport { InstallOptions } from './plugin-manager';\n\nexport interface PluginInterface {\n beforeLoad?: () => void;\n load();\n getName(): string;\n}\n\nexport interface PluginOptions {\n activate?: boolean;\n displayName?: string;\n description?: string;\n version?: string;\n install?: (this: Plugin) => void;\n load?: (this: Plugin) => void;\n plugin?: typeof Plugin;\n [key: string]: any;\n}\n\nexport type PluginType = typeof Plugin;\n\nexport abstract class Plugin<O = any> implements PluginInterface {\n options: O;\n app: Application;\n db: Database;\n\n constructor(app: Application, options?: O) {\n this.app = app;\n this.db = app.db;\n this.setOptions(options);\n }\n\n setOptions(options: O) {\n this.options = options || ({} as any);\n }\n\n public abstract getName(): string;\n\n beforeLoad() {}\n\n async install(options?: InstallOptions) {}\n\n async load() {\n const collectionPath = this.collectionPath();\n if (collectionPath) {\n await this.db.import({\n directory: collectionPath,\n });\n }\n }\n\n collectionPath() {\n return null;\n }\n\n protected getPackageName(dirname: string) {\n const f = finder(dirname);\n const packageObj = f.next().value;\n return packageObj['name'];\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export declare function readConfig(dir: string): Promise<{}>;
2
+ export declare class ConfigurationRepository {
3
+ protected items: Map<string, any>;
4
+ get(key: string, defaultValue?: any): any;
5
+ set(key: string, value: any): Map<string, any>;
6
+ toObject(): {};
7
+ }
8
+ export declare function loadConfiguration(configurationDir: string, repository: ConfigurationRepository): Promise<void>;
@@ -0,0 +1,63 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import lodash from 'lodash';
11
+ import fs from 'fs';
12
+ import path from 'path';
13
+ export function readConfig(dir) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const repository = new ConfigurationRepository();
16
+ yield loadConfiguration(dir, repository);
17
+ return repository.toObject();
18
+ });
19
+ }
20
+ export class ConfigurationRepository {
21
+ constructor() {
22
+ this.items = new Map();
23
+ }
24
+ get(key, defaultValue = undefined) {
25
+ if (this.items.has(key)) {
26
+ return this.items.get(key);
27
+ }
28
+ return defaultValue;
29
+ }
30
+ set(key, value) {
31
+ return this.items.set(key, value);
32
+ }
33
+ toObject() {
34
+ const result = {};
35
+ for (const [key, value] of this.items.entries()) {
36
+ lodash.set(result, key, value);
37
+ }
38
+ return result;
39
+ }
40
+ }
41
+ export function loadConfiguration(configurationDir, repository) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const getConfigurationFiles = (dir, prefix = []) => __awaiter(this, void 0, void 0, function* () {
44
+ const files = yield fs.promises.readdir(dir, { withFileTypes: true });
45
+ for (const file of files) {
46
+ if (file.isDirectory()) {
47
+ yield getConfigurationFiles(path.join(dir, file.name), [...prefix, file.name]);
48
+ }
49
+ else {
50
+ if (!['ts', 'js'].includes(file.name.split('.').slice(1).join('.'))) {
51
+ continue;
52
+ }
53
+ const filePath = path.join(dir, file.name);
54
+ const keyName = path.parse(filePath).name;
55
+ const configuration = require(filePath).default;
56
+ repository.set([...prefix, keyName].join('.'), configuration);
57
+ }
58
+ }
59
+ });
60
+ yield getConfigurationFiles(configurationDir);
61
+ });
62
+ }
63
+ //# sourceMappingURL=read-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-config.js","sourceRoot":"","sources":["../src/read-config.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,UAAgB,UAAU,CAAC,GAAW;;QAC1C,MAAM,UAAU,GAAG,IAAI,uBAAuB,EAAE,CAAC;QACjD,MAAM,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACzC,OAAO,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CAAA;AAED,MAAM,OAAO,uBAAuB;IAApC;QACY,UAAK,GAAG,IAAI,GAAG,EAAe,CAAC;IAuB3C,CAAC;IArBC,GAAG,CAAC,GAAW,EAAE,YAAY,GAAG,SAAS;QACvC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACvB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC5B;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAU;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,QAAQ;QACN,MAAM,MAAM,GAAG,EAAE,CAAC;QAElB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE;YAC/C,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;SAChC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,MAAM,UAAgB,iBAAiB,CAAC,gBAAwB,EAAE,UAAmC;;QACnG,MAAM,qBAAqB,GAAG,CAAO,GAAW,EAAE,MAAM,GAAG,EAAE,EAAE,EAAE;YAC/D,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;YACtE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE;oBACtB,MAAM,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;iBAChF;qBAAM;oBACL,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;wBACnE,SAAS;qBACV;oBAED,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;oBAC1C,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;oBAEhD,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,CAAC;iBAC/D;aACF;QACH,CAAC,CAAA,CAAC;QAEF,MAAM,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;IAChD,CAAC;CAAA","sourcesContent":["import lodash from 'lodash';\nimport fs from 'fs';\nimport path from 'path';\n\nexport async function readConfig(dir: string) {\n const repository = new ConfigurationRepository();\n await loadConfiguration(dir, repository);\n return repository.toObject();\n}\n\nexport class ConfigurationRepository {\n protected items = new Map<string, any>();\n\n get(key: string, defaultValue = undefined) {\n if (this.items.has(key)) {\n return this.items.get(key);\n }\n\n return defaultValue;\n }\n\n set(key: string, value: any) {\n return this.items.set(key, value);\n }\n\n toObject() {\n const result = {};\n\n for (const [key, value] of this.items.entries()) {\n lodash.set(result, key, value);\n }\n\n return result;\n }\n}\n\nexport async function loadConfiguration(configurationDir: string, repository: ConfigurationRepository) {\n const getConfigurationFiles = async (dir: string, prefix = []) => {\n const files = await fs.promises.readdir(dir, { withFileTypes: true });\n for (const file of files) {\n if (file.isDirectory()) {\n await getConfigurationFiles(path.join(dir, file.name), [...prefix, file.name]);\n } else {\n if (!['ts', 'js'].includes(file.name.split('.').slice(1).join('.'))) {\n continue;\n }\n\n const filePath = path.join(dir, file.name);\n const keyName = path.parse(filePath).name;\n const configuration = require(filePath).default;\n\n repository.set([...prefix, keyName].join('.'), configuration);\n }\n }\n };\n\n await getConfigurationFiles(configurationDir);\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { AvailableActionOptions } from '@nocobase/acl';
2
+ declare const availableActions: {
3
+ [key: string]: AvailableActionOptions;
4
+ };
5
+ export { availableActions };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.availableActions = void 0;
4
+ const availableActions = {
5
+ create: {
6
+ displayName: '{{t("Add new")}}',
7
+ type: 'new-data',
8
+ onNewRecord: true,
9
+ allowConfigureFields: true,
10
+ },
11
+ // import: {
12
+ // displayName: '{{t("Import")}}',
13
+ // type: 'new-data',
14
+ // scope: false,
15
+ // },
16
+ export: {
17
+ displayName: '{{t("Export")}}',
18
+ type: 'old-data',
19
+ allowConfigureFields: true,
20
+ },
21
+ view: {
22
+ displayName: '{{t("View")}}',
23
+ type: 'old-data',
24
+ aliases: ['get', 'list'],
25
+ allowConfigureFields: true,
26
+ },
27
+ update: {
28
+ displayName: '{{t("Edit")}}',
29
+ type: 'old-data',
30
+ aliases: ['update', 'move'],
31
+ allowConfigureFields: true,
32
+ },
33
+ destroy: {
34
+ displayName: '{{t("Delete")}}',
35
+ type: 'old-data',
36
+ },
37
+ };
38
+ exports.availableActions = availableActions;
39
+ //# sourceMappingURL=available-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"available-action.js","sourceRoot":"","sources":["../../src/acl/available-action.ts"],"names":[],"mappings":";;;AAEA,MAAM,gBAAgB,GAElB;IACF,MAAM,EAAE;QACN,WAAW,EAAE,kBAAkB;QAC/B,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,IAAI;QACjB,oBAAoB,EAAE,IAAI;KAC3B;IACD,YAAY;IACZ,oCAAoC;IACpC,sBAAsB;IACtB,kBAAkB;IAClB,KAAK;IACL,MAAM,EAAE;QACN,WAAW,EAAE,iBAAiB;QAC9B,IAAI,EAAE,UAAU;QAChB,oBAAoB,EAAE,IAAI;KAC3B;IACD,IAAI,EAAE;QACJ,WAAW,EAAE,eAAe;QAC5B,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;QACxB,oBAAoB,EAAE,IAAI;KAC3B;IACD,MAAM,EAAE;QACN,WAAW,EAAE,eAAe;QAC5B,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC3B,oBAAoB,EAAE,IAAI;KAC3B;IACD,OAAO,EAAE;QACP,WAAW,EAAE,iBAAiB;QAC9B,IAAI,EAAE,UAAU;KACjB;CACF,CAAC;AAEO,4CAAgB","sourcesContent":["import { AvailableActionOptions } from '@nocobase/acl';\n\nconst availableActions: {\n [key: string]: AvailableActionOptions;\n} = {\n create: {\n displayName: '{{t(\"Add new\")}}',\n type: 'new-data',\n onNewRecord: true,\n allowConfigureFields: true,\n },\n // import: {\n // displayName: '{{t(\"Import\")}}',\n // type: 'new-data',\n // scope: false,\n // },\n export: {\n displayName: '{{t(\"Export\")}}',\n type: 'old-data',\n allowConfigureFields: true,\n },\n view: {\n displayName: '{{t(\"View\")}}',\n type: 'old-data',\n aliases: ['get', 'list'],\n allowConfigureFields: true,\n },\n update: {\n displayName: '{{t(\"Edit\")}}',\n type: 'old-data',\n aliases: ['update', 'move'],\n allowConfigureFields: true,\n },\n destroy: {\n displayName: '{{t(\"Delete\")}}',\n type: 'old-data',\n },\n};\n\nexport { availableActions };\n"]}
@@ -0,0 +1,2 @@
1
+ import { ACL } from '@nocobase/acl';
2
+ export declare function createACL(): ACL;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createACL = void 0;
4
+ const acl_1 = require("@nocobase/acl");
5
+ const available_action_1 = require("./available-action");
6
+ const configureResources = [
7
+ 'roles',
8
+ 'collections',
9
+ 'roles.collections',
10
+ 'roles.resources',
11
+ 'rolesResourcesScopes',
12
+ 'availableActions',
13
+ ];
14
+ function createACL() {
15
+ const acl = new acl_1.ACL();
16
+ for (const [actionName, actionParams] of Object.entries(available_action_1.availableActions)) {
17
+ acl.setAvailableAction(actionName, actionParams);
18
+ }
19
+ acl.registerConfigResources(configureResources);
20
+ return acl;
21
+ }
22
+ exports.createACL = createACL;
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/acl/index.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,yDAAsD;AAEtD,MAAM,kBAAkB,GAAG;IACzB,OAAO;IACP,aAAa;IACb,mBAAmB;IACnB,iBAAiB;IACjB,sBAAsB;IACtB,kBAAkB;CACnB,CAAC;AAEF,SAAgB,SAAS;IACvB,MAAM,GAAG,GAAG,IAAI,SAAG,EAAE,CAAC;IAEtB,KAAK,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mCAAgB,CAAC,EAAE;QACzE,GAAG,CAAC,kBAAkB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;KAClD;IAED,GAAG,CAAC,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;IAEhD,OAAO,GAAG,CAAC;AACb,CAAC;AAVD,8BAUC","sourcesContent":["import { ACL } from '@nocobase/acl';\nimport { availableActions } from './available-action';\n\nconst configureResources = [\n 'roles',\n 'collections',\n 'roles.collections',\n 'roles.resources',\n 'rolesResourcesScopes',\n 'availableActions',\n];\n\nexport function createACL() {\n const acl = new ACL();\n\n for (const [actionName, actionParams] of Object.entries(availableActions)) {\n acl.setAvailableAction(actionName, actionParams);\n }\n\n acl.registerConfigResources(configureResources);\n\n return acl;\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ import Application, { ApplicationOptions } from './application';
3
+ import http, { IncomingMessage } from 'http';
4
+ import EventEmitter from 'events';
5
+ declare type AppSelector = (req: IncomingMessage) => Application | string | undefined | null;
6
+ export declare class AppManager extends EventEmitter {
7
+ private app;
8
+ applications: Map<string, Application>;
9
+ constructor(app: Application);
10
+ appSelector: AppSelector;
11
+ createApplication(name: string, options: ApplicationOptions): Application;
12
+ removeApplication(name: string): Promise<void>;
13
+ setAppSelector(selector: AppSelector): void;
14
+ listen(...args: any[]): http.Server;
15
+ getApplication(appName: string): Promise<null | Application>;
16
+ callback(): (req: any, res: any) => Promise<void>;
17
+ emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
18
+ }
19
+ export {};
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AppManager = void 0;
16
+ const application_1 = __importDefault(require("./application"));
17
+ const http_1 = __importDefault(require("http"));
18
+ const events_1 = __importDefault(require("events"));
19
+ const utils_1 = require("@nocobase/utils");
20
+ class AppManager extends events_1.default {
21
+ constructor(app) {
22
+ super();
23
+ this.app = app;
24
+ this.applications = new Map();
25
+ this.appSelector = (req) => this.app;
26
+ app.on('beforeStop', (mainApp, options) => __awaiter(this, void 0, void 0, function* () {
27
+ return yield Promise.all([...this.applications.values()].map((application) => application.stop(options)));
28
+ }));
29
+ app.on('afterDestroy', (mainApp, options) => __awaiter(this, void 0, void 0, function* () {
30
+ return yield Promise.all([...this.applications.values()].map((application) => application.destroy(options)));
31
+ }));
32
+ }
33
+ createApplication(name, options) {
34
+ const application = new application_1.default(options);
35
+ this.applications.set(name, application);
36
+ return application;
37
+ }
38
+ removeApplication(name) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const application = this.applications.get(name);
41
+ if (!application) {
42
+ return;
43
+ }
44
+ yield application.destroy();
45
+ this.applications.delete(name);
46
+ });
47
+ }
48
+ setAppSelector(selector) {
49
+ this.appSelector = selector;
50
+ }
51
+ listen(...args) {
52
+ const server = http_1.default.createServer(this.callback());
53
+ return server.listen(...args);
54
+ }
55
+ getApplication(appName) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ yield this.emitAsync('beforeGetApplication', {
58
+ appManager: this,
59
+ name: appName,
60
+ });
61
+ return this.applications.get(appName);
62
+ });
63
+ }
64
+ callback() {
65
+ return (req, res) => __awaiter(this, void 0, void 0, function* () {
66
+ let handleApp = this.appSelector(req) || this.app;
67
+ if (typeof handleApp === 'string') {
68
+ handleApp = (yield this.getApplication(handleApp)) || this.app;
69
+ }
70
+ handleApp.callback()(req, res);
71
+ });
72
+ }
73
+ }
74
+ exports.AppManager = AppManager;
75
+ (0, utils_1.applyMixins)(AppManager, [utils_1.AsyncEmitter]);
76
+ //# sourceMappingURL=app-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-manager.js","sourceRoot":"","sources":["../src/app-manager.ts"],"names":[],"mappings":"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","sourcesContent":["import Application, { ApplicationOptions } from './application';\nimport http, { IncomingMessage } from 'http';\nimport EventEmitter from 'events';\nimport { applyMixins, AsyncEmitter } from '@nocobase/utils';\n\ntype AppSelector = (req: IncomingMessage) => Application | string | undefined | null;\n\nexport class AppManager extends EventEmitter {\n public applications: Map<string, Application> = new Map<string, Application>();\n\n constructor(private app: Application) {\n super();\n\n app.on('beforeStop', async (mainApp, options) => {\n return await Promise.all(\n [...this.applications.values()].map((application: Application) => application.stop(options)),\n );\n });\n\n app.on('afterDestroy', async (mainApp, options) => {\n return await Promise.all(\n [...this.applications.values()].map((application: Application) => application.destroy(options)),\n );\n });\n }\n\n appSelector: AppSelector = (req: IncomingMessage) => this.app;\n\n createApplication(name: string, options: ApplicationOptions): Application {\n const application = new Application(options);\n this.applications.set(name, application);\n return application;\n }\n\n async removeApplication(name: string) {\n const application = this.applications.get(name);\n if (!application) {\n return;\n }\n\n await application.destroy();\n\n this.applications.delete(name);\n }\n\n setAppSelector(selector: AppSelector) {\n this.appSelector = selector;\n }\n\n listen(...args) {\n const server = http.createServer(this.callback());\n return server.listen(...args);\n }\n\n async getApplication(appName: string): Promise<null | Application> {\n await this.emitAsync('beforeGetApplication', {\n appManager: this,\n name: appName,\n });\n\n return this.applications.get(appName);\n }\n\n callback() {\n return async (req, res) => {\n let handleApp = this.appSelector(req) || this.app;\n\n if (typeof handleApp === 'string') {\n handleApp = (await this.getApplication(handleApp)) || this.app;\n }\n\n handleApp.callback()(req, res);\n };\n }\n\n emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;\n}\n\napplyMixins(AppManager, [AsyncEmitter]);\n"]}
@@ -1,20 +1,30 @@
1
- import Koa from 'koa';
2
- import { Command, CommandOptions } from 'commander';
3
- import Database, { DatabaseOptions, TableOptions } from '@nocobase/database';
1
+ /// <reference types="node" />
2
+ /// <reference types="koa-bodyparser" />
3
+ import { ACL } from '@nocobase/acl';
4
+ import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
4
5
  import Resourcer, { ResourceOptions } from '@nocobase/resourcer';
5
- import { PluginType, Plugin, PluginOptions } from './plugin';
6
+ import { AsyncEmitter } from '@nocobase/utils';
7
+ import { Command, CommandOptions } from 'commander';
8
+ import { Server } from 'http';
6
9
  import { i18n, InitOptions } from 'i18next';
10
+ import Koa from 'koa';
11
+ import { AppManager } from './app-manager';
12
+ import { Plugin } from './plugin';
13
+ import { InstallOptions, PluginManager } from './plugin-manager';
14
+ export declare type PluginConfiguration = string | [string, any];
15
+ export declare type PluginsConfigurations = Array<PluginConfiguration>;
7
16
  export interface ResourcerOptions {
8
17
  prefix?: string;
9
18
  }
10
19
  export interface ApplicationOptions {
11
- database?: DatabaseOptions;
20
+ database?: IDatabaseOptions | Database;
12
21
  resourcer?: ResourcerOptions;
13
22
  bodyParser?: any;
14
23
  cors?: any;
15
24
  dataWrapping?: boolean;
16
25
  registerActions?: boolean;
17
26
  i18n?: i18n | InitOptions;
27
+ plugins?: PluginsConfigurations;
18
28
  }
19
29
  interface DefaultState {
20
30
  currentUser?: any;
@@ -36,23 +46,52 @@ interface ActionsOptions {
36
46
  resourceName?: string;
37
47
  resourceNames?: string[];
38
48
  }
39
- export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa {
49
+ interface ListenOptions {
50
+ port?: number | undefined;
51
+ host?: string | undefined;
52
+ backlog?: number | undefined;
53
+ path?: string | undefined;
54
+ exclusive?: boolean | undefined;
55
+ readableAll?: boolean | undefined;
56
+ writableAll?: boolean | undefined;
57
+ /**
58
+ * @default false
59
+ */
60
+ ipv6Only?: boolean | undefined;
61
+ signal?: AbortSignal | undefined;
62
+ }
63
+ interface StartOptions {
64
+ cliArgs?: any[];
65
+ listen?: ListenOptions;
66
+ }
67
+ export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {
68
+ options: ApplicationOptions;
40
69
  readonly db: Database;
41
70
  readonly resourcer: Resourcer;
42
71
  readonly cli: Command;
43
72
  readonly i18n: i18n;
44
- protected plugins: Map<string, Plugin>;
73
+ readonly pm: PluginManager;
74
+ readonly acl: ACL;
75
+ readonly appManager: AppManager;
76
+ protected plugins: Map<string, Plugin<any>>;
77
+ listenServer: Server;
45
78
  constructor(options: ApplicationOptions);
79
+ plugin<O = any>(pluginClass: any, options?: O): Plugin<O>;
80
+ loadPluginConfig(pluginsConfigurations: PluginsConfigurations): void;
46
81
  use<NewStateT = {}, NewContextT = {}>(middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>, options?: MiddlewareOptions): Koa<Koa.DefaultState & StateT & NewStateT, Koa.DefaultContext & ContextT & NewContextT>;
47
- collection(options: TableOptions): import("@nocobase/database").Table;
82
+ collection(options: CollectionOptions): import("@nocobase/database").Collection<any, any>;
48
83
  resource(options: ResourceOptions): import("@nocobase/resourcer").Resource;
49
84
  actions(handlers: any, options?: ActionsOptions): void;
50
- command(nameAndArgs: string, opts?: CommandOptions): Command;
85
+ command(name: string, desc?: string, opts?: CommandOptions): Command;
51
86
  findCommand(name: string): Command;
52
- plugin(options?: PluginType | PluginOptions, ext?: PluginOptions): Plugin;
53
87
  load(): Promise<void>;
54
- emitAsync(event: string | symbol, ...args: any[]): Promise<boolean>;
88
+ getPlugin<P extends Plugin>(name: string): P;
55
89
  parse(argv?: string[]): Promise<Command>;
56
- destroy(): Promise<void>;
90
+ start(options?: StartOptions): Promise<void>;
91
+ listen(...args: any[]): Server;
92
+ stop(options?: any): Promise<void>;
93
+ destroy(options?: any): Promise<void>;
94
+ install(options?: InstallOptions): Promise<void>;
95
+ emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
57
96
  }
58
97
  export default Application;