@nocobase/plugin-multi-app-manager 2.1.0-alpha.1 → 2.1.0-alpha.11

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 (146) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -10
  3. package/dist/client/Migrate.d.ts +10 -0
  4. package/dist/client/e9551d3b66931c0a.js +10 -0
  5. package/dist/client/index.js +1 -1
  6. package/dist/externalVersion.js +7 -7
  7. package/dist/locale/en-US.json +3 -2
  8. package/dist/locale/zh-CN.json +3 -2
  9. package/dist/node_modules/p-queue/dist/index.d.ts +101 -0
  10. package/dist/node_modules/p-queue/dist/index.js +1 -0
  11. package/dist/node_modules/p-queue/dist/lower-bound.d.ts +1 -0
  12. package/dist/node_modules/p-queue/dist/lower-bound.js +21 -0
  13. package/dist/node_modules/p-queue/dist/options.d.ts +64 -0
  14. package/dist/node_modules/p-queue/dist/options.js +2 -0
  15. package/dist/node_modules/p-queue/dist/priority-queue.d.ts +12 -0
  16. package/dist/node_modules/p-queue/dist/priority-queue.js +32 -0
  17. package/dist/node_modules/p-queue/dist/queue.d.ts +7 -0
  18. package/dist/node_modules/p-queue/dist/queue.js +2 -0
  19. package/dist/node_modules/p-queue/license +9 -0
  20. package/dist/node_modules/p-queue/node_modules/eventemitter3/index.d.ts +134 -0
  21. package/dist/node_modules/p-queue/node_modules/eventemitter3/index.js +336 -0
  22. package/dist/node_modules/p-queue/node_modules/eventemitter3/package.json +56 -0
  23. package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.js +340 -0
  24. package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.min.js +1 -0
  25. package/dist/node_modules/p-queue/package.json +1 -0
  26. package/dist/server/adapters/legacy-adapter.d.ts +43 -0
  27. package/dist/server/adapters/legacy-adapter.js +207 -0
  28. package/dist/server/server.d.ts +4 -6
  29. package/dist/server/server.js +38 -191
  30. package/package.json +3 -3
  31. package/dist/client/db3a142b120d6553.js +0 -10
  32. package/dist/node_modules/mariadb/LICENSE +0 -502
  33. package/dist/node_modules/mariadb/callback.js +0 -41
  34. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +0 -278
  35. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  36. package/dist/node_modules/mariadb/lib/cmd/change-user.js +0 -149
  37. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +0 -17
  38. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +0 -102
  39. package/dist/node_modules/mariadb/lib/cmd/command.js +0 -168
  40. package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +0 -327
  41. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +0 -168
  43. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +0 -23
  44. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +0 -761
  45. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +0 -55
  46. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +0 -58
  47. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +0 -19
  48. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +0 -142
  49. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +0 -74
  50. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  51. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  52. package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +0 -74
  53. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +0 -29
  54. package/dist/node_modules/mariadb/lib/cmd/ping.js +0 -52
  55. package/dist/node_modules/mariadb/lib/cmd/query.js +0 -255
  56. package/dist/node_modules/mariadb/lib/cmd/quit.js +0 -28
  57. package/dist/node_modules/mariadb/lib/cmd/reset.js +0 -54
  58. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  59. package/dist/node_modules/mariadb/lib/cmd/stream.js +0 -45
  60. package/dist/node_modules/mariadb/lib/config/connection-options.js +0 -258
  61. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  62. package/dist/node_modules/mariadb/lib/config/pool-options.js +0 -47
  63. package/dist/node_modules/mariadb/lib/connection-callback.js +0 -160
  64. package/dist/node_modules/mariadb/lib/connection.js +0 -1460
  65. package/dist/node_modules/mariadb/lib/const/capabilities.js +0 -64
  66. package/dist/node_modules/mariadb/lib/const/collations.js +0 -473
  67. package/dist/node_modules/mariadb/lib/const/connection_status.js +0 -13
  68. package/dist/node_modules/mariadb/lib/const/error-code.js +0 -1282
  69. package/dist/node_modules/mariadb/lib/const/field-detail.js +0 -35
  70. package/dist/node_modules/mariadb/lib/const/field-type.js +0 -71
  71. package/dist/node_modules/mariadb/lib/const/server-status.js +0 -30
  72. package/dist/node_modules/mariadb/lib/const/state-change.js +0 -12
  73. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  74. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  75. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +0 -141
  76. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +0 -171
  77. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +0 -193
  78. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +0 -36
  79. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +0 -37
  80. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +0 -502
  81. package/dist/node_modules/mariadb/lib/io/packet.js +0 -515
  82. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  83. package/dist/node_modules/mariadb/lib/misc/connection-information.js +0 -96
  84. package/dist/node_modules/mariadb/lib/misc/errors.js +0 -123
  85. package/dist/node_modules/mariadb/lib/misc/parse.js +0 -1033
  86. package/dist/node_modules/mariadb/lib/misc/utils.js +0 -298
  87. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  88. package/dist/node_modules/mariadb/lib/pool-callback.js +0 -202
  89. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  90. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
  91. package/dist/node_modules/mariadb/lib/pool-promise.js +0 -108
  92. package/dist/node_modules/mariadb/node_modules/@types/node/assert/strict.d.ts +0 -8
  93. package/dist/node_modules/mariadb/node_modules/@types/node/assert.d.ts +0 -912
  94. package/dist/node_modules/mariadb/node_modules/@types/node/async_hooks.d.ts +0 -501
  95. package/dist/node_modules/mariadb/node_modules/@types/node/buffer.d.ts +0 -2232
  96. package/dist/node_modules/mariadb/node_modules/@types/node/child_process.d.ts +0 -1366
  97. package/dist/node_modules/mariadb/node_modules/@types/node/cluster.d.ts +0 -414
  98. package/dist/node_modules/mariadb/node_modules/@types/node/console.d.ts +0 -412
  99. package/dist/node_modules/mariadb/node_modules/@types/node/constants.d.ts +0 -18
  100. package/dist/node_modules/mariadb/node_modules/@types/node/crypto.d.ts +0 -3338
  101. package/dist/node_modules/mariadb/node_modules/@types/node/dgram.d.ts +0 -545
  102. package/dist/node_modules/mariadb/node_modules/@types/node/diagnostics_channel.d.ts +0 -152
  103. package/dist/node_modules/mariadb/node_modules/@types/node/dns/promises.d.ts +0 -370
  104. package/dist/node_modules/mariadb/node_modules/@types/node/dns.d.ts +0 -659
  105. package/dist/node_modules/mariadb/node_modules/@types/node/domain.d.ts +0 -169
  106. package/dist/node_modules/mariadb/node_modules/@types/node/events.d.ts +0 -651
  107. package/dist/node_modules/mariadb/node_modules/@types/node/fs/promises.d.ts +0 -1091
  108. package/dist/node_modules/mariadb/node_modules/@types/node/fs.d.ts +0 -3869
  109. package/dist/node_modules/mariadb/node_modules/@types/node/globals.d.ts +0 -294
  110. package/dist/node_modules/mariadb/node_modules/@types/node/globals.global.d.ts +0 -1
  111. package/dist/node_modules/mariadb/node_modules/@types/node/http.d.ts +0 -1396
  112. package/dist/node_modules/mariadb/node_modules/@types/node/http2.d.ts +0 -2101
  113. package/dist/node_modules/mariadb/node_modules/@types/node/https.d.ts +0 -391
  114. package/dist/node_modules/mariadb/node_modules/@types/node/index.d.ts +0 -129
  115. package/dist/node_modules/mariadb/node_modules/@types/node/inspector.d.ts +0 -2744
  116. package/dist/node_modules/mariadb/node_modules/@types/node/module.d.ts +0 -114
  117. package/dist/node_modules/mariadb/node_modules/@types/node/net.d.ts +0 -791
  118. package/dist/node_modules/mariadb/node_modules/@types/node/os.d.ts +0 -455
  119. package/dist/node_modules/mariadb/node_modules/@types/node/package.json +0 -220
  120. package/dist/node_modules/mariadb/node_modules/@types/node/path.d.ts +0 -180
  121. package/dist/node_modules/mariadb/node_modules/@types/node/perf_hooks.d.ts +0 -557
  122. package/dist/node_modules/mariadb/node_modules/@types/node/process.d.ts +0 -1481
  123. package/dist/node_modules/mariadb/node_modules/@types/node/punycode.d.ts +0 -117
  124. package/dist/node_modules/mariadb/node_modules/@types/node/querystring.d.ts +0 -131
  125. package/dist/node_modules/mariadb/node_modules/@types/node/readline.d.ts +0 -650
  126. package/dist/node_modules/mariadb/node_modules/@types/node/repl.d.ts +0 -424
  127. package/dist/node_modules/mariadb/node_modules/@types/node/stream/consumers.d.ts +0 -24
  128. package/dist/node_modules/mariadb/node_modules/@types/node/stream/promises.d.ts +0 -42
  129. package/dist/node_modules/mariadb/node_modules/@types/node/stream/web.d.ts +0 -330
  130. package/dist/node_modules/mariadb/node_modules/@types/node/stream.d.ts +0 -1249
  131. package/dist/node_modules/mariadb/node_modules/@types/node/string_decoder.d.ts +0 -67
  132. package/dist/node_modules/mariadb/node_modules/@types/node/timers/promises.d.ts +0 -68
  133. package/dist/node_modules/mariadb/node_modules/@types/node/timers.d.ts +0 -94
  134. package/dist/node_modules/mariadb/node_modules/@types/node/tls.d.ts +0 -1020
  135. package/dist/node_modules/mariadb/node_modules/@types/node/trace_events.d.ts +0 -161
  136. package/dist/node_modules/mariadb/node_modules/@types/node/tty.d.ts +0 -204
  137. package/dist/node_modules/mariadb/node_modules/@types/node/url.d.ts +0 -891
  138. package/dist/node_modules/mariadb/node_modules/@types/node/util.d.ts +0 -1594
  139. package/dist/node_modules/mariadb/node_modules/@types/node/v8.d.ts +0 -378
  140. package/dist/node_modules/mariadb/node_modules/@types/node/vm.d.ts +0 -507
  141. package/dist/node_modules/mariadb/node_modules/@types/node/wasi.d.ts +0 -158
  142. package/dist/node_modules/mariadb/node_modules/@types/node/worker_threads.d.ts +0 -649
  143. package/dist/node_modules/mariadb/node_modules/@types/node/zlib.d.ts +0 -517
  144. package/dist/node_modules/mariadb/package.json +0 -1
  145. package/dist/node_modules/mariadb/promise.js +0 -34
  146. 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,77 +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
