codeweaver 3.0.2 → 3.0.5
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
|
@@ -161,7 +161,7 @@ export default class ProductController {
|
|
|
161
161
|
}
|
|
162
162
|
const product = await this.get(id);
|
|
163
163
|
if (product != null) {
|
|
164
|
-
await assign(
|
|
164
|
+
await assign(product, updateData, ZodProduct);
|
|
165
165
|
await productCache.delete(updateData.id.toString());
|
|
166
166
|
await productsCache.delete("key");
|
|
167
167
|
} else {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { ResponseError } from "./error-handling";
|
|
3
|
+
import { parallelMap } from "./parallel/parallel";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Strictly assign obj (type T1) to T2 using a Zod schema.
|
|
@@ -14,24 +15,22 @@ import { ResponseError } from "./error-handling";
|
|
|
14
15
|
* @returns T2 representing the destination after assignment
|
|
15
16
|
*/
|
|
16
17
|
export default async function assign<T1 extends object, T2 extends object>(
|
|
17
|
-
source: T1,
|
|
18
18
|
destination: T2,
|
|
19
|
-
|
|
19
|
+
source: T1,
|
|
20
|
+
destinationSchema?: z.ZodObject<any>
|
|
20
21
|
): Promise<T2> {
|
|
21
|
-
let keys = Object.keys(
|
|
22
|
+
let keys = Object.keys(destinationSchema?.shape ?? destination);
|
|
22
23
|
|
|
23
24
|
// Iterate schema keys
|
|
24
|
-
await
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
30
|
-
);
|
|
25
|
+
await parallelMap(keys, async (key) => {
|
|
26
|
+
if (source.hasOwnProperty(key)) {
|
|
27
|
+
(destination as any)[key] = (source as any)[key];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
31
30
|
|
|
32
|
-
if (
|
|
31
|
+
if (destinationSchema != null) {
|
|
33
32
|
// Validate using the schema on the subset (this will also coerce if the schema has transforms)
|
|
34
|
-
const parseResult = await
|
|
33
|
+
const parseResult = await destinationSchema.safeParseAsync(destination);
|
|
35
34
|
if (parseResult.success == false) {
|
|
36
35
|
// Build a descriptive error message from the first issue
|
|
37
36
|
const issue = parseResult.error.issues?.[0];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z, ZodRawShape } from "zod";
|
|
2
2
|
import { ResponseError } from "./error-handling";
|
|
3
|
+
import { parallelMap } from "./parallel/parallel";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Helper: normalize and validate a numeric string for integer parsing.
|
|
@@ -131,13 +132,11 @@ export async function convert<T1 extends object, T2 extends object>(
|
|
|
131
132
|
const candidate: any = {};
|
|
132
133
|
|
|
133
134
|
// Iterate schema keys
|
|
134
|
-
await
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
})
|
|
140
|
-
);
|
|
135
|
+
await parallelMap(keysSchema, async (key) => {
|
|
136
|
+
if ((data as any).hasOwnProperty(key)) {
|
|
137
|
+
candidate[key] = (data as any)[key];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
141
140
|
|
|
142
141
|
// Validate against the schema
|
|
143
142
|
if (ignoreValidation) {
|
|
@@ -2,6 +2,21 @@ import { ResponseError } from "../error-handling";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { WorkerPool } from "./worker-pool";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Creates a setter function that, when invoked, rebinds the captured
|
|
7
|
+
* destination binding to the provided source value.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of both `destination` and `source`, constrained to object types.
|
|
10
|
+
* @param {T} destination - The destination value (captured by the closure).
|
|
11
|
+
* @param {T} source - The source value to which `destination` will be rebound when the returned function runs.
|
|
12
|
+
* @returns {() => void} A function that, when called, rebinds the captured `destination` to `source`.
|
|
13
|
+
*/
|
|
14
|
+
export function set<T extends object>(destination: T, source: T): () => void {
|
|
15
|
+
return () => {
|
|
16
|
+
destination = source;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
5
20
|
/**
|
|
6
21
|
* Executes multiple asynchronous or synchronous tasks in parallel and returns their results as an array.
|
|
7
22
|
*
|
|
@@ -13,7 +28,9 @@ import { WorkerPool } from "./worker-pool";
|
|
|
13
28
|
* const results = await parallel(
|
|
14
29
|
* () => fetchUser(1),
|
|
15
30
|
* () => fetchUser(2),
|
|
16
|
-
*
|
|
31
|
+
* fetchProduct,
|
|
32
|
+
* set(user.id, 1),
|
|
33
|
+
* set(user.name, "Bob")
|
|
17
34
|
* );
|
|
18
35
|
* console.log(results); // [user1, user2, user3]
|
|
19
36
|
*/
|
|
@@ -117,11 +134,11 @@ export async function parallelCpuMap<T, R>(
|
|
|
117
134
|
throw new Error("concurrency must be greater than 0");
|
|
118
135
|
}
|
|
119
136
|
|
|
120
|
-
// Worker pool setup
|
|
121
|
-
const workerPath = path.resolve(__dirname, mapperWorkerFilePath);
|
|
122
|
-
|
|
123
137
|
// Instantiate a concrete pool
|
|
124
|
-
const workerPool = new WorkerPool<T, R>(
|
|
138
|
+
const workerPool = new WorkerPool<T, R>(
|
|
139
|
+
mapperWorkerFilePath,
|
|
140
|
+
concurrencyLevel
|
|
141
|
+
);
|
|
125
142
|
|
|
126
143
|
try {
|
|
127
144
|
// Dispatch all items and collect results in order
|