@autometa/http 2.0.0-rc.0 → 2.0.0-rc.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/http.d.ts +25 -0
- package/dist/index.cjs +60 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/http.d.ts
CHANGED
|
@@ -181,6 +181,14 @@ export declare class HTTP {
|
|
|
181
181
|
from: StatusCode;
|
|
182
182
|
to: StatusCode;
|
|
183
183
|
}[]): HTTP;
|
|
184
|
+
/**
|
|
185
|
+
* Transforms the resolved response into another shape.
|
|
186
|
+
*
|
|
187
|
+
* The response has already been parsed and schema-validated before the
|
|
188
|
+
* transformer runs. This is a convenient way to project a response into
|
|
189
|
+
* a domain model while keeping type inference on the return value.
|
|
190
|
+
*/
|
|
191
|
+
transform<TResponse, TResult>(transformer: (response: HTTPResponse<TResponse>) => TResult | Promise<TResult>): HTTPTransformClient<TResponse, TResult>;
|
|
184
192
|
/**
|
|
185
193
|
* Sets a shared query parameter for all future requests.
|
|
186
194
|
*/
|
|
@@ -298,3 +306,20 @@ export declare class HTTP {
|
|
|
298
306
|
private delayRetry;
|
|
299
307
|
private derive;
|
|
300
308
|
}
|
|
309
|
+
declare class HTTPTransformClient<TResponse, TResult> {
|
|
310
|
+
private base;
|
|
311
|
+
private transform;
|
|
312
|
+
constructor(base: HTTP, transform: (response: HTTPResponse<TResponse>) => TResult | Promise<TResult>);
|
|
313
|
+
fetchWith(method: HTTPMethod | Lowercase<HTTPMethod>, options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
314
|
+
get(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
315
|
+
post(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
316
|
+
put(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
317
|
+
patch(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
318
|
+
delete(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
319
|
+
head(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
320
|
+
options(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
321
|
+
trace(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
322
|
+
connect(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
323
|
+
stream(options?: HTTPAdditionalOptions<unknown>): Promise<TResult>;
|
|
324
|
+
}
|
|
325
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1126,6 +1126,16 @@ var _HTTP = class _HTTP {
|
|
|
1126
1126
|
meta.schema(parser, ...args);
|
|
1127
1127
|
});
|
|
1128
1128
|
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Transforms the resolved response into another shape.
|
|
1131
|
+
*
|
|
1132
|
+
* The response has already been parsed and schema-validated before the
|
|
1133
|
+
* transformer runs. This is a convenient way to project a response into
|
|
1134
|
+
* a domain model while keeping type inference on the return value.
|
|
1135
|
+
*/
|
|
1136
|
+
transform(transformer) {
|
|
1137
|
+
return new HTTPTransformClient(this, transformer);
|
|
1138
|
+
}
|
|
1129
1139
|
sharedParam(name, value, ...rest) {
|
|
1130
1140
|
this.builder.param(name, toParamValue(value, rest));
|
|
1131
1141
|
return this;
|
|
@@ -1519,6 +1529,56 @@ var _HTTP = class _HTTP {
|
|
|
1519
1529
|
};
|
|
1520
1530
|
_HTTP.sharedPlugins = [];
|
|
1521
1531
|
var HTTP = _HTTP;
|
|
1532
|
+
var HTTPTransformClient = class {
|
|
1533
|
+
constructor(base, transform) {
|
|
1534
|
+
this.base = base;
|
|
1535
|
+
this.transform = transform;
|
|
1536
|
+
}
|
|
1537
|
+
async fetchWith(method, options) {
|
|
1538
|
+
const response = await this.base.fetchWith(method, options);
|
|
1539
|
+
return this.transform(response);
|
|
1540
|
+
}
|
|
1541
|
+
async get(options) {
|
|
1542
|
+
const response = await this.base.get(options);
|
|
1543
|
+
return this.transform(response);
|
|
1544
|
+
}
|
|
1545
|
+
async post(options) {
|
|
1546
|
+
const response = await this.base.post(options);
|
|
1547
|
+
return this.transform(response);
|
|
1548
|
+
}
|
|
1549
|
+
async put(options) {
|
|
1550
|
+
const response = await this.base.put(options);
|
|
1551
|
+
return this.transform(response);
|
|
1552
|
+
}
|
|
1553
|
+
async patch(options) {
|
|
1554
|
+
const response = await this.base.patch(options);
|
|
1555
|
+
return this.transform(response);
|
|
1556
|
+
}
|
|
1557
|
+
async delete(options) {
|
|
1558
|
+
const response = await this.base.delete(options);
|
|
1559
|
+
return this.transform(response);
|
|
1560
|
+
}
|
|
1561
|
+
async head(options) {
|
|
1562
|
+
const response = await this.base.head(options);
|
|
1563
|
+
return this.transform(response);
|
|
1564
|
+
}
|
|
1565
|
+
async options(options) {
|
|
1566
|
+
const response = await this.base.options(options);
|
|
1567
|
+
return this.transform(response);
|
|
1568
|
+
}
|
|
1569
|
+
async trace(options) {
|
|
1570
|
+
const response = await this.base.trace(options);
|
|
1571
|
+
return this.transform(response);
|
|
1572
|
+
}
|
|
1573
|
+
async connect(options) {
|
|
1574
|
+
const response = await this.base.connect(options);
|
|
1575
|
+
return this.transform(response);
|
|
1576
|
+
}
|
|
1577
|
+
async stream(options) {
|
|
1578
|
+
const response = await this.base.stream(options);
|
|
1579
|
+
return this.transform(response);
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1522
1582
|
function mergeOptions2(base, overrides) {
|
|
1523
1583
|
if (!overrides) {
|
|
1524
1584
|
return { ...base };
|