@datapos/datapos-shared 0.3.586 → 0.3.588

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
- class c extends Error {
1
+ class i 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 i {
10
+ constructor(s, t, r, a) {
11
+ super(s, t, r, a), this.name = "AppError";
11
12
  }
12
13
  }
13
- 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);
14
+ class E extends i {
15
+ constructor(s, t, r, a) {
16
+ super(s, t, r, a), this.name = "APIError";
18
17
  }
19
18
  }
20
- class d extends c {
21
- constructor(s, o, r) {
22
- super(s, o, r), this.name = "EngineError";
19
+ class d extends i {
20
+ constructor(s, t, r, a) {
21
+ super(s, t, r, a), this.name = "EngineError";
23
22
  }
24
23
  }
25
- class m extends c {
26
- constructor(s, o, r) {
27
- super(s, o, r), this.name = "ConnectorError";
24
+ class m extends i {
25
+ constructor(s, t, r, a) {
26
+ super(s, t, r, a), this.name = "ConnectorError";
28
27
  }
29
28
  }
30
- 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);
29
+ class l extends i {
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 c;
40
37
  try {
41
- n = await e.text();
42
- } catch (u) {
43
- n = `<body unavailable: ${a(u).message}>`;
38
+ c = await e.text();
39
+ } catch (o) {
40
+ c = `<body unavailable: ${n(o).message}>`;
44
41
  }
45
- return new i(t, o, n);
42
+ return new l(a, t, { body: f(c) });
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 b(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,72 @@ 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 w(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
+ const c = { ...Object.fromEntries(Object.entries(e ?? {})) };
100
+ r.name ? (a = { data: c, locator: "", message: r.message, name: r.name, stack: r.stack }, r = r.cause == null ? null : n(r.cause)) : (a = { data: c, locator: "", message: g(r), name: "Error", stack: void 0 }, r = null);
100
101
  }
101
- /(?:\.{3}|[.!?])$/.test(t.message) || (t.message += "."), o.push(t);
102
+ /(?:\.{3}|[.!?])$/.test(a.message) || (a.message += "."), t.push(a);
102
103
  }
103
- return o;
104
+ return t;
104
105
  }
105
- function w(e) {
106
+ function y(e) {
106
107
  if (e.length === 0) return;
107
108
  let s;
108
- for (const o of e.toReversed()) {
109
+ for (const t of e.toReversed()) {
109
110
  let r;
110
- switch (o.name) {
111
+ switch (t.name) {
111
112
  case "APIError":
112
- r = new E(o.message, o.locator, o.body, { cause: s });
113
+ r = new E(t.message, t.locator, t.data, { cause: s });
114
+ break;
115
+ case "AppError":
116
+ r = new u(t.message, t.locator, t.data, { cause: s });
113
117
  break;
114
118
  case "ConnectorError":
115
- r = new m(o.message, o.locator, { cause: s });
119
+ r = new m(t.message, t.locator, t.data, { cause: s });
116
120
  break;
117
121
  case "EngineError":
118
- r = new d(o.message, o.locator, { cause: s });
122
+ r = new d(t.message, t.locator, t.data, { cause: s });
119
123
  break;
120
124
  case "FetchError":
121
- r = new i(o.message, o.locator, o.body, { cause: s });
125
+ r = new l(t.message, t.locator, t.data, { cause: s });
122
126
  break;
123
127
  default:
124
- r = new Error(o.message, { cause: s }), r.name = o.name;
128
+ r = new Error(t.message, { cause: s }), r.name = t.name;
125
129
  break;
126
130
  }
127
- o.stack !== void 0 && (r.stack = o.stack), s = r;
131
+ t.stack !== void 0 && (r.stack = t.stack), s = r;
128
132
  }
129
133
  return s;
130
134
  }
@@ -137,21 +141,21 @@ function g(e) {
137
141
  }
138
142
  return s === "" && (s = "Unknown error"), s;
139
143
  }
140
- function l(e) {
144
+ function f(e) {
141
145
  if (!(e == null || e === ""))
142
146
  return e.length > 2048 ? `${e.slice(0, 2048)}... [truncated]` : e;
143
147
  }
144
148
  export {
145
149
  E as APIError,
146
- y as AppError,
150
+ u as AppError,
147
151
  m as ConnectorError,
148
- c as DPUError,
152
+ i as DPUseError,
149
153
  d as EngineError,
150
- 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
+ l as FetchError,
155
+ p as buildFetchError,
156
+ h as concatenateSerialisedErrorMessages,
157
+ b as ignoreErrors,
158
+ n as normalizeToError,
159
+ w as serialiseError,
160
+ y as unserialiseError
157
161
  };
@@ -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 {
8
+ export declare class DPUseError extends Error {
9
+ readonly data: Record<string, unknown> | undefined;
9
10
  readonly locator: string;
10
- constructor(message: string, locator: string, options?: ErrorOptions);
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.586",
3
+ "version": "0.3.588",
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>",