@contrail/cli 3.6.0-alpha.f45f126 → 3.7.0-alpha.1c66a91

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.
Files changed (105) hide show
  1. package/README.md +207 -3
  2. package/dist/api/types.d.ts +35 -0
  3. package/dist/api/types.js +49 -1
  4. package/dist/auth/login.d.ts +1 -1
  5. package/dist/auth/login.js +46 -29
  6. package/dist/auth/login.spec.js +31 -15
  7. package/dist/auth/sign-in-error.d.ts +7 -0
  8. package/dist/auth/sign-in-error.js +24 -0
  9. package/dist/auth/sign-in-error.spec.d.ts +1 -0
  10. package/dist/auth/sign-in-error.spec.js +22 -0
  11. package/dist/auth/sso.d.ts +5 -3
  12. package/dist/auth/sso.js +34 -18
  13. package/dist/auth/sso.spec.js +63 -10
  14. package/dist/basecommand.d.ts +3 -0
  15. package/dist/basecommand.js +10 -3
  16. package/dist/commands/app/getApiKey.js +2 -2
  17. package/dist/commands/app/publish.js +1 -1
  18. package/dist/commands/app/version/prerelease.d.ts +11 -0
  19. package/dist/commands/app/version/prerelease.js +32 -0
  20. package/dist/commands/entities/create.d.ts +49 -0
  21. package/dist/commands/entities/create.js +618 -0
  22. package/dist/commands/entities/create.spec.d.ts +1 -0
  23. package/dist/commands/entities/create.spec.js +581 -0
  24. package/dist/commands/entities/delete.d.ts +20 -0
  25. package/dist/commands/entities/delete.js +146 -0
  26. package/dist/commands/entities/get.d.ts +25 -0
  27. package/dist/commands/entities/get.js +298 -0
  28. package/dist/commands/entities/grammar.spec.d.ts +1 -0
  29. package/dist/commands/entities/grammar.spec.js +79 -0
  30. package/dist/commands/entities/output.spec.d.ts +1 -0
  31. package/dist/commands/entities/output.spec.js +72 -0
  32. package/dist/commands/entities/update.d.ts +32 -0
  33. package/dist/commands/entities/update.js +212 -0
  34. package/dist/commands/login.js +1 -1
  35. package/dist/commands/webhooks/delete.js +2 -3
  36. package/dist/common.d.ts +10 -1
  37. package/dist/common.js +37 -1
  38. package/dist/common.spec.d.ts +1 -0
  39. package/dist/common.spec.js +40 -0
  40. package/dist/helpers/app/app-config-validators.js +4 -4
  41. package/dist/helpers/app/app-config-validators.spec.js +36 -0
  42. package/dist/helpers/app/app-deployer.d.ts +1 -0
  43. package/dist/helpers/app/app-deployer.js +34 -0
  44. package/dist/helpers/app/upgrade-version.d.ts +3 -1
  45. package/dist/helpers/app/upgrade-version.js +7 -8
  46. package/dist/helpers/app/upgrade-version.spec.js +15 -0
  47. package/dist/helpers/config/config.d.ts +3 -3
  48. package/dist/helpers/config/config.js +3 -3
  49. package/dist/helpers/entities/assortment-items.d.ts +11 -0
  50. package/dist/helpers/entities/assortment-items.js +76 -0
  51. package/dist/helpers/entities/batchFetch.d.ts +11 -0
  52. package/dist/helpers/entities/batchFetch.js +50 -0
  53. package/dist/helpers/entities/index.d.ts +3 -0
  54. package/dist/helpers/entities/index.js +6 -0
  55. package/dist/helpers/entities/items.d.ts +6 -0
  56. package/dist/helpers/entities/items.js +60 -0
  57. package/dist/helpers/entities/items.spec.d.ts +1 -0
  58. package/dist/helpers/entities/items.spec.js +19 -0
  59. package/dist/helpers/entities/project-items.d.ts +2 -0
  60. package/dist/helpers/entities/project-items.js +44 -0
  61. package/dist/helpers/file-helpers.d.ts +1 -0
  62. package/dist/helpers/file-helpers.js +20 -3
  63. package/dist/helpers/propertySpecifications/dateRanges.d.ts +34 -0
  64. package/dist/helpers/propertySpecifications/dateRanges.js +91 -0
  65. package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +1 -0
  66. package/dist/helpers/propertySpecifications/dateRanges.spec.js +97 -0
  67. package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +39 -0
  68. package/dist/helpers/propertySpecifications/propertySpecifications.js +102 -0
  69. package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +1 -0
  70. package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +387 -0
  71. package/dist/helpers/propertySpecifications/propertyValues.d.ts +31 -0
  72. package/dist/helpers/propertySpecifications/propertyValues.js +132 -0
  73. package/dist/helpers/propertySpecifications/propertyValues.spec.d.ts +1 -0
  74. package/dist/helpers/propertySpecifications/propertyValues.spec.js +156 -0
  75. package/dist/logger.js +4 -1
  76. package/dist/logger.spec.d.ts +1 -0
  77. package/dist/logger.spec.js +12 -0
  78. package/node_modules/@contrail/entity-compare/package.json +6 -3
  79. package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
  80. package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
  81. package/node_modules/@contrail/loader/lib/constants.js +1 -9
  82. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
  83. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
  84. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
  85. package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
  86. package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
  87. package/node_modules/@contrail/loader/package.json +2 -2
  88. package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +1 -4
  89. package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
  90. package/node_modules/@contrail/sdk/lib/config/config.d.ts +3 -0
  91. package/node_modules/@contrail/sdk/lib/config/config.js +13 -7
  92. package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
  93. package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
  94. package/node_modules/@contrail/sdk/lib/entities/entities.client.js +3 -1
  95. package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
  96. package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
  97. package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
  98. package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
  99. package/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
  100. package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
  101. package/node_modules/@contrail/sdk/lib/index.js +1 -0
  102. package/node_modules/@contrail/sdk/package.json +1 -1
  103. package/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
  104. package/oclif.manifest.json +492 -2
  105. package/package.json +6 -12
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findItemsNotInAssortment = exports.createAssortmentItem = void 0;
4
+ const sdk_1 = require("@contrail/sdk");
5
+ const batchFetch_1 = require("./batchFetch");
6
+ const items_1 = require("./items");
7
+ async function createAssortmentItem(assortmentItem, options = {}) {
8
+ const client = new sdk_1.Entities();
9
+ const { assortmentId, itemId } = assortmentItem;
10
+ const { skipHydrateRelationships = false, apiVersion } = options;
11
+ // add item to assortment
12
+ await client.create({
13
+ entityName: 'assortment',
14
+ id: assortmentId,
15
+ relation: 'items',
16
+ object: { itemIds: [itemId] },
17
+ apiVersion,
18
+ });
19
+ // Update assortment item with properties
20
+ const updated = await client.update({
21
+ entityName: 'assortment-item',
22
+ id: `${assortmentId}:${itemId}`,
23
+ object: assortmentItem,
24
+ skipHydrateRelationships,
25
+ apiVersion,
26
+ });
27
+ return updated;
28
+ }
29
+ exports.createAssortmentItem = createAssortmentItem;
30
+ // Methods to find an item not in the assortment
31
+ const ASSORTMENT_ITEMS_CACHE_BY_ASSORTMENT_ID = new Map();
32
+ const ASSORTMENT_ITEMS_CACHE_BY_ITEM_ID = new Map();
33
+ async function cacheAssortmentItemsByAssortmentId(assortmentId) {
34
+ if (!assortmentId) {
35
+ throw new Error('Assortment ID is required to cache assortment items');
36
+ }
37
+ if (ASSORTMENT_ITEMS_CACHE_BY_ASSORTMENT_ID.has(assortmentId)) {
38
+ return; // Already cached
39
+ }
40
+ const assortmentItems = await (0, batchFetch_1.batchFetch)('assortment-item', {
41
+ criteria: { assortmentId },
42
+ propertySlugs: ['id', 'assortmentId', 'itemId'],
43
+ });
44
+ ASSORTMENT_ITEMS_CACHE_BY_ASSORTMENT_ID.set(assortmentId, assortmentItems);
45
+ assortmentItems.forEach((item) => {
46
+ if (!ASSORTMENT_ITEMS_CACHE_BY_ITEM_ID.has(item.itemId)) {
47
+ ASSORTMENT_ITEMS_CACHE_BY_ITEM_ID.set(item.itemId, []);
48
+ }
49
+ ASSORTMENT_ITEMS_CACHE_BY_ITEM_ID.get(item.itemId).push(item);
50
+ });
51
+ }
52
+ async function getAssortmentItemsByAssortmentId(assortmentId) {
53
+ if (!assortmentId) {
54
+ throw new Error('Assortment ID is required to get assortment items');
55
+ }
56
+ await cacheAssortmentItemsByAssortmentId(assortmentId);
57
+ const assortmentItems = ASSORTMENT_ITEMS_CACHE_BY_ASSORTMENT_ID.get(assortmentId);
58
+ if (!assortmentItems) {
59
+ throw new Error(`No assortment items found for assortment ID ${assortmentId}`);
60
+ }
61
+ return assortmentItems;
62
+ }
63
+ async function findItemsNotInAssortment(assortmentId, count) {
64
+ if (!assortmentId) {
65
+ throw new Error('Assortment ID is required to find items not in assortment');
66
+ }
67
+ const assortmentItemsInAssortment = await getAssortmentItemsByAssortmentId(assortmentId);
68
+ const items = await (0, items_1.getManyItems)(count + assortmentItemsInAssortment.length);
69
+ const assortmentItemIds = new Set(assortmentItemsInAssortment.map((ai) => ai.itemId));
70
+ const itemsNotInAssortment = items.filter((item) => !assortmentItemIds.has(item.id));
71
+ if (itemsNotInAssortment.length === 0) {
72
+ throw new Error(`All items are already in assortment ${assortmentId}`);
73
+ }
74
+ return itemsNotInAssortment.sort((a, b) => a.id.localeCompare(b.id)); // sorting ensures consistent order of response
75
+ }
76
+ exports.findItemsNotInAssortment = findItemsNotInAssortment;
@@ -0,0 +1,11 @@
1
+ import { AssortmentItem, ProjectItem } from '@contrail/entity-types';
2
+ import { EntitiesClientGetOptions } from '@contrail/sdk';
3
+ export declare function canBatchFetchEntity(entityName: string): entityName is keyof BatchFetchableEntityMap;
4
+ export interface BatchFetchableEntityMap {
5
+ 'project-item': ProjectItem;
6
+ 'assortment-item': AssortmentItem;
7
+ }
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][]>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.batchFetch = exports.canBatchFetchEntity = void 0;
4
+ const sdk_1 = require("@contrail/sdk");
5
+ const util_1 = require("@contrail/util");
6
+ // Maps entity names to their types for batch fetching.
7
+ // This allows for type-safe batch fetching of entities
8
+ // such that the Type returned always matches the entity name.
9
+ const BATCH_FETCHABLE_ENTITIES = ['assortment-item', 'project-item'];
10
+ function canBatchFetchEntity(entityName) {
11
+ return BATCH_FETCHABLE_ENTITIES.includes(entityName);
12
+ }
13
+ exports.canBatchFetchEntity = canBatchFetchEntity;
14
+ async function batchFetch(entityName, options) {
15
+ const response = await requestBatchFetch(entityName, options);
16
+ return parseBatchFetchResponse(response);
17
+ }
18
+ exports.batchFetch = batchFetch;
19
+ async function requestBatchFetch(entityName, options) {
20
+ const client = new sdk_1.Entities();
21
+ // NOTE: There is probably a helper somewhere else that manages this conversion
22
+ const optionsClone = { ...options };
23
+ if (optionsClone.criteria) {
24
+ optionsClone.where = optionsClone.criteria;
25
+ }
26
+ delete optionsClone.customParams;
27
+ return client.create({
28
+ entityName: entityName,
29
+ suffix: 'batch-fetch',
30
+ object: optionsClone,
31
+ });
32
+ }
33
+ async function parseBatchFetchResponse(response) {
34
+ if ('results' in response) {
35
+ return response.results;
36
+ }
37
+ else if ('resultsCompressedString' in response) {
38
+ const compressedString = response.resultsCompressedString;
39
+ const jsonData = (0, util_1.decompressFromString)(compressedString);
40
+ return jsonData;
41
+ }
42
+ else if ('resultsDownloadUrl' in response) {
43
+ const downloadUrl = response.resultsDownloadUrl;
44
+ const data = await fetch(downloadUrl).then((res) => res.json());
45
+ return data;
46
+ }
47
+ else {
48
+ throw new Error('Invalid batch fetch response format');
49
+ }
50
+ }
@@ -0,0 +1,3 @@
1
+ export * from './assortment-items';
2
+ export * from './items';
3
+ export * from './project-items';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./assortment-items"), exports);
5
+ tslib_1.__exportStar(require("./items"), exports);
6
+ tslib_1.__exportStar(require("./project-items"), exports);
@@ -0,0 +1,6 @@
1
+ import { Item } from '@contrail/entity-types';
2
+ export type SparseItem = Pick<Item, 'id' | 'itemFamilyId' | 'roles' | 'name'>;
3
+ export declare function getManyItems(maxCount?: number): Promise<SparseItem[]>;
4
+ export declare function getItemFamilies(count: number): Promise<SparseItem[] | undefined>;
5
+ export declare const Roles: readonly ["option", "family"];
6
+ export type Role = (typeof Roles)[number];
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Roles = exports.getItemFamilies = exports.getManyItems = void 0;
4
+ const sdk_1 = require("@contrail/sdk");
5
+ const ITEM_FETCH_CEILING = 10000;
6
+ async function getManyItems(maxCount) {
7
+ const client = new sdk_1.Entities();
8
+ const limit = maxCount ?? ITEM_FETCH_CEILING;
9
+ const items = [];
10
+ let nextPageKey = undefined;
11
+ while (true) {
12
+ const response = await client.get({
13
+ entityName: 'item',
14
+ apiVersion: sdk_1.API_VERSION.V2,
15
+ nextPageKey,
16
+ });
17
+ nextPageKey = response.nextPageKey;
18
+ if (response.results.length === 0) {
19
+ break;
20
+ }
21
+ items.push(...response.results);
22
+ if (!nextPageKey) {
23
+ break; // an absent cursor restarts pagination from page one
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
+ }
29
+ break;
30
+ }
31
+ }
32
+ return items;
33
+ }
34
+ exports.getManyItems = getManyItems;
35
+ async function getItemFamilies(count) {
36
+ return getItems({ roles: ['family'] }, count);
37
+ }
38
+ exports.getItemFamilies = getItemFamilies;
39
+ exports.Roles = ['option', 'family'];
40
+ async function getItems(criteria, count = 100) {
41
+ const client = new sdk_1.Entities();
42
+ const items = [];
43
+ let nextPageKey = undefined;
44
+ do {
45
+ const response = await client.get({
46
+ entityName: 'item',
47
+ criteria,
48
+ nextPageKey,
49
+ apiVersion: sdk_1.API_VERSION.V2,
50
+ });
51
+ nextPageKey = response.nextPageKey;
52
+ if (response.results.length === 0) {
53
+ break;
54
+ }
55
+ const numItemsCanBeAdded = count - items.length;
56
+ const itemsToAdd = response.results.slice(0, numItemsCanBeAdded);
57
+ items.push(...itemsToAdd);
58
+ } while (nextPageKey && items.length < count);
59
+ return items;
60
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
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('should stop on the last page rather than refetching the first', async () => {
12
+ mockGet.mockImplementation(async ({ nextPageKey }) => nextPageKey === 'page-2'
13
+ ? { results: [{ id: 'b' }], nextPageKey: undefined }
14
+ : { results: [{ id: 'a' }], nextPageKey: 'page-2' });
15
+ const items = await (0, items_1.getManyItems)(10);
16
+ expect(mockGet).toHaveBeenCalledTimes(2);
17
+ expect(items.map((item) => item.id)).toEqual(['a', 'b']);
18
+ });
19
+ });
@@ -0,0 +1,2 @@
1
+ import { Item } from '@contrail/entity-types';
2
+ export declare function findItemsNotInProject(projectId: string): Promise<Item[]>;
@@ -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 inquirer_1.default.prompt([
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,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;