@autometa/http 2.0.0-rc.1 → 2.0.0-rc.3
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/index.js
CHANGED
|
@@ -1124,6 +1124,16 @@ var _HTTP = class _HTTP {
|
|
|
1124
1124
|
meta.schema(parser, ...args);
|
|
1125
1125
|
});
|
|
1126
1126
|
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Transforms the resolved response into another shape.
|
|
1129
|
+
*
|
|
1130
|
+
* The response has already been parsed and schema-validated before the
|
|
1131
|
+
* transformer runs. This is a convenient way to project a response into
|
|
1132
|
+
* a domain model while keeping type inference on the return value.
|
|
1133
|
+
*/
|
|
1134
|
+
transform(transformer) {
|
|
1135
|
+
return new HTTPTransformClient(this, transformer);
|
|
1136
|
+
}
|
|
1127
1137
|
sharedParam(name, value, ...rest) {
|
|
1128
1138
|
this.builder.param(name, toParamValue(value, rest));
|
|
1129
1139
|
return this;
|
|
@@ -1517,6 +1527,56 @@ var _HTTP = class _HTTP {
|
|
|
1517
1527
|
};
|
|
1518
1528
|
_HTTP.sharedPlugins = [];
|
|
1519
1529
|
var HTTP = _HTTP;
|
|
1530
|
+
var HTTPTransformClient = class {
|
|
1531
|
+
constructor(base, transform) {
|
|
1532
|
+
this.base = base;
|
|
1533
|
+
this.transform = transform;
|
|
1534
|
+
}
|
|
1535
|
+
async fetchWith(method, options) {
|
|
1536
|
+
const response = await this.base.fetchWith(method, options);
|
|
1537
|
+
return this.transform(response);
|
|
1538
|
+
}
|
|
1539
|
+
async get(options) {
|
|
1540
|
+
const response = await this.base.get(options);
|
|
1541
|
+
return this.transform(response);
|
|
1542
|
+
}
|
|
1543
|
+
async post(options) {
|
|
1544
|
+
const response = await this.base.post(options);
|
|
1545
|
+
return this.transform(response);
|
|
1546
|
+
}
|
|
1547
|
+
async put(options) {
|
|
1548
|
+
const response = await this.base.put(options);
|
|
1549
|
+
return this.transform(response);
|
|
1550
|
+
}
|
|
1551
|
+
async patch(options) {
|
|
1552
|
+
const response = await this.base.patch(options);
|
|
1553
|
+
return this.transform(response);
|
|
1554
|
+
}
|
|
1555
|
+
async delete(options) {
|
|
1556
|
+
const response = await this.base.delete(options);
|
|
1557
|
+
return this.transform(response);
|
|
1558
|
+
}
|
|
1559
|
+
async head(options) {
|
|
1560
|
+
const response = await this.base.head(options);
|
|
1561
|
+
return this.transform(response);
|
|
1562
|
+
}
|
|
1563
|
+
async options(options) {
|
|
1564
|
+
const response = await this.base.options(options);
|
|
1565
|
+
return this.transform(response);
|
|
1566
|
+
}
|
|
1567
|
+
async trace(options) {
|
|
1568
|
+
const response = await this.base.trace(options);
|
|
1569
|
+
return this.transform(response);
|
|
1570
|
+
}
|
|
1571
|
+
async connect(options) {
|
|
1572
|
+
const response = await this.base.connect(options);
|
|
1573
|
+
return this.transform(response);
|
|
1574
|
+
}
|
|
1575
|
+
async stream(options) {
|
|
1576
|
+
const response = await this.base.stream(options);
|
|
1577
|
+
return this.transform(response);
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1520
1580
|
function mergeOptions2(base, overrides) {
|
|
1521
1581
|
if (!overrides) {
|
|
1522
1582
|
return { ...base };
|