- logger: mainApp.options.logger
147
- };
148
- };
149
83
  class PluginMultiAppManagerServer extends import_server.Plugin {
150
- appDbCreator = defaultDbCreator;
151
- appOptionsFactory = defaultAppOptionsFactory;
152
84
  subAppUpgradeHandler = defaultSubAppUpgradeHandle;
153
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
+ }
154
96
  static getDatabaseConfig(app) {
155
97
  let oldConfig = app.options.database instanceof import_database.Database ? app.options.database.options : app.options.database;
156
98
  if (!oldConfig && app.db) {
@@ -158,43 +100,11 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
158
100
  }
159
101
  return import_lodash.default.cloneDeep(import_lodash.default.omit(oldConfig, ["migrator"]));
160
102
  }
161
- async handleSyncMessage(message) {
162
- const { type } = message;
163
- if (type === "subAppStarted") {
164
- const { appName } = message;
165
- const model = await this.app.db.getRepository("applications").findOne({
166
- filter: {
167
- name: appName
168
- }
169
- });
170
- if (!model) {
171
- return;
172
- }
173
- if (import_server.AppSupervisor.getInstance().hasApp(appName)) {
174
- return;
175
- }
176
- const subApp = model.registerToSupervisor(this.app, {
177
- appOptionsFactory: this.appOptionsFactory
178
- });
179
- subApp.runCommand("start", "--quickstart");
180
- }
181
- if (type === "subAppStopped") {
182
- const { appName } = message;
183
- await import_server.AppSupervisor.getInstance().stopApp(appName);
184
- }
185
- if (type === "removeApp") {
186
- const { appName } = message;
187
- await import_server.AppSupervisor.getInstance().removeApp(appName);
188
- }
189
- }
190
- setSubAppUpgradeHandler(handler) {
191
- this.subAppUpgradeHandler = handler;
192
- }
193
- setAppOptionsFactory(factory) {
194
- this.appOptionsFactory = factory;
103
+ setAppOptionsFactory(appOptionsFactory) {
104
+ import_server.AppSupervisor.getInstance().setAppOptionsFactory(appOptionsFactory);
195
105
  }
196
- setAppDbCreator(appDbCreator) {
197
- this.appDbCreator = appDbCreator;
106
+ static staticImport() {
107
+ this.registerLegacyAdapter();
198
108
  }
199
109
  beforeLoad() {
200
110
  this.db.registerModels({
@@ -207,6 +117,10 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
207
117
  }
208
118
  }
209
119
  setMetrics() {
120
+ const supervisor = import_server.AppSupervisor.getInstance();
121
+ if (supervisor.getDiscoveryAdapter().name !== "legacy") {
122
+ return;
123
+ }
210
124
  this.meter = this.app.telemetry.metric.getMeter();
211
125
  if (!this.meter) {
212
126
  return;
@@ -216,7 +130,6 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
216
130
  });
217
131
  this.meter.addBatchObservableCallback(
218
132
  (observableResult) => {
219
- const supervisor = import_server.AppSupervisor.getInstance();
220
133
  const allStatuses = { ...supervisor.appStatus };
221
134
  const createCounts = () => ({
222
135
  preparing: 0,
@@ -243,6 +156,7 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
243
156
  );
244
157
  }
245
158
  async load() {
159
+ const supervisor = import_server.AppSupervisor.getInstance();
246
160
  this.setMetrics();
247
161
  this.db.on(
248
162
  "applications.afterCreateWithAssociations",
@@ -253,34 +167,23 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
253
167
  if (name === "main") {
254
168
  throw new Error('Application name "main" is reserved');
255
169
  }
256
- const subApp = model.registerToSupervisor(this.app, {
257
- appOptionsFactory: this.appOptionsFactory
258
- });
259
- subApp.on("afterStart", async () => {
260
- this.sendSyncMessage({
261
- type: "subAppStarted",
262
- appName: name
263
- });
264
- });
265
- subApp.on("afterStop", async () => {
266
- this.sendSyncMessage({
267
- type: "subAppStopped",
268
- appName: name
269
- });
170
+ const subApp = supervisor.registerApp({
171
+ appModel: model,
172
+ mainApp: this.app
270
173
  });
271
174
  const quickstart = async () => {
272
175
  try {
273
- await this.appDbCreator(subApp, {
176
+ await supervisor.createDatabase({
177
+ app: subApp,
274
178
  transaction,
275
- applicationModel: model,
276
- context: options.context
179
+ appOptions: model.get("options") || {}
277
180
  });
278
181
  } catch (error) {
279
182
  this.log.error(error, { method: "appDbCreator" });
280
- import_server.AppSupervisor.getInstance().setAppStatus(subApp.name, "error");
183
+ await supervisor.setAppStatus(subApp.name, "error");
281
184
  return;
282
185
  }
283
- await import_server.AppSupervisor.getInstance().getApp(subApp.name);
186
+ await supervisor.getApp(subApp.name);
284
187
  };
285
188
  if ((_a = options == null ? void 0 : options.context) == null ? void 0 : _a.waitSubAppInstall) {
286
189
  await quickstart();
@@ -292,65 +195,9 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
292
195
  }
293
196
  }
294
197
  );
295
- this.db.on("applications.afterDestroy", async (model, options) => {
296
- await import_server.AppSupervisor.getInstance().removeApp(model.get("name"));
297
- this.sendSyncMessage(
298
- {
299
- type: "removeApp",
300
- appName: model.get("name")
301
- },
302
- {
303
- transaction: options.transaction
304
- }
305
- );
198
+ this.db.on("applications.afterDestroy", async (model) => {
199
+ await supervisor.removeApp(model.get("name"));
306
200
  });
307
- const self = this;
308
- async function LazyLoadApplication({
309
- appSupervisor,
310
- appName,
311
- options
312
- }) {
313
- const loadButNotStart = options == null ? void 0 : options.upgrading;
314
- const name = appName;
315
- if (appSupervisor.hasApp(name)) {
316
- return;
317
- }
318
- const mainApp = await appSupervisor.getApp("main");
319
- if (!mainApp) {
320
- return;
321
- }
322
- const applicationRecord = await mainApp.db.getRepository("applications").findOne({
323
- filter: {
324
- name
325
- }
326
- });
327
- if (!applicationRecord) {
328
- return;
329
- }
330
- const instanceOptions = applicationRecord.get("options");
331
- if ((instanceOptions == null ? void 0 : instanceOptions.standaloneDeployment) && appSupervisor.runningMode !== "single") {
332
- return;
333
- }
334
- const subApp = applicationRecord.registerToSupervisor(mainApp, {
335
- appOptionsFactory: self.appOptionsFactory
336
- });
337
- subApp.on("afterStart", async () => {
338
- this.sendSyncMessage({
339
- type: "subAppStarted",
340
- appName: name
341
- });
342
- });
343
- subApp.on("afterStop", async () => {
344
- this.sendSyncMessage({
345
- type: "subAppStopped",
346
- appName: name
347
- });
348
- });
349
- if (!loadButNotStart) {
350
- await subApp.runCommand("start", "--quickstart");
351
- }
352
- }
353
- import_server.AppSupervisor.getInstance().setAppBootstrapper(LazyLoadApplication.bind(this));
354
201
  import_server.Gateway.getInstance().addAppSelectorMiddleware(async (ctx, next) => {
355
202
  const { req } = ctx;
356
203
  if (!ctx.resolvedAppName && req.headers["x-hostname"]) {
@@ -372,12 +219,12 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
372
219
  });
373
220
  this.app.on("afterStart", async (app) => {
374
221
  const repository = this.db.getRepository("applications");
375
- const appSupervisor = import_server.AppSupervisor.getInstance();
222
+ const appSupervisor = supervisor;
376
223
  this.app.setMaintainingMessage("starting sub applications...");
377
224
  if (appSupervisor.runningMode == "single") {
378
225
  import_server.Gateway.getInstance().addAppSelectorMiddleware((ctx) => ctx.resolvedAppName = appSupervisor.singleAppName);
379
226
  try {
380
- await import_server.AppSupervisor.getInstance().getApp(appSupervisor.singleAppName);
227
+ await supervisor.getApp(appSupervisor.singleAppName);
381
228
  } catch (err) {
382
229
  console.error("Auto register sub application in single mode failed: ", appSupervisor.singleAppName, err);
383
230
  }
@@ -390,7 +237,7 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
390
237
  }
391
238
  });
392
239
  for (const subAppInstance of subApps) {
393
- import_server.AppSupervisor.getInstance().getApp(subAppInstance.name);
240
+ supervisor.getApp(subAppInstance.name);
394
241
  }
395
242
  } catch (err) {
396
243
  this.log.error("Auto register sub applications failed: ", err);
@@ -413,7 +260,7 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
413
260
  this.app.resourcer.registerActionHandlers({
414
261
  "applications:stop": async (ctx, next) => {
415
262
  const { filterByTk } = ctx.action.params;
416
- import_server.AppSupervisor.getInstance().stopApp(filterByTk);
263
+ supervisor.stopApp(filterByTk);
417
264
  ctx.body = "ok";
418
265
  await next();
419
266
  }
@@ -421,7 +268,7 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
421
268
  this.app.resourcer.registerActionHandlers({
422
269
  "applications:start": async (ctx, next) => {
423
270
  const { filterByTk } = ctx.action.params;
424
- import_server.AppSupervisor.getInstance().startApp(filterByTk);
271
+ supervisor.startApp(filterByTk);
425
272
  ctx.body = "ok";
426
273
  await next();
427
274
  }
@@ -443,7 +290,7 @@ class PluginMultiAppManagerServer extends import_server.Plugin {
443
290
  if (actionName === "list" && resourceName === "applications") {
444
291
  const applications = ctx.body.rows;
445
292
  for (const application of applications) {
446
- const appStatus = import_server.AppSupervisor.getInstance().getAppStatus(application.name, "stopped");
293
+ const appStatus = await supervisor.getAppStatus(application.name, "stopped");
447
294
  application.status = appStatus;
448
295
  }
449
296
  }
package/package.json CHANGED
@@ -6,8 +6,8 @@
6
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
7
  "description.ru-RU": "Позволяет динамически создавать несколько приложений без отдельных развертываний.",
8
8
  "description.zh-CN": "多应用以进程共享的方式运行,仅适合测试和演示环境,生产环境下请勿使用。",
9
- "version": "2.1.0-alpha.1",
10
- "license": "AGPL-3.0",
9
+ "version": "2.1.0-alpha.11",
10
+ "license": "Apache-2.0",
11
11
  "main": "./dist/server/index.js",
12
12
  "homepage": "https://docs.nocobase.com/handbook/multi-app-manager",
13
13
  "homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/multi-app-manager",
@@ -31,7 +31,7 @@
31
31
  "@nocobase/test": "2.x",
32
32
  "@nocobase/utils": "2.x"
33
33
  },
34
- "gitHead": "d27baf21569643d6fa83f882233f4e90eb5b89f1",
34
+ "gitHead": "bb96d633a6371afb586072ff516bd0613c757db0",
35
35
  "keywords": [
36
36
  "system"
37
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"],{7101:function(e,n,t){t.r(n),t.d(n,{AppManager:function(){return g}});var a=t(3772),c=t(2721),r=t(8156),o=t.n(r),u=t(9570),i=t(2785),p=t(8875),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:(0,u.J1)(),components:{AppVisitor:s,JwtSecretInput:l}}))}}}]);