Source: models/File.js

  1. var assign = require('object-assign');
  2. var Node = require('./Node');
  3. require('../polyfill');
  4. /**
  5. * Create a file from the server's object representation.
  6. *
  7. * @param {Object} obj Data from the server, which doesn't follow typical
  8. * javaScript naming conventions.
  9. * @constructor
  10. * @memberof models
  11. */
  12. function File(obj) {
  13. this._data = obj || {};
  14. var self = this;
  15. Object.defineProperties(this, {
  16. /**
  17. * The absolute depot path of the file
  18. *
  19. * @type string
  20. * @name models.File#depotFile
  21. * @memberOf models.File
  22. */
  23. 'depotFile': {
  24. get: function() {
  25. return self._data['DepotFile'];
  26. },
  27. set: function(x) {
  28. self._data['DepotFile'] = x;
  29. }
  30. },
  31. /**
  32. * File's revision number.
  33. *
  34. * @type number
  35. * @name models.File#revision
  36. * @memberOf models.File
  37. * @readonly
  38. */
  39. 'revision': {
  40. get: function() {
  41. var n = self._data['Revision'];
  42. if (typeof n == 'string') {
  43. n = parseInt(n);
  44. }
  45. return n;
  46. }
  47. },
  48. /**
  49. * ID of the changelist that created this file revision.
  50. *
  51. * @type string
  52. * @name models.File#change
  53. * @memberOf models.File
  54. * @readonly
  55. */
  56. 'change': {
  57. get: function() {
  58. return self._data['Change'];
  59. }
  60. },
  61. /**
  62. * Action taken at the head, one of 'add', 'edit', 'delete', 'branch',
  63. * 'move_add', 'move_delete', 'integrate', 'import', 'purge', or 'archive'.
  64. *
  65. * @type string
  66. * @name models.File#action
  67. * @memberOf models.File
  68. * @readonly
  69. */
  70. 'action': {
  71. get: function() {
  72. return self._data['Action'];
  73. }
  74. },
  75. /**
  76. * File type - one of 'text', 'binary', 'symlink', 'apple', 'resource',
  77. * 'unicode', 'utf16'
  78. *
  79. * @type string
  80. * @name models.File#type
  81. * @memberOf models.File
  82. * @readonly
  83. */
  84. 'type': {
  85. get: function() {
  86. return self._data['Type'];
  87. }
  88. },
  89. /**
  90. * Date of when the file revision was created
  91. *
  92. * @type Date
  93. * @name models.File#date
  94. * @memberOf models.File
  95. * @readonly
  96. */
  97. 'date': {
  98. get: function() {
  99. return new Date(self._data['Date']);
  100. }
  101. },
  102. /**
  103. * For consistency with Node operations
  104. *
  105. * @type string
  106. * @name models.File#name
  107. * @memberOf models.File
  108. * @readonly
  109. */
  110. 'name': {
  111. get: function() {
  112. return this.pathId[this.pathId.length - 1];
  113. }
  114. },
  115. /**
  116. * For consistency with Node operations
  117. *
  118. * @type Array<string>
  119. * @name models.File#pathId
  120. * @memberOf models.File
  121. * @readonly
  122. */
  123. 'pathId': {
  124. get: function() {
  125. var path = this.depotFile;
  126. if (path.startsWith('//')) {
  127. path = path.substring(2);
  128. }
  129. return path.split('/');
  130. }
  131. }
  132. });
  133. }
  134. assign(File.prototype, Node, {
  135. });
  136. module.exports = File;