@datapos/datapos-shared 0.3.515 → 0.3.516

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.
@@ -1,124 +1,164 @@
1
1
  class i extends Error {
2
2
  locator;
3
3
  /** Logical source of the error. */
4
- constructor(o, t, r) {
5
- super(o, r), this.name = new.target.name, this.locator = t;
4
+ constructor(n, o, e) {
5
+ super(n, e), this.name = new.target.name, this.locator = o;
6
6
  }
7
7
  }
8
8
  class a extends i {
9
9
  }
10
- class g extends a {
10
+ class d extends a {
11
11
  }
12
- class p extends a {
12
+ class f extends a {
13
13
  }
14
14
  class c extends a {
15
15
  body;
16
16
  /** Sanitized HTTP response body. */
17
- constructor(o, t, r, n) {
18
- super(o, t, n), this.name = new.target.name, this.body = E(r ?? void 0);
17
+ constructor(n, o, e, t) {
18
+ super(n, o, t), this.name = new.target.name, this.body = b(e ?? void 0);
19
19
  }
20
20
  }
21
- class y extends i {
21
+ class g extends i {
22
22
  }
23
- class m extends a {
23
+ class l extends a {
24
24
  componentName;
25
25
  /** Vue component name, if available. */
26
26
  info;
27
27
  /** Vue error info string. */
28
- constructor(o, t, r, n, s) {
29
- super(o, t, s), this.name = new.target.name, this.info = r, this.componentName = n;
28
+ constructor(n, o, e, t, s) {
29
+ super(n, o, s), this.name = new.target.name, this.info = e, this.componentName = t;
30
30
  }
31
31
  }
32
- class w extends a {
32
+ class E extends a {
33
33
  }
34
- class h extends a {
34
+ class u extends a {
35
35
  }
36
- async function b(e, o, t) {
37
- const r = ` - ${e.statusText}`, n = `${o} Response status '${e.status}${e.statusText ? r : ""}' received.`;
36
+ async function y(r, n, o) {
37
+ const e = ` - ${r.statusText}`, t = `${n} Response status '${r.status}${r.statusText ? e : ""}' received.`;
38
38
  let s;
39
39
  try {
40
- s = await e.text();
41
- } catch (d) {
42
- s = `<body unavailable: ${l(d).message}>`;
40
+ s = await r.text();
41
+ } catch (m) {
42
+ s = `<body unavailable: ${w(m).message}>`;
43
43
  }
44
- return new c(n, t, s);
44
+ return new c(t, o, s);
45
45
  }
46
- function k(e) {
47
- return e.map((o) => o.message).join(" ");
46
+ function h(r) {
47
+ return r.map((n) => n.message).join(" ");
48
48
  }
49
- function x(e) {
49
+ function R(r) {
50
50
  try {
51
- e();
51
+ r();
52
52
  } catch {
53
53
  }
54
54
  }
55
- function l(e) {
56
- if (e instanceof Error) return e;
57
- if (typeof e == "string") return new Error(e);
58
- if (typeof e == "number" || typeof e == "boolean" || typeof e == "bigint") return new Error(String(e));
59
- if (typeof e == "symbol") return new Error(e.description ?? "Unknown error");
60
- if (e != null && typeof e == "object")
55
+ function w(r) {
56
+ if (r instanceof Error) return r;
57
+ if (typeof r == "string") return new Error(r);
58
+ if (typeof r == "number" || typeof r == "boolean" || typeof r == "bigint") return new Error(String(r));
59
+ if (typeof r == "symbol") return new Error(r.description ?? "Unknown error");
60
+ if (r != null && typeof r == "object")
61
61
  try {
62
- return new Error(JSON.stringify(e));
62
+ return new Error(JSON.stringify(r));
63
63
  } catch {
64
64
  return new Error("Unknown error");
65
65
  }
66
66
  return new Error("Unknown error");
67
67
  }
68
- function R(e) {
69
- const o = /* @__PURE__ */ new Set(), t = [];
70
- let r = e;
71
- for (; r != null && !o.has(r); ) {
72
- o.add(r);
73
- let n;
74
- if (r instanceof c)
75
- n = { componentName: void 0, body: r.body, info: void 0, locator: r.locator, message: r.message, name: r.name, stack: r.stack }, r = r.cause;
76
- else if (r instanceof m)
77
- n = {
78
- componentName: r.componentName,
68
+ function x(r) {
69
+ const n = /* @__PURE__ */ new Set(), o = [];
70
+ let e = r;
71
+ for (; e != null && !n.has(e); ) {
72
+ n.add(e);
73
+ let t;
74
+ if (e instanceof c)
75
+ t = { componentName: void 0, body: e.body, info: void 0, locator: e.locator, message: e.message, name: e.name, stack: e.stack }, e = e.cause;
76
+ else if (e instanceof l)
77
+ t = {
78
+ componentName: e.componentName,
79
79
  body: void 0,
80
- info: r.info,
81
- locator: r.locator,
82
- message: r.message,
83
- name: r.name,
84
- stack: r.stack
85
- }, r = r.cause;
86
- else if (r instanceof i)
87
- n = { componentName: void 0, body: void 0, info: void 0, locator: r.locator, message: r.message, name: r.name, stack: r.stack }, r = r.cause;
88
- else if (r instanceof Error) {
89
- const s = r;
90
- n = { componentName: void 0, body: void 0, info: void 0, locator: "", message: s.message, name: s.name, stack: s.stack }, r = s.cause;
80
+ info: e.info,
81
+ locator: e.locator,
82
+ message: e.message,
83
+ name: e.name,
84
+ stack: e.stack
85
+ }, e = e.cause;
86
+ else if (e instanceof i)
87
+ t = { componentName: void 0, body: void 0, info: void 0, locator: e.locator, message: e.message, name: e.name, stack: e.stack }, e = e.cause;
88
+ else if (e instanceof Error) {
89
+ const s = e;
90
+ t = { componentName: void 0, body: void 0, info: void 0, locator: "", message: s.message, name: s.name, stack: s.stack }, e = s.cause;
91
91
  } else
92
- n = { componentName: void 0, body: void 0, info: void 0, locator: "", message: f(r), name: "Error", stack: void 0 }, r = void 0;
93
- /(?:\.{3}|[.!?])$/.test(n.message) || (n.message += "."), t.push(n);
92
+ t = { componentName: void 0, body: void 0, info: void 0, locator: "", message: p(e), name: "Error", stack: void 0 }, e = void 0;
93
+ /(?:\.{3}|[.!?])$/.test(t.message) || (t.message += "."), o.push(t);
94
94
  }
95
- return t;
95
+ return o;
96
+ }
97
+ function v(r) {
98
+ if (r.length === 0) return;
99
+ let n;
100
+ for (const o of r.toReversed()) {
101
+ let e;
102
+ if (o.body !== void 0)
103
+ e = new c(o.message, o.locator, o.body, { cause: n });
104
+ else if (o.info !== void 0)
105
+ e = new l(o.message, o.locator, o.info, o.componentName, { cause: n });
106
+ else if (o.locator === "")
107
+ e = new Error(o.message, { cause: n }), e.name = o.name;
108
+ else
109
+ switch (o.name) {
110
+ case "APIError":
111
+ e = new d(o.message, o.locator, { cause: n });
112
+ break;
113
+ case "EngineError":
114
+ e = new f(o.message, o.locator, { cause: n });
115
+ break;
116
+ case "ApplicationError":
117
+ e = new a(o.message, o.locator, { cause: n });
118
+ break;
119
+ case "OperationalError":
120
+ e = new g(o.message, o.locator, { cause: n });
121
+ break;
122
+ case "WindowHandledRuntimeError":
123
+ e = new E(o.message, o.locator, { cause: n });
124
+ break;
125
+ case "WindowHandledPromiseRejectionError":
126
+ e = new u(o.message, o.locator, { cause: n });
127
+ break;
128
+ default:
129
+ e = new i(o.message, o.locator, { cause: n });
130
+ break;
131
+ }
132
+ o.stack !== void 0 && (e.stack = o.stack), n = e;
133
+ }
134
+ return n;
96
135
  }
97
- function f(e) {
98
- let o;
136
+ function p(r) {
137
+ let n;
99
138
  try {
100
- o = JSON.stringify(e);
139
+ n = JSON.stringify(r);
101
140
  } catch {
102
- typeof e == "symbol" ? o = e.description ?? "Unknown error" : typeof e == "bigint" ? o = e.toString() : o = "Unknown error";
141
+ typeof r == "symbol" ? n = r.description ?? "Unknown error" : typeof r == "bigint" ? n = r.toString() : n = "Unknown error";
103
142
  }
104
- return o === "" && (o = "Unknown error"), o;
143
+ return n === "" && (n = "Unknown error"), n;
105
144
  }
106
- function E(e) {
107
- if (!(e == null || e === ""))
108
- return e.length > 2048 ? `${e.slice(0, 2048)}... [truncated]` : e;
145
+ function b(r) {
146
+ if (!(r == null || r === ""))
147
+ return r.length > 2048 ? `${r.slice(0, 2048)}... [truncated]` : r;
109
148
  }
110
149
  export {
111
- g as APIError,
150
+ d as APIError,
112
151
  a as ApplicationError,
113
- p as EngineError,
152
+ f as EngineError,
114
153
  c as FetchError,
115
- y as OperationalError,
116
- m as VueHandledError,
117
- h as WindowHandledPromiseRejectionError,
118
- w as WindowHandledRuntimeError,
119
- b as buildFetchError,
120
- k as concatenateSerialisedErrorMessages,
121
- x as ignoreErrors,
122
- l as normalizeToError,
123
- R as serialiseError
154
+ g as OperationalError,
155
+ l as VueHandledError,
156
+ u as WindowHandledPromiseRejectionError,
157
+ E as WindowHandledRuntimeError,
158
+ y as buildFetchError,
159
+ h as concatenateSerialisedErrorMessages,
160
+ R as ignoreErrors,
161
+ w as normalizeToError,
162
+ x as serialiseError,
163
+ v as unserialiseError
124
164
  };
@@ -79,7 +79,13 @@ declare function normalizeToError(value: unknown): Error;
79
79
  * - Messages are normalized to end with punctuation.
80
80
  */
81
81
  declare function serialiseError(error?: unknown): SerialisedError[];
82
+ /** Unserialises an array of {@link SerialisedError} objects back into an error with a cause chain.
83
+ * - Reconstructs the appropriate error class based on serialized properties.
84
+ * - Chains errors from outermost to root cause using the `cause` option.
85
+ * - Returns `undefined` if the input array is empty.
86
+ */
87
+ declare function unserialiseError(serialisedErrors: SerialisedError[]): Error | undefined;
82
88
  /** Exports. */
83
89
  export type { SerialisedError };
84
90
  export { ApplicationError, APIError, EngineError, FetchError, OperationalError, VueHandledError, WindowHandledRuntimeError, WindowHandledPromiseRejectionError };
85
- export { buildFetchError, concatenateSerialisedErrorMessages, ignoreErrors, normalizeToError, serialiseError };
91
+ export { buildFetchError, concatenateSerialisedErrorMessages, ignoreErrors, normalizeToError, serialiseError, unserialiseError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datapos/datapos-shared",
3
- "version": "0.3.515",
3
+ "version": "0.3.516",
4
4
  "description": "A library containing common constants, types and utilities used across all Data Positioning projects.",
5
5
  "license": "MIT",
6
6
  "author": "Jonathan Terrell <terrell.jm@gmail.com>",