@nocobase/server 1.2.12-alpha → 1.3.0-alpha.20240710084543

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 (124) hide show
  1. package/package.json +14 -14
  2. package/lib/acl/available-action.d.ts +0 -13
  3. package/lib/acl/available-action.js +0 -71
  4. package/lib/acl/index.d.ts +0 -10
  5. package/lib/acl/index.js +0 -46
  6. package/lib/app-command.d.ts +0 -20
  7. package/lib/app-command.js +0 -82
  8. package/lib/app-supervisor.d.ts +0 -69
  9. package/lib/app-supervisor.js +0 -302
  10. package/lib/application.d.ts +0 -345
  11. package/lib/application.js +0 -876
  12. package/lib/cache/index.d.ts +0 -11
  13. package/lib/cache/index.js +0 -44
  14. package/lib/commands/console.d.ts +0 -11
  15. package/lib/commands/console.js +0 -48
  16. package/lib/commands/create-migration.d.ts +0 -11
  17. package/lib/commands/create-migration.js +0 -79
  18. package/lib/commands/db-auth.d.ts +0 -11
  19. package/lib/commands/db-auth.js +0 -38
  20. package/lib/commands/db-clean.d.ts +0 -11
  21. package/lib/commands/db-clean.js +0 -41
  22. package/lib/commands/db-sync.d.ts +0 -11
  23. package/lib/commands/db-sync.js +0 -50
  24. package/lib/commands/destroy.d.ts +0 -11
  25. package/lib/commands/destroy.js +0 -40
  26. package/lib/commands/index.d.ts +0 -10
  27. package/lib/commands/index.js +0 -82
  28. package/lib/commands/install.d.ts +0 -11
  29. package/lib/commands/install.js +0 -43
  30. package/lib/commands/migrator.d.ts +0 -11
  31. package/lib/commands/migrator.js +0 -41
  32. package/lib/commands/pm.d.ts +0 -11
  33. package/lib/commands/pm.js +0 -98
  34. package/lib/commands/refresh.d.ts +0 -11
  35. package/lib/commands/refresh.js +0 -41
  36. package/lib/commands/restart.d.ts +0 -11
  37. package/lib/commands/restart.js +0 -45
  38. package/lib/commands/start.d.ts +0 -11
  39. package/lib/commands/start.js +0 -85
  40. package/lib/commands/stop.d.ts +0 -11
  41. package/lib/commands/stop.js +0 -44
  42. package/lib/commands/upgrade.d.ts +0 -14
  43. package/lib/commands/upgrade.js +0 -39
  44. package/lib/cron/cron-job-manager.d.ts +0 -22
  45. package/lib/cron/cron-job-manager.js +0 -82
  46. package/lib/errors/application-not-install.d.ts +0 -12
  47. package/lib/errors/application-not-install.js +0 -45
  48. package/lib/errors/handler.d.ts +0 -11
  49. package/lib/errors/handler.js +0 -50
  50. package/lib/errors/plugin-command-error.d.ts +0 -10
  51. package/lib/errors/plugin-command-error.js +0 -40
  52. package/lib/errors/plugin-not-exist.d.ts +0 -10
  53. package/lib/errors/plugin-not-exist.js +0 -40
  54. package/lib/gateway/errors.d.ts +0 -30
  55. package/lib/gateway/errors.js +0 -154
  56. package/lib/gateway/index.d.ts +0 -79
  57. package/lib/gateway/index.js +0 -393
  58. package/lib/gateway/ipc-socket-client.d.ts +0 -27
  59. package/lib/gateway/ipc-socket-client.js +0 -110
  60. package/lib/gateway/ipc-socket-server.d.ts +0 -21
  61. package/lib/gateway/ipc-socket-server.js +0 -150
  62. package/lib/gateway/ws-server.d.ts +0 -36
  63. package/lib/gateway/ws-server.js +0 -196
  64. package/lib/helper.d.ts +0 -18
  65. package/lib/helper.js +0 -193
  66. package/lib/helpers/application-version.d.ts +0 -18
  67. package/lib/helpers/application-version.js +0 -88
  68. package/lib/index.d.ts +0 -17
  69. package/lib/index.js +0 -64
  70. package/lib/locale/index.d.ts +0 -9
  71. package/lib/locale/index.js +0 -30
  72. package/lib/locale/locale.d.ts +0 -38
  73. package/lib/locale/locale.js +0 -174
  74. package/lib/locale/resource.d.ts +0 -9
  75. package/lib/locale/resource.js +0 -87
  76. package/lib/main-data-source.d.ts +0 -12
  77. package/lib/main-data-source.js +0 -57
  78. package/lib/middlewares/data-template.d.ts +0 -10
  79. package/lib/middlewares/data-template.js +0 -146
  80. package/lib/middlewares/data-wrapping.d.ts +0 -11
  81. package/lib/middlewares/data-wrapping.js +0 -100
  82. package/lib/middlewares/i18n.d.ts +0 -9
  83. package/lib/middlewares/i18n.js +0 -53
  84. package/lib/middlewares/index.d.ts +0 -10
  85. package/lib/middlewares/index.js +0 -39
  86. package/lib/middlewares/parse-variables.d.ts +0 -9
  87. package/lib/middlewares/parse-variables.js +0 -95
  88. package/lib/middlewares/validate-filter-params.d.ts +0 -9
  89. package/lib/middlewares/validate-filter-params.js +0 -42
  90. package/lib/migration.d.ts +0 -20
  91. package/lib/migration.js +0 -54
  92. package/lib/migrations/20230912193824-package-name-unique.d.ts +0 -14
  93. package/lib/migrations/20230912193824-package-name-unique.js +0 -59
  94. package/lib/migrations/20230912294620-update-pkg.d.ts +0 -14
  95. package/lib/migrations/20230912294620-update-pkg.js +0 -65
  96. package/lib/migrations/20240106082756-update-plugins.d.ts +0 -14
  97. package/lib/migrations/20240106082756-update-plugins.js +0 -51
  98. package/lib/migrations/20240428235620-rename-plugins.d.ts +0 -14
  99. package/lib/migrations/20240428235620-rename-plugins.js +0 -49
  100. package/lib/plugin-manager/clientStaticUtils.d.ts +0 -31
  101. package/lib/plugin-manager/clientStaticUtils.js +0 -129
  102. package/lib/plugin-manager/constants.d.ts +0 -15
  103. package/lib/plugin-manager/constants.js +0 -135
  104. package/lib/plugin-manager/deps.d.ts +0 -10
  105. package/lib/plugin-manager/deps.js +0 -83
  106. package/lib/plugin-manager/index.d.ts +0 -10
  107. package/lib/plugin-manager/index.js +0 -32
  108. package/lib/plugin-manager/middleware.d.ts +0 -10
  109. package/lib/plugin-manager/middleware.js +0 -45
  110. package/lib/plugin-manager/options/collection.d.ts +0 -10
  111. package/lib/plugin-manager/options/collection.js +0 -47
  112. package/lib/plugin-manager/options/resource.d.ts +0 -23
  113. package/lib/plugin-manager/options/resource.js +0 -186
  114. package/lib/plugin-manager/plugin-manager-repository.d.ts +0 -36
  115. package/lib/plugin-manager/plugin-manager-repository.js +0 -158
  116. package/lib/plugin-manager/plugin-manager.d.ts +0 -206
  117. package/lib/plugin-manager/plugin-manager.js +0 -1100
  118. package/lib/plugin-manager/types.d.ts +0 -23
  119. package/lib/plugin-manager/types.js +0 -24
  120. package/lib/plugin-manager/utils.d.ts +0 -115
  121. package/lib/plugin-manager/utils.js +0 -568
  122. package/lib/plugin.d.ts +0 -99
  123. package/lib/plugin.js +0 -228
  124. package/lib/swagger/index.json +0 -1569
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "1.2.12-alpha",
3
+ "version": "1.3.0-alpha.20240710084543",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
@@ -10,18 +10,18 @@
10
10
  "@koa/cors": "^3.1.0",
