@kalutskii/foundation 0.6.25 → 0.7.1

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
@@ -1,7 +1,7 @@
1
1
  import { SQL } from 'drizzle-orm';
2
2
  import { ErrorHandler, MiddlewareHandler, Context, TypedResponse } from 'hono';
3
3
  import { Locale } from 'date-fns';
4
- import z, { ZodObject, ZodRawShape, z as z$1 } from 'zod';
4
+ import z$1, { z, ZodObject, ZodRawShape } from 'zod';
5
5
  import { SymmetricAlgorithm } from 'hono/utils/jwt/jwa';
6
6
 
7
7
  /**
@@ -66,6 +66,16 @@ declare function respond<T extends object = Record<string, never>, S extends Suc
66
66
  status: S;
67
67
  data?: T;
68
68
  }): Response & TypedResponse<APISuccess<T> | APIError, S, 'json'>;
69
+ /**
70
+ * Responds with a file download, setting the appropriate headers for content disposition and type.
71
+ * Supports specifying a filename and optional content type, defaulting to 'application/octet-stream'.
72
+ */
73
+ declare function fileRespond<S extends SuccessStatusCode>(c: Context, options: {
74
+ status: S;
75
+ content: ArrayBuffer;
76
+ filename: string;
77
+ contentType?: string;
78
+ }): Response;
69
79
 
70
80
  /**
71
81
  * Factory for creating successful API responses with serializable data.
@@ -252,7 +262,7 @@ declare const zodBulkSelectionSchema: <const TIdentifierSchema extends z.ZodType
252
262
  * Shared bulk-selection payload produced by `zodBulkSelectionSchema`.
253
263
  * String identifiers are used by default for frontend table integrations.
254
264
  */
255
- type ZodBulkSelection<TIdentifier extends string | number = string> = z.infer<ReturnType<typeof zodBulkSelectionSchema<z.ZodType<TIdentifier>>>>;
265
+ type ZodBulkSelection<TIdentifier extends string | number = string> = z$1.infer<ReturnType<typeof zodBulkSelectionSchema<z.ZodType<TIdentifier>>>>;
256
266
  /**
257
267
  * Explicit bulk selection containing only identifiers chosen by the client.
258
268
  * This branch does not require resolving an all-matching search snapshot.
@@ -283,11 +293,11 @@ type JWTSignOptions = {
283
293
  /**
284
294
  * Utility types for inferring payload types from Zod schemas.
285
295
  */
286
- type Payload<T> = T extends z.ZodType ? z.infer<T> : T;
296
+ type Payload<T> = T extends z$1.ZodType ? z$1.infer<T> : T;
287
297
  /**
288
298
  * Utility type to extract the payload schema type from a Zod schema.
289
299
  * */
290
- type PayloadSchema<T> = T extends z.ZodType ? T : never;
300
+ type PayloadSchema<T> = T extends z$1.ZodType ? T : never;
291
301
 
292
302
  /**
293
303
  * A service class for handling JWT operations with optional Zod schema validation for the payload.
@@ -341,7 +351,7 @@ declare const zodPaginationShape: {
341
351
  * TypeScript output produced after successful pagination validation.
342
352
  * Defaulted fields are represented as required numeric properties.
343
353
  */
344
- type ZodPaginationOptions = z.infer<typeof zodPaginationSchema>;
354
+ type ZodPaginationOptions = z$1.infer<typeof zodPaginationSchema>;
345
355
  /**
346
356
  * Feature flags shared by both supported search schema composition modes.
347
357
  * Literal values are preserved in the resulting runtime and static shapes.
@@ -365,12 +375,12 @@ type ZodSearchFeatureOptions<TQueryEnabled extends boolean, TPaginationEnabled e
365
375
  * `filters` is the concise mode that applies partial and non-empty rules.
366
376
  * `whereSchema` accepts a fully prepared schema with custom Zod effects.
367
377
  */
