@nocobase/server 2.0.0-beta.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/lib/aes-encryptor.d.ts +1 -0
  2. package/lib/aes-encryptor.js +8 -5
  3. package/lib/ai/create-docs-index.d.ts +13 -0
  4. package/lib/ai/create-docs-index.js +892 -0
  5. package/lib/app-supervisor/app-options-factory.d.ts +80 -0
  6. package/lib/app-supervisor/app-options-factory.js +91 -0
  7. package/lib/app-supervisor/condition-registry.d.ts +18 -0
  8. package/lib/app-supervisor/condition-registry.js +60 -0
  9. package/lib/app-supervisor/db-creator.d.ts +16 -0
  10. package/lib/app-supervisor/db-creator.js +163 -0
  11. package/lib/app-supervisor/db-drivers.d.ts +11 -0
  12. package/lib/app-supervisor/db-drivers.js +52 -0
  13. package/lib/app-supervisor/index.d.ts +161 -0
  14. package/lib/app-supervisor/index.js +690 -0
  15. package/lib/app-supervisor/main-only-adapter.d.ts +37 -0
  16. package/lib/app-supervisor/main-only-adapter.js +156 -0
  17. package/lib/app-supervisor/types.d.ts +161 -0
  18. package/lib/app-supervisor/types.js +24 -0
  19. package/lib/application.d.ts +3 -1
  20. package/lib/application.js +10 -6
  21. package/lib/commands/ai.d.ts +11 -0
  22. package/lib/commands/ai.js +40 -0
  23. package/lib/commands/console.js +1 -1
  24. package/lib/commands/index.js +2 -0
  25. package/lib/commands/install.js +2 -0
  26. package/lib/commands/start.js +3 -0
  27. package/lib/commands/upgrade.js +2 -0
  28. package/lib/gateway/errors.js +1 -1
  29. package/lib/gateway/index.js +64 -15
  30. package/lib/gateway/ipc-socket-server.js +1 -1
  31. package/lib/gateway/ws-server.js +3 -2
  32. package/lib/helper.js +20 -3
  33. package/lib/plugin-manager/deps.js +1 -1
  34. package/lib/plugin-manager/plugin-manager.js +2 -0
  35. package/lib/plugin.d.ts +5 -0
  36. package/lib/plugin.js +25 -0
  37. package/lib/redis-connection-manager.d.ts +15 -5
  38. package/lib/redis-connection-manager.js +117 -24
  39. package/package.json +18 -17
  40. package/lib/app-supervisor.d.ts +0 -74
  41. package/lib/app-supervisor.js +0 -338
