bruce-models 3.2.6 → 3.2.7

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.
@@ -2977,6 +2977,27 @@ var Entity;
2977
2977
  return null;
2978
2978
  }
2979
2979
  Entity.GetValue = GetValue;
2980
+ /**
2981
+ * Removes a value from an entity.
2982
+ * This will mutate the entity record and run "delete" on the object property.
2983
+ * @param params
2984
+ */
2985
+ function RemoveValue(params) {
2986
+ const { entity: data, path } = params;
2987
+ let curData = data;
2988
+ for (let i = 0; i < path.length; i++) {
2989
+ const step = path[i];
2990
+ if (!curData[step]) {
2991
+ return;
2992
+ }
2993
+ if (i >= path.length - 1) {
2994
+ delete curData[step];
2995
+ return;
2996
+ }
2997
+ curData = curData[step];
2998
+ }
2999
+ }
3000
+ Entity.RemoveValue = RemoveValue;
2980
3001
  /**
2981
3002
  * Calculates an entity's name based on attribute priority set in the type.
2982
3003
  * @param params
@@ -6232,6 +6253,69 @@ var EntityAttribute;
6232
6253
  return GetAttribute(item.Structure, path.slice(1));
6233
6254
  }
6234
6255
  EntityAttribute.GetAttribute = GetAttribute;
6256
+ /**
6257
+ * Removes an attribute from a provided hierarchy of attributes.
6258
+ * Eg: Use the path: ["Bruce", "ID"] to remove the "ID" attribute.
6259
+ * This will mutate the items array.
6260
+ * @param items
6261
+ * @param path
6262
+ */
6263
+ function RemoveAttribute(items, path) {
6264
+ if (!items || !path || !path.length) {
6265
+ return;
6266
+ }
6267
+ const key = path[0];
6268
+ if (path.length === 1) {
6269
+ // If we're at the last key in the path, remove the item from the items array.
6270
+ const index = items.findIndex((i) => i.Key === key);
6271
+ if (index !== -1) {
6272
+ items.splice(index, 1);
6273
+ }
6274
+ return;
6275
+ }
6276
+ // If we're not at the end of the path, dig further.
6277
+ const item = items.find((i) => i.Key === key);
6278
+ if (item && item.Structure) {
6279
+ RemoveAttribute(item.Structure, path.slice(1));
6280
+ }
6281
+ }
6282
+ EntityAttribute.RemoveAttribute = RemoveAttribute;
6283
+ /**
6284
+ * Adds an attribute to a provided hierarchy of attributes.
6285
+ * Eg: Use the path: ["Bruce", "ID"] to add the "ID" attribute.
6286
+ * This will mutate the items array.
6287
+ * This requires the path to be valid and for a parent attribute to exist.
6288
+ * @param items
6289
+ * @param path
6290
+ * @param attribute
6291
+ */
6292
+ function AddAttribute(items, path, attribute) {
6293
+ const key = path[0];
6294
+ if (path.length === 1) {
6295
+ // If we're at the last key in the path, add the attribute to the items array.
6296
+ const index = items.findIndex((i) => i.Key === key);
6297
+ if (index !== -1) {
6298
+ // Overwrite existing attribute if it already exists.
6299
+ items[index] = attribute;
6300
+ }
6301
+ else {
6302
+ // Add new attribute if it doesn't exist.
6303
+ items.push(attribute);
6304
+ }
6305
+ return;
6306
+ }
6307
+ // If we're not at the end of the path, dig further.
6308
+ let item = items.find((i) => i.Key === key);
6309
+ if (!item) {
6310
+ item = { Key: key, Structure: [] };
6311
+ items.push(item);
6312
+ }
6313
+ if (!item.Structure) {
6314
+ item.Structure = [];
6315
+ }
6316
+ AddAttribute(item.Structure, path.slice(1), attribute);
6317
+ }
6318
+ EntityAttribute.AddAttribute = AddAttribute;
6235
6319
  })(EntityAttribute || (EntityAttribute = {}));
6236
6320
 
6237
6321
  /**
@@ -10536,7 +10620,7 @@ var DataSource;
10536
10620
  DataSource.GetList = GetList;
10537
10621
  })(DataSource || (DataSource = {}));
10538
10622
 
10539
- const VERSION = "3.2.6";
10623
+ const VERSION = "3.2.7";
10540
10624
 
10541
10625
  export { VERSION, AnnDocument, CustomForm, AbstractApi, Api, BruceApi, GlobalApi, GuardianApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, LRUCache, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityCoords, EntityTypeVisualSettings, EntityAttribute, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, ProjectViewLegacy, ProjectViewLegacyBookmark, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, Account, AccountInvite, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup, Uploader, Plugin, ENVIRONMENT, DataSource };
10542
10626
  //# sourceMappingURL=bruce-models.es5.js.map