@nocobase/server 1.2.13-alpha → 1.3.0-alpha.20240710084543
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -14
- package/lib/acl/available-action.d.ts +0 -13
- package/lib/acl/available-action.js +0 -71
- package/lib/acl/index.d.ts +0 -10
- package/lib/acl/index.js +0 -46
- package/lib/app-command.d.ts +0 -20
- package/lib/app-command.js +0 -82
- package/lib/app-supervisor.d.ts +0 -69
- package/lib/app-supervisor.js +0 -302
- package/lib/application.d.ts +0 -345
- package/lib/application.js +0 -876
- package/lib/cache/index.d.ts +0 -11
- package/lib/cache/index.js +0 -44
- package/lib/commands/console.d.ts +0 -11
- package/lib/commands/console.js +0 -48
- package/lib/commands/create-migration.d.ts +0 -11
- package/lib/commands/create-migration.js +0 -79
- package/lib/commands/db-auth.d.ts +0 -11
- package/lib/commands/db-auth.js +0 -38
- package/lib/commands/db-clean.d.ts +0 -11
- package/lib/commands/db-clean.js +0 -41
- package/lib/commands/db-sync.d.ts +0 -11
- package/lib/commands/db-sync.js +0 -50
- package/lib/commands/destroy.d.ts +0 -11
- package/lib/commands/destroy.js +0 -40
- package/lib/commands/index.d.ts +0 -10
- package/lib/commands/index.js +0 -82
- package/lib/commands/install.d.ts +0 -11
- package/lib/commands/install.js +0 -43
- package/lib/commands/migrator.d.ts +0 -11
- package/lib/commands/migrator.js +0 -41
- package/lib/commands/pm.d.ts +0 -11
- package/lib/commands/pm.js +0 -98
- package/lib/commands/refresh.d.ts +0 -11
- package/lib/commands/refresh.js +0 -41
- package/lib/commands/restart.d.ts +0 -11
- package/lib/commands/restart.js +0 -45
- package/lib/commands/start.d.ts +0 -11
- package/lib/commands/start.js +0 -85
- package/lib/commands/stop.d.ts +0 -11
- package/lib/commands/stop.js +0 -44
- package/lib/commands/upgrade.d.ts +0 -14
- package/lib/commands/upgrade.js +0 -39
- package/lib/cron/cron-job-manager.d.ts +0 -22
- package/lib/cron/cron-job-manager.js +0 -82
- package/lib/errors/application-not-install.d.ts +0 -12
- package/lib/errors/application-not-install.js +0 -45
- package/lib/errors/handler.d.ts +0 -11
- package/lib/errors/handler.js +0 -50
- package/lib/errors/plugin-command-error.d.ts +0 -10
- package/lib/errors/plugin-command-error.js +0 -40
- package/lib/errors/plugin-not-exist.d.ts +0 -10
- package/lib/errors/plugin-not-exist.js +0 -40
- package/lib/gateway/errors.d.ts +0 -30
- package/lib/gateway/errors.js +0 -154
- package/lib/gateway/index.d.ts +0 -79
- package/lib/gateway/index.js +0 -393
- package/lib/gateway/ipc-socket-client.d.ts +0 -27
- package/lib/gateway/ipc-socket-client.js +0 -110
- package/lib/gateway/ipc-socket-server.d.ts +0 -21
- package/lib/gateway/ipc-socket-server.js +0 -150
- package/lib/gateway/ws-server.d.ts +0 -36
- package/lib/gateway/ws-server.js +0 -196
- package/lib/helper.d.ts +0 -18
- package/lib/helper.js +0 -193
- package/lib/helpers/application-version.d.ts +0 -18
- package/lib/helpers/application-version.js +0 -88
- package/lib/index.d.ts +0 -17
- package/lib/index.js +0 -64
- package/lib/locale/index.d.ts +0 -9
- package/lib/locale/index.js +0 -30
- package/lib/locale/locale.d.ts +0 -38
- package/lib/locale/locale.js +0 -174
- package/lib/locale/resource.d.ts +0 -9
- package/lib/locale/resource.js +0 -87
- package/lib/main-data-source.d.ts +0 -12
- package/lib/main-data-source.js +0 -57
- package/lib/middlewares/data-template.d.ts +0 -10
- package/lib/middlewares/data-template.js +0 -146
- package/lib/middlewares/data-wrapping.d.ts +0 -11
- package/lib/middlewares/data-wrapping.js +0 -100
- package/lib/middlewares/i18n.d.ts +0 -9
- package/lib/middlewares/i18n.js +0 -53
- package/lib/middlewares/index.d.ts +0 -10
- package/lib/middlewares/index.js +0 -39
- package/lib/middlewares/parse-variables.d.ts +0 -9
- package/lib/middlewares/parse-variables.js +0 -95
- package/lib/middlewares/validate-filter-params.d.ts +0 -9
- package/lib/middlewares/validate-filter-params.js +0 -42
- package/lib/migration.d.ts +0 -20
- package/lib/migration.js +0 -54
- package/lib/migrations/20230912193824-package-name-unique.d.ts +0 -14
- package/lib/migrations/20230912193824-package-name-unique.js +0 -59
- package/lib/migrations/20230912294620-update-pkg.d.ts +0 -14
- package/lib/migrations/20230912294620-update-pkg.js +0 -65
- package/lib/migrations/20240106082756-update-plugins.d.ts +0 -14
- package/lib/migrations/20240106082756-update-plugins.js +0 -51
- package/lib/migrations/20240428235620-rename-plugins.d.ts +0 -14
- package/lib/migrations/20240428235620-rename-plugins.js +0 -49
- package/lib/plugin-manager/clientStaticUtils.d.ts +0 -31
- package/lib/plugin-manager/clientStaticUtils.js +0 -129
- package/lib/plugin-manager/constants.d.ts +0 -15
- package/lib/plugin-manager/constants.js +0 -135
- package/lib/plugin-manager/deps.d.ts +0 -10
- package/lib/plugin-manager/deps.js +0 -83
- package/lib/plugin-manager/index.d.ts +0 -10
- package/lib/plugin-manager/index.js +0 -32
- package/lib/plugin-manager/middleware.d.ts +0 -10
- package/lib/plugin-manager/middleware.js +0 -45
- package/lib/plugin-manager/options/collection.d.ts +0 -10
- package/lib/plugin-manager/options/collection.js +0 -47
- package/lib/plugin-manager/options/resource.d.ts +0 -23
- package/lib/plugin-manager/options/resource.js +0 -186
- package/lib/plugin-manager/plugin-manager-repository.d.ts +0 -36
- package/lib/plugin-manager/plugin-manager-repository.js +0 -158
- package/lib/plugin-manager/plugin-manager.d.ts +0 -206
- package/lib/plugin-manager/plugin-manager.js +0 -1100
- package/lib/plugin-manager/types.d.ts +0 -23
- package/lib/plugin-manager/types.js +0 -24
- package/lib/plugin-manager/utils.d.ts +0 -115
- package/lib/plugin-manager/utils.js +0 -568
- package/lib/plugin.d.ts +0 -99
- package/lib/plugin.js +0 -228
- package/lib/swagger/index.json +0 -1569
package/lib/application.js
DELETED
|
@@ -1,876 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
-
var __export = (target, all) => {
|
|
18
|
-
for (var name in all)
|
|
19
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
-
};
|
|
21
|
-
var __copyProps = (to, from, except, desc) => {
|
|
22
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(from))
|
|
24
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var application_exports = {};
|
|
39
|
-
__export(application_exports, {
|
|
40
|
-
Application: () => Application,
|
|
41
|
-
default: () => application_default
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(application_exports);
|
|
44
|
-
var import_actions = require("@nocobase/actions");
|
|
45
|
-
var import_auth = require("@nocobase/auth");
|
|
46
|
-
var import_database = __toESM(require("@nocobase/database"));
|
|
47
|
-
var import_logger = require("@nocobase/logger");
|
|
48
|
-
var import_telemetry = require("@nocobase/telemetry");
|
|
49
|
-
var import_utils = require("@nocobase/utils");
|
|
50
|
-
var import_crypto = require("crypto");
|
|
51
|
-
var import_glob = __toESM(require("glob"));
|
|
52
|
-
var import_koa = __toESM(require("koa"));
|
|
53
|
-
var import_koa_compose = __toESM(require("koa-compose"));
|
|
54
|
-
var import_lodash = __toESM(require("lodash"));
|
|
55
|
-
var import_path = require("path");
|
|
56
|
-
var import_semver = __toESM(require("semver"));
|
|
57
|
-
var import_acl = require("./acl");
|
|
58
|
-
var import_app_command = require("./app-command");
|
|
59
|
-
var import_app_supervisor = require("./app-supervisor");
|
|
60
|
-
var import_cache2 = require("./cache");
|
|
61
|
-
var import_commands = require("./commands");
|
|
62
|
-
var import_cron_job_manager = require("./cron/cron-job-manager");
|
|
63
|
-
var import_application_not_install = require("./errors/application-not-install");
|
|
64
|
-
var import_helper = require("./helper");
|
|
65
|
-
var import_application_version = require("./helpers/application-version");
|
|
66
|
-
var import_locale = require("./locale");
|
|
67
|
-
var import_plugin_manager = require("./plugin-manager");
|
|
68
|
-
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
69
|
-
var import_package = __toESM(require("../package.json"));
|
|
70
|
-
var import_main_data_source = require("./main-data-source");
|
|
71
|
-
var import_validate_filter_params = __toESM(require("./middlewares/validate-filter-params"));
|
|
72
|
-
var import_path2 = __toESM(require("path"));
|
|
73
|
-
var import_middlewares = require("./middlewares");
|
|
74
|
-
var import_data_template = require("./middlewares/data-template");
|
|
75
|
-
const _Application = class _Application extends import_koa.default {
|
|
76
|
-
constructor(options) {
|
|
77
|
-
super();
|
|
78
|
-
this.options = options;
|
|
79
|
-
this.context.reqId = (0, import_crypto.randomUUID)();
|
|
80
|
-
this.rawOptions = this.name == "main" ? import_lodash.default.cloneDeep(options) : {};
|
|
81
|
-
this.init();
|
|
82
|
-
this._appSupervisor.addApp(this);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
stopped = false;
|
|
88
|
-
/**
|
|
89
|
-
* @internal
|
|
90
|
-
*/
|
|
91
|
-
ready = false;
|
|
92
|
-
/**
|
|
93
|
-
* @internal
|
|
94
|
-
*/
|
|
95
|
-
rawOptions;
|
|
96
|
-
/**
|
|
97
|
-
* @internal
|
|
98
|
-
*/
|
|
99
|
-
activatedCommand = null;
|
|
100
|
-
/**
|
|
101
|
-
* @internal
|
|
102
|
-
*/
|
|
103
|
-
running = false;
|
|
104
|
-
/**
|
|
105
|
-
* @internal
|
|
106
|
-
*/
|
|
107
|
-
perfHistograms = /* @__PURE__ */ new Map();
|
|
108
|
-
plugins = /* @__PURE__ */ new Map();
|
|
109
|
-
_appSupervisor = import_app_supervisor.AppSupervisor.getInstance();
|
|
110
|
-
_started;
|
|
111
|
-
_authenticated = false;
|
|
112
|
-
_maintaining = false;
|
|
113
|
-
_maintainingCommandStatus;
|
|
114
|
-
_maintainingStatusBeforeCommand;
|
|
115
|
-
_actionCommand;
|
|
116
|
-
/**
|
|
117
|
-
* @internal
|
|
118
|
-
*/
|
|
119
|
-
requestLogger;
|
|
120
|
-
sqlLogger;
|
|
121
|
-
_logger;
|
|
122
|
-
get logger() {
|
|
123
|
-
return this._logger;
|
|
124
|
-
}
|
|
125
|
-
get log() {
|
|
126
|
-
return this._logger;
|
|
127
|
-
}
|
|
128
|
-
_loaded;
|
|
129
|
-
/**
|
|
130
|
-
* @internal
|
|
131
|
-
*/
|
|
132
|
-
get loaded() {
|
|
133
|
-
return this._loaded;
|
|
134
|
-
}
|
|
135
|
-
_maintainingMessage;
|
|
136
|
-
/**
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
139
|
-
get maintainingMessage() {
|
|
140
|
-
return this._maintainingMessage;
|
|
141
|
-
}
|
|
142
|
-
_cronJobManager;
|
|
143
|
-
get cronJobManager() {
|
|
144
|
-
return this._cronJobManager;
|
|
145
|
-
}
|
|
146
|
-
get mainDataSource() {
|
|
147
|
-
var _a;
|
|
148
|
-
return (_a = this.dataSourceManager) == null ? void 0 : _a.dataSources.get("main");
|
|
149
|
-
}
|
|
150
|
-
get db() {
|
|
151
|
-
if (!this.mainDataSource) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
return this.mainDataSource.collectionManager.db;
|
|
155
|
-
}
|
|
156
|
-
get resourceManager() {
|
|
157
|
-
return this.mainDataSource.resourceManager;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* This method is deprecated and should not be used.
|
|
161
|
-
* Use {@link #resourceManager} instead.
|
|
162
|
-
* @deprecated
|
|
163
|
-
*/
|
|
164
|
-
get resourcer() {
|
|
165
|
-
return this.mainDataSource.resourceManager;
|
|
166
|
-
}
|
|
167
|
-
_cacheManager;
|
|
168
|
-
get cacheManager() {
|
|
169
|
-
return this._cacheManager;
|
|
170
|
-
}
|
|
171
|
-
_cache;
|
|
172
|
-
get cache() {
|
|
173
|
-
return this._cache;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* @internal
|
|
177
|
-
*/
|
|
178
|
-
set cache(cache) {
|
|
179
|
-
this._cache = cache;
|
|
180
|
-
}
|
|
181
|
-
_cli;
|
|
182
|
-
get cli() {
|
|
183
|
-
return this._cli;
|
|
184
|
-
}
|
|
185
|
-
_i18n;
|
|
186
|
-
get i18n() {
|
|
187
|
-
return this._i18n;
|
|
188
|
-
}
|
|
189
|
-
_pm;
|
|
190
|
-
get pm() {
|
|
191
|
-
return this._pm;
|
|
192
|
-
}
|
|
193
|
-
get acl() {
|
|
194
|
-
return this.mainDataSource.acl;
|
|
195
|
-
}
|
|
196
|
-
_authManager;
|
|
197
|
-
get authManager() {
|
|
198
|
-
return this._authManager;
|
|
199
|
-
}
|
|
200
|
-
_locales;
|
|
201
|
-
/**
|
|
202
|
-
* This method is deprecated and should not be used.
|
|
203
|
-
* Use {@link #localeManager} instead.
|
|
204
|
-
* @deprecated
|
|
205
|
-
*/
|
|
206
|
-
get locales() {
|
|
207
|
-
return this._locales;
|
|
208
|
-
}
|
|
209
|
-
get localeManager() {
|
|
210
|
-
return this._locales;
|
|
211
|
-
}
|
|
212
|
-
_telemetry;
|
|
213
|
-
get telemetry() {
|
|
214
|
-
return this._telemetry;
|
|
215
|
-
}
|
|
216
|
-
_version;
|
|
217
|
-
get version() {
|
|
218
|
-
return this._version;
|
|
219
|
-
}
|
|
220
|
-
get name() {
|
|
221
|
-
return this.options.name || "main";
|
|
222
|
-
}
|
|
223
|
-
_dataSourceManager;
|
|
224
|
-
get dataSourceManager() {
|
|
225
|
-
return this._dataSourceManager;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* @internal
|
|
229
|
-
*/
|
|
230
|
-
getMaintaining() {
|
|
231
|
-
return this._maintainingCommandStatus;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* @internal
|
|
235
|
-
*/
|
|
236
|
-
setMaintaining(_maintainingCommandStatus) {
|
|
237
|
-
this._maintainingCommandStatus = _maintainingCommandStatus;
|
|
238
|
-
this.emit("maintaining", _maintainingCommandStatus);
|
|
239
|
-
if (_maintainingCommandStatus.status == "command_end") {
|
|
240
|
-
this._maintaining = false;
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
this._maintaining = true;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* @internal
|
|
247
|
-
*/
|
|
248
|
-
setMaintainingMessage(message) {
|
|
249
|
-
this._maintainingMessage = message;
|
|
250
|
-
this.emit("maintainingMessageChanged", {
|
|
251
|
-
message: this._maintainingMessage,
|
|
252
|
-
maintainingStatus: this._maintainingCommandStatus
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* This method is deprecated and should not be used.
|
|
257
|
-
* Use {@link #this.version.get()} instead.
|
|
258
|
-
* @deprecated
|
|
259
|
-
*/
|
|
260
|
-
getVersion() {
|
|
261
|
-
return import_package.default.version;
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* This method is deprecated and should not be used.
|
|
265
|
-
* Use {@link #this.pm.addPreset()} instead.
|
|
266
|
-
* @deprecated
|
|
267
|
-
*/
|
|
268
|
-
plugin(pluginClass, options) {
|
|
269
|
-
this.log.debug(`add plugin`, { method: "plugin", name: pluginClass.name });
|
|
270
|
-
this.pm.addPreset(pluginClass, options);
|
|
271
|
-
}
|
|
272
|
-
// @ts-ignore
|
|
273
|
-
use(middleware, options) {
|
|
274
|
-
this.middleware.add(middleware, options);
|
|
275
|
-
return this;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* @internal
|
|
279
|
-
*/
|
|
280
|
-
callback() {
|
|
281
|
-
const fn = (0, import_koa_compose.default)(this.middleware.nodes);
|
|
282
|
-
if (!this.listenerCount("error"))
|
|
283
|
-
this.on("error", this.onerror);
|
|
284
|
-
return (req, res) => {
|
|
285
|
-
const ctx = this.createContext(req, res);
|
|
286
|
-
return this.handleRequest(ctx, fn);
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* This method is deprecated and should not be used.
|
|
291
|
-
* Use {@link #this.db.collection()} instead.
|
|
292
|
-
* @deprecated
|
|
293
|
-
*/
|
|
294
|
-
collection(options) {
|
|
295
|
-
return this.db.collection(options);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* This method is deprecated and should not be used.
|
|
299
|
-
* Use {@link #this.resourceManager.define()} instead.
|
|
300
|
-
* @deprecated
|
|
301
|
-
*/
|
|
302
|
-
resource(options) {
|
|
303
|
-
return this.resourceManager.define(options);
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* This method is deprecated and should not be used.
|
|
307
|
-
* Use {@link #this.resourceManager.registerActionHandlers()} instead.
|
|
308
|
-
* @deprecated
|
|
309
|
-
*/
|
|
310
|
-
actions(handlers, options) {
|
|
311
|
-
return this.resourceManager.registerActionHandlers(handlers);
|
|
312
|
-
}
|
|
313
|
-
command(name, desc, opts) {
|
|
314
|
-
return this.cli.command(name, desc, opts).allowUnknownOption();
|
|
315
|
-
}
|
|
316
|
-
findCommand(name) {
|
|
317
|
-
return this.cli._findCommand(name);
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* @internal
|
|
321
|
-
*/
|
|
322
|
-
async reInit() {
|
|
323
|
-
if (!this._loaded) {
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
this.log.info("app reinitializing");
|
|
327
|
-
if (this.cacheManager) {
|
|
328
|
-
await this.cacheManager.close();
|
|
329
|
-
}
|
|
330
|
-
if (this.telemetry.started) {
|
|
331
|
-
await this.telemetry.shutdown();
|
|
332
|
-
}
|
|
333
|
-
this.closeLogger();
|
|
334
|
-
const oldDb = this.db;
|
|
335
|
-
this.init();
|
|
336
|
-
if (!oldDb.closed()) {
|
|
337
|
-
await oldDb.close();
|
|
338
|
-
}
|
|
339
|
-
this._loaded = false;
|
|
340
|
-
}
|
|
341
|
-
async load(options) {
|
|
342
|
-
var _a;
|
|
343
|
-
if (this._loaded) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (options == null ? void 0 : options.reload) {
|
|
347
|
-
this.setMaintainingMessage("app reload");
|
|
348
|
-
this.log.info(`app.reload()`, { method: "load" });
|
|
349
|
-
if (this.cacheManager) {
|
|
350
|
-
await this.cacheManager.close();
|
|
351
|
-
}
|
|
352
|
-
if (this.telemetry.started) {
|
|
353
|
-
await this.telemetry.shutdown();
|
|
354
|
-
}
|
|
355
|
-
const oldDb = this.db;
|
|
356
|
-
this.init();
|
|
357
|
-
if (!oldDb.closed()) {
|
|
358
|
-
await oldDb.close();
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
this._cacheManager = await (0, import_cache2.createCacheManager)(this, this.options.cacheManager);
|
|
362
|
-
this.log.debug("init plugins");
|
|
363
|
-
this.setMaintainingMessage("init plugins");
|
|
364
|
-
await this.pm.initPlugins();
|
|
365
|
-
this.log.debug("loading app...");
|
|
366
|
-
this.setMaintainingMessage("start load");
|
|
367
|
-
this.setMaintainingMessage("emit beforeLoad");
|
|
368
|
-
if ((options == null ? void 0 : options.hooks) !== false) {
|
|
369
|
-
await this.emitAsync("beforeLoad", this, options);
|
|
370
|
-
}
|
|
371
|
-
this.telemetry.init();
|
|
372
|
-
if ((_a = this.options.telemetry) == null ? void 0 : _a.enabled) {
|
|
373
|
-
this.telemetry.start();
|
|
374
|
-
}
|
|
375
|
-
await this.pm.load(options);
|
|
376
|
-
if (options == null ? void 0 : options.sync) {
|
|
377
|
-
await this.db.sync();
|
|
378
|
-
}
|
|
379
|
-
this.setMaintainingMessage("emit afterLoad");
|
|
380
|
-
if ((options == null ? void 0 : options.hooks) !== false) {
|
|
381
|
-
await this.emitAsync("afterLoad", this, options);
|
|
382
|
-
}
|
|
383
|
-
this._loaded = true;
|
|
384
|
-
}
|
|
385
|
-
async reload(options) {
|
|
386
|
-
this.log.debug(`start reload`, { method: "reload" });
|
|
387
|
-
this._loaded = false;
|
|
388
|
-
await this.emitAsync("beforeReload", this, options);
|
|
389
|
-
await this.load({
|
|
390
|
-
...options,
|
|
391
|
-
reload: true
|
|
392
|
-
});
|
|
393
|
-
this.log.debug("emit afterReload", { method: "reload" });
|
|
394
|
-
this.setMaintainingMessage("emit afterReload");
|
|
395
|
-
await this.emitAsync("afterReload", this, options);
|
|
396
|
-
this.log.debug(`finish reload`, { method: "reload" });
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* This method is deprecated and should not be used.
|
|
400
|
-
* Use {@link this.pm.get()} instead.
|
|
401
|
-
* @deprecated
|
|
402
|
-
*/
|
|
403
|
-
getPlugin(name) {
|
|
404
|
-
return this.pm.get(name);
|
|
405
|
-
}
|
|
406
|
-
async authenticate() {
|
|
407
|
-
if (this._authenticated) {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
this._authenticated = true;
|
|
411
|
-
await this.db.auth();
|
|
412
|
-
await this.db.checkVersion();
|
|
413
|
-
await this.db.prepare();
|
|
414
|
-
}
|
|
415
|
-
async runCommand(command, ...args) {
|
|
416
|
-
return await this.runAsCLI([command, ...args], { from: "user" });
|
|
417
|
-
}
|
|
418
|
-
async runCommandThrowError(command, ...args) {
|
|
419
|
-
return await this.runAsCLI([command, ...args], { from: "user", throwError: true });
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* @internal
|
|
423
|
-
*/
|
|
424
|
-
async loadMigrations(options) {
|
|
425
|
-
const { directory, context, namespace } = options;
|
|
426
|
-
const migrations = {
|
|
427
|
-
beforeLoad: [],
|
|
428
|
-
afterSync: [],
|
|
429
|
-
afterLoad: []
|
|
430
|
-
};
|
|
431
|
-
const extensions = ["js", "ts"];
|
|
432
|
-
const patten = `${directory}/*.{${extensions.join(",")}}`;
|
|
433
|
-
const files = import_glob.default.sync(patten, {
|
|
434
|
-
ignore: ["**/*.d.ts"]
|
|
435
|
-
});
|
|
436
|
-
const appVersion = await this.version.get();
|
|
437
|
-
for (const file of files) {
|
|
438
|
-
let filename = (0, import_path.basename)(file);
|
|
439
|
-
filename = filename.substring(0, filename.lastIndexOf(".")) || filename;
|
|
440
|
-
const Migration = await (0, import_utils.importModule)(file);
|
|
441
|
-
const m = new Migration({ app: this, db: this.db, ...context });
|
|
442
|
-
if (!m.appVersion || import_semver.default.satisfies(appVersion, m.appVersion, { includePrerelease: true })) {
|
|
443
|
-
m.name = `${filename}/${namespace}`;
|
|
444
|
-
migrations[m.on || "afterLoad"].push(m);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
return migrations;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* @internal
|
|
451
|
-
*/
|
|
452
|
-
async loadCoreMigrations() {
|
|
453
|
-
const migrations = await this.loadMigrations({
|
|
454
|
-
directory: (0, import_path.resolve)(__dirname, "migrations"),
|
|
455
|
-
namespace: "@nocobase/server"
|
|
456
|
-
});
|
|
457
|
-
return {
|
|
458
|
-
beforeLoad: {
|
|
459
|
-
up: async () => {
|
|
460
|
-
this.log.debug("run core migrations(beforeLoad)");
|
|
461
|
-
const migrator = this.db.createMigrator({ migrations: migrations.beforeLoad });
|
|
462
|
-
await migrator.up();
|
|
463
|
-
}
|
|
464
|
-
},
|
|
465
|
-
afterSync: {
|
|
466
|
-
up: async () => {
|
|
467
|
-
this.log.debug("run core migrations(afterSync)");
|
|
468
|
-
const migrator = this.db.createMigrator({ migrations: migrations.afterSync });
|
|
469
|
-
await migrator.up();
|
|
470
|
-
}
|
|
471
|
-
},
|
|
472
|
-
afterLoad: {
|
|
473
|
-
up: async () => {
|
|
474
|
-
this.log.debug("run core migrations(afterLoad)");
|
|
475
|
-
const migrator = this.db.createMigrator({ migrations: migrations.afterLoad });
|
|
476
|
-
await migrator.up();
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* @internal
|
|
483
|
-
*/
|
|
484
|
-
async runAsCLI(argv = process.argv, options) {
|
|
485
|
-
if (this.activatedCommand) {
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
if (options == null ? void 0 : options.reqId) {
|
|
489
|
-
this.context.reqId = options.reqId;
|
|
490
|
-
this._logger = this._logger.child({ reqId: this.context.reqId });
|
|
491
|
-
}
|
|
492
|
-
this._maintainingStatusBeforeCommand = this._maintainingCommandStatus;
|
|
493
|
-
try {
|
|
494
|
-
const commandName = (options == null ? void 0 : options.from) === "user" ? argv[0] : argv[2];
|
|
495
|
-
if (!this.cli.hasCommand(commandName)) {
|
|
496
|
-
await this.pm.loadCommands();
|
|
497
|
-
}
|
|
498
|
-
const command = await this.cli.parseAsync(argv, options);
|
|
499
|
-
this.setMaintaining({
|
|
500
|
-
status: "command_end",
|
|
501
|
-
command: this.activatedCommand
|
|
502
|
-
});
|
|
503
|
-
return command;
|
|
504
|
-
} catch (error) {
|
|
505
|
-
if (!this.activatedCommand) {
|
|
506
|
-
this.activatedCommand = {
|
|
507
|
-
name: "unknown"
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
this.setMaintaining({
|
|
511
|
-
status: "command_error",
|
|
512
|
-
command: this.activatedCommand,
|
|
513
|
-
error
|
|
514
|
-
});
|
|
515
|
-
if (options == null ? void 0 : options.throwError) {
|
|
516
|
-
throw error;
|
|
517
|
-
} else {
|
|
518
|
-
this.log.error(error);
|
|
519
|
-
}
|
|
520
|
-
} finally {
|
|
521
|
-
const _actionCommand = this._actionCommand;
|
|
522
|
-
if (_actionCommand) {
|
|
523
|
-
const options2 = _actionCommand["options"];
|
|
524
|
-
_actionCommand["_optionValues"] = {};
|
|
525
|
-
_actionCommand["_optionValueSources"] = {};
|
|
526
|
-
_actionCommand["options"] = [];
|
|
527
|
-
for (const option of options2) {
|
|
528
|
-
_actionCommand.addOption(option);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
this._actionCommand = null;
|
|
532
|
-
this.activatedCommand = null;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
async start(options = {}) {
|
|
536
|
-
if (this._started) {
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
this._started = true;
|
|
540
|
-
if (options.checkInstall && !await this.isInstalled()) {
|
|
541
|
-
throw new import_application_not_install.ApplicationNotInstall(
|
|
542
|
-
`Application ${this.name} is not installed, Please run 'yarn nocobase install' command first`
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
this.log.debug(`starting app...`);
|
|
546
|
-
this.setMaintainingMessage("starting app...");
|
|
547
|
-
if (this.db.closed()) {
|
|
548
|
-
await this.db.reconnect();
|
|
549
|
-
}
|
|
550
|
-
this.setMaintainingMessage("emit beforeStart");
|
|
551
|
-
await this.emitAsync("beforeStart", this, options);
|
|
552
|
-
this.setMaintainingMessage("emit afterStart");
|
|
553
|
-
await this.emitAsync("afterStart", this, options);
|
|
554
|
-
await this.emitStartedEvent(options);
|
|
555
|
-
this.stopped = false;
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* @internal
|
|
559
|
-
*/
|
|
560
|
-
async emitStartedEvent(options = {}) {
|
|
561
|
-
await this.emitAsync("__started", this, {
|
|
562
|
-
maintainingStatus: import_lodash.default.cloneDeep(this._maintainingCommandStatus),
|
|
563
|
-
options
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
async isStarted() {
|
|
567
|
-
return this._started;
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* @internal
|
|
571
|
-
*/
|
|
572
|
-
async tryReloadOrRestart(options = {}) {
|
|
573
|
-
if (this._started) {
|
|
574
|
-
await this.restart(options);
|
|
575
|
-
} else {
|
|
576
|
-
await this.reload(options);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
async restart(options = {}) {
|
|
580
|
-
if (!this._started) {
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
this.log.info("restarting...");
|
|
584
|
-
this._started = false;
|
|
585
|
-
await this.emitAsync("beforeStop");
|
|
586
|
-
await this.reload(options);
|
|
587
|
-
await this.start(options);
|
|
588
|
-
this.emit("__restarted", this, options);
|
|
589
|
-
}
|
|
590
|
-
async stop(options = {}) {
|
|
591
|
-
const log = options.logging === false ? {
|
|
592
|
-
debug() {
|
|
593
|
-
},
|
|
594
|
-
warn() {
|
|
595
|
-
},
|
|
596
|
-
info() {
|
|
597
|
-
},
|
|
598
|
-
error() {
|
|
599
|
-
}
|
|
600
|
-
} : this.log;
|
|
601
|
-
log.debug("stop app...", { method: "stop" });
|
|
602
|
-
this.setMaintainingMessage("stopping app...");
|
|
603
|
-
if (this.stopped) {
|
|
604
|
-
log.warn(`app is stopped`, { method: "stop" });
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
await this.emitAsync("beforeStop", this, options);
|
|
608
|
-
try {
|
|
609
|
-
if (!this.db.closed()) {
|
|
610
|
-
log.info(`close db`, { method: "stop" });
|
|
611
|
-
await this.db.close();
|
|
612
|
-
}
|
|
613
|
-
} catch (e) {
|
|
614
|
-
log.error(e.message, { method: "stop", err: e.stack });
|
|
615
|
-
}
|
|
616
|
-
if (this.cacheManager) {
|
|
617
|
-
await this.cacheManager.close();
|
|
618
|
-
}
|
|
619
|
-
if (this.telemetry.started) {
|
|
620
|
-
await this.telemetry.shutdown();
|
|
621
|
-
}
|
|
622
|
-
await this.emitAsync("afterStop", this, options);
|
|
623
|
-
this.stopped = true;
|
|
624
|
-
log.info(`app has stopped`, { method: "stop" });
|
|
625
|
-
this._started = false;
|
|
626
|
-
}
|
|
627
|
-
async destroy(options = {}) {
|
|
628
|
-
this.log.debug("start destroy app", { method: "destory" });
|
|
629
|
-
this.setMaintainingMessage("destroying app...");
|
|
630
|
-
await this.emitAsync("beforeDestroy", this, options);
|
|
631
|
-
await this.stop(options);
|
|
632
|
-
this.log.debug("emit afterDestroy", { method: "destory" });
|
|
633
|
-
await this.emitAsync("afterDestroy", this, options);
|
|
634
|
-
this.log.debug("finish destroy app", { method: "destory" });
|
|
635
|
-
this.closeLogger();
|
|
636
|
-
}
|
|
637
|
-
async isInstalled() {
|
|
638
|
-
return await this.db.collectionExistsInDb("applicationVersion") || await this.db.collectionExistsInDb("collections");
|
|
639
|
-
}
|
|
640
|
-
async install(options = {}) {
|
|
641
|
-
var _a;
|
|
642
|
-
const reinstall = options.clean || options.force;
|
|
643
|
-
if (reinstall) {
|
|
644
|
-
await this.db.clean({ drop: true });
|
|
645
|
-
}
|
|
646
|
-
if (await this.isInstalled()) {
|
|
647
|
-
this.log.warn("app is installed");
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
await this.reInit();
|
|
651
|
-
await this.db.sync();
|
|
652
|
-
await this.load({ hooks: false });
|
|
653
|
-
this.log.debug("emit beforeInstall", { method: "install" });
|
|
654
|
-
this.setMaintainingMessage("call beforeInstall hook...");
|
|
655
|
-
await this.emitAsync("beforeInstall", this, options);
|
|
656
|
-
await this.pm.install();
|
|
657
|
-
await this.version.update();
|
|
658
|
-
this.log.debug("emit afterInstall", { method: "install" });
|
|
659
|
-
this.setMaintainingMessage("call afterInstall hook...");
|
|
660
|
-
await this.emitAsync("afterInstall", this, options);
|
|
661
|
-
if ((_a = this._maintainingStatusBeforeCommand) == null ? void 0 : _a.error) {
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
if (this._started) {
|
|
665
|
-
await this.restart();
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
async upgrade(options = {}) {
|
|
669
|
-
this.log.info("upgrading...");
|
|
670
|
-
await this.reInit();
|
|
671
|
-
const migrator1 = await this.loadCoreMigrations();
|
|
672
|
-
await migrator1.beforeLoad.up();
|
|
673
|
-
await this.db.sync();
|
|
674
|
-
await migrator1.afterSync.up();
|
|
675
|
-
await this.pm.initPresetPlugins();
|
|
676
|
-
const migrator2 = await this.pm.loadPresetMigrations();
|
|
677
|
-
await migrator2.beforeLoad.up();
|
|
678
|
-
await this.pm.load();
|
|
679
|
-
await this.db.sync();
|
|
680
|
-
await migrator2.afterSync.up();
|
|
681
|
-
await this.pm.upgrade();
|
|
682
|
-
await this.pm.initOtherPlugins();
|
|
683
|
-
const migrator3 = await this.pm.loadOtherMigrations();
|
|
684
|
-
await migrator3.beforeLoad.up();
|
|
685
|
-
await this.load({ sync: true });
|
|
686
|
-
await migrator3.afterSync.up();
|
|
687
|
-
await this.pm.upgrade();
|
|
688
|
-
await migrator1.afterLoad.up();
|
|
689
|
-
await migrator2.afterLoad.up();
|
|
690
|
-
await migrator3.afterLoad.up();
|
|
691
|
-
await this.pm.repository.updateVersions();
|
|
692
|
-
await this.version.update();
|
|
693
|
-
await this.emitAsync("afterUpgrade", this, options);
|
|
694
|
-
await this.restart();
|
|
695
|
-
}
|
|
696
|
-
toJSON() {
|
|
697
|
-
return {
|
|
698
|
-
appName: this.name,
|
|
699
|
-
name: this.name
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* @internal
|
|
704
|
-
*/
|
|
705
|
-
reInitEvents() {
|
|
706
|
-
for (const eventName of this.eventNames()) {
|
|
707
|
-
for (const listener of this.listeners(eventName)) {
|
|
708
|
-
if (listener["_reinitializable"]) {
|
|
709
|
-
this.removeListener(eventName, listener);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
createLogger(options) {
|
|
715
|
-
const { dirname } = options;
|
|
716
|
-
return (0, import_logger.createLogger)({
|
|
717
|
-
...options,
|
|
718
|
-
dirname: (0, import_logger.getLoggerFilePath)(import_path2.default.join(this.name || "main", dirname || ""))
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
createCLI() {
|
|
722
|
-
const command = new import_app_command.AppCommand("nocobase").usage("[command] [options]").hook("preAction", async (_, actionCommand) => {
|
|
723
|
-
this._actionCommand = actionCommand;
|
|
724
|
-
this.activatedCommand = {
|
|
725
|
-
name: (0, import_helper.getCommandFullName)(actionCommand)
|
|
726
|
-
};
|
|
727
|
-
this.setMaintaining({
|
|
728
|
-
status: "command_begin",
|
|
729
|
-
command: this.activatedCommand
|
|
730
|
-
});
|
|
731
|
-
this.setMaintaining({
|
|
732
|
-
status: "command_running",
|
|
733
|
-
command: this.activatedCommand
|
|
734
|
-
});
|
|
735
|
-
if (actionCommand["_authenticate"]) {
|
|
736
|
-
await this.authenticate();
|
|
737
|
-
}
|
|
738
|
-
if (actionCommand["_preload"]) {
|
|
739
|
-
await this.load();
|
|
740
|
-
}
|
|
741
|
-
}).hook("postAction", async (_, actionCommand) => {
|
|
742
|
-
var _a;
|
|
743
|
-
if (((_a = this._maintainingStatusBeforeCommand) == null ? void 0 : _a.error) && this._started) {
|
|
744
|
-
await this.restart();
|
|
745
|
-
}
|
|
746
|
-
});
|
|
747
|
-
command.exitOverride((err) => {
|
|
748
|
-
throw err;
|
|
749
|
-
});
|
|
750
|
-
return command;
|
|
751
|
-
}
|
|
752
|
-
initLogger(options) {
|
|
753
|
-
this._logger = (0, import_logger.createSystemLogger)({
|
|
754
|
-
dirname: (0, import_logger.getLoggerFilePath)(this.name),
|
|
755
|
-
filename: "system",
|
|
756
|
-
seperateError: true,
|
|
757
|
-
...(options == null ? void 0 : options.system) || {}
|
|
758
|
-
}).child({
|
|
759
|
-
reqId: this.context.reqId,
|
|
760
|
-
app: this.name,
|
|
761
|
-
module: "application"
|
|
762
|
-
// Due to the use of custom log levels,
|
|
763
|
-
// we have to use any type here until Winston updates the type definitions.
|
|
764
|
-
});
|
|
765
|
-
this.requestLogger = (0, import_logger.createLogger)({
|
|
766
|
-
dirname: (0, import_logger.getLoggerFilePath)(this.name),
|
|
767
|
-
filename: "request",
|
|
768
|
-
...(options == null ? void 0 : options.request) || {}
|
|
769
|
-
});
|
|
770
|
-
this.sqlLogger = this.createLogger({
|
|
771
|
-
filename: "sql",
|
|
772
|
-
level: "debug"
|
|
773
|
-
});
|
|
774
|
-
}
|
|
775
|
-
closeLogger() {
|
|
776
|
-
var _a, _b, _c;
|
|
777
|
-
(_a = this.log) == null ? void 0 : _a.close();
|
|
778
|
-
(_b = this.requestLogger) == null ? void 0 : _b.close();
|
|
779
|
-
(_c = this.sqlLogger) == null ? void 0 : _c.close();
|
|
780
|
-
}
|
|
781
|
-
init() {
|
|
782
|
-
const options = this.options;
|
|
783
|
-
this.initLogger(options.logger);
|
|
784
|
-
this.reInitEvents();
|
|
785
|
-
this.middleware = new import_utils.Toposort();
|
|
786
|
-
this.plugins = /* @__PURE__ */ new Map();
|
|
787
|
-
if (this.db) {
|
|
788
|
-
this.db.removeAllListeners();
|
|
789
|
-
}
|
|
790
|
-
this.createMainDataSource(options);
|
|
791
|
-
this._cronJobManager = new import_cron_job_manager.CronJobManager(this);
|
|
792
|
-
this._cli = this.createCLI();
|
|
793
|
-
this._i18n = (0, import_helper.createI18n)(options);
|
|
794
|
-
this.context.db = this.db;
|
|
795
|
-
this.context.resourcer = this.resourceManager;
|
|
796
|
-
this.context.resourceManager = this.resourceManager;
|
|
797
|
-
this.context.cacheManager = this._cacheManager;
|
|
798
|
-
this.context.cache = this._cache;
|
|
799
|
-
const plugins = this._pm ? this._pm.options.plugins : options.plugins;
|
|
800
|
-
this._pm = new import_plugin_manager.PluginManager({
|
|
801
|
-
app: this,
|
|
802
|
-
plugins: plugins || []
|
|
803
|
-
});
|
|
804
|
-
this._telemetry = new import_telemetry.Telemetry({
|
|
805
|
-
serviceName: `nocobase-${this.name}`,
|
|
806
|
-
version: this.getVersion(),
|
|
807
|
-
...options.telemetry
|
|
808
|
-
});
|
|
809
|
-
this._authManager = new import_auth.AuthManager({
|
|
810
|
-
authKey: "X-Authenticator",
|
|
811
|
-
default: "basic",
|
|
812
|
-
...this.options.authManager || {}
|
|
813
|
-
});
|
|
814
|
-
this.resourceManager.define({
|
|
815
|
-
name: "auth",
|
|
816
|
-
actions: import_auth.actions
|
|
817
|
-
});
|
|
818
|
-
this._dataSourceManager.use(this._authManager.middleware(), { tag: "auth" });
|
|
819
|
-
this._dataSourceManager.use(import_validate_filter_params.default, { tag: "validate-filter-params", before: ["auth"] });
|
|
820
|
-
this._dataSourceManager.use(import_middlewares.parseVariables, {
|
|
821
|
-
group: "parseVariables",
|
|
822
|
-
after: "acl"
|
|
823
|
-
});
|
|
824
|
-
this._dataSourceManager.use(import_data_template.dataTemplate, { group: "dataTemplate", after: "acl" });
|
|
825
|
-
this._locales = new import_locale.Locale((0, import_helper.createAppProxy)(this));
|
|
826
|
-
if (options.perfHooks) {
|
|
827
|
-
(0, import_helper.enablePerfHooks)(this);
|
|
828
|
-
}
|
|
829
|
-
(0, import_helper.registerMiddlewares)(this, options);
|
|
830
|
-
if (options.registerActions !== false) {
|
|
831
|
-
(0, import_actions.registerActions)(this);
|
|
832
|
-
}
|
|
833
|
-
(0, import_commands.registerCli)(this);
|
|
834
|
-
this._version = new import_application_version.ApplicationVersion(this);
|
|
835
|
-
}
|
|
836
|
-
createMainDataSource(options) {
|
|
837
|
-
const mainDataSourceInstance = new import_main_data_source.MainDataSource({
|
|
838
|
-
name: "main",
|
|
839
|
-
database: this.createDatabase(options),
|
|
840
|
-
acl: (0, import_acl.createACL)(),
|
|
841
|
-
resourceManager: (0, import_helper.createResourcer)(options),
|
|
842
|
-
useACL: options.acl
|
|
843
|
-
});
|
|
844
|
-
this._dataSourceManager = new import_data_source_manager.DataSourceManager();
|
|
845
|
-
this.dataSourceManager.dataSources.set("main", mainDataSourceInstance);
|
|
846
|
-
}
|
|
847
|
-
createDatabase(options) {
|
|
848
|
-
const logging = /* @__PURE__ */ __name((msg) => {
|
|
849
|
-
if (typeof msg === "string") {
|
|
850
|
-
msg = msg.replace(/[\r\n]/gm, "").replace(/\s+/g, " ");
|
|
851
|
-
}
|
|
852
|
-
if (msg.includes("INSERT INTO")) {
|
|
853
|
-
msg = msg.substring(0, 2e3) + "...";
|
|
854
|
-
}
|
|
855
|
-
this.sqlLogger.debug({ message: msg, app: this.name, reqId: this.context.reqId });
|
|
856
|
-
}, "logging");
|
|
857
|
-
const dbOptions = options.database instanceof import_database.default ? options.database.options : options.database;
|
|
858
|
-
const db = new import_database.default({
|
|
859
|
-
...dbOptions,
|
|
860
|
-
logging: dbOptions.logging ? logging : false,
|
|
861
|
-
migrator: {
|
|
862
|
-
context: { app: this }
|
|
863
|
-
},
|
|
864
|
-
logger: this._logger.child({ module: "database" })
|
|
865
|
-
});
|
|
866
|
-
return db;
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
|
-
__name(_Application, "Application");
|
|
870
|
-
let Application = _Application;
|
|
871
|
-
(0, import_utils.applyMixins)(Application, [import_utils.AsyncEmitter]);
|
|
872
|
-
var application_default = Application;
|
|
873
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
874
|
-
0 && (module.exports = {
|
|
875
|
-
Application
|
|
876
|
-
});
|