codeweaver 3.0.5 → 3.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeweaver",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "main": "src/main.ts",
5
5
  "bin": {
6
6
  "codeweaver": "command.js"
@@ -1,5 +1,4 @@
1
1
  import { z } from "zod";
2
- import { ResponseError } from "./error-handling";
3
2
  import { parallelMap } from "./parallel/parallel";
4
3
 
5
4
  /**
@@ -36,10 +35,7 @@ export default async function assign<T1 extends object, T2 extends object>(
36
35
  const issue = parseResult.error.issues?.[0];
37
36
  const path = issue?.path?.length ? issue.path.join(".") : "value";
38
37
  const message = issue?.message ?? "Schema validation failed";
39
- throw new ResponseError(
40
- `Validation failed for "${path}": ${message}`,
41
- 500
42
- );
38
+ throw new Error(`Validation failed for "${path}": ${message}`);
43
39
  }
44
40
  }
45
41
 
@@ -1,5 +1,4 @@
1
1
  import { z, ZodRawShape } from "zod";
2
- import { ResponseError } from "./error-handling";
3
2
  import { parallelMap } from "./parallel/parallel";
4
3
 
5
4
  /**
@@ -42,10 +41,7 @@ export function stringToInteger(input: string): number {
42
41
  try {
43
42
  return parseIntegerStrict(input);
44
43
  } catch {
45
- throw new ResponseError(
46
- "The input parameter must be a valid integer.",
47
- 400
48
- );
44
+ throw new Error("The input parameter must be a valid integer.");
49
45
  }
50
46
  }
51
47
 
@@ -72,9 +68,8 @@ export function stringToBoolean(input: string): boolean {
72
68
  return false;
73
69
  }
74
70
 
75
- throw new ResponseError(
76
- "The input parameter must be a boolean (e.g., true/false, 1/0).",
77
- 400
71
+ throw new Error(
72
+ "The input parameter must be a boolean (e.g., true/false, 1/0)."
78
73
  );
79
74
  }
80
75
 
@@ -99,7 +94,7 @@ export function stringToNumber(input: string): number {
99
94
 
100
95
  return n;
101
96
  } catch {
102
- throw new ResponseError("The input parameter must be a valid number.", 400);
97
+ throw new Error("The input parameter must be a valid number.");
103
98
  }
104
99
  }
105
100
 
@@ -122,7 +117,7 @@ export async function convert<T1 extends object, T2 extends object>(
122
117
  // Derive the runtime keys from the schema's shape
123
118
  const shape = (schema as any)._def?.shape as ZodRawShape | undefined;
124
119
  if (!shape) {
125
- throw new ResponseError("Provided schema has no shape.", 500);
120
+ throw new Error("Provided schema has no shape.");
126
121
  }
127
122
 
128
123
  const keysSchema = Object.keys(shape) as Array<keyof any>;
@@ -150,10 +145,7 @@ export async function convert<T1 extends object, T2 extends object>(
150
145
  }));
151
146
 
152
147
  // You can log issues or throw a structured error
153
- throw new ResponseError(
154
- `Validation failed: ${JSON.stringify(issues)}`,
155
- 500
156
- );
148
+ throw new Error(`Validation failed: ${JSON.stringify(issues)}`);
157
149
  }
158
150
 
159
151
  // Return the validated data typed as T2
@@ -45,7 +45,9 @@ export class ResponseError extends Error {
45
45
  super(message);
46
46
 
47
47
  // If a custom stack is provided, you might assign it; otherwise, the runtime stack will be used.
48
- if (stack) this.stack = stack;
48
+ if (stack) {
49
+ this.stack = stack;
50
+ }
49
51
  }
50
52
  }
51
53
 
@@ -1,5 +1,3 @@
1
- import { ResponseError } from "../error-handling";
2
-
3
1
  /**
4
2
  * Event callback type for channel send event.
5
3
  * @template T - Type of the value sent through the channel.
@@ -38,7 +36,7 @@ export class Channel<T> {
38
36
  */
39
37
  public async send(value: T): Promise<void> {
40
38
  if (this.closed) {
41
- throw new ResponseError("Channel is closed", 500);
39
+ throw new Error("Channel is closed");
42
40
  }
43
41
  if (this.receivers.length > 0) {
44
42
  const receiver = this.receivers.shift()!;
@@ -62,7 +60,7 @@ export class Channel<T> {
62
60
  return this.queue.shift()!;
63
61
  }
64
62
  if (this.closed) {
65
- throw new ResponseError("Channel is closed", 500);
63
+ throw new Error("Channel is closed");
66
64
  }
67
65
  return await new Promise<T>((resolve) => {
68
66
  this.receivers.push(resolve);
@@ -1,5 +1,3 @@
1
- import { ResponseError } from "../error-handling";
2
- import path from "path";
3
1
  import { WorkerPool } from "./worker-pool";
4
2
 
5
3
  /**
@@ -77,11 +75,11 @@ export async function parallelMapWithConcurrencyLevel<T, U>(
77
75
  concurrencyLevel: number = Infinity
78
76
  ): Promise<U[]> {
79
77
  if (!Array.isArray(items)) {
80
- throw new ResponseError("Items must be an array", 400);
78
+ throw new TypeError("Items must be an array");
81
79
  }
82
80
 
83
81
  if (concurrencyLevel <= 0) {
84
- throw new ResponseError("Concurrency must be greater than 0", 500);
82
+ throw new Error("Concurrency must be greater than 0");
85
83
  }
86
84
 
87
85
  // If concurrency is not finite, use the simple Promise.all approach
@@ -1,6 +1,5 @@
1
1
  import { Worker } from "worker_threads";
2
2
  import os from "os";
3
- import { ResponseError } from "../error-handling";
4
3
 
5
4
  export type Task<T> = { id: number; payload: T };
6
5
  export type Result<R> = { id: number; result?: R; error?: string };
@@ -28,9 +27,7 @@ export class WorkerPool<T, R> {
28
27
  if (code !== 0) {
29
28
  // Notify all pending promises about the exit
30
29
  for (const [, p] of this.pending) {
31
- p.reject(
32
- new ResponseError(`Worker ${i} exited with code ${code}`, 500)
33
- );
30
+ p.reject(new Error(`Worker ${i} exited with code ${code}`));
34
31
  }
35
32
  this.pending.clear();
36
33
  }
@@ -56,10 +53,7 @@ export class WorkerPool<T, R> {
56
53
  // This simple version broadcasts the error to all pending tasks for safety.
57
54
  for (const [id, entry] of this.pending) {
58
55
  entry.reject(
59
- new ResponseError(
60
- `Worker ${workerIndex} error: ${err?.message ?? err}`,
61
- 500
62
- )
56
+ new Error(`Worker ${workerIndex} error: ${err?.message ?? err}`)
63
57
  );
64
58
  }
65
59
  this.pending.clear();
@@ -77,8 +71,7 @@ export class WorkerPool<T, R> {
77
71
 
78
72
  // Map all items using a round-robin distribution across workers
79
73
  async mapAll(items: T[]): Promise<R[]> {
80
- if (!Array.isArray(items))
81
- throw new ResponseError("Items must be an array", 400);
74
+ if (!Array.isArray(items)) throw new Error("Items must be an array");
82
75
  const results: R[] = new Array(items.length);
83
76
 
84
77
  const workerCount = this.workers.length;