@dereekb/util 13.0.7 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/fetch/package.json +2 -2
  2. package/index.cjs.js +4107 -1516
  3. package/index.esm.js +4107 -1516
  4. package/package.json +1 -2
  5. package/src/lib/array/array.d.ts +92 -47
  6. package/src/lib/array/array.find.d.ts +14 -18
  7. package/src/lib/array/array.index.d.ts +43 -14
  8. package/src/lib/array/array.indexed.d.ts +66 -17
  9. package/src/lib/array/array.limit.d.ts +11 -0
  10. package/src/lib/array/array.make.d.ts +9 -3
  11. package/src/lib/array/array.map.d.ts +20 -8
  12. package/src/lib/array/array.number.d.ts +63 -5
  13. package/src/lib/array/array.random.d.ts +12 -9
  14. package/src/lib/array/array.set.d.ts +24 -1
  15. package/src/lib/array/array.string.d.ts +104 -0
  16. package/src/lib/array/array.unique.d.ts +60 -8
  17. package/src/lib/array/array.value.d.ts +20 -11
  18. package/src/lib/assertion/assertion.d.ts +30 -2
  19. package/src/lib/assertion/assertion.generic.d.ts +8 -0
  20. package/src/lib/assertion/assertion.number.d.ts +16 -0
  21. package/src/lib/auth/auth.role.claims.d.ts +14 -8
  22. package/src/lib/boolean.d.ts +54 -1
  23. package/src/lib/contact/domain.d.ts +22 -4
  24. package/src/lib/contact/random.d.ts +24 -0
  25. package/src/lib/date/date.d.ts +8 -13
  26. package/src/lib/date/hour.d.ts +51 -32
  27. package/src/lib/date/minute.d.ts +4 -4
  28. package/src/lib/date/time.d.ts +12 -3
  29. package/src/lib/date/week.d.ts +77 -10
  30. package/src/lib/error/error.d.ts +54 -3
  31. package/src/lib/error/error.server.d.ts +25 -2
  32. package/src/lib/filter/filter.d.ts +12 -7
  33. package/src/lib/function/function.boolean.d.ts +4 -4
  34. package/src/lib/function/function.d.ts +2 -5
  35. package/src/lib/function/function.forward.d.ts +19 -3
  36. package/src/lib/getter/getter.cache.d.ts +9 -5
  37. package/src/lib/getter/getter.d.ts +39 -22
  38. package/src/lib/getter/getter.map.d.ts +10 -4
  39. package/src/lib/getter/getter.util.d.ts +3 -3
  40. package/src/lib/grouping.d.ts +98 -31
  41. package/src/lib/hash.d.ts +15 -8
  42. package/src/lib/iterable/iterable.d.ts +62 -50
  43. package/src/lib/iterable/iterable.map.d.ts +4 -4
  44. package/src/lib/iterate.d.ts +17 -1
  45. package/src/lib/key.d.ts +32 -10
  46. package/src/lib/lifecycle.d.ts +10 -1
  47. package/src/lib/map/map.d.ts +17 -16
  48. package/src/lib/map/map.intersection.d.ts +5 -4
  49. package/src/lib/map/map.key.d.ts +16 -15
  50. package/src/lib/misc/host.d.ts +6 -3
  51. package/src/lib/model/id.batch.d.ts +7 -3
  52. package/src/lib/model/id.factory.d.ts +16 -1
  53. package/src/lib/model/model.conversion.d.ts +49 -6
  54. package/src/lib/model/model.conversion.field.d.ts +13 -3
  55. package/src/lib/model/model.copy.d.ts +11 -0
  56. package/src/lib/model/model.d.ts +174 -1
  57. package/src/lib/model/model.modify.d.ts +24 -5
  58. package/src/lib/nodejs/stream.d.ts +8 -6
  59. package/src/lib/number/bitwise.dencoder.d.ts +43 -3
  60. package/src/lib/number/bound.d.ts +34 -5
  61. package/src/lib/number/dollar.d.ts +13 -6
  62. package/src/lib/number/factory.d.ts +11 -3
  63. package/src/lib/number/number.d.ts +55 -32
  64. package/src/lib/number/random.d.ts +13 -3
  65. package/src/lib/number/round.d.ts +47 -26
  66. package/src/lib/number/sort.d.ts +7 -1
  67. package/src/lib/number/transform.d.ts +16 -0
  68. package/src/lib/object/object.array.d.ts +16 -2
  69. package/src/lib/object/object.array.delta.d.ts +6 -2
  70. package/src/lib/object/object.d.ts +33 -5
  71. package/src/lib/object/object.empty.d.ts +4 -2
  72. package/src/lib/object/object.equal.d.ts +21 -4
  73. package/src/lib/object/object.filter.tuple.d.ts +105 -3
  74. package/src/lib/object/object.key.d.ts +13 -6
  75. package/src/lib/object/object.map.d.ts +30 -19
  76. package/src/lib/page/page.d.ts +21 -0
  77. package/src/lib/page/page.filter.d.ts +16 -9
  78. package/src/lib/path/path.d.ts +101 -14
  79. package/src/lib/path/path.tree.d.ts +16 -0
  80. package/src/lib/promise/callback.d.ts +18 -0
  81. package/src/lib/promise/is.d.ts +10 -3
  82. package/src/lib/promise/map.d.ts +5 -3
  83. package/src/lib/promise/poll.d.ts +14 -4
  84. package/src/lib/promise/promise.d.ts +84 -18
  85. package/src/lib/promise/promise.factory.d.ts +18 -2
  86. package/src/lib/promise/promise.limit.d.ts +22 -2
  87. package/src/lib/promise/promise.loop.d.ts +69 -1
  88. package/src/lib/promise/promise.ref.d.ts +14 -2
  89. package/src/lib/promise/promise.task.d.ts +8 -4
  90. package/src/lib/promise/promise.type.d.ts +4 -4
  91. package/src/lib/promise/use.d.ts +6 -4
  92. package/src/lib/promise/wait.d.ts +5 -2
  93. package/src/lib/relation/relation.d.ts +98 -0
  94. package/src/lib/service/handler.config.d.ts +47 -9
  95. package/src/lib/service/handler.d.ts +43 -1
  96. package/src/lib/service/typed.service.d.ts +21 -2
  97. package/src/lib/set/set.allowed.d.ts +6 -4
  98. package/src/lib/set/set.d.ts +174 -46
  99. package/src/lib/set/set.decision.d.ts +4 -2
  100. package/src/lib/set/set.delta.d.ts +16 -3
  101. package/src/lib/set/set.hashset.d.ts +43 -0
  102. package/src/lib/set/set.selection.d.ts +7 -3
  103. package/src/lib/sort.d.ts +36 -16
  104. package/src/lib/string/char.d.ts +48 -34
  105. package/src/lib/string/dencoder.d.ts +84 -13
  106. package/src/lib/string/factory.d.ts +13 -4
  107. package/src/lib/string/html.d.ts +7 -6
  108. package/src/lib/string/mimetype.d.ts +65 -1
  109. package/src/lib/string/prefix.d.ts +21 -7
  110. package/src/lib/string/record.d.ts +7 -4
  111. package/src/lib/string/replace.d.ts +77 -33
  112. package/src/lib/string/search.d.ts +19 -9
  113. package/src/lib/string/sort.d.ts +10 -1
  114. package/src/lib/string/string.d.ts +74 -21
  115. package/src/lib/string/transform.d.ts +7 -0
  116. package/src/lib/string/tree.d.ts +91 -29
  117. package/src/lib/string/url.d.ts +148 -63
  118. package/src/lib/tree/tree.explore.d.ts +84 -17
  119. package/src/lib/tree/tree.flatten.d.ts +44 -7
  120. package/src/lib/type.d.ts +15 -12
  121. package/src/lib/value/address.d.ts +66 -17
  122. package/src/lib/value/bound.d.ts +253 -17
  123. package/src/lib/value/build.d.ts +30 -5
  124. package/src/lib/value/comparator.d.ts +53 -25
  125. package/src/lib/value/cron.d.ts +14 -6
  126. package/src/lib/value/decision.d.ts +57 -13
  127. package/src/lib/value/equal.d.ts +44 -13
  128. package/src/lib/value/indexed.d.ts +253 -82
  129. package/src/lib/value/label.d.ts +16 -5
  130. package/src/lib/value/map.d.ts +77 -20
  131. package/src/lib/value/maybe.d.ts +47 -49
  132. package/src/lib/value/modifier.d.ts +82 -27
  133. package/src/lib/value/point.d.ts +248 -54
  134. package/src/lib/value/url.d.ts +10 -3
  135. package/src/lib/value/use.d.ts +99 -8
  136. package/src/lib/value/vector.d.ts +71 -9
  137. package/test/index.cjs.js +86 -23
  138. package/test/index.esm.js +86 -23
  139. package/test/package.json +2 -2
  140. package/test/src/lib/shared/shared.d.ts +31 -5
  141. package/test/src/lib/shared/shared.fail.d.ts +72 -9
  142. package/test/src/lib/shared/shared.function.d.ts +40 -2
  143. package/test/src/lib/shared/shared.wrap.d.ts +20 -1
