better-call 1.1.4 → 1.1.6

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.
@@ -0,0 +1,171 @@
1
+
2
+ //#region src/error.ts
3
+ function isErrorStackTraceLimitWritable() {
4
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
5
+ if (desc === void 0) return Object.isExtensible(Error);
6
+ return Object.prototype.hasOwnProperty.call(desc, "writable") ? desc.writable : desc.set !== void 0;
7
+ }
8
+ /**
9
+ * Hide internal stack frames from the error stack trace.
10
+ */
11
+ function hideInternalStackFrames(stack) {
12
+ const lines = stack.split("\n at ");
13
+ if (lines.length <= 1) return stack;
14
+ lines.splice(1, 1);
15
+ return lines.join("\n at ");
16
+ }
17
+ /**
18
+ * Creates a custom error class that hides stack frames.
19
+ */
20
+ function makeErrorForHideStackFrame(Base, clazz) {
21
+ class HideStackFramesError extends Base {
22
+ #hiddenStack;
23
+ constructor(...args) {
24
+ if (isErrorStackTraceLimitWritable()) {
25
+ const limit = Error.stackTraceLimit;
26
+ Error.stackTraceLimit = 0;
27
+ super(...args);
28
+ Error.stackTraceLimit = limit;
29
+ } else super(...args);
30
+ const stack = (/* @__PURE__ */ new Error()).stack;
31
+ if (stack) this.#hiddenStack = hideInternalStackFrames(stack.replace(/^Error/, this.name));
32
+ }
33
+ get errorStack() {
34
+ return this.#hiddenStack;
35
+ }
36
+ }
37
+ Object.defineProperty(HideStackFramesError.prototype, "constructor", {
38
+ get() {
39
+ return clazz;
40
+ },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
44
+ return HideStackFramesError;
45
+ }
46
+ const statusCodes = {
47
+ OK: 200,
48
+ CREATED: 201,
49
+ ACCEPTED: 202,
50
+ NO_CONTENT: 204,
51
+ MULTIPLE_CHOICES: 300,
52
+ MOVED_PERMANENTLY: 301,
53
+ FOUND: 302,
54
+ SEE_OTHER: 303,
55
+ NOT_MODIFIED: 304,
56
+ TEMPORARY_REDIRECT: 307,
57
+ BAD_REQUEST: 400,
58
+ UNAUTHORIZED: 401,
59
+ PAYMENT_REQUIRED: 402,
60
+ FORBIDDEN: 403,
61
+ NOT_FOUND: 404,
62
+ METHOD_NOT_ALLOWED: 405,
63
+ NOT_ACCEPTABLE: 406,
64
+ PROXY_AUTHENTICATION_REQUIRED: 407,
65
+ REQUEST_TIMEOUT: 408,
66
+ CONFLICT: 409,
67
+ GONE: 410,
68
+ LENGTH_REQUIRED: 411,
69
+ PRECONDITION_FAILED: 412,
70
+ PAYLOAD_TOO_LARGE: 413,
71
+ URI_TOO_LONG: 414,
72
+ UNSUPPORTED_MEDIA_TYPE: 415,
73
+ RANGE_NOT_SATISFIABLE: 416,
74
+ EXPECTATION_FAILED: 417,
75
+ "I'M_A_TEAPOT": 418,
76
+ MISDIRECTED_REQUEST: 421,
77
+ UNPROCESSABLE_ENTITY: 422,
78
+ LOCKED: 423,
79
+ FAILED_DEPENDENCY: 424,
80
+ TOO_EARLY: 425,
81
+ UPGRADE_REQUIRED: 426,
82
+ PRECONDITION_REQUIRED: 428,
83
+ TOO_MANY_REQUESTS: 429,
84
+ REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
85
+ UNAVAILABLE_FOR_LEGAL_REASONS: 451,
86
+ INTERNAL_SERVER_ERROR: 500,
87
+ NOT_IMPLEMENTED: 501,
88
+ BAD_GATEWAY: 502,
89
+ SERVICE_UNAVAILABLE: 503,
90
+ GATEWAY_TIMEOUT: 504,
91
+ HTTP_VERSION_NOT_SUPPORTED: 505,
92
+ VARIANT_ALSO_NEGOTIATES: 506,
93
+ INSUFFICIENT_STORAGE: 507,
94
+ LOOP_DETECTED: 508,
95
+ NOT_EXTENDED: 510,
96
+ NETWORK_AUTHENTICATION_REQUIRED: 511
97
+ };
98
+ var InternalAPIError = class extends Error {
99
+ constructor(status = "INTERNAL_SERVER_ERROR", body = void 0, headers = {}, statusCode = typeof status === "number" ? status : statusCodes[status]) {
100
+ super(body?.message, body?.cause ? { cause: body.cause } : void 0);
101
+ this.status = status;
102
+ this.body = body;
103
+ this.headers = headers;
104
+ this.statusCode = statusCode;
105
+ this.name = "APIError";
106
+ this.status = status;
107
+ this.headers = headers;
108
+ this.statusCode = statusCode;
109
+ this.body = body ? {
110
+ code: body?.message?.toUpperCase().replace(/ /g, "_").replace(/[^A-Z0-9_]/g, ""),
111
+ ...body
112
+ } : void 0;
113
+ }
114
+ };
115
+ var ValidationError = class extends InternalAPIError {
116
+ constructor(message, issues) {
117
+ super(400, {
118
+ message,
119
+ code: "VALIDATION_ERROR"
120
+ });
121
+ this.message = message;
122
+ this.issues = issues;
123
+ this.issues = issues;
124
+ }
125
+ };
126
+ var BetterCallError = class extends Error {
127
+ constructor(message) {
128
+ super(message);
129
+ this.name = "BetterCallError";
130
+ }
131
+ };
132
+ const APIError = makeErrorForHideStackFrame(InternalAPIError, Error);
133
+
134
+ //#endregion
135
+ Object.defineProperty(exports, 'APIError', {
136
+ enumerable: true,
137
+ get: function () {
138
+ return APIError;
139
+ }
140
+ });
141
+ Object.defineProperty(exports, 'BetterCallError', {
142
+ enumerable: true,
143
+ get: function () {
144
+ return BetterCallError;
145
+ }
146
+ });
147
+ Object.defineProperty(exports, 'ValidationError', {
148
+ enumerable: true,
149
+ get: function () {
150
+ return ValidationError;
151
+ }
152
+ });
153
+ Object.defineProperty(exports, 'hideInternalStackFrames', {
154
+ enumerable: true,
155
+ get: function () {
156
+ return hideInternalStackFrames;
157
+ }
158
+ });
159
+ Object.defineProperty(exports, 'makeErrorForHideStackFrame', {
160
+ enumerable: true,
161
+ get: function () {
162
+ return makeErrorForHideStackFrame;
163
+ }
164
+ });
165
+ Object.defineProperty(exports, 'statusCodes', {
166
+ enumerable: true,
167
+ get: function () {
168
+ return statusCodes;
169
+ }
170
+ });
171
+ //# sourceMappingURL=error2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error2.cjs","names":["#hiddenStack","status: keyof typeof statusCodes | Status","body:\n\t\t\t| ({\n\t\t\t\t\tmessage?: string;\n\t\t\t\t\tcode?: string;\n\t\t\t\t\tcause?: unknown;\n\t\t\t } & Record<string, any>)\n\t\t\t| undefined","headers: HeadersInit","message: string","issues: readonly StandardSchemaV1.Issue[]"],"sources":["../src/error.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"./standard-schema\";\n// https://github.com/nodejs/node/blob/360f7cc7867b43344aac00564286b895e15f21d7/lib/internal/errors.js#L246C1-L261C2\nfunction isErrorStackTraceLimitWritable() {\n\tconst desc = Object.getOwnPropertyDescriptor(Error, \"stackTraceLimit\");\n\tif (desc === undefined) {\n\t\treturn Object.isExtensible(Error);\n\t}\n\n\treturn Object.prototype.hasOwnProperty.call(desc, \"writable\")\n\t\t? desc.writable\n\t\t: desc.set !== undefined;\n}\n\n/**\n * Hide internal stack frames from the error stack trace.\n */\nexport function hideInternalStackFrames(stack: string): string {\n\tconst lines = stack.split(\"\\n at \");\n\tif (lines.length <= 1) {\n\t\treturn stack;\n\t}\n\tlines.splice(1, 1);\n\treturn lines.join(\"\\n at \");\n}\n\n// https://github.com/nodejs/node/blob/360f7cc7867b43344aac00564286b895e15f21d7/lib/internal/errors.js#L411-L432\n/**\n * Creates a custom error class that hides stack frames.\n */\nexport function makeErrorForHideStackFrame<B extends new (...args: any[]) => Error>(\n\tBase: B,\n\tclazz: any,\n): {\n\tnew (...args: ConstructorParameters<B>): InstanceType<B> & { errorStack: string | undefined };\n} {\n\tclass HideStackFramesError extends Base {\n\t\t#hiddenStack: string | undefined;\n\n\t\tconstructor(...args: any[]) {\n\t\t\tif (isErrorStackTraceLimitWritable()) {\n\t\t\t\tconst limit = Error.stackTraceLimit;\n\t\t\t\tError.stackTraceLimit = 0;\n\t\t\t\tsuper(...args);\n\t\t\t\tError.stackTraceLimit = limit;\n\t\t\t} else {\n\t\t\t\tsuper(...args);\n\t\t\t}\n\t\t\tconst stack = new Error().stack;\n\t\t\tif (stack) {\n\t\t\t\tthis.#hiddenStack = hideInternalStackFrames(stack.replace(/^Error/, this.name));\n\t\t\t}\n\t\t}\n\n\t\t// use `getter` here to avoid the stack trace being captured by loggers\n\t\tget errorStack() {\n\t\t\treturn this.#hiddenStack;\n\t\t}\n\t}\n\n\t// This is a workaround for wpt tests that expect that the error\n\t// constructor has a `name` property of the base class.\n\tObject.defineProperty(HideStackFramesError.prototype, \"constructor\", {\n\t\tget() {\n\t\t\treturn clazz;\n\t\t},\n\t\tenumerable: false,\n\t\tconfigurable: true,\n\t});\n\n\treturn HideStackFramesError as any;\n}\n\nexport const statusCodes = {\n\tOK: 200,\n\tCREATED: 201,\n\tACCEPTED: 202,\n\tNO_CONTENT: 204,\n\tMULTIPLE_CHOICES: 300,\n\tMOVED_PERMANENTLY: 301,\n\tFOUND: 302,\n\tSEE_OTHER: 303,\n\tNOT_MODIFIED: 304,\n\tTEMPORARY_REDIRECT: 307,\n\tBAD_REQUEST: 400,\n\tUNAUTHORIZED: 401,\n\tPAYMENT_REQUIRED: 402,\n\tFORBIDDEN: 403,\n\tNOT_FOUND: 404,\n\tMETHOD_NOT_ALLOWED: 405,\n\tNOT_ACCEPTABLE: 406,\n\tPROXY_AUTHENTICATION_REQUIRED: 407,\n\tREQUEST_TIMEOUT: 408,\n\tCONFLICT: 409,\n\tGONE: 410,\n\tLENGTH_REQUIRED: 411,\n\tPRECONDITION_FAILED: 412,\n\tPAYLOAD_TOO_LARGE: 413,\n\tURI_TOO_LONG: 414,\n\tUNSUPPORTED_MEDIA_TYPE: 415,\n\tRANGE_NOT_SATISFIABLE: 416,\n\tEXPECTATION_FAILED: 417,\n\t\"I'M_A_TEAPOT\": 418,\n\tMISDIRECTED_REQUEST: 421,\n\tUNPROCESSABLE_ENTITY: 422,\n\tLOCKED: 423,\n\tFAILED_DEPENDENCY: 424,\n\tTOO_EARLY: 425,\n\tUPGRADE_REQUIRED: 426,\n\tPRECONDITION_REQUIRED: 428,\n\tTOO_MANY_REQUESTS: 429,\n\tREQUEST_HEADER_FIELDS_TOO_LARGE: 431,\n\tUNAVAILABLE_FOR_LEGAL_REASONS: 451,\n\tINTERNAL_SERVER_ERROR: 500,\n\tNOT_IMPLEMENTED: 501,\n\tBAD_GATEWAY: 502,\n\tSERVICE_UNAVAILABLE: 503,\n\tGATEWAY_TIMEOUT: 504,\n\tHTTP_VERSION_NOT_SUPPORTED: 505,\n\tVARIANT_ALSO_NEGOTIATES: 506,\n\tINSUFFICIENT_STORAGE: 507,\n\tLOOP_DETECTED: 508,\n\tNOT_EXTENDED: 510,\n\tNETWORK_AUTHENTICATION_REQUIRED: 511,\n};\n\nexport type Status =\n\t| 100\n\t| 101\n\t| 102\n\t| 103\n\t| 200\n\t| 201\n\t| 202\n\t| 203\n\t| 204\n\t| 205\n\t| 206\n\t| 207\n\t| 208\n\t| 226\n\t| 300\n\t| 301\n\t| 302\n\t| 303\n\t| 304\n\t| 305\n\t| 306\n\t| 307\n\t| 308\n\t| 400\n\t| 401\n\t| 402\n\t| 403\n\t| 404\n\t| 405\n\t| 406\n\t| 407\n\t| 408\n\t| 409\n\t| 410\n\t| 411\n\t| 412\n\t| 413\n\t| 414\n\t| 415\n\t| 416\n\t| 417\n\t| 418\n\t| 421\n\t| 422\n\t| 423\n\t| 424\n\t| 425\n\t| 426\n\t| 428\n\t| 429\n\t| 431\n\t| 451\n\t| 500\n\t| 501\n\t| 502\n\t| 503\n\t| 504\n\t| 505\n\t| 506\n\t| 507\n\t| 508\n\t| 510\n\t| 511;\n\nclass InternalAPIError extends Error {\n\tconstructor(\n\t\tpublic status: keyof typeof statusCodes | Status = \"INTERNAL_SERVER_ERROR\",\n\t\tpublic body:\n\t\t\t| ({\n\t\t\t\t\tmessage?: string;\n\t\t\t\t\tcode?: string;\n\t\t\t\t\tcause?: unknown;\n\t\t\t } & Record<string, any>)\n\t\t\t| undefined = undefined,\n\t\tpublic headers: HeadersInit = {},\n\t\tpublic statusCode = typeof status === \"number\" ? status : statusCodes[status],\n\t) {\n\t\tsuper(\n\t\t\tbody?.message,\n\t\t\tbody?.cause\n\t\t\t\t? {\n\t\t\t\t\t\tcause: body.cause,\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.name = \"APIError\";\n\t\tthis.status = status;\n\t\tthis.headers = headers;\n\t\tthis.statusCode = statusCode;\n\t\tthis.body = body\n\t\t\t? {\n\t\t\t\t\tcode: body?.message\n\t\t\t\t\t\t?.toUpperCase()\n\t\t\t\t\t\t.replace(/ /g, \"_\")\n\t\t\t\t\t\t.replace(/[^A-Z0-9_]/g, \"\"),\n\t\t\t\t\t...body,\n\t\t\t\t}\n\t\t\t: undefined;\n\t}\n}\n\nexport class ValidationError extends InternalAPIError {\n\tconstructor(\n\t\tpublic message: string,\n\t\tpublic issues: readonly StandardSchemaV1.Issue[],\n\t) {\n\t\tsuper(400, {\n\t\t\tmessage: message,\n\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t});\n\n\t\tthis.issues = issues;\n\t}\n}\n\nexport class BetterCallError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"BetterCallError\";\n\t}\n}\n\nexport type APIError = InstanceType<typeof InternalAPIError>;\nexport const APIError = makeErrorForHideStackFrame(InternalAPIError, Error);\n"],"mappings":";;AAEA,SAAS,iCAAiC;CACzC,MAAM,OAAO,OAAO,yBAAyB,OAAO,kBAAkB;AACtE,KAAI,SAAS,OACZ,QAAO,OAAO,aAAa,MAAM;AAGlC,QAAO,OAAO,UAAU,eAAe,KAAK,MAAM,WAAW,GAC1D,KAAK,WACL,KAAK,QAAQ;;;;;AAMjB,SAAgB,wBAAwB,OAAuB;CAC9D,MAAM,QAAQ,MAAM,MAAM,YAAY;AACtC,KAAI,MAAM,UAAU,EACnB,QAAO;AAER,OAAM,OAAO,GAAG,EAAE;AAClB,QAAO,MAAM,KAAK,YAAY;;;;;AAO/B,SAAgB,2BACf,MACA,OAGC;CACD,MAAM,6BAA6B,KAAK;EACvC;EAEA,YAAY,GAAG,MAAa;AAC3B,OAAI,gCAAgC,EAAE;IACrC,MAAM,QAAQ,MAAM;AACpB,UAAM,kBAAkB;AACxB,UAAM,GAAG,KAAK;AACd,UAAM,kBAAkB;SAExB,OAAM,GAAG,KAAK;GAEf,MAAM,yBAAQ,IAAI,OAAO,EAAC;AAC1B,OAAI,MACH,OAAKA,cAAe,wBAAwB,MAAM,QAAQ,UAAU,KAAK,KAAK,CAAC;;EAKjF,IAAI,aAAa;AAChB,UAAO,MAAKA;;;AAMd,QAAO,eAAe,qBAAqB,WAAW,eAAe;EACpE,MAAM;AACL,UAAO;;EAER,YAAY;EACZ,cAAc;EACd,CAAC;AAEF,QAAO;;AAGR,MAAa,cAAc;CAC1B,IAAI;CACJ,SAAS;CACT,UAAU;CACV,YAAY;CACZ,kBAAkB;CAClB,mBAAmB;CACnB,OAAO;CACP,WAAW;CACX,cAAc;CACd,oBAAoB;CACpB,aAAa;CACb,cAAc;CACd,kBAAkB;CAClB,WAAW;CACX,WAAW;CACX,oBAAoB;CACpB,gBAAgB;CAChB,+BAA+B;CAC/B,iBAAiB;CACjB,UAAU;CACV,MAAM;CACN,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,cAAc;CACd,wBAAwB;CACxB,uBAAuB;CACvB,oBAAoB;CACpB,gBAAgB;CAChB,qBAAqB;CACrB,sBAAsB;CACtB,QAAQ;CACR,mBAAmB;CACnB,WAAW;CACX,kBAAkB;CAClB,uBAAuB;CACvB,mBAAmB;CACnB,iCAAiC;CACjC,+BAA+B;CAC/B,uBAAuB;CACvB,iBAAiB;CACjB,aAAa;CACb,qBAAqB;CACrB,iBAAiB;CACjB,4BAA4B;CAC5B,yBAAyB;CACzB,sBAAsB;CACtB,eAAe;CACf,cAAc;CACd,iCAAiC;CACjC;AAmED,IAAM,mBAAN,cAA+B,MAAM;CACpC,YACC,AAAOC,SAA4C,yBACnD,AAAOC,OAMQ,QACf,AAAOC,UAAuB,EAAE,EAChC,AAAO,aAAa,OAAO,WAAW,WAAW,SAAS,YAAY,SACrE;AACD,QACC,MAAM,SACN,MAAM,QACH,EACA,OAAO,KAAK,OACZ,GACA,OACH;EAlBM;EACA;EAOA;EACA;AAUP,OAAK,OAAO;AACZ,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,aAAa;AAClB,OAAK,OAAO,OACT;GACA,MAAM,MAAM,SACT,aAAa,CACd,QAAQ,MAAM,IAAI,CAClB,QAAQ,eAAe,GAAG;GAC5B,GAAG;GACH,GACA;;;AAIL,IAAa,kBAAb,cAAqC,iBAAiB;CACrD,YACC,AAAOC,SACP,AAAOC,QACN;AACD,QAAM,KAAK;GACD;GACT,MAAM;GACN,CAAC;EANK;EACA;AAOP,OAAK,SAAS;;;AAIhB,IAAa,kBAAb,cAAqC,MAAM;CAC1C,YAAY,SAAiB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO;;;AAKd,MAAa,WAAW,2BAA2B,kBAAkB,MAAM"}
@@ -0,0 +1,157 @@
1
+ //#region src/standard-schema.d.ts
2
+ /** The Standard Schema interface. */
3
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
4
+ /** The Standard Schema properties. */
5
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
6
+ }
7
+ declare namespace StandardSchemaV1 {
8
+ /** The Standard Schema properties interface. */
9
+ interface Props<Input = unknown, Output = Input> {
10
+ /** The version number of the standard. */
11
+ readonly version: 1;
12
+ /** The vendor name of the schema library. */
13
+ readonly vendor: string;
14
+ /** Validates unknown input values. */
15
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
16
+ /** Inferred types associated with the schema. */
17
+ readonly types?: Types<Input, Output> | undefined;
18
+ }
19
+ /** The result interface of the validate function. */
20
+ type Result<Output> = SuccessResult<Output> | FailureResult;
21
+ /** The result interface if validation succeeds. */
22
+ interface SuccessResult<Output> {
23
+ /** The typed output value. */
24
+ readonly value: Output;
25
+ /** The non-existent issues. */
26
+ readonly issues?: undefined;
27
+ }
28
+ /** The result interface if validation fails. */
29
+ interface FailureResult {
30
+ /** The issues of failed validation. */
31
+ readonly issues: ReadonlyArray<Issue>;
32
+ }
33
+ /** The issue interface of the failure output. */
34
+ interface Issue {
35
+ /** The error message of the issue. */
36
+ readonly message: string;
37
+ /** The path of the issue, if any. */
38
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
39
+ }
40
+ /** The path segment interface of the issue. */
41
+ interface PathSegment {
42
+ /** The key representing a path segment. */
43
+ readonly key: PropertyKey;
44
+ }
45
+ /** The Standard Schema types interface. */
46
+ interface Types<Input = unknown, Output = Input> {
47
+ /** The input type of the schema. */
48
+ readonly input: Input;
49
+ /** The output type of the schema. */
50
+ readonly output: Output;
51
+ }
52
+ /** Infers the input type of a Standard Schema. */
53
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
54
+ /** Infers the output type of a Standard Schema. */
55
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
56
+ }
57
+ //#endregion
58
+ //#region src/error.d.ts
59
+ /**
60
+ * Hide internal stack frames from the error stack trace.
61
+ */
62
+ declare function hideInternalStackFrames(stack: string): string;
63
+ /**
64
+ * Creates a custom error class that hides stack frames.
65
+ */
66
+ declare function makeErrorForHideStackFrame<B extends new (...args: any[]) => Error>(Base: B, clazz: any): {
67
+ new (...args: ConstructorParameters<B>): InstanceType<B> & {
68
+ errorStack: string | undefined;
69
+ };
70
+ };
71
+ declare const statusCodes: {
72
+ OK: number;
73
+ CREATED: number;
74
+ ACCEPTED: number;
75
+ NO_CONTENT: number;
76
+ MULTIPLE_CHOICES: number;
77
+ MOVED_PERMANENTLY: number;
78
+ FOUND: number;
79
+ SEE_OTHER: number;
80
+ NOT_MODIFIED: number;
81
+ TEMPORARY_REDIRECT: number;
82
+ BAD_REQUEST: number;
83
+ UNAUTHORIZED: number;
84
+ PAYMENT_REQUIRED: number;
85
+ FORBIDDEN: number;
86
+ NOT_FOUND: number;
87
+ METHOD_NOT_ALLOWED: number;
88
+ NOT_ACCEPTABLE: number;
89
+ PROXY_AUTHENTICATION_REQUIRED: number;
90
+ REQUEST_TIMEOUT: number;
91
+ CONFLICT: number;
92
+ GONE: number;
93
+ LENGTH_REQUIRED: number;
94
+ PRECONDITION_FAILED: number;
95
+ PAYLOAD_TOO_LARGE: number;
96
+ URI_TOO_LONG: number;
97
+ UNSUPPORTED_MEDIA_TYPE: number;
98
+ RANGE_NOT_SATISFIABLE: number;
99
+ EXPECTATION_FAILED: number;
100
+ "I'M_A_TEAPOT": number;
101
+ MISDIRECTED_REQUEST: number;
102
+ UNPROCESSABLE_ENTITY: number;
103
+ LOCKED: number;
104
+ FAILED_DEPENDENCY: number;
105
+ TOO_EARLY: number;
106
+ UPGRADE_REQUIRED: number;
107
+ PRECONDITION_REQUIRED: number;
108
+ TOO_MANY_REQUESTS: number;
109
+ REQUEST_HEADER_FIELDS_TOO_LARGE: number;
110
+ UNAVAILABLE_FOR_LEGAL_REASONS: number;
111
+ INTERNAL_SERVER_ERROR: number;
112
+ NOT_IMPLEMENTED: number;
113
+ BAD_GATEWAY: number;
114
+ SERVICE_UNAVAILABLE: number;
115
+ GATEWAY_TIMEOUT: number;
116
+ HTTP_VERSION_NOT_SUPPORTED: number;
117
+ VARIANT_ALSO_NEGOTIATES: number;
118
+ INSUFFICIENT_STORAGE: number;
119
+ LOOP_DETECTED: number;
120
+ NOT_EXTENDED: number;
121
+ NETWORK_AUTHENTICATION_REQUIRED: number;
122
+ };
123
+ type Status = 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
124
+ declare class InternalAPIError extends Error {
125
+ status: keyof typeof statusCodes | Status;
126
+ body: ({
127
+ message?: string;
128
+ code?: string;
129
+ cause?: unknown;
130
+ } & Record<string, any>) | undefined;
131
+ headers: HeadersInit;
132
+ statusCode: number;
133
+ constructor(status?: keyof typeof statusCodes | Status, body?: ({
134
+ message?: string;
135
+ code?: string;
136
+ cause?: unknown;
137
+ } & Record<string, any>) | undefined, headers?: HeadersInit, statusCode?: number);
138
+ }
139
+ declare class ValidationError extends InternalAPIError {
140
+ message: string;
141
+ issues: readonly StandardSchemaV1.Issue[];
142
+ constructor(message: string, issues: readonly StandardSchemaV1.Issue[]);
143
+ }
144
+ declare class BetterCallError extends Error {
145
+ constructor(message: string);
146
+ }
147
+ type APIError = InstanceType<typeof InternalAPIError>;
148
+ declare const APIError: new (status?: "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED" | Status | undefined, body?: ({
149
+ message?: string;
150
+ code?: string;
151
+ cause?: unknown;
152
+ } & Record<string, any>) | undefined, headers?: HeadersInit | undefined, statusCode?: number | undefined) => InternalAPIError & {
153
+ errorStack: string | undefined;
154
+ };
155
+ //#endregion
156
+ export { hideInternalStackFrames as a, StandardSchemaV1 as c, ValidationError as i, BetterCallError as n, makeErrorForHideStackFrame as o, Status as r, statusCodes as s, APIError as t };
157
+ //# sourceMappingURL=error2.d.cts.map
@@ -0,0 +1,157 @@
1
+ //#region src/standard-schema.d.ts
2
+ /** The Standard Schema interface. */
3
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
4
+ /** The Standard Schema properties. */
5
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
6
+ }
7
+ declare namespace StandardSchemaV1 {
8
+ /** The Standard Schema properties interface. */
9
+ interface Props<Input = unknown, Output = Input> {
10
+ /** The version number of the standard. */
11
+ readonly version: 1;
12
+ /** The vendor name of the schema library. */
13
+ readonly vendor: string;
14
+ /** Validates unknown input values. */
15
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
16
+ /** Inferred types associated with the schema. */
17
+ readonly types?: Types<Input, Output> | undefined;
18
+ }
19
+ /** The result interface of the validate function. */
20
+ type Result<Output> = SuccessResult<Output> | FailureResult;
21
+ /** The result interface if validation succeeds. */
22
+ interface SuccessResult<Output> {
23
+ /** The typed output value. */
24
+ readonly value: Output;
25
+ /** The non-existent issues. */
26
+ readonly issues?: undefined;
27
+ }
28
+ /** The result interface if validation fails. */
29
+ interface FailureResult {
30
+ /** The issues of failed validation. */
31
+ readonly issues: ReadonlyArray<Issue>;
32
+ }
33
+ /** The issue interface of the failure output. */
34
+ interface Issue {
35
+ /** The error message of the issue. */
36
+ readonly message: string;
37
+ /** The path of the issue, if any. */
38
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
39
+ }
40
+ /** The path segment interface of the issue. */
41
+ interface PathSegment {
42
+ /** The key representing a path segment. */
43
+ readonly key: PropertyKey;
44
+ }
45
+ /** The Standard Schema types interface. */
46
+ interface Types<Input = unknown, Output = Input> {
47
+ /** The input type of the schema. */
48
+ readonly input: Input;
49
+ /** The output type of the schema. */
50
+ readonly output: Output;
51
+ }
52
+ /** Infers the input type of a Standard Schema. */
53
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
54
+ /** Infers the output type of a Standard Schema. */
55
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
56
+ }
57
+ //#endregion
58
+ //#region src/error.d.ts
59
+ /**
60
+ * Hide internal stack frames from the error stack trace.
61
+ */
62
+ declare function hideInternalStackFrames(stack: string): string;
63
+ /**
64
+ * Creates a custom error class that hides stack frames.
65
+ */
66
+ declare function makeErrorForHideStackFrame<B extends new (...args: any[]) => Error>(Base: B, clazz: any): {
67
+ new (...args: ConstructorParameters<B>): InstanceType<B> & {
68
+ errorStack: string | undefined;
69
+ };
70
+ };
71
+ declare const statusCodes: {
72
+ OK: number;
73
+ CREATED: number;
74
+ ACCEPTED: number;
75
+ NO_CONTENT: number;
76
+ MULTIPLE_CHOICES: number;
77
+ MOVED_PERMANENTLY: number;
78
+ FOUND: number;
79
+ SEE_OTHER: number;
80
+ NOT_MODIFIED: number;
81
+ TEMPORARY_REDIRECT: number;
82
+ BAD_REQUEST: number;
83
+ UNAUTHORIZED: number;
84
+ PAYMENT_REQUIRED: number;
85
+ FORBIDDEN: number;
86
+ NOT_FOUND: number;
87
+ METHOD_NOT_ALLOWED: number;
88
+ NOT_ACCEPTABLE: number;
89
+ PROXY_AUTHENTICATION_REQUIRED: number;
90
+ REQUEST_TIMEOUT: number;
91
+ CONFLICT: number;
92
+ GONE: number;
93
+ LENGTH_REQUIRED: number;
94
+ PRECONDITION_FAILED: number;
95
+ PAYLOAD_TOO_LARGE: number;
96
+ URI_TOO_LONG: number;
97
+ UNSUPPORTED_MEDIA_TYPE: number;
98
+ RANGE_NOT_SATISFIABLE: number;
99
+ EXPECTATION_FAILED: number;
100
+ "I'M_A_TEAPOT": number;
101
+ MISDIRECTED_REQUEST: number;
102
+ UNPROCESSABLE_ENTITY: number;
103
+ LOCKED: number;
104
+ FAILED_DEPENDENCY: number;
105
+ TOO_EARLY: number;
106
+ UPGRADE_REQUIRED: number;
107
+ PRECONDITION_REQUIRED: number;
108
+ TOO_MANY_REQUESTS: number;
109
+ REQUEST_HEADER_FIELDS_TOO_LARGE: number;
110
+ UNAVAILABLE_FOR_LEGAL_REASONS: number;
111
+ INTERNAL_SERVER_ERROR: number;
112
+ NOT_IMPLEMENTED: number;
113
+ BAD_GATEWAY: number;
114
+ SERVICE_UNAVAILABLE: number;
115
+ GATEWAY_TIMEOUT: number;
116
+ HTTP_VERSION_NOT_SUPPORTED: number;
117
+ VARIANT_ALSO_NEGOTIATES: number;
118
+ INSUFFICIENT_STORAGE: number;
119
+ LOOP_DETECTED: number;
120
+ NOT_EXTENDED: number;
121
+ NETWORK_AUTHENTICATION_REQUIRED: number;
122
+ };
123
+ type Status = 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
124
+ declare class InternalAPIError extends Error {
125
+ status: keyof typeof statusCodes | Status;
126
+ body: ({
127
+ message?: string;
128
+ code?: string;
129
+ cause?: unknown;
130
+ } & Record<string, any>) | undefined;
131
+ headers: HeadersInit;
132
+ statusCode: number;
133
+ constructor(status?: keyof typeof statusCodes | Status, body?: ({
134
+ message?: string;
135
+ code?: string;
136
+ cause?: unknown;
137
+ } & Record<string, any>) | undefined, headers?: HeadersInit, statusCode?: number);
138
+ }
139
+ declare class ValidationError extends InternalAPIError {
140
+ message: string;
141
+ issues: readonly StandardSchemaV1.Issue[];
142
+ constructor(message: string, issues: readonly StandardSchemaV1.Issue[]);
143
+ }
144
+ declare class BetterCallError extends Error {
145
+ constructor(message: string);
146
+ }
147
+ type APIError = InstanceType<typeof InternalAPIError>;
148
+ declare const APIError: new (status?: "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED" | Status | undefined, body?: ({
149
+ message?: string;
150
+ code?: string;
151
+ cause?: unknown;
152
+ } & Record<string, any>) | undefined, headers?: HeadersInit | undefined, statusCode?: number | undefined) => InternalAPIError & {
153
+ errorStack: string | undefined;
154
+ };
155
+ //#endregion
156
+ export { hideInternalStackFrames as a, StandardSchemaV1 as c, ValidationError as i, BetterCallError as n, makeErrorForHideStackFrame as o, Status as r, statusCodes as s, APIError as t };
157
+ //# sourceMappingURL=error2.d.ts.map
package/dist/error2.js ADDED
@@ -0,0 +1,135 @@
1
+ //#region src/error.ts
2
+ function isErrorStackTraceLimitWritable() {
3
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
4
+ if (desc === void 0) return Object.isExtensible(Error);
5
+ return Object.prototype.hasOwnProperty.call(desc, "writable") ? desc.writable : desc.set !== void 0;
6
+ }
7
+ /**
8
+ * Hide internal stack frames from the error stack trace.
9
+ */
10
+ function hideInternalStackFrames(stack) {
11
+ const lines = stack.split("\n at ");
12
+ if (lines.length <= 1) return stack;
13
+ lines.splice(1, 1);
14
+ return lines.join("\n at ");
15
+ }
16
+ /**
17
+ * Creates a custom error class that hides stack frames.
18
+ */
19
+ function makeErrorForHideStackFrame(Base, clazz) {
20
+ class HideStackFramesError extends Base {
21
+ #hiddenStack;
22
+ constructor(...args) {
23
+ if (isErrorStackTraceLimitWritable()) {
24
+ const limit = Error.stackTraceLimit;
25
+ Error.stackTraceLimit = 0;
26
+ super(...args);
27
+ Error.stackTraceLimit = limit;
28
+ } else super(...args);
29
+ const stack = (/* @__PURE__ */ new Error()).stack;
30
+ if (stack) this.#hiddenStack = hideInternalStackFrames(stack.replace(/^Error/, this.name));
31
+ }
32
+ get errorStack() {
33
+ return this.#hiddenStack;
34
+ }
35
+ }
36
+ Object.defineProperty(HideStackFramesError.prototype, "constructor", {
37
+ get() {
38
+ return clazz;
39
+ },
40
+ enumerable: false,
41
+ configurable: true
42
+ });
43
+ return HideStackFramesError;
44
+ }
45
+ const statusCodes = {
46
+ OK: 200,
47
+ CREATED: 201,
48
+ ACCEPTED: 202,
49
+ NO_CONTENT: 204,
50
+ MULTIPLE_CHOICES: 300,
51
+ MOVED_PERMANENTLY: 301,
52
+ FOUND: 302,
53
+ SEE_OTHER: 303,
54
+ NOT_MODIFIED: 304,
55
+ TEMPORARY_REDIRECT: 307,
56
+ BAD_REQUEST: 400,
57
+ UNAUTHORIZED: 401,
58
+ PAYMENT_REQUIRED: 402,
59
+ FORBIDDEN: 403,
60
+ NOT_FOUND: 404,
61
+ METHOD_NOT_ALLOWED: 405,
62
+ NOT_ACCEPTABLE: 406,
63
+ PROXY_AUTHENTICATION_REQUIRED: 407,
64
+ REQUEST_TIMEOUT: 408,
65
+ CONFLICT: 409,
66
+ GONE: 410,
67
+ LENGTH_REQUIRED: 411,
68
+ PRECONDITION_FAILED: 412,
69
+ PAYLOAD_TOO_LARGE: 413,
70
+ URI_TOO_LONG: 414,
71
+ UNSUPPORTED_MEDIA_TYPE: 415,
72
+ RANGE_NOT_SATISFIABLE: 416,
73
+ EXPECTATION_FAILED: 417,
74
+ "I'M_A_TEAPOT": 418,
75
+ MISDIRECTED_REQUEST: 421,
76
+ UNPROCESSABLE_ENTITY: 422,
77
+ LOCKED: 423,
78
+ FAILED_DEPENDENCY: 424,
79
+ TOO_EARLY: 425,
80
+ UPGRADE_REQUIRED: 426,
81
+ PRECONDITION_REQUIRED: 428,
82
+ TOO_MANY_REQUESTS: 429,
83
+ REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
84
+ UNAVAILABLE_FOR_LEGAL_REASONS: 451,
85
+ INTERNAL_SERVER_ERROR: 500,
86
+ NOT_IMPLEMENTED: 501,
87
+ BAD_GATEWAY: 502,
88
+ SERVICE_UNAVAILABLE: 503,
89
+ GATEWAY_TIMEOUT: 504,
90
+ HTTP_VERSION_NOT_SUPPORTED: 505,
91
+ VARIANT_ALSO_NEGOTIATES: 506,
92
+ INSUFFICIENT_STORAGE: 507,
93
+ LOOP_DETECTED: 508,
94
+ NOT_EXTENDED: 510,
95
+ NETWORK_AUTHENTICATION_REQUIRED: 511
96
+ };
97
+ var InternalAPIError = class extends Error {
98
+ constructor(status = "INTERNAL_SERVER_ERROR", body = void 0, headers = {}, statusCode = typeof status === "number" ? status : statusCodes[status]) {
99
+ super(body?.message, body?.cause ? { cause: body.cause } : void 0);
100
+ this.status = status;
101
+ this.body = body;
102
+ this.headers = headers;
103
+ this.statusCode = statusCode;
104
+ this.name = "APIError";
105
+ this.status = status;
106
+ this.headers = headers;
107
+ this.statusCode = statusCode;
108
+ this.body = body ? {
109
+ code: body?.message?.toUpperCase().replace(/ /g, "_").replace(/[^A-Z0-9_]/g, ""),
110
+ ...body
111
+ } : void 0;
112
+ }
113
+ };
114
+ var ValidationError = class extends InternalAPIError {
115
+ constructor(message, issues) {
116
+ super(400, {
117
+ message,
118
+ code: "VALIDATION_ERROR"
119
+ });
120
+ this.message = message;
121
+ this.issues = issues;
122
+ this.issues = issues;
123
+ }
124
+ };
125
+ var BetterCallError = class extends Error {
126
+ constructor(message) {
127
+ super(message);
128
+ this.name = "BetterCallError";
129
+ }
130
+ };
131
+ const APIError = makeErrorForHideStackFrame(InternalAPIError, Error);
132
+
133
+ //#endregion
134
+ export { makeErrorForHideStackFrame as a, hideInternalStackFrames as i, BetterCallError as n, statusCodes as o, ValidationError as r, APIError as t };
135
+ //# sourceMappingURL=error2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error2.js","names":["#hiddenStack","status: keyof typeof statusCodes | Status","body:\n\t\t\t| ({\n\t\t\t\t\tmessage?: string;\n\t\t\t\t\tcode?: string;\n\t\t\t\t\tcause?: unknown;\n\t\t\t } & Record<string, any>)\n\t\t\t| undefined","headers: HeadersInit","message: string","issues: readonly StandardSchemaV1.Issue[]"],"sources":["../src/error.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"./standard-schema\";\n// https://github.com/nodejs/node/blob/360f7cc7867b43344aac00564286b895e15f21d7/lib/internal/errors.js#L246C1-L261C2\nfunction isErrorStackTraceLimitWritable() {\n\tconst desc = Object.getOwnPropertyDescriptor(Error, \"stackTraceLimit\");\n\tif (desc === undefined) {\n\t\treturn Object.isExtensible(Error);\n\t}\n\n\treturn Object.prototype.hasOwnProperty.call(desc, \"writable\")\n\t\t? desc.writable\n\t\t: desc.set !== undefined;\n}\n\n/**\n * Hide internal stack frames from the error stack trace.\n */\nexport function hideInternalStackFrames(stack: string): string {\n\tconst lines = stack.split(\"\\n at \");\n\tif (lines.length <= 1) {\n\t\treturn stack;\n\t}\n\tlines.splice(1, 1);\n\treturn lines.join(\"\\n at \");\n}\n\n// https://github.com/nodejs/node/blob/360f7cc7867b43344aac00564286b895e15f21d7/lib/internal/errors.js#L411-L432\n/**\n * Creates a custom error class that hides stack frames.\n */\nexport function makeErrorForHideStackFrame<B extends new (...args: any[]) => Error>(\n\tBase: B,\n\tclazz: any,\n): {\n\tnew (...args: ConstructorParameters<B>): InstanceType<B> & { errorStack: string | undefined };\n} {\n\tclass HideStackFramesError extends Base {\n\t\t#hiddenStack: string | undefined;\n\n\t\tconstructor(...args: any[]) {\n\t\t\tif (isErrorStackTraceLimitWritable()) {\n\t\t\t\tconst limit = Error.stackTraceLimit;\n\t\t\t\tError.stackTraceLimit = 0;\n\t\t\t\tsuper(...args);\n\t\t\t\tError.stackTraceLimit = limit;\n\t\t\t} else {\n\t\t\t\tsuper(...args);\n\t\t\t}\n\t\t\tconst stack = new Error().stack;\n\t\t\tif (stack) {\n\t\t\t\tthis.#hiddenStack = hideInternalStackFrames(stack.replace(/^Error/, this.name));\n\t\t\t}\n\t\t}\n\n\t\t// use `getter` here to avoid the stack trace being captured by loggers\n\t\tget errorStack() {\n\t\t\treturn this.#hiddenStack;\n\t\t}\n\t}\n\n\t// This is a workaround for wpt tests that expect that the error\n\t// constructor has a `name` property of the base class.\n\tObject.defineProperty(HideStackFramesError.prototype, \"constructor\", {\n\t\tget() {\n\t\t\treturn clazz;\n\t\t},\n\t\tenumerable: false,\n\t\tconfigurable: true,\n\t});\n\n\treturn HideStackFramesError as any;\n}\n\nexport const statusCodes = {\n\tOK: 200,\n\tCREATED: 201,\n\tACCEPTED: 202,\n\tNO_CONTENT: 204,\n\tMULTIPLE_CHOICES: 300,\n\tMOVED_PERMANENTLY: 301,\n\tFOUND: 302,\n\tSEE_OTHER: 303,\n\tNOT_MODIFIED: 304,\n\tTEMPORARY_REDIRECT: 307,\n\tBAD_REQUEST: 400,\n\tUNAUTHORIZED: 401,\n\tPAYMENT_REQUIRED: 402,\n\tFORBIDDEN: 403,\n\tNOT_FOUND: 404,\n\tMETHOD_NOT_ALLOWED: 405,\n\tNOT_ACCEPTABLE: 406,\n\tPROXY_AUTHENTICATION_REQUIRED: 407,\n\tREQUEST_TIMEOUT: 408,\n\tCONFLICT: 409,\n\tGONE: 410,\n\tLENGTH_REQUIRED: 411,\n\tPRECONDITION_FAILED: 412,\n\tPAYLOAD_TOO_LARGE: 413,\n\tURI_TOO_LONG: 414,\n\tUNSUPPORTED_MEDIA_TYPE: 415,\n\tRANGE_NOT_SATISFIABLE: 416,\n\tEXPECTATION_FAILED: 417,\n\t\"I'M_A_TEAPOT\": 418,\n\tMISDIRECTED_REQUEST: 421,\n\tUNPROCESSABLE_ENTITY: 422,\n\tLOCKED: 423,\n\tFAILED_DEPENDENCY: 424,\n\tTOO_EARLY: 425,\n\tUPGRADE_REQUIRED: 426,\n\tPRECONDITION_REQUIRED: 428,\n\tTOO_MANY_REQUESTS: 429,\n\tREQUEST_HEADER_FIELDS_TOO_LARGE: 431,\n\tUNAVAILABLE_FOR_LEGAL_REASONS: 451,\n\tINTERNAL_SERVER_ERROR: 500,\n\tNOT_IMPLEMENTED: 501,\n\tBAD_GATEWAY: 502,\n\tSERVICE_UNAVAILABLE: 503,\n\tGATEWAY_TIMEOUT: 504,\n\tHTTP_VERSION_NOT_SUPPORTED: 505,\n\tVARIANT_ALSO_NEGOTIATES: 506,\n\tINSUFFICIENT_STORAGE: 507,\n\tLOOP_DETECTED: 508,\n\tNOT_EXTENDED: 510,\n\tNETWORK_AUTHENTICATION_REQUIRED: 511,\n};\n\nexport type Status =\n\t| 100\n\t| 101\n\t| 102\n\t| 103\n\t| 200\n\t| 201\n\t| 202\n\t| 203\n\t| 204\n\t| 205\n\t| 206\n\t| 207\n\t| 208\n\t| 226\n\t| 300\n\t| 301\n\t| 302\n\t| 303\n\t| 304\n\t| 305\n\t| 306\n\t| 307\n\t| 308\n\t| 400\n\t| 401\n\t| 402\n\t| 403\n\t| 404\n\t| 405\n\t| 406\n\t| 407\n\t| 408\n\t| 409\n\t| 410\n\t| 411\n\t| 412\n\t| 413\n\t| 414\n\t| 415\n\t| 416\n\t| 417\n\t| 418\n\t| 421\n\t| 422\n\t| 423\n\t| 424\n\t| 425\n\t| 426\n\t| 428\n\t| 429\n\t| 431\n\t| 451\n\t| 500\n\t| 501\n\t| 502\n\t| 503\n\t| 504\n\t| 505\n\t| 506\n\t| 507\n\t| 508\n\t| 510\n\t| 511;\n\nclass InternalAPIError extends Error {\n\tconstructor(\n\t\tpublic status: keyof typeof statusCodes | Status = \"INTERNAL_SERVER_ERROR\",\n\t\tpublic body:\n\t\t\t| ({\n\t\t\t\t\tmessage?: string;\n\t\t\t\t\tcode?: string;\n\t\t\t\t\tcause?: unknown;\n\t\t\t } & Record<string, any>)\n\t\t\t| undefined = undefined,\n\t\tpublic headers: HeadersInit = {},\n\t\tpublic statusCode = typeof status === \"number\" ? status : statusCodes[status],\n\t) {\n\t\tsuper(\n\t\t\tbody?.message,\n\t\t\tbody?.cause\n\t\t\t\t? {\n\t\t\t\t\t\tcause: body.cause,\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.name = \"APIError\";\n\t\tthis.status = status;\n\t\tthis.headers = headers;\n\t\tthis.statusCode = statusCode;\n\t\tthis.body = body\n\t\t\t? {\n\t\t\t\t\tcode: body?.message\n\t\t\t\t\t\t?.toUpperCase()\n\t\t\t\t\t\t.replace(/ /g, \"_\")\n\t\t\t\t\t\t.replace(/[^A-Z0-9_]/g, \"\"),\n\t\t\t\t\t...body,\n\t\t\t\t}\n\t\t\t: undefined;\n\t}\n}\n\nexport class ValidationError extends InternalAPIError {\n\tconstructor(\n\t\tpublic message: string,\n\t\tpublic issues: readonly StandardSchemaV1.Issue[],\n\t) {\n\t\tsuper(400, {\n\t\t\tmessage: message,\n\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t});\n\n\t\tthis.issues = issues;\n\t}\n}\n\nexport class BetterCallError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"BetterCallError\";\n\t}\n}\n\nexport type APIError = InstanceType<typeof InternalAPIError>;\nexport const APIError = makeErrorForHideStackFrame(InternalAPIError, Error);\n"],"mappings":";AAEA,SAAS,iCAAiC;CACzC,MAAM,OAAO,OAAO,yBAAyB,OAAO,kBAAkB;AACtE,KAAI,SAAS,OACZ,QAAO,OAAO,aAAa,MAAM;AAGlC,QAAO,OAAO,UAAU,eAAe,KAAK,MAAM,WAAW,GAC1D,KAAK,WACL,KAAK,QAAQ;;;;;AAMjB,SAAgB,wBAAwB,OAAuB;CAC9D,MAAM,QAAQ,MAAM,MAAM,YAAY;AACtC,KAAI,MAAM,UAAU,EACnB,QAAO;AAER,OAAM,OAAO,GAAG,EAAE;AAClB,QAAO,MAAM,KAAK,YAAY;;;;;AAO/B,SAAgB,2BACf,MACA,OAGC;CACD,MAAM,6BAA6B,KAAK;EACvC;EAEA,YAAY,GAAG,MAAa;AAC3B,OAAI,gCAAgC,EAAE;IACrC,MAAM,QAAQ,MAAM;AACpB,UAAM,kBAAkB;AACxB,UAAM,GAAG,KAAK;AACd,UAAM,kBAAkB;SAExB,OAAM,GAAG,KAAK;GAEf,MAAM,yBAAQ,IAAI,OAAO,EAAC;AAC1B,OAAI,MACH,OAAKA,cAAe,wBAAwB,MAAM,QAAQ,UAAU,KAAK,KAAK,CAAC;;EAKjF,IAAI,aAAa;AAChB,UAAO,MAAKA;;;AAMd,QAAO,eAAe,qBAAqB,WAAW,eAAe;EACpE,MAAM;AACL,UAAO;;EAER,YAAY;EACZ,cAAc;EACd,CAAC;AAEF,QAAO;;AAGR,MAAa,cAAc;CAC1B,IAAI;CACJ,SAAS;CACT,UAAU;CACV,YAAY;CACZ,kBAAkB;CAClB,mBAAmB;CACnB,OAAO;CACP,WAAW;CACX,cAAc;CACd,oBAAoB;CACpB,aAAa;CACb,cAAc;CACd,kBAAkB;CAClB,WAAW;CACX,WAAW;CACX,oBAAoB;CACpB,gBAAgB;CAChB,+BAA+B;CAC/B,iBAAiB;CACjB,UAAU;CACV,MAAM;CACN,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,cAAc;CACd,wBAAwB;CACxB,uBAAuB;CACvB,oBAAoB;CACpB,gBAAgB;CAChB,qBAAqB;CACrB,sBAAsB;CACtB,QAAQ;CACR,mBAAmB;CACnB,WAAW;CACX,kBAAkB;CAClB,uBAAuB;CACvB,mBAAmB;CACnB,iCAAiC;CACjC,+BAA+B;CAC/B,uBAAuB;CACvB,iBAAiB;CACjB,aAAa;CACb,qBAAqB;CACrB,iBAAiB;CACjB,4BAA4B;CAC5B,yBAAyB;CACzB,sBAAsB;CACtB,eAAe;CACf,cAAc;CACd,iCAAiC;CACjC;AAmED,IAAM,mBAAN,cAA+B,MAAM;CACpC,YACC,AAAOC,SAA4C,yBACnD,AAAOC,OAMQ,QACf,AAAOC,UAAuB,EAAE,EAChC,AAAO,aAAa,OAAO,WAAW,WAAW,SAAS,YAAY,SACrE;AACD,QACC,MAAM,SACN,MAAM,QACH,EACA,OAAO,KAAK,OACZ,GACA,OACH;EAlBM;EACA;EAOA;EACA;AAUP,OAAK,OAAO;AACZ,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,aAAa;AAClB,OAAK,OAAO,OACT;GACA,MAAM,MAAM,SACT,aAAa,CACd,QAAQ,MAAM,IAAI,CAClB,QAAQ,eAAe,GAAG;GAC5B,GAAG;GACH,GACA;;;AAIL,IAAa,kBAAb,cAAqC,iBAAiB;CACrD,YACC,AAAOC,SACP,AAAOC,QACN;AACD,QAAM,KAAK;GACD;GACT,MAAM;GACN,CAAC;EANK;EACA;AAOP,OAAK,SAAS;;;AAIhB,IAAa,kBAAb,cAAqC,MAAM;CAC1C,YAAY,SAAiB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO;;;AAKd,MAAa,WAAW,2BAA2B,kBAAkB,MAAM"}