@contrail/cli 3.6.0-alpha.bd1031b → 3.6.0-alpha.c4e7620
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 +182 -26
- package/dist/api/types.d.ts +35 -0
- package/dist/api/types.js +49 -1
- package/dist/auth/login.d.ts +0 -4
- package/dist/auth/login.js +52 -115
- package/dist/auth/login.spec.js +0 -98
- package/dist/basecommand.js +2 -2
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/entities/create.d.ts +49 -0
- package/dist/commands/entities/create.js +618 -0
- package/dist/commands/entities/create.spec.js +581 -0
- package/dist/commands/entities/delete.d.ts +20 -0
- package/dist/commands/entities/delete.js +146 -0
- package/dist/commands/entities/get.d.ts +25 -0
- package/dist/commands/entities/get.js +298 -0
- package/dist/commands/entities/grammar.spec.d.ts +1 -0
- package/dist/commands/entities/grammar.spec.js +79 -0
- package/dist/commands/entities/output.spec.d.ts +1 -0
- package/dist/commands/entities/output.spec.js +72 -0
- package/dist/commands/entities/update.d.ts +32 -0
- package/dist/commands/entities/update.js +212 -0
- package/dist/commands/webhooks/delete.js +2 -3
- package/dist/common.d.ts +10 -1
- package/dist/common.js +37 -1
- package/dist/common.spec.d.ts +1 -0
- package/dist/common.spec.js +40 -0
- package/dist/helpers/config/config.d.ts +3 -3
- package/dist/helpers/config/config.js +3 -3
- package/dist/helpers/entities/assortment-items.d.ts +11 -0
- package/dist/helpers/entities/assortment-items.js +76 -0
- package/dist/helpers/entities/batchFetch.d.ts +11 -0
- package/dist/helpers/entities/batchFetch.js +50 -0
- package/dist/helpers/entities/index.d.ts +3 -0
- package/dist/helpers/entities/index.js +6 -0
- package/dist/helpers/entities/items.d.ts +6 -0
- package/dist/helpers/entities/items.js +60 -0
- package/dist/helpers/entities/items.spec.d.ts +1 -0
- package/dist/helpers/entities/items.spec.js +19 -0
- package/dist/helpers/entities/project-items.d.ts +2 -0
- package/dist/helpers/entities/project-items.js +44 -0
- package/dist/helpers/file-helpers.d.ts +1 -0
- package/dist/helpers/file-helpers.js +20 -3
- package/dist/helpers/propertySpecifications/dateRanges.d.ts +34 -0
- package/dist/helpers/propertySpecifications/dateRanges.js +91 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.js +97 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +39 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.js +102 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +387 -0
- package/dist/helpers/propertySpecifications/propertyValues.d.ts +31 -0
- package/dist/helpers/propertySpecifications/propertyValues.js +132 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.js +156 -0
- package/dist/logger.js +4 -1
- package/dist/logger.spec.d.ts +1 -0
- package/dist/logger.spec.js +12 -0
- package/node_modules/@contrail/entity-compare/package.json +6 -3
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
- package/node_modules/@contrail/loader/lib/constants.js +1 -9
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +1 -4
- package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
- package/node_modules/@contrail/sdk/lib/config/config.d.ts +3 -0
- package/node_modules/@contrail/sdk/lib/config/config.js +13 -7
- package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
- package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
- package/node_modules/@contrail/sdk/lib/entities/entities.client.js +3 -1
- package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
- package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/index.js +1 -0
- package/node_modules/@contrail/sdk/package.json +1 -1
- package/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
- package/oclif.manifest.json +449 -50
- package/package.json +6 -12
- package/dist/auth/sso.d.ts +0 -36
- package/dist/auth/sso.js +0 -174
- package/dist/auth/sso.spec.js +0 -148
- package/dist/commands/login.d.ts +0 -12
- package/dist/commands/login.js +0 -25
- /package/dist/{auth/sso.spec.d.ts → commands/entities/create.spec.d.ts} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findItemsNotInProject = void 0;
|
|
4
|
+
const batchFetch_1 = require("./batchFetch");
|
|
5
|
+
const items_1 = require("./items");
|
|
6
|
+
const PROJECT_ITEMS_CACHE_BY_PROJECT_ID = new Map();
|
|
7
|
+
const PROJECT_ITEMS_CACHE_BY_ITEM_ID = new Map();
|
|
8
|
+
async function cacheProjectItemsByProjectId(projectId) {
|
|
9
|
+
if (PROJECT_ITEMS_CACHE_BY_PROJECT_ID.has(projectId)) {
|
|
10
|
+
return; // Already cached
|
|
11
|
+
}
|
|
12
|
+
const projectItems = await (0, batchFetch_1.batchFetch)('project-item', {
|
|
13
|
+
criteria: { projectId },
|
|
14
|
+
propertySlugs: ['id', 'projectId', 'itemId'],
|
|
15
|
+
});
|
|
16
|
+
PROJECT_ITEMS_CACHE_BY_PROJECT_ID.set(projectId, projectItems);
|
|
17
|
+
projectItems.forEach((item) => {
|
|
18
|
+
if (!PROJECT_ITEMS_CACHE_BY_ITEM_ID.has(item.itemId)) {
|
|
19
|
+
PROJECT_ITEMS_CACHE_BY_ITEM_ID.set(item.itemId, []);
|
|
20
|
+
}
|
|
21
|
+
PROJECT_ITEMS_CACHE_BY_ITEM_ID.get(item.itemId).push(item);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function getProjectItemsByProjectId(projectId) {
|
|
25
|
+
await cacheProjectItemsByProjectId(projectId);
|
|
26
|
+
const projectItems = PROJECT_ITEMS_CACHE_BY_PROJECT_ID.get(projectId);
|
|
27
|
+
if (!projectItems) {
|
|
28
|
+
throw new Error(`No project items found for project ID ${projectId}`);
|
|
29
|
+
}
|
|
30
|
+
return projectItems;
|
|
31
|
+
}
|
|
32
|
+
async function findItemsNotInProject(projectId) {
|
|
33
|
+
const [projectItemsInProject, allItems] = await Promise.all([
|
|
34
|
+
getProjectItemsByProjectId(projectId),
|
|
35
|
+
(0, items_1.getManyItems)(),
|
|
36
|
+
]);
|
|
37
|
+
const projectItemIds = new Set(projectItemsInProject.map((item) => item.itemId));
|
|
38
|
+
const itemsNotInProject = allItems.filter((item) => !projectItemIds.has(item.id));
|
|
39
|
+
if (itemsNotInProject.length === 0) {
|
|
40
|
+
throw new Error(`All items are already in project ${projectId}`);
|
|
41
|
+
}
|
|
42
|
+
return itemsNotInProject.sort((a, b) => a.id.localeCompare(b.id)); // sorting ensures consistent order of response
|
|
43
|
+
}
|
|
44
|
+
exports.findItemsNotInProject = findItemsNotInProject;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function safeFileOverwrite(fileLocation: string, overwrite: boolean): Promise<boolean>;
|
|
2
2
|
export declare function parseCSVData(data: string): any;
|
|
3
|
+
export declare function parseFileAsJsonArray(fileName: string): any[];
|
|
3
4
|
export declare function saveData(data: any, fileLocation: string, overwrite: boolean): Promise<void>;
|
|
4
5
|
export declare function loadData(fileLocation: string): any;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadData = exports.saveData = exports.parseCSVData = exports.safeFileOverwrite = void 0;
|
|
3
|
+
exports.loadData = exports.saveData = exports.parseFileAsJsonArray = exports.parseCSVData = exports.safeFileOverwrite = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const common_1 = require("../common");
|
|
6
7
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
|
-
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
8
8
|
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
9
9
|
const logger_1 = tslib_1.__importDefault(require("../logger"));
|
|
10
10
|
const sync_1 = require("csv-parse/sync");
|
|
@@ -15,7 +15,7 @@ async function safeFileOverwrite(fileLocation, overwrite) {
|
|
|
15
15
|
logger_1.default.info(`overwriting ${fileLocation}`);
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
|
-
const answers = await
|
|
18
|
+
const answers = await (0, common_1.promptOnStderr)([
|
|
19
19
|
{
|
|
20
20
|
type: 'confirm',
|
|
21
21
|
name: 'shouldOverwrite',
|
|
@@ -37,6 +37,23 @@ function parseCSVData(data) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
exports.parseCSVData = parseCSVData;
|
|
40
|
+
function parseFileAsJsonArray(fileName) {
|
|
41
|
+
if (!fs_1.default.existsSync(fileName)) {
|
|
42
|
+
throw new Error(`File not found: ${fileName}`);
|
|
43
|
+
}
|
|
44
|
+
const fileContent = fs_1.default.readFileSync(fileName, 'utf-8');
|
|
45
|
+
try {
|
|
46
|
+
const jsonArray = JSON.parse(fileContent);
|
|
47
|
+
if (!Array.isArray(jsonArray)) {
|
|
48
|
+
throw new Error(`File content is not a valid JSON array: ${fileName}`);
|
|
49
|
+
}
|
|
50
|
+
return jsonArray;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error(`Error parsing JSON from file ${fileName}: ${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.parseFileAsJsonArray = parseFileAsJsonArray;
|
|
40
57
|
//saves data as yaml to fileLocation (resolved against the current directory), prompting before overwriting unless overwrite is passed
|
|
41
58
|
async function saveData(data, fileLocation, overwrite) {
|
|
42
59
|
const yamlStr = js_yaml_1.default.dump(data);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date Range Parsing Utilities
|
|
3
|
+
*
|
|
4
|
+
* Resolves the date range syntax used in get criteria values:
|
|
5
|
+
* - 2025-09-15..2025-09-16 (date range)
|
|
6
|
+
* - 2025-09-15T04:00:00Z..2025-09-16T03:59:59Z (timestamp range)
|
|
7
|
+
* - 2025-09-15.. (from date onwards)
|
|
8
|
+
* - ..2025-09-16 (until date)
|
|
9
|
+
*/
|
|
10
|
+
export type DateRange = {
|
|
11
|
+
start?: Date;
|
|
12
|
+
end?: Date;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a criteria value uses date range syntax (..)
|
|
16
|
+
*/
|
|
17
|
+
export declare function isDateRangeValue(value: unknown): value is string;
|
|
18
|
+
/**
|
|
19
|
+
* Parses a date range value into its bounds
|
|
20
|
+
* @param rangeValue - The value (e.g., "2025-09-15..2025-09-16")
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseDateRange(rangeValue: string): DateRange;
|
|
23
|
+
/**
|
|
24
|
+
* Parses a date string, handling both date-only and full timestamp formats
|
|
25
|
+
* @param dateStr - Date string (e.g., "2025-09-15" or "2025-09-15T04:00:00Z")
|
|
26
|
+
* @param boundType - Whether this is the 'start' or 'end' of a range (affects date-only handling)
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseDate(dateStr: string, boundType?: 'start' | 'end'): Date;
|
|
29
|
+
/**
|
|
30
|
+
* Converts a date range to JSURL BETWEEN format
|
|
31
|
+
* @param range - The date range object
|
|
32
|
+
* @param isEndOfRange - Whether this date represents the end of a range (affects date-only handling)
|
|
33
|
+
*/
|
|
34
|
+
export declare function convertDateRangeToJSURL(range: DateRange): string;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Date Range Parsing Utilities
|
|
4
|
+
*
|
|
5
|
+
* Resolves the date range syntax used in get criteria values:
|
|
6
|
+
* - 2025-09-15..2025-09-16 (date range)
|
|
7
|
+
* - 2025-09-15T04:00:00Z..2025-09-16T03:59:59Z (timestamp range)
|
|
8
|
+
* - 2025-09-15.. (from date onwards)
|
|
9
|
+
* - ..2025-09-16 (until date)
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.convertDateRangeToJSURL = exports.parseDate = exports.parseDateRange = exports.isDateRangeValue = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if a criteria value uses date range syntax (..)
|
|
15
|
+
*/
|
|
16
|
+
function isDateRangeValue(value) {
|
|
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()));
|
|
23
|
+
}
|
|
24
|
+
exports.isDateRangeValue = isDateRangeValue;
|
|
25
|
+
function toBoundedDate(dateStr) {
|
|
26
|
+
return new Date(dateStr.includes('T') ? dateStr : `${dateStr}T00:00:00.000Z`);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parses a date range value into its bounds
|
|
30
|
+
* @param rangeValue - The value (e.g., "2025-09-15..2025-09-16")
|
|
31
|
+
*/
|
|
32
|
+
function parseDateRange(rangeValue) {
|
|
33
|
+
if (!rangeValue.includes('..')) {
|
|
34
|
+
throw new Error(`Invalid date range: ${rangeValue}`);
|
|
35
|
+
}
|
|
36
|
+
const [startStr, endStr] = rangeValue.split('..');
|
|
37
|
+
const range = {
|
|
38
|
+
start: startStr.trim() ? parseDate(startStr.trim(), 'start') : undefined,
|
|
39
|
+
end: endStr.trim() ? parseDate(endStr.trim(), 'end') : undefined,
|
|
40
|
+
};
|
|
41
|
+
// At least one bound must be specified
|
|
42
|
+
if (!range.start && !range.end) {
|
|
43
|
+
throw new Error(`Date range must have at least one bound: ${rangeValue}`);
|
|
44
|
+
}
|
|
45
|
+
return range;
|
|
46
|
+
}
|
|
47
|
+
exports.parseDateRange = parseDateRange;
|
|
48
|
+
/**
|
|
49
|
+
* Parses a date string, handling both date-only and full timestamp formats
|
|
50
|
+
* @param dateStr - Date string (e.g., "2025-09-15" or "2025-09-15T04:00:00Z")
|
|
51
|
+
* @param boundType - Whether this is the 'start' or 'end' of a range (affects date-only handling)
|
|
52
|
+
*/
|
|
53
|
+
function parseDate(dateStr, boundType = 'start') {
|
|
54
|
+
if (!dateStr.includes('T')) {
|
|
55
|
+
if (boundType === 'start') {
|
|
56
|
+
dateStr = `${dateStr}T00:00:00.000Z`;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
dateStr = `${dateStr}T23:59:59.999Z`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const date = new Date(dateStr);
|
|
63
|
+
if (isNaN(date.getTime())) {
|
|
64
|
+
throw new Error(`Invalid date format: ${dateStr}`);
|
|
65
|
+
}
|
|
66
|
+
return date;
|
|
67
|
+
}
|
|
68
|
+
exports.parseDate = parseDate;
|
|
69
|
+
/**
|
|
70
|
+
* Converts a date range to JSURL BETWEEN format
|
|
71
|
+
* @param range - The date range object
|
|
72
|
+
* @param isEndOfRange - Whether this date represents the end of a range (affects date-only handling)
|
|
73
|
+
*/
|
|
74
|
+
function convertDateRangeToJSURL(range) {
|
|
75
|
+
if (!range.start && !range.end) {
|
|
76
|
+
throw new Error('Date range must have at least one bound');
|
|
77
|
+
}
|
|
78
|
+
if (range.start && range.end) {
|
|
79
|
+
const startISO = range.start.toISOString();
|
|
80
|
+
const endISO = range.end.toISOString();
|
|
81
|
+
return `BETWEEN ${startISO} and ${endISO}`;
|
|
82
|
+
}
|
|
83
|
+
else if (range.start) {
|
|
84
|
+
return `>= ${range.start.toISOString()}`;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const endISO = range.end.toISOString();
|
|
88
|
+
return `<= ${endISO}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.convertDateRangeToJSURL = convertDateRangeToJSURL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dateRanges_1 = require("./dateRanges");
|
|
4
|
+
describe('Date Range Specifications', () => {
|
|
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
|
+
});
|
|
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
|
+
});
|
|
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
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('parseDate', () => {
|
|
26
|
+
it('should parse ISO timestamps correctly', () => {
|
|
27
|
+
const date = (0, dateRanges_1.parseDate)('2025-09-15T04:00:00Z');
|
|
28
|
+
expect(date.toISOString()).toBe('2025-09-15T04:00:00.000Z');
|
|
29
|
+
});
|
|
30
|
+
it('should parse date-only strings as start of day', () => {
|
|
31
|
+
const date = (0, dateRanges_1.parseDate)('2025-09-15', 'start');
|
|
32
|
+
expect(date.toISOString()).toBe('2025-09-15T00:00:00.000Z');
|
|
33
|
+
});
|
|
34
|
+
it('should parse date-only strings as end of day for end bound', () => {
|
|
35
|
+
const date = (0, dateRanges_1.parseDate)('2025-09-15', 'end');
|
|
36
|
+
expect(date.toISOString()).toBe('2025-09-15T23:59:59.999Z');
|
|
37
|
+
});
|
|
38
|
+
it('should throw for invalid date strings', () => {
|
|
39
|
+
expect(() => (0, dateRanges_1.parseDate)('invalid-date')).toThrow('Invalid date format');
|
|
40
|
+
expect(() => (0, dateRanges_1.parseDate)('2025-13-50')).toThrow('Invalid date format');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('parseDateRange', () => {
|
|
44
|
+
it('should parse full date ranges', () => {
|
|
45
|
+
const result = (0, dateRanges_1.parseDateRange)('2025-09-15..2025-09-16');
|
|
46
|
+
expect(result.start).toEqual(new Date('2025-09-15T00:00:00.000Z'));
|
|
47
|
+
expect(result.end).toEqual(new Date('2025-09-16T23:59:59.999Z'));
|
|
48
|
+
});
|
|
49
|
+
it('should parse open-ended start ranges', () => {
|
|
50
|
+
const result = (0, dateRanges_1.parseDateRange)('2025-09-15..');
|
|
51
|
+
expect(result.start).toEqual(new Date('2025-09-15T00:00:00.000Z'));
|
|
52
|
+
expect(result.end).toBeUndefined();
|
|
53
|
+
});
|
|
54
|
+
it('should parse open-ended end ranges', () => {
|
|
55
|
+
const result = (0, dateRanges_1.parseDateRange)('..2025-09-16');
|
|
56
|
+
expect(result.start).toBeUndefined();
|
|
57
|
+
expect(result.end).toEqual(new Date('2025-09-16T23:59:59.999Z'));
|
|
58
|
+
});
|
|
59
|
+
it('should parse timestamp ranges', () => {
|
|
60
|
+
const result = (0, dateRanges_1.parseDateRange)('2025-09-15T04:00:00Z..2025-09-16T03:59:59Z');
|
|
61
|
+
expect(result.start).toEqual(new Date('2025-09-15T04:00:00.000Z'));
|
|
62
|
+
expect(result.end).toEqual(new Date('2025-09-16T03:59:59.000Z'));
|
|
63
|
+
});
|
|
64
|
+
it('should throw for invalid ranges', () => {
|
|
65
|
+
expect(() => (0, dateRanges_1.parseDateRange)('invalid')).toThrow('Invalid date range');
|
|
66
|
+
expect(() => (0, dateRanges_1.parseDateRange)('..')).toThrow('Date range must have at least one bound');
|
|
67
|
+
expect(() => (0, dateRanges_1.parseDateRange)('invalid..date')).toThrow('Invalid date format');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('convertDateRangeToJSURL', () => {
|
|
71
|
+
it('should convert full ranges to BETWEEN format', () => {
|
|
72
|
+
const range = {
|
|
73
|
+
start: new Date('2025-09-15T00:00:00.000Z'),
|
|
74
|
+
end: new Date('2025-09-16T23:59:59.999Z'),
|
|
75
|
+
};
|
|
76
|
+
const result = (0, dateRanges_1.convertDateRangeToJSURL)(range);
|
|
77
|
+
expect(result).toBe('BETWEEN 2025-09-15T00:00:00.000Z and 2025-09-16T23:59:59.999Z');
|
|
78
|
+
});
|
|
79
|
+
it('should convert start-only ranges to >= format', () => {
|
|
80
|
+
const range = {
|
|
81
|
+
start: new Date('2025-09-15T00:00:00.000Z'),
|
|
82
|
+
};
|
|
83
|
+
const result = (0, dateRanges_1.convertDateRangeToJSURL)(range);
|
|
84
|
+
expect(result).toBe('>= 2025-09-15T00:00:00.000Z');
|
|
85
|
+
});
|
|
86
|
+
it('should convert end-only ranges to <= format', () => {
|
|
87
|
+
const range = {
|
|
88
|
+
end: new Date('2025-09-16T23:59:59.999Z'),
|
|
89
|
+
};
|
|
90
|
+
const result = (0, dateRanges_1.convertDateRangeToJSURL)(range);
|
|
91
|
+
expect(result).toBe('<= 2025-09-16T23:59:59.999Z');
|
|
92
|
+
});
|
|
93
|
+
it('should throw for empty ranges', () => {
|
|
94
|
+
expect(() => (0, dateRanges_1.convertDateRangeToJSURL)({})).toThrow('Date range must have at least one bound');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Property Specification
|
|
3
|
+
*
|
|
4
|
+
* Property Specifications is an argument pattern used to express that
|
|
5
|
+
* a specific property has a specific value. In GET requests, this is used
|
|
6
|
+
* to specify the query parameters. In PUT requests, this is used to
|
|
7
|
+
* specify the properties to update.
|
|
8
|
+
*
|
|
9
|
+
* Each follows the format: slug=value
|
|
10
|
+
*
|
|
11
|
+
* It is typically used as the argv in a command.
|
|
12
|
+
*
|
|
13
|
+
* Special handling for empty values:
|
|
14
|
+
* - slug= (empty value) → property is set to undefined (unset)
|
|
15
|
+
* - slug='""' or slug="''" → property is set to empty string ""
|
|
16
|
+
*
|
|
17
|
+
* Examples:
|
|
18
|
+
*
|
|
19
|
+
* contrail entities get color -- id=123
|
|
20
|
+
* contrail entities update color 123 -- name=obsidian hex=000000
|
|
21
|
+
* contrail entities update color 123 -- description= notes='""'
|
|
22
|
+
*/
|
|
23
|
+
export type PropertySpecification = {
|
|
24
|
+
slug: string;
|
|
25
|
+
value: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
export type PropertySpecificationBySlug = Map<string, string | number | string[] | number[] | undefined>;
|
|
28
|
+
export type PropertySpecificationString = `${string}=${string}`;
|
|
29
|
+
export declare function parsePropertySpecification(spec: PropertySpecificationString): PropertySpecification;
|
|
30
|
+
export declare function parsePropertySpecificationsIntoMap(propertySpecifications: PropertySpecificationString[]): PropertySpecificationBySlug;
|
|
31
|
+
/**
|
|
32
|
+
* Splits command argv tokens (after the typePath) into positional ids and
|
|
33
|
+
* property specifications.
|
|
34
|
+
*/
|
|
35
|
+
export declare function partitionIdsAndSpecs(tokens: string[]): {
|
|
36
|
+
ids: string[];
|
|
37
|
+
specs: PropertySpecificationString[];
|
|
38
|
+
};
|
|
39
|
+
export declare function isValidPropertySpecification(maybeSpec: string): maybeSpec is PropertySpecificationString;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Property Specification
|
|
4
|
+
*
|
|
5
|
+
* Property Specifications is an argument pattern used to express that
|
|
6
|
+
* a specific property has a specific value. In GET requests, this is used
|
|
7
|
+
* to specify the query parameters. In PUT requests, this is used to
|
|
8
|
+
* specify the properties to update.
|
|
9
|
+
*
|
|
10
|
+
* Each follows the format: slug=value
|
|
11
|
+
*
|
|
12
|
+
* It is typically used as the argv in a command.
|
|
13
|
+
*
|
|
14
|
+
* Special handling for empty values:
|
|
15
|
+
* - slug= (empty value) → property is set to undefined (unset)
|
|
16
|
+
* - slug='""' or slug="''" → property is set to empty string ""
|
|
17
|
+
*
|
|
18
|
+
* Examples:
|
|
19
|
+
*
|
|
20
|
+
* contrail entities get color -- id=123
|
|
21
|
+
* contrail entities update color 123 -- name=obsidian hex=000000
|
|
22
|
+
* contrail entities update color 123 -- description= notes='""'
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.isValidPropertySpecification = exports.partitionIdsAndSpecs = exports.parsePropertySpecificationsIntoMap = exports.parsePropertySpecification = void 0;
|
|
26
|
+
// Special tokens for empty strings
|
|
27
|
+
const DOUBLE_QUOTED_EMPTY = '""';
|
|
28
|
+
const SINGLE_QUOTED_EMPTY = "''"; // eslint-disable-line quotes
|
|
29
|
+
function parsePropertySpecification(spec) {
|
|
30
|
+
const equalsIndex = spec.indexOf('=');
|
|
31
|
+
if (equalsIndex === -1) {
|
|
32
|
+
throw new Error(`Invalid property specification: ${spec}`);
|
|
33
|
+
}
|
|
34
|
+
const slug = spec.substring(0, equalsIndex);
|
|
35
|
+
const value = spec.substring(equalsIndex + 1);
|
|
36
|
+
if (!slug) {
|
|
37
|
+
throw new Error(`Invalid property specification: ${spec}`);
|
|
38
|
+
}
|
|
39
|
+
// Handle special cases for empty strings:
|
|
40
|
+
// - x= means undefined (unset the property)
|
|
41
|
+
// - x='""' or x="''" means empty string ""
|
|
42
|
+
let finalValue;
|
|
43
|
+
if (value === '') {
|
|
44
|
+
finalValue = undefined;
|
|
45
|
+
}
|
|
46
|
+
else if (value === DOUBLE_QUOTED_EMPTY || value === SINGLE_QUOTED_EMPTY) {
|
|
47
|
+
finalValue = '';
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
finalValue = value;
|
|
51
|
+
}
|
|
52
|
+
return { slug, value: finalValue };
|
|
53
|
+
}
|
|
54
|
+
exports.parsePropertySpecification = parsePropertySpecification;
|
|
55
|
+
function parsePropertySpecificationsIntoMap(propertySpecifications) {
|
|
56
|
+
const propertySpecBySlug = new Map();
|
|
57
|
+
for (const spec of propertySpecifications) {
|
|
58
|
+
const { slug, value } = parsePropertySpecification(spec);
|
|
59
|
+
if (slug === 'ids' && value !== undefined) {
|
|
60
|
+
// ids is the one comma-split exception: it is a list of ids by definition
|
|
61
|
+
// and ids never contain commas.
|
|
62
|
+
const idsArray = value.split(',').map((id) => id.trim());
|
|
63
|
+
const existingIds = propertySpecBySlug.get(slug);
|
|
64
|
+
propertySpecBySlug.set(slug, Array.isArray(existingIds) ? [...existingIds, ...idsArray] : idsArray);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const existing = propertySpecBySlug.get(slug);
|
|
68
|
+
if (propertySpecBySlug.has(slug) && existing !== undefined && value !== undefined) {
|
|
69
|
+
propertySpecBySlug.set(slug, Array.isArray(existing) ? [...existing, value] : [existing, value]);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
propertySpecBySlug.set(slug, value);
|
|
73
|
+
}
|
|
74
|
+
return propertySpecBySlug;
|
|
75
|
+
}
|
|
76
|
+
exports.parsePropertySpecificationsIntoMap = parsePropertySpecificationsIntoMap;
|
|
77
|
+
/**
|
|
78
|
+
* Splits command argv tokens (after the typePath) into positional ids and
|
|
79
|
+
* property specifications.
|
|
80
|
+
*/
|
|
81
|
+
function partitionIdsAndSpecs(tokens) {
|
|
82
|
+
// a token carrying '=' belongs to neither bucket below, so it would vanish silently
|
|
83
|
+
const malformed = tokens.filter((token) => token.includes('=') && !isValidPropertySpecification(token));
|
|
84
|
+
if (malformed.length > 0) {
|
|
85
|
+
throw new Error(`Invalid property specification: ${malformed.join(' ')}. Expected slug=value.`);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
ids: tokens.filter((token) => !token.includes('=')),
|
|
89
|
+
specs: tokens.filter(isValidPropertySpecification),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
exports.partitionIdsAndSpecs = partitionIdsAndSpecs;
|
|
93
|
+
function isValidPropertySpecification(maybeSpec) {
|
|
94
|
+
try {
|
|
95
|
+
const { slug } = parsePropertySpecification(maybeSpec);
|
|
96
|
+
return !!slug;
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.isValidPropertySpecification = isValidPropertySpecification;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|