@@ -1,40 +1,102 @@
1
1
  import { type Maybe } from './maybe.type';
2
+ /**
3
+ * A 2D point or size with x and y components.
4
+ */
2
5
  export interface Vector {
3
6
  x: number;
4
7
  y: number;
5
8
  }
9
+ /**
10
+ * A {@link Vector} represented as a `[x, y]` tuple.
11
+ */
6
12
  export type VectorTuple = [number, number];
13
+ /**
14
+ * Safely compares two optional vectors for equality.
15
+ *
16
+ * If both values are non-nullish, delegates to {@link vectorsAreEqual}.
17
+ * If both are nullish, uses strict equality (`===`).
18
+ *
19
+ * @param a - first vector
20
+ * @param b - second vector
21
+ */
7
22
  export declare function isSameVector(a: Maybe<Partial<Vector>>, b: Maybe<Partial<Vector>>): boolean;
23
+ /**
24
+ * Returns `true` if both vectors have the same `x` and `y` values using strict equality.
25
+ *
26
+ * @param a - first vector
27
+ * @param b - second vector
28
+ */
8
29
  export declare function vectorsAreEqual(a: Partial<Vector>, b: Partial<Vector>): boolean;
9
30
  /**
10
- * Function that resizes a vector.
31
+ * Function that transforms a {@link Vector} into a new vector, typically used for resizing or clamping dimensions.
11
32
  */
