@nestia/e2e 14.0.1 → 14.0.3

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.
@@ -6,16 +6,30 @@
6
6
  * in functional programming style. Functions use direct parameter passing for
7
7
  * simplicity while maintaining functional programming principles.
8
8
  *
9
+ * Processing cost: Sequential array operations visit each required position
10
+ * once; has short-circuits, and subsets materializes the exponential power-set
11
+ * output. Async helpers await one user callback per position and preserve its
12
+ * ordering rather than assuming callbacks are independent.
13
+ *
14
+ * Resource ownership: Async helpers await one callback at a time and keep their
15
+ * input and partial output until settlement; results transfer to the caller.
16
+ * Synchronous helpers retain only their local arrays and recursion state.
17
+ * Callback resources and cancellation belong to the caller.
18
+ *
9
19
  * @author Jeongho Nam - https://github.com/samchon
10
20
  * @example
11
- * ```typescript
12
21
  * // Asynchronous filtering example
13
22
  * const numbers = [1, 2, 3, 4, 5];
14
- * const evenNumbers = await ArrayUtil.asyncFilter(numbers,
15
- * async (num) => num % 2 === 0
23
+ * const evenNumbers = await ArrayUtil.asyncFilter(
24
+ * numbers,
25
+ * async (num) => num % 2 === 0,
16
26
  * );
17
27
  * console.log(evenNumbers); // [2, 4]
18
- * ```;
28
+ *
29
+ * @evidence contracts/common.md#principled-implementation Asynchronous filtering and mapping share sequential `asyncForEach`; repetition awaits each index and collects its results. Synchronous helpers use loops and native methods, and `subsets` enumerates the include or exclude choice per position.
30
+ * @evidence contracts/common.md#clear-and-simple-design Filtering and mapping share iteration without allocating unused results; repetition separately collects its results, with one private count validator.
31
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts No function special-cases a value, a fixture, or a caller; ordering and short-circuiting follow from the loop and the native `some`.
32
+ * @evidence contracts/common.md#meaningful-documentation The namespace prose states the sequential, functional style, and each function documents its parameters, its result, and an example.
19
33
  */
