better-call 1.0.13 → 1.0.14

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/client.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BetterFetchOption, BetterFetchResponse } from '@better-fetch/fetch';
2
- import { j as Router, X as UnionToIntersection, b as Endpoint, U as HasRequiredKeys } from './router-BEp4ze3Q.cjs';
2
+ import { j as Router, X as UnionToIntersection, b as Endpoint, U as HasRequiredKeys } from './router-BcwNrqXF.cjs';
3
3
 
4
4
  type HasRequired<T extends {
5
5
  body?: any;
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BetterFetchOption, BetterFetchResponse } from '@better-fetch/fetch';
2
- import { j as Router, X as UnionToIntersection, b as Endpoint, U as HasRequiredKeys } from './router-BEp4ze3Q.js';
2
+ import { j as Router, X as UnionToIntersection, b as Endpoint, U as HasRequiredKeys } from './router-BcwNrqXF.js';
3
3
 
4
4
  type HasRequired<T extends {
5
5
  body?: any;
package/dist/index.cjs CHANGED
@@ -3,6 +3,9 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
6
9
  var __export = (target, all) => {
7
10
  for (var name in all)
8
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +19,10 @@ var __copyProps = (to, from, except, desc) => {
16
19
  return to;
17
20
  };
18
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
19
26
 
20
27
  // src/index.ts
21
28
  var src_exports = {};
@@ -37,6 +44,60 @@ __export(src_exports, {
37
44
  module.exports = __toCommonJS(src_exports);
38
45
 
39
46
  // src/error.ts
47
+ function isErrorStackTraceLimitWritable() {
48
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
49
+ if (desc === void 0) {
50
+ return Object.isExtensible(Error);
51
+ }
52
+ return Object.prototype.hasOwnProperty.call(desc, "writable") ? desc.writable : desc.set !== void 0;
53
+ }
54
+ var ErrorWithStack = class extends Error {
55
+ constructor() {
56
+ super();
57
+ this.name = "ErrorWithStack";
58
+ }
59
+ };
60
+ function hideInternalStackFrames(stack) {
61
+ const lines = stack.split("\n at ");
62
+ if (lines.length <= 1) {
63
+ return stack;
64
+ }
65
+ lines.splice(1, 1);
66
+ return lines.join("\n at ");
67
+ }
68
+ function makeErrorForHideStackFrame(Base, clazz) {
69
+ var _errorWithStack;
70
+ class HideStackFramesError extends Base {
71
+ // This is a workaround for wpt tests that expect that the error
72
+ // constructor has a `name` property of the base class.
73
+ get ["constructor"]() {
74
+ var __super = (...args) => {
75
+ super(...args);
76
+ __privateAdd(this, _errorWithStack);
77
+ return this;
78
+ };
79
+ return clazz;
80
+ }
81
+ constructor(...args2) {
82
+ if (isErrorStackTraceLimitWritable()) {
83
+ const limit = Error.stackTraceLimit;
84
+ Error.stackTraceLimit = 0;
85
+ __super(...args2);
86
+ Error.stackTraceLimit = limit;
87
+ } else {
88
+ __super(...args2);
89
+ }
90
+ __privateSet(this, _errorWithStack, new ErrorWithStack());
91
+ __privateGet(this, _errorWithStack).stack = hideInternalStackFrames(__privateGet(this, _errorWithStack).stack ?? "");
92
+ }
93
+ // use `getter` here to avoid the stack trace being captured by loggers
94
+ get errorWithStack() {
95
+ return __privateGet(this, _errorWithStack);
96
+ }
97
+ }
98
+ _errorWithStack = new WeakMap();
99
+ return HideStackFramesError;
100
+ }
40
101
  var _statusCode = {
41
102
  OK: 200,
42
103
  CREATED: 201,
@@ -89,9 +150,14 @@ var _statusCode = {
89
150
  NOT_EXTENDED: 510,
90
151
  NETWORK_AUTHENTICATION_REQUIRED: 511
91
152
  };
92
- var APIError = class extends Error {
153
+ var InternalAPIError = class extends Error {
93
154
  constructor(status = "INTERNAL_SERVER_ERROR", body = void 0, headers = {}, statusCode = typeof status === "number" ? status : _statusCode[status]) {
94
- super(body?.message);
155
+ super(
156
+ body?.message,
157
+ body?.cause ? {
158
+ cause: body.cause
159
+ } : void 0
160
+ );
95
161
  this.status = status;
96
162
  this.body = body;
97
163
  this.headers = headers;
@@ -104,9 +170,9 @@ var APIError = class extends Error {
104
170
  code: body?.message?.toUpperCase().replace(/ /g, "_").replace(/[^A-Z0-9_]/g, ""),
105
171
  ...body
106
172
  } : void 0;
107
- this.stack = "";
108
173
  }
109
174
  };
175
+ var APIError = makeErrorForHideStackFrame(InternalAPIError, Error);
110
176
 
111
177
  // src/utils.ts
112
178
  async function getBody(request) {