@contrail/flexplm 1.0.17 → 1.0.19

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 (47) hide show
  1. package/lib/entity-processor/base-entity-processor.d.ts +30 -30
  2. package/lib/entity-processor/base-entity-processor.js +143 -143
  3. package/lib/flexplm-request.d.ts +3 -3
  4. package/lib/flexplm-request.js +34 -34
  5. package/lib/flexplm-utils.d.ts +5 -5
  6. package/lib/flexplm-utils.js +33 -33
  7. package/lib/index.d.ts +19 -17
  8. package/lib/index.js +35 -33
  9. package/lib/interfaces/interfaces.d.ts +91 -91
  10. package/lib/interfaces/interfaces.js +2 -2
  11. package/lib/interfaces/item-family-changes.d.ts +19 -19
  12. package/lib/interfaces/item-family-changes.js +49 -49
  13. package/lib/interfaces/publish-change-data.d.ts +17 -17
  14. package/lib/interfaces/publish-change-data.js +30 -30
  15. package/lib/publish/base-process-publish-assortment-callback.d.ts +8 -8
  16. package/lib/publish/base-process-publish-assortment-callback.js +19 -19
  17. package/lib/publish/base-process-publish-assortment.d.ts +57 -57
  18. package/lib/publish/base-process-publish-assortment.js +570 -563
  19. package/lib/publish/mockData.d.ts +774 -774
  20. package/lib/publish/mockData.js +3033 -3033
  21. package/lib/util/config-defaults.d.ts +6 -6
  22. package/lib/util/config-defaults.js +71 -71
  23. package/lib/util/data-converter.d.ts +22 -22
  24. package/lib/util/data-converter.js +318 -318
  25. package/lib/util/federation.d.ts +15 -15
  26. package/lib/util/federation.js +149 -149
  27. package/lib/util/flexplm-connect.d.ts +16 -16
  28. package/lib/util/flexplm-connect.js +130 -130
  29. package/lib/util/logger-config.d.ts +1 -1
  30. package/lib/util/logger-config.js +26 -26
  31. package/lib/util/map-util-spec-mockData.d.ts +0 -0
  32. package/lib/util/map-util-spec-mockData.js +203 -0
  33. package/lib/util/map-utils.d.ts +4 -3
  34. package/lib/util/map-utils.js +28 -20
  35. package/lib/util/mockData.d.ts +39 -39
  36. package/lib/util/mockData.js +100 -100
  37. package/lib/util/thumbnail-util.d.ts +15 -15
  38. package/lib/util/thumbnail-util.js +112 -112
  39. package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
  40. package/lib/util/type-conversion-utils-spec-mockData.js +205 -0
  41. package/lib/util/type-conversion-utils.d.ts +10 -0
  42. package/lib/util/type-conversion-utils.js +100 -0
  43. package/lib/util/type-defaults.d.ts +9 -0
  44. package/lib/util/type-defaults.js +117 -0
  45. package/lib/util/type-utils.d.ts +12 -12
  46. package/lib/util/type-utils.js +101 -101
  47. package/package.json +47 -46