12
33
  export type VectorResizeFunction = (input: Vector) => Vector;
13
34
  /**
14
- * Creates a VectorResizeFunction that returns the larger x/y values from the input and the minimum vector.
35
+ * Creates a {@link VectorResizeFunction} that enforces minimum x/y dimensions.
15
36
  *
16
- * @param min
17
- * @returns
37
+ * For each axis, if a minimum is specified, the result uses whichever value is larger (input or minimum).
38
+ * If a minimum is not specified for an axis, the input value is passed through unchanged.
39
+ *
40
+ * @param minSize - the minimum dimensions to enforce
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const resize = vectorMinimumSizeResizeFunction({ x: 5 });
45
+ * resize({ x: 3, y: 10 });
46
+ * // { x: 5, y: 10 }
47
+ * ```
18
48
  */
19
49
  export declare function vectorMinimumSizeResizeFunction(minSize: Partial<Vector>): VectorResizeFunction;
50
+ /**
51
+ * The origin point of a {@link Rectangle}, typically the bottom-left corner.
52
+ */
20
53
  export type RectangleOrigin = Vector;
54
+ /**
55
+ * The top-right (north-east) corner of a {@link Rectangle}.
56
+ */
21
57
  export type TopRightCorner = Vector;
58
+ /**
59
+ * The bottom-left (south-west) corner of a {@link Rectangle}.
60
+ */
22
61
  export type BottomLeftCorner = Vector;
62
+ /**
63
+ * An axis-aligned rectangle defined by its top-right and bottom-left corners.
64
+ */
23
65
  export interface Rectangle {
24
66
  /**
25
- * Upper-Right/North-East corner.
67
+ * Upper-right / north-east corner.
26
68
  */
27
69
  tr: TopRightCorner;
28
70
  /**
29
- * Bottom-Left/South-West corner.
71
+ * Bottom-left / south-west corner.
30
72
  */
31
73
  bl: BottomLeftCorner;
32
74
  }
33
75
  /**
34
- * Returns true if the input vector overlaps another.
76
+ * Returns `true` if the two rectangles overlap (share any interior area).
35
77
  *
36
- * @param a
37
- * @param b
78
+ * Degenerate rectangles (where corners coincide on an axis) are considered non-overlapping.
79
+ *
80
+ * @param a - first rectangle
81
+ * @param b - second rectangle
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const a: Rectangle = { tr: { x: 10, y: 10 }, bl: { x: 0, y: 0 } };
86
+ * const b: Rectangle = { tr: { x: 5, y: 5 }, bl: { x: 0, y: 0 } };
87
+ *
88
+ * rectangleOverlapsRectangle(a, b);
89
+ * // true
90
+ * ```
38
91
  */
39
92
  export declare function rectangleOverlapsRectangle(a: Rectangle, b: Rectangle): boolean;
93
+ /**
94
+ * Computes the intersection rectangle of two axis-aligned rectangles.
95
+ *
96
+ * Returns the overlapping {@link Rectangle} if the two inputs intersect,
97
+ * or `undefined` if they do not overlap.
98
+ *
99
+ * @param a - first rectangle
100
+ * @param b - second rectangle
101
+ */
40
102
  export declare function getOverlappingRectangle(a: Rectangle, b: Rectangle): Maybe<Rectangle>;
package/test/index.cjs.js CHANGED
@@ -218,8 +218,8 @@ function _ts_generator$2(thisArg, body) {
218
218
  }
