@nocobase/server 2.1.0-alpha.7 → 2.1.0-alpha.8

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.
@@ -13,7 +13,7 @@ import type { AppSupervisor } from './index';
13
13
  export declare class MainOnlyAdapter implements AppDiscoveryAdapter, AppProcessAdapter {
14
14
  protected readonly supervisor: AppSupervisor;
15
15
  readonly name: string;
16
- app: Application;
16
+ apps: Record<string, Application>;
17
17
  status: AppStatus;
18
18
  appErrors: Record<string, Error>;
19
19
  constructor(supervisor: AppSupervisor);
@@ -36,7 +36,7 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
36
36
  this.name = "main-only";
37
37
  }
38
38
  name;
39
- app;
39
+ apps = {};
40
40
  status;
41
41
  appErrors = {};
42
42
  async getApp(appName, options = {}) {
@@ -47,10 +47,10 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
47
47
  if (!options.withOutBootStrap) {
48
48
  await this.bootstrapApp(appName);
49
49
  }
50
- return this.app;
50
+ return this.apps[appName];
51
51
  }
52
52
  async bootstrapApp(appName) {
53
- if (appName !== "main" || !this.app) {
53
+ if (appName !== "main" || !this.apps[appName]) {
54
54
  this.setAppStatus(appName, "not_found");
55
55
  return;
56
56
  }
@@ -66,23 +66,23 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
66
66
  this.supervisor.logger.warn(`only main app is supported`, { method: "addApp" });
67
67
  return;
68
68
  }
69
- if (this.app) {
69
+ if (this.apps[app.name]) {
70
70
  throw new Error(`app ${app.name} already exists`);
71
71
  }
72
- this.app = app;
72
+ this.apps[app.name] = app;
73
73
  if (!this.status || this.status === "not_found") {
74
74
  this.setAppStatus(app.name, "preparing");
75
75
  }
76
76
  return app;
77
77
  }
78
78
  getApps() {
79
- return [this.app];
79
+ return Object.values(this.apps);
80
80
  }
81
81
  hasApp(appName) {
82
82
  if (appName !== "main") {
83
83
  return false;
84
84
  }
85
- return !!this.app;
85
+ return !!this.apps[appName];
86
86
  }
87
87
  async startApp(appName) {
88
88
  if (appName !== "main") {
@@ -93,31 +93,36 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
93
93
  await (app == null ? void 0 : app.runCommand("start", "--quickstart"));
94
94
  }
95
95
  async stopApp(appName) {
96
+ var _a;
96
97
  if (appName !== "main") {
97
98
  this.supervisor.logger.warn(`only main app is supported`, { method: "stopApp" });
98
99
  return;
99
100
  }
100
- await this.app.runCommand("stop");
101
+ if (!this.apps[appName]) {
102
+ return;
103
+ }
104
+ await ((_a = this.apps[appName]) == null ? void 0 : _a.runCommand("stop"));
101
105
  }
102
106
  async removeApp(appName) {
103
107
  if (appName !== "main") {
104
108
  this.supervisor.logger.warn(`only main app is supported`, { method: "removeApp" });
105
109
  return;
106
110
  }
107
- if (!this.app) {
111
+ if (!this.apps[appName]) {
108
112
  return;
109
113
  }
110
- await this.app.runCommand("destroy");
114
+ await this.apps[appName].runCommand("destroy");
115
+ this.apps[appName] = null;
111
116
  }
112
117
  async upgradeApp(appName) {
113
118
  if (appName !== "main") {
114
119
  this.supervisor.logger.warn(`only main app is supported`, { method: "upgrade" });
115
120
  return;
116
121
  }
117
- if (!this.app) {
122
+ if (!this.apps[appName]) {
118
123
  return;
119
124
  }
120
- await this.app.runCommand("upgrade");
125
+ await this.apps[appName].runCommand("upgrade");
121
126
  }
122
127
  async removeAllApps() {
123
128
  return this.removeApp("main");
@@ -37,7 +37,9 @@ var install_default = /* @__PURE__ */ __name((app) => {
37
37
  if (options.lang) {
38
38
  process.env.INIT_APP_LANG = options.lang;
39
39
  }
40
- await (0, import_create_docs_index.createDocsIndex)(app);
40
+ if (!process.env.VITEST) {
41
+ await (0, import_create_docs_index.createDocsIndex)(app);
42
+ }
41
43
  await app.install(options);
42
44
  const reinstall = options.clean || options.force;
43
45
  app.log.info(`app ${reinstall ? "reinstalled" : "installed"} successfully [v${app.getVersion()}]`);
@@ -34,7 +34,9 @@ var import_create_docs_index = require("../ai/create-docs-index");
34
34
  /* istanbul ignore file -- @preserve */
35
35
  var upgrade_default = /* @__PURE__ */ __name((app) => {
36
36
  app.command("upgrade").ipc().auth().action(async (options) => {
37
- await (0, import_create_docs_index.createDocsIndex)(app);
37
+ if (!process.env.VITEST) {
38
+ await (0, import_create_docs_index.createDocsIndex)(app);
39
+ }
38
40
  await app.upgrade(options);
39
41
  app.log.info(`\u2728 NocoBase has been upgraded to v${app.getVersion()}`);
40
42
  });
package/lib/helper.js CHANGED
@@ -239,14 +239,46 @@ function isNumeric(str) {
239
239
  return !isNaN(str) && !isNaN(parseFloat(str));
240
240
  }
241
241
  __name(isNumeric, "isNumeric");
242
+ function getFieldFromCollectionManager(ctx, resourceName, fieldPath) {
243
+ var _a;
244
+ const collectionManager = (_a = ctx.dataSource) == null ? void 0 : _a.collectionManager;
245
+ if (!(collectionManager == null ? void 0 : collectionManager.getCollection)) {
246
+ return;
247
+ }
248
+ const collection = collectionManager.getCollection(resourceName);
249
+ if (!(collection == null ? void 0 : collection.getField)) {
250
+ return;
251
+ }
252
+ const [firstName, ...others] = fieldPath.split(".");
253
+ let field = collection.getField(firstName);
254
+ if (!field || !others.length) {
255
+ return field;
256
+ }
257
+ let currentCollection = typeof field.targetCollection === "function" ? field.targetCollection() : field.targetCollection;
258
+ for (const name of others) {
259
+ if (!(currentCollection == null ? void 0 : currentCollection.getField)) {
260
+ return;
261
+ }
262
+ field = currentCollection.getField(name);
263
+ if (!field) {
264
+ return;
265
+ }
266
+ currentCollection = typeof field.targetCollection === "function" ? field.targetCollection() : field.targetCollection;
267
+ }
268
+ return field;
269
+ }
270
+ __name(getFieldFromCollectionManager, "getFieldFromCollectionManager");
242
271
  function createContextVariablesScope(ctx) {
243
272
  const state = JSON.parse(JSON.stringify(ctx.state));
244
273
  return {
245
274
  timezone: ctx.get("x-timezone"),
246
275
  now: (/* @__PURE__ */ new Date()).toISOString(),
247
276
  getField: /* @__PURE__ */ __name((path) => {
248
- const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
249
277
  const { resourceName } = ctx.action;
278
+ const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
279
+ if (!ctx.database) {
280
+ return getFieldFromCollectionManager(ctx, resourceName, fieldPath);
281
+ }
250
282
  return ctx.database.getFieldByPath(`${resourceName}.${fieldPath}`);
251
283
  }, "getField"),
252
284
  vars: {
@@ -46,6 +46,8 @@ var import_utils = require("@nocobase/utils");
46
46
  var import_fs = __toESM(require("fs"));
47
47
  var import_fs_extra = __toESM(require("fs-extra"));
48
48
  var import_path = __toESM(require("path"));
49
+ var import_crypto = __toESM(require("crypto"));
50
+ var import_package = __toESM(require("../../../package.json"));
49
51
  const _PackageUrls = class _PackageUrls {
50
52
  static async get(packageName) {
51
53
  if (!this.items[packageName]) {
@@ -63,7 +65,19 @@ const _PackageUrls = class _PackageUrls {
63
65
  const distExists = await import_fs_extra.default.exists(dist);
64
66
  if (distExists) {
65
67
  const fsState = await import_fs_extra.default.stat(distExists ? dist : pkgPath);
66
- t = `?t=${fsState.mtime.getTime()}`;
68
+ const appKey = process.env.APP_KEY || "";
69
+ let version = "";
70
+ try {
71
+ const pkgJson = await import_fs_extra.default.readJson(import_path.default.resolve(pkgPath, "package.json"));
72
+ if (pkgJson && typeof pkgJson.version === "string") {
73
+ version = pkgJson.version;
74
+ }
75
+ } catch (error) {
76
+ }
77
+ const appVersion = import_package.default.version;
78
+ const salt = process.env.PLUGIN_URL_HASH_SALT || "";
79
+ const hash = import_crypto.default.createHash("sha256").update(fsState.mtime.getTime() + appKey + version + appVersion + salt).digest("hex").slice(0, 8);
80
+ t = `?hash=${hash}`;
67
81
  }
68
82
  const cdnBaseUrl = process.env.CDN_BASE_URL.replace(/\/+$/, "");
69
83
  const url = `${cdnBaseUrl}${"/static/plugins/"}${packageName}/${PLUGIN_CLIENT_ENTRY_FILE}${t}`;
@@ -58,6 +58,14 @@ var import_collection = __toESM(require("./options/collection"));
58
58
  var import_resource = __toESM(require("./options/resource"));
59
59
  var import_plugin_manager_repository = require("./plugin-manager-repository");
60
60
  var import_utils2 = require("./utils");
61
+ const _PluginLoadError = class _PluginLoadError extends Error {
62
+ constructor(pluginName) {
63
+ super(`${pluginName} plugin load error`);
64
+ this.name = "PluginLoadError";
65
+ }
66
+ };
67
+ __name(_PluginLoadError, "PluginLoadError");
68
+ let PluginLoadError = _PluginLoadError;
61
69
  const sleep = /* @__PURE__ */ __name(async (timeout = 0) => {
62
70
  return new Promise((resolve2) => {
63
71
  setTimeout(resolve2, timeout);
@@ -526,7 +534,7 @@ const _PluginManager = class _PluginManager {
526
534
  const { name: pluginName } = await _PluginManager.parseName(name);
527
535
  const plugin = this.get(pluginName);
528
536
  if (!plugin) {
529
- throw new Error(`${pluginName} plugin does not exist`);
537
+ throw new PluginLoadError(pluginName);
530
538
  }
531
539
  if (added[pluginName]) {
532
540
  continue;
@@ -549,7 +557,7 @@ const _PluginManager = class _PluginManager {
549
557
  const { name: pluginName } = await _PluginManager.parseName(name);
550
558
  const plugin = this.get(pluginName);
551
559
  if (!plugin) {
552
- throw new Error(`${pluginName} plugin does not exist`);
560
+ throw new PluginLoadError(pluginName);
553
561
  }
554
562
  if (added[pluginName]) {
555
563
  continue;
@@ -574,7 +582,7 @@ const _PluginManager = class _PluginManager {
574
582
  const { name: pluginName } = await _PluginManager.parseName(name);
575
583
  const plugin = this.get(pluginName);
576
584
  if (!plugin) {
577
- throw new Error(`${pluginName} plugin does not exist`);
585
+ throw new PluginLoadError(pluginName);
578
586
  }
579
587
  if (plugin.enabled) {
580
588
  continue;
@@ -647,7 +655,7 @@ const _PluginManager = class _PluginManager {
647
655
  const { name: pluginName } = await _PluginManager.parseName(name2);
648
656
  const plugin = this.get(pluginName);
649
657
  if (!plugin) {
650
- throw new Error(`${pluginName} plugin does not exist`);
658
+ throw new PluginLoadError(pluginName);
651
659
  }
652
660
  if (!plugin.enabled) {
653
661
  continue;
@@ -340,7 +340,7 @@ async function updatePluginByCompressedFileUrl(options) {
340
340
  });
341
341
  if (!instance) {
342
342
  await removeTmpDir(tempFile, tempPackageContentDir);
343
- throw new Error(`plugin ${packageName} does not exist`);
343
+ throw new Error(`${packageName} does not exist`);
344
344
  }
345
345
  const { packageDir } = await copyTempPackageToStorageAndLinkToNodeModules(
346
346
  tempFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "2.1.0-alpha.7",
3
+ "version": "2.1.0-alpha.8",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -10,21 +10,21 @@
10
10
  "@koa/cors": "^5.0.0",
11
11
  "@koa/multer": "^3.1.0",
12
12
  "@koa/router": "^13.1.0",
13
- "@nocobase/acl": "2.1.0-alpha.7",
14
- "@nocobase/actions": "2.1.0-alpha.7",
15
- "@nocobase/ai": "2.1.0-alpha.7",
16
- "@nocobase/auth": "2.1.0-alpha.7",
17
- "@nocobase/cache": "2.1.0-alpha.7",
18
- "@nocobase/data-source-manager": "2.1.0-alpha.7",
19
- "@nocobase/database": "2.1.0-alpha.7",
20
- "@nocobase/evaluators": "2.1.0-alpha.7",
21
- "@nocobase/lock-manager": "2.1.0-alpha.7",
22
- "@nocobase/logger": "2.1.0-alpha.7",
23
- "@nocobase/resourcer": "2.1.0-alpha.7",
24
- "@nocobase/sdk": "2.1.0-alpha.7",
25
- "@nocobase/snowflake-id": "2.1.0-alpha.7",
26
- "@nocobase/telemetry": "2.1.0-alpha.7",
27
- "@nocobase/utils": "2.1.0-alpha.7",
13
+ "@nocobase/acl": "2.1.0-alpha.8",
14
+ "@nocobase/actions": "2.1.0-alpha.8",
15
+ "@nocobase/ai": "2.1.0-alpha.8",
16
+ "@nocobase/auth": "2.1.0-alpha.8",
17
+ "@nocobase/cache": "2.1.0-alpha.8",
18
+ "@nocobase/data-source-manager": "2.1.0-alpha.8",
19
+ "@nocobase/database": "2.1.0-alpha.8",
20
+ "@nocobase/evaluators": "2.1.0-alpha.8",
21
+ "@nocobase/lock-manager": "2.1.0-alpha.8",
22
+ "@nocobase/logger": "2.1.0-alpha.8",
23
+ "@nocobase/resourcer": "2.1.0-alpha.8",
24
+ "@nocobase/sdk": "2.1.0-alpha.8",
25
+ "@nocobase/snowflake-id": "2.1.0-alpha.8",
26
+ "@nocobase/telemetry": "2.1.0-alpha.8",
27
+ "@nocobase/utils": "2.1.0-alpha.8",
28
28
  "@types/decompress": "4.2.7",
29
29
  "@types/ini": "^1.3.31",
30
30
  "@types/koa-send": "^4.1.3",
@@ -61,5 +61,5 @@
61
61
  "@types/serve-handler": "^6.1.1",
62
62
  "@types/ws": "^8.5.5"
63
63
  },
64
- "gitHead": "fe825ef778c0d9a941e8517d6443ffc012238391"
64
+ "gitHead": "eda3bfb9df40d4394905e178f1c5331adbec4e76"
65
65
  }