@visulima/storage 1.0.0-alpha.1 → 1.0.0-alpha.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/CHANGELOG.md +30 -0
- package/README.md +33 -14
- package/dist/adapter/nuxt/module.d.ts +39 -0
- package/dist/adapter/nuxt/module.js +93 -0
- package/dist/adapter/nuxt/package.json +20 -0
- package/dist/handler/base/base-handler-core.d.ts +91 -0
- package/dist/handler/base/base-handler-fetch.d.ts +76 -0
- package/dist/handler/base/base-handler-node.d.ts +137 -0
- package/dist/handler/http/fetch/index.d.ts +4 -0
- package/dist/handler/http/fetch/index.js +4 -0
- package/dist/handler/http/hono/index.d.ts +67 -0
- package/dist/handler/http/hono/index.js +65 -0
- package/dist/handler/http/nextjs/index.d.ts +61 -0
- package/dist/handler/http/nextjs/index.js +37 -0
- package/dist/handler/http/node/index.d.ts +4 -0
- package/dist/handler/http/node/index.js +4 -0
- package/dist/handler/http/solid-start/index.d.ts +60 -0
- package/dist/handler/http/solid-start/index.js +44 -0
- package/dist/handler/multipart/multipart-base.d.ts +84 -0
- package/dist/handler/multipart/multipart-fetch.d.ts +64 -0
- package/dist/handler/multipart/multipart.d.ts +49 -0
- package/dist/handler/rest/rest-base.d.ts +106 -0
- package/dist/handler/rest/rest-fetch.d.ts +88 -0
- package/dist/handler/rest/rest.d.ts +93 -0
- package/dist/handler/tus/tus-base.d.ts +152 -0
- package/dist/handler/tus/tus-fetch.d.ts +72 -0
- package/dist/handler/tus/tus.d.ts +78 -0
- package/dist/handler/types.d.ts +53 -0
- package/dist/handler/utils/request-parser.d.ts +72 -0
- package/dist/handler/utils/response-builder.d.ts +83 -0
- package/dist/handler/utils/storage-utils.d.ts +10 -0
- package/dist/handler/utils/stream-utils.d.ts +29 -0
- package/dist/handler/utils/upload-handlers.d.ts +76 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +13 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/no-op-metrics.d.ts +15 -0
- package/dist/metrics/opentelemetry-metrics.d.ts +55 -0
- package/dist/openapi/index.d.ts +5 -0
- package/dist/openapi/index.js +5 -0
- package/dist/openapi/rest.d.ts +7 -0
- package/dist/openapi/shared.d.ts +13 -0
- package/dist/openapi/transform.d.ts +3 -0
- package/dist/openapi/tus.d.ts +7 -0
- package/dist/openapi/xhr.d.ts +7 -0
- package/dist/packem_shared/AwsLightFile-tTneXZgG.js +11 -0
- package/dist/packem_shared/AwsLightMetaStorage-BWSOtVaN.js +4 -0
- package/dist/packem_shared/AwsLightStorage-Blv-GP4v.js +133 -0
- package/dist/packem_shared/AzureFile-CesgFzps.js +8 -0
- package/dist/packem_shared/AzureSMetaStorage-CFs-OYJT.js +88 -0
- package/dist/packem_shared/AzureStorage-B0v048hG.js +357 -0
- package/dist/packem_shared/BaseTransformer-C2gLib6v.js +82 -0
- package/dist/packem_shared/DiskStorage-BlltBst6.js +12 -0
- package/dist/packem_shared/DiskStorageWithChecksum-BJTmMklc.js +238 -0
- package/dist/packem_shared/ERRORS-D0apMqnc.js +97 -0
- package/dist/packem_shared/File-Bb3P23dr.js +69 -0
- package/dist/packem_shared/GCSConfig-vPP22kN6.js +11 -0
- package/dist/packem_shared/GCSFile-BIEunhAN.js +8 -0
- package/dist/packem_shared/GCSMetaStorage-BMFEdzJ7.js +7 -0
- package/dist/packem_shared/GCStorage-DnhiwaS9.js +406 -0
- package/dist/packem_shared/LocalMetaStorage-CZHhKkMd.js +7 -0
- package/dist/packem_shared/MediaTransformer-D6658DL1.js +1197 -0
- package/dist/packem_shared/MetaStorage-pECeFOad.js +46 -0
- package/dist/packem_shared/Metadata-DRLXeJ0F.js +89 -0
- package/dist/packem_shared/Multipart-CNFK_Okz.js +163 -0
- package/dist/packem_shared/Multipart-CtUL7BQw.js +128 -0
- package/dist/packem_shared/NetlifyBlobFile-CXzyjqrD.js +14 -0
- package/dist/packem_shared/NetlifyBlobMetaStorage-DxZ5aDvD.js +9 -0
- package/dist/packem_shared/NetlifyBlobStorage-CLPtjHqd.js +376 -0
- package/dist/packem_shared/NoOpMetrics-DhAk5rXc.js +10 -0
- package/dist/packem_shared/OpenTelemetryMetrics-BnxhqIaH.js +67 -0
- package/dist/packem_shared/Rest-CAOAEkOj.js +267 -0
- package/dist/packem_shared/Rest-DNuLwBrK.js +228 -0
- package/dist/packem_shared/S3File-DZiyk9Qt.js +11 -0
- package/dist/packem_shared/S3MetaStorage-Dz9aDabA.js +76 -0
- package/dist/packem_shared/S3Storage-DHmTk-hU.js +316 -0
- package/dist/packem_shared/TUS_RESUMABLE-GJzZ9R-f.js +434 -0
- package/dist/packem_shared/Tus-B8PmlMgR.js +200 -0
- package/dist/packem_shared/Tus-C4F1aYOl.js +195 -0
- package/dist/packem_shared/ValidationError-BfF1aE4h.js +26 -0
- package/dist/packem_shared/VercelBlobFile-BCg4aTEq.js +18 -0
- package/dist/packem_shared/VercelBlobMetaStorage-Bd9F-VFm.js +9 -0
- package/dist/packem_shared/VercelBlobStorage-DD9LMOS6.js +261 -0
- package/dist/packem_shared/_commonjsHelpers-B85MJLTf.js +5 -0
- package/dist/packem_shared/aws-light-meta-storage-DKJBgbR6.js +446 -0
- package/dist/packem_shared/backblaze-BlMnIcBC.js +20 -0
- package/dist/packem_shared/base-handler-core-BKuf4YLT.js +303 -0
- package/dist/packem_shared/base-handler-fetch-Cr0hLiqg.js +291 -0
- package/dist/packem_shared/base-handler-node-gk5aN9Cx.js +730 -0
- package/dist/packem_shared/cache-B88MXQ_2.js +18 -0
- package/dist/packem_shared/cloudflare-Bi1q8wXE.js +21 -0
- package/dist/packem_shared/defaultCloudStorageFileNameValidation-DUuacjWv.js +11 -0
- package/dist/packem_shared/digitalOcean-CWQRJM3L.js +21 -0
- package/dist/packem_shared/disk-storage-Bh2wy3YW.js +810 -0
- package/dist/packem_shared/gcs-meta-storage-0tgMNnPO.js +158 -0
- package/dist/packem_shared/has-content-CY66ehMK.js +3 -0
- package/dist/packem_shared/headers-DoS5nwM-.js +3220 -0
- package/dist/packem_shared/is-expired-CTThU1q5.js +8 -0
- package/dist/packem_shared/isRetryableError-Dycp7127.js +82 -0
- package/dist/packem_shared/isValidMediaType-BeDgiObq.js +35 -0
- package/dist/packem_shared/local-meta-storage-By-3SNBI.js +649 -0
- package/dist/packem_shared/minio-C2YBZQOw.js +22 -0
- package/dist/packem_shared/multipart-base-B3i67SSX.js +102 -0
- package/dist/packem_shared/part-match-BMNqHDYD.js +96 -0
- package/dist/packem_shared/path-CR6YkPXX-7R1-9CMk.js +161 -0
- package/dist/packem_shared/response-builder-BtnRiBUI.js +45 -0
- package/dist/packem_shared/rest-base-GRCcnan7.js +457 -0
- package/dist/packem_shared/restOpenApiSpec-CwcHHY2C.js +800 -0
- package/dist/packem_shared/s3-base-storage-C1DIHTYY.js +510 -0
- package/dist/packem_shared/sharedGet-Cpo7QUyu.js +1019 -0
- package/dist/packem_shared/storage-C6NSXb8h.js +1175 -0
- package/dist/packem_shared/tigris-Hac8TKnX.js +21 -0
- package/dist/packem_shared/transformOpenApiSpec-DWM5WtnN.js +975 -0
- package/dist/packem_shared/tusOpenApiSpec-6ohiToBy.js +740 -0
- package/dist/packem_shared/update-size-CCGm6i1J.js +8 -0
- package/dist/packem_shared/validator-BeX_lJet.js +78 -0
- package/dist/packem_shared/waitForStorage-Cscw85sx.js +18 -0
- package/dist/packem_shared/wasabi-DIyflHSd.js +21 -0
- package/dist/packem_shared/xhrOpenApiSpec-DS17brnx.js +264 -0
- package/dist/storage/aws/clients/backblaze.d.ts +12 -0
- package/dist/storage/aws/clients/cloudflare.d.ts +13 -0
- package/dist/storage/aws/clients/digital-ocean.d.ts +12 -0
- package/dist/storage/aws/clients/index.d.ts +6 -0
- package/dist/storage/aws/clients/index.js +6 -0
- package/dist/storage/aws/clients/minio.d.ts +13 -0
- package/dist/storage/aws/clients/tigris.d.ts +12 -0
- package/dist/storage/aws/clients/types.d.ts +95 -0
- package/dist/storage/aws/clients/wasabi.d.ts +12 -0
- package/dist/storage/aws/index.d.ts +4 -0
- package/dist/storage/aws/index.js +3 -0
- package/dist/storage/aws/s3-base-storage.d.ts +248 -0
- package/dist/storage/aws/s3-client-adapter.d.ts +110 -0
- package/dist/storage/aws/s3-file.d.ts +10 -0
- package/dist/storage/aws/s3-meta-storage.d.ts +15 -0
- package/dist/storage/aws/s3-storage.d.ts +70 -0
- package/dist/storage/aws/types.d.ts +119 -0
- package/dist/storage/aws-light/aws-light-api-adapter.d.ts +130 -0
- package/dist/storage/aws-light/aws-light-file.d.ts +10 -0
- package/dist/storage/aws-light/aws-light-meta-storage.d.ts +19 -0
- package/dist/storage/aws-light/aws-light-storage.d.ts +65 -0
- package/dist/storage/aws-light/index.d.ts +4 -0
- package/dist/storage/aws-light/index.js +3 -0
- package/dist/storage/aws-light/types.d.ts +37 -0
- package/dist/storage/azure/azure-file.d.ts +6 -0
- package/dist/storage/azure/azure-meta-storage.d.ts +15 -0
- package/dist/storage/azure/azure-storage.d.ts +69 -0
- package/dist/storage/azure/index.d.ts +4 -0
- package/dist/storage/azure/index.js +3 -0
- package/dist/storage/azure/types.d.ts +62 -0
- package/dist/storage/gcs/fetch-error.d.ts +11 -0
- package/dist/storage/gcs/gcs-config.d.ts +2 -0
- package/dist/storage/gcs/gcs-file.d.ts +6 -0
- package/dist/storage/gcs/gcs-meta-storage.d.ts +27 -0
- package/dist/storage/gcs/gcs-storage.d.ts +91 -0
- package/dist/storage/gcs/index.d.ts +5 -0
- package/dist/storage/gcs/index.js +4 -0
- package/dist/storage/gcs/types.d.ts +55 -0
- package/dist/storage/gcs/utils.d.ts +7 -0
- package/dist/storage/local/disk-storage-with-checksum.d.ts +15 -0
- package/dist/storage/local/disk-storage.d.ts +135 -0
- package/dist/storage/local/index.d.ts +4 -0
- package/dist/storage/local/index.js +3 -0
- package/dist/storage/local/local-meta-storage.d.ts +32 -0
- package/dist/storage/meta-storage.d.ts +30 -0
- package/dist/storage/netlify-blob/index.d.ts +4 -0
- package/dist/storage/netlify-blob/index.js +3 -0
- package/dist/storage/netlify-blob/netlify-blob-file.d.ts +12 -0
- package/dist/storage/netlify-blob/netlify-blob-meta-storage.d.ts +7 -0
- package/dist/storage/netlify-blob/netlify-blob-storage.d.ts +93 -0
- package/dist/storage/netlify-blob/types.d.ts +30 -0
- package/dist/storage/storage.d.ts +353 -0
- package/dist/storage/types.d.ts +221 -0
- package/dist/storage/utils/file/file.d.ts +25 -0
- package/dist/storage/utils/file/get-file-status.d.ts +9 -0
- package/dist/storage/utils/file/has-content.d.ts +9 -0
- package/dist/storage/utils/file/index.d.ts +10 -0
- package/dist/storage/utils/file/is-expired.d.ts +8 -0
- package/dist/storage/utils/file/metadata.d.ts +18 -0
- package/dist/storage/utils/file/part-match.d.ts +11 -0
- package/dist/storage/utils/file/types.d.ts +37 -0
- package/dist/storage/utils/file/update-metadata.d.ts +10 -0
- package/dist/storage/utils/file/update-size.d.ts +10 -0
- package/dist/storage/vercel-blob/index.d.ts +4 -0
- package/dist/storage/vercel-blob/index.js +3 -0
- package/dist/storage/vercel-blob/types.d.ts +32 -0
- package/dist/storage/vercel-blob/vercel-blob-file.d.ts +16 -0
- package/dist/storage/vercel-blob/vercel-blob-meta-storage.d.ts +7 -0
- package/dist/storage/vercel-blob/vercel-blob-storage.d.ts +76 -0
- package/dist/transformer/audio-transformer.d.ts +128 -0
- package/dist/transformer/audio-transformer.js +278 -0
- package/dist/transformer/base-transformer.d.ts +63 -0
- package/dist/transformer/image-transformer.d.ts +571 -0
- package/dist/transformer/image-transformer.js +1100 -0
- package/dist/transformer/index.d.ts +5 -0
- package/dist/transformer/index.js +4 -0
- package/dist/transformer/media-transformer.d.ts +332 -0
- package/dist/transformer/types.d.ts +652 -0
- package/dist/transformer/utils.d.ts +33 -0
- package/dist/transformer/validation-error.d.ts +23 -0
- package/dist/transformer/video-transformer.d.ts +145 -0
- package/dist/transformer/video-transformer.js +310 -0
- package/dist/utils/cache.d.ts +32 -0
- package/dist/utils/chunked-upload.d.ts +65 -0
- package/dist/utils/detect-file-type.d.ts +28 -0
- package/dist/utils/errors.d.ts +74 -0
- package/dist/utils/file-path-url-matcher.d.ts +18 -0
- package/dist/utils/headers.d.ts +111 -0
- package/dist/utils/http.d.ts +92 -0
- package/dist/utils/locker.d.ts +26 -0
- package/dist/utils/pipes/stream-checksum.d.ts +47 -0
- package/dist/utils/pipes/stream-length.d.ts +22 -0
- package/dist/utils/primitives/get-last-one.d.ts +3 -0
- package/dist/utils/primitives/is-record.d.ts +2 -0
- package/dist/utils/primitives/map-values.d.ts +9 -0
- package/dist/utils/primitives/pick.d.ts +2 -0
- package/dist/utils/primitives/to-milliseconds.d.ts +12 -0
- package/dist/utils/primitives/to-seconds.d.ts +12 -0
- package/dist/utils/range-checksum.d.ts +33 -0
- package/dist/utils/range-hasher.d.ts +46 -0
- package/dist/utils/retry.d.ts +64 -0
- package/dist/utils/types.d.ts +108 -0
- package/dist/utils/validation-error.d.ts +22 -0
- package/dist/utils/validator.d.ts +36 -0
- package/package.json +5 -5
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const filePathUrlMatcher: (path: string) => {
|
|
2
|
+
params: PathMatch;
|
|
3
|
+
path: string;
|
|
4
|
+
} | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Parsed URL components from file path matching.
|
|
7
|
+
*/
|
|
8
|
+
export type PathMatch = {
|
|
9
|
+
/** File extension (e.g., "jpg", "png") */
|
|
10
|
+
ext?: string;
|
|
11
|
+
/** Metadata request type (e.g., "metadata") */
|
|
12
|
+
metadata?: string;
|
|
13
|
+
/** Path segments before the UUID */
|
|
14
|
+
path?: string[];
|
|
15
|
+
/** File UUID identifier */
|
|
16
|
+
uuid: string;
|
|
17
|
+
};
|
|
18
|
+
export default filePathUrlMatcher;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced HTTP header utilities using remix-run/headers for type-safe header manipulation.
|
|
3
|
+
* This module provides internal utilities for the storage package to handle complex headers.
|
|
4
|
+
*/
|
|
5
|
+
import { Accept, ContentDisposition, ContentType, SuperHeaders } from "@remix-run/headers";
|
|
6
|
+
import type { Headers as UploadHeaders } from "./types.d.ts";
|
|
7
|
+
/**
|
|
8
|
+
* Cache-Control directive options
|
|
9
|
+
*/
|
|
10
|
+
export interface CacheControlOptions {
|
|
11
|
+
immutable?: boolean;
|
|
12
|
+
maxAge?: number;
|
|
13
|
+
minFresh?: number;
|
|
14
|
+
mustRevalidate?: boolean;
|
|
15
|
+
noCache?: boolean;
|
|
16
|
+
noStore?: boolean;
|
|
17
|
+
private?: boolean;
|
|
18
|
+
proxyRevalidate?: boolean;
|
|
19
|
+
public?: boolean;
|
|
20
|
+
sMaxAge?: number;
|
|
21
|
+
staleIfError?: number;
|
|
22
|
+
staleWhileRevalidate?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Utility functions for working with HTTP headers using \@remix-run/headers.
|
|
26
|
+
*/
|
|
27
|
+
export declare const HeaderUtilities: {
|
|
28
|
+
/**
|
|
29
|
+
* Check if client accepts a specific media type based on Accept header.
|
|
30
|
+
* @param acceptHeader HTTP Accept header value
|
|
31
|
+
* @param mediaType Media type to check for acceptance
|
|
32
|
+
* @returns True if the media type is accepted by the client
|
|
33
|
+
*/
|
|
34
|
+
acceptsMediaType(acceptHeader: string | undefined, mediaType: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Create Cache-Control header value from options.
|
|
37
|
+
* @param options Cache control directives configuration
|
|
38
|
+
* @returns Cache-Control header value string
|
|
39
|
+
*/
|
|
40
|
+
createCacheControl(options: CacheControlOptions): string;
|
|
41
|
+
/**
|
|
42
|
+
* Create common cache control presets with predefined configurations.
|
|
43
|
+
* @param preset Preset name ('no-cache', 'no-store', 'public', 'private', or 'immutable')
|
|
44
|
+
* @returns Cache-Control header value string for the preset
|
|
45
|
+
*/
|
|
46
|
+
createCacheControlPreset(preset: "no-cache" | "no-store" | "public" | "private" | "immutable"): string;
|
|
47
|
+
/**
|
|
48
|
+
* Create Content-Disposition header for file downloads with optional filename.
|
|
49
|
+
* @param options
|
|
50
|
+
* @param options.filename Filename for the download
|
|
51
|
+
* @param options.filenameSplat Alternative filename format
|
|
52
|
+
* @param options.type Disposition type ('inline' or 'attachment')
|
|
53
|
+
* @returns Content-Disposition header value string
|
|
54
|
+
*/
|
|
55
|
+
createContentDisposition(options: {
|
|
56
|
+
filename?: string;
|
|
57
|
+
filenameSplat?: string;
|
|
58
|
+
type: "inline" | "attachment";
|
|
59
|
+
}): string;
|
|
60
|
+
/**
|
|
61
|
+
* Create Content-Type header value from structured data with optional charset and boundary.
|
|
62
|
+
* @param options
|
|
63
|
+
* @param options.boundary Multipart boundary string
|
|
64
|
+
* @param options.charset Character encoding (e.g., 'utf8')
|
|
65
|
+
* @param options.mediaType MIME media type (e.g., 'application/json')
|
|
66
|
+
* @returns Content-Type header value string
|
|
67
|
+
*/
|
|
68
|
+
createContentType(options: {
|
|
69
|
+
boundary?: string;
|
|
70
|
+
charset?: string;
|
|
71
|
+
mediaType: string;
|
|
72
|
+
}): string;
|
|
73
|
+
/**
|
|
74
|
+
* Get content type with charset if not already present.
|
|
75
|
+
* @param contentType Content-Type header value to ensure charset for
|
|
76
|
+
* @param defaultCharset Default charset to use if not present (default: 'utf8')
|
|
77
|
+
* @returns Content-Type header value with charset ensured
|
|
78
|
+
*/
|
|
79
|
+
ensureCharset(contentType: string, defaultCharset?: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* Convert our Headers type to EnhancedHeaders from remix-run/headers.
|
|
82
|
+
* @param headers Headers in array or object format
|
|
83
|
+
* @returns SuperHeaders instance with converted header values
|
|
84
|
+
*/
|
|
85
|
+
fromHeaders(headers: UploadHeaders): SuperHeaders;
|
|
86
|
+
/**
|
|
87
|
+
* Get preferred media type from Accept header based on quality factors and supported types.
|
|
88
|
+
* @param acceptHeader HTTP Accept header value
|
|
89
|
+
* @param supportedTypes Array of supported MIME types to match against
|
|
90
|
+
* @returns Best matching media type or undefined if no match found
|
|
91
|
+
*/
|
|
92
|
+
getPreferredMediaType(acceptHeader: string | undefined, supportedTypes: string[]): string | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Parse Accept header with quality factor support.
|
|
95
|
+
* @param headerValue HTTP Accept header value to parse
|
|
96
|
+
* @returns Accept instance or undefined if header is invalid or missing
|
|
97
|
+
*/
|
|
98
|
+
parseAccept(headerValue: string | undefined): Accept | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Parse Content-Disposition header into structured object.
|
|
101
|
+
* @param headerValue HTTP Content-Disposition header value to parse
|
|
102
|
+
* @returns ContentDisposition instance or undefined if header is invalid or missing
|
|
103
|
+
*/
|
|
104
|
+
parseContentDisposition(headerValue: string | undefined): ContentDisposition | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Parse Content-Type header with structured access to media type, charset, and boundary.
|
|
107
|
+
* @param headerValue HTTP Content-Type header value to parse
|
|
108
|
+
* @returns ContentType instance or undefined if header is invalid or missing
|
|
109
|
+
*/
|
|
110
|
+
parseContentType(headerValue: string | undefined): ContentType | undefined;
|
|
111
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { IncomingMessage, OutgoingHttpHeader, ServerResponse } from "node:http";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
import type { Headers, IncomingMessageWithBody } from "./types.d.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Reads the body of an HTTP request as a string with optional size limit.
|
|
6
|
+
* @param request HTTP request object to read body from
|
|
7
|
+
* @param encoding Text encoding to use (defaults to 'utf8')
|
|
8
|
+
* @param limit Maximum body size in characters (throws error if exceeded)
|
|
9
|
+
* @returns Promise resolving to the request body as a string
|
|
10
|
+
*/
|
|
11
|
+
export declare const readBody: (request: IncomingMessage, encoding: BufferEncoding, limit: number | undefined) => Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieve the value of a specific header of an HTTP request.
|
|
14
|
+
* @param request request object
|
|
15
|
+
* @param name name of the header
|
|
16
|
+
* @param all if true, returns all values of the header, comma-separated, otherwise returns the last value.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Get a header value. If `all` is true, returns the comma-joined value.
|
|
20
|
+
*/
|
|
21
|
+
export declare const getHeader: (request: IncomingMessage, name: string, all?: boolean) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Extracts JSON metadata from an HTTP request body.
|
|
24
|
+
* Parses the request body as JSON if the content type is 'application/json'.
|
|
25
|
+
* @param request HTTP request with potential body data
|
|
26
|
+
* @param limit Maximum body size limit in bytes (default: 16MB)
|
|
27
|
+
* @returns Parsed metadata object, or empty object if not JSON
|
|
28
|
+
*/
|
|
29
|
+
export declare const getMetadata: (request: IncomingMessageWithBody<Record<string, unknown>>, limit?: number) => Promise<Record<string, unknown>>;
|
|
30
|
+
/**
|
|
31
|
+
* Appends value to the end of the multi-value header
|
|
32
|
+
*/
|
|
33
|
+
/** Append a value to a multi-valued response header. */
|
|
34
|
+
export declare const appendHeader: (response: ServerResponse, name: string, value: OutgoingHttpHeader) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the value of a specific header of an HTTP response.
|
|
37
|
+
*/
|
|
38
|
+
/** Set multiple response headers and expose them for CORS. */
|
|
39
|
+
export declare const setHeaders: (response: ServerResponse, headers?: Headers) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Extracts host with port from a HTTP or HTTPS request.
|
|
42
|
+
* Prefers x-forwarded-host header for proxy compatibility.
|
|
43
|
+
* @param request HTTP request object
|
|
44
|
+
* @returns Host string with port (e.g., "example.com:8080")
|
|
45
|
+
*/
|
|
46
|
+
export declare const extractHost: (request: IncomingMessage & {
|
|
47
|
+
host?: string;
|
|
48
|
+
hostname?: string;
|
|
49
|
+
}) => string;
|
|
50
|
+
/**
|
|
51
|
+
* Extracts protocol from a HTTP or HTTPS request.
|
|
52
|
+
* Prefers x-forwarded-proto header for proxy compatibility.
|
|
53
|
+
* @param request HTTP request object
|
|
54
|
+
* @returns Protocol string ('http' or 'https')
|
|
55
|
+
*/
|
|
56
|
+
export declare const extractProto: (request: IncomingMessage) => string;
|
|
57
|
+
/**
|
|
58
|
+
* Try build a protocol:hostname:port string from a request object.
|
|
59
|
+
*/
|
|
60
|
+
/** Build protocol://host from an IncomingMessage using forwarded headers. */
|
|
61
|
+
export declare const getBaseUrl: (request: IncomingMessage) => string;
|
|
62
|
+
/**
|
|
63
|
+
* Extracts the real path from a request URL, excluding query parameters.
|
|
64
|
+
* Prefers originalUrl for Express compatibility.
|
|
65
|
+
* @internal
|
|
66
|
+
* @param request HTTP request object
|
|
67
|
+
* @returns The path component of the URL without query parameters
|
|
68
|
+
* @throws TypeError if path is undefined
|
|
69
|
+
*/
|
|
70
|
+
export declare const getRealPath: (request: IncomingMessage & {
|
|
71
|
+
originalUrl?: string;
|
|
72
|
+
}) => string;
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
export declare const uuidRegex: RegExp;
|
|
77
|
+
/**
|
|
78
|
+
* Extracts a UUID identifier from the request URL path.
|
|
79
|
+
* Uses regex pattern to match UUID-like strings in the URL.
|
|
80
|
+
* @internal
|
|
81
|
+
* @param request HTTP request object
|
|
82
|
+
* @returns The extracted UUID identifier
|
|
83
|
+
* @throws TypeError if no valid ID is found in the path
|
|
84
|
+
*/
|
|
85
|
+
export declare const getIdFromRequest: (request: IncomingMessage & {
|
|
86
|
+
originalUrl?: string;
|
|
87
|
+
}) => string;
|
|
88
|
+
/**
|
|
89
|
+
* Converts a request to a Node.js Readable stream.
|
|
90
|
+
* Handles both Node.js IncomingMessage and Web API Request objects.
|
|
91
|
+
*/
|
|
92
|
+
export declare const getRequestStream: (request: IncomingMessage | Request) => Readable;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LRUCache as Cache } from "lru-cache";
|
|
2
|
+
/**
|
|
3
|
+
* A simple lock map keyed by strings, backed by LRUCache. Locks
|
|
4
|
+
* automatically expire according to the configured TTL preventing deadlocks.
|
|
5
|
+
*/
|
|
6
|
+
declare class Locker<K extends string = string, V extends string = string> extends Cache<K, V, number> {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new Locker instance with configurable TTL and cache options.
|
|
9
|
+
* @param options LRU cache configuration options
|
|
10
|
+
*/
|
|
11
|
+
constructor(options?: Cache.Options<K, V, number>);
|
|
12
|
+
/**
|
|
13
|
+
* Acquires a lock for the specified key.
|
|
14
|
+
* Throws an error if the key is already locked.
|
|
15
|
+
* @param key The key to lock
|
|
16
|
+
* @returns The lock token (same as the key)
|
|
17
|
+
* @throws Error if the key is already locked
|
|
18
|
+
*/
|
|
19
|
+
lock(key: K): string;
|
|
20
|
+
/**
|
|
21
|
+
* Releases the lock for the specified key.
|
|
22
|
+
* @param key The key to unlock
|
|
23
|
+
*/
|
|
24
|
+
unlock(key: K): void;
|
|
25
|
+
}
|
|
26
|
+
export default Locker;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { BinaryToTextEncoding } from "node:crypto";
|
|
2
|
+
import { PassThrough, Transform } from "node:stream";
|
|
3
|
+
/**
|
|
4
|
+
* Transform stream that validates checksums as data passes through.
|
|
5
|
+
* Calculates hash of streaming data and validates against expected checksum.
|
|
6
|
+
*/
|
|
7
|
+
export declare class StreamChecksum extends Transform {
|
|
8
|
+
readonly checksum: string;
|
|
9
|
+
readonly algorithm: string;
|
|
10
|
+
private readonly encoding;
|
|
11
|
+
length: number;
|
|
12
|
+
private digest;
|
|
13
|
+
private hash;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the calculated digest value after the stream has finished processing.
|
|
16
|
+
* @returns The digest value in the configured encoding, or empty string if not yet calculated
|
|
17
|
+
*/
|
|
18
|
+
get calculatedDigest(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new StreamChecksum transform stream.
|
|
21
|
+
* @param checksum Expected checksum value to validate against
|
|
22
|
+
* @param algorithm Hash algorithm to use (e.g., 'md5', 'sha256')
|
|
23
|
+
* @param encoding Encoding for the checksum comparison (defaults to 'base64')
|
|
24
|
+
*/
|
|
25
|
+
constructor(checksum: string, algorithm: string, encoding?: BinaryToTextEncoding);
|
|
26
|
+
/**
|
|
27
|
+
* Transform method that updates the hash with incoming data.
|
|
28
|
+
* @param chunk Buffer chunk to process
|
|
29
|
+
* @param _encoding Unused encoding parameter
|
|
30
|
+
* @param done Callback to signal completion
|
|
31
|
+
*/
|
|
32
|
+
_transform(chunk: Buffer, _encoding: string, done: () => void): void;
|
|
33
|
+
/**
|
|
34
|
+
* Finalization method that validates the checksum.
|
|
35
|
+
* @param callback Callback called with error if checksum validation fails
|
|
36
|
+
*/
|
|
37
|
+
_flush(callback: (error?: Error) => void): void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Factory function that returns either a StreamChecksum transform or a PassThrough stream.
|
|
41
|
+
* Returns PassThrough when no algorithm is provided.
|
|
42
|
+
* @param checksum Expected checksum value
|
|
43
|
+
* @param algorithm Hash algorithm (if empty, returns PassThrough)
|
|
44
|
+
* @param encoding Encoding for checksum comparison
|
|
45
|
+
* @returns StreamChecksum instance or PassThrough stream
|
|
46
|
+
*/
|
|
47
|
+
export declare const streamChecksum: (checksum: string, algorithm: string, encoding?: BinaryToTextEncoding) => PassThrough | StreamChecksum;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Transform } from "node:stream";
|
|
2
|
+
/**
|
|
3
|
+
* Transform stream that tracks byte length and enforces size limits.
|
|
4
|
+
* Counts total bytes passing through and optionally enforces a maximum limit.
|
|
5
|
+
*/
|
|
6
|
+
declare class StreamLength extends Transform {
|
|
7
|
+
readonly limit: number;
|
|
8
|
+
length: number;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new StreamLength transform stream.
|
|
11
|
+
* @param limit Maximum number of bytes allowed (defaults to infinity)
|
|
12
|
+
*/
|
|
13
|
+
constructor(limit?: number);
|
|
14
|
+
/**
|
|
15
|
+
* Transform method that counts bytes and enforces size limits.
|
|
16
|
+
* @param chunk Buffer chunk to process
|
|
17
|
+
* @param _encoding Unused encoding parameter
|
|
18
|
+
* @param callback Callback called with error if limit exceeded
|
|
19
|
+
*/
|
|
20
|
+
_transform(chunk: Buffer, _encoding: string, callback: (error?: Error) => void): void;
|
|
21
|
+
}
|
|
22
|
+
export default StreamLength;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps object values using a transformation function.
|
|
3
|
+
* @param object The source object to map values from
|
|
4
|
+
* @param function_ The function to transform each value
|
|
5
|
+
* @returns A new object with transformed values
|
|
6
|
+
* @template T - The type of the transformed values
|
|
7
|
+
*/
|
|
8
|
+
declare const mapValues: <T>(object: Record<string, unknown>, function_: (value: unknown) => T) => Record<string, T>;
|
|
9
|
+
export default mapValues;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a human-readable duration string to milliseconds.
|
|
3
|
+
* @param value Duration value (number in ms or human-readable string)
|
|
4
|
+
* @returns Duration in milliseconds, or undefined if parsing fails
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* toMilliseconds("5m") // 300000
|
|
8
|
+
* toMilliseconds(5000) // 5000
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
declare const toMilliseconds: (value: number | string | undefined) => number | undefined;
|
|
12
|
+
export default toMilliseconds;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a human-readable duration string to seconds.
|
|
3
|
+
* @param value Duration value (number in seconds or human-readable string)
|
|
4
|
+
* @returns Duration in seconds
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* toSeconds("5m") // 300
|
|
8
|
+
* toSeconds(300) // 300
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
declare const toSeconds: (value: number | string) => number;
|
|
12
|
+
export default toSeconds;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BinaryToTextEncoding, Hash } from "node:crypto";
|
|
2
|
+
import { Transform } from "node:stream";
|
|
3
|
+
import type { RangeChecksum as IRangeChecksum, RangeHasher as IRangeHasher } from "./types.d.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Transform stream that calculates checksums for specific file ranges.
|
|
6
|
+
* Used for validating partial file integrity during resumable uploads.
|
|
7
|
+
*/
|
|
8
|
+
declare class RangeChecksum extends Transform implements IRangeChecksum {
|
|
9
|
+
readonly path: string;
|
|
10
|
+
hash: Hash;
|
|
11
|
+
private readonly hashCopy;
|
|
12
|
+
private hashes;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new RangeChecksum transform stream.
|
|
15
|
+
* @param hashes Range hasher instance managing multiple file hashes
|
|
16
|
+
* @param path File path identifier for this checksum operation
|
|
17
|
+
*/
|
|
18
|
+
constructor(hashes: IRangeHasher, path: string);
|
|
19
|
+
/**
|
|
20
|
+
* Resets the hash state to its initial value.
|
|
21
|
+
* Useful for reusing the checksum calculator for multiple operations.
|
|
22
|
+
*/
|
|
23
|
+
reset(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the current hash digest in the specified encoding.
|
|
26
|
+
* @param encoding Output encoding format (default: 'hex')
|
|
27
|
+
* @returns Hash digest as a string
|
|
28
|
+
*/
|
|
29
|
+
digest(encoding?: BinaryToTextEncoding): string;
|
|
30
|
+
_transform(chunk: Buffer, _encoding: string, done: () => void): void;
|
|
31
|
+
_flush(callback: (error?: Error) => void): void;
|
|
32
|
+
}
|
|
33
|
+
export default RangeChecksum;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Hash } from "node:crypto";
|
|
2
|
+
import { LRUCache as Cache } from "lru-cache";
|
|
3
|
+
import type { RangeChecksum as IRangeChecksum } from "./types.d.ts";
|
|
4
|
+
/**
|
|
5
|
+
* LRU cache-based range hasher for incremental file integrity verification.
|
|
6
|
+
* Manages multiple file hash calculations with automatic cleanup and persistence.
|
|
7
|
+
*/
|
|
8
|
+
declare class RangeHasher extends Cache<string, Hash, number> {
|
|
9
|
+
algorithm: "md5" | "sha1";
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new RangeHasher instance.
|
|
12
|
+
* @param algorithm Hash algorithm to use (default: 'sha1')
|
|
13
|
+
* @param options LRU cache configuration options
|
|
14
|
+
*/
|
|
15
|
+
constructor(algorithm?: "md5" | "sha1", options?: Cache.Options<string, Hash, number>);
|
|
16
|
+
/**
|
|
17
|
+
* Returns the hex-encoded digest for a previously initialized path.
|
|
18
|
+
* @param path File path identifier
|
|
19
|
+
* @returns Hex-encoded hash digest, or empty string if not found
|
|
20
|
+
*/
|
|
21
|
+
hex(path: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the base64-encoded digest for a previously initialized path.
|
|
24
|
+
* @param path File path identifier
|
|
25
|
+
* @returns Base64-encoded hash digest, or empty string if not found
|
|
26
|
+
*/
|
|
27
|
+
base64(path: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Initializes or continues a hasher for a file from the specified offset.
|
|
30
|
+
* Returns cached hash if available, otherwise calculates from filesystem.
|
|
31
|
+
* @param path File path to hash
|
|
32
|
+
* @param start Starting offset in bytes (default: 0)
|
|
33
|
+
* @returns Promise resolving to the hash instance
|
|
34
|
+
*/
|
|
35
|
+
init(path: string, start?: number): Promise<Hash>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a transform stream that updates the rolling hash for a file path.
|
|
38
|
+
* Useful for incremental hashing during streaming operations.
|
|
39
|
+
* @param path File path identifier for hash tracking
|
|
40
|
+
* @returns RangeChecksum transform stream instance
|
|
41
|
+
*/
|
|
42
|
+
digester(path: string): IRangeChecksum;
|
|
43
|
+
updateFromFs(path: string, start?: number, initial?: Hash): Promise<Hash>;
|
|
44
|
+
private fromFs;
|
|
45
|
+
}
|
|
46
|
+
export default RangeHasher;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry configuration options for storage operations
|
|
3
|
+
*/
|
|
4
|
+
export interface RetryConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Multiplier for exponential backoff (e.g., 2 means delays double each retry)
|
|
7
|
+
* @default 2
|
|
8
|
+
*/
|
|
9
|
+
backoffMultiplier?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Custom function to calculate delay for a specific retry attempt
|
|
12
|
+
* @param attempt The current retry attempt (0-indexed)
|
|
13
|
+
* @param error The error that occurred
|
|
14
|
+
* @returns Delay in milliseconds, or undefined to use default exponential backoff
|
|
15
|
+
*/
|
|
16
|
+
calculateDelay?: (attempt: number, error: unknown) => number | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Initial delay in milliseconds before first retry
|
|
19
|
+
* @default 1000
|
|
20
|
+
*/
|
|
21
|
+
initialDelay?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Maximum delay in milliseconds between retries
|
|
24
|
+
* @default 30000
|
|
25
|
+
*/
|
|
26
|
+
maxDelay?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum number of retry attempts
|
|
29
|
+
* @default 3
|
|
30
|
+
*/
|
|
31
|
+
maxRetries?: number;
|
|
32
|
+
/**
|
|
33
|
+
* HTTP status codes that should trigger a retry
|
|
34
|
+
* @default [408, 429, 500, 502, 503, 504]
|
|
35
|
+
*/
|
|
36
|
+
retryableStatusCodes?: number[];
|
|
37
|
+
/**
|
|
38
|
+
* Custom function to determine if an error should be retried
|
|
39
|
+
* @param error The error that occurred
|
|
40
|
+
* @returns true if the error should be retried, false otherwise
|
|
41
|
+
*/
|
|
42
|
+
shouldRetry?: (error: unknown) => boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Determines if an error is retryable based on common patterns
|
|
46
|
+
* @param error The error to check
|
|
47
|
+
* @param retryableStatusCodes HTTP status codes that should trigger retry
|
|
48
|
+
* @returns true if the error is retryable
|
|
49
|
+
*/
|
|
50
|
+
export declare const isRetryableError: (error: unknown, retryableStatusCodes?: number[]) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Retry an async operation with exponential backoff
|
|
53
|
+
* @param fn The async function to retry
|
|
54
|
+
* @param config Retry configuration
|
|
55
|
+
* @returns The result of the function
|
|
56
|
+
* @throws The last error if all retries are exhausted
|
|
57
|
+
*/
|
|
58
|
+
export declare const retry: <T>(function_: () => Promise<T>, config?: RetryConfig) => Promise<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Create a retry wrapper function with pre-configured settings.
|
|
61
|
+
* @param config Retry configuration
|
|
62
|
+
* @returns A function that wraps async operations with retry logic
|
|
63
|
+
*/
|
|
64
|
+
export declare const createRetryWrapper: (config?: RetryConfig) => <T>(function_: () => Promise<T>) => Promise<T>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { BinaryToTextEncoding, Hash } from "node:crypto";
|
|
2
|
+
import type { IncomingMessage } from "node:http";
|
|
3
|
+
import type { Transform } from "node:stream";
|
|
4
|
+
import type { LRUCache as Cache } from "lru-cache";
|
|
5
|
+
/**
|
|
6
|
+
* Transform that computes a rolling checksum for a stream while passing
|
|
7
|
+
* data through unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export interface RangeChecksum extends Transform {
|
|
10
|
+
/** Return the current digest in the selected encoding. */
|
|
11
|
+
digest: (encoding: BinaryToTextEncoding) => string;
|
|
12
|
+
hash: Hash;
|
|
13
|
+
path: string;
|
|
14
|
+
reset: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* LRU-backed map of rolling hashers keyed by file path. Used to compute
|
|
18
|
+
* hex/base64 digests and resume hashing from an offset.
|
|
19
|
+
*/
|
|
20
|
+
export interface RangeHasher extends Cache<string, Hash> {
|
|
21
|
+
algorithm: "md5" | "sha1";
|
|
22
|
+
base64: (path: string) => string;
|
|
23
|
+
digester: (path: string) => RangeChecksum;
|
|
24
|
+
hex: (path: string) => string;
|
|
25
|
+
init: (path: string, start: number) => Promise<Hash>;
|
|
26
|
+
updateFromFs: (path: string, start: number, initial?: Hash) => Promise<Hash>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Normalized HTTP error payload returned by handlers and storage backends.
|
|
30
|
+
*/
|
|
31
|
+
export interface HttpErrorBody {
|
|
32
|
+
code: string;
|
|
33
|
+
detail?: Record<string, unknown> | string;
|
|
34
|
+
message: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
retryable?: boolean;
|
|
37
|
+
UploadErrorCode?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Rich HTTP error including status code and optional headers/body.
|
|
41
|
+
*/
|
|
42
|
+
export interface HttpError<T = HttpErrorBody> extends UploadResponse<T> {
|
|
43
|
+
statusCode: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Node.js IncomingMessage with an optional parsed body attached.
|
|
47
|
+
*/
|
|
48
|
+
export interface IncomingMessageWithBody<T = unknown> extends IncomingMessage {
|
|
49
|
+
_body?: boolean;
|
|
50
|
+
body?: T;
|
|
51
|
+
}
|
|
52
|
+
export type Header = string[] | number | string;
|
|
53
|
+
export type Headers = Record<string, Header>;
|
|
54
|
+
export type ResponseBody = Record<string, unknown> | string | Buffer | Uint8Array;
|
|
55
|
+
export type ResponseBodyType = "json" | "text";
|
|
56
|
+
/**
|
|
57
|
+
* Tuple form for quick response definitions: [status, body, headers].
|
|
58
|
+
*/
|
|
59
|
+
export type ResponseTuple<T = ResponseBody> = [statusCode: number, body?: T, headers?: Headers];
|
|
60
|
+
/**
|
|
61
|
+
* Structured response used across handlers and storage operations.
|
|
62
|
+
*/
|
|
63
|
+
export interface UploadResponse<T = ResponseBody> extends Record<string, unknown> {
|
|
64
|
+
body?: T;
|
|
65
|
+
headers?: Headers;
|
|
66
|
+
statusCode?: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Declarative validator configuration for a single rule.
|
|
70
|
+
*/
|
|
71
|
+
export interface ValidatorConfig<T> {
|
|
72
|
+
isValid?: (t: T) => Promise<boolean> | boolean;
|
|
73
|
+
response?: HttpError<HttpErrorBody> | ResponseTuple<ResponseBody>;
|
|
74
|
+
value?: unknown;
|
|
75
|
+
}
|
|
76
|
+
/** Map of rule-name -> validator configuration. */
|
|
77
|
+
export type Validation<T> = Record<string, ValidatorConfig<T>>;
|
|
78
|
+
/** Narrowed error response shape for validation failures. */
|
|
79
|
+
export interface ValidationError extends HttpError {
|
|
80
|
+
code: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Metrics interface for observability.
|
|
84
|
+
* Provides counters, timers, and gauges for tracking storage operations.
|
|
85
|
+
*/
|
|
86
|
+
export interface Metrics {
|
|
87
|
+
/**
|
|
88
|
+
* Set a gauge metric value.
|
|
89
|
+
* @param name Metric name (e.g., "storage.files.size")
|
|
90
|
+
* @param value Gauge value
|
|
91
|
+
* @param attributes Optional attributes/labels
|
|
92
|
+
*/
|
|
93
|
+
gauge: (name: string, value: number, attributes?: Record<string, string | number>) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Increment a counter metric.
|
|
96
|
+
* @param name Metric name (e.g., "storage.operations.create.count")
|
|
97
|
+
* @param value Increment value (default: 1)
|
|
98
|
+
* @param attributes Optional attributes/labels (e.g., { storage: "s3", operation: "create" })
|
|
99
|
+
*/
|
|
100
|
+
increment: (name: string, value?: number, attributes?: Record<string, string | number>) => void;
|
|
101
|
+
/**
|
|
102
|
+
* Record a duration/timing metric in milliseconds.
|
|
103
|
+
* @param name Metric name (e.g., "storage.operations.write.duration")
|
|
104
|
+
* @param duration Duration in milliseconds
|
|
105
|
+
* @param attributes Optional attributes/labels
|
|
106
|
+
*/
|
|
107
|
+
timing: (name: string, duration: number, attributes?: Record<string, string | number>) => void;
|
|
108
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Headers, HttpErrorBody, ValidationError as IValidationError } from "./types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Error class for validation failures with detailed error information.
|
|
4
|
+
* Implements the ValidationError interface for consistent error handling.
|
|
5
|
+
*/
|
|
6
|
+
declare class ValidationError extends Error implements IValidationError {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly statusCode: number;
|
|
9
|
+
readonly body: HttpErrorBody;
|
|
10
|
+
readonly headers: Headers;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new ValidationError instance.
|
|
15
|
+
* @param code Machine-readable error code
|
|
16
|
+
* @param statusCode HTTP status code for the error
|
|
17
|
+
* @param body Error response body (string or structured object)
|
|
18
|
+
* @param headers HTTP headers to include in error response
|
|
19
|
+
*/
|
|
20
|
+
constructor(code: string, statusCode: number, body: HttpErrorBody, headers: Headers);
|
|
21
|
+
}
|
|
22
|
+
export default ValidationError;
|