@nocobase/server 1.5.0-beta.1 → 1.6.0-alpha.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "1.5.0-beta.1",
3
+ "version": "1.6.0-alpha.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
@@ -10,22 +10,24 @@
10
10
  "@koa/cors": "^3.1.0",
11
11
  "@koa/multer": "^3.0.2",
12
12
  "@koa/router": "^9.4.0",
13
- "@nocobase/acl": "1.5.0-beta.1",
14
- "@nocobase/actions": "1.5.0-beta.1",
15
- "@nocobase/auth": "1.5.0-beta.1",
16
- "@nocobase/cache": "1.5.0-beta.1",
17
- "@nocobase/data-source-manager": "1.5.0-beta.1",
18
- "@nocobase/database": "1.5.0-beta.1",
19
- "@nocobase/evaluators": "1.5.0-beta.1",
20
- "@nocobase/logger": "1.5.0-beta.1",
21
- "@nocobase/resourcer": "1.5.0-beta.1",
22
- "@nocobase/sdk": "1.5.0-beta.1",
23
- "@nocobase/telemetry": "1.5.0-beta.1",
24
- "@nocobase/utils": "1.5.0-beta.1",
13
+ "@nocobase/acl": "1.6.0-alpha.2",
14
+ "@nocobase/actions": "1.6.0-alpha.2",
15
+ "@nocobase/auth": "1.6.0-alpha.2",
16
+ "@nocobase/cache": "1.6.0-alpha.2",
17
+ "@nocobase/data-source-manager": "1.6.0-alpha.2",
18
+ "@nocobase/database": "1.6.0-alpha.2",
19
+ "@nocobase/evaluators": "1.6.0-alpha.2",
20
+ "@nocobase/lock-manager": "1.6.0-alpha.2",
21
+ "@nocobase/logger": "1.6.0-alpha.2",
22
+ "@nocobase/resourcer": "1.6.0-alpha.2",
23
+ "@nocobase/sdk": "1.6.0-alpha.2",
24
+ "@nocobase/telemetry": "1.6.0-alpha.2",
25
+ "@nocobase/utils": "1.6.0-alpha.2",
25
26
  "@types/decompress": "4.2.7",
26
27
  "@types/ini": "^1.3.31",
27
28
  "@types/koa-send": "^4.1.3",
28
29
  "@types/multer": "^1.4.5",
30
+ "async-mutex": "^0.5.0",
29
31
  "axios": "^1.7.0",
30
32
  "chalk": "^4.1.1",
31
33
  "commander": "^9.2.0",
@@ -54,5 +56,5 @@
54
56
  "@types/serve-handler": "^6.1.1",
55
57
  "@types/ws": "^8.5.5"
56
58
  },
57
- "gitHead": "10c6f1f3d90e91f3aabfa80449c7ef062e90f6af"
59
+ "gitHead": "08bbc34c21727fc0ad0880f397a42bf7741091ee"
58
60
  }
