@builttocreate/engine-utils 2.8.0-beta.9 → 2.9.0

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.
@@ -101,7 +101,8 @@ var getDefaultJoyDoc = exports.getDefaultJoyDoc = function getDefaultJoyDoc() {
101
101
  */
102
102
  var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc) {
103
103
  if (!doc) return getDefaultJoyDoc();
104
- var nextDoc = removeOrphanedFieldsFromJoydoc(doc);
104
+ var _removeOrphanedFields = removeOrphanedFieldsFromJoydoc(doc),
105
+ nextDoc = _removeOrphanedFields.nextDoc;
105
106
 
106
107
  /**
107
108
  * Step 1.1: Replace doc._id if it is not valid
@@ -161,58 +162,9 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
161
162
  * Remove orphaned fields from doc
162
163
  */
163
164
 
164
- // export const removeOrphanedFieldsFromJoydoc = (doc) => {
165
-
166
- // const nextDoc = { ...doc };
167
-
168
- // /**
169
- // * Logic below removes orphaned fields (ie fields without fieldPositions)
170
- // */
171
-
172
- // nextDoc.fields = nextDoc.fields.filter((field) => {
173
-
174
- // let isOrphanedField = true;
175
-
176
- // nextDoc.files.forEach((file) => {
177
-
178
- // const primaryViewPages = file.pages;
179
-
180
- // // Check if field is associated with any field positions in primary view pages
181
- // const isFieldAssociatedWithPrimaryView = primaryViewPages.some((page) => {
182
- // return page.fieldPositions.some((fieldPosition) => fieldPosition.field === field._id);
183
- // });
184
-
185
- // // Check if field is associated with other views
186
- // let isFieldAssociatedWithAnotherView;
187
-
188
- // if (file.views && file.views.length > 0) {
189
-
190
- // isFieldAssociatedWithAnotherView = file.views.some((view) => {
191
- // return view.pages.some((page) => {
192
- // return page.fieldPositions.some((fieldPosition) => fieldPosition.field === field._id);
193
- // });
194
- // });
195
-
196
- // }
197
-
198
- // if (isFieldAssociatedWithPrimaryView || isFieldAssociatedWithAnotherView) {
199
- // isOrphanedField = false;
200
- // }
201
-
202
- // });
203
-
204
- // if (!isOrphanedField) return field;
205
-
206
- // return null;
207
-
208
- // });
209
-
210
- // return nextDoc;
211
-
212
- // };
213
-
214
165
  var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = function removeOrphanedFieldsFromJoydoc(doc) {
215
166
  var _nextDoc$files;
167
+ if (!doc) return getDefaultJoyDoc();
216
168
  var nextDoc = _objectSpread({}, doc);
217
169
  var associatedFieldIdLookup = {};
218
170
  nextDoc === null || nextDoc === void 0 ? void 0 : (_nextDoc$files = nextDoc.files) === null || _nextDoc$files === void 0 ? void 0 : _nextDoc$files.forEach(function (file) {
@@ -221,7 +173,7 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
221
173
  * Primary view
222
174
  */
223
175
  file.pages.forEach(function (page) {
224
- page.fieldPositions.forEach(function (fieldPosition) {
176
+ page === null || page === void 0 ? void 0 : page.fieldPositions.forEach(function (fieldPosition) {
225
177
  return associatedFieldIdLookup[fieldPosition.field] = true;
226
178
  });
227
179
  });
@@ -249,7 +201,7 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
249
201
  });
250
202
  nextDoc.fields = validFields;
251
203
  return {
252
- doc: nextDoc,
204
+ nextDoc: nextDoc,
253
205
  deletedFields: deletedFields
254
206
  };
255
207
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builttocreate/engine-utils",
3
- "version": "2.8.0-beta.9",
3
+ "version": "2.9.0",
4
4
  "description": "Utility library for common logic shared across web and mobile",
5
5
  "main": "dist/index.js",
6
6
  "files": [