@aws-sdk/protocol-http
Advanced tools
Comparing version 3.289.0 to 3.290.0
@@ -21,5 +21,3 @@ "use strict"; | ||
toString() { | ||
return this.values | ||
.map((v) => (v.includes(",") || v.includes(" ") ? `"${v}"` : v)) | ||
.join(", "); | ||
return this.values.map((v) => (v.includes(",") ? `"${v}"` : v)).join(", "); | ||
} | ||
@@ -26,0 +24,0 @@ get() { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Fields = void 0; | ||
const Field_1 = require("./Field"); | ||
class Fields { | ||
@@ -22,3 +23,12 @@ constructor({ fields = [], encoding = "utf-8" }) { | ||
} | ||
getAll() { | ||
return Object.values(this.entries); | ||
} | ||
static from(fieldsToCreate, encoding) { | ||
return fieldsToCreate.reduce((fields, fieldArgs) => { | ||
fields.setField(new Field_1.Field(fieldArgs)); | ||
return fields; | ||
}, new Fields({ encoding })); | ||
} | ||
} | ||
exports.Fields = Fields; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HttpRequest = void 0; | ||
const Fields_1 = require("./Fields"); | ||
const headersProxy_1 = require("./headersProxy"); | ||
const queryProxy_1 = require("./queryProxy"); | ||
class HttpRequest { | ||
constructor(options) { | ||
this.protocol = "https"; | ||
this.hostname = "localhost"; | ||
this.path = "/"; | ||
this.query = {}; | ||
this.headers = {}; | ||
this.method = options.method || "GET"; | ||
this.hostname = options.hostname || "localhost"; | ||
this.port = options.port; | ||
this.query = options.query || {}; | ||
this.headers = options.headers || {}; | ||
this.destination = HttpRequest.getDefaultDestination(options); | ||
this.fields = (0, headersProxy_1.headersToFields)(options.headers || {}); | ||
this.body = options.body; | ||
this.protocol = options.protocol | ||
? options.protocol.slice(-1) !== ":" | ||
? `${options.protocol}:` | ||
: options.protocol | ||
: "https:"; | ||
this.path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/"; | ||
const httpRequest = this; | ||
Object.defineProperties(httpRequest, { | ||
protocol: { | ||
enumerable: true, | ||
get() { | ||
return httpRequest.destination.protocol; | ||
}, | ||
set(protocol) { | ||
httpRequest.destination.protocol = protocol; | ||
}, | ||
}, | ||
hostname: { | ||
enumerable: true, | ||
get() { | ||
return httpRequest.destination.hostname; | ||
}, | ||
set(hostname) { | ||
httpRequest.destination.hostname = hostname; | ||
}, | ||
}, | ||
port: { | ||
enumerable: true, | ||
get() { | ||
const port = httpRequest.destination.port; | ||
return port ? Number(port) : undefined; | ||
}, | ||
set(port) { | ||
httpRequest.destination.port = String(port); | ||
}, | ||
}, | ||
path: { | ||
enumerable: true, | ||
get() { | ||
return httpRequest.destination.pathname; | ||
}, | ||
set(path) { | ||
httpRequest.destination.pathname = path; | ||
}, | ||
}, | ||
query: { | ||
enumerable: true, | ||
get() { | ||
return (0, queryProxy_1.getQueryProxy)(httpRequest.destination.searchParams); | ||
}, | ||
set(query) { | ||
const searchParams = (0, queryProxy_1.queryToSearchParams)(query || {}); | ||
httpRequest.destination.search = searchParams.toString(); | ||
}, | ||
}, | ||
headers: { | ||
enumerable: true, | ||
get() { | ||
return (0, headersProxy_1.getHeadersProxy)(httpRequest.fields); | ||
}, | ||
set(headers) { | ||
httpRequest.fields = (0, headersProxy_1.headersToFields)(headers); | ||
}, | ||
}, | ||
}); | ||
} | ||
static from(options) { | ||
const request = new HttpRequest(options); | ||
if (options.destination) { | ||
request.destination = options.destination; | ||
} | ||
if (options.fields) { | ||
request.fields = options.fields; | ||
} | ||
return request; | ||
} | ||
static isInstance(request) { | ||
@@ -31,20 +100,26 @@ if (!request) | ||
clone() { | ||
const cloned = new HttpRequest({ | ||
return HttpRequest.from({ | ||
...this, | ||
headers: { ...this.headers }, | ||
destination: new URL(this.destination), | ||
fields: Fields_1.Fields.from(this.fields.getAll().map((field) => ({ | ||
...field, | ||
values: [...field.values], | ||
}))), | ||
}); | ||
if (cloned.query) | ||
cloned.query = cloneQuery(cloned.query); | ||
return cloned; | ||
} | ||
static getDefaultDestination(options) { | ||
const protocol = options.protocol | ||
? options.protocol.slice(-1) !== ":" | ||
? `${options.protocol}:` | ||
: options.protocol | ||
: "https:"; | ||
const hostname = options.hostname || "localhost"; | ||
const port = options.port ? `:${String(options.port)}` : ""; | ||
const path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/"; | ||
const searchParams = (0, queryProxy_1.queryToSearchParams)(options.query || {}); | ||
const url = new URL(`${protocol}//${hostname}${port}${path}`); | ||
url.search = searchParams.toString(); | ||
return url; | ||
} | ||
} | ||
exports.HttpRequest = HttpRequest; | ||
function cloneQuery(query) { | ||
return Object.keys(query).reduce((carry, paramName) => { | ||
const param = query[paramName]; | ||
return { | ||
...carry, | ||
[paramName]: Array.isArray(param) ? [...param] : param, | ||
}; | ||
}, {}); | ||
} |
@@ -18,5 +18,3 @@ import { FieldPosition } from "./FieldPosition"; | ||
toString() { | ||
return this.values | ||
.map((v) => (v.includes(",") || v.includes(" ") ? `"${v}"` : v)) | ||
.join(", "); | ||
return this.values.map((v) => (v.includes(",") ? `"${v}"` : v)).join(", "); | ||
} | ||
@@ -23,0 +21,0 @@ get() { |
@@ -0,1 +1,2 @@ | ||
import { Field } from "./Field"; | ||
export class Fields { | ||
@@ -19,2 +20,11 @@ constructor({ fields = [], encoding = "utf-8" }) { | ||
} | ||
getAll() { | ||
return Object.values(this.entries); | ||
} | ||
static from(fieldsToCreate, encoding) { | ||
return fieldsToCreate.reduce((fields, fieldArgs) => { | ||
fields.setField(new Field(fieldArgs)); | ||
return fields; | ||
}, new Fields({ encoding })); | ||
} | ||
} |
@@ -0,16 +1,85 @@ | ||
import { Fields } from "./Fields"; | ||
import { getHeadersProxy, headersToFields } from "./headersProxy"; | ||
import { getQueryProxy, queryToSearchParams } from "./queryProxy"; | ||
export class HttpRequest { | ||
constructor(options) { | ||
this.protocol = "https"; | ||
this.hostname = "localhost"; | ||
this.path = "/"; | ||
this.query = {}; | ||
this.headers = {}; | ||
this.method = options.method || "GET"; | ||
this.hostname = options.hostname || "localhost"; | ||
this.port = options.port; | ||
this.query = options.query || {}; | ||
this.headers = options.headers || {}; | ||
this.destination = HttpRequest.getDefaultDestination(options); | ||
this.fields = headersToFields(options.headers || {}); | ||
this.body = options.body; | ||
this.protocol = options.protocol | ||
? options.protocol.slice(-1) !== ":" | ||
? `${options.protocol}:` | ||
: options.protocol | ||
: "https:"; | ||
this.path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/"; | ||
const httpRequest = this; | ||
Object.defineProperties(httpRequest, { | ||
protocol: { | ||
enumerable: true, | ||
get() { | ||
return httpRequest.destination.protocol; | ||
}, | ||
set(protocol) { | ||
httpRequest.destination.protocol = protocol; | ||
}, | ||
}, | ||
hostname: { | ||
enumerable: true, | ||
get() { | ||
return httpRequest.destination.hostname; | ||
}, | ||
set(hostname) { | ||
httpRequest.destination.hostname = hostname; | ||
}, | ||
}, | ||
port: { | ||
enumerable: true, | ||
get() { | ||
const port = httpRequest.destination.port; | ||
return port ? Number(port) : undefined; | ||
}, | ||
set(port) { | ||
httpRequest.destination.port = String(port); | ||
}, | ||
}, | ||
path: { | ||
enumerable: true, | ||
get() { | ||
return httpRequest.destination.pathname; | ||
}, | ||
set(path) { | ||
httpRequest.destination.pathname = path; | ||
}, | ||
}, | ||
query: { | ||
enumerable: true, | ||
get() { | ||
return getQueryProxy(httpRequest.destination.searchParams); | ||
}, | ||
set(query) { | ||
const searchParams = queryToSearchParams(query || {}); | ||
httpRequest.destination.search = searchParams.toString(); | ||
}, | ||
}, | ||
headers: { | ||
enumerable: true, | ||
get() { | ||
return getHeadersProxy(httpRequest.fields); | ||
}, | ||
set(headers) { | ||
httpRequest.fields = headersToFields(headers); | ||
}, | ||
}, | ||
}); | ||
} | ||
static from(options) { | ||
const request = new HttpRequest(options); | ||
if (options.destination) { | ||
request.destination = options.destination; | ||
} | ||
if (options.fields) { | ||
request.fields = options.fields; | ||
} | ||
return request; | ||
} | ||
static isInstance(request) { | ||
@@ -28,19 +97,25 @@ if (!request) | ||
clone() { | ||
const cloned = new HttpRequest({ | ||
return HttpRequest.from({ | ||
...this, | ||
headers: { ...this.headers }, | ||
destination: new URL(this.destination), | ||
fields: Fields.from(this.fields.getAll().map((field) => ({ | ||
...field, | ||
values: [...field.values], | ||
}))), | ||
}); | ||
if (cloned.query) | ||
cloned.query = cloneQuery(cloned.query); | ||
return cloned; | ||
} | ||
static getDefaultDestination(options) { | ||
const protocol = options.protocol | ||
? options.protocol.slice(-1) !== ":" | ||
? `${options.protocol}:` | ||
: options.protocol | ||
: "https:"; | ||
const hostname = options.hostname || "localhost"; | ||
const port = options.port ? `:${String(options.port)}` : ""; | ||
const path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/"; | ||
const searchParams = queryToSearchParams(options.query || {}); | ||
const url = new URL(`${protocol}//${hostname}${port}${path}`); | ||
url.search = searchParams.toString(); | ||
return url; | ||
} | ||
} | ||
function cloneQuery(query) { | ||
return Object.keys(query).reduce((carry, paramName) => { | ||
const param = query[paramName]; | ||
return { | ||
...carry, | ||
[paramName]: Array.isArray(param) ? [...param] : param, | ||
}; | ||
}, {}); | ||
} |
@@ -43,3 +43,3 @@ import { FieldPosition } from "./FieldPosition"; | ||
/** | ||
* Get comma-delimited string. | ||
* Get comma-delimited string to be sent over the wire. | ||
* | ||
@@ -46,0 +46,0 @@ * @returns String representation of {@link Field}. |
@@ -1,2 +0,2 @@ | ||
import { Field } from "./Field"; | ||
import { Field, FieldOptions } from "./Field"; | ||
import { FieldPosition } from "./FieldPosition"; | ||
@@ -44,2 +44,19 @@ export declare type FieldsOptions = { | ||
getByType(kind: FieldPosition): Field[]; | ||
/** | ||
* Retrieves all the {@link Field}s in the collection. | ||
* Includes headers and trailers. | ||
* | ||
* @returns All fields in the collection. | ||
*/ | ||
getAll(): Field[]; | ||
/** | ||
* Utility for creating {@link Fields} without having to | ||
* construct each {@link Field} individually. | ||
* | ||
* @param fieldsToCreate List of arguments used to create each | ||
* {@link Field}. | ||
* @param encoding Optional encoding of resultant {@link Fields}. | ||
* @returns The {@link Fields} instance. | ||
*/ | ||
static from(fieldsToCreate: FieldOptions[], encoding?: string): Fields; | ||
} |
@@ -1,20 +0,63 @@ | ||
import { Endpoint, HeaderBag, HttpMessage, HttpRequest as IHttpRequest, QueryParameterBag } from "@aws-sdk/types"; | ||
declare type HttpRequestOptions = Partial<HttpMessage> & Partial<Endpoint> & { | ||
import { HeaderBag, QueryParameterBag, Request } from "@aws-sdk/types"; | ||
import { Fields } from "./Fields"; | ||
export interface HttpRequestOptions { | ||
method?: string; | ||
}; | ||
export interface HttpRequest extends IHttpRequest { | ||
protocol?: string; | ||
hostname?: string; | ||
port?: number; | ||
path?: string; | ||
query?: QueryParameterBag; | ||
headers?: HeaderBag; | ||
body?: any; | ||
} | ||
export declare class HttpRequest implements HttpMessage, Endpoint { | ||
export interface HttpRequestFromOptions { | ||
method?: string; | ||
destination?: URL; | ||
fields?: Fields; | ||
body?: any; | ||
} | ||
export interface HttpRequest extends Request { | ||
method: string; | ||
destination: URL; | ||
fields: Fields; | ||
body?: any; | ||
} | ||
export declare class HttpRequest implements Request { | ||
method: string; | ||
destination: URL; | ||
fields: Fields; | ||
body?: any; | ||
/** | ||
* @deprecated Use protocol in {@link destination} | ||
*/ | ||
protocol: string; | ||
/** | ||
* @deprecated Use hostname in {@link destination} | ||
*/ | ||
hostname: string; | ||
/** | ||
* @deprecated Use port in {@link destination} | ||
*/ | ||
port?: number; | ||
/** | ||
* @deprecated Use pathname in {@link destination} | ||
*/ | ||
path: string; | ||
/** | ||
* @deprecated Use searchParams in {@link destination} | ||
*/ | ||
query: QueryParameterBag; | ||
/** | ||
* @deprecated Use {@link fields} | ||
*/ | ||
headers: HeaderBag; | ||
body?: any; | ||
/** | ||
* | ||
* @deprecated Use {@link HttpRequest.from} | ||
*/ | ||
constructor(options: HttpRequestOptions); | ||
static from(options: HttpRequestFromOptions): HttpRequest; | ||
static isInstance(request: unknown): request is HttpRequest; | ||
clone(): HttpRequest; | ||
private static getDefaultDestination; | ||
} | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
import { Field } from "./Field"; | ||
import { Field, FieldOptions } from "./Field"; | ||
import { FieldPosition } from "./FieldPosition"; | ||
@@ -15,2 +15,4 @@ export declare type FieldsOptions = { | ||
getByType(kind: FieldPosition): Field[]; | ||
getAll(): Field[]; | ||
static from(fieldsToCreate: FieldOptions[], encoding?: string): Fields; | ||
} |
@@ -1,15 +0,30 @@ | ||
import { | ||
Endpoint, | ||
HeaderBag, | ||
HttpMessage, | ||
HttpRequest as IHttpRequest, | ||
QueryParameterBag, | ||
} from "@aws-sdk/types"; | ||
declare type HttpRequestOptions = Partial<HttpMessage> & | ||
Partial<Endpoint> & { | ||
method?: string; | ||
}; | ||
export interface HttpRequest extends IHttpRequest {} | ||
export declare class HttpRequest implements HttpMessage, Endpoint { | ||
import { HeaderBag, QueryParameterBag, Request } from "@aws-sdk/types"; | ||
import { Fields } from "./Fields"; | ||
export interface HttpRequestOptions { | ||
method?: string; | ||
protocol?: string; | ||
hostname?: string; | ||
port?: number; | ||
path?: string; | ||
query?: QueryParameterBag; | ||
headers?: HeaderBag; | ||
body?: any; | ||
} | ||
export interface HttpRequestFromOptions { | ||
method?: string; | ||
destination?: URL; | ||
fields?: Fields; | ||
body?: any; | ||
} | ||
export interface HttpRequest extends Request { | ||
method: string; | ||
destination: URL; | ||
fields: Fields; | ||
body?: any; | ||
} | ||
export declare class HttpRequest implements Request { | ||
method: string; | ||
destination: URL; | ||
fields: Fields; | ||
body?: any; | ||
protocol: string; | ||
@@ -21,7 +36,7 @@ hostname: string; | ||
headers: HeaderBag; | ||
body?: any; | ||
constructor(options: HttpRequestOptions); | ||
static from(options: HttpRequestFromOptions): HttpRequest; | ||
static isInstance(request: unknown): request is HttpRequest; | ||
clone(): HttpRequest; | ||
private static getDefaultDestination; | ||
} | ||
export {}; |
{ | ||
"name": "@aws-sdk/protocol-http", | ||
"version": "3.289.0", | ||
"version": "3.290.0", | ||
"scripts": { | ||
@@ -12,3 +12,3 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo", | ||
"test": "jest" | ||
"test": "jest --coverage" | ||
}, | ||
@@ -25,3 +25,3 @@ "main": "./dist-cjs/index.js", | ||
"dependencies": { | ||
"@aws-sdk/types": "3.289.0", | ||
"@aws-sdk/types": "3.290.0", | ||
"tslib": "^2.3.1" | ||
@@ -28,0 +28,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49705
43
1070
+ Added@aws-sdk/types@3.290.0(transitive)
- Removed@aws-sdk/types@3.289.0(transitive)
Updated@aws-sdk/types@3.290.0