219
219
  /**
220
220
  * Passes the error to the TestDoneCallback.
221
- * @param done
222
- * @param e
221
+ * @param done - the test framework's done callback to signal completion or failure
222
+ * @param e - the error to pass to the callback; defaults to a generic error
223
223
  */ function failWithTestDoneCallback(done) {
224
224
  var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : new Error('failed test');
225
225
  if (done.fail != null) {
@@ -335,8 +335,8 @@ function _ts_generator$2(thisArg, body) {
335
335
  /**
336
336
  * Creates a TestContextBuilderFunction given the input builder.
337
337
  *
338
- * @param builder
339
- * @returns
338
+ * @param builder - configuration defining how to build configs, fixtures, and manage instance lifecycle
339
+ * @returns a builder function that accepts optional partial config and produces a {@link TestContextFactory}
340
340
  */ function testContextBuilder(builder) {
341
341
  return function(inputConfig) {
342
342
  var config = builder.buildConfig(inputConfig);
@@ -369,7 +369,12 @@ function _ts_generator$2(thisArg, body) {
369
369
  };
370
370
  }
371
371
  /**
372
- * Creates a test context and configurations that will initialize an instance
372
+ * Registers beforeEach/afterEach hooks that manage instance lifecycle for a test context fixture.
373
+ *
374
+ * Before each test, a new instance is created and set on the fixture. After each test, the instance
375
+ * is cleared and optionally destroyed. Test declarations happen synchronously between the hooks.
376
+ *
377
+ * @param config - fixture, test builder, and instance lifecycle functions
373
378
  */ function useTestContextFixture(config) {
374
379
  var buildTests = config.buildTests, fixture = config.fixture, initInstance = config.initInstance, destroyInstance = config.destroyInstance;
375
380
  var clearInstance;
@@ -665,12 +670,20 @@ function _ts_generator$1(thisArg, body) {
665
670
  };
666
671
  }
667
672
  }
668
- var AbstractWrappedFixture = function AbstractWrappedFixture(fixture) {
673
+ /**
674
+ * Abstract base class for wrapping an existing test fixture to add additional context or behavior.
675
+ *
676
+ * Subclasses extend this to provide a richer test API while delegating to the underlying fixture.
677
+ */ var AbstractWrappedFixture = function AbstractWrappedFixture(fixture) {
669
678
  _class_call_check$3(this, AbstractWrappedFixture);
670
679
  _define_property$1(this, "fixture", void 0);
671
680
  this.fixture = fixture;
672
681
  };
673
- var AbstractWrappedFixtureWithInstance = /*#__PURE__*/ function(AbstractTestContextFixture) {
682
+ /**
683
+ * Abstract base class for a wrapped fixture that also manages its own test instance.
684
+ *
685
+ * Combines fixture wrapping with per-test instance lifecycle management from {@link AbstractTestContextFixture}.
686
+ */ var AbstractWrappedFixtureWithInstance = /*#__PURE__*/ function(AbstractTestContextFixture) {
674
687
  _inherits$3(AbstractWrappedFixtureWithInstance, AbstractTestContextFixture);
675
688
  function AbstractWrappedFixtureWithInstance(parent) {
676
689
  _class_call_check$3(this, AbstractWrappedFixtureWithInstance);
@@ -684,7 +697,7 @@ var AbstractWrappedFixtureWithInstance = /*#__PURE__*/ function(AbstractTestCont
684
697
  /**
685
698
  * Wraps the input TestContextFactory to emit another type of Fixture for tests.
686
699
  *
687
- * @returns
700
+ * @returns a function that transforms a {@link TestContextFactory} of type `F` into one of type `W`
688
701
  */ function wrapTestContextFactory(config) {
689
702
  return function(factory) {
690
703
  return function(buildTests) {
@@ -739,7 +752,15 @@ var AbstractWrappedFixtureWithInstance = /*#__PURE__*/ function(AbstractTestCont
739
752
  };
740
753
  };
741
754
  }
742
- function instanceWrapTestContextFactory(config) {
755
+ /**
756
+ * Wraps a {@link TestContextFactory} to produce a fixture that manages its own instance lifecycle.
757
+ *
758
+ * Built on top of {@link wrapTestContextFactory}, this variant automatically creates, sets, and tears down
759
+ * an instance on the wrapped fixture for each test, using the provided {@link InstanceWrapTestContextConfig}.
760
+ *
761
+ * @param config - configuration for wrapping the fixture and managing instance lifecycle
762
+ * @returns a function that transforms a {@link TestContextFactory} of type `F` into one of type `W`
763
+ */ function instanceWrapTestContextFactory(config) {
743
764
  return wrapTestContextFactory({
744
765
  wrapFixture: config.wrapFixture,
745
766
  setupWrap: function setupWrap(wrap) {
@@ -804,14 +825,26 @@ function instanceWrapTestContextFactory(config) {
804
825
  }
805
826
 
806
827
  /**
807
- * Creates a test context and configurations that provides a function to build tests based on the configuration.
828
+ * Sets up a test fixture that forwards calls to a lazily-resolved function reference.
829
+ *
830
+ * The forwarded function delegates to the getter at call time, so the underlying implementation
831
+ * can change between tests while test declarations remain stable.
832
+ *
833
+ * @param config - provides the getter for the function under test
834
+ * @param buildTests - declares test cases using the forwarded function
808
835
  */ function useTestFunctionFixture(config, buildTests) {
809
836
  var fn = config.fn;
810
837
  var forward = util.forwardFunction(fn);
811
838
  buildTests(forward);
812
839
  }
813
840
  /**
814
- * Creates a test context and configurations that provides a function to build tests based on the configuration.
841
+ * Sets up a test fixture for multiple named functions, forwarding each to its lazily-resolved getter.
842
+ *
843
+ * Similar to {@link useTestFunctionFixture} but operates on a map of functions, allowing tests
844
+ * to be declared against multiple related function implementations at once.
845
+ *
846
+ * @param config - provides getters for each named function under test
847
+ * @param buildTests - declares test cases using the map of forwarded functions
815
848
  */ function useTestFunctionMapFixture(config, buildTests) {
816
849
  var forwardedFunctions = util.mapObjectMap(config.fns, function(fn) {
817
850
  return util.forwardFunction(fn);
@@ -1037,10 +1070,21 @@ function _ts_generator(thisArg, body) {
1037
1070
  }
1038
1071
  return ExpectedFailError;
1039
1072
  }(makeError.BaseError);
1040
- function failSuccessfullyError(message) {
1073
+ /**
1074
+ * Creates an {@link ExpectedFailError} without throwing it, for use in deferred error handling.
1075
+ *
1076
+ * @param message - optional error message
1077
+ */ function failSuccessfullyError(message) {
1041
1078
  return new ExpectedFailError(message);
1042
1079
  }
1043
- function failSuccessfully(message) {
1080
+ /**
1081
+ * Throws an {@link ExpectedFailError} to signal that a test reached the expected failure point.
1082
+ *
1083
+ * Used within {@link shouldFail} or {@link expectSuccessfulFail} to indicate that the expected
1084
+ * error path was taken successfully.
1085
+ *
1086
+ * @param message - optional error message
1087
+ */ function failSuccessfully(message) {
1044
1088
  throw failSuccessfullyError(message);
1045
1089
  }
1046
1090
  /**
@@ -1053,7 +1097,11 @@ function failSuccessfully(message) {
1053
1097
  }
1054
1098
  return UnexpectedSuccessFailureError;
1055
1099
  }(makeError.BaseError);
1056
- function failDueToSuccessError(message) {
1100
+ /**
1101
+ * Creates an {@link UnexpectedSuccessFailureError} without throwing it.
1102
+ *
1103
+ * @param message - optional error message; defaults to a standard "expected an error" message
1104
+ */ function failDueToSuccessError(message) {
1057
1105
  return new UnexpectedSuccessFailureError(message !== null && message !== void 0 ? message : 'expected an error to occur but was successful instead');
1058
1106
  }
1059
1107
  /**
@@ -1072,13 +1120,24 @@ function failDueToSuccessError(message) {
1072
1120
  }
1073
1121
  return ExpectedErrorOfSpecificTypeError;
1074
1122
  }(makeError.BaseError);
1075
- function failTest(message) {
1123
+ /**
1124
+ * Fails the current test by throwing an {@link UnexpectedSuccessFailureError}.
1125
+ * Use when a code path should not have been reached.
1126
+ *
1127
+ * @param message - optional error message
1128
+ */ function failTest(message) {
1076
1129
  throw failDueToSuccessError(message);
1077
1130
  }
1078
- function failDueToSuccess() {
1131
+ /**
1132
+ * Throws an {@link UnexpectedSuccessFailureError} with a default message.
1133
+ * Typically called when an operation succeeds but was expected to throw.
1134
+ */ function failDueToSuccess() {
1079
1135
  throw failDueToSuccessError();
1080
1136
  }
1081
- function EXPECT_ERROR_DEFAULT_HANDLER(e) {
1137
+ /**
1138
+ * Default error handler for {@link expectSuccessfulFail} that passes through {@link ExpectedFailError}
1139
+ * instances and re-throws all other errors.
1140
+ */ function EXPECT_ERROR_DEFAULT_HANDLER(e) {
1082
1141
  if (_instanceof(e, ExpectedFailError)) ; else {
1083
1142
  throw e;
1084
1143
  }
@@ -1088,8 +1147,8 @@ function EXPECT_ERROR_DEFAULT_HANDLER(e) {
1088
1147
  *
1089
1148
  * Throws an ExpectedErrorOfSpecificTypeError on failures.
1090
1149
  *
1091
- * @param expectedType
1092
- * @returns
1150
+ * @param expectedType - the class or constructor function that the error should be an instance of
1151
+ * @returns an assertion function that validates the error type via instanceof
1093
1152
  */ function expectFailAssertErrorType(expectedType) {
1094
1153
  return function(error) {
1095
1154
  if (!_instanceof(error, expectedType)) {
@@ -1138,9 +1197,8 @@ function expectSuccessfulFail(errorFn) {
1138
1197
  *
1139
1198
  * This is typically used in conjunction with failSuccessfully(), expectSuccessfulFail(), or expectFail().
1140
1199
  *
1141
- * @param fn
1142
- * @param strict
1143
- * @returns
1200
+ * @param fn - the test function that is expected to throw an {@link ExpectedFailError}
1201
+ * @returns an async test function suitable for use with `it()`
1144
1202
  */ function shouldFail(fn) {
1145
1203
  var usesDoneCallback = fn.length > 0;
1146
1204
  // Return a function that checks arguments at runtime to avoid done callback deprecation warning
@@ -1205,7 +1263,12 @@ function itShouldFail(describeOrFn, fn) {
1205
1263
  }
1206
1264
  it(description, shouldFail(fn));
1207
1265
  }
1208
- function fakeDoneHandler() {
1266
+ /**
1267
+ * Creates a {@link FakeDoneHandler} that converts done-callback invocations into promise resolution/rejection.
1268
+ *
1269
+ * Calling the returned function with no arguments resolves the promise;
1270
+ * calling it with an error (or calling `.fail()`) rejects the promise.
1271
+ */ function fakeDoneHandler() {
1209
1272
  var promiseRef = util.promiseReference();
1210
1273
  var doneHandler = promiseRef.resolve;
1211
1274
  var failHandler = function failHandler(e) {
package/test/index.esm.js CHANGED
@@ -216,8 +216,8 @@ function _ts_generator$2(thisArg, body) {
216
216
  }
217
217
  /**
218
218
  * Passes the error to the TestDoneCallback.
219
- * @param done
220
- * @param e
219
+ * @param done - the test framework's done callback to signal completion or failure
220
+ * @param e - the error to pass to the callback; defaults to a generic error
221
221
  */ function failWithTestDoneCallback(done) {
222
222
  var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : new Error('failed test');
223
223
  if (done.fail != null) {
@@ -333,8 +333,8 @@ function _ts_generator$2(thisArg, body) {
333
333
  /**
334
334
  * Creates a TestContextBuilderFunction given the input builder.
335
335
  *
336
- * @param builder
337
- * @returns
336
+ * @param builder - configuration defining how to build configs, fixtures, and manage instance lifecycle
337
+ * @returns a builder function that accepts optional partial config and produces a {@link TestContextFactory}
338
338
  */ function testContextBuilder(builder) {
339
339
  return function(inputConfig) {
340
340
  var config = builder.buildConfig(inputConfig);
@@ -367,7 +367,12 @@ function _ts_generator$2(thisArg, body) {
367
367
  };
368
368
  }
369
369
  /**
370
- * Creates a test context and configurations that will initialize an instance
370
+ * Registers beforeEach/afterEach hooks that manage instance lifecycle for a test context fixture.
371
+ *
372
+ * Before each test, a new instance is created and set on the fixture. After each test, the instance
373
+ * is cleared and optionally destroyed. Test declarations happen synchronously between the hooks.
374
+ *
375
+ * @param config - fixture, test builder, and instance lifecycle functions
371
376
  */ function useTestContextFixture(config) {
372
377
  var buildTests = config.buildTests, fixture = config.fixture, initInstance = config.initInstance, destroyInstance = config.destroyInstance;
373
378
  var clearInstance;
@@ -663,12 +668,20 @@ function _ts_generator$1(thisArg, body) {
663
668
  };
664
669
  }
665
670
  }
666
- var AbstractWrappedFixture = function AbstractWrappedFixture(fixture) {
671
+ /**
672
+ * Abstract base class for wrapping an existing test fixture to add additional context or behavior.
673
+ *
674
+ * Subclasses extend this to provide a richer test API while delegating to the underlying fixture.
675
+ */ var AbstractWrappedFixture = function AbstractWrappedFixture(fixture) {
667
676
  _class_call_check$3(this, AbstractWrappedFixture);
668
677
  _define_property$1(this, "fixture", void 0);
669
678
  this.fixture = fixture;
670
679
  };
671
- var AbstractWrappedFixtureWithInstance = /*#__PURE__*/ function(AbstractTestContextFixture) {
680
+ /**
681
+ * Abstract base class for a wrapped fixture that also manages its own test instance.
682
+ *
683
+ * Combines fixture wrapping with per-test instance lifecycle management from {@link AbstractTestContextFixture}.
684
+ */ var AbstractWrappedFixtureWithInstance = /*#__PURE__*/ function(AbstractTestContextFixture) {
672
685
  _inherits$3(AbstractWrappedFixtureWithInstance, AbstractTestContextFixture);
673
686
  function AbstractWrappedFixtureWithInstance(parent) {
674
687
  _class_call_check$3(this, AbstractWrappedFixtureWithInstance);
@@ -682,7 +695,7 @@ var AbstractWrappedFixtureWithInstance = /*#__PURE__*/ function(AbstractTestCont
682
695
  /**
683
696
  * Wraps the input TestContextFactory to emit another type of Fixture for tests.
684
697
  *
685
- * @returns
698
+ * @returns a function that transforms a {@link TestContextFactory} of type `F` into one of type `W`
686
699
  */ function wrapTestContextFactory(config) {
687
700
  return function(factory) {
688
701
  return function(buildTests) {
@@ -737,7 +750,15 @@ var AbstractWrappedFixtureWithInstance = /*#__PURE__*/ function(AbstractTestCont
737
750
  };
738
751
  };
739
752
  }
740
- function instanceWrapTestContextFactory(config) {
753
+ /**
754
+ * Wraps a {@link TestContextFactory} to produce a fixture that manages its own instance lifecycle.
755
+ *
756
+ * Built on top of {@link wrapTestContextFactory}, this variant automatically creates, sets, and tears down
757
+ * an instance on the wrapped fixture for each test, using the provided {@link InstanceWrapTestContextConfig}.
758
+ *
759
+ * @param config - configuration for wrapping the fixture and managing instance lifecycle
760
+ * @returns a function that transforms a {@link TestContextFactory} of type `F` into one of type `W`
761
+ */ function instanceWrapTestContextFactory(config) {
741
762
  return wrapTestContextFactory({
742
763
  wrapFixture: config.wrapFixture,
743
764
  setupWrap: function setupWrap(wrap) {
@@ -802,14 +823,26 @@ function instanceWrapTestContextFactory(config) {
802
823
  }
803
824
 
804
825
  /**
805
- * Creates a test context and configurations that provides a function to build tests based on the configuration.
826
+ * Sets up a test fixture that forwards calls to a lazily-resolved function reference.
827
+ *
828
+ * The forwarded function delegates to the getter at call time, so the underlying implementation
829
+ * can change between tests while test declarations remain stable.
830
+ *
831
+ * @param config - provides the getter for the function under test
832
+ * @param buildTests - declares test cases using the forwarded function
806
833
  */ function useTestFunctionFixture(config, buildTests) {
807
834
  var fn = config.fn;
808
835
  var forward = forwardFunction(fn);
809
836
  buildTests(forward);
810
837
  }
811
838
  /**
812
- * Creates a test context and configurations that provides a function to build tests based on the configuration.
839
+ * Sets up a test fixture for multiple named functions, forwarding each to its lazily-resolved getter.
840
+ *
841
+ * Similar to {@link useTestFunctionFixture} but operates on a map of functions, allowing tests
842
+ * to be declared against multiple related function implementations at once.
843
+ *
844
+ * @param config - provides getters for each named function under test
845
+ * @param buildTests - declares test cases using the map of forwarded functions
813
846
  */ function useTestFunctionMapFixture(config, buildTests) {
814
847
  var forwardedFunctions = mapObjectMap(config.fns, function(fn) {
815
848
  return forwardFunction(fn);
@@ -1035,10 +1068,21 @@ function _ts_generator(thisArg, body) {
1035
1068
  }
1036
1069
  return ExpectedFailError;
1037
1070
  }(BaseError);
1038
- function failSuccessfullyError(message) {
1071
+ /**
1072
+ * Creates an {@link ExpectedFailError} without throwing it, for use in deferred error handling.
1073
+ *
1074
+ * @param message - optional error message
1075
+ */ function failSuccessfullyError(message) {
1039
1076
  return new ExpectedFailError(message);
1040
1077
  }
1041
- function failSuccessfully(message) {
1078
+ /**
1079
+ * Throws an {@link ExpectedFailError} to signal that a test reached the expected failure point.
1080
+ *
1081
+ * Used within {@link shouldFail} or {@link expectSuccessfulFail} to indicate that the expected
1082
+ * error path was taken successfully.
1083
+ *
1084
+ * @param message - optional error message
1085
+ */ function failSuccessfully(message) {
1042
1086
  throw failSuccessfullyError(message);
1043
1087
  }
1044
1088
  /**
@@ -1051,7 +1095,11 @@ function failSuccessfully(message) {
1051
1095
  }
1052
1096
  return UnexpectedSuccessFailureError;
1053
1097
  }(BaseError);
1054
- function failDueToSuccessError(message) {
1098
+ /**
1099
+ * Creates an {@link UnexpectedSuccessFailureError} without throwing it.
1100
+ *
1101
+ * @param message - optional error message; defaults to a standard "expected an error" message
1102
+ */ function failDueToSuccessError(message) {
1055
1103
  return new UnexpectedSuccessFailureError(message !== null && message !== void 0 ? message : 'expected an error to occur but was successful instead');
1056
1104
  }
1057
1105
  /**
@@ -1070,13 +1118,24 @@ function failDueToSuccessError(message) {
1070
1118
  }
1071
1119
  return ExpectedErrorOfSpecificTypeError;
1072
1120
  }(BaseError);
1073
- function failTest(message) {
1121
+ /**
1122
+ * Fails the current test by throwing an {@link UnexpectedSuccessFailureError}.
1123
+ * Use when a code path should not have been reached.
1124
+ *
1125
+ * @param message - optional error message
1126
+ */ function failTest(message) {
1074
1127
  throw failDueToSuccessError(message);
1075
1128
  }
1076
- function failDueToSuccess() {
1129
+ /**
1130
+ * Throws an {@link UnexpectedSuccessFailureError} with a default message.
1131
+ * Typically called when an operation succeeds but was expected to throw.
1132
+ */ function failDueToSuccess() {
1077
1133
  throw failDueToSuccessError();
1078
1134
  }
1079
- function EXPECT_ERROR_DEFAULT_HANDLER(e) {
1135
+ /**
1136
+ * Default error handler for {@link expectSuccessfulFail} that passes through {@link ExpectedFailError}
1137
+ * instances and re-throws all other errors.
1138
+ */ function EXPECT_ERROR_DEFAULT_HANDLER(e) {
1080
1139
  if (_instanceof(e, ExpectedFailError)) ; else {
1081
1140
  throw e;
1082
1141
  }
@@ -1086,8 +1145,8 @@ function EXPECT_ERROR_DEFAULT_HANDLER(e) {
1086
1145
  *
1087
1146
  * Throws an ExpectedErrorOfSpecificTypeError on failures.
1088
1147
  *
1089
- * @param expectedType
1090
- * @returns
1148
+ * @param expectedType - the class or constructor function that the error should be an instance of
1149
+ * @returns an assertion function that validates the error type via instanceof
1091
1150
  */ function expectFailAssertErrorType(expectedType) {
1092
1151
  return function(error) {
1093
1152
  if (!_instanceof(error, expectedType)) {
@@ -1136,9 +1195,8 @@ function expectSuccessfulFail(errorFn) {
1136
1195
  *
1137
1196
  * This is typically used in conjunction with failSuccessfully(), expectSuccessfulFail(), or expectFail().
1138
1197
  *
1139
- * @param fn
1140
- * @param strict
1141
- * @returns
1198
+ * @param fn - the test function that is expected to throw an {@link ExpectedFailError}
1199
+ * @returns an async test function suitable for use with `it()`
1142
1200
  */ function shouldFail(fn) {
1143
1201
  var usesDoneCallback = fn.length > 0;
1144
1202
  // Return a function that checks arguments at runtime to avoid done callback deprecation warning
@@ -1203,7 +1261,12 @@ function itShouldFail(describeOrFn, fn) {
1203
1261
  }
1204
1262
  it(description, shouldFail(fn));
1205
1263
  }
1206
- function fakeDoneHandler() {
1264
+ /**
1265
+ * Creates a {@link FakeDoneHandler} that converts done-callback invocations into promise resolution/rejection.
1266
+ *
1267
+ * Calling the returned function with no arguments resolves the promise;
1268
+ * calling it with an error (or calling `.fail()`) rejects the promise.
1269
+ */ function fakeDoneHandler() {
1207
1270
  var promiseRef = promiseReference();
1208
1271
  var doneHandler = promiseRef.resolve;
1209
1272
  var failHandler = function failHandler(e) {
package/test/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@dereekb/util/test",
3
- "version": "13.0.7",
3
+ "version": "13.2.0",
4
4
  "peerDependencies": {
5
- "@dereekb/util": "13.0.7",
5
+ "@dereekb/util": "13.2.0",
6
6
  "make-error": "^1.3.0"
7
7
  },
8
8
  "exports": {
@@ -16,12 +16,22 @@ export type TestDoneCallback = ((...args: any[]) => any) & {
16
16
  };
17
17
  /**
18
18
  * Passes the error to the TestDoneCallback.
19
- * @param done
20
- * @param e
19
+ * @param done - the test framework's done callback to signal completion or failure
20
+ * @param e - the error to pass to the callback; defaults to a generic error
21
21
  */
22
22
  export declare function failWithTestDoneCallback(done: TestDoneCallback, e?: unknown): void;
23
+ /**
24
+ * A test function that receives a done callback to signal completion.
25
+ */
23
26
  export type TestProvidesCallbackWithDone = (cb: TestDoneCallback) => void | undefined;
27
+ /**
28
+ * A test function that either uses a done callback or returns a promise to signal completion.
29
+ */
24
30
  export type TestProvidesCallback = TestProvidesCallbackWithDone | (() => Promise<unknown>);
31
+ /**
32
+ * Reference wrapper around a {@link TestDoneCallback} that exposes the underlying promise,
33
+ * allowing callers to await the done signal.
34
+ */
25
35
  export type TestDoneCallbackRef = Omit<TestDoneCallback, 'fail'> & {
26
36
  readonly _promise: PromiseReference<void>;
27
37
  readonly done: TestDoneCallback;
@@ -65,6 +75,9 @@ export type TestFixtureInstance<I> = I;
65
75
  export interface TestFixture<I> {
66
76
  readonly instance: TestFixtureInstance<I>;
67
77
  }
78
+ /**
79
+ * Cleanup function returned by {@link TestContextFixture.setInstance} to clear the current instance after a test completes.
80
+ */
68
81
  export type TestContextFixtureClearInstanceFunction = () => void;
69
82
  /**
70
83
  * TestFixture with additional functions that the TestContextFactory sees for managing the instance.
@@ -96,6 +109,10 @@ export declare abstract class AbstractChildTestContextFixture<I, P extends TestC
96
109
  readonly parent: P;
97
110
  constructor(parent: P);
98
111
  }
112
+ /**
113
+ * Function that declares tests using the provided fixture. Called during test suite setup
114
+ * to register test cases that will later run against fresh fixture instances.
115
+ */
99
116
  export type BuildTestsWithContextFunction<F> = (fixture: F) => void;
100
117
  /**
101
118
  * Used for tests to execute a number of tests using the fixture.
@@ -138,10 +155,14 @@ export interface TestContextBuilderConfig<I, F extends TestContextFixture<I>, C>
138
155
  /**
139
156
  * Creates a TestContextBuilderFunction given the input builder.
140
157
  *
141
- * @param builder
142
- * @returns
158
+ * @param builder - configuration defining how to build configs, fixtures, and manage instance lifecycle
159
+ * @returns a builder function that accepts optional partial config and produces a {@link TestContextFactory}
143
160
  */
144
161
  export declare function testContextBuilder<I, F extends TestContextFixture<I>, C>(builder: TestContextBuilderConfig<I, F, C>): TestContextBuilderFunction<I, F, C>;
162
+ /**
163
+ * Configuration for {@link useTestContextFixture} that defines how to initialize and destroy
164
+ * test instances, along with the fixture and test-building function.
165
+ */
145
166
  export interface UseContextFixture<C extends TestContextFixture<I>, I> {
146
167
  readonly fixture: C;
147
168
  readonly buildTests: BuildTestsWithContextFunction<C>;
@@ -149,6 +170,11 @@ export interface UseContextFixture<C extends TestContextFixture<I>, I> {
149
170
  destroyInstance?(instance: I): PromiseOrValue<void>;
150
171
  }
151
172
  /**
152
- * Creates a test context and configurations that will initialize an instance
173
+ * Registers beforeEach/afterEach hooks that manage instance lifecycle for a test context fixture.
174
+ *
175
+ * Before each test, a new instance is created and set on the fixture. After each test, the instance
176
+ * is cleared and optionally destroyed. Test declarations happen synchronously between the hooks.
177
+ *
178
+ * @param config - fixture, test builder, and instance lifecycle functions
153
179
  */
154
180
  export declare function useTestContextFixture<C extends TestContextFixture<I>, I>(config: UseContextFixture<C, I>): void;