@nocobase/server 1.3.44-beta → 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.
@@ -0,0 +1,183 @@
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 findPackageNames_exports = {};
39
+ __export(findPackageNames_exports, {
40
+ appendToBuiltInPlugins: () => appendToBuiltInPlugins,
41
+ findAllPlugins: () => findAllPlugins,
42
+ findBuiltInPlugins: () => findBuiltInPlugins,
43
+ findLocalPlugins: () => findLocalPlugins,
44
+ findPackageNames: () => findPackageNames,
45
+ packageNameTrim: () => packageNameTrim
46
+ });
47
+ module.exports = __toCommonJS(findPackageNames_exports);
48
+ var import_fast_glob = __toESM(require("fast-glob"));
49
+ var import_fs_extra = __toESM(require("fs-extra"));
50
+ var import_lodash = __toESM(require("lodash"));
51
+ var import_path = __toESM(require("path"));
52
+ var import__ = require("./");
53
+ function splitNames(name) {
54
+ return (name || "").split(",").filter(Boolean);
55
+ }
56
+ __name(splitNames, "splitNames");
57
+ async function trim(packageNames) {
58
+ const nameOrPkgs = import_lodash.default.uniq(packageNames).filter(Boolean);
59
+ const names = [];
60
+ for (const nameOrPkg of nameOrPkgs) {
61
+ const { name, packageName } = await import__.PluginManager.parseName(nameOrPkg);
62
+ try {
63
+ await import__.PluginManager.getPackageJson(packageName);
64
+ names.push(name);
65
+ } catch (error) {
66
+ }
67
+ }
68
+ return names;
69
+ }
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
+ ];
83
+ async function findPackageNames() {
84
+ const patterns = [
85
+ "./packages/plugins/*/package.json",
86
+ "./packages/plugins/*/*/package.json",
87
+ "./packages/pro-plugins/*/*/package.json",
88
+ "./storage/plugins/*/package.json",
89
+ "./storage/plugins/*/*/package.json"
90
+ ];
91
+ try {
92
+ const packageJsonPaths = await (0, import_fast_glob.default)(patterns, {
93
+ cwd: process.cwd(),
94
+ absolute: true,
95
+ ignore: ["**/external-db-data-source/**"]
96
+ });
97
+ const packageNames = await Promise.all(
98
+ packageJsonPaths.map(async (packageJsonPath) => {
99
+ const packageJson = await import_fs_extra.default.readJson(packageJsonPath);
100
+ return packageJson.name;
101
+ })
102
+ );
103
+ const nocobasePlugins = await findNocobasePlugins();
104
+ const { APPEND_PRESET_BUILT_IN_PLUGINS = "", APPEND_PRESET_LOCAL_PLUGINS = "" } = process.env;
105
+ return trim(
106
+ packageNames.filter((pkg) => pkg && !excludes.includes(pkg)).concat(nocobasePlugins).concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS)).concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS))
107
+ );
108
+ } catch (error) {
109
+ return [];
110
+ }
111
+ }
112
+ __name(findPackageNames, "findPackageNames");
113
+ async function getPackageJson() {
114
+ const packageJson = await import_fs_extra.default.readJson(
115
+ import_path.default.resolve(process.env.NODE_MODULES_PATH, "@nocobase/preset-nocobase/package.json")
116
+ );
117
+ return packageJson;
118
+ }
119
+ __name(getPackageJson, "getPackageJson");
120
+ async function findNocobasePlugins() {
121
+ try {
122
+ const packageJson = await getPackageJson();
123
+ const pluginNames = Object.keys(packageJson.dependencies).filter((name) => name.startsWith("@nocobase/plugin-"));
124
+ return trim(pluginNames.filter((pkg) => pkg && !excludes.includes(pkg)));
125
+ } catch (error) {
126
+ return [];
127
+ }
128
+ }
129
+ __name(findNocobasePlugins, "findNocobasePlugins");
130
+ async function findBuiltInPlugins() {
131
+ const { APPEND_PRESET_BUILT_IN_PLUGINS = "" } = process.env;
132
+ try {
133
+ const packageJson = await getPackageJson();
134
+ return trim(packageJson.builtIn.concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS)));
135
+ } catch (error) {
136
+ return [];
137
+ }
138
+ }
139
+ __name(findBuiltInPlugins, "findBuiltInPlugins");
140
+ async function findLocalPlugins() {
141
+ const { APPEND_PRESET_LOCAL_PLUGINS = "" } = process.env;
142
+ const plugins1 = await findNocobasePlugins();
143
+ const plugins2 = await findPackageNames();
144
+ const builtInPlugins = await findBuiltInPlugins();
145
+ const packageJson = await getPackageJson();
146
+ const items = await trim(
147
+ import_lodash.default.difference(
148
+ plugins1.concat(plugins2).concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS)),
149
+ builtInPlugins.concat(await trim(packageJson.deprecated))
150
+ )
151
+ );
152
+ return items;
153
+ }
154
+ __name(findLocalPlugins, "findLocalPlugins");
155
+ async function findAllPlugins() {
156
+ const builtInPlugins = await findBuiltInPlugins();
157
+ const localPlugins = await findLocalPlugins();
158
+ return import_lodash.default.uniq(builtInPlugins.concat(localPlugins));
159
+ }
160
+ __name(findAllPlugins, "findAllPlugins");
161
+ const packageNameTrim = trim;
162
+ async function appendToBuiltInPlugins(nameOrPkg) {
163
+ const APPEND_PRESET_BUILT_IN_PLUGINS = process.env.APPEND_PRESET_BUILT_IN_PLUGINS || "";
164
+ const keys = APPEND_PRESET_BUILT_IN_PLUGINS.split(",");
165
+ const { name, packageName } = await import__.PluginManager.parseName(nameOrPkg);
166
+ if (keys.includes(packageName)) {
167
+ return;
168
+ }
169
+ if (keys.includes(name)) {
170
+ return;
171
+ }
172
+ process.env.APPEND_PRESET_BUILT_IN_PLUGINS += "," + nameOrPkg;
173
+ }
174
+ __name(appendToBuiltInPlugins, "appendToBuiltInPlugins");
175
+ // Annotate the CommonJS export names for ESM import in node:
176
+ 0 && (module.exports = {
177
+ appendToBuiltInPlugins,
178
+ findAllPlugins,
179
+ findBuiltInPlugins,
180
+ findLocalPlugins,
181
+ findPackageNames,
182
+ packageNameTrim
183
+ });
@@ -146,7 +146,8 @@ var resource_default = {
146
146
  async list(ctx, next) {
147
147
  const locale = ctx.getCurrentLocale();
148
148
  const pm = ctx.app.pm;
149
- ctx.body = await pm.list({ locale, isPreset: false });
149
+ const plugin = pm.get("nocobase");
150
+ ctx.body = await plugin.getAllPlugins(locale);
150
151
  await next();
151
152
  },
152
153
  async listEnabled(ctx, next) {
@@ -179,7 +180,8 @@ var resource_default = {
179
180
  if (!filterByTk) {
180
181
  ctx.throw(400, "plugin name invalid");
181
182
  }
182
- ctx.body = await pm.get(filterByTk).toJSON({ locale });
183
+ const plugin = pm.get("nocobase");
184
+ ctx.body = await plugin.getPluginInfo(filterByTk, locale);
183
185
  await next();
184
186
  }
185
187
  }
@@ -17,6 +17,7 @@ export declare class PluginManagerRepository extends Repository {
17
17
  * @internal
18
18
  */
19
19
  setPluginManager(pm: PluginManager): void;
20
+ createByName(nameOrPkgs: any): Promise<void>;
20
21
  has(nameOrPkg: string): Promise<boolean>;
21
22
  /**
22
23
  * @deprecated
@@ -54,6 +54,8 @@ const _PluginManagerRepository = class _PluginManagerRepository extends import_d
54
54
  setPluginManager(pm) {
55
55
  this.pm = pm;
56
56
  }
57
+ async createByName(nameOrPkgs) {
58
+ }
57
59
  async has(nameOrPkg) {
58
60
  const { name } = await import_plugin_manager.PluginManager.parseName(nameOrPkg);
59
61
  const instance = await this.findOne({
@@ -103,11 +105,19 @@ const _PluginManagerRepository = class _PluginManagerRepository extends import_d
103
105
  return pluginNames;
104
106
  }
105
107
  async updateVersions() {
106
- const items = await this.find();
108
+ const items = await this.find({
109
+ filter: {
110
+ enabled: true
111
+ }
112
+ });
107
113
  for (const item of items) {
108
- const json = await import_plugin_manager.PluginManager.getPackageJson(item.packageName);
109
- item.set("version", json.version);
110
- await item.save();
114
+ try {
115
+ const json = await import_plugin_manager.PluginManager.getPackageJson(item.packageName);
116
+ item.set("version", json.version);
117
+ await item.save();
118
+ } catch (error) {
119
+ this.pm.app.log.error(error);
120
+ }
111
121
  }
112
122
  }
113
123
  /**
@@ -136,7 +146,10 @@ const _PluginManagerRepository = class _PluginManagerRepository extends import_d
136
146
  return [];
137
147
  }
138
148
  return await this.find({
139
- sort: "id"
149
+ sort: "id",
150
+ filter: {
151
+ enabled: true
152
+ }
140
153
  });
141
154
  }
142
155
  async init() {
@@ -13,6 +13,7 @@ import Application from '../application';
13
13
  import { Plugin } from '../plugin';
14
14
  import { PluginManagerRepository } from './plugin-manager-repository';
15
15
  import { PluginData } from './types';
16
+ import { checkAndGetCompatible } from './utils';
16
17
  export declare const sleep: (timeout?: number) => Promise<unknown>;
17
18
  export interface PluginManagerOptions {
18
19
  app: Application;
@@ -28,6 +29,7 @@ export declare class AddPresetError extends Error {
28
29
  }
29
30
  export declare class PluginManager {
30
31
  options: PluginManagerOptions;
32
+ static checkAndGetCompatible: typeof checkAndGetCompatible;
31
33
  /**
32
34
  * @internal
33
35
  */
@@ -57,10 +59,11 @@ export declare class PluginManager {
57
59
  */
58
60
  _repository: PluginManagerRepository;
59
61
  get repository(): PluginManagerRepository;
62
+ static packageExists(nameOrPkg: string): Promise<boolean>;
60
63
  /**
61
64
  * @internal
62
65
  */
63
- static getPackageJson(packageName: string): Promise<any>;
66
+ static getPackageJson(nameOrPkg: string): Promise<any>;
64
67
  /**
65
68
  * @internal
66
69
  */