index.d.cts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. export type ObjectDefinition = import("./types.ts").ObjectDefinition;
  2. export type PropertyDefinition = import("./types.ts").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. */
  42. constructor(definitions: ObjectDefinition);
  43. /**
  44. * Determines if a strategy has been registered for the given object key.
  45. * @param {string} key The object key to find a strategy for.
  46. * @returns {boolean} True if the key has a strategy registered, false if not.
  47. */
  48. hasKey(key: string): boolean;
  49. /**
  50. * Merges objects together to create a new object comprised of the keys
  51. * of the all objects. Keys are merged based on the each key's merge
  52. * strategy.
  53. * @param {...Object} objects The objects to merge.
  54. * @returns {Object} A new object with a mix of all objects' keys.
  55. * @throws {Error} If any object is invalid.
  56. */
  57. merge(...objects: any[]): any;
  58. /**
  59. * Validates an object's keys based on the validate strategy for each key.
  60. * @param {Object} object The object to validate.
  61. * @returns {void}
  62. * @throws {Error} When the object is invalid.
  63. */
  64. validate(object: any): void;
  65. #private;
  66. }
  67. /**
  68. * @fileoverview Validation Strategy
  69. */
  70. /**
  71. * Container class for several different validation strategies.
  72. */
  73. export class ValidationStrategy {
  74. /**
  75. * Validates that a value is an array.
  76. * @param {*} value The value to validate.
  77. * @returns {void}
  78. * @throws {TypeError} If the value is invalid.
  79. */
  80. static array(value: any): void;
  81. /**
  82. * Validates that a value is a boolean.
  83. * @param {*} value The value to validate.
  84. * @returns {void}
  85. * @throws {TypeError} If the value is invalid.
  86. */
  87. static boolean(value: any): void;
  88. /**
  89. * Validates that a value is a number.
  90. * @param {*} value The value to validate.
  91. * @returns {void}
  92. * @throws {TypeError} If the value is invalid.
  93. */
  94. static number(value: any): void;
  95. /**
  96. * Validates that a value is a object.
  97. * @param {*} value The value to validate.
  98. * @returns {void}
  99. * @throws {TypeError} If the value is invalid.
  100. */
  101. static object(value: any): void;
  102. /**
  103. * Validates that a value is a object or null.
  104. * @param {*} value The value to validate.
  105. * @returns {void}
  106. * @throws {TypeError} If the value is invalid.
  107. */
  108. static "object?"(value: any): void;
  109. /**
  110. * Validates that a value is a string.
  111. * @param {*} value The value to validate.
  112. * @returns {void}
  113. * @throws {TypeError} If the value is invalid.
  114. */
  115. static string(value: any): void;
  116. /**
  117. * Validates that a value is a non-empty string.
  118. * @param {*} value The value to validate.
  119. * @returns {void}
  120. * @throws {TypeError} If the value is invalid.
  121. */
  122. static "string!"(value: any): void;
  123. }