@@ -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
+ });
@@ -0,0 +1,161 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ /// <reference types="node" />
10
+ /// <reference types="node" />
11
+ /// <reference types="node" />
12
+ import { IncomingMessage, ServerResponse } from 'http';
13
+ import { AsyncEmitter } from '@nocobase/utils';
14
+ import { EventEmitter } from 'events';
15
+ import Application, { ApplicationOptions } from '../application';
16
+ import type { AppDiscoveryAdapter, AppProcessAdapter, AppStatus, EnvironmentInfo, GetAppOptions, ProcessCommand, AppDbCreator, AppOptionsFactory, AppDbCreatorOptions, AppCommandAdapter, AppModel, BootstrapLock } from './types';
17
+ import { Predicate } from './condition-registry';
18
+ import { PubSubManagerPublishOptions } from '../pub-sub-manager';
19
+ import { Transaction, Transactionable } from '@nocobase/database';
20
+ import { SystemLogger } from '@nocobase/logger';
21
+ import AesEncryptor from '../aes-encryptor';
22
+ export type AppDiscoveryAdapterFactory = (context: {
23
+ supervisor: AppSupervisor;
24
+ }) => AppDiscoveryAdapter;
25
+ export type AppProcessAdapterFactory = (context: {
26
+ supervisor: AppSupervisor;
27
+ }) => AppProcessAdapter;
28
+ export type AppCommandAdapterFactory = (context: {
29
+ supervisor: AppSupervisor;
30
+ }) => AppCommandAdapter;
31
+ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter {
32
+ private static instance;
33
+ private static discoveryAdapterFactories;
34
+ private static processAdapterFactories;
35
+ private static commandAdapterFactories;
36
+ private static defaultDiscoveryAdapterName;
37
+ private static defaultProcessAdapterName;
38
+ private static defaultCommandAdapterName;
39
+ runningMode: 'single' | 'multiple';
40
+ singleAppName: string | null;
41
+ logger: SystemLogger;
42
+ aesEncryptor?: AesEncryptor;
43
+ emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
44
+ private discoveryAdapter;
45
+ private processAdapter;
46
+ private commandAdapter;
47
+ private discoveryAdapterName;
48
+ private processAdapterName;
49
+ private commandAdapterName;
50
+ private appDbCreator;
51
+ appOptionsFactory: AppOptionsFactory;
52
+ private environmentHeartbeatInterval;
53
+ private environmentHeartbeatTimer;
54
+ private constructor();
55
+ private resolveDiscoveryAdapterName;
56
+ private resolveProcessAdapterName;
57
+ private resolveCommandAdapterName;
58
+ private createDiscoveryAdapter;
59
+ private isProcessCapableAdapter;
60
+ private createProcessAdapter;
61
+ private createCommandAdapter;
62
+ static registerDiscoveryAdapter(name: string, factory: AppDiscoveryAdapterFactory): void;
63
+ static registerProcessAdapter(name: string, factory: AppProcessAdapterFactory): void;
64
+ static registerCommandAdapter(name: string, factory: AppCommandAdapterFactory): void;
65
+ static setDefaultDiscoveryAdapter(name: string): void;
66
+ static setDefaultProcessAdapter(name: string): void;
67
+ static setDefaultCommandAdapter(name: string): void;
68
+ static getInstance(): AppSupervisor;
69
+ get apps(): Record<string, Application>;
70
+ get appStatus(): Record<string, AppStatus>;
71
+ get appErrors(): Record<string, Error>;
72
+ get lastSeenAt(): Map<string, number>;
73
+ get lastMaintainingMessage(): Record<string, string>;
74
+ get statusBeforeCommanding(): Record<string, AppStatus>;
75
+ get environmentName(): string;
76
+ get environmentUrl(): string;
77
+ get environmentProxyUrl(): string;
78
+ getProcessAdapter(): AppProcessAdapter;
79
+ getDiscoveryAdapter(): AppDiscoveryAdapter;
80
+ registerAppDbCreator(condition: Predicate<AppDbCreatorOptions>, creator: AppDbCreator, priority?: number): void;
81
+ createDatabase(options: AppDbCreatorOptions): Promise<void>;
82
+ setAppOptionsFactory(factory: AppOptionsFactory): void;
83
+ bootstrapApp(appName: string): Promise<void>;
84
+ initApp({ appName, options }: {
85
+ appName: string;
86
+ options?: {
87
+ upgrading?: boolean;
88
+ };
89
+ }): Promise<void>;
90
+ setAppError(appName: string, error: Error): void;
91
+ hasAppError(appName: string): boolean;
92
+ clearAppError(appName: string): void;
93
+ reset(): Promise<void>;
94
+ destroy(): Promise<void>;
95
+ getAppStatus(appName: string, defaultStatus?: AppStatus): Promise<AppStatus>;
96
+ setAppStatus(appName: string, status: AppStatus, options?: {}): Promise<void>;
97
+ clearAppStatus(appName: string): Promise<void>;
98
+ getAppsStatuses(appNames?: string[]): Promise<import("./types").AppStatusesResult>;
99
+ getBootstrapLock(appName: string): Promise<BootstrapLock | null>;
100
+ registerApp({ appModel, mainApp, hook }: {
101
+ appModel: AppModel;
102
+ mainApp?: Application;
103
+ hook?: boolean;
104
+ }): Application<import("../application").DefaultState, import("../application").DefaultContext>;
105
+ bootMainApp(options: ApplicationOptions): Application<import("../application").DefaultState, import("../application").DefaultContext>;
106
+ setAppLastSeenAt(appName: string): Promise<void>;
107
+ getAppLastSeenAt(appName: string): Promise<number>;
108
+ addAppModel(appModel: AppModel): Promise<void>;
109
+ getAppModel(appName: string): Promise<AppModel>;
110
+ removeAppModel(appName: string): Promise<void>;
111
+ getAppNameByCName(cname: string): Promise<string>;
112
+ addAutoStartApps(environmentName: string, appNames: string[]): Promise<void>;
113
+ getAutoStartApps(): Promise<string[]>;
114
+ removeAutoStartApps(environmentName: string, appNames: string[]): Promise<void>;
115
+ addApp(app: Application): Application<import("../application").DefaultState, import("../application").DefaultContext>;
116
+ getApp(appName: string, options?: GetAppOptions): Promise<Application<import("../application").DefaultState, import("../application").DefaultContext>>;
117
+ hasApp(appName: string): boolean;
118
+ createApp(options: {
119
+ appModel: AppModel;
120
+ mainApp?: Application;
121
+ transaction?: Transaction;
122
+ }, context?: {
123
+ requestId: string;
124
+ }): Promise<void>;
125
+ startApp(appName: string, context?: {
126
+ requestId: string;
127
+ }): Promise<void>;
128
+ stopApp(appName: string, context?: {
129
+ requestId: string;
130
+ }): Promise<void>;
131
+ removeApp(appName: string, context?: {
132
+ requestId: string;
133
+ }): Promise<void>;
134
+ upgradeApp(appName: string, context?: {
135
+ requestId: string;
136
+ }): Promise<void>;
137
+ /**
138
+ * @deprecated
139
+ * use {#getApps} instead
140
+ */
141
+ subApps(): Application<import("../application").DefaultState, import("../application").DefaultContext>[];
142
+ getApps(): Application<import("../application").DefaultState, import("../application").DefaultContext>[];
143
+ proxyWeb(appName: string, req: IncomingMessage, res: ServerResponse): Promise<boolean>;
144
+ proxyWs(req: IncomingMessage, socket: any, head: Buffer): Promise<boolean>;
145
+ registerEnvironment(mainApp: Application): Promise<void>;
146
+ unregisterEnvironment(): Promise<void>;
147
+ private normalizeEnvInfo;
148
+ listEnvironments(): Promise<EnvironmentInfo[]>;
149
+ getEnvironment(environmentName: string): Promise<EnvironmentInfo>;
150
+ heartbeatEnvironment(): Promise<void>;
151
+ dispatchCommand(command: ProcessCommand): Promise<void>;
152
+ registerCommandHandler(mainApp: Application): void;
153
+ sendSyncMessage(mainApp: Application, message: {
154
+ type: string;
155
+ appName: string;
156
+ }, options?: PubSubManagerPublishOptions & Transactionable): Promise<void>;
157
+ on(eventName: string | symbol, listener: (...args: any[]) => void): this;
158
+ private bindAppEvents;
159
+ }
160
+ export type { AppDiscoveryAdapter, AppProcessAdapter, AppCommandAdapter, AppStatus, ProcessCommand, EnvironmentInfo, GetAppOptions, AppDbCreator, AppOptionsFactory, AppModel, AppModelOptions, BootstrapLock, } from './types';
161
+ export { MainOnlyAdapter } from './main-only-adapter';