@nocobase/server 0.21.0-alpha.14 → 0.21.0-alpha.16

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.
Files changed (38) hide show
  1. package/lib/acl/index.js +0 -12
  2. package/lib/application.d.ts +3 -13
  3. package/lib/application.js +35 -50
  4. package/lib/commands/console.js +1 -0
  5. package/lib/commands/create-migration.js +1 -0
  6. package/lib/commands/db-auth.js +1 -0
  7. package/lib/commands/db-clean.js +1 -0
  8. package/lib/commands/db-sync.js +1 -0
  9. package/lib/commands/destroy.js +1 -0
  10. package/lib/commands/index.js +1 -0
  11. package/lib/commands/install.js +1 -0
  12. package/lib/commands/migrator.js +1 -0
  13. package/lib/commands/pm.js +1 -0
  14. package/lib/commands/refresh.js +1 -0
  15. package/lib/commands/restart.js +1 -0
  16. package/lib/commands/start.js +1 -0
  17. package/lib/commands/stop.js +1 -0
  18. package/lib/commands/upgrade.js +1 -0
  19. package/lib/gateway/index.d.ts +2 -2
  20. package/lib/gateway/index.js +12 -12
  21. package/lib/helper.js +2 -0
  22. package/lib/middlewares/index.d.ts +0 -1
  23. package/lib/middlewares/index.js +1 -3
  24. package/lib/migration.js +1 -0
  25. package/lib/migrations/20230912193824-package-name-unique.js +1 -0
  26. package/lib/migrations/20230912294620-update-pkg.js +1 -0
  27. package/lib/migrations/20240106082756-update-plugins.js +1 -0
  28. package/lib/plugin-manager/clientStaticUtils.js +1 -0
  29. package/lib/plugin-manager/plugin-manager.d.ts +3 -7
  30. package/lib/plugin-manager/plugin-manager.js +15 -32
  31. package/lib/plugin-manager/utils.js +3 -2
  32. package/lib/plugin.d.ts +7 -7
  33. package/lib/plugin.js +31 -30
  34. package/package.json +14 -14
  35. package/lib/helpers/multiple-instance-manager.d.ts +0 -6
  36. package/lib/helpers/multiple-instance-manager.js +0 -40
  37. package/lib/middlewares/db2resource.d.ts +0 -6
  38. package/lib/middlewares/db2resource.js +0 -69
package/lib/acl/index.js CHANGED
@@ -23,23 +23,11 @@ __export(acl_exports, {
23
23
  module.exports = __toCommonJS(acl_exports);
24
24
  var import_acl = require("@nocobase/acl");
25
25
  var import_available_action = require("./available-action");
26
- const configureResources = [
27
- "roles",
28
- "users",
29
- "collections",
30
- "fields",
31
- "collections.fields",
32
- "roles.collections",
33
- "roles.resources",
34
- "rolesResourcesScopes",
35
- "availableActions"
36
- ];
37
26
  function createACL() {
38
27
  const acl = new import_acl.ACL();
39
28
  for (const [actionName, actionParams] of Object.entries(import_available_action.availableActions)) {
40
29
  acl.setAvailableAction(actionName, actionParams);
41
30
  }
42
- acl.registerConfigResources(configureResources);
43
31
  return acl;
44
32
  }
45
33
  __name(createACL, "createACL");
@@ -142,13 +142,14 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
142
142
  protected plugins: Map<string, Plugin<any>>;
143
143
  protected _appSupervisor: AppSupervisor;
144
144
  protected _started: boolean;
145
- protected _logger: SystemLogger;
146
145
  private _authenticated;
147
146
  private _maintaining;
148
147
  private _maintainingCommandStatus;
149
148
  private _maintainingStatusBeforeCommand;
150
149
  private _actionCommand;
151
150
  constructor(options: ApplicationOptions);
151
+ protected _logger: SystemLogger;
152
+ get logger(): SystemLogger;
152
153
  protected _loaded: boolean;
153
154
  /**
154
155
  * @internal
@@ -163,7 +164,6 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
163
164
  get cronJobManager(): CronJobManager;
164
165
  get mainDataSource(): SequelizeDataSource;
165
166
  get db(): Database;
166
- get logger(): SystemLogger;
167
167
  get resourceManager(): import("@nocobase/resourcer").ResourceManager;
168
168
  /**
169
169
  * This method is deprecated and should not be used.
@@ -265,16 +265,9 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
265
265
  * @deprecated
266
266
  */
267
267
  getPlugin<P extends Plugin>(name: string | typeof Plugin): P;
268
- /**
269
- * This method is deprecated and should not be used.
270
- * Use {@link this.runAsCLI()} instead.
271
- * @deprecated
272
- */
273
- parse(argv?: string[]): Promise<AppCommand>;
274
268
  authenticate(): Promise<void>;
275
269
  runCommand(command: string, ...args: any[]): Promise<AppCommand>;
276
270
  runCommandThrowError(command: string, ...args: any[]): Promise<AppCommand>;
277
- protected createCLI(): AppCommand;
278
271
  /**
279
272
  * @internal
280
273
  */
@@ -297,10 +290,6 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
297
290
  up: () => Promise<void>;
298
291
  };
299
292
  }>;
300
- /**
301
- * @internal
302
- */
303
- loadPluginCommands(): Promise<void>;
304
293
  /**
305
294
  * @internal
306
295
  */
@@ -333,6 +322,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
333
322
  */
334
323
  reInitEvents(): void;
335
324
  createLogger(options: LoggerOptions): import("winston").Logger;
325
+ protected createCLI(): AppCommand;
336
326
  protected init(): void;
337
327
  protected createMainDataSource(options: ApplicationOptions): void;
338
328
  protected createDatabase(options: ApplicationOptions): Database;
@@ -96,12 +96,15 @@ const _Application = class _Application extends import_koa.default {
96
96
  plugins = /* @__PURE__ */ new Map();
97
97
  _appSupervisor = import_app_supervisor.AppSupervisor.getInstance();
98
98
  _started;
99
- _logger;
100
99
  _authenticated = false;
101
100
  _maintaining = false;
102
101
  _maintainingCommandStatus;
103
102
  _maintainingStatusBeforeCommand;
104
103
  _actionCommand;
104
+ _logger;
105
+ get logger() {
106
+ return this._logger;
107
+ }
105
108
  _loaded;
106
109
  /**
107
110
  * @internal
@@ -130,9 +133,6 @@ const _Application = class _Application extends import_koa.default {
130
133
  }
131
134
  return this.mainDataSource.collectionManager.db;
132
135
  }
133
- get logger() {
134
- return this._logger;
135
- }
136
136
  get resourceManager() {
137
137
  return this.mainDataSource.resourceManager;
138
138
  }
@@ -383,14 +383,6 @@ const _Application = class _Application extends import_koa.default {
383
383
  getPlugin(name) {
384
384
  return this.pm.get(name);
385
385
  }
386
- /**
387
- * This method is deprecated and should not be used.
388
- * Use {@link this.runAsCLI()} instead.
389
- * @deprecated
390
- */
391
- async parse(argv = process.argv) {
392
- return this.runAsCLI(argv);
393
- }
394
386
  async authenticate() {
395
387
  if (this._authenticated) {
396
388
  return;
@@ -406,37 +398,6 @@ const _Application = class _Application extends import_koa.default {
406
398
  async runCommandThrowError(command, ...args) {
407
399
  return await this.runAsCLI([command, ...args], { from: "user", throwError: true });
408
400
  }
409
- createCLI() {
410
- const command = new import_app_command.AppCommand("nocobase").usage("[command] [options]").hook("preAction", async (_, actionCommand) => {
411
- this._actionCommand = actionCommand;
412
- this.activatedCommand = {
413
- name: (0, import_helper.getCommandFullName)(actionCommand)
414
- };
415
- this.setMaintaining({
416
- status: "command_begin",
417
- command: this.activatedCommand
418
- });
419
- this.setMaintaining({
420
- status: "command_running",
421
- command: this.activatedCommand
422
- });
423
- if (actionCommand["_authenticate"]) {
424
- await this.authenticate();
425
- }
426
- if (actionCommand["_preload"]) {
427
- await this.load();
428
- }
429
- }).hook("postAction", async (_, actionCommand) => {
430
- var _a;
431
- if (((_a = this._maintainingStatusBeforeCommand) == null ? void 0 : _a.error) && this._started) {
432
- await this.restart();
433
- }
434
- });
435
- command.exitOverride((err) => {
436
- throw err;
437
- });
438
- return command;
439
- }
440
401
  /**
441
402
  * @internal
442
403
  */
@@ -497,13 +458,6 @@ const _Application = class _Application extends import_koa.default {
497
458
  }
498
459
  };
499
460
  }
500
- /**
501
- * @internal
502
- */
503
- async loadPluginCommands() {
504
- this.log.debug("load plugin commands");
505
- await this.pm.loadCommands();
506
- }
507
461
  /**
508
462
  * @internal
509
463
  */
@@ -742,6 +696,37 @@ const _Application = class _Application extends import_koa.default {
742
696
  dirname: (0, import_logger.getLoggerFilePath)(this.name || "main", dirname || "")
743
697
  });
744
698
  }
