@nestia/e2e 10.0.2 → 11.0.0-dev.20260305
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/package.json +19 -21
- package/src/ArrayUtil.ts +320 -320
- package/src/DynamicExecutor.ts +274 -274
- package/src/GaffComparator.ts +287 -287
- package/src/MapUtil.ts +86 -86
- package/src/RandomGenerator.ts +490 -490
- package/src/TestValidator.ts +635 -635
- package/src/index.ts +4 -4
- package/src/internal/json_equal_to.ts +35 -35
- package/src/module.ts +7 -7
- package/lib/ArrayUtil.d.ts +0 -244
- package/lib/ArrayUtil.js +0 -410
- package/lib/ArrayUtil.js.map +0 -1
- package/lib/DynamicExecutor.d.ts +0 -144
- package/lib/DynamicExecutor.js +0 -373
- package/lib/DynamicExecutor.js.map +0 -1
- package/lib/GaffComparator.d.ts +0 -255
- package/lib/GaffComparator.js +0 -286
- package/lib/GaffComparator.js.map +0 -1
- package/lib/MapUtil.d.ts +0 -79
- package/lib/MapUtil.js +0 -92
- package/lib/MapUtil.js.map +0 -1
- package/lib/RandomGenerator.d.ts +0 -416
- package/lib/RandomGenerator.js +0 -480
- package/lib/RandomGenerator.js.map +0 -1
- package/lib/TestValidator.d.ts +0 -389
- package/lib/TestValidator.js +0 -643
- package/lib/TestValidator.js.map +0 -1
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -42
- package/lib/index.js.map +0 -1
- package/lib/internal/json_equal_to.d.ts +0 -1
- package/lib/internal/json_equal_to.js +0 -51
- package/lib/internal/json_equal_to.js.map +0 -1
- package/lib/module.d.ts +0 -6
- package/lib/module.js +0 -23
- package/lib/module.js.map +0 -1
package/lib/GaffComparator.js
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GaffComparator = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Type-safe comparator functions for Array.sort() operations with advanced
|
|
6
|
-
* field access.
|
|
7
|
-
*
|
|
8
|
-
* GaffComparator provides a collection of specialized comparator functions
|
|
9
|
-
* designed to work seamlessly with Array.sort() and testing frameworks like
|
|
10
|
-
* TestValidator.sort(). Each comparator supports both single values and arrays
|
|
11
|
-
* of values, enabling complex multi-field sorting scenarios with lexicographic
|
|
12
|
-
* ordering.
|
|
13
|
-
*
|
|
14
|
-
* Key features:
|
|
15
|
-
*
|
|
16
|
-
* - Generic type safety for any object structure
|
|
17
|
-
* - Support for single values or arrays of values per field
|
|
18
|
-
* - Lexicographic comparison for multi-value scenarios
|
|
19
|
-
* - Locale-aware string comparison
|
|
20
|
-
* - Automatic type conversion for dates and numbers
|
|
21
|
-
*
|
|
22
|
-
* The comparators follow the standard JavaScript sort contract:
|
|
23
|
-
*
|
|
24
|
-
* - Return < 0 if first element should come before second
|
|
25
|
-
* - Return > 0 if first element should come after second
|
|
26
|
-
* - Return 0 if elements are equal
|
|
27
|
-
*
|
|
28
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* // Basic usage with single fields
|
|
32
|
-
* users.sort(GaffComparator.strings(user => user.name));
|
|
33
|
-
* posts.sort(GaffComparator.dates(post => post.createdAt));
|
|
34
|
-
* products.sort(GaffComparator.numbers(product => product.price));
|
|
35
|
-
*
|
|
36
|
-
* // Multi-field sorting with arrays
|
|
37
|
-
* users.sort(GaffComparator.strings(user => [user.lastName, user.firstName]));
|
|
38
|
-
* events.sort(GaffComparator.dates(event => [event.startDate, event.endDate]));
|
|
39
|
-
*
|
|
40
|
-
* // Integration with TestValidator's currying pattern
|
|
41
|
-
* const validator = TestValidator.sort("user sorting",
|
|
42
|
-
* (sortable) => api.getUsers({ sort: sortable })
|
|
43
|
-
* )("name", "email")(
|
|
44
|
-
* GaffComparator.strings(user => [user.name, user.email])
|
|
45
|
-
* );
|
|
46
|
-
* await validator("+"); // ascending
|
|
47
|
-
* await validator("-"); // descending
|
|
48
|
-
* ```;
|
|
49
|
-
*/
|
|
50
|
-
var GaffComparator;
|
|
51
|
-
(function (GaffComparator) {
|
|
52
|
-
/**
|
|
53
|
-
* Creates a comparator function for string-based sorting with locale-aware
|
|
54
|
-
* comparison.
|
|
55
|
-
*
|
|
56
|
-
* Generates a comparator that extracts string values from objects and
|
|
57
|
-
* performs lexicographic comparison using locale-sensitive string comparison.
|
|
58
|
-
* Supports both single strings and arrays of strings for multi-field sorting
|
|
59
|
-
* scenarios.
|
|
60
|
-
*
|
|
61
|
-
* When comparing arrays, performs lexicographic ordering: compares the first
|
|
62
|
-
* elements, then the second elements if the first are equal, and so on. This
|
|
63
|
-
* enables complex sorting like "sort by last name, then by first name".
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* interface User {
|
|
68
|
-
* id: string;
|
|
69
|
-
* firstName: string;
|
|
70
|
-
* lastName: string;
|
|
71
|
-
* email: string;
|
|
72
|
-
* status: 'active' | 'inactive';
|
|
73
|
-
* }
|
|
74
|
-
*
|
|
75
|
-
* const users: User[] = [
|
|
76
|
-
* { id: '1', firstName: 'John', lastName: 'Doe', email: 'john@example.com', status: 'active' },
|
|
77
|
-
* { id: '2', firstName: 'Jane', lastName: 'Doe', email: 'jane@example.com', status: 'inactive' },
|
|
78
|
-
* { id: '3', firstName: 'Bob', lastName: 'Smith', email: 'bob@example.com', status: 'active' }
|
|
79
|
-
* ];
|
|
80
|
-
*
|
|
81
|
-
* // Single field sorting
|
|
82
|
-
* users.sort(GaffComparator.strings(user => user.lastName));
|
|
83
|
-
* // Result: Doe, Doe, Smith
|
|
84
|
-
*
|
|
85
|
-
* // Multi-field sorting: last name, then first name
|
|
86
|
-
* users.sort(GaffComparator.strings(user => [user.lastName, user.firstName]));
|
|
87
|
-
* // Result: Doe Jane, Doe John, Smith Bob
|
|
88
|
-
*
|
|
89
|
-
* // Status-based sorting
|
|
90
|
-
* users.sort(GaffComparator.strings(user => user.status));
|
|
91
|
-
* // Result: active users first, then inactive
|
|
92
|
-
*
|
|
93
|
-
* // Complex multi-field: status, then last name, then first name
|
|
94
|
-
* users.sort(GaffComparator.strings(user => [user.status, user.lastName, user.firstName]));
|
|
95
|
-
*
|
|
96
|
-
* // Integration with TestValidator sorting validation
|
|
97
|
-
* const sortValidator = TestValidator.sort("user name sorting",
|
|
98
|
-
* (sortFields) => userApi.getUsers({ sort: sortFields })
|
|
99
|
-
* )("lastName", "firstName")(
|
|
100
|
-
* GaffComparator.strings(user => [user.lastName, user.firstName])
|
|
101
|
-
* );
|
|
102
|
-
* await sortValidator("+"); // test ascending order
|
|
103
|
-
* await sortValidator("-"); // test descending order
|
|
104
|
-
* ```;
|
|
105
|
-
*
|
|
106
|
-
* @template T - The type of objects being compared
|
|
107
|
-
* @param getter - Function that extracts string value(s) from input objects
|
|
108
|
-
* @returns A comparator function suitable for Array.sort()
|
|
109
|
-
*/
|
|
110
|
-
GaffComparator.strings = function (getter) {
|
|
111
|
-
return function (x, y) {
|
|
112
|
-
var a = wrap(getter(x));
|
|
113
|
-
var b = wrap(getter(y));
|
|
114
|
-
var idx = a.findIndex(function (v, i) { return v !== b[i]; });
|
|
115
|
-
return idx !== -1 ? compare(a[idx], b[idx]) : 0;
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* Creates a comparator function for date-based sorting with automatic string
|
|
120
|
-
* parsing.
|
|
121
|
-
*
|
|
122
|
-
* Generates a comparator that extracts date values from objects,
|
|
123
|
-
* automatically converting string representations to Date objects for
|
|
124
|
-
* numerical comparison. Supports both single dates and arrays of dates for
|
|
125
|
-
* complex temporal sorting.
|
|
126
|
-
*
|
|
127
|
-
* Date strings are parsed using the standard Date constructor, which supports
|
|
128
|
-
* ISO 8601 format, RFC 2822 format, and other common date representations.
|
|
129
|
-
* The comparison is performed on millisecond timestamps for precise
|
|
130
|
-
* ordering.
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* interface Event {
|
|
135
|
-
* id: string;
|
|
136
|
-
* title: string;
|
|
137
|
-
* startDate: string;
|
|
138
|
-
* endDate: string;
|
|
139
|
-
* createdAt: string;
|
|
140
|
-
* updatedAt: string;
|
|
141
|
-
* }
|
|
142
|
-
*
|
|
143
|
-
* const events: Event[] = [
|
|
144
|
-
* {
|
|
145
|
-
* id: '1',
|
|
146
|
-
* title: 'Conference',
|
|
147
|
-
* startDate: '2024-03-15T09:00:00Z',
|
|
148
|
-
* endDate: '2024-03-15T17:00:00Z',
|
|
149
|
-
* createdAt: '2024-01-10T10:00:00Z',
|
|
150
|
-
* updatedAt: '2024-02-01T15:30:00Z'
|
|
151
|
-
* },
|
|
152
|
-
* {
|
|
153
|
-
* id: '2',
|
|
154
|
-
* title: 'Workshop',
|
|
155
|
-
* startDate: '2024-03-10T14:00:00Z',
|
|
156
|
-
* endDate: '2024-03-10T16:00:00Z',
|
|
157
|
-
* createdAt: '2024-01-15T11:00:00Z',
|
|
158
|
-
* updatedAt: '2024-01-20T09:15:00Z'
|
|
159
|
-
* }
|
|
160
|
-
* ];
|
|
161
|
-
*
|
|
162
|
-
* // Sort by start date (chronological order)
|
|
163
|
-
* events.sort(GaffComparator.dates(event => event.startDate));
|
|
164
|
-
*
|
|
165
|
-
* // Sort by creation date (oldest first)
|
|
166
|
-
* events.sort(GaffComparator.dates(event => event.createdAt));
|
|
167
|
-
*
|
|
168
|
-
* // Multi-field: start date, then end date
|
|
169
|
-
* events.sort(GaffComparator.dates(event => [event.startDate, event.endDate]));
|
|
170
|
-
*
|
|
171
|
-
* // Sort by modification history: created date, then updated date
|
|
172
|
-
* events.sort(GaffComparator.dates(event => [event.createdAt, event.updatedAt]));
|
|
173
|
-
*
|
|
174
|
-
* // Validate API date sorting with TestValidator
|
|
175
|
-
* const dateValidator = TestValidator.sort("event chronological sorting",
|
|
176
|
-
* (sortFields) => eventApi.getEvents({ sort: sortFields })
|
|
177
|
-
* )("startDate")(
|
|
178
|
-
* GaffComparator.dates(event => event.startDate)
|
|
179
|
-
* );
|
|
180
|
-
* await dateValidator("+", true); // ascending with trace logging
|
|
181
|
-
*
|
|
182
|
-
* // Test complex date-based sorting
|
|
183
|
-
* const sortByEventSchedule = GaffComparator.dates(event => [
|
|
184
|
-
* event.startDate,
|
|
185
|
-
* event.endDate
|
|
186
|
-
* ]);
|
|
187
|
-
* ```;
|
|
188
|
-
*
|
|
189
|
-
* @template T - The type of objects being compared
|
|
190
|
-
* @param getter - Function that extracts date string(s) from input objects
|
|
191
|
-
* @returns A comparator function suitable for Array.sort()
|
|
192
|
-
*/
|
|
193
|
-
GaffComparator.dates = function (getter) {
|
|
194
|
-
return function (x, y) {
|
|
195
|
-
var take = function (v) {
|
|
196
|
-
return wrap(getter(v)).map(function (str) { return new Date(str).getTime(); });
|
|
197
|
-
};
|
|
198
|
-
var a = take(x);
|
|
199
|
-
var b = take(y);
|
|
200
|
-
var idx = a.findIndex(function (v, i) { return v !== b[i]; });
|
|
201
|
-
return idx !== -1 ? a[idx] - b[idx] : 0;
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
/**
|
|
205
|
-
* Creates a comparator function for numerical sorting with multi-value
|
|
206
|
-
* support.
|
|
207
|
-
*
|
|
208
|
-
* Generates a comparator that extracts numerical values from objects and
|
|
209
|
-
* performs mathematical comparison. Supports both single numbers and arrays
|
|
210
|
-
* of numbers for complex numerical sorting scenarios like sorting by price
|
|
211
|
-
* then by rating.
|
|
212
|
-
*
|
|
213
|
-
* When comparing arrays, performs lexicographic numerical ordering: compares
|
|
214
|
-
* the first numbers, then the second numbers if the first are equal, and so
|
|
215
|
-
* on. This enables sophisticated sorting like "sort by price ascending, then
|
|
216
|
-
* by rating descending".
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* ```typescript
|
|
220
|
-
* interface Product {
|
|
221
|
-
* id: string;
|
|
222
|
-
* name: string;
|
|
223
|
-
* price: number;
|
|
224
|
-
* rating: number;
|
|
225
|
-
* stock: number;
|
|
226
|
-
* categoryId: number;
|
|
227
|
-
* salesCount: number;
|
|
228
|
-
* }
|
|
229
|
-
*
|
|
230
|
-
* const products: Product[] = [
|
|
231
|
-
* { id: '1', name: 'Laptop', price: 999.99, rating: 4.5, stock: 15, categoryId: 1, salesCount: 150 },
|
|
232
|
-
* { id: '2', name: 'Mouse', price: 29.99, rating: 4.2, stock: 50, categoryId: 1, salesCount: 300 },
|
|
233
|
-
* { id: '3', name: 'Keyboard', price: 79.99, rating: 4.8, stock: 25, categoryId: 1, salesCount: 200 }
|
|
234
|
-
* ];
|
|
235
|
-
*
|
|
236
|
-
* // Sort by price (ascending)
|
|
237
|
-
* products.sort(GaffComparator.numbers(product => product.price));
|
|
238
|
-
* // Result: Mouse ($29.99), Keyboard ($79.99), Laptop ($999.99)
|
|
239
|
-
*
|
|
240
|
-
* // Sort by rating (descending requires negation)
|
|
241
|
-
* products.sort(GaffComparator.numbers(product => -product.rating));
|
|
242
|
-
* // Result: Keyboard (4.8), Laptop (4.5), Mouse (4.2)
|
|
243
|
-
*
|
|
244
|
-
* // Multi-field: category, then price
|
|
245
|
-
* products.sort(GaffComparator.numbers(product => [product.categoryId, product.price]));
|
|
246
|
-
*
|
|
247
|
-
* // Complex business logic: popularity (sales) then rating
|
|
248
|
-
* products.sort(GaffComparator.numbers(product => [-product.salesCount, -product.rating]));
|
|
249
|
-
* // Negative values for descending order
|
|
250
|
-
*
|
|
251
|
-
* // Sort by inventory priority: low stock first, then by sales
|
|
252
|
-
* products.sort(GaffComparator.numbers(product => [product.stock, -product.salesCount]));
|
|
253
|
-
*
|
|
254
|
-
* // Validate API numerical sorting with TestValidator
|
|
255
|
-
* const priceValidator = TestValidator.sort("product price sorting",
|
|
256
|
-
* (sortFields) => productApi.getProducts({ sort: sortFields })
|
|
257
|
-
* )("price")(
|
|
258
|
-
* GaffComparator.numbers(product => product.price)
|
|
259
|
-
* );
|
|
260
|
-
* await priceValidator("+"); // test ascending order
|
|
261
|
-
* await priceValidator("-"); // test descending order
|
|
262
|
-
*
|
|
263
|
-
* // Test multi-criteria sorting
|
|
264
|
-
* const sortByBusinessValue = GaffComparator.numbers(product => [
|
|
265
|
-
* -product.salesCount, // High sales first
|
|
266
|
-
* -product.rating, // High rating first
|
|
267
|
-
* product.price // Low price first (for tie-breaking)
|
|
268
|
-
* ]);
|
|
269
|
-
* ```;
|
|
270
|
-
*
|
|
271
|
-
* @template T - The type of objects being compared
|
|
272
|
-
* @param closure - Function that extracts number value(s) from input objects
|
|
273
|
-
* @returns A comparator function suitable for Array.sort()
|
|
274
|
-
*/
|
|
275
|
-
GaffComparator.numbers = function (closure) {
|
|
276
|
-
return function (x, y) {
|
|
277
|
-
var a = wrap(closure(x));
|
|
278
|
-
var b = wrap(closure(y));
|
|
279
|
-
var idx = a.findIndex(function (v, i) { return v !== b[i]; });
|
|
280
|
-
return idx !== -1 ? a[idx] - b[idx] : 0;
|
|
281
|
-
};
|
|
282
|
-
};
|
|
283
|
-
var compare = function (x, y) { return x.localeCompare(y); };
|
|
284
|
-
var wrap = function (elem) { return (Array.isArray(elem) ? elem : [elem]); };
|
|
285
|
-
})(GaffComparator || (exports.GaffComparator = GaffComparator = {}));
|
|
286
|
-
//# sourceMappingURL=GaffComparator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GaffComparator.js","sourceRoot":"","sources":["../src/GaffComparator.ts"],"names":[],"mappings":"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"}
|
package/lib/MapUtil.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
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 declare 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
|
-
function take<K, V>(map: Map<K, V>, key: K, value: () => V): V;
|
|
79
|
-
}
|
package/lib/MapUtil.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MapUtil = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* A namespace providing utility functions for Map manipulation.
|
|
6
|
-
*
|
|
7
|
-
* This namespace contains helper functions for working with JavaScript Map
|
|
8
|
-
* objects, providing convenient methods for common Map operations like
|
|
9
|
-
* retrieving values with lazy initialization.
|
|
10
|
-
*
|
|
11
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* // Create a cache with lazy initialization
|
|
15
|
-
* const cache = new Map<string, ExpensiveObject>();
|
|
16
|
-
*
|
|
17
|
-
* const obj = MapUtil.take(cache, "key1", () => {
|
|
18
|
-
* console.log("Creating expensive object...");
|
|
19
|
-
* return new ExpensiveObject();
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // Subsequent calls return cached value without re-creating
|
|
23
|
-
* const sameObj = MapUtil.take(cache, "key1", () => new ExpensiveObject());
|
|
24
|
-
* console.log(obj === sameObj); // true
|
|
25
|
-
* ```;
|
|
26
|
-
*/
|
|
27
|
-
var MapUtil;
|
|
28
|
-
(function (MapUtil) {
|
|
29
|
-
/**
|
|
30
|
-
* Retrieves a value from a Map or creates it using a lazy initialization
|
|
31
|
-
* function.
|
|
32
|
-
*
|
|
33
|
-
* This function implements the "get or create" pattern for Maps. If the key
|
|
34
|
-
* exists in the Map, it returns the existing value. Otherwise, it calls the
|
|
35
|
-
* provided factory function to create a new value, stores it in the Map, and
|
|
36
|
-
* returns it. The factory function is only called when the key doesn't exist,
|
|
37
|
-
* enabling lazy initialization and caching patterns.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* // Simple caching example
|
|
42
|
-
* const userCache = new Map<number, User>();
|
|
43
|
-
*
|
|
44
|
-
* const user = MapUtil.take(userCache, userId, () => {
|
|
45
|
-
* // This expensive operation only runs if userId is not cached
|
|
46
|
-
* return fetchUserFromDatabase(userId);
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
-
* // Configuration object caching
|
|
50
|
-
* const configs = new Map<string, Config>();
|
|
51
|
-
*
|
|
52
|
-
* const dbConfig = MapUtil.take(configs, "database", () => ({
|
|
53
|
-
* host: "localhost",
|
|
54
|
-
* port: 5432,
|
|
55
|
-
* database: "myapp"
|
|
56
|
-
* }));
|
|
57
|
-
*
|
|
58
|
-
* // Lazy computation results
|
|
59
|
-
* const computationCache = new Map<string, number>();
|
|
60
|
-
*
|
|
61
|
-
* const result = MapUtil.take(computationCache, "fibonacci-40", () => {
|
|
62
|
-
* console.log("Computing fibonacci(40)...");
|
|
63
|
-
* return fibonacci(40); // Only computed once
|
|
64
|
-
* });
|
|
65
|
-
*
|
|
66
|
-
* // Using with complex keys
|
|
67
|
-
* const cache = new Map<[number, number], Matrix>();
|
|
68
|
-
* const key: [number, number] = [rows, cols];
|
|
69
|
-
*
|
|
70
|
-
* const matrix = MapUtil.take(cache, key, () =>
|
|
71
|
-
* generateIdentityMatrix(rows, cols)
|
|
72
|
-
* );
|
|
73
|
-
* ```;
|
|
74
|
-
*
|
|
75
|
-
* @template K - The type of keys in the Map
|
|
76
|
-
* @template V - The type of values in the Map
|
|
77
|
-
* @param map - The Map to retrieve from or update
|
|
78
|
-
* @param key - The key to look up in the Map
|
|
79
|
-
* @param value - A factory function that creates the value if key doesn't exist
|
|
80
|
-
* @returns The existing value if found, or the newly created value
|
|
81
|
-
*/
|
|
82
|
-
function take(map, key, value) {
|
|
83
|
-
if (map.has(key)) {
|
|
84
|
-
return map.get(key);
|
|
85
|
-
}
|
|
86
|
-
var newValue = value();
|
|
87
|
-
map.set(key, newValue);
|
|
88
|
-
return newValue;
|
|
89
|
-
}
|
|
90
|
-
MapUtil.take = take;
|
|
91
|
-
})(MapUtil || (exports.MapUtil = MapUtil = {}));
|
|
92
|
-
//# sourceMappingURL=MapUtil.js.map
|
package/lib/MapUtil.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MapUtil.js","sourceRoot":"","sources":["../src/MapUtil.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,IAAiB,OAAO,CA8DvB;AA9DD,WAAiB,OAAO;IACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoDG;IACH,SAAgB,IAAI,CAAO,GAAc,EAAE,GAAM,EAAE,KAAc;QAC/D,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACjB,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAM,CAAC;QAC3B,CAAC;QACD,IAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;QACzB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACvB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAPe,YAAI,OAOnB,CAAA;AACH,CAAC,EA9DgB,OAAO,uBAAP,OAAO,QA8DvB"}
|