@nocobase/plugin-multi-app-manager 2.0.0-alpha.7 → 2.0.0-alpha.71

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 (161) hide show
  1. package/dist/client/00b71fff3c8c7167.js +10 -0
  2. package/dist/client/Migrate.d.ts +10 -0
  3. package/dist/client/index.d.ts +1 -0
  4. package/dist/client/index.js +1 -1
  5. package/dist/client/settings/schemas/applications.d.ts +63 -1
  6. package/dist/externalVersion.js +8 -7
  7. package/dist/locale/de-DE.json +19 -7
  8. package/dist/locale/en-US.json +21 -7
  9. package/dist/locale/es-ES.json +23 -6
  10. package/dist/locale/fr-FR.json +26 -0
  11. package/dist/locale/hu-HU.json +26 -0
  12. package/dist/locale/id-ID.json +26 -0
  13. package/dist/locale/it-IT.json +19 -7
  14. package/dist/locale/ja-JP.json +18 -6
  15. package/dist/locale/ko-KR.json +22 -7
  16. package/dist/locale/nl-NL.json +24 -9
  17. package/dist/locale/pt-BR.json +23 -6
  18. package/dist/locale/ru-RU.json +26 -0
  19. package/dist/locale/tr-TR.json +26 -0
  20. package/dist/locale/uk-UA.json +26 -0
  21. package/dist/locale/vi-VN.json +26 -0
  22. package/dist/locale/zh-CN.json +17 -15
  23. package/dist/locale/zh-TW.json +26 -0
  24. package/dist/node_modules/p-queue/dist/index.d.ts +101 -0
  25. package/dist/node_modules/p-queue/dist/index.js +1 -0
  26. package/dist/node_modules/p-queue/dist/lower-bound.d.ts +1 -0
  27. package/dist/node_modules/p-queue/dist/lower-bound.js +21 -0
  28. package/dist/node_modules/p-queue/dist/options.d.ts +64 -0
  29. package/dist/node_modules/p-queue/dist/options.js +2 -0
  30. package/dist/node_modules/p-queue/dist/priority-queue.d.ts +12 -0
  31. package/dist/node_modules/p-queue/dist/priority-queue.js +32 -0
  32. package/dist/node_modules/p-queue/dist/queue.d.ts +7 -0
  33. package/dist/node_modules/p-queue/dist/queue.js +2 -0
  34. package/dist/node_modules/p-queue/license +9 -0
  35. package/dist/node_modules/p-queue/node_modules/eventemitter3/index.d.ts +134 -0
  36. package/dist/node_modules/p-queue/node_modules/eventemitter3/index.js +336 -0
  37. package/dist/node_modules/p-queue/node_modules/eventemitter3/package.json +56 -0
  38. package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.js +340 -0
  39. package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.min.js +1 -0
  40. package/dist/node_modules/p-queue/package.json +1 -0
  41. package/dist/server/adapters/legacy-adapter.d.ts +43 -0
  42. package/dist/server/adapters/legacy-adapter.js +207 -0
  43. package/dist/server/server.d.ts +7 -6
  44. package/dist/server/server.js +110 -186
  45. package/package.json +5 -2
  46. package/dist/client/bd12299af6cdc73a.js +0 -10
  47. package/dist/node_modules/mariadb/LICENSE +0 -502
  48. package/dist/node_modules/mariadb/callback.js +0 -41
  49. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +0 -278
  50. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  51. package/dist/node_modules/mariadb/lib/cmd/change-user.js +0 -149
  52. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +0 -17
  53. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +0 -102
  54. package/dist/node_modules/mariadb/lib/cmd/command.js +0 -168
  55. package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +0 -327
  56. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  57. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +0 -168
  58. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +0 -23
  59. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +0 -761
  60. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +0 -55
  61. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +0 -58
  62. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +0 -19
  63. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +0 -142
  64. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +0 -74
  65. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  66. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  67. package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +0 -74
  68. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +0 -29
  69. package/dist/node_modules/mariadb/lib/cmd/ping.js +0 -52
  70. package/dist/node_modules/mariadb/lib/cmd/query.js +0 -255
  71. package/dist/node_modules/mariadb/lib/cmd/quit.js +0 -28
  72. package/dist/node_modules/mariadb/lib/cmd/reset.js +0 -54
  73. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  74. package/dist/node_modules/mariadb/lib/cmd/stream.js +0 -45
  75. package/dist/node_modules/mariadb/lib/config/connection-options.js +0 -258
  76. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  77. package/dist/node_modules/mariadb/lib/config/pool-options.js +0 -47
  78. package/dist/node_modules/mariadb/lib/connection-callback.js +0 -160
  79. package/dist/node_modules/mariadb/lib/connection.js +0 -1460
  80. package/dist/node_modules/mariadb/lib/const/capabilities.js +0 -64
  81. package/dist/node_modules/mariadb/lib/const/collations.js +0 -473
  82. package/dist/node_modules/mariadb/lib/const/connection_status.js +0 -13
  83. package/dist/node_modules/mariadb/lib/const/error-code.js +0 -1282
  84. package/dist/node_modules/mariadb/lib/const/field-detail.js +0 -35
  85. package/dist/node_modules/mariadb/lib/const/field-type.js +0 -71
  86. package/dist/node_modules/mariadb/lib/const/server-status.js +0 -30
  87. package/dist/node_modules/mariadb/lib/const/state-change.js +0 -12
  88. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  89. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  90. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +0 -141
  91. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +0 -171
  92. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +0 -193
  93. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +0 -36
  94. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +0 -37
  95. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +0 -502
  96. package/dist/node_modules/mariadb/lib/io/packet.js +0 -515
  97. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  98. package/dist/node_modules/mariadb/lib/misc/connection-information.js +0 -96
  99. package/dist/node_modules/mariadb/lib/misc/errors.js +0 -123
  100. package/dist/node_modules/mariadb/lib/misc/parse.js +0 -1033
  101. package/dist/node_modules/mariadb/lib/misc/utils.js +0 -298
  102. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  103. package/dist/node_modules/mariadb/lib/pool-callback.js +0 -202
  104. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  105. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
  106. package/dist/node_modules/mariadb/lib/pool-promise.js +0 -108
  107. package/dist/node_modules/mariadb/node_modules/@types/node/assert/strict.d.ts +0 -8
  108. package/dist/node_modules/mariadb/node_modules/@types/node/assert.d.ts +0 -912
  109. package/dist/node_modules/mariadb/node_modules/@types/node/async_hooks.d.ts +0 -501
  110. package/dist/node_modules/mariadb/node_modules/@types/node/buffer.d.ts +0 -2232
  111. package/dist/node_modules/mariadb/node_modules/@types/node/child_process.d.ts +0 -1366
  112. package/dist/node_modules/mariadb/node_modules/@types/node/cluster.d.ts +0 -414
  113. package/dist/node_modules/mariadb/node_modules/@types/node/console.d.ts +0 -412
  114. package/dist/node_modules/mariadb/node_modules/@types/node/constants.d.ts +0 -18
  115. package/dist/node_modules/mariadb/node_modules/@types/node/crypto.d.ts +0 -3338
  116. package/dist/node_modules/mariadb/node_modules/@types/node/dgram.d.ts +0 -545
  117. package/dist/node_modules/mariadb/node_modules/@types/node/diagnostics_channel.d.ts +0 -152
  118. package/dist/node_modules/mariadb/node_modules/@types/node/dns/promises.d.ts +0 -370
  119. package/dist/node_modules/mariadb/node_modules/@types/node/dns.d.ts +0 -659
  120. package/dist/node_modules/mariadb/node_modules/@types/node/domain.d.ts +0 -169
  121. package/dist/node_modules/mariadb/node_modules/@types/node/events.d.ts +0 -651
  122. package/dist/node_modules/mariadb/node_modules/@types/node/fs/promises.d.ts +0 -1091
  123. package/dist/node_modules/mariadb/node_modules/@types/node/fs.d.ts +0 -3869
  124. package/dist/node_modules/mariadb/node_modules/@types/node/globals.d.ts +0 -294
  125. package/dist/node_modules/mariadb/node_modules/@types/node/globals.global.d.ts +0 -1
  126. package/dist/node_modules/mariadb/node_modules/@types/node/http.d.ts +0 -1396
  127. package/dist/node_modules/mariadb/node_modules/@types/node/http2.d.ts +0 -2101
  128. package/dist/node_modules/mariadb/node_modules/@types/node/https.d.ts +0 -391
  129. package/dist/node_modules/mariadb/node_modules/@types/node/index.d.ts +0 -129
  130. package/dist/node_modules/mariadb/node_modules/@types/node/inspector.d.ts +0 -2744
  131. package/dist/node_modules/mariadb/node_modules/@types/node/module.d.ts +0 -114
  132. package/dist/node_modules/mariadb/node_modules/@types/node/net.d.ts +0 -791
  133. package/dist/node_modules/mariadb/node_modules/@types/node/os.d.ts +0 -455
  134. package/dist/node_modules/mariadb/node_modules/@types/node/package.json +0 -220
  135. package/dist/node_modules/mariadb/node_modules/@types/node/path.d.ts +0 -180
  136. package/dist/node_modules/mariadb/node_modules/@types/node/perf_hooks.d.ts +0 -557
  137. package/dist/node_modules/mariadb/node_modules/@types/node/process.d.ts +0 -1481
  138. package/dist/node_modules/mariadb/node_modules/@types/node/punycode.d.ts +0 -117
  139. package/dist/node_modules/mariadb/node_modules/@types/node/querystring.d.ts +0 -131
  140. package/dist/node_modules/mariadb/node_modules/@types/node/readline.d.ts +0 -650
  141. package/dist/node_modules/mariadb/node_modules/@types/node/repl.d.ts +0 -424
  142. package/dist/node_modules/mariadb/node_modules/@types/node/stream/consumers.d.ts +0 -24
  143. package/dist/node_modules/mariadb/node_modules/@types/node/stream/promises.d.ts +0 -42
  144. package/dist/node_modules/mariadb/node_modules/@types/node/stream/web.d.ts +0 -330
  145. package/dist/node_modules/mariadb/node_modules/@types/node/stream.d.ts +0 -1249
  146. package/dist/node_modules/mariadb/node_modules/@types/node/string_decoder.d.ts +0 -67
  147. package/dist/node_modules/mariadb/node_modules/@types/node/timers/promises.d.ts +0 -68
  148. package/dist/node_modules/mariadb/node_modules/@types/node/timers.d.ts +0 -94
  149. package/dist/node_modules/mariadb/node_modules/@types/node/tls.d.ts +0 -1020
  150. package/dist/node_modules/mariadb/node_modules/@types/node/trace_events.d.ts +0 -161
  151. package/dist/node_modules/mariadb/node_modules/@types/node/tty.d.ts +0 -204
  152. package/dist/node_modules/mariadb/node_modules/@types/node/url.d.ts +0 -891
  153. package/dist/node_modules/mariadb/node_modules/@types/node/util.d.ts +0 -1594
  154. package/dist/node_modules/mariadb/node_modules/@types/node/v8.d.ts +0 -378
  155. package/dist/node_modules/mariadb/node_modules/@types/node/vm.d.ts +0 -507
  156. package/dist/node_modules/mariadb/node_modules/@types/node/wasi.d.ts +0 -158
  157. package/dist/node_modules/mariadb/node_modules/@types/node/worker_threads.d.ts +0 -649
  158. package/dist/node_modules/mariadb/node_modules/@types/node/zlib.d.ts +0 -517
  159. package/dist/node_modules/mariadb/package.json +0 -1
  160. package/dist/node_modules/mariadb/promise.js +0 -34
  161. package/dist/node_modules/mariadb/types/index.d.ts +0 -870
