@h3ravel/http 11.5.0 → 11.5.2

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 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];
@@ -19110,14 +19110,14 @@ var Request = class Request {
19110
19110
  */
19111
19111
  request;
19112
19112
  /**
19113
- * Query string parameters (GET).
19114
- */
19115
- query;
19116
- /**
19117
19113
  * Uploaded files (FILES).
19118
19114
  */
19119
19115
  files;
19120
19116
  /**
19117
+ * Query string parameters (GET).
19118
+ */
19119
+ query;
19120
+ /**
19121
19121
  * Server and execution environment parameters
19122
19122
  */
19123
19123
  server;
@@ -19238,14 +19238,37 @@ 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 source = this.allFiles();
19245
- return key ? (0, __h3ravel_support.data_get)(source, key, defaultValue) : source;
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;
19249
+ }
19250
+ /**
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));
19246
19260
  }
19247
19261
  /**
19248
- * Get an array of all of the files on the request.
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;
@@ -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
@@ -581,14 +581,14 @@ declare class Request implements IRequest {
581
581
  * @see getPayload() for portability between content types
582
582
  */
583
583
  protected request: InputBag;
584
- /**
585
- * Query string parameters (GET).
586
- */
587
- query: InputBag;
588
584
  /**
589
585
  * Uploaded files (FILES).
590
586
  */
591
587
  files: FileBag;
588
+ /**
589
+ * Query string parameters (GET).
590
+ */
591
+ query: InputBag;
592
592
  /**
593
593
  * Server and execution environment parameters
594
594
  */
@@ -664,11 +664,26 @@ declare class Request implements IRequest {
664
664
  *
665
665
  * @param key
666
666
  * @param defaultValue
667
+ * @param expectArray
667
668
  * @returns
668
669
  */
669
- file<K extends string | undefined = undefined>(key?: K, defaultValue?: any): K extends undefined ? Record<string, UploadedFile | UploadedFile[]> : UploadedFile | UploadedFile[];
670
+ 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;
671
+ /**
672
+ * Determine if the uploaded data contains a file.
673
+ *
674
+ * @param key
675
+ * @return boolean
676
+ */
677
+ hasFile(key: string): boolean;
678
+ /**
679
+ * Check that the given file is a valid file instance.
680
+ *
681
+ * @param file
682
+ * @return boolean
683
+ */
684
+ protected isValidFile(file: UploadedFile): boolean;
670
685
  /**
671
- * Get an array of all of the files on the request.
686
+ * Get an object with all the files on the request.
672
687
  */
673
688
  allFiles(): Record<string, UploadedFile | UploadedFile[]>;
674
689
  /**
@@ -848,20 +863,6 @@ declare class Request implements IRequest {
848
863
  * @return {string | ReadableStream | Promise<string | ReadableStream>}
849
864
  */
850
865
  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
866
  /**
866
867
  * Gets a "parameter" value from any bag.
867
868
  *
package/dist/index.d.ts CHANGED
@@ -581,14 +581,14 @@ declare class Request implements IRequest {
581
581
  * @see getPayload() for portability between content types
582
582
  */
583
583
  protected request: InputBag;
584
- /**
585
- * Query string parameters (GET).
586
- */
587
- query: InputBag;
588
584
  /**
589
585
  * Uploaded files (FILES).
590
586
  */
591
587
  files: FileBag;
588
+ /**
589
+ * Query string parameters (GET).
590
+ */
591
+ query: InputBag;
592
592
  /**
593
593
  * Server and execution environment parameters
594
594
  */
@@ -664,11 +664,26 @@ declare class Request implements IRequest {
664
664
  *
665
665
  * @param key
666
666
  * @param defaultValue
667
+ * @param expectArray
667
668
  * @returns
668
669
  */
669
- file<K extends string | undefined = undefined>(key?: K, defaultValue?: any): K extends undefined ? Record<string, UploadedFile | UploadedFile[]> : UploadedFile | UploadedFile[];
670
+ 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;
671
+ /**
672
+ * Determine if the uploaded data contains a file.
673
+ *
674
+ * @param key
675
+ * @return boolean
676
+ */
677
+ hasFile(key: string): boolean;
678
+ /**
679
+ * Check that the given file is a valid file instance.
680
+ *
681
+ * @param file
682
+ * @return boolean
683
+ */
684
+ protected isValidFile(file: UploadedFile): boolean;
670
685
  /**
671
- * Get an array of all of the files on the request.
686
+ * Get an object with all the files on the request.
672
687
  */
673
688
  allFiles(): Record<string, UploadedFile | UploadedFile[]>;
674
689
  /**
@@ -848,20 +863,6 @@ declare class Request implements IRequest {
848
863
  * @return {string | ReadableStream | Promise<string | ReadableStream>}
849
864
  */
850
865
  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
866
  /**
866
867
  * Gets a "parameter" value from any bag.
867
868
  *
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];
@@ -19090,14 +19090,14 @@ var Request = class Request {
19090
19090
  */
19091
19091
  request;
19092
19092
  /**
19093
- * Query string parameters (GET).
19094
- */
19095
- query;
19096
- /**
19097
19093
  * Uploaded files (FILES).
19098
19094
  */
19099
19095
  files;
19100
19096
  /**
19097
+ * Query string parameters (GET).
19098
+ */
19099
+ query;
19100
+ /**
19101
19101
  * Server and execution environment parameters
19102
19102
  */
19103
19103
  server;
@@ -19218,14 +19218,37 @@ 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 source = this.allFiles();
19225
- return key ? data_get(source, key, defaultValue) : source;
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;
19229
+ }
19230
+ /**
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));
19226
19240
  }
19227
19241
  /**
19228
- * Get an array of all of the files on the request.
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;
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/http",
3
- "version": "11.5.0",
3
+ "version": "11.5.2",
4
4
  "description": "HTTP kernel, middleware pipeline, request/response classes for H3ravel.",
5
5
  "h3ravel": {
6
6
  "providers": [