@nocobase/server 0.21.0-alpha.1 → 0.21.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/application.d.ts +38 -7
- package/lib/application.js +22 -12
- package/lib/commands/pm.js +7 -0
- package/lib/commands/start.js +19 -2
- package/lib/gateway/ws-server.js +5 -1
- package/lib/helper.js +1 -11
- package/lib/locale/locale.js +1 -1
- package/lib/main-data-source.js +10 -0
- package/lib/middlewares/data-wrapping.js +1 -0
- package/lib/middlewares/db2resource.js +1 -8
- package/lib/middlewares/validate-filter-params.d.ts +1 -0
- package/lib/middlewares/validate-filter-params.js +33 -0
- package/lib/plugin-manager/plugin-manager.d.ts +2 -1
- package/lib/plugin-manager/plugin-manager.js +49 -10
- package/lib/plugin-manager/utils.js +11 -3
- package/package.json +14 -14
package/lib/application.d.ts
CHANGED
|
@@ -22,9 +22,16 @@ import { InstallOptions, PluginManager } from './plugin-manager';
|
|
|
22
22
|
import { DataSourceManager, SequelizeDataSource } from '@nocobase/data-source-manager';
|
|
23
23
|
export type PluginType = string | typeof Plugin;
|
|
24
24
|
export type PluginConfiguration = PluginType | [PluginType, any];
|
|
25
|
-
export interface
|
|
25
|
+
export interface ResourceManagerOptions {
|
|
26
26
|
prefix?: string;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* this interface is deprecated and should not be used.
|
|
30
|
+
* @deprecated
|
|
31
|
+
* use {@link ResourceManagerOptions} instead
|
|
32
|
+
*/
|
|
33
|
+
export interface ResourcerOptions extends ResourceManagerOptions {
|
|
34
|
+
}
|
|
28
35
|
export interface AppLoggerOptions {
|
|
29
36
|
request: RequestLoggerOptions;
|
|
30
37
|
system: SystemLoggerOptions;
|
|
@@ -35,7 +42,13 @@ export interface AppTelemetryOptions extends TelemetryOptions {
|
|
|
35
42
|
export interface ApplicationOptions {
|
|
36
43
|
database?: IDatabaseOptions | Database;
|
|
37
44
|
cacheManager?: CacheManagerOptions;
|
|
38
|
-
|
|
45
|
+
/**
|
|
46
|
+
* this property is deprecated and should not be used.
|
|
47
|
+
* @deprecated
|
|
48
|
+
* use {@link ApplicationOptions.resourceManager} instead
|
|
49
|
+
*/
|
|
50
|
+
resourcer?: ResourceManagerOptions;
|
|
51
|
+
resourceManager?: ResourceManagerOptions;
|
|
39
52
|
bodyParser?: any;
|
|
40
53
|
cors?: any;
|
|
41
54
|
dataWrapping?: boolean;
|
|
@@ -44,9 +57,15 @@ export interface ApplicationOptions {
|
|
|
44
57
|
plugins?: PluginConfiguration[];
|
|
45
58
|
acl?: boolean;
|
|
46
59
|
logger?: AppLoggerOptions;
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
47
63
|
pmSock?: string;
|
|
48
64
|
name?: string;
|
|
49
65
|
authManager?: AuthManagerOptions;
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
50
69
|
perfHooks?: boolean;
|
|
51
70
|
telemetry?: AppTelemetryOptions;
|
|
52
71
|
}
|
|
@@ -65,6 +84,12 @@ interface ActionsOptions {
|
|
|
65
84
|
resourceName?: string;
|
|
66
85
|
resourceNames?: string[];
|
|
67
86
|
}
|
|
87
|
+
interface LoadOptions {
|
|
88
|
+
reload?: boolean;
|
|
89
|
+
hooks?: boolean;
|
|
90
|
+
sync?: boolean;
|
|
91
|
+
[key: string]: any;
|
|
92
|
+
}
|
|
68
93
|
interface StartOptions {
|
|
69
94
|
cliArgs?: any[];
|
|
70
95
|
dbSync?: boolean;
|
|
@@ -139,7 +164,13 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
139
164
|
get mainDataSource(): SequelizeDataSource;
|
|
140
165
|
get db(): Database;
|
|
141
166
|
get logger(): SystemLogger;
|
|
142
|
-
get
|
|
167
|
+
get resourceManager(): import("@nocobase/resourcer").ResourceManager;
|
|
168
|
+
/**
|
|
169
|
+
* This method is deprecated and should not be used.
|
|
170
|
+
* Use {@link #resourceManager} instead.
|
|
171
|
+
* @deprecated
|
|
172
|
+
*/
|
|
173
|
+
get resourcer(): import("@nocobase/resourcer").ResourceManager;
|
|
143
174
|
protected _cacheManager: CacheManager;
|
|
144
175
|
get cacheManager(): CacheManager;
|
|
145
176
|
protected _cache: Cache;
|
|
@@ -210,13 +241,13 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
210
241
|
collection(options: CollectionOptions): import("@nocobase/database").Collection<any, any>;
|
|
211
242
|
/**
|
|
212
243
|
* This method is deprecated and should not be used.
|
|
213
|
-
* Use {@link #this.
|
|
244
|
+
* Use {@link #this.resourceManager.define()} instead.
|
|
214
245
|
* @deprecated
|
|
215
246
|
*/
|
|
216
247
|
resource(options: ResourceOptions): import("@nocobase/resourcer").Resource;
|
|
217
248
|
/**
|
|
218
249
|
* This method is deprecated and should not be used.
|
|
219
|
-
* Use {@link #this.
|
|
250
|
+
* Use {@link #this.resourceManager.registerActionHandlers()} instead.
|
|
220
251
|
* @deprecated
|
|
221
252
|
*/
|
|
222
253
|
actions(handlers: any, options?: ActionsOptions): void;
|
|
@@ -226,8 +257,8 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
226
257
|
* @internal
|
|
227
258
|
*/
|
|
228
259
|
reInit(): Promise<void>;
|
|
229
|
-
load(options?:
|
|
230
|
-
reload(options?:
|
|
260
|
+
load(options?: LoadOptions): Promise<void>;
|
|
261
|
+
reload(options?: LoadOptions): Promise<void>;
|
|
231
262
|
/**
|
|
232
263
|
* This method is deprecated and should not be used.
|
|
233
264
|
* Use {@link this.pm.get()} instead.
|
package/lib/application.js
CHANGED
|
@@ -59,6 +59,7 @@ var import_plugin_manager = require("./plugin-manager");
|
|
|
59
59
|
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
60
60
|
var import_package = __toESM(require("../package.json"));
|
|
61
61
|
var import_main_data_source = require("./main-data-source");
|
|
62
|
+
var import_validate_filter_params = __toESM(require("./middlewares/validate-filter-params"));
|
|
62
63
|
const _Application = class _Application extends import_koa.default {
|
|
63
64
|
constructor(options) {
|
|
64
65
|
super();
|
|
@@ -132,6 +133,14 @@ const _Application = class _Application extends import_koa.default {
|
|
|
132
133
|
get logger() {
|
|
133
134
|
return this._logger;
|
|
134
135
|
}
|
|
136
|
+
get resourceManager() {
|
|
137
|
+
return this.mainDataSource.resourceManager;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* This method is deprecated and should not be used.
|
|
141
|
+
* Use {@link #resourceManager} instead.
|
|
142
|
+
* @deprecated
|
|
143
|
+
*/
|
|
135
144
|
get resourcer() {
|
|
136
145
|
return this.mainDataSource.resourceManager;
|
|
137
146
|
}
|
|
@@ -270,19 +279,19 @@ const _Application = class _Application extends import_koa.default {
|
|
|
270
279
|
}
|
|
271
280
|
/**
|
|
272
281
|
* This method is deprecated and should not be used.
|
|
273
|
-
* Use {@link #this.
|
|
282
|
+
* Use {@link #this.resourceManager.define()} instead.
|
|
274
283
|
* @deprecated
|
|
275
284
|
*/
|
|
276
285
|
resource(options) {
|
|
277
|
-
return this.
|
|
286
|
+
return this.resourceManager.define(options);
|
|
278
287
|
}
|
|
279
288
|
/**
|
|
280
289
|
* This method is deprecated and should not be used.
|
|
281
|
-
* Use {@link #this.
|
|
290
|
+
* Use {@link #this.resourceManager.registerActionHandlers()} instead.
|
|
282
291
|
* @deprecated
|
|
283
292
|
*/
|
|
284
293
|
actions(handlers, options) {
|
|
285
|
-
return this.
|
|
294
|
+
return this.resourceManager.registerActionHandlers(handlers);
|
|
286
295
|
}
|
|
287
296
|
command(name, desc, opts) {
|
|
288
297
|
return this.cli.command(name, desc, opts).allowUnknownOption();
|
|
@@ -502,7 +511,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
502
511
|
if (this.activatedCommand) {
|
|
503
512
|
return;
|
|
504
513
|
}
|
|
505
|
-
if (options.reqId) {
|
|
514
|
+
if (options == null ? void 0 : options.reqId) {
|
|
506
515
|
this.context.reqId = options.reqId;
|
|
507
516
|
this._logger = this._logger.child({ reqId: this.context.reqId });
|
|
508
517
|
}
|
|
@@ -531,6 +540,8 @@ const _Application = class _Application extends import_koa.default {
|
|
|
531
540
|
});
|
|
532
541
|
if (options == null ? void 0 : options.throwError) {
|
|
533
542
|
throw error;
|
|
543
|
+
} else {
|
|
544
|
+
this.log.error(error);
|
|
534
545
|
}
|
|
535
546
|
} finally {
|
|
536
547
|
const _actionCommand = this._actionCommand;
|
|
@@ -755,7 +766,8 @@ const _Application = class _Application extends import_koa.default {
|
|
|
755
766
|
this._cli = this.createCLI();
|
|
756
767
|
this._i18n = (0, import_helper.createI18n)(options);
|
|
757
768
|
this.context.db = this.db;
|
|
758
|
-
this.context.resourcer = this.
|
|
769
|
+
this.context.resourcer = this.resourceManager;
|
|
770
|
+
this.context.resourceManager = this.resourceManager;
|
|
759
771
|
this.context.cacheManager = this._cacheManager;
|
|
760
772
|
this.context.cache = this._cache;
|
|
761
773
|
const plugins = this._pm ? this._pm.options.plugins : options.plugins;
|
|
@@ -773,15 +785,12 @@ const _Application = class _Application extends import_koa.default {
|
|
|
773
785
|
default: "basic",
|
|
774
786
|
...this.options.authManager || {}
|
|
775
787
|
});
|
|
776
|
-
this.
|
|
788
|
+
this.resourceManager.define({
|
|
777
789
|
name: "auth",
|
|
778
790
|
actions: import_auth.actions
|
|
779
791
|
});
|
|
780
792
|
this._dataSourceManager.use(this._authManager.middleware(), { tag: "auth" });
|
|
781
|
-
this.
|
|
782
|
-
if (this.options.acl !== false) {
|
|
783
|
-
this.resourcer.use(this.acl.middleware(), { tag: "acl", after: ["auth"] });
|
|
784
|
-
}
|
|
793
|
+
this._dataSourceManager.use(import_validate_filter_params.default, { tag: "validate-filter-params", before: ["auth"] });
|
|
785
794
|
this._locales = new import_locale.Locale((0, import_helper.createAppProxy)(this));
|
|
786
795
|
if (options.perfHooks) {
|
|
787
796
|
(0, import_helper.enablePerfHooks)(this);
|
|
@@ -798,7 +807,8 @@ const _Application = class _Application extends import_koa.default {
|
|
|
798
807
|
name: "main",
|
|
799
808
|
database: this.createDatabase(options),
|
|
800
809
|
acl: (0, import_acl.createACL)(),
|
|
801
|
-
resourceManager: (0, import_helper.createResourcer)(options)
|
|
810
|
+
resourceManager: (0, import_helper.createResourcer)(options),
|
|
811
|
+
useACL: options.acl
|
|
802
812
|
});
|
|
803
813
|
this._dataSourceManager = new import_data_source_manager.DataSourceManager();
|
|
804
814
|
this.dataSourceManager.dataSources.set("main", mainDataSourceInstance);
|
package/lib/commands/pm.js
CHANGED
|
@@ -55,6 +55,13 @@ var pm_default = /* @__PURE__ */ __name((app) => {
|
|
|
55
55
|
throw new import_plugin_command_error.PluginCommandError(`Failed to update plugin`, { cause: error });
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
|
+
pm.command("enable-all").ipc().preload().action(async () => {
|
|
59
|
+
try {
|
|
60
|
+
await app.pm.enable("*");
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw new import_plugin_command_error.PluginCommandError(`Failed to enable plugin`, { cause: error });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
58
65
|
pm.command("enable").ipc().preload().arguments("<plugins...>").action(async (plugins) => {
|
|
59
66
|
try {
|
|
60
67
|
await app.pm.enable(plugins);
|
package/lib/commands/start.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
8
|
var __export = (target, all) => {
|
|
@@ -15,18 +17,33 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var start_exports = {};
|
|
20
30
|
__export(start_exports, {
|
|
21
31
|
default: () => start_default
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(start_exports);
|
|
34
|
+
var import_utils = require("@nocobase/utils");
|
|
35
|
+
var import_fs = __toESM(require("fs"));
|
|
36
|
+
var import_path = require("path");
|
|
24
37
|
var import_application_not_install = require("../errors/application-not-install");
|
|
25
38
|
var start_default = /* @__PURE__ */ __name((app) => {
|
|
26
39
|
app.command("start").auth().option("--db-sync").option("--quickstart").action(async (...cliArgs) => {
|
|
27
40
|
const [options] = cliArgs;
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
const file = (0, import_path.resolve)(process.cwd(), "storage/app-upgrading");
|
|
42
|
+
const upgrading = await (0, import_utils.fsExists)(file);
|
|
43
|
+
if (upgrading) {
|
|
44
|
+
await app.upgrade();
|
|
45
|
+
await import_fs.default.promises.rm(file);
|
|
46
|
+
} else if (options.quickstart) {
|
|
30
47
|
if (await app.isInstalled()) {
|
|
31
48
|
await app.upgrade();
|
|
32
49
|
} else {
|
package/lib/gateway/ws-server.js
CHANGED
|
@@ -70,10 +70,14 @@ const _WSServer = class _WSServer {
|
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
import_app_supervisor.AppSupervisor.getInstance().on("appError", async ({ appName, error }) => {
|
|
73
|
+
let message = error.message;
|
|
74
|
+
if (error.cause) {
|
|
75
|
+
message = `${message}: ${error.cause.message}`;
|
|
76
|
+
}
|
|
73
77
|
this.sendToConnectionsByTag("app", appName, {
|
|
74
78
|
type: "notification",
|
|
75
79
|
payload: {
|
|
76
|
-
message
|
|
80
|
+
message,
|
|
77
81
|
type: "error"
|
|
78
82
|
}
|
|
79
83
|
});
|
package/lib/helper.js
CHANGED
|
@@ -47,10 +47,7 @@ var import_i18next = __toESM(require("i18next"));
|
|
|
47
47
|
var import_koa_bodyparser = __toESM(require("koa-bodyparser"));
|
|
48
48
|
var import_path = require("path");
|
|
49
49
|
var import_perf_hooks = require("perf_hooks");
|
|
50
|
-
var import_middlewares = require("./middlewares");
|
|
51
|
-
var import_data_template = require("./middlewares/data-template");
|
|
52
50
|
var import_data_wrapping = require("./middlewares/data-wrapping");
|
|
53
|
-
var import_db2resource = require("./middlewares/db2resource");
|
|
54
51
|
var import_i18n = require("./middlewares/i18n");
|
|
55
52
|
function createI18n(options) {
|
|
56
53
|
const instance = import_i18next.default.createInstance();
|
|
@@ -111,14 +108,7 @@ function registerMiddlewares(app, options) {
|
|
|
111
108
|
if (options.dataWrapping !== false) {
|
|
112
109
|
app.use((0, import_data_wrapping.dataWrapping)(), { tag: "dataWrapping", after: "i18n" });
|
|
113
110
|
}
|
|
114
|
-
app.
|
|
115
|
-
tag: "parseVariables",
|
|
116
|
-
after: "acl"
|
|
117
|
-
});
|
|
118
|
-
app.resourcer.use(import_data_template.dateTemplate, { tag: "dateTemplate", after: "acl" });
|
|
119
|
-
app.use(import_db2resource.db2resource, { tag: "db2resource", after: "dataWrapping" });
|
|
120
|
-
app.use(app.resourcer.restApiMiddleware({ skipIfDataSourceExists: true }), { tag: "restApi", after: "db2resource" });
|
|
121
|
-
app.use(app.dataSourceManager.middleware(), { tag: "dataSource", after: "restApi" });
|
|
111
|
+
app.use(app.dataSourceManager.middleware(), { tag: "dataSource", after: "dataWrapping" });
|
|
122
112
|
}
|
|
123
113
|
__name(registerMiddlewares, "registerMiddlewares");
|
|
124
114
|
const createAppProxy = /* @__PURE__ */ __name((app) => {
|
package/lib/locale/locale.js
CHANGED
|
@@ -86,7 +86,7 @@ const _Locale = class _Locale {
|
|
|
86
86
|
getResources(lang) {
|
|
87
87
|
var _a;
|
|
88
88
|
const resources = {};
|
|
89
|
-
const names = this.app.pm.
|
|
89
|
+
const names = this.app.pm.getPlugins().keys();
|
|
90
90
|
for (const name of names) {
|
|
91
91
|
try {
|
|
92
92
|
const p = this.app.pm.get(name);
|
package/lib/main-data-source.js
CHANGED
|
@@ -22,6 +22,8 @@ __export(main_data_source_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(main_data_source_exports);
|
|
24
24
|
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
25
|
+
var import_middlewares = require("./middlewares");
|
|
26
|
+
var import_data_template = require("./middlewares/data-template");
|
|
25
27
|
const _MainDataSource = class _MainDataSource extends import_data_source_manager.SequelizeDataSource {
|
|
26
28
|
init(options = {}) {
|
|
27
29
|
const { acl, resourceManager, database } = options;
|
|
@@ -35,6 +37,14 @@ const _MainDataSource = class _MainDataSource extends import_data_source_manager
|
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
});
|
|
40
|
+
if (options.useACL !== false) {
|
|
41
|
+
this.resourceManager.use(this.acl.middleware(), { group: "acl", after: "auth" });
|
|
42
|
+
}
|
|
43
|
+
this.resourceManager.use(import_middlewares.parseVariables, {
|
|
44
|
+
group: "parseVariables",
|
|
45
|
+
after: "acl"
|
|
46
|
+
});
|
|
47
|
+
this.resourceManager.use(import_data_template.dateTemplate, { group: "dateTemplate", after: "acl" });
|
|
38
48
|
}
|
|
39
49
|
};
|
|
40
50
|
__name(_MainDataSource, "MainDataSource");
|
|
@@ -24,10 +24,6 @@ __export(db2resource_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(db2resource_exports);
|
|
25
25
|
var import_resourcer = require("@nocobase/resourcer");
|
|
26
26
|
async function db2resource(ctx, next) {
|
|
27
|
-
const dataSource = ctx.get("x-data-source");
|
|
28
|
-
if (dataSource) {
|
|
29
|
-
return next();
|
|
30
|
-
}
|
|
31
27
|
const resourcer = ctx.resourcer;
|
|
32
28
|
const database = ctx.db;
|
|
33
29
|
const params = (0, import_resourcer.parseRequest)(
|
|
@@ -48,11 +44,8 @@ async function db2resource(ctx, next) {
|
|
|
48
44
|
return next();
|
|
49
45
|
}
|
|
50
46
|
const splitResult = resourceName.split(".");
|
|
51
|
-
|
|
47
|
+
const collectionName = splitResult[0];
|
|
52
48
|
const fieldName = splitResult[1];
|
|
53
|
-
if (collectionName.includes("@")) {
|
|
54
|
-
collectionName = collectionName.split("@")[1];
|
|
55
|
-
}
|
|
56
49
|
if (!database.hasCollection(collectionName)) {
|
|
57
50
|
return next();
|
|
58
51
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function validateFilterParams(ctx: any, next: any): Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validate_filter_params_exports = {};
|
|
20
|
+
__export(validate_filter_params_exports, {
|
|
21
|
+
default: () => validateFilterParams
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(validate_filter_params_exports);
|
|
24
|
+
var import_utils = require("@nocobase/utils");
|
|
25
|
+
async function validateFilterParams(ctx, next) {
|
|
26
|
+
const { params } = ctx.action;
|
|
27
|
+
const guardedActions = ["update", "destroy"];
|
|
28
|
+
if (params.filter && !(0, import_utils.isValidFilter)(params.filter) && guardedActions.includes(params.actionName)) {
|
|
29
|
+
throw new Error(`Invalid filter: ${JSON.stringify(params.filter)}`);
|
|
30
|
+
}
|
|
31
|
+
await next();
|
|
32
|
+
}
|
|
33
|
+
__name(validateFilterParams, "validateFilterParams");
|
|
@@ -82,7 +82,7 @@ export declare class PluginManager {
|
|
|
82
82
|
create(pluginName: string, options?: {
|
|
83
83
|
forceRecreate?: boolean;
|
|
84
84
|
}): Promise<void>;
|
|
85
|
-
add(plugin?:
|
|
85
|
+
add(plugin?: string | typeof Plugin, options?: any, insert?: boolean, isUpgrade?: boolean): Promise<void>;
|
|
86
86
|
/**
|
|
87
87
|
* @internal
|
|
88
88
|
*/
|
|
@@ -93,6 +93,7 @@ export declare class PluginManager {
|
|
|
93
93
|
loadCommands(): Promise<void>;
|
|
94
94
|
load(options?: any): Promise<void>;
|
|
95
95
|
install(options?: InstallOptions): Promise<void>;
|
|
96
|
+
private sort;
|
|
96
97
|
enable(name: string | string[]): Promise<void>;
|
|
97
98
|
disable(name: string | string[]): Promise<void>;
|
|
98
99
|
remove(name: string | string[], options?: {
|
|
@@ -34,6 +34,7 @@ __export(plugin_manager_exports, {
|
|
|
34
34
|
sleep: () => sleep
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(plugin_manager_exports);
|
|
37
|
+
var import_topo = __toESM(require("@hapi/topo"));
|
|
37
38
|
var import_utils = require("@nocobase/utils");
|
|
38
39
|
var import_plugin_symlink = require("@nocobase/utils/plugin-symlink");
|
|
39
40
|
var import_execa = __toESM(require("execa"));
|
|
@@ -312,6 +313,9 @@ const _PluginManager = class _PluginManager {
|
|
|
312
313
|
if (options.name) {
|
|
313
314
|
this.pluginAliases.set(options.name, instance);
|
|
314
315
|
}
|
|
316
|
+
if (options.packageName) {
|
|
317
|
+
this.pluginAliases.set(options.packageName, instance);
|
|
318
|
+
}
|
|
315
319
|
if (insert && options.name) {
|
|
316
320
|
await this.repository.updateOrCreate({
|
|
317
321
|
values: {
|
|
@@ -443,8 +447,27 @@ const _PluginManager = class _PluginManager {
|
|
|
443
447
|
}
|
|
444
448
|
});
|
|
445
449
|
}
|
|
450
|
+
sort(names) {
|
|
451
|
+
var _a, _b, _c;
|
|
452
|
+
const pluginNames = import_lodash.default.castArray(names);
|
|
453
|
+
if (pluginNames.length === 1) {
|
|
454
|
+
return pluginNames;
|
|
455
|
+
}
|
|
456
|
+
const sorter = new import_topo.default.Sorter();
|
|
457
|
+
for (const pluginName of pluginNames) {
|
|
458
|
+
const plugin = this.get(pluginName);
|
|
459
|
+
const peerDependencies = Object.keys(((_b = (_a = plugin.options) == null ? void 0 : _a.packageJson) == null ? void 0 : _b.peerDependencies) || {});
|
|
460
|
+
sorter.add(pluginName, { after: peerDependencies, group: ((_c = plugin.options) == null ? void 0 : _c.packageName) || pluginName });
|
|
461
|
+
}
|
|
462
|
+
return sorter.nodes;
|
|
463
|
+
}
|
|
446
464
|
async enable(name) {
|
|
447
|
-
|
|
465
|
+
let pluginNames = name;
|
|
466
|
+
if (name === "*") {
|
|
467
|
+
const items = await this.repository.find();
|
|
468
|
+
pluginNames = items.map((item) => item.name);
|
|
469
|
+
}
|
|
470
|
+
pluginNames = this.sort(pluginNames);
|
|
448
471
|
this.app.log.debug(`enabling plugin ${pluginNames.join(",")}`);
|
|
449
472
|
this.app.setMaintainingMessage(`enabling plugin ${pluginNames.join(",")}`);
|
|
450
473
|
const toBeUpdated = [];
|
|
@@ -457,9 +480,17 @@ const _PluginManager = class _PluginManager {
|
|
|
457
480
|
continue;
|
|
458
481
|
}
|
|
459
482
|
await this.app.emitAsync("beforeEnablePlugin", pluginName);
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
483
|
+
try {
|
|
484
|
+
await plugin.beforeEnable();
|
|
485
|
+
plugin.enabled = true;
|
|
486
|
+
toBeUpdated.push(pluginName);
|
|
487
|
+
} catch (error) {
|
|
488
|
+
if (name === "*") {
|
|
489
|
+
this.app.log.error(error.message);
|
|
490
|
+
} else {
|
|
491
|
+
throw error;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
463
494
|
}
|
|
464
495
|
if (toBeUpdated.length === 0) {
|
|
465
496
|
return;
|
|
@@ -474,10 +505,10 @@ const _PluginManager = class _PluginManager {
|
|
|
474
505
|
});
|
|
475
506
|
try {
|
|
476
507
|
await this.app.reload();
|
|
477
|
-
this.app.log.debug(`syncing database in enable plugin ${
|
|
478
|
-
this.app.setMaintainingMessage(`syncing database in enable plugin ${
|
|
508
|
+
this.app.log.debug(`syncing database in enable plugin ${toBeUpdated.join(",")}...`);
|
|
509
|
+
this.app.setMaintainingMessage(`syncing database in enable plugin ${toBeUpdated.join(",")}...`);
|
|
479
510
|
await this.app.db.sync();
|
|
480
|
-
for (const pluginName of
|
|
511
|
+
for (const pluginName of toBeUpdated) {
|
|
481
512
|
const plugin = this.get(pluginName);
|
|
482
513
|
if (!plugin.installed) {
|
|
483
514
|
this.app.log.debug(`installing plugin ${pluginName}...`);
|
|
@@ -494,7 +525,7 @@ const _PluginManager = class _PluginManager {
|
|
|
494
525
|
installed: true
|
|
495
526
|
}
|
|
496
527
|
});
|
|
497
|
-
for (const pluginName of
|
|
528
|
+
for (const pluginName of toBeUpdated) {
|
|
498
529
|
const plugin = this.get(pluginName);
|
|
499
530
|
this.app.log.debug(`emit afterEnablePlugin event...`);
|
|
500
531
|
await plugin.afterEnable();
|
|
@@ -758,7 +789,15 @@ const _PluginManager = class _PluginManager {
|
|
|
758
789
|
} else {
|
|
759
790
|
await this.upgradeByNpm(options);
|
|
760
791
|
}
|
|
761
|
-
|
|
792
|
+
const file = (0, import_path.resolve)(process.cwd(), "storage/app-upgrading");
|
|
793
|
+
await import_fs.default.promises.writeFile(file, "", "utf-8");
|
|
794
|
+
if (process.env.IS_DEV_CMD) {
|
|
795
|
+
await (0, import_helper.tsxRerunning)();
|
|
796
|
+
} else {
|
|
797
|
+
await (0, import_execa.default)("yarn", ["nocobase", "pm2-restart"], {
|
|
798
|
+
env: process.env
|
|
799
|
+
});
|
|
800
|
+
}
|
|
762
801
|
}
|
|
763
802
|
/**
|
|
764
803
|
* @internal
|
|
@@ -815,7 +854,7 @@ const _PluginManager = class _PluginManager {
|
|
|
815
854
|
async list(options = {}) {
|
|
816
855
|
const { locale = "en-US", isPreset = false } = options;
|
|
817
856
|
return Promise.all(
|
|
818
|
-
[...this.
|
|
857
|
+
[...this.getPlugins().keys()].map((name) => {
|
|
819
858
|
const plugin = this.get(name);
|
|
820
859
|
if (!isPreset && plugin.options.isPreset) {
|
|
821
860
|
return;
|
|
@@ -445,15 +445,23 @@ async function getExternalVersionFromSource(packageName) {
|
|
|
445
445
|
__name(getExternalVersionFromSource, "getExternalVersionFromSource");
|
|
446
446
|
async function getCompatible(packageName) {
|
|
447
447
|
let externalVersion;
|
|
448
|
-
|
|
448
|
+
const hasSrc = import_fs_extra.default.existsSync(import_path.default.join((0, import_clientStaticUtils.getPackageDir)(packageName), "src"));
|
|
449
|
+
let hasError = false;
|
|
450
|
+
if (hasSrc) {
|
|
451
|
+
try {
|
|
452
|
+
externalVersion = await getExternalVersionFromSource(packageName);
|
|
453
|
+
} catch (error) {
|
|
454
|
+
console.log("getExternalVersionFromSource error:", error);
|
|
455
|
+
hasError = true;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (hasError || !hasSrc) {
|
|
449
459
|
const res = await getExternalVersionFromDistFile(packageName);
|
|
450
460
|
if (!res) {
|
|
451
461
|
return false;
|
|
452
462
|
} else {
|
|
453
463
|
externalVersion = res;
|
|
454
464
|
}
|
|
455
|
-
} else {
|
|
456
|
-
externalVersion = await getExternalVersionFromSource(packageName);
|
|
457
465
|
}
|
|
458
466
|
return Object.keys(externalVersion).reduce((result, packageName2) => {
|
|
459
467
|
const packageVersion = externalVersion[packageName2];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "0.21.0-alpha.
|
|
3
|
+
"version": "0.21.0-alpha.10",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.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": "0.21.0-alpha.
|
|
14
|
-
"@nocobase/actions": "0.21.0-alpha.
|
|
15
|
-
"@nocobase/auth": "0.21.0-alpha.
|
|
16
|
-
"@nocobase/cache": "0.21.0-alpha.
|
|
17
|
-
"@nocobase/data-source-manager": "0.21.0-alpha.
|
|
18
|
-
"@nocobase/database": "0.21.0-alpha.
|
|
19
|
-
"@nocobase/evaluators": "0.21.0-alpha.
|
|
20
|
-
"@nocobase/logger": "0.21.0-alpha.
|
|
21
|
-
"@nocobase/resourcer": "0.21.0-alpha.
|
|
22
|
-
"@nocobase/sdk": "0.21.0-alpha.
|
|
23
|
-
"@nocobase/telemetry": "0.21.0-alpha.
|
|
24
|
-
"@nocobase/utils": "0.21.0-alpha.
|
|
13
|
+
"@nocobase/acl": "0.21.0-alpha.10",
|
|
14
|
+
"@nocobase/actions": "0.21.0-alpha.10",
|
|
15
|
+
"@nocobase/auth": "0.21.0-alpha.10",
|
|
16
|
+
"@nocobase/cache": "0.21.0-alpha.10",
|
|
17
|
+
"@nocobase/data-source-manager": "0.21.0-alpha.10",
|
|
18
|
+
"@nocobase/database": "0.21.0-alpha.10",
|
|
19
|
+
"@nocobase/evaluators": "0.21.0-alpha.10",
|
|
20
|
+
"@nocobase/logger": "0.21.0-alpha.10",
|
|
21
|
+
"@nocobase/resourcer": "0.21.0-alpha.10",
|
|
22
|
+
"@nocobase/sdk": "0.21.0-alpha.10",
|
|
23
|
+
"@nocobase/telemetry": "0.21.0-alpha.10",
|
|
24
|
+
"@nocobase/utils": "0.21.0-alpha.10",
|
|
25
25
|
"@types/decompress": "4.2.4",
|
|
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": "98adf5ec996a4f359c6ca1c4a6ac837c43b6e268"
|
|
58
58
|
}
|