@contrail/cli 3.6.0-alpha-8-alpha.45c63ad → 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
|
@@ -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.
|
|
20
|
+
@contrail/cli/3.6.0-alpha-8-alpha.ccc04b5 linux-x64 node-v24.22.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -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
|
-
|
|
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
|
|
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([
|
|
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([
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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;
|
package/oclif.manifest.json
CHANGED