better-call 1.1.2 → 1.1.4

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/router.d.cts CHANGED
@@ -8,6 +8,63 @@ type MergeObject<T extends Record<string, any> | never, S extends Record<string,
8
8
  type InferParamPath<Path> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}:${infer Param}` ? { [K in Param]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
9
9
  type InferParamWildCard<Path> = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}/*` ? { [K in "_"]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamWildCard<Rest> : {};
10
10
  //#endregion
11
+ //#region src/standard-schema.d.ts
12
+ /** The Standard Schema interface. */
13
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
14
+ /** The Standard Schema properties. */
15
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
16
+ }
17
+ declare namespace StandardSchemaV1 {
18
+ /** The Standard Schema properties interface. */
19
+ interface Props<Input = unknown, Output = Input> {
20
+ /** The version number of the standard. */
21
+ readonly version: 1;
22
+ /** The vendor name of the schema library. */
23
+ readonly vendor: string;
24
+ /** Validates unknown input values. */
25
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
26
+ /** Inferred types associated with the schema. */
27
+ readonly types?: Types<Input, Output> | undefined;
28
+ }
29
+ /** The result interface of the validate function. */
30
+ type Result<Output> = SuccessResult<Output> | FailureResult;
31
+ /** The result interface if validation succeeds. */
32
+ interface SuccessResult<Output> {
33
+ /** The typed output value. */
34
+ readonly value: Output;
35
+ /** The non-existent issues. */
36
+ readonly issues?: undefined;
37
+ }
38
+ /** The result interface if validation fails. */
39
+ interface FailureResult {
40
+ /** The issues of failed validation. */
41
+ readonly issues: ReadonlyArray<Issue>;
42
+ }
43
+ /** The issue interface of the failure output. */
44
+ interface Issue {
45
+ /** The error message of the issue. */
46
+ readonly message: string;
47
+ /** The path of the issue, if any. */
48
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
49
+ }
50
+ /** The path segment interface of the issue. */
51
+ interface PathSegment {
52
+ /** The key representing a path segment. */
53
+ readonly key: PropertyKey;
54
+ }
55
+ /** The Standard Schema types interface. */
56
+ interface Types<Input = unknown, Output = Input> {
57
+ /** The input type of the schema. */
58
+ readonly input: Input;
59
+ /** The output type of the schema. */
60
+ readonly output: Output;
61
+ }
62
+ /** Infers the input type of a Standard Schema. */
63
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
64
+ /** Infers the output type of a Standard Schema. */
65
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
66
+ }
67
+ //#endregion
11
68
  //#region src/error.d.ts
