@kalutskii/foundation 0.6.9 → 0.6.10

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,14 +58,6 @@ type FetchResult<T> = {
58
58
  data: null;
59
59
  };
60
60
 
61
- /**
62
- * Utility type that simplifies a given type T by flattening its structure.
63
- * This is particularly useful for improving the readability of complex types.
64
- */
65
- type Simplify<T> = {
66
- [K in keyof T]: T[K];
67
- } & {};
68
-
69
61
  type QueryPrimitive = string | number | boolean | bigint | Date | null | undefined;
70
62
  /**
71
63
  * Recursively transforms all fields of T to `string`, matching how query parameters are serialized.
@@ -74,20 +66,6 @@ type QueryPrimitive = string | number | boolean | bigint | Date | null | undefin
74
66
  type AsQuery<T> = T extends QueryPrimitive ? string : T extends readonly (infer Item)[] ? AsQuery<Item>[] : T extends object ? {
75
67
  [Key in keyof T]: AsQuery<T[Key]>;
76
68
  } : string;
77
- /**
78
- * Utility type that ensures at least one property from the specified
79
- * keys of a given type T is required, while the rest remain optional.
80
- *
81
- * This is useful for scenarios where you want to enforce that at least one
82
- * of several optional (nullable) properties must be provided in an object.
83
- *
84
- * ```ts
85
- * type Example = AtLeastOne<{ a?: string; b?: number; c?: boolean }>;
86
- * // Valid: { a: "hello" }, { b: 42 }, { c: true }, { a: "hello", b: 42 }
87
- * // Invalid: {}, { a: undefined, b: undefined, c: undefined }
88
- * ```
89
- */
90
- type AtLeastOne<T, Keys extends keyof T = keyof T> = Keys extends keyof T ? Simplify<Required<Pick<T, Keys>> & Partial<Omit<T, Keys>>> : never;
91
69
 
92
70
  /**
93
71
  * Wraps c.json with a typed success payload / (or void data) & possible APIError response.
@@ -227,6 +205,28 @@ declare const log: {
227
205
  error: (message: string, service?: string, stack?: string) => void;
228
206
  };
229
207
 
208
+ /**
209
+ * Utility type that simplifies a given type T by flattening its structure.
210
+ * This is particularly useful for improving the readability of complex types.
211
+ */
212
+ type Simplify<T> = {
213
+ [K in keyof T]: T[K];
214
+ } & {};
215
+ /**
216
+ * Utility type that ensures at least one property from the specified
217
+ * keys of a given type T is required, while the rest remain optional.
218
+ *
219
+ * This is useful for scenarios where you want to enforce that at least one
220
+ * of several optional (nullable) properties must be provided in an object.
221
+ *
222
+ * ```ts
223
+ * type Example = AtLeastOne<{ a?: string; b?: number; c?: boolean }>;
224
+ * // Valid: { a: "hello" }, { b: 42 }, { c: true }, { a: "hello", b: 42 }
225
+ * // Invalid: {}, { a: undefined, b: undefined, c: undefined }
226
+ * ```
227
+ */
228
+ type AtLeastOne<T, Keys extends keyof T = keyof T> = Keys extends keyof T ? Simplify<Required<Pick<T, Keys>> & Partial<Omit<T, Keys>>> : never;
229
+
230
230
  /** Options for configuring the JWT service. */
231
231
  type JWTServiceOptions = {
232
232
  /** The algorithm to use for signing and verifying JWTs. Defaults to 'HS256'. */
@@ -385,6 +385,7 @@ declare const isZodOptional: (schema: z.ZodTypeAny) => schema is z.ZodOptional<z
385
385
  */
386
386
  declare const unwrapOptional: (schema: z.ZodTypeAny) => z.ZodTypeAny;
387
387
 
388
+ declare const parseQueryValue: (value: unknown) => unknown;
388
389
  /**
389
390
  * Query parameters always arrive as strings, even when they semantically represent numbers
390
391
  * or booleans, so we preprocess them to convert to the appropriate types before validation.
@@ -404,4 +405,10 @@ declare const unwrapOptional: (schema: z.ZodTypeAny) => z.ZodTypeAny;
404
405
  */
405
406
  declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>;
406
407
 
407
- export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AnyZodObject, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type FlattenZodShape, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, SUCCESS_STATUS_CODES, type Simplify, type SuccessStatusCode, ZodJWTService, type ZodPaginationOptions, type ZodShape, asQuery, asQuerySchema, failure, fetchAndThrow, fetchSafely, flattenZodShape, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, isZodObject, isZodOptional, log, measureExecutionTime, onHandlerError, refinePagination, respond, safeExecute, sqlWhere, success, unwrapOptional, zodPaginationSchema, zodPaginationShape };
408
+ /**
409
+ * Checks if the given value is a plain object (i.e., an object
410
+ * that is not null, not an array, and has a prototype of Object).
411
+ */
412
+ declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
413
+
414
+ export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AnyZodObject, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type FlattenZodShape, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, SUCCESS_STATUS_CODES, type Simplify, type SuccessStatusCode, ZodJWTService, type ZodPaginationOptions, type ZodShape, asQuery, asQuerySchema, failure, fetchAndThrow, fetchSafely, flattenZodShape, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, isPlainObject, isZodObject, isZodOptional, log, measureExecutionTime, onHandlerError, parseQueryValue, refinePagination, respond, safeExecute, sqlWhere, success, unwrapOptional, zodPaginationSchema, zodPaginationShape };
package/dist/index.js CHANGED
@@ -279,6 +279,11 @@ var flattenZodShape = (shape) => {
279
279
  var asQuerySchema = (schema) => {
280
280
  return z4.object(flattenZodShape(schema.shape)).strict();
281
281
  };
282
+
283
+ // src/zod-validation/zod-validation.utilities.ts
284
+ var isPlainObject = (value) => {
285
+ return typeof value === "object" && value !== null && !Array.isArray(value);
286
+ };
282
287
  export {
283
288
  EXCEPTION_STATUS_CODES,
284
289
  SUCCESS_STATUS_CODES,
@@ -297,11 +302,13 @@ export {
297
302
  getUTCOffset,
298
303
  getZonedTime,
299
304
  honoLoggingHandler,
305
+ isPlainObject,
300
306
  isZodObject,
301
307
  isZodOptional,
302
308
  log,
303
309
  measureExecutionTime,
304
310
  onHandlerError,
311
+ parseQueryValue,
305
312
  refinePagination,
306
313
  respond,
307
314
  safeExecute,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kalutskii/foundation",
3
- "version": "0.6.9",
3
+ "version": "0.6.10",
4
4
  "description": "Typescript collection of most common utilities, schemas and functions among private projects.",
5
5
  "type": "module",
6
6
  "repository": {