@nocobase/server 1.9.0-beta.16 → 1.9.0-beta.17

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.
@@ -56,7 +56,7 @@ const availableActions = {
56
56
  update: {
57
57
  displayName: '{{t("Edit")}}',
58
58
  type: "old-data",
59
- aliases: ["update", "move", "add", "set", "remove", "toggle"],
59
+ aliases: ["update", "move"],
60
60
  allowConfigureFields: true
61
61
  },
62
62
  destroy: {
@@ -36,7 +36,6 @@ import { AuditManager } from './audit-manager';
36
36
  import { Environment } from './environment';
37
37
  import { ServiceContainer } from './service-container';
38
38
  import { EventQueue, EventQueueOptions } from './event-queue';
39
- import { BackgroundJobManager, BackgroundJobManagerOptions } from './background-job-manager';
40
39
  import { RedisConfig, RedisConnectionManager } from './redis-connection-manager';
41
40
  import { WorkerIdAllocator } from './worker-id-allocator';
42
41
  export type PluginType = string | typeof Plugin;
@@ -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
  */
@@ -190,7 +188,6 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
190
188
  container: ServiceContainer;
191
189
  lockManager: LockManager;
192
190
  eventQueue: EventQueue;
193
- backgroundJobManager: BackgroundJobManager;
194
191
  constructor(options: ApplicationOptions);
195
192
  private static staticCommands;
196
193
  static addCommand(callback: (app: Application) => void): void;
@@ -83,7 +83,6 @@ var import_audit_manager = require("./audit-manager");
83
83
  var import_environment = require("./environment");
84
84
  var import_service_container = require("./service-container");
85
85
  var import_event_queue = require("./event-queue");
86
- var import_background_job_manager = require("./background-job-manager");
87
86
  var import_redis_connection_manager = require("./redis-connection-manager");
88
87
  var import_worker_id_allocator = require("./worker-id-allocator");
89
88
  var import_snowflake_id_field = require("./snowflake-id-field");
@@ -142,7 +141,6 @@ const _Application = class _Application extends import_koa.default {
142
141
  container = new import_service_container.ServiceContainer();
143
142
  lockManager;
144
143
  eventQueue;
145
- backgroundJobManager;
146
144
  static addCommand(callback) {
147
145
  this.staticCommands.push(callback);
148
146
  }
@@ -911,7 +909,6 @@ const _Application = class _Application extends import_koa.default {
911
909
  this.pubSubManager = (0, import_pub_sub_manager.createPubSubManager)(this, options.pubSubManager);
912
910
  this.syncMessageManager = new import_sync_message_manager.SyncMessageManager(this, options.syncMessageManager);
913
911
  this.eventQueue = new import_event_queue.EventQueue(this, options.eventQueue);
914
- this.backgroundJobManager = new import_background_job_manager.BackgroundJobManager(this, options.backgroundJobManager);
915
912
  this.lockManager = new import_lock_manager.LockManager({
916
913
  defaultAdapter: process.env.LOCK_ADAPTER_DEFAULT,
917
914
  ...options.lockManager
@@ -300,13 +300,13 @@ const _EventQueue = class _EventQueue {
300
300
  return this.adapter.isConnected();
301
301
  }
302
302
  async connect() {
303
- if (!this.adapter) {
304
- throw new Error("no adapter set, cannot connect");
305
- }
306
303
  if (!this.app.serving()) {
307
304
  this.app.logger.warn("app is not serving, will not connect to event queue");
308
305
  return;
309
306
  }
307
+ if (!this.adapter) {
308
+ throw new Error("no adapter set, cannot connect");
309
+ }
310
310
  await this.adapter.connect();
311
311
  this.app.logger.debug(`connected to adapter, using memory? ${this.adapter instanceof MemoryEventQueueAdapter}`);
312
312
  for (const [channel, event] of this.events.entries()) {
@@ -342,6 +342,10 @@ const _EventQueue = class _EventQueue {
342
342
  }
343
343
  }
344
344
  async publish(channel, message, options = {}) {
345
+ if (!this.app.serving()) {
346
+ this.app.logger.warn("app is not serving, will not publish message to event queue");
347
+ return;
348
+ }
345
349
  if (!this.adapter) {
346
350
  throw new Error("no adapter set, cannot publish");
347
351
  }
package/lib/index.d.ts CHANGED
@@ -18,7 +18,6 @@ export * from './plugin';
18
18
  export * from './plugin-manager';
19
19
  export * from './pub-sub-manager';
20
20
  export * from './event-queue';
21
- export * from './background-job-manager';
22
21
  export * from './worker-id-allocator';
23
22
  export * from './redis-connection-manager';
24
23
  export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
package/lib/index.js CHANGED
@@ -60,7 +60,6 @@ __reExport(src_exports, require("./plugin"), module.exports);
60
60
  __reExport(src_exports, require("./plugin-manager"), module.exports);
61
61
  __reExport(src_exports, require("./pub-sub-manager"), module.exports);
62
62
  __reExport(src_exports, require("./event-queue"), module.exports);
63
- __reExport(src_exports, require("./background-job-manager"), module.exports);
64
63
  __reExport(src_exports, require("./worker-id-allocator"), module.exports);
65
64
  __reExport(src_exports, require("./redis-connection-manager"), module.exports);
66
65
  var import_findPackageNames = require("./plugin-manager/findPackageNames");
@@ -86,7 +85,6 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
86
85
  ...require("./plugin-manager"),
87
86
  ...require("./pub-sub-manager"),
88
87
  ...require("./event-queue"),
89
- ...require("./background-job-manager"),
90
88
  ...require("./worker-id-allocator"),
91
89
  ...require("./redis-connection-manager")
92
90
  });
@@ -17,8 +17,8 @@ export declare class PubSubManager {
17
17
  protected adapter: IPubSubAdapter;
18
18
  protected handlerManager: HandlerManager;
19
19
  constructor(app: Application, options?: PubSubManagerOptions);
20
- get channelPrefix(): string;
21
20
  setAdapter(adapter: IPubSubAdapter): void;
21
+ getFullChannel(channel: string): string;
22
22
  isConnected(): Promise<boolean>;
23
23
  connect(): Promise<void>;
24
24
  close(): Promise<any>;
@@ -55,13 +55,13 @@ const _PubSubManager = class _PubSubManager {
55
55
  publisherId;
56
56
  adapter;
57
57
  handlerManager;
58
- get channelPrefix() {
59
- var _a;
60
- return ((_a = this.options) == null ? void 0 : _a.channelPrefix) ? `${this.options.channelPrefix}.` : "";
61
- }
62
58
  setAdapter(adapter) {
63
59
  this.adapter = adapter;
64
60
  }
61
+ getFullChannel(channel) {
62
+ var _a;
63
+ return [this.app.name, (_a = this.options) == null ? void 0 : _a.channelPrefix, channel].filter(Boolean).join(".");
64
+ }
65
65
  async isConnected() {
66
66
  if (this.adapter) {
67
67
  return this.adapter.isConnected();
@@ -79,7 +79,7 @@ const _PubSubManager = class _PubSubManager {
79
79
  await this.adapter.connect();
80
80
  await this.handlerManager.each(async (channel, headler) => {
81
81
  this.app.logger.debug(`[PubSubManager] subscribe ${channel} added before connected`);
82
- await this.adapter.subscribe(`${this.channelPrefix}${channel}`, headler);
82
+ await this.adapter.subscribe(this.getFullChannel(channel), headler);
83
83
  });
84
84
  }
85
85
  async close() {
@@ -93,7 +93,7 @@ const _PubSubManager = class _PubSubManager {
93
93
  const handler = this.handlerManager.set(channel, callback, options);
94
94
  if (await this.isConnected()) {
95
95
  this.app.logger.debug(`[PubSubManager] subscribe ${channel} added after connected`);
96
- await this.adapter.subscribe(`${this.channelPrefix}${channel}`, handler);
96
+ await this.adapter.subscribe(this.getFullChannel(channel), handler);
97
97
  }
98
98
  }
99
99
  async unsubscribe(channel, callback) {
@@ -101,7 +101,7 @@ const _PubSubManager = class _PubSubManager {
101
101
  if (!this.adapter || !handler) {
102
102
  return;
103
103
  }
104
- return this.adapter.unsubscribe(`${this.channelPrefix}${channel}`, handler);
104
+ return this.adapter.unsubscribe(this.getFullChannel(channel), handler);
105
105
  }
106
106
  async publish(channel, message, options) {
107
107
  var _a;
@@ -116,7 +116,7 @@ const _PubSubManager = class _PubSubManager {
116
116
  ...options,
117
117
  message
118
118
  });
119
- await this.adapter.publish(`${this.channelPrefix}${channel}`, wrappedMessage);
119
+ await this.adapter.publish(this.getFullChannel(channel), wrappedMessage);
120
120
  this.app.logger.trace(`[PubSubManager] published message to channel ${channel}`);
121
121
  }
122
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "1.9.0-beta.16",
3
+ "version": "1.9.0-beta.17",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
@@ -10,20 +10,20 @@
10
10
  "@koa/cors": "^5.0.0",
11
11
  "@koa/multer": "^3.1.0",
12
12
  "@koa/router": "^13.1.0",
13
- "@nocobase/acl": "1.9.0-beta.16",
14
- "@nocobase/actions": "1.9.0-beta.16",
15
- "@nocobase/auth": "1.9.0-beta.16",
16
- "@nocobase/cache": "1.9.0-beta.16",
17
- "@nocobase/data-source-manager": "1.9.0-beta.16",
18
- "@nocobase/database": "1.9.0-beta.16",
19
- "@nocobase/evaluators": "1.9.0-beta.16",
20
- "@nocobase/lock-manager": "1.9.0-beta.16",
21
- "@nocobase/logger": "1.9.0-beta.16",
22
- "@nocobase/resourcer": "1.9.0-beta.16",
23
- "@nocobase/sdk": "1.9.0-beta.16",
24
- "@nocobase/snowflake-id": "1.9.0-beta.16",
25
- "@nocobase/telemetry": "1.9.0-beta.16",
26
- "@nocobase/utils": "1.9.0-beta.16",
13
+ "@nocobase/acl": "1.9.0-beta.17",
14
+ "@nocobase/actions": "1.9.0-beta.17",
15
+ "@nocobase/auth": "1.9.0-beta.17",
16
+ "@nocobase/cache": "1.9.0-beta.17",
17
+ "@nocobase/data-source-manager": "1.9.0-beta.17",
18
+ "@nocobase/database": "1.9.0-beta.17",
19
+ "@nocobase/evaluators": "1.9.0-beta.17",
20
+ "@nocobase/lock-manager": "1.9.0-beta.17",
21
+ "@nocobase/logger": "1.9.0-beta.17",
22
+ "@nocobase/resourcer": "1.9.0-beta.17",
23
+ "@nocobase/sdk": "1.9.0-beta.17",
24
+ "@nocobase/snowflake-id": "1.9.0-beta.17",
25
+ "@nocobase/telemetry": "1.9.0-beta.17",
26
+ "@nocobase/utils": "1.9.0-beta.17",
27
27
  "@types/decompress": "4.2.7",
28
28
  "@types/ini": "^1.3.31",
29
29
  "@types/koa-send": "^4.1.3",
@@ -59,5 +59,5 @@
59
59
  "@types/serve-handler": "^6.1.1",
60
60
  "@types/ws": "^8.5.5"
61
61
  },
62
- "gitHead": "ff9b917d27840cc08e3f60d02384504ae0e35995"
62
+ "gitHead": "4f95b676235fa3f7583493412279d8132a20c4d0"
63
63
  }
@@ -1,40 +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 Application from './application';
10
- import { QueueEventOptions, QueueMessageOptions } from './event-queue';
11
- export interface BackgroundJobManagerOptions {
12
- channel?: string;
13
- }
14
- type BackgroundJobEventOptions = Pick<QueueEventOptions, 'process' | 'idle'>;
15
- declare class BackgroundJobManager {
16
- private app;
17
- private options;
18
- static DEFAULT_CHANNEL: string;
19
- private subscriptions;
20
- private processing;
21
- private get channel();
22
- private onAfterStart;
23
- private onBeforeStop;
24
- private process;
25
- constructor(app: Application, options?: BackgroundJobManagerOptions);
26
- private get idle();
27
- /**
28
- * 订阅指定主题的任务处理器
29
- * @param options 订阅选项
30
- */
31
- subscribe(topic: string, options: BackgroundJobEventOptions): void;
32
- /**
33
- * 取消订阅指定主题
34
- * @param topic 主题名称
35
- */
36
- unsubscribe(topic: string): void;
37
- publish(topic: string, payload: any, options?: QueueMessageOptions): Promise<void>;
38
- }
39
- export { BackgroundJobManager };
40
- export default BackgroundJobManager;
@@ -1,111 +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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
30
- var background_job_manager_exports = {};
31
- __export(background_job_manager_exports, {
32
- BackgroundJobManager: () => BackgroundJobManager,
33
- default: () => background_job_manager_default
34
- });
35
- module.exports = __toCommonJS(background_job_manager_exports);
36
- const _BackgroundJobManager = class _BackgroundJobManager {
37
- constructor(app, options = {}) {
38
- this.app = app;
39
- this.options = options;
40
- this.app.on("afterStart", this.onAfterStart);
41
- this.app.on("beforeStop", this.onBeforeStop);
42
- }
43
- subscriptions = /* @__PURE__ */ new Map();
44
- // topic -> handler
45
- processing = null;
46
- get channel() {
47
- return this.options.channel ?? _BackgroundJobManager.DEFAULT_CHANNEL;
48
- }
49
- onAfterStart = /* @__PURE__ */ __name(() => {
50
- this.app.eventQueue.subscribe(this.channel, {
51
- idle: /* @__PURE__ */ __name(() => this.idle, "idle"),
52
- process: this.process
53
- });
54
- }, "onAfterStart");
55
- onBeforeStop = /* @__PURE__ */ __name(() => {
56
- this.app.eventQueue.unsubscribe(this.channel);
57
- }, "onBeforeStop");
58
- process = /* @__PURE__ */ __name(async ({ topic, payload }, options) => {
59
- const event = this.subscriptions.get(topic);
60
- if (!event) {
61
- this.app.logger.warn(`No handler found for topic: ${topic}, event skipped.`);
62
- return;
63
- }
64
- this.processing = event.process(payload, options);
65
- try {
66
- await this.processing;
67
- this.app.logger.debug(`Completed background job ${topic}:${options.id}`);
68
- } catch (error) {
69
- this.app.logger.error(`Failed to process background job ${topic}:${options.id}`, error);
70
- throw error;
71
- } finally {
72
- this.processing = null;
73
- }
74
- }, "process");
75
- get idle() {
76
- return !this.processing && [...this.subscriptions.values()].every((event) => event.idle());
77
- }
78
- /**
79
- * 订阅指定主题的任务处理器
80
- * @param options 订阅选项
81
- */
82
- subscribe(topic, options) {
83
- if (this.subscriptions.has(topic)) {
84
- this.app.logger.warn(`Topic "${topic}" already has a handler, skip...`);
85
- return;
86
- }
87
- this.subscriptions.set(topic, options);
88
- this.app.logger.debug(`Subscribed to background job topic: ${topic}`);
89
- }
90
- /**
91
- * 取消订阅指定主题
92
- * @param topic 主题名称
93
- */
94
- unsubscribe(topic) {
95
- if (this.subscriptions.has(topic)) {
96
- this.subscriptions.delete(topic);
97
- this.app.logger.debug(`Unsubscribed from background job topic: ${topic}`);
98
- }
99
- }
100
- async publish(topic, payload, options) {
101
- await this.app.eventQueue.publish(this.channel, { topic, payload }, options);
102
- }
103
- };
104
- __name(_BackgroundJobManager, "BackgroundJobManager");
105
- __publicField(_BackgroundJobManager, "DEFAULT_CHANNEL", "background-jobs");
106
- let BackgroundJobManager = _BackgroundJobManager;
107
- var background_job_manager_default = BackgroundJobManager;
108
- // Annotate the CommonJS export names for ESM import in node:
109
- 0 && (module.exports = {
110
- BackgroundJobManager
111
- });