@@ -1,46 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- /// <reference types="node" />
10
- import EventEmitter from 'node:events';
11
- import Application from './application';
12
- export declare abstract class SyncAdapter extends EventEmitter {
13
- abstract get ready(): boolean;
14
- abstract publish(data: SyncMessage): void | Promise<void>;
15
- }
16
- export type SyncMessageData = Record<string, string>;
17
- export type SyncEventCallback = (message: SyncMessageData) => void;
18
- export type SyncMessage = {
19
- namespace: string;
20
- nodeId: string;
21
- appName: string;
22
- } & SyncMessageData;
23
- /**
24
- * @experimental
25
- */
26
- export declare class SyncManager {
27
- private app;
28
- private nodeId;
29
- private eventEmitter;
30
- private adapter;
31
- private incomingBuffer;
32
- private outgoingBuffer;
33
- private flushTimer;
34
- get available(): boolean;
35
- private onMessage;
36
- private onSync;
37
- private onReady;
38
- constructor(app: Application);
39
- init(adapter: SyncAdapter): void;
40
- subscribe(namespace: string, callback: SyncEventCallback): void;
41
- unsubscribe(namespace: string, callback: SyncEventCallback): void;
42
- /**
43
- * Publish a message to the sync manager
44
- */
45
- publish(namespace: string, data?: SyncMessageData): void | Promise<void>;
46
- }
@@ -1,137 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var sync_manager_exports = {};
39
- __export(sync_manager_exports, {
40
- SyncAdapter: () => SyncAdapter,
41
- SyncManager: () => SyncManager
42
- });
43
- module.exports = __toCommonJS(sync_manager_exports);
44
- var import_node_crypto = require("node:crypto");
45
- var import_node_events = __toESM(require("node:events"));
46
- var import_lodash = require("lodash");
47
- const _SyncAdapter = class _SyncAdapter extends import_node_events.default {
48
- };
49
- __name(_SyncAdapter, "SyncAdapter");
50
- let SyncAdapter = _SyncAdapter;
51
- const _SyncManager = class _SyncManager {
52
- constructor(app) {
53
- this.app = app;
54
- this.nodeId = `${process.env.NODE_ID || (0, import_node_crypto.randomUUID)()}-${process.pid}`;
55
- }
56
- nodeId;
57
- eventEmitter = new import_node_events.default();
58
- adapter = null;
59
- incomingBuffer = [];
60
- outgoingBuffer = [];
61
- flushTimer = null;
62
- get available() {
63
- return this.adapter ? this.adapter.ready : false;
64
- }
65
- onMessage(namespace, message) {
66
- this.app.logger.info(`emit sync event in namespace ${namespace}`);
67
- this.eventEmitter.emit(namespace, message);
68
- const pluginInstance = this.app.pm.get(namespace);
69
- pluginInstance.onSync(message);
70
- }
71
- onSync = /* @__PURE__ */ __name((messages) => {
72
- this.app.logger.info("sync messages received, save into buffer:", messages);
73
- if (this.flushTimer) {
74
- clearTimeout(this.flushTimer);
75
- this.flushTimer = null;
76
- }
77
- this.incomingBuffer = (0, import_lodash.uniqWith)(
78
- this.incomingBuffer.concat(
79
- messages.filter((item) => item.nodeId !== this.nodeId && item.appName === this.app.name).map(({ nodeId, appName, ...message }) => message)
80
- ),
81
- import_lodash.isEqual
82
- );
83
- this.flushTimer = setTimeout(() => {
84
- this.incomingBuffer.forEach(({ namespace, ...message }) => {
85
- this.onMessage(namespace, message);
86
- });
87
- this.incomingBuffer = [];
88
- }, 1e3);
89
- }, "onSync");
90
- onReady = /* @__PURE__ */ __name(() => {
91
- while (this.outgoingBuffer.length) {
92
- const [namespace, data] = this.outgoingBuffer.shift();
93
- this.publish(namespace, data);
94
- }
95
- }, "onReady");
96
- init(adapter) {
97
- if (this.adapter) {
98
- throw new Error("sync adapter is already exists");
99
- }
100
- if (!adapter) {
101
- return;
102
- }
103
- this.adapter = adapter;
104
- this.adapter.on("message", this.onSync);
105
- this.adapter.on("ready", this.onReady);
106
- }
107
- subscribe(namespace, callback) {
108
- this.eventEmitter.on(namespace, callback);
109
- }
110
- unsubscribe(namespace, callback) {
111
- this.eventEmitter.off(namespace, callback);
112
- }
113
- /**
114
- * Publish a message to the sync manager
115
- */
116
- publish(namespace, data = {}) {
117
- if (!this.adapter) {
118
- return;
119
- }
120
- if (!this.adapter.ready) {
121
- this.outgoingBuffer.push([namespace, data]);
122
- this.app.logger.warn(`sync adapter is not ready for now, message will be send when it is ready`);
123
- return;
124
- }
125
- this.app.logger.info(`publishing sync message from #${this.nodeId} (${this.app.name}) in namespace ${namespace}:`, {
126
- data
127
- });
128
- return this.adapter.publish({ ...data, nodeId: this.nodeId, appName: this.app.name, namespace });
129
- }
130
- };
131
- __name(_SyncManager, "SyncManager");
132
- let SyncManager = _SyncManager;
133
- // Annotate the CommonJS export names for ESM import in node:
134
- 0 && (module.exports = {
135
- SyncAdapter,
136
- SyncManager
137
- });