@contrail/cli 3.6.0-alpha-8-alpha.a4b98b5 → 3.6.0-alpha-8-alpha.7ff28fb
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 +1 -1
- package/dist/commands/entities/create.js +0 -28
- package/dist/helpers/entities/assortment-items.d.ts +0 -1
- package/dist/helpers/entities/assortment-items.js +1 -12
- package/dist/helpers/entities/items.d.ts +0 -2
- package/dist/helpers/entities/items.js +1 -18
- package/dist/helpers/entities/project-items.d.ts +0 -1
- package/dist/helpers/entities/project-items.js +1 -22
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
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.7ff28fb linux-x64 node-v24.22.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -22,24 +22,6 @@ let SHOULD_SKIP_HYDRATE_RELATIONSHIPS = false;
|
|
|
22
22
|
let SHOULD_GENERATE_MISSING_VALUES = false;
|
|
23
23
|
let NUM_ENTITIES_TO_CREATE = 1; // Default to creating one entity if not specified
|
|
24
24
|
const getNumEntitiesToCreate = () => NUM_ENTITIES_TO_CREATE; // method to get the latest number in case this changes later
|
|
25
|
-
const baseValidationMap = {
|
|
26
|
-
assortmentId: async (_slug, assortmentId) => (0, entities_1.throwIfInvalidAssortmentId)(assortmentId),
|
|
27
|
-
itemId: async (_slug, itemId) => (0, entities_1.throwIfInvalidItemId)(itemId),
|
|
28
|
-
projectId: async (_slug, projectId) => (0, entities_1.throwIfInvalidProjectId)(projectId),
|
|
29
|
-
};
|
|
30
|
-
const throwIfInvalidPropertyLevelFn = async (_slug, maybeRoles) => [].concat(maybeRoles).forEach((maybeRole) => (0, entities_1.throwIfInvalidItemLevel)(maybeRole));
|
|
31
|
-
const throwIfInvalidUserOrgRoleFn = async (_slug, maybeRole) => {
|
|
32
|
-
if (maybeRole !== 'MEMBER' && maybeRole !== 'ADMIN') {
|
|
33
|
-
throw new Error(`${maybeRole} is not a valid User Org Role`); // TODO: get these roles from a shared library
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const SLUG_VALIDATION_BY_ROOT_MAP = {
|
|
37
|
-
item: { ...baseValidationMap, roles: throwIfInvalidPropertyLevelFn },
|
|
38
|
-
'project-item': { ...baseValidationMap, roles: throwIfInvalidPropertyLevelFn },
|
|
39
|
-
'assortment-item': baseValidationMap,
|
|
40
|
-
'user-org': baseValidationMap,
|
|
41
|
-
'custom-entity': { ...baseValidationMap, role: throwIfInvalidUserOrgRoleFn },
|
|
42
|
-
};
|
|
43
25
|
const SLUGS_THAT_MUST_BE_SPECIFIED_BY_TYPE_PATH = {
|
|
44
26
|
item: ['roles'],
|
|
45
27
|
'project-item': ['projectId'],
|
|
@@ -333,8 +315,6 @@ async function buildEntitiesToCreate(entityTypePath, entities, propertySpecifica
|
|
|
333
315
|
...createEntityWithPopulatedValues(type, typesCache, objectReferencesCache, propertySpecificationBySlug),
|
|
334
316
|
...entity,
|
|
335
317
|
}));
|
|
336
|
-
const limit = (0, p_limit_1.default)(30);
|
|
337
|
-
await Promise.all(populatedEntities.map(async () => limit(() => throwIfEntityIsInvalid)));
|
|
338
318
|
// Skip system value generation unless -g flag is set (generateValues mode)
|
|
339
319
|
if (!SHOULD_GENERATE_MISSING_VALUES) {
|
|
340
320
|
console.error('Using only specified properties. Use --generate-values to auto-generate missing values.');
|
|
@@ -428,14 +408,6 @@ function pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCac
|
|
|
428
408
|
}
|
|
429
409
|
return entity;
|
|
430
410
|
}
|
|
431
|
-
async function throwIfEntityIsInvalid(typeRoot, entity) {
|
|
432
|
-
const propertySlugs = Object.keys(entity);
|
|
433
|
-
const validationMap = SLUG_VALIDATION_BY_ROOT_MAP[typeRoot] || {};
|
|
434
|
-
const promises = propertySlugs
|
|
435
|
-
.filter((slug) => validationMap[slug])
|
|
436
|
-
.map((slug) => validationMap[slug](slug, entity[slug]));
|
|
437
|
-
await Promise.all(promises);
|
|
438
|
-
}
|
|
439
411
|
function pickRandomValueForProperty(property, objectReferencesCache, typeReferencesCache) {
|
|
440
412
|
const getRandomObjectReference = (referencedTypePath) => {
|
|
441
413
|
if (!objectReferencesCache.has(referencedTypePath)) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Item } from '@contrail/entity-types';
|
|
2
2
|
import { API_VERSION } from '@contrail/sdk';
|
|
3
|
-
export declare function throwIfInvalidAssortmentId(assortmentId: string): Promise<void>;
|
|
4
3
|
export declare function createAssortmentItem(assortmentItem: {
|
|
5
4
|
assortmentId: string;
|
|
6
5
|
itemId: string;
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findItemsNotInAssortment = exports.createAssortmentItem =
|
|
3
|
+
exports.findItemsNotInAssortment = exports.createAssortmentItem = void 0;
|
|
4
4
|
const sdk_1 = require("@contrail/sdk");
|
|
5
5
|
const batchFetch_1 = require("./batchFetch");
|
|
6
6
|
const items_1 = require("./items");
|
|
7
|
-
async function throwIfInvalidAssortmentId(assortmentId) {
|
|
8
|
-
if (!(await doesAssortmentExistById(assortmentId))) {
|
|
9
|
-
throw new Error(`Assortment with ID ${assortmentId} does not exist`);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.throwIfInvalidAssortmentId = throwIfInvalidAssortmentId;
|
|
13
|
-
async function doesAssortmentExistById(id) {
|
|
14
|
-
const client = new sdk_1.Entities();
|
|
15
|
-
const assortment = await client.get({ entityName: 'assortment', id });
|
|
16
|
-
return !!assortment;
|
|
17
|
-
}
|
|
18
7
|
async function createAssortmentItem(assortmentItem, options = {}) {
|
|
19
8
|
const client = new sdk_1.Entities();
|
|
20
9
|
const { assortmentId, itemId } = assortmentItem;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Item } from '@contrail/entity-types';
|
|
2
|
-
export declare function throwIfInvalidItemId(itemId: string): Promise<void>;
|
|
3
2
|
export type SparseItem = Pick<Item, 'id' | 'itemFamilyId' | 'roles' | 'name'>;
|
|
4
3
|
export declare function getAllItemsUsingCacheFallback(): Promise<SparseItem[]>;
|
|
5
4
|
export declare function getManyItems(maxCount?: number): Promise<SparseItem[]>;
|
|
@@ -7,4 +6,3 @@ export declare function getItemFamilies(count: number): Promise<SparseItem[] | u
|
|
|
7
6
|
export declare function getFamilyName(item: SparseItem): Promise<string[] | undefined>;
|
|
8
7
|
export declare const Roles: readonly ["option", "family"];
|
|
9
8
|
export type Role = (typeof Roles)[number];
|
|
10
|
-
export declare function throwIfInvalidItemLevel(role: string): asserts role is Role;
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Roles = exports.getFamilyName = exports.getItemFamilies = exports.getManyItems = exports.getAllItemsUsingCacheFallback = void 0;
|
|
4
4
|
const sdk_1 = require("@contrail/sdk");
|
|
5
|
-
async function throwIfInvalidItemId(itemId) {
|
|
6
|
-
if (!(await doesItemExistById(itemId))) {
|
|
7
|
-
throw new Error(`Item with ID ${itemId} does not exist`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.throwIfInvalidItemId = throwIfInvalidItemId;
|
|
11
|
-
async function doesItemExistById(id) {
|
|
12
|
-
const client = new sdk_1.Entities();
|
|
13
|
-
const item = await client.get({ entityName: 'item', id });
|
|
14
|
-
return !!item;
|
|
15
|
-
}
|
|
16
5
|
const ITEMS_CACHE_BY_ID = new Map();
|
|
17
6
|
async function getAllItemsUsingCacheFallback() {
|
|
18
7
|
if (ITEMS_CACHE_BY_ID.size > 0) {
|
|
@@ -73,12 +62,6 @@ async function ensureItemCacheIsPopulated() {
|
|
|
73
62
|
}
|
|
74
63
|
}
|
|
75
64
|
exports.Roles = ['option', 'family'];
|
|
76
|
-
function throwIfInvalidItemLevel(role) {
|
|
77
|
-
if (!exports.Roles.includes(role)) {
|
|
78
|
-
throw new Error(`Invalid role: ${role}. Valid roles are: ${exports.Roles.join(', ')}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.throwIfInvalidItemLevel = throwIfInvalidItemLevel;
|
|
82
65
|
async function getItems(criteria, count = 100) {
|
|
83
66
|
const client = new sdk_1.Entities();
|
|
84
67
|
const items = [];
|
|
@@ -1,31 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findItemsNotInProject =
|
|
4
|
-
const sdk_1 = require("@contrail/sdk");
|
|
3
|
+
exports.findItemsNotInProject = void 0;
|
|
5
4
|
const batchFetch_1 = require("./batchFetch");
|
|
6
5
|
const items_1 = require("./items");
|
|
7
6
|
const PROJECT_ITEMS_CACHE_BY_PROJECT_ID = new Map();
|
|
8
7
|
const PROJECT_ITEMS_CACHE_BY_ITEM_ID = new Map();
|
|
9
|
-
async function throwIfInvalidProjectId(projectId) {
|
|
10
|
-
if (!(await doesProjectExistById(projectId))) {
|
|
11
|
-
throw new Error(`Project with ID ${projectId} does not exist`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.throwIfInvalidProjectId = throwIfInvalidProjectId;
|
|
15
|
-
async function doesProjectExistById(id) {
|
|
16
|
-
const client = new sdk_1.Entities();
|
|
17
|
-
const project = await client
|
|
18
|
-
.get({
|
|
19
|
-
entityName: 'project',
|
|
20
|
-
id,
|
|
21
|
-
customParams: { propertySlugs: 'id' },
|
|
22
|
-
})
|
|
23
|
-
.catch((e) => {
|
|
24
|
-
console.error(e);
|
|
25
|
-
return null; // Return null if project does not exist
|
|
26
|
-
});
|
|
27
|
-
return !!project;
|
|
28
|
-
}
|
|
29
8
|
async function cacheProjectItemsByProjectId(projectId) {
|
|
30
9
|
if (PROJECT_ITEMS_CACHE_BY_PROJECT_ID.has(projectId)) {
|
|
31
10
|
return; // Already cached
|
package/oclif.manifest.json
CHANGED