@kalutskii/foundation 0.7.14 → 0.7.16

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
@@ -533,28 +533,36 @@ declare function formatTime(time: Date, { locale, tz }?: {
533
533
 
534
534
  /**
535
535
  * Recursively replaces dots in a string literal with underscores.
536
- * Every other character remains unchanged in the resulting type.
536
+ * Every other character remains unchanged in the resulting literal type.
537
537
  *
538
538
  * @example
539
539
  * type Key = ReplaceDotsWithUnderscores<'foo.bar.baz'>; // `foo_bar_baz`
540
540
  */
541
- type ReplaceDotsWithUnderscores<TValue extends string> = TValue extends `${infer Head}.${infer Tail}` ? `${Head}_${ReplaceDotsWithUnderscores<Tail>}` : TValue;
541
+ type ReplaceDotsWithUnderscores<TValue extends string> = TValue extends `${infer Head}.${infer Tail}` ? `${ReplaceDotsWithUnderscores<Head>}_${ReplaceDotsWithUnderscores<Tail>}` : TValue;
542
+ /**
543
+ * Recursively replaces hyphens in a string literal with underscores.
544
+ * Every other character remains unchanged in the resulting literal type.
545
+ *
546
+ * @example
547
+ * type Key = ReplaceHyphensWithUnderscores<'foo-bar-baz'>; // `foo_bar_baz`
548
+ */
549
+ type ReplaceHyphensWithUnderscores<TValue extends string> = TValue extends `${infer Head}-${infer Tail}` ? `${ReplaceHyphensWithUnderscores<Head>}_${ReplaceHyphensWithUnderscores<Tail>}` : TValue;
542
550
  /**
543
551
  * Maps string literals to immutable uppercase enum-like keys.
544
- * Dots become underscores while every value preserves its original literal.
552
+ * Dots and hyphens become underscores while values preserve their original literals.
545
553
  *
546
554
  * @example
547
555
  * type Statuses = StringEnumRecord<readonly ['review.pending', 'published']>;
548
556
  */
549
557
  type StringEnumRecord<TValues extends readonly string[]> = Readonly<{
550
- [Value in TValues[number] as Uppercase<ReplaceDotsWithUnderscores<Value>>]: Value;
558
+ [Value in TValues[number] as Uppercase<ReplaceHyphensWithUnderscores<ReplaceDotsWithUnderscores<Value>>>]: Value;
551
559
  }>;
552
560
  /**
553
561
  * Creates an immutable enum-like record from a readonly string array.
554
- * Keys are uppercased and every dot is replaced with an underscore.
562
+ * Keys are uppercased and every dot or hyphen is replaced with an underscore.
555
563
  *
556
564
  * @example
557
- * createStringEnumRecord(['foo.s', 'baz'] as const); // `{ FOO_S: 'foo.s', BAZ: 'baz' }`
565
+ * createStringEnumRecord(['foo-bar.s', 'baz'] as const); // `{ FOO_BAR_S: 'foo-bar.s', BAZ: 'baz' }`
558
566
  */
559
567
  declare function createStringEnumRecord<const T extends readonly string[]>(values: T): StringEnumRecord<T>;
560
568
 
@@ -899,6 +907,15 @@ declare const parseQueryValue: (value: unknown) => unknown;
899
907
  * // { page: 2, isActive: true }
900
908
  */
901
909
  declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>;
910
+ /**
911
+ * Recursively converts a domain payload into its string-based query representation.
912
+ * Objects and arrays are copied while `null` and `undefined` retain their omission semantics.
913
+ *
914
+ * @example
915
+ * preprocessQueryPayload({ page: 2, enabled: true });
916
+ * // { page: '2', enabled: 'true' }
917
+ */
918
+ declare function preprocessQueryPayload<TValue>(value: TValue): AsQuery<TValue>;
902
919
 
903
920
  /**
904
921
  * Checks whether a value is a plain record backed by `Object.prototype`.
@@ -906,4 +923,4 @@ declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>
906
923
  */
907
924
  declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
908
925
 
909
- export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, DEFAULT_UPLOAD_MAX_FILE_SIZE, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type FileFormat, type FileFormatConfig, type HonoFileRespondOptions, type HonoRespondOptions, type JWTServiceOptions, type JWTSignOptions, type LogLevel, type MeasuredExecution, type Payload, type PayloadSchema, REDACTED_LOG_VALUE, type ReplaceDotsWithUnderscores, SUCCESS_STATUS_CODES, type Simplify, type StringEnumRecord, type SuccessStatusCode, type UploadFilesValidationOptions, type UploadFilesValidationResult, type UploadPreset, type UploadValidationError, type ZodBulkExcludeSelection, type ZodBulkIncludeSelection, type ZodBulkSelection, ZodJWTService, type ZodPaginationOptions, type ZodSearchSchemaOptions, type ZodUploadFileSchemaOptions, asQuery, createStringEnumRecord, createUploadAccept, createZodSearchWhereSchema, defineUploadPreset, documentUploadPreset, failure, fetchAndThrow, fetchSafely, fileFormat, fileFormatsArray, fileFormatsConfig, fileFormatsRecord, fileRespond, formatTime, generateRandomString, getColoredHTTPStatus, getFileExtension, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, httpStatusColors, imageTransparentUploadPreset, imageUploadPreset, isFileExtensionSupported, isFileFormatSupported, isFileMimeTypeSupported, isPlainObject, log, logLevel, logLevelColors, logLevelsArray, logLevelsRecord, loggingMiddleware, matchesMimeType, measureExecutionTime, normalizeFileExtension, onHandlerError, parseQueryValue, redactSensitiveJSON, redactSensitiveSearchParams, respond, safeExecute, sensitiveLogKeyParts, sqlWhere, success, uploadValidationError, uploadValidationErrorsArray, uploadValidationErrorsRecord, validateUploadFile, validateUploadFiles, zodAtLeastOne, zodBulkSelectionSchema, zodPaginationSchema, zodPaginationShape, zodSearchQuerySchema, zodSearchSchema, zodUploadFileSchema };
926
+ export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, DEFAULT_UPLOAD_MAX_FILE_SIZE, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type FileFormat, type FileFormatConfig, type HonoFileRespondOptions, type HonoRespondOptions, type JWTServiceOptions, type JWTSignOptions, type LogLevel, type MeasuredExecution, type Payload, type PayloadSchema, REDACTED_LOG_VALUE, type ReplaceDotsWithUnderscores, type ReplaceHyphensWithUnderscores, SUCCESS_STATUS_CODES, type Simplify, type StringEnumRecord, type SuccessStatusCode, type UploadFilesValidationOptions, type UploadFilesValidationResult, type UploadPreset, type UploadValidationError, type ZodBulkExcludeSelection, type ZodBulkIncludeSelection, type ZodBulkSelection, ZodJWTService, type ZodPaginationOptions, type ZodSearchSchemaOptions, type ZodUploadFileSchemaOptions, asQuery, createStringEnumRecord, createUploadAccept, createZodSearchWhereSchema, defineUploadPreset, documentUploadPreset, failure, fetchAndThrow, fetchSafely, fileFormat, fileFormatsArray, fileFormatsConfig, fileFormatsRecord, fileRespond, formatTime, generateRandomString, getColoredHTTPStatus, getFileExtension, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, httpStatusColors, imageTransparentUploadPreset, imageUploadPreset, isFileExtensionSupported, isFileFormatSupported, isFileMimeTypeSupported, isPlainObject, log, logLevel, logLevelColors, logLevelsArray, logLevelsRecord, loggingMiddleware, matchesMimeType, measureExecutionTime, normalizeFileExtension, onHandlerError, parseQueryValue, preprocessQueryPayload, redactSensitiveJSON, redactSensitiveSearchParams, respond, safeExecute, sensitiveLogKeyParts, sqlWhere, success, uploadValidationError, uploadValidationErrorsArray, uploadValidationErrorsRecord, validateUploadFile, validateUploadFiles, zodAtLeastOne, zodBulkSelectionSchema, zodPaginationSchema, zodPaginationShape, zodSearchQuerySchema, zodSearchSchema, zodUploadFileSchema };
package/dist/index.js CHANGED
@@ -56,7 +56,7 @@ import { blue, green, red, yellow } from "kleur/colors";
56
56
 
