@nocobase/server 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 (58) hide show
  1. package/lib/acl/available-action.js +1 -1
  2. package/lib/aes-encryptor.d.ts +1 -0
  3. package/lib/aes-encryptor.js +12 -5
  4. package/lib/app-command.d.ts +1 -0
  5. package/lib/app-command.js +3 -0
  6. package/lib/app-supervisor/app-options-factory.d.ts +80 -0
  7. package/lib/app-supervisor/app-options-factory.js +91 -0
  8. package/lib/app-supervisor/condition-registry.d.ts +18 -0
  9. package/lib/app-supervisor/condition-registry.js +60 -0
  10. package/lib/app-supervisor/db-creator.d.ts +16 -0
  11. package/lib/app-supervisor/db-creator.js +163 -0
  12. package/lib/app-supervisor/db-drivers.d.ts +11 -0
  13. package/lib/app-supervisor/db-drivers.js +52 -0
  14. package/lib/app-supervisor/index.d.ts +161 -0
  15. package/lib/app-supervisor/index.js +690 -0
  16. package/lib/app-supervisor/main-only-adapter.d.ts +37 -0
  17. package/lib/app-supervisor/main-only-adapter.js +156 -0
  18. package/lib/app-supervisor/types.d.ts +161 -0
  19. package/lib/app-supervisor/types.js +24 -0
  20. package/lib/application.d.ts +10 -7
  21. package/lib/application.js +30 -18
  22. package/lib/commands/index.js +2 -0
  23. package/lib/commands/pm.js +11 -0
  24. package/lib/commands/repair.d.ts +11 -0
  25. package/lib/commands/repair.js +43 -0
  26. package/lib/commands/start.js +1 -1
  27. package/lib/event-queue.d.ts +8 -1
  28. package/lib/event-queue.js +25 -22
  29. package/lib/gateway/errors.js +50 -12
  30. package/lib/gateway/index.d.ts +8 -0
  31. package/lib/gateway/index.js +80 -16
  32. package/lib/gateway/ipc-socket-server.js +1 -1
  33. package/lib/gateway/ws-server.js +6 -2
  34. package/lib/helper.d.ts +359 -0
  35. package/lib/helper.js +78 -3
  36. package/lib/index.d.ts +2 -1
  37. package/lib/index.js +6 -3
  38. package/lib/locale/locale.js +1 -1
  39. package/lib/locale/resource.js +6 -9
  40. package/lib/main-data-source.d.ts +11 -0
  41. package/lib/main-data-source.js +128 -0
  42. package/lib/middlewares/data-template.js +1 -6
  43. package/lib/middlewares/parse-variables.js +2 -49
  44. package/lib/plugin-manager/deps.js +2 -2
  45. package/lib/plugin-manager/options/resource.js +52 -25
  46. package/lib/plugin-manager/plugin-manager.d.ts +1 -0
  47. package/lib/plugin-manager/plugin-manager.js +36 -1
  48. package/lib/pub-sub-manager/pub-sub-manager.d.ts +1 -1
  49. package/lib/pub-sub-manager/pub-sub-manager.js +14 -20
  50. package/lib/redis-connection-manager.d.ts +15 -5
  51. package/lib/redis-connection-manager.js +117 -24
  52. package/lib/snowflake-id-field.d.ts +2 -1
  53. package/lib/snowflake-id-field.js +2 -2
  54. package/package.json +18 -17
  55. package/lib/app-supervisor.d.ts +0 -69
  56. package/lib/app-supervisor.js +0 -299
  57. package/lib/background-job-manager.d.ts +0 -40
  58. package/lib/background-job-manager.js +0 -111
