@kalutskii/foundation 0.7.9 → 0.7.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/README.md +2 -1
- package/dist/index.d.ts +66 -1
- package/dist/index.js +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ The package contains several deliberately isolated areas:
|
|
|
24
24
|
| ---------------- | ----------------------------------------------------------------------------------------- |
|
|
25
25
|
| `utilities` | Framework-independent datetime, enum, execution, generation, logging, and type utilities. |
|
|
26
26
|
| `http` | Shared HTTP result contracts, factories, status constants, and result resolvers. |
|
|
27
|
-
| `upload` | Shared file-format metadata,
|
|
27
|
+
| `upload` | Shared upload presets, file-format metadata, validation, and reusable Zod schemas. |
|
|
28
28
|
| `zod-validation` | Generic Zod parsing, validation, refinement, and related type utilities. |
|
|
29
29
|
| `zod-search` | Reusable search and pagination contracts composed from lower-level Zod primitives. |
|
|
30
30
|
| `zod-bulk` | Include/exclude selection contracts shared by frontend and backend bulk operations. |
|
|
@@ -122,6 +122,7 @@ single public API boundary and should export only symbols intentionally supporte
|
|
|
122
122
|
| `*.services.ts` | Stateful service classes that coordinate one external capability. |
|
|
123
123
|
| `*.validation.ts` | Ordered validation behavior returning stable domain error keys. |
|
|
124
124
|
| `*.factory.ts` | Functions whose primary responsibility is constructing non-schema values. |
|
|
125
|
+
| `*.presets.ts` | Ready-to-use policies composed from public domain values. |
|
|
125
126
|
| `*.resolvers.ts` | Functions that unwrap, normalize, or translate an existing result. |
|
|
126
127
|
| `*.utilities.ts` | Stateless reusable behavior that has no narrower architectural owner. |
|
|
127
128
|
| `*.parsing.ts` | Input parsing and preprocessing before domain validation. |
|
package/dist/index.d.ts
CHANGED
|
@@ -194,6 +194,32 @@ declare const uploadValidationError: Readonly<{
|
|
|
194
194
|
}>;
|
|
195
195
|
|
|
196
196
|
type FileFormatConfig = (typeof fileFormatsConfig)[FileFormat];
|
|
197
|
+
/**
|
|
198
|
+
* Shared upload policy consumed by browser controls and backend validation.
|
|
199
|
+
* One preset keeps format, size, capacity, and fallback rules synchronized.
|
|
200
|
+
*/
|
|
201
|
+
type UploadPreset<TFormats extends readonly FileFormat[] = readonly FileFormat[]> = Readonly<{
|
|
202
|
+
/**
|
|
203
|
+
* Supported formats accepted by every consumer of the preset.
|
|
204
|
+
* Const inference preserves the supplied format tuple without widening.
|
|
205
|
+
*/
|
|
206
|
+
formats: TFormats;
|
|
207
|
+
/**
|
|
208
|
+
* Maximum accepted size of one uploaded file measured in bytes.
|
|
209
|
+
* Schema and client validation can share this exact numeric boundary.
|
|
210
|
+
*/
|
|
211
|
+
maxFileSize: number;
|
|
212
|
+
/**
|
|
213
|
+
* Optional maximum number of files retained by one upload collection.
|
|
214
|
+
* Single-file controls can set this value to `1` for shared capacity rules.
|
|
215
|
+
*/
|
|
216
|
+
maxFilesCount?: number;
|
|
217
|
+
/**
|
|
218
|
+
* Allows extensions to compensate for absent or unreliable MIME metadata.
|
|
219
|
+
* The fallback remains disabled when this option is omitted.
|
|
220
|
+
*/
|
|
221
|
+
extensionFallback?: boolean;
|
|
222
|
+
}>;
|
|
197
223
|
/**
|
|
198
224
|
* Constraints used to validate an incoming collection of browser files.
|
|
199
225
|
* Existing and incoming counts are combined when enforcing capacity.
|
|
@@ -258,6 +284,45 @@ type ZodUploadFileSchemaOptions = Readonly<{
|
|
|
258
284
|
extensionFallback?: boolean;
|
|
259
285
|
}>;
|
|
260
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Defines one shared upload policy while preserving its literal format tuple.
|
|
289
|
+
* The resulting preset can drive schemas, picker hints, and batch validation.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* const imageUploadPreset = defineUploadPreset({
|
|
293
|
+
* formats: [fileFormat.JPG, fileFormat.PNG, fileFormat.WEBP],
|
|
294
|
+
* maxFileSize: 8 * 1024 * 1024,
|
|
295
|
+
* maxFilesCount: 1,
|
|
296
|
+
* });
|
|
297
|
+
*/
|
|
298
|
+
declare function defineUploadPreset<const TFormats extends readonly FileFormat[]>(preset: UploadPreset<TFormats>): UploadPreset<TFormats>;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Default maximum size of one file accepted by the built-in upload presets.
|
|
302
|
+
* The 20 MiB boundary matches the existing upload component policy.
|
|
303
|
+
*/
|
|
304
|
+
declare const DEFAULT_UPLOAD_MAX_FILE_SIZE: number;
|
|
305
|
+
/**
|
|
306
|
+
* Ready-to-use policy for every image format supported by the upload catalog.
|
|
307
|
+
* Each image may occupy up to 20 MiB while collection capacity remains unrestricted.
|
|
308
|
+
*/
|
|
309
|
+
declare const imageUploadPreset: Readonly<{
|
|
310
|
+
formats: readonly ["png", "jpg", "webp", "avif", "heic"];
|
|
311
|
+
maxFileSize: number;
|
|
312
|
+
maxFilesCount?: number;
|
|
313
|
+
extensionFallback?: boolean;
|
|
314
|
+
}>;
|
|
315
|
+
/**
|
|
316
|
+
* Ready-to-use policy for every document format supported by the upload catalog.
|
|
317
|
+
* Each document may occupy up to 20 MiB while collection capacity remains unrestricted.
|
|
318
|
+
*/
|
|
319
|
+
declare const documentUploadPreset: Readonly<{
|
|
320
|
+
formats: readonly ["pdf", "rtf", "txt"];
|
|
321
|
+
maxFileSize: number;
|
|
322
|
+
maxFilesCount?: number;
|
|
323
|
+
extensionFallback?: boolean;
|
|
324
|
+
}>;
|
|
325
|
+
|
|
261
326
|
/**
|
|
262
327
|
* Builds a reusable Zod schema for one uploaded file with format and size.
|
|
263
328
|
* MIME matching is strict unless extension fallback is explicitly enabled.
|
|
@@ -767,4 +832,4 @@ declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>
|
|
|
767
832
|
*/
|
|
768
833
|
declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
769
834
|
|
|
770
|
-
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type FileFormat, type FileFormatConfig, type HonoFileRespondOptions, type HonoRespondOptions, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, type ReplaceDotsWithUnderscores, SUCCESS_STATUS_CODES, type Simplify, type StringEnumRecord, type SuccessStatusCode, type UploadFilesValidationOptions, type UploadFilesValidationResult, type UploadValidationError, type ZodBulkExcludeSelection, type ZodBulkIncludeSelection, type ZodBulkSelection, ZodJWTService, type ZodPaginationOptions, type ZodSearchSchemaOptions, type ZodUploadFileSchemaOptions, asQuery, createStringEnumRecord, createUploadAccept, createZodSearchWhereSchema, failure, fetchAndThrow, fetchSafely, fileFormat, fileFormatsArray, fileFormatsConfig, fileFormatsRecord, fileRespond, formatTime, generateRandomString, getColoredHTTPStatus, getFileExtension, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, isFileExtensionSupported, isFileFormatSupported, isFileMimeTypeSupported, isPlainObject, log, matchesMimeType, measureExecutionTime, normalizeFileExtension, onHandlerError, parseQueryValue, respond, safeExecute, sqlWhere, success, uploadValidationError, uploadValidationErrorsArray, uploadValidationErrorsRecord, validateUploadFile, validateUploadFiles, zodAtLeastOne, zodBulkSelectionSchema, zodPaginationSchema, zodPaginationShape, zodSearchQuerySchema, zodSearchSchema, zodUploadFileSchema };
|
|
835
|
+
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 MeasuredExecution, type Payload, type PayloadSchema, 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, honoLoggingHandler, imageUploadPreset, isFileExtensionSupported, isFileFormatSupported, isFileMimeTypeSupported, isPlainObject, log, matchesMimeType, measureExecutionTime, normalizeFileExtension, onHandlerError, parseQueryValue, respond, safeExecute, sqlWhere, success, uploadValidationError, uploadValidationErrorsArray, uploadValidationErrorsRecord, validateUploadFile, validateUploadFiles, zodAtLeastOne, zodBulkSelectionSchema, zodPaginationSchema, zodPaginationShape, zodSearchQuerySchema, zodSearchSchema, zodUploadFileSchema };
|
package/dist/index.js
CHANGED
|
@@ -208,6 +208,22 @@ var fileFormatsConfig = {
|
|
|
208
208
|
[fileFormatsRecord.TXT]: { name: "TXT", mimeTypes: ["text/plain"], extensions: [".txt"] }
|
|
209
209
|
};
|
|
210
210
|
|
|
211
|
+
// src/upload/upload.factory.ts
|
|
212
|
+
function defineUploadPreset(preset) {
|
|
213
|
+
return preset;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/upload/upload.presets.ts
|
|
217
|
+
var DEFAULT_UPLOAD_MAX_FILE_SIZE = 20 * 1024 * 1024;
|
|
218
|
+
var imageUploadPreset = defineUploadPreset({
|
|
219
|
+
formats: [fileFormat.PNG, fileFormat.JPG, fileFormat.WEBP, fileFormat.AVIF, fileFormat.HEIC],
|
|
220
|
+
maxFileSize: DEFAULT_UPLOAD_MAX_FILE_SIZE
|
|
221
|
+
});
|
|
222
|
+
var documentUploadPreset = defineUploadPreset({
|
|
223
|
+
formats: [fileFormat.PDF, fileFormat.RTF, fileFormat.TXT],
|
|
224
|
+
maxFileSize: DEFAULT_UPLOAD_MAX_FILE_SIZE
|
|
225
|
+
});
|
|
226
|
+
|
|
211
227
|
// src/upload/upload.schemas.ts
|
|
212
228
|
import { z } from "zod";
|
|
213
229
|
|
|
@@ -430,6 +446,7 @@ var parseQueryValue = (value) => {
|
|
|
430
446
|
};
|
|
431
447
|
var asQuery = (schema) => z5.preprocess(parseQueryValue, schema);
|
|
432
448
|
export {
|
|
449
|
+
DEFAULT_UPLOAD_MAX_FILE_SIZE,
|
|
433
450
|
EXCEPTION_STATUS_CODES,
|
|
434
451
|
SUCCESS_STATUS_CODES,
|
|
435
452
|
ZodJWTService,
|
|
@@ -437,6 +454,8 @@ export {
|
|
|
437
454
|
createStringEnumRecord,
|
|
438
455
|
createUploadAccept,
|
|
439
456
|
createZodSearchWhereSchema,
|
|
457
|
+
defineUploadPreset,
|
|
458
|
+
documentUploadPreset,
|
|
440
459
|
failure,
|
|
441
460
|
fetchAndThrow,
|
|
442
461
|
fetchSafely,
|
|
@@ -454,6 +473,7 @@ export {
|
|
|
454
473
|
getUTCOffset,
|
|
455
474
|
getZonedTime,
|
|
456
475
|
honoLoggingHandler,
|
|
476
|
+
imageUploadPreset,
|
|
457
477
|
isFileExtensionSupported,
|
|
458
478
|
isFileFormatSupported,
|
|
459
479
|
isFileMimeTypeSupported,
|