@h3ravel/http 11.5.0 → 11.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +35 -32
- package/dist/index.d.cts +17 -20
- package/dist/index.d.ts +17 -20
- package/dist/index.js +35 -32
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -18997,7 +18997,7 @@ var FormRequest = class {
|
|
|
18997
18997
|
};
|
|
18998
18998
|
for (const [rawKey, value] of data.entries()) {
|
|
18999
18999
|
const key = rawKey.endsWith("[]") ? rawKey.slice(0, -2) : rawKey;
|
|
19000
|
-
if (value instanceof File) {
|
|
19000
|
+
if (value instanceof UploadedFile || value instanceof File) {
|
|
19001
19001
|
const uploaded = value instanceof UploadedFile ? value : UploadedFile.createFromBase(value);
|
|
19002
19002
|
if (this.dataset.files[key]) {
|
|
19003
19003
|
const existing = this.dataset.files[key];
|
|
@@ -19088,6 +19088,10 @@ var Request = class Request {
|
|
|
19088
19088
|
*/
|
|
19089
19089
|
#json;
|
|
19090
19090
|
#uri;
|
|
19091
|
+
/**
|
|
19092
|
+
* Uploaded files (FILES).
|
|
19093
|
+
*/
|
|
19094
|
+
#files;
|
|
19091
19095
|
#method = void 0;
|
|
19092
19096
|
/**
|
|
19093
19097
|
* Gets route parameters.
|
|
@@ -19114,10 +19118,6 @@ var Request = class Request {
|
|
|
19114
19118
|
*/
|
|
19115
19119
|
query;
|
|
19116
19120
|
/**
|
|
19117
|
-
* Uploaded files (FILES).
|
|
19118
|
-
*/
|
|
19119
|
-
files;
|
|
19120
|
-
/**
|
|
19121
19121
|
* Server and execution environment parameters
|
|
19122
19122
|
*/
|
|
19123
19123
|
server;
|
|
@@ -19172,7 +19172,7 @@ var Request = class Request {
|
|
|
19172
19172
|
this.query = new InputBag((0, h3.getQuery)(this.event), this.event);
|
|
19173
19173
|
this.attributes = new ParamBag((0, h3.getRouterParams)(this.event), this.event);
|
|
19174
19174
|
this.cookies = new InputBag((0, h3.parseCookies)(this.event), this.event);
|
|
19175
|
-
this
|
|
19175
|
+
this.#files = new FileBag(this.formData ? this.formData.files() : {}, this.event);
|
|
19176
19176
|
this.server = new ServerBag(Object.fromEntries(this.event.req.headers.entries()), this.event);
|
|
19177
19177
|
this.headers = new HeaderBag(this.server.getHeaders());
|
|
19178
19178
|
this.acceptableContentTypes = [];
|
|
@@ -19238,18 +19238,41 @@ var Request = class Request {
|
|
|
19238
19238
|
*
|
|
19239
19239
|
* @param key
|
|
19240
19240
|
* @param defaultValue
|
|
19241
|
+
* @param expectArray
|
|
19241
19242
|
* @returns
|
|
19242
19243
|
*/
|
|
19243
|
-
file(key, defaultValue) {
|
|
19244
|
-
const
|
|
19245
|
-
|
|
19244
|
+
file(key, defaultValue, expectArray) {
|
|
19245
|
+
const files = (0, __h3ravel_support.data_get)(this.allFiles(), key, defaultValue);
|
|
19246
|
+
if (!files) return defaultValue;
|
|
19247
|
+
if (Array.isArray(files)) return expectArray ? files : files[0];
|
|
19248
|
+
return files;
|
|
19246
19249
|
}
|
|
19247
19250
|
/**
|
|
19248
|
-
*
|
|
19251
|
+
* Determine if the uploaded data contains a file.
|
|
19252
|
+
*
|
|
19253
|
+
* @param key
|
|
19254
|
+
* @return boolean
|
|
19255
|
+
*/
|
|
19256
|
+
hasFile(key) {
|
|
19257
|
+
let files = this.file(key, void 0, true);
|
|
19258
|
+
if (!Array.isArray(files)) files = [files];
|
|
19259
|
+
return files.some((e) => this.isValidFile(e));
|
|
19260
|
+
}
|
|
19261
|
+
/**
|
|
19262
|
+
* Check that the given file is a valid file instance.
|
|
19263
|
+
*
|
|
19264
|
+
* @param file
|
|
19265
|
+
* @return boolean
|
|
19266
|
+
*/
|
|
19267
|
+
isValidFile(file) {
|
|
19268
|
+
return file.content instanceof File && file.size > 0;
|
|
19269
|
+
}
|
|
19270
|
+
/**
|
|
19271
|
+
* Get an object with all the files on the request.
|
|
19249
19272
|
*/
|
|
19250
19273
|
allFiles() {
|
|
19251
19274
|
if (this.convertedFiles) return this.convertedFiles;
|
|
19252
|
-
const entries = Object.entries(this
|
|
19275
|
+
const entries = Object.entries(this.#files.all()).filter((e) => e[1] != null);
|
|
19253
19276
|
const files = Object.fromEntries(entries);
|
|
19254
19277
|
this.convertedFiles = this.convertUploadedFiles(files);
|
|
19255
19278
|
return this.convertedFiles;
|
|
@@ -19328,7 +19351,7 @@ var Request = class Request {
|
|
|
19328
19351
|
* Get the keys for all of the input and files.
|
|
19329
19352
|
*/
|
|
19330
19353
|
keys() {
|
|
19331
|
-
return [...Object.keys(this.input()), ...this
|
|
19354
|
+
return [...Object.keys(this.input()), ...this.#files.keys()];
|
|
19332
19355
|
}
|
|
19333
19356
|
/**
|
|
19334
19357
|
* Determine if the request is sending JSON.
|
|
@@ -19591,26 +19614,6 @@ var Request = class Request {
|
|
|
19591
19614
|
return content;
|
|
19592
19615
|
}
|
|
19593
19616
|
/**
|
|
19594
|
-
* Determine if the uploaded data contains a file.
|
|
19595
|
-
*
|
|
19596
|
-
* @param key
|
|
19597
|
-
* @return boolean
|
|
19598
|
-
*/
|
|
19599
|
-
hasFile(key) {
|
|
19600
|
-
let files = this.file(key);
|
|
19601
|
-
if (!Array.isArray(files)) files = [files];
|
|
19602
|
-
return files.some((e) => this.isValidFile(e));
|
|
19603
|
-
}
|
|
19604
|
-
/**
|
|
19605
|
-
* Check that the given file is a valid file instance.
|
|
19606
|
-
*
|
|
19607
|
-
* @param file
|
|
19608
|
-
* @return boolean
|
|
19609
|
-
*/
|
|
19610
|
-
isValidFile(file) {
|
|
19611
|
-
return file.content instanceof File && file.size > 0;
|
|
19612
|
-
}
|
|
19613
|
-
/**
|
|
19614
19617
|
* Gets a "parameter" value from any bag.
|
|
19615
19618
|
*
|
|
19616
19619
|
* This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
|
package/dist/index.d.cts
CHANGED
|
@@ -585,10 +585,6 @@ declare class Request implements IRequest {
|
|
|
585
585
|
* Query string parameters (GET).
|
|
586
586
|
*/
|
|
587
587
|
query: InputBag;
|
|
588
|
-
/**
|
|
589
|
-
* Uploaded files (FILES).
|
|
590
|
-
*/
|
|
591
|
-
files: FileBag;
|
|
592
588
|
/**
|
|
593
589
|
* Server and execution environment parameters
|
|
594
590
|
*/
|
|
@@ -664,11 +660,26 @@ declare class Request implements IRequest {
|
|
|
664
660
|
*
|
|
665
661
|
* @param key
|
|
666
662
|
* @param defaultValue
|
|
663
|
+
* @param expectArray
|
|
667
664
|
* @returns
|
|
668
665
|
*/
|
|
669
|
-
file<K extends string | undefined = undefined>(key?: K, defaultValue?: any): K extends undefined ? Record<string,
|
|
666
|
+
file<K extends string | undefined = undefined, E extends boolean | undefined = undefined>(key?: K, defaultValue?: any, expectArray?: E): K extends undefined ? Record<string, E extends true ? UploadedFile[] : UploadedFile> : E extends true ? UploadedFile[] : UploadedFile;
|
|
667
|
+
/**
|
|
668
|
+
* Determine if the uploaded data contains a file.
|
|
669
|
+
*
|
|
670
|
+
* @param key
|
|
671
|
+
* @return boolean
|
|
672
|
+
*/
|
|
673
|
+
hasFile(key: string): boolean;
|
|
674
|
+
/**
|
|
675
|
+
* Check that the given file is a valid file instance.
|
|
676
|
+
*
|
|
677
|
+
* @param file
|
|
678
|
+
* @return boolean
|
|
679
|
+
*/
|
|
680
|
+
protected isValidFile(file: UploadedFile): boolean;
|
|
670
681
|
/**
|
|
671
|
-
* Get an
|
|
682
|
+
* Get an object with all the files on the request.
|
|
672
683
|
*/
|
|
673
684
|
allFiles(): Record<string, UploadedFile | UploadedFile[]>;
|
|
674
685
|
/**
|
|
@@ -848,20 +859,6 @@ declare class Request implements IRequest {
|
|
|
848
859
|
* @return {string | ReadableStream | Promise<string | ReadableStream>}
|
|
849
860
|
*/
|
|
850
861
|
getContent(asStream?: boolean): string | ReadableStream;
|
|
851
|
-
/**
|
|
852
|
-
* Determine if the uploaded data contains a file.
|
|
853
|
-
*
|
|
854
|
-
* @param key
|
|
855
|
-
* @return boolean
|
|
856
|
-
*/
|
|
857
|
-
hasFile(key: string): boolean;
|
|
858
|
-
/**
|
|
859
|
-
* Check that the given file is a valid file instance.
|
|
860
|
-
*
|
|
861
|
-
* @param file
|
|
862
|
-
* @return boolean
|
|
863
|
-
*/
|
|
864
|
-
protected isValidFile(file: UploadedFile): boolean;
|
|
865
862
|
/**
|
|
866
863
|
* Gets a "parameter" value from any bag.
|
|
867
864
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -585,10 +585,6 @@ declare class Request implements IRequest {
|
|
|
585
585
|
* Query string parameters (GET).
|
|
586
586
|
*/
|
|
587
587
|
query: InputBag;
|
|
588
|
-
/**
|
|
589
|
-
* Uploaded files (FILES).
|
|
590
|
-
*/
|
|
591
|
-
files: FileBag;
|
|
592
588
|
/**
|
|
593
589
|
* Server and execution environment parameters
|
|
594
590
|
*/
|
|
@@ -664,11 +660,26 @@ declare class Request implements IRequest {
|
|
|
664
660
|
*
|
|
665
661
|
* @param key
|
|
666
662
|
* @param defaultValue
|
|
663
|
+
* @param expectArray
|
|
667
664
|
* @returns
|
|
668
665
|
*/
|
|
669
|
-
file<K extends string | undefined = undefined>(key?: K, defaultValue?: any): K extends undefined ? Record<string,
|
|
666
|
+
file<K extends string | undefined = undefined, E extends boolean | undefined = undefined>(key?: K, defaultValue?: any, expectArray?: E): K extends undefined ? Record<string, E extends true ? UploadedFile[] : UploadedFile> : E extends true ? UploadedFile[] : UploadedFile;
|
|
667
|
+
/**
|
|
668
|
+
* Determine if the uploaded data contains a file.
|
|
669
|
+
*
|
|
670
|
+
* @param key
|
|
671
|
+
* @return boolean
|
|
672
|
+
*/
|
|
673
|
+
hasFile(key: string): boolean;
|
|
674
|
+
/**
|
|
675
|
+
* Check that the given file is a valid file instance.
|
|
676
|
+
*
|
|
677
|
+
* @param file
|
|
678
|
+
* @return boolean
|
|
679
|
+
*/
|
|
680
|
+
protected isValidFile(file: UploadedFile): boolean;
|
|
670
681
|
/**
|
|
671
|
-
* Get an
|
|
682
|
+
* Get an object with all the files on the request.
|
|
672
683
|
*/
|
|
673
684
|
allFiles(): Record<string, UploadedFile | UploadedFile[]>;
|
|
674
685
|
/**
|
|
@@ -848,20 +859,6 @@ declare class Request implements IRequest {
|
|
|
848
859
|
* @return {string | ReadableStream | Promise<string | ReadableStream>}
|
|
849
860
|
*/
|
|
850
861
|
getContent(asStream?: boolean): string | ReadableStream;
|
|
851
|
-
/**
|
|
852
|
-
* Determine if the uploaded data contains a file.
|
|
853
|
-
*
|
|
854
|
-
* @param key
|
|
855
|
-
* @return boolean
|
|
856
|
-
*/
|
|
857
|
-
hasFile(key: string): boolean;
|
|
858
|
-
/**
|
|
859
|
-
* Check that the given file is a valid file instance.
|
|
860
|
-
*
|
|
861
|
-
* @param file
|
|
862
|
-
* @return boolean
|
|
863
|
-
*/
|
|
864
|
-
protected isValidFile(file: UploadedFile): boolean;
|
|
865
862
|
/**
|
|
866
863
|
* Gets a "parameter" value from any bag.
|
|
867
864
|
*
|
package/dist/index.js
CHANGED
|
@@ -18977,7 +18977,7 @@ var FormRequest = class {
|
|
|
18977
18977
|
};
|
|
18978
18978
|
for (const [rawKey, value] of data.entries()) {
|
|
18979
18979
|
const key = rawKey.endsWith("[]") ? rawKey.slice(0, -2) : rawKey;
|
|
18980
|
-
if (value instanceof File) {
|
|
18980
|
+
if (value instanceof UploadedFile || value instanceof File) {
|
|
18981
18981
|
const uploaded = value instanceof UploadedFile ? value : UploadedFile.createFromBase(value);
|
|
18982
18982
|
if (this.dataset.files[key]) {
|
|
18983
18983
|
const existing = this.dataset.files[key];
|
|
@@ -19068,6 +19068,10 @@ var Request = class Request {
|
|
|
19068
19068
|
*/
|
|
19069
19069
|
#json;
|
|
19070
19070
|
#uri;
|
|
19071
|
+
/**
|
|
19072
|
+
* Uploaded files (FILES).
|
|
19073
|
+
*/
|
|
19074
|
+
#files;
|
|
19071
19075
|
#method = void 0;
|
|
19072
19076
|
/**
|
|
19073
19077
|
* Gets route parameters.
|
|
@@ -19094,10 +19098,6 @@ var Request = class Request {
|
|
|
19094
19098
|
*/
|
|
19095
19099
|
query;
|
|
19096
19100
|
/**
|
|
19097
|
-
* Uploaded files (FILES).
|
|
19098
|
-
*/
|
|
19099
|
-
files;
|
|
19100
|
-
/**
|
|
19101
19101
|
* Server and execution environment parameters
|
|
19102
19102
|
*/
|
|
19103
19103
|
server;
|
|
@@ -19152,7 +19152,7 @@ var Request = class Request {
|
|
|
19152
19152
|
this.query = new InputBag(getQuery(this.event), this.event);
|
|
19153
19153
|
this.attributes = new ParamBag(getRouterParams(this.event), this.event);
|
|
19154
19154
|
this.cookies = new InputBag(parseCookies(this.event), this.event);
|
|
19155
|
-
this
|
|
19155
|
+
this.#files = new FileBag(this.formData ? this.formData.files() : {}, this.event);
|
|
19156
19156
|
this.server = new ServerBag(Object.fromEntries(this.event.req.headers.entries()), this.event);
|
|
19157
19157
|
this.headers = new HeaderBag(this.server.getHeaders());
|
|
19158
19158
|
this.acceptableContentTypes = [];
|
|
@@ -19218,18 +19218,41 @@ var Request = class Request {
|
|
|
19218
19218
|
*
|
|
19219
19219
|
* @param key
|
|
19220
19220
|
* @param defaultValue
|
|
19221
|
+
* @param expectArray
|
|
19221
19222
|
* @returns
|
|
19222
19223
|
*/
|
|
19223
|
-
file(key, defaultValue) {
|
|
19224
|
-
const
|
|
19225
|
-
|
|
19224
|
+
file(key, defaultValue, expectArray) {
|
|
19225
|
+
const files = data_get(this.allFiles(), key, defaultValue);
|
|
19226
|
+
if (!files) return defaultValue;
|
|
19227
|
+
if (Array.isArray(files)) return expectArray ? files : files[0];
|
|
19228
|
+
return files;
|
|
19226
19229
|
}
|
|
19227
19230
|
/**
|
|
19228
|
-
*
|
|
19231
|
+
* Determine if the uploaded data contains a file.
|
|
19232
|
+
*
|
|
19233
|
+
* @param key
|
|
19234
|
+
* @return boolean
|
|
19235
|
+
*/
|
|
19236
|
+
hasFile(key) {
|
|
19237
|
+
let files = this.file(key, void 0, true);
|
|
19238
|
+
if (!Array.isArray(files)) files = [files];
|
|
19239
|
+
return files.some((e) => this.isValidFile(e));
|
|
19240
|
+
}
|
|
19241
|
+
/**
|
|
19242
|
+
* Check that the given file is a valid file instance.
|
|
19243
|
+
*
|
|
19244
|
+
* @param file
|
|
19245
|
+
* @return boolean
|
|
19246
|
+
*/
|
|
19247
|
+
isValidFile(file) {
|
|
19248
|
+
return file.content instanceof File && file.size > 0;
|
|
19249
|
+
}
|
|
19250
|
+
/**
|
|
19251
|
+
* Get an object with all the files on the request.
|
|
19229
19252
|
*/
|
|
19230
19253
|
allFiles() {
|
|
19231
19254
|
if (this.convertedFiles) return this.convertedFiles;
|
|
19232
|
-
const entries = Object.entries(this
|
|
19255
|
+
const entries = Object.entries(this.#files.all()).filter((e) => e[1] != null);
|
|
19233
19256
|
const files = Object.fromEntries(entries);
|
|
19234
19257
|
this.convertedFiles = this.convertUploadedFiles(files);
|
|
19235
19258
|
return this.convertedFiles;
|
|
@@ -19308,7 +19331,7 @@ var Request = class Request {
|
|
|
19308
19331
|
* Get the keys for all of the input and files.
|
|
19309
19332
|
*/
|
|
19310
19333
|
keys() {
|
|
19311
|
-
return [...Object.keys(this.input()), ...this
|
|
19334
|
+
return [...Object.keys(this.input()), ...this.#files.keys()];
|
|
19312
19335
|
}
|
|
19313
19336
|
/**
|
|
19314
19337
|
* Determine if the request is sending JSON.
|
|
@@ -19571,26 +19594,6 @@ var Request = class Request {
|
|
|
19571
19594
|
return content;
|
|
19572
19595
|
}
|
|
19573
19596
|
/**
|
|
19574
|
-
* Determine if the uploaded data contains a file.
|
|
19575
|
-
*
|
|
19576
|
-
* @param key
|
|
19577
|
-
* @return boolean
|
|
19578
|
-
*/
|
|
19579
|
-
hasFile(key) {
|
|
19580
|
-
let files = this.file(key);
|
|
19581
|
-
if (!Array.isArray(files)) files = [files];
|
|
19582
|
-
return files.some((e) => this.isValidFile(e));
|
|
19583
|
-
}
|
|
19584
|
-
/**
|
|
19585
|
-
* Check that the given file is a valid file instance.
|
|
19586
|
-
*
|
|
19587
|
-
* @param file
|
|
19588
|
-
* @return boolean
|
|
19589
|
-
*/
|
|
19590
|
-
isValidFile(file) {
|
|
19591
|
-
return file.content instanceof File && file.size > 0;
|
|
19592
|
-
}
|
|
19593
|
-
/**
|
|
19594
19597
|
* Gets a "parameter" value from any bag.
|
|
19595
19598
|
*
|
|
19596
19599
|
* This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
|