Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contrail/types

Package Overview
Dependencies
Maintainers
0
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contrail/types - npm Package Compare versions

Comparing version 3.0.68 to 3.0.69

4

lib/copy/copy-helper.d.ts

@@ -7,6 +7,6 @@ import { Type } from "../types";

export declare class CopyHelper {
static buildCopiesOfEntitiesWithLevels(entitiesToCopy: Array<any>, typeMap: {
static buildCopiesOfEntities(entitiesToCopy: Array<any>, typeMap: {
[typeId: string]: Type;
}, propertySlugsToIgnore?: string[]): Array<any>;
static buildCopyOfEntityWithLevels(entityToCopy: any, typeMap: {
static buildCopyOfEntity(entityToCopy: any, typeMap: {
[typeId: string]: Type;

@@ -13,0 +13,0 @@ }, propertySlugsToIgnore?: string[]): any;

@@ -12,7 +12,7 @@ "use strict";

class CopyHelper {
static buildCopiesOfEntitiesWithLevels(entitiesToCopy, typeMap, propertySlugsToIgnore = []) {
const entityCopies = entitiesToCopy.map(entity => this.buildCopyOfEntityWithLevels(entity, typeMap, propertySlugsToIgnore));
static buildCopiesOfEntities(entitiesToCopy, typeMap, propertySlugsToIgnore = []) {
const entityCopies = entitiesToCopy.map(entity => this.buildCopyOfEntity(entity, typeMap, propertySlugsToIgnore));
return entityCopies.filter(entity => !!entity);
}
static buildCopyOfEntityWithLevels(entityToCopy, typeMap, propertySlugsToIgnore = []) {
static buildCopyOfEntity(entityToCopy, typeMap, propertySlugsToIgnore = []) {
if (!entityToCopy) {

@@ -23,11 +23,13 @@ console.warn('Input entity does not have a type.');

const entityType = typeMap[entityToCopy?.typeId];
if (!entityType || !entityType.typeProperties) {
if (!entityType || !entityType.typeProperties || !entityType.typePath) {
console.warn('Entity type not found or has no properties.');
return;
}
const rootType = entityType.typePath.split(':')[0];
const isLeveledEntity = ['item', 'project-item'].includes(rootType);
const isFamilyEntity = entityToCopy.roles?.includes('family');
const isOptionEntity = entityToCopy.roles?.includes('option');
const typeLevel = isFamilyEntity ? 'family' : isOptionEntity ? 'option' : null;
if (!typeLevel) {
console.warn('Only "family" and "option" entities can be copied.');
if (isLeveledEntity && !typeLevel) {
console.warn('Leveled entity does not have assigned role of "family" or "option".');
return;

@@ -50,15 +52,22 @@ }

];
const propertiesToCopy = entityType.typeProperties.filter(property => (property.copyBehavior === type_properties_1.CopyBehavior.Copy || !property.copyBehavior) &&
property.propertyLevel &&
[typeLevel, 'overridable', 'all'].includes(property.propertyLevel) &&
property.propertyType &&
validCopyPropertyTypes.includes(property.propertyType) &&
!property.isUniqueProperty);
const propertiesToDefault = entityType.typeProperties.filter(property => property.copyBehavior === type_properties_1.CopyBehavior.Default &&
property.propertyLevel &&
[typeLevel, 'overridable', 'all'].includes(property.propertyLevel) &&
property.propertyType &&
validCopyPropertyTypes.includes(property.propertyType) &&
!property.isUniqueProperty);
const propertiesToIgnore = [...new Set(...propertySlugsToIgnore, 'id', 'roles', 'specifiedId')];
const propertiesToCopy = entityType.typeProperties.filter(property => {
const isConfiguredToCopy = property.copyBehavior === type_properties_1.CopyBehavior.Copy || !property.copyBehavior;
const doesPropertyLevelMatch = !isLeveledEntity || (property.propertyLevel && [typeLevel, 'overridable', 'all'].includes(property.propertyLevel));
const isPropertyTypeCopyable = property.propertyType && validCopyPropertyTypes.includes(property.propertyType);
return Boolean(isConfiguredToCopy &&
doesPropertyLevelMatch &&
isPropertyTypeCopyable &&
!property.isUniqueProperty);
});
const propertiesToDefault = entityType.typeProperties.filter(property => {
const isConfiguredToDefault = property.copyBehavior === type_properties_1.CopyBehavior.Default;
const doesPropertyLevelMatch = !isLeveledEntity || (property.propertyLevel && [typeLevel, 'overridable', 'all'].includes(property.propertyLevel));
const isPropertyTypeCopyable = property.propertyType && validCopyPropertyTypes.includes(property.propertyType);
return Boolean(isConfiguredToDefault &&
doesPropertyLevelMatch &&
isPropertyTypeCopyable &&
!property.isUniqueProperty);
});
const defaultPropertiesToIgnore = isLeveledEntity ? ['id', 'roles', 'specifiedId'] : ['id', 'specifiedId'];
const propertiesToIgnore = [...new Set(...propertySlugsToIgnore, ...defaultPropertiesToIgnore)];
const copy = {};

@@ -75,10 +84,12 @@ propertiesToCopy.forEach(property => {

});
this.assignCopyMetadata(copy, entityToCopy, isOptionEntity);
this.assignCopyMetadata(copy, entityToCopy);
return copy;
}
static assignCopyMetadata(copyOfEntity, entityToCopy, isOptionEntity) {
static assignCopyMetadata(copyOfEntity, entityToCopy) {
copyOfEntity.createdFromId = entityToCopy.id;
copyOfEntity.createMethod = CopyMethodTypes.QUICK_COPY;
copyOfEntity.typeId = entityToCopy.typeId;
copyOfEntity.roles = entityToCopy.roles;
if (entityToCopy.roles) {
copyOfEntity.roles = entityToCopy.roles;
}
if (entityToCopy.workspaceId) {

@@ -85,0 +96,0 @@ copyOfEntity.workspaceId = entityToCopy.workspaceId;

{
"name": "@contrail/types",
"version": "3.0.68",
"version": "3.0.69",
"description": "Types Utility module",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc