@alextheman/utility 5.13.1 → 5.15.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 +302 -237
- package/dist/index.d.cts +207 -160
- package/dist/index.d.ts +206 -159
- package/dist/index.js +302 -238
- package/dist/internal/index.cjs +342 -43
- package/dist/internal/index.d.cts +36 -18
- package/dist/internal/index.d.ts +36 -18
- package/dist/internal/index.js +342 -43
- package/dist/node/index.cjs +31 -2
- package/dist/node/index.js +31 -2
- package/dist/v6/index.cjs +31 -4
- package/dist/v6/index.d.cts +40 -32
- package/dist/v6/index.d.ts +40 -32
- package/dist/v6/index.js +32 -4
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import z$1, { ZodError, ZodType, z } from "zod";
|
|
1
|
+
import z$1, { ZodCoercedDate, ZodCoercedNumber, ZodError, ZodType, z } from "zod";
|
|
2
2
|
import { DotenvParseOutput } from "dotenv";
|
|
3
3
|
|
|
4
4
|
//#region src/root/constants/FILE_PATH_REGEX.d.ts
|
|
@@ -17,7 +17,7 @@ declare const VERSION_NUMBER_PATTERN: string;
|
|
|
17
17
|
declare const VERSION_NUMBER_REGEX: RegExp;
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/root/deprecated/DataError.d.ts
|
|
20
|
-
interface ExpectErrorOptions$
|
|
20
|
+
interface ExpectErrorOptions$1 {
|
|
21
21
|
expectedCode?: string;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
@@ -59,7 +59,7 @@ declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<P
|
|
|
59
59
|
*
|
|
60
60
|
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
61
61
|
*/
|
|
62
|
-
static expectError(errorFunction: () => unknown, options?: ExpectErrorOptions$
|
|
62
|
+
static expectError(errorFunction: () => unknown, options?: ExpectErrorOptions$1): DataError;
|
|
63
63
|
/**
|
|
64
64
|
* Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
|
|
65
65
|
*
|
|
@@ -71,7 +71,7 @@ declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<P
|
|
|
71
71
|
*
|
|
72
72
|
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
73
73
|
*/
|
|
74
|
-
static expectErrorAsync(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions$
|
|
74
|
+
static expectErrorAsync(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions$1): Promise<DataError>;
|
|
75
75
|
}
|
|
76
76
|
//#endregion
|
|
77
77
|
//#region src/root/deprecated/RecordKey.d.ts
|
|
@@ -674,9 +674,19 @@ type IgnoreCase<StringType extends string> = string extends StringType ? string
|
|
|
674
674
|
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
675
675
|
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
676
676
|
//#endregion
|
|
677
|
+
//#region src/root/types/NonNull.d.ts
|
|
678
|
+
/**
|
|
679
|
+
* Removes `null` from a type.
|
|
680
|
+
*
|
|
681
|
+
* @category Types
|
|
682
|
+
*
|
|
683
|
+
* @template InputType - The type to check.
|
|
684
|
+
*/
|
|
685
|
+
type NonNull<InputType> = InputType extends null ? never : InputType;
|
|
686
|
+
//#endregion
|
|
677
687
|
//#region src/root/types/NonUndefined.d.ts
|
|
678
688
|
/**
|
|
679
|
-
*
|
|
689
|
+
* Removes `undefined` from a type.
|
|
680
690
|
*
|
|
681
691
|
* @category Types
|
|
682
692
|
*
|
|
@@ -806,159 +816,6 @@ type VersionType = CreateEnumType<typeof VersionType>;
|
|
|
806
816
|
*/
|
|
807
817
|
declare function parseVersionType(input: unknown): VersionType;
|
|
808
818
|
//#endregion
|
|
809
|
-
//#region src/v6/CodeError.d.ts
|
|
810
|
-
interface ExpectErrorOptions$1<ErrorCode extends string = string> {
|
|
811
|
-
expectedCode?: ErrorCode;
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* Represents errors that can be described using a standardised error code, and a human-readable error message.
|
|
815
|
-
*
|
|
816
|
-
* @category Types
|
|
817
|
-
*
|
|
818
|
-
* @template ErrorCode The type of the standardised error code.
|
|
819
|
-
*/
|
|
820
|
-
declare class CodeError<ErrorCode extends string = string> extends Error {
|
|
821
|
-
code: ErrorCode;
|
|
822
|
-
/**
|
|
823
|
-
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
824
|
-
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
825
|
-
* @param options - Extra options to pass to super Error constructor.
|
|
826
|
-
*/
|
|
827
|
-
constructor(code: ErrorCode, message?: string, options?: ErrorOptions);
|
|
828
|
-
/**
|
|
829
|
-
* Checks whether the given input may have been caused by a CodeError.
|
|
830
|
-
*
|
|
831
|
-
* @param input - The input to check.
|
|
832
|
-
*
|
|
833
|
-
* @returns `true` if the input is a CodeError, and `false` otherwise. The type of the input will also be narrowed down to CodeError if `true`.
|
|
834
|
-
*/
|
|
835
|
-
static check(input: unknown): input is CodeError<string>;
|
|
836
|
-
protected static checkCaughtError<ErrorCode extends string = string>(this: typeof CodeError, error: unknown, options?: ExpectErrorOptions$1<ErrorCode>): CodeError;
|
|
837
|
-
/**
|
|
838
|
-
* Gets the thrown `CodeError` from a given function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
|
|
839
|
-
*
|
|
840
|
-
* @param errorFunction - The function expected to throw the error.
|
|
841
|
-
* @param options - Extra options to apply.
|
|
842
|
-
*
|
|
843
|
-
* @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
|
|
844
|
-
* @throws {Error} If no `CodeError` was thrown by the `errorFunction`
|
|
845
|
-
*
|
|
846
|
-
* @returns The `CodeError` that was thrown by the `errorFunction`
|
|
847
|
-
*/
|
|
848
|
-
static expectError<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => unknown, options?: ExpectErrorOptions$1<ErrorCode>): CodeError;
|
|
849
|
-
/**
|
|
850
|
-
* Gets the thrown `CodeError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
|
|
851
|
-
*
|
|
852
|
-
* @param errorFunction - The function expected to throw the error.
|
|
853
|
-
* @param options - Extra options to apply.
|
|
854
|
-
*
|
|
855
|
-
* @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
|
|
856
|
-
* @throws {Error} If no `CodeError` was thrown by the `errorFunction`
|
|
857
|
-
*
|
|
858
|
-
* @returns The `CodeError` that was thrown by the `errorFunction`
|
|
859
|
-
*/
|
|
860
|
-
static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions$1<ErrorCode>): Promise<CodeError>;
|
|
861
|
-
}
|
|
862
|
-
//#endregion
|
|
863
|
-
//#region src/v6/DataError.d.ts
|
|
864
|
-
type DefaultDataErrorCode = "INVALID_DATA";
|
|
865
|
-
interface ExpectErrorOptions<ErrorCode extends string = DefaultDataErrorCode> {
|
|
866
|
-
expectedCode?: ErrorCode | DefaultDataErrorCode;
|
|
867
|
-
}
|
|
868
|
-
declare const DataErrorCode: {
|
|
869
|
-
readonly INVALID_DATA: "INVALID_DATA";
|
|
870
|
-
};
|
|
871
|
-
type DataErrorCode = CreateEnumType<typeof DataErrorCode>;
|
|
872
|
-
/**
|
|
873
|
-
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
874
|
-
*
|
|
875
|
-
* @category Types
|
|
876
|
-
*
|
|
877
|
-
* @template DataType - The type of the data that caused the error.
|
|
878
|
-
*/
|
|
879
|
-
declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = DataErrorCode> extends CodeError<ErrorCode | DataErrorCode> {
|
|
880
|
-
data: DataType;
|
|
881
|
-
/**
|
|
882
|
-
* @param data - The data that caused the error.
|
|
883
|
-
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
884
|
-
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
885
|
-
* @param options - Extra options to pass to super Error constructor.
|
|
886
|
-
*/
|
|
887
|
-
constructor(data: DataType, code?: ErrorCode | DefaultDataErrorCode, message?: string, options?: ErrorOptions);
|
|
888
|
-
/**
|
|
889
|
-
* Checks whether the given input may have been caused by a DataError.
|
|
890
|
-
*
|
|
891
|
-
* @param input - The input to check.
|
|
892
|
-
*
|
|
893
|
-
* @returns `true` if the input is a DataError, and `false` otherwise. The type of the input will also be narrowed down to DataError if `true`.
|
|
894
|
-
*/
|
|
895
|
-
static check<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = DataErrorCode>(input: unknown): input is DataError$1<DataType, ErrorCode>;
|
|
896
|
-
/**
|
|
897
|
-
* Gets the thrown `DataError` from a given function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
|
|
898
|
-
*
|
|
899
|
-
* @param errorFunction - The function expected to throw the error.
|
|
900
|
-
* @param options - Extra options to apply.
|
|
901
|
-
*
|
|
902
|
-
* @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
|
|
903
|
-
* @throws {Error} If no `DataError` was thrown by the `errorFunction`
|
|
904
|
-
*
|
|
905
|
-
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
906
|
-
*/
|
|
907
|
-
static expectError<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = DefaultDataErrorCode>(errorFunction: () => unknown, options?: ExpectErrorOptions<ErrorCode>): DataError$1<DataType, ErrorCode>;
|
|
908
|
-
/**
|
|
909
|
-
* Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
|
|
910
|
-
*
|
|
911
|
-
* @param errorFunction - The function expected to throw the error.
|
|
912
|
-
* @param options - Extra options to apply.
|
|
913
|
-
*
|
|
914
|
-
* @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
|
|
915
|
-
* @throws {Error} If no `DataError` was thrown by the `errorFunction`
|
|
916
|
-
*
|
|
917
|
-
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
918
|
-
*/
|
|
919
|
-
static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = DefaultDataErrorCode>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError$1<DataType, ErrorCode>>;
|
|
920
|
-
}
|
|
921
|
-
//#endregion
|
|
922
|
-
//#region src/root/functions/parsers/zod/parseZodSchema.d.ts
|
|
923
|
-
/**
|
|
924
|
-
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
925
|
-
*
|
|
926
|
-
* NOTE: Use `parseZodSchemaAsync` if your schema includes an asynchronous function.
|
|
927
|
-
*
|
|
928
|
-
* @category Parsers
|
|
929
|
-
*
|
|
930
|
-
* @template SchemaType - The Zod schema type.
|
|
931
|
-
* @template ErrorType - The type of error to throw on invalid data.
|
|
932
|
-
*
|
|
933
|
-
* @param schema - The Zod schema to use in parsing.
|
|
934
|
-
* @param input - The data to parse.
|
|
935
|
-
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
936
|
-
*
|
|
937
|
-
* @throws {DataErrorCode} If the given data cannot be parsed according to the schema.
|
|
938
|
-
*
|
|
939
|
-
* @returns The parsed data from the Zod schema.
|
|
940
|
-
*/
|
|
941
|
-
declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
|
|
942
|
-
//#endregion
|
|
943
|
-
//#region src/root/functions/parsers/zod/parseZodSchemaAsync.d.ts
|
|
944
|
-
/**
|
|
945
|
-
* An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
|
|
946
|
-
*
|
|
947
|
-
* @category Parsers
|
|
948
|
-
*
|
|
949
|
-
* @template SchemaType - The Zod schema type.
|
|
950
|
-
* @template ErrorType - The type of error to throw on invalid data.
|
|
951
|
-
*
|
|
952
|
-
* @param schema - The Zod schema to use in parsing.
|
|
953
|
-
* @param input - The data to parse.
|
|
954
|
-
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
955
|
-
*
|
|
956
|
-
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
957
|
-
*
|
|
958
|
-
* @returns The parsed data from the Zod schema.
|
|
959
|
-
*/
|
|
960
|
-
declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z.infer<SchemaType>>;
|
|
961
|
-
//#endregion
|
|
962
819
|
//#region src/root/functions/recursive/deepCopy.d.ts
|
|
963
820
|
/**
|
|
964
821
|
* Deeply copies an object or array such that all child objects/arrays are also copied.
|
|
@@ -1264,4 +1121,194 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1264
1121
|
*/
|
|
1265
1122
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1266
1123
|
//#endregion
|
|
1267
|
-
|
|
1124
|
+
//#region src/v6/CodeError.d.ts
|
|
1125
|
+
interface ExpectErrorOptions<ErrorCode extends string = string> {
|
|
1126
|
+
expectedCode?: ErrorCode;
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Represents errors that can be described using a standardised error code, and a human-readable error message.
|
|
1130
|
+
*
|
|
1131
|
+
* @category Types
|
|
1132
|
+
*
|
|
1133
|
+
* @template ErrorCode The type of the standardised error code.
|
|
1134
|
+
*/
|
|
1135
|
+
declare class CodeError<ErrorCode extends string = string> extends Error {
|
|
1136
|
+
code: ErrorCode;
|
|
1137
|
+
/**
|
|
1138
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
1139
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
1140
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
1141
|
+
*/
|
|
1142
|
+
constructor(code: ErrorCode, message?: string, options?: ErrorOptions);
|
|
1143
|
+
/**
|
|
1144
|
+
* Checks whether the given input may have been caused by a CodeError.
|
|
1145
|
+
*
|
|
1146
|
+
* @param input - The input to check.
|
|
1147
|
+
*
|
|
1148
|
+
* @returns `true` if the input is a CodeError, and `false` otherwise. The type of the input will also be narrowed down to CodeError if `true`.
|
|
1149
|
+
*/
|
|
1150
|
+
static check<ErrorCode extends string = string>(input: unknown): input is CodeError<ErrorCode>;
|
|
1151
|
+
protected static checkCaughtError<ErrorCode extends string = string>(this: typeof CodeError, error: unknown, options?: ExpectErrorOptions<ErrorCode>): CodeError<ErrorCode>;
|
|
1152
|
+
/**
|
|
1153
|
+
* Check a `CodeError` against its error code
|
|
1154
|
+
*
|
|
1155
|
+
* This will also automatically narrow down the type of the input to be `CodeError`, with its error code properly typed if this function returns true.
|
|
1156
|
+
*
|
|
1157
|
+
* @template ErrorCode The type of the error code
|
|
1158
|
+
*
|
|
1159
|
+
* @param input - The input to check.
|
|
1160
|
+
* @param code - The expected code of the resulting error.
|
|
1161
|
+
*
|
|
1162
|
+
* @returns `true` if the error code matches the expected code, and `false` otherwise. The type of the input will also be narrowed down to CodeError, and its code will be narrowed to the expected code's type if the function returns `true`.
|
|
1163
|
+
*/
|
|
1164
|
+
static checkWithCode<ErrorCode extends string = string>(input: unknown, code: ErrorCode): input is CodeError<ErrorCode>;
|
|
1165
|
+
/**
|
|
1166
|
+
* Gets the thrown `CodeError` from a given function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
|
|
1167
|
+
*
|
|
1168
|
+
* @param errorFunction - The function expected to throw the error.
|
|
1169
|
+
* @param options - Extra options to apply.
|
|
1170
|
+
*
|
|
1171
|
+
* @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
|
|
1172
|
+
* @throws {Error} If no `CodeError` was thrown by the `errorFunction`
|
|
1173
|
+
*
|
|
1174
|
+
* @returns The `CodeError` that was thrown by the `errorFunction`
|
|
1175
|
+
*/
|
|
1176
|
+
static expectError<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => unknown, options?: ExpectErrorOptions<ErrorCode>): CodeError<ErrorCode>;
|
|
1177
|
+
/**
|
|
1178
|
+
* Gets the thrown `CodeError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
|
|
1179
|
+
*
|
|
1180
|
+
* @param errorFunction - The function expected to throw the error.
|
|
1181
|
+
* @param options - Extra options to apply.
|
|
1182
|
+
*
|
|
1183
|
+
* @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
|
|
1184
|
+
* @throws {Error} If no `CodeError` was thrown by the `errorFunction`
|
|
1185
|
+
*
|
|
1186
|
+
* @returns The `CodeError` that was thrown by the `errorFunction`
|
|
1187
|
+
*/
|
|
1188
|
+
static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<CodeError>;
|
|
1189
|
+
}
|
|
1190
|
+
//#endregion
|
|
1191
|
+
//#region src/v6/DataError.d.ts
|
|
1192
|
+
/**
|
|
1193
|
+
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
1194
|
+
*
|
|
1195
|
+
* @category Types
|
|
1196
|
+
*
|
|
1197
|
+
* @template DataType - The type of the data that caused the error.
|
|
1198
|
+
*/
|
|
1199
|
+
declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string> extends CodeError<ErrorCode> {
|
|
1200
|
+
data: DataType;
|
|
1201
|
+
/**
|
|
1202
|
+
* @param data - The data that caused the error.
|
|
1203
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
1204
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
1205
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
1206
|
+
*/
|
|
1207
|
+
constructor(data: DataType, code: ErrorCode, message?: string, options?: ErrorOptions);
|
|
1208
|
+
/**
|
|
1209
|
+
* Checks whether the given input may have been caused by a DataError.
|
|
1210
|
+
*
|
|
1211
|
+
* @param input - The input to check.
|
|
1212
|
+
*
|
|
1213
|
+
* @returns `true` if the input is a DataError, and `false` otherwise. The type of the input will also be narrowed down to DataError if `true`.
|
|
1214
|
+
*/
|
|
1215
|
+
static check<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string>(input: unknown): input is DataError$1<DataType, ErrorCode>;
|
|
1216
|
+
/**
|
|
1217
|
+
* Check a `DataError` against its error code
|
|
1218
|
+
*
|
|
1219
|
+
* This will also automatically narrow down the type of the input to be `DataError`, with its error code properly typed if this function returns true.
|
|
1220
|
+
*
|
|
1221
|
+
* @template ErrorCode The type of the error code
|
|
1222
|
+
*
|
|
1223
|
+
* @param input - The input to check.
|
|
1224
|
+
* @param code - The expected code of the resulting error.
|
|
1225
|
+
*
|
|
1226
|
+
* @returns `true` if the error code matches the expected code, and `false` otherwise. The type of the input will also be narrowed down to `DataError`, and its code will be narrowed to the expected code's type if the function returns `true`.
|
|
1227
|
+
*/
|
|
1228
|
+
static checkWithCode<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string>(input: unknown, code: ErrorCode): input is DataError$1<DataType, ErrorCode>;
|
|
1229
|
+
/**
|
|
1230
|
+
* Gets the thrown `DataError` from a given function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
|
|
1231
|
+
*
|
|
1232
|
+
* @param errorFunction - The function expected to throw the error.
|
|
1233
|
+
* @param options - Extra options to apply.
|
|
1234
|
+
*
|
|
1235
|
+
* @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
|
|
1236
|
+
* @throws {Error} If no `DataError` was thrown by the `errorFunction`
|
|
1237
|
+
*
|
|
1238
|
+
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
1239
|
+
*/
|
|
1240
|
+
static expectError<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = string>(errorFunction: () => unknown, options?: ExpectErrorOptions<ErrorCode>): DataError$1<DataType, ErrorCode>;
|
|
1241
|
+
/**
|
|
1242
|
+
* Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
|
|
1243
|
+
*
|
|
1244
|
+
* @param errorFunction - The function expected to throw the error.
|
|
1245
|
+
* @param options - Extra options to apply.
|
|
1246
|
+
*
|
|
1247
|
+
* @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
|
|
1248
|
+
* @throws {Error} If no `DataError` was thrown by the `errorFunction`
|
|
1249
|
+
*
|
|
1250
|
+
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
1251
|
+
*/
|
|
1252
|
+
static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = string>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError$1<DataType, ErrorCode>>;
|
|
1253
|
+
}
|
|
1254
|
+
//#endregion
|
|
1255
|
+
//#region src/root/zod/parseZodSchema.d.ts
|
|
1256
|
+
/**
|
|
1257
|
+
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
1258
|
+
*
|
|
1259
|
+
* NOTE: Use `parseZodSchemaAsync` if your schema includes an asynchronous function.
|
|
1260
|
+
*
|
|
1261
|
+
* @category Parsers
|
|
1262
|
+
*
|
|
1263
|
+
* @deprecated Please use `az.with(schema).parse(input)` instead.
|
|
1264
|
+
*
|
|
1265
|
+
* @template SchemaType - The Zod schema type.
|
|
1266
|
+
* @template ErrorType - The type of error to throw on invalid data.
|
|
1267
|
+
*
|
|
1268
|
+
* @param schema - The Zod schema to use in parsing.
|
|
1269
|
+
* @param input - The data to parse.
|
|
1270
|
+
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
1271
|
+
*
|
|
1272
|
+
* @throws {DataErrorCode} If the given data cannot be parsed according to the schema.
|
|
1273
|
+
*
|
|
1274
|
+
* @returns The parsed data from the Zod schema.
|
|
1275
|
+
*/
|
|
1276
|
+
declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
|
|
1277
|
+
//#endregion
|
|
1278
|
+
//#region src/root/zod/parseZodSchemaAsync.d.ts
|
|
1279
|
+
/**
|
|
1280
|
+
* An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
|
|
1281
|
+
*
|
|
1282
|
+
* @category Parsers
|
|
1283
|
+
*
|
|
1284
|
+
* @deprecated Please use `az.with(schema).parseAsync(input)` instead.
|
|
1285
|
+
*
|
|
1286
|
+
* @template SchemaType - The Zod schema type.
|
|
1287
|
+
* @template ErrorType - The type of error to throw on invalid data.
|
|
1288
|
+
*
|
|
1289
|
+
* @param schema - The Zod schema to use in parsing.
|
|
1290
|
+
* @param input - The data to parse.
|
|
1291
|
+
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
1292
|
+
*
|
|
1293
|
+
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
1294
|
+
*
|
|
1295
|
+
* @returns The parsed data from the Zod schema.
|
|
1296
|
+
*/
|
|
1297
|
+
declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z.infer<SchemaType>>;
|
|
1298
|
+
//#endregion
|
|
1299
|
+
//#region src/root/zod/zodFieldWrapper.d.ts
|
|
1300
|
+
declare function zodFieldWrapper<SchemaType extends ZodType<unknown, string | null>>(schema: SchemaType): ZodType<z$1.infer<SchemaType>, string>;
|
|
1301
|
+
//#endregion
|
|
1302
|
+
//#region src/root/zod/az.d.ts
|
|
1303
|
+
declare const az: {
|
|
1304
|
+
field: typeof zodFieldWrapper;
|
|
1305
|
+
fieldNumber: () => ZodCoercedNumber<string | null>;
|
|
1306
|
+
versionNumber: () => ZodType<VersionNumber, unknown>;
|
|
1307
|
+
fieldDate: () => ZodCoercedDate<string | null>;
|
|
1308
|
+
with: <SchemaType extends ZodType>(schema: SchemaType) => {
|
|
1309
|
+
parse: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>, string>>(input: unknown, error?: ErrorType | ((zodError: z$1.ZodError<unknown>) => void | ErrorType)) => ReturnType<typeof parseZodSchema<SchemaType, ErrorType>>;
|
|
1310
|
+
parseAsync: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>, string>>(input: unknown, error?: ErrorType | ((zodError: z$1.ZodError<unknown>) => void | ErrorType)) => ReturnType<typeof parseZodSchemaAsync<SchemaType, ErrorType>>;
|
|
1311
|
+
};
|
|
1312
|
+
};
|
|
1313
|
+
//#endregion
|
|
1314
|
+
export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, type NonNull, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, az, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
|