@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
@@ -9,13 +9,31 @@ import { type TestDoneCallback } from './shared';
9
9
  */
10
10
  export declare class ExpectedFailError extends BaseError {
11
11
  }
12
+ /**
13
+ * Creates an {@link ExpectedFailError} without throwing it, for use in deferred error handling.
14
+ *
15
+ * @param message - optional error message
16
+ */
12
17
  export declare function failSuccessfullyError(message?: string): ExpectedFailError;
18
+ /**
19
+ * Throws an {@link ExpectedFailError} to signal that a test reached the expected failure point.
20
+ *
21
+ * Used within {@link shouldFail} or {@link expectSuccessfulFail} to indicate that the expected
22
+ * error path was taken successfully.
23
+ *
24
+ * @param message - optional error message
25
+ */
13
26
  export declare function failSuccessfully(message?: string): never;
14
27
  /**
15
28
  * Error thrown when success occurs when it should not have.
16
29
  */
17
30
  export declare class UnexpectedSuccessFailureError extends BaseError {
18
31
  }
32
+ /**
33
+ * Creates an {@link UnexpectedSuccessFailureError} without throwing it.
34
+ *
35
+ * @param message - optional error message; defaults to a standard "expected an error" message
36
+ */
19
37
  export declare function failDueToSuccessError(message?: string): UnexpectedSuccessFailureError;
20
38
  /**
21
39
  * Error thrown when the error type was different than the expected type.
@@ -25,8 +43,22 @@ export declare class ExpectedErrorOfSpecificTypeError extends BaseError {
25
43
  readonly expectedType?: Maybe<ClassLikeType | string>;
26
44
  constructor(encounteredType: unknown, expectedType?: Maybe<ClassLikeType | string>);
27
45
  }
46
+ /**
47
+ * Fails the current test by throwing an {@link UnexpectedSuccessFailureError}.
48
+ * Use when a code path should not have been reached.
49
+ *
50
+ * @param message - optional error message
51
+ */
28
52
  export declare function failTest(message?: string): never;
53
+ /**
54
+ * Throws an {@link UnexpectedSuccessFailureError} with a default message.
55
+ * Typically called when an operation succeeds but was expected to throw.
56
+ */
29
57
  export declare function failDueToSuccess(): never;
58
+ /**
59
+ * Default error handler for {@link expectSuccessfulFail} that passes through {@link ExpectedFailError}
60
+ * instances and re-throws all other errors.
61
+ */
30
62
  export declare function EXPECT_ERROR_DEFAULT_HANDLER(e: unknown): void;
31
63
  /**
32
64
  * Used to assert additional information about the expected error.
@@ -39,45 +71,76 @@ export type ExpectFailAssertionFunction = (error: unknown) => PromiseOrValue<May
39
71
  *
40
72
  * Throws an ExpectedErrorOfSpecificTypeError on failures.
41
73
  *
42
- * @param expectedType
43
- * @returns
74
+ * @param expectedType - the class or constructor function that the error should be an instance of
75
+ * @returns an assertion function that validates the error type via instanceof
44
76
  */
45
77
  export declare function expectFailAssertErrorType(expectedType: ClassType | ClassLikeType | typeof Error | any): ExpectFailAssertionFunction;
46
78
  /**
47
79
  * Function that expects any failure to be thrown, then throws an ExpectedFailError.
48
80
  *
49
- * @param errorFn
50
- * @param handleError
81
+ * @param errorFn - function expected to throw an error (sync or async)
82
+ * @param assertFailType - optional assertion to validate the type or content of the thrown error
51
83
  */
52
84
  export declare function expectFail(errorFn: () => void, assertFailType?: ExpectFailAssertionFunction): void;
53
85
  export declare function expectFail(errorFn: () => Promise<void>, assertFailType?: ExpectFailAssertionFunction): Promise<void>;
54
86
  /**
55
87
  * Function that expects an ExpectedFailError to be thrown.
56
88
  *
57
- * @param errorFn
58
- * @param handleError
89
+ * @param errorFn - function expected to throw (sync or async); if it succeeds, the test fails
90
+ * @param handleError - optional custom error handler; defaults to {@link EXPECT_ERROR_DEFAULT_HANDLER}
59
91
  */
60
92
  export declare function expectSuccessfulFail(errorFn: () => void, handleError?: (e: unknown) => void): void;
61
93
  export declare function expectSuccessfulFail(errorFn: () => Promise<void>, handleError?: (e: unknown) => void): Promise<void>;
94
+ /**
95
+ * Extended done callback for {@link shouldFail} tests that adds a {@link failSuccessfully} convenience method.
96
+ */
62
97
  export interface ShouldFailDoneCallback extends TestDoneCallback {
63
98
  failSuccessfully(): void;
64
99
  }
