@nocobase/server 1.4.0-alpha → 1.4.0-alpha.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.
- package/lib/application.d.ts +4 -0
- package/lib/application.js +25 -4
- package/lib/gateway/index.js +1 -1
- package/lib/helper.js +13 -12
- package/lib/middlewares/data-template.d.ts +1 -1
- package/lib/middlewares/data-template.js +3 -2
- package/lib/middlewares/i18n.js +1 -1
- package/lib/middlewares/parse-variables.d.ts +1 -1
- package/lib/middlewares/parse-variables.js +3 -2
- package/lib/plugin-manager/deps.js +1 -1
- package/lib/plugin-manager/findPackageNames.js +14 -14
- package/package.json +14 -14
package/lib/application.d.ts
CHANGED
|
@@ -162,6 +162,8 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
162
162
|
private _maintainingStatusBeforeCommand;
|
|
163
163
|
private _actionCommand;
|
|
164
164
|
constructor(options: ApplicationOptions);
|
|
165
|
+
private static staticCommands;
|
|
166
|
+
static addCommand(callback: (app: Application) => void): void;
|
|
165
167
|
private _sqlLogger;
|
|
166
168
|
get sqlLogger(): Logger;
|
|
167
169
|
protected _logger: SystemLogger;
|
|
@@ -243,6 +245,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
243
245
|
* @deprecated
|
|
244
246
|
*/
|
|
245
247
|
getVersion(): string;
|
|
248
|
+
getPackageVersion(): string;
|
|
246
249
|
/**
|
|
247
250
|
* This method is deprecated and should not be used.
|
|
248
251
|
* Use {@link #this.pm.addPreset()} instead.
|
|
@@ -278,6 +281,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
278
281
|
* @internal
|
|
279
282
|
*/
|
|
280
283
|
reInit(): Promise<void>;
|
|
284
|
+
createCacheManager(): Promise<CacheManager>;
|
|
281
285
|
load(options?: LoadOptions): Promise<void>;
|
|
282
286
|
reload(options?: LoadOptions): Promise<void>;
|
|
283
287
|
/**
|
package/lib/application.js
CHANGED
|
@@ -13,6 +13,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
13
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
14
|
var __getProtoOf = Object.getPrototypeOf;
|
|
15
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
17
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
18
|
var __export = (target, all) => {
|
|
18
19
|
for (var name in all)
|
|
@@ -35,6 +36,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
35
36
|
mod
|
|
36
37
|
));
|
|
37
38
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
38
40
|
var application_exports = {};
|
|
39
41
|
__export(application_exports, {
|
|
40
42
|
Application: () => Application,
|
|
@@ -119,6 +121,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
119
121
|
_maintainingCommandStatus;
|
|
120
122
|
_maintainingStatusBeforeCommand;
|
|
121
123
|
_actionCommand;
|
|
124
|
+
static addCommand(callback) {
|
|
125
|
+
this.staticCommands.push(callback);
|
|
126
|
+
}
|
|
122
127
|
_sqlLogger;
|
|
123
128
|
get sqlLogger() {
|
|
124
129
|
return this._sqlLogger;
|
|
@@ -272,6 +277,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
272
277
|
getVersion() {
|
|
273
278
|
return import_package.default.version;
|
|
274
279
|
}
|
|
280
|
+
getPackageVersion() {
|
|
281
|
+
return import_package.default.version;
|
|
282
|
+
}
|
|
275
283
|
/**
|
|
276
284
|
* This method is deprecated and should not be used.
|
|
277
285
|
* Use {@link #this.pm.addPreset()} instead.
|
|
@@ -283,7 +291,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
283
291
|
}
|
|
284
292
|
// @ts-ignore
|
|
285
293
|
use(middleware, options) {
|
|
286
|
-
this.middleware.add(middleware, options);
|
|
294
|
+
this.middleware.add((0, import_utils.wrapMiddlewareWithLogging)(middleware, this.logger), options);
|
|
287
295
|
return this;
|
|
288
296
|
}
|
|
289
297
|
/**
|
|
@@ -349,6 +357,10 @@ const _Application = class _Application extends import_koa.default {
|
|
|
349
357
|
}
|
|
350
358
|
this._loaded = false;
|
|
351
359
|
}
|
|
360
|
+
async createCacheManager() {
|
|
361
|
+
this._cacheManager = await (0, import_cache2.createCacheManager)(this, this.options.cacheManager);
|
|
362
|
+
return this._cacheManager;
|
|
363
|
+
}
|
|
352
364
|
async load(options) {
|
|
353
365
|
var _a;
|
|
354
366
|
if (this._loaded) {
|
|
@@ -372,7 +384,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
372
384
|
if (this.cacheManager) {
|
|
373
385
|
await this.cacheManager.close();
|
|
374
386
|
}
|
|
375
|
-
this._cacheManager = await
|
|
387
|
+
this._cacheManager = await this.createCacheManager();
|
|
376
388
|
this.log.debug("init plugins");
|
|
377
389
|
this.setMaintainingMessage("init plugins");
|
|
378
390
|
await this.pm.initPlugins();
|
|
@@ -850,6 +862,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
850
862
|
}
|
|
851
863
|
(0, import_commands.registerCli)(this);
|
|
852
864
|
this._version = new import_application_version.ApplicationVersion(this);
|
|
865
|
+
for (const callback of _Application.staticCommands) {
|
|
866
|
+
callback(this);
|
|
867
|
+
}
|
|
853
868
|
}
|
|
854
869
|
createMainDataSource(options) {
|
|
855
870
|
const mainDataSourceInstance = new import_main_data_source.MainDataSource({
|
|
@@ -866,14 +881,19 @@ const _Application = class _Application extends import_koa.default {
|
|
|
866
881
|
this.dataSourceManager.dataSources.set("main", mainDataSourceInstance);
|
|
867
882
|
}
|
|
868
883
|
createDatabase(options) {
|
|
869
|
-
const logging = /* @__PURE__ */ __name((
|
|
884
|
+
const logging = /* @__PURE__ */ __name((...args) => {
|
|
885
|
+
let msg = args[0];
|
|
870
886
|
if (typeof msg === "string") {
|
|
871
887
|
msg = msg.replace(/[\r\n]/gm, "").replace(/\s+/g, " ");
|
|
872
888
|
}
|
|
873
889
|
if (msg.includes("INSERT INTO")) {
|
|
874
890
|
msg = msg.substring(0, 2e3) + "...";
|
|
875
891
|
}
|
|
876
|
-
|
|
892
|
+
const content = { message: msg, app: this.name, reqId: this.context.reqId };
|
|
893
|
+
if (args[1] && typeof args[1] === "number") {
|
|
894
|
+
content.executeTime = args[1];
|
|
895
|
+
}
|
|
896
|
+
this._sqlLogger.debug(content);
|
|
877
897
|
}, "logging");
|
|
878
898
|
const dbOptions = options.database instanceof import_database.default ? options.database.options : options.database;
|
|
879
899
|
const db = new import_database.default({
|
|
@@ -888,6 +908,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
888
908
|
}
|
|
889
909
|
};
|
|
890
910
|
__name(_Application, "Application");
|
|
911
|
+
__publicField(_Application, "staticCommands", []);
|
|
891
912
|
let Application = _Application;
|
|
892
913
|
(0, import_utils.applyMixins)(Application, [import_utils.AsyncEmitter]);
|
|
893
914
|
var application_default = Application;
|
package/lib/gateway/index.js
CHANGED
|
@@ -265,7 +265,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
265
265
|
if (!process.env.IS_DEV_CMD) {
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
|
-
const file =
|
|
268
|
+
const file = process.env.WATCH_FILE;
|
|
269
269
|
if (!import_fs.default.existsSync(file)) {
|
|
270
270
|
await import_fs.default.promises.writeFile(file, `export const watchId = '${(0, import_utils.uid)()}';`, "utf-8");
|
|
271
271
|
}
|
package/lib/helper.js
CHANGED
|
@@ -54,14 +54,13 @@ var import_crypto = require("crypto");
|
|
|
54
54
|
var import_fs = __toESM(require("fs"));
|
|
55
55
|
var import_i18next = __toESM(require("i18next"));
|
|
56
56
|
var import_koa_bodyparser = __toESM(require("koa-bodyparser"));
|
|
57
|
-
var import_path = require("path");
|
|
58
57
|
var import_perf_hooks = require("perf_hooks");
|
|
59
58
|
var import_data_wrapping = require("./middlewares/data-wrapping");
|
|
60
59
|
var import_i18n = require("./middlewares/i18n");
|
|
61
60
|
function createI18n(options) {
|
|
62
61
|
const instance = import_i18next.default.createInstance();
|
|
63
62
|
instance.init({
|
|
64
|
-
lng: "en-US",
|
|
63
|
+
lng: process.env.INIT_LANG || "en-US",
|
|
65
64
|
resources: {},
|
|
66
65
|
keySeparator: false,
|
|
67
66
|
nsSeparator: false,
|
|
@@ -76,10 +75,13 @@ function createResourcer(options) {
|
|
|
76
75
|
__name(createResourcer, "createResourcer");
|
|
77
76
|
function registerMiddlewares(app, options) {
|
|
78
77
|
var _a;
|
|
79
|
-
app.use(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
app.use(
|
|
79
|
+
/* @__PURE__ */ __name(async function generateReqId(ctx, next) {
|
|
80
|
+
app.context.reqId = (0, import_crypto.randomUUID)();
|
|
81
|
+
await next();
|
|
82
|
+
}, "generateReqId"),
|
|
83
|
+
{ tag: "generateReqId" }
|
|
84
|
+
);
|
|
83
85
|
app.use((0, import_logger.requestLogger)(app.name, app.requestLogger, (_a = options.logger) == null ? void 0 : _a.request), { tag: "logger" });
|
|
84
86
|
app.use(
|
|
85
87
|
(0, import_cors.default)({
|
|
@@ -106,16 +108,16 @@ function registerMiddlewares(app, options) {
|
|
|
106
108
|
}
|
|
107
109
|
);
|
|
108
110
|
}
|
|
109
|
-
app.use(async (ctx, next)
|
|
111
|
+
app.use(/* @__PURE__ */ __name(async function getBearerToken(ctx, next) {
|
|
110
112
|
ctx.getBearerToken = () => {
|
|
111
113
|
const token = ctx.get("Authorization").replace(/^Bearer\s+/gi, "");
|
|
112
114
|
return token || ctx.query.token;
|
|
113
115
|
};
|
|
114
116
|
await next();
|
|
115
|
-
});
|
|
116
|
-
app.use(import_i18n.i18n, { tag: "i18n",
|
|
117
|
+
}, "getBearerToken"));
|
|
118
|
+
app.use(import_i18n.i18n, { tag: "i18n", before: "cors" });
|
|
117
119
|
if (options.dataWrapping !== false) {
|
|
118
|
-
app.use((0, import_data_wrapping.dataWrapping)(), { tag: "dataWrapping", after: "
|
|
120
|
+
app.use((0, import_data_wrapping.dataWrapping)(), { tag: "dataWrapping", after: "cors" });
|
|
119
121
|
}
|
|
120
122
|
app.use(app.dataSourceManager.middleware(), { tag: "dataSource", after: "dataWrapping" });
|
|
121
123
|
}
|
|
@@ -148,8 +150,7 @@ const getCommandFullName = /* @__PURE__ */ __name((command) => {
|
|
|
148
150
|
}, "getCommandFullName");
|
|
149
151
|
/* istanbul ignore next -- @preserve */
|
|
150
152
|
const tsxRerunning = /* @__PURE__ */ __name(async () => {
|
|
151
|
-
const
|
|
152
|
-
await import_fs.default.promises.writeFile(file, `export const watchId = '${(0, import_utils.uid)()}';`, "utf-8");
|
|
153
|
+
await import_fs.default.promises.writeFile(process.env.WATCH_FILE, `export const watchId = '${(0, import_utils.uid)()}';`, "utf-8");
|
|
153
154
|
}, "tsxRerunning");
|
|
154
155
|
/* istanbul ignore next -- @preserve */
|
|
155
156
|
const enablePerfHooks = /* @__PURE__ */ __name((app) => {
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Context } from '@nocobase/actions';
|
|
10
|
-
export declare
|
|
10
|
+
export declare function dataTemplate(ctx: Context, next: any): Promise<void>;
|
|
@@ -30,7 +30,7 @@ __export(data_template_exports, {
|
|
|
30
30
|
dataTemplate: () => dataTemplate
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(data_template_exports);
|
|
33
|
-
|
|
33
|
+
async function dataTemplate(ctx, next) {
|
|
34
34
|
const { resourceName, actionName } = ctx.action;
|
|
35
35
|
const { isTemplate, fields } = ctx.action.params;
|
|
36
36
|
await next();
|
|
@@ -40,7 +40,8 @@ const dataTemplate = /* @__PURE__ */ __name(async (ctx, next) => {
|
|
|
40
40
|
include: fields
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
|
+
__name(dataTemplate, "dataTemplate");
|
|
44
45
|
const traverseHasMany = /* @__PURE__ */ __name((arr, { collection, exclude = [], include = [] }) => {
|
|
45
46
|
if (!arr) {
|
|
46
47
|
return arr;
|
package/lib/middlewares/i18n.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
export declare
|
|
9
|
+
export declare function parseVariables(ctx: any, next: any): Promise<any>;
|
|
@@ -59,7 +59,7 @@ function isNumeric(str) {
|
|
|
59
59
|
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
60
60
|
}
|
|
61
61
|
__name(isNumeric, "isNumeric");
|
|
62
|
-
|
|
62
|
+
async function parseVariables(ctx, next) {
|
|
63
63
|
const filter = ctx.action.params.filter;
|
|
64
64
|
if (!filter) {
|
|
65
65
|
return next();
|
|
@@ -86,7 +86,8 @@ const parseVariables = /* @__PURE__ */ __name(async (ctx, next) => {
|
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
await next();
|
|
89
|
-
}
|
|
89
|
+
}
|
|
90
|
+
__name(parseVariables, "parseVariables");
|
|
90
91
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
92
|
0 && (module.exports = {
|
|
92
93
|
parseVariables
|
|
@@ -68,6 +68,18 @@ async function trim(packageNames) {
|
|
|
68
68
|
return names;
|
|
69
69
|
}
|
|
70
70
|
__name(trim, "trim");
|
|
71
|
+
const excludes = [
|
|
72
|
+
"@nocobase/plugin-audit-logs",
|
|
73
|
+
"@nocobase/plugin-backup-restore",
|
|
74
|
+
"@nocobase/plugin-charts",
|
|
75
|
+
"@nocobase/plugin-disable-pm-add",
|
|
76
|
+
"@nocobase/plugin-mobile-client",
|
|
77
|
+
"@nocobase/plugin-mock-collections",
|
|
78
|
+
"@nocobase/plugin-multi-app-share-collection",
|
|
79
|
+
"@nocobase/plugin-notifications",
|
|
80
|
+
"@nocobase/plugin-snapshot-field",
|
|
81
|
+
"@nocobase/plugin-workflow-test"
|
|
82
|
+
];
|
|
71
83
|
async function findPackageNames() {
|
|
72
84
|
const patterns = [
|
|
73
85
|
"./packages/plugins/*/package.json",
|
|
@@ -88,22 +100,10 @@ async function findPackageNames() {
|
|
|
88
100
|
return packageJson.name;
|
|
89
101
|
})
|
|
90
102
|
);
|
|
91
|
-
const excludes = [
|
|
92
|
-
"@nocobase/plugin-audit-logs",
|
|
93
|
-
"@nocobase/plugin-backup-restore",
|
|
94
|
-
"@nocobase/plugin-charts",
|
|
95
|
-
"@nocobase/plugin-disable-pm-add",
|
|
96
|
-
"@nocobase/plugin-mobile-client",
|
|
97
|
-
"@nocobase/plugin-mock-collections",
|
|
98
|
-
"@nocobase/plugin-multi-app-share-collection",
|
|
99
|
-
"@nocobase/plugin-notifications",
|
|
100
|
-
"@nocobase/plugin-snapshot-field",
|
|
101
|
-
"@nocobase/plugin-workflow-test"
|
|
102
|
-
];
|
|
103
103
|
const nocobasePlugins = await findNocobasePlugins();
|
|
104
104
|
const { APPEND_PRESET_BUILT_IN_PLUGINS = "", APPEND_PRESET_LOCAL_PLUGINS = "" } = process.env;
|
|
105
105
|
return trim(
|
|
106
|
-
|
|
106
|
+
packageNames.filter((pkg) => pkg && !excludes.includes(pkg)).concat(nocobasePlugins).concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS)).concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS))
|
|
107
107
|
);
|
|
108
108
|
} catch (error) {
|
|
109
109
|
return [];
|
|
@@ -121,7 +121,7 @@ async function findNocobasePlugins() {
|
|
|
121
121
|
try {
|
|
122
122
|
const packageJson = await getPackageJson();
|
|
123
123
|
const pluginNames = Object.keys(packageJson.dependencies).filter((name) => name.startsWith("@nocobase/plugin-"));
|
|
124
|
-
return trim(pluginNames);
|
|
124
|
+
return trim(pluginNames.filter((pkg) => pkg && !excludes.includes(pkg)));
|
|
125
125
|
} catch (error) {
|
|
126
126
|
return [];
|
|
127
127
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "1.4.0-alpha",
|
|
3
|
+
"version": "1.4.0-alpha.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
"@koa/cors": "^3.1.0",
|
|
11
11
|
"@koa/multer": "^3.0.2",
|
|
12
12
|
"@koa/router": "^9.4.0",
|
|
13
|
-
"@nocobase/acl": "1.4.0-alpha",
|
|
14
|
-
"@nocobase/actions": "1.4.0-alpha",
|
|
15
|
-
"@nocobase/auth": "1.4.0-alpha",
|
|
16
|
-
"@nocobase/cache": "1.4.0-alpha",
|
|
17
|
-
"@nocobase/data-source-manager": "1.4.0-alpha",
|
|
18
|
-
"@nocobase/database": "1.4.0-alpha",
|
|
19
|
-
"@nocobase/evaluators": "1.4.0-alpha",
|
|
20
|
-
"@nocobase/logger": "1.4.0-alpha",
|
|
21
|
-
"@nocobase/resourcer": "1.4.0-alpha",
|
|
22
|
-
"@nocobase/sdk": "1.4.0-alpha",
|
|
23
|
-
"@nocobase/telemetry": "1.4.0-alpha",
|
|
24
|
-
"@nocobase/utils": "1.4.0-alpha",
|
|
13
|
+
"@nocobase/acl": "1.4.0-alpha.0",
|
|
14
|
+
"@nocobase/actions": "1.4.0-alpha.0",
|
|
15
|
+
"@nocobase/auth": "1.4.0-alpha.0",
|
|
16
|
+
"@nocobase/cache": "1.4.0-alpha.0",
|
|
17
|
+
"@nocobase/data-source-manager": "1.4.0-alpha.0",
|
|
18
|
+
"@nocobase/database": "1.4.0-alpha.0",
|
|
19
|
+
"@nocobase/evaluators": "1.4.0-alpha.0",
|
|
20
|
+
"@nocobase/logger": "1.4.0-alpha.0",
|
|
21
|
+
"@nocobase/resourcer": "1.4.0-alpha.0",
|
|
22
|
+
"@nocobase/sdk": "1.4.0-alpha.0",
|
|
23
|
+
"@nocobase/telemetry": "1.4.0-alpha.0",
|
|
24
|
+
"@nocobase/utils": "1.4.0-alpha.0",
|
|
25
25
|
"@types/decompress": "4.2.7",
|
|
26
26
|
"@types/ini": "^1.3.31",
|
|
27
27
|
"@types/koa-send": "^4.1.3",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"@types/serve-handler": "^6.1.1",
|
|
55
55
|
"@types/ws": "^8.5.5"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "8ffa7b54bbaf720c0c9857da4b19a99110dffc4b"
|
|
58
58
|
}
|