11
11
  "@koa/multer": "^3.0.2",
12
12
  "@koa/router": "^9.4.0",
13
- "@nocobase/acl": "1.2.12-alpha",
14
- "@nocobase/actions": "1.2.12-alpha",
15
- "@nocobase/auth": "1.2.12-alpha",
16
- "@nocobase/cache": "1.2.12-alpha",
17
- "@nocobase/data-source-manager": "1.2.12-alpha",
18
- "@nocobase/database": "1.2.12-alpha",
19
- "@nocobase/evaluators": "1.2.12-alpha",
20
- "@nocobase/logger": "1.2.12-alpha",
21
- "@nocobase/resourcer": "1.2.12-alpha",
22
- "@nocobase/sdk": "1.2.12-alpha",
23
- "@nocobase/telemetry": "1.2.12-alpha",
24
- "@nocobase/utils": "1.2.12-alpha",
13
+ "@nocobase/acl": "1.3.0-alpha.20240710084543",
14
+ "@nocobase/actions": "1.3.0-alpha.20240710084543",
15
+ "@nocobase/auth": "1.3.0-alpha.20240710084543",
16
+ "@nocobase/cache": "1.3.0-alpha.20240710084543",
17
+ "@nocobase/data-source-manager": "1.3.0-alpha.20240710084543",
18
+ "@nocobase/database": "1.3.0-alpha.20240710084543",
19
+ "@nocobase/evaluators": "1.3.0-alpha.20240710084543",
20
+ "@nocobase/logger": "1.3.0-alpha.20240710084543",
21
+ "@nocobase/resourcer": "1.3.0-alpha.20240710084543",
22
+ "@nocobase/sdk": "1.3.0-alpha.20240710084543",
23
+ "@nocobase/telemetry": "1.3.0-alpha.20240710084543",
24
+ "@nocobase/utils": "1.3.0-alpha.20240710084543",
25
25
  "@types/decompress": "4.2.4",
