@kalutskii/foundation 0.6.2 → 0.6.3

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
@@ -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.ZodNumber | z.ZodInt>(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, atLeastOneDefined, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, log, measureExecutionTime, onHandlerError, paginationSchema, refinePagination, respond, safeExecute, success };
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,17 +168,6 @@ async function measureExecutionTime(execution) {
168
168
 
169
169
  // src/validation/validation.refiners.ts
170
170
  import z2 from "zod";
171
-
172
- // src/validation/validation.messages.ts
173
- var AT_LEAST_ONE_DEFINED_ERROR = (keys) => `At least one of the specified keys must be defined: ${keys.join(", ")}`;
174
-
175
- // src/validation/validation.refiners.ts
176
- var atLeastOneDefined = (schema) => {
177
- const keys = Object.keys(schema.shape);
178
- return schema.partial().refine((value) => keys.some((key) => value[key] != null), {
179
- message: AT_LEAST_ONE_DEFINED_ERROR(keys)
180
- });
181
- };
182
171
  var asQueryNumber = (schema) => z2.preprocess((v) => typeof v === "string" ? Number(v) : v, schema);
183
172
  var asQueryBoolean = (schema) => {
184
173
  const POSITIVE_VALUES = ["1", "true", "yes", "y", "on"];
@@ -251,7 +240,6 @@ export {
251
240
  ZodJWTService,
252
241
  asQueryBoolean,
253
242
  asQueryNumber,
254
- atLeastOneDefined,
255
243
  failure,
256
244
  fetchAndThrow,
257
245
  fetchSafely,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kalutskii/foundation",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Typescript collection of most common utilities, schemas and functions among private projects.",
5
5
  "type": "module",
6
6
  "repository": {