@datapos/datapos-shared 0.3.585 → 0.3.587

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,59 +1,56 @@
1
1
  class c extends Error {
2
+ data;
2
3
  locator;
3
4
  // Error locator 'package.module.method'
4
- constructor(s, o, r) {
5
- super(s, r), this.name = "DPUError", this.locator = o;
5
+ constructor(s, t, r, a) {
6
+ super(s, a), this.name = "DPUseError", this.data = r, this.locator = t;
6
7
  }
7
8
  }
8
- class y extends c {
9
- constructor(s, o, r) {
10
- super(s, o, r), this.name = "AppError";
9
+ class u extends c {
10
+ constructor(s, t, r, a) {
11
+ super(s, t, r, a), this.name = "AppError";
11
12
  }
12
13
  }
13
14
  class E extends c {
14
- body;
15
- // Sanitized snapshot of the response body
16
- constructor(s, o, r, t) {
17
- super(s, o, t), this.name = "APIError", this.body = l(r ?? void 0);
15
+ constructor(s, t, r, a) {
16
+ super(s, t, r, a), this.name = "APIError";
18
17
  }
19
18
  }
20
19
  class d extends c {
21
- constructor(s, o, r) {
22
- super(s, o, r), this.name = "EngineError";
20
+ constructor(s, t, r, a) {
21
+ super(s, t, r, a), this.name = "EngineError";
23
22
  }
24
23
  }
25
24
  class m extends c {
26
- constructor(s, o, r) {
27
- super(s, o, r), this.name = "ConnectorError";
25
+ constructor(s, t, r, a) {
26
+ super(s, t, r, a), this.name = "ConnectorError";
28
27
  }
29
28
  }
30
29
  class i extends c {
31
- body;
32
- // Sanitized portion of the response body
33
- constructor(s, o, r, t) {
34
- super(s, o, t), this.name = "FetchError", this.body = l(r ?? void 0);
30
+ constructor(s, t, r, a) {
31
+ super(s, t, r, a), this.name = "FetchError";
35
32
  }
36
33
  }
37
- async function b(e, s, o) {
38
- const r = ` - ${e.statusText}`, t = `${s} Response status '${e.status}${e.statusText ? r : ""}' received.`;
39
- let n;
34
+ async function p(e, s, t) {
35
+ const r = ` - ${e.statusText}`, a = `${s} Response status '${e.status}${e.statusText ? r : ""}' received.`;
36
+ let o;
40
37
  try {
41
- n = await e.text();
42
- } catch (u) {
43
- n = `<body unavailable: ${a(u).message}>`;
38
+ o = await e.text();
39
+ } catch (l) {
40
+ o = `<body unavailable: ${n(l).message}>`;
44
41
  }
45
- return new i(t, o, n);
42
+ return new i(a, t, { body: f(o) });
46
43
  }
47
- function p(e) {
44
+ function h(e) {
48
45
  return e.map((s) => s.message).join(" ");
49
46
  }
50
- function k(e) {
47
+ function w(e) {
51
48
  try {
52
49
  e();
53
50
  } catch {
54
51
  }
55
52
  }
56
- function a(e) {
53
+ function n(e) {
57
54
  if (e instanceof Error) return e;
58
55
  if (typeof e == "string") return new Error(e);
59
56
  if (typeof e == "number" || typeof e == "boolean" || typeof e == "bigint") return new Error(String(e));
@@ -66,65 +63,71 @@ function a(e) {
66
63
  }
67
64
  return new Error("Unknown error");
68
65
  }
69
- function h(e) {
70
- const s = /* @__PURE__ */ new Set(), o = [];
71
- let r = a(e);
66
+ function b(e) {
67
+ const s = /* @__PURE__ */ new Set(), t = [];
68
+ let r = n(e);
72
69
  for (; r != null && !s.has(r); ) {
73
70
  s.add(r);
74
- let t;
71
+ let a;
75
72
  switch (r.name) {
76
73
  case "APIError": {
77
- const n = r;
78
- t = { body: n.body, locator: n.locator, message: r.message, name: "APIError", stack: r.stack }, r = r.cause == null ? null : a(r.cause);
74
+ const o = r;
75
+ a = { data: o.data, locator: o.locator, message: r.message, name: "APIError", stack: r.stack }, r = r.cause == null ? null : n(r.cause);
79
76
  break;
80
77
  }
81
78
  case "AppError": {
82
- t = { body: void 0, locator: r.locator, message: r.message, name: "AppError", stack: r.stack }, r = r.cause == null ? null : a(r.cause);
79
+ const o = r;
80
+ a = { data: o.data, locator: o.locator, message: r.message, name: "AppError", stack: r.stack }, r = r.cause == null ? null : n(r.cause);
83
81
  break;
84
82
  }
85
83
  case "ConnectorError": {
86
- t = { body: void 0, locator: r.locator, message: r.message, name: "ConnectorError", stack: r.stack }, r = r.cause == null ? null : a(r.cause);
84
+ const o = r;
85
+ a = { data: o.data, locator: o.locator, message: r.message, name: "ConnectorError", stack: r.stack }, r = r.cause == null ? null : n(r.cause);
87
86
  break;
88
87
  }
89
88
  case "EngineError": {
90
- t = { body: void 0, locator: r.locator, message: r.message, name: "EngineError", stack: r.stack }, r = r.cause == null ? null : a(r.cause);
89
+ const o = r;
90
+ a = { data: o.data, locator: o.locator, message: r.message, name: "EngineError", stack: r.stack }, r = r.cause == null ? null : n(r.cause);
91
91
  break;
92
92
  }
93
93
  case "FetchError": {
94
- const n = r;
95
- t = { body: n.body, locator: n.locator, message: r.message, name: "FetchError", stack: r.stack }, r = r.cause == null ? null : a(r.cause);
94
+ const o = r;
95
+ a = { data: o.data, locator: o.locator, message: r.message, name: "FetchError", stack: r.stack }, r = r.cause == null ? null : n(r.cause);
96
96
  break;
97
97
  }
98
98
  default:
99
- r.name ? (t = { body: void 0, locator: "", message: r.message, name: r.name, stack: r.stack }, r = r.cause == null ? null : a(r.cause)) : (t = { body: void 0, locator: "", message: g(r), name: "Error", stack: void 0 }, r = null);
99
+ r.name ? (a = { data: void 0, locator: "", message: r.message, name: r.name, stack: r.stack }, r = r.cause == null ? null : n(r.cause)) : (a = { data: void 0, locator: "", message: g(r), name: "Error", stack: void 0 }, r = null);
100
100
  }
101
- /(?:\.{3}|[.!?])$/.test(t.message) || (t.message += "."), o.push(t);
101
+ /(?:\.{3}|[.!?])$/.test(a.message) || (a.message += "."), t.push(a);
102
102
  }
103
- return o;
103
+ return t;
104
104
  }
105
- function w(e) {
105
+ function y(e) {
106
106
  if (e.length === 0) return;
107
107
  let s;
108
- for (const o of e.toReversed()) {
108
+ for (const t of e.toReversed()) {
109
109
  let r;
110
- switch (o.name) {
110
+ switch (t.name) {
111
111
  case "APIError":
112
- r = new E(o.message, o.locator, o.body, { cause: s });
112
+ r = new E(t.message, t.locator, t.data, { cause: s });
113
+ break;
114
+ case "AppError":
115
+ r = new u(t.message, t.locator, t.data, { cause: s });
113
116
  break;
114
117
  case "ConnectorError":
115
- r = new m(o.message, o.locator, { cause: s });
118
+ r = new m(t.message, t.locator, t.data, { cause: s });
116
119
  break;
117
120
  case "EngineError":
118
- r = new d(o.message, o.locator, { cause: s });
121
+ r = new d(t.message, t.locator, t.data, { cause: s });
119
122
  break;
120
123
  case "FetchError":
121
- r = new i(o.message, o.locator, o.body, { cause: s });
124
+ r = new i(t.message, t.locator, t.data, { cause: s });
122
125
  break;
123
126
  default:
124
- r = new Error(o.message, { cause: s }), r.name = o.name;
127
+ r = new Error(t.message, { cause: s }), r.name = t.name;
125
128
  break;
126
129
  }
127
- o.stack !== void 0 && (r.stack = o.stack), s = r;
130
+ t.stack !== void 0 && (r.stack = t.stack), s = r;
128
131
  }
129
132
  return s;
130
133
  }
@@ -137,21 +140,21 @@ function g(e) {
137
140
  }
138
141
  return s === "" && (s = "Unknown error"), s;
139
142
  }
140
- function l(e) {
143
+ function f(e) {
141
144
  if (!(e == null || e === ""))
142
145
  return e.length > 2048 ? `${e.slice(0, 2048)}... [truncated]` : e;
143
146
  }
144
147
  export {
145
148
  E as APIError,
146
- y as AppError,
149
+ u as AppError,
147
150
  m as ConnectorError,
148
- c as DPUError,
151
+ c as DPUseError,
149
152
  d as EngineError,
150
153
  i as FetchError,
151
- b as buildFetchError,
152
- p as concatenateSerialisedErrorMessages,
153
- k as ignoreErrors,
154
- a as normalizeToError,
155
- h as serialiseError,
156
- w as unserialiseError
154
+ p as buildFetchError,
155
+ h as concatenateSerialisedErrorMessages,
156
+ w as ignoreErrors,
157
+ n as normalizeToError,
158
+ b as serialiseError,
159
+ y as unserialiseError
157
160
  };
@@ -1,30 +1,29 @@
1
1
  export interface SerialisedError {
2
- body: string | undefined;
2
+ data: Record<string, unknown> | undefined;
3
3
  locator: string;
4
4
  message: string;
5
5
  name: string;
6
6
  stack: string | undefined;
7
7
  }
8
- export declare class DPUError extends Error {
9
- readonly locator: string | undefined;
10
- constructor(message: string, locator: string | undefined, options?: ErrorOptions);
8
+ export declare class DPUseError extends Error {
9
+ readonly data: Record<string, unknown> | undefined;
10
+ readonly locator: string;
11
+ constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions);
11
12
  }
12
- export declare class AppError extends DPUError {
13
- constructor(message: string, locator: string, options?: ErrorOptions);
13
+ export declare class AppError extends DPUseError {
14
+ constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions);
14
15
  }
15
- export declare class APIError extends DPUError {
16
- readonly body: string | undefined;
17
- constructor(message: string, locator: string, body: string | undefined, options?: ErrorOptions);
16
+ export declare class APIError extends DPUseError {
17
+ constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions);
18
18
  }
19
- export declare class EngineError extends DPUError {
20
- constructor(message: string, locator: string, options?: ErrorOptions);
19
+ export declare class EngineError extends DPUseError {
20
+ constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions);
21
21
  }
22
- export declare class ConnectorError extends DPUError {
23
- constructor(message: string, locator: string, options?: ErrorOptions);
22
+ export declare class ConnectorError extends DPUseError {
23
+ constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions);
24
24
  }
25
- export declare class FetchError extends DPUError {
26
- readonly body: string | undefined;
27
- constructor(message: string, locator: string, body: string | undefined, options?: ErrorOptions);
25
+ export declare class FetchError extends DPUseError {
26
+ constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions);
28
27
  }
29
28
  export declare function buildFetchError(response: {
30
29
  status: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datapos/datapos-shared",
3
- "version": "0.3.585",
3
+ "version": "0.3.587",
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>",