@contrail/cli 3.6.0-alpha-8-alpha.ec1ef67 → 3.6.0-alpha-8-alpha.e2d1830
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 +5 -5
- package/dist/commands/entities/create.js +4 -4
- package/dist/commands/entities/get.js +1 -1
- package/dist/helpers/entities/assortment-items.js +1 -1
- package/dist/helpers/entities/batchFetch.d.ts +4 -1
- package/dist/helpers/entities/batchFetch.js +1 -0
- package/dist/helpers/entities/items.js +7 -3
- package/dist/helpers/entities/project-items.js +1 -1
- package/dist/helpers/propertySpecifications/dateRanges.js +9 -1
- package/dist/helpers/propertySpecifications/dateRanges.spec.js +6 -0
- package/oclif.manifest.json +5 -5
- 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.e2d1830 linux-x64 node-v24.22.2
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -583,17 +583,17 @@ EXAMPLES
|
|
|
583
583
|
|
|
584
584
|
$ contrail entities create color -- name="Electric Blue" green=1 red=2 blue=3 # creates one color with specified properties only
|
|
585
585
|
|
|
586
|
-
$ contrail entities create custom-
|
|
586
|
+
$ contrail entities create custom-entity:franchise
|
|
587
587
|
|
|
588
|
-
$ contrail entities create project-item -n=
|
|
588
|
+
$ contrail entities create project-item -n=10 -- projectId=abc # creates 10 project items within project ABC
|
|
589
589
|
|
|
590
590
|
$ contrail entities create color -g -r # creates a random color with a human readable ID
|
|
591
591
|
|
|
592
592
|
$ contrail entities create color -d -- name=test # simulates the creation of a color without actually creating it
|
|
593
593
|
|
|
594
|
-
$ contrail entities create custom-entity:franchise -
|
|
594
|
+
$ contrail entities create custom-entity:franchise -S # creates an entity and the response does not contain hydrated relationships
|
|
595
595
|
|
|
596
|
-
$ contrail entities create color -g -- name=Electric Blue # creates a color with the name specified and other properties auto-generated
|
|
596
|
+
$ contrail entities create color -g -- name="Electric Blue" # creates a color with the name specified and other properties auto-generated
|
|
597
597
|
|
|
598
598
|
$ contrail entities create color -o /tmp/colors.json -- name=Blue green=1 red=2 blue=3 # creates a color and saves the output to /tmp/colors.json
|
|
599
599
|
```
|
|
@@ -144,12 +144,12 @@ class CreateEntity extends basecommand_1.BaseCommand {
|
|
|
144
144
|
static examples = [
|
|
145
145
|
'contrail entities create color -g -n=10 # creates 10 random colors',
|
|
146
146
|
'contrail entities create color -- name="Electric Blue" green=1 red=2 blue=3 # creates one color with specified properties only',
|
|
147
|
-
'contrail entities create custom-
|
|
148
|
-
'contrail entities create project-item -n=
|
|
147
|
+
'contrail entities create custom-entity:franchise',
|
|
148
|
+
'contrail entities create project-item -n=10 -- projectId=abc # creates 10 project items within project ABC',
|
|
149
149
|
'contrail entities create color -g -r # creates a random color with a human readable ID',
|
|
150
150
|
'contrail entities create color -d -- name=test # simulates the creation of a color without actually creating it',
|
|
151
|
-
'contrail entities create custom-entity:franchise -
|
|
152
|
-
'contrail entities create color -g -- name=Electric Blue # creates a color with the name specified and other properties auto-generated',
|
|
151
|
+
'contrail entities create custom-entity:franchise -S # creates an entity and the response does not contain hydrated relationships',
|
|
152
|
+
'contrail entities create color -g -- name="Electric Blue" # creates a color with the name specified and other properties auto-generated',
|
|
153
153
|
'contrail entities create color -o /tmp/colors.json -- name=Blue green=1 red=2 blue=3 # creates a color and saves the output to /tmp/colors.json',
|
|
154
154
|
];
|
|
155
155
|
static flags = {
|
|
@@ -250,7 +250,7 @@ async function find(entityName, options = {}) {
|
|
|
250
250
|
// a suffix names a specific sub-route and an id names one entity; both always go
|
|
251
251
|
// through the plain client (batch-fetch only understands criteria)
|
|
252
252
|
if ((0, batchFetch_1.canBatchFetchEntity)(entityName) && !suffix && !id) {
|
|
253
|
-
return (0, batchFetch_1.batchFetch)(entityName, payload);
|
|
253
|
+
return (0, batchFetch_1.batchFetch)(entityName, { ...payload, propertySlugs });
|
|
254
254
|
}
|
|
255
255
|
else {
|
|
256
256
|
return client.get(payload);
|
|
@@ -39,7 +39,7 @@ async function cacheAssortmentItemsByAssortmentId(assortmentId) {
|
|
|
39
39
|
}
|
|
40
40
|
const assortmentItems = await (0, batchFetch_1.batchFetch)('assortment-item', {
|
|
41
41
|
criteria: { assortmentId },
|
|
42
|
-
|
|
42
|
+
propertySlugs: ['id', 'assortmentId', 'itemId'],
|
|
43
43
|
});
|
|
44
44
|
ASSORTMENT_ITEMS_CACHE_BY_ASSORTMENT_ID.set(assortmentId, assortmentItems);
|
|
45
45
|
assortmentItems.forEach((item) => {
|
|
@@ -5,4 +5,7 @@ export interface BatchFetchableEntityMap {
|
|
|
5
5
|
'project-item': ProjectItem;
|
|
6
6
|
'assortment-item': AssortmentItem;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export type BatchFetchOptions = EntitiesClientGetOptions & {
|
|
9
|
+
propertySlugs?: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare function batchFetch<K extends keyof BatchFetchableEntityMap>(entityName: K, options: BatchFetchOptions): Promise<BatchFetchableEntityMap[K][]>;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Roles = exports.getItemFamilies = exports.getManyItems = void 0;
|
|
4
4
|
const sdk_1 = require("@contrail/sdk");
|
|
5
|
-
|
|
5
|
+
const ITEM_FETCH_CEILING = 10000;
|
|
6
|
+
async function getManyItems(maxCount) {
|
|
6
7
|
const client = new sdk_1.Entities();
|
|
8
|
+
const limit = maxCount ?? ITEM_FETCH_CEILING;
|
|
7
9
|
const items = [];
|
|
8
10
|
let nextPageKey = undefined;
|
|
9
11
|
while (true) {
|
|
@@ -20,8 +22,10 @@ async function getManyItems(maxCount = 10000) {
|
|
|
20
22
|
if (!nextPageKey) {
|
|
21
23
|
break; // an absent cursor restarts pagination from page one
|
|
22
24
|
}
|
|
23
|
-
if (items.length >=
|
|
24
|
-
|
|
25
|
+
if (items.length >= limit) {
|
|
26
|
+
if (maxCount === undefined) {
|
|
27
|
+
console.warn(`Reached maximum item limit of ${limit}. Some items may not be included.`);
|
|
28
|
+
}
|
|
25
29
|
break;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
@@ -11,7 +11,7 @@ async function cacheProjectItemsByProjectId(projectId) {
|
|
|
11
11
|
}
|
|
12
12
|
const projectItems = await (0, batchFetch_1.batchFetch)('project-item', {
|
|
13
13
|
criteria: { projectId },
|
|
14
|
-
|
|
14
|
+
propertySlugs: ['id', 'projectId', 'itemId'],
|
|
15
15
|
});
|
|
16
16
|
PROJECT_ITEMS_CACHE_BY_PROJECT_ID.set(projectId, projectItems);
|
|
17
17
|
projectItems.forEach((item) => {
|
|
@@ -14,9 +14,17 @@ exports.convertDateRangeToJSURL = exports.parseDate = exports.parseDateRange = e
|
|
|
14
14
|
* Checks if a criteria value uses date range syntax (..)
|
|
15
15
|
*/
|
|
16
16
|
function isDateRangeValue(value) {
|
|
17
|
-
|
|
17
|
+
if (typeof value !== 'string' || !value.includes('..')) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const [start, end] = value.split('..');
|
|
21
|
+
const bounds = [start.trim(), end?.trim()].filter(Boolean);
|
|
22
|
+
return bounds.length > 0 && bounds.every((bound) => !isNaN(toBoundedDate(bound).getTime()));
|
|
18
23
|
}
|
|
19
24
|
exports.isDateRangeValue = isDateRangeValue;
|
|
25
|
+
function toBoundedDate(dateStr) {
|
|
26
|
+
return new Date(dateStr.includes('T') ? dateStr : `${dateStr}T00:00:00.000Z`);
|
|
27
|
+
}
|
|
20
28
|
/**
|
|
21
29
|
* Parses a date range value into its bounds
|
|
22
30
|
* @param rangeValue - The value (e.g., "2025-09-15..2025-09-16")
|
|
@@ -15,6 +15,12 @@ describe('Date Range Specifications', () => {
|
|
|
15
15
|
expect((0, dateRanges_1.isDateRangeValue)(42)).toBe(false);
|
|
16
16
|
expect((0, dateRanges_1.isDateRangeValue)(undefined)).toBe(false);
|
|
17
17
|
});
|
|
18
|
+
it('should reject dotted values whose bounds are not dates', () => {
|
|
19
|
+
expect((0, dateRanges_1.isDateRangeValue)('Loading...')).toBe(false);
|
|
20
|
+
expect((0, dateRanges_1.isDateRangeValue)('a..b')).toBe(false);
|
|
21
|
+
expect((0, dateRanges_1.isDateRangeValue)('v1..v2')).toBe(false);
|
|
22
|
+
expect((0, dateRanges_1.isDateRangeValue)('..')).toBe(false);
|
|
23
|
+
});
|
|
18
24
|
});
|
|
19
25
|
describe('parseDate', () => {
|
|
20
26
|
it('should parse ISO timestamps correctly', () => {
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.6.0-alpha-8-alpha.
|
|
2
|
+
"version": "3.6.0-alpha-8-alpha.e2d1830",
|
|
3
3
|
"commands": {
|
|
4
4
|
"app:create": {
|
|
5
5
|
"id": "app:create",
|
|
@@ -683,12 +683,12 @@
|
|
|
683
683
|
"examples": [
|
|
684
684
|
"contrail entities create color -g -n=10 # creates 10 random colors",
|
|
685
685
|
"contrail entities create color -- name=\"Electric Blue\" green=1 red=2 blue=3 # creates one color with specified properties only",
|
|
686
|
-
"contrail entities create custom-
|
|
687
|
-
"contrail entities create project-item -n=
|
|
686
|
+
"contrail entities create custom-entity:franchise",
|
|
687
|
+
"contrail entities create project-item -n=10 -- projectId=abc # creates 10 project items within project ABC",
|
|
688
688
|
"contrail entities create color -g -r # creates a random color with a human readable ID",
|
|
689
689
|
"contrail entities create color -d -- name=test # simulates the creation of a color without actually creating it",
|
|
690
|
-
"contrail entities create custom-entity:franchise -
|
|
691
|
-
"contrail entities create color -g -- name
|
|
690
|
+
"contrail entities create custom-entity:franchise -S # creates an entity and the response does not contain hydrated relationships",
|
|
691
|
+
"contrail entities create color -g -- name=\"Electric Blue\" # creates a color with the name specified and other properties auto-generated",
|
|
692
692
|
"contrail entities create color -o /tmp/colors.json -- name=Blue green=1 red=2 blue=3 # creates a color and saves the output to /tmp/colors.json"
|
|
693
693
|
],
|
|
694
694
|
"flags": {
|