@contrail/cli 3.6.0-alpha-8-alpha.45c63ad → 3.6.0-alpha-8-alpha.418c5f6

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.45c63ad linux-x64 node-v24.22.1
20
+ @contrail/cli/3.6.0-alpha-8-alpha.418c5f6 linux-x64 node-v24.22.1
21
21
  $ contrail --help [COMMAND]
22
22
  USAGE
23
23
  $ contrail COMMAND
@@ -51,9 +51,9 @@ To get instructions on how to set up autocomplete for your shell, run `contrail
51
51
  * [`contrail config list`](#contrail-config-list)
52
52
  * [`contrail config set`](#contrail-config-set)
53
53
  * [`contrail config use [NAME]`](#contrail-config-use-name)
54
- * [`contrail entities create ENTITYNAME`](#contrail-entities-create-entityname)
54
+ * [`contrail entities create TYPEPATH`](#contrail-entities-create-typepath)
55
55
  * [`contrail entities delete ENTITYNAME [IDS]`](#contrail-entities-delete-entityname-ids)
56
- * [`contrail entities get ENTITYNAME [IDS]`](#contrail-entities-get-entityname-ids)
56
+ * [`contrail entities get TYPEPATH [IDS]`](#contrail-entities-get-typepath-ids)
57
57
  * [`contrail entities update ENTITYNAME [IDS]`](#contrail-entities-update-entityname-ids)
58
58
  * [`contrail feature-flags export`](#contrail-feature-flags-export)
59
59
  * [`contrail feature-flags import`](#contrail-feature-flags-import)
@@ -543,17 +543,17 @@ EXAMPLES
543
543
  $ contrail config use demo-org
544
544
  ```
545
545
 
546
- ## `contrail entities create ENTITYNAME`
546
+ ## `contrail entities create TYPEPATH`
547
547
 
548
548
  Create entities
549
549
 
550
550
  ```
551
551
  USAGE
552
- $ contrail entities create ENTITYNAME [-l error|warn|info|debug] [-e true|false] [-n <value>] [-d] [-i <value>] [-o
552
+ $ contrail entities create TYPEPATH [-l error|warn|info|debug] [-e true|false] [-n <value>] [-d] [-i <value>] [-o
553
553
  <value>] [-g] [-r] [-S] [--suffix <value>] [--apiVersion 1|2]
554
554
 
555
555
  ARGUMENTS
556
- ENTITYNAME The name of the entity type to create
556
+ TYPEPATH The type path of the entity to create (e.g. color, custom-entity:franchise)
557
557
 
558
558
  FLAGS
559
559
  -S, --skipHydrateRelationships If true, does not hydrate relationships for the created entities
@@ -608,7 +608,7 @@ USAGE
608
608
  <value>] [--apiVersion 1|2]
609
609
 
610
610
  ARGUMENTS
611
- ENTITYNAME The name of the entity type to delete
611
+ ENTITYNAME The name of the entity type to delete (type paths are not supported)
612
612
  IDS One or more entity ids to delete
613
613
 
614
614
  FLAGS
@@ -635,18 +635,18 @@ EXAMPLES
635
635
  $ contrail entities delete item -i ids.json
636
636
  ```
637
637
 
638
- ## `contrail entities get ENTITYNAME [IDS]`
638
+ ## `contrail entities get TYPEPATH [IDS]`
639
639
 
640
640
  Get an entity
641
641
 
