@vritti/api-sdk 0.3.14 → 0.3.15

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/files.cjs ADDED
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/files/index.ts
22
+ var files_exports = {};
23
+ __export(files_exports, {
24
+ MultipartDto: () => MultipartDto,
25
+ UploadedFile: () => UploadedFile,
26
+ UploadedFiles: () => UploadedFiles,
27
+ readMultipart: () => readMultipart
28
+ });
29
+ module.exports = __toCommonJS(files_exports);
30
+
31
+ // src/files/uploaded-file.decorator.ts
32
+ var import_common20 = require("@nestjs/common");
33
+ var import_class_transformer = require("class-transformer");
34
+ var import_class_validator = require("class-validator");
35
+
36
+ // src/exceptions/bad-gateway.exception.ts
37
+ var import_common2 = require("@nestjs/common");
38
+
39
+ // src/exceptions/base-field.exception.ts
40
+ var import_common = require("@nestjs/common");
41
+ var HttpProblemException = class extends import_common.HttpException {
42
+ static {
43
+ __name(this, "HttpProblemException");
44
+ }
45
+ constructor(detailOrOptions, httpStatus) {
46
+ const options = typeof detailOrOptions === "string" ? {
47
+ detail: detailOrOptions
48
+ } : detailOrOptions;
49
+ super({
50
+ type: options.type ?? "about:blank",
51
+ label: options.label,
52
+ detail: options.detail,
53
+ errors: options.errors ?? []
54
+ }, httpStatus);
55
+ }
56
+ };
57
+
58
+ // src/exceptions/bad-request.exception.ts
59
+ var import_common3 = require("@nestjs/common");
60
+ var BadRequestException = class extends HttpProblemException {
61
+ static {
62
+ __name(this, "BadRequestException");
63
+ }
64
+ constructor(detailOrOptions) {
65
+ super(detailOrOptions ?? "Bad Request", import_common3.HttpStatus.BAD_REQUEST);
66
+ }
67
+ };
68
+
69
+ // src/exceptions/conflict.exception.ts
70
+ var import_common4 = require("@nestjs/common");
71
+
72
+ // src/exceptions/forbidden.exception.ts
73
+ var import_common5 = require("@nestjs/common");
74
+
75
+ // src/exceptions/gone.exception.ts
76
+ var import_common6 = require("@nestjs/common");
77
+
78
+ // src/exceptions/internal-server-error.exception.ts
79
+ var import_common7 = require("@nestjs/common");
80
+
81
+ // src/exceptions/method-not-allowed.exception.ts
82
+ var import_common8 = require("@nestjs/common");
83
+
84
+ // src/exceptions/not-acceptable.exception.ts
85
+ var import_common9 = require("@nestjs/common");
86
+
87
+ // src/exceptions/not-found.exception.ts
88
+ var import_common10 = require("@nestjs/common");
89
+
90
+ // src/exceptions/not-implemented.exception.ts
91
+ var import_common11 = require("@nestjs/common");
92
+
93
+ // src/exceptions/payload-too-large.exception.ts
94
+ var import_common12 = require("@nestjs/common");
95
+
96
+ // src/exceptions/request-timeout.exception.ts
97
+ var import_common13 = require("@nestjs/common");
98
+
99
+ // src/exceptions/service-unavailable.exception.ts
100
+ var import_common14 = require("@nestjs/common");
101
+
102
+ // src/exceptions/too-many-requests.exception.ts
103
+ var import_common15 = require("@nestjs/common");
104
+
105
+ // src/exceptions/unauthorized.exception.ts
106
+ var import_common16 = require("@nestjs/common");
107
+
108
+ // src/exceptions/unprocessable-entity.exception.ts
109
+ var import_common17 = require("@nestjs/common");
110
+
111
+ // src/exceptions/unsupported-media-type.exception.ts
112
+ var import_common18 = require("@nestjs/common");
113
+
114
+ // src/exceptions/validation.exception.ts
115
+ var import_common19 = require("@nestjs/common");
116
+
117
+ // src/files/uploaded-file.decorator.ts
118
+ var PARSED = Symbol("vritti.multipart");
119
+ function readMultipart(request) {
120
+ const cached = request;
121
+ cached[PARSED] ??= (async () => {
122
+ const content = {
123
+ fields: {},
124
+ files: {}
125
+ };
126
+ for await (const part of request.parts()) {
127
+ if (part.type === "file") {
128
+ const file = {
129
+ buffer: await part.toBuffer(),
130
+ filename: part.filename,
131
+ mimetype: part.mimetype
132
+ };
133
+ const existing = content.files[part.fieldname];
134
+ if (existing) existing.push(file);
135
+ else content.files[part.fieldname] = [
136
+ file
137
+ ];
138
+ } else {
139
+ content.fields[part.fieldname] = part.value;
140
+ }
141
+ }
142
+ return content;
143
+ })();
144
+ return cached[PARSED];
145
+ }
146
+ __name(readMultipart, "readMultipart");
147
+ function flatten(files) {
148
+ return Object.values(files).flat();
149
+ }
150
+ __name(flatten, "flatten");
151
+ var UploadedFile = (0, import_common20.createParamDecorator)(async (fieldName, ctx) => {
152
+ const { files } = await readMultipart(ctx.switchToHttp().getRequest());
153
+ const file = (fieldName ? files[fieldName] : flatten(files))?.[0];
154
+ if (!file) {
155
+ const field = fieldName ?? "file";
156
+ throw new BadRequestException({
157
+ label: "File Required",
158
+ detail: `Please attach a file${fieldName ? ` under "${fieldName}"` : ""} to your request.`,
159
+ errors: [
160
+ {
161
+ field,
162
+ message: "File required"
163
+ }
164
+ ]
165
+ });
166
+ }
167
+ return file;
168
+ });
169
+ var UploadedFiles = (0, import_common20.createParamDecorator)(async (fieldName, ctx) => {
170
+ const { files } = await readMultipart(ctx.switchToHttp().getRequest());
171
+ if (!fieldName) return files;
172
+ const matched = files[fieldName] ?? [];
173
+ if (matched.length === 0) {
174
+ throw new BadRequestException({
175
+ label: "Files Required",
176
+ detail: `Please attach at least one file under "${fieldName}" to your request.`,
177
+ errors: [
178
+ {
179
+ field: fieldName,
180
+ message: "At least one file is required"
181
+ }
182
+ ]
183
+ });
184
+ }
185
+ return matched;
186
+ });
187
+ var MultipartDto = (0, import_common20.createParamDecorator)(async (dtoClass, ctx) => {
188
+ const { fields } = await readMultipart(ctx.switchToHttp().getRequest());
189
+ const dto = (0, import_class_transformer.plainToInstance)(dtoClass, fields);
190
+ const errors = await (0, import_class_validator.validate)(dto);
191
+ if (errors.length > 0) {
192
+ throw new BadRequestException({
193
+ label: "Validation Failed",
194
+ detail: "One or more fields are invalid.",
195
+ errors: errors.map((e) => ({
196
+ field: e.property,
197
+ message: Object.values(e.constraints ?? {})[0] ?? "Invalid value"
198
+ }))
199
+ });
200
+ }
201
+ return dto;
202
+ });
203
+ // Annotate the CommonJS export names for ESM import in node:
204
+ 0 && (module.exports = {
205
+ MultipartDto,
206
+ UploadedFile,
207
+ UploadedFiles,
208
+ readMultipart
209
+ });
210
+ //# sourceMappingURL=files.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/files/index.ts","../src/files/uploaded-file.decorator.ts","../src/exceptions/bad-gateway.exception.ts","../src/exceptions/base-field.exception.ts","../src/exceptions/bad-request.exception.ts","../src/exceptions/conflict.exception.ts","../src/exceptions/forbidden.exception.ts","../src/exceptions/gone.exception.ts","../src/exceptions/internal-server-error.exception.ts","../src/exceptions/method-not-allowed.exception.ts","../src/exceptions/not-acceptable.exception.ts","../src/exceptions/not-found.exception.ts","../src/exceptions/not-implemented.exception.ts","../src/exceptions/payload-too-large.exception.ts","../src/exceptions/request-timeout.exception.ts","../src/exceptions/service-unavailable.exception.ts","../src/exceptions/too-many-requests.exception.ts","../src/exceptions/unauthorized.exception.ts","../src/exceptions/unprocessable-entity.exception.ts","../src/exceptions/unsupported-media-type.exception.ts","../src/exceptions/validation.exception.ts"],"sourcesContent":["export {\n type MultipartContent,\n MultipartDto,\n readMultipart,\n UploadedFile,\n type UploadedFileMap,\n type UploadedFileResult,\n UploadedFiles,\n} from './uploaded-file.decorator';\n","import type {} from '@fastify/multipart';\nimport { createParamDecorator, type ExecutionContext } from '@nestjs/common';\nimport { type ClassConstructor, plainToInstance } from 'class-transformer';\nimport { validate } from 'class-validator';\nimport type { FastifyRequest } from 'fastify';\nimport { BadRequestException } from '../exceptions';\n\nexport interface UploadedFileResult {\n buffer: Buffer;\n filename: string;\n mimetype: string;\n}\n\nexport type UploadedFileMap = Record<string, UploadedFileResult[]>;\n\nexport interface MultipartContent {\n fields: Record<string, unknown>;\n files: UploadedFileMap;\n}\n\nconst PARSED = Symbol('vritti.multipart');\n\ntype ParsedRequest = FastifyRequest & { [PARSED]?: Promise<MultipartContent> };\n\n// Reads the whole multipart body once and caches it — the part stream cannot be walked twice\nexport function readMultipart(request: FastifyRequest): Promise<MultipartContent> {\n const cached = request as ParsedRequest;\n cached[PARSED] ??= (async () => {\n const content: MultipartContent = { fields: {}, files: {} };\n for await (const part of request.parts()) {\n if (part.type === 'file') {\n const file = { buffer: await part.toBuffer(), filename: part.filename, mimetype: part.mimetype };\n const existing = content.files[part.fieldname];\n if (existing) existing.push(file);\n else content.files[part.fieldname] = [file];\n } else {\n content.fields[part.fieldname] = part.value;\n }\n }\n return content;\n })();\n return cached[PARSED];\n}\n\nfunction flatten(files: Record<string, UploadedFileResult[]>): UploadedFileResult[] {\n return Object.values(files).flat();\n}\n\n// The single file sent under `fieldName`, or the only file on the request; throws when absent\nexport const UploadedFile = createParamDecorator(\n async (fieldName: string | undefined, ctx: ExecutionContext): Promise<UploadedFileResult> => {\n const { files } = await readMultipart(ctx.switchToHttp().getRequest<FastifyRequest>());\n const file = (fieldName ? files[fieldName] : flatten(files))?.[0];\n\n if (!file) {\n const field = fieldName ?? 'file';\n throw new BadRequestException({\n label: 'File Required',\n detail: `Please attach a file${fieldName ? ` under \"${fieldName}\"` : ''} to your request.`,\n errors: [{ field, message: 'File required' }],\n });\n }\n return file;\n },\n);\n\n// Every file under `fieldName` (throws when none), or with no name every file keyed by field name (never throws)\nexport const UploadedFiles = createParamDecorator(\n async (\n fieldName: string | undefined,\n ctx: ExecutionContext,\n ): Promise<UploadedFileResult[] | Record<string, UploadedFileResult[]>> => {\n const { files } = await readMultipart(ctx.switchToHttp().getRequest<FastifyRequest>());\n if (!fieldName) return files;\n\n const matched = files[fieldName] ?? [];\n if (matched.length === 0) {\n throw new BadRequestException({\n label: 'Files Required',\n detail: `Please attach at least one file under \"${fieldName}\" to your request.`,\n errors: [{ field: fieldName, message: 'At least one file is required' }],\n });\n }\n return matched;\n },\n);\n\n// The request's text fields validated into `dto`, for a multipart form whose body cannot reach @Body() —\n// fastify only surfaces fields while walking the parts, so request.body is empty without attachFieldsToBody.\nexport const MultipartDto = createParamDecorator(\n async <T extends object>(dtoClass: ClassConstructor<T>, ctx: ExecutionContext): Promise<T> => {\n const { fields } = await readMultipart(ctx.switchToHttp().getRequest<FastifyRequest>());\n const dto = plainToInstance(dtoClass, fields);\n const errors = await validate(dto as object);\n\n if (errors.length > 0) {\n throw new BadRequestException({\n label: 'Validation Failed',\n detail: 'One or more fields are invalid.',\n errors: errors.map((e) => ({\n field: e.property,\n message: Object.values(e.constraints ?? {})[0] ?? 'Invalid value',\n })),\n });\n }\n return dto;\n },\n);\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class BadGatewayException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Bad Gateway', HttpStatus.BAD_GATEWAY);\n }\n}\n","import { HttpException, HttpStatus } from '@nestjs/common';\nimport type { FieldError } from '../types/error-response.types';\n\n// Re-export FieldError for backwards compatibility\nexport type { FieldError } from '../types/error-response.types';\n\nexport interface ProblemOptions {\n type?: string;\n label?: string;\n detail?: string;\n errors?: FieldError[];\n}\n\nexport abstract class HttpProblemException extends HttpException {\n constructor(detailOrOptions: string | ProblemOptions, httpStatus: HttpStatus) {\n const options = typeof detailOrOptions === 'string' ? { detail: detailOrOptions } : detailOrOptions;\n\n super(\n {\n type: options.type ?? 'about:blank',\n label: options.label,\n detail: options.detail,\n errors: options.errors ?? [],\n },\n httpStatus,\n );\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class BadRequestException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Bad Request', HttpStatus.BAD_REQUEST);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ConflictException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Conflict', HttpStatus.CONFLICT);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ForbiddenException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Forbidden', HttpStatus.FORBIDDEN);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class GoneException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Gone', HttpStatus.GONE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class InternalServerErrorException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Internal Server Error', HttpStatus.INTERNAL_SERVER_ERROR);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class MethodNotAllowedException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Method Not Allowed', HttpStatus.METHOD_NOT_ALLOWED);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class NotAcceptableException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Not Acceptable', HttpStatus.NOT_ACCEPTABLE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class NotFoundException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Not Found', HttpStatus.NOT_FOUND);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class NotImplementedException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Not Implemented', HttpStatus.NOT_IMPLEMENTED);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class PayloadTooLargeException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Payload Too Large', HttpStatus.PAYLOAD_TOO_LARGE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class RequestTimeoutException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Request Timeout', HttpStatus.REQUEST_TIMEOUT);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ServiceUnavailableException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Service Unavailable', HttpStatus.SERVICE_UNAVAILABLE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class TooManyRequestsException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Too Many Requests', HttpStatus.TOO_MANY_REQUESTS);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class UnauthorizedException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Unauthorized', HttpStatus.UNAUTHORIZED);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class UnprocessableEntityException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Unprocessable Entity', HttpStatus.UNPROCESSABLE_ENTITY);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class UnsupportedMediaTypeException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Unsupported Media Type', HttpStatus.UNSUPPORTED_MEDIA_TYPE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ValidationException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Validation Failed', HttpStatus.UNPROCESSABLE_ENTITY);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACCA,IAAAA,kBAA4D;AAC5D,+BAAuD;AACvD,6BAAyB;;;ACHzB,IAAAC,iBAA2B;;;ACA3B,oBAA0C;AAanC,IAAeC,uBAAf,cAA4CC,4BAAAA;EAbnD,OAamDA;;;EACjD,YAAYC,iBAA0CC,YAAwB;AAC5E,UAAMC,UAAU,OAAOF,oBAAoB,WAAW;MAAEG,QAAQH;IAAgB,IAAIA;AAEpF,UACE;MACEI,MAAMF,QAAQE,QAAQ;MACtBC,OAAOH,QAAQG;MACfF,QAAQD,QAAQC;MAChBG,QAAQJ,QAAQI,UAAU,CAAA;IAC5B,GACAL,UAAAA;EAEJ;AACF;;;AC3BA,IAAAM,iBAA2B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C,QAAQA,OAAOU,IAAI,CAACC,OAAO;QACzBf,OAAOe,EAAEC;QACTX,SAASd,OAAOC,OAAOuB,EAAEE,eAAe,CAAC,CAAA,EAAG,CAAA,KAAM;MACpD,EAAA;IACF,CAAA;EACF;AACA,SAAON;AACT,CAAA;","names":["import_common","import_common","HttpProblemException","HttpException","detailOrOptions","httpStatus","options","detail","type","label","errors","import_common","BadRequestException","HttpProblemException","detailOrOptions","HttpStatus","BAD_REQUEST","import_common","import_common","import_common","import_common","import_common","import_common","import_common","import_common","import_common","import_common","import_common","import_common","import_common","import_common","import_common","import_common","PARSED","Symbol","readMultipart","request","cached","content","fields","files","part","parts","type","file","buffer","toBuffer","filename","mimetype","existing","fieldname","push","value","flatten","Object","values","flat","UploadedFile","createParamDecorator","fieldName","ctx","switchToHttp","getRequest","field","BadRequestException","label","detail","errors","message","UploadedFiles","matched","length","MultipartDto","dtoClass","dto","plainToInstance","validate","map","e","property","constraints"]}
@@ -0,0 +1,20 @@
1
+ import * as _nestjs_common from '@nestjs/common';
2
+ import { ClassConstructor } from 'class-transformer';
3
+ import { FastifyRequest } from 'fastify';
4
+
5
+ interface UploadedFileResult {
6
+ buffer: Buffer;
7
+ filename: string;
8
+ mimetype: string;
9
+ }
10
+ type UploadedFileMap = Record<string, UploadedFileResult[]>;
11
+ interface MultipartContent {
12
+ fields: Record<string, unknown>;
13
+ files: UploadedFileMap;
14
+ }
15
+ declare function readMultipart(request: FastifyRequest): Promise<MultipartContent>;
16
+ declare const UploadedFile: (...dataOrPipes: (string | _nestjs_common.PipeTransform<any, any> | _nestjs_common.Type<_nestjs_common.PipeTransform<any, any>> | undefined)[]) => ParameterDecorator;
17
+ declare const UploadedFiles: (...dataOrPipes: (string | _nestjs_common.PipeTransform<any, any> | _nestjs_common.Type<_nestjs_common.PipeTransform<any, any>> | undefined)[]) => ParameterDecorator;
18
+ declare const MultipartDto: <T extends object>(...dataOrPipes: (ClassConstructor<T> | _nestjs_common.PipeTransform<any, any> | _nestjs_common.Type<_nestjs_common.PipeTransform<any, any>>)[]) => ParameterDecorator;
19
+
20
+ export { type MultipartContent, MultipartDto, UploadedFile, type UploadedFileMap, type UploadedFileResult, UploadedFiles, readMultipart };
@@ -0,0 +1,20 @@
1
+ import * as _nestjs_common from '@nestjs/common';
2
+ import { ClassConstructor } from 'class-transformer';
3
+ import { FastifyRequest } from 'fastify';
4
+
5
+ interface UploadedFileResult {
6
+ buffer: Buffer;
7
+ filename: string;
8
+ mimetype: string;
9
+ }
10
+ type UploadedFileMap = Record<string, UploadedFileResult[]>;
11
+ interface MultipartContent {
12
+ fields: Record<string, unknown>;
13
+ files: UploadedFileMap;
14
+ }
15
+ declare function readMultipart(request: FastifyRequest): Promise<MultipartContent>;
16
+ declare const UploadedFile: (...dataOrPipes: (string | _nestjs_common.PipeTransform<any, any> | _nestjs_common.Type<_nestjs_common.PipeTransform<any, any>> | undefined)[]) => ParameterDecorator;
17
+ declare const UploadedFiles: (...dataOrPipes: (string | _nestjs_common.PipeTransform<any, any> | _nestjs_common.Type<_nestjs_common.PipeTransform<any, any>> | undefined)[]) => ParameterDecorator;
18
+ declare const MultipartDto: <T extends object>(...dataOrPipes: (ClassConstructor<T> | _nestjs_common.PipeTransform<any, any> | _nestjs_common.Type<_nestjs_common.PipeTransform<any, any>>)[]) => ParameterDecorator;
19
+
20
+ export { type MultipartContent, MultipartDto, UploadedFile, type UploadedFileMap, type UploadedFileResult, UploadedFiles, readMultipart };
package/dist/files.js ADDED
@@ -0,0 +1,182 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/files/uploaded-file.decorator.ts
5
+ import { createParamDecorator } from "@nestjs/common";
6
+ import { plainToInstance } from "class-transformer";
7
+ import { validate } from "class-validator";
8
+
9
+ // src/exceptions/bad-gateway.exception.ts
10
+ import { HttpStatus } from "@nestjs/common";
11
+
12
+ // src/exceptions/base-field.exception.ts
13
+ import { HttpException } from "@nestjs/common";
14
+ var HttpProblemException = class extends HttpException {
15
+ static {
16
+ __name(this, "HttpProblemException");
17
+ }
18
+ constructor(detailOrOptions, httpStatus) {
19
+ const options = typeof detailOrOptions === "string" ? {
20
+ detail: detailOrOptions
21
+ } : detailOrOptions;
22
+ super({
23
+ type: options.type ?? "about:blank",
24
+ label: options.label,
25
+ detail: options.detail,
26
+ errors: options.errors ?? []
27
+ }, httpStatus);
28
+ }
29
+ };
30
+
31
+ // src/exceptions/bad-request.exception.ts
32
+ import { HttpStatus as HttpStatus2 } from "@nestjs/common";
33
+ var BadRequestException = class extends HttpProblemException {
34
+ static {
35
+ __name(this, "BadRequestException");
36
+ }
37
+ constructor(detailOrOptions) {
38
+ super(detailOrOptions ?? "Bad Request", HttpStatus2.BAD_REQUEST);
39
+ }
40
+ };
41
+
42
+ // src/exceptions/conflict.exception.ts
43
+ import { HttpStatus as HttpStatus3 } from "@nestjs/common";
44
+
45
+ // src/exceptions/forbidden.exception.ts
46
+ import { HttpStatus as HttpStatus4 } from "@nestjs/common";
47
+
48
+ // src/exceptions/gone.exception.ts
49
+ import { HttpStatus as HttpStatus5 } from "@nestjs/common";
50
+
51
+ // src/exceptions/internal-server-error.exception.ts
52
+ import { HttpStatus as HttpStatus6 } from "@nestjs/common";
53
+
54
+ // src/exceptions/method-not-allowed.exception.ts
55
+ import { HttpStatus as HttpStatus7 } from "@nestjs/common";
56
+
57
+ // src/exceptions/not-acceptable.exception.ts
58
+ import { HttpStatus as HttpStatus8 } from "@nestjs/common";
59
+
60
+ // src/exceptions/not-found.exception.ts
61
+ import { HttpStatus as HttpStatus9 } from "@nestjs/common";
62
+
63
+ // src/exceptions/not-implemented.exception.ts
64
+ import { HttpStatus as HttpStatus10 } from "@nestjs/common";
65
+
66
+ // src/exceptions/payload-too-large.exception.ts
67
+ import { HttpStatus as HttpStatus11 } from "@nestjs/common";
68
+
69
+ // src/exceptions/request-timeout.exception.ts
70
+ import { HttpStatus as HttpStatus12 } from "@nestjs/common";
71
+
72
+ // src/exceptions/service-unavailable.exception.ts
73
+ import { HttpStatus as HttpStatus13 } from "@nestjs/common";
74
+
75
+ // src/exceptions/too-many-requests.exception.ts
76
+ import { HttpStatus as HttpStatus14 } from "@nestjs/common";
77
+
78
+ // src/exceptions/unauthorized.exception.ts
79
+ import { HttpStatus as HttpStatus15 } from "@nestjs/common";
80
+
81
+ // src/exceptions/unprocessable-entity.exception.ts
82
+ import { HttpStatus as HttpStatus16 } from "@nestjs/common";
83
+
84
+ // src/exceptions/unsupported-media-type.exception.ts
85
+ import { HttpStatus as HttpStatus17 } from "@nestjs/common";
86
+
87
+ // src/exceptions/validation.exception.ts
88
+ import { HttpStatus as HttpStatus18 } from "@nestjs/common";
89
+
90
+ // src/files/uploaded-file.decorator.ts
91
+ var PARSED = Symbol("vritti.multipart");
92
+ function readMultipart(request) {
93
+ const cached = request;
94
+ cached[PARSED] ??= (async () => {
95
+ const content = {
96
+ fields: {},
97
+ files: {}
98
+ };
99
+ for await (const part of request.parts()) {
100
+ if (part.type === "file") {
101
+ const file = {
102
+ buffer: await part.toBuffer(),
103
+ filename: part.filename,
104
+ mimetype: part.mimetype
105
+ };
106
+ const existing = content.files[part.fieldname];
107
+ if (existing) existing.push(file);
108
+ else content.files[part.fieldname] = [
109
+ file
110
+ ];
111
+ } else {
112
+ content.fields[part.fieldname] = part.value;
113
+ }
114
+ }
115
+ return content;
116
+ })();
117
+ return cached[PARSED];
118
+ }
119
+ __name(readMultipart, "readMultipart");
120
+ function flatten(files) {
121
+ return Object.values(files).flat();
122
+ }
123
+ __name(flatten, "flatten");
124
+ var UploadedFile = createParamDecorator(async (fieldName, ctx) => {
125
+ const { files } = await readMultipart(ctx.switchToHttp().getRequest());
126
+ const file = (fieldName ? files[fieldName] : flatten(files))?.[0];
127
+ if (!file) {
128
+ const field = fieldName ?? "file";
129
+ throw new BadRequestException({
130
+ label: "File Required",
131
+ detail: `Please attach a file${fieldName ? ` under "${fieldName}"` : ""} to your request.`,
132
+ errors: [
133
+ {
134
+ field,
135
+ message: "File required"
136
+ }
137
+ ]
138
+ });
139
+ }
140
+ return file;
141
+ });
142
+ var UploadedFiles = createParamDecorator(async (fieldName, ctx) => {
143
+ const { files } = await readMultipart(ctx.switchToHttp().getRequest());
144
+ if (!fieldName) return files;
145
+ const matched = files[fieldName] ?? [];
146
+ if (matched.length === 0) {
147
+ throw new BadRequestException({
148
+ label: "Files Required",
149
+ detail: `Please attach at least one file under "${fieldName}" to your request.`,
150
+ errors: [
151
+ {
152
+ field: fieldName,
153
+ message: "At least one file is required"
154
+ }
155
+ ]
156
+ });
157
+ }
158
+ return matched;
159
+ });
160
+ var MultipartDto = createParamDecorator(async (dtoClass, ctx) => {
161
+ const { fields } = await readMultipart(ctx.switchToHttp().getRequest());
162
+ const dto = plainToInstance(dtoClass, fields);
163
+ const errors = await validate(dto);
164
+ if (errors.length > 0) {
165
+ throw new BadRequestException({
166
+ label: "Validation Failed",
167
+ detail: "One or more fields are invalid.",
168
+ errors: errors.map((e) => ({
169
+ field: e.property,
170
+ message: Object.values(e.constraints ?? {})[0] ?? "Invalid value"
171
+ }))
172
+ });
173
+ }
174
+ return dto;
175
+ });
176
+ export {
177
+ MultipartDto,
178
+ UploadedFile,
179
+ UploadedFiles,
180
+ readMultipart
181
+ };
182
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/files/uploaded-file.decorator.ts","../src/exceptions/bad-gateway.exception.ts","../src/exceptions/base-field.exception.ts","../src/exceptions/bad-request.exception.ts","../src/exceptions/conflict.exception.ts","../src/exceptions/forbidden.exception.ts","../src/exceptions/gone.exception.ts","../src/exceptions/internal-server-error.exception.ts","../src/exceptions/method-not-allowed.exception.ts","../src/exceptions/not-acceptable.exception.ts","../src/exceptions/not-found.exception.ts","../src/exceptions/not-implemented.exception.ts","../src/exceptions/payload-too-large.exception.ts","../src/exceptions/request-timeout.exception.ts","../src/exceptions/service-unavailable.exception.ts","../src/exceptions/too-many-requests.exception.ts","../src/exceptions/unauthorized.exception.ts","../src/exceptions/unprocessable-entity.exception.ts","../src/exceptions/unsupported-media-type.exception.ts","../src/exceptions/validation.exception.ts"],"sourcesContent":["import type {} from '@fastify/multipart';\nimport { createParamDecorator, type ExecutionContext } from '@nestjs/common';\nimport { type ClassConstructor, plainToInstance } from 'class-transformer';\nimport { validate } from 'class-validator';\nimport type { FastifyRequest } from 'fastify';\nimport { BadRequestException } from '../exceptions';\n\nexport interface UploadedFileResult {\n buffer: Buffer;\n filename: string;\n mimetype: string;\n}\n\nexport type UploadedFileMap = Record<string, UploadedFileResult[]>;\n\nexport interface MultipartContent {\n fields: Record<string, unknown>;\n files: UploadedFileMap;\n}\n\nconst PARSED = Symbol('vritti.multipart');\n\ntype ParsedRequest = FastifyRequest & { [PARSED]?: Promise<MultipartContent> };\n\n// Reads the whole multipart body once and caches it — the part stream cannot be walked twice\nexport function readMultipart(request: FastifyRequest): Promise<MultipartContent> {\n const cached = request as ParsedRequest;\n cached[PARSED] ??= (async () => {\n const content: MultipartContent = { fields: {}, files: {} };\n for await (const part of request.parts()) {\n if (part.type === 'file') {\n const file = { buffer: await part.toBuffer(), filename: part.filename, mimetype: part.mimetype };\n const existing = content.files[part.fieldname];\n if (existing) existing.push(file);\n else content.files[part.fieldname] = [file];\n } else {\n content.fields[part.fieldname] = part.value;\n }\n }\n return content;\n })();\n return cached[PARSED];\n}\n\nfunction flatten(files: Record<string, UploadedFileResult[]>): UploadedFileResult[] {\n return Object.values(files).flat();\n}\n\n// The single file sent under `fieldName`, or the only file on the request; throws when absent\nexport const UploadedFile = createParamDecorator(\n async (fieldName: string | undefined, ctx: ExecutionContext): Promise<UploadedFileResult> => {\n const { files } = await readMultipart(ctx.switchToHttp().getRequest<FastifyRequest>());\n const file = (fieldName ? files[fieldName] : flatten(files))?.[0];\n\n if (!file) {\n const field = fieldName ?? 'file';\n throw new BadRequestException({\n label: 'File Required',\n detail: `Please attach a file${fieldName ? ` under \"${fieldName}\"` : ''} to your request.`,\n errors: [{ field, message: 'File required' }],\n });\n }\n return file;\n },\n);\n\n// Every file under `fieldName` (throws when none), or with no name every file keyed by field name (never throws)\nexport const UploadedFiles = createParamDecorator(\n async (\n fieldName: string | undefined,\n ctx: ExecutionContext,\n ): Promise<UploadedFileResult[] | Record<string, UploadedFileResult[]>> => {\n const { files } = await readMultipart(ctx.switchToHttp().getRequest<FastifyRequest>());\n if (!fieldName) return files;\n\n const matched = files[fieldName] ?? [];\n if (matched.length === 0) {\n throw new BadRequestException({\n label: 'Files Required',\n detail: `Please attach at least one file under \"${fieldName}\" to your request.`,\n errors: [{ field: fieldName, message: 'At least one file is required' }],\n });\n }\n return matched;\n },\n);\n\n// The request's text fields validated into `dto`, for a multipart form whose body cannot reach @Body() —\n// fastify only surfaces fields while walking the parts, so request.body is empty without attachFieldsToBody.\nexport const MultipartDto = createParamDecorator(\n async <T extends object>(dtoClass: ClassConstructor<T>, ctx: ExecutionContext): Promise<T> => {\n const { fields } = await readMultipart(ctx.switchToHttp().getRequest<FastifyRequest>());\n const dto = plainToInstance(dtoClass, fields);\n const errors = await validate(dto as object);\n\n if (errors.length > 0) {\n throw new BadRequestException({\n label: 'Validation Failed',\n detail: 'One or more fields are invalid.',\n errors: errors.map((e) => ({\n field: e.property,\n message: Object.values(e.constraints ?? {})[0] ?? 'Invalid value',\n })),\n });\n }\n return dto;\n },\n);\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class BadGatewayException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Bad Gateway', HttpStatus.BAD_GATEWAY);\n }\n}\n","import { HttpException, HttpStatus } from '@nestjs/common';\nimport type { FieldError } from '../types/error-response.types';\n\n// Re-export FieldError for backwards compatibility\nexport type { FieldError } from '../types/error-response.types';\n\nexport interface ProblemOptions {\n type?: string;\n label?: string;\n detail?: string;\n errors?: FieldError[];\n}\n\nexport abstract class HttpProblemException extends HttpException {\n constructor(detailOrOptions: string | ProblemOptions, httpStatus: HttpStatus) {\n const options = typeof detailOrOptions === 'string' ? { detail: detailOrOptions } : detailOrOptions;\n\n super(\n {\n type: options.type ?? 'about:blank',\n label: options.label,\n detail: options.detail,\n errors: options.errors ?? [],\n },\n httpStatus,\n );\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class BadRequestException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Bad Request', HttpStatus.BAD_REQUEST);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ConflictException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Conflict', HttpStatus.CONFLICT);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ForbiddenException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Forbidden', HttpStatus.FORBIDDEN);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class GoneException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Gone', HttpStatus.GONE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class InternalServerErrorException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Internal Server Error', HttpStatus.INTERNAL_SERVER_ERROR);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class MethodNotAllowedException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Method Not Allowed', HttpStatus.METHOD_NOT_ALLOWED);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class NotAcceptableException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Not Acceptable', HttpStatus.NOT_ACCEPTABLE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class NotFoundException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Not Found', HttpStatus.NOT_FOUND);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class NotImplementedException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Not Implemented', HttpStatus.NOT_IMPLEMENTED);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class PayloadTooLargeException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Payload Too Large', HttpStatus.PAYLOAD_TOO_LARGE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class RequestTimeoutException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Request Timeout', HttpStatus.REQUEST_TIMEOUT);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ServiceUnavailableException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Service Unavailable', HttpStatus.SERVICE_UNAVAILABLE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class TooManyRequestsException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Too Many Requests', HttpStatus.TOO_MANY_REQUESTS);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class UnauthorizedException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Unauthorized', HttpStatus.UNAUTHORIZED);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class UnprocessableEntityException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Unprocessable Entity', HttpStatus.UNPROCESSABLE_ENTITY);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class UnsupportedMediaTypeException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Unsupported Media Type', HttpStatus.UNSUPPORTED_MEDIA_TYPE);\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ValidationException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Validation Failed', HttpStatus.UNPROCESSABLE_ENTITY);\n }\n}\n"],"mappings":";;;;AACA,SAASA,4BAAmD;AAC5D,SAAgCC,uBAAuB;AACvD,SAASC,gBAAgB;;;ACHzB,SAASC,kBAAkB;;;ACA3B,SAASC,qBAAiC;AAanC,IAAeC,uBAAf,cAA4CC,cAAAA;EAbnD,OAamDA;;;EACjD,YAAYC,iBAA0CC,YAAwB;AAC5E,UAAMC,UAAU,OAAOF,oBAAoB,WAAW;MAAEG,QAAQH;IAAgB,IAAIA;AAEpF,UACE;MACEI,MAAMF,QAAQE,QAAQ;MACtBC,OAAOH,QAAQG;MACfF,QAAQD,QA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C,WAAU,CAAA;AACpE,QAAMY,MAAMC,gBAAgBF,UAAUlC,MAAAA;AACtC,QAAM4B,SAAS,MAAMS,SAASF,GAAAA;AAE9B,MAAIP,OAAOI,SAAS,GAAG;AACrB,UAAM,IAAIP,oBAAoB;MAC5BC,OAAO;MACPC,QAAQ;MACRC,QAAQA,OAAOU,IAAI,CAACC,OAAO;QACzBf,OAAOe,EAAEC;QACTX,SAASd,OAAOC,OAAOuB,EAAEE,eAAe,CAAC,CAAA,EAAG,CAAA,KAAM;MACpD,EAAA;IACF,CAAA;EACF;AACA,SAAON;AACT,CAAA;","names":["createParamDecorator","plainToInstance","validate","HttpStatus","HttpException","HttpProblemException","HttpException","detailOrOptions","httpStatus","options","detail","type","label","errors","HttpStatus","BadRequestException","HttpProblemException","detailOrOptions","HttpStatus","BAD_REQUEST","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","HttpStatus","PARSED","Symbol","readMultipart","request","cached","content","fields","files","part","parts","type","file","buffer","toBuffer","filename","mimetype","existing","fieldname","push","value","flatten","Object","values","flat","UploadedFile","createParamDecorator","fieldName","ctx","switchToHttp","getRequest","field","BadRequestException","label","detail","errors","message","UploadedFiles","matched","length","MultipartDto","dtoClass","dto","plainToInstance","validate","map","e","property","constraints"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vritti/api-sdk",
3
3
  "type": "module",
4
- "version": "0.3.14",
4
+ "version": "0.3.15",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -236,6 +236,16 @@
236
236
  "default": "./dist/decorators.cjs"
237
237
  }
238
238
  },
239
+ "./files": {
240
+ "import": {
241
+ "types": "./dist/files.d.ts",
242
+ "default": "./dist/files.js"
243
+ },
244
+ "require": {
245
+ "types": "./dist/files.d.cts",
246
+ "default": "./dist/files.cjs"
247
+ }
248
+ },
239
249
  "./filters": {
240
250
  "import": {
241
251
  "types": "./dist/filters.d.ts",