@kalutskii/foundation 0.6.11 → 0.6.12
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/dist/index.d.ts +11 -11
- package/dist/index.js +10 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -58,12 +58,12 @@ type FetchResult<T> = {
|
|
|
58
58
|
data: null;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
type QueryPrimitive = string | number | boolean | bigint | Date
|
|
61
|
+
type QueryPrimitive = string | number | boolean | bigint | Date;
|
|
62
62
|
/**
|
|
63
63
|
* Recursively transforms all fields of T to `string`, matching how query parameters are serialized.
|
|
64
64
|
* Handles nested objects, arrays, and primitive values (including null and undefined as optional).
|
|
65
65
|
*/
|
|
66
|
-
type AsQuery<T> = T extends QueryPrimitive ? string : T extends readonly (infer Item)[] ? AsQuery<Item>[] : T extends object ? {
|
|
66
|
+
type AsQuery<T> = T extends null | undefined ? T : T extends QueryPrimitive ? string : T extends readonly (infer Item)[] ? AsQuery<Item>[] : T extends object ? {
|
|
67
67
|
[Key in keyof T]: AsQuery<T[Key]>;
|
|
68
68
|
} : string;
|
|
69
69
|
|
|
@@ -317,21 +317,21 @@ declare const refinePagination: (options?: ZodPaginationOptions) => ZodPaginatio
|
|
|
317
317
|
|
|
318
318
|
declare const parseQueryValue: (value: unknown) => unknown;
|
|
319
319
|
/**
|
|
320
|
-
*
|
|
321
|
-
*
|
|
320
|
+
* Preprocesses query-like values before Zod validation.
|
|
321
|
+
*
|
|
322
|
+
* Query parameters are string-based by nature, even when they semantically represent
|
|
323
|
+
* numbers or booleans. This helper converts only clear primitive values, allowing
|
|
324
|
+
* regular schemas like `z.number()` and `z.boolean()` to validate query input directly.
|
|
322
325
|
*
|
|
323
326
|
* ```ts
|
|
324
|
-
* const schema = z.object({
|
|
327
|
+
* const schema = asQuery(z.object({
|
|
325
328
|
* page: z.number().int().positive(),
|
|
326
329
|
* isActive: z.boolean(),
|
|
327
|
-
* });
|
|
330
|
+
* }));
|
|
328
331
|
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
332
|
+
* schema.parse({ page: '2', isActive: 'true' });
|
|
333
|
+
* // { page: 2, isActive: true }
|
|
331
334
|
* ```
|
|
332
|
-
*
|
|
333
|
-
* @param schema - The Zod schema to validate the query parameters against.
|
|
334
|
-
* @returns A new Zod schema that preprocesses query parameter values before validation.
|
|
335
335
|
*/
|
|
336
336
|
declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>;
|
|
337
337
|
|
package/dist/index.js
CHANGED
|
@@ -219,9 +219,19 @@ import z2 from "zod";
|
|
|
219
219
|
|
|
220
220
|
// src/zod-validation/zod-validation.refiners.ts
|
|
221
221
|
import z from "zod";
|
|
222
|
+
|
|
223
|
+
// src/zod-validation/zod-validation.utilities.ts
|
|
224
|
+
var isPlainObject = (value) => {
|
|
225
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/zod-validation/zod-validation.refiners.ts
|
|
222
229
|
var parseQueryValue = (value) => {
|
|
223
230
|
if (Array.isArray(value))
|
|
224
231
|
return value.map(parseQueryValue);
|
|
232
|
+
if (isPlainObject(value)) {
|
|
233
|
+
return Object.fromEntries(Object.entries(value).map(([key, value2]) => [key, parseQueryValue(value2)]));
|
|
234
|
+
}
|
|
225
235
|
if (typeof value !== "string")
|
|
226
236
|
return value;
|
|
227
237
|
const normalized = value.trim().toLowerCase();
|
|
@@ -245,11 +255,6 @@ var zodPaginationSchema = z2.object({
|
|
|
245
255
|
limit: asQuery(z2.number().int().positive()).optional()
|
|
246
256
|
});
|
|
247
257
|
var zodPaginationShape = zodPaginationSchema.shape;
|
|
248
|
-
|
|
249
|
-
// src/zod-validation/zod-validation.utilities.ts
|
|
250
|
-
var isPlainObject = (value) => {
|
|
251
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
252
|
-
};
|
|
253
258
|
export {
|
|
254
259
|
EXCEPTION_STATUS_CODES,
|
|
255
260
|
SUCCESS_STATUS_CODES,
|