@contrail/cli 3.6.0-alpha.f45f126 → 3.7.0-alpha.51db987
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 -1
- package/dist/api/types.d.ts +35 -0
- package/dist/api/types.js +49 -1
- package/dist/auth/login.d.ts +1 -1
- package/dist/auth/login.js +46 -29
- package/dist/auth/login.spec.js +31 -15
- package/dist/auth/sign-in-error.d.ts +7 -0
- package/dist/auth/sign-in-error.js +24 -0
- package/dist/auth/sign-in-error.spec.d.ts +1 -0
- package/dist/auth/sign-in-error.spec.js +22 -0
- package/dist/auth/sso.d.ts +5 -3
- package/dist/auth/sso.js +34 -18
- package/dist/auth/sso.spec.js +63 -10
- package/dist/basecommand.d.ts +3 -0
- package/dist/basecommand.js +10 -3
- 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.d.ts +1 -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/login.js +1 -1
- 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 -1
- package/package.json +6 -12
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const propertySpecifications_1 = require("./propertySpecifications");
|
|
4
|
+
describe('parsePropertySpecification', () => {
|
|
5
|
+
it('should parse a valid property specification', () => {
|
|
6
|
+
const spec = 'name=john';
|
|
7
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
8
|
+
expect(result).toEqual({
|
|
9
|
+
slug: 'name',
|
|
10
|
+
value: 'john',
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
it('should parse property specification with numeric value', () => {
|
|
14
|
+
const spec = 'id=123';
|
|
15
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
16
|
+
expect(result).toEqual({
|
|
17
|
+
slug: 'id',
|
|
18
|
+
value: '123',
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
it('should parse property specification with hex color value', () => {
|
|
22
|
+
const spec = 'hex=000000';
|
|
23
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
24
|
+
expect(result).toEqual({
|
|
25
|
+
slug: 'hex',
|
|
26
|
+
value: '000000',
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
it('should parse property specification with spaces in value', () => {
|
|
30
|
+
const spec = 'name=john doe';
|
|
31
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
32
|
+
expect(result).toEqual({
|
|
33
|
+
slug: 'name',
|
|
34
|
+
value: 'john doe',
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it('should parse property specification with equals sign in value', () => {
|
|
38
|
+
const spec = 'formula=x=y+z';
|
|
39
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
40
|
+
expect(result).toEqual({
|
|
41
|
+
slug: 'formula',
|
|
42
|
+
value: 'x=y+z',
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it('should parse property specification with empty value', () => {
|
|
46
|
+
const spec = 'description=';
|
|
47
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
48
|
+
expect(result).toEqual({
|
|
49
|
+
slug: 'description',
|
|
50
|
+
value: undefined,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('should distinguish between empty value and empty string', () => {
|
|
54
|
+
const emptySpec = 'description=';
|
|
55
|
+
const emptyStringSpec = 'description=""';
|
|
56
|
+
const emptyResult = (0, propertySpecifications_1.parsePropertySpecification)(emptySpec);
|
|
57
|
+
const emptyStringResult = (0, propertySpecifications_1.parsePropertySpecification)(emptyStringSpec);
|
|
58
|
+
expect(emptyResult).toEqual({
|
|
59
|
+
slug: 'description',
|
|
60
|
+
value: undefined,
|
|
61
|
+
});
|
|
62
|
+
expect(emptyStringResult).toEqual({
|
|
63
|
+
slug: 'description',
|
|
64
|
+
value: '',
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it('should handle both double and single quoted empty strings', () => {
|
|
68
|
+
const doubleQuotedSpec = 'field=""';
|
|
69
|
+
const singleQuotedSpec = "field=''"; // eslint-disable-line quotes
|
|
70
|
+
const doubleQuotedResult = (0, propertySpecifications_1.parsePropertySpecification)(doubleQuotedSpec);
|
|
71
|
+
const singleQuotedResult = (0, propertySpecifications_1.parsePropertySpecification)(singleQuotedSpec);
|
|
72
|
+
expect(doubleQuotedResult).toEqual({
|
|
73
|
+
slug: 'field',
|
|
74
|
+
value: '',
|
|
75
|
+
});
|
|
76
|
+
expect(singleQuotedResult).toEqual({
|
|
77
|
+
slug: 'field',
|
|
78
|
+
value: '',
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
it('should throw error for spec without equals sign', () => {
|
|
82
|
+
const spec = 'invalidspec';
|
|
83
|
+
expect(() => (0, propertySpecifications_1.parsePropertySpecification)(spec)).toThrow('Invalid property specification: invalidspec');
|
|
84
|
+
});
|
|
85
|
+
it('should throw error for spec with only equals sign', () => {
|
|
86
|
+
const spec = '=';
|
|
87
|
+
expect(() => (0, propertySpecifications_1.parsePropertySpecification)(spec)).toThrow('Invalid property specification: =');
|
|
88
|
+
});
|
|
89
|
+
it('should throw error for spec with empty slug', () => {
|
|
90
|
+
const spec = '=value';
|
|
91
|
+
expect(() => (0, propertySpecifications_1.parsePropertySpecification)(spec)).toThrow('Invalid property specification: =value');
|
|
92
|
+
});
|
|
93
|
+
it('should parse property specification with special characters in slug', () => {
|
|
94
|
+
const spec = 'property_name=value';
|
|
95
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
96
|
+
expect(result).toEqual({
|
|
97
|
+
slug: 'property_name',
|
|
98
|
+
value: 'value',
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
it('should parse property specification with hyphenated slug', () => {
|
|
102
|
+
const spec = 'property-name=value';
|
|
103
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
104
|
+
expect(result).toEqual({
|
|
105
|
+
slug: 'property-name',
|
|
106
|
+
value: 'value',
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
describe('parsePropertySpecificationsIntoMap', () => {
|
|
111
|
+
it('should parse multiple property specifications into a map', () => {
|
|
112
|
+
const specs = ['name=obsidian', 'hex=000000', 'id=123'];
|
|
113
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
114
|
+
expect(result).toBeInstanceOf(Map);
|
|
115
|
+
expect(result.get('name')).toBe('obsidian');
|
|
116
|
+
expect(result.get('hex')).toBe('000000');
|
|
117
|
+
expect(result.get('id')).toBe('123');
|
|
118
|
+
expect(result.size).toBe(3);
|
|
119
|
+
});
|
|
120
|
+
it('should handle empty array', () => {
|
|
121
|
+
const specs = [];
|
|
122
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
123
|
+
expect(result).toBeInstanceOf(Map);
|
|
124
|
+
expect(result.size).toBe(0);
|
|
125
|
+
});
|
|
126
|
+
it('should handle single property specification', () => {
|
|
127
|
+
const specs = ['name=john'];
|
|
128
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
129
|
+
expect(result).toBeInstanceOf(Map);
|
|
130
|
+
expect(result.get('name')).toBe('john');
|
|
131
|
+
expect(result.size).toBe(1);
|
|
132
|
+
});
|
|
133
|
+
it('should handle property specifications with complex values', () => {
|
|
134
|
+
const specs = [
|
|
135
|
+
'description=This is a long description with spaces',
|
|
136
|
+
'formula=x=y+z',
|
|
137
|
+
'url=https://example.com',
|
|
138
|
+
];
|
|
139
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
140
|
+
expect(result.get('description')).toBe('This is a long description with spaces');
|
|
141
|
+
expect(result.get('formula')).toBe('x=y+z'); // Now correctly handles multiple equals
|
|
142
|
+
expect(result.get('url')).toBe('https://example.com');
|
|
143
|
+
expect(result.size).toBe(3);
|
|
144
|
+
});
|
|
145
|
+
it('should accumulate repeated keys into an array', () => {
|
|
146
|
+
const specs = ['name=first', 'name=second', 'name=third'];
|
|
147
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
148
|
+
expect(result.get('name')).toEqual(['first', 'second', 'third']);
|
|
149
|
+
expect(result.size).toBe(1);
|
|
150
|
+
});
|
|
151
|
+
it('should keep a single value scalar', () => {
|
|
152
|
+
const specs = ['status=archived'];
|
|
153
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
154
|
+
expect(result.get('status')).toBe('archived');
|
|
155
|
+
});
|
|
156
|
+
it('should handle property specifications with empty values', () => {
|
|
157
|
+
const specs = ['name=john', 'description=', 'notes=""'];
|
|
158
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
159
|
+
expect(result.get('name')).toBe('john');
|
|
160
|
+
expect(result.get('description')).toBeUndefined();
|
|
161
|
+
expect(result.get('notes')).toBe(''); // Empty quotes are converted to empty string
|
|
162
|
+
expect(result.size).toBe(3);
|
|
163
|
+
});
|
|
164
|
+
it('should throw error for invalid property specifications', () => {
|
|
165
|
+
const specs = [
|
|
166
|
+
'name=john',
|
|
167
|
+
'invalid',
|
|
168
|
+
];
|
|
169
|
+
expect(() => (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs)).toThrow('Invalid property specification: invalid');
|
|
170
|
+
});
|
|
171
|
+
it('should build roles arrays from repeated keys, with commas literal', () => {
|
|
172
|
+
const specs = ['roles=option', 'roles=family', 'name=Test'];
|
|
173
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
174
|
+
expect(result.get('roles')).toEqual(['option', 'family']);
|
|
175
|
+
expect(result.get('name')).toBe('Test');
|
|
176
|
+
});
|
|
177
|
+
it('should treat a comma in a roles value as literal', () => {
|
|
178
|
+
const specs = ['roles=option,family'];
|
|
179
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
180
|
+
expect(result.get('roles')).toBe('option,family');
|
|
181
|
+
});
|
|
182
|
+
it('should keep commas literal in ordinary values', () => {
|
|
183
|
+
const specs = ['name=my,name'];
|
|
184
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
185
|
+
expect(result.get('name')).toBe('my,name');
|
|
186
|
+
});
|
|
187
|
+
it('should handle ids as comma-separated array', () => {
|
|
188
|
+
const specs = ['ids=1,2,3', 'name=Test'];
|
|
189
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
190
|
+
expect(result.get('ids')).toEqual(['1', '2', '3']);
|
|
191
|
+
expect(result.get('name')).toBe('Test');
|
|
192
|
+
});
|
|
193
|
+
it('should accumulate repeated ids keys', () => {
|
|
194
|
+
const specs = ['ids=1,2', 'ids=3'];
|
|
195
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
196
|
+
expect(result.get('ids')).toEqual(['1', '2', '3']);
|
|
197
|
+
});
|
|
198
|
+
it('should handle ids as single value', () => {
|
|
199
|
+
const specs = ['ids=123'];
|
|
200
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
201
|
+
expect(result.get('ids')).toEqual(['123']);
|
|
202
|
+
});
|
|
203
|
+
it('should trim whitespace in ids array', () => {
|
|
204
|
+
const specs = ['ids=1, 2, 3, 4'];
|
|
205
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
206
|
+
expect(result.get('ids')).toEqual(['1', '2', '3', '4']);
|
|
207
|
+
});
|
|
208
|
+
it('should not parse roles as array when value is undefined', () => {
|
|
209
|
+
const specs = ['roles='];
|
|
210
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
211
|
+
expect(result.get('roles')).toBeUndefined();
|
|
212
|
+
});
|
|
213
|
+
it('should not parse ids as array when value is undefined', () => {
|
|
214
|
+
const specs = ['ids='];
|
|
215
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
216
|
+
expect(result.get('ids')).toBeUndefined();
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
describe('isValidPropertySpecification', () => {
|
|
220
|
+
it('should return true for valid property specifications', () => {
|
|
221
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('name=john')).toBe(true);
|
|
222
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('id=123')).toBe(true);
|
|
223
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('hex=000000')).toBe(true);
|
|
224
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('description=This is a description')).toBe(true);
|
|
225
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('formula=x=y+z')).toBe(true);
|
|
226
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('property_name=value')).toBe(true);
|
|
227
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('property-name=value')).toBe(true);
|
|
228
|
+
});
|
|
229
|
+
it('should return true for property specifications with empty values', () => {
|
|
230
|
+
// Now implementation should accept empty values
|
|
231
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('description=')).toBe(true);
|
|
232
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('notes=')).toBe(true);
|
|
233
|
+
});
|
|
234
|
+
it('should return false for invalid property specifications', () => {
|
|
235
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('invalid')).toBe(false);
|
|
236
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('')).toBe(false);
|
|
237
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('=')).toBe(false);
|
|
238
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('=value')).toBe(false);
|
|
239
|
+
});
|
|
240
|
+
it('should return false for null or undefined', () => {
|
|
241
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)(null)).toBe(false);
|
|
242
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)(undefined)).toBe(false);
|
|
243
|
+
});
|
|
244
|
+
it('should return false for non-string values', () => {
|
|
245
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)(123)).toBe(false);
|
|
246
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)({})).toBe(false);
|
|
247
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)([])).toBe(false);
|
|
248
|
+
});
|
|
249
|
+
it('should act as type guard', () => {
|
|
250
|
+
const maybeSpec = 'name=john';
|
|
251
|
+
if ((0, propertySpecifications_1.isValidPropertySpecification)(maybeSpec)) {
|
|
252
|
+
// TypeScript should recognize maybeSpec as PropertySpecificationString
|
|
253
|
+
const parsed = (0, propertySpecifications_1.parsePropertySpecification)(maybeSpec);
|
|
254
|
+
expect(parsed.slug).toBe('name');
|
|
255
|
+
expect(parsed.value).toBe('john');
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
describe('integration tests', () => {
|
|
260
|
+
it('should work with the example from the comments', () => {
|
|
261
|
+
// Example: contrail entities get color -- id=123
|
|
262
|
+
const getSpecs = ['id=123'];
|
|
263
|
+
const getMap = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(getSpecs);
|
|
264
|
+
expect(getMap.get('id')).toBe('123');
|
|
265
|
+
expect(getMap.size).toBe(1);
|
|
266
|
+
});
|
|
267
|
+
it('should work with the update example from the comments', () => {
|
|
268
|
+
// Example: contrail entities update color 123 -- name=obsidian hex=000000
|
|
269
|
+
const updateSpecs = ['name=obsidian', 'hex=000000'];
|
|
270
|
+
const updateMap = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(updateSpecs);
|
|
271
|
+
expect(updateMap.get('name')).toBe('obsidian');
|
|
272
|
+
expect(updateMap.get('hex')).toBe('000000');
|
|
273
|
+
expect(updateMap.size).toBe(2);
|
|
274
|
+
});
|
|
275
|
+
it('should handle validation before parsing', () => {
|
|
276
|
+
const userInputs = ['name=john', 'invalid', 'id=123', '=empty'];
|
|
277
|
+
const validSpecs = userInputs.filter(propertySpecifications_1.isValidPropertySpecification);
|
|
278
|
+
expect(validSpecs).toEqual(['name=john', 'id=123']);
|
|
279
|
+
const map = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(validSpecs);
|
|
280
|
+
expect(map.get('name')).toBe('john');
|
|
281
|
+
expect(map.get('id')).toBe('123');
|
|
282
|
+
expect(map.size).toBe(2);
|
|
283
|
+
});
|
|
284
|
+
it('should handle command line parsing issue with empty strings', () => {
|
|
285
|
+
// When user types: contrail entities update color 123 -- description="" notes=''
|
|
286
|
+
// The shell may convert this to: ['description=', 'notes='] or ['description=""', 'notes=\'\'']
|
|
287
|
+
// depending on the shell and escaping
|
|
288
|
+
// Test case 1: Shell strips quotes (common case)
|
|
289
|
+
const shellStrippedSpecs = ['description=', 'notes='];
|
|
290
|
+
const shellStrippedMap = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(shellStrippedSpecs);
|
|
291
|
+
expect(shellStrippedMap.get('description')).toBeUndefined(); // Empty = undefined
|
|
292
|
+
expect(shellStrippedMap.get('notes')).toBeUndefined(); // Empty = undefined
|
|
293
|
+
// Test case 2: Shell preserves quotes (desired case for empty strings)
|
|
294
|
+
const quotedSpecs = ['description=""'];
|
|
295
|
+
const quotedMap = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(quotedSpecs);
|
|
296
|
+
expect(quotedMap.get('description')).toBe(''); // Quoted empty = empty string
|
|
297
|
+
// Test case 3: Mixed usage
|
|
298
|
+
const mixedSpecs = ['name=test', 'description=', 'notes=""'];
|
|
299
|
+
const mixedMap = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(mixedSpecs);
|
|
300
|
+
expect(mixedMap.get('name')).toBe('test');
|
|
301
|
+
expect(mixedMap.get('description')).toBeUndefined(); // Unset
|
|
302
|
+
expect(mixedMap.get('notes')).toBe(''); // Empty string
|
|
303
|
+
expect(mixedMap.size).toBe(3);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
describe('edge cases and limitations', () => {
|
|
307
|
+
it('should handle multiple equals signs correctly', () => {
|
|
308
|
+
// This test shows that multiple equals signs are now handled correctly
|
|
309
|
+
const spec = 'calculation=2+2=4';
|
|
310
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
311
|
+
expect(result).toEqual({
|
|
312
|
+
slug: 'calculation',
|
|
313
|
+
value: '2+2=4', // now preserves everything after first equals
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
it('should handle the specific example equation=x+z=1', () => {
|
|
317
|
+
const spec = 'equation=x+z=1';
|
|
318
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
319
|
+
expect(result).toEqual({
|
|
320
|
+
slug: 'equation',
|
|
321
|
+
value: 'x+z=1',
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
it('should handle mathematical expressions with one equals', () => {
|
|
325
|
+
const spec = 'formula=x+y';
|
|
326
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
327
|
+
expect(result).toEqual({
|
|
328
|
+
slug: 'formula',
|
|
329
|
+
value: 'x+y',
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
it('should handle URLs without equals signs', () => {
|
|
333
|
+
const spec = 'url=https://example.com/path';
|
|
334
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
335
|
+
expect(result).toEqual({
|
|
336
|
+
slug: 'url',
|
|
337
|
+
value: 'https://example.com/path',
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
it('should handle JSON-like values', () => {
|
|
341
|
+
const spec = 'config={"key":"value"}';
|
|
342
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
343
|
+
expect(result).toEqual({
|
|
344
|
+
slug: 'config',
|
|
345
|
+
value: '{"key":"value"}',
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
it('should handle comma-separated values', () => {
|
|
349
|
+
const spec = 'tags=red,blue,green';
|
|
350
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
351
|
+
expect(result).toEqual({
|
|
352
|
+
slug: 'tags',
|
|
353
|
+
value: 'red,blue,green',
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
it('should handle escaped characters', () => {
|
|
357
|
+
const spec = 'message=Hello\\nWorld';
|
|
358
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
359
|
+
expect(result).toEqual({
|
|
360
|
+
slug: 'message',
|
|
361
|
+
value: 'Hello\\nWorld',
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
it('should handle whitespace in slugs', () => {
|
|
365
|
+
// This documents current behavior - spaces in slugs are allowed
|
|
366
|
+
const spec = 'property name=value';
|
|
367
|
+
const result = (0, propertySpecifications_1.parsePropertySpecification)(spec);
|
|
368
|
+
expect(result).toEqual({
|
|
369
|
+
slug: 'property name',
|
|
370
|
+
value: 'value',
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
describe('values containing ..', () => {
|
|
375
|
+
it('should keep them literal, since date ranges resolve in get criteria', () => {
|
|
376
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)([
|
|
377
|
+
'description=Loading...',
|
|
378
|
+
'notes=2025-01-01..2025-12-31',
|
|
379
|
+
]);
|
|
380
|
+
expect(result.get('description')).toBe('Loading...');
|
|
381
|
+
expect(result.get('notes')).toBe('2025-01-01..2025-12-31');
|
|
382
|
+
});
|
|
383
|
+
it('should not discard them during partitioning', () => {
|
|
384
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('description=Loading...')).toBe(true);
|
|
385
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('createdOn=2025-13-50..2025-13-51')).toBe(true);
|
|
386
|
+
});
|
|
387
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns parsed property specification values into the shapes the API expects.
|
|
3
|
+
*
|
|
4
|
+
* Writes cast only from a type definition and never guess, so a wrong value
|
|
5
|
+
* fails loudly rather than being silently rewritten. Reads fall back to the
|
|
6
|
+
* value's own shape for slugs no resolved type defines, because the alternative
|
|
7
|
+
* is a criterion that matches nothing and reports no error.
|
|
8
|
+
*/
|
|
9
|
+
import { PropertyType, TypeProperty } from '@contrail/types';
|
|
10
|
+
export declare function getPropertySlug(property: TypeProperty): string;
|
|
11
|
+
export declare function castValueToPropertyType(value: string | number | string[] | number[], propertyType: PropertyType, propertySlug: string): any;
|
|
12
|
+
/**
|
|
13
|
+
* Coerces a value from its own shape. Only used for reads, and only for slugs
|
|
14
|
+
* no resolved type defines.
|
|
15
|
+
*/
|
|
16
|
+
export declare function inferAndCastValue(value: any): any;
|
|
17
|
+
/**
|
|
18
|
+
* Builds the slug to property type lookup for one or more resolved types.
|
|
19
|
+
* Where two types define the same slug differently the first one given wins.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildPropertyTypeMap(typePropertySets: (TypeProperty[] | undefined)[]): Map<string, PropertyType>;
|
|
22
|
+
/**
|
|
23
|
+
* Casts values for a write. A slug the type does not define is written through
|
|
24
|
+
* unchanged, which is what happens for a property only a subtype declares.
|
|
25
|
+
*/
|
|
26
|
+
export declare function castValuesToPropertyTypes(valueBySlug: Map<string, any>, typeProperties?: TypeProperty[]): Record<string, any>;
|
|
27
|
+
/**
|
|
28
|
+
* Casts values for a read, falling back to the value's own shape so that a
|
|
29
|
+
* criterion on a slug the resolved types do not define still matches.
|
|
30
|
+
*/
|
|
31
|
+
export declare function castCriteriaValues(valueBySlug: Map<string, any>, typePropertySets?: (TypeProperty[] | undefined)[]): Record<string, any>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Turns parsed property specification values into the shapes the API expects.
|
|
4
|
+
*
|
|
5
|
+
* Writes cast only from a type definition and never guess, so a wrong value
|
|
6
|
+
* fails loudly rather than being silently rewritten. Reads fall back to the
|
|
7
|
+
* value's own shape for slugs no resolved type defines, because the alternative
|
|
8
|
+
* is a criterion that matches nothing and reports no error.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.castCriteriaValues = exports.castValuesToPropertyTypes = exports.buildPropertyTypeMap = exports.inferAndCastValue = exports.castValueToPropertyType = exports.getPropertySlug = void 0;
|
|
12
|
+
const types_1 = require("@contrail/types");
|
|
13
|
+
// identifiers are always strings; coercing one would turn a numeric id into a number
|
|
14
|
+
const SLUGS_NEVER_CAST = new Set(['id', 'ids']);
|
|
15
|
+
const ISO_DATE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
16
|
+
function getPropertySlug(property) {
|
|
17
|
+
return property.propertyType === types_1.PropertyType.ObjectReference
|
|
18
|
+
? `${property.slug}Id`
|
|
19
|
+
: property.slug;
|
|
20
|
+
}
|
|
21
|
+
exports.getPropertySlug = getPropertySlug;
|
|
22
|
+
function castValueToPropertyType(value, propertyType, propertySlug) {
|
|
23
|
+
if (Array.isArray(value) && propertyType !== types_1.PropertyType.MultiSelect) {
|
|
24
|
+
return value.map((element) => castValueToPropertyType(element, propertyType, propertySlug));
|
|
25
|
+
}
|
|
26
|
+
switch (propertyType) {
|
|
27
|
+
case types_1.PropertyType.Boolean:
|
|
28
|
+
return value.toString().toLowerCase() === 'true';
|
|
29
|
+
case types_1.PropertyType.Number:
|
|
30
|
+
case types_1.PropertyType.Currency:
|
|
31
|
+
case types_1.PropertyType.Percent:
|
|
32
|
+
case types_1.PropertyType.Rating:
|
|
33
|
+
case types_1.PropertyType.Sequence:
|
|
34
|
+
const numValue = parseFloat(value.toString());
|
|
35
|
+
if (isNaN(numValue)) {
|
|
36
|
+
throw new Error(`Invalid number value: ${value}`);
|
|
37
|
+
}
|
|
38
|
+
return numValue;
|
|
39
|
+
case types_1.PropertyType.Date:
|
|
40
|
+
const date = new Date(value.toString());
|
|
41
|
+
if (isNaN(date.getTime())) {
|
|
42
|
+
throw new Error(`Invalid date value for ${propertySlug}: ${value}`);
|
|
43
|
+
}
|
|
44
|
+
return date.toISOString();
|
|
45
|
+
case types_1.PropertyType.MultiSelect:
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
// the old comma syntax parses as one literal value; warn instead of guessing at a split
|
|
50
|
+
if (typeof value === 'string' && value.includes(',')) {
|
|
51
|
+
console.error(`${propertySlug} value "${value}" contains a comma and is treated as one literal value. To pass several values, repeat the key: ${propertySlug}=${value
|
|
52
|
+
.split(',')
|
|
53
|
+
.join(` ${propertySlug}=`)}`);
|
|
54
|
+
}
|
|
55
|
+
return [value];
|
|
56
|
+
default:
|
|
57
|
+
return value; // For string and other types, return as is
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.castValueToPropertyType = castValueToPropertyType;
|
|
61
|
+
/**
|
|
62
|
+
* Coerces a value from its own shape. Only used for reads, and only for slugs
|
|
63
|
+
* no resolved type defines.
|
|
64
|
+
*/
|
|
65
|
+
function inferAndCastValue(value) {
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
return value.map(inferAndCastValue);
|
|
68
|
+
}
|
|
69
|
+
if (typeof value !== 'string' || value === '') {
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
if (value === 'true')
|
|
73
|
+
return true;
|
|
74
|
+
if (value === 'false')
|
|
75
|
+
return false;
|
|
76
|
+
if (ISO_DATE.test(value) && !isNaN(new Date(value).getTime())) {
|
|
77
|
+
return new Date(value).toISOString();
|
|
78
|
+
}
|
|
79
|
+
// only coerce a number that survives the round trip, so 000000, 007 and 12.50 stay strings
|
|
80
|
+
const asNumber = Number(value);
|
|
81
|
+
return !isNaN(asNumber) && String(asNumber) === value ? asNumber : value;
|
|
82
|
+
}
|
|
83
|
+
exports.inferAndCastValue = inferAndCastValue;
|
|
84
|
+
/**
|
|
85
|
+
* Builds the slug to property type lookup for one or more resolved types.
|
|
86
|
+
* Where two types define the same slug differently the first one given wins.
|
|
87
|
+
*/
|
|
88
|
+
function buildPropertyTypeMap(typePropertySets) {
|
|
89
|
+
const propertyTypeBySlug = new Map();
|
|
90
|
+
for (const typeProperties of typePropertySets) {
|
|
91
|
+
for (const property of typeProperties ?? []) {
|
|
92
|
+
const slug = getPropertySlug(property);
|
|
93
|
+
if (!propertyTypeBySlug.has(slug)) {
|
|
94
|
+
propertyTypeBySlug.set(slug, property.propertyType);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return propertyTypeBySlug;
|
|
99
|
+
}
|
|
100
|
+
exports.buildPropertyTypeMap = buildPropertyTypeMap;
|
|
101
|
+
/**
|
|
102
|
+
* Casts values for a write. A slug the type does not define is written through
|
|
103
|
+
* unchanged, which is what happens for a property only a subtype declares.
|
|
104
|
+
*/
|
|
105
|
+
function castValuesToPropertyTypes(valueBySlug, typeProperties = []) {
|
|
106
|
+
const propertyTypeBySlug = buildPropertyTypeMap([typeProperties]);
|
|
107
|
+
return Object.fromEntries([...valueBySlug.entries()].map(([slug, value]) => [
|
|
108
|
+
slug,
|
|
109
|
+
SLUGS_NEVER_CAST.has(slug) || !propertyTypeBySlug.has(slug)
|
|
110
|
+
? value
|
|
111
|
+
: castValueToPropertyType(value, propertyTypeBySlug.get(slug), slug),
|
|
112
|
+
]));
|
|
113
|
+
}
|
|
114
|
+
exports.castValuesToPropertyTypes = castValuesToPropertyTypes;
|
|
115
|
+
/**
|
|
116
|
+
* Casts values for a read, falling back to the value's own shape so that a
|
|
117
|
+
* criterion on a slug the resolved types do not define still matches.
|
|
118
|
+
*/
|
|
119
|
+
function castCriteriaValues(valueBySlug, typePropertySets = []) {
|
|
120
|
+
const propertyTypeBySlug = buildPropertyTypeMap(typePropertySets);
|
|
121
|
+
return Object.fromEntries([...valueBySlug.entries()].map(([slug, value]) => {
|
|
122
|
+
if (SLUGS_NEVER_CAST.has(slug))
|
|
123
|
+
return [slug, value];
|
|
124
|
+
return [
|
|
125
|
+
slug,
|
|
126
|
+
propertyTypeBySlug.has(slug)
|
|
127
|
+
? castValueToPropertyType(value, propertyTypeBySlug.get(slug), slug)
|
|
128
|
+
: inferAndCastValue(value),
|
|
129
|
+
];
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
exports.castCriteriaValues = castCriteriaValues;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|