codeweaver 3.1.0 → 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/.env.example CHANGED
@@ -1,20 +1,20 @@
1
- # Environment
2
- NODE_ENV=development # or "production" depending on your deployment
3
-
4
- # Server
5
- HTTP=http://localhost:3000
6
- PORT=3000
7
-
8
- # Feature flags
9
- SWAGGER=true
10
-
11
- # Timeouts and limits
12
- TIMEOUT=30
13
-
14
- # Rate limiting (separate vars)
15
- RATE_LIMIT_TIME_SPAN=60
16
- RATE_LIMIT_ALLOWED_CALLS=100
17
-
18
- # Memoization and cache
19
- MEMOIZE_TIME=300
1
+ # Environment
2
+ NODE_ENV=development # or "production" depending on your deployment
3
+
4
+ # Server
5
+ HTTP=http://localhost:3000
6
+ PORT=3000
7
+
8
+ # Feature flags
9
+ SWAGGER=true
10
+
11
+ # Timeouts and limits
12
+ TIMEOUT=30
13
+
14
+ # Rate limiting (separate vars)
15
+ RATE_LIMIT_TIME_SPAN=60
16
+ RATE_LIMIT_ALLOWED_CALLS=100
17
+
18
+ # Memoization and cache
19
+ MEMOIZE_TIME=300
20
20
  CACHE_SIZE=1000
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
  ```
@@ -351,7 +348,7 @@ Once the application is running, visit the Swagger UI at http://localhost:3000/a
351
348
 
352
349
  ### Decorators
353
350
 
354
- To prevent abuse of your API, you can utilize throttling, caching, and error handling decorators from the `utils-decorators` packages respectively. This packages provides decorators that can be applied directly to your service and controller classes.
351
+ To prevent abuse of your API, you can utilize throttling, caching, and error handling decorators from the `utils-decorators` package. This package provides decorators that can be applied directly to your service and controller classes.
355
352
 
356
353
  ### Contributing
357
354
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeweaver",
3
- "version": "3.1.0",
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
  };
@@ -4,15 +4,12 @@ import { WorkerPool } from "./worker-pool";
4
4
  * Creates a setter function that, when invoked, rebinds the captured
5
5
  * destination binding to the provided source value.
6
6
  *
7
- * @template T - The type of both `destination` and `source`, constrained to object types.
8
- * @param {T} destination - The destination value (captured by the closure).
9
- * @param {T} source - The source value to which `destination` will be rebound when the returned function runs.
7
+ * @template T - The type of both `destination` and `source`.
8
+ * @param {T} destination - The destination value.
9
+ * @param {T} source - The source value.
10
10
  * @returns {() => void} A function that, when called, rebinds the captured `destination` to `source`.
11
11
  */
12
- export function set<T extends object>(
13
- destination: keyof T,
14
- source: keyof T
15
- ): () => void {
12
+ export function set<T>(destination: T, source: T): () => void {
16
13
  return () => {
17
14
  destination = source;
18
15
  };
@@ -1,8 +1,8 @@
1
- {
2
- "compilerOptions": {
3
- "baseUrl": ".",
4
- "paths": {
5
- "@/*": ["dist/*"]
6
- }
7
- }
8
- }
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "paths": {
5
+ "@/*": ["dist/*"]
6
+ }
7
+ }
8
+ }