fix(core): Enhance type safety for response in binary requests

This commit is contained in:
Philipp Kunz 2024-11-06 20:58:17 +01:00
parent 62db3a9bc5
commit 39d3bb4d24
6 changed files with 4717 additions and 1979 deletions

62
changelog.md Normal file
View File

@ -0,0 +1,62 @@
# Changelog
## 2024-11-06 - 2.0.23 - fix(core)
Enhance type safety for response in binary requests
- Updated the dependency versions in package.json to their latest versions.
- Improved type inference for the response body in getBinary method of smartrequest.binaryrest.ts.
- Introduced generic typing to IExtendedIncomingMessage interface for better type safety.
## 2024-05-29 - 2.0.22 - Documentation
update description
## 2024-04-01 - 2.0.21 - Configuration
Updated configuration files
- Updated `tsconfig`
- Updated `npmextra.json`: githost
## 2023-07-10 - 2.0.15 - Structure
Refactored the organization structure
- Switched to a new organization scheme
## 2022-07-29 - 1.1.57 to 2.0.0 - Major Update
Significant changes and improvements leading to a major version update
- **BREAKING CHANGE**: Switched the core to use ECMAScript modules (ESM)
## 2018-08-14 - 1.1.12 to 1.1.13 - Functional Enhancements
Enhanced request capabilities and removed unnecessary dependencies
- Fixed request module to allow sending strings
- Removed CI dependencies
## 2018-07-19 - 1.1.1 to 1.1.11 - Various Fixes and Improvements
Improvements and fixes across various components
- Added formData capability
- Corrected path resolution to use current working directory (CWD)
- Improved formData handling
- Included correct headers
- Updated request ending method
## 2018-06-19 - 1.0.14 - Structural Fix
Resolved conflicts with file extensions
- Changed `.json.ts` to `.jsonrest.ts` to avoid conflicts
## 2018-06-13 - 1.0.8 to 1.0.10 - Core Updates
Ensured binary handling compliance
- Enhanced core to uphold latest standards
- Correct binary file handling response
- Fix for handling and returning binary responses
## 2017-06-09 - 1.0.4 to 1.0.6 - Infrastructure and Type Improvements
Types and infrastructure updates
- Improved types
- Removed need for content type on post requests
- Updated for new infrastructure

View File

@ -36,17 +36,17 @@
},
"homepage": "https://code.foss.global/push.rocks/smartrequest",
"dependencies": {
"@push.rocks/smartpromise": "^4.0.2",
"@push.rocks/smarturl": "^3.0.6",
"@push.rocks/smartpromise": "^4.0.4",
"@push.rocks/smarturl": "^3.1.0",
"agentkeepalive": "^4.5.0",
"form-data": "^4.0.0"
"form-data": "^4.0.1"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.77",
"@git.zone/tsbuild": "^2.2.0",
"@git.zone/tsrun": "^1.3.3",
"@git.zone/tstest": "^1.0.90",
"@pushrocks/tapbundle": "^5.0.8",
"@types/node": "^20.9.0"
"@types/node": "^22.9.0"
},
"files": [
"ts/**/*",

6608
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartrequest',
version: '2.0.22',
version: '2.0.23',
description: 'A module for modern HTTP/HTTPS requests with support for form data, file uploads, JSON, binary data, streams, and more.'
}

View File

@ -1,6 +1,6 @@
// this file implements methods to get and post binary data.
import * as interfaces from './smartrequest.interfaces.js';
import { request } from './smartrequest.request.js';
import { request, type IExtendedIncomingMessage } from './smartrequest.request.js';
import * as plugins from './smartrequest.plugins.js';
@ -29,5 +29,5 @@ export const getBinary = async (
done.resolve();
});
await done.promise;
return response;
return response as IExtendedIncomingMessage<Buffer>;
};

View File

@ -1,8 +1,8 @@
import * as plugins from './smartrequest.plugins.js';
import * as interfaces from './smartrequest.interfaces.js';
export interface IExtendedIncomingMessage extends plugins.http.IncomingMessage {
body: any;
export interface IExtendedIncomingMessage<T = any> extends plugins.http.IncomingMessage {
body: T;
}
const buildUtf8Response = (