@@ -0,0 +1,37 @@
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 Application from '../application';
10
+ import type { AppDiscoveryAdapter, AppProcessAdapter, AppStatus, GetAppOptions } from './types';
11
+ import type { AppSupervisor } from './index';
12
+ /** Minimal single-process adapter only for booting the main application. */
13
+ export declare class MainOnlyAdapter implements AppDiscoveryAdapter, AppProcessAdapter {
14
+ protected readonly supervisor: AppSupervisor;
15
+ readonly name: string;
16
+ app: Application;
17
+ status: AppStatus;
18
+ appErrors: Record<string, Error>;
19
+ constructor(supervisor: AppSupervisor);
20
+ getApp(appName: string, options?: GetAppOptions): Promise<Application<import("../application").DefaultState, import("../application").DefaultContext>>;
21
+ bootstrapApp(appName: string): Promise<void>;
22
+ addApp(app: Application): Application<import("../application").DefaultState, import("../application").DefaultContext>;
23
+ getApps(): Application<import("../application").DefaultState, import("../application").DefaultContext>[];
24
+ hasApp(appName: string): boolean;
25
+ startApp(appName: string): Promise<void>;
26
+ stopApp(appName: string): Promise<void>;
27
+ removeApp(appName: string): Promise<void>;
28
+ upgradeApp(appName: string): Promise<void>;
29
+ removeAllApps(): Promise<void>;
30
+ setAppStatus(appName: string, status: AppStatus, options?: {}): void;
31
+ getAppStatus(appName: string, defaultStatus?: AppStatus): AppStatus;
32
+ hasAppError(appName: string): boolean;
33
+ setAppError(appName: string, error: Error): void;
34
+ clearAppError(appName: string): void;
35
+ setAppLastSeenAt(): void;
36
+ getAppLastSeenAt(appName: string): any;
37
+ }
@@ -0,0 +1,156 @@
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 main_only_adapter_exports = {};
29
+ __export(main_only_adapter_exports, {
30
+ MainOnlyAdapter: () => MainOnlyAdapter
31
+ });
32
+ module.exports = __toCommonJS(main_only_adapter_exports);
33
+ const _MainOnlyAdapter = class _MainOnlyAdapter {
34
+ constructor(supervisor) {
35
+ this.supervisor = supervisor;
36
+ this.name = "main-only";
37
+ }
38
+ name;
39
+ app;
40
+ status;
41
+ appErrors = {};
42
+ async getApp(appName, options = {}) {
43
+ if (appName !== "main") {
44
+ this.supervisor.logger.warn(`only main app is supported`, { method: "getApp", appName });
45
+ return;
46
+ }
47
+ if (!options.withOutBootStrap) {
48
+ await this.bootstrapApp(appName);
49
+ }
50
+ return this.app;
51
+ }
52
+ async bootstrapApp(appName) {
53
+ if (appName !== "main" || !this.app) {
54
+ this.setAppStatus(appName, "not_found");
55
+ return;
56
+ }
57
+ const status = this.getAppStatus("main");
58
+ if (this.hasApp(appName) && status && status !== "preparing") {
59
+ return;
60
+ }
61
+ this.setAppStatus("main", "initializing");
62
+ this.setAppStatus("main", "initialized");
63
+ }
64
+ addApp(app) {
65
+ if (app.name !== "main") {
66
+ this.supervisor.logger.warn(`only main app is supported`, { method: "addApp" });
67
+ return;
68
+ }
69
+ if (this.app) {
70
+ throw new Error(`app ${app.name} already exists`);
71
+ }
72
+ this.app = app;
73
+ if (!this.status || this.status === "not_found") {
74
+ this.setAppStatus(app.name, "preparing");
75
+ }
76
+ return app;
77
+ }
78
+ getApps() {
79
+ return [this.app];
80
+ }
81
+ hasApp(appName) {
82
+ if (appName !== "main") {
83
+ return false;
84
+ }
85
+ return !!this.app;
86
+ }
87
+ async startApp(appName) {
88
+ if (appName !== "main") {
89
+ this.supervisor.logger.warn(`only main app is supported`, { method: "startApp" });
90
+ return;
91
+ }
92
+ const app = await this.getApp(appName, { withOutBootStrap: true });
93
+ await (app == null ? void 0 : app.runCommand("start", "--quickstart"));
94
+ }
95
+ async stopApp(appName) {
96
+ if (appName !== "main") {
97
+ this.supervisor.logger.warn(`only main app is supported`, { method: "stopApp" });
98
+ return;
99
+ }
100
+ await this.app.runCommand("stop");
101
+ }
102
+ async removeApp(appName) {
103
+ if (appName !== "main") {
104
+ this.supervisor.logger.warn(`only main app is supported`, { method: "removeApp" });
105
+ return;
106
+ }
107
+ if (!this.app) {
108
+ return;
109
+ }
110
+ await this.app.runCommand("destroy");
111
+ }
112
+ async upgradeApp(appName) {
113
+ if (appName !== "main") {
114
+ this.supervisor.logger.warn(`only main app is supported`, { method: "upgrade" });
115
+ return;
116
+ }
117
+ if (!this.app) {
118
+ return;
119
+ }
120
+ await this.app.runCommand("upgrade");
121
+ }
122
+ async removeAllApps() {
123
+ return this.removeApp("main");
124
+ }
125
+ setAppStatus(appName, status, options = {}) {
126
+ if (this.status === status) {
127
+ return;
128
+ }
129
+ this.status = status;
130
+ this.supervisor.emit("appStatusChanged", { appName, status, options });
131
+ }
132
+ getAppStatus(appName, defaultStatus) {
133
+ return this.status ?? defaultStatus ?? null;
134
+ }
135
+ hasAppError(appName) {
136
+ return !!this.appErrors[appName];
137
+ }
138
+ setAppError(appName, error) {
139
+ this.appErrors[appName] = error;
140
+ this.supervisor.emit("appError", { appName, error });
141
+ }
142
+ clearAppError(appName) {
143
+ this.appErrors[appName] = null;
144
+ }
145
+ setAppLastSeenAt() {
146
+ }
147
+ getAppLastSeenAt(appName) {
148
+ return null;
149
+ }
150
+ };
151
+ __name(_MainOnlyAdapter, "MainOnlyAdapter");
152
+ let MainOnlyAdapter = _MainOnlyAdapter;
153
+ // Annotate the CommonJS export names for ESM import in node:
154
+ 0 && (module.exports = {
155
+ MainOnlyAdapter
156
+ });
@@ -0,0 +1,161 @@
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
+ /// <reference types="node" />
11
+ import { IDatabaseOptions, Transaction, Transactionable } from '@nocobase/database';
12
+ import type Application from '../application';
13
+ import type { AppSupervisor } from './index';
14
+ import type { IncomingMessage, ServerResponse } from 'http';
15
+ /**
16
+ * Options accepted by discovery adapter when loading an application.
17
+ */
18
+ export type GetAppOptions = {
19
+ withOutBootStrap?: boolean;
20
+ [key: string]: any;
21
+ };
22
+ /**
23
+ * Parameters supplied to a bootstrapper when a sub-application is being started.
24
+ */
25
+ export type BootOptions = {
26
+ appName: string;
27
+ options: Record<string, any>;
28
+ appSupervisor: AppSupervisor;
29
+ };
30
+ /**
31
+ * Callback used by process adapters to lazily initialize applications.
32
+ */
33
+ export type AppBootstrapper = (bootOptions: BootOptions) => Promise<void>;
34
+ /**
35
+ * All supported lifecycle states of a managed application.
36
+ */
37
+ export type AppStatus = 'preparing' | 'initializing' | 'initialized' | 'running' | 'commanding' | 'stopped' | 'error' | 'not_found';
38
+ /**
39
+ * Metadata representing a deployable environment (container, pod, VM, etc.).
40
+ */
41
+ export type EnvironmentInfo = {
42
+ name: string;
43
+ url?: string;
44
+ proxyUrl?: string;
45
+ available?: boolean;
46
+ appVersion?: string;
47
+ lastHeartbeatAt?: number;
48
+ };
49
+ export type BootstrapLock = {
50
+ acquire: () => Promise<boolean>;
51
+ release: () => Promise<void>;
52
+ };
53
+ export type AppModelOptions = {
54
+ dbConnType?: 'new_database' | 'new_connection' | 'new_schema' | string;
55
+ database?: IDatabaseOptions;
56
+ [key: string]: any;
57
+ };
58
+ export type AppModel = {
59
+ name: string;
60
+ cname?: string;
61
+ environment?: string;
62
+ environments?: string[];
63
+ options: AppModelOptions;
64
+ };
65
+ export type ProcessCommand = {
66
+ requestId: string;
67
+ appName: string;
68
+ action: 'create' | 'start' | 'stop' | 'remove' | string;
69
+ environments: string[];
70
+ payload?: Record<string, any>;
71
+ };
72
+ export type AppDbCreatorOptions = Transactionable & {
73
+ app: Application;
74
+ appOptions: AppModelOptions;
75
+ };
76
+ export type AppDbCreator = (options: AppDbCreatorOptions) => Promise<void>;
77
+ export type AppOptionsFactory = (appName: string, mainApp: Application, options?: AppModelOptions) => any;
78
+ /**
79
+ * Abstraction for discovering applications across deployment environments.
80
+ */
81
+ export type AppStatusesResult = Record<string, AppStatus | Record<string, AppStatus> | null>;
82
+ export interface AppDiscoveryAdapter {
83
+ readonly name: string;
84
+ readonly environmentName?: string;
85
+ readonly environmentUrl?: string;
86
+ readonly environmentProxyUrl?: string;
87
+ readonly appStatus?: Record<string, AppStatus>;
88
+ readonly lastSeenAt?: Map<string, number>;
89
+ /**
90
+ * Update the "last seen at" timestamp for an application.
91
+ */
92
+ setAppLastSeenAt(appName: string): void | Promise<void>;
93
+ getAppLastSeenAt(appName: string): number | null | Promise<number | null>;
94
+ /**
95
+ * Read the cached lifecycle status for a given application.
96
+ */
97
+ getAppStatus(appName: string, defaultStatus?: AppStatus): Promise<AppStatus | null> | AppStatus | null;
98
+ /**
99
+ * Persist an application's lifecycle status back to the discovery backend.
100
+ */
101
+ setAppStatus(appName: string, status: AppStatus, options?: Record<string, any>): void | Promise<void>;
102
+ clearAppStatus?(appName: string): void | Promise<void>;
103
+ loadAppModels?(mainApp: Application): Promise<void>;
104
+ getAppsStatuses?(appNames?: string[]): Promise<AppStatusesResult> | AppStatusesResult;
105
+ addAutoStartApps?(environmentName: string, appName: string[]): Promise<void>;
106
+ getAutoStartApps?(environmentName: string): Promise<string[]>;
107
+ removeAutoStartApps?(environmentName: string, appNames: string[]): Promise<void>;
108
+ addAppModel?(appModel: AppModel): Promise<void>;
109
+ getAppModel?(appName: string): Promise<AppModel>;
110
+ removeAppModel?(appName: string): Promise<void>;
111
+ getAppNameByCName?(cname: string): Promise<string | null>;
112
+ registerEnvironment?(environment: EnvironmentInfo): Promise<boolean>;
113
+ unregisterEnvironment?(): Promise<void>;
114
+ listEnvironments?(): Promise<EnvironmentInfo[]>;
115
+ getEnvironment?(environmentName: string): Promise<EnvironmentInfo | null>;
116
+ heartbeatEnvironment?(): Promise<void>;
117
+ getBootstrapLock?(appName: string): Promise<BootstrapLock | null> | BootstrapLock | null;
118
+ proxyWeb?(appName: string, req: IncomingMessage, res: ServerResponse): Promise<boolean>;
119
+ proxyWs?(req: IncomingMessage, socket: any, head: Buffer): Promise<boolean>;
120
+ dispose?(): Promise<void>;
121
+ }
122
+ export interface AppProcessAdapter {
123
+ readonly name: string;
124
+ readonly apps?: Record<string, Application>;
125
+ readonly appErrors?: Record<string, Error>;
126
+ readonly lastMaintainingMessage?: Record<string, string>;
127
+ readonly statusBeforeCommanding?: Record<string, AppStatus>;
128
+ addApp(app: Application): void;
129
+ getApp(appName: string, options?: GetAppOptions): Promise<Application>;
130
+ hasApp(appName: string): boolean;
131
+ bootstrapApp(appName: string): Promise<void>;
132
+ getApps?(): Application[];
133
+ createApp?(options: {
134
+ appModel: AppModel;
135
+ mainApp?: Application;
136
+ transaction?: Transaction;
137
+ }, context?: {
138
+ requestId: string;
139
+ }): Promise<void>;
140
+ startApp?(appName: string, context?: {
141
+ requestId: string;
142
+ }): Promise<void>;
143
+ stopApp?(appName: string, context?: {
144
+ requestId: string;
145
+ }): Promise<void>;
146
+ removeApp?(appName: string, context?: {
147
+ requestId: string;
148
+ }): Promise<void>;
149
+ upgradeApp?(appName: string, context?: {
150
+ requestId: string;
151
+ }): Promise<void>;
152
+ removeAllApps?(): Promise<void>;
153
+ setAppError?(appName: string, error: Error): void;
154
+ hasAppError?(appName: string): boolean;
155
+ clearAppError?(appName: string): void;
156
+ }
157
+ export interface AppCommandAdapter {
158
+ dispatchCommand(command: ProcessCommand): Promise<void>;
159
+ registerCommandHandler(mainApp: Application): void;
160
+ dispose?(): Promise<void>;
161
+ }
@@ -0,0 +1,24 @@
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 __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var types_exports = {};
24
+ module.exports = __toCommonJS(types_exports);
@@ -34,10 +34,9 @@ import { SyncMessageManager } from './sync-message-manager';
34
34
  import AesEncryptor from './aes-encryptor';