12
69
  /**
13
70
  * Hide internal stack frames from the error stack trace.
@@ -89,6 +146,11 @@ declare class InternalAPIError extends Error {
89
146
  cause?: unknown;
90
147
  } & Record<string, any>) | undefined, headers?: HeadersInit, statusCode?: number);
91
148
  }
149
+ declare class ValidationError extends InternalAPIError {
150
+ message: string;
151
+ issues: readonly StandardSchemaV1.Issue[];
152
+ constructor(message: string, issues: readonly StandardSchemaV1.Issue[]);
153
+ }
92
154
  declare class BetterCallError extends Error {
93
155
  constructor(message: string);
94
156
  }
@@ -202,63 +264,6 @@ declare function parseCookies(str: string): Map<string, string>;
202
264
  declare const serializeCookie: (key: string, value: string, opt?: CookieOptions) => string;
203
265
  declare const serializeSignedCookie: (key: string, value: string, secret: string, opt?: CookieOptions) => Promise<string>;
204
266
  //#endregion
205
- //#region src/standard-schema.d.ts
206
- /** The Standard Schema interface. */
207
- interface StandardSchemaV1<Input = unknown, Output = Input> {
208
- /** The Standard Schema properties. */
209
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
210
- }
211
- declare namespace StandardSchemaV1 {
212
- /** The Standard Schema properties interface. */
213
- interface Props<Input = unknown, Output = Input> {
214
- /** The version number of the standard. */
215
- readonly version: 1;
216
- /** The vendor name of the schema library. */
217
- readonly vendor: string;
218
- /** Validates unknown input values. */
219
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
220
- /** Inferred types associated with the schema. */
221
- readonly types?: Types<Input, Output> | undefined;
222
- }
223
- /** The result interface of the validate function. */
224
- type Result<Output> = SuccessResult<Output> | FailureResult;
225
- /** The result interface if validation succeeds. */
226
- interface SuccessResult<Output> {
227
- /** The typed output value. */
228
- readonly value: Output;
229
- /** The non-existent issues. */
230
- readonly issues?: undefined;
231
- }
232
- /** The result interface if validation fails. */
233
- interface FailureResult {
234
- /** The issues of failed validation. */
235
- readonly issues: ReadonlyArray<Issue>;
236
- }
237
- /** The issue interface of the failure output. */
238
- interface Issue {
239
- /** The error message of the issue. */
240
- readonly message: string;
241
- /** The path of the issue, if any. */
242
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
243
- }
244
- /** The path segment interface of the issue. */
245
- interface PathSegment {
246
- /** The key representing a path segment. */
247
- readonly key: PropertyKey;
248
- }
249
- /** The Standard Schema types interface. */
250
- interface Types<Input = unknown, Output = Input> {
251
- /** The input type of the schema. */
252
- readonly input: Input;
253
- /** The output type of the schema. */
254
- readonly output: Output;
255
- }
256
- /** Infers the input type of a Standard Schema. */
257
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
258
- /** Infers the output type of a Standard Schema. */
259
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
260
- }
261
- //#endregion
262
267
  //#region src/context.d.ts
263
268
  type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
264
269
  type Method = HTTPMethod | "*";
@@ -981,6 +986,17 @@ interface EndpointBaseOptions {
981
986
  * @returns - The response to return
982
987
  */
983
988
  onAPIError?: (e: APIError) => void | Promise<void>;
989
+ /**
990
+ * A callback to run before a validation error is thrown
991
+ * You can customize the validation error message by throwing your own APIError
992
+ */
993
+ onValidationError?: ({
994
+ issues,
995
+ message
996
+ }: {
997
+ message: string;
998
+ issues: readonly StandardSchemaV1.Issue[];
999
+ }) => void | Promise<void>;
984
1000
  }
985
1001
  type EndpointBodyMethodOptions = {
986
1002
  /**
@@ -1309,5 +1325,5 @@ declare const createRouter: <E extends Record<string, Endpoint>, Config extends
1309
1325
  };
1310
1326
  type Router = ReturnType<typeof createRouter>;
1311
1327
  //#endregion
1312
- export { statusCodes as $, InferMiddlewareQuery as A, createInternalContext as B, InferBody as C, InferInputMethod as D, InferHeadersInput as E, InferRequest as F, parseCookies as G, CookieOptions as H, InferRequestInput as I, APIError as J, serializeCookie as K, InferUse as L, InferParamInput as M, InferQuery as N, InferMethod as O, InferQueryInput as P, makeErrorForHideStackFrame as Q, InputContext as R, HTTPMethod as S, InferHeaders as T, CookiePrefixOptions as U, StandardSchemaV1 as V, getCookieKey as W, Status as X, BetterCallError as Y, hideInternalStackFrames as Z, MiddlewareContext as _, EndpointBaseOptions as a, Prettify as at, MiddlewareResponse as b, EndpointOptions as c, OpenAPIParameter as d, HasRequiredKeys as et, OpenAPISchemaType as f, Middleware as g, getHTML as h, Endpoint as i, MergeObject as it, InferParam as j, InferMiddlewareBody as k, StrictEndpoint as l, generator as m, RouterConfig as n, InferParamWildCard as nt, EndpointBodyMethodOptions as o, RequiredKeysOf as ot, Path$1 as p, serializeSignedCookie as q, createRouter as r, IsEmptyObject as rt, EndpointContext as s, UnionToIntersection as st, Router as t, InferParamPath as tt, createEndpoint as u, MiddlewareInputContext as v, InferBodyInput as w, createMiddleware as x, MiddlewareOptions as y, Method as z };
1328
+ export { statusCodes as $, InferMiddlewareQuery as A, createInternalContext as B, InferBody as C, InferInputMethod as D, InferHeadersInput as E, InferRequest as F, serializeCookie as G, CookiePrefixOptions as H, InferRequestInput as I, BetterCallError as J, serializeSignedCookie as K, InferUse as L, InferParamInput as M, InferQuery as N, InferMethod as O, InferQueryInput as P, makeErrorForHideStackFrame as Q, InputContext as R, HTTPMethod as S, InferHeaders as T, getCookieKey as U, CookieOptions as V, parseCookies as W, ValidationError as X, Status as Y, hideInternalStackFrames as Z, MiddlewareContext as _, EndpointBaseOptions as a, MergeObject as at, MiddlewareResponse as b, EndpointOptions as c, UnionToIntersection as ct, OpenAPIParameter as d, StandardSchemaV1 as et, OpenAPISchemaType as f, Middleware as g, getHTML as h, Endpoint as i, IsEmptyObject as it, InferParam as j, InferMiddlewareBody as k, StrictEndpoint as l, generator as m, RouterConfig as n, InferParamPath as nt, EndpointBodyMethodOptions as o, Prettify as ot, Path$1 as p, APIError as q, createRouter as r, InferParamWildCard as rt, EndpointContext as s, RequiredKeysOf as st, Router as t, HasRequiredKeys as tt, createEndpoint as u, MiddlewareInputContext as v, InferBodyInput as w, createMiddleware as x, MiddlewareOptions as y, Method as z };
1313
1329
  //# sourceMappingURL=router.d.cts.map
package/dist/router.d.ts CHANGED
@@ -8,6 +8,63 @@ type MergeObject<T extends Record<string, any> | never, S extends Record<string,
8
8
  type InferParamPath<Path> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}:${infer Param}` ? { [K in Param]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
9
9
  type InferParamWildCard<Path> = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}/*` ? { [K in "_"]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamWildCard<Rest> : {};
10
10
  //#endregion
11
+ //#region src/standard-schema.d.ts
12
+ /** The Standard Schema interface. */
13
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
14
+ /** The Standard Schema properties. */
15
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
16
+ }
17
+ declare namespace StandardSchemaV1 {
18
+ /** The Standard Schema properties interface. */
19
+ interface Props<Input = unknown, Output = Input> {
20
+ /** The version number of the standard. */
21
+ readonly version: 1;
22
+ /** The vendor name of the schema library. */
23
+ readonly vendor: string;
24
+ /** Validates unknown input values. */
25
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
26
+ /** Inferred types associated with the schema. */
27
+ readonly types?: Types<Input, Output> | undefined;
28
+ }
29
+ /** The result interface of the validate function. */
30
+ type Result<Output> = SuccessResult<Output> | FailureResult;
31
+ /** The result interface if validation succeeds. */
32
+ interface SuccessResult<Output> {
33
+ /** The typed output value. */
34
+ readonly value: Output;
35
+ /** The non-existent issues. */
36
+ readonly issues?: undefined;
37
+ }
38
+ /** The result interface if validation fails. */
39
+ interface FailureResult {
40
+ /** The issues of failed validation. */
41
+ readonly issues: ReadonlyArray<Issue>;
42
+ }
43
+ /** The issue interface of the failure output. */
44
+ interface Issue {
45
+ /** The error message of the issue. */
46
+ readonly message: string;
47
+ /** The path of the issue, if any. */
48
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
49
+ }
50
+ /** The path segment interface of the issue. */
51
+ interface PathSegment {
52
+ /** The key representing a path segment. */
53
+ readonly key: PropertyKey;
54
+ }
55
+ /** The Standard Schema types interface. */
56
+ interface Types<Input = unknown, Output = Input> {
57
+ /** The input type of the schema. */
58
+ readonly input: Input;
59
+ /** The output type of the schema. */
60
+ readonly output: Output;
61
+ }
62
+ /** Infers the input type of a Standard Schema. */
63
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
64
+ /** Infers the output type of a Standard Schema. */
65
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
66
+ }
67
+ //#endregion
11
68
  //#region src/error.d.ts
12
69
  /**
13
70
  * Hide internal stack frames from the error stack trace.
@@ -89,6 +146,11 @@ declare class InternalAPIError extends Error {
89
146
  cause?: unknown;
90
147
  } & Record<string, any>) | undefined, headers?: HeadersInit, statusCode?: number);
91
148
  }
149
+ declare class ValidationError extends InternalAPIError {
150
+ message: string;
151
+ issues: readonly StandardSchemaV1.Issue[];
152
+ constructor(message: string, issues: readonly StandardSchemaV1.Issue[]);
153
+ }
92
154
  declare class BetterCallError extends Error {
93
155
  constructor(message: string);
94
156
  }
@@ -202,63 +264,6 @@ declare function parseCookies(str: string): Map<string, string>;
202
264
  declare const serializeCookie: (key: string, value: string, opt?: CookieOptions) => string;
203
265
  declare const serializeSignedCookie: (key: string, value: string, secret: string, opt?: CookieOptions) => Promise<string>;
204
266
  //#endregion
205
- //#region src/standard-schema.d.ts
206
- /** The Standard Schema interface. */
207
- interface StandardSchemaV1<Input = unknown, Output = Input> {
208
- /** The Standard Schema properties. */
209
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
210
- }
211
- declare namespace StandardSchemaV1 {
212
- /** The Standard Schema properties interface. */
213
- interface Props<Input = unknown, Output = Input> {
214
- /** The version number of the standard. */
215
- readonly version: 1;
216
- /** The vendor name of the schema library. */
217
- readonly vendor: string;
218
- /** Validates unknown input values. */
219
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
220
- /** Inferred types associated with the schema. */
221
- readonly types?: Types<Input, Output> | undefined;
222
- }
223
- /** The result interface of the validate function. */
224
- type Result<Output> = SuccessResult<Output> | FailureResult;
225
- /** The result interface if validation succeeds. */
226
- interface SuccessResult<Output> {
227
- /** The typed output value. */
228
- readonly value: Output;
229
- /** The non-existent issues. */
230
- readonly issues?: undefined;
231
- }
232
- /** The result interface if validation fails. */
233
- interface FailureResult {
234
- /** The issues of failed validation. */
235
- readonly issues: ReadonlyArray<Issue>;
236
- }
237
- /** The issue interface of the failure output. */
238
- interface Issue {
239
- /** The error message of the issue. */
240
- readonly message: string;
241
- /** The path of the issue, if any. */
242
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
243
- }
244
- /** The path segment interface of the issue. */
245
- interface PathSegment {
246
- /** The key representing a path segment. */
247
- readonly key: PropertyKey;
248
- }
249
- /** The Standard Schema types interface. */
250
- interface Types<Input = unknown, Output = Input> {
251
- /** The input type of the schema. */
252
- readonly input: Input;
253
- /** The output type of the schema. */
254
- readonly output: Output;
255
- }
256
- /** Infers the input type of a Standard Schema. */
257
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
258
- /** Infers the output type of a Standard Schema. */
259
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
260
- }
261
- //#endregion
262
267
  //#region src/context.d.ts
263
268
  type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
264
269
  type Method = HTTPMethod | "*";
@@ -981,6 +986,17 @@ interface EndpointBaseOptions {
981
986
  * @returns - The response to return
982
987
  */
983
988
  onAPIError?: (e: APIError) => void | Promise<void>;
989
+ /**
990
+ * A callback to run before a validation error is thrown
991
+ * You can customize the validation error message by throwing your own APIError
992
+ */
993
+ onValidationError?: ({
994
+ issues,
995
+ message
996
+ }: {
997
+ message: string;
998
+ issues: readonly StandardSchemaV1.Issue[];
999
+ }) => void | Promise<void>;
984
1000
  }
