mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-04 04:28:08 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
		
			708 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			708 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/**
 | 
						|
 * Copyright (c) HashiCorp, Inc.
 | 
						|
 * SPDX-License-Identifier: BUSL-1.1
 | 
						|
 */
 | 
						|
 | 
						|
import Transform from '@ember-data/serializer/transform';
 | 
						|
 | 
						|
/**
 | 
						|
 * transforms array types from the server to a comma separated string
 | 
						|
 * useful when using changedAttributes() in the serializer to track attribute changes for PATCH requests
 | 
						|
 * because arrays are not trackable and strings are!
 | 
						|
 */
 | 
						|
export default class CommaString extends Transform {
 | 
						|
  deserialize(serialized) {
 | 
						|
    if (Array.isArray(serialized)) {
 | 
						|
      return serialized.join(',');
 | 
						|
    }
 | 
						|
    return serialized;
 | 
						|
  }
 | 
						|
 | 
						|
  serialize(deserialized) {
 | 
						|
    if (typeof deserialized === 'string') {
 | 
						|
      return deserialized.split(',');
 | 
						|
    }
 | 
						|
    return deserialized;
 | 
						|
  }
 | 
						|
}
 |