@nocobase/server 2.1.0-alpha.19 → 2.1.0-alpha.20

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.
@@ -122,7 +122,7 @@ const _MainDataSource = class _MainDataSource extends import_data_source_manager
122
122
  const loadedData = {};
123
123
  for (const collection of collections) {
124
124
  const c = db.getCollection(collection.name);
125
- loadedData[c.tableName()] = {
125
+ loadedData[c.model.tableName] = {
126
126
  ...collection.toJSON(),
127
127
  fields: collection.fields.map((field) => {
128
128
  const f = c.getField(field.name);
@@ -44,10 +44,10 @@ __export(resource_exports, {
44
44
  });
45
45
  module.exports = __toCommonJS(resource_exports);
46
46
  var import_utils = require("@nocobase/utils");
47
+ var import_crypto = __toESM(require("crypto"));
47
48
  var import_fs = __toESM(require("fs"));
48
49
  var import_fs_extra = __toESM(require("fs-extra"));
49
50
  var import_path = __toESM(require("path"));
50
- var import_crypto = __toESM(require("crypto"));
51
51
  var import_utils2 = require("../utils");
52
52
  var import_package = __toESM(require("../../../package.json"));
53
53
  const PLUGIN_CLIENT_ENTRY_FILES = {
@@ -139,6 +139,21 @@ async function listEnabledPlugins(ctx, lane = "client") {
139
139
  return arr;
140
140
  }
141
141
  __name(listEnabledPlugins, "listEnabledPlugins");
142
+ function normalizePmPluginKeys(filterByTk) {
143
+ return filterByTk.split(",").map((k) => k.trim()).filter(Boolean);
144
+ }
145
+ __name(normalizePmPluginKeys, "normalizePmPluginKeys");
146
+ function coerceAwaitResponse(value) {
147
+ if (value === true || value === 1) {
148
+ return true;
149
+ }
150
+ if (typeof value === "string") {
151
+ const v = value.trim().toLowerCase();
152
+ return v === "true" || v === "1" || v === "yes";
153
+ }
154
+ return false;
155
+ }
156
+ __name(coerceAwaitResponse, "coerceAwaitResponse");
142
157
  var resource_default = {
143
158
  name: "pm",
144
159
  actions: {
@@ -216,23 +231,46 @@ var resource_default = {
216
231
  await next();
217
232
  },
218
233
  async enable(ctx, next) {
219
- const { filterByTk } = ctx.action.params;
234
+ const { filterByTk, awaitResponse: awaitResponseRaw } = ctx.action.params;
220
235
  const app = ctx.app;
221
- if (!filterByTk) {
236
+ if (filterByTk == null || filterByTk === "" || typeof filterByTk !== "string") {
237
+ ctx.throw(400, "plugin name invalid");
238
+ }
239
+ const keys = normalizePmPluginKeys(filterByTk);
240
+ if (!keys.length) {
222
241
  ctx.throw(400, "plugin name invalid");
223
242
  }
224
- const keys = Array.isArray(filterByTk) ? filterByTk : [filterByTk];
225
- app.runAsCLI(["pm", "enable", ...keys], { from: "user" });
243
+ const awaitResponse = coerceAwaitResponse(awaitResponseRaw);
244
+ const argv = ["pm", "enable", ...keys];
245
+ if (awaitResponse) {
246
+ await app.runAsCLI(argv, { from: "user", throwError: true });
247
+ } else {
248
+ void app.runAsCLI(argv, { from: "user" }).catch((err) => {
249
+ app.log.error(err);
250
+ });
251
+ }
226
252
  ctx.body = filterByTk;
227
253
  await next();
228
254
  },
229
255
  async disable(ctx, next) {
230
- const { filterByTk } = ctx.action.params;
231
- if (!filterByTk) {
256
+ const { filterByTk, awaitResponse: awaitResponseRaw } = ctx.action.params;
257
+ const app = ctx.app;
258
+ if (filterByTk == null || filterByTk === "" || typeof filterByTk !== "string") {
232
259
  ctx.throw(400, "plugin name invalid");
233
260
  }
234
- const app = ctx.app;
235
- app.runAsCLI(["pm", "disable", filterByTk], { from: "user" });
261
+ const keys = normalizePmPluginKeys(filterByTk);
262
+ if (!keys.length) {
263
+ ctx.throw(400, "plugin name invalid");
264
+ }
265
+ const awaitResponse = coerceAwaitResponse(awaitResponseRaw);
266
+ const argv = ["pm", "disable", ...keys];
267
+ if (awaitResponse) {
268
+ await app.runAsCLI(argv, { from: "user", throwError: true });
269
+ } else {
270
+ void app.runAsCLI(argv, { from: "user" }).catch((err) => {
271
+ app.log.error(err);
272
+ });
273
+ }
236
274
  ctx.body = filterByTk;
237
275
  await next();
238
276
  },
@@ -34,6 +34,25 @@ declare const _default: {
34
34
  })[];
35
35
  components: {
36
36
  schemas: {
37
+ PMPluginListSummaryItem: {
38
+ readonly type: "object";
39
+ readonly description: "Compact plugin row returned when listing with `mode=summary`.";
40
+ readonly properties: {
41
+ readonly displayName: {
42
+ readonly type: "string";
43
+ };
44
+ readonly packageName: {
45
+ readonly type: "string";
46
+ };
47
+ readonly enabled: {
48
+ readonly type: "boolean";
49
+ };
50
+ readonly description: {
51
+ readonly type: "string";
52
+ };
53
+ };
54
+ readonly additionalProperties: true;
55
+ };
37
56
  PMPlugin: {
38
57
  readonly type: "object";
39
58
  readonly properties: {
@@ -356,18 +375,29 @@ declare const _default: {
356
375
  readonly get: {
357
376
  readonly tags: readonly ["pm"];
358
377
  readonly summary: "List available plugins";
359
- readonly description: "Return plugin metadata from the plugin manager.";
360
- readonly parameters: readonly [];
378
+ readonly description: "Return plugin metadata from the plugin manager. Pass `mode=summary` for a lightweight list built from discovered packages; omit `mode` for full records (locale-aware via the nocobase plugin).";
379
+ readonly parameters: readonly [{
380
+ name: string;
381
+ in: string;
382
+ required: boolean;
383
+ description: string;
384
+ schema: {
385
+ type: string;
386
+ enum: string[];
387
+ };
388
+ }];
361
389
  readonly responses: {
362
390
  readonly 200: {
363
391
  description: string;
364
392
  content: {
365
393
  'application/json': {
366
394
  schema: {
367
- type: string;
368
- items: {
369
- $ref: string;
370
- };
395
+ oneOf: {
396
+ type: string;
397
+ items: {
398
+ $ref: string;
399
+ };
400
+ }[];
371
401
  };
372
402
  };
373
403
  };
@@ -537,14 +567,23 @@ declare const _default: {
537
567
  readonly post: {
538
568
  readonly tags: readonly ["pm"];
539
569
  readonly summary: "Enable a plugin";
540
- readonly description: "Queue an enable operation for a plugin.";
570
+ readonly description: "Run plugin enable via the plugin manager. Use `awaitResponse=true` to wait for completion. Multiple plugins can be passed in `filterByTk` as a comma-separated list.";
541
571
  readonly parameters: readonly [{
542
572
  name: string;
543
573
  in: string;
574
+ required: boolean;
544
575
  description: string;
576
+ schema: {
577
+ type: string;
578
+ };
579
+ }, {
580
+ name: string;
581
+ in: string;
545
582
  required: boolean;
583
+ description: string;
546
584
  schema: {
547
585
  type: string;
586
+ default: boolean;
548
587
  };
549
588
  }];
550
589
  readonly responses: {
@@ -573,14 +612,23 @@ declare const _default: {
573
612
  readonly post: {
574
613
  readonly tags: readonly ["pm"];
575
614
  readonly summary: "Disable a plugin";
576
- readonly description: "Queue a disable operation for a plugin.";
615
+ readonly description: "Run plugin disable via the plugin manager. Use `awaitResponse=true` to wait for completion. Multiple plugins can be passed in `filterByTk` as a comma-separated list.";
577
616
  readonly parameters: readonly [{
578
617
  name: string;
579
618
  in: string;
619
+ required: boolean;
580
620
  description: string;
621
+ schema: {
622
+ type: string;
623
+ };
624
+ }, {
625
+ name: string;
626
+ in: string;
581
627
  required: boolean;
628
+ description: string;
582
629
  schema: {
583
630
  type: string;
631
+ default: boolean;
584
632
  };
585
633
  }];
586
634
  readonly responses: {
@@ -8,6 +8,25 @@
8
8
  */
9
9
  export declare const pmComponents: {
10
10
  readonly schemas: {
11
+ readonly PMPluginListSummaryItem: {
12
+ readonly type: "object";
13
+ readonly description: "Compact plugin row returned when listing with `mode=summary`.";
14
+ readonly properties: {
15
+ readonly displayName: {
16
+ readonly type: "string";
17
+ };
18
+ readonly packageName: {
19
+ readonly type: "string";
20
+ };
21
+ readonly enabled: {
22
+ readonly type: "boolean";
23
+ };
24
+ readonly description: {
25
+ readonly type: "string";
26
+ };
27
+ };
28
+ readonly additionalProperties: true;
29
+ };
11
30
  readonly PMPlugin: {
12
31
  readonly type: "object";
13
32
  readonly properties: {
@@ -125,18 +144,29 @@ declare const _default: {
125
144
  readonly get: {
126
145
  readonly tags: readonly ["pm"];
127
146
  readonly summary: "List available plugins";
128
- readonly description: "Return plugin metadata from the plugin manager.";
129
- readonly parameters: readonly [];
147
+ readonly description: "Return plugin metadata from the plugin manager. Pass `mode=summary` for a lightweight list built from discovered packages; omit `mode` for full records (locale-aware via the nocobase plugin).";
148
+ readonly parameters: readonly [{
149
+ name: string;
150
+ in: string;
151
+ required: boolean;
152
+ description: string;
153
+ schema: {
154
+ type: string;
155
+ enum: string[];
156
+ };
157
+ }];
130
158
  readonly responses: {
131
159
  readonly 200: {
132
160
  description: string;
133
161
  content: {
134
162
  'application/json': {
135
163
  schema: {
136
- type: string;
137
- items: {
138
- $ref: string;
139
- };
164
+ oneOf: {
165
+ type: string;
166
+ items: {
167
+ $ref: string;
168
+ };
169
+ }[];
140
170
  };
141
171
  };
142
172
  };
@@ -306,14 +336,23 @@ declare const _default: {
306
336
  readonly post: {
307
337
  readonly tags: readonly ["pm"];
308
338
  readonly summary: "Enable a plugin";
309
- readonly description: "Queue an enable operation for a plugin.";
339
+ readonly description: "Run plugin enable via the plugin manager. Use `awaitResponse=true` to wait for completion. Multiple plugins can be passed in `filterByTk` as a comma-separated list.";
310
340
  readonly parameters: readonly [{
311
341
  name: string;
312
342
  in: string;
343
+ required: boolean;
313
344
  description: string;
345
+ schema: {
346
+ type: string;
347
+ };
348
+ }, {
349
+ name: string;
350
+ in: string;
314
351
  required: boolean;
352
+ description: string;
315
353
  schema: {
316
354
  type: string;
355
+ default: boolean;
317
356
  };
318
357
  }];
319
358
  readonly responses: {
@@ -342,14 +381,23 @@ declare const _default: {
342
381
  readonly post: {
343
382
  readonly tags: readonly ["pm"];
344
383
  readonly summary: "Disable a plugin";
345
- readonly description: "Queue a disable operation for a plugin.";
384
+ readonly description: "Run plugin disable via the plugin manager. Use `awaitResponse=true` to wait for completion. Multiple plugins can be passed in `filterByTk` as a comma-separated list.";
346
385
  readonly parameters: readonly [{
347
386
  name: string;
348
387
  in: string;
388
+ required: boolean;
349
389
  description: string;
390
+ schema: {
391
+ type: string;
392
+ };
393
+ }, {
394
+ name: string;
395
+ in: string;
350
396
  required: boolean;
397
+ description: string;
351
398
  schema: {
352
399
  type: string;
400
+ default: boolean;
353
401
  };
354
402
  }];
355
403
  readonly responses: {
package/lib/swagger/pm.js CHANGED
@@ -39,28 +39,67 @@ const pluginNameParameter = {
39
39
  type: "string"
40
40
  }
41
41
  };
42
- const pluginListResponse = {
42
+ const pluginPmEnableDisableFilterParameter = {
43
+ name: "filterByTk",
44
+ in: "query",
45
+ required: true,
46
+ description: "Plugin package name(s). Pass multiple plugins as a comma-separated list (e.g. `@nocobase/plugin-a,@nocobase/plugin-b`).",
47
+ schema: {
48
+ type: "string"
49
+ }
50
+ };
51
+ const pluginPmAwaitResponseParameter = {
52
+ name: "awaitResponse",
53
+ in: "query",
54
+ required: false,
55
+ description: "When `true`, await the CLI operation and return its result in the response body. When `false` or omitted, start the operation and return promptly (body is usually the plugin name or the `filterByTk` value for enable).",
56
+ schema: {
57
+ type: "boolean",
58
+ default: false
59
+ }
60
+ };
61
+ const pluginListModeParameter = {
62
+ name: "mode",
63
+ in: "query",
64
+ required: false,
65
+ description: "Use `summary` for a compact list (`displayName`, `packageName`, `enabled`, `description`). Omit for full plugin objects (`PMPlugin`), including locale-specific fields from the nocobase plugin.",
66
+ schema: {
67
+ type: "string",
68
+ enum: ["summary"]
69
+ }
70
+ };
71
+ const enabledPluginListResponse = {
43
72
  description: "OK",
44
73
  content: {
45
74
  "application/json": {
46
75
  schema: {
47
76
  type: "array",
48
77
  items: {
49
- $ref: "#/components/schemas/PMPlugin"
78
+ $ref: "#/components/schemas/PMEnabledPlugin"
50
79
  }
51
80
  }
52
81
  }
53
82
  }
54
83
  };
55
- const enabledPluginListResponse = {
56
- description: "OK",
84
+ const pluginListResponseOneOf = {
85
+ description: "OK. Shape depends on `mode`: full `PMPlugin` list by default, or `PMPluginListSummaryItem` when `mode=summary`.",
57
86
  content: {
58
87
  "application/json": {
59
88
  schema: {
60
- type: "array",
61
- items: {
62
- $ref: "#/components/schemas/PMEnabledPlugin"
63
- }
89
+ oneOf: [
90
+ {
91
+ type: "array",
92
+ items: {
93
+ $ref: "#/components/schemas/PMPlugin"
94
+ }
95
+ },
96
+ {
97
+ type: "array",
98
+ items: {
99
+ $ref: "#/components/schemas/PMPluginListSummaryItem"
100
+ }
101
+ }
102
+ ]
64
103
  }
65
104
  }
66
105
  }
@@ -85,6 +124,25 @@ const pluginOperationResponse = {
85
124
  };
86
125
  const pmComponents = {
87
126
  schemas: {
127
+ PMPluginListSummaryItem: {
128
+ type: "object",
129
+ description: "Compact plugin row returned when listing with `mode=summary`.",
130
+ properties: {
131
+ displayName: {
132
+ type: "string"
133
+ },
134
+ packageName: {
135
+ type: "string"
136
+ },
137
+ enabled: {
138
+ type: "boolean"
139
+ },
140
+ description: {
141
+ type: "string"
142
+ }
143
+ },
144
+ additionalProperties: true
145
+ },
88
146
  PMPlugin: {
89
147
  type: "object",
90
148
  properties: {
@@ -202,10 +260,10 @@ var pm_default = {
202
260
  get: {
203
261
  tags: ["pm"],
204
262
  summary: "List available plugins",
205
- description: "Return plugin metadata from the plugin manager.",
206
- parameters: [],
263
+ description: "Return plugin metadata from the plugin manager. Pass `mode=summary` for a lightweight list built from discovered packages; omit `mode` for full records (locale-aware via the nocobase plugin).",
264
+ parameters: [pluginListModeParameter],
207
265
  responses: {
208
- 200: pluginListResponse
266
+ 200: pluginListResponseOneOf
209
267
  }
210
268
  }
211
269
  },
@@ -328,8 +386,8 @@ var pm_default = {
328
386
  post: {
329
387
  tags: ["pm"],
330
388
  summary: "Enable a plugin",
331
- description: "Queue an enable operation for a plugin.",
332
- parameters: [pluginNameParameter],
389
+ description: "Run plugin enable via the plugin manager. Use `awaitResponse=true` to wait for completion. Multiple plugins can be passed in `filterByTk` as a comma-separated list.",
390
+ parameters: [pluginPmEnableDisableFilterParameter, pluginPmAwaitResponseParameter],
333
391
  responses: {
334
392
  200: pluginOperationResponse
335
393
  }
@@ -339,8 +397,8 @@ var pm_default = {
339
397
  post: {
340
398
  tags: ["pm"],
341
399
  summary: "Disable a plugin",
342
- description: "Queue a disable operation for a plugin.",
343
- parameters: [pluginNameParameter],
400
+ description: "Run plugin disable via the plugin manager. Use `awaitResponse=true` to wait for completion. Multiple plugins can be passed in `filterByTk` as a comma-separated list.",
401
+ parameters: [pluginPmEnableDisableFilterParameter, pluginPmAwaitResponseParameter],
344
402
  responses: {
345
403
  200: pluginOperationResponse
346
404
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "2.1.0-alpha.19",
3
+ "version": "2.1.0-alpha.20",
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.19",
14
- "@nocobase/actions": "2.1.0-alpha.19",
15
- "@nocobase/ai": "2.1.0-alpha.19",
16
- "@nocobase/auth": "2.1.0-alpha.19",
17
- "@nocobase/cache": "2.1.0-alpha.19",
18
- "@nocobase/data-source-manager": "2.1.0-alpha.19",
19
- "@nocobase/database": "2.1.0-alpha.19",
20
- "@nocobase/evaluators": "2.1.0-alpha.19",
21
- "@nocobase/lock-manager": "2.1.0-alpha.19",
22
- "@nocobase/logger": "2.1.0-alpha.19",
23
- "@nocobase/resourcer": "2.1.0-alpha.19",
24
- "@nocobase/sdk": "2.1.0-alpha.19",
25
- "@nocobase/snowflake-id": "2.1.0-alpha.19",
26
- "@nocobase/telemetry": "2.1.0-alpha.19",
27
- "@nocobase/utils": "2.1.0-alpha.19",
13
+ "@nocobase/acl": "2.1.0-alpha.20",
14
+ "@nocobase/actions": "2.1.0-alpha.20",
15
+ "@nocobase/ai": "2.1.0-alpha.20",
16
+ "@nocobase/auth": "2.1.0-alpha.20",
17
+ "@nocobase/cache": "2.1.0-alpha.20",
18
+ "@nocobase/data-source-manager": "2.1.0-alpha.20",
19
+ "@nocobase/database": "2.1.0-alpha.20",
20
+ "@nocobase/evaluators": "2.1.0-alpha.20",
21
+ "@nocobase/lock-manager": "2.1.0-alpha.20",
22
+ "@nocobase/logger": "2.1.0-alpha.20",
23
+ "@nocobase/resourcer": "2.1.0-alpha.20",
24
+ "@nocobase/sdk": "2.1.0-alpha.20",
25
+ "@nocobase/snowflake-id": "2.1.0-alpha.20",
26
+ "@nocobase/telemetry": "2.1.0-alpha.20",
27
+ "@nocobase/utils": "2.1.0-alpha.20",
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": "3d13700360eac1c0f9dbf6a5f167ed396a294a3c"
64
+ "gitHead": "3d1535db6bf93ca23257faf474afee0d565f54c6"
65
65
  }