@nocobase/cli 3.0.0-alpha.8 → 3.0.0-alpha.9

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.
@@ -1,10 +1,19 @@
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
+ */
1
9
  import { Command } from '@oclif/core';
2
10
  import { buildCreateArgs, createFlags, runResourceCommand } from '../../../lib/resource-command.js';
3
11
  export default class ResourceCreate extends Command {
4
- static summary = 'Create a record in a resource';
5
- static description = 'Create a record in a generic resource. Pass record content through --values as a JSON object.';
12
+ static summary = 'Create one or more records in a resource';
13
+ static description = 'Create records in a generic resource. Pass record content through --values as a JSON object, or as a JSON array of objects to create multiple records in a single request.';
6
14
  static examples = [
7
15
  `<%= config.bin %> <%= command.id %> --resource users --values '{"nickname":"Ada"}'`,
16
+ `<%= config.bin %> <%= command.id %> --resource users --values '[{"nickname":"Ada"},{"nickname":"Grace"}]'`,
8
17
  `<%= config.bin %> <%= command.id %> --resource posts.comments --source-id 1 --values '{"content":"Hello"}'`,
9
18
  ];
10
19
  static flags = createFlags;
@@ -41,6 +41,22 @@ function parseObjectFlag(value, flagName) {
41
41
  }
42
42
  return parsed;
43
43
  }
44
+ function parseValuesFlag(value, flagName) {
45
+ if (value === undefined) {
46
+ return undefined;
47
+ }
48
+ const parsed = parseJson(value, flagName);
49
+ if (!parsed || typeof parsed !== 'object') {
50
+ throw new Error(`--${flagName} must be a JSON object, or a JSON array of objects to create multiple records`);
51
+ }
52
+ if (Array.isArray(parsed)) {
53
+ const invalidIndex = parsed.findIndex((item) => !item || Array.isArray(item) || typeof item !== 'object');
54
+ if (invalidIndex !== -1) {
55
+ throw new Error(`--${flagName} array items must all be JSON objects, but item ${invalidIndex} is not`);
56
+ }
57
+ }
58
+ return parsed;
59
+ }
44
60
  function parseJsonArrayFlag(value, flagName) {
45
61
  if (value === undefined) {
46
62
  return undefined;
@@ -187,7 +203,7 @@ export const createFlags = {
187
203
  ...resourceBaseFlags,
188
204
  ...resourceAssociationFlags,
189
205
  values: Flags.string({
190
- description: 'Record values used by create as a JSON object.',
206
+ description: 'Record values used by create as a JSON object, or a JSON array of objects to create multiple records in one request.',
191
207
  required: true,
192
208
  }),
193
209
  whitelist: Flags.string({
@@ -298,7 +314,7 @@ export function buildGetArgs(flags) {
298
314
  export function buildCreateArgs(flags) {
299
315
  return {
300
316
  ...pickSharedArgs(flags),
301
- values: parseObjectFlag(flags.values, 'values'),
317
+ values: parseValuesFlag(flags.values, 'values'),
302
318
  whitelist: parseStringArrayFlags(flags.whitelist, 'whitelist'),
303
319
  blacklist: parseStringArrayFlags(flags.blacklist, 'blacklist'),
304
320
  };
@@ -1,3 +1,11 @@
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
+ */
1
9
  import { executeRawApiRequest } from './api-client.js';
2
10
  function buildActionUrl(resource, action, sourceId) {
3
11
  if (typeof sourceId === 'undefined' || sourceId === null || !resource.includes('.')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "3.0.0-alpha.8",
3
+ "version": "3.0.0-alpha.9",
4
4
  "description": "NocoBase Command Line Tool",
5
5
  "type": "module",
6
6
  "main": "dist/generated/command-registry.js",
@@ -147,5 +147,5 @@
147
147
  "type": "git",
148
148
  "url": "git+https://github.com/nocobase/nocobase.git"
149
149
  },
150
- "gitHead": "ce017f3deb8b2414c6b13818042c4187270d1d8a"
150
+ "gitHead": "82aaad40c5be1120839a11301a48e7fe690f48c3"
151
151
  }