@builttocreate/engine-utils 2.10.1-beta.v593.28 → 2.10.1-beta.v593.4
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/dist/fieldHelper.js +1 -40
- package/dist/generateReadableId.js +5 -35
- package/dist/joyDocHelper.js +2 -3
- package/dist/validateReadableId.js +1 -47
- package/package.json +1 -1
package/dist/fieldHelper.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.isTargetOptionDeleted = exports.isFieldEmpty = exports.handleMultiSelectOptionToggle = exports.getTemplateWithLookups = exports.getMultiSelectFieldValue = exports.getImportFieldValues = exports.getDefaultOption = exports.getDefaultFieldValuesFromTemplate = exports.getChartFieldValue = exports
|
|
7
|
+
exports.isTargetOptionDeleted = exports.isFieldEmpty = exports.handleMultiSelectOptionToggle = exports.getTemplateWithLookups = exports.getMultiSelectFieldValue = exports.getImportFieldValues = exports.getDefaultOption = exports.getDefaultFieldValuesFromTemplate = exports.getChartFieldValue = exports["default"] = void 0;
|
|
8
8
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
@@ -298,45 +298,6 @@ var isTargetOptionDeleted = exports.isTargetOptionDeleted = function isTargetOpt
|
|
|
298
298
|
var result = !(undeletedOptions.length > 0);
|
|
299
299
|
return result;
|
|
300
300
|
};
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
*
|
|
304
|
-
* Flattens a nested schema tree into an array of objects and adds a depth property to each object.
|
|
305
|
-
*
|
|
306
|
-
* @param {Object} schemaObj
|
|
307
|
-
* @returns {Array} // An array of objects with the schema's id, depth, and other properties.
|
|
308
|
-
*/
|
|
309
|
-
var flattenSchemaTree = exports.flattenSchemaTree = function flattenSchemaTree(schemaObj) {
|
|
310
|
-
var flattened = [];
|
|
311
|
-
|
|
312
|
-
// Recursive function to traverse the tree.
|
|
313
|
-
function traverse(schemaId, depth, parentId) {
|
|
314
|
-
var node = schemaObj[schemaId];
|
|
315
|
-
if (!node) return;
|
|
316
|
-
|
|
317
|
-
// Create a new object that includes the schema's id and its depth.
|
|
318
|
-
flattened.push(_objectSpread({
|
|
319
|
-
id: schemaId,
|
|
320
|
-
parentId: parentId,
|
|
321
|
-
depth: depth
|
|
322
|
-
}, node));
|
|
323
|
-
|
|
324
|
-
// If the node has children, traverse them with increased depth.
|
|
325
|
-
if (node.children && node.children.length > 0) {
|
|
326
|
-
node.children.forEach(function (childId) {
|
|
327
|
-
return traverse(childId, depth + 1, schemaId);
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Find and traverse each root node.
|
|
333
|
-
Object.keys(schemaObj).forEach(function (schemaId) {
|
|
334
|
-
if (schemaObj[schemaId].root) {
|
|
335
|
-
traverse(schemaId, 0);
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
return flattened;
|
|
339
|
-
};
|
|
340
301
|
var _default = exports["default"] = {
|
|
341
302
|
getDefaultOption: getDefaultOption,
|
|
342
303
|
getChartFieldValue: getChartFieldValue,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -9,7 +8,6 @@ exports.generateReadableTableColumnId = generateReadableTableColumnId;
|
|
|
9
8
|
exports.getFieldPositionsCount = getFieldPositionsCount;
|
|
10
9
|
exports.getFieldsCount = getFieldsCount;
|
|
11
10
|
exports.getViewsFieldPositionsCount = getViewsFieldPositionsCount;
|
|
12
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
11
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
14
12
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
13
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; }
|
|
@@ -114,20 +112,13 @@ function generateReadableId(parts, type) {
|
|
|
114
112
|
throw new Error('generateReadableId: at least one of fields, pages, or views is required');
|
|
115
113
|
}
|
|
116
114
|
if (!fields) console.warn('generateReadableId: fields parameter is missing');
|
|
117
|
-
|
|
115
|
+
var count = 0;
|
|
116
|
+
if (fields) count += getFieldsCount(fields, type);
|
|
118
117
|
// Note: leaving for now until we allow targeting fieldPositions
|
|
119
118
|
// if (pages) count += getFieldPositionsCount(pages, type);
|
|
120
119
|
// if (views && views.length > 1) count += getViewsFieldPositionsCount(views, type);
|
|
121
120
|
|
|
122
|
-
|
|
123
|
-
var readableId = "".concat(type).concat(splitterId).concat(count + 1);
|
|
124
|
-
while (fields.some(function (field) {
|
|
125
|
-
return field._id === readableId;
|
|
126
|
-
})) {
|
|
127
|
-
count++;
|
|
128
|
-
readableId = "".concat(type).concat(splitterId).concat(count + 1);
|
|
129
|
-
}
|
|
130
|
-
return readableId;
|
|
121
|
+
return "".concat(type).concat(splitterId).concat(count + 1);
|
|
131
122
|
}
|
|
132
123
|
;
|
|
133
124
|
|
|
@@ -139,11 +130,8 @@ function generateReadableId(parts, type) {
|
|
|
139
130
|
* @returns {String} - An ID in the format "{tableId}Column{count+1}" (e.g. "table1Column1")
|
|
140
131
|
*/
|
|
141
132
|
function generateReadableTableColumnId(tableId, tableColumns, columnId) {
|
|
142
|
-
//Add logic that ensures that created Id is not a duplicate
|
|
143
133
|
if (!tableId) throw new Error('generateReadableTableColumnId: tableId is required');
|
|
144
|
-
if (!columnId) throw new Error('generateReadableTableColumnId: columnId is required');
|
|
145
134
|
if (!tableColumns || !Array.isArray(tableColumns)) {
|
|
146
|
-
console.warn('generateReadableTableColumnId: tableColumns parameter is missing or not an array');
|
|
147
135
|
return "".concat(tableId, "Column1");
|
|
148
136
|
}
|
|
149
137
|
var counts = {};
|
|
@@ -155,31 +143,13 @@ function generateReadableTableColumnId(tableId, tableColumns, columnId) {
|
|
|
155
143
|
var _iterator = _createForOfIteratorHelper(validColumns),
|
|
156
144
|
_step;
|
|
157
145
|
try {
|
|
158
|
-
|
|
146
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
159
147
|
var col = _step.value;
|
|
160
148
|
var type = (col.type || 'unknown').toLowerCase();
|
|
161
149
|
counts[type] = (counts[type] || 0) + 1;
|
|
162
|
-
var readableId = "".concat(type).concat(counts[type]);
|
|
163
150
|
if (col._id === columnId) {
|
|
164
|
-
|
|
165
|
-
* If the generatedReadableId is already present in the tableColumns,
|
|
166
|
-
* we need to increment the count until we find a unique ID.
|
|
167
|
-
* This ensures that the new column ID is unique.
|
|
168
|
-
*/
|
|
169
|
-
while (validColumns.some(function (column) {
|
|
170
|
-
return column._id === readableId;
|
|
171
|
-
})) {
|
|
172
|
-
counts[type]++;
|
|
173
|
-
readableId = "".concat(type).concat(counts[type]);
|
|
174
|
-
}
|
|
175
|
-
return {
|
|
176
|
-
v: readableId
|
|
177
|
-
};
|
|
151
|
+
return "".concat(type).concat(counts[type]);
|
|
178
152
|
}
|
|
179
|
-
};
|
|
180
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
181
|
-
var _ret = _loop();
|
|
182
|
-
if ((0, _typeof2["default"])(_ret) === "object") return _ret.v;
|
|
183
153
|
}
|
|
184
154
|
} catch (err) {
|
|
185
155
|
_iterator.e(err);
|
package/dist/joyDocHelper.js
CHANGED
|
@@ -100,12 +100,11 @@ var getDefaultJoyDoc = exports.getDefaultJoyDoc = function getDefaultJoyDoc() {
|
|
|
100
100
|
*/
|
|
101
101
|
var getFieldId = function getFieldId(existingId, type, doc) {
|
|
102
102
|
// If existing ID is a valid ObjectId or readableId, maintain it
|
|
103
|
-
//Note: readableId validation is already done when it's being generated
|
|
104
|
-
|
|
105
103
|
if (existingId && (0, _validateObjectId["default"])(existingId)) {
|
|
106
104
|
return existingId;
|
|
105
|
+
} else if (existingId && (0, _validateReadableId["default"])(existingId)) {
|
|
106
|
+
return existingId;
|
|
107
107
|
}
|
|
108
|
-
if (existingId) return existingId;
|
|
109
108
|
|
|
110
109
|
// Otherwise, generate a readable ID
|
|
111
110
|
if (type) {
|
|
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
|
-
var _fieldHelper = require("./fieldHelper");
|
|
11
|
-
var _FieldTypes = _interopRequireDefault(require("./constants/FieldTypes"));
|
|
12
10
|
// Check if value follows a valid readableId pattern for use in JavaScript formulas
|
|
13
11
|
// Note to test this please run npm test src/validateReadableId.test.js
|
|
14
12
|
|
|
@@ -83,7 +81,7 @@ var JOYDOC_PROPERTIES = new Set(['_id', 'identifier', 'name', 'type', 'files', '
|
|
|
83
81
|
* @param {*} readableId - The ID to validate
|
|
84
82
|
* @returns {boolean} - True if valid, false otherwise
|
|
85
83
|
*/
|
|
86
|
-
var _default = exports["default"] = function _default(readableId
|
|
84
|
+
var _default = exports["default"] = function _default(readableId) {
|
|
87
85
|
// Must be a non-empty string
|
|
88
86
|
if (typeof readableId !== 'string' || readableId.length === 0) {
|
|
89
87
|
console.warn("validateReadableId: Invalid input - expected non-empty string, got ".concat(typeof readableId === 'string' ? 'empty string' : (0, _typeof2["default"])(readableId)));
|
|
@@ -144,49 +142,5 @@ var _default = exports["default"] = function _default(readableId, fields, tableC
|
|
|
144
142
|
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it's an Excel function name"));
|
|
145
143
|
return false;
|
|
146
144
|
}
|
|
147
|
-
|
|
148
|
-
//6. Check for duplicates in readableIds
|
|
149
|
-
|
|
150
|
-
if (Array.isArray(fields)) {
|
|
151
|
-
//DuplicateId check for fieldIds
|
|
152
|
-
var duplicateField = fields.find(function (field) {
|
|
153
|
-
return field._id === readableId;
|
|
154
|
-
});
|
|
155
|
-
if (duplicateField) {
|
|
156
|
-
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it already exists in fields"));
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* DuplicateId check for nested tables of collection fields
|
|
162
|
-
* When readableIds for nestedTables are passed in, we need the fieldId to retrieve the collection fields that houses the nestedTable
|
|
163
|
-
*/
|
|
164
|
-
if (fieldId) {
|
|
165
|
-
var targetField = fields.find(function (field) {
|
|
166
|
-
return field._id === fieldId;
|
|
167
|
-
});
|
|
168
|
-
if ((targetField === null || targetField === void 0 ? void 0 : targetField.type) === _FieldTypes["default"].collection) {
|
|
169
|
-
var flattenedSchema = (0, _fieldHelper.flattenSchemaTree)(targetField.schema);
|
|
170
|
-
var readableIdExists = flattenedSchema.some(function (schema) {
|
|
171
|
-
return schema.id === readableId;
|
|
172
|
-
});
|
|
173
|
-
if (readableIdExists) {
|
|
174
|
-
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it already exists in fields"));
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
//DuplicateId check for columnIds
|
|
182
|
-
if (tableColumns && Array.isArray(tableColumns)) {
|
|
183
|
-
var duplicateColumnId = tableColumns.find(function (column) {
|
|
184
|
-
return column._id === readableId;
|
|
185
|
-
});
|
|
186
|
-
if (duplicateColumnId) {
|
|
187
|
-
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it already exists in fields"));
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
145
|
return true;
|
|
192
146
|
};
|