985
1001
  type EndpointBodyMethodOptions = {
986
1002
  /**
@@ -1309,5 +1325,5 @@ declare const createRouter: <E extends Record<string, Endpoint>, Config extends
1309
1325
  };
1310
1326
  type Router = ReturnType<typeof createRouter>;
1311
1327
  //#endregion
1312
- export { statusCodes as $, InferMiddlewareQuery as A, createInternalContext as B, InferBody as C, InferInputMethod as D, InferHeadersInput as E, InferRequest as F, parseCookies as G, CookieOptions as H, InferRequestInput as I, APIError as J, serializeCookie as K, InferUse as L, InferParamInput as M, InferQuery as N, InferMethod as O, InferQueryInput as P, makeErrorForHideStackFrame as Q, InputContext as R, HTTPMethod as S, InferHeaders as T, CookiePrefixOptions as U, StandardSchemaV1 as V, getCookieKey as W, Status as X, BetterCallError as Y, hideInternalStackFrames as Z, MiddlewareContext as _, EndpointBaseOptions as a, Prettify as at, MiddlewareResponse as b, EndpointOptions as c, OpenAPIParameter as d, HasRequiredKeys as et, OpenAPISchemaType as f, Middleware as g, getHTML as h, Endpoint as i, MergeObject as it, InferParam as j, InferMiddlewareBody as k, StrictEndpoint as l, generator as m, RouterConfig as n, InferParamWildCard as nt, EndpointBodyMethodOptions as o, RequiredKeysOf as ot, Path$1 as p, serializeSignedCookie as q, createRouter as r, IsEmptyObject as rt, EndpointContext as s, UnionToIntersection as st, Router as t, InferParamPath as tt, createEndpoint as u, MiddlewareInputContext as v, InferBodyInput as w, createMiddleware as x, MiddlewareOptions as y, Method as z };
1328
+ export { statusCodes as $, InferMiddlewareQuery as A, createInternalContext as B, InferBody as C, InferInputMethod as D, InferHeadersInput as E, InferRequest as F, serializeCookie as G, CookiePrefixOptions as H, InferRequestInput as I, BetterCallError as J, serializeSignedCookie as K, InferUse as L, InferParamInput as M, InferQuery as N, InferMethod as O, InferQueryInput as P, makeErrorForHideStackFrame as Q, InputContext as R, HTTPMethod as S, InferHeaders as T, getCookieKey as U, CookieOptions as V, parseCookies as W, ValidationError as X, Status as Y, hideInternalStackFrames as Z, MiddlewareContext as _, EndpointBaseOptions as a, MergeObject as at, MiddlewareResponse as b, EndpointOptions as c, UnionToIntersection as ct, OpenAPIParameter as d, StandardSchemaV1 as et, OpenAPISchemaType as f, Middleware as g, getHTML as h, Endpoint as i, IsEmptyObject as it, InferParam as j, InferMiddlewareBody as k, StrictEndpoint as l, generator as m, RouterConfig as n, InferParamPath as nt, EndpointBodyMethodOptions as o, Prettify as ot, Path$1 as p, APIError as q, createRouter as r, InferParamWildCard as rt, EndpointContext as s, RequiredKeysOf as st, Router as t, HasRequiredKeys as tt, createEndpoint as u, MiddlewareInputContext as v, InferBodyInput as w, createMiddleware as x, MiddlewareOptions as y, Method as z };
1313
1329
  //# sourceMappingURL=router.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-call",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "@better-auth/utils": "^0.3.0",
35
35
  "@better-fetch/fetch": "^1.1.4",
36
- "rou3": "^0.5.1",
36
+ "rou3": "^0.7.10",
37
37
  "set-cookie-parser": "^2.7.1"
38
38
  },
39
39
  "peerDependencies": {