aspi 2.6.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 +9 -7
- package/dist/index.d.cts +70 -68
- package/dist/index.d.ts +70 -68
- package/dist/index.js +8 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,7 @@ __export(index_exports, {
|
|
|
30
30
|
isAspiError: () => isAspiError,
|
|
31
31
|
isCustomError: () => isCustomError,
|
|
32
32
|
isJSONParseError: () => isJSONParseError,
|
|
33
|
-
|
|
33
|
+
isSchemaParseError: () => isSchemaParseError
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
@@ -110,12 +110,12 @@ var isAspiError = (error) => {
|
|
|
110
110
|
var isCustomError = (error) => {
|
|
111
111
|
return error instanceof CustomError;
|
|
112
112
|
};
|
|
113
|
-
var isParseError = (error) => {
|
|
114
|
-
return error instanceof CustomError && error.tag === "parseError";
|
|
115
|
-
};
|
|
116
113
|
var isJSONParseError = (error) => {
|
|
117
114
|
return error instanceof CustomError && error.tag === "jsonParseError";
|
|
118
115
|
};
|
|
116
|
+
var isSchemaParseError = (error) => {
|
|
117
|
+
return error instanceof CustomError && error.tag === "schemaParseError";
|
|
118
|
+
};
|
|
119
119
|
|
|
120
120
|
// src/result.ts
|
|
121
121
|
var result_exports = {};
|
|
@@ -1176,7 +1176,9 @@ var Request = class {
|
|
|
1176
1176
|
}
|
|
1177
1177
|
async #makeRequest(responseParser, isJson = false) {
|
|
1178
1178
|
if (this.#bodySchemaIssues.length) {
|
|
1179
|
-
return err(
|
|
1179
|
+
return err(
|
|
1180
|
+
new CustomError("schemaParseError", this.#bodySchemaIssues)
|
|
1181
|
+
);
|
|
1180
1182
|
}
|
|
1181
1183
|
const request = this.#request();
|
|
1182
1184
|
const { retries, retryDelay, retryOn, retryWhile, onRetry } = this.#sanitisedRetryConfig();
|
|
@@ -1315,7 +1317,7 @@ var Request = class {
|
|
|
1315
1317
|
throw new Error("Schema validation should not return a promise");
|
|
1316
1318
|
}
|
|
1317
1319
|
if (data.issues) {
|
|
1318
|
-
return err(new CustomError("
|
|
1320
|
+
return err(new CustomError("schemaParseError", data.issues));
|
|
1319
1321
|
}
|
|
1320
1322
|
return ok({
|
|
1321
1323
|
data: data.value,
|
|
@@ -1939,5 +1941,5 @@ var Aspi = class {
|
|
|
1939
1941
|
isAspiError,
|
|
1940
1942
|
isCustomError,
|
|
1941
1943
|
isJSONParseError,
|
|
1942
|
-
|
|
1944
|
+
isSchemaParseError
|
|
1943
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.
|
|
@@ -364,14 +425,16 @@ interface JSONParseError extends CustomError<'jsonParseError', {
|
|
|
364
425
|
}> {
|
|
365
426
|
}
|
|
366
427
|
/**
|
|
367
|
-
*
|
|
368
|
-
*
|
|
428
|
+
* Interface representing a schema validation error (body or response).
|
|
429
|
+
* @interface SchemaParseError
|
|
430
|
+
* @extends {CustomError<'schemaParseError', ReadonlyArray<StandardSchemaV1.Issue>>}
|
|
369
431
|
*/
|
|
370
|
-
|
|
432
|
+
interface SchemaParseError extends CustomError<'schemaParseError', ReadonlyArray<StandardSchemaV1.Issue>> {
|
|
433
|
+
}
|
|
371
434
|
declare const isAspiError: <TReq extends AspiRequestInit>(error: unknown) => error is AspiError<TReq>;
|
|
372
435
|
declare const isCustomError: <Tag extends string, A>(error: unknown) => error is CustomError<Tag, A>;
|
|
373
|
-
declare const isParseError: (error: unknown) => error is ParseError;
|
|
374
436
|
declare const isJSONParseError: (error: unknown) => error is JSONParseError;
|
|
437
|
+
declare const isSchemaParseError: (error: unknown) => error is SchemaParseError;
|
|
375
438
|
|
|
376
439
|
/**
|
|
377
440
|
* Arguments passed to a capability factory.
|
|
@@ -756,67 +819,6 @@ declare namespace result {
|
|
|
756
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 };
|
|
757
820
|
}
|
|
758
821
|
|
|
759
|
-
/**
|
|
760
|
-
* Standard Schema is a common interface designed to be implemented by JavaScript and TypeScript schema libraries.
|
|
761
|
-
* Will support multiple schema validators including Zod, Valibot, and ArkType
|
|
762
|
-
* https://standardschema.dev/
|
|
763
|
-
*/
|
|
764
|
-
/** The Standard Schema interface. */
|
|
765
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
766
|
-
/** The Standard Schema properties. */
|
|
767
|
-
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
768
|
-
}
|
|
769
|
-
declare namespace StandardSchemaV1 {
|
|
770
|
-
/** The Standard Schema properties interface. */
|
|
771
|
-
interface Props<Input = unknown, Output = Input> {
|
|
772
|
-
/** The version number of the standard. */
|
|
773
|
-
readonly version: 1;
|
|
774
|
-
/** The vendor name of the schema library. */
|
|
775
|
-
readonly vendor: string;
|
|
776
|
-
/** Validates unknown input values. */
|
|
777
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
778
|
-
/** Inferred types associated with the schema. */
|
|
779
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
780
|
-
}
|
|
781
|
-
/** The result interface of the validate function. */
|
|
782
|
-
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
783
|
-
/** The result interface if validation succeeds. */
|
|
784
|
-
interface SuccessResult<Output> {
|
|
785
|
-
/** The typed output value. */
|
|
786
|
-
readonly value: Output;
|
|
787
|
-
/** The non-existent issues. */
|
|
788
|
-
readonly issues?: undefined;
|
|
789
|
-
}
|
|
790
|
-
/** The result interface if validation fails. */
|
|
791
|
-
interface FailureResult {
|
|
792
|
-
/** The issues of failed validation. */
|
|
793
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
794
|
-
}
|
|
795
|
-
/** The issue interface of the failure output. */
|
|
796
|
-
interface Issue {
|
|
797
|
-
/** The error message of the issue. */
|
|
798
|
-
readonly message: string;
|
|
799
|
-
/** The path of the issue, if any. */
|
|
800
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
801
|
-
}
|
|
802
|
-
/** The path segment interface of the issue. */
|
|
803
|
-
interface PathSegment {
|
|
804
|
-
/** The key representing a path segment. */
|
|
805
|
-
readonly key: PropertyKey;
|
|
806
|
-
}
|
|
807
|
-
/** The Standard Schema types interface. */
|
|
808
|
-
interface Types<Input = unknown, Output = Input> {
|
|
809
|
-
/** The input type of the schema. */
|
|
810
|
-
readonly input: Input;
|
|
811
|
-
/** The output type of the schema. */
|
|
812
|
-
readonly output: Output;
|
|
813
|
-
}
|
|
814
|
-
/** Infers the input type of a Standard Schema. */
|
|
815
|
-
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
816
|
-
/** Infers the output type of a Standard Schema. */
|
|
817
|
-
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
818
|
-
}
|
|
819
|
-
|
|
820
822
|
/**
|
|
821
823
|
* A class for building and executing HTTP requests with customizable options and error handling.
|
|
822
824
|
* @template Method The HTTP method type (GET, POST, etc.)
|
|
@@ -937,7 +939,7 @@ declare class Request<Method extends HttpMethods, TRequest extends AspiRequestIn
|
|
|
937
939
|
bodySchema<TSchema extends StandardSchemaV1>(schema: TSchema): Request<Method, TRequest, Omit<Opts, "bodySchema"> & {
|
|
938
940
|
bodySchema: TSchema;
|
|
939
941
|
error: Opts["error"] & {
|
|
940
|
-
|
|
942
|
+
schemaParseError: CustomError<"schemaParseError", StandardSchemaV1.FailureResult["issues"]>;
|
|
941
943
|
};
|
|
942
944
|
}>;
|
|
943
945
|
/**
|
|
@@ -1209,7 +1211,7 @@ declare class Request<Method extends HttpMethods, TRequest extends AspiRequestIn
|
|
|
1209
1211
|
schema<TSchema extends StandardSchemaV1>(schema: TSchema): Request<Method, TRequest, Merge<Omit<Opts, "schema">, {
|
|
1210
1212
|
schema: TSchema;
|
|
1211
1213
|
error: Merge<Opts["error"], {
|
|
1212
|
-
|
|
1214
|
+
schemaParseError: CustomError<"schemaParseError", StandardSchemaV1.FailureResult["issues"]>;
|
|
1213
1215
|
}>;
|
|
1214
1216
|
}>>;
|
|
1215
1217
|
/**
|
|
@@ -2005,4 +2007,4 @@ declare class Aspi<TRequest extends AspiRequestInit = AspiRequestInit, Opts exte
|
|
|
2005
2007
|
useCapability(capability: Capability<TRequest>): this;
|
|
2006
2008
|
}
|
|
2007
2009
|
|
|
2008
|
-
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
|
|
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.
|
|
@@ -364,14 +425,16 @@ interface JSONParseError extends CustomError<'jsonParseError', {
|
|
|
364
425
|
}> {
|
|
365
426
|
}
|
|
366
427
|
/**
|
|
367
|
-
*
|
|
368
|
-
*
|
|
428
|
+
* Interface representing a schema validation error (body or response).
|
|
429
|
+
* @interface SchemaParseError
|
|
430
|
+
* @extends {CustomError<'schemaParseError', ReadonlyArray<StandardSchemaV1.Issue>>}
|
|
369
431
|
*/
|
|
370
|
-
|
|
432
|
+
interface SchemaParseError extends CustomError<'schemaParseError', ReadonlyArray<StandardSchemaV1.Issue>> {
|
|
433
|
+
}
|
|
371
434
|
declare const isAspiError: <TReq extends AspiRequestInit>(error: unknown) => error is AspiError<TReq>;
|
|
372
435
|
declare const isCustomError: <Tag extends string, A>(error: unknown) => error is CustomError<Tag, A>;
|
|
373
|
-
declare const isParseError: (error: unknown) => error is ParseError;
|
|
374
436
|
declare const isJSONParseError: (error: unknown) => error is JSONParseError;
|
|
437
|
+
declare const isSchemaParseError: (error: unknown) => error is SchemaParseError;
|
|
375
438
|
|
|
376
439
|
/**
|
|
377
440
|
* Arguments passed to a capability factory.
|
|
@@ -756,67 +819,6 @@ declare namespace result {
|
|
|
756
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 };
|
|
757
820
|
}
|
|
758
821
|
|
|
759
|
-
/**
|
|
760
|
-
* Standard Schema is a common interface designed to be implemented by JavaScript and TypeScript schema libraries.
|
|
761
|
-
* Will support multiple schema validators including Zod, Valibot, and ArkType
|
|
762
|
-
* https://standardschema.dev/
|
|
763
|
-
*/
|
|
764
|
-
/** The Standard Schema interface. */
|
|
765
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
766
|
-
/** The Standard Schema properties. */
|
|
767
|
-
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
768
|
-
}
|
|
769
|
-
declare namespace StandardSchemaV1 {
|
|
770
|
-
/** The Standard Schema properties interface. */
|
|
771
|
-
interface Props<Input = unknown, Output = Input> {
|
|
772
|
-
/** The version number of the standard. */
|
|
773
|
-
readonly version: 1;
|
|
774
|
-
/** The vendor name of the schema library. */
|
|
775
|
-
readonly vendor: string;
|
|
776
|
-
/** Validates unknown input values. */
|
|
777
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
778
|
-
/** Inferred types associated with the schema. */
|
|
779
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
780
|
-
}
|
|
781
|
-
/** The result interface of the validate function. */
|
|
782
|
-
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
783
|
-
/** The result interface if validation succeeds. */
|
|
784
|
-
interface SuccessResult<Output> {
|
|
785
|
-
/** The typed output value. */
|
|
786
|
-
readonly value: Output;
|
|
787
|
-
/** The non-existent issues. */
|
|
788
|
-
readonly issues?: undefined;
|
|
789
|
-
}
|
|
790
|
-
/** The result interface if validation fails. */
|
|
791
|
-
interface FailureResult {
|
|
792
|
-
/** The issues of failed validation. */
|
|
793
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
794
|
-
}
|
|
795
|
-
/** The issue interface of the failure output. */
|
|
796
|
-
interface Issue {
|
|
797
|
-
/** The error message of the issue. */
|
|
798
|
-
readonly message: string;
|
|
799
|
-
/** The path of the issue, if any. */
|
|
800
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
801
|
-
}
|
|
802
|
-
/** The path segment interface of the issue. */
|
|
803
|
-
interface PathSegment {
|
|
804
|
-
/** The key representing a path segment. */
|
|
805
|
-
readonly key: PropertyKey;
|
|
806
|
-
}
|
|
807
|
-
/** The Standard Schema types interface. */
|
|
808
|
-
interface Types<Input = unknown, Output = Input> {
|
|
809
|
-
/** The input type of the schema. */
|
|
810
|
-
readonly input: Input;
|
|
811
|
-
/** The output type of the schema. */
|
|
812
|
-
readonly output: Output;
|
|
813
|
-
}
|
|
814
|
-
/** Infers the input type of a Standard Schema. */
|
|
815
|
-
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
816
|
-
/** Infers the output type of a Standard Schema. */
|
|
817
|
-
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
818
|
-
}
|
|
819
|
-
|
|
820
822
|
/**
|
|
821
823
|
* A class for building and executing HTTP requests with customizable options and error handling.
|
|
822
824
|
* @template Method The HTTP method type (GET, POST, etc.)
|
|
@@ -937,7 +939,7 @@ declare class Request<Method extends HttpMethods, TRequest extends AspiRequestIn
|
|
|
937
939
|
bodySchema<TSchema extends StandardSchemaV1>(schema: TSchema): Request<Method, TRequest, Omit<Opts, "bodySchema"> & {
|
|
938
940
|
bodySchema: TSchema;
|
|
939
941
|
error: Opts["error"] & {
|
|
940
|
-
|
|
942
|
+
schemaParseError: CustomError<"schemaParseError", StandardSchemaV1.FailureResult["issues"]>;
|
|
941
943
|
};
|
|
942
944
|
}>;
|
|
943
945
|
/**
|
|
@@ -1209,7 +1211,7 @@ declare class Request<Method extends HttpMethods, TRequest extends AspiRequestIn
|
|
|
1209
1211
|
schema<TSchema extends StandardSchemaV1>(schema: TSchema): Request<Method, TRequest, Merge<Omit<Opts, "schema">, {
|
|
1210
1212
|
schema: TSchema;
|
|
1211
1213
|
error: Merge<Opts["error"], {
|
|
1212
|
-
|
|
1214
|
+
schemaParseError: CustomError<"schemaParseError", StandardSchemaV1.FailureResult["issues"]>;
|
|
1213
1215
|
}>;
|
|
1214
1216
|
}>>;
|
|
1215
1217
|
/**
|
|
@@ -2005,4 +2007,4 @@ declare class Aspi<TRequest extends AspiRequestInit = AspiRequestInit, Opts exte
|
|
|
2005
2007
|
useCapability(capability: Capability<TRequest>): this;
|
|
2006
2008
|
}
|
|
2007
2009
|
|
|
2008
|
-
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
|
|
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,12 +80,12 @@ var isAspiError = (error) => {
|
|
|
80
80
|
var isCustomError = (error) => {
|
|
81
81
|
return error instanceof CustomError;
|
|
82
82
|
};
|
|
83
|
-
var isParseError = (error) => {
|
|
84
|
-
return error instanceof CustomError && error.tag === "parseError";
|
|
85
|
-
};
|
|
86
83
|
var isJSONParseError = (error) => {
|
|
87
84
|
return error instanceof CustomError && error.tag === "jsonParseError";
|
|
88
85
|
};
|
|
86
|
+
var isSchemaParseError = (error) => {
|
|
87
|
+
return error instanceof CustomError && error.tag === "schemaParseError";
|
|
88
|
+
};
|
|
89
89
|
|
|
90
90
|
// src/result.ts
|
|
91
91
|
var result_exports = {};
|
|
@@ -1146,7 +1146,9 @@ var Request = class {
|
|
|
1146
1146
|
}
|
|
1147
1147
|
async #makeRequest(responseParser, isJson = false) {
|
|
1148
1148
|
if (this.#bodySchemaIssues.length) {
|
|
1149
|
-
return err(
|
|
1149
|
+
return err(
|
|
1150
|
+
new CustomError("schemaParseError", this.#bodySchemaIssues)
|
|
1151
|
+
);
|
|
1150
1152
|
}
|
|
1151
1153
|
const request = this.#request();
|
|
1152
1154
|
const { retries, retryDelay, retryOn, retryWhile, onRetry } = this.#sanitisedRetryConfig();
|
|
@@ -1285,7 +1287,7 @@ var Request = class {
|
|
|
1285
1287
|
throw new Error("Schema validation should not return a promise");
|
|
1286
1288
|
}
|
|
1287
1289
|
if (data.issues) {
|
|
1288
|
-
return err(new CustomError("
|
|
1290
|
+
return err(new CustomError("schemaParseError", data.issues));
|
|
1289
1291
|
}
|
|
1290
1292
|
return ok({
|
|
1291
1293
|
data: data.value,
|
|
@@ -1908,5 +1910,5 @@ export {
|
|
|
1908
1910
|
isAspiError,
|
|
1909
1911
|
isCustomError,
|
|
1910
1912
|
isJSONParseError,
|
|
1911
|
-
|
|
1913
|
+
isSchemaParseError
|
|
1912
1914
|
};
|
package/package.json
CHANGED