100
+ /**
101
+ * A test function for {@link shouldFail} that receives a {@link ShouldFailDoneCallback} to signal failure outcomes.
102
+ */
65
103
  export type ShouldFailProvidesCallbackWithDone = (cb: ShouldFailDoneCallback) => void | undefined;
104
+ /**
105
+ * A test function for {@link shouldFail} that returns its result directly (sync or async), without using a done callback.
106
+ */
66
107
  export type ShouldFailProvidesCallbackWithResult = () => PromiseOrValue<unknown>;
108
+ /**
109
+ * Union type for test functions accepted by {@link shouldFail}. Supports both done-callback and promise-based patterns.
110
+ */
67
111
  export type ShouldFailProvidesCallback = ShouldFailProvidesCallbackWithDone | ShouldFailProvidesCallbackWithResult;
68
112
  /**
69
113
  * Used to wrap a testing function and watch for ExpectedFailError errors in order to pass the test. Other exceptions are treated normally as failures.
70
114
  *
71
115
  * This is typically used in conjunction with failSuccessfully(), expectSuccessfulFail(), or expectFail().
72
116
  *
73
- * @param fn
74
- * @param strict
75
- * @returns
117
+ * @param fn - the test function that is expected to throw an {@link ExpectedFailError}
118
+ * @returns an async test function suitable for use with `it()`
76
119
  */
77
120
  export declare function shouldFail(fn: ShouldFailProvidesCallback): () => Promise<unknown>;
121
+ /**
122
+ * Convenience wrapper that registers an `it()` test case which is expected to fail.
123
+ *
124
+ * Automatically generates a "should fail" description and wraps the test function with {@link shouldFail}.
125
+ *
126
+ * @param describeOrFn - either a description suffix (e.g., "when input is null") or the test function directly
127
+ * @param fn - the test function, if a description string was provided as the first argument
128
+ */
78
129
  export declare function itShouldFail(fn: ShouldFailProvidesCallback): void;
79
130
  export declare function itShouldFail(describe: string, fn: ShouldFailProvidesCallback): void;
131
+ /**
132
+ * A simulated done callback that bridges callback-based test patterns to promises.
133
+ *
134
+ * Calling the handler or its `fail` method resolves or rejects the underlying promise,
135
+ * allowing callback-style tests to be awaited.
136
+ */
80
137
  export interface FakeDoneHandler extends TestDoneCallback, PromiseReference {
81
138
  _ref: PromiseReference;
82
139
  }
140
+ /**
141
+ * Creates a {@link FakeDoneHandler} that converts done-callback invocations into promise resolution/rejection.
142
+ *
143
+ * Calling the returned function with no arguments resolves the promise;
144
+ * calling it with an error (or calling `.fail()`) rejects the promise.
145
+ */
83
146
  export declare function fakeDoneHandler(): FakeDoneHandler;
@@ -1,25 +1,63 @@
1
1
  import { type Getter } from '@dereekb/util';
2
+ /**
3
+ * A getter that returns the function under test. Allows the function reference to be swapped
4
+ * between tests without re-declaring test cases.
5
+ */
2
6
  export type UseTestFunctionFixtureFunctionGetter<I extends (...args: any[]) => O, O = any> = Getter<I>;
7
+ /**
8
+ * Configuration for {@link useTestFunctionFixture} providing a getter for the function under test.
9
+ */
3
10
  export interface UseTestFunctionFixture<I extends (...args: any[]) => O, O = any> {
4
11
  fn: Getter<I>;
5
12
  }
13
+ /**
14
+ * Function that declares test cases using the provided forwarded function reference.
15
+ */
6
16
  export type TestFunctionFixtureBuildTests<I> = (fn: I) => void;
7
17
  /**
8
- * Creates a test context and configurations that provides a function to build tests based on the configuration.
18
+ * Sets up a test fixture that forwards calls to a lazily-resolved function reference.
19
+ *
20
+ * The forwarded function delegates to the getter at call time, so the underlying implementation
21
+ * can change between tests while test declarations remain stable.
22
+ *
23
+ * @param config - provides the getter for the function under test
24
+ * @param buildTests - declares test cases using the forwarded function
9
25
  */
10
26
  export declare function useTestFunctionFixture<I extends (...args: any[]) => O, O = any>(config: UseTestFunctionFixture<I, O>, buildTests: TestFunctionFixtureBuildTests<I>): void;
27
+ /**
28
+ * A record of named functions, used as the shape for multi-function test fixtures.
29
+ */
11
30
  export type UseTestFunctionMapObject = Record<string, (...args: any[]) => any>;
31
+ /**
32
+ * Configuration for {@link useTestFunctionMapFixture} providing getters for multiple named functions.
33
+ */
12
34
  export type UseTestFunctionMapFixture<T extends UseTestFunctionMapObject> = {
13
35
  fns: UseTestFunctionMapFixtureGetterFunctions<T>;
14
36
  };
