gtx-cli 2.0.12 → 2.0.13

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - [#505](https://github.com/generaltranslation/gt/pull/505) [`e8c5650`](https://github.com/generaltranslation/gt/commit/e8c5650c163119301d2f9d6b946c0ed8383c57e1) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: json translation for composite arrays where there are multiple default locale items
8
+
3
9
  ## 2.0.12
4
10
 
5
11
  ### Patch Changes
@@ -21,22 +21,21 @@ export function generatePreset(preset) {
21
21
  },
22
22
  },
23
23
  },
24
- // Enable this when support multiple language objects in array
25
- // '$.redirects': {
26
- // type: 'array',
27
- // key: '$.language',
28
- // include: [],
29
- // transform: {
30
- // '$.source': {
31
- // match: '^/{locale}/(.*)$',
32
- // replace: '/{locale}/$1',
33
- // },
34
- // '$.destination': {
35
- // match: '^/{locale}/(.*)$',
36
- // replace: '/{locale}/$1',
37
- // },
38
- // },
39
- // },
24
+ '$.redirects': {
25
+ type: 'array',
26
+ key: '$.language',
27
+ include: [],
28
+ transform: {
29
+ '$.source': {
30
+ match: '^/{locale}/(.*)$',
31
+ replace: '/{locale}/$1',
32
+ },
33
+ '$.destination': {
34
+ match: '^/{locale}/(.*)$',
35
+ replace: '/{locale}/$1',
36
+ },
37
+ },
38
+ },
40
39
  },
41
40
  };
42
41
  default:
@@ -56,7 +56,7 @@ export function flattenJsonWithStringFilter(json, jsonPaths) {
56
56
  }
57
57
  });
58
58
  }
59
- catch (error) {
59
+ catch {
60
60
  logError(`Error with JSONPath pattern: ${jsonPath}`);
61
61
  }
62
62
  }
@@ -3,4 +3,11 @@ export declare function mergeJson(originalContent: string, filePath: string, opt
3
3
  translatedContent: string;
4
4
  targetLocale: string;
5
5
  }[], defaultLocale: string): string[];
6
+ /**
7
+ * Apply transformations to the sourceItem in-place
8
+ * @param sourceItem - The source item to apply transformations to
9
+ * @param transform - The transformations to apply
10
+ * @param targetLocale - The target locale
11
+ * @param defaultLocale - The default locale
12
+ */
6
13
  export declare function applyTransformations(sourceItem: any, transform: SourceObjectOptions['transform'], targetLocale: string, defaultLocale: string): void;
