@nestia/e2e 7.4.0 → 8.0.0-dev.20250829-2
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.
- package/LICENSE +21 -21
- package/README.md +93 -93
- package/lib/ArrayUtil.d.ts +36 -32
- package/lib/ArrayUtil.js +134 -148
- package/lib/ArrayUtil.js.map +1 -1
- package/lib/GaffComparator.d.ts +19 -12
- package/lib/GaffComparator.js +19 -12
- package/lib/GaffComparator.js.map +1 -1
- package/lib/MapUtil.d.ts +79 -0
- package/lib/MapUtil.js +92 -0
- package/lib/MapUtil.js.map +1 -0
- package/lib/RandomGenerator.d.ts +107 -71
- package/lib/RandomGenerator.js +124 -109
- package/lib/RandomGenerator.js.map +1 -1
- package/lib/TestValidator.d.ts +107 -145
- package/lib/TestValidator.js +308 -351
- package/lib/TestValidator.js.map +1 -1
- package/lib/module.d.ts +2 -1
- package/lib/module.js +2 -1
- package/lib/module.js.map +1 -1
- package/package.json +1 -1
- package/src/ArrayUtil.ts +89 -91
- package/src/GaffComparator.ts +19 -12
- package/src/MapUtil.ts +86 -0
- package/src/RandomGenerator.ts +138 -101
- package/src/TestValidator.ts +251 -294
- package/src/module.ts +3 -1
package/lib/TestValidator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAoD;AACpD,0DAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,IAAiB,aAAa,
|
|
1
|
+
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA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CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;IACnD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/lib/module.d.ts
CHANGED
package/lib/module.js
CHANGED
|
@@ -15,8 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./ArrayUtil"), exports);
|
|
18
|
+
__exportStar(require("./MapUtil"), exports);
|
|
19
|
+
__exportStar(require("./RandomGenerator"), exports);
|
|
18
20
|
__exportStar(require("./DynamicExecutor"), exports);
|
|
19
21
|
__exportStar(require("./GaffComparator"), exports);
|
|
20
|
-
__exportStar(require("./RandomGenerator"), exports);
|
|
21
22
|
__exportStar(require("./TestValidator"), exports);
|
|
22
23
|
//# sourceMappingURL=module.js.map
|
package/lib/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,oDAAkC;AAClC,mDAAiC;AACjC,
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,4CAA0B;AAC1B,oDAAkC;AAElC,oDAAkC;AAClC,mDAAiC;AACjC,kDAAgC"}
|
package/package.json
CHANGED
package/src/ArrayUtil.ts
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This namespace contains utility functions for array operations including
|
|
5
5
|
* asynchronous processing, filtering, mapping, and repetition tasks implemented
|
|
6
|
-
* in functional programming style.
|
|
7
|
-
*
|
|
6
|
+
* in functional programming style. Functions use direct parameter passing for
|
|
7
|
+
* simplicity while maintaining functional programming principles.
|
|
8
8
|
*
|
|
9
9
|
* @author Jeongho Nam - https://github.com/samchon
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
12
12
|
* // Asynchronous filtering example
|
|
13
13
|
* const numbers = [1, 2, 3, 4, 5];
|
|
14
|
-
* const evenNumbers = await ArrayUtil.asyncFilter(numbers
|
|
14
|
+
* const evenNumbers = await ArrayUtil.asyncFilter(numbers,
|
|
15
15
|
* async (num) => num % 2 === 0
|
|
16
16
|
* );
|
|
17
17
|
* console.log(evenNumbers); // [2, 4]
|
|
@@ -22,9 +22,9 @@ export namespace ArrayUtil {
|
|
|
22
22
|
* Filters an array by applying an asynchronous predicate function to each
|
|
23
23
|
* element.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* Elements are processed sequentially, ensuring order is maintained. The
|
|
26
|
+
* predicate function receives the element, index, and the full array as
|
|
27
|
+
* parameters.
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```typescript
|
|
@@ -34,7 +34,7 @@ export namespace ArrayUtil {
|
|
|
34
34
|
* { id: 3, name: 'Charlie', active: true }
|
|
35
35
|
* ];
|
|
36
36
|
*
|
|
37
|
-
* const activeUsers = await ArrayUtil.asyncFilter(users
|
|
37
|
+
* const activeUsers = await ArrayUtil.asyncFilter(users,
|
|
38
38
|
* async (user) => {
|
|
39
39
|
* // Async validation logic (e.g., API call)
|
|
40
40
|
* await new Promise(resolve => setTimeout(resolve, 100));
|
|
@@ -46,25 +46,24 @@ export namespace ArrayUtil {
|
|
|
46
46
|
*
|
|
47
47
|
* @template Input - The type of elements in the input array
|
|
48
48
|
* @param elements - The readonly array to filter
|
|
49
|
-
* @
|
|
50
|
-
*
|
|
49
|
+
* @param pred - The asynchronous predicate function to test each element
|
|
50
|
+
* @returns A Promise resolving to the filtered array
|
|
51
51
|
*/
|
|
52
|
-
export const asyncFilter =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
await
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
52
|
+
export const asyncFilter = async <Input>(
|
|
53
|
+
elements: readonly Input[],
|
|
54
|
+
pred: (
|
|
55
|
+
elem: Input,
|
|
56
|
+
index: number,
|
|
57
|
+
array: readonly Input[],
|
|
58
|
+
) => Promise<boolean>,
|
|
59
|
+
): Promise<Input[]> => {
|
|
60
|
+
const ret: Input[] = [];
|
|
61
|
+
await asyncForEach(elements, async (elem, index, array) => {
|
|
62
|
+
const flag: boolean = await pred(elem, index, array);
|
|
63
|
+
if (flag === true) ret.push(elem);
|
|
64
|
+
});
|
|
65
|
+
return ret;
|
|
66
|
+
};
|
|
68
67
|
|
|
69
68
|
/**
|
|
70
69
|
* Executes an asynchronous function for each element in an array
|
|
@@ -79,7 +78,7 @@ export namespace ArrayUtil {
|
|
|
79
78
|
* ```typescript
|
|
80
79
|
* const urls = ['url1', 'url2', 'url3'];
|
|
81
80
|
*
|
|
82
|
-
* await ArrayUtil.asyncForEach(urls
|
|
81
|
+
* await ArrayUtil.asyncForEach(urls, async (url, index) => {
|
|
83
82
|
* console.log(`Processing ${index}: ${url}`);
|
|
84
83
|
* const data = await fetch(url);
|
|
85
84
|
* await processData(data);
|
|
@@ -90,21 +89,21 @@ export namespace ArrayUtil {
|
|
|
90
89
|
*
|
|
91
90
|
* @template Input - The type of elements in the input array
|
|
92
91
|
* @param elements - The readonly array to process
|
|
93
|
-
* @
|
|
92
|
+
* @param closure - The asynchronous function to execute for each element
|
|
93
|
+
* @returns A Promise<void> that resolves when all operations complete
|
|
94
94
|
*/
|
|
95
|
-
export const asyncForEach =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
};
|
|
95
|
+
export const asyncForEach = async <Input>(
|
|
96
|
+
elements: readonly Input[],
|
|
97
|
+
closure: (
|
|
98
|
+
elem: Input,
|
|
99
|
+
index: number,
|
|
100
|
+
array: readonly Input[],
|
|
101
|
+
) => Promise<any>,
|
|
102
|
+
): Promise<void> => {
|
|
103
|
+
await asyncRepeat(elements.length, (index) =>
|
|
104
|
+
closure(elements[index], index, elements),
|
|
105
|
+
);
|
|
106
|
+
};
|
|
108
107
|
|
|
109
108
|
/**
|
|
110
109
|
* Transforms each element of an array using an asynchronous function to
|
|
@@ -112,7 +111,8 @@ export namespace ArrayUtil {
|
|
|
112
111
|
*
|
|
113
112
|
* Similar to JavaScript's native map but processes asynchronous functions
|
|
114
113
|
* sequentially. Each element's transformation is completed before proceeding
|
|
115
|
-
* to the next element, ensuring order is maintained.
|
|
114
|
+
* to the next element, ensuring order is maintained. This function still
|
|
115
|
+
* maintains the currying pattern for composition.
|
|
116
116
|
*
|
|
117
117
|
* @example
|
|
118
118
|
* ```typescript
|
|
@@ -129,27 +129,25 @@ export namespace ArrayUtil {
|
|
|
129
129
|
* ```
|
|
130
130
|
*
|
|
131
131
|
* @template Input - The type of elements in the input array
|
|
132
|
-
* @template Output - The type of elements in the output array
|
|
133
132
|
* @param elements - The readonly array to transform
|
|
134
133
|
* @returns A function that takes a transformation function and returns a
|
|
135
134
|
* Promise resolving to the transformed array
|
|
136
135
|
*/
|
|
137
|
-
export const asyncMap =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
await
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
136
|
+
export const asyncMap = async <Input, Output>(
|
|
137
|
+
elements: readonly Input[],
|
|
138
|
+
closure: (
|
|
139
|
+
elem: Input,
|
|
140
|
+
index: number,
|
|
141
|
+
array: readonly Input[],
|
|
142
|
+
) => Promise<Output>,
|
|
143
|
+
): Promise<Output[]> => {
|
|
144
|
+
const ret: Output[] = [];
|
|
145
|
+
await asyncForEach(elements, async (elem, index, array) => {
|
|
146
|
+
const output: Output = await closure(elem, index, array);
|
|
147
|
+
ret.push(output);
|
|
148
|
+
});
|
|
149
|
+
return ret;
|
|
150
|
+
};
|
|
153
151
|
|
|
154
152
|
/**
|
|
155
153
|
* Executes an asynchronous function a specified number of times sequentially.
|
|
@@ -161,7 +159,7 @@ export namespace ArrayUtil {
|
|
|
161
159
|
* @example
|
|
162
160
|
* ```typescript
|
|
163
161
|
* // Generate random data 5 times
|
|
164
|
-
* const randomData = await ArrayUtil.asyncRepeat(5
|
|
162
|
+
* const randomData = await ArrayUtil.asyncRepeat(5, async (index) => {
|
|
165
163
|
* await new Promise(resolve => setTimeout(resolve, 100)); // Wait 0.1 seconds
|
|
166
164
|
* return {
|
|
167
165
|
* id: index,
|
|
@@ -172,29 +170,26 @@ export namespace ArrayUtil {
|
|
|
172
170
|
* console.log('Generated data:', randomData);
|
|
173
171
|
* ```;
|
|
174
172
|
*
|
|
173
|
+
* @template T - The type of the result from each execution
|
|
175
174
|
* @param count - The number of times to repeat (non-negative integer)
|
|
176
|
-
* @
|
|
177
|
-
*
|
|
175
|
+
* @param closure - The asynchronous function to execute repeatedly
|
|
176
|
+
* @returns A Promise resolving to an array of results
|
|
178
177
|
*/
|
|
179
|
-
export const asyncRepeat =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return output;
|
|
190
|
-
};
|
|
178
|
+
export const asyncRepeat = async <T>(
|
|
179
|
+
count: number,
|
|
180
|
+
closure: (index: number) => Promise<T>,
|
|
181
|
+
): Promise<T[]> => {
|
|
182
|
+
const indexes: number[] = new Array(count).fill(1).map((_, index) => index);
|
|
183
|
+
const output: T[] = [];
|
|
184
|
+
for (const index of indexes) output.push(await closure(index));
|
|
185
|
+
return output;
|
|
186
|
+
};
|
|
191
187
|
|
|
192
188
|
/**
|
|
193
189
|
* Checks if at least one element in the array satisfies the given condition.
|
|
194
190
|
*
|
|
195
|
-
* Similar to JavaScript's native some() method
|
|
196
|
-
*
|
|
197
|
-
* true immediately when the first element satisfying the condition is found.
|
|
191
|
+
* Similar to JavaScript's native some() method. Returns true immediately when
|
|
192
|
+
* the first element satisfying the condition is found.
|
|
198
193
|
*
|
|
199
194
|
* @example
|
|
200
195
|
* ```typescript
|
|
@@ -205,24 +200,25 @@ export namespace ArrayUtil {
|
|
|
205
200
|
* { name: 'Orange', price: 80, inStock: true }
|
|
206
201
|
* ];
|
|
207
202
|
*
|
|
208
|
-
* const hasEvenNumber = ArrayUtil.has(numbers
|
|
203
|
+
* const hasEvenNumber = ArrayUtil.has(numbers, num => num % 2 === 0);
|
|
209
204
|
* console.log(hasEvenNumber); // true (8 exists)
|
|
210
205
|
*
|
|
211
|
-
* const hasExpensiveItem = ArrayUtil.has(products
|
|
206
|
+
* const hasExpensiveItem = ArrayUtil.has(products, product => product.price > 90);
|
|
212
207
|
* console.log(hasExpensiveItem); // true (Apple costs 100)
|
|
213
208
|
*
|
|
214
|
-
* const hasOutOfStock = ArrayUtil.has(products
|
|
209
|
+
* const hasOutOfStock = ArrayUtil.has(products, product => !product.inStock);
|
|
215
210
|
* console.log(hasOutOfStock); // true (Banana is out of stock)
|
|
216
211
|
* ```;
|
|
217
212
|
*
|
|
218
213
|
* @template T - The type of elements in the array
|
|
219
214
|
* @param elements - The readonly array to check
|
|
220
|
-
* @
|
|
215
|
+
* @param pred - The predicate function to test elements
|
|
216
|
+
* @returns Boolean indicating if any element satisfies the condition
|
|
221
217
|
*/
|
|
222
|
-
export const has =
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
218
|
+
export const has = <T>(
|
|
219
|
+
elements: readonly T[],
|
|
220
|
+
pred: (elem: T) => boolean,
|
|
221
|
+
): boolean => elements.find(pred) !== undefined;
|
|
226
222
|
|
|
227
223
|
/**
|
|
228
224
|
* Executes a function a specified number of times and collects the results
|
|
@@ -234,11 +230,11 @@ export namespace ArrayUtil {
|
|
|
234
230
|
* @example
|
|
235
231
|
* ```typescript
|
|
236
232
|
* // Generate an array of squares from 1 to 5
|
|
237
|
-
* const squares = ArrayUtil.repeat(5
|
|
233
|
+
* const squares = ArrayUtil.repeat(5, index => (index + 1) ** 2);
|
|
238
234
|
* console.log(squares); // [1, 4, 9, 16, 25]
|
|
239
235
|
*
|
|
240
236
|
* // Generate an array of default user objects
|
|
241
|
-
* const users = ArrayUtil.repeat(3
|
|
237
|
+
* const users = ArrayUtil.repeat(3, index => ({
|
|
242
238
|
* id: index + 1,
|
|
243
239
|
* name: `User${index + 1}`,
|
|
244
240
|
* email: `user${index + 1}@example.com`
|
|
@@ -251,13 +247,15 @@ export namespace ArrayUtil {
|
|
|
251
247
|
* // ]
|
|
252
248
|
* ```
|
|
253
249
|
*
|
|
250
|
+
* @template T - The type of the result from each execution
|
|
254
251
|
* @param count - The number of times to repeat (non-negative integer)
|
|
255
|
-
* @
|
|
252
|
+
* @param closure - The function to execute repeatedly
|
|
253
|
+
* @returns An array of results
|
|
256
254
|
*/
|
|
257
|
-
export const repeat =
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
255
|
+
export const repeat = <T>(
|
|
256
|
+
count: number,
|
|
257
|
+
closure: (index: number) => T,
|
|
258
|
+
): T[] => new Array(count).fill("").map((_, index) => closure(index));
|
|
261
259
|
|
|
262
260
|
/**
|
|
263
261
|
* Generates all possible subsets of a given array.
|
package/src/GaffComparator.ts
CHANGED
|
@@ -34,12 +34,14 @@
|
|
|
34
34
|
* users.sort(GaffComparator.strings(user => [user.lastName, user.firstName]));
|
|
35
35
|
* events.sort(GaffComparator.dates(event => [event.startDate, event.endDate]));
|
|
36
36
|
*
|
|
37
|
-
* // Integration with TestValidator
|
|
38
|
-
*
|
|
37
|
+
* // Integration with TestValidator's currying pattern
|
|
38
|
+
* const validator = TestValidator.sort("user sorting",
|
|
39
39
|
* (sortable) => api.getUsers({ sort: sortable })
|
|
40
40
|
* )("name", "email")(
|
|
41
41
|
* GaffComparator.strings(user => [user.name, user.email])
|
|
42
|
-
* )
|
|
42
|
+
* );
|
|
43
|
+
* await validator("+"); // ascending
|
|
44
|
+
* await validator("-"); // descending
|
|
43
45
|
* ```;
|
|
44
46
|
*/
|
|
45
47
|
export namespace GaffComparator {
|
|
@@ -87,12 +89,14 @@ export namespace GaffComparator {
|
|
|
87
89
|
* // Complex multi-field: status, then last name, then first name
|
|
88
90
|
* users.sort(GaffComparator.strings(user => [user.status, user.lastName, user.firstName]));
|
|
89
91
|
*
|
|
90
|
-
* // Integration with
|
|
91
|
-
*
|
|
92
|
+
* // Integration with TestValidator sorting validation
|
|
93
|
+
* const sortValidator = TestValidator.sort("user name sorting",
|
|
92
94
|
* (sortFields) => userApi.getUsers({ sort: sortFields })
|
|
93
95
|
* )("lastName", "firstName")(
|
|
94
96
|
* GaffComparator.strings(user => [user.lastName, user.firstName])
|
|
95
|
-
* )
|
|
97
|
+
* );
|
|
98
|
+
* await sortValidator("+"); // test ascending order
|
|
99
|
+
* await sortValidator("-"); // test descending order
|
|
96
100
|
* ```;
|
|
97
101
|
*
|
|
98
102
|
* @template T - The type of objects being compared
|
|
@@ -165,12 +169,13 @@ export namespace GaffComparator {
|
|
|
165
169
|
* // Sort by modification history: created date, then updated date
|
|
166
170
|
* events.sort(GaffComparator.dates(event => [event.createdAt, event.updatedAt]));
|
|
167
171
|
*
|
|
168
|
-
* // Validate API date sorting
|
|
169
|
-
*
|
|
172
|
+
* // Validate API date sorting with TestValidator
|
|
173
|
+
* const dateValidator = TestValidator.sort("event chronological sorting",
|
|
170
174
|
* (sortFields) => eventApi.getEvents({ sort: sortFields })
|
|
171
175
|
* )("startDate")(
|
|
172
176
|
* GaffComparator.dates(event => event.startDate)
|
|
173
|
-
* )
|
|
177
|
+
* );
|
|
178
|
+
* await dateValidator("+", true); // ascending with trace logging
|
|
174
179
|
*
|
|
175
180
|
* // Test complex date-based sorting
|
|
176
181
|
* const sortByEventSchedule = GaffComparator.dates(event => [
|
|
@@ -245,12 +250,14 @@ export namespace GaffComparator {
|
|
|
245
250
|
* // Sort by inventory priority: low stock first, then by sales
|
|
246
251
|
* products.sort(GaffComparator.numbers(product => [product.stock, -product.salesCount]));
|
|
247
252
|
*
|
|
248
|
-
* // Validate API numerical sorting
|
|
249
|
-
*
|
|
253
|
+
* // Validate API numerical sorting with TestValidator
|
|
254
|
+
* const priceValidator = TestValidator.sort("product price sorting",
|
|
250
255
|
* (sortFields) => productApi.getProducts({ sort: sortFields })
|
|
251
256
|
* )("price")(
|
|
252
257
|
* GaffComparator.numbers(product => product.price)
|
|
253
|
-
* )
|
|
258
|
+
* );
|
|
259
|
+
* await priceValidator("+"); // test ascending order
|
|
260
|
+
* await priceValidator("-"); // test descending order
|
|
254
261
|
*
|
|
255
262
|
* // Test multi-criteria sorting
|
|
256
263
|
* const sortByBusinessValue = GaffComparator.numbers(product => [
|
package/src/MapUtil.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A namespace providing utility functions for Map manipulation.
|
|
3
|
+
*
|
|
4
|
+
* This namespace contains helper functions for working with JavaScript Map
|
|
5
|
+
* objects, providing convenient methods for common Map operations like
|
|
6
|
+
* retrieving values with lazy initialization.
|
|
7
|
+
*
|
|
8
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Create a cache with lazy initialization
|
|
12
|
+
* const cache = new Map<string, ExpensiveObject>();
|
|
13
|
+
*
|
|
14
|
+
* const obj = MapUtil.take(cache, "key1", () => {
|
|
15
|
+
* console.log("Creating expensive object...");
|
|
16
|
+
* return new ExpensiveObject();
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Subsequent calls return cached value without re-creating
|
|
20
|
+
* const sameObj = MapUtil.take(cache, "key1", () => new ExpensiveObject());
|
|
21
|
+
* console.log(obj === sameObj); // true
|
|
22
|
+
* ```;
|
|
23
|
+
*/
|
|
24
|
+
export namespace MapUtil {
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves a value from a Map or creates it using a lazy initialization
|
|
27
|
+
* function.
|
|
28
|
+
*
|
|
29
|
+
* This function implements the "get or create" pattern for Maps. If the key
|
|
30
|
+
* exists in the Map, it returns the existing value. Otherwise, it calls the
|
|
31
|
+
* provided factory function to create a new value, stores it in the Map, and
|
|
32
|
+
* returns it. The factory function is only called when the key doesn't exist,
|
|
33
|
+
* enabling lazy initialization and caching patterns.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Simple caching example
|
|
38
|
+
* const userCache = new Map<number, User>();
|
|
39
|
+
*
|
|
40
|
+
* const user = MapUtil.take(userCache, userId, () => {
|
|
41
|
+
* // This expensive operation only runs if userId is not cached
|
|
42
|
+
* return fetchUserFromDatabase(userId);
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Configuration object caching
|
|
46
|
+
* const configs = new Map<string, Config>();
|
|
47
|
+
*
|
|
48
|
+
* const dbConfig = MapUtil.take(configs, "database", () => ({
|
|
49
|
+
* host: "localhost",
|
|
50
|
+
* port: 5432,
|
|
51
|
+
* database: "myapp"
|
|
52
|
+
* }));
|
|
53
|
+
*
|
|
54
|
+
* // Lazy computation results
|
|
55
|
+
* const computationCache = new Map<string, number>();
|
|
56
|
+
*
|
|
57
|
+
* const result = MapUtil.take(computationCache, "fibonacci-40", () => {
|
|
58
|
+
* console.log("Computing fibonacci(40)...");
|
|
59
|
+
* return fibonacci(40); // Only computed once
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Using with complex keys
|
|
63
|
+
* const cache = new Map<[number, number], Matrix>();
|
|
64
|
+
* const key: [number, number] = [rows, cols];
|
|
65
|
+
*
|
|
66
|
+
* const matrix = MapUtil.take(cache, key, () =>
|
|
67
|
+
* generateIdentityMatrix(rows, cols)
|
|
68
|
+
* );
|
|
69
|
+
* ```;
|
|
70
|
+
*
|
|
71
|
+
* @template K - The type of keys in the Map
|
|
72
|
+
* @template V - The type of values in the Map
|
|
73
|
+
* @param map - The Map to retrieve from or update
|
|
74
|
+
* @param key - The key to look up in the Map
|
|
75
|
+
* @param value - A factory function that creates the value if key doesn't exist
|
|
76
|
+
* @returns The existing value if found, or the newly created value
|
|
77
|
+
*/
|
|
78
|
+
export function take<K, V>(map: Map<K, V>, key: K, value: () => V): V {
|
|
79
|
+
if (map.has(key)) {
|
|
80
|
+
return map.get(key) as V;
|
|
81
|
+
}
|
|
82
|
+
const newValue = value();
|
|
83
|
+
map.set(key, newValue);
|
|
84
|
+
return newValue;
|
|
85
|
+
}
|
|
86
|
+
}
|