37
+ /**
38
+ * Maps each key in `T` to its corresponding function getter type, filtering out non-getter entries.
39
+ */
15
40
  export type UseTestFunctionMapFixtureGetterFunctions<T extends UseTestFunctionMapObject> = {
16
41
  [K in keyof T]: T[K] extends UseTestFunctionFixtureFunctionGetter<infer I, infer O> ? T[K] : never;
17
42
  };
43
+ /**
44
+ * Maps each key in `T` to the unwrapped function type returned by its getter.
45
+ * This is the shape of the object passed to test-building functions.
46
+ */
18
47
  export type UseTestFunctionMapFixtureFunctions<T extends UseTestFunctionMapObject> = {
19
48
  [K in keyof T]: T[K] extends UseTestFunctionFixtureFunctionGetter<infer I, infer O> ? I : never;
20
49
  };
50
+ /**
51
+ * Function that declares test cases using the provided map of forwarded function references.
52
+ */
21
53
  export type TestFunctionFixtureMapBuildTests<T extends UseTestFunctionMapObject> = (fixture: UseTestFunctionMapFixtureFunctions<T>) => void;
22
54
  /**
23
- * Creates a test context and configurations that provides a function to build tests based on the configuration.
55
+ * Sets up a test fixture for multiple named functions, forwarding each to its lazily-resolved getter.
56
+ *
57
+ * Similar to {@link useTestFunctionFixture} but operates on a map of functions, allowing tests
58
+ * to be declared against multiple related function implementations at once.
59
+ *
60
+ * @param config - provides getters for each named function under test
61
+ * @param buildTests - declares test cases using the map of forwarded functions
24
62
  */
25
63
  export declare function useTestFunctionMapFixture<T extends UseTestFunctionMapObject>(config: UseTestFunctionMapFixture<T>, buildTests: TestFunctionFixtureMapBuildTests<T>): void;
@@ -1,8 +1,18 @@
1
1
  import { AbstractTestContextFixture, type TestContextFactory } from './shared';
2
+ /**
3
+ * Abstract base class for wrapping an existing test fixture to add additional context or behavior.
4
+ *
5
+ * Subclasses extend this to provide a richer test API while delegating to the underlying fixture.
6
+ */
2
7
  export declare abstract class AbstractWrappedFixture<F> {
3
8
  readonly fixture: F;
4
9
  constructor(fixture: F);
5
10
  }
11
+ /**
12
+ * Abstract base class for a wrapped fixture that also manages its own test instance.
13
+ *
14
+ * Combines fixture wrapping with per-test instance lifecycle management from {@link AbstractTestContextFixture}.
15
+ */
6
16
  export declare abstract class AbstractWrappedFixtureWithInstance<I, F> extends AbstractTestContextFixture<I> {
7
17
  readonly parent: F;
8
18
  constructor(parent: F);
@@ -37,7 +47,7 @@ export interface WrapTestContextConfig<W, F, E = any> {
37
47
  /**
38
48
  * Wraps the input TestContextFactory to emit another type of Fixture for tests.
39
49
  *
40
- * @returns
50
+ * @returns a function that transforms a {@link TestContextFactory} of type `F` into one of type `W`
41
51
  */
42
52
  export declare function wrapTestContextFactory<W, F, E = any>(config: WrapTestContextConfig<W, F, E>): (factory: TestContextFactory<F>) => TestContextFactory<W>;
43
53
  export interface InstanceWrapTestContextConfig<I, W extends AbstractWrappedFixtureWithInstance<I, F>, F> extends Pick<WrapTestContextConfig<W, F>, 'wrapFixture'> {
@@ -58,4 +68,13 @@ export interface InstanceWrapTestContextConfig<I, W extends AbstractWrappedFixtu
58
68
  */
59
69
  teardownInstance?: (instance: I) => void | Promise<void>;
60
70
  }
71
+ /**
72
+ * Wraps a {@link TestContextFactory} to produce a fixture that manages its own instance lifecycle.
73
+ *
74
+ * Built on top of {@link wrapTestContextFactory}, this variant automatically creates, sets, and tears down
75
+ * an instance on the wrapped fixture for each test, using the provided {@link InstanceWrapTestContextConfig}.
76
+ *
77
+ * @param config - configuration for wrapping the fixture and managing instance lifecycle
78
+ * @returns a function that transforms a {@link TestContextFactory} of type `F` into one of type `W`
79
+ */
61
80
  export declare function instanceWrapTestContextFactory<I, W extends AbstractWrappedFixtureWithInstance<I, F>, F>(config: InstanceWrapTestContextConfig<I, W, F>): (factory: TestContextFactory<F>) => TestContextFactory<W>;