@nocobase/server 1.9.0-beta.8 → 2.0.0-alpha.10
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/lib/aes-encryptor.js +7 -9
- package/lib/application.d.ts +13 -2
- package/lib/application.js +45 -24
- package/lib/gateway/index.d.ts +12 -1
- package/lib/gateway/index.js +69 -2
- package/lib/index.d.ts +3 -0
- package/lib/index.js +7 -1
- package/lib/locale/resource.js +7 -0
- package/lib/middlewares/data-template.js +1 -6
- package/lib/migrations/20250902230900-update-primary-keys.d.ts +14 -0
- package/lib/migrations/20250902230900-update-primary-keys.js +124 -0
- package/lib/plugin.js +5 -1
- package/lib/redis-connection-manager.d.ts +28 -0
- package/lib/redis-connection-manager.js +119 -0
- package/lib/snowflake-id-field.d.ts +10 -0
- package/lib/snowflake-id-field.js +48 -0
- package/lib/worker-id-allocator.d.ts +18 -0
- package/lib/worker-id-allocator.js +56 -0
- package/package.json +17 -15
package/lib/aes-encryptor.js
CHANGED
|
@@ -53,25 +53,25 @@ const _AesEncryptor = class _AesEncryptor {
|
|
|
53
53
|
this.key = key;
|
|
54
54
|
}
|
|
55
55
|
async encrypt(text) {
|
|
56
|
-
return new Promise((
|
|
56
|
+
return new Promise((resolve2, reject) => {
|
|
57
57
|
try {
|
|
58
58
|
const iv = import_crypto.default.randomBytes(16);
|
|
59
59
|
const cipher = import_crypto.default.createCipheriv("aes-256-cbc", this.key, iv);
|
|
60
60
|
const encrypted = Buffer.concat([cipher.update(Buffer.from(text, "utf8")), cipher.final()]);
|
|
61
|
-
|
|
61
|
+
resolve2(iv.toString("hex") + encrypted.toString("hex"));
|
|
62
62
|
} catch (error) {
|
|
63
63
|
reject(error);
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
async decrypt(encryptedText) {
|
|
68
|
-
return new Promise((
|
|
68
|
+
return new Promise((resolve2, reject) => {
|
|
69
69
|
try {
|
|
70
70
|
const iv = Buffer.from(encryptedText.slice(0, 32), "hex");
|
|
71
71
|
const encrypted = Buffer.from(encryptedText.slice(32), "hex");
|
|
72
72
|
const decipher = import_crypto.default.createDecipheriv("aes-256-cbc", this.key, iv);
|
|
73
73
|
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
74
|
-
|
|
74
|
+
resolve2(decrypted.toString("utf8"));
|
|
75
75
|
} catch (error) {
|
|
76
76
|
reject(error);
|
|
77
77
|
}
|
|
@@ -109,11 +109,9 @@ const _AesEncryptor = class _AesEncryptor {
|
|
|
109
109
|
return appKeyPath;
|
|
110
110
|
}
|
|
111
111
|
static async create(app) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
key = await _AesEncryptor.getOrGenerateKey(keyPath);
|
|
116
|
-
}
|
|
112
|
+
const KEY_PATH = process.env.APP_AES_SECRET_KEY_PATH;
|
|
113
|
+
const keyPath = KEY_PATH ? (0, import_path.resolve)(process.cwd(), KEY_PATH) : await this.getKeyPath(app.name);
|
|
114
|
+
const key = await _AesEncryptor.getOrGenerateKey(keyPath);
|
|
117
115
|
return new _AesEncryptor(key);
|
|
118
116
|
}
|
|
119
117
|
};
|
package/lib/application.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ import { Environment } from './environment';
|
|
|
37
37
|
import { ServiceContainer } from './service-container';
|
|
38
38
|
import { EventQueue, EventQueueOptions } from './event-queue';
|
|
39
39
|
import { BackgroundJobManager, BackgroundJobManagerOptions } from './background-job-manager';
|
|
40
|
+
import { RedisConfig, RedisConnectionManager } from './redis-connection-manager';
|
|
41
|
+
import { WorkerIdAllocator } from './worker-id-allocator';
|
|
40
42
|
export type PluginType = string | typeof Plugin;
|
|
41
43
|
export type PluginConfiguration = PluginType | [PluginType, any];
|
|
42
44
|
export interface ResourceManagerOptions {
|
|
@@ -57,8 +59,9 @@ export interface AppTelemetryOptions extends TelemetryOptions {
|
|
|
57
59
|
enabled?: boolean;
|
|
58
60
|
}
|
|
59
61
|
export interface ApplicationOptions {
|
|
60
|
-
instanceId?:
|
|
62
|
+
instanceId?: number;
|
|
61
63
|
database?: IDatabaseOptions | Database;
|
|
64
|
+
redisConfig?: RedisConfig;
|
|
62
65
|
cacheManager?: CacheManagerOptions;
|
|
63
66
|
/**
|
|
64
67
|
* this property is deprecated and should not be used.
|
|
@@ -131,9 +134,12 @@ export type MaintainingCommandStatus = {
|
|
|
131
134
|
status: MaintainingStatus;
|
|
132
135
|
error?: Error;
|
|
133
136
|
};
|
|
137
|
+
interface SnowflakeIdGenerator {
|
|
138
|
+
generate(): number | BigInt;
|
|
139
|
+
}
|
|
134
140
|
export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {
|
|
135
141
|
options: ApplicationOptions;
|
|
136
|
-
|
|
142
|
+
private _instanceId;
|
|
137
143
|
/**
|
|
138
144
|
* @internal
|
|
139
145
|
*/
|
|
@@ -168,6 +174,9 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
168
174
|
/**
|
|
169
175
|
* @internal
|
|
170
176
|
*/
|
|
177
|
+
redisConnectionManager: RedisConnectionManager;
|
|
178
|
+
workerIdAllocator: WorkerIdAllocator;
|
|
179
|
+
snowflakeIdGenerator: SnowflakeIdGenerator;
|
|
171
180
|
pubSubManager: PubSubManager;
|
|
172
181
|
syncMessageManager: SyncMessageManager;
|
|
173
182
|
requestLogger: Logger;
|
|
@@ -186,6 +195,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
186
195
|
private static staticCommands;
|
|
187
196
|
static addCommand(callback: (app: Application) => void): void;
|
|
188
197
|
private _sqlLogger;
|
|
198
|
+
get instanceId(): number;
|
|
189
199
|
get sqlLogger(): Logger;
|
|
190
200
|
protected _logger: SystemLogger;
|
|
191
201
|
get logger(): SystemLogger;
|
|
@@ -309,6 +319,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
309
319
|
actions(handlers: any, options?: ActionsOptions): void;
|
|
310
320
|
command(name: string, desc?: string, opts?: CommandOptions): AppCommand;
|
|
311
321
|
findCommand(name: string): Command;
|
|
322
|
+
private disposeServices;
|
|
312
323
|
/**
|
|
313
324
|
* @internal
|
|
314
325
|
*/
|
package/lib/application.js
CHANGED
|
@@ -51,12 +51,12 @@ 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
53
|
var import_utils = require("@nocobase/utils");
|
|
54
|
+
var import_snowflake_id = require("@nocobase/snowflake-id");
|
|
54
55
|
var import_crypto = require("crypto");
|
|
55
56
|
var import_glob = __toESM(require("glob"));
|
|
56
57
|
var import_koa = __toESM(require("koa"));
|
|
57
58
|
var import_koa_compose = __toESM(require("koa-compose"));
|
|
58
59
|
var import_lodash = __toESM(require("lodash"));
|
|
59
|
-
var import_nanoid = require("nanoid");
|
|
60
60
|
var import_path = __toESM(require("path"));
|
|
61
61
|
var import_semver = __toESM(require("semver"));
|
|
62
62
|
var import_acl = require("./acl");
|
|
@@ -84,11 +84,13 @@ var import_environment = require("./environment");
|
|
|
84
84
|
var import_service_container = require("./service-container");
|
|
85
85
|
var import_event_queue = require("./event-queue");
|
|
86
86
|
var import_background_job_manager = require("./background-job-manager");
|
|
87
|
+
var import_redis_connection_manager = require("./redis-connection-manager");
|
|
88
|
+
var import_worker_id_allocator = require("./worker-id-allocator");
|
|
89
|
+
var import_snowflake_id_field = require("./snowflake-id-field");
|
|
87
90
|
const _Application = class _Application extends import_koa.default {
|
|
88
91
|
constructor(options) {
|
|
89
92
|
super();
|
|
90
93
|
this.options = options;
|
|
91
|
-
this.instanceId = options.instanceId || (0, import_nanoid.nanoid)();
|
|
92
94
|
this.context.reqId = (0, import_crypto.randomUUID)();
|
|
93
95
|
this.rawOptions = this.name == "main" ? import_lodash.default.cloneDeep(options) : {};
|
|
94
96
|
this.init();
|
|
@@ -96,7 +98,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
96
98
|
this._appSupervisor.addApp(this);
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
|
-
|
|
101
|
+
_instanceId;
|
|
100
102
|
/**
|
|
101
103
|
* @internal
|
|
102
104
|
*/
|
|
@@ -124,6 +126,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
124
126
|
/**
|
|
125
127
|
* @internal
|
|
126
128
|
*/
|
|
129
|
+
redisConnectionManager;
|
|
130
|
+
workerIdAllocator;
|
|
131
|
+
snowflakeIdGenerator;
|
|
127
132
|
pubSubManager;
|
|
128
133
|
syncMessageManager;
|
|
129
134
|
requestLogger;
|
|
@@ -142,6 +147,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
142
147
|
this.staticCommands.push(callback);
|
|
143
148
|
}
|
|
144
149
|
_sqlLogger;
|
|
150
|
+
get instanceId() {
|
|
151
|
+
return this._instanceId;
|
|
152
|
+
}
|
|
145
153
|
get sqlLogger() {
|
|
146
154
|
return this._sqlLogger;
|
|
147
155
|
}
|
|
@@ -392,16 +400,10 @@ const _Application = class _Application extends import_koa.default {
|
|
|
392
400
|
findCommand(name) {
|
|
393
401
|
return this.cli._findCommand(name);
|
|
394
402
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
async reInit() {
|
|
399
|
-
if (!this._loaded) {
|
|
400
|
-
return;
|
|
403
|
+
async disposeServices() {
|
|
404
|
+
if (this.redisConnectionManager) {
|
|
405
|
+
await this.redisConnectionManager.close();
|
|
401
406
|
}
|
|
402
|
-
this.log.info("app reinitializing");
|
|
403
|
-
await this.emitAsync("beforeStop");
|
|
404
|
-
await this.emitAsync("afterStop");
|
|
405
407
|
if (this.cacheManager) {
|
|
406
408
|
await this.cacheManager.close();
|
|
407
409
|
}
|
|
@@ -411,6 +413,19 @@ const _Application = class _Application extends import_koa.default {
|
|
|
411
413
|
if (this.telemetry.started) {
|
|
412
414
|
await this.telemetry.shutdown();
|
|
413
415
|
}
|
|
416
|
+
await this.workerIdAllocator.release();
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* @internal
|
|
420
|
+
*/
|
|
421
|
+
async reInit() {
|
|
422
|
+
if (!this._loaded) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
this.log.info("app reinitializing");
|
|
426
|
+
await this.emitAsync("beforeStop");
|
|
427
|
+
await this.emitAsync("afterStop");
|
|
428
|
+
await this.disposeServices();
|
|
414
429
|
this.closeLogger();
|
|
415
430
|
const oldDb = this.db;
|
|
416
431
|
this.init();
|
|
@@ -434,12 +449,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
434
449
|
if (options == null ? void 0 : options.reload) {
|
|
435
450
|
this.setMaintainingMessage("app reload");
|
|
436
451
|
this.log.info(`app.reload()`, { method: "load" });
|
|
437
|
-
|
|
438
|
-
await this.cacheManager.close();
|
|
439
|
-
}
|
|
440
|
-
if (this.telemetry.started) {
|
|
441
|
-
await this.telemetry.shutdown();
|
|
442
|
-
}
|
|
452
|
+
await this.disposeServices();
|
|
443
453
|
const oldDb = this.db;
|
|
444
454
|
this.init();
|
|
445
455
|
if (!oldDb.closed()) {
|
|
@@ -460,6 +470,15 @@ const _Application = class _Application extends import_koa.default {
|
|
|
460
470
|
if ((options == null ? void 0 : options.hooks) !== false) {
|
|
461
471
|
await this.emitAsync("beforeLoad", this, options);
|
|
462
472
|
}
|
|
473
|
+
if (!this._instanceId) {
|
|
474
|
+
this._instanceId = await this.workerIdAllocator.getWorkerId();
|
|
475
|
+
this.log.info(`allocate worker id: ${this._instanceId}`, { method: "load" });
|
|
476
|
+
}
|
|
477
|
+
if (!this.snowflakeIdGenerator) {
|
|
478
|
+
this.snowflakeIdGenerator = new import_snowflake_id.Snowflake({
|
|
479
|
+
workerId: this._instanceId
|
|
480
|
+
});
|
|
481
|
+
}
|
|
463
482
|
if (!this.telemetry.started) {
|
|
464
483
|
this.telemetry.init();
|
|
465
484
|
if ((_a = this.options.telemetry) == null ? void 0 : _a.enabled) {
|
|
@@ -707,12 +726,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
707
726
|
} catch (e) {
|
|
708
727
|
log.error(e.message, { method: "stop", err: e.stack });
|
|
709
728
|
}
|
|
710
|
-
|
|
711
|
-
await this.cacheManager.close();
|
|
712
|
-
}
|
|
713
|
-
if (this.telemetry.started) {
|
|
714
|
-
await this.telemetry.shutdown();
|
|
715
|
-
}
|
|
729
|
+
await this.disposeServices();
|
|
716
730
|
await this.emitAsync("afterStop", this, options);
|
|
717
731
|
this.emit("__stopped", this, options);
|
|
718
732
|
this.stopped = true;
|
|
@@ -876,6 +890,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
876
890
|
}
|
|
877
891
|
init() {
|
|
878
892
|
const options = this.options;
|
|
893
|
+
this._instanceId = options.instanceId;
|
|
879
894
|
this.initLogger(options.logger);
|
|
880
895
|
this.reInitEvents();
|
|
881
896
|
this.middleware = new import_utils.Toposort();
|
|
@@ -884,6 +899,11 @@ const _Application = class _Application extends import_koa.default {
|
|
|
884
899
|
this.db.removeAllListeners();
|
|
885
900
|
}
|
|
886
901
|
this.createMainDataSource(options);
|
|
902
|
+
this.redisConnectionManager = new import_redis_connection_manager.RedisConnectionManager({
|
|
903
|
+
redisConfig: options.redisConfig,
|
|
904
|
+
logger: this._logger.child({ module: "redis-connection-manager" })
|
|
905
|
+
});
|
|
906
|
+
this.workerIdAllocator = new import_worker_id_allocator.WorkerIdAllocator();
|
|
887
907
|
this._cronJobManager = new import_cron_job_manager.CronJobManager(this);
|
|
888
908
|
this._env = new import_environment.Environment();
|
|
889
909
|
this._cli = this.createCLI();
|
|
@@ -962,6 +982,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
962
982
|
app: this
|
|
963
983
|
});
|
|
964
984
|
this.dataSourceManager.dataSources.set("main", mainDataSourceInstance);
|
|
985
|
+
(0, import_snowflake_id_field.setupSnowflakeIdField)(this);
|
|
965
986
|
}
|
|
966
987
|
createDatabase(options) {
|
|
967
988
|
const logging = /* @__PURE__ */ __name((...args) => {
|
package/lib/gateway/index.d.ts
CHANGED
|
@@ -8,14 +8,17 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/// <reference types="node" />
|
|
10
10
|
/// <reference types="node" />
|
|
11
|
+
/// <reference types="node" />
|
|
12
|
+
/// <reference types="node" />
|
|
11
13
|
import { SystemLogger } from '@nocobase/logger';
|
|
12
14
|
import { Registry, Toposort, ToposortOptions } from '@nocobase/utils';
|
|
13
15
|
import { EventEmitter } from 'events';
|
|
14
16
|
import http, { IncomingMessage, ServerResponse } from 'http';
|
|
15
|
-
import { ApplicationOptions } from '../application';
|
|
17
|
+
import { ApplicationOptions, Application } from '../application';
|
|
16
18
|
import { IPCSocketClient } from './ipc-socket-client';
|
|
17
19
|
import { IPCSocketServer } from './ipc-socket-server';
|
|
18
20
|
import { WSServer } from './ws-server';
|
|
21
|
+
import { Duplex } from 'node:stream';
|
|
19
22
|
export interface IncomingRequest {
|
|
20
23
|
url: string;
|
|
21
24
|
headers: any;
|
|
@@ -47,6 +50,8 @@ export declare class Gateway extends EventEmitter {
|
|
|
47
50
|
private port;
|
|
48
51
|
private host;
|
|
49
52
|
private socketPath;
|
|
53
|
+
private terminating;
|
|
54
|
+
private onTerminate;
|
|
50
55
|
private constructor();
|
|
51
56
|
static getInstance(options?: any): Gateway;
|
|
52
57
|
static getIPCSocketClient(): Promise<false | IPCSocketClient>;
|
|
@@ -76,5 +81,11 @@ export declare class Gateway extends EventEmitter {
|
|
|
76
81
|
tryConnectToIPCServer(): Promise<false | IPCSocketClient>;
|
|
77
82
|
getIPCSocketClient(): Promise<IPCSocketClient>;
|
|
78
83
|
close(): void;
|
|
84
|
+
private static requestHandlers;
|
|
85
|
+
static registerRequestHandler(handler: (req: IncomingRequest, res: ServerResponse, app: Application) => boolean | void): void;
|
|
86
|
+
static unregisterRequestHandler(handler: (req: IncomingRequest, res: ServerResponse, app: Application) => boolean | void): void;
|
|
87
|
+
private static wsServers;
|
|
88
|
+
static registerWsHandler(wsServer: (req: IncomingMessage, socket: Duplex, head: Buffer, app: Application) => boolean | void): void;
|
|
89
|
+
static unregisterWsHandler(wsServer: (req: IncomingMessage, socket: Duplex, head: Buffer, app: Application) => boolean | void): void;
|
|
79
90
|
}
|
|
80
91
|
export {};
|
package/lib/gateway/index.js
CHANGED
|
@@ -86,10 +86,37 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
86
86
|
port = import_node_process.default.env.APP_PORT ? parseInt(import_node_process.default.env.APP_PORT) : null;
|
|
87
87
|
host = "0.0.0.0";
|
|
88
88
|
socketPath = (0, import_path.resolve)(import_node_process.default.cwd(), "storage", "gateway.sock");
|
|
89
|
+
terminating = false;
|
|
90
|
+
onTerminate = /* @__PURE__ */ __name(async (signal) => {
|
|
91
|
+
var _a;
|
|
92
|
+
if (this.terminating) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.terminating = true;
|
|
96
|
+
const supervisor = import_app_supervisor.AppSupervisor.getInstance();
|
|
97
|
+
const apps = Object.values(supervisor.apps || {});
|
|
98
|
+
try {
|
|
99
|
+
for (const app of apps) {
|
|
100
|
+
try {
|
|
101
|
+
await app.destroy({ signal });
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const logger = (app == null ? void 0 : app.log) ?? console;
|
|
104
|
+
(_a = logger.error) == null ? void 0 : _a.call(logger, error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
await supervisor.destroy();
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error("Failed to shutdown applications gracefully", error);
|
|
110
|
+
} finally {
|
|
111
|
+
this.destroy();
|
|
112
|
+
}
|
|
113
|
+
}, "onTerminate");
|
|
89
114
|
constructor() {
|
|
90
115
|
super();
|
|
91
116
|
this.reset();
|
|
92
117
|
this.socketPath = getSocketPath();
|
|
118
|
+
import_node_process.default.once("SIGTERM", this.onTerminate);
|
|
119
|
+
import_node_process.default.once("SIGINT", this.onTerminate);
|
|
93
120
|
}
|
|
94
121
|
static getInstance(options = {}) {
|
|
95
122
|
if (!_Gateway.instance) {
|
|
@@ -106,6 +133,8 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
106
133
|
}
|
|
107
134
|
}
|
|
108
135
|
destroy() {
|
|
136
|
+
import_node_process.default.off("SIGTERM", this.onTerminate);
|
|
137
|
+
import_node_process.default.off("SIGINT", this.onTerminate);
|
|
109
138
|
this.reset();
|
|
110
139
|
_Gateway.instance = null;
|
|
111
140
|
}
|
|
@@ -137,6 +166,10 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
137
166
|
this.ipcSocketServer.close();
|
|
138
167
|
this.ipcSocketServer = null;
|
|
139
168
|
}
|
|
169
|
+
if (this.wsServer) {
|
|
170
|
+
this.wsServer.close();
|
|
171
|
+
this.wsServer = null;
|
|
172
|
+
}
|
|
140
173
|
}
|
|
141
174
|
addAppSelectorMiddleware(middleware, options) {
|
|
142
175
|
if (this.selectorMiddlewares.nodes.some((existingFunc) => existingFunc.toString() === middleware.toString())) {
|
|
@@ -360,9 +393,29 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
360
393
|
console.log("gateway port is not set, http server will not start");
|
|
361
394
|
return;
|
|
362
395
|
}
|
|
363
|
-
this.server = import_http.default.createServer(
|
|
396
|
+
this.server = import_http.default.createServer(async (req, res) => {
|
|
397
|
+
const appInstance = await import_app_supervisor.AppSupervisor.getInstance().getApp("main");
|
|
398
|
+
for (const handler2 of _Gateway.requestHandlers) {
|
|
399
|
+
try {
|
|
400
|
+
const result = await handler2(req, res, appInstance);
|
|
401
|
+
if (result !== false) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
} catch (error) {
|
|
405
|
+
console.error("gateway request handler error:", error);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
this.getCallback()(req, res);
|
|
409
|
+
});
|
|
364
410
|
this.wsServer = new import_ws_server.WSServer();
|
|
365
|
-
this.server.on("upgrade", (request, socket, head) => {
|
|
411
|
+
this.server.on("upgrade", async (request, socket, head) => {
|
|
412
|
+
const appInstance = await import_app_supervisor.AppSupervisor.getInstance().getApp("main");
|
|
413
|
+
for (const handle of _Gateway.wsServers) {
|
|
414
|
+
const result = await handle(request, socket, head, appInstance);
|
|
415
|
+
if (result !== false) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
366
419
|
const { pathname } = (0, import_url.parse)(request.url);
|
|
367
420
|
if (pathname === import_node_process.default.env.WS_PATH) {
|
|
368
421
|
this.wsServer.wss.handleUpgrade(request, socket, head, (ws) => {
|
|
@@ -395,9 +448,23 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
395
448
|
(_a = this.server) == null ? void 0 : _a.close();
|
|
396
449
|
(_b = this.wsServer) == null ? void 0 : _b.close();
|
|
397
450
|
}
|
|
451
|
+
static registerRequestHandler(handler2) {
|
|
452
|
+
_Gateway.requestHandlers.push(handler2);
|
|
453
|
+
}
|
|
454
|
+
static unregisterRequestHandler(handler2) {
|
|
455
|
+
_Gateway.requestHandlers = _Gateway.requestHandlers.filter((h) => h !== handler2);
|
|
456
|
+
}
|
|
457
|
+
static registerWsHandler(wsServer) {
|
|
458
|
+
_Gateway.wsServers.push(wsServer);
|
|
459
|
+
}
|
|
460
|
+
static unregisterWsHandler(wsServer) {
|
|
461
|
+
_Gateway.wsServers = _Gateway.wsServers.filter((ws) => ws !== wsServer);
|
|
462
|
+
}
|
|
398
463
|
};
|
|
399
464
|
__name(_Gateway, "Gateway");
|
|
400
465
|
__publicField(_Gateway, "instance");
|
|
466
|
+
__publicField(_Gateway, "requestHandlers", []);
|
|
467
|
+
__publicField(_Gateway, "wsServers", []);
|
|
401
468
|
let Gateway = _Gateway;
|
|
402
469
|
// Annotate the CommonJS export names for ESM import in node:
|
|
403
470
|
0 && (module.exports = {
|
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
export * from './aes-encryptor';
|
|
10
10
|
export * from './app-supervisor';
|
|
11
11
|
export * from './application';
|
|
12
|
+
export * from './gateway/ws-server';
|
|
12
13
|
export { Application as default } from './application';
|
|
13
14
|
export * from './audit-manager';
|
|
14
15
|
export * from './gateway';
|
|
@@ -19,6 +20,8 @@ export * from './plugin-manager';
|
|
|
19
20
|
export * from './pub-sub-manager';
|
|
20
21
|
export * from './event-queue';
|
|
21
22
|
export * from './background-job-manager';
|
|
23
|
+
export * from './worker-id-allocator';
|
|
24
|
+
export * from './redis-connection-manager';
|
|
22
25
|
export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
23
26
|
export { appendToBuiltInPlugins, findAllPlugins, findBuiltInPlugins, findLocalPlugins, packageNameTrim, } from './plugin-manager/findPackageNames';
|
|
24
27
|
export { runPluginStaticImports } from './run-plugin-static-imports';
|
package/lib/index.js
CHANGED
|
@@ -51,6 +51,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
51
51
|
__reExport(src_exports, require("./aes-encryptor"), module.exports);
|
|
52
52
|
__reExport(src_exports, require("./app-supervisor"), module.exports);
|
|
53
53
|
__reExport(src_exports, require("./application"), module.exports);
|
|
54
|
+
__reExport(src_exports, require("./gateway/ws-server"), module.exports);
|
|
54
55
|
var import_application = require("./application");
|
|
55
56
|
__reExport(src_exports, require("./audit-manager"), module.exports);
|
|
56
57
|
__reExport(src_exports, require("./gateway"), module.exports);
|
|
@@ -61,6 +62,8 @@ __reExport(src_exports, require("./plugin-manager"), module.exports);
|
|
|
61
62
|
__reExport(src_exports, require("./pub-sub-manager"), module.exports);
|
|
62
63
|
__reExport(src_exports, require("./event-queue"), module.exports);
|
|
63
64
|
__reExport(src_exports, require("./background-job-manager"), module.exports);
|
|
65
|
+
__reExport(src_exports, require("./worker-id-allocator"), module.exports);
|
|
66
|
+
__reExport(src_exports, require("./redis-connection-manager"), module.exports);
|
|
64
67
|
var import_findPackageNames = require("./plugin-manager/findPackageNames");
|
|
65
68
|
var import_run_plugin_static_imports = require("./run-plugin-static-imports");
|
|
66
69
|
const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
@@ -77,6 +80,7 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
|
77
80
|
...require("./aes-encryptor"),
|
|
78
81
|
...require("./app-supervisor"),
|
|
79
82
|
...require("./application"),
|
|
83
|
+
...require("./gateway/ws-server"),
|
|
80
84
|
...require("./audit-manager"),
|
|
81
85
|
...require("./gateway"),
|
|
82
86
|
...require("./migration"),
|
|
@@ -84,5 +88,7 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
|
84
88
|
...require("./plugin-manager"),
|
|
85
89
|
...require("./pub-sub-manager"),
|
|
86
90
|
...require("./event-queue"),
|
|
87
|
-
...require("./background-job-manager")
|
|
91
|
+
...require("./background-job-manager"),
|
|
92
|
+
...require("./worker-id-allocator"),
|
|
93
|
+
...require("./redis-connection-manager")
|
|
88
94
|
});
|
package/lib/locale/resource.js
CHANGED
|
@@ -59,6 +59,13 @@ const getResource = /* @__PURE__ */ __name((packageName, lang, isPlugin = true)
|
|
|
59
59
|
}
|
|
60
60
|
} catch (error) {
|
|
61
61
|
}
|
|
62
|
+
try {
|
|
63
|
+
require.resolve("@nocobase/flow-engine/src");
|
|
64
|
+
if (packageName === "@nocobase/plugin-flow-engine") {
|
|
65
|
+
packageName = "@nocobase/flow-engine";
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
}
|
|
62
69
|
prefixes.unshift("src");
|
|
63
70
|
}
|
|
64
71
|
for (const prefix of prefixes) {
|
|
@@ -126,12 +126,7 @@ const traverseJSON = /* @__PURE__ */ __name((data, options) => {
|
|
|
126
126
|
include: subInclude
|
|
127
127
|
});
|
|
128
128
|
} else if (field.type === "belongsTo") {
|
|
129
|
-
result[key] =
|
|
130
|
-
collection: collection.db.getCollection(field.target),
|
|
131
|
-
// exclude: [field.foreignKey],
|
|
132
|
-
include: subInclude,
|
|
133
|
-
excludePk: false
|
|
134
|
-
});
|
|
129
|
+
result[key] = data[key];
|
|
135
130
|
} else if (field.type === "belongsToMany") {
|
|
136
131
|
result[key] = traverseBelongsToMany(data[key], {
|
|
137
132
|
collection: collection.db.getCollection(field.target),
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { Migration } from '../migration';
|
|
10
|
+
export default class extends Migration {
|
|
11
|
+
on: string;
|
|
12
|
+
appVersion: string;
|
|
13
|
+
up(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 update_primary_keys_exports = {};
|
|
29
|
+
__export(update_primary_keys_exports, {
|
|
30
|
+
default: () => update_primary_keys_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(update_primary_keys_exports);
|
|
33
|
+
var import_sequelize = require("sequelize");
|
|
34
|
+
var import_migration = require("../migration");
|
|
35
|
+
const collections = [
|
|
36
|
+
"departments",
|
|
37
|
+
"desktopRoutes",
|
|
38
|
+
"mobileRoutes",
|
|
39
|
+
"collectionCategories",
|
|
40
|
+
"dataSourcesRolesResources",
|
|
41
|
+
"dataSourcesRolesResourcesActions",
|
|
42
|
+
"dataSourcesRolesResourcesScopes",
|
|
43
|
+
"storages",
|
|
44
|
+
"workflows",
|
|
45
|
+
"flow_nodes",
|
|
46
|
+
"executions",
|
|
47
|
+
"userWokrflowTasks",
|
|
48
|
+
"workflowCategories",
|
|
49
|
+
"approvalExecutions",
|
|
50
|
+
"approvalRecords",
|
|
51
|
+
"approvals",
|
|
52
|
+
"workflowManualTasks",
|
|
53
|
+
"workflowCcTasks",
|
|
54
|
+
"approvalMsgTpls",
|
|
55
|
+
"mailAccounts",
|
|
56
|
+
"mailSettings"
|
|
57
|
+
];
|
|
58
|
+
const _update_primary_keys_default = class _update_primary_keys_default extends import_migration.Migration {
|
|
59
|
+
on = "afterLoad";
|
|
60
|
+
// 'beforeLoad' or 'afterLoad'
|
|
61
|
+
appVersion = "<1.9.0";
|
|
62
|
+
async up() {
|
|
63
|
+
const repo = this.db.getRepository("fields");
|
|
64
|
+
if (!repo) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const queryInterface = this.db.sequelize.getQueryInterface();
|
|
68
|
+
for (const collectionName of collections) {
|
|
69
|
+
const collection = this.db.getCollection(collectionName);
|
|
70
|
+
if (collection) {
|
|
71
|
+
const tableName = collection.getTableNameWithSchema();
|
|
72
|
+
if (this.db.isPostgresCompatibleDialect()) {
|
|
73
|
+
await this.db.sequelize.transaction(async (transaction) => {
|
|
74
|
+
const schema = collection.collectionSchema();
|
|
75
|
+
const table = collection.model.tableName;
|
|
76
|
+
const seqName = `"${schema}"."${table}_id_seq"`;
|
|
77
|
+
await this.db.sequelize.query(`ALTER TABLE "${schema}"."${table}" ALTER COLUMN id DROP DEFAULT;`, {
|
|
78
|
+
transaction
|
|
79
|
+
});
|
|
80
|
+
await this.db.sequelize.query(`DROP SEQUENCE IF EXISTS ${seqName} CASCADE;`, { transaction });
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
await queryInterface.changeColumn(tableName, "id", {
|
|
84
|
+
type: import_sequelize.DataTypes.BIGINT,
|
|
85
|
+
allowNull: false
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const field = await repo.findOne({
|
|
90
|
+
filter: {
|
|
91
|
+
collectionName,
|
|
92
|
+
name: "id"
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (field) {
|
|
96
|
+
const options = { ...field.options };
|
|
97
|
+
delete options["autoIncrement"];
|
|
98
|
+
await repo.update({
|
|
99
|
+
filter: { key: field.key },
|
|
100
|
+
values: {
|
|
101
|
+
type: "snowflakeId",
|
|
102
|
+
options
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const treeCollections = [...this.db.collections.values()].filter((collection) => collection.options.tree);
|
|
108
|
+
for (const collection of treeCollections) {
|
|
109
|
+
const pathCollection = this.db.getCollection(`main_${collection.name}_path`);
|
|
110
|
+
if (pathCollection) {
|
|
111
|
+
const nodePk = pathCollection.getField("nodePk").columnName();
|
|
112
|
+
await queryInterface.changeColumn(pathCollection.getTableNameWithSchema(), nodePk, {
|
|
113
|
+
type: import_sequelize.DataTypes.BIGINT
|
|
114
|
+
});
|
|
115
|
+
const rootPk = pathCollection.getField("rootPk").columnName();
|
|
116
|
+
await queryInterface.changeColumn(pathCollection.getTableNameWithSchema(), rootPk, {
|
|
117
|
+
type: import_sequelize.DataTypes.BIGINT
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
__name(_update_primary_keys_default, "default");
|
|
124
|
+
let update_primary_keys_default = _update_primary_keys_default;
|
package/lib/plugin.js
CHANGED
|
@@ -130,7 +130,11 @@ const _Plugin = class _Plugin {
|
|
|
130
130
|
if (!this.name) {
|
|
131
131
|
throw new Error(`plugin name invalid`);
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
try {
|
|
134
|
+
await this.app.syncMessageManager.publish(this.name, message, options);
|
|
135
|
+
} catch (err) {
|
|
136
|
+
this.log.error(err);
|
|
137
|
+
}
|
|
134
138
|
}
|
|
135
139
|
/**
|
|
136
140
|
* @deprecated
|
|
@@ -0,0 +1,28 @@
|
|
|
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 Redis from 'ioredis';
|
|
10
|
+
import { Logger } from '@nocobase/logger';
|
|
11
|
+
export { Redis };
|
|
12
|
+
export interface RedisConfig {
|
|
13
|
+
connectionString: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class RedisConnectionManager {
|
|
16
|
+
private logger;
|
|
17
|
+
private config;
|
|
18
|
+
private connections;
|
|
19
|
+
constructor(config: {
|
|
20
|
+
redisConfig: RedisConfig;
|
|
21
|
+
logger: Logger;
|
|
22
|
+
});
|
|
23
|
+
private bindEvents;
|
|
24
|
+
private getClient;
|
|
25
|
+
getConnection(key?: string, config?: RedisConfig): Redis | null;
|
|
26
|
+
getConnectionSync(key?: string, config?: RedisConfig): Promise<Redis>;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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 redis_connection_manager_exports = {};
|
|
39
|
+
__export(redis_connection_manager_exports, {
|
|
40
|
+
Redis: () => import_ioredis.default,
|
|
41
|
+
RedisConnectionManager: () => RedisConnectionManager
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(redis_connection_manager_exports);
|
|
44
|
+
var import_ioredis = __toESM(require("ioredis"));
|
|
45
|
+
const _RedisConnectionManager = class _RedisConnectionManager {
|
|
46
|
+
logger;
|
|
47
|
+
config;
|
|
48
|
+
connections = /* @__PURE__ */ new Map();
|
|
49
|
+
constructor(config) {
|
|
50
|
+
this.config = config.redisConfig;
|
|
51
|
+
this.logger = config.logger;
|
|
52
|
+
}
|
|
53
|
+
bindEvents(conn, key, config) {
|
|
54
|
+
conn.on("connect", () => {
|
|
55
|
+
this.logger.info(`Redis connected`, {
|
|
56
|
+
method: "getConnection",
|
|
57
|
+
key,
|
|
58
|
+
config
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
conn.on("error", (err) => {
|
|
62
|
+
this.logger.error(err.message, {
|
|
63
|
+
err,
|
|
64
|
+
method: "getConnection",
|
|
65
|
+
key,
|
|
66
|
+
config
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
conn.on("close", () => {
|
|
70
|
+
this.logger.trace(`Redis closed`, {
|
|
71
|
+
method: "getConnection",
|
|
72
|
+
key,
|
|
73
|
+
config
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
getClient(key = "default", config) {
|
|
78
|
+
let conn = this.connections.get(key);
|
|
79
|
+
if (conn) {
|
|
80
|
+
return conn;
|
|
81
|
+
}
|
|
82
|
+
const cfg = config || this.config;
|
|
83
|
+
if (!cfg.connectionString) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
conn = new import_ioredis.default(cfg.connectionString);
|
|
87
|
+
this.connections.set(key, conn);
|
|
88
|
+
this.bindEvents(conn, key, cfg);
|
|
89
|
+
return conn;
|
|
90
|
+
}
|
|
91
|
+
getConnection(key = "default", config) {
|
|
92
|
+
return this.getClient(key, config);
|
|
93
|
+
}
|
|
94
|
+
async getConnectionSync(key = "default", config) {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const conn = this.getClient(key, config);
|
|
97
|
+
if (!conn) {
|
|
98
|
+
return reject(new Error("Redis connect string is missing"));
|
|
99
|
+
}
|
|
100
|
+
conn.once("connect", () => resolve(conn));
|
|
101
|
+
conn.once("error", reject);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async close() {
|
|
105
|
+
for (const conn of this.connections.values()) {
|
|
106
|
+
if (!(conn == null ? void 0 : conn.status) || conn.status === "close" || conn.status === "end") {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
await conn.quit();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
__name(_RedisConnectionManager, "RedisConnectionManager");
|
|
114
|
+
let RedisConnectionManager = _RedisConnectionManager;
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
Redis,
|
|
118
|
+
RedisConnectionManager
|
|
119
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export declare function setupSnowflakeIdField(app: Application): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
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 snowflake_id_field_exports = {};
|
|
29
|
+
__export(snowflake_id_field_exports, {
|
|
30
|
+
setupSnowflakeIdField: () => setupSnowflakeIdField
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(snowflake_id_field_exports);
|
|
33
|
+
var import_database = require("@nocobase/database");
|
|
34
|
+
function setupSnowflakeIdField(app) {
|
|
35
|
+
const _SnowflakeIdField = class _SnowflakeIdField extends import_database.SnowflakeIdField {
|
|
36
|
+
};
|
|
37
|
+
__name(_SnowflakeIdField, "SnowflakeIdField");
|
|
38
|
+
let SnowflakeIdField = _SnowflakeIdField;
|
|
39
|
+
SnowflakeIdField.setApp(app);
|
|
40
|
+
app.db.registerFieldTypes({
|
|
41
|
+
snowflakeId: SnowflakeIdField
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
__name(setupSnowflakeIdField, "setupSnowflakeIdField");
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
setupSnowflakeIdField
|
|
48
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
export interface WorkerIdAllocatorAdapter {
|
|
10
|
+
getWorkerId(): Promise<number>;
|
|
11
|
+
release(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare class WorkerIdAllocator {
|
|
14
|
+
private adapter;
|
|
15
|
+
setAdapter(adapter: WorkerIdAllocatorAdapter): void;
|
|
16
|
+
getWorkerId(): Promise<number>;
|
|
17
|
+
release(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 worker_id_allocator_exports = {};
|
|
29
|
+
__export(worker_id_allocator_exports, {
|
|
30
|
+
WorkerIdAllocator: () => WorkerIdAllocator
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(worker_id_allocator_exports);
|
|
33
|
+
const _WorkerIdAllocator = class _WorkerIdAllocator {
|
|
34
|
+
adapter;
|
|
35
|
+
setAdapter(adapter) {
|
|
36
|
+
this.adapter = adapter;
|
|
37
|
+
}
|
|
38
|
+
async getWorkerId() {
|
|
39
|
+
if (this.adapter) {
|
|
40
|
+
return this.adapter.getWorkerId();
|
|
41
|
+
}
|
|
42
|
+
return Math.floor(Math.random() * 32);
|
|
43
|
+
}
|
|
44
|
+
async release() {
|
|
45
|
+
if (this.adapter) {
|
|
46
|
+
return this.adapter.release();
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
__name(_WorkerIdAllocator, "WorkerIdAllocator");
|
|
52
|
+
let WorkerIdAllocator = _WorkerIdAllocator;
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
WorkerIdAllocator
|
|
56
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -10,19 +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": "
|
|
14
|
-
"@nocobase/actions": "
|
|
15
|
-
"@nocobase/auth": "
|
|
16
|
-
"@nocobase/cache": "
|
|
17
|
-
"@nocobase/data-source-manager": "
|
|
18
|
-
"@nocobase/database": "
|
|
19
|
-
"@nocobase/evaluators": "
|
|
20
|
-
"@nocobase/lock-manager": "
|
|
21
|
-
"@nocobase/logger": "
|
|
22
|
-
"@nocobase/resourcer": "
|
|
23
|
-
"@nocobase/sdk": "
|
|
24
|
-
"@nocobase/
|
|
25
|
-
"@nocobase/
|
|
13
|
+
"@nocobase/acl": "2.0.0-alpha.10",
|
|
14
|
+
"@nocobase/actions": "2.0.0-alpha.10",
|
|
15
|
+
"@nocobase/auth": "2.0.0-alpha.10",
|
|
16
|
+
"@nocobase/cache": "2.0.0-alpha.10",
|
|
17
|
+
"@nocobase/data-source-manager": "2.0.0-alpha.10",
|
|
18
|
+
"@nocobase/database": "2.0.0-alpha.10",
|
|
19
|
+
"@nocobase/evaluators": "2.0.0-alpha.10",
|
|
20
|
+
"@nocobase/lock-manager": "2.0.0-alpha.10",
|
|
21
|
+
"@nocobase/logger": "2.0.0-alpha.10",
|
|
22
|
+
"@nocobase/resourcer": "2.0.0-alpha.10",
|
|
23
|
+
"@nocobase/sdk": "2.0.0-alpha.10",
|
|
24
|
+
"@nocobase/snowflake-id": "2.0.0-alpha.10",
|
|
25
|
+
"@nocobase/telemetry": "2.0.0-alpha.10",
|
|
26
|
+
"@nocobase/utils": "2.0.0-alpha.10",
|
|
26
27
|
"@types/decompress": "4.2.7",
|
|
27
28
|
"@types/ini": "^1.3.31",
|
|
28
29
|
"@types/koa-send": "^4.1.3",
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"fs-extra": "^11.1.1",
|
|
41
42
|
"i18next": "^22.4.9",
|
|
42
43
|
"ini": "^4.1.1",
|
|
44
|
+
"ioredis": "^5.7.0",
|
|
43
45
|
"koa": "^2.15.4",
|
|
44
46
|
"koa-bodyparser": "^4.3.0",
|
|
45
47
|
"koa-send": "^5.0.1",
|
|
@@ -57,5 +59,5 @@
|
|
|
57
59
|
"@types/serve-handler": "^6.1.1",
|
|
58
60
|
"@types/ws": "^8.5.5"
|
|
59
61
|
},
|
|
60
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "6422cfb6fa6c8450de2efa3294fd29a28b228990"
|
|
61
63
|
}
|