@contrail/cli 3.6.0-alpha-8-alpha.65a5f6a → 3.6.0-alpha-8-alpha.ccc04b5

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
@@ -6,7 +6,6 @@ The Contrail CLI is the best way to manage your instance data through a programm
6
6
  * [Contrail CLI](#contrail-cli)
7
7
  * [Usage](#usage)
8
8
  * [Autocomplete](#autocomplete)
9
- * [Entities](#entities)
10
9
  * [Commands](#commands)
11
10
  <!-- tocstop -->
12
11
 
@@ -18,7 +17,7 @@ $ npm install -g @contrail/cli
18
17
  $ contrail COMMAND
19
18
  running command...
20
19
  $ contrail (--version)
21
- @contrail/cli/3.6.0-alpha-8-alpha.65a5f6a linux-x64 node-v24.22.1
20
+ @contrail/cli/3.6.0-alpha-8-alpha.ccc04b5 linux-x64 node-v24.22.1
22
21
  $ contrail --help [COMMAND]
23
22
  USAGE
24
23
  $ contrail COMMAND
@@ -30,54 +29,6 @@ USAGE
30
29
 
31
30
  To get instructions on how to set up autocomplete for your shell, run `contrail autocomplete`.
32
31
 
33
- # Entities
34
-
35
- The `contrail entities` commands create, query, update, and delete platform entities. They are built to be called from scripts. Per-command flags and examples are under [Commands](#commands) below.
36
-
37
- ## stdout is JSON, everything else is stderr
38
-
39
- Every `entities` command writes JSON and nothing else to stdout. Progress logs, warnings, and prompts go to stderr, so output pipes without filtering:
40
-
41
- ```sh-session
42
- $ contrail entities get item -e=false -t 3 -p id,name | jq -r '.[].name'
43
- ```
44
-
45
- Redirect the two streams separately to keep the logs:
46
-
47
- ```sh-session
48
- $ contrail entities get item -e=false > items.json 2> run.log
49
- ```
50
-
51
- `-o/--outputFile` writes the JSON to a file and leaves stdout empty.
52
-
53
- ## Scripts need `-e=false`
54
-
55
- `--alwaysConfirmEnv` defaults to true, so the command prints the current environment and waits for you to confirm it. With no terminal attached there is nothing to answer the prompt, and the command exits 130 having written no output. Pass `-e=false` from any script, cron job, or CI step.
56
-
57
- ## Property values go after `--`
58
-
59
- Values are `slug=value` pairs. Everything before `--` is flags and ids:
60
-
61
- ```sh-session
62
- $ contrail entities create color -e=false -- name="Electric Blue" hex=0000ff
63
- $ contrail entities update color abc123 -e=false -- name=obsidian
64
- $ contrail entities get color -e=false -- createdOn=2025-09-15..2025-09-16
65
- ```
66
-
67
- Quote any value containing a space. Repeat a key to pass several values to a multi-select property (`-- colors=option colors=family`); a comma inside one value is kept as part of that value.
68
-
69
- On `update`, `slug=` unsets a property and `slug='""'` sets it to an empty string.
70
-
71
- ## Exit codes
72
-
73
- | Code | Meaning |
74
- | --- | --- |
75
- | 0 | Every row succeeded |
76
- | 1 | At least one row failed; the JSON summary names which |
77
- | 130 | The environment prompt could not be answered (see `-e=false`) |
78
-
79
- Bulk commands run every row to completion. One failure does not stop the rest, and the summary reports each row's outcome.
80
-
81
32
  # Commands
82
33
 
83
34
  <!-- commands -->
@@ -34,6 +34,7 @@ export type CreateSummary = {
34
34
  }[];
35
35
  };
36
36
  export declare function summarizeSettledCreates(inputs: any[], settled: PromiseSettledResult<any>[]): CreateSummary;
37
+ export declare function pickRandomPropertyValues(type: TypeWithProperties, objectReferencesCache: ObjectReferenceCachesByTypePath, typeReferencesCache: TypeReferencesCacheByPath, roles?: Role[], suppliedSlugs?: Set<string>): any;
37
38
  export type WithId = {
38
39
  id: string;
39
40
  [key: string]: any;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doesPropertyLevelMatchRole = exports.selectRandomObject = exports.buildObjectReferenceCache = exports.getReferencedObjectPaths = exports.castValueToPropertyType = exports.pickRandomValueForProperty = exports.summarizeSettledCreates = void 0;
3
+ exports.doesPropertyLevelMatchRole = exports.selectRandomObject = exports.buildObjectReferenceCache = exports.getReferencedObjectPaths = exports.castValueToPropertyType = exports.pickRandomValueForProperty = exports.pickRandomPropertyValues = exports.summarizeSettledCreates = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs_1 = tslib_1.__importDefault(require("fs"));
6
6
  const unique_names_generator_1 = require("unique-names-generator");
@@ -312,7 +312,7 @@ async function buildEntitiesToCreate(entityTypePath, entities, propertySpecifica
312
312
  buildLocalObjectReferencesCache(getReferencedObjectPaths(type)),
313
313
  ]);
314
314
  const populatedEntities = entities.map((entity) => ({
315
- ...createEntityWithPopulatedValues(type, typesCache, objectReferencesCache, propertySpecificationBySlug),
315
+ ...createEntityWithPopulatedValues(type, typesCache, objectReferencesCache, propertySpecificationBySlug, entity),
316
316
  ...entity,
317
317
  }));
318
318
  // Skip system value generation unless -g flag is set (generateValues mode)
@@ -345,11 +345,13 @@ async function buildEntitiesToCreate(entityTypePath, entities, propertySpecifica
345
345
  }
346
346
  return populatedEntities;
347
347
  }
348
- function createEntityWithPopulatedValues(type, typeReferencesCache, objectReferencesCache, propertySpecificationBySlug) {
349
- const rolesValue = propertySpecificationBySlug?.get('roles');
348
+ function createEntityWithPopulatedValues(type, typeReferencesCache, objectReferencesCache, propertySpecificationBySlug, inputRow) {
349
+ // the row wins over the command line, matching the spread order at the call site
350
+ const rolesValue = inputRow?.roles ?? propertySpecificationBySlug?.get('roles');
350
351
  const roles = rolesValue === undefined ? undefined : [].concat(rolesValue);
352
+ const suppliedSlugs = collectSuppliedSlugs(propertySpecificationBySlug, inputRow);
351
353
  const entity = SHOULD_GENERATE_MISSING_VALUES
352
- ? pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCache, roles)
354
+ ? pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCache, roles, suppliedSlugs)
353
355
  : {};
354
356
  // Handle property specifications
355
357
  for (const [propertySlug, specifiedValue] of propertySpecificationBySlug.entries()) {
@@ -387,13 +389,25 @@ function createEntityWithPopulatedValues(type, typeReferencesCache, objectRefere
387
389
  }
388
390
  return entity;
389
391
  }
390
- function pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCache, roles) {
392
+ function collectSuppliedSlugs(propertySpecificationBySlug, inputRow) {
393
+ const fromCommandLine = [...(propertySpecificationBySlug?.entries() ?? [])]
394
+ .filter(([, value]) => value !== undefined)
395
+ .map(([slug]) => slug);
396
+ const fromRow = Object.entries(inputRow ?? {})
397
+ .filter(([, value]) => value !== undefined)
398
+ .map(([slug]) => slug);
399
+ return new Set([...fromCommandLine, ...fromRow]);
400
+ }
401
+ function pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCache, roles, suppliedSlugs) {
391
402
  const entity = {};
392
403
  // Get values for properties
393
404
  for (const property of type.typeProperties) {
394
405
  // Validate property level
395
406
  if (roles?.length && roles.every((r) => !doesPropertyLevelMatchRole(property.propertyLevel, r)))
396
407
  continue;
408
+ // the caller pinned this value, so do not generate (or fail) on its behalf
409
+ if (suppliedSlugs?.has(getPropertySlug(property)))
410
+ continue;
397
411
  // Generate random value
398
412
  if (property.propertyType === types_1.PropertyType.ObjectReference) {
399
413
  const cache = objectReferencesCache.get(property.referencedTypePath);
@@ -408,6 +422,7 @@ function pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCac
408
422
  }
409
423
  return entity;
410
424
  }
425
+ exports.pickRandomPropertyValues = pickRandomPropertyValues;
411
426
  function pickRandomValueForProperty(property, objectReferencesCache, typeReferencesCache) {
412
427
  const getRandomObjectReference = (referencedTypePath) => {
413
428
  if (!objectReferencesCache.has(referencedTypePath)) {
@@ -516,14 +516,13 @@ describe('Entity Creation E2E Happy Path', () => {
516
516
  });
517
517
  describe('castValueToPropertyType array coercion', () => {
518
518
  it('should coerce a single value on a multi-value property to a one-element array', () => {
519
- expect((0, create_1.castValueToPropertyType)('option', types_1.PropertyType.MultiSelect, 'colors')).toEqual(['option']);
520
- });
521
- it('should pass arrays through on multi-value properties', () => {
522
- expect((0, create_1.castValueToPropertyType)(['option', 'family'], types_1.PropertyType.MultiSelect, 'colors')).toEqual([
519
+ expect((0, create_1.castValueToPropertyType)('option', types_1.PropertyType.MultiSelect, 'colors')).toEqual([
523
520
  'option',
524
- 'family',
525
521
  ]);
526
522
  });
523
+ it('should pass arrays through on multi-value properties', () => {
524
+ expect((0, create_1.castValueToPropertyType)(['option', 'family'], types_1.PropertyType.MultiSelect, 'colors')).toEqual(['option', 'family']);
525
+ });
527
526
  it('should keep a comma value literal on a multi-value property and warn with the repeated-key form', () => {
528
527
  const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
529
528
  expect((0, create_1.castValueToPropertyType)('option,family', types_1.PropertyType.MultiSelect, 'colors')).toEqual([
@@ -534,7 +533,10 @@ describe('castValueToPropertyType array coercion', () => {
534
533
  });
535
534
  it('should cast each element of a repeated-key array on scalar property types', () => {
536
535
  expect((0, create_1.castValueToPropertyType)(['1', '2'], types_1.PropertyType.Number, 'rank')).toEqual([1, 2]);
537
- expect((0, create_1.castValueToPropertyType)(['true', 'false'], types_1.PropertyType.Boolean, 'isActive')).toEqual([true, false]);
536
+ expect((0, create_1.castValueToPropertyType)(['true', 'false'], types_1.PropertyType.Boolean, 'isActive')).toEqual([
537
+ true,
538
+ false,
539
+ ]);
538
540
  });
539
541
  it('should keep commas literal on string properties without warning', () => {
540
542
  const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
@@ -543,3 +545,39 @@ describe('castValueToPropertyType array coercion', () => {
543
545
  consoleError.mockRestore();
544
546
  });
545
547
  });
548
+ describe('pickRandomPropertyValues', () => {
549
+ const caches = [new Map(), new Map()];
550
+ const typeWith = (properties) => ({ typePath: 't', typeProperties: properties });
551
+ const familyOnly = {
552
+ slug: 'familyText',
553
+ propertyType: types_1.PropertyType.String,
554
+ propertyLevel: types_1.PropertyLevel.FAMILY,
555
+ };
556
+ const optionOnly = {
557
+ slug: 'optionText',
558
+ propertyType: types_1.PropertyType.String,
559
+ propertyLevel: types_1.PropertyLevel.OPTION,
560
+ };
561
+ const unsupported = {
562
+ slug: 'users',
563
+ propertyType: types_1.PropertyType.UserList,
564
+ propertyLevel: types_1.PropertyLevel.ALL,
565
+ };
566
+ it('generates only the properties matching the given roles', () => {
567
+ const type = typeWith([familyOnly, optionOnly]);
568
+ const family = (0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], ['family']);
569
+ const option = (0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], ['option']);
570
+ expect(Object.keys(family)).toEqual(['familyText']);
571
+ expect(Object.keys(option)).toEqual(['optionText']);
572
+ });
573
+ it('skips properties the caller already supplied', () => {
574
+ const type = typeWith([familyOnly, optionOnly]);
575
+ const result = (0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], undefined, new Set(['familyText']));
576
+ expect(Object.keys(result)).toEqual(['optionText']);
577
+ });
578
+ it('does not fail on an unsupported property type when its value was supplied', () => {
579
+ const type = typeWith([unsupported]);
580
+ expect(() => (0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1])).toThrow('Cannot handle property type: userList');
581
+ expect((0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], undefined, new Set(['users']))).toEqual({});
582
+ });
583
+ });
@@ -86,10 +86,9 @@ class UpdateEntity extends basecommand_1.BaseCommand {
86
86
  const skipped = entitiesToUpdate.filter(({ id }) => !id).length;
87
87
  const entitiesWithId = entitiesToUpdate.filter(({ id }) => id);
88
88
  // will be applied to all entities
89
- const fixedValues = [...propertySpec.entries()].reduce((acc, [key, value]) => {
90
- acc[key] = value;
91
- return acc;
92
- }, {});
89
+ // slug= parses to undefined, and JSON.stringify drops undefined keys, so an unset
90
+ // has to travel as an explicit null for the server to clear the property
91
+ const fixedValues = Object.fromEntries([...propertySpec.entries()].map(([slug, value]) => [slug, value ?? null]));
93
92
  async function updateEntity(entity) {
94
93
  const newEntityState = { ...entity, ...fixedValues };
95
94
  const id = entity.id;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.6.0-alpha-8-alpha.65a5f6a",
2
+ "version": "3.6.0-alpha-8-alpha.ccc04b5",
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.65a5f6a",
3
+ "version": "3.6.0-alpha-8-alpha.ccc04b5",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",