35
35
  import { AuditManager } from './audit-manager';
36
36
  import { Environment } from './environment';
37
- import { ServiceContainer } from './service-container';
38
37
  import { EventQueue, EventQueueOptions } from './event-queue';
39
- import { BackgroundJobManager, BackgroundJobManagerOptions } from './background-job-manager';
40
38
  import { RedisConfig, RedisConnectionManager } from './redis-connection-manager';
39
+ import { ServiceContainer } from './service-container';
41
40
  import { WorkerIdAllocator } from './worker-id-allocator';
42
41
  export type PluginType = string | typeof Plugin;
43
42
  export type PluginConfiguration = PluginType | [PluginType, any];
@@ -89,7 +88,6 @@ export interface ApplicationOptions {
89
88
  auditManager?: AuditManager;
90
89
  lockManager?: LockManagerOptions;
91
90
  eventQueue?: EventQueueOptions;
92
- backgroundJobManager?: BackgroundJobManagerOptions;
93
91
  /**
94
92
  * @internal
95
93
  */
@@ -129,7 +127,12 @@ interface StartOptions {
129
127
  type MaintainingStatus = 'command_begin' | 'command_end' | 'command_running' | 'command_error';
130
128
  export type MaintainingCommandStatus = {
131
129
  command: {
130
+ components?: {
131
+ maintaining: string;
132
+ maintainingDialog: string;
133
+ };
132
134
  name: string;
135
+ [key: string]: any;
133
136
  };
134
137
  status: MaintainingStatus;
135
138
  error?: Error;
@@ -190,9 +193,9 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
190
193
  container: ServiceContainer;
191
194
  lockManager: LockManager;
192
195
  eventQueue: EventQueue;
193
- backgroundJobManager: BackgroundJobManager;
194
196
  constructor(options: ApplicationOptions);
195
197
  private static staticCommands;
198
+ static registerStaticCommand(callback: (app: Application) => void): void;
196
199
  static addCommand(callback: (app: Application) => void): void;
197
200
  private _sqlLogger;
198
201
  get instanceId(): number;
@@ -219,7 +222,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
219
222
  get environment(): Environment;
220
223
  protected _cronJobManager: CronJobManager;
221
224
  get cronJobManager(): CronJobManager;
222
- get mainDataSource(): SequelizeDataSource;
225
+ get mainDataSource(): SequelizeDataSource<import("@nocobase/data-source-manager").DatabaseIntrospector>;
223
226
  get db(): Database;
224
227
  get resourceManager(): import("@nocobase/resourcer").ResourceManager;
225
228
  /**
@@ -276,14 +279,14 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
276
279
  /**
277
280
  * @internal
278
281
  */
279
- setMaintaining(_maintainingCommandStatus: MaintainingCommandStatus): void;
282
+ setMaintaining(_maintainingCommandStatus: MaintainingCommandStatus): Promise<void>;
280
283
  /**
281
284
  * @internal
282
285
  */
283
286
  setMaintainingMessage(message: string): void;
284
287
  /**
285
288
  * This method is deprecated and should not be used.
286
- * Use {@link #this.version.get()} instead.
289
+ * Use {@link #this.getPackageVersion} instead.
287
290
  * @deprecated
288
291
  */
289
292
  getVersion(): string;
@@ -50,8 +50,8 @@ var import_database = __toESM(require("@nocobase/database"));
50
50
  var import_logger = require("@nocobase/logger");
51
51
  var import_telemetry = require("@nocobase/telemetry");
52
52
  var import_lock_manager = require("@nocobase/lock-manager");
53
- var import_utils = require("@nocobase/utils");
54
53
  var import_snowflake_id = require("@nocobase/snowflake-id");
54
+ var import_utils = require("@nocobase/utils");
55
55
  var import_crypto = require("crypto");
56
56
  var import_glob = __toESM(require("glob"));
57
57
  var import_koa = __toESM(require("koa"));
@@ -81,12 +81,11 @@ var import_available_action = require("./acl/available-action");
81
81
  var import_aes_encryptor = __toESM(require("./aes-encryptor"));
82
82
  var import_audit_manager = require("./audit-manager");
83
83
  var import_environment = require("./environment");
84
- var import_service_container = require("./service-container");
85
84
  var import_event_queue = require("./event-queue");
86
- var import_background_job_manager = require("./background-job-manager");
87
85
  var import_redis_connection_manager = require("./redis-connection-manager");
88
- var import_worker_id_allocator = require("./worker-id-allocator");
86
+ var import_service_container = require("./service-container");
89
87
  var import_snowflake_id_field = require("./snowflake-id-field");
88
+ var import_worker_id_allocator = require("./worker-id-allocator");
90
89
  const _Application = class _Application extends import_koa.default {
91
90
  constructor(options) {
92
91
  super();
@@ -142,7 +141,9 @@ const _Application = class _Application extends import_koa.default {
142
141
  container = new import_service_container.ServiceContainer();
143
142
  lockManager;
144
143
  eventQueue;
145
- backgroundJobManager;
144
+ static registerStaticCommand(callback) {
145
+ this.staticCommands.push(callback);
146
+ }
146
147
  static addCommand(callback) {
147
148
  this.staticCommands.push(callback);
148
149
  }
@@ -315,9 +316,9 @@ const _Application = class _Application extends import_koa.default {
315
316
  /**
316
317
  * @internal
317
318
  */
318
- setMaintaining(_maintainingCommandStatus) {
319
+ async setMaintaining(_maintainingCommandStatus) {
319
320
  this._maintainingCommandStatus = _maintainingCommandStatus;
320
- this.emit("maintaining", _maintainingCommandStatus);
321
+ await this.emitAsync("maintaining", _maintainingCommandStatus);
321
322
  if (_maintainingCommandStatus.status == "command_end") {
322
323
  this._maintaining = false;
323
324
  return;
@@ -336,7 +337,7 @@ const _Application = class _Application extends import_koa.default {
336
337
  }
337
338
  /**
338
339
  * This method is deprecated and should not be used.
339
- * Use {@link #this.version.get()} instead.
340
+ * Use {@link #this.getPackageVersion} instead.
340
341
  * @deprecated
341
342
  */
342
343
  getVersion() {
@@ -609,7 +610,7 @@ const _Application = class _Application extends import_koa.default {
609
610
  await this.pm.loadCommands();
610
611
  }
611
612
  const command = await this.cli.parseAsync(argv, options);
612
- this.setMaintaining({
613
+ await this.setMaintaining({
613
614
  status: "command_end",
614
615
  command: this.activatedCommand
615
616
  });
@@ -620,7 +621,7 @@ const _Application = class _Application extends import_koa.default {
620
621
  name: "unknown"
621
622
  };
622
623
  }
623
- this.setMaintaining({
624
+ await this.setMaintaining({
624
625
  status: "command_error",
625
626
  command: this.activatedCommand,
626
627
  error
@@ -777,6 +778,12 @@ const _Application = class _Application extends import_koa.default {
777
778
  }
778
779
  async upgrade(options = {}) {
779
780
  this.log.info("upgrading...");
781
+ const pkgVersion = this.getPackageVersion();
782
+ const appVersion = await this.version.get();
783
+ if (process.env.SKIP_SAME_VERSION_UPGRADE === "true" && pkgVersion === appVersion) {
784
+ this.log.info(`app is already the latest version (${appVersion})`);
785
+ return;
786
+ }
780
787
  await this.reInit();
781
788
  const migrator1 = await this.loadCoreMigrations();
782
789
  await migrator1.beforeLoad.up();
@@ -800,7 +807,9 @@ const _Application = class _Application extends import_koa.default {
800
807
  await migrator3.afterLoad.up();
801
808
  await this.pm.repository.updateVersions();
802
809
  await this.version.update();
803
- await this.emitAsync("afterUpgrade", this, options);
810
+ if (!options.quickstart) {
811
+ await this.emitAsync("afterUpgrade", this, options);
812
+ }
804
813
  await this.restart();
805
814
  }
806
815
  toJSON() {
@@ -834,11 +843,11 @@ const _Application = class _Application extends import_koa.default {
834
843
  this.activatedCommand = {
835
844
  name: (0, import_helper.getCommandFullName)(actionCommand)
836
845
  };
837
- this.setMaintaining({
846
+ await this.setMaintaining({
838
847
  status: "command_begin",
839
848
  command: this.activatedCommand
840
849
  });
841
- this.setMaintaining({
850
+ await this.setMaintaining({
842
851
  status: "command_running",
843
852
  command: this.activatedCommand
844
853
  });
@@ -911,7 +920,6 @@ const _Application = class _Application extends import_koa.default {
911
920
  this.pubSubManager = (0, import_pub_sub_manager.createPubSubManager)(this, options.pubSubManager);
912
921
  this.syncMessageManager = new import_sync_message_manager.SyncMessageManager(this, options.syncMessageManager);
913
922
  this.eventQueue = new import_event_queue.EventQueue(this, options.eventQueue);
914
- this.backgroundJobManager = new import_background_job_manager.BackgroundJobManager(this, options.backgroundJobManager);
915
923
  this.lockManager = new import_lock_manager.LockManager({
916
924
  defaultAdapter: process.env.LOCK_ADAPTER_DEFAULT,
917
925
  ...options.lockManager
@@ -927,8 +935,8 @@ const _Application = class _Application extends import_koa.default {
927
935
  plugins: plugins || []
928
936
  });
929
937
  this._telemetry = new import_telemetry.Telemetry({
930
- serviceName: `nocobase-${this.name}`,
931
- version: this.getVersion(),
938
+ appName: this.name,
939
+ version: this.getPackageVersion(),
932
940
  ...options.telemetry
933
941
  });
934
942
  this._authManager = new import_auth.AuthManager({
@@ -941,6 +949,11 @@ const _Application = class _Application extends import_koa.default {
941
949
  name: "auth",
942
950
  actions: import_auth.actions
943
951
  });
952
+ this._dataSourceManager.beforeAddDataSource((dataSource) => {
953
+ if (dataSource.collectionManager instanceof import_data_source_manager.SequelizeCollectionManager) {
954
+ (0, import_snowflake_id_field.setupSnowflakeIdField)(this, dataSource.collectionManager.db);
955
+ }
956
+ });
944
957
  this._dataSourceManager.afterAddDataSource((dataSource) => {
945
958
  if (dataSource.collectionManager instanceof import_data_source_manager.SequelizeCollectionManager) {
946
959
  for (const [actionName, actionParams] of Object.entries(import_available_action.availableActions)) {
@@ -948,7 +961,7 @@ const _Application = class _Application extends import_koa.default {
948
961
  }
949
962
  }
950
963
  });
951
- this._dataSourceManager.use(this._authManager.middleware(), { tag: "auth" });
964
+ this._dataSourceManager.use(this._authManager.middleware(), { tag: "auth", before: "default" });
952
965
  this._dataSourceManager.use(import_validate_filter_params.default, { tag: "validate-filter-params", before: ["auth"] });
953
966
  this._dataSourceManager.use(import_middlewares.parseVariables, {
954
967
  group: "parseVariables",
@@ -982,7 +995,6 @@ const _Application = class _Application extends import_koa.default {
982
995
  app: this
983
996
  });
984
997
  this.dataSourceManager.dataSources.set("main", mainDataSourceInstance);
985
- (0, import_snowflake_id_field.setupSnowflakeIdField)(this);
986
998
  }
987
999
  createDatabase(options) {
988
1000
  const logging = /* @__PURE__ */ __name((...args) => {
@@ -53,6 +53,7 @@ var import_start = __toESM(require("./start"));
53
53
  var import_stop = __toESM(require("./stop"));
54
54
  var import_upgrade = __toESM(require("./upgrade"));
55
55
  var import_console = __toESM(require("./console"));
56
+ var import_repair = __toESM(require("./repair"));
56
57
  /* istanbul ignore file -- @preserve */
57
58
  function registerCli(app) {
58
59
  (0, import_console.default)(app);
@@ -68,6 +69,7 @@ function registerCli(app) {
68
69
  (0, import_destroy.default)(app);
69
70
  (0, import_start.default)(app);
70
71
  (0, import_refresh.default)(app);
72
+ (0, import_repair.default)(app);
71
73
  app.command("build").argument("[packages...]");
72
74
  app.command("clean");
73
75
  app.command("dev").usage("[options]").option("-p, --port [port]").option("--client").option("--server");
@@ -38,6 +38,17 @@ var pm_default = /* @__PURE__ */ __name((app) => {
38
38
  pm.command("create").argument("plugin").option("--force-recreate").action(async (plugin, options) => {
39
39
  await app.pm.create(plugin, options);
40
40
  });
41
+ pm.command("pull").arguments("<packageNames...>").option("--registry [registry]").option("--auth-token [authToken]").option("--version [version]").action(async (packageNames, options, cli) => {
42
+ try {
43
+ let name = packageNames;
44
+ if (Array.isArray(packageNames) && packageNames.length === 1) {
45
+ name = packageNames[0];
46
+ }
47
+ await app.pm.pull(name, { ...options });
48
+ } catch (error) {
49
+ throw new import_plugin_command_error.PluginCommandError(`Failed to pull plugin`, { cause: error });
50
+ }
51
+ });
41
52
  pm.command("add").ipc().preload().arguments("<packageNames...>").option("--registry [registry]").option("--auth-token [authToken]").option("--version [version]").action(async (packageNames, options, cli) => {
42
53
  try {
43
54
  let name = packageNames;
@@ -0,0 +1,11 @@
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 Application from '../application';
10
+ declare const _default: (app: Application) => void;
11
+ export default _default;