@zayne-labs/callapi-plugins 4.0.41 → 4.0.43
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyFunction } from "@zayne-labs/toolkit-type-helpers";
|
|
2
2
|
|
|
3
|
-
//#region ../callapi/dist/index-
|
|
3
|
+
//#region ../callapi/dist/index-UfuQFNcf.d.ts
|
|
4
4
|
//#region src/constants/common.d.ts
|
|
5
5
|
declare const fetchSpecificKeys: readonly (keyof RequestInit | "duplex")[];
|
|
6
6
|
//#endregion
|
|
@@ -993,11 +993,11 @@ type ResultModeOption<TErrorData, TResultMode extends ResultModeType> = TErrorDa
|
|
|
993
993
|
} : {
|
|
994
994
|
resultMode?: TResultMode;
|
|
995
995
|
};
|
|
996
|
-
type
|
|
997
|
-
type ThrowOnErrorType<TErrorData, TThrowOnError extends
|
|
996
|
+
type ThrowOnErrorBoolean = boolean;
|
|
997
|
+
type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorBoolean> = TThrowOnError | ((context: ErrorContext<{
|
|
998
998
|
ErrorData: TErrorData;
|
|
999
999
|
}>) => TThrowOnError);
|
|
1000
|
-
type ThrowOnErrorOption<TErrorData, TThrowOnError extends
|
|
1000
|
+
type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorBoolean> = TErrorData extends false ? {
|
|
1001
1001
|
throwOnError: true;
|
|
1002
1002
|
} : TErrorData extends false | undefined ? {
|
|
1003
1003
|
throwOnError?: true;
|
|
@@ -1145,9 +1145,9 @@ type CallApiRequestOptions = {
|
|
|
1145
1145
|
method?: MethodUnion;
|
|
1146
1146
|
} & Pick<ModifiedRequestInit, FetchSpecificKeysUnion>;
|
|
1147
1147
|
type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
|
|
1148
|
-
headers: Record<
|
|
1148
|
+
headers: Record<"Authorization" | "Content-Type" | CommonRequestHeaders, string | undefined>;
|
|
1149
1149
|
};
|
|
1150
|
-
type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends
|
|
1150
|
+
type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedMergedPluginExtraOptions = Partial<InferPluginExtraOptions<TPluginArray> & InferSchemaOutput<TCallApiContext["InferredExtraOptions"], TCallApiContext["InferredExtraOptions"]>>, TComputedCallApiContext extends CallApiContext = OverrideCallApiContext<TCallApiContext, {
|
|
1151
1151
|
Data: TData;
|
|
1152
1152
|
ErrorData: TErrorData;
|
|
1153
1153
|
InferredExtraOptions: TComputedMergedPluginExtraOptions;
|
|
@@ -1399,58 +1399,23 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiC
|
|
|
1399
1399
|
*/
|
|
1400
1400
|
responseType?: TResponseType;
|
|
1401
1401
|
/**
|
|
1402
|
-
*
|
|
1402
|
+
* Dictates how CallApi processes and returns the final result
|
|
1403
1403
|
*
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1404
|
+
- **"all"** (default): Returns `{ data, error, response }`. Standard lifecycle.
|
|
1405
|
+
- **"onlyData"**: Returns only the data from the response.
|
|
1406
|
+
- **"onlyResponse"**: Returns only the `Response` object.
|
|
1407
|
+
- **"fetchApi"**: Also returns only the `Response` object, but also skips parsing of the response body internally and data/errorData schema validation.
|
|
1408
|
+
- **"withoutResponse"**: Returns `{ data, error }`. Standard lifecycle, but omits the `response` property.
|
|
1407
1409
|
*
|
|
1408
|
-
* When combined with throwOnError: true, null/error variants are automatically removed:
|
|
1409
|
-
* - **"all" + throwOnError: true**: Returns { data, error: null, response } (error property is null, throws instead)
|
|
1410
|
-
* - **"onlyData" + throwOnError: true**: Returns data (never null, throws on error)
|
|
1411
1410
|
*
|
|
1412
|
-
*
|
|
1411
|
+
* **Note:**
|
|
1412
|
+
* By default, simplified modes (`"onlyData"`, `"onlyResponse"`, `"fetchApi"`) do not throw errors.
|
|
1413
|
+
* Success/failure should be handled via hooks or by checking the return value (e.g., `if (data)` or `if (response?.ok)`).
|
|
1414
|
+
* To force an exception instead, set `throwOnError: true`.
|
|
1413
1415
|
*
|
|
1414
|
-
* @example
|
|
1415
|
-
* ```ts
|
|
1416
|
-
* // Complete result with all information (default)
|
|
1417
|
-
* const { data, error, response } = await callApi("/users", { resultMode: "all" });
|
|
1418
|
-
* if (error) {
|
|
1419
|
-
* console.error("Request failed:", error);
|
|
1420
|
-
* } else {
|
|
1421
|
-
* console.log("Users:", data);
|
|
1422
|
-
* }
|
|
1423
1416
|
*
|
|
1424
|
-
*
|
|
1425
|
-
* try {
|
|
1426
|
-
* const { data, response } = await callApi("/users", {
|
|
1427
|
-
* resultMode: "all",
|
|
1428
|
-
* throwOnError: true
|
|
1429
|
-
* });
|
|
1430
|
-
* console.log("Users:", data); // data is never null here
|
|
1431
|
-
* } catch (error) {
|
|
1432
|
-
* console.error("Request failed:", error);
|
|
1433
|
-
* }
|
|
1434
|
-
*
|
|
1435
|
-
* // Only data, returns null on errors
|
|
1436
|
-
* const users = await callApi("/users", { resultMode: "onlyData" });
|
|
1437
|
-
* if (users) {
|
|
1438
|
-
* console.log("Users:", users);
|
|
1439
|
-
* } else {
|
|
1440
|
-
* console.log("Request failed");
|
|
1441
|
-
* }
|
|
1417
|
+
* @default "all"
|
|
1442
1418
|
*
|
|
1443
|
-
* // Only data, throws on errors (throwOnError removes null from type)
|
|
1444
|
-
* try {
|
|
1445
|
-
* const users = await callApi("/users", {
|
|
1446
|
-
* resultMode: "onlyData",
|
|
1447
|
-
* throwOnError: true
|
|
1448
|
-
* });
|
|
1449
|
-
* console.log("Users:", users); // users is never null here
|
|
1450
|
-
* } catch (error) {
|
|
1451
|
-
* console.error("Request failed:", error);
|
|
1452
|
-
* }
|
|
1453
|
-
* ```
|
|
1454
1419
|
*/
|
|
1455
1420
|
resultMode?: TResultMode;
|
|
1456
1421
|
/**
|
|
@@ -1523,7 +1488,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiC
|
|
|
1523
1488
|
*/
|
|
1524
1489
|
timeout?: number;
|
|
1525
1490
|
};
|
|
1526
|
-
type BaseCallApiExtraOptions<TBaseCallApiContext extends CallApiContext = DefaultCallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends
|
|
1491
|
+
type BaseCallApiExtraOptions<TBaseCallApiContext extends CallApiContext = DefaultCallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
|
|
1527
1492
|
/**
|
|
1528
1493
|
* Array of base CallApi plugins to extend library functionality.
|
|
1529
1494
|
*
|
|
@@ -1634,7 +1599,7 @@ type GetExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfig>
|
|
|
1634
1599
|
type InferExtendPluginContext<TBasePluginArray extends CallApiPlugin[]> = {
|
|
1635
1600
|
basePlugins: TBasePluginArray;
|
|
1636
1601
|
};
|
|
1637
|
-
type CallApiExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends
|
|
1602
|
+
type CallApiExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string> = SharedExtraOptions<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1638
1603
|
/**
|
|
1639
1604
|
* Array of instance-specific CallApi plugins or a function to configure plugins.
|
|
1640
1605
|
*
|
|
@@ -1668,8 +1633,8 @@ type InstanceContext = {
|
|
|
1668
1633
|
options: CallApiExtraOptions;
|
|
1669
1634
|
request: CallApiRequestOptions;
|
|
1670
1635
|
};
|
|
1671
|
-
type BaseCallApiConfig<TBaseCallApiContext extends CallApiContext = DefaultCallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends
|
|
1672
|
-
type CallApiConfig<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends
|
|
1636
|
+
type BaseCallApiConfig<TBaseCallApiContext extends CallApiContext = DefaultCallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
|
|
1637
|
+
type CallApiConfig<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey, TCallApiContext> & InferRequestOptions<TSchema, TInitURL> & Omit<CallApiExtraOptions<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string, CallApiContext>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
1673
1638
|
//#endregion
|
|
1674
1639
|
//#region src/result.d.ts
|
|
1675
1640
|
type ResponseParser<TData> = (text: string) => Awaitable<TData>;
|
|
@@ -1723,8 +1688,10 @@ type CallApiResultErrorVariant<TErrorData> = {
|
|
|
1723
1688
|
response: Response | null;
|
|
1724
1689
|
};
|
|
1725
1690
|
type CallApiResultSuccessOrErrorVariant<TData, TError> = CallApiResultErrorVariant<TError> | CallApiResultSuccessVariant<TData>;
|
|
1726
|
-
type
|
|
1691
|
+
type GetCallApiResult<TThrowOnError extends ThrowOnErrorBoolean, TResultWithException extends CallApiResultSuccessVariant<unknown>, TResultWithoutException extends CallApiResultSuccessOrErrorVariant<unknown, unknown>> = TThrowOnError extends true ? TResultWithException : TResultWithoutException;
|
|
1692
|
+
type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TComputedResult extends GetCallApiResult<TThrowOnError, CallApiResultSuccessVariant<TData>, CallApiResultSuccessOrErrorVariant<TData, TErrorData>> = GetCallApiResult<TThrowOnError, CallApiResultSuccessVariant<TData>, CallApiResultSuccessOrErrorVariant<TData, TErrorData>>> = UnmaskType<{
|
|
1727
1693
|
all: TComputedResult;
|
|
1694
|
+
fetchApi: TComputedResult["response"];
|
|
1728
1695
|
onlyData: TComputedResult["data"];
|
|
1729
1696
|
onlyResponse: TComputedResult["response"];
|
|
1730
1697
|
withoutResponse: Prettify<DistributiveOmit<TComputedResult, "response">>;
|
|
@@ -1925,4 +1892,4 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
|
|
|
1925
1892
|
};
|
|
1926
1893
|
//#endregion
|
|
1927
1894
|
export { defaultConsoleObject as n, loggerPlugin as r, LoggerOptions as t };
|
|
1928
|
-
//# sourceMappingURL=index-
|
|
1895
|
+
//# sourceMappingURL=index-C01h-7d8.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "./index-
|
|
1
|
+
import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "./index-C01h-7d8.js";
|
|
2
2
|
export { LoggerOptions, defaultConsoleObject, loggerPlugin };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "../../index-
|
|
1
|
+
import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "../../index-C01h-7d8.js";
|
|
2
2
|
export { LoggerOptions, defaultConsoleObject, loggerPlugin };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/callapi-plugins",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.43",
|
|
5
5
|
"description": "A collection of plugins for callapi",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@zayne-labs/toolkit-type-helpers": ">=0.11.17",
|
|
26
26
|
"consola": "3.x.x",
|
|
27
|
-
"@zayne-labs/callapi": "1.11.
|
|
27
|
+
"@zayne-labs/callapi": "1.11.43"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@arethetypeswrong/cli": "0.18.2",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"tsdown": "0.19.0-beta.3",
|
|
42
42
|
"typescript": "5.9.3",
|
|
43
43
|
"vitest": "^4.0.16",
|
|
44
|
-
"@zayne-labs/callapi": "1.11.
|
|
44
|
+
"@zayne-labs/callapi": "1.11.43"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public",
|