57
57
  // src/utilities/enums.utilities.ts
58
58
  function createStringEnumRecord(values) {
59
- return Object.freeze(Object.fromEntries(values.map((value) => [value.replace(/\./g, "_").toUpperCase(), value])));
59
+ return Object.freeze(Object.fromEntries(values.map((value) => [value.replaceAll(/[.-]/g, "_").toUpperCase(), value])));
60
60
  }
61
61
 
62
62
  // src/logging/logging.enums.ts
@@ -524,6 +524,20 @@ var parseQueryValue = (value) => {
524
524
  return value;
525
525
  };
526
526
  var asQuery = (schema) => z5.preprocess(parseQueryValue, schema);
527
+ function preprocessQueryPayload(value) {
528
+ if (Array.isArray(value)) {
529
+ return value.map(preprocessQueryPayload);
530
+ }
531
+ if (isPlainObject(value)) {
532
+ const entries = Object.entries(value).map(([key, entryValue]) => {
533
+ return [key, preprocessQueryPayload(entryValue)];
534
+ });
535
+ return Object.fromEntries(entries);
536
+ }
537
+ if (value === null || value === void 0)
538
+ return value;
539
+ return String(value);
540
+ }
527
541
  export {
528
542
  DEFAULT_UPLOAD_MAX_FILE_SIZE,
529
543
  EXCEPTION_STATUS_CODES,
@@ -570,6 +584,7 @@ export {
570
584
  normalizeFileExtension,
571
585
  onHandlerError,
572
586
  parseQueryValue,
587
+ preprocessQueryPayload,
573
588
  redactSensitiveJSON,
574
589
  redactSensitiveSearchParams,
575
590
  respond,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kalutskii/foundation",
3
- "version": "0.7.14",
3
+ "version": "0.7.16",
4
4
  "description": "Typescript collection of most common utilities, schemas and functions among private projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",