@contrail/cli 3.6.0-alpha-8-alpha.5ffe1e1 → 3.6.0-alpha-8-alpha.ec1ef67

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.
package/README.md CHANGED
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
17
17
  $ contrail COMMAND
18
18
  running command...
19
19
  $ contrail (--version)
20
- @contrail/cli/3.6.0-alpha-8-alpha.5ffe1e1 linux-x64 node-v24.22.2
20
+ @contrail/cli/3.6.0-alpha-8-alpha.ec1ef67 linux-x64 node-v24.22.2
21
21
  $ contrail --help [COMMAND]
22
22
  USAGE
23
23
  $ contrail COMMAND
@@ -247,6 +247,10 @@ class CreateEntity extends basecommand_1.BaseCommand {
247
247
  if (count !== undefined && count <= 0) {
248
248
  this.error('Count must be a positive integer.');
249
249
  }
250
+ const unknownSubtype = await findUnknownSubtypeError(entityTypePath);
251
+ if (unknownSubtype) {
252
+ this.error(unknownSubtype);
253
+ }
250
254
  const partialEntities = inputFilename
251
255
  ? (0, file_helpers_1.parseFileAsJsonArray)(inputFilename)
252
256
  : Array.from({ length: count || 1 }).fill({});
@@ -314,14 +318,27 @@ async function createEntities(entityName, entities, routing = {}) {
314
318
  const settled = await Promise.allSettled(entities.map(async (e) => limit(() => createEntity(entityName, e, routing))));
315
319
  return summarizeSettledCreates(entities, settled);
316
320
  }
321
+ /**
322
+ * A subtype that does not exist under a type-managed root would otherwise be dropped,
323
+ * creating a root entity instead. The API cannot catch that, because the request it
324
+ * receives is a valid root create. A root that does not exist is left to the API.
325
+ */
326
+ async function findUnknownSubtypeError(entityTypePath) {
327
+ const { root } = (0, types_2.parseTypePath)(entityTypePath);
328
+ if (root === entityTypePath || (await (0, types_3.getTypeByPath)(entityTypePath))) {
329
+ return undefined;
330
+ }
331
+ return (await (0, types_3.getTypeByPath)(root))
332
+ ? `Type not found for path: ${entityTypePath}. The root ${root} exists, so this subtype is misspelled or missing.`
333
+ : undefined;
334
+ }
317
335
  async function buildEntitiesToCreate(entityTypePath, entities, propertySpecificationBySlug) {
318
336
  let type = await (0, types_3.getTypeByPath)(entityTypePath);
319
337
  if (!type) {
320
338
  console.warn(`Type not found for path: ${entityTypePath}`);
321
- type = {
322
- typePath: '',
323
- typeProperties: [],
324
- }; // Fallback to an empty type; This allows us to create entities that are not type-managed
339
+ // an untyped entity such as a webhook has no type record; keep the requested path
340
+ // so the root still resolves for the generated-value lookups
341
+ type = { typePath: entityTypePath, typeProperties: [] };
325
342
  }
326
343
  const [typesCache, objectReferencesCache] = await Promise.all([
327
344
  (0, types_2.buildLocalTypesCache)([...(0, types_2.getReferencedTypePaths)(type), entityTypePath]),
@@ -461,7 +478,7 @@ function pickRandomValueForProperty(property, objectReferencesCache, typeReferen
461
478
  case types_1.PropertyType.MultiSelect:
462
479
  if (!property.options)
463
480
  throw new Error('Option set is required for MultiSelect property');
464
- const randomSelection = pickRandomOptions(property.options, Math.max(2, property.options.length)); // Avoid picking more than the number of options
481
+ const randomSelection = pickRandomOptions(property.options, 1 + Math.floor(Math.random() * property.options.length));
465
482
  return randomSelection.map((option) => option.value);
466
483
  case types_1.PropertyType.Sequence:
467
484
  return generateRandomNumber();
@@ -493,7 +510,7 @@ function pickRandomValueForProperty(property, objectReferencesCache, typeReferen
493
510
  }
494
511
  exports.pickRandomValueForProperty = pickRandomValueForProperty;
495
512
  function pickRandomOptions(options, count) {
496
- const shuffled = options.sort(() => 0.5 - Math.random());
513
+ const shuffled = [...options].sort(() => 0.5 - Math.random());
497
514
  return shuffled.slice(0, count);
498
515
  }
499
516
  function generateRandomBooleanValue() {
@@ -550,3 +550,32 @@ describe('pickRandomPropertyValues', () => {
550
550
  expect((0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], undefined, new Set(['users']))).toEqual({});
551
551
  });
552
552
  });
553
+ describe('MultiSelect generation', () => {
554
+ const caches = [new Map(), new Map()];
555
+ const options = ['na', 'active', 'big', 'classic', 'custom', 'pro'].map((value) => ({ value }));
556
+ it('picks a real subset rather than every option', () => {
557
+ const property = {
558
+ slug: 'tags',
559
+ propertyType: types_1.PropertyType.MultiSelect,
560
+ propertyLevel: types_1.PropertyLevel.ALL,
561
+ options,
562
+ };
563
+ const counts = new Set(Array.from({ length: 40 }, () => (0, create_1.pickRandomValueForProperty)(property, caches[0], caches[1]).length));
564
+ expect(Math.max(...counts)).toBeLessThanOrEqual(options.length);
565
+ expect(Math.min(...counts)).toBeGreaterThan(0);
566
+ expect(counts.size).toBeGreaterThan(1);
567
+ });
568
+ it('does not reorder the option list it was given', () => {
569
+ const property = {
570
+ slug: 'tags',
571
+ propertyType: types_1.PropertyType.MultiSelect,
572
+ propertyLevel: types_1.PropertyLevel.ALL,
573
+ options,
574
+ };
575
+ const before = options.map((option) => option.value);
576
+ for (let i = 0; i < 20; i++) {
577
+ (0, create_1.pickRandomValueForProperty)(property, caches[0], caches[1]);
578
+ }
579
+ expect(options.map((option) => option.value)).toEqual(before);
580
+ });
581
+ });
@@ -6,7 +6,6 @@ const login_1 = require("../../auth/login");
6
6
  const webhooks_1 = require("../../api/webhooks");
7
7
  const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
8
8
  const basecommand_1 = require("../../basecommand");
9
- const logger_1 = tslib_1.__importDefault(require("../../logger"));
10
9
  class DeleteWebhooks extends basecommand_1.BaseCommand {
11
10
  static description = 'Delete an existing webhook. To delete a single webhook, pass its ID. To delete multiple webhooks, do not pass a value for the ID, and select multiple using the interactive selector';
12
11
  static examples = [
@@ -43,10 +42,10 @@ class DeleteWebhooks extends basecommand_1.BaseCommand {
43
42
  }
44
43
  }
45
44
  if (this.flags.json) {
46
- logger_1.default.info(JSON.stringify(deletedWebhooks, null, 2));
45
+ this.log(JSON.stringify(deletedWebhooks, null, 2));
47
46
  }
48
47
  else {
49
- logger_1.default.info(deletedWebhooks.map((x) => x.id).join('\n'));
48
+ this.log(deletedWebhooks.map((x) => x.id).join('\n'));
50
49
  }
51
50
  }
52
51
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.6.0-alpha-8-alpha.5ffe1e1",
2
+ "version": "3.6.0-alpha-8-alpha.ec1ef67",
3
3
  "commands": {
4
4
  "app:create": {
5
5
  "id": "app:create",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "3.6.0-alpha-8-alpha.5ffe1e1",
3
+ "version": "3.6.0-alpha-8-alpha.ec1ef67",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",
@@ -57,6 +57,7 @@
57
57
  "listr": "^0.14.3",
58
58
  "lodash": "^4.17.21",
59
59
  "ncp": "^2.0.0",
60
+ "p-limit": "^3.1.0",
60
61
  "pkg-install": "^1.0.0",
61
62
  "semver": "^7.5.4",
62
63
  "unique-names-generator": "^4.7.1",