@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.
- package/lib/acl/available-action.js +1 -1
- package/lib/aes-encryptor.d.ts +1 -0
- package/lib/aes-encryptor.js +12 -5
- package/lib/app-command.d.ts +1 -0
- package/lib/app-command.js +3 -0
- package/lib/app-supervisor/app-options-factory.d.ts +80 -0
- package/lib/app-supervisor/app-options-factory.js +91 -0
- package/lib/app-supervisor/condition-registry.d.ts +18 -0
- package/lib/app-supervisor/condition-registry.js +60 -0
- package/lib/app-supervisor/db-creator.d.ts +16 -0
- package/lib/app-supervisor/db-creator.js +163 -0
- package/lib/app-supervisor/db-drivers.d.ts +11 -0
- package/lib/app-supervisor/db-drivers.js +52 -0
- package/lib/app-supervisor/index.d.ts +161 -0
- package/lib/app-supervisor/index.js +690 -0
- package/lib/app-supervisor/main-only-adapter.d.ts +37 -0
- package/lib/app-supervisor/main-only-adapter.js +156 -0
- package/lib/app-supervisor/types.d.ts +161 -0
- package/lib/app-supervisor/types.js +24 -0
- package/lib/application.d.ts +10 -7
- package/lib/application.js +30 -18
- package/lib/commands/index.js +2 -0
- package/lib/commands/pm.js +11 -0
- package/lib/commands/repair.d.ts +11 -0
- package/lib/commands/repair.js +43 -0
- package/lib/commands/start.js +1 -1
- package/lib/event-queue.d.ts +8 -1
- package/lib/event-queue.js +25 -22
- package/lib/gateway/errors.js +50 -12
- package/lib/gateway/index.d.ts +8 -0
- package/lib/gateway/index.js +80 -16
- package/lib/gateway/ipc-socket-server.js +1 -1
- package/lib/gateway/ws-server.js +6 -2
- package/lib/helper.d.ts +359 -0
- package/lib/helper.js +78 -3
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -3
- package/lib/locale/locale.js +1 -1
- package/lib/locale/resource.js +6 -9
- package/lib/main-data-source.d.ts +11 -0
- package/lib/main-data-source.js +128 -0
- package/lib/middlewares/data-template.js +1 -6
- package/lib/middlewares/parse-variables.js +2 -49
- package/lib/plugin-manager/deps.js +2 -2
- package/lib/plugin-manager/options/resource.js +52 -25
- package/lib/plugin-manager/plugin-manager.d.ts +1 -0
- package/lib/plugin-manager/plugin-manager.js +36 -1
- package/lib/pub-sub-manager/pub-sub-manager.d.ts +1 -1
- package/lib/pub-sub-manager/pub-sub-manager.js +14 -20
- package/lib/redis-connection-manager.d.ts +15 -5
- package/lib/redis-connection-manager.js +117 -24
- package/lib/snowflake-id-field.d.ts +2 -1
- package/lib/snowflake-id-field.js +2 -2
- package/package.json +18 -17
- package/lib/app-supervisor.d.ts +0 -69
- package/lib/app-supervisor.js +0 -299
- package/lib/background-job-manager.d.ts +0 -40
- package/lib/background-job-manager.js +0 -111
package/lib/aes-encryptor.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare class AesEncryptor {
|
|
|
13
13
|
constructor(key: Buffer);
|
|
14
14
|
encrypt(text: string): Promise<string>;
|
|
15
15
|
decrypt(encryptedText: string): Promise<string>;
|
|
16
|
+
decryptSync(encryptedText: string): string;
|
|
16
17
|
static getOrGenerateKey(keyFilePath: string): Promise<Buffer>;
|
|
17
18
|
static getKeyPath(appName: string): Promise<string>;
|
|
18
19
|
static create(app: Application): Promise<AesEncryptor>;
|
package/lib/aes-encryptor.js
CHANGED
|
@@ -67,16 +67,19 @@ const _AesEncryptor = class _AesEncryptor {
|
|
|
67
67
|
async decrypt(encryptedText) {
|
|
68
68
|
return new Promise((resolve2, reject) => {
|
|
69
69
|
try {
|
|
70
|
-
|
|
71
|
-
const encrypted = Buffer.from(encryptedText.slice(32), "hex");
|
|
72
|
-
const decipher = import_crypto.default.createDecipheriv("aes-256-cbc", this.key, iv);
|
|
73
|
-
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
74
|
-
resolve2(decrypted.toString("utf8"));
|
|
70
|
+
resolve2(this.decryptSync(encryptedText));
|
|
75
71
|
} catch (error) {
|
|
76
72
|
reject(error);
|
|
77
73
|
}
|
|
78
74
|
});
|
|
79
75
|
}
|
|
76
|
+
decryptSync(encryptedText) {
|
|
77
|
+
const iv = Buffer.from(encryptedText.slice(0, 32), "hex");
|
|
78
|
+
const encrypted = Buffer.from(encryptedText.slice(32), "hex");
|
|
79
|
+
const decipher = import_crypto.default.createDecipheriv("aes-256-cbc", this.key, iv);
|
|
80
|
+
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
81
|
+
return decrypted.toString("utf8");
|
|
82
|
+
}
|
|
80
83
|
static async getOrGenerateKey(keyFilePath) {
|
|
81
84
|
try {
|
|
82
85
|
const key = await import_fs_extra.default.readFile(keyFilePath);
|
|
@@ -109,6 +112,10 @@ const _AesEncryptor = class _AesEncryptor {
|
|
|
109
112
|
return appKeyPath;
|
|
110
113
|
}
|
|
111
114
|
static async create(app) {
|
|
115
|
+
if (process.env.APP_AES_SECRET_KEY) {
|
|
116
|
+
const key2 = Buffer.from(process.env.APP_AES_SECRET_KEY, "hex");
|
|
117
|
+
return new _AesEncryptor(key2);
|
|
118
|
+
}
|
|
112
119
|
const KEY_PATH = process.env.APP_AES_SECRET_KEY_PATH;
|
|
113
120
|
const keyPath = KEY_PATH ? (0, import_path.resolve)(process.cwd(), KEY_PATH) : await this.getKeyPath(app.name);
|
|
114
121
|
const key = await _AesEncryptor.getOrGenerateKey(keyPath);
|
package/lib/app-command.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class AppCommand extends Command {
|
|
|
14
14
|
auth(): this;
|
|
15
15
|
preload(): this;
|
|
16
16
|
hasCommand(name: string): boolean;
|
|
17
|
+
findCommand(name: string): any;
|
|
17
18
|
isHandleByIPCServer(): boolean;
|
|
18
19
|
createCommand(name?: string): AppCommand;
|
|
19
20
|
parseHandleByIPCServer(argv: any, parseOptions?: any): Boolean;
|
package/lib/app-command.js
CHANGED
|
@@ -51,6 +51,9 @@ const _AppCommand = class _AppCommand extends import_commander.Command {
|
|
|
51
51
|
const names = this.commands.map((c) => c.name());
|
|
52
52
|
return names.includes(name);
|
|
53
53
|
}
|
|
54
|
+
findCommand(name) {
|
|
55
|
+
return this._findCommand(name);
|
|
56
|
+
}
|
|
54
57
|
isHandleByIPCServer() {
|
|
55
58
|
return this._handleByIPCServer;
|
|
56
59
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
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 { IDatabaseOptions } from '@nocobase/database';
|
|
10
|
+
import Application from '../application';
|
|
11
|
+
import { AppModelOptions } from './types';
|
|
12
|
+
export declare const appOptionsFactory: (appName: string, mainApp: Application, options: AppModelOptions) => {
|
|
13
|
+
dbConnType: string;
|
|
14
|
+
database: {
|
|
15
|
+
tablePrefix: string;
|
|
16
|
+
migrator?: any;
|
|
17
|
+
usingBigIntForId?: boolean;
|
|
18
|
+
underscored?: boolean;
|
|
19
|
+
logger?: import("@nocobase/logger/lib/logger").Logger | import("@nocobase/logger/lib/logger").LoggerOptions;
|
|
20
|
+
customHooks?: any;
|
|
21
|
+
instanceId?: string;
|
|
22
|
+
addAllCollections?: boolean;
|
|
23
|
+
dialect?: import("sequelize").Dialect;
|
|
24
|
+
dialectModule?: object;
|
|
25
|
+
dialectModulePath?: string;
|
|
26
|
+
dialectOptions?: object;
|
|
27
|
+
storage?: string;
|
|
28
|
+
database?: string;
|
|
29
|
+
username?: string;
|
|
30
|
+
password?: string;
|
|
31
|
+
host?: string;
|
|
32
|
+
port?: number;
|
|
33
|
+
ssl?: boolean;
|
|
34
|
+
protocol?: string;
|
|
35
|
+
define?: import("sequelize").ModelOptions<import("sequelize").Model<any, any>>;
|
|
36
|
+
query?: import("sequelize").QueryOptions;
|
|
37
|
+
set?: import("sequelize").DefaultSetOptions;
|
|
38
|
+
sync?: import("@nocobase/database").SyncOptions;
|
|
39
|
+
timezone?: string;
|
|
40
|
+
omitNull?: boolean;
|
|
41
|
+
native?: boolean;
|
|
42
|
+
replication?: false | import("sequelize").ReplicationOptions;
|
|
43
|
+
pool?: import("sequelize").PoolOptions;
|
|
44
|
+
quoteIdentifiers?: boolean;
|
|
45
|
+
isolationLevel?: string;
|
|
46
|
+
transactionType?: import("@nocobase/database").Transaction.TYPES;
|
|
47
|
+
typeValidation?: boolean;
|
|
48
|
+
operatorsAliases?: import("sequelize").OperatorsAliases;
|
|
49
|
+
standardConformingStrings?: boolean;
|
|
50
|
+
clientMinMessages?: string | boolean;
|
|
51
|
+
hooks?: Partial<import("sequelize/types/hooks").SequelizeHooks<import("sequelize").Model<any, any>, any, any>>;
|
|
52
|
+
minifyAliases?: boolean;
|
|
53
|
+
logQueryParameters?: boolean;
|
|
54
|
+
retry?: import("retry-as-promised").Options;
|
|
55
|
+
schema?: string;
|
|
56
|
+
attributeBehavior?: "escape" | "throw" | "unsafe-legacy";
|
|
57
|
+
logging?: boolean | ((sql: string, timing?: number) => void);
|
|
58
|
+
benchmark?: boolean;
|
|
59
|
+
};
|
|
60
|
+
plugins: string[];
|
|
61
|
+
resourcer: {
|
|
62
|
+
prefix: string;
|
|
63
|
+
};
|
|
64
|
+
cacheManager: {
|
|
65
|
+
prefix: string;
|
|
66
|
+
defaultStore?: string;
|
|
67
|
+
stores?: {
|
|
68
|
+
[storeType: string]: {
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
store?: "memory" | import("cache-manager").FactoryStore<import("cache-manager").Store, any>;
|
|
71
|
+
close?: (store: import("cache-manager").Store) => Promise<void>;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
logger: import("../application").AppLoggerOptions;
|
|
76
|
+
} & {
|
|
77
|
+
name: string;
|
|
78
|
+
dbConnType?: string;
|
|
79
|
+
database?: IDatabaseOptions;
|
|
80
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
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 app_options_factory_exports = {};
|
|
39
|
+
__export(app_options_factory_exports, {
|
|
40
|
+
appOptionsFactory: () => appOptionsFactory
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(app_options_factory_exports);
|
|
43
|
+
var import_database = require("@nocobase/database");
|
|
44
|
+
var import_lodash = __toESM(require("lodash"));
|
|
45
|
+
var import_path = __toESM(require("path"));
|
|
46
|
+
var import_lodash2 = __toESM(require("lodash"));
|
|
47
|
+
function getDatabaseConfig(app) {
|
|
48
|
+
let oldConfig = app.options.database instanceof import_database.Database ? app.options.database.options : app.options.database;
|
|
49
|
+
if (!oldConfig && app.db) {
|
|
50
|
+
oldConfig = app.db.options;
|
|
51
|
+
}
|
|
52
|
+
return import_lodash.default.cloneDeep(import_lodash.default.omit(oldConfig, ["migrator"]));
|
|
53
|
+
}
|
|
54
|
+
__name(getDatabaseConfig, "getDatabaseConfig");
|
|
55
|
+
const appOptionsFactory = /* @__PURE__ */ __name((appName, mainApp, options) => {
|
|
56
|
+
const rawDatabaseOptions = getDatabaseConfig(mainApp);
|
|
57
|
+
let dbConnType = "new_database";
|
|
58
|
+
if (rawDatabaseOptions.dialect === "sqlite") {
|
|
59
|
+
const mainAppStorage = rawDatabaseOptions.storage;
|
|
60
|
+
if (mainAppStorage !== ":memory:") {
|
|
61
|
+
const mainStorageDir = import_path.default.dirname(mainAppStorage);
|
|
62
|
+
rawDatabaseOptions.storage = import_path.default.join(mainStorageDir, `${appName}.sqlite`);
|
|
63
|
+
}
|
|
64
|
+
} else if (process.env.USE_DB_SCHEMA_IN_SUBAPP === "true" && ["postgres", "kingbase"].includes(rawDatabaseOptions.dialect)) {
|
|
65
|
+
rawDatabaseOptions.schema = appName;
|
|
66
|
+
dbConnType = "new_schema";
|
|
67
|
+
} else if ((options == null ? void 0 : options.dbConnType) !== "new_schema") {
|
|
68
|
+
rawDatabaseOptions.database = appName;
|
|
69
|
+
}
|
|
70
|
+
const defaultOptions = {
|
|
71
|
+
dbConnType,
|
|
72
|
+
database: {
|
|
73
|
+
...rawDatabaseOptions,
|
|
74
|
+
tablePrefix: ""
|
|
75
|
+
},
|
|
76
|
+
plugins: ["nocobase"],
|
|
77
|
+
resourcer: {
|
|
78
|
+
prefix: process.env.API_BASE_PATH
|
|
79
|
+
},
|
|
80
|
+
cacheManager: {
|
|
81
|
+
...mainApp.options.cacheManager,
|
|
82
|
+
prefix: appName
|
|
83
|
+
},
|
|
84
|
+
logger: mainApp.options.logger
|
|
85
|
+
};
|
|
86
|
+
return import_lodash2.default.merge({}, defaultOptions, { ...options, name: appName });
|
|
87
|
+
}, "appOptionsFactory");
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
appOptionsFactory
|
|
91
|
+
});
|
|
@@ -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 type Predicate<C> = (ctx: C) => boolean | Promise<boolean>;
|
|
10
|
+
type Handler<C, R> = (ctx: C) => R | Promise<R>;
|
|
11
|
+
export declare class ConditionalRegistry<C, R> {
|
|
12
|
+
private rules;
|
|
13
|
+
private defaultHandler?;
|
|
14
|
+
register(when: Predicate<C>, run: Handler<C, R>, priority?: number): void;
|
|
15
|
+
setDefault(run: Handler<C, R>): void;
|
|
16
|
+
run(ctx: C): Promise<R>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
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 condition_registry_exports = {};
|
|
29
|
+
__export(condition_registry_exports, {
|
|
30
|
+
ConditionalRegistry: () => ConditionalRegistry
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(condition_registry_exports);
|
|
33
|
+
const _ConditionalRegistry = class _ConditionalRegistry {
|
|
34
|
+
rules = [];
|
|
35
|
+
defaultHandler;
|
|
36
|
+
register(when, run, priority = 0) {
|
|
37
|
+
this.rules.push({ when, run, priority });
|
|
38
|
+
this.rules.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
39
|
+
}
|
|
40
|
+
setDefault(run) {
|
|
41
|
+
this.defaultHandler = run;
|
|
42
|
+
}
|
|
43
|
+
async run(ctx) {
|
|
44
|
+
for (const rule of this.rules) {
|
|
45
|
+
if (await rule.when(ctx)) {
|
|
46
|
+
return await rule.run(ctx);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (this.defaultHandler) {
|
|
50
|
+
return await this.defaultHandler(ctx);
|
|
51
|
+
}
|
|
52
|
+
throw new Error("No handler matched and no default handler defined");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
__name(_ConditionalRegistry, "ConditionalRegistry");
|
|
56
|
+
let ConditionalRegistry = _ConditionalRegistry;
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
ConditionalRegistry
|
|
60
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { Predicate } from './condition-registry';
|
|
10
|
+
import type { AppDbCreator, AppDbCreatorOptions } from './types';
|
|
11
|
+
export declare const createDatabaseCondition: Predicate<AppDbCreatorOptions>;
|
|
12
|
+
export declare const createConnectionCondition: Predicate<AppDbCreatorOptions>;
|
|
13
|
+
export declare const createSchemaCondition: Predicate<AppDbCreatorOptions>;
|
|
14
|
+
export declare const createDatabase: AppDbCreator;
|
|
15
|
+
export declare const createConnection: AppDbCreator;
|
|
16
|
+
export declare const createSchema: AppDbCreator;
|
|
@@ -0,0 +1,163 @@
|
|
|
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 db_creator_exports = {};
|
|
29
|
+
__export(db_creator_exports, {
|
|
30
|
+
createConnection: () => createConnection,
|
|
31
|
+
createConnectionCondition: () => createConnectionCondition,
|
|
32
|
+
createDatabase: () => createDatabase,
|
|
33
|
+
createDatabaseCondition: () => createDatabaseCondition,
|
|
34
|
+
createSchema: () => createSchema,
|
|
35
|
+
createSchemaCondition: () => createSchemaCondition
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(db_creator_exports);
|
|
38
|
+
var import_db_drivers = require("./db-drivers");
|
|
39
|
+
async function createMySQLDatabase({
|
|
40
|
+
host,
|
|
41
|
+
port,
|
|
42
|
+
username,
|
|
43
|
+
password,
|
|
44
|
+
database,
|
|
45
|
+
driver
|
|
46
|
+
}) {
|
|
47
|
+
var _a;
|
|
48
|
+
const conn = await driver.createConnection({
|
|
49
|
+
host,
|
|
50
|
+
port,
|
|
51
|
+
user: username,
|
|
52
|
+
password
|
|
53
|
+
});
|
|
54
|
+
await conn.query(`CREATE DATABASE IF NOT EXISTS \`${database}\``);
|
|
55
|
+
await (((_a = conn.end) == null ? void 0 : _a.call(conn)) ?? conn.close());
|
|
56
|
+
}
|
|
57
|
+
__name(createMySQLDatabase, "createMySQLDatabase");
|
|
58
|
+
async function withPgClient(options, fn) {
|
|
59
|
+
const { Client } = (0, import_db_drivers.loadPgModule)();
|
|
60
|
+
const client = new Client(options);
|
|
61
|
+
await client.connect();
|
|
62
|
+
try {
|
|
63
|
+
await fn(client);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.log(e);
|
|
66
|
+
} finally {
|
|
67
|
+
await client.end();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
__name(withPgClient, "withPgClient");
|
|
71
|
+
const createDatabaseCondition = /* @__PURE__ */ __name(({ appOptions }) => !(appOptions == null ? void 0 : appOptions.dbConnType) || appOptions.dbConnType === "new_database", "createDatabaseCondition");
|
|
72
|
+
const createConnectionCondition = /* @__PURE__ */ __name(({ appOptions }) => (appOptions == null ? void 0 : appOptions.dbConnType) === "new_connection", "createConnectionCondition");
|
|
73
|
+
const createSchemaCondition = /* @__PURE__ */ __name(({ appOptions }) => appOptions.dbConnType === "new_schema", "createSchemaCondition");
|
|
74
|
+
const createDatabase = /* @__PURE__ */ __name(async ({ app }) => {
|
|
75
|
+
const { host, port, username, password, dialect, database } = app.options.database;
|
|
76
|
+
if (dialect === "mysql") {
|
|
77
|
+
const mysql = (0, import_db_drivers.loadMysqlDriver)();
|
|
78
|
+
return createMySQLDatabase({
|
|
79
|
+
host,
|
|
80
|
+
port,
|
|
81
|
+
username,
|
|
82
|
+
password,
|
|
83
|
+
database,
|
|
84
|
+
driver: mysql
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (dialect === "mariadb") {
|
|
88
|
+
const mariadb = (0, import_db_drivers.loadMariadbDriver)();
|
|
89
|
+
return createMySQLDatabase({
|
|
90
|
+
host,
|
|
91
|
+
port,
|
|
92
|
+
username,
|
|
93
|
+
password,
|
|
94
|
+
database,
|
|
95
|
+
driver: mariadb
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (["postgres", "kingbase"].includes(dialect)) {
|
|
99
|
+
return withPgClient({ host, port, user: username, password, database: dialect }, async (client) => {
|
|
100
|
+
const exists = await client.query("SELECT 1 FROM pg_database WHERE datname = $1", [database]);
|
|
101
|
+
if (exists.rowCount === 0) {
|
|
102
|
+
await client.query(`CREATE DATABASE "${database}"`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}, "createDatabase");
|
|
107
|
+
const createConnection = /* @__PURE__ */ __name(async ({ app }) => {
|
|
108
|
+
const { host, port, username, password, dialect, database, schema } = app.options.database;
|
|
109
|
+
if (dialect === "mysql") {
|
|
110
|
+
const mysql = (0, import_db_drivers.loadMysqlDriver)();
|
|
111
|
+
return createMySQLDatabase({
|
|
112
|
+
host,
|
|
113
|
+
port,
|
|
114
|
+
username,
|
|
115
|
+
password,
|
|
116
|
+
database,
|
|
117
|
+
driver: mysql
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (dialect === "mariadb") {
|
|
121
|
+
const mariadb = (0, import_db_drivers.loadMariadbDriver)();
|
|
122
|
+
return createMySQLDatabase({
|
|
123
|
+
host,
|
|
124
|
+
port,
|
|
125
|
+
username,
|
|
126
|
+
password,
|
|
127
|
+
database,
|
|
128
|
+
driver: mariadb
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (["postgres", "kingbase"].includes(dialect)) {
|
|
132
|
+
if (schema) {
|
|
133
|
+
return withPgClient(
|
|
134
|
+
{ host, port, user: username, password, database },
|
|
135
|
+
(client) => client.query(`CREATE SCHEMA IF NOT EXISTS ${schema}`)
|
|
136
|
+
);
|
|
137
|
+
} else {
|
|
138
|
+
return withPgClient(
|
|
139
|
+
{ host, port, user: username, password, database: dialect },
|
|
140
|
+
(client) => client.query(`CREATE DATABASE "${database}"`)
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, "createConnection");
|
|
145
|
+
const createSchema = /* @__PURE__ */ __name(async ({ app }) => {
|
|
146
|
+
const { host, port, username, password, dialect, schema, database } = app.options.database;
|
|
147
|
+
if (!["postgres", "kingbase"].includes(dialect)) {
|
|
148
|
+
throw new Error("Schema is only supported for postgres/kingbase");
|
|
149
|
+
}
|
|
150
|
+
return withPgClient(
|
|
151
|
+
{ host, port, user: username, password, database },
|
|
152
|
+
(client) => client.query(`CREATE SCHEMA IF NOT EXISTS ${schema}`)
|
|
153
|
+
);
|
|
154
|
+
}, "createSchema");
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
createConnection,
|
|
158
|
+
createConnectionCondition,
|
|
159
|
+
createDatabase,
|
|
160
|
+
createDatabaseCondition,
|
|
161
|
+
createSchema,
|
|
162
|
+
createSchemaCondition
|
|
163
|
+
});
|
|
@@ -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
|
+
export declare function loadMysqlDriver(): any;
|
|
10
|
+
export declare function loadMariadbDriver(): any;
|
|
11
|
+
export declare function loadPgModule(): any;
|
|
@@ -0,0 +1,52 @@
|
|
|
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 db_drivers_exports = {};
|
|
29
|
+
__export(db_drivers_exports, {
|
|
30
|
+
loadMariadbDriver: () => loadMariadbDriver,
|
|
31
|
+
loadMysqlDriver: () => loadMysqlDriver,
|
|
32
|
+
loadPgModule: () => loadPgModule
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(db_drivers_exports);
|
|
35
|
+
function loadMysqlDriver() {
|
|
36
|
+
return require("mysql2/promise");
|
|
37
|
+
}
|
|
38
|
+
__name(loadMysqlDriver, "loadMysqlDriver");
|
|
39
|
+
function loadMariadbDriver() {
|
|
40
|
+
return require("mariadb");
|
|
41
|
+
}
|
|
42
|
+
__name(loadMariadbDriver, "loadMariadbDriver");
|
|
43
|
+
function loadPgModule() {
|
|
44
|
+
return require("pg");
|
|
45
|
+
}
|
|
46
|
+
__name(loadPgModule, "loadPgModule");
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
loadMariadbDriver,
|
|
50
|
+
loadMysqlDriver,
|
|
51
|
+
loadPgModule
|
|
52
|
+
});
|