aspi 2.5.0 → 2.7.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 +16 -4
- package/dist/index.d.cts +73 -64
- package/dist/index.d.ts +73 -64
- package/dist/index.js +13 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,9 @@ __export(index_exports, {
|
|
|
28
28
|
getHttpErrorStatus: () => getHttpErrorStatus,
|
|
29
29
|
httpErrors: () => httpErrors,
|
|
30
30
|
isAspiError: () => isAspiError,
|
|
31
|
-
isCustomError: () => isCustomError
|
|
31
|
+
isCustomError: () => isCustomError,
|
|
32
|
+
isJSONParseError: () => isJSONParseError,
|
|
33
|
+
isSchemaParseError: () => isSchemaParseError
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(index_exports);
|
|
34
36
|
|
|
@@ -108,6 +110,12 @@ var isAspiError = (error) => {
|
|
|
108
110
|
var isCustomError = (error) => {
|
|
109
111
|
return error instanceof CustomError;
|
|
110
112
|
};
|
|
113
|
+
var isJSONParseError = (error) => {
|
|
114
|
+
return error instanceof CustomError && error.tag === "jsonParseError";
|
|
115
|
+
};
|
|
116
|
+
var isSchemaParseError = (error) => {
|
|
117
|
+
return error instanceof CustomError && error.tag === "schemaParseError";
|
|
118
|
+
};
|
|
111
119
|
|
|
112
120
|
// src/result.ts
|
|
113
121
|
var result_exports = {};
|
|
@@ -1168,7 +1176,9 @@ var Request = class {
|
|
|
1168
1176
|
}
|
|
1169
1177
|
async #makeRequest(responseParser, isJson = false) {
|
|
1170
1178
|
if (this.#bodySchemaIssues.length) {
|
|
1171
|
-
return err(
|
|
1179
|
+
return err(
|
|
1180
|
+
new CustomError("schemaParseError", this.#bodySchemaIssues)
|
|
1181
|
+
);
|
|
1172
1182
|
}
|
|
1173
1183
|
const request = this.#request();
|
|
1174
1184
|
const { retries, retryDelay, retryOn, retryWhile, onRetry } = this.#sanitisedRetryConfig();
|
|
@@ -1307,7 +1317,7 @@ var Request = class {
|
|
|
1307
1317
|
throw new Error("Schema validation should not return a promise");
|
|
1308
1318
|
}
|
|
1309
1319
|
if (data.issues) {
|
|
1310
|
-
return err(new CustomError("
|
|
1320
|
+
return err(new CustomError("schemaParseError", data.issues));
|
|
1311
1321
|
}
|
|
1312
1322
|
return ok({
|
|
1313
1323
|
data: data.value,
|
|
@@ -1929,5 +1939,7 @@ var Aspi = class {
|
|
|
1929
1939
|
getHttpErrorStatus,
|
|
1930
1940
|
httpErrors,
|
|
1931
1941
|
isAspiError,
|
|
1932
|
-
isCustomError
|
|
1942
|
+
isCustomError,
|
|
1943
|
+
isJSONParseError,
|
|
1944
|
+
isSchemaParseError
|
|
1933
1945
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard Schema is a common interface designed to be implemented by JavaScript and TypeScript schema libraries.
|
|
3
|
+
* Will support multiple schema validators including Zod, Valibot, and ArkType
|
|
4
|
+
* https://standardschema.dev/
|
|
5
|
+
*/
|
|
6
|
+
/** The Standard Schema interface. */
|
|
7
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
8
|
+
/** The Standard Schema properties. */
|
|
9
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
10
|
+
}
|
|
11
|
+
declare namespace StandardSchemaV1 {
|
|
12
|
+
/** The Standard Schema properties interface. */
|
|
13
|
+
interface Props<Input = unknown, Output = Input> {
|
|
14
|
+
/** The version number of the standard. */
|
|
15
|
+
readonly version: 1;
|
|
16
|
+
/** The vendor name of the schema library. */
|
|
17
|
+
readonly vendor: string;
|
|
18
|
+
/** Validates unknown input values. */
|
|
19
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
20
|
+
/** Inferred types associated with the schema. */
|
|
21
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** The result interface of the validate function. */
|
|
24
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
25
|
+
/** The result interface if validation succeeds. */
|
|
26
|
+
interface SuccessResult<Output> {
|
|
27
|
+
/** The typed output value. */
|
|
28
|
+
readonly value: Output;
|
|
29
|
+
/** The non-existent issues. */
|
|
30
|
+
readonly issues?: undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The result interface if validation fails. */
|
|
33
|
+
interface FailureResult {
|
|
34
|
+
/** The issues of failed validation. */
|
|
35
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
36
|
+
}
|
|
37
|
+
/** The issue interface of the failure output. */
|
|
38
|
+
interface Issue {
|
|
39
|
+
/** The error message of the issue. */
|
|
40
|
+
readonly message: string;
|
|
41
|
+
/** The path of the issue, if any. */
|
|
42
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
43
|
+
}
|
|
44
|
+
/** The path segment interface of the issue. */
|
|
45
|
+
interface PathSegment {
|
|
46
|
+
/** The key representing a path segment. */
|
|
47
|
+
readonly key: PropertyKey;
|
|
48
|
+
}
|
|
49
|
+
/** The Standard Schema types interface. */
|
|
50
|
+
interface Types<Input = unknown, Output = Input> {
|
|
51
|
+
/** The input type of the schema. */
|
|
52
|
+
readonly input: Input;
|
|
53
|
+
/** The output type of the schema. */
|
|
54
|
+
readonly output: Output;
|
|
55
|
+
}
|
|
56
|
+
/** Infers the input type of a Standard Schema. */
|
|
57
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
58
|
+
/** Infers the output type of a Standard Schema. */
|
|
59
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
60
|
+
}
|
|
61
|
+
|
|
1
62
|
/**
|
|
2
63
|
* Standard HTTP /**
|
|
3
64
|
* Common HTTP error status codes with their numeric values.
|
|
@@ -363,8 +424,17 @@ interface JSONParseError extends CustomError<'jsonParseError', {
|
|
|
363
424
|
message: string;
|
|
364
425
|
}> {
|
|
365
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* Interface representing a schema validation error (body or response).
|
|
429
|
+
* @interface SchemaParseError
|
|
430
|
+
* @extends {CustomError<'schemaParseError', ReadonlyArray<StandardSchemaV1.Issue>>}
|
|
431
|
+
*/
|
|
432
|
+
interface SchemaParseError extends CustomError<'schemaParseError', ReadonlyArray<StandardSchemaV1.Issue>> {
|
|
433
|
+
}
|
|
366
434
|
declare const isAspiError: <TReq extends AspiRequestInit>(error: unknown) => error is AspiError<TReq>;
|
|
367
435
|
declare const isCustomError: <Tag extends string, A>(error: unknown) => error is CustomError<Tag, A>;
|
|
436
|
+
declare const isJSONParseError: (error: unknown) => error is JSONParseError;
|
|
437
|
+
declare const isSchemaParseError: (error: unknown) => error is SchemaParseError;
|
|
368
438
|
|
|
369
439
|
/**
|
|
370
440
|
* Arguments passed to a capability factory.
|
|
@@ -749,67 +819,6 @@ declare namespace result {
|
|
|
749
819
|
export { type result_Err as Err, type result_Ok as Ok, type result_Result as Result, result_catchAllErrors as catchAllErrors, result_catchError as catchError, result_catchErrors as catchErrors, result_err as err, result_getErrorOrNull as getErrorOrNull, result_getOrElse as getOrElse, result_getOrNull as getOrNull, result_getOrThrow as getOrThrow, result_getOrThrowWith as getOrThrowWith, result_isErr as isErr, result_isOk as isOk, result_map as map, result_mapErr as mapErr, result_match as match, result_ok as ok, result_pipe as pipe };
|
|
750
820
|
}
|
|
751
821
|
|
|
752
|
-
/**
|
|
753
|
-
* Standard Schema is a common interface designed to be implemented by JavaScript and TypeScript schema libraries.
|
|
754
|
-
* Will support multiple schema validators including Zod, Valibot, and ArkType
|
|
755
|
-
* https://standardschema.dev/
|
|
756
|
-
*/
|
|
757
|
-
/** The Standard Schema interface. */
|
|
758
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
759
|
-
/** The Standard Schema properties. */
|
|
760
|
-
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
761
|
-
}
|
|
762
|
-
declare namespace StandardSchemaV1 {
|
|
763
|
-
/** The Standard Schema properties interface. */
|
|
764
|
-
interface Props<Input = unknown, Output = Input> {
|
|
765
|
-
/** The version number of the standard. */
|
|
766
|
-
readonly version: 1;
|
|
767
|
-
/** The vendor name of the schema library. */
|
|
768
|
-
readonly vendor: string;
|
|
769
|
-
/** Validates unknown input values. */
|
|
770
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
771
|
-
/** Inferred types associated with the schema. */
|
|
772
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
773
|
-
}
|
|
774
|
-
/** The result interface of the validate function. */
|
|
775
|
-
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
776
|
-
/** The result interface if validation succeeds. */
|
|
777
|
-
interface SuccessResult<Output> {
|
|
778
|
-
/** The typed output value. */
|
|
779
|
-
readonly value: Output;
|
|
780
|
-
/** The non-existent issues. */
|
|
781
|
-
readonly issues?: undefined;
|
|
782
|
-
}
|
|
783
|
-
/** The result interface if validation fails. */
|
|
784
|
-
interface FailureResult {
|
|
785
|
-
/** The issues of failed validation. */
|
|
786
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
787
|
-
}
|
|
788
|
-
/** The issue interface of the failure output. */
|
|
789
|
-
interface Issue {
|
|
790
|
-
/** The error message of the issue. */
|
|
791
|
-
readonly message: string;
|
|
792
|
-
/** The path of the issue, if any. */
|
|
793
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
794
|
-
}
|
|
795
|
-
/** The path segment interface of the issue. */
|
|
796
|
-
interface PathSegment {
|
|
797
|
-
/** The key representing a path segment. */
|
|
798
|
-
readonly key: PropertyKey;
|
|
799
|
-
}
|
|
800
|
-
/** The Standard Schema types interface. */
|
|
801
|
-
interface Types<Input = unknown, Output = Input> {
|
|
802
|
-
/** The input type of the schema. */
|
|
803
|
-
readonly input: Input;
|
|
804
|
-
/** The output type of the schema. */
|
|
805
|
-
readonly output: Output;
|
|
806
|
-
}
|
|
807
|
-
/** Infers the input type of a Standard Schema. */
|
|
808
|
-
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
809
|
-
/** Infers the output type of a Standard Schema. */
|
|
810
|
-
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
811
|
-
}
|
|
812
|
-
|
|
813
822
|
/**
|
|
814
823
|
* A class for building and executing HTTP requests with customizable options and error handling.
|
|
815
824
|
* @template Method The HTTP method type (GET, POST, etc.)
|
|
@@ -930,7 +939,7 @@ declare class Request<Method extends HttpMethods, TRequest extends AspiRequestIn
|
|
|
930
939
|
bodySchema<TSchema extends StandardSchemaV1>(schema: TSchema): Request<Method, TRequest, Omit<Opts, "bodySchema"> & {
|
|
931
940
|
bodySchema: TSchema;
|
|
932
941
|
error: Opts["error"] & {
|
|
933
|
-
|
|
942
|
+
schemaParseError: CustomError<"schemaParseError", StandardSchemaV1.FailureResult["issues"]>;
|
|
934
943
|
};
|
|
935
944
|
}>;
|
|
936
945
|
/**
|
|
@@ -1202,7 +1211,7 @@ declare class Request<Method extends HttpMethods, TRequest extends AspiRequestIn
|
|
|
1202
1211
|
schema<TSchema extends StandardSchemaV1>(schema: TSchema): Request<Method, TRequest, Merge<Omit<Opts, "schema">, {
|
|
1203
1212
|
schema: TSchema;
|
|
1204
1213
|
error: Merge<Opts["error"], {
|
|
1205
|
-
|
|
1214
|
+
schemaParseError: CustomError<"schemaParseError", StandardSchemaV1.FailureResult["issues"]>;
|
|
1206
1215
|
}>;
|
|
1207
1216
|
}>>;
|
|
1208
1217
|
/**
|
|
@@ -1998,4 +2007,4 @@ declare class Aspi<TRequest extends AspiRequestInit = AspiRequestInit, Opts exte
|
|
|
1998
2007
|
useCapability(capability: Capability<TRequest>): this;
|
|
1999
2008
|
}
|
|
2000
2009
|
|
|
2001
|
-
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, getHttpErrorStatus, httpErrors, isAspiError, isCustomError };
|
|
2010
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard Schema is a common interface designed to be implemented by JavaScript and TypeScript schema libraries.
|
|
3
|
+
* Will support multiple schema validators including Zod, Valibot, and ArkType
|
|
4
|
+
* https://standardschema.dev/
|
|
5
|
+
*/
|
|
6
|
+
/** The Standard Schema interface. */
|
|
7
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
8
|
+
/** The Standard Schema properties. */
|
|
9
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
10
|
+
}
|
|
11
|
+
declare namespace StandardSchemaV1 {
|
|
12
|
+
/** The Standard Schema properties interface. */
|
|
13
|
+
interface Props<Input = unknown, Output = Input> {
|
|
14
|
+
/** The version number of the standard. */
|
|
15
|
+
readonly version: 1;
|
|
16
|
+
/** The vendor name of the schema library. */
|
|
17
|
+
readonly vendor: string;
|
|
18
|
+
/** Validates unknown input values. */
|
|
19
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
20
|
+
/** Inferred types associated with the schema. */
|
|
21
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** The result interface of the validate function. */
|
|
24
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
25
|
+
/** The result interface if validation succeeds. */
|
|
26
|
+
interface SuccessResult<Output> {
|
|
27
|
+
/** The typed output value. */
|
|
28
|
+
readonly value: Output;
|
|
29
|
+
/** The non-existent issues. */
|
|
30
|
+
readonly issues?: undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The result interface if validation fails. */
|
|
33
|
+
interface FailureResult {
|
|
34
|
+
/** The issues of failed validation. */
|
|
35
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
36
|
+
}
|
|
37
|
+
/** The issue interface of the failure output. */
|
|
38
|
+
interface Issue {
|
|
39
|
+
/** The error message of the issue. */
|
|
40
|
+
readonly message: string;
|
|
41
|
+
/** The path of the issue, if any. */
|
|
42
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
43
|
+
}
|
|
44
|
+
/** The path segment interface of the issue. */
|
|
45
|
+
interface PathSegment {
|
|
46
|
+
/** The key representing a path segment. */
|
|
47
|
+
readonly key: PropertyKey;
|
|
48
|
+
}
|
|
49
|
+
/** The Standard Schema types interface. */
|
|
50
|
+
interface Types<Input = unknown, Output = Input> {
|
|
51
|
+
/** The input type of the schema. */
|
|
52
|
+
readonly input: Input;
|
|
53
|
+
/** The output type of the schema. */
|
|
54
|
+
readonly output: Output;
|
|
55
|
+
}
|
|
56
|
+
/** Infers the input type of a Standard Schema. */
|
|
57
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
58
|
+
/** Infers the output type of a Standard Schema. */
|
|
59
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
60
|
+
}
|
|
61
|
+
|
|
1
62
|
/**
|
|
2
63
|
* Standard HTTP /**
|
|
3
64
|
* Common HTTP error status codes with their numeric values.
|
|
@@ -363,8 +424,17 @@ interface JSONParseError extends CustomError<'jsonParseError', {
|
|
|
363
424
|
message: string;
|
|
364
425
|
}> {
|
|
365
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* Interface representing a schema validation error (body or response).
|
|
429
|
+
* @interface SchemaParseError
|
|
430
|
+
* @extends {CustomError<'schemaParseError', ReadonlyArray<StandardSchemaV1.Issue>>}
|
|
431
|
+
*/
|
|
432
|
+
interface SchemaParseError extends CustomError<'schemaParseError', ReadonlyArray<StandardSchemaV1.Issue>> {
|
|
433
|
+
}
|
|
366
434
|
declare const isAspiError: <TReq extends AspiRequestInit>(error: unknown) => error is AspiError<TReq>;
|
|
367
435
|
declare const isCustomError: <Tag extends string, A>(error: unknown) => error is CustomError<Tag, A>;
|
|
436
|
+
declare const isJSONParseError: (error: unknown) => error is JSONParseError;
|
|
437
|
+
declare const isSchemaParseError: (error: unknown) => error is SchemaParseError;
|
|
368
438
|
|
|
369
439
|
/**
|
|
370
440
|
* Arguments passed to a capability factory.
|
|
@@ -749,67 +819,6 @@ declare namespace result {
|
|
|
749
819
|
export { type result_Err as Err, type result_Ok as Ok, type result_Result as Result, result_catchAllErrors as catchAllErrors, result_catchError as catchError, result_catchErrors as catchErrors, result_err as err, result_getErrorOrNull as getErrorOrNull, result_getOrElse as getOrElse, result_getOrNull as getOrNull, result_getOrThrow as getOrThrow, result_getOrThrowWith as getOrThrowWith, result_isErr as isErr, result_isOk as isOk, result_map as map, result_mapErr as mapErr, result_match as match, result_ok as ok, result_pipe as pipe };
|
|
750
820
|
}
|
|
751
821
|
|
|
752
|
-
/**
|
|
753
|
-
* Standard Schema is a common interface designed to be implemented by JavaScript and TypeScript schema libraries.
|
|
754
|
-
* Will support multiple schema validators including Zod, Valibot, and ArkType
|
|
755
|
-
* https://standardschema.dev/
|
|
756
|
-
*/
|
|
757
|
-
/** The Standard Schema interface. */
|
|
758
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
759
|
-
/** The Standard Schema properties. */
|
|
760
|
-
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
761
|
-
}
|
|
762
|
-
declare namespace StandardSchemaV1 {
|
|
763
|
-
/** The Standard Schema properties interface. */
|
|
764
|
-
interface Props<Input = unknown, Output = Input> {
|
|
765
|
-
/** The version number of the standard. */
|
|
766
|
-
readonly version: 1;
|
|
767
|
-
/** The vendor name of the schema library. */
|
|
768
|
-
readonly vendor: string;
|
|
769
|
-
/** Validates unknown input values. */
|
|
770
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
771
|
-
/** Inferred types associated with the schema. */
|
|
772
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
773
|
-
}
|
|
774
|
-
/** The result interface of the validate function. */
|
|
775
|
-
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
776
|
-
/** The result interface if validation succeeds. */
|
|
777
|
-
interface SuccessResult<Output> {
|
|
778
|
-
/** The typed output value. */
|
|
779
|
-
readonly value: Output;
|
|
780
|
-
/** The non-existent issues. */
|
|
781
|
-
readonly issues?: undefined;
|
|
782
|
-
}
|
|
783
|
-
/** The result interface if validation fails. */
|
|
784
|
-
interface FailureResult {
|
|
785
|
-
/** The issues of failed validation. */
|
|
786
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
787
|
-
}
|
|
788
|
-
/** The issue interface of the failure output. */
|
|
789
|
-
interface Issue {
|
|
790
|
-
/** The error message of the issue. */
|
|
791
|
-
readonly message: string;
|
|
792
|
-
/** The path of the issue, if any. */
|
|
793
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
794
|
-
}
|
|
795
|
-
/** The path segment interface of the issue. */
|
|
796
|
-
interface PathSegment {
|
|
797
|
-
/** The key representing a path segment. */
|
|
798
|
-
readonly key: PropertyKey;
|
|
799
|
-
}
|
|
800
|
-
/** The Standard Schema types interface. */
|
|
801
|
-
interface Types<Input = unknown, Output = Input> {
|
|
802
|
-
/** The input type of the schema. */
|
|
803
|
-
readonly input: Input;
|
|
804
|
-
/** The output type of the schema. */
|
|
805
|
-
readonly output: Output;
|
|
806
|
-
}
|
|
807
|
-
/** Infers the input type of a Standard Schema. */
|
|
808
|
-
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
809
|
-
/** Infers the output type of a Standard Schema. */
|
|
810
|
-
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
811
|
-
}
|
|
812
|
-
|
|
813
822
|
/**
|
|
814
823
|
* A class for building and executing HTTP requests with customizable options and error handling.
|
|
815
824
|
* @template Method The HTTP method type (GET, POST, etc.)
|
|
@@ -930,7 +939,7 @@ declare class Request<Method extends HttpMethods, TRequest extends AspiRequestIn
|
|
|
930
939
|
bodySchema<TSchema extends StandardSchemaV1>(schema: TSchema): Request<Method, TRequest, Omit<Opts, "bodySchema"> & {
|
|
931
940
|
bodySchema: TSchema;
|
|
932
941
|
error: Opts["error"] & {
|
|
933
|
-
|
|
942
|
+
schemaParseError: CustomError<"schemaParseError", StandardSchemaV1.FailureResult["issues"]>;
|
|
934
943
|
};
|
|
935
944
|
}>;
|
|
936
945
|
/**
|
|
@@ -1202,7 +1211,7 @@ declare class Request<Method extends HttpMethods, TRequest extends AspiRequestIn
|
|
|
1202
1211
|
schema<TSchema extends StandardSchemaV1>(schema: TSchema): Request<Method, TRequest, Merge<Omit<Opts, "schema">, {
|
|
1203
1212
|
schema: TSchema;
|
|
1204
1213
|
error: Merge<Opts["error"], {
|
|
1205
|
-
|
|
1214
|
+
schemaParseError: CustomError<"schemaParseError", StandardSchemaV1.FailureResult["issues"]>;
|
|
1206
1215
|
}>;
|
|
1207
1216
|
}>>;
|
|
1208
1217
|
/**
|
|
@@ -1998,4 +2007,4 @@ declare class Aspi<TRequest extends AspiRequestInit = AspiRequestInit, Opts exte
|
|
|
1998
2007
|
useCapability(capability: Capability<TRequest>): this;
|
|
1999
2008
|
}
|
|
2000
2009
|
|
|
2001
|
-
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, getHttpErrorStatus, httpErrors, isAspiError, isCustomError };
|
|
2010
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -80,6 +80,12 @@ var isAspiError = (error) => {
|
|
|
80
80
|
var isCustomError = (error) => {
|
|
81
81
|
return error instanceof CustomError;
|
|
82
82
|
};
|
|
83
|
+
var isJSONParseError = (error) => {
|
|
84
|
+
return error instanceof CustomError && error.tag === "jsonParseError";
|
|
85
|
+
};
|
|
86
|
+
var isSchemaParseError = (error) => {
|
|
87
|
+
return error instanceof CustomError && error.tag === "schemaParseError";
|
|
88
|
+
};
|
|
83
89
|
|
|
84
90
|
// src/result.ts
|
|
85
91
|
var result_exports = {};
|
|
@@ -1140,7 +1146,9 @@ var Request = class {
|
|
|
1140
1146
|
}
|
|
1141
1147
|
async #makeRequest(responseParser, isJson = false) {
|
|
1142
1148
|
if (this.#bodySchemaIssues.length) {
|
|
1143
|
-
return err(
|
|
1149
|
+
return err(
|
|
1150
|
+
new CustomError("schemaParseError", this.#bodySchemaIssues)
|
|
1151
|
+
);
|
|
1144
1152
|
}
|
|
1145
1153
|
const request = this.#request();
|
|
1146
1154
|
const { retries, retryDelay, retryOn, retryWhile, onRetry } = this.#sanitisedRetryConfig();
|
|
@@ -1279,7 +1287,7 @@ var Request = class {
|
|
|
1279
1287
|
throw new Error("Schema validation should not return a promise");
|
|
1280
1288
|
}
|
|
1281
1289
|
if (data.issues) {
|
|
1282
|
-
return err(new CustomError("
|
|
1290
|
+
return err(new CustomError("schemaParseError", data.issues));
|
|
1283
1291
|
}
|
|
1284
1292
|
return ok({
|
|
1285
1293
|
data: data.value,
|
|
@@ -1900,5 +1908,7 @@ export {
|
|
|
1900
1908
|
getHttpErrorStatus,
|
|
1901
1909
|
httpErrors,
|
|
1902
1910
|
isAspiError,
|
|
1903
|
-
isCustomError
|
|
1911
|
+
isCustomError,
|
|
1912
|
+
isJSONParseError,
|
|
1913
|
+
isSchemaParseError
|
|
1904
1914
|
};
|
package/package.json
CHANGED