codeweaver 3.1.1 → 3.1.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
@@ -210,20 +210,16 @@ For example, in the provided `UserController`, the `createUser` method demonstra
210
210
  Here’s a brief breakdown of key components used in the `UserController`:
211
211
 
212
212
  ```typescript
213
- import {
214
- ZodUserCreationDto,
215
- UserCreationDto,
216
- UserDto,
217
- ZodUserDto,
218
- } from "./dto/user.dto";
213
+ import { UserCreationDto, UserDto, ZodUserDto } from "./dto/user.dto";
219
214
  import { memoizeAsync, onError, rateLimit, timeout } from "utils-decorators";
220
215
  import { ResponseError } from "@/utilities/error-handling";
221
216
  import { convert, stringToInteger } from "@/utilities/conversion";
222
- import config from "@/config";
217
+ import { config } from "@/config";
223
218
  import { users } from "@/db";
224
- import { User } from "@/entities/user.entity";
219
+ import { User, ZodUser } from "@/entities/user.entity";
225
220
  import { MapAsyncCache } from "@/utilities/cache/memory-cache";
226
221
  import { Injectable } from "@/utilities/container";
222
+ import { parallelMap } from "@/utilities/parallel/parallel";
227
223
 
228
224
  function exceedHandler() {
229
225
  const message = "Too much call in allowed window";
@@ -270,8 +266,7 @@ export default class UserController {
270
266
  * @returns {User} A fully formed User object ready for persistence.
271
267
  */
272
268
  public async validateUserCreationDto(user: UserCreationDto): Promise<User> {
273
- const newUser = await ZodUserCreationDto.parseAsync(user);
274
- return { ...newUser, id: users.length + 1 };
269
+ return await convert(user, ZodUser);
275
270
  }
276
271
 
277
272
  @rateLimit({
@@ -288,7 +283,6 @@ export default class UserController {
288
283
  */
289
284
  public async create(user: User): Promise<void> {
290
285
  users.push(user);
291
- await userCache.set(user.id.toString(), user as User);
292
286
  await usersCache.delete("key");
293
287
  }
294
288
 
@@ -309,7 +303,10 @@ export default class UserController {
309
303
  * @throws {ResponseError} 500 - When rate limit exceeded
310
304
  */
311
305
  public async getAll(): Promise<UserDto[]> {
312
- return users as UserDto[];
306
+ return await parallelMap(
307
+ users,
308
+ async (user) => await convert(user, ZodUserDto)
309
+ );
313
310
  }
314
311
 
315
312
  @memoizeAsync({
@@ -334,7 +331,7 @@ export default class UserController {
334
331
  if (user == null) {
335
332
  throw new ResponseError("Product not found");
336
333
  }
337
- return convert(user!, ZodUserDto);
334
+ return convert(user, ZodUserDto);
338
335
  }
339
336
  }
340
337
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeweaver",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "main": "src/main.ts",
5
5
  "bin": {
6
6
  "codeweaver": "command.js"
@@ -1,16 +1,42 @@
1
1
  import { ZodUser } from "@/entities/user.entity";
2
2
 
3
+ /**
4
+ * DTO for a User.
5
+ * Derived from the full User schema.
6
+ */
7
+ export const ZodUserDto = ZodUser;
8
+
9
+ /**
10
+ * DTO for creating a User.
11
+ * Derived from the full User schema by omitting the system-generated id.
12
+ */
3
13
  export const ZodUserCreationDto = ZodUser.omit({ id: true });
4
- export const ZodUserDto = ZodUser.omit({ password: true });
5
14
 
15
+ /**
16
+ * Data required to create a User.
17
+ */
6
18
  export type UserCreationDto = {
19
+ /** Username for the new user. */
7
20
  username: string;
21
+
22
+ /** Email address for the new user. */
8
23
  email: string;
24
+
25
+ /** Password for the new user. */
9
26
  password: string;
10
27
  };
11
28
 
29
+ /**
30
+ * Data for a User returned by APIs (or stored for client consumption).
31
+ * Excludes sensitive information such as the password.
32
+ */
12
33
  export type UserDto = {
34
+ /** Unique identifier for the user. */
13
35
  id: number;
36
+
37
+ /** Username of the user. */
14
38
  username: string;
39
+
40
+ /** Email address of the user. */
15
41
  email: string;
16
42
  };