@kalutskii/foundation 0.6.2 → 0.6.4
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 +12 -24
- package/dist/index.js +7 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -219,6 +219,17 @@ type Simplify<T> = {
|
|
|
219
219
|
[K in keyof T]: T[K];
|
|
220
220
|
} & {};
|
|
221
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Transforms a string to a number (when passing query parameters).
|
|
224
|
+
* Example usage: `asQueryNumber(z.number())('123') = 123`
|
|
225
|
+
*/
|
|
226
|
+
declare const asQueryNumber: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>;
|
|
227
|
+
/**
|
|
228
|
+
* Transforms various string representations of boolean values into actual booleans.
|
|
229
|
+
* See POSITIVE_VALUES and NEGATIVE_VALUES arrays below for supported inputs.
|
|
230
|
+
*/
|
|
231
|
+
declare const asQueryBoolean: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>;
|
|
232
|
+
|
|
222
233
|
/**
|
|
223
234
|
* A utility type that represents a value that can be of type T or null.
|
|
224
235
|
* Commonly used for optional fields in data models or function return types.
|
|
@@ -249,29 +260,6 @@ type XOR<T, U> = Simplify<T & {
|
|
|
249
260
|
*/
|
|
250
261
|
type AtLeastOne<T, Keys extends keyof T = keyof T> = Keys extends keyof T ? Simplify<Required<Pick<T, Keys>> & Partial<Omit<T, Keys>>> : never;
|
|
251
262
|
|
|
252
|
-
/**
|
|
253
|
-
* Refines a Zod object schema to ensure that at least one of its keys is defined.
|
|
254
|
-
* This is useful for validating objects where at least one property must be present.
|
|
255
|
-
*
|
|
256
|
-
* ```ts
|
|
257
|
-
* const mySchema = z.object({
|
|
258
|
-
* a: z.string()
|
|
259
|
-
* b: z.number()
|
|
260
|
-
* }).refine(atLeastOneDefined);
|
|
261
|
-
* ```
|
|
262
|
-
*/
|
|
263
|
-
declare const atLeastOneDefined: <T extends z.ZodRawShape>(schema: z.ZodObject<T>) => z.ZodType<AtLeastOne<z.infer<z.ZodObject<T>>>>;
|
|
264
|
-
/**
|
|
265
|
-
* Transforms a string to a number (when passing query parameters).
|
|
266
|
-
* Example usage: `asQueryNumber(z.number())('123') = 123`
|
|
267
|
-
*/
|
|
268
|
-
declare const asQueryNumber: <T extends z.ZodNumber>(schema: T) => z.ZodPreprocess<T>;
|
|
269
|
-
/**
|
|
270
|
-
* Transforms various string representations of boolean values into actual booleans.
|
|
271
|
-
* See POSITIVE_VALUES and NEGATIVE_VALUES arrays below for supported inputs.
|
|
272
|
-
*/
|
|
273
|
-
declare const asQueryBoolean: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>;
|
|
274
|
-
|
|
275
263
|
/** Options for configuring the JWT service. */
|
|
276
264
|
type JWTServiceOptions = {
|
|
277
265
|
/** The algorithm to use for signing and verifying JWTs. Defaults to 'HS256'. */
|
|
@@ -320,4 +308,4 @@ declare class ZodJWTService<TPayloadOrSchema> {
|
|
|
320
308
|
verifyOrThrow(token: string, secret: string): Promise<Payload<TPayloadOrSchema>>;
|
|
321
309
|
}
|
|
322
310
|
|
|
323
|
-
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type PaginationOptions, type Payload, type PayloadSchema, SUCCESS_STATUS_CODES, type Simplify, type SuccessStatusCode, type XOR, ZodJWTService, asQueryBoolean, asQueryNumber,
|
|
311
|
+
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type PaginationOptions, type Payload, type PayloadSchema, SUCCESS_STATUS_CODES, type Simplify, type SuccessStatusCode, type XOR, ZodJWTService, asQueryBoolean, asQueryNumber, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, log, measureExecutionTime, onHandlerError, paginationSchema, refinePagination, respond, safeExecute, success };
|
package/dist/index.js
CHANGED
|
@@ -168,18 +168,13 @@ async function measureExecutionTime(execution) {
|
|
|
168
168
|
|
|
169
169
|
// src/validation/validation.refiners.ts
|
|
170
170
|
import z2 from "zod";
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return schema.partial().refine((value) => keys.some((key) => value[key] != null), {
|
|
179
|
-
message: AT_LEAST_ONE_DEFINED_ERROR(keys)
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
var asQueryNumber = (schema) => z2.preprocess((v) => typeof v === "string" ? Number(v) : v, schema);
|
|
171
|
+
var asQueryNumber = (schema) => z2.preprocess((value) => {
|
|
172
|
+
if (typeof value !== "string")
|
|
173
|
+
return value;
|
|
174
|
+
if (value.trim() === "")
|
|
175
|
+
return value;
|
|
176
|
+
return Number(value);
|
|
177
|
+
}, schema);
|
|
183
178
|
var asQueryBoolean = (schema) => {
|
|
184
179
|
const POSITIVE_VALUES = ["1", "true", "yes", "y", "on"];
|
|
185
180
|
const NEGATIVE_VALUES = ["0", "false", "no", "n", "off"];
|
|
@@ -251,7 +246,6 @@ export {
|
|
|
251
246
|
ZodJWTService,
|
|
252
247
|
asQueryBoolean,
|
|
253
248
|
asQueryNumber,
|
|
254
|
-
atLeastOneDefined,
|
|
255
249
|
failure,
|
|
256
250
|
fetchAndThrow,
|
|
257
251
|
fetchSafely,
|