@valbuild/server 0.84.2 → 0.85.0
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.
|
@@ -6542,38 +6542,7 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
|
6542
6542
|
const actualQueryParams = groupQueryParams(Array.from(url.searchParams.entries()));
|
|
6543
6543
|
let query = {};
|
|
6544
6544
|
if (reqDefinition.query) {
|
|
6545
|
-
|
|
6546
|
-
// @see ValidQueryParamTypes in ApiRouter.ts where we explain what we want to support
|
|
6547
|
-
// We prioritized a declarative ApiRouter, so this code is what we ended up with for better of worse
|
|
6548
|
-
const queryRules = {};
|
|
6549
|
-
for (const [key, zodRule] of Object.entries(reqDefinition.query)) {
|
|
6550
|
-
let innerType = zodRule;
|
|
6551
|
-
let isOptional = false;
|
|
6552
|
-
let isArray = false;
|
|
6553
|
-
// extract inner types:
|
|
6554
|
-
if (innerType instanceof zod.z.ZodOptional) {
|
|
6555
|
-
isOptional = true;
|
|
6556
|
-
innerType = innerType.unwrap();
|
|
6557
|
-
}
|
|
6558
|
-
if (innerType instanceof zod.z.ZodArray) {
|
|
6559
|
-
isArray = true;
|
|
6560
|
-
innerType = innerType.element;
|
|
6561
|
-
}
|
|
6562
|
-
// convert boolean to union of literals true and false so we can parse it as a string
|
|
6563
|
-
if (innerType instanceof zod.z.ZodBoolean) {
|
|
6564
|
-
innerType = zod.z.union([zod.z.literal("true"), zod.z.literal("false")]).transform(arg => arg === "true");
|
|
6565
|
-
}
|
|
6566
|
-
// re-build rules:
|
|
6567
|
-
let arrayCompatibleRule = innerType;
|
|
6568
|
-
arrayCompatibleRule = zod.z.array(innerType); // we always want to parse an array because we group the query params by into an array
|
|
6569
|
-
if (isOptional) {
|
|
6570
|
-
arrayCompatibleRule = arrayCompatibleRule.optional();
|
|
6571
|
-
}
|
|
6572
|
-
if (!isArray) {
|
|
6573
|
-
arrayCompatibleRule = arrayCompatibleRule.transform(arg => arg && arg[0]);
|
|
6574
|
-
}
|
|
6575
|
-
queryRules[key] = arrayCompatibleRule;
|
|
6576
|
-
}
|
|
6545
|
+
const queryRules = reqDefinition.query;
|
|
6577
6546
|
const queryRes = zod.z.object(queryRules).safeParse(actualQueryParams);
|
|
6578
6547
|
if (!queryRes.success) {
|
|
6579
6548
|
return zodErrorResult(queryRes.error, `invalid query params: (${JSON.stringify(actualQueryParams)})`);
|
|
@@ -6542,38 +6542,7 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
|
6542
6542
|
const actualQueryParams = groupQueryParams(Array.from(url.searchParams.entries()));
|
|
6543
6543
|
let query = {};
|
|
6544
6544
|
if (reqDefinition.query) {
|
|
6545
|
-
|
|
6546
|
-
// @see ValidQueryParamTypes in ApiRouter.ts where we explain what we want to support
|
|
6547
|
-
// We prioritized a declarative ApiRouter, so this code is what we ended up with for better of worse
|
|
6548
|
-
const queryRules = {};
|
|
6549
|
-
for (const [key, zodRule] of Object.entries(reqDefinition.query)) {
|
|
6550
|
-
let innerType = zodRule;
|
|
6551
|
-
let isOptional = false;
|
|
6552
|
-
let isArray = false;
|
|
6553
|
-
// extract inner types:
|
|
6554
|
-
if (innerType instanceof zod.z.ZodOptional) {
|
|
6555
|
-
isOptional = true;
|
|
6556
|
-
innerType = innerType.unwrap();
|
|
6557
|
-
}
|
|
6558
|
-
if (innerType instanceof zod.z.ZodArray) {
|
|
6559
|
-
isArray = true;
|
|
6560
|
-
innerType = innerType.element;
|
|
6561
|
-
}
|
|
6562
|
-
// convert boolean to union of literals true and false so we can parse it as a string
|
|
6563
|
-
if (innerType instanceof zod.z.ZodBoolean) {
|
|
6564
|
-
innerType = zod.z.union([zod.z.literal("true"), zod.z.literal("false")]).transform(arg => arg === "true");
|
|
6565
|
-
}
|
|
6566
|
-
// re-build rules:
|
|
6567
|
-
let arrayCompatibleRule = innerType;
|
|
6568
|
-
arrayCompatibleRule = zod.z.array(innerType); // we always want to parse an array because we group the query params by into an array
|
|
6569
|
-
if (isOptional) {
|
|
6570
|
-
arrayCompatibleRule = arrayCompatibleRule.optional();
|
|
6571
|
-
}
|
|
6572
|
-
if (!isArray) {
|
|
6573
|
-
arrayCompatibleRule = arrayCompatibleRule.transform(arg => arg && arg[0]);
|
|
6574
|
-
}
|
|
6575
|
-
queryRules[key] = arrayCompatibleRule;
|
|
6576
|
-
}
|
|
6545
|
+
const queryRules = reqDefinition.query;
|
|
6577
6546
|
const queryRes = zod.z.object(queryRules).safeParse(actualQueryParams);
|
|
6578
6547
|
if (!queryRes.success) {
|
|
6579
6548
|
return zodErrorResult(queryRes.error, `invalid query params: (${JSON.stringify(actualQueryParams)})`);
|
|
@@ -6511,38 +6511,7 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
|
6511
6511
|
const actualQueryParams = groupQueryParams(Array.from(url.searchParams.entries()));
|
|
6512
6512
|
let query = {};
|
|
6513
6513
|
if (reqDefinition.query) {
|
|
6514
|
-
|
|
6515
|
-
// @see ValidQueryParamTypes in ApiRouter.ts where we explain what we want to support
|
|
6516
|
-
// We prioritized a declarative ApiRouter, so this code is what we ended up with for better of worse
|
|
6517
|
-
const queryRules = {};
|
|
6518
|
-
for (const [key, zodRule] of Object.entries(reqDefinition.query)) {
|
|
6519
|
-
let innerType = zodRule;
|
|
6520
|
-
let isOptional = false;
|
|
6521
|
-
let isArray = false;
|
|
6522
|
-
// extract inner types:
|
|
6523
|
-
if (innerType instanceof z.ZodOptional) {
|
|
6524
|
-
isOptional = true;
|
|
6525
|
-
innerType = innerType.unwrap();
|
|
6526
|
-
}
|
|
6527
|
-
if (innerType instanceof z.ZodArray) {
|
|
6528
|
-
isArray = true;
|
|
6529
|
-
innerType = innerType.element;
|
|
6530
|
-
}
|
|
6531
|
-
// convert boolean to union of literals true and false so we can parse it as a string
|
|
6532
|
-
if (innerType instanceof z.ZodBoolean) {
|
|
6533
|
-
innerType = z.union([z.literal("true"), z.literal("false")]).transform(arg => arg === "true");
|
|
6534
|
-
}
|
|
6535
|
-
// re-build rules:
|
|
6536
|
-
let arrayCompatibleRule = innerType;
|
|
6537
|
-
arrayCompatibleRule = z.array(innerType); // we always want to parse an array because we group the query params by into an array
|
|
6538
|
-
if (isOptional) {
|
|
6539
|
-
arrayCompatibleRule = arrayCompatibleRule.optional();
|
|
6540
|
-
}
|
|
6541
|
-
if (!isArray) {
|
|
6542
|
-
arrayCompatibleRule = arrayCompatibleRule.transform(arg => arg && arg[0]);
|
|
6543
|
-
}
|
|
6544
|
-
queryRules[key] = arrayCompatibleRule;
|
|
6545
|
-
}
|
|
6514
|
+
const queryRules = reqDefinition.query;
|
|
6546
6515
|
const queryRes = z.object(queryRules).safeParse(actualQueryParams);
|
|
6547
6516
|
if (!queryRes.success) {
|
|
6548
6517
|
return zodErrorResult(queryRes.error, `invalid query params: (${JSON.stringify(actualQueryParams)})`);
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"./package.json": "./package.json"
|
|
13
13
|
},
|
|
14
14
|
"types": "dist/valbuild-server.cjs.d.ts",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.85.0",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"typecheck": "tsc --noEmit",
|
|
18
18
|
"test": "jest",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"@types/jest": "^29.2.5"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@valbuild/core": "~0.
|
|
27
|
-
"@valbuild/shared": "~0.
|
|
28
|
-
"@valbuild/ui": "~0.
|
|
26
|
+
"@valbuild/core": "~0.85.0",
|
|
27
|
+
"@valbuild/shared": "~0.85.0",
|
|
28
|
+
"@valbuild/ui": "~0.85.0",
|
|
29
29
|
"chokidar": "^4.0.1",
|
|
30
30
|
"image-size": "^1.0.2",
|
|
31
31
|
"minimatch": "^3.0.4",
|