@kalutskii/foundation 0.6.11 → 0.6.13

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 CHANGED
@@ -58,12 +58,12 @@ type FetchResult<T> = {
58
58
  data: null;
59
59
  };
60
60
 
61
- type QueryPrimitive = string | number | boolean | bigint | Date | null | undefined;
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
 
@@ -280,8 +280,8 @@ declare class ZodJWTService<TPayloadOrSchema> {
280
280
  }
281
281
 
282
282
  declare const zodPaginationSchema: z.ZodObject<{
283
- offset: z.ZodOptional<z.ZodPreprocess<z.ZodNumber>>;
284
- limit: z.ZodOptional<z.ZodPreprocess<z.ZodNumber>>;
283
+ offset: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
284
+ limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
285
285
  }, z.core.$strip>;
286
286
  /**
287
287
  * Reusable pagination fields for flat query schemas, allowing for
@@ -291,8 +291,8 @@ declare const zodPaginationSchema: z.ZodObject<{
291
291
  * or use `zodPaginationSchema.extend(...)` when building directly from the schema.
292
292
  */
293
293
  declare const zodPaginationShape: {
294
- offset: z.ZodOptional<z.ZodPreprocess<z.ZodNumber>>;
295
- limit: z.ZodOptional<z.ZodPreprocess<z.ZodNumber>>;
294
+ offset: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
295
+ limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
296
296
  };
297
297
  /**
298
298
  * TypeScript type representing the pagination options validated by the `zodPaginationSchema`.
@@ -317,21 +317,21 @@ declare const refinePagination: (options?: ZodPaginationOptions) => ZodPaginatio
317
317
 
318
318
  declare const parseQueryValue: (value: unknown) => unknown;
319
319
  /**
320
- * Query parameters always arrive as strings, even when they semantically represent numbers
321
- * or booleans, so we preprocess them to convert to the appropriate types before validation.
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
- * const queryParams = { page: '2', isActive: 'true' };
330
- * const result = schema.parse(queryParams); // { page: 2, isActive: true }
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
@@ -215,13 +215,30 @@ var refinePagination = (options) => ({
215
215
  });
216
216
 
217
217
  // src/zod-pagination/zod-pagination.schemas.ts
218
+ import z from "zod";
219
+ var zodPaginationSchema = z.object({
220
+ /** Integer representing the starting point for pagination. */
221
+ offset: z.coerce.number().int().nonnegative().optional(),
222
+ /** Integer representing the maximum number of items to return. */
223
+ limit: z.coerce.number().int().positive().optional()
224
+ });
225
+ var zodPaginationShape = zodPaginationSchema.shape;
226
+
227
+ // src/zod-validation/zod-validation.refiners.ts
218
228
  import z2 from "zod";
219
229
 
230
+ // src/zod-validation/zod-validation.utilities.ts
231
+ var isPlainObject = (value) => {
232
+ return typeof value === "object" && value !== null && !Array.isArray(value);
233
+ };
234
+
220
235
  // src/zod-validation/zod-validation.refiners.ts
221
- import z from "zod";
222
236
  var parseQueryValue = (value) => {
223
237
  if (Array.isArray(value))
224
238
  return value.map(parseQueryValue);
239
+ if (isPlainObject(value)) {
240
+ return Object.fromEntries(Object.entries(value).map(([key, value2]) => [key, parseQueryValue(value2)]));
241
+ }
225
242
  if (typeof value !== "string")
226
243
  return value;
227
244
  const normalized = value.trim().toLowerCase();
@@ -235,21 +252,7 @@ var parseQueryValue = (value) => {
235
252
  return Number(normalized);
236
253
  return value;
237
254
  };
238
- var asQuery = (schema) => z.preprocess(parseQueryValue, schema);
239
-
240
- // src/zod-pagination/zod-pagination.schemas.ts
241
- var zodPaginationSchema = z2.object({
242
- /** Integer representing the starting point for pagination. */
243
- offset: asQuery(z2.number().int().nonnegative()).optional(),
244
- /** Integer representing the maximum number of items to return. */
245
- limit: asQuery(z2.number().int().positive()).optional()
246
- });
247
- 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
- };
255
+ var asQuery = (schema) => z2.preprocess(parseQueryValue, schema);
253
256
  export {
254
257
  EXCEPTION_STATUS_CODES,
255
258
  SUCCESS_STATUS_CODES,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kalutskii/foundation",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
4
4
  "description": "Typescript collection of most common utilities, schemas and functions among private projects.",
5
5
  "type": "module",
6
6
  "repository": {