@@ -42,8 +42,8 @@ module.exports = __toCommonJS(server_exports);
42
42
  var import_database = require("@nocobase/database");
43
43
  var import_server = require("@nocobase/server");
44
44
  var import_lodash = __toESM(require("lodash"));
45
- var import_path = __toESM(require("path"));
46
45
  var import_server2 = require("../server");
46
+ var import_legacy_adapter = require("./adapters/legacy-adapter");
47
47
  const defaultSubAppUpgradeHandle = async (mainApp) => {
48
48
  const repository = mainApp.db.getRepository("applications");
49
49
  const findOptions = {};
@@ -63,14 +63,14 @@ const defaultSubAppUpgradeHandle = async (mainApp) => {
63
63
  if ((instanceOptions == null ? void 0 : instanceOptions.standaloneDeployment) && appSupervisor.runningMode !== "single") {
64
64
  continue;
65
65
  }
66
- const beforeSubAppStatus = import_server.AppSupervisor.getInstance().getAppStatus(instance.name);
66
+ const beforeSubAppStatus = await import_server.AppSupervisor.getInstance().getAppStatus(instance.name);
67
67
  const subApp = await appSupervisor.getApp(instance.name, {
68
68
  upgrading: true
69
69
  });
70
70
  try {
71
71
  mainApp.setMaintainingMessage(`upgrading sub app ${instance.name}...`);
72
72
  await subApp.runAsCLI(["upgrade"], { from: "user" });
73
- if (!beforeSubAppStatus && import_server.AppSupervisor.getInstance().getAppStatus(instance.name) === "initialized") {
73
+ if (!beforeSubAppStatus && await import_server.AppSupervisor.getInstance().getAppStatus(instance.name) === "initialized") {
74
74
  await import_server.AppSupervisor.getInstance().removeApp(instance.name);
75
75
  }
76
76
  } catch (error) {
@@ -80,75 +80,19 @@ const defaultSubAppUpgradeHandle = async (mainApp) => {
80
80
  }
81
81
  }
82
82
  };
83
- const defaultDbCreator = async (app) => {
84
- const databaseOptions = app.options.database;
85
- const { host, port, username, password, dialect, database, schema } = databaseOptions;
86
- if (dialect === "mysql") {
87
- const mysql = require("mysql2/promise");
88
- const connection = await mysql.createConnection({ host, port, user: username, password });
89
- await connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
90
- await connection.close();
91
- }
92
- if (dialect === "mariadb") {
93
- const mariadb = require("mariadb");
94
- const connection = await mariadb.createConnection({ host, port, user: username, password });
95
- await connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
96
- await connection.end();
97
- }
98
- if (["postgres", "kingbase"].includes(dialect)) {
99
- const { Client } = require("pg");
100
- const client = new Client({
101
- host,
102
- port,
103
- user: username,
104
- password,
105
- database: dialect
106
- });
107
- await client.connect();
108
- try {
109
- if (process.env.USE_DB_SCHEMA_IN_SUBAPP === "true") {
110
- await client.query(`CREATE SCHEMA IF NOT EXISTS ${schema}`);
111
- } else {
112
- await client.query(`CREATE DATABASE "${database}"`);
113
- }
114
- } catch (e) {
115
- console.log(e);
116
- }
117
- await client.end();
118
- }
119
- };
120
- const defaultAppOptionsFactory = (appName, mainApp) => {
121
- const rawDatabaseOptions = PluginMultiAppManagerServer.getDatabaseConfig(mainApp);
122
- if (rawDatabaseOptions.dialect === "sqlite") {
123
- const mainAppStorage = rawDatabaseOptions.storage;
124
- if (mainAppStorage !== ":memory:") {
125
- const mainStorageDir = import_path.default.dirname(mainAppStorage);
126
- rawDatabaseOptions.storage = import_path.default.join(mainStorageDir, `${appName}.sqlite`);
127
- }
128
- } else if (process.env.USE_DB_SCHEMA_IN_SUBAPP === "true" && ["postgres", "kingbase"].includes(rawDatabaseOptions.dialect)) {
129
- rawDatabaseOptions.schema = appName;
130
- } else {
131
- rawDatabaseOptions.database = appName;
132
- }
133
- return {
134
- database: {
135
- ...rawDatabaseOptions,
136
- tablePrefix: ""
137
- },
138
- plugins: ["nocobase"],
139
- resourcer: {
140
- prefix: process.env.API_BASE_PATH
141
- },
142
- cacheManager: {
143
- ...mainApp.options.cacheManager,
144
- prefix: appName
145
- }
146
- };
147
- };
148
83
  class PluginMultiAppManagerServer extends import_server.Plugin {
149
- appDbCreator = defaultDbCreator;
150
- appOptionsFactory = defaultAppOptionsFactory;
151
84
  subAppUpgradeHandler = defaultSubAppUpgradeHandle;
85
+ meter;
86
+ setSubAppUpgradeHandler(handler) {
87
+ this.subAppUpgradeHandler = handler;
88
+ }
89
+ static registerLegacyAdapter() {
90
+ const factory = ({ supervisor }) => new import_legacy_adapter.LegacyAdapter(supervisor);
91
+ import_server.AppSupervisor.registerDiscoveryAdapter("legacy", factory);
92
+ import_server.AppSupervisor.registerProcessAdapter("legacy", factory);
93
+ import_server.AppSupervisor.setDefaultDiscoveryAdapter("legacy");
94
+ import_server.AppSupervisor.setDefaultProcessAdapter("legacy");
95
+ }
152
96
  static getDatabaseConfig(app) {
153
97
  let oldConfig = app.options.database instanceof import_database.Database ? app.options.database.options : app.options.database;
154
98
  if (!oldConfig && app.db) {
@@ -156,39 +100,11 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
156
100
  }
157
101
  return import_lodash.default.cloneDeep(import_lodash.default.omit(oldConfig, ["migrator"]));
158
102
  }
159
- async handleSyncMessage(message) {
160
- const { type } = message;
161
- if (type === "subAppStarted") {
162
- const { appName } = message;
163
- const model = await this.app.db.getRepository("applications").findOne({
164
- filter: {
165
- name: appName
166
- }
167
- });
168
- if (!model) {
169
- return;
170
- }
171
- if (import_server.AppSupervisor.getInstance().hasApp(appName)) {
172
- return;
173
- }
174
- const subApp = model.registerToSupervisor(this.app, {
175
- appOptionsFactory: this.appOptionsFactory
176
- });
177
- subApp.runCommand("start", "--quickstart");
178
- }
179
- if (type === "removeApp") {
180
- const { appName } = message;
181
- await import_server.AppSupervisor.getInstance().removeApp(appName);
182
- }
183
- }
184
- setSubAppUpgradeHandler(handler) {
185
- this.subAppUpgradeHandler = handler;
103
+ setAppOptionsFactory(appOptionsFactory) {
104
+ import_server.AppSupervisor.getInstance().setAppOptionsFactory(appOptionsFactory);
186
105
  }
187
- setAppOptionsFactory(factory) {
188
- this.appOptionsFactory = factory;
189
- }
190
- setAppDbCreator(appDbCreator) {
191
- this.appDbCreator = appDbCreator;
106
+ static staticImport() {
107
+ this.registerLegacyAdapter();
192
108
  }
193
109
  beforeLoad() {
194
110
  this.db.registerModels({
@@ -200,8 +116,48 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
200
116
  throw new Error("@nocobase/plugin-multi-app-manager can only be enabled in the main app");
201
117
  }
202
118
  }
119
+ setMetrics() {
120
+ const supervisor = import_server.AppSupervisor.getInstance();
121
+ if (supervisor.getDiscoveryAdapter().name !== "legacy") {
122
+ return;
123
+ }
124
+ this.meter = this.app.telemetry.metric.getMeter();
125
+ if (!this.meter) {
126
+ return;
127
+ }
128
+ const subAppStatusGauge = this.meter.createObservableGauge("sub_app_status", {
129
+ description: "Number of sub applications by cached status in supervisor.appStatus"
130
+ });
131
+ this.meter.addBatchObservableCallback(
132
+ (observableResult) => {
133
+ const allStatuses = { ...supervisor.appStatus };
134
+ const createCounts = () => ({
135
+ preparing: 0,
136
+ initializing: 0,
137
+ initialized: 0,
138
+ running: 0,
139
+ commanding: 0,
140
+ stopped: 0,
141
+ error: 0,
142
+ not_found: 0
143
+ });
144
+ const cachedCounts = createCounts();
145
+ for (let status of Object.values(allStatuses)) {
146
+ if (!status) {
147
+ status = "stopped";
148
+ }
149
+ if (cachedCounts[status] !== void 0) cachedCounts[status]++;
150
+ }
151
+ for (const [status, count] of Object.entries(cachedCounts)) {
152
+ observableResult.observe(subAppStatusGauge, count, { status });
153
+ }
154
+ },
155
+ [subAppStatusGauge]
156
+ );
157
+ }
203
158
  async load() {
204
- await this.importCollections(import_path.default.resolve(__dirname, "collections"));
159
+ const supervisor = import_server.AppSupervisor.getInstance();
160
+ this.setMetrics();
205
161
  this.db.on(
206
162
  "applications.afterCreateWithAssociations",
207
163
  async (model, options) => {
@@ -211,82 +167,37 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
211
167
  if (name === "main") {
212
168
  throw new Error('Application name "main" is reserved');
213
169
  }
214
- const subApp = model.registerToSupervisor(this.app, {
215
- appOptionsFactory: this.appOptionsFactory
216
- });
217
- subApp.on("afterStart", async () => {
218
- this.sendSyncMessage({
219
- type: "subAppStarted",
220
- appName: name
221
- });
170
+ const subApp = supervisor.registerApp({
171
+ appModel: model,
172
+ mainApp: this.app
222
173
  });
223
174
  const quickstart = async () => {
224
- await this.appDbCreator(subApp, {
225
- transaction,
226
- applicationModel: model,
227
- context: options.context
228
- });
229
- await subApp.runCommand("start", "--quickstart");
175
+ try {
176
+ await supervisor.createDatabase({
177
+ app: subApp,
178
+ transaction,
179
+ appOptions: model.get("options") || {}
180
+ });
181
+ } catch (error) {
182
+ this.log.error(error, { method: "appDbCreator" });
183
+ await supervisor.setAppStatus(subApp.name, "error");
184
+ return;
185
+ }
186
+ await supervisor.getApp(subApp.name);
230
187
  };
231
- const startPromise = quickstart();
232
188
  if ((_a = options == null ? void 0 : options.context) == null ? void 0 : _a.waitSubAppInstall) {
233
- await startPromise;
189
+ await quickstart();
190
+ await subApp.runCommand("start", "--quickstart");
191
+ } else {
192
+ quickstart().catch((err) => {
193
+ this.log.error(err);
194
+ });
234
195
  }
235
196
  }
236
197
  );
237
- this.db.on("applications.afterDestroy", async (model, options) => {
238
- await import_server.AppSupervisor.getInstance().removeApp(model.get("name"));
239
- this.sendSyncMessage(
240
- {
241
- type: "removeApp",
242
- appName: model.get("name")
243
- },
244
- {
245
- transaction: options.transaction
246
- }
247
- );
198
+ this.db.on("applications.afterDestroy", async (model) => {
199
+ await supervisor.removeApp(model.get("name"));
248
200
  });
249
- const self = this;
250
- async function LazyLoadApplication({
251
- appSupervisor,
252
- appName,
253
- options
254
- }) {
255
- const loadButNotStart = options == null ? void 0 : options.upgrading;
256
- const name = appName;
257
- if (appSupervisor.hasApp(name)) {
258
- return;
259
- }
260
- const mainApp = await appSupervisor.getApp("main");
261
- const applicationRecord = await mainApp.db.getRepository("applications").findOne({
262
- filter: {
263
- name
264
- }
265
- });
266
- if (!applicationRecord) {
267
- return;
268
- }
269
- const instanceOptions = applicationRecord.get("options");
270
- if ((instanceOptions == null ? void 0 : instanceOptions.standaloneDeployment) && appSupervisor.runningMode !== "single") {
271
- return;
272
- }
273
- if (!applicationRecord) {
274
- return;
275
- }
276
- const subApp = applicationRecord.registerToSupervisor(mainApp, {
277
- appOptionsFactory: self.appOptionsFactory
278
- });
279
- subApp.on("afterStart", async () => {
280
- this.sendSyncMessage({
281
- type: "subAppStarted",
282
- appName: name
283
- });
284
- });
285
- if (!loadButNotStart) {
286
- await subApp.runCommand("start", "--quickstart");
287
- }
288
- }
289
- import_server.AppSupervisor.getInstance().setAppBootstrapper(LazyLoadApplication.bind(this));
290
201
  import_server.Gateway.getInstance().addAppSelectorMiddleware(async (ctx, next) => {
291
202
  const { req } = ctx;
292
203
  if (!ctx.resolvedAppName && req.headers["x-hostname"]) {
@@ -308,12 +219,12 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
308
219
  });
309
220
  this.app.on("afterStart", async (app) => {
310
221
  const repository = this.db.getRepository("applications");
311
- const appSupervisor = import_server.AppSupervisor.getInstance();
222
+ const appSupervisor = supervisor;
312
223
  this.app.setMaintainingMessage("starting sub applications...");
313
224
  if (appSupervisor.runningMode == "single") {
314
225
  import_server.Gateway.getInstance().addAppSelectorMiddleware((ctx) => ctx.resolvedAppName = appSupervisor.singleAppName);
315
226
  try {
316
- await import_server.AppSupervisor.getInstance().getApp(appSupervisor.singleAppName);
227
+ await supervisor.getApp(appSupervisor.singleAppName);
317
228
  } catch (err) {
318
229
  console.error("Auto register sub application in single mode failed: ", appSupervisor.singleAppName, err);
319
230
  }
@@ -325,21 +236,11 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
325
236
  "options.autoStart": true
326
237
  }
327
238
  });
328
- const promises = [];
329
239
  for (const subAppInstance of subApps) {
330
- promises.push(
331
- (async () => {
332
- if (!appSupervisor.hasApp(subAppInstance.name)) {
333
- await import_server.AppSupervisor.getInstance().getApp(subAppInstance.name);
334
- } else if (appSupervisor.getAppStatus(subAppInstance.name) === "initialized") {
335
- (await import_server.AppSupervisor.getInstance().getApp(subAppInstance.name)).runCommand("start", "--quickstart");
336
- }
337
- })()
338
- );
240
+ supervisor.getApp(subAppInstance.name);
339
241
  }
340
- await Promise.all(promises);
341
242
  } catch (err) {
342
- console.error("Auto register sub applications failed: ", err);
243
+ this.log.error("Auto register sub applications failed: ", err);
343
244
  }
344
245
  });
345
246
  this.app.on("afterUpgrade", async (app, options) => {
@@ -353,6 +254,29 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
353
254
  }
354
255
  });
355
256
  ctx.body = items;
257
+ await next();
258
+ }
259
+ });
260
+ this.app.resourcer.registerActionHandlers({
261
+ "applications:stop": async (ctx, next) => {
262
+ const { filterByTk } = ctx.action.params;
263
+ supervisor.stopApp(filterByTk);
264
+ ctx.body = "ok";
265
+ await next();
266
+ }
267
+ });
268
+ this.app.resourcer.registerActionHandlers({
269
+ "applications:start": async (ctx, next) => {
270
+ const { filterByTk } = ctx.action.params;
271
+ supervisor.startApp(filterByTk);
272
+ ctx.body = "ok";
273
+ await next();
274
+ }
275
+ });
276
+ this.app.resourcer.registerActionHandlers({
277
+ "applications:memoryUsage": async (ctx, next) => {
278
+ ctx.body = process.memoryUsage();
279
+ await next();
356
280
  }
357
281
  });
358
282
  this.app.acl.allow("applications", "listPinned", "loggedIn");
@@ -366,7 +290,7 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
366
290
  if (actionName === "list" && resourceName === "applications") {
367
291
  const applications = ctx.body.rows;
368
292
  for (const application of applications) {
369
- const appStatus = import_server.AppSupervisor.getInstance().getAppStatus(application.name, "stopped");
293
+ const appStatus = await supervisor.getAppStatus(application.name, "stopped");
370
294
  application.status = appStatus;
371
295
  }
372
296
  }
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-multi-app-manager",
3
3
  "displayName": "Multi-app manager (deprecated)",
4
+ "displayName.ru-RU": "Менеджер мульти-приложений",
4
5
  "displayName.zh-CN": "多应用管理器(已废弃)",
5
6
  "description": "Multi-app runs applications in a process-sharing manner, suitable for testing and demo environments only. Do not use it in production.",
7
+ "description.ru-RU": "Позволяет динамически создавать несколько приложений без отдельных развертываний.",
6
8
  "description.zh-CN": "多应用以进程共享的方式运行,仅适合测试和演示环境,生产环境下请勿使用。",
7
- "version": "2.0.0-alpha.7",
9
+ "version": "2.0.0-alpha.71",
8
10
  "license": "AGPL-3.0",
9
11
  "main": "./dist/server/index.js",
10
12
  "homepage": "https://docs.nocobase.com/handbook/multi-app-manager",
13
+ "homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/multi-app-manager",
11
14
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/multi-app-manager",
12
15
  "devDependencies": {
13
16
  "@formily/react": "2.x",
@@ -28,7 +31,7 @@
28
31
  "@nocobase/test": "2.x",
29
32
  "@nocobase/utils": "2.x"
30
33
  },
31
- "gitHead": "cb012f93256f534472d3ae56e075839ca1675779",
34
+ "gitHead": "b6fc484eb698fa12fba02dd468a04e39079b1e79",
32
35
  "keywords": [
33
36
  "system"
34
37
  ]
@@ -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
-
10
- "use strict";(self.webpackChunk_nocobase_plugin_multi_app_manager=self.webpackChunk_nocobase_plugin_multi_app_manager||[]).push([["959"],{931:function(e,n,t){t.r(n),t.d(n,{AppManager:function(){return g}});var a=t(772),c=t(721),r=t(156),o=t.n(r),u=t(570),i=t(785),p=t(875),l=function(e){var n=e.value,t=e.onChange,a=(0,i.g)().t;return o().createElement(c.Checkbox,{onChange:function(e){e.target.checked?t("".concat((0,p.uid)()).concat((0,p.uid)()).concat((0,p.uid)()).concat((0,p.uid)())):t("")},checked:!!n},a("Automatically generate a JWT secret"))},m=function(){var e=(0,a.useRecord)(),n=(0,a.useApp)();return e.cname?"//".concat(e.cname):n.getRouteUrl("/apps/".concat(e.name,"/admin/"))},s=function(){var e=(0,i.g)().t,n=m();return o().createElement("a",{href:n,target:"_blank",rel:"noreferrer"},e("View",{ns:"client"}))},g=function(){return o().createElement(c.Card,{bordered:!1},o().createElement(a.SchemaComponent,{schema:u.fK,components:{AppVisitor:s,JwtSecretInput:l}}))}}}]);