642
642
  ```
643
643
  USAGE
644
- $ contrail entities get ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-o <value>] [-p <value>]
645
- [-P] [-s <value>] [-S] [-t <value>] [-r <value>] [--suffix <value>] [--apiVersion 1|2]
644
+ $ contrail entities get TYPEPATH [IDS] [-l error|warn|info|debug] [-e true|false] [-o <value>] [-p <value>] [-P]
645
+ [-s <value>] [-S] [-t <value>] [-r <value>] [--suffix <value>] [--apiVersion 1|2]
646
646
 
647
647
  ARGUMENTS
648
- ENTITYNAME The name of the entity type to fetch
649
- IDS One or more entity ids; shorthand for the id/ids criteria
648
+ TYPEPATH The type path of the entities to fetch (e.g. color, custom-entity:franchise)
649
+ IDS One or more entity ids; shorthand for the id/ids criteria
650
650
 
651
651
  FLAGS
652
652
  -P, --paginated If true, fetches all entities in a paginated manner
@@ -692,7 +692,7 @@ USAGE
692
692
  [--suffix <value>] [--apiVersion 1|2]
693
693
 
694
694
  ARGUMENTS
695
- ENTITYNAME The name of the entity type to update
695
+ ENTITYNAME The name of the entity type to update (type paths are not supported)
696
696
  IDS One or more entity ids to update
697
697
 
698
698
  FLAGS
@@ -20,7 +20,7 @@ export default class CreateEntity extends BaseCommand {
20
20
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
21
21
  };
22
22
  static args: {
23
- entityName: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
23
+ typePath: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
24
24
  };
25
25
  static strict: boolean;
26
26
  init(): Promise<void>;
@@ -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");
@@ -28,6 +28,14 @@ const SLUGS_THAT_MUST_BE_SPECIFIED_BY_TYPE_PATH = {
28
28
  'assortment-item': ['assortmentId'],
29
29
  'user-org': ['role'],
30
30
  };
31
+ // Candidate items are excluded against a single parent, so one command generates for one
32
+ // parent. Mixed input would hand later rows candidates never checked against their own parent.
33
+ function throwIfParentsAreMixed(entities, parentSlug, parentLabel) {
34
+ const parentIds = new Set(entities.map((entity) => entity[parentSlug]));
35
+ if (parentIds.size > 1) {
36
+ throw new Error(`Generated item ids are drawn from one ${parentLabel}'s candidates, but the input spans ${parentIds.size} ${parentLabel}s. Run one ${parentLabel} per command, or supply itemId for each row.`);
37
+ }
38
+ }
31
39
  const FIND_VALID_VALUE_MAP = {
32
40
  assortment: [
33
41
  {
@@ -44,7 +52,10 @@ const FIND_VALID_VALUE_MAP = {
44
52
  'assortment-item': [
45
53
  {
46
54
  slug: 'itemId',
47
- findValidValuesFn: async (assortmentItems, count) => new Set((await (0, entities_1.findItemsNotInAssortment)(assortmentItems[0].assortmentId, count)).map(({ id }) => id)),
55
+ findValidValuesFn: async (assortmentItems, count) => {
56
+ throwIfParentsAreMixed(assortmentItems, 'assortmentId', 'assortment');
57
+ return new Set((await (0, entities_1.findItemsNotInAssortment)(assortmentItems[0].assortmentId, count)).map(({ id }) => id));
58
+ },
48
59
  applyValueToEntityFn: (entity, validValues) => {
49
60
  if (entity.itemId)
50
61
  return; // skip if already specified
@@ -56,7 +67,10 @@ const FIND_VALID_VALUE_MAP = {
56
67
  'project-item': [
57
68
  {
58
69
  slug: 'itemId',
59
- findValidValuesFn: async (projectItems) => new Set((await (0, entities_1.findItemsNotInProject)(projectItems[0].projectId)).map(({ id }) => id)),
70
+ findValidValuesFn: async (projectItems) => {
71
+ throwIfParentsAreMixed(projectItems, 'projectId', 'project');
72
+ return new Set((await (0, entities_1.findItemsNotInProject)(projectItems[0].projectId)).map(({ id }) => id));
73
+ },
60
74
  applyValueToEntityFn: (entity, validValues) => {
61
75
  if (entity.itemId)
62
76
  return; // skip if already specified
@@ -193,8 +207,8 @@ class CreateEntity extends basecommand_1.BaseCommand {
193
207
  }),
194
208
  };
195
209
  static args = {
196
- entityName: core_1.Args.string({
197
- description: 'The name of the entity type to create',
210
+ typePath: core_1.Args.string({
211
+ description: 'The type path of the entity to create (e.g. color, custom-entity:franchise)',
198
212
  required: true,
199
213
  multiple: false,
200
214
  }),
@@ -208,7 +222,7 @@ class CreateEntity extends basecommand_1.BaseCommand {
208
222
  await (0, login_1.authUser)();
209
223
  const { flags, argv, args } = await this.parse(CreateEntity);
210
224
  const { count, dryRun: isDryRun, inputFile: inputFilename, outputFile: outputFilename, generateValues: shouldGenerateMissingValues, readableIds: shouldUseReadableIds, skipHydrateRelationships, suffix, apiVersion, } = flags;
211
- const { entityName: entityTypePath } = args;
225
+ const { typePath: entityTypePath } = args;
212
226
  // Global flags is a little hacky, but it was easier
213
227
  // and it doesn't see *that* bad because they are only valid
214
228
  // for the lifecycle of the command.
@@ -312,7 +326,7 @@ async function buildEntitiesToCreate(entityTypePath, entities, propertySpecifica
312
326
  buildLocalObjectReferencesCache(getReferencedObjectPaths(type)),
313
327
  ]);
314
328
  const populatedEntities = entities.map((entity) => ({
315
- ...createEntityWithPopulatedValues(type, typesCache, objectReferencesCache, propertySpecificationBySlug),
329
+ ...createEntityWithPopulatedValues(type, typesCache, objectReferencesCache, propertySpecificationBySlug, entity),
316
330
  ...entity,
317
331
  }));
318
332
  // Skip system value generation unless -g flag is set (generateValues mode)
@@ -345,11 +359,13 @@ async function buildEntitiesToCreate(entityTypePath, entities, propertySpecifica
345
359
  }
346
360
  return populatedEntities;
347
361
  }
348
- function createEntityWithPopulatedValues(type, typeReferencesCache, objectReferencesCache, propertySpecificationBySlug) {
349
- const rolesValue = propertySpecificationBySlug?.get('roles');
362
+ function createEntityWithPopulatedValues(type, typeReferencesCache, objectReferencesCache, propertySpecificationBySlug, inputRow) {
363
+ // the row wins over the command line, matching the spread order at the call site
364
+ const rolesValue = inputRow?.roles ?? propertySpecificationBySlug?.get('roles');
350
365
  const roles = rolesValue === undefined ? undefined : [].concat(rolesValue);
366
+ const suppliedSlugs = collectSuppliedSlugs(propertySpecificationBySlug, inputRow);
351
367
  const entity = SHOULD_GENERATE_MISSING_VALUES
352
- ? pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCache, roles)
368
+ ? pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCache, roles, suppliedSlugs)
353
369
  : {};
354
370
  // Handle property specifications
355
371
  for (const [propertySlug, specifiedValue] of propertySpecificationBySlug.entries()) {
@@ -387,13 +403,25 @@ function createEntityWithPopulatedValues(type, typeReferencesCache, objectRefere
387
403
  }
388
404
  return entity;
389
405
  }
390
- function pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCache, roles) {
406
+ function collectSuppliedSlugs(propertySpecificationBySlug, inputRow) {
407
+ const fromCommandLine = [...(propertySpecificationBySlug?.entries() ?? [])]
408
+ .filter(([, value]) => value !== undefined)
409
+ .map(([slug]) => slug);
410
+ const fromRow = Object.entries(inputRow ?? {})
411
+ .filter(([, value]) => value !== undefined)
412
+ .map(([slug]) => slug);
413
+ return new Set([...fromCommandLine, ...fromRow]);
414
+ }
415
+ function pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCache, roles, suppliedSlugs) {
391
416
  const entity = {};
392
417
  // Get values for properties
393
418
  for (const property of type.typeProperties) {
394
419
  // Validate property level
395
420
  if (roles?.length && roles.every((r) => !doesPropertyLevelMatchRole(property.propertyLevel, r)))
396
421
  continue;
422
+ // the caller pinned this value, so do not generate (or fail) on its behalf
423
+ if (suppliedSlugs?.has(getPropertySlug(property)))
424
+ continue;
397
425
  // Generate random value
398
426
  if (property.propertyType === types_1.PropertyType.ObjectReference) {
399
427
  const cache = objectReferencesCache.get(property.referencedTypePath);
@@ -408,6 +436,7 @@ function pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCac
408
436
  }
409
437
  return entity;
410
438
  }
439
+ exports.pickRandomPropertyValues = pickRandomPropertyValues;
411
440
  function pickRandomValueForProperty(property, objectReferencesCache, typeReferencesCache) {
412
441
  const getRandomObjectReference = (referencedTypePath) => {
413
442
  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
+ });
@@ -42,7 +42,7 @@ class DeleteEntity extends basecommand_1.BaseCommand {
42
42
  };
43
43
  static args = {
44
44
  entityName: core_1.Args.string({
45
- description: 'The name of the entity type to delete',
45
+ description: 'The name of the entity type to delete (type paths are not supported)',
46
46
  required: true,
47
47
  }),
48
48
  ids: core_1.Args.string({
@@ -64,6 +64,9 @@ class DeleteEntity extends basecommand_1.BaseCommand {
64
64
  IS_DRY_RUN = true;
65
65
  console.error('Running in dry run mode. No entities will be deleted.');
66
66
  }
67
+ if (entityName.includes(':')) {
68
+ this.error(`delete takes an entity name, not a type path. Use: contrail entities delete ${entityName.split(':')[0]} <ID...>`);
69
+ }
67
70
  const tokens = argv.slice(1);
68
71
  const valueTokens = tokens.filter((token) => token.includes('='));
69
72
  if (valueTokens.length > 0) {
@@ -16,7 +16,7 @@ export default class GetEntity extends BaseCommand {
16
16
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
17
17
  };
18
18
  static args: {
19
- entityName: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
19
+ typePath: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
20
20
  ids: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
21
21
  };
22
22
  static strict: boolean;
@@ -8,6 +8,7 @@ const sdk_1 = require("@contrail/sdk");
8
8
  const login_1 = require("../../auth/login");
9
9
  const common_1 = require("../../common");
10
10
  const types_1 = require("../../api/types");
11
+ const dateRanges_1 = require("../../helpers/propertySpecifications/dateRanges");
11
12
  const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
12
13
  const batchFetch_1 = require("../../helpers/entities/batchFetch");
13
14
  let SHOULD_USE_PAGINATED_FIND = false;
@@ -73,8 +74,8 @@ class GetEntity extends basecommand_1.BaseCommand {
73
74
  }),
74
75
  };
75
76
  static args = {
76
- entityName: core_1.Args.string({
77
- description: 'The name of the entity type to fetch',
77
+ typePath: core_1.Args.string({
78
+ description: 'The type path of the entities to fetch (e.g. color, custom-entity:franchise)',
78
79
  required: true,
79
80
  }),
80
81
  ids: core_1.Args.string({
@@ -90,7 +91,7 @@ class GetEntity extends basecommand_1.BaseCommand {
90
91
  async run() {
91
92
  await (0, login_1.authUser)();
92
93
  const { args, flags, argv } = await this.parse(GetEntity);
93
- const { entityName: typePath } = args;
94
+ const { typePath } = args;
94
95
  const { outputFile, paginated: shouldUsePaginatedFind, propertySlugs, relations: relationString, skip, skipHydrateRelationships, suffix, apiVersion, take, } = flags;
95
96
  SHOULD_USE_PAGINATED_FIND = shouldUsePaginatedFind;
96
97
  MAX_NUMBER_OF_ENTITIES_TO_FETCH = take;
@@ -206,7 +207,11 @@ async function getEntityByTypePath(typePath, propertySpec, options = {}) {
206
207
  function convertPropertySpecIntoCriteria(propertySpec) {
207
208
  const criteria = {};
208
209
  propertySpec.forEach((value, slug) => {
209
- criteria[slug] = value;
210
+ // date ranges are a query concept, so they resolve here rather than in the shared
211
+ // parser that create and update also use
212
+ criteria[slug] = (0, dateRanges_1.isDateRangeValue)(value)
213
+ ? (0, dateRanges_1.convertDateRangeToJSURL)((0, dateRanges_1.parseDateRange)(value))
214
+ : value;
210
215
  });
211
216
  return criteria;
212
217
  }
@@ -241,9 +246,13 @@ async function* streamPaginatedFind(typePath, options = {}) {
241
246
  let nextPageKey = undefined;
242
247
  let count = 0;
243
248
  const { root: entityName } = (0, types_1.parseTypePath)(typePath);
249
+ // a custom entity collection holds every subtype, so the paginated read needs the
250
+ // same type-path filter the single-shot read applies
251
+ const criteria = entityName === 'custom-entity' ? { ...options.criteria, typePath } : options.criteria;
244
252
  while (true) {
245
253
  const opts = {
246
254
  ...options,
255
+ criteria,
247
256
  entityName,
248
257
  // paginated reads require the V2 response shape unless overridden
249
258
  apiVersion: options.apiVersion ?? sdk_1.API_VERSION.V2,
@@ -48,7 +48,7 @@ class UpdateEntity extends basecommand_1.BaseCommand {
48
48
  };
49
49
  static args = {
50
50
  entityName: core_1.Args.string({
51
- description: 'The name of the entity type to update',
51
+ description: 'The name of the entity type to update (type paths are not supported)',
52
52
  required: true,
53
53
  }),
54
54
  ids: core_1.Args.string({
@@ -66,6 +66,9 @@ class UpdateEntity extends basecommand_1.BaseCommand {
66
66
  const { args, argv } = await this.parse(UpdateEntity);
67
67
  const { entityName } = args;
68
68
  const { dryRun: isDryRun, inputFile: inputFilename, skipHydrateRelationships, suffix, apiVersion, } = this.flags;
69
+ if (entityName.includes(':')) {
70
+ this.error(`update takes an entity name, not a type path. Use: contrail entities update ${entityName.split(':')[0]} <ID...>`);
71
+ }
69
72
  const { ids: positionalIds, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(argv.slice(1));
70
73
  const propertySpec = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
71
74
  if (propertySpec.has('id') || propertySpec.has('ids')) {
@@ -86,10 +89,9 @@ class UpdateEntity extends basecommand_1.BaseCommand {
86
89
  const skipped = entitiesToUpdate.filter(({ id }) => !id).length;
87
90
  const entitiesWithId = entitiesToUpdate.filter(({ id }) => id);
88
91
  // will be applied to all entities
89
- const fixedValues = [...propertySpec.entries()].reduce((acc, [key, value]) => {
90
- acc[key] = value;
91
- return acc;
92
- }, {});
92
+ // slug= parses to undefined, and JSON.stringify drops undefined keys, so an unset
93
+ // has to travel as an explicit null for the server to clear the property
94
+ const fixedValues = Object.fromEntries([...propertySpec.entries()].map(([slug, value]) => [slug, value ?? null]));
93
95
  async function updateEntity(entity) {
94
96
  const newEntityState = { ...entity, ...fixedValues };
95
97
  const id = entity.id;
@@ -32,6 +32,9 @@ async function getManyItems(maxCount = 10000) {
32
32
  break; // No more assortments to fetch
33
33
  }
34
34
  items.push(...response.results);
35
+ if (!nextPageKey) {
36
+ break; // last page; without this the next request refetches page one
37
+ }
35
38
  if (items.length >= maxCount) {
36
39
  console.warn(`Reached maximum item limit of ${maxCount}. Some items may not be included.`);
37
40
  break; // Stop if we reach the maximum limit
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const items_1 = require("./items");
4
+ const mockGet = jest.fn();
5
+ jest.mock('@contrail/sdk', () => ({
6
+ Entities: jest.fn().mockImplementation(() => ({ get: (...args) => mockGet(...args) })),
7
+ API_VERSION: { V2: '2' },
8
+ }));
9
+ describe('getManyItems', () => {
10
+ beforeEach(() => jest.clearAllMocks());
11
+ it('stops on the last page rather than refetching the first', async () => {
12
+ // the final page carries results but no cursor, which previously restarted pagination
13
+ mockGet.mockImplementation(async ({ nextPageKey }) => nextPageKey === 'page-2'
14
+ ? { results: [{ id: 'b' }], nextPageKey: undefined }
15
+ : { results: [{ id: 'a' }], nextPageKey: 'page-2' });
16
+ const items = await (0, items_1.getManyItems)(10);
17
+ expect(mockGet).toHaveBeenCalledTimes(2);
18
+ expect(items.map((item) => item.id)).toEqual(['a', 'b']);
19
+ });
20
+ });
@@ -11,19 +11,15 @@ export type DateRange = {
11
11
  start?: Date;
12
12
  end?: Date;
13
13
  };
14
- export type DateRangeSpecification = {
15
- slug: string;
16
- range: DateRange;
17
- };
18
14
  /**
19
- * Checks if a property specification contains date range syntax (..)
15
+ * Checks if a criteria value uses date range syntax (..)
20
16
  */
21
- export declare function isDateRangeSpecification(spec: string): boolean;
17
+ export declare function isDateRangeValue(value: unknown): value is string;
22
18
  /**
23
- * Parses a date range specification into its components
24
- * @param spec - The specification string (e.g., "createdOn=2025-09-15..2025-09-16")
19
+ * Parses a date range value into its bounds
20
+ * @param rangeValue - The value (e.g., "2025-09-15..2025-09-16")
25
21
  */
26
- export declare function parseDateRangeSpecification(spec: string): DateRangeSpecification;
22
+ export declare function parseDateRange(rangeValue: string): DateRange;
27
23
  /**
28
24
  * Parses a date string, handling both date-only and full timestamp formats
29
25
  * @param dateStr - Date string (e.g., "2025-09-15" or "2025-09-15T04:00:00Z")
@@ -9,27 +9,21 @@
9
9
  * - createdOn=..2025-09-16 (until date)
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.convertDateRangeToJSURL = exports.parseDate = exports.parseDateRangeSpecification = exports.isDateRangeSpecification = void 0;
12
+ exports.convertDateRangeToJSURL = exports.parseDate = exports.parseDateRange = exports.isDateRangeValue = void 0;
13
13
  /**
14
- * Checks if a property specification contains date range syntax (..)
14
+ * Checks if a criteria value uses date range syntax (..)
15
15
  */
16
- function isDateRangeSpecification(spec) {
17
- return spec.includes('=') && spec.includes('..');
16
+ function isDateRangeValue(value) {
17
+ return typeof value === 'string' && value.includes('..');
18
18
  }
19
- exports.isDateRangeSpecification = isDateRangeSpecification;
19
+ exports.isDateRangeValue = isDateRangeValue;
20
20
  /**
21
- * Parses a date range specification into its components
22
- * @param spec - The specification string (e.g., "createdOn=2025-09-15..2025-09-16")
21
+ * Parses a date range value into its bounds
22
+ * @param rangeValue - The value (e.g., "2025-09-15..2025-09-16")
23
23
  */
24
- function parseDateRangeSpecification(spec) {
25
- const equalsIndex = spec.indexOf('=');
26
- if (equalsIndex === -1) {
27
- throw new Error(`Invalid date range specification: ${spec}`);
28
- }
29
- const slug = spec.substring(0, equalsIndex);
30
- const rangeValue = spec.substring(equalsIndex + 1);
31
- if (!slug || !rangeValue || !rangeValue.includes('..')) {
32
- throw new Error(`Invalid date range specification: ${spec}`);
24
+ function parseDateRange(rangeValue) {
25
+ if (!rangeValue.includes('..')) {
26
+ throw new Error(`Invalid date range: ${rangeValue}`);
33
27
  }
34
28
  const [startStr, endStr] = rangeValue.split('..');
35
29
  const range = {
@@ -38,11 +32,11 @@ function parseDateRangeSpecification(spec) {
38
32
  };
39
33
  // At least one bound must be specified
40
34
  if (!range.start && !range.end) {
41
- throw new Error(`Date range must have at least one bound: ${spec}`);
35
+ throw new Error(`Date range must have at least one bound: ${rangeValue}`);
42
36
  }
43
- return { slug, range };
37
+ return range;
44
38
  }
45
- exports.parseDateRangeSpecification = parseDateRangeSpecification;
39
+ exports.parseDateRange = parseDateRange;
46
40
  /**
47
41
  * Parses a date string, handling both date-only and full timestamp formats
48
42
  * @param dateStr - Date string (e.g., "2025-09-15" or "2025-09-15T04:00:00Z")
@@ -2,18 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const dateRanges_1 = require("./dateRanges");
4
4
  describe('Date Range Specifications', () => {
5
- describe('isDateRangeSpecification', () => {
6
- it('should identify valid date range specifications', () => {
7
- expect((0, dateRanges_1.isDateRangeSpecification)('createdOn=2025-09-15..2025-09-16')).toBe(true);
8
- expect((0, dateRanges_1.isDateRangeSpecification)('updatedAt=2025-09-15T04:00:00Z..2025-09-16T03:59:59Z')).toBe(true);
9
- expect((0, dateRanges_1.isDateRangeSpecification)('date=2025-09-15..')).toBe(true);
10
- expect((0, dateRanges_1.isDateRangeSpecification)('date=..2025-09-16')).toBe(true);
5
+ describe('isDateRangeValue', () => {
6
+ it('should identify valid date range values', () => {
7
+ expect((0, dateRanges_1.isDateRangeValue)('2025-09-15..2025-09-16')).toBe(true);
8
+ expect((0, dateRanges_1.isDateRangeValue)('2025-09-15T04:00:00Z..2025-09-16T03:59:59Z')).toBe(true);
9
+ expect((0, dateRanges_1.isDateRangeValue)('2025-09-15..')).toBe(true);
10
+ expect((0, dateRanges_1.isDateRangeValue)('..2025-09-16')).toBe(true);
11
11
  });
12
- it('should reject non-date-range specifications', () => {
13
- expect((0, dateRanges_1.isDateRangeSpecification)('id=123')).toBe(false);
14
- expect((0, dateRanges_1.isDateRangeSpecification)('name=test')).toBe(false);
15
- expect((0, dateRanges_1.isDateRangeSpecification)('invalid')).toBe(false);
16
- expect((0, dateRanges_1.isDateRangeSpecification)('field=value')).toBe(false);
12
+ it('should reject values without range syntax', () => {
13
+ expect((0, dateRanges_1.isDateRangeValue)('123')).toBe(false);
14
+ expect((0, dateRanges_1.isDateRangeValue)('test')).toBe(false);
15
+ expect((0, dateRanges_1.isDateRangeValue)(42)).toBe(false);
16
+ expect((0, dateRanges_1.isDateRangeValue)(undefined)).toBe(false);
17
17
  });
18
18
  });
19
19
  describe('parseDate', () => {
@@ -34,35 +34,31 @@ describe('Date Range Specifications', () => {
34
34
  expect(() => (0, dateRanges_1.parseDate)('2025-13-50')).toThrow('Invalid date format');
35
35
  });
36
36
  });
37
- describe('parseDateRangeSpecification', () => {
37
+ describe('parseDateRange', () => {
38
38
  it('should parse full date ranges', () => {
39
- const result = (0, dateRanges_1.parseDateRangeSpecification)('createdOn=2025-09-15..2025-09-16');
40
- expect(result.slug).toBe('createdOn');
41
- expect(result.range.start).toEqual(new Date('2025-09-15T00:00:00.000Z'));
42
- expect(result.range.end).toEqual(new Date('2025-09-16T23:59:59.999Z'));
39
+ const result = (0, dateRanges_1.parseDateRange)('2025-09-15..2025-09-16');
40
+ expect(result.start).toEqual(new Date('2025-09-15T00:00:00.000Z'));
41
+ expect(result.end).toEqual(new Date('2025-09-16T23:59:59.999Z'));
43
42
  });
44
43
  it('should parse open-ended start ranges', () => {
45
- const result = (0, dateRanges_1.parseDateRangeSpecification)('createdOn=2025-09-15..');
46
- expect(result.slug).toBe('createdOn');
47
- expect(result.range.start).toEqual(new Date('2025-09-15T00:00:00.000Z'));
48
- expect(result.range.end).toBeUndefined();
44
+ const result = (0, dateRanges_1.parseDateRange)('2025-09-15..');
45
+ expect(result.start).toEqual(new Date('2025-09-15T00:00:00.000Z'));
46
+ expect(result.end).toBeUndefined();
49
47
  });
50
48
  it('should parse open-ended end ranges', () => {
51
- const result = (0, dateRanges_1.parseDateRangeSpecification)('createdOn=..2025-09-16');
52
- expect(result.slug).toBe('createdOn');
53
- expect(result.range.start).toBeUndefined();
54
- expect(result.range.end).toEqual(new Date('2025-09-16T23:59:59.999Z'));
49
+ const result = (0, dateRanges_1.parseDateRange)('..2025-09-16');
50
+ expect(result.start).toBeUndefined();
51
+ expect(result.end).toEqual(new Date('2025-09-16T23:59:59.999Z'));
55
52
  });
56
53
  it('should parse timestamp ranges', () => {
57
- const result = (0, dateRanges_1.parseDateRangeSpecification)('createdOn=2025-09-15T04:00:00Z..2025-09-16T03:59:59Z');
58
- expect(result.slug).toBe('createdOn');
59
- expect(result.range.start).toEqual(new Date('2025-09-15T04:00:00.000Z'));
60
- expect(result.range.end).toEqual(new Date('2025-09-16T03:59:59.000Z'));
54
+ const result = (0, dateRanges_1.parseDateRange)('2025-09-15T04:00:00Z..2025-09-16T03:59:59Z');
55
+ expect(result.start).toEqual(new Date('2025-09-15T04:00:00.000Z'));
56
+ expect(result.end).toEqual(new Date('2025-09-16T03:59:59.000Z'));
61
57
  });
62
- it('should throw for invalid specifications', () => {
63
- expect(() => (0, dateRanges_1.parseDateRangeSpecification)('invalid')).toThrow('Invalid date range specification');
64
- expect(() => (0, dateRanges_1.parseDateRangeSpecification)('field=..')).toThrow('Date range must have at least one bound');
65
- expect(() => (0, dateRanges_1.parseDateRangeSpecification)('field=invalid..date')).toThrow('Invalid date format');
58
+ it('should throw for invalid ranges', () => {
59
+ expect(() => (0, dateRanges_1.parseDateRange)('invalid')).toThrow('Invalid date range');
60
+ expect(() => (0, dateRanges_1.parseDateRange)('..')).toThrow('Date range must have at least one bound');
61
+ expect(() => (0, dateRanges_1.parseDateRange)('invalid..date')).toThrow('Invalid date format');
66
62
  });
67
63
  });
68
64
  describe('convertDateRangeToJSURL', () => {
@@ -19,7 +19,7 @@
19
19
  * contrail entities get color -- id=123
20
20
  * contrail entities update color 123 -- name=obsidian hex=000000
21
21
  * contrail entities update color 123 -- description= notes='""'
22
- * contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16
22
+ * contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16 (ranges resolve in get)
23
23
  */
24
24
  export type PropertySpecification = {
25
25
  slug: string;
@@ -20,11 +20,10 @@
20
20
  * contrail entities get color -- id=123
21
21
  * contrail entities update color 123 -- name=obsidian hex=000000
22
22
  * contrail entities update color 123 -- description= notes='""'
23
- * contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16
23
+ * contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16 (ranges resolve in get)
24
24
  */
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.isValidPropertySpecification = exports.partitionIdsAndSpecs = exports.parsePropertySpecificationsIntoMap = exports.parsePropertySpecification = void 0;
27
- const dateRanges_1 = require("./dateRanges");
28
27
  // Special tokens for empty strings
29
28
  const DOUBLE_QUOTED_EMPTY = '""';
30
29
  const SINGLE_QUOTED_EMPTY = "''"; // eslint-disable-line quotes
@@ -57,12 +56,6 @@ exports.parsePropertySpecification = parsePropertySpecification;
57
56
  function parsePropertySpecificationsIntoMap(propertySpecifications) {
58
57
  const propertySpecBySlug = new Map();
59
58
  for (const spec of propertySpecifications) {
60
- if ((0, dateRanges_1.isDateRangeSpecification)(spec)) {
61
- const { slug, range } = (0, dateRanges_1.parseDateRangeSpecification)(spec);
62
- const jsUrlValue = (0, dateRanges_1.convertDateRangeToJSURL)(range);
63
- propertySpecBySlug.set(slug, jsUrlValue);
64
- continue;
65
- }
66
59
  const { slug, value } = parsePropertySpecification(spec);
67
60
  if (slug === 'ids' && value !== undefined) {
68
61
  // ids is the one comma-split exception: it is a list of ids by definition
@@ -95,10 +88,6 @@ function partitionIdsAndSpecs(tokens) {
95
88
  exports.partitionIdsAndSpecs = partitionIdsAndSpecs;
96
89
  function isValidPropertySpecification(maybeSpec) {
97
90
  try {
98
- if ((0, dateRanges_1.isDateRangeSpecification)(maybeSpec)) {
99
- (0, dateRanges_1.parseDateRangeSpecification)(maybeSpec);
100
- return true;
101
- }
102
91
  const { slug } = parsePropertySpecification(maybeSpec);
103
92
  return !!slug;
104
93
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.6.0-alpha-8-alpha.45c63ad",
2
+ "version": "3.6.0-alpha-8-alpha.418c5f6",
3
3
  "commands": {
4
4
  "app:create": {
5
5
  "id": "app:create",
@@ -795,9 +795,9 @@
795
795
  }
796
796
  },
797
797
  "args": {
798
- "entityName": {
799
- "name": "entityName",
800
- "description": "The name of the entity type to create",
798
+ "typePath": {
799
+ "name": "typePath",
800
+ "description": "The type path of the entity to create (e.g. color, custom-entity:franchise)",
801
801
  "required": true
802
802
  }
803
803
  }
@@ -881,7 +881,7 @@
881
881
  "args": {
882
882
  "entityName": {
883
883
  "name": "entityName",
884
- "description": "The name of the entity type to delete",
884
+ "description": "The name of the entity type to delete (type paths are not supported)",
885
885
  "required": true
886
886
  },
887
887
  "ids": {
@@ -1011,9 +1011,9 @@
1011
1011
  }
1012
1012
  },
1013
1013
  "args": {
1014
- "entityName": {
1015
- "name": "entityName",
1016
- "description": "The name of the entity type to fetch",
1014
+ "typePath": {
1015
+ "name": "typePath",
1016
+ "description": "The type path of the entities to fetch (e.g. color, custom-entity:franchise)",
1017
1017
  "required": true
1018
1018
  },
1019
1019
  "ids": {
@@ -1110,7 +1110,7 @@
1110
1110
  "args": {
1111
1111
  "entityName": {
1112
1112
  "name": "entityName",
1113
- "description": "The name of the entity type to update",
1113
+ "description": "The name of the entity type to update (type paths are not supported)",
1114
1114
  "required": true
1115
1115
  },
1116
1116
  "ids": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "3.6.0-alpha-8-alpha.45c63ad",
3
+ "version": "3.6.0-alpha-8-alpha.418c5f6",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",