20
34
  export declare namespace ArrayUtil {
21
35
  /**
@@ -26,28 +40,39 @@ export declare namespace ArrayUtil {
26
40
  * predicate function receives the element, index, and the full array as
27
41
  * parameters.
28
42
  *
43
+ * Processing cost: Each of N elements invokes its predicate once in sequence;
44
+ * array bookkeeping is O(N), with O(M) output for M accepted elements.
45
+ *
46
+ * Resource ownership: The invocation awaits one callback at a time and
47
+ * retains only its partial output and current call; success transfers the
48
+ * output to the caller and rejection releases local state. Callback-owned
49
+ * external resources remain the callback owner’s responsibility.
50
+ *
29
51
  * @example
30
- * ```typescript
31
52
  * const users = [
32
- * { id: 1, name: 'Alice', active: true },
33
- * { id: 2, name: 'Bob', active: false },
34
- * { id: 3, name: 'Charlie', active: true }
53
+ * { id: 1, name: "Alice", active: true },
54
+ * { id: 2, name: "Bob", active: false },
55
+ * { id: 3, name: "Charlie", active: true },
35
56
  * ];
36
57
  *
37
- * const activeUsers = await ArrayUtil.asyncFilter(users,
58
+ * const activeUsers = await ArrayUtil.asyncFilter(
59
+ * users,
38
60
  * async (user) => {
39
61
  * // Async validation logic (e.g., API call)
40
- * await new Promise(resolve => setTimeout(resolve, 100));
62
+ * await new Promise((resolve) => setTimeout(resolve, 100));
41
63
  * return user.active;
42
- * }
64
+ * },
43
65
  * );
44
66
  * console.log(activeUsers); // [{ id: 1, name: 'Alice', active: true }, { id: 3, name: 'Charlie', active: true }]
45
- * ```;
46
67
  *
47
68
  * @template Input - The type of elements in the input array
48
69
  * @param elements - The readonly array to filter
49
70
  * @param pred - The asynchronous predicate function to test each element
50
71
  * @returns A Promise resolving to the filtered array
72
+ * @evidence contracts/common.md#principled-implementation The predicate runs on each element in order and the next call starts after the previous promise settles; an element is kept only when the awaited result is exactly `true`, which the `Promise<boolean>` type guarantees for well-typed callers, and a rejection stops the iteration and rejects the result.
73
+ * @evidence contracts/common.md#clear-and-simple-design It composes `asyncForEach` with one push instead of reimplementing the loop.
74
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The predicate alone decides inclusion; no element is skipped or retried.
75
+ * @evidence contracts/common.md#meaningful-documentation The comment states the sequential order, the predicate arguments, and the result, with an example.
51
76
  */
52
77
  const asyncFilter: <Input>(elements: readonly Input[], pred: (elem: Input, index: number, array: readonly Input[]) => Promise<boolean>) => Promise<Input[]>;
53
78
  /**
@@ -59,23 +84,33 @@ export declare namespace ArrayUtil {
59
84
  * performs sequential processing rather than parallel processing, making it
60
85
  * suitable for operations where order matters.
61
86
  *
87
+ * Processing cost: Each of N elements invokes its callback once in sequence:
88
+ * O(N) bookkeeping with no result array.
89
+ *
90
+ * Resource ownership: The invocation retains its input while awaiting one
91
+ * callback at a time, discards callback results and releases local state on
92
+ * completion or rejection. Callback-owned external resources remain the
93
+ * callback owner’s responsibility.
94
+ *
62
95
  * @example
63
- * ```typescript
64
- * const urls = ['url1', 'url2', 'url3'];
96
+ * const urls = ["url1", "url2", "url3"];
65
97
  *
66
98
  * await ArrayUtil.asyncForEach(urls, async (url, index) => {
67
- * console.log(`Processing ${index}: ${url}`);
68
- * const data = await fetch(url);
69
- * await processData(data);
70
- * console.log(`Completed ${index}: ${url}`);
99
+ * console.log(`Processing ${index}: ${url}`);
100
+ * const data = await fetch(url);
101
+ * await processData(data);
102
+ * console.log(`Completed ${index}: ${url}`);
71
103
  * });
72
- * console.log('All URLs processed sequentially');
73
- * ```
104
+ * console.log("All URLs processed sequentially");
74
105
  *
75
106
  * @template Input - The type of elements in the input array
76
107
  * @param elements - The readonly array to process
77
108
  * @param closure - The asynchronous function to execute for each element
78
109
  * @returns A Promise<void> that resolves when all operations complete
110
+ * @evidence contracts/common.md#principled-implementation The initial array length determines the visited indices, and each callback receives the current element, index and original array. Each call is awaited before advancing, so rejection ends iteration and propagates.
111
+ * @evidence contracts/common.md#clear-and-simple-design One sequential loop discards callback results without collecting an unused array.
112
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The closure receives every element exactly once and no error is swallowed.
113
+ * @evidence contracts/common.md#meaningful-documentation The comment contrasts it with the native forEach, states the sequential semantics, and gives an example.
79
114
  */
80
115
  const asyncForEach: <Input>(elements: readonly Input[], closure: (elem: Input, index: number, array: readonly Input[]) => Promise<any>) => Promise<void>;
81
116
  /**
@@ -84,27 +119,40 @@ export declare namespace ArrayUtil {
84
119
  *
85
120
  * Similar to JavaScript's native map but processes asynchronous functions
86
121
  * sequentially. Each element's transformation is completed before proceeding
87
- * to the next element, ensuring order is maintained. This function still
88
- * maintains the currying pattern for composition.
122
+ * to the next element, ensuring order is maintained.
123
+ *
124
+ * Processing cost: Each of N elements invokes its mapper once in sequence and
125
+ * stores one result: O(N) bookkeeping and output space.
126
+ *
127
+ * Resource ownership: The invocation awaits one callback at a time and
128
+ * retains only its partial output and current call; success transfers the
129
+ * output to the caller and rejection releases local state. Callback-owned
130
+ * external resources remain the callback owner’s responsibility.
89
131
  *
90
132
  * @example
91
- * ```typescript
92
133
  * const userIds = [1, 2, 3, 4, 5];
93
134
  *
94
- * const userDetails = await ArrayUtil.asyncMap(userIds)(
95
- * async (id, index) => {
96
- * console.log(`Fetching user ${id} (${index + 1}/${userIds.length})`);
97
- * const response = await fetch(`/api/users/${id}`);
98
- * return await response.json();
99
- * }
135
+ * const userDetails = await ArrayUtil.asyncMap(
136
+ * userIds,
137
+ * async (id, index) => {
138
+ * console.log(
139
+ * `Fetching user ${id} (${index + 1}/${userIds.length})`,
140
+ * );
141
+ * const response = await fetch(`/api/users/${id}`);
142
+ * return await response.json();
143
+ * },
100
144
  * );
101
- * console.log('All users fetched:', userDetails);
102
- * ```
145
+ * console.log("All users fetched:", userDetails);
103
146
  *
104
147
  * @template Input - The type of elements in the input array
148
+ * @template Output - The type of elements in the resulting array
105
149
  * @param elements - The readonly array to transform
106
- * @returns A function that takes a transformation function and returns a
107
- * Promise resolving to the transformed array
150
+ * @param closure - The asynchronous function that transforms each element
151
+ * @returns A Promise resolving to the transformed array
152
+ * @evidence contracts/common.md#principled-implementation The closure result of each element is pushed in iteration order, so the output order equals the input order, which holds because the calls are sequential.
153
+ * @evidence contracts/common.md#clear-and-simple-design It composes `asyncForEach` with one push.
154
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Every element is transformed by the caller's closure, with no memoization or skipping.
155
+ * @evidence contracts/common.md#meaningful-documentation The comment states the sequential order and the parameters, and the example calls the two-argument form the function has.
108
156
  */
109
157
  const asyncMap: <Input, Output>(elements: readonly Input[], closure: (elem: Input, index: number, array: readonly Input[]) => Promise<Output>) => Promise<Output[]>;
110
158
  /**
@@ -114,24 +162,34 @@ export declare namespace ArrayUtil {
114
162
  * execution is performed sequentially, and all results are collected into an
115
163
  * array.
116
164
  *
165
+ * Processing cost: The callback runs once for each of N indices, in sequence,
166
+ * with O(N) result storage.
167
+ *
168
+ * Resource ownership: The invocation awaits one callback at a time and
169
+ * retains only its partial output and current call; success transfers the
170
+ * output to the caller and rejection releases local state. Callback-owned
171
+ * external resources remain the callback owner’s responsibility.
172
+ *
117
173
  * @example
118
- * ```typescript
119
174
  * // Generate random data 5 times
120
175
  * const randomData = await ArrayUtil.asyncRepeat(5, async (index) => {
121
- * await new Promise(resolve => setTimeout(resolve, 100)); // Wait 0.1 seconds
176
+ * await new Promise((resolve) => setTimeout(resolve, 100)); // Wait 0.1 seconds
122
177
  * return {
123
178
  * id: index,
124
179
  * value: Math.random(),
125
- * timestamp: new Date().toISOString()
180
+ * timestamp: new Date().toISOString(),
126
181
  * };
127
182
  * });
128
- * console.log('Generated data:', randomData);
129
- * ```;
183
+ * console.log("Generated data:", randomData);
130
184
  *
131
185
  * @template T - The type of the result from each execution
132
- * @param count - The number of times to repeat (non-negative integer)
186
+ * @param count - The number of times to repeat (integer from 0 to 2^32 - 1)
133
187
  * @param closure - The asynchronous function to execute repeatedly
134
188
  * @returns A Promise resolving to an array of results
189
+ * @evidence contracts/common.md#principled-implementation A count outside the integer range 0 through 2^32 - 1 is refused with a `RangeError` before any callback, because JavaScript arrays cannot represent a larger length; otherwise the closure is awaited for each index from 0 to count minus one and the results are collected in order, so the cost is linear in the count with no index array.
190
+ * @evidence contracts/common.md#clear-and-simple-design One validation and one loop; the validator is shared with `repeat`.
191
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The loop is the direct implementation of the documented behavior, and an invalid count is an error, not a coerced number.
192
+ * @evidence contracts/common.md#meaningful-documentation The comment states the index range, the sequential execution, and the result, and the count must be a non-negative integer as documented.
135
193
  */
136
194
  const asyncRepeat: <T>(count: number, closure: (index: number) => Promise<T>) => Promise<T[]>;
137
195
  /**
@@ -140,29 +198,40 @@ export declare namespace ArrayUtil {
140
198
  * Similar to JavaScript's native some() method. Returns true immediately when
141
199
  * the first element satisfying the condition is found.
142
200
  *
201
+ * Processing cost: Native some stops at the first matching element:
202
+ * worst-case N predicate calls and constant auxiliary storage.
203
+ *
143
204
  * @example
144
- * ```typescript
145
205
  * const numbers = [1, 3, 5, 7, 8, 9];
146
206
  * const products = [
147
- * { name: 'Apple', price: 100, inStock: true },
148
- * { name: 'Banana', price: 50, inStock: false },
149
- * { name: 'Orange', price: 80, inStock: true }
207
+ * { name: "Apple", price: 100, inStock: true },
208
+ * { name: "Banana", price: 50, inStock: false },
209
+ * { name: "Orange", price: 80, inStock: true },
150
210
  * ];
151
211
  *
152
- * const hasEvenNumber = ArrayUtil.has(numbers, num => num % 2 === 0);
212
+ * const hasEvenNumber = ArrayUtil.has(numbers, (num) => num % 2 === 0);
153
213
  * console.log(hasEvenNumber); // true (8 exists)
154
214
  *
155
- * const hasExpensiveItem = ArrayUtil.has(products, product => product.price > 90);
215
+ * const hasExpensiveItem = ArrayUtil.has(
216
+ * products,
217
+ * (product) => product.price > 90,
218
+ * );
156
219
  * console.log(hasExpensiveItem); // true (Apple costs 100)
157
220
  *
158
- * const hasOutOfStock = ArrayUtil.has(products, product => !product.inStock);
221
+ * const hasOutOfStock = ArrayUtil.has(
222
+ * products,
223
+ * (product) => !product.inStock,
224
+ * );
159
225
  * console.log(hasOutOfStock); // true (Banana is out of stock)
160
- * ```;
161
226
  *
162
227
  * @template T - The type of elements in the array
163
228
  * @param elements - The readonly array to check
164
229
  * @param pred - The predicate function to test elements
165
230
  * @returns Boolean indicating if any element satisfies the condition
231
+ * @evidence contracts/common.md#principled-implementation The native `some` implements the existential search and returns at the first satisfying element, and the predicate receives only the element.
232
+ * @evidence contracts/common.md#clear-and-simple-design A one-expression delegation that keeps the native short-circuit visible.
233
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The predicate alone decides membership.
234
+ * @evidence contracts/common.md#meaningful-documentation The comment states the short-circuit and gives examples.
166
235
  */
167
236
  const has: <T>(elements: readonly T[], pred: (elem: T) => boolean) => boolean;
168
237
  /**
@@ -172,17 +241,19 @@ export declare namespace ArrayUtil {
172
241
  * A synchronous repetition function that executes the given function for each
173
242
  * index (from 0 to count-1) and collects the results into an array.
174
243
  *
244
+ * Processing cost: The callback runs once for each of N indices, with O(N)
245
+ * output storage.
246
+ *
175
247
  * @example
176
- * ```typescript
177
248
  * // Generate an array of squares from 1 to 5
178
- * const squares = ArrayUtil.repeat(5, index => (index + 1) ** 2);
249
+ * const squares = ArrayUtil.repeat(5, (index) => (index + 1) ** 2);
179
250
  * console.log(squares); // [1, 4, 9, 16, 25]
180
251
  *
181
252
  * // Generate an array of default user objects
182
- * const users = ArrayUtil.repeat(3, index => ({
183
- * id: index + 1,
184
- * name: `User${index + 1}`,
185
- * email: `user${index + 1}@example.com`
253
+ * const users = ArrayUtil.repeat(3, (index) => ({
254
+ * id: index + 1,
255
+ * name: `User${index + 1}`,
256
+ * email: `user${index + 1}@example.com`,
186
257
  * }));
187
258
  * console.log(users);
188
259
  * // [
@@ -190,12 +261,15 @@ export declare namespace ArrayUtil {
190
261
  * // { id: 2, name: 'User2', email: 'user2@example.com' },
191
262
  * // { id: 3, name: 'User3', email: 'user3@example.com' }
192
263
  * // ]
193
- * ```
194
264
  *
195
265
  * @template T - The type of the result from each execution
196
- * @param count - The number of times to repeat (non-negative integer)
266
+ * @param count - The number of times to repeat (integer from 0 to 2^32 - 1)
197
267
  * @param closure - The function to execute repeatedly
198
268
  * @returns An array of results
269
+ * @evidence contracts/common.md#principled-implementation An invalid count is refused with a `RangeError`, and otherwise the closure is called for each index from 0 to count minus one and the results are collected in order, with cost linear in the count.
270
+ * @evidence contracts/common.md#clear-and-simple-design The synchronous counterpart of `asyncRepeat`, sharing its validator.
271
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The loop implements the documented behavior directly.
272
+ * @evidence contracts/common.md#meaningful-documentation The comment states the index range and the result, with examples.
199
273
  */
200
274
  const repeat: <T>(count: number, closure: (index: number) => T) => T[];
201
275
  /**
@@ -203,42 +277,50 @@ export declare namespace ArrayUtil {
203
277
  *
204
278
  * Implements the mathematical concept of power set, generating 2^n subsets
205
279
  * from an array of n elements. Uses depth-first search (DFS) algorithm to
206
- * calculate all possible combinations of including or excluding each
207
- * element.
280
+ * calculate all possible combinations of including or excluding each element.
281
+ * Each element is included before it is excluded, so the first subset is the
282
+ * whole array and the last one is empty.
283
+ *
284
+ * Processing cost: The DFS visits the include/exclude tree and filters N
285
+ * input positions at each of 2^N leaves. This is O(N 2^N) time and
286
+ * materialized output space, the scale required by returning every subset,
287
+ * with O(N) recursion/mask state.
208
288
  *
209
289
  * @example
210
- * ```typescript
211
290
  * const numbers = [1, 2, 3];
212
291
  * const allSubsets = ArrayUtil.subsets(numbers);
213
292
  * console.log(allSubsets);
214
293
  * // [
215
- * // [], // empty set
216
- * // [3], // {3}
217
- * // [2], // {2}
218
- * // [2, 3], // {2, 3}
219
- * // [1], // {1}
220
- * // [1, 3], // {1, 3}
294
+ * // [1, 2, 3], // {1, 2, 3}
221
295
  * // [1, 2], // {1, 2}
222
- * // [1, 2, 3] // {1, 2, 3}
296
+ * // [1, 3], // {1, 3}
297
+ * // [1], // {1}
298
+ * // [2, 3], // {2, 3}
299
+ * // [2], // {2}
300
+ * // [3], // {3}
301
+ * // [] // empty set
223
302
  * // ]
224
303
  *
225
- * const colors = ['red', 'blue'];
304
+ * const colors = ["red", "blue"];
226
305
  * const colorSubsets = ArrayUtil.subsets(colors);
227
306
  * console.log(colorSubsets);
228
307
  * // [
229
- * // [],
230
- * // ['blue'],
308
+ * // ['red', 'blue'],
231
309
  * // ['red'],
232
- * // ['red', 'blue']
310
+ * // ['blue'],
311
+ * // []
233
312
  * // ]
234
313
  *
235
314
  * // Warning: Result size grows exponentially with array size
236
315
  * // Example: 10 elements → 1,024 subsets, 20 elements → 1,048,576 subsets
237
- * ```;
238
316
  *
239
317
  * @template T - The type of elements in the array
240
318
  * @param array - The array to generate subsets from
241
319
  * @returns An array containing all possible subsets
320
+ * @evidence contracts/common.md#principled-implementation A depth-first search decides for each position whether the element is in the subset, including it first, and each leaf materializes the chosen elements with `filter`, so the 2^n subsets appear in a fixed order, the whole array first and the empty array last; the recursion depth is the array length and the output size is exponential, which bounds the useful input size.
321
+ * @evidence contracts/common.md#clear-and-simple-design One recursive function over a mask, with no options.
322
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It enumerates every subset without sampling or a size cap, and the array is not mutated.
323
+ * @evidence contracts/common.md#meaningful-documentation The comment states the power-set meaning, the exact enumeration order, and the exponential growth warning, and the examples show that order.
242
324
  */
243
325
  const subsets: <T>(array: T[]) => T[][];
244
326
  }