@@ -1,318 +1,318 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataConverter = void 0;
4
- const sdk_1 = require("@contrail/sdk");
5
- const type_utils_1 = require("./type-utils");
6
- const transform_data_1 = require("@contrail/transform-data");
7
- const app_framework_1 = require("@contrail/app-framework");
8
- const util_1 = require("@contrail/util");
9
- class DataConverter {
10
- constructor(config, mapFileUtil) {
11
- this.config = config;
12
- this.mapFileUtil = mapFileUtil;
13
- this.useDisplayForEnumerationMatching = false;
14
- this.objRefCache = {};
15
- this.typeUtils = new type_utils_1.TypeUtils();
16
- this.transformMapFile = this.config['transformMapFile'];
17
- this.useDisplayForEnumerationMatching = this.config['dataConverter']
18
- && this.config['dataConverter']['useDisplayForEnumerationMatching'];
19
- }
20
- async getFlexPLMObjectDataFromEvent(event, dataToSkip) {
21
- return this.getFlexPLMObjectData(event.newData, dataToSkip, true);
22
- }
23
- async getFlexPLMObjectData(newData, dataToSkip, expandObjRef) {
24
- if (app_framework_1.Logger.isDebugOn()) {
25
- console.debug('newData: ' + JSON.stringify(newData));
26
- }
27
- dataToSkip = dataToSkip.concat(['updatedOn', 'updatedById', 'createdOn', 'createdById', 'modifiedAt', 'orgId', 'createdAt', 'id', 'typeId', 'workspaceId']);
28
- const data = {};
29
- const typeId = newData?.typeId;
30
- if (!typeId) {
31
- return;
32
- }
33
- data['typePath'] = newData['typePath'];
34
- const type = await this.typeUtils.getTypeById(typeId);
35
- const typeProps = this.typeUtils.filterTypeProperties(type, newData);
36
- for (const prop of typeProps) {
37
- const slug = prop['slug'];
38
- if (dataToSkip.includes(slug)) {
39
- continue;
40
- }
41
- data[slug] = await this.getFlexPLMValue(prop, newData, expandObjRef);
42
- }
43
- if (app_framework_1.Logger.isDebugOn()) {
44
- console.debug('getFlexPLMObjectData-data: ' + JSON.stringify(data));
45
- }
46
- return data;
47
- }
48
- async getFlexPLMValue(prop, newData, expandObjRef) {
49
- const propertyType = prop['propertyType'];
50
- const slug = prop['slug'];
51
- const nd = newData[slug];
52
- let value;
53
- if (['string', 'text'].includes(propertyType)) {
54
- value = nd || '';
55
- }
56
- else if (['number', 'currency', 'percent', 'sequence'].includes(propertyType)) {
57
- value = nd || 0;
58
- }
59
- else if ('date' === propertyType) {
60
- if (nd) {
61
- value = nd;
62
- }
63
- else {
64
- value = null;
65
- }
66
- }
67
- else if ('boolean' === propertyType) {
68
- value = (nd) ? true : false;
69
- }
70
- else if ('choice' === propertyType) {
71
- value = this.getEnumerationValue(prop, nd);
72
- }
73
- else if ('multi_select' === propertyType) {
74
- value = this.getEnumerationValue(prop, nd);
75
- }
76
- else if ('object_reference' === propertyType) {
77
- value = await this.getObjectReferenceValue(prop, newData, expandObjRef);
78
- if (app_framework_1.Logger.isDebugOn()) {
79
- console.debug('object_reference: ' + JSON.stringify(value));
80
- }
81
- }
82
- else if ('image' === propertyType) {
83
- }
84
- else if ('formula' === propertyType) {
85
- value = nd;
86
- }
87
- else if ('json' === propertyType) {
88
- value = nd;
89
- }
90
- return value;
91
- }
92
- getEnumerationValue(prop, nd) {
93
- const propertyType = prop['propertyType'];
94
- let value;
95
- if (['choice', 'multi_select'].includes(propertyType)) {
96
- const options = prop['options'];
97
- if ('choice' === propertyType) {
98
- if (nd) {
99
- const option = options.find(option => option.value == nd);
100
- if (option) {
101
- value = Object.assign({}, option);
102
- }
103
- }
104
- else {
105
- value = {};
106
- }
107
- }
108
- else if ('multi_select' === propertyType) {
109
- value = [];
110
- if (nd instanceof Array) {
111
- nd.forEach(key => {
112
- const optionObject = options.find(option => option.value == key);
113
- if (optionObject) {
114
- const option = Object.assign({}, optionObject);
115
- value.push(option);
116
- }
117
- });
118
- }
119
- else if (typeof nd === 'string' && '' !== nd) {
120
- const optionObject = options.find(option => option.value == nd);
121
- if (optionObject) {
122
- const option = Object.assign({}, optionObject);
123
- value.push(option);
124
- }
125
- }
126
- }
127
- }
128
- return value;
129
- }
130
- async getObjectReferenceValue(prop, newData, expandObjRef = false) {
131
- const slug = prop['slug'];
132
- console.debug('getObjectReferenceValue-prop: ' + slug);
133
- let value = newData[slug];
134
- const entityType = prop['referencedTypeRootSlug'];
135
- const entityId = newData[slug + 'Id'];
136
- if (!value && expandObjRef) {
137
- if (entityId) {
138
- if (this.objRefCache[entityId]) {
139
- console.log('cache hit: ' + entityId);
140
- return this.objRefCache[entityId];
141
- }
142
- const criteria = {
143
- id: entityId
144
- };
145
- const entities = await new sdk_1.Entities().get({
146
- entityName: entityType,
147
- criteria
148
- });
149
- value = (entities && entities[0]) ? entities[0] : undefined;
150
- }
151
- }
152
- if (value) {
153
- const unprocessedValue = value;
154
- const objectClass = this.typeUtils.getEventObjectClass(entityType, newData);
155
- value = await this.getFlexPLMObjectData(value, [], false);
156
- value['entityReference'] = entityType + ':' + entityId;
157
- value['objectClass'] = objectClass;
158
- value['typePath'] = unprocessedValue['typePath'];
159
- if (this.transformMapFile) {
160
- const wholeMap = await this.mapFileUtil.getMapFile(this.transformMapFile);
161
- const objClass = this.getMappingClass(unprocessedValue, wholeMap);
162
- const mapping = await this.mapFileUtil.getMappingSection(this.transformMapFile, objClass, 'vibe2flex');
163
- if (mapping) {
164
- const tasks = transform_data_1.MapFileUtil.getTransformTasks(mapping);
165
- if (tasks.length > 0) {
166
- const convertedArray = transform_data_1.TransformProcessor.transformData([value], tasks);
167
- value = convertedArray[0];
168
- }
169
- }
170
- }
171
- }
172
- else {
173
- value = {};
174
- }
175
- this.objRefCache[entityId] = value;
176
- return value;
177
- }
178
- getMappingClass(entity, mapping) {
179
- const entityTypePath = entity['typePath'];
180
- const typeMapKey = mapping['typeMapKey'];
181
- let objClass = typeMapKey[entityTypePath];
182
- const entityType = entity['entityType'];
183
- if (!objClass) {
184
- objClass = this.typeUtils.getEventObjectClass(entityType, entity);
185
- }
186
- if (!objClass) {
187
- objClass = entityType;
188
- }
189
- return objClass;
190
- }
191
- async setEntityValues(entity, data, keysToSkip = []) {
192
- const type = await this.typeUtils.getTypeById(entity.typeId);
193
- keysToSkip = keysToSkip.concat(['updatedOn', 'updatedById', 'createdOn', 'createdById', 'modifiedAt', 'orgId', 'createdAt', 'id', 'typeId', 'workspaceId']);
194
- let typeProps = this.typeUtils.filterTypeProperties(type, entity);
195
- typeProps = typeProps.filter(prop => !keysToSkip.includes(prop['slug']));
196
- const dataKeys = Object.getOwnPropertyNames(data);
197
- typeProps = typeProps.filter(prop => dataKeys.includes(prop['slug']));
198
- for (const prop of typeProps) {
199
- const slug = prop['slug'];
200
- entity[slug] = await this.getEntityValue(prop, data);
201
- }
202
- return entity;
203
- }
204
- async getEntityValues(objectClass, data, keysToSkip = []) {
205
- const entityValues = {};
206
- const tco = this.typeUtils.getEntityTypeClientOptions(objectClass, data);
207
- const type = await this.typeUtils.getByRootAndPath(tco);
208
- const typePath = type['typePath'];
209
- if (typePath && (typePath.startsWith('item') || typePath.startsWith('project-item'))) {
210
- if (['LCSProduct', 'LCSProductSeasonLink'].includes(objectClass)) {
211
- entityValues['roles'] = ['family'];
212
- }
213
- else {
214
- entityValues['roles'] = ['color', 'option'];
215
- }
216
- }
217
- let typeProps = this.typeUtils.filterTypeProperties(type, entityValues);
218
- typeProps = typeProps.filter(prop => !keysToSkip.includes(prop['slug']));
219
- for (const prop of typeProps) {
220
- const slug = prop['slug'];
221
- const value = await this.getEntityValue(prop, data);
222
- if (value) {
223
- entityValues[slug] = value;
224
- }
225
- }
226
- return entityValues;
227
- }
228
- async getEntityValue(prop, data) {
229
- const propertyType = prop['propertyType'];
230
- const slug = prop['slug'];
231
- const nd = data[slug];
232
- let value;
233
- if (['string', 'text'].includes(propertyType)) {
234
- value = nd;
235
- }
236
- else if (['number', 'currency', 'percent', 'sequence'].includes(propertyType)) {
237
- value = (null === nd) ? 0 : nd;
238
- }
239
- else if ('date' === propertyType) {
240
- if (nd) {
241
- const d = new Date(nd);
242
- value = d.toISOString();
243
- }
244
- else {
245
- value = null;
246
- }
247
- }
248
- else if ('boolean' === propertyType) {
249
- value = (nd) ? true : false;
250
- }
251
- else if ('choice' === propertyType) {
252
- value = this.setEnumerationKeys(prop, nd, this.useDisplayForEnumerationMatching);
253
- }
254
- else if ('multi_select' === propertyType) {
255
- value = this.setEnumerationKeys(prop, nd, this.useDisplayForEnumerationMatching);
256
- }
257
- else if ('object_reference' === propertyType) {
258
- }
259
- else if ('image' === propertyType) {
260
- console.log('TODO');
261
- }
262
- else if ('formula' === propertyType) {
263
- console.log('TODO');
264
- }
265
- else if ('json' === propertyType) {
266
- console.log('TODO');
267
- }
268
- return value;
269
- }
270
- setEnumerationKeys(prop, nd, matchByDisplay) {
271
- const propertyType = prop['propertyType'];
272
- let value;
273
- if (['choice', 'multi_select'].includes(propertyType)) {
274
- const options = prop['options'];
275
- if ('choice' === propertyType) {
276
- if (nd) {
277
- const matchKey = (matchByDisplay) ? 'display' : 'value';
278
- const option = options.find(option => option[matchKey] == nd[matchKey]);
279
- if (option) {
280
- value = option.value;
281
- }
282
- }
283
- else {
284
- value = undefined;
285
- }
286
- }
287
- else if ('multi_select' === propertyType) {
288
- value = [];
289
- const matchKey = (matchByDisplay) ? 'display' : 'value';
290
- if (nd instanceof Array) {
291
- nd.forEach(selectedOpt => {
292
- const optionObject = options.find(option => option[matchKey] == selectedOpt[matchKey]);
293
- if (optionObject) {
294
- const option = optionObject.value;
295
- value.push(option);
296
- }
297
- });
298
- }
299
- }
300
- }
301
- return value;
302
- }
303
- getPersistableChanges(entity, changes) {
304
- const entityCompareValues = {};
305
- for (const key of (Object.getOwnPropertyNames(changes))) {
306
- entityCompareValues[key] = entity[key];
307
- }
308
- const diffs = util_1.ObjectUtil.compareDeep(entityCompareValues, changes, '');
309
- const diffValues = {};
310
- if (diffs && diffs.length > 0) {
311
- for (const diff of diffs) {
312
- diffValues[diff.propertyName] = diff.newValue;
313
- }
314
- }
315
- return diffValues;
316
- }
317
- }
318
- exports.DataConverter = DataConverter;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataConverter = void 0;
4
+ const sdk_1 = require("@contrail/sdk");
5
+ const type_utils_1 = require("./type-utils");
6
+ const transform_data_1 = require("@contrail/transform-data");
7
+ const app_framework_1 = require("@contrail/app-framework");
8
+ const util_1 = require("@contrail/util");
9
+ class DataConverter {
10
+ constructor(config, mapFileUtil) {
11
+ this.config = config;
12
+ this.mapFileUtil = mapFileUtil;
13
+ this.useDisplayForEnumerationMatching = false;
14
+ this.objRefCache = {};
15
+ this.typeUtils = new type_utils_1.TypeUtils();
16
+ this.transformMapFile = this.config['transformMapFile'];
17
+ this.useDisplayForEnumerationMatching = this.config['dataConverter']
18
+ && this.config['dataConverter']['useDisplayForEnumerationMatching'];
19
+ }
20
+ async getFlexPLMObjectDataFromEvent(event, dataToSkip) {
21
+ return this.getFlexPLMObjectData(event.newData, dataToSkip, true);
22
+ }
23
+ async getFlexPLMObjectData(newData, dataToSkip, expandObjRef) {
24
+ if (app_framework_1.Logger.isDebugOn()) {
25
+ console.debug('newData: ' + JSON.stringify(newData));
26
+ }
27
+ dataToSkip = dataToSkip.concat(['updatedOn', 'updatedById', 'createdOn', 'createdById', 'modifiedAt', 'orgId', 'createdAt', 'id', 'typeId', 'workspaceId']);
28
+ const data = {};
29
+ const typeId = newData?.typeId;
30
+ if (!typeId) {
31
+ return;
32
+ }
33
+ data['typePath'] = newData['typePath'];
34
+ const type = await this.typeUtils.getTypeById(typeId);
35
+ const typeProps = this.typeUtils.filterTypeProperties(type, newData);
36
+ for (const prop of typeProps) {
37
+ const slug = prop['slug'];
38
+ if (dataToSkip.includes(slug)) {
39
+ continue;
40
+ }
41
+ data[slug] = await this.getFlexPLMValue(prop, newData, expandObjRef);
42
+ }
43
+ if (app_framework_1.Logger.isDebugOn()) {
44
+ console.debug('getFlexPLMObjectData-data: ' + JSON.stringify(data));
45
+ }
46
+ return data;
47
+ }
48
+ async getFlexPLMValue(prop, newData, expandObjRef) {
49
+ const propertyType = prop['propertyType'];
50
+ const slug = prop['slug'];
51
+ const nd = newData[slug];
52
+ let value;
53
+ if (['string', 'text'].includes(propertyType)) {
54
+ value = nd || '';
55
+ }
56
+ else if (['number', 'currency', 'percent', 'sequence'].includes(propertyType)) {
57
+ value = nd || 0;
58
+ }
59
+ else if ('date' === propertyType) {
60
+ if (nd) {
61
+ value = nd;
62
+ }
63
+ else {
64
+ value = null;
65
+ }
66
+ }
67
+ else if ('boolean' === propertyType) {
68
+ value = (nd) ? true : false;
69
+ }
70
+ else if ('choice' === propertyType) {
71
+ value = this.getEnumerationValue(prop, nd);
72
+ }
73
+ else if ('multi_select' === propertyType) {
74
+ value = this.getEnumerationValue(prop, nd);
75
+ }
76
+ else if ('object_reference' === propertyType) {
77
+ value = await this.getObjectReferenceValue(prop, newData, expandObjRef);
78
+ if (app_framework_1.Logger.isDebugOn()) {
79
+ console.debug('object_reference: ' + JSON.stringify(value));
80
+ }
81
+ }
82
+ else if ('image' === propertyType) {
83
+ }
84
+ else if ('formula' === propertyType) {
85
+ value = nd;
86
+ }
87
+ else if ('json' === propertyType) {
88
+ value = nd;
89
+ }
90
+ return value;
91
+ }
92
+ getEnumerationValue(prop, nd) {
93
+ const propertyType = prop['propertyType'];
94
+ let value;
95
+ if (['choice', 'multi_select'].includes(propertyType)) {
96
+ const options = prop['options'];
97
+ if ('choice' === propertyType) {
98
+ if (nd) {
99
+ const option = options.find(option => option.value == nd);
100
+ if (option) {
101
+ value = Object.assign({}, option);
102
+ }
103
+ }
104
+ else {
105
+ value = {};
106
+ }
107
+ }
108
+ else if ('multi_select' === propertyType) {
109
+ value = [];
110
+ if (nd instanceof Array) {
111
+ nd.forEach(key => {
112
+ const optionObject = options.find(option => option.value == key);
113
+ if (optionObject) {
114
+ const option = Object.assign({}, optionObject);
115
+ value.push(option);
116
+ }
117
+ });
118
+ }
119
+ else if (typeof nd === 'string' && '' !== nd) {
120
+ const optionObject = options.find(option => option.value == nd);
121
+ if (optionObject) {
122
+ const option = Object.assign({}, optionObject);
123
+ value.push(option);
124
+ }
125
+ }
126
+ }
127
+ }
128
+ return value;
129
+ }
130
+ async getObjectReferenceValue(prop, newData, expandObjRef = false) {
131
+ const slug = prop['slug'];
132
+ console.debug('getObjectReferenceValue-prop: ' + slug);
133
+ let value = newData[slug];
134
+ const entityType = prop['referencedTypeRootSlug'];
135
+ const entityId = newData[slug + 'Id'];
136
+ if ((!value || typeof value === 'string') && expandObjRef) {
137
+ if (entityId) {
138
+ if (this.objRefCache[entityId]) {
139
+ console.log('cache hit: ' + entityId);
140
+ return this.objRefCache[entityId];
141
+ }
142
+ const criteria = {
143
+ id: entityId
144
+ };
145
+ const entities = await new sdk_1.Entities().get({
146
+ entityName: entityType,
147
+ criteria
148
+ });
149
+ value = (entities && entities[0]) ? entities[0] : undefined;
150
+ }
151
+ }
152
+ if (value && !(typeof value === 'string')) {
153
+ const unprocessedValue = value;
154
+ const objectClass = this.typeUtils.getEventObjectClass(entityType, newData);
155
+ value = await this.getFlexPLMObjectData(value, [], false);
156
+ value['entityReference'] = entityType + ':' + entityId;
157
+ value['objectClass'] = objectClass;
158
+ value['typePath'] = unprocessedValue['typePath'];
159
+ if (this.transformMapFile) {
160
+ const wholeMap = await this.mapFileUtil.getMapFile(this.transformMapFile);
161
+ const objClass = this.getMappingClass(unprocessedValue, wholeMap);
162
+ const mapping = await this.mapFileUtil.getMappingSection(this.transformMapFile, objClass, 'vibe2flex');
163
+ if (mapping) {
164
+ const tasks = transform_data_1.MapFileUtil.getTransformTasks(mapping);
165
+ if (tasks.length > 0) {
166
+ const convertedArray = transform_data_1.TransformProcessor.transformData([value], tasks);
167
+ value = convertedArray[0];
168
+ }
169
+ }
170
+ }
171
+ }
172
+ else {
173
+ value = {};
174
+ }
175
+ this.objRefCache[entityId] = value;
176
+ return value;
177
+ }
178
+ getMappingClass(entity, mapping) {
179
+ const entityTypePath = entity['typePath'];
180
+ const typeMapKey = mapping['typeMapKey'];
181
+ let objClass = typeMapKey[entityTypePath];
182
+ const entityType = entity['entityType'];
183
+ if (!objClass) {
184
+ objClass = this.typeUtils.getEventObjectClass(entityType, entity);
185
+ }
186
+ if (!objClass) {
187
+ objClass = entityType;
188
+ }
189
+ return objClass;
190
+ }
191
+ async setEntityValues(entity, data, keysToSkip = []) {
192
+ const type = await this.typeUtils.getTypeById(entity.typeId);
193
+ keysToSkip = keysToSkip.concat(['updatedOn', 'updatedById', 'createdOn', 'createdById', 'modifiedAt', 'orgId', 'createdAt', 'id', 'typeId', 'workspaceId']);
194
+ let typeProps = this.typeUtils.filterTypeProperties(type, entity);
195
+ typeProps = typeProps.filter(prop => !keysToSkip.includes(prop['slug']));
196
+ const dataKeys = Object.getOwnPropertyNames(data);
197
+ typeProps = typeProps.filter(prop => dataKeys.includes(prop['slug']));
198
+ for (const prop of typeProps) {
199
+ const slug = prop['slug'];
200
+ entity[slug] = await this.getEntityValue(prop, data);
201
+ }
202
+ return entity;
203
+ }
204
+ async getEntityValues(objectClass, data, keysToSkip = []) {
205
+ const entityValues = {};
206
+ const tco = this.typeUtils.getEntityTypeClientOptions(objectClass, data);
207
+ const type = await this.typeUtils.getByRootAndPath(tco);
208
+ const typePath = type['typePath'];
209
+ if (typePath && (typePath.startsWith('item') || typePath.startsWith('project-item'))) {
210
+ if (['LCSProduct', 'LCSProductSeasonLink'].includes(objectClass)) {
211
+ entityValues['roles'] = ['family'];
212
+ }
213
+ else {
214
+ entityValues['roles'] = ['color', 'option'];
215
+ }
216
+ }
217
+ let typeProps = this.typeUtils.filterTypeProperties(type, entityValues);
218
+ typeProps = typeProps.filter(prop => !keysToSkip.includes(prop['slug']));
219
+ for (const prop of typeProps) {
220
+ const slug = prop['slug'];
221
+ const value = await this.getEntityValue(prop, data);
222
+ if (value) {
223
+ entityValues[slug] = value;
224
+ }
225
+ }
226
+ return entityValues;
227
+ }
228
+ async getEntityValue(prop, data) {
229
+ const propertyType = prop['propertyType'];
230
+ const slug = prop['slug'];
231
+ const nd = data[slug];
232
+ let value;
233
+ if (['string', 'text'].includes(propertyType)) {
234
+ value = nd;
235
+ }
236
+ else if (['number', 'currency', 'percent', 'sequence'].includes(propertyType)) {
237
+ value = (null === nd) ? 0 : nd;
238
+ }
239
+ else if ('date' === propertyType) {
240
+ if (nd) {
241
+ const d = new Date(nd);
242
+ value = d.toISOString();
243
+ }
244
+ else {
245
+ value = null;
246
+ }
247
+ }
248
+ else if ('boolean' === propertyType) {
249
+ value = (nd) ? true : false;
250
+ }
251
+ else if ('choice' === propertyType) {
252
+ value = this.setEnumerationKeys(prop, nd, this.useDisplayForEnumerationMatching);
253
+ }
254
+ else if ('multi_select' === propertyType) {
255
+ value = this.setEnumerationKeys(prop, nd, this.useDisplayForEnumerationMatching);
256
+ }
257
+ else if ('object_reference' === propertyType) {
258
+ }
259
+ else if ('image' === propertyType) {
260
+ console.log('TODO');
261
+ }
262
+ else if ('formula' === propertyType) {
263
+ console.log('TODO');
264
+ }
265
+ else if ('json' === propertyType) {
266
+ console.log('TODO');
267
+ }
268
+ return value;
269
+ }
270
+ setEnumerationKeys(prop, nd, matchByDisplay) {
271
+ const propertyType = prop['propertyType'];
272
+ let value;
273
+ if (['choice', 'multi_select'].includes(propertyType)) {
274
+ const options = prop['options'] || [];
275
+ if ('choice' === propertyType) {
276
+ if (nd) {
277
+ const matchKey = (matchByDisplay) ? 'display' : 'value';
278
+ const option = options.find(option => option[matchKey] == nd[matchKey]);
279
+ if (option) {
280
+ value = option.value;
281
+ }
282
+ }
283
+ else {
284
+ value = undefined;
285
+ }
286
+ }
287
+ else if ('multi_select' === propertyType) {
288
+ value = [];
289
+ const matchKey = (matchByDisplay) ? 'display' : 'value';
290
+ if (nd instanceof Array) {
291
+ nd.forEach(selectedOpt => {
292
+ const optionObject = options.find(option => option[matchKey] == selectedOpt[matchKey]);
293
+ if (optionObject) {
294
+ const option = optionObject.value;
295
+ value.push(option);
296
+ }
297
+ });
298
+ }
299
+ }
300
+ }
301
+ return value;
302
+ }
303
+ getPersistableChanges(entity, changes) {
304
+ const entityCompareValues = {};
305
+ for (const key of (Object.getOwnPropertyNames(changes))) {
306
+ entityCompareValues[key] = entity[key];
307
+ }
308
+ const diffs = util_1.ObjectUtil.compareDeep(entityCompareValues, changes, '');
309
+ const diffValues = {};
310
+ if (diffs && diffs.length > 0) {
311
+ for (const diff of diffs) {
312
+ diffValues[diff.propertyName] = diff.newValue;
313
+ }
314
+ }
315
+ return diffValues;
316
+ }
317
+ }
318
+ exports.DataConverter = DataConverter;