bruce-models 3.2.6 → 3.2.8

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.
@@ -2926,6 +2926,27 @@
2926
2926
  return null;
2927
2927
  }
2928
2928
  Entity.GetValue = GetValue;
2929
+ /**
2930
+ * Removes a value from an entity.
2931
+ * This will mutate the entity record and run "delete" on the object property.
2932
+ * @param params
2933
+ */
2934
+ function RemoveValue(params) {
2935
+ const { entity: data, path } = params;
2936
+ let curData = data;
2937
+ for (let i = 0; i < path.length; i++) {
2938
+ const step = path[i];
2939
+ if (typeof curData != "object" || curData == null) {
2940
+ return;
2941
+ }
2942
+ if (i >= path.length - 1) {
2943
+ delete curData[step];
2944
+ return;
2945
+ }
2946
+ curData = curData[step];
2947
+ }
2948
+ }
2949
+ Entity.RemoveValue = RemoveValue;
2929
2950
  /**
2930
2951
  * Calculates an entity's name based on attribute priority set in the type.
2931
2952
  * @param params
@@ -6096,6 +6117,69 @@
6096
6117
  return GetAttribute(item.Structure, path.slice(1));
6097
6118
  }
6098
6119
  EntityAttribute.GetAttribute = GetAttribute;
6120
+ /**
6121
+ * Removes an attribute from a provided hierarchy of attributes.
6122
+ * Eg: Use the path: ["Bruce", "ID"] to remove the "ID" attribute.
6123
+ * This will mutate the items array.
6124
+ * @param items
6125
+ * @param path
6126
+ */
6127
+ function RemoveAttribute(items, path) {
6128
+ if (!items || !path || !path.length) {
6129
+ return;
6130
+ }
6131
+ const key = path[0];
6132
+ if (path.length === 1) {
6133
+ // If we're at the last key in the path, remove the item from the items array.
6134
+ const index = items.findIndex((i) => i.Key === key);
6135
+ if (index !== -1) {
6136
+ items.splice(index, 1);
6137
+ }
6138
+ return;
6139
+ }
6140
+ // If we're not at the end of the path, dig further.
6141
+ const item = items.find((i) => i.Key === key);
6142
+ if (item && item.Structure) {
6143
+ RemoveAttribute(item.Structure, path.slice(1));
6144
+ }
6145
+ }
6146
+ EntityAttribute.RemoveAttribute = RemoveAttribute;
6147
+ /**
6148
+ * Adds an attribute to a provided hierarchy of attributes.
6149
+ * Eg: Use the path: ["Bruce", "ID"] to add the "ID" attribute.
6150
+ * This will mutate the items array.
6151
+ * This requires the path to be valid and for a parent attribute to exist.
6152
+ * @param items
6153
+ * @param path
6154
+ * @param attribute
6155
+ */
6156
+ function AddAttribute(items, path, attribute) {
6157
+ const key = path[0];
6158
+ if (path.length === 1) {
6159
+ // If we're at the last key in the path, add the attribute to the items array.
6160
+ const index = items.findIndex((i) => i.Key === key);
6161
+ if (index !== -1) {
6162
+ // Overwrite existing attribute if it already exists.
6163
+ items[index] = attribute;
6164
+ }
6165
+ else {
6166
+ // Add new attribute if it doesn't exist.
6167
+ items.push(attribute);
6168
+ }
6169
+ return;
6170
+ }
6171
+ // If we're not at the end of the path, dig further.
6172
+ let item = items.find((i) => i.Key === key);
6173
+ if (!item) {
6174
+ item = { Key: key, Structure: [] };
6175
+ items.push(item);
6176
+ }
6177
+ if (!item.Structure) {
6178
+ item.Structure = [];
6179
+ }
6180
+ AddAttribute(item.Structure, path.slice(1), attribute);
6181
+ }
6182
+ EntityAttribute.AddAttribute = AddAttribute;
6099
6183
  })(exports.EntityAttribute || (exports.EntityAttribute = {}));
6100
6184
 
6101
6185
  (function (Uploader) {
@@ -10283,7 +10367,7 @@
10283
10367
  DataSource.GetList = GetList;
10284
10368
  })(exports.DataSource || (exports.DataSource = {}));
10285
10369
 
10286
- const VERSION = "3.2.6";
10370
+ const VERSION = "3.2.8";
10287
10371
 
10288
10372
  exports.VERSION = VERSION;
10289
10373
  exports.AbstractApi = AbstractApi;