codeweaver 4.0.0 → 4.0.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/README.md
CHANGED
|
@@ -250,7 +250,8 @@ async function invalidInputHandler(e: ResponseError) {
|
|
|
250
250
|
throw new ResponseError(message, 400, e?.message);
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
const
|
|
253
|
+
const userCache = new MapAsyncCache<UserDto>(config.cacheSize);
|
|
254
|
+
const usersCache = new MapAsyncCache<UserDto[]>(1);
|
|
254
255
|
|
|
255
256
|
@Injectable()
|
|
256
257
|
/**
|
|
@@ -283,7 +284,7 @@ export default class UserController {
|
|
|
283
284
|
return await convert(user, ZodUser);
|
|
284
285
|
}
|
|
285
286
|
|
|
286
|
-
@Invalidate(usersCache)
|
|
287
|
+
@Invalidate(usersCache, true)
|
|
287
288
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
288
289
|
/**
|
|
289
290
|
* Create a new user
|
|
@@ -296,7 +297,7 @@ export default class UserController {
|
|
|
296
297
|
users.push(user);
|
|
297
298
|
}
|
|
298
299
|
|
|
299
|
-
@Memoize(usersCache)
|
|
300
|
+
@Memoize(usersCache, () => "key")
|
|
300
301
|
@Timeout(config.timeout)
|
|
301
302
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
302
303
|
/**
|
|
@@ -304,21 +305,23 @@ export default class UserController {
|
|
|
304
305
|
* @returns {Promise<UserDto[]>} List of users with hidden password fields
|
|
305
306
|
* @throws {ResponseError} 500 - When rate limit exceeded
|
|
306
307
|
*/
|
|
307
|
-
public async getAll(
|
|
308
|
+
public async getAll(
|
|
309
|
+
timeoutSignal?: AbortSignal
|
|
310
|
+
): Promise<(UserDto | null)[]> {
|
|
308
311
|
return await parallelMap(users, async (user) =>
|
|
309
|
-
|
|
312
|
+
timeoutSignal?.aborted == false
|
|
310
313
|
? await convert<User, UserDto>(user!, ZodUserDto)
|
|
311
314
|
: null
|
|
312
315
|
);
|
|
313
316
|
}
|
|
314
317
|
|
|
315
|
-
@Memoize(
|
|
318
|
+
@Memoize(userCache)
|
|
316
319
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
317
320
|
/**
|
|
318
321
|
* Get user by ID
|
|
319
322
|
* @param {number} id - User ID as string
|
|
320
323
|
* @returns {Promise<UserDto>} User details or error object
|
|
321
|
-
* @throws {ResponseError} 404 - User not
|
|
324
|
+
* @throws {ResponseError} 404 - User not fou
|
|
322
325
|
* @throws {ResponseError} 400 - Invalid ID format
|
|
323
326
|
*/
|
|
324
327
|
public async get(id: number): Promise<UserDto> {
|
package/package.json
CHANGED
|
@@ -53,7 +53,7 @@ export function Memoize<Entity, MethodArgs extends any[] = any[]>(
|
|
|
53
53
|
*/
|
|
54
54
|
export function Invalidate<Entity>(
|
|
55
55
|
cache: AsyncCache<Entity>,
|
|
56
|
-
shouldClearAll: boolean =
|
|
56
|
+
shouldClearAll: boolean = false
|
|
57
57
|
) {
|
|
58
58
|
return createMethodDecorator<
|
|
59
59
|
[AsyncCache<Entity>, boolean | true],
|
|
@@ -20,7 +20,7 @@ async function invalidInputHandler(e: ResponseError) {
|
|
|
20
20
|
throw new ResponseError(message, 400, e.message);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const ordersCache = new MapAsyncCache<OrderDto[]>(
|
|
23
|
+
const ordersCache = new MapAsyncCache<OrderDto[]>(1);
|
|
24
24
|
const orderCache = new MapAsyncCache<OrderDto>(config.cacheSize);
|
|
25
25
|
|
|
26
26
|
@Injectable()
|
|
@@ -63,7 +63,7 @@ export default class OrderController {
|
|
|
63
63
|
return convert(newOrder, ZodOrder);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
@Invalidate(ordersCache)
|
|
66
|
+
@Invalidate(ordersCache, true)
|
|
67
67
|
@RateLimit(
|
|
68
68
|
config.rateLimitTimeSpan,
|
|
69
69
|
config.rateLimitAllowedCalls,
|
|
@@ -80,7 +80,7 @@ export default class OrderController {
|
|
|
80
80
|
orders.push(order);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
@Memoize(
|
|
83
|
+
@Memoize(ordersCache, () => "key")
|
|
84
84
|
@Timeout(config.timeout)
|
|
85
85
|
@RateLimit(
|
|
86
86
|
config.rateLimitTimeSpan,
|
|
@@ -91,10 +91,13 @@ export default class OrderController {
|
|
|
91
91
|
* Retrieves all orders
|
|
92
92
|
* @returns List of orders
|
|
93
93
|
*/
|
|
94
|
-
public async getAll(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
public async getAll(
|
|
95
|
+
timeoutSignal?: AbortSignal
|
|
96
|
+
): Promise<(OrderDto | null)[]> {
|
|
97
|
+
return await parallelMap(orders, async (order) =>
|
|
98
|
+
timeoutSignal?.aborted == false
|
|
99
|
+
? await convert<Order, OrderDto>(order, ZodOrderDto)
|
|
100
|
+
: null
|
|
98
101
|
);
|
|
99
102
|
}
|
|
100
103
|
|
|
@@ -117,8 +120,8 @@ export default class OrderController {
|
|
|
117
120
|
return await convert(order, ZodOrder);
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
@Invalidate(orderCache
|
|
121
|
-
@Invalidate(ordersCache)
|
|
123
|
+
@Invalidate(orderCache)
|
|
124
|
+
@Invalidate(ordersCache, true)
|
|
122
125
|
@RateLimit(
|
|
123
126
|
config.rateLimitTimeSpan,
|
|
124
127
|
config.rateLimitAllowedCalls,
|
|
@@ -143,8 +146,8 @@ export default class OrderController {
|
|
|
143
146
|
order.deliveredAt = new Date();
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
@Invalidate(orderCache
|
|
147
|
-
@Invalidate(ordersCache)
|
|
149
|
+
@Invalidate(orderCache)
|
|
150
|
+
@Invalidate(ordersCache, true)
|
|
148
151
|
@RateLimit(
|
|
149
152
|
config.rateLimitTimeSpan,
|
|
150
153
|
config.rateLimitAllowedCalls,
|
|
@@ -21,7 +21,7 @@ async function invalidInputHandler(e: ResponseError) {
|
|
|
21
21
|
throw new ResponseError(message, 400, e.message);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const productsCache = new MapAsyncCache<ProductDto[]>(
|
|
24
|
+
const productsCache = new MapAsyncCache<ProductDto[]>(1);
|
|
25
25
|
const productCache = new MapAsyncCache<ProductDto>(config.cacheSize);
|
|
26
26
|
|
|
27
27
|
@Injectable()
|
|
@@ -70,7 +70,7 @@ export default class ProductController {
|
|
|
70
70
|
return await convert(product, ZodProduct);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
@Invalidate(productsCache)
|
|
73
|
+
@Invalidate(productsCache, true)
|
|
74
74
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
75
75
|
/**
|
|
76
76
|
* Creates a new product with validated data
|
|
@@ -83,17 +83,20 @@ export default class ProductController {
|
|
|
83
83
|
products.push(product);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
@Memoize(productsCache)
|
|
86
|
+
@Memoize(productsCache, () => "key")
|
|
87
87
|
@Timeout(config.timeout)
|
|
88
88
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
89
89
|
/**
|
|
90
90
|
* Retrieves all products with truncated descriptions
|
|
91
91
|
* @returns List of products with summarized descriptions
|
|
92
92
|
*/
|
|
93
|
-
public async getAll(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
public async getAll(
|
|
94
|
+
timeoutSignal?: AbortSignal
|
|
95
|
+
): Promise<(ProductDto | null)[]> {
|
|
96
|
+
return await parallelMap(products, async (product) =>
|
|
97
|
+
timeoutSignal?.aborted == false
|
|
98
|
+
? await convert<Product, ProductDto>(product, ZodProductDto)
|
|
99
|
+
: null
|
|
97
100
|
);
|
|
98
101
|
}
|
|
99
102
|
|
|
@@ -112,8 +115,8 @@ export default class ProductController {
|
|
|
112
115
|
return await convert(product, ZodProduct);
|
|
113
116
|
}
|
|
114
117
|
|
|
115
|
-
@Invalidate(productCache
|
|
116
|
-
@Invalidate(productsCache)
|
|
118
|
+
@Invalidate(productCache)
|
|
119
|
+
@Invalidate(productsCache, true)
|
|
117
120
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
118
121
|
/**
|
|
119
122
|
* Updates an existing product
|
|
@@ -135,8 +138,8 @@ export default class ProductController {
|
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
140
|
|
|
138
|
-
@Invalidate(productCache
|
|
139
|
-
@Invalidate(productsCache)
|
|
141
|
+
@Invalidate(productCache)
|
|
142
|
+
@Invalidate(productsCache, true)
|
|
140
143
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
141
144
|
/**
|
|
142
145
|
* Deletes a product by ID
|
|
@@ -15,7 +15,8 @@ async function invalidInputHandler(e: ResponseError) {
|
|
|
15
15
|
throw new ResponseError(message, 400, e?.message);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const userCache = new MapAsyncCache<UserDto>(config.cacheSize);
|
|
19
|
+
const usersCache = new MapAsyncCache<UserDto[]>(1);
|
|
19
20
|
|
|
20
21
|
@Injectable()
|
|
21
22
|
/**
|
|
@@ -48,7 +49,7 @@ export default class UserController {
|
|
|
48
49
|
return await convert(user, ZodUser);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
@Invalidate(usersCache)
|
|
52
|
+
@Invalidate(usersCache, true)
|
|
52
53
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
53
54
|
/**
|
|
54
55
|
* Create a new user
|
|
@@ -61,7 +62,7 @@ export default class UserController {
|
|
|
61
62
|
users.push(user);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
@Memoize(usersCache)
|
|
65
|
+
@Memoize(usersCache, () => "key")
|
|
65
66
|
@Timeout(config.timeout)
|
|
66
67
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
67
68
|
/**
|
|
@@ -69,15 +70,17 @@ export default class UserController {
|
|
|
69
70
|
* @returns {Promise<UserDto[]>} List of users with hidden password fields
|
|
70
71
|
* @throws {ResponseError} 500 - When rate limit exceeded
|
|
71
72
|
*/
|
|
72
|
-
public async getAll(
|
|
73
|
+
public async getAll(
|
|
74
|
+
timeoutSignal?: AbortSignal
|
|
75
|
+
): Promise<(UserDto | null)[]> {
|
|
73
76
|
return await parallelMap(users, async (user) =>
|
|
74
|
-
|
|
77
|
+
timeoutSignal?.aborted == false
|
|
75
78
|
? await convert<User, UserDto>(user!, ZodUserDto)
|
|
76
79
|
: null
|
|
77
80
|
);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
@Memoize(
|
|
83
|
+
@Memoize(userCache)
|
|
81
84
|
@RateLimit(config.rateLimitTimeSpan, config.rateLimitAllowedCalls)
|
|
82
85
|
/**
|
|
83
86
|
* Get user by ID
|