368
- type ZodSearchSchemaOptions<TShape extends z.ZodRawShape = never, TWhereSchema extends z.ZodType<Record<string, unknown>> = never, TQueryEnabled extends boolean = true, TPaginationEnabled extends boolean = true> = ZodSearchFeatureOptions<TQueryEnabled, TPaginationEnabled> & ({
378
+ type ZodSearchSchemaOptions<TShape extends z$1.ZodRawShape = never, TWhereSchema extends z$1.ZodType<Record<string, unknown>> = never, TQueryEnabled extends boolean = true, TPaginationEnabled extends boolean = true> = ZodSearchFeatureOptions<TQueryEnabled, TPaginationEnabled> & ({
369
379
  /**
370
380
  * Object schema whose fields become optional filters inside `where`.
371
381
  * The factory requires one defined value whenever `where` is present.
372
382
  */
373
- filters: z.ZodObject<TShape>;
383
+ filters: z$1.ZodObject<TShape>;
374
384
  /** Prevents combining automatic filters with a prepared schema. */
375
385
  whereSchema?: never;
376
386
  } | {
@@ -470,7 +480,7 @@ type AtLeastOne<T, Keys extends keyof T = keyof T> = Keys extends keyof T ? Simp
470
480
  * zQuery(zodAtLeastOne(userSelectSchema)) // result: UserSelect ✓
471
481
  * ```
472
482
  */
473
- declare const zodAtLeastOne: <T extends ZodObject<ZodRawShape>>(schema: T) => z$1.ZodPipe<T, z$1.ZodTransform<Awaited<AtLeastOne<z$1.core.output<T>>>, z$1.core.output<T>>>;
483
+ declare const zodAtLeastOne: <T extends ZodObject<ZodRawShape>>(schema: T) => z.ZodPipe<T, z.ZodTransform<Awaited<AtLeastOne<z.core.output<T>>>, z.core.output<T>>>;
474
484
 
475
485
  declare const parseQueryValue: (value: unknown) => unknown;
476
486
  /**
@@ -498,4 +508,4 @@ declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>
498
508
  */
499
509
  declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
500
510
 
501
- 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 Payload, type PayloadSchema, type ReplaceDotsWithUnderscores, SUCCESS_STATUS_CODES, type Simplify, type StringEnumRecord, type SuccessStatusCode, type ZodBulkExcludeSelection, type ZodBulkIncludeSelection, type ZodBulkSelection, ZodJWTService, type ZodPaginationOptions, type ZodSearchSchemaOptions, asQuery, createStringEnumRecord, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, isPlainObject, log, measureExecutionTime, onHandlerError, parseQueryValue, respond, safeExecute, sqlWhere, success, zodAtLeastOne, zodBulkSelectionSchema, zodPaginationSchema, zodPaginationShape, zodSearchSchema };
511
+ 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 Payload, type PayloadSchema, type ReplaceDotsWithUnderscores, SUCCESS_STATUS_CODES, type Simplify, type StringEnumRecord, type SuccessStatusCode, type ZodBulkExcludeSelection, type ZodBulkIncludeSelection, type ZodBulkSelection, ZodJWTService, type ZodPaginationOptions, type ZodSearchSchemaOptions, asQuery, createStringEnumRecord, failure, fetchAndThrow, fetchSafely, fileRespond, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, isPlainObject, log, measureExecutionTime, onHandlerError, parseQueryValue, respond, safeExecute, sqlWhere, success, zodAtLeastOne, zodBulkSelectionSchema, zodPaginationSchema, zodPaginationShape, zodSearchSchema };
package/dist/index.js CHANGED
@@ -123,6 +123,11 @@ var honoLoggingHandler = async (c, next) => {
123
123
  function respond(c, options) {
124
124
  return c.json(success({ status: options.status, data: options.data ?? {} }), options.status);
125
125
  }
126
+ function fileRespond(c, options) {
127
+ c.header("Content-Disposition", `attachment; filename="${options.filename}"`);
128
+ c.header("Content-Type", options.contentType ?? "application/octet-stream");
129
+ return c.body(options.content, options.status);
130
+ }
126
131
 
127
132
  // src/http/http.constants.ts
128
133
  var SUCCESS_STATUS_CODES = [200, 201, 202, 307];
@@ -165,7 +170,7 @@ async function measureExecutionTime(execution) {
165
170
  }
166
171
 
167
172
  // src/zod-bulk/zod-bulk.schemas.ts
168
- import z from "zod";
173
+ import { z } from "zod";
169
174
  var DEFAULT_ERROR_MESSAGE = "Selection identifiers must be provided.";
170
175
  var zodBulkSelectionSchema = ({ identifierSchema }) => {
171
176
  const identifiersSchema = z.array(identifierSchema).refine((identifiers) => new Set(identifiers).size === identifiers.length, {
@@ -227,7 +232,7 @@ var ZodJWTService = class {
227
232
  };
228
233
 
229
234
  // src/zod-search/zod-search.pagination.schemas.ts
230
- import z2 from "zod";
235
+ import { z as z2 } from "zod";
231
236
  var zodPaginationSchema = z2.object({
232
237
  /**
233
238
  * Zero-based number of records skipped before collecting a result page.
@@ -243,7 +248,7 @@ var zodPaginationSchema = z2.object({
243
248
  var zodPaginationShape = zodPaginationSchema.shape;
244
249
 
245
250
  // src/zod-search/zod-search.schemas.ts
246
- import z3 from "zod";
251
+ import { z as z3 } from "zod";
247
252
 
248
253
  // src/zod-validation/zod-validation.refiners.ts
249
254
  var DEFAULT_ERROR_MESSAGE2 = "Invalid input. At least one field must be provided.";
@@ -267,7 +272,7 @@ var zodSearchSchema = (options) => {
267
272
  };
268
273
 
269
274
  // src/zod-validation/zod-validation.parsing.ts
270
- import z4 from "zod";
275
+ import { z as z4 } from "zod";
271
276
 
272
277
  // src/zod-validation/zod-validation.utilities.ts
273
278
  var isPlainObject = (value) => {
@@ -304,6 +309,7 @@ export {
304
309
  failure,
305
310
  fetchAndThrow,
306
311
  fetchSafely,
312
+ fileRespond,
307
313
  formatTime,
308
314
  generateRandomString,
309
315
  getColoredHTTPStatus,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kalutskii/foundation",
3
- "version": "0.6.25",
3
+ "version": "0.7.1",
4
4
  "description": "Typescript collection of most common utilities, schemas and functions among private projects.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -12,10 +12,10 @@
12
12
  },
13
13
  "scripts": {
14
14
  "build": "tsup",
15
+ "typecheck": "tsc --noEmit",
15
16
  "lint": "eslint . --ext .ts --fix",
16
17
  "format": "prettier --write .",
17
- "test": "bun test",
18
- "typecheck": "tsc --noEmit"
18
+ "test": "bun test"
19
19
  },
20
20
  "exports": {
21
21
  ".": {