699
+ createCLI() {
700
+ const command = new import_app_command.AppCommand("nocobase").usage("[command] [options]").hook("preAction", async (_, actionCommand) => {
701
+ this._actionCommand = actionCommand;
702
+ this.activatedCommand = {
703
+ name: (0, import_helper.getCommandFullName)(actionCommand)
704
+ };
705
+ this.setMaintaining({
706
+ status: "command_begin",
707
+ command: this.activatedCommand
708
+ });
709
+ this.setMaintaining({
710
+ status: "command_running",
711
+ command: this.activatedCommand
712
+ });
713
+ if (actionCommand["_authenticate"]) {
714
+ await this.authenticate();
715
+ }
716
+ if (actionCommand["_preload"]) {
717
+ await this.load();
718
+ }
719
+ }).hook("postAction", async (_, actionCommand) => {
720
+ var _a;
721
+ if (((_a = this._maintainingStatusBeforeCommand) == null ? void 0 : _a.error) && this._started) {
722
+ await this.restart();
723
+ }
724
+ });
725
+ command.exitOverride((err) => {
726
+ throw err;
727
+ });
728
+ return command;
729
+ }
745
730
  init() {
746
731
  var _a;
747
732
  const options = this.options;
@@ -21,6 +21,7 @@ __export(console_exports, {
21
21
  default: () => console_default
22
22
  });
23
23
  module.exports = __toCommonJS(console_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  const REPL = require("repl");
25
26
  var console_default = /* @__PURE__ */ __name((app) => {
26
27
  app.command("console").preload().action(async () => {
@@ -34,6 +34,7 @@ module.exports = __toCommonJS(create_migration_exports);
34
34
  var import_dayjs = __toESM(require("dayjs"));
35
35
  var import_fs = __toESM(require("fs"));
36
36
  var import_path = require("path");
37
+ /* istanbul ignore file -- @preserve */
37
38
  var create_migration_default = /* @__PURE__ */ __name((app) => {
38
39
  app.command("create-migration").argument("<name>").option("--pkg <pkg>").option("--on [on]").action(async (name, options) => {
39
40
  const pkg = options.pkg;
@@ -21,6 +21,7 @@ __export(db_auth_exports, {
21
21
  default: () => db_auth_default
22
22
  });
23
23
  module.exports = __toCommonJS(db_auth_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var db_auth_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("db:auth").option("-r, --retry [retry]").action(async (opts) => {
26
27
  await app.db.auth({ retry: opts.retry || 10 });
@@ -21,6 +21,7 @@ __export(db_clean_exports, {
21
21
  default: () => db_clean_default
22
22
  });
23
23
  module.exports = __toCommonJS(db_clean_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var db_clean_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("db:clean").auth().option("-y, --yes").action(async (opts) => {
26
27
  console.log("Clearing database");
@@ -21,6 +21,7 @@ __export(db_sync_exports, {
21
21
  default: () => db_sync_default
22
22
  });
23
23
  module.exports = __toCommonJS(db_sync_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var db_sync_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("db:sync").auth().preload().action(async (...cliArgs) => {
26
27
  const [opts] = cliArgs;
@@ -21,6 +21,7 @@ __export(destroy_exports, {
21
21
  default: () => destroy_default
22
22
  });
23
23
  module.exports = __toCommonJS(destroy_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var destroy_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("destroy").preload().action(async (...cliArgs) => {
26
27
  await app.destroy({
@@ -44,6 +44,7 @@ var import_start = __toESM(require("./start"));
44
44
  var import_stop = __toESM(require("./stop"));
45
45
  var import_upgrade = __toESM(require("./upgrade"));
46
46
  var import_console = __toESM(require("./console"));
47
+ /* istanbul ignore file -- @preserve */
47
48
  function registerCli(app) {
48
49
  (0, import_console.default)(app);
49
50
  (0, import_db_auth.default)(app);
@@ -21,6 +21,7 @@ __export(install_exports, {
21
21
  default: () => install_default
22
22
  });
23
23
  module.exports = __toCommonJS(install_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var install_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("install").ipc().auth().option("-f, --force").option("-c, --clean").option("--lang <lang>").action(async (options) => {
26
27
  if (options.lang) {
@@ -21,6 +21,7 @@ __export(migrator_exports, {
21
21
  default: () => migrator_default
22
22
  });
23
23
  module.exports = __toCommonJS(migrator_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var migrator_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("migrator").preload().action(async (opts) => {
26
27
  console.log("migrating...");
@@ -33,6 +33,7 @@ __export(pm_exports, {
33
33
  module.exports = __toCommonJS(pm_exports);
34
34
  var import_lodash = __toESM(require("lodash"));
35
35
  var import_plugin_command_error = require("../errors/plugin-command-error");
36
+ /* istanbul ignore file -- @preserve */
36
37
  var pm_default = /* @__PURE__ */ __name((app) => {
37
38
  const pm = app.command("pm");
38
39
  pm.command("create").arguments("plugin").option("--force-recreate").action(async (plugin, options) => {
@@ -21,6 +21,7 @@ __export(refresh_exports, {
21
21
  default: () => refresh_default
22
22
  });
23
23
  module.exports = __toCommonJS(refresh_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var refresh_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("refresh").ipc().action(async (cliArgs) => {
26
27
  await app.restart({
@@ -21,6 +21,7 @@ __export(restart_exports, {
21
21
  default: () => restart_default
22
22
  });
23
23
  module.exports = __toCommonJS(restart_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var restart_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("restart").ipc().action(async (...cliArgs) => {
26
27
  if (!await app.isStarted()) {
@@ -35,6 +35,7 @@ var import_utils = require("@nocobase/utils");
35
35
  var import_fs = __toESM(require("fs"));
36
36
  var import_path = require("path");
37
37
  var import_application_not_install = require("../errors/application-not-install");
38
+ /* istanbul ignore file -- @preserve */
38
39
  var start_default = /* @__PURE__ */ __name((app) => {
39
40
  app.command("start").auth().option("--db-sync").option("--quickstart").action(async (...cliArgs) => {
40
41
  const [options] = cliArgs;
@@ -21,6 +21,7 @@ __export(stop_exports, {
21
21
  default: () => stop_default
22
22
  });
23
23
  module.exports = __toCommonJS(stop_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var stop_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("stop").ipc().action(async (...cliArgs) => {
26
27
  if (!await app.isStarted()) {
@@ -21,6 +21,7 @@ __export(upgrade_exports, {
21
21
  default: () => upgrade_default
22
22
  });
23
23
  module.exports = __toCommonJS(upgrade_exports);
24
+ /* istanbul ignore file -- @preserve */
24
25
  var upgrade_default = /* @__PURE__ */ __name((app) => {
25
26
  app.command("upgrade").ipc().auth().action(async (options) => {
26
27
  await app.upgrade(options);
@@ -33,13 +33,14 @@ export declare class Gateway extends EventEmitter {
33
33
  selectorMiddlewares: Toposort<AppSelectorMiddleware>;
34
34
  server: http.Server | null;
35
35
  ipcSocketServer: IPCSocketServer | null;
36
+ loggers: Registry<SystemLogger>;
36
37
  private port;
37
38
  private host;
38
39
  private wsServer;
39
40
  private socketPath;
40
- loggers: Registry<SystemLogger>;
41
41
  private constructor();
42
42
  static getInstance(options?: any): Gateway;
43
+ static getIPCSocketClient(): Promise<false | IPCSocketClient>;
43
44
  destroy(): void;
44
45
  reset(): void;
45
46
  addAppSelectorMiddleware(middleware: AppSelectorMiddleware, options?: ToposortOptions): void;
@@ -66,6 +67,5 @@ export declare class Gateway extends EventEmitter {
66
67
  tryConnectToIPCServer(): Promise<false | IPCSocketClient>;
67
68
  getIPCSocketClient(): Promise<IPCSocketClient>;
68
69
  close(): void;
69
- static getIPCSocketClient(): Promise<false | IPCSocketClient>;
70
70
  }
71
71
  export {};
@@ -65,11 +65,11 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
65
65
  selectorMiddlewares = new import_utils.Toposort();
66
66
  server = null;
67
67
  ipcSocketServer = null;
68
+ loggers = new import_utils.Registry();
68
69
  port = process.env.APP_PORT ? parseInt(process.env.APP_PORT) : null;
69
70
  host = "0.0.0.0";
70
71
  wsServer;
71
72
  socketPath = (0, import_path.resolve)(process.cwd(), "storage", "gateway.sock");
72
- loggers = new import_utils.Registry();
73
73
  constructor() {
74
74
  super();
75
75
  this.reset();
@@ -83,6 +83,14 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
83
83
  }
84
84
  return _Gateway.instance;
85
85
  }
86
+ static async getIPCSocketClient() {
87
+ const socketPath = (0, import_path.resolve)(process.cwd(), process.env.SOCKET_PATH || "storage/gateway.sock");
88
+ try {
89
+ return await import_ipc_socket_client.IPCSocketClient.getConnection(socketPath);
90
+ } catch (error) {
91
+ return false;
92
+ }
93
+ }
86
94
  destroy() {
87
95
  this.reset();
88
96
  _Gateway.instance = null;
@@ -242,6 +250,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
242
250
  getCallback() {
243
251
  return this.requestHandler.bind(this);
244
252
  }
253
+ /* istanbul ignore next -- @preserve */
245
254
  async watch() {
246
255
  if (!process.env.IS_DEV_CMD) {
247
256
  return;
@@ -252,6 +261,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
252
261
  }
253
262
  require(file);
254
263
  }
264
+ /* istanbul ignore next -- @preserve */
255
265
  async run(options) {
256
266
  const isStart = this.isStart();
257
267
  let ipcClient;
@@ -303,11 +313,9 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
303
313
  return argv[2] === "help";
304
314
  }
305
315
  getStartOptions() {
306
- const argv = process.argv;
307
316
  const program = new import_commander.Command();
308
317
  program.allowUnknownOption().option("-s, --silent").option("-p, --port [post]").option("-h, --host [host]").option("--db-sync").parse(process.argv);
309
- const options = program.opts();
310
- return options;
318
+ return program.opts();
311
319
  }
312
320
  start(options) {
313
321
  this.startHttpServer(options);
@@ -362,14 +370,6 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
362
370
  (_a = this.server) == null ? void 0 : _a.close();
363
371
  (_b = this.wsServer) == null ? void 0 : _b.close();
364
372
  }
365
- static async getIPCSocketClient() {
366
- const socketPath = (0, import_path.resolve)(process.cwd(), process.env.SOCKET_PATH || "storage/gateway.sock");
367
- try {
368
- return await import_ipc_socket_client.IPCSocketClient.getConnection(socketPath);
369
- } catch (error) {
370
- return false;
371
- }
372
- }
373
373
  };
374
374
  __name(_Gateway, "Gateway");
375
375
  __publicField(_Gateway, "instance");
package/lib/helper.js CHANGED
@@ -137,10 +137,12 @@ const getCommandFullName = /* @__PURE__ */ __name((command) => {
137
137
  }
138
138
  return names.join(".");
139
139
  }, "getCommandFullName");
140
+ /* istanbul ignore next -- @preserve */
140
141
  const tsxRerunning = /* @__PURE__ */ __name(async () => {
141
142
  const file = (0, import_path.resolve)(process.cwd(), "storage/app.watch.ts");
142
143
  await import_fs.default.promises.writeFile(file, `export const watchId = '${(0, import_utils.uid)()}';`, "utf-8");
143
144
  }, "tsxRerunning");
145
+ /* istanbul ignore next -- @preserve */
144
146
  const enablePerfHooks = /* @__PURE__ */ __name((app) => {
145
147
  app.context.getPerfHistogram = (name) => {
146
148
  if (!app.perfHistograms.has(name)) {
@@ -1,3 +1,2 @@
1
1
  export * from './data-wrapping';
2
- export * from './db2resource';
3
2
  export { parseVariables } from './parse-variables';
@@ -22,11 +22,9 @@ __export(middlewares_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(middlewares_exports);
24
24
  __reExport(middlewares_exports, require("./data-wrapping"), module.exports);
25
- __reExport(middlewares_exports, require("./db2resource"), module.exports);
26
25
  var import_parse_variables = require("./parse-variables");
27
26
  // Annotate the CommonJS export names for ESM import in node:
28
27
  0 && (module.exports = {
29
28
  parseVariables,
30
- ...require("./data-wrapping"),
31
- ...require("./db2resource")
29
+ ...require("./data-wrapping")
32
30
  });
package/lib/migration.js CHANGED
@@ -22,6 +22,7 @@ __export(migration_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(migration_exports);
24
24
  var import_database = require("@nocobase/database");
25
+ /* istanbul ignore file -- @preserve */
25
26
  const _Migration = class _Migration extends import_database.Migration {
26
27
  appVersion = "";
27
28
  pluginVersion = "";
@@ -23,6 +23,7 @@ __export(package_name_unique_exports, {
23
23
  module.exports = __toCommonJS(package_name_unique_exports);
24
24
  var import_database = require("@nocobase/database");
25
25
  var import_migration = require("../migration");
26
+ /* istanbul ignore file -- @preserve */
26
27
  const _package_name_unique_default = class _package_name_unique_default extends import_migration.Migration {
27
28
  on = "beforeLoad";
28
29
  appVersion = "<0.14.0-alpha.2";
@@ -23,6 +23,7 @@ __export(update_pkg_exports, {
23
23
  module.exports = __toCommonJS(update_pkg_exports);
24
24
  var import_migration = require("../migration");
25
25
  var import_plugin_manager = require("../plugin-manager");
26
+ /* istanbul ignore file -- @preserve */
26
27
  const _update_pkg_default = class _update_pkg_default extends import_migration.Migration {
27
28
  on = "afterSync";
28
29
  // 'beforeLoad' or 'afterLoad'
@@ -22,6 +22,7 @@ __export(update_plugins_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(update_plugins_exports);
24
24
  var import_migration = require("../migration");
25
+ /* istanbul ignore file -- @preserve */
25
26
  const _update_plugins_default = class _update_plugins_default extends import_migration.Migration {
26
27
  on = "afterSync";
27
28
  // 'beforeLoad' or 'afterLoad'
@@ -42,6 +42,7 @@ __export(clientStaticUtils_exports, {
42
42
  module.exports = __toCommonJS(clientStaticUtils_exports);
43
43
  var import_fs = __toESM(require("fs"));
44
44
  var import_path = __toESM(require("path"));
45
+ /* istanbul ignore file -- @preserve */
45
46
  const PLUGIN_STATICS_PATH = "/static/plugins/";
46
47
  function getDepPkgPath(packageName, cwd) {
47
48
  try {
@@ -43,11 +43,11 @@ export declare class PluginManager {
43
43
  /**
44
44
  * @internal
45
45
  */
46
- _repository: PluginManagerRepository;
46
+ constructor(options: PluginManagerOptions);
47
47
  /**
48
48
  * @internal
49
49
  */
50
- constructor(options: PluginManagerOptions);
50
+ _repository: PluginManagerRepository;
51
51
  get repository(): PluginManagerRepository;
52
52
  /**
53
53
  * @internal
@@ -93,17 +93,12 @@ 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;
97
96
  enable(name: string | string[]): Promise<void>;
98
97
  disable(name: string | string[]): Promise<void>;
99
98
  remove(name: string | string[], options?: {
100
99
  removeDir?: boolean;
101
100
  force?: boolean;
102
101
  }): Promise<void>;
103
- /**
104
- * @deprecated
105
- */
106
- loadOne(plugin: Plugin): Promise<void>;
107
102
  /**
108
103
  * @internal
109
104
  */
@@ -196,5 +191,6 @@ export declare class PluginManager {
196
191
  * @internal
197
192
  */
198
193
  initPresetPlugins(): Promise<void>;
194
+ private sort;
199
195
  }
200
196
  export default PluginManager;
@@ -223,6 +223,7 @@ const _PluginManager = class _PluginManager {
223
223
  this.app.pm.pluginInstances.delete(instance.constructor);
224
224
  }
225
225
  }
226
+ /* istanbul ignore next -- @preserve */
226
227
  async create(pluginName, options) {
227
228
  const createPlugin = /* @__PURE__ */ __name(async (name) => {
228
229
  const pluginDir = (0, import_path.resolve)(process.cwd(), "packages/plugins", name);
@@ -447,20 +448,6 @@ const _PluginManager = class _PluginManager {
447
448
  }
448
449
  });
449
450
  }
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
- }
464
451
  async enable(name) {
465
452
  let pluginNames = name;
466
453
  if (name === "*") {
@@ -667,24 +654,6 @@ const _PluginManager = class _PluginManager {
667
654
  }
668
655
  await (0, import_execa.default)("yarn", ["nocobase", "refresh"]);
669
656
  }
670
- /**
671
- * @deprecated
672
- */
673
- async loadOne(plugin) {
674
- this.app.setMaintainingMessage(`loading plugin ${plugin.name}...`);
675
- if (plugin.state.loaded || !plugin.enabled) {
676
- return;
677
- }
678
- const name = plugin.getName();
679
- await plugin.beforeLoad();
680
- await this.app.emitAsync("beforeLoadPlugin", plugin, {});
681
- this.app.logger.debug(`loading plugin...`, { submodule: "plugin-manager", method: "loadOne", name });
682
- await plugin.load();
683
- plugin.state.loaded = true;
684
- await this.app.emitAsync("afterLoadPlugin", plugin, {});
685
- this.app.logger.debug(`after load plugin...`, { submodule: "plugin-manager", method: "loadOne", name });
686
- this.app.setMaintainingMessage(`loaded plugin ${plugin.name}`);
687
- }
688
657
  /**
689
658
  * @internal
690
659
  */
@@ -1016,6 +985,20 @@ const _PluginManager = class _PluginManager {
1016
985
  }
1017
986
  this["_initPresetPlugins"] = true;
1018
987
  }
988
+ sort(names) {
989
+ var _a, _b, _c;
990
+ const pluginNames = import_lodash.default.castArray(names);
991
+ if (pluginNames.length === 1) {
992
+ return pluginNames;
993
+ }
994
+ const sorter = new import_topo.default.Sorter();
995
+ for (const pluginName of pluginNames) {
996
+ const plugin = this.get(pluginName);
997
+ const peerDependencies = Object.keys(((_b = (_a = plugin.options) == null ? void 0 : _a.packageJson) == null ? void 0 : _b.peerDependencies) || {});
998
+ sorter.add(pluginName, { after: peerDependencies, group: ((_c = plugin.options) == null ? void 0 : _c.packageName) || pluginName });
999
+ }
1000
+ return sorter.nodes;
1001
+ }
1019
1002
  };
1020
1003
  __name(_PluginManager, "PluginManager");
1021
1004
  let PluginManager = _PluginManager;
@@ -78,6 +78,7 @@ var import_semver = __toESM(require("semver"));
78
78
  var import_clientStaticUtils = require("./clientStaticUtils");
79
79
  var import_constants = require("./constants");
80
80
  var import_deps = __toESM(require("./deps"));
81
+ /* istanbul ignore next -- @preserve */
81
82
  async function getTempDir() {
82
83
  const temporaryDirectory = await import_fs_extra.default.realpath(import_os.default.tmpdir());
83
84
  return import_path.default.join(temporaryDirectory, import_constants.APP_NAME);
@@ -116,11 +117,11 @@ __name(getNodeModulesPluginDir, "getNodeModulesPluginDir");
116
117
  function getAuthorizationHeaders(registry, authToken) {
117
118
  const headers = {};
118
119
  if (registry && !authToken) {
119
- const npmrcPath = import_path.default.join(process.cwd(), ".npmrc");
120
+ const npmrcPath = import_path.default.join(import_os.default.homedir(), ".npmrc");
120
121
  const url = new URL(registry);
121
122
  let envConfig = process.env;
122
123
  if (import_fs_extra.default.existsSync(npmrcPath)) {
123
- const content = import_fs_extra.default.readFileSync(import_path.default.join(process.cwd(), ".npmrc"), "utf-8");
124
+ const content = import_fs_extra.default.readFileSync(npmrcPath, "utf-8");
124
125
  envConfig = {
125
126
  ...envConfig,
126
127
  ...import_ini.default.parse(content)
package/lib/plugin.d.ts CHANGED
@@ -65,10 +65,6 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
65
65
  * @internal
66
66
  */
67
67
  setOptions(options: any): void;
68
- /**
69
- * @internal
70
- */
71
- protected getSourceDir(): Promise<string>;
72
68
  /**
73
69
  * @internal
74
70
  */
@@ -90,13 +86,17 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
90
86
  */
91
87
  requiredPlugins(): any[];
92
88
  t(text: TFuncKey | TFuncKey[], options?: TOptions): import("i18next").TFunctionDetailedResult<object>;
89
+ /**
90
+ * @experimental
91
+ */
92
+ toJSON(options?: any): Promise<any>;
93
93
  /**
94
94
  * @internal
95
95
  */
96
- protected isDev(): Promise<boolean>;
96
+ protected getSourceDir(): Promise<string>;
97
97
  /**
98
- * @experimental
98
+ * @internal
99
99
  */
100
- toJSON(options?: any): Promise<any>;
100
+ protected isDev(): Promise<boolean>;
101
101
  }
102
102
  export default Plugin;
package/lib/plugin.js CHANGED
@@ -38,6 +38,7 @@ var import_glob = __toESM(require("glob"));
38
38
  var import_path = require("path");
39
39
  var import_plugin_manager = require("./plugin-manager");
40
40
  var import_utils2 = require("./plugin-manager/utils");
41
+ /* istanbul ignore file -- @preserve */
41
42
  const _Plugin = class _Plugin {
42
43
  options;
43
44
  app;
@@ -126,21 +127,6 @@ const _Plugin = class _Plugin {
126
127
  setOptions(options) {
127
128
  this.options = options || {};
128
129
  }
129
- /**
130
- * @internal
131
- */
132
- async getSourceDir() {
133
- if (this._sourceDir) {
134
- return this._sourceDir;
135
- }
136
- if (await this.isDev()) {
137
- return this._sourceDir = "src";
138
- }
139
- if ((0, import_path.basename)(__dirname) === "src") {
140
- return this._sourceDir = "src";
141
- }
142
- return this._sourceDir = this.isPreset ? "lib" : "dist";
143
- }
144
130
  /**
145
131
  * @internal
146
132
  */
@@ -217,21 +203,6 @@ const _Plugin = class _Plugin {
217
203
  t(text, options = {}) {
218
204
  return this.app.i18n.t(text, { ns: this.options["packageName"], ...options });
219
205
  }
220
- /**
221
- * @internal
222
- */
223
- async isDev() {
224
- if (!this.options.packageName) {
225
- return false;
226
- }
227
- const file = await import_fs.default.promises.realpath(
228
- (0, import_path.resolve)(process.env.NODE_MODULES_PATH || (0, import_path.resolve)(process.cwd(), "node_modules"), this.options.packageName)
229
- );
230
- if (file.startsWith((0, import_path.resolve)(process.cwd(), "packages"))) {
231
- return !!process.env.IS_DEV_CMD;
232
- }
233
- return false;
234
- }
235
206
  /**
236
207
  * @experimental
237
208
  */
@@ -266,6 +237,36 @@ const _Plugin = class _Plugin {
266
237
  }
267
238
  return results;
268
239
  }
240
+ /**
241
+ * @internal
242
+ */
243
+ async getSourceDir() {
244
+ if (this._sourceDir) {
245
+ return this._sourceDir;
246
+ }
247
+ if (await this.isDev()) {
248
+ return this._sourceDir = "src";
249
+ }
250
+ if ((0, import_path.basename)(__dirname) === "src") {
251
+ return this._sourceDir = "src";
252
+ }
253
+ return this._sourceDir = this.isPreset ? "lib" : "dist";
254
+ }
255
+ /**
256
+ * @internal
257
+ */
258
+ async isDev() {
259
+ if (!this.options.packageName) {
260
+ return false;
261
+ }
262
+ const file = await import_fs.default.promises.realpath(
263
+ (0, import_path.resolve)(process.env.NODE_MODULES_PATH || (0, import_path.resolve)(process.cwd(), "node_modules"), this.options.packageName)
264
+ );
265
+ if (file.startsWith((0, import_path.resolve)(process.cwd(), "packages"))) {
266
+ return !!process.env.IS_DEV_CMD;
267
+ }
268
+ return false;
269
+ }
269
270
  };
270
271
  __name(_Plugin, "Plugin");
271
272
  let Plugin = _Plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "0.21.0-alpha.14",
3
+ "version": "0.21.0-alpha.16",
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",
14
- "@nocobase/actions": "0.21.0-alpha.14",
15
- "@nocobase/auth": "0.21.0-alpha.14",
16
- "@nocobase/cache": "0.21.0-alpha.14",
17
- "@nocobase/data-source-manager": "0.21.0-alpha.14",
18
- "@nocobase/database": "0.21.0-alpha.14",
19
- "@nocobase/evaluators": "0.21.0-alpha.14",
20
- "@nocobase/logger": "0.21.0-alpha.14",
21
- "@nocobase/resourcer": "0.21.0-alpha.14",
22
- "@nocobase/sdk": "0.21.0-alpha.14",
23
- "@nocobase/telemetry": "0.21.0-alpha.14",
24
- "@nocobase/utils": "0.21.0-alpha.14",
13
+ "@nocobase/acl": "0.21.0-alpha.16",
14
+ "@nocobase/actions": "0.21.0-alpha.16",
15
+ "@nocobase/auth": "0.21.0-alpha.16",
16
+ "@nocobase/cache": "0.21.0-alpha.16",
17
+ "@nocobase/data-source-manager": "0.21.0-alpha.16",
18
+ "@nocobase/database": "0.21.0-alpha.16",
19
+ "@nocobase/evaluators": "0.21.0-alpha.16",
20
+ "@nocobase/logger": "0.21.0-alpha.16",
21
+ "@nocobase/resourcer": "0.21.0-alpha.16",
22
+ "@nocobase/sdk": "0.21.0-alpha.16",
23
+ "@nocobase/telemetry": "0.21.0-alpha.16",
24
+ "@nocobase/utils": "0.21.0-alpha.16",
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": "dbcca03c0535e14f0b09fd13306731b4438829c4"
57
+ "gitHead": "2914500f14e4454cc5702a49371230865660ca33"
58
58
  }
@@ -1,6 +0,0 @@
1
- export declare class MultipleInstanceManager<Item> {
2
- map: Map<string, Item>;
3
- constructor();
4
- get(key: string): Item;
5
- set(key: string, value: Item): void;
6
- }
@@ -1,40 +0,0 @@
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 multiple_instance_manager_exports = {};
20
- __export(multiple_instance_manager_exports, {
21
- MultipleInstanceManager: () => MultipleInstanceManager
22
- });
23
- module.exports = __toCommonJS(multiple_instance_manager_exports);
24
- const _MultipleInstanceManager = class _MultipleInstanceManager {
25
- map = /* @__PURE__ */ new Map();
26
- constructor() {
27
- }
28
- get(key) {
29
- return this.map.get(key);
30
- }
31
- set(key, value) {
32
- this.map.set(key, value);
33
- }
34
- };
35
- __name(_MultipleInstanceManager, "MultipleInstanceManager");
36
- let MultipleInstanceManager = _MultipleInstanceManager;
37
- // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {
39
- MultipleInstanceManager
40
- });
@@ -1,6 +0,0 @@
1
- import Database from '@nocobase/database';
2
- import { ResourcerContext } from '@nocobase/resourcer';
3
- export declare function db2resource(ctx: ResourcerContext & {
4
- db: Database;
5
- }, next: () => Promise<any>): Promise<any>;
6
- export default db2resource;
@@ -1,69 +0,0 @@
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 db2resource_exports = {};
20
- __export(db2resource_exports, {
21
- db2resource: () => db2resource,
22
- default: () => db2resource_default
23
- });
24
- module.exports = __toCommonJS(db2resource_exports);
25
- var import_resourcer = require("@nocobase/resourcer");
26
- async function db2resource(ctx, next) {
27
- const resourcer = ctx.resourcer;
28
- const database = ctx.db;
29
- const params = (0, import_resourcer.parseRequest)(
30
- {
31
- path: ctx.request.path,
32
- method: ctx.request.method
33
- },
34
- {
35
- prefix: resourcer.options.prefix,
36
- accessors: resourcer.options.accessors
37
- }
38
- );
39
- if (!params) {
40
- return next();
41
- }
42
- const resourceName = (0, import_resourcer.getNameByParams)(params);
43
- if (resourcer.isDefined(resourceName)) {
44
- return next();
45
- }
46
- const splitResult = resourceName.split(".");
47
- const collectionName = splitResult[0];
48
- const fieldName = splitResult[1];
49
- if (!database.hasCollection(collectionName)) {
50
- return next();
51
- }
52
- const collection = database.getCollection(collectionName);
53
- let resourceType = "single";
54
- if (fieldName && collection.hasField(fieldName)) {
55
- const field = collection.getField(fieldName);
56
- resourceType = field.type;
57
- }
58
- resourcer.define({
59
- type: resourceType,
60
- name: resourceName
61
- });
62
- return next();
63
- }
64
- __name(db2resource, "db2resource");
65
- var db2resource_default = db2resource;
66
- // Annotate the CommonJS export names for ESM import in node:
67
- 0 && (module.exports = {
68
- db2resource
69
- });