26
26
  "@types/ini": "^1.3.31",
27
27
  "@types/koa-send": "^4.1.3",
@@ -54,5 +54,5 @@
54
54
  "@types/serve-handler": "^6.1.1",
55
55
  "@types/ws": "^8.5.5"
56
56
  },
57
- "gitHead": "553231d4882496cb7f1f17fa7541899ce82a27ab"
57
+ "gitHead": "07a8b596fc64a9779a194cb9b0dc2ca7570ed9d4"
58
58
  }
@@ -1,13 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { AvailableActionOptions } from '@nocobase/acl';
10
- declare const availableActions: {
11
- [key: string]: AvailableActionOptions;
12
- };
13
- export { availableActions };
@@ -1,71 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var available_action_exports = {};
28
- __export(available_action_exports, {
29
- availableActions: () => availableActions
30
- });
31
- module.exports = __toCommonJS(available_action_exports);
32
- const availableActions = {
33
- create: {
34
- displayName: '{{t("Add new")}}',
35
- type: "new-data",
36
- onNewRecord: true,
37
- aliases: ["create", "firstOrCreate", "updateOrCreate"],
38
- allowConfigureFields: true
39
- },
40
- // import: {
41
- // displayName: '{{t("Import")}}',
42
- // type: 'new-data',
43
- // scope: false,
44
- // },
45
- // export: {
46
- // displayName: '{{t("Export")}}',
47
- // type: 'old-data',
48
- // allowConfigureFields: true,
49
- // },
50
- view: {
51
- displayName: '{{t("View")}}',
52
- type: "old-data",
53
- aliases: ["get", "list"],
54
- allowConfigureFields: true
55
- },
56
- update: {
57
- displayName: '{{t("Edit")}}',
58
- type: "old-data",
59
- aliases: ["update", "move", "add", "set", "remove", "toggle"],
60
- allowConfigureFields: true
61
- },
62
- destroy: {
63
- displayName: '{{t("Delete")}}',
64
- aliases: ["destroy"],
65
- type: "old-data"
66
- }
67
- };
68
- // Annotate the CommonJS export names for ESM import in node:
69
- 0 && (module.exports = {
70
- availableActions
71
- });
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { ACL } from '@nocobase/acl';
10
- export declare function createACL(): ACL;
package/lib/acl/index.js DELETED
@@ -1,46 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
- var __export = (target, all) => {
16
- for (var name in all)
17
- __defProp(target, name, { get: all[name], enumerable: true });
18
- };
19
- var __copyProps = (to, from, except, desc) => {
20
- if (from && typeof from === "object" || typeof from === "function") {
21
- for (let key of __getOwnPropNames(from))
22
- if (!__hasOwnProp.call(to, key) && key !== except)
23
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
- }
25
- return to;
26
- };
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var acl_exports = {};
29
- __export(acl_exports, {
30
- createACL: () => createACL
31
- });
32
- module.exports = __toCommonJS(acl_exports);
33
- var import_acl = require("@nocobase/acl");
34
- var import_available_action = require("./available-action");
35
- function createACL() {
36
- const acl = new import_acl.ACL();
37
- for (const [actionName, actionParams] of Object.entries(import_available_action.availableActions)) {
38
- acl.setAvailableAction(actionName, actionParams);
39
- }
40
- return acl;
41
- }
42
- __name(createACL, "createACL");
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- createACL
46
- });
@@ -1,20 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Command } from 'commander';
10
- export declare class AppCommand extends Command {
11
- private _handleByIPCServer;
12
- _preload: boolean;
13
- ipc(): this;
14
- auth(): this;
15
- preload(): this;
16
- hasCommand(name: string): boolean;
17
- isHandleByIPCServer(): boolean;
18
- createCommand(name?: string): AppCommand;
19
- parseHandleByIPCServer(argv: any, parseOptions?: any): Boolean;
20
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
- var __export = (target, all) => {
16
- for (var name in all)
17
- __defProp(target, name, { get: all[name], enumerable: true });
18
- };
19
- var __copyProps = (to, from, except, desc) => {
20
- if (from && typeof from === "object" || typeof from === "function") {
21
- for (let key of __getOwnPropNames(from))
22
- if (!__hasOwnProp.call(to, key) && key !== except)
23
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
- }
25
- return to;
26
- };
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var app_command_exports = {};
29
- __export(app_command_exports, {
30
- AppCommand: () => AppCommand
31
- });
32
- module.exports = __toCommonJS(app_command_exports);
33
- var import_commander = require("commander");
34
- const _AppCommand = class _AppCommand extends import_commander.Command {
35
- _handleByIPCServer = false;
36
- _preload = false;
37
- ipc() {
38
- this._handleByIPCServer = true;
39
- return this;
40
- }
41
- auth() {
42
- this["_authenticate"] = true;
43
- return this;
44
- }
45
- preload() {
46
- this["_authenticate"] = true;
47
- this._preload = true;
48
- return this;
49
- }
50
- hasCommand(name) {
51
- const names = this.commands.map((c) => c.name());
52
- return names.includes(name);
53
- }
54
- isHandleByIPCServer() {
55
- return this._handleByIPCServer;
56
- }
57
- createCommand(name) {
58
- return new _AppCommand(name);
59
- }
60
- parseHandleByIPCServer(argv, parseOptions) {
61
- const userArgs = this._prepareUserArgs(argv, parseOptions);
62
- if (userArgs[0] === "nocobase") {
63
- userArgs.shift();
64
- }
65
- let lastCommand = this;
66
- for (const arg of userArgs) {
67
- const subCommand = lastCommand._findCommand(arg);
68
- if (subCommand) {
69
- lastCommand = subCommand;
70
- } else {
71
- break;
72
- }
73
- }
74
- return lastCommand && lastCommand.isHandleByIPCServer();
75
- }
76
- };
77
- __name(_AppCommand, "AppCommand");
78
- let AppCommand = _AppCommand;
79
- // Annotate the CommonJS export names for ESM import in node:
80
- 0 && (module.exports = {
81
- AppCommand
82
- });
@@ -1,69 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- /// <reference types="node" />
10
- import { AsyncEmitter } from '@nocobase/utils';
11
- import { EventEmitter } from 'events';
12
- import Application, { ApplicationOptions } from './application';
13
- type BootOptions = {
14
- appName: string;
15
- options: any;
16
- appSupervisor: AppSupervisor;
17
- };
18
- type AppBootstrapper = (bootOptions: BootOptions) => Promise<void>;
19
- type AppStatus = 'initializing' | 'initialized' | 'running' | 'commanding' | 'stopped' | 'error' | 'not_found';
20
- export declare class AppSupervisor extends EventEmitter implements AsyncEmitter {
21
- private static instance;
22
- runningMode: 'single' | 'multiple';
23
- singleAppName: string | null;
24
- emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
25
- apps: {
26
- [appName: string]: Application;
27
- };
28
- lastSeenAt: Map<string, number>;
29
- appErrors: {
30
- [appName: string]: Error;
31
- };
32
- appStatus: {
33
- [appName: string]: AppStatus;
34
- };
35
- lastMaintainingMessage: {
36
- [appName: string]: string;
37
- };
38
- statusBeforeCommanding: {
39
- [appName: string]: AppStatus;
40
- };
41
- private appMutexes;
42
- private appBootstrapper;
43
- private constructor();
44
- static getInstance(): AppSupervisor;
45
- setAppError(appName: string, error: Error): void;
46
- hasAppError(appName: string): boolean;
47
- clearAppError(appName: string): void;
48
- reset(): Promise<void>;
49
- destroy(): Promise<void>;
50
- setAppStatus(appName: string, status: AppStatus, options?: {}): void;
51
- getMutexOfApp(appName: string): any;
52
- bootStrapApp(appName: string, options?: {}): Promise<void>;
53
- getApp(appName: string, options?: {
54
- withOutBootStrap?: boolean;
55
- [key: string]: any;
56
- }): Promise<Application<import("./application").DefaultState, import("./application").DefaultContext>>;
57
- setAppBootstrapper(appBootstrapper: AppBootstrapper): void;
58
- getAppStatus(appName: string, defaultStatus?: AppStatus): AppStatus | null;
59
- bootMainApp(options: ApplicationOptions): Application<import("./application").DefaultState, import("./application").DefaultContext>;
60
- hasApp(appName: string): boolean;
61
- touchApp(appName: string): void;
62
- addApp(app: Application): Application<import("./application").DefaultState, import("./application").DefaultContext>;
63
- getAppsNames(): Promise<string[]>;
64
- removeApp(appName: string): Promise<void>;
65
- subApps(): Application<import("./application").DefaultState, import("./application").DefaultContext>[];
66
- on(eventName: string | symbol, listener: (...args: any[]) => void): this;
67
- private bindAppEvents;
68
- }
69
- export {};
@@ -1,302 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
18
- var __export = (target, all) => {
19
- for (var name in all)
20
- __defProp(target, name, { get: all[name], enumerable: true });
21
- };
22
- var __copyProps = (to, from, except, desc) => {
23
- if (from && typeof from === "object" || typeof from === "function") {
24
- for (let key of __getOwnPropNames(from))
25
- if (!__hasOwnProp.call(to, key) && key !== except)
26
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
27
- }
28
- return to;
29
- };
30
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
- // If the importer is in node compatibility mode or this is not an ESM
32
- // file that has been converted to a CommonJS file using a Babel-
33
- // compatible transform (i.e. "__esModule" has not been set), then set
34
- // "default" to the CommonJS "module.exports" for node compatibility.
35
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
36
- mod
37
- ));
38
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
- var __publicField = (obj, key, value) => {
40
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
41
- return value;
42
- };
43
- var app_supervisor_exports = {};
44
- __export(app_supervisor_exports, {
45
- AppSupervisor: () => AppSupervisor
46
- });
47
- module.exports = __toCommonJS(app_supervisor_exports);
48
- var import_utils = require("@nocobase/utils");
49
- var import_async_mutex = require("async-mutex");
50
- var import_events = require("events");
51
- var import_application = __toESM(require("./application"));
52
- var import_handler = require("./errors/handler");
53
- const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
54
- runningMode = "multiple";
55
- singleAppName = null;
56
- apps = {};
57
- lastSeenAt = /* @__PURE__ */ new Map();
58
- appErrors = {};
59
- appStatus = {};
60
- lastMaintainingMessage = {};
61
- statusBeforeCommanding = {};
62
- appMutexes = {};
63
- appBootstrapper = null;
64
- constructor() {
65
- super();
66
- if (process.env.STARTUP_SUBAPP) {
67
- this.runningMode = "single";
68
- this.singleAppName = process.env.STARTUP_SUBAPP;
69
- }
70
- }
71
- static getInstance() {
72
- if (!_AppSupervisor.instance) {
73
- _AppSupervisor.instance = new _AppSupervisor();
74
- }
75
- return _AppSupervisor.instance;
76
- }
77
- setAppError(appName, error) {
78
- this.appErrors[appName] = error;
79
- this.emit("appError", {
80
- appName,
81
- error
82
- });
83
- }
84
- hasAppError(appName) {
85
- return !!this.appErrors[appName];
86
- }
87
- clearAppError(appName) {
88
- delete this.appErrors[appName];
89
- }
90
- async reset() {
91
- const appNames = Object.keys(this.apps);
92
- for (const appName of appNames) {
93
- await this.removeApp(appName);
94
- }
95
- this.appBootstrapper = null;
96
- this.removeAllListeners();
97
- }
98
- async destroy() {
99
- await this.reset();
100
- _AppSupervisor.instance = null;
101
- }
102
- setAppStatus(appName, status, options = {}) {
103
- if (this.appStatus[appName] === status) {
104
- return;
105
- }
106
- this.appStatus[appName] = status;
107
- this.emit("appStatusChanged", {
108
- appName,
109
- status,
110
- options
111
- });
112
- }
113
- getMutexOfApp(appName) {
114
- if (!this.appMutexes[appName]) {
115
- this.appMutexes[appName] = new import_async_mutex.Mutex();
116
- }
117
- return this.appMutexes[appName];
118
- }
119
- async bootStrapApp(appName, options = {}) {
120
- await this.getMutexOfApp(appName).runExclusive(async () => {
121
- if (!this.hasApp(appName)) {
122
- this.setAppStatus(appName, "initializing");
123
- if (this.appBootstrapper) {
124
- await this.appBootstrapper({
125
- appSupervisor: this,
126
- appName,
127
- options
128
- });
129
- }
130
- if (!this.hasApp(appName)) {
131
- this.setAppStatus(appName, "not_found");
132
- } else if (!this.getAppStatus(appName) || this.getAppStatus(appName) == "initializing") {
133
- this.setAppStatus(appName, "initialized");
134
- }
135
- }
136
- });
137
- }
138
- async getApp(appName, options = {}) {
139
- if (!options.withOutBootStrap) {
140
- await this.bootStrapApp(appName, options);
141
- }
142
- return this.apps[appName];
143
- }
144
- setAppBootstrapper(appBootstrapper) {
145
- this.appBootstrapper = appBootstrapper;
146
- }
147
- getAppStatus(appName, defaultStatus) {
148
- const status = this.appStatus[appName];
149
- if (status === void 0 && defaultStatus !== void 0) {
150
- return defaultStatus;
151
- }
152
- return status;
153
- }
154
- bootMainApp(options) {
155
- return new import_application.default(options);
156
- }
157
- hasApp(appName) {
158
- return !!this.apps[appName];
159
- }
160
- touchApp(appName) {
161
- if (!this.hasApp(appName)) {
162
- return;
163
- }
164
- this.lastSeenAt.set(appName, Math.floor(Date.now() / 1e3));
165
- }
166
- // add app into supervisor
167
- addApp(app) {
168
- if (this.apps[app.name]) {
169
- throw new Error(`app ${app.name} already exists`);
170
- }
171
- app.logger.info(`add app ${app.name} into supervisor`, { submodule: "supervisor", method: "addApp" });
172
- this.bindAppEvents(app);
173
- this.apps[app.name] = app;
174
- this.emit("afterAppAdded", app);
175
- if (!this.getAppStatus(app.name) || this.getAppStatus(app.name) == "not_found") {
176
- this.setAppStatus(app.name, "initialized");
177
- }
178
- return app;
179
- }
180
- // get registered app names
181
- async getAppsNames() {
182
- const apps = Object.values(this.apps);
183
- return apps.map((app) => app.name);
184
- }
185
- async removeApp(appName) {
186
- if (!this.apps[appName]) {
187
- console.log(`app ${appName} not exists`);
188
- return;
189
- }
190
- await this.apps[appName].runCommand("destroy");
191
- }
192
- subApps() {
193
- return Object.values(this.apps).filter((app) => app.name !== "main");
194
- }
195
- on(eventName, listener) {
196
- const listeners = this.listeners(eventName);
197
- const listenerName = listener.name;
198
- if (listenerName !== "") {
199
- const exists = listeners.find((l) => l.name === listenerName);
200
- if (exists) {
201
- super.removeListener(eventName, exists);
202
- }
203
- }
204
- return super.on(eventName, listener);
205
- }
206
- bindAppEvents(app) {
207
- app.on("afterDestroy", () => {
208
- delete this.apps[app.name];
209
- delete this.appStatus[app.name];
210
- delete this.appErrors[app.name];
211
- delete this.lastMaintainingMessage[app.name];
212
- delete this.statusBeforeCommanding[app.name];
213
- this.lastSeenAt.delete(app.name);
214
- });
215
- app.on("maintainingMessageChanged", ({ message, maintainingStatus }) => {
216
- if (this.lastMaintainingMessage[app.name] === message) {
217
- return;
218
- }
219
- this.lastMaintainingMessage[app.name] = message;
220
- const appStatus = this.getAppStatus(app.name);
221
- if (!maintainingStatus && appStatus !== "running") {
222
- return;
223
- }
224
- this.emit("appMaintainingMessageChanged", {
225
- appName: app.name,
226
- message,
227
- status: appStatus,
228
- command: appStatus == "running" ? null : maintainingStatus.command
229
- });
230
- });
231
- app.on("__started", async (_app, options) => {
232
- const { maintainingStatus, options: startOptions } = options;
233
- if (maintainingStatus && [
234
- "install",
235
- "upgrade",
236
- "refresh",
237
- "restore",
238
- "pm.add",
239
- "pm.update",
240
- "pm.enable",
241
- "pm.disable",
242
- "pm.remove"
243
- ].includes(maintainingStatus.command.name) && !startOptions.recover) {
244
- this.setAppStatus(app.name, "running", {
245
- refresh: true
246
- });
247
- } else {
248
- this.setAppStatus(app.name, "running");
249
- }
250
- });
251
- app.on("afterStop", async () => {
252
- this.setAppStatus(app.name, "stopped");
253
- });
254
- app.on("maintaining", (maintainingStatus) => {
255
- const { status, command } = maintainingStatus;
256
- switch (status) {
257
- case "command_begin":
258
- {
259
- this.statusBeforeCommanding[app.name] = this.getAppStatus(app.name);
260
- this.setAppStatus(app.name, "commanding");
261
- }
262
- break;
263
- case "command_running":
264
- break;
265
- case "command_end":
266
- {
267
- const appStatus = this.getAppStatus(app.name);
268
- this.emit("appMaintainingStatusChanged", maintainingStatus);
269
- if (appStatus == "commanding") {
270
- this.setAppStatus(app.name, this.statusBeforeCommanding[app.name]);
271
- }
272
- }
273
- break;
274
- case "command_error":
275
- {
276
- const errorLevel = (0, import_handler.getErrorLevel)(maintainingStatus.error);
277
- if (errorLevel === "fatal") {
278
- this.setAppError(app.name, maintainingStatus.error);
279
- this.setAppStatus(app.name, "error");
280
- break;
281
- }
282
- if (errorLevel === "warn") {
283
- this.emit("appError", {
284
- appName: app.name,
285
- error: maintainingStatus.error
286
- });
287
- }
288
- this.setAppStatus(app.name, this.statusBeforeCommanding[app.name]);
289
- }
290
- break;
291
- }
292
- });
293
- }
294
- };
295
- __name(_AppSupervisor, "AppSupervisor");
296
- __publicField(_AppSupervisor, "instance");
297
- let AppSupervisor = _AppSupervisor;
298
- (0, import_utils.applyMixins)(AppSupervisor, [import_utils.AsyncEmitter]);
299
- // Annotate the CommonJS export names for ESM import in node:
300
- 0 && (module.exports = {
301
- AppSupervisor
302
- });