@@ -12,7 +12,7 @@ export function mergeJson(originalContent, filePath, options, targets, defaultLo
12
12
  try {
13
13
  originalJson = JSON.parse(originalContent);
14
14
  }
15
- catch (error) {
15
+ catch {
16
16
  logError(`Invalid JSON file: ${filePath}`);
17
17
  exit(1);
18
18
  }
@@ -55,57 +55,85 @@ export function mergeJson(originalContent, filePath, options, targets, defaultLo
55
55
  exit(1);
56
56
  }
57
57
  // Get source item for default locale
58
- const matchingDefaultLocaleItem = findMatchingItemArray(defaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
59
- if (!matchingDefaultLocaleItem) {
60
- logError(`Matching sourceItem not found at path: ${sourceObjectPointer} for locale: ${defaultLocale}. Please check your JSON schema`);
58
+ const matchingDefaultLocaleItems = findMatchingItemArray(defaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
59
+ if (!Object.keys(matchingDefaultLocaleItems).length) {
60
+ logError(`Matching sourceItems not found at path: ${sourceObjectPointer} for locale: ${defaultLocale}. Please check your JSON schema`);
61
61
  exit(1);
62
62
  }
63
- const { sourceItem: defaultLocaleSourceItem, keyPointer: defaultLocaleKeyPointer, } = matchingDefaultLocaleItem;
63
+ const matchingDefaultLocaleItemKeys = new Set(Object.keys(matchingDefaultLocaleItems));
64
64
  // For each target:
65
- // 1. Validate that the targetJson has a jsonPointer for the current sourceObjectPointer
66
- // 2. If it does, find the source item for the target locale
67
- // 3. Override the source item with the translated values
68
- // 4. Apply additional mutations to the sourceItem
69
- // 5. Merge the source item with the original JSON
65
+ // 1. Get the target items
66
+ // 2. Track all array indecies to remove (will be overwritten)
67
+ // 3. Merge matchingDefaultLocaleItems and targetItems
68
+ // 4. Validate that the mergedItems is not empty
69
+ // For each target item:
70
+ // 5. Validate that all the array indecies are still present in the source json
71
+ // 6. Override the source item with the translated values
72
+ // 7. Apply additional mutations to the sourceItem
73
+ // 8. Track all items to add
74
+ // 9. Check that items to add is >= items to remove
75
+ // 10. Remove all items for the target locale (they can be identified by the key)
76
+ const indiciesToRemove = new Set();
77
+ const itemsToAdd = [];
70
78
  for (const target of targets) {
71
79
  const targetJson = JSON.parse(target.translatedContent);
72
- // 1. Validate that the targetJson has a jsonPointer for the current sourceObjectPointer
73
- if (!targetJson[sourceObjectPointer]) {
80
+ let targetItems = targetJson[sourceObjectPointer];
81
+ // 1. Get the target items
82
+ if (!targetItems) {
83
+ // If no translation can be found, a transformation may need to happen still
84
+ targetItems = {};
85
+ }
86
+ // 2. Track all array indecies to remove (will be overwritten)
87
+ const targetItemsToRemove = findMatchingItemArray(target.targetLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
88
+ Object.values(targetItemsToRemove).forEach(({ index }) => indiciesToRemove.add(index));
89
+ // 3. Merge matchingDefaultLocaleItems and targetItems
90
+ const mergedItems = {
91
+ ...(sourceObjectOptions.transform ? matchingDefaultLocaleItems : {}),
92
+ ...targetItems,
93
+ };
94
+ // 4. Validate that the mergedItems is not empty
95
+ if (Object.keys(mergedItems).length === 0) {
74
96
  logWarning(`Translated JSON for locale: ${target.targetLocale} does not have a valid sourceObjectPointer: ${sourceObjectPointer}. Skipping this target`);
75
97
  continue;
76
98
  }
77
- // 2. Find the source item for the target locale
78
- const matchingTargetItem = findMatchingItemArray(target.targetLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
79
- // If the target locale has a matching source item, use it to mutate the source item
80
- // Otherwise, fallback to the default locale source item
81
- const mutateSourceItem = structuredClone(defaultLocaleSourceItem);
82
- const mutateSourceItemIndex = matchingTargetItem
83
- ? matchingTargetItem.itemIndex
84
- : undefined;
85
- const mutateSourceItemKeyPointer = defaultLocaleKeyPointer;
86
- const { identifyingLocaleProperty: targetLocaleKeyProperty } = getSourceObjectOptionsArray(target.targetLocale, sourceObjectPointer, sourceObjectOptions);
87
- // 3. Override the source item with the translated values
88
- JSONPointer.set(mutateSourceItem, mutateSourceItemKeyPointer, targetLocaleKeyProperty);
89
- for (const [translatedKeyJsonPointer, translatedValue,] of Object.entries(targetJson[sourceObjectPointer] || {})) {
90
- try {
91
- const value = JSONPointer.get(mutateSourceItem, translatedKeyJsonPointer);
92
- if (!value)
93
- continue;
94
- JSONPointer.set(mutateSourceItem, translatedKeyJsonPointer, translatedValue);
99
+ for (const [sourceItemPointer, targetItem] of Object.entries(mergedItems)) {
100
+ // 5. Validate that all the array indecies are still present in the source json
101
+ if (!matchingDefaultLocaleItemKeys.has(sourceItemPointer)) {
102
+ logError(`Array index ${sourceItemPointer} is not present in the source json. It is possible that the source json has been modified since the translation was generated.`);
103
+ exit(1);
95
104
  }
96
- catch (error) { }
97
- }
98
- // 4. Apply additional mutations to the sourceItem
99
- applyTransformations(mutateSourceItem, sourceObjectOptions.transform, target.targetLocale, defaultLocale);
100
- // 5. Merge the source item with the original JSON
101
- if (mutateSourceItemIndex) {
102
- sourceObjectValue[mutateSourceItemIndex] = mutateSourceItem;
103
- }
104
- else {
105
- sourceObjectValue.push(mutateSourceItem);
105
+ // 6. Override the source item with the translated values
106
+ const defaultLocaleSourceItem = matchingDefaultLocaleItems[sourceItemPointer].sourceItem;
107
+ const defaultLocaleKeyPointer = matchingDefaultLocaleItems[sourceItemPointer].keyPointer;
108
+ const mutatedSourceItem = structuredClone(defaultLocaleSourceItem);
109
+ const { identifyingLocaleProperty: targetLocaleKeyProperty } = getSourceObjectOptionsArray(target.targetLocale, sourceObjectPointer, sourceObjectOptions);
110
+ JSONPointer.set(mutatedSourceItem, defaultLocaleKeyPointer, targetLocaleKeyProperty);
111
+ for (const [translatedKeyJsonPointer, translatedValue,] of Object.entries(targetItem || {})) {
112
+ try {
113
+ const value = JSONPointer.get(mutatedSourceItem, translatedKeyJsonPointer);
114
+ if (!value)
115
+ continue;
116
+ JSONPointer.set(mutatedSourceItem, translatedKeyJsonPointer, translatedValue);
117
+ }
118
+ catch {
119
+ /* empty */
120
+ }
121
+ }
122
+ // 7. Apply additional mutations to the sourceItem
123
+ applyTransformations(mutatedSourceItem, sourceObjectOptions.transform, target.targetLocale, defaultLocale);
124
+ itemsToAdd.push(mutatedSourceItem);
106
125
  }
107
126
  }
108
- JSONPointer.set(mergedJson, sourceObjectPointer, sourceObjectValue);
127
+ // 8. Check that items to add is >= items to remove (if this happens, something is very wrong)
128
+ if (itemsToAdd.length < indiciesToRemove.size) {
129
+ logError(`Items to add is less than items to remove at path: ${sourceObjectPointer}. Please check your JSON schema key field.`);
130
+ exit(1);
131
+ }
132
+ // 9. Remove all items for the target locale (they can be identified by the key)
133
+ const filteredSourceObjectValue = sourceObjectValue.filter((_, index) => !indiciesToRemove.has(index));
134
+ // 10. Add all items to the original JSON
135
+ filteredSourceObjectValue.push(...itemsToAdd);
136
+ JSONPointer.set(mergedJson, sourceObjectPointer, filteredSourceObjectValue);
109
137
  }
110
138
  else {
111
139
  // Validate type
@@ -122,17 +150,19 @@ export function mergeJson(originalContent, filePath, options, targets, defaultLo
122
150
  }
123
151
  const { sourceItem: defaultLocaleSourceItem } = matchingDefaultLocaleItem;
124
152
  // For each target:
125
- // 1. Validate that the targetJson has a jsonPointer for the current sourceObjectPointer
126
- // 2. If it does, find the source item for the target locale
127
- // 3. Override the source item with the translated values
128
- // 4. Apply additional mutations to the sourceItem
129
- // 5. Merge the source item with the original JSON
153
+ // 1. Get the target items
154
+ // 2. Find the source item for the target locale
155
+ // 3. Merge the target items with the source item
156
+ // 4. Validate that the mergedItems is not empty
157
+ // 5. Override the source item with the translated values
158
+ // 6. Apply additional mutations to the sourceItem
159
+ // 7. Merge the source item with the original JSON (if the source item is not a new item)
130
160
  for (const target of targets) {
131
161
  const targetJson = JSON.parse(target.translatedContent);
132
- // 1. Validate that the targetJson has a jsonPointer for the current sourceObjectPointer
133
- if (!targetJson[sourceObjectPointer]) {
134
- logWarning(`Translated JSON for locale: ${target.targetLocale} does not have a valid sourceObjectPointer: ${sourceObjectPointer}. Skipping this target`);
135
- continue;
162
+ // 1. Get the target items
163
+ let targetItems = targetJson[sourceObjectPointer];
164
+ if (!targetItems) {
165
+ targetItems = {};
136
166
  }
137
167
  // 2. Find the source item for the target locale
138
168
  const matchingTargetItem = findMatchingItemObject(target.targetLocale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue);
@@ -140,19 +170,31 @@ export function mergeJson(originalContent, filePath, options, targets, defaultLo
140
170
  // Otherwise, fallback to the default locale source item
141
171
  const mutateSourceItem = structuredClone(defaultLocaleSourceItem);
142
172
  const mutateSourceItemKey = matchingTargetItem.keyParentProperty;
143
- // 3. Override the source item with the translated values
144
- for (const [translatedKeyJsonPointer, translatedValue,] of Object.entries(targetJson[sourceObjectPointer] || {})) {
173
+ // 3. Merge the target items with the source item (if there are transformations to perform)
174
+ const mergedItems = {
175
+ ...(sourceObjectOptions.transform ? defaultLocaleSourceItem : {}),
176
+ ...targetItems,
177
+ };
178
+ // 4. Validate that the mergedItems is not empty
179
+ if (Object.keys(mergedItems).length === 0) {
180
+ logWarning(`Translated JSON for locale: ${target.targetLocale} does not have a valid sourceObjectPointer: ${sourceObjectPointer}. Skipping this target`);
181
+ continue;
182
+ }
183
+ // 5. Override the source item with the translated values
184
+ for (const [translatedKeyJsonPointer, translatedValue,] of Object.entries(mergedItems || {})) {
145
185
  try {
146
186
  const value = JSONPointer.get(mutateSourceItem, translatedKeyJsonPointer);
147
187
  if (!value)
148
188
  continue;
149
189
  JSONPointer.set(mutateSourceItem, translatedKeyJsonPointer, translatedValue);
150
190
  }
151
- catch (error) { }
191
+ catch {
192
+ /* empty */
193
+ }
152
194
  }
153
- // 4. Apply additional mutations to the sourceItem
195
+ // 6. Apply additional mutations to the sourceItem
154
196
  applyTransformations(mutateSourceItem, sourceObjectOptions.transform, target.targetLocale, defaultLocale);
155
- // 5. Merge the source item with the original JSON
197
+ // 7. Merge the source item with the original JSON
156
198
  sourceObjectValue[mutateSourceItemKey] = mutateSourceItem;
157
199
  }
158
200
  JSONPointer.set(mergedJson, sourceObjectPointer, sourceObjectValue);
@@ -184,7 +226,13 @@ function replaceLocalePlaceholders(string, localeProperties) {
184
226
  return match;
185
227
  });
186
228
  }
187
- // apply transformations to the sourceItem in-place
229
+ /**
230
+ * Apply transformations to the sourceItem in-place
231
+ * @param sourceItem - The source item to apply transformations to
232
+ * @param transform - The transformations to apply
233
+ * @param targetLocale - The target locale
234
+ * @param defaultLocale - The default locale
235
+ */
188
236
  export function applyTransformations(sourceItem, transform, targetLocale, defaultLocale) {
189
237
  if (!transform)
190
238
  return;
@@ -12,7 +12,7 @@ export function parseJson(content, filePath, options, defaultLocale) {
12
12
  try {
13
13
  json = JSON.parse(content);
14
14
  }
15
- catch (error) {
15
+ catch {
16
16
  logError(`Invalid JSON file: ${filePath}`);
17
17
  exit(1);
18
18
  }
@@ -31,6 +31,10 @@ export function parseJson(content, filePath, options, defaultLocale) {
31
31
  // Construct lvl 2
32
32
  const sourceObjectsToTranslate = {};
33
33
  for (const [sourceObjectPointer, { sourceObjectValue, sourceObjectOptions },] of Object.entries(sourceObjectPointers)) {
34
+ // Skip if no includes
35
+ if (!sourceObjectOptions.include.length) {
36
+ continue;
37
+ }
34
38
  // Find the default locale in each source item in each sourceObjectValue
35
39
  // Array: use key field
36
40
  if (sourceObjectOptions.type === 'array') {
@@ -39,38 +43,45 @@ export function parseJson(content, filePath, options, defaultLocale) {
39
43
  logError(`Source object value is not an array at path: ${sourceObjectPointer}`);
40
44
  exit(1);
41
45
  }
42
- // Validate localeProperty
43
- const matchingItem = findMatchingItemArray(defaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
44
- if (!matchingItem) {
46
+ // Find matching source items
47
+ const matchingItems = findMatchingItemArray(defaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
48
+ if (!Object.keys(matchingItems).length) {
45
49
  logError(`Matching sourceItem not found at path: ${sourceObjectPointer} for locale: ${defaultLocale}. Please check your JSON schema`);
46
50
  exit(1);
47
51
  }
48
- const { sourceItem, keyPointer } = matchingItem;
49
- // Get the fields to translate from the includes
50
- let itemsToTranslate = [];
51
- for (const include of sourceObjectOptions.include) {
52
- try {
53
- const matchingItems = JSONPath({
54
- json: sourceItem,
55
- path: include,
56
- resultType: 'all',
57
- flatten: true,
58
- wrap: true,
59
- });
60
- if (matchingItems) {
61
- itemsToTranslate.push(...matchingItems);
52
+ // Construct lvl 3
53
+ const sourceItemsToTranslate = {};
54
+ for (const [arrayPointer, matchingItem] of Object.entries(matchingItems)) {
55
+ const { sourceItem, keyPointer } = matchingItem;
56
+ // Get the fields to translate from the includes
57
+ const matchingItemsToTranslate = [];
58
+ for (const include of sourceObjectOptions.include) {
59
+ try {
60
+ const matchingItems = JSONPath({
61
+ json: sourceItem,
62
+ path: include,
63
+ resultType: 'all',
64
+ flatten: true,
65
+ wrap: true,
66
+ });
67
+ if (matchingItems) {
68
+ matchingItemsToTranslate.push(...matchingItems);
69
+ }
70
+ }
71
+ catch {
72
+ /* empty */
62
73
  }
63
74
  }
64
- catch (error) { }
75
+ // Filter out the key pointer
76
+ sourceItemsToTranslate[arrayPointer] = Object.fromEntries(matchingItemsToTranslate
77
+ .filter((item) => item.pointer !== keyPointer)
78
+ .map((item) => [
79
+ item.pointer,
80
+ item.value,
81
+ ]));
65
82
  }
66
- itemsToTranslate = Object.fromEntries(itemsToTranslate
67
- .filter((item) => item.pointer !== keyPointer)
68
- .map((item) => [
69
- item.pointer,
70
- item.value,
71
- ]));
72
83
  // Add the items to translate to the result
73
- sourceObjectsToTranslate[sourceObjectPointer] = itemsToTranslate;
84
+ sourceObjectsToTranslate[sourceObjectPointer] = sourceItemsToTranslate;
74
85
  }
75
86
  else {
76
87
  // Object: use the key in this object with the matching locale property
@@ -1,15 +1,29 @@
1
1
  import { AdditionalOptions, JsonSchema, SourceObjectOptions } from '../../types/index.js';
2
- export declare function findMatchingItemArray(locale: string, sourceObjectOptions: SourceObjectOptions, sourceObjectPointer: string, sourceObjectValue: any): {
2
+ export declare function findMatchingItemArray(locale: string, sourceObjectOptions: SourceObjectOptions, sourceObjectPointer: string, sourceObjectValue: any): Record<string, {
3
3
  sourceItem: any;
4
4
  keyParentProperty: string;
5
- itemIndex: number;
6
5
  keyPointer: string;
7
- } | null;
6
+ index: number;
7
+ }>;
8
8
  export declare function findMatchingItemObject(locale: string, sourceObjectPointer: string, sourceObjectOptions: SourceObjectOptions, sourceObjectValue: any): {
9
9
  sourceItem: any | undefined;
10
10
  keyParentProperty: string;
11
11
  };
12
+ /**
13
+ * Get the identifying locale property for an object
14
+ * @param locale - The locale to get the identifying locale property for
15
+ * @param sourceObjectPointer - The path to the source object
16
+ * @param sourceObjectOptions - The source object options
17
+ * @returns The identifying locale property
18
+ */
12
19
  export declare function getIdentifyingLocaleProperty(locale: string, sourceObjectPointer: string, sourceObjectOptions: SourceObjectOptions): string;
20
+ /**
21
+ * Get the identifying locale property and the json path to the key for an array
22
+ * @param locale - The locale to get the identifying locale property for
23
+ * @param sourceObjectPointer - The path to the source object
24
+ * @param sourceObjectOptions - The source object options
25
+ * @returns The identifying locale property and the json path to the key
26
+ */
13
27
  export declare function getSourceObjectOptionsArray(locale: string, sourceObjectPointer: string, sourceObjectOptions: SourceObjectOptions): {
14
28
  identifyingLocaleProperty: string;
15
29
  localeKeyJsonPath: string;
@@ -17,6 +31,13 @@ export declare function getSourceObjectOptionsArray(locale: string, sourceObject
17
31
  export declare function getSourceObjectOptionsObject(defaultLocale: string, sourceObjectPointer: string, sourceObjectOptions: SourceObjectOptions): {
18
32
  identifyingLocaleProperty: string;
19
33
  };
34
+ /**
35
+ * Generate a mapping of sourceObjectPointer to SourceObjectOptions
36
+ * where the sourceObjectPointer is a jsonpointer to the array or object containing
37
+ * @param jsonSchema - The json schema to generate the mapping from
38
+ * @param originalJson - The original json to generate the mapping from
39
+ * @returns A mapping of sourceObjectPointer to SourceObjectOptions
40
+ */
20
41
  export declare function generateSourceObjectPointers(jsonSchema: {
21
42
  [sourceObjectPath: string]: SourceObjectOptions;
22
43
  }, originalJson: any): Record<string, {
@@ -11,6 +11,7 @@ const { isMatch } = micromatch;
11
11
  export function findMatchingItemArray(locale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue) {
12
12
  const { identifyingLocaleProperty, localeKeyJsonPath } = getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions);
13
13
  // Use the json pointer key to locate the source item
14
+ const matchingItems = {};
14
15
  for (const [index, item] of sourceObjectValue.entries()) {
15
16
  // Get the key candidates
16
17
  const keyCandidates = JSONPath({
@@ -24,23 +25,28 @@ export function findMatchingItemArray(locale, sourceObjectOptions, sourceObjectP
24
25
  logError(`Source item at path: ${sourceObjectPointer} does not have a key value at path: ${localeKeyJsonPath}`);
25
26
  exit(1);
26
27
  }
27
- else if (keyCandidates.length !== 1) {
28
+ else if (keyCandidates.length === 0) {
29
+ // If no key candidates, skip the item
30
+ continue;
31
+ }
32
+ else if (keyCandidates.length > 1) {
33
+ // If multiple key candidates, exit with an error
28
34
  logError(`Source item at path: ${sourceObjectPointer} has multiple matching keys with path: ${localeKeyJsonPath}`);
29
35
  exit(1);
30
36
  }
31
- // Validate the key is the identifying locale property
32
- if (!keyCandidates.length ||
33
- identifyingLocaleProperty !== keyCandidates[0].value) {
37
+ else if (identifyingLocaleProperty !== keyCandidates[0].value) {
38
+ // Validate the key is the identifying locale property
34
39
  continue;
35
40
  }
36
- return {
41
+ // Map the index to the source item
42
+ matchingItems[`/${index}`] = {
37
43
  sourceItem: item,
38
44
  keyParentProperty: keyCandidates[0].parentProperty,
39
- itemIndex: index,
40
45
  keyPointer: keyCandidates[0].pointer,
46
+ index,
41
47
  };
42
48
  }
43
- return null;
49
+ return matchingItems;
44
50
  }
45
51
  export function findMatchingItemObject(locale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue) {
46
52
  const { identifyingLocaleProperty } = getSourceObjectOptionsObject(locale, sourceObjectPointer, sourceObjectOptions);
@@ -56,6 +62,13 @@ export function findMatchingItemObject(locale, sourceObjectPointer, sourceObject
56
62
  keyParentProperty: identifyingLocaleProperty,
57
63
  };
58
64
  }
65
+ /**
66
+ * Get the identifying locale property for an object
67
+ * @param locale - The locale to get the identifying locale property for
68
+ * @param sourceObjectPointer - The path to the source object
69
+ * @param sourceObjectOptions - The source object options
70
+ * @returns The identifying locale property
71
+ */
59
72
  export function getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions) {
60
73
  // Validate localeProperty
61
74
  const localeProperty = sourceObjectOptions.localeProperty || 'code';
@@ -66,6 +79,13 @@ export function getIdentifyingLocaleProperty(locale, sourceObjectPointer, source
66
79
  }
67
80
  return identifyingLocaleProperty;
68
81
  }
82
+ /**
83
+ * Get the identifying locale property and the json path to the key for an array
84
+ * @param locale - The locale to get the identifying locale property for
85
+ * @param sourceObjectPointer - The path to the source object
86
+ * @param sourceObjectOptions - The source object options
87
+ * @returns The identifying locale property and the json path to the key
88
+ */
69
89
  export function getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions) {
70
90
  const identifyingLocaleProperty = getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions);
71
91
  const localeKeyJsonPath = sourceObjectOptions.key;
@@ -84,8 +104,13 @@ export function getSourceObjectOptionsObject(defaultLocale, sourceObjectPointer,
84
104
  }
85
105
  return { identifyingLocaleProperty };
86
106
  }
87
- // Generate a mapping of sourceObjectPointer to SourceObjectOptions
88
- // where the sourceObjectPointer is a jsonpointer to the array or object containing
107
+ /**
108
+ * Generate a mapping of sourceObjectPointer to SourceObjectOptions
109
+ * where the sourceObjectPointer is a jsonpointer to the array or object containing
110
+ * @param jsonSchema - The json schema to generate the mapping from
111
+ * @param originalJson - The original json to generate the mapping from
112
+ * @returns A mapping of sourceObjectPointer to SourceObjectOptions
113
+ */
89
114
  export function generateSourceObjectPointers(jsonSchema, originalJson) {
90
115
  const sourceObjectPointers = Object.entries(jsonSchema).reduce((acc, [sourceObjectPath, sourceObjectOptions]) => {
91
116
  const sourceObjects = flattenJson(originalJson, [sourceObjectPath]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.0.12",
3
+ "version": "2.0.13",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [