@kalutskii/foundation 0.6.3 → 0.6.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/dist/index.d.ts CHANGED
@@ -104,8 +104,8 @@ declare function fetchAndThrow<TResult extends APIContractResult<unknown>>(fetch
104
104
  * ```
105
105
  */
106
106
  declare const paginationSchema: z.ZodObject<{
107
- offset: z.ZodOptional<z.ZodNumber>;
108
- limit: z.ZodOptional<z.ZodNumber>;
107
+ offset: z.ZodOptional<z.ZodPreprocess<z.ZodNumber>>;
108
+ limit: z.ZodOptional<z.ZodPreprocess<z.ZodNumber>>;
109
109
  }, z.core.$strip>;
110
110
  /**
111
111
  * A TypeScript type representing the pagination options validated by the `paginationSchema`.
@@ -223,7 +223,7 @@ type Simplify<T> = {
223
223
  * Transforms a string to a number (when passing query parameters).
224
224
  * Example usage: `asQueryNumber(z.number())('123') = 123`
225
225
  */
226
- declare const asQueryNumber: <T extends z.ZodNumber | z.ZodInt>(schema: T) => z.ZodPreprocess<T>;
226
+ declare const asQueryNumber: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>;
227
227
  /**
228
228
  * Transforms various string representations of boolean values into actual booleans.
229
229
  * See POSITIVE_VALUES and NEGATIVE_VALUES arrays below for supported inputs.
package/dist/index.js CHANGED
@@ -131,10 +131,38 @@ async function fetchAndThrow(fetcher) {
131
131
  }
132
132
 
133
133
  // src/pagination/pagination.schemas.ts
134
+ import z2 from "zod";
135
+
136
+ // src/validation/validation.refiners.ts
134
137
  import z from "zod";
135
- var paginationSchema = z.object({
136
- offset: z.number().int().nonnegative().optional(),
137
- limit: z.number().int().positive().optional()
138
+ var asQueryNumber = (schema) => z.preprocess((value) => {
139
+ if (typeof value !== "string")
140
+ return value;
141
+ if (value.trim() === "")
142
+ return value;
143
+ return Number(value);
144
+ }, schema);
145
+ var asQueryBoolean = (schema) => {
146
+ const POSITIVE_VALUES = ["1", "true", "yes", "y", "on"];
147
+ const NEGATIVE_VALUES = ["0", "false", "no", "n", "off"];
148
+ return z.preprocess((value) => {
149
+ if (typeof value === "boolean")
150
+ return value;
151
+ if (typeof value === "string") {
152
+ const normalized = value.trim().toLowerCase();
153
+ if (POSITIVE_VALUES.includes(normalized))
154
+ return true;
155
+ if (NEGATIVE_VALUES.includes(normalized))
156
+ return false;
157
+ }
158
+ return value;
159
+ }, schema);
160
+ };
161
+
162
+ // src/pagination/pagination.schemas.ts
163
+ var paginationSchema = z2.object({
164
+ offset: asQueryNumber(z2.number().int().nonnegative()).optional(),
165
+ limit: asQueryNumber(z2.number().int().positive()).optional()
138
166
  });
139
167
 
140
168
  // src/pagination/pagination.refiners.ts
@@ -166,26 +194,6 @@ async function measureExecutionTime(execution) {
166
194
  return { result, executionTime: Math.round(executionTime) };
167
195
  }
168
196
 
169
- // src/validation/validation.refiners.ts
170
- import z2 from "zod";
171
- var asQueryNumber = (schema) => z2.preprocess((v) => typeof v === "string" ? Number(v) : v, schema);
172
- var asQueryBoolean = (schema) => {
173
- const POSITIVE_VALUES = ["1", "true", "yes", "y", "on"];
174
- const NEGATIVE_VALUES = ["0", "false", "no", "n", "off"];
175
- return z2.preprocess((value) => {
176
- if (typeof value === "boolean")
177
- return value;
178
- if (typeof value === "string") {
179
- const normalized = value.trim().toLowerCase();
180
- if (POSITIVE_VALUES.includes(normalized))
181
- return true;
182
- if (NEGATIVE_VALUES.includes(normalized))
183
- return false;
184
- }
185
- return value;
186
- }, schema);
187
- };
188
-
189
197
  // src/zod-jwt/zod-jwt.schemas.ts
190
198
  import { decode as decodeJWT, sign as signJWT, verify as verifyJWT } from "hono/jwt";
191
199
  var ZodJWTService = class {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kalutskii/foundation",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "Typescript collection of most common utilities, schemas and functions among private projects.",
5
5
  "type": "module",
6
6
  "repository": {