index.d.cts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. export type ObjectDefinition = $typests.ObjectDefinition;
  2. export type PropertyDefinition = $typests.PropertyDefinition;
  3. /**
  4. * @fileoverview Merge Strategy
  5. */
  6. /**
  7. * Container class for several different merge strategies.
  8. */
  9. export class MergeStrategy {
  10. /**
  11. * Merges two keys by overwriting the first with the second.
  12. * @param {*} value1 The value from the first object key.
  13. * @param {*} value2 The value from the second object key.
  14. * @returns {*} The second value.
  15. */
  16. static overwrite(value1: any, value2: any): any;
  17. /**
  18. * Merges two keys by replacing the first with the second only if the
  19. * second is defined.
  20. * @param {*} value1 The value from the first object key.
  21. * @param {*} value2 The value from the second object key.
  22. * @returns {*} The second value if it is defined.
  23. */
  24. static replace(value1: any, value2: any): any;
  25. /**
  26. * Merges two properties by assigning properties from the second to the first.
  27. * @param {*} value1 The value from the first object key.
  28. * @param {*} value2 The value from the second object key.
  29. * @returns {*} A new object containing properties from both value1 and
  30. * value2.
  31. */
  32. static assign(value1: any, value2: any): any;
  33. }
  34. /**
  35. * Represents an object validation/merging schema.
  36. */
  37. export class ObjectSchema {
  38. /**
  39. * Creates a new instance.
  40. * @param {ObjectDefinition} definitions The schema definitions.
  41. * @throws {Error} When the definitions are missing or invalid.
  42. */
  43. constructor(definitions: ObjectDefinition);
  44. /**
  45. * Determines if a strategy has been registered for the given object key.
  46. * @param {string} key The object key to find a strategy for.
  47. * @returns {boolean} True if the key has a strategy registered, false if not.
  48. */
  49. hasKey(key: string): boolean;
  50. /**
  51. * Merges objects together to create a new object comprised of the keys
  52. * of the all objects. Keys are merged based on the each key's merge
  53. * strategy.
  54. * @param {...Object} objects The objects to merge.
  55. * @returns {Object} A new object with a mix of all objects' keys.
  56. * @throws {TypeError} If any object is invalid.
  57. */
  58. merge(...objects: any[]): any;
  59. /**
  60. * Validates an object's keys based on the validate strategy for each key.
  61. * @param {Object} object The object to validate.
  62. * @returns {void}
  63. * @throws {Error} When the object is invalid.
  64. */
  65. validate(object: any): void;
  66. #private;
  67. }
  68. /**
  69. * @fileoverview Validation Strategy
  70. */
  71. /**
  72. * Container class for several different validation strategies.
  73. */
  74. export class ValidationStrategy {
  75. /**
  76. * Validates that a value is an array.
  77. * @param {*} value The value to validate.
  78. * @returns {void}
  79. * @throws {TypeError} If the value is invalid.
  80. */
  81. static array(value: any): void;
  82. /**
  83. * Validates that a value is a boolean.
  84. * @param {*} value The value to validate.
  85. * @returns {void}
  86. * @throws {TypeError} If the value is invalid.
  87. */
  88. static boolean(value: any): void;
  89. /**
  90. * Validates that a value is a number.
  91. * @param {*} value The value to validate.
  92. * @returns {void}
  93. * @throws {TypeError} If the value is invalid.
  94. */
  95. static number(value: any): void;
  96. /**
  97. * Validates that a value is a object.
  98. * @param {*} value The value to validate.
  99. * @returns {void}
  100. * @throws {TypeError} If the value is invalid.
  101. */
  102. static object(value: any): void;
  103. /**
  104. * Validates that a value is a object or null.
  105. * @param {*} value The value to validate.
  106. * @returns {void}
  107. * @throws {TypeError} If the value is invalid.
  108. */
  109. static "object?"(value: any): void;
  110. /**
  111. * Validates that a value is a string.
  112. * @param {*} value The value to validate.
  113. * @returns {void}
  114. * @throws {TypeError} If the value is invalid.
  115. */
  116. static string(value: any): void;
  117. /**
  118. * Validates that a value is a non-empty string.
  119. * @param {*} value The value to validate.
  120. * @returns {void}
  121. * @throws {TypeError} If the value is invalid.
  122. */
  123. static "string!"(value: any): void;
  124. }
  125. import type * as $typests from "./types.cts";