aspi 2.9.0 → 2.10.0
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 +12 -2
- package/dist/index.d.cts +33 -1
- package/dist/index.d.ts +33 -1
- package/dist/index.js +12 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -332,6 +332,7 @@ var Request = class {
|
|
|
332
332
|
#querySchemaAsyncResult = null;
|
|
333
333
|
#querySchemaAsyncParams = null;
|
|
334
334
|
#throwOnError = false;
|
|
335
|
+
#queryParamSerializer;
|
|
335
336
|
#capabilities = [];
|
|
336
337
|
constructor(method, path, requestOptions, capabilities = []) {
|
|
337
338
|
this.#path = path;
|
|
@@ -344,6 +345,7 @@ var Request = class {
|
|
|
344
345
|
this.#customErrorCbs = { ...requestOptions?.errorCbs || {} };
|
|
345
346
|
this.#throwOnError = requestOptions.throwOnError || false;
|
|
346
347
|
this.#shouldBeResult = requestOptions.shouldBeResult || false;
|
|
348
|
+
this.#queryParamSerializer = requestOptions.queryParamSerializer;
|
|
347
349
|
this.#capabilities = [...capabilities];
|
|
348
350
|
}
|
|
349
351
|
/**
|
|
@@ -1092,6 +1094,11 @@ var Request = class {
|
|
|
1092
1094
|
return qp;
|
|
1093
1095
|
}
|
|
1094
1096
|
if (typeof value === "object" && value !== null) {
|
|
1097
|
+
if (this.#queryParamSerializer) {
|
|
1098
|
+
return this.#valueToQueryParams(
|
|
1099
|
+
this.#queryParamSerializer(value)
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1095
1102
|
const qp = new URLSearchParams();
|
|
1096
1103
|
for (const [key, val] of Object.entries(
|
|
1097
1104
|
value
|
|
@@ -1642,11 +1649,13 @@ var Aspi2 = class {
|
|
|
1642
1649
|
#customErrorCbs = {};
|
|
1643
1650
|
#throwOnError = false;
|
|
1644
1651
|
#shouldBeResult = false;
|
|
1652
|
+
#queryParamSerializer;
|
|
1645
1653
|
#capabilities = [];
|
|
1646
1654
|
constructor(config) {
|
|
1647
|
-
const { retryConfig, ...requestInit } = config;
|
|
1655
|
+
const { retryConfig, queryParamSerializer, ...requestInit } = config;
|
|
1648
1656
|
this.#globalRequestInit = requestInit;
|
|
1649
1657
|
this.#retryConfig = retryConfig;
|
|
1658
|
+
this.#queryParamSerializer = queryParamSerializer;
|
|
1650
1659
|
}
|
|
1651
1660
|
/**
|
|
1652
1661
|
* Sets or overrides the base URL used for all subsequent API requests.
|
|
@@ -1697,7 +1706,8 @@ var Aspi2 = class {
|
|
|
1697
1706
|
errorCbs: this.#customErrorCbs,
|
|
1698
1707
|
throwOnError: this.#throwOnError,
|
|
1699
1708
|
shouldBeResult: this.#shouldBeResult,
|
|
1700
|
-
retryConfig: this.#retryConfig
|
|
1709
|
+
retryConfig: this.#retryConfig,
|
|
1710
|
+
queryParamSerializer: this.#queryParamSerializer
|
|
1701
1711
|
},
|
|
1702
1712
|
this.#capabilities
|
|
1703
1713
|
);
|
package/dist/index.d.cts
CHANGED
|
@@ -156,6 +156,9 @@ type BaseURL = string | URL;
|
|
|
156
156
|
* is intended to be passed alongside a `RequestInit` object when initializing
|
|
157
157
|
* an Aspi instance.
|
|
158
158
|
*/
|
|
159
|
+
type QueryParamSerializerInput = Record<string, unknown>;
|
|
160
|
+
type QueryParamSerializerResult = URLSearchParams | string | Iterable<[string, string]>;
|
|
161
|
+
type QueryParamSerializer = (params: QueryParamSerializerInput) => QueryParamSerializerResult;
|
|
159
162
|
type AspiConfigBase = {
|
|
160
163
|
/**
|
|
161
164
|
* The base URL for all Aspi requests.
|
|
@@ -165,6 +168,34 @@ type AspiConfigBase = {
|
|
|
165
168
|
* Optional retry configuration applied to all requests.
|
|
166
169
|
*/
|
|
167
170
|
retryConfig?: AspiRetryConfig<AspiRequestInit>;
|
|
171
|
+
/**
|
|
172
|
+
* Optional custom serializer for object-style query parameters passed to
|
|
173
|
+
* `setQueryParams`. Receives the parsed/validated param object and must return
|
|
174
|
+
* a value that Aspi can turn into query params (`URLSearchParams`, a query
|
|
175
|
+
* string, or an iterable of `[key, value]` tuples).
|
|
176
|
+
*
|
|
177
|
+
* When omitted, arrays are stringified using the default
|
|
178
|
+
* `URLSearchParams` behaviour (`tag=a%2Cb%2Cc`).
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* const api = new Aspi({
|
|
183
|
+
* baseUrl: 'https://api.example.com',
|
|
184
|
+
* queryParamSerializer: (params) => {
|
|
185
|
+
* const qp = new URLSearchParams();
|
|
186
|
+
* for (const [key, value] of Object.entries(params)) {
|
|
187
|
+
* if (Array.isArray(value)) {
|
|
188
|
+
* for (const item of value) qp.append(key, String(item));
|
|
189
|
+
* } else {
|
|
190
|
+
* qp.append(key, String(value));
|
|
191
|
+
* }
|
|
192
|
+
* }
|
|
193
|
+
* return qp;
|
|
194
|
+
* },
|
|
195
|
+
* });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
queryParamSerializer?: QueryParamSerializer;
|
|
168
199
|
};
|
|
169
200
|
/**
|
|
170
201
|
* Configuration for an Aspi instance (without request body).
|
|
@@ -285,6 +316,7 @@ type RequestOptions<TRequest extends AspiRequestInit> = {
|
|
|
285
316
|
errorCbs?: ErrorCallbacks;
|
|
286
317
|
throwOnError?: boolean;
|
|
287
318
|
shouldBeResult?: boolean;
|
|
319
|
+
queryParamSerializer?: QueryParamSerializer;
|
|
288
320
|
};
|
|
289
321
|
/**
|
|
290
322
|
* Record of custom error callbacks keyed by HTTP status code.
|
|
@@ -2086,4 +2118,4 @@ declare class Aspi<TRequest extends AspiRequestInit = AspiRequestInit, Opts exte
|
|
|
2086
2118
|
useCapability(capability: Capability<TRequest>): this;
|
|
2087
2119
|
}
|
|
2088
2120
|
|
|
2089
|
-
export { Aspi, type AspiConfigBase, AspiError, type AspiPlainResponse, type AspiRequest, type AspiRequestInit, type AspiRequestInitWithoutBodyAndMethod, type AspiResponse, type AspiResultOk, type AspiRetryConfig, type BaseURL, type Capability, type CapabilityArgs, CustomError, type CustomErrorCb, type ErrorCallbacks, type HttpErrorCodes, type HttpErrorStatus, type HttpMethods, type JSONParseError, type Merge, type Prettify, Request, type RequestOptions, type RequestTransformer, result as Result, type SchemaParseError, getHttpErrorStatus, httpErrors, isAspiError, isCustomError, isJSONParseError, isSchemaParseError };
|
|
2121
|
+
export { Aspi, type AspiConfigBase, AspiError, type AspiPlainResponse, type AspiRequest, type AspiRequestInit, type AspiRequestInitWithoutBodyAndMethod, type AspiResponse, type AspiResultOk, type AspiRetryConfig, type BaseURL, type Capability, type CapabilityArgs, CustomError, type CustomErrorCb, type ErrorCallbacks, type HttpErrorCodes, type HttpErrorStatus, type HttpMethods, type JSONParseError, type Merge, type Prettify, type QueryParamSerializer, type QueryParamSerializerInput, type QueryParamSerializerResult, Request, type RequestOptions, type RequestTransformer, result as Result, type SchemaParseError, getHttpErrorStatus, httpErrors, isAspiError, isCustomError, isJSONParseError, isSchemaParseError };
|
package/dist/index.d.ts
CHANGED
|
@@ -156,6 +156,9 @@ type BaseURL = string | URL;
|
|
|
156
156
|
* is intended to be passed alongside a `RequestInit` object when initializing
|
|
157
157
|
* an Aspi instance.
|
|
158
158
|
*/
|
|
159
|
+
type QueryParamSerializerInput = Record<string, unknown>;
|
|
160
|
+
type QueryParamSerializerResult = URLSearchParams | string | Iterable<[string, string]>;
|
|
161
|
+
type QueryParamSerializer = (params: QueryParamSerializerInput) => QueryParamSerializerResult;
|
|
159
162
|
type AspiConfigBase = {
|
|
160
163
|
/**
|
|
161
164
|
* The base URL for all Aspi requests.
|
|
@@ -165,6 +168,34 @@ type AspiConfigBase = {
|
|
|
165
168
|
* Optional retry configuration applied to all requests.
|
|
166
169
|
*/
|
|
167
170
|
retryConfig?: AspiRetryConfig<AspiRequestInit>;
|
|
171
|
+
/**
|
|
172
|
+
* Optional custom serializer for object-style query parameters passed to
|
|
173
|
+
* `setQueryParams`. Receives the parsed/validated param object and must return
|
|
174
|
+
* a value that Aspi can turn into query params (`URLSearchParams`, a query
|
|
175
|
+
* string, or an iterable of `[key, value]` tuples).
|
|
176
|
+
*
|
|
177
|
+
* When omitted, arrays are stringified using the default
|
|
178
|
+
* `URLSearchParams` behaviour (`tag=a%2Cb%2Cc`).
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* const api = new Aspi({
|
|
183
|
+
* baseUrl: 'https://api.example.com',
|
|
184
|
+
* queryParamSerializer: (params) => {
|
|
185
|
+
* const qp = new URLSearchParams();
|
|
186
|
+
* for (const [key, value] of Object.entries(params)) {
|
|
187
|
+
* if (Array.isArray(value)) {
|
|
188
|
+
* for (const item of value) qp.append(key, String(item));
|
|
189
|
+
* } else {
|
|
190
|
+
* qp.append(key, String(value));
|
|
191
|
+
* }
|
|
192
|
+
* }
|
|
193
|
+
* return qp;
|
|
194
|
+
* },
|
|
195
|
+
* });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
queryParamSerializer?: QueryParamSerializer;
|
|
168
199
|
};
|
|
169
200
|
/**
|
|
170
201
|
* Configuration for an Aspi instance (without request body).
|
|
@@ -285,6 +316,7 @@ type RequestOptions<TRequest extends AspiRequestInit> = {
|
|
|
285
316
|
errorCbs?: ErrorCallbacks;
|
|
286
317
|
throwOnError?: boolean;
|
|
287
318
|
shouldBeResult?: boolean;
|
|
319
|
+
queryParamSerializer?: QueryParamSerializer;
|
|
288
320
|
};
|
|
289
321
|
/**
|
|
290
322
|
* Record of custom error callbacks keyed by HTTP status code.
|
|
@@ -2086,4 +2118,4 @@ declare class Aspi<TRequest extends AspiRequestInit = AspiRequestInit, Opts exte
|
|
|
2086
2118
|
useCapability(capability: Capability<TRequest>): this;
|
|
2087
2119
|
}
|
|
2088
2120
|
|
|
2089
|
-
export { Aspi, type AspiConfigBase, AspiError, type AspiPlainResponse, type AspiRequest, type AspiRequestInit, type AspiRequestInitWithoutBodyAndMethod, type AspiResponse, type AspiResultOk, type AspiRetryConfig, type BaseURL, type Capability, type CapabilityArgs, CustomError, type CustomErrorCb, type ErrorCallbacks, type HttpErrorCodes, type HttpErrorStatus, type HttpMethods, type JSONParseError, type Merge, type Prettify, Request, type RequestOptions, type RequestTransformer, result as Result, type SchemaParseError, getHttpErrorStatus, httpErrors, isAspiError, isCustomError, isJSONParseError, isSchemaParseError };
|
|
2121
|
+
export { Aspi, type AspiConfigBase, AspiError, type AspiPlainResponse, type AspiRequest, type AspiRequestInit, type AspiRequestInitWithoutBodyAndMethod, type AspiResponse, type AspiResultOk, type AspiRetryConfig, type BaseURL, type Capability, type CapabilityArgs, CustomError, type CustomErrorCb, type ErrorCallbacks, type HttpErrorCodes, type HttpErrorStatus, type HttpMethods, type JSONParseError, type Merge, type Prettify, type QueryParamSerializer, type QueryParamSerializerInput, type QueryParamSerializerResult, Request, type RequestOptions, type RequestTransformer, result as Result, type SchemaParseError, getHttpErrorStatus, httpErrors, isAspiError, isCustomError, isJSONParseError, isSchemaParseError };
|
package/dist/index.js
CHANGED
|
@@ -302,6 +302,7 @@ var Request = class {
|
|
|
302
302
|
#querySchemaAsyncResult = null;
|
|
303
303
|
#querySchemaAsyncParams = null;
|
|
304
304
|
#throwOnError = false;
|
|
305
|
+
#queryParamSerializer;
|
|
305
306
|
#capabilities = [];
|
|
306
307
|
constructor(method, path, requestOptions, capabilities = []) {
|
|
307
308
|
this.#path = path;
|
|
@@ -314,6 +315,7 @@ var Request = class {
|
|
|
314
315
|
this.#customErrorCbs = { ...requestOptions?.errorCbs || {} };
|
|
315
316
|
this.#throwOnError = requestOptions.throwOnError || false;
|
|
316
317
|
this.#shouldBeResult = requestOptions.shouldBeResult || false;
|
|
318
|
+
this.#queryParamSerializer = requestOptions.queryParamSerializer;
|
|
317
319
|
this.#capabilities = [...capabilities];
|
|
318
320
|
}
|
|
319
321
|
/**
|
|
@@ -1062,6 +1064,11 @@ var Request = class {
|
|
|
1062
1064
|
return qp;
|
|
1063
1065
|
}
|
|
1064
1066
|
if (typeof value === "object" && value !== null) {
|
|
1067
|
+
if (this.#queryParamSerializer) {
|
|
1068
|
+
return this.#valueToQueryParams(
|
|
1069
|
+
this.#queryParamSerializer(value)
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1065
1072
|
const qp = new URLSearchParams();
|
|
1066
1073
|
for (const [key, val] of Object.entries(
|
|
1067
1074
|
value
|
|
@@ -1612,11 +1619,13 @@ var Aspi2 = class {
|
|
|
1612
1619
|
#customErrorCbs = {};
|
|
1613
1620
|
#throwOnError = false;
|
|
1614
1621
|
#shouldBeResult = false;
|
|
1622
|
+
#queryParamSerializer;
|
|
1615
1623
|
#capabilities = [];
|
|
1616
1624
|
constructor(config) {
|
|
1617
|
-
const { retryConfig, ...requestInit } = config;
|
|
1625
|
+
const { retryConfig, queryParamSerializer, ...requestInit } = config;
|
|
1618
1626
|
this.#globalRequestInit = requestInit;
|
|
1619
1627
|
this.#retryConfig = retryConfig;
|
|
1628
|
+
this.#queryParamSerializer = queryParamSerializer;
|
|
1620
1629
|
}
|
|
1621
1630
|
/**
|
|
1622
1631
|
* Sets or overrides the base URL used for all subsequent API requests.
|
|
@@ -1667,7 +1676,8 @@ var Aspi2 = class {
|
|
|
1667
1676
|
errorCbs: this.#customErrorCbs,
|
|
1668
1677
|
throwOnError: this.#throwOnError,
|
|
1669
1678
|
shouldBeResult: this.#shouldBeResult,
|
|
1670
|
-
retryConfig: this.#retryConfig
|
|
1679
|
+
retryConfig: this.#retryConfig,
|
|
1680
|
+
queryParamSerializer: this.#queryParamSerializer
|
|
1671
1681
|
},
|
|
1672
1682
|
this.#capabilities
|
|
1673
1683
|
);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aspi",
|
|
3
3
|
"description": "Rest API client for typescript projects with chain of responsibility design pattern.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.10.0",
|
|
5
5
|
"module": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"devDependencies": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"zod": "^3.24.1"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"typescript": "
|
|
16
|
+
"typescript": ">=5"
|
|
17
17
|
},
|
|
18
18
|
"author": {
|
|
19
19
|
"email": "harshpareek91@gmai.com",
|